akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    if(n < a || n < b){
        cout << -1 << endl;
        return 0;
    }

    
    vector<int> idx(b, 0), start(b+1);
    start[0] = 1;
    idx[0] = a;
    reppp(i, 1, b){
        start[i] = start[i-1] + idx[i-1];
        idx[i] = (n-a)/(b-1) + ((n-a)%(b-1)>=i?1:0);
        if(idx[i] > a || idx[i] == 0){
            cout << -1 << endl;
            return 0;
        }
    }
    start[b] = start[b-1] + idx[b-1];

    if(start[b] != n+1){
        cout << -1 << endl;
        return 0;
    }

    for(int i=b-1;i>=0;i--){
        reppp(j, start[i], start[i+1]){
            cout << j << " ";
        }
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 3456
#include<iostream>
#include<cstdio>
using namespace std;
long long n,i,a[20],cnt,mx,x[20],N;
bool all9()
{
	for(int i=1;i<=cnt;i++)
	  if(a[i]!=9)
	    return false;
	return true;
}
bool all92()
{
	for(int i=1;i<cnt;i++)
	  if(a[i]!=9)
	    return false;
	return true;
}
void toarray()
{
	cnt=0;
	while(n)
	  a[++cnt]=n%10,n/=10;
}
int main()
{
	cin>>n;N=n;
	toarray();
	if(all9())
	{
		cout<<cnt*9;
		return 0;
	}
	if(all92())
	{
		cout<<cnt*9-9+a[cnt];
		return 0;
	}
	cout<<cnt*9-10+a[cnt];
	return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    string s;cin >>s;
    ll n=s.size();
    vector<ll>ans(n,0);
    ll r=0;
    for (int i = 0; i < n; ++i) {
        if(s[i]=='R'){
            r++;
        }
        else if(r!=0){
            ans[i-1]=r;
            r=0;
        }
    }
    //ok
    reverse(all(s));
    reverse(all(ans));
    ll l=0;
    for (int i = 0; i < n; ++i) {
        if(s[i]=='L'){
            l++;
        }
        else if(l!=0){
            ans[i-1]=l;
            l=0;
        }
    }
    reverse(all(ans));
   // for (int i = 0; i < n; ++i) {
     //   cout <<ans[i]<<" ";
    //}
    //cout <<endl;
    for (int i = 0; i < n; ++i) {
        if(ans[i]>0){
            ll tmp=ans[i]+ans[i+1];
            if(tmp%2==0){
                ans[i]=tmp/2;
                ans[i+1]=tmp/2;
            }
            else {
                if(ans[i]>ans[i+1]){
                    if(max(ans[i],ans[i+1])%2==0){
                        ans[i]=tmp/2;
                        ans[i+1]=tmp/2+1;
                    }
                    else {
                        ans[i]=tmp/2+1;
                        ans[i+1]=tmp/2;
                    }
                }
                else {
                    if(max(ans[i],ans[i+1])%2==0){
                        ans[i+1]=tmp/2;
                        ans[i]=tmp/2+1;
                    }
                    else {
                        ans[i+1]=tmp/2+1;
                        ans[i]=tmp/2;
                    }
                }
            }
            i++;
        }
    }
    for (int i = 0; i < n; ++i) {
        cout <<ans[i]<<" ";
    }
    cout <<endl;
    return 0;
}

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

int x[3000], y[3000];
bool g[5001][5001];

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	while(cin >> n && n){
		
		for(int i = 0; i < 5000; ++i){
			for(int j = 0; j < 5000; ++j){
				g[i][j] = false;
			}
		}
		
		for(int i = 0; i != n; ++i)
		{
			cin >> x[i] >> y[i];
			g[x[i]][y[i]] = true;
		}
		
		int ans = 0;
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < n; ++j){
				int dx = x[j] - x[i];
				int dy = y[j] - y[i];
				int res = dx * dx + dy * dy;
				if(dx >= 0 && dy >= 0 && res > ans && 
						x[j] + dy <= 5000 &&y[i] - dx >= 0 &&
						g[x[i] + dy][y[i] - dx] && g[x[j] + dy][y[j] - dx]){
							ans = res;
				}
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 25640
#!/usr/bin/env python3
import sys


def solve(N: int, S: "List[str]"):
    r = {'AC':0, 'WA':0, 'TLE':0, 'RE':0}
    for s in S:
        r[s] += 1

    print(f'AC x {r["AC"]}')
    print(f'WA x {r["WA"]}')
    print(f'TLE x {r["TLE"]}')
    print(f'RE x {r["RE"]}')
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    S = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 16212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
const ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

//UnionFind
//全て添字で扱うこと
struct union_find {
  vll parent;
  vll sizes;

  //コンストラクタ
  union_find(ll n) {
    for (ll i = 0; i < n; i++) {
      parent.push_back(i);
      sizes.push_back(1);
    }
  }

  //頂点nの根
  ll root_of(ll n) {
    if (parent[n] == n) return n;
    return parent[n] = root_of(parent[n]);
  }

  //頂点nと間接的に繋がっている頂点の数(自身含む)
  ll size_of(ll n) {return sizes[root_of(n)];}

  //頂点a, bが間接的に繋がっているか判定
  bool is_united(ll a, ll b) {return (root_of(a) == root_of(b));}

  //頂点aを含むグラフに頂点bを含むグラフを結合
  void unite(ll a, ll b) {
    if (is_united(a, b)) return;
    //if (size_of(a) < size_of(b)) swap(a, b);
    sizes[root_of(a)] += size_of(b);
    parent[root_of(b)] = root_of(a);
  }
};

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  union_find uf(n);
  vector<vll> nx(n, vll(0));
  for (ll i = 0; i < m; i++) {
    ll a, b;
    cin >> a >> b;
    uf.unite(a - 1, b - 1);
    nx[a - 1].push_back(b - 1);
    nx[b - 1].push_back(a - 1);
  }
  vll bl(n, 0);
  for (ll i = 0; i < k; i++) {
    ll c, d;
    cin >> c >> d;
    if (uf.is_united(c - 1, d - 1)) {
      bl[c - 1]++;
      bl[d - 1]++;
    }
  }
  for (ll i = 0; i < n - 1; i++) cout << uf.size_of(i) - 1 - nx[i].size() - bl[i] << " ";
  cout << uf.size_of(n - 1) - 1 - nx[n - 1].size() - bl[n - 1] << endl;
}

Measured memory_bytes: 9836
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const ll INF = 1<<29;
int main(){
int n;cin>>n;
vector<string> s(n);
map<string,int> map;
ll cnt=0;
rep(i,n){
    cin>>s[i];
    sort(all(s[i]));
    cnt+=map[s[i]];
    map[s[i]]++;
}
cout<<cnt<<endl;
}

Measured memory_bytes: 18176
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb(in,tmp) in.push_back(tmp)
#define all(in) in.begin(),n.end()
#define PI acos(-1)
using namespace std;
int main(){
  int sum=0;
  int tmp;
  rep(i,5){
    cin>>tmp;
    if(tmp>=40)sum+=tmp;
    else sum+=40;
  }
  cout<<sum/5<<endl;


}

Measured memory_bytes: 1160
def main():
    import collections
    
    N = int(input())
    num_list = [int(i) for i in input().split()]

    count_list = collections.Counter(num_list)
    calc_d = collections.defaultdict(int)
    
    for i in set(count_list.values()):
        calc_d[i] = int(i * (i - 1) / 2 - (i - 1) * (i - 2) / 2)
    
    ans = int(sum([0 if i == 1 else i * (i - 1) / 2 for i in count_list.values()]))

    for i in num_list:
        print(ans - calc_d[count_list[i]])

if __name__ == '__main__':
    main()

Measured memory_bytes: 26772
import java.util.*;

class Main{
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt(); //3桁の整数
      
      int N_3 = N/100;
      int N_2 = (N/10)%10;
      int N_1 = N%10;
      
      if( N_3 == 7)
        System.out.println("Yes");
      else{
      	if( N_2 == 7)
          System.out.println("Yes");
        else{
        	if(N_1 == 7)
              System.out.println("Yes");
          	else
              System.out.println("No");
        }
      }
      
    }
}

Measured memory_bytes: 35576
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5, M = N<<3;
int n, P[N], Q[N], bP[N], bQ[N], S, T, tot = 1, hd[N<<1], cur[N<<1], nxt[M], to[M], cap[M], d[N<<1], ans;
void _add(int x, int y, int z) { nxt[++tot] = hd[x], to[tot] = y, cap[tot] = z, hd[x] = tot; }
void add(int x, int y, int z) { _add(x, y, z), _add(y, x, 0); }
bool bfs()
{
    static int q[N<<1], l, r; q[l=r=1] = S, memset(d+1, 0, sizeof(int)*T), d[S] = 1;
    while(l <= r) for(int x = q[l++], i = hd[x], y; i; i = nxt[i]) if(!d[y = to[i]]&&cap[i])
    {    d[y] = d[x]+1, q[++r] = y; if(y == T) return true; }
    return false;
}
int dfs(int x, int f)
{
    if(x == T) return f; int r = f, k;
    for(int &i = cur[x], y; i&&r; i = nxt[i]) if(d[y=to[i]] == d[x]+1&&cap[i])
        k = dfs(y, min(cap[i], r)), cap[i] -= k, r -= k, cap[i^1] += k, !k?d[y]=0:0;
    return f-r;
}
int main()
{
    scanf("%d", &n), S = n<<1, T = n<<1|1, ans = n;  
    for(int i = 1; i <= n; ++i) scanf("%d", P+i), ++P[i], bP[i] = i;
    for(int i = 1; i <= n; ++i) scanf("%d", Q+i), ++Q[i], bQ[i] = i+n;
    for(int i = 1; i <= n; ++i)
    {
        if(bP[i] == i) for(int x = P[i]; x != i; x = P[x]) bP[x] = i;
        if(bQ[i] == i+n) for(int x = Q[i]; x != i; x = Q[x]) bQ[x] = i+n;
    }
    for(int i = 1; i <= n; ++i)
        if(P[i] == i&&Q[i] == i) --ans;
        else if(Q[i] == i) add(S, bP[i], 1);
        else if(P[i] == i) add(bQ[i], T, 1);
        else if(P[i] != Q[i]) add(bQ[i], bP[i], 1);
        else add(bQ[i], bP[i], 1), add(bP[i], bQ[i], 1);
    while(bfs()) memcpy(cur+1, hd+1, sizeof(int)*T), ans -= dfs(S, n); printf("%d\n", ans);
    return 0;
}

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

using Graph = vector<vector<int>>;
using pint = pair<int,int>;

int N,M;
Graph G;
int S,T;

int64_t solve(){
    vector<vector<int64_t>> dist(N,vector<int64_t>(3,-1));
    dist[S][0] = 0;
    queue<pint> que;
    que.push(pint(S,0));
    while ( !que.empty() ){
        pint p = que.front(); que.pop();
        int64_t pos = p.first;
        int64_t num = p.second;
        for ( auto npos: G[pos] ){
            int64_t nnum = ( num + 1 ) % 3;
            if ( dist.at(npos).at(nnum) == -1 ){
                dist.at(npos).at(nnum) = dist.at(pos).at(num) + 1;
                que.push(pint(npos,nnum));
            }
        }
    }
    if ( dist.at(T).at(0) == -1 ) return -1;
    else return dist.at(T).at(0) / 3 ;
}

int main() {
    cin >> N >> M;
    G.assign(N,vector<int>());
    for ( int i = 0; i < M; ++i){
        int u,v;
        cin >> u >> v;
        --u; --v;
        G[u].push_back(v);
    }
    cin >> S >> T ;
    --S; --T;
    cout << solve() << endl;
    
    return 0;
}



Measured memory_bytes: 11136
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())
W = [input() for _ in range(N)]

s = W[0][-1]

ok = True
used = set()
used.add(W[0])
for w in W[1:]:
    if s != w[0] or w in used:
        ok = False

    s = w[-1]
    used.add(w)

print("Yes" if ok else "No")


Measured memory_bytes: 3572
//header
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<stdlib.h>
#include<time.h>

//main
int main(void)
{
	char st[15];
	int a, b, c;
	int max=999;

	gets(st);

	for (int i = 0; i < 8; i++) {
		if (st[i + 2] == 0) {
			break;
		}

		a = st[i] - 48;
		b = st[i + 1] - 48;
		c = st[i + 2] - 48;
		
		if (max > abs(753 - (100 * a + 10 * b + c))) {
			max = abs(753 - (100 * a + 10 * b + c));
		}
	}
	printf("%d", max);

	return 0;

}

Measured memory_bytes: 128
awk -M '\
NR==1{split($0,A)}
NR==2{N=$1}
END{
    A[2] = A[2] < 2*A[1] ? A[2] : 2*A[1];
    A[3] = A[2]*2 < A[3] ? A[2]*2 : A[3];
    if(A[3]*2 <= A[4] || N==1){
        print N*A[3]
    }else{
        t = int(N/2);
        print t*A[4]+(N%2)*A[3]
    }
}'

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

int main() {
    int64_t N, K;
    std::cin >> N >> K;

    int A[N];
    for (int i = 0; i < N; ++i) {
        std::cin >> A[i];
        --A[i];
    }

    if (K <= N) {
        int cur = 0;
        for (int64_t i = 0; i < K; ++i) {
            cur = A[cur];
        }

        std::cout << cur + 1 << std::endl;
        return 0;
    }

    std::vector<int64_t> visited(N, -1);
    visited[0] = 0;
    int64_t cur = 0, before_loop = 0, loop_cnt = 1;
    for (int64_t i = 1; i <= N; ++i) {
        cur = A[cur];
        if (visited[cur] == -1) {
            visited[cur] = i;
        } else {
            before_loop = visited[cur];
            loop_cnt = i - visited[cur];
            break;
        } 
    }

    K -= before_loop;
    K %= loop_cnt;

    for (int64_t i = 0; i < K; ++i) {
        cur = A[cur];
    }

    std::cout << cur + 1 << std::endl;

    return 0;
}


Measured memory_bytes: 5596
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val s = br.readLine()!!
    val t = br.readLine()!!
    val convertMapSToT = mutableMapOf<Char, Char>()
    val convertMapTToS = mutableMapOf<Char, Char>()

    for (i in s.indices) {
        val sToT = convertMapSToT[s[i]]
        val tToS = convertMapTToS[t[i]]

        if (sToT == null) {
            convertMapSToT[s[i]] = t[i]
        } else if (t[i] != sToT) {
            out.println("No")
            return
        }

        if (tToS == null) {
            convertMapTToS[t[i]] = s[i]
        } else if (s[i] != tToS) {
            out.println("No")
            return
        }
    }
    out.println("Yes")
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


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

class Main
{
	static long MOD = 1000000007;
	static class node
	{
		int h, b, idx;
		node(int h, int b, int idx)
		{
			this.h=h;
			this.b=b;
			this.idx=idx;
		}
	}

	static class sorting implements Comparator<node>
	{
		@Override
		public int compare(node n1, node n2)
		{
			return n1.h-n2.h;
		}
	}

	static void updateBIT(long bit[], int idx, long val)
	{
		while(idx<bit.length)
		{
			bit[idx]=Math.max(bit[idx], val);
			idx+=(idx&(-idx));
		}
	}

	static long queryBIT(long bit[], int idx)
	{
		long ans=0;
		while(idx>0)
		{
			ans=Math.max(ans, bit[idx]);
			idx-=(idx&(-idx));
		}
		return ans;
	}

	public static void main(String[] args)
	{
		FastReader scan=new FastReader();
		int n=scan.nextInt();
		int h[]=new int[n];
		int b[]=new int[n];

		ArrayList<node> ar=new ArrayList<>();

		for(int i=0;i<n;i++)
			h[i]=scan.nextInt();

		for(int i=0;i<n;i++)
			b[i]=scan.nextInt();

		for(int i=0;i<n;i++)
		{
			node newnode=new node(h[i], b[i], i+1);
			ar.add(newnode);
		}
		
		Collections.sort(ar, new sorting());

		long bit[]=new long[n+2];
		long ans=0;

		for(int i=0;i<n;i++)
		{
			node curr = ar.get(i);
			long get = queryBIT(bit, curr.idx-1);

			ans = Math.max(ans, get+curr.b);

			updateBIT(bit, curr.idx, (long)(get+curr.b));
		}

		System.out.println(ans);

	}


static class FastReader
{
    BufferedReader br;
    StringTokenizer st;
 
    public FastReader()
    {
        br = new BufferedReader(new
                InputStreamReader(System.in));
    }
 
    String next()
    {
        while (st == null || !st.hasMoreElements())
        {
            try
            {
                st = new StringTokenizer(br.readLine());
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }
 
    int nextInt()
    {
        return Integer.parseInt(next());
    }
 
    long nextLong()
    {
        return Long.parseLong(next());
    }
 
    double nextDouble()
    {
        return Double.parseDouble(next());
    }
 
    String nextLine()
    {
        String str = "";
        try
        {
            str = br.readLine();
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        return str;
    }
}



}


Measured memory_bytes: 69668
/*
* Author : Omkar Deshmukh
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define all(v) v.begin(), v.end()
#define intvect vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; i < n; i++)
#define boolv vector<bool>
#define ld long double
#define deb(x) cout << #x << " " << x << endl;
#define pb push_back
#define pob pop_back
#define F first
#define S second
#define ub upper_bound
#define bs binary_search
#define lb lower_bound
#define ull unsigned long long

// bool flag = 0;
// const ll mod = 1e9 + 7;
// const ll N = (ll)5e5 + 4;
// bool ans = 0;
template <typename... T>
void read(T &... args)
{
    ((cin >> args), ...);
}

template <typename... T>
void write(T &&... args) //rvalue references
{
    ((cout << args), ...);
}

void vjudge()
{
#ifndef ONLINE_JUDGE
    if (fopen("input.txt", "r"))
    {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void solve()
{
    int n;
    read(n);
    int d;
    read(d);
    int ctr = 0;
    while (n--)
    {
        int x, y;
        read(x, y);
        if (sqrt(x * x + y * y) <= d)
            ctr++;
    }
    write(ctr);
}

int32_t main()
{
    vjudge();
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
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; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;



int main(){

string s;
cin >> s;
for(int i=0;i<s.length();i++){
    cout << 'x';
}
cout << endl;

return 0;
}





Measured memory_bytes: 256
from collections import Counter

n , m = map(int, input().split())
err = 0
ans = 0

par = [0] * n
rank = [0] * n

#初期化
for i in range(n):
    par[i] = i
    rank[i] = 0

#判定(一番上野根を求める)
def find(x):
    if par[x] == x:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
    
#結合
def unite(x , y):
    rx = find(x)
    ry = find(y)
    
    if rx == ry:
        return
    
    if rank[rx] < rank[ry]:
        par[rx] = ry
    elif rank[rx] > rank[ry]:
        par[ry] = rx
    else:
        par[ry] = x
        rank[rx] += 1

a = [0] * m
b = [0] * m

for i in range(m):
    a[i] , b[i] = map(int, input().split())

ans = 0
for i in range(m):
    for v in range(n):
        par[v] = v
        rank[v] = 0
        
    for j in range(m):
        if j == i:
            continue
        unite(a[j]-1 , b[j]-1)
        r = [find(k) for k in range(n)]
    if len(Counter(r)) != 1:
        ans += 1
        
print(ans)

Measured memory_bytes: 46572
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

int main() {
  ll x, y, z; cin >> x >> y >> z;
  ll k; cin >> k;
  vector <ll> a(x), b(y), c(z);
  rep(i, x) cin >> a.at(i);
  rep(i, y) cin >> b.at(i);
  rep(i, z) cin >> c.at(i);
  vector <ll> ab;
  rep(i, x) {
    rep(j, y) {
      ab.push_back(a.at(i)+b.at(j));
    }
  }
  sort(ab.begin(), ab.end());
  reverse(ab.begin(), ab.end());
  sort(c.begin(), c.end());
  vector <ll> loc(z, 0);
  rep(i, k) {
    vector <pair <ll, ll>> v(z, pair <ll, ll> ());
    ll res = 0, max_loc;
    rep(j, z) {
      if (loc.at(j) < x*y) {
        ll tmp = c.at(j) + ab.at(loc.at(j));
        if (tmp > res) {
          res = tmp;
          max_loc = j;
        }
      }
    }
    cout << res << endl;
    loc.at(max_loc)++;
  }
}

Measured memory_bytes: 11660
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val w = Array(n) { readLine()!! }
    val s = mutableSetOf(w[0])
    var c = w[0].last()
    for (i in 1 until n) {
        val cw = w[i]
        if (cw.first() != c || cw in s) {
            println("No")
            return
        }
        c = cw.last()
        s += cw
    }
    println("Yes")
}


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

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 998244353 #出力の制限
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
ans =0
ml =[m-1]*n

if n ==1:
    print(m)
    exit()
elif m ==1:
    if k ==n-1:
        print(1)
        exit()
    else:
        print(0)
        exit()
for l in range(1,n):
    ml[l] = ml[l-1]*(m-1) % mod

for i in range( 2, n + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

for j in range(k+1):
    if n-2-j >=0:
        a = m*ml[n-2-j]*cmb(n-1,j,mod)
        ans +=a
    elif n - 2- j == -1:
        a = n
        ans +=a
    elif n - 2- j == -2:
        a = 1
        ans +=a        
print(ans % mod)

Measured memory_bytes: 40872
#include <stdio.h>

int main(){
    int n,s=0;
    scanf("%d", &n);
    char str[50];
    scanf("%s", &str);

    for(int i=0; i < n; ++i){
       if (str[i]=='A' && str[(i+1)]=='B' && str[(i+2)]=='C'){
           ++s;
       }
    }
printf("%d", s);
    return 0;
}


Measured memory_bytes: 128
import sys

n = int(sys.stdin.readline())
numbers = sys.stdin.readline().split()
for i in range(n):
    numbers[i] = int(numbers[i])
a_list = [0, abs(numbers[1] - numbers[0])]
if n > 2:
    a_list.append(abs(numbers[2] - numbers[0]))
else:
    print(a_list[-1])
    sys.exit()
for i in range(3, n):
    a_list.append(min(a_list[i-1]+abs(numbers[i-1] - numbers[i]), a_list[i-2]+abs(numbers[i-2] - numbers[i])))
print(a_list[-1])
sys.exit()

Measured memory_bytes: 16696
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1)
int main()
{
    int n,i,j,k,l;
    double x,y;
    cin>>x;
    y=2*pi*x;
    cout<<fixed<<setprecision(2)<<y<<endl;
    return 0;
}


Measured memory_bytes: 3764
// #include C/C++ {
#include <bits/stdc++.h>
// }
using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef _DEBUG

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 10005
#define MAX_M 55
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

/////////////////////////////////////////////////////////////
vector <int> G[MAX_N];
int deg[MAX_N];
int c[MAX_N];
int res[MAX_N];
/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
	//  WF("output.txt");
	DF("err.txt");

	int N;
	scanf("%d", &N);
	for (int i = 1; i < N; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		G[a].emplace_back(b);
		G[b].emplace_back(a);
		deg[a]++;
		deg[b]++;
	}
	for (int j = 0; j < N; j++) scanf("%d", c + j);
	sort(c, c + N);
	queue <int> Q;
	for (int s = 1; s <= N; s++) if (deg[s] == 1) Q.push(s);
	int ptr = 0;
	while (!Q.empty()) {
		int u = Q.front(); Q.pop();
		res[u] = c[ptr++];
		for (int v : G[u]){
			deg[u]--;
			if (--deg[v] == 1) Q.push(v);
		}
	}
	int summ = 0;
	for (int u = 1; u <= N; u++) for (int v : G[u]) 
		summ += min(res[u], res[v]);
	printf("%d\n", summ >> 1);
	for (int s = 1; s <= N; s++) printf("%d%c", res[s], " \n"[s == N]);
	return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	private StringTokenizer st;
	private BufferedReader bf;
	private int w;
	
	Main() {
		readData();
		

	}	

	private void readData() {
		try {
			bf = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(bf.readLine());
			
			int n = nextInt();
			int[] a;
			for (int i = 0;i < n ; i++) {
				a = new int[3];
				a[0] = nextInt();
				a[1] = nextInt();
				a[2] = nextInt();
				Arrays.sort(a);
				
//				for(int k: a)
//					System.out.println(k);
					
				if ((a[0]*a[0]+a[1]*a[1])==a[2]*a[2])
					System.out.println("YES");
				else
					System.out.println("NO");
			}
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
	
	
	private String next() throws IOException {
		if (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(bf.readLine());
		return st.nextToken();
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Main m = new Main();
	}

}

Measured memory_bytes: 18464
N=int(input())
kuku=[1,
 2,
 3,
 4,
 5,
 6,
 7,
 8,
 9,
 2,
 4,
 6,
 8,
 10,
 12,
 14,
 16,
 18,
 3,
 6,
 9,
 12,
 15,
 18,
 21,
 24,
 27,
 4,
 8,
 12,
 16,
 20,
 24,
 28,
 32,
 36,
 5,
 10,
 15,
 20,
 25,
 30,
 35,
 40,
 45,
 6,
 12,
 18,
 24,
 30,
 36,
 42,
 48,
 54,
 7,
 14,
 21,
 28,
 35,
 42,
 49,
 56,
 63,
 8,
 16,
 24,
 32,
 40,
 48,
 56,
 64,
 72,
 9,
 18,
 27,
 36,
 45,
 54,
 63,
 72,
 81]
if N in kuku:
    print("Yes")
else:
    print("No")

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

using namespace std;

int solve(vector<vector<int>>& a, int index, vector<int>& current, int goal, int cost, vector<int> costs) {
	if (index == a.size()) {
		for (auto skill : current) {
			if (skill < goal) {
				return INT_MAX;
			}
		}

		return cost;
	}

	int res = INT_MAX;

	res = min(res, solve(a, index + 1, current, goal, cost, costs));

	for (int i = 0; i < a[index].size(); i++) {
		current[i] += a[index][i];
	}

	res = min(res, solve(a, index + 1, current, goal, cost + costs[index], costs));

	for (int i = 0; i < a[index].size(); i++) {
		current[i] -= a[index][i];
	}

	return res;
}

int main() {
	int n, m, x;
	cin >> n >> m >> x;

	vector<int> costs(n);

	vector<vector<int>> a(n, vector<int>(m, 0));

	for (int i = 0; i < n; i++) {
		cin >> costs[i];
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}

	vector<int> current(m);

	int res = solve(a, 0, current, x, 0, costs);

	cout << (res == INT_MAX ? -1 : res);
} 

Measured memory_bytes: 3612
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int A = stdIn.nextInt();
			int B = stdIn.nextInt();
			if(A == 0 && B == 0)
			{
				break;
			}
			int sum = B - A;
			int thousand, fiveHundred, hundred;
			thousand = sum / 1000;
			sum %= 1000;
			fiveHundred = sum / 500;
			sum %= 500;
			hundred = sum / 100;
			System.out.println(hundred + " " + fiveHundred + " " + thousand);
		}
	}
}

Measured memory_bytes: 12000
from math import gcd, sqrt
from functools import reduce

n, *A = map(int, open(0).read().split())
def f(A):
    sup = max(A)+1
    table = [set() for i in range(sup)]
    for i in range(2, sup):
        if not table[i]:
            for j in range(i, sup, i):
                table[j].add(i)
    D = set()
    for a in A:
        for b in table[a]:
            if b not in D:
                D.add(b)
            else:
                return False
    return True

if reduce(gcd, A) == 1:
    if f(A):
        print('pairwise coprime')
    else:
        print('setwise coprime')
else:
    print('not coprime')

Measured memory_bytes: 366452
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

n,a,b,c=map(int,input().split())
L=[]
for _ in range(n):
    L.append(int(input()))

ans=99999
for i in range(4**len(L)):
    i_4_list=list(Base_10_to_n(i, 4).zfill(len(L)))
    at,bt,ct=[],[],[]
    for num,i_4 in enumerate(i_4_list):
        if i_4=='0':
            at.append(L[num])
        elif i_4=='1':
            bt.append(L[num])
        elif i_4=='2':
            ct.append(L[num])
        else:
            continue
    if min(len(at),len(bt),len(ct))>0:
        al=0
        al+=(len(at)+len(bt)+len(ct)-3)*10
        al+=(abs(sum(at)-a)+abs(sum(bt)-b)+abs(sum(ct)-c))
        if al < ans:
            ans=al
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
int a,sum=0;
  scanf("%d",&a);
int b[100],c[100];
  for (int i=0;i<a;i++){
    scanf("%d",&b[i]);
  }
  for (int i=0;i<a;i++){
    scanf("%d",&c[i]);
  }
  for (int i=0;i<a;i++){
    if(b[i]>c[i]){
      sum=sum+b[i]-c[i];
  }
}
printf("%d",sum);
}

Measured memory_bytes: 128
'''
Author : Shubhanshu Jain;
'''
import sys
input = sys.stdin.readline
from collections import Counter
import math
import random;
mod =1000000007
r1 = lambda : int(input());
rm = lambda : map(int,input().split());
rls = lambda : list(rm())

a,b,x = rm();
if(x<a):
    print("NO");
elif((a+b)>=x):
    print("YES");
else:
    print("NO")

Measured memory_bytes: 4584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define lcm(a, b) ((a * b) / gcd(a, b))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()
#define UN(v) sort(all(v)), v.resize(unique(all(v))-v.begin())

#define endl '\n'

const long long INF = 100000000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;
const double PI = acos(-1);

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

lli gcd(lli a , lli b) {
    if(b == 0) return a;
    a %= b;
    return gcd(b,a);
}

void solve() {
    lli n;
    cin >> n;
    vlli graph[MAXN];
    vlli colorParent(MAXN, 0), vis(MAXN, 0);
    map<plli, lli> colorEdges;
    vplli edges;

    for (int i = 1; i < n; ++i) {
        lli u, v;
        cin >> u >> v;
        graph[u].push_back(v);
        graph[v].push_back(u);
        edges.push_back({u, v});
    }

    //bfs
    queue<lli> q;
    q.push(1);
    lli ans = 0;

    while (!q.empty()) {
        lli x = q.front();
        q.pop();

        ans = max(ans, (lli)graph[x].size());

        if (vis[x]) {
            continue;
        }
        vis[x] = 1;

        int color = 1;
        for (lli u : graph[x]) {
            if (vis[u]) continue;
            if (color == colorParent[x]) color++;
            colorParent[u] = colorEdges[{u, x}] = colorEdges[{x, u}] = color++;
            //vis[u] = 1;
            q.push(u);
        }
    }

    cout << ans << endl;
    for (auto & edge : edges) {
        cout << colorEdges[{edge.first, edge.second}] << endl;
    }
}

int main()
{
    IOS;
    //comment it out
    //freopen("input.txt", "r", stdin);
    lli t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 22256
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
#include <chrono>
using namespace std;
using namespace std::chrono;
int main(){
    int n;
    cin >> n;
    long long l[100];
    for(int i = 0; i <= n; i++){
        if(i == 0) l[i] = 2;
        else if(i == 1) l[i] = 1;
        else l[i] = l[i-1] + l[i-2];
    }
    cout << l[n] << endl;
}

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

typedef map<int,int> Map;

int main(){
  int n;
  Map mp0,mp1;
  cin >> n;
  for (int i = 0; i < n; i+=2) {
    int a,b;
    cin >> a >> b;
    mp0[a]++;
    mp1[b]++;
  }

  int mx00,key00,mx01,key01,mx10,key10,mx11,key11;
  mx00 = 0;
  mx01 = 0;
  mx10 = 0;
  mx11 = 0;
  for(auto itr=mp0.begin(); itr != mp0.end(); itr++){
    if(itr->second >= mx00){
      mx01 = mx00;
      key01 = key00;

      mx00 = itr->second;
      key00 = itr->first;
    }else if(itr->second >= mx01){
      mx01 = itr->second;
      key01 = itr->first;
    }

  }
  for(auto itr=mp1.begin(); itr != mp1.end(); itr++){
    if(itr->second >= mx10){
      mx11 = mx10;
      key11 = mx10;

      mx10 = itr->second;
      key10 = itr->first;
    }else if(itr->second >= mx11){
      mx11 = itr->second;
      key11 = itr->first;
    }
  }

  if(key00!=key10){
    cout << n/2-mx00+n/2-mx10 << endl;
  }else{
    int a = n/2-mx01+n/2-mx10;
    int b = n/2-mx00+n/2-mx11;
    cout << min(a,b) << endl;
  }

  return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>

#define INF 1000000000
#define LM 55555
using namespace::std;


long Lmax(long x, long y) {
	if (x > y)return x;
	return y;
}

int max(int x, int y) {
	if (x > y)return x;
	return y;
}

long Lmin(long x, long y) {
	if (x < y)return x;
	return y;
}


int min(int x, int y) {
	if (x < y)return x;
	return y;
}

int abs(int a) {
	if (a < 0) {
		return -a;
	}
	return a;
}

int A,B,C,X,Y,N, M[LM],num,v[55555],ch,ans;
string s[50], t[100];
bool a, b, c;
int main() {
	cin >> A>>B>>C>>N;
	if (abs(A - C) <= N) {
		cout << "Yes" << endl;
		return 0;
	}

	if (abs(A - B) <= N&&abs(C - B) <= N) {
		cout << "Yes" << endl;
		return 0;
	}


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




Measured memory_bytes: 256
n,m = map(int, input().split())
l = dict()
for i in range(1,m+1):
  l[i] = 0

for i in range(n):
  x = list(map(int, input().split()))
  k = x[0]
  for j in x[1:]:
    l[j] += 1

cnt = 0
for k,v in l.items():
  if v==n:
    cnt += 1
print(cnt)

Measured memory_bytes: 9136
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using P = pair<ll, bool>;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int w, h;
  cin >> w >> h;
  vector<ll> p(w), q(h);
  rep(i, w) cin >> p[i];
  rep(i, h) cin >> q[i];
  int xnum = 0, ynum = 0;
  priority_queue<P, vector<P>, greater<P>> pq;
  rep(i, w) pq.push({p[i], 1});
  rep(i, h) pq.push({q[i], 0});
  ll ans = 0;
  while (!pq.empty()) {
    ll v;
    bool f;
    tie(v, f) = pq.top();
    pq.pop();
    if (f) {
      ans += v*max(h+1-ynum, 0);
      xnum++;
    } else {
      ans += v*max(w+1-xnum, 0);
      ynum++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7920
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N, P;
	string S;
	vector<pair<pair<string, int>, int> > PP;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> S >> P;
		PP.push_back({ { S, 1000 - P }, i + 1 });
	}
	sort(PP.begin(), PP.end());
	for (int i = 0; i < N; i++) {
		cout << PP[i].second << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long K, A, B;
  cin >> K >> A >> B;
  if (B <= A + 1){
    cout << K + 1 << endl;
  } else if (K <= A){
    cout << K + 1 << endl;
  } else {
    cout << A + (K - A + 1) / 2 * (B - A) + (K - A + 1) % 2 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int count[26] = {};
    int offset = 97;

    // 入力をカウント
    for(int i = 0; i < S.size(); i++){
        count[(int)S[i] - offset] += 1;
    }

    // 最初に0のアルファベットを出力
    int found = 0;
    for(int i = 0; i < 26; i++){
        if(count[i] == 0){
            found = i + offset;
            break;
        }
    }
    if(found == 0){
        cout << "None" << endl;
    }
    else{
        cout << (char)found << endl;
    }
}

Measured memory_bytes: 512
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int M = Integer.parseInt(sc.next());
    
    PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
    for(int i = 0; i < N; i++){
      int A = Integer.parseInt(sc.next());
      pq.offer(A);
    }
    
    for(int i = 0; i < M; i++){
      int B = pq.poll();
      pq.offer(B/2);
    }
    
    long ans = 0;
    for(int i = 0; i < N; i++){
      ans += pq.poll();
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 50232
#include<stdio.h>
#include<string.h>
int main(){
  int sum,i;
  char x[1000];
 
  while(1){
    scanf("%s",x);
    if(strlen(x)==1&&x[0]=='0') break;
 
    sum=0;
    for(i=0;i<strlen(x);i++){
      sum+=x[i]-'0';
    }
  printf("%d\n", sum);
  }
 
  return 0;
}


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

/* Defines begin */
#define fastio ios_base::sync_with_stdio(false), cin.tie(NULL) , cout.tie(NULL);
#define w1 solve();
#define pb push_back
#define mp make_pair
#define double long double
#define fi first 
#define se second
#define all(a) (a).begin(),(a).end()
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define FOR2(I,A,B) for(ll I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define random (rand()<<16|rand())
#define sqr(x) (x)*(x)
#define base complex<double>
#define LOCAL
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
/* Defines end */

/* Constants begin */
const long long int inf = 2e18 + 7;
const long long int mod = 1e9 + 7;
const double eps = 1e-7;
const double PI = 2*acos(0.0);
const double E = 2.71828;
/* Constants end */

/* Typedef begin */
typedef long long int ll;
typedef pair<ll,ll> pi;
typedef vector<ll> vi;
/* Typedef end */

template <typename Arg1>
void __f(const char* name, Arg1&& arg1)
{
	cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << ": " << arg1 << " |";
	__f(comma + 1, args...);
}



void solve()
{
//    ll t;
//    cin >> t;
//    ll a, b;
//    bool flag = false;
//    bool flag2 = false;
//    bool flag3 = false;
//    cin >> a >> b;
//    ll cnt = 0;
//    ll temp ;
//    vector<pair<ll, ll>> arr(t);
//    FOR(i,1,t)
//    {
//        arr[i - 1].first = a;
//        arr[i - 1].second = b;
//    	cin >> a >> b;
//        if(arr[i - 1].first == arr[i - 1].second)
//            flag = true;
//        else
//            flag = false;
//        arr[i].first = a;
//        arr[i].second = b;
//        if(arr[i].first == arr[i].second)
//            flag2 = true;
//        else
//            flag2 = false;
//        if(flag == flag2)
//        {
//            cnt++;
//
//            if(cnt <= 3)
//            {
//                temp = cnt;
//                flag3 = true;
//            }
//        }
//        else
//        {
//            cnt = 0;
//
//        }
//            
//	}
//    //cout << cnt << "\n";
//    if(flag3 == true && temp >= 3)
//        cout << "Yes\n";
//    else
//        cout << "No\n";


    ll n;
    cin >> n;
    ll a, b;
    ll cnt = 0;
    FOR(i,0,n)
    {
    	cin >> a >> b;
        if(a == b)
            cnt++;
        else
            cnt = 0;
        if( cnt == 3)
        {
            cout << "Yes\n";
            return ;
        }
    }

    cout << "No\n";
	
}



 
 
auto main() -> int
{
	fastio
	w1
	return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>

int nextInt();
int min(int a, int b){return a>b?b:a;}
int max(int a, int b){return a<b?b:a;}

int N, A, B;

int main(){
	N=nextInt();
	A=nextInt();
	B=nextInt();
	printf("%d %d\n", min(A, B), max(0, A+B-N));
	return 0;
}

int nextInt(){
	int f=0; char c=getchar();
	while((c<'0')||('9'<c)){c=getchar();}
	while((c>='0')&&(c<='9')){f=f*10+(c-'0'); c=getchar();}
	return f;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;

  int C[VMAX+1];
  int n, i, j;
  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for (i=0;i<=VMAX;i++) C[i] = 0;

  for (i=0;i<n;i++){
    scanf("%hu", &A[i + 1]);
    C[A[i + 1]]++;
  }

  for (i =1;i<=VMAX;i++) C[i] = C[i] + C[i - 1];

  for (j=1;j<=n;j++){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for (i=1;i<=n;i++){
    if (i>1) printf(" ");
    printf("%d", B[i]);
  }

  printf("\n");

  return 0;
}

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

#define pb push_back
#define mk make_pair
#define lob lower_bound
#define upb upper_bound
#define fst first
#define scd second

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;

/*  ------  by:duyi  ------  */ // myt天下第一
int n,K,dp[21][1<<21];
char s[(1<<20)+5];
int main() {
	scanf("%d%d",&n,&K);
	for(int i=0;i<=n;++i){
		scanf("%s",s);
		for(int j=0;j<(1<<i);++j)if(s[j]=='1'){
			dp[i][j|(1<<i)]=1;
		}
	}
	for(int i=n;i>=1;--i){//未确定部分的长度
		for(int j=i;j<=n;++j){//整个串的长度
			int b=(1<<j);
			for(int k=0;k<b;++k){
				int tmp=dp[i][k|b],p=-1,q=-1;if(!tmp)continue;
				for(int t=i-1;t>=0;--t)if(((k>>t)&1)==1){p=t;break;}
				for(int t=i-1;t>=0;--t)if(((k>>t)&1)==0){q=t;break;}
				dp[0][(k+b)>>i]+=tmp;
				if(p!=-1)dp[p][((((k>>i)<<1)|1)<<p)|(((1<<p)-1)&k)|(1<<(j-(i-p)+1))]+=tmp;
				if(q!=-1)dp[q][(((k>>i)<<1)<<q)|(((1<<q)-1)&k)|(1<<(j-(i-q)+1))]+=tmp;
			}
		}
	}
	for(int i=n;i>=0;--i){
		for(int j=0;j<(1<<i);++j){
			if(dp[0][j|(1<<i)]>=K){
				for(int k=i-1;k>=0;--k)if((j>>k)&1)putchar('1');else putchar('0');
				puts("");
				return 0;
			}
		}
	}
	assert(0);
}

Measured memory_bytes: 171264
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        int sum = 0;
        List<String> list = new ArrayList<>();
        for (int i = 1; sum < n; i++) {
            sum += i;
            list.add(Integer.toString(i));
        }
        int diff = sum - n;
        if (0 < diff) {
            list.remove(list.indexOf(Integer.toString(diff)));
        }

        String result = String.join("\r\n", list);

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 23764
N,M,R = map(int,input().split())
R = list(map(int,input().split()))
dp = [[float("INF")]*(N+1) for _ in range(N+1)]
for i in range(N+1):
    dp[i][i] = 0

for _ in range(M):
    a,b,c = map(int,input().split())
    dp[a][b] = min(dp[a][b],c)
    dp[b][a] = min(dp[b][a],c)

for i in range(1,N+1):
    for j in range(1,N+1):
        for k in range(1,N+1):
            dp[j][k] = min(dp[j][k],dp[j][i]+dp[i][k])

def dfs(p,n,path,cost):
    path.add(n)
    cost += dp[p][n]
    
    if len(path) == len(R):
        return cost
    else:
        res = float("INF")
        for r in R:
            if r not in path:
                res = min(res,dfs(n,r,path,cost))
                path.remove(r)
        return res
ans = float("INF")
for r in R:
    ans = min(ans,dfs(r,r,set(),0))
print(ans)

Measured memory_bytes: 76940
#include <map>
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;

int road[2 * 100000 + 1];
int rail[2 * 100000 + 1];

int root1 (int i) {
  if (i == road[i]) {
    return i;  
  }  
  int sub = root1(road[i]);
  road[i] = sub;
  return sub;
}

int root2 (int i) {
  if (i == rail[i]) {
    return i;  
  }  
  int sub = root2(rail[i]);
  rail[i] = sub;
  return sub;
}

void unite1 (int i, int j) {
  int sub = root1(i);
  int sub1= root1(j);
  road[sub1] = sub;  
}

void unite2 (int i, int j) {
  int sub = root2(i); 
  int sub1= root2(j);
  rail[sub1] = sub; 
}

int main () {
  int n, k, l;
  cin >> n >> k >> l;
  for (int i = 0; i <= n; i++) {
    road[i] = i;
    rail[i] = i;  
  }  
  pair<int, int> pq[k];
  map<pair<int, int>, int> sum;
  for (int i = 0; i < k; i++) {
    int sub, sub1;
    cin >> sub >> sub1;
    if (sub > sub1) {
      swap(sub, sub1);  
    }
    pq[i] = make_pair(sub, sub1);  
  }
  pair<int, int> rs[l];
  for (int i = 0; i < l; i++) {
    int sub, sub1;
    cin >> sub >> sub1;
    if (sub > sub1) {
      swap(sub, sub1);  
    }
    rs[i] = make_pair(sub, sub1); 
  }
  sort(pq, pq + k);
  sort(rs, rs + l);
  for (int i = 0; i < k; i++) {
    unite1(pq[i].first, pq[i].second);  
  }
  for (int i = 0; i < l; i++) {
    unite2(rs[i].first, rs[i].second);  
  }
  for (int i = 1; i <= n; i++) {
    sum[make_pair(root1(i), root2(i))]++;
  }
  for (int i = 1; i <= n; i++) {
    if (i == n) {
      cout << sum[make_pair(root1(i), root2(i))] << endl;    
    }
    else {
      cout << sum[make_pair(root1(i), root2(i))] << " ";  
    }
  }
}

Measured memory_bytes: 15104