akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 605;
const LL MOD = 1610612741;
char s[maxn][maxn];
const LL MOD1 = 146527;
const LL MOD2 = 19260817;
LL sum1[maxn][maxn],sum2[maxn][maxn];
LL bas1[maxn],bas2[maxn];
int n;
int ans1,ans2;
int main(){
    scanf("%d",&n);
    for (int i=1;i<=n;i++){
        scanf("%s",&s[i][1]);
    }
    for (int i=1;i<=2*n;i++){
        for (int j=1;j<=2*n;j++){
            int ii = i>n?i-n:i;
            int jj = j>n?j-n:j;
            s[i][j] = s[ii][jj];
        }
    }
    bas1[0]=bas2[0]=1;
    for (int i=1;i<maxn;i++){
        bas1[i] = bas1[i-1]*MOD1%MOD;
        bas2[i] = bas2[i-1]*MOD2%MOD;
    }
    for (int i=1;i<=2*n;i++){
        for (int j=1;j<=2*n;j++){
            sum1[i][j] = sum1[i][j-1]*MOD1%MOD+s[i][j]-'a'+1;
            sum1[i][j]%=MOD;
        }
    }
    for (int i=1;i<=2*n;i++){
        for (int j=1;j<=2*n;j++){
            sum1[i][j] = sum1[i-1][j]*MOD2%MOD+sum1[i][j];
            sum1[i][j]%=MOD;
        }
    }

    for (int i=1;i<=2*n;i++){
        for (int j=1;j<=2*n;j++){
            sum2[i][j] = sum2[i][j-1]*MOD2%MOD+s[i][j]-'a'+1;
            sum2[i][j]%=MOD;
        }
    }
    for (int i=1;i<=2*n;i++){
        for (int j=1;j<=2*n;j++){
            sum2[i][j] = sum2[i-1][j]*MOD1%MOD+sum2[i][j];
            sum2[i][j]%=MOD;
        }
    }
    int ans =0;
    for (int i=0;i<n;i++){
        for (int j=0;j<n;j++){
            LL now = sum1[n+i][n+j];
            LL temp1 = sum1[i][n+j]*bas2[n]%MOD;
            LL temp2 = sum1[n+i][j]*bas1[n]%MOD;
            LL temp3 = sum1[i][j]*bas1[n]%MOD*bas2[n]%MOD;
            LL temp11 = (now-temp1-temp2+temp3+3*MOD)%MOD;
        //    cout<<tar<<" "<<temp<<endl;
            now = sum2[n+i][j+n];
            temp1 = sum2[i][n+j]*bas1[n]%MOD;
            temp2 = sum2[i+n][j]*bas2[n]%MOD;
            temp3 = sum2[i][j]*bas1[n]%MOD*bas2[n]%MOD;
            LL temp22 = (now-temp1-temp2+temp3+3*MOD)%MOD;
            if (temp11==temp22)ans++;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 6272
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

double N;
int n;
int a;
double ans;

int main() {
	cin >> N;
	for (int i = 0; i <= N; i++) {
		if (i % 2 == 1) {
			a++;
		}
	}
	ans = double(a / N);
	printf("%.6lf", ans);
	return 0;
}

Measured memory_bytes: 256
//pragma
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#define YOU using
#define DONT namespace
#define SAY std

YOU DONT SAY;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define REPP(i,a,b,d) for(int i=a;i<=b;i+=d)
#define REP(i,a,b) REPP(i,a,b,1)
#define REVV(i,a,b,d) for(int i=a;i>=b;i-=d)
#define REV(i,a,b) REVV(i,a,b,1)

#define FOR(i,a) for(int i=0; i<a; i++)
#define FORD(i,a) for(int i=(int)a-1; i>=0; i--)

#define pb push_back
#define F first
#define S second

const int OO = 1e9;
const ll INF = 1e18;

const int irand(int lo,int hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

const ll lrand(ll lo,ll hi){
	return ((double)rand()/(RAND_MAX + 1.0)) * (hi-lo+1) + lo;
}

#define getc getchar
template<typename T>
T getnum(){
	int sign = 1;
	T ret = 0;
	char c;

	do{
		c = getc();
	}while(c == ' ' || c == '\n');
	if(c == '-')sign = -1;
	else ret = c-'0';
	while(1){
		c = getc();
		if(c < '0' || c > '9')break;
		ret = 10*ret + c-'0';
	}
	return sign * ret;
}

inline void ini(int& x){
	x = getnum<int>();
}

inline void scani(int& x){
	scanf("%d",&x);
}

//end of macro

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #define endl '\n'
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(10);
    
    string str;
    cin>>str;
    for(int i=0; i<str.size(); i+=2)cout << str[i];
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 592
#include <stdio.h>
#define swap(type, x, y) do{ type t = x; x = y; y = t; }while(0)

void quick(int array[], int left, int right){
  int pl = left, pr = right, x = array[(left + right) / 2];
  do{
    while(array[pl] > x) pl++;
    while(array[pr] < x) pr--;
    if(pl <= pr){
      swap(int, array[pl], array[pr]);
      pl++; pr--;
    }
  }while(pl <= pr);
  if(pl < right) quick(array, pl, right);
  if(pr > left) quick(array, left, pr);
}

int main(){
  int n;  scanf("%d", &n);
  int a[102];
  for(int i=0; i<n; i++)
    scanf("%d", &a[i]);
  quick(a, 0, n-1);

  int alice = 0, bob = 0;
  for(int i=0; i<n; i++){
 
    if(i%2==1)
      bob += a[i];
    else
      alice += a[i];
  }
 
  printf("%d\n", alice-bob);
  return 0;
}
	
  


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main (){

    string S;
    string divide[4] = {"dream","dreamer","erase","eraser"};

    cin >> S;

    reverse(S.begin(),S.end());
    for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());

    bool can = true;
    for (int i = 0; i < S.size();) {
        bool can2 = false; // 4 個の文字列たちどれかで divide できるか
        for (int j = 0; j < 4; ++j) {
            string d = divide[j];
            if (S.substr(i, d.size()) == d) { // d で divide できるか
                can2 = true;
                i += d.size(); // divide できたら i を進める
            }
        }
        if (!can2) { // divide できなかったら
            can = false;
            break;
        }
    }

    if (can) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;

}

Measured memory_bytes: 512
r, g, b = map(int, input().split())
k = int(input())

def check(r, g, b):
    return g > r and b > g

cnt = 0
while g <= r:
    g *= 2
    cnt += 1
while b <= g:
    b *= 2
    cnt += 1

if cnt <= k:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61724
import java.util.*;
import java.io.*;

class Main {

	void solve () {

		int n = in.nextInt(), k = in.nextInt();
		char[] s = in.next().toCharArray();
		s[k-1] = Character.toLowerCase(s[k-1]);
		out.println(String.valueOf(s));
		
	}
	
	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);
	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

}

Measured memory_bytes: 21716
#include <iostream>
#include <cmath>

using namespace std;
int main(){
    string S,T;
    int i,C;
    cin >> S >> T;
    C = 0;
    for(i=0; i<S.size();i++){
        C += int(S[i] != T[i]);
    }
    cout << C;

    return 0;
}


Measured memory_bytes: 3856
N = int(input())
A,B = map(int,input().split())
P = list(map(int,input().split()))
A_list,B_list,C_list = list(),list(),list()

for i in range(len(P)):
	if P[i] <= A:
		A_list.append(P[i])
	elif A+1<=P[i] and P[i] <= B:
		B_list.append(P[i])
	else:
		C_list.append(P[i])
		
print(min(len(A_list),len(B_list),len(C_list)))

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>

using namespace std;

int main() {
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		int n;
		cin >> n;
		int z1, z2;
		int up, down;
		up = down = 0;
		for (int j = 0; j < n; j++) {
			cin >> z2;
			if (j == 0) {
			} else {
				if (z1 > z2) {
					down = max(down, z1-z2);
				} else {
					up = max(up, z2-z1);
				}
			}
			z1 = z2;
		}
		cout << up << ' ' << down << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
n = int(input())
G = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    G[a].append(b)
    G[b].append(a)

from collections import deque
que = deque()
start = 0
que.append((0,-1))
rG = [-1]*n
while que:
    cur, prev = que.popleft()
    rG[cur] = prev
    for to in G[cur]:
        if to != prev:
            que.append((to, cur))

ans = 0
for i in range(n):
    x = i
    y = rG[i]
    if y == -1:
        ans += (x+1)*(n-x)
    elif x < y:
        ans += (x+1)*(y-x)
    else:
        ans += (x-y)*(n-x)
print(ans)


Measured memory_bytes: 113044
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	int a, b, c;
	cin >> a >> b >> c;

	bool used[60][2];
	memset(used, 0, sizeof(used));

	int cnt = 0, ans = 0;
	bool flag = true;
	while(true) {
		if(cnt & 1) {
			ans += b;
			if(used[ans%60][1]) {
				flag = false;
				break;
			}
			used[ans%60][1] = true;
		} else {
			if(ans % 60 + a >= 60 && ans % 60 <= c) {
				ans += c - ans % 60;
				break;
			}
			else if(c >= ans % 60 && (ans + a) % 60 >= c) {
				ans += c - ans % 60;
				break;
			} else {
				ans += a;
				if(used[ans%60][0]) {
					flag = false;
					break;
				}
				used[ans%60][0] = true;
			}
		}
		cnt++;
	}

	if(flag) cout << ans << endl;
	else cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lld long double
#define vc vector
typedef pair<ll,ll>pairs;
int main() {
	// your code goes here
	std::ios::sync_with_stdio(false);
	ll t,n,i,j,k,l,c,f;
	f=INT_MAX;
	ll x;
	cin>>x>>n;
	vector<ll>a(201);
	c=x;
	i=1;
	while(i<=n)
	{
	    cin>>k;
	    a[k]++;
	    i++;
	}
	if(a[x]==0)
	{
	    cout<<x;
	    exit(0);
	}
	for(i=1;i<=100;i++)
	{
	    if(a[x-i]==0||(x-i)<0)
	    {
	        cout<<x-i;
	        break;
	    }
	    if(a[x+i]==0)
	    {
	        cout<<x+i;break;
	    }
	}
	return 0;
}


Measured memory_bytes: 3656
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
//#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M=1000000007;
const ll MM=998244353;
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";

 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  if(a<=0)return 0;
  a%=m;
  if(!b)return 1;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}

const ll N=1e5+5;



int main()
{ 

IOS;


ll n;cin>>n;

vl x(N);

ll mx=0;

for(int i=0;i<n;i++){
  ll d;cin>>d;
  if(!i&&d){
    cout<<0;
    return 0;
  }
  x[d]++;
  mx=max(mx,d);
}


if(x[0]!=1){
  cout<<0;
  return 0;
}

ll ans=1;

for(int i=1;i<=mx;i++){

ans=(ans*powM(x[i-1],x[i],MM))%MM;
if(!ans)break;
}

cout<<ans;

//end_routine();

return 0;
 
}


Measured memory_bytes: 4008
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a%2==1&&b%2==1)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	public void solve() throws IOException {
		int n = nextInt();
		int[][] mat = new int[n][n];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				mat[i][j] = nextInt();
			}
		}
		int[][][] sum = new int[n][n][n];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				sum[i][j][j] = mat[i][j];
				for(int k = j+1; k < n; k++){
					sum[i][j][k] = sum[i][j][k-1] + mat[i][k];
				}
			}
		}
	/*	for(int[][] x : sum){
			for(int[] y : x){
				for(int z : y){
					writer.print(z + " ");
				}
				writer.println();
			}
			writer.println();
		}*/
		long ans = Integer.MIN_VALUE;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				for(int k = j; k < n; k++){
					long tmp = 0;
					for(int l = i; l < n; l++){
						tmp += sum[l][j][k];
						ans = Math.max(ans, tmp);
		//				writer.println("sum[" + l + "][" + j + "][" + k + "] = " + sum[l][j][k]);
		//				writer.println(i + ", " + j + ", " + k + ", " + l + ", " + tmp);
					}
				}
			}
		}
		writer.println(ans);
	}

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

	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;

	public void run() throws IOException {
		try {
			reader = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
}

Measured memory_bytes: 28436
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c = LI()
    print(min(a+b,b+c,c+a))
    return

#B
def B():
    def check(s):
        x = len(s)
        if x % 2:
            return False
        if s[:x // 2] == s[x // 2:]:
            return True
    s = S()
    for i in range(1,len(s)):
        if check(s[: - i]):
            print(len(s) - i)
            return

#C
def C():
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    B()


Measured memory_bytes: 39152
macro_rules! scan {
    ($($var:ident : $t:ty),*) => {
        let stdin = std::io::stdin();
        let mut stdin = std::io::BufReader::new(stdin.lock());
        let mut s = String::new();
        let mut iter = read_one_line(&mut s, &mut stdin);
        $(
            let mut s = String::new();
            let next = iter.next();
            let x = match next {
                Some(a) => {a},
                None => {
                    
                    iter = read_one_line(&mut s, &mut stdin);
                    iter.next().unwrap()
                }
            };
            let res = x.parse().unwrap();
            #[allow(unused_mut)]
            let mut $var:$t = res;
        )*
    };
}

fn read_one_line<'a>(s:&'a mut String, stdin: &mut std::io::BufReader<std::io::StdinLock>) ->  std::str::SplitWhitespace<'a>{
    use std::io::BufRead;
    s.clear();
    stdin.read_line(s).unwrap();
    let ret = s.split_whitespace();
    ret
}


fn main() {
    scan!(s:String, t:String);
    println!("{}", if &s[..] == &t[..t.len()-1] {
        "Yes"
    } else {
        "No"
    });
}

Measured memory_bytes: 2156
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var st = Reads();
            var ab = ReadInts();
            var u = Read();

            if (u == st[0])
            {
                WriteLine(ab[0] - 1 + " " + ab[1]);
            }
            else
            {
                WriteLine(ab[0] + " " + (ab[1] - 1));
            }
        }
        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13140
n=int(raw_input())

amin = 9999999999
amin_b = None
amax = -1
amax_b = None

for i in xrange(n):
  a,b = map(int, raw_input().split())
  if a < amin:
    amin = a
    amin_b = b
  if a > amax:
    amax = a
    amax_b = b

print amax + amax_b

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

using namespace std;

int main(void){
    int N;
    cin>>N;
    vector<string> s(N);
    for(int i=0;i<N;i++){
        cin>>s[i];
    }
    long long ans=0;
    for(int i=0;i<N;i++){
        sort(s[i].begin(),s[i].end());
    }
    map<string,long long> dict;
    for(int i=0;i<N;i++){
        dict[s[i]]++;
    }
    for(auto x:dict){
        ans+=(x.second)*(x.second-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 18176
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(A, P):
    return ((A*3)+P) // 2


def main():
    A, P = read_int_n()
    print(slv(A, P))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7996
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <ctype.h>
using namespace std;

typedef long long ll;

int dx[4] = { 0, -1, 1, 0 };
int dy[4] = { -1, 0, 0, 1 };

int m[1010];

int main() {
  int a, b;
  cin >> a >> b;

  auto getDigit = [](int num) {
    int res = 0;
    while (num != 0) {
      num /= 10;
      ++res;
    }
    return res;
  };

  int num = a * pow(10, getDigit(b)) + b;

  if (sqrt(num) - (int)sqrt(num) == 0.0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

int main()
{
  int sum_taro,sum_hanako;
  int card_taro[100],card_hanako[100];
  short n,m;
  short i,j;
  int difference_sum;
  char k;
  int answer_taro,answer_hanako,answer_sum;
  short a = -1;

  while(1){
    sum_taro = 0;
    sum_hanako = 0;
    k = 0;
    scanf("%hd %hd",&n,&m);

    if(n == 0 && m == 0){
      break;
    }

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

    for(i = 0;i < m;i++){
      scanf("%d",&card_hanako[i]);
      sum_hanako = sum_hanako + card_hanako[i];
    }

    if(sum_taro >= sum_hanako){
      difference_sum = sum_taro - sum_hanako;

      for(i = 0;i < n;i++){
        for(j = 0;j < m;j++){
          if(difference_sum % 2 == 0 && difference_sum/2 == card_taro[i] - card_hanako[j]){
            if(k == 0){
              answer_sum = card_taro[i] + card_hanako[j];
              answer_taro = card_taro[i];
              answer_hanako = card_hanako[j];
              k = 1;
            }
            else{
              if(answer_sum > card_taro[i] + card_hanako[j]){
                answer_sum = card_taro[i] + card_hanako[j];
                answer_taro = card_taro[i];
                answer_hanako = card_hanako[j];
              }
            }
          }
        }
      }
    }
    else{
      difference_sum = sum_hanako - sum_taro;

      for(i = 0;i < m;i++){
        for(j = 0;j < n;j++){
          if(difference_sum % 2 == 0 && difference_sum/2 == card_hanako[i] - card_taro[j]){
            if(k == 0){
              answer_sum = card_taro[j] + card_hanako[i];
              answer_taro = card_taro[j];
              answer_hanako = card_hanako[i];
              k = 1;
            }
            else{
              if(answer_sum > card_taro[j] + card_hanako[i]){
                answer_sum = card_taro[j] + card_hanako[i];
                answer_taro = card_taro[j];
                answer_hanako = card_hanako[i];
              }
            }
          }
        }
      }
    }

    if(k == 0){
      printf("%hd\n",a);
    }
    else{
      printf("%d %d\n",answer_taro,answer_hanako);
    }
  }

  return 0;
}

Measured memory_bytes: 600
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($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)*}
    };
}
 
#[allow(unused_macros)]
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)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
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<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n: usize,
        q: usize,
        edge: [(usize, usize); n-1],
        op: [(usize, usize); q]
    }

    let mut info = vec![0; n+1];
    let mut arr = vec![0; n+1]; 

    for e in &edge {
        info[e.1] = e.0;
    }

    //ops situ
    for e in &op {
        arr[e.0] = arr[e.0] + e.1;
    }

    for i in 1..n+1 {
        let mut t = arr[i];
        t = t +  arr[info[i]];       
        print!("{} ", t);
        arr[i] = t;
    }

    println!("");


}


Measured memory_bytes: 18684
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
long double PI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998626034825342117;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
void dfs() {

}
int main() {
    cout << "Yes" << endl;
    int N, M; cin >> N >> M;
    vector<int>A(M);
    vector<int>B(M);
    vector<vector<int>>G(N);
    rep(i, M) {
        cin >> A[i] >> B[i];
        G[A[i]-1].push_back(B[i]);
        G[B[i]-1].push_back(A[i]);
    }
    vector<int>GO(N, -1);
    queue<int>go;
    GO[0] = 0;
    go.push(0);
    while (!go.empty()) {
        int a = go.front();
        go.pop();
        for (int i : G[a]) {
            if (GO[i-1] != -1)continue;
            GO[i-1] = a+1;
            go.push(i-1);
        }
    }
    REP(i, N)cout << GO[i] << endl;
}

Measured memory_bytes: 11264
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    X, Y = input().split()
    if int(X, 16) == int(Y, 16):
        print('=')
    elif int(X, 16) < int(Y, 16):
        print('<')
    else:
        print('>')


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<stdio.h>
#include<math.h>
long long int g_c_d(long long int a,long long int b);
int main()
{
    long long int lcm,gcd,a,b,product;
    while(scanf("%lld %lld",&a,&b)==2)
    {
        gcd=g_c_d(a,b);
        product=a*b;
        lcm=product/gcd;
        printf("%lld %lld\n",gcd,lcm);
    }
    return(0);
}
long long int g_c_d(long long int a,long long int b)
{
    long long int r;
    if((a%b)==0)
    {
        return(b);
    }
    else
    {
        r=a%b;
        return(g_c_d(b,r));
    }
}

Measured memory_bytes: 1024
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, cos, radians, pi, sin, gcd
from operator import mul
from functools import reduce
from operator import mul


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod = 1000000007

n = I()
D = defaultdict(int)
A = []
B = []
F = []
pow2 = [1] * (n + 1)
for i in range(1, n + 1):
    pow2[i] = pow2[i - 1] * 2 % mod

ans = 1
cnt1 = 0
cnt2 = 0
cnt3 = 0
for i in range(n):
    a, b = LI()
    flg = 0
    if a * b < 0:
        flg = 1
    a = abs(a)
    b = abs(b)
    g = gcd(a, b)
    if g:
        a = a // g
        b = b // g
    A += [a]
    B += [b]
    F += [flg]
    if a == 0 and b == 0:
        cnt3 += 1
    elif a == 0:
        cnt1 += 1
    elif b == 0:
        cnt2 += 1
    else:
        D[(flg, a, b)] += 1

visited = defaultdict(int)
for j in range(n):
    fi, ai, bi = F[j], A[j], B[j]
    if ai == 0 or bi == 0:
        continue
    if visited[(fi, ai, bi)]:
        continue
    visited[(fi, ai, bi)] = 1
    visited[(fi ^ 1, bi, ai)] = 1
    ans = ans * (pow2[D[(fi, ai, bi)]] + pow2[D[(fi ^ 1, bi, ai)]] - 1) % mod

print((ans * (pow2[cnt1] + pow2[cnt2] - 1) + cnt3 - 1) % mod)


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

using namespace std;


//adio amore
const int maxi =1e6+10;
#define pb push_back
#define pii pair<int,int>

int a[maxi];
string s, t;
int n;
vector<int> v[maxi];

int main()
{
    cin>>s;
    cin>>t;

    int n =  s.size();
    int m = t.size();
    int ans = m;

    for(int i = 0; i<n-m+1;i++){
       int cur = 0;
        for (int j = 0; j<m;j++)
         if (s[i + j] != t[j]) cur++;
         ans = min(ans, cur);
    }

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


Measured memory_bytes: 27072
from collections import Counter

n=int(input())
s=[input() for i in range(n)]

ss=Counter(s[0])

for i in range(1,n):
    check=Counter(s[i])
    
    for key,value in ss.items():
        ss[key]=min(value,check[key])
ans=[]
for key,value in ss.items():
    ans+=[key]*value
ans.sort()
print(''.join(ans))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
  fio;
  int a[5];
  int ans;
  for(int i=0;i<5;i++)
  {
    cin>>a[i];
    if(a[i]==0)
    {
     ans=i+1;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    vector<int> A(100000);
    vector<int> B(N);
    for(int i=0; i<N; i++) cin >> B[i];

    for(int a : B) {
        if(a-1 >= 0) A[a-1]++;
        A[a]++;
        if(a+1 <= N) A[a+1]++;
    }
    sort(A.begin(), A.end());
    cout << A[99999] << endl;
}

Measured memory_bytes: 4028
li = [int(input()) for _ in range(5)]
 
s = 0
temp = 10
for i in range(5):
    if li[i]%10 != 0 and li[i]%10 < temp:
        temp = li[i]%10
        s = i
else:
    t = li.pop(s)
    
ans = 0

for i in li:
    if i%10 == 0:
        ans += i//10
    else:
        ans += 1 + i//10
        
print(ans * 10 + t)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;

    vector<bool> broken(n + 1);
    for (int i = 0; i < m; i++)
    {
        int a;
        cin >> a;
        broken[a] = true;
    }

    vector<int> dp(n + 2);
    const int mod = 1000000007;
    dp[n] = 1;
    for (int i = n-1; i >= 0; i--)
    {
        if (broken[i])
        {
            dp[i] = 0;
            continue;
        }
        dp[i] = (dp[i + 1] + dp[i + 2]) % mod;
    }

    cout << dp[0] << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef vector<vl> mt;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<string> vs;
typedef vector<vs> table;
typedef vector<vl> v2;
typedef vector<v2> v3;
typedef vector<v3> v4;


const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 50;

string s;

void error(){
  cout << "No" << endl;
  exit(0);
}

int main(){
  cin >> s;
  for(ll i = 0;i < s.size();i+=2){
    if(s[i] == 'L') error();
  }
  for(ll i = 1;i < s.size();i+=2){
    if(s[i] == 'R') error();
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 764
#include <iostream>
#include <vector>

int main()
{
	int n, k;
	std::cin >> n >> k;
	std::vector<int> a;
	for (int i = 0; i < n; i++)
	{
		int temp;
		std::cin >> temp;
		a.push_back(temp);
	}

	for (int i = k + 1; i <= n; i++)
	{
		if (a[i - 1] > a[i - k - 1])
			std::cout << "Yes" << std::endl;
		else
			std::cout << "No" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 4200
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>

#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>

using namespace std;

int main()
{
    int64_t N, K;
    std::cin >> N >> K;

    std::unordered_map<int64_t, int64_t> A;
    for (size_t i = 0; i < N; ++i) {
        int64_t t;
        std::cin >> t;
        A[t] = A[t] + 1;
    }

    std::vector<int64_t> B;
    for (auto& a: A) {
        B.push_back(a.second);
    }

    std::sort(std::begin(B), std::end(B),
              [](const auto& a, const auto& b) {
                  return a > b;
              });

    if (B.size() <= K) {
        std::cout << 0 << std::endl;
    }
    else {
        auto sum = std::accumulate(B.begin() + K, B.end(), 0LL, [](int total, auto v) {
                return total + v;
            });
        std::cout << sum << std::endl;
    }

    return 0;
}


Measured memory_bytes: 11592
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll n, k;
  cin >> n >> k;
  ll xx = (n/k);
  ll tt = xx + 1;
  cout << min(abs(n - (xx*k)), abs(n - (k*tt)));
  return 0;
} //good night.

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

using namespace std;

typedef long long int ll;

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

typedef pair<int,int> pair;

int main(){
    int a,b; cin >> a >> b;
    if(a>b){
        int tmp=a;
        a=b;
        b=tmp;
    }

    for(int i=0;i<b;i++) printf("%d",a);
    puts("");
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        ab[] sum = new ab[n];
        for (int i = 0; i < n; i++) {
            ab a = new ab(in.nl(),in.nl());
            sum[i] = a;
        }
        Arrays.sort(sum);
        long T = 0, A = 0;
        for (int i = 0; i < n; i++) {
            if(i%2==0){
                T += sum[i].a;
            }else{
                A += sum[i].b;
            }
        }
        out.println(T-A);
    }
    public static class ab implements Comparable<ab>{
        long a, b;
        public ab(long a, long b){
            this.a = a;
            this.b = b;
        }
        @Override
        public int compareTo(ab o) {
            return Long.compare(o.a+o.b,a+b);
        }
    }


    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

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

a_abs = [abs(i) for i in a]
a_abs_sum = sum(a_abs)
if 0 in a or len([i for i in a if i < 0]) % 2 == 0:
  print(a_abs_sum)
else:
  print(a_abs_sum - min(a_abs) * 2)

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

int main(){
	
	int N;
	vector<int> h;

	cin >> N;
	

	h.resize(N);

	vector<int> ans;
	ans.resize(N);
	
	for (int i = 0; i < N; i++){
		cin >> h[i];
	}

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

	for (int i = 0; i < N; i++){
		cout << ans[i] + 1 << " ";
	}
	return 0;
}

Measured memory_bytes: 1536
import java.util.Scanner;

public class Main {


    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] stones = new int[n];
        for (int i = 0; i < n; i++) {
            stones[i] = scanner.nextInt();
        }
        int[] dp = new int[n];
        int[] cal = new int[n];
        System.out.println(minInjured(stones, n - 1, dp, cal, k));
    }

    public static int minInjured(int[] stones, int n, int[] dp, int[] cal, int k) {

        if (n == 0) {
            return 0;
        }

        if (n == 1) {
            return Math.abs(stones[1] - stones[0]);
        }

        if (cal[n] == 1) {
            return dp[n];
        }

        for (int i = 1; i <= k; i++) {
            if (n - i >= 0 && cal[n - i] != 1) {
                dp[n - i] = minInjured(stones, n - i, dp, cal, k);
                cal[n - i] = 1;
            }
        }

        int min = Integer.MAX_VALUE;
        for (int i = 1; i <= k; i++) {
            if (n - i >= 0) {
                min = Math.min(dp[n - i] + Math.abs(stones[n] - stones[n - i]), min);
            }
        }
        dp[n] = min;

        return dp[n];
    }
}


Measured memory_bytes: 64708
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	int n, T[10001];

	while(cin >> n, n)
	{
		ll ans = 0;

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

		sort(T, T+n);

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

		cout << ans << endl;
	}
}

Measured memory_bytes: 1208
from sys import stdin
S=(stdin.readline().rstrip())
T=(stdin.readline().rstrip())
if S == T:
    print("Yes")

else:
    flag=0
    moji=S
    for s in reversed(S):
        moji=s+moji[:-1]
        if moji == T:
            print("Yes")
            flag=1
            break
    if flag==0:
        print("No")

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

int main() {
  // Nの入力
  int N,R;
  cin >> N >> R;

  int inner;


  if(N>=10){
    inner = R;
  } else {
    inner = R + (100 * (10-N));
  }

  cout << inner << endl;

}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int t = Integer.parseInt(sc.next());
        Integer[] a = new Integer[t];
        Arrays.setAll(a, i -> Integer.parseInt(sc.next()));
        sc.close();

        // 主処理
        int max = Arrays.stream(a).mapToInt(i -> i).max().orElse(0);
        int sum = Arrays.stream(a).mapToInt(i -> i).sum();
        int result = Math.max(0, max - (sum - max + 1));

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 35948
program ABC149C
    implicit none
    integer(8)::X,i,j,div_max,flg
    read(5,*)X

    if(X==2)then
        print'(i0)',2
    else
        do i=X,100003
            div_max=int(sqrt(real(i)))+1
            flg=0
            do j=2,div_max
                if(mod(i,j)==0)then
                    flg=1
                    exit
                end if
            end do

            if(flg==0)then
                print'(i0)',i
                exit
            end if
        end do
    end if

end program ABC149C

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

int main(){
  int N;
  cin >> N;
  ll l_0 = 2;
  ll l_1 = 1;
  ll tmp;
  if (N==1) cout << l_1 << endl;
  else {
    rep(i,N-1){
    tmp = l_0;
    l_0 = l_1;
    l_1 = l_0 + tmp;
  }
  cout << l_1 << endl;
  }
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        // 解
        int ans = 0;

        // 入力
        int[] inp1 = CSRD.RI(' ');
        int[] inp2 = CSRD.RI(' ');

        int[,] masu = new int[20, 20];

        // 処理
        for (int i = 0; i < inp1[0]; i++)
        {
            for (int j = 0; j < inp1[1]; j++)
            {
                if (i < inp2[0] || j < inp2[1])
                {
                    masu[i, j] = 1;
                }
            }
        }

        for (int i = 0; i < inp1[0]; i++)
        {
            for (int j = 0; j < inp1[1]; j++)
            {
                if (masu[i, j] == 0)
                {
                    ans++;
                }
            }
        }


        //出力
        CSWT.WS(ans);
    }
}

class CSRD
{
    // 文字列または数値の入力
    public static string RS() { return Console.ReadLine(); }
    public static int RI() { return int.Parse(Console.ReadLine()); }
    public static string[] RS(char sep) { return Console.ReadLine().Split(sep); }
    public static int[] RI(char sep) { return Console.ReadLine().Split(sep).Select(x => int.Parse(x)).ToArray(); }
}

class CSWT
{
    public static void WS(object param) { Console.WriteLine(param); }
}

Measured memory_bytes: 13396
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,c;
	scanf("%d",&a);
	if(a==1)
	printf("Hello World");
	else
	{
		scanf("%d%d",&b,&c);
		printf("%d",b+c);
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using Lint=long long;

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

    const int MAX=10000;
    vector<int> cnt(MAX+1);
    
    int N; cin>>N;
    for(int i=0;i<N;i++){
        int a; cin>>a;
        cnt[a]++;
    }

    vector<int> a;
    for(int i=0;i<=MAX;i++){
        while(cnt[i]--) a.push_back(i);
    }

    for(int i=0;i<N;i++){
        cout<<a[i]<<(i==N-1? '\n':' ');
    }
    return 0;
}


Measured memory_bytes: 11240
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){ 
    int N;
    cin >>N;
    vector<int> Q(N);
    vector<int> P(N);
    for(int i = 0;i < N;i++){
        cin >> P[i];
        Q[i] = i + 1;
    } 
    bool frag = 0;
    int cnt = 0;
    for(int i = 0;i < N;i++){
        if(P[i] != Q[i])cnt++;
    }
    if(cnt == 0 || cnt == 2) cout << "YES" << endl;
    else cout << "NO" << endl;
}   

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

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

	int *a = new int[N] ;
	for (int i = 0; i < N; i++)
		cin >> a[i] ;

	int cnt = 0 ;
	for (int i = 0; i < N; i++) {
		while (a[i]%2 == 0) { // even

			a[i] = a[i] / 2 ;
			cnt++ ;
//			cout <<"N=" << i << ", a[" << i << "] =" << a[i] << endl ;			
		}
	}

	cout << cnt << endl ;

	delete[] a ;

	return 0 ;
}

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

int N;

int main() {
    cin >> N;

    map<string, int> mp;
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        mp[s]++;
    }

    int mx = 0;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        int val = itr->second;
        mx = max(mx, val);
    } 

    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
        string key = itr->first; 
        int val = itr->second;
        if (val == mx) {
            cout << key << endl;
        }
    } 

    return 0;
}

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

int main() {
  int n,a = 0;
  cin >> n;

  for(int m = n ; m > 0 ; m /= 10){
    a += m % 10;
  }

  if(n % a == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;  
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,sum,n,m;
 
  while(scanf("%d %d",&a,&b)!=EOF){
    sum=a+b;
    m = 1;
    for ( n = 1; n <= 1000000; n = n*10){
      if(n<=sum && sum<n*10){printf("%d\n", m);}
      m = m+1;
    }
     
  }
  return 0;
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s, t;
	int N;
	cin>>N>>s>>t;
	int j = 0;
	// while(t[i] == s[N-1-i] && i < N)
	// 	i++;
	for(j = 0; s.substr(j) != t.substr(0, N-j) && j < N; j++){

	}
	cout<<N+j;

	return 0;
}

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

using namespace std;

int n;
int a[maxn], b[maxn];

int main(){
	scanf("%d", &n);
	for(int i = 1;i <= n;i++) scanf("%d", &a[i]);
	for(int i = 1;i <= n;i++) scanf("%d", &b[i]);
	reverse(b + 1, b + 1 + n);
	int l = n, r = 1;
	for(int i = 1;i <= n;i++){
		if(a[i] == b[i]) l = min(l, i), r = max(r, i);
	}
	for(int i = 1;i <= n && l <= r;i++){
		if(a[i] != a[l] && b[i] != a[l]) swap(b[i], b[l++]);
	}
	if(l <= r) return printf("No"), 0;
	puts("Yes");
	for(int i = 1;i <= n;i++) printf("%d ", b[i]);
}

Measured memory_bytes: 5324