akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void)
{
	int n,m,i,j,flg;
	char a;
	scanf("%d %d %c",&n,&m,&a);
	for(i=0;i<n;i++){
		if(i==0||i==n-1) printf("+");
		else printf("-");
	}
	printf("\n");
	
	for(i=1;i<m-1;i++){
		for(j=0;j<n;j++){
			if(j==0||j==n-1) printf("|");
			else if(i==m/2&&j==n/2) printf("%c",a);
			else printf(".");
			
		}
		printf("\n");
	}
	
	for(i=0;i<n;i++){
		if(i==0||i==n-1) printf("+");
		else printf("-");
	}
	printf("\n");
}	


Measured memory_bytes: 2576
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

int N,K;

signed main()
{
	cin>>N>>K;

	if (N > K) {
		int c = N / K;
		int n = N - c * K;
		// n < K
		cout << min(n, K - n) << endl;
	} else {
		cout << min(N, K - N) << endl;
	}
}




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

int main() {
  string n;
  cin >> n;
  char x = n.at(n.size()-1);
  if(x == '3') cout << "bon";
  else if(x == '0' || x == '1' || x == '6' || x == '8') cout << "pon";
  else cout << "hon";
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#define endl  "\n"
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);
using namespace std;
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}
int32_t main()
{
	string s;
	cin >> s;
	int n=s.size();
	string raj="",r="";
	raj=s.substr(0,n/2);
	r=s.substr((n+1)/2,n/2);
	for(int i=0;i<s.size();i++)
	{
		if(s[i]!=s[n-1-i])
		{
			cout << "No";
			return 0;
		}
	}
	///cout << raj << " " << r;
	for(int i=0;i<raj.size();i++)
	{
		if(raj[i]!=raj[raj.size()-1-i])
		{
			cout << "No";
			return 0;
		}
		if(r[i]!=r[r.size()-1-i])
		{
			cout << "No";
			return 0;
		}
		
	}
	cout << "Yes";
}




Measured memory_bytes: 256
n = gets.to_i
p = gets.chomp.split(" ").map(&:to_i)

sorted = p.sort
dif = 0
for i in 0..n-1
  dif += 1 if p[i] != sorted[i]
end
if dif <= 2
  puts "YES"
else
  puts "NO"
end

Measured memory_bytes: 3836
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        sc.nextLine();
        int[] b = new int[a];
        for(int i = 0;i<a;i++){
            b[i] = sc.nextInt();
        }
        Arrays.sort(b);
        int max = b[a-1]-b[0];
        System.out.println(max);
    }
}

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

#define N 1010 

using namespace std;

typedef long long ll;

const int mod = 1000000007 ;

char *p1, *p2, buf[100000];

#define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1 ++ )

int rd() {
	int x = 0, f = 1;
	char c = nc();
	while (c < 48) {
		if (c == '-')
			f = -1;
		c = nc();
	}
	while (c > 47) {
		x = (((x << 2) + x) << 1) + (c ^ 48), c = nc();
	}
	return x * f;
}

int to[N], sum[N], dp[N][N], g[N];

int main() {
	int n = rd(), k = rd();
	for (int i = 1; i <= k; i ++ ) {
		int x = rd(), y = rd();
		to[x] = y, to[y] = x;
		sum[x] ++ , sum[y] ++ ;
	}
	n *= 2;
	for (int i = 1; i <= n; i ++ ) {
		sum[i] += sum[i - 1];
	}

	// init_g
	g[0] = 1;
	for (int i = 2; i <= n; i += 2) {
		g[i] = (ll)g[i - 2] * (i - 1) % mod;
	}

	for (int i = 1; i <= n; i ++ ) {
		for (int j = i + 1; j <= n; j += 2) {
			bool flag = false;
			for (int k = i; k <= j; k ++ ) {
				if (to[k] && (to[k] < i || to[k] > j)) {
					flag = true;
					break;
				}
			}
			if (flag) {
				continue;
			}
			dp[i][j] = g[j - i + 1 - sum[j] + sum[i - 1]];
			for (int l = i + 1; l < j; l += 2) {
				dp[i][j] = ((ll)dp[i][j] + mod - (ll)dp[i][l] * g[j - l - sum[j] + sum[l]] % mod) % mod;
			}
		}
	}
	k <<= 1;
	int ans = 0;

	for (int i = 1; i <= n; i ++ ) {
		for (int j = i + 1; j <= n; j += 2) {
			ans = (ans + (ll)dp[i][j] * g[n - (j - i + 1) - (k - (sum[j] - sum[i - 1]))] % mod) % mod;
		}
	}

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

Measured memory_bytes: 4352
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007

int N,M;
int a[1005],b[1005];
int c[1005][20];
int dp[1005][1<<12];//dp[i][j]:i番目まで使った時、状態jになるための最低値
vector<int> ans;
signed main(){
    scanf("%lld %lld",&N,&M);
    rep(i,M){
        scanf("%lld %lld",&a[i],&b[i]);
        rep(j,b[i]){
            scanf("%lld",&c[i][j]);c[i][j]--;
        }
    }
    //bitDP
    //dp[i][j]:i番目まで使った時、状態jになるための最低値
    rep(i,M+1)for(int j=0;j<(1<<N);j++)dp[i][j]=LLINF;
    dp[0][0]=0;//0この鍵までしか使わないと0
    rep(i,M){
        //鍵で開けられる箱が1になった数字を求める
        int boxes=0;
        for(int j=0;j<b[i];j++){
            boxes|=1<<c[i][j];
        }
        //printf("boxes:%lld\n",boxes);
        for(int j=0;j<(1<<N);j++){
            //状態jから、鍵iで開けられる状態について遷移
            dp[i+1][j|boxes]=min(dp[i+1][j|boxes],dp[i][j]+a[i]);
            //鍵を使わないとき
            dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
        }
    }
    /*rep(i,M){
        for(int j=0;j<(1<<N);j++)printf("%lld ",dp[i][j]);
        printf("\n");
    }*/
    if(dp[M][(1<<N)-1]<LLINF)printf("%lld\n",dp[M][(1<<N)-1]);
    else printf("%lld\n",(int)-1);
    return 0;
}


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

const ll INF = 1LL << 60;

struct item {
  ll w, s, v;

  bool operator<(const item z) const {
    return w + s < z.w + z.s;
  }
};

int main(void) {
  ll N;
  cin >> N;
  vector<item> items(N);
  REP(i, 0, N) cin >> items[i].w >> items[i].s >> items[i].v;

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

  vector<vector<ll>> dp(N + 1, vector<ll>(10001, -INF));
  dp[0][0] = 0;

  ll ans = -INF;
  REP(i, 0, N) {
    ll w = items[i].w;
    ll s = items[i].s;
    ll v = items[i].v;

    REP(j, 0, 10001) {
      if (j <= s) {
        ans = max(ans, dp[i][j] + v);
        if (j + w <= 10000) {
          dp[i + 1][j + w] = max(dp[i + 1][j + w], dp[i][j] + v);
        }
      }
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 78592
#include <iostream>
#include <math.h>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cstdlib>
#include <unordered_map>
#include <numeric>
#include <functional>
#include <limits.h>
#include <utility>
#include <stack>

using namespace std;

#define fs first
#define sc second

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

bool compare(vector<int> x, vector<int> y){
    int xSum = 0, ySum = 0;
    for(int i = 0; i < 9; i++){
        xSum += x[i];
        ySum += y[i];
    }
    if(xSum != ySum){
        return xSum < ySum;
    }
    for(int i = 8; i >= 0; i--){
        if(x[i] == y[i]){
            continue;
        }
        else{
            return x[i] < y[i];
        }
    }
}

vector<int> dp[10100];

int main(){
    int N, M;
    bool check[9];  fill(check, check+9, 0);
    int matchNum[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a; cin >> a;
        check[a-1] = true;
    }

    vector<int> initVec(9, 0);
    dp[0] = initVec;
    for(int i = 0; i < N; i++){
        if(dp[i].empty()){
            continue;
        }
        for(int j = 0; j < 9; j++){
            if(!check[j]){
                continue;
            }
            vector<int> v(9, 0);
            for(int k = 0; k < 9; k++){
                v[k] = dp[i][k];
            }
            v[j]++;
            if(dp[i + matchNum[j]].empty()){
                dp[i+matchNum[j]] = v;
            }
            else if(compare(dp[i+matchNum[j]], v)){
                dp[i+matchNum[j]] = v;
            }
        }
    }

    vector<int> res = dp[N];
    for(int i = 8; i >= 0; i--){
        for(int j = 0; j < res[i]; j++){
            cout << i+1;
        }
    }
    cout << endl;



    return 0;
}

Measured memory_bytes: 896
#include <iostream>
using namespace std;
int main(){
    int a,b ;
    cin >> a >> b;
    while(a != 0 || b != 0){
        for(int i=1;i<=a;i++){
            if(i==1 || i ==a){
                for(int h=1;h<=b;h++){
                    cout << "#"; 
                }
                cout << endl;
            } else {
                for(int h=1;h<=b;h++){
                    if(h ==1 || h == b){
                        cout << "#";
                    } else {
                        cout << ".";
                    }
                }
                cout << endl;
            }
        }
        cout << endl;
        cin >> a >> b;
    }
}


Measured memory_bytes: 3092
#include <iostream>
using namespace std;
int main(){
	int a;
	cin>>a;
	if(a<10)return cout<<a<<endl,0;
	if(a<100)return cout<<9<<endl,0;
	if(a<1000)return cout<<a-90<<endl,0;
	if(a<10000)return cout<<909<<endl,0;
	if(a<100000)return cout<<a-9090<<endl,0;
	if(a<1000000)return cout<<90909<<endl,0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, 0, n){
        cin >> a[i];
    }
    vector<int> b(m), c(m);
    vector<P> d(m);
    rep(i, 0, m){
        cin >> b[i] >> c[i];
        d[i] = {c[i], b[i]};
    }
    sort(d.rbegin(), d.rend());
    int ans = 0;
    int idx = 0;
    vector<int> e = a;
    rep(i, 0, m){
        rep(j, 0, d[i].second){
            if(e.size() < 2 * n) e.push_back(d[i].first);
        }
        if(e.size() == 2 * n) break;
    }
    sort(e.rbegin(), e.rend());
    rep(i, 0, n) ans += e[i];
    cout << ans << endl;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n, x;cin>>n>>x;
  int c = 2*n-1;
  if(x==1 || x==c){ cout<<"No"<<endl; return 0; }

  cout<<"Yes"<<endl;

  int f = 0;
  if(x<n)f=n+x-1;
  else if(x>n)f=x-n;

  rep(i, c)cout<<(i+f)%c+1<<' ';

  return 0;
}

Measured memory_bytes: 1536
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/input.txt"
exit $?
'''
import sys


def _i(): return int(sys.stdin.readline().strip())


def main():
    x = _i()
    sq = [i**5 for i in range(120)]
    for i in range(1, 120):
        i5 = sq[i]
        for j in range(-i, i):
            j5 = sq[j] if j >= 0 else -sq[-j]
            if i5-j5 == x:
                return f"{i} {j}"


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 63732
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define PI acos(-1)
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define sp fixed<<setprecision
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

const int M = 998244353;
const int N = 1e6+5;

int a[N];
int first[N];

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int n,x,m;
        cin>>n>>x>>m;
        if(!x)return cout<<0,0;
        int id = 1;
        first[x] = 1;
        a[id++] = x;
        while(id <= n)
        {
            x = x*x;
            x %= m;
            if(first[x])break;
            first[x] = id;
            a[id++] = x;
        }
        int ans = 0;
        if(id > n)for(int i=1;i<=n;i++)ans += a[i];
        else
        {
            int lim = first[x];
            for(int i=1;i<lim;i++,n--)ans += a[i];
            int sum = 0,len = id - lim;
            for(int i=lim,j=0;j<len;j++,i++)sum += a[i];
            ans += (sum*(n/len));
            n %= len;
            for(int i=lim,j=0;j<n;j++,i++)ans += a[i];
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 4740
// 自分で出したやつの改善例
#include <iostream>
#include <vector>
#define FOR(i, n) for (int i = 0; i < (int)(n); i++)
const int MAX_N = 210000;
using namespace std;
using ll = long long;

int main() {
  ll N, K;

  cin >> N >> K;

  vector<ll> A(N + 1, 0);
  vector<int> seen(N + 1, -1), ans;

  FOR(i, N) cin >> A[i], A[i]--;

  ll cur = 0;
  ll cnt = 0;
  while (1) {
    if (seen[cur] >= 0) break;
    seen[cur] = cnt;
    if (ans.size() == K) return cout << cur + 1 << endl, 0;
    ans.emplace_back(cur);
    cnt++;
    cur = A[cur];
  }

  int start = seen[cur];
  int num = (K - start) % (cnt - start);

  cout << ans[start + num] + 1 << endl;

  return 0;
}


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

int main()
{
	int a, b, k;
	cin >> a >> b >> k;

	if (b - a >= k * 2) {
		for (int i = a; i < a + k; i++) cout << i << endl;
		for (int i = b - k + 1; i <= b; i++) cout << i << endl;
	}
	else for (int i = a; i <= b; i++) cout << i << endl;
}

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

namespace ConsoleApplication1
{
    class Program
    {
        static readonly Dictionary<string, char> dic = new Dictionary<string, char>()
        {
            {"11",'a' }, {"12",'b' }, {"13",'c' }, {"14",'d' }, {"15",'e' },
            {"21",'f' }, {"22",'g' }, {"23",'h' }, {"24",'i' }, {"25",'j' },
            {"31",'k' }, {"32",'l' }, {"33",'m' }, {"34",'n' }, {"35",'o' },
            {"41",'p' }, {"42",'q' }, {"43",'r' }, {"44",'s' }, {"45",'t' },
            {"51",'u' }, {"52",'v' }, {"53",'w' }, {"54",'x' }, {"55",'y' },
            {"61",'z' }, {"62",'.' }, {"63",'?' }, {"64",'!' }, {"65",' ' },
        };

        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            string input;

            while (!string.IsNullOrEmpty(input = Console.ReadLine()))
            {
                sb.AppendLine(Convert(input));
            }
            Console.Write(sb);
        }

        static string Convert(string source)
        {
            if (source.Length % 2 == 1) return "NA";

            StringBuilder ret = new StringBuilder();

            for (int i = 0; i < source.Length; i += 2)
            {
                string sub = source.Substring(i, 2);

                if (!dic.ContainsKey(sub)) return "NA";

                ret.Append(dic[sub]);
            }
            return ret.ToString();
        }
    }
}

Measured memory_bytes: 8872
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define pb(a) push_back(a)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int solve(int y, int m, int d){
    int sum = 0;
    sum+= d - 1;

    if(y % 3){
        while(m != 1){
            if((m - 1) % 2 == 1) sum+= 20;
            else sum+= 19;
            m--;
        }
    }else{
        sum+= (m - 1) * 20;
    }

    int thirdYear = (y - 1) / 3;
    y-= thirdYear + 1;

    sum+= thirdYear * 20 * 10;
    sum+= y * (20 * 5 + 19 * 5);
    return sum;
}

int main(){
    int n;
    while(cin >> n){
        rep(i,n){
            int y, m, d, days = 196470;
            cin >> y >> m >> d;
            cout << days - solve(y,m,d) << endl;
        }
    }
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<stack>
#include<map>
#include<utility>
#include<vector>
#include<cmath>
#include <algorithm>

using namespace std;

int main(){

	string S,temp;
	typedef pair<string, int> P;
	vector <P>  arry (4);

	arry[0].first="dreamer"; arry[0].second=arry[0].first.size();
	arry[1].first="dream"; arry[1].second=arry[1].first.size();
	arry[2].first="eraser"; arry[2].second=arry[2].first.size();
	arry[3].first="erase"; arry[3].second=arry[3].first.size();

	//stack<string> temp;

	
	cin >> S;

	int num=0,ss;
	bool flag =0;


	reverse(S.begin(),S.end());

	for(int i=0; i<4; i++) reverse(arry[i].first.begin(),arry[i].first.end());


	while(temp !=S ){

	

		for(int i=0; i<4;i++){

		flag=0;

			//cout << i <<" " <<temp  <<" " << arry[i].first<< " " << S.substr(num,arry[i].second) << " " <<num <<" " <<arry[i].second+num <<" "<<S.size()<<" " <<  temp.size()+arry[i].second<<endl;
			if(arry[i].first == S.substr(num,arry[i].second)  && S.size() >= temp.size()+arry[i].second){


				//temp+=arry[i].first;
				temp.insert(num,arry[i].first);
				//cout << temp <<endl;
				num += arry[i].second;
				//cout <<S.substr(num,arry[i].second=arry[i].first.size()) <<endl;
				flag=1;
				break;
		
			}
			
			
		}
		if(flag==0) break;

	//	cout <<temp <<" "<<S <<endl;

	}

	if(S==temp)cout <<"YES" <<endl;

	else cout << "NO" <<endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
/*
int main(){
    string s,t;
    cin >> s >> t ;
    int c,maxx=0;
    for(int i=0;i<=s.size()-t.size();i++){
        c=0;
        rep(j,t.size()){
            if(s[j+1]==t[j]) c++;
        }
        maxx=max(maxx,c);
    }
    cout << t.size()-maxx << endl;
    /*
        if(s[i+a]==t[i]){
            c++;

            if(max<c)max=c;
        }
        a++;
    }
    cout << c << endl;

}*/
int main()
{
	string s,t;
	cin >> s >> t;
	int maxx=0;
	for(int i=0;i<=s.size()-t.size();i++)
	{
		int sum=0;
		for(int j=0;j<t.size();j++)
		{
			if(s[j+i]==t[j])sum++;
		}
		maxx=max(maxx,sum);
	}
	cout << t.size()-maxx << endl ; 
}

Measured memory_bytes: 3628
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}}

void main()
{
  int n; readV(n);
  int[] x, y; readC(n, x, y);

  struct T { int x, y, i; }
  auto t = new T[](n);
  foreach (i; 0..n) t[i] = T(x[i], y[i], i);

  struct R { int u, v, c; }
  R[] r;

  t.sort!"a.x < b.x";
  foreach (i; 0..n-1)
    r ~= R(t[i].i, t[i+1].i, min((t[i].x-t[i+1].x).abs, (t[i].y-t[i+1].y).abs));

  t.sort!"a.y < b.y";
  foreach (i; 0..n-1)
    r ~= R(t[i].i, t[i+1].i, min((t[i].x-t[i+1].x).abs, (t[i].y-t[i+1].y).abs));

  r.sort!"a.c < b.c";
  auto uf = UnionFind!int(n), ans = 0L;
  foreach (ri; r)
    if (!uf.isSame(ri.u, ri.v)) {
      uf.unite(ri.u, ri.v);
      ans += ri.c;
    }

  writeln(ans);
}

struct UnionFind(T)
{
  import std.algorithm, std.range;

  T[] p; // parent
  const T s; // sentinel
  const T n;
  T countForests; // number of forests
  T[] countNodes; // number of nodes in forests

  this(T n)
  {
    this.n = n;
    s = n;
    p = new T[](n);
    p[] = s;
    countForests = n;
    countNodes = new T[](n);
    countNodes[] = 1;
  }

  T opIndex(T i)
  {
    if (p[i] == s) {
      return i;
    } else {
      p[i] = this[p[i]];
      return p[i];
    }
  }

  bool unite(T i, T j)
  {
    auto pi = this[i], pj = this[j];
    if (pi != pj) {
      p[pj] = pi;
      --countForests;
      countNodes[pi] += countNodes[pj];
      return true;
    } else {
      return false;
    }
  }

  auto countNodesOf(T i) { return countNodes[this[i]]; }
  bool isSame(T i, T j) { return this[i] == this[j]; }

  auto groups()
  {
    auto g = new T[][](n);
    foreach (i; 0..n) g[this[i]] ~= i;
    return g.filter!(l => !l.empty);
  }
}


Measured memory_bytes: 11260
#include <cstdio>
using namespace std;
 
static const int MAX_N = 1000001;
 
int main()
{
 
    int n, a, min = MAX_N, max = -MAX_N;
    long long sum = 0;
 
    scanf( "%d", &n );
    for( int i = 0; i < n; i++ ) {
 
        scanf( "%d", &a );
        if( a < min ) min = a;
        if( a > max ) max = a;
 
        sum += a;
 
    }
 
    printf( "%d %d %ld\n", min, max, sum );
 
    return 0;
 
}


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

int main(){
    int n;  cin >> n;
    string s;   cin >> s;
    int r = 0;
    int R = 0, W = 0;
    int ans = 10000000;
    rep(i, n){ if(s[i] == 'R') r++; }
    for(int i = -1; i < n; i++){
        if(i < 0){
            R = r;
            ans = min(ans, max(R, W));
        }else{
            if(s[i] == 'R'){
                R--;
            }else{
                W++;
            }
            ans = min(ans, max(R, W));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3736
//--------------------------------------------------
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,avx,avx2,popcnt,fma")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//--------------------------------------------------
#include <bits/stdc++.h>
#include <chrono>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <cassert>
#include <random>
#include <bitset>
#include <iomanip>
#include <numeric>
#include <time.h>
#include <ctime>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <stack>
#include <cstring>
//--------------------------------------------------
#define forn(i, n) for(int i = 0; i < n; i++)
#define forw(i, n) for(int i = n-1; i >= 0; --i)
#define forns(i, n, s) for(int i = s; i < n; i++)
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
//----------------------------------------------------
using namespace std;
//----------------------------------------------------
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef long double ld;
typedef vector<ll> lnum;
typedef complex<ld> comp;
//----------------------------------------------------
const ll mod = 1e9 + 7, mod2 = 998244353;
const ld eps = 1e-6;
const ll inf = 1e18;
const int base = 1e9;
const ld PI = 3.1415926;
//----------------------------------------------------
//#define endl '\n';
#ifdef MY_DEBUG
void deb(ld x) { cerr << x << endl; };
#else
void deb(ld x){};
#endif
//----------------------------------------------------
//----------------------------------------------------
string str;
//----------------------------------------------------
unsigned int bitcount(ull val) { return __builtin_popcount(val) + __builtin_popcount(val >> 32); }

void local() {
    freopen("test.in", "r", stdin);
}

void remote() {
}

void read() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> str;
}


int main() {
#ifdef MY_DEBUG
    local();
#else
    remote();
#endif
    read();

    cout << ((str[2]==str[3] && str[4] == str[5]) ? "Yes" : "No") << endl;


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main () 
{
	int a,b,d,c;
	cin>>a>>b>>c;
	d=a+b+c;
	if(d>=22)
	{
		cout<<"bust";
	}
	else
	{
		cout<<"win";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define ALL(a) (a).begin(),(a).end()
#define EACH(e,v) for(auto& e:v)
#define SORT(v) sort(ALL(v))
#define PERM(v) SORT(v);for(bool c##p=1;c##p;c##p=next_permutation(ALL(v)))
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <class T> void chmax(T & a, T const & b) { if (b > a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = 1000'000'007;
#define int long long
int a[51];
int dp[51][2];

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

ll mod_pow(ll a, ll b, ll r) {
return b <= 0? 1: (b % 2? a: 1) * mod_pow(a * a % r, b / 2, r) % r;
}
signed main(){
    int n,p;
    cin>>n>>p;
    rep(i,n){
        cin>>a[i];
    }


    if(a[0]%2==0){
        dp[0][0]=2;
        dp[0][1]=0;
    }else{
        dp[0][0]=1;
        dp[0][1]=1;
    }
    rep(i,n-1){
        if(a[i+1]%2==0){
            dp[i+1][0]=dp[i][0]+dp[i][0];
            dp[i+1][1]=dp[i][1]+dp[i][1];
        }else{
            dp[i+1][0]=dp[i][1]+dp[i][0];
            dp[i+1][1]=dp[i][0]+dp[i][1];
        }
    }
    cout<<dp[n-1][p]<<endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000)

def gcd(a, b):
    if b == 1:
        return 1
    r = a % b
    if r == 0:
        return b
    else:
        return gcd(b, r)

def lcm(A, n):
    if n == 2:
        return A[0]* (A[1] // gcd(A[0], A[1]))
    #lcm(A, n)はA[0]-A[n-1]までの最小公倍数を求める
    rec = lcm(A, n-1)
    return rec * (A[n-1] // gcd(rec, A[n-1]))

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
if n >= 2:
    ans = lcm(a, n)
else:
    ans = a[0]
print(str(ans))

Measured memory_bytes: 3064
//
// Created by Hideaki Imamura on 2019-06-06.
//

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

bool is_ok(string s, int x, int y) {
    if (s[x] == '#') return false;
    if (s[y] == '#') return false;
    for (int i = x + 1; i < y - 1; ++i) {
        if (s[i] == '#' and s[i + 1] == '#') return false;
    }
    return true;
}

int return_3blank(string s, int x, int y) {
    for (int i = x; i <= y - 2; ++i) {
        if (s[i] == '.' and s[i + 1] == '.' and s[i + 2] == '.') return i;
    }
    return -1;
}

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

    a--;
    b--;
    c--;
    d--;

    if (c < d) {
        if (is_ok(s, b, d) and is_ok(s, a, c)) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else { //d < c
        int hoge = return_3blank(s, b - 1, d + 1);
        if (hoge >= 0) {
            if (is_ok(s, b, hoge + 1) and is_ok(s, a, hoge) and is_ok(s, hoge + 2, c) and is_ok(s, hoge + 1, d)) {
                cout << "Yes" << endl;
            } else {
                cout << "No" << endl;
            }
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1220
#import sympy

def count_divisor(num: int) -> int:
    i =1 
    count = 0
    while i * i < num:
        if num % i == 0:
            count += 2
        i += 1
    if num % i == 0:
        count += 1
    return count

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

M = 10**9+7
N = int(input())

data = [0] * (N+1)
i = N
while i > 0:
    #dic = sympy.factorint(i)
    lis = factorization(i)
    #for k, v in dic.items():
    #    data[k] += v
    for li in lis:
        k, v = li
        data[k] += v 
    i -= 1

ans = 1
data[1] = 0
for d in data:
    if d != 0:
        ans = ans * (d+1) % M
        ans %= M

print(ans)
#print(factorization(1))
#print(sympy.factorint(1))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, M;
  cin >> N >> M;
  vector<int> H(N);
  vector<int> q(N);
  for(int i = 0; i < N; i++) {
    cin >> H.at(i);
    q.at(i) = i + 1;
  }
  vector<int> A(M);
  vector<int> B(M);
  for(int i = 0; i < M; i++) {
    cin >> A.at(i) >> B.at(i);
  }
  for(int i = 0; i < M; i++) {
    if(H.at(A.at(i) - 1) > H.at(B.at(i) - 1)) {
      q.at(B.at(i) - 1) = 0;
    }
    else if(H.at(A.at(i) - 1) < H.at(B.at(i) - 1)) {
      q.at(A.at(i) - 1) = 0;
    }
    else {
      q.at(A.at(i) - 1) = 0;
      q.at(B.at(i) - 1) = 0;
    }
  }
  int count = 0;
  for(int i = 0; i < N; i++) {
    if(!(q.at(i) == 0)) {
      count++;
    }
  }
  cout << count << endl;
}

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

const int N_MAX = 1e5+1;

int H, W, N, sr, sc;
string S, T;

int pos[4];
unordered_map<char, int> taka;
unordered_map<char, int> aoki;

void solve(){
  taka['U'] = 0;
  taka['D'] = 1;
  taka['L'] = 2;
  taka['R'] = 3;

  aoki['U'] = 1;
  aoki['D'] = 0;
  aoki['L'] = 3;
  aoki['R'] = 2;

  bool clr = true;

  for(int i = 0; i < N; i++){
    int idx = taka[S[i]];
    int move = (idx % 2 == 0) ? -1 : 1;
    int lim = (idx <= 1) ? H : W;

    pos[idx] += move;
    if(pos[idx] <= 0 || pos[idx] > lim) clr = false;

    if(!clr) break;

    idx = aoki[T[i]];
    move = (idx % 2 == 0) ? 1 : -1;
    lim = (idx <= 1) ? H : W;

    if(pos[idx] + move > 0 && pos[idx] + move <= lim)
      pos[idx] += move;
  }
  cout << (clr ? "YES" : "NO") << endl;
}


int main() {

  cin >> H >> W >> N >> sr >> sc >> S >> T;
  pos[0] = pos[1] = sr;
  pos[2] = pos[3] = sc;

  solve();
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Vll = vector<ll>;
using Pll = pair<ll, ll>;
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define all(a) (a).begin(), (a).end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline int sz(T &x) { return x.size(); }
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
const ll INFll = 1ll<<60;


template<typename T>
struct edge {
  int v; T w;
  edge(int v, T w) : v(v), w(w) {}
};
template<typename T>
using Graph = vector<vector<edge<T>>>;

string rev(string s) { reverse(all(s)); return s; }

map<string, int> idS[2];
vector<string> s[2];


int main() {
  int n; cin >> n;
  Vll c(n);
  rep(i, n) {
    string x;
    cin >> x >> c[i];
    s[0].push_back(x);
    s[1].push_back(rev(x));
  }

  const int M = 21;
  auto nid = [&] (int r, int i, int j) { return n*M*r + M*i + j; };

  int N = n*M*2;
  Graph<ll> G(N);

  rep(r, 2) rep(i, n) rep2(j, 1, sz(s[r][i])+1) rep(k, n) {
    auto s1 = rev(s[r][i].substr(0, j));
    auto s2 = s[r][k];

    int l = sz(s2);
    int mn = min(j, l);
    if (s1.substr(0, mn) != s2.substr(0, mn)) continue;
    
    int r2 = r;
    int i2 = i;
    int j2 = abs(j-l);
    if (j < l) r2 ^= 1, i2 = k;
    G[nid(r, i, j)].emplace_back(nid(r2, i2, j2), c[k]);
  }

  Vll dist(N, INFll);
  priority_queue<Pll, vector<Pll>, greater<Pll>> pq;
  rep(i, n) {
    int x = nid(0, i, sz(s[0][i]));
    dist[x] = c[i];
    pq.emplace(dist[x], x);
  } 
  while (!pq.empty()) {
    auto [d, u] = pq.top(); pq.pop();
    if (dist[u] < d) continue;
    for (auto &[v, w] : G[u]) {
      if (chmin(dist[v], d+w)) pq.emplace(dist[v], v);
    }
  }

  ll ans = INFll;
  rep(r, 2) rep(i, n) rep(j, sz(s[r][i])+1) {
    auto t = s[r][i].substr(0, j);
    if (t == rev(t)) chmin(ans, dist[nid(r, i, j)]);
  }
  cout << (ans == INFll ? -1 : ans) << '\n';
}


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

int a[300000];

int main()
{
    int N;
    while(cin>>N)
    {
        int i;
        for(i=0;i<N;i++)
            scanf("%d",&a[i]);
        int mi=a[0];
        int num=1;
        for(i=1;i<N;i++)
            if(a[i]<=mi)
            {
                num++;
                mi=a[i];
            }
        cout<<num<<endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF ll 1 << 60
#define MOD 1000000007

typedef  long long ll;

using namespace std;

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 gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return a;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}

int dig(int d){
    int ans = 1;
    if(d == 0) return ans;
    while(d != 0){
        d--;
        ans*=100;
    }
    return ans;
}

void solve(void){
    int n;
    cin >> n;
    vector<string> s(n);
    int ans = 0;
    int anum = 0;
    int bnum = 0;
    int abnum = 0;
    rep(i,0,n) {
        cin >> s[i];
        rep(j,0,s[i].size()-1){
            if(s[i][j] == 'A' && s[i][j+1] == 'B') ans++;
        }
            if(s[i][s[i].size()-1] == 'A' && s[i][0] == 'B')abnum++;
            if(s[i][s[i].size()-1] != 'A' && s[i][0] == 'B') bnum++;
            if(s[i][s[i].size()-1] == 'A' && s[i][0] != 'B') anum++;

    }

    if(abnum == 0){
        ans += min(anum,bnum);
    }else if(bnum+anum > 0){
        ans += abnum+min(anum,bnum);
    }
    if(abnum!=0 && bnum+anum == 0){
        ans+=abnum-1;
    }

    cout << ans<< endl;


}

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

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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m) {
  int ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}

int gcd(int a, int b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}

void solution() {
  int x;
  cin >> x;
  int k = 100;
  for (int i = 1; i <= 10000; i++) {
    k = k + (k / 100);
    if (x <= k) {
      cout << i << endl;
      return;
    }
  }
}

int32_t main() {
  DESYNC;
  solution();
}


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

using namespace std;

int main() {
  int a, b, n;
  while (cin >> a >> b >> n) {
    int c = (a % b) * 10;
    int sum = 0;
    for (int i = 1; i <= n; ++i) {
      sum += int(c / b);
      c = (c % b) * 10;
    }
    cout << sum << endl;
  }
}


Measured memory_bytes: 2976
#include<stdio.h>

int main(void)
{
  int A[1000];
  int n,m,i;
  double low;
  double gou=0;
  int count=0;
  
  scanf("%d", &n); scanf("%d", &m);
  
  for(i=0;i<n;i++){
    scanf("%d", &A[i]);
    gou=gou+A[i];
  }
  low=gou/(4*m);
  for(i=0;i<n;i++){
    if(A[i]>=low)
      count+=1;
  }
  if(count>=m)
    puts("Yes");
  else puts("No");
  
  return 0;
}
  


Measured memory_bytes: 1664
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a;
    cin>>a;
    if(int(a.find('C'))!=-1 and int(a.rfind('F'))!=-1 and a.find('C')<a.rfind('F'))//个人码风问题，习惯用and而不是&&
        cout<<"Yes";
    else
        cout<<"No";
}

Measured memory_bytes: 256
import math
N = int(input())
#一番短くなるのは、a = b となるケース
#一番長くなるのは　b = 1ととなるケース
end = int(math.sqrt(N))+1
ans = len(str(N+1))

for b in range(1, end):
  if N % b == 0:
    a = N // b
    ans = min(ans, len(str(max(a,b))))
    #print(a,b, ans)
print(ans)

Measured memory_bytes: 3060
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	ll n, a, b;
	cin >> n >> a >> b;

	ll origi = n / (a + b) * a;
	ll mdu = n % (a + b);
	ll ans = origi + min(mdu, a);
	cout << ans << '\n';
}



Measured memory_bytes: 256
n = int(input())
data = []
for i in range(n):
    s = list(input())
    s.sort()
    data.append(s)
data.sort()
i=0
j=0
count=1
decount=0
for i in range(n-1):
  if data[i]==data[i+1]:
    count=count+1
  else:
    decount=decount+(count-1)*count/2
    count=1
decount=decount+(count-1)*count/2
print(int(decount))

Measured memory_bytes: 24652
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
typedef long long ll;
using namespace std;
 
ll poqw(ll a, ll b){
  ll ans=1;
  rep(i,b) ans*=a;
  return ans;
}
 
int main(){
   ll n; cin >> n; 
   ll ans=0; ll count=1;
   if((n%2)==1) cout << 0 << endl;
   else{
     n/=2;
     ll j=n;
       for(;;){
           j=n/poqw(5,count);
           if(j) ans+=j;
           else break;
           count++;
       }
    cout << ans << endl;
   }
return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (a % 2 == 0 || b % 2 == 0) {
			System.out.println("Even");
		} else {
			System.out.println("Odd");
		}
	}
}


Measured memory_bytes: 23892
from collections import *
from math import *

a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())
if(a < b):
	x = a+v*t
	y = b+w*t
	if(x >= y):
		print("YES")
	else:
		print("NO")
else:
	x = a-v*t
	y = b-w*t
	if(x <= y):
		print("YES")
	else:
		print("NO")

Measured memory_bytes: 65048
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e16
using namespace std;
typedef pair<ll, ll> P;


int main(void) {
	ll n, m, l, r, x, y;
	cin >> n >> m;
	cin >> l >> r;
	for (ll i = 1;i < m;i++) {
		cin >> x >> y;
		if (l <= x)l= x;
		if (y <= r)r = y;
	}
	cout << max(r - l + 1, (ll)0) << endl;
	return 0;
}

Measured memory_bytes: 256
/*
 * src.cpp
 *
 *  Created on: 2016/09/11
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

int main(){
	int a,b,h;
	cin>>a>>b>>h;
	cout<<(a+b)*h/2<<endl;
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main(){
	int n,start;
	string s;

	cin >> n;

	scanf("%*c");

	for(int i=0;i<n;i++){
		std::getline(cin,s);
		while(1){
			start = s.find("Hoshino",0);
			if(string::npos==start)break;
			s.replace(start,7,"Hoshina");
		}
		cout << s << endl;
	}

	return 0;
}

Measured memory_bytes: 1228
def dfs(a, b, v, c)
  if c == 10
    return true
  end

  if a < v[c]
    return dfs(v[c], b, v, c+1)
  end

  if b < v[c]
    return dfs(a, v[c], v, c+1)
  end

  return false
end

n = readline.chomp.to_i
n.times{
  v = readline.chomp.split.map{|c| c.to_i}

  if dfs(0, 0, v, 0)
    puts "YES"
  else
    puts "NO"
  end
}

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

int main(void){
  string s;
  cin >> s;
  map<char, int> letterCount;
  for(char c : s){
    letterCount[c]++;
  }
  if(letterCount.size() == s.length()){
    cout << "yes" << endl;
  }
  else{
    cout << "no" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){

    int a,b; //input
    int d; //output
    int r; //output
    double f; //output

    scanf("%d %d",&a,&b);

    d = a / b;
    r = a % b;
    f = (double)a / (double)b;

    printf("%d %d %.5f\n",d,r,f);

    return 0;
}

Measured memory_bytes: 1808
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>

#define ll long long
#define sz 200005

using namespace std;

int main()
{
    ll n;
    
    scanf("%lld",&n);
    
    printf("ABC%lld\n",n);

    return (0);
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999999
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    ll n;
    cin >> n;
    VI a(n+1);
    VI b(n);
    REP(i,n+1)cin >> a[i];
    REP(i,n)cin >> b[i];
    ll res=0;
    REP(i,n){
        int cnt=0;
        if(a[i]>=b[i]){
            cnt += b[i];
            a[i] -= b[i];
            b[i] = 0;
        }else{
            cnt += a[i];
            b[i] -= a[i];
            a[i] = 0;
            if(a[i+1]>=b[i]){
                cnt += b[i];
                a[i+1] -= b[i];
                b[i] = 0;
            }else{
                cnt += a[i+1];
                b[i] -= a[i+1];
                a[i+1] = 0;
            }
        }
        res += cnt;
    }
    cout << res << endl;
    return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    map<string, int> mp;
    string S;
    rep(_, N) {
        cin >> S;
        mp[S]++;
    }

    string types[] = {"AC", "WA", "TLE", "RE"};
    for (auto t: types) cout << t << " x " << mp[t] << endl;
}


Measured memory_bytes: 3640
N, S = map(int, input().split())
A = list(map(int, input().split()))

mod = 998244353

dp = [[0 for j in range(S+1)] for i in range(N+1)]
dp[0][0] = 1

for i in range(N):
    for j in range(S+1):
        dp[i+1][j] += 2*dp[i][j]
        dp[i+1][j] %= mod
        if j + A[i] <= S:
            dp[i+1][j+A[i]] += dp[i][j]
            dp[i+1][j+A[i]] %= mod

print(dp[N][S])

Measured memory_bytes: 153256
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using P = pair<ll, ll>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const ll INF = 1LL << 60;
const int inf = 1<<30;
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 (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, pair<T,T> const&P){
    os << P.first;
    os << " ";
    os << P.second;
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
//fixed<<setprecision(10)<<ans<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B;
    cin >> A >> B;
    if (A*2<=16 && B*2<=16) cout << "Yay!\n";
    else cout << ":(\n";
}

Measured memory_bytes: 256