akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>
#include <vector>

using namespace std;

#define INF 0x3f3f3f3f
#define fi first
#define se second


int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    map<int,int> ma;
    ma[-1] = 1;
    ma[INF] = 1;

    for (int a: A) {
        auto it = ma.lower_bound(a);
        it--;

//        cout << "it " << it->fi << " " << it->se << endl;

        if (it->fi == -1) {
            if (ma.count(a) == 0) ma[a] = 0;
            ma[a]++;
        }
        else {
            ma[it->fi]--;
            if (ma[it->fi] == 0) ma.erase(it);
            if (ma.count(a) == 0) ma[a] = 0;
            ma[a]++;
        }

//        cout << "map" << endl;
//        for (auto x: ma) {
//            cout << x.fi << " " << x.se << endl;
//        }
//        cout << endl;
    }

    int ans = 0;
    for (auto x: ma) {
        if (x.fi == -1 || x.fi == INF) continue;
        ans += x.se;
    }
    cout << ans << endl;
}


Measured memory_bytes: 5248
//I had a dream :)
#include <bits/stdc++.h>
//#ifdef atom #else #endif
using namespace std;
typedef long long ll; typedef pair<int, int> ii;
#define X first
#define Y second
#define vi vector<int>
#define vii vector< ii >
#define pb push_back
int f[5];
int main()
{
    //#ifndef atom freopen(".in", "r", stdin); freopen(".out", "w", stdout); #endif
    int n;
    cin >> n;
    for(int i = 0; i< n; i++)
    {
        string s;
        cin >> s;
        if(s[0] == 'M') f[0]++;
        else if(s[0] == 'A') f[1]++;
        else if(s[0] == 'R') f[2]++;
        else if(s[0] == 'C') f[3]++;
        else if(s[0] == 'H') f[4]++;
    }
    ll res = 0;
    for(int i = 0; i< 5; i++)
    {
        for(int j = i+1; j< 5; j++)
        {
            for(int k = j+1; k< 5; k++)
            {
                res += 1LL*f[i]*f[j]*f[k];
            }
        }
    }
    printf("%lld\n", res);
}


Measured memory_bytes: 256
a[25];main(n,i,p){for(;scanf("%d",&n),n;puts("0")){for(i=0;i<n;i++)scanf("%d",a+i);for(puts("31"),i=0,p=31;p>1;printf("%d\n",p-=(p-1)%5))printf("%d\n",p-=a[i++%n]);}exit(0);}

Measured memory_bytes: 0
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;
    long[] dp;
    long n;
    long S;

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int n = S.length();
        long[][] dp = new long[n + 1][13];
        dp[0][0] = 1;
        int f = 1;

        for (int i = 0; i < n; i++) {
            char c = S.charAt(n - i - 1);
            if (c == '?') {
                for (int j = 0; j < 13; j++) {
                    for (int d = 0; d < 10; d++) {
                        dp[i + 1][(j + f * d) % 13] += dp[i][j];
                        dp[i + 1][(j + f * d) % 13] %= (int) 1e9 + 7;
                    }
                }
            } else {
                int d = c - '0';
                for (int j = 0; j < 13; j++) {
                    dp[i + 1][(j + f * d) % 13] += dp[i][j];
                    dp[i + 1][(j + f * d) % 13] %= (int) 1e9 + 7;
                }
            }
            f *= 10;
            f %= 13;
        }
        System.out.println(dp[n][5]);
    }
}


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


using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    sort(arr.begin(), arr.end(), greater<int>());
    long long int ans = arr[0];
    for (int i = 2; i < n; i++) {
        //cout << "i: " << i << " num: " << arr[(i / 2)] << endl;
        ans += arr[i / 2];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4020
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> d(n);
  for(int i=0;i<n;i++)
    cin>>d.at(i);
  sort(d.begin(),d.end());
  int c=1;
  for(int i=1;i<n;i++)
    if(d.at(i)>d.at(i-1))
      c++;
  cout<<c<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
int arr[305][305]; 
bool flg[305][305]; 
int main()
{
	// freopen("ARC083-D.in", "r", stdin); 
	int n; 
	scanf("%d", &n); 
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
			scanf("%d", arr[i] + j); 
	}
	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] + arr[k][j] < arr[i][j])
				{
					puts("-1"); 
					return 0; 
				}
				if (arr[i][k] + arr[k][j] == arr[i][j] && k != i && k != j)
					flg[i][j] = true; 
			}
		}
	}
	long long ans = 0; 
	for (int i = 0; i < n; i++)
	{
		for (int j = i; j < n; j++)
		{
			if (!flg[i][j])
				ans += arr[i][j]; 
		}
	}
	printf("%lld\n", ans);
	return 0; 
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Khela ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll ,ll>
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int max=1e9+100;
const ll  MAX=1e18+500;
const int sz=2e5+100;
int mark[sz];
int main()
{
    Khela
    int a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    while(cin>>n)
    {
        memset(mark,0,sizeof mark);
        int ara[n+2];
        for(i=1;i<=n;i++) cin>>ara[i];

        int ct=0;
        for(i=n;i>=1;i--){
           int tot=0;
           for(j=i+i;j<=n;j+=i) tot+=mark[j];
           if(tot % 2 != ara[i]){
               ++ct;
               ++mark[i];
           }
        }
        
        cout<<ct<<endl;
        for(i=1;i<=n;i++){
            if(mark[i]>0){
                cout<<i<<" ";
            }
        }
       if(ct>0) cout<<endl;
      
        
    }





}

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

int	main(void)
{
	int H, W;
	cin >> H >> W;
	while (!(H == 0 && W == 0))
	{
		for (int i = 0; i < H; i++)
		{
			int j = 0;
			if (i % 2 == 0)
			{
				cout << '#';
				j++;
			}
			while (j < W)
			{
				cout << '.';
				j++;
				if (j < W)
				{
					cout << '#';
					j++;
				}
			}
			cout << endl;
		}
		cin >> H >> W;
		cout << endl;
	}
}



Measured memory_bytes: 3104
n = int(input())
h = list(map(int, input().split()))
INF = 10 ** 12

dp = [INF] * (n+1) # 初期化
dp[0] = 0 # 初期条件
for i in range(1,n):
  dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
  if i > 1:
    dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))
print(dp[n-1])

Measured memory_bytes: 13976
/* Simplicity and Goodness */

#include <bits/stdc++.h>
using namespace std;
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld ",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define deb(x) cout << #x << ' ' << x << '\n'
#define rep(i,ini,n) for(int i=ini;i<(int)n;i++)
#define per(i,ini) for(int i=ini;i>=0;i--)
#define tc int tt; scn(tt); while(tt --)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 998244353;
const int N = 2e5+2;


int main()
{
    int k, a, b;
    cin >> k >> a >> b;

    int one = (a-1) / k, two = b / k;

    if(two - one == 0)
    printf("NG\n");
    else
    printf("OK\n");
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> vec(n);
    int min = 1000000000;
    rep(i, n){
        cin >> vec[i];
        int num = 0;
        while(vec[i] % 2 == 0){
            vec[i] /= 2;
            num++;
            if(num > min) break;
        }
        
        if(min > num) min = num;
    }
    
    cout << min << endl;
    
}

Measured memory_bytes: 3652
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(Math.abs(x-a)<Math.abs(x-b)){
      System.out.println("A");
    }else{
      System.out.println("B");
    }
  }
}


Measured memory_bytes: 25044
/*Program from Luvwgyx*/
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define int long long
using namespace std;
deque<int >s1,s2;int n;
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void print(int x){
    if(x<0)putchar('-'),x=-x;
    if(x>9)print(x/10);
    putchar(x%10+'0');
}
void write(int x){print(x);putchar('\n');}
void Write(int x){print(x);putchar(' ');}
signed main(){
    int n=read()+1,digit=0,now=0;
    for(int i=1;i<=n;i<<=1)digit++;
    for(int i=digit-2;i>=0;i--){
        s1.push_back(++now);s2.push_back(now);
        if((n>>i)&1)s1.push_front(++now),s2.push_back(now);
    }write((int)s1.size()+(int)s2.size());
    deque<int > :: iterator it;
    for(it=s1.begin();it!=s1.end();it++)Write(*it);
    for(it=s2.begin();it!=s2.end();it++)Write(*it);
    puts("");
    return 0;
}


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


int main(){
	//freopen("i.txt","r",stdin);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin >> n;
	string s[n]; long long d[n];
	for(int i = 0;i < n;i++){
		cin >> s[i];
		cin >> d[i];
	}
	string x; cin >> x;
	
	long long ans = -1;
	
	for(int i = 0;i < n;i++){
		if(ans != -1) ans += d[i];
		if(s[i] == x) ans = 0;
	}
	cout << ans;
}


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

int table[1000001];

int main() {
  int n,a,b;
  while(cin>>n>>a>>b, n|a|b) {
    memset(table, 0, sizeof(table));

    for(int i=0; i<=n; ++i) {
      if(i%a==0) {
	//	cout<<i<<endl;
	table[i] = 1;
	for(int j=1; i+j*b<=n && table[i+j*b] == 0; ++j)
	  table[i+j*b] = 1;
      }
    }

    int ans = 0;
    for(int i=0; i<=n; ++i)
      if(table[i] == 0) ans++;

    cout<<ans<<endl;
  }
}

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

int main(){
  int N;
  vector<int>A;
  cin >>N;

  for (int i = 0; i<N;i++){
    int x;
    cin >>x;
    A.push_back(x-i+1);
  }

  sort(A.begin(),A.end());
  long long int ans= 0;



  for (int i = 0; i< N;i++){
    ans += abs(A[i]-A[(N-1)/2]);
  }
  cout <<ans<<endl;
  return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;


int main(){
  ll n,k;
  cin >> n >> k;
  ll ans=0;
  if(k==0){ cout << n*n << endl; return 0; }
  
  for(int b=k+1; b<=n; b++){
    ans += ((n-b+1)/b+1)*(b-k);
    if(n%b>=k && b!=k+1 && n%b!=b-1){ ans += n%b-(k-1); }
  }

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


Measured memory_bytes: 256
import sys
from fractions import gcd


def lcm_base(a, b):
    return (a * b) // gcd(a, b)


input = sys.stdin.readline

N, M = map(int, input().split())
A = sorted(map(int, input().split()))
LCM = 1
count = -1
for a in A:
    if a % 2 == 1:
        print(0)
        exit()
    tmp_count = 0
    tmp = a
    while tmp % 2 == 0:
        tmp = tmp//2
        tmp_count += 1
    LCM = lcm_base(LCM, a//2)

    if count == -1:
        count = tmp_count
    if tmp_count != count:
        print(0)
        exit()
tmp = (M//LCM)
if tmp % 2 == 0:
    tmp = tmp//2
else:
    tmp = tmp//2+1
print(tmp)


Measured memory_bytes: 85228
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int n=s.length();
	string temp=s.at(0)+"";
	int x=0;
	string tem="";
	for(int i=i;i<n;i++){
		
		tem=tem+s.at(i);
		if(tem!=temp){
			x++;
			temp=tem;
			tem="";
		}
	
	}
	cout<<x<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;

signed main() {
    ll n, m;
    cin >> n >> m;
    
    vll b1(n);
    vll b2(n);
    rep(i, m) {
        ll a, b;
        cin >> a >> b; a--; b--;
        
        if (a == 0) {
            b1[b] = 1;
        } else if (b == 0) {
            b1[a] = 1;
        }
        if (a == n-1) {
            b2[b] = 1;
        } else if (b == n-1) {
            b2[a] = 1;
        }
        
    }
    
    rep(i, n) {
        if (b1[i] == 1 && b2[i] == 1) {
            mes("POSSIBLE");
            re0;
        }
    }
    
    mes("IMPOSSIBLE");
    

}
    
    
    
    
    


Measured memory_bytes: 6252
K = int(input())
map = {0: True}
cnt = 1
nana = 7 % K
md = 7 % K
while md not in map:
# for i in range(100):
    cnt += 1
    map[md] = True
    md = (10 * md + nana) % K
    # print(md)
if md == 0:
    print(cnt)
else:
    print("-1")


Measured memory_bytes: 92628
blue = []
red = []
N = int(input())
for card in range(N):
    blue.append(input())
M = int(input())
for card in range(M):
    red.append(input())

max = 0
for b in blue:
    if max < blue.count(b) - red.count(b):
        max = blue.count(b) - red.count(b)
        
print(max)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

int main() {
	ll l, r;
	cin >> l >> r;
	if (r - l >= 2018) {
		cout << 0 << endl;
		return 0;
	}

	int ans = 3000;
	for (int i = l % 2019; i < r % 2019; i++) {
		for (int j = i + 1; j <= r % 2019; j++) {
			ans = min(ans, (i*j) % 2019);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import re
class c(int):
 def __add__(self,n):return c(int(self)+int(n))
 def __sub__(self,n):return c(int(self)-int(n))
 def __mul__(self,n):return c(int(self)*int(n))
 def __truediv__(self,n):return c(int(int(self)/int(n)))
for _ in[0]*int(input()):print(eval(re.sub(r'(\d+)',r'c(\1)',input()[:-1])))


Measured memory_bytes: 6608
# coding: utf-8

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

#Xの中に0が含まれていた場合、0を含まない状態へと各変数を書き換える。
if X.count(0) == 1:
    n -= 1
    k -= 1
    X.remove(0)

#0を除いた0が空である場合は、0を返す    
if X == []:
    print(0)
else:
    #Xを、負の要素からなるminusと、正の要素からなるplusに分割する。
    minus = list(filter(lambda x : x < 0, X ))
    plus = list(filter(lambda x : x > 0, X ))
    
    #負にi本、正にk-i本つけるのにかかる時間をt[i]に格納する。
    t =[]
    for i in range(k+1):
        #負にi本、正にk-i本つけることが不可能ならt[i]に無限大を格納する。
        if len(minus) < i or len(plus) < k-i:
            t.append(float("inf"))
        else:
            #正方向に行くだけの場合
            if i == 0:
                t.append(plus[k-1])
            #負方向に行くだけの場合    
            elif i == k:
                t.append(-minus[-i])
            #正負どちらにも行く場合
            else:
                t.append(min(-minus[-i], plus[k-i-1])*2 + max(-minus[-i], plus[k-i-1]))
    
    print(min(t))

Measured memory_bytes: 65560
from collections import defaultdict

n = int(input())
a_li = list(map(int,input().split()))

a_li.sort()
a_count = defaultdict(int)
for x in a_li:
    a_count[x] += 1

ans = 0

a_set = set(a_li)

for i in a_set:
    s = a_count[i] + a_count[i-1] + a_count[i+1]
    ans = max(ans,s)

print(ans)

Measured memory_bytes: 21472
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Khela ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll ,ll>
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int Max=1e9+100;
const ll  MAX=1e18+500;
const int sz=1e5+100;
ll parent[sz];
ll ran[sz];
void init(ll n)
{
    for(ll i=0;i<=n;i++) parent[i]=i,ran[i]=1;
}
ll Find(ll x)
{
    if(parent[x]==x) return x;
    else return (parent[x]=Find(parent[x]));
}
void Union(ll x,ll y)
{
    ll p=Find(x);
    ll q=Find(y);
    if(p==q) return ;
    else{
        if(ran[p]>ran[q]) parent[q]=p,ran[p]+=ran[q];
        else parent[p]=q,ran[q]+=ran[p];
    }
}
int main()
{
    Khela
    ll a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    while(cin>>n>>m)
    {
        vector<PII> edge;
        for(i=0;i<m;i++){
            cin>>p>>q;
            edge.push_back({p,q});
        }
        init(n+1);
        ll ans=(n-1)*n;
        ans/=2;
        vector<ll> test; 
        test.push_back(ans);
        for(i=m-1;i>=0;i--)
        {
            x=edge[i].f,y=edge[i].second;
            p=Find(x),q=Find(y);
            if(p != q){
                ans-=(ran[p]*ran[q]);
                Union(p,q);
            }
            test.push_back(ans);
        }

        for(i=m-1;i>=0;i--) cout<<test[i]<<endl;
    }





}

Measured memory_bytes: 6256
#include<iostream>
#include<algorithm>


using namespace std;

int main(void) {
    int N;
    cin >> N;
    int a[N];
    for (int i=0; i<N; i++) cin >> a[i];

    sort(a,a+N, greater<int>());

    int Alice = 0;
    int Bob = 0;

    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) {
            Alice += a[i];
        }
        else {
            Bob += a[i];
        }
    }

    cout << Alice - Bob << endl;
}


Measured memory_bytes: 256
from heapq import heappush, heapreplace

def main():
    INF = 10 ** 9 + 5

    N, K, *TD = map(int, open(0).read().split())

    E = [[] for _ in range(N)]
    for t, d in zip(*[iter(TD)] * 2):
        E[t - 1].append(d)

    for e in E:
        if e:
            e.sort(reverse=True)
        else:
            e.append(-INF)
    E.sort(key=lambda x: -x[0])

    cur = 0
    Q = []
    for ei in E[:K]:
        cur += ei[0]
        for eij in ei[1:]:
            heappush(Q, -eij)

    for ei in E[K:]:
        for eij in ei:
            heappush(Q, -eij)

    res = cur + K * K
    for x in reversed(range(1, K)):
        v, w = E[x][0], -Q[0]
        if v < w:
            heapreplace(Q, -v)
            cur += w - v

        tmp = cur + x * x
        if res < tmp:
            res = tmp

    print(res)

if __name__ == '__main__':
    main()


Measured memory_bytes: 32964
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ull unsigned long long
#define mp make_pair
#define F first
#define S second
#define mod 1000000007

ll dp[1003][1005];
char a[1005][1004];

int main()
{
    int h,w;
    cin >> h >> w;

    for(int i=1; i<=h ;i++)
    {
        for(int j=1; j<=w; j++)
        {
            cin >> a[i][j];
        }
    }

    dp[1][0] = 1;
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            if(a[i][j] == '.')
                dp[i][j] = (dp[i-1][j] + dp[i][j-1])%mod;
            //else
              //  dp[i][j] = 0;
        }
    }

    cout << dp[h][w] << endl;

}


Measured memory_bytes: 9088
S = list(map(int, list(input())))

MOD = 2019

mods = [0 for _ in range(2019)]
mods[0] = 1

num = 0
digit = 1
for s in S[::-1]:
  num = s * digit + num
  num %= MOD
  mods[num] += 1
  digit = (digit * 10) % MOD
  
ans = 0
for m in mods:
  ans += m * (m - 1) // 2

print(ans)


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

int main() {
    using namespace std;
    constexpr unsigned long MOD = 998244353;
    unsigned long N;
    cin >> N;
    vector<vector<unsigned long>> children(N + 1);
    {
        vector<pair<long, long>> robots;
        for(long i{0}, x, d; i++ < N; robots.emplace_back(x, x + d))cin >> x >> d;
        sort(robots.begin(), robots.end());
        stack<pair<unsigned long, long>> st;
        st.emplace(0, 3000000000);
        for(unsigned long i{0}; i < N; ++i){
            while(st.top().second <= robots[i].first)st.pop();
            children[st.top().first].emplace_back(i + 1);
            while(st.top().second < robots[i].second)st.pop();
            st.emplace(i + 1, robots[i].second);
        }
    }
    vector<unsigned long> dp(N + 1, 1);
    for(unsigned long i{N + 1}; i--; ++dp[i])for(const auto& j : children[i])(dp[i] *= dp[j]) %= MOD;
    cout << (dp[0] - 1) % MOD << endl;
    return 0;
}

Measured memory_bytes: 14316
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define db double
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repn(i,a,b)   for(ll i=a;i>=b;i--)
#define F first
#define S second
#define qi queue<ll>
#define pii pair<ll,ll>
#define vi vector<ll>
#define si set<ll>
#define vii vector<pii>
#define mi multiset<ll>
#define mii multiset<pii>
#define MI map<ll,ll>
#define pb push_back
#define mp  make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define mod 998244353
#define mod2 998244353
 
const ll N=1e9+7;
 
int fexp(int a, int b){int ans = 1;while(b){if(b&1) ans = ans*a%mod2; b/=2;a=a*a%mod2;}return ans;}
int inverse(int a, int p){return fexp(a, p-2);}
 
ll solve(){
    
    return 0;
}
 
signed main(){
    IOS
// 	#ifndef ONLINE_JUDGE
//     	freopen("input.txt", "r", stdin);
// 		freopen("output.txt", "w", stdout);
// 	#endif
	ll n;
  cin>>n;
  vi v(n,0);
  ull j=0;
  rep(i,0,n){
    cin>>v[i];
    j+=v[i];
  }
  ull ans=0;
  rep(i,0,n-1){
    j-=v[i];
    ans+=(((v[i]%N)*(j%N))%N)%N;
  }
  cout<<ans%N;
    return 0;
}
// size_t f= str.find(string s,0); find s in str from start
// if found then (f != string::npos)
// m.insert({x,y}); m[x]=y;

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

using namespace std;


bool tupleCompare(const tuple<string, int, int> &firstElof, const tuple<string, int, int> &secondElof)
{
  if(std::get<0>(firstElof) < std::get<0>(secondElof))
    {
      return true;
    }
  else if(std::get<0>(firstElof) == std::get<0>(secondElof))
    {
      return std::get<1>(firstElof) > std::get<1>(secondElof);
    }
  else
    {
      return false;
    }
}



int main()
{
  int n;
  cin >> n;
  vector<tuple<string, int, int> > pa;
  string s;
  int p;
  pa.resize(n);

  for(int i = 0;
      i < n;
      ++i)
    {
      cin >> s >> p;
      pa[i] = make_tuple(s,p,i);
    }

  sort(pa.begin(), pa.end(), tupleCompare);

  for(int i = 0;
      i < n;
      ++i)
    {
      cout << get<2>(pa[i]) + 1 << endl;
    }

  return 0;
}


Measured memory_bytes: 256
// Author - Sumit 

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define int ll
#define ps push
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
#define mp make_pair
#define rep(i,a,b) for (int i = a; i < b; i++)
#define repd(i,a,b) for (int i = a; i >= b; i--)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pair<int,int>>
#define itr :: iterator it
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define debug(x) cout << x << "\n";
#define debug2(x,y) cout << x << " " << y << "\n";
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
template<typename T, typename U> inline void remin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void remax(T &x, U y) { if(x < y) x = y; }
 


void solve(){
    int m1,d1,m2,d2;
    cin>>m1>>d1>>m2>>d2;
    int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
    if(m2-m1==1){
        debug(1);
    }else{
        debug(0);
    }

}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

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


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int a,b;
  scanf("%d %d",&a,&b);
  if(a>=b)
  {
    for(int i = 0;i<a;i++)
      printf("%d",b);
    
  }
  else
  {
    for(int i = 0;i<b;i++)
      printf("%d",a);
    
  }
  
  return 0;
}

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

int main(){
    int n,m,l;
    cin >> n >> m >> l;
    vector< vector< int > > a(n,vector< int >(m));
    vector< vector< int > > b(m, vector< int >(l));
    for(int i=0;i<n;i++){
        for(int j =0;j<m;j++)cin >> a[i][j];
    }
    
    for(int i=0;i<m;i++){
        for(int j =0;j<l;j++) cin >> b[i][j];
    }

    vector< vector< long long > > ans(n, vector< long long >(l));
    
    for(int i =0;i<n;i++){
        for(int j=0;j<l;j++){
            for(int k=0;k<m;k++){
                ans[i][j] += a[i][k] * b[k][j];
                
            }
        }
    }
    
    for(int i=0;i<n;i++){
        for(int j =0;j<l;j++) {
            if(j==l-1)cout << ans[i][j];
            else cout << ans[i][j] << " ";
            
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3208
#!/usr/bin/env python3
import sys
INF = float("inf")

MOD = 5  # type: int


def yes():
    print("YES")  # type: str


def no():
    print("NO")  # type: str


def solve(A: int, B: int, C: int):
    tot = 0
    for _ in range(100):
        tot += A
        if tot % B == C:
            yes()
            return
    no()
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, sum;
  vector<int> v(10000, 0);
  cin >> a >> b >> c;
  sum = a;
  while (1) {
    if (v[sum % b] == 1) {
      cout << "NO" << endl;
      break;
    }
    if (sum % b == c) {
      cout << "YES" << endl;
      break;
    } else {
      v[sum % b]++;
    }
    sum += a;
  }
  return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#define REP(i, a, n) for(int i = a; i <= n; i++)
using namespace std;


string S;

bool dfs(int i) {
  if(i == S.length()) return true;

  bool ret = false;
  if(i + 5 < S.length() + 1 && S.compare(i, 5, "dream")   == 0) ret = ret || dfs(i + 5);
  if(i + 7 < S.length() + 1 && S.compare(i, 7, "dreamer") == 0) ret = ret || dfs(i + 7);
  if(i + 5 < S.length() + 1 && S.compare(i, 5, "erase")   == 0) ret = ret || dfs(i + 5);
  if(i + 6 < S.length() + 1 && S.compare(i, 6, "eraser")  == 0) ret = ret || dfs(i + 6);

  return ret;
}

int main(void) {
  cin >> S;

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

  return 0;
}


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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << x << '\n'; return 0;}while(0)

const int MOD = 1e9+7;

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    fori(i,n-2) {
        if(s[i] == 'A' && s[i+1]=='B' && s[i+2]=='C') ans++;
    }

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


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

using namespace std;
int main(){
	int n,a,b,c,d;
	cin>>n>>a>>b>>c>>d;
	string s;
	cin>>s;
	s='$'+s;
	int cnt;
	if(c>d){
		cnt=0;
		bool check=0;
		for(int i=b-1;i<=d+1;i++){
			if(s[i]=='.')cnt++;
			else{
				if(cnt>=3){
					check=1;
					break;
				}
				else cnt=0;
			}
		}
		if(cnt>=3)check=1;
		if(check==0){
			cout<<"No";
			return 0;
		}
	}
	for(int i=a;i<c;i++){
		if(s[i]=='#'&&s[i+1]=='#'){
			cout<<"No";
			return 0;
		}
	}
	for(int i=b;i<d;i++){
		if(s[i]=='#'&&s[i+1]=='#'){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 772
using System;
using System.Linq;

public class Program
{
    static void Main()
    {
        long h = long.Parse(Console.ReadLine());
        long count = 0;
        while (h != 1)
        {
            h /= 2;
            count++;
        }
        long ans = 1;
        for (int i = 1; i <= count; i++)
        {
            ans += (long)Math.Pow(2, i);
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
#define _GLIBCXX_DEBUG //エラーを出すためのおまじない
#include <bits/stdc++.h>
//#include <cstdlib>  // abs() for integer
#include <cmath>    // abs() for float, and fabs()
#include <math.h>
using namespace std;
#define coYES cout << "YES" << endl
#define coNO cout << "NO" << endl
#define coYes cout << "Yes" << endl
#define coNo cout << "No" << endl
#define coyes cout << "yes" << endl
#define cono cout << "no" << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n, k;
  cin >> n >> k;
  int count = 0;
  while(n>0) {
    n /= k;
    count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;
int main(){
  long long int n;
  cin >> n;
  int x=n%10;
  if(x==2||x==4||x==5||x==7||x==9){
    cout << "hon" << endl;
  }
  else if(x==0||x==1||x==6||x==8){
    cout <<"pon" << endl;
  }
  else{
    cout << "bon" << endl;
  }
}

Measured memory_bytes: 3588
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
#define PI 3.141592653589793238462643383279


void change(int *x, int *y){
	int z;
	z = *x;
	*x = *y;
	*y = z;
}
int compare_int(const void *a, const void *b){
	return *(int*)a - *(int*)b;
}

int gcd(int a, int b)
{
    int c;
    if (a < b) {
        a+=b; b=a-b; a-=b;
    }
    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return a;
}
int main(void){
	int n, k;
	scanf("%d %d\n", &n, &k );
	char s[n];
	int Lnum=0;
	int Rnum=0;
	int pair=0;
	for(int i=0;i<n;i++){
		scanf("%c", &s[i]);
     //printf("%c %d\n", s[i], i);
		if(s[i]=='L'){
			//Lnum++;
			if(i>0){
				if(s[i-1]=='L'){
                  pair++;//printf("a");
                }
			}
		}else if(s[i]=='R'){
			//Rnum++;	
			if(i>0){
				if(s[i-1]=='R'){
                  pair++;//printf("b");
                }
			}
        }
	}
	
	int ans = pair + k * 2;
	if(ans >= n)	ans = n-1;
	
	printf("%d", ans);
 // printf("\n%c", s[n-1]);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> table(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0 ; j < W ; j++){
    cin >> table.at(i).at(j);
    }
  }
	vector<bool> a(H,false);
  	vector<bool> b(W,false);
  
  for(int i=0; i<H ; i++){
    for(int j=0; j<W; j++){
      if(table.at(i).at(j)=='#'){
      	a.at(i) = true;
        b.at(j) = true;
      }
    }
  }
  
  for(int i=0; i<H; i++){
    if(a.at(i)){
   	for(int j=0; j<W; j++){ 
     		if(b.at(j)){
             	cout << table.at(i).at(j); 
            }
   		}
      cout << endl;
    }
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
//0-indexedで用いる (実装は1-indexedの配列だけど
//SegmentTree(n,f,m1):=サイズnの初期化。ここでfは2つの区間の要素をマージする二項演算m1はモノイドの単位元である。
//set(k,x) k番目の要素にxを代入する
//build() (代入で作った場合)セグメント木を構築するのに必要
//query(a,b) 区間[a,b)に対して二項演算した結果を返す
//update(k,x) k(0-indexed)番目の要素をxに変更する 
//operator[k] k(0-indexed)番目の要素を返す

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;
 
  int sz;
  vector< Monoid > seg;
 
  const F f;
  const Monoid M1;
 
  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }
 
  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }
 
  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }
 
  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }
 
  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }
 
  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }
};


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

  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p[i];

  SegmentTree<int> seg_odd(n, [](int a, int b) { return min(a, b); }, INT_MAX);
  SegmentTree<int> seg_even(n, [](int a, int b) { return min(a, b); }, INT_MAX);

  map<int,int> v_to_pos;

  rep(i,n){
    if(i%2==0) seg_even.set(i,p[i]);
    else seg_odd.set(i,p[i]);
    v_to_pos[p[i]] = i;
  }
  seg_even.build();
  seg_odd.build();

  deque<int> ans;
  set<int> used;
  using Pi = tuple< int, int, int, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  que.push(make_tuple(-1,-1,0,n-1));
  while(!que.empty()){
    auto qt = que.top();que.pop();
    int fv = get<0>(qt);
    int sv = get<1>(qt);
    int st_ind = get<2>(qt);
    int ed_ind = get<3>(qt);
    // cout << fv << " " << sv << " " << st_ind << " " << ed_ind << endl;
    if(fv>0 && used.count(fv)==0){
      ans.push_back(fv);
      ans.push_back(sv);
      used.insert(fv);
      used.insert(sv);
    }
    if(st_ind>=ed_ind) continue;
    int nfv,nsv;
    if(st_ind%2==0){
      nfv = seg_even.query(st_ind,ed_ind+1);
      nsv = seg_odd.query(v_to_pos[nfv]+1,ed_ind+1);
    }
    else{
      nfv = seg_odd.query(st_ind,ed_ind+1);
      nsv = seg_even.query(v_to_pos[nfv]+1,ed_ind+1);
    }
    // cout << "next " << endl;
    // cout << nfv << " " << nsv << endl;
    if(nfv!=INT_MAX && nsv!=INT_MAX){
      
      que.push(make_tuple(nfv,nsv,st_ind,v_to_pos[nfv]-1));
      que.push(make_tuple(nfv,nsv,v_to_pos[nfv]+1,v_to_pos[nsv]-1));
      que.push(make_tuple(nfv,nsv,v_to_pos[nsv]+1,ed_ind));
    }
  }
  rep(i,ans.size()){
    cout << ans[i] << " \n"[i==ans.size()-1];
  }
  
  return 0;
    

}


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

int main(){
    int a,b;
    cin >> a >> b;
    if((a%3==0)||(b%3==0)||((a+b)%3==0)) cout <<"Possible" <<endl;
    else cout << "Impossible" << endl;
      }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pi 3.141592653589793116
#define mod 1e9+7
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int main() {
  off;
  int t;
  //cin>>t;
  t=1;
  while(t--){ 
  int n=5; 
    int a[5],sum=0,min1=INT_MAX;
    for(int i=0;i<n;i++)
       {
        cin>>a[i];
        if(a[i]%10!=0)
          {
              sum+=((a[i]/10+1)*10);
          }
         else
           sum+=a[i];  
       }
    for(int i=0;i<n;i++)
       {
          if(a[i]%10!=0)
          {
              min1=min(min1,sum-((a[i]/10+1)*10)+a[i]);

          }
         else
           min1=min(min1,sum);
          //min1=min(min1,)
       }
     cout<<min1<<" ";   
  }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
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; }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INTINF = 1<<30;
const int MOD = 1000000007;

void add(long long &a, long long b) {
  a += b;
  if (a >= MOD) a -= MOD;
}

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int N;
ll ma,mb;
vector<ll> a,b,c;

ll dp[51][510][510];

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> a(N);
    rep(i,N) cin >> a[i], a[i]--;
    int now = 0, c = 0;
    for(;;){
      if(now == 1){
        printf("%d\n", c);
        break;
      }
      if(c >= N){
        printf("-1\n");
        break;
      }
      c++;
      now = a[now];
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <limits.h>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<lint> vl;
typedef pair<lint,lint> pll;



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

    int a; cin>>a;
    cout<<a+a*a+a*a*a;
}


Measured memory_bytes: 3648
//killer_R@$tog!
#include<bits/stdc++.h>
using namespace std;
#define hell 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define mp make_pair
#define fi first
#define se second
#define ub upper_bound
#define lb lower_bound
#define ll long long int
#define N 100009
#define all(b) b.begin(),b.end();
//int pr[N];
//int seg[N];
/*int query(int l,int r,int sl,int sr,int p)
{
    if(r<sl || l>sr)
        return 0;
    if(sr<=r && sl>=l)
        return seg[p];
    int m=sl+(sr-sl)/2;
    return (__gcd(query(l,r,sl,m,2*p+1),query(l,r,m+1,sr,2*p+2)));
}

int build(int l,int r,int p,int arr[])
{
    if(l==r)
    {
        seg[p]=arr[l];
        return seg[p];
    }
    int m=l+(r-l)/2;
    seg[p]=__gcd(build(l,m,2*p+1,arr),build(m+1,r,2*p+2,arr));
    return seg[p];
}
void isprime()
{
    memset(pr,1,sizeof(pr));
    pr[1]=0;
    for(int i=2;i*i<=N;i++)
    {
        if(pr[i])
        {
            for(j=i*i;j<=N;j+=i)
            {
                pr[j]=0;
            }
        }
    }
}*/
void killer()
{
    int n,m;cin>>n>>m;char a[n][m];int dp[n][m];
    rep(i,0,n)
    {
        rep(j,0,m)
        {
            cin>>a[i][j];dp[i][j]=0;
        }
    }dp[0][0]=1;
    rep(i,0,n)
    {
        rep(j,0,m)
        {
            if(i==j && j==0)continue;
            if(i>0)
            {
                if(a[i-1][j]=='.')
                    dp[i][j]=(dp[i-1][j]+dp[i][j])%hell;
            }
            
            if(j>0)
            {
                if(a[i][j-1]=='.')
                    dp[i][j]=(dp[i][j-1]+dp[i][j])%hell;
            }
        }
    }
    cout<<dp[n-1][m-1];
    return;
}
int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    //int h=(int)ceil(log2(n));
    //h=2*(int)pow(2,h)-1;
    //build(0,n-1,0,a);

    ll t;
    t=1;
    while(t--)
        killer();

    return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    int a[n][n];
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n-1; j++){
            scanf("%d",&a[i][j]);
            a[i][j]--;
        }
    }
    int cur[n];
    memset(cur,0,sizeof(cur));
    bool change = true;
    int ans = 0;
    while (change){
        change = false;
        ans++;
        //printf("%d\n",ans);
        int done[n];
        memset(done,0,sizeof(done));
        for (int j = 0; j < n; j++){
            if (cur[j] == n-1) continue;
            int k = a[j][cur[j]];
            //printf("%d -> %d\n",j,k);
            if (a[k][cur[k]] == j){
                done[k] = 1;
            }
        }
        for (int j = 0; j < n; j++){
            if (done[j]) {cur[j]++; change = true;}
        }
    }
    for (int i = 0; i < n; i++){
        if (cur[i] != n-1){
            printf("-1");
            return 0;
        }
    }
    printf("%d ",ans-1);

}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, check = 0;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < N; i++) {
    if (a.at(i) != i + 1) {
      swap(a.at(i), a.at(a.at(i) - 1));
      break;
    }
  }
  for (int i = 0; i < N; i++) {
    if (a.at(i) != i + 1) {
      check = 1;
      break;
    }
  }
  if (check == 1) {
    cout << "NO" << endl;
  }
  else {
    cout << "YES" << endl;
  }
}

Measured memory_bytes: 256
while True:
    m, f, r = map(int, input().split())

    if(m == -1 and f == -1 and r == -1):
        break

    total = m + f
    if(m == -1 or f == -1):
        print('F')
    elif(total >= 80):
        print('A')
    elif(65 <= total and total < 80):
        print('B')
    elif(50 <= total and total < 65):
        print('C')
    elif(30 <= total and total < 50):
        if(50 <= r):
            print('C')
        else:
            print('D')
    else:
        print('F')



Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<int> x(n),y(n),b(n);
  for(int i=0;i<n;i++){
    cin >> x[i];
    y[i]=x[i];
  }
  sort(y.begin(),y.end());
  for(int i=0;i<n;i++){
    if(x[i]<=y[n/2-1]){
      b[i]=y[n/2];
    }
    else{
      b[i]=y[n/2-1];
    }
    cout << b[i] << endl;
  }
}

Measured memory_bytes: 4608
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) (a<<b)
#define Rshift(a,b) (a>>b)
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  u64 &value() noexcept { return a; }
  constexpr u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) { a -= Modulus; }
    return *this;
  }
  modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) { a += Modulus; }
    a -= rhs.a;
    return *this;
  }
  modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp & 1) { *this *= rhs; }
      rhs *= rhs;
      exp >>= 1;
    }
    return *this;
  }
};

using Mint = modint<mod>;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    ll n, a, b;
    cin >> n >> a >> b;
    ll x2 = 2;
    ll nn(n);
	auto ans = Mint(1);
    while (nn) {
        if (nn & 1) {
            ans *= x2;
        }
        x2 = x2 * x2 % mod;
        nn >>= 1;
    }
    int i;
    auto ma = Mint(1);
    xrep(i, 1, a + 1) {
        ma *= n - i + 1;
        ma /= i;
    }
    auto mb = Mint(1);
    xrep(i, 1, b + 1) {
        mb *= n - i + 1;
        mb /= i;
    }
    ans -= ma.value();
    ans -= mb.value();
    ans -= 1;
    cout << ans.value() << endl;
}


Measured memory_bytes: 256