akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<array>
#include<algorithm>
using namespace std;
int main(){
    array<long long,50>a;
    int n,minn,maxn;
    long long min = 1000001;
    long long max = -1000001;
    cin>>n;
    for(int i = 0; i < n; i++){
        cin>>a.at(i);
        if(min > a.at(i)){
            min = a.at(i);
            minn = i;
        }
        if(max < a.at(i)){
            max = a.at(i);
            maxn = i;
        }
    }
    if(min*max<=0){
      cout<<2*n-1<<endl;
    if(abs(min) >= abs(max)){
        for(int i = 0; i <n;i++){
            cout<<minn+1<<' '<<i+1<<endl;
        }
        for(int i = n; i > 1; i--){
            cout<<i<<' '<<i-1<<endl;
        }
    }else{
        for(int i = 0; i < n; i++){
            cout<<maxn+1<<' '<<i+1<<endl;
        }
        for(int i = 1; i < n; i++){
            cout<<i<<' '<<i+1<<endl;
        }
    }
    }
    if(min > 0 && max > 0){
      cout<<n-1<<endl;
        for(int i = 1; i < n; i++){
            cout<<i<<' '<<i+1<<endl;
    }
    }
    if(min < 0 && max < 0){
      cout<<n-1<<endl;
        for(int i = n; i > 1; i--){
            cout<<i<<' '<<i-1<<endl;
        }
    }
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>

int main()
{
	int x[5];
	for( int i = 0; i < 5; i++ ){
		std::cin >> x[i];
	}
	
	std::sort( x, x + 5 );

	std::cout << x[4];
	
	for( int i = 3; i >= 0; i-- ){
	 	std::cout << " " << x[i];
	}
	
	std::cout << std::endl;

 	return 0;
}

Measured memory_bytes: 1176
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 100010
bool used[N];
vector<int> g[N];
ll d[N], sz[N];
vector<int> path;
int n;
bool dfs(int u){
	used[u] = true;
	sz[u] = 1;
	bool res = u==n-1;
	for(auto v: g[u]){
		if(used[v]) continue;
		d[v] = d[u]+1;
		res |= dfs(v);
		sz[u] += sz[v];
	}
	if(res) path.pb(u);
	return res;
}

int main(){
	cin>>n;
	rep(i, n-1){
		int a, b;
		cin>>a>>b;
		a--; b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	dfs(0);
	queue<int> q[2];
	int cnt[2];
	cnt[0] = (path.size()+1)/2; cnt[1] = path.size()/2;
	reverse(all(path));
	mset(used, 0);
	{
		int l = 0, r = path.size()-1;
		while(l<=r){
			q[0].push(path[l++]);
			if(l<=r) q[1].push(path[r--]);
		}
		for(auto x: path) used[x] = true;
	}
	rep(i, 2){
		while(!q[i].empty()){
			int u = q[i].front(); q[i].pop();
			for(auto v: g[u]){
				if(used[v]) continue;
				q[i].push(v);
				cnt[i]++;
				used[v] = true;
			}
		}
	}
	cout<<(cnt[1]>=cnt[0]?"Snuke":"Fennec")<<endl;
	return 0;
}


Measured memory_bytes: 14456
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <signal.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }

void rsorta_d32(void *base, const int count, const int size, const int index){
	typedef int32_t rsort_t;
	rsort_t (*a)[size] = (rsort_t(*)[size])base;
	rsort_t (*b)[size] = (rsort_t(*)[size])malloc(count*size*sizeof(rsort_t));
	int c[0x100];
	for(int k=0; k<4; k++){
		memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(k<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(k<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	}
	free(b);
}

int main(void){
	int n=nextint();
	int ans=0;
	for(int i=1; i<=n; i++){
		int a=nextint();
		if((a&i&1)==1) ans++;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 1568
#include <stdio.h>
#include <algorithm>
using namespace std;
int n, cnt[100100], p = 998244353;
typedef long long ll;
int main(void) {
	scanf("%d", &n);
	int x; scanf("%d", &x);
	if (x != 0) {
		return !printf("0\n");
	}
	cnt[0] = 1;

	for (int i = 1; i < n; i++) {
		scanf("%d", &x);
		cnt[x]++;
	}
	
	if (cnt[0] != 1) {
		return !printf("0\n");
	}

	while (cnt[n] == 0) n--;

	ll ans = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < cnt[i + 1]; j++) {
			ans *= cnt[i];
			ans %= p;
		}
	}
	
	printf("%lld\n", ans);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL);

int main() {
  FAST;
  string S;
  cin >> S;
  if (S == "ABC") {
    cout << "ARC" << endl;
  }
  else {
    cout << "ABC" << endl;
  }
}

Measured memory_bytes: 3604
/*
 * Articulation Points
 * Find articulation points of a given undirected graph G(V,E).
 *
 * A vertex in an undirected graph is an articulation point (or cut vertex) iff
 * removing it disconnects the graph.
 *
 * Input
 * |V| |E|
 * s0 t0
 * s1 t1
 * :
 * s|E|−1 t|E|−1
 * , where |V| is the number of vertices and |E| is the number of edges in the
 * graph. The graph vertices are named with the numbers 0, 1,..., |V|-1
 * respectively.
 *
 * si and ti represent source and target verticess of i-th edge (undirected).
 *
 * Output
 * A list of articulation points of the graph G ordered by name.
 *
 * Constraints
 * 1 ≤ |V| ≤ 100,000
 * 0 ≤ |E| ≤ 100,000
 * The graph is connected
 * There are no parallel edges
 * There are no self-loops
 */

#include <algorithm>
#include <iostream>
#include <stack>
using namespace std;

struct edge {
  int to, next;
} E[200000];

struct {
  int pre, low, parent;
} tree[100000];

struct dfsdata {
  int id, parent;
  bool token;
};

int LE[100000];
bool visited[100000];

int prenumber = 0;

void dfs(int u, int parent) {
  ++prenumber;
  tree[u] = {prenumber, prenumber, parent};
  for (int j = LE[u]; j != -1; j = E[j].next) {
    int v = E[j].to;
    if (v == parent)
      continue;
    if (visited[v]) {
      tree[u].low = min(tree[u].low, tree[v].pre);
    } else {
      visited[v] = true;
      dfs(v, u);
      tree[u].low = min(tree[u].low, tree[v].low);
    }
  }
}

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

  fill(LE, LE + 100000, -1);
  fill(visited, visited + 100000, false);

  int n, m;
  cin >> n >> m;
  for (int i = 0, src, dst; i < 2 * m; i += 2) {
    cin >> src >> dst;
    E[i] = {dst, LE[src]};
    LE[src] = i;
    E[i + 1] = {src, LE[dst]};
    LE[dst] = i + 1;
  }

  visited[0] = true;
  dfs(0, -1);

  // node 0 chosen arbitrarily
  // given: graph is connected => 0 is only root
  int n_children_of_root = 0;
  for (int i = 0; i < n; ++i) {
    if (tree[i].parent == 0)
      ++n_children_of_root;
  }
  if (n_children_of_root > 1)
    cout << 0 << endl;

  for (int i = 1; i < n; ++i) {
    for (int j = LE[i]; j != -1; j = E[j].next) {
      if (tree[E[j].to].parent == i and tree[E[j].to].low >= tree[i].pre) {
        cout << i << endl;
        break;
      }
    }
  }
}


Measured memory_bytes: 4836
import sys
import math

N = int(input())
ALPHABET = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
result = []

def alphabet_decimal(v):
    quotient = math.floor(v / len(ALPHABET))
    surplus = v % len(ALPHABET)
    quotient -= 1 if surplus == 0 else 0
    surplus = len(ALPHABET) if surplus == 0 else surplus
    result.append(surplus)
    if len(ALPHABET) < quotient:
        alphabet_decimal(quotient)
    elif len(ALPHABET) < v:
        result.append(quotient)
    return "".join([ALPHABET[i - 1] for i in reversed(result)])

print(alphabet_decimal(N).lower())

Measured memory_bytes: 9236
import numpy as np

def main():
    X,Y = map(int, input().split())
    res = 0
    if(X in [1,2,3]):
        if(X==1):
            res += 300000
        elif(X==2):
            res += 200000
        else:
            res += 100000
    if(Y in[1,2,3]):
        if(Y==1):
            res += 300000
        elif(Y==2):
            res += 200000
        else:
            res += 100000
    if(X==1 and Y==1):
        res += 400000
    print(res)


if __name__ == "__main__":
    main()


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

//vector <long long> v[200001][4];

//stack <long long> s[1000000], wym;

//queue <long long> s;

long long int  x[100][100], y[10000], z;
char s[10000];

int main()
{
    long long int d, e, f, i, j, q, t, n, m, a, b, c, w, p;
    double k;
    t=1;
//    scanf("%lld", &t);
    for(q=1; q<=t; q++)
    {
        scanf("%lld", &n);

        w=0;

        for(i=0; i<n; i++)
        {
            scanf("%s", s);
            b=strlen(s);
            c=9;
            a=0;
            for(j=0; j<b; j++)
            {
                if(s[j]=='.')c=10-b+j;
                else
                {
                    a*=10;
                    a+=s[j]-'0';
                }
            }
            for(j=0; j<c; j++)a*=10;
            b=0;
            c=0;
            while(a%2==0 && b<18){a/=2;b++;}
            while(a%5==0 && c<18){a/=5;c++;}
            x[b][c]++;
        }

        for(i=0; i<=18; i++)
        {
            for(j=0; j<=18; j++)
            {
                for(a=0; a<=18; a++)
                {
                    for(b=0; b<=18; b++)
                    {
                        if(i+a>=18 && j+b>=18)
                        {
                            if(a==i && b==j)w+=(x[i][j]*(x[a][b]-1))/2;
                            else w+=x[i][j]*x[a][b];
                        }
                    }
                }
                x[i][j]=0;
            }
        }

        printf("%lld\n", w);

    }
    return(0);
}


Measured memory_bytes: 3776
# coding=utf-8
def merge(a, left, mid, right):
    n1 = mid-left
    n2 = right - mid

    left_list = [a[left + i] for i in range(n1)]
    right_list = [a[mid + i] for i in range(n2)]
    left_list.append(1000000007)
    right_list.append(1000000007)

    i = 0
    j = 0
    ctr = 0
    for k in range(left, right):
        ctr += 1
        if left_list[i] <= right_list[j]:
            a[k] = left_list[i]
            i += 1
        else:
            a[k] = right_list[j]
            j += 1
    return ctr


def merge_sort(a, left, right, counter):
    if left+1 < right:
        mid = (left + right)//2
        counter1 = merge_sort(a, left, mid, counter)[1]
        counter2 = merge_sort(a, mid, right, counter)[1]
        counter += merge(a, left, mid, right)
        counter += counter1
        counter += counter2
    return a, counter


if __name__ == '__main__':
    n = int(input())
    S = list(map(int, input().split()))
    merge_counter = 0
    S, merge_counter = merge_sort(S[:], 0, len(S), merge_counter)

    print(' '.join(map(str, S)))
    print(merge_counter)

Measured memory_bytes: 66596
import math
A, B, H, M = map(int, input().split())
time = H*60+M
h_a = (time/720)*360
m_a = M*6
arg = abs(h_a - m_a)
print(math.sqrt(float(A)**2 + float(B)**2 - 2*A*B*math.cos(math.radians(arg))))

Measured memory_bytes: 9508
#include <iostream>
#include<vector>
#define rep(i,n) for(int i= 0;i < (n); ++i)
using namespace std;

int main() {
    int h,w,k;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    int ans = 0;
    rep(is,1 << h)rep(js,1<<w){
        int cnt = 0;
        rep(i,h)rep(j,w){
            if(is >> i&1)continue;
            if(js >> j&1)continue;
            if(s[i][j]== '#') cnt++;
        }
        if(cnt == k) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << (a-c) * (b- d) << endl;
}


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

using vi = vector<int>;
#define f(i,a,b) for (int i = a; i < b; i++)
#define pb push_back

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	clock_t start = clock();
#endif

	int n; cin >> n;
	vi adj[n];
	f(i,0,n-1) {
		int a,b; cin>>a>>b;
		adj[--a].pb(--b); adj[b].pb(a);
	}
	bool found = 0;
	function<int(int,int)> dfs = [&](int v, int p) {
		int ans = 0;
		for (int w : adj[v]) if (w != p)
			ans += dfs(w,v);
		if (ans == 0) return 1;
		if (ans == 1) return 0;
		found = 1;
		return 0;
	};
	found |= dfs(0,-1);
	cout << (found?"First":"Second") << endl;


#ifdef LOCAL
	cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
#endif
	
	return 0;
}



Measured memory_bytes: 5888
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        String S = scanner.next();
        String T = scanner.next();
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        String U = scanner.next();
        if (U.compareTo(S)==0){
            A--;
        }else {
            B--;
        }
        pw.println(A);
        pw.println(B);
        pw.close();
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(String file) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(file));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll n;
ll dp[102][100005];
pair<ll,ll>ar[105];
ll answer(ll w,ll index){
	if(w<=0||index>=n)
		return 0;
	if(w<ar[index].first)
		return answer(w,index+1);
	if(dp[index][w]!=-1)
		return dp[index][w];
	return dp[index][w]=max(answer(w-(ar[index].first),index+1)+ar[index].second,answer(w,index+1));
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	for(int i=0;i<102;i++){
		for(int j=0;j<100005;j++)
			dp[i][j]=-1;
	}
	ll w;
	cin>>n>>w;
	for(ll i=0;i<n;i++){
		ll a,b;
		cin>>a>>b;
		ar[i]={a,b};
	}
	cout<<answer(w,0);
}

Measured memory_bytes: 80000
import std.stdio;

int[40] dp;

void main(){
	int n;
	dp[1..4] = [1, 2, 4];
	foreach (i; 3..30) dp[i+1] = dp[i] + dp[i-1] + dp[i-2];
	while (readf("%d\n", &n), n) writeln((((dp[n]+9)/10)+364)/365);
}

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

int main(){
	int n;
	cin >> n;
	vector<int> p(n);
	rep(i,n) cin >> p[i];
	int counts = 0;
	rep(i,n) if(p[i] != i + 1) counts++;
	if(counts == 2 || counts == 0) cout << "YES" << endl;
	else cout << "NO" << endl;
} 

// cout << fixed << setprecision(15) <<  << endl;

Measured memory_bytes: 3560
import collections

N = int(input())
V = [int(_) for _ in input().split()]

def calc(vs):
    cs = collections.Counter(vs)
    cs[0] = 0
    return cs.most_common()

ve = calc(V[::2])
vo = calc(V[1::2])

result = 0

if ve[0][0] != vo[0][0]:
    result = N - ve[0][1] - vo[0][1]
else:
    result = N - max(ve[0][1] + vo[1][1], ve[1][1] + vo[0][1])

print(result)



Measured memory_bytes: 20700
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        long q = Long.parseLong(sc.next());
        long h = Long.parseLong(sc.next());
        long s = Long.parseLong(sc.next());
        long d = Long.parseLong(sc.next());
        long n = Long.parseLong(sc.next());

        // 主処理
        double[] priceS = new double[] { q * 4.0, h * 2.0, (double) s };
        double[] priceD = new double[] { q * 8.0, h * 4.0, s * 2.0, (double) d };
        long minS = (long) Arrays.stream(priceS).min().getAsDouble();
        long minD = (long) Arrays.stream(priceD).min().getAsDouble();

        long result = n / 2 * minD + n % 2 * minS;

        // 出力
        System.out.println(result);
        sc.close();
    }
}


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

using namespace std;
int main(){
    int h,n,k;
    long long int sum=0;
    cin>>h>>n;
    for(int i=0;i<n;i++){
        cin>>k;
        sum+=k;
    }
    if(sum>=h){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <functional>
#include <set>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

void solve() {
    int h, w;
    std::cin >> h >> w;

    std::vector<std::string> ss(h);
    for (auto& s : ss) std::cin >> s;

    auto dp = vec(h, vec(h, vec(w, vec(w, -1))));

    std::function<int(int, int, int, int)>
        dfs = [&](int lx, int rx, int ly, int ry) {
            if (rx < lx || ry < ly) return 0;

            auto& ret = dp[lx][rx][ly][ry];
            if (ret != -1) return ret;

            std::set<int> gs;
            for (int x = lx; x <= rx; ++x) {
                for (int y = ly; y <= ry; ++y) {
                    if (ss[x][y] == 'X') continue;

                    int g = dfs(lx, x - 1, ly, y - 1) ^
                            dfs(x + 1, rx, ly, y - 1) ^
                            dfs(lx, x - 1, y + 1, ry) ^
                            dfs(x + 1, rx, y + 1, ry);
                    gs.insert(g);
                }
            }

            for (int i = 0;; ++i) {
                if (!gs.count(i)) {
                    ret = i;
                    break;
                }
            }
            return ret;
        };

    int g = dfs(0, h - 1, 0, w - 1);
    std::cout << (g == 0 ? "Second" : "First") << std::endl;
}

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

    solve();

    return 0;
}



Measured memory_bytes: 4204
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main() {
    ll n,k;
    cin >> n >> k;
    int a[n];
    REP(i,n) a[i] = 0;
    REP(i,k){
        int d;
        cin >> d;
        REP(j,d){
            int aij;
            cin >> aij;
            a[aij-1]++;
        }
    }
    int ans = 0;
    REP(i,n){
        if(a[i] == 0) ans++;
    }

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

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

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

bool is_prime(int n) {
    if (n == 1) return false;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return true;
}

int main() {
    int a, d, n;
    while (cin >> a >> d >> n, a) {
        while (n--) {
            while (!is_prime(a)) a += d;
            a += d;
        }
        a -= d;
        cout << a << endl;
    }
    return 0;
}

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

const int maxn = 202000;
ll a[maxn], n, m;
ll ans = 0x3f3f3f3f3f3f3f3f;

bool judge(int x) {
    ll res = 0;
    assert((n - x) % 2 == 0);
    for(int l = x + 1, r = n; l < r; l++, r--) {
        if(a[l] + a[r] < m) return false;
        res = max(res, a[l] + a[r] - m);
    }
    for(int l = 1, r = x; l < r; l++, r--) {
        res = max(res, a[l] + a[r]);
    }
    ans = min(ans, res);
    return true;
}

int main() {
    scanf("%lld%lld", &n, &m);
    n <<= 1;
    rep(i, n) scanf("%lld", &a[i]);
    sort(a + 1, a + n + 1);
    int l = 0, r = n;
    while(l < r) {
        int mid = (l + r) >> 1;
        if((n - mid) & 1) mid--;
        if(judge(mid)) r = mid;
        else l = mid + 2;
    }
    judge(l);
    printf("%lld\n", ans);
    
    return 0;
}

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

lint A[55], P[55];

lint rec(lint n, lint x){
    if(n==0){
        if(x<=0) return 0LL;
        return 1LL;
    }

    if(x <= 1 + A[n-1]) return rec(n-1, x-1);
    return P[n-1] + 1 + rec(n-1, min(A[n-1], x-A[n-1]-2)); 
}

int main(){
    lint n, x; cin >> n >> x;

    A[0] = P[0] = 1;
    for(int i=1;i<=n;i++){
        A[i] = 2 * A[i-1] + 3;
        P[i] = 2 * P[i-1] + 1;
    }

    cout << rec(n, x) << endl;
    return 0;
}

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

int main(){
    int r, g, b;
    int num;
    
    cin >> r >> g >> b;
    num = r*100 + g*10 + b;
    
    if (num%4==0)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long sum=0;
		for(int i=0;i<n;i++){
			sum+=sc.nextLong();
		}
		System.out.println((int)Math.floor(sum/n));
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define yes "Yes\n"
#define no "No\n"
//int m,n;
//int i,j,k,l;
//int a,b,c,d,e,f,g;
//int sum,total;
//long long int ;
//float ;
//double ;
//char a[101],b[101],s[101],t[101],u[101];
char c;
int main(void){
    scanf("%c",&c);
    printf("%c\n",c+1);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
	__INIT() {
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(15);
	}
}__init;


int main(void) {
	string s, t;
	cin >> s >> t;
	cout << t << s << endl;
	return 0;
}


Measured memory_bytes: 3572
import java.util.*;
 
public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int[] v=new int[n];
        int[] c=new int[n];
        for(int i=0;i<n;i++){
            v[i]=sc.nextInt();
        }
        for(int i=0;i<n;i++){
            c[i]=sc.nextInt();
        }
        int output=0;
        for(int i=0;i<n;i++){
            output+=Math.max(0, v[i]-c[i]);
        }
        System.out.println(output);
    }
}

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

void solve(long long A, long long B, long long N) {
    long long x = N < B ? N : B - 1;
    long long ans = floor((A * (x % B)) / B);
    cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can
// remove this line by using your custom template)
int main() {
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long N;
    scanf("%lld", &N);
    solve(A, B, N);
    return 0;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1000000000 + 7;

bool debug = 0;

void solve() {
    string s;
    cin >> s;
    int cnt = 0;
    for (int i = 0; i < (int)s.size() - 1; i++) {
        if (s[i] != s[i + 1]) cnt++;
    }
    cout << cnt << endl;
}

int main() {
    if (debug) {
        while (true) {
            cout << "********" << endl;
            solve();
        }
    } else {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace  std ;
typedef long l ;
typedef long long ll ;
typedef vector<int>vi ;
typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
long long power(long long k , long long n , long long m=1e9+7)
{
    long long res = 1;
    while(n)
    {
        if(n%2!=0)
        {
            res = (res*k)%m ;
        }
        k = (k*k)%m ;
        n = n/2 ;
    }
    return(res) ;
}
ll nck(ll n , ll k ,ll m=1e9+7)
{
    ll i , j,b=1,c=1 ;
    if(n-k<k)
    {
        k = n-k ;
    }
    while(k)
    {
        b*=n ;
        c*=k ;
        ll g = __gcd(b,c) ;
        b/=g ;
        c/=g ;
        n--;
        k-- ;
    }
    return(b) ;
}
long long fact(long long n , long long m = 1e9+7)
{
    long long a = 1 ;
    if(n==0 || n==1)
    {
        return(1) ;
    }
    while(n>0)
    {
        a = (a%m * n%m)%m ;
        n-- ;
    }
    return(a) ;
}
void READ(vll &v, ll n)
{
    ll a ;
    for(ll i=0 ; i<n ; i=i+1)
    {
        cin>>a ;
        v.pb(a) ;
    }
}
void PRINT(vll &v, ll n)
{
    ll a ;
    for(ll i=0 ; i<n ; i=i+1)
    {
        cout<<v[i]<<" " ;
    }
    cout<<"\n" ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    std::cout.unsetf ( std::ios::floatfield );//this and next line for floating precision upto 6
    std::cout.precision(10);
    ll a,b,c,d,e,x,i,j,n,t,m,k,y,s;
    double p,q,r,w,u ;
    string str = "",str1 = "" ;
    char ch,chr ;
    ll a1,a2,b1,b2 ;
    cin>>n ;
    vll v;
    READ(v,n);
    bool haa = true ;
    for(i=n-1 ; i>0 ; i=i-1)
    {
        if(v[i]<v[i-1])
        {
            if(v[i-1]-v[i]==1)
            {
                v[i-1] = v[i] ;
            }
            else
            {
                haa = false ;
                break;
            }
        }
    }
    if(haa)
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n" ;
    }
}

Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
using namespace std;
     
int main() {
    int a,b;
    cin >> a>>b;
    int aa[3];
    aa[0] = a+b;
    aa[1] = a-b;
    aa[2] = a*b;
    sort(aa,aa+3);
    cout << aa[2] << endl;
}

Measured memory_bytes: 256
def resolve():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = {}
    for i in range(n):
        if a[i] in b:
            b[a[i]] += 1
        else:
            b[a[i]] = 1
    c = sorted(b.values())
    if len(c) <= k:
        print(0)
    else:
        print(sum(c[:(len(c)-k)]))
resolve()

Measured memory_bytes: 96848
#include<iostream>
#include<stdio.h>

using namespace std;

bool arr[10000];
long long listprime[10000];
int banyakprima = 0;

void sieve()
{
	for(int i = 3 ; i < 10000 ; i ++)
	{
		if(i%2 == 1)
		{
			arr[i] = true;
		}
		else
		arr[i] = false;
	}
	listprime[banyakprima] = 2;
	banyakprima++;
	arr[1] = false ; arr[0] = false ; arr[2] = true;
	for(int i = 3 ; i < 10000 ; i = i + 2)
	{
		if(arr[i])
		{
			listprime[banyakprima] = i;
			banyakprima++;
			for(long long j = i*i ; j < 10000 ; j = j + i )
			{
				arr[j] = false;
			}
		}
		
	}
}

int main()
{
	sieve();
	long long n , p ;
	while(cin>>n)
	{
		long long res = 1 ;
		long long tamp = n;
		long long hasil = 0;
		while(tamp != 1 && res != n)
		{
			if(arr[res] == true && arr[tamp] == true)
			{
				hasil++;
			}
			tamp--;
			res++;
		}
		cout<<hasil<<endl;
	}
}


Measured memory_bytes: 3108
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let n = v[0];
	let v:Vec<i32> = procon_read();
	let a = v[0];
	if n%500 <= a {
		println!("Yes");
	}else{
		println!("No");
	}
}

Measured memory_bytes: 4352
// C - Bugged
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; cin>>N;
	int sumS = 0;
	int minS = INT_MAX;
	for(int i=1; i<=N; ++i){
		int s; cin>>s;
		sumS += s;
		if(s%10){
			minS = min(minS, s);
		}
	}

	if(sumS%10==0){
		if(minS == INT_MAX) sumS = 0;
		else sumS -= minS;
	}
	cout<< sumS <<endl;
}

Measured memory_bytes: 256
#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
LL a,b,c,d,i,j,k,m,n,t;
string s[200040];
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>a>>b;
	if(a>b)cout<<"safe";
	else cout<<"unsafe";
}

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

void dfs(const vector<vector<int>> &G, int v, vector<bool> &seen) {
    seen[v] = true;
    for (auto next_v : G[v]) {
        if (seen[next_v]) continue;
        dfs(G, next_v, seen);
    }
}

int main(void)
{
    long long N, M;
    cin >> N >> M;
    vector<long long> a(M);
    vector<long long> b(M);
    for (long long i = 0; i < M; i++)
    {
        long long A, B;
        cin >> A >> B;
        a[i] = A - 1;
        b[i] = B - 1;
    }

    long long ans = 0;
    vector<vector<int>> G(N);
    vector<bool> seen(N);
    for (long long i = 0; i < M; i++)
    {
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }
    for (long long j = 0; j < M; j++)
    {
        for (long long i = 0; i < N; i++)
        {
            seen[i] = false;
        }
        G[a[j]].erase(remove(G[a[j]].begin(), G[a[j]].end(), b[j]), G[a[j]].end());
        G[b[j]].erase(remove(G[b[j]].begin(), G[b[j]].end(), a[j]), G[b[j]].end());
        dfs(G, 1, seen);
        G[a[j]].push_back(b[j]);
        G[b[j]].push_back(a[j]);
        for (long long i = 0; i < N; i++)
        {
            if (seen[i] == false)
            {
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;
}

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

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

using namespace std;

template<class G>
class Fenwick_tree{
	vector<G> a;
public:
	Fenwick_tree(){}
	Fenwick_tree(int n){ build(n); }
	Fenwick_tree(const vector<G>& a){ build(a); }
	void build(int n){
		a.assign(n,G{});
	}
	void build(const vector<G>& a){
		this->a=a;
		for(int i=1;i<a.size();i++) if(i+(i&-i)-1<a.size()) (this->a)[i+(i&-i)-1]+=(this->a)[i-1];
	}
	void add(int i,const G& val){
		for(i++;i<=a.size();i+=i&-i) a[i-1]+=val;
	}
	G sum(int l,int r)const{
		if(l==0){
			G res{};
			for(;r>0;r-=r&-r) res+=a[r-1];
			return res;
		}
		return sum(0,r)-sum(0,l);
	}
	int lower_bound(G val)const{
		if(val<=G{}) return 0;
		int x=0,k;
		for(k=1;k<=a.size();k<<=1);
		for(k>>=1;k>0;k>>=1) if(x+k<=a.size() && a[x+k-1]<val) val-=a[x+k-1], x+=k;
		return x;
	}
	int upper_bound(G val)const{
		if(val<G{}) return 0;
		int x=0,k;
		for(k=1;k<=a.size();k<<=1);
		for(k>>=1;k>0;k>>=1) if(x+k<=a.size() && a[x+k-1]<=val) val-=a[x+k-1], x+=k;
		return x;
	}
};

class mint{
	static const int MOD=998244353;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return mint(-x); }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator+(long long x,const mint& m){ return mint(x)+m; }
mint operator-(long long x,const mint& m){ return mint(x)-m; }
mint operator*(long long x,const mint& m){ return mint(x)*m; }
mint operator/(long long x,const mint& m){ return mint(x)/m; }

int main(){
	int n,k; scanf("%d%d",&n,&k);
	vector<int> l(k),r(k);
	rep(i,k) scanf("%d%d",&l[i],&r[i]);

	Fenwick_tree<mint> dp(n);
	dp.add(0,1);
	rep(i,n){
		rep(j,k){
			dp.add(i,dp.sum(max(i-r[j],0),max(i-l[j]+1,0)));
		}
	}
	cout<<dp.sum(n-1,n)<<'\n';

	return 0;
}


Measured memory_bytes: 4072
#include<bits/stdc++.h>
using namespace std;
int c[100005];
vector<int>v[100005];
int n;
int fennec=0,snuke=0;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		c[i]=0;
	for(int i=0;i<n-1;i++)
	{
		int a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	queue<int>q;
	q.push(1);
	q.push(n);
	c[1]=1;//black
	c[n]=2;//white
	
	while(!q.empty())
	{
		int x=q.front();
		q.pop();
		for(int i=0;i<v[x].size();i++)
		{
			int y=v[x][i];
			if(c[y]==0)
			{
				q.push(y);
				c[y]=c[x];
				if(c[y]==1)
					fennec++;
				else if(c[y]==2)
					snuke++;
			}
		}
	}
	if(fennec>snuke)
		cout<<"Fennec"<<endl;
	else
		cout<<"Snuke"<<endl;
	return 0;
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
#define tt long t;cin>>t;while(t--)
#define tez ios_base::sync_with_stdio(false); cin.tie(NULL);
#define lli long long int
#define plli pair<lli,lli>
#define vlli vector<lli>
#define vplli vector<plli>
#define pqlli priority_queue <lli>
#define pqplli priority_queue <plli>
#define mplli map<lli,lli>
#define all(v) v.begin(),v.end()
#define alll(s) s.begin(),s.end(),s.begin(), ::tolower
#define allu(s) s.begin(),s.end(),s.begin(), ::toupper
 
#define mod 1000000007
#define ff first
#define ss second
#define fori(i,a,b)    for(int i=a;i<b;i++)
#define ford(i,a,b)    for(int i=a;i>=b;i--)
#define br cout<<endl
#define sz(v) (long)v.size()
#define YS cout<<"YES"<<endl
#define ys cout<<"yes"<<endl
#define Ys cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define no cout<<"no"<<endl
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define bs binary_search
#define mp make_pair
#define llmn LLONG_MIN
#define llmx  LLONG_MAX
#define stp setprecision
#define fxd fixed
#define tu (char)toupper
#define tl (char)tolower
#define coutv(v) for(lli index=0;index<v.size();index++) {cout<<v[index]<<" ";} br;
 
using namespace std;
using namespace std::chrono; 
 
/*
lli count01(string s,char ch){
  lli mx=0,c=0;
  if(ch=='0'){
 
   fori(i,0,sz(s)){
     if(s[i]=='0'){
        c++;}
     else{
        c=0;}
        if(c>mx){mx=c;}
 
   }
 
  }
  else{
 
    fori(i,0,sz(s)){
     if(s[i]=='1'){
        c++;}
     else{
        c=0;}
        if(c>mx){mx=c;}
 
    }
 
  }
return mx;
 
}
*/
/*
vector<lli> prime(lli n){
  bool a[n+1];
  memset(a,true,sizeof(a));
  for(lli i=2;i*i<=n;i++){
    if(a[i]){
      for(lli j=i*i;j<=n;j+=i)
      {  a[j]=false;}
    }
  }
  vector<lli>v;
  for(lli i=2;i<=n;i++){
    if(a[i]){
      v.pb(i);
    }
  }
  return v;
}
*/

/*
lli power( lli a, lli x){
    lli ans=1;
    a=a%mod;
    while(x>0){
       if(x%2==1){
        ans=(ans*a)%mod;
       }
       a=(a*a)%mod;
       x/=2;
   }
   return ans;
}
*/

//int dir[][2]={{0,1},{0,-1},{-1,0},{1,0}};

void solve(){
lli a,b,c,d;
cin>>a>>b>>c>>d;
vlli v;
v.pb(a*c);
v.pb(a*d);
v.pb(b*c);
v.pb(b*d);
sort(all(v));
cout<<v[3]<<endl;
}


int main(){
tez
auto start = high_resolution_clock::now(); 

solve();



auto stop = high_resolution_clock::now(); 
auto duration = duration_cast<microseconds>(stop - start);
double Tsec= (double)duration.count()/(double)1000000;
//cout<<Tsec<<endl;
 
return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <vector>
#include <memory.h>
#include <iostream>
#include <map>
#include <algorithm>
  
// Shabdan Batyrkulov
  
using namespace std;
  
#define pb push_back
#define fr first
#define sc second
#define mk make_pair
#define ll long long
#define ld long double
#define vi vector <int>
#define pii pair <int, int>
#define OK puts("OK");                                                                           
                                                                                                
const int N = (int)1e5 + 7;                                                                 
const int inf = (int)1e9 + 7;
const int MAX = (int)1e2 + 7;


int main () {
	int r, g, b;
	scanf("%d %d %d", &r, &g, &b);
	int ans = 1;
	ans = r * 100 + g * 10 + b;
	if (ans % 4 == 0) {
		puts("YES");
	} else {
		puts("NO");
	}		
}    


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long ans[100005],h[100005];
int main(){
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>h[i];
	memset(ans,63,sizeof(ans));
	ans[0]=0;
	ans[1]=fabs(h[1]-h[0]);
	for(int i=2;i<n;i++)for(int j=1;j<=k&&i>=j;j++)if(ans[i]>ans[i-j]+fabs(h[i]-h[i-j]))ans[i]=ans[i-j]+fabs(h[i]-h[i-j]);
	cout<<ans[n-1];
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <vector>
using namespace std;
typedef long long int64;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 20, P = 1e9+7;
int n, m, all, d[N+5][N+5], f[2][1<<N|5], p = 1, q = 0, ans;
int main()
{
    n = read()-1, m = read(), all = (1<<n)-1;
    for(int i = read(); i; --i) 
    {
        int a = read(), b = read()-1, c = read();
        d[a][b] = c+1;
    }
    f[0][0] = 1;
    for(int i = 1, t, u; i <= m; ++i)
        for(int j = 0; j < n; ++j)
        {
            swap(p, q), t = 1<<j, u = all^((t<<1)-1);
            memset(f[q], 0, sizeof(int)*(all+1));
            for(int s = 0, r; s <= all; ++s)
                if(f[p][s])
                {
                    if(d[i][j] != 2&&(s&t) == 0) f[q][s] = (f[q][s]+f[p][s])%P;
                    if(d[i][j] != 1)
                    {
                        if(s&t) r = s;
                        else if((u&s) == 0) r = s|t;
                        else r = (s|t)^((u&s)&-(u&s));
                        f[q][r] = (f[q][r]+f[p][s])%P;
                    }
                }
        }
    for(int s = 0; s <= all; ++s) ans = (ans+f[q][s])%P;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 8320
N = int(input())
h = [_ for _ in map(int, input().split())]

ans = 0
p = 0
started = True # 前の項が0であるか

while any(h):

    cur = h[p] # 現在位置の値
    
    if cur > 0:
        h[p] -= 1
        if started:
            started = False
            ans += 1
    else:
        started = True
         
    p += 1
    
    if p >= N:
        p = 0 # 最初から
        started = True

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    ll t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

    ll l = t1 * (a1 - b1);
    ll d = l + t2 * (a2 - b2);

    if (d == 0){
        cout << "infinity" << endl;
        return 0;
    }
    if ((d > 0 && l > 0) || (d < 0 && l < 0)) {
        cout << 0 << endl;
        return 0;
    }

    d = abs(d);
    l = abs(l);

    ll ans = 1;
    if (l % d != 0) ans += 2 * (l/d);
    else ans += 2 * (l/d) - 1;

    cout << ans << endl;

    return 0;
}


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

const int mod = 1000000007;
ll modpow(ll a, ll n){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main(){
	int n, k;
	cin >> n >> k;

	int niCk = n;//in
	ll iniCk = 1;
	int kaiCk = k;//in
	int waiCk = 1;
	vector<ll> iCk(niCk);//out
	for(int i=kaiCk-1; i<niCk; i++){
		iCk.at(i) = iniCk;
		iniCk *= kaiCk;
		kaiCk++;
		if(iniCk > mod) iniCk %= mod;
		iniCk *= modpow(waiCk, mod-2);
		waiCk++;
		if(iniCk > mod) iniCk %= mod;
	}

	vector<int> a(n);
	rep(i, n) cin >> a.at(i);
	sort(a.begin(), a.end());
	ll masum = 0;
	ll misum = 0;
	rep(i, n){
		masum += iCk.at(i) * a.at(i);
		if(masum >= mod) masum %= mod;
		if(masum <= -1*mod) masum %= mod;
		if(masum < 0) masum += mod;
	}
	reverse(a.begin(), a.end());
	rep(i, n){
		misum += iCk.at(i) * a.at(i);
		if(misum >= mod) misum %= mod;
		if(misum <= -1*mod) misum %= mod;
		if(misum < 0) misum += mod;
	}
	ll ans = masum - misum;
	if(ans < 0) ans += mod;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>

using namespace std;

int main(){
	int a[3][3];
  	for(int i=0; i < 3; i++){
      for(int j = 0; j < 3; j++){
        cin >> a[i][j];
      }
    }
  	
  	int flag = 0;
  	
  	for(int i= 0; i < 2; i++){
    	int diff = a[0][i] - a[0][i+1];
      	for(int j = 0; j < 3; j++){
          if(a[j][i] - a[j][i+1] != diff) flag = 1;
        }
     }
  
     for(int i= 0; i < 2; i++){
    	int diff = a[i][0] - a[i+1][0];
      	for(int j = 0; j < 3; j++){
          if(a[i][j] - a[i+1][j] != diff) flag = 1;
        }
     }
	if(flag != 0) cout << "No" << endl;
  	else cout << "Yes" << endl;
  
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc111_c() {
	ll N;
	ll ans = 0;

	cin >> N;

	vector<ll> v1(100001, 0), v2(100001, 0);
	ll tmp;
	rep(i, N) {
		cin >> tmp;
		if (i % 2 == 0) {
			v1[tmp]++;
		}
		else {
			v2[tmp]++;
		}
	}

	priority_queue<P> max1, max2;
	max1.push(make_pair(0, 0));
	max2.push(make_pair(0, 0));
	rep(i, 100001) {
		if (v1[i] != 0) {
			max1.push(make_pair(v1[i], i));
		}
		if (v2[i] != 0) {
			max2.push(make_pair(v2[i], i));
		}
	}

	ll ans1, ans2;
	ll m11, m12, m21, m22;
	if (max1.top().second != max2.top().second) {
		ans = (N / 2 - max1.top().first) + (N / 2 - max2.top().first);
	}
	else {
		m11 = max1.top().first;
		max1.pop();
		m12 = max1.top().first;
		m21 = max2.top().first;
		max2.pop();
		m22 = max2.top().first;
		ans1 = (N / 2 - m11) + (N / 2 - m22);
		ans2 = (N / 2 - m12) + (N / 2 - m21);

		ans = min(ans1, ans2);
	}

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

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

	solve_abc111_c();

	return 0;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int a, b, c[5600], d[5600], ans;
signed main() {
	cin >> a >> b;
	for1(i, a)cin >> c[i];
	for1(j, b)cin >> d[j];
	for1(p, b) {
		int pi = p;
		for1(i, a)if (d[pi] == c[i])pi++;
		ans = max(ans, pi - p);
	}
	cout << ans << endl;
}


Measured memory_bytes: 3152
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<unordered_map>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N 110
unordered_map<ll,ll> d[N];

#define X 100010
ll inv[X],invfact[X],fact[X];
void Pre(){
    inv[1]=invfact[0]=fact[0]=1;
    for(ll i=1;i<X;i++){
	if(i>1)inv[i]=(mod-(mod/i*inv[mod%i]%mod))%mod;
	invfact[i]=invfact[i-1]*inv[i]%mod;
	fact[i]=fact[i-1]*i%mod;
    }
}
ll C(ll n,ll k){
    if(n<k)return 0;
    return fact[n]*invfact[n-k]%mod*invfact[k]%mod;
}

int main(){
    Pre();
    ll n,m;cin>>n>>m;
    vector<ll> v;
    for(int i=1;i*i<=m;i++){
	if(m%i!=0)continue;
	v.push_back(i);
	if(i*i!=m)v.push_back(m/i);
    }
    unordered_map<ll,vector<ll> > e;
    for(auto i:v){
	for(auto j:v){
	    if(i%j==0&&i!=j){e[i].push_back(j);}
	}
    }
    d[0][m]=1;
    ll ans=0;
    lol(i,N-1){
	for(auto j:v){
	    for(auto k:e[j]){
		d[i+1][k]=(d[i+1][k]+d[i][j])%mod;
	    }
	}
	ans=(ans+d[i+1][1]*C(n,i+1))%mod;
    }
    cout<<max((ll)1,ans)<<endl;
    return 0;
}


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

#define ll             long long
#define LL             long long
#define gcd(a,b)       __gcd(a, b)
#define lcm(a,b)       a * (b / gcd(a, b))
#define pii            pair<int, int>
#define pll            pair<ll, ll>
#define pil            pair<int, ll>
#define pli            pair<ll, int>
#define vi             vector<int>
#define vl             vector<ll>
#define vii            vector<pii>
#define vll            vector<pll>
#define vil            vector<pil>
#define vli            vector<pli>
#define pb             push_back
#define ppb            pop_back
#define mp             make_pair
#define ff             first
#define ss             second
#define all(v)         v.begin(), v.end()
#define fill(a, b)     memset(a, b, sizeof a)
#define smax(a, b)     a = max(a, b)
#define smin(a, b)     a = min(a, b)
#define sqr(x)         x * x
#define cube(x)        x * x * x
#define endl           '\n'

int in() {
	int n;
	scanf("%d", &n);
	return n;
}

ll Lin() {
	ll n;
	scanf("%lld", &n);
	return n;
}

double Din() {
	double n;
	scanf("%lf", &n);
	return n;
}

const ll inf = (ll)1e17;
const ll mod = (ll)1e9 + 7;
const int N = 1e5 + 5;

ll a[N][4];
ll dp[N][4];

ll call(int pos, int k) {
	if (pos == 0) return 0;
	if (dp[pos][k] != -1) return dp[pos][k];
	ll ans = 0;
	for (int i = 1; i <= 3; i++) {
		if (i == k) continue;
		ans = max(ans, call(pos - 1, i) + a[pos][k]);
	}
	return dp[pos][k] = ans;
}

int solve() {
	int n = in();
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= 3; j++) {
			a[i][j] = Lin();
		}
	}
	fill(dp, -1);
	printf("%lld\n", call(n + 1, 0));
	return 0;
}

int main() {
	int test = 1, tc = 0;
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
	return 0;
}


Measured memory_bytes: 14336