akhauriyash/Code-Regression huggingface dataset:
n = int(input())
g = [list(map(int, input().split())) for _ in range(n - 1)]

g_list = [[] for _ in range(n)]
for gi in g:
    g_list[gi[0] - 1].append([gi[1] - 1, gi[2] % 2])
    g_list[gi[1] - 1].append([gi[0] - 1, gi[2] % 2])


color = [-1] * n

from collections import deque

q = deque()

color[0] = 0
q.append(0)
while q:
    v = q.popleft()
    for i, j in g_list[v]:
        if color[i] == -1:
            color[i] = (color[v] + j) % 2
            q.append(i)

[print(c) for c in color]


Measured memory_bytes: 66852
#include<stdio.h>

int main(){
    int i,n,j,k;
    int b,f,r,v;
    int p[4][3][10]={0};

    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d %d %d",&b,&f,&r,&v);
        p[b-1][f-1][r-1]+=v;
    }
    for(k=0;k<4;k++){
        for(j=0;j<3;j++){
            for(i=0;i<10;i++){
                printf(" %d",p[k][j][i]);
            }
            printf("\n");
        }
        if(k==3){
            break;
        }
        printf("####################\n");
    }
    return 0;
}


Measured memory_bytes: 2056
#include <iostream>  // cin,cout
#include <stdio.h>   // printf,scanf (standard input/output)
#include <cmath>     // abs(x),pow(x,2)
#include <string>
#include <string.h>  // strlen, strcmp
#include <algorithm> // min,max, sort(v.begin(),v.end())
#include <vector>
#include <time.h>
using namespace std;


int main(){
    int N;
    long long A[100010];
    
    // 入力
    cin >> N;
    for (int i=0;i<N;i++) cin >> A[i];
    
    for (int i=0;i<N;i++) {
        if (A[i]==0) {
            cout << "0" << endl;
            return 0;
        }
    }
    
    long long temp = 1e18;
    
    
    long long result = 1;
    for (int i=0;i<N;i++) {
        
        double aa = temp/result;
        double flag = A[i]/aa;
        //cout << flag << endl;
        
        if (flag > 1.0) {
            cout << "-1" << endl;
            return 0;
        }
        else {
            result *= A[i];
        }
    }
    
    cout << result << endl;
    
    return 0;
}


Measured memory_bytes: 3972
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>

#define REP(i, n) for (int i = 0; i < n; i++)
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9

using namespace std;
typedef long long ll;

int main() {
	while (1) {
		int x, y, s;
		int ans=-1;
		cin >> x >> y >> s;
		if (x == 0 && y == 0 && s == 0) break;
		for (int a=1; a<1000; a++){
			for (int b=1; b<1000; b++){
				if (a*(100+x)/100 + b*(100+x)/100 == s){
					ans = max(ans, a*(100+y)/100 + b*(100+y)/100);
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}



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




int main(){
    string s,t;cin>>s>>t;
    vector<ll> a[26];
    unordered_map<char,ll> mp;
    rep(i,0,25)mp[alp[i]]=i;
    rep(i,0,s.size()-1){
        a[mp[s[i]]].pb(i);
    }
    ll num=0;
    ll now=0;
    rep(i,0,t.size()-1){
        if(a[mp[t[i]]].size()==0){
            cout<<-1<<endl;
            return 0;
        }
        ll l=lower_bound(a[mp[t[i]]].begin(),a[mp[t[i]]].end(),now)-a[mp[t[i]]].begin();
        if(l==a[mp[t[i]]].size()){
            num++;
            now=a[mp[t[i]]][0]+1;
        }else{
            now=a[mp[t[i]]][l]+1;
        }
        //cout<<num<<' '<<now<<endl;
        
    }
    cout<<num*s.size()+now<<endl;
    
    
    
    
    return 0;
}



Measured memory_bytes: 1724
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pf(n) printf("%d\n",n)
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1001001001;
const double PI = acos(-1);

int main() {
	int n;
	cin >> n;
	vector<int> w(n);
	rep(i, n) cin >> w[i];

	int sum = 0;
	rep(i, n) sum += w[i];

	int sub = 0;
	int ans = 10010001;
	rep(i, n) {
		sub += w[i];
		ans = min(abs(2 * sub - sum), ans);
		//pf(abs(2 * sub - sum));
	}
	pf(ans);

	return 0;
}

Measured memory_bytes: 3728
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
struct edge {int to,cap,rev,id;};
const int MAX_V=400,inf=1000;
vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];
void add_edge(int from, int to, int cap, int id){
	edge e1={to,cap,G[to].size(),id},e2={from,0,G[from].size(),-1};
	G[from].push_back(e1);
	G[to].push_back(e2);
}
void bfs(int s){
	memset(level,-1,sizeof(level));
	queue<int> que;
	level[s]=0;
	que.push(s);
	while(!que.empty()){
		int v=que.front();
		que.pop();
		for(int i=0;i<G[v].size();i++){
			edge &e=G[v][i];
			if(e.cap>0 && level[e.to]<0){
				level[e.to]=level[v]+1;
				que.push(e.to);
			}
		}
	}
}
int dfs(int v,int t,int f){
	if(v==t) return f;
	for(int &i=iter[v];i<G[v].size();i++){
		edge &e=G[v][i];
		if(e.cap>0 && level[v]<level[e.to]){
			int d=dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap-=d;
				G[e.to][e.rev].cap+=d;
				return d;
			}
		}
	}
	return 0;
}
int max_flow(int s,int t){
	int flow=0;
	while(true){
		bfs(s);
		if(level[t]<0) return flow;
		memset(iter,0,sizeof(iter));
		int f;
		while( (f=dfs(s,t,inf))>0 ) flow+=f;
	}
}
int main(){
	int n,m,x[1000],y[1000];
	cin >> n >> m;
	int s=0,t=n+1;
	rep(i,m){
		cin >> x[i] >> y[i];
		add_edge(x[i],y[i],1,-1);
		add_edge(y[i],x[i],1,i);
	}
	int ss,tt;
	cin >> ss >> tt;
	add_edge(s,ss,inf,-1);
	add_edge(tt,t,inf,-1);
	cout << max_flow(s,t) << endl;
	bool ans[1000]={};
	rep1(i,n){
		rep(j,G[i].size()){
			edge e=G[i][j];
			if(e.id<0) continue;
			if(e.cap==0) ans[e.id]=true;
		}
	}
	int cnt=0;
	rep(i,m) if(ans[i]) cnt++;
	cout << cnt << endl;
	rep(i,m) if(ans[i]) cout << i+1 << endl;
}

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

struct Card {
  char suit, value;
};

void BubbleSort(struct Card C[], int N) {
  for(int i = 0; i < N-1; i++) {
    for (int j = N-1; j > i; j --) {
      if (C[j-1].value > C[j].value) swap(C[j-1], C[j]);
    }
  }
}

void SelectionSort(struct Card C[], int N) {
  for(int i = 0; i < N-1; i ++) {
    int minj = i;
    for(int j = i+1; j < N; j++) {
      if (C[minj].value > C[j].value) minj = j;
    }
    if (C[minj].value != C[i].value) swap(C[minj], C [i]);
  }
}

int main()
{
  Card C1[100], C2[100];
  int N;cin>>N;
  char ch;
  rep(i, N) cin >> C1[i].suit >> C1[i].value;
  rep(i, N) C2[i] = C1[i];

  BubbleSort(C1, N);
  rep(i, N) {
    if (i != N-1) cout << C1[i].suit << C1[i].value << " ";
    else cout << C1[i].suit << C1[i].value;
  }
  cout << endl;
  cout << "Stable" << endl;

  SelectionSort(C2, N);
  rep(i, N) {
    if (i != N-1) cout << C2[i].suit << C2[i].value << " ";
    else cout << C2[i].suit << C2[i].value;
  }
  cout << endl;

  bool flg = true;
  rep(i, N) {
    if (C1[i].suit != C2[i].suit || C1[i].value != C2[i].value) {
      flg = false;
    }
  }

  if (flg) cout << "Stable" << endl;
  else cout << "Not stable" << endl;

  return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define MOD 1000000007

int main(void){
    ll n;
    bool f = false;
    while(1){
        cin >> n;
        if(!n) break;
        n /= 10;
        int c1,c5,c10,c50;
        cin >> c1 >> c5 >> c10 >> c50;
        int b1,b5,b10,b50;
        ll c = c1 + c5*5 + c10*10 + c50*50 - n;
        b50 = max(0LL,c50-c/50);
        c%=50;
        b10 = max(0LL,c10-c/10);
        c%=10;
        b5 = max(0LL,c5-c/5);
        c%=5;
        b1 = max(0LL,c1-c);
        if(f) cout << endl;
        if(b1) cout << "10 " << b1 << endl;
        if(b5) cout << "50 " << b5 << endl; 
        if(b10) cout << "100 " << b10 << endl; 
        if(b50) cout << "500 " << b50 << endl; 
        f = true;
    }
}


Measured memory_bytes: 3092
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  long long n,a,b,c,e,d,m;
  cin>>n>>a>>b>>c>>d>>e;
  m=min({a,b,c,d,e});
  if(n%m)cout<<5+n/m<<endl;
  else cout<<5+n/m-1<<endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int c = sc.nextInt();
		
		while(h != 0 || w != 0 || c != 0){
			int[][] p = new int[h + 2][w + 2];
			for(int i = 1; i <= h; i++){
				for(int j = 1; j <= w; j++){
					p[i][j] = sc.nextInt();
				}
			}
			int size = 0;
			for(int i = 1; i < p[1][1]; i++){
				size = Math.max(size, func(p, c, 1, i));
			}
			for(int i = p[1][1] + 1; i <= 6; i++){
				size = Math.max(size, func(p, c, 1, i));
			}
			System.out.println(size);
			
			h = sc.nextInt();
			w = sc.nextInt();
			c = sc.nextInt();
		}
		
		
		sc.close();
	}
	static int func(int[][] p, int c, int cnt, int drw){
		int size = 0;
		int oc = p[1][1];
		
		boolean[][] chk = new boolean[p.length][p[0].length];
		for(int i = 0; i < p.length; i++){
			Arrays.fill(chk[i], false);
		}
		int[][] cp = new int[p.length][p[0].length];
		for(int i = 0; i < p.length; i++){
			for(int j = 0; j < p[0].length; j++){
				cp[i][j] = p[i][j];
			}
		}
		
		LinkedList<A> list = new LinkedList<A>();
		
		list.push(new A(1, 1));
		while(!list.isEmpty()){
			A a = list.poll();
			if(!chk[a.h][a.w]){
				cp[a.h][a.w] = drw;
				chk[a.h][a.w] = true;
				
				if(!chk[a.h - 1][a.w] && p[a.h - 1][a.w] == oc){
					list.add(new A(a.h - 1, a.w));
				}
				if(!chk[a.h + 1][a.w] && p[a.h + 1][a.w] == oc){
					list.add(new A(a.h + 1, a.w));
				}
				if(!chk[a.h][a.w - 1] && p[a.h][a.w - 1] == oc){
					list.add(new A(a.h, a.w - 1));
				}
				if(!chk[a.h][a.w + 1] && p[a.h][a.w + 1] == oc){
					list.add(new A(a.h, a.w + 1));
				}
			}
		}

		if(cnt == 5){
			for(int i = 0; i < p.length; i++){
				Arrays.fill(chk[i], false);
			}
			list.push(new A(1, 1));
			while(!list.isEmpty()){
				A a = list.poll();
				if(!chk[a.h][a.w]){
					size++;
					chk[a.h][a.w] = true;
					if(!chk[a.h - 1][a.w] && cp[a.h - 1][a.w] == c){
						list.add(new A(a.h - 1, a.w));
					}
					if(!chk[a.h + 1][a.w] && cp[a.h + 1][a.w] == c){
						list.add(new A(a.h + 1, a.w));
					}
					if(!chk[a.h][a.w - 1] && cp[a.h][a.w - 1] == c){
						list.add(new A(a.h, a.w - 1));
					}
					if(!chk[a.h][a.w + 1] && cp[a.h][a.w + 1] == c){
						list.add(new A(a.h, a.w + 1));
					}
				}
			}
		}else if(cnt == 4){
			size = Math.max(size, func(cp, c, cnt + 1, c));
		}else{
			for(int i = 1; i < cp[1][1]; i++){
				size = Math.max(size, func(cp, c, cnt + 1, i));
			}
			for(int i = cp[1][1] + 1; i <= 6; i++){
				size = Math.max(size, func(cp, c, cnt + 1, i));
			}
		}
		return size;
	}
}
class A{
	int h;
	int w;
	A(int h, int w){
		this.h = h;
		this.w = w;
	}
}

Measured memory_bytes: 163832
#include <bits/stdc++.h>
#include<limits.h>
#include<stdio.h>
#include<cstring>
#include<string>
using namespace  std;
typedef long long ll;
typedef long double ld;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define fi first
#define se second
#define rsz(a,n) a.resize(n)
#define test(t) ll t;cin>>t;while(t--)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define fillv(a,k) memset(a,k,sizeof(a))
#define leadzero(a) __builtin_clz(a) //count leading zeros
#define trailzero(a) __builtin_ctz(a) //count trailing zeros
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln cout<<endl
#define sp cout<<" "
#define spaceprint(a,i,s,n) {forsn(i,s,n) { cout<<a[i]; sp;}}
#define lineprint(a,i,s,n) {forsn(i,s,n) {cout<<a[i]; ln;}}
#define maxe(a) *max_element(a.begin(),a.end())
#define maxi(a) max_element(a.begin(),a.end())-a.begin()
#define mine(a) *min_element(a.begin(),a.end())
#define mini(a) min_element(a.begin(),a.end())-a.begin()
#define all(c) c.begin(),c.end()
#define trav(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element)  (find(all(container),element) != container.end())// check the presence of element
//copy(from_begin, from_end, to_begin); copy function
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<string> vs;
typedef vector<int> v32;
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
typedef map<ll,ll> m64;
const int LIM = 1e5+5, MOD =  1e9+7;
#define sumv(v) accumulate(all(v),ll(0))
#define productv(v) accumulate(all(v), ll(1), multiplies< ll >())
ll gcd(ll a, ll b) { if(b == 0) return a; return gcd(b, a % b); }
ll fastpowMOD(ll a, ll p,ll MOD){ if(p==0) return 1; ll z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }
bool seive[100005];
ll dp[10005][105];
void SieveOfEratosthenes(ll n)
{ memset(seive, true, sizeof(seive)); for (ll p=2; p*p<=n; p++) if (seive[p] == true) for (ll i=p*p; i<=n; i += p) seive[i] = false; }
int main()
{
    fast;
    ll n,k,i;
    ll s;
    cin>>n>>k>>s;
    for(i=0;i<k;i++)
    {
        cout<<s<<" ";
    }
    ll t;
    if(s==1e9)
    {
        t=s-1;
    }
    else
        t=s+1;
    for(;i<n;i++)
        cout<<t<<" ";

}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
  ll a,v,b,w,t;
  cin >> a >> v >> b >> w >> t;
  ll c = a;
  ll d = b;
  for (int i = 1; i <= t; i++) {
    if (a > b) {
      c -= v;
      d -= w;
      if (c <= d){ 
        cout << "YES\n";
        return 0;
      }
    }else if (a < b) {
      c += v;
      d += w;
      if (c >= d){ 
        cout << "YES\n";
        return 0;
      }
    }
    if (c == d){ 
        cout << "YES\n";
      return 0;
    }
  }
  cout << "NO\n";

  return 0;
}


Measured memory_bytes: 3620
object Main extends App {
  val scanner = new java.util.Scanner(System.in)

  val inputs = Iterator.continually {
    val n = scanner.nextInt()
    val x = scanner.nextInt()

    (n, x)
  }

  val outputs = inputs.takeWhile(_ != (0, 0)).map {
    case (n, x) =>
      val comb = for {
        a <- 1 to n
        b <- (a+1) to n
        c <- (b+1) to n
        if a + b + c == x
      } yield (a, b, c)

      comb.size
  }

  outputs.foreach(println)
}

Measured memory_bytes: 94488
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll N, K;
    ll x[MAX_N];
    ll m[MAX_N], p[MAX_N];
    ll l = 0;
    ll r = 0;
    ll answer = INF;

    cin >> N >> K;
    rep(i, N) cin >> x[i];
    
    rep(i, N){
        if (x[i] < 0){m[l] = - x[i]; l ++;}
        else {p[r] = x[i]; r ++;}
    }

    sort(m, m + l);
    
    if (l < K && r >= K) answer = p[K - 1];
    else if (r < K && l >= K) answer = m[K - 1];
    else if (l >= K && r >= K) answer = min(m[K - 1], p[K - 1]);
    
    rep(i, min(l, r)){
        if (l <= r && r > K - 2 - i && K - 2 - i >= 0) answer = min({answer, 2 * m[i] + p[K - 2 - i], m[i] + 2 * p[K - 2 - i]});
        else if (r <= l && l > K - 2 - i && K - 2 - i >= 0) answer = min({answer, 2 * p[i] + m[K - 2 - i], p[i] + 2 * m[K - 2 - i]});
    }

    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;


    void solve()
    {
        var S = cin.next;
        if (S == "zyxwvutsrqponmlkjihgfedcba")
        {
            WriteLine(-1);
        }
        var A = new bool[26];
        foreach (var item in S)
        {
            A[item - 'a'] = true;
        }
        for (int i = 0; i < 26; i++)
        {
            if (!A[i])
            {
                WriteLine(S + (char)(i + 'a'));
                return;
            }
        }

        for (int i = 0; i < S.Length; i++)
        {
            int u = S.Length - i - 1;
            for (int j = S[u] - 'a' + 1; j < 26; j++)
            {
                if (!A[j])
                {
                    WriteLine(S.Substring(0, S.Length - i - 1) + (char)(j + 'a'));
                    return;
                }
            }
            A[S[u] - 'a'] = false;
        }

    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1061109567
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s,"r",stdin);
#define out(s) freopen(s,"w",stdout);
#define fi first
#define se second
#define bw(i,r,l) for (int i=r-1;i>=l;i--)
#define fw(i,l,r) for (int i=l;i<r;i++)
#define fa(i,x) for (auto i:x)
using namespace std;
typedef pair<int, int> edge;
string s;
int cur = 0;
vector<edge> e;
void bad() {
	cout << "-1";
	exit(0);
}
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> s;
	int n = s.length();
	s = " " + s;
	fw (i, 1, n) if (s[i] != s[n - i]) bad();
	if (s[1] == '0') bad();
	if (s[n] == '1') bad();
	int lstsz = 1;
	cur = 1;
	fw (i, 2, n + 1) if (s[i] == '1') {
		//Last root was cur. For the k - 1 more nodes give them indices cur + 1, ..., cur + k - 1.
		//The new root is cur + k
		int k = i - lstsz;
		e.pb({cur + k, cur});
		fw (j, cur + 1, cur + k) e.pb({cur + k, j});
		cur = cur + k;
		lstsz = i;
	}
	//Finally, connect an edge between n and cur
	e.pb({n, cur});
	fa (i, e) cout << i.fi << " " << i.se << "\n";
	return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

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

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

    priority_queue<ll> q;

    for (int i = 0; i < N; ++i) {
        int Ai;
        cin >> Ai;

        q.push(Ai);
    }

    for (int i = 0; i < M; ++i) {
        int t = q.top();
        q.pop();

        t = t / 2;

        q.push(t);
    }

    ll ans = 0;
    while (!q.empty()) {
        ans += q.top();
        q.pop();
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1400
A = int(input())
B = int(input())
C = int(input())
X = int(input())
ans = 0
for a in range(A+1):
  for b in range(B+1):
    y = 500*a + 100*b
    c = (X - y)//50
    if 0 <= c <= C:
      ans += 1

print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int ans = Math.max(a + b, Math.max(2*a-1, 2*b-1) ); 

        System.out.println(ans);
    }
}

Measured memory_bytes: 22740
// #pragma GCC optimize("O3")
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

template <class T1, class T2>
ostream& operator << (ostream& out, pair <T1, T2> p)
{
	out << '(' << p.first << ',' << p.second << ')';
	return out;
}

template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
	in >> p.first >> p.second;
	return in;
}

template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
	for (T &x : v)
		in >> x;
	return in;
}

template <class T>
ostream& operator << (ostream& out, vector<vector<T>> &v)
{
	for (vector<T> &x : v)
		out << x << '\n';
	return out;
}

template <class T>
ostream& operator << (ostream& out, vector<T> &v)
{
	for (T &x : v)
		out << x << ' ';
	return out;
}

long long gcd (long long a, long long b)
{
	if (b > a)
		swap(a, b);
	return (b ? gcd(b, a % b) : a);
}

using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define F          first
#define S          second
#define First      first.first
#define Second     first.second
#define Third      second
#define mp         make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
#define per(i,b,a) for (int i = b; i > a; i--)
#define all(x)     x.begin(), x.end()
#define ret(x)     return cout << x, 0;
#define throwex    throw runtime_error ("Found the error.");

const int h = 1000000007;

signed main()
{
	ios::sync_with_stdio(false);
	#ifdef ONLINE_JUDGE
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.setstate(ios::failbit);
	#endif

	ll h,w;
	cin >> h >> w;
	if(h == 1 or w == 1)
		ret(1);
	ll ans = 0;
	
	cout << (2*(h/2) * 2*(w/2)) / 2 + (h & 1 ? (w+1)/2 : 0)+ (w & 1 ? (h+1)/2 : 0) + ((w & 1) and (h&1) ? -1 : 0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  string s;
  cin >> s;
  int n=s.size();
  int m=n/2;
  int cnt=0;
  rep(i,n)if(s[i]=='p')cnt++;
  cout << m-cnt << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    UnionFind uf(n);
    vector<ll> a(m), b(m), ans(m);
    REP(i,m){
        cin >> a[i] >> b[i];
        --a[i], --b[i];
    }
    ans[m-1] = n * (n - 1) / 2;
    for(int i=m-1;i>0;i--){
        ans[i-1] = ans[i];
        if(!uf.issame(a[i], b[i])){
            ans[i-1] -= (ll)uf.size(a[i]) * uf.size(b[i]);
            uf.unite(a[i], b[i]);
        }
    }
    REP(i,m) cout << ans[i] << endl;
}

Measured memory_bytes: 4096
#include<stdio.h>
int main(){
int a,b,i,j,k,l,x,y,z;
scanf("%d%d",&a,&b);
char c[100][100];
printf("100"" ""100\n");
for(i=0;i<50;i++){for(j=0;j<100;j++){c[i][j]='.';}}
for(i=50;i<100;i++){for(j=0;j<100;j++){c[i][j]='#';}}
j=0;k=0;
for(i=1;i<b;i++){
c[k][j]='#';
if(j!=98){j+=2;}else{k+=2;j=0;}
}
j=0;k=99;
for(i=1;i<a;i++){
c[k][j]='.';
if(j!=98){j+=2;}else{k-=2;j=0;}}
for(i=0;i<100;i++){
for(j=0;j<99;j++){
printf("%c",c[i][j]);}
printf("%c\n",c[i][99]);
}
return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
    
int main() {
    string s;
    cin >> s;
    int index = 0;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'B') {
            if (index > 0) {
                index--;
            }
        } else {
            s[index++] = s[i];
        }
    }
    for (int i = 0; i < index; i++) {
        cout << s[i];
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,k; cin >> n >> k;
	ll ans=0;
	vector<ll> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	sort(a.begin(),a.end());
	for(int i=0;i<n-k;i++){
		ans+=a[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <bitset>
#include <algorithm>
#define int long long
using namespace std;
#define mod 1000000007
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
bool vis[30000005], vis1[3000005];
vector<int> vec[3000005];
// v1, vec1[3000005];
//int child[2000005];
//int divi[2000005];

// int dis[100005] = {0};
// int h[100005];
// int p[100005];
// int dp[100005][100];
// bool f = 0;
// int bad[100005], good[100005];
// int p5[100005];
int final_sum[200005], max_sum[10005];
//int level[200005];
//int time1 = 0;
void dfs(int node)
{
    vis[node] = 1;
    //level[node] = time1;
    //time1++;
    for (int i = 0; i < vec[node].size(); i++)
    {
        if (!vis[vec[node][i]])
        {
            //  if (bit[vec[node][i]]            {

            dfs(vec[node][i]);
            final_sum[node] += final_sum[vec[node][i]];
        }
    } //  if ()
      //   if (b == 0)
      //  count1[b][node] += count1[b][vec[node][i]];
      //}
      // time1--;
}

int32_t main()
{
    string str;
    cin >> str;
    int sum = 0;
    for (int i = 0; i < str.length(); i++)
    {
        sum += (str[i] - '0');
    }
    if (sum % 9)
    {
        cout << "No"
             << "\n";
    }
    else
    {
        cout << "Yes"
             << "\n";
    }

    return 0;
}

Measured memory_bytes: 74072
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 200000000000000
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

//////////////

#define S second
#define F first
#define int long long  

/////////////


signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int n1=b/c-(a-1)/c;
	int n2=b/d-(a-1)/d;
	int e=(c*d)/__gcd(c,d);
	int n3=b/e-(a-1)/e;
	cout<<b-a+1-(n1+n2-n3);
}

Measured memory_bytes: 256
n,a,b = map(int, input().split())

if a>b:
    print(0)
    exit()
if n==1:
    if b-a>0:
        print(0)
    else:
        print(1)
    exit()
if n==2:
    print(1)
    exit()

res = (a+b*(n-1)) - (a*(n-1)+b) + 1
print(res)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    static Scanner in = new Scanner(System.in);

    static void run() {
        int n = in.nextInt(), m = in.nextInt();
        Map<Integer, List<Integer>> g = new HashMap<>();
        for (int i=0;i<m;i++) {
            int u = in.nextInt() - 1, v = in.nextInt() - 1;
            g.computeIfAbsent(u, k -> new ArrayList<>()).add(v);
            g.computeIfAbsent(v, k -> new ArrayList<>()).add(u);
        }
        int[] p = new int[n];
        Arrays.fill(p, -1);
        p[0] = 0;
        Queue<Integer> q = new ArrayDeque<>();
        q.add(0);
        while (!q.isEmpty()) {
            int curr = q.poll();
            if (!g.containsKey(curr)) continue;
            for (int nxt : g.get(curr)) {
                if (p[nxt] == -1) {
                    p[nxt] = curr;
                    q.add(nxt);
                }
            }
        }
        for (int i=0;i<n;i++) {
            if (p[i] == -1) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
        for (int i=1;i<n;i++) System.out.println(p[i] + 1);
    }

    public static void main(String[] args) {
        run();
    }
}


Measured memory_bytes: 83868
#include<stdio.h>
#include<algorithm>
#include<map>
using namespace std;
int row[41000];
int col[41000];
map<pair<int,int>,int> m;
char str[10];
int dir;
int n;
pair<int,int> conv(int a,int b){
	int ret1=0;
	int ret2=0;
	switch(dir&3){
		case 0:
			ret1=a;
			ret2=b;
			break;
		case 1:
			ret1=b;
			ret2=n-a+1;
			break;
		case 2:
			ret1=n-a+1;
			ret2=n-b+1;
			break;
		case 3:
			ret1=n-b+1;
			ret2=a;
			break;
	}
	if(dir&4)swap(ret1,ret2);
	return make_pair(row[ret1],col[ret2]);
}
int main(){
	int a,b,c,d,e,f,g;
	int q;
	scanf("%d%d%d%d%d%d%d%d%d",&n,&q,&a,&b,&c,&d,&e,&f,&g);
	long long h=314159265;
	long long mod=1000000007;
	for(int i=1;i<=n;i++)row[i]=i;
	for(int i=1;i<=n;i++)col[i]=i;
	while(q--){
		scanf("%s",str);
		if(str[0]=='W'){
			int R,C,V;
			scanf("%d%d%d",&R,&C,&V);
			pair<int,int> at=conv(R,C);
			m[at]=V;
		}
		if(str[0]=='C'){
			int r1,c1,r2,c2;
			scanf("%d%d%d%d",&r1,&c1,&r2,&c2);
			pair<int,int> at1=conv(r1,c1);
			pair<int,int> at2=conv(r2,c2);
			if(m.count(at1))m[at2]=m[at1];
			else m[at2]=((long long)at1.first*a+(long long)at1.second*b)%c;
		}
		if(str[0]=='S'){
			int r1,r2;
			scanf("%d%d",&r1,&r2);
			if((dir/4+(str[1]=='R')+dir%4)&1){
				if((dir+1+dir/4*1+(str[1]!='R')*2)%4<2)swap(row[r1],row[r2]);
				else swap(row[n-r1+1],row[n-r2+1]);
			}else{
				if((dir+dir/4*3+(str[1]=='R')*2)%4<2)swap(col[r1],col[r2]);
				else swap(col[n-r1+1],col[n-r2+1]);
			}
		}
		if(str[0]=='R'){
			if(str[1]=='L'){
				dir=(dir&4)+((dir%4+1)&3);
			}
			if(str[1]=='R'){
				dir=(dir&4)+((dir%4+3)&3);
			}
			if(str[1]=='H'){
				dir=((dir&4)?0:4)+(dir%4)^1;
			}
			if(str[1]=='V'){
				dir=((dir&4)?0:4)+(dir%4)^3;
			}
		}
	}/*
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			pair<int,int> at=conv(i,j);
			int ans;
			if(m.count(at))ans=m[at];
			else ans=((long long)at.first*a+(long long)at.second*b)%c;
			printf("%d ",ans);
		}
		printf("\n");
	}*/
	for(int i=d;i<=e;i++){
		for(int j=f;j<=g;j++){
			pair<int,int> at=conv(i,j);
			if(m.count(at))h=(h*31+m[at])%mod;
			else h=(h*31+((long long)at.first*a+(long long)at.second*b)%c)%mod;
		}
	}
	printf("%lld\n",h);
}

Measured memory_bytes: 1968
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

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

			string s = Console.ReadLine();

			int c0 = 0, c1 = 0;
			for (int i = 0; i < s.Length; i++) {
				if (s[i] == '0') {
					c0++;
				} else {
					c1++;
				}
			}
			Console.WriteLine(Math.Min(c0, c1) * 2);

		}
	}
}

Measured memory_bytes: 11232
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <deque>
using namespace std;
typedef long long ll;
struct A {
	bool c[26];
};
A tree[2000001];
string a;
bool ans[26];
void init(int node, int x, int y) {
	if (x != y) {
		int mid = (x + y) / 2;
		init(node * 2, x, mid);
		init(node * 2 + 1, mid + 1, y);
		for (int i = 0; i <= 25; i++) {
			if (tree[node * 2].c[i] || tree[node * 2 + 1].c[i]) {
				tree[node].c[i] = true;
			}
		}
	}
	else {
		tree[node].c[(a[x] - 'a')] = true;
	}
}
void Update(int node, int x, int y, int i, char v) {
	if (x > i || y < i)return;
	if (x != y) {
		int mid = (x + y) / 2;
		Update(node * 2, x, mid, i, v);
		Update(node * 2 + 1, mid + 1, y, i, v);
		memset(tree[node].c, false, sizeof(tree[node].c));
		for (int i = 0; i <= 25; i++) {
			if (tree[node * 2].c[i] || tree[node * 2 + 1].c[i]) {
				tree[node].c[i] = true;
			}
		}
	}
	else {
		tree[node].c[(a[i] - 'a')] = false;
		tree[node].c[(v - 'a')] = true;
	}
}
void Quary(int node, int x, int y, int i, int j) {
	if (x > j || y < i)return;
	if (i <= x && y <= j) {
		for (int i = 0; i <= 25; i++) {
			if (tree[node].c[i])ans[i] = true;
		}
	}
	else {
		int mid = (x + y) / 2;
		Quary(node * 2, x, mid, i, j);
		Quary(node * 2 + 1, mid + 1, y, i, j);
	}
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);	
	int n; cin >> n >> a;
	int q; cin >> q;
	init(1, 0, a.size() - 1);
	while (q--) {
		int z; cin >> z; 
		if (z == 1) {
			int x; char y; cin >> x >> y;
			Update(1, 0, a.size() - 1, x - 1, y);
			a[x - 1] = y;
		}
		else {
			int x, y; cin >> x >> y;
			memset(ans, false, sizeof(ans));
			int cnt = 0;
			Quary(1, 0, a.size() - 1, x - 1, y - 1);
			for (int i = 0; i <= 25; i++) {
				if (ans[i])cnt += 1;
			}
			cout << cnt << '\n';
		}
	} 

}




Measured memory_bytes: 29596
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <ctype.h>
#include <algorithm>
#include <cmath>
#include <vector>

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define square(x) (x) * (x)

const int INF = 1e9;

using namespace std;

int main() {
    int h, w;
    ostringstream os;
    while(1){
        cin >> h >> w;
        if (h + w == 0)
            break;
        REP(i, h){
            REP(i, w) os << "#";
            os << endl;
        }
        os << endl;
    }
    cout << os.str();
    return 0;
}

Measured memory_bytes: 1324
import java.io.*;
import java.util.*;
import java.math.BigInteger;
public class Main {

static long[] list=new long[87];

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

   String[] nyuA=sc.nextLine().split(" ");
   
int a=Integer.parseInt(nyuA[0]);
int b=Integer.parseInt(nyuA[1]);

int[] num=new int[1000];

int count=0;
for(int i=1;i<=999;i++){
count+=i;
num[i-1]=count;
}


System.out.println(num[b-a-2]-a);
}

}



Measured memory_bytes: 21844
// finish date: 2019/2/22

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>>
        vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;

vi depth;
vb used;

int dfs(vector<set<int>> &path, int i) {
    if (used[i]) return depth[i] + 1;
    int ma = 0;
    for (int e: path[i]) {
        ma = max(ma, dfs(path, e));
    }
    used[i] = true;
    depth[i] = ma;
    return depth[i] + 1;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<set<int>> path(N);
    depth = vi(N, 0);
    used = vb(N, false);
    int x, y;
    rep(i, M) {
        cin >> x >> y;
        x--, y--;
        path[x].insert(y);
    }
    int ma = 0;
    rep(i, N) {
        dfs(path, i);
        ma = max(ma, depth[i]);
    }

    cout << ma << endl;


    return 0;
}

Measured memory_bytes: 13440
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define endl "\n"
#define dbg(x) cout << #x << " = " << (x) << endl;
const ll MOD = 1000000007;
const ll INF = 1e18;

string s, t;
int dp[3001][3001];
int n, m;

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("F:\\Scripts\\input","r",stdin);
    // freopen("F:\\Scripts\\output","w",stdout);
    // #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> s >> t;
    s = "0" + s;
    t = "0" + t;
    n = s.size();
    m = t.size();
    vector<char> res;;
    for(int i = 1;i < n;i++) for (int j = 1;j < m;j++){
        if (s[i] == t[j]) dp[i][j] = 1 + dp[i-1][j-1];
        else dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
        // cout << dp[i][j] << " ";
    }
    int i = n-1, j = m-1;
    while (i >= 1 and j >= 1){
        if (dp[i][j] == dp[i-1][j]) i--;
        else if (dp[i][j] == dp[i][j-1])j--; 
        else if (dp[i][j] > dp[i-1][j-1]){
            res.push_back(s[i]);
            i--, j--;
        }
    }

    for(int i = res.size()-1;i >= 0;i--)
        cout << res[i];
    return 0;
    
}

Measured memory_bytes: 35456
import sys
#from me.io import dup_file_stdin

#@dup_file_stdin
def solve():
    while True:
        l = list(map(int,sys.stdin.readline().split(' ')))
        if l[0] == 0: break
        l.sort();
        n = int(sys.stdin.readline())
        for i in range(n):
            r = int(sys.stdin.readline())
            if r*r*4>l[0]*l[0]+l[1]*l[1]:
                print("OK")
            else:
                print("NA")
solve()
 

Measured memory_bytes: 7784
#include<bits/stdc++.h>
#define ll long long
using namespace std;
    
int main(){
    ll n, x, y;
    vector<pair<ll,ll>> a;
    vector<ll> arrx, arry;
    
    cin >> n;
    for(ll i=0;i<n;i++){
        cin >> x >> y;
        a.push_back({x,y});
        arrx.push_back(x+y);
        arry.push_back(y-x);
    }
    sort(arrx.begin(),arrx.end());
    sort(arry.begin(),arry.end());
    ll mx = 0;

    for(int i=0;i<n;i++){
        mx = max({mx,abs(arrx[i]-arrx[0]),abs(arrx[i]-arrx[n-1])});
        mx = max({mx,abs(arry[i]-arry[0]),abs(arry[i]-arry[n-1])});
    }

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

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

int main()
{
    int i;
    string s;
    
    cin >> s;
    
    for(i = 0; i < 19; i++) {
        if(s[i] == ',') {
            cout << ' ';
        } else {
            cout << s[i];
        }
    }
    
    cout << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
 
using namespace std;
 
int main(){
    int H,W;
    while(true){
        scanf("%d %d",&H,&W);
        if(H == 0 && W == 0) break;
        for(int i = 0; i < W; i++) printf("#");
        printf("\n");
 
        for(int i = 1; i < H-1; i++){
            printf("#");
            for(int j = 1; j < W-1; j++) printf(".");
            printf("#\n");
        }
 
        if(H > 1){
            for(int i = 0; i < W; i++) printf("#");
            printf("\n");
        }
        printf("\n");
    }
}


Measured memory_bytes: 2556
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from queue import Queue


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    abc = LIST()
    abc.sort()
    print(abc[0] * abc[1] * (abc[2] % 2))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5200
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

//rev?????????????????°??????
struct edge { int to, cap, rev; };

vector<edge> G[MAX_N];
int level[MAX_N];	//s??????????????¢
int iter[MAX_N];	//???????????§??????????????£??????

void add_edge(int from, int to, int cap) {
	G[from].push_back({ to,cap,(int)G[to].size() });
	G[to].push_back({ from,0,(int)G[from].size() - 1 });
}

//s????????????????????¢???BFS??§?¨??????????
void bfs(int s) {
	fill(level, level + MAX_N, -1);
	queue<int> que;
	level[s] = 0;
	que.push(s);
	while (!que.empty()) {
		int v = que.front();
		que.pop();
		for (int i = 0; i < G[v].size(); i++) {
			edge &e = G[v][i];
			if (e.cap > 0 && level[e.to] < 0) {
				level[e.to] = level[v] + 1;
				que.push(e.to);
			}
		}
	}
}

//?¢?????????????DFS??§??¢???
int dfs(int v, int t, int f) {
	if (v == t)return f;
	for (int &i = iter[v]; i < G[v].size(); i++) {
		edge &e = G[v][i];
		if (e.cap > 0 && level[v] < level[e.to]) {
			int d = dfs(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

//s??????t???????????§???????±???????
int max_flow(int s, int t) {
	int flow = 0;
	for (;;) {
		bfs(s);
		//REP(i, 10) {
		//	cout << i << " " << level[i] << endl;
		//}
		if (level[t] < 0)return flow;
		fill(iter, iter + MAX_N, 0);
		int f;
		while ((f = dfs(s, t, INF)) > 0) {
			flow += f;
		}
		//cout << "flow:" << flow << endl;
	}
}

int main() {
	int n, e;
	int s, t, c;
	cin >> n >> e;
	REP(i,e){
		cin >> s >> t >> c;
		add_edge(s, t, c);
	}
	cout << max_flow(0, n - 1) << endl;
}

Measured memory_bytes: 12564
#include <cstdio>

int N;
int M=2;
int A[110][110];
int memo[110][110];

void solve()
{
	int i, j;
	memo[0][0] = A[0][0];
	for(i=0; i<M; i++){
		for(j=0; j<N; j++){
			if(i+1<M){
				if(memo[i+1][j] < memo[i][j]+A[i+1][j])
					memo[i+1][j] = memo[i][j]+A[i+1][j];
			}
			if(j+1<N){
				if(memo[i][j+1] < memo[i][j]+A[i][j+1])
					memo[i][j+1] = memo[i][j]+A[i][j+1];
			}
		}
	}
	printf("%d\n", memo[M-1][N-1]);
}

int main()
{
	int i, j;
	scanf("%d", &N);
	for(i=0; i<M; i++)
		for(j=0; j<N; j++)
			scanf("%d", &A[i][j]);
	solve();
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int c0 = 0 , c1 =0,c2=0,c3 = 0;
        String s;
        for(int i = 0; i < n; i++){
             s = input.next();
            if(s.equals("AC"))
                c0++;
            else if(s.equals("WA"))
                c1++;
            else if(s.equals("TLE"))
                c2++;
            else if(s.equals("RE"))
                c3++;
        }
        System.out.println("AC" + " x " + c0);
        System.out.println("WA" + " x " + c1);
        System.out.println("TLE" + " x " + c2);
        System.out.println("RE" + " x " + c3);

    }

    }


Measured memory_bytes: 58592
#include <iostream>
#include <string>
using namespace std;
int main(){
	int n;
	string a,b;
	cin >> n;
	int countera=0,counterb=0;
	for( int i=0 ; i<n ; i++ ){
		cin >> a >> b;
		int min = a.size();
		if( a.size() > b.size() )
			min = b.size();
		int max=a.size();
		if( a.size() < b.size() )
			max=b.size();
		int counter=0;

		for( int j=0 ; j<min ; j++ ){
			char cha = a[j];
			char chb = b[j];
			if( isupper(cha) )
				a[j] = cha = tolower(cha);
			if( isupper(chb) )
				b[j] = chb = tolower(chb);

			if( cha-'a' < chb-'a' ){
				countera+=3;
				break;
			}
			else if( cha-'a' > chb-'a' ){
				counterb+=3;
				break;
			}
			else{
				counter++;
				if( counter == min ){
					if( max==min ){
							countera++;
							counterb++;
					}
					else if( max==a.size() )
						counterb+=3;
					else
						countera+=3;
					break;
				}

			}
		}
	//	cout << counterb <<" "<<countera << endl;
	}
	cout << counterb <<" " << countera << endl;
}

Measured memory_bytes: 3160