akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
int N,M;
int total;
int mask[2000],cost[2000],memo[1005][10000];
int dp(int key, int treasures){

    if (key == M){
        if(treasures == total) return 0;
        else return 1e9;
    }
    
    if(memo[key][treasures] != -1) return memo[key][treasures];

    int a = dp(key+1, treasures | mask[key]) + cost[key];
    
    int b = dp(key+1, treasures);
    
    int ans = min(a,b);
    memo[key][treasures] = ans;
    
    return ans;
}
int main() {
    int n,m,i,j;
    cin>>n>>m;
    N=n;M=m;
    memset(memo,-1,sizeof(memo));
    for(i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        int sum=0;
        for(j=0;j<b;j++){
            int x;
            cin>>x;
            x--;
            sum+=(1<<x);
        }
        mask[i]=sum;
        cost[i]=a;
        //cout<<sum<<' ';
    }
    total=pow(2,N)-1;
    int ans=dp(0,0);
    
    ans = (ans!=1e9) ? ans : -1;
    cout<<ans;
}

Measured memory_bytes: 39552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
  ll n;
  cin >> n;
  vector<ll> a(n + 1);
  for (ll i = 0; i < n + 1; i++)
  {
    cin >> a[i];
  }
  ll ans = 0;
  for (ll i = 0; i < n; i++)
  {
    ll b = 0;
    cin >> b;
    if (a[i] >= b)
    {
      ans += b;
    }
    else
    {
      ans += a[i];
      if (a[i + 1] > b - a[i])
      {
        ans += b - a[i];
        a[i + 1] -= b - a[i];
      }
      else
      {
        ans += a[i + 1];
        a[i + 1] = 0;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3972
#include <iostream>
using namespace std;
int main(){
	int N,s[100],ans=0,b=0;
	int k=0,q=0;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>s[i];
	}
	for(int i=0;i<N;i++){
		ans+=s[i];
	}
	for(int i=0;i<N;i++){
		if(s[i]%10==0){
			b=b+1;
		}
		if(b==N){
			cout<<0<<endl;
			q=1;
		}
	}
	if(ans%10==0 && q==0){
		for(int i=0;i<N;i++){
			if(k<ans-s[i] && s[i]%10!=0)k=ans-s[i];	
		}
		cout<<k<<endl;
	}
	if(ans%10!=0 && q==0){
		cout<<ans<<endl;
	}
	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int X = nextInt();
  int t = nextInt();
  cout << max(0, X - t) << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
#define EPS (1e-10)

struct Point{
  double x,y;
  Point(){};
  Point(double x,double y):x(x),y(y){}
  Point operator+(Point p){return Point(x+p.x, y+p.y);}
  Point operator-(Point p){return Point(x-p.x, y-p.y);}
  Point operator*(double k){return Point(x*k,y*k);}
  Point operator/(double k){return Point(x/k,y/k);}
  double norm(){return x*x + y*y;}
  double abs(){return sqrt(norm());}
};

struct Segment{
  Point p1,p2;
  Segment(){};
  Segment(Point p1,Point p2):p1(p1),p2(p2){}
};
typedef Segment Line;
typedef vector<Point> Polygon;

typedef Point Vector;
double dot(Vector a,Vector b){return a.x * b.x + a.y * b.y;}
double cross(Vector a,Vector b){return a.x * b.y - a.y * b.x;}
double norm(Vector a){return a.x * a.x + a.y * a.y;}
double abs(Vector a){return sqrt(norm(a));}

double getDistanceLP(Line l,Point p){
  return abs(cross(l.p2 - l.p1, p - l.p1) / abs(l.p2 - l.p1));
}

double getDistanceSP(Segment s,Point p){
  if(dot(s.p2 - s.p1, p-s.p1) < 0.0) return abs(p-s.p1);
  if(dot(s.p1 - s.p2, p-s.p2) < 0.0) return abs(p-s.p2);
  return getDistanceLP(s,p);
}

istream& operator>>(istream &is,Point& p){
  is>>p.x>>p.y;
  return is;
}

signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n;
  cin>>n;
  vector<Polygon> s(2,Polygon(n));
  double r[n];
  for(Int i=0;i<n;i++){
    cin>>r[i]>>s[0][i]>>s[1][i];
  }
  vector<Int> dp(1<<16,0);
  dp[0]=1;
  Int ans=0;
  for(Int b=0;b<(1<<n);b++){
    if(!dp[b]) continue;
    //cout<<b<<endl;
    ans=max(ans,Int(__builtin_popcount(b)));
    for(Int i=0;i<n;i++){
      if((b>>i)&1) continue;
      bool f=1;
      for(Int j=0;j<n;j++){
	if(i==j) continue;
	double d=getDistanceSP(Segment(s[0][i],s[1][i]),s[(b>>j)&1][j]);
	if(0){
	  cout<<i<<" "<<j<<":"<<r[i]+r[j]<<" "<<d<<endl;
	  cout<<s[0][i].x<<" "<<s[0][i].y<<endl;
	  cout<<s[1][i].x<<" "<<s[1][i].y<<endl;
	  cout<<s[0][j].x<<" "<<s[0][j].y<<endl;
	  cout<<s[1][j].x<<" "<<s[1][j].y<<endl;
	}
	f&=(r[i]+r[j]<d+EPS);
      }
      Int nb=b|(1<<i);
      dp[nb]|=f;
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3484
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		sc.close();
		//一回の実行にかかる時間
		int s = 1900*m + 100*(n-m);
		//全て成功する確率
		double p = 1/Math.pow(2, m);
		/**
		i回目に成功する確率pi
		double pi = Math.pow(1-p,i-1)*p
		i回目で成功する期待値
		double e = i*s*pi
		**/
		
		double te = s/p;
		
		
		
		System.out.println((int)te);
	}
	

}


Measured memory_bytes: 21844
#include<cstdio>
#include<algorithm>
using namespace std;
long long ans=0;
long long dfs(long long a,long long b)
{
	if (b==0) return ans-=a;
	ans+=a/b*b*2;
	return dfs(b,a%b);
}
int main()
{
	long long n,m;
	scanf("%lld%lld",&n,&m);
	ans+=n;
	n=n-m;
	if (n<m) swap(n,m);
	dfs(n,m);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include <cassert>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int>VI;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define fi first
#define se second
#define MAX 100100//5
#define MAX_N 200100
#define MAX_B 1001001//6
#define MAX_S 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MOD 1000000007
#define INF 1 << 29
#define INFTY 1000000000000000000LL
#define MAX_INT INT_MAX

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


int main(){
    int n,m;cin>>n>>m;
    int a[MAX],b[MAX],c[MAX];rep(i,n)cin>>a[i];
    sort(a,a+n);
    rep(i,m)cin>>b[i]>>c[i];
    vector<P>x(m);
    rep(i,m)x[i]=P(c[i],b[i]);
    sort(ALL(x),greater<P>());
    int j=0;
    rep(i,n){
        if(a[i]<x[j].fi){
            a[i]=x[j].fi;
            x[j].se--;
        }
        if(x[j].se<=0){
            j++;
        }
        if(j==m)break;
    }
    ll ans=0;
    rep(i,n){ans+=a[i];}
    cout<<ans<<endl;
    
    
    
}

Measured memory_bytes: 2176
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n;
    cin >> n;

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }

    ll flag = 1;
    ll ans = 0;
    while(flag){
        vl b(n);
        flag = 0;
        ll cnt = 0;
        rep(i, n) {
            cnt += a[i]/n;
            b[i] = a[i]/n;
            a[i] %= n;
        }
        rep(i, n) {
            a[i] += cnt - b[i];
            if(a[i] >= n) {
                flag = 1;
            } 
        }
        ans += cnt;
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 256
n,t = (int(i) for i in input().split())
ni = [int(i) for i in input().split()]

total = 0

for i in range(1,len(ni)) :
  delta = ni[i] - ni[i-1]
  if delta < t :
    total += delta
  else :
    total += t

    
print(total+t)

Measured memory_bytes: 25200
Q = 10**9 + 7
def getInv(N):#Qはmod
    inv = [0] * (N + 1)
    inv[0] = 1
    inv[1] = 1
    for i in range(2, N + 1):
        inv[i] = (-(Q // i) * inv[Q%i]) % Q
    return inv
modfunctional = [1]*(10**5+2)
modinv = getInv(10**5+2)
modinvfunctional = [1]*(10**5+2)
for i in range(10**5+1):
    modinvfunctional[i+1] = (modinvfunctional[i]*modinv[i+1])%Q
for i in range(10**5+1):
    modfunctional[i+1] = (modfunctional[i]*(i+1))%Q

n = int( input())
A = list( map( int, input().split()))
V = [0 for _ in range(n+1)]
for i in range(n+1):
    if V[A[i]] == 1:
        b = A[i]
        break
    V[A[i]] = 1
b_1 = -1
for i in range(n+1):
    if A[i] == b:
        if b_1 == -1:
            b_1 = i
        else:
            b_2 = i
            break
d = b_1 + n - b_2
for k in range(1, n+2):
    if k-1 > d:
        print(((modfunctional[n+1]*modinvfunctional[k])*modinvfunctional[n+1-k])%Q)
    else:
        print( (modfunctional[n+1]*modinvfunctional[k]%Q*modinvfunctional[n+1-k]%Q - modfunctional[d]*modinvfunctional[k-1]%Q*modinvfunctional[d-k+1]%Q)%Q)

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

int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    string S;
    cin >> S;
    for (int i = 0; i < n; i++)
        A[i] =  S[i] - '0';
    for (int i = 0; i < n - 1; i++)
        A[i] = abs(A[i] - A[i + 1]);
    n--;
    A.erase(A.begin() + n, A.end());

    auto f = [&](){
        int b = 0;
        for (int i = 0; i < n; i++){
            b ^= (A[i] & 1) & (((n - 1) & i) == i);
        }
        return b;
    };

    if (f() == 1){
        puts("1");
        return 0;
    }

    if (any_of(A.begin(), A.end(), [](const auto &a){return a == 1;})){
        puts("0");
        return 0;
    }

    for (auto &a: A)
        a >>= 1;

    puts(f() == 1 ? "2" : "0");
}


Measured memory_bytes: 5252
fn main() {
    let n: usize = read();
    let mut mx = 0i32;
    let mut mn = 10001i32;
    for _i in 0..n {
        let a: i32 = read();
        mx = max(mx, a);
        mn = min(mn, a);
    }
    let ans = mx - mn;
    println!("{}", ans);
}

// 以下関数


use std::io::*;
use std::str::FromStr;
pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub const MOD: u64 = 1_000_000_007;

pub fn is_prime(n: i32) -> bool {
    if n < 2 {
        return false;
    } else if n == 2 {
        return true;
    }
    let mut i = 2;
    while i * i < n {
        if n % i == 0 {
            return false;
        } else {
            i += 1;
            continue;
        }
    }
    true
}

pub fn lcm(mut n: i32, mut m: i32) -> i32 {
    n = if n > m { m } else { n };
    m = if n > m { n } else { m };
    let mut i = n;
    while i % m != 0 {
        i += n;
    }
    i
}

pub fn abs(n: i32) -> i32 {
    if n >= 0 {
        n
    } else {
        -n
    }
}

pub fn max(n: i32, m: i32) -> i32 {
    if n >= m {
        n
    } else {
        m
    }
}

pub fn min(n: i32, m: i32) -> i32 {
    if n <= m {
        n
    } else {
        m
    }
}

pub fn factorial(n: u32) -> u32 {
    if n == 0 {
        return 1
    }
    let mut r = n;
    for i in 0..n-1{
        r *= n-i-1;
    }
    r
}

pub fn combination(n: u32, m: u32) -> u32 {
    factorial(n) / factorial(m) / factorial(n-m)
}

Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <map>
#include <set>

using namespace std;

int get_root(vector<int>& tree, int a){
	if(tree[a]==a) return a;
	int r=get_root(tree, tree[a]);
	tree[a]=r;
	return r;
}

int append(vector<int>& tree, int a, int b){
	int ra=get_root(tree, a);
	int rb=get_root(tree, b);
	tree[ra]=rb;
	return ra;
}

int main(){
	int n, k, l;
	cin >> n >> k >> l;
	vector<int> tree_k(n);
	vector<int> tree_l(n);
	for(int i=0; i<n; ++i) tree_k[i]=tree_l[i]=i;
	for(int i=0; i<k; ++i){
		int p, q;
		cin >> p >> q;
		append(tree_k, p-1, q-1);
	}
	for(int i=0; i<l; ++i){
		int r, s;
		cin >> r >> s;
		append(tree_l, r-1, s-1);
	}
	map<pair<int, int>, set<int>> group;
	for(int i=0; i<n; ++i){
		group[make_pair(get_root(tree_k, i), get_root(tree_l, i))].insert(i);
	}
	vector<int> result(n, 0);
	for(auto& p : group){
		int num=p.second.size();
		for(auto& i : p.second){
			result[i]=num;
		}
	}
	for(int i=0; i<n; ++i){
		if(i) cout << " ";
		cout << result[i];
	}
	cout << "\n";
	return 0;
}


Measured memory_bytes: 29056
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string s;
	cin >> s;
	
	bool ret = true;
	for (int i = s.length() - 1; i > 0; i--) {
		if (i % 2 == 0) {
			ret = true;

			for (int j = 0; j < i / 2; j++) {
				if (s[j] != s[i / 2 + j]) {
					ret = false;
				}
			}

			if (ret) {
				cout << i << endl;

				return 0;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#define P pair<int,string>
using namespace std;

int main()
{
	int a, b;
	while (cin >> b>>a, a | b) {
		int c[100]{};
		for (int d = 0; d < a; d++) {
			char e; cin >> e;
			if (e == 's') {
				int f, g; cin >> f >> g; f++;
				int s = 0;
				for (int i = 0; i < b; i++) {
					if (c[i] == 0) {
						s++; 
						if (s >= g) {
							cout << i - s + 1 << endl;
							for (int o = i-s+1; o <= i; o++)c[o] = f;
							break;
						}
					}
					else s = 0;
					if(b-1==i)puts("impossible");
				}
			}
			else {
				int f; cin >> f; f++;
				for (int i = 0; i < b; i++) {
					if (c[i] == f)c[i] = 0;
				}
			}
		}
		puts("END");
	}
}

Measured memory_bytes: 3064
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**6+10
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

r1, c1, r2, c2 = map(int, input().split())

def g(r, c):
  return cmb(r+c+2,c+1,mod)-1

ans = g(r2,c2)-g(r2,c1-1)-g(r1-1,c2)+g(r1-1,c1-1)
print(ans%mod)


Measured memory_bytes: 132908
#include<stdio.h>
#include<string.h>
int main(){
	int i,j,k,l,c,n;
	char s[40][10][30];
	int e[6]={0,2,4,1,3,5};
	int d[30][6]={
		{0,1,2,3,4,5},
		{1,2,0,5,3,4},
		{2,1,5,0,4,3},
		{3,1,0,5,4,2},
		{4,3,0,5,2,1},
		{5,1,3,2,4,0},
	};
	for(i=0;i<6;i++){
		for(j=0;j<6;j++)d[20-i*4][j]=d[5-i][j];
	}
	for(i=0;i<6;i++){
		for(j=0;j<3;j++){
			for(k=0;k<6;k++)d[i*4+j+1][k]=d[i*4+j][e[k]];
		}
	}
	while(scanf("%d",&n),n){
		for(i=c=0;i<n;i++){
			for(j=0;j<6;j++)scanf("%s",s[i][j]);
		}
		for(i=0;i<n;i++){
			for(j=i+1;j<n;j++){
				for(k=0;k<24;k++){
					for(l=0;l<6;l++){
						if(strcmp(s[i][l],s[j][d[k][l]]))goto NEXT;
					}
					c++;
					goto END;
					NEXT:;
				}
			}
			END:;
		}
		printf("%d\n",c);
	}
	return 0;
}

Measured memory_bytes: 624
# import sys
# sys.setrecursionlimit(10 ** 6)
# # input = sys.stdin.readline    ####
# def int1(x): return int(x) - 1
def II(): return int(input())

# def MI(): return map(int, input().split())
# def MI1(): return map(int1, input().split())
#
# def LI(): return list(map(int, input().split()))
# def LI1(): return list(map(int1, input().split()))
# def LLI(rows_number): return [LI() for _ in range(rows_number)]
#
# def SI(): return input().split()
#
# def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
# INF = float('inf')
#
# from math import ceil, floor, log2, sqrt
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product
# from heapq import heapify, heappop, heappush

def is_prime(n):
    for i in range(2, int(pow(n, 0.5))+1):
        if n % i == 0:
            return False

    return True


def solve():
    X = II()

    while 1:
        if is_prime(X):
            print(X)
            return

        X += 1



if __name__ == '__main__':
    solve()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
const int INFTY =2147483647;

int L[200000],R[200000];

void merge(int A[],int left,int mid,int right){
    int n1=mid-left;
    int n2=right-mid;
    for(int i=0;i<n1;i++) L[i]=A[left+i];
    for(int i=0;i<n2;i++) R[i]=A[mid+i];
    L[n1] =R[n2]=INFTY;
    int i=0,j=0;
    for(int p=left;p<right;p++){
        if(L[i]<=R[j]) A[p]=L[i++];
        else A[p]=R[j++];
    }
}

void sort(int A[],int left,int right){
    if(left+1<right){
        int mid=(left + right)/2;
        sort(A,left,mid);
        sort(A,mid,right);
        merge(A,left,mid,right);
    }
}

//sort(A,0,n)で使用
int main(){
    int n,k,ans=0;
    int A[1005];
    cin>>n>>k;
    REP(i,n) cin>>A[i];
    sort(A,0,n);
    REP(i,k) ans+=A[i];
    cout<<ans<<endl;
}

Measured memory_bytes: 3616
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
typedef long long i64;
int A, B, C; i64 k;
int main()
{
    scanf("%d%d%d%lld", &A, &B, &C, &k);
    if(~k&1) printf("%d\n", A-B); else printf("%d\n", B-A);
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N, 0);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  
  int ans = 0;
  for (int i = N; i > 0; i--) {
    if (2 * i > N) {
      B.at(i - 1) = A.at(i - 1);
      ans += A.at(i - 1);
    }
    else {
      int X = 0;
      for (int j = 2; i * j <= N; j++) X += B.at(i * j - 1);
      if (X % 2 != A.at(i - 1)) {
        B.at(i - 1) = 1;
        ans++;
      }
    }
  }
  cout << ans << endl;
  if (ans != 0) {
    for (int i = 0; i < N; i++) {
      if (B.at(i) == 1) cout << i + 1 << " ";
    }
    cout << endl;
  }
}

Measured memory_bytes: 2432
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<n; i++){
			a[i] = sc.nextInt();
		}
		sc.close();
		
		int ans = (int) Math.pow(3, n);
		int num = 1;
		for(int i=0; i<n; i++){
			if(a[i]%2 == 0){
				num*=2;
			}
		}
		System.out.println(ans- num);
		
	}
}


Measured memory_bytes: 25044
line = gets.split(' ').map(&:to_i)

thp = line[0]
tat = line[1]
ahp = line[2]
aat = line[3]
 
for i in 1..1000 do
  ahp -= tat
  if ahp <= 0 then
    print "Yes"
    break
  end
  thp -= aat
  if thp <= 0 then
    print "No"
    break
  end
end

Measured memory_bytes: 14288
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<
//        pair<long long, int>, // change type
//        null_type,
//        less<pair<long long, int> >, // change type
//        rb_tree_tag,
//        tree_order_statistics_node_update>
//        ordered_set;

//template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;


vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)

typedef long long ll;
#define rep(i, start, end) for(int i = start; i < end; ++i)
#define sz(x) (int)((x).size())
#define pb push_back
#define all(x) x.begin(), x.end()
#define clr(d, v) memset(d, v, sizeof(d))
#define pii pair<int, int>
//#define debug(x) cerr << #x << " : " << (x) << " "
const double PI = 3.14159265358979323846;
const double eps = (1e-8);
int isGreater(long double x, long double y)
{
    if (abs(x - y) < eps)
        return 0;
    if (x > y)
        return 1;
    return -1;
}

int n;
const int MAX_N = 505;
int dist[MAX_N][MAX_N], isDanger[MAX_N][MAX_N];
int di[] = {-1, 1, 0, 0};
int dj[] = {0, 0, -1, 1};

bool valid(int i, int j)
{
    return i >= 0 && j >= 0 && i < n && j < n;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    rep(i,0,n)
    {
        rep(j,0,n)
        {
            dist[i][j] = min(min(i, n - i - 1), min(j, n - j - 1));
            isDanger[i][j] = 1;
        }
    }

    int ans = 0;
    vector<pair<int, int> > q;
    q.reserve(n * n);
    rep(k,0,n * n)
    {
        int x;
        cin >> x;
        --x;
        int i = x/n, j = x%n;
        ans += dist[i][j];
        isDanger[i][j] = 0;
        q.push_back({i, j});
        while(!q.empty())
        {
            auto u = q.back();
            int ci = u.first, cj = u.second;
            q.pop_back();
            rep(mv,0,4)
            {
                int ni = ci + di[mv], nj = cj + dj[mv];
                if (valid(ni, nj) && dist[ni][nj] > dist[ci][cj] + isDanger[ci][cj])
                {
                    dist[ni][nj] = dist[ci][cj] + isDanger[ci][cj];
                    q.push_back({ni, nj});
                }
            }
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 5988
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main{

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] token = br.readLine().split(" ");
		int a_col = Integer.parseInt(token[0]);
		int a_row = Integer.parseInt(token[1]);
		int b_col = a_row;
		int[][] a = new int[a_col][a_row];
		int[] b = new int[b_col];

		for(int i = 0; i < a_col; i++){

			token = br.readLine().split(" ");

			for(int j = 0; j < a_row; j++){
				a[i][j] = Integer.parseInt(token[j]);
			}

		}

		for(int i = 0; i < b_col; i++){
			b[i] = Integer.parseInt(br.readLine());
		}

		for(int i = 0; i < a_col; i++){

			int sum = 0;

			for(int j = 0; j < a_row; j++){
				sum += a[i][j] * b[j];
			}

			System.out.println(sum);

		}

	}
}

Measured memory_bytes: 27540
const MAX_SUM: usize = 51 * 51;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn solve(x: &[u32], a: u32) -> u64 {
    let a = a as usize;
    let len = x.len();
    let mut dp = vec![vec![vec![0; MAX_SUM]; len + 1]; len + 1];
    dp[0][0][0] = 1;
    for i in 1..len + 1 {
        for j in 0..i + 1 {
            for k in 0..MAX_SUM {
                let next = if x[i - 1] as usize > k {
                    dp[i - 1][j][k]
                } else if j > 0 {
                    dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i - 1] as usize]
                } else {
                    0
                };
                dp[i][j][k] = next;
            }
        }
    }
    let mut result = 0;
    for k in 1..len + 1 {
        result += dp[len][k][k * a];
    }
    result
}

fn main() {
    input!(n: u32, a: u32, x: [u32; n]);
    println!("{}", solve(&x, a));
}


Measured memory_bytes: 78076
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
    ll N, A, B;
    cin >> N >> A >> B;
    vector<ll> X(N);
    for(int i=0; i<N; i++) cin >> X[i];

    ll ans = 0;
    for(int i=1; i<N; i++){
        ans += min(B, A*(X[i]-X[i-1]));
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int N,K; cin >> N >> K;
  vector<int> child(N);
  int tmp,d,ans=0;
  REP(i,K){
    cin >> d;
    REP(j,d){
      cin >> tmp;
      child[tmp-1]++;
    }
  }
  REP(i,N){
    if(child[i] == 0)
      ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3620
while 1:
    n=raw_input()
    if n=="0000": break
    if int(n)%1111==0:
        print "NA"
        continue
    ans = 0
    while n!="6174":
        n="".join(sorted(n))
        n=str(int(n[::-1])-int(n)).zfill(4)
        ans+=1
    print ans

Measured memory_bytes: 4208
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pdbs;
using namespace std;

// typedef tree<int, null_type, less<int>, rb_tree_tag,  
//             tree_order_statistics_node_update>  
//     ordered_set;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define eb emplace_back
#define sf(x) sizeof(x)
#define len(x) x.length()
#define sz(x) x.size()
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define LB(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define UB(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef unsigned long long ull;
typedef long double ld; 
typedef tuple<int,int,int> State;

ll mod = 1e9 + 7;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
#define citc(tc) int tc; cin>>tc; while(tc--) 
#define each(a,x) for( auto &a:(x))
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (ll i = (l); i < (r); i++)
#define rep2r(i, l, r) for (ll i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()
#define deb(x) cout<<#x<<" "<<x<<endl;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cinll2(l, z) ll l, z; cin>>l>>z;
#define cinll3(l, z, x) ll l, z, x; cin>>l>>z>>x;
#define cinai(a, n) vi a(n); rep(i, n) { cin>>a[i]; }
#define cinal(a, n) vl a(n); rep(i, n) { cin>>a[i]; }
#define coutai(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define coutal(a, n) rep(i, n) { cout<<a[i]<<" "; } ent;
#define ent cout<<endl;
#define resize_vec(a) a.resize(unique(a.begin(), a.end()) - a.begin());
#define ms(dp, x) memset(dp, x, sf(dp))


// const long long MAX_SIZE = 1000000; 
// vector<long long >isprime(MAX_SIZE , true); 
// vector<long long >prime; 
// vector<long long >SPF(MAX_SIZE); 
  
// // function generate all prime number less then N in O(n) 
// void manipulated_seive(ll N) 
// { 
//     isprime[0] = isprime[1] = false ;  
//     for (ll i=2; i<N ; i++) 
//     {  
//         if (isprime[i]) 
//         { 
//             prime.push_back(i); 
//             SPF[i] = i; 
//         } 
//         for (ll j=0;j < prime.size() && i*prime[j] < N && prime[j] <= SPF[i];j++) 
//         { 
//             isprime[i*prime[j]]=false; 
//             SPF[i*prime[j]] = prime[j] ; 
//         } 
//     } 
// } 


ll powm(ll a, ll b, ll mod) {
	ll res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
bool sortinrev(const pair<int,int> &a, const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
} 

void solve()
{
	ll n;
	cin>>n;
	map<string ,ll> m;
	string s;
	rep(i, n)
		cin>>s, m[s] = 1;
	cout<<m.size()<<endl;
}
int main()
{
	fastio();
	// citc(tc)
		solve();
}


Measured memory_bytes: 19280
n=int(input())
task=[tuple(map(int,input().split())) for _ in range(n)]

task=sorted(task,key=lambda x:x[1])

t=0
for i in range(n):
  t+=task[i][0]
  if t>task[i][1]:
    print('No')
    exit()

print('Yes')

Measured memory_bytes: 34304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int INF = 1e9;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  int H, W, K;
  cin >> H >> W >> K;
  vector<vector<int>> c(H + 2, vector<int>(W + 2));
  vector<vector<int>> d(H + 2, vector<int>(W + 2, INF));

  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  for (int i = 1; i <= H; i++) {
    string s;
    cin >> s;
    for (int j = 1; j <= W; j++) {
      c[i][j] = (s[j - 1] == '.' ? 1 : 0);
    }
  }

  priority_queue<pair<int, pair<pair<int, int>, int>>,
                 vector<pair<int, pair<pair<int, int>, int>>>,
                 greater<pair<int, pair<pair<int, int>, int>>>>
      que;
  que.push(make_pair(0, make_pair(make_pair(x1, y1), -1)));
  while (!que.empty()) {
    int dist = que.top().first;
    int x = que.top().second.first.first, y = que.top().second.first.second;
    int dir = que.top().second.second;
    que.pop();
    if (x == x2 && y == y2) {
      cout << dist << endl;
      return 0;
    }
    if (dist > d[x][y]) continue;
    for (int i = 0; i < 4; i++) {
      if (i % 2 == dir % 2) continue;
      int ddx = 0, ddy = 0;
      while (true) {
        ddx += dx[i], ddy += dy[i];
        int tmp = (abs(ddx + ddy) + K - 1) / K;
        if (c[x + ddx][y + ddy]) {
          if (d[x + ddx][y + ddy] > dist + tmp) {
            d[x + ddx][y + ddy] = dist + tmp;
            que.push(make_pair(dist + tmp,
                               make_pair(make_pair(x + ddx, y + ddy), i)));
          }
        } else {
          break;
        }
      }
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 48940
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0;i < N;i++)
typedef pair<int,int> Pi;
#define F first
#define S second
int main()
{
  int H,W;
  while(cin >> H >> W,H && W){;
    Pi sum[100];
    Rep(i,100)sum[i] = Pi(0,-i);
    int data;
    Rep(i,H){
      Rep(j,W){
	cin >> data;
	sum[j].F += data;
      }
    }
    sort(sum,sum + W,greater<Pi>());
    Rep(i,W - 1){
      cout << -sum[i].S + 1 << " ";
    }
    cout << -sum[W - 1].S + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    ll N;
    ll sum = 0;
    cin >> N;

    for (int i=1; i<=N; i++) {
        if(i%3!=0 && i%5!=0) {
            sum += i;
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define int long long
#define endre getchar();getchar();return 0
#define INF 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define input() for(int i=0;i<n;i++)cin>>a[i];
#define P pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return (y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int n) {
	if (n == 0)return 1;
	return (kai(n - 1)*n) % INF;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int mystoi(string s) {
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		cnt += (int)(s[i] - '0') * pow(10, s.size() - i - 1);
	}
	return cnt;
}
int n, a[100005], cnt, ma;
signed main() {
	cin >> n;
	input();
	sort(a, a + n);
	rep(i, n) {
		cnt += a[i];
		if (cnt * 2 < a[i + 1])ma = i + 1;
	}
	cout << n - ma << endl;
	endre;
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n, q;
    while (cin >> n >> q && n){
        int a[101] = {};
        REP(i,n){
            int m;
            cin >> m;
            while (m--){
                int x;
                cin >> x;
                a[x]++;
            }
        }
        int ans, ma = 0;
        FOR(i,1,100){
            if (a[i] > ma){
                ans = i;
                ma = a[i];
            }
        }
        cout << (ma >= q ? ans : 0) << endl;
    }
    return 0;
}

Measured memory_bytes: 3044
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////


int main() {

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

	ll ans = 0;

	while (N > 0) {
		ans++;
		N /= K;
	}

	cout << ans;

	
	
	system("PAUSE");

	

}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  sort(a.rbegin(), a.rend());
  int s = accumulate(a.begin(), a.end(), 0);
  if (a.at(m - 1) * 4 * m < s) {
    puts("No");
  } else {
    puts("Yes");
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<cassert>

typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
using std::max;
using std::min;
using std::abs;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 5000000000000;
//typedef std::pair<int, int> P;
struct edge { int to;double cost; };
#define VMAX 1010

     ll N,M,K;
     ll A[200010],B,C;
     ll P[11];
     ll ans;
     char S[100];
int main() {
    cin>>N>>K;
    ll a,b;
    a=abs(N-((N/K)+1)*K);
    b=abs(N-((N/K))*K);
    cout<<min(a,b)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline void myassert(bool a,string s){ if(!a)cerr<<s<<endl,exit(0);}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=1e6+20;
int n,m,k;
int a[maxn<<1],b[maxn<<1];

inline void init()
{
	n=read();m=read();k=read();
	static char str[maxn];
	scanf("%s",str+1); REP(i,1,n)a[i]=str[n-i+1]-'0';
	scanf("%s",str+1); REP(i,1,m)b[i]=str[m-i+1]-'0';
}

#define pii pair<int,int>

inline void doing()
{
	vector<int>st; st.push_back(0x3f3f3f3f);
	DREP(i,max(n,m),1)
	{
		if(a[i]^b[i])st.push_back(i);
		else if(a[i] && b[i])
		{
			int rest=k-1,pos=i+1,x=3;
			a[i]=b[i]=0;
			vector<int>rem;
			while(rest>=0 )
			{
				if(st.back()==pos)
				{
					st.pop_back();
					int v=a[pos]<<1|b[pos]; // v:1~2,x:1~3
					if(x==3)x=v,a[pos]^=1,b[pos]^=1,rem.push_back(pos);
					else if(x==v) (v==2?a[pos]:b[pos])=0;
					else {
						rest--;
						if(rest<0)break;
						a[pos]=b[pos]=0;
						x=3;
					}
					++pos;
				}else
				{
					if(x==3)
					{
						int cha=st.back()-pos;
						if(rest>=cha)rest-=cha,pos=st.back();
						else { pos+=rest; break;}
					}else break;
				}
			}
			if(x&2)a[pos]^=1;
			if(x&1)b[pos]^=1;
			if(a[pos] || b[pos])st.push_back(pos);
			while(!rem.empty())st.push_back(rem.back()),rem.pop_back();
		}
	}
	int na=2e6+2,nb=2e6+2;
	while(!a[na])--na;
	while(!b[nb])--nb;
	DREP(i,na,1)printf("%d",a[i]); puts("");
	DREP(i,nb,1)printf("%d",b[i]); puts("");
}

int main()
{
	init();
	doing();
	return 0;
}


Measured memory_bytes: 20844
def reach?(s,t)
  d = t[0] - s[0]
  l = (t[1] - s[1]).abs + (t[2] - s[2]).abs
  d >= l && (d - l).even? ? t : false 
end

current = [0,0,0]
puts gets.to_i.times.all?{ current = reach?(current,gets.split.map(&:to_i)) } ? 'Yes' : 'No'


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


double maxLiquid(double a, double b, double theta){
    double tanTheta = tan(theta*M_PI/180);
    if(tanTheta < b/a){
        // 水平にちかい
        return a*(2*b - a*tanTheta)*a/2;
    }else{
        return b*b/(2*tanTheta)*a;
    }
}

void solve(long long a, long long b, long long x){
    double bb = 0;
    double u = 90;
    // f(-)は増加。減少なら不等式は>か>=にする。
    while(u - bb > pow(10, -8)){
        double piv = (u + bb)/2;
        if(maxLiquid(a, b, piv) > x){ // 必要なら不等号はとりかえる。とにかく左側がTRUEということにする(右がTRUEなら反転する)
            bb = piv;
        }else{
            u = piv;
        }
    }
    // bはfがK未満(条件が真)の位置のうち一番右、uはfがK以上(条件が偽)の位置のうち一番左
    printf("%.6f\n", bb);
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    long long x;
    scanf("%lld",&x);
    solve(a, b, x);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef struct { double x,y;} point;

double nai(point a,point b){ return a.x*b.x+a.y*b.y; }

int main(){
point p1,p2;
double x,y;
cin>>x>>y;
p1.x=x;
p1.y=y;
cin>>x>>y;
p2.x=x;
p2.y=y;
point vec={p2.x-p1.x , p2.y-p1.y};
point e={vec.x/sqrt(nai(vec,vec)) , vec.y/sqrt(nai(vec,vec))};
int q;
cin>>q;
for(int i=0;i<q;i++){
cin>>x>>y;
point p;
p.x=x-p1.x;
p.y=y-p1.y;
point m;
	m.x=p1.x+nai(p,e)*e.x;
	m.y=p1.y+nai(p,e)*e.y;
point vec2={m.x-x,m.y-y};

printf("%0.9lf %0.9lf\n",x+2*vec2.x,y+2*vec2.y);


}
return 0;
}



Measured memory_bytes: 3292
#include <stdio.h>

int main(){
  int n,i,a[3];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d%d%d",&a[0],&a[1],&a[2]);
    if(a[0]*a[0]+a[1]*a[1] == a[2]*a[2]||
      a[0]*a[0]+a[2]*a[2] == a[1]*a[1] ||    a[2]*a[2]+a[1]*a[1] == a[0]*a[0]) printf("YES\n");
    else printf("NO\n");
  }

  return 0;
}

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

#define clr(a,i) memset((a), (i) ,sizeof(a))

int main(){
  long long n,a,b;
  string s;
  std::cin >> n >> a >> b >> s;
  a+=b;
  rep(i,n){
    if(s[i]=='c') cout << "No" << endl;
    else if(s[i]=='b'&&b>0&&a>0) {
      std::cout << "Yes" << std::endl;
      a--; b--;
    }else if(s[i]=='a'&&a>0){
      std::cout << "Yes" << std::endl;
      a--;
    }else std::cout << "No" << std::endl;
  }
}


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

int main(){
  
   int N,K,x,S;
    
   cin >> N >> K;
  
  S = 0;
  
  for(int i = 0; N > i;i++){
    
  	cin >> x;
    
    if(K  >= 2*x){
      S = S + x;
    }
    
    else{
      S = S + (K-x);
    }
    
  }
  
  
  cout << 2*S << endl;
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long double ll;
struct Edge{
  int s,t;
  ll w;
  Edge(int s,int t,ll w):s(s),t(t),w(w){}
};
const ll INF = 2000000000001LL;
ll dist[1000];
ll dist2[1000];

vector<Edge> E;
int n;
int m;
int main(){
  cin >> n >> m;
  for(int i=0;i<n;++i)
    dist[i]=-INF;

  while(m--){
    int a,b;ll c;
    cin >> a >> b >> c;
    a--;b--;
    E.push_back(Edge(a,b,c));
  }

  dist[0]=0;

  for(int i=0;i<n;++i){
    for(Edge e:E){
      if(dist[e.s]+e.w > dist[e.t]){
	dist[e.t] = dist[e.s]+e.w;
      }
    }
  }

  for(int i=0;i<n;++i)
    dist2[i]=dist[i];

  for(int i=0;i<n;++i){
    for(Edge e:E){
      if(dist2[e.s]+e.w > dist2[e.t]){
	dist2[e.t] = dist2[e.s]+e.w;
      }
    }
  }


  bool inf = false;
  if(dist2[n-1]>dist[n-1])
    inf=true;
  
  if(inf)
    cout << "inf" << endl;
  else
    cout << fixed << setprecision(0) << dist[n-1] << endl;

  return 0;
}


Measured memory_bytes: 384
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy[4] = {-1, 0, +1, 0};
int dx[4] = {0, +1, 0, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

//-----------------------ここから-----------


int main(void){
    int n;
    cin >> n;

    vector<string> w(n);

    for(int i = 0; i < n; i++){
        cin >> w[i];
    }

    bool ok = true;
    for(int i = 1; i < n; i++){
        if(w[i - 1][w[i - 1].size() - 1] != w[i][0]){
            ok = false;
            break;
        }

        for(int j = 0; j < i; j++){
            if(w[i] == w[j]){
                ok = false;
                break;
            }
        }

        if(!ok)break;
    }

    if(ok){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#define ttt template <typename T>
#define pca point<T> const &
ttt struct point { T x, y; };
ttt point<T> operator + (pca a, pca b) { return { a.x+b.x, a.y+b.y }; }
ttt point<T> operator - (pca a, pca b) { return { a.x-b.x, a.y-b.y }; }
ttt point<T> operator - (pca a) { return { -a.x, -a.y }; }
ttt point<T> operator * (T a, pca b) { return { a*b.x, a*b.y }; }
ttt std::pair<T,T> to_pair(pca a) { return { a.x, a.y }; }
ttt bool operator == (pca a, pca b) { return to_pair(a) == to_pair(b); }
ttt bool operator != (pca a, pca b) { return to_pair(a) != to_pair(b); }
ttt bool operator <  (pca a, pca b) { return to_pair(a) <  to_pair(b); }
ttt bool operator <= (pca a, pca b) { return to_pair(a) <= to_pair(b); }
ttt bool operator >= (pca a, pca b) { return to_pair(a) >= to_pair(b); }
ttt bool operator >  (pca a, pca b) { return to_pair(a) >  to_pair(b); }
ttt T length_squared(pca p) { return p.x*p.x + p.y*p.y; }
ttt double length(pca p) { return sqrt(length_squared(p)); }
ttt point<T> normalized(pca a) { return (1 / length(a)) * a; }
ttt T   dot(pca p, pca q) { return p.x * q.x + p.y * q.y; }
ttt T cross(pca p, pca q) { return p.x * q.y - p.y * q.x; }
ttt int ccw(pca a, pca b, pca c) { T x = cross(b - a, c - a); return x > 0 ? 1 : x < 0 ? -1 : 0; }
#undef ttt
#undef pca
template <typename T> std::istream & operator >> (std::istream & input, point<T> & p) { return input >> p.x >> p.y; }
template <typename T> std::ostream & operator << (std::ostream & output, const point<T> & p) { return output << p.x << ' ' << p.y; }
template <typename T> struct circle { point<T> p; T r; };
template <typename T> bool operator == (circle<T> const & a, circle<T> const & b) { return a.p == b.p and a.r == b.r; }
template <typename T> bool operator != (circle<T> const & a, circle<T> const & b) { return not (a == b); }
using namespace std;
int main() {
    int n; cin >> n;
    while (n --) {
        circle<double> a, b;
        cin >> a.p >> a.r >> b.p >> b.r;
        double l = length(a.p - b.p);
        if (a.r + b.r < l) {
            cout << 0 << endl;
        } else if (l + a.r < b.r) {
            cout << - 2 << endl;
        } else if (l + b.r < a.r) {
            cout << 2 << endl;
        } else {
            cout << 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1240