akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <functional>
using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;
ll dp[101][4][4][4];

int main() {
  int N;
  cin>>N;
  int A,G,C;
  A = 0;
  G = 1;
  C = 2;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      for (int k = 0; k < 4; k++) {
        if (i == A && j == G && k == C) continue;
        if (i == G && j == A && k == C) continue;
        if (i == A && j == C && k == G) continue;
        dp[3][i][j][k] = 1;
      }
    }
  }
  for (int i = 3; i < N; i++) {
    for (int j = 0; j < 4; j++) {
      for (int k = 0; k < 4; k++) {
        for (int l = 0; l < 4; l++) {
          for (int m = 0; m < 4; m++) {
            if (k == A && l == G && m == C) continue;
            if (k == G && l == A && m == C) continue;
            if (k == A && l == C && m == G) continue;
            if (j == A && l == G && m == C) continue;
            if (j == A && k == G && m == C) continue;
            dp[i+1][k][l][m] += dp[i][j][k][l];
            dp[i+1][k][l][m] %= MOD;
          }
        }
      }
    }
  }
  ll ans;
  ans = 0;
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      for (int k = 0; k < 4; k++) {
        ans += dp[N][i][j][k];
        ans %= MOD;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

// cond: a>b
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int main()
{
  int n,k;
  cin>>n>>k;
  int g = 0;
  int m = 0;
  REP(i,n) {
    int a;
    cin>>a;
    m = max(m, a);
    if (a < g) swap(a, g);
    g = gcd(a,g);
  }

  if ((k % g) == 0) {
    if (k <= m) {
      cout << "POSSIBLE" << endl;
    } else {
      cout << "IMPOSSIBLE" << endl;
    }
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
  return 0;
}


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

typedef long long ll; 

int main(){
        ll h,w,n; cin>>h>>w>>n; 
        map<pair<int,int>,ll> m; 
        while(n--) {
                int a,b; cin>>a>>b; for(int i=0;i<3;i++){ for(int j=0;j<3;j++) { m[make_pair(a-i,b-j)]++; } }
        }
        vector<ll> ans(10,0); 
        for(auto it=m.begin();it!=m.end();it++){
                pair<int,int> p=it->first; 
                if(p.first>=1 && p.first<=h-2 && p.second>=1 && p.second <= w-2) {
                        ans[it->second]++; 
                }
        }
        ll sum=0; for(int i=1;i<10;i++) sum+=ans[i]; 
        ans[0]=(h-2)*(w-2)-sum; 
        for(int i=0;i<10;i++){
                cout<<ans[i]<<endl; 
        }
	return 0; 
}



Measured memory_bytes: 56576
#include<bits/stdc++.h>
#define mod 1000000007
#define int long long int
#define phi 1.6180339
#define rep(i,n) for(auto i=0;i<(n);i++)
#define endl "\n"
#define For(i,a,b) for(auto i=(a);i<(b);i++)
#define op1 cin.tie(NULL)
#define op2 cout.tie(NULL)
#define op3 std::ios_base::sync_with_stdio(false)
#define MAXX 1000001
using namespace std;
vector<int> arr(MAXX);
void trozen()
{
    int x,y,z;
    cin>>x>>y>>z;
    int temp=x;
    x=y;
    y=temp;
    temp=x;
    x=z;
    z=temp;
    cout<<x<<" "<<y<<" "<<z<<endl;
}
int32_t main()
{
    op1;op2;op3;
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    trozen();
    return 0;
}


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

ll lcm(ll a, ll b) {
  ll g = gcd(a,b);
  return (a/g)*(b/g)*g;
}

int main(){
  int x;
  cin >> x;
  int y = lcm(x,360);
  cout << y/x << endl;
  return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){

	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int N,D,i;
	string x,a;
	cin >> N >> x >> D;
	int zero=0;
	REP(i,N) if(x[i]=='0') zero++;
	if(D==0){
		cout << x << endl;
		return 0;
	}

	if(D>zero){
	D-=zero;
	a=x;
	for(i=0;i<N;i++){
		if(x[i]=='0'){
			a[i]='1';
			zero--;
			if(zero==0) break;
		}
	}

	for(i=N-1;i>=0;i--){
		if(x[i]=='1'){
			a[i]='0';
			D--;
			if(D==0) break;
		}
	}

	cout << a << endl;

	}else{

		a=x;
		REP(i,N){
			if(x[i]=='0'){
				a[i]='1';
				D--;
				if(D==0) break;
			}
		}

		cout << a << endl;
	}



	return 0;
}

Measured memory_bytes: 1208
object Main{
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val str : String = sc.next
    val reds = str.toList.count(_ == 'R')
    if(reds > n-reds){
      println("Yes")
    }
    else{
      println("No")
    }
  }
}

Measured memory_bytes: 27296
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int a=0;
    string S;
    cin >> S;
    if (S.size()%2 == 1){
        for(int i = 1; i <= S.size()/2; i++){
            if(S[i-1] != S[S.size()-i]) a++;
        }
    }
    else {
        for(int i = 1; i <= S.size()/2; i++){
            if(S[i-1] != S[S.size()-i]) a++;
        }
    }
    cout<< a <<endl;
    
}

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

signed main() {
	int x; cin >> x;
	int res = 1;
	for (int i = 2; i <= 32; i++) {
		for (int j = 2; pow(i, j) <= x; j++) {
			res = max(res,(int) pow(i, j));
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 640
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] l = new int[n];
		for(int i = 0; i < n; i++){
		    l[i] = sc.nextInt();
		}

		// 計算
	    int result = 0;
	    Arrays.sort(l);
	    for(int i = 0; i < n; i++){
		    for(int j = i + 1; j < n; j++){
		        for(int k = j + 1; k < n; k++){
		            if(l[k] - l[j] < l[i]){
		                result++;
		            }else{
		                break;
		            }
		        }
		    }
		}

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


Measured memory_bytes: 28016
N, M = [int(i) for i in input().split()]
E = [[] for _ in range(3 * N)]
for _ in range(M):
    u, v = [int(i) - 1 for i in input().split()]
    E[3 * u].append(3 * v + 1)
    E[3 * u + 1].append(3 * v + 2)
    E[3 * u + 2].append(3 * v)
S, T = [3 * (int(i) - 1) for i in input().split()]

from collections import deque
Q = deque()
Q.append((S, 0))

visited = [False] * (3 * N)
visited[S] = True

ans = -1
while Q:
    a, d = Q.popleft()
    if a == T:
        ans = d
        break
    for b in E[a]:
        if not visited[b]:
            Q.append((b, d + 1))
            visited[b] = True

if ans % 3 == 0:
    print(ans // 3)
else:
    print(-1)


Measured memory_bytes: 50608
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
	int N,K;
	char A;
	string S;
	cin >> N >> S >> K;
	K--;
	string SS;
	A = S[K];
	for (int i = 0; i < N; i++) {
		if (S[i] == S[K]) {
			SS.push_back(A);
		}
		else SS.push_back('*');
	}
	cout << SS << endl;
}

Measured memory_bytes: 256
//AOJ0279

#include <iostream>
using namespace std;

int main(){
  while(true){
    int N;
    cin >> N;

    if(N==0)
      break;

    int cnt0 = 0;
    int cnt1 = 0;

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

      if(k==0){
        cnt0++;
      }
      else if(k==1){
        cnt1++;
      }
    }

    if(cnt0+cnt1==N){
      cout << "NA" << endl;
    }
    else{
      cout << N-cnt0+1 << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
int x[200000],y[200000],n;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>x[i]>>y[i];
	int i1=0,i2=0,i3=0,i4=0,m1x=x[0],m1y=y[0],m2x=x[0],m2y=y[0],m3x=x[0],m3y=y[0],m4x=x[0],m4y=y[0];
	for(int i=1;i<n;i++){
		if(x[i]+y[i]>m1x+m1y){
			i1=i;
			m1x=x[i];
			m1y=y[i];
		}
		if(x[i]+y[i]<m2x+m2y){
			i2=i;
			m2x=x[i];
			m2y=y[i];
		}
		if(x[i]-y[i]>m3x-m3y){
			i3=i;
			m3x=x[i];
			m3y=y[i];
		}
		if(x[i]-y[i]<m4x-m4y){
			i4=i;
			m4x=x[i];
			m4y=y[i];
		}
	}
	int r1=0,r2=0,r3=0,r4=0;
	if(i1!=i2)
		r1=abs(m1x-m2x)+abs(m1y-m2y);
	if(i3!=i4)
		r2=abs(m3x-m4x)+abs(m3y-m4y);
	cout<<max(r1,r2);
	return 0;
}

Measured memory_bytes: 5212
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main(){
  int N;cin>>N;
  int L[(N*2)+10];
  for(int i=0;i<N*2;i++)cin>>L[i];
  sort(L,L+(N*2));
  int ans=0;
  for(int i=0;i<N*2;i+=2)ans+=L[i];
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int d[11][11];
  int n,s,i,j;
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    for(i=0;i<n;i++){
      s=0;
      for(j=0;j<n;j++){
	scanf("%d",&d[i][j]);
	s+=d[i][j];
      }
      d[i][n]=s;
    }
    for(i=0;i<=n;i++){
      s=0;
      for(j=0;j<n;j++){
	s+=d[j][i];
      }
      d[n][i]=s;
    }
    for(i=0;i<=n;i++){
      for(j=0;j<=n;j++){
	printf("%5d",d[i][j]);
      }
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n;
  cin>>n;
  vector<int> counter(n,0);
  int a;
  REP(i,n){
    cin>>a;
    counter[a]++;
  }
  long long ans=1;
  if(n%2==1){
    REP(i,n){
      if(i%2==0){
        if(counter[i]==2 && i!=0){
          continue;
        }else if(counter[i]==1 && i==0){
          continue;
        }else{
          cout<<0<<endl;
          return 0;
        }
      }else{
        if(counter[i]==0){
          continue;
        }else{
          cout<<0<<endl;
          return 0;
        }
      }
    }
    REP(i,(n-1)/2){
      ans = mod(ans*2);
    }
    cout<<ans<<endl;
  }else{
    REP(i,n){
      if(i%2==1){
        if(counter[i]==2){
          continue;
        }else{
          cout<<0<<endl;
          return 0;
        }
      }else{
        if(counter[i]==0){
          continue;
        }else{
          cout<<0<<endl;
          return 0;
        }
      }
    }
    REP(i,n/2){
      ans = mod(ans*2);
    }
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long S, W;
    cin >> S >> W;
    if(W >= S) cout << "unsafe" << endl;
    else cout << "safe" << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3652
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    P = [int(p) for p in input().split()]
    count = 0
    now = 0
    while now < N:
        if P[now] == now + 1:
            count += 1
            if now < N - 1:
                if P[now + 1] == now + 2: now += 1
        now += 1
    print(count)
   

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 13876
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static Dictionary<int, int> dic;

    static object process(TextReader input) {
        var spl = input.ReadLine().Split(' ');
        var sx = int.Parse(spl[0]);
        var sy = int.Parse(spl[1]);
        var tx = int.Parse(spl[2]);
        var ty = int.Parse(spl[3]);

        StringBuilder sb = new StringBuilder();
        Action<char, int> repeat = (c, k) => {
            for(int i=0; i<k; i++) sb.Append(c);
        };

        var xl = Math.Abs(sx - tx);
        var yl = Math.Abs(sy - ty);

        //go
        repeat('R', xl);
        repeat('U', yl);
        
        //back
        repeat('L', xl);
        repeat('D', yl);
        
        //go
        repeat('D', 1);
        repeat('R', xl+1);
        repeat('U', yl+1);
        repeat('L', 1);

        //back
        repeat('U', 1);
        repeat('L', xl + 1);
        repeat('D', yl + 1);
        repeat('R', 1);

        if (sx > tx) {
            for(int i=0; i<sb.Length; i++) {
                if(sb[i] == 'R') sb[i] = 'L';
                else if(sb[i] == 'L') sb[i] = 'R';
            }
        }
        if (sy > ty) {
            for (int i = 0; i < sb.Length; i++) {
                if (sb[i] == 'U') sb[i] = 'D';
                else if (sb[i] == 'D') sb[i] = 'U';
            }
        }

        return sb;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


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

#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)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) {
    cin >> a.at(i);
  }
  int res;
  if (n <= k) {
    res = 1;
  } else {
    res = ceil((double) (n - 1) / (k - 1));
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3804
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <stdio.h>
#define   FOR(i,n) for(int i=0;i<n;i++)

using namespace std;
int int_sort(const void*a,const void *b) {
    return *(  int *) b - *(int *) a;
    //qsort(b, a, sizeof(long long int), int_sort);
}

template<typename T>
istream& operator >>(istream& is, vector<T>& vec){
    for(T& x: vec) is >>x;
    return is;
}
int main() {
    int a,b;



    cin>>a>>b;
	if((a+b)%2==0){
		cout<<(a+b)/2;
		return 0;
	}
	else{
		cout<<(a+b+1)/2;
		return 0;
	}


    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define min(x,y) ((x)<(y)?(x):(y))
#define max(x,y) ((x)>(y)?(x):(y))
#define ll long long
using namespace std;
const int maxn=1e5+5;
int fi[maxn],dui[maxn*2],ne[maxn*2],qc[maxn],dui1[maxn*2];
ll de[maxn],ans,mi;
int size[maxn];
int i,j,k,l,m,n,x,y,z,c1,c2,now;

void add(int x,int y,int z){
    if (fi[x]==0) fi[x]=++now; else ne[qc[x]]=++now;
    dui[now]=y; dui1[now]=z; qc[x]=now;
}
void dfs_size(int x,int y){
    size[x]=1;
    for(int i=fi[x];i;i=ne[i]){
        if (dui[i]==y) continue;
        dfs_size(dui[i],x);
        size[x]=size[x]+size[dui[i]];
    }
}
void dfs_root(int x,int y){
    int z=size[1]-size[x];
    for(int i=fi[x];i;i=ne[i]){
        if (dui[i]==y) continue;
        z=max(z,size[dui[i]]);
        dfs_root(dui[i],x);
    }
    if (z<l){
        l=z; c1=x; c2=0;
    } else if (z==l) c2=x;
}
void dfs_dep(int x,int y){
    for(int i=fi[x];i;i=ne[i]){
        if (dui[i]==y) continue;
        de[dui[i]]=de[x]+dui1[i];
        dfs_dep(dui[i],x);
    }
    ans=ans+de[x]+de[x];
}
int main(){
    scanf("%d",&n);
    fo(i,1,n-1){
        scanf("%d%d%d",&x,&y,&z);
        add(x,y,z); add(y,x,z);
    }
    dfs_size(1,0);
    l=n+1;
    dfs_root(1,0);
    dfs_dep(c1,0);
    if (c2==0){
        mi=1e16;
        fo(i,1,n) if (i!=c1) mi=min(mi,de[i]);
    } else mi=de[c2];
    printf("%lld\n",ans-mi);
    return 0;
}

Measured memory_bytes: 8576
a,b,c,d=map(int,input().split())
 
n=4
x=[a,b,c,d]

for j in range(n-1,1,-1):
    for i in range(j):
        if x[i]>x[i+1]:
            x[i], x[i+1] = x[i+1], x[i]
            
if x[0]==x[1] and x[2]==x[3]:
    print('yes')
else:
    print('no')


Measured memory_bytes: 5600
#include <iostream>
#include <cmath>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
int main(void) {
    ll i, n;
    cin >> n;
    ll t;
    vector<ll> a;
    for(i=0; i<n; i++) {
        scanf("%lld", &t);
        a.push_back(t);
    }
    sort(a.begin(), a.end());
    ll mx=a[n-1];
    ll mi=mx, tmp=-1;
    for(i=0; i<n; i++) {
        if(mi>=abs(mx/2-a[i]) && mx!=a[i]) {
            mi = abs(mx/2-a[i]);
            tmp = a[i];
        }
        
    }
    cout << mx << ' ' << tmp << endl;
}


Measured memory_bytes: 1400
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef double ld;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}
template <class T>
vector<ll> countVector(vector<T>v,T guard=0){
    ll size=v.size();
    v.push_back(guard);
    vector<ll>ret;
    ll count=1;
    for(int i=0;i<size;i++){
        if(v[i]==v[i+1]){
            count++;
        }else{
            ret.push_back(count);
            count=1;
        }
    }
    return ret;
}
ll gcd(ll a,ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

long long lcm(long long a,long long b){
	return a/gcd(a,b)*b;
}

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main(){
	init();
	ld N,K;cin>>N>>K;
	ld ans=0;
	ld data=(K-1)/K;
	for(int i=1;i<=N;i++){
		ll num=0;
		ll a=i;
		while(a<K){
			num++;
			a*=2;
		}
		//cout<<a<<" "<<num<<endl;
		ans+=powl(0.5L,(ld)num)/N;
	}
	cout<<setprecision(30)<<fixed<<ans<<endl;
}


Measured memory_bytes: 256
from sys import stdin

def ria(sep = ''):
    if sep == '' :
        return list(map(int, input().split())) 
    else: return list(map(int, input().split(sep)))
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()

N = ri()
A = [0] * 5
for i in range(5): A[i] = ri()

prev = N
head = 0
tail = 0
for i in range(5):
    if(A[i] >= prev):
        nhead = head + 1
        ntail = tail + 1
        head = nhead
        tail = ntail
    else :
        nhead = head + 1
        ntail = head + (N + (A[i] - 1)) // A[i]
        head = nhead
        tail = ntail
    # print("{0}, {1}".format(head, tail))
    prev = min(prev, A[i])
print (tail)


Measured memory_bytes: 3064
import java.util.*;
import java.io.*;

class Mon{
	long x, h;
	long cnt;

	public Mon(long x, long h, long cnt) {
		super();
		this.x = x;
		this.h = h;
		this.cnt = cnt;
	}
	
}

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt();
		long d = fs.nextInt(), a = fs.nextInt();
		TreeSet<Mon> ts = new TreeSet<>((m1,m2)->m1.x - m2.x<0?-1:1);
		for(int i=0;i<n;i++) {
			int tx = fs.nextInt();//x
			int th = fs.nextInt();//h
			ts.add(new Mon(tx,th,0));
		}

		long ans = 0;
		PriorityQueue<Mon> pq = new PriorityQueue<>((m1,m2)->m1.x - m2.x<0?-1:1);
		pq.offer(ts.pollFirst());
		while(!ts.isEmpty()) {
			if(pq.isEmpty()) {
				Mon t = ts.pollFirst();
				t.cnt = ans;
				pq.add(t);
				continue;
			}
			Mon tm = pq.poll();
			tm.h -= a *(ans - tm.cnt);
			if(tm.h <= 0)continue;
			long t = (tm.h + a - 1) / a;
			ans += t;
			
			while(!ts.isEmpty()) {
				Mon nm = ts.pollFirst();
				if(nm.x>tm.x+2*d) {
					ts.add(nm);
					break;
				}
				nm.cnt = (ans - t);
				pq.add(nm);

			}
		}
		
		if(!pq.isEmpty()) {
			long max = 0;
			while(!pq.isEmpty()) {
				Mon now = pq.poll();
				now.h -= a * (ans - now.cnt);
				if(now.h>0) {
					long t = (now.h + a - 1)/a;
					max = Math.max(max, t);
				}
			}
			ans += max;
		}
		
		System.out.println(ans);
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

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

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

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

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 74608
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
  "sort"
)

type Infant [][]int
func (I Infant) Len() int { return len(I) }
func (I Infant) Less(i, j int) bool { return I[i][0] < I[j][0] }
func (I Infant) Swap(i, j int) { I[i], I[j] = I[j], I[i] }

func Solve() {
  var N int
  NextInt(&N)
  var A []int
  NextIntVec(&A)
  B := make([][]int, N)
  for i, a := range A {
    B[i] = []int{a, i}
  }
  sort.Sort(sort.Reverse(Infant(B)))
  DP := make([][]int, N + 1)
  for i := range DP { DP[i] = make([]int, N + 1) }
  for i, b := range B {
    for j := 0; j < i + 1; j++ {
      DP[i + 1][j + 1] = MaxInt(DP[i][j] + b[0] * AbsInt(b[1] - j), DP[i + 1][j + 1])
      DP[i + 1][j] = MaxInt(DP[i][j] + b[0] * AbsInt(N - 1 - i + j - b[1]), DP[i + 1][j])
    }
  }
  Write(MaxInt(DP[N]...))
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

Measured memory_bytes: 23216
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    int n;
    i64 k;
    std::cin >> n >> k;
    std::vector bin(n, std::vector<int>(70, -1));
    for (int i = 0; i < n; i++) {
        int a;
        std::cin >> a;
        bin[i][0] = a - 1;
    }

    for (int i = 1; i < 70; i++) for (int j = 0; j < n; j++) {
        if (bin[j][i - 1] < 0) continue;
        bin[j][i] = bin[bin[j][i - 1]][i - 1];
    }

    int v = 0;
    for (i64 i = 0; i < 63; i++) {
        if ((1ll << i) & k) v = bin[v][i];
    }

    std::cout << v + 1 << std::endl;

    return 0;
}


Measured memory_bytes: 64244
n = gets.to_i
m = Array.new(n){ Array.new(n, 0) }

readlines.each do |line|
  # 1 2 2 4
  line = line.chomp!.split.map(&:to_i)
  v = line[0] - 1
  line[1].times do |index|
    m[v][line[index + 2] - 1] = 1
  end
end
m.each do |line|
  puts line.join(' ')
end



Measured memory_bytes: 8884
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>

using namespace std;

int n,k;
vector<vector<int> > cards;

bool check(string seq){
  int sum=0;
  bool f=false;
  for(int i = 0;i < cards.size(); i++){
    sum=0;
    for(int j = 0; j < cards[0].size(); j++){
      int t=cards[i][j]-1;
      sum+=seq[t]-'0';
    }
    if(!((sum>=n/8)&&(sum<=3*n/8)))
      return false;
  }
  return true;
}

int main(){

  cin>>n>>k;
  for(int i = 0; i < k; i++){
    vector<int> v;
    for(int j = 0; j < n/2; j++){
      int t;
      cin>>t;
      v.push_back(t);
    }
    cards.push_back(v);
  }
  // ツ猟青探ツつオツづ湘ーツ個渉づーツづ敖つスツつキseqツつェツづつォツつスツづァfin
  while(1){
    string seq;
    for(int i = 0; i < n; i++){
      int a=rand()%2;
      seq+=(char)(a+'0');
    }
    if(check(seq)){
      cout<<seq<<endl;
      break;
    }
  }
  cards.clear();

  return 0;
}

Measured memory_bytes: 1896
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long LL;

LL ec = 0,nxt[4005],to[4005],hed[2005] = {0};
void add_edge(LL f,LL t){
	++ ec; to[ec] = t; nxt[ec] = hed[f]; hed[f] = ec;
}

LL n,k;
LL siz[2005],dep[2005],del;
void dfs(LL u,LL f){
	dep[u] = dep[f] + 1;
	if(dep[u] > k) del ++;
	for(LL i = hed[u];i;i = nxt[i]){
		LL v = to[i];
		if(v == f) continue;
		dfs(v,u);
	}
}

int main(){
	ios::sync_with_stdio(false);
	LL ans = 0x3f3f3f3f3f3f3f3f;
	LL u[2005],v[2005];
	cin >> n >> k;
	for(LL i = 1;i < n;i ++){
		cin >> u[i] >> v[i];
		add_edge(u[i],v[i]);
		add_edge(v[i],u[i]);
	}
	if(k & 1){
		k >>= 1;
		for(LL i = 1;i < n;i ++){
			del = 0;
			dep[v[i]] = -1; dfs(u[i],v[i]);
			dep[u[i]] = -1; dfs(v[i],u[i]);
			ans = min(ans,del);
		}
	}
	else{
		k >>= 1; dep[0] = -1;
		for(LL i = 1;i <= n;i ++){
			del = 0; dfs(i,0);
			ans = min(ans,del);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + (ll)b) % mod
#define MUL(a, b) a = (a * (ll)b) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rer(i, a, b) for(int i = a - 1; i >= b; i--)
#define all(a) (a).begin(), (a).end()
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef pair<int, pi> ppi;
typedef vector<ll> vec;

const int MAX_N = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;

void Debug() {cout << '\n'; }

template<class FIRST, class... REST> 
void Debug(FIRST arg, REST... rest) { cout << arg << " "; Debug(rest...); }

template<class T>
ostream& operator<< (ostream& out, const vector<T>& v) {
	out << "[";
	if(!v.empty()) {
		rep(i, 0, (int)v.size() - 1) out << v[i] << ", ";
		out << v.back();
	}
	out << "]";
  return out;
}

template<class S, class T>
ostream& operator<< (ostream& out, const pair<S, T>& v) {
	out << "(" << v.first << ", " << v.second << ")";
	return out;
}

///g++ -g3 -std=c++0x -DLOCAL -Wall -ftrapv -D_GLIBCXX_DEBUG -Wl,-stack,268435456 -o
///g++ -O2 -std=c++0x -DLOCAL -Wall -Wl,-stack,268435456 -o

////////////////////////////////////////////////////////////////////////

int N, M, H, W;
const int yajue = 114514 * 810;

void solve() {
	cin >> N >> M >> H >> W;
	if(N % H == 0 && M % W == 0) cout << "No\n";
	else {
		cout << "Yes\n";
		rep(i, 0, N) {
			rep(j, 0, M) {
				if(i % H == 0 && j % W == 0) cout << yajue << " ";
				else if(i % H == H - 1 && j % W == W - 1) cout << -yajue - 1 << " ";
				else cout << 0 << " ";
			}
			cout << "\n";
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);	
    cout << fixed;
	cout.precision(20);
#ifdef LOCAL
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}

Measured memory_bytes: 2560
def divisor(n):
    x=[]
    y=[]
    for i in range(1,int(n**.5)+1):
        if n%i==0:
            x.append(i)
            y.append(n//i)
    if y[-1]==x[-1]:
        y=y[:-1]
    return x+y[::-1]
N=int(input())
a=0
d=divisor(N)
for K in d:
    if K==1:continue
    n=N
    while n>=K:
        if n%K==0:
            n//=K
        else:
            n%=K
    if n==1:
        a+=1
if N-1>1 and N-1 not in d:
    a+=len(divisor(N-1))-1
print(a)

Measured memory_bytes: 3316
#include <iostream>


int main()
{
	unsigned long long N;
	std::cin >> N;

	std::string S;
	std::cin >> S;

	int hit = 0;
	for (int i = 0; i < (N - 2); ++i) {
		if ((S[i] == 'A') && (S[i +1] == 'B') && (S[i +2] == 'C')) {
			++hit;
			i += 2;
		}
	}

	std::cout << hit << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
main(){
  int N;
  while(1){
    scanf("%d",&N);
    if(N==0) break;
    int res=0;
    int keta = 5;
    for(int i=0;i<19;i++){
      res += (N/keta);
      keta*=5;
    }
    printf("%d\n",res);
  }
}

Measured memory_bytes: 1028
def main():
  n, k = input().split()
  a=set(input().split())
  while True:
      n1=set(n)
      if n1 & a == set():
          print(n)
          break
      else:
          n=int(n)
          n+=1
          n=str(n)
  
  
if __name__=="__main__":
  main()


Measured memory_bytes: 9140
#include <stdio.h>

int A[1000000], n;

/* 二分探索 */
int binarySearch(int key) {
  int left = 0;
  int right = n;
  int mid;
  while(left < right) {
    mid = (left + right) / 2;
    if(key == A[mid]) return 1; /* keyを発見 */
    if(key > A[mid]) left = mid + 1; /* 後半を探索 */
    else if(key < A[mid]) right = mid; /* 前半を探索 */
  }
  return 0;
}

int main(void) {
  int i, q, k, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++) {
    scanf("%d",&k);
    if(binarySearch(k))
      sum++;
  }
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 2112
n, x, y= map(int, input().split())
res_list = [0] * (n-1)

def get_shortest_path(i, j, x, y):
  base_dist = j - i
  dist_short = abs(x-i) + abs(y-j) + 1
  return min(base_dist, dist_short)

for i in range(n-1):
  for j in range(i+1, n):
    dist = get_shortest_path(i, j, x-1, y-1)
    res_list[dist-1] += 1
for i in range(n-1):
  print(res_list[i])

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
int main()
{
       int n,x,sum=0;
       cin>>n>>x;
       int arr[n];
       for(int i=0;i<n;i++){
        cin>>arr[i];
        sum+=arr[i];
       }
      int* m=min_element(arr,arr+n);
       sum=x-sum;
       cout<<n+(sum/ *m);
    return 0;
   }

Measured memory_bytes: 3644
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll mod=998244353;
ll power(ll n,ll p){
    ll ans=1;
    while(p){
        if(p&1)ans=(ans*n)%mod;
        n=(n*n)%mod;
        p>>=1;
    }
    return ans;
}
ll n,mx,a[100005],ans=1,freq[100005];
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    cin>>n;
    for(ll i=1;i<=n;i++)cin>>a[i],freq[a[i]]++,mx=max(mx,a[i]);
    if(a[1]!=0 || freq[0]!=1)return cout<<"0" , 0;
    for(ll i=1;i<=mx;i++)ans=(ans * power(freq[i-1],freq[i]) )%mod;
    cout<<ans;
}




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

using namespace std;

#define MAX_H 500
#define MAX_W 500
#define F first
#define S second
typedef pair<int,int> pii;

int H,W;
char field[MAX_H][MAX_W];
vector<pii> v[26];

bool inField(int x,int y){
    return (0 <= x && x < W && 0 <= y && y < H);
}

int calc(int x,int y){
    for(int i = 0 ; i < 26 ; i++){
        v[i].clear();
    }
    const int dx[] = {-1,0,1,0};
    const int dy[] = {0,-1,0,1};
    for(int i = 0 ; i < 4 ; i++){
        int nx = x, ny = y;
        while(1){
            nx += dx[i]; ny += dy[i];
            if(!inField(nx,ny)) break;
            if(field[ny][nx] != '.'){
                v[field[ny][nx]-'A'].push_back(pii(nx,ny));
                break;
            }
        }
    }
    int res = 0;
    for(int i = 0 ; i < 26 ; i++){
        if(v[i].size() == 2){
            field[v[i][0].S][v[i][0].F] = '.';
            field[v[i][1].S][v[i][1].F] = '.';
            res += 2;
        }
    }
    return res;
}

int main(){
    cin >> H >> W;
    for(int i = 0 ; i < H ; i++){
        for(int j = 0 ; j < W ; j++){
            cin >> field[i][j];
        }
    }
    int res = 0;
    bool update = 1;
    while(update){
        update = 0;
        for(int i = 0 ; i < H ; i++){
            for(int j = 0 ; j < W ; j++){
                if(field[i][j] != '.') continue;
                int r = calc(j,i);
                if(r > 0){
                    res += r;
                    update = 1;
                }
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1440
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

int gcd(int a,int b) {
    if(a == 0 || b == 0) {
        return max(a,b);
    }
    else {
        if(a < b) {
            int tmp = a;
            a = b;
            b = tmp;
        }
        int r = a % b;
        while(r != 0) {
            a = b;
            b = r;
            r = a % b;
        }
        return b;
    }
}

signed main() {
    int A,B;
    cin >> A >> B;
    int C = gcd(A,B);
    int ret = 1;
    for(int i = 2;i <= sqrt(C);i++) {
        if(C % i == 0) {
            ret++;
            while(C % i == 0) {
                C = C / i;
            }
        }
    }
    if(C != 1) {
      	ret++;
    }
    cout << ret << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def ok(t, s):
    N = len(t)
    for i in range(N):
        if t[i]:
            for x, y in s[i]:
                if y == 1:
                    if not t[x]:
                        return False
                elif y == 0:
                    if t[x]:
                        return False

    return True


def solve():
    N = int(input())

    s = defaultdict(list)
    for i in range(N):
        A = int(input())
        for _ in range(A):
            X, Y = map(int, input().split())
            X -= 1
            s[i].append((X, Y))

    ans = 0
    for b in range(2 ** N):
        t = [0] * N
        num = 0
        for i in range(N):
            if (b >> i) & 1:
                t[i] = 1
                num += 1
        if ok(t, s):
            ans = max(ans, num)

    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 70000
#include<iostream>
using namespace std;
int main() {
	int n, m, p;
	while (cin >> n >> m >> p, n || m || p) {
		int sum = 0;
		int key;
		for (int i = 1; i <= n; i++) {
			int k; cin >> k;
			sum += k;
			if (i == m)key = k;
		}
		if (key == 0)cout << "0\n";
		else cout << sum  * (100 - p)  / key << endl;
	}
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n;
int a[maxn];
bool hit[maxn];

void proc(int x) {

    for (int i=2; i*i<=x; i++) {
	if (x%i==0) {
	    if (hit[i]) {
		out("setwise coprime");
	    }
	    while (x%i==0) {
		x /= i;
	    }
	    hit[i]=true;
	}
    }


    if (x>1) {
	if (hit[x]) {
	    out("setwise coprime");
	}
	hit[x] = true;
    }
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n;
    for (int i=0; i<n; i++) {
	cin>>a[i];
    }
    int g = a[0];
    for (int i=1; i<n; i++) {
	g = __gcd(g, a[i]);
    }

    if (g > 1) out("not coprime");

    for (int i=0; i<n; i++) {
	proc(a[i]);
    }


    cout<<"pairwise coprime\n";
    
    return 0;
}


Measured memory_bytes: 7480
n,m = map(int,input().split())
a = set([int(input()) for _ in range(m)])
mod = 10 ** 9 + 7
dp = [float("inf")] * (n+1)
dp[0] = 1
for i in range(1,n+1):
    if i in a:
        dp[i] = 0
    elif i < 2:
        dp[i] = i
    else:
        dp[i] = (dp[i-1] + dp[i-2]) % mod
print(dp[-1])

Measured memory_bytes: 13216
def alphabet_to_int(c):
    if c=="a":
        return 0
    elif c=="b":
        return 1
    elif c=="c":
        return 2
    elif c=="d":
        return 3
    elif c=="e":
        return 4
    elif c=="f":
        return 5
    elif c=="g":
        return 6
    elif c=="h":
        return 7
    elif c=="i":
        return 8
    elif c=="j":
        return 9
    elif c=="k":
        return 10
    elif c=="l":
        return 11
    elif c=="m":
        return 12        
    elif c=="n":
        return 13
    elif c=="o":
        return 14
    elif c=="p":
        return 15
    elif c=="q":
        return 16
    elif c=="r":
        return 17
    elif c=="s":
        return 18
    elif c=="t":
        return 19
    elif c=="u":
        return 20
    elif c=="v":
        return 21
    elif c=="w":
        return 22
    elif c=="x":
        return 23
    elif c=="y":
        return 24              
    elif c=="z":
        return 25        
        
def int_to_alphabet(i):
    if i==0:
        return "a"
    elif i==1:
        return "b"
    elif i==2:
        return "c"
    elif i==3:
        return "d"
    elif i==4:
        return "e"
    elif i==5:
        return "f"
    elif i==6:
        return "g"
    elif i==7:
        return "h"
    elif i==8:
        return "i"
    elif i==9:
        return "j"
    elif i==10:
        return "k"
    elif i==11:
        return "l"
    elif i==12:
        return "m"        
    elif i==13:
        return "n"
    elif i==14:
        return "o"
    elif i==15:
        return "p"
    elif i==16:
        return "q"
    elif i==17:
        return "r"
    elif i==18:
        return "s"
    elif i==19:
        return "t"
    elif i==20:
        return "u"
    elif i==21:
        return "v"
    elif i==22:
        return "w"
    elif i==23:
        return "x"
    elif i==24:
        return "y"              
    elif i==25:
        return "z"        
            
        
S=raw_input()

if len(S)<=25:
    char_set = [0 for i in range(26)]
    for i in range(len(S)):
        char_set[alphabet_to_int(S[i])]=1
    for i in range(26):
        if char_set[i]==0:
            ans=S+int_to_alphabet(i)
            print ans
            break
else:
    prev_char=S[-1]
    prev_set = [0 for i in range(26)]
    prev_set[alphabet_to_int(prev_char)]=1
    for i in range(26):
        if alphabet_to_int(prev_char)>alphabet_to_int(S[-(i+1)]):
            for j in range(alphabet_to_int(S[-(i+1)]),26):
                if prev_set[j] == 1:
                        ans=S[:-(i+1)]+int_to_alphabet(j)
                        break
            print ans
            break
        if i==25:
            print -1
        prev_set[alphabet_to_int(S[-(i+1)])]=1
        prev_char=S[-(i+1)]


Measured memory_bytes: 2824
def main():

    n, k = map(int, input().split())
    mod = pow(10, 9) + 7

    g1 = [1, 1]
    g2 = [1, 1]
    inv = [0, 1]

    for i in range(2, n+1):
        g1.append((g1[-1] * i) % mod)
        inv.append( ( -inv[mod % i] * (mod//i)) % mod )
        g2.append((g2[-1] * inv[-1]) % mod)

    def combi(n, r):
        r = min(r, n-r)
        return g1[n]*g2[r]*g2[n-r]%mod

    if k >= n-1:
        k = n-1
    ans = 1
    for i in range(1, k+1):
        ans += (combi(n, i) * combi(n-1, n-i-1)) % mod
    return ans % mod


if __name__ == '__main__':
    print(main())

Measured memory_bytes: 81904
#include<stdio.h>
 
int main(void)
{
	int n1, n2, A[100000], B[100000];
	int i, j, k, l = 0;
	int min, max, mid;
	int count = 0;

	scanf("%d", &n1);

	for (i = 0;i < n1;i++) {
		scanf("%d", &A[i]);
	}

	scanf("%d", &n2);

	for (i = 0;i < n2;i++) {
		scanf("%d", &B[i]);
	}
	
	

	for (i = 0;i < n2;i++) {
		min = 0;
		max = n1 - 1;
		mid = (n1 - 1) / 2;
		while (min < max){
				
			
			
			if (B[i] < A[mid]) {
				max = mid - 1;
			}
			if (B[i] > A[mid]) {
				min = mid + 1;
			}
			mid = (max + min) / 2;
			if (A[mid] == B[i]) {
				count++;
				break;
			}
		
		}
	}

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




	return 0;
}
 



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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define pb push_back
#define f first
#define s second
#define INF 1000000000000
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

const int MAXN = 100100, MAXK = 25;
const ll MOD = 1e9+7;

int n, m;
vi adj[MAXN];
int dp[MAXN];
vi sorted;
int deg[MAXN];

void toposort () {
    queue<int> q;
    FOR(i, 1, n) if (deg[i] == 0) q.push(i);
    while (!q.empty()) {
        int v = q.front(); q.pop();
        sorted.pb(v);
        for (int u : adj[v]) {
            deg[u]--;
            if (deg[u] == 0)
                q.push(u);
        }
    }
}

int main()
{
    FAST_IO;

    cin >> n >> m;
    FOR(i, 1, m) {
        int u, v; cin >> u >> v;
        adj[u].pb(v);
        deg[v]++;
    }

    toposort();

    reverse(sorted.begin(), sorted.end());

    int ans = 0;
    for (int v : sorted) {
        dp[v] = 0;
        for (int u : adj[v])
            dp[v] = max(dp[v], dp[u] + 1);
        ans = max(ans, dp[v]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7032
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

template<class T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

template<class T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

ll fact(ll n){
    if(n==0)return 1;
    else return n*fact(n-1)%MOD;
}
ll calc(ll n,ll k){
    if(k==0)return 1;
    ll m=n*n%MOD;
    if(k%2)return n*calc(m,k/2)%MOD;
    else return calc(m,k/2)%MOD;
}
ll comb(ll n,ll k){
    ll ret=fact(n);
    ret=ret*calc(fact(k),MOD-2)%MOD;
    ret=ret*calc(fact(n-k),MOD-2)%MOD;
    return ret;
}

int main() {
    ll x,y;
    cin>>x>>y;
    ll ans = 0;

    for(ll i=0;i*2<=x;i++){
        ll j = x-(i*2);
        if(j*2+i==y){
           
            ans +=comb(j+i,i);
            ans %= MOD;

        }
    }

cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 10624
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto lr = readln.split.to!(long[]);
    auto L = lr[0];
    auto R = lr[1];
    if (R - L >= 2050) {
        writeln(0);
    } else {
        long min_r = long.max;
        foreach (i; L..R) foreach (j; i+1..R+1) min_r = min(min_r, i * j % 2019L);
        writeln(min_r);
    }
}

Measured memory_bytes: 256