akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

using ll = long long;

int main() {
    string s, t;
    cin >> s >> t;
    vector<vector<int>> v(26);
    rep(i, s.size()) {
        v[s[i] - 'a'].push_back(i + 1);
    }
    /*
    rep(i, 26) {
        rep(j, v[i].size()) {
            cout << v[i][j] << " ";
        }
        cout << "\n";
    }
    */
    ll ans = 0;
    int x = 0;
    rep(i, t.size()) {
        //cout << "i=" << i;
        if (v[t[i] - 'a'].size() == 0) {
            cout << "-1\n";
            return 0;
        }
        int y = upper_bound(v[t[i] - 'a'].begin(), v[t[i] - 'a'].end(), x) - v[t[i] - 'a'].begin();
        //cout << " y=" << y;
        if (y == v[t[i] - 'a'].size()) {
            ans += s.size();
            y = upper_bound(v[t[i] - 'a'].begin(), v[t[i] - 'a'].end(), 0) - v[t[i] - 'a'].begin();
        }
        x = v[t[i] - 'a'][y];
        //cout << " ans=" << ans << " x=" << x << "\n";
    }
    cout << ans + x << "\n";
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 9223372036854775807;
#define Sort(a) sort(a.begin(), a.end())
#define Bsort(a) sort(a.begin(), a.end(), greater<ll>())
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  ll n;
  cin >> n;
  vector<ll> a(n);
  unsigned long long ans = 1;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << '\n';
      return 0;
    }
  }
  Sort(a);
  for (int i = 0; i < n; i++) {
    if (ans > 1000000000000000000LL / a[i]) {
      cout << -1 << '\n';
      return 0;
    }
    ans = ans * a[i];
  }
  cout << ans << '\n';
}

Measured memory_bytes: 3980
N, M = map(int, input().split())
C = list(map(int, input().split()))
INF = 10**9
dp = [INF]*(N+1)
dp[0] = 0
for i in range(M):
    for n in range(N+1):
        if n >= C[i]:
            dp[n] = min(dp[n], dp[n-C[i]]+1)
print(dp[N])


Measured memory_bytes: 7516
h,w=map(int,input().split())
a=[]
for i in range(h):
  a.append(input())
for i in range(w+2):
  if(i!=w+1):
    print("#",end="")
  else:
    print("#")
for i in range(h):
  print("#",end="")
  print(a[i],end="")
  print("#")
for i in range(w+2):
  if(i!=w+1):
    print("#",end="")
  else:
    print("#")

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n;
	while(cin>>n,n){
		vector<vector<int> > st;
		vector<int> vec;
		int dt;
		rep(i,n){
			cin>>dt;
			if(i==0){
				vec.push_back(dt);
				if(i==n-1)st.push_back(vec);
			}else{
				if(vec[vec.size()-1]+1==dt){
					vec.push_back(dt);
				}else{
					st.push_back(vec);
					vec.clear();
					vec.push_back(dt);
				}
				if(i==n-1)st.push_back(vec);
			}
		}
		rep(i,st.size()){
			if(i!=0)cout<<" ";
			if(st[i].size()==1)cout<<st[i][0];
			else cout<<st[i][0]<<"-"<<st[i][st[i].size()-1];
		}
		cout<<endl;
	}
	return 0;
}

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

int main() {
    int64_t N;
    cin >> N;
    for (int64_t X = 1; ; X++) {
        int64_t cost = X * 1.08;
        if (cost == N) {
            cout << X << endl;
            return 0;
        } else if (cost > N) {
            cout << ":(" << endl;
            return 0;
        }
    }
}

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

using namespace std;

int main() {
  int n, l;
  cin >> n >> l;
  vector<string> v;
  for (int i = 0; i < n; i++) {
    string work;
    cin >> work;
    v.push_back(work);
  }
  sort(v.begin(), v.end());
  string result = "";
  for (int i = 0; i < n; i++) {
    result += v.at(i);
  }
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 256
N = int(input())
ST = input()

# n=1,Nが(S,S)(S,W)(W,S)(W,W)の4通りを仮定してずらずら決めていけばよいはず
# S=0, W=1として, 1-xで切り替える
# 最後に矛盾が生じないやつだけえらぶO(1)で判定できそうだけど。。

pat = [(0,0),(0,1),(1,0),(1,1)]
fl = False

for p in pat:
  ans = []
  x_now = p[0]
  x_prev = p[1]
  ans.append(x_now)
  for i in range(N):
    if ST[i] == 'o':
      if x_now == 0:
        x_next = x_prev
      else:
        x_next = 1 - x_prev
    else:
      if x_now == 0:
        x_next = 1 - x_prev
      else:
        x_next = x_prev
  
    #print(i, ST[i], x_prev, x_now, x_next)
    ans.append(x_next)
    x_prev, x_now = x_now, x_next

  #if ans[-1] == ans[0]:
  if ans[-2] == p[1] and ans[-1] == ans[0]:
    #correct case
    fl = True
    #print(ans)
    break

if fl:
  for i in range(N):
    print("S" if ans[i] == 0 else "W", end="")
  print()
else:
  print("-1")
  

Measured memory_bytes: 5480
N = int(input())
A = list(map(int,input().split()))
money = 1000
kab = 0
flag = 0

for i in range(N-1):
  if flag == 1:
    money += A[i] * kab
    kab = 0
    flag = 0
  if A[i] < A[i+1]:
    temp = money // A[i]
    kab += temp
    money -= temp * A[i]
    flag = 1

if flag == 1:
  money += A[N-1] * kab
  
print(money)  

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

int main(){
  ll K; cin >> K;
  vector<ll> a(K);
  for(ll i = 0; i < K; i++) cin >> a[K - i - 1];
  
  ll L = 2, R = 2;
  for(ll i = 0; i < K; i++){
    ll qer = a[i];
    L = ((L-1) / qer) * qer + qer;
    if(L > R) {cout << -1 << endl; return 0;}
    R = (R / qer) * qer + qer - 1;
  }
  cout << L << ' ' << R << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;    
typedef long double ld;  
#define pb push_back     
using namespace std;





int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
	
    int a, b, c, d; cin >> a >> b >> c >> d;
    if(a + b > c + d) cout << "Left\n";
    if(a + b < c + d) cout << "Right\n";
    if(a + b == c + d) cout << "Balanced\n";
    return 0;

}


Measured memory_bytes: 256
// Problem : C - Multiplication 3
// Contest : AtCoder - AtCoder Beginner Contest 169
// URL : https://atcoder.jp/contests/abc169/tasks/abc169_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms

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

#define int     long long int
#define pii     pair<int, int>
#define vi      vector<int>
#define vii     vector<pair<int, int>>
#define pb      push_back
#define all(a)  (a).begin(),(a).end()
#define f       first
#define s       second
#define endl    '\n'
#define mod     1000000007    		

void solve()
{
	int a ; string b ; 
	cin >> a >> b ;
	int x, y ;
	x = b[0] - '0' ;
	y = (b[2] - '0') * 10 + b[3] - '0' ;
	int ans = a * x + (a * y) / 100 ;
	cout << ans << endl ; 
}

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

    int t = 1 ;
    //cin >> t ;
    while(t--)
    {
        solve() ;
    }
    return 0 ;
}

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

//素因数分解(関数ver)
map<int64_t,int64_t> prime_fact(int64_t n){
  int64_t a = 2;
  map<int64_t,int64_t> mp;
  while(n >= a*a){
    if(n %a == 0){
      mp[a]++;
      n /= a;
    }
    else{
      a++;
    }
  }
  if(n != 1){
    mp[n]++;
  }
  return mp;
}

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec[i];
  }
  
  map<int,int> ans;
  for(int i=0; i<N; i++){
    map<int, int> A;
    int a = 2;
    int n = vec[i];
    while(n >= a*a){
      if(n %a == 0){
        A[a]++;
        n /= a;
      }
      else{
        a++;
      }
    }
    if(n != 1){
     A[n]++;
    }
    for(auto itr = A.begin(); itr != A.end(); itr++){
      ans[itr->first]++;
    }
  }
  
  int coprime = 0;
  
  for(auto itr = ans.begin(); itr != ans.end(); itr++){
    coprime = max(coprime,itr->second);
  }
  
  if(coprime <= 1){
    cout << "pairwise coprime" << endl;
  }
  else if(coprime != N){
    cout << "setwise coprime" << endl;
  }
  else{
    cout << "not coprime" << endl;
  }
}



Measured memory_bytes: 10832
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

ll mod=1e9+7 ;
ll dp[200010];
int chnum[200010];
int main(){
	int n;cin>>n;
	dp[0]=1;
	for(int i=0;i<n;){
        i++;
		int C; cin>>C;
		dp[i]=dp[i-1]+(chnum[C]!=0&&chnum[C]<i-1?dp[chnum[C]]:0);
		dp[i]%=mod;
		chnum[C]=i;
	}
	cout<<dp[n]<<endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <string>
#include <algorithm>
using namespace std;

int H,W,C;
int board[8][8];
int b[8][8];
int check[8][8];
int ord[5];
int ans;

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

bool in(int x, int y){
    return 0 <= x && x < W && 0 <= y && y < H;
}

void dfs(int x, int y, int color){
    //cerr << x << " " << y << " " << color << endl;
    check[y][x] = 1;
    for(int k = 0; k < 4; k++){
        int nx = x + dx[k], ny = y + dy[k];
        if(!in(nx, ny) || b[ny][nx] != color || check[ny][nx]) continue;
        dfs(nx, ny, color);
    }
}

int calc(){
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            b[i][j] = board[i][j];
        }
    }
    for(int t = 0; t < 5; t++){
        //cout << ord[t] << endl;
        memset(check, 0, sizeof check);
        dfs(0, 0, b[0][0]);
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                if(check[i][j]) b[i][j] = ord[t];
            }
        }
    }

    memset(check, 0, sizeof check);
    dfs(0, 0, b[0][0]);
    int ret = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(check[i][j] && b[i][j] == C) ret++;
        }
    }
    return ret;
}

void f(int n){
    if(n == 5){
        ans = max(ans, calc());
        return;
    }
    for(int i = 1; i <= 6; i++){
        ord[n] = i;
        f(n + 1);
    }
}

int main(){
    while(cin >> H >> W >> C, H){
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                cin >> board[i][j];
            }
        }
        ans = 0;
        f(0);
        cout << ans <<endl;
    }
}

Measured memory_bytes: 3076
#include <cstdio>
#include <algorithm>
#include <vector>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') w = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
	return data * w;
}

const int N(3005), Mod(1e9 + 7), inv2((Mod + 1) >> 1);
int n, Q, f[N][N], a[N], Pow = 1, ans;

int main()
{
	n = read(), Q = read();
	for (int i = 1; i <= n; i++) a[i] = read();
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++) f[i][j] = a[i] < a[j];
	for (int i = 1, x, y; i <= Q; i++)
	{
		Pow = (Pow + Pow) % Mod, x = read(), y = read();
		f[x][y] = f[y][x] = 1ll * inv2 * (f[x][y] + f[y][x]) % Mod;
		for (int j = 1; j <= n; j++)
		{
			if (j == x || j == y) continue;
			f[x][j] = f[y][j] = 1ll * inv2 * (f[x][j] + f[y][j]) % Mod;
			f[j][x] = f[j][y] = 1ll * inv2 * (f[j][x] + f[j][y]) % Mod;
		}
	}
	for (int i = 1; i <= n; i++)
		for (int j = i + 1; j <= n; j++) ans = (ans + f[j][i]) % Mod;
	printf("%lld\n", 1ll * ans * Pow % Mod);
	return 0;
}


Measured memory_bytes: 35456
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
#define Di 3.1415926
#include<math.h>
#define INF 0x3f3f3f3f
using namespace std;
ll  ans=0,n;
void dfs(ll  x,int a,int b,int c)
{
    if(x>n)return;
    if(a&&b&&c) ans++;
    dfs(10*x+3,1,b,c);
    dfs(10*x+5,a,1,c);
    dfs(10*x+7,a,b,1);
}
int main()
{

     cin>>n;
     dfs(0,0,0,0);
     cout<<ans<<endl;

 return 0;
}


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 int ll;
typedef pair<int, int> P;
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; }

const int mod = 1000000007;
struct mint{
	ll x;
	mint(ll x = 0):x((x%mod+mod)%mod){}
	mint operator-() const{return mint(-x);}
	mint& operator+=(const mint a){
		if((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if(!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if(t&1) a *= *this;
		return a;
	}
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
	bool operator==(const mint a){
		return x == a.x;
	}
};

mint dp[100005][13];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    string s;
    cin >> s;
    dp[0][0] = 1;
    int n = s.size();
    reverse(s.begin(), s.end());
    int ten = 1;
    rep(i,n){
        rep(j,13){
            if(s[i] != '?'){
                int nj = (j + (s[i] - '0') * ten) % 13;
                dp[i+1][nj] += dp[i][j];
            }
            else{
                rep(k,10){
                    int nj = (j + k * ten) % 13;
                    dp[i+1][nj] += dp[i][j];
                }
            }
        }
        ten = (ten * 10) % 13;
    }
    cout << dp[n][5].x << endl;
	return 0;
}

Measured memory_bytes: 13932
import math
x = int(input())

a = 10 ** 6
b = int(math.sqrt(a)+1)
p = [True]*(a+1)
p[0] = False
p[1] = False

for i in range(4, a+1, 2):
  p[i] = False
  
for i in range(3, b+1, 2):
  if p[i]:
    for j in range(i+i, a+1, i):
      p[j] = False

for i in range(x, a+1):
  if p[i]:
    print(i)
    break

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

int main()
{
    int N;
    int sum = 0;
    bitset < 2000005 > bt;
    bt |= 1;
    cin >> N;
    for(int i = 0; i < N; i++) {
        int A;
        cin >> A;
        sum += A;
        bt |= (bt << A);
    }
    for(int i = (sum + 1) / 2; i < 2000005; i++) {
        if(bt[i]) {
            cout << i << endl;
            break;
        }
    }
    return (0);
}

Measured memory_bytes: 1152
import sys
input = sys.stdin.readline
import bisect
left = bisect.bisect_left
right = bisect.bisect_right

def question():
    n ,q = map(int,input().split())
    s = input()
    lr = [list(map(int,input().split())) for i in range(q)]
    a = [i for i in range(n-1) if s[i:i+2] == 'AC']

    for i in range(q):
        left_index = left(a, lr[i][0] - 1)
        right_index = right(a, lr[i][1] - 2)
        print(right_index - left_index)

question()

Measured memory_bytes: 31952
// vim: foldmethod=marker
#include <iostream> // cout, endl, cin{{{
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
typedef long long ll;/*}}}*/

int main(int argc, char *argv[])
{
  int n, m;
  cin >> n >> m;
  int P[m];
  string *S = new string[m];

  for (int i = 0; i < m; ++i) {
    cin >> P[i] >> S[i];
  }

  int ac_num = 0;
  int Wa_tmp[n + 1];
  for (int i = 0; i <= n; ++i) { Wa_tmp[i] = 0; }
  int wa_num = 0;
  bool AC[n + 1];
  for (int i = 0; i <= n; ++i) { AC[i] = false; }

  for (int i = 0; i < m; ++i) {
    int p = P[i];
    if (S[i] == "WA" && !AC[p])  {
      Wa_tmp[p] += 1;
    }
    if (S[i] == "AC" && !AC[p]) {
      AC[p] = true;
      wa_num += Wa_tmp[p];
      ac_num += 1;
    }
  }

  cout << ac_num << " " << wa_num << endl;

}


Measured memory_bytes: 3456
x=int(input())
ans=2*(x//11)
rem=x%11
if rem==0:
    print(ans)
    import sys
    sys.exit()
if rem<=6:
    ans+=1
else:
    ans+=2
print(ans)
#print(2*ans) if x%11==0 else print(2*ans+1)


Measured memory_bytes: 2940
import bisect
def double(n):
    return n*2

N = int(input())
A = list(map(int,input().split()))
B = list(map(double,A))
# print(A) 
# print(B) 
sum=0
rsum=[]
tocutsum=0
rsumcut=[] 
for x in B:
    sum = sum + x
    tocut= max(0,x-2)
    rsum.append(sum)
    tocutsum = tocutsum + tocut 
    rsumcut.append(tocutsum)
# print(sum)
# print(rsum)
# print("rsumcut",rsumcut)
middle= sum // 2;
# print("Middle",middle)
br = bisect.bisect_right(rsum,middle)
# print(br)


xleft = middle - rsum[br-1]
xright = rsum[br] - middle 

print(min(xleft,xright))
# print("Ans",min(xleft,xright))
# print("Costleft,rigth",costleft,costright)

Measured memory_bytes: 42408
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class BST:
    def __init__(self):
        self.root = None

    def insert(self, v):
        x = TreeNode(v)
        if not self.root:
            self.root = x
            return

        r = self.root
        while r is not None:
            parent = r
            if x.val < r.val:
                r = r.left
            else:
                r = r.right

        if x.val < parent.val:
            parent.left = x
        else:
            parent.right = x

    def in_order(self):
        def helper(node):
            if not node:
                return
            helper(node.left)
            res.append(node.val)
            helper(node.right)

        res = []
        helper(self.root)
        return res

    def pre_order(self):
        def helper(node):
            if not node:
                return
            res.append(node.val)
            helper(node.left)
            helper(node.right)

        res = []
        helper(self.root)
        return res

    def find(self, target):
        if not self.root:
            return False
        r = self.root
        while r:
            if target < r.val:
                r = r.left
            elif target == r.val:
                return True
            else:
                r = r.right
        return False


test = BST()
n = int(input())
for _ in range(n):
    order = input()
    if order.startswith("insert"):
        i, x = order.split()
        test.insert(int(x))
    elif order.startswith("find"):
        i, x = order.split()
        print("yes" if test.find(int(x)) else "no")
    else:
        print(" ",end="")
        print(*test.in_order())
        print(" ",end="")
        print(*test.pre_order())



Measured memory_bytes: 94428
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[],int n,int g) {
	for(int i=g; i<n; i++) {
		int v = A[i];
		int j = i - g;
		while(j>=0 && A[j] >v) {
			A[j+g] = A[j];
			j -= g;
			cnt++;
		}
		A[j+g] = v;
	}
}

void shellSort(int A[], int n) {
	for(int h=1; ;) {
		if(h>n) break;
		G.push_back(h);
		h = 3*h + 1;
	}

	for(int i=G.size()-1; i>=0; i--) {
		insertionSort(A, n, G[i]);
	}
}

int main(void) {
	cin >> n;
	for(int i=0; i<n; i++) scanf("%d",&A[i]);
	cnt = 0;
	shellSort(A,n);

	cout << G.size() << endl;
	for(int i=G.size()-1; i>=0; i--) {
		printf("%d", G[i]);
		if(i) printf(" ");
	}
	printf("\n");
	printf("%d\n",cnt);
	for(int i=0;i<n;i++) printf("%d\n",A[i]);

	return 0;
}



Measured memory_bytes: 7184
N = gets.to_i
ac = wa = tle = re = 0
s = []
N.times do |i|
  s << gets.to_s.chomp
end

for i in s
  if i == "AC"
    ac +=1
  elsif i == "WA"
    wa += 1
  elsif i == "TLE"
    tle += 1
  elsif i == "RE"
    re += 1
  end
end

puts "AC x #{ac}"
puts "WA x #{wa}"
puts "TLE x #{tle}"
puts "RE x #{re}"


Measured memory_bytes: 21672
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <random>
#include <chrono>
#include <string>
#include <bitset>
#include <cassert>
#include <queue>
#include <memory>

//#pragma comment(linker, "/STACK:16777216")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,abm,mmx,avx,avx2,popcnt,tune=native")

using namespace std;

//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

#define ll long long
#define ull unsigned long long
//#define double long double
//#define int ll
//#define int ull
//#define int short
//#define int unsigned short
//#define int unsigned int
#define mp make_pair
#define F first
#define S second
#define pii pair<int, int>
#define hash hash228
#define get get228
const int SZ = 1e2 + 4;
const double EPS = 1e-7;
const int mod = 998244353;
const int hashpow = 127;
const int inf = 2e9;

#define kek cout << "kek"

int n, a, b, c, d;
string s;

void read() {
    cin >> n >> a >> b >> c >> d >> s;
    --a, --b, --c, --d;
}

void solve() {
    if (c > d) {
        bool z = false;
        for (int i = b - 1; i <= min(d - 1, n - 3); ++i) {
            if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') {
                z = true;
                break;
            }
        }
        if (!z) {
            cout << "No\n";
            return;
        }
        for (int i = a; i < c; ++i) {
            if (s[i] == '#' && s[i + 1] == '#') {
                cout << "No\n";
                return;
            }
        }
        cout << "Yes\n";
    }
    else {
        for (int i = a; i < d; ++i) {
            if (s[i] == '#' && s[i + 1] == '#') {
                cout << "No\n";
                return;
            }
        }
        cout << "Yes\n";
    }
}

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

    //    int t;
    //    cin >> t;
    //    for (int i = 0; i < t; ++i) {
    read();
    solve();
    //    }

    return 0;
}

Measured memory_bytes: 592
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx")
// #pragma comment(linker, "/stack:200000000"]
 
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>
#include <random>
#include <fstream>
#include <sstream>
#include <chrono>

#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define hm unordered_map 
#define pii pair<int, int>
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define cinv(v) for (auto& x: v) cin >> x
#define fr(i, n) for (int i = 0; i < n; ++i)
#define fl(i, l, n) for (int i = l; i < n; ++i)

#define int ll

using namespace std;

#ifdef __LOCAL
	#define dbg(x) cerr << #x << " : " << x << '\n'
	const int maxn = 20;
#else 
	#define dbg(x)
	const int maxn = 2e5 + 20;
#endif

//tg: @galebickosikasa
 
const ll inf = (ll) 2e9;
const ld pi = asin (1) * 2;
const ld eps = 1e-8;
const ll mod = (ll)1e9 + 7;
const ll ns = 97;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());



signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n;
	cin >> n;
	vector<int> goo;
	--n;
	while (n >= 0) {
		goo.pb (n % 26);
		n /= 26;
		--n;
	}
	reverse (all (goo));
	for (auto& x: goo) {
		char t = 'a' + x;
		cout << t;
	}







}

Measured memory_bytes: 3560
#include <stdio.h>

int main(){
    int A = 0, B = 0, X = 0, i;
    while(1){
        scanf("%d %d", &A, &B);
        if(3<=A && B<=20){
            break;
        }else{
            printf("plese set number");
        }
    }
    for(i=0; i<2; i++){
        if(A >= B){
            X = X + A;
            A = A - 1;
        }else if(A < B){
            X = X + B;
            B = B - 1;
        }
    }
    printf("%d", X);
}

Measured memory_bytes: 128
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//







int main(void) {

    int s, w; cin >> s >> w;
    if (s <= w) {
        cout << "unsafe" << endl;
    }
    else {
        cout << "safe" << endl;
    }



    return 0;
}











Measured memory_bytes: 3596
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    S = input()

    if S[-1] == "s":
        print(S + "es")
    else:
        print(S + "s")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61672
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main()
{
  string s;
  cin>>s;
  int p = 0;
  map<int, int> dp;
  dp[p] = 0;
  for(char c:s) {
    p ^= 1 << (c - 'a');
    for(auto&& i:irange(0,26)) {
      int q = p ^ (1 << i);
      if (dp.count(q)) {
        if (!dp.count(p)) dp[p] = dp[q] + 1;
        else dp[p] = min(dp[p], dp[q] + 1);
      }
    }
  }
  cout<<max(dp[p], 1)<<endl;
  return 0;
}


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


int main()
{
	ll N,T;
	cin>>N>>T;
	ll t_prev=0;
	ll ans=0;
	rep(i,N)
	{
		ll t;
		cin>>t;
		if(t_prev+T>=t)
		{
			ans+=t-t_prev;
		}
		else
		{
			ans+=T;
		}
		t_prev=t;
	}
	cout<<ans+T<<endl;
	return 0;
}


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

using namespace std;

typedef long long ll;

int main(){
	int n;
	cin >> n;
	int ans = 0;
	for(int i = 0; i < 4; i++){
		if(n % 10 == 2)ans++;
		n/=10;
	}
	cout << ans << endl;
    return 0;
}

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

uint64_t sigma(uint64_t syokou, uint64_t kousuu){
    return (syokou+syokou+kousuu-1)*kousuu/2;
}

int main(){
    uint64_t n,k;
    cin>>n>>k;

    uint64_t ans=0;
    rep(i,k,n+2){
        uint64_t min,max;
        min=sigma(0,i);
        max=sigma(n+1-i,i);
        
        ans+=(max-min+1)%MOD;
        ans%=MOD;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using System.Linq;
using System.IO;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
#if DEBUG
            ReadLine();
#endif
        }

        void Solve(ConsoleInput cin)
        {
            string s = cin.Read;
            int[] cnt = { 0, 0 };

            foreach (char c in s)
            {
                if (c == '0')
                {
                    cnt[0]++;
                }
                else
                {
                    cnt[1]++;
                }
            }

            Console.WriteLine(cnt.Min() * 2);
        }

        class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;

            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }

            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }

            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}

Measured memory_bytes: 13920
#include<stdio.h>
#include<string.h>
int main()
{
char ch[100000];
gets(ch);
int i,j,k,l,n;
l=strlen(ch);
for(i='a';i<='z';i++)
{
int temp=0;
for(j=0;j<l;j++)
{
if(i==ch[j])
{

temp++;
}


}
if(temp%2!=0)
{
printf("No\n");
return 0;

}


}
printf("Yes\n");
return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d >> s;
    a--; b--; c--; d--;
    bool f = true;
    for(int i = a + 1; i < c; i++){
        if(s[i] == '#' && s[i - 1] == '#') f = false;
    }
    for(int i = b + 1; i < d; i++){
        if(s[i] == '#' && s[i - 1] == '#') f = false;
    }
    if(d < c){
        bool g = false;
        for(int i = b; i <= d; i++){
            if(s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') g = true;
        }
        if(!g) f = false;
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int inv2=(mod+1)/2;
int n,k;
int a[2005];
int main(){
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++)
		scanf("%d",a+i);
	int num1=0,num2=0;
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
			if(a[i]>a[j])num1++;
			else if(a[i]<a[j])num2++;
	ll ans=0;
	ans=(1ll*k*(k+1)%mod*inv2%mod*num1%mod+1ll*k*(k-1)%mod*inv2%mod*num2%mod+mod)%mod;
	printf("%lld",ans);
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int ans = 0;
		if (n % 1000 != 0)
			ans = 1000 - (n % 1000);

		System.out.println(ans);
	}

}


Measured memory_bytes: 35612
def resolve():
    s = int(input())
    a = []
    a.append(s)
    while True:
        if a[-1] % 2 == 0:
            a.append(a[-1]/2)
        else:
            a.append(3 * a[-1] + 1)

        if len(a) != len(set(a)):
            print(len(a))
            return

resolve()

Measured memory_bytes: 3060
h, w, m = map(int, input().split())
H = [0 for i in range(h)]
W = [0 for i in range(w)]
s = set()
for i in range(m):
    a,b = map(int, input().split())
    H[a-1] += 1
    W[b-1] += 1
    s.add((a,b))
hma = max(H)
wma = max(W)
h_index = [i+1 for i, x in enumerate(H) if x == hma]
w_index = [i+1 for i, x in enumerate(W) if x == wma]
val = -1
for j in range(len(h_index)):
    for k in range(len(w_index)):
        if (h_index[j],w_index[k]) in s:
            continue
        else:
            val = 0
            break
print(hma+wma+val)

Measured memory_bytes: 83424
#define _CRT_SECURE_NO_WARNINGS
#define forn(i, a, n) for(int i = a; i < n; ++i)
#define pb push_back
#define mp make_pair
#define f first
//#define sex second

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <set>
#include <ostream>
#include <queue>
#include <functional>
#include <sstream>
#include <map>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
#pragma comment(linker, "/STACK:228228000")
const ll mod = 998244353;

ll a, b;
ll ds[1000];

int main()
{
	/*
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/
	
	cin >> a >> b;
	forn(i, 1, 1000)
	{
		ds[i] = ds[i - 1] + i;
	}

	forn(i, 2, 1000)
	{
		if (ds[i - 1] - a == ds[i] - b)
			if ((ds[i - 1] - a >=1)  && (ds[i] - b >= 1))
			{
				cout << ds[i] - b;
				break;
			}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
int n,m,x;
char s[maxn],t[maxn];
int main(){
	cin>>n>>m>>s>>t;
	x=__gcd(n,m);
	for(int i=0;i<x;++i)
		if(s[n/x*i]!=t[m/x*i]){
			puts("-1");
			return 0;
		}
	printf("%lld\n",(ll)n*m/x);
}

Measured memory_bytes: 384
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
 
int a; 
a = sc.nextInt();
 
int b; 
b = sc.nextInt();

int c;
c = sc.nextInt();


if(a<b && b<c)
{
System.out.println("Yes");
}
else
{
System.out.println("No");

}
}
}



Measured memory_bytes: 26216
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc199_a
{
    public class Program
    {
        static void Main(string[] args)
        {

            //string[] input = Console.ReadLine().Split('/');
            //int Y = int.Parse(input[0]);
            //int M = int.Parse(input[1]);
            //int D = int.Parse(input[2]);

            DateTime time1 = DateTime.Parse(Console.ReadLine());
            



            Console.WriteLine(Seileki(time1));

        }

        public static string Seileki(DateTime time1)
        {
            DateTime time2 = DateTime.Parse("2019 / 04 / 30");
            if (time1 <= time2)
            {
                return "Heisei";
            }
            else
            {
                return "TBD";
            }

        }



    }
}


Measured memory_bytes: 13536
#include <stdio.h>
int main (){
	int N, A, B;
	scanf ("%d %d %d", &N, &A, &B);
	int sum = 0;
	for (int i = 1; i <= N; i++){
		int digitSum = 0;
		int temp = i;
		while (temp != 0) {
			digitSum = digitSum + temp % 10;
			temp /= 10;
		}
		if (digitSum >= A && digitSum <= B){
			sum += i;
		}
	}
	printf ("%d\n", sum);
	return 0;
}

Measured memory_bytes: 1732
#include<iostream>
using namespace std;
int main()
{
	int m[32]={0},i,e;
	for(i=1;i<=28;i++)
	{
		cin>>e;
		m[e]=1;

	}
	for(i=1;i<=30;i++)
	{
		if(m[i]==0)
			cout<<i<<endl;
	}
	return 0;
}

Measured memory_bytes: 3088
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static List<Edge>[] graph;
        static long[] depth;
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            depth = new long[100010];
            graph = Enumerable.Repeat(0, n).Select(_ => new List<Edge>()).ToArray();
            
            for (var i = 0; i < n - 1; i++) {
               var t = Console.ReadLine().Split().Select(int.Parse).ToArray();
               t[0]--;
               t[1]--;
               
               graph[t[0]].Add(new Edge(){To=t[1],Cost=t[2]});
               graph[t[1]].Add(new Edge(){To=t[0],Cost=t[2]});
            }

            var m = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int Q = m[0], K = m[1];
            Dfs(--K, -1, 0);

            for (var i = 0; i < Q; i++) {
               var q = Console.ReadLine().Split().Select(int.Parse).ToArray();
               //Console.WriteLine($"{K} {q[0]} {q[1]}");
               var ans = depth[--q[0]]+depth[--q[1]];
               Console.WriteLine(ans);
            }
        }

        static void Dfs(int node, int parent, long cost)
        {
            depth[node] = cost;
            for (var i = 0; i < graph[node].Count; i++) {
                if (parent == graph[node][i].To) continue;
                Dfs(graph[node][i].To, node, cost+graph[node][i].Cost);
            }
        }
    }

    class Edge
    {
       public int To {get; set;}
       public int Cost {get; set;}
    }
}


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

int main() {
  int a, b, x;
  cin >> a >> b >> x;

  double ab = a * b;
  double s = x / static_cast<double>(a);
  double rad = 0;
  if (s >= ab / 2) {
    double num = (ab - s) * 2 / pow(a, 2);
    rad = atan(num);
  } else {
    double num = pow(b, 2) / (2 * s);
    rad = atan(num);
  }
  double ans = rad * 180 / M_PI;
  printf("%.9f\n", ans);
}


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


#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

ll mod = 1e9 + 7ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll inf = 1ll << 60;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(b/a, c);
    return 0;
}





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

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main(){
  ll n,k;
  cin>>n>>k;
  vector<ll> v;
  rep(i,0,n){
    ll a;
    cin>>a;
    v.pb(a);
  }
  ll mx = 0;
  rep(i,0,k+1){
    rep(j,0,k+1){
      if(i+j>k)continue;
      if(i+j>n)continue;
      vector<ll> v1;
      rep(l,0,i){
        v1.pb(v[l]);
      }
      reverse(all(v));
      rep(l,0,j){
        v1.pb(v[l]);
      }
      reverse(all(v));
      sort(all(v1));
      ll k1 = k-(i+j);
      if(k1>0){
        rep(l,0,min((ll)v1.sz,k1)){
          if(v1[l]<0){
            v1[l] = 0;
          }
        }
      }
      ll c = 0;
      rep(l,0,v1.sz){
        c += v1[l];
      }
      mx = max(mx,c);
    }
  }
  cout << mx << endl;
  return 0;
}

Measured memory_bytes: 256
m = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]

n = int(input())
i = 1

while n >= i:
    b, f, r, v = map(int, input().split())
    m[b-1][f-1][r-1] += v
    i += 1

bc, fc, rc = 0, 0, 0
while 4 > bc:
    while 3 > fc:
        while 10 > rc:
            if rc != 9:
                print(" {}".format(m[bc][fc][rc]), end = "")
            if rc == 9:
                print(" {}".format(m[bc][fc][rc]))
            rc += 1
        rc = 0
        fc += 1
    if bc != 3:
        print("####################")
    fc = 0
    bc += 1



Measured memory_bytes: 5620
#include <cstdio>
#include <vector>
#include <cstring>
#define mp make_pair
#define N 200005
using namespace std;
typedef pair<int,int> Pair;
vector <Pair> v[N];
int n,m,k,flag,vis[N],T,x,y,val;
long long l,r,va[N];
void dfs(int now,long long val)
{
	if (!flag)
		return;
	if (vis[now])
	{
		if (va[now]!=val)
			flag=0;
		return;
	}
	vis[now]=1;
	va[now]=val;
	if (now<=n)
		l=max(l,val);
	else
		r=min(r,val);
	for (int i=0;i<v[now].size();i++)
		dfs(v[now][i].first,val+v[now][i].second);
}
main()
{
//	freopen("then.in","r",stdin);
//	freopen("then.out","w",stdout);
//	scanf("%d",&T);
//	while(T--)
//	{
		flag=1;
		scanf("%d%d%d",&n,&m,&k);
		for (int i=0;i<k;i++)
		{
			scanf("%d%d%d",&x,&y,&val);
			v[x].push_back(mp(y+n,val));
			v[y+n].push_back(mp(x,-val));
			if (val<0)
				flag=0;
		}
		for (int i=1;i<=n+m;i++)
			if (!vis[i])
			{
				l=-1e18,r=1e18;
				dfs(i,0);
				if (l>r)
					flag=0;
				if (!flag)
					break;				
			}
		if (flag)
			puts("Yes");
		else
			puts("No");
		memset(vis,0,sizeof vis);
		memset(va,0,sizeof va);
		for (int i=1;i<=m+n;i++)
			v[i].clear();
//	}
}

Measured memory_bytes: 15104
#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;
#define all(x) (x).begin(),(x).end()

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);std::cout<<std::fixed<<std::setprecision(10);
    int N;
    cin >> N;
    vector<vector<int>> A(N,vector<int>(N-1));
    REP(i,N)REP(l,N-1)cin >> A[i][l];
    vector<int> pla(N);
    vector<int> plane(N);
    vector<int> ok(N,N-1);
    int count = 0,check = 1;
    for(;;){
        REP(i,N)if(pla[i] != N-1&&pla[A[i][pla[i]]-1] != N-1)if(A[A[i][pla[i]]-1][pla[A[i][pla[i]]-1]] == i+1){
            plane[i]++;
            check = 0;
        }
        if(check){
            if(ok == pla){
            }else{
                count = -1;
            }
            break;
        }
        count++;
        pla = plane;
        check = 1;
    }
    cout <<count<< "\n";
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;

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

  bool c=false,f=false;
  string s;
  cin >> s;
  int len;
  len=s.length();
  for(int i=0;i<len;i++){
    if(c){
      if(s[i]=='F') f=true;
    }
    else{
      if(s[i]=='C') c=true;
    }
  }
  if(c && f) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
vec r(2001,0),d(2001,0),s(2001,0);
vector<int> G[200001];
int z=0;
int search(int x,int y){
    if(x==z||r[x]) return 0;
    r[x]=1;
    d[x]=y;
    for(auto i:G[x]) search(i,y+1);
}
int main(){
    ll n,k,a,b;
    cin>>n>>k;
    rep(i,n-1) cin>>a>>b,G[a].push_back(b),G[b].push_back(a);
    if(k%2==0){
        ll ans=n;
        rep(i,n){
            fill(all(r),0),fill(all(d),0);
            search(i+1,0);
            ll c=0;
            rep(j,n) if(d[j+1]>k/2) c++;
            ans=min(ans,c);
        }
        cout<<ans<<"\n";
    }
    else{
        ll ans=n;
        rep(i,n)for(auto j:G[i+1]){
            z=j;
            fill(all(r),0),fill(all(d),0);
            search(i+1,0);
            z=0;
            search(j,0);
            ll c=0;
            rep(j,n) if(d[j+1]>(k-1)/2) c++;
            ans=min(ans,c);
        }
        cout<<ans<<"\n";
    }
}

Measured memory_bytes: 5120
/*
  Author - KISHAN TIWARI
  Dream bigger. Do bigger.
  Wake up with determination. Go to bed with satisfaction.
*/
//Sometimes later becomes never. Do it now.
#include<bits/stdc++.h>
using namespace std;
#define ll           long long
#define f(i,a,b)     for(ll i=a;i<b;i++)
#define mod          1000000007
#define fi           first
#define se           second
#define pa           pair <ll,ll>
#define mp           make_pair
#define pb           push_back
#define ve           vector<ll>
#define vep          vector< pa >
#define all(a)       a.begin(), a.end()
#define sz(x)        (ll)x.size()
#define c(t)         cout<<t<<"\n"
using namespace std;
void solve()
{  ll a,b,c;
cin>>a>>b>>c;
ll x=c-a+b;
if(x<0)
    c(0);
else
    c(x);

}
int main()
{
    ios::sync_with_stdio(true);
   //freopen ("input.txt","r",stdin);
   //freopen ("output.txt","w",stdout);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;
    while(t--)
    {

        solve();
    }
return 0;
}


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

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

const long long MOD = 1000000007;

int main(){
  int n;
  cin>>n;
  vector<int> w(n);
  int s1=0,s2=0;
  rep(i,n){
    cin>>w.at(i);
    s2+=w.at(i);
  }
  int ans=100000;
  rep(i,n-1){
    s1+=w.at(i);
    s2-=w.at(i);
    if(s1>=s2) ans=min(ans,s1-s2);
    else ans=min(ans,s2-s1);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static int[] p;
	
	static int dfs(int nth, int a, int b) {
		if(nth < p.length) {
			return Math.min(dfs(nth+1, a+p[nth], b), dfs(nth+1, a, b+p[nth]));
		}
		else {
			return Math.abs(a-b);
		}
	}
	
	public static void main(String args[]){
		try(Scanner sc=new Scanner(System.in)){
			while(sc.hasNext()) {
				int n = sc.nextInt();
				if(n == 0) break;
				p = new int[n];
				for(int i = 0; i < n; i++) {
					p[i] = sc.nextInt();
				}
				System.out.println(dfs(0, 0, 0));
			}
		}
	}
}


Measured memory_bytes: 28516
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var num = ToInt32(ReadLine());
        //var ar = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var ab = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var p = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var a = new int[3];
        for (var i = 0; i < num; i++)
        {
            if (p[i] <= ab[0]) a[0]++;
            else if (p[i] <= ab[1]) a[1]++;
            else a[2]++;
        }
        WriteLine(a.Min());
    }
    private const string ALFA = "abcdefghijklmnopqrstuvwxyz";
    private const int MOD = 1000000007;
}


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

int main()
{
    int a,b,x = 0;

    cin >> a >> b;

    if( a > b){
        x += a;
        a--;
    }else if( a < b){
        x += b;
        b--;
    }else if(a == b ){
        x += a;
        a--;
    }


    if( a > b){
        x += a;
        a--;
    }else if( a < b){
        x += b;
        b--;
    } else if( a == b) {
        x += a;
        a--;
    }

    cout << x;
}

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

#define MAX 1000001
#define MAX2 10001



int main(){

  int i;
  int t,p;
  char T[MAX],P[MAX2];

  
  scanf("%s%s",T,P);
  t = strlen(T);
  p = strlen(P);

  
  for(i = 0;i < t;i++){

    if(strncmp(&T[i],P,p)==0){
    printf("%d\n",i);
      }
  }


  
  return 0;
}

Measured memory_bytes: 1548