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

typedef pair<int, int> P;
typedef pair<P, int> P2;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
const int X = 123123;
const int Y = 321321;

int A, B;
int D[10][10];
int N;
int down[101], up[101];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> A >> B;
  rep(x, A) rep(y, B) cin >> D[x][y];
  bool ok = true;
  rep(x, A) rep(y, B-1) if (D[x][y] > D[x][y+1]) ok = false;
  rep(x, A-1) rep(y, B) if (D[x][y] > D[x+1][y]) ok = false;
  if (!ok) {
    cout << "Impossible\n";
    return 0;
  }
  vector<P2> edges;
  int s = 0, t = 1;
  N = 2;
  down[0] = s;
  up[0] = t;
  for (int i=1; i<=100; i++) {
    down[i] = N++;
    edges.pb(P2(P(down[i-1], down[i]), X));
  }
  for (int i=1; i<=100; i++) {
    up[i] = N++;
    edges.pb(P2(P(up[i], up[i-1]), Y));
  }
  vector<P2> vs;
  for (int a=0; a<=100; a++) {
    for (int b=0; b<=100; b++) {
      int c = 0;
      for (int x=1; x<=A; x++) {
        for (int y=1; y<=B; y++) {
          c = max(c, D[x-1][y-1]-a*x-b*y);
        }
      }
      vs.pb(P2(P(a, b), c));
      edges.pb(P2(P(down[a], up[b]), c));
    }
  }
  for (int x=1; x<=A; x++) {
    for (int y=1; y<=B; y++) {
      int dist = INF;
      for (P2 p : vs) {
        int a = p._1._1, b = p._1._2, c = p._2;
        dist = min(dist, a*x+b*y+c);
      }
      if (dist != D[x-1][y-1]) {
        cout << "Impossible\n";
        return 0;
      }
    }
  }
  cout << "Possible\n";
  cout << N << " " << edges.size() << "\n";
  for (P2 p : edges) {
    cout << p._1._1+1 << " " << p._1._2+1 << " ";
    int w = p._2;
    if (w == X) cout << "X\n";
    else if (w == Y) cout << "Y\n";
    else cout << w << "\n";
  }
  cout << "1 2\n";
  return 0;
}


Measured memory_bytes: 768
from collections import deque

N=int(input())
graph=[[] for _ in range(N)]
for i in range(N):
    a=int(input())-1
    graph[i].append(a)

d=[float("inf")]*N
d[0]=0
queue=deque([0])
while queue:
    x=queue.pop()
    for y in graph[x]:
        if d[y]!=float("inf"):
            break
        d[y]=d[x]+1
        queue.append(y)

if d[1]==float("inf"):
    print(-1)
else:
    print(d[1])

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

int main(int argc, const char * argv[]) {
    int k;
    cin>>k;
    for (int i = k; i<=999; i++) {
        int a = i%10;
        int b = (i%100-a)/10;
        int c = (i-i%100)/100;
        if (a==b&&a==c) {
            printf("%d\n", i);
            break;
        }
    }
    
    return 0;
}

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


using namespace std;
double pi=3.14159265358979323846264338;
long long sum;
long long ma;
long long n,k,st,x,t;
string s;
long long pr(long long a, long long b){
	long long k=1;
	if(b==0)return 1;
	
	for(int i=0;i<b;i++)k=k*10;
	return k;
}
long long arr[200001];
bool che(long long a){
	long long cur=0;
	for(int i=0;i<n;i++){
		cur+=(arr[i]+a-1)/(a)-1;
	}
	if(cur<=k)return true;
	return false;
}
int main(){
	cin>>s;
	n=s.length();
	k=0;
	for(int i=0;i<n;i++){
		k+=(int)(s[i]-'0');
	}
	if(k%9==0)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

int intpow(int x,int y){
  double a=x,b=y;
  return pow(a,b);
}//(x,y) xをy乗する

int intfabs(int x){
  double a=x;
  return fabs(a);
}//(x) の絶対値

int in(){
  int a;
  cin >> a;
  return a;
}//int型関数の受け取り

void forin(int* x,int y){
  for (int i=0;i<y;i++){
    cin >> x[i];
  }
}//配列の受け取り

main(){
  int n=in(),a=in(),b=in();
  if (a>b) cout << b << " ";
  else cout << a << " ";
  if (n>a+b) cout << '0' << endl;
  else cout << a+b-n << endl;
}


Measured memory_bytes: 256
#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;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	ll n;
	cin>>n>>s;
	ll ans=0;
	range(i,1,n){
		if(s[i]!=s[i-1])ans++;
	}
	cout<<ans+1<<endl;
}


Measured memory_bytes: 512
// F - Surrounded Nodes

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
const ll MOD = 1e9 + 7;

struct Node {
	vector<int> neighbors;
};

int N;
Node nodes[200000];
vector<int> node_cnt[200000]; // node_cnt[i][j]: nodes[i]のj番目のneighborから先のノードの数

// mod p （pは素数）の下でのべき乗を求める
ll mod_pow(ll a, ll n, ll p) {
		ll result = 1;
		while (n > 0) {
			if (n & 1) result = result * a % p;
			a = a * a % p;
			n >>= 1;
		}
		return result;
	};

// mod p （pは素数）の下での逆元を求める（フェルマーの小定理を利用）
ll mod_inverse(ll a, ll p) {
	return mod_pow(a, p-2, p);
}

// mod p （pは素数）の下での除算 (a / b)
ll mod_devide(ll a, ll b, ll p) {
	return a * mod_inverse(b, p) % p;
}

// nodes[i] から先（nodes[i]を含む）のノードの数を返す
// 同時にprev側のノードの数も計算
int dfs(int i, int prev_i) {
	int result = 1;
	int prev_j = -1;
	for (int j=0; j<nodes[i].neighbors.size(); j++) {
		int next_i = nodes[i].neighbors[j];

		if (next_i == prev_i) {
			prev_j = j;
			continue;
		}

		if (node_cnt[i][j] != -1) {
			result += node_cnt[i][j];
			continue;
		}

		node_cnt[i][j] = dfs(next_i, i);
		result += node_cnt[i][j];
	};

	if (prev_j != -1) {
		node_cnt[i][prev_j] = N - result;
	}

	return result;
}

int main() {
	cin >> N;

	int A, B;
	for (int i=0; i<N-1; i++) {
		cin >> A >> B;
		A--;
		B--;
		nodes[A].neighbors.push_back(B);
		node_cnt[A].push_back(-1);
		nodes[B].neighbors.push_back(A);
		node_cnt[B].push_back(-1);
	}

	// node_cnt[i][j]を求める
	dfs(0, -1);

	/*
	// **** debug : check DFS result ****
	for (int i=0; i<N; i++) {
		cout << "node " << i + 1 << " :";
		for (int n : node_cnt[i]) {
			cout << " " << n;
		}
		cout << endl;
	}
	*/

	// nodeごとに穴あき度の期待値を算出し、それを合計する
	// （y/xについて、xの逆元にyを掛けたものがz）
	ll ans = 0;
	ll inv2 = mod_inverse(2, MOD); // 2の逆元
	ll prob_all_white = mod_pow(inv2, N-1, MOD);

	for (int i=0; i<N; i++) {
		if (nodes[i].neighbors.size() == 1) continue; // 端点は期待値0

		// nodes[i]から出ている部分木のうち、nodes[i].neighbors[j] からの木だけが黒を含む確率
		ll prob_one_black = 0;
		for (int j=0; j<nodes[i].neighbors.size(); j++) {
			ll prob = (1 - mod_pow(inv2, node_cnt[i][j], MOD) + MOD) % MOD; // 黒を含む部分木
			prob = (prob * mod_pow(inv2, N - node_cnt[i][j] - 1, MOD)) % MOD; // それ以外
			prob_one_black = (prob_one_black + prob) % MOD;
		}

		ll prob = (1 - prob_all_white + MOD) % MOD;
		prob = (prob - prob_one_black + MOD) % MOD;
		prob = (prob * inv2) % MOD; // そもそもnodes[i]が白

		// 確率がそのまま穴あき度の期待値になる
		ans = (ans + prob) % MOD;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 35456
def main():
    N, M = map(int, input().split(' '))
    A_list = list(map(int, input().split(' ')))
    A_sum = sum(A_list) / (4 * M)
    cnt = 0
    for a in A_list:
        if a >= A_sum:
            cnt += 1
            if A_sum <= cnt:
                break
    if cnt >= M:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <tuple>
#include <utility>
#include <functional>
#include <set>
#include <map>
#include <bitset>
#include <list>

using namespace std;


#define INF pow(10, 9)
// typedef priority_queue<tuple<int,int,int>, vector< tuple<int, int, int> >, greater< tuple<int, int, int> > > PQ;
typedef long long int ll;





int main(void)
{


    ll a, b, c, d;
    cin >> a >> b >> c >> d; // SからTを見る
    ll Max = max(a*c, a*d);
    ll Max2 = max(b*c, b*d);
    Max = max(Max, Max2);

    cout << Max <<endl;




    return 0;
}


Measured memory_bytes: 3604
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		String n = fs.next();
		char c[] = n.toCharArray();
		int len = n.length();
		int a[] = new int[len+1];
		for(int i=0;i<len;i++)a[i+1] = c[i] - '0';
		
		int ans = 0;
		for(int i=len;i>=1;i--) {
			while(a[i]>=10) {
				a[i]-=10;
				a[i-1]++;
			}
			if(a[i]<5)ans+=a[i];
			else if(a[i]==5) {
				if(a[i-1]<5)ans+=a[i];
				else {
					ans+= (10 - a[i]);
					a[i-1]++;
				}
			}
			else {
				ans+= (10 - a[i]);
				a[i-1]++;
			}
		}
		ans += a[0];
		System.out.println(ans);
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

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

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 38240
class String
  def to_ia
    split(/\s/).map {|s| s.to_i}
  end
end
  
def linear_search(subject, search)
  hash = {}
  subject.each do |k|
    hash[k] = true
  end
  ans = 0
  search.each do |s|
    if hash[s]
      ans += 1
    end
  end
  ans
end

STDIN.readline
subject = STDIN.readline.to_ia
STDIN.readline
search = STDIN.readline.to_ia

puts linear_search(subject, search)

Measured memory_bytes: 9096
from collections import deque
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(m)]

# nxt: 一手で行ける部屋のリスト
q = deque([])
path = [-1] * n
nxt = [[] for _ in range(n)]
for i in range(m):
    ab[i].sort()
    # 1とつながっている経路を見つけたらqueueに入れておく
    if ab[i][0] == 1:
        q.append([ab[i][0]-1, ab[i][1]-1])
    nxt[ab[i][0]-1].append(ab[i][1]-1)
    nxt[ab[i][1]-1].append(ab[i][0]-1)


def bfs(queue, visited):
    while len(queue) > 0:
        now = queue.popleft()  # now = [現在地, 目的地]
        dst = now[1]  # dst = 目的地
        if visited[dst] == -1:  # 目的地が未訪問の場合
            visited[dst] = now[0]+1
            for i in range(len(nxt[dst])):
                q.append([dst, nxt[dst][i]])
    return visited


ans = bfs(q, path)
print("Yes")
for i in range(1, n):
    print(ans[i])


Measured memory_bytes: 158576
local n,m=io.read("n","n")
local box={}
local red={}
for i=1,n do
    box[i]=1
    red[i]=false
end
red[1]=true

for i=1,m do
    local x,y=io.read("n","n")
    if red[x] then
        red[y]=true
    end
    box[x]=box[x]-1
    box[y]=box[y]+1
    if box[x]==0 then
        red[x]=false
    end
end

local counter=0
for i=1,n do
    counter=counter+(red[i] and 1 or 0)
end
print(counter)

Measured memory_bytes: 4444
import java.io.*;

class Main
{
	public static void main(String[] args) throws IOException
	{

	BufferedReader br =
		new BufferedReader(new InputStreamReader(System.in));
	

	String str = br.readLine();
	int x = Integer.parseInt(str);


	System.out.println( x*x*x );

	}
}

Measured memory_bytes: 24300
<?php
	fscanf(STDIN, "%d", $N);
    
	$base = 10;
	$i = 10;
	$count = 1;
	$result = 0;
	while ($i <= $N) {
      
      if ($count % 2 != 0) {
        $result += pow($base, $count-1) * 9;
      }
      
      $count++;
      $i = pow($base, $count); 
    }

	if ($count % 2 != 0) {
      $result += $N - pow($base, $count-1) + 1;
    }

	echo ($result);
?>

Measured memory_bytes: 3828
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <utility>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define MOD 1000000007

int main(int argc, char const *argv[]) {
  int A,B;
  cin >> A >> B;
  if(A==1) A = 14;
  if(B==1) B = 14;
  if(A > B) cout << "Alice" << endl;
  if(A == B) cout << "Draw" << endl;
  if(A < B) cout << "Bob" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  long i, n;

  scanf("%ld\n", &n);

  long a[n];

  for(i = 0; i < n; i++){
    if(i == n - 1)
      scanf("%ld\n", &a[i]);
    else
      scanf("%ld ", &a[i]);
  }

  long min = a[0];
  long max = a[0];
  long sum = 0;
  
  for(i = 0; i < n; i++){
    if(min >= a[i])
      min = a[i];
    if(max <= a[i])
      max = a[i];
    sum = sum + a[i];
  }

  printf("%ld %ld %ld\n", min, max, sum);

  return 0;
}

Measured memory_bytes: 680
N = int(input())
TA = []
for i in range(N):
    T, A = map(int, input().split())
    TA.append((T, A))

T, A = TA[0]
answer = T+A
p = 1
prev = p
pT, pA = T, A
for i in range(1,N):
    # (T+A) * p >= prev
    # p >= prev/(T+A)
    T, A = TA[i]
    s = T+A
    p = (answer+s-1)//s
    p1 = (pT+T-1)//T
    p2 = (pA+A-1)//A
    p = max([p,p1,p2])
    pT, pA = p*T, p*A
    answer =  pT+pA
    #print(T, A, p, answer, sep="\t")
print(answer)

    


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

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("in.txt","r",stdin)
#define write()         freopen("out.txt","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%llu",&n)
#define ull             unsigned long long
#define endll           pf("\n")
#define pf              printf
#define PI              acos(-1.0)
#define eps             1e-12
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MX 100005
#define MOD  1000000000
#define mod1 1000000009
#define var    int i,j,c=0,t,l,r,mid,z=0,k,x,y

//int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
//int dy[8]={1,-1,1,-1,1,-1,0,0};
//int dx[4]={1,-1,0,0};  //4 direction
//int dy[4]={0,0,1,-1};
ll n,m,a[200005];

int main()
{
    ll var;
    sfl(n);
    for(i=1;i<n;i++)
    {
        sfl(x);
        a[x]++;
    }
    for(i=1;i<=n;i++)
    {
        pf("%lld\n",a[i]);
    }
}


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

int main() {
    vector<int> a(26,0);
    char ch;
    int x;
    while ( cin >> ch ){
        x = ch - 'a';
        if((x >= 0) && (x < 26)) a[x]++;
        x = ch - 'A';
        if((x >= 0) && (x < 26)) a[x]++;
    }
    
    for (int i = 0; i < 26; i++) {
        ch = i + 'a';
        cout << ch << " : " << a[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3112
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    H, W, K = lr()
    S = []
    for i in range(H):
        S.append([int(s) for s in sr()])
    ans = 2000
    idx = [0]*H
    for div in range(1<<(H-1)):
        g = 0
        for i in range(H):
            idx[i] = g
            if div>>i&1:
                g += 1
        g += 1
        c = [[0]*W for i in range(g)]
        for i in range(H):
            for j in range(W):
                c[idx[i]][j] += S[i][j]
        ok = True
        for i in range(g):
            for j in range(W):
                if c[i][j] > K:
                    ok = False
        if not ok:
            continue
        num = g-1
        now = [0]*g
        def add(j):
            for i in range(g):
                now[i] += c[i][j]
            for i in range(g):
                if now[i] > K:
                    return False
            return True
        for j in range(W):
            if not add(j):
                num += 1
                now = [0]*g
                add(j)
        ans = min(ans, num)
    print(ans)
resolve()

Measured memory_bytes: 3316
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i32 sx, sy, tx, ty, d[2011][2011];

string bfs(i32 sx, i32 sy, i32 tx, i32 ty) {
  d[sx][sy] = 0;
  queue<pair<i32, i32>> q;
  q.emplace(sx, sy);
  while (!q.empty()) {
    i32 i, j;
    tie(i, j) = q.front();
    q.pop();
    i32 di = 1, dj = 0;
    for (i32 k = 0; k < 4; ++k) {
      i32 ti = i + di, tj = j + dj;
      if (0 <= ti && ti < 2011 && 0 <= tj && tj < 2011
          && d[ti][tj] >= (1 << 30)) {
        d[ti][tj] = d[i][j] + 1;
        q.emplace(ti, tj);
      }
      swap(di, dj);
      di = -di;
    }
  }
  i32 i = tx, j = ty;
  string s;
  while (i != sx || j != sy) {
    i32 di = 1, dj = 0;
    i32 k;
    for (k = 0; k < 4; ++k) {
      i32 ti = i + di, tj = j + dj;
      if (0 <= ti && ti < 2011 && 0 <= tj && tj < 2011
          && d[ti][tj] == d[i][j] - 1) {
        s.push_back("LDRU"[k]);
        d[i][j] = -1;
        i = ti;
        j = tj;
        break;
      }
      swap(di, dj);
      di = -di;
    }
    assert(k != 4);
  }
  reverse(begin(s), end(s));
  
  for (i64 i = 0; i < 2011; ++i) {
    for (i64 j = 0; j < 2011; ++j) {
      if (d[i][j] >= 0) d[i][j] = 1 << 30;
    }
  }
  
  return s;
}

int main() {
  cin >> sx >> sy >> tx >> ty;
  sx += 1005;
  sy += 1005;
  tx += 1005;
  ty += 1005;
  for (i64 i = 0; i < 2011; ++i) {
    for (i64 j = 0; j < 2011; ++j) {
      d[i][j] = 1 << 30;
    }
  }
  cout << bfs(sx, sy, tx, ty);
  cout << bfs(tx, ty, sx, sy);
  cout << bfs(sx, sy, tx, ty);
  cout << bfs(tx, ty, sx, sy);
  cout << endl;
  return 0;
}



Measured memory_bytes: 16128
S = input()

if (1 <= int(S[:2]) <= 12) and (1 <= int(S[2:4]) <= 12):
    print('AMBIGUOUS')
elif (0 <= int(S[:2]) <= 99) and (1 <= int(S[2:4]) <= 12):
    print('YYMM')
elif (1 <= int(S[:2]) <= 12) and (0 <= int(S[2:4]) <= 99):
    print('MMYY')
else:
    print('NA')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
void solve()
{
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=1; i<=n; i++)
    {
    	for(ll j=1; j<=n; j++)
    	{
    		if(i*j<n)
    			ans++;
    		else
    			break;
    	}
    }
    cout<<ans<<endl;
}
int main()
{
	#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3792
#include <bits/stdc++.h>
#define inf 1000000000 //1E+9
using namespace std;


int main(){
	int n,L;cin>>n>>L;
	vector<string> s(n);for(int i=0;i<n;i++)cin>>s[i];
	sort(s.begin(),s.end());
	for(int i=0;i<n;i++)cout<<s[i];
	cout<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
lint zyo[200100],rz[200100];
lint mo=1000000007;
lint extgcd(lint a, lint b, lint &x, lint &y) {
  lint g = a; x = 1; y = 0;
  if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
  return g;
}
lint invMod(lint a, lint m) {
  lint x, y;
  if (extgcd(a, m, x, y) == 1) return (x + m) % m;return 0;
}
lint co(int a,int b){
	return zyo[a+b]*rz[a]%mo*rz[b]%mo;
}
int ch[200100];
lint dp[200100],out[200100];
vector<int> gr[200100];
int n;
void dfs(int v,int u){
	ch[v]=0;dp[v]=1;
	rep(i,gr[v].size()){
		int w=gr[v][i];
		if(w==u) continue;
		dfs(w,v);
		dp[v]*=dp[w];dp[v]%=mo;
		dp[v]*=co(ch[v],ch[w]+1);dp[v]%=mo;
		ch[v]+=ch[w]+1;
	}
	//ch[v]++;
}
void dfs2(int v,int u,lint X){
	int c=n-1-ch[v];
	out[v]=dp[v]*X;out[v]%=mo;
	out[v]*=co(c,ch[v]);out[v]%=mo;
	rep(i,gr[v].size()){
		int w=gr[v][i];
		if(w==u) continue;
		lint nX=out[v]*invMod(co(n-2-ch[w],ch[w]+1),mo);nX%=mo;
		nX*=invMod(dp[w],mo);nX%=mo;
		dfs2(w,v,nX);
	}
}
int main()
{
	zyo[0]=1;rep(i,200050) zyo[i+1]=zyo[i]*(i+1)%mo;
	rep(i,200050) rz[i]=invMod(zyo[i],mo);
	int a,b;cin>>n;
	rep(i,n-1){
		cin>>a>>b;a--;b--;
		gr[a].pb(b);gr[b].pb(a);
	}
	dfs(0,-1);
	dfs2(0,-1,1);
	//rep(i,n) cout<<dp[i]<<' '<<ch[i]<<' '<<endl;
	rep(i,n) cout<<out[i]<<endl;
}


Measured memory_bytes: 20980
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m = na()
a = na()
ok = 0
s = sum(a)
for v in a:
    if v*(4*m) >= s:
        ok += 1
if ok >= m:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int lim(int last,int K,vector<int>n){
    int x=0,kurai=1;
    for(int k=K-2;k>=1;k--){
        x+=n[k]*kurai;
        kurai*=10;
    }
    if(last<=n[K-1])x++;
    return x;
}
int main(){
    int N;
    cin>>N;
    if(N<=9){
        cout<<N<<endl;
        return 0;
    }
    vector<int>n;
    while(N){
        n.insert(n.begin(),N%10);
        N/=10;
    }
    int K=n.size();
    int X[2]={};/*
    X[0]:2桁以上ー2桁以上
    X[1]:1桁ー2桁以上
    */
    //X[0]
    for(int i=1;i<=9;i++){
        for(int j=1;j<=9;j++){
            //A=j?i,B=i?j
            for(int ak=0;ak<=K-2;ak++){//Aが先頭と末尾に挟まれている数
                for(int bk=0;bk<=K-2;bk++){//Bが先頭と末尾に挟まれている数
                    
                    int x=1;
                    if(ak<K-2 && bk<K-2){//ABともに桁数がK未満なので、何を入れても問題ない
                        for(int k=0;k<ak+bk;k++){
                            x*=10;
                        }
                        X[0]+=x;
                    }
                    if(ak<K-2 && bk==K-2){//Bの桁数がK
                        if(i<n[0])for(int k=0;k<bk;k++)x*=10;//BはN未満なので、何を入れても問題ない
                        if(i==n[0]){//Bは先頭の桁がNと一致
                            x=lim(j,K,n);
                        }
                        if(i>n[0])continue;//BはNより大きいので、組は作れない
                        for(int k=0;k<ak;k++)x*=10;
                        X[0]+=x;
                    }
                    if(ak==K-2 && bk<K-2){//Aの桁数はK
                        if(j<n[0])for(int k=0;k<ak;k++)x*=10;//AはN未満なので、何を入れても問題ない
                        if(j==n[0]){//Aは先頭の桁がNと一致
                            x=lim(i,K,n);
                        }
                        if(j>n[0])continue;//AはNより大きいので、組は作れない
                        for(int k=0;k<bk;k++)x*=10;
                        X[0]+=x;
                    }
                }
            }
            //AもBもK桁
            int b=max(i,j),s=min(i,j);
            int x=1;
            if(b<n[0])for(int k=0;k<2*K-4;k++)x*=10;
            if(b==n[0]){
                x=lim(s,K,n);
                if(b==s)x*=x;
                else for(int k=0;k<K-2;k++)x*=10;
            }
            if(b>n[0])continue;
            X[0]+=x;
        }
    }
    //X[1]
    for(int i=1;i<=9;i++){
        for(int j=0;j<=K-2;j++){
            int x=1;
            if(j<K-2 || i<n[0])for(int k=0;k<j;k++)x*=10;
            else if(i==n[0])x=lim(i,K,n);
            else continue;
            X[1]+=x;
        }
    }
    X[1]*=2;
    cout<<X[0]+X[1]+9<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int
main()
{
  int a, b;
  cin >> a >> b;
  if (a == b) {
    cout << 1 << endl;
  }
  else {
    int n = (b - 1) / (a - 1);
    int r = (b - 1) % (a - 1);
    if (r > 0) {
      ++n;
    }
    cout << n << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n = gets.to_i
arr = gets.split.map{|i| i.to_i}
maxc = 2<<100
arr.each do |a|
    c = 0
    loop{
        if a%2!=0 then
            break
        else
            a/=2
            c+=1
        end
    }
    maxc = [maxc, c].min
end
puts maxc


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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for ( int i = 0; i < N; i++) cin >> vec.at(i);
  
  sort(vec.begin(), vec.end());
  cout << vec.at(N - 1) -vec.at(0) <<endl;  
}

Measured memory_bytes: 256
import java.util.*;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int h = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int ans = 0;

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
        }

        Arrays.sort(a);
        Arrays.sort(b);

        for (int i = n - 1; i >= 0; i--) {
            if (b[i] > a[n - 1]) {
                h -= b[i];
                ans++;
                if (h <= 0)
                    break;
            }
        }
        if (h > 0) {
            if (h % a[n - 1] == 0)
                ans += h / a[n - 1];
            else if (h % a[n - 1] != 0)
                ans += h / a[n - 1] + 1;
        }
        System.out.println(ans);
        sc.close();
    }
}

Measured memory_bytes: 78760
#include <stdio.h>
#include <string.h>

int main(void)
{
 char card[201], sub[201];
 int m, h, i, j, k;
 int c = 0;
 int l = 0;

while(1){

scanf("%s", card);

if(card[0] == '-')
 break;

scanf("%d", &m);

for(i = 0; i < 202; i++)
{
 if(card[i] != '\0')
   c++;
 else if(card[i] == '\0')
   break;
}

for(i = 0; i < m; i++)
{
 scanf("%d", &h);

for(j = 0; j < h; j++)
  sub[j] = card[j];

for(j = h; j < c; j++)
  card[j-h] = card[j];


  for(j = 0; j < h; j++)
   card[c-h+j] = sub[j];

}
 
 printf("%s\n", card);
 c = 0;

}


return 0;

}



Measured memory_bytes: 2100
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  cin>>n;
  vi a(n);
  rep(i,n)cin>>a[i],a[i]--;
  int ans=0;
  rep(i,n)if(a[a[i]]==i)ans++;
  cout<<ans/2<<endl;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<bits/stdc++.h>
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define ll long long int
#define F first
#define S second
#define f(i,x,n) for(ll i=x;i<n;i++)
using namespace std;
ll solve(int W, ll w[], ll v[], int n){
	ll dp[n+1][W+1];
	f(i,0,n+1){
		f(j,0,W+1){
			if(i==0 || j==0) dp[i][j]=0;
			else if(w[i-1]>j) dp[i][j]=dp[i-1][j];
			else dp[i][j]=max(dp[i-1][j-w[i-1]] +v[i-1], dp[i-1][j]);
		}
	}
	return dp[n][W];
}
int main(){
	int n,W;
	cin>>n>>W;
	ll w[n],v[n];
	f(i,0,n) cin>>w[i]>>v[i];
	cout<<solve(W,w,v,n);
	

	return 0;
	}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

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

	int x = N / 1.08;
	x--;

	for(int i=0; i<3; i++){
		if(100*N<=x*108 && x*108<(N+1)*100){
			cout << x << endl;
			return 0;
		}
		x++;
	}
	cout << ":(" << endl;

	return 0;
}


Measured memory_bytes: 256
#def main(S, b):

if __name__ == '__main__':
    n, a, b = map(int, input().split())

    c = n // (a + b)

    ans = c * a

    if (n - c * (a + b) > a):
        ans += a
    else:

        ans += n - c * (a + b)

    print(ans)


Measured memory_bytes: 2940
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    A, B, C, D = LI()

    L = A + B
    R = C + D
    if L == R:
        print('Balanced')
    elif L > R:
        print('Left')
    else:
        print('Right')

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9964
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const int mo = 1e9 + 7;
typedef long long ll;
#define INF 1 << 30
void solve()
{
    int n;
    cin >> n;
    vector<int> t(n), v(n);
    rep(i, n) cin >> t[i];
    rep(i, n) cin >> v[i];
    int T = 0;
    rep(i, n) T += t[i];
    vector<int> ub(2 * T + 1, INF);
    int x = 0;
    rep(i, n) rep(y, t[i])
    {
        ub[x] = min(ub[x], v[i] * 2);
        ub[x + 1] = min(ub[x + 1], v[i] * 2);
        ub[x + 2] = min(ub[x + 2], v[i] * 2);
        x += 2;
    }
    ub[0] = ub[2 * T] = 0;
    rep(x, 2 * T) ub[x + 1] = min(ub[x + 1], ub[x] + 1);
    for (int x = 2 * T; x > 0; x--)
        ub[x - 1] = min(ub[x - 1], ub[x] + 1);
    double ans = 0;
    rep(x, 2 * T) ans += (ub[x] + ub[x + 1]) / 2.0;
    printf("%.5lf\n", ans / 4);
}
main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    solve();
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int get_cnt(ll x) {
    int ans = 0;
    while(x > 0) {
        x %= int(__builtin_popcount(x));
        ans += 1;
    }
    return ans;
}

int main() {
    int n;
    string x;
    cin >> n >> x;
    vector<int> ans(n, 0);
    ll cnt_1 = 0;
    for(int i = 0; i < n; i++) {
        if (x[i] == '1')
            cnt_1 += 1;
    }
    if (cnt_1 == 0) {
        for(int i = 0; i < n; i++)
            cout << 1 << endl;
        return 0;
    } else if (cnt_1 == 1) {
        for(int i = 0; i < n; i++) {
            if (x[i] == '1') {
                cout << 0 << endl;
            } else {
                if (x.back() == '1' || i == n-1) {
                    cout << 2 << endl;
                } else {
                    cout << 1 << endl;
                }
            }
        }
        return 0;
    }
    ll cur_sub = 0, cur_add = 0;
    ll mod_sub = cnt_1 - 1;
    ll mod_add = cnt_1 + 1;
    reverse(x.begin(), x.end());
    ll fac_sub = 1 % mod_sub;
    ll fac_add = 1 % mod_add;
    for(int i = 0; i < n; i++) {
        if (x[i] == '1') {
            cur_sub = (cur_sub + fac_sub) % mod_sub;
            cur_add = (cur_add + fac_add) % mod_add;
        }
        fac_sub = (fac_sub * 2) % mod_sub;
        fac_add = (fac_add * 2) % mod_add; 
    }
    fac_sub = 1 % mod_sub;
    fac_add = 1 % mod_add;
    vector<int> tmp(n, 0);
    //cout << cnt_1 << endl;
    //cout << cur_sub << " " << cur_add <<endl;
    for(int i = 0; i < n; i++) {
        if (x[i] == '0') {
            tmp[i] = (cur_add + fac_add) % mod_add;
        } else {
            tmp[i] = ((cur_sub - fac_sub) + (mod_sub*100)) % mod_sub;
        }
        ans[i] = get_cnt(tmp[i]) + 1;
        
        fac_sub = (fac_sub * 2) % mod_sub;
        fac_add = (fac_add * 2) % mod_add; 
    }
    reverse(ans.begin(), ans.end());
    for(auto& val: ans)
        cout << val << endl;
    return 0;
}


Measured memory_bytes: 5168
object Main extends App{
  import scala.io.StdIn._
  val Array(n,m)=readLine().split(" ").map(_.toInt)
  val a=readLine().split(" ").map(_.toInt)
  var ans=0
  for{i <- a}{ans+=i}
  println(if(ans>n) -1 else n-ans)
}

Measured memory_bytes: 54900
#include <stdio.h>
#include <limits.h>

int main(int argc, char const *argv[])
{
    long long int a[4];

    scanf("%lld %lld %lld %lld", &a[0], &a[1], &a[2], &a[3]);

    long long int val[4];

    size_t k = 0;
    for (size_t i = 0; i < 2; i++)
    {
        for (size_t j = 2; j < 4; j++)
        {
            val[k++] = a[i] * a[j];
        }
    }

    long long int max = LLONG_MIN;
    for (size_t i = 0; i < 4; i++)
    {
        if (max < val[i])
        {
            max = val[i];
        }
    }

    printf("%lld\n", max);

    return 0;
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 10;
const int p = 1e9 + 7;
int f[maxn+10];
void init(){
    f[0]=1;
    for(int i=1;i<=maxn;i++){
        f[i]=(long long)f[i-1]*i%p;
    }
}

int fast(int a,int n){
    if(n==0)return 1;
    if(n%2)return (long long)a*fast(a,n-1)%p;
    int tmp=fast(a,n/2);
    return (long long)tmp*tmp%p;
}

int C(int n,int m){
    if(n==m||m==0)return 1;
    return ((long long)f[n]*fast(f[m],p-2)%p)*fast(f[n-m],p-2)%p;
}

int main() {
	int x,y;
	scanf("%d%d",&x,&y);
	int t1 = (2*y-x);	
	int t2 = (2*x-y);
	if(t1 % 3 != 0 || t2 %3 != 0 || t1 < 0 || t2 < 0){
		printf("0\n");
	}
	else{
		init();
		t1 = t1/3;
		t2 = t2/3;
		printf("%d\n",C(t1+t2,t1));
	}
    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#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(v) v.begin(), v.end()
#define F first
#define S second
#define INF 1000000000000
#define MOD 10000007
typedef long long ll;
//
int last(int d,int i,vector<int> answer){
   
      int t=0;
    for(int k=1;k<=d;k++){
       
       if(i==answer[d-k]) break;
       t++;
    }
   return t;
}

int main(){
   int D;cin>>D;
   vector<int> dism;
   rep(i,26){
      int a;cin>>a;
      dism.push_back(a);
   }
   vector<vector<int>> point(D,vector<int>(26,0));
   rep(i,D){
      rep(j,26){
         int s;cin>>s;
         point[i][j]=s;
      }
   }
//    vector<int> answer;
//    rep(i,D){
//       int a;cin>>a;
//       answer.push_back(a-1);
//    }
   vector<int> answer(D,-1);
   
   
   rep(i,D){
      ll ma=-INF;
      int ch=0;
      rep(k,26){
         
         ll ans=0;
         answer[i]=k;
      
      ans=ans+point[i][k];
      rep(j,26){
       ans=ans-(dism[j]*(last(i+1,j,answer)));
      }
      if(ans>ma)ch=k;
      ma=max(ma,ans);
      
      }
      answer[i]=ch;
   }
   rep(i,answer.size()){
      answer[i]++;
   }
   for(auto e:answer)cout<<e<<endl;
 //  rep(i,26){  cout<<last(1,i,answer);}
}

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

#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define MOD 998244353

using namespace std;

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

    int N, S;
    cin >> N >> S;
    int result = 0;
    vector<int> dp(S + 1);
    REP(_, N) {
        int A;
        cin >> A;
        RFOR(s, A, S + 1) {
            dp[s] = (dp[s] + dp[s - A]) % MOD;
        }
        dp[0]++;
        if (A <= S) {
            dp[A]++;
        }
        result = (result + dp[S]) % MOD;
    }
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 3652
import java.util.*;

public class Main {
	
	static boolean table[][];
	static int n, m;
	static boolean memo[];
	static int cout;
	static boolean check[];
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		m = sc.nextInt();
		int[] a = new int[m],
			  b = new int[m];
		table = new boolean[n][n];
		for(int i = 0; i < m; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			table[a[i] - 1][b[i] - 1] = true;
			table[b[i] - 1][a[i] - 1] = true;
		}
		memo = new boolean[n];
		check = new boolean[n];
		memo[0] = true;
		Arrays.fill(check, true);
		cout = 0;
		dfs(0);
		System.out.println(cout);
	}
	
	public static void dfs(int p) {
		if(Arrays.equals(memo, check)) {
			cout++;
			return;
		}
		for(int i = 0; i < n; i++) {
			if(table[p][i] == true && memo[i] == false) {
				memo[i] = true;
				dfs(i);
				memo[i] = false;
			}
		}
		return;
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int p[20];

int main()
{
	int n, ans = 0;

	cin >> n;
	rep(i, n) cin >> p[i];
	rep(i, n - 2) {
		if (((p[i] < p[i + 1]) && (p[i + 1] < p[i + 2])) ||
			((p[i] > p[i + 1]) && (p[i + 1] > p[i + 2]))) ans++;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np
import numba
from numba import jit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@jit
def main(n):
  ans = [n]
  m = 0
  while not ans[m] in ans[:m]:
    if n%2 == 0:
      n /= 2
      ans.append(n)
    else:
      n = 3 * n + 1
      ans.append(n)
    m += 1
  return m+1
    
    
  
n = int(input())
print(main(n))

Measured memory_bytes: 111168
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#include<set>
#include <numeric>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define DIVCEIL(a,b) ((a+b-1)/b)
//int CHMAX

int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int MODFACT(int a, int mod) {
	if (a == 0)
		return 1;
	else
		return (a * FACT(a - 1))%mod;
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
int MODnPr(int n, int r, int mod) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++) {
		sum *= i;
		sum = sum % MOD;
	}
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b)
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b)
{
	return  a * b / GCD(a, b);
}
int NUMOFDIV(int n) {
	int ans = 0;
	REP(i, n) {
		if (n % i == 0)
			ans++;
	}
	return ans;
}
int CEIL1(int n) {
	return (n + 9) / 10 * 10;
}
int DIGITSUM(int n) {
	int sum = 0, dig;
	while (n) {
		dig = n % 10;
		sum += dig;
		n /= 10;
	}
	return sum;
}
int DIVTIME(int n, int k) {
	int div = 0;
	while (n % k == 0) {
		div++;
		n /= k;
	}
	return div;
}
int MODPOW(int a, int n, int mod) {
	// a^n mod
	int ans = 1;
	while (n > 0) {
		if (n & 1)
			ans = ans * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return ans;
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool between(int x, int min, int max) {
	if (min < x && x < max)
		return true;
	else
		return false;
}
inline bool PRIMEOR(int x) {
	if (x == 1)
		return false;
	if (x == 2)
		return true;
	if (x % 2 == 0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}
bool SQRTOR(int n) {
	if (sqrt(n) == (int)sqrt(n))
		return true;
	else
		return false;
}
// 順位付け
using namespace std;
#pragma endregion
signed main() {
	int N, T,c,x,min=10000;
	cin >> N >> T;
	vector <int> a(N);
	rep(i, N) {
		cin >> c >> x;
		if (x <= T && c <min)
			min = c;
	}
	if (min != 10000)
		cout << min;
	else
		cout << "TLE";
}

Measured memory_bytes: 256
H,W = map(int,input().split())
mod = 1000000007

a_matrix = []
for _ in range(H):
    a_matrix.append(list(input()))

dp = [[0 for w in range(W+1)] for h in range(H+1)]

dp[1][0] = 1

for w in range(1,W+1):
    for h in range(1,H+1):
        if a_matrix[h-1][w-1] == ".":
            dp[h][w] = (dp[h-1][w] + dp[h][w-1]) % mod
        else:
            dp[h][w] = 0
print(dp[H][W])
        



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

int main() {
  vector<int> X(3);
  for (int i=0; i<3; i++)
    cin >> X.at(i);
  vector<int> X_1(3);
  X_1 = {5,7,5};
  vector<int> X_2(3);
  X_2 = {5,5,7};
  vector<int> X_3(3);
  X_3 = {7,5,5};
  if(X == X_1 || X ==X_2 || X == X_3)
    cout << "YES"<< endl; 
  else
    cout << "NO" <<endl;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;
int L[300001], R[300001];
int main() {
  int N, M; cin >> N >> M;
  vector<string> a(N);
  vector<string> b(M);
  rep(i, N) cin >> a[i];
  rep(i, M) cin >> b[i];
  rep(i, N - M + 1) rep(j, N - M + 1) {
    bool flag = 1;
    rep(k, M) rep(l, M) {
      if (a[i + k][j + l] != b[k][l]) {
        flag = 0;
      }
    }
    if (flag) {
      cout << "Yes\n";
      exit(0);
    }
  }
  cout << "No\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=j;i<n;i++)
int selectionsort(int A[],int n){
    int x=0;
    rep(i,0,n-1){
        int minv=i;
        rep(j,i+1,n){
            if(A[minv]>A[j])minv=j;
        }
        if(minv!=i){
            swap(A[i],A[minv]);
            x++;
        }   
    }
    return x;
}
int main(){
    int n;cin>>n;
    int A[n];
    rep(i,0,n)cin>>A[i];
    int ans=selectionsort(A,n);
    rep(i,0,n-1)cout<<A[i]<<" ";
    cout<<A[n-1]<<endl;
    cout<<ans<<endl;
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using ld=long double;

struct edge{
    P to;
    int cost;
};

int main(){
    int n,m;cin >>n>>m;
    map<P,vector<edge>>g;
    set<P>used;
    deque<edge>que;
    que.emplace_back(edge{P(0,-1),0});
    for (int i = 0; i < m; ++i) {
        int p,q,c;cin >>p>>q>>c;
        p--;q--;
        g[P(p,c)].emplace_back((edge){P(q,c),0});
        g[P(q,c)].emplace_back((edge){P(p,c),0});
        g[P(p,c)].emplace_back((edge){P(q,-1),0});
        g[P(q,c)].emplace_back((edge){P(p,-1),0});
        g[P(p,-1)].emplace_back((edge){P(q,c),1});
        g[P(q,-1)].emplace_back((edge){P(p,c),1});
    }
    int ans=-1;
    while(que.size()){
        edge es=que.front();
        que.pop_front();
        if(used.find(es.to)!=used.end())continue;
        used.insert(es.to);
        if(es.to.first==n-1){
            ans=es.cost;
            break;
        }
        for(auto itr:g[es.to]){
            if(used.find(itr.to)!=used.end())continue;
            if(itr.cost==0)que.emplace_front((edge){itr.to,es.cost});
            else que.emplace_back((edge){itr.to,es.cost+1});
        }
    }
    cout <<ans <<endl;
}


Measured memory_bytes: 74276