akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  ll N, Q;
  cin >> N >> Q;
  vector<triple> a;
  rep(i, N) {
    ll S, T, X;
    cin >> S >> T >> X;
    a.emplace_back(X, S, T);
  }
  sort(all(a)); // Sorted by X.
  // For Debug
  // rep(i, N) {
  //   ll S, T, X;
  //   tie(X, S, T) = a[i];
  //   cout << "X: "<<X<<", S: "<<S<<", T: "<<T << endl;
  // }

  set<P> D; // The set of pairs. The pair is (Di, i).
  rep(i, Q) {
    ll d;
    cin >> d;
    P p(d, i);
    D.emplace(p);
  }
  // for (auto x : D) {
  //   cout << x.first<<", "<<x.second << endl;
  // }

  vector<ll> ans(Q, -1);

  // Here, D is sorted. We want to know the position of Si-0.5-Xi and Ti-0.5-X in D.
  // We check [S-X-1, T-X-1] by upper_bound (S-X-1 < Q[i..j] <= T-X-1).
  rep(i, N) {
    ll S, T, X;
    tie(X, S, T) = a[i];

    P sp(S-X-1, INF); // the second is dummy.
    auto sit = D.upper_bound(sp);
    P tp(T-X-1, INF); // the second is dummy.
    auto tit = D.upper_bound(tp);

    // For Debug
    // cout << i << ": " << endl;
    // cout << "X: "<<X<<", S: "<<S<<", T: "<<T << endl;
    // cout << "S-X-1: " << S-X-1 << ", T-X-1:" << T-X-1 << endl;
    // if (sit != D.end()) {
    //   cout << "*sit: (" << (*sit).first<<", "<<(*sit).second << ") " << endl;
    // }
    // if (tit != D.end()) {
    //   cout << "*tit: (" << (*tit).first<<", "<<(*tit).second << ") " << endl;
    // }
    // for (auto it = sit; it != tit; ++it) {
    //   cout << "(" << (*it).first<<", "<<(*it).second << ") " << endl;
    // }

    for (auto it = sit; it != tit; ++it) {
      ans[(*it).second] = X; // Set distance
    }
    D.erase(sit, tit);

    // cout << "D:" << endl;
    // for (auto x : D) {
    //   cout << x.first<<", "<<x.second << endl;
    // }
    // cout << endl;
  }

  rep(i, Q) {
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 21228
n = int(input())
s = input()

c = 'RGB'
cnt = [[0 for _ in range(n + 1)] for _ in range(3)]
for i in range(n - 1, -1, -1):
     for j in range(3):
         cnt[j][i] = cnt[j][i + 1]
         if s[i] == c[j]:
             cnt[j][i] += 1
ans = 0
for i in range(n - 3):
    for j in range(i + 1, n - 1):
        if s[i] == s[j]:
            continue
        for k in range(3):
            if s[i] == c[k] or s[j] == c[k]:
                continue
            ans += cnt[k][j + 1]
            if 2 * j - i < n and s[2 * j - i] == c[k]:
                ans -= 1
print(ans)

Measured memory_bytes: 68584
N = int(input())
count = [0] * (N + 1)
for x in range(1, 100):
    if 2 * ((x + 1) ** 2) + 4 > 2 * N:
        break
    for y in range(1, 100):
        if ((x + y) ** 2 + (y + 1) ** 2 + (1 + x) ** 2) > 2 * N:
            break
        for z in range(1, 100):
            # print(x, y, z)
            score = ((x + y) ** 2 + (y + z) ** 2 + (z + x) ** 2) // 2
            if score > N:
                break
            else:
                count[score] += 1
for i in range(1, N + 1):
    print(count[i])


Measured memory_bytes: 9128
N,K = map(int,input().split())

p = list(map(int,input().split()))
max = 0
for i in range(K):
    max += (1+p[i])/2
tmp = max
for i in range(K,len(p)):
    tmp -= (1+p[i-K])/2
    tmp += (1+p[i])/2
    #print(max)
    if max < tmp:
        max = tmp
    #print(max)    
print(max)




#ロケットペンシル方式

Measured memory_bytes: 24804
import * as fs from 'fs';

const input = fs.readFileSync('/dev/stdin', 'utf8').split(/[ \n]/);
const a: string = input[0];
const b: string = input[1];

let ansA: string = '';
let ansB: string = '';

for (let i = 0; i < +b; i++) {
  ansA += a;
}
for (let i = 0; i < +a; i++) {
  ansB += b;
}

let list = [ansA, ansB];
list.sort();

if (list[0] == ansA) {
  console.log(+ansA);
} else {
  console.log(+ansB);
}


Measured memory_bytes: 7372
#include <cstdio>

int main() {
    int a, b;
    char o;
    scanf("%d %c %d", &a, &o, &b);
    for (;;) {
        if (o == '?') {
            return 0;
        }
        int r;
        if (o == '+') {
            r = a + b;
        }
        if (o == '-') {
            r = a - b;
        }
        if (o == '*') {
            r = a * b;
        }
        if (o == '/') {
            r = a / b;
        }
        printf("%d\n", r);
        scanf("%d %c %d", &a, &o, &b);
    }
}


Measured memory_bytes: 2584
n, m = map(int, input().split())
if n%2 == 1:
  for i in range(m):
    print(m-i, m+1+i)
else:
  for i in range(m):
    if 4*(i+1) > n:
      print(m-i, m+2+i)
    else:
      print(m-i, m+1+i)

Measured memory_bytes: 9276
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()

class modfact(object):
    def __init__(self, n):
        fact, invfact = [1] * (n + 1), [1] * (n + 1)
        for i in range(1, n + 1): fact[i] = i * fact[i - 1] % MOD
        invfact[n] = pow(fact[n], MOD - 2, MOD)
        for i in range(n - 1, -1, -1): invfact[i] = invfact[i + 1] * (i + 1) % MOD
        self._fact, self._invfact = fact, invfact

    def inv(self, n):
        return self._fact[n - 1] * self._invfact[n] % MOD

    def fact(self, n):
        return self._fact[n]

    def invfact(self, n):
        return self._invfact[n]

    def comb(self, n, k):
        if k < 0 or n < k: return 0
        return self._fact[n] * self._invfact[k] % MOD * self._invfact[n - k] % MOD

    def perm(self, n, k):
        if k < 0 or n < k: return 0
        return self._fact[n] * self._invfact[n - k] % MOD

def resolve():
    k = int(input())
    n = len(input())
    mf = modfact(n + k)
    ans = 0
    for i in range(n, n + k + 1):
        ans += mf.comb(n + k, i) * pow(25, n + k - i, MOD)
        ans %= MOD
    print(ans)
resolve()

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int X,N;
  cin>>X>>N;
  vector<int>p(N);
  for(int i=0;i<N;i++)cin>>p[i];
  sort(rng(p));
  int MIN=INT_MAX;
  int ans;
  for(int i=101;i>=-1;i--){
    bool ok=true;
    for(int j=0;j<N;j++)if(p[j]==i)ok=false;
    if(ok&&MIN>=abs(i-X))MIN=abs(i-X),ans=i;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3640
#[allow(unused_imports)]
use std::collections::HashSet;

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let hw = read_vec::<usize>();
    let h = hw[0];
    let w = hw[1];

    let mut shogai_yoko : Vec<Vec<usize>> = Vec::with_capacity(h);
    let mut shogai_tate : Vec<Vec<usize>> = Vec::with_capacity(w);
    for _i in 0..w {
        let v : Vec<usize> = Vec::with_capacity(h);
        shogai_tate.push(v)
    }
    
    for i in 0..h {
        let mut v : Vec<usize> = Vec::with_capacity(w);
        let s = read::<String>();
        for (j, c) in s.chars().enumerate() {
            if c == '#' {
                v.push(j);
                shogai_tate[j].push(i)
            }
        }
        if v.is_empty() || v[v.len()-1] < w - 1 {
            v.push(w);
        }
        shogai_yoko.push(v);
    }
    for j in 0..w {
        let v = &mut shogai_tate[j];
        if v.is_empty() || v[v.len() - 1] < h - 1 {
            v.push(h)
        }
    }


    let answer = solve(h, w, &shogai_yoko, &shogai_tate);
    println!("{}", answer);
}

fn solve(h: usize, w: usize, shogai_yoko: &[Vec<usize>], shogai_tate: &[Vec<usize>]) -> usize {
     // (yoko, tate)
     let mut dp : Vec<Vec<usize>> = Vec::with_capacity(h);
     for _i in 0..h {
        let v : Vec<usize> = vec![0; w];
        dp.push(v);
     }

     // yoko
     for i in 0..h {
        let mut from = 0;
        for x in &shogai_yoko[i] {
            let d = x - from;
            if d > 1 {
                for j in from..*x {
                    dp[i][j] = d - 1;
                }
            }
            from = x + 1;
        }
    }

    // tate (and total)
    let mut max = 0;
    let limit = (h-1) + (w-1);
    for j in 0..w {
        let mut from = 0;
        for x in &shogai_tate[j] {
            let d = x - from;
            if d > 0 {
                for i in from..*x {
                    let val = dp[i][j] + (d - 1);
                    if val > max {
                        max = val;
                        if max == limit {
                            return max + 1;
                        }
                    }
                }
            }
            from = x + 1;
        }
    }
    return max + 1
}


Measured memory_bytes: 127228
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main(){
  int a, b;
  cin >> a >> b;
  //if(x=='a'||x=='i'||x=='u'||x=='e'||x=='o')){cout << "vowel" << endl;}
  //else{cout << "consonant" << endl;}
  //int x = a*b;
  //int y = c*d;
  if(a<b){
    if(a==1){cout << "Alice" << endl;}
    else{cout << "Bob" << endl;}
  //else(y<x){cout < x << endl;}
  }else if(b<a)
    if(b==1){cout << "Bob" << endl;}
    else{cout << "Alice" << endl;}
  else{cout << "Draw" << endl;}
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

static class Ex{
	public static int LowerBound<T>  (this IList<T> a, T v) where T:IComparable<T> {
		if(a[0].CompareTo(v) >= 0) return 0;
		int l = 0, r = a.Count;
		while(r - l > 1){
			int c = (r + l) / 2;
			if(a[c].CompareTo(v) < 0) l = c;
			else r = c;
		}
		return r;
	}
	public static int UpperBound<T>  (this IList<T> a, T v) where T:IComparable<T> {
		if(a[0].CompareTo(v) > 0) return 0;
		int l = 0, r = a.Count;
		while(r - l > 1){
			int c = (r + l) / 2;
			if(a[c].CompareTo(v) <= 0) l = c;
			else r = c;
		}
		return r;
	}
	public static String YN(this bool b) {
		return b ? "Yay" : ":(";
	}
	public static bool chMax<T> (ref T a, T b) where T:IComparable<T> {
		if(a.CompareTo(b) < 0){ a = b; return true;}
		return false;
	}
}

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long l = 0, r = (long) 1e9;
		while(r - l > 1){
			long c = (r + l) / 2;
			if(Count(c) >= M){
				l = c;
			} else {
				r = c;
			}
		}
		//Console.WriteLine("l:{0}",l);
		long[] sum = new long[N + 1];
		for(int i=0;i<N;i++){
			sum[i + 1] = sum[i] + A[i];
		}
		long lsum = 0;
		long lcnt = 0;
		for(int i=0;i<N;i++){
			long v = A[i];
			int idx = A.LowerBound(l - v);
			lsum += (sum[N] - sum[idx]) + (N - idx) * v;
			lcnt += (N - idx);
		}
		if(lcnt > M){
			lsum -= (lcnt - M) * l;
		}
		
		Console.WriteLine(lsum);
		
		
		
	}
	
	long Count(long t){
		long cnt = 0;
		for(int i=0;i<N;i++){
			long v = A[i];
			int idx = A.LowerBound(t - v);
			cnt += N - idx;
		}
		return cnt;
	}
	
	
	
	
	int N;
	long M;
	long[] A;
	public Sol(){
		var d = rla();
		N = (int)d[0]; M = d[1];
		A = rla();
		Array.Sort(A);
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 21472
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

enum { AC, WA };
int q_ac_table[100000] = {0};
int q_wa_table[100000] = {0};
int nac = 0, nwa = 0;

void search_table(int idx, int acwa) {
    if(q_ac_table[idx]) {
        return;
    }

    if(acwa == AC) {
        nac++;
        nwa += q_wa_table[idx];
        q_ac_table[idx] = 1;
    }
    else if(acwa == WA) {
        q_wa_table[idx]++;
    }
}

int main(void) {
    int nq, ns;
    scanf("%d %d", &nq, &ns);

    for(int i = 0; i < ns; i++) {
        int p; char acwa[3];
        scanf("%d %s", &p, acwa);
        int res = (acwa[0] == 'A') ? AC : WA;
        search_table(p - 1, res);
    }

    printf("%d %d\n", nac, nwa);
}


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

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

    string ans = "No";
    while (N > 0)
    {
        if (N % 10 == 9)
        {
            ans = "Yes";
        }
        N /= 10;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<cmath>
#include<algorithm>
#include<map>
#include<vector>
#include<sstream>
#include<iostream>
using namespace std;
int main(void){

    int n;
    string s[300];
    while(cin>>n,n!=0){
        for(int i = 0;i < n;i++)cin>>s[i];
        int ans = 0;
        // hor
        for(int i = 0;i < n;i++){
            int cnt = 0;
            for(int j = 0;j < n;j++){
                if(s[i][j] == '1')ans = max(ans,++cnt);
                else cnt = 0;
            }
        }

        //ver
        for(int j = 0;j < n;j++){
            int cnt = 0;
            for(int i = 0;i < n;i++){
                if(s[i][j] == '1')ans = max(ans,++cnt);
                else cnt = 0;
            }
        }

        //dia_1
        int dp[300][300] = {};
        for(int i = 0;i < n;i++){
            for(int j = 0;j < n;j++){
                if(s[i][j] == '1'){
                    if(i == 0 || j == 0){
                        dp[i][j] = 1;
                        ans = max(ans,dp[i][j]);
                    }
                    else{
                        dp[i][j] = dp[i-1][j-1] + 1;
                        ans = max(ans,dp[i][j]);
                    }
                }
            }
        }

        //dia_2
        int dp2[300][300] = {};
        for(int i = 0;i < n;i++){
            for(int j = n-1;j >= 0;j--){
                if(s[i][j] == '1'){
                    if(i == 0 || j == n-1){
                        dp2[i][j] = 1;
                        ans = max(ans,dp2[i][j]);
                    }
                    else{
                        dp2[i][j] = dp2[i-1][j+1] + 1;
                        ans = max(ans,dp2[i][j]);
                    }
                }
            }
        }
        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 2004
#include<bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
long long  n,m;
int main() {
	IO
	long long n;
	cin>>n;
	string s="";
	while(n!=0)
    {
        n--;
        char c = 'a'+n%26;
        n/=26;
        s=s+c;

    }
    reverse(s.begin(),s.end());
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define Rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define Repe(i,a,b) for(register int i=(a);i>=(b);--i)
#define pb push_back
#define mp make_pair
#define Chkmax(a,b) a=a>b?a:b
#define Chkmin(a,b) a=a<b?a:b
typedef unsigned long long uint64;
typedef unsigned int uint32;
typedef long long ll;

using namespace std;

namespace IO
{
    const uint32 Buffsize=1<<15,Output=1<<23;
    static char Ch[Buffsize],*S=Ch,*T=Ch;
    inline char getc()
    {
        return((S==T)&&(T=(S=Ch)+fread(Ch,1,Buffsize,stdin),S==T)?0:*S++);
    }
    static char Out[Output],*nowps=Out;
    
    inline void flush(){fwrite(Out,1,nowps-Out,stdout);nowps=Out;}

    template<typename T>inline void read(T&x)
    {
        x=0;static char ch;T f=1;
        for(ch=getc();!isdigit(ch);ch=getc())if(ch=='-')f=-1;
        for(;isdigit(ch);ch=getc())x=x*10+(ch^48);
        x*=f;
    }

    template<typename T>inline void write(T x,char ch='\n')
    {
        if(!x)*nowps++='0';
        if(x<0)*nowps++='-',x=-x;
        static uint32 sta[111],tp;
        for(tp=0;x;x/=10)sta[++tp]=x%10;
        for(;tp;*nowps++=sta[tp--]^48);
        *nowps++=ch;
    }
}
using namespace IO;

inline void file()
{
#ifndef ONLINE_JUDGE
    FILE*DSA=freopen("water.in","r",stdin);
    FILE*SDU=freopen("water.out","w",stdout);
#endif
}

const int MAXN=5e5+7;

static int n,m;

vector<int>ed[MAXN];

static int a[MAXN],b[MAXN];

void init()
{
	read(n);read(m);
	Rep(i,1,n)read(a[i]),read(b[i]),a[i]=max(0,a[i]-b[i]);
	static int u,v;
	Rep(i,1,m)read(u),read(v),ed[u].pb(v),ed[v].pb(u);
}

static ll dp[MAXN],sm[MAXN];

static int fa[MAXN],sta[MAXN];

static int flg;

inline int Find(int u)
{return u==fa[u]?u:fa[u]=Find(fa[u]);}

static int vis[MAXN];

inline void getdp(int u)
{
	sm[u]=b[u],dp[u]=a[u];
	vis[u]=1;
	for(register int v:ed[u])
	{
		int ver=Find(v);
		if(ver!=u&&vis[v])
		{
			Chkmin(dp[u],max(dp[ver],a[u]-sm[ver]));
			sm[u]+=sm[ver];
			fa[ver]=u;
		}
	}
}

inline bool cmp(int x,int y){return a[x]<a[y];}

inline void solve()
{
	Rep(i,1,n)fa[i]=sta[i]=i;sort(sta+1,sta+n+1,cmp);
	a[0]=-1;
	Rep(i,1,n)getdp(sta[i]);
	cout<<sm[sta[n]]+dp[sta[n]]<<endl;
}

int main()
{
	init();
	solve();
    return 0;
}


Measured memory_bytes: 28156
#include <bits/stdc++.h>
using namespace std;
int n;
int a[10009];
int ssss(int i,int is)
{
    if(i==n&&is==1)return 1;
    if(i==n)return 0;
    if(a[i]%2==0)
        return ssss(i+1,1)+(2*ssss(i+1,is));
    else
    return ssss(i+1,is)+(2*ssss(i+1,1));

}
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    cout<<ssss(0,-1);
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(readline())


def ints(): return list(map(int, readline().split()))


def _make_minimum_prime(N: int):
    # xの最小の素因数表を作成
    min_prime = [x for x in range(N + 1)]
    # min_prime[0] = 0  # 0と1は素数ではない
    # min_prime[1] = 1
    for i in range(2, int(N ** 0.5) + 1):
        if min_prime[i] == i:  # 素数だったら更新
            for j in range(2 * i, N + 1, i):  # iの倍数は素数でない
                if min_prime[j] == j:
                    min_prime[j] = i
    return min_prime


min_prime = _make_minimum_prime(10**6)


from collections import Counter


def fast_factorization(N: int):
    # -> List[Tuple[int,int]] (素数,冪数)を格納
    # 最小素数配列min_primeを使ってO(log N)で因数分解
    if N == 1:
        return Counter()  # 1は素数ではない
    # 素因数分解
    arr = []
    tmp = N
    while tmp != 1:
        p = min_prime[tmp]
        tmp //= p
        arr.append(p)

    return Counter(arr)


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from math import gcd


N = a_int()
A = ints()

# setかはすぐわかる
# setでなければ not coprime
# pairは互いに素かをみればいいのか
# つまり因数分解して足してったときにすべての素数のべき数が1以下であれば良い

g_set = 0
cnt = defaultdict(lambda: 0)
flg = 1  # pairwiseであるフラグ
for a in A:
    g_set = gcd(g_set, a)
    if flg:
        for p, n in fast_factorization(a).items():
            if cnt[p] != 0:
                flg = 0
            cnt[p] += n


# print(cnt)
# for v in cnt.values():
#     if v > 1:
#         flg = 0
#         break

if g_set > 1:
    print('not coprime')
elif flg:
    print('pairwise coprime')
else:
    print('setwise coprime')


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

int main(){
  long long a,b;
  cin >> a >> b;
  long long answer = a+b;
  if(answer % 2 == 0){
    answer /= 2;
    cout << answer << endl;
  }else{
    cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int digit_sum(int n) {
  int sum=n%10;
  while(n!=0) {
    n/=10;
    sum+=n%10;
  }
  return sum;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}




int main() {
  int n;
  cin >> n;
  char s[n];
  cin >> s;
  int x=0,ans=0;
  REP(i,n) {
    if(s[i]=='I') x++;
    if(s[i]=='D') x--;
    ans=max(ans,x);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST

main :: IO ()
main = getLine >>= putStrLn . solve

solve :: String -> String
solve s 
  | lmm && rmm = "AMBIGUOUS"
  | lmm = "MMYY"
  | rmm = "YYMM"
  | otherwise = "NA"
  where
    (l, r) = splitAt 2 s
    lmm = canBeMM $ read l
    rmm = canBeMM $ read r

canBeMM n = 1 <= n && n <=12 



Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
#define data_type long long

int main()
{
    data_type a,b,c,ans;
    cin>>a>>b>>c;
    ans=(a/(b+c))*b+min(b,a%(b+c));
    if(b==0)
      cout<<0<<endl;
    else if(b+c>=a)
      cout<<min(a,b)<<endl;
    else
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n,m;
    int S[205];
    while(cin >> n >> m, !(n==0 && m==0)){
        for(int i=0; i<n+m; i++){
            int s;
            cin >> s;
            S[i] = s;
        }
        int a=0,b=0;
        for(int i=0; i<n; i++){a += S[i];}
        for(int i=n; i<n+m; i++){b += S[i];}
        if((a+b)%2==1){cout << -1 << endl;}
        else{
            int ans1=105,ans2=105;
            for(int i=0; i<n; i++){
                for(int j=n; j<n+m; j++){
                    if(S[i]-S[j] == (a-b)/2 && ans1+ans2 > S[i]+S[j] ){
                        ans1=S[i];
                        ans2=S[j];
                    }
                }
            }
            if(ans1==105 && ans2==105)cout<< -1 << endl;
            else cout << ans1 << " " << ans2 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1160
# 052_a
A, B, C, D = map(int, input().split())
S1=A*B
S2=C*D

if (1<=A&A<=10**4)&(1<=B&B<=10**4)&(1<=C&C<=10**4)&(1<=D&D<=10**4):
    if S1>S2:
        print(S1)
    elif S1<=S2:
        print(S2)


Measured memory_bytes: 9048
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int w,h,n;
  cin >> w >> h >> n;
  vector<int> x(n),y(n),a(n);
  rep(i,n) cin >> x[i] >> y[i] >> a[i];
  
  int xl = 0,xu = w,yl = 0,yu = h;
  rep(i,n){
    if(a[i]==1){
      xl = max(xl,x[i]);
    }
    else if(a[i]==2){
      xu = min(xu,x[i]);
    }
    else if(a[i]==3){
      yl = max(yl,y[i]);
    }
    else{
      yu = min(yu,y[i]);
    }
  }
  
  if(xu-xl>0&&yu-yl>0){
    cout << (xu-xl)*(yu-yl) << "\n";
  }
  else{
    cout << 0 << "\n";
  }
  
  return 0;
}
			

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

int main(void){
    int n, m, sum=0, b, c=0;
    cin >> n >> m;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
        sum += a[i];
    }
    b = (sum%(4*m) == 0) ? sum/(4*m) : sum/(4*m)+1;
    for(int i=0; i<n; i++){
        if(a[i] >= b) c++;
        if(c == m){
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}

Measured memory_bytes: 3568
<?php

fscanf(STDIN, "%d", $n);
$p_arr = [];
for ($i = 0; $i < $n; ++$i) {
    $p_arr[] = trim(fgets(STDIN));
}

$max = max($p_arr);
$total = array_sum($p_arr);
echo ($total - $max) + $max / 2;


Measured memory_bytes: 4728
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

/**
 * エラトステネスの篩を用いた実装
 *
 * @author kou
 *
 */
public class Main {

    public static void main(String[] args) {
        boolean[] isPrime = new boolean[100000 + 1];
        Arrays.fill(isPrime, true);
        for (int i = 2; i <= Math.sqrt(100000); i++) {
            if (!isPrime[i]) {
                continue;
            }

            for (int j = i + 1; j <= 100000; j++) {
                if (!isPrime[j]) {
                    continue;
                }
                if (j % i == 0) {
                    isPrime[j] = false;
                }
            }
        }

        Set<Integer> primeSet = new HashSet<Integer>();
        for (int i = 2; i <= 100000; i++) {
            if (isPrime[i]) {
                primeSet.add(i);
            }
        }

        Map<Integer, Integer> like2017Map = new HashMap<Integer, Integer>();
        like2017Map.put(-1, 0);
        int count = 0;
        for (int i = 1; i <= 100000; i += 2) {
            if (primeSet.contains(i) && primeSet.contains((i + 1) / 2)) {
                count++;
            }
            like2017Map.put(i, count);
        }

        Scanner scan = new Scanner(System.in);
        int q = Integer.parseInt(scan.next());
        for (int i = 0; i < q; i++) {
            int l = Integer.parseInt(scan.next());
            int r = Integer.parseInt(scan.next());
            System.out.println(like2017Map.get(r) - like2017Map.get(l - 2));
        }
        scan.close();
    }
}


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

int main() {
	int a, b;
	cin >> a >> b;
	cout << (a + b + 1) / 2;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

整数xを整数Nで割って小数点以下を切り上げる時、
代わりに整数(x+N-1)を整数Nで割って小数点以下を切り捨てることで求められる
そして、プログラムにおいて整数型同士の割り算は小数点以下が切り捨てられるので、上のコードのようになる
*/

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    k=int(input())
    lis=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    print(lis[k-1])
if __name__=='__main__':
    main()

Measured memory_bytes: 3060
def main():
    import math
    a,b,h,m = map(int,input().split())
    mang = m*6
    hang = h*30+m*0.5
    arg = abs(hang-mang)
    arg = min(360-arg,arg)
    l = a**2+b**2-2*a*b*math.cos(arg/180*math.pi)
    print(l**0.5)

if __name__ == "__main__":
    main()


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

using namespace std;

int main() {
	int sum = 0;
	vector<int> a(3);
	for (int i = 0; i < 3; i++) {
		cin >> a[i];
		sum += a[i];
	}
	int m = max(a[0], max(a[1], a[2]));
	if (sum % 2 == 3 * m % 2) {
		cout << (3 * m - sum) / 2 << endl;
	}
	else {
		cout << (3 * m + 3 - sum) / 2 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;

void main(){
	int n = readln.chomp.to!int;
	
	BigInt ans = BigInt(0);
	BigInt leftover = 0;
	
	foreach(i; 0 .. n){
		long a = readln.chomp.to!int;
		if(a <= leftover){
			ans += a;
			leftover = 0;
			}
		else{
			ans += leftover;
			leftover = a - leftover;
			ans += leftover / 2;
			leftover %= 2;
			}
		}
	
	ans.writeln;
	
	}

Measured memory_bytes: 1276
#include <iostream>

 

using namespace std;

 

int main()
{
    int i, x;
    
    for(i=1; i<=10000; i++)
    {
        cin >> x;
        if(x==0)
        break;
        cout << "Case " << i << ": " << x << endl;
        
    }
} 


Measured memory_bytes: 3016
while True:
    try:
        v = list(map(int, input().split(',')))
        l =[0] + v[:10]
        v1 = v[-2]
        v2 = v[-1]
        t = float(sum(l)) / (v1 + v2)
        d = t * v1

        for i in range(1,11):
            d -= l[i]
            if d <= 0:
                break
        print(i)

    except EOFError:
        break

Measured memory_bytes: 7608
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
from decimal import Decimal
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m,K = inpl()
s = [input() for _ in range(n)]
res = INF
for pat in itertools.product([0,1], repeat=n-1):
    pat = list(pat) + [0]
    group = []
    tmp = []
    for i,j in enumerate(pat):
        tmp += [i]
        if j or i == n-1:
            group += [tmp]
            tmp = []
    
    ln = len(group)
    white = [[0]*ln for _ in range(m)]
    ccc = set()
    cnt = pat.count(1) 
    ok = True
    for i in range(m):
        for j,z in enumerate(group):
            for k in z:
                if s[k][i] == '1':
                    white[i][j] += 1
            if max(white[i]) > K:
                ok = False
                break
    if not ok: continue
    
    now = [0] * ln
    for i in range(m):
        ok = True
        for j in range(ln):
            if now[j] + white[i][j] > K:
                ok = False
                break
        if ok:
            for j in range(ln):
                now[j] += white[i][j]
        else:
            cnt += 1
            for j in range(ln):
                now[j] = white[i][j]
    res = min(res, cnt)
print(res)

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

using ll = long long int;
using bigint = int64_t;

#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define bitcount __builtin_popcount
#define endl "\n"
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define deb(x) cout << #x << " = " << x << endl;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(ll i = a; i <= b; i++)
#define ffo(i, a, b) for(ll i = a; i >= b; i--)
#define ffi(i,a,b,c) for(ll i = a ; i <= b ; i += c)
#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int mod = 1000000007;

void io_set() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

vector < ll > g[200005];
bool vis[200005];
ll c = 1;

void dfs(ll s) {
    vis[s] = true;
    for (auto it : g[s]) {
        if (!vis[it]) c++, dfs(it);
    }
}

void solve() {
    ll n, m, u, v, ans = 0; cin >> n >> m;
    rep(i, m) {
        cin >> u >> v;
        g[u].pb(v), g[v].pb(u);
    }
    fo(i, 1, n) {
        if (!vis[i]) c = 1, dfs(i), ans = max(ans, c);
    }
    cout << ans << endl;
}

int main() {
    IOS;
    //io_set();
    ll tt = 1;
    //cin >> tt;
    while (tt--) {
        solve();
    }
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vst;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;


const ll mod=(1e+9)+7;
const ll inf=1e+16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)

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

 ll n,res=0;
  cin >> n;
  vvll a(n,vll(n));
  rep(i,0,n){
   rep(j,0,n){
     cin >> a[i][j];
   }
  }
  
  
   rep(i,0,n){
    rep(j,0,n){
      ll l=inf;
      rep(k,0,n){
      if(k==i||k==j) continue;
     if(a[i][j]>a[i][k]+a[k][j]) {
       cout << -1 << endl;
       return 0;
     }
      l=min(l,a[i][k]+a[k][j]);
    }
    if(a[i][j]<l) res+=a[i][j];
   }
  }
  
 
 cout << res/2 << endl;
  
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

ll digitsum(ll n){
    ll res=0;
    while(n>0){
        res+=n%10;
        n/=10;
    }
    return res;
}

int main(){
    ll K;
    cin >> K;
    ll a=0,cnt=0,i=1,last=0;
    while(K>0){
        ll n=(ll)i*pow(10,cnt)+a;
        if (last>=n){
            ++i;
            continue;
        }
        if ((ll)pow(10,cnt)*digitsum(n)>=n){
            cout << n << endl;
            ++i,--K;
            last=n;
        }
        else {
            cnt++;
            a*=10,a+=9;
            i=1;
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
 
#define ll long long int
 
using namespace std;
 
int arr[100005];
 
int main(void)
{
	int n; scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&arr[i]);
	sort(arr,arr+n);
	ll ans = 0;
	if(n%2==0)
	{
		for(int i=0;i<(n/2)-1;i++)
			ans += 2*arr[n-1-i];
		for(int i=0;i<(n/2)-1;i++)
			ans -= 2*arr[i];
		ans += (arr[(n/2)]-arr[(n/2)-1]);	
	}
	else
	{
		ll t1=0; 
		for(int i=0;i<(n/2);i++)
			t1 += 2*arr[n-1-i];
		for(int i=0;i<(n/2)-1;i++)
			t1 -= 2*arr[i];
		t1 -= (arr[(n/2)-1]+arr[n/2]);
		ll t2=0;
		for(int i=0;i<(n/2)-1;i++)
			t2 += 2*arr[n-1-i];
		for(int i=0;i<(n/2);i++)
			t2 -= 2*arr[i];
		t2 += arr[n/2]+arr[n/2+1];
		
		ans = t1<t2 ? t2:t1;		
	}
	printf("%lld",ans);		
	return 0;
}

Measured memory_bytes: 512
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6;
const LL mod = 1000000007ll;

int N,K;
int a[100];

string ans = "Second";

void solve(){
	//石が残りi個のとき、先手が勝てるかどうかをdp[i]とおく
	vector<int> dp(K+1,0);

	for(int i=1;i<=K;i++){
		for(int j=0;j<N;j++){
			if(i>=a[j]) dp[i] |= !dp[i-a[j]];
		}
	}
	if(dp[K]) ans="First";
}
 
int main(){
	cin >> N >> K;
	for(int i=0;i<N;i++) cin >> a[i];
 
	solve();

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

Measured memory_bytes: 640
N = int(input())
X = list(map(int, input().split()))

Max = max(X)
p_min = 1000000000
for i in range(1, 101):
    p = 0
    for j in range(len(X)):
        p += (X[j] - i)**2
    if  p < p_min:
        p_min = p
    else:
        p_min = p_min
print(p_min)


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

int par[100010];
int r[100010];

void init(int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    r[i]=0;
  }
}

int find(int x){
  if(par[x]==x){
    return x;
  }
  else{
    return par[x]=find(par[x]);
  }
}

void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y) return;
  if(r[x]<r[y]) par[x]=y;
  else{
    par[y]=x;
    if(r[x]==r[y]) r[x]++;
  }
}

int main(){
  int n,m;
  cin >> n >> m;
  int x[m],y[m],z[m];
  for(int i=0;i<m;i++){
    cin >> x[i] >> y[i] >> z[i];
    x[i]--;
    y[i]--;
  }
  init(n);
  for(int i=0;i<m;i++){
    unite(x[i],y[i]);
  }
  int count[n];
  for(int i=0;i<n;i++) count[i]=find(i);
  sort(count,count+n);
  int ans=1;
  for(int i=0;i<n-1;i++){
    if(count[i]!=count[i+1]){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define	foreach( gg,itit )	for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define	mp make_pair
#define	pb push_back
#define sz(a) int((a).size())
#define all(a)  a.begin(), a.end()
#define	debug(ccc)	cout << #ccc << " = " << ccc << endl;
#define present(c,x) ((c).find(x) != (c).end())
const double eps = 1e-8;
#define EQ(a,b) (fabs((a)-(b))<eps)
inline int max(int a,int b){return a<b?b:a;}
inline int min(int a,int b){return a>b?b:a;}
inline ll max(ll a,ll b){return a<b?b:a;}
inline ll min(ll a,ll b){return a>b?b:a;}
const int mod = 1e9+7;
const int N = 1e6+10;
const ll inf = 1e18;

ll power(ll a,ll n){
	if(n==0){
		return 1;
	}
	ll b = power(a,n/2);
	b = b*b%mod;
	if(n%2) b= b*a%mod;
	return b;
}

int add(int a,int b){ return (a+b)%mod;}
int mul(int a,int b){ return (ll)a*b%mod;}

ll A[2],dp1[2][N],dp2[N],S[N];
int nextPos[2][N],ar[2][N];
int n; 

ll P1(int pos,int lst);
ll P0(int pos);

ll P1(int pos,int last){
	if(pos==n) return 1;
	ll &ret = dp1[last][pos];
	if(ret!=-1) return ret;
	ret = 0;
	if(nextPos[last][pos-1]==pos) return ret = P0(pos);
	if(ar[last^1][pos]>=nextPos[last][pos-1]){
		ret = (ret + P1(nextPos[last][pos-1],last^1))%mod;
	}
	return ret;
}

ll P0(int pos){
	if(pos==n) return 1;
	ll &ret = dp2[pos];
	if(ret!=-1) return ret;
	ret = 0;
	return ret = (P1(pos+1,0) + P1(pos+1,1))%mod;
}


int main(){
 // 	freopen("nice.in","r",stdin);
 // freopen("nice.out","w",stdout);
	scanf("%d %lld %lld",&n,&A[0],&A[1]);
	REP(i,n){
		scanf("%lld",&S[i]);
	}
	ar[0][n]=n; ar[1][n]=n;
	for(int i=n-1;i>=0;i--){
		REP(j,2){
			nextPos[j][i] = lower_bound(S,S+n,S[i]+A[j]) - S;	
			ar[j][i]=i+1;
			if(nextPos[j][i]==i+1) ar[j][i]=ar[j][i+1];
			// printf("%d %d %d %d\n",i,j,nextPos[j][i],ar[j][i]);  
		}
	}
	FILL(dp1,-1); FILL(dp2,-1);
	printf("%lld\n",P0(0));

	return 0;
}




Measured memory_bytes: 32256
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll,char> P;
typedef pair<P,ll> PP;
typedef vector<vector<ll> > Graph;
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; }
const ll INF = 1e18;

ll n;
vector<ll>x,y,p;


int main(){
    cin >> n;
    x.resize(n);
    y.resize(n);
    p.resize(n);
    rep(i,n)cin>>x[i]>>y[i]>>p[i];
    //前計算
    vector<vector<ll> > dist_x((1<<n),vector<ll>(n,INF));
    vector<vector<ll> > dist_y((1<<n),vector<ll>(n,INF));
    for(int bit=0;bit<(1<<n);bit++){
        rep(i,n){
            if(!((bit>>i)&1))continue;
            rep(j,n){
                chmin(dist_x[bit][j],abs(x[j]-x[i]));
            }
        }
        rep(j,n){
            chmin(dist_x[bit][j],abs(x[j]));
        }
    }
    for(int bit=0;bit<(1<<n);bit++){
        rep(i,n){
            if(!((bit>>i)&1))continue;
            rep(j,n){
                chmin(dist_y[bit][j],abs(y[j]-y[i]));
            }
        }
        rep(j,n){
            chmin(dist_y[bit][j],abs(y[j]));
        }
    }

    
    vector<ll>ans(n+1,INF);
    for(int bit=0;bit<pow(3,n);bit++){
        int tate = 0;
        int yoko = 0;
        int tmp = bit;
        ll res = 0;
        int cnt = 0;
        rep(i,n){
            int amari = tmp%3;
            if(tmp%3==0){
                tate |= (1<<i);
                cnt++;
            }
            if(tmp%3==1){
                yoko |= (1<<i);
                cnt++;
            }
            tmp /= 3;
        }
        rep(i,n){
            ll now = min(dist_x[tate][i],dist_y[yoko][i]) * p[i];
            res += now;
        }
        chmin(ans[cnt],res);
    }
    rep(i,n+1){
        cout << ans[i] << endl;
    }
    /*
    cout << endl;
    rep(i,dist_x.size()){
        rep(j,dist_x[i].size()){
            cout << dist_x[i][j] << endl;
        }
    }
    */
    return 0;
}


Measured memory_bytes: 13068
#include<bits/stdc++.h>
#define pii pair<int, int>
#define fir first
#define sec second
#define ll long long
using namespace std;
const int MAXN = 2e5 + 7;
pii p[MAXN];
int r[MAXN];
ll lazy[MAXN];
int main()
{
    int n, D, A; scanf("%d%d%d", &n, &D, &A);
    for (int i = 1; i <= n; i++) scanf("%d%d", &p[i].fir, &p[i].sec);
    sort(p + 1, p + 1 + n);
    ll ans = 0;
    for (int i = 1, j = 1; i <= n; i++)
    {
        while (j < n && p[j + 1].fir <= (ll)p[i].fir + 2 * D) j++;
        lazy[i] += lazy[i - 1];
        p[i].sec -= lazy[i];
        if (p[i].sec > 0) 
        {
            ll t = (p[i].sec - 1) / A + 1;
            ans += t;
            lazy[i] += t * A; lazy[j + 1] -= t * A;
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 3328
# -*- coding:utf-8 -*-
import sys


def partition(lst, p, r):
    x = lst[r]
    i = p - 1
    for j in range(p, r):
        if lst[j] <= x:
            i += 1
            tmp = lst[i]
            lst[i] = lst[j]
            lst[j] = tmp
    i += 1
    tmp = lst[i]
    lst[i] = lst[r]
    lst[r] = tmp
    return i


if __name__ == "__main__":
    data = [val.split() for val in sys.stdin.readlines()]
    n = int(data[0][0])
    progression = [int(val) for val in data[1]]
    i = partition(progression, 0, n - 1)
    result = [str(val) for val in progression]
    result[i] = "[" + result[i] + "]"
    print(" ".join(result))

Measured memory_bytes: 25076
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def longest_common_subsequence(S, T):
    """compute table dp satisfying: 
    dp[i,j] = LCS(S[:i], T[:j])"""
    LS, LT = len(S), len(T)
    dp = np.zeros((LS + 1, LT + 1), np.int32)
    for n in range(1, LS + 1):
        dp[n, 1:] = dp[n - 1, :-1] + (S[n - 1] == T)  # 左上から
        np.maximum(dp[n], dp[n - 1], out=dp[n])  # 上から
        np.maximum.accumulate(dp[n], out=dp[n])  # 左から
    return dp

def reconstruct_LCS(S, T, dp):
    tmp = []
    i, j = len(S), len(T)
    while i > 0 and j > 0:
        if S[i - 1] == T[j - 1]:
            i, j = i - 1, j - 1
            tmp.append(S[i])
        elif dp[i, j] == dp[i - 1, j]:
            i -= 1
        else:
            j -= 1
    return ''.join(reversed(tmp))

S = np.array(list(readline().decode()), 'U1')[:-1]
T = np.array(list(readline().decode()), 'U1')[:-1]

dp = longest_common_subsequence(S, T)

print(reconstruct_LCS(S, T, dp))


Measured memory_bytes: 62324
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int v[3][3];
int main(){
    rep(i,3){
        rep(j,3){
            cin >> v[i][j];
        }
    }
    bool flag = true;
    rep(i,2){
        if(v[0][i+1]-v[0][i]!=v[1][i+1]-v[1][i])
        flag = false;
        if (v[2][i + 1] - v[2][i] != v[1][i + 1] - v[1][i])
            flag = false;
        if (v[0][i + 1] - v[0][i] != v[2][i + 1] - v[2][i])
            flag = false;
        if (v[i+1][0] - v[i][0] != v[i+1][1] - v[i][1])
            flag = false;
        if (v[i + 1][2] - v[i][2] != v[i + 1][1] - v[i][1])
            flag = false;
        if (v[i + 1][0] - v[i][0] != v[i + 1][2] - v[i][2])
            flag = false;
    }
    if(flag){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv;

void main()
{
    foreach(n; stdin.byLine().map!(to!int))
    {
        bool flag;
        foreach(i; 0..10)
        {
            if(n & 1)
            {
                if(flag) " ".write;
                else flag = true;
                (2 ^^ i).write;
            }
            n >>>= 1;
        }
        writeln;
    }
}

Measured memory_bytes: 1060
def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y,x%y)

n = int(input())
a = [int(i) for i in input().split()]
ra = list(reversed(a))
ans = 0
left = [0]*(n+1)
right = [0]*(n+1)

for i in range(n):
    left[i+1] = gcd(left[i],a[i])
    right[i+1] = gcd(right[i],ra[i])

right = list(reversed(right))

for i in range(n):
    ans = max(ans, gcd(left[i],right[i+1]))

print(ans)



Measured memory_bytes: 14400
N, M, Q = map(int,input().split())
a_d = [list(map(int,input().split())) for _ in range(Q)]

ans = 0
for i1 in range(1,M+1):
    for i2 in range(i1,M+1):
        for i3 in range(i2,M+1):
            for i4 in range(i3,M+1):
                for i5 in range(i4,M+1):
                    for i6 in range(i5,M+1):
                        for i7 in range(i6,M+1):
                            for i8 in range(i7,M+1):
                                for i9 in range(i8,M+1):
                                    for i10 in range(i9,M+1):
                                        A = [i1,i2,i3,i4,i5,i6,i7,i8,i9,i10]
                                        tmp = 0
                                        for a,b,c,d in a_d:
                                            if A[b-1]-A[a-1] == c:
                                                tmp += d
                                        ans = max(ans,tmp)
print(ans)


Measured memory_bytes: 9240