akhauriyash/Code-Regression huggingface dataset:
while true
    n = gets.to_i
    break if n == 0
    arr = Array.new(n, 0)
    turn = 0
    ba = 0
    cards = gets.chomp.split("")
    cards.each{|card|
        arr[turn] += 1
        case card
        when "S"
            ba += arr[turn]
            arr[turn] = 0
        when "L"
            arr[turn] += ba
            ba = 0
        end
        turn = (turn + 1) % n
    }
    arr.sort!
    arr << ba
    puts arr.join(" ")
end


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

ll per[2000005], pre[2000005];
map< pair < int , int > , vector < int > > mp;

void solve()
{
    int n;
    cin >> n;
    for(int i = 1; i<=n; i++){
        int f , l;
        l = i%10;
        int d = i;
        while(d >= 10) d /= 10;
        f = d;
        mp[{f,l}].push_back( i );
    }
    for(auto v : mp)sort(v.second.begin(),v.second.end());

    ll ans = 0 ;
    for(auto v : mp){
        int f = v.first.second;
        int l = v.first.first;
        ans += (v.second.size()*mp[{f,l}].size());
    }
    cout<<ans<<"\n";
}
int main()
{
    solve();
    return 0;
}


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

int main() {
  int S;
  cin >> S;
  int s = S%100;
  string answer;
  if (100<=S && S<1300) {
    if (1<=s && s<=12) {
      answer = "AMBIGUOUS";
    }
    else {
      answer = "MMYY";
    }
  }
  else {
    if (1<=s && s<=12) {
      answer = "YYMM";
    }
    else {
      answer = "NA";
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  string s,t;
  int c=0,i;
  cin>>s;
  cin>>t;
  for(i=0;i<3;i++)
  {
    if(s.at(i)==t.at(i))
       c++;
   }
       cout<<c;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for (int i = x, i##_len = (n); i < i##_len; ++i)
#define ALL(n) begin(n), end(n)

int main()
{
  int A, B;
  cin >> A >> B;
  cout << 6 / A / B << endl;
}

Measured memory_bytes: 256
#define ll long long
#define lld long double
#define cn(n)  ll n;cin >> n;
#define tes(t) ll t;cin>>t;while(t--) 
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define repd(i, a, b) for (int i = a; i >= b; i--)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define al(v) v.begin(), v.end()
#define oset(X) tree<X, null_type, less<X>, rb_tree_tag, tree_order_statistics_node_update>
#define roset(X) tree<X, null_type, greater<X>, rb_tree_tag, tree_order_statistics_node_update>
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;
const ll MOD2 = 998244353;
const long double PI = 3.141592653589793;
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;
ll power(ll x, ll y, ll p){ll res = 1;x %= p;while (y > 0){if (y & 1)res = (res * x) % p;y = y >> 1;x = (x * x) % p;}return res;}
ll po(ll base, ll powerRaised){if (powerRaised != 0)return (base * po(base, powerRaised - 1));else return 1;}
ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}
ll lcm(ll a, ll b){return (a * b) / gcd(a, b);}
vector<int>v[200009];
int vis[200009]={0};
int cnt=0;
void dfs(int start,int par)
{
  vis[start]=1;
  cnt++;
  for(int i:v[start])
  {
    if(!vis[i] && i!=par)
    dfs(i,start);
  }
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
// #ifndef ONLINE_JUDGE
//   freopen("input.txt", "r", stdin);
//   freopen("output.txt", "w", stdout);
// #endif //*
	int n,m;
  cin>>n>>m;
  rep(i,0,m-1)
  {
    int x,y;
    cin>>x>>y;
    v[x].pb(y);
    v[y].pb(x);
  }
  int ans=0;
  for(int i=1;i<=n;i++)
  {
    if(!vis[i])
    {
      cnt=0;
      dfs(i,-1);
      ans=max(ans,cnt);
    }
  }
  cout<<ans<<endl;
	
	
}
	

  


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

#define MAX(a,b) (a > b) ? a : b
#define MIN(a,b) (a < b) ? a : b
const int inf = 1000000000; // 10^9

int main(){
   int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);
   //printf("%d %d\n",MIN(b,d),MAX(a,c));
   int ac = MAX(a,c);
   int bd = MIN(b,d);
   printf("%d",bd-ac<0?0:bd-ac);
}

Measured memory_bytes: 128
#include <cstdio>
#include <vector>
#include <queue>
using namespace std;

short ans[1 << 24];

int adj[] = {-6, -1, 1, 6};
int pos[] = {7, 8, 9, 10, 13, 14, 15, 16};

int encode(const vector<int> &v){
	int r = 0;
	for(int i = 0; i < 8; ++i){
		r |= v[pos[i]] << (3 * i);
	}
	return r;
}

void decode(int r, vector<int> &ret){
	ret.assign(24, -1);
	for(int i = 0; i < 8; ++i){
		ret[pos[i]] = r & 7;
		r >>= 3;
	}
}

int main(){
	for(int i = 0; i < (1 << 24); ++i){
		ans[i] = -1;
	}

	vector<int> v(24, -1), w;
	for(int i = 0; i < 8; ++i){
		v[pos[i]] = i;
	}
	int c = encode(v);
	ans[c] = 0;
	queue<int> q;
	q.push(c);
	q.push(-1);
	int tm = 1;
	while(q.size() > 1){
		c = q.front();
		q.pop();
		if(c == -1){
			++tm;
			q.push(-1);
		}
		else{
			decode(c, v);
			int x;
			for(x = 7; v[x]; ++x);
			for(int i = 0; i < 4; ++i){
				int y = x + adj[i];
				if(v[y] > 0){
					swap(v[x], v[y]);
					c = encode(v);
					if(ans[c] == -1){
						ans[c] = tm;
						q.push(c);
					}
					swap(v[x], v[y]);
				}
			}
		}
	}

	while(1){
		for(int i = 0; i < 8; ++i){
			if(scanf("%d", &v[pos[i]]) == EOF){
				return 0;
			}
		}
		printf("%d\n", ans[encode(v)]);
	}
}

Measured memory_bytes: 33832
#include <bits/stdc++.h>
#define ll long long
#define _ ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
using namespace std;

int main() { _
    int n; cin >> n;
    int AC = 0, WA = 0, TLE = 0, RE = 0;
    for(int i = 0; i < n; i++){
        string s; cin >> s;
        if(s == "AC") AC++;
        if(s == "WA") WA++;
        if(s == "TLE") TLE++;
        if(s == "RE") RE++;
    }
    cout << "AC x " << AC << endl;
    cout << "WA x " << WA << endl;
    cout << "TLE x " << TLE << endl;
    cout << "RE x " << RE << endl;

}

Measured memory_bytes: 3592
import java.io.PrintWriter;
import java.util.*;

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

	void run() {
		solver();
	}

	void solver() {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		while (true) {
			int W = sc.nextInt();
			int n = sc.nextInt();
			if (W == 0 && n == 0)
				break;
			long[] accum = new long[n + 1];
			int[] x = new int[n];
			for (int i = 0; i < n; ++i) {
				x[i] = sc.nextInt();
			}
			for (int i = 0; i < n; ++i) {
				accum[i + 1] = accum[i] + x[i];
			}
			int lack = 0;
			int gap = 1;
			outer: for (int i = 15; i >= -1; --i) {
				int ngap = gap + (i >= 0 ? (1 << i) : 0);
				int[] vis = new int[n + 1];
				vis[0] = 1;
				vis[1] = -1;
				for (int j = 0; j < n; ++j) {
					vis[j] += (j > 0 ? vis[j - 1] : 0);
					if (vis[j] > 0) {
						if (accum[n] - accum[j] + (n - j - 1) <= W) {
							continue outer;
						}
						int left = j;
						int right = n;
						while (right - left > 1) {
							int middle = (right + left) / 2;
							if (accum[middle] - accum[j] + (middle - j - 1) <= W) {
								left = middle;
							} else {
								right = middle;
							}
						}
						int dmax = left;

						left = j;
						right = n;
						while (right - left > 1) {
							int middle = (right + left) / 2;
							if (W <= accum[middle] - accum[j] + (long) ngap * (middle - j - 1)) {
								right = middle;
							} else {
								left = middle;
							}
						}
						int dmin = right;
						
						if (dmin > dmax)
							continue;
						++vis[dmin];
						--vis[dmax + 1];
					}
				}
				++lack;
				gap = ngap;
			}
			if (lack > 0)
				++gap;
			pw.println(gap);
		}
		pw.close();
		sc.close();
	}

	
	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 160404
/*zxj*/
#include<iostream> 
#include<string>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<sstream>
#define sf scanf
#define pf printf
#define pfn printf("\n");
#define pfk printf(" ");
#define pf0 printf("0");
#define pf1 printf("1");
#define ll long long
#define sfd(n) scanf("%d",&n);
#define sfdd(n,m) scanf("%d%d",&n,&m);
#define sfld(n) scanf("%lld",&n);
#define sfldd(n,m) scanf("%lld%lld",&n,&m);
#define sflf(n) scanf("%lf",&n);
#define sflff(n,m) scanf("%lf%lf",&n,&m);
#define sfc(n) scanf("%c",n);
#define sfcc(n,m) scanf("%c%c",n,m);
#define sfs(n) scanf("%s",n);
#define sfss(n,m) scanf("%s%s",n,m);
#define pfd(n) printf("%d",n);
#define pfld(n) printf("%lld",n);
#define pflf(n) printf("%lf",n);
#define pfc(n) printf("%c",n);
#define pfs(n) printf("%s",n);
using namespace std;
#define csh(a,n) memset(a,n,sizeof(a));
struct ab{
	int a,b;
}arr[1000000];
bool fff(struct ab a,struct ab b){
	return a.a<b.a;
}
int main(){
	int n;
	cin>>n;
	int m;
	cin>>m;
	for(int i=0;i<n;i++){
		sfdd(arr[i].a,arr[i].b)
	}
	sort(arr,arr+n,fff);
	priority_queue<int>brr;
	int q=0;
	int sum=0;
	for(int i=1;i<=m;i++){
		while(arr[q].a<=i&&q<n){
			brr.push(arr[q++].b);
		}
		if(!brr.empty()){
			sum+=brr.top();
			brr.pop();
		}
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 1660
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int W,a,b;
	cin >> W >> a >> b;
	if(a < b) swap(a,b);
	if(a-b < W) cout << 0 << endl;
	else cout << -W - b + a << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>

using namespace std;

int main() {
	string abc = "abcdefghijklmnopqrstuvwxyz";
	string s;
	cin >> s;
	set<char> st;
	for (int i = 0; i < s.size(); i++) {
		st.insert(s[i]);
	}
	if (st.size() == 26) {
		cout << "None" << endl;
	}
	else {
		int j = 0;
		for (set<char>::iterator ite = st.begin(); ite != st.end(); ite++) {
			if (*(ite) != abc[j]) {
				cout << abc[j] << endl;
				break;
			}
			j++;
		}
		if (j == 25) {
			cout << 'z' << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 512
H, W=map(int, input().split())
A= [list(input()) for _ in range(H)]
B = [[0]*W for _ in range(H)]
nx = [1,1,1,0,0,-1,-1,-1]
ny = [-1, 0, 1, -1, 1, -1, 0, 1]
for i in range(H):
  for j in range(W):
    if A[i][j] == "#":
      B[i][j] = "#"
    else:
      c = 0
      for k in range(8):
        newx = i+nx[k]
        newy = j+ny[k]
        if 0<= newx <= H-1 and 0<= newy <= W-1:
          if A[newx][newy] == "#":
            c += 1
      B[i][j] = str(c)
C=[0]*H
for i in range(H):
    C[i] = "".join(B[i])
for i in range(H):
  print(C[i])
        


Measured memory_bytes: 40176
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int cnt=0,n=b;
		for(int i=1; i<= b/a ; i++) {
			if(cnt == c) {
				break;
			}
			cnt ++;
		}
		System.out.println(cnt);
    }
}


Measured memory_bytes: 23124
#include <stdio.h>
#include <math.h>
int main()
{
	int n,i,j,k,sum=0;
	scanf("%d",&n);
	int tri[n];
	for(i=0;i<n;i++)
	{
		scanf("%d",&tri[i]);
	}
	for(i=0;i<n-1;i++)
	{
		for(j=i+1;j<n;j++)
		{
			if(tri[i]>tri[j])
			{
				tri[i]=tri[i]+tri[j];
				tri[j]=tri[i]-tri[j];
				tri[i]=tri[i]-tri[j];
			}
		}
	}
	for(i=0;i<n-2;i++)
	{
		for(j=i+1;j<n-1;j++)
		{
			for(k=j+1;k<n;k++)
			{
				if(tri[i]+tri[j]>tri[k]) sum++;
			}
		}
	}
	printf("%d",sum);
} 

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

#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define reg register
#define ll long long
#define N 100005

using namespace std;

inline ll read() {
    reg ll s = 0, t = 0; reg char ch = getchar();
    while (!isdigit(ch)) t |= ch == '-', ch = getchar();
    while (isdigit(ch)) s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}

int n, h[N];
int ans = 0, res = 1;

int main() {
    n = read();
    rep (i, 1, n) h[i] = read();
    rep (i, 2, n) {
        if (h[i] <= h[i - 1]) res++;
        else ans = max(ans, res), res = 1;
    }
    ans = max(ans, res);
    cout << ans - 1 << endl;
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
int main(){
  char txt,j='a';
  int alpha[26]={},i=0, sa, res;
  while(1){
    res = scanf("%c",&txt);
    sa=26;
    if(res == EOF)break;
    if(txt==' ')continue;
    if(txt>='A' && txt<='Z')sa=txt-'A';
    else if(txt>='a' && txt<='z')sa=txt-'a';
    if(sa<26)
    alpha[sa]++;

  }
  while(j<='z'){
    printf("%c : %d\n",j,alpha[i]);
    i++;
    j++;
  }

  return 0;
}

Measured memory_bytes: 540
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main()
{
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    cout << a[0]+a[1] << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.awt.geom.*;

public class Main{
	String s;
	int pos;
	int INF = 1 << 29;
	
	public void doit(){
		Scanner sc = new Scanner(System.in);
		int dataset = sc.nextInt();
		while(dataset-- > 0){
			s = sc.next() + "#";
			pos = 0;
			int res = dfs();
			System.out.println(res);
		}
	}

	private int dfs(){
		if(Character.isDigit(s.charAt(pos))){
			int num = s.charAt(pos++) - '0';
			while(Character.isDigit(s.charAt(pos))){
				num = num * 10 + s.charAt(pos++) - '0';
			}
			return num / 2 + 1;
		}
		else{
			int min = INF;
			ArrayList<Integer> list = new ArrayList<Integer>();
			while(s.charAt(pos) == '['){
				pos++;
				int res = dfs();
				pos++;
				list.add(res);
			}
			if(list.size() == 0){
				return min;
			}
			else{
				Collections.sort(list);
				int sum = 0;
				for(int i = 0; i < list.size() / 2 + 1;i++){
					sum += list.get(i);
				}
				return sum;
			}
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

Measured memory_bytes: 63360
#include<stdio.h>
 int main(void)
 {
     char C1[5],C2[5];
     int i,s=0;

     scanf("%s",C1);
     scanf("%s",C2);

     for(i=0;i<3;i++){
       if(C1[i]==C2[2-i]) s++;
     }

     if(s<3) printf("NO\n");
     else printf("YES\n");

     return 0;
 }



Measured memory_bytes: 128
#include<iostream>
#include<array>

using namespace std;

int main(){
    int n,m = 0;
    array<int,200000>a;
    array<int,200000>b;
    cin>>n;
    for(int i = 0; i < n; i++){
        cin>>a.at(i);
        b.at(i) = 0;
    }
    for(int i = n; i > 0; i--){
        int sum = 0,num = i * 2;
        while(num <= n){
            sum += b.at(num - 1);
            num += i;
        }
        sum = sum % 2;
        if(sum != a.at(i-1)) {
            b.at(i-1)++;
            m++;
        }
    }
    cout<<m<<endl;
    for(int i = 0; i < n; i++){
        if(b.at(i) == 1) cout<<i + 1<<endl;
    }
}

Measured memory_bytes: 2432
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX_N 100000

int n;
int A[MAX_N];

int partition(int p, int r){
  int x = A[r];   //基準
  int i = p - 1;
  for(int j = p; j < r; j++){
    if(A[j] <= x){
      i++; swap(A[i], A[j]);
    }
  }
  swap(A[i+1], A[r]);
  return i + 1;
}

int main(void){
  cin >> n;
  for(int i = 0; i < n; i++) cin >> A[i];
  int x = partition(0, n - 1);
  for(int i = 0; i < n; i++){
    if(i) cout << " ";
    if(i == x) cout << "[";
    cout << A[i];
    if(i == x) cout << "]";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1548
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<stack>
#include<queue>
#include<iostream>
using namespace std;
int main(void)
{
	int a,b,c;
	int i,j;
	int n;
	while(1) {
		cin >> n;
		if(n==0)break;
		for(i=0;i<n;i++) {
			cin >>a>>b>>c;
			if(a==100 || b==100 || c==100) cout<<"A"<<endl;
			else if((a+b)/2>=90) cout<<"A"<<endl;
			else if((a+b+c)/3>=80) cout<<"A"<<endl;
			else if((a+b+c)/3>=70) cout<<"B"<<endl;
			else if((a+b+c)/3>=50 && a>=80 || b>=80) cout<<"B"<<endl;
			else cout<<"C"<<endl;
		}
	}
	exit(0);
}

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

#define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = (int)(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl

using namespace std;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

namespace pb_ds {   
    namespace io {
        const int MaxBuff = 1 << 15;
        const int Output = 1 << 23;
        char B[MaxBuff], *S = B, *T = B;
        #define getc() ((S == T) && (T = (S = B) + fread(B, 1, MaxBuff, stdin), S == T) ? 0 : *S++)
        char Out[Output], *iter = Out;
        inline void flush() {
            fwrite(Out, 1, iter - Out, stdout);
            iter = Out;
        }
    }
 
    template<class Type = int> inline Type read() {
        using namespace io;
        register char ch; register Type ans = 0; register bool neg = 0;
        while(ch = getc(), (ch < '0' || ch > '9') && ch != '-')     ;
        ch == '-' ? neg = 1 : ans = ch - '0';
        while(ch = getc(), '0' <= ch && ch <= '9') ans = ans * 10 + ch - '0';
        return neg ? -ans : ans;
    }
}
 
using namespace pb_ds;

void File() {
#ifdef zjp_shadow
	freopen ("C.in", "r", stdin);
	freopen ("C.out", "w", stdout);
#endif
}

const int N = 2e5 + 1e3;

int n, a[N];

long long ans, pre, sum;

int main () {

	File();

	n = read();
	For (i, 1, n)
		sum += (a[i] = read());
	ans = 1e18;

	For (i, 1, n - 1)
		pre += a[i], chkmin(ans, abs(sum - 2 * pre));
	printf ("%lld\n", ans);

	return 0;

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define F first
#define S second
const int N = 2e5 + 87;
int a[N];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    sort(a,a+n);
    int x = a[n-1];
    int i = lower_bound(a,a+n-1,x/2) - a;
    if (i == n-1)
        --i;
    if (i && abs(x/2 - a[i-1]) < abs(a[i] - x/2))
        --i;
    cout << x << ' ' << a[i] << '\n';
}

Measured memory_bytes: 640
N = int(input())
A = list(map(int,input().split()))
ans = 0
tmp = 0
prev = -1
for a in A:
  if prev<a:
    ans = max(tmp, ans)
    tmp = 0
  else:
    tmp+=1
  prev = a
ans = max(ans,tmp)
print(ans)

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

using namespace std;


#define PI 3.14159265
#define int long long




main(){

	int n, x; cin >> n >> x;

	vector <int> l(n);

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


	int ans = 1, current = 0;

	for(int i = 0; i < n; i++){
		current += l[i];
		if(current <= x){
			ans++;
		}
	}

	cout << ans << endl;




	
	
	return 0;
}

Measured memory_bytes: 256
"use strict";
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

var re = /\s+|$/;
reader.on('close', () => {
    var f = lines[0].trim().split(' ').map(Number);
    console.log(aux(f[0],f[1],f[2],f[3]));
});

function aux(x0,y0,x1,y1)
{
    return Math.sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));
}


Measured memory_bytes: 16564
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var W = parseInt(input[0].split(" ")[1]);
  var w = new Array(N);
  var v = new Array(N);
  for(var i=0;i<N;i++){
    tmp=input[i+1].split(" ");
    w[i] =parseInt(tmp[0]);
    v[i] =parseInt(tmp[1]);
  }
  var dp = new Array(1000*N+1).fill(Math.pow(10,9)+1);
  dp[0]=0;
  for(var i=0;i<N;i++){
    for(var j=dp.length-1;j>=v[i];j--){
      if(dp[j-v[i]]+w[i]<=W){
        dp[j]=Math.min(dp[j],dp[j-v[i]]+w[i]);
      }
    }
  }
  var ans=0;
  for(var i=dp.length-1;i>=0;i--){
    if(dp[i]<=W){
      ans=i;
      break;
    }
  }

  console.log('%s', ans);
  return ans;
}
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout.precision(10);
	int n;
	cin >> n;
	int x, y, cnt = 0;
	for (int i = 0; i < n; i++) {
		cin >> x >> y;
		if (x == y)
			cnt++;
		else
			cnt = 0;
		if (cnt >= 3) {
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
	return 0;
}

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

#define ARRAY_MAX 114514

int main(){

    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0;i < 6;i++){
        if(s[i] == '1'){
            ans++;
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 764
import java.util.Scanner;

public class Main{
  
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    String[] tokens = scanner.nextLine().split(" +");
    
    int A = Integer.parseInt(tokens[0]);
    int B = Integer.parseInt(tokens[1]);
    int C = Integer.parseInt(tokens[2]);
    int D = Integer.parseInt(tokens[3]);
    
    System.out.println(Math.max(A*B, C*D));
  }
}

Measured memory_bytes: 21972
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <set>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

struct Point {
  int x;
  int y;
  int type;
  Point() {;}
  Point(double x, double y, int type) : x(x), y(y), type(type) {;}
  bool operator<(const Point &rhs) const {
    if (y != rhs.y) { return y < rhs.y; }
    return x < rhs.x;
  }
};

struct Event {
  int x;
  Point p;
  int in;
  Event() {;}
  Event(int x, Point p, int in) : x(x), p(p), in(in) {;}
  bool operator<(const Event &rhs) const {
    if (x != rhs.x) { return x < rhs.x; }
    return in > rhs.in;
  }
};

inline int square(int x) { return x * x; }

inline int dist2(const Point &a, const Point &b) {
  return square(a.x - b.x) + square(a.y - b.y);
}

int an, bn, n;
int r;
Event event[500000];

int PlaneSweep() {
  int ans = 0;
  set<Point> open[2];
  REP(iter, n) {
    Event &e = event[iter];
    Point &p = e.p;
    if (e.in) {
      set<Point>::iterator lower = open[p.type ^ 1].lower_bound(Point(0, p.y - 4.0 * r - 1, 0));
      set<Point>::iterator upper = open[p.type ^ 1].upper_bound(Point(0, p.y + 4.0 * r + 1, 0));
      for (set<Point>::iterator it = lower; it != upper; it++) {
        if (dist2(*it, p) <= 16.0 * r * r) { ans++; }
      }
      open[p.type].insert(p);
    } else {
      open[p.type].erase(open[p.type].find(p));
    }
  }
  return ans;
}

int main() {
  while (scanf("%d %d %d", &an, &bn, &r), an|bn) {
    n = (an + bn) * 2;
    REP(i, an) {
      int x, y;
      scanf("%d %d", &x, &y);
      event[2 * i + 0] = Event(x - 2 * r, Point(x, y, 0), 1);
      event[2 * i + 1] = Event(x + 2 * r, Point(x, y, 0), 0);
    }
    REP(i, bn) {
      int x, y;
      scanf("%d %d", &x, &y);
      event[2 * an + 2 * i + 0] = Event(x - 2 * r, Point(x, y, 1), 1);
      event[2 * an + 2 * i + 1] = Event(x + 2 * r, Point(x, y, 1), 0);
    }
    sort(event, event + n);
    int ans = PlaneSweep();
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 8756
#include<iostream>
#include<vector>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;

int main(){
	int n;
	cin>>n;
	vector<long long int>a(n);
	rep(i,n)cin>>a[i];
	rep(i,n){
		if(a[i]==0){
			cout<<0<<endl;
			return 0;
		}
	}
	long long int sum = 1;
	rep(i,n){
		if((1000000000000000000)/sum>=a[i]){
			sum*=a[i];
		}else{
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3996
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 NK = Sarray();

            var N = NK[0];
            var K = NK[1];
            var ans = K * (long)Pow(K - 1, N - 1);
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include<iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(ll i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout<< "YES"<<endl;
#define No cout<< "No"<<endl;
#define Yes cout<< "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
 
//(int)'a'=97 (int)'A'=65 (int)'1'=49
//おまじない
 
const int maxn = 300000;
 
int main(){
    
    ll n;
    ll mod = INF;
    ll ans=0;
    ll a[maxn];
    cin >> n;
    
    rep(i,n)cin >> a[i];
    
    ll b = 1;
    rep(i,60){
        ll c = b;
        b=b*2;
        ll A=0,B=0;
        rep(j,n){
            if(c<=a[j]%b)A++;
        }
        B = n-A;
        ans += (((A*B)%mod)*(c % mod))%mod;
        ans %=mod;
    }
    
    cout << ans <<endl;
    
    return 0;
}

Measured memory_bytes: 2560
n = 10 ** 9
k = 2 * 10 ** 5
mod = 10**9 + 7

modinv_table = [-1] * (k+1)
modinv_table[1] = 1
for i in range(2, k+1):
  modinv_table[i] = (-modinv_table[mod % i] * (mod // i)) % mod

def binomial_coefficients(n, k):
  ans = 1
  for i in range(k):
    ans *= n-i
    ans *= modinv_table[i + 1]
    ans %= mod
  return ans

s,a,b = map(int, input().split())
sum = 0
if s == 2:
  pass
else:
  d = pow(2, s, mod) - 1
  sum = d - binomial_coefficients(s, a) - binomial_coefficients(s, b)
while sum < 0:
  sum = sum + mod
print(sum)

Measured memory_bytes: 11252
#include <bits/stdc++.h>
using namespace std;
#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 fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e18 + 3)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int n;
    cin >> n;
    int A[n];
    REP(i,n) cin >> A[i];
    sort(A,A+n);
    int k = A[n-1];
    int kazu[n] = {};
    REP(i,n){
        kazu[A[i]] ++;
    }

    int kijun = k / 2;
    if(k % 2 == 1) kijun ++;
    REP(i,kijun){
        if(kazu[i] != 0){
            cout << "Impossible" << endl;
            return 0;
        }
    }
    if(k %2 == 1){
        if(kazu[kijun] != 2){
            cout << "Impossible" << endl;
            return 0;
        }
    }
    else{
        if(kazu[kijun] != 1){
            cout << "Impossible" << endl;
            return 0;
        }
    }
    FOR(i,kijun + 1, k+1){
        if(kazu[i] < 2){
            cout<< "Impossible" << endl;
            return 0;
        }
    }
    cout << "Possible" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<cstdlib>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<vector>
#include<cmath>
#include<string>
#include<deque>
#define lmid l,mid,rt<<1
#define rmid mid+1,r,rt<<1|1
using namespace std;
int x[9000], y[9000];
int dpx[9000], dpy[9000];
char s[9000];
int main() {
     int cntx = 0, cnty = 0;
     scanf("%s", s);
     int n = strlen(s);
     int xx, yy;
     scanf("%d%d", &xx, &yy);
     bool flag = true, vis = true; //为x方向
     int res = 0, ans = 0;
     for (int i = 0; i < n; i++) {
          if (s[i] == 'T') {
               res++;
               ans = 1;
          }
          if (s[i] == 'F') {
               if (ans == 0) {
                    xx -= 1;
                    res = 0;
                    continue;
               }
               if (res % 2) {
                    flag = !flag;
               }
               if (flag) {
                    if (res == 0) {
                         x[cntx]++;
                    } else x[++cntx]++;
               } else {
                    if (res == 0) {
                         y[cnty]++;
                    } else y[++cnty]++;
               }
               res = 0;
          }
     }
     xx = abs(xx), yy = abs(yy);
     dpx[0] = 1, dpy[0] = 1;
     int a = xx, b = yy;
     for (int i = 0; i <= cntx; i++) {
          //cout<<x[i]<<endl;
          a += x[i];
     }
     for (int i = 0; i <= cnty; i++) {
          //cout<<y[i]<<endl;
          b += y[i];
     }
     //cout<<a<<" "<<b<<endl;
     if ((a % 2) == 0) {
          a /= 2;
          for (int i = 0; i <= cntx; i++) {
               //cout<<x[i]<<endl;
               for (int j = a; j >= x[i]; j--) {
                    dpx[j] += dpx[j - x[i]];
               }
          }
     } else {printf("No\n");return 0;}
     if ((b % 2) == 0) {
          b /= 2;
          for (int i = 0; i <= cnty; i++) {
               //cout<<x[i]<<endl;
               for (int j = b; j >= y[i]; j--) {
                    dpy[j] += dpy[j - y[i]];
               }
          }
     } else{printf("No\n");return 0;}
     if (dpx[a] && dpy[b]) {
          printf("Yes\n");
     } else printf("No\n");
     return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
cd = [list(map(int, input().split())) for i in range(m)]

for i in range(n):
    ans = 1
    dis = abs(ab[i][0] - cd[0][0]) + abs(ab[i][1] - cd[0][1])
    for j in range(m):
        if dis > abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]):
            dis = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
            ans = j+1
    print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

void solve() {
	int n, k;
	cin >> n >> k;
	
	vi dp(k + 1, 0);
	dp[0] = 1;
	for(int i = 0; i < n; i++) {
		int a;
		cin >> a;
		vi fake(k + 1, 0);
		for(int j = k; j >= 0; j--) {
			int tmp = dp[j];
			int l = j + 1, r = min(a + j, k);
			if(r >= l) {
				fake[l] = (fake[l] + tmp) % P;
				if(r + 1 <= k)fake[r + 1] = (fake[r + 1] - tmp + P) % P;
			}
		}
		
		int sum = 0;
		for(int j = 0; j < k + 1; j++) {
			sum = (sum + fake[j]) % P;
			dp[j] = (dp[j] + sum) % P;
		}
	}
	
	cout << dp[k] << endl;
}

int main(){
#define MULTITEST 0
#if MULTITEST   
 
    CASET {
        solve();
    }
    
#else

    solve();
    
#endif

    return 0;
}

Measured memory_bytes: 4056
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        List<Integer> h = new ArrayList<>();

        for (int i = 0; i < n; i++) {
            h.add(sc.nextInt());
        }
        Collections.sort(h);
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n - k + 1; i++) {
            int hmax = h.get(i + k - 1);
            int hmin = h.get(i);
            if (min > hmax - hmin) {
                min = hmax - hmin;
            }
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 57984
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <sstream>

using namespace std;
using ll = long long;

int main() {
	ll argN;
	cin >> argN;
	vector<ll> argA(argN * 3);

	for (ll i = 0; i < argN * 3; ++i) {
		cin >> argA.at(i);
	}

	sort(argA.begin(), argA.end(), greater<ll>());
	ll ret = 0;
	for (ll i = 0; i < argN * 2; i += 2) {
		ret += argA.at(i + 1);
	}

	cout << ret << endl;
}

Measured memory_bytes: 2560
raw_time = int(raw_input())
 
if 0 <= raw_time < 86400:
    hour = raw_time / 3600
    minute = (raw_time - hour * 3600) / 60
    second = (raw_time - hour * 3600 - minute * 60)
    print("%d:%d:%d") % (hour, minute, second)

Measured memory_bytes: 6424
N = int(input())
X = list(map(int, (input().split())))

distance = lambda Xi, P: (Xi - P) ** 2

X_max = max(X)

answer = None
for P in range(1, X_max + 1):
    total = 0
    for Xi in X:
        total += distance(Xi, P)
    answer = min(total, answer) if answer is not None else total

print(answer)


Measured memory_bytes: 38640
import itertools

N = int(input())
A = list(map(int,input().split()))
A.sort()
B = list(itertools.accumulate(A))
jdg = 0

for i in range(1,N):
    if A[i] > B[i-1]*2:
        #print(A[i],B[i-1])
        jdg = i
print(N-jdg)

Measured memory_bytes: 63856
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main {

	public static final int mod=1000000007;
	public static LinkedList<Integer>[] tree;
	public static long ans=1;
	public static long k;
	public static boolean[] visited;
	
	
	public static void dfs(int current) {
		 if(current==0) {
			 ans=(ans%mod*k%mod)%mod;
			 for(int i=0;i<tree[current].size();i++) {
				 ans=(ans%mod*(k-1-i)%mod)%mod;
			 }
		 }else {
			 for(int i=0;i<tree[current].size()-1;i++) {
				 ans=(ans%mod*(k-2-i)%mod)%mod;
			 }
		 }
		 visited[current]=true;
		for(Integer x:tree[current]) {
			 	if(!visited[x])dfs(x);
		 }
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		out=new PrintWriter (new BufferedOutputStream(System.out));
		FastReader s=new FastReader();
		int n=s.nextInt();
		k=s.nextInt();
		visited=new boolean[n];
		tree=new LinkedList[n];
		for(int i=0;i<n;i++)tree[i]=new LinkedList<Integer>();
		for(int i=0;i<n-1;i++) {
			int x=s.nextInt()-1;
			int y=s.nextInt()-1;
			tree[x].add(y);
			tree[y].add(x);
		}
		dfs(0);
		out.println(ans);
		out.close();
	}

	public static PrintWriter out;
	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
		//it reads the data about the specified point and divide the data about it ,it is quite fast
		//than using direct 

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
			//InputStream reads the data and decodes in character stream
			//It acts as bridge between byte stream and character stream
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception e) {
				e.printStackTrace();
			}
			return str;
		}
	}
	
}


Measured memory_bytes: 78756
r, g, b, n = map(int, input().split())

count = 0
a = n // r
t = n // g

for i in range(a+1):
    for j in range(t+1):
        rg = i * r + j * g
        rest = n - rg
        if rest < 0:
            continue
        elif rest % b == 0:
            count += 1

print(count)

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

int main(){
    int N,K;
    cin >> N >> K;
    long long H[N];
    for(int i=0; i<N; i++){
        cin >> H[i];
    }
    sort(H, H+N);

    long long sum=0;
    for(int i=0; i<N-K; i++){
        sum += H[i];
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x;
  cin>>x;
  for(int i=x;;i++){
    bool sosu=false;
    int ans=0;
    if(i==1){
      sosu=false;// 1は違う
    }
    else if(i==2){
      sosu=true; // 2はOK
    }
    else{
      for(int j=1; j<i-1; j++){
        if(i%(j+1)==0){
          ans++;
        }
      }
      if(ans==0){
        sosu=true;
      }
    }
    if(sosu){
      cout<<i<<endl;
      break;
    }
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
//#include<cmath>
//#include<array>
#include<algorithm>
//#include<deque>
#include<vector>
//#include<utility>
//#include<set>
//#include<map>
//#include<list>
//#include<bitset>

using namespace std;
using LLI = long long int;
LLI N;

//array<int, 8>dir_x = { 0,0,1,1,1,-1,-1,-1 };
//array<int, 8>dir_y = { 1,-1,1,0,-1,1,0,-1 };
//array<int, 4>dir_x2 = { 0,0,1,-1 };
//array<int, 4>dir_y2 = { 1,-1,0,0 };
//char alp[] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };

//class UnionFind {
//public:
//	vector<int>data;
//	UnionFind(int size) :data(size, -1) {};
//	bool unionset(int x, int y) {
//		x = root(x), y = root(y);
//		if (x != y) {
//			if (data[y] < data[x]) {
//				swap(x, y);
//			}
//			data[x] += data[y];
//			data[y] = x;
//		}
//		return x != y;
//	}
//	bool findset(int x, int y) {
//		return root(x) == root(y);
//	}
//	int root(int x) {
//		return data[x] < 0 ? x : data[x] = root(data[x]);
//	}
//	int size(int x) {
//		return -data[root(x)];
//	}
//};

LLI gcd(LLI x, LLI y) {
	LLI  r;
	if (x < y) {
		swap(x, y);
	}
	r = x % y;
	while (r != 0) {
		x = y;
		y = r;
		r = x % y;
	}
	return y;
}
LLI lcm(LLI x, LLI y) {
	return x / gcd(x, y) * y;
}

long nCr(int n, int r) {
	long ans = 1;
	for (int i = n; i > n - r; i--) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; i++) {
		ans = ans / i;
	}
	return ans;
}

//const int n_max = 8;
//array<array<bool, n_max>, n_max>graph;
//int dfs(int v,int N,array<bool,n_max>visited) {
//	int ret = 0;
//	bool all_visited = true;
//	for (int i = 0; i < N;i++) {
//		if (visited[i] == false) {
//			all_visited = false;
//		}
//	}	
//	if (all_visited) {
//		return 1;
//	}
//	for (int i = 0; i < N;i++) {
//		if (graph[v][i] == false) {
//			continue;
//		}
//		if (visited[i] == true) {
//			continue;
//		}
//		visited[i] = true;
//		ret += dfs(i,N,visited);
//		visited[i] = false;
//	}
//	return ret;
//}

//vector<vector<int>>sub;
//int dfs(int id) {
//	if (sub[id].size() == 0) {
//		return 1;
//	}
//	int minP = (int)1e9;
//	int maxP = 0;
//	for (int i : sub[id]) {
//		int P = dfs(i);
//		minP = min(minP, P);
//		maxP = max(maxP, P);
//	}
//	return minP + maxP + 1;
//}

//#define debug(x) cerr << #x << " : " << x << endl
//#define debugv(x) cerr << #x << " : "; for(auto i:x) cerr << i << ", "; cerr<<endl

int main(void) {
	LLI R, G, B,cnt = 0,sum;
	cin >> R >> G >> B >> N;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N;j++) {
			sum = N - (R * i) - (G * j);
			if (sum % B == 0 && sum >= 0) {
				cnt++;
			}
		}
	}
	cout << cnt << endl;
}

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

int main()
{
  char s[100]={};
  int i;
  
  scanf("%s",s);
  
  int l=strlen(s);
  int count=0;
  
  count=l-2;
  
  printf("%c%d%c\n",s[0],count,s[l-1]);
  
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n,max=0,min=1000,a[100];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		if(max<a[i]){
			max=a[i];
		}
		if(min>a[i]){
			min=a[i];
		}
	}
	cout<<max-min<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int M =1e5+5;
int a[M];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int b;
		scanf("%d",&b);
		a[b]++;
		a[b+1]++;
		a[b-1]++;
	}
	int max=0;
	for(int i=0;i<M-1;i++)
	{
		if(max<a[i])max=a[i];
	}
	printf("%d\n",max);
	return 0;
}

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

int main() {
	//freopen("in", "r", stdin);

	int n, m;
	scanf("%d %d", &n, &m);
	printf("%d\n", (1 << m) * (m * 1900 + (n - m) * 100));
	return 0;
}

Measured memory_bytes: 256
S_A = gets.split("")
S_B = gets.split("")
S_C = gets.split("")
x = 'A'
while S_A.size > 0 && S_B.size > 0 && S_C.size > 0
    if x == 'A'
        if S_A[0] == 'a'
            x = 'A' 
        elsif S_A[0] == 'b'
            x = 'B'
        elsif S_A[0] == 'c'
            x = 'C'
        end
        S_A.delete_at(0)
    elsif x == 'B'
        if S_B[0] == 'a'
            x = 'A' 
        elsif S_B[0] == 'b'
            x = 'B'
        elsif S_B[0] == 'c'
            x = 'C'
        end
        S_B.delete_at(0)
    elsif x == 'C'
        if S_C[0] == 'a'
            x = 'A' 
        elsif S_C[0] == 'b'
            x = 'B'
        elsif S_C[0] == 'c'
            x = 'C'
        end
        S_C.delete_at(0)
    end
end

if S_A.size == 0
    puts 'A'
elsif S_B.size == 0
    puts 'B'
elsif S_C.size == 0
    puts 'C'
end


    

Measured memory_bytes: 1788
#include<stdio.h>
int main(){
  int s = 0;
  int m = 0;
  int h = 0;
  scanf("%d",&s);
  h = s/3600;
  m = s%3600/60;
  s = s%60;
  printf("%d:%d:%d\n",h,m,s);
  return 0;
}

Measured memory_bytes: 592
#include <cstdio>
#define FOR(i, l, r) for(int i = l; i <= r; ++i)

using namespace std;

const int N = 1010;

long long a[N], mx[N], ans;
int wh[N], num, n, ansi, tmp;

int main()
{
    scanf("%d", &n);
    FOR(i, 1, n) scanf("%lld", &a[i]);
    ans = -1e9 - 10;

    FOR(i, 1, n)
    {
        for(int j = i - 2; j > 0; j -= 2)
            if (mx[j] > mx[i]) mx[i] = mx[j], wh[i] = j;
        mx[i] += a[i];
        if (mx[i] > ans) ans = mx[i], ansi = i;
    }

    printf("%lld\n", ans);
    for(int i = ansi; i; i = wh[i]) if (!wh[i]) tmp = i;
    for(int i = n; i > ansi; --i) ++num;
    for(int i = wh[ansi], lst = ansi; i; lst = i, i = wh[i])
        for(int j = (i + lst) / 2; j > i; --j) ++num;
    printf("%d\n", num + tmp - 1);
    for(int i = n; i > ansi; --i) printf("%d\n", i);
    for(int i = wh[ansi], lst = ansi; i; lst = i, i = wh[i])
        for(int j = (i + lst) / 2; j > i; --j) printf("%d\n", j);
    FOR(i, 1, tmp - 1) puts("1");

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ld long double

using namespace std;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
    
    ll k;
    cin >> k;

    //if(k%2 == 0) cout << -1 << endl;

    ll use = 7;
    ll add = 7;

    for(int i = 1; i < 999986; i++){
        use %= k;

        if(use == 0){ cout << i << endl; return 0; }

        add *= 10;
        add %= k;

        use += add;

    }

    cout << -1 << endl;
   

    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main()
{
  int n,a[100],i;
  scanf("%d",&n);
  for(i=0; i<n; i++)
    {
      scanf("%d",&a[i]);
    }
  if(n!=0) printf("%d",a[n-1]);
  for(i=n-2; i>=0; i--)
    {
      printf(" %d",a[i]);
    }
  printf("\n");
  return 0;
}

Measured memory_bytes: 600
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <complex>
#include <cstdio>
#include <queue>

using namespace std;
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	int even = 0;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		if (A % 2 == 0) {
			even++;
		}
	}
	int ans = pow(3, N) - pow(2, even);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int MX = 2010 * 2010;

bitset<MX> dp;

int n;

int sum;

int a[2100];

int main() {
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i], sum += a[i];
	dp[0] = 1;
	for (int i = 0; i < n; ++i) {
		dp |= (dp << a[i]);
	}
	sum = (sum + 1) / 2;
	for (int i = sum; i < MX; ++i) {
		if (dp[i]) {
			cout << i << "\n";
			return 0;
		}
	}
	return 0;
}




Measured memory_bytes: 1792
def run(n, a):
    now = a[0]
    cnt = 0
    if n == 1:
        return 0
    i = 1
    while(True):
        if now == a[i]:
            cnt += 1
            i += 1
            if i >= n:
                return cnt
            now = a[i]
            i += 1
            if i >= n:
                return cnt
        else:
            now = a[i]
            i += 1
            if i >= n:
                return cnt


def read_line():
    n = int(input())
    a = list(map(int, input().split()))
    return (n, a)


def main():
    n, a = read_line()
    print(run(n, a))


if __name__ == '__main__':
    main()


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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;


int main() {
  int N;
  cin >> N;
  int ans=0;
  for(int i=1;i<=N;i+=2){
    int d=0;
    reps(j,i){
      if(!(i%j))d++;
    }
    if(d==8)ans++;
  }
  cout << ans;
}

Measured memory_bytes: 256
N=int(input())
c=list(input())

left=0
right=N
ans=0
while True:
    
    for il in range(left,N):
        if c[il]=="W":
            break
    else:
        il=N
        
    for ir in range(right-1,-1,-1):
        if c[ir]=="R":
            break
    else:
        ir=-1
    
    
    if il<ir:
        c[il]="R"
        c[ir]="W"
        left=il+1
        right=ir
        ans+=1
    else:
        break
        
print(ans)

Measured memory_bytes: 78160
#include <iostream>
#include <algorithm>
using namespace std;
int main(void) {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int x = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'I') x++;
    else x--;
    ans = max(ans, x);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256