akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		int N=in.nextInt();
		int judge=0;
		while(N-->0)
		{
			if(judge!=0)
				System.out.println();
			judge=1;

			int a[][]=new int[9][9];
			boolean b[][]=new boolean[9][9];
			for(int i=0;i<9;i++)
				for(int j=0;j<9;j++)
				{
					a[i][j]=in.nextInt();
					b[i][j]=true;
				}
			for(int i=0;i<9;i++)
				for(int j=0;j<9;j++)
					for(int k=j+1;k<9;k++)
					{
						if(a[i][j]==a[i][k])
							b[i][j]=b[i][k]=false;
						if(a[j][i]==a[k][i])
							b[j][i]=b[k][i]=false;
					}

			for(int i=0;i<3;i++)
				for(int j=0;j<3;j++)
				{

					for(int k=0;k<3;k++)
						for(int l=0;l<3;l++)
						{
							if(i==k&&j==l)
								continue;
							if(a[i][j]==a[k][l])
								b[i][j]=b[k][l]=false;
						}
				}
			for(int i=0;i<3;i++)
				for(int j=3;j<6;j++)
				{

					for(int k=0;k<3;k++)
						for(int l=3;l<6;l++)
						{
							if(i==k&&j==l)
								continue;
							if(a[i][j]==a[k][l])
								b[i][j]=b[k][l]=false;
						}
				}
			for(int i=0;i<3;i++)
				for(int j=6;j<9;j++)
				{

					for(int k=0;k<3;k++)
						for(int l=6;l<9;l++)
						{
							if(i==k&&j==l)
								continue;
							if(a[i][j]==a[k][l])
								b[i][j]=b[k][l]=false;
						}
				}

			for(int i=3;i<6;i++)
				for(int j=0;j<3;j++)
				{

					for(int k=3;k<6;k++)
						for(int l=0;l<3;l++)
						{
							if(i==k&&j==l)
								continue;
							if(a[i][j]==a[k][l])
								b[i][j]=b[k][l]=false;
						}
				}
			for(int i=3;i<6;i++)
				for(int j=3;j<6;j++)
				{

					for(int k=3;k<6;k++)
						for(int l=3;l<6;l++)
						{
							if(i==k&&j==l)
								continue;
							if(a[i][j]==a[k][l])
								b[i][j]=b[k][l]=false;
						}
				}
			for(int i=3;i<6;i++)
				for(int j=6;j<9;j++)
				{

					for(int k=3;k<6;k++)
						for(int l=6;l<9;l++)
						{
							if(i==k&&j==l)
								continue;
							if(a[i][j]==a[k][l])
								b[i][j]=b[k][l]=false;
						}
				}

			for(int i=6;i<9;i++)
				for(int j=0;j<3;j++)
				{

					for(int k=6;k<9;k++)
						for(int l=0;l<3;l++)
						{
							if(i==k&&j==l)
								continue;
							if(a[i][j]==a[k][l])
								b[i][j]=b[k][l]=false;
						}
				}
			for(int i=6;i<9;i++)
				for(int j=3;j<6;j++)
				{

					for(int k=6;k<9;k++)
						for(int l=3;l<6;l++)
						{
							if(i==k&&j==l)
								continue;
							if(a[i][j]==a[k][l])
								b[i][j]=b[k][l]=false;
						}
				}
			for(int i=6;i<9;i++)
				for(int j=6;j<9;j++)
				{

					for(int k=6;k<9;k++)
						for(int l=6;l<9;l++)
						{
							if(i==k&&j==l)
								continue;
							if(a[i][j]==a[k][l])
								b[i][j]=b[k][l]=false;
						}
				}

			for(int i=0;i<9;i++)
			{
				for(int j=0;j<9;j++)
					System.out.print(b[i][j] ? " "+a[i][j] : "*"+a[i][j]);
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 23672
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;

  int ans=0;

  char N;

  if(A<K){
    K=K-A;
    ans=A;
  }
  else if(K<=A){
    ans=K;
    K=0;
  }

  if(K>0 && B<K){
    K=K-B;
  }
  else if(K>0){
    K=0;
  }
  
  if(K>0){
    ans=ans-K;
  }

  cout << ans << endl;


return 0;
}

Measured memory_bytes: 3636
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

     static Scanner scanner;

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

         int N=gi();
         long[] a=new long[N];
         long[] x=new long[N];
         
         for(int i=0; i<N;i++) {
        	 a[i]=gl();
         }
         
         x[0]=0;
         for (int i=0; i<N; i++) {
        	 if(i%2==0) {
        		 x[0]+=a[i];
        	 } else {
        		 x[0]-=a[i];
        	 }
         }
         for(int i=1; i<N;i++) {
        	 x[i]=2*a[i-1] - x[i-1];
         }
         
         for (int i=0; i<N; i++) {
        	 if(i!=0)System.out.print(" ");
        	 System.out.print(x[i]);
         }

         //System.out.print("Yes");
     }
     
     public static class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> implements Comparable<Pair<K, V>> {
    		/** serialVersionUID. */
    	    private static final long serialVersionUID = 6411527075103472113L;

    	    public Pair(final K key, final V value) {
    	        super(key, value);
    	    }

    		@Override
    		public int compareTo(Pair<K, V> o) {

    			Comparable key = (Comparable)this.getKey();
    			Comparable key2 = (Comparable)o.getKey();

    			return key.compareTo(key2);
    		}

    	}

     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

Measured memory_bytes: 62748
N=int(input())
TXY=[list(map(int,input().split(' '))) for i in range(N)]
t,x,y=0,0,0
for i,j,k in TXY:
    chk=(i-t-(abs(x-j)+abs(y+k)))
    if chk<0 or chk%2!=0:
        print('No')
        exit()
print('Yes')

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

int main(){
  int num[3][3];
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>num[i][j];
      if(i!=0){
        num[i][j]-=num[0][j];
      }
    }
  }
  if(num[1][0]==num[1][1] && num[1][1]==num[1][2] && num[2][0]==num[2][1] && num[2][1]==num[2][2]){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
s = gets.chomp.to_i

def f(n)
  if n % 2 == 0 then
    n / 2
  else
    n * 3 + 1
  end
end

n = 1
an = s
a = []
while true do
  unless a.index(an).nil? then
    break
  end
  
  a.push(an)
  
  an = f(an)
  n += 1
end

puts n.to_s

Measured memory_bytes: 1788
#include<stdio.h>
int main()
{
    int a, b,i;
    scanf("%d %d", &a, &b);

    if( a>=b){
        for( i=1; i<=a;i++)
            printf("%d",b);
    }
    else
    {
        for( i=1; i<=b; i++)
            printf("%d", a);
    }
}


Measured memory_bytes: 128
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
int main(void){
    int n,i;
    double x[1001]={0};
    double y[1001]={0};
    double d1=0,square=0,d2,cubic=0,d3,dinf;
    
    
    scanf("%d",&n);
    
    for(i=1; i<=n; i++){
        scanf("%lf",&x[i]);
    }
    
    for(i=1; i<=n; i++){
        scanf("%lf",&y[i]);
    }
    
    for(i=1; i<=n; i++){
        d1 += fabs(x[i]-y[i]);
    }
    
    for(i=1; i<=n; i++){
        square += pow(fabs(x[i]-y[i]),2);
    }
    d2=sqrt(square);
    
    for(i=1; i<=n; i++){
        cubic += pow(fabs(x[i]-y[i]),3);
    }
    d3=cbrt(cubic);
    
    dinf=fabs(x[1]-y[1]);
    for(i=1; i<=n; i++){
        dinf = (fabs(x[i]-y[i]) > dinf) ? fabs(x[i]-y[i]) : dinf;
    }
    
    
    printf("%lf\n%lf\n%lf\n%lf\n",d1,d2,d3,dinf);
    
    return 0;
}

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

using namespace std;

const int MAX_N = 13, MAX_POW3_N = 531441, MAX_M = 200020;

int N, M, Half, pow3[MAX_N], salsa[MAX_POW3_N], highbits[MAX_POW3_N], Ans[MAX_POW3_N];

char S[MAX_M];

int main() {
    scanf("%d", &N); Half = N / 2;
    scanf("%s", S + 1); M = strlen(S + 1);
    pow3[0] = 1;
    for (int i = 1; i <= N; i++) pow3[i] = pow3[i - 1] * 3;
    for (int i = 0; i < pow3[N]; i++) {
        int result = 0;
        for (int j = 0; j < N; j++) {
            int t = i / pow3[j] % 3;
            result += (3 - t) % 3 * pow3[j];
        }
        salsa[i] = result;
    }
    for (int i = 0; i < pow3[Half]; i++) {
        int lowbits = i;
        for (int j = 0; j < pow3[N - Half]; j++)
            highbits[j] = j;
        bool high_flip = false;
        for (int j = 1; j <= M; j++) {
            if (S[j] == 'S') {
                high_flip ^= true;
                lowbits = salsa[lowbits];
            } else {
                if (++lowbits == pow3[Half]) {
                    lowbits = 0;
                    if (high_flip) {
                        for (int j = 0; j < pow3[N - Half]; j++) {
                            highbits[j] = salsa[highbits[j]];
                        }
                        high_flip = false;
                    }
                    for (int j = 0; j < pow3[N - Half]; j++) {
                        if (++highbits[j] == pow3[N - Half])
                            highbits[j] = 0;
                    }
                }
            }
        }
        if (high_flip) {
            for (int j = 0; j < pow3[N - Half]; j++) {
                highbits[j] = salsa[highbits[j]];
            }
        }
        high_flip = false;
        for (int j = 0; j < pow3[N - Half]; j++){
            Ans[j * pow3[Half] + i] = highbits[j] * pow3[Half] + lowbits;
        }
    }
    for (int i = 0; i < pow3[N]; i++) printf("%d ", Ans[i]);
    printf("\n");
}

Measured memory_bytes: 8348
#include <bits/stdc++.h>
# define ll int64_t
#define rep(i,n) for(ll i=0;i<n;i++)
#define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}





int main(void){
    ll n,sum=0;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) {
        cin>>a[i];
        while(a[i]%2==0){
            sum++;
            a[i] /= 2;
        }
    }
    cout<<sum<<endl;
    return 0;
}

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

std::string S, T;
int length;

bool solve();
bool able(int);

int main()
{
	if (solve()) puts("Yes");
	else puts("No");

	return 0;
}

bool solve()
{
	std::cin >> S >> T;
	length = (int)S.size();
	for (int i{}; i < length; i++)
		if (able(i))
			return true;
	return false;
}

bool able(int s_begin)
{
	for (int t_i{}; t_i < length; t_i++)
		if (S[(s_begin + t_i) % length] != T[t_i])
			return false;
	return true;
}

Measured memory_bytes: 256
H, W, N = map(int, input().split())
s_r, s_c = map(int, input().split())
S = input()
T = input()

# vertical direction
up, down = 0, H-1
for i in range(N-1, -1, -1):
    if T[i] == 'U':
        down = min(H-1, down + 1)
    elif T[i] == 'D':
        up = max(0, up - 1)
    
    if S[i] == 'U':
        up += 1
    elif S[i] == 'D':
        down -= 1
    
    if up > down:
        print('NO')
        exit()
        
# horizontal direction
left, right = 0, W-1
for i in range(N-1, -1, -1):    
    if T[i] == 'L':
        right = min(W-1, right + 1)
    elif T[i] == 'R':
        left = max(0, left - 1)
    
    if S[i] == 'L':
        left += 1
    elif S[i] == 'R':
        right -= 1
    
    if left > right:
        print('NO')
        exit()
if up <= s_r-1 <=down and left <= s_c-1 <= right:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3888
#include <iostream>
using namespace std;
int main(void){
    string s;
    cin >> s;
    int t = 0;
    for(int i = 0;i < s.size();i++){
          t += s[i] - '0';
          t %= 9;
    }
    if(t == 0){
          cout << "Yes" << endl;
    }else{
          cout << "No" << endl;
    }
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
template<typename T>
inline void read(T &x)
{
	x=0;
	int f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-') f=-1;
		ch=getchar();
}
	while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
	x*=f;
	return;
}	
template<typename T>
void write(T x)
{
	if(x<0) putchar('-'),x=-x;
	if(x>=10) write(x/10);
	putchar(x%10+'0');
	return;
}
const int MAXN=3010;
int n,m,k;
long long mp[MAXN][MAXN];
long long f[MAXN][MAXN][5];
int main()
{
    read(n),read(m),read(k);
    for(int i=1;i<=k;++i)
    {
        int x,y;
        read(x),read(y),read(mp[x][y]);
    }
    for(int i=1;i<=n;++i)
    for(int j=1;j<=m;++j)
    {
        f[i][j][0]=max(f[i][j][0],max(max(f[i-1][j][0],f[i-1][j][1]),max(f[i-1][j][2],f[i-1][j][3])));
        f[i][j][1]=max(f[i][j][1],max(max(f[i-1][j][0],f[i-1][j][1]),max(f[i-1][j][2],f[i-1][j][3]))+mp[i][j]);
        for(int k=1;k<=3;++k) f[i][j][k]=max(f[i][j][k],max(f[i][j-1][k-1]+mp[i][j],f[i][j-1][k]));
    }
    write(max(max(f[n][m][0],f[n][m][3]),max(f[n][m][1],f[n][m][2]))),putchar('\n');
	return 0;
}


Measured memory_bytes: 426528
def main():

    from bisect import bisect_left as bl, bisect_right as br, insort
    import sys,heapq,math
    from collections import defaultdict as dd, deque
    def data(): return sys.stdin.readline().strip()
    def mdata(): return list(map(int, data().split()))
    out = sys.stdout.write
    # sys.setrecursionlimit(100000)
    INF = int(1e9)
    mod = int(1e9)+7

    x=int(data())
    p=100
    cnt=0
    while p<x:
        p+=p//100
        cnt+=1
    print(cnt)



if __name__ == '__main__':
    main()


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

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 N;
  cin >> N;
  vector<ll> A(N);
  REP(i, N)
  cin >> A[i];
  sort(ALL(A));
  reverse(ALL(A));
  ll sum1 = 0, sum2 = 0;
  // A1 > A2 < A3 > ...のパターン
  int pos = 0;
  REP(i, (N - 2) / 2)
  sum1 += (2 * A[pos++]);
  sum1 += A[pos++];
  sum1 += (N % 2 == 0) ? -A[pos++] : A[pos++];
  REP(i, (N - 1) / 2)
  sum1 -= (2 * A[pos++]);
  // A1 < A2 > A3 < ...のパターン
  pos = 0;
  REP(i, (N - 1) / 2)
  sum2 += (2 * A[pos++]);
  sum2 += (N % 2 == 0) ? A[pos++] : -A[pos++];
  sum2 -= A[pos++];
  REP(i, (N - 2) / 2)
  sum2 -= (2 * A[pos++]);
  cout << max(sum1, sum2) << endl;
  return 0;
}

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

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

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int L = scanner.nextInt();
        String[] S = new String[N];
        for(int i = 0; i < N; i++) {
            S[i] = scanner.next();
        }
        Arrays.sort(S);
        for(int i = 0; i < N; i++) {
            System.out.print(S[i]);
        }
    }
}

Measured memory_bytes: 37440
import java.util.Scanner;

class Main {
  public static void main(String args[]){
     Scanner ap = new Scanner(System.in);
     //整数入力
     int A = ap.nextInt();
     int P = ap.nextInt();
     
     int pie = (A*3 + P) / 2;
      
      System.out.println(pie);
      
  }
}

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

using namespace std;

int main(){
  string s, t;
  cin >> s;
  cin >> t;
  int count = 0;
  if(s[0] == t[0]){
    count++;
  }
  if(s[1] == t[1]){
    count++;
  }
  if(s[2] == t[2]){
    count++;
  }
  
  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
        int i, j;
        for(i = 1; i <= 9; i++)
        {
                for(j = 1; j <= 9; j++)
                {
                        printf("%dx%d=%d\n", i, j,i*j);
                }
        }
 return 0;
}

Measured memory_bytes: 924
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001; // > 10^9
const int MOD = (int)1e9 + 7;
const ll INFLL = 1001001001001001001;  // > 10^18
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {
    
    ll n; cin >>n;
    vector<ll> a(n); rep(i,n) cin >> a[i];

    ll ans = 0;
    for (ll i = 0; i < n; i++) {
        for (ll j = i + 1; j < n; j++) {
            ans += a[i]*a[j];
        }
    }

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


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

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

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

    sort(L.rbegin(), L.rend());

    int total = 0;
    for(int i = 1; i < n; i++){
        total += L[i];
    }

    if(L[0] < total){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int main(){
	char a;
	cin >> a;
	if('Z' < a) cout << "a" << endl;
	else cout << "A" << endl;
}

Measured memory_bytes: 3624
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readInteger()
    val xList = readLongList()

    var ans = Long.MAX_VALUE
    for (p in 1..100L) {
        val tmp = xList.fold(0L) { acc, x -> acc + (x - p) * (x - p) }
        ans = min(ans, tmp)
    }
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 36424
import java.util.*;

class Main{
    static double pi = Math.PI;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        double a = (double)sc.nextInt();
        double b = (double)sc.nextInt();
        double h = (double)sc.nextInt();
        double m = (double)sc.nextInt();

        double theta = (h/6.0 - 11.0*m/360.0)*pi;
        double tmp = a*a + b*b - 2.0*a*b*Math.cos(theta);
        System.out.println(Math.sqrt(tmp));


    }

}


Measured memory_bytes: 27196
#include<iostream>
using namespace std;
const int NUMBER=100;

int BubbleSort(int A[],int n){
  int count=0;
  bool flag=1;
  for(int i=0;flag;i++){
    flag=0;
    for(int j=n-1;j>=i+1;j--){
      if(A[j]<A[j-1]){
	  swap(A[j],A[j-1]);
	  count++;
	  flag=1;
	}
    }
  }
  return count;
}

int main(){
  int A[NUMBER];
  int n;
  int count;

  cin>>n;

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


  count=BubbleSort(A,n);

  int i;
  for(i=0;i<n-1;i++){
    cout<<A[i]<<' ';
  }
  cout<<A[i]<<endl;

  cout<<count<<endl;

  return 0;
}


  



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

namespace abc153_b
{
    class Program
    {
        static void Main(string[] args)
        { 
            string[] HN = Console.ReadLine().Split(' ');
            int H = int.Parse(HN[0]);
            int N = int.Parse(HN[1]);
            HN = Console.ReadLine().Split(' ');

            int ans = 0;

            for (int i = 0; i < N; i++)
            {
                ans += int.Parse(HN[i]);
            }

            Console.WriteLine(H <= ans ? "Yes" : "No");

            Console.Read();

        }
    }
}



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

const int maxn = 21, maxm = 1 << maxn;
int n, k, dp[maxn + 3][maxm + 3];
char s[maxm + 3];

int main() {
	scanf("%d %d", &n, &k);
	for (int i = 0; i <= n; i++) {
		scanf("%s", s);
		for (int j = 0; j < 1 << i; j++) {
			dp[i][1 << i | j] = s[j] ^ '0';
		}
	}
	for (int i = n; i; i--) {
		for (int j = i; j <= n; j++) {
			int b = 1 << j;
			for (int k = 0; k < b; k++) {
				int x = dp[i][k | b], p = -1, q = -1;
				for (int t = i; t; t--) {
					if (~k >> (t - 1) & 1) {
						p = t;
						break;
					}
				}
				for (int t = i; t; t--) {
					if (k >> (t - 1) & 1) {
						q = t;
						break;
					}
				}
				dp[0][(k | b) >> i] += x;
				if (p != -1) {
					dp[p - 1][(k & ((1 << (p - 1)) - 1)) | (((k >> i) << 1 | 0) << (p - 1)) | (b >> (i - p))] += x;
				}
				if (q != -1) {
					dp[q - 1][(k & ((1 << (q - 1)) - 1)) | (((k >> i) << 1 | 1) << (q - 1)) | (b >> (i - q))] += x;
				}
			}
		}
	}
	for (int i = n; i >= 0; i--) {
		for (int j = 1 << i; j < 1 << (i + 1); j++) {
			if (dp[0][j] >= k) {
				for (int t = i - 1; t >= 0; t--) {
					printf("%d", j >> t & 1);
				}
				puts("");
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 173440
import java.util.Scanner;
 
class Main {
     static int n, s;
     static int[] nums = {0,1,2,3,4,5,6,7,8,9};
     static int mm (int sum, int i, int cnt) {
        if (cnt == n) return sum == s ? 1 : 0;
        if (sum > s || i >= nums.length) return 0;
        return mm(sum + nums[i], i + 1, cnt + 1) +
               mm(sum, i + 1, cnt);}
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in); 
        while (true) {
            n = sc.nextInt();
            s = sc.nextInt();
            if (s == 0 && n == 0) break;
            System.out.println(mm(0,0,0));
        }
 
    }
 
}

Measured memory_bytes: 18060
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000


int main(){
	
	int N;
	cin>>N;
	
	int A = 0,C = 1,G = 2,T = 3;
	
	vector<vector<vector<vector<vector<int>>>>> dp(N+1,vector<vector<vector<vector<int>>>>(4,vector<vector<vector<int>>>(4,vector<vector<int>>(4,vector<int>(4,0)))));
	dp[0][T][T][T][T] = 1;
	
	for(int i=0;i<N;i++){
		for(int c1=0;c1<4;c1++){
			for(int c2=0;c2<4;c2++){
				for(int c3=0;c3<4;c3++){
					for(int c4=0;c4<4;c4++){
						if(c2==A&&c3==G&&c4==C)continue;
						if(c1==A&&c3==G&&c4==C)continue;
						if(c1==A&&c2==G&&c4==C)continue;
						if(c2==G&&c3==A&&c4==C)continue;
						if(c2==A&&c3==C&&c4==G)continue;
						for(int next=0;next<4;next++){
							dp[i+1][c2][c3][c4][next] = mod(dp[i+1][c2][c3][c4][next] + dp[i][c1][c2][c3][c4]);
						}
						
					}
				}
			}
		}
	}
	
	int ans = 0;
	
	for(int c1=0;c1<4;c1++){
		for(int c2=0;c2<4;c2++){
			for(int c3=0;c3<4;c3++){
				for(int c4=0;c4<4;c4++){
					if(c2==A&&c3==G&&c4==C)continue;
					if(c1==A&&c3==G&&c4==C)continue;
					if(c1==A&&c2==G&&c4==C)continue;
					if(c2==G&&c3==A&&c4==C)continue;
					if(c2==A&&c3==C&&c4==G)continue;
					
					ans = mod(ans + dp[N][c1][c2][c3][c4]);
					
				}
			}
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 640
from collections import defaultdict


def main():

    N = int(input())
    words = defaultdict(int)
    for _ in range(N):
        words[input()] += 1

    M = int(input())
    for _ in range(M):
        words[input()] -= 1

    words['len(word)>10'] = 0
    print(max(words.values()))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <cstdlib>
#include <utility>
#include <cmath>
using namespace std;
#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(), (x).end() 
#define ayacin ios::sync_with_stdio(false);
#define yukari 1000000000000000000LL
#define M_PI12 3.141592653
#define Parsee long double
#define reimu iterator 
#define mokou __builtin_popcount
#define __sum accumulate
#define rep(i,a,b) for(i=a;i<=b;i++)
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define ls rt<<1
#define rs rt<<1|1 
#define eps 1e-10  
#define zero(a) fabs(a)<eps  
#define x first
#define y second
using namespace std;
const int MAXN=1e5+5; 
char s[MAXN];
int main(){
	int m,n,i,j,k;
	scanf("%s",s+1);
	m=strlen(s+1);
	int ans=0;
	rep(i,2,m){
		if(s[i]!=s[i-1]) ans++;
	} 
	cout<<ans<<endl;
}



Measured memory_bytes: 384
//#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mod = 1e9 + 7;
const ll infll = 1e18 + 9;
const int infint = 1e9 + 7;
const int MAXN = 1e5 + 7;
const double eps = 1e-9;
const long double pi = 3.1415926535897932384626433832795;
const long double e = 2.71828182845904523536028747135266;
inline ll read()
{
    ll kr = 1, xs = 0;char ls;ls = getchar();
    while (!isdigit(ls)){
        if (!(ls ^ 45)) kr = -1;
        ls = getchar();
    }
    while (isdigit(ls)){
        xs = (xs << 1) + (xs << 3) + (ls ^ 48);ls = getchar();
    }return xs * kr;
}
// inline __int128 read128()
// {
//     __int128 kr=1,xs=0;char ls;ls=getchar();
//     while(!isdigit(ls)){
//         if(!(ls^45)) kr=-1;ls=getchar();
//     }
//     while(isdigit(ls)){
//         xs=(xs<<1)+(xs<<3)+(ls^48);ls=getchar();
//     }
//     return xs*kr;
// }
inline ull readull()
{
    ull xs = 0;char ls;ls = getchar();
    while (!isdigit(ls))ls = getchar();
    while (isdigit(ls)){
        xs = (xs << 1) + (xs << 3) + (ls ^ 48);ls = getchar();
    }return xs;
}
inline void writeull(ull x)
{
    if (x < 0){
        x *= -1;putchar('-');
    }
    if (x >= 10) writeull(x / 10);
    putchar('0' + x % 10);
}
inline void write(ll x)
{
    if (x < 0){
        x *= -1;putchar('-');
    }
    if (x >= 10) write(x / 10);
    putchar('0' + x % 10);
}
// inline void write(__int128 x){
//     if(x<0){x*=-1;putchar('-');}
//     if(x>=10) write(x/10);
//     putchar('0'+x%10);
// }
///////////////////////////////////////////////////////////////////////////////////////
int main()
{
    int t=1;
    // t = read();
    while(t--){
        string a;
        cin >> a;
        if(a[a.size()-1]=='s') a.push_back('e'),a.push_back('s');
        else a.push_back('s');
        cout << a << endl;
    }
    return 0;
}

Measured memory_bytes: 3612
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int cnt = 0;
		int idx = -1;
		int n = sc.nextInt();
		String boad = sc.next();
		for(int i = 0; i < n; i++) {
			String old = sc.next();
			for(int k = 0; k < old.length(); k++) {
					if(idx == i) break;
						if(boad.charAt(0) == old.charAt(k)) {//1文字目が一致
							for(int a = k+1; a < old.length(); a++) {
								if(idx == i) break;
								if(boad.charAt(1) == old.charAt(a)) {//2文字目が一致
									int space = a-k;
									int at = 2;
										for(int c = a+space; c < old.length(); c += space) {
											if(boad.charAt(at) == old.charAt(c)) {
												if(at == boad.length()-1 && i != idx) {
													cnt++;
													idx = i;
													break;
												} 
												at++;
											} else {
												break;
											}
										}
								}
							}
						}		
				}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 20716
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#define io_init cin.tie(0);ios::sync_with_stdio(0);cout<<setprecision(10)
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

vector<ll> l;
void dfs(string num, int depth) {
	ll n = stoll(num);
	if (n > 3234566667LL || depth > 10)return;
	l.push_back(n);
	if (num.back() != '0')dfs((num + (char)(num.back() - 1)), depth + 1);
	dfs((num + num.back()), depth + 1);
	if (num.back() != '9')dfs((num + (char)(num.back() + 1)), depth + 1);
}
int main() {
	io_init;
	for (int i = 1; i < 10; i++)dfs(to_string(i), 1);
	sort(l.begin(), l.end());
	int K;
	cin >> K;
	cout << l[K-1] << endl;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int n,m,c,d;
int le=0;;
int l[33];
int main()
{
  cin>>n>>m;
  for(int i=0;i<n;i++)
  {
  	cin>>c;
  	for(int i=0;i<c;i++)
  	{
  	  cin>>d;
  	  l[d]++;
  	}
  }
  for(int i=1;i<=m;i++)
    if(l[i]==n)
      le++;
  cout<<le;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;

ll max_op(ll x, ll y){ return max(x, y); }
ll e(){ return 0; }

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

    const ll MAXVAL = 300000;
    segtree<ll, max_op, e> st(MAXVAL + 1);
    ll ans = 0;
    REP(i, n){
        ll ai;
        cin >> ai;
        const ll l = max(ai - k, 0LL);
        const ll r = min(ai + k + 1, MAXVAL + 1);
        ll tmp = 1 + st.prod(l, r);
        st.set(ai, max(st.get(ai), tmp));
        ans = max(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 13852
n=int(input())
mod=10**9+7

def kaijou(n):
  ans=1
  for i in range(1,n+1):
    ans*=i
    ans%=mod
  return ans%mod

k,t=divmod(n,3)
if n>=3:
  ans=(kaijou(t+k-1)*pow(kaijou(k-1),mod-2,mod)*pow(kaijou(t),mod-2,mod))
  bunpai=t
  for i in range(k-1,0,-1):
    bunpai+=3
    ans+=(kaijou(bunpai+i-1)*pow(kaijou(i-1),mod-2,mod)*pow(kaijou(bunpai),mod-2,mod))
    ans%=mod
  print(ans%mod)
else:
  print(0)

    

Measured memory_bytes: 9092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const ll INF = numeric_limits<ll>::max();
int main()
{
    int n, m; cin >> n >> m;
    vector<ll> ans(m);
    vector<vector<P>> py(n);
    int p, y;
    rep(i, m) {
        cin >> p >> y;--p;
        py[p].push_back(P(i, y));
    }
    rep(i, n) {
        if (py[i].size() > 0){
            sort(py[i].begin(), py[i].end(),
            [](const P& x, const P& y){return x.second < y.second;}
            );
        }
        rep(j, py[i].size()){
            // cout << i << j << endl;
            ans[py[i][j].first] = (i+1)*1000'000 + j+1;
        }
    }

    rep(i, m){
        printf("%012ld\n", ans[i]);
    }
    return 0;
}

Measured memory_bytes: 9536
// atcoder/abc145/E/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, t;
  while (cin >> n >> t) {
    vector<pair<int, int>> v(n);
    cin >> v;

    const int N = 3000 + 5;
    const int T = 3000 + 5;

    static int dp1[N][T];
    fill(&dp1[0][0], &dp1[N - 1][T - 1] + 1, -(1 << 29));
    dp1[0][0] = 0;
    for (int i = 0; i < v.size(); ++i) {
      for (int j = 0; j < t; ++j) {
        if (j + v[i].first < t) {
          setmax(dp1[i + 1][j + v[i].first], dp1[i][j] + v[i].second);
        }
        setmax(dp1[i + 1][j], dp1[i][j]);
      }
    }

    reverse(v.begin(), v.end());
    static int dp2[N][T];
    fill(&dp2[0][0], &dp2[N - 1][T - 1] + 1, -(1 << 29));
    dp2[0][0] = 0;
    for (int i = 0; i < v.size(); ++i) {
      for (int j = 0; j < t; ++j) {
        if (j + v[i].first < t) {
          setmax(dp2[i + 1][j + v[i].first], dp2[i][j] + v[i].second);
        }
        setmax(dp2[i + 1][j], dp2[i][j]);
      }
    }

    for (int i = 0; i < N; ++i) {
      for (int j = 1; j < t; ++j) {
        setmax(dp1[i][j], dp1[i][j - 1]);
      }
    }
    for (int i = 0; i < N; ++i) {
      for (int j = 1; j < t; ++j) {
        setmax(dp2[i][j], dp2[i][j - 1]);
      }
    }

    reverse(v.begin(), v.end());
    int mx = 0;
    static int x[T];
    for (int i = 0; i < v.size(); ++i) {
      for (int j = 0; j < t; ++j) {
        setmax(mx, dp1[i][j] + dp2[n - i - 1][t - j - 1] + v[i].second);
      }
    }
    cout << mx << endl;
  }

  return 0;
}


Measured memory_bytes: 70912
#include <iostream>
using namespace std;
int main(void){
    
    int a, b;
    cin >> a >> b;
    
    if(a == b){
        cout << "a == b" << endl;
    }
    else if(a > b){
        cout << "a > b" << endl;
    }
    else{
        cout << "a < b" << endl;
    }
    
}



Measured memory_bytes: 3084
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <list>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

const double PI  = 3.141592653589793238463;
const int INF = 1000000007;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

int solve(int k, int s){
    int res = 0;
    for(int x = 0; x <= k; x++){
        for(int y = 0; y <= k; y++){
            int z = s - x - y;
            if(0 <= z && z <= k){
                res++;
            }
        }
    }
    return res;
}

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

    int k, s;
    cin >> k >> s;

    cout << solve(k, s) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
//g++ -std=c++11 

using namespace std;

long long N, K;
vector<long long> A;

#define DIV 1000000007

long long kaidan[10000000];

void kaical(long long n){
	kaidan[0] = 1;
	for(long long i = 1; i < n; i++){
		kaidan[i] = kaidan[i-1] * i;
		kaidan[i] %= DIV;
	}
}

long long modpow(long long ori, long long po){
	long long res = 1;
	while(po > 0){
		if(po&1){
			res *= ori;
			res %= DIV;
		}
		ori *= ori;
		ori %= DIV;
		po >>= 1;
	}
	return res;
}

//nCk
long long combination(long long n, long long k){
	if(n == 0 && k == 0)return 1;
	if(n < k || n < 0)return 0;
	long long n_kai = kaidan[n];
	long long k_kai = kaidan[k];
	long long nmk_kai = kaidan[n-k];

	long long ans = n_kai * modpow(k_kai, DIV - 2);
	ans %= DIV;
	ans *= modpow(nmk_kai, DIV-2);
	ans %= DIV;
	return ans;
}


//equal or less
long long countLess(long long num) {
	long long start = -1;
	long long end = N;
	while(start + 1 < end) {
		long long mid = (start + end)/2;
		if(A[mid] < num) {
			start = mid;
		} else {
			end = mid;
		}
	}
	return start + 1;
}

//equal or large
long long countBig(long long num) {
	long long start = -1;
	long long end = N;
	while(start + 1 < end) {
		long long mid = (start + end)/2;
		if(A[mid] > num) {
			end = mid;
		} else {
			start = mid;
		}
	}
	return N - end;
}

map<long long, long long> memo;

int main(){
	cin >> N >> K;
	rep(i, N) {
		long long tmp;
		cin >> tmp;
		A.push_back(tmp);
		memo[tmp]++;
	}
	sort(A.begin(), A.end());

	long long ans = 0;
	kaical(N+5);

	for(auto item: memo) {
		long long num = item.first;
		long long same = item.second;

		long long less = countLess(num);


		//cout << " num = " << num << " same = " << same << endl;
		//cout << "less = " << less << endl;
		//同じのを何個使う?
		for(long long i = 1; i <= min(same, K); i++) {
		//	cout << " i = " << i << endl;
			long long tmp = num;

			tmp *= combination(same, i);
			tmp %= DIV;
			tmp *= combination(less, K - i);
			tmp %= DIV;
			//cout << "comb(" << same << ", " << i << ")" << endl;
			//cout << "comb(" << less << ", " << K-i << ")" << endl;

			ans += tmp; 
			ans += DIV;
			ans %= DIV;
		}

		long long bigger = countBig(num);
		//cout << "bigger = " << bigger << endl;
		for(long long i = 1; i <= min(same, K); i++) {
			//cout << " i = " << i << endl;
			long long tmp = num;

			tmp *= combination(same, i);
			tmp %= DIV;
			tmp *= combination(bigger, K - i);
			tmp %= DIV;
			//cout << "comb(" << same << ", " << i << ")" << endl;
			//cout << "comb(" << bigger << ", " << K-i << ")" << endl;

			ans -= tmp; 
			ans += DIV;
			ans %= DIV;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 10536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
ll a[maxn];
ll lcm ( int n , int m ) {
	return n / __gcd( n , m ) * m ;
}
ll nlcm ( ll *a , int n ) {
	if( n==1 ) return *a ;
	return lcm( a[n-1] , nlcm( a , n-1 ) );
}
int main(){
	int n;
	ll m;
	scanf("%d%lld",&n,&m);
	for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);a[i]=a[i]/2;
	}
	ll c=nlcm( a , n );
  for(int i=0;i<n;i++){
    ll g=a[i];
    if((c/g)%2) continue;
    puts("0");
    return 0;
  }
    printf("%lld\n",(m/c+1)/2);
	return 0;
}


Measured memory_bytes: 4096
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while(sc.hasNext()){
            String A=sc.next();
            String B=sc.next();
            System.out.println(longestCommonSubsequence(A,B));
        }
    }

    public static String longestCommonSubsequence(String A, String B) {
        int lenA=A.length();
        int lenB=B.length();
        int[][] dp=new int[lenA+1][lenB+1];
        int[][] back=new int[lenA+1][lenB+1];
        for (int i=1;i<=lenA;i++) {
            for (int j=1;j<=lenB;j++) {
                if (A.charAt(i-1)==B.charAt(j-1)) {
                    dp[i][j]=dp[i-1][j-1]+1;
                    back[i][j]=1; //左上
                }else if(dp[i-1][j]>dp[i][j-1]){
                    dp[i][j]=dp[i-1][j];
                    back[i][j]=2; //上
                }else{
                    dp[i][j]=dp[i][j-1];
                    back[i][j]=0; //左
                }
            }
        }
        int i=lenA,j=lenB;
        StringBuilder res=new StringBuilder();
        while(i>0 && j>0){
            if (back[i][j]==1) {
                i--;j--;
                res.append(A.charAt(i));
            }else if(back[i][j]==2){
                i--;
            }else{
                j--;
            }
        }
        return res.reverse().toString();
    }

}

Measured memory_bytes: 132172
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
using ll = long long;
const int INF = 1<<29;
const int MOD = 1e9+7;
const ll LINF = 1e18;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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 int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};

const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};

vector< vector<int> > Graph;
vector< int > value;





int main(int argc, const char * argv[]) {
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a,b; cin >> a >> b;
    if(2*b >= a) cout << 0 << endl;
    else cout << a - 2*b << endl;
   
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int r=n%10;
    if(r==2 || r==4 || r==5 || r==7 || r==9)
        cout<<"hon";
    else if(r==0 || r==1 || r==6 || r==8)
        cout<<"pon";
    else
        cout<<"bon";
    return 0;
}

Measured memory_bytes: 3636
using System;

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(" ");
        var N = int.Parse(input[0]);
        double X = int.Parse(input[1]);

        var min = Math.Pow(10, 5);
        var count = 0;
        for (var i = 0; i < N; i++)
        {
            var m = int.Parse(Console.ReadLine());
            if (m < min) min = m;
            X -= m;
            count++;
        }

        while (X >= min)
        {
            X -= min;
            count++;
        }
        
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 27740
import java.util.*;

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

		for (int i=0; i < 3; i++){
			list[i] = scan.nextInt();
		}

		int temp =0;
		temp = list[0];
		list[0] = list[1];
		list[1]  = temp;
		temp = list[0];
		list[0] = list[2];
		list[2] = temp;

		for (int i=0; i < 3; i++){
			if(i != 2)System.out.print(list[i] + " ");
			if(i == 2)System.out.print(list[i]);
		}
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <deque>
#include <numeric>
#include <sstream>
#include <iomanip>
using lint = long long;

int main()
{
    lint q;
    scanf("%lld", &q);

    std::set<lint> s;
    s.insert(2);
    s.insert(3);

    for (int i = 5; i < 1e5 + 2; ++i)
    {
        lint ok = 1;
        for (auto p : s)
        {
            if (p > sqrt(i) + 2)
                break;
            if (i % p == 0)
            {
                ok = 0;
                break;
            }
        }
        if (ok)
        {
            s.insert(i);
        }
    }

    std::vector<lint> good;

    for (auto p : s)
    {
        if (s.find((p + 1) / 2) != s.end() && p != 2)
        {
            good.push_back(p);
        }
    }

    std::vector<lint> lv(q);
    std::vector<lint> rv(q);

    for (int i = 0; i < q; ++i)
    {
        scanf("%lld", &lv[i]);
        scanf("%lld", &rv[i]);
    }

    for (int i = 0; i < q; ++i)
    {
        lint l, r;

        l = lv[i];
        r = rv[i];

        lint ans = 0;

        lint r_idx = std::upper_bound(good.begin(), good.end(), r) - good.begin();
        lint l_idx = std::lower_bound(good.begin(), good.end(), l) - good.begin();

        ans = r_idx - l_idx;
        std::cout << ans << "\n";
    }

    return 0;
}


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

using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i < (n); --i)
#define all(x) (x).begin(), (x).end()
#define gsort(x, n) sort((x), (x + n) greater<int>())
#define rv(s) reverse((s).begin(), (s).end())
#define setout(n, x) setw(n) << setfill(x)
#define Fixed(n) fixed << setprecision(n)
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1e9 + 7;

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

   int n;
   cin>>n;
   int sum=0;

   sum += (n/500) * 1000;
   n %= 500;
   sum += (n/5) * 5;
   cout<<sum<<'\n';
   return 0;
}

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


int main(){
    int64_t N,K,n;
    cin>>N>>K;
    if(N>K){
        N=N%K;
    }
    n=N;
    if(N>K){
        N=N-K;
    }
    else{
        N=K-N;
    }
    if(n<N){
        cout<<n<<endl;
    }
    else{
        cout<<N<<endl;
    }
}


Measured memory_bytes: 256