akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys


def solve(N: int):
    if N % 2 == 0:              # 偶数
        key = int(N/2)
        M = (N-2)*key
        print(M)
        for i in range(1, key+1):
            for j in range(i+1, N+1):
                if (j <= key) or\
                   (j > key and i % key != (N+1-j) % key):
                    print(i, j)
        for i in range(key+1, N):
            for j in range(i+1, N+1):
                print(i, j)
    else:
        key = int(N/2)
        M = (N-3)*key + N-1
        print(M)
        for i in range(1, key+1):
            for j in range(i+1, N+1):
                if (j <= key) or\
                   (j > key and i % key != (N-j) % key):
                    print(i, j)
                elif j == N:
                    print(i, j)
        for i in range(key+1, N):
            for j in range(i+1, N+1):
                print(i, j)
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

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

int binarySearch(int arr[], int l, int r, int x) 
{ 
    while (l <= r) { 
        int m = l + (r - l) / 2; 
        if (arr[m] == x) 
            return m; 
        else if (arr[m] < x) 
            l = m + 1; 
        else
            r = m - 1; 
    } 
    return -1; 
}

int main(void) {
  int X, N;
  scanf("%d %d", &X, &N);
  int p[N], i;
  for(i = 0; i < N; ++i)
    scanf("%d", &p[i]);
  int b, a, min = 101, ans = 0, absolute;
  qsort(p, N, sizeof(int), comfun);
  for(i = 0; i <= 101; ++i){
    b = binarySearch(p, 0, N - 1, i);
    if(b == -1){
      a = X - i;
      absolute = abs(a);
      if(absolute < min){
        min = absolute;
        ans = i;
      }
    }
    else 
      continue;
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 1732
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1000010;
long long a[N];
long long sum[N];
long long n, m;
long long ans;
void solve()
{
	for(int i = 1 ; i <= n ; i ++)
		sum[i] = sum[i - 1] + a[i];
	for(int i = 1 ; i <= n ; i ++)
	{
		long long tmp;
		if(i & 1)
		{
			int x = (i - 1) >> 1;
			tmp = ((long long)m * x - (sum[n] - sum[n - x])) * 2 + a[n - x] + (sum[n - x - 1] - sum[n - x - x - 1]) * 2;
		}
		else
		{
			int x = i >> 1;
            tmp = (m * (x - 1) - (sum[n] - sum[n - x + 1])) * 2 + ((long long)m - a[n - x + 1]) + (sum[n - x] - sum[n - x - x]) * 2;
		}
		ans = max(ans, tmp);
	}
}
int main()
{
	scanf("%lld%lld", &m, &n);
	for(int i = 1 ; i <= n ; i ++)
		scanf("%lld", &a[i]);
	solve();
	for(int i = 1 ; i <= n ; i ++)
		a[i] = m - a[i];
	reverse(a + 1, a + 1 + n);
	solve();
	printf("%lld", ans);
	return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int X;
  cin >> X;
  int ans = 1;
  for(int i = 2; i <= X; i++) {
    int a = i * i;
    if(a > X) break;
    ans = max(ans, a);
    while(a <= X) {
      ans = max(ans, a);
      a *= i;
    }
  }
  cout << ans << endl;
  return 0;
}

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

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

    vector<int> arr(n), cnt(1e6+10, 0);
    vector<bool> table(1e6+10, false);

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

    sort(arr.begin(), arr.end());
    arr.resize(distance(arr.begin(), unique(arr.begin(), arr.end())));
    int mx_element = arr.back();

    for (auto x : arr) {
        if (cnt[x] > 1) table[x] = true;
        for (int i = 2; x * i <= mx_element; i++) {
            table[x*i] = true;
        }
    }

    int ans = 0;
    for (auto x : arr) {
        ans += (!table[x]);
    }

    cout << ans << endl;


}

Measured memory_bytes: 7980
#include <bits/stdc++.h>
#define F first
#define S second
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;

string s[555];
int cb[555];

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	int fm=0;
	int h=0;
	for (int i=0;i<n;i++){
		cin>>s[i];
	}
	for (int i=0;i<n;i++){
		for (int ii=0;ii<n;ii++){
			if (s[i][ii]=='#'){
				cb[ii]=1;
			}
		}
	}
	for (int i=0;i<n;i++){
		int f=0;
		for (int ii=0;ii<n;ii++){
			if (s[i][ii]=='#') f++;
		}
		if (f) h=1;
		if (cb[i]){
			fm=max(fm, f);
		}
		else{
			fm=max(fm, f-1);
		}
	}
	if (!h){
		cout<<-1<<endl;
		return 0;
	}
	int ne=0;
	for (int i=0;i<n;i++){
		int f=0;
		for (int ii=0;ii<n;ii++){
			if (s[ii][i]=='#') f++;
		}
		if (f<n){
			ne++;
		}
	}
	cout<<n-fm+ne<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int a[100005];
inline int read() {
    int x=0;
    char ch=getchar();
    while (!isdigit(ch)) ch=getchar();
    while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
    return x;
}
int main() {
    int n=read();
    for (int i=1;i<=n;i++) a[i]=read();
    sort(a+1,a+n+1,greater<int>());
    for (int i=1;i<=n;i++) {
        if (a[i+1]<=i && a[i]>=i) {
            int j=0;
            while (a[j+i+1]==i) j++;
            if ((a[i]-i)%2==0 && j%2==0) puts("Second");
            else puts("First");
        }
    }
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

int main(){
    ll N, M;
    cin >> N >> M;
    vll ans = divisor(M);
    ll g = ans.size();
    if(N == 1){
        cout << M;
    }
    else{
    for(int i=0; i<g; i++){
        if(ans[i]*N>M){
            cout << ans[i-1];
            break;
        }
    }    
    }
}

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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long
#define massert(x) if(!(x))return 0;
#define m2assert(x) if(!(x)){int l=0;while(true)l++;}
using namespace std;
main(){
  int n,m,inf=1e8;
  cin>>n>>m;
  
  vector<int> dp((1<<n),inf),vislist;
  vector<bool> visited((1<<n),false);
  dp[0]=0;
  visited[0]=true;
  
  for(int i=0;i<m;++i){
    int a,b,c,k;
    cin>>a>>b;
    c=0;
    for(int i=0;i<b;++i){
      cin>>k;
      c|=(1<<(k-1));
    }
    dp[c]=min(dp[c],a);
    if(!visited[c]){
      visited[c]=true;
      vislist.push_back(c);
    }
  }
  
  bool ref=true;
  while(ref){
    ref=false;
    int vs=vislist.size();
    for(int i=0;i<vs;++i)for(int j=0;j<vs;++j){
      int p=vislist[i],q=vislist[j];
      if(p==q)continue;
      int pq=(p|q);
      m2assert(0<=pq&&pq<(1<<n));
      massert(0<=p&&p<(1<<n));
      if(!visited[pq]){
        ref=true;
        visited[pq]=true;
        vislist.push_back(pq);
        cerr<<"["<<pq<<"<-"<<p<<","<<q<<"]"<<dp[pq]<<"->"<<dp[p]+dp[q]<<"\n";
        dp[pq]=dp[p]+dp[q];
      }
      else if(dp[pq]>dp[p]+dp[q]){
        ref=true;
        cerr<<"["<<p<<","<<q<<"]"<<dp[pq]<<"->"<<dp[p]+dp[q]<<"\n";
        dp[pq]=dp[p]+dp[q];
      }
    }
  }
  int r=dp[(1<<n)-1];
  cout<<(r<inf?r:-1);
}

Measured memory_bytes: 384
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int W = scan.nextInt();
        int[] w = new int[n];
        int[] v = new int[n];
        for(int i = 0; i < n; i++){
            w[i] = scan.nextInt();
            v[i] = scan.nextInt();
        }
        int[][] dp = new int[n + 1][100001];
        for(int i = 0; i < n + 1; i++){
            for(int j = 0; j < 100001; j++){
                dp[i][j] = 1_000_000_001;
            }
        }
        dp[0][0] = 0;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < 100001; j++){
                if(j < v[i]) dp[i + 1][j] = dp[i][j];
                else dp[i + 1][j] = Math.min(dp[i][j], dp[i][j - v[i]] + w[i]);
            }
        }
        for(int i = 100000; i >= 0; i--){
            if(dp[n][i] <= W){
                System.out.println(i);
                return;
            }
        }
        scan.close();
    }

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

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

	int main() {
		long long N, A, B, C, D; cin >> N >> A >> B >> C >> D;
		string S; cin >> S;
		if (C < D) {
			for (long long i = A; i < D; i++) {
				if (S.at(i) == '#' && S.at(i - 1) == '#') {
					cout << "No" << endl;
					return 0;
				}
			}
			cout << "Yes" << endl;
		}
		else {
			for (long long i = A; i < C; i++) {
				if (S.at(i) == '#' && S.at(i - 1) == '#') {
					cout << "No" << endl;
					return 0;
				}
			}
			for (long long i = B; i < D + 1; i++) {
				if (S.at(i) == '.' && S.at(i - 1) == '.' && S.at(i - 2) == '.') {
					cout << "Yes" << endl;
					return 0;
				}
			}
			cout << "No" << endl;
		}
	}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int i,j,H,W;
    char a;
    cin >> H >> W;
    
    for(i=0;i<W+2;i++){
        cout << "#";
    }
    cout << endl;
    for(i=0;i<H;i++){
        cout << "#";
        for(j=0;j<W;j++){
            cin >> a;
            cout << a;
        }
        cout << "#"<<endl;
    }

    for(i=0;i<W+2;i++){
        cout << "#";
    }
  cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define MAX 10000
#define INFTY (1<<20)
#define WHITE 0//未発見
#define GRAY 1//発見済み未確定
#define BLACK 2//確定済み

int n;//num of vertexes
vector<pair<int,int> > v_list[MAX+1];//頂点の隣接リスト(vector)を要素として持つ配列(添え字が頂点番号)

//http://homepage2.nifty.com/well/Operator.html#PAREN
class greaterInt{
public:
	bool operator() (pair<int,int>& a,pair<int,int>& b){
		return a.second > b.second;
	}
};

void dijkstra(){
	priority_queue<pair<int,int>,vector<pair<int,int> >,greaterInt> PQ;//<頂点番号,挿入時点での最短距離>
	int color[MAX];//各頂点の状態を格納する配列
	int d[MAX];//各頂点までの現在の最短距離を格納する変数

	for(int i=0;i<n;i++){
		d[i] = INFTY;
		color[i] = WHITE;
	}

	d[0] = 0;
	PQ.push(make_pair(0,0));//make_pairを使うと勝手にpairで宣言した型に直してくれる
	color[0] = GRAY;

	//PQ.empty() == trueのときこれ以上更新はなくこれまであった更新に関してはすべて処理
	//が終わっている状態
	while( !PQ.empty() ){
		pair<int,int> f = PQ.top();PQ.pop();
		int u = f.first;//今回確定する頂点番号
		
		if( color[u] == BLACK ) continue;//continue break http://kotazi.com/archives/1383
		//以下ではf.second == d[u]が保障される

		color[u] = BLACK;

		for(int j = 0;j < v_list[u].size();j++ ){
			int v = v_list[u][j].first;//はじめの[]は配列要素番号，二つ目の[]はベクトルの要素番号
			if(color[v] == BLACK) continue;
			if( d[v] > d[u] + v_list[u][j].second){
				d[v] = d[u] + v_list[u][j].second;
				PQ.push(make_pair(v,d[v]));
				color[v] = GRAY;
			}
		}
	}

	for(int i = 0;i < n;i++){
		cout <<i <<" " <<(d[i] == INFTY ? -1 : d[i]) <<endl;//http://msmori.blogspot.jp/2011/01/3.html
		//cout <<i <<" " <<d[i] <<endl;
	}
}

int main(){
	int k, u, v, c;

	cin >>n;
	for(int i = 0;i < n;i++){
		cin >>u >>k;
		for(int j = 0;j < k;j++){
			cin >>v >>c;
			v_list[u].push_back(make_pair(v,c));
		}
	}
	dijkstra();


	return 0;
}

Measured memory_bytes: 6308
N = int(input())
D, X = list(map(int, input().split()))
A = [int(input()) for _ in range(N)]
result = X
for n in range(N):
    if D % A[n] == 0:
        result += (D // A[n])
    else:
        result += (D // A[n]) + 1
print(result)

Measured memory_bytes: 3060
n, m = map(int, input().split())

cond = []
for _ in range(m):
    s, c = map(int, input().split())
    cond.append((s, c))
inf = float('infinity')
ans = inf
for i in range(10 ** n):
    string = str(i)
    if len(string) != n:
        continue
    for s, c in cond:
        if len(string) < s:
            break
        if string[s - 1] == str(c):
            continue
        else:
            break
    else:
        ans = min(ans, i)
if ans == inf:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 38256
a,b,c = map(int, input().split())
if a <= b and b <= c:
    print(a,b,c)
elif a <= c and c <= b:
    print(a,c,b)
elif b < a and a < c:
    print(b,a,c)
elif b <= c and c <= a:
    print(b,c,a)
elif c <= a and a <= b:
    print(c,a,b)
else:
    print(c,b,a)


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

int main(){
  int r,d,x;
  cin >> r >> d >>x;
  vector<int> n(10);
  n.at(0)=r*x-d;
  cout << n.at(0) << endl;
  for(int i=1;i<10;i++){
    n.at(i)=r*n.at(i-1)-d;
    cout << n.at(i) << endl;
  }
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CMultiplication3 solver = new CMultiplication3();
        solver.solve(1, in, out);
        out.close();
    }

    static class CMultiplication3 {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            long a = s.nextLong(), b = (s.nextChar() - '0') * 100 + s.nextChar() * 0 + (s.nextChar() - '0') * 10 + (s.nextChar() - '0');
            w.println(a * b / 100);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public long nextLong() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }

            while (!isSpaceChar(c));
            return res * sgn;
        }

        public char nextChar() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            return (char) c;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 25572
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int> x(n);
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    int ans=1e9;
    for(int i=0;i+k-1<n;i++){
        int l=x[i],r=x[i+k-1];
        ans=min(ans,min(abs(l)+abs(r-l),abs(r)+abs(r-l)));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
 
using namespace std;
 
int main(){
    int N; cin>>N;
    vector<int> sequenceP(N);
    vector<int> sequenceQ(N);
    for(int i=0;i<N;i++)cin>>sequenceP.at(i);
    for(int i=0;i<N;i++)cin>>sequenceQ.at(i);
    vector<int> sequence(N);
    for(int i = 0;i<N;i++)sequence.at(i)=sequenceP.at(i);
    sort(sequence.begin(),sequence.end());
    int count=0;
    int A,B;
    do{
        count++;
        if(sequence==sequenceP)A=count;
        if(sequence==sequenceQ)B=count;
    }while(next_permutation(sequence.begin(),sequence.end()));

    int ans = abs(A-B);
    cout<<ans<<endl;
}



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

#define ll long long int
#define ull unsigned long long int
#define db double
#define ld long double
#define MOD 1000000007
#define inf (1LL << 62)
#define pi acos(-1.0)
#define si(a) scanf("%lld",&a)
#define sd(n) scanf("%lf", &n)
#define for1(i, stop) for(ll i = 1; i <= stop; i++)
#define for0(i, stop) for(ll i = 0; i < stop; i++)
#define rep1(i, start) for(ll i = start; i >= 1; i--)
#define rep0(i, start) for(ll i = (start-1); i >= 0; i--)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define pb(v,a) v.push_back(a)
#define pll pair <ll, ll>
#define mp make_pair
#define pbp(v,a,i) v.push_back(make_pair(a,i))
#define srt(v) sort(v.begin(),v.end())
#define rv(v) reverse(v.begin(),v.end())
#define ms(n, i) memset(n, i, sizeof(n))
#define debug printf("Debug\n");
#define en '\n'



#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

string multiply(string num1, string num2)
{
    int len1 = num1.size();
    int len2 = num2.size();
    if (len1 == 0 || len2 == 0)
    return "0";

    // will keep the result number in vector
    // in reverse order
    vector<int> result(len1 + len2, 0);

    // Below two indexes are used to find positions
    // in result.
    int i_n1 = 0;
    int i_n2 = 0;

    // Go from right to left in num1
    for (int i=len1-1; i>=0; i--)
    {
        int carry = 0;
        int n1 = num1[i] - '0';

        // To shift position to left after every
        // multiplication of a digit in num2
        i_n2 = 0;

        // Go from right to left in num2
        for (int j=len2-1; j>=0; j--)
        {
            // Take current digit of second number
            int n2 = num2[j] - '0';

            // Multiply with current digit of first number
            // and add result to previously stored result
            // at current position.
            int sum = n1*n2 + result[i_n1 + i_n2] + carry;

            // Carry for next iteration
            carry = sum/10;

            // Store result
            result[i_n1 + i_n2] = sum % 10;

            i_n2++;
        }

        // store carry in next cell
        if (carry > 0)
            result[i_n1 + i_n2] += carry;

        // To shift position to left after every
        // multiplication of a digit in num1.
        i_n1++;
    }

    // ignore '0's from the right
    int i = result.size() - 1;
    while (i>=0 && result[i] == 0)
    i--;

    // If all were '0's - means either both or
    // one of num1 or num2 were '0'
    if (i == -1)
    return "0";

    // generate the result string
    string s = "";

    while (i >= 0)
        s += std::to_string(result[i--]);

    return s;
}

int main()
{
	_fastio
	ll n;
	ll a,gn=1;
	string s,ss="1000000000000000000",ans="1";
	cin>>n;
	while(n--)
	{
		cin>>s;
		if(s=="0" || ans=="0")
			ans="0";
		else if(ans.size()>=ss.size() && ans>ss)
			ans="-1";
		else if(ans!="-1")
		{
			ans=multiply(ans,s);
		}

	}
	if(ans.size()>=ss.size() && ans>ss)
		ans="-1";
	cout<<ans<<en;
}


Measured memory_bytes: 3724
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
using namespace std;
vector<int> c = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int main(){
	int N, M;
	cin >> N >> M;
	vector<int> A(M);
	for (int i = 0; i < M; i++){
		cin >> A[i];
	}
	set<int> st;
	for (int i = 0; i < M; i++){
		st.insert(A[i]);
	}
	vector<vector<int>> num(8);
	for (int i = 0; i < M; i++){
		num[c[A[i]]].push_back(A[i]);
	}
	for (int i = 0; i < 8; i++){
		sort(num[i].begin(), num[i].end());
		reverse(num[i].begin(), num[i].end());
	}
	int mn = -1;
	for (int i = 0; i < 8; i++){
		if (!num[i].empty()){
			mn = i;
			break;
		}
	}
	string ans = "";
	while (N >= 36){
		N -= mn;
		ans += '0' + num[mn][0];
	}
	//DP
	vector<vector<bool>> dp(20, vector<bool>(36, false));
	dp[0][0] = true;
	for (int i = 0; i < 19; i++){
		for (int j = 0; j < 36; j++){
			if (dp[i][j]){
				for (int k = 0; k < 8; k++){
					if (!num[k].empty() && j + k < 36){
						dp[i + 1][j + k] = true;
					}
				}
			}
		}
	}
	int L = 0;
	for (int i = 0; i < 20; i++){
		if (dp[i][N]){
			L = i;
		}
	}
	while (L > 0){
		for (int i = 9; i >= 1; i--){
			if (st.count(i) && N >= c[i]){
				if (dp[L - 1][N - c[i]]){
					L--;
					N -= c[i];
					ans += '0' + i;
					break;
				}
			}
		}
	}
	sort(ans.rbegin(), ans.rend());
	cout << ans << endl;
}

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

int main(){
	int n;
	cin >> n;
	int p[101], m[101][101];

	for (int i = 1; i <= n; i++) {
		cin >> p[i - 1] >> p[i];
	}

	for (int i = 1; i <= n; i++) m[i][i] = 0;
	for (int l = 2; l <= n; l++) {
		for (int i = 1; i <= n - l + 1; i++) {
			int j = i + l - 1;
			m[i][j] = (1 << 21);
			for (int k = i; k <= j-1; k++) {
				m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}
	cout << m[1][n] << endl;
}


Measured memory_bytes: 3136
#include <stdio.h>
int main(void){
    int a;
    long long wa = 0;
    scanf("%d", &a);
    for (int i = 1; i <= a; i++){
        if ( i % 3 != 0 && i % 5 != 0){
            wa += i;
            
        }
    }
    printf("%lld\n", wa);
}

Measured memory_bytes: 1736
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };

double a, b, c, d, e, f;
double moto, minn = 9999999;
double anssa, anszen;
bool flag[62][62][62][62];

double func(double na, double nb, double nc, double nd) {

	if (flag[(int)na][(int)nb][(int)nc][(int)nd] == true) {
		return 0;
	}

	flag[(int)na][(int)nb][(int)nc][(int)nd] = true;

	if (na * 100 + nb * 100 + nc + nd > f) {
		return 0;
	}

	//if ((nc + nd)!= 0 && minn > abs(moto - ((nc + nd) / ((nc + nd) + (na * 100 + nb * 100))))) {
	//if ((nc + nd) != 0 && moto - ((nc + nd) / ((nc + nd) + (na * 100 + nb * 100))) >= 0 && minn > moto - ((nc + nd) / ((nc + nd) + (na * 100 + nb * 100)))) {
	if (moto - ((nc + nd) / ((nc + nd) + (na * 100 + nb * 100))) >= 0 && minn > moto - ((nc + nd) / ((nc + nd) + (na * 100 + nb * 100)))) {
		minn = moto - ( (nc + nd) / ((nc + nd) + (na * 100 + nb * 100)) );
		anssa = nc + nd;
		anszen = (nc + nd + (na * 100 + nb * 100));
		//cout << na << " " << nb << " " << nc << " " << nd << " " << anszen << " " << ((nc + nd) / ((nc + nd) + (na * 100 + nb * 100))) <<  endl;
	}


	func(na + a, nb, nc, nd);
	func(na , nb + b, nc, nd);
	func(na , nb, nc + c, nd);
	func(na , nb, nc, nd + d);


	return 0;
}

signed main() {
	
	memset(flag, false, sizeof(flag));

	cin >> a >> b >> c >> d >> e >> f;
	moto = e / (100 + e);

	func(0, 0, 0, 0);

	//cout << minn << endl;
	if (abs(moto - anssa / anszen) > moto) {
		cout << a * 100 << " " << 0 << endl;
	}
	else {
		cout << anszen << " " << anssa << endl;
	}

	return 0;
}

Measured memory_bytes: 14720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
static const int INF = 2000000000;



int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  int ans = 0;
  rep(i, n){
    cin >> a[i];
    ans += a[i];
  }  
  if (ans % 10) {
    cout << ans << endl;
    return 0;
  }
  else {
    sort(ALL(a));
    rep(i, n){
      ans -= a[i];
      if (ans % 10){
        cout << ans << endl;
        return 0;
      } else {
        ans += a[i];
      }
    }
  }
  cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>

const long long INF = 1000000007;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int , pii> piii;
typedef pair<pii, pii> piiii;

int d;
int arr[10011];
int dp[10011][101];

int main() {	
	string s;
	getline(cin, s);
	int len = s.length();
	for (int i = len; i >0; i--) arr[i] = s[len-i] - '0';
	scanf("%d", &d);
	int tmp = 0;
	for (int i = 2; i <= len; i++) tmp += arr[i];
	if (d == 1) {
		ll x[10011];
		x[1] = 1;
		for (int i = 2; i <= 10001; i++) x[i] = (x[i - 1] * 10) % INF;
		ll ans = 0;
		for (int i = 1; i <= len; i++) {
			ans = (ans + x[i] * arr[i]) % INF;
		}
		printf("%lld\n", ans);
		return 0;
	}
	for (int i = 1; i <= 10001; i++) {
		for (int j = 0; j < 100; j++) dp[i][j] = 0;
	}
	for (int i = 0; i <= 9; i++) {
		dp[1][i%d]++;
	}
	for (int i = 2; i <= 10001; i++) {
		for (int j = 0; j <= 9; j++) {
			//i번째자리가 j인 경우
			for (int k = 0; k < d; k++) dp[i][(j + k) % d] = (dp[i][(j+k)%d]+dp[i - 1][k])%INF;
		}
	}
	/*for (int i = 1; i <= 2; i++) {
		for (int j = 0; j < d; j++) printf("%d ", dp[i][j]);
		printf("\n");
	}*/
	int ans = 0;
	int cur = len;
	int sum = 0;
	while (cur!=1) {
		if (arr[cur] == 0) {
			cur--;
			continue;
		}
		ans = (ans + dp[cur - 1][sum]) % INF;
		sum = (sum + d - 1) % d;
		arr[cur] --;
	}
	int cnt = 0;
	for (int i = 0; i <= arr[1]; i++) {
		if ((tmp + i) % d == 0) cnt++;
	}
	printf("%d\n", (ans + cnt -1+INF)%INF);
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
int main(){
  	long long a,b,ans=0;
  	cin >> a >> b;
  	if(a!=0){
  		if(b>=2){
  			if(a*2<=b){
  				ans+=a;
  				b-=a*2;
  			}else{
  				ans+=b/2;
  				b-=(b/2)*2;
  			}
  		}
  	}
	ans+=b/4;
  	cout << ans << endl;
  	return 0;
}


Measured memory_bytes: 384
line = input().split()

hontai = int(line[0])
ashi = int(line[1])
flag = "true"

for i in range(hontai+1):
  kame = int(i)
  tsuru = int(hontai-kame)
  if ashi == (4*kame)+(2*tsuru):
    print("Yes")
    flag = "false"
    break

if flag=="true":
  print("No")

Measured memory_bytes: 9192
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * (n)
        
    def find(self, x):
        if self.parents[x] < 0:     # 根ならその番号を返す
            return x
        else:                       # 根でないならその要素で再検索
            self.parents[x] = self.find(self.parents[x])    # 走査過程で親を書き換え
            return self.parents[x]
        
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:                  # 既に同じ木に属している場合
            return
        
        # 違う木に属している場合は高い方の木に低い方を併合
        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]  # 併合される側の要素数を加算
        self.parents[y] = x                 # 併合する側の親を書き換え
    
    def size(self, x):
        return -self.parents[self.find(x)]
    
    def issame(self, x, y):
        return self.find[x] == self.find(y)


'''
参考
https://qiita.com/K_SIO/items/03ff1fc1184cb39674aa#d-friends
'''
if __name__ == '__main__':
    N, M = map(int, input().split())
    uf = UnionFind(N)

    for _ in range(M):
        A, B = map(int, input().split())
        uf.union(A-1, B-1)
    
    ans = 0

    for i in range(N):
        ans = max(ans, uf.size(i))
    
    print(ans)


Measured memory_bytes: 14540
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

//桁数
ll GetDigit(ll num)
{
  return log10(num) + 1;
}

//約数全列挙
vector<ll> enum_div(ll n)
{
  vector<ll> ret;
  for (ll i = 1; i * i <= n; ++i)
  {
    if (n % i == 0)
    {
      ret.push_back(i);
      if (i * i != n)
      {
        ret.push_back(n / i);
      }
    }
  }
  sort(begin(ret), end(ret));
  return ret;
}

//累乗(xのn乗%mod)
ll modpow(ll x, ll n, ll mod = MAX)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

//階乗
ll factorial(ll n)
{
  if (n > 0)
    return n * factorial(n - 1);
  else
    return 1;
}

ll modinv(ll a, ll mod)
{
  ll b = mod, u = 1, v = 0;
  while (b)
  {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= mod;
  if (u < 0)
    u += mod;
  return u;
}

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

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

void Main()
{
  ll a; cin >> a;
  fin(a + a * a + a * a * a);
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}


Measured memory_bytes: 3720
object Main extends App {
  val N = readLine.toInt
  val arr = readLine.split(" ").map(_.toInt).toList
  
  def devide(arr: Seq[Int], count: Int): Int = {
    val devided = arr.map(_ / 2)
    if (arr.exists(_ % 2 == 1)) count
    else devide(devided, count + 1)
  }
  
  println(devide(arr, 0))
}

Measured memory_bytes: 27336
#include <stdio.h>

int fibonatch(int a);

int k;
int z[44];


int main(void)
{
	z[0] = 1;
	z[1] = 1;
	
//	printf("%d", fibonatch(2));
	
	scanf("%d", &k);
	
	printf("%d\n", fibonatch(k));
	
	return (0);
}

int fibonatch(int a) {
	if (a == 0 || a == 1) {
		return (1);
	}
		
	fibonatch(a - 1);
	
	z[a] = z[a - 1] + z[a - 2];
	
	
	return (z[a]);
}




Measured memory_bytes: 2052
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define MOD 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=350;
//↑templete
signed main(){
	string S;
	cin>>S;
	int ans=0;
	for(int i=1;i<S.length();i++)
		if(S[i]!=S[i-1])
			ans++;
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 512
#include <cstdio>
#include <cstring>

char A[200010];
int len;
int cnt[26];
long long res;

int main()
{
	int i;
	scanf("%s" ,&A);
	len = strlen(A);
	for(i=0; i<len; i++){
		cnt[A[i]-'a'] ++;
	}
	for(i=0; i<26; i++){
		cnt[i] = len-cnt[i];
	}
	res = 0;
	for(i=0; i<len; i++){
		res += cnt[A[i]-'a'];
	}
	res /= 2;
	res ++;
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <stack>
using namespace std;
int main(void){
    stack<int> st;
    string x;
    int a, b;
    while(cin >> x){
        if(x == "+"){
            a = st.top();
            st.pop();
            b = st.top();
            st.pop();
            st.push(a+b);
        }
        else if(x == "-"){
            a = st.top();
            st.pop();
            b = st.top();
            st.pop();
            st.push(b-a);
        }
        else if(x == "*"){
            a = st.top();
            st.pop();
            b = st.top();
            st.pop();
            st.push(a*b);
        }
        else{
            st.push(stoi(x));
        }
    }
    cout << st.top() << endl;
    

    return 0;
}



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

using namespace std;

int main()
{
  int N, T;
  cin >> N ;
  vector <int> x(N);
  vector <int> y(N);
  vector <int> h(N);
  
  for( int i=0;i<N;i++ )
    cin >> x[i] >> y[i] >> h[i];

  for( int cx=0;cx<=100;cx++ )
    for( int cy=0;cy<=100;cy++ )
      {
	int hh = -1;
	int min_h = -1;
	int flg = false;
	for( int i=0;i<N;i++ )
	  {
	    int tmp = abs(x[i]-cx)+abs(y[i]-cy);
	    if( h[i]>0 )
	      {
		if( (hh!= -1 && hh != h[i]+tmp)
		    || (min_h!=-1 && min_h<h[i]+tmp) )
		  {
		    flg = true;
		    break;
		  }
		hh = h[i]+tmp;
	      }
	    else
	      {
		if( (hh!=-1 && tmp < hh) )
		  {
		    flg = true;
		    break;
		  }
		if( min_h==-1 || tmp < min_h)
		  min_h = tmp;
	      }
	  }
	if(flg)
	  continue;
	
	if( hh != -1 )
	  cout <<  cx << " " << cy << " " << hh << endl;
	else
	  cout <<  cx << " " << cy << " " << min_h << endl;
	return 0;
      }
}


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

#define int long long int
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define lb lower_bound
#define ub upper_bound
#define srt(a) sort(a.begin(),a.end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
#define mxe(a) *max_element(a.begin(),a.end())
#define mne(a) *min_element(a.begin(),a.end())
#define endl '\n'
#define mod 1000000007
#define INF64 1e18
const int N=3005;
int dp[N][N];
void solve(){
  int n ;cin>>n;
  vi a(n+1);
  for(int i=1;i<=n;i++)
    cin>>a[i];
  for(int i=n;i>0;i--)
    for(int j=i;j<=n;j++)
      dp[i][j]=max(a[i]-dp[i+1][j],a[j]-dp[i][j-1]);
  cout<<dp[1][n];
}

int32_t main(){
  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
  #endif
  
  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);

  int T=1;
  //cin>>T;
  for(int TT=1;TT<=T;TT++){
    solve();
  }
}

Measured memory_bytes: 49744
#include <stdio.h>

int main() {
	int n,a,b;
	scanf("%d %d %d\n", &n, &a, &b);
	unsigned long int x[n];
	for(int i=0; i<n; i++) scanf("%lu", &x[i]);
	
	unsigned long int ans=0;
	for(int i=0; i<n-1; i++){
		if(a*(x[i+1]-x[i]) < b) ans += a*(x[i+1]-x[i]);
		else ans += b;
	}
	
	printf("%lu", ans);
	return 0;
}

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

int main() {
  int a;
  cin >> a;
  
  int first_num = a % 10; // 一の位
  int second_num = (a % 100 - first_num) / 10; // 十の位
  int third_num = (a - second_num * 10 - first_num) / 100; // 百の位
  
  cout << third_num + second_num + first_num << endl;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;

    while(true){
        c -= b;
        if(c <= 0){
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
        if(a <= 0){
            cout << "No" << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3632
import math

a,b,h,m = map(int, input().split())

min_args = m*6
h_args = (h*60 + m)*0.5
arg = max(min_args - h_args, h_args - min_args)
rad = math.radians(arg)
c_2 = a**2 + b**2 - 2*a*b*math.cos(rad)
ans = math.sqrt(c_2)
print(ans)

Measured memory_bytes: 9508
#include <iostream>
#include <cmath>

using namespace std;

int main() {
  long long H;
  cin >> H;

  int bunretsu_kaisuu = 0;
  while (H > 1) {
    H /= 2;
    bunretsu_kaisuu++;
  }
  
  long long ans = 0;
  for (int i = 0; i <= bunretsu_kaisuu; i++){
    ans += pow(2, i);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
	int x, h;
	while (true) {
		cin >> x >> h;
		if (x==0 && h==0) break;
		
		double surface_area = static_cast<double>(x*x) + 2.0 * static_cast<double>(x) * sqrt(static_cast<double>(h*h+x*x/4.0));
		cout << fixed << setprecision(6) << surface_area << endl;
	}
	
	return 0;
}

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

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type / Class / Struct Definitions:
using ll = long long;
using ull = unsigned long long;

//Constants:
const int INF = (1ll << 30) - 1;  //nearly 1.07e9
const ll INFLL = 1ll << 60;       //nearly 1.15e18
const int MOD = 1e9 + 7;
const long double EPS = 1.0e-14;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);

//================ Main Loop ================
int main() {
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    int max = 0;
    ll sum = 0;
    rep(i, n) {
        cin >> a[i];
        if(i > 0) {
            sum += a[i] - a[i - 1];
            chmax(max, a[i] - a[i - 1]);
        }
    }
    sum += a[0] + k - a[n - 1];
    chmax(max, a[0] + k - a[n - 1]);
    cout << sum - max << endl;
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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

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


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

#define all(x) (x).begin(),(x).end()
#define init() \
  ios::sync_with_stdio(false); \
  cin.tie(0)

using namespace std;

using ll = long long;
using ull = unsigned long long;

template<typename M, typename N>
constexpr common_type_t<M, N> gcd(M a, N b) {
  return a == 0 ? b
    : b == 0 ? a
    : gcd(b, a % b);
}

template <typename M, typename N>
constexpr common_type_t<M, N> lcm(M a, N b) {
  return a * b / gcd(a, b);
}

int main() {
  init();

  int n;
  cin >> n;
  vector<int> a(n);
  for(int i =0; i<n; i++){
    cin >> a[i];
  }
  sort(all(a));
  auto res = unique(all(a));
  a.erase(res, a.end());
  cout << a.size() << '\n';

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll         long long
#define fl(i,n)    for(i=0;i<n;i++)
#define fld(i,a,b) for(i=a;i>b;i--)
#define fli(i,a,n) for(i=a;i<n;i++)
#define inp(i,a,n) for(i=0;i<n;i++) {cin>>a[i];}
#define op(i,a,n)  for(i=0;i<n;i++) {cout<<a[i]<<" ";}
#define pb         push_back
#define mp         make_pair
#define F          first 
#define S          second
#define mod        998244353
#define all(x)     x.begin(),x.end()    
#define speedup    ios_base::sync_with_stdio(false),cin.tie(0)
using namespace std;
void comp() {
	ll i,j,k,m,n;
	ll a,b,c;
	cin>>n>>k;
	vector<ll>v1(n+1);
	fl(i,n) {
		cin>>v1[i+1];
	}
	bool vis[n+1]={0};
	int dis[n+1]={0};
	queue<ll>q;
	q.push(1);
	vis[1]=1;
	dis[1]=0;
	ll temp;
	vector<ll>v3;
	int start;
	while(!q.empty()) {
		temp=q.front();
		v3.pb(temp);
		q.pop();
		if(vis[v1[temp]]==0) {
			q.push(v1[temp]);
			vis[v1[temp]]=1;
			dis[v1[temp]]=dis[temp]+1;
		}
		else {
			start=v1[temp];
			break;
		}
	}
	if(k<=dis[start]+1) {
		cout<<v3[k]<<"\n";
	}
	else {
		k-=dis[start];
		k%=(v3.size()-dis[start]);
		cout<<v3[dis[start]+k]<<"\n";
	}

}

int main() {
    speedup;
    ll i=0,t;
    t=1;
    //cin>>t;
    while(t--) {
        comp();
    }
    return 0;
}

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

string num (int x) {
    string res = to_string(x);
    while (int(res.size()) < 6)
        res = "0" + res;
    return res;
}

signed main () {
    int n, m;
    cin >> n >> m;
    vector < vector < pair < int, int > > > region(n + 1);
    for (int i = 0; i < m; ++i) {
        int p, y;
        cin >> p >> y;
        region[p].push_back(make_pair(y, i));
    }
    for (int i = 0; i <= n; ++i)
        sort(region[i].begin(), region[i].end());
    vector < string > ans(m);
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j < int(region[i].size()); ++j) 
            ans[region[i][j].second] = num(i) + num(j + 1);
    }
    for (string s: ans)
        cout << s << '\n';
}


Measured memory_bytes: 12416
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

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

    int n; cin >> n;
    bool data[n][20];

    F0R(i, n) {
        int cur; cin >> cur;
        F0R(j, 20) {
            if (cur % 2 == 1) {
                data[i][j] = true;
            } else data[i][j] = false;
            cur /= 2;
        }
    }

    bool cur[20]; memset(cur, 0, sizeof(cur));

    F0R(i, 20) {
        if (data[0][i]) cur[i] = true;
    }

    ll ans = 0;
    ll firstInserted = 0;
    FOR(i, 1, n) {
        bool works = true;
        F0R(j, 20) {
            if (data[i][j] && cur[j]) works = false;
        }

        while (works == false) {
            ll c = i;
            ans += c - firstInserted;
            F0R(j, 20) {
                if (data[firstInserted][j]) cur[j] = false;
            }
            firstInserted++;
            works = true;
            F0R(j, 20) {
                if (data[i][j] && cur[j]) works = false;
            }
        }

        F0R(j, 20) {
            if (data[i][j]) cur[j] = true;
        }

    }

    ll t = (ll) n - firstInserted;
    ans += t * (t + 1) / 2;

    cout << ans;
    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343

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

//how many string of digits with length len and contains numNonZero non-zero digits
int cnt(int len, int numNonZero) {
    if (len == 0) {
        return (numNonZero == 0 ? 1 : 0);
    }

    if (numNonZero < 0 || numNonZero > len)
        return 0;

    if (numNonZero == 0)
        return 1;
    else if (numNonZero == 1)
        return 9 * len;
    else if (numNonZero == 2)
        return 9 * 9 * ((len * len - len)/2);
    else if (numNonZero == 3)
        return 9 * 9 * 9 * (len*(len - 1)*(len - 2))/6;
}

//how many integers below s that contains exactly k non zero digits
int f(string s, int k) {
    int len = (int) s.length();
    int numNonZeroSoFar = 0;

    int answer = 0;
    for (int i = 0; i < len; i++) {
        int currDigit = (int) (s[i] - '0');
        for (int dig = currDigit - 1; dig >= 0; dig--) {
            if (dig == 0)
                answer += cnt(len - i - 1, k - numNonZeroSoFar);
            else
                answer += cnt(len - i - 1, k - numNonZeroSoFar - 1);
        }

        if (currDigit != 0)
            numNonZeroSoFar += 1;
    }

    return answer;
}

int main() {
    string N;
    int K;

    cin >> N >> K;

    int answer = 0;
    answer += f(N, K);

    int numNonZero = 0;
    for (int i = 0; i < N.length(); i++) {
        if (N[i] != '0')
            numNonZero += 1;
    }

    if (numNonZero == K)
        answer += 1;

    cout << answer << endl;
}


Measured memory_bytes: 256
def main():
    h,w= map(int, input().split())
    a = []
    for i in range(h):
        a.append(input())
    cnt = len(a[0])+2
    print("#" * cnt)
    for _ in a:
        print(f'#{_}#')
    print("#" * cnt)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9168
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;

int rec(int v, std::vector<int>& dp, std::vector<std::vector<int>>& G){
    if(dp[v] != -1) return dp.at(v);

    int ans = 0;
    for(auto nv : G.at(v)){
        chmax(ans, rec(nv,dp,G) + 1);
    }
    return dp.at(v) = ans;
}

int main(){
    int N, M;
    std::cin >> N >> M;

    std::vector<std::vector<int>> G;
    G.assign(N, std::vector<int>());
    for(int i=0; i<M; i++){
        int x, y; std::cin >> x >> y; --x; --y;
        G.at(x).push_back(y);
    }

    std::vector<int> dp(N, -1);
    //vを始点にした時の有効パスの最長のものの長さ
    int ans=0;
    for(int v=0; v<N; ++v){
        chmax(ans, rec(v,dp,G));
    }

    std::cout << ans;
    return 0;
}


Measured memory_bytes: 8832