akhauriyash/Code-Regression huggingface dataset:
void main()
{
    long[] tmp = readln.split.to!(long[]);
    long n = tmp[0], m = tmp[1];

    long mod = 10 ^^ 9 + 7;

    long factorial(long x)
    {
        long result = 1;

        foreach (i; 2 .. x+1)
        {
            result = result * i % mod;
        }

        return result;
    }

    long cnt;
    if (n == m)
    {
        cnt = factorial(n) * factorial(m) % mod;
        cnt = cnt * 2 % mod;
    }
    else if (abs(n - m) == 1)
    {
        cnt = factorial(n) * factorial(m) % mod;
    }

    cnt.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringJoiner;
import java.util.StringTokenizer;
import java.util.function.IntUnaryOperator;
import java.util.function.LongUnaryOperator;

class Main {
    static In in = new In();
    static Out out = new Out();
    static long mod = 1000000007;
    static long inf = 0xfffffffffffffffL;

    void solve() {
        int n = in.nextInt();
        int k = in.nextInt();
        double[] p = new double[n];
        for (int i = 0; i < n; i++) {
            p[i] = (in.nextInt() + 1) / 2.0;
        }
        double ans = 0;
        double sum = 0;
        for (int i = 0; i <= n; i++) {
            if (i >= k) {
                ans = Math.max(ans, sum);
                sum -= p[i - k];
            }
            if (i == n) {
                break;
            }
            sum += p[i];
        }
        out.println(ans);
    }

    public static void main(String[]$) {
        new Main().solve();
        out.flush();
    }
}

class In {
    private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 0x10000);
    private StringTokenizer tokenizer;

    String next() {
        try {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                tokenizer = new StringTokenizer(reader.readLine());
            }
        } catch (IOException ignored) {
        }
        return tokenizer.nextToken();
    }

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

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

    char[][] nextCharArray(int n, int m) {
        char[][] a = new char[n][m];
        for (int i = 0; i < n; i++) {
            a[i] = next().toCharArray();
        }
        return a;
    }

    int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    int[] nextIntArray(int n, IntUnaryOperator op) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsInt(nextInt());
        }
        return a;
    }

    long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextLong();
        }
        return a;
    }

    long[] nextLongArray(int n, LongUnaryOperator op) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = op.applyAsLong(nextLong());
        }
        return a;
    }
}

class Out {
    private static PrintWriter out = new PrintWriter(System.out);

    void println(Object... a) {
        StringJoiner joiner = new StringJoiner(" ");
        for (Object obj : a) {
            joiner.add(String.valueOf(obj));
        }
        out.println(joiner);
    }

    void flush() {
        out.flush();
    }
}


Measured memory_bytes: 41784
o[256],z[257];main(N,S,A,C,s,a,c,r,i){for(;scanf("%d",&N),N;printf("%d %d %d\n",S,A,C)){
	double H=9,h,n=N;
	for(i=1;i<=N;i++)scanf("%d",z+i);
	for(s=0;s<16;s++)for(a=0;a<16;a++)for(c=0;c<16;c++){
		for(r=s,h=0,i=1;i<=N;i++)o[(z[i]+(r=(a*r+c)%256))%256]++;
		for(i=0;i<256;i++)if(o[i])h-=o[i]/n*log(o[i]/n),o[i]=0;
		if(h+1e-9<H)H=h,S=s,A=a,C=c;
	}
}exit(0);}

Measured memory_bytes: 640
N = list(input())
if len(N) == 1:
    n = int(N[0])
else:
    n = int(N[-1])

if n == 2 or n == 4 or n == 5 or n == 7 or n == 9:
    print("hon")
elif n == 0 or n == 1 or n == 6 or n == 8:
    print("pon")
elif n == 3:
    print("bon")


Measured memory_bytes: 9184
def gcd2(x, y):
    if y == 0:
        return x
    else:
        return gcd2(y, x % y)
def gcd3(x,y,z):
    return gcd2(gcd2(x, y), z)

ans = 0
K = int(input())
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            ans += gcd3(i, j, k)

print(ans)

Measured memory_bytes: 77164
def encode(x):
    return chr(x + 97)


def solve(N):
    N -= 1
    ans = []
    while True:
        q, r = divmod(N, 26)
        ans.append(r)
        if q == 0:
            break
        N //= 26
        N -= 1
    return "".join(map(encode, ans[::-1]))


print(solve(int(input())))


Measured memory_bytes: 9184
n = int(input())
a, b = list(map(int, input().split()))
p = list(map(int, input().split()))

c1 = 0
c2 = 0
c3 = 0

for num in p:
    if num <= a:
        c1 += 1
    elif num <= b:
        c2 += 1
    else:
        c3 += 1

print(min(c1, c2, c3))


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());

        int remain = a - b;
        int ans = c - remain > 0 ? c - remain : 0;
        System.out.println(ans);
    }

}


Measured memory_bytes: 23508
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll n,a,b;

int main(){
	scanf("%lld%lld%lld",&n,&a,&b);
	
    printf("%lld %lld",min(a,b),max(0,a+b-n));
}

Measured memory_bytes: 128
#include <cstdio>
using namespace std;
const int L = 1000000007;
int N, M, t, a[100001], dp[100001];
int main() {
  scanf("%d %d", &N, &M);
  for(int i = 0; i < M; i++) {scanf("%d", &t); a[t] = 1;};
  dp[0] = 1, dp[1] = !a[1];
  for(int i = 2; i <= N; i++) {
    if(a[i]) {dp[i] = 0; continue;}
    dp[i] = (dp[i-1]+dp[i-2])%L;
  }
  printf("%d", dp[N]);
}

Measured memory_bytes: 896
N,K = map(int, input().split())
ab_list = []
for i in range(N):
    a = list(map(int, input().split()))
    ab_list.append(a)
    
ab_list.sort()
    
count =0
for i in ab_list:
    count+=i[1]
    if (count >= K):
        print(i[0])
        break

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

int main() {
  int A,B;
  cin >> A >> B;
  if(A >= 13){
    cout << B << endl;
  } else if(A <= 5){ 
    cout << 0 << endl;
  } else {
    cout << B/2 << endl;
  }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 100

int main(){
  int A[N],a,i,j,v,k;

  scanf("%d",&a);

  for(i=0;i<a-1;i++){
    scanf("%d",&A[i]);
    printf("%d ",A[i]);
   
  }
  
  scanf("%d",&A[a-1]);
  printf("%d",A[a-1]);
  printf("\n");
  
  for (i=1;i<=a-1;i++){
    v = A[i];
    j = i - 1;
      
    while(j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    for(k=0;k<a-1;k++){
     
      printf("%d ",A[k]);
    }
    printf("%d",A[a-1]);
    printf("\n");
  }   
   
  return 0;
  

}



Measured memory_bytes: 2056
a,b,c,d=(int(x) for x in input().split())
win = 0
while(True):
    c=c-b
    if c <= 0:
        win = 1
        break
    a=a-d
    if a <= 0:
        win = 2
        break
if win == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9120
x, n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
    print(x)
else:
    a = x
    b = x
    while a in p:
        a -= 1
    while b in p:
        b += 1
    if abs(a -x) > abs(b - x):
        print(b)
    else:
        print(a)

Measured memory_bytes: 9140
import java.util.Scanner;
import java.lang.Math;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        while(true){
            String s = sc.next();
            if(s.equals("-")) break;
            int n = sc.nextInt();
            int cnt = 0,h,l=s.length();
            for(int i=0;i<n;i++){
                h = sc.nextInt();
                cnt += h;
            }
            char[] s_ch = new char[s.length()];
            for(int i=0;i<l;i++){
                s_ch[i] = s.charAt((cnt+i)%l);
                System.out.print(s_ch[i]);
            }
            System.out.println();
        }
        sc.close();
    }
}


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

int main() {
  int A, B;
  cin >> A >> B;
  
  int ans = B - A + 1;
  for (int i = A; i <= B; i++) {
    string s = to_string(i);
    int j = 0, k = s.size() - 1;
    while (j <= k) {
      if (s.at(j) == s.at(k)) {
        j++;
        k--;
      } else {
        ans--;
        break;
      }
    }
  }
  cout << ans;
}


Measured memory_bytes: 3660
l={}
for i in [1]*input():
	a,n=map(str,raw_input().split())
	try:l[a]+=int(n)
	except:l[a]=int(n)
for k,v in sorted(sorted(l.items(),key=lambda x:x[0]),key=lambda x:len(x[0])):print k,v

Measured memory_bytes: 4284
import string
s = input()
ans = 101
for last in string.ascii_lowercase:
    t = list(s)
    while len(set(t)) != 1:
        for i in range(len(t)):
            if last in t[i:i+2]:
                t[i] = last
        t.pop()
    ans = min(ans, len(s)-len(t))
print(ans)

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

int main(){
  int N,num,i = 1,j;
  cin >> N;
  vector<int> b(N);
  for(j = 0;j < N;j++){
    cin >> b.at(j);
  }
  for(j = 0;j < N;j++){
    num += 1;
    i = b.at(i-1);
    if(i == 2)break;
  }
  if(j == N){
    cout << -1 << endl;
  }else{
    cout << num << endl;
  }
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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


int main(void){

	string s, t; cin >> s >> t;
	cout << t << s << endl;


	return 0;

}


Measured memory_bytes: 256
N = int(input())
list2 = []

list1 =[int(i) for i in range(1,N+1)]
for i in range(N):
  list2.append([i, list1[i]])

for i in range(N):
  if len(list2) == 1:
    ans = list2[0][0]
    print(ans+1)  
    break
  
    
  for a in list2:
    
    if a[1] % 2 != 0:
      list2.remove(a)

  for j in range(len(list2)):
    list2[j][1] = list2[j][1]/2

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

int main() {
  int N , A , B ;
  cin >> N >> A >> B ;
  
  //
  
  if ( N * A < B ) {
    cout << N * A << endl;
  }
  else if ( N * A > B ) {
    cout << B << endl;
  }
  else if ( N * A == B ){
    cout << B << endl;
  }
}


Measured memory_bytes: 3552
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  long y;
  cin >> n >> y;
  int yuki = -1;
  int higu = -1;
  int nogu = -1;
  int i,j;
  int chk = 0;
  for(i=0;i<=n;i++){
    for(j=0;j<=n-i;j++){
      if(i + 5*j + 10*(n-i-j) == y/1000){
        nogu = i;
        higu = j;
        yuki = n-i-j;
      } 
    }
  }

  cout << yuki <<" "<< higu <<" "<< nogu;
}

Measured memory_bytes: 256
//最古の遺跡

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<utility>
#include<map>
using namespace std;
int n, ans = 0;
string a, b, c;
int main() {
	cin >> n >> a >> b >> c;
	for (int i = 0; i < n; i++) {
		if (a[i] == b[i] && a[i] != c[i]) {
			ans++;
		}
		else if (a[i] != b[i] && a[i] == c[i]) {
			ans++;
		} 
		else if (c[i] == b[i] && a[i] != c[i]) {
			ans++;
		}
		else if (a[i] == b[i] && b[i] == c[i]) {
		}
		else ans += 2;
	}
	cout << ans << endl;

	return 0;
}

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

int main()
{
	int x;
	cin >> x;
	int xmod = x % 100;
	int inum = (x - xmod) / 100;
	int isum = 0;
	
	int xpd5 = xmod - xmod % 5;
	isum += xpd5 / 5;
	xmod -= xpd5;


	int xpd4 = xmod - xmod % 4;
	isum += xpd4 / 4;
	xmod -= xpd4;

	int xpd3 = xmod - xmod % 3;
	isum += xpd3 / 3;
	xmod -= xpd3;

	int xpd2 = xmod - xmod % 2;
	isum += xpd2 / 2;
	xmod -= xpd2;

	isum += xmod;

	if (isum > inum) {
		cout << "0";
	}
	else {
		cout << "1";
	}
}

Measured memory_bytes: 256
import itertools

a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]

a = list(itertools.chain.from_iterable(a))

def return_index(l, x, default=-1):
    if x in l:
        return l.index(x)
    else:
        return default

def check_bingo(a):
    if a[0] + a[1] + a[2] == 0:
        return True
    if a[3] + a[4] + a[5] == 0:
        return True
    if a[6] + a[7] + a[8] == 0:
        return True
    if a[0] + a[3] + a[6] == 0:
        return True
    if a[1] + a[4] + a[7] == 0:
        return True
    if a[2] + a[5] + a[8] == 0:
        return True
    if a[0] + a[4] + a[8] == 0:
        return True
    if a[2] + a[4] + a[6] == 0:
        return True
    return False

for i in b:
    if return_index(a, i) >= 0:
        a[return_index(a, i)] = 0

print("Yes") if check_bingo(a) else print("No")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n, c, k;
    cin>>n>>c>>k;
    vl ts(n);
    cin>>ts;
    sort(rng(ts));

    ll st = ts[0];
    ll cnt = 0;
    ll ans = 0;
    rep(i, n) {
        if (ts[i] - st > k) {
            ans++;
            st = ts[i];
            cnt = 0;
        }
        if (cnt == c) {
            ans++;
            st = ts[i];
            cnt = 0;
        }
        cnt++;
    }
    if (cnt) ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<string> vstring;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;
#define Pi 3.1415926535897932384626
#define mod llint(1e9+7)

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(llint a, llint b) {
	return a > b;
}

// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//aCbを1000000007で割った余りを求める
llint convination(llint a, llint b) {
	llint ans = 1;
	for (llint i = 0; i < b; i++) {
		ans *= a - i;
		ans %= 1000000007;
	}
	for (llint i = 1; i <= b; i++) {
		ans *= modinv(i, 1000000007);
		ans %= 1000000007;
	}
	return ans;
}

//aのb乗をmodで割った余りを求める
llint power(llint a, llint b) {
	if (b == 1)return a;
	if (b == 0)return 1;
	llint tmp = power(a, (llint)b / 2);
	tmp *= tmp;
	tmp %= mod;
	if (b % 2 == 1) {
		tmp *= a;
		tmp %= mod;
	}
	return tmp;
}

int main() {
	int n;
	cin >> n;
	vint a(n);
	bool ans = true;
	rep(i, n) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	rep(i, n - 1) {
		if (a[i] == a[i + 1])ans = false;
	}
	YES(ans);
	return 0;
}

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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int alice = 0;
    int bob = 0;
    sort(a.begin(),a.end());
    reverse(a.begin(), a.end());
    for(int i = 0; i < n; i+=2){
        alice+=a[i];
    }
    for(int i = 1; i < n; i+=2){
        bob+=a[i];
    }
    cout << alice-bob;
}

Measured memory_bytes: 256
import math

N,D=map(int,input().split())
x=[input().split() for i in range(N)]

flag=0
ANS=0

for i in range(0,N):
    for j in range(i+1,N):
        for k in range(0,D):
            ANS+=(int(x[i][k])-int(x[j][k]))*(int(x[i][k])-int(x[j][k]))
        if math.sqrt(ANS)==int(math.sqrt(ANS)):
            flag+=1
        ANS=0
        
print(flag)

Measured memory_bytes: 3064
from math import ceil
N, A, B = map(int, input().split())
h = []
for i in range(N):
  h += [int(input())]

Th = 2*max(h)//B
Tl = 0
while Tl+1<Th:
  t = (Th+Tl)//2
  d = []
  for i in range(N):
    c = h[i]
    d += [c-B*t]
  for i in range(N):
    c = d[i]
    if c<=0:
      continue
    t -= ceil(c/(A-B))
    if t<0:
      Tl = (Th+Tl)//2
      break
  else:
    Th = (Th+Tl)//2
print(Th)


Measured memory_bytes: 85464
import sys
import math

N, M = map(int, input().split())

ans = 0

if (N + M) % 2 == 0:
  if N != M:
    print(0)
    sys.exit()

  ans = (math.factorial(N) * math.factorial(M)) * 2
else:
  if not N == M - 1 and not N - 1 == M:
    print(0)
    sys.exit()

  ans = math.factorial(N) * math.factorial(M)

print(ans % (10**9 + 7))

Measured memory_bytes: 5184
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		
		int a=sc.nextInt();		//1が書かれたカード
		int b=sc.nextInt();		//0が書かれたカード
		int c=sc.nextInt();		//-1が書かれたカード
		int k=sc.nextInt();		//k枚選ぶ
		
		if(k<=a){
        	System.out.println(k);
        }else if(k<=a+b){
        	System.out.println(a);
        }else{
        	System.out.println(2*a-k+b);
        }
	}

}


Measured memory_bytes: 27032
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main(){ 
  long long int a,b=100,c=0;cin>>a;
  while(b<=a){
    b*=1.01;
    c++;
    if(b>=a)break;
  }
  cout<<c;
  }


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e12;


int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    vector<vector<ll> > dp(n+1,vector<ll>(n+1,0) );//[i,j)での再全解
    for(int i=1;i<=n;i++){
	for(int j=0; i+j<=n;j++){
	    int k = i+j;
	    if( (n-i)%2 == 0){//先手
		dp[j][k] = max( dp[j+1][k] + a[j], dp[j][k-1] + a[k-1] );
	    }else{//後手
		dp[j][k] = min( dp[j+1][k] - a[j], dp[j][k-1] - a[k-1] );
	    }
	}
    }
    cout<<dp[0][n]<<endl;
    return 0;
}


Measured memory_bytes: 70784
#include<iostream>
#include<cstdint>
#include<string>
#include<algorithm>

int const MAXP = 1e4;
int N, P;
std::string S;

void calc_small() {
  int64_t dp[2][10], ans = 0;
  std::fill_n(dp[0], P, 0);
  int d = S[0] - '0';
  dp[0][d%P] = 1;
  ans = dp[0][0];
  for(int i = 1; i < N; ++i) {
    d = S[i] - '0';
    std::fill_n(dp[i%2], P, 0);
    dp[i%2][d%P] = 1;
    for(int p = 0; p < P; ++p) dp[i%2][(p*10+d)%P] += dp[(i-1)%2][p];
    ans += dp[i%2][0];
  }
  std::cout << ans << std::endl;
}

int main() {
  std::cin >> N >> P >> S;
  if(P > 10) {
    int64_t dp[MAXP], ans = 0;
    int inv10 = 1, a = 1, b = 0;
    while(inv10*10%P != 1) ++inv10;
    int d = S[0] - '0';
    dp[d] = 1;
    ans = dp[b];
    for(int i = 1; i < N; ++i) {
      d = S[i] - '0';
      ++dp[b];
      (a *= inv10) %= P;
      (b += (P-a)*d) %= P;
      ans += dp[b];
    }
    std::cout << ans << std::endl;
  } else calc_small();
  return 0;
}


Measured memory_bytes: 644
/*
    Written by Nitrogens
    Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 1e4+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl

char input[maxn];
int digit[maxn];
ll dp[maxn][105];
int n, d;

ll dfs(int pos, bool limit, int sum)
{
    if(pos == n + 1)               return 1LL * (sum == 0);
    if(!limit && dp[pos][sum] != -1)    return dp[pos][sum];
    int range = limit ? digit[pos] : 9;
    ll res = 0;
    for(int i = 0; i <= range; i++)
    {
        res = (res + dfs(pos + 1, limit && i == digit[pos], (sum + i) % d)) % Mod;
    }
    if(!limit)  dp[pos][sum] = res;
    return res;
}

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);

    scanf("%s", input + 1);
    scanf("%d", &d);

    n = strlen(input + 1);
    for(int i = 1; i <= n; i++) digit[i] = input[i] - '0';

    memset(dp, -1, sizeof(dp));
    ll answer = dfs(1, true, 0);

    printf("%lld\n", (answer - 1 + Mod) % Mod);

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 9088
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define gcd(a,b) __gcd(a,b)s
const int N=2e5+10;
const int inf=1e9;
const int mod=1e9+7;

int  main(int argc, char const *argv[])
{
	/*#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(0);

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

    int cnt[n+1]={0};

    for(int i=1; i<=n; i++)
    {
        for(int j=i+1; j<=n; j++)
        {
            int dis1=abs(x-i)+1+abs(y-j);
            int dis2=abs(x-j)+1+abs(y-i);
            int dis=min(abs(i-j), min(dis1, dis2));
            cnt[dis]++;
        }
    }

    for(int i=1; i<n; i++)
        cout << cnt[i] << endl;

	return 0;
}



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

int main()
{
	int N;
	cin >> N;
	int min_value = N + 1;
	int ans = 0;
	for (int i = 0; i < N; ++i)
	{
		int p;
		cin >> p;
		if (p <= min_value)
		{
			min_value = p;
			ans++;
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 256
// abc060_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif
    
    int A, B, C;
    cin >> A >> B >> C;
    
    if (C % gcd(A, B) == 0){
        print("YES");
    } else{
        print("NO");
    }


    return 0;
}


Measured memory_bytes: 256
i,j,k;
long s[444],p[444][444],S;
main(a)
{
	scanf("%*d");
	for(;~scanf("%d",&a);)
	{
		i=j++;
		for(s[j]=S+=a;i--;)
		{
			p[i][j]=9e18;
			for(k=i;++k<j;)
			{
				p[i][j]=fmin(p[i][j],p[i][k]+p[k][j]+S-s[i]);
			}
		}
	}
	printf("%ld",p[0][j]);
}

Measured memory_bytes: 1536
#include <stdio.h>          // printf(), scanf()

#define MAX_N 131072
#define MAX_INT 0x7fffffff
#define min(a, b) ((a) < (b) ? (a) : (b))

int dat[2 * MAX_N - 1];
int n;

void
init_rmq(int m)
{
	int i;

	n = 1;
	while (n < m)
		n *= 2;

	for (i = 0; i < 2 * n - 1; ++i)
		dat[i] = MAX_INT;
}

void
update(int k, int a)
{
	k += n - 1;
	dat[k] = a;
	while (k > 0)
	{
		k = (k - 1) / 2;
		dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
	}
}

int
query(int a, int b, int k, int l, int r)
{
	if (r <= a || b <= l)
		return MAX_INT;

	if (a <= l && r <= b)
		return dat[k];

	int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
	int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
	return min(vl, vr);
}

int
main(int argc, char** argv)
{
	int q;
	int c, x, y;
	int i;

	scanf("%d %d", &n, &q);
	init_rmq(n);
	for (i = 0; i < q; ++i)
	{
		scanf("%d %d %d", &c, &x, &y);
		if (c == 0)
			update(x, y);
		else
			printf("%d\n", query(x, y + 1, 0, 0, n));
	}

	return 0;
}

Measured memory_bytes: 1624
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <assert.h>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main(){
  ll a,b;
  cin>>a>>b;
  if(a<=b){
    cout << "unsafe" << endl;
  }
  else{
    cout << "safe" << endl;
  }
  return 0;
}

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

int main() {
    int n; cin >> n;
    vector<vector<P>> data(n);
    rep(i,n) {
        int a; cin >> a;
        rep(j,a) {
            int x, y; cin >> x >> y;
            x--; 
            data[i].push_back(P(x,y));
        }
    }
    int ans = 0;
    rep(i,1<<n) {
        bool ok = true;
        rep(j,n) {
            if (i>>j&1) {
                rep(k,data[j].size()) {
                    if (data[j][k].second == 1) {
                        if (!(i>>data[j][k].first&1)) ok = false;
                    } else {
                        if (i>>data[j][k].first&1) ok = false;
                    }
                }
            }
        }
        if (ok) ans = max(ans,__builtin_popcount(i));
    }
    cout << ans << endl;
}

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

int main(){
	int n,m,c,count=0;
	cin>>n>>m>>c;
	int b[m+5],arr[n+5][m+5],psum[n+5];
	for(int i=1;i<=n;i++){
		psum[i]=0;
	}
	for(int i=1;i<=m;i++){
		cin>>b[i];
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>arr[i][j];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			psum[i]=psum[i]+(arr[i][j]*b[j]);
		}
	}
	for(int i=1;i<=n;i++){
		if(psum[i]+c>0){
			count++;
		}
	}
	cout<<count<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <map>
#include <cctype>
#include <vector>
using namespace std;

typedef long long LL;

const string charset = "01+-*()=";
string input;
int sz;
int ans;
map<char,int> mp;
vector<char> tbl;
const char *p;

LL expr();
LL term();
LL factor();

LL expr(){
	LL x = term();
	while(1){
		if(*p == '+'){
			++p;
			LL y = term();
			x += y;
		}
		else if(*p == '-'){
			++p;
			LL y = term();
			x -= y;
		}
		else{ break; }
	}
	return x;
}

LL term(){
	LL x = factor();
	while(*p == '*'){
		++p;
		LL y = factor();
		x *= y;
	}
	return x;
}

LL factor(){
	if(*p == '-'){
		++p;
		LL x = factor();
		return -x;
	}
	if(*p == '('){
		++p;
		LL x = expr();
		if(*p != ')'){ throw 1; }
		++p;
		return x;
	}
	if(*p == '0'){
		++p;
		return 0;
	}
	if(*p == '1'){
		char *endp;
		LL x = strtoll(p, &endp, 2);
		p = endp;
		return x;
	}
	throw 2;
}

void check() try{
	string e;
	for(char c : input){
		if(isalpha(c)){
			e += tbl[mp[c]];
		}
		else{
			e += c;
		}
	}
	p = e.c_str();
	
	LL lt = expr();
	if(*p == '='){
		++p;
		LL rt = expr();
		if(!*p && lt == rt){
			++ans;
		}
	}
}
catch(...){}

void dfs(int i, int u){
	if(i == sz){
		check();
	}
	else{
		for(int j = 0; j < 8; ++j){
			if(!(u >> j & 1)){
				tbl[i] = charset[j];
				dfs(i + 1, u | 1 << j);
			}
		}
	}
}

int main(){
	cin >> input;
	for(char c : input){
		if(isalpha(c)){
			mp.emplace(c, mp.size());
		}
	}
	sz = mp.size();
	if(sz <= 8){
		tbl.assign(sz, 0);
		dfs(0, 0);
	}

	cout << ans << endl;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i=0; i<N; i++) cin >> A.at(i);
    bool isEnd = false;
    int ans = 0;
    while (true) {
        for (int i=0; i<N; i++) {
            if (A.at(i)%2!=0) {
                isEnd = true;
                break;
            }
            A.at(i)/=2;
        }
        if (isEnd) {
            cout << ans << "\n";
            return 0;
        }
        ans++;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdint>
using namespace std;

const int MOD = 1000000007; // 今回使う余り
const int MAX = 100001;
const int64_t MIN = 0;
int main() {
	string S;
	cin >> S;
	int l = S.size();
	static int64_t three[MAX], A[MAX], C[MAX], Q[MAX];
	A[0] = S[0] == 'A' ? 1 : 0;
	C[0] = S[0] == 'C' ? 1 : 0;
	Q[0] = S[0] == '?' ? 1 : 0;
	for (int i = 0;i < l;i ++) {
		A[i] = A[i - 1] + (S[i] == 'A' ? 1 : 0);
		C[i] = C[i - 1] + (S[i] == 'C' ? 1 : 0);
		Q[i] = Q[i - 1] + (S[i] == '?' ? 1 : 0);
	}
	three[0] = 1;
	for (int i = 1;i < l;i ++) {
		three[i] = three[i - 1] * 3 % MOD;
	}

	int64_t ans = 0;
  // l -> 文字列のサイズ
	for (int i = 1;i < l - 1; i++) {
		if (S[i] == 'B' || S[i] == '?') {
			ans += A[i] * (C[l - 1] - C[i]) % MOD * three[max(MIN, Q[l - 1] - (S[i] == '?' ? 1 : 0))] % MOD; // AとCを選ぶ場合 S[i]が'?'の場合 -1
			ans += Q[i - 1] * (C[l - 1] - C[i]) % MOD * three[max(MIN, Q[l - 1] - (S[i] == '?' ? 2 : 1))] % MOD; // ?とCを選ぶ場合
			ans += A[i] * (Q[l - 1] - Q[i]) % MOD * three[max(MIN, Q[l - 1] - (S[i] == '?' ? 2 : 1))] % MOD; // Aと?を選ぶ場合
			ans += Q[i - 1] * (Q[l - 1] - Q[i]) % MOD * three[max(MIN, Q[l - 1] - (S[i] == '?' ? 3 : 2))] % MOD; // ?と?を選ぶ場合
			ans %= MOD;
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

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

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int a, b;
  cin >> a >> b;

  if (a + b >= 10) cout << "error" << "\n";
  else cout << a + b << "\n";

  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<map>
#include<vector>
#define debug(...) fprintf(stderr,__VA_ARGS__) 
#define ref(a,b,c) for(int a=b;a<=c;++a)
#define def(a,b,c) for(int a=b;a>=c;--a)
#define fi first
#define se second
using namespace std;
inline char nc(){
//	return getchar();
	static char buf[100000],*l=buf,*r=buf;
	return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++; 
}
template<class T>void read(T &x){
	x=0;int f=1,ch=nc();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
	x*=f;
}
typedef long long LL;
typedef pair<int,int> pii;
const int maxn=1e5+10;
LL D[maxn];
LL f[maxn];
int n;
int p[maxn];
int siz[maxn];
map<LL,int>idx; 
vector<pii>an; 
inline int cmp(const int&a,const int&b){
	return D[a]>D[b];
}
bool solve(){
	ref(i,1,n)p[i]=i,siz[i]=1,f[i]=0;
	sort(p+1,p+n+1,cmp);
	ref(i,1,n-1){
		int u=p[i];
		if(!idx.count(D[u]-n+2*siz[u]))return 0;
		int fa=idx[D[u]-n+2*siz[u]]; 
		if(u==fa)return 0;
		an.push_back(make_pair(fa,u));
		siz[fa]+=siz[u];
		f[fa]+=f[u]+siz[u];
	}
	if(f[p[n]]!=D[p[n]])return 0;
	ref(i,0,n-2)printf("%d %d\n",an[i].fi,an[i].se);
	return 1;
}
int main(){
	read(n);
	ref(i,1,n){
		read(D[i]);
		idx[D[i]]=i;
	}
	if(!solve())puts("-1");
	return 0;
}

Measured memory_bytes: 11000
import java.util.*;
class Main {
    static long cntX;
    static long cntY;
    static HashMap<Integer, List<Integer>> map;
    static boolean[] visited;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        map = new HashMap<>();

        for(int i = 0; i<N; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt()+100001;
            if(!map.containsKey(x)) {
                map.put(x, new ArrayList<>());
            }
            if(!map.containsKey(y)) {
                map.put(y, new ArrayList<>());
            }
            map.get(x).add(y);
            map.get(y).add(x);
        }

        visited = new boolean[100001*2];
        long ans = 0;
        for(int i = 0; i<100001; i++) {
            cntX = 0;
            cntY = 0;
            dfs(i);
            ans += cntX*cntY;
        }

        System.out.println(ans-N);

    }
    public static void dfs(int x) {
        if(visited[x]) return;
        visited[x] = true;
        if(x<100001) cntX++;
        else cntY++;
        if(map.containsKey(x)) {
            for(int i: map.get(x)) {
                dfs(i);
            }
        }
    }
}

Measured memory_bytes: 119436
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	char lc1Buf[1024], lc1Out[1024];

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// 座標X取得
	int liX;
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d", &liX);

	// 最短時間取得[n*(n+1)/2=X、n^2+n-2X=0、(n+0.5)^2=2x-0.5*0.5
	int liN = (int)(sqrt(2.0 * (double)liX - 0.5 * 0.5) - 0.5);

	// 最短で行けるかチェック
	int liSum = liN * (liN + 1) / 2;
	if (liSum < liX) {
		liN++;
	}

	// 結果セット
	sprintf(lc1Out, "%d\n", liN);

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



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



int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	int k;
	int minj;
	int count = 0;
	for (int i = 0;i < N;i++)cin >>A[i];
	for (int i = 0;i < N;i++)
	{
		minj = i;
		for (int j = i;j < N;j++)
		{
			if (A[j] < A[minj]) {
				minj = j;
			}
				
			
		}
		k = A[i];
		A[i] = A[minj];
		A[minj] = k;
		if(minj!=i)count++;
	}

	for (int i = 0;i < N;i++) {
		if (i != 0) {
			cout << " ";
		}cout << A[i];
	}cout << endl;
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 3112
#include<stdio.h>
#include<vector>
#include<string>
#include<iostream>
using namespace std;

int main(){
  int x[5];
  int k;
  for (int i = 0; i < 5; i++){
    cin >> x[i];
  }
  cin >> k;


  bool res = true;
  for(int i = 0; i < 5; i++){
    for (int j = i+1; j < 5; j++ )
    if(x[j] - x[i] > k) {
      res = false;
      break;
    }    
  }
  if(res) cout << "Yay!" << endl;
  else cout << ":(" << endl;
}

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

using namespace std;

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

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()

int main(){
    int N,K;
    cin>>N>>K;
    string A;
    while(N!=0){
        A+=char(N%K);
        N-=(N%K);
        N/=K;
    }

    cout<<A.size()<<endl;

    return 0;
}

//a=97,z=122

Measured memory_bytes: 256
using System;
class Program
{
    static void Main()
    {
        string[] input = Console.ReadLine().Split(' ');
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);
        int c = int.Parse(input[2]);
        if ((a + b == c) || (a + c == b) || (b + c == a)) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}

Measured memory_bytes: 2776
def DP_2(n,h,k):
  #初期化
  dp = [float("inf")] * n
  dp[0] = 0
  #DP
  for i in range(1,n):
        dp[i] = min([dp[m] + abs(h[m] - h[i]) for m in range(max(0, i - k),  i)])
  return dp[-1]

        
n,k = map(int,input().split())
h = list(map(int,input().split()))
print(DP_2(n,h,k))

Measured memory_bytes: 13980
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
using namespace std;
// main
int main(){
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int count = 0;
    int total = 0;
    REP(a, A+1){
        REP(b, B+1){
            REP(c, C+1){
                total = 500*(a) + 100*(b) + 50*(c);
                if(total == X)count++;
            }
        }
    }

    cout << count << "\n";
    return 0;
}

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

using namespace std;


int main()
{
    string s;
    long long int k, i=0,j, t,n;
    cin >> k >> s;
    if(s.size() > k)
    {
        for(i=0;i<k;i++)
        {
            cout << s[i];
        }
        cout << "...";

    }else
    {
        cout << s;
    }


    return 0;
}


Measured memory_bytes: 3628
#![allow(unused_mut, unused_macros, unused_variables, unused_assignments, non_snake_case, unused_imports, dead_code)]

use std::cmp::*;
use std::collections::*;

// [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 から拝借
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    // ABC128-C-Switches用に拡張
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, $t);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// Pythonからの移行組としては苦しすぎるのでライブラリ濫造
fn gcd(a:usize, b:usize) -> usize {
    if b == 0 {return a};
    return gcd(b, a % b);
}

// エントリーポイント
fn main() {
    input! {
        R : usize
    }
    println!("{}", R * R * 3);
}


Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int mn = min(a, min(b, c));
  int mx = max(a, max(b, c));
  cout << mn << " " << mx << endl;
  return 0;
}


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

template <typename T>
struct BIT {
    int n;
    vector<T> data;

    BIT(int n) : n(n), data(n + 1) {}
    void add(int a, T w) {
        for (int x = ++a; x <= n; x += x & -x) data[x] += w;
    }
    T sum(int a) {
        T ret = 0;
        for (int x = a; x > 0; x -= x & -x) ret += data[x];
        return ret;
    }
};

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

    int n, q;
    cin >> n >> q;
    BIT<int> bit(n);
    for (int i = 0; i < q; i++) {
        int t;
        cin >> t;
        if (t == 0) {
            int x, y;
            cin >> x >> y;
            x--;
            bit.add(x, y);
        } else {
            int l, r;
            cin >> l >> r;
            l--;
            cout << bit.sum(r) - bit.sum(l) << endl;
        }
    }
}



Measured memory_bytes: 3264
#include "bits/stdc++.h"

using namespace std;
using ll = long long;

int main() {
    int h, w, k; cin >> h >> w >> k;
    string g[h + 2];

    for (int i = 0; i < h; i++) cin >> g[i];

    int ans = 0;
    for (int r = 0; r < (1 << h); r++) {
        for (int c = 0; c < (1 << w); c++) {
            int ttl = 0;
            for (int i = 0; i < h; i++) {
                if (r & (1 << i)) continue;
                for (int j = 0; j < w; j++) {
                    if (c & (1 << j)) continue;
                    if (g[i][j] == '#') ttl++;
                }
            }

            if (ttl == k) ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3632
import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        ArrayList<ArrayList<Integer>> arr=new ArrayList<>(n+1);
        for(int i=0;i<=n;i++){
            ArrayList<Integer> temp=new ArrayList<>();
            arr.add(temp);
        }
        for(int i=1;i<=n-1;i++){
            int x=s.nextInt();
            int y=s.nextInt();
            arr.get(x).add(y);
            arr.get(y).add(x);
        }
        long dp[][]=new long[n+1][2];
        int mod=1000000007;
        f(1,0,arr,-1,dp,mod);
        System.out.println(dp[1][0]);

    }
    public static long f(int root,int constraint,ArrayList<ArrayList<Integer>> arr,int parent,long dp[][],int mod){
        if(dp[root][constraint]!=0) return dp[root][constraint];
        ArrayList<Integer> temp=arr.get(root);
        long ans=0;
        long w1=1;
        for(int i=0;i<temp.size();i++){
            int child=temp.get(i);
            if(child!=parent){
                w1=(w1*f(child,0,arr,root,dp,mod)) % mod;
            }
        }
        ans=ans+w1;
        if(constraint==0){
            long w2=1;
             for(int i=0;i<temp.size();i++){
                int child=temp.get(i);
                if(child!=parent){
                    w2=(w2*f(child,1,arr,root,dp,mod)) % mod;
                }
             }
             ans=(ans+w2) % mod;
            return dp[root][constraint]=ans;
        }
            return dp[root][constraint]=ans;
    }
}

Measured memory_bytes: 85984
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 = a*b;
		
		if(c%2==0) {
			System.out.println("Even");
		}else{
			System.out.println("Odd");
			
		}
		
	}
}


Measured memory_bytes: 21332