akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using Graph = vector<vector<int>>;


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    ll n;
    //cout << fixed <<(ll) 26 * 26 * 26 * 26 * 26 * 26 * 26 * 26 * 26 *26 <<endl;
    //cout << fixed <<(ll) 1000000000000001 << endl;
    cin >> n;
    ll tmp_m = 1;
    ll x = n;
    vector<char> ab = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
    FOR(i, 1, 11){
        ll tmp_x = n - 26* (pow(26, i) - 1) / 25 ;
        if(tmp_x > 0){
            tmp_m = i+1;
            x = tmp_x;
        }
    }
    x -= 1;
    deque<char> ans;
    FOR(i, 1, tmp_m+1){
        ans.push_front(ab[x%26]);
        x /= 26;
    }
    REP(i, ans.size()){
        cout << ans[i];
    }
    cout <<endl;

}



Measured memory_bytes: 4104
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
 
		int n = scanner.nextInt();
		int arr[] = new int[n];
		for(int i = 0; i < n - 1; i++) {
			int value = scanner.nextInt();
			arr[value - 1] += 1;
		}
		
		for(int value : arr)
			System.out.println(value);
		
 
		scanner.close();
	}
 
}

Measured memory_bytes: 59116
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin>>n;
	vector<ll>arr(n);
	for(int i=0; i<n; i++)
	 cin>>arr[i];
	ll ans=arr[0];
	for(int i=1; i<n; i++)
	 ans=ans^arr[i];
	for(int i=0; i<n; i++){
	 ll temp=ans^arr[i];
	 cout<<temp<<" ";
    }
	return 0;
}



Measured memory_bytes: 4836
#include<stdio.h>
int main(){
	int a[26]={0};
	char b;
	while(scanf("%c",&b)!=EOF){
		if(b>=65&&b<=90){
			a[b-65]++;
		}
		if(b>=97&&b<=122){
			a[b-97]++;
		}
	}
	int i;
	for(i=0;i<26;i++){
		printf("%c : %d\n",i+97,a[i]);
	}
	return 0;
}



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

const int M = 1e9+7;

int main() {
    cout.fixed;
    cout.precision(12);
	int n , i , j ,k , l;
	cin >> n;
	vector < double >v(n+1);
	for(i=1;i<=n;++i) 
	    cin >> v[i];
	int h = n - n/2;
	vector < vector < double > >dp(n + 1, vector < double >(n + 1 , 0));
	dp[0][0] = 1;
	for(i=1;i<=n;i++) {
	    dp[0][i] = dp[0][i-1] * (1-v[i]);
	}
	for(i=1;i<=n;i++) {
	    for(j=i;j<=n;j++) {
	        if(i == j) 
	            dp[i][j] = dp[i-1][j-1] * v[i];
	        else 
	            dp[i][j] = dp[i-1][j-1] * v[j] + dp[i][j-1] * (1-v[j]);
	    }
	}
	
	double ans = 0;
// 	cout << h << endl;
	for(i=h;i<=n;i++) {
	   // cout << dp[i][n] << endl;
	    ans += dp[i][n];
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 70656
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>
#include<time.h>
#include<bitset>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<sstream>
#include<random>
#include<numeric>

//by Skeef79

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>
#define what_is(x) cout<<#x<<" is "<<x<<en;

using namespace std;

const int INF = 2000000000;
const ll LINF = 2000000000000000000;

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

template <typename T> void input(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a[i].size(); j++)
			cin >> a[i][j];
}

struct BIT
{
	vector<int> t;
	int n;

	BIT()
	{

	}

	int pref(int r)
	{
		int res = 0;
		for (; r >= 0; r = (r & (r + 1)) - 1)
			res += t[r];
		return res;
	}
	
	void inc(int i,int val)
	{
		for (; i < n; i |= (i + 1))
			t[i] += val;
	}

	void init(vector<int>&a)
	{
		for (int i = 0; i < n; i++)
			inc(i, a[i]);
	}

	int get(int l, int r)
	{
		return pref(r) - pref(l-1);
	}

};

void solve()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<BIT> t(26);

	for (char c = 'a'; c <= 'z'; c++)
	{
		vector<int>a(n);
		t[c - 'a'].n = n;
		t[c - 'a'].t = vector<int>(n);
		for (int i = 0; i < n; i++)
			if (s[i] == c)
				a[i] = 1;
		t[c - 'a'].init(a);
	}
	int q;
	cin >> q;
	while (q--)
	{
		int type;
		cin >> type;
		if (type == 1)
		{
			int i;
			char c;
			cin >> i >> c;
			i--;
			int idx = s[i] - 'a';
			t[idx].inc(i, -1);
			s[i] = c;
			idx = s[i] - 'a';
			t[idx].inc(i, 1);
		}
		else
		{
			int l, r;
			cin >> l >> r;
			l--, r--;
			int ans = 0;
			for (int i = 0; i < 26; i++)
				ans += (t[i].get(l, r) > 0 ? 1 : 0);
			cout << ans << en;	
		}
	}

}

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

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif

	int tst = 1;
	//cin >> tst;
	while (tst--)
		solve();

}

Measured memory_bytes: 53624
#include <algorithm>
#include <iostream>
using namespace std;
#define MAX_E 100000
#define MAX_V 10000

struct edge {
  int u, v, cost;
};

int V, E;
edge es[MAX_E];
int par[MAX_V];
int r[MAX_V];

void init_union_find(int v) {
  for(int i = 0; i < v; i++) {
    par[i] = i;
    r[i] = 0;
  }
}

int find(int x) {
  if(par[x] == x) return x;
  else return par[x] = find(par[x]);
}

void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if(x == y) return ;

  if(r[x] < r[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if(r[x] == r[y]) r[x]++;
  }
}

bool same(int x, int y) {
  return find(x) == find(y);
}

bool comp(const edge& e1, const edge& e2) {
  return e1.cost < e2.cost;
}

int kruskal() {
  sort(es, es + E, comp);
  init_union_find(V);
  int res = 0;
  for(int i = 0; i < E; i++) {
    edge e = es[i];
    if(!same(e.u, e.v)) {
      unite(e.u, e.v);
      res += e.cost;
    }
  }
  return res;
}

int main () {
  cin >> V >> E;

  for(int i = 0; i < E; i++) {
    int v1, v2, c;
    cin >> v1 >> v2 >> c;
    es[i].u = v1;
    es[i].v = v2;
    es[i].cost = c;
  }

  cout << kruskal() << endl;

}

Measured memory_bytes: 2428
#include <iostream>
#include <cmath>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<double,int> P;

int main() {
  int n;
  vector<P> V;
  P temp;
  while(cin >> n) {
    V.clear();
    if(n==0) break;
    int k;
    double h,w;
    for(int i=0;i<n;i++) {
      cin >> k >> h >> w;
      temp.first = abs(w / ((h/100)*(h/100)) - 22.0);
      temp.second = k;
      V.push_back(temp);
    }

    sort(V.begin(),V.end());
    temp = V[0];
    cout << temp.second << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X,Y;
  cin >> hex >> X ;
  cin >> hex >> Y;
  if (X > Y){ cout << ">" << endl; }
  else if (X < Y){ cout << "<" << endl;}
  else if (X = Y){ cout << "=" << endl;}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)
typedef double D;
typedef complex<D> P;
typedef pair<P, P> L;
typedef vector<P> VP;
const D EPS = 1e-9;
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)
D dot(P a, P b) {return (conj(a)*b).X; }
D cross(P a, P b) {  return (conj(a)*b).Y;}
int ccw(P a, P b, P c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1; 
  if (cross(b,c) < -EPS) return -1;
  if (dot(b,c)   < -EPS) return +2;
  if (norm(b) < norm(c)) return -2;  
  return 0; 
}
P crosspointLL(P a1, P a2, P b1, P b2) {
  D d1 = cross(b2-b1, b1-a1);
  D d2 = cross(b2-b1, a2-a1);
  if (EQ(d1, 0) && EQ(d2, 0)) return a1;
  if (EQ(d2, 0)) throw "kouten ga nai";
  return a1 + d1/d2 * (a2-a1);
}
VP convexCut(const VP& ps, P a1, P a2) {
  int n = ps.size();
  VP ret;
  rep(i,n) {
    int ccwc = ccw(a1, a2, ps[i]);
    if (ccwc != -1) ret.push_back(ps[i]);
    int ccwn = ccw(a1, a2, ps[(i + 1) % n]);
    if (ccwc * ccwn == -1) ret.push_back(crosspointLL(a1, a2, ps[i], ps[(i + 1) % n]));
  }
  return ret;
}
D area(const VP& ps) {
  D a = 0;
  rep (i, ps.size()) a += cross(ps[i], ps[(i+1) % ps.size()]);
  return a / 2;
}
VP voronoiCell(P p, const VP& ps, const VP& outer) {
  VP cl = outer;
  rep (i, ps.size()) {
    if (EQ(abs(ps[i]-p), 0)) continue;
    P h = (p+ps[i])*0.5;
    cl = convexCut(cl, h, h + (ps[i]-h)*P(0,1) );
  }
  return cl;
}
int n,m;
VP v1,v2;
double x,y;
int main(){
  while(cin>>n>>m,n){
    v1.clear();
    v2.clear();
    rep(i,n){
      cin>>x>>y;
      v1.push_back(P(x,y));
    }
    rep(i,m){
      cin>>x>>y;
      v2.push_back(P(x,y));
    }
    rep(i,m){
      VP t=voronoiCell(v2[i],v2,v1);
      printf("%.10f\n",area(t));
    }
  }
}

Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    int N,D;
    cin >> N >> D;
    vector<vector<int>> X(N,vector<int>(D));
    REP(i,N){
        REP(j,D){
            cin >> X[i][j];
        }
    }
    double cnt = 0,ans = 0;
    REP(i,N){
        for(int j = i+1;j < N;j++){
            REP(k,D){
                ans += abs(X[i][k] -X[j][k])*abs(X[i][k] -X[j][k]);
            }
            for(double k = 1;k < 1600;k++){
                if(ans == k*k) cnt++;
            }
            ans = 0;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[10000100],b[10000100];
int len;

void fz()
{
	char cc[10000100];
	for(int i=len-1,j=0;i>=0;i--,j++)
	{
		cc[j]=a[i];
	}
	strcpy(a,cc);
}

int main()
{
	cin>>a;
	strcpy(b,a);
	len=strlen(a);
	fz();
	for(int i=0;i<len;i++)
	{
		if(a[i]=='b') a[i]='d';
		else if(a[i]=='d') a[i]='b';
		else if(a[i]=='q') a[i]='p';
		else if(a[i]=='p') a[i]='q';
	}
	if(strcmp(a,b)==0)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
} 

Measured memory_bytes: 4480
#083B.py
n,a,b=map(int,input().split())

l=[]

	
for i in range(1,n+1):
	#print(i)
	d=i
	count=0
	while(i!=0):
		count+=i%10
		#print(count)
		i=int(i/10)	
	if(a<=count and count<=b):
		l.append(d)

#print(l)
#print(count)
print(sum(l))

		


Measured memory_bytes: 3300
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#define FOR(idx, begin, end) for(int idx = (int)(begin), idx##_sz = (int)(end); idx < idx##_sz; ++idx)

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

using namespace std;
typedef long long lint;

const int MOD = 1000000007, INF = 1111111111;
const double EPS = 1e-9;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string S;
	cin >> S;

	int bit = 0b0;
	lint tmp = 0;
	lint sum = 0;

	while (bit^(1 << S.length() - 1)) {

		tmp = 0;
		for (int i = 0; i < (int)(S.length()); i++) {

			tmp = 10 * tmp + (S[i] - '0');

			if (bit & (1 << i)) {
				sum += tmp;
				tmp = 0;
			}
		}
		sum += tmp;
		bit += 0b1;
	}

	cout << sum;
	return 0;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var rList = new List<int>();

            while (true)
            {
                var line = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();

                if (!IsLoop(line)) break;

                rList.Add(Calc(line));
            }

            Output(rList);

        }

        static bool IsLoop(int[] line)
        {
            if (line.Any(a => a != 0))
                return true;
            return false;
        }

        static int Calc(int[] line)
        {
            var n = line[0];
            var x = line[1];
            var count = 0;

            foreach (var i in Enumerable.Range(1, n-2))
            {
                foreach (var j in Enumerable.Range(i+1, n-i-1))
                {
                    foreach (var k in Enumerable.Range(j+1, n-j))
                    {
                        if (i + j + k == x)
                        {
                            count++;
                        }
                    }
                }
            }
            return count;

        }

        static void Output(List<int> result)
        {
            foreach (var r in result)
            {
                Console.WriteLine(r);
            }
        }
    }

}



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

int main()
{
    string a, b, c;
    cin >> a >> b >> c;

    if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0])
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    
}

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

int main(){
    int N; cin>>N;
    int high=0;
    int ans=0;
    rep(i,N){
        int h; cin>>h;
        if(high <= h){
            ans++;
            high = h;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3532
#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;
typedef string str;
typedef std::pair<ll,ll> pl;
typedef std::map<string, ll> msl;
typedef std::map<ll, ll> mll;
typedef std::vector<ll> vl;
const long double EPS = 1e-9;
 
#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()
#define tol(c) char((c)+0x20)
#define tou(c) char((c)-0x20)
#define pb push_back
#define mp make_pair
#define pr(a) cout << (a)
#define prl(a) cout << (a) << endl
#define prl2(a,b) cout << (a) << " " << (b) << endl
#define prs(a) cout << (a) << " "
#define yn(condition) if ((condition)) prl("Yes"); else prl("No");
#define YN(condition) if ((condition)) prl("YES"); else prl("NO");
#define rpr(i,n,ans) rep((i),(n)) prs((ans[(i)]))
#define cpr(i,n,ans) rep((i),(n)) prl((ans[(i)]))
#define in1(a) cin >> (a)
#define in2(a,b) cin >> (a) >> (b)
#define in3(a,b,c) cin >> (a) >> (b) >> (c)
#define in4(a,b,c,d) cin >> (a) >> (b) >> (c) >> (d)
#define rin1(i,n,a) rep((i),(n)) cin >> (a[(i)])
#define rin2(i,n,a,b) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)])
#define rin3(i,n,a,b,c) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)]) >> (c[(i)])
#define e1 first
#define e2 second
#define ctol(c) ll((c)) - ll('0')
#define ltos(n) to_string((n))
#define items(kv, v) for(auto &(kv): (v))
#define ndig(N, n) ctol(ll(ltos((N))[ll(ltos((N)).length()) - (n)]))
#define beto(a,b,c) (a) < (b) && (b) < (c)
#define betc(a,b,c) (a) <= (b) && (b) <= (c)
#define rsort(a,n) sort(a,a+n,greater<>())
 
const ll mod = 1e9 + 7;
const ll INF = mod * mod;
const ll MAX_N = 100;
 
int main(void){
    ll n;
    ll d[MAX_N];
    ll answer = 0;
    mll cnt;

    in1(n);
    rin1(i,n,d);

    sort(d,d+n);
    rep(i,n) cnt[d[i]] = 0;
    prl(cnt.size());

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <vector>
struct Node{
	int a,b,c,d;
}t[60];
int n,m,q,ans;
void dfs(int cnt);
using namespace std;
vector<int>num;
int main()
{
	cin>>n>>m>>q;
	for (int i=1;i<=q;i++)
	{
		cin>>t[i].a>>t[i].b>>t[i].c>>t[i].d;
	}
	num.push_back(0);
	dfs(1);
	cout<<ans;
	return 0;
}
void dfs(int start)
{
	if (num.size()==n+1)
	{
		int temp=0;
		for (int i=1;i<=q;i++)
		{
			if (num[t[i].b]-num[t[i].a]==t[i].c)   temp+=t[i].d;
		}
		ans=max(ans,temp);
		/*for (int i=1;i<=n;i++)
		{
			cout<<num[i]<<"   ";
		}
		cout<<temp<<endl;*/
		return ;
	}
	for (int i=start;i<=m;i++)
	{
		num.push_back(i);
		dfs(i);
		num.pop_back();
	}
}

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

int main() {
  int N,W;
  cin >> N >> W;
  vector<ll> w(N);
  vector<ll> v(N);
  rep(i,N){
      cin >> w[i];
      cin >> v[i];
  }
vector<vector<ll>> dp(N+1, vector<ll>(100000+1,1000000000000));
/*dp[i+1][j]=i番目までの品物から価値がj以上になるように選んだ時の、
重さの総和の最小値
*/
  dp[0][0] = 0;
for(int i  =0;i<N;i++){
    for(int j = 0;j<=100000;j++){
        //i番目の品物を選ぶ場合
        if(j >= v[i]) dp[i+1][j] = min(dp[i][j],dp[i][j-v[i]] + w[i]);
        //i番目の品物を選ばない場合
        else dp[i+1][j] = dp[i][j];
    }
}

ll res = 0;
for(int j = 0;j <=100000;j++){
    if(dp[N][j] <= W) res = j;
}
cout << res << endl;

}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	long long int ans = 0, input, l, s;
	cin >> ans;
	for(int i = 0; i < n - 1; i++) {
		cin >> input;
		l = max(input, ans);
		s = min(input, ans);
		ans = l;
		while(l % s) {
			l += ans;
		}
		ans = l;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define to_ll(b) stoll(b)
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	string s,t,u;
	cin>>s>>t>>u;
	queue<char> aq,bq,cq;
	rep(i,0,s.size()) aq.push(s[i]);
	rep(i,0,t.size()) bq.push(t[i]);
	rep(i,0,u.size()) cq.push(u[i]);
	char ans='g';
	char v='a';
	while(true){
		if(v=='a'){
			if(aq.empty()){
				ans='A';
				break;
			}
			v=aq.front();
			aq.pop();
		}
		if(v=='b'){
			if(bq.empty()){
				ans='B';
				break;
			}
			v=bq.front();
			bq.pop();
		}
		if(v=='c'){
			if(cq.empty()){
				ans='C';
				break;
			}
			v=cq.front();
			cq.pop();
		}
	}
	cout<<ans;
		
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

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

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    int n;
    cin >> n;
    string s1,s2;
    cin >> s1 >> s2;
    mint ans = 1;
    int id = 1;
    if(s1[0]==s2[0]){
        ans *= 3;
    }
    else{
        ans *= 6;
        id++;
    }
    while(id<n){
        if(s1[id]==s2[id]){
            if(s1[id-1]==s2[id-1]){
                ans *= 2;
            }
            else{
                ans *= 1;
            }
            id++;
        }
        else{
            if(s1[id-1]==s2[id-1]){
                ans *= 2;
            }
            else{
                ans *= 3;
            }
            id += 2;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3604
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#define ll long long
#define inf 1e9
#define eps 1e-10
#define mod 9901
#define mkp make_pair
using namespace std;
int i,j,k,m,s,t,n,ans1,ans2,n1,nn,m1,mx;
int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int kabs(int a)
{
   if (a<0) return -a;
   return a; 
}
void add(int &x,int y)
{
   x+=y;
   if (x>=mod) x-=mod;
}
void dec(int &x,int y)
{
	x-=y;
	if (x<0) x+=mod;
}
int bo,first[101000],net[201000],zhi[201000],a[101000],p[101000],l1[101000],r1[101000];
void insert(int u,int v)
{
	net[++m1]=first[u];
	first[u]=m1;
	zhi[m1]=v;
}
void dfs(int x,int fa)
{
	if (!bo) return;
	int k,v,bo2=0;
	for (k=first[x];k;k=net[k])
	{
		v=zhi[k];
		if (v==fa) continue;
		dfs(v,x);
		p[x]|=p[v];
	}
	if (a[x]!=-1) p[x]=1;
	if (!bo) return;
	if (!p[x]) return;
	if (a[x]!=-1)
		bo2=1,l1[x]=r1[x]=a[x];
	for (k=first[x];k;k=net[k])
	{
		v=zhi[k];
		if (v==fa) continue;
		if (!p[v]) continue;
		if (!bo2)
		{
			bo2=1;
			l1[x]=l1[v]-1;
			r1[x]=r1[v]+1;
		} else
		{
			if (l1[v]-1>r1[x]) {bo=0;return;}
			if (r1[v]+1<l1[x]) {bo=0;return;}
			if (l1[x]%2!=(l1[v]-1)%2) {bo=0;return;}
			l1[x]=max(l1[x],l1[v]-1);
			r1[x]=min(r1[x],r1[v]+1);
			if (l1[x]>r1[x]) {bo=0;return;}
		}
	}
}
void solve(int x,int fa)
{
	int k,v;
	if (x==1) a[x]=l1[x]; else
	if (!p[x]||(a[fa]+1>=l1[x]&&a[fa]+1<=r1[x])) a[x]=a[fa]+1; else a[x]=a[fa]-1;
	for (k=first[x];k;k=net[k])
	{
		v=zhi[k];
		if (v==fa) continue;
		solve(v,x);
	}
}
int main()
{
	scanf("%d",&n);
	for (i=1;i<n;i++)
		scanf("%d%d",&s,&t),insert(s,t),insert(t,s);
	scanf("%d",&m);
	memset(a,-1,sizeof(a));
	for (i=1;i<=m;i++)
		scanf("%d%d",&s,&t),a[s]=t,p[s]=1;
	bo=1;
	dfs(1,0);
	if (!bo)
	{
		puts("No");
		return 0;
	}
	solve(1,0);
	puts("Yes");
	for (i=1;i<=n;i++)
		printf("%d\n",a[i]);
}

Measured memory_bytes: 9088
s = input()
q = int(input())
left = ""
right = ""
flag_swap = False
for i in range(q):
  query = list(input().split())
  if query[0] == "1":
    flag_swap = not flag_swap
  else:
    if (query[1] == "1" and not flag_swap) or (query[1] == "2" and flag_swap):
      left += query[2]
    else:
      right += query[2]

if flag_swap:
  print(right[::-1]+s[::-1]+left)
else:
  print(left[::-1]+s+right)
  
      
      

Measured memory_bytes: 4468
import collections

def get_max_value(dict1, dict2):
    max_dict1=max(dict1, key=dict1.get)
    max_dict2=max(dict2, key=dict2.get)
    return max_dict1, max_dict2

n=int(input())
a=list(map(int, input().split()))

if len(collections.Counter(a))==1:
    print(int(n/2))
else:
    a_even=[a[i] for i in range(0,n,2)]
    a_odd=[a[i]for i in range(1,n,2)]

    a_even_c=collections.Counter(a_even)
    a_odd_c=collections.Counter(a_odd)

    while(True):
        max_a_even, max_a_odd=get_max_value(a_even_c, a_odd_c)
        if max_a_even!=max_a_odd:
            replace_count=n-a_even_c[max_a_even]-a_odd_c[max_a_odd]
            break
        else:
            if a_even_c[max_a_even]>a_odd_c[max_a_odd]:
                del a_odd_c[max_a_odd]
            elif a_even_c[max_a_even]==a_odd_c[max_a_odd]:
                temp=a_even_c[max_a_even]
                del a_odd_c[max_a_odd]
                del a_even_c[max_a_even]
                even_2, odd_2=get_max_value(a_even_c, a_odd_c)
                if a_even_c[even_2]>=a_odd_c[odd_2]:
                    a_odd_c[max_a_odd]=temp
                else:
                    a_even_c[max_a_even]=temp
            else:
                del a_even_c[max_a_even]

    print(replace_count)

Measured memory_bytes: 19928
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;
    vector<bool> lazyFlag;

public:
    LazySegmentTree(vector<ll> v) {
      int sz = (int)v.size();
      n = 1; while(n < sz) n *= 2;
      node.resize(2*n-1);
      lazy.resize(2*n-1, 0);
      lazyFlag.resize(2*n-1, false);
      for(int i=0; i<sz; i++) node[i+n-1] = v[i];
      for(int i=n-2; i>=0; i--) node[i] = (node[i*2+1] + node[i*2+2]);
    }

    void lazyEvaluate(ll k, ll l, ll r) {
      if(lazyFlag[k]) {
        node[k] = ((r-l) * lazy[k]);
        if(r - l > 1) {
          lazy[k*2+1] = lazy[k*2+2] = lazy[k];
          lazyFlag[k*2+1] = lazyFlag[k*2+2] = true;
        }
        lazyFlag[k] = false;
      }
    }

    void update(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        lazyEvaluate(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
          lazy[k] = x;
          lazyFlag[k] = true;
          lazyEvaluate(k, l, r);
        }
        else {
          update(a, b, x, 2*k+1, l, (l+r)/2);
          update(a, b, x, 2*k+2, (l+r)/2, r);
          node[k] = (node[2*k+1] + node[2*k+2]);
        }
    }

    ll find(int a, int b, int k=0, ll l=0, ll r=-1) {
      if(r < 0) r = n;
      lazyEvaluate(k, l, r);
      if(b <= l || r <= a) return 0;
      if(a <= l && r <= b) return node[k];
      ll vl = find(a, b, 2*k+1, l, (l+r)/2);
      ll vr = find(a, b, 2*k+2, (l+r)/2, r);
      return (vl + vr);
    }
};

int main(int argc, char const *argv[]) {
  ll k, n;std::cin >> k >> n;
  // S = k^1 + k^2 + k^3 ....
  // Kが偶数 -> K/2, K, K, k...
  if(k%2==0){
    vll ans;
    ans.push_back(k/2);
    re(i, n-1) ans.push_back(k);
    re(i, ans.size()) std::cout << ans[i] << (i==ans.size()-1?"\n":" ");
    return 0;
  }
  LazySegmentTree seg(vll(n, (k/2)+k%2));
  ll las = n-1;


  for(int i=0;i<n/2;i++){
    ll q = seg.find(las, las+1);
    if(q==1){
      seg.update(las, las+1, 0);
      las--;
    }else{
      seg.update(las, las+1, q-1);
      seg.update(las+1, n, k);
      las = n-1;
    }
  }

  vll ans;
  for(int i=0;i<n;i++){
    ll q = seg.find(i, i+1);
    if(q==0) break;
    ans.push_back(q);
  }
  re(i, ans.size()) std::cout << ans[i] << (i==ans.size()-1?"\n":" ");
  return 0;
}


Measured memory_bytes: 25768
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;
const double EPS = 1e-8;
// 1 	指定の数値だけ先へ進む 	1~10
// 2 	指定の数値の金額を得る 	1~100
// 3 	指定の数値の金額を支払う 	1~100
const int none_e = 0;
const int go_e = 1;
const int get_e = 2;
const int pay_e = 3;


struct Event{
    int type;
    int value;
    Event(int _type,int _value)
        : type(_type),value(_value) {}
    Event()
        : type(0),value(0) {}
};
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& val){
    os << "[ ";
    for(typename vector<T>::const_iterator it=val.begin();
        it != val.end();++it){
        os << *it << " ";
    }
    os << "]";
    return os;
}
// ルーレットの情報とボードの情報を入力とし、
// ゴール時の所持金の期待値を出力するプログラムを作成してください。
// X は 1 以上 4 以下、各 Vi は 1 以上 10 以下、Y、N はそれぞれ 1 以上 50 以下、
// Z は 0 以上 Y-1 以下、E は 1 以上 3 以下の整数です。
// なお、所持金の期待値は小数点以下切り捨ての整数で出力してください。
int main(){
    while(true){
        int x,y,z;
        cin >> x >> y >> z;
        if(x == 0 and y == 0 and z == 0) break;
        vector<int> roulette(x);
        vector<Event> board(y+1);
        vector<vector<double>> dp(y+1,vector<double>(100*z+1));

        for(int i=0;i<x;i++){
            cin >> roulette[i];
        }
        for(int i=0;i<z;i++){
            int n,e,a;
            cin >> n >> e >> a;
            board[n] = Event(e,a);
        }
        dp[0][0] = 1;

        for(size_t where=0;where<board.size()-1;where++){
            for(size_t have=0;have<dp[where].size();have++){
                if(abs(dp[where][have] < EPS)) continue;
                for(int r : roulette){
                    int next = min(y,(int)(where+r));
                    int willhave = have;
                    Event e = board[next];
                    if(e.type == go_e) next = min(y,next+e.value);
                    else if(e.type == get_e) willhave += e.value;
                    else if(e.type == pay_e) willhave = max(0,willhave - e.value);
                    dp[next][willhave] += dp[where][have] / roulette.size();
                }
            }
        }
        double ret = 0;
        for(size_t have=0;have<dp[y].size();have++){
            ret += have * dp[y][have];
        }
        cout << floor(ret) << endl;
    }
    return 0;
}

Measured memory_bytes: 3244
#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)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

string s;
int main(){
    int n;
    while(cin>>n,n){
        int mx=0;
        set<string> st;
        rep(i,n){
            cin>>s;
            string t;
            t+=s[0];
            FOR(j,1,s.size()){
                if(s[j-1]=='a'||s[j-1]=='e'||s[j-1]=='i'||s[j-1]=='o'||s[j-1]=='u'){
                    t+=s[j];
                }
            }
            st.insert(t);
            mx=max(mx,(int)t.size());
        }
        if(st.size()!=n){
            cout<<-1<<endl;
            continue;
        }
        while(mx){
            set<string> tmp;
            for(auto it:st){
                if(it.size()==mx) it.pop_back(),tmp.insert(it);
                else tmp.insert(it); 
            }
            if(tmp.size()!=n){
                cout<<mx<<endl;
                break;
            }
            --mx;
            st=tmp;
        }
    }
    return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);

const int MAXN = 100 + 5;
const int MAXK = 1e5 + 5;

int n, k, a[MAXN];
bool dp[MAXK];

int main() {
    IOS
    
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        dp[a[i]] = 1;
    }
    sort(a, a + n);
    
    for (int i = 0; i <= k; i++) {
        if (!dp[i]) {
            for (int j = 0; j < n && i + a[j] <= k; j++) {
                dp[i + a[j]] = 1;
            }
        }
    }

    if (dp[k]) {
        cout << "First\n";
    } else {
        cout << "Second\n";
    }
}

Measured memory_bytes: 3752
import time

import sys
sys.setrecursionlimit(10000) # set recursion-stack depth

n ,c = list(map(int,input().split())) # remove raw_
v = [0]*(n)
w = [0]*(n)

for a in range(n) :
    v[a],w[a] = list(map(int,input().split())) # remove raw_

mm = [[None for i in range(c + 1)] for j in range(n + 1)]

def comb(i, c):
    if i == n:
        return 0
    else:
        if mm[i][c] != None:
            return mm[i][c]

        a = comb(i+1, c)

        b = -1
        if c >= w[i]:
            b = v[i] + comb(i+1, c - w[i])

        mm[i][c] = max(a, b)
        return mm[i][c]

print(comb(0, c))


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

int mp[200];
int main(){
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	int mod = a%b;
	for(;;){
		if(mp[mod] == 1)break;
		mp[mod] = 1;
		if(mod == c){
			printf("YES\n");
			return 0;
		}
		mod = (mod+a)%b;
	}
	printf("NO\n");
	return 0;
}

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

MAX_DIGIT = 40

dp = [[-1, -1] for _ in range(MAX_DIGIT+1)]
dp[0][0] = 0
for i in range(MAX_DIGIT):
    mask = 1 << (MAX_DIGIT - i - 1)
    cnt_1 = 0
    for v in a:
        if v & mask:
            cnt_1 += 1
    cnt_0 = n - cnt_1

    cost_0 = mask * cnt_1
    cost_1 = mask * cnt_0

    if dp[i][1] != -1:
        dp[i+1][1] = max(dp[i+1][1], dp[i][1] + max(cost_0, cost_1))


    if k & mask:
        dp[i+1][1] = max(dp[i+1][1], dp[i][0] + cost_0)


    if k & mask:
        dp[i+1][0] = max(dp[i+1][0], dp[i][0] + cost_1)
    else:
        dp[i+1][0] = max(dp[i+1][0], dp[i][0] + cost_0)

print(max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]))

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

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

    int N = S.size();
    bool flag = false;
    if (S[0] == 'k' && S.substr(N - 6) == "eyence") {
        flag = true;
    }
    else if (S.substr(0, 2) == "ke" && S.substr(N - 5) == "yence") {
        flag = true;
    }
    else if (S.substr(0, 3) == "key" && S.substr(N - 4) == "ence") {
        flag = true;
    }
    else if (S.substr(0, 4) == "keye" && S.substr(N - 3) == "nce") {
        flag = true;
    }
    else if (S.substr(0, 5) == "keyen" && S.substr(N - 2) == "ce") {
        flag = true;
    }
    else if (S.substr(0, 6) == "keyenc" && S.substr(N - 1) == "e") {
        flag = true;
    }
    else if (S.substr(0, 7) == "keyence") {
        flag = true;
    }

    if (flag) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();

            for (var i = 1; i < S.Length; i++)
            {
                if (S[i] == S[i-1])
                {
                    Console.WriteLine("Bad");
                    return;
                }
            }
            Console.WriteLine("Good");
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define ll long long
using namespace std;
bitset<4000010>b;
ll n,x,maxn;
int main()
{
	scanf("%d",&n);
	b[0]=1;
	while (n--)
	{
		scanf("%d",&x);
		b|=b<<x;
		maxn+=x;
	}
	ll i=0;
	for(i=(maxn+1)/2;!b[i];i++);
	printf("%d\n",i); 
	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <stack>
#include <cstring>

using namespace std;

int main(){
	int menseki;
	int d;
	while(cin >> d){
	menseki = 0;
	
	for(int i = 1; i * d < 600; i++){
		menseki += (i * d) * (i * d) * d;
	}

	cout << menseki << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
#include <map>
#include <string>
#include <vector>

std::string mcxi(int n) {
  std::string res;
  if (n / 1000 > 0) {
    if (n / 1000 > 1) res += std::to_string(n / 1000);
    res += 'm';
    n %= 1000;
  }
  if (n / 100 > 0) {
    if (n / 100 > 1) res += std::to_string(n / 100);
    res += 'c';
    n %= 100;
  }
  if (n / 10 > 0) {
    if (n / 10 > 1) res += std::to_string(n / 10);
    res += 'x';
    n %= 10;
  }
  if (n > 0) {
    if (n > 1) res += std::to_string(n);
    res += 'i';
  }
  return res;
}

int main() {
  std::map<std::string, int> dec;
  std::vector<std::string> enc(10000);

  for (int i = 1; i < 10000; ++i) {
    std::string s = mcxi(i);
    dec[s] = i;
    enc[i] = s;
  }

  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    char buf[16];
    scanf("%s", buf);
    int a = dec[buf];
    scanf("%s", buf);
    int b = dec[buf];
    printf("%s\n", enc[a+b].c_str());
  }
}



Measured memory_bytes: 4088
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define PI acos(-1.0)
#define INF 1000000000
#define pow10 tipa_pow10
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
int mult(int a , int b)
{
    return ((ll)a * b) % mod;
}
int add(int a , int b)
{
    return a + b >= mod ? a + b - mod : a + b;
}
int main()
{
    string s;
    int w;
    string ans;
    cin >> s >> w;
    for(int i = 0; i < s.size(); i += w)
    {
        ans += s[i];
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b, sum_a = 0, sum_b = 0, c = 0;
	int syousuu = 0;
	
	while (scanf("%d,%d", &a, &b) != EOF){
		sum_a += a * b;
		sum_b += b;
		c++;
	}
	if (sum_b % c != 0 && 2 * (sum_b % c) >= c){
		syousuu = 1;
	}
	
	printf("%d\n%d\n", sum_a, syousuu + sum_b / c);
	
	return (0);
}

Measured memory_bytes: 592
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
        new Main().run();
    }
	char[][] map;
	int[][] sq;
	int max;
	int n;
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			if(n == 0){
				break;
			}
			map = new char[n][];
			sq = new int[n][n];
			max = 0;
			for(int i = 0;i < n;i++){
				map[i] = scan.next().toCharArray();
			}
			for(int i = 0;i < n;i++){
				sq[0][i] = (map[0][i] == '.')?1:0;
				sq[i][0] = (map[i][0] == '.')?1:0;
			}
			for(int i = 1;i < n;i++){
				for(int j = 1;j < n;j++){
					if(map[i][j] == '*'){
						sq[i][j] = 0;
					}else if(sq[i-1][j-1] == 0 || sq[i-1][j] == 0 || sq[i][j-1] == 0){
						sq[i][j] = 1;
						max = Math.max(max,sq[i][j]);
					}else{
						sq[i][j] = Math.min(sq[i-1][j-1],Math.min(sq[i-1][j],sq[i][j-1]))+1;
						max = Math.max(max,sq[i][j]);
					}
				}
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 60088
#include <algorithm>
#include <array>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <utility>
#include <vector>
#define FOR(i,a,b) for (int i=(a),for_##i##_max=(b);i<=(for_##i##_max);++i)
#define RFOR(i,a,b) for (int i=(a),rfor_##i##_min=(b);i>=(rfor_##i##_min);--i)
#define REP(i,n) for (int i=0,rep_##i##_len=(n);i<(rep_##i##_len);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)
constexpr int INF = 100100100;

template<typename T>
void chmin(T &x, T y) {
  x = std::min(x, y);
}

template<typename T>
void chmax(T &x, T y) {
  x = std::max(x, y);
}

using namespace std;

int main() {
  // cout << fixed << setprecision(10);
  int N; cin >> N;
  int max_h = 0;
  int ans = 0;
  REP(i, N) {
    int H; cin >> H;
    if (H >= max_h) {
      ++ans;
      max_h = H;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[]a = new long[N];
		long sum = 0;
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextLong();
			sum += a[i];
		}
		sc.close();
		long[]b = new long[N + 1];
		for(int i = 1; i <= N; i++) {
			b[i] = b[i-1] + a[i - 1];
		}
		long min = Long.MAX_VALUE;
		for(int i = 1; i <= N - 1; i++) {
			long x = b[i];
			long y = sum - b[i];
			min = Math.min(min, Math.abs(x - y));
		}
		System.out.println(min);
	}
}

Measured memory_bytes: 85884
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN = 100000;

int n,sx;
int x[MAXN], cnt[MAXN];

ll votecnt[MAXN];

void run() {
	scanf("%d%d", &n, &sx); REP(i, n) scanf("%d%d", &x[i], &cnt[i]);

	REP(i, n) votecnt[i] = cnt[i];
	int l = 0, r = n - 1; ll ret = 0; int lastdir = 0;
	while (x[l]<sx&&x[r]>sx) {
		if (votecnt[l] >= votecnt[r]) {
			if (lastdir != +1) ret += x[r] - x[l]; lastdir = +1; votecnt[l] += votecnt[r]; --r;
		} else {
			if (lastdir != -1) ret += x[r] - x[l]; lastdir = -1; votecnt[r] += votecnt[l]; ++l;
		}
	}
	if (x[l] < sx) ret += sx - x[l];
	if (x[r] > sx) ret += x[r] - sx;
	printf("%lld\n", ret);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d,e;
  cin >> a >> b >> c >> d >> e;
  
  if (a == 0) {
    cout << "1" << endl;
  }
  else if (b == 0){
    cout << "2" << endl;
  }    
  else if (c == 0){
    cout << "3" << endl;
  }
  else if (d == 0){
    cout << "4" << endl;
  }  
  else {
    cout << "5" << endl;
  }  
  
}

Measured memory_bytes: 3616
#include<map>
#include<cstdio>
#include<string>
#include<algorithm>

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

using namespace std;

struct Interval{
	int a,b;
	Interval(){}
	Interval(int A,int B):a(A),b(B){}
	bool operator<(const Interval &I)const{ return b<I.b; }
};

bool intersect(const Interval &I,const Interval &J){
	return I.a<J.b && J.a<I.b;
}

int solve(int n,Interval *I){
	sort(I,I+n);

	int ans=0,r=-1;
	rep(i,n) if(r<=I[i].a) r=I[i].b, ans++;

	return ans;
}

int main(){
	for(int n;scanf("%d",&n),n;){
		map<string,int> f;
		Interval I[500];
		rep(i,n){
			char name[33];
			int week,start; scanf("%s%d%d",name,&week,&start);
			f[name]=i;

			int h=start/100,m=start%100;
			start=week*24*60+h*60+m;
			I[i]=Interval(start,start+30);
		}

		int nf; scanf("%d",&nf);
		Interval fav[500];
		rep(i,nf){
			char name[33]; scanf("%s",name);
			fav[i]=I[f[name]];
		}

		bool ok=true;
		rep(j,nf) rep(i,j) if(intersect(fav[i],fav[j])) ok=false;
		if(!ok){ puts("-1"); continue; }

		int n2=0;
		Interval J[500];
		rep(i,n){
			bool ok=true;
			rep(j,nf) if(intersect(I[i],fav[j])) ok=false;
			if(ok) J[n2++]=I[i];
		}

		printf("%d\n",nf+solve(n2,J));
	}

	return 0;
}

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

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

  int n;
  cin >> n;

  map<ll,ll> mp;
  ll sum = 0;

  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;

    ++mp[a];
  }

  for (auto e : mp) sum += e.first * e.second;

  int q;
  cin >> q;

  while (q --> 0) {
    int b, c;
    cin >> b >> c;

    sum -= mp[b] * b;
    sum += mp[b] * c;

    mp[c] += mp[b];
    mp[b] = 0;

    cout << sum << '\n';
  }

  return (0);
}


Measured memory_bytes: 9592
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll H[100005];

int main()
{
	int K, N;
	cin >> N >> K;
	REP(i, N)
	{
		cin >> H[i];
	}
	sort(H, H + N);
	ll min = INF;
	REP(i, N)
	{
		int t = i + K - 1;
		if (t >= N)
		{
			break;
		}

		min = std::min(min, abs(H[t] - H[i]));
	}
	cout << min << endl;
	return 0;
}

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

// #include<cstdio>

int main(){
  int n, m;
  int a[100][100],b[100],c[100]={};

  cin >> n >> m;

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

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

  for (int i=0; i<n; i++){
    for (int j=0; j<m; j++){
      c[i]+=a[i][j]*b[j];
    }
    cout << c[i] << "\n";
  }

  return 0;
}

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

using namespace std;

struct Trio{  int a, b, c;  };

int soma(Trio x){  return x.a + x.b + x.c;  }

int max(int a, int b, int c){
  int max1 = max(a, b), max2 = max(b, c);
  return max(max1, max2);
}

int solve(Trio t, int op)
{
  if (op == 0)  return soma(t);
  
  Trio t1, t2, t3;
  t1.a = 2*(t.a), t1.b = t.b, t1.c = t.c;
  t2.a = t.a, t2.b = 2*(t.b), t2.c = t.c;
  t3.a = t.a, t3.b = t.b, t3.c = 2*(t.c);
  return  max(solve(t1, op - 1), solve(t2, op - 1), solve(t3, op - 1));
}

int main(){
  ios_base:: sync_with_stdio(false); cin.tie(0);
  
  int k;
  Trio n;
  cin >> n.a >> n.b >> n.c >> k;
  
  cout << solve(n, k) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void dfs(vector<int> adj[],vector<int> w[],int i,int a[])
{
	for(int j=0;j<adj[i].size();j++)
	{
		if(a[adj[i][j]]!=-1)
			continue;
		if(w[i][j]%2==0)
		{
			a[adj[i][j]]= a[i];
		}
		else
		{
			a[adj[i][j]] = a[i]==0?1:0;
		}
		dfs(adj,w,adj[i][j],a);
	}
}
int main() {
	int n,i,j,k;
	cin>>n;
	int a[n+1];
	for(int i=0;i<=n;i++)
	a[i]=-1;
	vector<int> adj[n+1];
	vector<int> w[n+1];
	for(int a=0;a<n-1;a++)
	{
		cin>>i>>j>>k;
		adj[i].push_back(j);
		adj[j].push_back(i);
		w[i].push_back(k);
		w[j].push_back(k);
	}
	a[1]=0;
	dfs(adj,w,1,a);
	for(int i=1;i<=n;i++)
	cout<<a[i]<<" ";
	// your code goes here
	return 0;
}

Measured memory_bytes: 14848
n = int(input())
p = [0 for _ in range(n)]
m = [0 for _ in range(n)]
for i in range(n):
  xi,yi = map(int,input().split())
  p[i] = xi+yi
  m[i] = xi-yi
p.sort()
m.sort()
print(max(p[-1] - p[0],m[-1] - m[0]))

Measured memory_bytes: 94048
#include <bits/stdc++.h>
using namespace std;
bool vis[2000006];
vector<long long int> ans;
void dfs(int u,vector<long long int> adj[])
{
    vis[u]=true;
ans.push_back(u);
    for(long long int i=0;i<adj[u].size();i++)
    {
        if(vis[adj[u][i]]==false)
        {
            dfs(adj[u][i],adj);
        }
        else
        {
            ans.push_back(adj[u][i]);
            return;
        }
    }

}
int main() {
    long long int n;
    long long int k;
    cin>>n>>k;
    vector<long long int> adj[n+1];
    for(int i=1;i<=n;i++)
    {
        long long int data;
        cin>>data;
        adj[i].push_back(data);
    }
    memset(vis,false,sizeof(vis));
    int count=0;
    dfs(1,adj);
     n=ans.size();int index=-1;
    for(int i=0;i<n-1;i++){
if(ans[i]==ans[n-1])
{
    index=i;break;
}
    }
    ans.pop_back();
    
    long long int before=index;
    long long int repeat=n-index-1;
    if(k<=before)cout<<ans[k];
    else {
        k=k-index;
        long long int rem=k%(repeat);
        cout<<ans[index+rem];
    }
}

Measured memory_bytes: 30032