akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll, ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define pdd pair<double, double>
#define f first
#define s second
#define MOD 1000000007
#define mkp make_pair
#define M_PI 3.14159265358979323846
#define FOR(i,l,r) for (int i=l;i<=r;i++)
#define LOR(i,l,r) for (ll i=l;i<=r;i++)
#define FORD(i,r,l) for (int i=r;i>=l;i--)
#define LORD(i,r,l) for (ll i=r;i>=l;i--)
#define INF 1000000000
#define CL(x) memset(x,0,sizeof(x))
#define DEB(x) cout << #x << " : " << x << '\n'
#define ALL(x) x.begin(), x.end()
#define SZ(x) x.size()
#define UI(x) (int)(x-'A')
#define LI(x) (int)(x-'a')
typedef long long ll;


int N;

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

    cin>>N;
    cout<<N*N*N<<'\n';

    return 0;
}


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

void get_lcs(string s, string t){
    int N = s.length();
    int M = t.length();
    int dp[N+1][M+1];
    for(int i=0; i<=N; i++)
	    dp[i][0] = 0;
    for(int j=0; j<=M; j++)
	    dp[0][j] = 0;
    for(int i=1; i<=N; i++){
        for(int j=1; j<=M; j++){
            if(s[i-1]==t[j-1])
	        dp[i][j] = 1 + dp[i-1][j-1];
	    else
		dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
	}
    }
    int i = N;
    int j = M;
    string res = "";
    while(1){
        if(i==0 or j==0)
	    break;
	if(s[i-1] == t[j-1]){
	    res += s[i-1];
	    i--;
	    j--;
	}
	else if(dp[i][j-1] > dp[i-1][j])
	    j--;
	else
	    i--;
    }
    reverse(res.begin(), res.end());
    cout << res << endl;

}

int main()
{
    string s, t;
    cin >> s;
    cin >> t;

    get_lcs(s, t);
    return 0;
}


Measured memory_bytes: 35456
fun main(args: Array<String>) {
    val (c11, c12, c13) = readLine()!!.split(" ").map { it.toInt() }
    val (c21, c22, c23) = readLine()!!.split(" ").map { it.toInt() }
    val (c31, c32, c33) = readLine()!!.split(" ").map { it.toInt() }
    val a1 = 0
    val b1 = c11
    val b2 = c12
    val b3 = c13
    val a2 = c21 - b1
    val a3 = c31 - b1
    if ((a2 + b2 == c22) and (a2 + b3 == c23) and (a3 + b2 == c32) and (a3 + b3 == c33)){
        println("Yes")
    }else{
        println("No")
    }
}


Measured memory_bytes: 37872
#include <stdio.h>
int main(void){

  int r,c,x,sum,i,j;
  int data[101][101];
  scanf("%d",&r);
  scanf("%d",&c);

  for (i=0;i<r;i++){
    sum=0;
    for (j=0;j<c;j++){
      scanf("%d",&x);
      data[i][j]=x;
      sum+=x;
    }
    data[i][c]=sum;
  }

  for (j=0;j<=c;j++){
    sum=0;
    for (i=0;i<r;i++){
      sum+=data[i][j];
    }
    data[r][j]=sum;
  }

  for (i=0;i<=r;i++){
    for (j=0;j<c;j++){
      printf("%d ",data[i][j]);
    }
    printf("%d\n",data[i][j]);
  }

  return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

const int MAX_V = 420;
const int Base = MAX_V / 2;

vector<int> es[MAX_V];

struct SCC{//O(V+E)
    static const int MAX_V = 1010;
    int V;
    vector<int> G[MAX_V], rG[MAX_V];
    vector<int> vs;
    bool used[MAX_V];
    int cmp[MAX_V];
    vector<vector<int> > res;

    SCC(int v) : V(v){};
    void add_edge(int from, int to){
        G[from].push_back(to);
        rG[to].push_back(from);
    }

    void dfs(int v){
        used[v] = true;
        for(int i = 0; i < G[v].size(); i++){
            if(!used[G[v][i]]) dfs(G[v][i]);
        }
        vs.push_back(v);
    }
    void rdfs(int v, int k){
        used[v] = true;
        cmp[v] = k;
        for(int i = 0; i < rG[v].size(); i++){
            if(!used[rG[v][i]]) rdfs(rG[v][i], k);
        }
    }

    int scc(){
        memset(used, 0, sizeof(used));
        vs.clear();
        for(int v = 0; v < V; v++){
            if(!used[v]) dfs(v);
        }
        memset(used, 0, sizeof(used));
        int k = 0;
        for(int i = vs.size() - 1; i >= 0; i--){
            if(!used[vs[i]]) rdfs(vs[i], k++);
        }

        res.clear();
        res.resize(k);
        for(int i = 0; i < V; i++){
            res[cmp[i]].push_back(i);
        }
        return k;
    }
    bool check(int v, int W) {
    	return cmp[W] == cmp[v];
    }
};

int main(){
	int n, h;
	cin >> n >> h;
	vi a(n), b(n), c(n), d(n);
	rep(i, n) cin >> a[i] >> b[i] >> c[i] >> d[i];
	vi l(n), r(n);
	rep(i, n) {
		l[i] = (c[i] == 0 ? a[i] : -c[i]);
		r[i] = (d[i] == 0 ? b[i] : -d[i]);
	}
	set<int> st;
	rep(i, n) {
		int frm = (l[i] > 0 ? l[i] : Base - l[i]);
		int to = (r[i] > 0 ? Base + r[i] : -r[i]);
		st.insert(frm);
		st.insert(to);
		if(frm == to) continue;
		es[frm].pb(to);
	}
	int W = MAX_V-1;
	vector<int> in(MAX_V), out(MAX_V);
	SCC g(MAX_V);
	rep(i, MAX_V) {
		sort(all(es[i]));
		//es[i].erase(unique(all(es[i])), es[i].end());
		int prv = -1;
		for(auto& to : es[i]) {
			if(prv != to) g.add_edge(i, to);
			prv = to;
			in[to]++;
		}
		out[i] = es[i].size();
	}
	bool f = true;
	rep(i, MAX_V) {
		if(i >= Base) {
			if(in[i] == out[i]);
			else if(in[i] < out[i]) f = false;
			else g.add_edge(i, W);
		}
		else {
			if(in[i] == out[i]);
			else if(in[i] > out[i]) f = false;
			else g.add_edge(W, i);
		}
	}
	g.scc();
	for(auto& v : st) if(!g.check(v, W)) f = false;
	cout << (f?"YES":"NO") << endl;
	return 0;
}

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

int main() {
   int N,K;
   cin >> N >> K;
   int P[N];
   for (int i=0; i<N; i++) {
       cin >> P[i];
   }
   sort(P,P+N);
   int count=0;
   for (int i=0; i<K; i++) {
       count+=P[i];
   }
   cout << count << endl;
}

Measured memory_bytes: 3596
//==========================Head files==========================
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<set>
#include<iostream>
#include<map>
#define LL long long
#define db double
#define mp make_pair
#define pr pair<int, int>
#define fir first
#define sec second
#define pb push_back
#define ms(i, j) memset(i, j, sizeof i)
using namespace std;
//==========================Templates==========================
inline int read() {
    int x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
inline LL readl() {
    LL x = 0, f = 1; char c = getchar();
    while(c < '0' || c > '9'){if (c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9'){x = x * 10 + c - '0'; c = getchar();}
    return x * f;
}
int power(int a, int b) {
	int ans = 1;
	while (b) {
		if(b & 1) ans = ans * a;
		b >>= 1; a = a * a;
	}
	return ans;
}
int power_mod(int a, int b, int mod) {
	a %= mod;
	int ans = 1;
	while (b) {
		if(b & 1) ans = (ans * a) % mod;
		b >>= 1, a = (a * a) % mod;
	}
	return ans;
}
LL powerl(LL a, LL b) {
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = ans * a;
		b >>= 1ll;a = a * a;
	}
	return ans;
}
LL power_modl(LL a, LL b, LL mod) {
	a %= mod;
	LL ans = 1ll;
	while (b) {
		if(b & 1ll) ans = (ans * a) % mod;
		b >>= 1ll, a = (a * a) % mod;
	}
	return ans;
}
LL gcdl(LL a, LL b) {return b == 0 ? a : gcdl(b, a % b);}
LL abssl(LL a) {return a > 0 ? a : -a;}
int gcd(int a, int b) {return b == 0 ? a : gcd(b, a % b);}
int abss(int a) {return a > 0 ? a : -a;}
//==========================Main body==========================
#define LD "%I64d"
#define D "%d"
#define pt printf
#define sn scanf
#define pty printf("YES\n")
#define ptn printf("NO\n")
//==========================Code here==========================
char s[10], t[10];
int main() {
	cin >> s >> t;
	int ans = 0;
	for (int i = 0; i < 3 ;++i) if (s[i] == t[i]) ++ans;
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

constexpr ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

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

    int n;
    cin >> n;
    int a[n], sum = 0;
    rep(i, n) cin >> a[i], sum += a[i];
    sum = sum + 1 >> 1;
    bitset<2003000> dp(1);
    rep(i, n) dp |= dp << a[i];
    while(!dp[sum])
        sum++;
    cout << sum;
}

Measured memory_bytes: 1152
import sys

read = sys.stdin.read
INF = 1 << 60


def main():
    N, W, *WV = map(int, read().split())
    weight = WV[::2]
    value = WV[1::2]

    V = sum(value)
    dp = [[INF] * (V + 1) for _ in range(N + 1)]
    dp[0][0] = 0
    for i in range(N):
        for v in range(V + 1):
            if v - value[i] >= 0:
                dp[i + 1][v] = dp[i][v - value[i]] + weight[i]
            if dp[i + 1][v] > dp[i][v]:
                dp[i + 1][v] = dp[i][v]

    ans = 0
    for v in range(V + 1):
        if dp[N][v] <= W:
            ans = v
    print(ans)
    return


if __name__ == '__main__':
    main()


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

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> v;
  for(int i=0; i<n; i++){
    int x;
    cin >> x;
  }
  cout << (n - 1 + k - 2) / (k - 1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<cstring>
#include<stdio.h>
using namespace std;
int main(){
	int n,sum=0;
	scanf("%d",&n);
	long long a;
	for(int i=1;i<=n;i++){
		scanf("%lld",&a);
		sum+=a%2;
		sum%=2;
	}
	if(sum==1)printf("NO\n");
	else printf("YES\n");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int n,a[maxn];
int m,s;
bool check()
{
	for (int i=1;i<=n;i++)
	    if (a[i]!=n-1) return 0;
	return 1;
}
int main()
{
	cin>>n;
	for (int i=1;i<=n;i++) scanf("%d",&a[i]),m=max(m,a[i]);
	if (check())
	{
		cout<<"Yes";return 0;
	}
	for (int i=1;i<=n;i++)
	    if (a[i]<m)
	    {
	    	if (a[i]==m-1) s++;
	    	else
	    	{
	    		cout<<"No";return 0;
			}
		}
	if (m<s||2*(m-s)>n-s||(n>s&&m-s<1)) cout<<"No";
	else cout<<"Yes";
	return 0;
}

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

int main(){
    ll n;cin>>n;
    ll a = 0, b = 0;
    for(int i = 0; i < n; i++){
        ll x,y; cin>>x>>y;
        if(i == 0){
            a = x,b = y;
        }
        if(a <= x && b <= y){
            a = x,b = y;
        }
           ll ma = (a+x-1)/x;
           ll mb = (b+y-1)/y;
           if(ma>mb){
               a = x*ma;
               b = y*ma;
           } else {
               a = x*mb;
               b = y*mb;
           }
    }
    cout<<a+b;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
	string str;
	getline(cin,str);
	//cin >> str;
	for(int i=0;i<str.size();i++){
		if(str[i] >= 'a' && str[i] <= 'z'){
			str[i] -= 32;
		} else if(str[i] >= 'A' && str[i] <= 'Z'){
			str[i] += 32;
		}
	}
	cout << str << endl;
	return 0;
}



Measured memory_bytes: 3144
short lcs[4002][4002];

int main(){
  char a[4002],b[4002];
  int i,j,_a,_b,m;
  while(~scanf("%s%s",a+1,b+1)){
    memset(lcs,0,sizeof(lcs));
    _a=strlen(a+1);_b=strlen(b+1);
    for(i=1;i<=_a;i++)
      for(j=1;j<=_b;j++)
        lcs[i][j]=a[i]==b[j]?lcs[i-1][j-1]+1:0;
    for(m=0,i=1;i<=_a;i++)
      for(j=1;j<=_b;j++)
        if(m<lcs[i][j])m=lcs[i][j];
    printf("%d\n",m);
  }
  return 0;
}

Measured memory_bytes: 30000
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 3.14159265358979323846
#define pdd pair<double,double>
bool comp(int a,int b)
{
	return a>b;
}
long long bigpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int main() 
{
	int s;
	cin>>s;
	vector<ll> dp(s+1,0);
	dp[0]=1;
	ll mod=1e9+7;
	for(int i=3;i<=s;i++)
	{
		for(int j=i-3;j>=0;j--)
		{
			dp[i]=(dp[i]+dp[j])%mod;
		}
	}
	cout<<dp[s];
	return 0;    
}

Measured memory_bytes: 3556
open System

[<EntryPoint>]
let main argv =
    let n = stdin.ReadLine() |> int
    let xs = stdin.ReadLine().Split() |> Array.map int
    [|Array.min xs .. Array.max xs|]
    |> Array.map (fun p ->
        xs
        |> Array.sumBy (fun x -> pown (x - p) 2)
    )
    |> Array.min
    |> stdout.WriteLine
    0


Measured memory_bytes: 11348
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 long long
#endif

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

ll mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}
	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}
	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;

map<pair<ll, ll>, ll> cnt;
map<pair<ll, ll>, bool> used;

ll gcd(ll a, ll b) {
	return (a == 0 ? b : gcd(b % a, a));
}

pair<ll, ll> norm(pair<ll, ll> p) {
	if (p.X == 0) return { 0,1 };
	if (p.Y == 0) return { 1,0 };
	ll znak = (((p.X < 0) ^ (p.Y < 0)) ? -1 : 1);
	ll g = gcd(abs(p.X), abs(p.Y));
	return { znak * abs(p.X) / g, abs(p.Y) / g };
}

pair<ll, ll> obr(pair<ll, ll> p) {
	if (p.X == 0) return { p.Y,p.X };
	if (p.Y == 0) return { p.Y,p.X };
	ll znak = (p.X < 0 ? 1 : -1);
	return { znak * abs(p.Y), abs(p.X)};
}

ll pw[maxn];

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	//freopen("output.txt", "w", stdout);
	pw[0] = 1;
	for (ll i = 1; i < maxn; i++) pw[i] = mul(pw[i - 1], 2);

	ll n; cin >> n;
	ll rofl = 0;
	for (ll i = 0; i < n; i++) {
		ll x, y; cin >> x >> y;
		if (x == 0 and y == 0) {
			rofl++;
			continue;
		}
		pair<ll, ll> p = { x, y };
		p = norm(p);
		cnt[p]++;
	}

	ll ans = 1;
	for (auto pp : cnt) {
		auto p = pp.X;
		auto p1 = obr(p);		
		if (used[p] or used[p1]) continue;
		used[p] = 1, used[p1] = 1;
		ll n = cnt[p], m = cnt[p1];
		ll kek = pw[n] + pw[m] - 1;
		kek %= mod; if (kek < 0)kek += mod;
		ans = mul(ans, kek);
	}
	ans--;
	ans += rofl;
	ans %= mod;
	if (ans < 0) ans += mod;
	cout << ans << endl;

	return 0;
}

/*

*/

Measured memory_bytes: 55936
#include <bits/stdc++.h>
using namespace std;
#define ll int
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
        ll n,k;
        cin>>n;
        ll arr[n],dp[n+5];
        for(int i=0;i<n;i++){
            cin>>arr[i];
            dp[i]=INT_MAX;
        }
        dp[0]=0;
        for(int i=1;i<n;i++){
            for(int j=max(0,i-2);j<i;j++){
                dp[i]=min(dp[j]+abs(arr[i]-arr[j]) ,dp[i]);
            }
        }

        cout<<dp[n-1]<<endl;

        

        
    return 0;                               // Reading input fromSTDIN
}


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

int main() {
	int a,b,x;
	char op;

	while (true) {

	cin >>a >> op >> b;
	if (op == '+') {
		x=a+b;
		cout <<x<<endl;
	} else if (op == '-') {
		x=a-b;
		cout <<x<<endl;
	} else if (op == '*') {
		x=a*b;
		cout <<x<<endl;
	} else if (op == '/') {
		x=a/b;
		cout <<x<<endl;
	} else if (op == '?') break;

	}

}



Measured memory_bytes: 3076
#include <iostream>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0; i<n; ++i)

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int sum;
  int tt;

  if(a > b && a > c) {
    sum = a;
    tt = b + c;
  }else if(b > a && b > c) {
    sum = b;
    tt = a + c;
  }else {
    sum = c;
    tt = a + b;
  }

  rep(i, k) sum *= 2;

  sum += tt;

  cout << sum << endl;

  return 0;
}


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

int main( void )
{
  long long int N;
  cin >> N;

  long long int ans = 1;

  for( int i = 1; i <= N; i++ ) {
    ans = ( ans * i ) % 1000000007;
  }

  cout << ans << endl;
    
}

Measured memory_bytes: 3616
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	int a, b, k;
	cin >> a >> b >> k;
	if(a + k - 1 >= b - k + 1) {
		for(int i = a; i <= b; i++) cout << i << endl;
	}
	else {
		rep(i, k) cout << a + i << endl;
		rep(i, k) cout << b - k + 1 + i << endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

const int r[][6] = {
	{0, 2, 3, 4, 1, 5},
	{4, 1, 0, 3, 5, 2},
	{1, 5, 2, 0, 4, 3}
};
vector<vi> ds;
int cs, t[3][3], f[3][3], dice[3][3][3];
set<int> ans;

vi rot(int d, const vi &v){
	vi res;
	rep(i, 6) res.pb(v[r[d][i]]);
	return res;
}
void gen(set<vi> &s, const vi &v){
	if(s.count(v)) return;
	s.insert(v);
	rep(i, 3){
		vi nv = v;
		rep(j, 3){
			nv = rot(i, nv);
			gen(s, nv);
		}
	}
}
void rec(int x, int y, int z){
	if(z == 3){
		rec(x, y + 1, 0);
		return;
	}
	if(y == 3){
		rec(x + 1, 0, 0);
		return;
	}
	if(x >= 3){
		int tmp = 0;
		rep(i, 3) rep(j, 3){
			tmp += ds[dice[i][2][j]][2];
		}
		ans.insert(tmp);
		return;
	}
	//cerr<<x<<" "<<y<<" "<<z<<endl;
	
	rep(i, ds.size()){
		if(t[z][y] && ds[i][0] != t[z][y] || f[x][y] && ds[i][1] != f[x][y]) continue;
		bool ok = 1;
		rep(d, 6){
			const int dz[] = {0, 1, 0, -1, 0, 0};
			const int dy[] = {0, 0, 1, 0, -1, 0};
			const int dx[] = {-1, 0, 0, 0, 0, 1};
			
			int nx = x + dx[d], ny = y + dy[d], nz = z + dz[d];
			if(nx < 0 || ny < 0 || nz < 0 || nx >= 3 || ny >= 3 || nz >= 3) continue;
			if(dice[nx][ny][nz] < 0) continue;
			if(ds[dice[nx][ny][nz]][d] != ds[i][d]) ok = 0;
		}
		if(ok){
			dice[x][y][z] = i;
			rec(x, y, z + 1);
			dice[x][y][z] = -1;
		}
	}
}

int main(){
	set<vi> s;
	vi v;
	v.pb(1); v.pb(2); v.pb(3); v.pb(5); v.pb(4); v.pb(6);
	gen(s, v);
	ds = vector<vi>(all(s));
	
	cin >> cs;
	while(cs--){
		rep(i, 3) rep(j, 3) cin >> t[i][j];
		rep(i, 3) rep(j, 3) cin >> f[i][j];
		
		memset(dice, -1, sizeof(dice));
		ans.clear();
		rec(0, 0, 0);
		if(ans.empty()) cout << 0 << endl;
		else{
			bool f = 1;
			each(i, ans){
				if(f) f = 0;
				else cout << " ";
				cout << *i;
			}
			cout << endl;
		}
	}
	return 0;
}

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

using namespace std;

int main()
{
    long a,b,c,k,res=0,xa,xb,xc,k1,k2,k3;
    cin >> a >> b >> c >> k;
    xa = min(k,a);
    k1 = k - xa;
    xb = min(k1, b);
    k2 = k1 - xb;
    xc = min(k2, c);
    k3 = k2 - xc;
    res = xa*1 + xb*0 + xc*(-1);
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3612
# Problem: https://atcoder.jp/contests/abc047/tasks/abc047_b
# Python 3rd Try

import sys
# import pprint
# from collections import defaultdict
# import heapq,copy
# from collections import deque
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(WIDTH, HEIGHT, OPERATION):
    result = 0
    all_ope = len(OPERATION)
    up_max = HEIGHT
    left_min = 0
    right_max = WIDTH
    down_min = 0
    for j in range(0, all_ope, +1):
        each_ope = OPERATION[j]
        ope = each_ope[2]
        if ope == 1:
            if left_min < each_ope[0]:
                left_min = each_ope[0]
        if ope == 2:
            if each_ope[0] < right_max:
                right_max = each_ope[0]
        if ope == 3:
            if down_min < each_ope[1]:
                down_min = each_ope[1]
        if ope == 4:
            if each_ope[1] < up_max:
                up_max = each_ope[1]
    if ((left_min < right_max) and (down_min < up_max)):
        result = (right_max-left_min) * (up_max - down_min)
    return result


if __name__ == "__main__":

    W, H, N = MI()
    OPE = list()
    for _ in range(0, N, +1):
        OPE.append(LI())
    print("{}".format(solver(W, H, OPE)))


Measured memory_bytes: 9172
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
// #include "prettyprint.hpp"

int main() {
  long N, K;
  cin >> N >> K;
  int A[N];
  long sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }

  vector<long> divisors;
  for (int i = 1; i <= sqrt(sum); i++) {
    if (sum % i == 0) {
      divisors.push_back(i);

      if (i != sqrt(sum)) {
        divisors.push_back(sum / i);
      }
    }
  }

  sort(divisors.begin(), divisors.end());

  long max = 1;
  for (int i = 0; i < divisors.size(); i++) {
    long cur = divisors[i];

    long count = 0;
    int r[N];
    long sum = 0;
    for (int j = 0; j < N; j++) {
      r[j] = A[j] % cur;
      sum += r[j];
    }
    sort(r, r + N);

    // cout << "r[i] ";
    // for (int i = 0; i < N; i++) {
    //   cout << r[i] << " ";
    // }
    // cout << endl;

    if (sum < 0) {
      int c = -sum / cur;
      for (int i = 0; i < c; i++) {
        r[i] += cur;
      }
    } else {
      int c = sum / cur;
      for (int i = 0; i < c; i++) {
        r[N - 1 - i] -= cur;
      }
    }

    sort(r, r + N);

    // cout << "r[i] ";
    // for (int i = 0; i < N; i++) {
    //   cout << r[i] << " ";
    // }
    // cout << endl;

    for (int i = 0; i < N; i++) {
      if (r[i] >= 0) break;
      count += r[i];
    }

    count = -count;

    // cout << "cur " << cur << endl;
    // cout << "count " << count << endl;
    if (count <= K) {
      max = cur;
    }
  }

  cout << max << endl;

  return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    let s:Vec<char> = read::<String>().chars().collect();

    println!("{}", 700 + s.iter().filter(|&x| *x=='o').count()*100);

}


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

  const int MOD = 1000000007;

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

  //for
  #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }


int ans = MOD;

void dfs(int f, int e){

}

int main() {
int N;
cin >> N;
int mi = MOD, ma = 0, score = MOD;
REP(i, N){
    int a, b;
    cin >> a >> b;
    mi = min(mi, a);
    ma = max(ma, a);
    score = min(score, b);
}

int ans = mi + (ma - mi) + score;
print(ans);


}



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

int main()
{
    long long a,b,x,ans;
    while(cin>>a>>b>>x)
    {
        if(a%x==0)
        {
            ans=abs((a/x)-(b/x));
            ans=ans+1;
        }
        else
            ans=abs((a/x)-(b/x));

        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3640
def task(n):
    if n == 1:
        print(0)
        return

    primes = {}
    i = 2
    while i < 1000001 and i <= n:
        if n % i == 0:
            n = n // i
            if not i in primes:
                primes[i] = 0
            primes[i] += 1
        else:
            i += 1

    # print(primes)
    ans = 0

    if n > 1:
        ans = 1

    for prime in primes:
        e = 1
        count = primes[prime]
        while count >= e:
            count -= e
            e += 1
            ans += 1

    print(ans)


n = int(input())
task(n)


Measured memory_bytes: 62676
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <cmath>
using namespace std;
int main() {
  int ans = 1000000;
  string s, t;
  cin >> s >> t;
  for (int i=0; i<s.size()-t.size()+1; i++) {
    int count = 0;
    for (int j=0; j<t.size(); j++) {
      if (s[i+j]!=t[j]) count++;
    }
    ans = min(ans, count);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3232
#include <iostream>
#include <fstream>
#include <sstream>

#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <deque>
#include <string>

#include <algorithm>
#include <numeric>

#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>

#define pb push_back
#define pbk pop_back
#define mp make_pair
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define foreach(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define len(a) ((int) (a).size())

#ifdef CUTEBMAING
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

using namespace std;

typedef long long int64;
typedef long double ld;
typedef unsigned long long lint;

const int inf = (1 << 30) - 1;
const int64 linf = (1ll << 62) - 1;

int main() {
#ifdef XCODE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n; cin >> n;
    int c1 = 0, c2 = 0, c4 = 0;
    for (int i = 0; i < n; i++) {
    	int x; scanf("%d", &x);
    	if (x % 4 == 0) {
    		c4++;
    	} else if (x % 2 == 0) {
    		c2++;
    	} else {
    		c1++;
    	}
    }
    vector<int> a(n);
    int it = 0;
    while (c1 > 0) {
    	if (it >= n) {
    		puts("No");
    		return 0;
    	}
    	a[it++] = 1;
    	c1--;
    	if (it < n) {
    		a[it++] = 4;
    		c4--;
    	}
    }
    if (c4 >= 0) {
    	puts("Yes");
    } else {
    	puts("No");
    }
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#define N 26

typedef struct
{
  int par;         //親
  int left;
  int right;
  int sib;
}Binary;

int n,dep[N],hei[N];
Binary B[N];

void Depth(void);
void Print(void);
int Height(int);

int main()
{
  int i,id,l,r,root;
  scanf("%d",&n);
  for(i=0;i<n;i++) B[i].par = B[i].left = B[i].right = B[i].sib = -1;  //初期化

  for(i=0;i<n;i++)                      //n回ループ
  {
    scanf("%d%d%d",&id,&l,&r);     //id:節点,left:左の子の番号,right:右の子
    B[id].left = l;
    B[id].right = r;
    if(l!=-1)B[l].par = id;
    if(r!=-1)B[r].par = id;
    if(l!=-1)B[l].sib = B[id].right;           //deg
    if(r!=-1)B[r].sib = B[id].left;           //deg*/
  }
  for(i=0;i<n;i++)  if(B[i].par == -1) hei[i] = Height(i);
  Depth();
  Print();

  return 0;
}

void Depth(void)
{
  int i,j;
  for(i=0;i<n;i++)
  {
    j=i;
    while(B[j].par != -1)
    {
      dep[i]++;
      j = B[j].par;
    }
  }
}

void Print(void)
{
  int i,deg=0;
  for(i=0;i<n;i++)
  {
    deg=0;
    printf("node %d: ",i);
    printf("parent = %d, ",B[i].par);
    printf("sibling = %d, ",B[i].sib);
    if(B[i].left != -1)deg++;
    if(B[i].right != -1)deg++;
    printf("degree = %d, ",deg);
    printf("depth = %d, ",dep[i]);
    printf("height = %d, ",hei[i]);
    if(B[i].par == -1)printf("root\n");
    else if(hei[i] == 0)printf("leaf\n");
    else printf("internal node\n");
  }
}

int Height(int i)
{
  int hei1 = 0, hei2 = 0;
  if(B[i].left != -1) hei1= Height(B[i].left)+1;
  if(B[i].right != -1)hei2 = Height(B[i].right)+1;

  return hei[i] = hei1 > hei2 ? hei1 : hei2;
}



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

int main(){
  long long int n, k, q, i, p;
  cin>>n>>k>>q;
  long long int arr[n+1] = {0};

  for(i=0; i<q; i++){
    cin>>p;
    arr[p]++;
  }

  for(i=1; i<=n; i++){
    if(k-q+arr[i]>0)
      cout<<"Yes\n";
    else
      cout<<"No\n";
  }

  return 0;
}


Measured memory_bytes: 1408
def lcs_len(x, y):
    ly = len(y)
    tcsl = [0] * (ly + 1)
    for x_i in x:
        pre_tcsl = list(tcsl)
        for j in range(ly):
            if x_i == y[j]:
                tcsl[j] = pre_tcsl[j - 1] + 1
            elif tcsl[j] < tcsl[j - 1]:
                tcsl[j] = tcsl[j - 1]
    print(tcsl[j])


q = int(input())

for i in range(q):
    ax = input()
    ay = input()
    lcs_len(ax, ay)

Measured memory_bytes: 7772
n,y = map(int,input().split())
for i in range(n+1):
    for j in range(n+1):
        if i*10000+j*5000+(n-i-j)*1000==y and n-i-j>=0:
            print(i,j,n-i-j)
            exit()
print(-1,-1,-1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fi first
#define se second
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 5;
 
int n;
ll a[N], p[62];
 
void insert(ll x) {
    for(int i = 60; i >= 0; i--) {
        if(x >> i & 1) {
            if(!p[i]) {
                p[i] = x;
                break;
            }
            x ^= p[i];
        }
    }
}
 
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    ll all = 0;
    for(int i = 1; i <= n; i++) cin >> a[i], all ^= a[i];
    for(int i = 0; i <= 60; i++) {
        if(all >> i & 1) {
            for(int j = 1; j <= n; j++) {
                if(a[j] >> i & 1) a[j] -= (1ll << i);
            }
        }
    }
    for(int i = 1; i <= n; i++) insert(a[i]);
    ll ans = 0;
    for(int i = 60; i >= 0; i--) {
        if((p[i] ^ ans) > ans) ans = p[i] ^ ans;
    }
    cout << ans + (ans ^ all);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

struct mint {
    lint v;
    lint _mod;
    mint() : v(0) {}
    mint(signed v, lint _mod = mod) : v(v), _mod(_mod) {}
    mint(lint t, lint _mod = mod) : _mod(_mod) {
        v = t % _mod;
        if (v < 0)
            v += _mod;
    }

    mint pow(lint k) {
        mint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    static mint add_identity() { return mint(0); }
    static mint mul_identity() { return mint(1); }
    mint inv() { return pow(_mod - 2); }

    mint &operator+=(mint a) {
        v += a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator-=(mint a) {
        v += _mod - a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator*=(mint a) {
        v = v * a.v % _mod;
        return *this;
    }
    mint &operator/=(mint a) { return (*this) *= a.inv(); }

    mint operator+(mint a) const { return mint(v) += a; };
    mint operator-(mint a) const { return mint(v) -= a; };
    mint operator*(mint a) const { return mint(v) *= a; };
    mint operator/(mint a) const { return mint(v) /= a; };

    mint operator-() const { return v ? mint(_mod - v) : mint(v); }

    bool operator==(const mint a) const { return v == a.v; }
    bool operator!=(const mint a) const { return v != a.v; }
    bool operator<(const mint a) const { return v < a.v; }
};
ostream &operator<<(ostream &os, mint m) { return os << m.v; }

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, k;
    cin >> n >> k;
    mint ret = 0;
    for (lint i = k; i <= n + 1; ++i) {
        lint mini = (i - 1) * i / 2;
        lint maxi = (n + n + 1 - i) * i / 2;
        ret += maxi - mini + 1;
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 3652
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);

// ===

struct UnionFind {
    parent: Vec<usize>,
    rank: Vec<usize>
}

impl UnionFind {
    fn new(n: usize) -> Self {
        let mut parent = vec![0; n];
        for i in 0..n {
            parent[i] = i;
        }
        UnionFind { parent: parent, rank: vec![0; n] }
    }

    fn unite(&mut self, a: usize, b: usize) {
        let pa = self.find(a);
        let pb = self.find(b);
        if pa == pb {
            return;
        }

        let mut next_rank = 0;
        if self.rank[pa] <= self.rank[pb] {
            self.parent[pa] = pb;
            next_rank = max(self.rank[pb], self.rank[pa] + 1);
        } else {
            self.parent[pb] = pa;
            next_rank = self.rank[pa];
        }
        self.rank[pa] = next_rank;
        self.rank[pb] = next_rank;
    }

    fn find(&mut self, u: usize) -> usize {
        if self.parent[u] == u {
            return u;
        }
        let mut pu = self.parent[u];
        pu = self.find(pu);
        self.parent[u] = pu;
        return pu
    }
}

fn main() {
    let (n, m): (usize, usize) = read();
    let p: Vec<usize> = readnc::<usize>().iter().map(|u| u-1).collect();

    let mut uf = UnionFind::new(n);
    for i in 0..m {
        let (a, b): (usize, usize) = read();
        uf.unite(a-1, b-1);
    }

    let mut id_positions = vec![0; n];
    for i in 0..n {
        id_positions[i] = uf.find(i);
    }

    let mut ans = 0;
    for i in 0..n {
        if uf.find(i) == id_positions[p[i]] {
            ans += 1;
        }
    }

    println!("{}", ans);
}



Measured memory_bytes: 8444
#include <stdio.h>
#include<math.h>

int main()
{
	long N,walk,walkmini;
	scanf("%ld", &N);;
	walkmini = N-1;
		for (long i = 2; i <= sqrt(N); i++)
		{
			if (N%i== 0)
			{
				walk = (i - 1) + (N/i - 1);;
				if (walkmini > walk)
				{
					walkmini = walk;
				}
			}
		}
	printf("%ld", walkmini);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll N,l;
	cin >> N;
	vector<P> A(N);
	for(ll i = 0;i < N;i++){
		cin >> l;
		A[i].fs = l;
		A[i].sc = i;
 	}
	sort(ALL(A));

	for(ll i = 0;i < N;i++){
		cout << A[i].sc + 1;
		cout << ' ';
 	} 



	return 0;
}

Measured memory_bytes: 2432
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

bool f[7][7];
bool tmp[7][7];
int sum;
int xs, ys;
int w, h;

void check(int y, int x){
  REP(i, 4){
    int yy = y + _dy[i];
    int xx = x + _dx[i];
    if(ISIN(xx, yy, w, h) && tmp[yy][xx]){
      tmp[yy][xx] = false;
      check(yy, xx);
    }
  }
}

bool solve(int y, int x, int cnt){
  if(cnt != 2 && cnt != sum){
    if(abs(y - ys) + abs(x - xs) == 1)
      return false;
  }

  bool ret = false;
  f[y][x] = false;

  if(sum == cnt){
    if(abs(y - ys) + abs(x - xs) == 1)
      ret = true;
  }else{
    /* check */
    memcpy(tmp, f, sizeof(tmp));
    //REP(i, h) REP(j, w) tmp[i][j] = f[i][j];
    check(y, x);
    bool ok = true;
    REP(i, h) REP(j, w) if(tmp[i][j]) ok = false;

    if(ok){
      REP(i, 4){
        int yy = y + _dy[i];
        int xx = x + _dx[i];

        if(ISIN(xx, yy, w, h) && f[yy][xx]){
          if(solve(yy, xx, cnt+1)){
            ret = true;
            break;
          }
        }
      }
    }
  }

  f[y][x] = true;
  return ret;
}

int main(){
  while(true){
    w = getInt();
    h = getInt();

    bool ans = false;

    if(w + h == 0) break;

    xs = ys = -1;
    sum = 0;

    REP(i,h) REP(j,w){
      f[i][j] = getInt() == 0 ? true : false;
      if(f[i][j]) sum++;
      if(ys == -1 && f[i][j]){
        ys = i; xs = j;
      }
    }

    if(h == 7 && w == 7 && sum == 7 * 7) ans = false;
    else if(h == 7 && w == 7 && sum == 7 * 7 - 1){
      REP(i,h) REP(j,w) if(!f[i][j]){
        if((i + j) % 2 == 0) ans = true;
        else ans = false;
      }
    }
    else if(ys != -1) ans = solve(ys, xs, 1);

    puts(ans ? "Yes" : "No");
  }
  return 0;
}

Measured memory_bytes: 800
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    int n, L;
    cin >> n >> L;
    ll s = 0;
    for(int i = 1; i <= n; i++) {
        s += L + i - 1;
    }
    ll best_ss = 0;
    for(int i = 1; i <= n; i++) {
        ll ss = 0;
        for(int j = 1; j <= n; j++) {
            if(j != i) {
                ss += L + j - 1;
            }
        }
        if(abs(best_ss - s) > abs(ss - s)) {
            best_ss = ss;
        }
    }
    cout << best_ss << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << -1; return;}
#define yes {cout << "Yes"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

void solve() {
    int n; cin >> n;
    string s; cin >> s;
    loop(i, s.size())
        s[i] = (s[i] - 'A' + n) % 26 + 'A';
    cout << s;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3628
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod   998244353
#define PI 2*acos(0.0)
#define dbg(a) cout<<#a<<" ->->->-> "<<a<<"\n"
int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};

ll bigmod(ll x, ll p)
{
    ll res = 1;
    while(p)
    {
        if(p&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        p >>= 1;
    }
    return res;
}

//=============================================ASIFAZAD==============================================//


int32_t main()
{
    io;
    ull n, k;
    cin>>n>>k;
    if(n > k)
        n -= ((n-k)/k + 1)*k;
    cout<<min(n, k-n);
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
map <pair<ll, ll>, ll> dp;


ll solve(ll n, ll w, vector<ll> &wei, vector<ll> &val)
{
    if(w < 0)
        return (-1e10);
    if(n < 0)
        return 0;    

    if(dp.find({n, w}) != dp.end())
        return dp[{n, w}];    
    
    if(n)
        dp[{n, w}] = solve(n - 1, w, wei, val);    
    else
        dp[{n, w}] = 0;   

    if(w >= wei[n])
        dp[{n, w}] = max(dp[{n, w}], val[n] + solve(n - 1, w - wei[n], wei, val));

    return  dp[{n, w}];   
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, w;
    cin >> n >> w;
    vector <ll> wei(n), val(n);

    for(int i = 0; i < n; i++)
        cin >> wei[i] >> val[i];

    cout << solve(n - 1, w, wei, val) <<"\n";    
    return 0;
}


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

int main() {
	int N;
	cin >> N;
	int A[2][N];
	for(int i=0; i<N; i++){
		cin >> A[0][i];
	}
	for(int i=0; i<N; i++){
		cin >> A[1][i];
	}
	
	int ans=0;
	for(int i=0; i<N; i++){
		int sum=0;
		for(int j=0; j<=i; j++){
			sum+=A[0][j];
		}
		for(int j=i; j<N; j++){
			sum+=A[1][j];
		}
		
		ans=max(ans,sum);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main() {
  string S;
  cin >> S;
  for (size_t i = 0; i < S.size(); i++) {
    if (S[i] == '9') {
      S[i] = '1';
    } else if (S[i] == '1') {
      S[i] = '9';
    }
  }
  cout << S << endl;
  return 0;
}


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

using namespace std;


int a,b,c,d,e,f;
double m=-1;

double memo[60][6000];

double dfs(int s,int t){
  if(100*s+t+100*a<=f){
    double r;
    r=(double)100*t/(100*(s+a)+t);
    m=max(m,r);
    if(memo[s+a][t]==0){
      dfs(s+a,t);
    }
  }
  if(100*s+t+100*b<=f){
    double r;
    r=(double)100*t/(100*(s+b)+t);
    m=max(m,r);
    if(memo[s+b][t]==0){
      dfs(s+b,t);
    }
  }
  if(100*s+t+c<=f && t+c<=s*e){
    double r;
    r=(double)100*(t+c)/(100*s+t+c);
    m=max(m,r);
    if(memo[s][t+c]==0){
      dfs(s,t+c);
    }
  }
  if(100*s+t+d<=f && t+d<=s*e){
    double r;
    r=(double)100*(t+d)/(100*s+t+d);
    m=max(m,r);
    if(memo[s][t+d]==0){
      dfs(s,t+d);
    }
  }
  return memo[s][t]=m;
}

int p=-1;
int q=-1;
bool memoo[60][6000];
void dfss(int s,int t,double n){
  if(100*s+t+100*a<=f){
    double r;
    r=(double)100*t/(100*(s+a)+t);
    if(fabs(n - r) <= DBL_EPSILON * fmax(1, fmax(fabs(n), fabs(r)))){
      p=100*(s+a)+t;
      q=t;
    }
    if(!memoo[s+a][t]){
          memoo[s+a][t]=true;
          dfss(s+a,t,n);
    }
  }
  if(100*s+t+100*b<=f){
    double r;
    r=(double)100*t/(100*(s+b)+t);
    if(fabs(n - r) <= DBL_EPSILON * fmax(1, fmax(fabs(n), fabs(r)))){
      p=100*(s+b)+t;
      q=t;
    }
    if(!memoo[s+b][t]){
        memoo[s+b][t]=true;
        dfss(s+b,t,n);
    }
  }
  if(100*s+t+c<=f && t+c<=s*e){
    double r;
    r=(double)100*(t+c)/(100*s+t+c);
    if(fabs(n - r) <= DBL_EPSILON * fmax(1, fmax(fabs(n), fabs(r)))){
      p=100*s+t+c;
      q=t+c;
    }
    if(!memoo[s][t+c]){
        memoo[s][t+c]=true;
        dfss(s,t+c,n);
    }
  }
  if(100*s+t+d<=f && t+d<=s*e){
    double r;
    r=(double)100*(t+d)/(100*s+t+d);
    if(fabs(n - r) <= DBL_EPSILON * fmax(1, fmax(fabs(n), fabs(r)))){
      p=100*s+t+d;
      q=t+d;
    }
    if(!memoo[s][t+d]){
        memoo[s][t+d]=true;
        dfss(s,t+d,n);
    }
  }
}



int main(){
  cin >> a >> b >> c >> d >> e >> f;
  double n=dfs(0,0);
  dfss(0,0,n);
  cout << p << ' ' << q << endl;
}

Measured memory_bytes: 512
package main

import (
	"fmt"
	"sort"
	"strconv"
)

type Restaurant struct {
	S string
	P int
	Idx int
}

type Restaurants []Restaurant

func (r Restaurants) Len() int {
	return len(r)
}

func (r Restaurants) Less(i, j int) bool {
	if r[i].S != r[j].S {
		return r[i].S < r[j].S
	}
	return r[i].P > r[j].P
}

func (r Restaurants) Swap(i, j int) {
	r[i], r[j] = r[j], r[i]
}

func solve() {
	var ts string
	var N int
	fmt.Scan(&N)

	var restaurants Restaurants
	for i := 0; i < N; i++ {
		var s string
		fmt.Scan(&s, &ts)
		p, _ := strconv.Atoi(ts)
		restaurants = append(restaurants, Restaurant{s, p, i+1})
	}
	sort.Sort(restaurants)
	for _, r := range restaurants {
		fmt.Println(r.Idx)
	}
}

func main() {
	solve()
}


Measured memory_bytes: 512