akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <unordered_set>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

int objX, objY;
vector<int> dx;
vector<int> dy;

bool reachable0(vector<int> dd, int objP) {
    unordered_set<int> pos;
    pos.insert(abs(objP));
    for(int d : dd) {
        unordered_set<int> dpos;
        for(int p : pos) {
            dpos.insert(abs(p + d));
            dpos.insert(abs(p - d));
        }
        pos = dpos;
    }
    return pos.find(0) != pos.end();
}


int main() {
    string s;
    cin >> s;
    cin >> objX >> objY;
    s.push_back('T');

    int cd = 0;
    bool dirX = true;
    int i = 0;
    while(s[i] == 'F' && i < s.size()) {
       --objX; ++i; 
    }
    for(; i < s.size(); ++i) {
        if(s[i] == 'F') {
            cd++; continue;
        }
        if(cd > 0) {
            if(dirX) {dx.push_back(cd);}
            else {dy.push_back(cd);}
        }
        cd = 0;
        dirX = !dirX;
    }

    if(reachable0(dx, objX) && reachable0(dy, objY)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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

int X, Y, A, B, C;
//int p[100010], q[100010], r[100010], apple[300010];
//vector<int> p, q, r;



int main ()
{
    cin >> X >> Y >> A >> B >> C;
    vector<int> p(A);
    vector<int> q(B);
    vector<int> r(C);
    for(int i = 0; i < A; i++) cin >> p[i];
    for(int i = 0; i < B; i++) cin >> q[i];
    for(int i = 0; i < C; i++) cin >> r[i];
    sort(p.begin(), p.end(), greater<int>());
    sort(q.begin(), q.end(), greater<int>());

    for(int i = 0; i < X; i++)r.push_back(p[i]);
    for(int j = 0; j < Y; j++)r.push_back(q[j]);
    sort(r.begin(), r.end(), greater<int>());

    long long res = 0;
    for(int i = 0; i < X + Y; i++) res += r[i];

    cout << res << endl;
    
}

Measured memory_bytes: 2552
n = int(input())
s = input()
nr = s.count('R')
nw = len(s)-nr
a = ('R'*nr)+('W'*nw)
c = 0
for i in range(n):
  if(s[i:i+1] != a[i:i+1]):
    c += 1
print(c // 2)

Measured memory_bytes: 9672
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,int> P;

int main(){
  ll A[3][1100],ans[1100000],ans2[3100000];
  int X[3],K;
  cin>>X[0]>>X[1]>>X[2]>>K;
  for(int i=0;i<3;i++){
    for(int j=0;j<X[i];j++){
      cin>>A[i][j];
    }
  }
  ll count=0;
  for(int i=0;i<X[0];i++){
    for(int j=0;j<X[1];j++){
      ans[count]=A[0][i]+A[1][j];
      count++;
    }
  }
  sort(ans, ans+count, greater<ll>()); //逆順

  count=0;
  
  for(int i=0;i<K;i++){
    for(int j=0;j<X[2];j++){
      ans2[count++]=ans[i]+A[2][j];
    }
  }
  sort(ans2, ans2+count, greater<ll>());//逆順

  for(int i=0;i<K;i++) cout<<ans2[i]<<endl;
}


Measured memory_bytes: 33024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String st = sc.nextLine();
		int n = Integer.parseInt(st);
		int h = n / 3600;
		int m = (n / 60) - (h * 60);
		int s = n % 60;
		System.out.print(h);
		System.out.print(":");
		System.out.print(m);
		System.out.print(":");
		System.out.println(s);
	}

}

Measured memory_bytes: 26208
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
typedef long double ldouble;
typedef long long LL;
#define mp make_pair
#define CHECK(x) if(!(x)) return false;

const int MAXN = 1010;
int v[MAXN];

int main() {
  while (1) {
    int n, m;
    scanf("%d%d", &n, &m);
    if (n == 0 && m == 0)
      break;
    for (int i = 0; i < n; ++i)
      scanf("%d", &v[i]);
    sort(v, v + n);
    int best = -1;
    int il = 0, ir = n - 1;
    while (il < ir) {
      int cand = v[il] + v[ir];
      if (cand <= m) {
        best = max(best, cand);
        ++il;
      }
      else
        --ir;
    }
    if (best < 0)
      puts("NONE");
    else printf("%d\n", best);
  }
  return 0;
}



Measured memory_bytes: 2748
package main

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

/*
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
)
*/

func main() {
	var wtr = bufio.NewWriter(os.Stdout)

	var S string
	fmt.Scan(&S)

	/*
		var sc = bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Scan()
		//temp := strings.Split(sc.Text(), " ")
		//N, _ := strconv.Atoi(temp[0])
		sc.Scan()
		temp := strings.Split(sc.Text(), " ")
	*/
	mina := 1000000
	for i := 0; i < len(S)-2; i++ {
		p, _ := strconv.Atoi(S[i : i+3])
		//fmt.Println(S[i : i+3])
		a := p - 753
		if a < 0 {
			a *= -1
		}
		if mina > a {
			mina = a
		}
	}

	fmt.Fprintln(wtr, mina)
	_ = wtr.Flush()
}


Measured memory_bytes: 1844
S=input()
Q=int(input())
added=(list(),list())
head=0
for i in range(Q):
    l=input().split()
    if int(l[0])==1:
        head=(head+1) % 2
    else:
        adding=(int(l[1])+head-1)%2
        added[adding].append(l[2])
#    print(added,head)

#print(added)
print(''.join(reversed(added[head])),end="")
if head==1:
    S=S[::-1]
print(S,end="")
print(''.join(added[(head+1)%2]))


Measured memory_bytes: 6272
#include<bits/stdc++.h>
#define lint long long int 
#define mm 1000000007
using namespace std;

int main()
{
     lint n,t;
     cin>>n>>t;
     t/=1000;
     int x,y,z;
     for(x=0;x<=n;x++)
     {
           for(y=0;y<=n;y++)
           {
                 z=n-x-y;
                       if(10*x+5*y+z==t && z>=0)
                       {
                             cout<<x<<" "<<y<<" "<<z<<endl;
                             return 0;
                       }
                 
           }
     }
     cout<<"-1 -1 -1"<<endl;
      return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"	
	typedef long long LL;
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define mod2 998244353
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define sz(v) ((ll)(v).size())
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define pb push_back
	#define f first
	#define s second
	#define dbg(a) cout<<#a<<" --> "<<(a)<<"\n";
	#define forn(i,n) for (ll i=0; i<(n); ++i)
	#define fornd(i,n) for (ll i=(n)-1; i>=0; --i)	
	#define forab(i,a,b) for (ll i=(a); i<=(b); ++i)
	#define read(a) ll a; cin >> a;
	#define reads(s) string s; cin >> s;
	#define readb(a, b) ll a, b; cin >> a >> b;
	#define readc(a, b, c) ll a, b, c; cin >> a >> b >> c;
	#define readarr(a, n) int a[(n) + 1] = {}; forab(i, 0, (n-1)) {cin >> a[i];}
	#define readmat(a, n, m) int a[n + 1][m + 1] = {}; forab(i, 1, n) {forab(j, 1, m) cin >> a[i][j];}
	#define readv(A,n) vll A(n,0); forn(i,n) cin>>A[i]; 
	#define print(a) cout << a << endl;
	#define printarr(a, n) forab (i, 1, n) cout << a[i] << " "; cout << endl;
	#define printv(v) for (int i: v) cout << i << " "; cout << endl;
	#define printmat(a, n, m) forab(i, 1, n) {forab (j, 1, m) cout << a[i][j] << " "; cout << endl;}
	 
	#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
	using namespace std;
	bool isPowerOfTwo(int x) {
    return x && (!(x & (x - 1)));
	}
	int takemod(int x) {
    return (x % mod + mod) % mod;
	}
 
	int fpow(int base, int power, int MOD) {
    int result = 1;
    base = base % MOD;
    while (power) {
        if (power & 1)
            result = (result * base) % MOD;
        base = (base * base) % MOD;
        power = power >> 1;
    }
    return result;
	}
 
	int modinv(int x) {return fpow(x, mod - 2, mod);}
	void solve()
	{
		ll x;
		cin>>x;
		if(x>=30)
		{
			cout<<"Yes"<<endl;
			return;
		}
		cout<<"No"<<endl;
	}
	int main()
	{	
		#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		#endif
		fast_io;
		int T=1;
		//cin>>T;
		// cin.ignore(); must be there when using getline(cin, s)
		while(T--)
		{
			solve();
		}
		return 0;
	}

	
	

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	COMinit();

	int N, K;
	cin >> N >> K;
	rep(i, 1, K + 1)
	{
		if (i == 1)
		{
			if (N == K)
			{
				cout << 1 << endl;
			}
			else
			{
				cout << (((COM(N - K - 1, i) + 2 * COM(N - K - 1, i - 1))%MOD)*COM(K - 1, i - 1)) % MOD << endl;
			}
		}
		else
		{
			cout << (((COM(N - K - 1, i) + 2 * COM(N - K - 1, i - 1) + COM(N - K - 1, i - 2))%MOD)*COM(K - 1, i - 1)) % MOD << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 12160
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)

#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define op(i) cout << (i) << endl;
#define F first
#define S second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const ll mod = 1e9 + 7;
const ll infl = 1e17;

typedef unsigned long long ull;



int main()
{
    ll n;
    cin >> n;
    if (n==3){
        cout << "2 5 63" << endl;
        return 0;
    }
    ll k = n / 8;
    ll l = n % 8;
    rep(i,k){
        ll x = 12 * i;
        cout << x + 2 << " ";
        cout << x + 3 << " ";
        cout << x + 4 << " ";
        cout << x + 6 << " ";
        cout << x + 8 << " ";
        cout << x + 9 << " ";
        cout << x + 10 << " ";
        cout << x + 12 << " ";
    }
    ll x = 12 * k;
    if (l%2==1){
        cout << x + 6 << " ";
        l--;
    }
    if (l>=2){
        cout << x + 2 << " " << x + 4 << " ";
        l -= 2;
    }
    if (l >= 2)
    {
        cout << x + 3 << " " << x + 9 << " ";
        l -= 2;
    }
    if (l >= 2)
    {
        cout << x + 8 << " " << x + 10 << " ";
        l -= 2;
    }
    cout << endl;
}


Measured memory_bytes: 384
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a
 
def lcm(a,b):
  return a*b//gcd(a,b)

a, b, c, d = map(int, input().split())
c1 = (b // c) - (a // c)
if a % c == 0:
    c1 += 1
d1 = (b // d) - (a // d)
if a % d == 0:
    d1 += 1
lam1 = lcm(c, d)
cd = (b // (lam1)) - (a // (lam1))
if a % lam1 == 0:
    cd += 1
print((b - a + 1) - ((c1 + d1) - cd))

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    vector<ll> a(N + 1), b(N + 1), c(N + 1);
    vector<vector<ll>> dp(N + 1, vector<ll>(3, -1e15));
    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    for (int i = 1; i <= N; i++)
    {
        cin >> a[i] >> b[i] >> c[i];
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
    }
    cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << endl;
}


Measured memory_bytes: 8064
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include<stack>
using namespace std;
#define PI 3.14159265358979
typedef  long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>
int main(void)
{
    ll x;
    cin>>x;

    if(x<=6) cout<<1<<endl;
    else if(x<=11) cout<<2<<endl;

    else
    {
        ll a = x/11;
        ll b = x-a*11;
        if(b==0) cout<<2*a<<endl;
        else if(b<=6) cout<<2*a+1<<endl;
        else cout<<2*a+2<<endl;
    }
 }

Measured memory_bytes: 888
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

vector<int> v;
vector<int> c;
int n;
int solve(int k, int value, int cost)
{
  if (k == n)
  {
    return value - cost;
  }

  return std::max(solve(k + 1, value, cost), solve(k + 1, value + v[k], cost + c[k]));
}

int main()
{
  cin >> n;

  int a, b;
  for (int i = 0; i < n; i++)
  {
    cin >> a;
    v.push_back(a);
  }
  for (int i = 0; i < n; i++)
  {
    cin >> b;
    c.push_back(b);
  }

  cout << solve(0, 0, 0) << endl;
}

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

int main() {
 int n;
 cin >> n;
 set<int> s;
 rep(i,n) {
     int d;
     cin >> d;
     s.insert(d);
 }

 cout << s.size() << endl;
}

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

int  main(void)
{
	int i;
	char s[5];
	cin >> s;
	for( i = 0 ; i < 3 ; i ++ )
	{
		if( s[ i ] == s[ i + 1 ] )
			break;
	}
	if( i == 3 )
		cout << "Good";
	else
		cout << "Bad";
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.lang.*;

public class Main {
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        String o = fs.nextToken(), e = fs.nextToken();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < e.length(); i++) {
            sb.append(o.charAt(i));
            sb.append(e.charAt(i));
        }
        if (o.length() != e.length()) {
            sb.append(o.charAt(o.length() - 1));
        }
        System.out.println(sb.toString());
    }
}


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

int main() {
    int n,m;
    ll k;
    cin >> n >> m >> k;
    vector<ll> a(n),b(m);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];
    ll time=0;
    rep(i,m) time += b[i];
    int j=m;
    int ans=0;

    rep(i,n+1) {
        while(j > 0 && time > k){
            --j;
            time -= b[j];
        }
        if(time>k) break;
        ans = max(ans, i+j);
        if(i==n) break;
        time += a[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6392
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  // ここにプログラムを追記
  int N, A;
  cin >> N >> A;

  if ((N % 500) <= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int main()
{

        int H1, M1,H2, M2, K;
        cin >> H1 >> M1 >> H2 >> M2 >> K;
        int ans = H2 * 60 + M2;
        int ans2 = H1 * 60 + M1;
        cout << ans - ans2 - K << endl;



}


Measured memory_bytes: 3640
X = raw_input()
Y = X.split(' ')
if Y[0] == "1" and Y[1] == "0" and Y[2] == "0":
  print "Close"
elif Y[0] == "0" and Y[1] == "1" and Y[2] == "0":
  print "Close"
elif Y[0] == "1" and Y[1] == "1" and Y[2] == "0":
  print "Open"
elif Y[0] == "0" and Y[1] == "0" and Y[2] == "1":
  print "Open"
else:
  print "Close"

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

template <typename T>
uint64_t Getdigit(T num) {
  uint64_t digit = 0;
  while (num != 0) {
    num /= 10;
    digit++;
  }
  return digit;
}

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

  int ans = 11;
  for (int64_t i = 1; i <= (int64_t)sqrt(n); ++i) {
    int a = Getdigit(i);
    if (n % i == 0) {
      int b = Getdigit(n / i);
      ans = min(ans, max(a, b));
    }
  }
  cout << ans << endl;
}

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

vector<int> v(312345);

int N;
int main () {
    cin >> N;
    for(int i=0; i<3*N; i++) cin >> v[i];
    sort(v.rbegin(),v.rend());
    long long int ans = 0;
    int i = 1;
    while(N) {
        ans += v[i];
        i+=2;
        N--;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main()
{
  int n;
  cin >> n;
  while(n--){
    string mcxi1, mcxi2;
    cin >> mcxi1 >> mcxi2;
    int dec1 = 0, dec2 = 0;
    int mlp = 1;
    for(int i = 0; i < mcxi1.size(); i++){
      if('0' <= mcxi1[i] && mcxi1[i] <= '9') mlp = (mcxi1[i] - '0');
      else {
	switch(mcxi1[i]){
	case 'm': dec1 += mlp * 1000; break;
	case 'c': dec1 += mlp * 100; break;
	case 'x': dec1 += mlp * 10; break;
	case 'i': dec1 += mlp; break;
	}
	mlp = 1;
      }
    }
    mlp = 1;
    for(int i = 0; i < mcxi2.size(); i++){
      if('0' <= mcxi2[i] && mcxi2[i] <= '9') mlp = (mcxi2[i] - '0');
      else {
	switch(mcxi2[i]){
	case 'm': dec2 += mlp * 1000; break;
	case 'c': dec2 += mlp * 100; break;
	case 'x': dec2 += mlp * 10; break;
	case 'i': dec2 += mlp; break;
	}
	mlp = 1;
      }
    }
    int add = dec1 + dec2;
    string tani = "mcxi";
    int idx = 0;
    for(int i = 1000; i > 0; i /= 10){
      if(add / i > 1) cout << add / i << tani[idx];
      else if(add / i == 1) cout << tani[idx];
      add %= i;
      idx++;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define lli long long int
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define true 1
#define false 0



int main(void){
	int i;
	char s[17];
	char a[17] = "CODEFESTIVAL2016";
	int count = 0;
	scanf("%s",s); 
	for(i=0;i<16;i++){
		if(s[i]!=a[i]){
			count++;
		}
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
int n, k;

ll pow(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2)
	{
		return pow(x, y - 1) * x % mod;
	}
	else
	{
		ll yyy = pow(x, y / 2);
		return yyy * yyy % mod;
	}
}

ll div(ll x)
{
	return pow(x, mod - 2);
}

int main(void)
{
	cin >> n >> k;
	if (k == 1)
	{
		cout << 0 << endl;
	}
	else
	{
		cout << n - k << endl;
	}
	int www;
	cin >> www;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//よく日本語を読むと奇数しか見てないのでpqr=3,5,7,11,13ぐらいしか使わなくて、その候補は357,3511,3513,
//5*3^3=135を忘れていた
//3^3*7=189まで忘れちゃった
int main(){
  int n;
  cin>>n;
  if(n<105){cout<<0;}
  else if(n<135){cout<<1;}
  else if(n<165){cout<<2;}
  else if(n<189){cout<<3;}
  else if(n<195){cout<<4;}
  else{cout<<5;}
}

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

int main(){
  int n,d,x,count=0;
  cin>>n>>d>>x;
  int num[n];
  for(int i=0;i<n;i++){
    cin>>num[i];
    count++;
    int z= num[i]+1;
    while(z<=d){
      count++;
      z+=num[i];
    }
  }
  cout<<count+x<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s,w;
	cin >> s >> w;
	if(s[0]==w[2] && s[1]==w[1] && s[2]==w[0]){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}



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

#define all(x) (x).begin(), (x).end()
#define pb push_back

typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;

int main(){
	int n,k;
	string s;
	cin>>n>>s>>k;
	char tar=s[k-1];

	for (int i = 0; i < s.size(); ++i){
		if(s[i]==tar)
			cout<<tar;
		else
			cout<<'*';
	}

	cout<<endl;

}


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

using namespace std;

typedef long long int ll;

int main()
{


    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin >> a[i];
    ll cur=1,ans=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]==cur)
            {
                cur++;
                continue;
            }
        else
        {
            ans++;
        }
    }
    if(ans==n)
        cout<<-1;
    else
        cout<<ans;
    return 0;
}

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

using namespace std;
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
typedef vector<ll> vll;
typedef vector<int> vi;
const ll N = 1e7 + 10;
const int M = 1e9 + 7;
const double eps = 1e-9;
ll nod[N];

int main() {
    for (int i = 1; i < N; ++i) {
        for (int j = i; j < N; j += i) {
            nod[j]++;
        }
    }
    ll n;
    cin >> n;
    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans += nod[i] * i;
    }
    cout << ans << endl;
}



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

using namespace std;

void Main() {
    int W, H, N;
    cin >> W >> H >> N;

    int ans = W * H;
    int adjustX = 0;
    int adjustY = 0;
    for (int i = 0; i < N; ++i) {
        int x, y, a;
        cin >> x >> y >> a;
        x += adjustX;
        y += adjustY;
        if (a == 1 && 0 < x) {
            W -= x;
            adjustX -= x;
        }
        else if (a == 2 && x < W) {
            W -= (W - x);
        }
        else if (a == 3 && 0 < y) {
            H -= y;
            adjustY -= y;
        }
        else if (a == 4 && y < H) {
            H -= (H - y);
        }
        if (H <= 0) {
            H = 0;
            break;
        }
        if (W <= 0) {
            W = 0;
            break;
        }
    }
    cout << H * W << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

int main(void){
  char s[200001];
  scanf("%s", s);
  int mini, maxi;
  
  for(int i = 0; i < strlen(s); i++){
    if(s[i] == 'A'){
      mini = i;
      break;
    }
  }
  for(int i = strlen(s) - 1; i >= 0; i--){
    if(s[i] == 'Z'){
      maxi = i;
      break;
    }
  }
  
  printf("%d\n", maxi - mini + 1);
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int train[10000],moving,situation=0,ans[10000],n=0,ende=0;
    while(cin>>moving){
        if(moving!=0){
            train[situation]=moving;
            situation++;
        }
        else {
                situation--;
                ans[ende]=train[situation];
                ende++;
        }
    }
    for(int i=0;i<ende;i++)cout<<ans[i]<<endl;

}

Measured memory_bytes: 1164
import itertools

n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))

l = []
for i in range(1, n+1):
    l.append(i)
m = []
for j in itertools.permutations(l, n):
    m.append(list(j))

for a in range(9*8*7*6*5*4*3*2):
    if p == m[a]:
        x = a
        break
for b in range(9*8*7*6*5*4*3*2):
    if q == m[b]:
        y = b
        break
print(abs(x-y))

Measured memory_bytes: 14648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

int main()
{
  ll a,b,c; cin>>a>>b>>c;

  cout << min(b/a, c) << endl;

  return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;

int main()
{
    int N;
    cin >> N;
    int p[N];
    rep(i, N)
    {
        cin >> p[i];
    }

    int count = 0;
    rep(i, N) if (i + 1 != p[i]) count++;

    if (count <= 2)
    {
        OP("YES");
    }
    else
    {
        OP("NO");
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  string s; cin >> s;

  vl arr;
  char c = s[0];
  ll num = 0;
  rep(i,s.size()) {
    if (s[i] == c) ++num;
    else {
      arr.push_back(num);
      c = s[i];
      num = 1;
    }
  }
  arr.push_back(num);

  int i = 0;
  ll ans = 0;
  if (s[0] == '>') {
    ans += arr[i] * (arr[i] + 1) / 2;
    ++i;
  }
  
  while (i < arr.size()) {
    if (i+1 == arr.size()) {
      ans += arr[i] * (arr[i] + 1) / 2;
      break;
    }

    if (arr[i] == arr[i+1]) {
      ans += arr[i] * arr[i];
    }
    else {
      ans += arr[i] * (arr[i] + 1) / 2;
      ans += arr[i+1] * (arr[i+1] + 1) / 2;
      ans -= min(arr[i], arr[i+1]);
    }

    i += 2;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3068
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <numeric>
#include <climits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <utility>
#include <cctype>
#include <iterator>
////////////////////////////////////////////////
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
////////////////////////////////////////////////
////////////////////////////////////////////////
int main() {
  ////////////////////////////////////////////////
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ////////////////////////////////////////////////
  int n;
  string s;
  cin >> n >> s;
  vecint b(n + 1, 0);
  vecint w(n + 1, 0);
  REP(i, n) {
    b[i + 1] = b[i];
    w[i + 1] = w[i];
    if (s[i] == '.') w[i + 1]++;
    if (s[i] == '#') b[i + 1]++;
  }
  // REP(i, n + 1) cout << b[i] << " ";
  // cout << endl;
  // REP(i, n + 1) cout << w[i] << " ";
  // cout << endl;

  int ans = min(b.back(), w.back());
  REP(i, n) {
    int b2w = b[i];
    int w2b = (w[n] - w[i]);
    // cout << i << " " << b2w << " " << w2b << endl;
    ans = min(ans, b2w + w2b);
  }
  cout << ans << endl;
}


Measured memory_bytes: 2196
#include <bits/stdc++.h>
using namespace std;
set<int> p;
int main()
{
	int x,n;
	cin>>x>>n;
	for(int i=0;i<n;i++)
	{
		int P;
		cin>>P;
		p.insert(P);
	}
	int cnt=0,ans;
	while(1){
		if(p.find(x-cnt)==p.end()){
			ans=x-cnt;
			break;
		}else{
			if(p.find(x+cnt)==p.end()){
				ans=x+cnt;
				break;
			}
		}
		cnt++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

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

    map<int, int> mp;
    for(int i = 0; i < N; i++){
        mp[A[i]]++;
    }
    vector<int> B;
    for(auto p: mp){
        B.push_back(p.second);
    }
    //cout << "Yes"<<endl;

    sort(B.begin(), B.end());
    int sum = 0;
    int f = B.size();
    //cout << B.size() << "  " << K << endl;
    if(((int)B.size()- K) <= 0){
        cout << 0 <<endl;
        return 0;
    }
    else{
        for(int i = 0; i < B.size() - K; i++ ){
            sum += B[i];
        }
        cout << sum <<endl;
    }
}

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

#define fs first
#define sc second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define pb emplace_back

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, string s = "\n") { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

int main() {
	string s;
	cin >> s;

	int ans = inf;
	for (char c = 'a'; c <= 'z'; ++c) {
		int cnt = 0;
		int l = 0;
		for (int i = 0; i < s.size(); ++i) {
			if (s[i] == c) {
				chmax(cnt, i - l);
				l = i + 1;
			}
		}

		chmax(cnt, (int)s.size() - l);
		chmin(ans, cnt);
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef long long LL;

#define d(x)  cout<<#x<<" = "<<(x)<<endl;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).rbegin()) i=(c).rbegin(); i!=(c).rend(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c,n) sort(c,c+n)
#define VSORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define DFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define DREP(i,n) DFOR(i,n,0)
#define INF 1000000000

const double EPS = 1e-10;
const double PI  = acos(-1.0);
////////////////////////////////////////////////
/*
int main()
{
	char s[6];
	scanf("%s",s);
	for(int i=0;i<6;i++)
	{
		if(s[i]=='A')
		{
			if(s[i+1]=='C')
			{
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}
*/
int main()
{
	int n;cin>>n;
	int a[20]={0};
	int m=1;
	REP(i,n)
	{
		cin>>a[i];
		if(a[i]%2==1)m*=1;
		else m*=2;
	}
	cout<<(pow(3,n)-m)<<endl;
	return 0;
}

Measured memory_bytes: 640
N = int(input())
txys = [(0,0,0,)] + [tuple(map(int,input().split())) for _ in range(N)]

def check():
    for i in range(N):
        t1,x1,y1 = txys[i]
        t2,x2,y2 = txys[i+1]

        dt = t2-t1
        dxy = abs(x1-x2) + abs(y1-y2)

        if dxy > dt:
            return False
        if (dxy - dt)%2 != 0:
            return False
        
    return True

if check():
    print("Yes")
else:
    print("No")

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

#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define rrep(i, a, b) for (int i = int(a) - 1; i >= b; i--)
#define sz(x) (int)(x).size()

using namespace std;
using ll = long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];
  sort(a.begin(), a.end());
  bool flag = true;
  rep(i, 0, n - 1) {
    if (a[i] == a[i + 1]) {
      flag = false;
    }
  }
  if (flag) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

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

using namespace std;

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

    set<int> s;

    for(int i = 0; i < n; i++) {
        int a;
        cin >> a;

       s.insert(a);
    }
    
    if(s.size()==n){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int n;
int main(){
    int a,b;
    cin>>a>>b;
    if(b%a==0) cout<<a+b<<endl;
    else cout<<b-a<<endl;
    return 0;
}

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

int main()
{
    int a,b,k,c;
    cin>>k>>a>>b;
    c=a/k;
    if(a%k==0||(k*(c+1)<=b))cout<<"OK"<<endl;
    else
        cout<<"NG"<<endl;


    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define FOR(i, a, b) for (int i=(a); i<(b); ++i)
#define ROF(i, b, a) for (int i=(b); i>(a); --i)
#define CASET int _T; cin >> _T; FOR(caset, 0, _T)
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define vvi vector<vi>
#define vvb vector<vb>
#define pii pair<int,int>
#define t3i tuple<int,int,int>
#define mii map<int,int>
#define vpii vector<pii>
#define vt3i vector<t3i>
#define sq(x) (x)*(x)
#define inv(x) powa(x, MOD-2)
 
long long INF = 1LL<<60;
long long MOD = 1e9+7;

template <typename A, typename B> istream &operator>>(istream &is, pair<A, B> &pr) {is >> pr.first >> pr.second; return is;}
template <typename A> istream &operator>>(istream &is, vector<A> &v) {for (auto &x : v) is >> x; return is;}
ostream &operator<<(ostream &os, char &c) {os << (char)c; return os;}
ostream &operator<<(ostream &os, const char s[]) {os << (string)s; return os;}
ostream &operator<<(ostream &os, string &s) {for (char &c : s) os << (char)c; return os;}
template <typename A, typename B> ostream &operator<<(ostream &os, pair<A, B> &pr) {os << '(' << pr.first << ", " << pr.second << ')'; return os;}
ostream &operator<<(ostream &os, vb &v) {
    bool first = true;
    os << '[';
    for (const bool &x : v) {
        if (!first) os << ", ";
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
template <class C> ostream &operator<<(ostream &os, C &v) {
    bool first = true;
    os << '[';
    for (auto &x : v) {
        if (!first) os << ", ";
        first = false;
        os << x;
    }
    os << ']';
    return os;
}
int powa(int base, int exp) {
    int res = 1;
    while (exp) {
        if (exp&1) res = res*base % MOD;
        base = base*base % MOD;
        exp >>= 1;
    }
    return res;
}
bool mini(int &a, int b) { return b < a ? a = b, 1 : 0; }
bool maxi(int &a, int b) { return b > a ? a = b, 1 : 0; }

main() {
    ios::sync_with_stdio(0), cin.tie(0);

    int n;
    cin >> n;
    vi a(n);
    cin >> a;
    vi pref = a, suff = a;
    FOR(i, 1, n) pref[i] += pref[i-1];
    ROF(i, n-2, -1) suff[i] += suff[i+1];

    vi prefs(n), suffs(n);
    int h = 0;
    FOR(i, 1, n) {
        while (h<n-1 && abs(pref[h+1] - pref[i]/2) < abs(pref[h] - pref[i]/2)) ++h;
        prefs[i] = min(pref[h], pref[i] - pref[h]);
    }
    h = n-1;
    ROF(i, n-2, -1) {
        while (h>0 && abs(suff[h-1] - suff[i]/2) < abs(suff[h] - suff[i]/2)) --h;
        suffs[i] = min(suff[h], suff[i] - suff[h]);
    }
    
    int res = INF;
    FOR(i, 2, n-1) {
        vi vals = {prefs[i-1], pref[i-1] - prefs[i-1], suffs[i], suff[i] - suffs[i]};
        mini(res, *max_element(vals.begin(), vals.end()) - *min_element(vals.begin(), vals.end()));
    }
    cout << res;
}

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

char str[100001];

int main()
{
    gets(str);
    int i,ans=0;
    for(i=1;i<strlen(str);i++)
    	if(str[i]!=str[i-1])
    		ans++;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 384
i=list(map(int,input().split()))
x=[[0,1],[0,2],[1,2]]

for a in range(3):
    if( i[ x[a][0] ] > i[ x[a][1] ]):
        swap=i[ x[a][0] ]
        i[ x[a][0] ]= i[ x[a][1] ]
        i[ x[a][1] ]=swap
        

print(i[0],end=' ')
print(i[1],end=' ')
print(i[2],end='\n')


Measured memory_bytes: 5604
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

int N;
int A[100010],B[100010];
pair<int,pair<int,int>> C[100010];

signed main(){
	int sum=0,sum2=0;
	cin>>N;
	REP(i,N){
		cin>>A[i]>>B[i];
		C[i]=make_pair(A[i]+B[i],make_pair(A[i],B[i]));
	}
	sort(C,C+N,greater<>());
	REP(i,N){
		if(i%2==0){
			sum+=C[i].second.first;
		}
		else{
			sum2+=C[i].second.second;
		}
	}
	cout<<sum-sum2<<endl;
	return 0;
}


Measured memory_bytes: 4224
N = int(input())
c = list(input())

num_r1, num_r2 = 0, 0
num_w1, num_w2 = 0, 0
for i in range(int(N/2)):
  if c[i] == 'R':
    num_r1 += 1
  else:
    num_w1 += 1
for i in range(int(N/2), N):
  if c[i] == 'R':
    num_r2 += 1
  else:
    num_w2 += 1
#print('r:', num_r1, num_r2)
#print('w:', num_w1, num_w2)

count = 0
for i in range(num_r1+num_r2):
  if c[i] == 'W':
    count+=1
if count == 0:
  print(0)
else:
  print(count)
  
  
  

Measured memory_bytes: 10716
n, m = map(int, input().split())

grid = [None]*n
mod = 10**9+7

for i in range(n):
    grid[i] = list(input())

dp = [[0]*m for _ in range(n)]

dp[0][0] = 1

for i in range(n):
    if grid[i][0] != '#':
        dp[i][0] = 1
    else:
        break

for i in range(m):
    if grid[0][i] != '#':
        dp[0][i] = 1
    else:
        break

for i in range(1, n):
    for j in range(1, m):
        if grid[i][j] == '#':
            continue

        dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % mod

print(dp[-1][-1])

Measured memory_bytes: 116972
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


void solve(){
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i,N) cin >> A[i];
    ll sum = 0;
    ll right = 0;
    ll ans = 0;
    for(int left=0;left<N;left++){
        while(right < N && (sum ^ A[right]) == (sum + A[right])){
            sum += A[right];
            right++;
        }

        ans += right - left;
        if(right == left) right++;
        else sum -= A[left];
    }
    cout << ans << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    // int T; cin >> T; REP(t,T) solve();
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}

const int INF = 1001001001;
//const ll INF = 1e18;

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

ll cal_gcd(ll a, ll b) {
	ll m = max(a, b);
	ll n = min(a, b);
	while (m%n != 0) {
		ll b = m % n;
		m = n;
		n = b;
	}
	return n;
}

vector<pair<ll, ll>> prime_factorize(ll N) {
	vector<pair<ll,ll>> res;
	for (long long a = 2; a * a <= N; ++a) {
		if (N % a != 0) continue;
		long long ex = 0; 
		while (N % a == 0) {
			++ex;
			N /= a;
		}
		res.push_back({ a, ex });
	}
	if (N != 1) res.push_back({ N, 1 });
	return res;
}

int main() {
	ll n;
	cin >> n;
	auto prime = prime_factorize(n);
	int ans = 0;
	for (auto p : prime) {
		int i = 1;
		while (p.second > 0) {
			if (p.second > 2 * i) {
				p.second -= i;
			}
			else {
				p.second = 0;
			}
			ans++;
			i++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

using namespace std;
typedef long long ll;


struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N, Q; cin >> N >> Q;
    UnionFind uf(N);
    for(int i = 0; i < Q; i++){
        int t, u, v; cin >> t >> u >> v;
        if(t == 0){
            uf.unionSet(u, v);
        }else{
            cout << (uf.findSet(u, v) ? 1 : 0) << endl;
        }
    }
}

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

#define int long long
#define INF 1e18+5

vector<int> w(1009);
vector<int> s(1009);
vector<int> v(1009);

vector< int > dp(20009);

bool comp(int a, int b){
    return s[a] + w[a] > s[b] + w[b];
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;

    vector<int> elements(n);

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

    sort(elements.begin(), elements.end(), comp);

    for(int j = 0; j < n; j++){

        int i = elements[j];

        for(int k = w[i]; k < 20009; k++){

            dp[min(k-w[i],s[i])] = max(dp[min(k-w[i], s[i])], dp[k]+v[i]);

        }
    }

    int ans = 0;

    for(int i = 0; i < 20009; i++){
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,half=0;
    string s;
    cin >> n >> s;

    half = s.length() / 2;

    if (n % 2 == 0&&s.substr(0, half)==s.substr(half, half)) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

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

int mp[110][110];

int main()
{
	int h,w,n;cin>>h>>w>>n;
	
	REP(i,110)REP(j,110)mp[i][j] = -1;
	rep(i,1,h+1)rep(j,1,w+1)mp[i][j] = 0;
	
	vector<int> v(n);
	REP(i,n)cin>>v[i];
	
	int cou = 0;
	
	int nx = 1;int ny = 1;
	
	REP(i,n)
	{
		while(v[i])
		{
			mp[nx][ny] = i+1;
			if(mp[nx+dx[cou]][ny+dy[cou]] != 0)
			{
				cou = (cou+1)%4;
			}
			nx += dx[cou];ny += dy[cou];
			v[i]--;
		}
	}
	
	rep(i,1,h+1)
	{
		rep(j,1,w)
		{
			cout << mp[i][j] << ' ';
		}
		cout << mp[i][w] << endl;
	}

	return 0;
}

Measured memory_bytes: 384