akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 10L^^18;
enum mod = 10L ^^ 9 + 7;

void main() {
    int n;
    scan(n);
    auto a = readln.split.to!(int[]);

    auto c = new int[](3);
    foreach (i ; 0 .. n) {
        c[a[i]-1]++;
    }

    auto dp = new double[][][](n + 1, n + 1, n + 1);
    fillAll(dp, -1);

    double dfs(int i, int j, int k) {
        auto v = &dp[i][j][k];
        if (i + j + k == 0) {
            return 0;
        }
        if (*v != -1) {
            return *v;
        }
        *v = 0;
        if (i) {
            *v += 1.0 * i * dfs(i-1, j, k);
        }
        if (j) {
            *v += 1.0 * j * dfs(i+1, j-1, k);
        }
        if (k) {
            *v += 1.0 * k * dfs(i, j+1, k-1);
        }
        *v += n;
        *v /= (i + j + k);
        return *v;
    }

    auto ans = dfs(c[0], c[1], c[2]);

    writefln("%.12f", ans);
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 367484
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto&& x : v){cout << x << " ";} cout << endl
#define printVV(vv) for(auto&& v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto&& p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;

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

    string s;
    int t = 0;
    while (cin >> s, s[0] != '0') {
        // cout << "--- t = " << t++ << " ---" << endl;

        int n = s.size();
        vi cnt(11);
        cnt[0] = 1;
        vi sm(2);
        int ans = 0;

        int pre_x;
        rep(i, n) {
            sm[i%2] += (s[i] - '0');
            int x = (sm[0] > sm[1] ? (sm[0] - sm[1]) % 11 : (11 - (sm[1] - sm[0]) % 11) % 11);
            ans += cnt[x];
            if (i != 0 && s[i] != '0') {
                cnt[pre_x]++;
            }
            pre_x = x;

            // cout << i << " " << ans << endl;
            // printV(cnt);
            // printV(sm);
            // cout << endl;
        }

        cout << ans << endl;
    }

}

Measured memory_bytes: 3212
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>
#include <cassert>
#include <bitset>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define EL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int a,b,c;
	std::cin >> a >> b >> c;
	if(-(a+b-c)<0) print("No");
	else if((a+b-c)*(a+b-c)>4*a*b) print("Yes");
	else print("No");
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
static const int MAX = 500;
static const int INFTY = (1<<21);
 
int main(void){
    int n, i, j;
    int M[MAX][MAX];
    int d[MAX];
    int key[MAX];
    int p[MAX];
    int m,u,k,c,v;
    /* your code*/
 
  scanf("%d", &n);
  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      M[i][j] = INFTY;
    }
  }
 
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &u, &k);
    for ( j = 0; j < k; j++ ){
      scanf("%d %d", &v, &c);
      M[u][v] = c;
    }
  }
 
  /*your code */
     
     
    for(i=0;i<n;i++){
        p[i]=-1;
        key[i]=0;
        d[i]=INFTY;
    }
     
    d[0]=0;
     
     
    while(u!=-1){
        u=-1;
        m=INFTY;
         
        for(i=0;i<n;i++){
            if(m>d[i] && (key[i]==0)){
                u=i;
                m=d[i];
                 
            }
        }
         
        //if(u==-1)break;
        key[u]=1;
         
        for(i=0;i<n;i++) {
            if(d[i] >= M[u][i]+d[u] && (key[i] == 0)) {
                p[i] = u;
                d[i] = M[u][i]+d[u];
            }
        }
         
         
         
         
    }
 
  for ( i = 0; i < n; i++ ){
    printf("%d %d\n", i, (d[i]==INFTY?-1:d[i]));
  }
 
  return 0;
}

Measured memory_bytes: 804
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

ll n,m,v,p;
lvector A;

bool canwin(ll i) {
  if(n-i<=p) return true;
  ll val=A[i]+m;
  lvector B(n);
  rep(j,n) {
    if(j>=n-p+1) B[j]=m;
    else B[j]=min(val-A[j],m);
  }
  if(*min_element(ALL(B))<0) return false;
  B[i]=0;
  return accumulate(ALL(B),0ll)>=m*(v-1);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin>>n>>m>>v>>p;
  A.resize(n);rep(i,n) cin>>A[i];sort(ALL(A));
  ll l=-1,r=n-1,x;
  while(l+1<r) {
    x=(l+r)/2;
    if(canwin(x)) r=x;else l=x;
  }
  print(n-r);
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  long ans = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      for (int k = 1; k <= N; k++) {
        ans += gcd(gcd(i, j), k);
      }
    }
  }
  cout << ans << "\n";
}

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

int main() {
    int n, q, key;
    int counter=0;
    set<int> datas;
    cin >> n;
    for(int i=0; i<n; i++) {
        int tmp; cin >> tmp; datas.insert(tmp);
    }
    cin >> q;
    for(int i=0; i<q; i++) {
        cin >> key;
        auto itr = datas.find(key);
        if(itr != datas.end()) counter++;
    }
    cout << counter << endl;
    return 0;
}



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

int main() {
  int a,b = 0;
  cin >> a;
  vector<int> vec(a);
  for(int i = 0;i < a;i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  for(int i = 0;i < a;i++) {
    if(i % 2 == 0) {
      b = b + vec.at(i);
    } else {
      b = b - vec.at(i);
    }
  }
  cout << b << endl;
}

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

using namespace std;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF 1e9
#define MOD 1000000007

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

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

void solve() {
  string str;
  cin >> str;
  int n=0, m=0;
  rep(i, str.size()) {
    if (str[i] == '0') n++;
    else m++;
  }
  cout << 2 * min(n, m) << endl;
  
}

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

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A;
        A = new int[N];
        for(int i = 0; i < N; i++){
            A[i] = sc.nextInt();
        }
        int Count = 0;
        int flag = 1;
        while(flag == 1){
            flag = 0;
            for(int j = N-1; j > 0; j--){
                if(A[j] < A[j-1]){
                    int tmp = A[j];
                    A[j] = A[j-1];
                    A[j-1] = tmp;
                    flag = 1;
                    Count++;
                }
            }
        }
        for(int i = 0; i < N-1; i++){
            System.out.print(A[i]+" ");
        }
        System.out.println(A[N-1]);
        System.out.println(Count);
    }
}


Measured memory_bytes: 26320
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	int N;
	cin >> N;

	vint C(N);
	vint A;

	//A
	for (int i = 0; i < N; i++) {
		int tmp;
		int bef;

		cin >> tmp;

		if (i != 0) {
			if (bef + 1 == tmp) {
				A.push_back(bef - 1);
			}
		}

		bef = tmp;
	}

	//B
	int ans = 0;

	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;

		ans += tmp;
	}

	//C
	for (int i = 0; i < N - 1; i++) {
		cin >> C[i];
	}
	for (int i = 0; i < (int)A.size(); i++) {
		ans += C[A[i]];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;

ll INF = 1e+18;
using G = vector<map<int, int>>;

int 
main()
{
  int N; cin >> N;
  vector<char> ori(N);
  rep(i, 0, N) cin >> ori[i];
  map<char, set<int>> m;
  rep(i, 0, N){
    m[ori[i]].insert(i + 1);
  }

  int Q; cin >> Q;
  rep(i, 0, Q){
    int type; cin >> type;
    if(type == 1){
      int index;
      char c;
      cin >> index >> c;
      m[c].insert(index);
      char rc = ori[index - 1];
      if(rc != c) m[rc].erase(index);
      ori[index - 1] = c;
    } else {
      ll l, r; cin >> l >> r;
      if(l > r){
        ll tmp = l;
        l = r;
        r = tmp;
      }
      ll ans = 0;
      rep(i, 0, 26){
        if(m[(char)(97 + i)].size() == 0) continue;
        ll posi = *m[(char)(97 + i)].lower_bound(l);
        if(posi >= l && posi <= r) ++ans;
      }
      cout << ans << endl;
    }
  }
}

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

bool isPrime(int x); 
int gcd(int a, int b); 
vector<int> primeFactorization(int x); 
void printVector(vector<long> list, string str); 
void setPrecision(int n);

int main() {
  int n;
  cin >> n;
  int odd = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;

    if (a%2 == 1) odd++;
  }

  if (odd %2 == 0) {
    cout << "YES" <<endl;
  } else {
    cout << "NO" << endl;
  }
}

int gcd(int a, int b) {
  if (a%b == 0) {
    return b;
  } else return gcd(b, a%b);
}

bool isPrime(int x) {
  if (x < 2) return false;
  if (x == 2) return true;
  if (x % 2 == 0) return false;

  double num = sqrt(x);
  for (int i = 3; i <= num; i+=2) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

// 素因数分解
// example: primeFactorization(12) = vector<int>{2, 2, 3}
vector<int> primeFactorization(int x) {
  vector<int> ans;
  int i = 2;
  while (i*i <= x) {
    if (x % i == 0) {
      ans.push_back(i);
      x /= i;
    } else {
      i++;
    }
  }
  ans.push_back(x);
  return ans;
}

void printVector(vector<long> list, string str) {
  for (int i = 0; i < list.size(); i++) {
    cout << str << ": " << list[i] << endl;
  }
}

void setPrecision(int n) {
  cout << fixed << setprecision(n);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
int main(void)
{
	int D,N;
	float P;
	scanf("%d %d",&D,&N);
	if(N!=100) 
		P=pow(100,D)*N;
	else 
		P=pow(100,D)*(N+1);
	printf("%.0f\n",P);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using lli = long long int;
using i64 = int64_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
  i64 n, t;
  vector<i64> a;
  cin >> n >> t;
  read_n(a, n);
  i64 s = t;
  for (i64 i = 0; i < n - 1; ++i) {
    s += min(t, a[i + 1] - a[i]);
  }
  cout << s << '\n';
  return 0;
}



Measured memory_bytes: 1792
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

import bisect
from collections import defaultdict

def main():
	s=RD()
	t=RD()
	d=defaultdict(list)

	for i,ss in enumerate(s):
		d[ss].append(i)
	#print(d)

	now=-1
	cnt=0

	for tt in t:
		if d[tt]==[]:
			print(-1)
			exit()
		else:
			i=bisect.bisect_right(d[tt],now)
			if len(d[tt])==i:
				cnt+=1
				now=d[tt][0]
			else:
				now=d[tt][i]
		#print(tt,i,now,cnt)
	print(len(s)*cnt+now+1)

























if __name__ == "__main__":
	main()


Measured memory_bytes: 78064
#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define int ll
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 2e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };



#define N 100010
int n, m;
vi par(N); //親
vi ran(N); //木の深さ
vi num(N); //要素数

		   //n要素で初期化
void init(int n) {
	int i;
	for (i = 0; i < n; i++) {
		par[i] = i;
		ran[i] = 0;
		num[i] = 1;
	}
}

//木の根を求める
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}

//xとyの属する集合を併合
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	int numsum = num[x] + num[y];
	if (x == y) {
		return;
	}
	if (ran[x]<ran[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (ran[x] == ran[y]) {
			ran[x]++;
		}
	}
	num[x] = num[y] = numsum;
}

//xとyが同じ集合に属するか否か
bool same(int x, int y) {
	return find(x) == find(y);
}



signed main() {
	int i, j;
	cin >> n >> m;
	vector<pii> a(n + 1);
	for (i = 0; i < n; i++) {
		cin >> a[i].first;
		a[i].second = i;
	}
	a[n] = pii(inf, -1);
	sort(a.begin(), a.end());
	init(n);
	vi x(m), y(m);
	vi used(n, 0);
	for (i = 0; i < m; i++) {
		cin >> x[i] >> y[i];
		unite(x[i], y[i]);
	}
	int cnt = 0;
	for (i = 0; i < n; i++) {
		int temp = find(i);
		if (!used[temp]) {
			used[temp] = 1;
			cnt++;
		}
	}
	if (cnt == 1) {
		cout << 0 << endl;
		return 0;
	}
	if (2 * (cnt - 1) > n) {
		cout << "Impossible" << endl;
		return 0;
	}
	int ans = 0;
	vector<bool> used2(n, false);
	for (i = 0; i < n; i++) {
		int temp = find(a[i].second);
		if (used[temp] == 1) {
			used2[i] = true;
			used[temp] = 2;
			ans += a[i].first;
		}
	}
	pii now;
	cnt = 2 * (cnt - 1) - cnt;
	if (cnt == 0) {
		cout << ans << endl;
		return 0;
	}
	for (i = 0; i < n; i++) {
		if (used2[i]) {
			continue;
		}
		ans += a[i].first;
		cnt--;
		if (cnt == 0) {
			cout << ans << endl;
			return 0;
		}
	}
	/*
	for (i = 1; i < n; i++) {
		pii nx = a[i];
		if (same(now.second, nx.second)) {
			que.push(nx);
		}
		else {
			unite(now.second, nx.second);
			cnt--;
			ans += now.first + nx.first;
			if (cnt == 1) {
				cout << ans << endl;
				return 0;
			}
			if (!que.empty()) {
				now = que.front();
				que.pop();
			}
			else {
				now = a[++i];
			}
		}
	}
	*/
	cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 6528
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[] a = new int[N];
		
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		
		Arrays.sort(a);
		int[] num = new int[N];
		int check = 0;
		int count = 1;
		
		for(int i = 1; i < N; i++) {
			if(a[i] == a[i - 1]) {
				count++;
				if(i == N - 1 && count >= a[i - 1]) {
					num[check] = count - a[i];
				} else if(i == N - 1 && count < a[i - 1]) {
					num[check] = count;
				}
			} else {
				if(count >= a[i - 1]) {
					num[check] = count - a[i - 1];
					count = 1;
					check++;
					if(i == N - 1) {
						num[check] = 1;
					}
				} else {
					num[check] = count;
					count = 1;
					check++;
					if(i == N - 1) {
						num[check] = 1;
					}
				}
			}
		}

		long min = 0;
		
		for(int i = 0; i < num.length; i++) {
			min += num[i];
		}
		if(N > 1) {
			System.out.println(min);
		} else if(N == 1 && a[0] == 1) {
			System.out.println(0);
		} else {
			System.out.println(1);
		}
	}
}


Measured memory_bytes: 50136
#include<bits/stdc++.h>
using namespace std;
int n,k;
long long ans;
int main(){
	cin>>n>>k;
	for(int i=k+1;i<=n;i++){
		//cout<<i<<":";
		long long tmp=n/i;
		//cout<<tmp<<"---"<<(i-k)<<"  ";
		ans+=tmp*(i-k);
		tmp=n%i;
		tmp-=max(k-1,0);
		if(tmp>0) ans+=tmp;//cout<<tmp;
		//cout<<endl;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a.at(i);
	vector<vector<bool>> dp(110,vector<bool>(10010,false));
	dp[0][0]=true;
	rep(i,n){
		rep(j,10010){
			if(dp[i][j]){
				dp[i+1][j]=true;
				dp[i+1][j+a.at(i)]=true;
			}
		}
	}
	for(int i=10000;i>=0;--i){
		for(int j=0;j<=n;++j){
			if(dp[j][i] && i%10!=0){
				cout << i << endl;
				return 0;
			}
		}
	}
	cout << 0 << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int (i)=0; (i)<(n); (i)++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int N;
vector<int> a;
vector<vector<int>> G;
vector<int> ans;
vector<int> dp;
int cnt = 0;

void dfs(int s, int prv){
    bool flg = false;
    auto itr = lower_bound(dp.begin(), dp.end(), a[s]);
    int prev = *itr;
    if(*itr == 1<<30){
        cnt++;
        flg = true;
    }
    *itr = a[s];

    ans[s] = cnt;

    //for(int i=0; i<N; i++){
    //    if(dp[i] == 1<<30){
    //        ans[s] = i;
    //        break;
    //    }
    //}

    for(int t : G[s]){
        if(t == prv) continue;
        dfs(t, s);
    }
    *itr = prev;
    if(flg) cnt--;
}

int main(){
    cin >> N;
    a.resize(N);
    G.resize(N);
    ans.resize(N);
    dp.resize(N, 1<<30);
    REP(i, N) cin >> a[i];
    REP(i, N-1){
        int u, v;
        cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(0, -1);
    for(auto x : ans)
        cout << x << endl;

    return 0;
}

Measured memory_bytes: 30840
//#pragma GCC target ("avx2,sse2")
//#pragma GCC optimization ("Ofast")
//#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <queue>

using namespace std;

const int N = 2e6 + 14;
const int INF = 1e9;
const int mod = 1e9;
const int SZ = (1 << 17) - 1;
const int K = 320;

#define eb emplace_back
#define sz(s) (int)(s.size())
#define ppb pop_back

#define ll long long

#define int ll

int a[N];

void solve() {
	int n;
	cin >> n;
	bool ok = false;
	for (int i = 1; i <= n; ++ i) {
		cin >> a[i];
		if (!(a[i] & 1)) {
			if (a[i] % 3 == 0 or a[i] % 5 == 0) {
				continue;
			}
			ok = true;
		}
	}
	cout << (!ok ? "APPROVED" : "DENIED");
}

main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cerr << "Ready\n";
	solve();
	return 0;
}

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

int main() {
  int n , k;
  cin >> n >> k;
  vector<int> price(n);
  for(int i=0;i<n;i++){
    int a;
    cin >>a;
    price[i]=a;
  }
  sort(price.begin() , price.end() );
  int ans=0;
  for(int i=0; i<k; i++)
    ans += price[i];
  cout << ans << endl;
}


Measured memory_bytes: 3632
#include<stdio.h>

void swap(long long int* a, long long int* b)
{
    long long int c=*a;
    *a=*b;
    *b=c;
}
long long int gcd(long long int a, long long int b)
{
    if(a<b)
    {
        swap(&a,&b);
    }
    while(a%b!=0)
    {
        long long int c=a%b;
        a=b;
        b=c;
    }
    return b;
}

int main()
{
    int n;
    scanf("%d", &n);
    long long int p[n+5];
    for(int i=0; i<n; i++)
    {
        scanf("%lld", &p[i]);
    }
    long long int ans = p[0];
    for(int i=1; i<n; i++)
    {
        ans = gcd(ans, p[i]);
    }
    printf("%lld\n", ans);

    return 0;
}


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

using namespace std;

int n, a[105];
bool dp[105][105];

int main(){
	scanf("%d", &n);
	
	for(int i = 1; i <= n; i++)
	scanf("%d", &a[i]);
	
	for(int i = 1; i <= n + 1; i++)
	dp[0][i] = 1;
	
	for(int i = 1; i <= n + 1; i++){
		if(a[i] && i != n + 1) continue;
		for(int j = 1; j <= n + 1; j++){
			for(int k = 1; k <= j; k++){
				if(i - k < 0) break;
				dp[i][j] |= dp[i - k][j];
			}
		}
	}
	
	for(int i = 1; i <= n + 1; i++){
		if(dp[n + 1][i])
		return 0 * printf("%d\n", i);
	}
}



Measured memory_bytes: 3224
#!/usr/bin/env python3
# CGL_1_C: Points/Vectors - Counter-Clockwise

from enum import Enum
from math import sqrt


class Position(Enum):
    COUNTER_CLOCKWISE = 0
    CLOCKWISE = 1
    ONLINE_BACK = 2
    ONLINE_FRONT = 3
    ON_SEGMENT = 4


def dot(v1, v2):
    x1, y1 = v1
    x2, y2 = v2
    return x1 * x2 + y1 * y2


def length(v):
    x, y = v
    return sqrt(x**2 + y**2)


def orthogonal(v):
    x, y = v
    return -y, x


def ccw(v1, v2):
    d1 = dot(v1, v2)
    d2 = dot(orthogonal(v1), v2)

    if d2 > 0:
        return Position.COUNTER_CLOCKWISE
    elif d2 < 0:
        return Position.CLOCKWISE
    elif d1 < 0:
        return Position.ONLINE_BACK
    else:
        if length(v1) >= length(v2):
            return Position.ON_SEGMENT
        else:
            return Position.ONLINE_FRONT


def run():
    x0, y0, x1, y1 = [int(i) for i in input().split()]
    q = int(input())

    for _ in range(q):
        x2, y2 = [int(i) for i in input().split()]
        pos = ccw((x1-x0, y1-y0), (x2-x0, y2-y0))
        print(pos.name)


if __name__ == '__main__':
    run()



Measured memory_bytes: 6392
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        int N = sc.nextInt();
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < N; ++i) {
            int a = sc.nextInt();
            if (set.contains(a)) {
                set.remove(a);
            } else {
                set.add(a);
            }
        }
        _out.println(set.size());
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 60700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int k, x;
    cin >> k >> x;
    if (k * 500 >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

using namespace std;

#define EPS 1e-8
typedef complex<double> Point;

int main(){
  int N;
  while(cin >> N,N){
    Point p[N];
    for(int i = 0 ; i < N ; i++){
      cin >> p[i].real() >> p[i].imag();
    }
    int res = 1;
    for(int i = 0 ; i < N-1 ; i++){
      for(int j = i+1 ; j < N ; j++){
        Point np = p[j]-p[i];
        double d = abs(np);
        if(d + EPS > 2.0){ continue; }
        np /= d;
        np *= Point(0,1);
        Point cp = (p[i]+p[j])/2.0;
        Point v = sqrt(1.0-d*d/4.0)*np;
        int cnt = 2;
        Point center = cp + v;
        for(int k = 0 ; k < N ; k++){
          if(i == k || j == k) continue;
          Point diff = center-p[k];
          if(norm(diff) < 1.0 + EPS){
            cnt++;
          }
        }
        res = max(res,cnt);
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1260
// Created by Kshitij Anand NSIT
#include <bits/stdc++.h>
//#include <ext/numeric>
//using namespace __gnu_cxx;


using namespace std;


#define int long long
#define pb push_back
#define P pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define vc vector<char>
#define vb vector<bool>
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define mp(a, b) make_pair(a, b)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define fill(arr,val) memset(arr,val,sizeof(arr))
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x
#define db(x)  cout<<#x<<" : "<<x<<endl


const int N = 1000000007;

int dp[2001] = {};

int func(int n){

    // if(n <= 3)return 1;

    if(dp[n] != -1)return dp[n];

    int ans = 0;
    bool check = true;
    for(int i=3; i<=n ; i++) {
        if(n - i >=3  || n - i ==0){
            check = false;
            ans = (ans%N + func(n - i)%N)%N;

        }
    }
    if(check)ans = (ans%N + 1)%N;

    dp[n] = ans;

    return ans;
}

void solve(){

    int n,a,b,c, ans=0, count=0, sum=0;
    cin>>n;
    if(n <=2){

        cout<<0<<endl;
        return;
    }
    fill(dp , -1);
    cout<<func(n)<<endl;  
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    
  //  int t; cin>>t; while(t--)
    {     
      solve();
    }

  return 0;
}


Measured memory_bytes: 3660
using System;
using System.Collections.Generic;

namespace AOJ.Volume0
{
    public class RhombicPath
    {
        public static int Main()
        {
            var data = new List<string>();
            while (true)
            {
                var input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) { break; }
                data.Add(input);
            }

            int n = (data.Count / 2) + 1;
            var path = new int[data.Count, n];
            int cnt = 0;
            foreach(var d in data)
            {
                var tmp = d.Split(',');
                int tmp_c = tmp.Length;
                for(int i = 0; i < tmp_c; i++) { path[cnt, i] = int.Parse(tmp[i]); }
                cnt++;
            }

            var dp = new int[data.Count, n];
            dp[0, 0] = path[0, 0];
            int stop = -1;
            for (int i = 0; i < data.Count - 1; i++)
            {
                if (i < n) { stop++; }
                else { stop--; }
                for(int j = 0; j <= stop; j++)
                {
                    // ????????????n-1???????????§?????????????????????????????????????????????
                    // n??????????????????????????§???????????????????????????????????????????????????
                    if (i < n - 1)
                    {
                        dp[i + 1, j] = Math.Max(dp[i + 1, j], dp[i, j] + path[i + 1, j]);
                        dp[i + 1, j + 1] = Math.Max(dp[i + 1, j + 1], dp[i, j] + path[i + 1, j + 1]);
                    }
                    else
                    {
                        if (j == 0)
                        {
                            // ?????????????????????
                            dp[i + 1, j] = Math.Max(dp[i + 1, j], dp[i, j] + path[i + 1, j]);
                        }
                        else if(j == stop)
                        {
                            // ?????????????????????
                            dp[i + 1, j - 1] = Math.Max(dp[i + 1, j - 1], dp[i, j] + path[i + 1, j - 1]);
                        }
                        else
                        {
                            dp[i + 1, j] = Math.Max(dp[i + 1, j], dp[i, j] + path[i + 1, j]);
                            dp[i + 1, j - 1] = Math.Max(dp[i + 1, j - 1], dp[i, j] + path[i + 1, j - 1]);
                        }
                    }
                }
            }

            Console.WriteLine(dp[data.Count - 1, 0]);
            return 0;
        }
    }
}

Measured memory_bytes: 9408
#include <vector>
#include <iostream>

using namespace std;

const int kSize = 100;
int n;

void Print(int A[kSize]) {
    for (int i = 0; i < n; ++i) {
        if (i > 0) {
            cout << " ";
        }

        cout << A[i];
    }

    cout << endl;
}

int main() {
    cin >> n;
    int A[kSize];

    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }

    Print(A);

    for (int i = 1; i < n; ++i) {
        int var = A[i];
        int j = i - 1;
        for (; j >= 0 && A[j] > var; --j) {
            A[j + 1] = A[j];
        }

        A[j + 1] = var;
        Print(A);
    }
}


Measured memory_bytes: 3100
#include "bits/stdc++.h"
using namespace std;
void solve(){
    long long mina, maxa, n;
    mina = 1000000010;
    maxa = 0;
    cin >> n;
    vector<long long> data(n);
    for(int i = 0; i < n; i++){
    cin >> data.at(i);
    mina = min(mina, data.at(i));
    maxa = max(maxa, data.at(i));
    }
    cout << abs(maxa - mina) << endl;
}
int main(){
    solve();
    return 0;
}

Measured memory_bytes: 256
N = input()
A = sorted(list(map(int, input().split())))
ans = 1

for i in A:
    if i == 0: 
        ans = 0
        break
    elif ans > 10**18:
        break
    else:
        ans *=i

if ans > 10**18:
    print(-1)
else:
    print(ans)


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

#define f(i,a,b) for( ll  i = a; i < (ll) 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 all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter   ios::sync_with_stdio(false);cin.tie(0)

// policy-based



using namespace std;


typedef long long ll; // int or long long
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;



 
const ll MAX = 2e6+1;
const ll inf = 1e9;
const ll mod = 998244353;


ll res[MAX];
ll pos[MAX];
int main(){
	fastio;
	ll n,x,m,per,ini;
	cin >> n >> x >> m;
	if(x == 0){
		cout << "0\n";
		return 0;
	}
	res[0] = x%m;
	f(i,0,MAX) pos[i] = -1;
	pos[ res[0] ] = 0;
	f(i,1,MAX){
		res[i] = (res[i-1]*res[i-1])%m;
		if(pos[ res[i]] != -1) {
			ini = pos[res[i]];
			per = i - ini ;
			break;
		}
		pos[res[i]] = i;
	}	

	ll ans = 0,sum =0;
	if(n <= ini) f(i,0,n) ans += res[i];
	else{
		f(i,0,ini) ans += res[i];
		f(i,ini,ini+per) sum += res[i];
		f(i,ini, ini +  (n-ini)%per ) ans += res[i];
		ans += sum * ( (n-ini)/per);

	}

	cout << ans - res[0] + x << endl;
	return 0;
} 

Measured memory_bytes: 19592
//#define TEST
using System;
using static System.Console;

class Program
{
    static void Main()
    {
        var n = int.Parse(ReadLine());
        double[] ta = Array.ConvertAll(ReadLine().Split(),double.Parse);
        var t = ta[0];
        var a = ta[1];
        double[] h = Array.ConvertAll(ReadLine().Split(), double.Parse);

        var tempPos = 0;
        var tempTemp = Math.Abs(a - (t - h[0] * 0.006));
        for (var i = 0; i < n; i++)
        {
            var compTemp =Math.Abs(a - (t - h[i] * 0.006));
#if TEST
            WriteLine(compTemp);
#endif
            if (compTemp < tempTemp)
            {
                tempPos = i;
                tempTemp = compTemp;
            }
        }
        WriteLine(++tempPos);
    }
}

Measured memory_bytes: 11164
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

template<typename V,typename H> void resize(vector<V>& v,const H a){v.resize(a);}
template<typename V,typename H,typename... T> void resize(vector<V>& v,const H& a,const T... b){v.resize(a);for(auto &v:v) resize(v,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

vi a(3);

signed main(){

    in(a);
    sort(all(a));
    out(a[0],a[1],a[2]);

    return 0;
}



Measured memory_bytes: 3096
#include <stdio.h>
#include <stdlib.h>
 
int main()
{
    char s[4];
    scanf("%s",s);
    int a=0,i;
    for(i=0;i<4;i++)
    {
        if(s[i]=='-')
        {
            a--;
        }
        if(s[i]=='+')
            a++;
 
    }
    printf("%d\n",a);
    return 0;
}

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


int main() {
    string S;
    cin >> S;
    if (S == "Sunny") {
        cout << "Cloudy" << endl;
    } else if (S == "Cloudy") {
        cout << "Rainy" << endl;
    } else {
        cout << "Sunny" << endl;
    }

}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
Scanner scan=new Scanner(System.in);
String a=scan.next();
String b=scan.next();
String c=scan.next();
System.out.println(a.charAt(0)+""+b.charAt(1)+""+c.charAt(2));
}
	}

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

int main()
{
  int N;
  cin >> N;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  vector<int64_t> L(N), R(N);
  L.at(0) = A.at(0), R.at(N - 1) = A.at(N - 1);
  for (int i = 1; i < N; i++)
  {
    L.at(i) = __gcd(A.at(i), L.at(i - 1));
  }
  for (int i = N - 2; i >= 0; i--)
  {
    R.at(i) = __gcd(A.at(i), R.at(i + 1));
  }
  int64_t ans = max(L.at(N - 2), R.at(1));
  for (int i = 1; i < N - 1; i++)
  {
    ans = max(ans, __gcd(L.at(i - 1), R.at(i + 1)));
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();

            var max = 0;
            var cur = 0;
            for (var i = 0; i < N; i++)
            {
                if (S[i] == 'I')
                {
                    cur++;
                    max = Math.Max(cur, max);
                }
                else
                    cur--;
            }

            Console.WriteLine(max);
        }
    }
}


Measured memory_bytes: 13140
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

int cnt[26];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        cnt[s[0]-'A']++;
    }
    int ans = 0;
    while (1) {
        int tmp = 0;
        sort(cnt, cnt+26);
        reverse(cnt, cnt+26);
        for (int i = 0; i < 26; i++) {
            if (tmp >= K) break;
            if (cnt[i]) {
                tmp++;
                cnt[i]--;
            }
        }
        if (tmp < K) break;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
vector<int> sfl(int c, vector<int> v){
	int n = v.size();
	vector<int> res;
	for(int i = 0; i < n/2 + 1; i+=c){
		REP(j,c){
			if(n/2 + i + j < n)res.push_back(v[n/2+i+j]);
		}
		REP(j,c){
			if(i + j < n/2)res.push_back(v[i+j]);
		}
	}
	return res;
}

int main(){
	int n,r;
	while(cin>>n>>r){
		vector<int> v(n);
		REP(i,n)v[i] = i;
		REP(i,r){
			int c;
			cin>>c;
			v = sfl(c,v);
		}
		cout<<v.back()<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;
class Main{
	public static void main(String[]agrs){
    Scanner sc = new Scanner(System.in);
	int a;
	int b;
	
	a = sc.nextInt();
	b = sc.nextInt();
	System.out.print(a*b);
	System.out.print(" ");
	System.out.println((a+b)*2);
	}
}

Measured memory_bytes: 17156
#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;

const int letter_MAX = 1201;
int co[26] = {};
int letter[letter_MAX];


int main(){
	for (int j = 0; j < letter_MAX;j++){
		letter[j]=getchar();
		if (letter[j] == EOF)break;
		letter[j] = tolower(letter[j]);
		for (int i = 0; i < 26; i++){
			if (i == letter[j] - 'a')co[i]++;
		}
	}
	for (int i = 0; i < 26; i++){
		char a = i + 'a';
		cout << a << " : " << co[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3076
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder output = new StringBuilder();

//      ?????°????????????????????????????§????????????????????????????????????????1????????????????????????
        while(true){

            String input = br.readLine();
            String[] strArray = input.split(" ");

            int H = Integer.parseInt(strArray[0]);  //?????????'#'?????°
            int W = Integer.parseInt(strArray[1]);  //?????????'#'?????°

//          H??¨W?????±???0?????¨??????????????????
            if(H == 0 && W == 0){
                break;
            }

            for(int i = 0; i < H; i++){
                for(int j = 0; j < W; j++){
                    output.append("#");
                }
                output.append("\n");
            }
            output.append("\n");
        }
        System.out.print(output);
    }
}

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

int h[100010];
int main() {
	int n; cin >> n;
	for (int i=1; i<=n; ++i) {
		cin >> h[i];
	}

	h[0] = 0;
	for (int i=n; i>0; --i) {
		if (h[i]>=h[i-1]) {
          continue;
        } else {
          if (h[i]>=h[i-1]-1) {
              h[i-1] = h[i-1]-1;
              continue;
          }
        }
		cout << "No" << endl;
      	return 0;
	}
	cout << "Yes" << endl;
	
	return 0;
}


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

class cmp {
  public:
  bool operator() (pair<int, int> x, pair<int, int> y) {
    return 1LL * x.first * (1 << y.second) < 1LL * y.first * (1 << x.second);
  }
};

int main() { // claudio van
  int n, m; scanf("%d %d", &n, &m);
  priority_queue<pair<int, int>, vector<pair<int, int> >, cmp> pq;
  for (int i = 0; i < n; ++i) {
    int x; scanf("%d", &x);
    pq.push(make_pair(x, 0));
  }
  for (int i = 0; i < m; ++i) {
    pair<int, int> t = pq.top(); pq.pop();
    if (t.first / (1 << t.second) == 0) break;
    t.second++;
    pq.push(t);
  }
  ll ans = 0;
  for (int i = 0; i < n; ++i) {
    pair<int, int> t = pq.top(); pq.pop();
    ans += t.first / (1 << t.second);
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 1400
N,T = map(int,input().split())
t = list(map(int,input().split()))
dff_list = list()

if N == 1:
  print(T)
  exit(0)
  
for i in range(1,N):
  dff = t[i] - t[i -1]
  dff_list.append(dff)
  
ans_list = [T if T <= i else i for i in dff_list]

ans = sum(ans_list) + T
print(ans)

Measured memory_bytes: 26836
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, a, n) for (int i = a; i <= (n); ++i)

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

    if (R < 1200) {
        cout << "ABC" << endl;
    } else if (R < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N,K;
int A[200005], B[200005]; // 逆回り 

int main() {
  INCANT;
  cin >> K >> N;
  rep(i, N) cin >> A[i];
  int d = 0;
  rep(i, N-1) {
    d = max(d, A[i+1]-A[i]);
  }
  d = max(K+A[0]-A[N-1], d);

  cout << K-d << "\n";
  return 0;
}

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

int main(){
    int N,M;
    cin >> N >> M;
    int cnt = 0;
    if(N>1){
        cnt += N*(N-1)/2;
    }
    if(M>1){
        cnt += M*(M-1)/2;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String integers = br.readLine();
			System.out.println(compare(integers));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private static String compare(String integers) {
		String[] integerss = integers.split(" ");
		int a = Integer.parseInt(integerss[0]);
		int b = Integer.parseInt(integerss[1]);
		if (a < b) {
			return "a < b";
		} else if (a > b) {
			return "a > b";
		}
		return "a == b";
	}
}


Measured memory_bytes: 24308
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();

		for (int i = 0; i < S.length(); i++) {
			S = S.substring(1) + S.charAt(0);
			if (S.equals(T)) {
				System.out.println("Yes");
				return;
			}
		}

		System.out.println("No");

		return;
	}
}


Measured memory_bytes: 22868