akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,s,n) for(int i=s; i<n; i++)
#define ALL(x) x.begin(), x.end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;

bool visit[1<<24];
int c[24];
int key[24];
int n;

void dfs(int x) {
	visit[x] = true;
	for(int i=0; i<n; i++) {
		if(x & (1<<i)) continue;
		bool ok = true;
		for(int ii=0; ii<n; ii++) {
			if( !(x&(1<<ii)) && (key[i]&(1<<ii)) ) {
				ok = false;
				break;
			}
		}
		if(!ok) continue;

		for(int j=i+1; j<n; j++) {
			if(x & (1<<j)) continue;
			if(c[i] != c[j]) continue;
			if( visit[x | (1<<i) | (1<<j)] ) continue;
			ok = true;
			for(int jj=0; jj<n; jj++) {
				if( !(x&(1<<jj)) && (key[j]&(1<<jj)) ) {
					ok = false;
					break;
				}
			}
			if(ok) {
				dfs(x | (1<<i) | (1<<j));
			}
		}
	}
}

int main() {
	while(cin >> n, n) {
		memset(visit, 0, sizeof(visit));
		vi x(n), y(n), r(n);
		rep(i, n) {
			cin >> x[i] >> y[i] >> r[i] >> c[i];
		}
		memset(key, 0, sizeof(key));
		rep(i, n) {
			for(int j=i-1; j>=0; j--) {
				int d = (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]);
				if(d < (r[i]+r[j])*(r[i]+r[j])) {
					key[i] |= (1<<j);
				}
			}
		}

		dfs(0);

		int maxi = 0;
		rep(i, (1<<n)) {
			if(visit[i]) {
				int num = 0;
				rep(j, n) {
					if( i & (1<<j) ) num++;
				}
				maxi = max(maxi, num);
			}
		}
		cout << maxi << endl;
	}
	return 0;
}

Measured memory_bytes: 17588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 100000000000000
#define N 550

vector<vector<ll>> adj={{0,1},{1,0},{0,-1},{-1,0}};
vector<vector<ll>> seats(N,vector<ll>(N,-1));
vector<vector<ll>> soon(N,vector<ll>(N,0));
void dfs1(ll x, ll y);
void dfs2(ll x, ll y);

void dfs2(ll x, ll y){
    //cout << "dfs2" << x << " " << y << endl;
    REP(i,4){
        ll nex = x+adj[i][0];
        ll ney = y+adj[i][1];
        if (seats[nex][ney]>seats[x][y]&&soon[nex][ney]==0){
            dfs2(nex,ney);
        }
        else if (seats[nex][ney]>seats[x][y]&&soon[nex][ney]==1){
            dfs1(nex,ney);
        }
    }
    seats[x][y]--;
}

void dfs1(ll x, ll y){
    //cout << "dfs1" << x << " " << y << endl;
    seats[x][y]--;
    REP(i,4){
        ll nex = x+adj[i][0];
        ll ney = y+adj[i][1];
        if (soon[nex][ney]==1&&seats[nex][ney]==seats[x][y]+1){
            dfs1(nex,ney);
        }
        else if (seats[nex][ney]==seats[x][y]+1){
            dfs2(nex,ney);
        }
    }
}

int main(){
    ll n, p; cin >> n;
    ll ind=1;
    while(ind<=n+1-ind){
        FOR(i,ind,n+1-ind)FOR(j,ind,n+1-ind){
            seats[i][j]=ind-1;
        }
        ind++;
    }
    ll ans = 0;
    REP(i,n*n){
        cin >> p;
        ll h = (p-1)/n+1;
        ll w = (p-1)%n+1;
        ans+=seats[h][w];
        soon[h][w]=1;
        REP(j,4){
            ll adh = h+adj[j][0];
            ll adw = w+adj[j][1];
            //cout << h << " " << w << " " << adh << " " << adw << endl;
            if (soon[adh][adw]==1&&seats[adh][adw]>seats[h][w]){
                dfs1(adh,adw);
            }
            else if (soon[adh][adw]==0&&seats[adh][adw]>seats[h][w]){
                dfs2(adh,adw);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 27564
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	var N int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &N)

	hs := make([]int, N)
	for i := 0; i < N; i++ {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d", &hs[i])
	}
	ans := 0
	for h := 1; h < 101; h++ {
		isTarget := false
		for i := 0; i < N; i++ {
			if hs[i] >= h {
				if !isTarget {
					ans++
				}
				isTarget = true
			} else {
				isTarget = false
			}
		}
	}
	fmt.Println(ans)
}


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

int main(){
  int N;
  cin >> N;
  
  int m = 0;
  int input;
  int count = 0;
  
  for(int i = 0; i < N; i++){
    cin >> input;
    if(m <= input){
      m = input;
      count++;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a,b,c;
    int tmp;
    scanf("%d %d %d",&a,&b,&c);
    if(a>b){
        tmp=a;
        a=b;
        b=tmp;
    }if(b>c){
        tmp=b;
        b=c;
        c=tmp;
    }if(a>b){
        tmp=a;
        a=b;
        b=tmp;
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
int main(){
    ll n,m;cin >> n >>m;
    if(m==n-1)cout << 0 <<endl,exit(0);
    if((n-m-1)*2>n)cout << "Impossible" <<endl,exit(0);
    vl a(n);rep(i,n)cin >> a[i];
    UnionFind uf(n);
    rep(i,m){
        ll x,y;cin >> x >>y;
        if(!uf.same(x,y))uf.merge(x,y);
    }
    map<ll,vl> mp,sortmap;
    rep(i,n){
        mp[uf.root(i)].pb(a[i]);
    }
    for(auto p:mp){
        vl z=p.se;
        sort(all(z));
        sortmap[p.fi]=z;
    }
    vl use;
    ll ans=0;
    for(auto p:sortmap){
        ans+=p.se[0];
        repl(i,1,p.se.size()){
            use.pb(p.se[i]);
        }
    }
    sort(all(use));
    rep(i,n-m-2){
        ans+=use[i];
    }
    cout << ans <<endl;
}

Measured memory_bytes: 13696
#include<stdlib.h>
#include<iostream>
using namespace std;

int asc(const void *a, const void *b) {
	return *(int *)b - *(int *)a;
}

int main()
{
	int N,a[100];

	cin >> N;

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

	for(int j=i;j<100;j++)
	{
		a[j] = 0;
	}

/*
	cout << " " << endl;

	for(i=0;i<100;i++)
	{
		cout << a[i] << endl;
	}
*/
	qsort(a, sizeof(a) / sizeof(int), sizeof(int), asc);

	int sum_alice=0;
	int sum_bob=0;

	for(i=0;i<N;i+=2)
	{
		sum_alice+=a[i];
	}
	for(i=1;i<N;i+=2)
	{
		sum_bob+=a[i];
	}
/*
	cout << " " << endl;

	for(i=0;i<N;i++)
	{
		cout << a[i] << endl;
	}
*/
	cout << sum_alice-sum_bob << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<limits.h>
#include<float.h>

#define NUM 10

int main(){
	int n, m, k[NUM], s[NUM][NUM], p[NUM], ans = 0;
	scanf("%d%d\n", &n, &m);
	for(int i=0; i<m; i++){
		scanf("%d", &k[i]);
		for(int j=0; j<k[i]; j++){
			scanf("%d", &s[i][j]);
		}
	}
	for(int i=0; i<m; i++){
		scanf("%d", &p[i]);
	}
	for(int i=0; i<(1<<n); i++){
		int j;
		for(j=0; j<m; j++){
			int on = 0;
			for(int l=0; l<k[j]; l++){
				if((1 << (s[j][l] - 1)) & i) on++;
			}
			if(on % 2 != p[j]) break;
		}
		if(j == m) ans++;
	}
	printf("%d\n", ans);
	return 0;
}

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

using namespace std;

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

    int n;
    cin>>n;

    vector<int> arr(n);

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

    int q;
    cin>>q;

    while(q--)
    {
        int l,r;
        cin>>l>>r;

        reverse(arr.begin()+l,arr.begin()+r);
    }

    for(int i=0;i<arr.size();i++)
    {
        cout<<arr[i]<<((i==arr.size()-1)?'\n':' ');
    }


    return 0;
}



Measured memory_bytes: 3164
s = raw_input()
K = int(raw_input())
_s, _K = s[:], K
a = "abcdefghijklmnopqrstuvwxyz"
ai = a.index("a")
zi = a.index("z") 
si = [zi - a.index(c) + 1 if c != "a" else 0  for c in s]

for i, (c, ci) in enumerate(zip(s, si)):
    if K == 0:
        break
    if c == "a":
        continue
    if ci <= K:
        s = s[0:i] + "a" + s[i+1:]
        K = K - ci

K = K % len(a)
if K > 0:
    s = s[:-1] + a[a.index(s[-1]) + K]

print(s)

Measured memory_bytes: 11716
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int a=0,b=0;
  for(int i=0;i<s.size();i++){
    if(i%2==0){
      if(s[i]=='0'){
        a++;
      }
    }
    if(i%2==1){
      if(s[i]=='1'){
        a++;
      }
    }
  }
  for(int i=0;i<s.size();i++){
    if(i%2==0){
      if(s[i]=='1'){
        b++;
      }
    }
    if(i%2==1){
      if(s[i]=='0'){
        b++;
      }
    }
  }
  cout << min(a,b) << endl;
}

Measured memory_bytes: 512
///  author:Kissheart  ///
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
#define gcd(a,b) __gcd(a,b)
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );
void factor(ll n,ll a[MAX],ll b[MAX],ll &tot)
{
    ll temp,i,now;
    temp=(ll)((double)sqrt(n)+1);
    tot=0;
    now=n;
    for(ll i=2;i<=temp;i++)
    {
        if(now%i==0)
        {
            a[++tot]=i;
            b[tot]=0;
        }
        while(now%i==0)
        {
            ++b[tot];
            now/=i;
        }
    }
    if(now!=1)
    {
        a[++tot]=now;
        b[tot]=1;
    }
}
ll a[MAX],b[MAX];
ll n,tot,p;
int main()
{
    scanf("%lld%lld",&p,&n);
    factor(n,a,b,tot);
    //printf("%lld\n",tot);
    if(p==1)
    {
        printf("%lld\n",n);
        return 0;
    }

    ll ans=1;
    for(ll i=tot;i>=1;i--)
    {
        //printf("%lld %lld\n",b[i],p);
        for(ll j=1;j<=b[i]/p;j++)
            ans=ans*a[i];
    }
    printf("%lld\n",ans);
    return 0;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/21  Problem: ABC 059 A / Link: http://abc059.contest.atcoder.jp/tasks/abc059_a  ----- */


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

	string ans;
	FOR(i, 0, 3) {
		string s; cin >> s;
		ans +=toupper( s.front());
	}
	
	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5123;
const long long inf = 1ll<<60;
long long f[2][maxn][maxn], tmp[2][maxn];
long long a[maxn];
vector<int> e[maxn];
int sz[maxn];
void solve(int u, int v){
	f[0][u][0] = a[u] > 0 ? a[u] : inf;
	f[1][u][0] = a[u];
	sz[u] = 1;
	for(int to : e[u]) if(to != v) {
		solve(to, u);
		for(int i = 0; i < sz[u] + sz[to]; i++) tmp[0][i] = tmp[1][i] = inf;
		for(int pci = 0; pci <= 1; pci++){
			for(int i = 0; i < sz[u]; i++){
				for(int pcj = 0; pcj <= 1; pcj++){
					for(int j = 0; j < sz[to]; j++){
						int pcn = pci | pcj;
						long long comb = f[pci][u][i] + f[pcj][to][j];
						if(pcn){
							tmp[pcn][i + j] = min(tmp[pcn][i + j], comb);
						} else {
							tmp[pcn][i + j] = min(tmp[pcn][i + j], comb);
						}
						long long cut = f[pci][u][i];
						if(pcj && f[pcj][to][j] >= 0) cut = inf;
						if(!pcj && f[pcj][to][j] == inf) cut = inf;
						tmp[pci][i+j+1] = min(tmp[pci][i+j+1], cut);
					}
				}
			}
		}
		sz[u] += sz[to];
		for(int i = 0; i < sz[u]; i++) f[0][u][i] = tmp[0][i];
		for(int i = 0; i < sz[u]; i++) f[1][u][i] = tmp[1][i];
	}
}	
int main(){
	int n; cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 0; i < n - 1; i++){
		int u, v; cin >> u >> v;
		e[u].push_back(v);
		e[v].push_back(u);
	}
	solve(1, 0);
	int ans = n - 1;
	for(int i = n - 1; i >= 0; i--) if(f[0][1][i] < inf || f[1][1][i] < 0) ans = i;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 401536
#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;

int main()
{
    int m,d;
    cin>>m>>d;
    int ans=0;
    for(int i=1;i<=m;i++)
    {
        for(int j=10;j<=d;j++)
        {
            int d1=j%10;
            int t=floor(j/10.0);
            int d2=t%10;
            if(d1>=2&&d2>=2&&d1*d2==i)
            {
                ans++;
                //printf("%d %d %d\n",d2,d1,i);
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"

using ll = long long;
using P = pair<int, int>;

const long long MOD = 1e9+7;

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; }

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

vector<vector<int>> graph;

vector<int> color;

bool dfs(int v, int c) {
    color[v] = c;
    for (int to: graph[v]) {
        if (color[to] == c) return false;
        if (color[to] == 0 && !dfs(to, -c)) return false;
    }
    return true;
}

int main() {
    ll n, m;
    cin >> n >> m;
    graph.resize(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    
    color.resize(n);
    
    ll all = 0;
    if (dfs(0, 1)) {
        ll cnt = 0;
        rep(i, n) if (color[i] == 1) cnt++;
        all = cnt * (n - cnt);
    }
    else all = n * (n - 1) / 2;
    cout << all - m << endl;
}

Measured memory_bytes: 6528
import java.util.Scanner;
class Main{
  			public static void main(String args[]){
			Scanner sc = new Scanner(System.in);
			//数値kと文字列sを入力
			int k = sc.nextInt();
            String s = sc.next();
            //文字列sの文字数をaに代入
            int a = s.length();
              
            //aがk以下ならばそのままsを出力、
            //上回る場合はsをk文字分取り出して末尾に...をつけて出力
            if(k>=a){
              System.out.println(s);
            }else if(k<=a){
              System.out.println(s.substring(0,k)+"...");
            }
        }
	}

Measured memory_bytes: 38636
#include <stdio.h>
int main(){
	int s[51],n,r,p,c,koukan,i,j,k,ps[50],cs[50];
	
	while(1){
		for(i=1;i<51;i++){
			s[i]=i;
		}
			
		scanf("%d %d",&n,&r);
		if(n==0&&r==0)break;
		for(i=0;i<r;i++){
			scanf("%d %d",&p,&c);
			for(j=1,k=n-((p-1)+c)+1;j<=c;j++,k++){
				cs[j]=s[k];
			}
			for(j=1,k=n-p+2;k<=n;j++,k++){
				ps[j]=s[k];
			}
			for(j=n-((p-1)+c)+1,k=1;k<=p-1;j++,k++){
				s[j]=ps[k];
			}
			for(j=n-c+1,k=1;k<=c;j++,k++){
				s[j]=cs[k];
			}
		}
		printf("%d\n",s[n]);
	}
	return 0;
}

Measured memory_bytes: 600
fun main(args:Array<String>) {
    val s= readLine()!!.toString()
    val n=s.length
    val a=n/2
    val b=if (n%2==1) a+1
        else a
    var suma=0
    var sumb=0
    for (i in 0 until n){
        if (i%2==0){
            if (s[i]=='1') suma++
        }
        else{
            if (s[i]=='1') sumb++
        }
    }
    var ca=(b-suma)+sumb
    var cb=(a-sumb)+suma
    println(
        if (n==1) 0
        else Math.min(ca,cb)
    )
}


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

int main()
{
  int ar[3][3];
  unordered_map<int,pair<int,int>> m;
  for(int i=0;i<3;i++)
  {
    for(int j=0;j<3;j++)
    {
      cin >> ar[i][j];
      m[ar[i][j]] = {i,j};
    }
  }
  int n;
  cin >> n;
  bool v[3][3] = {false};
  for(int i=0;i<n;i++)
  {
    int x;
    cin >> x;
    if(m.count(x))
    {
      v[m[x].first][m[x].second] = true;
    }
  }
  bool hit = false;
  // row
    if(v[0][0] && v[0][1] && v[0][2]) hit = true;
    if(v[1][0] && v[1][1] && v[1][2]) hit = true;
    if(v[2][0] && v[2][1] && v[2][2]) hit = true;
  // col
    if(v[0][0] && v[1][0] && v[2][0]) hit = true;
    if(v[0][1] && v[1][1] && v[2][1]) hit = true;
    if(v[0][2] && v[1][2] && v[2][2]) hit = true;
  // diag
  	if(v[0][0] && v[1][1] && v[2][2]) hit = true;
  	if(v[2][0] && v[1][1] && v[0][2]) hit = true;
  
  if(hit) cout << "Yes";
  else cout << "No";
  
}
  


Measured memory_bytes: 256
def main():
    N = int(input())
    ans = ''

    while N != 0:
        if N % 2 != 0:
            N -= 1
            ans = '1' + ans
        else:
            ans = "0" + ans
        
        N = N // (-2)
        
    if ans == "":
        ans = "0"

    print(ans)

main()

Measured memory_bytes: 38256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
using namespace std;
typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e18;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N, T; cin >> N >> T;
  	vl cs(N, 0), ts(N, 0); REP(i, N) cin >> cs[i] >> ts[i];
  	ll ret = LINF;
  	REP(i, N){
      if(ts[i] <= T) ret = min(ret, cs[i]);
    }
    cout << ((ret == LINF) ? "TLE" : to_string(ret)) << endstr;
    return 0;
}


Measured memory_bytes: 764
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n,k = LI()
    r,s,p = LI()
    t = list(S())
    ans = 0

    for i in t[:k]:
        if i=="r":
            ans += p
        elif i == "s":
            ans += r
        elif i == "p":
            ans += s
    
    for i in range(k,n):
        if t[i]=="r":
            if t[i-k]=="r":
                t[i] = ""
            else:
                ans += p
        elif t[i]=="s":
            if t[i-k]=="s":
                t[i] = ""
            else:
                ans += r
        elif t[i]=="p":
            if t[i-k]=="p":
                t[i] = ""
            else:
                ans += s
        
    print(ans)
main()            


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

int main() {
    int N, Q, a, b, c;
    cin >> N >> Q;
    fenwick_tree<ll> fw(N);
    rep(i, N) {
        cin >> a;
        fw.add(i, a);
    }
    rep(i, Q) {
        cin >> a >> b >> c;
        if (a) {
            cout << fw.sum(b, c) << endl;
        } else {
            fw.add(b, c);
        }
    }
}

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

int main(){
    string str1, str2;
    cin >> str1 >> str2;
    if(str1[0] == str2[2] && str1[1] == str2[1] && str1[2] == str2[0]){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }

    return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  string s; cin >> s;
  if (s.size()==3) swap(s[0],s[2]);
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdbool.h>
#define min(a, b) ((a) > (b) ? (b) : (a))
#define ll long long

int n, m, a, b, c, d, e[1010][5555]={};

int main(){
    for(int i=0; i<1010; i++)for(int j=1; j<5555; j++)e[i][j] = 1001001001;
    //e[0][0] = 0;
    scanf("%d%d", &n, &m);
    for(int i=0; i<m; i++){
        for(int j=0;j<(1<<n);j++)e[i+1][j]=min(e[i][j], e[i+1][j]);
        scanf("%d%d", &a, &b);
        d = 0;
        for(int j=0; j<b; j++){
            scanf("%d", &c);
            d |= (1<<(c-1));
        }
        for(int j=0; j<(1<<n); j++){
            e[i+1][j|d] = min(min(e[i+1][j|d], e[i][j|d]), e[i][j] + a);
        }
    }
    int ans = 1001001001;
    for(int i=0; i<=m; i++)ans = min(ans, e[i][(1<<n)-1]);
    printf("%d\n", ans==1001001001?-1:ans);
    return 0;
}

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

using namespace std;

#define REP(i,m) for(ll i=0; i<m; i++)
#define FOR(i,n,m) for(ll i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main(){
	int n;
	cin >> n;
	P p[n];
	REP(i, n){
		ll a, b;
		cin >> a >> b;
		p[i] ={b, a};
	}
	sort(p, p+n);
	ll cur = 0;
	REP(i, n){
		cur += p[i].second;
		if(cur > p[i].first){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
} 


Measured memory_bytes: 3328
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (ll i = (ll)(a); i<(ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;
TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM K, TNM V> using umap = unordered_map<K, V>;
TPL<TNM K, TNM V> using uset = unordered_set<K, V>;

TPL<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
void bOUT(bool c, string s, string t) { OUT(c ? s : t); }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;

TPL<TNM V, TNM H> void resize(vector<V>& v, const H h) { v.resize(h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
TPL<TNM V, TNM T> void fill(V& x, const T& val) { x = val; }
TPL<TNM V, TNM T> void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }

int main(void) {
	int K;
	cin >> K;
	int o, e;
	o = e = 0;
	for (int i = 1; i <= K; ++i) {
		if (i % 2)o++;
		else e++;
	}
	cout << o * e << endl;
	return 0;
}

Measured memory_bytes: 256
// Problem : D - Teleporter
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...)
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int a[200000];
long long k;
bool visited[200000];
vector<int> cycle;

void dfs(int u, int d = 0) {
    if (d == k) {
        cout << u + 1 << "\n";
        exit(0);
    }
    if (visited[u]) {
        cycle.push_back(u);
        return;
    }
    
    visited[u] = true;
    dfs(a[u], d + 1);
    if (cycle.back() == a[u]) {
        cycle.push_back(u);
        if (cycle[0] == u) {
            reverse(cycle.begin(), cycle.end());
            cycle.pop_back();
            k -= d;
            cout << cycle[k % cycle.size()] + 1 << "\n";
            exit(0);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
    int n;
    cin >> n >> k;
    for (int i=0; i<n; i++) {
        cin >> a[i];
        a[i]--;
    }
    
    dfs(0);

    return 0;
}


Measured memory_bytes: 12104
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define pi  pair<int,int>
#define pl  pair<ll,ll>
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define N 200000+5
ll dp[N];

ll solve(ll a[],ll n,ll i)
{
    if(i>=n-1)
        return 0;
    if(dp[i]!=-1)    
    return dp[i];
    
    ll p=INT_MAX,q=INT_MAX;

    if(i<n-1)
    p=abs(a[i]-a[i+1]); 
     
    if(i<n-2)
    q=abs(a[i]-a[i+2]);

    dp[i]= (min(p+solve(a,n,i+1),q+solve(a,n,i+2))); 
    return dp[i];
}


int main() {
// #ifndef ONLINE_JUDGE
//     freopen("input.txt","r",stdin);
//     freopen("output.txt","w",stdout);
// #endif
    ll n,i;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    memset(dp,-1,sizeof(dp));
    ll ans=solve(a,n,0);
    cout<<ans;
    return 0;
    
}

Measured memory_bytes: 4992
#include<iostream>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && b == c) {
		cout << "1" << endl;
	}
	else if (a == b || a == c || b == c) {
		cout << "2" << endl;
	}
	else cout << "3" << endl;
}

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

using namespace std;

int main(){
  int a,b,c,d,p;
  int sum=0,sum_a=0,sum_b=0;

  cin>>a>>b>>c>>d>>p;

  sum_a=a*p;

  if(p<=c)
    sum_b=b;
  else if (p>c)
    sum_b=b+(p-c)*d;
  
  sum=min({sum_a,sum_b});

  cout<<sum<<endl;

  return 0;
}



Measured memory_bytes: 3084
#include <cstdlib>
#include <iostream>
#include <queue>
#include <tuple>

using namespace std;

int main()
{
	for(int t,n;cin>>t>>n,t|n;){
		int grid[121][121]={}; // -1:block,0:empty,1:visitable
		for(int i=0;i<n;i++){
			int x,y; cin>>x>>y;
			grid[60+y][60+x]=-1;
		}
		int x0,y0; cin>>x0>>y0;
		
		queue<tuple<int,int,int>> q;
		q.emplace(x0,y0,0);
		while(!q.empty()){
			auto c=q.front(); q.pop();
			int cx=get<0>(c),cy=get<1>(c),ct=get<2>(c);
			if(abs(cx)>60 || abs(cy)>60 || grid[60+cy][60+cx] || ct>t)
				continue;
			grid[60+cy][60+cx]=1;
			int dx[]={1,1,0,-1,-1,0},dy[]={0,1,1,0,-1,-1};
			for(int i=0;i<6;i++)
				q.emplace(cx+dx[i],cy+dy[i],ct+1);
		}
		
		int res=0;
		for(int i=0;i<121;i++)
			for(int j=0;j<121;j++)
				res+=grid[i][j]==1;
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1292
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

template <class abel> struct WUFT {
private:
	vector<int> par, rank;
	vector<abel> d_w;
	void init(int n = 1, abel su = 0) {
		par.resize(n); rank.resize(n); d_w.resize(n);
		for (int i = 0; i < n; i++)par[i] = i, rank[i] = 0, d_w[i] += su;
	}
	int root(int x) {
		if (par[x] == x)return x;
		else {
			int r = root(par[x]);
			d_w[x] += d_w[par[x]];
			return par[x] = r;
		}
	}
public:
	WUFT(int n = 1, abel su = 0) {
		init(n, su);
	}
	abel weight(int x) {
		root(x);
		return d_w[x];
	}
	bool issame(int x, int y) {
		return root(x) == root(y);
	}
	bool merge(int x, int y, abel w = 1) {
		w += weight(x); w -= weight(y);
		x = root(x); y = root(y);
		if (x == y)false;
		if (rank[x] < rank[y])swap(x, y), w = -w;
		if (rank[x] == rank[y])rank[x]++;
		par[y] = x;
		d_w[y] = w;
		return true;
	}
	abel diff(int x, int y) {
		return weight(y) - weight(x);
	}
};

int main() {
	int N, M;
	cin >> N >> M;
	WUFT<ll> uft(N+1);
	bool flag = true;
	for (int i = 0; i < M; i++) {
		int L, R, D;
		cin >> L >> R >> D;
		if (uft.issame(L, R)) {
			if (uft.weight(R) - uft.weight(L) != D) {
				flag = false;
			}
		}
		else {
			uft.merge(L, R, D);
		}
	}
	if (flag) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 1792
open System
open System.Collections.Generic

[<AutoOpen>]
module FastIO =
    let reader = new IO.StreamReader(new IO.BufferedStream(Console.OpenStandardInput()))
    let inline read f = reader.ReadLine() |> f
    let inline reada f = reader.ReadLine().Split() |> Array.map f
    let inline readChars() = read string |> Seq.toArray
    let inline readInts() = readChars() |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

    let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput()))
    let inline write (s: string) = writer.Write s
    let inline writeln (s: string) = writer.WriteLine s
    let inline puts (s: ^a) = string s |> writeln

    let inline ioDispose() =
        reader.Dispose()
        writer.Dispose()

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

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

let main() =
    let [| h; w |] = reada int64
    if h = 1L || w = 1L then
        puts 1
    else
        let hw = h * w
        let ans = (hw + 2L - 1L) / 2L
        puts ans
    ()

// -----------------------------------------------------------------------------------------------------
main()
ioDispose()
ioDispose()


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

long n,m;

int main(){
    cin >> n >> m;
    if(n == 1 && m == 1){
        cout << 1 << endl;
    }else if(n == 1 | m == 1){
        cout << n + m - 3 << endl;
    }else cout << (n - 2)*(m - 2) << endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

n = int(input())
n1 = n % 100
n2 = n % 10
if n2 == 3:
    print ('bon');
elif (n2 == 0 or n2 == 1 or n2 == 6 or n2 == 8):
    print ('pon');
else:
    print ('hon');

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

int main(){
    int n;
    cin >> n;
    int x=0;
    int t = 0;
    bool flg = false;
    while(t < n){
        t = x * 1.08;
        if(n == t){
            flg = true;
            break;
        }
        x++;
    }
    if(flg){
        cout << x << endl;
    }
    else{
        cout << ":(" << endl;
    }

}

Measured memory_bytes: 256
//#define local
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;
#ifdef local
#include "debug.cpp"
#else
#define debug(...)
#endif
const ll mod = 1e9+7;

ll powmod(ll x,ll n){
    if(n == 0)return 1;
    if(n%2)return x*powmod(x*x%mod,n/2)%mod;
    return powmod(x*x%mod,n/2)%mod;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout << fixed << setprecision(10);
    ll n; cin >> n;
    cout << (powmod(10,n) - 2*powmod(9,n) + powmod(8,n) + 3*mod)%mod << endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include<vector>
int main()
{
    int n;
    std::cin>>n;
    std::vector<int> a(n);
    std::vector<int> b(n);
    for(int i=0;i<n;i++){
        std::cin>>a[i]>>b[i];
        if(a[i]%b[i]==0){
            std::cout<<b[i]<<std::endl;
        }else{
            std::cout<<a[i]%b[i]<<std::endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1196
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <set>
#include <vector>
#include <queue>

using namespace std;

void preambule() {
  cin.tie(0);
  cout.precision(16);
  cout << fixed;
}

int n = 3;

vector<int> a(n);

void input() {
  for (auto&& i : a)
    cin >> i;
}

void solve1() {
  int ans = 1e9;

  do {
    for (int i = 0; i < n; ++i)
      ans = min(ans, a[i] + a[(i + 1) % n]);
  } while (next_permutation(a.begin(), a.end()));

  cout << ans;
}

int main() {
#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  preambule();
  input();
  solve1();
}


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

int main() {
	while(1){
		int n;
		cin >> n;
		if(n == 0)break;
		int card[201] = {0}, hoge;
		for(int i = 0; i < n; i++){
			cin >> hoge;
			card[hoge] = 1;
		}
		int now = 0, away[2] = {0};
		bool p = 1;
		while(1){
			if(away[0] == n || away[1] == n)break;
			for(int i = 1; i <= 2 * n; i++){
				if(card[i] == p){
					card[i] = -1;
					away[p]++;
					p = !p;
				}
			}
			p = !p;
		}
		cout << n - away[0] << endl;
		cout << n - away[1] << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

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

        int iResult = 0;
        for (int i = 1; i <= 5; i++) {
            if (0 == Integer.parseInt(sc.next())) {
                iResult = i;
            }
        }
        System.out.print(iResult);

    }
}


Measured memory_bytes: 35620
N = int(input())
l = [int(i) for i in input().split()]

count = 0
p = 10**9
sum_l = 0
for i in l:
    sum_l += abs(i)
    p = min(p,abs(i))
    if i < 0:
        count += 1

if count%2 == 0:
    print(sum_l)
else:
    print(sum_l-2*p)


Measured memory_bytes: 64880
# vim: fileencoding=utf-8


def main():
    n = int(input())
    string_list = [input() for i in range(n)]
    c1, c2, c3, c4 = 0, 0, 0, 0
    for s in string_list:
        if s == "AC":
            c1 += 1
        elif s == "WA":
            c2 += 1
        elif s == "TLE":
            c3 += 1
        elif s == "RE":
            c4 += 1
    print(f"AC x {c1}")
    print(f"WA x {c2}")
    print(f"TLE x {c3}")
    print(f"RE x {c4}")


if __name__ == "__main__":
    main()


Measured memory_bytes: 79208
#include<stdio.h>
     
    int main(void){
        char S[3],T[3];
        
        scanf("%s",S);
        scanf("%s",T);
     
        int i;
        int j=0;
     
        for(i=0;i<3;i++){
            if(S[i]==T[i])
               j++;
        }
     
        printf("%d",j);

        return 0;
    }

Measured memory_bytes: 128
import java.util.*;

@SuppressWarnings("unchecked")
public class Main {
	// public static void printArray(int[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	// public static<T> void printArrayT(T[] a) {
	// 	for (int i = 0; i < a.length; i++) {
	// 		System.out.print(a[i] + ", ");
	// 	}
	// 	System.out.println();
	// }

	public static String joinInt(int[] a, String separator) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < a.length; i++) {
			if (i > 0) {
				sb.append(separator);
			}
			sb.append(a[i]);
		}
		return sb.toString();		
	}

	static int[] nextIntArray(Scanner sc, int N) {
		int[] arr = new int[N];
		for (int i = 0; i < N; i++) {
			arr[i] = sc.nextInt();
		}
		return arr;
	}

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

		long min = Long.MAX_VALUE;
		for (long i = 1; i*i <= N; i++) {
			if (N%i == 0) {
				long j = N/i;
				min = Math.min(min, i + j - 2);
			}
		}
		System.out.println(min);
	}
}


Measured memory_bytes: 23764
#import<cstdio>
#define k 999
#define r(a) for(int i=0;i<a;i++)
#define s(a) scanf("%d",&a);
#define c(a,b) a=a<b?a:b
int w,n,m,d[k],p[k];main(){s(n)s(m)r(n)s(d[i])r(n)p[i]=1e9;r(m){s(w)r(n)c(p[i],p[i+1]+w*d[n-i-1]);}printf("%d\n",p[0]);}

Measured memory_bytes: 1036
#include <iostream>
#include <iomanip>
using namespace std;
int main( void )
{
	while ( !cin.eof() )
	{
		int a, b, c, d, e, f;
		cin >> a >> b >> c >> d >> e >> f;
		if ( cin.eof() )
			break;

		double delta = 1.0 / ( a*e - b*d );

		double x = (double)( e * c - b * f ) * delta;
		double y = (double)( a * f - d * c ) * delta;

		if ( x == 0.0 )
			x = 0.0;
		if ( y == 0.0 )
			y = 0.0;

		cout << setprecision(3) << setiosflags(ios::fixed) << x << " " << y << endl;

	}

	return 0;
}

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

typedef long long ll;
typedef long double ld;
// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// use merge(all(vec1), all(vec2), vec3.begin()) to merge 2 vectors, use vec3.resize(vec1.size() + vec2.size()) first
// ll pos = partition_point(all(vec), pred) - vec.begin(); bool pred(ll a){return a<3};
// print number in binary -> cout << bitset<20>(n);

const int N=200010;
ll n,m,k;
ll a[N],b[N];
int main(){
	cin>>n>>m>>k;
	for(int i=0;i<n;++i)cin>>a[i];
	for(int i=0;i<m;++i)cin>>b[i];
	int l=0,r=0,s=0,res=0;
	while(l<n&&a[l]+s<=k)s+=a[l++];
	while(r<m&&b[r]+s<=k)s+=b[r++];
	res=l+r;
	while(r<m&&l){
		--l;s-=a[l];
		while(r<m&&s+b[r]<=k)s+=b[r++];
		res=max(res,l+r);
	}
	cout<<res<<endl;
}


Measured memory_bytes: 6696
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  cout << (s[1]=='B' ? "ARC\n" : "ABC\n");
  return 0;
}


Measured memory_bytes: 3652
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <string>
#include <typeinfo>
#include <vector>
//#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

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

int main()
{
  int n, k;
  string s;
  cin >> n >> s >> k;
  char c = s.at(k - 1);
  rep(i,n){
    if(s.at(i)!=c){
      s.at(i) = '*';
    }
  }
  cout << s << endl;
  return 0;
}

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

int main() {
    int H,W;
    cin >> H >> W;
    string S[H+1];
    for(int i = 0; i < H; ++i) cin >> S[i];

    int num;
    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
            //each cell
            if(S[i][j] == '#') continue;

            //count
            num = 0;
            for(int k = i-1; k <= i+1; ++k){
                if(k < 0 || k >= H) continue; //out of area
                for(int l = j-1; l <= j+1; ++l){
                    if(l < 0 || l >= W) continue; //out of area
                    if(S[k][l] == '#') num++;
                }
            }
            S[i][j] = '0' + num;
        }
    }
    for(int i = 0; i < H; ++i) cout << S[i] << endl;
}

Measured memory_bytes: 256
// ggppgggpgg
// 0123456789
// 0112233445
// 0101010101
// 0011010101
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    char[] s = sc.next().toCharArray();
    int pnum = 0;
    int lose = 0;
    int lastLoseIdx = 0;
    for (int i = 0; i < s.length; i++) {
      if (i%2 == 1) {
        pnum++;
      }
      if (s[i] == 'p') {
        if (pnum > 0) {
          pnum--;
        } else {
          lose++;
          lastLoseIdx = i;
        }
      }
    }
    
    int win = 0;
    for (int i = lastLoseIdx; i < s.length && pnum > 0; i++) {
      if (s[i] == 'g') {
        win++;
        pnum--;
      }
    }
    
    System.out.println(win - lose);
  }
}

Measured memory_bytes: 27220
#include<iostream>
#include <algorithm>
#include<queue>
#include<cmath>
#include<math.h>
using namespace std;


int n, x, y;
int a[2005];
int main() 
{
	cin >> n >> x >> y;
	for (int i = 1; i <= n - 1; i++)
	{
		for (int j = i + 1; j <= n; j++)
			a[min(j - i, abs(i - x) + abs(j - y) + 1)]++;
	}
	for (int i = 1; i <= n - 1; i++)
		cout << a[i] << endl;
	return 0;
}



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

#define ll long long
#define all x.begin(),x.end()
#define MAX 200005

int main()
{
	ios_base::sync_with_stdio(NULL);
	cin.tie(0); cout.tie(0);

	char a;
	cin >> a;

	if(a=='z') cout << 'a' << endl;
	else cout << char(a+1) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <iostream>
#include <string>
#include <unordered_map>
#include <iterator>
using namespace std;
typedef long long ll;

int main()
{
    ll n;
    ll ans = 0;
    cin >> n;
    vector<string> s(n);
    unordered_map<string, ll> mp;

    for (int i = 0; i < n; i++)
    {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }

    for (ll i = 0; i < n; i++)
    {
        ans += mp[s[i]];
        mp[s[i]]++;
    }

    cout << ans << endl;
}


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

int main(){
    int a,b;
    cin >> a >> b;
    int result = 0;
    for(int i = a; i<=b; ++i){
        if(i%10 == i/10000%10 && i/10%10 == i/1000%10) ++result;
    }
    cout << result << endl; return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <stack>
#include <utility>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define FST first
#define SEC second

typedef pair <int,int> pxy;

int dfs(int map[][50],int w,int h){
  int dd[10]={0, 1, 1, 1, 0, -1, -1, -1, 0, 1};
  stack <pxy> s;
  int num=0;
  rep(y,h){
    rep(x,w){
      if(map[x][y]==1){
	s.push(pxy(x,y));
	while(!s.empty()){
	  int cx=s.top().FST,cy=s.top().SEC;
	  s.pop();
	  map[cx][cy]=0;
	  rep(r,8){
	    int nx=cx+dd[r],ny=cy+dd[r+2];
	    if(nx<0||w<=nx||ny<0||h<=ny||map[nx][ny]==0) continue;
	    s.push(pxy(nx,ny));
	  }
	}
	num++;
      }
    }
  }
  return num;
}

int main() {
  for(;;){
    int w,h,x,y;
    scanf("%d %d",&w,&h);
    int map[50][50];
    if(w==0&&h==0) break;
    rep(i,h){
      rep(j,w){
	cin >> map[j][i];
      }
    }
    cout << dfs(map,w,h) << endl;
  } 
}

Measured memory_bytes: 1332