akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
const ll MODA=998244353;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
vector<ll> fac;
vector<ll> finv;
vector<ll> inv;
void COMinit(ll N,ll P){
    rep(i,N+1){
        if(i==0){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else if(i==1){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else{
            fac.push_back(fac.at(i-1)*i%P);
            inv.push_back(P-inv.at(P%i)*(P/i)%P);
            finv.push_back(finv.at(i-1)*inv.at(i)%P);
        }
    }
}

ll COM(ll n,ll k,ll P){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P;
}
int main()
{
    string S;
    cin>>S;
    ll l=S.size();
    rep(i,l){
        if(S.at(i)=='P')cout<<'P';
        else cout<<'D';
    }
    cout<<endl;
}

Measured memory_bytes: 3760
#!/usr/bin/env python3
import bisect
import collections
import sys

sys.setrecursionlimit(1000000)
ACMOD = 1000000007
INF = 1 << 62

YES = "Yes"  # type: str


def solve(N: int, M: int, A: "List[int]", B: "List[int]"):
    adj = [[] for _ in range(N)]
    for i in range(M):
        a = A[i]
        b = B[i]
        adj[a - 1].append(b - 1)
        adj[b - 1].append(a - 1)
    visited = set()
    q = collections.deque([(0, 0)])  # (index,from)
    ans = [-1] * N
    while q:
        index, _from = q.popleft()
        if index in visited:
            continue
        visited.add(index)
        ans[index] = _from
        for adj_v in adj[index]:
            q.append((adj_v, index))

    if len(visited) != N:
        print("No")
        return
    print("Yes")
    for i, a in enumerate(ans):
        if i == 0:
            continue
        print(a + 1)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int()] * (M)  # type: "List[int]"
    B = [int()] * (M)  # type: "List[int]"
    for i in range(M):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, M, A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 69192
#include <bits/stdc++.h>
#define ll long long
#define arena ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

void dfs(ll v,ll color[],vector<pair<ll,ll>> g[],bool visited[])
{
    visited[v]=true;
    
    for(auto it:g[v])
    {
        if(visited[it.first]==false)
        {
            visited[it.first]=true;
            
            if((it.second)%2==0)
            color[it.first]=color[v];
            else
            {
                if(color[v]==1)
                {
                    color[it.first]=0;
                }
                else
                color[it.first]=1;
            }
            dfs(it.first,color,g,visited);
        }
    }
}

int main() 
{
    arena
    
    ll n;
    cin>>n;
    vector<pair<ll,ll>> g[n+1];
    for(ll i=1;i<=n-1;i++)
    {
        ll u,v,w;
        cin>>u>>v>>w;
        g[u].push_back({v,w});
        g[v].push_back({u,w});
    }
    
    bool visited[n+1];
    for(ll i=0;i<=n;i++)
    visited[i]=false;
    
    ll color[n+1];
    for(ll i=0;i<=n;i++)
    color[i]=-1;
    
    color[1]=1;
    
    dfs(1,color,g,visited);
    
    for(ll i=1;i<=n;i++)
    cout<<color[i]<<'\n';
}

Measured memory_bytes: 10880
#include<cstdio>
using namespace std;
typedef long long LL;
LL n,x;
LL gcd(LL x,LL y){return y?gcd(y,x%y):x;}
int main(){
	scanf("%lld%lld",&n,&x);
	printf("%lld",3*(n-gcd(n,x)));
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 200009;
ll n,i,g;
ll a[N],pos[N];
ii p[N];
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n;
    rep(i,0,n){
        cin>>a[i];
        p[i] = {a[i],i};
    }
    g = (n - 1) / 2;
    sort(p,p + n);
    rep(i,0,n) pos[p[i].se] = i;
    rep(i,0,n){
        if(pos[i] <= g)
            cout<<p[g + 1].f<<endl;
        else
            cout<<p[g].f<<endl;
    }
    return 0;
}

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

int main() {
    ll n;
    cin >> n;
    ll sum = 0;
    vector<ll> a(n);
    for(int i=0; i<n; ++i) {
        cin >> a[i];
    }
    ll res1 = 0;
    for(int i=0; i<n; ++i) {
        if(i == 0) {
            if(a[0] <= 0) {
                res1 += -a[0] + 1;
                sum = 1;
            } else {
                sum += a[i];
            }
        } else if(sum > 0 && sum + a[i] >= 0) {
            res1 += sum + a[i] + 1;
            sum = -1;
        } else if(sum < 0 && sum + a[i] <= 0) {
            res1 += -(sum + a[i]) + 1;
            sum = 1;
        } else {
            sum += a[i];
        }
    }
    sum = 0;
    ll res2 = 0;
    for(int i=0; i<n; ++i) {
        if(i == 0) {
            if(a[0] >= 0) {
                res2 += a[0] + 1;
                sum = -1;
            } else {
                sum += a[i];
            }
        } else if(sum > 0 && sum + a[i] >= 0) {
            res2 += sum + a[i] + 1;
            sum = -1;
        } else if(sum < 0 && sum + a[i] <= 0) {
            res2 += -(sum + a[i]) + 1;
            sum = 1;
        } else {
            sum += a[i];
        }
    }
    cout << min(res1, res2) << endl;
}


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

struct Fast {Fast() {std::cin.tie(0); ios::sync_with_stdio(false);}} fast;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define MOD 1000000007


int main() {
    int N; cin >> N;
    string S; cin >> S;
    int ans = 0;
    
    for (int k = 1; k < N; k++) {
        set<char> A, B;
        for (int i = 0; i < k ; i++)  {
            A.insert(S[i]);
        }
        for (int i = k; i < N; i++) {
            B.insert(S[i]);
        }
        int tmp = 0;
        rep(i, 26) {
            char c = 'a' + i;
            if (A.count(c) && B.count(c)) tmp++;
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
line = gets.chomp.to_i
puts l[line-1]

Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i=0; i<(long long)(n); i++)
#define REP(i, k, n) for(long long i=(long long)(k); i<(long long)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define PQ(T) priority_queue<T>
#define PQS(T) priority_queue<T, vector<T>, greater<T> >
#define deci cout << fixed << setprecision(15);
typedef long long ll;
const ll inf = 1020304050607080910;
const int mod = 1000000007;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
ll gcd(ll x,ll y){if(x>y)swap(x, y);while(x!=0){y%=x;swap(x, y);}return y;}
ll mpow(ll x,ll r){if(r==0)return 1;if(r%2==1){return x*mpow(x,r-1)%mod;}else{ll aa=mpow(x,r/2);return aa*aa%mod;}}

int N, ng, a[100010], ans[100010];
PQS(int) pq;

void OUT(void){
	rep(index, N) cout << ans[index] << " ";
	cout << "\n";
}

int main(){
	cin >> N;
	rep(i, N){ cin >> a[i+1]; pq.push(i+1); }
	if(N==2){ cout << -1 << endl; return 0; }
	if(N==3){
		vector<int> aa = {1, 2, 3};
		do{
			if(a[aa[0]] != aa[1] && a[aa[1]] != aa[2]){
				cout << aa[0] << " " << aa[1] << " " << aa[2] << "\n";
				return 0;
			}
		}while(next_permutation(all(aa)));
	}
	rep(i, N-1){
		if(i==0){ ans[i] = 1; pq.pop(); }
		else{
			int t = pq.top(); pq.pop();
			if(t == a[ans[i-1]]){
				ans[i] = pq.top(); pq.pop();
				pq.push(t);
			}else ans[i] = t;
		}
	}
	ans[N-1] = pq.top(); pq.pop();
	if(a[ans[N-2]] != ans[N-1]){ OUT(); return 0; }
	if(a[ans[N-3]] != ans[N-1] && a[ans[N-1]] != ans[N-2]){
		swap(ans[N-2], ans[N-1]); OUT(); return 0;
	}
	for(int i=N-4; i>=0; i--){
		if(i==N-4){
			ng = a[ans[i]];
			vector<int> aa = {ans[N-3], ans[N-2], ans[N-1]};
			sort(all(aa));
			do{
				if(ng != aa[0] && a[aa[0]] != aa[1] && a[aa[1]] != aa[2]){
					rep(j, N-3) cout << ans[j] << " ";
					cout << aa[0] << " " << aa[1] << " " << aa[2] << "\n";
					return 0;
				}
			}while(next_permutation(all(aa)));
			for(int j=N-3; j<N; j++){
				if(ans[j] != ng) pq.push(ans[j]);
				if(ans[j] != ng && a[ans[j]] != ng){
					int n1 = ans[N-2]+ans[N-1]-ng;
					int n2 = ans[N-3];
					if(n2 > ng) swap(n2, ng);
					ans[N-3] = n1, ans[N-2] = n2, ans[N-1] = ng;
					if(a[ans[N-3]] != ans[N-2] && a[ans[N-2]] != ans[N-1]){
						OUT(); return 0;
					}
					swap(ans[N-2], ans[N-1]);
					OUT(); return 0;
				}
			}
			pq.push(ans[i]);
		}else{
			if(a[ans[i]] != ng){
				ans[i+1] = ng;
				rep(j, N-i-2){
					int t = pq.top(); pq.pop();
					if(j != 0){ ans[j+i+2] = t; continue; }
					if(a[ans[i+1]] != t) ans[i+2] = t;
					else{
						ans[i+2] = pq.top(); pq.pop();
						pq.push(t);
					}
				}
				OUT();
				return 0; 
			}
			pq.push(ans[i]);
		}
	}
	ans[0] = ng;
	rep(i, N-1){
		int t = pq.top(); pq.pop();
		if(i != 0){ ans[i+1] = t; continue; }
		if(a[ans[i]] != t) ans[i+1] = t;
		else{
			ans[i+1] = pq.top(); pq.pop();
			pq.push(t);
		}
	}
	OUT();
	return 0;
}


Measured memory_bytes: 2168
#include <stdio.h>

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

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

    int cnt = 0;
    
    for(int i=1; i<=n; i++){
        if(p[i]!=i){
            cnt++;
        }
    }

    if(cnt==2 || cnt==0){
        printf("YES\n");
    }
    else{
        printf("NO\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define N 1000000 + 5
#define inf 123456789
#define rep(i, l, r) for(int i = l; i <= r; ++i)
#define Next(i, u) for(int i = h[u]; i; i = e[i].next)
struct edge{
    int v, next, w;
}e[N << 1];
struct node{
    int p, dis;
    bool operator < (const node &x) const{
        return x.dis < dis;
    }
};
bool book[N];
int n, m, u, v, c, uc, vc, tot, cnt, h[N], dis[N];
map <int, int> M[N];
priority_queue <node> q; 
int read(){
    char c; int x = 0, f = 1;
    c = getchar();
    while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
void add(int u, int v, int w){
    e[++tot].v = v, e[tot].w = w, e[tot].next = h[u], h[u] = tot;
    e[++tot].v = u, e[tot].w = w, e[tot].next = h[v], h[v] = tot;
}
int main(){
    n = read(), m = read(), cnt = n;
    rep(i, 1, m){
        u = read(), v = read(), c = read();
        if(M[u][c]) uc = M[u][c];
        else uc = M[u][c] = ++cnt, add(u, uc, 1);
        if(M[v][c]) vc = M[v][c];
        else vc = M[v][c] = ++cnt, add(v, vc, 1);
        add(uc, vc, 0);
    }
    memset(dis, 0x7f, sizeof(dis)), dis[1] = 0, q.push(node{1, 0});
    while(!q.empty()){
        int u = q.top().p; q.pop();
        if(book[u]) continue; book[u] = true;
        Next(i, u){
            int v = e[i].v;
            if(dis[v] > dis[u] + e[i].w) dis[v] = dis[u] + e[i].w, q.push(node{v, dis[v]});
        }
    }
    printf("%d", dis[n] > inf ? -1 : dis[n] / 2);
    return 0;
}

Measured memory_bytes: 90204
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n, a, b = MAP()
h = [INT() for _ in range(n)]
ad = a - b
l = 1
r = 10 ** 9
while r - l > 1:
    c = (r + l) // 2
    cnt = 0
    for i in range(n):
        cnt += (max(h[i] - b * c, 0) + ad - 1) // ad
    if c > cnt:
        r = c
    else:
        l = c
ans = inf
for i in range(l, r + 1):
    cnt = 0
    for j in range(n):
        cnt += (max(h[j] - b * i, 0) + ad - 1) // ad
    ans = min(ans, max(i, cnt))
print(ans)


Measured memory_bytes: 66904
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

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

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	x := getInt()
	a := make([]int, N)
	b := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
		if a[i] > x {
			b[i] = a[i] - x
		}
	}

	//	out(N, x, a, b)

	s := 0
	cnt := 0
	for i := 0; i < N; i++ {
		s = s + a[i]
		//		out("s", s)
		d := 0
		if s > x {
			d = s - x
			s = a[i] - d
			a[i] -= d
		} else {
			s = a[i]
		}
		cnt += d
		//		out(a[i], s, d, cnt)
	}
	//	out(a)
	out(cnt)
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAX_N = 100005;
int par[MAX_N],parcol[MAX_N],ans[MAX_N];
bool visit[MAX_N];
int maxcol = 1;

struct Edge
{
	int to,id;
};

vector<vector<Edge> > G(MAX_N);

void init()
{
	rep(i,MAX_N)
	{
		visit[i] = false;
	}
}

void makepar(int n)
{
	rep(i,G[n].size())
	{
		if (visit[G[n][i].to] == false)
		{
			par[G[n][i].to] = n;
			visit[G[n][i].to] = true;
			makepar(G[n][i].to);
		}
	}
	return;
}

void paint(int n, int c)
{
	int nowcol = 1;
	//cout << "G[n],size(): " << G[n].size() << endl;
	rep(i,G[n].size())
	{
		int u = G[n][i].to, ei = G[n][i].id;
		if (u == par[n])
		{
			//cout << "a" << endl;
			continue;
		}
		if (nowcol == c) nowcol++;
		//cout << "id:" << ei << " col:" << nowcol << endl;
		ans[ei] = nowcol;
		nowcol++;
		paint(u, ans[ei]);
	}
}

int main()
{
	int N;
	cin >> N;
	rep(i,N-1)
	{
		int a,b;
		cin >> a >> b;
		G[a-1].push_back(Edge{b-1,i});
		G[b-1].push_back(Edge{a-1,i});
	}

	par[0] = 0;
	visit[0] = true;
	makepar(0);
	paint(0,-1);

	int maxcol = 1;
	rep(i,N)
	{
		maxcol = max(maxcol,int(G[i].size()));
	}
	cout << maxcol << endl;
	rep(i,N-1)
	{
		cout << ans[i] << endl;
	}
	return 0;
}

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

int main(void)
{
    int n, tmp;
    cin >> n;
    int d[n][2];
    rep(i, n){
        rep(j, 2){
            cin >> tmp;
            d[i][j] = tmp;
        }
    }

    string ans="No";

    rep(i, n-2){
        if(d[i][0]==d[i][1]){
            if(d[i+1][0]==d[i+1][1]){
                if(d[i+2][0]==d[i+2][1]){
                    ans="Yes";
                    break;
                }else{
                    i+=2;
                }
            }else{
                i++;
            }
        }
    }

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

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

int main() {
  int n;
  cin >> n;
  vector<long long> a(200005, 0);
  vector<long long> c(200005, 0);
  for (int i = 1; i <= n; i++) {
    cin >> c.at(i);
    a.at(c.at(i))++;
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += a.at(i) * (a.at(i) - 1) / 2;
  }

  for (int i = 1; i <= n; i++) {
    cout << ans - a.at(c.at(i)) + 1 << endl;
  }
}


Measured memory_bytes: 5760
# abc120_b.py
import fractions 
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

A, B, K = map(int,input().split())
cnt = 0
_max = gcd(A,B)
while _max>=0:
    if A%_max==0 and B%_max==0:
        cnt += 1
        if cnt == K:
            print(_max)
            exit()
    _max -=1


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

using namespace std;

typedef pair<int,int> pi;


int main()
{
    int n,k;
    cin>>n>>k;
    vector<int> win(k+1,-1);
    vector<int> a(n);
    for(int i=0; i<n; i++)
        cin>>a[i];

    for(int i=1; i<=k; i++)
    {
        for(int j=0; j<n; j++)
        {
            int s = a[j];
            if(i-s<0)continue;

            if(win[i-s]==-1)
            {
                win[i]=1;
                break;
            }
        }
    }
    if(win[k]==1)
        cout<<"First";
    else
        cout<<"Second";
    return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string[]A = new string[N];
		string[]C = new string[N];
		int[]B = new int[N];
		for(var i=0;i<N;i++){
			string[] str = Console.ReadLine().Split();
			A[i] = str[0];
			C[i] = str[0];
			B[i] = int.Parse(str[1]);
		}
		Array.Sort(C);
		var dic = new Dictionary<string,int>();
		for(var i=0;i<N;i++){
			dic[C[i]] = i;
		}
		int[]D = new int[N];
		for(var i=0;i<N;i++){
			int a = 1;
			for(var j=0;j<N;j++){
				if(dic[A[j]]<dic[A[i]] || (A[j]==A[i] && B[j]>B[i])){
					a++;
				}
			}
			D[a-1] = i+1;
		}
		for(var i=0;i<N;i++){
			Console.WriteLine(D[i]);
		}
	}
}

Measured memory_bytes: 13152
S = gets.chomp

s = S.split(//)
K = %w(R U D).freeze
G = %w(L U D).freeze
0.upto(S.length - 1) do |i|
  n = i + 1
  if (n % 2 == 0 && !G.include?(s[i])) ||
     (n % 2 == 1 && !K.include?(s[i]))
    puts "No"
    exit
  end
end

puts "Yes"


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
const int N=100009;
int main()
{
  int n,ar[N],i;
  cin>>n;
  for(i=0; i<n; i++)
  {
    cin>>ar[i];
  }
  sort(ar,ar+n);
  /*for(i=0; i<n; i++)
  {
    cout<<i+1<<" "<<ar[i]<<endl;
  }*/
  int d=n/2;
  cout<<ar[d]-ar[d-1]<<endl;
 return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long 
#define rep(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define endl "\n"
#define dd double
using namespace std;

int main() 
{
    ios_base::sync_with_stdio(false);   
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n-1];
    rep(i,0,n-1)
    {
        cin>>a[i];
    }
    vector <int>p(n,0);
    for(int i=0;i<n-1;i++)
    {
        p[a[i]-1]++;
    }
     for(int i=0;i<n;i++)
    {
        cout<<p[i]<<endl;
    }  
    
}

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll X; cin >> X;

  ll ans = 1;
  for (ll b = 2; b <= 40; b++) {
    ll c = b * b;
    while (c <= X) {
      ans = max(ans, c);
      c *= b;
    }
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3604
#include <iostream>

int main(void){
    int A, B, C, X;
    std::string ans = "NO";
    std::cin >> A >> B >> C;

    for (int i = 0; i < B; ++i){
        X = A * (i + 1);
        if (X % B == C){
            ans = "YES";
            break;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


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

#define endll '\n'
#define ll long long

const int crow = 25;
bool visited [crow][crow];
string tiles[crow];
int row, col, cnt;

void dfs (int posx, int posy) {
    if (posx < 0 || posy < 0 || posx >= col || posy >= row || visited [posy][posx] || tiles[posy][posx] == '#')
        return;
    visited [posy][posx] = true;
    cnt++;
    dfs (posx-1, posy);
    dfs (posx+1, posy);
    dfs (posx, posy-1);
    dfs (posx, posy+1);
}


int main () {

    cin  >> col >> row;
    while (row && col) {
        int posx = 0, posy = 0;
        for (int j = 0; j < row; j++) {
            cin >> tiles[j];
            for (int i = 0; i < col; i++) {
                visited [j][i] = false;
                if (tiles[j][i] == '@') {
                    posx = i;
                    posy = j;
                    //visited [j][i] = true;
                }
            }
        }
        cnt = 0;
        dfs (posx, posy);
        cout << cnt << endll;
        cin  >> col >> row;
    }
}


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

const bool DEBUG = false;

using History = unordered_map<int, int>;

int solve(const int num, History& history) {
  if (DEBUG) cout << "num: " << num << endl;

  // キャッシュヒットの確認
  auto it = history.find(num);
  if (it != history.end()) {
    if (DEBUG) cout << "Cache hit: " << it->first << ", " << it->second << endl;
    return it->second;
  }

  int current;

  // 9の累乗のチェック
  current = num;
  if (current % 9 == 0) {
    while (current % 9 == 0) {
      current /= 9;
    }
    if (current == 1) {
      if (DEBUG) cout << "last withdraw with 9: " << num << endl;
      history[num] = 1;
      return 1;
    }
  }

  // 6の累乗のチェック
  current = num;
  if (current % 6 == 0) {
    while (current % 6 == 0) {
      current /= 6;
    }
    if (current == 1) {
      if (DEBUG) cout << "last withdraw with 6: " << num << endl;
      history[num] = 1;
      return 1;
    }
  }

  // 1-9で6でも9でも割れない場合
  if (num < 6) {
    if (DEBUG) cout << "last withdraw with 1: " << num << endl;
    history[num] = num;
    return num;
  }

  // いずれも割り切れない場合，上から順に検証
  int candidate_6 = 1;
  int candidate_9 = 1;
  while (candidate_6 * 6 <= num) candidate_6 *= 6;
  while (candidate_9 * 9 <= num) candidate_9 *= 9;
  if (DEBUG) cout << "candidate withdraw: " << candidate_6 << endl;
  int count_6 = solve(num - candidate_6, history) + 1;
  if (DEBUG) cout << "candidate withdraw: " << candidate_9 << endl;
  int count_9 = solve(num - candidate_9, history) + 1;

  int count = min(count_6, count_9);

  // int candidate = max(candidate_6, candidate_9);
  // if (DEBUG) cout << "withdraw: " << candidate << endl;
  // int count = solve(num - candidate, history) + 1;

  history[num] = count;
  return count;
}

int main(int argc, char const* argv[]) {
  int N;
  cin >> N;

  History history;

  int count = solve(N, history);
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	if (n % 2 == 0) {
		cout << 0.5000000000 << endl;
	}
	else {
		double d = (n - 1) / 2 + 1;
		double e = n;
		cout << d / e << endl;
	}
	return 0;
}

Measured memory_bytes: 256
from heapq import heappush, heappop, heapify


class UnionFindTree():
    def __init__(self, N):
        self.N = N
        self.__parent_of = [None] * N
        self.__rank_of = [0] * N
        self.__size = [1] * N

    def root(self, value):
        if self.__parent_of[value] is None:
            return value
        else:
            self.__parent_of[value] = self.root(self.__parent_of[value])
            return self.__parent_of[value]

    def unite(self, a, b):
        r1 = self.root(a)
        r2 = self.root(b)
        if r1 != r2:
            if self.__rank_of[r1] < self.__rank_of[r2]:
                self.__parent_of[r1] = r2
                self.__size[r2] += self.__size[r1]
            else:
                self.__parent_of[r2] = r1
                self.__size[r1] += self.__size[r2]
                if self.__rank_of[r1] == self.__rank_of[r2]:
                    self.__rank_of[r1] += 1

    def is_same(self, a, b):
        return self.root(a) == self.root(b)

    def size(self, a):
        return self.__size[self.root(a)]

    def groups(self):
        groups = {}
        for k in range(self.N):
            r = self.root(k)
            if r not in groups:
                groups[r] = []
            groups[r].append(k)
        return [groups[x] for x in groups]


def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    uft = UnionFindTree(N)
    for _ in range(M):
        x, y = map(int, input().split())
        uft.unite(x, y)
    groups = uft.groups()
    if len(groups) == 1:
        print(0)
        return
    ans = 0
    h = []
    for g in groups:
        costs = [A[x] for x in g]
        costs.sort()
        ans += costs[0]
        for cost in costs[1:]:
            heappush(h, cost)
    if len(groups) == 2 and N == 2:
        print(ans)
        return
    if len(h) < len(groups)-2:
        print("Impossible")
        return
    for _ in range(len(groups)-2):
        ans += heappop(h)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 111928
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	int count = 700;
	string s;
	cin >> s;
	for (int i = 0; i < 3; i++) {
		if (s[i] == 'o') {
			count = count + 100;
		}
	}
	cout << count << endl;
	int x;
	cin >>x;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
using namespace std;
int l,r;
int main() {
	scanf("%d%d",&l,&r);
	if(r-l<=2019) {
		int ans=2019;
		For(i,l,r)
			For(j,i+1,r)
			ans=min(1LL*ans,1LL*i*j%2019);
		printf("%d\n",ans);
		return 0;
	}
	puts("0");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);
vector<ll> G[100005];//隣接リスト
vector<bool> visited(100005);
vector<ll> ans(100005,INF);
void bfs(){
    queue<ll> que;
    
    que.push(1);
    visited[1]=true;
    while(que.size()){
        ll tmp=que.front(); que.pop();
        rep(i,sz(G[tmp])){
            if(!visited[G[tmp][i]]){
                ans[G[tmp][i]]=tmp;
                visited[G[tmp][i]]=true;
                que.push(G[tmp][i]);
            }
        }
    }
}
int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N,M; cin>>N>>M;
    rep(i,M){
        ll A,B; cin>>A>>B;
        G[A].pb(B);
        G[B].pb(A);
    }
    bfs();
    
    bool c=true;
    rep1(i,N){
        if(!visited[i]) c=false;
    }
    if(c){
        cout<<"Yes"<<endl;
        FOR(i,2,N+1){
            cout<<ans[i]<<endl;
        }
    }
    else cout<<"No"<<endl;
}



Measured memory_bytes: 12884
#include"bits/stdc++.h"
#include<valarray>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#define MAX 18

int n;

vector<long long int> v;


unordered_map<int,long long int> dp[MAX][MAX][850];

inline long long int dfs(int l,int r,int vl,int vr){
	if(l+1>=r)return 0;
	if(dp[l][r][vl].count(vr))return dp[l][r][vl][vr];
	dp[l][r][vl][vr]=LLONG_MAX;
	for(int i=l+1;i<r;i++){
		long long int tmp=vl+vr;
		long long int cof=tmp;
		long long int ret=dfs(l,i,vl,cof)+dfs(i,r,cof,vr)+cof*v[i];
		dp[l][r][vl][vr]=min(dp[l][r][vl][vr],ret);
	}
	return dp[l][r][vl][vr];
}


int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		long long int a;
		scanf("%lld",&a);
		v.push_back(a);
	}
	long long int ans=dfs(0,n-1,1,1)+v[0]+v.back();
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 26624
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] s = new int[n];
		for(int i=0;i<n;i++){
			s[i] = in.nextInt();
		}
		int q = in.nextInt();
		int[] t = new int[q];
		for(int i=0;i<q;i++){
			t[i] = in.nextInt();
		}
		int count = 0;
		for(int i=0;i<q;i++){
			int ul = s.length;
			int ll = -1;
			boolean flag = false;
			while(ll+1<ul){
				int mid = (ll+ul)/2;
				if(s[mid] == t[i]){
					flag = true;
					break;
				}
				else if(s[mid]<t[i]){
					ll = mid;
				}
				else{
					ul = mid;
				}
			}
			if(flag){
				count++;
			}
		}
		System.out.println(count);
	}
}

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

int main(){
    ll a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k>a+b){
        cout << a-(k-a-b) << endl;
    } else if(k>a){
        cout << a << endl;
    } else {
        cout << k << endl;
    }
}

Measured memory_bytes: 3584
#include <algorithm>
#include <cstdio>
#include <vector>

int main() {
  int n, l, q, a, b, left, right;
  int x[100000];
  std::vector<int> next[30];
  std::scanf("%d", &n);
  for (int ni = 0; ni < n; ++ni) {
    std::scanf("%d", &x[ni]);
  }
  std::scanf("%d%d", &l, &q);
  next[0].resize(n);
  for (int ni = 0; ni < n; ++ni) {
    int lower = ni;
    int upper = n;
    while (upper - lower > 1) {
      int pos = (lower + upper) / 2;
      if (x[pos] - x[ni] <= l) {
        lower = pos;
      } else {
        upper = pos;
      }
    }
    next[0][ni] = lower;
  }
  for (int k = 1; k < 30; ++k) {
    next[k].resize(n);
    for (int ni = 0; ni < n; ++ni) {
      next[k][ni] = next[k - 1][next[k - 1][ni]];
    }
  }
  for (int qi = 0; qi < q; ++qi) {
    int ans = 0;
    std::scanf("%d%d", &a, &b);
    left = std::min(a - 1, b - 1);
    right = std::max(a - 1, b - 1);
    for (int k = 29; k >= 0; --k) {
      if (next[k][left] < right) {
        left = next[k][left];
        ans += (1 << k);
      }
    }
    while (left < right) {
      left = next[0][left];
      ++ans;
    }
    std::printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 12928
#include<bits/stdc++.h>
#define x first
#define y second
typedef std::pair<int,int> pii;

const int maxN = 2e5 + 5;
const int P = 1e9 + 7;

int N;
pii A[maxN];
pii B[maxN];
int pre[maxN];
int suf[maxN];
int val[maxN];

int sum[maxN];
void Add(int x,int d) {
  if(!x) return ;
  for(; x <= N + 1; x += x & -x)
    (sum[x] += d) %= P;
}

int Get(int x) {
  if(x < 0) return 0;
  int res = 0;
  for(; x; x -= x & -x)
    (res += sum[x]) %= P;
  return res;
}

void input() {
  scanf("%d", &N);
  for(int i = 1;i <= N; ++i) {
    scanf("%d%d", &A[i].x, &A[i].y);
    val[i] = A[i].y;
  }
}

void exec() {
  std::sort(A + 1, A + N + 1);
  pre[1] = A[1].y; suf[N] = A[N].y;
  for(int i = 2;i <= N; ++i) pre[i] = std::max(pre[i-1], A[i].y);
  for(int i = N - 1; i; --i) suf[i] = std::min(suf[i+1], A[i].y);

  std::sort(val + 1,val + N + 1);

  for(int i = 1;i <= N; ++i) {
    A[i].y = std::lower_bound(val + 1, val + N + 1, A[i].y) - val;
    B[i].y = std::lower_bound(val + 1, val + N + 1, pre[i]) - val + 1;
    B[i].x = std::lower_bound(val + 1, val + N + 1, suf[i]) - val + 1;
    //std::cerr << B[i].x << ' ' << B[i].y << '\n';
  }

  std::sort(B + 1, B + N + 1); Add(1, 1);

  for(int i = 1;i <= N; ++i) {
    int tmp = (Get(N+1) - Get(B[i].x-2) + P) % P;
    Add(B[i].y, tmp);
    //std::cerr << tmp << '\n';
  }

  printf("%d\n", (Get(N+1) - Get(N) + P) % P);
}

int main() {
  if(fopen("infection.in","r")) {
    freopen("infection.in","r",stdin);
    freopen("infection.out","w",stdout);
  }

  input();
  exec();
  
  return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
typedef pair<P,double> C;
typedef pair<P,P> L;
 
const double eps=1e-8;
 
bool eq(double a,double b){
  return -eps<a-b&&a-b<eps;
}
 
double cross(P a,P b){
  return imag(b*conj(a));
}
 
bool isCrossCC(C a,C b){
  double ar=a.second, br=b.second;
  double dist=abs(a.first-b.first);
  if( dist > ar+br+eps)return false;
  if( dist > ar+br-eps )return true;
  if( dist > abs(ar-br)+eps)return true;
  if( dist > abs(ar-br)-eps)return true;
  return false;
}
 
double Sqrt(double x){
  if(x<0)return 0;
  return sqrt(x);
}
 
P reflect(P a,P b,P c){
  b-=a;
  c-=a;
  return a+ conj(c/b)*b;
}
 
P getCrossCC(C a,C b){
  P p1=a.first,p2=b.first;
  double r1=a.second, r2=b.second;
  double cA = (r1*r1+norm(p1-p2)-r2*r2) / (2.0*r1*abs(p1-p2));
  return p1+(p2-p1)/abs(p1-p2)*r1*P(cA, Sqrt(1.0-cA*cA) );
}
 
int n;
int t[15];
int u[6];
bool used[15];
double ans=-1;
 
double calcArea(double a,double b,double c){
  P p1=P(0,0);
  P p2=P(b,0);
  P p3=getCrossCC( C(p1,a) , C(p2,c) );
  return abs( cross( p1-p3 , p2-p3 )*0.5 );
}
 
P getCrossLL(L line0,L line1){
  P a=line0.first, b=line0.second;
  P c=line1.first, d=line1.second;
  a-=d;b-=d;c-=d;
  return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}
 
bool check(int a,int b,int c){
  if(a<b)swap(a,b);
  if(b<c)swap(b,c);
  if(a<b)swap(a,b);
  return ( a < b + c );
}
 
 
void check(){
 
   
  double S=calcArea(u[0],u[1],u[2]);
 
  double h=1e9;
   
  C ca = C( P(0,0) , u[4] );
  C cb = C( P(u[1],0) , u[5] );
  C cc = C( getCrossCC( C(ca.first,u[0]) , C(cb.first,u[2]) ) , u[3] );
 
  if( isCrossCC(ca,cb) == false )return;
  if( isCrossCC(cc,cb) == false )return;
  if( isCrossCC(ca,cc) == false )return;
   
  L fi  = L( getCrossCC(ca,cb) , getCrossCC(cb,ca) );
  if( abs(fi.second-fi.first ) < eps )return;
   
  L se  = L( getCrossCC(cc,ca) , getCrossCC(ca,cc) );
  if( abs(se.second-se.first ) < eps )return;
   
 
  L th = L( getCrossCC(cc,cb) , getCrossCC(cb,cc) );
   
  P target=getCrossLL(fi,se);
 
  P target2 = getCrossLL( th,se);
  if( abs(target-target2) > eps )return;
   
  double di;
   
  di=abs(P(0,0)-target);
  double Ah=min(h, Sqrt(u[4]*u[4]-di*di) );
 
  di=abs(P(u[1],0)-target);
  double Bh=min(h, Sqrt(u[5]*u[5]-di*di) );
 
  di=abs(cc.first-target);
  double Ch=min(h, Sqrt(cc.second*cc.second-di*di) );
  if( !eq(Ah,Ch) )return;
  if( !eq(Ah,Bh) )return;
  if( !eq(Bh,Ch) )return;
  h=min( Ah, Bh);
  h=min( h, Ah);
 
  ans=max(ans, h*S/3.0);
}
 
void dfs(int cnt){
  if(cnt>=3 && !check(u[0],u[1],u[2]))return;
  if(cnt>=5 && !check(u[0],u[3],u[4]))return;
  if(cnt>=6 && !check(u[1],u[4],u[5]))return;
  if(cnt>=6 && !check(u[2],u[3],u[5]))return;
   
  if(cnt==6){
    check();
  }else{
    for(int i=0;i<n;i++){
      if(used[i])continue;
      used[i]=true;
      u[cnt]=t[i];
      dfs(cnt+1);
      used[i]=false;
    }
  }
}
 
int main(){
  while(1){
    scanf("%d",&n);
    if(n==0)break;
     
    for(int i=0;i<n;i++){
      scanf("%d",&t[i]);
    }
 
    sort(t,t+n);
     
    memset(used,false,sizeof(used));
    ans=-1;
    dfs(0);
    printf("%.10f\n",ans);
  }
  return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

std::string S;

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

    std::cin >> S;

    ll res = 0;
    int s = 0, c = 0;

    for(char &ch : S){
        if(s == 0 && ch == 'A'){
            s += 1;
            c += 1;
        }else if(s == 1 && ch == 'A'){
            c += 1;
        }else if(s == 1 && ch == 'B'){
            s += 1;
        }else if(s == 2 && ch == 'A'){
            s = 1;
            c = 1;
        }else if(s == 2 && ch == 'C'){
            s += 1;
            res += c;
        }else if(s == 3 && ch == 'A'){
            s = 1;
            c += 1;
        }else if(s == 3 && ch == 'B'){
            s = 2;
        }else{
            s = 0;
            c = 0;
        }
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 720
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,m,i,j;
    int s[5],c[5];
    char buf[4];

    scanf("%d %d",&n,&m);
    for (i = 0; i < m; i++)
    {
        scanf("%d %d",&s[i],&c[i]);
    }
    if(n == 1)
    {
        for (i = 0; i < 10; i++)
        {
            sprintf(buf,"%d",i);
            for (j = 0; j < m; j++)
            {
                if(buf[s[j] - 1] - '0' != c[j])break;
            }
            if(j == m)break;
        }
        if(i != 10)printf("%d",i);
        else printf("-1");
    }
    else if(n == 2)
    {
        for (i = 10; i < 100; i++)
        {
            sprintf(buf,"%d",i);
            for (j = 0; j < m; j++)
            {
                if(buf[s[j] - 1] - '0' != c[j])break;
            }
            if(j == m)break;
        }
        if(i != 100)printf("%d",i);
        else printf("-1");
    }
    else
    {
        for (i = 100; i < 1000; i++)
        {
            sprintf(buf,"%d",i);
            for (j = 0; j < m; j++)
            {
                if(buf[s[j] - 1] - '0' != c[j])break;
            }
            if(j == m)break;
        }
        if(i != 1000)printf("%d",i);
        else printf("-1");
    }   
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  multiset<ll> se;
  for(ll i=0;i<n;i++){
    ll a; cin >>a; se.insert(a);
  }
  ll ans=0;
  while(se.size()){
    ll num = *se.rbegin();
    se.erase(se.find(num));
    ll t=1;
    while(t<=num)t*=2;
    if(se.count(t-num)){
      se.erase(se.find(t-num));
      ans++;
    }
  }
  cout<<ans<<endl;
}

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

int main(){
  long long a,b,k;
  cin >> a >> b >> k;
  if(a>=k){
   cout << a-k << " " << b;
  }
  else if(a+b>=k){
    cout << "0 " << a+b-k;
  }
  else{
    cout << "0 0";
  }
  return 0;
}




Measured memory_bytes: 256
using System.Collections.Generic;
using System.Collections;
using System.IO;
using System.Linq;
using System.Text;
using System;

class Prog
{
    public static void Main(string[] args)
    {
        new Prog().Solve();
    }

    public void Solve()
    {
        N = int.Parse(Console.ReadLine());
        hs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();


        int[] dp = new int[N];

        dp[0] = 0;
        dp[1] = Math.Abs(hs[0] - hs[1]);

        for (int i = 2; i < N; i++)
        {
            dp[i] = Math.Min((dp[i - 2] + Math.Abs(hs[i] - hs[i - 2])) , (dp[i - 1] + Math.Abs(hs[i] - hs[i - 1])));
        }
        Console.WriteLine(dp[N - 1]);
        Console.ReadKey();
    }

    int N;
    int[] hs;
}

public struct Vector2
{
    public Vector2(double x, double y)
    {
        this.@this = new double[] { x, y };
    }


    public double[] @this;

    public double x
    {
        get
        {
            return @this[0];
        }
        set
        {
            @this[0] = value;
        }
    }

    public double y
    {
        get
        {
            return @this[1];
        }
        set
        {
            @this[1] = value;
        }
    }

    public double magnitude { get { return Math.Pow(sqrMagnitude, 1 / 2); } }

    public double sqrMagnitude { get { return Math.Pow(x, 2) + Math.Pow(y, 2); } }

    public Vector2 normalized { get { return this * (1 / this.magnitude); } }

    public static Vector2 operator +(Vector2 a, Vector2 b)
    {
        return new Vector2(a.x + b.x, a.y + b.y);
    }

    public static Vector2 operator -(Vector2 a, Vector2 b)
    {
        return new Vector2(a.x - b.x, a.y - b.y);
    }

    public static Vector2 operator *(Vector2 a, double b)
    {
        return new Vector2(a.x * b, a.y * b);
    }


    public static Vector2 operator /(Vector2 a, double b)
    {
        if (b == 0)
        {
            throw new DivideByZeroException();
        }
        else return new Vector2(a.x / b, a.y / b);
    }

    public bool Equals(Vector2 other)
    {
        return (@this[0] == other.@this[0] && @this[1] == other.@this[1]);
    }

}

Measured memory_bytes: 18016
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
char board1[15][15];
int board[15][15];
int x ;
int main()
{
  bool flag1 = false;
  while( 1 ){
    for(int i=0 ; i<8; i++) {
      if(scanf("%s", board1[i]) == EOF ){
	flag1 = true;
	break;
      }
    }
    for(int i = 0;i < 8;i++){
      for(int j = 0;j <8;j++){
	board[i][j] =board1[i][j]-'0';
      }
    }
    if(flag1)
      break;
    bool flag = false;
    for(int i = 0;i < 8;i++){
      for(int j = 0;j < 8;j++){
	if(board[i][j] ==1){
	  if(board[i][j+1]==1&&board[i+1][j] ==1&&board[i+1][j+1]==1){
	    cout <<"A"<<endl;
	    flag = true;
	  }else if(board[i+1][j]==1&&board[i+2][j]==1&&board[i+3][j]==1){
	    cout <<"B"<<endl;
	    flag = true;
	  }else if(board[i][j+1]==1&&board[i][j+2]==1&&board[i][j+3]==1){
	    cout <<"C"<<endl;
	    flag = true;
	  }else if(board[i+1][j-1]==1&&board[i+1][j]==1&&board[i+1][j]==1&&board[i+2][j-1]==1){
	    cout <<"D"<<endl;
	    flag = true;
	  }else if(board[i][j+1]==1&&board[i+1][j+1]==1&&board[i+1][j+2]==1){
	    cout <<"E"<<endl;
	    flag = true;
	  }else if(board[i+1][j]==1&&board[i+1][j+1]==1&&board[i+2][j+1]==1){
	    cout <<"F"<<endl;
	    flag = true;
	  }else if(board[i][j+1] ==1&&board[i+1][j-1] ==1&&board[i+1][j]==1){
	    cout <<"G"<<endl;
	    flag = true;
	  }
	}
 
      }

    }
  
  }
  return 0;
}

Measured memory_bytes: 1152
import sys
sys.setrecursionlimit(10 ** 5)


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

S = SI()
k = len(S)
count = 15-k
for s in S:
    if s=="o":
        count+=1

if count>=8:
    print("YES")
else:
    print("NO")



Measured memory_bytes: 3064
#pragma GCC optimize("O3")
//#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
#define re return
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define make_unique(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define fi first
#define se second
#define ss second.second
#define sf second.first
#define ff first.first
#define fs first.second
#define sqrt(x) sqrt(abs(x))
#define mp make_pair
#define PI 3.14159265358979323846
#define E 2.71828182845904523536
#define er erase
#define in insert
#define fo(i,n) for((i)=0;(i)<(n);(i)++)
#define ro(i,n) for((i)=n-1;(i)>=0;(i)--)
#define fr(i,j,n) for((i)=(j);(i)<(n);(i)++)
#define rf(i,j,n) for((i)=((n)-1);(i)>=(j);(i)--)
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
    const int N=(int)1e5+100;
    const int M=(int)2e6+100;
    const int inf=(int)1e9+100;
#define filename ""

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //freopen(filename".in","r",stdin);
    //freopen(filename".out","w",stdout);
    //freopen("ans.txt","w",stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    srand(time(0));
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n,i,a;
    cin>>n;
    set<int> s;
    int ans=0;
    fo(i,n)
    {
        cin>>a;
        s.in(a);
        if (s.lower_bound(a)==s.begin())
        {
            ans++;
        }
    }
    cout<<ans;
}


Measured memory_bytes: 9600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
    int a,b,c;
    cin >> a >> b >> c;
  if (a+b+c == 17) cout << "YES" << endl;
  else cout << "NO" << endl;
    
  return 0;
}


Measured memory_bytes: 256