akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A, B = [], []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ans = 0
for x, y in zip(A[::-1], B[::-1]):
    if (x + ans) % y == 0:
        continue
    else:
        ans += y - (x+ans)%y
print(ans)

Measured memory_bytes: 12624
#include<bits/stdc++.h>
#include<stdlib.h>
#include<string.h>
#define ll long long
#define ull unsigned long long int
#define T int test; scanf("%d",&test); while(test--)
#define pb push_back
#define in insert
#define PI acos(-1)
#define sc(n) scanf("%d",&n)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define lsc(n) scanf("%lld",&n)
#define lsc2(a,b) scanf("%lld%lld",&a,&b)
#define rep(i,n) for(i=0;i<n;i++)
#define fr(i,a,b) for(i=a;i<b;i++)
#define gcd(a,b) __gcd(a,b)
#define gcd3(a,b,c) __gcd(__gcd(a,b),c)
#define lcm(a,b) (a*b)/__gcd(a,b)
using namespace std;



int main()
{
	ll n,ans=0,i,j,k;
	lsc(n);
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			for(k=1;k<=n;k++)
			{
				ans+=gcd3(i,j,k);
			}
		}
	}
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3776
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
import pprint
sys.setrecursionlimit(10 ** 9)


INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



n, r = LI()
if n < 10:
    r += 100 * (10 - n)


print(r)

Measured memory_bytes: 39408
#include <iostream>
#include <algorithm>
using namespace std;
double arr[1000000];
int main(){
    int a,b,c,i,n;
    cin>>n;
    for(i = 0;i < n;i++){
        cin>>arr[i];
    }

    sort(arr,arr+n);
    double sum = arr[0];
    for(i = 0;i < n;i++){
        sum = (arr[i]+sum)/2;
    }
    cout<<sum;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <set>
#include <stack>

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,b,n) for(int i=b;i<n;i++)

const float PI = 3.1415926;
static const int INFTY = (1<<30);

using namespace std;

typedef long long ll;
typedef long double ld;

string num;
int n;
ll res;
stack<ll> s;

void cul() {
  ll t = 1;
  int tmp = s.size();
  rep(h, tmp) {
    res += s.top() * t;
    s.pop();
    t *= 10;
  }
}

int main() {
  cin >> num;
  res = 0;
  n = num.size();
  for(ll mask=0; mask < (1<<(n-1)); mask++) {
    for(int i=0; i<n; i++) {
      s.push(num[i] - '0');
      if(i == n-1 || mask & (1<<i)) {
        cul();
      }
    }
  }
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
//if it can you can use
//#include <bits/stdc++.h>
using namespace std;

#define FOR(i,a,b) for (auto i=(a);i<(b);i++)
#define RFOR(i,a,b) for (auto i=(b)-1;i>=(a);i--)
#define REP(i,n) for (auto i=0;i<(n);i++)
#define RREP(i,n) for (auto i=(n)-1;i>=0;i--)
#define EACHIM(i,v) for(auto i : v)
#define EACH(i,v) for(auto &i : v)
#define inf INT_MAX/3
#define INF INT_MAX/3
#define PB push_back
#define pb push_back
#define MP make_pair
#define mp make_pair
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define PII pair<int,int>
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define MI map<string, int>
#define MD map<string, double>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define in scanf
#define out printf
#define LL long long
#define ll long long
#define ULL unsigned long long
#define ull unsigned long long
#define eps 1e-14
#define FST first
#define SEC second
#define SORT(v) sort(ALL(v));
#define int(x) int x; scanf("%d",&x);
#define lint(x) long long x; scanf("%lld",&x);
#define vint(v,n) vector<int> v(n); REP(i,n) scanf("%d", &v[i]);
#define vvint(v,n1,n2) vector<vector<int> > v(n1, vector<int>(n2, 0)) ; REP(i,n1) REP(j,n1) scanf("%d", &v[i][j]);
#define vlint(v,n) vector<ll int> v(n); REP(i,n) scanf("%lld", &v[i]);
#define vvlint(v,n1,n2) vector<vector<ll int> > v(n1, vector<ll int>(n2, 0)); REP(i,n1) REP(j,n1) scanf("%lld", &v[i][j]);
#define double(x) double x; scanf("%lf",&x);
#define vdouble(v,n) vector<double> v(n); REP(i,n) scanf("%lf", &v[i]);
#define vvdoube(v,n1,n2) vector<vector<double> > v(n1, vector<double>(n2, 0)); REP(i,n1) REP(j,n1) scanf("%lf", &v[i][j]);
#define char(x) char x; scanf("%c",&x);
#define vchar(v,n) vector<char> v(n); REP(i,n) scanf("%c", &v[i]);
#define vvchar(v,n1,n2) vector<vector<char> > v(n1, vector<char>(n2, 0)); REP(i,n1) REP(j,n1) scanf("%c", &v[i][j]);
#define string(x) string x; cin >> x;

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(int argc, char const *argv[]) {
    int x=0;
    int seven=0 ,five = 0;
    for (size_t i = 0; i < 3; i++) {
        std::cin >> x;
        seven += x==7;
        five += x==5;
    }
    if (seven ==1 && five ==2) {
        std::cout << "YES" << std::endl;
    }else{
        std::cout << "NO" << std::endl;
    }

}


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

typedef long long ll;
const int maxn=1e5+10;
int n,m,a[maxn],x[maxn],d[maxn],p[maxn],fa[63][maxn];
ll k,ans[maxn];

int main(){
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>a[i];
	cin>>m>>k;
	for(int i=1;i<=m;++i)
		cin>>x[i];
	for(int i=1;i<n;++i)
		d[i]=a[i+1]-a[i];
	for(int i=1;i<n;++i)
		p[i]=i;
	for(int i=1;i<=m;++i)
		swap(p[x[i]-1],p[x[i]]);
	for(int i=1;i<n;++i)
		fa[0][i]=p[i];
	for(int i=1;i<63;++i)
		for(int j=1;j<n;++j)
			fa[i][j]=fa[i-1][fa[i-1][j]];
	ans[1]=a[1];
	for(int i=1;i<n;++i){
		int pos=i;
		for(int j=62;~j;--j)
			if(k>>j&1ll)
				pos=fa[j][pos];
		ans[i+1]=ans[i]+d[pos];
	}
	for(int i=1;i<=n;++i)
		printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 28160
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a; }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

int main() {
    int n, m;
    cin >> n >> m;
    vint a(n);
    rep(i, n) cin >> a[i];
 
    rep(i, n) a[i] >>= 1;
    ll l = a[0];
    srep(i, 1, n) l = lcm(l, a[i]);
 
    bool f = true;
    rep(i, n) {
        if ((l-a[i])%(2*a[i]) != 0) f = false; 
    }
    int ans = m / l - m / l / 2;
    if (!f) ans = 0;

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

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

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
    int N;
    cin >> N;
    vi a(N);
    rep(i, N) cin >> a[i];

    bool can = false;
    int ans = 0;
    int pos = 0;
    rep(i, N+1){
        pos = a[pos] -1 ;
        ans++;
        if(pos == 1){
            can = true;
            break;
        }
    }

    cout << (can == true ? ans : -1) << endl;

    return 0;
}

Measured memory_bytes: 640
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(m)]

ans = []
for i in range(n):
    dis = []
    for j in range(m):
        dis.append(abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1]))
    ans.append(dis.index(min(dis)) + 1)
for i in ans:
    print(i)

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

n = int(input())
s = str(input())
A = list(s)
A = A[0:n]

A = [{ord(c)-ord('a')} for c in A]
#print(A)

def segfunc(x, y):
    return x | y

def init(init_val):
    # set_val
    for i in range(n):
        seg[i+num-1] = init_val[i]
    # built
    for i in range(num-2, -1, -1):
        seg[i] = segfunc(seg[2*i+1], seg[2*i+2])

def update(k, x):
    k += num - 1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[2*k+1], seg[2*k+2])

def query(p, q):
    if q <= p:
        return ide_ele
    p += num - 1
    q += num - 2
    res = ide_ele
    while q-p>1:
        if p%2 == 0:
            res = segfunc(res, seg[p])
        if q%2 == 1:
            res = segfunc(res, seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res, seg[p])
    else:
        res = segfunc(segfunc(res, seg[p]), seg[q])
    return res

# identity element
ide_ele = set()

# num: n以上の最小の2のべき乗
num = 2**(n-1).bit_length()
seg = [ide_ele]*2*num

init(A)

q = int(input())

for _ in range(q):
    c, x, y = map(str, input().split())
    if c == '1':
        x = int(x)-1
        y = {ord(y)-ord('a')}
        update(x, y)
    else:
        l = int(x)-1
        r = int(y)-1
        print(len(query(l, r+1)))

Measured memory_bytes: 477876
#![allow(dead_code)]
#![allow(unused_imports)]
use ascii::{AsciiChar, AsciiStr, AsciiString};
use indexmap::IndexMap;
use itertools::*;
use libm::*;
use num::*;
use ordered_float::OrderedFloat;
use permutohedron::LexicalPermutation;
use proconio::marker::{Bytes, Chars};
use proconio::{fastout, input};
use std::cmp::{max, min, Ordering};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::mem::swap;

fn main() {
    input!(mut n: u128);
    let mut v = vec![];
    while n > 0 {
        let c = (n - 1) % 26;
        n = (n - 1) / 26;
        v.push((b'a' + c as u8) as char);
    }
    println!("{}", v.iter().rev().collect::<String>());

}



Measured memory_bytes: 2176
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
 
		try (Scanner sc = new Scanner(System.in)) {
 
			int n = sc.nextInt();
			int t[] = new int[n + 1];
			int x[] = new int[n + 1];
			int y[] = new int[n + 1];
			t[0] = 0;
			x[0] = 0;
			y[0] = 0;
			for (int i = 1; i < n + 1; i++) {
				t[i] = sc.nextInt();
				x[i] = sc.nextInt();
				y[i] = sc.nextInt();
			}
			String result = "Yes";
			for(int i = 1; i < n + 1; i++) {
				if(t[i] - t[i-1] >= Math.abs(x[i]-x[i-1]) + Math.abs(y[i]-y[i-1]) &&
						(t[i] - t[i-1]) % 2 == (Math.abs(x[i]-x[i-1]) + Math.abs(y[i]-y[i-1]))%2) {
				}
				else {
					result = "No";
					break;
				}
			}
			System.out.println(result);
		}
	}
}

Measured memory_bytes: 92632
n = int(input())
a = input()
b = input()
c = input()
cnt = 0
for i in range(n):
    c1,c2,c3=0,0,0

    if b[i] ==a[i] and c[i]==b[i]:
        pass

    elif b[i] ==a[i] or c[i]==b[i] or c[i] ==a[i]:

        cnt+=1
    else:
        cnt+=2

print(cnt)


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int main()
{
// #ifndef ONLINE_JUDGE
// 	freopen("input", "r", stdin);
// 	freopen("output", "w", stdout);
// #endif

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

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

	sort(v.begin(), v.end(), greater<int>());

	long ans = v[0], m = n - 2;

	for (int i = 0; i < m; ++i)
	{
		ans += v[i / 2 + 1];
		// cout << ans << " ";
	}

	cout << ans << endl;
}

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

struct Card
{
  char mark;
  int num;

  bool operator==(const Card &c) const
  {
    return mark == c.mark && num == c.num;
  }
} card_s;

void output_array(vector<Card> &v)
{
  for (int i = 0; i < v.size(); i++)
    cout << (i ? " " : "") << v[i].mark << v[i].num;
  cout << "\n";
}

vector<Card> bubble_sort(vector<Card> &cards)
{
  vector<Card> v(cards.size());
  copy(cards.begin(), cards.end(), v.begin());

  for (int i = 0; i < v.size(); i++)
  {
    for (int j = v.size() - 1; j > i; j--)
    {
      if (v[j].num < v[j - 1].num)
      {
        swap(v[j], v[j - 1]);
      }
    }
  }

  return v;
}

vector<Card> selection_sort(vector<Card> &cards)
{
  vector<Card> v(cards.size());
  copy(cards.begin(), cards.end(), v.begin());

  for (int i = 0; i < v.size(); i++)
  {
    int minj = i;
    for (int j = i; j < v.size(); j++)
    {
      if (v[j].num < v[minj].num)
      {
        minj = j;
      }
    }
    swap(v[i], v[minj]);
  }

  return v;
}

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

  int n;
  cin >> n;

  vector<Card> r(n);
  for (int i = 0; i < n; i++)
  {
    string str;
    cin >> str;
    r[i].mark = str[0];
    r[i].num = stoi(str.substr(1, 1));
  }

  vector<Card> bsorted = bubble_sort(r);
  output_array(bsorted);
  cout << "Stable\n";

  vector<Card> ssorted = selection_sort(r);
  output_array(ssorted);

  // 安定かどうかは、常に安定なバブルソートと比較する
  int is_stable = 1;
  for (int i = 0; i < n; i++)
  {
    is_stable &= bsorted[i] == ssorted[i];
  }
  cout << (is_stable ? "Stable" : "Not stable") << "\n";

  return 0;
}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<vector<int> > Graph;


int main() {
  //入力
  int n;
  cin >> n;
  vector<int> L(n);
  rep(i,n)cin>>L[i];

  int ans=0;
  int a,b;
  sort(L.begin(),L.end());
  rep(b,n)rep(a,b){
    int ab=L[a]+L[b];
    int r=lower_bound(L.begin(),L.end(),ab)-L.begin();
    int l=b+1;
    ans+=r-l;
  }
  cout << ans << endl;
  
  return 0;
}

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int n, m;
  cin >> n >> m;
  vi a(n);
  rep(i, n) cin >> a[i];
  multiset<int> st(a.begin(), a.end());
  dump(st);
  rep(i, m) {
    auto it = st.end();
    it--;
    // dump(*it);
    int j = *it;
    j = j >> 1;
    st.erase(it);
    st.insert(j);
    // dump(st);
  }
  ll ans = 0;
  for (auto it = st.begin(); it != st.end(); it++) {
    ans += *it;
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << ele << endl
#define print10(ele) cout << fixed << setprecision(10) << ele << endl

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

struct UnionFind {
  ivec d;
  UnionFind(int n) : d(n, -1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x, y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};

int deg[100005];
ivec to[100005];

int main() {
  int n, m, k;
  cin >> n >> m >> k;

  UnionFind uf(n);
  REP(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    deg[a]++;
    deg[b]++;
    uf.unite(a, b);
  }

  REP(i, k) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  REP(i, n) {
    int ans = uf.size(i) - 1 - deg[i];
    for (int u : to[i]) {
      if (uf.same(i, u)) ans--;
    }
    print(ans);
  }

  return 0;
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
#define INF 100000000
typedef string::const_iterator State;
void expression(State &begin);
void statement(State &begin);

int h, w;
int dir; // N0 E1 S2 W3
int dh[] = {-1,0,1,0};
int dw[] = {0,1,0,-1};
vector<vector<char>> a(60, vector<char>(60));
string s;
long long cnt = 0LL;
long long cntc = 0LL;

bool check(char c, bool t){
	cntc++;
	if(cntc==INF){
		cout << -1 << endl;
		exit(0);
	}
	switch(c){
		case 'N':
			return t^(dir==0);
		case 'E':
			return t^(dir==1);
		case 'S':
			return t^(dir==2);
		case 'W':
			return t^(dir==3);
		case 'C':
			return t^(a[h+dh[dir]][w+dw[dir]] == '#');
		case 'B':
			return t^(a[h-dh[dir]][w-dw[dir]] == '#');
		case 'T':
			return t^true;
	}
	return t^false;
}


void move(State &begin){
	//cout << h << " " << w << " " << *begin << endl;
	if(cnt == INF){
		cout << -1 << endl;
		exit(0);
	}
	switch(*begin){
		case '^':
		if(check('C',true)){
				h += dh[dir];
				w += dw[dir];
			}
			begin++; cnt++; break;
		case '>':
			dir = (dir+1)%4;
			begin++; cnt++; break;
		case 'v':
			if(check('B',true)){
				h -= dh[dir];
				w -= dw[dir];
			}
			begin++; cnt++; break;
		case '<':
			dir = (dir+3)%4;
			begin++; cnt++; break;
	}
	if(a[h][w] == 'g'){
		cout << cnt << endl;
		exit(0);
	}
	return;
}


void while_statement(State &begin){
	begin++; // { を読み終わる
	bool t = false;
	if(*begin == '~'){
		t = true;
		begin++;
	}
	//cout << *begin << endl;
	State before = begin; // 条件式のbeginを保存
	while(check(*before,t)){
		begin = before; // 条件式まで戻る
		//cout << *begin << endl;
		begin++; // 条件式を読み終わる
		statement(begin); // プログラムを実行
		//cout << *begin << endl;
		//begin++; // }
	}
	int pc = 1;
	while(pc>0){
		if(*begin == '{') pc++;
		if(*begin == '}') pc--;
		begin++;
	}
	return;
}

void if_statement(State &begin){
	begin++; // { を読み終わる
	bool t = false;
	if(*begin == '~'){
		t = true;
		begin++;
	}
	//cout << *begin << endl;
	if(check(*begin,t)){
		//cout << *begin << endl;
		begin++; // 条件式を読み終わる
		statement(begin); // プログラムを実行
		//cout << *begin << endl;
		//begin++; // }
	}
	int pc = 1;
	while(pc>0){
		if(*begin == '[') pc++;
		if(*begin == ']') pc--;
		begin++;
	}
	return;
}



void statement(State &begin){
	if(begin == s.end()){
		cout << -1 << endl;
		exit(0);
	}
	switch(*begin){
		case '{':
			while_statement(begin);
			break;
		case '[':
			if_statement(begin);
			break;
		case '}':
			return;
		case ']':
			return;
		default:
			move(begin);
			break;
	}
	statement(begin);
}

int main(void){
	int H, W;
	cin >> H >> W;
	
	for(int i = 0; i < H; ++i){
		for(int j = 0; j < W; ++j){
			cin >> a[i][j];
			if(a[i][j] == 's'){
				h = i, w = j;
				dir = 0;
			}
		}
	}
	cin >> s;
	State begin = s.begin();
	statement(begin);
	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 3224
x,k,d = input().split()
x=int(x) 
k=int(k) 
d=int(d) 
if(abs(x)>k*d):
    print(abs(x)-k*d)
else:
    step=abs(x)//d
    k-=step
    if(x<0):
        x+=step*d
        if(k&1):
            x+=d
    else:
        x-=step*d
        if(k&1):
            x-=d
    print(abs(x))



Measured memory_bytes: 9196
#include <iostream>
#include <string>
#include <bits/stdc++.h>
                 
using namespace std;
                 
int main(){
  int N;
  int f = false;
  cin >> N;
  
  for(int i = 0; 4 * i <= N; i++){
    for(int j = 0; N >= 4 * i + 7 * j ; j++){
      if (N == 4 * i + 7 * j){
      f=true;
      break;
      }
    }
    if(f == true) break;
  }
  if(f == true) cout << "Yes";
  else cout << "No";
}

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;

ll mod = 1e9 + 7;
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; }
const ll inf = 1ll << 60;



int main() {
    int n, d;
    scanf("%d%d", &n, &d);
    vector<vector<int>> map(n, vector<int>(d));
    rp(i, 0, n) {
        rp(j, 0, d) scanf("%d", &map.at(i).at(j));
    }
    int count  = 0;
    rp(i, 0, n) {
        rp(j, i+1, n){
            int now = 0;
            rp(k, 0, d) {
                now += (map.at(i).at(k) - map.at(j).at(k)) * (map.at(i).at(k) - map.at(j).at(k));
            }
            int s = (int)sqrt(now);
            if (now == s * s) {
                count ++;
            }
        }
    }
    printf("%d", count);
    return 0;
} 

Measured memory_bytes: 384
//Let's join Kaede Takagaki Fun Club !!
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define all(x) x.begin(),x.end()
template<class T>
void dmp(T a){
	rep(i,a.size()) cout << a[i] << " ";
	cout << endl;
}
template<class T>
bool chmax(T&a, T b){
	if(a < b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
bool chmin(T&a, T b){
	if(a > b){
		a = b;
		return 1;
	}
	return 0;
}
template<class T>
void g(T &a){
	cin >> a;
}
template<class T>
void o(const T &a,bool space=false){
	cout << a << (space?' ':'\n');
}
//ios::sync_with_stdio(false);
const ll mod = 1000000007;//998244353
template<class T>
void add(T&a,T b){
	a+=b;
	if(a >= mod) a-=mod;
}

int main(){
	ios::sync_with_stdio(false);
	
	ll x; g(x);
	ll ans = (x/500) * 1000;
	x %= 500;
	ans += (x/5) * 5;
	o(ans);
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

int main() {
  int n, k;
  cin >> n >> k;
  cout << (n + k - 3) / (k - 1) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

struct UnionFind{
  vi r;
  UnionFind(int n){
    r=vi(n,-1);
  }
  int root(int x){
    if(r[x]<0) return x;
    return r[x]=root(r[x]);
  }
  bool unite(int x, int y){
    x=root(x); y=root(y);
    if(x==y) return false;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    r[y]=x;
    return true;
  }
  int size(int x){
    return -r[root(x)];
  }
  int same(int x, int y){
    if(root(x)==root(y)) return true;
    else return false;
  }
};

int comb(int x){
  return x*(x-1)/2;
}

int main(){
  ll n,m; cin>>n>>m;
  vll a(m),b(m); rep(i,m) cin>>a[i]>>b[i];
  rep(i,m) a[i]--,b[i]--;
  UnionFind UF(n);
  vll ans(m,n*(n-1)/2);
  for(int i=m-1;i>=0;i--){
    if(i>0&&!(UF.same(a[i],b[i]))){
      ans[i-1]=ans[i]-UF.size(a[i])*UF.size(b[i]);
    }else if(i>0){
      ans[i-1]=ans[i];
    }
    UF.unite(a[i],b[i]);
  }
  rep(i,m){
    cout<<ans[i]<<endl;
  }
}


Measured memory_bytes: 6704
#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll = int64_t; using ull = uint64_t; const ll INF = 9e18;
void print() { cout << endl; }
template<typename Head,typename... Tail> void print(Head head,Tail... tail){cout<<head;if(sizeof...(Tail)>0)cout<<" ";print(tail...);}
void print0() {}
template<typename Head,typename... Tail> void print0(Head head,Tail... tail){cout<<head;print0(tail...);}
// clang-format on

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    ll amax = 200002;

    vector<ll> bucket(amax, 0);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
        bucket[A[i]]++;
    }

    ll total = 0;
    for (ll i = 0; i < amax; i++) {
        ll m = bucket[i];
        total += m * (m - 1) / 2;
    }

    for (ll i = 0; i < N; i++) {
        ll m = bucket[A[i]];
        ll result;
        if (m >= 2) {
            result = total - m * (m - 1) / 2 + (m - 1) * (m - 2) / 2;
        } else {
            result = total;
        }
        print(result);
    }
}


Measured memory_bytes: 6468
anntena  = [int(input()) for i in range(5)]
k = int(input())

distance = []
for i in range(4):
    for j in range(i + 1, 5):
        distance.append(anntena[j] - anntena[i])
    
tmp = [i for i in distance if i  > k ]
if len(tmp) == 0:
    print("Yay!")
else:
    print(":(")

Measured memory_bytes: 3064
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-03-19 02:02:25
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

LL modpower(LL n, LL m, LL mod) {
    if (m == 0) {
        return 1;
    } else if (m % 2 == 0) {
        LL p = modpower(n, m/2, mod);
        return p*p % mod;
    } else {
        return n*modpower(n, m-1, mod) % mod;
    }
}

LL modinv(LL n, LL mod) {
    return modpower(n, mod-2, mod);
}

LL modcombination(LL n, LL r, LL mod) {
    LL ret = 1;

    for (int i = 0; i < r; i++) {
        ret *= (n-i);
        ret %= mod;
        ret *= modinv(i+1, mod);
        ret % mod;
    }

    return ret % mod;
}

ostringstream oss_global;
string s_global = oss_global.str();

int main()
{
    string s;
    cin >> s;
    
    int n = s.length() + 1;

    //左に連続する "<" の数をかぞえる
    vector<int> left(n);
    int cur = 0;
    for (int i = 0; i <= n-2; i++) {
        left[i] = cur;
        if (s[i] == '<') cur++;
        else cur = 0;
    }
    left[n-1] = cur;

    //右に連続する ">" の数をかぞえる
    vector<int> right(n);
    cur = 0;
    for (int i = n-2; i >= 0; i--) {
        right[i+1] = cur;
        if (s[i] == '>') cur++;
        else cur = 0;
    }
    right[0] = cur;

    vector<int> a(n);
    for (int i = 0; i < n; i++)
        a[i] = max(left[i], right[i]);

    LL ans = 0;
    for (int i = 0; i < n; i++) {
        ans += a[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6788
//aea ctmr
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
//v.erase(unique(v.begin(),v.end()),v.end());
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) ll((a).size())
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
 
 
typedef long double ld;
typedef long long ll;
const ll N = 100500;
const ll mod = 1e+9 + 9;
const ld PI = acos(-1);
const ll INF = 1e+18;
using namespace std;
using namespace __gnu_pbds;
 
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;}
 
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);}
#else
#define trace(...)
#endif

vector <ll> ro, ge, inc;
vector <pair <ll, ll>> uwu;
ll r_ac[N];
ll g_ac[N];
ll inc_ac[N];

void solve(){
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    
    for(ll i = 0; i < a; i++){
        ll u; cin >> u;
        ro.push_back(u);
        uwu.push_back({u, 1});
    }
    for(ll i = 0; i < b; i++){
        ll u; cin >> u;
        ge.push_back(u);
        uwu.push_back({u, 2});
    }
    for(ll i = 0; i < c; i++){
        ll u; cin >> u;
        inc.push_back(u);
    }
    sort(ro.rbegin(), ro.rend()); sort(ge.rbegin(), ge.rend()); sort(inc.rbegin(), inc.rend());
    sort(uwu.rbegin(), uwu.rend());
    for(ll i = 1; i <= a; i++) r_ac[i] = r_ac[i - 1] + ro[i - 1];
    for(ll i = 1; i <= b; i++) g_ac[i] = g_ac[i - 1] + ge[i - 1];
    for(ll i = 1; i <= c; i++) inc_ac[i] = inc_ac[i - 1] + inc[i - 1];
    ll r = 0, g = 0;
    ll ans = 0;
    if(x + y <= c) ans = max(ans, inc_ac[x + y]); 
    for(ll i = 1; i <= a + b; i++){
        //esto ocurre si hay i weadas comidas        
        if(uwu[i - 1].ss == 1) r++;
        else g++;
        
        ll g_tom = min(g, y);
        ll r_tom = min(r, x);
        ll un_tom = x - g_tom + y - r_tom;
        if(un_tom <= c and un_tom >= 0){
            ans = max(ans, r_ac[r_tom] + g_ac[g_tom] + inc_ac[un_tom]);
        }
    }
    
    cout << ans << endl;
}

int main(){
    fastio;
    
    ll tc;
    //cin >> tc;
    tc = 1;
    while(tc--) solve();
    
    return 0;
}
 

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

using namespace std;
const int maxn = 1e5 + 30;
int a[maxn];

int main(){
  int n; int L; cin >> n >> L;
  for(int i=1;i<=n;i++){
    scanf("%d", &a[i]);
  }
  for(int i=1;i<n;i++){
    if(a[i] + a[i+1] >= L){
      cout << "Possible\n";
      for(int e = 1; e < i; e++) cout << e << "\n";
      for(int e = n-1; e > i; e--){
	cout << e << "\n";
      }
      cout << i << "\n";
      return 0;
    }
  }
  cout << "Impossible\n";
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int n, x, y;
    cin >> n >> x >> y;

    vector<int> res(n-1, 0);

    int dis;

    for(int i = 1; i <= n; i++) {
        for(int j = i+1; j <= n; j++) {
            dis = min(j-i, min(abs(x-i)+1+abs(y-j), abs(x-j)+1+abs(y-i)));
            res[dis-1]++;
        }
    }

    REP(i, n-1) {
        cout << res[i] << endl;
        
    }

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

Measured memory_bytes: 3624
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
using namespace std;
int n;
signed main()
{
	scanf("%d",&n);long long ans(1);long long mod(1e9+7);
	for(register int i(2);i<=n;i++){ans=((ans*(i%mod))%mod);}
	printf("%d",ans);
	return putchar(10),0;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    int K[N+1], A[N+1][M+1];
    for (int i = 1; i <= N; i++) {
        cin >> K[i]; 
        for (int j = 1; j <= K[i]; j++) {
            cin >> A[i][j];
        }
    }
    int table_like_food[M+1];
    for (int i = 1; i <= M; i++) {
        table_like_food[i] = 0;
    }
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= K[i]; j++) {
            table_like_food[A[i][j]]++;
        }
    }
    int result = 0;
    for (int i = 1; i <= M; i++) {
        if (table_like_food[i] == N) {
            result++;
        }
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
number = input().strip().split(' ')
number_list = list(map(int,number))
A = number_list[0]
B = number_list[1]
K = number_list[2]

while K > 0:
    if A % 2 == 0:
        A = A
    else:
        A = A - 1
    A = A / 2
    B = B + A
    K = K - 1
    if K > 0:
        if B % 2 == 0:
            B = B
        else:
            B = B - 1
        B = B / 2
        A = A + B
        K = K - 1
print(str(int(A)) + ' ' + str(int(B)))

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
//const int mod = 1e9 + 7;

int main(){
 long long n,sum=0;
 cin>>n;
 int i;
 
 for(i=0;sum<n;i++)
 sum+=i;
 cout<<i-1<<endl; 
	
	
	return 0;
} 

Measured memory_bytes: 256
# coding:utf-8

import sys
import bisect

# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


N, M = LI()
A = LI()
B = LI()

A.sort()
B.sort()

SA = set(A)
SB = set(B)


if N != len(SA) or M != len(SB):
    print(0)
    exit()

ans = 1
num = 0
aa = N
bb = M
for i in range(1, N * M + 1)[::-1]:
    if i in SA and i in SB:
        pass
    elif i in SB:
        while aa != 0 and 0 < i <= A[aa - 1]:
            aa -= 1
        ans *= N - aa
        ans %= MOD
    elif i in SA:
        while bb != 0 and 0 < i <= B[bb - 1]:
            bb -= 1
        ans *= M - bb
        ans %= MOD
    else:
        while aa != 0 and 0 < i <= A[aa - 1]:
            aa -= 1
        while bb != 0 and 0 < i <= B[bb - 1]:
            bb -= 1
        ans *= (M - bb) * (N - aa) - num
        ans %= MOD
    num += 1
    # print(i, ans, num)

print(ans)


Measured memory_bytes: 3188
import java.util.*;
class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int num=sc.nextInt();
		System.out.print("Christmas ");
		for(int i=0;i<25-num;i++)
		{
			System.out.print("Eve ");
		}
		System.out.println();
	}
}

Measured memory_bytes: 21332
--{-# LANGUAGE OverloadedStrings #-}
--{-# LANGUAGE OverloadedLists   #-}
{-# LANGUAGE BangPatterns      #-} --引数に!
{-# LANGUAGE MultiWayIf        #-}
{-# LANGUAGE TupleSections     #-}

import Data.List
import Data.Tree
import Data.Array  --変数衝突
import Data.Array.Unboxed
import Data.Array.MArray
import Data.Array.ST
--import Data.Vector as V　--変数衝突
import qualified Data.Vector.Unboxed as V (last,(!),fromList,Vector)
import Control.Monad
import Control.Monad.State
import Control.Monad.ST

solve :: Int -> [(Int,Int)] -> Int
solve m []         = 0
solve m ((a,b):ls) | m < 0 = 0
                   | otherwise = if m >= b then b*a + (solve (m-b) ls)
                     else m*a

main :: IO ()
main = do
  [n,m] <- map read.words <$> getLine
  ls <- replicateM n $ do
    (a:b:cs) <- map read.words <$> getLine
    return (a,b)
  putStrLn $ show $ solve m (sortOn fst ls)


Measured memory_bytes: 96124
n, x, y = map(int, input().split())
num_list = list(range(1,n+1))

ans_list = [0] * (n-1)

for i in range(1, n):
  for j in range(i+1, n+1):
    ans = min(j - i, abs(x-i) + 1 + abs(y-j))
    ans_list[ans-1] += 1

for i in range(n-1):
  print(ans_list[i])

Measured memory_bytes: 3444
def main():
    K = int(input())
    A, B = map(int, input().split())

    for x in range(A, B + 1):
        if x % K == 0:
            print('OK')
            return
    print('NG')


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 9160
#include "bits/stdc++.h"
using namespace std;
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP((i),0,(n))
#define ALL(v) (v).begin(),(v).end()

int main() {
	int n;
	cin >> n;
	vector<char> s(n);
	rep(i, n)cin >> s.at(i);
	sort(s.begin(), s.end());
	if (s.at(n-1) == 'W')cout << "Three" << endl;
	else cout << "Four" << endl;
	return 0;
}

Measured memory_bytes: 256
while True : 
    try :
        temp = input()
        if temp == '00000000' or temp == '' : pass
        else :
            if '1111' in temp : print('C')
            else : 
                onetwo, place = temp.count('1'), temp.index('1')
                temp = input()
                if onetwo == 1 :
                    if temp.count('1') == 1 :
                        print('B')
                        input()
                    elif temp.index('1') == place : print('F')
                    else : print('D')
                    input()
                elif onetwo == 2 :
                    if temp.index('1') == place : print('A')
                    elif temp.index('1') == place + 1 : print('E')
                    else : print('G')
    except : break

Measured memory_bytes: 7336
n, k = map(int, input().split(" "))

ans = 0
for i in range(k, n+2):
    min = i * ( 0 + i-1) / 2
    max = i * ( (n+1 - i) + n) / 2
    ans += int(max - min + 1)

print(ans % (10**9 + 7))

Measured memory_bytes: 67784
import java.util.*;

public class Main {
  public static boolean solve(int i, int m, List<Integer> list) {
    if(m == 0) {
      return true;
    } else if(i >= list.size()) {
      return false;
    } else {
      return (solve(i + 1, m, list)) || (solve(i + 1, m - list.get(i), list));
    }
  }
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    List<Integer> arr = new ArrayList<>();
    for(int i = 0; i < n; i++) {
      arr.add(sc.nextInt());
    }
    int q = sc.nextInt();
    for(int i = 0; i < q; i++) {
      int m = sc.nextInt();
      if(solve(0, m, arr)) {
        System.out.println("yes");
      } else {
        System.out.println("no");
      }
    }
  }
}



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

#define ll long long
#define ull unsigned long long
#define ii pair<int,int>
#define iii pair<ii, int>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ep emplace_back
#define sz(a) (int) a.size()
#define cl(a) a.clear()

#define vi vector<int>
#define vii vector<ii>

#define FOR(x,a,b) for (int x=a;x<=b;x++)
#define FOD(x,a,b) for (int x=a;x>=b;x--)
#define REP(x,a,b) for (int x=a;x<b;x++)
#define RED(x,a,b) for (int x=a;x>b;x--)

const int N = 1e5 + 10;
const int M = 1e4 + 10;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double pi = acos(-1.0);
const double eps = 1e-6;

int dx[] = {0 , -1 , 0 , 1};
int dy[] = {1 , 0 , -1 , 0};
string s;
int k;
int main()
{
	//freopen("input.txt", "r" , stdin);
	cin >> s >> k;
	int n = s.length();
    FOR(i, 0, n-1)
    {
        if (s[i] == 'a')
            continue;
        if (k >= ('z' - s[i] + 1))
        {
            k -= ('z' - s[i] + 1);
            s[i] = 'a';
        }
    }

    s[n-1] += k%26;
    if (s[n-1] > 'z')
        s[n-1] = 'a'+(s[n-1] -'z'-1);

    cout << s;
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
{
long long int a,b;
  cin >> a >> b ;
  long long int g[b];
  for(int     i=0; i<b; i++)
  {
  cin >>  g[i] ;
  }
 
  
  
  
  
  
  long long int h=0;
    for(int i=0; i<b; i++)
    {
         h=h+g[i];
    }
   
  if(a-h>=0)
  {
  cout << a-h ;
  }
  else
  {
  cout << "-1" ;
  }
  
 
    
    
    
    
    
    
 
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll n; cin >> n;
    vector<ll> a(n); cin >> a;
    ll ans = 0;
    rep(i, n){
        if((i+1)%2 == 1 && a[i]%2 == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
def bb
    n = gets.chomp.to_i

    y = 0
    for i in 1..n
        x, v = gets.chomp.split(/\s/)#.map{|x| x.to_f}
        if v == 'JPY'
            y += x.to_i
        else
            y += x.to_f * 380000
        end
    end

    puts y
end

bb

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

pair<long, long> bestsplit(vector<long> &asum, int begin, int end) {
  int lower_bound = begin + 1, upper_bound = end - 1;
  while (upper_bound - lower_bound > 1) {
    int mid = (lower_bound + upper_bound) / 2;
    if (2 * asum.at(mid) < asum.at(begin) + asum.at(end)) {
      lower_bound = mid;
    } else {
      upper_bound = mid;
    }
  }
  if (upper_bound - lower_bound == 1
      && asum.at(begin) + asum.at(end) > asum.at(lower_bound) + asum.at(upper_bound)) {
    lower_bound = upper_bound;
  }
  return make_pair(asum.at(lower_bound) - asum.at(begin),
                   asum.at(end) - asum.at(lower_bound));
}

int main()
{
  int n;
  cin >> n;
  vector<long> asum(n + 1);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    asum.at(i + 1) = asum.at(i) + a;
  }
  long diff_min = 1l << 60;
  for (int i = 2; i <= n - 2; i++) {
    vector<long> s(4);
    pair<long, long> cache;
    cache = bestsplit(asum, 0, i);
    s.at(0) = cache.first;
    s.at(1) = cache.second;
    cache = bestsplit(asum, i, n);
    s.at(2) = cache.first;
    s.at(3) = cache.second;
    long diff = *max_element(s.begin(), s.end()) - *min_element(s.begin(), s.end());
    if (diff < diff_min) diff_min = diff;
  }
  cout << diff_min << endl;
}


Measured memory_bytes: 1792
s = input()
t = input()

start = [-1] * 26
goal = [-1] * 26
flag = True
length = len(s)
dict = { chr(97 + i):i for i in range(26) }
for i in range(0, length):
	a = dict[s[i]]
	b = dict[t[i]]

	if start[a] != -1 or goal[b] != -1:
		if start[a] != b or goal[b] != a:
			flag = False
			break
	else:
		start[a] = b;
		goal[b] = a;
if flag:
	print("Yes")
else:
	print("No")

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

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

namespace
{
	vector<ll> Divisers(ll x)
	{
		ll sqrtX = static_cast<ll>(sqrt(static_cast<long double>(x) + 0.01));
		if ((sqrtX + 1) * (sqrtX + 1) <= x)
			++sqrtX;
		vector<ll> ret; ret.reserve(1000);
		for (ll i = 1; i <= sqrtX; ++i)
		{
			if (x % i != 0)
				continue;
			ret.push_back(i);
			ret.push_back(x / i);
		}
		sort(ret.begin(), ret.end());
		return ret;
	}
}

void ABC136E()
{
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	for (auto& x : A)
		cin >> x;

	ll sum = accumulate(A.begin(), A.end(), 0LL);
	auto divisers = Divisers(sum);
	vector<int> B(N);
	for (auto p = divisers.rbegin(); p != divisers.rend(); ++p)
	{
		ll X = *p;

		for (int i = 0; i < N; ++i)
		{
			B[i] = A[i] % X;
		}
		sort(B.begin(), B.end());
		ll C = 0, D = 0;
		int i = 0, j = N - 1;
		while (i <= j)
		{
			if (C < D)
			{
				C += B[i++];
			}
			else
			{
				D += X - B[j--];
			}
			if (max(C, D) > K)
				break;
		}
		if (max(C,D) <= K)
		{
			cout << X << endl;
			return;
		}

	}
}

int main()
{
	ABC136E();
	return 0;
}

Measured memory_bytes: 256
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace std;
const long long N=200005, INF=2000000000000000000;
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int n,k;
    cin>>n>>k;
    int h[n];
    for(int i=0;i<n;i++)
    cin>>h[i];
    int dp[n];
    dp[0]=0;dp[1]=abs(h[0]-h[1]);
    for(int i=2;i<n;i++)
    {
        dp[i]=INF;
        for(int j=1;j<=min(k, i);j++)
        dp[i]=min(dp[i-j]+abs(h[i]-h[i-j]), dp[i]);
    }
    cout<<dp[n-1];
}

Measured memory_bytes: 1792