akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int maxn = 2e5+11;

ll list[maxn];

int n;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>list[i];
    }
    sort(list+1,list+1+n,greater<int>());
    
    for(int i=1;i<=n;i++){
        if(i + 1 > list[i+1]){
            int j=0;
            int a,b;
            while(list[i+1+j] ==i ) j++;
            if((j&1) || (list[i] - i)&1){
                printf("First\n");
            }
            else{
                printf("Second\n");
            }
            return 0;

        }
    }


    return 0;
}

Measured memory_bytes: 3868
# coding: utf-8

n,a,b=map(int,input().split())
cnt=0

x=n//(a+b)*a       # a+b個までで入っている青の数（入力例1の場合，3個）
y=n%(a+b)       # nを(a+b)で割った余り（入力例1の場合，1）

if y>a:
    x = x + a
else:
    x = x + y

print(x)

Measured memory_bytes: 2940
<?php
fscanf(STDIN, '%d', $cnt);
$nums = array_map('intval', explode(' ', trim(fgets(STDIN))));
$flag = true;
for ($i=0; $i < $cnt; $i++) { 
    if ($nums[$i] % 2 !== 0) {
        continue;
    }
    if ($nums[$i] % 3 !== 0 && $nums[$i] % 5 !== 0) {
        $flag = false;
    }
}
echo $flag ? 'APPROVED' : 'DENIED';
echo "\n";

Measured memory_bytes: 5112
#include<iostream>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
using ll = long long;
#define what(x) cerr << #x << " is " << x << endl;

int main(){
    int a, b, c, d, e, f;
    cin >> a >> b >> c >> d >> e >> f;
    double ret_dens = 0.0;
    int ret_tot = 100*a;
    int ret_sug = 0;
    const double max_dens = 100.0 * e / (100 + e) + 1.0e-13;
    for(int i = 0; i*a*100 <= f; ++i) {
        int leftj = f - i*a*100;
        for(int j = 0; j*b*100 <= leftj; ++j) {
            int leftk = leftj - j*b*100;
            for(int k = 0; k*c <= leftk; ++k) {
                int leftl = leftk - k*c;
                for(int l = 0; l*d <= leftl; ++l) {
                    int tot = (100*a*i + 100*b*j + c*k + d*l);
                    int sug = (k*c + l*d);
                    double dens = 100.0 * sug / tot;
                    if (tot <= f && dens < max_dens && dens > ret_dens) {
                        ret_dens = dens;
                        ret_tot = tot;
                        ret_sug = sug;
                    }
                }
            }
        }
    }
    cout << ret_tot << " " << ret_sug << endl;
    return 0;
}

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

//2整数a,bの最大公約数を返す
//O(log max(a,b))
long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}


//2整数a,bの最小公倍数
//ab=gcd(a,b)lcm(a,b)を利用
long long lcm(long long a,long long b){
    long long g=gcd(a,b);
    return a/g*b;
}

int main()
{
    int N;
    cin>>N;
    long long ans=1LL;//long long 型の1
    for(int i=0; i<N; i++){
        long long T;
        cin>>T;
        ans=lcm(ans,T);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
#define max 1000000
bool p[max];
int main(){
    p[1] = true;
    for(int i = 2; i * i < max; i++){
		if(p[i]) continue;
		for(int j = i * i; j < max; j+=i) p[j] = true;
	}
    int n;
    while(~scanf("%d",&n)){
		int ans = 0;
		for(int i = 1; i <= n; i++){
			if(!p[i])ans++;
		}
		printf("%d\n",ans);
	}
    return 0;
}

Measured memory_bytes: 2000
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;

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

int main(){
    int n, m, q; cin>>n>>m>>q;
    set<int> st;
    for(int i=0; i<n; i++){
        st.emplace(i);
    }

    auto itr = st.begin();
    for(int i=0; i<m; i++){
        int a; cin>>a;
        if(a % 2 == 0){
            for(int j=0; j<a; j++){
                itr++;
                if(itr == st.end()){
                    itr = st.begin();
                }
            }
        }
        else{
            for(int j=0; j<a; j++){
                if(itr == st.begin()){
                    itr = st.end();
                }
                itr--;
            }
        }

        itr = st.erase(itr);
        if(itr == st.end()){
            itr = st.begin();
        }
    }

    vector<bool> exist(n, false);
    for(auto i : st){
        exist[i] = true;
    }

    while(q--){
        int x; cin>>x;
        cout << exist[x] << endl;
    }
}


Measured memory_bytes: 11988
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
using vs = vector<string>; using tll = tuple<ll, ll, ll>; using vtll = vector<tll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define co(i) cout << i << endl;
#define co2(i,j) cout << i << " " << j << endl;
#define co3(i) cout << i << " ";
#define po(i) cout << i.first << " " << i.second << endl;
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop, bitSearch, bitList, nod, digitDP, treeDP//
//gcdlcm, isPrime, eratos, primeFactorize, Npow, combination, divisor, modinv, doubling//
//dfs, bfs, dijkstra, WarshallFloyd, BellmanFord, UnionFind, Kruskal, RMQ, LCA//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007, INF = 1LL << 60, ans = 0, z = 0, o = 1;
vl flag, D; vll path; vll A;
//***********//
int main() {
	
	cin >> X;
	if (X >= 1800) cout << 1;
	else if (X >= 1600) cout << 2;
	else if (X >= 1400) cout << 3;
	else if (X >= 1200) cout << 4;
	else if (X >= 1000) cout << 5;
	else if (X >= 800) cout << 6;
	else if (X >= 600) cout << 7;
	else if (X >= 400) cout << 8;
}

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

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

int main() {
  int N,A,B;
  cin >> N >> A >> B;
  int total=0;
  for (int i =1;i<=N;++i){
    int sum=findsum(i);
    if (sum>=A && sum<=B){
      total+=i;
    }
  }
  cout << total << endl;
}


Measured memory_bytes: 256
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
toLowerCase()はアルファベット以外に対して行ってもエラーにはならない
 */
//入力終了→Ctrl+D
import java.time.Year;
import java.util.*;
import java.awt.*;
import java.awt.Graphics.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        int ans=0;
        for (int i = 0; i < n; i++) {
            if(isPrime(sc.nextInt()))ans++;
        }
        out.println(ans);
    }
    static boolean isPrime(int p){
        if(p==1)return false;
        int s=(int)sqrt(p+1);
        for (int i = 2; i <= s; i++) {
            if(p%i==0)return false;
        }
        return true;
    }
}


Measured memory_bytes: 41284
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;

int main(void){
  int a, b;
  int sum = 1, c = 0;
  cin >> a >> b;
  while(sum < b){
    sum = sum + a - 1;
    c++;
  }
  cout << c << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
long long a[100000],n,cnt,Bar=2;
int main(){
	cin>>n;for(int i=0;i<n;i++)cin>>a[i];
	cnt+=a[0]-1;
	for(int i=1;i<n;i++){
		if(a[i]>Bar){
			if(a[i]%Bar==0){cnt++;a[i]-=(Bar+1);}
			if(a[i]%Bar!=0){cnt+=a[i]/Bar;a[i]%=Bar;}
		}
		if(a[i]==Bar)Bar++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=100000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	string s;

	cin>>s;

	ll total=1;
	rep(i,s.size()-1){
		if(s[i]!=s[i+1]){
			total++;
		}
	}
	cout<<total-1<<endl;

	return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String t = scanner.nextLine();

        System.out.println(lcs(s, t));
    }

    private static String lcs(String s, String t) {
        final int len1 = s.length();
        final int len2 = t.length();

        int[][] dp = new int[len1 + 1][len2 + 1];
        for (int r = 1; r <= len1; r++) {
            for (int c = 1; c <= len2; c++) {
                if (s.charAt(r - 1) == t.charAt(c - 1)) {
                    dp[r][c] = 1 + dp[r - 1][c - 1];
                } else {
                    dp[r][c] = Math.max(dp[r - 1][c], dp[r][c - 1]);
                }
            }
        }

        int index = dp[len1][len2];
        char[] lcs = new char[index];
        int i = len1;
        int j = len2;
        while(i > 0 && j > 0) {
            if(s.charAt(i - 1) == t.charAt(j - 1)) {
                lcs[--index] = s.charAt(i - 1);
                i--;
                j--;
            } else if(dp[i-1][j] > dp[i][j - 1]) {
                i--;
            } else {
                j--;
            }
        }
        return new String(lcs);
    }
}


Measured memory_bytes: 87016
h, w = map(int, input().split())
a = [input() for _ in range(h)]
ans_w = []
ans_h = []
for i in range(h):
  for j in range(w):
    if a[i][j] == "#":
      ans_h.append(i)
      break
for j in range(w):
  for i in range(h):
    if a[i][j] == "#":
      ans_w.append(j)
      break
for i in ans_h:
  print(*[a[i][j] for j in ans_w], sep="")

Measured memory_bytes: 4340
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

int N, ans = 0;

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

  vector< vector<int> > cnt(26);
  for(int i = 0; i < S.length(); i++){
    cnt[S[i] - 'a'].push_back(i);
  }

  for(int i = 0; i < 26; i++){
    int cnt_size = cnt[i].size();
    int left;

    for(int j = 0; j < cnt_size; j++){
      left = cnt[i][j];
      for(int k = cnt_size - 1, right = cnt[i][k]; k > j ; k--, right = cnt[i][k]){
        if(N - right <= ans || right - left <= ans) continue; //ansが更新されないところは枝刈り

        int t = 0;
        for(int m = 0; left + m < right; m++){
          if(S[left+m] == S[right+m]) t++;
          else break;
        }
        if(t > ans) ans = t;
      }

    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main() {
	char s[5];
	scanf("%s",s);
	for(int i=0;i<strlen(s);i++){
		if(s[i]=='A' && s[i+1]=='C'){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static llong MOD = 1000000007;
const static int IINF = INT_MAX;
const static llong LINF = LLONG_MAX;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

template<typename T> T my_gcd(T a, T b) {
    return (a ? my_gcd(b % a, a) : b);
}
template<typename T> T my_lcm(T a, T b) {
    return a * b / my_gcd(a, b);    
}
llong powmod(llong a, llong n) {
    llong res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }

    return res;
}
llong facmod(llong n) {
    if (n == 0) return 1;
    llong res = n;
    for (int i = n - 1; i > 0; --i) {
        res = (res * i) % MOD;
    }

    return res;
}
llong combmod(llong n, llong k) {
    llong res = 1;
    for (int i = 0; i < k; ++i) {
        res = (res * (n - i)) % MOD;
    } 
    res = (res * powmod(facmod(k), MOD - 2)) % MOD;

    return res;
}

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

    llong n, a, b;
    cin >> n >> a >> b;
    if (n == 2) {
        cout << 0 << endl;
        return 0;
    }

    llong ans = powmod(2, n) - 1;
    ans = (ans - combmod(n, a)) % MOD;
    ans = (ans - combmod(n, b)) % MOD;
    if (ans <  0) ans += MOD;

    cout << ans % MOD << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

template<int MOD>
struct ModInt {
  ll x;
  ModInt():x(0){}
  ModInt(ll x):x((x%MOD+MOD)%MOD){}
  int getMod() { return MOD; }
  ModInt operator-() const { return ModInt(0) - *this;}
  ModInt& operator+=(const ModInt& a){ if((x+=a.x)>=MOD) x-=MOD; return *this;}
  ModInt& operator-=(const ModInt& a){ if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
  ModInt& operator*=(const ModInt& a){ (x*=a.x)%=MOD; return *this;}
  ModInt operator+(const ModInt& a)const{ return ModInt(*this) += a;}
  ModInt operator-(const ModInt& a)const{ return ModInt(*this) -= a;}
  ModInt operator*(const ModInt& a)const{ return ModInt(*this) *= a;}
  bool operator<(const ModInt& a)const{ return x < a.x;}
  bool operator==(const ModInt& a)const{ return x == a.x;}
  ModInt pow(ll t) const {
    if (!t) return 1;
    ModInt a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  friend istream & operator >> (istream & in, ModInt & v) {
    ll x;
    in >> x;
    v.x = x;
    return in;
  }
  friend ostream & operator << (ostream & out, ModInt<MOD> const & v) {
    out << v.x;
    return out;
  }
};
const int MOD = 1000000007;
using mint = ModInt<MOD>;


int main() {
  int n, k; cin >> n >> k;
  vector<ll> P, M;
  loop(i,0,n) {
    ll a; cin >> a;
    if (a < 0) M.push_back(a);
    else P.push_back(a);
  }

  mint ans = 1;
  if (n == k) {
    for (auto a: M) ans *= a;
    for (auto a: P) ans *= a;
    cout << ans << endl;
    return 0;
  }

  if (P.size() == 0 and k%2==1) {
    sort(M.rbegin(), M.rend());
    loop(i,0,k) ans *= M[i];
    cout << ans << endl;
    return 0;
  }

  sort(P.rbegin(), P.rend());
  sort(M.begin(), M.end());
  vector<ll> A;
  if (k%2==1) {
    if (P.size()) for (int i=1; i<P.size()-1; i += 2) A.push_back(P[i] * P[i+1]);
    if (M.size()) for (int i=0; i<M.size()-1; i += 2) A.push_back(M[i] * M[i+1]);
    sort(A.rbegin(), A.rend());
    loop(i,0,k/2) ans *= A[i];
    ans *= P[0];
    cout << ans << endl;
    return 0;
  }

  if (P.size()) for (int i=0; i<P.size()-1; i += 2) A.push_back(P[i] * P[i+1]);
  if (M.size()) for (int i=0; i<M.size()-1; i += 2) A.push_back(M[i] * M[i+1]);
  sort(A.rbegin(), A.rend());
  loop(i,0,k/2) ans *= A[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6572
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back







int main()
{


	ll n, k;
	cin >> n >> k;

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

	ll dp[n];

	dp[0] = 0;


	for (int i = 1; i < n; i++)
	{
		dp[i] = INT_MAX;
		for (int j = k; j > 0; j--)
		{
			if (i - j >= 0)
			{
				dp[i] = min(dp[i], dp[i - j] + abs(arr[i] - arr[i - j]));
			}
		}

	}

	cout << dp[n - 1] << endl;
}





Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <set>

using namespace std;

#define ALL(co) co.begin(), co.end()

typedef long long LL;
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> Array;
typedef vector<int> LArray;

const int INF = 1 << 29;
const LL LINF = 1LL << 60;

int itiv;
inline int getInt() { return (cin >> itiv, itiv); }
void readAll(Array& vec, int n) { for (int i = 0; i < n; i++) cin >> vec[i]; }
inline bool between(int first, int last, int n) { return first <= n && n <= last; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }

int m, n;
int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 };
int dr[] = { 0, -1, 0, 1 }, dc[] = { -1, 0, 1, 0 };


LL dp[101][21];

int main(void)
{
	while(cin >> n && n)
	{
		memset(dp, 0, sizeof(dp));
		dp[0][getInt()] = 1;
		for (int i = 1; i < n - 1; i++)
		{
			int num = getInt();
			for (int j = 0; j < 21; j++)
			{
				if(between(0, 20, j + num))
					dp[i][j + num] += dp[i - 1][j];
				
				if(between(0, 20, j - num))
					dp[i][j - num] += dp[i - 1][j];
			}
		}
		cout << dp[n - 2][getInt()] << endl;
	}
	return 0;
}

Measured memory_bytes: 1180
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

N, K = map(int, raw_input().split())
h = map(int, raw_input().split())

DP = [0] + [INF] * N

for i in range(1, N):
    for j in range(min(i, K)):
        DP[i] = min(DP[i], DP[i - j - 1] + abs(h[i] - h[i - j - 1]))

print DP[N - 1]

Measured memory_bytes: 42348
S = input()
steppable = True

for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == 'L':
            steppable = False
            break
    else:
        if S[i] == 'R':
            steppable = False
            break

if steppable:
    print('Yes')
else:
    print('No')

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

int main() {
  int a;
  string s;
  cin >> a >> s;
  if (a >= 3200) cout << s << endl;
  else cout << "red" << endl;
}

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

int main(){
  ll N;
  cin >> N;
  vector<ll> A(N+1),B(N);
  for(int i=0;i<N+1;i++)cin >> A[i];
  for(int i=0;i<N;i++)cin >> B[i];
  ll cnt=0;
  for(int i=0;i<N;i++){
    if(B[i]>=A[i]+A[i+1]){cnt+=A[i]+A[i+1]; A[i+1]=0;}
    else if(B[i]>=A[i]){cnt+=B[i]; A[i+1]-=B[i]-A[i];}
    else{cnt+=B[i];}
  }
  cout << cnt << endl;
}

Measured memory_bytes: 1792
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return list(map(int, input().split()))
def II(): return int(input())
def S(): return input()


def main():
    w,h,n = LI()
    a = [[1]*w for _ in range(h)]
    for _ in range(n):
        x,y,t = LI()
        if t == 1:
            for _x in range(x):
                for _y in range(h):
                    a[_y][_x] = 0
        elif t == 2:
            for _x in range(x, w):
                for _y in range(h):
                    a[_y][_x] = 0
        elif t == 3:
            for _x in range(w):
                for _y in range(y):
                    a[_y][_x] = 0
        else:
            for _x in range(w):
                for _y in range(y,h):
                    a[_y][_x] = 0
    return sum(sum(_) for _ in a)





print(main())


Measured memory_bytes: 5588
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    int N,Q;
    cin >> N >> Q;
    string s;
    cin >> s;

    vector<int> A(N,0);
    vector<int> C(N,0);
    int flag=0;
    for(int i=0; i<N; i++){
        if(s[i]=='A'){
            flag=1;
            continue;
        }
        if(flag==1 && s[i]=='C'){
            A[i]++;
            C[i]++;
        }
        flag=0;
    }

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

    for(int i=0; i<Q; i++){
        int l,r;
        cin >> l >> r;
        l--;r--;
        cout << C[r]-A[l] << endl;
    }
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define INF 1000000007
#define MP make_pair
#define FI first
#define SE second
#define PB push_back
#define VI vector<int>
const double EPS = 1e-9, PI = acos(-1.0);
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int NUM = 100010;
int n, m, goal;
bool g[10][10];
double ans, num[10];
double dp[2][1 << 10][10];
void solve(double now[1 << 10][10], double nxt[1 << 10][10], int len)
{
    for(int i = 1; i <= goal; ++i)
		for(int j = 0; j < n; ++j)
			nxt[i][j] = 0.0;
    for(int i = 1; i < goal; ++i)
        for(int j = 0; j < n; ++j) if(i & (1 << j))
                for(int k = 0; k < n; ++k)
                    if(g[j][k])
                        nxt[i | (1 << k)][k] += num[j] * now[i][j];
	for(int i = 0; i < n; ++i) ans += nxt[goal][i] * len;
}
int main()
{
#ifdef ACM_TEST
    freopen("in.txt", "r", stdin);
#endif
    scanf("%d%d", &n, &m);
    for(int i = 0, u, v; i < m; ++i)
    {
        scanf("%d%d", &u, &v);
        --u, --v;
        g[u][v] = g[v][u] = true;
        num[u] += 1.0;
        num[v] += 1.0;
    }
    for(int i = 0; i < n; ++i) if(num[i]) num[i] = 1.0 / num[i];
    goal = (1 << n) - 1;
    dp[0][1][0] = 1.0;
    for(int i = 1, j = 0; i < 10000; ++i, j = !j) solve(dp[j], dp[!j], i);
    printf("%.6f", ans);
    return 0;
}

Measured memory_bytes: 1384
import sys
N = int(input())

if N % 2 == 1:
    print(0)
    sys.exit()


count = 0
start = 10
start_lis = []
while start <= N:
    start_lis.append(start)
    start = start // 2
    if int(str(start)[-1]) == 5:
        start *= 10
        
tmp10 = 10
while True:
    count += N // tmp10
    tmp10 *= 10
    if tmp10 > N:
        break

for i in range(1, len(start_lis)):
    tmp = start_lis[i]
    while True:
        count += (N + tmp) // (tmp * 2)
        tmp *= 10
        if tmp > N:
            break

print(count)
#print(*start_lis)




Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

typedef struct RMQandRAQ {
  i64 *add;
  i64 *max;
  i32 bit;
  i32 size;
} RMQandRAQ;

RMQandRAQ* new_RMQandRAQ (const i32 n) {
  i32 k = 0;
  while ((1 << k) < n) ++k;
  RMQandRAQ *s = (RMQandRAQ *) calloc (1, sizeof (RMQandRAQ));
  s->add = (i64 *) calloc (2 << k, sizeof (i64));
  s->max = (i64 *) calloc (2 << k, sizeof (i64));
  s->bit = k;
  s->size = 1 << k;
  return s;
}

static inline i64 max (i64 a, i64 b) {
  return a > b ? a : b;
}

static inline i64 eval (RMQandRAQ *s, i32 k) {
  return s->add[k] + s->max[k];
}

void propagate (RMQandRAQ *s, i32 x) {
  x += s->size;
  for (i32 bit = s->bit; bit > 0; bit--) {
    i32 k = x >> bit;
    s->add[2 * k] += s->add[k];
    s->add[2 * k + 1] += s->add[k];
    s->add[k] = 0;
    s->max[k] = max (eval (s, 2 * k), eval (s, 2 * k + 1));
  }
}

void save (RMQandRAQ *s, i32 x) {
  for (i32 k = (x + s->size) >> 1; k >= 1; k >>= 1) {
    s->max[k] = max (eval (s, 2 * k), eval (s, 2 * k + 1));
  }
}

void add (RMQandRAQ *s, i32 l, i32 r, i64 v) {
  propagate (s, l);
  propagate (s, r - 1);
  for (i32 x = l + s->size, y = r + s->size; x < y; x >>= 1, y >>= 1) {
    if (x & 1) s->add[x++] += v;
    if (y & 1) s->add[--y] += v;
  }
  save (s, l);
  save (s, r - 1);
}

i64 find (RMQandRAQ *s, i32 l, i32 r) {
  propagate (s, l);
  propagate (s, r - 1);
  i64 ans = 0;
  for (l += s->size, r += s->size; l < r; l >>= 1, r >>= 1) {
    if (l & 1) ans = max (ans, eval (s, l++));
    if (r & 1) ans = max (ans, eval (s, --r));
  }
  return ans;
}

typedef struct range {
  i32 l, r, v;
} range;

int cmp (const void *a, const void *b) {
  i32 d = ((range *)a)->r - ((range *)b)->r;
  return d == 0 ? 0 : d < 0 ? -1 : 1;
}

void run (void) {
  i32 n, m;
  scanf ("%" SCNi32 "%" SCNi32, &n, &m);
  range *p = (range *) calloc (m, sizeof (range));
  for (i32 i = 0; i < m; ++i) {
    i32 l, r, v;
    scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &l, &r, &v);
    p[i] = (range) {l, r, v};
  }
  qsort (p, m, sizeof (range), cmp);
  RMQandRAQ *s = new_RMQandRAQ (n + 1);
  for (i32 i = 1, j = 0; i <= n; ++i) {
    i64 v = find (s, 0, i);
    add (s, i, i + 1, v);
    for (; j < m && p[j].r <= i; ++j) {
      add (s, p[j].l, p[j].r + 1, p[j].v);
    }
  }
  printf ("%" PRIi64 "\n", find (s, 0, n + 1));
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 9428
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=100005;
const int inf=1000000000;

int n,val[N],l[N],r[N],dep[N],last[N],cnt;
bool vis[N],flag;
struct edge{int to,next;}e[N*2];

int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

void addedge(int u,int v)
{
	e[++cnt].to=v;e[cnt].next=last[u];last[u]=cnt;
	e[++cnt].to=u;e[cnt].next=last[v];last[v]=cnt;
}

void dfs(int x,int fa)
{
	dep[x]=dep[fa]+1;
	for (int i=last[x];i;i=e[i].next)
		if (e[i].to!=fa) dfs(e[i].to,x);
}

void dp(int x,int fa)
{
	if (vis[x]) l[x]=r[x]=val[x];
	else l[x]=-inf,r[x]=inf;
	for (int i=last[x];i;i=e[i].next)
	{
		if (e[i].to==fa) continue;
		dp(e[i].to,x);
		l[x]=max(l[x],l[e[i].to]-1);
		r[x]=min(r[x],r[e[i].to]+1);
	}
	if (l[x]>r[x]) flag=1;
}

void pri(int x,int fa)
{
	if (!vis[x])
	{
		if (val[fa]+1>=l[x]&&val[fa]+1<=r[x]) val[x]=val[fa]+1;
		else val[x]=val[fa]-1;
	}
	for (int i=last[x];i;i=e[i].next)
		if (e[i].to!=fa) pri(e[i].to,x);
}

int main()
{
	n=read();
	for (int i=1;i<n;i++)
	{
		int x=read(),y=read();
		addedge(x,y);
	}
	dfs(1,0);
	int m=read(),tag;
	for (int i=1;i<=m;i++)
	{
		int x=read(),y=read();
		vis[x]=1;val[x]=y;
		if (i==1) tag=(y&1)^(dep[x]&1);
		else if (((y&1)^(dep[x]&1))!=tag) {puts("No");return 0;}
	}
	dp(1,0);
	if (flag) {puts("No");return 0;}
	if (!vis[1]) vis[1]=1,val[1]=l[1];
	pri(1,0);
	puts("Yes");
	for (int i=1;i<=n;i++) printf("%d\n",val[i]);
	return 0;
}

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

// 繰り返し2乗法
int64_t modpow(int64_t a, int64_t n, int64_t mod){
  if(n == 1){
    return a % mod;
  }
  
  if(n%2 == 1){
    return (a * modpow(a, n-1, mod)) % mod;
  }
  
  int64_t t = modpow(a, n/2, mod);
  
  return (t * t) % mod;
  
}

// numberの約数を探す
std::vector<int> divisor(int number){
  std::vector<int> vec;
  for(int cnt = 1; cnt*cnt <= number; cnt++){
    if(number % cnt == 0){
      vec.push_back(cnt);
      if(cnt*cnt != number){
        vec.push_back(number/cnt);
      }
    }
  }
  return vec;
}
  


int main(){
  int N = 0;
  int K = 0;
  std::cin >> N >> K;
  
  const int64_t mod = 1000000007;
  
  std::vector<int64_t> vec_sub(K+1);
  
  int64_t answer = 0;
  for(int i = K; 0 < i; i--){
    int64_t cnt = ((modpow(K/i, N, mod)-vec_sub.at(i))%mod+mod)%mod; 
    answer = (answer+i*cnt+mod)%mod;
    
    std::vector<int> vec= divisor(i);
    for(int num : vec){
      vec_sub.at(num) = (vec_sub.at(num)+cnt+mod)%mod;
    }
    
  }
  
  std::cout << answer << std::endl;
  
  
  return 0;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define vecst   vector<string>
#define vecb    vector<bool>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << var << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "OK" : "NG"));}
//----------------------------------------------------------------

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

  bool ok=false;
  REP(i,a,b+1){
    if(i%k==0) ok=true;
  }
  prtok(ok);
}


Measured memory_bytes: 3596
import sys
import numpy as np
import math
from functools import reduce
sys.setrecursionlimit(10**6)

n=int(input())
a=list(map(int,input().split()))

b=1
for i in range(n):
    b*=a[i]

#def lcm_base(x,y):
#    return (x*y)//math.gcd(x,y)
#def lcm_list(numbers):
#    return reduce(lcm_base, numbers, 1)
#c=lcm_list(a)

#print(b)
#print(c)

ans=0
for j in range(n):
    ans+=(b-1)%a[j]
#    ans+=(c-1)%a[j]

#ans=0
##for i in range(b):
#for i in range(c):
#    f=0
#    for j in range(n):
#        f+=(i+1)%a[j]
#    ans=max(ans,f)

print(ans)



Measured memory_bytes: 12480
#include<bits/stdc++.h>
using namespace std;
int cnt,n,num;
queue<long long>q;
int main(){
	scanf("%d",&n);
	q.push(1);
	q.push(2);
	q.push(3);
	q.push(4);
	q.push(5);
	q.push(6);
	q.push(7);
	q.push(8);
	q.push(9);
	while(!q.empty()){
		long long t=q.front();q.pop();
		cnt++;
		if(cnt==n){printf("%lld",t);return 0;}
		if(t%10!=0)q.push(t*10+t%10-1);
		q.push(t*10+t%10);
		if(t%10!=9)q.push(t*10+t%10+1);
	}
}

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

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            new Main().solve(sc);
        }
    }

    void solve(Scanner sc) {
        int n = sc.nextInt();
        Integer[] as = new Integer[n];
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt();
        }
        Arrays.sort(as);

        Integer[] bs = new Integer[n];
        for (int i = 0; i < n; i++) {
            bs[i] = sc.nextInt();
        }

        Integer[] cs = new Integer[n];
        for (int i = 0; i < n; i++) {
            cs[i] = sc.nextInt();
        }
        Arrays.sort(cs);

        long ans = 0;
        for (Integer b : bs) {
            // lower bound
            long ai = Arrays.binarySearch(as, b, (x, y) -> (x.compareTo(y) >= 0) ? 1 : -1);
            ai = ~ai;

            // uppwer bound
            long ci = Arrays.binarySearch(cs, b, (x, y) -> (x.compareTo(y) > 0) ? 1 : -1);
            ci = ~ci;

            ans += ai * (cs.length - ci);
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 104928
#include <iostream>
#include <cstdlib>
#include <bitset>
#include <map>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
#include <sstream>
#include <math.h>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecchar vector<char>
#define vecstr vector<string>
#define vec2str vector<vector<string>>
#define vecbool vector<bool>
#define vec2bool vector<vector<bool>>
#define pairll pair<ll,ll>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

#define Pi 3.1415926535897932384626

int main() {
	ll n,ans=0;
	string s,t;
	bool flag = false;

	cin >> s >> t;

		ll maxCount=0;

		forll(i, 0, max((ll)(s.size()-t.size()),(ll)1))
		{
			ll count = 0;
			forll(j, 0, t.size())
			{
				if (s[i + j] == t[j])
				{
					count++;
				}
			}
			if (maxCount < count)
			{
				maxCount = count;
			}
		}

		ans = t.size()-maxCount;


	cout << ans;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int k,n,a[N],dis;
int main()
{
    cin>>k>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)dis=max(dis,(a[(i+1)%n]-a[i]+k)%k);
    cout<<k-dis;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 #include <math.h>
 #include <string>
 using namespace std;
 
 int main(){
    int N,K;
    int A;

    cin >> N >> K;

    if (N%2==0)
        A = N/2;
    else
        A = N/2 + 1;

    if (A>=K)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;


    return 0;
 }
 


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath> 
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
string s;
int main(){
	cin>>s;
	int n=s.size();
	for (int i=0;i<7;i++){
		string s1=s.substr(0,i),s2;
		if (i!=7) s2=s.substr(n-(7-i),7-i);
		if (s1+s2=="keyence"){
			puts("YES");  
			return 0;
		}
	}
	puts("NO");
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main()
{

    int a,b;
    cin >> a >> b;
    if (b-a>=0) cout << a << endl;
    else cout << a-1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int N, M;
  cin >> N >> M;
  int ans = N;
  for (int i = 0; i < M; i++) {
    int A;
    cin >> A;
    ans -= A;
  }
  if (ans < 0) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}


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

int main() {
    int N, M; cin >> N >> M;
    vector<int> A(N);
    int sum = 0, count = 0;
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) sum += A[i];
    for (int i = 0; i < N; i++) {
        if (A[i] * 4 * M >= sum) count++;
    }
    if (count >= M) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
N=int(input())

pit=[]
for _ in range(N):
    pit.append(list(map(int,input().split())))

dp=[[0]*3 for i in range(N)]

dp[0][0]=pit[0][0]
dp[0][1]=pit[0][1]
dp[0][2]=pit[0][2]

for n in range(1,N):
    dp[n][0]=max(dp[n-1][1],dp[n-1][2])+pit[n][0]
    dp[n][1]=max(dp[n-1][0],dp[n-1][2])+pit[n][1]
    dp[n][2]=max(dp[n-1][1],dp[n-1][0])+pit[n][2]

print(max(dp[-1]))


Measured memory_bytes: 47368
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    long long int a[4],ans;
    for(int i=0;i<3;i++){
    cin>>a[i];
    }
    sort(a,a+3);
    if(a[0]%2+a[1]%2+a[2]%2==1||a[0]%2+a[1]%2+a[2]%2==2){
        if(a[0]%2!=a[1]%2){
            ans=(a[2]*2-a[0]-a[1]+3)/2;
        }
        else{
            ans=(a[2]*2-a[0]-a[1])/2;
        }
    }
    else{
       ans=(a[2]*2-a[0]-a[1])/2; 
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue> 
using namespace std;
int main() 
{int n;
 cin>>n;
 int a[n+1],l[n+1],b[n+1],c=0;
 memset (a,0,sizeof(a));
 memset (l,0,sizeof(l));
 memset (b,0,sizeof(b));
 for (int i=1;i<=n;i++){
 cin>>a[i];
 a[i]+=a[i-1];}
 for (int i=1;i<=n;i++){
 cin>>l[i];
 l[i]+=l[i-1];
 }
 
 for (int i=1;i<=n;i++)
 b[i]=a[i]+l[n]-l[i-1]; 
 c=n+1;
 sort (b,b+c);
 cout<<b[n];

 system("pause");
 return 0;
}        

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

const double PI = acos(-1);
#define MOD 1000000007

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '

#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (abs(a*b)/gcd(a,b))
#define sqr(a) (a*a)

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

main()
{
    ///optimize();
    double r;
    while(cin>>r){
        cout<<fixed<<setprecision(12)<<2*r*PI el;
    }






}





///Brainless people are gonna understand this code.




///Brainless_Loco Terminates Here!


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

using ll=long long;

int gcd (int x, int y){
  if(x<y) swap(x,y);
  if(x%y==0) return y;
  else return gcd(x%y, y);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int ans = a[0];
  rep(i,n) ans = gcd(ans, a[i]);
  cout << ans << endl;  
}

Measured memory_bytes: 640
x,y = map(int,input().split())
if (2*x-y)%3 != 0 or 2*x-y < 0:
    print(0)
    exit()
else:
    b = int((2*x-y)/3)
    a = int(x-2*b)
if a < 0:
    print(0)
    exit()
else:
    small = min(a,b)
    bunbo = 1
    bunsi = 1
    sumer = a+b
    for i in range(small):
        bunsi *= sumer-i
        bunsi = bunsi%1000000007
        bunbo *= i+1
        bunbo = bunbo%1000000007
    bunbo = pow(bunbo,1000000005,1000000007)
    ans = (bunsi*bunbo)%1000000007
    print(ans)

Measured memory_bytes: 3188
// https://atcoder.jp/contests/abc161/tasks/abc161_e

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve() {
  ll N, K, C;
  string S;
  cin >> N >> K >> C >> S;

  VL front(N, -1);

  {
    ll worked = 0;

    rep(i, N) {
      if (S[i] == 'x') continue;

      front[i] = worked;
      ++worked;
      if (worked == K) break;
      i += C;
    }
  }

  VL back(N, -1);

  {
    ll worked = K - 1;

    repr(i, N) {
      if (S[i] == 'x') continue;

      back[i] = worked;
      --worked;
      if (worked == -1) break;
      i -= C;
    }
  }

  rep(i, N) {
    if (front[i] != -1 && front[i] == back[i]) {
      cout << i + 1 << "\n";
    }
  }
}

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif


Measured memory_bytes: 5012
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>

using namespace std;

int N, M;
vector<vector<int>> e;


int main() {
	cin >> N >> M;
	e.resize(N);
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		e[a].push_back(b);
		e[b].push_back(a);
	}
	queue<pair<int, int>> q;//島　今何回目の定期便
	q.push(make_pair(0, 0));
	while (q.size()) {
		pair<int, int> t = q.front(); q.pop();
		if (t.first == N - 1) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
		if (t.second == 2)continue;
		for (int i = 0; i < e[t.first].size(); i++) {
			q.push(make_pair(e[t.first][i], t.second + 1));
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 12784
S = tuple(input())

if S == ('R', 'R', 'R'):
    print(3)
elif S == ('R', 'R', 'S') or S == ('S', 'R', 'R'):
    print(2)
elif S == ('S', 'S', 'S'):
    print(0)
else:
    print(1)


Measured memory_bytes: 9040
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <map>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) string((s).rbegin(), (s).rend())
#define MP make_pair
#define X first
#define Y second

using namespace std;

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


bool prime[300000];

void setprime(){
	fill(prime, prime+300000, true);
	prime[0] = prime[1] = false;
	rep(i, 300000){
		if(prime[i]){
			for(int j = i*2; j < 300000; j+=i){
				prime[j] = false;
			}
		}
	}
}

int main(){
	setprime();

	while(1){
		int n;
		cin >> n;
		if(!n) break;

		int cnt = 0;
		for(int i = n+1; i <= n*2; i++){
			if(prime[i])cnt++;
		}
		cout << cnt << endl;
	}

	return 0;
}

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

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	double tmp = (int)((double)n/1.08);
	if((((int)(tmp*1.08)) == n) ) cout << (tmp) << "\n";
	else if((((int)((tmp+1)*1.08)) == n)) cout << (tmp+1) << "\n";
	else cout << ":(\n";
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	
	var s string
	fmt.Scan(&s)

	n := len(s)
	ans := make([]int, n)

	pre := "R"
	r := 1
	for i := 1; i < n; i++ {
		now := string(s[i])

		if now == "L" && pre == "R" {
			ans[i]=(r)/2
			ans[i-1]=(r-1)/2
		}

		if now == "R" {
			r++
		} else {
			r=0
		}
		pre = now
	}

	pre = "L"
	l := 1
	for i := 1; i < n; i++ {
		now := string(s[n-i-1])

		if now == "R" && pre == "L" {
			ans[n-i-1]+=(l)/2+1
			ans[n-i]+=(l-1)/2+1
		}

		if now == "L" {
			l++
		} else {
			l=0
		}
		pre = now
	}

	for i := 0; i < n; i++ {
		fmt.Print(ans[i])

		if i == n-1 {
			fmt.Println()
		} else {
			fmt.Print(" ")
		}
	}
}


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9


int main(){
  int N, K;
  cin >> N >> K;
  vector<int> x(N);
  int ans = 0;
  REP(i, N){
    cin >> x[i];
    ans += 2*min(x[i], abs(x[i]-K));
  }
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 256
local bls, brs = bit.lshift, bit.rshift
local mmi, mma = math.min, math.max
local bxor = bit.bxor

local function grayCode(x)
  return bxor(x, brs(x, 1))
end
local gw_way = {}
local gw_idx = {}
do
  local size = 11
  local prv = 0
  local bpos = {}
  for i = 1, size do
    bpos[bls(1, i - 1)] = i
  end
  local total = bls(1, size) - 1
  for i = 1, total do
    local v = grayCode(i)
    if prv < v then
      gw_way[i] = true
      gw_idx[i] = bpos[v - prv]
    else
      gw_way[i] = false
      gw_idx[i] = bpos[prv - v]
    end
    prv = v
  end
end

-- add_func(idx), rm_func(idx), work_func()
local function grayWalk(size, add_func, rm_func, work_func)
  local total = bls(1, size) - 1
  for i = 1, total do
    if gw_way[i] then
      add_func(gw_idx[i])
    else
      rm_func(gw_idx[i])
    end
    work_func()
  end
end

local n = io.read("*n")
local v, w = {}, {}
for i = 1, n do
  v[i], w[i] = io.read("*n", "*n")
end
local head_tbl = {}
local box = {}
local ten5 = 100000

local tgt = 0
local weight, val = 0, 0
local tbl = nil
local function add_func(idx)
  weight = weight + w[brs(tgt, idx - 1)]
  val = val + v[brs(tgt, idx - 1)]
end
local function rm_func(idx)
  weight = weight - w[brs(tgt, idx - 1)]
  val = val - v[brs(tgt, idx - 1)]
end
local function work_func()
  if weight <= ten5 then
    tbl[weight] = mma(tbl[weight], val)
  end
end

for i = 512, mmi(n, 1023) do
  tgt = i
  head_tbl[i - 511] = {}
  tbl = head_tbl[i - 511]
  for j = 1, ten5 do
    tbl[j] = 0
  end
  weight, val = 0, 0
  grayWalk(10, add_func, rm_func, work_func)
  for i = 2, ten5 do
    tbl[i] = mma(tbl[i], tbl[i - 1])
  end
end

local q = io.read("*n")
local ans, wlim = 0, 0
local function work_func2()
  if weight <= wlim then
    ans = mma(ans, val)
  end
end
local function work_func3()
  if weight <= wlim then
    ans = mma(ans, val)
  end
  if weight < wlim then
    ans = mma(ans, val + tbl[wlim - weight])
  end
end
for iq = 1, q do
  local pos, wlim_tmp = io.read("*n", "*n")
  wlim = wlim_tmp
  local deg = 0
  do
    local tmp = pos
    while 0 < tmp do
      deg, tmp = deg + 1, brs(tmp, 1)
    end
  end
  if pos < 512 then
    ans = 0
    weight, val = 0, 0
    tgt = pos
    grayWalk(deg, add_func, rm_func, work_func2)
    print(ans)
  elseif pos < 1024 then
    print(head_tbl[pos - 511][wlim])
  else
    deg = deg - 10
    tbl = head_tbl[brs(pos, deg) - 511]
    ans = tbl[wlim]
    weight, val = 0, 0
    tgt = pos
    grayWalk(deg, add_func, rm_func, work_func3)
    print(ans)
  end
end


Measured memory_bytes: 533236