akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */


// quoted from beet-aizu
template <typename T, typename E, typename F, typename G>
struct SegmentTree{
    // using F = function<T(T, T)>
    // using G = function<T(T, E)>
    int n;
    F f;
    G g;
    T ti;
    vector<T> dat;
    SegmentTree(){};
    SegmentTree(F f,G g,T ti):f(f),g(g),ti(ti){}
    void init(int n_){    
        n=1;
        while(n<n_) n<<=1;
        dat.assign(n<<1,ti);
    }
    void build(const vector<T> &v){
        int n_=v.size();
        init(n_);
        for(int i=0;i<n_;i++) dat[n+i]=v[i];
        for(int i=n-1;i;i--)
            dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
    }
    void update(int k,const E &x){
        k += n;
        dat[k] = g(dat[k], x);
        while(k>>=1)
            dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);    
    }
    T operator [](int k) const { return dat[k+n]; }
    T query(int a,int b) const {
        T vl=ti,vr=ti;
        for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
            if(l&1) vl=f(vl,dat[l++]);
            if(r&1) vr=f(dat[--r],vr);
        }
        return f(vl,vr);
    }

    /* TODO わからない 聞く 
    template<typename C>
    int find(int a,int b,C &check,int k,int l,int r){
        if(!check(dat[k])||r<=a||b<=l) return -1;
        if(k>=n) return k-n;
        int m=(l+r)>>1;
        int vl=find(a,b,check,(k<<1)|0,l,m);
        if(~vl) return vl;
        return find(a,b,check,(k<<1)|1,m,r);
    }
    template<typename C>
    int find(int a,int b,C &check){
        return find(a,b,check,1,0,n);
    }*/
    
};


/**  テンプレ
int main(){
}
**/

int main() {
  
  const int W = 100001;
  vector<lint> dat(W, 0);
  int n; cin >> n;
  for (int i = 0; i < n; i++) {
    int a; cin >> a;
    dat[a] += a;
  }

  using T = lint;  // type T
  using E = lint;  // type E
  auto f = [](T a, T b){ // return type T value
    return a + b;
  };
  auto g = [](T a, E b){ // return type T value
    return a + b;  // return b;
  };
  T ti = 0;  // identity element
  SegmentTree<T, E, decltype(f), decltype(g)> sg(f, g, ti);  // don't change
  sg.build(dat);

  int q; cin >> q;
  for (int i = 0; i < q; i++) {
    lint b, c; cin >> b >> c;
    lint cnt = sg.query(b, b + 1) / b;
    sg.update(b, -cnt * b);
    sg.update(c, cnt * c);
    cout << sg.query(0, W) << endl;
  }

  return 0;
}


Measured memory_bytes: 6156
import math

def solve():
    K = int(input())
    sum = 0
    for a in range(1, K + 1):
        for b in range(1, K + 1):
            ab = math.gcd(a, b)
            for c in range(1, K + 1):
                sum += math.gcd(ab, c)
                pass
    print(sum)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 9180
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  int N,K;
  cin >> N >> K;
  int d = 1;
  rep(i,36){
    if(N / d == 0){
      cout << i << endl;
      return 0;
    }
    d *= K;
  }
}

Measured memory_bytes: 3588
n = int(input())
a = list(map(int,input().split()))
a.sort()
a.append(-1)
ans = 0
p = 1
for i in range(1,n+1):
    if a[i-1] != a[i]:
        if a[i-1] != p:
            if p < a[i-1]:
                ans += p
            else:
                ans += p - a[i-1]
        p = 1
    else:
        p += 1
print(ans)

Measured memory_bytes: 20656
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <utility>
#include <string>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <cctype>

typedef long long int lli;

using namespace std;

int main() {

   int A,B,C,D;
   cin >> A >> B>> C >> D;
  
   while(B!=0 and A!=0){
   	C-=B;
    if(C<=0){
    break;}
    A-=D;
    if(A<=0){
    break;}
   }
  	if(C<=0 && A>0){
    	cout << "Yes" << endl;
    }
   	if(C>0 && A<=0){
    	cout << "No" << endl;
    }
    
}

Measured memory_bytes: 3636
n,q = (int(i) for i in input().split())
s = input()
x = [[i for i in input().split()] for i in range(q)]
l,r,s = 0,n+1,"#"+s+"#"
for i,j in x[::-1]:
    if l<=n and s[l+1]==i and  j=="L": l+=1
    elif s[l]==i and j=="R": l-=1
    if s[r-1]==i and j=="R": r-=1
    elif s[r]==i and j=="L": r+=1
print(max(0,r-l-1))

Measured memory_bytes: 28592
#include<iostream>
using namespace std;
char a[100005];
int cnt=1;
int n;
int main(){
	scanf("%d",&n);
	getchar();
	for(int i=0;i<n;i++){
		scanf("%c",&a[i]);
	}
	//printf("%c",a[1]);
	for(int i=1;i<n;i++){
		if(a[i]!=a[i-1]){
			cnt++;
			//printf("%d ",i);
		}
	}
	printf("%d",cnt);
} 

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, int> pli;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int main() {
	int N;
	cin >> N;
	int c = 1;

	rep(t, 9) {
		c *= 10;
		if (N == c) {
			puts("10");
			return 0;
		}
	}

	int s = 0;
	while (N) {
		s += (N % 10);
		N /= 10;
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int len = s.length();
		String s1=s.substring(0, (len-1)/2);
		String s2=s.substring(((len+3)/2)-1,len);
		boolean ans1=check(s1);
		boolean ans2=check(s2);
		if(ans1&&ans2&&s1.equals(s2)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		sc.close();
	}

	public boolean check(String s) {
		int n = s.length();
		for(int i=0; i<(n)/2; i++) {
			if( s.charAt(i) != (s.charAt(n-1-i))) {
				return false;
			}
		}
		return true;
	}
}


Measured memory_bytes: 21844
import Data.List
import Debug.Trace

main = do
  _ <- getLine
  as <- map read . words <$> getLine :: IO [Int]
  print $ solve as

solve as =
  ans 
  where
    grp = group $ sort as
    check [] acc = acc
    check as@(a:_) acc =
      let len = length a in
      let diff = len - head a in
      let del = if diff >= 0 then diff else len in
      traceShow (a,len,diff,del) $
      check (tail as) (acc+del)
    ans = check grp 0

Measured memory_bytes: 60796
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format, std.datetime;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long H, W;
    scan(H, W);
    auto C = new long[][](10);
    foreach (i; 0 .. 10)
        C[i] = aryread();
    auto A = new long[](H * W);
    foreach (i; 0 .. H)
    {
        auto a = aryread();
        foreach (j; 0 .. W)
        {
            A[i * W + j] = a[j];
        }
    }
    foreach (k; 0 .. 10)
        foreach (i; 0 .. 10)
            foreach (j; 0 .. 10)
                if (C[i][k] + C[k][j] < C[i][j])
                    C[i][j] = C[i][k] + C[k][j];
    long ans;
    foreach (a; A)
        if (a != -1)
        {
            ans += C[a][1];
        }
    writeln(ans);
}


Measured memory_bytes: 4220
MOD = 10**9 + 7
n = gets.to_i
s = gets.chomp
hash = Hash.new(0)
n.times do |i|
  hash[s[i]] += 1
end
sum = 1
hash.each_value do |x|
  sum *= x+1
  sum %= MOD
end
sum -= 1
sum %= MOD
puts sum

Measured memory_bytes: 14384
#include <bits/stdc++.h>
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<int> E1a;
    vector<bool> EaN(N, false);
    while (M--){
        int a, b;
        cin >> a >> b;
        if (a == 1) E1a.push_back(b);
        if (b == 1) E1a.push_back(b);
        if (a == N) EaN[b] = true;
        if (b == N) EaN[a] = true;
    }
    for (auto a : E1a){
        if (EaN[a]){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,k,l,c=0;
    map<int , int> mp;
    map<int , int> :: iterator it;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>j;
        mp[i]=j;
    }
    for(it=mp.begin();it!=mp.end();it++)
    {
        if(it->first!=it->second)
            c++;
    }
    if(c<=2)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}


Measured memory_bytes: 256
import itertools

n = int(input())
ps = input()
qs = input()

p = list(map(int,ps.split(' ')))
q = list(map(int,qs.split(' ')))
pn = 0
qn = 0

for x,a in enumerate(list(itertools.permutations([i+1 for i in range(n)],n))):
  if list(a)==p:
    pn = x
  if list(a)==q:
    qn = x

print(abs(pn-qn))

Measured memory_bytes: 47472
import sys
 
n, x, y = map(int, sys.stdin.readline().split())
x, y = x-1, y-1
cnt = [0] * (n - 1)
 
for i in range(n):
    for j in range(i+1, n):
        a = abs(j-i)
        b = abs(x-i) + abs(y-j) + 1
        c = abs(y-i) + abs(x-j) + 1
        cnt[min(a,b,c) - 1] += 1
 
for i in range(n-1):
    print(cnt[i])

Measured memory_bytes: 48604
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  string s;
  cin >> s;
  if (s[0] == 'A') {
    int count = 0;
    int cCount = 0;
    rep (i, s.size()) {
      if (s[i] >= 'A' && s[i] <= 'Z') count++;
      if (i >= 2 && i <= s.size() - 2 && s[i] == 'C') cCount++;
    }
    if (count == 2 && cCount == 1) {
      P("AC");
      return 0;
    }
  }
  P("WA");

  return 0;
}



Measured memory_bytes: 256
import collections
n = int(input())
v_ = list(map(int,input().split()))
v_g = v_[0:len(v_):2]
v_k = v_[1:len(v_):2]

counter_g = collections.Counter(v_g)
counter_g = sorted(counter_g.items(),key=lambda x:x[1])[::-1]
counter_k = collections.Counter(v_k)
counter_k = sorted(counter_k.items(),key=lambda x:x[1])[::-1]


if counter_g[0][0] != counter_k[0][0]:
  print(n - counter_g[0][1] - counter_k[0][1])
else:
  if len(counter_g) == 1 and len(counter_k) == 1:
    print(int(n/2))
  else:
    if len(counter_g) == 1:
      print(len(counter_k)-counter_k[1][1])
    elif len(counter_k) == 1:
      print(len(counter_g)-counter_g[1][1])
    else:
      print(min(n-counter_g[0][1]-counter_k[1][1],n-counter_g[1][1]-counter_k[0][1]))




Measured memory_bytes: 21212
main = do
    n <- read <$> getLine
    print $ findPowerOf2 (reverse [1 .. n]) $ powerOf2 (n `div` 2)

powerOf2 :: Int -> [Int]
powerOf2 max = map (2^) [0 .. max]

findPowerOf2 :: [Int] -> [Int] -> Int
findPowerOf2 [n] _ = n
findPowerOf2 (x:xs) po2 = if x `elem` po2 then x else findPowerOf2 xs po2

Measured memory_bytes: 3848
#include <bits/stdc++.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

using namespace std;

int main(){
  int N;
  cin >> N;
  int a[2][N];
  rep(i,N) cin >> a[0][i];
  rep(i,N) cin >> a[1][i];
  rep(i,N-1){
    a[0][i+1] += a[0][i];
    a[1][i+1] += a[1][i];
  }
  int ans = -1;
  rep(i,N){
    if(i != 0)ans = max(ans,a[0][i] + a[1][N-1] - a[1][i-1]);
    else      ans = max(ans,a[0][0] + a[1][N-1] );
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;

int field[19][17];
int DP[19][17];
int main()
{
	int w,h;
	while(cin >> w >> h){
		if(!w && !h)
			break;
		for(int i=0;i<19;i++){
			for(int j=0;j<17;j++){
				field[i][j] = 0;
				DP[i][j] = 0;
			}
		}
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				cin >> field[i][j];
			}
		}
		for(int j=1;j<=w;j++){
			if(field[1][j] == 1)
				DP[1][j] = 0;
			else if(field[1][j] == 0)
				DP[1][j] = 1;
		}
		
		for(int i=2;i<=h;i++){
			for(int j=1;j<=w;j++){
				if(field[i][j] == 1)
					DP[i][j] = 0;
				else if(field[i][j] == 0)
					DP[i][j] += DP[i-1][j-1] + DP[i-1][j] + DP[i-1][j+1];
				else if(field[i][j] == 2){
					DP[i][j] = 0;
					int dy = 0;
					while(field[i+dy][j] == 2){
						DP[i+dy][j] = 0;
						dy+=2;
					}
					DP[i+dy][j] += DP[i-1][j];
				}
			}
		}
		
		int sum = 0;
		for(int i=h;i<=h+2;i++){
			for(int j=1;j<=w;j++){
				sum += DP[i][j];
			}
		}
		cout << sum << endl;		
		/*
		for(int i=0;i<18;i++){
			for(int j=0;j<17;j++){
				cout << DP[i][j];
			}
			cout << endl;
		}*/
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template< int sz >
struct FastInput {
  char buf[sz + 1];
  char *o;

  FastInput() { init(); }

  void init() {
    o = buf;
    buf[fread(buf, sizeof(char), sizeof(char) * sz, stdin)] = '\0';
  }

  int64_t read() {
    int64_t ret = 0, sign = 1;
    while(*o && *o <= 32) ++o;
    if(*o == '-') sign *= -1, ++o;
    while(*o >= '0' && *o <= '9') {
      ret *= 10;
      ret += *o++ - '0';
    }
    return ret * sign;
  }
};

int main(){
    
    int N;cin>>N;
    vector<int> A(N);
    int cnt=0;
    for(int i=0;i<N;i++){
        cin>>A[i];
        if(A[i]%2) cnt++;
    }
    if(cnt%2) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		
		//入力
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a[]=new int[n];
		
		for(int i=0; i<a.length; i++) {
			a[i]=sc.nextInt();
		}

		//出力
		for(int i=a.length-1; i>0; i--) {
			System.out.printf("%d ",a[i]);
		}
		System.out.printf("%d%n",a[0]);
	}

}



Measured memory_bytes: 26492
#include<bits/stdc++.h>
using namespace std;


int main(){
    int n;
    cin >> n;
    bool ok=false;
    while(ok==false){
        int a=n%10;
        int sub=n;
        sub=sub/10;
        int b=sub%10;
        sub=sub/10;
        int c=sub%10;
        if(a==b && a==c && b==c){
            ok=true;
        }else{
            n++;
        }
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner stdin = new Scanner(System.in);

    int[] result = main(stdin.nextInt(), stdin.nextInt(), stdin.nextInt(), stdin.nextInt(), stdin.nextInt(),
        stdin.nextInt());
    System.out.println(result[0] + " " + result[1]);

    stdin.close();
  }

  public static int[] main(int A, int B, int C, int D, int E, int F) {
    // 100Aa + 100Bb + Cc + Dd <= F
    // (Cc + Dd) <= E * (Aa + Bb)
    double max = 0;
    int maxWater = 0;
    int maxSugar = 0;

    for (int a = 0; a * 100 <= F; a++) {
      for (int b = (a == 0) ? 1 : 0; (A * a + B * b) * 100 <= F; b++) {
        int water = (A * a + B * b) * 100;
        int sugarLimit = Math.min(E * (A * a + B * b), F - water);
        int sugar = maximizeSugar(C, D, sugarLimit);
        if (sugar == sugarLimit && sugar == E * (A * a + B * b)) {
          return new int[] { water + sugar, sugar };
        }

        if (sugar > max * (water + sugar)) {
          max = (double) sugar / (water + sugar);
          maxWater = water;
          maxSugar = sugar;
        }
      }
    }

    if (max == 0) {
      return new int[] { A * 100, 0 };
    } else {
      return new int[] { maxWater + maxSugar, maxSugar };
    }
  }

  private static int maximizeSugar(int C, int D, int limit) {
    int minRem = limit;
    for (int c = 0; c <= limit / C; c++) {
      minRem = Math.min((limit - C * c) % D, minRem);
    }
    return limit - minRem;
  }
}

Measured memory_bytes: 23124
#include "bits/stdc++.h"

using namespace std;



int main(){
	long long n,ac=0;
	string s;
	cin >> n >> s;

	for (auto&& x : s){
		if (x + n > 'Z') x = x + n - ('Z'-'A'+1);
		else x += n;
	}

	cout << s << endl;

	cin >> n;
	return 0;

	
}

//abc145-c

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> v[2];
    rep(i, M){
        int A;
        cin >> A;
        v[A%2].pb(A);
    }
    vector<int> a, b;
    if(N%2 == 0){
        if(sz(v[1]) == 0){
            if(M == 1){
                a.pb(N), b.pb(N-1), b.pb(1);
            }
            else{
                for(auto &e: v[0]) a.pb(e), b.pb(e);
                b.front()++, b.back()--;
            }
        }
        elif(sz(v[1]) == 2){
            a.pb(v[1][0]), b.pb(v[1][0]+1);
            for(auto &e: v[0]) a.pb(e), b.pb(e);
            a.pb(v[1][1]);
            if(v[1][1] > 1) b.pb(v[1][1]-1);
        }
        else{
            cout << "Impossible" << endl;
            return 0;
        }
    }
    else{
        if(sz(v[1]) == 1){
            if(M == 1){
                if(N == 1) a.pb(1), b.pb(1);
                else a.pb(N), b.pb(N-1), b.pb(1);
            }
            else{
                a.pb(v[1][0]), b.pb(v[1][0]+1);
                for(auto &e: v[0]) a.pb(e), b.pb(e);
                b.back()--;
            }
        }
        else{
            cout << "Impossible" << endl;
            return 0;
        }
    }
    for(auto &e: a) cout << e << ' '; cout << endl;
    cout << sz(b) << endl;
    for(auto &e: b) cout << e << ' '; cout << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

signed main(){
  string s, t;
  cin >> s >> t;
  int n = sz(s);

  s += s;

  vi a[26];
  rep(i, 0, sz(s)){
    a[s[i]-'a'].emplace_back(i+1);
  }

  rep(i, 0, 26) a[i].emplace_back(inf);

  int ans = 0, cur = 0;
  rep(i, 0, sz(t)){
    cur = *upper_bound(all(a[t[i]-'a']), cur);
    if(cur == inf){
      cout << -1 << endl;
      return 0;
    }
    if(cur > n){
      ans += n;
      cur -= n;
    }
  }
  ans += cur;

  if(ans >= inf) cout << -1 << endl;
  else cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2804
#include <stdio.h>
#include <string.h>


int main(){
    
    int num[3];
    scanf("%d %d %d", &num[0], &num[1], &num[2]);
    num[2]-=(num[0]-num[1]);
    if(num[2]<0)num[2]=0;
    printf("%d",num[2]);
}

Measured memory_bytes: 128
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define MOD 1000000007;

int main(){
	int n;
	cin >> n;
	map<string, int> mp;
	char last;
	for(int i=0; i<n; i++){
		string s;
		cin >> s;
		if(!i){
			last=s[s.size()-1];
			mp[s]++;
		}
		else if(last!=s[0] || mp[s]>0){
			cout << "No" << endl;
			return 0;
		}
		else{
			last=s[s.size()-1];
			mp[s]++;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
#pragma GCC optimize("O3")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 300*1000+15;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> tree_set;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}
signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    /*comment for all except cc/cf    
    #ifndef ONLINE_JUDGE    
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif//*/
   	int h,n;
   	cin>>h>>n;
   	pii a[n];
   	for (int i = 0; i < n; ++i)
   	{
   		cin>>a[i].ff>>a[i].ss;
   	}
   	int count[10005];
   	for (int i = 0; i < 10005; ++i)
   	{
   		count[i]=INF;
   	}
   	count[0]=0;
   	for (int i = 0; i < 10005; ++i)
   	{
   		for (int j = 0; j < n; ++j)
   		{
   			count[i] = min( count[ max(0ll,i-a[j].ff) ] + a[j].ss , count[i] );
   		}
   	}
   	cout<<count[h];

}

Measured memory_bytes: 384
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    n, *a = map(int, read().split())
    r = 0
    num = 2
    while True:
        c = [not (i % num) for i in a]
        if all(c):
            r += 1
            num *= 2
        else:
            break
    print(r)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9128
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int p[10002];
int r[10002];

void init(int n){
    for (int i = 0; i < n; ++i) {
        p[i]=i;
        r[i]=0;
    }
}


int find(int x){
	if(x != p[x]){
		p[x] = find(p[x]);
    }
   	return p[x];
}
     
void union_set(int x,int y){
	x = find(x);
	y = find(y);
	if(x==y) return;
	if(r[x] < r[y]){
		p[x] = y;	
	}else{
		p[y] = x;
		if(r[x] == r[y])r[x]++;
	}
	return ;
}





int main(){
	int n,m;
	while(cin >> n >> m&&n!=0){
		init(n);
		vector<vector<pair<pair<int,int>,pair<int,int> > > > g(n);
		vector<int>dst(n);
		dst[0] = 0;
		for(int i=0;i<m;i++){
			int u,v,d,c;
			cin >> u >> v >> d >> c;
			u--;
			v--;
			g[u].PB(MP(MP(d,c),MP(u,v)));
			g[v].PB(MP(MP(d,c),MP(v,u)));
		}
		priority_queue<pair<pair<int,int>,pair<int,int> >,vector<pair<pair<int,int>,pair<int,int> >>,greater<pair<pair<int,int>,pair<int,int> > > > pq;
		for(auto x:g[0]){
			pq.push(x);
		}
		int ans = 0;
		while(!pq.empty()){
			auto x = pq.top();
			pq.pop();
			if(find(0)!=find(x.second.second)){
				union_set(0,x.second.second);
				ans += x.first.second;
				dst[x.second.second] = x.first.first;
				for(auto y:g[x.second.second]){
					auto z = y;
					z.first.first += dst[x.second.second];
					pq.push(z);
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 4952
H, W = map(int, input().split())

A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]
Diff = [[0] * (W + 1) for _ in range(H + 1)]
M = 0
for i in range(H):
    for j in range(W):
        m = abs(A[i][j] - B[i][j])
        Diff[i][j] = m
        M += m

dp = [[0] * (W + 1) for _ in range(H + 1)]
dp[0][0] |= (1 << Diff[i][j])

for i in range(0, H):
    for j in range(0, W):
        here = dp[i][j]
        s = Diff[i][j]
        ni = nj = (here << s) | (here >> s)
        ex = 0
        for k in range(1, s + 1):
            if (here >> k) & 1:
                ex |= (1 << (s - k))
        dp[i + 1][j] |= (ni | ex)
        dp[i][j + 1] |= (nj | ex)

a = dp[H - 1][W - 1]
ans = 0
for k in range(M + 1):
    if (a >> k) & 1:
        ans = k
        break

print(k)


Measured memory_bytes: 53084
#include <stdio.h>
#include <math.h>


int main(void){
  
  int n;
  int prm[1000];
  int cnt;
  int jdg;
  int ans;
  int num;
  
  int i;
  int j;
  double k;
  int key;
    
  while( scanf("%d", &n ) != EOF ){
    
    k = sqrt( n );
    key = k + 1;
    
    
    ans = 1;
    if( n == 1 ) ans = 0;
    
    prm[0] = 2;
    for( i = 1; i < 200; i++ ){
      prm[i] = 0;
    }
    
      
  
    for( j = 3; j <= key; j+=2 ){
      jdg = 0;
      
      for( i = 0; prm[i]; i++ ){
        
        num = i + 1;
        if( !(j % prm[i]) ){
          jdg++;
          break;
        }
        
      }
      
      if( !jdg ){
        ans++;
        prm[num] = j;
        
      }
    }
    
    int a;
    
    
    for(j = 0; j < n-key; j++){
      a = 1;
      for( i = 0; prm[i]; i++ ){
        if( !((j+key+1)%prm[i]) ) {
          a = 0;
          break;
        }
      }
      
      if( a ) ans++;
      
    }
 
    
    
    printf("%d\n", ans);
  }
  
  return 0;
}

Measured memory_bytes: 600
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	m = make(map[string]struct{})
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanLines)
	sc.Scan()
	n, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}

	for i := 0; i < n; i++ {
		sc.Scan()
		line := sc.Text()
		ss := strings.Split(line, " ")
		commend := ss[0]
		value := ss[1]
		switch commend {
		case "insert":
			insert(value)
		case "find":
			if find(value) {
				fmt.Println("yes")
			} else {
				fmt.Println("no")
			}
		}
	}
}

var m map[string]struct{}

func insert(v string) {
	m[v] = struct{}{}
}

func find(v string) bool {
	_, ok := m[v]
	return ok
}



Measured memory_bytes: 37668
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll N, K;
    cin >> N >> K;

    while (true) {
        ll temp = N % K;
        if (temp < N) {
            N = temp;
        } else {
            break;
        }
    }

    cout << min(N, abs(N - K)) << "\n";
}


Measured memory_bytes: 256
import math

(a, b, C) = [float(i) for i in input().split()]
S = 0.5 * a * b * math.sin(math.radians(C))
c = math.sqrt(a * a + b * b - 2 * a * b * math.cos(math.radians(C)))

print("%8f" %(S))
print("%8f" %(a + b + c))
print("%8f" %(S / a * 2))

Measured memory_bytes: 6872
while True:
    temp = input()
    m, f, r = temp.split(' ')
    m, f, r = int(m), int(f), int(r)
    
    if m == -1 and f == -1 and r == -1:
        break;
    
    if m == -1 or f == -1:
        print('F')
    elif m + f >= 80:
        print('A')
    elif m + f >= 65:
        print('B')
    elif m + f >= 50:
        print('C')
    elif m + f >= 30:
        if r >= 50:
            print('C')
        else:
            print('D')
    else:
        print('F')


Measured memory_bytes: 5596
#include<iostream>
using namespace std;

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    while(a>0){
        c = c - b;
        if(c<=0){
            cout<<"Yes"<<endl;
            return 0;
        }
        a = a - d;
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 3632
#!/usr/bin/env python3
#ABC128 B

import sys
import math
import bisect
from heapq import heappush, heappop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
mod = 10**9 + 7

n = int(input())
sp = [list(input().split()) for _ in range(n)]
for i in range(n):
    sp[i].append(i+1)
sp.sort(key = lambda x:(x[0],-int(x[1])))
for i in range(n):
    print(sp[i][2])
    


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int h, w, d, q, v[100005], x[100005], y[100005];
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> h >> w >> d; 
    rep(i, 0, h) {
        rep(j, 0, w) {
            int val; cin >> val;
            x[val] = i, y[val] = j;
        }
    }
    erep(i, 0, d+1) v[i] = 0;
    erep(i, d+1, h*w) {
        v[i] = v[i-d] + abs(x[i] - x[i-d]) + abs(y[i] - y[i-d]);
    }
    cin >> q;
    rep(i, 0, q) {
        int l, r;
        cin >> l >> r;
        cout << v[r] - v[l] << endl;
    }
    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
using namespace std;
int main()
{
    int n, y, k1;
    cin >> n >> y;
    y /= 1000;
    for(int k10 = n; k10 >= 0; k10--){
        for(int k5 = n - k10; k5 >= 0; k5--){
            k1 = n - k10 - k5;
            if(k1 + k5*5 + k10*10 == y){
                cout << k10 << ' ' << k5 << ' ' << k1 << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;


void solve(long long N, long long K, std::vector<long long> H){
	sort(H.begin(),H.end());
	if(N<=K){
		cout << 0 << endl;
		return;
	}

	LL ret=0;
	for(int i=0;i<N-K;i++){
		ret+=H[i];
	}
	cout << ret << endl;

}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> H(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&H[i]);
    }
    solve(N, K, std::move(H));
    return 0;
}


Measured memory_bytes: 1792
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

L = input()
n = len(L)

cnt_1 = list(accumulate(map(int, list(L))))

ans = pow(2, cnt_1[-1], mod)
for i in range(n):
	if L[i] == "1":
		ans += pow(2, cnt_1[i]-1, mod) * pow(3, n-i-1, mod) % mod
		ans %= mod

print(ans)



Measured memory_bytes: 15292
#include <cstdio>
using namespace std;

#define lo(n,m) for(int i=n; i<m; i++)

int main(){
  int a[3],j=0,k=0;

  lo(0,3){
    if (scanf("%d",&a[i]) !=1 ){
      printf("None.\n");
    }
  }

  lo(0,3){
    if ( a[i] == 5){
      j++;
    }else if(a[i] == 7){
      k++;
    }
  }

  if ( j == 2 && k == 1){
    printf("YES\n");
  }else{
    printf("NO\n");
  }
  

  
  

  return 0;
}

  



Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
#define MOD 1000000007
int main(){
  int n;
  cin >> n;
  ll ans = 1;
  for(int i = 0; i < n; i++){
    ans *= (i + 1);
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

//#define DEBUG
#ifdef DEBUG
#define debug_printf printf
#else
#define debug_printf 1 ? 0 : printf
#endif

using namespace std;
typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;

#define INF   (1e9 + 7)
#define MAX_N (100)


ll N, W;
ll X[MAX_N], Y[MAX_N];

void solve() {
  map<ll, ll> dp[2];
  dp[0][0] = 0;
  for (int i = 0; i < N; i++) {
    int x = i % 2;
    int y = (i + 1) % 2;
    dp[y].clear();
    for (auto wv : dp[x]) {
      ll w = wv.first;
      ll v = wv.second;
      debug_printf("%lld:%lld ", w, v);
      dp[y][w] = max(v, dp[y][w]);
      if (w + X[i] <= W){
        dp[y][w + X[i]] = max(v + Y[i], dp[y][w + X[i]]);
      }
    }
    debug_printf("\n");
  }

  ll ans = 0;
  for (auto wv : dp[N % 2]) {
    if (wv.first <= W) {
      ans = max(ans, wv.second);
      debug_printf("%lld:%lld ", wv.first, wv.second);
    }
  }
  debug_printf("\n");

  cout << ans << endl;
}

int main() {
  cin >> N >> W;
  for (int i = 0; i < N; i++) cin >> X[i] >> Y[i];

  solve();

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
//vector<vector<int>> a(5, vector<int>(5, 0)) 5*5-0
int main(){
    int k;
    string s;
    string p = "...";
    cin >> k >> s;
    if(s.length() > k){
        s = s.substr(0, k);
        s = s + p;
        cout << s << endl;
    }else{
        cout << s << endl;
    }
}

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  int n = 0;
  cin >> n;
  map<int,int> count;
  for(int i = 0;i < n;i++){
    int num = 0;
    cin >> num;
    count[num]++;
  }
  int res = 0;
  for(auto& item:count){
    if(item.second % 2 == 1)res++;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
#define fbo find_by_order
#define ook order_of_key

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 122)return char(x-32);
    if( 65 <= int(x) && int(x) <= 90)return x;
    return -1;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 122)return x;
    if( 65 <= int(x) && int(x) <= 90)return char(x+32);
    return -1;
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    if( 97 <= int(x) && int(x) <= 122)return int(x-96);
    if( 65 <= int(x) && int(x) <= 90)return int(x-64);
    return -1;
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll quickpow (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = quickpow (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template
int n,ans;
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>n;
    ans = n/2;
    if(n%2) ans++;
    cout<<ans<<newl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define srt(x) sort((x).begin(), (x).end());
#define rsrt(x) sort((x).rbegin(), (x).rend());
#define deb(x) cout<<#x<<" = "<<(x)<<" (L"<<LINE<<")"<<endl;
#define vdeb(x) {cout<<#x<<" = { "; rep(i, x.size()) cout<<x[i]<<' '; cout <<'}'<<" (L"<<LINE<<")"<<endl;}
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vivi = vector<vi>;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vs = vector<string>;
using um = unordered_map<long long, long long>;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;

vector<vector<bool> > puttable(8, vector<bool>(8, true));
vllvll hist(8, vll(8, 0));

void put(ll row, ll col)
{
    rep(i, 0, 8) {
        puttable[row][i] = false;
        puttable[i][col] = false;
    }
    ll p = row, q = col;
    while (p < 8 and q < 8) {
        puttable[p][q] = false;
        ++p; ++q;
    }
    p = row; q = col;
    while (p >= 0 and q >= 0) {
        puttable[p][q] = false;
        --p; --q;
    }
    p = row; q = col;
    while (0 <= p and p < 8 and 0 <= q and q < 8) {
        puttable[p][q] = false;
        ++p; --q;
    }
    p = row; q = col;
    while (0 <= p and p < 8 and 0 <= q and q < 8) {
        puttable[p][q] = false;
        --p; ++q;
    }
}

pair<ll, ll> getpos()
{
    rep(i, 0, 8) {
        rep(j, 0, 8) {
            if (puttable[i][j] == true) {
                return pair<ll, ll>(i, j);
            }
        }
    }
    return pair<ll, ll>(INF, INF);
}

int main()
{
    ll k; 
    cin >> k;
    vll r(k), c(k);
    rep(i, 0, k) {
        cin >> r[i] >> c[i];
    }

    rep(i, 0, k) {
        put(r[i], c[i]);
        hist[r[i]][c[i]] = 1;
    }

    vll per(8);
    rep(i, 0, 8) {
        per[i] = i;
    }

    vllvll ans(8, vll(8, -1));

    do {
        bool flg = true;
        rep(i, 0, k) {
            if (c[i] != per[r[i]]) {
                flg = false;
            }
        }
        if (flg == false) continue;

        rep(i, 0, 8) rep(j, 0, 8) {hist[i][j] = 0; puttable[i][j] = true;}

        ll cnt = 0;
        rep(i, 0, 8) {
            if (puttable[i][per[i]]) {
                put(i, per[i]);
                hist[i][per[i]] = 1;
                ++cnt;
            }
        }
        if (cnt == 8) {
            rep(i, 0, 8) rep(j, 0, 8) ans[i][j] = hist[i][j];
            break;
        }
    } while (next_permutation(per.begin(), per.end()));

/*
    rep(i, 0, 8-k) {
        auto pos = getpos();
        if (pos.first != INF) {
            put(pos.first, pos.second);
            hist[pos.first][pos.second] = 1;
        }
    }

    put(4, 4);
*/
    rep(i, 0, 8) {
        rep(j, 0, 8) {
            if (hist[i][j] == 0)
                cout << '.';
            else
                cout << 'Q';
        }
        cout << endl;
    }
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 1; i < (n+1); i++)
using namespace std;
using ll = long long;
using P = pair <int, int>;

int gcd(int a, int b){
  int temp;

  if( a < b ) { temp = a; a = b; b = temp; }
  if( b < 1 ) return -1;

  if( a % b == 0 ) return b;
  return gcd( b, a % b );
}


int main() {
  int K;
  cin >> K;

  int ans = 0;

  rep(i, K){
    rep(j, K){
      rep(k, K){
        ans += gcd(gcd(i, j), k);
      }
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> f(int N, const vector<vector<ll>>& xx, int pp) {
	vector<int> idx;
	for (int i = 0; i < N; ++ i) if ((pp>>i)&1) idx.push_back(i);
	int n = idx.size();
	vector<ll> res(n+1, 1LL<<62);
	for (int p = 0; p < (1<<n); ++ p) {
		int cnt = __builtin_popcount(p);
		int q = 0;
		for (int i = 0; i < n; ++ i) if ((p>>i)&1) q |= 1<<idx[i];
		ll d = 0;
		for (int i : idx) {
			d += xx[i][q];
		}
		res[cnt] = min(res[cnt], d);
	}
	return res;
}
ll g(const vector<ll>& x, int pp, int i) {
	ll dd = abs(x[i]);
	for (unsigned j = 0; j < x.size(); ++ j) if ((pp>>j)&1) {
		dd = min(dd, abs(x[i]-x[j]));
	}
	return dd;
}
int main() {
	int N;
	cin >> N;
	vector<ll> X(N), Y(N), P(N);
	for (int i = 0; i < N; ++ i) cin >> X[i] >> Y[i] >> P[i];
	vector<vector<ll>> xx(N, vector<ll>(1<<N)), yy(N, vector<ll>(1<<N));
	for (int i = 0; i < N; ++ i) {
		for (int p = 0; p < (1<<N); ++ p) {
			xx[i][p] = g(X, p, i) * P[i];
			yy[i][p] = g(Y, p, i) * P[i];
		}
	}
	vector<ll> ans(N+1, 1LL<<62);
	for (int p = 0; p < (1<<N); ++ p) {
		auto ax = f(N, xx, p);
		auto ay = f(N, yy, ((1<<N)-1)&~p);
		for (int i = 0; i < (int)ax.size(); ++ i) {
			for (int j = 0; j < (int)ay.size() && i+j <= N; ++ j) {
				ans[i+j] = min(ans[i+j], ax[i] + ay[j]);
			}
		}
	}
	for (auto x : ans) cout << x << endl;
}


Measured memory_bytes: 11264
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int H = in.nextInt();
            int W = in.nextInt();
            char[][] a = new char[H][W];
            for (int r = 0; r < H; r++) {
                a[r] = in.next().toCharArray();
            }

            char[][] b = new char[H + 2][W + 2];
            for (int r = 0; r < b.length; r++) {
                for (int c = 0; c < b[r].length; c++) {
                    b[r][c] = '#';
                }
            }
            for (int r = 0; r < a.length; r++) {
                for (int c = 0; c < a[r].length; c++) {
                    b[r + 1][c + 1] = a[r][c];
                }
            }

            StringBuilder res = new StringBuilder();
            for (int r = 0; r < b.length; r++) {
                for (int c = 0; c < b[r].length; c++) {
                    res.append(b[r][c]);
                }
                res.append("\n");
            }

            System.out.println(res.toString());
        }
    }
}


Measured memory_bytes: 30100
#include <bits/stdc++.h>
using namespace std;

//g++ -g -o yourexe yourfile.cpp
//./yourexe < yourinput.in > youroutput.out

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 201

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast
    ll a, b;
    cin >> a >> b;
    if (a <= 9 && b <= 9)
        cout << a*b << endl;
    else
        cout << -1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  string a="CODEFESTIVAL2016";
  int ans=0;
  for(int i=0;i<S.size();i++){
    if(S[i]!=a[i]){ans++;}
  }
  cout << ans << endl;
}

Measured memory_bytes: 256