akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/* * * *   * * *   	* * * */
#define ll long long
#define ld long double
#define ms(a,v) memset(a,v,sizeof a)
/* * * *   * * *   	* * * */
 
/* *
 *
 * Author: Hamkor
 *
 * */
int main(){
	int n, l, m = 10000000, tot=0, ans; scanf("%d %d", &n, &l);
	int f[n+1];
	for (int i=1; i<=n; ++i){
		f[i] = l+i-1;
		tot+=l+i-1;
	}
	for (int i=1; i<=n; ++i){
		if (abs(tot - (tot-f[i])) < m){
			m = abs(tot - (tot-f[i]));
			ans=tot-f[i];
		}
	}
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
void Digvijay()
{
    int x;
    cin>>x;
    if(x>=30)cout<<"Yes\n";
    else cout<<"No\n";
}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int _=1;
    //cin>>_;
    for(int __=1;__<=_;__++)
    {
        Digvijay();
    }
}



Measured memory_bytes: 3644
n=int(input())
vec=[]
if n==3:
    vec=[2,5,63]
elif n==4:
    vec=[2,3,4,9]
elif n==5:
    vec=[2,3,4,6,9]
elif n==6:
    vec=[2,3,4,6,9,12]
elif n==7:
    vec=[2,3,4,6,8,9,10]
else:
    for i in range(1,30001):
        if (i%2)*(i%3)==0:
            vec.append(i)
            if len(vec)==n//8*8:
                break
    mx=vec[-1]
    n%=8
    if n==0:
        vec2=[]
    elif n==1:
        vec2=[6]
    elif n==2:
        vec2=[2,4]
    elif n==3:
        vec2=[2,4,6]
    elif n==4:
        vec2=[2,3,4,9]
    elif n==5:
        vec2=[2,3,4,6,9]
    elif n==6:
        vec2=[2,3,4,6,9,12]
    elif n==7:
        vec2=[2,3,4,6,8,9,10]
    for i in vec2:
        vec.append(i+mx)
print(*vec)

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

int main(){

    int res = 1;
    while(res){
        cin >> res;

        if(res == 0)
            break;

        int n[2][res];

        for(int i=0; i<res; i++){
            cin >> n[0][i];
            cin >> n[1][i];
        }
        int x = 0;
        int y = 0;

        for(int j=0; j<res; j++){
            if(n[0][j]>n[1][j])
                x += n[0][j]+n[1][j];
            else if(n[0][j]==n[1][j]){
                x += n[0][j];
                y += n[1][j];
            }
            else
                y += n[0][j]+n[1][j];
            }

            cout << x << ' ' << y << '\n';

    }

    return 0;
}



Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;

int main(){
  int n; cin>>n;
  ll k; cin>>k;
  vector<ll> num(n);
  ll ans=0;
  for(int i=0;i<n;i++){
    cin>>num[i];
  }
  vector<ll> c(n,0);
  for(int i=n-1;i>0;i--){
    for(int j=0;j<i;j++){
      if(num[i]<num[j]){
        c[i]++;
      }
    }
  }
  vector<ll> b(n);
  ll sum=(((k-1)*k)/2)%MOD;
  for(int i=0;i<n;i++){
    ll count=0;
    for(int j=0;j<n;j++){
      if(num[j]>num[i]){
        count++;
      }
    }
    b[i]=count;
  }
  
  for(int i=0;i<n;i++){
    ans+=b[i]*sum%MOD;
    ans+=k*c[i]%MOD;
    ans%=MOD;
  }
  
  cout << ans << endl;
}


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

int main()
{
    int t,n,i,k;
    cin>>n>>k;
    int dp[n+1],v[n+1],a=0,p;
    for(int i=0; i<n; i++) cin>>v[i];
    if(n<=k) cout<<abs(v[0]-v[n-1])<<endl;
    else
    {
       for(int i=1; i<=k; i++)
        dp[i] = abs(v[0]-v[i]);

     for(int i=k+1; i<n; i++)
       {
              a = INT_MAX;
              for(int j=i-1; j>=i-k; j--)
             {
                    p = dp[j]+abs(v[i] - v[j]);
                    if(a>p) a = p;
               }
               dp[i] = a;
        }
        cout<<dp[n-1]<<endl;
    }

    return 0;
}



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

int bubbleSort(int a[], int n) {
	int flag = 1;
	int counter = 0;
	while(flag) {
		flag = 0;
		for(int j=n-1; j>=1;j--) {
			if(a[j] < a[j-1]) {
				swap(a[j], a[j-1]);
				counter++;
			    flag = 1;
			}
		}
	}
	return counter;
}
int main() {
	int array[100];
	int n;
	int changeCounter;
	cin >> n;
	for(int i=0; i<n; i++) {
		cin >> array[i];
	}

	changeCounter = bubbleSort(array,n);

	for(int i=0; i<n; i++) {
		if(i>0)
			cout << " ";
		cout << array[i];
	}
	cout << endl;

	cout << changeCounter << endl;

}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vvi vector<vector<int>> 
#define vi vector<int> 
#define vpii vector<pair<int,int>> 
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define ffor(i,n) for(int i = 0; i < n; ++i)
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vi a(n);
    ffor(i,n) cin >> a[i];
    int ans = 0;
    int cur = 1;
    bool ok = false;
    for(int i = 0; i < n; ++i){
        while(i < n && a[i] != cur){
            ++ans;
            ++i;
        }
        if(i < n){
            if(a[i] == cur){++cur;ok = true;}
        }
    }
    cout << (!ok?-1:ans);
}

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

int main(){
    long int N;
    cin>>N;cin.ignore();
    string S;
    getline(cin,S);
    int num_siro=0;
    for(int i=0;i<N;i++){
        if(S[i]=='.'){
            num_siro+=1;
        }
    }    
    int num_kuro=N-num_siro;
    int kuro[N+1];
    int counter=0;
    for(int i=0;i<N+1;i++){
        kuro[i]=counter;
        if(i==N){
            break;
        }
        if(S[i]=='#'){
            counter+=1;
        }
    }
    int min_num_change=N;
    int num_change;
    for(int i=0;i<N+1;i++){
        num_change=kuro[i]+num_siro-(i-kuro[i]);
        if(num_change<min_num_change){
            min_num_change=num_change;
        }
    }
    cout<<min_num_change<<endl; 
}   

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  
  double sum = 0;
  for (int i = 0; i < N; i++){
    sum += 1.0 / A[i];
  }
  sum = 1.0 / sum; 
  
  cout << fixed << setprecision(10) << sum << endl;
}

Measured memory_bytes: 3736
#include <iostream>

using namespace std;

int main()
{
    string s,t;
    cin>>s>>t;
    int c=0;
    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i]){c++;}

    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 3804
c,t,d[4010][4010];char s[4010];i;main(j){for(**d=scanf("%s",s);s[i/2];i++)for(j=c+=s[i]?t++,s[i]-48:0;j>i+c-2*t&&~j;j--)d[i+1][j]=(d[i][j]+d[i][j-1])%998244353;printf("%d",d[i][c]);}

Measured memory_bytes: 60416
import java.io.PrintWriter

fun main() {
    val pw = PrintWriter(System.out)

    val n = readInputLine().toInt()

    val set = mutableSetOf<String>()

    repeat(n) {
        set.add(readInputLine())
    }

    pw.println(set.size)

    pw.flush()
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 78472
#include <bits/stdc++.h>
#include<math.h>
using ll = long long;
using namespace std;

int main(){
 ll a, b, n;
 cin >> a >> b >> n;
 ll x = min(b-1, n);
 ll ans = floor(a*x/b);
 cout << ans;
 return 0;
}

Measured memory_bytes: 3584
import java.util.*;

public class Main {
    public static void main(String[] args) {
      
      Scanner scanner = new Scanner(System.in);
      
      String input_text = scanner.nextLine();
      String[] str = input_text.split(" ");
 
		int x = Integer.parseInt(str[0]);
  		int y = Integer.parseInt(str[1]);
  		int z = Integer.parseInt(str[2]);
      	
        int ans = x;
  		if (x == y) {
    		ans = z;
  		} else if (x == z) {
   			ans = y;
  		}
 		System.out.println(ans);
    }
}

Measured memory_bytes: 22868
import java.util.Scanner;
//AGC029A
//Main
public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String S = sc.next();

		int len = S.length();
		long count = 0;
		int num = 0;
		int R[] = new int[len];
		int BWcnt = 0;

		for(int i = 0; i< len;i++) {
			if(S.substring(i, i+1).equals("W")) {
				count+= i-num;
				num++;
				BWcnt++;
			}
		}
		if(BWcnt == 0||BWcnt == len) {
			count=0;
		}

		System.out.println(count);

	}

}

Measured memory_bytes: 37484
//another memory test XD

#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

struct seg
{
	ll l, r, d;
	inline int operator<(const seg &a) const {return d > a.d;}
} s[10010];

const ll inf = (1ll<<62) - 1;
int n, m;
ll f[5010][5010][2];

int main()
{
	ios::sync_with_stdio(0);
	
	cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		cin >> s[i].l >> s[i].r;
		s[i].d = s[i].l + s[i].r;
	}
	sort(s+1, s+n+1);
	m = n >> 1;
	for (int i = 0; i <= m; ++i)
		for (int j = 0; j <= m; ++j)
			f[i][j][0] = f[i][j][1] = inf;
	f[0][0][0] = 0;
	
	for (int i = 0; i <= m; ++i)
		for (int j = 0; j <= m && i+j < n; ++j)
			for (int k = 0; k <= 1 && i+j+k < n; ++k)
			{
				const ll tmp = f[i][j][k]; const seg p = s[i+j+k+1];
				if (i < m)	f[i+1][j][k] = min(f[i+1][j][k], tmp + p.r + i*p.d);
				if (j < m)	f[i][j+1][k] = min(f[i][j+1][k], tmp + p.l + j*p.d);
				if (!k)		f[i][j][k|1] = min(f[i][j][k|1], tmp + m * p.d);
			}
	
	cout << f[m][m][n&1] << endl;
	
	return 0;
}

Measured memory_bytes: 196224
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i = 1;
		do {
			int x = i;

			if (x % 3 == 0) {
				System.out.print(" " + i);
			} else {

				while (true) {

					if (x % 10 == 3) {
						System.out.print(" " + i);
						break;
					}

					x /= 10;
					if (x != 0)
						continue;
					else
						break;
				}
			}
			i++;
		} while (i <= n);
		System.out.println();

	}
}

Measured memory_bytes: 28360
#include <iostream>
#include <cstring>

using namespace std;

const int N = 9;
int R[N], G[N], B[N], data_num[N];
char data_c[N];

int Rec(int data[N], int i)
{
    int res = 0;
    bool change = false;

    if (i < N && data[i] >= 3) {
        data[i] -= 3;
        res = max(res, Rec(data, i) + 1);
        data[i] += 3;
        change = true;
    }
    if (i + 2 < N && (data[i] > 0 && data[i + 1] > 0 && data[i + 2] > 0)) {
        --data[i], --data[i + 1], --data[i + 2];
        res = max(res, Rec(data, i) + 1);
        ++data[i], ++data[i + 1], ++data[i + 2];
        change = true;
    }

    if (i < N && !change)
        res += Rec(data, i + 1);

    return res;
}

int main()
{
    int T;

    cin >> T;
    while (T--) {
        memset(R, 0, sizeof(R));
        memset(G, 0, sizeof(G));
        memset(B, 0, sizeof(B));

        // Input
        for (int i = 0; i < N; ++i)
            cin >> data_num[i];
        for (int i = 0; i < N; ++i)
            cin >> data_c[i];

        for (int i = 0; i < N; ++i) {
            if (data_c[i] == 'R')
                R[data_num[i] - 1]++;
            else if (data_c[i] == 'G')
                G[data_num[i] - 1]++;
            else
                B[data_num[i] - 1]++;
        }

        int set = Rec(R, 0);
        set += Rec(G, 0);
        set += Rec(B, 0);

        if (set >= 3)
            cout << "1\n";
        else
            cout << "0\n";
    }

    return 0;
}

Measured memory_bytes: 1112
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
    char ch[201];
    fgets(ch, 201, stdin);
    string str, str2="";
    str = ch;
    for (auto & c: str) str2+= toupper(c);
    cout << str2;
    return 0;
}



Measured memory_bytes: 3040
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
using namespace std;



int main() {
    ios_base::sync_with_stdio(0);
    int r, g, b;
    cin >> r >> g >> b;
    int in = r * 100 + g * 10 + b;
    if (in % 4 == 0) {
    	cout << "YES";
	} else {
		cout << "NO";
	}
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0 ; (i) < (n) ; ++i)
#define forx(i, n) for(int i = 1 ; (i) <= (n) ; ++i)
#define ll long long
#define all(x) (x).begin(),(x).end()
#define sqr(x) (x) * (x)
#define debug(x) cout << #x <<" = " << x << endl
#define printvpair(v) for(auto x : v) cout << x.first  <<" " << x.second << endl;
#define printv(v) for(auto x : v) cout << x << " "; cout << endl;

const int N = 1e5 + 7;
int a,b,c;
int main() {

    cin >> a >> b;

    for (int i = 1; i <= 3 ; ++i) {
        if ((a * b * i) % 2 == 1){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int n,m,x;
  int a[110]={0};
  cin>>n>>m>>x;
  rep(i,m){
    int z;
    cin>>z;
    a[z]=1;
  }
  ll ans1=0,ans2=0;
  for(int i=x;i<n+1;i++){
    ans1+=a[i];
  }
  for(int i=x;i>=0;i--){
    ans2+=a[i];
  }
  cout<<min(ans1,ans2)<<endl;;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
x = [0]*n
y = [0]*n
for i in range(n): x[i],y[i] = map(int,input().split())

d = {(0,0):0}
for i in range(n-1):
    for j in range(i+1,n):
        dx = x[i]-x[j]
        dy = y[i]-y[j]
        d[(dx,dy)] = d.get((dx,dy),0) + 1
        d[(-dx,-dy)] = d.get((-dx,-dy),0) + 1
        
print(n-max(d.values()))

Measured memory_bytes: 3444
ms=[int(x) for x in input().split(' ')]
t=[ms[0],ms[1]]
a=[ms[2],ms[3]]
while True:
    a[0]-=t[1]
    if a[0]<1:
        print("Yes")
        break
    t[0]-=a[1]
    if t[0]<1:
        print('No')
        break


Measured memory_bytes: 9180
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

ll beki(ll n)
{
    if(n == 0){
        return 1;
    }
    ll ans = beki(n / 2);
    ans = ans * ans;
    if(n % 2 == 1){
        ans = ans * 2;
    }
    return ans;
}

int main(){
    ll n, p;
    cin >> n >> p;
    bool check = true;
    for(int i = 0; i < n; i++){
        int in;
        cin >> in;
        if(in % 2 == 1){
            check = false;
            break;
        }
    }
    if((check == true) && (p == 1)){
        cout << 0 << endl;
        return 0;
    }
    if(!check){
        n--;
    }
    cout << beki(n) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long MOD = 998244353;
    int[] a = new int[n];
    long sum = 0;
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
      sum += a[i];
    }
    long[][] dp = new long[n][100000];
    dp[0][0] = 2;
    dp[0][a[0]] = 1;
    for(int i = 1; i < n; i++) {
      for(int j = 0; j < 100000; j++) {
        if(j >= a[i]) {
          dp[i][j] = (2 * dp[i - 1][j] + dp[i - 1][j - a[i]]) % MOD;
        } else {
          dp[i][j] = (2 * dp[i - 1][j]) % MOD;
        }
      }
    }

    long ans = 1;
    for(int i = 0; i < n; i++) {
      ans = (ans * 3) % MOD;
    }
    long[][] dp2 = new long[n][50000];
    dp2[0][0] = 1;
    dp2[0][a[0]] = 1;
    for(int i = 1; i < n; i++) {
      for(int j = 0; j < 50000; j++) {
        if(j >= a[i]) {
          dp2[i][j] = (dp2[i - 1][j] + dp2[i - 1][j - a[i]]) % MOD;
        } else {
          dp2[i][j] = (dp2[i - 1][j]) % MOD;
        }        
      }
    }

    long t = 0;
    int q = (int)(sum / 2);
    if((sum % 2) == 1) q++;
    for(int j = q; j < 100000; j++) {
      t = (t + dp[n - 1][j]) % MOD;
    }
    t = (3 * t) % MOD;
    ans = (ans + MOD - t) % MOD;
    if((sum % 2) == 0) ans = (ans + 3 * dp2[n - 1][(int)(sum / 2)]) % MOD; 
    System.out.println(ans);
  }
}

Measured memory_bytes: 460000
import collections
N = int(input())
temp = [input() for i in range(N)]

count = collections.Counter(temp)
counter = 1
ll = count.most_common()
for i in range(len(ll) -1):
    if ll[i][1] == ll[i + 1][1]:
        counter += 1
    else:
        break

l = count.most_common(counter)
l.sort()
for i in range(len(l)):
    print(l[i][0])

Measured memory_bytes: 61168
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main(){
	int n; string s;
	cin >> n >> s;
	int a[n]; Rep(i, n) a[i] = 0;
	Rep(i, n){
		if(s[i] == 'E'){
			a[0] += 1; a[i] -= 1;
		}else if(s[i] == 'W'){
			a[i + 1] += 1;
		}
	}
	For(i, 1, n){
		a[i] += a[i - 1];
	}
	int answer = inf;
	Rep(i, n){
		answer = min(a[i], answer);
	}
	cout << answer << endl;
}

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

int main()
{
    unsigned long long n, a, b, x, x1, xx;
    unsigned long long ans=0;
    cin>>n>>a>>b>>x1;
    for(int i=1; i<n; i++)
    {
        cin>>x;
        xx = x-x1;
        xx = xx*a;
        if(xx<b)
            ans+=xx;
        else
            ans+=b;
        x1 = x;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <iostream>
#include  <string.h>
using namespace std;
int main()
{
    char a[10],b[10],c[10];
    cin >>a>>b>>c;
    
    if(a[strlen(a)-1]==b[0]&&b[strlen(b)-1]==c[0]){
        cout <<"YES"<<endl;
    }
    else{
        cout <<"NO"<<endl;
    }
    
    return 0;
    
}

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

#define rep3(i, s, n ,a) for (int i = (s); i < (int)(n); i+=a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

int main(){
    int n;
    cin >> n;
    set<string> S;
    rep(i, n){
        string str;
        cin >> str;
        S.insert(str);
    }
    cout << S.size() << endl;
    return 0;
}

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

#define i64 long long int
#define ran 1011

int s[11], k;
i64 a[3][ran];
vector<i64> v;

vector<i64> vmerge(vector<i64> v, int id) {
	priority_queue<i64> q;
	while(!q.empty()) q.pop();
	for(int i=0;i<(int)v.size();i++)
		for(int j=0;j<s[id];j++) {
			i64 x = v[i] + a[id][j];
			
			if (q.size() < k) q.push(-x);
			else 
			if (-(q.top()) < x) {
				q.pop();
				q.push(-x);
			}
		}
	vector<i64>res(0);
	while(!q.empty()) {
		res.push_back(-q.top());
		q.pop();
	}
	reverse(res.begin(), res.end());
	return res;
}

int main() {
	cin>>s[0]>>s[1]>>s[2]>>k;
	for(int i=0;i<3;i++) {
		for(int j=0;j<s[i];j++)
			cin>>a[i][j];
		sort(a[i], a[i]+s[i]);
	}
	v.clear();
	for(int i=0;i<min(k, s[0]);i++) v.push_back(a[0][i]);
	v=vmerge(v, 1);
	v=vmerge(v, 2);
	for(int i=0;i<(int)v.size();i++)
		cout<<v[i]<<endl;
	
	return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
using namespace std;
using ll = long long;

int main(){
	int N, prev;
	ll A, B;
	scanf("%d %lld %lld\n%d", &N, &A, &B, &prev);
	ll answer = 0;
	for (int i = 1; i < N; ++i){
		int tmp;
		scanf("%d", &tmp);
		answer += min((tmp - prev)*A, B);
		prev = tmp;
	}
	printf("%lld\n", answer);
	return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i, x, y)   for (__typeof(x) i = x; i < y; i++)
#define repr(i, x, y)   for (__typeof(x) i = x; i > y; i --)
#define endl "\n"
#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define rSort(x)                     sort((x).rbegin(),(x).rend())
#define X                           first
#define Y                           second
#define sep                         ' '
#define SZ(x)                       ll(x.size())
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define pb                          push_back
#define mp                          make_pair
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define first X
#define second Y

const ll N = 1e18;
const ll M = 1e17 + 7;

int32_t main()
{
     IOS;
     ll n,v,m=1,c,flg=1;
     cin >> n;
     vll A;
     rep(i,0,n){
         cin >> v;
         A.pb(v);
         if(v==0) {cout << "0";flg=2;}
     }
     Sort(A);
     if(flg!=2){
     rep(i,0,n){
      v=A[i];
      c=N/v;
      if(m>c){ 
        cout << "-1";
        flg=0;
        break;
      }
      m*=v;
     }
     if(flg) cout << m;
     }
     
}


Measured memory_bytes: 4248
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// -------------------------------------------------------------------------------------



int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  sort(all(a));

  int ans = 0;
  int k = 0;
  int cnt = 0;
  rep(i, n+1) {
    if(i==n || a[i] != k) {
      // cout << cnt << ", " << k << endl;
      if(cnt > k) {
        ans += (cnt - k);
      } else if(cnt < k) {
        ans += cnt;
      }
      k = a[i];
      cnt = 0;
    }
    cnt++;
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

int main() {
    int K, S;
    cin >> K >> S;

    int ans = 0;
    for (int i = 0; i <= K; i++) {
        for (int j = 0; j <= K; j++) {
            if (S - i - j >= 0 && S - i - j <= K) ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {

    val nums = arrayOf(0, 2, 5, 5, 4, 5, 6, 3, 7, 6)

    val n = readLine()!!.split(' ').map { it.toInt() }.first()

    val map = mutableMapOf<Int, Int>()

    readLine()!!.split(' ')
            .map { it.toInt() }
            .forEach {
                val num = nums[it]
                map[num] = Math.max(map.getOrPut(num) { 0 }, it)
            }

    val dp = IntArray(n + 1) { -1 }

    dp[0] = 0

    for (i in (1..n)) {
        dp[i] = map.keys.map {
            if (it > i) {
                return@map -1
            }

            if (dp[i - it] == -1) {
                return@map -1
            }

            dp[i - it] + 1
        }.max()!!
    }

    val vs = map.values.sortedDescending()

    var res = ""
    var n1 = n

    repeat(dp[n]) {
        vs.forEach {
            val j = n1 - nums[it]
            if (j < 0) {
                return@forEach
            }
            if (dp[j] == dp[n1] - 1) {
                res += it.toString()
                n1 = j
                return@repeat
            }
        }
    }

    println(res)
}


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

int main(){
    int M, N;
    cin >> N;
    string s[N];
    for(int i=0;i<N;i++){
        cin >> s[i];
    }
    cin >> M;
    string t[M];
    for(int i=0;i<M;i++){
        cin >> t[i];
    }

    string tmp;
    int x, y;
    x = 1;
    y = 0;
    for(int i=0;i<N;i++){
        tmp = s[i];
        for(int j=i + 1;j<N;j++){
            if(s[j] == tmp) x++;
        }
        for(int k=0;k<M;k++){
            if(t[k] == tmp) x--;
        }
        
        if(y < x) y = x;
        x = 1;
    }
    cout << y << "\n";
}


Measured memory_bytes: 256
# coding: utf-8
N,M=map(int,input().split())
NL=[0 for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    NL[a-1]+=1
    NL[b-1]+=1

flg=True

for i in range(N):
    if NL[i]%2==1:
        flg=False

if flg:
    print("YES")
else:
    print("NO")


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

int main(){
  	int X;
  	scanf("%d",&X);
  	char N[100000001];
	snprintf(N, 100000001,"%d", X);
  	
  	int fx=0;
  	int i = 0;
  	while (N[i] != '\0') {
      fx += N[i] - 48;
      i++;
    }
  	
  	if (X % fx == 0) printf("Yes\n"); 
  	else printf("No\n");
  	return 0;
  
}

Measured memory_bytes: 128
using System;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i < 10; i++)
            {
                for (int j = 1; j < 10; j++)
                {
                    Console.WriteLine("{0}x{1}={2}", i, j, i*j);
                }
            }
        }
    }
}

Measured memory_bytes: 5588
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int A, B;
  cin>>A>>B;
  cout << (A*B%2 != 0 ?	"Yes" :	"No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

struct Edge{
  int from;
  int to;
  long cost;
};

vb seen(100010,false);
stack<int> stk;

void dfs(vector<vector<Edge>> &Graph, int v){
  seen[v] = true;
  for(Edge ed : Graph.at(v)){
    int nv = ed.to;
    if(seen.at(nv)) continue;
    dfs(Graph, nv);
  }
  stk.push(v);
}

int main(){
  int n,m;
  cin >> n >> m;
  vector<vector<Edge>> Graph(n);
  vector<vector<Edge>> rev(n);
  rep(i,m){
    int x,y;
    cin >> x >> y;
    x--;y--;
    Graph.at(x).push_back({x,y,1});
    rev.at(y).push_back({y,x,1});
  }
  rep(i,n){
    if(seen[i]) continue;
    dfs(Graph, i);
  }
  vi dp(n,0);
  while(stk.size()){
    int v = stk.top();
    stk.pop();
    for(Edge ed : Graph.at(v)){
      int nv = ed.to;
      dp.at(nv) = max(dp.at(nv), dp.at(v) + 1);
    }
  }
  int ans = 0;
  rep(i,n) ans = max(ans, dp[i]);
  cout << ans << endl;
}

Measured memory_bytes: 16856
#include<iostream>
#include<cstring>
using namespace std;

int num[10];

bool check(int n)
{
	while(n != 0)
	{
		if(num[n % 10] == 0)	return false;
		n /= 10;
	}
	return true;
}

int main()
{
	memset(num, 1, sizeof(num));
	int n, k;	cin >> n >> k;
	for(int i = 0; i < k; i ++)
	{
		int x;	cin >> x;
		num[x] = 0;
	}
	for(int i = 0; ; i ++)
	{
		if(check(i) && i >= n)
		{
			cout << i << endl;
			break;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}



  








      

 
  int main() {
  ll a,b;
  int k;
  cin >> a >> b >> k;
  vector <ll> ans(k*2);
  
  for(int i=0; i<k; i++){
        if(a+i>=((double)a+b)/2){
            break;
        }
        cout<<a+i<<endl;
    }

    for(int i=k-1; i>=0; i--){
        if(b-i<((double)a+b)/2){
            continue;
        }
        cout<<b-i<<endl;
    }
}




Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define pii pair<int,int>
#define vvi vector<vector<int> >
#define vpi vector<pii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define INF 0x7fffffff
#define LINF 0x7fffffffffffffff
#define MOD 1000000007
#define lowbit(x) x&(-x)
#define HS 173LL
#define int long long
using namespace std;
int read()
{
	int x=0;
	char ch=getchar();
	while(!isdigit(ch))
		ch=getchar();
	while(isdigit(ch))
	{
		x=x*10+ch-'0';
		ch=getchar();
	}
	return x;
}
const int maxn=2e5+10,mod=1e9+7;
int n,a[maxn],sum=0,ans=0;
signed main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		a[i]%=mod;
	}
	for(int i=1;i<=n;i++)
	{
		sum=(sum+a[i])%mod;
	}
	for(int i=1;i<n;i++)
	{
		sum=(sum-a[i]+mod)%mod;
		ans+=(a[i]*sum%mod);
		ans%=mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5176
#include<cstdio>

int main(){
	double a,b,c,d,e,f,x,y;
	while(scanf("%lf %lf %lf %lf %lf %lf", &a, &b, &c, &d, &e, &f) + 1){
		x = ( e * c - b * f) / ( a * e - b * d);
		y = ( - d * c + a * f) / ( a * e - b * d);
		printf("%.3f %.3f\n", x + 0.000001, y + 0.000001);
	}
	return 0;
}

Measured memory_bytes: 1084
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int64_t> A(N+1);
  vector<int64_t> B(N);
  for(int i=0;i<=N;i++)
    cin>>A.at(i);
  for(int i=0;i<N;i++)
    cin>>B.at(i);
  
  vector<int64_t>c(N+1);
  c.at(0)=0;
  for(int i=0;i<N;i++){
 if(B.at(i)<A.at(i)-c.at(i)){
 c.at(i)+=B.at(i); c.at(i+1)=0;
 }
  else if(A.at(i)-c.at(i)<=B.at(i) && B.at(i)-A.at(i)+c.at(i)<=A.at(i+1)){
   c.at(i+1)=B.at(i)-A.at(i)+c.at(i);c.at(i)=A.at(i);
  
  }else{
  c.at(i)=A.at(i); c.at(i+1)=A.at(i+1);
  }
  
  
  }int64_t sum=0;
  for(int i=0;i<=N;i++)
    sum+=c.at(i);
  cout<<sum<<endl;

return 0;
}

Measured memory_bytes: 2560
n,x,y = map(int,input().split())
dist = [0]*(n-1)
for i in range(1,n):
  for j in range(i+1,n+1):
    dist[min(abs(j-i),abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1)-1] += 1
for i in range(n-1):
  print(dist[i])

Measured memory_bytes: 47452
#include<iostream>
#include<algorithm>
#include<cstdint>
using namespace std; // 575

const int MAX = 1000;
const int MOD = 1000000007; // 今回使う余り
int main() {
	int N, M, A[MAX], B[MAX];
	cin >> N >> M;
	for (int i = 0;i < N;++ i) cin >> A[i];
	for (int i = 0;i < M;++ i) cin >> B[i];
	sort(A, A+N);
	sort(B, B+M);
	int64_t ans = 1, tmp;
	for (int i = 1;i < N;++ i) if (A[i - 1] == A[i]) ans = 0;
	for (int i = 1;i < M;++ i) if (B[i - 1] == B[i]) ans = 0;
	for (int i = N * M, rA = N, rB = M;i > 0;-- i) {
		if (rA > 0 && A[rA - 1] >= i) -- rA;
		if (rB > 0 && B[rB - 1] >= i) -- rB;
		if (A[rA] == i) {
			if (B[rB] == i) tmp = 1;
			else tmp = M - rB;
		} else {
			if (B[rB] == i) tmp = N - rA;
			else tmp = (N - rA) * (M - rB) - (N * M - i);
		}
		ans *= tmp;
		ans %= MOD;
	}
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

まず、表は並び替えても問題ない、同じだ同じ
よってAとBをソートして考えてみよう
BA  129 147 151 158 167 168 169 175 176 178 179 180 181 182
150 *** *** *** *** *** *** *** *** *** *** *** *** *** *** 
159 *** *** *** *** *** *** *** *** *** *** *** *** *** *** 
167 *** *** *** *** 167 *** *** *** *** *** *** *** *** *** 
169 *** *** *** *** *** *** 169 *** *** *** *** *** *** *** 
173 *** *** *** *** *** *** *** *** *** *** *** *** *** *** 
175 *** *** *** *** *** *** *** 175 *** *** *** *** *** *** 
176 *** *** *** *** *** *** *** *** 176 *** *** *** *** *** 
177 *** *** *** *** *** *** *** *** *** *** *** *** *** *** 
178 *** *** *** *** *** *** *** *** *** 178 *** *** *** *** 
179 *** *** *** *** *** *** *** *** *** *** 179 *** *** *** 
180 *** *** *** *** *** *** *** *** *** *** *** 180 *** *** 
181 *** *** *** *** *** *** *** *** *** *** *** *** 181 *** 
182 *** *** *** *** *** *** *** *** *** *** *** *** *** 182 
こう考えると分かるが、大きい数から決め打っていくと良さそう
まず、場合分けは次のようにできる
1. 両方に存在する→1通り
2. 片方に存在する→もう片方のうち自身より大きい数に等しい
3. 存在しない→両方の自身より大きい数全体の面積のうち、確定していない場所全部
*/

Measured memory_bytes: 256
if __name__ == '__main__':
    A, B, C, X, Y = map(int, input().split())

    # A, B, C, X, Y = map(int, "1500 2000 1600 3 2".split())
    # A, B, C, X, Y = map(int, "1500 2000 1900 3 2".split())
    # A, B, C, X, Y = map(int, "1500 2000 500 90000 100000".split())

    # not buy AB
    if A + B < 2 * C:
        total = A * X + B * Y
        print(total)
        exit(0)

    # buy AB
    n_c_at_least = 2 * min(X, Y)

    X, Y = X - n_c_at_least // 2, Y - n_c_at_least // 2
    total = C * n_c_at_least

    if X > Y:
        total += min(A, 2 * C) * (X - Y)
    else:
        total += min(B, 2 * C) * (Y - X)

    print(total)


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

using namespace std;

#define mod 1000000007
#define ll long long int
#define mk make_pair
#define pb push_back
#define xx first
#define yy second
#define ar array

double pi=3.141592653589793238;
const int M = 1e9+7;
const int Nmax=5005;
const int MM = 1e7+1;
const int N=50010;


int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t=1;
//cin>>t;
while(t--){
ll x,m;
cin>>x>>m;
ll ans=0;
m=m*m;
while(x--){
    ll a,b;
    cin>>a>>b;
    if(a*a+b*b<=m)ans++;
}
cout<<ans<<"\n";
}
	return 0;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    long long ans = 0;
    int max_height = 0;
    REP(i, N){
        ans += max(0, max_height-A[i]);
        max_height = max(max_height, A[i]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4012
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N; cin>>N;
    vector<set<pair<int,int64_t>>> G(N);
    rep(i,0,N-1){
        int a,b;
        int64_t c;
        cin>>a>>b>>c;
        a--; b--;
        G.at(a).insert(make_pair(b,c));
        G.at(b).insert(make_pair(a,c));
    }
    int Q,K; cin>>Q>>K;
    K--;
    vector<pair<int,int>> Pass;
    rep(i,0,Q){
        int x,y; cin>>x>>y;
        x--; y--;
        Pass.emplace_back(x,y);
    }

    vector<int64_t> Cost(N,-1);
    Cost.at(K)=0;

    queue<int> q;
    q.push(K);

    while(!q.empty()){
        int n=q.front(); q.pop();

        for(auto g:G.at(n)){
            if(Cost.at(g.first)>=0) continue;

            Cost.at(g.first)=Cost.at(n)+g.second;
            q.push(g.first);
        }
    }

    for(auto p:Pass){
        int64_t ans=Cost.at(p.first)+Cost.at(p.second);
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 20724
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#define int long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用

using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位



int x[100001], y[100001];
int a[200001];
int bo[100][100];


signed main() {
	int N, P;
	cin >> N >> P;
	int maxa = 1000000000000;
	int ans = 1;
	if (N == 1) {
		cout << P << "\n";
		return 0;
	}

	for (int i = 2; i*i <= maxa; i++) {
		int test = P;
		int cou = 0;
		while (test % i == 0) {
			test /= i;
			cou++;
		}
		if (cou >= N) {
			ans = i;
		}
	}
	cout << ans << "\n";
	

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			int gx = sc.nextInt();
			int gy = sc.nextInt();
			int p = sc.nextInt();
			Matatabi[] list = new Matatabi[p];
			for (int j = 0; j < p; j++) {
				list[j] = new Matatabi(sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt());
			}
			
			int[][] dp = new int[gx+1][gy+1];
			for (int j = 0; j <= gx; j++) {
				for (int k = 0; k <= gy; k++) {
					if(j > 0 && k > 0) {
						boolean flag = true;
						for (int l = 0; l < p; l++) {
							if (list[l].exists(j-1, k, j, k)) {
								flag = false;
							}
						}
						if (flag)
							dp[j][k] += dp[j-1][k];
						
						flag = true;
						for (int l = 0; l < p; l++) {
							if (list[l].exists(j, k-1, j, k)) {
								flag = false;
							}
						}
						if (flag)
							dp[j][k] += dp[j][k-1];
						
					} else if (j > 0) {
						boolean flag = true;
						for (int l = 0; l < p; l++) {
							if (list[l].exists(j-1, k, j, k)) {
								flag = false;
							}
						}
						if (flag)
							dp[j][k] += dp[j-1][k];
					} else if (k > 0) {
						boolean flag = true;
						for (int l = 0; l < p; l++) {
							if (list[l].exists(j, k-1, j, k)) {
								flag = false;
							}
						}
						if (flag)
							dp[j][k] += dp[j][k-1];

					} else {
						dp[0][0] = 1;
					}
				}
			}
			if (dp[gx][gy] > 0) {
				System.out.println(dp[gx][gy]);
			} else {
				System.out.println("Miserable Hokusai!");
			}
		}
	}
}

class Matatabi {
	int x1;
	int y1;
	int x2;
	int y2;
	
	public Matatabi(int x1, int y1, int x2, int y2) {
		this.x1 = x1;
		this.y1 = y1;
		this.x2 = x2;
		this.y2 = y2;
	}
	
	public boolean exists(int x1, int y1, int x2, int y2) {
		return (this.x1 == x1 && this.y1 == y1 && this.x2 == x2 && this.y2 == y2) 
			|| (this.x1 == x2 && this.y1 == y2 && this.x2 == x1 && this.y2 == y1);
	}
}

Measured memory_bytes: 27332
#include<bits/stdc++.h>
#define gc getchar()
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define Rep(i,v) rep(i,0,(int)v.size()-1)
#define lint long long
#define INF (LLONG_MAX/2-10)
#define db double
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define debug(x) cerr<<#x<<"="<<x
#define sp <<" "
#define ln <<endl
using namespace std;
typedef pair<int,int> pii;
typedef set<int>::iterator sit;
inline int inn()
{
	int x,ch;while((ch=gc)<'0'||ch>'9');
	x=ch^'0';while((ch=gc)>='0'&&ch<='9')
		x=(x<<1)+(x<<3)+(ch^'0');return x;
}
const int N=200010;lint s[N],f[N];int x[N];
inline int gabs(int x) { return x<0?-x:x; }
struct segment{
	int l,r;lint v[2];
	segment *ch[2];
}*rt;
int build(segment* &rt,int l,int r)
{
	rt=new segment,rt->l=l,rt->r=r;int mid=(l+r)>>1;
	rt->v[0]=rt->v[1]=INF;if(l==r) return 0;
	return build(rt->ch[0],l,mid),build(rt->ch[1],mid+1,r);
}
inline int push_up(segment* &rt)
{
	rt->v[0]=min(rt->ch[0]->v[0],rt->ch[1]->v[0]);
	rt->v[1]=min(rt->ch[0]->v[1],rt->ch[1]->v[1]);
	return 0;
}
int update(segment* &rt,int p,lint fs)
{
	int l=rt->l,r=rt->r,mid=(l+r)>>1;
	if(l==r) return rt->v[0]=min(rt->v[0],fs-p),rt->v[1]=min(rt->v[1],fs+p),0;
	if(p<=mid) update(rt->ch[0],p,fs);else update(rt->ch[1],p,fs);
	return push_up(rt);
}
lint query(segment* &rt,int s,int t,int k)
{
	int l=rt->l,r=rt->r,mid=(l+r)>>1;lint ans=INF;
	if(s<=l&&r<=t) return rt->v[k];
	if(s<=mid) ans=min(ans,query(rt->ch[0],s,t,k));
	if(mid<t) ans=min(ans,query(rt->ch[1],s,t,k));
	return ans;
}
inline lint solve(int n,int q)
{
	rep(i,1,q) s[i]=s[i-1]+gabs(x[i]-x[i-1]);
	f[1]=0,build(rt,1,n),update(rt,x[0],f[1]-s[1]);
	lint ans=f[1]+s[q]-s[1];
	for(int i=2;i<=q;i++)
	{
		f[i]=min(query(rt,1,x[i],0)+x[i],query(rt,x[i],n,1)-x[i])+s[i-1];
		update(rt,x[i-1],f[i]-s[i]);
//		f[i]=INF;for(int j=1;j<i;j++) f[i]=min(f[i],f[j]+gabs(x[i]-x[j-1])+s[i-1]-s[j]);
		ans=min(ans,f[i]+s[q]-s[i]);
	}
	return ans;
}
int main()
{
	int n=inn(),q=inn()+1;x[0]=inn(),x[1]=inn();
	rep(i,2,q) x[i]=inn();lint ans=solve(n,q);
	swap(x[0],x[1]),ans=min(ans,solve(n,q));
	return !printf("%lld\n",ans);
}

Measured memory_bytes: 41600
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define vi vector<int>
#define sort_v(a) sort(a.begin(), a.end())

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

int main()
{
    int n, m;
    int x[100000];
    cin >> n >> m;
    rep(i, 0, m) cin >> x[i];
    sort(x, x + m);
    if (n >= m)
    {
        cout << 0 << endl;
        return 0;
    }
    int dif[100000] = {};
    rep(i, 0, m - 1)
    {
        dif[i] = x[i + 1] - x[i];
    }
    sort(dif, dif + m - 1);
    int sum = 0;
    rep(i, 0, m - n)
    {
        sum += dif[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 1024
/* in the name of Anton */

/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#ifdef ARYANC403
    #include "/home/aryan/codes/PastCodes/template/header.h"
#else
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
    #pragma GCC optimize ("-ffloat-store")
    #include<iostream>
    #include<bits/stdc++.h>
    #define dbg(args...)
#endif

using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) ((lli)(x).size())
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;


const auto start_time = std::chrono::high_resolution_clock::now();
void aryanc403()
{
#ifdef ARYANC403
auto end_time = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
#endif
}

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
const int N=2e5+5;

lli fac[N+5],inv[N+5];
lli po(lli a,lli n)
{
    if(n==0)
        return 1;
    if(n%2)
        return (a*po(a,n-1))%mod;
    return po(a*a%mod,n/2);
}

lli nCr(lli n,lli r)
{
    if(n<0||r<0||r>n)
        return 0;
    lli ans=1;
    ans=(ans*fac[n])%mod;
    ans=(ans*inv[r])%mod;
    ans=(ans*inv[n-r])%mod;
    return ans;
}

void pre(lli n)
{
    lli i;
    fac[0]=1;
    repA(i,1,n)
        fac[i]=(i*fac[i-1])%mod;
    inv[n]=po(fac[n],mod-2);
    repD(i,n,1)
        inv[i-1]=(i*inv[i])%mod;
    assert(inv[0]==1);
}

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    string s;
    vi a;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{
    pre(N);
    cin>>n;
    vi a(n+1,-1);
    lli cnt=0;
    fo(i,n+1)
    {
        cin>>in;
        if(a[in]==-1)
            a[in]=i;
        else
            cnt=a[in]+(n-i);
    }

    dbg(cnt);
    repA(i,1,n+1)
        cout<<(nCr(n+1,i)-nCr(cnt,i-1)+mod)%mod<<endl;
    dbg("nxt");

}   aryanc403();
    return 0;
}


Measured memory_bytes: 7108
N=int(input())
a=list(map(int,input().split()))
b=[0]*N
c=[]
cnt=0
for i in range(1,N+1)[::-1]:
  if sum(b[i-1::i])%2 != a[i-1]:
    b[i-1]=1
    c.append(i)
    cnt+=1
print(cnt)
if len(c)>0:
  print(*c,sep='\n')

Measured memory_bytes: 14048
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
const ll MOD = 1e9 + 7;
const ll INF = (ll)1e18;

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}

int main() {
#ifdef HIRO
  string quiz(QUIZ);
  ifstream cin("input/" + quiz + ".txt");
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  ll n;
  cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  int m[100001] ={0};
  int arr[n];
  int ti=0;
  fi(0,n) cin>>arr[i];
  for(int i=0;;){
    m[i]=1;
    ti++;
    int next=arr[i]-1;
    if(next==1){
      cout<<ti;
      return 0;
    }
    else if(m[next]){
      cout<<-1;
      return 0;
    }
    i=next;
  }
  // cout << ans << endl;
  return 0;
}



Measured memory_bytes: 1152