akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
using datas=pair<ll,ll>;
using tdata=pair<datas,ll>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

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

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}

int main(){
  ll i,j,N,M,K;
  cin>>N;
  vector<ll> v(N);
  string ss;cin>>ss;
  if(N>=3200){
    cout<<ss<<endl;
  }else{
    cout<<"red"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

int n,m;
static int degree[100000];
static vector<int> connect[100000];
static int color[100000];
static vector<int> vertex;

void operation(int start) {
	int i = start;
	for (int j = 0; j < connect[i].size(); j++) {
		if (color[connect[i][j]] == -1) {
			color[connect[i][j]] = 0;
			operation(connect[i][j]);
		}
	}
};

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

	for (int i = 0; i < n; i++) {
		degree[i] = 0;
		color[i] = -1;
		vertex.push_back(i);
	}

	for (int i = 0; i < m; i++) {
		int x, y, z;
		cin >> x >> y >> z;

		degree[x - 1]++;
		degree[y - 1]++;
		connect[x - 1].push_back(y - 1);
		connect[y - 1].push_back(x - 1);
	}

	int count = 0;
	bool check = true;

	while (true) {
		if (vertex.empty()) { break; }
		check = false;
		int start;
		while (true) {
			if (color[vertex[vertex.size() - 1]] == -1) {
				start = vertex[vertex.size() - 1];
				vertex.pop_back();
				check = true;
				break;
			}
			vertex.pop_back();

			if (vertex.empty()) { break; }
		}
		if (check == false) { break; }

		color[start] = 0;
		operation(start);
		count++;
	}

	

	cout << count << endl;
}

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

using namespace std;
using ll = long long;


// count 0...n divisible by x
ll f(ll n, ll x) {
  if (n<0) return 0;
  return  n/x + 1;
}

int main() {
  ll a,b,x;
  cin>>a>>b>>x;
  cout<<f(b,x)-f(a-1,x);
  return 0;
}

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

int main(){
    double ans = 0;
    int n; cin >> n;
    vector<int> v(n); rep(i,n) cin >> v.at(i);

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

    ans += (v.at(0) + v.at(1)) / 2.0;
    for(int i = 2; i < v.size(); i++){
        ans = (ans + v.at(i)) / 2.0;
    }

    cout << fixed << ans << endl;
}

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

const int limit=50;

int n,m;
int a[limit],b[limit];

bool graph[limit][limit];
bool visited[limit];

void dfs(int v){
    visited[v]=true;
    for(int v2=0; v2<n; v2++){
        if(graph[v][v2]==false) continue;
        if(visited[v2]==true) continue;
        dfs(v2);
    }
}

int main(void){
    cin >> n >> m;
    for(int i=0; i<m; i++){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
    }

    int ans=0;

    for(int i=0; i<m; i++){
        graph[a[i]][b[i]]=graph[b[i]][a[i]]=false;

        for(int j=0; j<n; j++) visited[j]=false;
        dfs(0);

        bool bridge=false;
        for(int j=0; j<n; j++){
            if(visited[j]==false) bridge=true;
        }
        if(bridge) ans++;

        graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;

    }   

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int a,J[1000];
void push(int);
int pop();
void push(int x){
  J[++a]=x;
}
int pop(){
  a--;
  return J[a+1];
}

int main(){
  int c,d;
  a=0;
  char b[100];
  
  while(scanf(" %s ",b) != EOF){
    if(b[0]=='+'){
      c=pop();
      d=pop();
      push(c + d);
      
    }else if(b[0]=='-'){
      d=pop();
      c=pop();
      push(c-d);
      
    }else  if(b[0]=='*'){
      c=pop();
      d=pop();
      push(c*d);
      
    }else{
      push(atoi(b));
    }
  }
  printf("%d\n",pop());
  return 0;
}



Measured memory_bytes: 2144
# -*- coding: utf-8 -*-

N, K = map(int, input().split())

if K == 0:
    ans = N ** 2
else:
    ans = 0
    for b in range(K+1, N+1):
        var = N % b
        if var >= K:
            ans += var - K + 1
        var2 = b - K
        var3 = N // b
        ans += var2 * var3
print(ans)


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

public class Main {
    
    class Answer {
        int X, Y;
        
        public int solve() {
            if (X % Y == 0) return -1;
            
            for (int i = 2; i < Integer.MAX_VALUE; i++) {
                if ( (X * i) % Y != 0 ) {
                    return X * i;
                }
            }
            return -1;
        }
        
        public void main(FastScanner in, PrintWriter out) {
            X = in.nextInt();
            Y = in.nextInt();
            out.println( solve() );
        }
        
        public void p(Object o) { System.out.print(o); }
        public void pl(Object o) { System.out.println(o); }
        public void arp(int[] o) { pl( Arrays.toString(o) ); }
        public void arpp(int[][] o) { 
            for (int i = 0; i < o.length; i++) {
                for (int j = 0; j < o[0].length; j++) { p(o[i][j] + " "); }
                pl("");
            }
        }
        public void ck(Object o1, Object o2) { pl(o1 + " " + o2); }
        public void ckk(Object o1, Object o2, Object o3) { pl(o1 + " " + o2 + " " + o3); }
        public void ckkk(Object o1, Object o2, Object o3, Object o4) { 
            pl(o1 + " " + o2 + " " + o3 + " " + o4);
        }
    }

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        
        Main problem = new Main();
        Answer ans = problem.new Answer();
        ans.main(in, out);
        
        out.close();
        in.close();
    }
    
    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        public FastScanner(InputStream in) { br = new BufferedReader(new InputStreamReader(in)); }
        public int nextInt() { return Integer.parseInt(next()); }
        public long nextLong() { return Long.parseLong(next()); }
        public double nextDouble() { return Double.parseDouble(next()); }
        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try { st = new StringTokenizer(br.readLine()); } 
                catch (IOException e) { e.printStackTrace(); }
            }
            return st.nextToken();
        }
        public String nextLine() {
            String str = "";
            try { str = br.readLine();
            } catch (IOException e) { e.printStackTrace(); }
            return str;
        }
        public void close() throws IOException { br.close(); }
    }
}

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

long long a;
int b;
int c;

int solve() {
  scanf("%lld %d.%d", &a, &b, &c);
  printf("%lld\n", a * (b * 100 + c) / 100);
  return 0;
}

int main() {
  int t = 1;
  // scanf("%d", &t);
  for (int tc = 0; tc < t; ++tc) {
    // printf("Case #%d: ", tc+1);
    solve();
  }
  return 0;
}


Measured memory_bytes: 3828
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi >
#define vvvi vector<vvi >
#define pii pair<int,int>
#define INF (int)1e9
#define MOD (int)1e9+7
typedef long long llong;
using namespace std;

int main(){
	int n,m;
	cin>>n>>m;
	
	if(m==0){
		vi dp(n+1,0);
		dp[0]=1;
		dp[1]=1;
		for(int i=2;i<=n;++i){
			dp[i]=dp[i-2]+dp[i-1];
			dp[i]%=MOD;
		}
		
		//REP(i,n+1) cout<<dp[i]<<" ";
		
		cout<<dp[n]<<endl;
		return 0;
	}
	
	vi a(m);
	REP(i,m) cin>>a[i];
	
	vi dp(n+1,0);
	dp[0]=1;
	dp[1]=1;
	int now=0;
	if(a[now]==1){
		dp[1]=0;
		now++;
		if(now==m) now--;
	}
	for(int i=2;i<=n;++i){
		if(i!=a[now]){
			dp[i]=dp[i-2]+dp[i-1];
			dp[i]%=MOD;
		}else{
			now++;
			if(now==m) now--;
		}
	}

	cout<<dp[n]<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp(a, b) make_pair(a, b)
#define pb(t) push_back(t)
#define ft first
#define sc second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll N, M;
vector<ll> out;
vector<ll> g[MAX];
ll p[MAX];
ll indeg[MAX];
ll V[MAX];

void bfs(ll s) {
    ll u, v, i;
    queue<ll> q;
    q.push(s);
    V[s]=1;
    
    while(q.size()) {
        u=q.front(); q.pop();
        out.pb(u);
        for(i=0; i<g[u].size(); i++) {
            v=g[u][i];
            indeg[v]--;
            if(V[v]==0 && indeg[v]==0) {
                V[v]=1;
                q.push(v);
            }
            
        }
    }
    
}

int main(void) {
    ll i, j;
    cin >> N >> M;
    
    for(i=0; i<N-1+M; i++) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        g[a].pb(b);
        indeg[b]++;
    }
    
    for(i=0; i<N; i++)
        if(V[i]==0 && indeg[i]==0)
            bfs(i);
    
    memset(p, -1, sizeof(p));
    for(i=0; i<N; i++) {
        ll u=out[i];
        for(j=0; j<g[u].size(); j++) {
            ll v=g[u][j];
            p[v]=u;
        }
    }
    
    for(i=0; i<N; i++)
        pt(p[i]+1);
}




Measured memory_bytes: 9588
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

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

    int upper, bottom;
    int cnt = 0;
    for (int i=1; i<6; i++) {
        if (i%2 == 0) {
            continue;
        }

        if (i==1) {
            bottom = 1;
        } else {
            bottom = pow(10, i-1);
        }
        upper = pow(10, i) - 1;


        if (bottom > n) {
            break;
        }

        if (n <= upper) {
            cnt += n-bottom+1;
        } else {
            cnt += upper-bottom+1;
        }
    }

    cout << cnt;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Coins
            var lines = ReadLines(4);
            int a = lines[0];
            int b = lines[1];
            int c = lines[2];
            int x = lines[3];
            int counts = 0;

            for(int i = 0; i <= a; i++)
            {
                for (int j = 0; j <= b; j++)
                {
                    int money = 500 * i + 100 * j;
                    int count = (x - money) / 50;

                    if (count >= 0 && count <= c)
                    {
                        counts++;
                    }
                }
            }
            
            Console.WriteLine(counts);
        }

        static List<int> ReadLines(int count = 0)
        {
            //[summary]コンソールの値を読み込む
            var numbers = new List<int>();

            //読み込む行数が未指定のときは、1行目の値を"count"とみなす
            if (count == 0)
            {
                string s = Console.ReadLine().TrimEnd();
                count = int.Parse(s);
            }

            for (int i = 0; i < count; i++)
            {
                string s = Console.ReadLine().TrimEnd();
                numbers.Add(int.Parse(s));
            }

            return numbers;
        }
    }
}

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

const int MAX = 1e5 + 10;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N; cin >> N;
    vector<int> dp(MAX, MAX);

    dp[0] = 0;
    for (int n = 1; n <= 1e5; ++n) {
        int p = 1;
        while (p <= n) {
            dp[n] = min(dp[n], dp[n - p] + 1);
            p *= 6;
        }
        p = 1;
        while (p <= n) {
            dp[n] = min(dp[n], dp[n - p] + 1);
            p *= 9;
        }
    }

    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
using namespace std;

int main() {
        int n, k;
        scanf("%d %d", &n, &k);
        vector<pair<int, int>> a(n);
        for (int i = 0; i < n; i ++) {
                scanf("%d %d", &a[i].first, &a[i].second);
        }
        vector<int> candidate;
        candidate.push_back(k);
        for (int p = 31; p >= 0; p --) {
                if ((k >> p) & 1) {
                        int tmp = k;
                        tmp &= ~(1 << p);
                        for (int q = p - 1; q >= 0; q --) {
                                tmp |= 1 << q;
                        }
                        candidate.push_back(tmp);
                }
        }
        long long ans = 0;
        for (auto it : candidate) {
                long long res = 0;
                for (int i = 0; i < n; i ++) {
                        if (it == (a[i].first | it)) {
                                res += a[i].second;
                        }
                }
                ans = max(ans, res);
        }
        printf("%lld\n", ans);
        return 0;
}



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

int main(){
  int n,max=0,b=0;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(max<a[i]){
      max = a[i];
      b = i;
    }
  }
  sort(a,a+n);
 for(int i=0;i<n;i++){
   if(i!=b)
     cout << max << endl;
   else
     cout << a[n-2] << endl;
 }
}

Measured memory_bytes: 2432
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
using namespace std;

int main() {
	const long long int mod = 1000000007;
	map<long long int, long long int>mp;
	long long int  s[200][200];
	//cout << fixed << setprecision(10);
	long long int n, m, a[200] = {}, res = 0,one=0,two=0;
	char ch[200001],onech,twoch;
	cin >> n;

	while (1) {
		if (n == 0) { return 0; }
		one = 0;
		two = 0;
		res = 0;
		for (int i = 0; i < n; i++) {
			cin >> ch[i];
		}
		for (int i = 0; i < n; i++) {
			a[ch[i]]++;
			one = 0;
			two = 0;
			for (int j = 'A'; j <= 'Z'; j++) {
				if (a[j] > one) { two = one; twoch = onech; one = a[j]; onech = j; }
				else if (a[j] > two) { two = a[j]; }
			}
			if (one  >= two+n-i) {
				cout << onech << " " << i+1<< endl;
				res = 1;
				i=n;
			}
		}

		if (res == 0) {
			cout << "TIE" << endl;
		}

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

		cin >> n;
	}
}


Measured memory_bytes: 3072
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();

		if (Math.abs(a - b) <= d && Math.abs(c - b) <= d || Math.abs(c - a) <= d) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();

	}

}


Measured memory_bytes: 35644
using System;

namespace ConsoleApp4
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();

            char last = s[s.Length - 1];
            if(last == 's')
            {
                Console.WriteLine(s + "es");
            }
            else
            {
                Console.WriteLine(s + "s");
            }
        }
    }
}


Measured memory_bytes: 25692
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
    int N;
    cin >> N;
    pint A[N];
    rep(i,N){
        cin >> A[i].first;
        A[i].second=i+1;
    }
    sort(A,A+N);
    rep(i,N) cout << A[i].second << " ";
}


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

int main() {
	ll n;
	cin>>n;
	if(n%2==1) cout<<0;
	else{
		ll c=0;
		n/=2;
		while(n>0){
			c+=n/5;
			n/=5;
		}
		cout<<c<<endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	char number[11];
	int i,j;
	while(1) {
		if(scanf("%s",number)==-1)break;
		for(i=0;i<10;i++)number[i]-='0';
		for(i=9;i>0;i--) {
			for(j=0;j<i;j++) {
				number[j]=(number[j]+number[j+1])%10;
			}
		}
		printf("%d\n",(int)number[0]);
	}
	return 0;
}

Measured memory_bytes: 0
// https://atcoder.jp/contests/dp/tasks/dp_o

#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <limits>

using namespace std;

long long helper(const vector<vector<int>>& match, vector<vector<long long>>& dp, int states, int idx) {
	if (idx >= match.size()) return 1;
	if (dp[idx][states] >= 0) return dp[idx][states];
	long long total = 0;
	for (int i = 0; i < match.size(); i++) {
		if (match[idx][i] == 0) continue;
		if (states & (1 << i)) continue;
		total = (total + helper(match, dp, states | (1 << i), idx + 1)) % 1000000007;
	}
	return dp[idx][states] = total;
}

int main (int argc, char* argv[]) {
	int n;
	cin >> n;

	vector<vector<int>> match(n, vector<int>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> match[i][j];
		}
	}

	vector<vector<long long>> dp(n, vector<long long>(2097152, -1));
	cout << helper(match, dp, 0, 0) << endl;
}


Measured memory_bytes: 360832
#include <stdio.h>

int main(void){
   char str[100001];
   int i,len=0;
   
   scanf("%100000s",str);
   
   for(i=0;str[i]!='\0';i++){
       len++;
   }
   
   for(i=0;i<len-1;i++){
       if(str[i] == str[i+1]){
           printf("%d %d\n",i+1,i+2);
           return 0;
       }
   }
   
   for(i=0;i<len-2;i++){
       if(str[i] == str[i+2]){
           printf("%d %d\n",i+1,i+3);
           return 0;
       }
   }
   
   printf("-1 -1\n");
   return 0;
}


Measured memory_bytes: 256
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <list>
#include <string>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;

int main()
{
    int A, B;
    cin >> A >> B;

    int ret = 0;
    REP(i, 2)
    {
        if (A >= B)
        {
            ret += A;
            A--;
        }
        else
        {
            ret += B;
            B--;
        }
    }

    cout << ret << endl;
}

void cheatsheet()
{
    // loop
    // vector<int> vec(10);
    vector<int> vecloop;
    REP(i, 10)
    {
        vecloop.push_back(i);
    }

    // swap
    int a = 1;
    int b = 5;
    swap(a, b); // -> a = 5, b = 1

    // sort
    int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    sort(arr, arr + 9, greater<int>()); // 9 8 7 6 5 4 3 2 1

    // lower
    vector<int> vec(arr, end(arr));
    sort(vec.begin(), vec.end());
    cout << lower_bound(vec.begin(), vec.end(), 2)[0]; // 2

    // map
    map<Pll, ll> m;
    m[Pll(10, 100)] = 100;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int N, M; 
int par[114514] = {}; 
int depth[114514] = {}; 
int find(int x){
	if(par[x] == x){
		return x;
	}
	else{
		return par[x] = find(par[x]); 
	}
}
void unite(int x, int y){
	x = find(x); 
	y = find(y); 
	if(x == y) return;
	else if(depth[x] < depth[y]){
		par[x] = y; 
	}else{
		par[y] = x; 
		if(depth[x] == depth[y]) depth[x] ++; 
	}
}
bool same(int x, int y){
	return find(x) == find(y); 
}
int main(){
	cin >> N >> M; 
	int A[100010] = {}; 
	for(int i = 1; i <= N; i++){
		cin >> A[i]; 
	}
	for(int i = 1; i <= N; i++){
		par[i] = i, depth[i] = 0; 
	}
	for(int m = 0; m < M; m++){
		int x, y; 
		cin >> x >> y; 
		unite(x, y); 
	} 
	int ans = 0; 
	for(int i = 1; i <= N; i++){
		if(same(i, A[i])) ans ++; 
	}
	cout << ans << endl; 
}

Measured memory_bytes: 1408
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define INF 100000000000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define MAXN 1<<20
int t[MAXN], lazy[MAXN];

void init(){
	fill_n(t,MAXN,INF);
	fill_n(lazy,MAXN,INF);
}

void push(int v) {
    t[v*2] = min(lazy[v],t[2*v]);
    lazy[v*2] = min(lazy[v],lazy[2*v]);
    t[v*2+1] = min( t[2*v+1], lazy[v]);
    lazy[v*2+1] = min(lazy[v], lazy[2*v+1] ) ;
    //lazy[v] = INF;
}

void update(int v, int tl, int tr, int l, int r, int addend) {
    if (l > r) 
        return;
    if (l == tl && tr == r) {
        t[v] = min(addend,t[v]);
        lazy[v] = min(addend,lazy[v]);
    } else {
        push(v);
        int tm = (tl + tr) / 2;
        update(v*2, tl, tm, l, min(r, tm), addend);
        update(v*2+1, tm+1, tr, max(l, tm+1), r, addend);
        t[v] = min(t[v*2], t[v*2+1]);
    }
}

int query(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return INF;
    if (l <= tl && tr <= r)
        return t[v];
    push(v);
    int tm = (tl + tr) / 2;
    return min(query(v*2, tl, tm, l, min(r, tm)), 
               query(v*2+1, tm+1, tr, max(l, tm+1), r));
}

int n,m,X[MAXN],T[MAXN],P[MAXN],B[MAXN],ans[MAXN] ;
vector<pair<int,int>> adj[MAXN];
int dist[MAXN];

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

	init();
	cin >> n >> m;
	for(int i=0;i<m;i++){
		int l, r, c;
		cin >> l >> r >> c;
		l--;r--;
		adj[l].pb({r,c});
	}
	update(1,0,n-1,0,0,0);
  for(int i=0;i<n;i++){
  	dist[i] = query(1,0,n-1,i,i);
  	for(auto t:adj[i]){
  		int cur = dist[i]+t.sc;
  		int l = i, r = t.fs;
  		update(1,0,n-1,l,r,cur);
  	}
  }  
  if(dist[n-1]>=INF){
  	dist[n-1]=-1;
  }
  cout << dist[n-1] << endl;

return 0;
}
///....


Measured memory_bytes: 47104
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
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;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

void solve(int w, int h) {
    vvi hor, var; 
    REP(i, 2*h-1) {
        int t;
        if (i%2 == 0) t = w-1;
        else t = w;

        vi v(t);
        REP(j, t) cin >> v[j];
        if (i%2 == 0) var.emplace_back(v);
        else hor.emplace_back(v);
    }

    queue<pii> q;
    q.push(pii(0, 0));
    vvi dist(h, vi(w, -1));
    dist[0][0] = 0;

    int dx[] = {0, 1, 0, -1};
    int dy[] = {-1, 0, 1, 0};
    while (!q.empty()) {
        pii now = q.front();
        q.pop();

        REP(i, 4) {
            int nx = now.first + dx[i];
            if (!INRANGE(nx, 0, w-1)) continue;
            int ny = now.second + dy[i];
            if (!INRANGE(ny, 0, h-1)) continue;

            if (dist[ny][nx] != -1) continue;
            if (i == 0) { //↑
                assert(INRANGE(now.second-1, 0, (int)hor.size()));
                assert(INRANGE(now.first, 0, (int)hor[0].size()));
                if (hor[now.second-1][now.first] == 1) continue;
            } else if (i == 1) {//→
                assert(INRANGE(now.second, 0, (int)var.size()));
                assert(INRANGE(now.first, 0, (int)var[0].size()));
                if (var[now.second][now.first] == 1) continue;
            } else if (i == 2) {//↓
                assert(INRANGE(now.second, 0, (int)hor.size()));
                assert(INRANGE(now.first, 0, (int)hor[0].size()));
                if (hor[now.second][now.first] == 1) continue;
            } else {//←
                assert(INRANGE(now.second, 0, (int)var.size()));
                assert(INRANGE(now.first, 0, (int)var[0].size()));
                if (var[now.second][now.first] == 1) continue;
            }

            q.push(pii(nx, ny));
            dist[ny][nx] = dist[now.second][now.first] + 1;
        }
    }

    if (dist[h-1][w-1] == -1) cout << 0 << endl;
    else cout << dist[h-1][w-1]+1 << endl;
}

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

    int w, h;
    while (true)
    {
        cin >> w >> h;
        if (w==0 and h==0) break;

        solve(w, h);
    }
    

    return 0;
}



Measured memory_bytes: 3240
nums = [int(input()) for i in range(5)]
maxleft = 0
m = -1
for i in range(5):
    temp = 10 - nums[i] % 10
    if temp > maxleft and temp != 10:
        maxleft = temp
        m = i

total = 0
for i in range(5):
    if i != m and nums[i] % 10 != 0:
        total += nums[i] - nums[i] % 10 + 10
    else:
        total += nums[i]
print(total)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(v) v.begin(), v.end()
#define revall(v) v.rbegin(), v.rend()
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){ if(y<h && y>=0 && x<w && x>=0) return true; return false; }
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; }





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> a(100010);
	rep(i,n){
		int b;cin >> b;
		if(b <= 100000) a.at(b)++;
	}
	int ans = n;
	rep(i,100001){
		if(a.at(i) >= i) ans -= i;
	}
	cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (a < 1 || a > 9 || b < 1 || b > 9) {
        cout << -1 << endl;
    } else {
        cout << a*b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
A,B = map(int,input().split())
S = 0
if B-A <= 20:
  for i in range(A,B+1):
    S ^= i
  print(S)
else:
  if A%4 == 1:
    S ^= A
    S ^= A+1
    S ^= A+2
    S ^= A+3
    S ^= A+4
    L = [B-1,B-2,B-3,B-4]
    for i in range(4):
      if L[i]%4 == 1:
        A = L[i]+1
        break
    for i in range(A,B+1):
      S ^= i
    print(S)
  elif A%4 == 2:
    S ^= A
    S ^= A+1
    S ^= A+2
    S ^= A+3
    L = [B-1,B-2,B-3,B-4]
    for i in range(4):
      if L[i] % 4 == 1:
        A = L[i]+1
        break
    for i in range(A,B+1):
      S ^= i
    print(S)
  elif A%4 == 3:
    S ^= A
    S ^= A+1
    S ^= A+2
    L = [B-1,B-2,B-3,B-4]
    for i in range(4):
      if L[i] % 4 == 1:
        A = L[i]+1
        break
    for i in range(A,B+1):
      S ^= i
    print(S)
  else:
    S ^= A
    S ^= A+1
    L = [B-1,B-2,B-3,B-4]
    for i in range(4):
      if L[i] % 4 == 1:
        A = L[i]+1
        break
    for i in range(A,B+1):
      S ^= i
    print(S)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = n; i >= n; i--)

#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))

#define endl "\n"
#define pb push_back
#define rtn return
#define elif else if

#define INF 2000000000	//int型は2 * 10^9ぐらいまで
#define MOD 1000000007
 
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};

typedef long long ll;
typedef unsigned long long ull;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

   int n, l[1000], r[1000], ans = 0;
   cin >> n;
   REP(i, n) cin >> l[i] >> r[i];

   REP(i, n) ans += r[i] - l[i] + 1;

   cout << ans << endl;
   
   rtn 0;
}

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

const int maxn = (int)(1e5) + 5;
char s[maxn];

int main() {
	scanf("%s", s + 1);
	int n = strlen(s + 1), res = 0, l = 1, r = n;
	while (l < r) {
		if (s[l] != s[r]) {
			if (s[l] == 'x') ++res, ++l; else if (s[r] == 'x') ++res, --r; 
			else return printf("-1\n"), 0;
		} else l++, r--;
	}
	return printf("%d\n", res), 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int N=105;
int s1[N],s2[N],a[N];
int main (){
	int n,ans=1<<30;scanf ("%d",&n);
	for (int i=1;i<=n;i++) scanf ("%d",&a[i]);
	for (int i=1;i<=n;i++) s1[i]=s1[i-1]+a[i];
	for (int i=n;i>=1;i--) s2[i]=s2[i+1]+a[i];
	for (int i=1;i<=n;i++) ans=min(ans,abs(s1[i]-s2[i+1]));
	printf ("%d",ans);
	return 0;
} 

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

int pt[M];
void build_pt() {
    for(int i=2; i<M; i++) if(pt[i]==0) {
        for(int j=i+i; j<M; j+=i) pt[j] = i;
    }
}

Int tot(int k) {
    Int r = k;
    while(k>1) {
        const int b = pt[k] ? pt[k] : k;
        r -= r/b;
        while(k%b==0) k/=b;
    }
    return r;
}

Int sum[M];

int main() {
    build_pt();
    sum[1] = 2;
    for(int i=2; i<M; i++) sum[i] = sum[i-1]+tot(i);
    int T;
    scanf("%d", &T);
    while(T--) {
        int n;
        scanf("%d", &n);
        cout << sum[n] << endl;
    }
    return 0;
}

Measured memory_bytes: 0
def resolve():
    MOD = 10 ** 9 + 7
    n, m = map(int, input().split())

    # i段目に到達するまでのルートの総数
    dp = [1] * (n + 1)

    for _ in range(m):
        dp[int(input())] = 0

    for i in range(2, n + 1):
        if dp[i] == 0:
            continue

        dp[i] = (dp[i - 1] + dp[i - 2]) % MOD

    print(dp[n])
    
resolve()

Measured memory_bytes: 44376
#include<stdio.h>
int main(void){
    int i;
    char s[13];
    gets(s);
    for(i=13;i>3;i--){
        if(i==4){
            s[4]=' ';
        }else{
        s[i]=s[i-1];
        }
    }
    puts(s);
    return 0;
}

Measured memory_bytes: 128
package main

import "fmt"

func sumi(n int) (s int) {
	s = 0
	for n > 0 {
		s += n % 10
		n = n / 10
	}
	return s
}
func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)
	sum := 0
	for i := 1; i <= n; i++ {
		if a <= sumi(i) && sumi(i) <= b {
			sum += i
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
    struct node *right;
    struct node *left;
    struct node *parent;
    int key;
};
typedef struct node * Node;

#define NIL NULL

Node root;


void insert(int k){
    Node y = NIL;
    Node x = root;
    Node z;

    z = malloc(sizeof(struct node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while(x!=NIL){
        y=x;
        if(z->key < x->key){
            x=x->left;
        }else{
            x=x->right;
        }
    }
    z->parent=y;
    if(y==NIL){
        root=z;
    }else{
        if(z->key < y->key){
            y->left=z;
        }else{
            y->right=z;
        }
    }
}

void inorder(Node u){
    if ( u == NIL ) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}
void preorder(Node u){
    if ( u == NIL ) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}


Node find(Node u,int k){
    while (u!=NIL && k!= u->key){
        if(k < u->key) u = u->left;
        else u = u->right;
    }
    return u;
}

int main(){
    int n, i, x;
    char com[20];
    scanf("%d", &n);

    for ( i = 0; i < n; i++ ){
        scanf("%s", com);
        if(com[0]=='f'){
            scanf("%d", &x);
            Node t= find(root,x);
            if(t!=NIL) printf("yes\n");
            else printf("no\n");
        }  else  if ( com[0] == 'i' ){
            scanf("%d", &x);
            insert(x);
        } else if ( com[0] == 'p'){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        } else break;

    }



    return 0;
}



Measured memory_bytes: 20480
N, P, Q = gets.split.map(&:to_i)
a = (1..N).map { gets.to_i }
b = (0..N-1).map {|i| (Q - i) * P - a[i] }.sort.reverse
c = [0]; b.each {|x| c << c[-1] + x }
p [0, (1..N).map {|i| c[i] + 2 * P * i * (i - 1) / 2 }.max].max + a.inject(:+)



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

int main()
{
  int r, d, x2000;
  cin >> r >> d >> x2000;
  int i;
  for(i = 1; i <= 10; i++)
  {
    x2000 = x2000*r-d;
    cout << x2000 << endl;
  }
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const double EPS = 1e-10;

int r, n, xl[20], xr[20], h[20];
int right[20], left[20]; // right:(i, i+1)  left:(-i-1, -i)

bool ok(double height) {
  for (int i = 0; i < r; i++) {
    double temp = sqrt(r * r - i * i) + height;
    if (temp - (double) right[i] > EPS) return false;
    if (temp - (double) left[i] > EPS) return false;
  }
  return true;
}

double search() {
  double lb = (double)-r, ub = 20.0;
  while (ub > lb + EPS) {
    double md = (lb + ub) / 2;
    if (ok(md)) lb = md;
    else ub = md;
  }
  return lb;
}

void inputright(int l, int r, int height) {
  for (int i = l; i < r; i++) right[i] = max(right[i], height);
}

void inputleft(int l, int r, int height) {
  for (int i = r; i > l; i--) left[-i] = max(left[-i], height);
}


int main() {
  while (2)  {
    scanf("%d%d", &r, &n);
    if (r == 0) break;
    for (int i = 0; i < 21; i++) right[i] = left[i] = 0;
    for (int i = 0; i < n; i++) {
      scanf("%d%d%d", &xl[i], &xr[i], &h[i]);
      if (xl[i] >= 0) inputright(xl[i], xr[i], h[i]);
      else if (xr[i] <= 0) inputleft(xl[i], xr[i], h[i]);
      else inputright(0, xr[i], h[i]), inputleft(xl[i], 0, h[i]);
    }
    printf("%f\n", (double) r + search());
  }
}



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

using Graph=vector<vector<int>>;
int main(){
    int n;
    cin>>n;
    Graph g(n);
    string c;
    for(int i=0;i<n-1;i++){
        int x,y;
        cin>>x>>y;
        x--,y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    
    cin>>c;
    if(n==1){
        cout<<(c[0]=='W')<<endl;
        return 0;
    }
    if(n==2){
        int cnt=(int)(c[0]=='W')+(int)(c[1]=='W');
        if(cnt==2) cout<<2<<endl;
        if(cnt==1) cout<<1<<endl;
        if(cnt==0) cout<<0<<endl;
        return 0;
    }
    int cnt=0;
    for(int i=0;i<=n;i++){
        if(i==n){
            if(cnt>0) break;
            cout<<0<<endl;
            return 0;
        }
        if(c[i]=='W'){
            cnt++;
        }
    }
    stack<int> hasi;
    vector<int> sz(n);
    vector<int> non(n,false);
    for(int i=0;i<n;i++){
        sz[i]=g[i].size();
        if(sz[i]==1){
            hasi.push(i);
        }
    }

    while(!hasi.empty()){
        int v=hasi.top();
        hasi.pop();
        if(c[v]=='B'){
            non[v]=true;
            for(int i=0;i<g[v].size();i++){    
                sz[g[v][i]]--;
                if(sz[g[v][i]]==1){
                    hasi.push(g[v][i]);
                }
            }
        }
    }
    
    vector<int> isBad(n);
    for(int i=0;i<n;i++){
        isBad[i]=((c[i]=='B' ? sz[i]%2==1 :sz[i]%2==0) && !non[i]);
    }
    int p=0;
    vector<int> dp(n);
    function<int(int,int)> dfs=[&](int v,int pre){
        int chi=0;
        int schi=0;
        for(int i=0;i<g[v].size();i++){
            if(g[v][i]!=pre){
                int sc=dfs(g[v][i],v);
                if(sc>=chi){
                    schi=chi;
                    chi=sc;
                }
                else if(sc>schi){
                    schi=sc;
                }
                
            }
        }
        
        if(non[v]) return dp[v]=0;
        p=max(p,chi+schi+(int)(isBad[v]));
        if(!isBad[v]) return dp[v]=chi;
        return dp[v]=chi+1;
    };
    dfs(0,-1);
    
    int tn=n-accumulate(non.begin(),non.end(),0);
    if(tn==1){
        cout<<1<<endl;
        return 0;
    }
    int badsum=accumulate(isBad.begin(),isBad.end(),0);
    cout<<2*(tn-1)-p+badsum-p<<endl;

    return 0;
}

Measured memory_bytes: 15872
use std::io::*;
use std::str::FromStr;
 
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s : String = read();
    let n = s.len();
    let s_ind = s.chars().collect::<Vec<char>>();
    println!("{}{}{}", s_ind[0], n-2, s_ind[n-1]);
}

Measured memory_bytes: 4352
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,a;
  cin >> n >> a;
  cout << (n*n)-a << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.next().toCharArray();
		char[] t = sc.next().toCharArray();
		
		int cnt = 0;
		for (int i = 0; i < s.length; i++) {
			if (s[i] != t[i]) cnt++;
		}
		
		System.out.println(cnt);
		
		sc.close();
	}
	
}



Measured memory_bytes: 32916
#include <iostream>

using namespace std;

int main(void) {
	long long s, c;
	cin >> s >> c;
	if (s * 2 > c) {
		cout << c / 2 << "\n";
		return 0;
	}
	c -= s * 2;
	cout << c / 4 + s << "\n";
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char str[105];
int main(){
	int i,k;
	scanf("%d %s",&k,str);
	int len=strlen(str);
	for(i=0;i<min(len,k);i++)
		putchar(str[i]);
	if(len>k)
		puts("...");
		
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int s=0,n,a[30000]={};
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=2*n;i++)
	 {
	 	scanf("%d",&a[i]);
	 }
	sort(a+1,a+n+n+1);
	for(int i=1;i<=2*n;i+=2)
	 {
	 	s+=a[i];
	 }
	printf("%d",s);
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = Integer.parseInt(sc.next());
        int W = Integer.parseInt(sc.next());
        int N = Integer.parseInt(sc.next());
        int[] a = new int[N];
        for (int i=0;i<N;i++) {
            a[i] = Integer.parseInt(sc.next());
        }
        int[][] grid = new int[H][W];
        int index = 0;
        int i=0;
        while (i<H*W) {
            for (int j=0;j<a[index];j++) {
                if ((i/W)%2==0) {
                    grid[i/W][i%W]=index+1;
                } else {
                    grid[i/W][(W-1)-i%W]=index+1;
                }
                i++;
            }
            index++;
        }
        for (int k=0;k<H;k++) {
            for (int j=0;j<W;j++) {
                if (j==W-1) {
                    System.out.println(grid[k][j]);
                } else {
                    System.out.print(grid[k][j]+" ");
                }
            }
        }
    }
}

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

int main() {
  int n, cnt=0;
  cin >> n;

  for (int i=1; i<=n; i+=2) {
    int yaku=0;
    for (int j=1; j<=i; j++) {
      if (i%j==0) yaku++;
    }

    if (yaku==8) cnt++;
  }

  cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int num = 1;
    char turn = 'a';
    int cnt1 = 0;
    int cnt2 = 0;
    int cnt3 = 0;
    String SA = sc.next();
    String SB = sc.next();
    String SC = sc.next();
    for(;;){
      if(turn=='a'){
        if(cnt1==SA.length()){
          System.out.println('A');
          return;
        }
        turn = SA.charAt(cnt1);
        cnt1++;
      }else if(turn =='b'){
        if(cnt2==SB.length()){
          System.out.println('B');
          return;
        }
        turn = SB.charAt(cnt2);
        cnt2++;
      }else if(turn =='c'){
        if(cnt3==SC.length()){
          System.out.println('C');
          return;
        }
        turn = SC.charAt(cnt3);
        cnt3++;
      }
    }
  }
}

Measured memory_bytes: 24916
// Original macro is in https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = || -> String {
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// for adhoc read (ex. https://atcoder.jp/contests/abc112/tasks/abc112_a)
#[allow(dead_code)]
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

#[allow(dead_code)]
fn lcm(a: i64, b: i64) -> i64 {
    a*b / gcd(a, b)
}

use std::cmp;

fn main() {
    input!{ w: i64, h: i64, x: i64, y: i64 }
    if 2*x == w && 2*y == h {
        println!("{} {}", ((w*h) as f64)/2 as f64, 1);
    } else {
        println!("{} {}", ((w*h) as f64)/2 as f64, 0);
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>

using namespace std;

int max_bfs_distance(const vector<string> & S, pair<int, int> pos){
    int H = S.size(), W = S.front().size();
    vector<int> dh{1, -1, 0, 0}, dw{0, 0, -1, 1};
    queue< pair<int, int> > Q;
    vector< vector<int> > maze(H, vector<int>(W, -1));
    maze.at(pos.first).at(pos.second) = 0;
    Q.push(pos);
    while(!Q.empty()) {
        pair<int, int> current = Q.front(); Q.pop();
        for(int i = 0; i < dh.size(); i++) {
            pair<int, int> move(current.first + dh.at(i), current.second + dw.at(i)); 
            if(move.first < 0 || H <= move.first) continue;
            if(move.second < 0 || W <= move.second) continue;
            if(S.at(move.first).at(move.second) == '#') continue;
            if(maze.at(move.first).at(move.second) >= 0) continue;
            maze.at(move.first).at(move.second) = maze.at(current.first).at(current.second) + 1;
            Q.push(move);
        }
    }

    int max = 0;
    for(int h = 0; h < H; h++) {
        for(int w = 0; w < W; w++) {
            if(max < maze.at(h).at(w)) max = maze.at(h).at(w);
        }
    }
    return max;
}

int main() {

    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for(int i = 0; i < H; i++) cin >> S.at(i);

    int ans = 0;
    for(int h = 0; h < H; h++) {
        for(int w = 0; w < W; w++) {
            if(S.at(h).at(w) == '#') continue;
            ans = max(ans, max_bfs_distance(S, make_pair(h, w)));
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
  char a[10];
  for(int i=0; i<10; ++i){
    cin>>a[i];
    a[i]=a[i]-'0';
  }
  bool can=false;
  if(a[0]*1000+a[1]*100+a[2]*10+a[3]>=2020) can=true;
  else if((a[0]*1000+a[1]*100+a[2]*10+a[3]==2019)&&(a[5]==1)) can=true;
  else if((a[0]*1000+a[1]*100+a[2]*10+a[3]==2019)&&(a[5]==0)&&(a[6]>=5)) can=true;
    
  if(can) cout<<"TBD"<<endl;
  else cout<<"Heisei"<<endl;
}


Measured memory_bytes: 256