akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

typedef long long ll;
const int N = 54, N3 = 125400;

struct item {
	int w, c, lim;
	item (int weight = 0, int cost = 0, int limit = 0) : w(weight), c(cost), lim(limit) {}
	inline bool operator < (const item &B) const {return (ll)w * B.c < (ll)c * B.w;}
} a[N];

int n, W, C;
int _[N], f[N][N3];
bool fail[N];

inline void up(int &x, const int y) {x < y ? x = y : 0;}
inline void down(int &x, const int y) {x > y ? x = y : 0;}
inline int min(const int x, const int y) {return x < y ? x : y;}

int distribute(int W) {
	int i, m, C = 0;
	for (i = 1; i <= n; ++i) m = min(W / a[i].w, a[i].lim), W -= m * a[i].w, C += m * a[i].c;
	return C;
}

int main() {
	int i, j, k, w, co, ans = 0; ll cost;
	scanf("%d%d%d%d", &n, &W, &j, &w), a[1] = item(w, 1, INT_MAX);
	for (i = 2; i <= n; ++i) scanf("%d%d", &w, _ + i), a[i] = item(w, 1, j);
	for (i = n; i > 1; --i) j = _[i], fail[j] |= fail[i] || (a[j].w += a[i].w) > W, a[j].c += a[i].c;
	C = n * n * n;
	for (i = w = n; i; --i) if (fail[i]) std::swap(a[i], a[n--]);
	memset(f, 63, sizeof f), **f = 0;
	for (i = 1; i <= n; ++i) {
		k = min(a[i].lim, w), a[i].lim -= k;
		for (co = 0; co <= k && (cost = (ll)co * a[i].w) <= W; ++co)
			for (j = co * a[i].c; j <= C; ++j)
				down(f[i][j], f[i - 1][j - co * a[i].c] + cost);
	}
	std::sort(a + 1, a + (n + 1));
	for (j = 0; j <= C; ++j) if (f[n][j] <= W) up(ans, distribute(W - f[n][j]) + j);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 26752
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
  
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}
  
int main()
{
  int n;

  cin >> n;
  if(n%2 == 0){
      cout << n/2 - 1 << endl;
  }
  else{
      cout << (n-1)/2 << endl;
  }
  return 0;
}


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

using namespace std;

namespace {
    string s;
    void input() {
        cin >> s;
    }

    void solve() {
        const string t = "AKIHABARA";
        int i = 0, j = 0;
        auto f = [&]() {
            while (j < t.size()) {
                if (i < s.size() && s[i] == t[j]) {
                    i++;
                    j++;
                } else if (t[j] == 'A') {
                    j++;
                } else {
                    return false;
                }
            }
            return i == s.size() && j == t.size();
        };
        cout << (f() ? "YES" : "NO") << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
//#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
#define puts(x) cout << x << endl
using namespace std;
int input() {
	int r;
	cin >> r;
	//scanf("%lld", &r);
	return r;
}
signed main() {
	int n, m; cin >> n >> m;
	int a = 1, b = n;
	if (n % 2) {
		for1(i, m) {
			cout << a << ' ' << b << endl;
			a++; b--;
		}
	}
	else {
		int k = 1; bool b00l = 0;
		for1(i, m) {
			cout << a << ' ' << b << endl;
			a++; b--;
			k += 2;
			if (k >= n / 2 && !b00l) { b--; b00l = 1; }
		}
	}
}

Measured memory_bytes: 3640
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
#mod = 10**9 + 7
#mod = 9982443453
mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
#mod = 10**9 + 7
#mod = 9982443453
mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
k,n = readInts()
A = sorted(readInts())
A.append(A[0])
long = 0
for i in range(n):
    if i != n-1:
        long = max(long,abs(A[i+1] - A[i]))
    else:
        long = max(long, abs((k-A[i]) + A[i+1]))
print(k - long)


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

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

  int max = 0;

  for(int i=1;i<N;i++) {
    string x = S.substr(0, i);
    string y = S.substr(i, N-i);

    int total = 0;
    map<char, int> counter;

    for(int j=0;j<x.size();j++) {
      for(int k=0;k<y.size();k++) {
        if(x[j] == y[k] && counter[x[j]] != 1) {
          total++;
          counter[x[j]]++;
          break;
        }
      }
    }

    if(total > max) {
      max = total;
    }
  }

  cout << max << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        int n = in.nextInt();
        int t = in.nextInt();
        int a = in.nextInt();
        double q = Double.MAX_VALUE;
        int index = 0;
        for (int i = 1; i <= n; i++) {
            double x = Math.abs(a - (t - in.nextInt() * 0.006));
            if (x < q) {
                q = x;
                index = i;
            }
        }

        out.println(index);
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

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

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

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}

Measured memory_bytes: 23252
// https://atcoder.jp/contests/abc128/tasks/abc128_b

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<string, int> PSI;
#define INF (1e9)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
// int gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// int lcm(long a, long b) { return a * b / gcd(a, b); }
typedef tuple<string, int, int> mytuple;
// タプルの最初の要素から順番に比較　もしその要素が同じなら次の要素で比較
bool mycompare(const mytuple &lhs, const mytuple &rhs) {
    if (std::get<0>(lhs) != std::get<0>(rhs))
        return std::get<0>(lhs) < std::get<0>(rhs);
    if (std::get<1>(lhs) != std::get<1>(rhs))
        return std::get<1>(lhs) > std::get<1>(rhs); // 点数が高い方
    return std::get<2>(lhs) < std::get<2>(rhs);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, p;
    string s;
    cin >> n;
    vector<mytuple> v(n);
    for (int i = 0; i < n; i++) {
        cin >> s >> p;
        v[i] = make_tuple(s, p, i + 1);
    }
    sort(ALL(v), mycompare);
    for (auto x : v) {
        cout << get<2>(x) << '\n';
    }

    return 0;
}

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

using namespace std;

typedef long long ll;

#define rep(i, N) for (ll i = 0; i < (ll)(N); ++i)

int main(){
    double N,K,ans=0;
    cin >> N >> K;
    vector<double> p(N,0);
    vector<double> exp(N,0);
    vector<double> sum(N,0);

    for(ll i=0;i<N;i++){
        cin >> p[i];
        exp[i] = (p[i]+1)/2;
        if(i!=0){
        sum[i] += exp[i]+sum[i-1];
        }else{
        sum[i] = exp[i];
        }
    }
    
    for(ll i=K-1;i<N;i++){
        if(i == K-1){
        ans = sum[i];
    }
    ans = max(ans,sum[i]-sum[i-K]);
}
    cout << fixed << ans << endl;
    return 0;
}

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

#define pb push_back
#define mp make_pair
#define f first
#define s second

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef long long ll;

int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n, k;
    cin >> n >> k;

    vi h(n);
    for(auto &i: h) cin >> i;

    vi dp(n,1e9+5);
    dp[0] = 0;
    
    for(int i=1; i < n; i++){
        for(int j=max(0, i-k); j < i; j++){
            dp[i] = min(dp[i], dp[j]+abs(h[i]-h[j]));
        }
    }

    cout << dp[n-1] << endl;

    return 0;
}

Measured memory_bytes: 1152
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int n,h,w;
  int x[SIZE];
  
  scanf("%d%d%d",&n,&h,&w);

  int sum[SIZE] = {};
  
  for(int i=0;i<n;i++){
    scanf("%d",x+i);
    if(i%2 == 0){
      sum[i*w + x[i]]++;
      sum[(i+1)*w + x[i]]--;
    }else{
      sum[i*w - x[i]]++;
      sum[(i+1)*w - x[i]]--;
    }
  }

  int ans = 0;
  
  for(int i=0;i<n*w;i++){
    ans += sum[i] == 0;
    sum[i+1] += sum[i];
  }

  printf("%d\n",ans*h);
  
  return 0;
}

Measured memory_bytes: 3612
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		long  X = s.nextLong();
	    long money =100;
		long Xyear =0;
		while( money < X ) {
			money *= 1.01;
			Xyear++;
		}
		System.out.println(Xyear);
	}

}

Measured memory_bytes: 35648
while True:
    s = 0
    n, x = map(int, input().split())
    if n == 0 and x == 0:
        break
    for a in range(1, n+1):
        for b in range(a+1, min(n+1, x-a)):
            for c in range(b+1, min(n+1, x-b)):
                s += 1 if a+b+c==x else 0
    print(s)    



Measured memory_bytes: 5596
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
using namespace std;

int main(){
    int a;
    cin>>a;
    a=a%10;
    if(a==3){
        cout<<"bon"<<endl;
    }
    else if(a<=1||a==6||a==8){
        cout<<"pon"<<endl;
    }
    else{
        cout<<"hon"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3596
using System;

namespace abc114A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int A = int.Parse(Console.ReadLine());
            if (A == 7 || A == 5 || A == 3)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
        }
    }
}


Measured memory_bytes: 11092
#include <stdio.h>
typedef struct{
  int number;
  float time;
}player;
int main(){
  player rase1[8];
  player rase2[8];
  player rase3[8];
  player total_rase[18];
  player tmp;
  int i,j=0,n=0,a=0,p;
  double k;
  for(i=0;i<24;i++){
    scanf("%d %lf",&p,&k);
    if(i >= 0 && i <= 7){
      rase1[j].number=p;
      rase1[j].time=k;
      j++;
    }
    else if(i <= 15){
      rase2[n].number=p;
      rase2[n].time=k;
      n++;
    }
    else if(i <= 23){
      rase3[a].number=p;
      rase3[a].time=k;
      a++;
    }
  }
  for(i=0;i<7;i++){
    for(j=7;j>i;j--){
      if(rase1[j].time < rase1[j-1].time){
	tmp=rase1[j];
	rase1[j]=rase1[j-1];
	rase1[j-1]=tmp;
      }
    }
  }
  for(i=0;i<7;i++){
    for(j=7;j>i;j--){
      if(rase2[j].time < rase2[j-1].time){
	tmp=rase2[j];
	rase2[j]=rase2[j-1];
	rase2[j-1]=tmp;
      }
    }
  }
  for(i=0;i<7;i++){
    for(j=7;j>i;j--){
      if(rase3[j].time < rase3[j-1].time){
	tmp=rase3[j];
	rase3[j]=rase3[j-1];
	rase3[j-1]=tmp;
      }
    }
  }
  for(i=0;i<2;i++){
    printf("%d %.2f\n",rase1[i].number,rase1[i].time);
  }
  for(i=0;i<2;i++){
    printf("%d %.2f\n",rase2[i].number,rase2[i].time);
  }
  for(i=0;i<2;i++){
    printf("%d %.2f\n",rase3[i].number,rase3[i].time);
  }
  for(i=2;i<8;i++){
    total_rase[i-2].number=rase1[i].number;
    total_rase[i-2].time=rase1[i].time;
  }
  for(i=10;i<16;i++){
    total_rase[i-4].number=rase2[i-8].number;
    total_rase[i-4].time=rase2[i-8].time;
  }
  for(i=18;i<24;i++){
    total_rase[i-6].number=rase3[i-16].number;
    total_rase[i-6].time=rase3[i-16].time;
  }
  for(i=0;i<17;i++){
    for(j=17;j>i;j--){
      if(total_rase[j].time < total_rase[j-1].time){
	tmp=total_rase[j];
	total_rase[j]=total_rase[j-1];
	total_rase[j-1]=tmp;
      }
    }
  }
  for(i=0;i<2;i++){
    printf("%d %.2f\n",total_rase[i].number,total_rase[i].time);
    }
  return (0);
}

Measured memory_bytes: 652
import numpy as np

n, k = map(int, input().split())
# お菓子とすぬけの行列(k行n列)
matrix = np.zeros(shape=(k, n))

for row in range(k):
  _ = int(input())
  fn = [int(i) for i in input().split()] 
  for col in fn:
	  matrix[row, col - 1] = 1 # お菓子kをすぬけnが持つかどうかのフラグ

print(np.count_nonzero(matrix.sum(axis=0)==0, axis=0))

Measured memory_bytes: 27260
while True:
    (m,n,o)=map(str, raw_input().split())
    m,o=int(m),int(o)
    if n=='?': break
    elif n=='+': print m+o
    elif n=='-': print m-o
    elif n=='*': print m*o
    elif n=='/': print m/o
    else: pass

Measured memory_bytes: 4208
//a
#include <iostream>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <functional>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>

#define REP(i,b,n) for(int i=b;i<n;i++)
#define REPR(i,b,n) for(int i=n-1;i>=b;i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define EACH(i, c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n, b) ((n>>b) & 1)
#define PB push_back
#define MP make_pair

using namespace std;

static const double PI = acos(-1.0);
static const double EPS = 1e-9;
typedef long long ll;
typedef pair<int, int> pii;



int main(){

	bool stu[31]={0};
	
	int a;
	
	for(int i=0; i<28; ++i){
		
		cin>>a;
		stu[a]=true;
	}
	
	for(int i=1; i<=30; ++i){
		if(!stu[i])
			cout << i<< endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std ;
#define ll long long 
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)

int const N = 1000, NN = N * N;
int fr[60], n, k, y[N];
vector<ll> x;
bool add[NN];

void ad(ll x, int v){
	int j = 0;
	while (x){
		if (x & 1)fr[j] += v;
		++j;
		x >>= 1;
	}
}

ll go(){
	ll an = 0;
	for (int i = 59; i >= 0; --i)if (fr[i] >= k){
		an |= 1ll << i;
		f(j, 0, x.size())if (add[j] && !(x[j] >> i & 1))ad(x[j], -1), add[j] = false;
	}
	return an;
}

int main(){
	scanf("%d%d", &n, &k);
	f(i, 0, n)scanf("%d", y + i);
	f(i, 0, n){
		ll s = 0;
		f(j, i, n)s += y[j], x.push_back(s);
	}
	f(i, 0, x.size())add[i] = true;
	f(i, 0, x.size())ad(x[i], 1);
	printf("%lld\n", go());
}

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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

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

int n,m;

int main(){
	cin >> n >> m;
	
	int cnt = 0;
	if(abs(n) < abs(m)){
		if(n < 0) cnt++;
		if(m < 0) cnt++;
		cnt += abs(m) - abs(n);
	}
	else if(abs(n) > abs(m)){
		if(n > 0) cnt++;
		if(m > 0) cnt++;
		cnt += abs(n) - abs(m);
	}
	else if(n != m) cnt++;
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {

	int a, b, c, s, count, i, d, num,e;

	cin >> a >> b >> c;

	count = 0;
	s = 0;
	i = 0;
	num = 0;
	e = 0;

		for (i = 1; i <= c; i++) {

			d = c%i;

			if (d == 0) {

				for (e = a; e <= b; e++) {

					if (e == i) {

						num = num + 1;
					}

				}
			}

		}

	cout << num << endl;
}

Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define lint long long int
#define rep(i,n) for(int i=0;i<int(n);i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define arep(i,a,n) for(int i=a;i<n;i++)
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define fill(a,x) fill(a.begin(),a.end(),x)
#define eb(data) emplace_back(data)
#define pb(data) emplace_back(data)
#define mp make_pair
#define ALNUM 26
#define vint vector<int>
#define F first
#define S second
#define ALL(data) data.begin(),data.end()
using namespace std;
template<typename Rast>inline void out(Rast rast){cout<<rast<<"\n";return;}
template<typename Rast>inline void in(Rast& rast){cin>>rast;return;}
template<typename T>istream& operator >> (istream& is, vector<T>& vec){for(T& x: vec) is >> x;return is;}
template<typename First, typename... Rest>void in(First& first, Rest&... rest){cin >> first;in(rest...);return;}
template<typename First, typename... Rest>void out(First first, Rest... rest){cout << first<<" ";out(rest...);return;}
template<typename T>T gcd( T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<typename T1,typename T2>bool chmax(T1& a,T2 b){if(a<b){a=b;return true;}else{return false;}}
template<typename T1,typename T2>bool chmin(T1& a,T2 b){if(a>b){a=b;return true;}else{return false;}}
template<typename T>T lcm(T a, T b){return a * b / gcd(a, b);}
static const double pi = 3.141592653589793;
lint power(lint N, lint P, lint M){if(P==0) return 1;if(P%2==0){lint t = power(N, P/2, M);return t*t % M;}return N * power(N, P-1, M);}
lint MOD=pow(10,9)+7;
//lint MOD=998244353;
lint inf=pow(2,50);
int intinf=pow(2,30);
/**int dirx[]={1,0};int diry[]={0,1};//*///右、下
/**/int dirx[]={0,1,0,-1};int diry[]={-1,0,1,0};//*///四方位
/**int dirx[]={-1,0,1,1,1,0,-1,-1};int diry[]={-1,-1,-1,0,1,1,1,0};//*///八方位

class unionfind{
public:
	vector<int> table;
	vector<int> wod;
	void init(int size){
		table.resize(size);
		wod.resize(size);
		rep(i,size)table[i]=i,wod[i]=i;
	};
	int root(int index){
		if(table[index]==index)return index;
		else{
			int hoge=root(table[index]);
			table[index]=hoge;
			return hoge;
		}
	};
	bool same(int x,int y){
		return(root(x)==root(y));
	};
	int marge(int x,int y){
		int yroot=root(y);
		int xroot=root(x);
		if(xroot==yroot)return 0;
		table[yroot]=xroot;
		return 0;
	}
};

int main(){
	cin.tie(0);ios::sync_with_stdio(false);cout<<std::fixed<<std::setprecision(12);
	vint a(3);
	in(a);
	sort(a);
	out(a[0],a[1],a[2]);
	return 0;
}



Measured memory_bytes: 3172
def factorial_mod(n,mod):
    ret = 1
    for i in range(1,n+1):
        ret *= i
        ret %= mod
    return ret
def comb_mod(n,r,mod):
    if r > n or r < 0:
        ret = 0
    else:
        fact_n  = factorial_mod(n, mod)
        fact_r  = factorial_mod(r, mod)
        fact_nr = factorial_mod(n-r, mod)
        ret = fact_n * pow(fact_r, mod-2, mod) * pow(fact_nr, mod-2, mod) % mod
    return ret

n,k = map(int,input().split())
m = 10**9+7
for i in range(1,k+1):
    print(comb_mod(n-k+1, i, m)*comb_mod(k-1, i-1, m)%m)

Measured memory_bytes: 9216
#include<stdio.h>

int main(){
	int in[5],k;


	for(int i=0;i<5;i++){
		scanf("%d",&(in[i]));
	}

	int val;
	int min_val=10;
	int best_i=0;
	for(int i=0;i<5;i++){
		val=in[i]%10;
		if(val!=0 && val<min_val){
			best_i=i;
			min_val=val;
		}
	}

	int time=0;
	for(int i=0;i<5;i++){

		if(i==best_i || in[i]%10==0){
			time+=in[i];
		}else{
			val=in[i]/10;
			val++;
			val*=10;
			time+=val;
		}
	}
	printf("%d\n",time);
	return 0;
}



Measured memory_bytes: 128
//#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

using namespace std;
using ll=long long;

void solve(){
  int h,w;
  cin >> h >> w;
  vector<string> gred(h);
  for(int i=0;i<h;i++)
    cin >> gred[i];
  vector<int> hind;
  std::vector<int> wind;
  for(int i=0;i<h;i++){int ct=0;
    for(int j=0;j<w;j++)
      if(gred[i][j]!='.')ct++;
    if(ct==0)hind.push_back(i);
  }
  for(int j=0;j<w;j++){int ct=0;
    for(int i=0;i<h;i++)
      if(gred[i][j]!='.')ct++;
    if(ct==0)wind.push_back(j);
  }
  for(int i=0;i<h;i++){
    string str="";bool a=true;
    for(int j=0;j<hind.size();j++)
      if(i==hind[j])a=false;
    if(!a)continue;
    for(int j=0;j<w;j++){
      bool b=true;
      for(int k=0;k<wind.size();k++)
        if(j==wind[k])b=false;
      if(b)str+=gred[i][j];
    }
    cout << str << endl;
  }
}

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


Measured memory_bytes: 256
_, S = input(), [*map(int, input().split())]
_, T = input(), [*map(int, input().split())]

def binary_search(S, t):
  left, right = 0, len(S)
  while left < right:
    mid = (left + right) // 2
    if S[mid] == t:
      return True
    if S[mid] > t:
      right = mid
    else:
      left = mid + 1
  return False

print(sum(binary_search(S, t) for t in T))


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

int main() {
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
  int N,K;
  cin>>N>>K;
  int a=0;
  int64_t answer=0;
  priority_queue<int> H;
  if(N<=K)
    cout<<0;
  
  else{
    rep(i,N){
      cin>>a;
      H.push(a);
    }
    rep(i,K)
      H.pop();
    while(!H.empty()){
      answer+=H.top();
      H.pop();
    }
    cout<<answer;
  }
      
}

Measured memory_bytes: 1400
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
  int n, k;
  cin >> n >> k;
  int h[n], dmin=1000000000;
  for(int i=0; i<n; i++){
    cin >> h[i];
  }

  sort(h, h+n);
  int d;

  for(int j=0; j<n-k+1; j++){
    d = h[j+k-1]-h[j];
    dmin = min(dmin, d);
  }

  cout << dmin << endl;
 
  return 0;
}
    

Measured memory_bytes: 640
import math

n = int(input())
#a, b, c = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for j in range(n)]
#table = [list(input()) for n in range(h)]
#list = [int(i) for i in input().split()]
#num = [int(i) for i in range(n)]
#s = [input() for i in range(n)]
#s = input()
#list = list(s)
#temp = [[0 for _ in range(13)] for _ in range(13)]

if (n // 10 == 0) :
    print(n)
elif (n // 100 == 0) :
    print(9)
elif (n // 1000 == 0) :
    print(n - 90)
elif (n // 10000 == 0) :
    print(909)
elif (n // 100000 == 0):
    print(n - 9090)
else :
    print(90909)

Measured memory_bytes: 3060
// need
#include <iostream>
#include <algorithm>
// data structure
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
//#include <deque>
#include <valarray>
#include <unordered_map>
#include <array>
// stream
//#include <istream>
#include <sstream>
//#include <ostream>
#include <fstream>
// etc
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
//#include <chrono>
using namespace std;

int main()
{
  string S;
  cin >> S;
  string d = "2019/04/30";
  if(S.compare(d) <= 0){
    cout << "Heisei" << endl;
  }
  else
    cout << "TBD" << endl;
  return 0;
}


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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h) {
        cin >> s[i];
    }

    vector<vector<int>> cnt(h, vector<int>(w));

    rep(i, h) {
        vector<int> done(w);
        rep(j, w) {

            if(s[i][j] == '#') {
                continue;
            }
            if(done[j]) {
                continue;
            }

            int l = 0;
            while(j+l < w) {
                if(s[i][j+l] == '#') {
                    break;
                }
                l++;
            }

            rep(k, l) {
                cnt[i][j+k] += l;
                done[j+k] = 1;
            }
        }
    }

    rep(j, w) {
        vector<int> done(h);
        rep(i, h) {
            
            if(s[i][j] == '#') {
                continue;
            }
            if(done[i]) {
                continue;
            }

            int l = 0;
            while(i+l < h) {
                if(s[i+l][j] == '#') {
                    break;
                }
                l++;
            }

            rep(k, l) {
                cnt[i+k][j] += l;
                done[i+k] = 1;
            }
        }
    }

    int ans = 0;
    rep(i, h) {
        rep(j,w) {
            ans = max(ans, cnt[i][j]-1);
        }
    }

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

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

#define MAX 100000
#define MAX_NAME 10

typedef struct {
  char name[MAX_NAME];
  int time;
  
}Process;

int head;
int tail;
Process Q[MAX];


void initialize()
{
  head = tail = 0;
}

int isEmpty()
{
  return head == tail;
}

int isFull()
{
  return head == (tail + 1) % MAX;
}

void enqueue(char *name, int time)
{
  if (isFull())
    exit(1);

  strcpy(Q[tail].name, name);
  Q[tail].time = time;

  tail = (tail + 1) % MAX;
    
}

Process dequeue()
{
  Process x;
  if (isEmpty())
    exit(1);

  x = Q[head];
  head = (head + 1) % MAX;
  
  return x;
}

int main(void)
{
  int n, q;
  char name[MAX_NAME];
  int time;
  Process p;
  
  scanf("%d %d", &n, &q);
  while (scanf("%s %d", name, &time) != EOF) {
    enqueue(name, time);
  }

  int sim_time = 0;
  while (!isEmpty()) {
    sim_time += q;
    p = dequeue();

    p.time -= q;
    if (p.time <= 0) {
      sim_time += p.time;
      printf("%s %d\n", p.name, sim_time);
    }
    else
      enqueue(p.name, p.time);
  }
  return 0;
}



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

using namespace std;

const double pi=acos(-1.0);
const double eps=1e-11;

#define size(A) ((int)A.size())
#define length(A) ((int)A.length())
#define mp(A,B) make_pair(A,B)
#define pb(x) push_back(X);

using int64=long long int;
using ipair=pair<int,int>;
using vi=vector<int>;
using vd=vector<double>;

int n,k,d;
set<int> s;

int f(int num){
	while(num){
		d=num%10;
		num/=10;
		if(s.count(d)==1){
			return 0;
		}
	}
	return 1;
}

int main(){
	cin>>n>>k;
	for(int i=0;i<k;i++){
		cin>>d;
		s.insert(d);
	}
	while(true){
		if(f(n)){
			cout<<n<<endl;
			break;
		}
		++n;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>

using namespace std;

typedef int itn;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef map<int, int> M;
typedef pair<int, int> P;
typedef stack<int> S;
typedef queue<int> Q;

const LL MOD = 1000000007;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    M mo, me;
    for (int i = 0; i < n; ++i)
    {
        int v;
        cin >> v;
        if (i & 1) ++mo[v];
        else ++me[v];
    }
    VI mok = VI(2, 0);
    VI mov = VI(2, 0);
    VI mek = VI(2, 0);
    VI mev = VI(2, 0);
    for (auto x : mo)
    {
        if (mov[0] < x.second)
        {
            mov[1] = mov[0];
            mok[1] = mok[0];
            mov[0] = x.second;
            mok[0] = x.first;
        }
        else if (mov[1] < x.second)
        {
            mov[1] = x.second;
            mok[1] = x.first;
        }
    }
    for (auto x : me)
    {
        if (mev[0] < x.second)
        {
            mev[1] = mev[0];
            mek[1] = mek[0];
            mev[0] = x.second;
            mek[0] = x.first;
        }
        else if (mev[1] < x.second)
        {
            mev[1] = x.second;
            mek[1] = x.first;
        }
    }
    
    int ans = 0;
    for (int i = 0; i < 2; ++i)
    {
        for (int j = 0; j < 2; ++j)
        {
            if (mok[i] == mek[j]) continue;
            ans = max(ans, mov[i]+mev[j]);
        }
    }
    cout << n-ans << endl;
    
    return 0;
}


Measured memory_bytes: 4992
N, M = gets.chop.split.map(&:to_i)

array = Array.new(N)

M.times {
  s, c = gets.chop.split.map(&:to_i)
  if array[s - 1] && array[s - 1] != c
    puts '-1'
    exit
  end

  array[s - 1] = c
}

if array.count > 1 && array[0] == 0
  puts '-1'
  exit
end

if array.count > 1 && array[0].nil?
  array[0] = 1
end

ans = array.reduce('') { |acc, i|
  if i
    acc = acc << i.to_s
  else
    acc = acc << '0'
  end
}

puts ans


Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long 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 INF = 1LL << 60;
const int INF = 1001001001;



int main(void){
    int n,m,x;
    cin >> n >> m >> x;
    int c[n],a[n][m];
    REP(i,n){
        REP(j,m+1){
            if(j==0) cin >> c[i];
            else cin >> a[i][j-1];
        }
    }

    int ans=INF;

    for (int bit = 0; bit < (1<<n); ++bit) {
        int csum=0,asum[m]={0};
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) {
                csum+=c[i];
                REP(j,m) asum[j]+=a[i][j];
            }
        }
        bool flag=true;
        REP(j,m){
            if(asum[j]<x){
                flag=false;
                break;
            }
        }
        if(flag) chmin(ans,csum);
    }
    if(ans==INF) cout << -1;
    else cout << ans;
    return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>

int a[1000000];

int main(void)
{
	int n;
	int i;
	long min;
	long max;
	long sum;
	
	scanf("%d", &n);
	for(i = 0;i < n;i++){
		scanf("%d", &a[i]);
	}
	sum = a[0];
	min = a[0];
	max = a[0];
	
	for(i = 1;i < n;i++){
		if(a[i] > max){
			max = a[i];
		}
		if(a[i] < min){
			min = a[i];
		}
		sum += a[i];
	}
	printf("%ld %ld %ld\n", min, max, sum);
	
	return (0);
}

Measured memory_bytes: 636
using System;

namespace exawizards2019B
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int input= Int32.Parse(Console.ReadLine());
            int N = input;
            string A = Console.ReadLine();
            string temp = "";
            string hoge = A;
            int a = hoge.Length;
            int Z = 0;
            for (int x = 0; x <= a - 1; x++)
            {
                temp = hoge.Substring(x, 1);
                if (temp == "R")
                    Z = Z + 1;
            }
            int L = N - Z;
            if (Z > L)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 11092
const Main = input => {
  input = input.split('\n')[0].split(' ').map(v => parseInt(v, 10))
  const n = input[2] - (input[0] - input[1])
  console.log(n < 0 ? 0 : n)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"))

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  for (int i=0; i<K; i++) {
    if (i%2==0) {
      if (A%2!=0) A--;
      B += A/2;
      A /= 2;
    }
    else {
      if (B%2!=0) B--;
      A += B/2;
      B /= 2;
    }
  }
  cout << A << " " << B << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;
#define ll long long
int main(){
    int ans=0;
    int a,b,c;
    cin >>a>>b>>c;
    if (a==b)cout <<c<<endl;
    if (b==c)cout <<a<<endl;
    if (c==a)cout <<b<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<vector>
using namespace std;
using ll = long long;


int main() {
	int n; cin >> n;
	vector<ll>a;
	set<ll>b;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		a.push_back(t);
		b.insert(t);
	}
	if (a.size() == b.size()) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 11120
A, B, K = map(int, input().split())

s = set()

for i in range(A, min(A + K, B + 1)):
    s.add(i)

for i in range(B, max(A - 1, B - K), -1):
    s.add(i)

s = sorted(s)

for i in s:
    print(i)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
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;}
constexpr long INF = 1LL << 62;
constexpr int MOD = 1e9 + 7;

long gcd(long a,long b) {return b==0 ? a : gcd(b, a%b);}
long lcm(long a,long b) {return min(2e18l + 100, a / gcd(a,b) * 1.0l * b);}

long n, m, a[20], table[1<<20];
double p[20];

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false); 
    cin >> n >> m;
    for(int i=0; i < n; ++i) cin >> a[i];
    for(int i=0; i < n; ++i) cin >> p[i], p[i] /= 100.0;

    for(int bit = 1; bit < (1<<n); ++bit) {
        long tmp = 1;
        for(int i = 0; i < n; ++i) 
            if(bit & (1<<i)) tmp = lcm(tmp, a[i]);
        table[bit] = m / tmp;
    }

    for(int i = 0; i < n; ++i) 
        for(int bit = 0; bit < (1<<n); ++bit)
            if(bit & (1<<i)) table[bit] -= table[bit ^ (1<<i)];

    double ans = 0.0;
    for(int bit=0; bit < (1<<n); ++bit) {
        double prob = 1.0;
        for(int i = 0; i < n; ++i) {
            if(bit & (1<<i)) prob *= p[i];
            else prob *= 1-p[i];
        }
        ans += abs(table[bit]) * prob;
    }

    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}


Measured memory_bytes: 11488
#include <cstdio>
using namespace std;
int zmap[10][10];




int main() {

    int n, r, c, idx, cn = 1;
    for (; ;) {
        scanf("%d", &n);
        if (n == 0) break;
        r = c = 0;
        zmap[0][0] = 1;
        idx=1;
        for (; ;) {
            zmap[c][++r] = ++idx;
            while(r > 0) {
                zmap[++c][--r] = ++idx;
            }
            if (idx >= n*n/2) break;
            zmap[++c][r] = ++idx;
            while(c > 0) {
                zmap[--c][++r] = ++idx;
            }
            if (idx >= n*n/2) break;
        }

        if (n % 2 == 0) {
            for (; ;) {
                zmap[c][++r] = ++idx;
                if (idx>= n*n) break;
                while(r < n - 1) {
                    zmap[--c][++r] = ++idx;
                }
                zmap[++c][r] = ++idx;
                if (idx >= n*n) break;
                while(c < n -1) {
                    zmap[++c][--r] = ++idx;
                }
            }
        }
        else {
            for (; ;) {
                zmap[++c][r] = ++idx;
                if (idx >= n*n) break;
                while(c < n -1) {
                    zmap[++c][--r] = ++idx;
                }
                zmap[c][++r] = ++idx;
                if (idx>= n*n) break;
                while(r < n - 1) {
                    zmap[--c][++r] = ++idx;
                }
            }
        }

        printf("Case %d:\n", cn++);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) printf("%3d", zmap[i][j]);
            printf("\n");
        }
    }
    return 0;

}



Measured memory_bytes: 2760
def solve(n, k):
    cnt = 0
    if k == 0:
        return n * n
    for b in range(k + 1, n + 1):
        p = n // b
        r = n % b
        cnt += p * (b - k)
        if r >= k:
            cnt += r - k + 1
    return cnt

n, k = map(int, input().split())
print(solve(int(n), int(k)))


Measured memory_bytes: 2940
N = int(input())
grid_a, grid_b = (list(map(int, input().split())) for _ in range(2))
table_a = []
tmp = 0
for i in grid_a:
    tmp += i
    table_a.append(tmp)
table_b = []
tmp = sum(grid_b)
for i in grid_b:
    table_b.append(tmp)
    tmp -= i
ans = 0
for i in range(N):
    ans = max(ans, table_a[i] + table_b[i])
print(ans)


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



int main(){
  int N;
  cin>>N;
  
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    vec.at(i)=i+1;
  }
  vector<int> P(N);
  for(int i=0;i<N;i++){
    cin>>P.at(i);
  }
  vector<int> Q(N);
  for(int i=0;i<N;i++){
    cin>>Q.at(i);
  }
  int i=0;
  int p,q;
  do{
    i++;
    if(vec==P) p=i;
    if(vec==Q) q=i;
  }while(next_permutation(vec.begin(),vec.end()));
  cout<<abs(p-q)<<endl;
}

Measured memory_bytes: 3576
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, Q = MAP()
S = input()
L = [LIST() for _ in range(Q)]

a = [0]*len(S)
for i in range(1, len(S)):
	if (S[i-1]=="A") and (S[i]=="C"):
		a[i] = a[i-1] + 1
	else:
		a[i] = a[i-1]

for i in range(Q):
	print(a[L[i][1] - 1] - a[L[i][0] - 1])

Measured memory_bytes: 85592
A,B,C,X,Y = map(int,input().split())

if A+B<=2*C:
  print(A*X+B*Y)
else:
  if X<=Y:
    print(min(2*C*X+B*(Y-X),2*C*Y))
  else:
    print(min(2*C*Y+A*(X-Y),2*C*X))

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

int main() {
  int N;
  cin >> N;
  vector<int> s(N);
  for (int i=0; i<N; i++) 
    cin >> s.at(i);
  
  sort(s.begin(), s.end());
  reverse(s.begin(), s.end());
  int x=0;
  int f=0;
  for (int i=0; i<N; i++) {
    if (f==0) {
      x += s.at(i);
      f = 1;
    }
    else {
      x -= s.at(i);
      f = 0;
    }
  }
  cout << x << endl;
}


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

using namespace std;

set <string> st;

int main() {
	int n;
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		st.insert(s);
	}
	
	printf("%d\n", (int)st.size());
}


Measured memory_bytes: 19392
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
const int LIMIT = 1e9 + 7;
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define all(v) (v).begin(), (v).end()

namespace /* debug */{
  #define DEBUG(...) do{cout<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数
  #define ldebug(...) do{cout<<"["<<setw(3)<<__LINE__<<"] ";debug(__VA_ARGS__);}while(0) //行数
  #define lDEBUG(...) do{cout<<"["<<setw(3)<<__LINE__<<"] "<<#__VA_ARGS__<<" = ";debug(__VA_ARGS__);}while(0) //変数, 行数
  template<class T>void show(T&x){cout<<x<<" ";} //出力
  template<class T>void showendl(T&x){cout<<x<<endl;} //出力改行
  template<class P,class Q>void show(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<") ";} //pair出力
  template<class P,class Q>void showendl(pair<P,Q>&x){cout<<"("<<x.first<<", "<<x.second<<")"<<endl;} //pair出力改行
  template<class H>void debug(H&&h){showendl(h);} //引数1つ
  template<class H,class...Ts>void debug(H&&h,Ts&&...ts){show(h);debug(forward<Ts>(ts)...);} //可変引数
  template<class T>void debug(vector<T>&vt){int i=0;for(auto x:vt)++i!=vt.size()?show(x):showendl(x);} //vector出力
  template<class T>void debug(initializer_list<T>init){int i=0;for(auto x:init)++i!=init.size()?show(x):showendl(x);} //初期化子リスト出力
}

int main(){
	string S;cin>>S;
  if(S=="SSS")cout<<0<<endl;
  else if(S=="SRR" || S=="RRS")cout<<2<<endl;
  else if(S=="RRR")cout<<3<<endl;
  else cout<<1<<endl;
}

Measured memory_bytes: 3620
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static double[] x, y, z;

	public static void main(String[] args) {
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			int M = sc.nextInt();
			HashMap<String, Node> map = new HashMap<String, Node>();
			Node cur = new Node(null);
			map.put(sc.next(), cur);
			int depth = 0;
			sc.nextLine();
			for (int i = 1; i < N; ++i) {
				String line = sc.nextLine();
				int d = 0;
				while (line.charAt(d) == ' ') {
					++d;
				}
				String name = line.substring(d);
				for (int j = 0; j <= depth - d; ++j) {
					cur = cur.parent;
				}
				Node node = new Node(cur);
				map.put(name, node);
				cur = node;
				depth = d;
			}
			for (int i = 0; i < M; ++i) {
				String X = sc.next();
				sc.next();
				sc.next();
				char query = sc.next().charAt(0);
				sc.next();
				String Y = sc.next();
				Y = Y.substring(0, Y.length() - 1);
				Node xn = map.get(X);
				Node yn = map.get(Y);
				boolean yes = false;
				if (query == 'c') {
					yes = xn.parent == yn;
				} else if (query == 'p') {
					yes = yn.parent == xn;
				} else if (query == 's') {
					yes = xn.parent == yn.parent;
				} else if (query == 'd') {
					Node node = xn;
					while (node != null) {
						if (node == yn) {
							yes = true;
							break;
						}
						node = node.parent;
					}
				} else if (query == 'a') {
					Node node = yn;
					while (node != null) {
						if (node == xn) {
							yes = true;
							break;
						}
						node = node.parent;
					}
				}
				System.out.println(yes ? "True" : "False");
			}
			System.out.println();
		}
	}

	static class Node {
		Node parent;

		Node(Node parent) {
			this.parent = parent;
		}
	}

}

Measured memory_bytes: 13000
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int getmin(int a,int b);

int main(){
    int n,k,r1,r2;
    scanf("%d %d",&n,&k);
    int x[n];
    int R[n];
    for(int i=0;i<n;i++){
        scanf("%d",&x[i]);
    }
    for(int j=0;j<n-k+1;j++){
        r1=abs(x[j])+abs(x[j]-x[k+j-1]);
        r2=abs(x[k+j-1])+abs(x[k+j-1]-x[j]);
        R[j]=getmin(r1,r2);
    }
    /*for(int i=0;i<n-k+1;i++){
        printf("R[%d]=%d ",i,R[i]);
    }
    printf("\n");*/
    for(int i=0;i<n-k+1;i++){
        for(int j=i+1;j<n-k+1;j++){
            if(R[i]>R[j]){
                int tmp=R[i];
                R[i]=R[j];
                R[j]=tmp;
            }
        }
    }
    /*for(int i=0;i<n-k+1;i++){
        printf("R[%d]=%d ",i,R[i]);
    }*/
    printf("%d",R[0]);
    return 0;
}

int getmin(int a,int b){
    int c;
    if(a>=b){
        c=b;
    }else{
        c=a;
    }
    return c;
}

Measured memory_bytes: 768
#include<stdio.h>
int main(){

  int x[10000],n,i,j,count=0;

  scanf("%d",&n);
  
  for(i=0 ; i < n ; i++){
  
    scanf("%d",&x[i]);
  
  }

  for(j = 0 ; j < n ; j++){

    if(isprime(x[j])== 1)count++;
    
  }
 
  printf("%d\n",count);

  return 0;
}


isprime(int x){ 

  int i = 3;
  
  if(x == 2)return 1;

  if(x < 2 || x%2 == 0)return 2;

  while(i <= sqrt(x)){
    if(x%i == 0)return 2;
    i = i+2;

  }

  return 1;

  
}

Measured memory_bytes: 628
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
using namespace std;

int dp[301][18];

int main(){
	int n;
	while(cin >> n, n){
		for(int i = 0; i <= n; i++) dp[i][1] = dp[i][0] = 1;
		for(int i = 0; i <= n; i++){
			for(int j = 2; j <= 18; j++){
				dp[i][j] = 0;
				int k;
				for(k = 0; i - k * j * j >= 0; k++){
					dp[i][j] += dp[i - k * j * j][j - 1];
				}
			}
		}
		cout << dp[n][18] << endl;
	}
}

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

struct P {
	int i, u, a, p;
	P(int i = 0, int u = 0, int a = 0, int p = 0): i(i), u(u), a(a), p(p){}
	bool operator < (const P &t) const {
		if (a != t.a) return a > t.a;
		if (p != t.p) return p < t.p;
		return i < t.i;
	}
};

vector<int> res;
int cnt[1001];

int main()
{
	int n;
	while (scanf("%d", &n), n){
		res.clear();
		memset(cnt, 0, sizeof(cnt));
		vector<P> ps;
		for (int i = 0; i < n; i++){
			int _i, u, a, p;
			scanf("%d %d %d %d", &_i, &u, &a, &p);
			ps.push_back(P(_i, u, a, p));
		}
		sort(ps.begin(), ps.end());
		for (int i = 0; i < ps.size(); i++){
			P &p = ps[i];
			if (res.size() < 10){
				if (cnt[p.u] < 3){
					res.push_back(p.i);
					cnt[p.u]++;
				}
			}
			else if (res.size() < 20){
				if (cnt[p.u] < 2){
					res.push_back(p.i);
					cnt[p.u]++;
				}
			}
			else if (res.size() < 26){
				if (cnt[p.u] < 1){
					res.push_back(p.i);
					cnt[p.u]++;
				}
			}
		}
		//sort(res.begin(), res.end());
		for (int i = 0; i < res.size(); i++){
			printf("%d\n", res[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 1224
n = int(input())
g = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    g[a].append(b)
    g[b].append(a)
#print(g)

from collections import deque
q = deque()
visit = [-1]*n
q.append(0)
visit[0] = 0
while q:
    x = q.popleft()
    for new_x in g[x]:
        if visit[new_x] != -1:
            continue
        visit[new_x] = visit[x]+1
        q.append(new_x)
        #if new_x == n-1:
            #break
#print(visit)

q = deque()
visit2 = [-1]*n
q.append(n-1)
visit2[n-1] = 0
while q:
    x = q.popleft()
    for new_x in g[x]:
        if visit2[new_x] != -1:
            continue
        visit2[new_x] = visit2[x]+1
        q.append(new_x)
#print(visit2)

fe = 0
sn = 0
for i in range(n):
    if visit[i] <= visit2[i]:
        fe += 1
    else:
        sn += 1
if fe > sn:
    print('Fennec')
else:
    print('Snuke')


Measured memory_bytes: 63648