akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <random>
#include <utility>
//#include <set>
//#include <map>
#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
ll INF = 1ll<<61 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}
void chmax(ll &a,ll b){	if(a<b) a = b ;}
void chmin(ll &a,ll b){ if(a>b) a = b ;}

int main(){
	ll n ; cin >> n ;
	vector<pll> x(n),y(n) ;
	for(int i=0;i<n;i++){
		cin >> x.at(i).first >> y.at(i).first ;
		x.at(i).second = y.at(i).second = i ;
	}
	sort(all(x)) ;
	sort(all(y)) ;
	vector<vector<pll>> g(n) ;
	for(int i=1;i<n;i++){
		int a = x.at(i-1).second ;
		int b = x.at(i).second ;
		g.at(a).emplace_back(x.at(i).first-x.at(i-1).first,b) ;
		g.at(b).emplace_back(x.at(i).first-x.at(i-1).first,a) ;
		a = y.at(i-1).second ;
		b = y.at(i).second ;
		g.at(a).emplace_back(y.at(i).first-y.at(i-1).first,b) ;
		g.at(b).emplace_back(y.at(i).first-y.at(i-1).first,a) ;
	}
	priority_queue<pll> pq ;
	pq.emplace(0,0) ;
	ll ans = 0 ;
	ll cnt = n ;
	vector<bool> use(n,false) ;
	while(!pq.empty()&&cnt){
		int p = pq.top().second ;
		int cost = -pq.top().first ;
		pq.pop() ;
		if(use.at(p)) continue ;
		ans += cost ;
		use.at(p) = true ;
		cnt-- ;
		for(int i=0;i<g.at(p).size();i++){
			int np = g.at(p).at(i).second ;
			if(use.at(np)) continue ;
			pq.emplace(-g.at(p).at(i).first,np) ;
		}
	}
	cout << ans << endl ;
}


Measured memory_bytes: 19396
N = int(input())
h = list(map(int, input().split()))

dp = [1000000000]*N
dp[0] = 0

for i in range(N-1):

    if dp[i+1] > abs(h[i+1] - h[i]) + dp[i] :
        dp[i+1] = abs(h[i+1] - h[i]) + dp[i]
    
    if i+2 < N:
        if dp[i+2] > abs(h[i+2] - h[i])+dp[i] :
            dp[i+2] = abs(h[i+2] - h[i]) + dp[i]
            
print(dp[N-1])

Measured memory_bytes: 13924
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define bit(k) (1LL<<(k))
typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<ll> X(N), Y(N);
    for(int i = 0; i < N;i++)cin >> X[i] >> Y[i];
    int wa = abs(X[0])+abs(Y[0]);
    for(int i = 0; i < N;i++){
        if(wa%2 != (abs(X[i])+abs(Y[i]))%2){
            cout << -1 << endl;
            return 0;
        }
    }
    vector<ll> d;
    for(int s = 32;s >= 0;s--){
        d.push_back(bit(s));
    }
    if((X[0]+Y[0])%2 == 0){
        d.push_back(1);
    }
    cout << d.size() << endl;
    rep(i,d.size()){
        cout << d[i] << " ";
    }
    cout << endl;
    for(int i = 0; i < N; i++){
        string ans = "";
        ll u = X[i] + Y[i];
        ll v = X[i] - Y[i];
        ll nx = 0;
        ll ny = 0;
        for(int j = 0; j < d.size();j++){
            //目的地まで+にしたい
            if(nx <= u){
                nx += d[j];
                if(ny <= v){
                    ny += d[j];
                    ans.push_back('R');
                }
                else{
                    ny -= d[j];
                    ans.push_back('U');
                }
            }
            else{
                nx -= d[j];
                if(ny <= v){
                    ny += d[j];
                    ans.push_back('D');
                }
                else{
                    ny -= d[j];
                    ans.push_back('L');
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
 
const int INF=1000000000;
 
using namespace std;
 
int main(void){
 
  int n,m,c,s,g,x,y,d,C;
  int p[21],q[21][51],r[21][51];
  int graph[21][101][101],G[101][101],cost[21][20001];;
   
  while(cin >> n >> m >> c >> s >> g,n|m|c|s|g){
   
    fill(graph[0][0],graph[21][101],INF);
    fill(G[0],G[101],INF);

    for(int i=0;i<21;i++)
      for(int j=0;j<101;j++)
	graph[i][j][j]=0;
 
    for(int i=0;i<m;i++){
      cin >> x >> y >> d >> C;
      graph[C][x][y]=graph[C][y][x]=min(graph[C][x][y],d);
    }
    
    for(int i=1;i<=c;i++)cin >> p[i];
    
    for(int i=1;i<=c;i++){
      for(int j=1;j<p[i];j++)cin >> q[i][j];
      for(int j=1;j<=p[i];j++)cin >> r[i][j];
    }
    
    for(int l=1;l<=c;l++){
      for(int k=1;k<=n;k++){
	for(int i=1;i<=n;i++){
	  for(int j=1;j<=n;j++){
	    graph[l][i][j]=min(graph[l][i][j],graph[l][i][k]+graph[l][k][j]);
	  }
	}
      }
    }
   
    fill(cost[0],cost[21],0);
    
    for(int i=1;i<=c;i++){
      for(int j=1,k=0;j<20001;j++){
	if(k<p[i] && q[i][k]<j)k++;
	cost[i][j]=cost[i][j-1]+r[i][k];
      }
    }
    
    for(int l=1;l<=c;l++){
      for(int i=1;i<=n;i++){
	for(int j=1;j<=n;j++){
	  if(graph[l][i][j]!=INF)
	    G[i][j]=min(G[i][j],cost[l][graph[l][i][j]]);
	}
      }      
    }
    
    for(int k=1;k<=n;k++)
      for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
	  G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
    
    if(G[s][g]==INF)cout << -1 << endl;
    else cout << G[s][g] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3684
import sys
# sys.setrecursionlimit(100000)


class UnionFind:
    def __init__(self, n: int):
        self.nodes = n
        self.parents = [-1] * n
        self.rank = [0] * n

    # retrun the root of element x
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # unite the group include element x and group include element y
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parents[y] += self.parents[x]
            self.parents[x] = y
        else:
            self.parents[x] += self.parents[y]
            self.parents[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # get size of the gourp which element x belongs
    def get_size(self, x):
        return -self.parents[self.find(x)]

    # check if element x and element y is same group
    def same(self, x, y):
        return self.find(x) == self.find(y)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n, m = input_int_list()
    union = UnionFind(n + 1)
    for _ in range(m):
        a, b = input_int_list()
        union.unite(a, b)

    ans = min(union.parents) * (-1)
    print(ans)

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 80960
N, M = list(map(int, input().split()))
S=input()
T=input()

from fractions import gcd
g = gcd(N,M)
n = N//g
m = M//g

if all([S[i*n]==T[i*m] for i in range(g)]):
  print((N*M)//g)
else:
  print(-1)

Measured memory_bytes: 5432
gets
array = gets.split(" ").map{|i| i.to_i}
max_num = 0
current_num = 0

array.each_with_index{|j,index|
  if array[index+1] then
    if array[index+1] <= j then
      current_num += 1
    else
      if max_num <= current_num then
        max_num = current_num
      end
      current_num = 0
    end
  else
    if max_num <= current_num then
      max_num = current_num
    end
    current_num = 0
  end
    }

puts max_num



Measured memory_bytes: 8580
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner in = new Scanner(System.in);
    int noOfItems = in.nextInt();
    int W = in.nextInt();
    Item[] items = new Item[noOfItems];
    
    for (int k = 0; k < noOfItems; k++) {
      items[k] = new Item(in.nextInt(), in.nextInt());
    }
    
    long[] dp = new long[W + 1];
    for (int i = 0; i < dp.length; i++) {
      dp[i] = 0L;
    }

    for (int i = 0; i < items.length; i++) {
      for (int j = W - items[i].weight; j >= 0; j--) {
        dp[j + items[i].weight] = Math.max(dp[j + items[i].weight], items[i].price + dp[j]);

      }

    }
    System.out.println(dp[W]);
    in.close();
  }


  static class Item implements Comparable<Item> {
    int weight;
    int price;

    public Item(int w, int p) {
      this.weight = w;
      this.price = p;
    }

    public int compareTo(Item t) {
      return this.weight - t.weight;
    }
  }

}


Measured memory_bytes: 23380
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
#define PI 3.14159265358979323846264338327950L
using namespace std;
using P = pair<int,int>;
using ll = long long;
using namespace std;
int main(void){
    // Your code here!
    ll n; cin >> n;
    ll ans = 0;
    rep(i, n+1){
        if(i % 3 == 0 or i % 5 == 0){continue;}
        ans += i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3504
$n = <>;chomp $n;
@a = ();
for my $_n (0..$n-1) {
    $a[$_n] = <>;
    chomp $a[$_n];
}

$i = 0;
$count  = 1;
$flg = 0;
for my $_n (0..$n-1) {
    next if $flg;
    if ($a[$i] == 2) {
        print $count;
        $flg=1;
    }

    $i = $a[$i] - 1;
    $count++;
}

print -1 unless $flg;


Measured memory_bytes: 17024
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n,a[100010];

int main(){
	cin >> n;
	REP(i,0,n) cin >> a[i];
	
	int f=2, c=1;
	REP(i,0,n-1){
		if(f==2 and a[i]<a[i+1]) f=1;
		else if(f==2 and a[i]>a[i+1]) f=0;
		else if(a[i]==a[i+1]) continue;
		else if(f and a[i]<a[i+1]) continue;
		else if(!f and a[i]>a[i+1]) continue;
		else c++,f=2;
		
	}
	
	cout << c << endl;
	return 0;
}



Measured memory_bytes: 640
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix

from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！

def main():
    n,*a=map(int,open(0).read().split())
    mod=10**9+7
    b=Counter(a).most_common()[0][0]
    l=a.index(b)
    r=a.index(b,l+1)
    n+=1
    nd=l+n-r-1
    
    inv=[0]*(n+1)
    inv[1]=1
    for i in range(2,n+1):
        inv[i]=(-(mod//i)*inv[mod%i])%mod
    tmp=n
    tmp2=1
    print(n-1)
    for i in range(2,n+1):
        tmp=(tmp*(n-i+1)*inv[i])%mod
        tmp2=(tmp2*(nd-i+2)*inv[i-1])%mod
        print((tmp-tmp2)%mod)


if __name__ == '__main__':
    main()

Measured memory_bytes: 23124
A, B = [int(v) for v in input().split()]

minV = min(A, B)
maxV = max(A, B)

if maxV % minV == 0:
  print(maxV)
  exit()

if maxV == minV + 1:
  print(maxV * minV)
  exit()

v = maxV * 2

for i in range(2, minV + 1):
  if v % minV != 0:
    v += maxV
    continue
  print(v)
  exit()


Measured memory_bytes: 3064
import math

a, b, x = map(int,input().split())
#xが0.5*Vを超えるか超えないかで場合分け
if x > 0.5*a*a*b:
    y = 2*x/a/a - b
    tan = (b-y)/a
    ans = math.atan(tan)
    print(math.degrees(ans))

elif x < 0.5*a*a*b:
    y = 2*x/a/b
    tan = b/y
    ans = math.atan(tan)
    print(math.degrees(ans))

else:
    print("45.0000000000")

Measured memory_bytes: 3064
"""
組み合わせ, nCrのmod

(i+1, j+2)で動く回数をm回、(i+2, j+1)で動く回数をn回とすると
m + 2n = x
2m + n = y
の方程式の解として、m,nが0以上の整数で求められる必要がある

m,nが0以上の整数で求められなければそのような行き方はない
求められれば、全部でm+n回の動きの中でどのm回で(i+1, j+2)の動きをするか（ないし、どのn回で(i+2, j+1)の動きをするか）が行き方の数なので、m+nCmを求めれば良い
"""
x,y = map(int, input().split())

mod = 10**9+7

def choose(n,r):
    p,q = 1,1
    for i in range(r):
        p = p*(n-i)%mod
        q = q*(i+1)%mod
    return p * pow(q,mod-2,mod) % mod # modの世界では逆元はpow(x,mod-2)をかけることと同じ

n = (2*x-y)/3
m = (y-n)/2

#if n >= 0 and m >= 0 and int(n)*10 == n*10 and int(m)*10 == m*10:
#    ans = choose(int(m+n), int(m))
if n >= 0 and m >= 0 and not n%1 and not m%1:
    ans = choose(int(m+n), int(m))
else:
    ans = 0
print(ans)

Measured memory_bytes: 3064
<?php
fscanf(STDIN, "%d %d %d", $a, $b, $k);

$count = 1;
$start = min($a, $b);
for( $i=$start; $i>=1; $i-- )
{
  if( $a % $i == 0 && $b % $i == 0 )
  {
    $k--;
    if( $k == 0 )
    {
      echo $i;
      exit;
    }
  }  
}

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

#define COUT(x) cout << #x << " = " << (x) << ", "
typedef long long ll;
const int MOD = 1000000007;

const int MAX = 1000000; //„ÉÜ„Éº„Éñ„É´„ÅÆÂ§ß„Åç„Åï

//a„ÅÆn‰πó(mod MOD)„ÇíË®àÁÆó
ll modPow(ll a, ll n){ 
  if(n == 1) return a % MOD;
  if(n % 2 == 1) return (a * modPow(a, n-1)) % MOD;
  ll tmp = modPow(a, n/2);
  return (tmp * tmp) % MOD;
}

ll fac[MAX], finv[MAX], inv[MAX];
//„ÉÜ„Éº„Éñ„É´„Çí‰Ωú„ÇãÂâçÂá¶ÁêÜ MAX=1000000 „Åæ„Åß
void COMint(){
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for(int i = 2; i < MAX; i++){
    fac[i] = fac[i-1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i-1] * inv[i] % MOD;
  }
}

//n„ÅåÂ§ß„Åç„ÅÑ„Å®„Åç
ll com[MAX];
void FastCOMinit(int n){
  COMint();
  com[0] = 1;
  for(int i = 1; i < MAX; i++){
    com[i] = (com[i-1] * (n - i + 1) % MOD) * inv[i] % MOD;
  }
}


int main(){
  ll n,a,b;
  cin >> n >> a >> b;
  ll two = modPow(2, n) - 1;
  FastCOMinit(n);
  ll res = (two - com[a] - com[b] + MOD + MOD) % MOD;
  cout << res << endl;
}


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

int main(){
  string sa,sb,sc;
  cin >> sa >> sb >> sc;
  int sas=sa.size();
  int sbs=sb.size();
  int scs=sc.size();
  int Sa=sas,Sb=sbs,Sc=scs;
  
  string x = "a";
  for(int i=0; i<sas+sbs+scs+1; i++){
   if(Sa==0 && x=="a"){
     cout << 'A' << endl;
     return 0;
   }
    if(Sb==0 && x=="b"){
     cout << 'B' << endl;
     return 0;
   }
    if(Sc==0 && x=="c"){
     cout << 'C' << endl;
     return 0;
   }
   if(x=="a"){
     x=sa[sas-Sa];
     Sa--;
   }
   else if(x=="b"){
     x=sb[sbs-Sb];
     Sb--;
   }
   else if(x=="c"){
     x=sc[scs-Sc];
     Sc--;
   }
  }
}

Measured memory_bytes: 384
K, N = list(map(lambda x: int(x), input().split(" ")))
A = list(map(lambda a: int(a), input().split(" ")))

D = [A[i + 1] - A[i] if i < len(A) - 1 else K - A[i] + A[0] for i in range(len(A))]
D.sort()
print(K - D[-1])

Measured memory_bytes: 32256
import numpy as np


def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

def lcm_base(x, y):
    return x*y // gcd(x, y)

N = int(input())
T = [int(input()) for _ in range(N)]

ans = 1
for t in T:
    ans = lcm_base(ans,t)
print(ans)


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

class Daice{
	int mas[];
	Daice(int[] mas){
		this.mas = mas;
	}

	void north() {
		int temp = mas[4];
		mas[4] = mas[0];
		mas[0] = mas[1];
		mas[1] = mas[5];
		mas[5] = temp;
	}

	void south() {
		int temp = mas[0];
		mas[0] = mas[4];
		mas[4] = mas[5];
		mas[5] = mas[1];
		mas[1] = temp;
	}

	void east() {
		int temp = mas[0];
		mas[0] = mas[3];
		mas[3] = mas[5];
		mas[5] = mas[2];
		mas[2] = temp;
	}

	void west() {
		int temp = mas[0];
		mas[0] = mas[2];
		mas[2] = mas[5];
		mas[5] = mas[3];
		mas[3] = temp;
	}

	int umen(int usam, int msam) {
		int u = 0;
		int m = 0;
		for(int i = 0; i < this.mas.length; i++) {
			if(this.mas[i] == usam) {
				u = i + 1;
			}
		}

		for(int i = 0; i < this.mas.length; i++) {
			if(this.mas[i] == msam) {
				m = i + 1;
			}
		}

		if(u == 1) {
			if(m == 2) {
				return 3;
			}else if(m == 3) {
				return 5;
			}else if(m == 4) {
				return 2;
			}else {
				return 4;
			}
		}else if(u == 2) {
			if(m == 1) {
				return 4;
			}else if(m == 3) {
				return 1;
			}else if(m == 4) {
				return 6;
			}else {
				return 3;
			}
		}else if(u == 3) {
			if(m == 1) {
				return 2;
			}else if(m == 2) {
				return 6;
			}else if(m == 5) {
				return 1;
			}else {
				return 5;
			}
		}else if(u == 4) {
			if(m == 1) {
				return 5;
			}else if(m == 2) {
				return 1;
			}else if(m == 5) {
				return 6;
			}else {
				return 2;
			}
		}else if(u == 5) {
			if(m == 1) {
				return 3;
			}else if(m == 3) {
				return 6;
			}else if(m == 4) {
				return 1;
			}else {
				return 4;
			}
		}else {
			if(m == 2) {
				return 4;
			}else if(m == 3) {
				return 2;
			}else if(m == 4) {
				return 5;
			}else {
				return 3;
			}
		}
	}

	void turn() {
		int temp = this.mas[1];
		this.mas[1] = this.mas[2];
		this.mas[2] = this.mas[4];
		this.mas[4] = this.mas[3];
		this.mas[3] = temp;
	}
}

class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int m[] = {sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt()};

		Daice d = new Daice(m);

		int m2[] = {sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt()};

		Daice d2 = new Daice(m2);

		int top = 0;


		for(int i = 0; i < d2.mas.length; i++) {
			if(d.mas[0] == d2.mas[i]) {
				top = i + 1;
				break;
			}
		}
		if(d.mas[0] == d.mas[1] && d.mas[1] == d.mas[2]) {
			d.mas[1] = d.mas[5];
			d.mas[5] = d.mas[2];
			top = 1;
		}

		if(top == 6) {
			d2.south();
			d2.south();
		}else if(top == 5) {
			d2.south();
		}else if(top == 4){
			d2.east();
		}else if(top == 3) {
			d2.west();
		}else if(top == 2) {
			d2.north();
		}

		int mae = 0;

		for(int i = 1; i < 5; i++) {
			if(d.mas[1] == d2.mas[i]) {
				mae = i + 1;
				break;
			}
		}
		if(mae == 0) {
			System.out.println("No");
		}

		if(mae == 3) {
			d2.turn();
		}else if(mae == 4) {
			d2.turn();
			d2.turn();
			d2.turn();
		}else if(mae == 5){
			d2.turn();
			d2.turn();
		}else {

		}
		if(Arrays.equals(d.mas, d2.mas)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 26436
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    cin >> n;
    VI a(n);
    REP(i,n){
        scanf("%d", &a[i]);
        a[i]--;
    }
    int ans = 0;
    REP(i,n){
        if (a[a[i]] == i){
            ans ++;
        }
    }
    cout << ans/2 << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


int main(){
    string s; cin>>s;
    ll k; cin>>k;
    rep(i, k){
        if(i >= s.size()) break;
        if(s[i] != '1'){
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << '1' << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rng(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int MOD = 1e9+7;


vector<vector<char>> tab(1010,vector<char>(1010,'#'));
ll dp[1010][1010];

int main() {
  int h, w;
  cin >> h >> w;
  for(int i = 1; i <= h; i++) {
    for(int j = 1; j <= w; j++) {
      cin >> tab[i][j];
    }
  }
  memset(dp,0,sizeof(dp));
  dp[h][w] = 1;
  for(int i = h; i > 0; i--) {
    for(int j = w; j > 0; j--) {
      if(tab[i][j]=='#') continue;
      if(tab[i-1][j]=='.') (dp[i-1][j] += dp[i][j])%=MOD;
      if(tab[i][j-1]=='.') (dp[i][j-1] += dp[i][j])%=MOD;
    }
  }
  cout << dp[1][1] << endl;
  return 0;
}

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

ll n,m;
vector<ll>gr[100005];
bool vis[200005]; 
ll dp[200005];
 ll dfs(ll node){
 	ll ans=0;
 	vis[node]=1;
 	for(ll i=0;i<gr[node].size();i++){
 		if(!vis[gr[node][i]]){
 		//	cout<<node<<' '<<gr[node][i]<<'\n';
 			ans=max(ans,1+dfs(gr[node][i]));
 		}
 		else{
 			ans=max(ans,1+dp[gr[node][i]]);
 		}
 		
 			
 		//};
 	}
 	dp[node]=ans;
 	return ans;
 }
 
int main(){
	//ll n,m;
	cin>>n>>m;
	memset(vis,0,sizeof(vis));
	for(ll i=0;i<m;i++){
		ll a,b;
		cin>>a>>b;
		gr[a].push_back(b);
	}
	ll ans=0;
	for(ll i=1;i<=n;i++){
		//if(!vis[i]){
	//	memset(vis,0,sizeof(vis));
			ans=max(ans,dfs(i));
	//	}
	}
	cout<<ans;
}

Measured memory_bytes: 8704
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Bits

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    as <- getIntList
    let s = foldl1' xor as
    let ans = map (xor s) as
    putStrLn . unwords $ map show ans

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

using namespace std;

typedef long long ll;

int a[8];
int main() {
  for (int i = 1; i <= 7; ++i) scanf("%d", &a[i]);
  ll ans = a[2];
  if (!a[1] || !a[4] || !a[5])
    ans += a[1] / 2 * 2 + a[4] / 2 * 2 + a[5] / 2 * 2;
  else {
    ans += (ll)a[1] + a[4] + a[5];
    ans -= !(a[1] % 2 == a[4] % 2 && a[4] % 2 == a[5] % 2);
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
n=int(input())
A=list(map(int,input().split()))
B=list(map(int, input().split()))
ans=0
for k in range(29):
    A_k,B_k=[[],[]],[[],[]]
    for ai in A:
        A_k[(ai&(1<<k))>>k].append(ai)
    for bi in B:
        B_k[(bi&(1<<k))>>k].append(bi)
    A,B=[],[]
    for i in range(2):
        A+=A_k[i]
        B+=B_k[i]
    mod=1<<(k+1)
    A_mod=[ai%mod for ai in A]
    B_mod=[bi%mod for bi in B]
    t=1<<k
    S=[n]*4
    cnt=0
    for ai in A_mod:
        Border=[t-ai,t*2-ai,t*3-ai,t*4-ai]
        for i in range(4):
            while 0<S[i] and Border[i]<=B_mod[S[i]-1]:
                S[i]-=1            
        cnt+=((S[1]-S[0])+(S[3]-S[2]))
    if cnt&1:
        ans+=t
print(ans)

Measured memory_bytes: 144060
n=int(input())
ST=[]
for i in range(n):
  s,t=map(str,input().split())
  ST.append((s,t))
chk=False
x=input()
ans=0
for s,t in ST:
  if chk:
    ans+=int(t)
  else:
    if s==x:
      chk=True
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n,m;
    cin >> n;
    intl a[n];
    cin(i,a);
    intl cnt = 1;
    sort(a,a + n,greater<>());
    rep(i,n-1)cnt += (a[i]>a[i+1]);
    cout << cnt << 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();
    int[] bricknumber=new int[N];
    int[] index=new int[N+2];//iのあったbricknumberのindex
    int last=N;
    
    for(int h=0;h<N;h++){
      bricknumber[h]=sc.nextInt();
    }
    
    index[0]=0;
    for(int k=1;k<=N;k++){
      index[k]=-1;
    }
    
    for(int i=1;i<=N;i++){
      for(int j=index[i-1];j<N;j++){
        if(bricknumber[j]==i){
          index[i]=j;
          break;
        }
      }
      if(index[i]==-1){
        last=i-1;
        break;
      }
      
    }
    if(last==0){
      last=N+1;
    }
    
    System.out.println(N-last);
    
  }
}

Measured memory_bytes: 85080
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

struct str {
	ll dis, x, y;
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n;
	cin >> n;
	vector<vector<ll>> ans(10, vector<ll>(10));
	ans[0][1] = ans[1][0] = 1;
	ans[0][2] = ans[2][0] = 2;
	ans[1][2] = ans[2][1] = 3;
	vector<str> vec;
	vec.pb({ 1,0,1 }); vec.pb({ 2,0,2 }); vec.pb({ 3,1,2 });
	for (int i = 3; i < 10; i++) {
		for (int j = 0; j < i; j++) {
			ll sum = 1;
			vector<int> check(10);
			int cnt = i;
			if (j == 0) cnt--;
			int small = cnt - 1; int big = cnt;
			for (int s = 0; s < vec.size(); s++) {
				if (small == 0) break;
				sum -= vec[s].dis;
				check[vec[s].x]++; check[vec[s].y]++;
				small--;
			}
			rep(c, 10) check[c] = 0;
			for (int s = vec.size() - 1; s >= 0; s--) {
				if (big == 0) break;
				if (check[vec[s].x] < 2 && check[vec[s].y] < 2) {
					sum += vec[s].dis;
					check[vec[s].x]++; check[vec[s].y]++;
					big--;
				}
			}
			vec.pb({ sum,i,j });
			ans[i][j] = ans[j][i] = sum;
		}
	}
	rep(i, n) {
		rep(j, n) {
			cout << ans[i][j] << ' ';
		}
		cout << '\n';
	}
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

int main()
{
    int R;
    cin >> R;
    cout << fixed << setprecision(10) << 2 * R * M_PI << endl;
    return 0;
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
long long dp[105][100005];
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<=n;i++)
		for(int j=0;j<=m;j++)
			dp[i][j]=-1;
	dp[0][0]=0;
	for(int i=1;i<=n;i++)
	{
		int a,b;
		cin>>a>>b;
		for(int j=0;j<=m;j++)
		{
			if(dp[i-1][j]!=-1)
			{
				dp[i][j]=max(dp[i][j],dp[i-1][j]);
				if(j+a<=m)dp[i][j+a]=max(dp[i][j+a],dp[i-1][j]+b);
			}
		}
	}
	long long ans=-1;
	for(int i=1;i<=m;i++)
		ans=max(ans,dp[n][i]);
	cout<<ans;
	return 0;
}

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

#define mod 1000000007

using namespace std;
 
int main(void){
	
	double A, B, C, D, E, F, sum = 0, sugar = 0, ans1 = 0, ans2 = 0;
	int i, j, k, l;
	double max = -1;
	
	cin >> A >> B >> C >> D >> E >> F;
	
	for(i=0; 100*A*i <= F; i++){
		for(j=0; 100*(A*i + B*j) <= F; j++){
			for(k=0; k*C<=E*(A*i + B*j); k++){
				for(l=0; k*C+l*D<=E*(A*i + B*j); l++){
					sum = 100*A*i + 100*B*j + k*C + l*D;
					sugar = k*C + l*D;
					if(sum > 0){
						if(max < sugar/sum && sum <= F){
							max = sugar / sum;
							ans1 = sum;
							ans2 = sugar;
						}
					}
				}
			}
		}
	}
	
	cout << ans1 << " " << ans2 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };


int main(void) {
    int H, N;
    vector<int> A(1010),B(1010);
    cin >> H >> N;
    for (int i=1;i<=N;i++) cin >> A[i] >> B[i];

    vector<int> dp1(100000010,0), dp2(100000010,0);
    for (int i=1;i<=N;i++) {
        // for (int j=0;j<=1000010;j++) dp2[j] = 0;
        for (int j=0;j<=100000010;j++) {
            if (j-B[i]>=0) dp2[j] = max(dp1[j],dp2[j-B[i]]+A[i]);  
            else dp2[j] = dp1[j];
            if (dp2[j] >= H) break;
        }
        dp1.swap(dp2);
    }
    // for (int i=0;i<=N;i++) {
    //     for (int j=0;j<=15;j++) cout << dp[i][j] << " ";
    //     cout << endl;
    // }
    for (int j=1;j<=100000010;j++) if (dp1[j] >= H) {
        cout << j << endl;
        break;
    }

    return 0;
}


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

int main(){
    int n, k;
    cin >> n >> k;

    deque<int> d;
    for(int i = 0; i < n; i++){
        int v; cin >> v;
        d.emplace_back(v);
    }
    int op = min(n, k);
    ll ans = 0;
    for(int l = 0; l <= op; l++){
        for(int r = 0; r <= op - l; r++){
            vector<int> vec;
            deque<int> dq = d;
            for(int i = 0; i < l; i++){
                int tmp = dq.front();
                dq.pop_front();
                vec.emplace_back(tmp);
            }
            for(int i = 0; i < r; i++){
                int tmp = dq.back();
                dq.pop_back();
                vec.emplace_back(tmp);
            }
            int retop = k - (l + r);
            int vecs = vec.size();
            retop = min(retop, vecs);
            sort(vec.begin(), vec.end());
            for(int i = 0; i < retop; i++){
                if(vec[i] >= 0) break;
                vec[i] = 0;
            }
            ll total = accumulate(vec.begin(), vec.end(), 0LL);
            ans = max(ans, total);
        }
    }
    cout << ans << endl;
}


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

using namespace std;

signed main() {
	//freopen("input.txt", "r", stdin);
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	string s, t;
	cin >> s >> t;

	int n = s.size();
	for (int i = 0; i < n; ++i) {
	 	string ns = s.substr(n - i, i) + s.substr(0, n - i);
	 	if (ns == t) {
	 	 	cout << "Yes\n";
	 	 	return 0;
	 	}
	}

	cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 
  string S,T,U;
  int A,B;
 
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
 
  if(S == U){
    A--;
  }
  
  else{
    B--;
  }
  
  cout << A << " "<< B << endl;
  
}

Measured memory_bytes: 256
N = gets.to_i
C = N.times.map{gets.to_i}
MOD = 10**9+7

left = Array.new(200001, -1)
dp = Array.new(N+1, 0)
dp[0] = 1
N.times do |i|
    dp[i+1] += dp[i]
    c = C[i]
    if left[c] >= 0 && left[c] < i-1
        dp[i+1] += dp[left[c]+1]
    end
    dp[i+1] %= MOD
    left[c] = i
end

puts dp[N]

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

int64_t sum(int x){
  int64_t y=0;
  for(int i=1; i<=x; i++){
    y += i;
  }
  return y;
}

int main() {
  string S;
  cin >> S;
  int N = S.size()+1;
  int64_t ans=0;
  int l=0, r=0;
  
  for(int i=0; i<N-2; i++){
    if(S.at(i) == '>' && S.at(i+1) == '<'){
      ans += sum(max(l+1,r)) + sum(min(l+1,r)-1);
      l=0;
      r=0;
    }else if(S.at(i) == '>'){
      l++;
    }else if(S.at(i) == '<'){
      r++;
    }
  }
  if(S.at(N-2) == '>'){
    l++;
  }else{
    r++;
  }
  ans += sum(max(l,r)) + sum(min(l,r)-1);
  
  cout << ans << endl;
}

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

int main(){
    int A,B,K;
    cin >> A >> B >> K;

    if(K > (B-A)/2) {
        for(int i = A; i < B+1;i++) {
            cout << i << endl;
        }
    } else {
        for(int i = A; i < A + K; i++) {
            cout << i << endl;
        }
        for(int i = B-K+1; i < B + 1; i++) {
            cout << i << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Main {

	public void run() throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		List<Integer> arrayData = new ArrayList<Integer>();
		String[] lineArray = line.split(" ");
		for (String token : lineArray) {
			arrayData.add(Integer.parseInt(token));
		}
		int A = arrayData.get(0);
		int B = arrayData.get(1);
		int K = arrayData.get(2);
		List<Integer> li = new ArrayList<Integer>();
		int smaller = Math.min(A, B);
		for(int i=1; i<=smaller;i++){
	
				if(A%i == 0 && B%i == 0){
					li.add(i);
				}

		}
		
		Collections.reverse(li);
		System.out.println(li.get(K-1));
	}
    public static void main(String[] args) throws Exception {
        new Main().run();
    }

}

Measured memory_bytes: 32544
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
using namespace std;

int main() {
	int H,W,ans=1000000,a,b,c;
	cin>>H>>W;
	a=H/3;
	b=(H-a)/2;
	c=H-b-a;
	if(a>b)swap(a,b);
	if(b>c)swap(b,c);
	if(a>b)swap(a,b);
	ans=min(ans,c*W-a*W);
	a=W/3;
	b=(W-a)/2;
	c=W-b-a;
	if(a>b)swap(a,b);
	if(b>c)swap(b,c);
	if(a>b)swap(a,b);
	ans=min(ans,c*H-a*H);
	a=H/3;
	b=W/2;
	c=W-b;
	ans=min(ans,max(max(a*W,b*(H-a)),c*(H-a))-min(min(a*W,b*(H-a)),c*(H-a)));
	a=H/3+1;
	b=W/2;
	c=W-b;
	ans=min(ans,max(max(a*W,b*(H-a)),c*(H-a))-min(min(a*W,b*(H-a)),c*(H-a)));
	a=W/3;
	b=H/2;
	c=H-b;
	ans=min(ans,max(max(a*H,b*(W-a)),c*(W-a))-min(min(a*H,b*(W-a)),c*(W-a)));
	a=W/3+1;
	b=H/2;
	c=H-b;
	ans=min(ans,max(max(a*H,b*(W-a)),c*(W-a))-min(min(a*H,b*(W-a)),c*(W-a)));
	cout<<ans;
}

Measured memory_bytes: 256
import numpy as np
N,L = (int(x) for x in input().split())
sum = N*(2*L+N-1)/2
if L >= 0:
  print(int(sum - L))
elif(L < 0 and L+N-1>0):
  print(int(sum))
else:
  print(int(sum - (L+N-1)))



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

using namespace std;
using ll = long long;

const int MOD = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<bool> ban(N + 1);
  for (int i = 0; i < M; i++) {
    int a;
    cin >> a;
    ban[a] = true;
  }
  vector<ll> dp(N + 2, 0);
  dp[0] = 1;
  for (int i = 0; i < N; i++) {
    if (ban[i]) continue;
    dp[i + 1] = (dp[i + 1] + dp[i]) % MOD;
    dp[i + 2] = (dp[i + 2] + dp[i]) % MOD;
  }
  cout << dp[N] << '\n';
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

    public static void main (String [] args){
        Scanner  sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Y = sc.nextInt();
        boolean flag = true;
        for (int x=0; x<= N; x++){
            for (int y =0; x+y <= N; y++){
                int z = N-y-x;
                if ((10000*x + 5000*y + 1000*z) == Y){
                    System.out.println(x+" "+ y+" "+z);
                    flag = false;
                    return;
                }
            }
        }
        if (flag){
            System.out.println("-1 -1 -1");
        }

    }
}

Measured memory_bytes: 22868
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int N = stdIn.nextInt();
			int A = stdIn.nextInt();
			int B = stdIn.nextInt();
			int C = stdIn.nextInt();
			int X = stdIn.nextInt();
			if(N == 0 && A == 0 && B == 0 && C == 0 && X == 0)
			{
				break;
			}
			List<Integer> list = new ArrayList<Integer>();
			for(int i = 0; i < N; ++i)
			{
				int a = stdIn.nextInt();
				list.add(a);
			}
			int count = 0;
			int pos = 0;
			while(true)
			{
				if(list.get(pos) == X)
				{
					++pos;
				}
				if(count >= 10001)
				{
					System.out.println(-1);
					break;
				}
				if(pos >= N)
				{
					System.out.println(count);
					break;
				}
				X = (A * X + B) % C;
				++count;
			}
		}
	}
}

Measured memory_bytes: 34160
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int fc(int n){
  string s = to_string(n);
  int ret = 0;
  rep(i, s.size()){
    ret += s.at(i) - '0';
  }
  return ret;
}

int main(){
  int n;
  cin >> n;
  int f = fc(n);
  if(n % f == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>

using namespace std;

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

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1 , number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1 , number1);
    }
}

ll i,j,k,ii,jj,n,m,a,b,c,d,e,g,h,r,w,l;
ll num,ans;
ll x[500005],y[500005],z[500005];
bool dame,flag;
bool dp[5000][5000];
ll ok,ng;
string s,t;


int main(){
	cin >> n >> m;
	for(i=0;i<n;i++){
		cin >> x[i];
	}
	for(i=0;i<m;i++){
		cin >> y[i];
	}
	sort(x,x+n);
	sort(y,y+m);
	if(x[n-1] != n*m || y[m-1] != n*m){
		p(0);
		return 0;
	}
	dp[n-1][m-1] = true;
	a = n-2;
	b = m-2;
	c = 1;
	d = 1;
	ans = 1;
	num = 1;
	for(i=n*m-1;i>=1;i--){
		//iの場所を探す
		if(x[a] == i && y[b] == i){
			//ここしかない
			num ++;
			a--;
			b--;
			c++;
			d++;
		}else if(x[a] == i){
			ans *= d;
			ans %= mod;
			num++;
			a--;
			c++;
		}else if(y[b] == i){
			ans *= c;
			ans %= mod;
			num++;
			b--;
			d++;
		}else{
			ans *= (c * d - num);
			ans %= mod;
			num++;
		}
		if(a < 0)a = 0;
		if(b < 0)b = 0;
		if(c > n)c = n;
		if(d > m)d = m;
		//pe(i);p(ans);
	}
	p(ans);
		


	return 0;
}


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

int main(void) {
	int n;
	cin >> n;
	int odd = 0;
	int a;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a % 2 == 1) {
			odd++;
		}
	}
	(odd % 2 == 0)? puts("YES"): puts("NO");
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner input = new Scanner (System.in);
        int N  = input.nextInt();
        int M  = input.nextInt();
       
            if (N == M){
                System.out.println("Yes");
            }
            else{
                System.out.println("No");
            }
        
    }
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long

using namespace std;

const int MOD = 1000000007;

int dp[100000][3];

int points[3];

ll n, k;
ll r, s, p;

ll calc(vector<int> h) {
  if (h.size() == 0) {
    return 0;
  }

  dp[0][0] = 0;
  dp[0][1] = 0;
  dp[0][2] = 0;
  switch (h[0]) {
    case 0:  // グー
      dp[0][2] = p;
      break;
    case 1:  // チョキ
      dp[0][0] = r;
      break;
    case 2:  // パー
      dp[0][1] = s;
      break;
  }

  for (ll i = 1; i < h.size(); i++) {
    for (ll this_choice = 0; this_choice <= 2; this_choice++) {
      int pre_max = 0;

      for (ll j = 0; j <= 2; j++) {
        if (j == this_choice) {
          continue;
        }
        pre_max = max(pre_max, dp[i - 1][j]);
      }

      int this_point = 0;
      if (h[i] == 0 && this_choice == 2) {
        this_point = points[this_choice];
      }
      if (h[i] == 1 && this_choice == 0) {
        this_point = points[this_choice];
      }
      if (h[i] == 2 && this_choice == 1) {
        this_point = points[this_choice];
      }
      dp[i][this_choice] = this_point + pre_max;
    }
  }

  int ans = 0;
  for (ll i = 0; i < 3; i++) {
    // cout << dp[h.size() - 1][i] << endl;
    ans = max(ans, dp[h.size() - 1][i]);
  }
  return ans;
}

int main() {
  scanf("%lld %lld", &n, &k);

  scanf("%lld %lld %lld", &r, &s, &p);

  points[0] = r;
  points[1] = s;
  points[2] = p;

  string str;
  cin >> str;

  ll ans = 0;

  for (ll i = 0; i < k; i++) {
    vector<int> vec;
    for (ll j = str.size() - 1 - i; j >= 0; j -= k) {
      int id;
      if (str[j] == 'r') {
        id = 0;
      } else if (str[j] == 's') {
        id = 1;
      } else if (str[j] == 'p') {
        id = 2;
      }
      vec.emplace_back(id);
    }

    vector<int> vec2;
    for (ll k = vec.size() - 1; k >= 0; k--) {
      vec2.emplace_back(vec[k]);
    }
    ll v = calc(vec2);
    ans += v;
  }

  cout << ans << endl;
}


Measured memory_bytes: 2872
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")


S, T = [sys.stdin.readline().rstrip() for _ in range(2)]
S = list(S)
T = list(T)
S.sort()
T.sort(reverse=True)
if S < T:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 13624
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int n,i; cin >> n >> i;
    cout << n-i+1 << endl;
}


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

namespace AthleteProgramming
{
    class Program
    {
        static void Main()
        {
            string str;
            int[] ab;

            while (true)
            {
                str = Console.ReadLine();
                if (str == null)
                {
                    break;
                }
                ab = str.Split(' ').Select(int.Parse).ToArray();
                int a = ab[0];
                int b = ab[1];
                if (a < b)
                {
                    int tmp = b;
                    b = a;
                    a = tmp;
                }
                int r = a % b;
                while (r!=0)
                {
                    a = b;
                    b = r;
                    r = a % b;
                }
                Console.WriteLine("{0} {1}",b,(ab[0]/b)*(ab[1]/b)*b);
                    
            }
        }

       
    }
}

Measured memory_bytes: 9544
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program {
	static void Main(string[] args) {
		new Calc().Solve();
	}
	public class Calc {
		private Utils.Scan cin = new Utils.Scan();
		public Calc() { }
		public void Solve() {
			var ABC = cin.ReadInt(' ');
			for (int i = 0; i < ABC[1]; i++) {
				if (i * ABC[0] % ABC[1] == ABC[2]) { Console.WriteLine("YES");return; }
			}
			Console.WriteLine("NO");
			return;
		}
	}
}
public static class Utils {
	public class Scan {
		public Scan() { }
		public int ReadInt() => Console.ReadLine().IntParse();
		public int[] ReadInt(char separator) => Console.ReadLine().Split(separator).Select(int.Parse).ToArray();
		public double ReadDouble() => double.Parse(Console.ReadLine());
		public double[] ReadDouble(char separator) => Console.ReadLine().Split(separator).Select(double.Parse).ToArray();
		public long ReadLong() => long.Parse(Console.ReadLine());
		public long[] ReadLong(char separator) => Console.ReadLine().Split(separator).Select(long.Parse).ToArray();
	}
	public static string Docking<T>(this IEnumerable<T> list, Func<T, string> filter = null) {
		StringBuilder sb = new StringBuilder();
		foreach (var item in list) {
			sb.Append(filter == null ? item.ToString() : filter(item));
		}
		return sb.ToString();
	}
	public static int IntParse(this string s) => int.Parse(s);
}

Measured memory_bytes: 13268