akhauriyash/Code-Regression huggingface dataset:
// READ & UNDERSTAND
// ll, int overflow, array bounds
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

string days[7]={"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	string s;
	cin >> s;
	for(int i=0; i<7; i++){
		if(s==days[i]){
			cout << 7-i << endl;
			break;
		}
	}
}	


Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc125c()
}

private tailrec fun gcd(a: Long, b: Long): Long {
    return if (b == 0L) a else gcd(b, a % b)
}

fun abc125c() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map { it.toLong() }

    val cumulativeGcdFromLeft = LongArray(n + 1)
    for (i in 0 until n) cumulativeGcdFromLeft[i + 1] = gcd(cumulativeGcdFromLeft[i], aList[i])

    val cumulativeGcdFromRight = LongArray(n + 1)
    for (i in n - 1 downTo 0) cumulativeGcdFromRight[i] = gcd(cumulativeGcdFromRight[i + 1], aList[i])

    val answer = (0 until n).map { gcd(cumulativeGcdFromLeft[it], cumulativeGcdFromRight[it + 1]) }.max()!!

    println(answer)
}


Measured memory_bytes: 59712
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<list>
#include<set>
#include<numeric>

#define MOD 1000000007

using namespace std;
typedef long long ll;

ll D[110];
ll sum[110];

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

	int A, B;  cin >> A >> B;

	int C;  cin >> C;

	for (int i = 0; i < N; i++) 
		cin >> D[i];

 	sort(D, D + N);
	reverse(D,D+N);

	sum[0] = D[0];
	for (int i = 1; i < N; i++) 
		sum[i] = sum[i - 1] + D[i];

	int mx = 0;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		mx = (sum[i]+C) / (A + (i + 1)*B);
		ans = max(ans, mx);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3032
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    unsigned long long n, m;
    unsigned long long d = 1000000007;
    scanf("%lld", &n);
    scanf("%lld", &m);
    int tmp1,tmp2;
    tmp1 = max(n, m);
    tmp2 = min(n, m);
    m = tmp1;
    n = tmp2;
    if (m - n >= 2) {
        printf("%d\n", 0);
    }
    else {
        unsigned long long ans = 1;
        for (int i = 1; i <= m; i++) {
            ans = (ans*i) % d;
        }
        for (int i = 1; i <= n; i++) {
            ans = (ans*i) % d;
        }
        if (m == n) {
            ans = (ans * 2) % d;
        }
        printf("%d\n", ans);
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

// 約数全列挙
vector<ll> enum_div(ll n){
  vector<ll> ret;
  for (ll i=1; i*i<=n; i++){
    if (n%i==0){
      ret.push_back(i);
      if (i!=1&&i*i!=n) ret.push_back(n/i);
    }
  }
  return ret;
}

int main() {
  ll N;
  cin >> N;
  vector<ll> div = enum_div(N);
  if (N!=1) div.push_back(N);
  for (int i=1; i<(int)div.size(); i++) div[i]--;
  ll res = 0;
  for (int i=1; i<(int)div.size(); i++) {
    // mの候補を全探索
    if (N/div[i]==N%div[i]) res += div[i];
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3612
// AtCoder Beginner Contest 057
// B - Checkpoints

#include <cstdio>
#include <algorithm>
#define MAX_N 50
#define MAX_M 50
#define INF ((int)8e8)
using namespace std;
typedef long long int ll;


int N, M;
int A[MAX_N], B[MAX_N];
int C[MAX_M], D[MAX_M];

int main() {

  int l_min, l_idx, d;

  scanf("%d%d", &N, &M);
  for (int i = 0; i < N; i++) {
    scanf("%d%d", &A[i], &B[i]);
  }
  for (int j = 0; j < M; j++) {
    scanf("%d%d", &C[j], &D[j]);
  }

  for (int i = 0; i < N; i++) {
    l_min = INF;
    l_idx = -1;
    for (int j = 0; j < M; j++) {
      d = abs(A[i] - C[j]) + abs(B[i] - D[j]);
      if (l_min > d) {
        l_min = d;
        l_idx = j + 1;
      }
    }
    printf("%d\n", l_idx);
  }

  return 0;

}




Measured memory_bytes: 128
def f(x):
  D=[-1]*(N+1)
  D[x]=0
  S=[None]*(N+1)
  S[x]=0
  ima=x+0
  for count in range(1, K+1):
    if D[P[ima]]<0:
      D[P[ima]]=count
      S[P[ima]]=S[ima]+C[P[ima]]
      ima=P[ima]+0
    else:
      if S[ima]+C[P[ima]]>S[P[ima]]:
        isshu=count-D[P[ima]]
        atonanshu=max((K-count)//isshu-1, 0)
        atonanho=K-(count+isshu*atonanshu)
        agatta=S[ima]+C[P[ima]]-S[P[ima]]
        S[P[ima]]=S[ima]+C[P[ima]]+agatta*atonanshu
        D[P[ima]]=D[ima]+1
        
        ima=P[ima]+0
        for _ in range(atonanho):
          S[P[ima]]=S[ima]+C[P[ima]]
          D[P[ima]]=D[ima]+1
          ima=P[ima]+0
      break
      
  if D[x]==0:
    S[x]=None
  return max([s for s in S if s is not None])

N, K=map(int, input().split())
P=[None]+list(map(int, input().split()))
C=[None]+list(map(int, input().split()))

print(max([f(x) for x in range(1, N+1)]))

Measured memory_bytes: 122960
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;
typedef complex<double> P;
namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
}
double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}
struct L : public vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};
int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}
bool intersectLS(const L &l, const L &s) {
  return cross(l[1]-l[0], s[0]-l[0])*       // s[0] is left of l
         cross(l[1]-l[0], s[1]-l[0]) < EPS; // s[1] is right of l
}
P crosspoint(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
  if (abs(A) < EPS) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
  return m[0] + B / A * (m[1] - m[0]);
}
double dp[1001];
P p[1001];
int main() {
  int n;
  while(cin >> n, n) {
    int vw, vc;
    cin >> vw >> vc;
    REP(i, n) {
      int x, y;
      cin >> x >> y;
      p[i] = P(x,y);
    }
    REP(i, n) dp[i] = INF;
    dp[0] = 0;
    REP(i, n-1) {
      //cout << dp[i] << " ";
      dp[i+1] = min(dp[i+1], dp[i] + abs(p[i] - p[i+1]) / vw);
      if (p[i+1].imag() > p[i].imag()) {
        int mi = p[i+1].imag();
        for (int j=i+2; j<n; ++j) {
          if (mi > p[j].imag()) {
            mi = p[j].imag();
            if (mi < p[i].imag()) {
              P q = crosspoint(L(p[i], p[i]+P(1,0)), L(p[j-1], p[j]));
              dp[j] = min(dp[j], dp[i] + (q.real()-p[i].real()) / vc + abs(p[j]-q) / vw);
              break;
            } else {
              P q = crosspoint(L(p[i], p[i+1]), L(p[j], p[j]+P(1,0)));
              dp[j] = min(dp[j], dp[i] + abs(p[i]-q) / vw + (p[j].real()-q.real()) / vc);
            }
          }
        }
      }
    }
    printf("%.8f\n", dp[n-1]);
  }
}

Measured memory_bytes: 0
#include<stdio.h>

int main(){

		int d,n;
		scanf("%d%d",&d,&n);
		int i,t=1;
		for(i=0;i<d;i++)t*=100;
		if(n!=100)printf("%d\n",t*n);
		else printf("%d\n",t*(n+1));
		return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){

  int n;
  cin >> n;
  vector<ll> u(n);
  bool is = true;
  rep(i,n)cin >> u[i];
  rep(i,n)if(u[i] & 1)is = false;
  !is ? cout << "first" << endl : cout << "second" << endl;




  

  return 0;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  
  int ans = 0;
  
  if(N==3){
    if(S[0]=='A' && S[1]=='B' && S[2]=='C') ans++;
  }else if(N > 3){
    rep(i, N-2){
      if(S[i]=='A' && S[i+1]=='B' && S[i+2]=='C') ans++;
    }
  }
  cout << ans << endl;

}

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

int main() {
  string a,b;
  cin >> a >> b;
  int c = 0;
  if(a.size() > b.size()) cout << "GREATER" << endl;
  else if(a.size() < b.size()) cout << "LESS" << endl;
  else{
    for(int i=0; i<a.size(); i++){
      if((int)a[i] > (int)b[i]){
        c++;
        break;
      }
      if((int)a[i] < (int)b[i]){
        c--;
        break;
      }
    }
    
    if(c == 1) cout << "GREATER" << endl;
    if(c == -1) cout << "LESS" << endl;
    if(c == 0) cout << "EQUAL" << endl;
  }
	return 0;
}


Measured memory_bytes: 256
"use strict";

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }

function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }

function main(input) {
  var lines = input.split('\n');
  var s = lines[0];
  var K = splitNum(lines[1]);
  var N = s.length;
  var substrs = new Set();

  for (var i = 0; i < N; i++) {
    for (var l = 1; l <= Math.min(N - i, K); l++) {
      substrs.add(s.slice(i, i + l));
    }
  }

  var arr = _toConsumableArray(substrs).sort();

  console.log(arr[K - 1]);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function splitNum(line) {
  return line.split(/\s+/).map(function (n) {
    return parseInt(n);
  });
}


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

// ref. http://kmjp.hatenablog.jp/entry/2019/10/28/0900

using namespace std;

typedef long long ll;

const ll MAX_A = 1000000LL;
const ll MAX_F = 1000000LL;

bool cond(const vector<ll> &as, const vector<ll> &fs, const ll time, const ll k) {
    ll count = 0;

    for (int i = 0; i < (int) as.size(); i++) {
        ll v = as[i] * fs[i];
        if (v > time) {
            count += (v - time - 1 + fs[i]) / fs[i];
        }
        if (count > k) {
            return false;
        }
    }

    return true;
}

int main(void) {
    ll n, k;

    cin >> n >> k;

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

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

    sort(as.begin(), as.end());
    sort(fs.begin(), fs.end(), [](const int &a, const int &b) { return a > b; });

    // for (int i = 0; i < n; i++) {
    //     cout << as[i] << " ";
    // }
    // cout << endl;

    // for (int i = 0; i < n; i++) {
    //     cout << fs[i] << " ";
    // }
    // cout << endl;

    ll left = -1, right = MAX_A * MAX_F + 1;
    while (right - left > 1) {
        ll mid = (left + right) / 2;
        // cout << left << "," << mid << "," << right << endl;
        if (cond(as, fs, mid, k)) {
            right = mid;
        } else {
            left = mid;
        }
    }

    cout << right << endl;

    return 0;
}


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

const int maxn = 105;

int n,x;
int a[maxn];

int main(){
	cin >> n >> x;	
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	sort(a,a+n);
	int cnt = 0; 
	int acc = 0;
	for (int i = 0; i < n-1; i++){
		acc+=a[i];
		if (acc <= x) cnt++;
		else break;
	}
	if (cnt == n-1){
		acc+=a[n-1];
		if (acc== x) cnt++;
	}
	cout << cnt << endl;
}


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

#define ll long long int
const int N = 102,W = 1e5+2;
int n,w;
ll weight[W],value[N], dp[N][W];

ll solve(ll i,ll j){
    if(j < 0)
        return -W*W;
    else if(i < 0)
        return 0;
    else if(dp[i][j] != -1)
        return dp[i][j];
    dp[i][j] = max(value[i] + solve(i-1,j-weight[i]),solve(i-1,j));
    return dp[i][j];
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> w;
    for(int i=0;i<n;i++){
        int j,k;
        cin >> j >> k;
        weight[i] = j;
        value[i] = k;
    }
    memset(dp,-1,sizeof(dp));
    cout << solve(n-1,w) << '\n';

    return 0;
}

Measured memory_bytes: 80128
def main():
    n = int(input())
    v = list(map(int,input().split()))
    odd={}
    even={}
    for i in range(n):
        if i%2==0:
            if v[i] not in odd:
                odd[v[i]]=1
            else:
                odd[v[i]]+=1
        else:
            if v[i] not in even:
                even[v[i]]=1
            else:
                even[v[i]]+=1
    cnt_o=[]
    cnt_e=[]
    for i in odd:
        cnt_o.append([odd[i],i])
    for i in even:
        cnt_e.append([even[i],i])
    cnt_o.append([0,10**6])
    cnt_e.append([0,10**6])
    cnt_o.sort(reverse=True)
    cnt_e.sort(reverse=True)
    if cnt_o[0][1]!=cnt_e[0][1]:
        print(n-cnt_o[0][0]-cnt_e[0][0])
        return
    else:
        print(min(n-cnt_o[1][0]-cnt_e[0][0],n-cnt_o[0][0]-cnt_e[1][0]))
        return
if __name__ == "__main__":
    main()

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> d, m, c;
    int pre = -1;
    vector<ll> msum(n, 0), csum(n, 0), cnum(n, 0);
    for (int i = 0; i < n; i++)
    {
        if (i != 0)
        {
            msum[i] = msum[i - 1];
            csum[i] = csum[i - 1];
            cnum[i] = cnum[i - 1];
        }
        if (s[i] == 'D')
        {
            d.push_back(i);
        }
        else if (s[i] == 'M')
        {
            m.push_back(i);
            msum[i]++;
        }
        else if (s[i] == 'C')
        {
            c.push_back(i);
            cnum[i]++;
            if (pre == -1)
                csum[i] = msum[i];
            else
                csum[i] = csum[pre] + msum[i];
            pre = i;
        }
    }
    int q;
    cin >> q;
    while (q--)
    {
        int k;
        cin >> k;
        ll res = 0;
        for (int i = 0; i < (int)d.size(); i++)
        {
            int pos = d[i];
            auto mi = upper_bound(c.begin(), c.end(), pos);
            if (mi == c.end())
                continue;
            auto ma = lower_bound(c.begin(), c.end(), pos + k);
            ma--;
            int miidx = *mi, maidx = *ma;
            res -= msum[pos] * (cnum[maidx] - cnum[pos]);
            if (mi == c.begin())
            {
                res += csum[maidx];
            }
            else
            {
                res += csum[maidx];
                res -= csum[miidx-1];
            }
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 32024
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int[] G => ReadLine().Split().Select(int.Parse).ToArray();
	const long MOD = 1000000007;
	const long InfL = 4011686018427387913L;
	int N;
	List<Edge>[] g;
	public K()
	{
		var I = G;
		N = I[0];
		var M = I[1];
		I = G;
		var s = I[0] - 1;
		var t = I[1] - 1;
		g = new List<Edge>[N];
		for (var i = 0; i < N; i++) g[i] = new List<Edge>();
		for (var i = 0; i < M; i++)
		{
			I = G;
			int a = I[0] - 1, b = I[1] - 1, c = I[2];
			g[a].Add(new Edge(b, c));
			g[b].Add(new Edge(a, c));
		}
		var ds = DijkstraFrom(s);
		var cs = Count(s, ds);
		var ct = Count(t, DijkstraFrom(t));
		done = new bool[N];
		DFS(t, ds);
		var ans = cs[t] * cs[t] % MOD;
		var D = ds[t];
		for (var u = 0; u < N; u++) if (done[u])
			{
				if (2 * ds[u] == D) ans = (ans - cs[u] * cs[u] % MOD * ct[u] % MOD * ct[u] % MOD) % MOD;
				else if (2 * ds[u] < D)
					foreach (var e in g[u]) if (done[e.To] && 2 * ds[e.To] > D && ds[u] + e.D == ds[e.To]) ans = (ans - cs[u] * cs[u] % MOD * ct[e.To] % MOD * ct[e.To] % MOD) % MOD;
			}
		if (ans < 0) ans += MOD;
		WriteLine(ans);
	}
	bool[] done;
	void DFS(int u, long[] d)
	{
		if (done[u]) return;
		done[u] = true;
		foreach (var e in g[u]) if (!done[e.To] && d[e.To] + e.D == d[u]) DFS(e.To, d);
	}
	long[] Count(int u, long[] d)
	{
		var t = new List<Edge>();
		for (var i = 0; i < N; i++) t.Add(new Edge(i, d[i]));
		t.Sort();
		var c = new long[N];
		c[u] = 1;
		foreach (var v in t.Select(hoge => hoge.To)) foreach (var e in g[v]) if (d[e.To] + e.D == d[v]) c[v] = (c[v] + c[e.To]) % MOD;
		return c;
	}
	long[] DijkstraFrom(int u)
	{
		var d = new long[N];
		for (var v = 0; v < N; v++) d[v] = InfL;
		var queue = new PriorityQueue();
		d[u] = 0;
		queue.Enqueue(new Edge(u, 0));
		while (queue.Count > 0)
		{
			var p = queue.Dequeue();
			var v = p.To;
			if (d[v] < p.D) continue;
			foreach (var e in g[v])
			{
				var t = d[v] + e.D;
				if (d[e.To] > t) queue.Enqueue(new Edge(e.To, d[e.To] = t));
			}
		}
		return d;
	}
}
struct Edge : IComparable<Edge>
{
	public readonly int To;
	public readonly long D;
	public Edge(int t, long d) { To = t; D = d; }
	public int CompareTo(Edge e) => D.CompareTo(e.D);
}
class PriorityQueue
{
	readonly List<Edge> list = new List<Edge>();
	public int Count { get; private set; } = 0;
	public void Enqueue(Edge x)
	{
		var i = Count++;
		list.Add(x);
		while (i > 0)
		{
			var p = (i - 1) / 2;
			if (list[p].CompareTo(x) <= 0) break;
			list[i] = list[p];
			i = p;
		}
		list[i] = x;
	}
	public Edge Dequeue()
	{
		var v = list[0];
		var x = list[--Count];
		list.RemoveAt(Count);
		if (Count == 0) return v;
		var i = 0;
		while (i * 2 + 1 < Count)
		{
			var l = 2 * i + 1;
			var r = 2 * i + 2;
			if (r < Count && list[r].CompareTo(list[l]) < 0) l = r;
			if (list[l].CompareTo(x) >= 0) break;
			list[i] = list[l];
			i = l;
		}
		list[i] = x;
		return v;
	}
	public Edge Peek() => list[0];
}


Measured memory_bytes: 59396
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <iostream>
#define maxn 100009
using namespace std;
int n;
vector<int>G[maxn];
int sg[maxn];
void dfs(int u, int fa){
	sg[u] = 0;
	for(auto v: G[u]){
		if(v == fa)
			continue;
		dfs(v, u);
		sg[u] ^= (sg[v] + 1);
	}
}
int main(){
	int n;
	cin >> n;
	for(int i = 1; i < n; i++){
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1, -1);
	if(sg[1])
		puts("Alice");
	else
		puts("Bob");
	return 0;
}

Measured memory_bytes: 12288
n,m,x=map(int,input().split())
c=[list(map(int,input().split())) for _ in range(n)]
l=[]
for i in range(2**n):
    l.append(format(i,'b').zfill(n))
l1=[]
for i in range(len(l)):
    s=[0]*(m+1)
    for j in range(n):
        if l[i][j]=='1':
            for k in range(m+1):
                s[k]+=c[j][k]

    for o in range(1,m+1):
        if s[o]<x:break
        if o==m:l1.append(s[0])
if len(l1)==0:print(-1) 
else:print(min(l1))

Measured memory_bytes: 9332
from operator import itemgetter

li = list(map(int, input().split()))
N = li[0]
M=li[1]
L = []
K=[]
for i in range(N):
    L.append([])
    

for i in range(M):
    li = list(map(int, input().split()))
    L[li[0] - 1].append([li[1], i])
    K.append(0)

for i in range(N):
        O = L[i]

        O.sort()
        for j in range(len(O)):
                K[O[j][1]]=str(i+1).zfill(6)+str(j+1).zfill(6)

for i in range(M):
        print(K[i])

Measured memory_bytes: 42820
#include <iostream>
using namespace std;
int main(){
  int N,M,X,Y;
  cin>>N>>M>>X>>Y;
  for(int i=0;i<N;i++){
    int v;
    cin>>v;
    X=max(X,v);
  }
  for(int i=0;i<M;i++){
    int v;
    cin>>v;
    Y=min(Y,v);
  }
  if(X<Y)
    cout<<"No War\n";
  else
    cout<<"War\n";
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int w,h,x,y,r;
    scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
    if (x-r>=0 && x+r<=w && y-r>=0 && y+r<=h){
        puts("Yes");
    } else {
        puts("No");
    }
    return 0;
}


Measured memory_bytes: 2140
n, m = map(int, input().split())


ichi = set()
enu = set()

for _ in range(m):
	a, b = list(map(int, input().split()))
	if a == 1:
		ichi.add(b)
	elif a == n:
		enu.add(b)
	elif b == 1:
		ichi.add(a)
	elif b == n:
		enu.add(a)

if ichi & enu != set():
	print("POSSIBLE")
else:
	print("IMPOSSIBLE")

Measured memory_bytes: 18996
#include <cstdio>
#include <queue>
#include <vector>

using namespace std;
#define MAX_V (10010)

vector<int> G[MAX_V];
int indeg[MAX_V];
bool arrived[MAX_V];
vector<int> ans;

void bfs( int s ) {
    queue<int> Q;
    Q.push( s );
    
    while ( !Q.empty() ) {
	int v = Q.front(); Q.pop();
	ans.push_back( v );
	for ( int i = 0; i < G[v].size(); i++ ) {
	    int t = G[v][i];
	    indeg[t]--;
	    if ( indeg[t] == 0 && !arrived[t] ) {
		arrived[t] = true;
		Q.push( t );
	    }
	}
    }
}


int main()
{
    int V, E;
    scanf("%d %d", &V, &E);
    
    for ( int i = 0; i < E; i++ ) {
	int s, t;
	scanf("%d %d", &s, &t);
	G[s].push_back( t );
        indeg[t]++;
    }

    for ( int i = 0; i < V; i++ ) {
	if ( !arrived[i] && indeg[i] == 0 ) {
	    arrived[i] = true;
	    bfs( i );
	}
    }

    for ( int i = 0; i < ans.size(); i++ ) {
	printf("%d\n", ans[i] );
    }


    return 0;
}

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

int main() {
  vector<int64_t> vec(87);
  vec.at(0)=2;
  vec.at(1)=1;
  
  for (int i=2;i<87;i++){
      vec.at(i)=vec.at(i-2)+vec.at(i-1);
  }
    
  int n;
  cin>>n;  
  
  cout<< vec.at(n)<<endl;
}

Measured memory_bytes: 3596
import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String args[])
	{
		Scanner x=new Scanner(System.in);
    	int n=x.nextInt();
		long c=0;
    	long a[]=new long[n+1];
		long b[]=new long[n];
		for(int i=0;i<n+1;i++)
		{
			a[i]=x.nextLong();
		}
		for(int i=0;i<n;i++)
		{
			b[i]=x.nextLong();
		}
		for(int i=0;i<n;i++)
		{
			c+=Math.min((a[i]+a[i+1]),b[i]);
			if(a[i]<b[i])
			{	
				b[i] -= a[i];
				if(a[i+1]>=b[i])
				{
				a[i+1]-=b[i];
				}
				else
				{
				a[i+1]=0;
				}
			}
		}
		System.out.println(c);
	}
}

Measured memory_bytes: 87984
#include<stdio.h>
int main()
{
    long long n,sum=0,T,max,min;
    scanf("%lld",&T);
    for(int i=1; i<=T; i++)
    {
        scanf("%lld ",&n);
        if(i==1)
            max=min=n;
        if(max<n)
            max=n;
        else if(min>n)
            min=n;
        sum=sum+n;
    }
    printf("%d %d %lld\n",min,max,sum);
    return 0;
}


Measured memory_bytes: 2140
def main():
    from itertools import permutations
    a = [int(input()) for _ in range(5)]

    ans = -1
    for perm in permutations(a):
        it = iter(perm)
        t = next(it)
        for x in it:
            t += (x + 9) // 10 * 10
        if not (~ans) or t < ans:
            ans = t
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include<bits/stdc++.h>

using namespace std;

int main()
{ int n ;
cin>>n;
if(n%1000==0)
    cout<<0;
else 
cout<<1000-(n%1000);



}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int a[100001];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n;i++) cin>>a[i];
	int cnt=1;
	int mode=0;
	for(int i=0;i<n;i++)
	{
		if(i==0)
		{
			continue;
		}
		if(mode==0)
		{
			if(a[i]==a[i-1]) continue;
			if(a[i]>a[i-1]) mode=1;
			else mode=-1;
		}
		else if(mode==1)
		{
			if(a[i]<a[i-1])
			{
				cnt++;
				mode=0;
			}
		}
		else
		{
			if(a[i]>a[i-1])
			{
				cnt++;
				mode=0;
			}
		}
	}
	cout<<cnt<<'\n';
}


Measured memory_bytes: 892
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define REP(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;

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

    int res = c - (a - b);
    if(res>=0) cout << res << endl;
    else cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma comment(linker, "/STACK:102400000,102400000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define Key_Value ch[ch[root][1]][0]
#define DBN1(a)           cerr<<#a<<"="<<(a)<<"\n"
#define DBN2(a,b)         cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define DBN3(a,b,c)       cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define DBN4(a,b,c,d)     cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"
#define DBN5(a,b,c,d,e)   cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<"\n"
#define DBN6(a,b,c,d,e,f) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<", "<<#e<<"="<<(e)<<", "<<#f<<"="<<(f)<<"\n"
#define clr(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define mp make_pair
#define ALL(x) x.begin(),x.end()
#define F first
#define S second
using namespace std;
typedef long long ll;
const int maxn=500000+5;
const int INF=0x3f3f3f3f;
const int P=1000000007;
const double PI=acos(-1.0);
template<typename T>
inline T read(T&x){
    x=0;int _f=0;char ch=getchar();
    while(ch<'0'||ch>'9')_f|=(ch=='-'),ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x=_f?-x:x;
}
template <class T1, class T2>inline void gmax(T1 &a,T2 b){if (b>a) a=b;}
template <class T1, class T2>inline void gmin(T1 &a,T2 b){if (b<a) a=b;}
void up(int&x,int y){x+=y;if(x>=P)x-=P;}
/*int n,a;
int main(){
    read(n),read(a);
    if (a>=n) puts("Yes");
    else{
        for (int i=0;i<=a;i++){
            if ((n-i)%500==0) return puts("Yes"),0;
        }
        puts("No");
    }
    return 0;
}*/
/*int n,a[105];
int main(){
    read(n);
    for (int i=1;i<=n;i++) read(a[i]);
    sort(a+1,a+1+n);
    reverse(a+1,a+1+n);
    int ans=0;
    for (int i=1;i<=n;i+=2){
        ans+=a[i]-a[i+1];
    }
    printf("%d\n",ans);
    return 0;
}*/
int c[4][4];
int main(){
    int ans=0;
    for (int i=1;i<=3;i++){
        for (int j=1;j<=3;j++){
            ans+=read(c[i][j]);
        }
    }
    if (ans%3!=0) puts("No");
    else{
        bool flag=true;
        int tmp;

        tmp=c[1][2]-c[1][1];
        for (int i=2;i<=3;i++){
            flag&=(tmp==c[i][2]-c[i][1]);
        }

        tmp=c[1][3]-c[1][2];
        for (int i=2;i<=3;i++){
            flag&=(tmp==c[i][3]-c[i][2]);
        }

        tmp=c[2][1]-c[1][1];
        for (int i=2;i<=3;i++){
            flag&=(tmp==c[2][i]-c[1][i]);
        }
        tmp=c[3][1]-c[2][1];
        for (int i=2;i<=3;i++){
            flag&=(tmp==c[3][i]-c[2][i]);
        }

        if (flag) puts("Yes");
        else puts("No");
    }
}


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

bool isPrime(int x) {
    if (x < 2) return false;
    if (x == 2) return true;
    if (x % 2 == 0) return false;
    for (int i = 3; i * i <= x; i += 2) {
        if (x % i == 0) return false;
    }
    return true;
}

int main() {
    int X;
    cin >> X;
    int ans;
    for (int i = X; ; i++) {
        if (isPrime(i)) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string S;
	string K="keyence";
	cin>>S;
	for(int i=0;i<7;i++)
		if(S.substr(0,i)==K.substr(0,i)&&S.substr(S.length()-7+i)==K.substr(i))
		{
			puts("YES");
			return 0;
		}
	puts("NO");
	return 0;
}

Measured memory_bytes: 256
m = gets.to_i
m.times{
  init = gets.to_i
  y  = gets.to_i
  n = gets.to_i
  max=0
  n.times{
    kind,bene,tesu = gets.split
    kind = kind.to_i
    bene = bene.to_f
    tesu = tesu.to_i
    if kind == 0
      a=init
      sum=0
      y.times{
        b=(a*bene).floor
        sum+=b
        a-=tesu
      }
      max=[a+sum,max].max
    else
      a=init
      y.times{
        b=(a*bene).floor
        a=a+b-tesu
      }
      max = [a,max].max
    end
  }
  puts max
}

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

//実行部
void Main()
{
  ll n; cin >> n;
  vll l(2 * n); rep(i, 2 * n) cin >> l[i];
  sort(all(l));
  ll ans = 0;
  for(ll i = 0;i < 2 * n;i += 2)
  {
    ans += l[i];
  }
  fin(ans);
}

//前処理
int main()
{
  ifstream in("text.txt");
  cin.rdbuf(in.rdbuf());
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}

/*
//test時
  g++ test.cpp -o test;./test
*/


Measured memory_bytes: 256
import sys
n = int(input())

ans = float("inf")
flag = 0
for i in range(2,int(n**(1/2))+1):
  if n%i == 0:
    ans = min(ans, i+(n//i)-2)
    flag = 1

if flag:
  print(ans)
else:
  print(n-1)   

Measured memory_bytes: 9296
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U>
inline void cmax(T& a, U b) { if (a < b) a = b; }
template<class T, class U>
inline void cmin(T& a, U b) { if (a > b) a = b; }

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);
  }
} io_setup;

constexpr char el = '\n';

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U>& p) {
  os << p.first << " " << p.second;
  return os;
}
template<typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template<typename T>
ostream &operator<<(ostream &os, const vector< T > &v) {
  rep(i, v.size())
    os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}
template<typename T>
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}
#line 2 "b.cpp"

int main() {
  ll n, m;
  cin >> n >> m;
  vl a(n);
  cin >> a;

  ll cnt = 0;
  double sum = 0;
  rep(i, n) {
    sum += a[i];
  }

  double d = sum / (4*m);
  rep(i, n) {
    if (a[i] >= d) {
      cnt++;
    }
  }

  if (cnt >= m) cout << "Yes" << el;
  else cout << "No" << el;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
ll km(ll x,ll y)
{
    ll ans=1;
    while(y)
    {
        if(y%2==1)
        {
            ans*=x;
        }
        x=x*x;
        y/=2;
    }
    return ans;
}
int main()
{
    ll a,b;
    while(~scanf("%lld%lld",&a,&b))
    {
        if(a==1) {printf("%lld\n",b);continue;}
        ll _b=(ll)sqrt(b);
        ll ans=1;
        for(ll i=2;i<=_b&&b>=i;i++)
        {
            ll tnt=0;
            while(b%i==0&&b!=1)
            {
                b/=i;
                tnt++;
            }
            ans=ans*km(i,tnt/a);

        }
        if(b!=1&&a==1)
        {
            ans*=b;
        }
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
/*Remember: The Struggle is Important*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

#define     int          long long int
#define     ld           long double
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     (__gcd((a),(b)))
#define     lcm(a,b)     (((a)*(b))/gcd((a),(b)))
#define     pb           push_back
#define     ins          insert
#define     pii          pair<int,int>
#define     F            first
#define     S            second
#define     show(x)      for(auto c:x)cout<<c<<" ";cout<<"\n";
#define     show2(x)     for(auto c:x)cout<<c.F<<" "<<c.S<<"\n";

const int inf=1e18,M=1e9+7;
const int N=1;

void solve()
{
    int n,m,q;
    cin>>n>>m>>q;

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

    vector<int> t(m);
    for(int i=0;i<m;++i)
        cin>>t[i];

    vector<int> one(n,inf),two(m,inf);

    int pos;

    for(int i=0;i<n;++i)
    {
        pos=lower_bound(all(t),s[i])-t.begin();

        if(pos>0)
            one[i]=min(one[i],s[i]-t[pos-1]);
        if(pos<m)
            one[i]=min(one[i],t[pos]-s[i]);
    }

    for(int i=0;i<m;++i)
    {
        pos=lower_bound(all(s),t[i])-s.begin();

        if(pos>0)
            two[i]=min(two[i],t[i]-s[pos-1]);
        if(pos<n)
            two[i]=min(two[i],s[pos]-t[i]);
    }

    int ans,x;
    for(;q;--q)
    {
        cin>>x;

        ans=inf;


        pos=lower_bound(all(s),x)-s.begin();

        if(pos>0)
            ans=min(ans,(x-s[pos-1])+one[pos-1]);
        if(pos<n)
            ans=min(ans,(s[pos]-x)+one[pos]);


        pos=lower_bound(all(t),x)-t.begin();

        if(pos>0)
            ans=min(ans,(x-t[pos-1])+two[pos-1]);
        if(pos<m)
            ans=min(ans,(t[pos]-x)+two[pos]);


       cout<<ans<<"\n";
    }
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



Measured memory_bytes: 4480
#include <iostream>

int main() {
    long n = 0;
    long k, a, b;
    std::cin >> k >> a >> b;
    if (k - a + 1 > 0 && b - a > 2) {
        n = (k - a + 1) / 2;
        std::cout << a + n * (b - a) + (k - a + 1) % 2;
    } else {
        std::cout << k + 1;
    }
    std::cout << std::endl;
}

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

using namespace std;

#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0)
typedef long long ll;
//#define int ll
#define swap(x, y)((x)^=(y)^=(x)^=(y))
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> matrix;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define f first
#define tcase int _; cin>> _; for( ; _; --_)
#define s second
#define endl '\n'
const int MAX = 1e6+1;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const double DEG = 180/PI;
const int MOD = 1e9+7;
int mod(int x, int m){ if(x >= 0) return x % m; if(-x < m) return m-(-x); return mod(x%m, m);}
int gcd (int a, int b) {while(b){a = mod(a, b); swap(a, b);} return a;}
int lcm (int a, int b) {return a / gcd(a, b) * b;}
int fexp(int base, int exp, int m){
	int total = 1;
	while(exp > 0){
		if(exp % 2 == 1){
			total = mod(((mod(total, m)) * (mod(base, m))), m);
			exp--;
		}
		base= mod((mod(base, m) * mod(base, m)), m);
		exp /= 2;
	}
	return mod(total, m);
}

int n;

void solve(){
    int a, b, c;
    cin>> a >> b>> c;
    if(a != b) swap(a, b);
    if(b != c) swap(a, c);
    cout<< a << ' ' << b << ' ' << c<< endl;
}

int32_t main(){
	fastio;
	solve();
	return 0;
}



Measured memory_bytes: 3620
fun main(args: Array<String>) {
    val x = readInt()
    var ans = 0
    if (x >= 2000 || x%100 <= (x/100)*5) ans = 1
    println(ans)
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

fun Int.pow(n: Int) = Math.pow(this.toDouble(), n.toDouble())

Measured memory_bytes: 31648
int main()
{
    int maxval;
    int i;
    scanf("%d", &i);
    i++;
    char string[i];
    for(int counter = 0; counter < (i); counter++)
    {
        scanf("%c", &string[counter]);
    }
    int val = 0;
    for (int j = 0; j < i; j++)
    {
        if(string[j] == 'I')
        {
            val++;
            if(val >= maxval)
            {
                maxval = val;
            }
        }
        else if (string[j] == 'D')
        {
            val--;
            if(val >= maxval)
            {
                maxval = val;
            }
        }
    }
    printf("%d\n", maxval);

    return 0;
}

Measured memory_bytes: 128
<?php
fscanf(STDIN, "%d %d", $a, $b);
$diff = abs(($a - $b) / 2);
if(!is_float($diff)){
    if(abs($a) > abs($b)){
        echo $b + $diff;
    }elseif(abs($a) < abs($b)){
        echo $a + $diff;
    }
}else{
    echo 'IMPOSSIBLE';
}
?>

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

int main(){
  int N, M; cin >> N >> M;
  vector<vector<int>> vec(M);
  for(int i = 0; i < M; i++){
    int k; cin >> k;
    vec[i].resize(k);
    for(int j = 0; j < k; j++){
      cin >> vec[i][j];
      vec[i][j]--;
    }
  }
  vector<int> p(M);
  for(int i = 0; i < M; i++){
    cin >> p[i];
  }
  int ans = 0;
  for(int i = 0; i < (1 << N); i++){
    bool ok = true;
    for(int j = 0; j < M; j++){
      int c = 0;
      for(int id : vec[j]){
        if((i >> id) & 1){
          c++;
        }
      }
      c %= 2;
      if(c != p[j]){
        ok = false;
      }
    }
    if(ok) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
	int n,x[365],y[365],b[365],p[365],ans[365];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i]>> b[i]>> p[i];
	}
	for (int i = 0; i < n; i++) {
		ans[i] = x[i] * b[i] + y[i] * p[i];
		if (b[i] >= 5 && p[i] >= 2) {
			ans[i] *= 0.8;
		} 
		if (b[i] < 5 && p[i] >= 2 && x[i] * b[i] + y[i] * p[i]>0.8*(x[i] * 5 + y[i] * p[i])) {
			ans[i] = x[i] * 5 + y[i] * p[i];
			ans[i] *= 0.8;
		}
		if (b[i] >= 5 && p[i] < 2 && x[i] * b[i] + y[i] * p[i]>0.8*(x[i] * b[i] + y[i] * 2)) {
			ans[i] = x[i] * b[i] + y[i] * 2;
			ans[i] *= 0.8;
		}
		if (b[i] < 5 && p[i] < 2 && x[i] * b[i] + y[i] * p[i]>0.8*(x[i] * 5 + y[i] * 2)) {
			ans[i] = x[i] * 5 + y[i] * 2;
			ans[i] *= 0.8;
		}
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3108
def m(L,R):
 T=[]
 for l in L[::-1]:
  while R and R[-1]>l:T+=[R.pop()]
  T+=[l]
 return R+T[::-1]
def d(A):
 l=len(A);global c;c+=l
 s=l//2;return m(d(A[:s]),d(A[s:]))if l>1 else A
c=-int(input())
print(*d(list(map(int,input().split()))))
print(c)


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

int main(){
    int N,L; cin >> N >> L;
    int sum=0;
    vector <int> A(N);
    for (int i=0; i<N; i++){
        A[i]=L+(i+1)-1;
        sum+=A[i];
    }
    
    if ((L+(0+1)-1<0) && (L+(N-1+1)-1<0)) sum-=A[N-1];
    else if ((L+(0+1)-1>0) && (L+(N-1+1)-1>0)) sum-=A[0];
    
    cout << sum;
}

Measured memory_bytes: 256
a,b,c,x,y = gets.split.map &:to_i
n = [x, y].max
ans = 10**9
0.upto(n) do |i|
  cnt = 2 * c * i + [y-i, 0].max * b + [x-i, 0].max * a
  ans = [ans,cnt].min
end
puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    int N; cin >> N;
    vector<string> S(N);
    REP(i, 0, N) cin >> S[i];

    int ans = 0;
    REP(a, 0, N) {
        bool symmetric = true;
        REP(i, 0, N) {
            REP(j, 0, N) {
                if (S[i][j] != S[(N + j - a) % N][(i + a) % N]) {
                    symmetric = false;
                }
            }
        }
        if (symmetric) ans += N;
    }
    cout << ans << endl;
    return 0;
}

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

//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long double db;

#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

template<typename T> void print(const T& a, ostream& out){	
	for(auto i: a) out << i << ' ';
	out << endl;
}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

	int h, w;
	cin >> h >> w;
	int ch, cw, dh, dw;
	cin >> ch >> cw >> dh >> dw;
	--ch; --cw; --dh; --dw;

	vector<string> s(h);
	FOR(i, 0, h) cin >> s[i];

	
	vector<int> dx = {-1, 1, 0, 0};
	vector<int> dy = {0, 0, 1, -1};

	auto ok = [&](int x, int y){
		return x >= 0 && x < h && y >= 0 && y < w && s[x][y] == '.';
	};

	deque<pair<int, int>> q;
	vector<vector<int>> d(h, vector<int>(w, -1));
	d[ch][cw] = 0;
	q.push_front({ch, cw});
	while(!q.empty()){
		int x = q.front().X, y = q.front().Y;		
		q.pop_front();
		
		FOR(k, 0, 4){
			int xx = x + dx[k], yy = y + dy[k];
			if (ok(xx, yy) && (d[xx][yy] == -1 || d[xx][yy] > d[x][y])){
				d[xx][yy] = d[x][y];
				q.push_front({xx, yy});
			}
		}
		
		FOR(DX, -2, 3) FOR(DY, -2, 3){
			int xx = x + DX, yy = y + DY;
			if (ok(xx, yy) && (d[xx][yy] == -1 || d[xx][yy] > d[x][y] + 1)){
				d[xx][yy] = d[x][y] + 1;
				q.push_back({xx, yy});
			}
		}
	}

	cout << d[dh][dw] << endl;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
    return 0;
}


Measured memory_bytes: 8804
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;

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

    string s;
    cin >> s;
    long long dp[3] = {}, nxt[3] = {};
    int cnt = 0;
    long long Pow[100010] = {};
    Pow[0] = 1;
    for (int i = 1; i < 100010; i++)
        Pow[i] = 3 * Pow[i - 1] % mod;
    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == '?')
        {
            nxt[0] = 3 * dp[0] + Pow[cnt];
            nxt[1] = 3 * dp[1] + dp[0];
            nxt[2] = 3 * dp[2] + dp[1];
            cnt++;
        }
        else if (s[i] == 'A')
        {
            nxt[0] = dp[0] + Pow[cnt];
            nxt[1] = dp[1];
            nxt[2] = dp[2];
        }
        else if (s[i] == 'B')
        {
            nxt[0] = dp[0];
            nxt[1] = dp[1] + dp[0];
            nxt[2] = dp[2];
        }
        else
        {
            nxt[0] = dp[0];
            nxt[1] = dp[1];
            nxt[2] = dp[2] + dp[1];
        }
        dp[0] = nxt[0] % mod;
        dp[1] = nxt[1] % mod;
        dp[2] = nxt[2] % mod;
        //cout << dp[0] << " " << dp[1] << " " << dp[2] << endl;
    }
    cout << dp[2] << endl;
}

Measured memory_bytes: 1232
#include <stdio.h>
#include <queue>

int N, M, x, i;

std::priority_queue<int> pq;

int main(void) 
{
	scanf("%d%d", &N, &M);

	for(i = 0; i < N; i++) {
		int a;
		scanf("%d",&x);
		pq.push(x);
	}

	for(i = 0; i < M; i++) {
		int price = pq.top(); pq.pop();
		price /= 2;
		pq.push(price);
	}

	long long sum = 0;
	
	for(i = 0; i < N; i++) {
		sum += pq.top(); pq.pop();
	}

	printf("%lld", sum);

	return 0;
}

Measured memory_bytes: 892
#include <stdio.h>
int main (void){
int a;  
 int b;
 int d;
 int r ;
double f ;
 scanf("%d\n",&a) ;  
scanf("%d\n",&b) ;
 d=a/b ;
 r=a%b ;
 f=(double)a/(double)b ;
 printf("%d %d %lf\n",d,r,f) ;
return 0 ;  }

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

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

int main()
{
    int n,k; cin >> n >> k;
    vector< bool > check(n,false);
    for( int i = 0; i < k; ++i )
    {
        int d; cin >> d;
        for( int j = 0; j < d; ++j )
        {
            int a; cin >> a;
            a--; check[a] = true;
        }
    }
    
    int ans = 0;
    for( int i = 0; i < check.size(); ++i )
    {
        if( check[i] == false )
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}



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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;

  int N;
  cin >> N;
  vector<int> A(N);
  int max = 0, secondmax = 0;
  for(int i = 0; i < N; ++i){
    cin >> A.at(i);
    if(A.at(i) >= max){
      secondmax = max;
      max = A.at(i);
    } else if(A.at(i) >= secondmax){
      secondmax = A.at(i);
    }
  }
  for(int i = 0; i < N; ++i){
    if(A.at(i) == max){
      cout << secondmax << " " <<endl;
    } else{
      cout << max << " " <<endl;
    }
  }

}

Measured memory_bytes: 2560