akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<queue>
#include<bitset>
#include<map>
using namespace std;
template<typename __T>
inline void read(__T &x)
{
    x=0;
    int f=1;char c=getchar();
    while(!isdigit(c)){if(c=='-')	f=-1;c=getchar();}
    while(isdigit(c))	{x=x*10+c-'0';c=getchar();}
    x*=f;
}
template<typename T>
T rabs(T x)
{
	return x>0?x:-x;
}
int a[2005];
int n,x,y;
long long dp[2005][2005][2];
int main()
{
	read(n);
	read(x);
	read(y);
	for(int i=2;i<=n+1;i++)
		read(a[i]);
	a[0]=x;
	a[1]=y;
	for(int i=0;i<=n+1;i++)
		for(int j=0;j<=n+1;j++)
		{
			dp[i][j][0]=999999999999ll;
			dp[i][j][1]=-999999999999ll;
		}
	for(int i=0;i<=n;i++)
		dp[i][n+1][0]=rabs(a[i]-a[n+1]);
	for(int i=0;i<=n;i++)
		dp[n+1][i][1]=rabs(a[i]-a[n+1]);
	int ans=0;
	for(int i=n;i>=0;i--)
		for(int j=n;j>=0;j--)
		{
			dp[i][j][0]=dp[j+1][j][1];
			dp[i][j][1]=dp[i][i+1][0];
			if(i==0 && j==1)	ans=dp[0][1][0];
			dp[i][j][0]=min(dp[i][j+1][0],dp[i][j][0]);
			dp[i][j][1]=max(dp[i+1][j][1],dp[i][j][1]);
		}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 62976
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;

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

  int32_t N;
  cin >> N;
  vector<int32_t> A(N);
  for (int32_t i = 0; i < N; ++i) {
    cin >> A[i];
  }

  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  int32_t alice = 0, bob = 0;
  for (int32_t i = 0; i < N; ++i) {
    if (i % 2 == 0) {
      alice += A[i];
    } else {
      bob += A[i];
    }
  }
  cout << (alice - bob) << endl;

  return 0;
}


Measured memory_bytes: 256
/*
      author : nishi5451
      created: 12.08.2020 14:35:12
*/

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


int main(){
    int n,k;
    cin >> n >> k;
    if(k==1) cout << 0 << endl;
    else cout << n-k << endl;
    return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <string>
#include <limits>

using namespace std;

using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
//i64 mod = 998244353;
int int_max = 2147483647;
i64 INF = 1e16;
int max_n = 1e5;


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

    i64 ans{0};
    if (n < 600) {
        ans = 8;
    } else if(n < 800) {
        ans = 7;
    } else if(n < 1000) {
        ans = 6;
    } else if (n<1200) {
        ans = 5;
    }
    else if (n<1400) {
           ans = 4;
    }
    else if (n<1600) {
           ans = 3;
    }
    else if (n<1800) {
           ans = 2;
    }
    else if (n<2000) {
           ans = 1;
   }




    cout << ans << endl;

    return 0;
}

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

int main(){
//srandom((unsigned long)time(NULL));
    string sa,sb,sc;
    cin>>sa>>sb>>sc;

    char nw='a';
    int ca=0,cb=0,cc=0;
     while(1){
       //cout<<nw<<endl;
         switch(nw){
            case 'a':
                nw=sa[ca];
                ca+=1;
                if(ca>sa.length()){
                    cout<<"A"<<endl;
                    return 0;
                }
                continue;
            case 'b':
            nw=sb[cb];
                cb+=1;
                if(cb>sb.length()){
                    cout<<"B"<<endl;
                    return 0;
                }
                continue;
            case 'c':
             nw=sc[cc];
                cc+=1;
                if(cc>sc.length()){
                    cout<<"C"<<endl;
                    return 0;
                }
                continue;
         }
         
    }


return 0;
}

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

int main() {
	string s;
	cin >> s;

	int ans = s.size();

	int cnt = 0;
	for (char c : s) {
		if (c == 'S') {
			cnt++;
		} else {
			if (cnt > 0) {
				cnt--;
				ans -= 2;
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
int main()
{
  int h,a,i=0;
  scanf("%d%d",&h,&a);
  while(1)
  {
      h=h-a;
      i++;
      if(h<1) break;
  }

    printf("%d",i);











  return 0;
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int n, a, b;
    cin >> n >> a >> b;

    int d, sum, ans=0, p;
    for(int in=1;in<=n;in++) {
        sum = 0;
        p = in;
        while(p!=0) {
            d = p % 10;
            sum += d;
            p /= 10;
        }
        if(a<=sum&&sum<=b) ans+=in;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,s[200005],a[200005];
long long ans=0;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i],ans+=s[a[i]],s[a[i]]++;
	for(int i=1;i<=n;i++)cout<<ans-s[a[i]]+1<<endl;
}


Measured memory_bytes: 3712
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });

            var N = Sarray()[0];
            var ans = 1L;
            while (N != 0)
            {
                ans <<= 1;
                N = N >> 1;
            }
            ans >>= 1;
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 11348
import java.util.Scanner;

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


        int[] result = new int[26];
        for (int i = 0; i < result.length; i++) {
            result[i] = 0;
        }

        while(sc.hasNext()){
            String input = sc.nextLine();
            for (int i = 0; i < input.length(); i++) {
                char ch = input.charAt(i);
                String str = String.valueOf(ch);
                str = str.toLowerCase();
                ch = str.charAt(0);

                for (char c = 'a'; c <= 'z'; c++) {
                    int index = c-'a';

                    if(ch == c){
                        result[index]++;
                    }

                }
            }
        }

        for (int i = 0; i < result.length; i++) {
            char alphabet = (char)(i+'a');
            System.out.println(alphabet + " : " + result[i]);
        }

        sc.close();
    }
}


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

using namespace std;


/******************************************************************************
	Main
******************************************************************************/
int main()
{
	int n = 0;
	cin >> n;
	assert(n >= 1 && n <= 100);

	string res = "APPROVED";
	for (int i = 0; i < n; i++) {
		int a_i = 0;
		cin >> a_i;
		assert(a_i >= 1 && a_i <= 1000);
		if ((a_i % 2 == 0) && (a_i % 3 != 0 && a_i % 5 != 0)) {
			res = "DENIED";
			break;
		}
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program{
	static void Main(){
		int n=int.Parse(Console.ReadLine());
		long ans=0;
		List<int[]> li=new List<int[]>();
		List<long[]> ho=new List<long[]>();
		long[,] a=new long[n,n];
		for(int i=0;i<n;i++){
			int[] q=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
			for(int j=i+1;j<n;j++){
				li.Add(new int[]{q[j],i,j});
			}
		}
		li.Sort((u,v)=>u[0]-v[0]);
		foreach(int[] i in li){
			if(a[i[1],i[2]]==0||a[i[1],i[2]]>i[0]){
				ans+=i[0];
				a[i[1],i[2]]=i[0];
				a[i[2],i[1]]=i[0];
			}
			else if(a[i[1],i[2]]<i[0]){
				ans=-1;
				break;
			}
			for(int j=0;j<n;j++){
				if(a[i[1],j]!=0&&j!=i[2]){ho.Add(new long[]{j,i[2],i[0]+a[i[1],j]});}
				if(a[j,i[2]]!=0&&j!=i[1]){ho.Add(new long[]{j,i[1],i[0]+a[j,i[2]]});}
			}
			foreach(long[] j in ho){
				if(a[j[0],j[1]]==0||a[j[0],j[1]]>j[2]){
					a[j[0],j[1]]=j[2];
					a[j[1],j[0]]=j[2];
				}
			}
			ho.Clear();
		}
		Console.WriteLine("{0}",ans);
	}
}

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

namespace CSharpSample01
{
    
    class Program
    {
        
        static void Main(string[] args)
        {
            int num_jewelry = int.Parse(Console.ReadLine());
            int[] values = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int[] costs = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            int my_value = 0;
            int my_cost = 0;

            for(int i = 0; i < num_jewelry; i++)
            {
                int value = values[i];
                int cost = costs[i];
                if(value > cost)
                {
                    my_value += value;
                    my_cost += cost;
                }
            }

            Console.WriteLine(my_value - my_cost);

        }
    }
}


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

int main(){
  ll a,b,c;
  cin>>a>>b>>c;
  if(c-a-b>0&&4*a*b<(c-a-b)*(c-a-b)){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

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


int main() {
  
  int N;
  cin>>N;
  
  vector<string> S(N);
for (int i = 0; i < N; i++) {
  cin >> S.at(i);
}
  sort(S.begin(), S.end());
  int sw=0;
  
  struct MyPair {
  int x;     // 1つ目のデータはint型であり、xという名前でアクセスできる
  string y;  // 2つ目のデータはstring型であり、yという名前でアクセスできる
};
  
  MyPair M[N];
  for (int i = 0; i < N; i++) {
  M[i].x=0;
    M[i].y="";
}
  int sw1=0;
 
  for (int i = 0; i < N-1; i++) {
    if(S.at(i)==S.at(i+1)){
      sw++;
      if(i==N-2){
        M[sw1].x=sw;
        M[sw1].y=S.at(i);
      }
    }else{
      
      M[sw1].x=sw;
      M[sw1].y=S.at(i);
      sw1++;
      sw=0;
      if(i==N-2){
        M[sw1].x=0;
        M[sw1].y=S.at(i+1);
      }
      
    }
  }
  int sw2=0;
  for(int i=0;i<N;i++){
    sw2=max(sw2,M[i].x);
  }
  
  for(int i=0;i<N;i++){
    if(sw2==M[i].x){
      cout<<M[i].y<<endl;
    }
  }
 
  
}




Measured memory_bytes: 17408
#include <bits/stdc++.h>
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int N,Y;
    cin >> N >> Y;
    int res10000 = -1, res5000 = -1, res1000= -1;
    int a,b,c;
    for(a=0;a<=N;a++){
      for(b=0;a+b<=N;b++){
        c = N - a - b;
        if((10000*a + 5000*b + 1000*c) == Y){
          res10000 = a;
          res5000 = b;
          res1000 = c;
        }
      }
    }
    cout << res10000 << " " << res5000 << " " << res1000 << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	// global
	static int mod = 1_000_000_007;
	static long fact[];
	static long inverse[];

	static long pow(long a,int n) {
	    long res=1;
	    while (n>0) {
	        if ((n-n/2*2)==1) {
	            res=res*a%mod;
	        }
	        a=a*a%mod;
	        n>>=1;
	    }
	    return res;
	}

	static long modinv(long n) {
	    return pow(n, mod-2);
	}

	static long comb(int n,int k){
    	if(n<0 || k<0 || n<k)return 0;
    	return fact[n]*(inverse[k]*inverse[n-k]%mod) %mod;
	}


	public static void main(String[] args) {
		// main method
		fact=new long[2000002];
		fact[0]=1;
		inverse=new long[2000002];
		inverse[0]=1;
		long[] pow_25 = new long[2000002];
		pow_25[0] = 1L;
		long[] pow_26 = new long[2000002];
		pow_26[0] = 1L;
		for(int i=1;i<2000002;i++){
		    fact[i]=(fact[i-1]*(long)i)%mod;
		    inverse[i]=modinv(fact[i]);
		    pow_25[i]=pow_25[i-1]*25%mod;
		    pow_26[i]=pow_26[i-1]*26%mod;
		}
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		String S = sc.next();

		int N = S.length();
		long ans = 0L;
		for (int i=N;i<=K+N;i++) {
			// ans = (ans + comb(i-1, N-1)*pow(25, i-N)%mod*pow(26, K+N-i)%mod)%mod;
			ans = (ans + comb(i-1, N-1)*pow_25[i-N]%mod*pow_26[K+N-i]%mod)%mod;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 109708
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using V = std::vector<ll>;
#define REP(i,b,e) for(ll i=b; i<e; i++)

int main(){
        ll n, m;
        scanf("%ld %ld", &n, &m);
        V links[n];
        REP(i, 0, m){
                ll a, b;
                scanf("%ld %ld", &a, &b);
                links[a-1].push_back(b-1);
                links[b-1].push_back(a-1);
        }

        V ans(n, -1);
        std::queue<P> que;
        que.emplace(-1, 0);
        while(!que.empty()){
                auto [from, now] = que.front();
                que.pop();
                if(ans[now]>=0) continue;
                ans[now] = from + 1;
                for(ll to: links[now]){
                        if(ans[to]>=0) continue;
                        que.emplace(now, to);
                }
        }
        puts("Yes");
        REP(i, 1, n) printf("%ld\n", ans[i]);
        return 0;
}

Measured memory_bytes: 14264
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n;
	static int[][]matrix;
	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}
	static boolean read(){
		n = sc.nextInt();
		if(n == 0)return false;
		matrix = new int[n+1][n+1];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				matrix[i][j] = sc.nextInt();
			}
		}
		return true;
	}
	static void solve(){
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				matrix[i][n] = matrix[i][n] + matrix[i][j];
			}
		}
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				matrix[n][i] = matrix[n][i] + matrix[j][i];
			}
		}
		for(int k = 0; k < n; k++){
			matrix[n][n] += matrix[n][k];
		}
		for(int i = 0; i < n+1; i++){
			for(int j = 0; j < n+1; j++){
				System.out.printf("%5d",matrix[i][j]);
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read()
{
	ll x = 0, f = 1; char c = getchar();
	while (!isdigit(c)) {if (c == '-') f = -1; c = getchar();}
	while (isdigit(c)) {x = x * 10 + c - '0', c = getchar();}
	return x * f;
}

const int MAXN = 1e5 + 10;
int n, seq[MAXN], sz[MAXN], root;
vector<int> linker[MAXN];
ll D[MAXN], f[MAXN], g[MAXN];

inline bool cmp(const int &a, const int &b) {return D[a] < D[b];}

void dfs(int x, int fa)
{
	f[x] = 0;
	for (int i = 0; i < linker[x].size(); i ++)
	{
		int cur = linker[x][i];
		if (cur == fa) continue;
		dfs(cur, x), f[x] += f[cur] + sz[cur];
	}
}

void dfs2(int x, int fa)
{
	if (x == root) g[x] = 0;
	else g[x] = g[fa] + n - sz[x] + f[fa] - f[x] - sz[x];
	for (int i = 0; i < linker[x].size(); i ++)
	{
		int cur = linker[x][i];
		if (cur == fa) continue;
		dfs2(cur, x);
	}
}

inline bool check()
{
	dfs(root, 0), dfs2(root, 0);
//	for (int i = 1; i <= n; i ++)
//		printf("(%d, %d), ", f[i], g[i]);
//	puts("");
	for (int i = 1; i <= n; i ++)
		if (f[i] + g[i] != D[i]) return 0;
	return 1;
}

int main()
{
//	freopen("input.txt", "r", stdin);
	n = read();
	for (int i = 1; i <= n; i ++) D[i] = read(), seq[i] = i, sz[i] = 1;
	sort(seq + 1, seq + 1 + n, cmp), root = seq[1];
	for (int i = n; i > 1; i --)
	{
		int now = seq[i];
		int l = 1, r = i - 1, pos = -1;
		ll need = D[now] + 2 * sz[now] - n;
		while (l <= r)
		{
			int mid = (l + r) >> 1;
			if (D[seq[mid]] == need)
			{
				pos = seq[mid];
				break;
			}
			else if (D[seq[mid]] > need) r = mid - 1;
			else l = mid + 1;
		}
//		printf("%d (%d, %d, %d, %d)\n", i, now, pos, sz[now], need);
		if (pos == -1) return puts("-1"), 0;
		linker[pos].push_back(now), sz[pos] += sz[now];
	}
	if (check())
	{
		for (int i = 1; i <= n; i ++)
		{
			for (int j = 0; j < linker[i].size(); j ++)
			{
				int to = linker[i][j];
				printf("%d %d\n", i, to);
			}
		}
	}
	else puts("-1");
	return 0;
}

Measured memory_bytes: 13824
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__

int main() {
    int N;
    cin >> N;
    vi T(N), A(N);
    rep(i, N) {
        cin >> T[i] >> A[i];
    }

    ll a = 1, t = 1;
    for (int i = 0; i < N; i++) {
        ll x = t / T[i];
        if (t % T[i] != 0) x++;

        ll y = a / A[i];
        if (a % A[i] != 0) y++;

        ll co = max(x, y);

        t = co * T[i];
        a = co * A[i];
    }

    cout << (a + t) << endl;
}

Measured memory_bytes: 3656
#include<stdio.h>

 int A[10000],n;



int linearSearch(int key){
  int j,flag;
  for(j=0;j<=n-1;j++){
    if(A[j]==key){
      return  1;
    }
  }
  return 0;
}


int main() {
  int i,q,key,sum=0;
 

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&key);
    if(linearSearch(key)){
      sum++;
    }
  }

  printf("%d\n",sum);

  return 0;
}



Measured memory_bytes: 2108
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');//Splitで区切り文字を指定して複数個受け取る。
		int n = int.Parse(input[0]);
		int q = int.Parse(input[1]);
		long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
		long[] questions = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
		long answer = 0;
		long sum = 0;
		int leftNum = 0;
		int rightNum = 0;

		for(int i = 0; i < q; i++)
		{
			answer = 0;
			leftNum = 0;
			rightNum = -1;
			sum = 0;
			while(true)
			{
				rightNum++;
				if(rightNum == n) break;
				sum += nums[rightNum];

				while(true)
				{
					if(leftNum == rightNum) break;
					if(sum > questions[i])
					{
						sum -= nums[leftNum];
						leftNum++;
					}
					else break;
				}

				if(sum <= questions[i]) answer += rightNum-leftNum+1;
			}
			Console.WriteLine(answer);
		}
	}
}


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

int N,W,w[111],v[111],ans;
map<int,int> dp;

int main(){
    cin >> N >> W;
    for(int i = 0;i < N;++i)
        cin >> w[i] >> v[i];
    dp[0] = 0;
    for(int i = 0;i < N;++i){
        auto tmp = dp;
        for(auto it: tmp) if(it.first + w[i] <= W)
            dp[it.first + w[i]] = max(dp[it.first + w[i]],it.second + v[i]);
    }
    for(auto i: dp)
        ans = max(ans,i.second);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define LL long long
#define ULL unsigned long long
#define UI unsigned int
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for(int i = j; i <= k; i++)
#define dep(i, j, k) for(int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF 0x3f3f3f3f
#define inf LLONG_MAX
#define PI acos(-1)
#define fir first
#define sec second
#define lb(x) ((x) & (-(x)))
#define dbg(x) cout<<#x<<" = "<<x<<endl;
using namespace std;
const int N = 1e6 + 5;
int n, m, l[N], r[N], cnt[N];
map < int, int > mp;
void solve() {
    scanf("%d %d", &n, &m);
    rep(i, 1, n) scanf("%d %d", &l[i], &r[i]);
    rep(i, 0, m - 1) mp[i] = i;
    cnt[0] = m;
    int ans = 0;
    rep(i, 1, n) {
        l[i]--; r[i]--;
        auto it = mp.lower_bound(l[i]);
        int pos = -1;
        while(it != mp.end() && it->fir <= r[i] + 1) {
            pos = max(pos, it->sec);
           
          // cout<<it->fir <<"  "<< it->sec<<endl; cout<<"pos="<<pos<<endl;
            cnt[it->fir - it->sec]--;
            it = mp.erase(it);
        }
        //cout<<"r[i]="<<r[i]<<endl;
        if(pos >= 0 && r[i] + 1 < m) {
            mp[r[i] + 1] = pos; 
            cnt[r[i] + 1 - pos]++;
        }
        while(!cnt[ans] && ans < m) ans++;
        if(ans == m) puts("-1");
        else printf("%d\n", i + ans);
    }
}
int main() {
//    int _; scanf("%d", &_);
//    while(_--) solve();
    solve();
    return 0;
}
  /*1  1
pos=1
2  2
pos=2
3  3
pos=3
r[i]=3
1
0  0
pos=0
r[i]=0
3
1  0
pos=0
r[i]=2
6
3  0
pos=0
r[i]=3
-1
*/ 


Measured memory_bytes: 15140
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000009
#define N 1000005
using namespace std;

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

ll n, ans;
set < ll > s;
set < ll > :: iterator it;

void dene(ll x){
	if(x <= 0 or x > n)return;
	if(n/x == n%x)
		s.insert(x);
}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%lld",&n);
	for(ll i = 1; i < min(n, N*1ll); i++){
		dene( (n - i)/i );
		dene( (n - i)/i + 1);
	}
	for(it = s.begin(); it != s.end(); it++)
		ans += *it;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <algorithm>
#include <map>

using namespace std;
using LLint = long long int;

const int mod = 1000000007;
int main(){
	int N,M;
	int S[6];
	int C[6];
	cin>>N>>M;
	for(int i=0;i<M;++i) cin>>S[i]>>C[i];
	
	map<int,int> mp;
	mp[1]=0;
	N==2?mp[2]=1:mp[2]=0;
	N==3?mp[3]=1:mp[3]=0;
	
	bool check=true;
	for(int i=0;i<M;++i)
	{
		for(int j=i+1;j<M;++j)
		{
			if(S[i]==S[j]&&C[i]!=C[j])
			{
				check=false;
				break;
			}
		}
		mp[N-S[i]+1]=C[i];
	}
	if(mp[N]==0&&N!=1)check=false;
	int ans=100*mp[3]+10*mp[2]+mp[1];
	check?cout<<ans<<endl:cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
    static int count = 0;
    public static void Merge(long s[], int left, int mid, int right){
        int n1 = mid- left;
        int n2 = right - mid;
        long L1[] = new long[n1 + 1];
        long L2[] = new long[n2 + 1];
        for(int i = 0 ; i < n1 ; i++)
            L1[i] = s[left+i];
        for(int i = 0 ; i < n2 ; i++)
            L2[i] = s[mid+i];
        L1[n1] = L2[n2] = 1000000001;
        int i = 0;
        int j = 0;
        for(int k = left ; k < right ; k++){
            count++;
            if(L1[i] <= L2[j]){
                s[k] = L1[i];
                i++;
            }
            else{
                s[k] = L2[j];
                j++;
            }
        }
    }
    public static void MergeSort(long s[], int left, int right){
        if(left+1 < right){
            int mid = (left + right)/2;
            MergeSort(s,left,mid);
            MergeSort(s,mid,right);
            Merge(s,left,mid,right);
        }
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long s[] = new long[n];
        for(int i = 0 ; i < n ; i++)
            s[i] = sc.nextLong();
        MergeSort(s,0,n);
        for(int i = 0 ; i < n-1 ; i++)
            System.out.print(s[i] + " ");
        System.out.println(s[n-1]);
        System.out.println(count);
    }
}


Measured memory_bytes: 176248
#include<iostream>
int main() {
	int a,b;
	std::cin >> a >> b; 
	if(a*b%2==0) {
	std::cout << "Even" << std::endl;
}
	else {
		std::cout << "Odd" << std::endl;
	}

	

			return 0;
		}
		


			
	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll M = 1e9 + 7;

int main() {
  ll n,a,b;
  cin >> n >> a >> b;

  if ((b-a) % 2 == 0){
    cout << (b-a) / 2 << endl;
    return 0;
  } else {
    ll x = (b-a) / 2 + a;
    ll y = (n-(a+(n-b))+1) / 2 + (n-b);
    cout << min(x,y) << endl;
    return 0;
  }
}

Measured memory_bytes: 3600
#include <stdint.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

ll calc_score(long long D, const std::vector<long long> &c, const std::vector<std::vector<long long>> &s,
              const std::vector<long long> &t, vector<set<ll>> &last) {
  ll score = 0;
  REP(d, D) {
    ll i = t[d] - 1;
    score += s[d][i];
    last[i].insert(d + 1);
    REP(j, 26) {
      score -= c[j] * (d + 1 - *last[j].rbegin());
    }
  }
  return score;
}

ll area(const set<ll> &last, ll d) {
  auto it = last.lower_bound(d);
  auto x = *it - d;
  it--;
  auto y = d - *it;
  return x * y;
}

ll calc_diff(const std::vector<long long> &c, const std::vector<std::vector<long long>> &s, ll d, vector<set<ll>> &last,
             ll pre, ll next) {
  ll diff = s[d - 1][next] - s[d - 1][pre];
  {
    auto it = last[next].insert(d).first;
    it++;
    auto n = *it;
    it--;
    it--;
    auto p = *it;
    ll x = n - d;
    ll y = d - p;
    diff += c[next] * x * y;
  }
  {
    last[pre].erase(d);
    diff -= c[pre] * area(last[pre], d);
  }
  return diff;
}

void solve(long long D, std::vector<long long> c, std::vector<std::vector<long long>> s, std::vector<long long> t,
           long long M, std::vector<long long> d, std::vector<long long> q) {
  vector<set<ll>> last(26);
  REP(j, 26) {
    last[j].insert(0);
  }
  ll score = calc_score(D, c, s, t, last);
  REP(j, 26) {
    last[j].insert(D + 1);
  }
  REP(i, M) {
    ll pre = t[d[i] - 1] - 1;
    ll next = q[i] - 1;
    t[d[i] - 1] = next + 1;

    score += calc_diff(c, s, d[i], last, pre, next);
    cout << score << endl;
  }
}

int main() {
  long long D;
  scanf("%lld", &D);
  std::vector<long long> c(26);
  for (int i = 0; i < 26; i++) {
    scanf("%lld", &c[i]);
  }
  std::vector<std::vector<long long>> s(D, std::vector<long long>(26));
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      scanf("%lld", &s[i][j]);
    }
  }
  std::vector<long long> t(D);
  for (int i = 0; i < D; i++) {
    scanf("%lld", &t[i]);
  }
  long long M;
  scanf("%lld", &M);
  std::vector<long long> d(M);
  std::vector<long long> q(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &d[i]);
    scanf("%lld", &q[i]);
  }
  solve(D, std::move(c), std::move(s), std::move(t), M, std::move(d), std::move(q));
  return 0;
}


Measured memory_bytes: 4756
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    long long a;
    string s;

    cin >> a >> s;

    long long x = 0;
    for (auto c : s) {
        if (isdigit(c)) {
            x = x * 10 + c - '0';
        }
    }


    long long res = a * x;
    res /= 100;

    cout << res << '\n';

    return 0;
}

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

int main()
{
	int n;cin>>n;
    vector<int> d(n);
    for(int i = 0; i < n; i++) cin>>d[i];
    int m;cin>>m;
    vector<int> t(m);
    for(int i = 0; i < m; i++) cin>>t[i];
    sort(d.begin(), d.end());
    sort(t.begin(), t.end());
    int j = 0;
    bool can = true;
    for(int i = 0; i < m; i++){
        if(j >= n) continue;
        while(d[j] != t[i]) {
            j++; 
            if(j == n){can = false; break;}
        }
        j++;
    }
    cout << (can ? "YES" : "NO") << endl;
	return 0;
}

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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    i64 N = input();
    
    i64 ans = infll;
    for (i64 i = 1; i * i <= N; ++i) {
        if (N % i) continue;
        chmin(ans, i + (N / i) - 2);
    }
    
    cout << ans << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


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

ll v[100005];

int main(){

    ll n, k; cin >> n >> k;
    int pos = 0;
    for(int i = 0; i < n; i++){
        cin >> v[i];
        if(v[i] == 1) pos = i;
    }

    int res = 0;
    for(int i = 0; i < n-1; i=i+k-1)
        res++;
    cout << res << endl;
	return 0;
}


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

int main()
{  
  int x;
char y;
string z;
 int a=0,b=0,o=0,ab=0;

  while(cin >>x >>y >>z){
    if(z=="A") a++;
      else if(z=="B") b++;
      else if(z=="AB") ab++;
      else if(z=="O") o++;
  }
cout << a << endl;
cout << b << endl;
cout << ab << endl;
cout << o << endl;

return 0;
} 

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

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

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

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

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

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
#define _cTime (chrono::system_clock::now())
#define progress (chrono::duration_cast<chrono::milliseconds>(_cTime-_sTime).count())
#define reset _sTime=_cTime
auto reset;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	cout<<(s<="2019/04/30"?"Heisei":"TBD")<<endl;

}


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

def main():
# 整数の入力
    k = int(input())
    # スペース区切りの整数の入力
    n = [int(x) for x in input().split(' ')]
    a = n[0]
    b = n[1]
    flag = False

    if a == b:
        if a % k == 0:
            flag = True
    for i in range(a, b + 1):
        if i % k == 0:
            flag = True

    if flag:
        print("OK")
    else:
        print("NG")

if __name__ == '__main__':
    main()

Measured memory_bytes: 9196
def solve():

    S = int(input())
    list = []
    list.append(S)

    i = 0

    while True:
        s = list[i]

        v = 0

        if s % 2 == 0:
            v = s//2
            if v in list:
                print(i+2)
                exit()
            list.append(v)
        else:
            v = 3*s+1
            if v in list:
                print(i+2)
                exit()
            list.append(v)

        i += 1


if __name__ == "__main__":
    solve()


Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	String s = String.valueOf(n);
	char c1 = s.charAt(0);
	char c2 = s.charAt(2);
	if (c1 == c2) {
		System.out.println("Yes");
	} else {
		System.out.println("No");
	}
}
}


Measured memory_bytes: 23764
#include <cstdio>
#include <iostream>
#include <set>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;

int main(void) {
  int n, k;
  cin >> n >> k;
  ll res = k;
  REP(i, n-1)
    res *= k-1;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), k = sc.nextInt();
		sc.close();
		int ans = 0, order = 0;
		
		for(int i = Math.max(a,  b); i >= 1; --i) {
			if(a % i == 0 && b  % i == 0) {
				++order;
				if(order == k)ans = i;
			}
		}
		System.out.println(ans);
	}

}


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

int main() {
  int N, A;
  cin >> N;
  map<int, int> MA;
  while (cin >> A) MA[A]++;
  int cnt = 0;
  for (auto ma : MA) if (!(ma.second % 2)) cnt++;
  cout << ((cnt % 2) ? MA.size() - 1 : MA.size()) << "\n";
}

Measured memory_bytes: 4992
class Wood:
  def __init__(self,noods,edges):
    self.noods = noods
    self.edges = edges
  def cons(self,other):
    self.noods.extend(other.noods)
    self.edges.extend(other.edges)

class Edge:
  def __init__(self,n1,n2,length):
    self.n1 = n1
    self.n2 = n2
    self.length = length

def check(woods,edge):
  w1 = woods[edge.n1]
  w2 = woods[edge.n2]
  if w1.noods!= w2.noods:
    w1.cons(w2)
    w1.edges.append(edge)
    for i in w1.noods:
      woods[i] = w1
while True:
  n = int(input())
  if n == 0:
    break
  m = int(input())
  e = []
  woods = []
  for i in range(m):
    n1,n2,length = map(int,input().split(","))
    edge = Edge(n1,n2,length)
    e.append(edge)
  e = sorted(e,key=lambda x:x.length)

  for i in range(n):
    wood = Wood([i],[])
    woods.append(wood)

  for edge in e:
    check(woods,edge)

  s = 0
  for edge in woods[0].edges:
    s += edge.length//100-1
  print(s)

Measured memory_bytes: 8752
#include <stdio.h>

int main() {
	long long int i, total=1,n;
	scanf("%d", &n);
	for(i=1;i<=n;i++)
	{
		int mod=1e9+7;
		total=(total*i)%(mod);
	}
	printf("%lld",total);
	
	return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxn 5010
const int p=1e9+7;
template <typename T>inline T read()
{
    register T sum=0;
    register char cc=getchar();
    int sym=1;
    while(cc!='-'&&(cc>'9'||cc<'0'))cc=getchar();
    if(cc=='-')sym=-1,cc=getchar();
    sum=sum*10+cc-'0';
    cc=getchar();
    while(cc>='0'&&cc<='9')sum=sum*10+cc-'0',cc=getchar();
    return sym*sum;
}
template <typename T>inline T read(T &a)
{
    a=read<T>();
    return a;
}
template <typename T,typename... Others> inline void read(T& a, Others&... b)
{
    a=read(a);
	read(b...);
}
struct Edge
{
	int v;
	Edge *next;
	Edge(int a=0,Edge *b=NULL)
	{
		v=a;
		next=b;
	}
}*head[maxn];
int n,ans,v[maxn],siz[maxn],f[maxn][maxn][2],g[maxn][2];
void upd(int &x,int y)
{
	x+=y;
	if(x>p)
		x-=p;
}
int add(int x,int y)
{
	return (x+y)%p;
}
int sub(int x,int y)
{
	return (x-y+p)%p;
}
int mul(int x,int y)
{
	return 1ll*x*y%p;
}
void dfs(int k,int fa)
{
	siz[k]=1;
	f[k][1][0]=1;
	for(Edge *i=head[k];i!=NULL;i=i->next)
	{
		if(i->v==fa)
			continue;
		dfs(i->v,k);
		for(int a=0;a<=siz[k];a++)
			for(int b=0;b<=siz[i->v];b++)
			{
				int x=add(mul(f[k][a][0],f[i->v][b][0]),mul(f[k][a][1],f[i->v][b][1]));
				int y=add(mul(f[k][a][0],f[i->v][b][1]),mul(f[k][a][1],f[i->v][b][0]));
				upd(g[a+b][0],x);
				upd(g[a+b][1],y);
				upd(g[a][0],mul(v[b],y));
				upd(g[a][1],mul(v[b],x));
			}
		siz[k]+=siz[i->v];
		for(int a=0;a<=siz[k];a++)
		{
			f[k][a][0]=g[a][0];
			f[k][a][1]=g[a][1];
			g[a][0]=g[a][1]=0;
		}
	}
}
int main()
{
	read(n);
	v[0]=1;
	for(int i=2;i<=n;i+=2)
		v[i]=mul(v[i-2],i-1);
	for(int i=1;i<n;i++)
	{
		int x,y;
		read(x,y);
		head[x]=new Edge(y,head[x]);
		head[y]=new Edge(x,head[y]);
	}
	dfs(1,0);
	for(int i=0;i<=n;i++)
	{
		ans=add(ans,mul(f[1][i][0],v[i]));
		ans=sub(ans,mul(f[1][i][1],v[i]));
	}
	printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 195328
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	for(;;){
		int s,f = 0;
		if(scanf("%d",&s) == EOF){break;}
		for(int i=0; i<10; i++) for(int l=0; l<10; l++) for(int m=0; m<10; m++) for(int n=0; n<10; n++) if(i+l+m+n == s){f++;}
		cout <<f<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
object Main{
  def main(args: Array[String]){
    val sc = new java.util.Scanner(System.in)
    val num = sc.nextInt
    val board = List.fill(num)(sc.nextInt)
    val count = 0
    operate(board, count)
  }
  def operate(board: List[Int], count: Int):Unit = {
    if(board.forall(_ % 2 == 0)){
      operate(board.map(x => x / 2), count + 1)
    } else {
      println(count)
    }
  }
}

Measured memory_bytes: 25788
#include <stdio.h>
#include <math.h>

int main(){
 double x1,x2,y1,y2=0;
 scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
 double x,y=0;
 x = (x2-x1);
 x = x*x;
 y = (y2-y1);
 y = y*y;
 x = x + y;
 x = sqrt(x);
 printf("%lf\n",x);
 return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll D[40][101010];

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

    ll N;
    cin >> N;
    vector<ll> x(N);
    REP(i, N) cin >> x[i];
    ll L, Q;
    cin >> L >> Q;

    REP(i, N){
      auto itr = upper_bound(x.begin(), x.end(), x[i]+L);
      ll pos = itr - x.begin();
      pos--;
      D[0][i] = pos;
    }

    REP(i, 39){
      REP(j, N){
        D[i+1][j] = D[i][D[i][j]];
      }
    }

    while(Q--){
      ll a, b;
      cin >> a >> b;
      a--, b--;
      if(a>b) swap(a, b);

      ll lb = -1;
      ll ub = 1e9+1;
      while(ub-lb>1){
        ll mid = (ub+lb)/2;
        ll now = a;
        REP(i, 40){
          if(mid>>i & 1) now = D[i][now];
        }
        if(now>=b) ub = mid;
        else lb = mid;
      }
      cout << ub << endl;
    }
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


int main()
{
    int N;
    cin >> N;
    vector<pair<int,int>> p(N);
    REP(i, N) cin >> p[i].first >> p[i].second;

    vector<int> s(N), m(N);
    REP(i, N){
        s[i] = p[i].first+p[i].second;
        m[i] = p[i].first-p[i].second;
    }
    sort(s.begin(), s.end());
    sort(m.begin(), m.end());

    cout << max(s.back()-s[0], m.back()-m[0]) << endl;

    return 0;
}

Measured memory_bytes: 6404
#include<iostream>

//関数の宣言
int add(int num, int x,int sum,int& result);

int main(){

	int num;
	int x;
	int sum=0;
	int result=0;

	while (1){

		std::cin >> num >> x;
		if (num == 0 && x == 0){
			break;
		}

		sum = 0;
		result = 0;
		int ans = add(num, x, sum, result);

		std::cout << ans / 6 << std::endl;
	}
}

//関数の定義
int add(int num, int x,int sum,int& result){
	for (int i = 1; i <= num; ++i){
		for (int j = 1; j <= num; ++j){
			for (int k = 1; k <= num; ++k){
				if (i == j || j == k || i == k){
					continue;
				}
				sum = i + j + k;
				if (sum == x){
					result += 1;
				}
			}
		}
	}
	return result;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
int n;
set<int> s;
int main()
{
	scanf("%d",&n);
	for (int i=0;i<n;i++)
	{
		int x;
		scanf("%d",&x);
		s.insert(x);
	}
	if (s.size()%2==1)
		printf("%d",s.size());
	else
		printf("%d",s.size()-1);
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define ll long long
#define pi 3.14159265358979
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

int main(){
    ll n,a[100005],max=0;
    cin>>n;
    rep(i,n){
        cin>>a[i];
        if(max<a[i]){
            max=a[i];
        }
        if(max-1>a[i]){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}

Measured memory_bytes: 4320
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

vector<vector<int>> G;
int dp[100010];

int rec(int x){
    if(dp[x]!=-1) return dp[x];//
    int res = 0;
    for(auto y : G[x]) chmax(res, rec(y) + 1);
    dp[x] = res;
    return dp[x];
    
}
int main() {
    int n, m;
    cin >> n >> m;
    G.assign(n, vector<int>());
    rep(i,m) {
        int x, y;
        cin >> x >> y;
        --x; --y;
        G[x].push_back(y);
    }
    //初期値-1
    rep(i,n) dp[i] = -1;

    int ans = 0;
    rep(i,n){
        chmax(ans,rec(i));
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
#define ll long long

ll INF = 1e9 + 7;
const int N = 1e5 + 5;

struct Trie{
    Trie * next[26];
    int cnt[26];

    Trie()
    {
        for(int i=0;i<26;i++)
        {
            next[i] = NULL;
            cnt[i] = 0;
        }
    }
};

Trie * head = new Trie;

int found(string &str)
{
    Trie * np = head;
    int n = str.size();
    for(int i = n-1; i>0;i--)
    {
        if(np->next[str[i] - 'a'] == NULL)
            return 0;
        np = np->next[str[i] - 'a'];
    }
    return np->cnt[str[0] - 'a'];
}

void add(string &str)
{
    vector<int> count(26,0);
    int n = str.size();
    for(int i=0;i<n;i++)
        count[str[i] - 'a']++;
    Trie * np = head;
    for(int i=n-1; i>=0; i--)
    {   
        for(int j=0;j<26;j++)
        {
            if(count[j] > 0)
                np->cnt[j]++;
        }
        count[str[i] - 'a']--;
        if(np->next[str[i] - 'a'] == NULL)
            np->next[str[i] - 'a'] = new Trie;
        np = np->next[str[i] - 'a'];
    }
}

bool compare(string &s1,string &s2) 
{ 
    return s1.size() > s2.size(); 
} 

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

    int n;
    cin>>n;

    vector<string> str(n);

    for(int i=0;i<n;i++)
        cin>>str[i];

    sort(str.begin(), str.end(), compare);

    ll sum = 0;
    for(int i=0;i<n;i++)
    {
        sum += found(str[i]);
        add(str[i]);
    }

    cout<<sum<<endl;
}


Measured memory_bytes: 316748
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long N = sc.nextLong();
        sc.close();

        if (N > B) {
            N = B;
        }

        long max = -1;
        for (long x = N; x >= 0; x--) {
            if (x < B - 1 && max != -1) {
                break;
            }
            long letMax = (long) (A * x / B) - A * (long) (x / B);
            if (letMax >= max) {
                max = letMax;
            }
        }

        System.out.println(max);
    }
}

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

int main()
{
    ll n, k;
    cin >> n >> k;
    n %= k;
    ll ans = min(n, abs(n - k));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256