akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<numeric>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//最大公約数
template<class T> T gcd(T a, T b)
{
	while (true)
	{
		T r;
		if (a%b == 0) return b;
		else
		{
			r = a % b;
			a = b;
			b = r;
		}
	}
}
//最小公倍数
template<class T> T lcm(T a, T b)
{
	return a / gcd(a, b)*b;
}
//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn = 1, Kr = 1, Knr = 1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}
//int型10進数をord桁のstring型2進数に変換する
string binary(int x,int ord)
{
	int y;
	string ans = "";
	for (int i = 0; i < ord; i++)
	{
		y = x / pow(2, ord - 1 - i);
		y %= 2;
		if (y == 0) ans += "0";
		else ans += "1";
	}

	return ans;
}


/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/

int H, W;
int field[55][55];

int d[3] = { -1,0,1 };

void dfs(int x, int y)
{
	field[x][y] = 0;

	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			int nx = x + d[i];
			int ny = y + d[j];
			if (0 <= nx && nx < H && 0 <= ny && ny < W&&field[nx][ny] == 1) dfs(nx, ny);
		}
	}
}

int main()
{
	while (true) {
		cin >> W >> H;

		if (H == 0 && W == 0) break;

		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				cin >> field[i][j];
			}
		}

		int ans = 0;

		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				if (field[i][j] == 1)
				{
					dfs(i, j);
					ans++;
				}
			}
		}

		cout << ans << endl;
	}

	return 0;
}



Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<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; }

const int  M = 1e6 + 5;
int main() {
    int n;cin>>n;
    vec a(n);
    rep(i,n) cin>>a[i];

    vec cnt(M);

    for(int x : a){
        if(cnt [x] != 0){
            cnt[x]=2;
            continue;
        }
        for(int i = x; i< M; i +=x){
            cnt[i]++;
        }
    }

    int  ans=0;
    for(int x : a){
        if(cnt[x] == 1) ans++;
    }

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

Measured memory_bytes: 8004
#include <stdio.h>

int main(void) {
	int n;
	int i;
	if (scanf("%d", &n) != 1) return 1;
	printf("%d:", n);
	for (i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			printf(" %d", i);
			n /= i;
		}
	}
	if (n > 1) printf(" %d", n);
	putchar('\n');
	return 0;
}



Measured memory_bytes: 2076
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FT first
#define SC second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;
const int INF = 1e9;
const double EPS = 1e-9;



int main()
{
  int a, b, c ;
  cin >> a >> b >> c ;
  REP(i,b){
    if((a*(i+1)-c)%b==0){
      cout <<"YES"<<endl ;
      return 0 ;
    }
  }
  
  cout <<"NO"<<endl ;

  return 0 ;
}



Measured memory_bytes: 256
D, G = map(int, input().split())
P, comp = [], []
r = 0
for i in range(D):
  p, c = map(int, input().split())
  P.append(p), comp.append(100 * (i+1) * p + c)
  r += p
for i in range(1<<D):
  _g, _r = 0, 0
  for j in range(D):
    if i>>j & 1:
      _g += comp[j]
      _r += P[j]
  if _g >= G:
    r = min(r, _r)
    continue
  for j in range(D):
    if i>>j & 1:
      continue
    _diff = G - _g
    _p = 100 * (j+1)
    x = int(_diff // _p)
    if _diff % _p > 0:
      x += 1
    if x <= P[j]:
      _r += x
      r = min(r, _r)
print(r)

Measured memory_bytes: 41200
#include <bits/stdc++.h>
#define N 3005
using namespace std;
const int mod = 998244353;
int n, S;
int a[N], f[N];

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

    int ans = 0;
    for(int i = 1; i <= n; ++i) {
        if(a[i] > S) continue;
        else if(a[i] == S) {
            ans = (ans + 1LL * i * (n - i + 1)) % mod;
        } else {
            ans = (ans + 1LL * f[S - a[i]] * (n - i + 1)) % mod;
            for(int j = S; j > a[i]; --j)
                (f[j] += f[j - a[i]]) %= mod;
            f[a[i]] = (f[a[i]] + i) % mod;
        }
    }

    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc177/tasks/abc177_e
#include <bits/stdc++.h>

using namespace std;

#define PVAR(x) (cout << #x"=" << x << endl)

// if all numbers share a prime factor      => not coprime
// if some but not all share a prime factor => setwise
// if no numbers share a prime factor       => pairwise
void test_case() {
  int n;
  cin >> n;
  vector<int> A(n);
  int ma = 0;
  for (int &a : A) {
    cin >> a;
    ma = max(ma, a);
  }

  // find prime factors
  vector<int> pfs(ma + 1);
  int pcount = 0;
  iota(pfs.begin(), pfs.end(), 0);
  for (int i = 2; i * i <= ma; i++) {
    if (pfs[i] == i) {
      pcount++;
      for (int j = i * i; j <= ma; j += i) {
        pfs[j] = i;
      }
    }
  }

  int cf = 0;
  bool pairwise_coprime = true;
  unordered_set<int> fs(pcount);
  for (int i = 0; i < n; i++) {
    int a = A[i];

    // if all numbers share common prime factors it is
    // the gcd over all numbers 
    cf = gcd(cf, a);

    // if a duplicate factor is found the set cannot
    // be pairwise coprime
    if (pairwise_coprime) {
      while (a > 1 && fs.find(pfs[a]) == fs.end()) {
        fs.insert(pfs[a]);
        int f = pfs[a];
        while (a % f == 0) a /= f;
      }

      pairwise_coprime = a == 1;
    }
  }

  // PVAR(common_factor);

  if (pairwise_coprime) {
    cout << "pairwise coprime" << endl;
  } else if (cf == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
}

int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  int i = 1;
  // cin >> i;
  while (i--) {
    test_case();
  }
  
  return 0;
}


Measured memory_bytes: 10992
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>

using namespace std;

int main()
{	
	vector<char> ls;

	int n;
	while(true)
	{
		cin >> n;
		if(n==0)break;
		vector<int> key(n);
		for(int i=0;i<n;i++)
			cin >> key[i];
		string s;
		cin >> s;
		string ans;
		for(int i=0;i<s.size();i++)
		{
			int tmp;
			if('a'<=s[i] and s[i]<='z')
				tmp=s[i]-'a';
			else
				tmp=s[i]-'A'+26;
			int aft=((tmp-key[i%n]+52)%52);
			if(aft<26)
				ans+=('a'+aft);
			else
				ans+=('A'+(aft-26));
		}

		cout << ans << endl;
	}





}



Measured memory_bytes: 3152
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if((n%10)==(n/100)){
            System.out.println("Yes");

        }
        else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35684
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<ll>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  int n,k;
  cin >> n >> k;
  int a[n];
  rep(i,n)cin >> a[i];
  sort(a,a+n);
  int ans=0;
  rep(i,k)ans+=a[i];
  cout << ans << endl;
}


Measured memory_bytes: 3644
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  // 頂点数 - 辺の数

  int N;
  cin >> N;
  
  i64 result = 0;
  F0R(i, N) {
    result += (i64)(i + 1) * (N - i);
  }
  //debug(result);

  F0R(i, N-1) {
    i64 a, b;
    cin >> a >> b;
    if (a > b) swap(a, b);

    result -= a * (N - b + 1);
    //debug(result);

  }
  cout << result;
}
#endif


Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
using namespace std;
#define MAX 2000000
bool isP[MAX];
int ans[MAX];

void make_table(){
  for(int i=0;i<MAX;i++)isP[i]=true;
  isP[0]=isP[1]=false;
  for(int i=2;i*i<MAX;i++){
    if(!isP[i])continue;
    for(int j=i*i;j<MAX;j+=i)isP[j]=false;
  }

  for(int i=1;i<MAX;i++){
    if(isP[i])continue;
    ans[i]=ans[i-1]+1;
  }
  for(int i=MAX-2;i>=0;i--){
    if(isP[i])continue;
    ans[i]=max(ans[i],ans[i+1]);
  }
}

int n;
int main(){
  make_table();
  while(1){
    cin>>n;
    if(n==0)break;
    cout<<(ans[n]>0?ans[n]+1:0)<<endl;
  }
  return 0;
}

Measured memory_bytes: 10924
#include<iostream>
#include<algorithm>
#include <string>
#include <vector>
using namespace std;
int main(){
    string s;
    int n;
    cin >> n;
    int i;
    cin >> s;
    int a;
    cin >> a;
    char c = s[a-1];
    for(i = 0; i< n; i++){
        if(s[i] != c){
            s[i] = '*';
        }
    }
    for(i =0; i<n ;i++){
        cout << s[i];
    }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2332>
 問題文============================================================
 =================================================================
 解説=============================================================

 ================================================================
 */

ll solve(){
    ll res = 0;
    ll N; cin >> N;
    vector<ll> p(N); for(auto& in:p) cin >> in;
    vector<ll> dist(N,LINF); dist[0] = 0;
    queue<ll> q; q.push(0);
    while(q.size()){
        ll n = q.front(); q.pop();
        if(p[n] == 0){
            for(int i = 1; i <= 6;i++){
                if(i + n >= N) break;
                if(dist[i+n] > dist[n] + 1){
                    dist[i+n] = dist[n] + 1;
                    q.push(i+n);
                }
            }
        }else{
            if(dist[n+p[n]] > dist[n]){
                dist[n+p[n]] = dist[n];
                q.push(n+p[n]);
            }
        }
    }
    res = dist[N-1];
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}



Measured memory_bytes: 4612
import math
from functools import reduce
K=int(input())
def gcd(*numbers):
    return reduce(math.gcd, numbers)
ans = 0
for a in range(1, K+1):
    for b in range(1, a+1):
        for c in range(1, b+1):
            if a==b & b==c:
                ans += a
            elif a!=b & b!=c:
                ans += gcd(a,b,c)*6 
            else:
                ans += gcd(a,b,c)*3

print(ans)

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

#include <vector>

int main(){
    int N,W;cin >> N >> W;
    vector<int> w(N),v(N);
    vector<vector<long long>> dp(N+1,vector<long long>(W+1));
    for(int i=0; i<N; i++) cin >> w.at(i) >> v.at(i);
    for(int i=0; i<N; i++) {
        for(int sum_w=0; sum_w <= W; sum_w++) {
            if(sum_w-w.at(i)>=0)dp[i+1][sum_w] = max(dp[i+1][sum_w],dp[i][sum_w-w.at(i)]+v.at(i));
            dp[i+1][sum_w] = max(dp[i+1][sum_w],dp[i][sum_w]);
        }
    } 
    printf("%lld\n",dp[N][W]);
}

Measured memory_bytes: 83176
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> S(N), T(M);
    for (ll i = 0; i < N; i++) {
        cin >> S[i];
    }
    for (ll i = 0; i < M; i++) {
        cin >> T[i];
    }

    constexpr ll MOD = 1e9 + 7;
    vector<vector<ll>> dp(N + 1, vector<ll>(M + 1, 0));

    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j < M; j++) {
            if (S[i] == T[j]) {
                (dp[i + 1][j + 1] += dp[i][j] + 1) %= MOD;
            }
        }

        //累積和を計算
        for (ll j = 0; j < M; j++) {
            (dp[i + 1][j + 1] += dp[i + 1][j]) %= MOD;
        }

        //前の結果に足す
        for (ll j = 0; j <= M; j++) {
            (dp[i + 1][j] += dp[i][j]) %= MOD;
        }
    }

    cout << dp[N][M] + 1 << endl;
}

Measured memory_bytes: 31616
fun main(args: Array<String>) = println(run {
    val (n,k) = readLine()!!.split(" ").map { it.toInt() }
    val h = (1..n).map { readLine()!!.toInt() }.sorted()

    var diff = h[k-1] - h[0]
    var min = diff
    for (i in k..h.lastIndex) {
        diff += (h[i]-h[i-1]) - (h[i-k+1]-h[i-k])
        min = Math.min(min, diff)
    }
    min
})

Measured memory_bytes: 47244
from math import gcd
n = int(input())
a = list(map(int, input().split()))

pref = [0]; suff = [0]

for i in range(n):
    pref.append(gcd(pref[-1], a[i]))

for i in range(n-1, -1, -1):
    suff.append(gcd(suff[-1], a[i]))

suff.reverse()

ans = pref[-1]

for i in range(len(pref)-1):
    ans = max(ans, gcd(pref[i], suff[i+1]))

print(ans)

Measured memory_bytes: 89600
#include <iostream>

using namespace std;

int value[100],weight[100];
//table[i][w] ?????????i????????§???????????´??????w??\?????????????????????????????§???
int table[101][10001];
int main(){
  int N,W;
  cin>>N>>W;
  for(int i=0;i<N;++i){
    cin>>value[i]>>weight[i];
  }

  for(int i=1;i<=N;++i){
    for(int w=1;w<=W;++w){
      if(w<weight[i-1]){
        table[i][w] = table[i-1][w];
      }else{
        table[i][w] = max(table[i-1][w],table[i-1][w-weight[i-1]]+value[i-1]);
      }
    }
  }
  cout<<table[N][W]<<endl;
  return 0;
}

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

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		for(;;)
		{
			int N = sc.nextInt(), M = sc.nextInt(), A = sc.nextInt();
			if (N==0&&M==0&&A==0) break;
			int[][] connect = new int[1000 + 1][N + 1];
			for (int i = 0; i < M; i++)
			{
				int h = sc.nextInt(), p = sc.nextInt(), q = sc.nextInt();
				connect[h][p] = q;
				connect[h][q] = p;
			}
			for (int i = 1000; i > 0; i--)
			{
				if (connect[i][A] != 0)
				{
					A = connect[i][A];
				}
			}
			System.out.println(A);
		}
	}
}
/*
4 4 1
3 1 2
2 2 3
3 3 4
1 3 4
0 0 0
*/

Measured memory_bytes: 16000
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]

# @lru_cache(None)
n=l()[0]
A=l()
d=[0 for i in range(10**5+1)]
s=0
for i in range(n):
    d[A[i]]+=1
    s+=A[i]
q=l()[0]
for i in range(q):
    b,c=l()
    s+=(c-b)*d[b]
    print(s)
    d[c]+=d[b]
    d[b]=0
    


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

plus = 0
minus = 0

for i in range(n):
    if s[i] == '(':
        plus += 1
    else:
        plus -= 1
        if plus < 0:
            minus += 1
        plus = max(plus,0)
        
print('('*minus+s+')'*plus)

Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>

int main()
{
  int n,m,i,j,cnt,ans=0,bit;
  int k[11],s[11][11],p[11];

  scanf("%d%d",&n,&m );

  for(i=0; i<m; i++){
    scanf("%d",&k[i]);
    for(j=0; j<k[i]; j++){
      scanf("%d", &s[i][j]);
    }
  }
  for(i=0; i<m; i++)
    scanf("%d", &p[i]);


    for(bit=0; bit<(1<<n); bit++)
    {
      for(i=0; i<m; i++){
        cnt = 0;
          for(j=0; j<k[i]; j++)
            {
              if(bit & (1<<(s[i][j] - 1)) )
              cnt++;
            }
        if(cnt%2 != p[i])
          break;
        if(i == (m-1))
          ans++;
      }

    }

  printf("%d",ans );
}


Measured memory_bytes: 1736
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;

int main() {
	int K, N, * A, dis;

	cin >> K >> N;

	A = new int[N];

	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	
	sort(A, A + N, less<int>());

	dis = K - A[N - 1] + A[0];

	for (int i = 0; i < N-1; i++) {
		if ( A[i +1] - A[i] > dis) {
			dis = A[i + 1] - A[i];
		}
	}

	cout << K - dis;

	return 0;
}


Measured memory_bytes: 1152
n=int(input())
l=[int(i) for i in input().split()]
ans=0
if n<3:
    print(0)
    exit()
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            chk=[l[i],l[j],l[k]]
            chk.sort()
            if chk[0]+chk[1]>chk[2] and chk[0]!=chk[1] and chk[1]!=chk[2]:
                ans+=1
print(ans)

Measured memory_bytes: 68248
#include <stdio.h>

int main(void) {
	int N, R, T;
	int p[100];
	int haitteru[1000];
	int kara[1000];
	int i, j;
	int buin[100];
	int count = 0;
	if (scanf("%d%d%d", &N, &R, &T) != 3) return 1;
	for (i = 0; i < R; i++) haitteru[i] = kara[i] = 0;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &p[i]) != 1) return 1;
		buin[i] = 0;
	}
	for (i = 0; i < T; i++) {
		for (j = 0; j < R; j++) {
			haitteru[j] += kara[j];
			kara[j] = 0;
		}
		for (j = 0; j < N; j++) {
			buin[j] = (buin[j] + p[j]) % R;
			if (i > 0) kara[buin[j]]++;
			if (haitteru[buin[j]] == 0) count++; else haitteru[buin[j]]--;
		}
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 604
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

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

int main(){
	int A,B;
	while(cin>>A>>B,A||B){
		int sum =abs(A-B);
		int coin[3]={0};
		if(sum/1000){
			coin[2]=(sum/1000);
			sum-=(sum/1000)*1000;
		}
		if(sum/500){
			coin[1]=(sum/500);
			sum -=(sum/500)*500;
		}
		if(sum/100){
			coin[0]=(sum/100);
			sum-=(sum/100)*100;
		}
		cout <<coin[0]<<" "<<coin[1]<<" "<<coin[2]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define REPA(x, v) for(auto&& x:v)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(v.rbegin(),v.rend())
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int K;
    cin >> K;
    vector<ll> A(K);
    REP(i,K) cin >> A[i];
    
    if(A[K-1]!=2){
        pr(-1);return 0;
    }

    ll minnl = 0, minnr = MAXINF;
    while(minnr-minnl > 1){
        ll mid = (minnr+minnl) / 2;

        ll tmp = mid;
        REP(i, K){
            tmp -= tmp%A[i]; 
        }
        if(tmp<=2) minnl = mid;
        else minnr = mid;
    }

    ll maxnl = 0, maxnr = MAXINF;
    while(maxnr-maxnl > 1){
        ll mid = (maxnr+maxnl) / 2;

        ll tmp = mid;
        REP(i, K){
            tmp -= tmp%A[i]; 
        }
        if(tmp>=2) maxnr = mid;
        else maxnl = mid;
    }

    if(maxnr > minnl){
        pr(-1);
        return 0;
    }
    pr(maxnr, minnl);
}

Measured memory_bytes: 4060
def _combination(left, source, n, yields):
    if(len(left) == n):
        yields.append(left)
    else:
        for i in range(len(source)):
            _combination(left + [source[i]], source[i + 1:], n, yields)
def combination(source, n):
    yields = []
    _combination([], source, n, yields)
    return yields

printedLater = []
while True:
    n, s = [int(i) for i in input().split()]
    if((n, s) == (0, 0)):
        break
    printedLater.append(len([x for x in combination(range(10), n) if sum(x) == s]))
for line in printedLater:
    print(line)


Measured memory_bytes: 5604
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//N is number of rows, M is number of columns, D is how we are jumping by
		int N = sc.nextInt(), M = sc.nextInt(), D = sc.nextInt();
		//row[k] which row k is on, col[k] which column k is on
		int row[] = new int[N*M], col[] = new int[N*M];
		for(int i = 1; i<=N; i++){
		  for(int j = 1; j<=M; j++){
		    int k = sc.nextInt();
		    k--; //we make it 0 indexed to make life easier
		    row[k] = i; //store the row val
		    col[k] = j; //store the col val
		  }
		}
		int O[][] = new int[D][N*M/D+1];//represents the distance between (k*D+r) and ((k-1)*D+r)
		int P[][] = new int[D][N*M/D+1];//PSA for O[r]
		for(int r = 0; r<D; r++){//looping through remainders
		  for(int k = 1; k * D + r < N*M; k++){ //looping through all floor of D
		    int f = (k-1) * D + r; //first cell
		    int s = k * D + r; //second cell
		    O[r][k] = Math.abs(row[f] - row[s]) + Math.abs(col[f] - col[s]);
		  }
		}
		for(int r = 0; r<D; r++){
		  for(int k = 1; k * D + r < N*M; k++){
		    P[r][k] = P[r][k-1] + O[r][k]; //building psa
		  }
		}
		int Q = sc.nextInt();
		while(Q-->0){
		  int l = sc.nextInt(), r = sc.nextInt();
		  l--;
		  r--;
		//Get the remainder of D and the floor and do prefix sum.
		//We want O[remainder][l/D+1] --> O[remainder][r/D]
		  System.out.println(P[r%D][r/D] - P[l%D][l/D]);
		}

	}

}


Measured memory_bytes: 61936
import sys
readline = sys.stdin.buffer.readline

n = int(readline())
z,w = [],[]
for _ in range(n):
    x, y = map(int,readline().split())
    z.append(x+y)
    w.append(x-y)

z.sort()
w.sort()

print(max(z[n-1]-z[0],w[n-1]-w[0]))



Measured memory_bytes: 88500
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
int x[11][600][1024], y[11][600], n, s;
int main() {
	x[0][0][0] = 1;
	for (int i = 1; i <= 10; i++) {
		for (int j = 0; j < 500; j++) {
			for (int k = 0; k < 1024; k++) {
				for (int l = 0; l < 10; l++) {
					if ((k / (1 << l)) % 2 == 0) {
						x[i][j + i*l][k + (1 << l)] += x[i - 1][j][k];
					}
				}
			}
		}
	}
	for (int i = 0; i <= 10; i++) {
		for (int j = 0; j < 500; j++) {
			for (int k = 0; k < 1024; k++) {
				y[i][j] += x[i][j][k];
			}
		}
	}
	while (cin >> n >> s) {
		cout << y[n][s] << endl;
	}
}

Measured memory_bytes: 25532
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

struct City {
	int x, y, a;
};

int main() {
	int N;
	while(~scanf("%d", &N)) {
		vector<City> cities(N);
		rep(i, N) {
			int x; int y; int a;
			scanf("%d%d%d", &x, &y, &a);
			cities[i] = { x, y, a };
		}
		vector<vector<double>> dist(N, vector<double>(N));
		rep(i, N) rep(j, N)
			dist[i][j] = hypot(cities[i].x - cities[j].x, cities[i].y - cities[j].y);
		vector<double> mstCost(1 << N, 1e99);
		rep(i, N) mstCost[1 << i] = 0;
		reu(S, 1, (1 << N) - 1) {
			double x = mstCost[S];
			rep(i, N) if(S >> i & 1) rep(j, N) if(~S >> j & 1)
				amin(mstCost[S | 1 << j], x + dist[i][j]);
		}
		vector<double> value(1 << N);
		reu(S, 1, 1 << N) {
			double A = 0;
			int K = 0;
			rep(i, N) if(S >> i & 1) {
				A += cities[i].a;
				++ K;
			}
			value[S] = max(0., A - mstCost[S]) / K;
		}
		vector<double> dp(1 << N);
		dp[0] = 1e99;
		reu(S, 1, 1 << N) {
			double x = 0;
			for(int T = S; T > 0; (-- T) &= S)
				amax(x, min(value[T], dp[S - T]));
			dp[S] = x;
		}
		double ans = dp.back();
		printf("%.10f\n", ans);
	}
	return 0;
}


Measured memory_bytes: 1152
n = int(raw_input())
for i in xrange(n):
    msg = raw_input()
    tmp = ''
    c = -1
    ans = ''
    table = [[],
             ['.', ',', '!', '?', ' '],
             ['a', 'b', 'c'],
             ['d', 'e', 'f'],
             ['g', 'h', 'i'],
             ['j', 'k', 'l'],
             ['m', 'n', 'o'],
             ['p', 'q', 'r', 's'],
             ['t', 'u', 'v'],
             ['w', 'x', 'y', 'z']]
    for j in xrange(len(msg)):
        if msg[j] == '0':
            if c > -1:
                if msg[j-1] == '1':
                    ans += table[int(msg[j-1])][c%5]
                elif msg[j-1] == '7' or msg[j-1] == '9':
                    ans += table[int(msg[j-1])][c%4]
                else:
                    ans += table[int(msg[j-1])][c%3]
                c = -1
        else:
            tmp = msg[j]
            c += 1
    print ans

Measured memory_bytes: 4268
from string import *

n = int(input())

Ta = []
Ha = []

Taro = 0
Hana = 0

for i in range(n):
    T, H = map(str,input().split())
        
    Ta = []
    Ha = []
        
    Tlen = len(T)
    Tlist = list(T)
    tsum = 0
        
    Hlen = len(H)
    Hlist = list(H)
    hsum = 0
        
    for k in range(Tlen):
        t = ascii_lowercase.find(Tlist[k])
        Ta.append(t)
        
    for k in range(Hlen): 
        h = ascii_lowercase.find(Hlist[k])
        Ha.append(h)
    
    if Ta==Ha :
        Taro += 1
        Hana += 1
        
    else :
        while True:
            
            mojisu = min(Tlen, Hlen)
    
            for j in range(mojisu):
                if Ta[j]>Ha[j]:
                    Taro += 3
                    break
                if Ha[j]>Ta[j]:
                    Hana += 3
                    break
                if Ta[j]==Ha[j]:
                    if j==mojisu-1:
                        if Tlen>Hlen:
                            Taro += 3
                            break
                        if Hlen>Tlen:
                            Hana += 3
                            break
                    pass
            break

print(Taro,Hana)


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

int main() {
  int n;
  cin >> n;
  if(n == 1) {
    cout << "1" << endl;
    return 0;
  } else {
    int64_t a, b, c;
    a = 2;
    b = 1;
    int count = 2;
    while (count <= n) {
      c = a+b;
      a = b;
      b = c;
      count++;
    }
    cout << c << endl;
    return 0;
  }
  
}

Measured memory_bytes: 3596
#include<iostream>

using namespace std;

int main(){
    int a[3];
    int ans = 0;
    for (int i = 0; i < 3; i++){
        cin >> a[i];
        ans += a[i];
    }
    if (ans > 21){
        cout << "bust" << endl;
    }else{
        cout << "win" << endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int a, b;

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

Measured memory_bytes: 256
def solve(N, A, B, Ps):
    q1 = len([p for p in Ps if p <= A])
    q2 = len([p for p in Ps if A + 1 <= p <= B])
    q3 = len([p for p in Ps if B + 1 <= p])
    return min(q1, q2, q3)


if __name__ == "__main__":
    N = int(input())
    A, B = tuple(map(int, input().split(" ")))
    Ps = list(map(int, input().split(" ")))
    print(solve(N, A, B, Ps))


Measured memory_bytes: 3064
# -*- coding:utf-8 -*-

N = int(input())
a = reversed(list(map(int, input().split())))

b = [0] * N

for i, aa in enumerate(a):
    box_number = N-i
    sum_item_num = N//box_number
    item_sum = 0
    for sum_count in range(sum_item_num, 0, -1):
        if sum_count != 1:
            item_sum += b[(box_number * sum_count) - 1]
        else:
            # if 1
            b[box_number - 1] = aa ^ (item_sum % 2)

b = [str(i+1) for i, x in enumerate(b) if x == 1]
print(len(b))
if len(b) > 0:
    print(' '.join(b))


Measured memory_bytes: 15020
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
ll gcd(ll a,ll b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

int main() {
    string S;
    cin >> S;
    ll ans=0, c=1;
    vector<ll> f(S.size());
    f[0] = 1;
    FOR(i, 1, S.size()-1)
        f[i] = f[i-1]*3%MOD;
    REP(i, S.size()) {
        if(S[i]=='1') {
            ans = (ans+c*f[S.size()-i-1])%MOD;
            c=(c*2)%MOD;
        }
    }
    ans = (ans+c)%MOD;
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1280
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;
    int w;
    cin >> w;
    int n = s.length();
    string res;
    for (int i = 0; i < n; i += w) {
        res += s[i];
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

main(void){
    int a, b;
    char op;
while(1){
scanf("%d %c %d",&a ,&op, &b);
if(op == '+')
printf("%d\n",a + b);
else if(op == '-')
printf("%d\n",a - b);
else if(op == '*')
printf("%d\n",a * b);
else if(op == '/')
printf("%d\n",a / b);
else
break;
}

return 0;
}


Measured memory_bytes: 1972
#include<cstdio>
const int N=2005;
int l[N][N],r[N][N],h[N][N],n,m,ans,mp[N][N],a[N][N];
char s[N];
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
int main(){
//	freopen("ex.in","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i){
		scanf("%s",s+1);
		for(int j=1;j<=m;++j) mp[i][j]=(s[j]=='#');
	}
	for(int i=1;i<n;++i) for(int j=2;j<=m;++j) if((mp[i][j]^mp[i+1][j])==(mp[i][j-1]^mp[i+1][j-1])) a[i][j]=1;
	for(int i=1;i<=n;++i) for(int j=1;j<=m;++j){
		if(a[i][j]==1) h[i][j]=h[i-1][j]+1,l[i][j]=l[i][j-1]+1;
		if(a[i][m-j+1]==1) r[i][m-j+1]=r[i][m-j+2]+1;
	}
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			if(h[i][j]>1){
				l[i][j]=min(l[i][j],l[i-1][j]);
				r[i][j]=min(r[i][j],r[i-1][j]);
			}
			ans=max(ans,(l[i][j]+r[i][j])*(h[i][j]+1));
		}
	}
	printf("%d\n",max(ans,max(n,m)));
	return 0;
} 

Measured memory_bytes: 78592
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<tuple>
#include<string>
typedef long long ll;
#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define repm(i,a,b) for(int i=(a);i>(b);i--)
#define F first
#define S second
using namespace std;
const ll INF = 1e12;
const double PI = 3.1415926535897932;
const int i_INF = 2147483647;
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; }


int main() {
	int n;
	cin >> n;
	int ans = 0;
	rep(i, 1, n + 1) {
		int h = 0;
		rep(j, 1, i + 1) {
			if (i % j == 0)h++;
		}
		if (h == 8 && (i % 2) == 1)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdint>
#include <utility>
#include <cstring>
using namespace std;

int main() {
    string s;
    cin >> s;
    int a[2] = {stoi(s.substr(0,2)),stoi(s.substr(2,2))};
    if(a[0] <= 12 && a[0] > 0) {
        if(a[1] <= 12 && a[1] > 0) cout << "AMBIGUOUS" << endl;
        else cout << "MMYY" << endl;
    }
    else {
        if(a[1] <= 12 && a[1] > 0) cout << "YYMM" << endl;
        else cout << "NA" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <utility>
#include <algorithm>

using namespace std;



int main(){

	int N;
	long T;
	cin >> N >> T;

	long long int sum = 0;

	long prev_t, t;
	cin >> prev_t;

	for(int i=1; i<N; i++){
		cin >> t;
		sum += min(t-prev_t, T);
		prev_t = t;
	}

	cout << sum+T << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  cout << a+2*(b-a) << endl;
  return 0;
}


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

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) a[i] = sc.nextInt();
    sc.close();

    long lcm = 1;
    for (int i = 0; i < N; i++) lcm = lcm(lcm, a[i] / 2);

    for (int i = 0; lcm != 0 && i < N; i++)
      if (lcm / (a[i] / 2) % 2 == 0) lcm = 0;

    long ans = lcm == 0 ? 0 : ((long) M / lcm + 1L) / 2L;
    System.out.println(ans);
  }
  
  private static long lcm(long a, long b) {
    return a / gcd(a, b) * b;
  }
  private static long gcd(long a, long b) {
//    return a < b ? gcd(b, a) : b == 0 ? a : gcd(b, a % b);
    long l = a < b ? b : a;
    long s = a < b ? a : b;
    long c = l % s;
    while (c != 0) {
      l = s;
      s = c;
      c = l % s;
    }
    return s;
  }
}

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

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

    if(a > 0) cout << "Positive" << endl;
    else if(b >= 0) cout << "Zero" << endl;
    else if((b - a + 1) % 2) cout << "Negative" << endl;
    else cout << "Positive" << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct BoolName : numpunct<char> {
  string t, f;
  BoolName (string t = "Yes", string f = "No") : t(t), f(f) {}
  string do_truename() const {return t;}
  string do_falsename() const {return f;}
};

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
    cout.imbue(locale(cout.getloc(), new BoolName));
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

void set_bool_name(string t, string f) {
  cout.imbue(locale(cout.getloc(), new BoolName(t, f)));
}

int main() {
  int r, g;
  cin >> r >> g;
  cout << 2 * g - r << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>
#include <queue>

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


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

    ll A[N];
    set<ll> st;
    for(int i=0; i<N; i++) {
        cin >> A[i];
        st.insert(A[i]);
    }

    bool flg = true;
    if(N % 3 != 0) flg = false;
    if(st.size() != 2 && st.size() != 3) flg = false;

    if(flg) {
        if(st.size() == 2) {
            auto itr = st.begin();
            ll a = *itr;
            ll b = *(++itr);
            if(a > b) {
                ll tmp = a;
                a = b;
                b = tmp;
            }
            if(a != 0) flg = false;
            else {
                ll cnt_b = 0;
                for(int i=0; i<N; i++) if(A[i] == b) cnt_b++;
                if(cnt_b != 2 * N / 3) flg = false;
            }

        } else if(st.size() == 3) {
            auto itr = st.begin();
            ll a = *itr;
            ll b = *(++itr);
            ll c = *(++itr);

            ll cnt_a = 0;
            ll cnt_b = 0;
            ll cnt_c = 0;
            for(int i=0; i<N; i++) {
                if(A[i] == a) cnt_a++;
                if(A[i] == b) cnt_b++;
                if(A[i] == c) cnt_c++;
            }
            if(cnt_a != N / 3) flg = false;
            if(cnt_b != N / 3) flg = false;
            if(cnt_c != N / 3) flg = false;

            if(a != (b^c)) flg = false;
            if(b != (a^c)) flg = false;
            if(c != (a^b)) flg = false;
        }
    }

    if(st.size() == 1 && *st.begin() == 0) flg = true;

    if(flg) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 4480
from collections import deque

N = int(input())
A = list(map(int, input().split()))
B = deque([])

for i, a in enumerate(A):
    if i % 2 == 0:
        B.append(a)
    else:
        B.appendleft(a)

C = list(B)
if N % 2 == 1:
    C = C[::-1]

for c in C:
    print(c, end=' ')
print()

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

void chmax(int64_t& a, int64_t b){
    a = max(a, b);
}

int main(){
    int N;
    cin >> N;
    vector<int64_t> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    vector<int> order;
    for(int i=0; i<N; i++) order.push_back(i);
    sort(order.begin(), order.end(), [&](int i, int j){ return A[i] > A[j]; });

    static int64_t dp[2001][2001];
    for(int i=0; i<N; i++) for(int j=0; i+j<N; j++){
        int pos = order[i+j];
        chmax(dp[i+1][j], dp[i][j] + A[pos]*abs(pos - i));
        chmax(dp[i][j+1], dp[i][j] + A[pos]*abs(pos - (N-1-j)));
    }
    int64_t ans = 0;
    for(int i=0; i<=N; i++) chmax(ans, dp[i][N-i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 26192
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9+7);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,1,-1};

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans % mod;
}

//modの値の確認をすること
int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep0(i, n)cin >> a[i];
    if(a[0] > 0){
        pf(-1);
        return 0;
    }
    ll ans = 0;
    rep1(i, n - 1){
        if(a[i - 1] + 2 <= a[i]){
            pf(-1);
            return 0;
        }
        if(a[i - 1] + 1 == a[i])++ans;
        else ans += a[i];
    }
    pf(ans);
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
using namespace std;
inline int D()
{
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}
const int N=2e5+9;

int arr[N];
   ll mod=1e9+7,sum=1;
   bool r= 0;
int main(){
   int  n =D();
   for(int i=0;i<n;i++)
   {

    int a=D();
    arr[a]++;
   }
         for(int i=!(n&1);i<n;i+=2){
            if(i)
                {
         if(arr[i]!= 2) r = 1;
            sum *=2;
            sum = sum % mod;
                }
                else if(arr[i] != 1) r = 1;
         }
  (r)?puts("0"):printf("%lld",sum);
    }

/**


8
7 5 1 1 7 3 5 3
bool ok(int val){
  int cntm=0,cntp=0;
  for(int i=0;i<n-val;i++)
  {
      cntm=0;cntp=0;
      for(int j=i;j<val;j++)
      {
      (arr[j]==1)?cntp++:cntm++;
      }
      if(cntp==cntm)
        break;
  }
  return cntp==cntm;
}
int binarySearch(){
  int low = 0, med, hi =n;
  while(low<hi){
    med = (low+hi+1)>>1;
    cout<<med<<" "<<hi<<" "<<low<<endl;
    if(ok(med))  low = med;
    else  hi = med-1;
  }
  return low;
}*/



/**
  int power1(int b, int p){               //O(p)
    if(!p)  return 1;
    return b*power1(b, p-1);
  }
  int power2(int b, int p){               //O(Log(p))
    if(!p)  return 1;
    int ret = power2(b, p/2);
    return (p&1 ? ret*ret*b : ret*ret);
  }
   int mul(int a, int b, int m){
      return (a%m * b%m) % m;
  }

*/


/**
void seive()
{
    bitset<N>iscomp;
    iscomp[0]=iscomp[1]=1;
    for(long long i=2; i<=N; ++i)
    {
        if(!iscomp[i])
        {
            a.push_back(i);
            for(long long j=i*i; j<=N; j+=i)
                iscomp[j]=1;
        }
    }
}
3
abc
abc
*/

    /**


    */


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define mod 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol n,a,b,c,d;
  long double g,h,f;
  cin >>g>>h>>f;
  long double an=g+h;
  if(an+2.0*sqrt(g*h)<f) cout <<"Yes\n";
  else cout <<"No\n";
  return (0);
}


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

int main() {
    int h,w;
    cin>>h>>w;
    string ss[h];
    for (int i=0;i<h;i++)
        cin>>ss[i];
    int f=1;
    int dx[]={1,-1,0,0};
    int dy[]={0,0,1,-1};
    for (int i=0;i<h;i++)
        for (int j=0;j<w;j++)
            if (ss[i][j]=='#') {
                int f2=0;
                for (int k=0;k<4;k++) {
                    int x=j+dx[k];
                    int y=i+dy[k];
                    f2|=0<=x&&x<w&&0<=y&&y<h&&ss[y][x]=='#';
                }
                f&=f2;
            }
    if (f)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define rep(i, a) for(int i = 0; i < a; ++i)
 
int main(void) {
  char w[20], t[1200];
  char s[100] = "END_OF_TEXT";
  int ans = 0;
  scanf("%s", w);
  rep(i, strlen(w)) if(w[i] >= 'A' && w[i] <= 'Z') w[i] += 'a' - 'A';
  while( scanf("%s", t) != EOF ) {
    if(!strcmp(t, s)) break;
    rep(i, strlen(t)) if(t[i] >= 'A' && t[i] <= 'Z') t[i] += 'a' - 'A';
    if(!strcmp(w, t)) ++ans;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 2056