akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <iomanip>
#include <limits>
#include <fstream>
#include <algorithm>
#include <sstream>
#include <map>
#include <unordered_map>
#include <ctime>
#include <cassert>
#include <cstring>
#include <sys/time.h>
#include <stdlib.h>
using namespace std;

bool comp(const string &a, const string &b){
  return a < b;
}

int main(int argc, char *argv[]){
  int n;
  cin >> n;
  vector<string> s;
  for(int i=0;i<n;i++){
    string si;
    cin >> si;
    s.push_back(si);
  }
  sort(s.begin(),s.end(),comp);
  vector<string> ss;
  string l = "";
  int max = 0, cnt = 0;
  for(int i=0;i<n;i++){
    if(s[i]==l){
      cnt++;
    }else{
      if(cnt>max){
        max = cnt;
        ss.erase(ss.begin(),ss.end());
        ss.push_back(l);
      }else if(cnt==max){
        ss.push_back(l);
      }
      l = s[i];
      cnt = 1;
    }
  }
  if(cnt>max){
    max = cnt;
    ss.erase(ss.begin(),ss.end());
    ss.push_back(l);
  }else if(cnt==max){
    ss.push_back(l);
  }
  for(int i=0;i<(int)ss.size();i++){
    cout << ss[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 15984
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define eb emplace_back
#define mp make_pair
using namespace std;
const ll INF=1e18;
const int MAX_N=2e5+10;
ll n,x,d;
map<int,vector<pair<ll,ll>>> vec;
int main(){
    cin>>n>>x>>d;
    if(d==0){
        if(x==0){
            cout<<1<<endl;
            return 0;
        }else{
            cout<<n+1<<endl;
            return 0;
        }
    }
    if(d<0){
        x=-x;
        d=-d;
    }
    for(ll i=0;i<=n;i++){
        vec[(i*x%d+d)%d].eb(mp(i*x/d+(0+i-1)*i/2,i*x/d+(n-i+n-1)*i/2));
    }
    ll ans=0;
    for(auto &x:vec){
       sort(x.second.begin(),x.second.end());
       ll pos=-INF;
       for(auto &y:x.second){
           //cout<<x.first<<" "<<y.first<<" "<<y.second<<endl;
            if(pos>=y.second){
                continue;
            }
            if(pos<y.first){
                ans+=abs((y.second-y.first))+1;
            }else{
                ans+=abs((y.second-pos));
            }
            pos=y.second;
       }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 22144
n,k=list(map(int,input().split()))
lis=[0]*n
for _ in range(k):
    d=int(input())
    A=list(map(int,input().split()))
    for a in A:
        lis[a-1]+=1
check=0
for l in lis:
    if l==0:
        check+=1
print(check)


Measured memory_bytes: 9180
import math


n, max_distance = map(int, input().split())
points = []
distances = []
for i in range(n):
    x, y = map(int, input().split())
    points.append((x, y))
    distances.append(math.sqrt(x*x + y*y))

count = 0
for v in distances:
    if v <= max_distance:
        count += 1

print(count)

Measured memory_bytes: 43932
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int x; int p;
	while(~scanf("%d%d", &x, &p)) {
		double t = p * 1e-2;
		double ans = (x / 2) * (1. / t);
		if(x % 2 != 0) ans = 1 + t * ans + (ans + (1 / t)) * (1 - t);
		printf("%.10f\n", ans);
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <iostream>
#include <queue>

using namespace std;

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64; // 9e18
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

const double PI = 3.141592653589793238463;
const int MAXN = 1000500;
const int MAXVALUE = 1000000500;
const long double EPS = 1e-7;
const i64 INF = 1e18;
i64 mod = 1e9 + 7;


i64 T, n, m, k;
//vector <vector<i64>> a;
//vector <i64> a;
//vector <i64> b;
vector <i64> dp;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(16);

    i64 a, b, v, w, t;

    cin >> a >> v >> b >> w >> t;

    bool fl = false;

    if (v > w) {
        i64 dv = v - w;
        i64 s = abs(a - b);
        i64 dt = s / dv + (i64)(bool)(s % dv);
        if (dt <= t) {
            fl = true;
        }
    }

    if (fl) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }


    return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int w, a, b;
  cin >> w >> a >> b;
  
  if(a>=b)    
    cout << max(0, a-w-b) << "\n";
  else
    cout << max(0, b-a-w) << "\n";

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int a,b,c;cin>>a>>b>>c;
	if (b > a){
		if(c > a && b > c){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}
	else{
		if(b < c && a > c){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int f[4];
int main()
{
	int a,b,i;
	scanf("%d %d",&a,&b);
	f[a]=f[b]=1;
	for(i=1;i<=3;i++)
		if(f[i]==0)
			printf("%d",i);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int L, R, d; cin >> L >> R >> d;
  int result = 0;
  for (int i = L; i < R + 1; i++) {
    if (i % d == 0) result++;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3588
while True:
    table = input().split()
 
    a = int(table[0])
    op = table[1]
    b = int(table[2])
 
    if op == '?':
        break
 
    if op == '+':
        print("%d"%(a+b))
    elif op == '-':
        print("%d"%(a-b))
    elif op == '/':
        print("%d"%(a/b))
    else:
        print("%d"%(a*b))


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

int main() {
  int n;
  cin >> n;
  int push = 0;
  vector<int> a(n+1, 0);
  for (int i = 1; i <= n; i++) cin >> a[i];
  set<int> s;
  int touch = 1;
  while(true) {
    s.insert(touch);
    touch = a[touch];
    push++;
    if(touch == 2) break;
    else if(s.count(touch)) {
      push = -1;
      break;
    }
  }
  cout << push;
}

Measured memory_bytes: 8200
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=2e5+5;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
    string s;
    cin>>s;
    if(s=="ABC")
        cout<<"ARC"<<'\n';
    else
        cout<<"ABC"<<'\n';


}


Measured memory_bytes: 3604
N, M = map(int, input().split())
g = {i: set() for i in range(1, N + 1)}
for _ in range(M):
    A, B = map(int, input().split())
    g[A].add(B)
    g[B].add(A)

if g[1].intersection(g[N]):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 89184
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

	int n, x, l[100], d[110];
	cin >> n >> x;
	d[0]=0;
	int ans=1;
	for(int i=0; i<n; i++){
		cin >> l[i];
		d[i+1]=d[i]+l[i];
		if(d[i+1]<=x){
			ans++;
		}
	}
	cout << ans << endl;	

	return 0;
}

Measured memory_bytes: 256
IDENTIFICATION DIVISION.
       PROGRAM-ID. test1.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 N PICTURE 9999.
       01 A PIC 9999.
       01 B PIC 9999.
       01 C PIC 9999.
       01 D PIC 9999.
       PROCEDURE DIVISION.
       MAIN.
        ACCEPT N.
        COMPUTE A=N / 1000.
        COMPUTE B= N - A * 1000.
     	COMPUTE B=B / 100.
      	COMPUTE C=N- A * 1000 - B * 100.
      	COMPUTE C=C / 10.
      	COMPUTE D=N - A * 1000 - B *100 - C*10.
      	IF A=B AND B=C THEN
      		DISPLAY "Yes"
      	ELSE IF B=C AND C=D THEN
      		DISPLAY "Yes"
      	ELSE
      		DISPLAY "No"
      	END-IF.
        STOP RUN.



Measured memory_bytes: 384
#include <iostream>
#include <math.h>
using namespace std;

int main() {
	int i,n,y,b,t,ans;
	double a,ma,r;
	while(cin >> n && n>0) {
	cin >> y; ma=0;
	for (i=0;i<n;i++) {
		cin >> b >> r >> t;
		if (t==1) a=1+y*r/100; else a=pow(1+r/100,y);
		if (ma<a) { ma=a; ans=b;}
	}
	cout << ans << endl;
   } 	 
	return 0;
} 

Measured memory_bytes: 1316
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int road1[111][111];
  int road2[111][111];
  int n,m;
  int a,b,cost,time;
  int p,q,r;
  int x;
  while(1){
    for(int i=0;i<111;i++){
      for(int j=0;j<111;j++){
    road1[i][j]=road2[i][j]=111111111;
      }
    }
    cin >> n >> m;
    if(n==0 && m==0)break;
    for(int i=0;i<n;i++){
      cin >> a >> b >> cost >> time;
      road1[a][b]=road1[b][a]=cost;
      road2[a][b]=road2[b][a]=time;
    }
 
    for(int k=1;k<=m;k++){
      for(int i=1;i<=m;i++){
    for(int j=1;j<=m;j++){
      if(road1[i][j]>road1[i][k]+road1[k][j]){
        road1[i][j]=road1[i][k]+road1[k][j];
      }
      if(road2[i][j]>road2[i][k]+road2[k][j]){
        road2[i][j]=road2[i][k]+road2[k][j];
      }
    }
      }
    }
     
    cin >> x;
    for(int i=0;i<x;i++){
      cin >> p >> q >> r;
      cout << (r==0 ? road1[p][q] : road2[p][q]) << endl;
    }
  }
}

Measured memory_bytes: 1256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int Pop(void);
void Push(int);

int prin = 0;

int stack[1000];

int main()
{
 
  int i,j;
  char s[100];
  
  while(scanf("%s",s) != EOF){
   
     
    if (s[0] == '+')
      {
	i = Pop();
	j = Pop();
	Push(j + i);
      }
    else if (s[0] == '-')
      {
	i = Pop();
	j = Pop();
	Push(j - i);
      }
    else if (s[0] == '*')
      {
	i = Pop();
	j = Pop();
	Push(j * i);
      }
    else
      {
	Push(atoi(s));
      }
  }
  printf("%d\n",Pop());
  return 0;
}
 
int Pop(void)
{
  prin --; 
  return stack[prin + 1];
}

void Push(int x)
{   
 
  stack[++ prin] = x;
}		

Measured memory_bytes: 548
#include<bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
typedef long long ll;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int main() {
    ll x[2011];
    ll r, d; cin >> r >> d >> x[2000];
    rrep(i, 2001, 2011) x[i] = r * x[i - 1] - d;
    rrep(i, 2001, 2011) cout << x[i] << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int q[2000000];
void swap(int i, int j) {
  int t;
  t=q[i];
  q[i]=q[j];
  q[j]=t;
}
int main(void) {
  int k,s=0,i,pr,l,r;
  char com[2];
  while (1) {
    scanf("%s", com);
    if(!strncmp(com,"en",2)) break;
    if(com[0]=='i'){
      scanf("%d", &k);
      q[i=s]=k;
      while (i>0 && q[i]>q[pr=(i-1)/2]) {
        swap(i,pr);
        i=pr;
      }
      ++s;
    } else {
      printf("%d\n", q[0]);
      q[i=0]=q[--s];
      --q[s];
      while ((l=i*2+1)<s) {
        if ((r=l+1)<s && q[r] > q[l]) l=r;
        if (q[i] < q[l]) swap(i,l);
        i=l;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 4696
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
const ll MAX = 200000, INF = 1e13;
ll n, k;
 
ll A[MAX], B[MAX], F[MAX];
 
bool C(ll x) {
    ll cnt = 0;
    sort(A, A + n);
    sort(F, F + n, greater<>());
    for (int i = 0; i < n; i++) {
        B[i] = x/F[i];
    }
    for (int i = 0; i < n; i++) {
        if (B[i] < A[i]) cnt += A[i] - B[i];
    }
    if (cnt > k) return false;
    else return true;
}
 
void solve() {
    ll lb = 0, ub = INF;
    for (int i = 0; i < 100; i++) {
        ll mid = (lb + ub) / 2;
        if (C(mid)) ub = mid;
        else lb = mid;
    }
 
    printf("%lld\n", ub);
}
 
int main() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> A[i];
    for (int i = 0; i < n; i++) cin >> F[i];
 
    solve();
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
int32_t main()
{
    string str;
    cin>>str;
    map<int,int> m;
    m[0]=1;
    int temp=0,x=1,ans=0;
    for(int i=str.size()-1;i>=0;i--)
    {
        temp=(temp+x*(str[i]-'0'))%2019;
        ans+=m[temp];
        m[temp]++;
        x=(x*10)%2019;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3724
import itertools
def myAnswer(N:int,A:list) -> int:
   ans = 0
   i = 0
   for c in itertools.accumulate(A[0]):
      a = A[1][i]
      ans = max(a+ans,a+c)
      i += 1
   return ans

   

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   A = []
   for _ in range(2):
      A.append(list(map(int,input().split())))
   print(myAnswer(N,A[:]))
if __name__ == '__main__':
   main()

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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++){
        cin >>a[i];
    }
    double b[n];
    double sum=0;
    for(int i=0; i<n; i++){
        b[i]=1.0/a[i];
        sum+=b[i];
    }

    double ans=1/sum;
    cout << fixed << setprecision(8) << ans <<  endl; 
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <functional>
#include <iomanip>

using namespace std;

#ifdef LOCAL
    #define debug(v) cerr<<v<<"\n"
#else
    #define debug(...) 42
#endif
#define out(v) cout<<v<<"\n"
#define _overload3(_1,_2,_3,name,...) name
#define _all1(a) (a).begin(),(a).end()
#define _all2(a,n) (a),(a)+n
#define all(...) _overload3(__VA_ARGS__,42,_all2,_all1,)(__VA_ARGS__)
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
const int MOD = 1e9+7;
const int INF = 1e9;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>ostream& operator<<(ostream& os, vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}
#include<type_traits>
template<typename T,size_t SIZE,enable_if_t<!is_same<remove_cv_t<T>,char>::value,nullptr_t> = nullptr>ostream& operator<<(ostream& os,T(&arr)[SIZE]){os<<"{";for(size_t i=0;i<SIZE;++i)os<<(i?", ":"")<<arr[i];os<<"}";return os;}

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int A, B; cin >> A >> B;
  cout << 6 - A - B << "\n";

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#define maxn 100505
#define ll long long
#define mod 1000000007
using namespace std;
int n,m,k,t;
int a[maxn],b[maxn];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(i&1)b[1]+=a[i];
        else b[1]-=a[i];
    }
    for(int i=2;i<=n;i++)
        b[i]=2*a[i-1]-b[i-1];
    for(int i=1;i<n;i++)
        printf("%d ",b[i]);
    printf("%d\n",b[n]);
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>	
#define pb push_back
#define N 100005
typedef long long ll;
//typedef pair<int,int> pii;
using namespace std;

std::vector<ll> A;

int main(){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	return !printf("%d",min(a,b)+min(c,d));
}



Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var a = cin.ReadIntArray(N);
            var ball = new int[N];
            for (int i = N; i > 0; i--)
            {
                var sum = 0;
                for (int j = N / i; j > 1; j--)
                {
                    sum += ball[i * j - 1];
                }
                ball[i - 1] = sum % 2 == a[i - 1] ? 0 : 1;
            }
            var M = 0;
            var ans = new List<int>();
            for (int i = 1; i <= N; i++)
            {
                if (ball[i - 1] == 1)
                {
                    M++;
                    ans.Add(i);
                }
            }
            Console.WriteLine(M);
            if (ans.Count > 0)
            {
                Console.WriteLine(string.Join(" ", ans));
            }
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


Measured memory_bytes: 33884
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

using namespace std;

int n, c;
int a[2000];
int d[2000];
int f[12000];
vector <int> v[12000];
vector <int> w[2000];

int gcd(int a, int b) {
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

void dfs(int x, int c, vector <int> &z) {
    int i;
    
    f[x] = c;
    if (x < n) z.push_back(x);
    
    for (i = 0; i < v[x].size(); i++) {
        if (f[v[x][i]] == c || f[v[x][i]] == -1) continue;
        
        dfs(v[x][i], c, z);
    }
}

void calc(vector <int> &z, int x) {
    int i, j;
    
    if (z.size() == 0) return;
    
    sort(z.begin(), z.end());
    
    for (i = 0; i < z.size(); i++) {
        if (x == -1 || gcd(x, a[z[i]]) != 1) break;
    }
    
    f[z[i]] = -1;
    for (j = 0; j < z.size(); j++) {
        if (i != j) {
            d[z[j]]++;
            w[z[i]].push_back(z[j]);
        }
    }
    
    for (j = 0; j < v[z[i]].size(); j++) {
        int y = v[z[i]][j];
        
        if (f[y] != -1) {
            vector <int> z2;
            
            dfs(y, ++c, z2);
            
            calc(z2, a[z[i]]);
        }
    }
}

int main() {
    int p, i, j;
    vector <int> ans;
    map <int, int> mp;
    priority_queue <int> q;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    
    sort(a, a + n);
    
    p = n;
    
    for (i = 0; i < n; i++) {
        int x = a[i];
        
        for (j = 2; j * j <= x; j++) {
            if (x % j == 0) {
                while (x % j == 0) x /= j;
                
                if (!mp.count(j)) mp[j] = p++;
                
                v[i].push_back(mp[j]);
                v[mp[j]].push_back(i);
            }
        }
        
        if (x > 1) {
            if (!mp.count(x)) mp[x] = p++;
            
            v[i].push_back(mp[x]);
            v[mp[x]].push_back(i);
        }
    }
    
    for (i = 0; i < n; i++) {
        if (f[i] != -1) {
            vector <int> z;
            
            dfs(i, ++c, z);
            
            calc(z, -1);
            
            q.push(i);
        }
    }
    
    while (!q.empty()) {
        int x = q.top();
        
        q.pop();
        
        ans.push_back(a[x]);
        
        for (i = 0; i < w[x].size(); i++) {
            int y = w[x][i];
            
            d[y]--;
            
            if (d[y] == 0) q.push(y);
        }
    }
    
    for (i = 0; i < n; i++) {
        if (i > 0) putchar(' ');
        printf("%d", ans[i]);
    }
    puts("");
    
    return 0;
}


Measured memory_bytes: 22016
import sys

n = int(input())
a_list = list(map(lambda x: int(x), input().split()))
possesion = 1000
num_stock = 0

# print(a_list)
for i in range(len(a_list) - 1):
    a_today = a_list[i]
    for a in a_list[i+1:]:
        a_next = a
        if a != a_today:
            break
    # これからずっと値段が変わらない場合は全部売ってあと放置
    if a_next == a_today:
        possesion += num_stock * a_list[-1]
        print(possesion)
        sys.exit()
    
    if a_today < a_next:
        # 買えるだけ買う
        possesion_yesterday = possesion
        possesion = possesion % a_today
        num_stock += possesion_yesterday // a_today
    if a_today > a_next:
        # うれるだけうる
        possesion += num_stock * a_today
        num_stock = 0
#     print(a_today, a_next, possesion, num_stock)

# 最終日は買えるだけ買う
possesion += num_stock * a_list[-1]
print(possesion)

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

using namespace std;

const int mod = 998244353;

int add() { return 0; }
template<typename... M> int add(int a, M... b) {
  int x = add(b...);
  return a + x - mod * (a + x >= mod);
}

int mul() { return 1; }
template<typename... M> int mul(int a, M... b) {
  return int(1ll * a * mul(b...) % mod);
}

int pwr(int a, long long x) {
  return (x ? mul(pwr(mul(a, a), x >> 1), (x & 1 ? a : 1)) : 1);
}

int dvd(int a, int b) {
  return mul(a, pwr(b, mod - 2));
}

int sub(int a, int b) {
  return a - b + mod * (a < b);
}

void inc(int& a, int b) {
  a = add(a, b);
}

void dec(int& a, int b) {
  a = sub(a, b);
}

const int N = 3030;
int dp[N][N];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);

  int n, s;
  cin >> n >> s;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    dp[i][0] = pwr(2, i);
    for (int j = 0; j <= s; ++j) {
      if (j > 0 and j < s) {
        inc(dp[i + 1][j], mul(2, dp[i][j]));
      }
      if (j + x <= s) {
        inc(dp[i + 1][j + x], dp[i][j]);
      }
    }
    inc(ans, mul(dp[i + 1][s], pwr(2, n - i - 1)));
  }
  cout << ans;

  return 0;
}


Measured memory_bytes: 39120
// https://atcoder.jp/contests/agc032/tasks/agc032_b

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

const ll INF = 1e18;

void solve() {
  ll N;
  cin >> N;

  VVL edge_list(N, VL(0));

  ll n = N;

  if (N % 2 == 1) {
    rep(i, N - 1) {
      edge_list[i].push_back(N - 1);
      edge_list[N - 1].push_back(i);
    }

    n--;
  }

  rep(j, n) rep(i, j) {
    if (j == n - 1 - i) continue;
    edge_list[i].push_back(j);
    edge_list[j].push_back(i);
  }

  ll edge_ct = 0;
  rep(i, N) edge_ct += edge_list[i].size();
  edge_ct /= 2;

  cout << edge_ct << endl;

  rep(u, N) {
    for (ll v : edge_list[u]) {
      unless(u < v) continue;
      cout << u + 1 << " " << v + 1 << endl;
    }
  }
}

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

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

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

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

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


Measured memory_bytes: 384
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cmath>
#include <limits>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define mod 1000000007
#define fst first
#define pb push_back
int main()
{
    int N;
    cin >> N;
    string s;
    cin >> s;
    int size = s.length();
    for(int i = 0; i < size; i++){
        int code = s[i] - 'A';
        code = (code + N) % 26;
        s[i] = code + 'A';
    }
    cout << s << endl;
}

Measured memory_bytes: 256
#![allow(unused_macros)]

// cf. [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita](https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8)
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        N: usize,
        AB: [(i64, i64); N],
    }
    let b_sum = AB.iter().map(|x| x.1).sum::<i64>();
    use std::collections::BinaryHeap;
    let mut heap = BinaryHeap::new();

    for (a, b) in AB {
        heap.push(a + b);
    }

    let mut ans = 0;
    for i in 0..N {
        if i % 2 == 0 {
            ans += heap.pop().unwrap();
        } else {
            heap.pop();
        }
    }
    println!("{}", ans - b_sum);
}


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

#define int long long
#define M 1000000009
#define M2 998244353

signed main(){
	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	int n;
	cin >> n;
	cout << (1000-n%1000)%1000 << endl;
}


Measured memory_bytes: 3648
#include <iostream>
#define ll long long int
#define N 55
using namespace std;
char s[N][N];
int dir[4][2]={0,1,1,0,0,-1,-1,0};
int a,b;
 
bool search(int x,int y){
    for(int i=0;i<4;i++){
        int xx = x+dir[i][0];
        int yy = y+dir[i][1];
        if(xx>=0&&xx<a&&y>=0&&y<b){
            if(s[xx][yy]=='#')
                return true;
        }
    }
    return false;
}
int main(){
    cin>>a>>b;
    for(int i=0;i<a;i++)
        for(int j=0;j<b;j++)
            cin>>s[i][j];
    for(int i=0;i<a;i++){
        for(int j=0;j<b;j++){
            if(s[i][j]=='#'){
                bool prime = search(i,j);
                if(!prime){
                    return 0*printf("No\n");
                }
            }
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int64_t gcdf (int64_t a,int64_t b){
  int64_t p = a;
  int64_t q = b;
  int64_t c = p%q;
  while(c != 0){
    p = q;
    q = c;
    c = p%q;
  }
  return q;
}

int main(){
  int64_t a,b;
  cin >> a >> b;
  int64_t result = a*b/(gcdf(a,b));
  cout << result << endl;
                        
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;
char txt[11][1001];
int label[11];
int cnt[11];
int N,M,K;
int sol(int P){
	for(int i=0;i<P;i++) cnt[i]=0;
	int sum=0;
	for(int i=0;i<M;i++){
		int nxt[11]={0,};
		for(int j=0;j<N;j++){
			nxt[label[j]]+=txt[j][i]=='1';
		}
		bool flag = false;
		for(int j=0;j<P;j++){
			if(nxt[j]>K) return 987654321;
			if(nxt[j]+cnt[j]>K){
				flag=true;
				break;
			}
			else cnt[j]+=nxt[j];
		}
		if(flag){
			sum++;
			for(int j=0;j<P;j++) cnt[j]=nxt[j];
		}
		
	}
	return sum;
}
int main(){
	scanf("%d %d %d",&N,&M,&K);
	for(int i=0;i<N;i++) scanf("%s",txt[i]);
	int Min = N*M;
	for(int S=0;S<(1<<(N-1));S++){
		int l=0;
		for(int i=0;i<N;i++){
			label[i]=l;
			if(S&(1<<i)) l++;
		}
		Min = min(Min,l+sol(l+1));
	}
	printf("%d",Min);
}

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

public class Main {

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}

	Scanner sc = new Scanner(System.in);

	void run() {

		int a[] = new int[4];
		for(int i =0 ;i < 4; i++){
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		int b[] = {1,4,7,9};
		for(int i =0 ; i < 4; i++){
			if(a[i] != b[i]){
				System.out.println("NO");
				return ;
			}
		}
		System.out.println("YES");
	}
}


Measured memory_bytes: 23252
#include<stdio.h>
int main(){
  int i,j,k,n,m,l;

  scanf("%d%d%d",&n,&m,&l);
  int A[n][m],B[m][l];
  long long C[n][l];
  for(i = 0;i < n;i++){
    for(j = 0;j < m;j++){
      scanf("%d",&A[i][j]);
    }
  }
  for(i = 0;i < m;i++){
    for(j = 0;j < l;j++){
      scanf("%d",&B[i][j]);
    }
  }
  
  for(i = 0;i < n;i++){
    for(j = 0;j < l;j++){
      C[i][j] = 0;
      for(k = 0;k < m;k++){
	C[i][j] += A[i][k] * B[k][j];
      }
      printf("%ld",C[i][j]);
      if(j != l-1){
	printf(" ");
      }
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2112
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>
#include<chrono>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 long long
#endif

#define all(x) x.begin(), x.end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));


struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

ll mod = 1e9 + 7;

namespace {
    ll mul(ll a, ll b) {
        ll val = a * b - (ll)((ld)a * b / mod) * mod;
        if (val < 0) val += mod;
        if (val >= mod) val -= mod;
        return val;
    }
    ll poww(ll a, ll b) {
        ll val = 1;
        a %= mod;
        while (b > 0) {
            if (b % 2) val = mul(a, val);
            a = mul(a, a);
            b >>= 1;
        }
        return val % mod;
    }
    ll inv(ll a) {
        return poww(a, mod - 2);
    }
}

ll const maxn = 3e5+5;

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("output.txt", "w", stdout);
    ll n; cin >> n;
    unordered_map<ll, ll>cnt;
    ll sm = 0;
    for (ll i = 0; i < n; i++) {
        ll x; cin >> x;
        cnt[x]++;
        sm += x;
    }

    ll q; cin >> q; while (q--) {
        ll b, c; cin >> b >> c;
        sm -= cnt[b] * b;
        sm -= cnt[c] * c;
        
        cnt[c] += cnt[b];
        cnt[b] = 0;
        sm += cnt[c] * c;
        cout << sm << '\n';
    }

    return 0;
}

/*

*/

Measured memory_bytes: 6972
#include <iostream>

using namespace std;

int main() {
	int i, j, o_len, e_len;
	string o, e;

	cin >> o;
	cin >> e;

	o_len = o.size();
	e_len = e.size();

	i = 0;
	while (1) {
		if (i < o_len)
			cout << o[i];
		else
			break;

		if (i < e_len)
			cout << e[i];
		else
			break;
		i++;
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N  = scan.nextInt();
        int K  =scan.nextInt();
        int[] A = new int[N];
        for(int i=0;i<N;++i)A[i]=scan.nextInt();
        int index = 0;
        for(int i=0;i<N;++i)if(A[i]==1)index=i;
        int ans = index/(K-1);
        index = (K-1)*ans;
        while(index<N-1){
            index+=(K-1);
            ++ans;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 50232
#  --*-coding:utf-8-*--

def dsMakeSet(ds, x):
    ds[x] = x


def dsFind(ds, x):
    if ds[x] == x:
        return x

    x0 = x
    while ds[x] != x:
        x = ds[x]

    ds[x0] = x
    return x


def dsUnion(ds, x, y):
    xRoot = dsFind(ds, x)
    yRoot = dsFind(ds, y)
    
    if xRoot != yRoot:
        ds[yRoot] = xRoot
        return True

    return False



def dsUpdate(ds):
    for x0 in ds:
        x = x0
        while ds[x] != x:
            x = ds[x]

        root = x
        x = x0

        while ds[x] != root:
            y = ds[x]
            ds[x] = root
            x = y


def main():
    N, M = map(int, input().split())
    P = list(map(int, input().split()))

    ds = {x:x for x in range(1, N+1)}
    for x, y in [map(int, input().split()) for _ in range(M)]:
        dsUnion(ds, x, y)
        
    dsUpdate(ds)

    Q = {}
    for x, root in ds.items():
        if not root in Q:
            Q[root] = set()

        Q[root].add(x)

    cnt = 0

    for q in Q.values():
        p = set(P[x-1] for x in q)
        cnt += len(q&p)

    print(cnt)



if __name__ == '__main__':
    main()


Measured memory_bytes: 62076
import sys
input = sys.stdin.readline

H,W,N = map(int,input().split())
A = []
for i in range(N):
    a,b = map(int,input().split())
    for i in [-1,0,1]:
        for j in [-1,0,1]:
            if (1< a+i <H) and (1 < b+j < W):
                A.append([a+i,b+j])
A.sort()
ans = [0]*10
hoge = 0
for i in range(len(A)):
    if A[i] == A[i-1]:
        hoge += 1
    else:
        ans[hoge]+= 1
        hoge = 1
ans[hoge]+= 1


ans[0] = (W-2)*(H-2)-sum(ans[1:])

for i in ans:
    print(i)

Measured memory_bytes: 156140
#include<iostream>
#include<vector>
#include<string>
using namespace std;
class change {
public:
	char after, before;
};
int main() {
	int n, m;
	while (cin >> n&&n) {
		vector<change>C(n);
		for (int i = 0; i < n; i++) {
			cin >> C[i].before >> C[i].after;

		}
		cin >> m;
		string s;
		for (int i = 0; i < m; i++) {
			char x;
			bool f = false;
			cin >> x;
			for (int j = 0; j < n; j++) {
				if (x == C[j].before) {
					s += C[j].after;
					f = true;
					break;
				}
			}
			if (!f)s += x;

		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 1332
#include <bits/stdc++.h>
#define REP(i, n) for(long long i = 0; i < (long long)(n); i++)
using namespace std;
using ll = long long;
using vec = vector<ll>;

int main() {
    ll A, B, N, max = 0, x, y, ans;
    cin >> A >> B >> N;



    if(N <= 10000000000){
        REP(i, N + 1){
            y = i;
            ans = (A * y / B) - (A * (y / B));
            if(ans >= max) {
                max = ans;
            }
        }
    } else {

    REP(i, 1000000000000000000){
        x = B * pow(10, i);
        y = x - 1;

        if(y > N){
            break;
        }

        ans = (A * y / B) - (A * (y / B));

        if(ans >= max){
            max = ans;
        }
    }
    }
  
  if(max == 0) {
        y = N-1;
        ans = (A * y / B) - (A * (y / B));
        max = ans;
    }


    cout << max << endl;
}


Measured memory_bytes: 3744
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] X = new int[N];
    int[] L = new int[N];
    for (int i = 0; i < N; i++) {
      X[i] = sc.nextInt();
      L[i] = sc.nextInt();
    }
    sc.close();

    Integer[] idx = new Integer[N];
    for (int i = 0; i < N; i++) idx[i] = i;
    Arrays.sort(idx, (l, r) -> Integer.compare(X[l] + L[l], X[r] + L[r]));

    int ans = 0;
    int c = Integer.MIN_VALUE;
    for (Integer i : idx) {
      int x = X[i];
      int l = L[i];
      if (c <= x - l) {
        ans++;
        c = x + l;
      }
    }
    System.out.println(ans);    
  }
}

Measured memory_bytes: 85960
h,w = map(int, input().split())
s = [input()+"." for i in range(h)] + ["."*(w+1)]
INF = 10 ** 18
dp = [[INF]*(w+1) for i in range(h+1)]
dp[0][0] = 1 if s[0][0] == "#" else 0
for i in range(h):
  for j in range(w):
    if s[i][j] == "#":
      dp[i+1][j] = min(dp[i+1][j], dp[i][j])
      dp[i][j+1] = min(dp[i][j+1], dp[i][j])
    else:
      vi = 1 if s[i+1][j] == "#" else 0
      vj = 1 if s[i][j+1] == "#" else 0
      dp[i+1][j] = min(dp[i+1][j], dp[i][j]+vi)
      dp[i][j+1] = min(dp[i][j+1], dp[i][j]+vj)
print(dp[h-1][w-1])

Measured memory_bytes: 42992
#include<iostream>

using namespace std;

long long pn[1000][2];
int len = 0;


int main() {
  int N;
  int f;

  cin >> N;

  int n = 1;
  while (n != N) {
    n++;
    int j = n;
    while (j != 1) {
      bool f = false;
      for (int i = 0; i < len; i++) {
        if (j % pn[i][0] == 0) {
          pn[i][1] += 1;
          f = true;
          j /= pn[i][0];
        }
      }
      if (!f) {
        pn[len][0] = n;
        pn[len][1] = 2;
        len += 1;
        j /= n;
      }
    }
  }

  long long cnt = 1;
  for (int i = 0; i < len; i++) {
    cnt *= pn[i][1];
    cnt = cnt % 1000000007;
  }


  cout << cnt << endl;

  return 0;
}


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

int main() {
  int N,a;
  cin >> N;
  vector<int> vec(N);
  for (int i=0;i<N;i++){
    cin >> a;
    vec.at(i)=a;
  }
  int i=1,j=0;
  while(i != 2){
    i=vec.at(i-1);
    j++;
    if (j>N){
      j=-1;
      break;
    }
  }
  cout << j << endl;
}

Measured memory_bytes: 640
X, K, D = map(int, input().split())

if abs(X) >= K * D:
  if X > 0:
    ans = X - K * D
  else:
    ans = X + K * D
  print(abs(ans))
else:
  count = int(abs(X) / D)
  if X > 0:
    one = X - D * count
    two = one - D
    if (K - count) % 2 == 0:
      print(abs(one))
    else:
      print(abs(two))
  else:
    one = X + D * count
    two = one + D
    if (K - count) % 2 == 0:
      print(abs(one))
    else:
      print(abs(two))
      
      
    



Measured memory_bytes: 61724
#include <stdio.h>
int main(void) {
    int n,out,first,second,third,score,i;
    char event[7];
    scanf("%d\n",&n);
    for (i=0; i<n; i++) {
        first=0,second=0,third=0,score=0,out=0;
        while (1) {
            scanf("%s\n",event);
            if (event[0]=='O') {
                out++;
                if (out==3) break;
            }
            if (event[0]=='H') {
                if (event[1]=='I') {
                    if (third==1) {
                        score++;
                        third--;
                    }
                    if (second==1) {
                        third++;
                        second--;
                    }
                    if (first==1) {
                        second++;
                        first--;
                    }
                    first++;
                } else {
                    score+=first+second+third+1;
                    first=0,second=0,third=0;
                }
            }
        }
        printf("%d\n",score);
    }
    return 0;
}

Measured memory_bytes: 600
c1=list(map(int,input().split()))
c2=list(map(int,input().split()))
c3=list(map(int,input().split()))
if c1[1]-c1[0]==c2[1]-c2[0]==c3[1]-c3[0] and c1[2]-c1[1]==c2[2]-c2[1]==c3[2]-c3[1]:
    print("Yes")
else:
    print("No")

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

int main(void){
    int n,m,i;
    cin >> n;
    vector<string> s(n);
    for(i=0;i<n;i++){
        cin >> s[i];
    }
    cin >> m;
    vector<string> t(m);
    for(i=0;i<m;i++){
        cin >> t[i];
    }
    vector<pair<int,string> > table;
    while(!s.empty()){
        string tmp = s[0];
        s.erase(s.begin());
        int cnt=1;
        for(i=s.size()-1;i>=0;i--){
            if(tmp == s[i]){
                cnt++;
                s.erase(s.begin()+i);
            }
        }
        for(i=t.size()-1;i>=0;i--){
            if(tmp == t[i]){
                cnt--;
                t.erase(t.begin()+i);
            }
        }
        table.push_back(make_pair(cnt, tmp));
    }
    int M = (*max_element(table.begin(),table.end())).first;
    cout << max(M, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define INF 100000
int main(void)
{
    char phone[10][6] = {"", ".,!? ", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
    char message[3000];
    int buf;
    int t;
    int i, j;
     
    scanf("%d", &t);
     
    while (t--){
        scanf("%s", message);
        getchar();
         
        i = 0;
        while (message[i] != '\0'){
            buf = INF;
            j = 0;
            while ('0' <= message[i] && message[i] <= '9' && message[i] != '0' && message[i] != '\0'){
                buf = phone[message[i] - '0'][j % strlen(phone[message[i] - '0'])];
                j++;
                if (message[i + 1] != '0' && i + 1 < strlen(message) && message[i] != message[i + 1]){
                    j = 0;
                }
                i++;
            }
            if (!('0' <= message[i] && message[i] <= '9') || message[i] != '0'){
                buf = INF;
            }
            if (buf != INF){
                printf("%c", buf);
            }
            if (message[i] == '\0'){
                break;
            }
            i++;
        }
        printf("\n");
    }
     
    return (0);
}

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

using namespace std;
typedef long long ll;
const int M = 100;

int main() {
    int n;
    cin >> n;
    vector<int> ans(n + 1);
    for (int x = 1; x <= M; x++) {
        for (int y = 1; y <= M; y++) {
            for (int z = 1; z <= M; z++) {
                int f = x * x + y * y + z * z + x * y + x * z + y * z;
                if (f <= n) ans[f]++;
            }
        }
    }
    for (int i = 1; i <= n; i++) cout << ans[i] << "\n";
}


Measured memory_bytes: 3556
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>

#define INF 100000000

using namespace std;

int main()
{
    int n,m,c;
    cin >> n >> m >> c;
    int b[m];
    for(int i = 0;i<m;i++)
    {
        cin >> b[i];
    }
    int a[n][m];
    int ans = 0;
    for(int i = 0;i<n;i++)
    {
        int tmp = 0;
        for(int j = 0;j<m;j++)
        {
            cin >> a[i][j];
            tmp += a[i][j]*b[j];
        }if(tmp + c > 0)
        ans++;   
    }
    cout << ans << endl;


    return 0;
}


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

a.sort()
x = [a[1],a[0],a[1] % a[0]]
for i in range(1,n):
    while x[2] > 0:
        x[0] = x[1]
        x[1] = x[2]
        x[2] = x[0] % x[1]
    if i != n - 1:
        x[0] = a[i+1]
        x[2] = x[0] % x[1]

print(x[1])


Measured memory_bytes: 14252
import java.util.*;
import java.io.*;
class Main{
   
public static void main (String[] args) {
    Scanner sc=new Scanner(System.in);
    int h=sc.nextInt();
    int w=sc.nextInt();
    int n=sc.nextInt();
    System.out.println((int)Math.min((int)Math.ceil((double)n/h),(int)Math.ceil((double)n/w)));
}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n';
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll mod=1e9+7;

int main(){
	IOS;
	string s;
	cin>>s;
	int one=0,two=0;
	for(auto i:s){
		if(i=='0') one++;
		else two++;
	}
	cout<<2*min(one,two)<<endl;
	return 0;
}

Measured memory_bytes: 512