akhauriyash/Code-Regression huggingface dataset:
n, m = map(int,input().split())
lists = [1,2]
bag_step = [-1]
last = 0
conbi = 1
 
def conbination(num):
    if len(lists) >= num:
        return lists[num-1]
    for i in range(len(lists),num):
        lists.append(lists[i-1]+lists[i-2])
    return lists[num-1]
 
for i in range(m):
    bag_step.append(int(input())) #穴が空いているステップ
bag_step.append(n+1)
for i in range(1,len(bag_step)):
  if bag_step[i] == bag_step[i-1] + 1:
    conbi = 0
    break
  if bag_step[i] == bag_step[i-1] + 2:
    continue
  conbi = conbi * conbination(bag_step[i] - bag_step[i-1] - 2)%(1000000007)
print(conbi)

Measured memory_bytes: 460020
#include<bits/stdc++.h>
#define inf 0x7fffffff
#define eps 1e-4
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const double pi = acos(-1);
inline ll read(){
    ll x = 0, f = 1;
    char ch = getchar();
    while(ch > '9' || ch < '0') {if(ch == '-') f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9'){x = x *10 + ch -'0';ch = getchar();}
    return x * f;
}

int n,k;
int a[200005];
int main(){
    int i,j;
    //freopen("a.out","r",stdin);
    //freopen("a.ans","w",stdout);
    n=read(),k=read();
    for(i=1;i<=n;i++) a[i]=read();
    for(i=k+1;i<=n;i++) 
					if(a[i]>a[i-k]) puts("Yes");
    				else puts("No");
    return 0;
}
/*
6
8 4
8 -4
5 5
5 -5
1 3
1 -3
*/

Measured memory_bytes: 4412
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

int main(){
    string S;
    cin>>S;
    int k=S.size();
    int cnt = 0;
    for(int i=0; i<k; i++){
        if(S[i]=='x')cnt++;
    }
    if(cnt>=8)cout<<"NO";
    else cout<<"YES";
    return 0;
}

Measured memory_bytes: 256
n = int(input())
mod = 10**9 + 7
divisor = [[i,0] for i in range(n+1)]


def factorization(n):
    arr = []
    temp = n
    for i in range(2,int(-(-n**0.5//1))+1):
        if temp%i == 0:
            cnt = 0
            while temp%i == 0:
                cnt += 1
                temp //= i
            arr.append([i,cnt])
    
    if temp != 1:
        arr.append([temp,1])
    
    if arr == []:
        arr.append([n,1])
    return arr

for i in range(2,n+1):
    lst = factorization(i)
    for l in lst:
        divisor[l[0]][1] += l[1]

ans = 1
for d in divisor:
    if d[1] != 0:
        ans *= (d[1] + 1)
        ans %= mod
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long int
using namespace std;
int32_t main()
{
	int a, b, c; cin >> a >> b >> c;
	int x[c + 50], y[c + 50], mx = 0, my = 0, cntx[a + 50] = {0}, cnty[b + 50] = {0};
	for(int i=0; i<c; i++)
	{
		cin >> x[i] >> y[i];
		cntx[x[i]] ++; mx = max(mx, cntx[x[i]]);
		cnty[y[i]] ++; my = max(my, cnty[y[i]]);
	}
	int t1 = 0, t2 = 0;
	for(int i=1; i<=a; i++) if(cntx[i] == mx) t1 ++;
	for(int i=1; i<=b; i++) if(cnty[i] == my) t2 ++;
	int t = t1 * t2;
	for(int i=0; i<c; i++)
	{
		if(cntx[x[i]] == mx && cnty[y[i]] == my) t --;
	}
	if(t) cout << mx + my;
	else  cout << mx + my - 1;
	cout << '\n';
	return 0;
}

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

int n;
vector<int> v1,v2;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		v1.push_back(x+y);
		v2.push_back(x-y);
	}
	sort(v1.begin(),v1.end());
	sort(v2.begin(),v2.end());
	printf("%d\n",max(v1[v1.size()-1]-v1[0],v2[v2.size()-1]-v2[0]));
	return 0;
}

Measured memory_bytes: 5112
#include <stdio.h>
struct Node{ int p, l, r;};
struct Node T[100000];
int n, H, D[100000];
int Depth(int x){
  int i;
  for(i=0; T[x].p != -1 ;i++) x = T[x].p;
  return i;
}
void print(int x){
  int i, c;
  printf("node %d: parent = %d, depth = %d,", x,T[x].p,D[x]);
  if ( T[x].p == -1 ) printf(" root, ");
  else if ( T[x].l == -1 ) printf(" leaf, ");
  else printf(" internal node, ");
  printf("[");
  for(i = 0, c = T[x].l; c != -1; i++, c = T[c].r){
    if (i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
}
int main(){
  int i, j, d, v, c, l;
  scanf("%d", &n);
  for ( i = 0; i < n; i++ )
    T[i].p = T[i].l = T[i].r = -1;
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &v, &d);
    for ( j = 0; j < d; j++ ){
      scanf("%d", &c);
      if ( j == 0 ) T[v].l = c;
      else T[l].r = c; l = c; T[c].p = v;
    }
  }
  H = 0;
  for ( i = 0; i < n; i++ ){
    D[i] = Depth(i);
    if ( D[i] > H ) H = D[i];
  }
  for ( i = 0; i < n; i++ ) print(i);
  return 0;
}



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

int main(){
    int A,B;
    cin>>A>>B;
    
    char a[101][101];
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            if(i<=50)a[i][j]='.';
            else a[i][j]='#';
        }
    }
    
    int i=1,j=1;
    while(B>1){
        a[i][j]='#';
        B--;
        j+=2;
        if(j==101){j=1;i+=2;}
    }
    
    i=52;j=1;
    while(A>1){
        a[i][j]='.';
        A--;
        j+=2;
        if(j==101){j=1;i+=2;}
    }
    
    cout<<"100 100"<<endl;
    
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            cout<<a[i][j];
        }
        cout<<endl;
    }    
}

Measured memory_bytes: 256
//#pragma GCC optimize(\"Ofast,no-stack-protector\")
//#pragma GCC target(\"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx\")
//#pragma GCC target(\"avx,tune=native\")
// Neil

#include<bits/stdc++.h>

using namespace std;

typedef complex<double> base;
typedef long double ld;
typedef long long ll;

#define endl "\n"
#define pb push_back
#define pii pair<int,int>
#define pll pair< ll , ll >
#define vi vector<int>
#define vvi vector< vi >
const int MAXN=(int)(2e5+5);
const ll MOD=(ll)(1e9+7);
int t;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int s = 0;
    if(k>0){
        s = s+min(a,k);
        k-=min(k,a);
    }
    if(k>0){
        k -= min(k,b);
    }
    if(k>0){
         s -= min(k,c);
        k -= min(k,c);  
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;

#define DEBUG(x) // cerr << #x << " = " << x << endl

typedef pair<int, int> P;

int D[30][30][4];
int dist[30][30];

int main() {
    for(int W, H; cin >> W >> H, W + H > 0; ) {
        for(int x = 0; x < W - 1; x++) {
            int k; cin >> k;
            D[0][x][0] = D[0][x + 1][2] = k;
        }
        for(int y = 0; y < H - 1; y++) {
            for(int x = 0; x < W; x++) {
                int k; cin >> k;
                D[y][x][3] = D[y + 1][x][1] = k;
            }
            for(int x = 0; x < W - 1; x++) {
                int k; cin >> k;
                D[y + 1][x][0] = D[y + 1][x + 1][2] = k;
            }
        }

        P g = P(H - 1, W - 1);
        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) {
                dist[i][j] = -1;
            }
        }
        queue<P> Q;
        Q.push(P(0, 0));
        dist[0][0] = 1;
        int ans = 0;
        while(!Q.empty()) {
            P p = Q.front(); Q.pop();
            DEBUG(p.first); DEBUG(p.second);
            if(p == g) {
                ans = dist[p.first][p.second];
                break;
            }
            const int dy[4] = { 0, -1, 0, 1 };
            const int dx[4] = { 1, 0, -1, 0 };
            for(int i = 0; i < 4; i++) {
                int ny = p.first + dy[i];
                int nx = p.second + dx[i];
                DEBUG(i);
                DEBUG(ny); DEBUG(nx);
                DEBUG(D[p.first][p.second][i]);
                if(!(0 <= nx && nx < W && 0 <= ny && ny < H)) continue;
                if(D[p.first][p.second][i] == 1 || dist[ny][nx] != -1) continue;
                DEBUG(ny); DEBUG(nx);
                Q.push(P(ny, nx));
                dist[ny][nx] = dist[p.first][p.second] + 1;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

#define MOD 1000000007

vector<ll> make_v(ll n){
  vector<ll> ret(n);
  for(ll i=0; i<n/2+1; i++){
    ret[i] = (n-i)*(i+1)%MOD;
    ret[n-1-i] = (n-i)*(i+1)%MOD;
  }
  return ret;
}

int main(){
  int n, m;
  cin >> n >> m;
  vector<ll> x, y;
  rep(i,n){
    ll tmp;
    cin >> tmp;
    x.push_back(tmp);
  }
  rep(i,m){
    ll tmp;
    cin >> tmp;
    y.push_back(tmp);
  }

  vector<ll> a = make_v(n-1);
  vector<ll> b = make_v(m-1);

  ll asum = 0;
  ll bsum = 0;
    
  rep(i,a.size()){
    asum += a[i]*(x[i+1]-x[i])%MOD;
    asum %= MOD;
  }
  rep(i,b.size()){
    bsum += b[i]*(y[i+1]-y[i])%MOD;
    bsum %= MOD;
  }
  ll ret = asum*bsum;
  ret %= MOD;

  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 3572
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
int main(){
	int d, x, y, Y[600];
	int i, sum = 0;

	

	for(i = 0;i < 600;i++){
		Y[i] = 0;
	}
	while(cin >> d){
		for(i = 1;d*i < 600;i++){
			x = d * i;
			y = x * x;
			Y[i] = y * d;
		}
		
		for(i = 1;i < 600;i++){
			sum += Y[i];
		}
		cout << sum << endl;
		sum = 0;
	}
	return 0;
}

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

int main() {
	int n; cin >> n;
    while (n!=0)
    {
        vector<int> cnt(26,0);
        int d=n;
        char tmp; 

        for (int i = 0; i < n; i++)
        {
            cin >> tmp;
            ++cnt[tmp-'A'];
            auto itr1=max_element(cnt.begin(),cnt.end());
            int m;
            if(itr1-cnt.begin()==0){
                auto mitr1=max_element(cnt.begin()+1,cnt.end());
                m=*mitr1;
            }else if(itr1-cnt.begin()==25){
                auto mitr1=max_element(cnt.begin(),cnt.end()-1);
                m=*mitr1;
            }else{
                auto mitr1=max_element(cnt.begin(),itr1);
                auto mitr2=max_element(itr1+1,cnt.end());
                m=max(*mitr1, *mitr2);
            }
            if(*itr1-m>n-1-i && d==n){
                d=i+1;
            }
        }

        auto itr=max_element(cnt.begin(),cnt.end());
        
        if(count(cnt.begin(),cnt.end(),*itr)>1){
            cout << "TIE" << endl;
        }else{
            cout << char('A'+itr-cnt.begin()) << " " << d << endl;
        }//うまいやり方を教えてもらう
        cin >> n;
    }
    
}
//g++ -o b.exe b.cpp


Measured memory_bytes: 3088
package main

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

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func main() {
	N := getStdinInt64()
	Nori := N
	arr := make([]bool, int(math.Sqrt(float64(N)))+1)

	// 初期化
	for i := 2; i < len(arr); i++ {
		arr[i] = true
	}
	// 素数を求める
	arr[0] = false
	arr[1] = false
	for i := 2; i < len(arr); i++ {
		if arr[i] {
			for j := i * 2; j < len(arr); j += i {
				arr[j] = false
			}
		}
	}
	// 割り切れるか判別（素因数分解）
	cnt := 0
	var i int64
	for i = 2; int(i) < len(arr); i++ {
		if arr[i] && (N%i) == 0 {
			mul := i
			pow := 1
			for {
				if N%mul == 0 {
					cnt++
					N /= mul
					pow++
					mul = 1
					for n := 0; n < pow; n++ {
						mul *= i
					}
				} else {
					break
				}
			}
			if N <= 1 {
				break
			}
		}
	}
	if N > 1 && int(N) > len(arr) {
		cnt++
	}

	if cnt == 0 && (Nori == 0 || Nori == 1) {
		fmt.Printf("%d\n", 0)
	} else if cnt == 0 {
		fmt.Printf("1\n")
	} else {
		fmt.Printf("%d\n", cnt)
	}
}

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 2832
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<30;
const ll LINF = 1LL<<58;
const ll mod = 1000000007;

int used[110];

void DFS(vector<vector<int>> Graph, int s){
    used[s]++;
    for (auto x : Graph[s]) if(!used[x]) DFS(Graph, x);
    return;
}

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> A(m), B(m);
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        A[i] = a;
        B[i] = b;
    }
    int ans = 0;
    rep(i,m) {
        vector<vector<int>> G(50, vector<int> (50));
        rep(j,m){
            if(i==j) continue;
            G[A[j]].pb(B[j]);
            G[B[j]].pb(A[j]);
        }
        memset(used, 0, sizeof(used));
        DFS(G, 0);
        bool ren = true;
        rep(j,n) if(!used[j]) ren = false;
        if(!ren) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 908
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
   int n;
   int num;
   int sum=0;
   cin>>n>>num;
   int x;
   for(int i=1;i<=n;i++)
   {
       cin>>x;
       if(num-x>=x)sum+=x;
       else sum+=num-x;
   }
   cout<<sum*2<<endl;
}


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

template<typename T_char>
T_char ToUpper(T_char cX){return toupper(cX);}

int main(){
  ll n, s = 0;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; ++i){
    cin >> a[i];
    s += a[i];
  }

  ll sum = 0;
  ll mn = s;
  for(int i=0; i<n; ++i){
    sum += a[i];
    mn = min(mn, abs(sum- (s- sum)));
  }

  cout << mn << endl;

}

Measured memory_bytes: 4052
#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;

#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define REP(i,m,n) for(int i=m; i<=(int)(n); ++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(),a.end()
#define FOR(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)

int n;

string in[5];

bool nok(int sz){
  rep(i,5)
    rep(j,SZ(in[i]))
    if(sz+j<SZ(in[i]))
      if(in[i][j]=='X' && in[i][sz+j]=='X')
        return true;

  return false;
}

bool nokl[200];
int ans;
int len[10];
void dfs(int ne,int nlen){
  if(ne==10){
    if(nlen+n-1<ans){
      ans = nlen+n-1;
      //cout << ans << endl;
    }
    return;
  }
  
  //cout << ne << ' ' << nlen << endl;

  for(int i=nlen;i<=nlen+n-1;++i){
    //if(i+n>ans) break;
    bool tok = false;
    rep(j,ne) if(nokl[i-len[j]]){
      tok=true;
      break;
    }
    if(tok) continue;
    len[ne] = i;
    dfs(ne+1,i+1);
  }
}

void solve(){
  memset(nokl,0,sizeof(nokl));
  rep(i,5) cin >> in[i];

  
  rep(i,SZ(in[0])){
    nokl[i+1] = nok(i+1);
    //if(nokl[i+1]) cout << i+1 << endl;
  }
  ans = 10*n;
  dfs(0,0);
  cout << ans << endl;
}

main(){
  while(cin >> n,n) solve();
}

Measured memory_bytes: 1204
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <bitset>
#include <list>
#include <cmath>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; ++i) {
		cin >> p.at(i);
	}
	int min = n + 1;
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		if (p.at(i) <= min) {
			ans++;
			min = p.at(i);
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
long long arr[205][205];
long long min(long long a,long long b) {
	return a>b?b:a;
}
int main() {
	long long n,m;
	while(scanf("%lld %lld",&n,&m)!=EOF) {
		long long x,y,c;
		for(int i=0; i<205; i++) {
			for(int j=0; j<205; j++) {
			arr[i][j]=10000000000;
			}
		}
		for(long long j=1; j<=m; j++) {
			scanf("%lld %lld %lld",&x,&y,&c);
//				arr[x][y]=min(arr[x][y],c);
				arr[x][y]=c;
		}
		for(int k=0; k<n; k++) {
			for(int i=0; i<n; i++) {
				for(int j=0; j<n; j++) {
				    if(arr[i][k]<10000000000&&arr[k][j]<10000000000){
				      arr[i][j]=min(arr[i][j],arr[i][k]+arr[k][j]);	
					}
				}
			}
		}
//		printf("\n");
		int t=0;
		for(int i=0; i<n; i++) {
			if(arr[i][i]<0) {
				t=1;
			}
		arr[i][i]=0;	
		}
		if(t==1) {
			printf("NEGATIVE CYCLE\n");
		} else {
			for(int i=0; i<n; i++) {
				for(int j=0; j<n; j++) {
					if(arr[i][j]==10000000000){
						if(j!=n-1) printf("INF ");
						 else printf("INF");
					}else{
						if(j!=n-1) printf("%lld ",arr[i][j]);
						 else  printf("%lld",arr[i][j]); 
					} 
				}
				printf("\n");
			}
		}
	}
	return 0;
}































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

int main() {
  int N, K;
  cin >> N >> K;
  int w = 1;
  
  for (int i=0; i<N; i++) {
    if (w > K) {
      w += K;
    }
    else {
      w *= 2;
    }
  }
  
  cout << w << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void solve()
{
	int n, m;
	while(cin >> n >> m, n || m)
	{
		vector<int> Vec;
		int temp;
		for(int i = 0; i < n; ++i)
		{
			cin >> temp;
			Vec.push_back(temp);
		}
		for(int i = 0; i < m; ++i)
		{
			cin >> temp;
			Vec.push_back(temp);
		}
		sort(Vec.begin(), Vec.end());
		int Max = 0;
		int pos = 0;
		for(int i = 0; i < n + m; ++i)
		{
			Max = max(Vec[i] - pos, Max);
			pos = Vec[i];
		}
		cout << Max << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1016
#include<iostream>
#include<stack>

using namespace std;

int main(){
    long long s;
    stack<char> ans;
    cin>>s;
    while(s){
        s-=1;
        ans.push(char('a'+s%26));
        s=s/26;
    }
    while(!ans.empty()){
        cout<<ans.top();
        ans.pop();
    }
    cout<<endl;
    return 0;
}

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

int main()
{
    int n;
    unsigned long long result = 1, border = 1000000000000000000;

    cin >> n;

    vector<unsigned long long> a(n);

    for (auto &i: a)
    {
        cin >> i;
        if(0 == i)
        {
            cout << 0 << endl;
            return 0; 
        }
    }
    sort(a.begin(),a.end());

    for (int i = 0; i < n ; i++)
    {
        result *= a.at(i);
        border /= a.at(i);

        if(border <= 0 )
        {
            cout << -1 << endl;
            return 0;        
        }
    }

    cout << result << endl;
    return 0;
}

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

using namespace std;

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 2e5+5;
int n, a[MX];
ll res = 0;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];

		if ((!i && a[i]) || (i && a[i-1] < a[i] - 1)) {
			cout << -1 << endl;
			return 0;
		}

		res += a[i];
		if (i && a[i-1] + 1 == a[i])
			res -= a[i-1];
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

//cout << fixed << setprecision(10);//
//最小公倍数//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//べき//
ll squ(ll n, ll p, ll m){
	if(p==0) return 1;
	if(p%2==0){
		ll t=squ(n, p/2, m);
		return t*t%m;
	}
	return n*squ(n,p-1,m);
	
}


//逆元mod(mを法とするaの逆元)//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
ll COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//nが大

ll com(ll n,ll m){
	if(n<=0 || m<=0 || n==m){
		return 1;
	}
	if(n<m){
		return 0;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}

	return k;
}


//


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




int main() {
ll n,x,y;
cin>>n>>x>>y;

ll k[n+1];
for(int i=1;i<=n-1;i++){
k[i]=0;
}


for(ll j=1;j<=n-1;j++){
	for(ll i=j+1;i<=n;i++){

if(i<=x){
	k[i-j]++;
	continue;
}
if(j>=y){
	k[i-j]++;
	continue;
}
if(j<=x && i>=y){
	k[x-j+1+i-y]++;
	continue;
}
if(x<=j && y>=i){
	ll p=min(j-x+y-i+1,i-j);
	k[p]++;
	continue;
}
if(x>=j && y>=i){
	ll p=min(x-j+1+y-i, i-j);
	k[p]++;
	continue;
}

ll p=min(j-x+1+i-y, i-j);
k[p]++;
continue;




	}
}

for(int i=1;i<=n-1;i++){
cout<<k[i]<<endl;
}
return 0;

}



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

int main() {
	int n; cin >> n;
	vector<long long>h(n+100,(int)1e9+500);
	for (int i = 0; i < n; i++) {
		int tmp; cin >> tmp;
		h[i] = tmp;
	}

	int tmpAns = 0, ans = 0;
	for (int i = 1; i <= n; i++) {
		if (h[i] <= h[i - 1])tmpAns++;
		else {
			ans = max(ans, tmpAns);
			tmpAns = 0;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
main :: IO ()
main = fmap (map read . words) getLine >>= \[x,y] -> print $ ans' x y

ans' :: Int -> Int -> Int
ans' m n = if m <= q then g (n-m*2) m else q where
  q = n `div` 2
  g :: Int -> Int -> Int
  g s m = m + s `div` 4


Measured memory_bytes: 508
#include <cstdio>
using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    int array[n];
    for(int x = 1;x <= n;x++)
        scanf("%d",&array[x]);
    for(int x = n;x > 1;x--)printf("%d ",array[x]);
    printf("%d\n",array[1]);
}


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

int main()
{
	vector<vector<int>> cv(3, vector<int>(3));

	for (auto& i : cv) {
		for (auto& j : i) {
			cin >> j;
		}
	}

	vector<int> diff12(3, 0);
	for (int i = 0; i < 3; ++i) {
		diff12[i] = cv[0][i] - cv[1][i];
	}

	vector<int> diff13(3, 0);
	for (int i = 0; i < 3; ++i) {
		diff13[i] = cv[0][i] - cv[2][i];
	}

	bool isYes = true;
	if (diff12[0] != diff12[1] || diff12[1] != diff12[2]) {
		isYes = false;
	}
	if (diff13[0] != diff13[1] || diff13[1] != diff13[2]) {
		isYes = false;
	}

	if (isYes) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define all(x) (x).begin(),(x).end()
#define print(x) if(x)cout<<"YES\n";else cout<<"NO\n";
#define f(i,x,y) for(ll i=x;i<=y;i++)
#define rf(i,x,y) for(ll i=x;i>=y;i--)
#define pb push_back
#define F first
#define S second
using namespace std;
int main()
{
// #ifndef HP
//   freopen("in.txt", "r", stdin);
//   freopen("out.txt", "w", stdout);
// #endif

  fastio;
  int q = 1;
  //cin >> q;
  while (q--)
  {
    ll x;
    cin>>x;
    cout<<(!x)<<endl;
  }
}

Measured memory_bytes: 3644
n,x,y=gets.split.map(&:to_i)
l=[0]*n
1.upto(n) do |i|
  (i+1).upto(n) do |j|
    if (i<=(x+y)/2&&j<=(x+y)/2)||(i>=(x+y)/2&&j>=(x+y)/2)||(j-i<=(y-x)/2)
      l[j-i]+=1
    elsif i<=x&&j>=y
      l[j-i-y+x+1]+=1
    elsif i<x
      l[x-i+y-j+1]+=1
    elsif j>y
      l[i-x+j-y+1]+=1
    else
      l[i-x+y-j+1]+=1
    end
  end
end
l.delete_at(0)
puts l


Measured memory_bytes: 1788
n = int(input())

x = [0] * (n + 2)
y = [0] * (n + 2)

ok = False 

for i in range(n):
    x[i],y[i] = map(int,input().split())
    
for i in range(n):
    if i + 2 < n :
        if (x[i],x[i + 1],x[i + 2]) == (y[i],y[i + 1],y[i + 2]):
            ok = True

print("Yes" if ok == True else "No")


Measured memory_bytes: 62444
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdio>

using namespace std;

long long int gcd(long long int a, long long int b) {
    return (b ? gcd(b, a%b) : a);
}

int main()
{
    long long int a, b;

    cin >> a >> b;

    cout << a * b / gcd(a, b) << endl;
}


Measured memory_bytes: 256
import math

n=int(input())
D={}

def DictAppend(n,d):
    if n in d:
        d[n]+=1
    else:
        d[n]=1

for i in range(1,n+1):
    if i==1:
        continue
    now=i
    while now%2==0:
        now//=2
        DictAppend(2,D)
    p=3
    while p<=math.sqrt(i):
        while now%p==0:
            now//=p
            DictAppend(p,D)
        p+=2
        if now==1:
            break
    if now>math.sqrt(i):
        DictAppend(now,D)

P=[74,24,14,4,2]
C=[0,0,0,0,0]
for d in D:
    for i in range(5):
        if D[d]>=P[i]:
            C[i]+=1

ans=0
ans+=C[0] #a**74
if C[4]>1:
    ans+=C[1]*(C[4]-1) #a**24 * b**2
if C[3]>1:
    ans+=C[2]*(C[3]-1) #a**14 * b**4
if C[4]>2:
    ans+=C[3]*(C[3]-1)//2*(C[4]-2) #a**4 * b**4 * c**2
print(ans)

Measured memory_bytes: 3064
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		Arrays.setAll(a, i -> Integer.parseInt(sc.next()));
		Arrays.sort(a);
		System.out.println(a[n - 1] - a[0]);
	}
}


Measured memory_bytes: 35672
//Hey u r too far away to know this
//CHIRAGA196
#include <bits/stdc++.h>
using namespace std;
#define     ff                  first
#define     pb                  push_back
#define     ss                  second
#define     IOS                 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define     all(v)              v.begin(), v.end()
#define     allr(v)             v.rbegin(), v.rend()
#define       int               long long
#define       endl             '\n'
const   int N = 1e6+5, Mod = 1e9 + 7;
int32_t main(){
        IOS;
      
        int n; cin >> n;
        vector<int> v(n);
        int sum = 0;
        for(auto &x:v){
            cin >> x, sum += x;
            sum %= Mod;
        }
        int ans = 0;
        for(int i = 0; i < n; i++){
            sum -= v[i];
            ans += (sum%Mod * v[i]%Mod)%Mod;
            ans %= Mod;
        }
        cout << (ans + Mod)%Mod;
        return 0;
}

Measured memory_bytes: 4780
import java.util.*;

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

		for(int set=1;;set++){
			int n = sc.nextInt();
			if(n == 0) break;

			ArrayList<ArrayList<Edge>> map = new ArrayList<ArrayList<Edge>>();
			for(int i=0;i<=80000;i++){
				map.add(new ArrayList<Edge>());
			}

			for(int i=0;i<n;i++){
				double x = sc.nextDouble();
				double y = sc.nextDouble();
				double r = sc.nextDouble();

				int left = (int)((x - r) * 100) + 40000;
				int right = (int)((x + r) * 100) + 40000;
				for(int j=left;j<right;j++){
					map.get(j).add(new Edge((int)((y-r)*100),true));
					map.get(j).add(new Edge((int)((y+r)*100),false));
				}
			}

			int ans = 0;
			for(int i=0;i<=80000;i++){
				if(map.get(i).isEmpty()) continue;
				Collections.sort(map.get(i));
				int level = 0;
				int top = 0;
				for(Edge e : map.get(i)){
					if(e.d){
						if(level == 0) top = e.place;
						level++;
					}
					else{
						level--;
						if(level == 0) ans += (e.place - top);
					}
				}
			}

			System.out.printf("%d %.2f\n",set,0.0001*ans);
		}
	}
}

class Edge implements Comparable<Edge>{
	int place;
	boolean d; //true : from, false : to

	Edge(int place,boolean d){
		this.place = place;
		this.d = d;
	}

	public int compareTo(Edge e){
		if(place < e.place) return -1;
		if(place > e.place) return 1;
		if(d == false && e.d == true) return 1;
		if(d == true && e.d == false) return -1;
		return 0;
	}
}

Measured memory_bytes: 28000
#[allow(unused_macros)]
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 ) * } };
}
#[allow(unused_macros)]
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 ) * } };
}
#[allow(unused_macros)]
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" ) };
}

#[allow(unused_macros)]
macro_rules! vec_md {
    ( $ init : expr ; $ ( $ dim : expr ) ;* ) => { vec_md ! ( $ ( $ dim ) ;* => $ init ) };
    ( $ head : expr ; $ ( $ tail : expr ) ;* => $ init : expr ) => { vec ! [ vec_md ! ( $ ( $ tail ) ;* => $ init ) ; $ head ] };
    ( $ head : expr => $ init : expr ) => { vec ! [ $ init ; $ head ] };
}

#[allow(dead_code)]
pub const M: u64 = 1_000_000_007;

fn main() {
    input! {
        k: chars,
        dd: usize
    }

    let n = k.len();
    let mut dp = vec_md![0u64;n+1;dd;2];
    let k_nums = k.into_iter().map(|c| (c as u8 - b'0') as usize) .collect::<Vec<_>>();
    dp[0][0][0] = 1;
    for i in 0..n {
        for j in 0..dd {
            for smaller in 0..2 {
                for d in 0..(if smaller == 0 {k_nums[i]+1} else {10}) {
                    dp[i+1][(j + d) % dd][smaller | (smaller == 0 && d < k_nums[i]) as usize]
                        += dp[i][j][smaller];
                    dp[i+1][(j + d) % dd][smaller | (smaller == 0 && d < k_nums[i]) as usize] %= M;
                }
            }
        }
    }
    let mut tmp = (dp[n][0][0] + dp[n][0][1]) as i64;
    tmp %= M as i64;
    tmp -= 1;
    if tmp < 0 {
        tmp += M as i64;
    }
    println!("{}", tmp);
}

Measured memory_bytes: 45308
def main():
    N = int(input().strip())
    A = [int(_a) for _a in input().strip().split()]
    Q = int(input().strip())
    BCS = []
    for i in range(Q):
        BCS.append([int(_bc) for _bc in input().strip().split()])

    Amap = {}
    for a in A:
        if a not in Amap:
            Amap[a] = 0
        Amap[a] += 1

    total = 0
    for k,v in Amap.items():
        total += (k*v)

    for bc in BCS:
        b = bc[0]
        c = bc[1]
        if b in Amap:
            num = Amap[b]

            del Amap[b]
            if c not in Amap:
                Amap[c] = 0
            Amap[c] += num

            total = total + num*c - num*b

        print(total)

main()



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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N, T;
    cin >> N >> T;
    vector<P> items(N);
    rep(i, N) cin >> items[i].first >> items[i].second;
    vector<vector<ll>> dp1(N + 1, vector<ll>(T, 0));
    vector<vector<ll>> dp2(N + 1, vector<ll>(T, 0));
    rep(i, N) {
        P p = items[i];
        rep(t, T) {
            if (t - p.first >= 0) {
                dp1[i + 1][t] = max(dp1[i + 1][t], dp1[i][t - p.first] + p.second);
            }
            dp1[i + 1][t] = max(dp1[i + 1][t], dp1[i][t]);
        }
    }

    rrep(i, N - 1, 0) {
        P p = items[i];
        rep(t, T) {
            if (t - p.first >= 0) {
                dp2[i][t] = max(dp2[i][t], dp2[i + 1][t - p.first] + p.second);
            }
            dp2[i][t] = max(dp2[i][t], dp2[i + 1][t]);
        }
    }
    ll ans = 0;
    rep(i, N) {
        P p = items[i];
        rep(j, T) {
            ans = max(ans, dp1[i][j] + dp2[i+1][T - 1 - j] + p.second);
        }
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 141184
/**
 *    author:  tourist
 *    created: 03.06.2018 15:15:11       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int ans = (int) 1e9;
  for (int a = 1; a < n; a++) {
    int b = n - a;
    int sum = 0;
    int x = a, y = b;
    while (x > 0) {
      sum += x % 10;
      x /= 10;
    }
    while (y > 0) {
      sum += y % 10;
      y /= 10;
    }
    ans = min(ans, sum);
  }
  cout << ans << '\n';
  return 0;
}


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

typedef long long lli;

int main() {
  lli q; cin >> q;
  lli sum = 0;
  while(q--) {
    lli p, n;
    char c;
    cin >> p >> c >> n;
    if(c == '(') sum += n;
    else sum -= n;
    cout << (sum ? "No" : "Yes") << endl;
  }
  return 0;
}

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

int main(){
  int n,count=0;
  cin >> n;
  
  vector<int>vec(n);
  vector<int>veco(3);
  
  for(int i=0;i<n;i++){
    cin >> vec.at(i);
  }
  
  for(int j=0;j<n-2;j++){
    veco = {vec.at(j),vec.at(j+1),vec.at(j+2)};
    
    sort(veco.begin(),veco.end());
    
    if(vec.at(j+1) == veco.at(1)){
      count++;
    }
  }
  
  cout << count << endl;
     
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(unused_variables)]
use proconio::input;
use proconio::marker::*;
use std::cmp::{min, max};
use std::collections::{HashSet, HashMap, BinaryHeap};

fn main() {
    input! {
        x: i64,
    }
    let mut t = 100;
    let mut ans = 0;
    while t < x{
        t += (t as f64 * 0.01) as i64;
        ans += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2112
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int h, w, k;
char map[345][345];
int ans[345][345];
int b[345];
signed main() {
	cin >> h >> w >> k;
	for1(i, h)for1(j, w) {
		cin >> map[i][j];
		if (map[i][j] == '#')b[i]++;
	}
	int p = 1; bool b00l = 0;
	for1(i, h) {
		if (b[i]) {
			for1(j, w) { ans[i][j] = p; if (map[i][j] == '#') { b[i]--; if (b[i]) p++; } }p++;
			if (!b00l)for (int i1 = 1; i1 < i; i1++)for1(j, w)ans[i1][j] = ans[i][j];
			b00l = 1;
		}
		else if (b00l) {
			for1(j, w)ans[i][j] = ans[i - 1][j];
		}
	}
	for1(i, h) {
		for1(j, w) {
			if (j != 1)cout << ' ';
			cout << ans[i][j];
		}cout << endl;
	}
}


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


int main() {
  string s;
  cin >> s;
  int n = s.size();
  string ans = "yes";
  for (int i = 0; i < n; ++i){
    for(int j=i+1; j < n ;++j){
      if(s[i] == s[j]) {
        ans = "no";
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// 自分の得意な言語で
		// Let's チャレンジ！！

		Scanner sc = new Scanner(System.in);

		// 問題数
		int n = sc.nextInt();
		// 提出数
		int m = sc.nextInt();

		// 正当数
		int sei = 0;
		// ペナ数
		int pena = 0;

		// 仮ペナマップ
		int[] iArr = new int[n + 1];

		// 正当マップ
		boolean[] bArr = new boolean[n + 1];

		for (int i = 0; i < m; i++) {
			// 問題番号
			int nm = sc.nextInt();
			// WA or AC
			String kekka = sc.next();

			if ("AC".equals(kekka)) {
				if (!bArr[nm]) {
					sei++;
					pena += iArr[nm];
					bArr[nm] = true;
				}
			} else {
				if (!bArr[nm]) {
					iArr[nm] = iArr[nm] + 1;
				}
			}
		}

		System.out.println(sei + " " + pena);

	}

}

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


int main()
{
    int  n;
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int ans =0;
    int curr =1;
    set<int> m;

    while( curr != 2)
    {

        if( m.find( curr) != m.end() )
        {
         cout<<-1;
         return 0;
        }
        m.insert(curr);
        curr = a[ curr ];
        ans++;
    }
    cout<<ans;
}

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

using namespace std;
#define         MAX         1000000
#define         input       freopen("input.txt","r",stdin)
#define         output      freopen("output.txt","w",stdout)

long long int n,k,tmp;

int main() {

    cin>>n>>k;

    if(n==0){
        cout<<n<<endl;
        return 0;
    }

    if(n==k){
        cout<<0<<endl;
        return 0;
    }

    if(n>k){
       tmp = n/k; tmp *= k; n = n-tmp;
    }


    tmp = abs(n-k);

    if(tmp < n){
        cout<<tmp<<endl;
    }else cout<<n<<endl;


    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>


//マクロ
/*動かない・・・
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _roverload3(_1,_2,_3,name,...) name
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(...) _roverload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
//*/
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
//*/
#define All(a) (a).begin(),(a).end()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e12
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
//*/
using namespace std;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数
int n;

//使用する関数
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 (a > b) { a = b; return 1; }
	return 0;
}

ll calc(ll a) {
	if (a == 1)return 1;
	return calc(a / 2) * 2 + 1;
}

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

	cin >> n;

	REP(i, n) {
		int a;
		cin >> a;
		if (a % 2 == 0) {
			if (a % 3 != 0 && a % 5 != 0) {
				cout << "DENIED" << endl;
				return 0;
			}
		}
	}
	cout << "APPROVED" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
typedef long long ll;
int k;
int p[maxn];
int main() {
    cin >> k;
    p[1] = 7 % k;
    for (int i = 2; i <= 1e6; i++) {
        p[i] = p[i - 1] * 10;
        p[i] %= k;
    }
    ll sum = 0;
    for (int i = 1; i <= 1e6; i++) {
        sum += p[i];
        sum %= k;
        if(sum == 0) {
            printf("%d\n", i);
            return 0;
        }
    }
    printf("-1\n");
}


Measured memory_bytes: 7664
#include <stdio.h>
int main(void){
    int N;
    scanf("%d",&N);
    int a[13]={};
    int ans=0;
    for(int i=0;i<N;i++){
        int kari;
        scanf("%d",&kari);
        a[kari]++;
    }
    for(int i=0;i<=12;i++){
        if(a[i]>2){printf("0");return 0;}
    }
    if(a[0]>0){printf("0");return 0;}
    if(a[12]>1){printf("0");return 0;}
    for(int j=0;j<(1<<12);j++){
        int time[25]={};
        time[0]=1;
        time[24]=1;
        for(int i=0;i<=12;i++){
            if(a[i]==2){time[i]=1;time[24-i]=1;}
            if(a[i]==1){int unko=((j>>i)%2);unko=(unko==1)?i:(24-i);time[unko]=1;}
        }
        int s=1919;
        int mae=0;
        for(int i=1;i<=24;i++){
            if(time[i]==1){s=s>(i-mae)?(i-mae):s;mae=i;}
        }
        if(ans<s){ans=s;/*for(int i=0;i<=24;i++)printf("%d:%d\n",i,time[i]);*/}
    //    printf("%d\n",s);
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 128
n=int(input())
a=list(map(int,input().split()))
lis=[0]*9
for i in range(n):
    if 1<=a[i]<=399: lis[0]+=1
    elif a[i]<=799:  lis[1]+=1
    elif a[i]<=1199: lis[2]+=1
    elif a[i]<=1599: lis[3]+=1
    elif a[i]<=1999: lis[4]+=1
    elif a[i]<=2399: lis[5]+=1
    elif a[i]<=2799: lis[6]+=1
    elif a[i]<=3199: lis[7]+=1
    else: lis[8]+=1

min_color = 0
for i in range(len(lis)-1):
    if lis[i]>0: min_color+=1
max_color = min_color + lis[-1]
if min_color ==0:
    print(1,max_color)
else:
    print(min_color,max_color)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define ll long long
#define lowbit(x) (x&-x)
using namespace std;
const int N = 1e5+7;
int a[N];
int main()
{
    int n;
    ll res = 0;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
    }
    sort(a+1, a+1+n);
    if(n&1)
    {
        for(int i = 1; i < n/2; i++)
        {
            res -= (a[i]<<1);
            res += (a[n-i+1]<<1);
        }
        int p = n/2;
        res += max(a[p+1]+a[p+2]-2*a[p], 2*a[p+2]-a[p+1]-a[p]);
    }
    else
    {
        for(int i = 1; i < n/2; i++)
        {
            res -= (a[i]<<1);
            res += (a[n-i+1]<<1);
        }
        res -= a[n/2];
        res += a[n/2+1];
    }
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<ii> vii;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define fr(be, en) for(int i = be; i <= en; i++) 
ll mod = LLONG_MAX;
ll power(ll a, ll b)
{
	if(b == 0) return 1;
	ll ans = power(a, b/2);
	ans = (ans*ans)%mod;
	if(b%2) ans*=a;
	return ans%mod;
}
ll mul(ll a,ll n, ll mod)
{
	ll ret;
	if(n==0) return 0;
	ret = mul(a,n/2, mod);
	ret = (ret+ret)%mod;
	if(n%2)	ret=(ret+a)%mod;
	return ret;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cout.tie(NULL);
	cin.tie(NULL);
	ll a, b, c, d, ans;
	cin >> a >> b >> c >> d;
	ans = max(a*c, max(a*d, max(b*c, b*d)));
	cout << ans;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

ll w[110];
ll v[110];
ll dp[110][110000];

int main() {
  ll n, W;
  cin >> n >> W;
  for(int i = 1; i <= n; i++) cin >> w[i] >> v[i];
  for(int i = 1; i <= n; i++) {
    for(int j = 0; j<= W; j++) {
      dp[i][j] = dp[i-1][j];
      if(j-w[i]>=0) {
        dp[i][j] = max(dp[i][j],dp[i-1][j-w[i]]+v[i]);
      }
    }
  }
  cout << dp[n][W] << endl;
  return 0;
}

Measured memory_bytes: 87424
/***
	chauhan176's code

	Nothing Happens , It's True
***/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define maxn 300005
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;

typedef pair<int,int>pi;
const ll inf = 1e10;//0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = 10000000;
#define PI 3.14159265
ll power(ll x,ll y,ll p)
{
    ll res = 1;
    x = x % p;

    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
int main()
{
    fastio;
    ll x,y;
    cin>>x>>y;
    if((x+y)%3!=0)
    {
        cout<<0<<endl;
        return 0;
    }
    ll ti = (x+y)/3;
    pi one = {2*ti , ti};
    ll dif = y-ti;
    if(y<ti || dif > ti)
    {
        cout<<0<<endl;
        return 0;
    }
    //trace4(ti,one.fi,one.se,dif);
    ll ans = 1;
    for(int i=ti;i>1;i--)
    {
        ans = ans*i;
        ans%=mod;
    }
    ll den = 1;
    for(int i=2;i<=dif;i++)
    {
        den = den*power(i,mod-2,mod);
        den = den%mod;
    }
    for(int i=2;i<=(ti-dif);i++)
    {
        den = den*power(i,mod-2,mod);
        den = den%mod;
    }
    //cout<<den<<endl;
    ans = (ans*den)%mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S; cin>>S;
  if(S.at(0)=='R'){
    if(S.at(1)=='R'){
      if(S.at(2)=='R')
        cout<<3<<endl;
    else cout<<2<<endl;
    }
    else cout<<1<<endl;
  }
  else{
    if(S.at(1)=='R'){
      if(S.at(2)=='R')
         cout<<2<<endl;
         else cout<<1<<endl;
         }
         else {
           if(S.at(2)=='R')
             cout<<1<<endl;
           else cout<<0<<endl;
         }
  }
}

Measured memory_bytes: 3624