akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<functional>
#include<vector>
#include<queue>
using namespace std;
#define f(i,n) for(int i=0;i<(int)n;i++)
#define MOD 1000000009

int main(void){
	char a[100];
	f(i, 100)a[i] = 0;
	int w,x, y, z;

	scanf("%s", a);
	w = a[0] - 48;
	x = a[1] - 48;
	y = a[2] - 48;
	z = a[3] - 48;
	if (w + x + y + z == 7){
		printf("%d+%d+%d+%d=7\n", w, x, y, z);
	}
	else if (w + x + y - z == 7){
		printf("%d+%d+%d-%d=7\n", w, x, y, z);
	}
	else if (w + x - y + z == 7){
		printf("%d+%d-%d+%d=7\n", w, x, y, z);
	}
	else if (w + x - y - z == 7){
		printf("%d+%d-%d-%d=7\n", w, x, y, z);
	}
	else if (w - x + y + z == 7){
		printf("%d-%d+%d+%d=7\n", w, x, y, z);
	}
	else if (w - x + y - z == 7){
		printf("%d-%d+%d-%d=7\n", w, x, y, z);
	}
	else if (w - x - y + z == 7){
		printf("%d-%d-%d+%d=7\n", w, x, y, z);
	}
	else if (w - x - y - z == 7){
		printf("%d-%d-%d-%d=7\n", w, x, y, z);
	}
	return 0;
}



Measured memory_bytes: 128
// inputに入力データ全体が入る
function Main(input) {
	ans = -1
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.trim().split("\n");
	var e = input[0].split(' ').map((n) => (parseInt(n)))[0]
	var t = input[0].split(' ').map((n) => (parseInt(n)))[1]
	var earr = []
	var tarr = []
	var m = 10000
	for (i = e *10; i <= m; i++) {
		if (Math.floor(i * 0.08) == e && Math.floor(i * 0.1) == t) {
			ans = i
			break
		}
	}

	//出力
	console.log(ans)
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
// Main(require('fs').readFileSync('./input.txt', 'utf-8'));

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

int N;
int lt, lx, ly, t, x, y;
bool works;

int main() {
	works = 1;
	cin.tie(0); ios_base::sync_with_stdio(0);

	cin >> N;
	while (N--) {
		cin >> t >> x >> y;

		int mt = abs(x - lx) + abs(y - ly);
		if (t - lt < mt) works = 0;
		if ((t - lt) % 2 != mt % 2) works = 0;

		lt = t; lx = x; ly = y;
	}

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

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

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> inp(N),outp(N);
    REP(i,N)cin >> inp[i];
    int count = 0;
    for(int i = N;i>0;i--){
        int before = 0;
        for(int l = 1;i*l<N+1;l++){
            before += outp[l*i-1];
        }
        if((before%2) == inp[i-1]){
            outp[i-1] = 0;
        }else{
            outp[i-1] = 1;
            count++;
        }
    }
    cout <<count<< "\n";
    REP(i,N){
        if(outp[i] == 1)cout<< i+1 << "\n";
    }
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    int Q;
    cin>>Q;
    while(Q--) {
	int A=gi(),B=gi(),C=gi(),D=gi(),k=(max(A,B)-1)/(min(A,B)+1)+1;
	int l=1,r=A+B,a,b;
	while(l<=r) {
	    int mid=(l+r)>>1;
	    a=A-mid/(k+1)*k-mid%(k+1),b=B-mid/(k+1);
	    if(mid%(k+1)) ++a;
	    if(1LL*a*k>=b) l=mid+1;
	    else r=mid-1;
	}
	a=A-r/(k+1)*k-r%(k+1),b=B-r/(k+1);
	if(r%(k+1)||!r) ++a;
	l=r+b-1LL*a*k;
	for(int i=C;i<=min(r,D);i++) putchar(i%(k+1)?'A':'B');
	for(int i=max(C,r+1);i<=D;i++) putchar((i-l)%(k+1)?'B':'A');
	puts("");
    }
    return 0;
}

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

typedef long long ll;

ll N;
vector<vector<ll>> A;

ll solve() {
  ll res = 0;
  for (ll i = 0; i < N; ++i)
    for (ll j = i + 1; j < N; ++j) {
      bool needed = true;
      for (ll k = 0; k < N; ++k) {
        if (k == i || k == j) continue;
        if (A[i][j] > A[i][k] + A[k][j]) return -1;
        if (A[i][j] == A[i][k] + A[k][j]) {
          needed = false;
          break;
        }
      }
      if (needed) res += A[i][j];
    }
  return res;
}
int main() {
  cin >> N;
  A.resize(N);
  for (auto &a : A) a.resize(N);
  for (ll i = 0; i < N; ++i)
    for (ll j = 0; j < N; ++j) cin >> A[i][j];
  cout << solve() << endl;
  return 0;
}


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

int main() {
    int N;
    cin >> N;
    int A[N], B[N];
    for(int i = 0; i < N; i++) {
        B[i+1] = 0;
    }
    for(int i = 2; i <= N; i++) {
        cin >> A[i];
        B[A[i]]++;
    }
    for(int i = 0; i < N; i++) {
        cout << B[i+1] << endl;
    }
}


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

int main() {
  int K,T; cin >> K >> T;
  vector<long long> a(T);
  long long mx = 0;
  for(int i = 0; i < T; i ++)cin >> a[i],mx = max(a[i],mx);
  cout << max(mx - 1 - (K - mx), 0LL) << endl;

}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); i++)
#define repi(i,a,b) for (int i=a;i<(b);i++)
#define SIZE_OF_ARRAY(a) (sizeof(a)/sizeof(a[0]))
using namespace std;
typedef long long ll;
  
  int main(void){
    cin.tie(0); //cin高速化
    ios::sync_with_stdio(false); //cin高速化
	int m;
    cin >> m;
    cout << (24-m)+24 << endl;
    return 0;
  } 

Measured memory_bytes: 256
#include<stdio.h>

int main(void){

int a,b,d,r;

double f;


scanf("%d %d",&a,&b);

if(1<=a,b<=1E+9){

d=a/b;


r=a%b;


f=(double)a/(double)b;


printf("%d %d %lf\n",d,r,f);

}

return 0;

}

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

const int maxn = 500010;
int n, pre[maxn], suf[maxn]; char s[maxn];
long long ans;

int main() {
    scanf("%s", s + 1), n = strlen(s + 1) + 1;
    for (int i = 1; i < n; i++) {
        if (s[i] == '>') pre[i] = 0;
        else pre[i] = pre[i - 1] + 1;
    }
    for (int i = n - 1; i; i--) {
        if (s[i] == '<') suf[i] = 0;
        else suf[i] = suf[i + 1] + 1;
    }
    for (int i = 1; i <= n; i++) {
        ans += max(pre[i - 1], suf[i]);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 4608
use std::io;
use std::cmp::Ordering;


fn main() {
    let (a, b) = {
        let i = read::<isize>();
        (i[0], i[1])
    };
    let op = match a.cmp(&b) {
        Ordering::Less => "<",
        Ordering::Equal => "==",
        Ordering::Greater => ">"
    };
    println!("a {} b", op);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}


Measured memory_bytes: 5020
// Sky's the limit :)
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    
    int T = 1; 
    // cin >> T; 
    while (T--) {
        int n;
        string s;
        cin >> n >> s;

        map<char, int> mp;
        for(auto c : s)
            mp[c]++;

        int ans = mp['R'] * mp['G'] * mp['B'];
        s = '#' + s;
        for(int i = 2; i <= n - 1; i++) {
            for(int j = 1; j <= n; j++) {
                int x = i - j;
                int y = i;
                int z = i + j;
                // cout << x << ' ' << y << ' ' << z << '\n';
                if(1 <= x && z <= n && s[x] != s[y] && s[y] != s[z] && s[z] != s[x]) {
                    // cout << x << ' ' << y << ' ' << z << '\n';
                    ans--;
                }
            }
        }

        cout << ans << '\n';
        
    }
    
    return 0;
}



Measured memory_bytes: 3628
N, M = map(int, input().split())
A = [int(x) for x in input().split()]
s = sum(A)
m = s / (4 * M)
B = []
cnt = 0
for a in A:
    if a < m:
        pass
    else:
        cnt += 1
if cnt >= M:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
local function reada(n,m)m=m or 1 r={}for i=1,m do r[i]={}end for i=1,n do for j=1,m do r[j][i]=io.read"*n"end end return unpack(r)end

local a
for i=1,5 do
if(io.read"*n"==0)then a=i break end
end
print(a)

Measured memory_bytes: 2712
n = int(input())
a = [ int(_) for _ in input().split() ]
b = [ int(_) for _ in input().split() ]
c = [ int(_) for _ in input().split() ]

a = [ _-1 for _ in a ]

ans = 0

for x in a:
	ans += b[x]
    
for j in range(len(a)-1):
	if a[j+1] == a[j] + 1:
		ans += c[a[j]]
        
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l,i##end=r;i<=i##end;++i)
#define per(i,r,l) for (int i=r,i##end=l;i>=i##end;--i)
#define pb push_back
#define ll long long
using namespace std;
const int N=2e5+5;
struct line{ int k,b; ll f(int x){ return (ll)k*x+b; } }a[N];
int b[N],dp[N];
bool cmp(line a,line b){ return (ll)(b.k-1)*a.b<(ll)(a.k-1)*b.b; }
int main(){
    int n,t,m=0; scanf("%d%d",&n,&t); ++t;
    for (int i=1;i<=n;++i){
        scanf("%d%d",&a[i].k,&a[i].b); ++a[i].k,++a[i].b;
        if (a[i].k==1) --n,b[++m]=a[i--].b;
    }
    sort(a+1,a+1+n,cmp);
    int mx=0; dp[0]=1;
    rep(i,1,n){
        ll x=a[i].f(dp[mx]);
        per(j,mx,1) dp[j]=min((ll)dp[j],a[i].f(dp[j-1]));
        if (x<=(ll)t) dp[++mx]=x;
    }
    sort(b+1,b+1+m);
    int ans=0,j=0,s=0;
    per(i,mx,0){
        while (j<m&&(ll)dp[i]+s+b[j+1]<=(ll)t) s+=b[++j];
        ans=max(ans,i+j);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
const double PI  = 3.1415926535897932384626433832795028841971;
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

int n, m, l;
int dp[5][41][9];
vector<PP> x[5];

int main(){
    cin >> n >> m >> l;
    rep(i,m){
        int d, a, k, t;
        cin >> d >> a >> k >> t;
        x[d].push_back(PP(a+k-1,P(a,t)));
    }
    rep(i,5) sort(x[i].begin(),x[i].end());
    rep(i,5){
        rep(j,x[i].size()){
            for(int u = l-1; u >= 0; u--){
                dp[i][u+1][x[i][j].first] = max(dp[i][u+1][x[i][j].first],dp[i][u][x[i][j].second.first-1]+x[i][j].second.second);
                for(int v = x[i][j].first; v < 8; v++) dp[i][u+1][v+1] = max(dp[i][u+1][v+1],dp[i][u+1][v]);
            }
        }
    }
    int ans[5][41];
    rep(i,5) rep(j,41) ans[i][j] = 0;
    rep(i,l+1) ans[0][i] = dp[0][i][8];
    for(int i = 1; i < 5; i++){
        rep(u,l+1){
            rep(v,l+1){
                if(u+v > l) continue;
                ans[i][u+v] = max(ans[i][u+v],ans[i-1][u]+dp[i][v][8]);
            }
        }
    }
    cout << ans[4][l] << endl;
}

Measured memory_bytes: 1216
#include <cstdio>
#include <map>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

const int MX = 6300500;
const int SZ = 3500;

#define pii pair<int,int>
pair<pii, pii> r[MX];

int gcd(int x, int y){
    while(x > 0 && y > 0){
        if(x > y) x %= y; else y %= x;
    }
    return x + y;
}

bool cmp(const pair<pii,pii> &x, const pair<pii,pii> &y){
//    return x.first.first / x.first.second < y.first.first / y.first.second;
    return (long long)x.first.first * y.first.second  < (long long)y.first.first  * x.first.second;
}

int main(int argc, char** argv)
{
//    freopen("/Users/melnykroman/CLionProjects/cf/in.txt", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int k = 0;
    for(int a = 1; a <= SZ; a++){
        for(int b = a; b <= SZ; b++){
            r[k++] = {{a + b, a * b},{a, b}};
        }
    }
    sort(r, r + k, cmp);

    int n;
    cin >> n;

    int pos = k - 1;


    for(int c = SZ - 1; c > 0; c--){
        while(pos >= 0){
            long long x = r[pos].first.first;
            long long y = r[pos].first.second;
            long long p = x * c + y;
            long long q = y * c;
//            if(p / q == 4 / n)
            if(p * n == 4 * q) {
                cout << r[pos].second.first << ' ' << r[pos].second.second << ' ' << c << endl;
                return 0;
            }
            if(p * n < 4 * q) break;
//            if(r[pos].second == make_pair(3498, 3498))
//                cerr << c << ' ' << p << ' ' << q  << endl;
            pos--;
        }
    }

    return 0;
}

Measured memory_bytes: 96512
#include<iostream>
#include<set>
using namespace std;
int main(){
  char s[3];for(int i=0;i<3;i++)cin>>s[i];
  set<char> list;for(int i=0;i<3;i++)list.insert(s[i]);
  if(list.size()==3)cout<<"Yes"<<endl;else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        siz.assign(sz_, 1LL);  // assign: 再代入
        par.resize(sz_);  // resize: 再確保
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main() {
  int N,M,K;cin>>N>>M>>K;
  vector<vector<int>> grp(N,vector<int>());
  UnionFind tree(N);
  rep(i,M) {
    int a,b;cin>>a>>b;
    a--;b--;
    grp[a].push_back(b);
    grp[b].push_back(a);
    tree.merge(a,b);
  }
  vector<int> block(N,0);
  rep(i,K) {
    int a,b;cin>>a>>b;
    a--;b--;
    if(tree.issame(a,b)) {
      block[a]++;
      block[b]++;
    }
  }
  rep(i,N) {
    cout<< tree.size(i) - grp[i].size() - block[i] - 1 << " ";
    if(i==N-1) cout<<endl;
  }
}


Measured memory_bytes: 11116
#include <bits/stdc++.h>
#define ll long long int
#define FASTIO std::ios::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define inf 1e18
#define err(x) cout<<x<<endl
#define all(x) x.begin(),x.end()
#define input_from_file  freopen("input.txt", "r", stdin);



using namespace std;
int main()
{

    FASTIO
    ll n;
    cin >> n;
    vector <pair<ll,ll> > ve;
    vector <pair<ll,ll> > ve2;
    for(ll i=0;i<n;i++)
    {
        ll u,v;
        cin>>u>>v;
        ve2.pb({u,v});
        ve.pb({v,i});
    }
    sort(all(ve));
    ll curr = 0;
    bool ok  = true;
    for(ll i=0;i<n;i++)
    {
        curr+=ve2[ve[i].S].F;
        if(curr > ve2[ve[i].S].S)
        {
            ok = false;
            break;
        }
    }
    if(ok)
    cout<<"Yes";
    else
    cout<<"No";



cout << endl ;
return 0;
}


Measured memory_bytes: 10592
chr_dict = {chr(ord('a') + i) : 0 for i in range(26)}

import sys
input_lines = sys.stdin.readlines()
for line in input_lines:
    for s in line:
        if s.lower() in chr_dict:
            chr_dict[s.lower()] += 1

print(*[f"{key} : {value}" for key,value in chr_dict.items()],sep="\n")


Measured memory_bytes: 5584
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def putsd(str)
  puts str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

nn = inputs[0][0]

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if $debugFlag
end


def find6(n)
  ret = 1
  while n >= ret*6
    ret *= 6
  end
  return ret
end

def find9(n)
  ret = 1
  while n >= ret*9
    ret *= 9
  end
  return ret
end

$hh = {}
def rec(n, d)
  return d if n == 0
  return $hh["#{n},#{d}"] if $hh["#{n},#{d}"] != nil
  
  n6 = find6(n)
  n9 = find9(n)

  $hh["#{n},#{d}"] = [rec(n - n6, d + 1), rec(n - n9, d + 1)].min 
  return $hh["#{n},#{d}"]
end

puts rec(nn, 0)


Measured memory_bytes: 1916
#!/usr/bin/python
# -*- coding: utf-8 -*-

from collections import defaultdict

n=int(raw_input())
v=[int(x) for x in raw_input().split()]

a,b = defaultdict(lambda: 0), defaultdict(lambda: 0)
for i, val in enumerate(v):
	if i%2 == 1:
		a[val] += 1
	else:
		b[val] += 1
a[-1] = 0
b[-2] = 0
aa = sorted([(y,x) for x, y in a.iteritems()], reverse=True)
bb = sorted([(y,x) for x, y in b.iteritems()], reverse=True)
# print aa, bb
if aa[0][1] != bb[0][1]:
	print n - (aa[0][0] + bb[0][0])
else:
	print n - max((aa[0][0] + bb[1][0]), (aa[1][0] + bb[0][0]))


Measured memory_bytes: 56304
//#include "stdafx.h"
#include<bits/stdc++.h> 
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
/*int gcd(int n,int m)
{
	if(m==0)
		return n;

	return gcd(m, n % m);
}*/
int a,b,x;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	cin>>a>>b>>x;
	if(x<a||x>=(a+b))cout<<"NO\n";
	else 
		cout<<"YES\n";

	return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)

char s[200010];
ll ptr[100010];

char t[200010];
ll tlen;
ll ans;
ll err;

void nxt(){
	//tを、tlen文字以下であって辞書順でtの直後にあたる文字列に置き換える
	//そのようなものが存在しなければ(⇔tが1のみからなる文字列なら)errフラグを立てる
	while(tlen>0&&t[tlen-1]=='1')tlen--;
	if(tlen==0)err=1;
	t[tlen-1]='1';
	t[tlen]=0;
}

int cmp(const void*a,const void*b){
	return strcmp(s+*(ll*)a,s+*(ll*)b);
}
int main(){
	ll n,k;
	scanf("%lld%lld",&n,&k);
	rep(i,0,n){
		scanf("%s",s+ptr[i]);
		ptr[i+1]=ptr[i]+strlen(s+ptr[i])+1;
	}
	qsort(ptr,n,sizeof(ll),cmp);
	s[ptr[n]]='2';//番兵
	
	
	ll i=0;
	while(!err){
		//strcmpの計算量大丈夫？
		if(!strcmp(t,s+ptr[i])){
			//完全に一致するなら次へ
			i++;
			nxt();
		}else if(!strncmp(t,s+ptr[i],tlen)){
			//prefixなら下へ潜る
			t[tlen++]='0';
			t[tlen]=0;
		}else{
			//prefixでないなら、ここは使える部分木の根
			//grundy数を更新して次へ
//			puts(t);fflush(0);
			ll temp=k-tlen+1;
			ans^=(temp&-temp);
			nxt();
		}
	}
	//printf("%lld ",ans);
	puts(ans?"Alice":"Bob");
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
using namespace std;

struct Node{
  struct Node *right;
  struct Node *left;
  struct Node *parent;
  int key;
};

Node *root,*NIL;

Node *treeMinimum(Node *x){
    while(x->left!=NIL)x=x->left;
    return x;
}

Node *treeMaximum(Node *x){
    while(x->right!=NIL)x=x->right;
    return x;
}

Node *treeSearch(Node *u, int k){
    while(u!=NIL && k!=u->key){
        if(k<u->key)u=u->left;
        else u=u->right;
    }
    return u;
}

Node *treeSuccessor(Node *x){
    if(x->right!=NIL)return treeMinimum(x->right);
    Node *y=x->parent;
    while(y!=NIL&&x==y->right){
        x=y;
        y=y->parent;
    }
    return y;
}

void treeDelete(Node *z){
  Node *y;
  Node *x;
  
  if(z->left==NIL||z->right==NIL)y=z;
  else y=treeSuccessor(z);
  
  if(y->left!=NIL){
      x=y->left;
  }else{
      x=y->right;
  }
  
  if(x!=NIL){
      x->parent=y->parent;
  }
  
  if(y->parent==NIL){
      root=x;
  }else{
      if(y==y->parent->left){
          y->parent->left=x;
      }else{
          y->parent->right=x;
      }
  }
  
  if(y!=z){
      z->key=y->key;
  }
  
  free(y);
}

void insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node*)malloc(sizeof(struct Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x!=NIL){
      y=x;
      if(z->key<x->key){
          x=x->left;
      }else{
          x=x->right;
      }
  }
  z->parent=y;
  if(y==NIL){
      root=z;
  }else{
      if(z->key<y->key){
          y->left=z;
      }else{
          y->right=z;
      }
  }
}

void inorder(Node *u){
    if(u==NIL)return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node *u){
    if(u==NIL)return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node *t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}


Measured memory_bytes: 21884
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,tmp;
    vector<int>num;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>tmp;
        num.push_back(tmp);
    }
    int mmin=num[0];
    int ans=1;
    for(int i=1;i<n;i++)
    {
        if(num[i]<=mmin)
        {
            ans++;
            mmin=(mmin,num[i]);
        }
    }
    cout<<ans;
}


Measured memory_bytes: 1400
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Set;
public class Main {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve() {
		int n = ni();
		Set<String> set = new HashSet<>();
		for(int i = 0; i < n; i++) {
			set.add(ns());
		}
		out.println(set.size());
	}


	void run() throws Exception {
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if (!INPUT.isEmpty())
			tr(System.currentTimeMillis() - s + "ms");
	}

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

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	private double nd() {
		return Double.parseDouble(ns());
	}

	private char nc() {
		return (char) skip();
	}

	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}

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

void factorization(long long n,map<long long ,long long>& mp){
    for(long long i=2;i*i<=n;i++){
        while(n%i==0){
            mp[i]++;
            n /= i;
        }
      }
      if(!(n == 1)) mp[n]++;
}

int main() {
  ll n,m;
  cin>>n;
  m=n;
  map<ll,ll> mp;
  if(n==1){
    cout<<0<<endl;
    return 0;
  }
  factorization(n,mp);
  if(mp[m]==1){
    cout<<1<<endl;
    return 0;
  }
  int ans=0;
  for(auto x : mp){
    if(x.first==1)break;
    for(int i=1; i<=100; i++){
      x.second-=i;
      ans++;
      if(x.second<=i)break;
    }
  }
  cout<<ans-1<<endl;
}

Measured memory_bytes: 3616
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int edge[3],rec = 0,loz = 0;
	for(;;){
		if(scanf("%d,%d,%d",&edge[0],&edge[1],&edge[2]) == EOF){break;}
		if(edge[2]*edge[2] == edge[1]*edge[1] + edge[0]*edge[0]){rec++;}
		else if(edge[0] == edge[1]){loz++;}
	}
	cout<<rec<<endl<<loz<<endl;
	return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>(b);--i)
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
  ll n,m,ans1=0,ans2=0;cin>>n>>m;
  vb ok(n,false);vll miss(n,0);
  rep(i,0,m){
    ll p;string s;
    cin>>p>>s;
    p--;
    if(s=="AC"){ok[p]=true;}
    else{
      if(!ok[p]){miss[p]++;}
    }
  }
  rep(i,0,n){
    if(ok[i]){ans1++;ans2+=miss[i];}
  }
  cout<<ans1<<" "<<ans2<<endl;
}




Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define per(i,j,n) for(int i=(int)(j);(int)(n)<=i;i--)
#define int long long
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define endl "\n"
#define vi vector<ll>
#define pii pair<ll,ll>
#define vii vector<vi>
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=(1ll<<62)-1;
signed main(){
  string S; cin>>S;
  S=S.substr(0,3);
  cout<<S<<endl;
}

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

int main() {
    std::string sample_str;
    std::string target_str;
    std::cin >> sample_str;
    std::cin >> target_str;

    if (sample_str.length() < target_str.length()) {
        return 0;
    }
    for (int i = 0; i < sample_str.length() - target_str.length() + 1; i++) {
        int count = 0;
        for (int j = 0; j < target_str.length(); j++) {
            if (sample_str[i + j] == target_str[j]) {
                count++;
            } else {
                break;
            }
        }
        if (count == target_str.length()) {
            std::cout << i << std::endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3244
#list(map(int,input().split()))
s=input()
n=len(s)
if n%2==1:
    print("No")
else:
    ans="Yes"
    for i in range(n):
        if i%2==1 and s[i]!="i":
            ans="No"
        if i%2==0 and s[i]!="h":
            ans="No"
    print(ans)


Measured memory_bytes: 38384
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
template<typename T>
bool all_same(vector<T> v1,vector<T> v2)
{
    sort(ALL(v1));
    sort(ALL(v2),greater<T>());
    return v1 == v2;
}
   
// g++ -std=c++11 prac.cpp
ll Max=-1e9,Min=1e9+1;

int main(){
    ll b,d,x=0,y=0,z,n,m,k,lank=1,w,sum=0,sum2=0,ans=0;
    string s,t;
    bool ok=true;
    cin >> n;   
    VI a(n*3);
    rep(i,n*3){
        cin >> a[i];
    }
    sort(ALL(a));
    int i = 3*n-2;
    while(n>0){
        ans += a[i];
        i-=2;
        n--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>

int main(void){
  int A,B,C,K;
  scanf("%d %d %d %d",&A,&B,&C,&K);
int t=0;
  for(int i=1;i<=K;i++){
    if(A>0){
      A--;
      t++;
  }else if(B>0){
      B--;
    }else if(C>0){
      C--;
      t--;
    }
  }
  printf("%d",t);
  return 0;
}

Measured memory_bytes: 1708
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	var n int
	n = nextInt()

	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}

	s, ans := selectionSort(a, n)

	printSlice(s)
	fmt.Println(ans)

}

func printSlice(s []int) {
	length := len(s)
	for i, v := range s {
		if i == length-1 {
			fmt.Printf("%d\n", v)
		} else {
			fmt.Printf("%d ", v)
		}
	}

}

func selectionSort(a []int, n int) ([]int, int) {
	ans := 0
	for i := 0; i < n-1; i++ {
		mini := i
		for j := i; j < n; j++ {
			if a[mini] > a[j] {
				mini = j
			}
		}
		minv := a[mini]
		a[mini] = a[i]
		a[i] = minv
		if i != mini {
			ans++
		}
	}

	return a, ans

}



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

int main(void)
{
    int num;
    int count5, count7;
    count5 = count7 = 0;
    for (int i = 0; i < 3; i++)
    {
        cin >> num;
        if (num == 5)
        {
            count5++;
        }
        else if (num == 7)
        {
            count7++;
        }
    }
    if (count5 == 2 && count7 == 1)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    
    
    
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };



int main()
{
	int T;
	cin >> T;
	while (T--)
	{
		int x, y, w, h;
		cin >> x >> y >> w >> h;
		int n;
		cin >> n;
		int res = 0;
		while (n--)
		{
			int a, b;
			cin >> a >> b;
			if (x <= a && a <= x + w
				&& y <= b && b <= y + h)
				++res;
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 0
from math import sqrt
n,d=map(int, input().split())
l=[input().split() for i in range(n)]
c=0
d2=0
for i in range(n):
  for j in range(i+1,n):
    s=0
    for k in range(d):
      s+=(int(l[i][k])-int(l[j][k]))**2
    if sqrt(s).is_integer():
      c+=1
print(c)



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

int main(){
  int A,B,C,X,count = 0;
  cin >> A >> B >> C >> X;
  
  for(int i = 0;i <= A;i++){
    for(int j = 0;j <= B;j++){
      for(int k = 0;k <= C;k++){
        if(X == 500 * i + 100 * j + 50 * k){
          count++;
        }
      }
    }
  }
  
  cout << count << endl;
}       

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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める

int main(){
    int N;
    cin >> N;
    int amari = N%1000;
    if(amari == 0){
        cout << 0 << endl;
    }else{
        cout << 1000 - amari << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=500010;

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

    ll a,b,m;
    cin>>a>>b>>m;
    ll ar[a],br[b];
    for(ll i=0;i<a;++i){cin>>ar[i];}
    for(ll i=0;i<b;++i){cin>>br[i];}
    ll ans=INT_MAX;
    for(ll i=0;i<m;++i)
    {
        ll c,d,x;
        cin>>c>>d>>x;
        ans=min(ans,ar[c-1]+br[d-1]-x);
    }
    sort(ar,ar+a);
    sort(br,br+b);
    ans=min(ans,ar[0]+br[0]);
    cout<<ans;

	return(0);
}


Measured memory_bytes: 1792
using System;
using System.Linq;

class ALDS1_1A
{
    static void Main()
    {
        int a = int.Parse(Console.ReadLine());
        int[] x = new int[a];
        string str = Console.ReadLine();
        for (int i = 0; i < a; i++)
        {
            x[i] = int.Parse(str.Split(' ')[i]);
        }
        int b, j;
        for (int i = 0; i < a; i++)
        {
            b = x[i];
            j = i - 1;
            while (j >= 0 && x[j] > b)
            {
                x[j + 1] = x[j];
                j--;
                x[j + 1] = b;
            }
            for (int k = 0; k < a; k++)
            {
                if (k == a - 1)
                {
                    Console.WriteLine(x[k]);
                }
                else Console.Write(x[k] + " ");
            }
        }
    }
}
    

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

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, a, b;
	cin >> n >> a >> b;
	int k = a + b;
	cout << (n / k) * a + min(a, (n % k)) << '\n';
}


Measured memory_bytes: 256
// C - Connect Cities
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;

int main(){
	int n, m; cin>>n>>m;
	dsu d(n);
	while(m--){
		int a, b; cin>>a>>b;
		d.merge(a-1, b-1);
	}
	cout<< d.groups().size() - 1 <<endl;
}


Measured memory_bytes: 8892
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
	// write your code here
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
        StringTokenizer st;
        //knapsack probk
        st = new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());
        int [] val = new int[N+1];
        int [] wt = new int[N+1];
        int W = Integer.parseInt(st.nextToken());
        long [][] K  = new long[N+1][W+1];
        for (int i=0;i<N;i++){
            st = new StringTokenizer(br.readLine());
            wt[i] = Integer.parseInt(st.nextToken());
            val[i] = Integer.parseInt(st.nextToken());
        }
        for (int i=0;i<=N;i++){
            for (int w =0;w<=W;w++){
             if (i==0|w==0)
                 K[i][w] = 0;
             else if (wt[i-1]<=w){
                 K[i][w] = Math.max(val[i-1]+K[i-1][w-wt[i-1]],K[i-1][w]);
             }else
                 K[i][w] = K[i-1][w];
            }
        }
        pw.println(K[N][W]);
        pw.flush();
    }
}


Measured memory_bytes: 125524
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)cin >> v[i];

    int ret = 0;
    for (int i = 1; i < n - 1; i++) {
        if ((v[i - 1] < v[i] && v[i] < v[i + 1]) || (v[i - 1] > v[i] && v[i] > v[i + 1]))ret++;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

// Java8
public class Main {
	Scanner sc = new Scanner(System.in);

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

	void run() throws Exception {
		while(true) {
			int n = sc.nextInt();
			if(n==0) break;
			int s = sc.nextInt();
			int t = sc.nextInt();
			int d = sc.nextInt();
			Lots lots = new Lots(d, n);
			for(int y=0; y<d; y++) {
				String row = sc.next();
				for(int x=0; x<n-1; x++) {
					if(row.charAt(x)=='1') {
						lots.putBar(y, x);
					}
				}
			}
			for(int y=0; y<d; y++) {
				for(int x=0; x<n-1; x++) {
					if(lots.noBar(y, x)) {
					}
				}
			}
			if(lots.trace(s-1)==t-1) {
				System.out.println(0);
			} else {
				boolean found = false;
				for(int y=0; y<d; y++) {
					if(!found) {
						for(int x=0; x<n-1; x++) {
							if(lots.noBar(y, x)) {
								Lots copy = lots.clone();
								copy.putBar(y, x);
								if(copy.trace(s-1)==t-1) {
									found = true;
									System.out.println((y+1) + " " + (x+1));
									break;
								}
							}
						}
					}
				}
				if(!found) {
					System.out.println(1);
				}
			}
		}
	}
}
class Lots implements Cloneable{
	int d;
	int n;
	int[][] f;
	Lots(int d, int n) {
		this.d = d;
		this.n = n;
		f = new int[d][n];
		for(int i=0; i<d; i++) {
			for(int j=0; j<n; j++) {
				f[i][j] = j;
			}
		}
	}
	boolean noBar(int y, int x) {
		return f[y][x]==x && f[y][x+1] == x+1;
	}

	void putBar(int y, int x) {
		int t = f[y][x];
		f[y][x] = f[y][x+1];
		f[y][x+1] = t;
	}

	int trace(int x) {
		int res = x;
		for(int[] r : f) {
			res = r[res];
		}
		return res;
	}

	@Override
	public Lots clone()
	{
		Lots r = new Lots(d, n);
		for(int y=0; y<d; y++) {
			for(int x=0; x<n; x++) {
				r.f[y][x] = f[y][x];
			}
		}
		return r;
	}
}


Measured memory_bytes: 28916
import sys

n = int(input())
w = [list(input()) for i in range(n)]

for i in range(n):
    for j in range(i):
        if w[i] == w[j]:
            print('No')
            sys.exit()
    
    if i != 0:
        if w[i-1][len(w[i-1]) - 1] != w[i][0]:
            print('No')
            sys.exit()

print('Yes')

Measured memory_bytes: 3060
#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); }

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

  int n;
  while (cin >> n) {
    lli c[n], s[n], f[n];
    for (int i = 0; i < n - 1; ++i) {
      cin >> c[i] >> s[i] >> f[i];
    }

    for (int j = 0; j < n; ++j) {
      lli x = 0;
      for (int i = j; i < n - 1; ++i) {
        lli y = (x / f[i]) + (bool)(x % f[i]);
        x = max(y * f[i], s[i]) + c[i];
      }
      cout << x << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////


int main(){fastio
    
    ll n,a,b;cin>>n>>a>>b;
    n%=12;
    rep(i,1,n){
        if(i%2==1)a=a-b;
        else b=a+b;
    }
    cout<<a<<" "<<b<<endl;
    
    return 0;
}



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

int main() {
  int a,b,c;
  cin >> a >> b >>c;
  
  if(a>=b&&a>=c)
    cout<<a*10+b+c<<endl;
  else if(b>=a&&b>=c)
    cout<<b*10+a+c<<endl;
  else
    cout<<c*10+b+a<<endl;
  
  
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

constexpr auto INF = INT_MAX/2;
constexpr auto MOD = 1000000007;

int main() {

	int n;
	cin >> n;
	map<string, int> ss;
	rep(i, n) {
		string s;		
		cin >> s;
		ss[s]++;
	}
	int ans = 0;
	for (auto x : ss) {
		if (x.second > 0)ans++;
	}

	cout << ans << endl;

}

Measured memory_bytes: 19216
# -*- coding: utf-8 -*-

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

dp = [1000000000000] * N
dp[0] = 0
for i, h in enumerate(A):
    for j in (range(1,K+1)):
        if i+j < len(A):
            dp[i + j] = min(dp[i + j], dp[i] + abs(A[i] - A[i+j]))
        #print(dp)

print(dp[-1])


Measured memory_bytes: 52448
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>

using namespace std;

typedef long long ll;
bool cmp(ll a, ll b){
    return a > b;
}

int main(){
    int n,j = 0;
    ll ans=0;
    vector<ll> A;
    vector<ll> circle;
    
    cin >> n;
    A.resize(n);
    for(int i = 0; i < n;i++){
        cin >> A[i]; 
    }
    sort(A.begin(),A.end(),cmp);
    /*
    for(int i= 0; i < n; i++){
        cout << A[i] << " ";
    }
    cout << endl;
    */
   if(n == 2){
       ans = A[0];
   }else if( n <= 3){
        //cout << "aaa" << endl;
        ans += (A[0] + A[1]);
    }
    /*else{
        circle.push_back(A[0]);
        circle.push_back(A[1]);
        ans += A[0];
        circle.push_back(A[2]);
        ans += A[1];
        for(int i = 3; i < n; i++){
            circle.insert(circle.begin()+j+1,A[i]);
            if(j + 2 != circle.size()){
                ans+=circle[j +2];
                //cout << circle[j+2] << " ";
                j += 2;
            }else {
                ans += circle[j];
                //cout << circle[j] << endl;
                j = 0;
            } 
        }

    }
    */
   else{
       ans += A[0];
       j = 1;
       for(int i = 1; i < n-1; i++){
           ans += A[j];
           if(i%2 == 0)j++;
       }
   }
    /*
    for(int i = 0; i < circle.size(); i++){
        cout << circle[i] << " ";
    }
    cout << endl;
    */
    

    cout << ans << endl;

    

    
    return 0;
}

Measured memory_bytes: 4820
import java.util.Scanner;

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

       String str = sc.nextLine();
        num=new int[str.length()];

        for(int i=0; i<str.length();i++){
        
            num[i]=str.charAt(i);
            if(65<=num[i]&&num[i]<=90){
                num[i]=num[i]+32;
            } else if(97<=num[i]&&num[i]<=122){
                num[i]=num[i]-32;
            }

           System.out.print((char)num[i]);

        }


        System.out.println("");










        sc.close();
    }
}


Measured memory_bytes: 26860