akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main(){
    string alphabet = "abcdefghijklmnopqrstuvwxyz";
    char c; cin>>c;
    int i;
    for (int i=0;i<alphabet.size();i++){
        if (alphabet[i] == c){
            cout << alphabet[i+1] << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    a,b,c,x,y = LI()
    if a < b:
        a,b = b,a
        x,y = y,x
    r = 0
    if a > c*2:
        r += x * c*2
        y = max(y-x,0)
        x = 0
    if b > c*2:
        r += y * c*2
        y = 0
    if a+b > c*2:
        t = min(x,y)
        r += t * c*2
        x -= t
        y -= t
    r += a * x
    r += b * y


    return r



print(main())



Measured memory_bytes: 5460
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int a[4][4] = {};
bool b[4][4] = {};

bool judge(){
    if(b[1][1] == true and b[1][2] == true and b[1][3] == true) return true;
    if(b[2][1] == true and b[2][2] == true and b[2][3] == true) return true;
    if(b[3][1] == true and b[3][2] == true and b[3][3] == true) return true;
    if(b[1][1] == true and b[2][1] == true and b[3][1] == true) return true;
    if(b[1][2] == true and b[2][2] == true and b[3][2] == true) return true;
    if(b[1][3] == true and b[2][3] == true and b[3][3] == true) return true;
    if(b[1][1] == true and b[2][2] == true and b[3][3] == true) return true;
    if(b[1][3] == true and b[2][2] == true and b[3][1] == true) return true;
    return false;
}
int main() {
    
    for (int i=1;i<=3;i++){
        for (int j=1;j<=3;j++){
            cin >> a[i][j];
        }
    }
    int n;
    cin >> n;
    vector <int> v;
    for (int i=0;i<n;i++){
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    for (int x=0;x<n;x++){
        for (int i=1;i<=3;i++){
            for (int j=1;j<=3;j++){
                if(a[i][j] == v[x]){
                    b[i][j] = true;
                }
            }
        }
    }
    cout << (judge() ? "Yes" : "No") << endl;


}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(A: int, P: int):
    print(int((3*A+P)/2))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    P = int(next(tokens))  # type: int
    solve(A, P)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.lang.Math;
import java.util.Map;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int[] ar = fs.readArray(5);

        for (int i =0; i<5;i++) {
            if (ar[i] == 0) {
                System.out.println(i+1);
            }
        }






    }
    public static String convertFromBaseToBase(String str, int fromBase, int toBase) {
        return Integer.toString(Integer.parseInt(str, fromBase), toBase);
    }


    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");

        public String next() {
            while (!st.hasMoreElements())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

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

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

}



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

using namespace std;

#define int long long

signed main(){
	int n; cin >> n;
	
	int res = 1000000000000000;
	for(int i = 1; i * i <= n; ++i){
		if(n%i == 0){
			res = min(res, n/i+i-2);
		}
	}
	cout<<res<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <complex>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<double> VEC;
typedef vector<VEC> MAT;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define MT(a,b,c) MP(a, MP(b, c))
#define T1 first
#define T2 second.first
#define T3 second.second

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

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

int DFS(int xt, int yt, int k){
	if(k>10)return 15;
	int ret = 15;
	REP(i,4){
		int x = xt;
		int y = yt;
		if(board[y+dy[i]][x+dx[i]]==1)continue;
		int flag = 1;
		while(flag){
			switch(board[y+dy[i]][x+dx[i]]){
			case -1:
				flag = 0;
				break;
			case 0:
				x += dx[i];
				y += dy[i];
				break;
			case 1:
				board[y+dy[i]][x+dx[i]] = 0;
				ret = min(ret, DFS(x,y,k+1)+1);
				board[y+dy[i]][x+dx[i]] = 1;
				flag = 0;
				break;
			case 3:
				ret = 1;
				flag = 0;
				break;
			}
		}
	}
	return ret;
}

int main(){
	int w, h;
	int x, y;
	while(cin>>w>>h, w){
		REP(i,h)REP(j,w)cin >> board[i+1][j+1];
		REP(i,w+2)board[0][i]=board[h+1][i]=-1;
		REP(i,h+2)board[i][0]=board[i][w+1]=-1;
		REP(i,h)REP(j,w)if(board[i+1][j+1]==2)y=i+1, x=j+1;
		board[y][x]=0;
		int ret = DFS(x, y, 0);
		if(ret > 10)ret=-1;
		cout << ret<< endl;
	}
	return 0;
}

Measured memory_bytes: 1160
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for i in range(H):
        for j in range(W):
            if i==0 or j==0 or i==H-1 or j==W-1:
                print('#',end='')
            else:
                print('.',end='')
        print()
    print()


Measured memory_bytes: 7000
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define Size(x) ((int)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
long long MOD = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo,gyakugen
//mint,dijkstra

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll h,w;
        cin>>h>>w;
        vvc G(w,vc(h));
        ll ans=h*w;
        rep(i,h)rep(j,w){
            cin>>G[j][i];
            if(G[j][i]=='#')ans--;
        }
        queue<pll> q;
        q.push({0,0});
        vvl visit(w,vl(h,-1));
        visit[0][0]=1;
        while(!q.empty()){
            ll x=q.front().first;
            ll y=q.front().second;
            q.pop();
            rep(i,4){
                ll nx=x+dx[i];
                ll ny=y+dy[i];
                if(nx<0||ny<0||nx>=w||ny>=h)continue;
                if(G[nx][ny]=='#'||visit[nx][ny]!=-1)continue;
                q.push({nx,ny});
                visit[nx][ny]=visit[x][y]+1;
            }
        }
        if(visit[w-1][h-1]==-1){
            cout<<-1<<endl;
        }else{
            cout<<ans-visit[w-1][h-1]<<endl;
        }
    }

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		String[] s = saori.nextHayami().split("");
		int count = 0;
		for(int i = 0;i < s.length;i++){
			if(s[i].equals("o")){
				count++;
			}
		}
		System.out.println(700 + count*100);
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 24660
//start of jonathanirvings' template v3.0.3 (BETA)

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

vi a,b;
int n,x;

vector<pii> hitung(vi v)
{
  map<int,int> occur;
  REP(i,SIZE(v)) occur[v[i]]++;
  vii temp;
  for (pii x : occur) temp.pb(mp(SIZE(v) - x.se,x.fi));
  SORT(temp);
  temp.pb(mp(SIZE(v),INF));
  temp.pb(mp(SIZE(v),INF+1));
  return temp;
}

int main()
{
  scanf("%d",&n);
  REP(i,n)
  {
    scanf("%d",&x);
    if (i % 2 == 0) a.pb(x);
    else b.pb(x);
  }
  vector<pii> aa = hitung(a);
  vector<pii> bb = hitung(b);
  int risan = INF;
  REP(i,min(10,SIZE(aa))) REP(j,min(10,SIZE(bb)))
    if (aa[i].se != bb[j].se) MIN(risan,aa[i].fi + bb[j].fi);
  printf("%d\n",risan);
  return 0;
}











Measured memory_bytes: 4364
inputs = []
STDIN.gets.chomp.to_i.times do
  input = STDIN.gets.chomp
  inputs << input.split.map(&:to_i).sort.reverse.map{|i| i**2}
end

inputs.each do |i|
  result = i[0] == i[1] + i[2] ? 'YES' : 'NO'
  puts result
end

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

using namespace std;
string rot(string s){
    string ret = s;
    for(int i = 1, j = 0; i < (int)s.size(); i ++, j ++){
        ret[i] = s[j];
    }
    ret[0] = s[(int)s.size() - 1];
    return ret;
}
int main()
{
    ios_base::sync_with_stdio(false);
    string a, b;
    cin >> a >> b;
    map<string, bool> vis;
    while(true){
        if(a == b){
            return 0 * printf("Yes\n");
        }
        if(vis[a]){
            break;
        }
        vis[a] = true;
        a = rot(a);
    }
    printf("No\n");
    return 0;
}


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

void convlower(string &a){
	for (int i = 0; i < a.length(); i++){
		if ('A' <= a[i] && 'Z' >= a[i]){
			a[i] = a[i] + 'a' - 'A';
		}
	}
}

int main(){
	string w,t;
	cin >> w;
	convlower(w);
	int count = 0;
	while (cin >> t, "END_OF_TEXT" != t){
		convlower(t);
		count += (t == w);
	}
	cout << count << endl;
}


Measured memory_bytes: 3228
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
from itertools import product
def resolve():
    L,R=map(int,input().split())
    L=bin(L)[2:].zfill(60)
    R=bin(R)[2:].zfill(60)

    dp=[[[0]*2 for _ in range(2)] for _ in range(2)]
    dp[0][0][0]=1 # dp[msb][mt][lt]

    for l,r in zip(L,R):
        l=int(l); r=int(r)
        ndp=[[[0]*2 for _ in range(2)] for _ in range(2)]
        for msb,mt,lt,x,y in product(range(2),repeat=5):
            if((not msb) and (x!=y)): continue
            if((not mt) and l>x): continue
            if((not lt) and y>r): continue
            if(x>y): continue
            ndp[max(msb,x*y==1)][max(mt,l<x)][max(lt,y<r)]+=dp[msb][mt][lt]
            ndp[max(msb,x*y==1)][max(mt,l<x)][max(lt,y<r)]%=MOD
        dp=ndp

    print(sum(dp[msb][mt][lt] for msb,mt,lt in product(range(2),repeat=3))%MOD)
resolve()

Measured memory_bytes: 39536
from sys import stdin
import fractions
N,M = [int(x) for x in stdin.readline().rstrip().split()]
S = (stdin.readline().rstrip())
T = (stdin.readline().rstrip())
g = fractions.gcd(N,M)
def lcm(a, b):
    return a * b / fractions.gcd(a, b)
flag = True
for i in range(g):
    if S[(i*N)//g] != T[(i*M)//g]:
        flag = False
        break
if flag:
    print(int(lcm(N,M)))
else:
    print(-1)

Measured memory_bytes: 5432
import java.util.Scanner;

class Main{

	public static void main(String[] args) {


		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int data[] = new int[x/2];
		int i= 2;
		int count = 0;
		
		if(x == 1){
			System.out.println(x);
		}else{

			while(i < data.length){
				int z = i;
				while(z <= x){
					z *= i;

				}
				z /= i;
				data[count] = z;
				i++;
				count++;
			}
			int max = 0;
			for(int j = 0;j < data.length;j++){
				max = Math.max(max, data[j]);	
			}

			System.out.println(max);




		}
	}





}






Measured memory_bytes: 21588
void main() {
	auto N = readln.chomp.to!int;
	dchar last;
	string[] m;
	foreach(i; 0..N) {
		auto S = readln.chomp;
		if(i==0) {
			m ~= S;
			last = S.back;
			continue;
		}
		if(last == S[0]) {
			last = S.back;
		} else {
			writeln("No");
			return;
		}
		foreach(j; m) {
			if(S == j) {
				writeln("No");
				return;
			}
		}
		m ~= S;
	}
	writeln("Yes");
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 380
N,K = map(int, input().split())
K2 = 2*K

A = [[ 0 for _ in range(K2) ] for _ in range(K2)]
for _ in range(N):
  x,y,c = input().split()
  x,y = int(x) % (K2), int(y) % (K2)
  if c == 'W':
    y = (y+K) % (K2)
  #if y >= K:
  #  x,y = (x+K) %K2, y-K
  A[x][y] += 1

for i in range(K2):
  A[i] = A[i]  + A[i][:K-1]
  
for i in range(K-1):
  A.append(A[i])
  
#for a in A:
#  print(a)


B = [[ 0 for _ in range(K2+K) ] for _ in range(K2+K)]
for i in range(K2+K-1):
  for j in range(K2+K-1):
    B[i+1][j+1] = B[i+1][j] + B[i][j+1] - B[i][j] + A[i][j]
    
ans = 0
for i in range(K):
  for j in range(K):
    # (i,j)(i+K-1)(j+K-1) , (i+K,j+K), (i+2k-1)(j+2k-1)
    wk = 0
    wk += B[i+K][j+K] - B[i][j+K] - B[i+K][j] + B[i][j]
    wk += B[i+K2][j+K2] - B[i+K][j+K2] - B[i+K2][j+K] + B[i+K][j+K]
    #print(i,i+K,i+K2)
    ans = max(wk,N-wk,ans) #N-wkは白黒反転させたとき
#for b in B:
#  print(b)
  
print(ans)

Measured memory_bytes: 229964
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<chrono>
//#include<boost/multiprecision/cpp_int.hpp>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define SZ(X) ((int64_t)((X).size()))
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define intmax (std::numeric_limits<int64_t>::max() / 4)
#define doublemax (std::numeric_limits<double>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);




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

	int N, M;
	cin >> N >> M;
	vector<int>road(N, 0);
	rep(i, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		road[a]++;
		road[b]++;
	}
	rep(i, N)cout << road[i] << endl;
	

	return 0;
}

Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ns()
    val ans = (N.toCharArray map {
      case '1' => '9'
      case '9' => '1'
      case c => c
    }).mkString
    out.println(ans)
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    rep(as.length)(i => s += as(i))
    s
  }
}

Measured memory_bytes: 25420
import java.util.Scanner;

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

		int large = a * b;
		int length = (a + b) * 2;

		System.out.println(large + " " + length);
	}
}

Measured memory_bytes: 26116
def f(n, k):
    md = 10 ** 9 + 7
    if k % 2:
        print(0)
        exit()
    k //= 2
    dp = [[[0] * (n + 2) for _ in range(n ** 2)] for __ in range(n + 1)]
    dp[0][0][0] = 1
    for i in range(1, n + 1):
        dpi1 = dp[i - 1]
        for j in range(i + 1):
            for s in range(j, k + 1):
                dpi1sj = dpi1[s - j]
                if j:
                    # 両方保留、片側、水平、両方上
                    dp[i][s][j] = (dpi1sj[j] * (j * 2 + 1) + dpi1sj[j + 1] * (j + 1) ** 2 + dpi1sj[j - 1]) % md
                else:
                    # 片側、水平、両方上
                    dp[i][s][j] = (dpi1sj[j] * (j * 2 + 1) + dpi1sj[j + 1] * (j + 1) ** 2) % md
    print(dp[n][k][0])

n, k = map(int, input().split())
f(n, k)


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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template<typename... Args> void rd(Args&... args) {((cin >> args), ...);}
template<typename... Args> void wr(Args... args) { ((cout << args << " "), ...); cout<<endl;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int ans=INF;
    int n,m,x;
    cin>>n>>m>>x;
    vector<vector<int>> a(n,vector<int>(m+1));
    for(auto& v:a) for(auto& it:v) cin>>it;
    for(int i=0;i<(1<<n);i++){
        vector<int> sum(m+1);
        int money=0;
        forn(j,n){
            if(i>>j&1){
                for1(k,m) sum[k]+=a[j][k];
                money+=a[j][0];
            }
        }
        int flag=0;
        for1(j,m) if(sum[j]<x){
            flag=1;
            break;
        }
        if(flag==0) ans=min(ans,money);
    }
    cout<<(ans==INF?-1:ans);
    return 0;
}



Measured memory_bytes: 3664
#include<iostream>
#include<deque>

using namespace std;


int card[201];
int sub1[201];
int sub2[201];

int n, m;

void cut(int k);
void suffle(void);

int main()
{
	cin >> n;
	cin >> m;
	
	deque<int> step(m);
	
	for(int i = 0; i < m; i++){
		cin >> step[i];
	}
	
	for(int i = 0; i < 2*n; i++){		//ツカツーツドツ渉可甘コツ可サ
		card[i] = i+1;
	}
	
	for(int i = 0; i < m; i++){
		if(step[i] == 0){
			suffle();
		}
		else{
			cut(step[i]);
		}
	}
	
	for(int i = 0; i < 2*n; i++){
		cout << card[i] << endl;
	}
}

void cut(int k){
	int i;
	int temp;
	
	for(i = 0; i < k; i++){
		sub1[i] = card[i];
	}
	temp = i;
	
	for(int j = 0;j < 2*n; j++){
		sub2[j] = card[temp];
		temp++;
	}
	
	for(i = 0;i < 2*n-k; i++){
		card[i] = sub2[i];
	}
	for(int j = 0; i < 2*n; i++){
		card[i] = sub1[j];
		j++;
	}
}

void suffle(void){
	int i, j = 0;
	
	for(i = 0; i < n; i++){
		sub1[i] = card[i];
	}
	
	for(;i < 2*n; i++){
		sub2[j] = card[i];
		j++;
	}
	j = 0;
	for(int i = 0; i < 2*n; i+=2){
		card[i] = sub1[j];
		j++;
	}
	j = 0;
	for(int i = 1; i < 2*n; i+=2){
		card[i] = sub2[j];
		j++;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, l, r;
  int x = 0;
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> l >> r;
    x+=r-l+1;
  }
  cout << x << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct union_find {
  std::vector<int> rank, par;
  int v_size;
  union_find() {}

  // 初期化
  union_find(int n) {
    v_size = n;
    rank.resize(n, 0);
    par.resize(n);
    for(int i=0;i<n;i++) {
      par[i] = i;
    }
  }

  // 木の根を求める
  int find(int x) {
    if(par[x] == x) {
      return x;
    } else {
      return par[x] = find(par[x]);
    }
  }

  // xとyの属する集合を併合
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;

    if(rank[x] < rank[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if(rank[x] == rank[y]) rank[x]++;
    }
  }

  // xとyが同じ集合に属するか否か
  bool same(int x, int y) {
    return find(x) == find(y);
  }

  // グループの個数を数える
  int count() {
    std::set<int> st;
    for(int i=0;i<v_size;i++) {
      st.insert(find(i));
    }
    return st.size();
  }

};
struct edge { int u, v, cost; };
bool comp(const edge& e1, const edge& e2) {
  return e1.cost < e2.cost;
}

const int MAX_E = 100010;
//edge es[MAX_E];
vector<edge> es;
ll V, E;

ll kruskal() {
  std::sort(es.begin(), es.end(), comp);
  union_find uf(V);
  ll res = 0;
  for(int i=0;i<E;i++) {
    edge e = es[i];
    if(!uf.same(e.u, e.v)) {
      uf.unite(e.u, e.v);
      res += e.cost;
    }
  }
  return res;
}

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

  vector<pair<ll, ll> > x(N), y(N);
  for(int i=0;i<N;i++) {
    ll xi, yi;
    cin >> xi >> yi;
    x[i] = make_pair(xi, i);
    y[i] = make_pair(yi, i);
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());

  for(int i=0;i<N-1;i++) {
    edge ex;
    ex.u = x[i].second;
    ex.v = x[i+1].second;
    ex.cost = abs(x[i].first-x[i+1].first);
    es.push_back(ex);

    edge ey;
    ey.u = y[i].second;
    ey.v = y[i+1].second;
    ey.cost = abs(y[i].first-y[i+1].first);
    es.push_back(ey);
  }

  V = N;
  E = es.size();
  ll ans = kruskal();
  cout << ans << endl;
}


Measured memory_bytes: 8180
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
typedef long long int ll;
using namespace std;
using Graph = vector<vector<int> >;

int A(int val){
    return 2*val;
}

int B(int val,int K){
    return val+K;
}

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N,K;
cin>>N>>K;
int val=1;
rep(i,N){
    int val_A=A(val);
    int val_B=B(val,K);

    if(val_A>val_B) val=val_B;
    else val=val_A;
}
cout<<val<<endl;

//system("pause");
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N, x = 0,p = 0,q = 0,r = 0;//xは内部のAB pはB.....A qはB...... rは.....A
  cin >>N;
//全ての文字列を分類する
  for(int i=0;i<N;i++){
    string s;
    cin >>s;
    int size;
    size = s.size();
    for(int t=0;t+2<size;t++){
        if(s.at(t)=='A'){
          if(s.at(t+1)=='B'){
          x++;
          }
        }
     }
     if(s.at(0)=='B'){
        if(s.at(size-1)=='A'){
          p++;
        }else{
          q++;
        }
      }else{
        if(s.at(size-1)=='A'){
          r++;
        }
      }
  }
    
//以下数える
  if(p==0){
    cout <<x+min(q,r) <<endl;  
  }else{
    if(q+r==0){
      cout <<x+p-1 <<endl;
    }else{
      cout <<min(q,r)+p+x <<endl;
    }
  }
}

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

int main(){
	string s;
	cin>>s;
	int i=(s.length()-1)/2;
	while(1){
		if(s.substr(0,i)==s.substr(i,i)){
			cout<<i*2;
			break;
		}
		i--;
	}
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
vector<int> v[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
	{
		int a, b;
		cin >> a >> b;
		v[a].push_back(b);
	}
	int ans = 0;
	priority_queue<int> q;
	for (int i = 1; i <= m; i++)
	{
		for (auto& x : v[i])
			q.push(x);
		if (!q.empty())
		{
			ans += q.top();
			q.pop();
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7936
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int x;
  cin >> x;
  x/=200;
  cout << 10-x << endl;
  return 0;
}


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

using namespace std;

int N, M;
vector<vector<bool>> graph;
vector<bool> visited;

void dfs(int u) {
  visited[u] = true;
  for (int v = 0; v < N; v++) {
    if (!graph[u][v]) continue;
    if (visited[v]) continue;
    dfs(v);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  vector<int> A(M), B(M);
  graph.assign(N, vector<bool>(N, false));
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
    A[i]--, B[i]--;
    graph[A[i]][B[i]] = graph[B[i]][A[i]] = true;
  }
  int res = 0;
  for (int i = 0; i < M; i++) {
    graph[A[i]][B[i]] = graph[B[i]][A[i]] = false;
    visited.assign(N, false);
    dfs(0);
    for (int j = 0; j < N; j++) {
      if (!visited[j]) {
        res++;
        break;
      }
    }
    graph[A[i]][B[i]] = graph[B[i]][A[i]] = true;
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main(){
    int n,d,count = 0;

    cin >> n >> d;
    vector<vector<int>>v(n,vector<int>(d));

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

    for(int i = 0;i < n-1;i++){
        for(int j = i+1;j < n;j++){
            double sum = 0.0,check;
            for(int k = 0;k < d;k++){
                int x = v[i][k] - v[j][k];
                sum += x*x;
            }
            check = sqrt(sum);
            if(ceil(check) == floor(check)) count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,x,y;
	cin>>n>>m>>x>>y;
	int max33 = x,min33 = y;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		if(a>max33)
			max33 = a;
	} 
	for(int i=0;i<m;i++)
	{
	 	int a;
	 	cin>>a;
	 	if(a<min33)
			min33 = a;
	}
	if(min33>max33)
		cout<<"No War"<<endl;
	else
		cout<<"War"<<endl;
	return 0;
} 

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

using namespace std;

int main() {
	int A, B;
	cin >> A >> B;
	char s[100];
	cin >> s;
	string ans = "Yes";
	for (int i = 0; i < A; i++) {
		if (!('0' <= s[i] && s[i] <= '9')) {
			ans = "No";
		}
	}
	if (s[A] != '-'){
		ans = "No";
	}

	for (int i = A + 1; i <= A + B; i++) {
		if (!('0' <= s[i] && s[i] <= '9')) {
			ans = "No";
		}
	}

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

Measured memory_bytes: 256
from collections import deque
import math

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

n = int(input())
da = NextIntList()
da = sorted(da)
ans = 1
for i in range(n):
    ans *= da[i]
    if ans > 10**18:
        ans = -1
    elif ans < 0:
        ans = -1

if ans < 0:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 22240
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
long long n, a, b;
vector<long long> h;

bool f(long long k) {
    long long tmp = 0;
    for(int i = 0; i < n; ++i) {
        long long rem = h.at(i) - b*k;
        if(rem > 0) tmp += (rem+(a-b-1)) / (a-b);
    }
    return (tmp <= k);
}

long long binary_search(long long ok, long long ng) {
    while(abs(ok-ng) > 1) {
        long long mid = (ok+ng) / 2;
        if(f(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main() {
    cin >> n >> a >> b;
    h = vector<long long>(n);
    for(int i = 0; i < n; ++i) {
        cin >> h.at(i);
    }
    cout << binary_search(INF, -1) << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pl pair<ll,ll>
#define plp pair<ll,pl>
#define ppl pair<pl,ll>
#define pb push_back
#define pi acos(-1.0)
#define eb emplace_back
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define vl vector<ll>
#define mp make_pair
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define vll vector<vector<ll>>
#define all(a) a.begin(),a.end()
#define INF 1e9+5
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
using namespace std;
 
 //ll n,m;
ll MOD1=1000000007;
ll MOD2=998244353;
 
 
void yes() {cout<<"YES"<<endl;}
void no() {cout<<"NO"<<endl; }
/*
ll gcd(ll a,ll b);
ll lcm(ll a, ll b);
ll mod_exp(ll x,ll power,ll m);
ll ext_gcd(ll a,ll b,ll& x,ll& y);
void swap(ll& a,ll& b);
ll root(vector<ll>& arr,ll a);
void Union(vector<ll>& arr,ll a,ll b);
const ll N=32001;
vl fenwick(N,0);
void update(ll index,ll add);
ll sum(ll index);
ll find_kth_smalest(ll k);
ll find(ll k);
ll ETF(ll n);
*/
 
 
ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    return gcd(b%a, a);
}
 
ll lcm(ll a, ll b)
{
    return ( a*b/(gcd(a,b)));
}
 
//void sieve();
//vector<ll> factorise(1000+2,-1);
//vector<ll> prime(20005,1);
//vl fug;
//void p();
//void fact();
 
 
/*
void sieve()
{
    prime[0]=prime[1]=0;
    for(ll i=2;i<=sqrt(2005);i++)
    {
        if(prime[i]==1)
        {
            for(ll j=i*i;j<2005;j+=i)
                prime[j]=0;
        }
    }
}
*/

ll k;

ll min(ll a,ll b){ return a>=b? b: a;}

ll mincost(vl& height,ll i,vl& dp)
{
    if(i==height.size()-1)  return 0;
    
    if(dp[i]!=INT_MAX) return dp[i];
    
  //  ll temp=min(height.size()-1,i+k);
    
    for(ll j=1;j<=k;j++)
    {
        if(i+j<=height.size()-1)
           dp[i]=min(dp[i] , abs(height[i+j]-height[i]) + mincost(height, i+j, dp));
        else
            break;
    }
    
    return dp[i];
}


void solve()
{
    ll n; cin>>n>>k; vl height(n); rep(i,0,n-1) cin>>height[i];
    
    vl dp(n+1,INT_MAX);
    
    cout<<mincost(height, 0,dp)<<endl;
    
   
    
    
    
    
    
    
    
 
    
}
 
int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll tests=1;
    //cin>>tests;
    while (tests--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 11132
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 9999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
//#define int long long


using namespace std;


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




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

long long power_mod(long long x, long long n, long long m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return power_mod(x * x % m, n / 2, m);
	else
		return x * power_mod(x, n - 1, m) % m;
}

long long power(long long a, long long n) {//aのn乗を計算します。
	long long x = 1;
	while (n > 0) {//全てのbitが捨てられるまで。
		if (n & 1) {//1番右のbitが1のとき。
			x = x * a;
		}
		a = a * a;
		n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
	}
	return x;
}



long long nCr(long long n, long long r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	long long i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}



const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

bool arr[100000100];
vector<ll>sosuu;
void Eratosthenes() {
	ll N = 10000010;
	int c = 0;
	for (int i = 0; i < N; i++) {
		arr[i] = 1;
	}
	for (ll i = 2; i < sqrt(N); i++) {
		if (arr[i]) {
			for (ll j = 0; i * (j + 2) < N; j++) {
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for (ll i = 2; i < N; i++) {
		if (arr[i]) {
			sosuu.pb(i);
			//cout << sosuu[c] << " ";
			c++;
		}
	}
	//cout << endl;
	//cout << c << endl;
}

ll stoL(string s) {
	ll n = s.length();
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ans += power(10, n - i - 1)*(ll)(s[i] - '0');
	}
	return ans;
}



int main() {
	map<int,int>mp;
	REP(i, 3) {
		int a, b; cin >> a >> b;
		mp[a]++, mp[b]++;
	}
	for (auto x : mp) {
		if (x.second > 2) {
			print("NO");
			return 0;
		}
	}
	print("YES");
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
typedef long long LONG;
using namespace std;
int main()
{
	int N;
	cin >> N;
	vector<int>A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	LONG result = 0;
	int height = 0;
	for (int i = 0; i < N; i++) {
		if (height > A[i]) {
			result += (height - A[i]);
		}
		else {
			height = A[i];
		}
	}
	cout << result;
	return 0;
}

Measured memory_bytes: 4044
#include <iostream>
#include <algorithm>
 
using namespace std;
 
int main(){
    int n,m;
    int check;
 
    cin >> n >> m;
    check = n;
 
    while(m--){
	cin >> n;
	check = __gcd(n,check);
    }
 
    cout << (check == 1 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3088
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    A_sorted = sorted(A, reverse=True)
    A_max = A_sorted[0]
    A_semi_max = A_sorted[1]
    
    for i in range(N):
        if A[i] != A_max:
            print(A_max)
        else:
            print(A_semi_max)
main()

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

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int X = Integer.parseInt(sc.next());
        int Y = Integer.parseInt(sc.next());
        sc.close();

        out.printf("%d\n", X + (Y / 2));
        out.flush();
    }
}


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


using namespace std;


#ifdef zxc

#include "debug.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ll = int64_t;
using ld = long double;
const ld EPS = 1e-8;
const ll MOD = 998244353;
const ld PI = 3.141592653589793;
const int maxn = 1000001;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

int a[maxn];

signed main() {
#ifdef zxc
    mt19937 mt(std::chrono::high_resolution_clock::now().time_since_epoch().count());
    freopen("../kolya_input.txt", "r", stdin);
//    freopen("../kolya_output.txt", "w", stdout);
#else
    mt19937 mt(228);
//            freopen("", "r", stdin);
//        freopen("hack.out", "w", stdout);
#endif
    fast_io();
    cout.precision(10);
    cout << fixed;
    auto start = chrono::steady_clock::now();
///

    int n;
    cin >> n;
    string s;
    cin >> s;
    while (s.size()) {
        a[s.size()] = s.back();
        s.pop_back();
    }
    for (int i = 1; i < n; ++i) {
        a[i - 1] = abs(a[i] - a[i + 1]);
    }
    --n;
    int parity = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] & 1 && ((n - 1) & i) == i) {
            ++parity;
        }
    }
    if (parity & 1) {
        cout << 1;
        return 0;
    }
    for (int i = 0; i < n; ++i) {
        if (a[i] & 1) {
            cout << 0;
            return 0;
        }
    }
    parity = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] == 2 && ((n - 1) & i) == i) {
            ++parity;
        }
    }
    if (parity & 1) {
        cout << 2 << "\n";
    } else {
        cout << "0";
    }
///
    auto end = chrono::steady_clock::now();
    debug("time", chrono::duration_cast<chrono::milliseconds>(end - start).count() / 1000.0);
}



Measured memory_bytes: 5276