akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mxn= 5e5+5;
// check for forloop
// take input
// overflow
// intialize variable
// go for easy solution
#define mod 1000000007
ll INF = 1000000000000000005LL;
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int n,k;
int main(){
    cin>>n>>k;
    int even=0, odd=0; ll ans=0;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        if(x%2==0){
            even++;
        }
        else odd++; 
    }
    if(k==0){
        if(odd>2)
        ans=pow(2, odd+even-1);
        if(odd==2){
            ans=pow(2,even+1);
        }
        if(odd<2){
            if(even)
            ans=pow(2,even);
        }
        cout<<ans;
    }
    else {
        if(odd==0)cout<<0;
        else {
            ans=pow(2, odd+even-1);
            cout<<ans;
        }
    }

}



Measured memory_bytes: 3964
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int h, w, n;
	cin>>h>>w>>n;
	int big = max(h,w);
	int cnt = 0;
	int times = 0;
	while(cnt < n)
	{
		cnt += big;
		times++;
	}
	cout<<times<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(),greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
// sort(a.begin(), a.end(), std::greater<int>());

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    SORT_INV(a);
    int c = 0, b = 0;
    rep(i, n)
    {
        if (i % 2 == 0)
            c += a[i];
        else
            b += a[i];
    }
    cout << c - b << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n, k, c = map(int, input().split())
    s = [True if i == 'o' else False for i in input()]
    L = [0]*k
    R = [0]*k
    i = n-1
    now = k-1
    while 0 <= now:
        if s[i]:
            R[now] = i
            i -= c
            now -= 1
        i -= 1
    i = 0
    now = 0
    while now < k:
        if s[i]:
            L[now] = i
            if L[now] == R[now]:
                print(i+1)
            i += c
            now += 1
        i += 1

        



if __name__ == '__main__':
    main()
    

Measured memory_bytes: 26224
#include <iostream>
using namespace std;
int main() {
  int A,B,C,D;
	cin >> A >> B >> C >>D;
  int L = A+B;
  int R = C+D;
	 if(L < R )cout << "Right"  << endl;
  if(L == R ) cout << "Balanced" << endl;
 if(L > R)  cout <<"Left"  << endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e14;
using Graph = vector<vector<int>>;

signed main(){
  int N, M, L;
  cin >> N >> M >> L;

  vector<vector<int>> G(N, vector<int>(N, INF));
  for( int i = 0; i < M; i++ ){
    int A, B, C;
    cin >> A >> B >> C;
    A--;
    B--;
    G[A][B] = C;
    G[B][A] = C;
  }

  //各頂点間の最短距離を求める
  for( int i = 0; i < N; i++ ){
    for( int j = 0; j < N; j++ ){
      for( int k = 0; k < N; k++ ){
        G[j][k] = min(G[j][k], G[j][i]+G[i][k]);
      }
    }
  }

  //最短距離がL以下の頂点間に辺を張る
  vector<vector<int>> G2(N, vector<int>(N, INF));
  for( int i = 0; i < N; i++ ){
    for( int j = i+1; j < N; j++ ){
      if( G[i][j] <= L ){
        G2[i][j] = 1;
        G2[j][i] = 1;
      }
    }
  }

  for( int i = 0; i < N; i++ ){
    for( int j = 0; j < N; j++ ){
      for( int k = 0; k < N; k++ ){
        G2[j][k] = min(G2[j][k], G2[j][i]+G2[i][k]);
      }
    }
  }

  int Q;
  cin >> Q;
  for( int q = 0; q < Q; q++ ){
    int S, T;
    cin >> S >> T;
    S--;
    T--;
    if( G2[S][T] < INF ) cout << G2[S][T]-1 << endl;
    else cout << -1 << endl;
  }


}


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

using ll = long long;
static const int MAX = 1e5;
static const ll INF = 1e18;

// ダイクストラ法 O(ElogV)
vector<pair<ll, ll>> G[MAX];
vector<ll> dist; // 最短距離
// main関数からこれらを削除すること

void dijkstra(int n, int s) { // n:頂点数 s:開始頂点
  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
  // first:最短距離 second:頂点の番号
  dist = vector<ll>(n, INF); // 初期化
  dist[s] = 0; // 開始点の距離は0
  pq.push(make_pair(0, s));
  
  while (!pq.empty()) {
    pair<ll, ll> p = pq.top();
    pq.pop();
    ll v = p.second;
    if (dist[v] < p.first) continue;
    for (int i = 0; i < G[v].size(); i++) {
      pair<ll, ll> p2 = G[v][i];
      if (dist[p2.first] > dist[v] + p2.second) {
        dist[p2.first] = dist[v] + p2.second;
        pq.push(make_pair(dist[p2.first], p2.first));
      }
    }
  }
}

vector<pair<ll, ll>> H[MAX];
vector<ll> dist2;

void dijkstra2(int n, int s) { // n:頂点数 s:開始頂点
  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
  // first:最短距離 second:頂点の番号
  dist2 = vector<ll>(n, INF); // 初期化
  dist2[s] = 0; // 開始点の距離は0
  pq.push(make_pair(0, s));
  
  while (!pq.empty()) {
    pair<ll, ll> p = pq.top();
    pq.pop();
    ll v = p.second;
    if (dist2[v] < p.first) continue;
    for (int i = 0; i < H[v].size(); i++) {
      pair<ll, ll> p2 = H[v][i];
      if (dist2[p2.first] > dist2[v] + p2.second) {
        dist2[p2.first] = dist2[v] + p2.second;
        pq.push(make_pair(dist2[p2.first], p2.first));
      }
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  // 重み付き無向(有向)グラフの隣接リスト
  int n, m, s, t; // n:頂点数 m:辺数
  cin >> n >> m >> s >> t;
  s--;
  t--;
  
  // vector<pair<ll, ll>> G[n], H[n]; // G:頂点数がnのグラフを表す隣接リスト
  
  for (int i = 0; i < m; i++) {
    ll u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    G[u].emplace_back(make_pair(v, a));
    G[v].emplace_back(make_pair(u, a)); // 有向グラフではこの行をコメントアウト
    H[u].emplace_back(make_pair(v, b));
    H[v].emplace_back(make_pair(u, b)); // 有向グラフではこの行をコメントアウト
  }
  
  dijkstra(n, s);
  dijkstra2(n, t);
  
  vector<ll> total(n);
  for (int i = n - 1; i >= 0; i--) {
    total[i] = dist[i] + dist2[i];
    if (i < n - 1) total[i] = min(total[i], total[i + 1]);
  }
  
  for (int i = 0; i < n; i++) cout << (ll) 1e15 - total[i] << '\n';
}

Measured memory_bytes: 19144
import java.util.Scanner;

public class Main {
    static void printBox(int H, int W) {
        char[] pat = {'#','.'};
        for(int i=0;i<H;i++) {
            for(int j=0;j<W;j++) {
                System.out.print(pat[(i+j) % 2]);
            }
            System.out.println("");
        }
        System.out.println("");
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(true) {
            int H = in.nextInt();
            int W = in.nextInt();
            if(H == 0) break;
            printBox(H, W);
        }
    }
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    int a[n];
    for(int i = 0; i < n; ++i)
        cin >> a[i];
    bool dp[k+1] = {};
    for (int x = 1; x <= k; x++) {
        for (int i = 0; i < n && !dp[x]; ++i) {
            if(x-a[i] >= 0 && !dp[x-a[i]])
                dp[x] = true;
        }
    }
    cout << (dp[k] ? "First" : "Second");
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
 {
 	int n,i,m,f=0;
 	cin>>n;
 	if(n<10)
 		f=1;
 	else
 		
 			for(i=2;i<10;i++)
 			{
 				if(n%i==0&&n/i<10)
 					{
 						f=1;	
					 }
			 }
		 
		if(f==1)
			cout<<"Yes"<<endl;
		else
			cout<<"No"<<endl;
 }

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

int main(){
    int N,K,l,r,res=1e9;
    
    cin >> N >> K;
    vector<int> v(N);
    for (int i=0;i<N;i++){
        cin >> v[i];
        }
    
    for (int i=0;i<N+1-K;++i){
        l = v[i];
        r = v[i+K-1];

        res = min(res,r-l+min(abs(l),abs(r)));
    }


    
    cout << res << endl;

    //sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});

}


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

typedef long long ll;


int main() {
    int n; cin >> n;
    vector<int> fib(n+1,0);
    fib[0]=1;
    fib[1]=1;
    
    for(int i=2; i<=n; i++){
        fib[i] = fib[i-1] + fib[i-2];
    }
    
    cout << fib[n] << endl;
}



Measured memory_bytes: 3124
import sys
sys.setrecursionlimit(10**9)

ordA = ord('a')

N = int(input())

def dfs(i, sSt):
    if i == N:
#        print(Ss)
        ans = ''.join([chr(ordA+S) for S in Ss])
        anss.append(ans)
    else:
        for s in range(0, sSt+2):
            Ss[i] = s
            dfs(i+1, max(s, sSt))

anss = []
Ss = [0] * N
dfs(1, 0)

print('\n'.join(anss))


Measured memory_bytes: 15128
def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    S = sum(A)
    count = S
    ans = 0
    for i in A:
        count -= i
        ans += count*i
        if ans > 10**9+7:
            ans %= (10**9+7)
    print(ans)
resolve()

Measured memory_bytes: 31436
#include <bits/stdc++.h>
using namespace std;
int n,m;
priority_queue<int>q;
int main(){
	cin>>n>>m;
	for (int i=1;i<=n;i++){
		int x;cin>>x;q.push(x);
	}
	while (m--){
		int x=q.top();q.pop();
		x/=2;q.push(x);
	}
	long long ans=0;
	while (!q.empty()){
		int x=q.top();q.pop();
		ans+=x;
	}
	cout<<ans;
}

Measured memory_bytes: 892
h, w = map(int, input().split())

s = []
s.append(list(("." * (w+1))))

for i in range(h):
    s.append(list(("." + input()+ ".")))

s.append(list(("." * (w+1))))
flag = False

for i in range(h-2):
    for j in range(w-2):
        if s[i+1][j+1] == '#':
            if s[i+2][j+1] == s[i][j+1] == s[i+1][j+2] == s[i+1][j] == '.':
                flag = True
            else:
                pass
        else:
            pass


if flag:
    print("No")
else:
    print("Yes")


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

using namespace std;
priority_queue<pair<int,int> > pq[6];
int X,Y,Z;
int As[100008],Bs[100008],Cs[100008],pos[100008];
void update(int vl) {
	if(pos[vl]==0) {
		pq[0].push(make_pair(Bs[vl]-As[vl],vl));
		pq[1].push(make_pair(Cs[vl]-As[vl],vl));
	} else if(pos[vl]==1) {
		pq[2].push(make_pair(As[vl]-Bs[vl],vl));
		pq[3].push(make_pair(Cs[vl]-Bs[vl],vl));
	} else {
		pq[4].push(make_pair(As[vl]-Cs[vl],vl));
		pq[5].push(make_pair(Bs[vl]-Cs[vl],vl));
	}
}
int main() {
	cin >> X >> Y >> Z;
	for(int i=0;i<X+Y+Z;i++) cin >> As[i] >> Bs[i] >> Cs[i];
	long long sol=0;
	for(int i=0;i<X;i++) {
		sol+=As[i];
		update(i);
	}
	for(int i=X;i<X+Y;i++) {
		sol+=Bs[i];
		pos[i]=1;
		update(i);
	}
	for(int i=X+Y;i<X+Y+Z;i++) {
		sol+=Cs[i];
		pos[i]=2;
		update(i);
	}
	while(1) {
		long long opt[6];
		for(int i=0;i<6;i++) {
			while(1) {
				if(pos[pq[i].top().second]!=i/2) {
					pq[i].pop();
				} else {
					break;
				}
			}
			opt[i]=pq[i].top().first;
		}
		if(opt[0]+opt[2]>0) {
			sol+=opt[0]+opt[2];
			int va=pq[0].top().second;
			int vb=pq[2].top().second;
			pos[va]=1;
			pos[vb]=0;
			update(va);
			update(vb);
		} else if(opt[1]+opt[4]>0) {
			sol+=opt[1]+opt[4];
			int va=pq[1].top().second;
			int vb=pq[4].top().second;
			pos[va]=2;
			pos[vb]=0;
			update(va);
			update(vb);
		} else if(opt[3]+opt[5]>0) {
			sol+=opt[3]+opt[5];
			int va=pq[3].top().second;
			int vb=pq[5].top().second;
			pos[va]=2;
			pos[vb]=1;
			update(va);
			update(vb);
		} else if(opt[0]+opt[3]+opt[4]>0) {
			sol+=opt[0]+opt[3]+opt[4];
			int va=pq[0].top().second;
			int vb=pq[3].top().second;
			int vc=pq[4].top().second;
			pos[va]=1;
			pos[vb]=2;
			pos[vc]=0;
			update(va);
			update(vb);
			update(vc);
		} else if(opt[1]+opt[2]+opt[5]>0) {
			sol+=opt[1]+opt[2]+opt[5];
			int va=pq[1].top().second;
			int vb=pq[2].top().second;
			int vc=pq[5].top().second;
			pos[va]=2;
			pos[vb]=0;
			pos[vc]=1;
			update(va);
			update(vb);
			update(vc);
		} else {
			break;
		}
	}
	cout << sol << endl;
	return 0;
}


Measured memory_bytes: 5108
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var XY = Sarray();
            var X = XY[0];
            var Y = XY[1];
            var ans = 0;
            while (X <= Y)
            {
                ++ans;
                X *= 2;
            }
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 13396
from _collections import deque
H,W = map(int,input().split())
T = []
for i in range(H):
    a = list(input())
    T.append(a)

K = [[0,0,0]]
P = deque(K)
dp = [[10**6]*W for _ in range(H)]
used = [[0]*W for _ in range(H)]
move = [(-1,0),(0,-1),(1,0),(0,1)]

while(len(P)>0):
    b = P.popleft()
    h = b[0]
    w = b[1]
    c = b[2]
    if c < dp[H-1][W-1]:
        for i,j in move:
            if h+i >= 0 and h+i <= H-1:
                if w+j >= 0 and w+j <= W-1:
                    if T[h+i][w+j] == ".":
                        dp[h+i][w+j] = min(c+1,dp[h+i][w+j])
                        if used[h+i][w+j] == 0:
                            used[h+i][w+j] = 1
                            P.append([h+i,w+j,c+1])

ans = 0
for i in range(H):
    for j in range(W):
        if T[i][j] == ".":
            ans += 1
if dp[H-1][W-1] == 10**6:
    print(-1)
else:
    print(ans-dp[H-1][W-1]-1)

Measured memory_bytes: 41712
function main(input: string[]): void {
    const a = parseInt(input.shift());
    const b = parseInt(input.shift());
    const x = parseInt(input.shift()) / a;
    if (a * b < x * 2) {
        // over half
        const r = a * b - x;
        const y = r * 2 / a;
        console.log(Math.atan(y / a) / Math.PI * 180);
    } else {
        // under half
        const y = x * 2 / b;
        console.log(Math.atan(b / y) / Math.PI * 180);
    }
}

import { readFileSync } from 'fs';
if (process.argv[1] == __filename) {
    const path = process.argv[2] || '/dev/stdin';
    const input = readFileSync(path, 'utf-8');
    main(input.split(/\s+/));
}

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

int w, h;
int xs, ys;
int xg, yg;
int n;
int b[102][102];

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

bool input() {
  cin >> w >> h;
  if (!w && !h) {
    return false;
  }
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      b[i][j] = -1;
    }
  }
  cin >> xs >> ys;
  cin >> xg >> yg;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int c, d, x, y;
    cin >> c >> d >> x >> y;
    if (!d) {
      for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 4; ++j) {
          b[y + i][x + j] = c;
        }
      }
    } else {
      for (int i = 0; i < 4; ++i) {
        for (int j = 0; j < 2; ++j) {
          b[y + i][x + j] = c;
        }
      }
    }
  }
  return true;
}

void dfs(int c, int y, int x) {
  if (b[y][x] != c) {
    return;
  }
  b[y][x] = -1;
  for (int i = 0; i < 4; ++i) {
    dfs(c, y + dy[i], x + dx[i]);
  }
}

void solve() {
  if (b[ys][xs] != b[yg][xg]) {
    cout << "NG" << endl;
    return;
  }

  dfs(b[ys][xs], ys, xs);
  if (b[yg][xg] == -1) {
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }
}

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

Measured memory_bytes: 3084
import java.util.*;
import java.lang.*;
class Main {
    public static void main(String args[]) {
        Scanner sc  = new Scanner(System.in);
      int n = sc.nextInt();
        Integer[] a = new Integer[n];
        for(int i=0;i<n;i++){
            a[i] = sc.nextInt();
        }
        Integer[] dp = new Integer[n];
        dp[0] = 0;
        for(int i=1;i<n;i++){
            dp[i] = Math.min((dp[Math.max(i-1,0)]+(Math.abs(a[i]-a[Math.max(i-1,0)]))),(dp[Math.max(i-2,0)]+(Math.abs(a[i]-a[Math.max(i-2,0)]))));
        }
        System.out.print(dp[n-1]);
    }
}

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

int n, val, cnt;
map<int,int> ada;

int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; ++i) {
		scanf("%d", &val);
		ada[val]++;
	}
	for(auto p : ada) {
		if(p.second & 1) {
			cnt++;
		}
	}
	printf("%d\n", cnt);
}

Measured memory_bytes: 4992
import sys
input = sys.stdin.readline

N,M = list(map(int,input().split()))
X = sorted(list(map(int,input().split())))
Xsub = []
for i in range(M-1):
    Xsub.append(X[i+1]-X[i])
    
Xsub = sorted(Xsub)

if N > 1:
    print(sum(Xsub[:-(N-1)] ))   
else:
    print(sum(Xsub))


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

using namespace std;

#define _int64 long long

int a[110000];
int n;

_int64 doit(int f)
{
  _int64 sum;
  _int64 ret;
  int i;
  ret=0;
  sum=0;
  for (i=0;i<n;i++)
  {
    sum+=a[i];
    if (f>0)
    {
      if (sum<=0)
      {
        ret+=(-sum);
        ret++;
        sum=1;
      }
    }
    else
    {
      if (sum>=0)
      {
        ret+=sum;
        ret++;
        sum=-1;
      }
    }
    f=-f;
  }
  //cout<<ret<<endl;
  return ret;
}
  

int main()
{
  _int64 sum,ans1,ans2;
  int f,i;
  scanf("%d",&n);
  for (i=0;i<n;i++)
    scanf("%d",&a[i]);
  ans1=doit(1);
  ans2=doit(-1);
  if (ans1<ans2) printf("%lld\n",ans1);
  else printf("%lld\n",ans2);
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define intt int64_t
#define all(vec) vec.begin(), vec.end()
#define MOD 1000000007

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    bool ans=false;
    if (a%3==0) ans=true;
    if (b%3==0) ans=true;
    if ((a+b)%3==0) ans=true;
    if (ans) printf("Possible\n");
    else printf("Impossible\n");
}


Measured memory_bytes: 256
T=zip(range(60,161,20),[2]+range(5,26,5),range(600,1601,200))
while True:
    n=input()
    if n==0:break
    cnt=0
    for p in range(n):
        x,y,h,w=map(int,raw_input().split())
        size=x+y+h
        for i,j,k in T:
            if size<=i and w<=j:
                cnt+=k
                break
    print cnt

Measured memory_bytes: 4472
#include <iostream>
#include <algorithm>
#include <functional>
#include <set>
#include <vector>
#include <array>
#include <cmath>
#include <queue>

#define r(i, v, n) for(int i = v; i < n; i++)
#define re(i, v, n) for(int i = v; i <= n; i++)
#define rr(e, v) for(auto&& (e) : (v))

using namespace std;
using ll = long long;
using ul = unsigned long;

int main() {
    ios_base::sync_with_stdio(false);

    int p, q, r;

    cin >> p >> q >> r;
    int a1 = p + q, a2 = p + r, a3 = q + r;
    if ( a1 < a2 && a1 < a3 ) {
        cout << a1 << endl;
    } else if ( a2 < a3 ) {
        cout << a2 << endl;
    } else {
        cout << a3 << endl;
    }

    return 0;
}



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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            out.println(in.nextInt() < 1200 ? "ABC" : "ARC");
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long nextLong() {
            long n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

        public int nextInt() {
            long n = nextLong();

            if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE)
                throw new NumberFormatException();

            return (int) n;
        }

    }
}



Measured memory_bytes: 21332
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
 
 
public class Main {
 
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        Scanner scan=new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        for (int i = 0;; i++) {
            int x=scan.nextInt();
            int y=scan.nextInt();
            if(x==0 && y==0)
                break;
            if(x>y)
                System.out.println(y+" "+x);
            else
                System.out.println(x+" "+y);
        }
 
    }
 
}

Measured memory_bytes: 34912
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

const int MOD = 1000000007;

int main(){

    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;

    string ans = "";

    rep(i,ty-sy){
        ans += 'U';
    }
    rep(i,tx-sx){
        ans += 'R';
    }
    rep(i,ty-sy){
        ans += 'D';
    }
    rep(i,tx-sx){
        ans += 'L';
    }

    ans += 'L';
    rep(i,ty-sy+1){
        ans += 'U';
    }
    rep(i,tx-sx+1){
        ans += 'R';
    }
    ans += 'D';

    ans += 'R';
    rep(i, ty-sy+1){
        ans += 'D';
    }
    rep(i, tx-sx+1){
        ans += 'L';
    }
    ans += 'U';

    cout << ans << endl;

}

Measured memory_bytes: 3640
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
 
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>
#include<iomanip>
 
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define pii pair<int,int>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define mp(a, b) make_pair(a, b)
#define mt(a,b,c) make_tuple(a,b,c)
#define rank qwertyuio
#define next dfghjk
#define plus fsghsf
#define minus ytryr
#define pb push_back
using namespace std;
 
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
 
const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int mod = (int)1e9 + 7;
const int mod1 = (int)1e9 + 9;
const int mod2 = 998244353;
const int mod3 = (int)1e6+3;
const ld eps = 1e-12;
const double pi = atan2(0, -1);
const int ABC = 26;

//vector<int> prime;
int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);<<" "
    ll n,k;
    ll r,s,p;
    string t;
    cin>>n>>k>>r>>s>>p>>t;
    ll i,j;
    ll h[n];
    rep(i,0,n){
        if(t[i]=='r'){
            h[i]=p;
        }
        else if(t[i]=='p'){
            h[i]=s;
        }
        else{
            h[i]=r;
        }
    }
    ll ans=0;
    for(i=0;i<k;i++){
        for(j=i;j<n;j+=k){
            //hand=j
            if(j<k){
                ans+=h[i];
            }
            else{
                if(t[j]==t[j-k]){
                    t[j]='X';
                }
                else{
                    ans+=h[j];
                }
            }
            //cout<<ans<<" "<<t[j]<<endl;
        }
    }
    cout<<ans;

    return 0;
             
    
}

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

int N;
char c[10] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' };


void dsf(int n, int k, string s){
  if(n == 1){ cout << s << endl; return ; }

  for(int i = 0; i < k; i++) dsf(n-1, k, s+c[i]);
  dsf(n-1, k+1, s+c[k]);

  return ;
}


int main(){
  cin >> N;

  dsf(N, 1, "a");
  return 0;
}


Measured memory_bytes: 1536
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#define MOD 1000000007
#define MAX(a,b) (a>b?a:b)
#define MAX3(a,b,c) MAX(a,MAX(b,c))
#define MIN(a,b) (a<b?a:b)
#define MIN3(a,b,c) MIN(a, MIN(b,c))
typedef long long lli;
typedef struct {
    int tate;
    int yoko;
} lamp;

int main()
{
    lli i,j,w,h,x,y,ans=0;
    scanf("%lld%lld%lld%lld",&w,&h,&x,&y);
    double ww = (double)w;
    double hh = (double)h;
    double temp = ww*hh/2;
    //printf("%lf %lf ",ww,hh);
    printf("%lf ",temp);
    if(2*x==w && 2*y==h) {
        printf("1");
    } else {
        printf("0");
    }
    return 0;
}


Measured memory_bytes: 128
import Data.List
import Data.Maybe
main = do
  n <- readLn :: IO Int
  xs <- getLine
  let cs = ['A'..'Z']
  putStrLn $ f xs n cs
  
f :: String -> Int -> String -> String
f "" _ _ = "" 
f (x:xs) n cs =
  let c = cs !! (((fromJust $ elemIndex x cs)+n) `mod` 26)
    in c : (f xs n cs)

Measured memory_bytes: 1404
#include <iostream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <string.h>
#include <map>
#include <stack>
#include <iomanip>
#include <chrono>
#include <random>
#include <math.h>
#include <time.h>
#include <bitset>
#include <assert.h>
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) x.begin(),x.end() 
#define PII pair <ll,ll>
#define N 100005
#define MOD 1000000007
#define INF 1000000000000000000
using namespace std;

ll func(ll n)
{
	return (n * (n + 1)) / 2;
}
ll power(ll a,ll b, ll c)
{
    ll res = 1;
    while(b != 0)
    {
        if(b & 1)
            res = (res * a) % c;
        a = (a * a) % c;
        b /= 2;
    }
    return res;
}
int main()
{
	ll n, m, k, ans = 0, xval, yval;
	cin >> n >> m >> k;
	ll fact[2 * N];
	fact[0] = 1;
	for (int i = 1; i < 2 * N; ++i)
	{
		fact[i] = (fact[i - 1] * i) % MOD;
	}
	ll nmck = fact[n * m - 2] * ((power(fact[(n * m - 2) - (k - 2)], MOD - 2, MOD) * power(fact[k - 2], MOD - 2, MOD)) % MOD);
	nmck %= MOD;
	cerr << nmck;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= m; ++j)
		{
			xval = func(n - i) * m + func(i - 1) * m;
			yval = func(m - j) * n + func(j - 1) * n;
			xval %= MOD;
			yval %= MOD;
			// cerr << i << " " << j << " " << xval << " " << yval << "\n";
			ans = (ans + nmck * (xval + yval)) % MOD;
		}
	}
	cout << (ans * power(2, MOD - 2, MOD)) % MOD;
}


Measured memory_bytes: 1916
using static System.Math;
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var a = new int[n];
        var c = new int[m + 1];
        var dp = new int[(1 << m)];
        for (int i = 0; i < 1 << m; i++) dp[i] = 99999999;
        dp[0] = 0;
        for (int i = 0; i < n; i++)
        {
            a[i] = int.Parse(Console.ReadLine().Trim());
            c[a[i]]++;
        }
        var b = new int[m + 1, n + 1];
        for (int i = 0; i < n; i++)
            for (int j = 1; j <= m; j++)
            {
                if (a[i] == j) b[j, i + 1] = b[j, i] + 1;
                else b[j, i + 1] = b[j, i];
            }
        var ans = getAns(b, c, m, dp);
        Console.WriteLine(ans);
    }
    static int getAns(int[,] b, int[] c, int m, int[] dp)
    {
        var imax = 1 << m;
        for (int i = 0; i < imax; i++)
        {
            var t = 0;
            for (int j = 1; j <= m; j++)
                if (((i >> (j - 1)) & 1) == 1) t += c[j];
            for (int j = 1; j <= m; j++)
                if (((i >> (j - 1)) & 1) == 0)
                {
                    var w = (i | (1 << (j - 1)));
                    var w2 = c[j] - (b[j, t + c[j]] - b[j, t]);
                    dp[w] = Min(dp[w], dp[i] + w2);
                }
        }
        return dp[imax - 1];
    }
}



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

using namespace std;

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

const int MAXN = 1e5 + 5;

bool sieve[MAXN];
int good[MAXN];

int main(){
    cin.tie(0);
    cin.sync_with_stdio(0);

    sieve[1] = true;
    for(int a = 2; a < MAXN; a++){
        if(!sieve[a]){
            for(int b = 2 * a; b < MAXN; b += a){
                sieve[b] = true;
            }
        }
    }
    for(int a = 1; a < MAXN; a++) {
        good[a] += good[a - 1];
        if(a % 2 == 1 && !sieve[a] && !sieve[(a + 1) / 2]){
            good[a]++;
        }
    }
    int Q;
    cin >> Q;

    while(Q--){
        int L, R;
        cin >> L >> R;
        cout << good[R] - good[L - 1] << "\n";
    }
}

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int K = sc.nextInt();
            int S = sc.nextInt();

            int X = 1000000000;
            if (S == X) {
                X--;
            }

            StringBuilder ans = new StringBuilder();
            for (int i = 0; i < K; i++) {
                ans.append(S).append(" ");
            }
            for (int i = K; i < N; i++) {
                ans.append(X).append(" ");
            }
            ans.delete(ans.length() - 1, ans.length());

            System.out.println(ans.toString());
        }
    }

}


Measured memory_bytes: 32132
if __name__ == "__main__":
    s = input()
    t = input()
    min_dist = len(s)

    for start in range(len(s) - len(t) + 1):
        curr_dist = 0
        for curr in range(len(t)):
            if s[start + curr] != t[curr]:
                curr_dist += 1
        min_dist = min(min_dist, curr_dist)
    print(min_dist)

Measured memory_bytes: 67604
#include <iostream>
#include <algorithm>
#include <utility>
#include <cstring>
using namespace std;

typedef long long ll;

const ll inf = 1e14;
ll n, m, sum, r, b[1005], a[1005], c[1005][13], dp[1005][1 << 13];

ll f(int p, int k)
{
    if (k == (1 << n) - 1)
        return 0;
    if (p == m)
        return inf;
    if (dp[p][k] != -1)
        return dp[p][k];
    ll mn = f(p + 1, k);
    int t = k;
    for (int i = 0; i < b[p]; ++i)
        k |= 1 << c[p][i];
    return dp[p][t] = min(mn, a[p] + f(p + 1, k));
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    memset(dp, -1, sizeof dp);
    cin >> n >> m;
    for (int i = 0; i < m; ++i)
    {
        cin >> a[i] >> b[i];
        for (int j = 0; j < b[i]; ++j)
            cin >> c[i][j], --c[i][j];
    }
    ll s = f(0, 0);
    if (s >= inf)
        cout << -1 << endl;
    else
        cout << s << endl;
    return 0;
}

Measured memory_bytes: 64768
#include<iostream>
using namespace std ;
int main()
	{
	long long n=1 ,m ,tmp ,mlast ,nlast;
	cin>>tmp ;
	m=tmp ;
	while(n<=m)
		{
		m=tmp/n ;
		if(n*m==tmp)
			{
			mlast=m ;
			nlast=n ;
			}
		n++ ;
		}
	//cout<<mlast<<" "<<nlast<<endl ;
	cout<<mlast+nlast-2<<endl ;
	}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type res struct {
	s string
	p int
	n int
}

type Rl []res

func (r Rl) Len() int {
	return len(r)
}

func (r Rl) Less(i, j int) bool {
	if r[i].s == r[j].s {
		return r[i].p > r[j].p
	}
	return r[i].s < r[j].s
}

func (r Rl) Swap(i, j int) {
	r[i], r[j] = r[j], r[i]
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	l := []res{}
	for i := 1; i <= n; i++ {
		sc.Scan()
		s := sc.Text()
		sc.Scan()
		p, _ := strconv.Atoi(sc.Text())
		l = append(l, res{s, p, i})
	}

	sort.Sort(Rl(l))

	for _, v := range l {
		fmt.Println(v.n)
	}
}


Measured memory_bytes: 640
#include<iostream>
#include<map>

int A[202020];
long long sum[202020];

int main(){
  int N,K;
  std::cin>>N>>K;
  for(int i=0;i<N;i++){
    std::cin>>A[i];
    sum[i+1]=sum[i]+A[i];
  }
  for(int i=1;i<=N;i++){
    sum[i]=sum[i]-i+K;
    (sum[i]%=K);
  }
  std::map<long long,int> mp;
  mp[sum[0]]++;
  long long ans=0;
  for(int i=1;i<=N;i++){
    if(i>=K) mp[sum[i-K]]--;
    ans+=mp[sum[i]];
    mp[sum[i]]++;
  }
  std::cout<<ans<<std::endl;
  return 0;
}

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

#define int long long
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int INF = 1 << 29;
const int N = 1e5 + 10;

struct IOsetup{
  IOsetup(){
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   cout.tie(nullptr);
   cout << fixed << setprecision(20);
  }
}IO;

int32_t main(){
  int n, m;
  cin >> n >> m;
  cout << (n == m ?  "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if ((A == 7 and  B == 5 and C == 5) or (A == 5 and  B == 7 and C == 5) or (A == 5 and  B == 5 and C == 7) ){
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    string a, b;
    cin >> a >> b;
    string ans1, ans2;
    rep(i, stoll(a)) {
        ans1 += b;
    }
    rep(i, stoll(b)) {
        ans2 += a;
    }
    if (ans1 < ans2) {
        cout << ans1 << '\n';
    } else {
        cout << ans2 << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int N = 1e5 + 20 , LG = 32 ;
int n , a[N] , X , cnt[LG] , ans ;

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

	cin >> n ;
	for (int i = 0 ; i < n ; i ++) {
		cin >> a[i] ;
		X ^= a[i] ;
	
		a[i] ^= a[i] - 1 ;

		cnt[__builtin_popcount(a[i])] ++ ;
	}

	for (int i = 1 ; i < LG ; i ++) {
		if ((X >> i & 1) != (X >> (i - 1) & 1)) {
			if (!cnt[i]) return cout << "-1\n" , 0 ;
			ans ++ ;
		}
	}

	cout << ans << '\n' ;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define endl "\n"
#define ll long long
#define eb emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mo 1000000007
#define MA 10e17
 ll int val[1000004]={0};
using namespace std;
//Conditional Operator (condition?true part:false part) eg : cout<<(y<=3?"YES":"NO")<<endl;
//string s(3,'1');
ll getmul(ll n){ll int k{0};while(n>0){k+=n%10;n=n/10;}return k;}//Sum OF n DIGITS
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t{1};
  //  cin>>t;
    while(t--){
        int x;
        cin>>x;
        if(x>=30)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
 return 0;
}

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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

template <class T1, class T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T1, class T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

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

    set<int> mR, mG, mB;

    for (int i = 0; i < N; ++i) {
        if (S[i] == 'R') {
            mR.emplace(i);
        } else if (S[i] == 'G') {
            mG.emplace(i);
        } else {
            mB.emplace(i);
        }
    }

    ll ans = mR.size() * mG.size() * mB.size();
    for (auto R : mR) {
        for (auto G : mG) {
            if ((R + G) % 2 == 0) {
                if (mB.find((R + G) / 2) != mB.end()) {
                    --ans;
                }
            }

            if (mB.find(2 * G - R) != mB.end()) {
                --ans;
            }
            if (mB.find(2 * R - G) != mB.end()) {
                --ans;
            }
        }
    }
    cout << ans << endl;
}

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

#define ntest 0

using namespace std;
int n;
long long a[200005], res;
void solve() {
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    sort(a + 1, a + n + 1);
    res = a[n];
    int p = n-1, q = 0;
    for (int i = 3; i <= n; ++i) {
        res += a[p];
        ++q;
        if (q == 2) {
            q = 0;
            --p;
        }
    }
    cout << res;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    if(ntest){
        int t;
        cin >> t;
        while(t--) solve();
    } else {
        solve();
    }

}




Measured memory_bytes: 5092
def func(q,m,W):
    s = 0
    c = 1
    for w in W:
        s += w
        if s > q:
            c += 1
            s = w
            if s > q:
                return 1
    return (c > m)

while(1):
    m,n=[int(x) for x in input().split()]
    if m==0:
        break
    W=[]
    A=[0]
    for i in range(n):
        W.append(int(input()))
        A.append(A[-1]+W[-1])
    A.pop(0)
    qsmall = sum(W)/m
    qbig   = 1500000
    while(1):
        if qbig - qsmall < 1e-3:
            break
        q = (qbig+qsmall)/2 
        issmall = func(q,m,W)
        if issmall:
            qsmall = q
        else:
            qbig = q
    q = int(qsmall)
    if func(q,m,W):
        print(q + 1)
    else:
        print(q)



Measured memory_bytes: 5632
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int A, B, C, X;
    cin >> A;
    cin >> B;
    cin >> C;
    cin >> X;

    ll ans = 0;
    REP(i, A + 1)
    {
        ll sum_500 = 500 * i;
        REP(j, B + 1)
        {
            ll sum_500_100 = sum_500 + 100 * j;
            REP(k, C + 1)
            {
                ll sum_500_100_50 = sum_500_100 + 50 * k;
                if (sum_500_100_50 == X)
                {
                    ans++;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3644
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int x = Math.max(a,b);
        int ans = 0;
        for (int i = x; 0 < i; i--) {
            int y = a - i;
            int z = b - i;
            if (Math.abs(y) == Math.abs(z)) {
                ans = i;
                break;
            }
        }
        if (ans == 0) {
            System.out.println("IMPOSSIBLE");
            System.exit(0);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 22100
package main

import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
  "sort"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt() int {
  n, _ := strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

type Items [][]int
func (I Items) Len() int { return len(I) }
func (I Items) Less(i, j int) bool {
  if I[i][0] == I[j][0] { return I[i][1] < I[j][1] }
  return I[i][0] < I[j][0]
}
func (I Items) Swap(i, j int) { I[i], I[j] = I[j], I[i] }

func Solve() {
  N := NextInt()
  A := NextIntVec()
  B := NextIntVec()
  SA := make([][]int, N)
  for i, a := range A {
    SA[i] = []int{a, i}
  }
  sort.Sort(Items(SA))
  SB := make([][]int, N)
  for i, b := range B {
    SB[i] = []int{b, i}
  }
  sort.Sort(Items(SB))
  for i := 0; i < N; i++ {
    if SA[i][0] <= SB[i][0] { continue }
    Write("No")
    return
  }
  for i := 1; i < N; i++ {
    if SB[i - 1][0] < SA[i][0] { continue }
    Write("Yes")
    return
  }
  M := make([]int, N)
  for i, sa := range SA {
    M[sa[1]] = i
  }
  cnt := 1
  s, t := SA[0][1], SB[0][1]
  for s != t {
    cnt++
    t = SB[M[t]][1]
  }
  if cnt < N {
    Write("Yes")
    return
  }
  Write("No")
  return
}

func main() {
  Solve()
  Output()
}

Measured memory_bytes: 12288
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    o = s_input()
    e = s_input()

    for i in range(len(o)+len(e)):
        if i % 2 == 0:
            print(o[i//2], end='')
        else:
            print(e[i//2], end='')

    print()

if __name__ == '__main__':
    main()


Measured memory_bytes: 72324
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)

using namespace std;
typedef long long int ll;
ll A[200000];
int N;
bool C(ll x){
    map<ll, int> m;
    rep(i,1,N){
        if(A[i]<=A[i-1]){
            m.erase(m.upper_bound(A[i]),m.end());
            if(m.find(A[i])==m.end()){
                m.insert(make_pair(A[i],1));
                if(x==1) return false;
            }
            else{
                m[A[i]]++;
                ll j=A[i];
                while(m[j]==x){
                    if(j==1) return false;
                    m[j]=0;
                    if(m.find(j-1)==m.end()) m.insert(make_pair(j-1,1));
                    else m[j-1]++;
                    j--;
                }
            }
        }
    }
    return true;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N;
    rep(i,0,N) cin>>A[i];
    ll l=0, r=2*1e5;
    while(r-l>1){
        ll mid=(l+r)/2;
        if(C(mid)) r=mid;
        else l=mid;
    }
    cout<<r<<"\n";
}

Measured memory_bytes: 1792