akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

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

		int[] C = new int[N];
		int[][] A = new int[N][M];

		for(int i=0; i<N; i++) {
			C[i] = sc.nextInt();
			for(int j=0; j<M; j++) {
				A[i][j] = sc.nextInt();
			}
		}
		
		int ans = Integer.MAX_VALUE;
		
		int[] v = new int[M];
		for(int b=1; b<(1<<N); b++) {
			Arrays.fill(v, 0);
			int cost = 0;
			for(int i=0; i<N; i++) {
				if((b&(1<<i)) != 0) {
					for(int j=0; j<M; j++) {
						v[j] += A[i][j];
					}
					cost += C[i];
				}
			}
			boolean ok = true;
			for(int i=0; i<M; i++) {
				if(v[i]<X) {
					ok=false;
					break;
				}
			}
			if(ok)
				ans = Math.min(ans, cost);
		}

		System.out.println(ans<Integer.MAX_VALUE ? ans : -1);
		sc.close();
	}
}


Measured memory_bytes: 28248
N = int(input())
k = list(map(int, input().split()))
d = {}
dd = {}
for i in range(N):
    a = k[i]
    if a in d:
        d[a] += 1
    else:
        d[a] = 1
tot = 0
for key in d:
    a = d[key]
    dd[key] = int(a*(a-1)/2)
    tot += dd[key]
for i in range(N):
    print(tot - d[k[i]]+1)

Measured memory_bytes: 32800
import sys
sys.setrecursionlimit(100000)

N, M = [int(x) for x in input().split()]
g = 0

A = []
B = []

for i in range(M):
    a, b = [int(x) for x in input().split()]
    A.append(a)
    B.append(b)

A.reverse()
B.reverse()


# ----- Union Find -----------
PARENT = list(range( N + 1 ))
SIZE = [1] * (N + 1 )

def root(n):
    if PARENT[n] == n:
        return n
    else:
        ret = root(PARENT[n])
        PARENT[n] = ret
        return ret

def same(n1, n2):
    return root(n1) == root(n2)


def unite(n1, n2):
    n1 = root(n1)
    n2 = root(n2)
    if n1 == n2:
        return
    PARENT[n1] = n2
    global g
    g = g + SIZE[n2] * SIZE[n1]
    SIZE[n2] += SIZE[n1]
    SIZE[n1] = 0

Z = N * (N - 1) // 2

ans = []
for i in range(M):
    a, b = A[i], B[i]
    unite(a, b)
    # print(PARENT[1:])
    # print(SIZE[1:])
    # print(g)
    # print(Z - g)
    ans.append(Z - g)
    # print("----")

ans.reverse()
del ans[0]
for a in ans:
    print(a)
print(Z)


Measured memory_bytes: 31176
#include <iostream>
#include <vector>
#include <string>
using namespace std;
  
typedef struct{
  int width;
  int height;
}CAKE;
  
int main() {
  int n,w,d;
  
  while( cin >> n >> w >> d, n || w || d ) {
  
    vector< CAKE > cake;
    CAKE tmp = {w,d};
    cake.push_back(tmp);
    int p,s;
    while( n-- ){
      cin >> p >> s;
      p--;
  
      int cnt = 0;
      while( true ){
	if ( s-cake[p].width <= 0) break;
        s -= cake[p].width;
        cnt++;
  
	if ( s-cake[p].height <= 0) break;
        s -= cake[p].height;
        cnt++;
      }
  
      
      cnt %= 4;
      //cout << "cnt" << cnt << endl;
      pair < CAKE,CAKE > P;
      if ( cnt % 2 == 0 ) {
  
        CAKE tmp = {s,cake[p].height};
        P.first = tmp;
        tmp.width = cake[p].width - s;
        P.second = tmp;
  
      } else {
        CAKE tmp = {cake[p].width,s};
        P.first = tmp;
        tmp.height = cake[p].height - s;
        P.second = tmp;
      }
  
     
      if (  P.first.width * P.first.height > P.second.width * P.second.height ) {
	cake.push_back(P.second);
	cake.push_back(P.first);
        cake.erase(cake.begin()+p);
      }else{
        cake.push_back(P.first);
        cake.push_back(P.second);
	cake.erase(cake.begin()+p);
      }
  
    }
    
    for ( int i = 0; i < cake.size(); i++ ) {
      for ( int j = 0; j < cake.size()-1; j++ ) {
    	if ( cake[j].width * cake[j].height >
    	     cake[j+1].width * cake[j+1].height ) 
    	  swap( cake[j] , cake[j+1] );
      }
      }
  
    for ( int i = 0; i < cake.size()-1; i++ ) {
      cout << cake[i].width * cake[i].height << " ";
    }
    cout << cake[cake.size()-1].width * cake[cake.size()-1].height << endl;
  
  
  }
  
  return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> V;
const long long MOD=1000000007LL;
const long long INFL=1LL << 60;
const int INF=1<<29;

vector< ll > divisor(ll n) {
vector< ll > ret;
  for(ll i = 1; i * i < n; i++) {
    if(n % i == 0) {
    if(n/i-1>i)ret.push_back(n/i);
    }
    }
    return (ret);
}
int main() {
    ll N;
    cin >>N;
    ll ans=0;
    vector<ll> ret=divisor(N);
    for(ll i=0;i<ret.size();i++){
        ans+=ret.at(i)-1;
        
    }
    cout <<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    int x[5];
    rep(i, 5){
        cin >> x[i];
    }
    rep(i, 5){
        if(x[i]==0){
            cout << i+1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ss second
#define ff first
#define N 100005
#define inf 1000000009
#define ll long long
#define pii pair<int,int>
#define sz(a) int(a.size())
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

ll a,num,k;
string s;

int main(){
	scanf("%lld",&a);
	cin >> s;
	num = (s[sz(s)-1]-48)+(s[sz(s)-2]-48)*10;
	for(int i = sz(s) - 4;i >= 0;i--){
		k *= 10;
		k += (s[i] - 48);
	}
	a = a*k+a*num/100;
	printf("%lld",a);
}


Measured memory_bytes: 3832
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

struct edge {
    ll to, idx;
};

vector<vector<edge>> graph;
vec dp;

ll dfs(ll idx, ll par) {
    ll cnt = 0;
    for (edge e : graph[idx]) {
        if (e.to == par) continue;
        cnt += dfs(e.to, idx);
    }
    return dp[idx] = cnt + 1;
}

const int MAX = 510000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM (int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modpow (ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

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

    COMinit();

    ll N;
    cin >> N;
    graph.assign(N, vector<edge>());
    dp.assign(N, -1);

    Rep (i, N-1) {
        ll a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back({b, i});
        graph[b].push_back({a, i});
    }

    dfs(0, -1);

    ll ans = 0;
    Rep (i, N) {   
        ll tmp = 1;
        tmp += MOD - graph[i].size();
        tmp %= MOD;
        for (auto e : graph[i]) {
            if (dp[e.to] > dp[i]) {
                tmp += modpow(2, N-dp[i]);
            } else {
                tmp += modpow(2, dp[e.to]);
            }
            tmp %= MOD;
        }
        tmp *= modpow(finv[2], N-1);
        tmp %= MOD;
        tmp = 1 - tmp + MOD;
        tmp *= finv[2];
        tmp %= MOD;
        // cout << tmp << "\n";
        ans += tmp;
        ans %= MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 35840
N = int(input())
S_1 = list(input())
S_2 = list(input())
if S_1[0] == S_2[0]:
	before_style = 1
	pattern = 3
	i = 1
else:
	before_style = 2
	pattern = 6
	i = 2
	

while i < N:
	if S_1[i] == S_2[i]:
		if before_style == 1:
			before_style = 1
			i += 1			
			pattern *= 2
		else:
			before_style = 1
			i += 1	
			pattern *= 1		
	else:
		if before_style == 1:
			before_style = 2
			i += 2
			pattern *= 2
		else:
			before_style = 2
			i += 2
			pattern *= 3


print(pattern % 1000000007)

		
	

Measured memory_bytes: 3064
#include"bits/stdc++.h"
using namespace std;
#define rep(i, N) for(int i=0; i<N; ++i)
using ul = unsigned long;
using ll = long long;

int main() {
    int n;
    string s;
    cin >> n >> s;
    rep(i, s.length()) {
        s[i] = s[i]+n;
        if (s[i] > 'Z') s[i] -= 26;
    }

    cout << s << endl;
}


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

namespace ABC179
{
    class Program
    {
        static void Main(string[] args)
        {
            a();
        }

        public static void a()
        {
            string s = Console.ReadLine();
            int a = s.Length - 1;
            if(s[a] == 's')
            { 
                s += "es";
            }
            else
            {
                s += "s";
            }
            Console.WriteLine(s);
        }
    }
}


Measured memory_bytes: 25892
#include<bits/stdc++.h>
using namespace std;
long long x,n,m,ans;
int main()
{
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=m;i++) scanf("%lld",&x),ans+=x;
	if(ans>=n) puts("Yes");
  else puts("No");
	return 0;
 } 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 

int div(int n) {
    int c = 1, val = 7;
    while(val % n != 0) {
        val = (val % n) * 10 + 7;
        ++c;
    }
    return c;
}
 
int32_t main()
{
    fast;
    int n; cin >> n;
    if(n % 2 == 0 or n % 5 == 0) {
        cout << -1;
        return 0;
    }
    cout << div(n);
    
    
    
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

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

	int total = 0;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		total += a;
	}

	if (total % 2 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

}






Measured memory_bytes: 3548
#include <iostream>
#include <algorithm>
using namespace std;
void dice(){
   int d1,d2,d3,d4,d5,d6;
   cin>>d1>>d2>>d3>>d4>>d5>>d6;

   char dir;
   int tmp;
   while(true){
       cin>>dir;
       if(cin.eof()) break;
       if(dir=='E'){
           tmp=d1;d1=d4;d4=d6;d6=d3;d3=tmp;
       }else if(dir=='N'){
           tmp=d1;d1=d2;d2=d6;d6=d5;d5=tmp;
       }else if(dir=='S'){
           tmp=d1;d1=d5;d5=d6;d6=d2;d2=tmp;
       }else if(dir=='W'){
           tmp=d1;d1=d3;d3=d6;d6=d4;d4=tmp;
       }
   }
   cout<<d1<<endl;
}
int main(){
   dice();
   return 0;
}


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

using namespace std;

const int N = 100005;

long long solve(long long x) {
    if (x == -1) return 0;
    return ((x & 1) ? (((x + 1) >> 1) & 1) : (x ^ ((x >> 1) & 1)));
}

int main() {
    long long a, b;
    cin >> a >> b;
    cout << (solve(b) ^ solve(a - 1)) << endl;
    return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int t, a;
    cin >> t >> a;
    vector<pair<int, int>> diffs(n);
    for (int i = 0; i < n; ++i) {
        auto& diff = diffs[i];
        diff.second = i;
        int h;
        cin >> h;
        diff.first = abs((1000 * t - 6 * h) - 1000 * a);
    }
    auto diff = *min_element(diffs.begin(), diffs.end());
    cout << diff.second+1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int N;
int p[30];

int main(){
  cin >> N;
  int ans=0;
  for (int i=0; i<N; i++) {
    cin >> p[i];
  }
  for (int i=2; i<N; i++) {
    if ((p[i-2] > p[i-1] && p[i-1] > p[i]) || (p[i-2] < p[i-1] && p[i-1] < p[i]) )
      ans++;
  }

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

Measured memory_bytes: 256
/*Lucky_Glass*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int MOD=1e9+7,N=610,INV2=500000004;

#define cs const int &
inline int Add(cs a,cs b){return a+b>=MOD? a+b-MOD:a+b;}
inline int Sub(cs a,cs b){return a-b<0? a-b+MOD:a-b;}
inline int Mul(cs a,cs b){return 1ll*a*b%MOD;}
inline int Pow(int a,int b){int r=1;while(b){if(b&1)r=Mul(r,a);a=Mul(a,a),b>>=1;}return r;}

int n;
int d[N],fac[N],ifac[N];
int f[2][N][N];

int main(){
	fac[0]=1;for(int i=1;i<N;i++) fac[i]=Mul(fac[i-1],i);
	ifac[N-1]=Pow(fac[N-1],MOD-2);for(int i=N-2;i>=0;i--) ifac[i]=Mul(ifac[i+1],i+1);
	scanf("%d",&n);
	int cnt2=0,all=0;
	for(int i=1;i<=n;i++) scanf("%d",&d[i]),cnt2+=d[i]==2,all+=d[i];
	if(cnt2==n){printf("%d\n",Mul(fac[n-1],INV2));return 0;}
	f[0][0][0]=1;
	for(int i=1,I=1;i<=n;i++,I^=1)
		for(int j=0;j<=i;j++)
			for(int k=0;k<=all;k++){
				f[I][j][k]=f[I^1][j][k];
				if(j && d[i]>=2 && k>=d[i])
					f[I][j][k]=Add(f[I][j][k],Mul(f[I^1][j-1][k-d[i]],d[i]-1));
			}
	int ans=0,pod=1;
	for(int i=1;i<=n;i++) pod=Mul(pod,ifac[d[i]-1]);
	for(int S=3;S<n;S++)
		for(int de=2*S;de<=all;de++){
			int mul=Mul(fac[S-1],fac[n-S-1]);
			mul=Mul(mul,Mul(INV2,pod));
			mul=Mul(mul,Sub(de,2*S));
			// printf("[%d][%d]=%d\n",S,de,f[n&1][S][de]);
			ans=Add(ans,Mul(mul,f[n&1][S][de]));
		}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	ll a,b;
	ll ans=0LL;
	cin >>n>>a>>b;
	V x(n);
	rep(i,n){
		cin>>x[i];
		if(i!=0){
			ans+=min((x[i]-x[i-1])*a,b);
		}
	}
	cout<<ans<<endl;
}
/*
1 2 5 7   2,5
 1 3 2
*/

Measured memory_bytes: 1024
using System;

class Calculator{
    public static void Main() {

        while (true)
        {

            String[] s = Console.ReadLine().Split();

            int a = int.Parse(s[0]);
            int b = int.Parse(s[2]);

            if(s[1] == "?")
            {
                break;
            }

            switch (s[1])
            {
                case "+":
                    Console.WriteLine(a + b);
                    break;
                case "-":
                    Console.WriteLine(a - b);
                    break;
                case "*":
                    Console.WriteLine(a * b);
                    break;
                case "/":
                    Console.WriteLine(a / b);
                    break;

            }
        }
    }
}



Measured memory_bytes: 9196
from itertools import accumulate
from collections import defaultdict


def main():
    n = int(input())
    prime_counter = defaultdict(int)  # key ^ value
    acc = tuple(accumulate(range(1, 42)))  # because 10^12 < 2^39

    def facs(n):
        yield 2
        for x in range(3, int(n ** 0.5) + 1, 2):
            yield x

    for fac in facs(n):
        while n % fac == 0:
            n //= fac
            prime_counter[fac] += 1
            # ここで if fac * fac > n: braek を入れると，
            # 計算量の少ないケースでは早く，多いケースでは遅くなる。
    if n != 1:
        prime_counter[n] += 1

    ans = 0
    for c in prime_counter.values():
        for i, x in enumerate(acc):
            if c < x:
                tmp = i
                break
        ans += tmp
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9712
#include <iostream>
#include <cstring>
#include <algorithm>
#include <limits.h>
#include <cmath>
#include <time.h>
#include <functional>
#include <cstdio>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define MOD1 1000000007;
#define MOD2 1000007
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/*  */
int dic[14000000];
ull pow(ull x,ull n) {
  ull res = 1;
  while(n > 0) {
    if(n&1) res = res * x;
    x = x * x;
    n >>= 1;
  }
  return res;
}
int dic_op(char str[14],int& key)
{
  int j;
  int f = 1;
  int g = 0;
  for(j = 0;j<10;j++) {
    if(str[j] == 'A')
      g += f * 1;
    else if(str[j] == 'C')
      g += f * 2;
    else if(str[j] == 'G')
      g += f * 3;
    else if(str[j] == 'T')
      g += f * 4;
    else break;
    f *= 5;
  }
  key = 0;
  if(j == 10) {
    f = 1;
    for(;j<10;j++) {
      if(str[j] == 'A')
        key += f * 1;
      else if(str[j] == 'C')
        key += f * 2;
      else if(str[j] == 'G')
        key += f * 3;
      else if(str[j] == 'T')
        key += f * 4;
      else break;
        f *= 5;
    }
  }
  return g;
}
int main()
{
  int i,j,k,l;
  long n;
  long ans = 0;
  char opstr[7];
  char str[13];
  int key;
  int a = 1;
  cin >> n;
  for (i = 0; i < n; i++) {
    scanf("%s %s",opstr,str);
    if(opstr[0] == 'i') {
      int tmp = dic_op(str,key);
      if( (dic[tmp] >> key) % 2 == 0) {
        dic[tmp] += 1 << key;
      }
    }
    else if(opstr[0] == 'f') {
      int tmp = dic_op(str,key);
      /*
      printf("tmp = %d\n",tmp);
      printf("key = %d\n",key);
      printf("dic[tmp] = %d\n",dic[tmp]);
      */
      if( (dic[tmp] >> key) % 2 == 1) {
        puts("yes");
      }
      else {
        puts("no");
      }
    }
  }
  return 0;
}

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

int main(){
	int N,cnt;
	string str,str2;
	char ch;
	while(true){
		cin>>N;
		if(N==0) break;
		cin>>str;
		for(int i=0;i<N;i++){
			cnt=1;
			str2="";
			for(int j=0;j<str.size()-1;j++){
				if(str[j]!=str[j+1]){
					str2+=(to_string(cnt)+str[j]);
					cnt=1;
				}
				else cnt++;
			}
			str2+=(to_string(cnt)+str[str.size()-1]);
			swap(str,str2);
		}
		cout<<str<<endl;
	}
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
using P = pair<ll, ll>;

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;}

const ll mod = 1000000007;
const int INF = 1<<29;

int main(){
  string S; cin >> S;
  if (S[0] == S[1] && S[0] == S[2] && S[1] == S[2]) cout << "No" << endl;
  else cout << "Yes" << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline  # 改行コード「\n」を呼んでしまうため、文字数など、注意！！

n = int(input().replace("\n",""))
s = input().replace("\n","")

ans = 0
for i in range(1000):
    i = str(i).zfill(3)
    x = s.find(i[0])
    y = s.find(i[1], x+1)
    z = s.find(i[2], y+1)
    if x != -1 and y != -1 and z != -1:
        ans += 1
print(ans)

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	static boolean visit[] = new boolean[5];
	static long[] arr = new long[5];
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Set<String> m = new HashSet<>();
		Set<String> a = new HashSet<>();
		Set<String> r = new HashSet<>();
		Set<String> c = new HashSet<>();
		Set<String> h = new HashSet<>();
		for(int i = 0; i < n; i++) {
			String s = sc.next();
			switch (s.charAt(0)) {
			case 'M':
				m.add(s);
				break;
			case 'A':
				a.add(s);
				break;
			case 'R':
				r.add(s);
				break;
			case 'C':
				c.add(s);
				break;
			case 'H':
				h.add(s);
			default:
				break;
			}
		}
		arr = new long[5];
		arr[0] = m.size();
		arr[1] = a.size();
		arr[2] = r.size();
		arr[3] = c.size();
		arr[4] = h.size();
		int count = 0;
		for(int i = 0; i < 5; i++) {
			if(arr[i] != 0) {
				count++;
			}
		}
		Arrays.sort(arr);
		long ans = 0L;
		if(count < 3) {
			System.out.println(0);
		} else if(count == 3) {
			System.out.println(arr[4]*arr[3]*arr[2]);
		} else if(count == 4) {
			System.out.println(arr[4]*arr[3]*arr[2]+arr[4]*arr[3]*arr[1]+arr[4]*arr[1]*arr[2]+arr[1]*arr[3]*arr[2]);
		} else {
			//System.out.println(bfs(0, 0L));
			System.out.println(arr[0]*arr[1]*arr[2]+arr[0]*arr[1]*arr[3]+arr[0]*arr[1]*arr[4]+arr[0]*arr[2]*arr[3]+arr[0]*arr[2]*arr[4]+arr[0]*arr[3]*arr[4]+arr[1]*arr[2]*arr[3]+arr[1]*arr[2]*arr[4]+arr[1]*arr[3]*arr[4]+arr[2]*arr[3]*arr[4]);
		}
	}
}

Measured memory_bytes: 53864
#include <stdio.h>
#define INF 1000000000

int main()
{
    int n, i, x = -INF, y = -INF, min = INF;
    int s[200000] = {0};
    
    scanf ("%d", &n);
    
    for (i = 0; i < n; i++) {
        scanf("%d", &s[i]);
    }
    
    for (i = 0; i < n - 1; i++) {
        if (s[i] < min) {
            min = s[i];
        }
        x = s[i + 1] - min;
        if (x > y) {
            y = x;
        }
    }
    
    printf ("%d\n", y);
    
    return 0;
}

Measured memory_bytes: 1388
#include <bits/stdc++.h>
using namespace std;
int n = 50;
long long ar[55];
int main(){
 	long long k;
	scanf("%lld", &k);
	for(int i = 0;i < n; ++i) ar[i] = i;
	long long plus = k / n;
	long long mod = k % n;
	for(int i = 0;i < n; ++i) ar[i] += plus;
	for(int i = 0;i < mod; ++i){
		for(int j = 0;j < n; ++j){
			if(i == j) ar[j] += n;
			else ar[j] -= 1;
		}
	}
	printf("50\n");
	for(int i = 0;i < n; ++i){
		printf("%lld%c", ar[i], (i == n - 1) ? '\n' : ' ');
	}
	return 0;
}

/*
5 0 1 2 3
4 5 0 1 2
3 4 5 0 1
2 3 4 5 0
1 2 3 4 5
*/

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,0,n) cin >> a[i];
    REP(i,0,n) {
        if (a[i] % 2 == 1) continue;
        if (a[i] % 3 != 0 && a[i] % 5 != 0) {
            cout << "DENIED" << endl;
            return;
        }
    }
    cout << "APPROVED" << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

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

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; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin>>n>>s;
  map<char,int> ma;
  rep(i,n)ma[s[i]]++;
  if(ma['R']>ma['B'])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int n, a[100005];
int main(){
    cin >> n;
    for(int i = 1 ; i <= n ; i++){
        cin >> a[i];
    }
    sort(a+1,a+n+1);
    cout << a[n/2 + 1] - a[n/2];
    return 0;
}


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

int main(){
  long count=0;
  int D,N;
  cin>>D>>N;
  if(N==100){
  N=101;
  }
  cout<<(int)pow(100,D)*N;
}


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

using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

int main() {
    int n, i, j, k;
    ll m;
    while(1){
        cin >> n >> m;
        if(n==0)break;
        vector<ll> a(n),b(n),del(n);
        for(i=0;i<n;i++){
            cin >> a[i];
        }
        for(i=0;i<n;i++){
            cin >> b[i];
            del[i]=(b[i]-a[i]+m)%m;
        }
        ll dp[n][n+1]; // dp[index][timer] := index番目のタイマーをtimer周多く押したときの最小回数
        for(i=0;i<=n;i++){
            dp[0][i] = del[0] + i*m;
        }
        
        for(int index=1;index<n;index++){
            for(int loop_cnt=0;loop_cnt<=n;loop_cnt++){
                dp[index][loop_cnt] = INF;
                for(int bef=max(loop_cnt-1,0);bef<=min(n,loop_cnt+1);bef++){
                    ll bef_loop = del[index-1] + m * (ll)bef; // ひとつ前のタイマーをbef周させたときの押す回数
                    ll now_loop = del[index] + m * (ll)loop_cnt; // 今のタイマーをloop_cnt周させたときの押す回数
                    dp[index][loop_cnt] = min(dp[index][loop_cnt],dp[index-1][bef]+max(0ll,now_loop-bef_loop));
                }
            }
        }

        ll ans = INF;
        for(i=0;i<=n;i++){
            ans = min(dp[n-1][i],ans);
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 10928
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) {cout << x[i] << " "; cout << endl;}
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    ll n; cin >> n;
    set<ll> st;
    for (ll i = 1; i*i <= n; i++) {
        if (n % i == 0) {
            st.insert(i);
            st.insert(n/i);
        }
    }
    ll ans = 0;
    for (ll x : st) {
        ll m = n/x - 1;
        if (1 <= x && x <= m-1) ans += m;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3896
#include <stdio.h>

int main(){
   char s[100001];
   int i,s0,s1;
    
   scanf("%s",s);
   s0=s1=0;
   for (i=0;s[i]!='\0';i++)
      if (i%2==0)
         if (s[i]=='0') s0++;
         else           s1++;
      else
         if (s[i]=='1') s0++;
         else           s1++;
   if (s0<s1) printf("%d\n",s0);
   else       printf("%d\n",s1);
   return 0;
}


Measured memory_bytes: 256
import copy

n, m = map(int, input().split())

x = [[0 for _ in range(n)] for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    x[a][b] = 1
    x[b][a] = 1

temp = []

def trace(p, route):
    hoge = copy.deepcopy(route)
    hoge.append(p)
    ret = 0
    for i in range(n):
        if i not in hoge and x[p][i] == 1:
            if len(hoge) == n - 1:
                return 1
            else:
                ret += trace(i, hoge)
    return ret

print(trace(0, temp))

Measured memory_bytes: 3444
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
using namespace std;

int main() {
    cout << fixed << setprecision(12);
    double N, K; cin >> N >> K;

    vector<double> powers;
    {
        int i = 0;
        while (pow(2, i) <= 200000) {
            powers.push_back(pow(2, i));
            i++;
        }
    }
    double sum = 0;
    for (double i = 1; i <= N; i++) {
        auto Iter = lower_bound(powers.begin(), powers.end(), K / i);
        double p = *Iter;
        sum += 1.0 / p;
    }
    cout << sum / N << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            string[] str;
            str = Console.ReadLine ().Split (' ');

            int A = int.Parse (str[0]);
            int B = int.Parse (str[1]);

            int ans = 1;

            for (ans = 1; ans < 2000; ans++)
            {
                if (Math.Floor (ans * 8 * 0.01) == A && Math.Floor (ans * 0.1) == B)
                {
                    Console.Write (ans);
                    return;
                }
            }
            Console.Write (-1);
        }
    }
    class MyLibrary
    {
        public static int GCD (int a, int b)
        {
            if (a % b == 0) return b;
            return GCD (b, a % b);
        }
    }
}

Measured memory_bytes: 27496
# -*- coding: utf-8 -*-
"""
A - Airport Bus
https://atcoder.jp/contests/agc011/tasks/agc011_a

"""
import sys


def solve(N, C, K, T):
    ans, i, j = 0, 0, 0
    while i < N:
        while j < N and i+C > j and T[i]+K >= T[j]:
            j += 1
        ans += 1
        i = j
    return ans


def main(args):
    N, C, K = map(int, input().split())
    T = sorted([int(input()) for _ in range(N)])
    ans = solve(N, C, K, T)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


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

int main(){
  int j, i=0;
  char str[25], rts[25];
  cin >> str ;
  while(1){
    if(str[i]=='\0'){
      break;
    }
    i++;
  }

  
  for(j=0;i>0;j++){
    rts[j]=str[i-1];
    i--;
  }
  rts[j]='\0';
  
  cout << rts << endl;
  return 0;
}

Measured memory_bytes: 2992
#ABC C121
import sys
n, m = map(int, sys.stdin.readline().split())
L = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]

L = sorted(L, key=lambda x:x[0])
total=0
for a, b in L:
    if m-b>=0:
        m-=b
        total+=a*b
        if m==0:
            print(total)
            break
    else:
        total +=a*m
        print(total)
        break

Measured memory_bytes: 29728
#include <iostream>
#include <cstdlib>
#include <vector>
#include <functional>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
    // データ何個あるか
    int n;
    // data (from stdin)
    long a,min,max;
    // 型は入ってくる値次第
    std::cin >> n;
    vector<long> v;
    for (int i=0; i<n; ++i){
        std::cin >> a;
        v.push_back(a);
    }
    // sort
    std::sort(v.begin(), v.end());
    min = v[0];
    max = v[n-1];
    std::cout << max-min << endl;
}



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

using namespace std;

typedef long long ll;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define INF 1000000000

int main() {

	int a, b, c, d;
	cin >> a >> b;
	cin >> c >> d;
	cout << (a - c)*(b - d) << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }

int sx, sy, tx, ty;

void _main() {
  cin >> sx >> sy >> tx >> ty;
  int dx = tx - sx;
  int dy = ty - sy;

  cout << string(dy  , 'U') << string(dx  , 'R');
  cout << string(dy  , 'D') << string(dx+1, 'L');
  cout << string(dy+1, 'U') << string(dx+1, 'R') << "DR";
  cout << string(dy+1, 'D') << string(dx+1, 'L') << "U\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define con_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define con_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
using namespace std;
struct point{int x;int y;};
int i,j,k,count1=0,count2=0;

int main(){
    int n;
    cin>>n;
    vector<double> vec(n);
    con_input(vec);
    sort(all(vec));
    double ans=0;
    for(i=0;i<n;i++){
        if(i==0)ans=vec[i];
        else {
            ans=(ans+vec[i])/2;
        }
    }
    printf("%.8lf\n",ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int M=155;
const int INF=2e9;
int n,cost[M][M],from[M],lx[M],ly[M],slack[M],vx[M],vy[M];
int path(int v){
  int t;
  vx[v]=1;
  for(int i=1;i<=n;i++)
    {
      if(vy[i])continue;
      t=lx[v]+ly[i]-cost[v][i];
      if(t==0)
	{
	  vy[i]=1;
	  if(from[i]==0||path(from[i]))
	    {
	      from[i]=v;
	      return 1;
            }
        }
      else if(t<slack[i])
	slack[i]=t;
    }
  return 0;
}
int hung()
{
  int d,ans=0;
  for(int i=1;i<=n;i++)
    while(true)
      {
	memset(vx,0,sizeof(vx));
	memset(vy,0,sizeof(vy));
	for(int j=1;j<=n;j++)
	  slack[j]=INF;
	if(path(i)) break;
	d=INF;
	for(int j=1;j<=n;j++)
	  if(!vy[j] && slack[j]<d)
	    d=slack[j];
	for(int j=1;j<=n;j++)
	  {
	    if(vx[j])lx[j]-=d;
	    if(vy[j])ly[j]+=d;
	  }
      }
  for(int i=1;i<=n;i++)
    ans+=cost[from[i]][i];//the from meaning...
  return ans;
}
int main()
{
  int y,e;
  cin>>n>>y>>e;
  while(e--)
    {
      int u,v;cin>>u>>v;u++;v++;
      cost[u][v]=1;
      if(cost[u][v]>lx[u])
	lx[u]=cost[u][v];
    }
  n=max(n,y);
  cout<<hung()<<endl;
}

Measured memory_bytes: 3164
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    String t=sc.next();
    for(int i=0;i<t.length();i++){
      System.out.print(t.charAt(i)=='P'?'P':'D');
    }
    System.out.println();
  }
}

Measured memory_bytes: 57980
n = int(input())
a = list(map(int, input().split()))

l = []
over3200 = 0
for i in a:
    if i >= 3200:
        over3200 += 1
    else:
        l.append(i//400)
if over3200 == n:
    print(1, over3200)
else:
    print(len(set(l)),len(set(l))+over3200)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
}
int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    int g = a[0];
    for(int i=1;i<n;i++){
        g = gcd(g, a[i]);
    }
    if(g > 1){
        puts("not coprime");
        return 0;
    }

    int mx = 1e6;
    vector< bool > isp(mx+1, true);
    vector< int > opf(mx+1, 1);
    isp[0] = isp[1] = false;
    for(int i=2;i<=mx;i++){
        if(isp[i]){
            opf[i] = i;
            if(i > mx/i) continue;
            for(int j=i*i;j<=mx;j+=i){
                isp[j] = false;
                opf[j] = i;
            }
        }
    }
    // for(int i=2;i<50;i++) cout << i << ": " << opf[i] << " " << ((isp[i])?"prime":"")<<endl;

    for(int i=0;i<n;i++){
        int x = a[i];
        while(x > 1){
            int d = opf[x];
            if(!isp[d]){
                puts("setwise coprime");
                return 0;
            }
            isp[d] = false;
            while(x%d == 0) x /= d;
        }
    }
    puts("pairwise coprime");
}


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


int main(){

    int N;
    cin >> N;
    if(N%2==0){
        cout << (double)0.5 << endl;
    }else{
        cout << (double)(N+1)/2/N << endl;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;

int main(void) {
  int n, k;
  cin >> n >> k;

  vector<ll> x(n), y(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i];
  }

  ll ans = 4 * (ll)1e18;
  for (int l = 0; l < n; l++) {
    for (int r = 0; r < n; r++) {
      for (int d = 0; d < n; d++) {
        for (int u = 0; u < n; u++) {
          if (y[l] < y[d] || y[r] < y[d]) continue;
          if (y[l] > y[u] || y[r] > y[u]) continue;
          if (x[u] < x[l] || x[d] < x[l]) continue;
          if (x[d] > x[r] || x[d] > x[r]) continue;
          if (x[l] >= x[r] || y[d] >= y[u]) continue;
          int sum = 0;
          for (int i = 0; i < n; i++) {
            sum += (x[l] <= x[i] && x[i] <= x[r] && y[d] <= y[i] && y[i] <= y[u]);
          }
          if (sum >= k && (x[r] - x[l]) * (y[u] - y[d]) < ans) {
            ans = (x[r] - x[l]) * (y[u] - y[d]);
          }
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
use whiteread::parse_line;

fn main() {
    let (a, b): (i32, i32) = parse_line().unwrap();
    let mut t: i32 = 1;
    let mut k: i32 = 0;
    while t < b {
      k = k + 1;
      t = t - 1 + a;
    }
    println!("{}", k);
}


Measured memory_bytes: 2168
#include<stdio.h>
double calc(double *,double *,int ,int);
int main(void){
  int n;
  scanf("%d",&n);
  double x[n],y[n];
  for(int i=0;i<n;i++){
    scanf("%lf%lf",&x[i],&y[i]);
  }
  double times=1,all=1;
  double dr=0;
  for(int i=n-1;i>=1;i--){
    times*=i;
  }
  all=times*n;
  times*=2;
  for(int i=0;i<n-1;i++){
	for(int j=i+1;j<n;j++){
      dr+=calc(x,y,i,j);
    }
  }
printf("%.10lf",dr*times/all);
  return 0;
}
  double calc(double *x,double *y,int i,int j){
  double dx=x[i]-x[j];
  double dy=y[i]-y[j];
  return sqrt(dx*dx+dy*dy);
}

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v),end()
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;

template<typename A,typename B> inline void chmin(A &a,B b){if(a>b) a=b;}
template<typename A,typename B> inline void chmax(A &a,B b){if(a<b) a=b;}
//-----------------------------------------------------------------------

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

    while(true)
    {
        int n,r,A[50];
        cin>>n>>r;
        if(n==0 && r==0) break;

        REP(i,n) A[i]=n-i;
        REP(i,r){
            int p,c;
            vector<int> v;
            cin>>p>>c;
            p--;
            for(int i=p;i<p+c;i++) v.pb(A[i]);
            for(int i=0;i<p;i++) v.pb(A[i]);
            for(int i=p+c;i<n;i++) v.pb(A[i]);
            REP(i,n) A[i]=v[i];
        }
        cout<<A[0]<<endl;

    }
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n], b[n];
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    
    double p1=0,p2=0,p3=0,p1max=0;
    rep(i,n)
    {
        int diff = abs(b[i] - a[i]);
        p1 += diff;
        p2 += (diff * diff);
        p3 += (diff * diff * diff);
        if(p1max < diff) {
            p1max = diff;
        }
    }
    cout << fixed << setprecision(6) << endl;
    cout << p1 << endl;
    cout << sqrt(p2) << endl;
    cout << cbrt(p3) << endl;
    cout << p1max << endl;
}


Measured memory_bytes: 3428
///
// File:  b.go
// Author: ymiyamoto
//
// Created on Sat Apr 14 21:53:01 2018
//
package main

import (
	"fmt"
)

var N, M, X int

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	fmt.Scan(&N, &M, &X)
	A := make([]int, M)

	count0 := 0
	count1 := 0

	for range A {
		var a int
		fmt.Scan(&a)
		if a < X {
			count0++
		} else {
			count1++
		}
	}
	fmt.Println(min(count0, count1))
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<ll> S(N), T(M);
    for(auto& x: S) cin >> x;
    for(auto& x: T) cin >> x;

    const ll MOD = 1e9+7;
    Vvec<ll> dp(N+1, vector<ll>(M+1));
    for(int i=0; i<=N; i++) dp[i][0] = 1;
    for(int j=0; j<=M; j++) dp[0][j] = 1;

    for(int i=1; i<=N; i++){
        for(int j=1; j<=M; j++){
            dp[i][j] = dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1];
            if(S[i-1] == T[j-1]) dp[i][j] += dp[i-1][j-1];
            dp[i][j] += MOD;
            dp[i][j] %= MOD;
        }
    }

    cout << dp[N][M] << endl;
}

Measured memory_bytes: 31616
#include<bits/stdc++.h>
#define rep(i,a) for(int (i)=0; (i)<(a); (i)++)
#define rrep(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define rep2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define all(v) v.begin(), v.end()
typedef long long ll;
using namespace std;


int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n; cin >> n;
  vector<ll> h(n+10);
  vector<ll> dp(n + 50,2^63-1);
  rep(i,n) cin >> h[i];
  dp[0] = 0;
  dp[1] = abs(h[0]-h[1]);
  rep2(i,2,n){
    ll tmp = dp[i-1] + abs(h[i]-h[i-1]);
    ll tmp2 = dp[i-2] + abs(h[i]-h[i-2]);
    dp[i] = min(tmp,tmp2);
  }
  cout << dp[n-1] << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

void solve(int test_case) {
	float n,x,t;
	cin>>n>>x>>t;
	n=ceil(n/x);
	n*=t;
	cout<<(int)n;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("in", "r", stdin);
	//freopen("out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
}	


Measured memory_bytes: 3736
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AGC012AGC
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            long[] a = new long[N*3];
            string[] vals = Console.ReadLine().Split(' ');
            for(int i=0; i < N*3; i++)
            {
                a[i] = long.Parse(vals[i]);
            }

            Array.Sort(a);
            /*
            foreach (var v in a)
                Console.Write(v);
            Console.WriteLine();
            */

            long ans = 0;
            for(int i=1; i<= N; i++)
            {
                int j = N * 3 - i * 2;
                ans += a[j];
            }
            
            Console.WriteLine(ans);

        }
    }
}

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

typedef long long int ll;
typedef string str;

int main ()
{
	ll t,n,m,k,i,a,b;
	cin >> k >> n;
	ll arr[n+4];
	ll ma=0;
	cin >> arr[0];
	arr[n]=arr[0];
	for(i=1;i<n;i++)
	{
		cin >> arr[i];
		a=arr[i]-arr[i-1];
		ma=max(a,ma);
	}
	a=k-arr[i-1]+arr[i];
	ma=max(a,ma);
	cout << k-ma << endl;
	return 0;
}

Measured memory_bytes: 1792
class SegTree:  # 0-index !!!
    """
    fx: モノイドXでの二項演算
    ex: モノイドXでの単位元
    init(seq, fx, ex): 配列seqで初期化 O(N)
    update(i, x): i番目の値をxに更新 O(logN)
    query(l, r): 区間[l,r)をfxしたものを返す O(logN)
    get(i): i番目の値を返す
    show(): 配列を返す
    """

    def __init__(self, seq, fx, ex):
        self.n = len(seq)
        self.fx = fx
        self.ex = ex
        self.size = 1<<(self.n - 1).bit_length()
        self.tree = [ex] * (self.size * 2)
        # build
        for i, x in enumerate(seq, start=self.size):
            self.tree[i] = x
        for i in reversed(range(1, self.size)):
            self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])

    def set(self, i, x):  # O(log(n))
        i += self.size
        self.tree[i] = x
        while i:
            i >>= 1
            self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, i, x):
        i += self.size
        self.tree[i] = x
        while i > 1:
            i >>= 1
            self.tree[i] = self.fx(self.tree[2 * i], self.tree[2 * i + 1])

    def query(self, l, r):  # l = r の場合はたぶんバグるので注意
        tmp_l = self.ex
        tmp_r = self.ex
        l += self.size
        r += self.size
        while l < r:
            if l & 1:
                tmp_l = self.fx(tmp_l, self.tree[l])
                l += 1
            if r & 1:
                tmp_r = self.fx(self.tree[r - 1], tmp_r)  # 交換法則を仮定しない(順序大事に)
            l >>= 1
            r >>= 1
        return self.fx(tmp_l, tmp_r)

    def get(self, i):
        return self.tree[self.size + i]

    def show(self):
        return self.tree[self.size: self.size + self.n]

# ---------------------- #

n, k = (int(x) for x in input().split())
P = list(int(x) for x in input().split())

min_seg = SegTree(P, fx=min, ex=10**18)
max_seg = SegTree(P, fx=max, ex=0)

asc_count = [1] * n
for i in range(1, n):
    if P[i] > P[i - 1]:
        asc_count[i] = asc_count[i - 1] + 1

ans = 0
no_count = 0
min_out_flag = False
for i in range(n - k + 1):
    if not min_out_flag or P[i + k - 1] != max_seg.query(i, i + k):
        ans += 1
        if asc_count[i + k - 1] >= k:
            no_count += 1
    if P[i] == min_seg.query(i, i + k):
        min_out_flag = True
    else:
        min_out_flag = False
print(ans - max(no_count - 1, 0))


Measured memory_bytes: 103560
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		int n = 0;
		String[] in = new String[123];
		String[] out = new String[123];

		while ((line = br.readLine()) != null) {
			if (n == 0) {
				if ((n = Integer.parseInt(line)) == 0)
					break;
			} else {
				if (line.contains(" ")) {
					in[line.charAt(0)] = line.substring(0, 1);
					out[line.charAt(0)] = line.substring(2);
				} else {
					if (in[line.charAt(0)] != null)
						System.out.print(out[line.charAt(0)]);
					else
						System.out.print(line);
				}
				n--;
				if (n == 0 && line.length() == 1) {
					System.out.println();
					in = new String[123];
					out = new String[123];
				}
			}
		}
	}
}

Measured memory_bytes: 36124