akhauriyash/Code-Regression huggingface dataset:
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(input())
A=[int(i) for i in input().split()]
inf=float("inf")
DP=[[-inf]*4 for _ in range(n+1)]
DP[0][2]=0
for i,a in enumerate(A):
  if (i+1)%2==0:
    DP[i+1][0]=DP[i][3]+a
    if i>=1:
      DP[i+1][0]=max(DP[i+1][0],DP[i-1][2]+a)
    DP[i+1][2]=DP[i][0]
    DP[i+1][3]=max(DP[i][1],DP[i][3])
    if i>=1:
      DP[i+1][3]=max(DP[i+1][3],DP[i-1][2])
  else:
    DP[i+1][0]=DP[i][2]+a
    DP[i+1][1]=DP[i][3]+a
    DP[i+1][3]=max(DP[i][0],DP[i][2])
if n%2==0:
  print(max(DP[n][0],DP[n][2]))
else:
  print(max(DP[n][1],DP[n][3]))



Measured memory_bytes: 58580
#include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e12;
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()

typedef complex<double> P;
typedef vector<P> VP;
double cross(P a, P b){
    return (conj(a)*b).Y;
}

struct argcomp{
	P p;
	bool operator()(const P &a, const P &b){
		return cross(a-p, b-p) < 0;
	}
};

int main(){
	while(1){
		int n;
		cin >> n;
		if(n==0) break;

		VP p(n);
		for(int i=0; i<n; i++){
			int x,y;
			cin >> x >> y;
			p[i] = P(x, y);
		}

		P curr = P(0, 0);
		argcomp comp;
		double ans = 0;
		while(!p.empty()){
			comp.p = curr;
			sort(p.begin(), p.end(), comp);
			P next = p[0];
			int lim = 1;
			for(int i=1; i<(int)p.size(); i++){
				if(abs(cross(next -curr, p[i] -curr)) < EPS){
					lim++;
					if(abs(p[i] -curr) > abs(next -curr)){
						next = p[i];
					}
				}
			}
			p.erase(p.begin(), p.begin() +lim);
			ans += abs(next -curr);
			curr = next;
		}
		cout << fixed << setprecision(1);
		cout << ans << endl;
	}
	return 0;
}


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

#define REP(i, start, count) for (int i = (start); i < (int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;

ll N;

int main(void)
{
    vector<int> d(20);
    cin >> N;

    ll ans = 0;
    if (N % 2 == 0) {
        ll n = 10;
        while (N >= n && n > 0) {
            ans += N / n;
            n *= 5;
        }
    }

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

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

template<int MOD>
class ModInt{
public:
    ModInt():value(0){}
    ModInt(long long val):value((int)(val<0?MOD+val%MOD:val%MOD)){ }

    ModInt& operator+=(ModInt that){
        value = value+that.value;
        if(value>=MOD)value-=MOD;
        return *this;
    }
    ModInt& operator-=(ModInt that){
        value -= that.value;
        if(value<0)value+=MOD;
        return *this;
    }
    ModInt& operator*=(ModInt that){
        value = (int)((long long)value * that.value % MOD);
        return *this;
    }
    ModInt &operator/=(ModInt that){
        return *this *= that.inverse();
    }
    ModInt operator+(ModInt that) const{
        return ModInt(*this)+=that;
    }
    ModInt operator-(ModInt that) const{
        return ModInt(*this)-=that;
    }
    ModInt operator*(ModInt that) const{
        return ModInt(*this)*=that;
    }
    ModInt operator/(ModInt that) const {
        return ModInt(*this) /= that;
    }
    ModInt operator^(long long k) const{
        if(value == 0)return 0;
        ModInt n = *this, res = 1;
        while(k){
            if(k & 1)res *= n;
            n *= n;
            k >>= 1;
        }
        return res;
    }
    ModInt inverse() const {
        long long a = value, b = MOD, u = 1, v = 0;
        while(b) {
            long long t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }
    int toi() const{ return value; }

private:
    int value;
};
typedef ModInt<1000000007> mint;
ostream& operator<<(ostream& os, const mint& x){
    os << x.toi();
    return os;
}

string nstr(){
    static const int MAX_LEN = 1000001;
    static char res_[MAX_LEN];
    scanf("%s",res_);
    return string(res_);
}

int N;
string S;

void solve(){
    vector<mint> cur(N + 1), nex(N + 1);
    cur[0] = 1;
    rep(i, N){
        fill(all(nex), mint());
        rep(j, N)nex[j + 1] += cur[j] * 2;
        for(int j = 1; j <= N; ++j)nex[j - 1] += cur[j];
        nex[0] += cur[0];
        swap(cur, nex);
    }

    const int M = sz(S);
    mint ans = cur[M] / (mint(2) ^ M);
    cout << ans << endl;
}

int main(){
    while(cin >> N){
        S = nstr();
        solve();
    }
}

Measured memory_bytes: 384
import bisect, copy, heapq, math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
abcde=[int(input()) for i in range(5)]
# print(n,abcde)

ans=4
for i in range(5):
    if min(abcde)==abcde[i]:
        ans+=math.ceil(n/abcde[i])
        break
print(ans)

Measured memory_bytes: 9724
import java.util.Scanner;
class Main{

	public void solve(){
    Scanner sc=new Scanner(System.in);
		
		int S=sc.nextInt();
		int h=S/3600;
		int m=(S-h*3600)/60;
		int s=S-h*3600-m*60;
		
		System.out.println(h+":"+m+":"+s);
	}
	public static void main(String[] args){
        Main obj =new Main();
        obj.solve();
    }
}

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

int main(){
  int n,i,c=0;
  string s;
  cin >> s;
  n=s.size();
  for(i=0;i<n;i++){
    if(s.at(i)=='0'+i%2){
      c++;
    }
  }
  
  cout << min(c,n-c) << endl;
} 

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(),(x).end()
#define lowbit(x) x&-x
#define pb push_back
#define ls (id<<1)
#define rs (id<<1|1)
#define Rint register int
#define UNI(x) sort(ALL(x)),x.resize(unique(ALL(x))-x.begin())
#define GETPOS(c,x) (lower_bound(ALL(c),x)-c.begin())
#define LEN(x) strlen(x)
#define MS0(x) memset((x),0,sizeof((x)))
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<pii> Vpii;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(ll &x) { scanf("%lld", &x); }
void _R(ull &x) { scanf("%llu", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const ll &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
const int MAXN=2e6+10,MAXM=4e6+10;
const int INF=INT_MAX,SINF=0x3f3f3f3f;
const ll llINF=LLONG_MAX;
const int MOD=1e9+7,mod=998244353;
const int inv2=5e8+4;
const int Lim=1<<20;

bool vis[MAXN];
void solve()
{
    int n,m;
    R(n,m);
    if(n&1)
    {
        for(int i=1;i<=m;i++)
        {
            int l=n/2-i+1,r=l+i*2-1;
            assert(!vis[r-l]);assert(!vis[l-r+n]);
            vis[r-l]=1;vis[l-r+n]=1;
            W(l,r);
        }
    }
    else
    {
        for(int i=1;i<=m;i++)
        {
            int p=n/4,l,r;
            if(i&1)
            {
                l=p-i/2,r=l+i;
            }
            else
            {
                r=n-p+i/2,l=r-i;
            }
            assert(!vis[r-l]);assert(!vis[l-r+n]);
            vis[r-l]=1;vis[l-r+n]=1;
            W(l,r);
        }
    }
}

int main()
{
    //freopen("in.txt","r",stdin);
    int t=1;
    //R(t);
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 4000
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
    string a;
    cin >> a;
	bool b = true;
    if(a[0] == '9' || a[1] == '9')
        cout << "Yes";
    else
        cout << "No";
}

Measured memory_bytes: 256
import time
import random

def calc(D, C, S, T):
    s = 0
    l = [-1] * len(C)
    for d, t in enumerate(T):
        s += S[d][t]
        s -= C[t] * (d - l[t]) * (d - l[t] - 1) // 2
        l[t] = d
    s -= sum(c * (d - l[i]) * (d - l[i] + 1) // 2 for i, c in enumerate(C))
    return s

def main():
    start = time.time()
    D = int(input())
    C = list(map(int, input().split()))
    S = [list(map(int, input().split())) for _ in range(D)]
    
    M = [0] * 26

    P = []
    
    for d in range(D):
        for i in range(26):
            M[i] += C[i]
        T = [m + s for m, s in zip(M, S[d])]
        i = T.index(max(T))
        M[i] = 0
        P.append(i)

    Sc = calc(D, C, S, P)
    while time.time() - start <= 1.8:
        d = random.randrange(D)
        q = random.randrange(26)
        if P[d] == q:
            continue
        old = P[d]
        P[d] = q
        Sn = calc(D, C, S, P)
        pe =(Sn - Sc) / (abs(Sc) if Sc != 0 else 1)
        if pe > 0 or random.uniform(0, 1) <= -pe / 5000:
            Sc = Sn
        else:
            P[d] = old
    return P

p = main()
print('\n'.join(str(i + 1) for i in p))


Measured memory_bytes: 81080
#include <iostream> 
#include <cstdio> 
#include <fstream> 
#include <algorithm> 
#include <cmath> 
#include <deque> 
#include <vector> 
#include <queue> 
#include <string> 
#include <cstring> 
#include <map> 
#include <stack> 
#include <set> 
using namespace std;
const int maxn = 1e3+7;
typedef long long ll;
int n,m;

set<int> s;
int main()
{
    ll n, a, b;
    scanf("%lld%lld%lld", &n, &a, &b);
    if(abs(a - b) % 2 == 0)printf("%lld\n", abs(a - b) / 2);
    else{
        printf("%lld\n", min((a + b - 2 + 1) / 2, (n + n - a - b + 1) / 2));
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>
#include <random>
#include <list>
#include <numeric>
#include <chrono>


#define rep(i,p,q) for(ll i = p;i < q;i++)
#define ll long long

using namespace std;

vector<vector<ll>> graph;
vector<ll> query;
vector<ll> ans;
vector<ll> visited;


const long long MAX_N = 1 << 17;

long long dat[2 * MAX_N - 1];

//141 D
int main(void) {
	ll n, m;
	cin >> n >> m;
	priority_queue<ll> pq = priority_queue<ll>();
	rep(i, 0, n) {
		ll a;
		cin >> a;
		pq.push(a);
	}
	if (n > 1) {
		while (m > 0) {
			ll f = pq.top();
			pq.pop();
			ll s = pq.top();
			for (ll count = 1; count <= m; count++) {
				ll newPrice = f / (ll)pow(2, count);
				if (newPrice <= s) {
					m -= count;
					pq.push(newPrice);
					break;
				}
				else if (count == m) {
					pq.push(newPrice);
					m = 0;
				}
			}
		}
	}
	else {
		ll f = pq.top();
		pq.pop();
		pq.push(f / (ll)pow(2, m));
	}
	
	ll ans = 0;
	while (pq.size() > 0) {
		ans += pq.top();
		pq.pop();
	}
	cout << ans << endl;
}


Measured memory_bytes: 1400
#include <iostream>

using namespace std;

int main()
{
    string str;
    cin>>str;
    int count = 0;
    for(int i = 0;i<str.length();i++)
    {
        if(str[i]=='1')
        {
            count+=1;
        }
        else if(str[i]=='2')
        {
            count+=2;
        }
        else if(str[i]=='3')
        {
            count+=3;
        }
        else if(str[i]=='4')
        {
            count+=4;
        }
        else if(str[i]=='5')
        {
            count+=5;
        }
        else if(str[i]=='6')
        {
            count+=6;
        }
        else if(str[i]=='7')
        {
            count+=7;
        }
        else if(str[i]=='8')
        {
            count+=8;
        }
        else if(str[i]=='9')
        {
            count+=9;
        }
    }
    if(count%9==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#define MOD 1000000007
typedef long long ll; 
ll dp[55][105], C[55][55]; 
int main()
{
	// freopen("AGC022-F.in", "r", stdin); 
	int n; 
	scanf("%d", &n); 
	for (int i = 0; i <= n; i++)
	{
		C[i][0] = 1; 
		for (int j = 1; j <= i; j++)
			C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD; 
	}
	dp[1][n] = dp[1][n - 1] = 1; 
	for (int i = 1; i <= n; i++)
	{
		for (int j = -i; j <= i; j++)
		{
			for (int a = 0; a < n; a++)
			{
				for (int b = 0; b < n; b++)
				{
					if (a + b && i + a + b <= n && ((j + a - b) & 1 ^ 1) && j <= a + b && -a - b <= j)
						(dp[i + a + b][(j + a - b) / 2 + n] += dp[i][j + n]
						 * C[i + a + b][a + b] % MOD * C[a + b][b]) %= MOD; 
				}
			}
		}
	}
	printf("%lld\n", dp[n][n]);
	return 0;
}


Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline()[:-1]


N, C, K = map(int, input().split())
T = [0]*N
for i in range(N):
    T[i] = int(input())
T.sort()

ans = 1
bus_time = T[0]
bus_num = 0
for i in range(N):
    if T[i] <= bus_time+K and bus_num < C:
        # 止まっているバスに乗る
        bus_num += 1
    else:
        # 新しいバスが必要
        bus_time = T[i]
        bus_num = 1
        ans += 1

print(ans)


Measured memory_bytes: 7468
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
using namespace std;
const int INF = 1000000000000;
const int mod = 1000000007;
int a[345678], first[345678], second[345678];
signed main() {
	int n, m, cnt = 1, ans = 0; cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> a[h];
	}
	for (int h = 0; h < n; h++) {
		if (h == 0) { ans += (a[h] - 1) / cnt; cnt++; }
		else if (cnt == a[h]) { cnt++; }
		else {
			ans += (a[h] - 1) / cnt;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)


void solve(long long X, long long A, long long B){
    X -= A;
    X %= B;
    cout << X << endl;
}

int main(){

    long long X;
    scanf("%lld",&X);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(X, A, B);
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i) = 0; (i) < (n); (i)++)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


int main() {
    int n, k, maxi = 0;
    cin >> n >> k;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
        maxi = max(maxi, a[i]);
    }

    int gcd_num = a[0];
    for(int i = 1; i < n; i++){
        gcd_num = gcd(gcd_num, a[i]);
    }
    cout << ((k % gcd_num || maxi < k) ? "IMPOSSIBLE\n" : "POSSIBLE\n");
}


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

public class Main {
	static int n, m;
	static int[] a, b;
	static int count = 0;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = Integer.parseInt(sc.next());
		a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());
		}
		m = Integer.parseInt(sc.next());
		b = new int[m];
		for (int i = 0; i < m; i++) {
			b[i] = Integer.parseInt(sc.next());
		}

		Arrays.sort(a);
		Arrays.sort(b);
		solve();
		System.out.println(count);
	}

	static void solve() {
		int l = 0;
		int r = n - 1;
		int t, at;

		for (int i = 0; i < m; i++) {
			t = b[i];
			at = search(l, r, t);
			if (at == -1)
				continue;
			count++;
			l = at = 1;
		}
	}

	static int search(int l, int r, int t) {
		while (l <= r) {
			int mid = (l + r) / 2;
			if (a[mid] == t)
				return t;
			if (a[mid] < t)
				return search(mid + 1, r, t);
			if (a[mid] > t)
				return search(l, mid - 1, t);
		}
		return -1;
	}
}



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

int mapa[300][300], sx,sy, t,counta;
typedef pair<int,int> P;

void bfs(){
  queue <P> Q;
  mapa[sx][sy]=1;
  Q.push(P(sx,sy));
  while(!Q.empty()){
    P p = Q.front();Q.pop();
    int x = p.first, y = p.second;
    counta++;
    if(mapa[x][y] == t) continue;
    for(int i = -1; i <= 1; i++){
      for(int j = -1; j <= 1; j++){
	if((i==-1&&j==1)||(i==1&&j==-1)||(i==0&&j==0))continue;
	int nx = x+i,ny = y+j;
	if(mapa[nx][ny] == 0){//cout<<nx<<" "<<ny<<endl;cout<<mapa[nx][ny]<<endl<<endl;
	  Q.push(P(nx,ny));
	  mapa[nx][ny] +=mapa[x][y]+1;
	}
      }
    }
  }
}


int main(){
  int n, x, y;
  while(1){
    cin>>t>>n;
    if(!t&&!n)break;
    t++;
    for(int i = 0; i < 300; i++)for(int j = 0; j < 300; j++)mapa[i][j] = 0;
    counta = 0;
    for(int i = 0; i < n; i++){
      cin>>x>>y;
      mapa[100+x][100+y] = -1;
    }
    cin>>sx>>sy;
    sx+=100; sy+=100;
    bfs();
    cout<<counta<<endl;
  }
  return 0;
}



Measured memory_bytes: 3468
import fractions
A, B, C, D = map(int, input().split())
cnt = 0
ac = (A-1) // C
bc = B // C
ad = (A-1) // D
bd = B // D
gcd_b = B // (C*D//fractions.gcd(C, D))
gcd_a = (A-1) // (C*D//fractions.gcd(C, D))
total = B - A + 1
a = bc - ac
b = bd - ad
gcdx = gcd_b - gcd_a

print(total-a-b+gcdx)


Measured memory_bytes: 5076
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
//#define mp make_pair
#define pb push_back
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdi pair<double, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head

const int N = 1e5 + 5;
int a[N], n;
LL pre[N], suf[N];
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	for (int i = 1; i <= n; ++i) pre[i] = __gcd(1LL*a[i], pre[i-1]);
	for (int i = n; i >= 1; --i) suf[i] = __gcd(1LL*a[i], suf[i+1]);
	LL ans = 0;
	for (int i = 1; i <= n; ++i) {
		ans = max(ans, __gcd(pre[i-1], suf[i+1]));
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2176
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

int daycnt(int y, int m, int d){
  ll res = 0; //1y1m1d
  if(m == 2)res += 31;
  else if(m == 3)res += 59;
  else if(m == 4)res += 90;
  else if(m == 5)res += 120;
  else if(m == 6)res += 151;
  else if(m == 7)res += 181;
  else if(m == 8)res += 212;
  else if(m == 9)res += 243;
  else if(m == 10)res += 273;
  else if(m == 11)res += 304;
  else if(m == 12)res += 334;
  if(m > 2 && y % 400 == 0)++res;
  else if(m > 2 && y % 100 != 0 && y % 4 == 0)++res;
  --y; res += y * 365 + y / 4 - y / 100 + y / 400;
  --d; res += d;
  return res;
}

signed main(void){
  int i, j;
  //pri(daycnt(1, 1, 1));
  for(int testcase = 0;testcase >= 0;testcase++){
    int y, m, d, x, l, c;
    scanf("%d%d%d%d%d%d", &y, &m, &d, &x, &l, &c);
    if(y < 0 || m < 0 || d < 0 || x < 0 || l < 0 || c < 0)break;

    pri(daycnt(x, l, c) - daycnt(y, m, d));

//*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3152
#include<stdio.h>
int main(void)
{
	int nisin[12],su[8]={128,64,32,16,8,4,2,1};
	double n,y;	int i;
	while(1){
		scanf("%lf",&n);
		if(n<0) break;
		else{
			for(i=0;i<12;i++) nisin[i]=0;
			if(n<256){
				for(i=0;i<8;i++){
					if(n>=su[i]){
						n-=su[i]; nisin[i]=1;
					}
				}
				if(n>0){
					y=0.5;
					for(i=8;i<12;i++){
//printf("y=%.4lf\n",y);
						if(n>=y){
							n-=y; nisin[i]=1;
						}
						y=y/2;
					}
				}
				if(n==0.0){
					for(i=0;i<12;i++){
						if(i==8) printf(".");
						printf("%d",nisin[i]);
					}
					printf("\n");
				}
				else printf("NA\n");
			}
			else printf("NA\n");
		}
		
	}
	return 0;
}


Measured memory_bytes: 2600
#include<stdio.h>
int main(){
	int a;
	int b;
	int c;
	int d;
	scanf("%d%d%d", &a, &b, &c);
	if(a > b){
		d = a;
		a = b;
		b = d;
	}
	if(b > c){
		d = b;
		b = c;
		c = d;
	}
	if(a > b){
		d = a;
		a = b;
		b = d;
	}
	printf("%d %d %d\n", a, b, c);
	return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define ll long long
#define lsb(x) (x & (-x))


using namespace std;




int main() {
    //fstream cin("A.in");
    //ofstream cout("A.out");
    int n, m;
    ios::sync_with_stdio(false);
    cin >> n >> m;
    cout << (1900 * m + 100 * (n - m)) * (1 << m);
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int par[100003],sz[100003];
int find(int v)
{
  if(par[v]==v)
    return v;
  return par[v]=find(par[v]);
}
void union_set(int u,int v)
{
  u=find(u);
  v=find(v);
  if(u!=v)
  {
    if(sz[u]<sz[v])
      swap(u,v);
    par[v]=u;
    sz[u]+=sz[v];
  }
}
int main()
{
  int n,m,k;
  cin>>n>>m>>k;
  int a[n+1];
  int b[n+1];
  memset(a,0,sizeof(a));
  memset(b,0,sizeof(b));
  int u,v;
  for(int i=1;i<=n;i++)
  {
    par[i]=i;
    sz[i]=1;
  }
  for(int i=0;i<m;i++)
  {
    cin>>u>>v;
    a[u]++;
    a[v]++;
    union_set(u,v);
  }
  //u=find(u);
  for(int i=0;i<k;i++)
  {
    cin>>u>>v;
    if(find(u)==find(v))
        b[u]++,b[v]++;
  }
  for(int i=1;i<=n;i++)
  {
    int ans=sz[find(i)]-1-a[i]-b[i];
    cout<<ans<<" ";
  }
  cout<<"\n";
  return 0;
}


Measured memory_bytes: 2432
#include <stdio.h>
#include <algorithm>

#define LIM_S 200002
#define LIM_N 200001

char str[LIM_S];

int R, G, B, N;
int A[LIM_N];

void receive_input() {
	fgets(str, sizeof(str), stdin);
	sscanf(str, "%d %d %d %d", &R, &G, &B, &N);
}

void initialize() {
}

int main(void) {
	receive_input();
	initialize();

	int r, g, b;
	int ans = 0;

	for (r = N/R; 0 <= r; r--) {
		for (g = N/G; 0 <= g; g--) {
			int x = N - (r*R+g*G);
			int b = x / B;
			if (x >= 0 && x % B == 0) {
				// printf("%d %d %d :%d\n", r, g, b, x);
				ans++;
			}
		}
	}

	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)

    val w, h, n = sc.nextInt()
    var up = h
    var down = 0
    var left = 0
    var right = w

    for (i <- 0 until n) {
      val x, y, a = sc.nextInt()
      a match {
        case 1 => left = math.max(left, x)
        case 2 => right = math.min(right, x)
        case 3 => down = math.max(down, y)
        case 4 => up = math.min(up, y)
      }
    }

    val width = math.max(0, right - left)
    val height = math.max(0, up - down)

    println(width * height)

  }
  def debug(args: Any*): Unit = {
    Console.err.println(args.mkString(" "))
  }
}


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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)
// while (getline(cin, S)) {}

// cout <<fixed <<setprecision(10)

// priority_queue<int> q;
// priority_queue<int, vector<int>, less<int>> q; // Default: vector, less
// priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

//
// Notes
//
// When specified less than N, try full scan.
// RE: empty vector
// Check Qs
// long/int
// xor -> count each bit
// Check values
// 	1,000,000 -> Loop
// 	100,000	-> vector(int:400KB, long:800KB) 

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (int i=0; i<n; i++)
#define	Rep1(i, n)	for (int i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	int N, M;
	cin >>N >>M;
	vector<vector<int>> A(N+1);
	if (M>0)
		Rep0(i, M) {
			int u, v;
			cin >>u >>v;
			A.at(u).push_back(v);
		}
	int S, T;
	cin >>S >>T;
	vector<vector<int>> B(N+1, vector<int> (3, INF));
	list<vector<int>> q;
	q.push_back({S, 0});
	B.at(S).at(0)=0;
	while (!q.empty()) {
		int Node=q.front().at(0);
		int Step=q.front().at(1);
		q.pop_front();
		Step++;
		int s=Step%3;
		if (0<A.at(Node).size())
			Rep0(i, A.at(Node).size()) {
				int TT=A.at(Node).at(i);
				if (B.at(TT).at(s)>Step) {
					B.at(TT).at(s)=Step;
					q.push_back({TT, Step});
				}
			}
		if (B.at(T).at(0)<INF) {
			cout <<B.at(T).at(0)/3 <<endl;
			return 0;
		}
	}
	cout <<-1 <<endl;
	return 0;
}



Measured memory_bytes: 11136
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N; cin >> N;
    deque<int> dq;
    rep(i,N){
        int a; cin >> a;
        if(i%2==0){
            dq.push_back(a);
        } else {
            dq.push_front(a);
        }
    }
    if(N%2) reverse(all(dq));
    rep(i,N){
        cout << dq[i] << endl;
    }
}

Measured memory_bytes: 3840
n = int(input())
s = input()
n = len(s)
white = [0]
for i, si in enumerate(s, 1):
    white.append(white[-1] + (1 if si == '.' else 0))

ans = n
for i in range(n + 1):
    # print(i, (i - white[i]) + (white[n] - white[i]))
    ans = min((i - white[i]) + (white[n] - white[i]), ans)

print(ans)


Measured memory_bytes: 11140
#include<iostream>

using namespace std;

int main()
{
	int K, S;
	
	cin >> K >> S;
	
	int count = 0;
	for(int i = 0; i <= K; i++){
		for(int j = 0; j <= K; j++){
			int k = S - i - j;
			if(k >= 0 && k <= K){
				count++;
			}
		}
	}
	
	cout << count;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var n=sc.I;
		var a=sc.Ia;
		var dp=new long[n];
		dp[0]=1000;
		for(int i = 1;i<n;i++) {
			dp[i]=dp[i-1];
			for(int j = 0;j<i;j++) {
				long p=dp[j]/a[j];
				dp[i]=Max(dp[i],dp[j]-p*a[j]+p*a[i]);
			}
		}
		Console.WriteLine("{0}",dp[n-1]);
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),int.Parse);}
	public int[] Ia3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),long.Parse);}
	public long[] La3(int a){return Array.ConvertAll((Console.ReadLine()+" "+a.ToString()).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(string a,string b){return Array.ConvertAll((a+Console.ReadLine()+b).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 27552
N, H = map(int, input().split(' '))
powers = []
for _ in range(N):
    a, b = map(int, input().split(' '))
    powers.extend([[a, True], [b, False]])

powers.sort(key=lambda x: -x[0])

import math
ans = 0
for power, is_a in powers:
    if H <= 0:
        break
    else:
        if is_a:
            ans += int(math.ceil(H/power))
            break
        else:
            H -= power
            ans += 1
print(ans)

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

int main(){
    int N,X;
    cin >> N >> X;
    int MIN = 1001;
    for (int i = 0; i < N; i++)
    {
        int m;
        cin >> m;
        X -= m;
        if(MIN > m) MIN = m;
    }
    cout << N + X/MIN << endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np


H, W = map(int, input().split())
S = np.ones((H, W), dtype=np.bool)
for i in range(H):
    S[i] = [s == "." for s in input()]

up = np.zeros((H, W), dtype=np.int16)
down = np.zeros((H, W), dtype=np.int16)
left = np.zeros((H, W), dtype=np.int16)
right = np.zeros((H, W), dtype=np.int16)

# up
up[0, :] = S[0, :]
for h in range(1, H):
    up[h, :] = up[h - 1, :] + 1
    up[h, :] *= S[h, :]

# down
down[H - 1, :] = S[H - 1, :]
for h in reversed(range(0, H - 1)):
    down[h, :] = down[h + 1, :] + 1
    down[h, :] *= S[h, :]

# left
left[:, 0] = S[:, 0]
for w in range(1, W):
    left[:, w] = left[:, w - 1] + 1
    left[:, w] *= S[:, w]

# right
right[:, W - 1] = S[:, W - 1]
for w in reversed(range(0, W - 1)):
    right[:, w] = right[:, w + 1] + 1
    right[:, w] *= S[:, w]

ans = np.max(up + down + left + right - 3)
print(ans)


Measured memory_bytes: 63204
loop do
  n = gets.chomp.to_i
  row_count = gets.chomp.to_i

  break if n == 0 && row_count == 0

  pairs = row_count.times.map { gets.chomp.split(' ').map(&:to_i) }

  friends, others = pairs.partition { |pair| pair[0] == 1 }
  friends = friends.map(&:last)
  foaf = others.inject([]) do |pairs, pair|
      pairs << pair[1] if friends.include?(pair[0])
      pairs << pair[0] if friends.include?(pair[1])
      pairs
    end

  puts (friends | foaf).uniq.size
end

Measured memory_bytes: 9000
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=pow(10,9)+7

h,w=map(int,input().split())
s=[input() for i in range(h)]
d=[[1,0],[0,1],[-1,0],[0,-1]]

whitecnt=0
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            whitecnt+=1
grid=[[0]*w for i in range(h)]
grid[0][0]=1
q=deque([[0,0,1]])
while q:
    x,y,dist=q.popleft()
    for xd, yd in d:
        if 0<=x+xd<w and 0<=y+yd<h and grid[y+yd][x+xd]==0 and s[y+yd][x+xd]==".":
            if x+xd==w-1 and y+yd==h-1:
                print(whitecnt-(dist+1))
                exit()
            # print(x+xd,y+yd)

            grid[y+yd][x+xd]=1
            q.append([x+xd,y+yd,dist+1])
# print(grid)
print(-1)


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

#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define forv(i,v) for (auto i = v.begin(); i != v.end(); ++i)
#define forr(i,v) for (auto i = v.end(); i != v.begin() && (--i, 1); )
#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

const ld pi = 3.1415926535897932384626433832795l;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T> inline T abs (T x) {return x > T() ? x : -x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

const int N = 200100;
int p[N];
int sz[N];
int rnd;

int get(int a) {
	if (a == p[a]) {
		return a;
	}
	return p[a] = get(p[a]);
}

void uni(int l, int r) {
	l = get(l), r = get(r);
	if (l == r) {
		return;
	}
	if (rnd ^= 1) {
		swap(l, r);
	}
	p[l] = r;
	sz[r] += sz[l];
}

bool use[N];

int main () {
	//std::ios::sync_with_stdio(false);
    //std::cin.tie(nullptr);
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
	rnd = 1;                                                                                                         
	ll n, m, q;
	cin >> n >> m >> q;
	bool is_two = false;
	bool ok = true;
	forn(i, n) {
		p[i] = i;
		sz[i] = 1;
	}
	ve<pii> e;
	forn(i, q) {
		int u, v, type;
		cin >> u >> v >> type;
		if (type == 0) {
			uni(u, v);
		}
		if (type == 1) {
			is_two = true;
			e.pb(mp(u, v));
		}
	}
	for (auto edge : e) {
		if (get(edge.fs) == get(edge.sc)) {
			ok = false;
			break;
		}
	}
	int cmp_count = 0;		
	memset(use, 0, sizeof(use));
	forn(i, n) {
		int root = get(i);
		if (use[root]) {
			continue;
		}
		use[root] = 1;
		cmp_count++;
	}
	if (is_two && cmp_count < 3) {
		ok = false;
	}
	if (is_two && m == n - 1) {
		ok = false;
	}
	if (m > n - cmp_count + 1ll * cmp_count * (cmp_count - 1) / 2) {
		ok = false;
	}
	if (ok) {
		puts("Yes");
	} else {
		puts("No");
	}
	return 0;
}


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

const string INF =  "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ";

string s, t;
string res = "UNRESTORABLE";

int main(){
  cin >> s >> t;
  int sl = s.length(), tl = t.length();
  
  string ans;
  rep(i, sl){
    string tmp = s;
    if(i > sl - tl) break;
    
    //sにtを入れることができたなら、tmpに記録する
    bool flag = true;
    rep(j, tl){
      if(s.at(i + j) != t.at(j) && s.at(i + j) != '?'){
        flag = false;
        break;
      }
      tmp.at(i + j) = t.at(j);
    }
    if(!flag) continue;
    rep(i, sl)if(tmp.at(i) == '?')tmp.at(i) = 'a';
    //if(flag)cout << tmp << endl;
    
    //resが初期状態のときのみtmpをそのまま記録
    if(res == "UNRESTORABLE"){
      res = tmp;
    }
    
    //tmpとansを比較し、より小さい方をansに記録
    if(res > tmp){
      res = tmp;
    }
  }
  //if(!(ans == INF)) res = ans;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

const LLONG GCM(const LLONG a, const LLONG b)
{
    if (b == 0) return a;
    return GCM(b, a % b);
}

// 素因数分解:O(sqrt(N))
const map<LLONG, LLONG> PrimeFactorize(LLONG N)
{
    map<LLONG, LLONG> prime2NumMap;
    for (LLONG p = 2; p * p <= N; ++p)
    {
        if (N % p != 0) continue;
        while (N % p == 0)
        {
            N /= p;
            ++prime2NumMap[p];
        }
    }
    if (N != 1) prime2NumMap[N] = 1;
    return prime2NumMap;
}

int main()
{
	int N; cin >> N;
	vector<LLONG> as(N); REP(i, N) cin >> as[i];
	sort(as.begin(), as.end(), greater<LLONG>());
	// pairwise coprime かどうかは，同じ素因数を持つかどうかチェックすればよい
	set<int> primeSet;
	bool noPairwise = false;
	for(const auto ai : as)
	{
		const auto primes = PrimeFactorize(ai);
		for (const auto &kvp : primes)
		{
			const LLONG p = kvp.first;
			if (primeSet.count(p))
			{
				noPairwise = true; break;
			}
			primeSet.insert(p);
		}
		if (noPairwise) break;
	}
	if (noPairwise)
	{
		// setwise coprime かどうかは，O(N)で計算可能
		LLONG gcd = as.front();
		for (int i = 1; i < N; ++i)
		{
			gcd = GCM(gcd, as[i]);
		}
		if (gcd == 1)
		{
			cout << "setwise coprime" << endl;
		}
		else
		{
			cout << "not coprime" << endl;
		}
	}
	else
	{
		cout << "pairwise coprime" << endl;
	}
}


Measured memory_bytes: 11132
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define Mod 998244353
#define pi 3.14159265358979323846
#define endl '\n'
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<char> vc;

int main()
{
    int n,k;
    cin>>n>>k;
    vll a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    vll pro(n+1);
    pro[0]=0;
    for(int i=1;i<=n;i++) pro[i]=pro[i-1]+a[i-1];

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


Measured memory_bytes: 6348
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	ll a, b;

	cin >> a >> b;

	if (a * b % 2 == 0) {
		cout << "Even" << endl;
	}
	else {
		cout << "Odd" << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>

main()
{
	int a,b;
	char op;
	
	while(1){
		scanf("%d %c %d",&a,&op,&b);
		if(op== '+'){
			printf("%d\n",a+b);
		}
		else if(op== '-'){
			printf("%d\n",a-b);
		}
		else if(op== '*'){
			printf("%d\n",a*b);
		}
		else if(op== '/'){
			printf("%d\n",a/b);
		}
		else{
			break;
		}
	}
	return 0;
	
}

Measured memory_bytes: 600
#include <stdio.h>

int maxi(int a,int b){if(a>b){return a;}return b;}

int main(void){
  int a, b, c, max, i;
  int k;
  int ans = 0;
  scanf("%d%d%d", &a, &b, &c);
  scanf("%d", &k);
  
  max = maxi(a, maxi(b, c));
  ans = a + b + c - max;
  for(i = 0; i < k; i++){
    max *= 2;
  }
  ans += max;
  printf("%d\n", ans);
  return 0;
}

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

class UnionFind {
	vector<int> data;
	int root(int a) {
		return data[a] < 0 ? a : data[a] = root(data[a]);
	}
public:
	UnionFind(int n) : data(n, -1) {}
	bool Find(int a, int b) {
		return root(a) == root(b);
	}
	void Union(int a, int b) {
		int ra = root(a), rb = root(b);
		if (ra == rb) return;
		if (data[ra] < data[rb]) {
			data[ra] += data[rb];
			data[rb] = a;
		}
		else {
			data[rb] += data[ra];
			data[ra] = b;
		}
	}
	int size(int a) {
		return -data[root(a)];
	}
};

int main()
{
	int N, M;
	cin >> N >> M;
	UnionFind uf(N + M);
	for (int i = 0, K, l; i < N; i++) {
		cin >> K;
		for (int j = 0; j < K; j++) {
			cin >> l;
			uf.Union(i, N + l - 1);
		}
	}
	bool res = true;
	for (int i = 1; i < N; i++) {
		if (!uf.Find(0, i)) {
			res = false;
			break;
		}
	}
	cout << (res ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

long long aaa(long long, long long);
long long t[100] = {};

int main()
{
	int n;
	long long ans;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%lld", &t[i]);
	}
	ans = t[0];
	for (int i = 0; i < n - 1; i++)
	{
		ans = aaa(ans, t[i + 1]);
	}
	printf("%lld", ans);
	return 0;
}

long long aaa(long long x, long long y)
{
	long long r, r1, x1, y1;
	if (x < y)
	{
		x1 = y;
		y1 = x;
	}
	else
	{
		x1 = x;
		y1 = y;
	}
	r = x1 % y1;
	while (r != 0)
	{
		x1 = y1;
		y1 = r;
		r = x1 % y1;
	}
	r1 = x * (y / y1);
	return r1;
}

Measured memory_bytes: 128
package main

import "fmt"

func main() {
	var s []byte
	fmt.Scan(&s)

	m := make(map[string]int, len(s))
	for _, v := range s {
		m[string(v)]++
	}

	cnt := 0
	for _, v := range m {
		if v == 2 {
			cnt++
		}
	}

	if cnt == 2 {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")


}


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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    ll n,m,sum=0;
    cin >> n >> m;
    vector<P> p(n);
    rep(i,n){
        ll a,b;
        cin >> a >>b;
        p[i] = make_pair(a,b);
    }
    sort(all(p));
    rep(i,n){
        sum += min(m,p[i].second)*p[i].first;
        m -= min(m,p[i].second);
        if(m == 0){
            cout << sum << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define REP(i,n) for (int i = 0; i < n; ++ i)
#define FOR(i,a,b) for (int i = a; i <= b; ++ i)
#define FORD(i,b,a) for (int i = b; i >= a; -- i)
#define debug(x) cerr << #x << ": " << x << "\n"
#define task ""
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> li;
typedef vector<int> vi;

int n, k;
long long res;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	//freopen(task".inp", "r", stdin);
	//freopen(task".out", "w", stdout);
	cin >> n >> k;
	FOR(b, k+1, n) {
		res += 1LL * n / b * (b - k);
		if (n % b >= k) res += n % b - k + 1;
	} 	
	if (k == 0) res -= n - k;
	cout << res;
}


Measured memory_bytes: 256
#include <cstddef>
#include <complex>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>

using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
    using namespace std;

    int n;
    cin >> n;
    vec<int> v(n);
    for (auto &e : v)
    {
        cin >> e;
    }
    sort(v.begin(), v.end());

    int m{};

    for (int i = 0; i < n - 1; ++i)
    {
        if (m <= min(v[i], v.back() - v[i]))
        {
            m = v[i];
        }
    }

    cout << v.back() << " " << m << endl;

    return 0;
}

Measured memory_bytes: 640