akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        int[] d = new int[n];
        for (int i = 0; i < n; i++) {
            d[i] = sc.nextInt();
        }
        long ans = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                ans += d[i] * d[j];
            }
        }
        System.out.println(ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int MOD = 1e9 + 7;

struct Combination{
  const int MOD = 1e9+7;

  vector<int> fact; //　fact[i] = iの階乗
  void init(int n){
    fact.resize(n+1);
    fact[0] = fact[1] = 1;
    for(int i = 2; i <= n; i++){
      fact[i] = i * fact[i-1] % MOD;
    }
  }

  int nCr(int n, int r){ // nCr = n!/r!(n-r)!
    if(n < r) return 0;
    return fact[n] * mod_pow(fact[r]*fact[n-r]%MOD, MOD-2) % MOD;
  }

  int mod_pow(int n, int p){ // a/n ≡ a*n^(p-2) nとpは互いに素
    int r = 1;
    for(; p > 0; p >>= 1){
      if(p & 1LL) r = (r * n) % MOD;
      n = (n * n) % MOD;
    }
    return r; // r = n^p % MOD
  }

}comb;

signed main(){

  int n, a, b; cin >> n >> a >> b;

  comb.init(1e6);
  int ans = comb.mod_pow(2, n);

  int res = 1, x = n;
  for(int i = 1; i <= a; i++){
    res *= (x - i + 1) % MOD * comb.mod_pow(i, MOD-2) % MOD;
    res %= MOD;
  }
  //cout << res << endl;
  ans = (ans - res + MOD) % MOD;

  res = 1, x = n;
  for(int i = 1; i <= b; i++){
    res *= (x - i + 1) % MOD * comb.mod_pow(i, MOD-2) % MOD;
    res %= MOD;
    //cout << x-i+1 << " " << i << " " << res << endl;
  }
  //cout <<res << endl;
  ans = (ans - res + MOD) % MOD;

  //if(n == 2) ans = 0;
  cout << (ans - 1) % MOD << endl;

  return 0;
}


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

ll n,k,m,a,b;
string s;

int main() {
  cin >> n >> m;
  vector<pair<ll,ll>> p(100005);
  rep(i,n){
  cin >> a >> b;
  p[i]=make_pair(a,b);
  }
  sort(all(p)); 
  ll d=0,ans=0,i=0;
  while(1){
    if(d+p[i].second<m){
    d+=p[i].second;
    ans+=p[i].first*p[i].second;
    i++;
    }else{
      ans+=(m-d)*p[i].first; 
      cout << ans << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 1920
import java.util.Scanner;

class Solver {
    public void Solve() {
        int n = sc.nextInt();
        int k = sc.nextInt();
        int p[] = new int[n];
        for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextInt();
        }
        double max = 0;
        double dp[] = new double[n];
        for (int i = 0; i < k; i++) {
            max += (1.0 * p[i] + 1) / 2;
        }
        dp[k - 1] = max;
        for (int i = k; i < n; i++) {
            dp[i] = dp[i - 1] - (1.0 * p[i - k] + 1) / 2;
            dp[i] += (1.0 * p[i] + 1) / 2;
        }
        for (int i = k - 1; i < dp.length; i++) {
            max = Math.max(max, dp[i]);
        }
        int a = 0;
        System.out.println(max);

    }

    Scanner sc;

    Solver(Scanner in) {
        this.sc = in;
    }
}

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


Measured memory_bytes: 84820
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        if(n%m==0)
            printf("0\n");
        else
            printf("1\n");
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <cassert>
#include <utility>
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <bitset>
#include <chrono>
#include <cstdlib>
#include <functional>
#include <tuple>
#include <climits>
#include <limits>
#include <deque>
#include <list>
#include <array>
#include <stack>
#include <queue>
#include <random>
#include <complex>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
 
#define init ios::sync_with_stdio(0); cin.tie(NULL);cout.tie(NULL);
#define setpr(x) cout << setprecision((x))
#define PI atan(1)*4
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mk(a , b) { min((a) , (b)) , max((a) , (b)) }
#define flush cout.flush()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endc "\n"
#define MOD 1000000007
#define meme(x) memset((x), 0, sizeof((x)))
#define memo(x) memset((x),-1, sizeof((x)))
 
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pld;

// #define int ll

ll egcd(ll a, ll b, ll &x, ll &y){
    if (a == 0LL){  
        x = 0LL;  
        y = 1LL;  
        return b;  
    }
    ll xx, yy;
    ll val = egcd(b % a, a, xx, yy);  
    x = yy - (b / a) * xx;  
    y = xx;  
    return val;
}

ll gcd(ll a, ll b){
    while(true){
        if(a>b)
            swap(a,b);
        if (a == 0) 
            return b; 
        ll p = b % a  , q = a;
        a = p;
        b = q;
    }
}
 
ll powerMod(ll x,ll y){
    ll res = 1;
    x %= MOD;
    while(y > 0){
        if(y & 1)res = (res*x)%MOD;
        y = y >> 1;
        x = (x * x)%MOD;
    }
    return res%MOD;
}

//  ==========      //\\       //||     ||====//||
//      ||         //  \\        ||     ||   // ||
//      ||        //====\\       ||     ||  //  ||
//      ||       //      \\      ||     || //   ||
//  ==========  //        \\  ========  ||//====|| 
//  code

vector< vector<ll> > adj, dp;

ll dfs(int node, int p, int prev){
    if(dp[node][prev] > -1){
        return dp[node][prev];
    }

   if(prev){
        ll ans = 1LL;
        for(auto i : adj[node]){
            if(i == p)
                continue;
            ans *= dfs(i, node, 0);
            ans %= MOD;
        }
        return dp[node][prev] = ans;
    } else {
        ll ans = 1LL, ans1 = 1LL;
        for(auto i : adj[node]){
            if(i == p)
                continue;
            ans *= dfs(i, node, 0);
            ans1 *= dfs(i, node, 1);
            ans %= MOD;
            ans1 %= MOD;
        }
        return dp[node][prev] = (ans + ans1) % MOD;
    }
}

void solve(){
    int n,i,j,k,l,p;
    cin >> n;
    adj.resize(n + 1);
    dp.resize(n + 1, vector<ll>(2, -1LL));

    for(i = 0; i < n - 1; i++){
        cin >> j >> k;
        adj[j].pb(k);
        adj[k].pb(j);
    }

    cout << dfs(1,0,0) << endc;
}

int32_t main(){
    init;
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


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

typedef long long LL;

using std::map;
using std::min;
using std::sort;

const int N=410;

int n,c[N][4],put[4],C[N][5],fact[5];
LL h[N];
map<LL,int>app;

LL Hash(int *c) {
	for (int w=0;w<4;++w) put[w]=c[w];
	for (int j=1;j<4;++j)
		for (int k=0;k<4;++k) {
			if (c[(j+k)%4]>put[k]) break;
			if (c[(j+k)%4]<put[k]) {
				for (int w=0;w<4;++w) put[w]=c[(j+w)%4];
				break;
			}
		}
	LL h=0;
	for (int j=0;j<4;++j) h=h*1000+put[j];
	return h;
}

void Init() {
	scanf("%d",&n);
	for (int i=1;i<=n;++i) {
		for (int j=0;j<4;++j) scanf("%d",&c[i][j]);
		h[i]=Hash(c[i]);
		app[h[i]]++;
	}
}

void Prepare() {
	for (int i=0;i<=n;++i) {
		C[i][0]=1;
		for (int j=1;j<=min(i,4);++j)
			C[i][j]=C[i-1][j-1]+C[i-1][j]; 
	}
	fact[0]=1; for (int i=1;i<=4;++i) fact[i]=fact[i-1]*i;
}

int Same(LL x) {
	int cnt=0; LL p=x;
	for (int i=3;i>=0;--i) put[i]=p%1000,p/=1000; 
	for (int i=0;i<4;++i) {
		LL h=0ll;
		for (int k=0;k<4;++k) h=h*1000+put[(i+k)%4];
		if (h==x) cnt++;
	}
	return cnt;
}

int qpow(int x,int t) {
	if (x==1 || !t) return 1;
	int ret=1;
	while (t) {
		if (t&1) ret=ret*x;
		x=x*x;
		t>>=1;
	}
	return ret;
}

void Solve() {
	Prepare();
	LL ans=0; int p[4];
	for (int i=1;i<=n;++i) {
		app[h[i]]--;
		for (int j=i+1;j<=n;++j) {
			int a=0; app[h[j]]--;
//			for (int a=0;a<4;++a)
				for (int b=0;b<4;++b) {
					LL t[4];
					p[0]=c[j][(1+b)&3]; p[1]=c[j][(0+b)%4]; p[2]=c[i][(1+a)%4]; p[3]=c[i][(0+a)%4]; t[0]=Hash(p);
					p[0]=c[i][(1+a)&3]; p[1]=c[j][(0+b)%4]; p[2]=c[j][(3+b)%4]; p[3]=c[i][(2+a)%4]; t[1]=Hash(p);
					p[0]=c[i][(3+a)%4]; p[1]=c[i][(2+a)%4]; p[2]=c[j][(3+b)%4]; p[3]=c[j][(2+b)%4]; t[2]=Hash(p);
					p[0]=c[j][(1+b)%4]; p[1]=c[i][(0+a)%4]; p[2]=c[i][(3+a)%4]; p[3]=c[j][(2+b)%4]; t[3]=Hash(p);
					sort(t,t+4); LL now=1ll;
					for (int i=0;i<4;) {
						int pos=i;
						while (t[i]==t[pos] && i<4) ++i;
						int p=app[t[pos]];
						if (now && p)
							p++,p--;
						now=1ll*now*C[p][i-pos]*fact[i-pos]*qpow(Same(t[pos]),i-pos);
					}
					ans+=now;
				}
			app[h[j]]++;
		}
		app[h[i]]++;
	}
	printf("%lld\n",ans/3);
}

int main() {
	Init();
	Solve();
	return 0;
}

Measured memory_bytes: 80128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin>>a;
  int b=a/100,c=(a/10)%10,d=a%10;
  if(b==9)b=1;
  else if(b==1)b=9;
   if(c==9)c=1;
  else if(c==1)c=9;
   if(d==9)d=1;
  else if(d==1)d=9;
  cout<<b<<c<<d<<endl;
}

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

#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[N][N];
int color[N], d[N], f[N], tt;

void dfs_visit(int u) {
  int v;
  color[u] = GRAY;
  d[u] = ++tt;
  for ( v = 0; v < n; v++ ) {
    if ( M[u][v] == 0) continue;
    if ( color[v] == WHITE ) {
      dfs_visit(v);
    }
  }
  color[u] = BLACK;
  f[u] = ++tt;
}

void dfs() {
  int u;
  for ( u = 0; u < n; u++ ) color[u] = WHITE;
  tt = 0;

  for ( u = 0; u < n; u++ ) {
    if ( color[u] == WHITE ) dfs_visit(u);
  }
  for ( u = 0; u < n; u++ ) {
    printf("%d %d %d\n", u + 1, d[u], f[u]);
  }
}

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

  for ( int i = 0; i < n; i++ ) {
    int a, b;
    cin >> a >> b;
    a--;
    for ( int j = 0; j < b; j++ ) {
      int c;
      cin >> c;
      c--;
      M[a][c] = 1;
    }
  }

  dfs();

  return 0;
}

Measured memory_bytes: 3224
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59
using ld = long double;

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    //cout << fixed << setprecision(5);
    int A, B, C;
    cin >> A >> B >> C;

    if (A == B && B == C)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define min(p,q)((p)<(q)?(p):(q))


//セグ木ここから
//*
//↓ここを変える
typedef struct atai{ll a;}atai;
atai xx(atai x,atai y){
	atai r;
	r.a=min(x.a,y.a);//min
	return r;
}
atai aid={(1LL<<31)-1};
//↑ここを変える

int segNUM;
atai *segN,*seg;
void seguse(int n){
	segN=(atai*)calloc(2*n,sizeof(atai));
	segNUM=n;
	seg=segN+segNUM;
	rep(i,1,2*segNUM)segN[i]=aid;
}
//seg[]に値を与えてから初期化
void seginit(){for(int node=segNUM-1;node;node--)segN[node]=xx(segN[node*2],segN[node*2+1]);}
void segupdate(int node,atai x){
	//seg[node]をxに更新
	node+=segNUM;
	segN[node]=x;
	while(node/=2)segN[node]=xx(segN[node*2],segN[node*2+1]);
}

atai segcalcsub(int l,int r,int k,int cl,int cr){
	if(l>=r)return aid;
	//完全に含むとき
	if(l<=cl&&cr<=r)return segN[k];

	int cm=(cl+cr)/2;
	//左側だけ
	if(r<=cm)return segcalcsub(l,r,2*k  ,cl,cm);
	//右側だけ
	if(cm<=l)return segcalcsub(l,r,2*k+1,cm,cr);
	//両方
	return xx(segcalcsub(l,r,2*k,cl,cm),segcalcsub(l,r,2*k+1,cm,cr));
}
atai segcalc(int l,int r){return segcalcsub(l,r,1,0,segNUM);}
//セグ木ここまで
//*/


int main(){
	int n,q;
	scanf("%d%d",&n,&q);
	seguse(1<<17);
	while(q--){
		int t,x,y;
		scanf("%d%d%d",&t,&x,&y);
		if(t)printf("%lld\n",segcalc(x,y+1).a);
		else{
			atai a={y};
			segupdate(x,a);
		}
	}
}


Measured memory_bytes: 3904
T=0..59
puts 9394,a=?+,0,1,3,?<,2,3,3,[0,1].map{|x|[a,x,3,x]+T.map{[a,v=x+4,v,v,a,v,3,6,[a,6,6,6]*(59-_1),?<,6,x,u=x*61+_1+9,a,v,u,v]}},T.map{|t|[a,2,2,2]+(1..t).map{[a,39+t-_1,99+_1,5,?<,3,5,5,a,2,5,2]}}

Measured memory_bytes: 14860
#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() {
	string s;
	cin >> s;
	int sum = 0;
	int l = s.size();
	rep(i, l) {
		int n = s[i] - '0';
		sum += n;
	}
	if (sum % 9 == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<P,int>

int n,m;
int p[111111];
string s[111111];
bool ac[111111];
int pena[111111];

signed main(){
    cin>>n>>m;
    rep(i,m)cin>>p[i]>>s[i];
    rep(i,m){
        if(s[i]=="AC"){
            ac[p[i]]=1;
        }
        if(s[i]=="WA"){
            if(!ac[p[i]])pena[p[i]]++;
        }
    }
    int a=0,b=0;
    rep(i,n+1){
        if(ac[i])a++;
        if(ac[i])b+=pena[i];
    }
    cout<<a<<" "<<b<<endl;
    return 0;
}


Measured memory_bytes: 6656
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <stack>
#include <vector>
using namespace std;
const long long INF = 0x3f3f3f3f;
typedef long long ll;
long long dis[2555]={0};
struct node{
    long long dis;
    int pos;
    bool operator<(const node &t)const{
        return dis>t.dis;
    }
};
vector<node>edg[2555];
int sele[2555]={0};
int vis[2555]={0};
int inq[2555]={0};
bool SPFA(int n)
{
    memset(vis,0,sizeof(vis));
    memset(inq,0,sizeof(inq));
    queue<int> Q;
    for(int i = 2;i <= n;i++) dis[i] = INF;
    dis[1]=0;
    inq[1] = 1;
    Q.push(1);
    int t,j;
    while(!Q.empty())
    {
        t = Q.front();
        Q.pop();
        vis[t] = 0;
        for(int i=0;i<edg[t].size();i++)
        {
            j=edg[t][i].pos;
            if(dis[t]+edg[t][i].dis<dis[j]&&sele[j]){
                dis[j]=dis[t]+edg[t][i].dis;
                if(!vis[j]){
                    if(inq[j]>=n)
                        return false;
                    inq[j]++;
                    Q.push(j);
                    vis[j]=1;
                }
            }
        }
    }
    return true;
}
void dfs(int x){
    vis[x]=1;
    for(int i=0;i<edg[x].size();i++)
        if(!vis[edg[x][i].pos])dfs(edg[x][i].pos);
}
int main()
{
    ios::sync_with_stdio(false);
    int n,m,k;
    int a,b;
    long long num;
    cin >> n >> m >> k;
    for(int i=0;i<m;i++){
        cin >> a >> b >> num;
        edg[a].push_back({k-num,b});
    }
    for(int i=1;i<=n;i++){
        memset(vis,0,sizeof vis);
        dfs(i);
        if(vis[n])sele[i]=1;
        //cout << sele[i] << endl;
    }
    for(int i=1;i<=n;i++)
        sort(edg[i].begin(),edg[i].end());
    if(SPFA(n)){
        cout << max(0ll,-dis[n]) <<endl;
    }
    else
        cout << -1 <<endl;

    return 0;
}


Measured memory_bytes: 640
i = gets
a = Array.new(2)
while a = gets
	c = a.split(" ")
	b = c.map(&:to_i).sort
	if (b[2] ** 2) == ((b[1] ** 2) + (b[0] ** 2))
		puts "YES"
	else
		puts "NO"
	end
end

Measured memory_bytes: 8720
while True:
    h1 = ""
    h2 = ""
    H,W = map(int, input().split())
    if H == 0 and W == 0:
        break
 
    for j in range(W):
      if j%2 == 0:
        h1 = h1 + "#"
      else:
        h1 = h1 + "."
    for j in range(W):
      if j%2 == 0:
        h2 = h2 + "."
      else:
        h2 = h2 + "#"
     
    for i in range(H):
        if i%2 == 0:
            print(h1)
        else:
            print(h2)
    print()


Measured memory_bytes: 5608
K, N = map(int, input().split())
A = list(map(int, input().split()))
path = [0] * N


for i in range(N-1):
    path[i] = A[i + 1] - A[i]
path[N - 1] = K - A[N - 1] + A[0]


print(K - max(path))

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

const int INF = 1 << 28;

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;

    int m = 0;
    vector<vector<int> > dp(10, vector<int>(10, INF));
    for (int i = 0; i < n; ++i) {
      int a, b, c;
      cin >> a >> b >> c;
      dp[a][b] = dp[b][a] = c;
      m = max(m, max(a, b));
    }
    ++m;

    for (int i = 0; i < 10; ++i)
      dp[i][i] = 0;

    for (int k = 0; k < m; ++k) {
      for (int i = 0; i < m; ++i) {
	for (int j = 0; j < m; ++j)
	  dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]);
      }
    }

    int index = 0, sum = INF;
    for (int i = 0; i < m; ++i) {
      int tmp = 0;
      for (int j = 0; j < m; ++j)
	tmp += dp[i][j];

      if (sum > tmp) {
	sum = tmp;
	index = i;
      }
    }

    cout << index << " " << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

struct node {
    int p = -1;
    int l;
    int r;
};

int N;
vector<node> G;

void rec1(int s, vector<int> &pre) {
    if (s == -1)
        return;
    pre.push_back(s);
    if (G[s].l != -1)
        rec1(G[s].l, pre);
    if (G[s].r != -1)
        rec1(G[s].r, pre);
}

void rec2(int s, vector<int> &in) {
    if (s == -1)
        return;
    rec2(G[s].l, in);
    in.push_back(s);
    rec2(G[s].r, in);
}

void rec3(int s, vector<int> &post) {
    if (s == -1)
        return;
    rec3(G[s].l, post);
    rec3(G[s].r, post);
    post.push_back(s);
}

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

    cin >> N;
    G.resize(N);
    rep(i, N) {
        int a, b, c;
        cin >> a >> b >> c;
        G[a].l = b, G[a].r = c;
        if (b != -1)
            G[b].p = a;
        if (c != -1)
            G[c].p = c;
    }

    int s;

    rep(i, N) {
        if (G[i].p == -1) {
            s = i;
            break;
        }
    }

    vector<int> pre, in, post;
    rec1(s, pre);
    rec2(s, in);
    rec3(s, post);

    cout << "Preorder" << endl;
    cout << " ";
    rep(i, N) {
        cout << pre[i];
        if (i != N - 1)
            cout << " ";
    }
    cout << endl;

    cout << "Inorder" << endl;
    cout << " ";
    rep(i, N) {
        cout << in[i];
        if (i != N - 1)
            cout << " ";
    }
    cout << endl;

    cout << "Postorder" << endl;
    cout << " ";
    rep(i, N) {
        cout << post[i];
        if (i != N - 1)
            cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 3216
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int n;
  cin >> n;
  int ans = INF;
  int tmp;
  rep (i, n) {
    cin >> tmp;
    int count = 0;
    while (tmp % 2 == 0) {
      tmp /= 2;
      count++;
    }
    ans = min(ans, count);
  }
  P(ans);
  return 0;
}



Measured memory_bytes: 256
using System;
using System.IO;

class Program{
    static void Main(string[] args){
        var N = int.Parse(Console.ReadLine());
        var a = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
        Array.Sort(a);
        var answer = 0;
        var isEven = (N - 1) % 2 == 0;
        for (int i = N - 1; i >= 0; i--)
            if(isEven)
                if (i % 2 == 0) answer += a[i];
                else answer -= a[i];
            else
                if (i % 2 == 1) answer += a[i];
                else answer -= a[i];
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 27496
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <utility>
#include <functional>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	cout << (n - 1) * (m - 1) << endl;

	return 0;
}

Measured memory_bytes: 764
-- String - Finding a Word

import Data.Char

main :: IO ()
main = do
  w <- getLine
  t <- getContents
  putStrLn . show $ countWord w t

countWord :: String -> String -> Int
countWord w t = length . filter (== w) $ xs
  where xs = map (map toLower) . takeWhile (/= "END_OF_TEXT") . words $ t



Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int water = c - (a - b);
        if(water < 0){
            water = 0;
        }
        System.out.println(water);
    }
}

Measured memory_bytes: 21844
n,x = gets.split.map(&:to_i)
ls = gets.split.map(&:to_i)
ls_sum = [0]
ls.size.times do |i|
        ls_sum << ls[0..i].inject(:+)
end
ans = ls_sum.select{|l| l <= x}.size
ans = n+1 if ans > n+1
puts ans

Measured memory_bytes: 1788
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define mod 1000000007
#define MAX 1000005
#define pb push_back
#define vi vector<int>
#define endl '\n'
using namespace std;
// cnt total no. of elements between range from a to b which contains digit d exactly k times
string b;
int k;
vi num;
int dp[10005][105][2];		//dp[pos][cnt][f]	f=if number has become less or not 
int call(int pos,int cnt,int f)
{
	if(num.size()==pos){
		if(cnt==0)
			return 1;
		return 0;
	}
	int limit,res=0;
	
	if(dp[pos][cnt%k][f]!=-1)
		return dp[pos][cnt%k][f];
	if(f==0)
		limit=num[pos];
	else
		limit=9;
		
	for(int i=0;i<=limit;i++)
	{
		int nf=f;
		int ncnt=cnt;
		if(f==0 && i<limit)
			nf=1;
		res+=call(pos+1,(ncnt+i%k)%k,nf);
	}
	return dp[pos][cnt][f]=res%mod;
}		

int solve(string b)
{
	num.clear();
	for(int i=0;i<b.length();i++)
	{
		num.pb(b[i]-'0');
	}
	memset(dp,-1,sizeof(dp));
	int res=call(0,0,0);
	return res;
}
signed main()
{
	fastio;
	cin>>b>>k;
	int res=(solve(b)-1+mod)%mod;
	cout<<res<<endl;
	return 0;
}




Measured memory_bytes: 17664
N,W=map(int,input().split())
WV=[]
for i in range(N):
    WV.append(list(map(int,input().split())))
dp=[[0 for i in range(10**5+1)] for j in range(N+1)]
dp[0][1:]=[10**18 for i in range(10**5)]
for i in range(N+1):
    for j in range(10**5+1):
        if i>0:
            if j-WV[i-1][1]>=0:
                dp[i][j]=min(dp[i-1][j],dp[i-1][j-WV[i-1][1]]+WV[i-1][0])
            else: 
                dp[i][j]=dp[i-1][j]
for i in reversed(range(10**5+1)):
    if dp[N][i]<=W:
        print(i)
        break

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

int main() {
    int l,r,d;
    cin >> l >> r >> d;
    int count=0;
    for(int i=l;i<=r;i++){
      if(i%d==0) count++;
    }

    cout << count << endl;
}

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

int main(){
    string S;
    cin >> S;
    if(S.at(2) == S.at(3) && S.at(4) == S.at(5)){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
n = int(input())
c0 = 0
c1 = 0
c2 = 0
c3 = 0
for i in range(n):
    a = input()
    if a == "AC":
        c0 += 1
    elif a == "WA":
        c1 += 1
    elif a == "TLE":
        c2 += 1
    else:
        c3 += 1
print("AC x ",c0)
print("WA x ",c1)
print("TLE x ",c2)
print("RE x ",c3)

    

Measured memory_bytes: 9196
#define _USE_MATH_DEFINES
#include <math.h>
#include <time.h>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <functional>
#include <typeinfo>
#include <utility>
#include <tuple>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)

#define PI M_PI
#define INF 1000000000
#define MOD 1000000007;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<bool>> vvb;
typedef vector<vector<string>> vvs;

constexpr int dir[4][2] = { { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 } };




/*<ここから>***********************************************************/


int F[100][14];
int P[100][15];

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

	rep(i, N) rep(j, 10) cin >> F[i][j];
	rep(i, N) rep(j, 11) cin >> P[i][j];

	int res = -(1 << 30);
	
	repr(bit, 1, (1 << 10)) {
		int cc = 0;
		rep(i, N) {
			int c = 0;
			for (int j = 0; j < 10; j++) if (((bit >> j) & 1) && F[i][j]) c++;
			cc += P[i][c];
		}

		if (res < cc) res = cc;
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
N = int(input())
A = [[] for _ in range(N)]
for i in range(N):
    A[i] = [i-1 for i in map(int, input().split())]


def pair(x,y):
    if x<y:
        return (x,y)
    else:
        return (y,x)

to_index = dict()
to_pair = dict()
idx = 0
for i in range(N):
    for j in range(i+1,N):
        to_index[(i,j)] = idx
        to_pair[idx] = (i,j)
        idx += 1
    
MAX_N = idx
# DAG TopoSort
in_count = [0]*MAX_N
edge = [[] for _ in range(MAX_N)]

for i in range(N):
    for j in range(N-2):
        vnum = to_index[pair(i,A[i][j+1])]
        pvnum = to_index[pair(i, A[i][j])]
        edge[pvnum].append(vnum)

for i in range(MAX_N):
    for v in edge[i]:
        in_count[v] += 1

S = []
L = [] #Sort結果
index = [0]*MAX_N # 頂点vのLにおけるインデックスindex[v]
ans = 0

for i in range(MAX_N):
    if in_count[i]==0: S.append(i)

while S:
    ans += 1
    new = []
    for _ in range(len(S)):
        v = S.pop()
        index[v] = len(L)
        L.append(v)
        for nv in edge[v]:
            in_count[nv] -= 1
            if in_count[nv]==0:
                new.append(nv)
    S = []
    for n in new:
        S.append(n)


if len(L) != MAX_N:
    print(-1)
    exit()
print(ans)

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

int main(){
  int N;cin>>N;
  vector<int> P(N),Q(N);
  for(int i=0;i<N;i++) cin>>P.at(i);
  for(int i=0;i<N;i++) cin>>Q.at(i);
  vector<int> v;
  for(int i=1;i<=N;i++) v.push_back(i);
  vector<vector<int>> D;
  do {
   D.push_back(v);
} while (next_permutation(v.begin(), v.end()));
  
  int Ln=D.size();
  int X=0;
  int Y=0;
  for(int i=0;i<Ln;i++){
    if(D[i]<P) X++;
  }
  for(int i=0;i<Ln;i++){
    if(D[i]<Q) Y++;
  }
  if(X>Y) cout<<X-Y<<endl;
  else cout<<Y-X<<endl;
}




Measured memory_bytes: 6280
#include<bits/stdc++.h>
using namespace std;
const int maxn=450;
long long int dp[maxn][maxn];
int n;
long long int a[maxn];
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
     cin>>n;
     for(int i=1;i<=n;i++){
     	cin>>a[i];a[i]+=a[i-1];
	 }
	 for(int i=n;i>=1;i--){
	 	for(int j=i;j<=n;j++){
	 		if(i==j){
	 			dp[i][j]=0;
			 }
			 else{
			 	dp[i][j]=(long long)1e18;
			 	for(int z=i;z<=j;z++){
			 		dp[i][j]=min(dp[i][z]+dp[z+1][j]+a[j]-a[i-1],dp[i][j]);
			}
			 }
	//		 cout<<i<<"| "<<j<<" "<<dp[i][j]<<endl;
		 }
	 }
	 cout<<dp[1][n];
	 }

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

int main(){
  int N;
  cin >> N;
  vector<string> arare(N);
  string result="Three";
  for(int i=1; i<N ;i++){
    cin >> arare.at(i) ;
  }
  for(int i=1; i<N;i++){
    if(arare.at(i)=="Y"){
      result = "Four";
    }else{
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) throws Exception{
		
		Scanner sc = new Scanner(System.in);
		
		int x5=0;
		int x7=0;
		
		for(int i=0; i<3; i++){
			int x = sc.nextInt();
			if(x == 5)
				x5++;
			else if(x == 7)
				x7++;
			else
				System.out.println("NO");
		}
		if(x5 == 2 && x7 == 1)
			System.out.println("YES");
		else
			System.out.println("NO");
		
		sc.close();
	}
}


Measured memory_bytes: 9680
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
ll solve(){
    ll res = 0;
    ll W,H,T; cin >> W >> H >> T;
    ll p; cin >> p;
    vector<pll> query(p);
    for(int i = 0; i < p;i++){
        cin >> query[i].first >> query[i].second;
        ll t; cin >> t;
    }
    vector<vector<ll>> s(H,vector<ll>(W));
    for(auto& vec:s) for(auto& in:vec) cin  >>in;
    
    vector<vector<ll>> plant(H,vector<ll>(W,0));
    for(int i = 0; i < p;i++){
        if(s[query[i].second][query[i].first]){
            plant[query[i].second][query[i].first]++;
        }
    }
    for(auto& vec:plant) res += accumulate(vec.begin(),vec.end(),0LL);
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}



Measured memory_bytes: 3264
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
  int K,S;
  cin >> K >> S;
  int count =0;
  rep(i,0,K+1) rep(j,0,K+1) {
      if(S-i-j>=0&&S-i-j<=K){
          count ++;
      }
  }
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int W = Integer.parseInt(sc.next());
		int H = Integer.parseInt(sc.next());
		int x = Integer.parseInt(sc.next());
		int y = Integer.parseInt(sc.next());
		int r = Integer.parseInt(sc.next());
		
		if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H) System.out.println("Yes");
		else System.out.println("No");

	}

}

Measured memory_bytes: 26092
#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 a;
    cin >> a;
    int f = 0;
    rep(i, 9){
        rep(j, 9){
            if(a == (i+1)*(j+1)) f = 1;
        }
    }
    if(f == 1){
	    cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

int A[1000000],n;

int main(void){
    cin >> n;
    rep(i,n){
        scanf("%d",&A[i]);
    }

    int q,k=0,sum=0;
    cin>>q;
    rep(i,q){
        scanf("%d",&k);
        //??????????????§????????¢?´¢(?????????)
        if( *lower_bound(A,A+n,k)==k) sum++;
    }

    cout<<sum<<endl;

    return 0;
}

Measured memory_bytes: 3500
#include<iostream>
using namespace std;
void trace(int a[], int n)
{
	int i;
	for (i = 0; i < n; i++) {
		if (i > 0)cout << " ";
		cout << a[i];
	}
	cout << endl;
}
void InsertionSort(int a[], int n)
{
	int j, i, v;
	for (i = 1; i < n; i++) {
		v = a[i];
		j = i - 1;
		while (j >= 0 && a[j] > v)
		{
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = v;
		trace(a, n);
	}
}
int main() {
	int n,a[100];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	trace(a, n);
	InsertionSort(a, n);
	return 0;
}


Measured memory_bytes: 3076
a,b,c,x,y = map(int,input().split())

if c*2 < a+b:
    if x >= y:
        if c*2 <= a:
            print(x*c*2)
        else:
            print(y*c*2+abs(x-y)*a)
    else:
        if c*2 <= b:
            print(y*c*2)
        else:
            print(x*c*2+abs(x-y)*b)
else:
    print(a*x+b*y)
        

Measured memory_bytes: 9048
import math
N = int(input())
max_l = len(str(N))
cnt = 0
for n in range(1, N+1):
    str_n = str(n)
    f_n, l_n = str_n[0], str_n[-1]
    if(f_n == '0' or l_n == '0'):
        continue
    if(f_n == l_n):
        cnt += 1
    i = 0
    while(int(l_n +'0'*i + f_n)<=N):
        cnt += min((N-int(l_n +'0'*i + f_n))//10 + 1, 10**i)
        i += 1

print(cnt)



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

int main() {
  int n;
  scanf("%d",&n);
  int a[100010];
  for (int i=1; i<=n; i++) {
    scanf("%d",a+i);
  }
  a[0]=0;
  a[n+1]=0;
  
  int original=0;
  for (int i=0; i<=n; i++) {
    original += abs(a[i+1]-a[i]);
  }
  
  for (int i=1; i<=n; i++) {
    printf("%d\n",original-abs(a[i+1]-a[i])-abs(a[i]-a[i-1])+abs(a[i+1]-a[i-1]));
  }

  return 0;
}

Measured memory_bytes: 1664
import math
A,B=map(int,input().split())
#A>B
if A<B:
  a,b=B,A
else:
  a,b=A,B
for s in range(int(math.sqrt(b))+1):
  X=abs(a-b)
  if a>X:
    if b>X:
      a,b=b,X
    else:
      a=X
  a,b=b,a%b
  if b==0:
    break
print(A*B//a)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

void solve(int n){
	vl dp(1<<n,LINF);
	dp[0]=0;
	vvl cost(n,vl(n+1));
	rep(i,n)rep(j,n+1)cin>>cost[i][j];
	rep(i,1<<n){
		rep(j,n){
			if(i&(1<<j))continue;
			ll mcos=cost[j][0];
			rep(k,n){
				if(i&(1<<k))chmin(mcos,cost[j][k+1]);
			}
			chmin(dp[i|(1<<j)],dp[i]+mcos);
		}
	}
	cout<<dp[(1<<n)-1]<<endl;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	while(cin>>n,n)solve(n);
}



Measured memory_bytes: 3692
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<queue>
using namespace std;
 
int vis[100009];
typedef pair<int, int> P;
 
 
int main()
{
    int k;
    scanf("%d", &k);
    deque<P> q;
    memset(vis, 0, sizeof(vis));
    q.push_back(make_pair(1, 1));
    while(!q.empty())
    {
        P x = q.front(); q.pop_front();
        if(vis[x.first]) continue;
        vis[x.first] = 1;
        if(x.first == 0)
        {
            printf("%d\n", x.second);
            break;
        }
        q.push_front(make_pair(x.first*10 % k, x.second));
        q.push_back(make_pair((x.first+1) % k, x.second+1));
 
    }
    return 0;
}

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

class Node {
private:
	std::vector<Node*> link_;
	int score_;
public:
	Node() :score_(0) {}
	~Node() {};
	void setLink(Node* p) { link_.push_back(p); }
	void addScore(int s) { score_ += s; }
	int getScore() { return score_; }
	void cascadeScore(int s, Node* parent);
};

void Node::cascadeScore(int s, Node* parent) {
	score_ += s;
	for (auto it = link_.begin(); it != link_.end(); it++) {
		if (*it != parent) {
			(*it)->cascadeScore(score_, this);
		}
	}
}

int main() {
	int N, Q;
	cin >> N >> Q;
	std::map<int, Node*> nodes;
	for (int i = 1; i <= N; i++) {
		Node* n = new Node();
		nodes.emplace(i, n);
	}
	for (int i = 1; i < N; i++) {
		int ia, ib;
		cin >> ia >> ib;
		nodes.at(ib)->setLink(nodes.at(ia));
		nodes.at(ia)->setLink(nodes.at(ib));
	}
	for (int i = 0; i < Q; i++) {
		int p, x;
		cin >> p >> x;
		nodes.at(p)->addScore(x);
	}
	nodes.at(1)->cascadeScore(0, nullptr);


	for (int i = 1; i <= N; i++) {
		if (i == 1) {
			cout << nodes.at(i)->getScore();
		}
		else {
			cout << " " << nodes.at(i)->getScore();
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 36736
#include<bits/stdc++.h>
using namespace std;
#define jxc 1000000007
#define MN 100010
int A(int x,int y){return ((x+y)%jxc+jxc)%jxc;}
int D(int x,int y){return ((x-y)%jxc+jxc)%jxc;}
int M(int x,int y){return ((1ll*x*y)%jxc+jxc)%jxc;}
int P(int x,int y){
	int res=1;
	for(;y;y>>=1,x=M(x,x))if(y&1)res=M(res,x);
	return res;
}
int Fac[MN],Ifac[MN],Inv[MN];
int a[MN];
int C(int x,int y){
	if(x<y)return 0;
	return M(Fac[x],M(Ifac[y],Ifac[x-y]));
}
int f[MN];
int main(){
	Fac[0]=Inv[1]=Fac[1]=Ifac[1]=Ifac[0]=1;
	for(int i=2;i<=100005;++i){
		Fac[i]=M(Fac[i-1],i);
		Inv[i]=M(Inv[jxc%i],(jxc-jxc/i));
		Ifac[i]=M(Ifac[i-1],Inv[i]);
	}
	// for(int i=1;i<=10005;++i)cout<<M(Fac[i],Ifac[i]);
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i)scanf("%d",a+i);
	f[0]=1<<n;
	sort(a+1,a+m+1);
	for(int i=m;i;--i){
		for(int j=(1<<n)-1;j;--j){
			for(int k=0;k<n;++k){
				if(j&(1<<k)){
					f[j]=D(f[j],M(f[j-(1<<k)],M(C((1<<n)-a[i]-j+(1<<k),(1<<k)-1),Fac[1<<k])));
				}
			}
		}
	}int res=0;
	for(int i=0;i<1<<n;++i)res=A(res,M(f[i],Fac[(1<<n)-i-1]));
		cout<<res;
	return 0;
}

Measured memory_bytes: 1664
import java.util.*;

public class Main {
  public static void main(String[] args) throws Exception {
    Scanner sc = new Scanner(System.in);
    while (true) {
      int H = sc.nextInt();
      int W = sc.nextInt();
      if (H == 0 && W == 0) {
        break;
      }
      for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
          System.out.print("#");
        }
        System.out.println();
      }
      System.out.println();
    }
  }
}



Measured memory_bytes: 36460
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
int main(){
int n;
cin >> n;
int mew = 0, hoge = 0;	
REP(i,n){
		int a,b;
		cin >> a >> b;
		if(mew < a){
		mew = max(a,mew);
		hoge = b;
		}
	}
cout << mew+hoge<<endl;
return 0;
}

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

int main() {
  char c;
  cin >> c;
  
  if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<iostream>
#include<algorithm>//next_permutation
#include<complex>
#include<math.h>
#include<sstream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep2(i, j, n) for (int i = j; i < (int)(n); i++)

int f(int n) {
	if (n % 2 == 0) {
		return n / 2;
	}
	else {
		return n * 3 + 1;
	}
}

int main() {
	map<int, bool>a;
	int s;
	cin >> s;
	int nows;
	nows = s;
	int i = 1;
	while (1) {
		if (a.count(nows)) {
			cout << i << endl;
			break;
		}
		else {
			a[nows] = true;
		}
		nows = f(nows);
		i++;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
string i_t_s(int x){
	string t="";
	while(x){
		t+=x%10+'0';
		x/=10;
	}
	reverse(all(t));
	re t;
}
int s_t_i(string t){
	int x=0;
	rep(i,sz(t)){
		x=x*10+(t[i]-'0');
	}
	re x;
}
int n;
ll a[200001];
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	rep(i,n)
	cin>>a[i];
	ll ans=0;
	forn(i,1,n){
		ans+=max(0ll,a[i-1]-a[i]);
		a[i]=max(a[i],a[i-1]);
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 5168
s = gets.chomp
if s == s.reverse
  puts '0'
elsif s.delete('x') != s.delete('x').reverse
  puts '-1'
else
  b = s.delete('x').size.even? ? 1 : 0
  c = (s.delete('x').size / 2.0).ceil
  a = 0
  x = ''
  y = ''
  s.size.times do |i|
    a += 1 if s[i] != 'x'
    if a == c
      x = s[0..i]
      y = s[i+b..-1].reverse
      break
    end
  end
#  puts "x=#{x} y=#{y}"
  i = 0
  j = 0
  cnt = 0
  while i < x.size
#    puts "i=#{i} j=#{j} x[i]=#{x[i]} y[j]=#{y[j]} cnt=#{cnt}"
    if x[i] == y[j]
      i += 1
      j += 1
    elsif y[j] == 'x'
      j += 1
      cnt += 1
    elsif x[i] == 'x'
      i += 1
      cnt += 1
    end
  end
  puts cnt
end

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

int main(){
  int n, m, p;
  while(true){
    cin >> n >> m >> p;
    if(n == 0)
      break;

    int ave = 0,  deno, x;
    for(int i=0; i<n; i++){
      cin >> x;
      if(i+1 == m)
        deno = x;

      ave += x*100;
    }
    if(deno == 0)
      cout << 0 << endl;
    else{
      ave = ave * (100 - p) / (100*deno);
      cout << ave << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 3016