akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int maxHeight = 0;
    int answer = 0;
    for(int i = 0; i < N; i++)
    {
        int height;
        cin >> height;
        if(maxHeight <= height){
            answer++;
            maxHeight = height;
        }
        
    }
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

ll v;
vector<vector<ll>> g;
vector<bool> used;

P dfs(ll p) {
	used[p] = true;
	P ret = P(1, (ll)g[p].size());
	REP(i,g[p].size()) {
		if(!used[g[p][i]]) {
			P tmp = dfs(g[p][i]);
			ret.first += tmp.first;
			ret.second += tmp.second;
		}
	}
	return ret;
}

string solve() {
	cin >> v;
	g.resize(v);
	used.assign(v,false);
	REP(i,v) REP(j,v) {
		char c;
		cin >> c;
		if(i == j) continue;
		if(c == 'Y') g[i].emplace_back(j);
	}
	ll odd = 0, eve = 0;
	ll lonely = 0;
	ll rem = 0;
	REP(i,v) if(!used[i]) {
		ll cnt1 = 0, cnt2 = 0; tie(cnt1, cnt2) = dfs(i);
		if(cnt1 % 2) odd++;
		else eve++;
		if(cnt1 == 1) lonely++;
		rem += cnt1 * (cnt1 - 1) / 2 - cnt2 / 2;
	}
	if(odd % 2) {
		if(((odd / 2) % 2) ^ (rem % 2)) return "Taro";
		else return "Hanako";
	} else {
		if(odd == 0) {
			if(rem % 2) return "Taro";
			else return "Hanako";			
		}
		if(((odd / 2) % 2) ^ (rem % 2)) {
			if(eve != 0) return "Taro";
			else {
				if(odd == 2) return "Hanako";
				else return "Taro";
			}
		} else {
			if(eve > 1) return "Hanako";
			else {
				if(odd == 2) return "Taro";
				else return "Hanako";
			}
		}
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << solve() << endl;	
	return 0;
}



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

using namespace std;

typedef long long ll;

const int INF = 1000000000;
const ll MOD = 1000000007;

int main()
{
  int N; scanf("%d", &N);
  string s, t;
  cin >> s >> t;
  bool is_vertical = (s[0] == t[0]);
  ll ans = is_vertical ? 3 : 6;
  int i = is_vertical ? 1 : 2;
  while (i < N) {
    if (s[i] == t[i]) {
      // vertical domino
      if (is_vertical) {
        // vertical to vertical
        ans *= 2;
      }
      else {
        // horizontal to vertical
        is_vertical = !is_vertical;
      }
      ++i;
    }
    else {
      // two horizontal dominoes
      if (is_vertical) {
        // vertical to horizontal
        ans *= 2;
        is_vertical = !is_vertical;
      }
      else {
        // horizontal to horizontal
        ans *= 3;
      }
      i += 2;
    }
    ans %= MOD;
  }

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


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,k,x,y,t;
    scanf("%d %d %d %d",&n,&k,&x,&y);
    if(n>k)
    {
        t=k*x+(n-k)*y;
    }
    else
    {
        t=n*x;
    }
    printf("%d\n",t);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

void dfs(vector<int> &ta, vector<int> &l, vector<int> &p, vector<int> &co, int lv, int &ans){
  int n = l.size();
  if(lv == n){
    int add = 0;
    rep(i, 3){
      if(p.at(i) == 0) return;
      add += abs(ta.at(i) - p.at(i));
      add += 10 * (co.at(i)-1);
    }
    ans = min(ans, add);
    return ;
  }
  dfs(ta, l, p, co, lv+1, ans);
  rep(i, 3){
    p.at(i) += l.at(lv);
    co.at(i)++;
    dfs(ta, l, p, co, lv+1, ans);
    p.at(i) -= l.at(lv);
    co.at(i)--;
  }
}

int main(){
  int n;
  cin >> n;
  vector<int> ta(3);
  rep(i, 3) cin >> ta.at(i);
  vector<int> l(n);
  rep(i, n) cin >> l.at(i);
  vector<int> p(3, 0), co(3, 0);
  int ans = 1001001001;
  dfs(ta, l, p, co, 0, ans);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}




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


  




int main (){
  ll n;
  cin >> n;
  n += 1;
  int cnt=0;
  while(n>10){
    cnt++;
    n/=10;
  }
  cout << cnt*9+n-1 << endl;
}

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

int main() {
  string S;
  cin >> S;
  int ans = 0, cur = 0;
  for(char c: S) {
    if(c == 'A' || c =='C' || c =='G' || c=='T') cur++;
    else cur = 0;
    ans = max(ans, cur);
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip> 
#include <bits/stdc++.h>
using namespace std;
double pi=3.14159265358979323846264338;


bool issqt(long long k){
	if(k<=3)return true;
	long long s=(long long)sqrt(k);
	//cout<<k<<" "<<s<<endl;
	for(long long i=2;i<=s;i++)
		if(k%i==0)return false;
	return true;
}
 
 
int main() {
	int n[6];
	for(int i=1;i<=5;i++){
		cin>>n[i];
		if(n[i]==0){
			cout<<i<<endl;
			return 0;
		}
	}
  return 0;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;
typedef long long ld;


int main() {
	// violinista forever xd
	ios::sync_with_stdio(0),cin.tie(0);
	
	string s; 
	cin >> s;
 
   for(int i=0;i<2;i++) {
    if (s[i] != s[i+1]) {
      cout << "Yes"<<endl;
      
      return (0);
    }
   }
 
  cout<< "No"<<endl;
	
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <string>
#include <queue>

using namespace std;

int main()
{
  queue<char> S;
  vector<bool> exist(26, false);
  string esu;
  cin >> esu;
  for (int i = 0; i < esu.length(); i++)
  {
    S.push(esu[i]);
  }

  if (esu == "zyxwvutsrqponmlkjihgfedcba")
  {
    cout << "-1" << endl;
    return 0;
  }
  for (int i = 0; i < 26; i++)
  {
    char moji = 'a' + i;
    if (esu.find(moji) == string::npos)
    {
      cout << esu << moji << endl;
      return 0;
    }
  }
  //もしだめだったら？
  while (true)
  {
    esu[esu.length() - 1]++;
    if (esu[esu.length() - 1] == '{')
    {
      esu.pop_back();
      continue;
    }
    else
    {
      if (esu.find_first_of(esu[esu.length() - 1]) == esu.length() - 1)
      {
        cout << esu << endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int n; cin>>n;
    int sum=0,maxi=0;
    rep(i,n){
        int l; cin>>l;
        sum+=l;
        maxi=max(maxi,l);
    }
    if(sum-maxi>maxi){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define P pair<int,int>
#define All(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
typedef long long ll;
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const ll LINF = 1e18;
int main() {
	string s;
	cin >> s;
	reverse(All(s));
	for (int i = 0; i < (int)s.size();) {
		if (i == s.size()) {
			break;
		} if (s.substr(i, 5) == "maerd") {
			i += 5;
		} else if (s.substr(i, 7) == "remaerd") {
			i += 7;
		} else if (s.substr(i, 5) == "esare") {
			i += 5;
		} else if (s.substr(i, 6) == "resare") {
			i += 6;
		} else {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 512
from itertools import accumulate
n,q=list(map(int,input().split()))
s=list(input())
l=[]
r=[]
for i in range(q):
  o,p=list(map(int,input().split()))
  l.append(o)
  r.append(p)
  
ruiseki=[]
for i in range(n-1):
  if s[i]=="A" and s[i+1]=="C":
    ruiseki.append(1)
  else:
    ruiseki.append(0)
ruiseki=[0]+list(accumulate(ruiseki))

for i in range(q):
  print(ruiseki[r[i]-1]-ruiseki[l[i]-1])
  
    

Measured memory_bytes: 23116
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n,K; cin >> n >> K;
  vector<ll> a(n);
  ll sum=0;
  rep(i,n){
    cin >> a[i];
    sum+=a[i];
  }
  ll ans=0;
  for(int i=1;i<=sqrt(sum);i++){
    if(sum%i!=0) continue;
    vector<ll> p={i,sum/i};
    rep(k,2){
      vector<ll> b=a;
      rep(j,n){
        b[j]%=p[k];
      }
      sort(all(b));
      vector<ll> s(n+1);
      s[0]=0;
      rep(j,n){
        s[j+1]=s[j]+b[j];
      }
      
      rep(j,n+1){
        ll mns=s[j];
        ll pls=p[k]*(n-j)-(s[n]-s[j]);
        if(mns==pls&&pls<=K) chmax(ans,p[k]);
      }
    }
  }
  cout << ans << endl;
}

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

int main(){
	while(1){
		int L, M, N, ans = 0;
		
		cin>>L;
		if(L == 0)
			break;

		for(int i=1;i<=12;i++){
			cin>>M>>N;
			L -= M-N;

			if((L <= 0) && (ans == 0))
				ans = i;
		}

		if(ans == 0)
			cout<<"NA"<<endl;
		else
			cout<<ans<<endl;
	}

	return 0;
}

Measured memory_bytes: 1160
import java.util.*;

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

	String[] type = {"A","B","C","D","E","F","G"};
	while(sc.hasNext()){
	    int[][] field = new int[8][8];
	    
	    for(int i=0; i<8; i++){
		String line = sc.next();
		for(int j=0; j<8; j++){
		    field[i][j] = Integer.parseInt(line.substring(j,j+1));
		}
	    }
	    
	    int[] x = new int[4];
	    int[] y = new int[4];
	    int count = 0;
	    for(int i=0; i<8; i++){
		if(count>=4){break;}
		for(int j=0; j<8; j++){
		    if(count>=4){break;}
		    if(field[i][j]==1){
			x[count] = j;
			y[count] = i;
			count++;
		    }
		}
	    }
	    
	    System.out.println(getType(x,y));
	}
    }

    public static String getType(int[] x, int[] y){
	if(x[0]==x[1]&&x[0]==x[2]&&x[0]==x[3]){return  "B";}
	if(y[0]==y[1]&&y[0]==y[2]&&y[0]==y[3]){return  "C";}
	if(x[0]==x[2]&&x[1]==x[3]&&y[0]==y[1]&&y[2]==y[3]){return "A";}
	if(x[0]==x[2]&&x[1]==x[3]&&y[1]==y[2]){return "D";}
	if(x[0]==x[1]&&x[2]==x[3]&&y[1]==y[2]){return "F";}
	if(x[1]==x[2]&&y[0]==y[1]&&y[2]==y[3]){return "E";}
	return "G";
    }
}

Measured memory_bytes: 12000
import sys
from math import ceil
def input(): return sys.stdin.readline().strip()

def main():
    N = int(input())
    T = [int(input()) for _ in range(5)]

    """
    最も定員人数が少ない乗り物を考える。（複数ある場合は一番左側にあるものを見る）
    それが定員x人で[i, i+1]区間を結んでいるとして、[0, i]区間の乗り物がどうなって
    いるかを無視しても、
        ・ある時間以降i+1の街にはx人ずつ降り立ち、
        ・i+1の街以降では乗り物待ちは発生しない。
    ことが分かる。

    よって求める時間は
        ・i街に誰かが来るまでの時間（i分）
        ・[i, i+1]区間でN人全員を送り出す時間（ceil(N / x)分）
        ・最後の人がi+1街から最後の町に到着するまでの時間（5 - i - 1分）
    を合計して
        i + ceil(N / x) + (5 - i - 1) = ceil(N / x) + 4
    となる。
    """

    print(4 + ceil(N / min(T)))


if __name__ == "__main__":
    main()


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

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

 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    ll n,a,b,c,d,e;
    cin >> n >> a >> b >> c >> d >> e;
    ll m = min(a,min(b,min(c,min(d,e))));
    
    ll ans;

    if (n%m==0) {
        ans = n/m-1+5;
    }
    else {
        ans = n/m+5;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3552
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
//最大公約数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
//最小公倍数
ll box(double a) 
{
	ll b = a;
	return b;
}
//切り捨て
ll fff(double a) 
{
	ll b = a + 0.5;
	return b;
}
//四捨五入
ll sum(ll n) { 
	return (1 + n) * n / 2;
}
//1から整数nまでの合計
bool prime(ll a)//素数判定、primeならtrue,違うならfalse
{
	if (a < 2) return false;
	else if (a == 2) return true;
	else if (a % 2 == 0) return false;
	double sqrtNum = sqrt(a);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (a % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}
//素数判定

// ===============================================================

int main() {
	ll n; cin >> n;
	vl a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	vl data(n);
	data[0] = a[0];
	for (int i = 0; i < n; i++) {
		if (min(data[i - 1], a[i]) == a[i]) {
			data[i] = a[i];
		}
		else data[i] = data[i - 1];
	}
	ll cnt = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] < data[i - 1]) {
			cnt++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 6468
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long int I;

int keta(int a){
    int count=0;
    while(a!=0){
        a/=10;
        count++;
    }
    return count;
}


int main(){
    int n,m,cnt=0;
    cin>>n>>m;
    int ans = n/m;
    if(n%m!=0)
        ans++;
    cout<<ans<<endl;

    return 0;
} //カモンAC

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*  Writen by : AS7
 *  "JUST KEEP GOING..."
 */
#define endl			'\n'
#define ll				long long
#define all(v)			((v).begin()), ((v).end())
#define allr(v)			((v).rbegin()), ((v).rend())
#define sz(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define For(i,s)        for(auto i:s)
#define Forr(i,s)        for(auto &i:s)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define vi				vector <int>
#define vl				vector <ll>
#define ii				pair <int,int>
#define vii				vector <ii>
#define vll				vector <pair<ll,ll>>
#define PI				double PPPPPP = 3.14159265358979323846;
#define bit(mask,i) ((mask>>i)&1)
const int N = 2e5+5;
map<string ,int > freq;
void solve(){
   int n;
   cin>>n;
   lp(i,n){
       string s;
       cin>>s;
       freq[s]++;
   }
   cout<<"AC x "<<freq["AC"]<<"\n"<<"WA x "<<freq["WA"]<<"\n"<<"TLE x "<<freq["TLE"]<<"\n"<<"RE x "<<freq["RE"]<<endl;

}
int main() {
    int t = 1;
  //  cin>>t;
    while (t--)solve();
}

Measured memory_bytes: 3640
import sys

f = sys.stdin
s = f.readline()[:-1]
week = {'SUN': 0, 'MON': 1, 'TUE': 2, 'WED': 3, 'THU': 4, 'FRI': 5, 'SAT': 6}

day = 7 - week[s]
print(day)

Measured memory_bytes: 2940
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    n = int(input().strip())
    a = []
    for i in range(n):
        a.append(int(input().strip()))
    m = INF
    ans = -INF
    for i in range(n):
        ans = max(ans, a[i] - m)
        if m > a[i]:
            m = a[i]
    print(ans)


if __name__ == '__main__':
    main()



Measured memory_bytes: 13684
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll l[100005],r[100005],ans[100005],fa[100005],cnt[100005];
ll get(ll x)
{
    return fa[x] == x ? x : fa[x] = get(fa[x]);
}
void merge(ll a,ll b)
{
    ll x = get(a),y = get(b);
    if(x != y)
    {
        cnt[y] += cnt[x];
        fa[x] = y;
    }

}
int main()
{
    ll n,m;
    scanf("%lld%lld",&n,&m);
    for(ll i=1; i<=m; i++)
    {
        scanf("%lld%lld",&l[i],&r[i]);
    }
    for(ll i=1; i<=n; i++)fa[i]=i;
    for(ll i=1; i<=n; i++)cnt[i]=1;
    ans[m]=n*(n-1)/2;
    for(ll i=m; i>=1; i--)
    {
        ll x=get(l[i]),y=get(r[i]);
        if(x==y)
        {
            ans[i-1]=ans[i];
            merge(x,y);
        }
        else
        {
            ans[i-1]=ans[i]-cnt[x]*cnt[y];
            merge(x,y);
        }
    }
    for(ll i=1;i<=m;i++)printf("%lld\n",ans[i]);
}


Measured memory_bytes: 5248
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
using namespace std;
using uint = unsigned int;
using ull = unsigned long long;

int main() {

	uint N, W;
	cin >> N >> W;

	vector<pair<uint, uint>> wv(N);
	ull vmax = 0;
	ull wmax = 0;
	for(uint i=0; i<N; i++) {
		uint w, v;
		cin >> w >> v;
		wv[i] = make_pair(w, v);
		vmax += v;
		wmax += w;
	}

	sort(wv.begin(), wv.end());
	vector<vector<ull>> dp(vmax+1, vector<ull>(N+1, wmax));

	for(uint i=0; i<=N; i++) {
		dp[0][i] = 0;
	}

	ull ans = 0;

	for(uint i=1; i<=N; i++) {
		for(uint j=1; j<=vmax; j++) {
			uint wi = wv[i-1].first;
			uint vi = wv[i-1].second;

			if(j >= vi) {
				dp[j][i] = min(dp[j-vi][i-1] + wi, dp[j][i-1]);
			} else {
				dp[j][i] = dp[j][i-1];
			}

			if(dp[j][i] <= W) {
				ans = j;
			}
		}
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 82304
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	int ans=0;
	if(2*c<a+b)
	{
		int minx=min(x,y);
		ans+=minx*2*c;
		x-=minx;
		y-=minx;
		if(2*c<a)
		{
			ans+=x*2*c;
			x=0;
		}
		if(2*c<b)
		{
			ans+=y*2*c;
			y=0;
		}
		ans+=x*a+y*b;
	}
	else
	{
		ans=a*x+b*y;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
def resolve():
    import sys
    input = sys.stdin.readline
    n = int(input())
    ans = dict()
    for _ in range(n):
        q, key, *x = input().split()
        if q == "0":
            ans[key] = x[0]
        elif q == "1":
            if key in ans:
                print(ans[key])
            else:
                print(0)
        else:
            ans[key] = "0"


resolve()



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

const int M = 1000005;

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> c(h, vector<char>(w));
  rep(i, h){
    rep(j, w){
      cin >> c[i][j];
    }
  }
  rep(i, h){
    int k = 2;
    while(k--){
      rep(j, w){
        cout << c[i][j];
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int n, x, y;
int d[5000];
int cnt[5000];

signed main() {

    cin >> n >> x >> y;

    for(int i = 1; i <= n; i++) {
        queue<int> que;
        memset(d, -1, sizeof(d));
        que.push(i);
        d[i] = 0;
        while(!que.empty()) {
            int v = que.front();
            que.pop();
            cnt[d[v]]++;
            if(1 < v and d[v-1] == -1) {
                d[v-1] = d[v] + 1;
                que.push(v-1);
            }
            if(v < n and d[v+1] == -1) {
                d[v+1] = d[v] + 1;
                que.push(v+1);
            }
            if(v == x and d[y] == -1) {
                d[y] = d[v] + 1;
                que.push(y);
            }
            if(v == y and d[x] == -1) {
                d[x] = d[v] + 1;
                que.push(x);
            }
        }
    }

    for(int i = 1; i < n; i++)
        cout << cnt[i]/2 << endl;

    
    return 0;
}



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

int main()
{
   double x1, x2, y1, y2;

   cin >> x1 >> y1 >> x2 >> y2;

   double d = sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) );

   cout << fixed << setprecision(12) << d <<endl;

	return 0;
}


Measured memory_bytes: 3300
#include <float.h>
#include <inttypes.h>
#include <limits.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

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

#define P 1000000007

int k[200000];
int rk[200000];

int getk(int a, int x){
	if(x==1) return a;
	int b = getk(a, x/2);
	b = ((long)b)*b%P;
	if((x&1)==0){
		return b;
	}else{
		return ((long)b)*a%P;
	}
}

int comb(int a, int b){
	if(a<b) return 0;
	return ((long)k[a])*rk[b]%P*rk[a-b]%P;
}

void comb_init(int n){
	k[0]=1;
	for(int i=1; i<=n; i++){
		k[i]=k[i-1]*((long)i)%P;
	}	
	rk[n]=getk(k[n], P-2);
	for(int i=n-1; i>=0; i--){
		rk[i]=((long)rk[i+1])*(i+1)%P;
	}
}

int a[25];
int main(void){
	int n=nextint();
	int m=nextint();
	int q=sqrt(m);
	int k=0;
	int max=1;
	for(int i=2; i<=q; i++){
		if(m%i==0){
			while(m%i==0){ m/=i; a[k]++; }
			if(a[k]>max) max=a[k];
			k++;
		}
	}
	if(m>1){
		a[k++]=1;
	}
	comb_init(n+max);
	long ans=1;
	for(int i=0; i<k; i++){
		ans=ans*comb(n+a[i]-1, a[i])%P;
	}
	printf("%ld\n", ans);
}


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

const char s[] = "RGBY";
int N, M, D;

int main() { 
    cin >> N >> M >> D; 
    for (int i = 0; i < N; i++, putchar('\n'))
        for (int j = 0, x, y; j < M; j++)
            x = (M + i + j) / D % 2,
            y = (M + i - j) / D % 2,
            putchar(s[2 * x + y]);
    return 0;
}

Measured memory_bytes: 3600
mod=10**9+7

def add(a, b):
    return (a + b) % mod

def sub(a, b):
    return (a + mod - b) % mod

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else            : return power(x, y//2)**2 * x % mod

def div(a, b):
    return mul(a, power(b, mod-2))

def cc(ii):
    iii=1
    for ii in range(1,ii+1):
        iii=iii*ii
    return iii

def cmb(a,b):
    iii=1
    for ii in range(a-b+1,a+1):
        iii=(iii*ii)%mod
    iiii=1
    for ii in range(1,b+1):
        iiii=(iiii*ii)%mod
#        print("ii,iiii:",ii,iiii)
#    print("a:",a,"b:",b,"iii:",iii,"iiii:",iiii)
#    print("a:",a,"b:",b,"a-b:",a-b,"a!:",iii,"b!:",iiii,"cmb:",iii//iiii)
    return div(iii,iiii)        

from functools import reduce

def cmb2(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    if r==1 : return n
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return div(over,under)        

n,k=map(int,input().split())

ib=k-1
ir=n-ib

for i in range(1,ib+2):
    if i>ir:
        print(0)
        continue
#    cb=cc(ib)//cc(ib-i+1)//cc(i-1)
#    cr=cc(ir)//cc(ir-i)//cc(i)
    cb=cmb2(ib,i-1)
    cr=cmb2(ir,i)
#    print("ib:",ib,i-1,cb,"ir:",ir,i,cr)
    print(mul(cb,cr))
    


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

// ただの辺
struct edge {
    int to;
    long long cost;
    // 引数一つの時は距離1
    edge(int t, long long c = 1) : to(t), cost(c) {}
};

vector<vector<edge>> g;

// dijkstra
// depend:edge
vector<long long> dijkstra(vector<vector<edge>> g, int start) {
    using P = pair<long long, long long>;
    vector<long long> res(g.size(), LLONG_MAX);
    res[start] = 0;
    priority_queue<P, vector<P>, greater<P>> pq;  // first:距離、second:行き先
    pq.push({0, start});
    while (!pq.empty()) {
        long long dist = pq.top().first, now = pq.top().second;
        pq.pop();
        if (res[now] < dist) continue;
        for (auto e : g[now]) {
            if (res[e.to] <= res[now] + e.cost) continue;
            res[e.to] = res[now] + e.cost;
            pq.push(make_pair(res[e.to], e.to));
        }
    }
    return res;
}

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

int main() {
    int n, m, s;
    cin >> n >> m >> s;
    g.resize(n * 2501);
    for (int i = 0; i < m; i++) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--, v--;
        // j:出発の所持金
        for (int j = 0; j <= 2500; j++) {
            if (j - a >= 0) {
                g[2501 * u + j].push_back(edge(2501 * v + j - a, b));
                g[2501 * v + j].push_back(edge(2501 * u + j - a, b));
            }
        }
    }
    for (int i = 0; i < n; i++) {
        int c, d;
        cin >> c >> d;
        // j:出発の所持金
        for (int j = 0; j <= 2500; j++) {
            g[2501 * i + j].push_back(edge(2501 * i + min(2500, j + c), d));
        }
    }
    auto dist = dijkstra(g, min(2500, s));
    for (int i = 1; i < n; i++) {
        lint ans = LLONG_MAX;
        for (int j = 0; j <= 2500; j++) {
            chmin(ans, dist[2501 * i + j]);
        }
        cout << ans << endl;
    }
}

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

int main() {
	int x;
  	cin>>x;
  
  	ll gohyaku=0;
  	ll goen=0;

  	while(x>=500){
    	gohyaku++;
        x -=500;
    }
  
  
  
  	while(x>=5){
    	goen++;
      	x -=5;
       }
  	
  	ll uresisa=gohyaku*1000+goen*5;
  
  	cout<<uresisa<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i = (m); i < (n); i++)
#define rrep(i,m,n) for(int i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll s;
    cin >> s;
    map<ll,ll> mp;
    mp[s] = 1;
    ll v = s;
    rep(i,0,100010){
        if(v % 2 == 0){
            v = v/2;
        }else{
            v = 3 * v + 1;
        }
        if(mp[v] == 1){
            print(i+2);
            return 0;
        }
        mp[v] = 1;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int ans=0;
	long long int N,D,X,Y;
	cin>>N>>D;
	for(int i=0;i<N;i++){
		cin>>X>>Y;
		ans += X*X+Y*Y<=D*D;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt() - 1;
        }
        int ans = 0;
        int current = 0;
        while (ans < n) {
            current = a[current];
            ans++;
            if (current == 1) {
                break;
            }
        }
        if (ans == n) {
            System.out.println(-1);
        }
        else {
            System.out.println(ans);
        }
    }
}


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

using namespace std;

//const int OO = 0x3f3f3f3f;
const long long OO = (long long) 1e18L+7;
//const unsigned long long UOO = (long long) 10e18+7;
#define lp(i,a,n) for(int i = a ; i < n ; ++i)
#define lpr(i,a,n) for(int i = a ; i >= n ; --i)
#define rep(i,vec) for(int i = 0 ; i < vec.size() ; ++i)
#define reprv(i,vec) for(int i = vec.size()-1; i >=0 ; --i)
#define eps (1e-5)
#define pb(i) push_back(i)
#define EPS 1e-9
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define debug(x) cout<<(#x)<<": \""<<x<<"\""<<endl
#define debugVec(vec) cout<<(#vec)<<": "; for (auto& i: vec) cout<<i<<" "; cout<<endl

typedef vector<int> vi ;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll ;
typedef pair<int,int> pii ;
typedef vector< pair<int,int> >  vpii;
typedef vector<pair<long long,long long>> vpll;
typedef vector<vector<int> > vvi ;
typedef complex<double> point;
typedef pair<ll,ll> pll;

ll  inv(ll a, ll b) {return 1 < a ? b - inv(b % a, a) * b / a : 1;}
ll  Pow(ll  B,ll  P){ll  R=1; while(P>0)  {if(P&1) R=(R*B);P/=2;B=(B*B);}return R;} //compute b^p
ll  GCD(ll  a,ll  b){ while(b){b ^= a ^=b ^= a %=b;}  return a;}
ll  LCM(ll  a,ll  b) { return (a / GCD(a,b)*b); }
ll  BigMod(ll  B,ll  P,ll  M){ ll  R=1; while(P>0)  {if(P&1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return (ll )R;} //compute b^p%m
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//int i=uniform_int_distribution<int>(1,n)(rng);
///-----------------------------------------------------------------------------

int n;
vll nms;

ll dp[3002][30002];



///-----------------------------------------------------------------------------
int main()
{
    #ifndef ONLINE_JUDGE
//       freopen( "output.txt" , "w" , stdout ) ;
    //   freopen( "input.txt" , "r" , stdin ) ;
    auto stTime = clock();
    #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
//    cout.tie(0);
///-----------------------------------------------------------------------------------

    cin >> n ;
    nms.resize(n);
    lp(i,0,n) cin >> nms[i];

    lpr(l,n-1,0)lp(r,l,n){
        if(l==r) dp[l][r] = nms[l];
        else dp[l][r] = max( nms[l] - dp[l+1][r] , nms[r] - dp[l][r-1] );
    }

    cout << dp[0][n-1];



///------------------------------------------------------------------------------------
    #ifndef ONLINE_JUDGE
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif

    return 0;
}


Measured memory_bytes: 50720
from bisect import bisect_right
N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
a.sort()
b.sort()
c.sort()
b2c = [0 for _ in range(len(b))]
for i, bn in enumerate(b):
    b2c[i] = len(c) - bisect_right(c, bn)
sm = sum(b2c)
smb2c = [0 for _ in range(len(b))]
smb2c[0] = b2c[0]
for i, bn in enumerate(b2c):
    if i > 0:
        smb2c[i] += smb2c[i - 1] + bn
ans = 0
for i, an in enumerate(a):
    tmp = bisect_right(b, an)
    if(tmp > 0):
        ans += sm - smb2c[tmp - 1]
    else:
        ans += sm
print(ans)


Measured memory_bytes: 24820
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yay!")
    else:print(":(")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
#n = ip()                                     #入力整数1つ
#a,b= (int(i) for i in input().split())       #入力整数横2つ以上
a = [int(i) for i in input().split()]        #入力整数配列
#c = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
a.sort()
s = a[1]
a[1]-=1
print(s+max(a))

Measured memory_bytes: 13860
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
 
using namespace std; 
 
#define NOT_FOUND -1
#define rep(i,n) for(int i=0;i<(int)(n); i++)
/*for文のマクロ定義
rep(i,回数){
    処理
}
*/
 
void swap(int *a, int *b){
	*b=*a-*b;
	*a-=*b;
	*b+=*a;
}
 
int sosu_judge(int N){
	/*素数ならば1
	  素数でなければ0を返す
	*/
	int i,j;
 
	if(N==2)   return 1;
	if(N%2==0) return 0;
 
	for(i=3;i<N && N%i!=0;i+=2);
 
	if(i>=N) return 1;
	
	return 0;
}
 
int factorial(int N){  //Nの階乗を求める関数
	int ans=1;
 
	while(N--) ans*=(N+1);
	return ans;
}
 
//クイックソートをする関数
void q_sort(int a[], int first, int last){
    int i,j;
    int x,t;
 
    x = a[(first + last) / 2];
    i = first; j=last;
 
    while(1){
        while( a[i] < x) i++;
        while( x < a[j]) j--;
        
        if( i >= j) break;
        
        swap(&a[i],&a[j]);
        i++; j--;
    }
    if(first < i-1) q_sort(a, first,i-1 );
    if(last > j+1)  q_sort(a, j+1,  last);
}
 
int b_search(int target, int array[],int right, int left){
    /*二分探索を行う関数である。
      戻り値は探索したい値の格納されている位置である。
      もし値が存在しない場合、NOT_FOUND(-1)を返す
    */
    int mid;
    while(left<right){
        mid=(right+left)/2;
        if(array[mid]<target) left =mid+1;
        else                  right=mid;
    }
    if(array[mid]==target) return mid;
    return NOT_FOUND;
}
 
unsigned long combination(int n, int r){
    /*nCrの値を求める関数である。
      値が巨大になる可能性があるため、戻り地はunsigned longである
    */
    int i,j;
    unsigned long a[17];
 
    if(n-r<r) r=n-r;
    if(r==0 ) return 1;
    if(r==1 ) return n;
    if(r>17 ) return 0;
    for(i=1;i<r;i++) a[i]=i+2;
    for(i=3;i<=n-r+1;i++){
        a[0]=i;
        for(j=1;j<r;j++)a[j]+=a[j-1];
    }
    return a[r-1];
}

int main(){
    int N,M;
    int ans=0;

    cin>>N>>M;

    if(M>1){
    ans+=combination(M,2);
    }
    if(N>1){
        ans+=combination(N,2);
    }
    cout<<ans<<endl;
    return 0;
}


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

int max(int x,int y){
  if(x>y) return x;
  return y;
}

int main(){
  int n,count=0,num=0;
  cin >> n;
  for(int i =1;i<=n;i++){
    int res=0,j;
    j=i;
    while(j%2==0){
      j/=2;
      res++;
    }
    if(res>=count) num=i;
    count=max(res,count);
  }
  cout << num << endl;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc149/tasks/abc149_d

def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

N, K = MAP()
R, S, P = MAP()
T = input()

point = {"r": P, "s": R, "p": S}


wins = [0] * N
ans = 0
for i in range(N):
    if i < K:
        ans += point[T[i]]
        wins[i] = 1
        continue
    if T[i] == T[i-K] and wins[i-K] == 1:
        continue
    else:
        ans += point[T[i]]
        wins[i] = 1

print(ans)        

Measured memory_bytes: 40688
#include <bits/stdc++.h>
using namespace std;
#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();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main()
{
    int N;
    cin >> N;
    vint a(N);
    int g = 0;
    rep(i, N)
    {
        cin >> a[i];
        g = __gcd(g, a[i]);
    }
    cout << g;
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n;
    cin >> n;
    double res = 0;
    for (int i = 0; i < n; ++i) {
        double a;
        cin >> a;
        res += 1.0 / a;
    }
    cout << fixed << setprecision(10) << 1.0 / res << endl;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, a, b, k, v, p, l[100008], r[100008], even[100008], ansv[100008], s;
vector<vector<ll>> g;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n;
	g.resize(n);
	zep(i, 0, n){
		l[i] = 0;
		r[i] = 1e6;
	}
	zep(i, 0, n-1){
		cin >> a >> b; 
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	
	cin >> k;
	memset(even, -1, sizeof(even));
	zep(i, 0, k){
		cin >> v >> p;
		v--;
		ansv[v] = p;
		l[v] = p;
		r[v] = p;
		even[v] = p%2;
		s = v;
	}
	
	bool ans = true;
	queue<ll> q;
	bool use[n];
	memset(use, 0, sizeof(use));
	q.push(s);
	use[s] = true;
	
	while(!q.empty()){
		ll at = q.front(); q.pop();
		
		zep(i, 0, g[at].size()){
			ll nx = g[at][i];
			if(even[nx] >= 0 && even[nx] == even[at]){ans = false;}
			even[nx] = 1-even[at];
			
			if(!use[nx]){
				q.push(nx);
				use[nx] = true;
			}
		}
	}
	
	if(ans){
		ll cnt[n];
		zep(i, 0, n){cnt[i] = g[i].size();}
		
		zep(i, 0, n){if(cnt[i] == 1){q.push(i);}}
		
		while(!q.empty()){
			ll at = q.front(); q.pop();
			if(r[at]-l[at] < 0){ans = false;}
			
			zep(i, 0, g[at].size()){
				ll nx = g[at][i];
				
				l[nx] = max(l[at]-1, l[nx]);
				r[nx] = min(r[at]+1, r[nx]);
				cnt[nx]--;
				
				if(cnt[nx] == 1){q.push(nx);}
			}
			s = at;
		}
		
		ansv[s] = r[s];
		if(ans){
			q.push(s);
			memset(use, 0, sizeof(use));
			use[s] = true;
			
			while(!q.empty()){
				ll at = q.front(); q.pop();
				
				zep(i, 0, g[at].size()){
					ll nx = g[at][i];
				
					if(!use[nx]){
						if(ansv[at]+1 > r[nx]){
							ansv[nx] = ansv[at]-1;
						}
						else{
							ansv[nx] = ansv[at]+1;
						}
						
						q.push(nx);
						use[nx] = true;
					}
				}
			}
		}
	}
	
	print((ans)? "Yes" : "No")
	if(ans){
		zep(i, 0, n){
			print(ansv[i])
		}
	}
	return 0;
}

Measured memory_bytes: 13312
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
typedef long long ll;
typedef pair<ll,ll> P;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
int main(){
    int n,k;
    cin>>n>>k;
    vi d(k);
    //vi a(k);
    int ans=0;

    vector<vector<ll>> a(k,vector<ll>(n));
    rep(i,k){
        cin>>d[i];
        rep(j,d[i]){
            cin>>a[i][j];
        }
    }
    for(int i=1;i<=n;i++){
        bool flag=false;
        for(int j=0;j<k;j++){
            for(int k=0;k<d[j];k++){
               if(i==a[j][k])flag=true;
               
            }
        }
        if(!flag)ans++;
    }

    cout<<ans;

}


Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
using namespace std;
 
int HCF(int a, int b){
    if(b){
        return HCF(b, a % b);
    }else{
        return a;
    }
}
 
int HCF_base(int a, int b){
    return HCF(max(a, b), min(a, b));
}
 
int main(){
    int N, K;
    cin >> N >> K;
    int GCD;
    cin >> GCD;
    int max_num = GCD;
    for(int i = 1; i < N; i++){
        int num;
        cin >> num;
        GCD = HCF_base(GCD, num);
        max_num = max(max_num, num);
    }
    if(K <= max_num && K % GCD == 0){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;

const int maxN = 510; 
const int INF = 1000000000;

char a[maxN];

int main()
{
	scanf("%s",a+1);
	int len = strlen(a+1);
	int flag = 0;
	if(a[1] != 'A')
	{
		printf("WA\n");
		return 0;
	}
	int cnt = 0;
	int pos;
	for(int i=3;i<=len-1;i++)
	{
		if(a[i] == 'C')
			pos = i,cnt++; 
	}
	if(cnt > 1 || cnt == 0 )
	{
		printf("WA\n");
		return 0;
	}
	for(int i=1;i<=len;i++)
	{
		if(i == 1 || i== pos)
			continue;
		if(a[i]<='Z')
		{
			printf("WA\n");
			return 0;
		}	
	}
	printf("AC\n");
	return 0;
}

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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}


ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

int main(){
  char c;
  cin>>c;
  string s ="abcdefghijklmnopqrstuvwxyz";
  rep(i,s.size()){ 
    if(s[i]==c){ 
      cout<<s[i+1];
      break;                  
    }
  }
}




Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<cctype>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    string a,b,c;
    while(cin>>a)
    {
        cin>>b;
        cin>>c;
        cout<<a[0]<<b[1]<<c[2]<<endl;
    }
}


Measured memory_bytes: 256
n, m = map(int, input().split())
x = list(map(int, input().split()))

if n >= m:
    print(0)
else:
    x.sort()
    diff = [abs(x[i] - x[i + 1]) for i in range(m - 1)]
    diff.sort()
    print(sum(diff[0:m - n]))


Measured memory_bytes: 13960
ary = Array.new(4){ Array.new(3){ Array.new(10,0) } }
n = gets.chomp.to_i
n.times do
  b,f,r,v = gets.chomp.split.map(&:to_i)
  ary[b - 1][f - 1][r - 1] += v

end

4.times do |i|
  3.times do |j|
    10.times do |k|
      ary[i][j][k] =
      print " " + ary[i][j][k].to_s
    end
    puts
  end
  puts "#" * 20 if i != 3
end


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

// JčÔľńć@
mint f(int n) {
  if (n == 0) return 1;
  mint x = f(n / 2);
  x *= x;
  if (n % 2 == 1) x *= 2;
  return x;
}

// gÝíš
mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i, a) {
    x *= n - i;
    y *= i + 1;
  }
  return x / y;
}

ll modpow(ll a, ll b) {
  ll r = 1;
  while (b) {
    if (b & 1) r = r * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return r;
}

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  mint ans = modpow(2,n);
  ans -= 1;
  ans -= choose(n, a);
  ans -= choose(n, b);

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


Measured memory_bytes: 3600