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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);

int main() {
	cin.sync_with_stdio(false);
	ll N, A, B;
	cin >> N >> A >> B;
	if (N<A + B - 1 || N>A*B)cout << -1 << endl;
	else {
		ll cnt = N - A - B + 1;
		vector<ll>p;
		ll num = A*B;
		rep(i, A) p.push_back(num - (A - 1 - i));
		num -= A;
		while (num-A+1>0) {
			rep(i, A) {
				if (i ==0 )p.push_back(num - (A - 1 - i));
				else {
					if (cnt == 0)break;
					p.push_back(num - (A - 1 - i));
					cnt--;
				}
			}
			num -= A;
		}
		vector<ll>tmp = p;
		sort(tmp.begin(), tmp.end());
		map<ll, ll>mp;
		rep(i, tmp.size()) {
			mp[tmp[i]] = i + 1;
		}
		rep(i, p.size()) {
			cout << mp[p[i]];
			if (i != p.size() - 1)cout << " ";
			else cout << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 26732
#include <bits/stdc++.h>
#define ll long long
#define ii pair<int, int>
#define ip pair<int, ii>
using namespace std;
const int N = 1e5 + 7, M = 3 + 7;
const int mod = 1000, inf = 1e7 + 7;


int main()
{

    int n;
    cin >> n;

    int d, x;
    cin >> d >> x;

    int cnt = 0;
    for(int i=0; i<n; i++)
    {
        int tmp;
        cin >> tmp;
        cnt += (d-1)/tmp;

    }
    cout << cnt + x + n << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
#define inc(i,j,k) for(re int i=j;i<=k;i++)
#define ll long long
using namespace std; 
const int N=4005;
const int mod=924844033;
inline int read(){
	int x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while('0'<=ch&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;
}
int n,k,cnt,f[N][N][2],a[N];
ll fac[N],ans;
int main(){
	n=read(),k=read();
	fac[0]=1;inc(i,1,n) fac[i]=fac[i-1]*i%mod;
	inc(i,1,k){
		for(re int j=i;j<=n;j+=k) a[++cnt]=j;
		for(re int j=i;j<=n;j+=k) a[++cnt]=j; 
	} 
	a[0]=-n;
	f[1][0][0]=1;
	inc(i,2,(n<<1)){
		inc(j,0,i/2){
			f[i][j][0]=(f[i-1][j][0]+f[i-1][j][1])%mod;
			if(j>0&&a[i]-a[i-1]==k) f[i][j][1]=f[i-1][j-1][0];
		}
	}
	inc(i,0,n){
		ll tmp=(f[n<<1][i][0]+f[n<<1][i][1])%mod;
		tmp=tmp*fac[n-i]%mod;
		(ans+=((i&1)?mod-tmp:tmp))%=mod; 
	}
	printf("%lld",ans);
}

Measured memory_bytes: 123648
#include<stdio.h>

int n,cnt=0;
void sort(int a[],int g)
{
	int i,j,v;
	for(i=g+1;i<n+1;i++)
	{
		v=a[i];
		j=i-g;
		while(j>=1&&a[j]>v)
		{
			a[j+g]=a[j];
			j-=g;
			cnt++;
		}
		a[j+g]=v;
	}
}



int main()
{
	int i,head=1;
	int G[500];
	
	scanf("%d",&n);
	int A[n];
	G[1]=1;
	
	for(i=1;i<n+1;i++)
	{
		scanf("%d",&A[i]);
	}
	
	while(G[head]*3+1<n)
	{
		head++;
	G[head]=G[head-1]*3+1;
	}
	for(i=head;i>=1;i--)
	{
		sort(A,G[i]);
	}
	printf("%d\n",head);
	for(i=head;i>=1;i--)
	{
		printf("%d ",G[i]);
	}
	printf("\n");
	printf("%d\n",cnt);
	for(i=1;i<=n;i++)
	{
		printf("%d\n",A[i]);
	}
	return 0;
}


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

int main() {
  int X, ans;
  cin >> X;
  vector<int> V(1000001, 1);
  for (int i=2; i<=1000000; i++) {
    if (V[i]) {
      if (i>=X) {
        ans = i;
        break;
      }
      else {
        for (int j=i; j<=1000000; j+=i) {
          V[j]=0;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 7208
#include <iostream>
#include <vector>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
#define rep2(i, N, i_f) for(int (i) = (i_f); (i) < (N); (i) ++)
#define rep3(i, N, i_f, sp) for(int (i) = (i_f); (i) < (N); (i) += (sp))
#define rrep(i, N) for(int (i) = (N) ; (i) >= 0; (i) --)

using namespace std;

int D, G;
int d_max = 10;

int p[10];
int c[10];

int main(void){
    cin >> D >> G;
    rep(i, D){
        cin >> p[i] >> c[i];
    }

    int ans = 1e3;
    rep(i, (1 << D)){
        int val = 0;
        int num = 0;
        int remain_max = 0;
        rep(j, D){
            if((1 << j) & i){
                num += p[j];
                val += 100 * (j + 1) * p[j] + c[j];
            }
            else {
                remain_max = j;
            }
        }
        int dnm = 100 * (remain_max + 1);
        int tmp = (G - val + dnm - 1) / dnm ;  
        if(tmp >= p[remain_max]){
            continue;
        }else if(tmp > 0){
            num += tmp;
        }
        ans = min(num, ans);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

      int n = Integer.parseInt(sc.next());

      int[] v = new int[n];
      for(int i=0;i<n;i++){
        v[i] = Integer.parseInt(sc.next());
      }
      int[] c = new int[n];
      for(int i=0;i<n;i++){
        c[i] = Integer.parseInt(sc.next());
      }

      int ans = 0;

      int[] vc = new int[n];
      for(int i=0;i<n;i++){
        vc[i] = v[i] - c[i];
        if(vc[i]>0){
          ans+=vc[i];
        }
      }

      System.out.println(ans);

    }
}


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

int p[200000];
vector<int>E[200000];

class Scc{
	vector<int>vs;
	vector<bool>used;
	vector<vector<int>>E,G;
public:
	vector<int>cmp;
	int n;
	Scc(int N){
		n=N;
		E.resize(n);
		G.resize(n);
		cmp.resize(n);
	}
private:
	void dfs(int v){
		used[v]=true;
		for(auto u:E[v]){
			if(!used[u])dfs(u);
		}
		vs.push_back(v);
	}
	void rdfs(int v,int k){
		used[v]=true;
		cmp[v]=k;
		for(auto u:G[v]){
			if(!used[u])rdfs(u,k);
		}
	}
public:
	void add_edge(int a,int b){
		E[a].push_back(b);
		G[b].push_back(a);
	}
	int scc(){
		used.assign(n,0);
		vs.clear();
		for(int v=0;v<n;v++){
			if(!used[v])dfs(v);
		}
		used.assign(n,0);
		int k=0;
		for(int i=vs.size()-1;i>=0;i--){
			if(!used[vs[i]])rdfs(vs[i],k++);
		}
		return k;
	}
};
int grundy[200000],grundy2[200000],g[200000];
bool namo[200000];

int dfs(int v){
	set<int>se;
	for(int u:E[v]){
		if(!namo[u])se.insert(dfs(u));
	}
	while(se.count(grundy[v]))grundy[v]++;
	if(namo[v]){
		grundy2[v]=grundy[v]+1;
		while(se.count(grundy2[v]))grundy2[v]++;
	}
	return grundy[v];
}

int cnt[200000];
int main(){
	int n;scanf("%d",&n);
	Scc scc(n);
	rep(i,n){
		scanf("%d",&p[i]);p[i]--;
		scc.add_edge(p[i],i);
		E[p[i]].push_back(i);
	}
	scc.scc();
	rep(i,n){
		cnt[scc.cmp[i]]++;
	}
	int a=max_element(cnt,cnt+n)-cnt;
	rep(i,n){
		if(scc.cmp[i]==a){
			namo[i]=true;
		}
	}
	rep(i,n){
		if(namo[i])dfs(i);
	}
	rep(i,n){
		if(scc.cmp[i]!=a)continue;
		g[i]=grundy[i];
		int v=i;
		do{
			for(int u:E[v]){
				if(scc.cmp[u]==a){
					if(g[v]==grundy[u])g[u]=grundy2[u];
					else g[u]=grundy[u];
					v=u;
					break;
				}
			}
		}while(v!=i);
		if(g[i]==grundy[i]){puts("POSSIBLE");return 0;}
		g[i]=grundy2[i];
		v=i;
		do{
			for(int u:E[v]){
				if(scc.cmp[u]==a){
					if(g[v]==grundy[u])g[u]=grundy2[u];
					else g[u]=grundy[u];
					v=u;
					break;
				}
			}
		}while(v!=i);
		if(g[i]==grundy2[i]){puts("POSSIBLE");return 0;}
		puts("IMPOSSIBLE");return 0;
	}
}

Measured memory_bytes: 39924
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
const ll mo = 998244353;
ll mypow(ll a, ll b)
{
  ll res = 1;
  a %= mo;
  while (b)
  {
    if (b & 1)
      res = res * a % mo;
    a = a * a % mo;
    b >>= 1;
  }
  return res;
}
int main()
{
ll n , m ;
cin >> n >> m ;
vector<vector<ll>> v(n, vector<ll>(m,0) );
rep(i,n)rep(j,m)cin >> v[i][j];
vector<bool>see(m,1);
rep(j,m){
  bool a=0;
  ll ind=0;
  rep(i,n){
    if(v[i][j]&&a==0&&see[i]){a=1;ind=i;}
    else if(v[i][j]&&a){
      rep(k,m){
        v[i][k]=(v[i][k]+v[ind][k])%2;
      }
    }
  }
  if(a)see[ind]=0;
}
ll c=0;
rep(i,n){
  ll t=0;
  rep(j,m)t+=v[i][j];
  if(t==0)c++;
}
auto modmul = [](auto... modx) {
  ll res = 1;
  for (auto modx_ : {modx...})
  {
    res *= modx_;
    res %= mo;
  }
  return res;
};
ans=modmul(mypow(2,m-1),mypow(2,n)-mypow(2,c)+mo);
cout << ans << endl;
return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

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

void Main() {
    i64 A;
    string B;
    cin >> A >> B;
    i64 C = (B[0] - '0') * 100 + (B[2] - '0') * 10 + (B[3] - '0');
    string ans = to_string(A * C);
    if (ans.size() < 3) {
        cout << "0" << endl;
    } else {
        for (u32 i = 0; i < ans.size() - 2; i++) {
            cout << ans[i];
        }
        cout << endl;
    }
}


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

int main(){
int heights[10];


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

	sort(heights , heights + 10);

	cout << heights[9] << endl << heights[8] << endl << heights[7] << endl;

return 0;
}

Measured memory_bytes: 1176
//Graph
#include <stdio.h>
int Adj[101][101],n;

void Initialization(){
  int i,j;
  for(i=1;i<=n;i++)
    for(j=1;j<=n;j++)
      Adj[i][j]=0;
}
void Print(){
  int i,j;
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      printf("%d",Adj[i][j]);
      if(j!=n)printf(" ");
    }
    printf("\n");
  }
}
int main(){
  int i,j,element,number,key;
  scanf("%d",&n);
  Initialization();

  for(i=0;i<n;i++){
    scanf("%d%d",&element,&number);
    for(j=0;j<number;j++){
      scanf("%d",&key);
      Adj[element][key]=1;
    }
  }

  Print();
  return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
struct dat{int a,b,c;};
struct edge{int to,cost;};
int d[3030],n,m,k;
vector<edge>G[3030];
void dijkstra(int s){
	d[s]=0;
	priority_queue<P,vector<P>,greater<P> >Q;
	Q.push(MP(0,s));
	while(!Q.empty()){
		P p=Q.top();Q.pop();
		int v=p.second;
		if(d[v]<p.first)continue;
		REP(i,G[v].size()){
			int to=G[v][i].to,cost=G[v][i].cost;
			if(d[to]>d[v]+cost){
				d[to]=d[v]+cost;
				Q.push(MP(d[to],to));
			}
		}
	}
}
int main(){
	REP(i,3030)d[i]=INF;
	cin>>n>>m>>k;
	vector<dat>road;
	REP(i,m){
		int a,b,c;
		cin>>a>>b>>c;a--;b--;
		road.PB((dat){a,b,c});
		G[a].PB((edge){b,c});
		G[b].PB((edge){a,c});
	}
	REP(i,k){
		int s;
		cin>>s;s--;
		dijkstra(s);
	}
	int ans=0;
	REP(i,road.size()){
		dat v=road[i];
		ans=max(ans,(d[v.a]+d[v.b]+v.c+1)/2);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 5260
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
const int mod=1e9+7;
const int N=1e5+3;
int f[N];int inv[N];
int modp(int a,int b)
{
	if(b==0)return 1;
	int u=modp(a,b/2);
	u=(u*u)%mod;
	if(b&1)return (a*u)%mod;
	return u;
}
int ncr(int n,int r)
{
	if(n<r)return 0;
	int res=(f[n]*inv[r])%mod;
	res*=inv[n-r];res%=mod;
	return res;
}
int32_t main()
{
	f[0]=1;
	int n=in();
	for(int i=1;i<N;i++)
	{
		f[i]=(i*f[i-1])%mod;
	}
	inv[N-1]=modp(f[N-1],mod-2);
	for(int i=N-2;i>=0;i--)inv[i]=((i+1)*inv[i+1])%mod;
	vector<int> a(n+1);
	trav(i,a)i=in();
	int num=accumulate(all(a),0LL)-(n*(n+1))/2;
	//cout<<num;
	vector<int> id;
	for(int i=0;i<=n;i++){if(a[i]==num)id.push_back(i);}
	int d=id[1]-id[0];
	//cout<<d;
	int ans;
	//cout<<ncr(4,2)<<" "<<ncr(5,2);
	
	
	for(int i=1;i<=n+1;i++)
	{
		ans=ncr(n+1,i)-ncr(n-d,i-1);
		ans+=mod;ans%=mod;
		cout<<ans<<"\n";
	}
	
	
	
	
	
}

Measured memory_bytes: 5596
def factorize(n):
    fct=[]
    b,e=2,0
    while b*b<=n:
        while n%b==0:
            n=n//b
            e=e+1
        if e>0:
            fct.append((b,e))
        b,e=b+1,0
    if n>1:
        fct.append((n,1))
    return fct
a=0
for i,j in factorize(int(input())):
    a+=int((-1+pow(1+8*j,0.5))/2)
print(a)

Measured memory_bytes: 9476
N = int(input())
A = [int(i) for i in input().split()]
def printA():
    for i in range(0, N-1):
            print(A[i], '', end='')
    print(A[N-1])

for i in range(0,N):
    v = A[i]
    for j in range(i,-1,-1):
        if A[j-1] <= v or j == 0:
            A[j+1:i+1] = A[j:i]
            A[j] = v
            break
    printA()


Measured memory_bytes: 6312
using System;
using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
class P
{
    static void Main()
    {
        int[] abc = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine(abc.Sum() >= abc[2] * 2 ? "Yes" : "No");
    }

}

Measured memory_bytes: 13396
import java.io.*;

class Main{
	private static void sort(int[] a){
		for(int i = 0;i<a.length-1;i++){
			for(int j = a.length-1;j > i;j--){
				if(a[j] > a[j-1]){
					int t = a[j];
					a[j] = a[j-1];
					a[j-1] = t;
				}
			}
		}
	}
	private static void print_hill(int[] a){
		for(int i = 0;i<3;i++){
			System.out.println(a[i]);
		}
	}
		public static void main(String args[]) throws IOException{
			int hills[] = new int[10];
			InputStreamReader inp = new InputStreamReader(System.in);
			BufferedReader bre = new BufferedReader(inp);
			int n;
			for(int i = 0;i<10;i++){
				String num = bre.readLine();
				n = Integer.parseInt(num);
				hills[i] = n;
			}
			sort(hills);
			print_hill(hills);
	}
}

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

int main() {
  int n, k, ans = 1;

  cin >> n >> k;

  for (int i = 0; i < n; i++) {
    if (ans < k)
      ans *= 2;
    else
      ans += k;
  }

  cout << ans;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
using namespace std;
int a,b,c[110000];
pair<int,int> d[110000];
signed main()
{
	cin>>a>>b;
	b+=a*3;
	cout<<b/2;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n - 1);
  rep(i, n) {
    int an;
    cin >> an;
    an--;
    a[i] = an;
  }
  rep(i, n) cin >> b[i];
  rep(i, n - 1) cin >> c[i];

  int ans = 0;
  rep(i, n) {
    ans += b[a[i]];
    if (i == 0) continue;
    if (a[i - 1] + 1 == a[i]) ans += c[a[i - 1]];
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<iostream>

using namespace std;

int main(){
  int n;
  cin >> n;
  int a = n % 28;
  if( a == 1|| a == 2 || a == 3 || a == 5 || a== 6|| a == 9 || a == 10 || a == 13 || a == 17 ) cout << "No" << endl;
  else cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<iomanip>

#define INF 1<<29

using namespace std;

//普通に全探索で行ける

int main(void) {
	int x;
	cin >> x;
	int ans = 1;
	for (int i = 2; i <= x; i++) {
		int power = i * i;
		for (int p=2;; p++) {
			if (power > x) {
				break;
			}
			ans = max(ans, power);
			power *= i;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
def main():
    n,m,c=L()
    b=L()
    a=[]
    for i in range(n):
        ai=L()
        a.append(ai)
    sum=0
    ans=0
    for i in range(n):
        sum=0
        for j in range(m):
            sum+=a[i][j]*b[j]
        sum+=c
        if sum>0: ans+=1
    print(ans)
    

if __name__ == '__main__':
    main()

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

int main(){
    int n;
    cin >> n;
    map<ll,int> mp;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    ll x = -1,y = 0;
    sort(a.rbegin(),a.rend());
    rep(i,n-1){
        if(a[i] != a[i+1]) continue;
        if(x == -1){
            x = a[i];
            i++;
        }
        else{
            y = a[i];
            break;
        }
    }
    ll ans = x*y;
    cout << ans << endl;
}

Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int[] bk = new int[N];
		int[] fr = new int[N];
		var UF = new UnionFind(N);
		for(int i=0;i<M;i++){
			UF.Unite(A[i], B[i]);
			fr[A[i]]++;
			fr[B[i]]++;
		}
		
		for(int i=0;i<K;i++){
			if(UF.United(C[i], D[i])){
				bk[C[i]]++;
				bk[D[i]]++;
			}
		}
		
		int[] ans = new int[N];
		for(int i=0;i<N;i++){
			int tot = UF.MemCnt(i);
			tot -= fr[i];
			tot -= bk[i];
			ans[i] = tot - 1;
		}
		
		Console.WriteLine(String.Join(" ",ans));
		
		
		
	}
	int N, M, K;
	int[] A,B;
	int[] C,D;
	public Sol(){
		var d = ria();
		N = d[0]; M = d[1]; K = d[2];
		A = new int[M];
		B = new int[M];
		for(int i=0;i<M;i++){
			d = ria();
			A[i] = d[0] - 1;
			B[i] = d[1] - 1; 
		}
		C = new int[K];
		D = new int[K];
		for(int i=0;i<K;i++){
			d = ria();
			C[i] = d[0] - 1;
			D[i] = d[1] - 1;
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}

class UnionFind{
	
	int[] parent;
	int[] mem;
	int compo;
	int N;
	public UnionFind(int n_){
		N = n_;
		parent = new int[N];
		mem = new int[N];
		for(int i = 0; i < N; i++){
			parent[i] = i;
			mem[i] = 1;
		}
		compo = N;
	}
	
	public int Parent(int a){
		if(parent[a] == a) return a;
		return parent[a] = Parent(parent[a]);
	}
	
	public bool United(int a, int b){
		return Parent(a) == Parent(b);
	}
	
	public bool Unite(int a, int b){
		a = Parent(a); b = Parent(b);
		if(a == b) return false;
		if(mem[a] > mem[b]){var t = a; a = b; b = t;}
		parent[a] = b;
		mem[b] += mem[a];
		compo -= 1;
		return true;
	}
	
	public bool IsRoot(int x){
		return x == parent[x];
	}
	public int MemCnt(int x){
		return mem[Parent(x)];
	}
	
	public void Dump(){
		Console.WriteLine(String.Join(" ", parent));
	}
	
	public int Compo{
		get{
			return compo;
		}
	}
	
}


Measured memory_bytes: 22816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 9;
inline int read()
{
    int data = 0, f = 1;
    char ch = getchar();
    while (!isdigit(ch))
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (isdigit(ch))
    {
        data = (data << 3) + (data << 1) + ch - '0';
        ch = getchar();
    }
    return f * data;
}
vector<int> edge[maxn];
int dis[maxn], ans;
bool vis[maxn];
void dfs(int x)
{
    if (vis[x])
        return;
    vis[x] = true;
    for (int i = 0; i < edge[x].size(); ++i)
    {
        dfs(edge[x][i]);
        dis[x] = max(dis[x], dis[edge[x][i]] + 1);
    }
    ans = max(ans, dis[x]);
}
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("data.txt","w",stdout);
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(0);
    int n = read(), m = read();
    while (m--)
    {
        int x = read(), y = read();
        edge[x].emplace_back(y);
    }
    for (int i = 1; i <= n; ++i)
        dfs(i);
    cout << ans << '\n';
    //fclose(stdin);
    //fclose(stdout);
    return 0;
}

Measured memory_bytes: 11532
import random

class Dice:
    def __init__(self):
        self.u = 1
        self.s = 2
        self.e = 3
        self.w = 4
        self.n = 5
        self.d = 6
        self.dic = {"W":0, "S":1, "E":2, "N":3}

    def __init__(self, u, s, e, w, n, d):
        self.u = u
        self.s = s
        self.e = e
        self.w = w
        self.n = n
        self.d = d
        self.dic = {"W":0, "S":1, "E":2, "N":3}

    def rot(self, way):
        if isinstance(way, str):
            way = self.dic[way]

        if way == 0:
            c = self.u
            self.u = self.e
            self.e = self.d
            self.d = self.w
            self.w = c

        elif way == 1:
            c = self.u
            self.u = self.n
            self.n = self.d
            self.d = self.s
            self.s = c

        elif way == 2:
            c = self.u
            self.u = self.w
            self.w = self.d
            self.d = self.e
            self.e = c

        else:
            c = self.u
            self.u = self.s
            self.s = self.d
            self.d = self.n
            self.n = c


ans = []

u1, s1, e1, w1, n1, d1 = map(int, input().split())
dice1 = Dice(u1, s1, e1, w1, n1, d1)
q = int(input())

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

    while True:
        dice1.rot(random.randint(0,3))
        if dice1.u == a and dice1.s == b:
            ans.append(dice1.e)
            break

for i in range(q):
    print(ans[i])


Measured memory_bytes: 8184
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
A = sorted(inpl())
B = sorted(inpl())
C = sorted(inpl())

ans = 0
for b in B:
    tmp = bisect.bisect_right(C,b)
    tmp2 = bisect.bisect_left(A,b)
    ans += (n-tmp) * tmp2

print(ans)

Measured memory_bytes: 109176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  ll N; cin>>N;
  ll s[N]; CINA(s,N);
  ll r = sum(s,N);
  if(r%10==0){
    ll m = 101;
    REP(i,N){
      if(s[i]%10>0){ m = min(s[i],m);}
    }
    if(m==101){r = 0;}
    else{ r -= m; }
  }
  cout << r << "\n";
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
     int a,b;
    while(~(scanf("%d %d",&a,&b))){

    //cin >>a>>b;

    if(a==b) {
        cout <<"Draw"<<endl;
    }
    else if(a==1&&b!=1)cout <<"Alice"<<endl;
    else if(b==1&&a!=1) cout <<"Bob"<<endl;
    else{
       // cout <<((a>b)?"Alice":"Bob")<<endl;
        if(a>b){cout <<"Alice"<<endl;}
        else if(a<b){cout <<"Bob"<<endl;}
        else {cout <<"draw"<<endl;}
    }}
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

	void run() {
		String pass = sc.next();
		boolean judge[] = new boolean[4];
		if (pass.length() > 5) {
			judge[0] = true;
		}
		for (int i = 0; i < pass.length(); i++) {
			if (Character.isDigit(pass.charAt(i))) {
				judge[1] = true;
			}
			if (Character.isUpperCase(pass.charAt(i))) {
				judge[2] = true;
			}
			if (Character.isLowerCase(pass.charAt(i))) {
				judge[3] = true;
			}
		}
		System.out.println(judge[0] && judge[1] && judge[2] && judge[3] ? "VALID"
						: "INVALID");
	}

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

}

Measured memory_bytes: 17328
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
	private static final int MaxNo = 13;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> al = new ArrayList<String>();
		ArrayList<Integer> data = new ArrayList<Integer>();
		String str;

		// ??\?????????
		while (true) {
			str = br.readLine();
			al.add(str);
			if (str.equals("0")) {
				break;
			}
		}

		// ?¨??????????
		String[] buf;
		int sum = 0;
		int cnt = 0;
		int index = 0;
		boolean flag = false;
		int[][] dataList = new int[al.size() / MaxNo][2];
		for (int i = 0; i < al.size(); i++) {
			buf = al.get(i).split(" ");
			if (buf.length < 2) {
				if (cnt >= 12) {
					cnt = 0;
					index++;
					sum = 0;
					flag = false;
				}
				if (!buf[0].equals("0")) {
					dataList[index][0] = Integer.parseInt(buf[0]);
				}
			} else {
				sum += Integer.parseInt(buf[0]) - Integer.parseInt(buf[1]);
				cnt++;
				if (!flag) {
					if (sum >= dataList[index][0]) {
						dataList[index][1] = cnt;
						flag = true;
					}
				}
			}
		}

		// ??????
		for (int i = 0; i < dataList.length; i++) {
			if (dataList[i][1] > 0) {
				System.out.println(dataList[i][1]);
			} else {
				System.out.println("NA");
			}
		}

	}
}

Measured memory_bytes: 31064
#include <iostream>
#include <string>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int mod = 1000000007;
int n;
string s;
bool isRight[200000];

signed main() {
	int i;
	
	cin >> n >> s;
	
	if (s[0] == 'W') { cout << 0 << endl; return 0; }
	
	isRight[0] = false;
	for (i = 1; i < s.length(); i++) {
		if (s[i - 1] != s[i]) {
			isRight[i] = isRight[i - 1];
		}
		else {
			isRight[i] = !isRight[i - 1];
		}
	}
	
	int left = 0;
	int ans = 1;
	for (i = 0; i < s.length(); i++) {
		if (isRight[i]) {
			ans *= left;
			ans %= mod;
			left--;
		}
		else {
			left++;
		}
	}
	if (left != 0) {
		cout << 0 << endl;
		return 0;
	}
	
	int fact = 1;
	for (i = 1; i <= n; i++) {
		fact = fact * i;
		fact %= mod;
	}
	cout << ans * fact % mod << endl;
	return 0;
}

Measured memory_bytes: 772
def judge(j,k):
    if j>=k:
        return(1)
    else:
        d=judge(2*j,k)
        return(1/2*d)
        
n,k= map(int,input().split())
sum=0
for i in range(n):
    sum+=judge(i+1,k)
print(sum/n)


Measured memory_bytes: 2940
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

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

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

template <typename T>
vector<T> divisor(T n){
  vector<T> res, res2;
  for(T i=1; i*i<=n; i++){
    if(n%i == 0){
      res.push_back(i);
      if(i*i < n) res2.push_back(n/i);
    }
  }

  reverse(res2.begin(), res2.end());
  res.insert(res.end(), res2.begin(), res2.end());

  return res;
}



int main(){
  int N;

  cin >> N;

  int ans = 0;

  for(int i=1;i<=N;i+=2){
    ans += divisor(i).size() == 8;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,cnt=0;
    double ans = 0;
    cin >> n;
    vector<int> v;
    for(int i=0;i<n;i++) v.push_back(i);
    int x[n],y[n];
    for(int i=0;i<n;i++) cin >> x[i] >> y[i];
    do{
        for(int i=0;i<v.size()-1;i++){
            int a = v[i],b = v[i+1];
            ans += sqrt(pow(x[a]-x[b],2)+pow(y[a]-y[b],2));
        }
        cnt++;
    }while(next_permutation(v.begin(),v.end()));
    cout <<fixed << setprecision(10) << ans/cnt << endl;
}

Measured memory_bytes: 3812
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<cstring>
#include<algorithm>
#define ll long long
#define Max(x,y) ((x) > (y) ? (x) : (y))
#define Min(x,y) ((x) < (y) ? (x) : (y))
#define mod 1000000007
#define N 100010
using namespace std;
inline int read(){
	int x = 0,f = 1;char ch = getchar();
	while(ch < '0' || ch > '9'){if(ch == '-')f = -1;ch = getchar();}
	while(ch >= '0' && ch <= '9'){x = x*10+ch-'0';ch = getchar();}
	return x*f;
}

int n;
map<int,int> mp;
int a[N],tot;

bool cmp(int a,int b){
	return a > b;
}

int main(){
	n = read();
	for(int i = 1;i <= n;i++){
		int x = read();
		mp[x]++;
		if(mp[x] == 2){
			a[++tot] = x;
			mp[x] = 0;
		}
	}
	sort(a+1,a+tot+1,cmp);
	printf("%lld\n",1ll*a[1]*a[2]);
	return 0;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define MAXN 10010
#define pii  pair<ll, ll>
#define ss second
#define ff first

using ll = long long;
using namespace std;
const int mod = 1e9 + 7;

int main(){
    ll n;
    cin >> n;

    cout << n*n*3 << endl;
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = list()
for i in range(n):
	a.append(list(map(int, input().split())))
b = list()
for i in range(m):
	b.append(int(input()))
for i in range(n):
	ans = 0
	for j in range(m):
		ans += a[i][j] * b[j]
	print(ans)


Measured memory_bytes: 5976
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int d[3010][2][3010];
int pos[3010][30];
int pre[3010][2][3010];
string s,t;
PII res;
void build()
{
	for (int i=0;i<26;i++)
	{
		pos[t.size()][i]=-1;
		for (int j=t.size()-1;j>=0;j--)
		{
			if (t[j]==i+'a') pos[j][i]=j;
			else pos[j][i]=pos[j+1][i];
		}
	}
}
void out(int x,int y,int z)
{
	//cout <<x<<" "<<y<<" "<<z<<" ##\n";
	if (pre[x][z][y]==-1) ;
	else if (d[x-1][0][pre[x][z][y]]+z==d[x][z][y])
		out(x-1,pre[x][z][y],0);
	else out(x-1,pre[x][z][y],1);
	if (z) cout <<s[x];
}
int main()
{
	cin >>s>>t;
	build();
	for (int i=0;i<s.size();i++)
	{
		for (int j=0;j<t.size();j++)
			pre[i][0][j]=pre[i][1][j]=-1;
	}
	for (int i=0;i<s.size();i++)
	{
		if (pos[0][s[i]-'a']==-1) continue;
		d[i][1][pos[0][s[i]-'a']]=1;
	}
	for (int i=0;i<s.size()-1;i++)
	{
		for (int j=0;j<t.size();j++)
		{
			int x=pos[j+1][s[i+1]-'a'];
			int mx=max(d[i][0][j],d[i][1][j]);
			if (x!=-1 && MP(d[i+1][1][x],-pre[i+1][1][x])<MP(mx+1,-j))
				d[i+1][1][x]=mx+1,pre[i+1][1][x]=j;
			if (MP(d[i+1][0][j],-pre[i+1][0][j])<MP(mx,-j))
				d[i+1][0][j]=mx,pre[i+1][0][j]=j;
		}
	}
	/*for (int i=0;i<s.size();i++)
	{
		for (int j=0;j<t.size();j++)
			cout <<max(d[i][0][j],d[i][1][j])<<" ";
		cout <<"\n";
	}*/
	for (int i=0;i<t.size();i++)
	{
		for (int j=0;j<2;j++)
		{
			if (d[s.size()-1][res.Snd][res.Fst]<d[s.size()-1][j][i])
				res=MP(i,j);
		}
	}
	//cout <<d[s.size()-1][res.Snd][res.Fst]<<" ##\n";
	out(s.size()-1,res.Fst,res.Snd);
	return 0;
}

Measured memory_bytes: 142080
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

int main() {
  while(1){
    int n;
    cin>>n;
    if(!n)break;
    vector<string> mp(n);
    REP(i,n) cin>>mp[i];
    vector<vector<int>> s(n,vector<int>(n));
    REP(i,n)REP(j,n)
      s[i][j] = (mp[i][j] == '.');
    FOR(i,1,n){
      FOR(j,1,n){
        if (s[i][j] == 0) continue;
        int minr = min(s[i-1][j], min(s[i-1][j-1], s[i][j-1]));
        s[i][j] = max(minr + 1, s[i][j]);
      }
    }
    int maxr = 0;
    REP(i,n)
      maxr=max(maxr, *max_element(begin(s[i]), end(s[i])));
    cout << maxr << endl;
  }
  return 0;
}

Measured memory_bytes: 6092
S = input()
T = input()

ans = []

for i in range(len(S) + 1 - len(T)):
	if S[i] == T[0] or S[i] == '?':
		s = ''
		flag = True
		
		for j in range(i):
			if S[j] == '?':
				s += 'a'
			else:
				s += S[j]
		
		for j in range(i, i + len(T)):
			if S[j] == T[j - i] or S[j] == '?':
				s += T[j - i]
			else:
				flag = False
				break
		
		if flag:
			for j in range(i + len(T), len(S)):
				if S[j] == '?':
					s += 'a'
				else:
					s += S[j]
			ans.append(s)

if len(ans) > 0:
	ans.sort()
	print(ans[0])
else:
	print('UNRESTORABLE')

Measured memory_bytes: 3064
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

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

    vector<int> A(N);
    map<int, int> val2pos;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        val2pos[A[i]] = i;
    }

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

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (i & 1 and !(val2pos[A[i]] & 1)) ans++;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 5376
N=input()
cards=list(map(int,input().split()))
cards.sort(reverse=True)
print(sum(cards[0::2])-sum(cards[1::2]))

#1番目に大きいもの、3番目に大きいもの....の和から、2番目に大きいもの、4番目に大きいもの...を引く

Measured memory_bytes: 2940
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
#include <algorithm>
#include <array>
#include <string.h>
#include <vector>



int main() {
	char buf[100];
	int check[3] = {1,1,1};
	int a, b, k;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &k);

	std::vector<int> ansv;

	int cta = a;
	int ctb = b;

	for (int i = 0; i < k; i++) {
		if (cta > b) break;
		if (ctb < a) break;
		ansv.push_back(cta);
		ansv.push_back(ctb);
		cta++;
		ctb--;
	}

	std::sort(ansv.begin(),ansv.end());
	ansv.erase(std::unique(ansv.begin(), ansv.end()), ansv.end());

	for (int x : ansv) {
		printf("%d\n", x);
	}



	return 0;
}

Measured memory_bytes: 256
// AOJ 3053 Phone Number
// 2018.3.17 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in()  // 非負整数の入力
{
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void outs(char *s) { while (*s) pc(*s++); }  // 文字列の表示

int K = 9;
int PP[] = { 0, 1,2,3,4,5,6,7,8,9 };   // 0はダミ
int *perm = PP + 1;                    // action()ではPP[1]から利用

/* 与えられた並び PP[] の次に大きい並べ替えを求める */
int next_perm()   // 順列の大きさはK
{
	int i, j, k, t;
	void action();

	while (1) {
		/* 上位桁のほうが下位桁よりも小さいところまで移動 */
		i = K; while (PP[i - 1] >= PP[i]) i--;

		/* 次の並べ替えがない */
		if (i == 1) return 0;

		/* PP[i-1]より値の大きい最も下位の桁をPP[j]とする */
		j = K; while (PP[i - 1] >= PP[j]) j--;

		/* PP[i-1]とPP[j]とを交換 */
		t = PP[i - 1], PP[i - 1] = PP[j], PP[j] = t;

		/* PP[i]から最下位までを逆順 */
		k = (K - i) >> 1; for (j = 0; j <= k; j++)
			t = PP[i + j], PP[i + j] = PP[K - j], PP[K - j] = t;

		action();
	}
	return 1;
}

#define INF 100000000
#define ABS(x) ((x)>=0?(x):-(x))
int N;
int ans[9], min;
int diff[10][10];
int cnt['9'+1]['9'+1];
int tbl[9][9] = {
	{0,1,2,1,2,3,2,3,4},
	{1,0,1,2,1,2,3,2,3},
	{2,1,0,3,2,1,4,3,2},
	{1,2,3,0,1,2,1,2,3},
	{2,1,2,1,0,1,2,1,2},
	{3,2,1,2,1,0,3,2,1},
	{2,3,4,1,2,3,0,1,2},
	{3,2,3,2,1,2,1,0,1},
	{4,3,2,3,2,1,2,1,0} };
void action()
{
	int i, j, k;
	
	for (i = 0; i < 9; i++) {
		k = perm[i];
		for (j = 0; j < 9; j++) diff[k][perm[j]] = tbl[i][j];
	}

	k = 0; for (i = 1; i <= 9; i++) for (j = 1; j <= 9; j++)
		k += diff[i][j] * cnt[i+'0'][j+'0'];

	if (k < min) {
		min = k;
		memcpy(ans, perm, sizeof(ans));
	}
}

int main()
{
	int i, j;

	N = in();
	if (N == 1) { outs("123\n456\n789\n"); return 0; }
	i = gc(); while (--N) j = gc(), cnt[i][j]++, i = j;

	min = INF;
	action();
	next_perm();
//	printf("Min=%d\n", min);

	for (i = 0; i < 9; i++) {
		pc(ans[i]+'0');
		if ((i + 1) % 3 == 0) pc('\n');
	}
	return 0;
}

#if 0
// テストデータを作成する
#include <time.h>
int main()
{
	int i, N = 100000;

	printf("%d\n", N);
	srand((unsigned)time(NULL));
	for (i = 0; i < N; i++) {
		printf("%1d", rand() % 9 + 1);
	}
	printf("\n");
	return 0;
}
#endif



Measured memory_bytes: 2112
#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(){
	int n,b;
	string a;
	cin >> n;
	vector<pair<string,int>> v(n);
	for(int i = 0; i < n; i++) {
		cin >> a >> b;
		v[i] = mp(a,b);
	}
	cin >> a;
	int ans =0;
	bool flag = false;
	for(int i = 0; i < n; i++) {
		if (flag){
			ans += v[i].sc;
		}
		if (a == v[i].fs){
			flag = true;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const double PI2 = 8.0 * atan(1.0);

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define FOR(i,s,n)	for(int i=s;i<(int)n;++i)

#define MOD (1000000007)

int main(int argc, char **argv) {
	int n;
	cin >> n;
	map<int, int> cnt;
	FOR(i, 2, n + 1) {
		int m = i, d = 2;
		for (; m > 1; ++d) for (; m % d == 0; m /= d) ++cnt[d];
	}
	ll res = 1;
	for (auto p : cnt) res = (res * (p.second + 1)) % MOD;
	cout << res << endl;
	return 0;
}


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

using namespace std;
typedef pair<int, int> p;
queue<p> que;

int main()
{
	int H,W;
	char map[52][52];
	int bc = 0;
	int d[51][51];
	int dx[4] = { 0,1,0,-1 };
	int dy[4] = { 1,0,-1,0 };

	cin >> H >> W;

	for (int i = 1; i <= H; i++) {
		for (int k = 1; k <= W; k++) {
			cin >> map[i][k];
		}
	}

	for (int i = 1; i <= H; i++) {
		for (int k = 1; k <= W; k++) {
			d[i][k] = -1;
			if (map[i][k] == '#') {
				bc += 1;           //黒マスの数を数える
			}
		}
	}

	d[1][1] = 0;

	que.push(p(1, 1));

	while (!que.empty()) {
		p P = que.front(); que.pop();
		int x = P.second; int y = P.first;
		if (x == W && y == H) { break; }
		for (int i = 0; i < 4; i++) {
			if (x + dx[i] > 0 && x + dx[i] <= W && y + dy[i] > 0 && y + dy[i] <= H && map[y+dy[i]][x + dx[i]] == '.'&&d[y+dy[i]][x+dx[i]]==-1) {
				d[y + dy[i]][x + dx[i]] = d[y][x] + 1;
				que.push(p(y + dy[i], x + dx[i]));
			}
		}
	}

	

	if (d[H][W] == -1) {
		cout << -1 << endl;
	}
	else {
		cout << H * W - (d[H][W]+1) - bc << endl;
	}


	return 0;
}



Measured memory_bytes: 256
fn read<T: std::str::FromStr>(stdin_lock: &mut std::io::StdinLock, buf: &mut Vec<u8>, delimiter: u8) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let h = read(&mut stdin_lock, &mut buf, b' ');
    let w = read(&mut stdin_lock, &mut buf, b'\n');
    let h1 = read(&mut stdin_lock, &mut buf, b' ');
    let w1 = read(&mut stdin_lock, &mut buf, b'\n');
    println!("{}", solve(h, w, h1, w1));
}

fn solve(h: u16, w: u16, h1: u16, w1: u16) -> u16 {
    (h - h1) * (w - w1)
}

#[test]
fn example1() {
    assert_eq!(1, solve(3, 2, 2, 1))
}

#[test]
fn example2() {
    assert_eq!(6, solve(5, 5, 2, 3))
}

#[test]
fn example3() {
    assert_eq!(0, solve(2, 4, 2, 4))
}


Measured memory_bytes: 4352
#include <iostream>

using namespace std;
int main(){
	int a,b,c,t;
	cin>>a>>b>>c;
	if(a>b){
		t=a;
		a=b;
		b=t;
	}
	if(b>c){
		t=b;
		b=c;
		c=t;
	}
	if(a>b){
		t=a;
		a=b;
		b=t;
	}
	cout<<a+b<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
public class Hello{
    public static void Main(){
        string[] s = Console.ReadLine().Split(' ');
        var hash = new HashSet<string>();
        for(int i = 0;i < s.Length;i++){
            hash.Add(s[i]);
        }
        Console.WriteLine(hash.Count);
    }
}


Measured memory_bytes: 11232
// abc155_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    vector<string> S(N);
    REP(i, N) cin >> S[i];

    map<string, int> mp;
    REP(i, N){
        mp[S[i]]++;
    }

    int mx = 0;
    for (auto e: mp){
        mx = max(mx, e.second);
    }

    vector<string> cand;
    for (auto e: mp){
        if (e.second == mx){
            cand.emplace_back(e.first);
        }
    }

    sort(ALL(cand));
    for (auto s: cand){
        print(s);
    }


    return 0;
}


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

typedef long long ll;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()

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

    if(s == t.substr(0, t.size() - 1)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3640
import std.stdio;

void main(){
	char ans;
	int n, m, e, j;
	while (readf("%d\n", &n), n) {
		foreach (i; 0..n) {
			readf("%d %d %d\n", &m, &e, &j);
			if (m == 100 || e == 100 || j == 100) ans = 'A';
			else if (m+e >= 90*2) ans = 'A';
			else if (m+e+j >= 80*3) ans = 'A';
			else if (m+e+j >= 70*3) ans = 'B';
			else if (m+e+j >= 50*3 && (m >= 80 || e >= 80)) ans = 'B';
			else ans = 'C';
			writeln(ans);
		}
	}
}

Measured memory_bytes: 964
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }

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

	int a, b, c;
	cin >> a >> b >> c;
	cout << max(0, c - (a - b));
}

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

ll calc(string s)
{
  int len = s.length();
  ll ret = stoll(s);
  for (int i=1; i<len; i++) {
    string sl = s.substr(0, i);
    ret += stoll(sl) * pow(2, (len-i-1));
    string sr = s.substr(i, len-i);
    ret += calc(sr);
  }
  return ret;
}

int main()
{
  string s;
  cin >> s;
  cout << calc(s) << endl;

  return 0;
}


Measured memory_bytes: 4016
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n, k;
const int maxN = 5005;
bool dp[maxN][maxN];
int a[maxN];
bool dpSuf[maxN][maxN];
int pref[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    dp[0][0] = true;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= k - 1; j++) {
            if (!dp[i][j]) continue;
            dp[i + 1][j] = true;
            if (j + a[i + 1] < k) dp[i + 1][j + a[i + 1]] = true;
        }
    }
    dpSuf[n + 1][0] = true;
    for (int i = n + 1; i > 1; i--) {
        for (int j = 0; j <= k - 1; j++) {
            if (!dpSuf[i][j]) continue;
            dpSuf[i - 1][j] = true;
            if (j + a[i - 1] < k) dpSuf[i - 1][j + a[i - 1]] = true;
        }
    }
    int c = 0;
    for (int who = 1; who <= n; who++) {
        pref[0] = dpSuf[who + 1][0];
        for (int j = 1; j <= k - 1; j++) {
            pref[j] = pref[j - 1] + (int)dpSuf[who + 1][j];
        }
        int l = max(0, k - a[who]);
        int r = k - 1;
        bool imp = false;
        for (int sz = 0; sz <= k - 1; sz++) {
            if (!dp[who - 1][sz]) continue;
            int hisl = max(l - sz, 0);
            int hisr = r - sz;
            if (hisl == 0 && pref[hisr] > 0) {
                imp = true;
                break;
            }
            if (hisl > 0 && pref[hisr] > pref[hisl - 1]) {
                imp = true;
                break;
            }
        }
        if (!imp) c++;
    }
    cout << c;
    return 0;
}

Measured memory_bytes: 49152