akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES {cout<<"YES"<<'\n';}
#define NO {cout<<"NO"<<'\n';}
#define Yes {cout<<"Yes"<<'\n';}
#define No {cout<<"No"<<'\n';}
#define yes {cout<<"yes"<<'\n';}
#define no {cout<<"no"<<'\n';}
void YN(bool flg){cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg){cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#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 out(n) {cout << n << '\n';}
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
int ABS(int a) {if(a<0) a = -a; return a;}
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n /= 2; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数の個数*/int divisor_number(int n){auto p = prime_factor(n); int res = 1; for(auto x:p)res*=(x.second+1); return res;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    VI a(n); REP(i,n) cin >> a[i];
    int now = 1;
    int ans = 0;
    REP(i,n){
        if(a[i]==now) now++;
        else ans++;
    }
    if(ans==n){out(-1);}
    else out(ans);

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#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 inf 1e12
#define all(c) c.begin(),c.end()
#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 fast_cin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define precise fixed(cout);cout<<setprecision(16);
#define OUT(x) for(auto a:x) cout << a << " "; cout << endl;
#define OK cout << "@===================ok===================@" <<endl;
#define WTF cout <<"< "<<lo<<" | "<< hi <<" >" << endl;

using namespace std;

int main()
{
    precise;
    int n;
    cin >> n;
    int even=0, odd=0;
    for(int i=1;i<=n;i++){

            if(i%2==0) even++;
            else odd++;

    }
    cout << double(odd)/(even+odd)<<"\n";
}


Measured memory_bytes: 256
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

#define DEBUG
#ifndef DEBUG
#define endl "\n"
#endif

const double PI=3.1415926535897932384626433;
typedef long long ll;
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }

typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    cini(x);
    cini(y);

    int ans=0;
    for(int i : { x, y})
        if(i==1)
            ans+=300000;
        else if(i==2)
            ans+=200000;
        else if(i==3)
            ans+=100000;

    if(x==1 && y==1)
        ans+=400000;

    cout<<ans<<endl;

}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#define rep(i,n) for(i=0;i<(n);++i)
int n, m, i, j, x, y, loop;
char buf[102];
char tile[102][102];
bool visited[102][102];

int main()
{
    while (true) {
        fgets(buf, 102, stdin);
        sscanf(buf, "%d %d", &n, &m);
        if (!(m|n)) break;

        rep(i, n) rep(j, m) visited[i][j] = false;
        rep(i, n) fgets(tile[i], 102, stdin);
        x = y = loop = 0;
        visited[y][x] = true;
        while (tile[y][x] != '.') {
            switch (tile[y][x]) {
                case '>': x++; break;
                case 'v': y++; break;
                case '<': x--; break;
                case '^': y--; break;
            }
            if (visited[y][x]) { loop = 1; break; }
            visited[y][x] = true;
        }
        if (loop) puts("LOOP"); else printf("%d %d\n", x, y);
    }
    return 0;
}

Measured memory_bytes: 0
<?php
	fscanf(STDIN, "%d", $n);
	for ($i=0; $i<$n; $i++) {
      fscanf(STDIN, "%s %d", $s, $p);
	  $states[] = $s;
      $points[] = $p;
      $stores[] = $i + 1;
    }
	
	# states を昇順、 points を降順でソート、 store も一緒に並べる。
	array_multisort($states, SORT_ASC, $points, SORT_DESC, $stores);

	for ($i=0; $i<$n; $i++) {
      echo $stores[$i] . "\n";
    }
?>


Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

struct Combination{
    Int MOD, MAX_N;
    vector<Int> f, f_inv;

    //---------- 初期化 ----------
    Combination(Int mod, Int max_n){
        MOD = mod;
        MAX_N = max_n;

        f = factorial(MAX_N);
        rep(i,f.size()) f_inv.push_back(inv(f[i]));
    }
    
    //---------- べき乗 ----------
    Int power(Int a, Int n){
        if(a == 0) return 0;
        if(n == 0) return 1;

        Int res = 1;
        while(n > 0){
            if(n % 2 == 1) res = res * a % MOD;
            a = a * a % MOD;
            n /= 2;
        }
        return res;
    }

    //---------- 逆元 ----------
    Int inv(Int a){
        return power(a, MOD-2);
    }

    //---------- 階乗 ----------
    vector<Int> factorial(Int n){
        vector<Int> res(n+1, 1);
        rep1(i,n) res[i] = i * res[i-1] % MOD;

        return res; // nまでの階乗の配列を返す
    }


    //--------- 組み合わせ ---------
    Int comb(Int n, Int r){
        return (f[n] * f_inv[r] % MOD) * f_inv[n-r] % MOD;
    }
};


int main(){
    Int N, M, K;
    cin >> N >> M >> K;

    if(M==1){
        if(K == N-1) cout << 1 << endl;
        else cout << 0 << endl;
        return 0;
    }

    Combination C(998244353, N);

    Int ans = 0;
    for(Int i=0; i<=K; i++){        
        Int tmp = M;
        tmp = tmp * C.comb(N-1,i) % C.MOD;
        tmp = tmp * C.power(M-1,N-1-i) % C.MOD;

        ans = (ans + tmp) % C.MOD;
    }

    cout << ans << endl;
}


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

int main(){
  ll n,k; cin >> n >> k;
  ll ret = 0;
  while(n>0){
    n/=k;
    ret++;
  }
  cout << ret;

}

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

int main() {
  int h,w;cin>>h>>w;
  string s[h];
  rep(i,h)cin>>s[i];
  vector<vi> hori(h, vi(w, 0)), vart(h, vi(w, 0));
  rep(i,h) {
    if (s[i][0]=='.') hori[i][0]=1;
    rep(j,w-1) {
      if (s[i][j+1]=='.') hori[i][j+1]=hori[i][j]+1;
      else {
        int k=j, x=hori[i][j];
        while (k>=0 && s[i][k]=='.') {
          hori[i][k]=x;
          k--;
        }
      }
    }
    if (s[i][w-1]=='.') {
      int k=w-1, x=hori[i][w-1];  
      while (s[i][k]=='.') {
        hori[i][k]=x;
        k--;
      }
    }
  }
  //rep(i,h) {rep(j,w)cout<<hori[i][j]<<" ";cout<<endl;}cout<<endl;
  
  rep(j,w) {
    if (s[0][j]=='.') vart[0][j]=1;
    rep(i,h-1) {
      if (s[i+1][j]=='.') vart[i+1][j]=vart[i][j]+1;
      else {
        int k=i, x=vart[i][j];
        while (k>=0 && s[k][j]=='.') {
          vart[k][j]=x;
          k--;
        }
      }
    }
    if (s[h-1][j]=='.') {
      int k=h-1, x=vart[h-1][j];  
      while (s[k][j]=='.') {
        vart[k][j]=x;
        k--;
      }
    }
  }
  //rep(i,h) {rep(j,w)cout<<vart[i][j]<<" ";cout<<endl;}
  
  int ans=0;
  rep(i,h)rep(j,w){
    ans = max(ans, hori[i][j]+vart[i][j]-1);
  }
  cout<<ans;
}


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

int main(void) {
	int n,i;
	scanf ("%d",&n);
	char st[100][11];
	for (i=0;i<n;i++) {
		scanf("%s",st[i]);
	}
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			if (strcmp(st[i], st[j]) == 0) {
				printf("No\n");
				return 0;
			}
		}
	}
	for (int i = 1; i < n; i++) {
		if (st[i-1][strlen(st[i-1])-1] != st[i][0]) {
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 128
local n = io.read("*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
local left = 1
local ret = 0
local sum, xor = 0, 0
for i = 1, n do
  sum = sum + a[i]
  xor = xor ~ a[i]
  while xor < sum do
    sum = sum - a[left]
    xor = xor ~ a[left]
    left = left + 1
  end
  ret = ret + i + 1 - left
end
print(ret)


Measured memory_bytes: 4472
# https://atcoder.jp/contests/abc135/tasks/abc135_b
import numpy as np


def calc(N: int, values: np.ndarray) -> bool:
    sorted_values = np.sort(values)
    difference = sorted_values != values
    difference_count = difference.sum()
    return difference_count == 0 or difference_count == 2


def load_input_as_int_array() -> np.ndarray:
    return np.array([int(v) for v in input().split(" ")])


def main() -> None:
    N = load_input_as_int_array()
    values = load_input_as_int_array()
    result = calc(N, values)
    result_str = "YES" if result else "NO"
    print(result_str)


main()


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

int main()
{
  int a, b, cnt = 0;
  cin >> a >> b;
  
  for (int i = a; i <= b; i++)
    if (i/10000 == i%10 && i/1000%10 == i/10%10)
      cnt++;
  
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char s[105];
bool book[27];
int len,minn=105,ll[27]={0};
int main()
{
	memset(book,0,sizeof(book));
	scanf("%s",s);
	len=strlen(s);
	for(int k=len-1;k>=0;k--)
	{
		int ans=0,tail=k-1;
		while(tail>=0&&s[k]!=s[tail])
		{
			ans++;
			tail--;
		}
		int now=s[k]-'a'+1;
		if(!book[now])ans=max(ans,len-k-1);
		book[now]=1;
		ll[now]=max(ll[now],ans);
	}
	for(int i=1;i<=26;i++)
	{
		if(book[i])
		{
			minn=min(minn,ll[i]);
		}
	}
	printf("%d",minn);
	return 0;
}

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

int main(){
	int k,a,b;
	long long int bis=0;
	long long int yen=0;
	cin >> k >> a >> b;
	if(b-a<=2 || k<=a){//叩くだけの方がいい
		cout << k+1 <<endl;
		return 0;
	}
	k-=(a-1);//最初の交換ができるまで
	bis=a;//A枚揃う
	if(k%2==1){
		k--;
		bis++;
	}
	for(int i=0;i<k/2;i++){
		yen=bis/a;
		bis+=b-a;
	}

	cout << bis <<endl;
	
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

bool is_753(lli x)
{
  set<lli> s;
  while (x) {
    s.insert(x % 10);
    x /= 10;
  }
  return s.size() == 3 && s.count(7) && s.count(5) && s.count(3);
}

set<lli> vis;
void rec(lli x, lli n)
{
  if (x <= n) {
    if (is_753(x)) vis.insert(x);
    rec(x * 10 + 7, n);
    rec(x * 10 + 5, n);
    rec(x * 10 + 3, n);
  }
  return ;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  lli n;
  while (cin >> n) {
    vis.clear();
    rec(7, n);
    rec(5, n);
    rec(3, n);
    cout << vis.size() << endl;
  }
  
  return 0;
}


Measured memory_bytes: 1536
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int A, B, C, D; cin >> A >> B >> C >> D;
    int M = (C-A)*60 + (D-B);
    int K; cin >> K; M -= K;
    cout << M << nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



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

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  string S;
  cin >> S;

  int cnt_red = 0, cnt_blue = 0;
  for(int i = 0; i < S.size(); i++) {
    if(S[i] == '0') cnt_red++;
    else cnt_blue++;
  }
  cout << min(cnt_red, cnt_blue) * 2 << endl;

  return 0;
}


Measured memory_bytes: 3712
#include<stdio.h>

int main(void){
  int i,j,k;
  int n,a[12],pre_a[12];
  int count,ans_count;
  int rs;

  for(;;){
    scanf("%d",&n);
    if(!n)
      break;

    for(i=0;i<n;i++)
      scanf("%d",&a[i]);

    ans_count=0;
    for(;;){
      rs=1;
      for(j=0;j<n;j++){
        count=0;
        for(k=0;k<n;k++){
          if(a[j]==a[k])
            count++;
        }
        pre_a[j]=count;
      }

      for(i=0;i<n;i++){
        if(a[i]!=pre_a[i])
          rs=0;
        a[i]=pre_a[i];
      }

      if(rs) break;

      ans_count++;
    }

    printf("%d\n",ans_count);
    for(i=0;i<n;i++){
      printf("%d",a[i]);
      if(i<n-1)
        printf(" ");
    }
    puts("");
  }

  return 0;
}

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

#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;

TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM T> inline istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }
TPL<TNM V, TNM H> void resize(vector<V>& _v, const H _h) { _v.resize(_h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& _v, const H& _h, const T& ... _t) { _v.resize(_h); for (auto& __v : _v) resize(__v, _t ...); }
TPL<TNM V, TNM T> TNM enable_if<!is_class<V>::value>::type fill(vector<V>& _v, const T& _t) { std::fill(ALL(_v), _t); }
TPL<TNM V, TNM T> TNM enable_if<is_class<V>::value>::type fill(vector<V>& _v, const T& _t) { for (auto& _e : _v) fill(_e, _t); }
TPL<TNM T> inline void UNIQUE(vector<T>& _v) { sort(ALL(_v)); _v.erase(unique(ALL(_v)), _v.end()); }

int A[200000 + 1];
int M[200000 + 1];

int main(void) {
	int N;
	scanf("%d", &N);

	for (int i = 1; i <= N; ++i) {
		scanf("%d", &A[i]);
	}

	
	fill(ALL(M), 0);

	for (int i = N; i > 0; --i) {
		int cnt = 0;
		if (i == 1) {
			for (int j = i + 1; j <= N; j++) {
				if (M[j])++cnt;
			}
		}
		else {
			int j = i;
			int c = 2;
			j = i * c;
			while (j <= N) {
				if (M[j])++cnt;
				++c;
				j = i * c;
			}
		}
		if (cnt % 2 != A[i]) {
			M[i] = 1;
		}
	}

	int ans = count(ALL(M), 1);
	printf("%d\n", ans);
	for (int i = 1; i <= N; ++i) {
		if (M[i]) printf("%d\n", i);
	}

	return 0;
}

Measured memory_bytes: 2560
from operator import sub, add
from itertools import product

a, b, c, d = map(int, input())

for op1, op2, op3 in product([sub, add], repeat=3):
    if op3(op2(op1(a, b), c), d) == 7:
        o, p, q = map(lambda op: "+" if op == add else "-", [op1, op2, op3])
        print(a, o, b, p, c, q, d, "=7", sep="")
        exit()

Measured memory_bytes: 3064
using System;

namespace ABC167C
{
    class Program
    {
        static void Main(string[] args)
        {
            var target = Console.ReadLine().Split(' ');
            int N = int.Parse(target[0]);
            int M = int.Parse(target[1]);
            int X = int.Parse(target[2]);
            int[] cost = new int[12];
            int[,] text = new int[12,12];
            int min_cost = 10000000;
            bool s_f = false;
            for(int i=0;i<N;i++){
              target = Console.ReadLine().Split(' ');
              cost[i] = int.Parse(target[0]);
              for(int j=0;j<M;j++)
                  text[i,j] = int.Parse(target[j+1]);
            }
            int[] skill = new int[12];
            int perm = 1 << N; 
            for(int i=0;i<perm;i++){
                int tmp_cost=0;
                for(int j=0;j<M;j++) skill[j] = 0;
                for(int j=0;j<N;j++){
                    if( (i & (1 << j)) == (1 << j)) {
                        for(int k=0;k<M;k++)
                            skill[k] += text[j,k];
                        tmp_cost+=cost[j]; 
                    }
                }
                bool f = true;
                for(int k=0;k<M;k++)
                    if(skill[k] < X) {f = false;}
                if(f && (tmp_cost < min_cost)) {
                    min_cost = tmp_cost;s_f = true;
                }
            }
            if(!s_f) Console.WriteLine("-1"); else Console.WriteLine(min_cost); 
        }
    }
}


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

int main() {
  int X, ans, count;
  cin >> X;
  ans = 0;
  
  ans = X / 500;
  X = X - (500 * ans);
  ans = ans * 1000;
  
  ans = (X / 5)*5 + ans;
    
  cout << ans << endl;
  
}


Measured memory_bytes: 256
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#define N 110000
#define LL long long
using namespace std;
struct node{LL d,id;}A[N];
LL n,L,T,s1,s2,w[N],a[N],ans[N];
bool cmp(node x,node y)
{
	if(x.d<y.d) return 1;
	if(x.d>y.d) return 0;
	if(x.id>y.id) return 1;
	return 0;
}
int main()
{
	scanf("%lld%lld%lld",&n,&L,&T);
	for(LL i=1;i<=n;i++) 
	{
		scanf("%lld%lld",&a[i],&w[i]);
		if(w[i]==1) s1++;
		else s2++;
		if(w[i]==1) A[i].d=(a[i]+T)%L;
		else A[i].d=((a[i]-T)%L+L)%L;
	}
	LL t=T/L;T%=L;
	if(w[1]==1) t=t*2*s2%n;
	else t=t*2*s1%n;
	for(LL i=2;i<=n;i++)
	{
		if(w[i]==w[1]) continue;
		LL d;
		if(w[1]==1) d=a[i]-a[1];
		else d=L-a[i]+a[1];
		if(2*T>=d) t++;
		if(2*T>=L+d) t++;
	}
	LL st;
	if(w[1]==1) st=(1+t)%n;
	else st=((1-t)%n+n)%n;
	if(st==0) st=n;
	A[1].id=st;
	sort(A+1,A+n+1,cmp);
	LL p,p1=0,p2=0;
	for(LL i=1;i<=n;i++) 
		if(A[i].id==st) 
		{
			p1=i;
			if(A[i].d==A[i+1].d) p2=i+1;
			break;
		}
	if(p2==0) p=p1;
	else
	{
		if(w[1]==1) {swap(A[p1],A[p2]);p=p2;}
		else p=p1;
	}
	for(LL i=p+1;i<=n;i++) 
	{
		A[i].id=A[i-1].id+1;
		if(A[i].id>n) A[i].id=1;
	}
	for(LL i=p-1;i>=1;i--)
	{
		A[i].id=A[i+1].id-1;
		if(A[i].id==0) A[i].id=n;
	}
	for(LL i=1;i<=n;i++) ans[A[i].id]=A[i].d;
	for(LL i=1;i<=n;i++) printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 5248
#include<iostream>
using namespace std;
int main(){
  long long mod=1000000007;
  long long n,m,i;
  cin >> n >> m;
  if(abs(n-m)>1){
    cout << 0 << endl;
    return 0;
  }
  long long ans=1;
  for(i=1;i<=n;i++){
    ans=ans*i%mod;
  }
  for(i=1;i<=m;i++){
    ans=ans*i%mod;
  }
  if(abs(n-m)==0){
    ans=ans*2%mod;
  }
  cout << ans%mod << endl;
}


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

int main(){
    int N, M;
    std::cin >> N >> M;
    std::vector< std::vector< int > > AB(N);
    
    for(int i=0;i<M;i++){
        int tmp1, tmp2;
        std::cin >> tmp1 >> tmp2;
        AB[tmp1 - 1].push_back(tmp2 - 1);
        AB[tmp2 - 1].push_back(tmp1 - 1);
    }
    
    std::vector< int > sign(N, -1);
    std::deque< int > deq;
    std::deque< int > deq_pre;
    deq.push_back(0);
    deq_pre.push_back(0);
    
    while(!deq.empty()){
        int cur = deq[0];
        if(sign[cur] == -1){
            sign[cur] = deq_pre[0];
            for(int i=0; i<AB[cur].size(); i++){
                deq.push_back(AB[cur][i]);
                deq_pre.push_back(cur);
            }
        }
        deq.pop_front();
        deq_pre.pop_front();
    }
    
    bool ok = true;
    for(int i=0; i<N; i++){
        if(sign[i] == -1){
            ok = false;
        }
    }
    if(ok){
        std::cout << "Yes" << std::endl;
        for(int i=1; i<N; i++){
            std::cout << sign[i] + 1 << std::endl;
        }
    }else{
        std::cout << "No" << std::endl;
    }
    
    
    return 0;
}



Measured memory_bytes: 12248
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw_2(62,1);


int main(){
    string s; cin>>s;
    ll ans=0,tmp=0;
    rep(i,sz(s)){
        if(s[i]=='B') tmp++;
        else{
            ans+=tmp;
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 3700
H,W=map(int,input().split())
N=int(input())
L=list(map(int,input().split()))
ans=[]
for i in range(N):
	for j in range(L[i]):
		ans.append((i+1))
for i in range(H):
	if i%2==0:
		print(*ans[i*W:(i+1)*W])
	elif i%2==1:
		tmp=ans[i*W:(i+1)*W]
		print(*tmp[::-1])

Measured memory_bytes: 3884
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)


int main() {
    int A, B;
    cin >> A >> B;
    int a = A + B;
    a = max(a, A - B);
    a = max(a, A * B);

    cout << a << endl;

    return 0;
}


Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))

D={}
ans=0
for i in range(n):
    now=A[i]
    ans+=A[i]
    if now in D:
        D[now]+=1
    else:
        D[now]=1
       
    

q=int(input())

for i in range(q):
    b,c=map(int,input().split())
    if b in D:
        ans=ans-b*D[b]+c*D[b]
        if c in D:
            D[c]+=D[b]
            D[b]=0
        else:
            D[c]=D[b]
            D[b]=0
    print(ans)








Measured memory_bytes: 20592
import java.util.Scanner;

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

        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D;

        D = A;
        A = B;
        B = D;

        D = A;
        A = C;
        C = D;

        System.out.print(A + " ");
        System.out.print(B + " ");
        System.out.print(C + " ");
    }
}

Measured memory_bytes: 21844
#define PI 3.141592653589793

int main(void){
    int a,b,c;
    double s,l,h;
    
    scanf("%d%d%d",&a,&b,&c);
    
    s = sin(c * PI / 180.0)*a*b/2;
    l = a + b + sqrt(a*a + b*b - 2*a*b * cos(c * PI / 180.0));
    h = s/a*2;
    
    printf("%lf %lf %lf\n" ,s,l,h);
    
    return 0;
}



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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

int main(){

    ll n; cin >> n;
    vll a(n);
    ll a_max = 0;
    rep(i, n){
        cin >> a[i];
        a_max = max(a_max, a[i]);
    }

    vector<ll> div(a_max+1, 0);
    rep(i, n){
        for(ll j=0;a[i]*j<=a_max;j++){
            div[a[i]*j]++;
        }
    }

    ll ans = 0;
    rep(i, n) if(div[a[i]]==1) ans++;

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

Measured memory_bytes: 12608
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int a,b,c;
  string s;
 cin >> a >> b;
  if(a + b == 15){
    cout << '+';
  }else if(a * b == 15){
    cout << '*';
  }else{
    cout << 'x';
  }
}

Measured memory_bytes: 256
S = input()
T = input()

ans = 10000
for i in range(len(S)-len(T)+1):
    count = 0
    for elts, eltt in zip(S[i:i+len(T)], T):
        if elts != eltt:
            count += 1
    ans = min(ans, count)

print(ans)


Measured memory_bytes: 67856
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	string S;
	cin >> S;
	S[3] = '8';
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = list(input())

# 一番左がリーダーの時
l = 0
r = S[1:].count('W')
ans = l + r
for i in range(1, N):
    if S[i-1] == 'E':  # 元リーダーの人が東向きの時
        l += 1
    if S[i] == 'W':  # 元リーダーが西向きの時
        r -= 1
    cnt = l+r
    ans = max(cnt, ans)  # 向きを変える必要のない人数
print(N - ans -1)  # 向きを変える必要のある人数

Measured memory_bytes: 8012
import java.util.Scanner;
public class Main { 
    public static void main(String[] args) { 
        Scanner sc = new Scanner(System.in);  
        while (true) { 
            int H = sc.nextInt(); 
            int W= sc.nextInt(); 
            if (H == 0 && W == 0) { 
                break; 
            } else {
                for (int i = 0 ; i < H ; i++){
                    for (int j = 0 ; j < W ; j++){
                        int k=i+j;
                        int kamari=k%2;
                        if (kamari == 1){
                            System.out.printf(".");
                        } else {
                            System.out.printf("#");
                        }
                    }
                    System.out.printf("\n");
                } 
                System.out.printf("\n");
            }
        } 
    }
}


Measured memory_bytes: 60944
/*
    Reference :-
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i < int(n); i++)
#define PI pair<ll,ll>
#define all(vec) vec.begin(),vec.end()
ll mod=1e9+7;
ll fac[100001];
ll power(ll n,ll k){
    ll ans=1;
    while(k){
        if(k&1)ans=(ans*n)%mod;
        k/=2;
        n=(n*n)%mod;
    }
    //ans=(ans-1+mod)%mod;
    return ans;
}
void modify(int l, int r, ll value,ll ar[],int n) {
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l&1) {ar[l] =((ar[l])+value);l++;}
    if (r&1) {r--;ar[r] =((ar[r])+value);}
  }
}
ll query(int p,ll ar[],int n) {
  ll res = -ar[p+n];
  res=0;
  for (p += n; p > 0; p >>= 1) res =((res)+ar[p]);
  return res;
}
int main(){
    //std::ios::sync_with_stdio(false);
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n,d,a;
    cin>>n>>d>>a;
    vector<PI> vec;
    forn(i,n){
        ll a1,b;
        cin>>a1>>b;
        vec.pb({a1,b});
    }
    sort(all(vec));
    ll t[2*n]={0};
    //forn(i,n)t[i+n]=vec[i].S;
    //for (int i = n - 1; i > 0; --i) t[i] = t[i<<1] - t[i<<1|1];
    ll ans1=0;
    for(int i=0;i<n;i++){
        ll val=query(i,t,n);
        //if(i==0)val=vec[0].second;
        val=vec[i].second-val;
        //cout<<val;
        if(val>0){
            ll val1=val/a;
            if(val%a!=0)val1++;
            //cout<<" "<<val1<<" ";
            ans1+=val1;
            ll mc=vec[i].first+d+d;
            int l=i,r=n-1,ans=-1;
            while(l<=r){
                int mid=(l+r)/2;
                if(vec[mid].first>mc)r=mid-1;
                else{
                    ans=mid;l=mid+1;
                }
            }
            //cout<<ans<<endl;
            modify(i,ans+1,(val1*a),t,n);
            //ans+=val1;
        }
    }
    cout<<ans1;

	return 0;
}


Measured memory_bytes: 7532
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author hakamada
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AtCoder103_1 solver = new AtCoder103_1();
        solver.solve(1, in, out);
        out.close();
    }

    static class AtCoder103_1 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int[] inp = new int[3];

            inp[0] = in.nextInt();
            inp[1] = in.nextInt();
            inp[2] = in.nextInt();

            int total[] = {0, 0, 0, 9999};

            total[0] = Math.abs(inp[0] - inp[1]);
            total[0] += Math.abs(inp[1] - inp[2]);

            total[1] = Math.abs(inp[0] - inp[2]);
            total[1] += Math.abs(inp[0] - inp[1]);

            total[2] = Math.abs(inp[1] - inp[2]);
            total[2] += Math.abs(inp[0] - inp[1]);

            total[3] = Math.abs(inp[1] - inp[2]);
            total[3] += Math.abs(inp[0] - inp[2]);

        /*
        total[2] = Math.abs(inp[1] - inp[2]);
        total[2] += Math.abs(inp[3] - inp[2]);
        */

            Arrays.sort(total);
            out.println(total[0]);
        }

    }
}



Measured memory_bytes: 25044
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)

int n, m;
double sheet[100][100], dp[100][100];

double dfs(int et, int b) {
  if (et == m) return 1.0;
  if (dp[et][b] >= 0) return dp[et][b];
  
  double res = 0;
  rep(i,n) {
    res = max(res, sheet[b][i] * dfs(et+1, i));
  }
  return dp[et][b] = res;
}

void solve() {
  rep(i,n) rep(j,n) cin>>sheet[i][j];
  double res = -1;
  memset(dp, -1, sizeof dp);
  
  rep(i,n) {
    res = max(dfs(1, i), res);
  }
  printf("%.2lf\n", res);
}

int main (int argc, char const* argv[]) {
  while (cin>>n>>m, n||m) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 0
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

sum = 0
for i in range(n):
  sum += b[a[i]-1]
  if i > 0 and a[i] - a[i-1] == 1:
    sum += c[a[i-1]-1]
    
print(sum)

Measured memory_bytes: 3064
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
const ll MAX = 500000;
bool isPrime[MAX];
vector<ll> prime;
void makePrime(){
  for (ll i = 0; i < MAX; i++){
    isPrime[i] = true;
  }
  for (ll i = 2; i * i < MAX + 1; i++){
    if(isPrime[i]){
      for (ll j = 2 * i; j < MAX; j += i) {
        isPrime[j] = false;
      }
    }
  }
  FOR(i,2,MAX) if(isPrime[i]) prime.push_back(i);
  return;
}
int main()
{
  makePrime();
  int N, R;
  while(cin >> N >> R, N != -1) {
    int j = upper_bound(prime.begin(), prime.end(), N) - prime.begin();
    vector<int> v;
    FOR(i,j,j+200) {
      FOR(k,i,j+200) {
        v.push_back(prime[i]+prime[k]);
      }
    }
    sort(v.begin(), v.end());
    cout << v[R-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 3832
import sys
readline = sys.stdin.readline

N,M,K = map(int,readline().split())
A = [0] + list(map(int,readline().split()))
B = [0] + list(map(int,readline().split()))

for i in range(1,len(A)):
  A[i] += A[i - 1]

for i in range(1,len(B)):
  B[i] += B[i - 1]

ans = 0
b_ind = len(B) - 1
for i in range(len(A)):
  if A[i] > K:
    break
  while b_ind >= 0 and A[i] + B[b_ind] > K:
    b_ind -= 1
    
  if ans < i + b_ind:
    ans = i + b_ind
    
print(ans)
  
  

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

int main(){
    int N,M,C;
    cin >> N >> M >> C;
    vector<int> B(M);
    vector<vector<int> > A(N, vector<int>(M) );
    rep(i,M){
        cin >> B[i];
    }
    rep(i,N){
        rep(j,M){
            cin >> A[i][j];
        }
    }
    int sum = 0;
    int ans = 0;
    rep(i,N){
        sum = 0; 
        rep(j,M){
            sum += A[i][j]*B[j];
        }
        sum += C;
        if(sum > 0)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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


int main()
{
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif

	ll p,n,i;
	cin>>p>>n;

	ll a[n];
	vector<ll> diff;

	for(i=0 ; i<n ; i++)cin>>a[i];
	for(i=1 ; i<n ; i++)diff.push_back(abs(a[i]-a[i-1]));
  	diff.push_back(p - a[n-1] + a[0]);

	cout<<p - (*max_element(diff.begin(),diff.end()));

	return 0;
} 


Measured memory_bytes: 3956
N, M = map(int, input().split())
G = [[] for _ in range(N)]
res = [10 ** 12] * M
for i in range(M):
    p, y = map(int, input().split())
    G[p - 1].append((y, i))

G = list(map(sorted, G))
for p in range(N):
    for m, (y, i) in enumerate(G[p], 1):
        res[i] += (p + 1) * 10 ** 6 + m

for r in res:
    print(str(r)[1:])


Measured memory_bytes: 73076
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#define N 200005
using namespace std;

struct st {int s, t, x;} a[N];
int n, q, d;
priority_queue<st> pq;

bool operator < (st p, st q) {return p.x > q.x;}
bool cmp(st p, st q) {
	if(p.s != q.s) return p.s < q.s;
	else return p.t < q.t;
}

int main() {
	int i;
	cin >> n >> q;
	for(i=0; i<n; i++) {
		scanf("%d%d%d", &a[i].s, &a[i].t, &a[i].x);
		a[i].s -= a[i].x;
		a[i].t -= a[i].x;
	}
	sort(a, a+n, cmp);
	i = 0;
	while(q--) {
		scanf("%d", &d);
		for(; i<n && a[i].s<=d; i++) pq.push(a[i]);
		while(!pq.empty()) {
			st z = pq.top();
			if(z.t > d) {printf("%d\n", z.x); break;}
			pq.pop();
		}
		if(pq.empty()) puts("-1");
	}
	return 0;
}

Measured memory_bytes: 7156
#include <stdio.h>
int main (){
int a,b,c,d;
scanf ("%d%d%d%d",&a,&b,&c,&d);
if (a*b>c*d){
printf ("%d",a*b);
}
  else {
  printf ("%d",c*d);
  }
return 0;
}

Measured memory_bytes: 128
import Control.Applicative
import Control.Monad
import Data.List

addList::[Int]->[Int]->[Int]
addList [x] [y] = [ x + y ]
addList x [] = x
addList [] y = y
addList (x:xs) (y:ys) = [x + y] ++ addList xs ys

main = do
    r:_ <- map read.words <$> getLine
    ss <- replicateM r (map read.words <$> getLine) ::IO[[Int]]
    let a = [ s ++ [sum s] | s <- ss]
    let b = foldr addList [] a
    putStrLn $ ((intercalate "\n"). map(unwords.map show)) a
    putStrLn $ (unwords.map show) b
    

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

int main() {
    int P, Q, R;
    cin >> P >> Q >> R;
    int a, b, c;
    a = P + Q;
    b = P + R;
    c = Q + R;
    cout << min(a, min(b, c)) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
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(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

struct Trie{
    struct Node{
        Node *ptr[26];
        int cnt[26];
        Node(){
            rep(i, 26){
                ptr[i] = nullptr;
                cnt[i] = 0;
            }
        }
    };

    Node *root;
    Trie(){
        root = new Node;
    }

    void add(string &s, vector<int> &a){
        Node *t = root;
        rep(c, 26)if(a[0] >> c & 1) t->cnt[c]++;
        rep(i, s.size()){
            if(!t->ptr[s[i] - 'a']) t->ptr[s[i] - 'a'] = new Node;
            rep(c, 26)if(a[i+1] >> c  & 1){
                t->ptr[s[i] - 'a']->cnt[c]++;
            }
            t = t->ptr[s[i] - 'a'];
        }
    }

    int query(string &s){
        Node *t = root;
        rep(i, (int)s.size()-1){
            t = t->ptr[s[i] - 'a'];
        }
        return t->cnt[*s.rbegin() - 'a'];
    }

    void _print(Node *t){
        rep(i, 26) printf("%d ", t->cnt[i]);
        printf("\n");
        rep(i, 26)if(t->ptr[i]){
            printf("%c\n", i + 'a');
            _print(t->ptr[i]);
        }
    }

    void print(){
        _print(root);
    }
};

int main(){
    int n;
    scanf("%d", &n);
    string s[n];
    Trie tr;
    rep(i, n){
        cin >> s[i];
        reverse(s[i].begin(), s[i].end());
        vector<int> a((int)s[i].size() + 1, 0);
        rep(j, s[i].size()) a[j] = (1 << (s[i][j] - 'a'));
        rrep(j, s[i].size()) a[j] |= a[j+1];

        tr.add(s[i], a);
    }
    lint ans = 0;
    rep(i, n) ans += tr.query(s[i]) - 1;
    printf("%lld\n", ans);
}

Measured memory_bytes: 317376
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 29)
using namespace std;

const int kN = 105;
int atl[kN][kN];

void warshallFloyd(int n){
    range(k,1,n + 1){
        range(i,1,n + 1){
            range(j,1,n + 1){
                atl[i][j] = min(atl[i][j], atl[i][k] + atl[k][j]);
            }
        }
    }
}

int requestCost(int n, int s, int g1, int g2){
    int retval = INF;
    range(i,1,n + 1){
        int cost = atl[s][i] + atl[i][g1] + atl[i][g2];
        retval = min(retval, cost);
    }
    return retval;
}

int main(){
    int n, m, s, g1, g2;
    while(cin >> n >> m >> s >> g1 >> g2, n||m||s||g1||g2){
        rep(i,kN) rep(j,kN) atl[i][j] = INF;
        rep(i,kN) atl[i][i] = 0;
        rep(i,m){
            int a, b, c;
            cin >> a >> b >> c;
            atl[a][b] = c;
        }
        warshallFloyd(n);
        cout << requestCost(n, s, g1, g2) << endl;
    }
}

Measured memory_bytes: 1204
def read_path():
    m = int(raw_input())
    return [complex(*[int(_) for _ in raw_input().split()]) for __ in xrange(m)]


def is_cong(p1, p2):
    l = len(p1)
    if l != len(p2):
        return False
    r = (p1[1] - p1[0]) / (p2[1] - p2[0])
    if r not in (1, 1j, -1, -1j):
        return False
    for i in xrange(1, l - 1):
        if (p1[i + 1] - p1[i]) / (p2[i + 1] - p2[i]) != r:
            return False
    return True


while True:
    n = int(raw_input())
    if n == 0:
        break
    p0 = read_path()
    p0r = list(reversed(p0))
    for i in xrange(1, n + 1):
        p = read_path()
        if is_cong(p0, p) or is_cong(p0r, p):
            print i
    print "+++++"

Measured memory_bytes: 6316
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
  const int mx = 110000;
  bool s[mx]; fill(s, s+mx, false); s[0] = s[1] = true;
  for(int i=2; i<mx; i++) {
    if (s[i]) continue;
    for(int j=2*i; j<mx; j+=i) {
      s[j]=true;
    }
  }
  int x; cin >> x; int i=x;
  for(i; i<mx && s[i]; i++);
  cout << i << endl;
}

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

using namespace std;

const int N = 2e5+1;

int n;
int a[N], b[N], s[N];

vector<int> d[N];
void init(){
    for(int j = 1; j < N; ++j)
        for(int i = j+j; i < N; i += j)
            d[i].push_back(j);
}

int main(){
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    init();
    cin >> n;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
    int cnt = 0;
    for(int i = n; i >= 1; --i){
        int sum = 0;
        if(s[i] != a[i]){
            b[i] ^= 1;
            for(int j : d[i])
                s[j] ^= 1;
        }
        cnt += b[i];
    }
    cout << cnt << '\n';
    for(int i = 1; i <= n; ++i)
        if(b[i]) cout << i << ' ';
    cout << '\n';
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> A(H);
  for (int i = 0; i < H; i++) {
    cin >> A.at(i);
  }

  vector<vector<char>> data(H+2, vector<char>(W+2, '#'));

  for (int i = 1; i < H+1; i++) {
    for (int j = 0; j < W+2; j++) {
      if (j != 0 && j != W+1) {
        data.at(i).at(j) = A.at(i-1).at(j-1);
      }
    }
  }
  
  for (int i = 0 ; i < H+2; i++) {
    for (int j = 0; j < W+2; j++) {
      cout << data.at(i).at(j);
      if ( j == W+1 ) {
        cout << endl;
      }
    }
  }
}


Measured memory_bytes: 256
n,k = map(int,input().split())
arr = list(map(int,input().split()))
d = {}
for a in arr:
    if a not in d:
        d[a] = 1
    else:
        d[a]+=1

if len(d) < k+1:
    print(0)
else:
    sup = len(d)-k
    a = []
    for k in d.keys():
        a.append(d[k])
    a.sort()
    # print(a)
    ans = sum(a[:sup])
    print(ans)


Measured memory_bytes: 33312
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int INF = 100000000;
int i,j,k;
int main(){
    string s,t;cin>>s>>t;
 
    vector<int> start(26,-1),goal(26,-1);//変換表
    for(i=0;i<s.size();i++){
        int a=(int)(s[i]-'a');
        int b=(int)(t[i]-'a');

        if(start[a]!=-1 || goal[b]!=-1){//変換済み
            if(start[a]!=b || goal[b]!=a){//単射でなくてはならないのでこの場合はおかしい
                cout<<"No"<<endl;
                return 0;
            }
        }
        else{//変換されていないなら、変換する
            start[a]=b;
            goal[b]=a;
        }
    }

    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 776
## main

n = gets.strip.to_i

n.times do
  bits = sprintf("%032b", gets.strip.to_i(16))
  #p bits

  s = (bits[0] == '1' ? '-' : '')
  i = bits[1, 24].to_i(2)
  f = bits[25, 7].to_i(2).to_f / 128
  puts "#{s}#{i + f}"
end

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

#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(0);
#define rep(i,a,n) for(int i=a;i<n;i++)
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define pii pair<int,int>
#define UMP(x,y) unordered_map<x,y>
#define MP(x,y) map<x,y>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define inf 1e18
#define endl "\n"
#define coutd(n) cout << fixed << setprecision(n)
#define watch(x) cout<<#x<<" = "<<x<<endl;
typedef double db;
typedef long double ld;	
const int mod = 1000000007;

using namespace std;

int32_t main(){
    fast
    
	int n,k;
	cin>>n>>k;
	map<int,int> mapping;
	rep(i,0,k){
		int a;
      	cin>>a;
		rep(i,0,a){
			int b;
			cin>>b;
			mapping[b]++;
		}
	}
	int count=0;
	rep(i,0,n){
		if(!mapping[i+1])
			count++;
	}
	cout<<count;
	
    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  ll a,b,v,w,t;
  cin >> a >> v >> b >> w >> t;

  cout << ( (a < b ? ( a + v * t >= b + w * t ? "YES" : "NO") : (a - v * t <= b - w * t ? "YES" : "NO"))) << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>

//#include <iomanip>

using ll = unsigned long long;
#define rep(i,n) for(int i = 0;i < (n);++i)
#define drep(i,n) for(int i = (n)-1;i >= 0;--i)
#define srep(i,s,t) for(int i = s;i < t;++i)

constexpr ll INF = 1001002003004005006ll;

int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  rep(i,n) std::cin >> a[i];
  std::vector<ll> s(n+1);
  s[0] = 0;
  rep(i,n) s[i+1] = a[i]+s[i];

  std::vector<std::vector<ll>> dp(n, std::vector<ll>(n,INF));
  drep(l,n) srep(r, l, n) {
    if (l == r) dp[l][r] = 0;
    else {
      srep(k,l,r) {
        dp[l][r] = std::min(dp[l][r], dp[l][k]+dp[k+1][r]+(s[r+1]-s[l]));
      }
    }
  }
  std::cout << dp[0][n-1] << '\n';
}


Measured memory_bytes: 1536
#!/usr/bin/env python3
#EDPC D

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,W = LI()
wv = [LI() for _ in range(n)]
dp = [[0]*(W+1) for _ in range(n+1)]
for i in range(n):
    w,v = wv[i]
    for j in range(W+1):
        if j < w:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j],dp[i][j-w] + v)
print(max(dp[-1]))

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

using namespace std;

bool is_coffee(const string &s) {
  return s[2] == s[3] && s[4] == s[5];
}

int main() {
  string s;
  cin >> s;
  cout << (is_coffee(s) ? "Yes" : "No");

  return 0;
}


Measured memory_bytes: 256