akhauriyash/Code-Regression huggingface dataset:
import sys,heapq,math,resource
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def setrlim():
  sys.setrecursionlimit(250000)
  soft,hard = resource.getrlimit(RLIMIT_STACK)
  # setrlimit works on ubuntu (and atcoder), but not on WSL
  #resource.setrlimit(RLIMIT_STACK, (128*1024*1024,hard))

def prime_division(x):
    q = int(math.sqrt(x))
    a = []
    for i in range(2,q+1):
        ex = 0
        while x%i == 0:
            ex += 1
            x //= i
        if ex>0:
            a.append([i,ex])
    if x>q:
        a.append([x,1])
    return a

def foo(x):
    b = []
    for y in a:
        if y%x != 0:
            b.append(y%x)
    b.sort()
    m = k
    while m>0 and len(b)>0:
        if b[0] < x-b[-1] or (len(b)==1 and b[0]<=x//2):
            if m<b[0]:
                return False
            m -= b[0]
            b[-1] += b[0]
            b = b[1:]
            #p = len(b)-1
            #while p>0 and b[p-1]>b[p]:
            #    b[p-1],b[p] = b[p],b[p-1]
        else:
            d = x-b[-1]
            if m<d:
                return False
            m -= d
            b[0] -= d
            b.pop()
            if b[0]==0:
                b = b[1:]
            #p = 0
            #while p<len(b)-1 and b[p]>b[p+1]:
            #    b[p],b[p+1] = b[p+1],b[p]
    return (len(b)==0)

n,k = inm()
a = inl()
sm = sum(a)
f = prime_division(sm)

facs = [1]
for z in f:
    b = z[0]
    e = z[1]
    newfacs = []
    for x in facs:
        for i in range(e+1):
            newfacs.append(x*(b**i))
    facs = newfacs

facs.sort(reverse=True)
for x in facs:
    if foo(x):
        print(x)
        exit()
print(1)


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

int main() {
    int n;
    string s;
    cin >> n >> s;
    if (n%2 == 1) {
        cout << "No" << endl;
        return 0;
    }

    bool f = true;
    rep(i, n/2) {
        if (s[i] != s[n/2+i]) f = false;
    }

    cout << (f ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
function Main(input) {
    input = input.split("\n")
    input = input[0].split('')    
    
    var count = 0

    for(var i=1;i<=input;i++){
        for(var j=1;j<=input;j++){
            for(var k=1;k<=input;k++){
                count++
            }
        }
    }
    console.log("%d",count)

}


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）

Main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 25160
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n; cin >> n;
    vector<int> h(n);
    bool ok = true;
    rep(i,n) {
        cin >> h[i];
        if (i == 0) continue;
        if (h[i-1] <= h[i]-1) h[i]--;
        if (h[i-1] > h[i]) {
            ok = false;
            break;
        }
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3964
s = [list(input()) for _ in range(3)]

n_row = 0

dic = {0:"A",1:"B",2:"C"}

while True:
    if len(s[n_row]) == 0:
        break

    s_num = s[n_row].pop(0)
    
    if s_num == "a":
        n_row = 0
    elif s_num == "b":
        n_row = 1
    elif s_num =="c":
        n_row = 2

print(dic[n_row])

Measured memory_bytes: 9068
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());

    int prev = Integer.parseInt(sc.next());
    ;
    int ans = 0;
    int colorMax = 10000;
    for (int i = 1; i < N; i++) {
      int a = Integer.parseInt(sc.next());
      if (a == prev) {
        ans++;
        prev = colorMax;
        colorMax--;
      } else {
        prev = a;
      }
    }

    System.out.println(ans);
  }
}

Measured memory_bytes: 21204
import copy
import sys
import math

def main():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    B = [0] * n

    # k_max = 1 + math.ceil(math.log10(n))

    for i in range(min(k, 41)):
        for j in range(n):
            l = max(0, j-A[j]) #座標iの電球が照らす範囲の左端
            r = min(n-1, j+A[j]) #座標iの電球が照らす範囲の右端
            B[l] += 1
            if (r+1 < n):
                B[r+1] -= 1 # 後ほど累積和にしたときに、照らす範囲の右端より外には影響が及ばないようにあらかじめ1引いておく

        for j in range(n-1):
            B[j+1] += B[j]

        A = copy.deepcopy(B)
        B = [0] * n

    print(*A)

if __name__ == '__main__':
    main()

Measured memory_bytes: 179396
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
long long fact[210000];
long long finv[210000];
long long inv[210000];
long long C(int a,int b){
	if(b<0||a<b)return 0;
	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
long long pw(long long a,long long b){
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int main(){
	int n,a,b,c;
	scanf("%d%d%d%d",&n,&a,&b,&c);
	long long ret=0;
	fact[0]=inv[1]=finv[0]=1;
	for(int i=2;i<210000;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i])%mod;
	}
	for(int i=1;i<210000;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
	for(int i=n;i<2*n;i++){
		long long ks=C(i-1,n-1);
		ks=ks*(pw(a*inv[a+b]%mod,n)*pw(b*inv[a+b]%mod,i-n)%mod+pw(a*inv[a+b]%mod,i-n)*pw(b*inv[a+b]%mod,n)%mod)%mod;
		ks=ks*i%mod;
		ret=(ret+ks*100%mod*inv[a+b])%mod;
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 5120
abc = list(map(int, input().split()))
if abc[0] > abc[1]:
    abc[0], abc[1] = abc[1], abc[0]
if abc[1] > abc[2]:
    abc[1], abc[2] = abc[2], abc[1]
if abc[0] > abc[1]:
    abc[0], abc[1] = abc[1], abc[0]
    
print(f"{abc[0]} {abc[1]} {abc[2]}")


Measured memory_bytes: 5612
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[10][10],w=0;
	int b,c,d;
	cin>>b>>c>>d;
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
		{
			a[1][1]=b;
			a[1][2]=c;
			a[2][2]=d;
			w=a[2][2]*3;
			a[1][3]=w-a[1][1]-a[1][2];
			a[3][3]=w-a[1][1]-a[2][2];
			a[2][3]=w-a[1][3]-a[3][3];
			a[2][1]=w-a[2][3]-a[2][2];
			a[3][1]=w-a[1][1]-a[2][1];
			a[3][2]=w-a[3][1]-a[3][3];
		}
	}
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
		{
			if(j!=3)
			cout<<a[i][j]<<" ";
			else
			cout<<a[i][j]<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
      	int result = 0;
      	for(int i=1;i<=num;i++){
          for(int j=1;j<=num;j++){
           // int tmp = gc.gcd(i,j);
            int tmp = gcd(i,j);
            for(int k=1;k<=num;k++){
         		//最初の2数の最大公約数を取得
              	result += gcd(tmp,k);
            }
          }
        }
      System.out.println(result);
    }
	static int gcd(int a,int b){
  		int tmp = 0;
  		int amari=-1;
  		if(a>=b){
    		tmp = a;
    		a = b;
  		}else{
    		tmp = b;
  		}

 		 while(amari != 0){
    		amari = a%tmp;
           	a = tmp;
           	tmp = amari;
  		 }
  		return a;
	}
}

Measured memory_bytes: 35888
from itertools import accumulate
from bisect import bisect

N = int(input())
C = [0]+list(accumulate(map(int,input().split())))
S = C[N]

def it():
  k1 = 1
  k2 = 3
  for i in range(2,N-1):
    ci = C[i]
    k1 = bisect(C, ci//2, lo=k1,hi=i)
    _,a,b = min((abs(ci-2*c),ci-c,c) for c in (C[k1-1],C[k1]))
    k2 = bisect(C, (S+ci)//2, lo=k2,hi=N)
    _,c,d = min((abs(ci+S-2*c),S-c,c-ci) for c in (C[k2-1],C[k2]))
    yield max(a,b,c,d)-min(a,b,c,d)

print(min(it()))

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


using namespace std;
double pi=3.14159265358979323846264338;
long long sum;

int main(){
	string a,b;
	cin>>a>>b;
	int lnth,lnth2;
	int ans=1000000000;
	lnth=a.length();
	lnth2=b.length();
	for(int i=0;i<=lnth-lnth2;i++){
		int num=0;
		for(int j=0;j<lnth2;j++){
			if(a[i+j]!=b[j])num++;
		}
		ans=min(ans,num);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<stdlib.h>
int main()
{
  int a,m,c,a1,a2,a3;
  scanf("%d%d%d",&a,&m,&c);
  a1=a/c;
  a2=m/c;
  if(a%c==0)
    a3=a2-a1+1;
  else
    a3=a2-a1;
  printf("%d",a3);
  
}

Measured memory_bytes: 1696
#include<bits/stdc++.h>
using namespace std;
bool kai(string S, int f, int l) {
  for (int i = f; i < l; i ++) {
    int j = l + f - i - 1;
    if (S[i] != S[j]) return false;
  }
  return true;
}
int main () {
  string S;
  cin >> S;
  int N = S.size();
  int ha = N / 2;
  if(kai(S, 0, N) && kai(S, 0, ha) && kai(S, ha + 1, N)) {
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

Measured memory_bytes: 256
/**
 *   created: 24 November 2019  09:33:01
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define int long long
#define PB push_back
#define PPB pop_back
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================

int32_t main()
{
	optimizeIO();
	int tt=1;
	//cin>>tt;
	while(tt--){
		int n;
		cin>>n;
		string s;
		cin>>s;
		vector<char> v(52);
		rep(i,0,26){
			// trace1()
			v[i] = 'A'+i;
		}
		rep(i,26,52){
			v[i] = 'A'+(i-26);
			// trace1(v[i]);
		}
		rep(i,0,s.size()){
			int ind = s[i]-'A';
			s[i] = v[ind+n];
		}
		cout<<s;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int MAXW = 51;
const int MAXH = 51;
int map[MAXW][MAXH];
int w,h;
int dx[] = {-1,0,1,-1,1,-1,0,1};
int dy[] = {1,1,1,0,0,-1,-1,-1};
int dfs(int x,int y){
  if(map[x][y] == 0)return 0;
  map[x][y] = 0;
  for(int i = 0;i < 9;i++){
    int nx = x+dx[i];
    int ny = y+dy[i];
    if(nx >= 0 && nx < w & ny >= 0 && ny < h)
      dfs(nx,ny);
  }
  return 1;
}

int main(){
  while(true){
    cin >> w >> h;
    if(w == 0 && h == 0)break;
    for(int i = 0;i < h;i++){
      for(int j = 0;j < w;j++){
        cin >> map[j][i];
      }
    }
    int count = 0;
    for(int i = 0;i < h;i++){
      for(int j = 0;j < w;j++){
        count += dfs(j,i);
      }
    }
    cout << count << endl;
  }
}

Measured memory_bytes: 1240
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int N;
double A[55];
int main(){
	scanf("%d",&N);
	for(int i=1;i<=N;i++)	scanf("%lf",&A[i]);
	sort(A+1,A+N+1);
	for(int i=1;i<N;i++)	A[i+1]=(A[i]+A[i+1])/2;
	printf("%lf",A[N]);
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>

bool board[14][14];

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

void DFS(int x,int y){
    board[x][y]=false;
    for(int i=0;i<4;i++){
        auto nx=x+dx[i],ny=y+dy[i];
        if (!board[nx][ny]) continue;
        DFS(nx,ny);
    }
}

int main(){

    while(true){
        for(int i=1;i<=12;i++){
            for(int j=1;j<=12;j++){
                auto sign=getchar();
                board[i][j]=(sign=='1');
            }
            getchar();
        }

        int ans=0;
        for(int i=1;i<=12;i++){
            for(int j=1;j<=12;j++){
                if (!board[i][j]) continue;
                DFS(i,j);
                ans++;
            }
        }

        printf("%d\n",ans);

        if (getchar()==EOF)
            break;
    }


    return 0;
}


Measured memory_bytes: 2608
#include <cstdio>
int main() {
    int n = 0, t = 0, tot = 0, maxLen = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &t);
        if (t > maxLen)
            maxLen = t;
        tot += t;
    }
    printf((maxLen * 2 < tot) ? "Yes" : "No");
    return 0;
}

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

s=[0]*(n+1)
for i in range(n):
  s[i+1] = s[i] + a[i]

result = 10**10
for i in range(1,n):
  snuke = s[i]
  arai = s[n] - s[i]
  result = min(result, abs(snuke-arai))
print(result)

Measured memory_bytes: 30664
import sys
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    n, k = map(int, input().split())

    ans = 0
    i = 0
    while True:
        if k**i > n:
            print(i)
            return
        else:
            i += 1
     
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 5304
program main
  implicit none
  
  integer :: n,k,i,s = 1
  read(*,*)n
  read(*,*)k
  do i = 1, n
    if (s <= k) then
      s = 2*s
    else
      s = s + k
    end if
  end do
  
  write(*,*)s
end program main

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

using namespace std;

int a,b,c,sum;

int main()
{
	scanf("%d%d%d",&a,&b,&c);
	sum=a+b+c;
	if(sum>=22) {
		printf("bust");
	}
	else {
		printf("win");
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
char s[10];
int n;
int a,w,t,r;
int main(){
    cin>>n;
    while (n--){
        cin>>s;
        if (s[0]=='A') ++a;
        if (s[0]=='W') ++w;
        if (s[0]=='T') ++t;
        if (s[0]=='R') ++r;
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<w<<endl;
    cout<<"TLE x "<<t<<endl;
    cout<<"RE x "<<r<<endl;
    return 0;
}

Measured memory_bytes: 3644
A,B,C,K=map(int,input().split())
import numpy as np
X = np.array([A,B,C])
Y = np.array([1,-1,0])
M = np.matrix('0 1 1; 1 0 1; 1 1 0')

def pow_V(Z,n):
  bin_n = format(n, 'b')
  ans = np.matrix('1 0 0; 0 1 0; 0 0 1')
  for i in range(0,len(bin_n)):
    if i == 0:
      XX = Z
    else:
      XX = XX * XX
    if bin_n[-(i+1)]=='1':
      ans = ans * XX
  return ans
MK = pow_V(M,K)
R = np.inner(Y, (X * MK))[0,0]
print(R)

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

using namespace std;

int main(){
  const int N_max = 100;
  int N;
  int a[N_max];
  cin >> N;
  for(int i = 0; i<N ; ++i){
    cin >> a[i];
  }

  
  //for
  int num_swaps = 0;

  for(int i = 0; i<N; ++i){
    int* min_ptr = min_element(a+i, a+N);
    if(min_ptr != a+i){
      swap(a[i], *min_ptr);
      ++num_swaps;
    }
  }
  
  //output
  for(int i = 0; i<N ; ++i){
    cout << ( i==0 ? "" : " ") << a[i];
  }
  cout << endl;
  cout << num_swaps <<endl;
  return 0;

  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x <<": "<<x<<"\n"
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template <class T> using vec = std::vector<T>;
template <class T = int> T in(){T x; cin>>x;return(x);}
template <class T > void print(T& x){cout<<x<<"\n";}
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s,t;
  cin>>s>>t;
  vec<vec<int>> dict(26,vec<int>());
  REP(i,(int)(s.size())){
      int index = s[i]-'a';
      dict[index].pb(i);
  }
  //-1判定
  bool flg = true;
  REP(i, (int)(t.size())) { 
    int index = t[i] - 'a';
    if (dict[index].size()==0){
        flg = false;
        break;
    }
   }
   if (!flg){
       cout <<"-1"<<"\n";
   }else{
       int slen = (int)(s.size());
       int counter=0;
       int currentind=-1;
       REP(i,(int)(t.size())){
         int index = t[i] - 'a';
        auto ans =upper_bound(ALL(dict[index]),currentind);
         if (ans==dict[index].end()) {
           counter++;
           currentind=dict[index][0];
         }else{
             currentind =*ans;
         }
        // DEBUG(currentind);
         //cout <<dict[0][0]<<endl;
       }
       cout <<1ll+slen*counter+currentind<<"\n";
   }
}

Measured memory_bytes: 1736
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define all(x) (x).begin(), (x).end()

int size = 1;
long MAX = (1l << 31) - 1;
vector<long> segtree, lazy;

void eval(int l, int r, int now){
    if(lazy[now] != -1){
        if(r - l > 1){
            lazy[now * 2 + 1] = lazy[now];
            lazy[now * 2 + 2] = lazy[now];
        }
        segtree[now] = lazy[now];
        lazy[now] = -1;
    }
}

void change(int a, int b, long x, int l, int r, int now){
    eval(l, r, now);
    if(r <= a || b <= l){
        return;
    }else if(a <= l && r <= b){
        lazy[now] = x;
        eval(l, r, now);
    }else{
        change(a, b, x, l, (l + r) / 2, now * 2 + 1);
        change(a, b, x, (l + r) / 2, r, now * 2 + 2);
        segtree[now] = min(segtree[now * 2 + 1], segtree[now * 2 + 2]);
    }
}

long minimum(int a, int b, int l, int r, int now){
    eval(l, r, now);
    if(r <= a || b <= l){
        return MAX;
    }else if(a <= l && r <= b){
        return segtree[now];
    }else{
        return min(minimum(a, b, l, (l + r) / 2, now * 2 + 1), minimum(a, b, (l + r) / 2, r, now * 2 + 2));
    }
}

int main(){
    int n, q;
    cin >> n >> q;
    while(size < n){
        size *= 2;
    }
    segtree.resize(size * 2 - 1, MAX);
    lazy.resize(size * 2 - 1, -1);
    for(int i = 0; i < q; i++){
        int com;
        cin >> com;
        if(com){
            int s, t;
            cin >> s >> t;
            cout << minimum(s, t + 1, 0, size, 0) << endl;
        }else{
            int s, t;
            long x;
            cin >> s >> t >> x;
            change(s, t + 1, x, 0, size, 0);
        }
    }
}



Measured memory_bytes: 7056
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int N,A,B;
    cin>>N>>A>>B;
    int q1=0,q2=0,q3=0;
    for(int i=0;i<N;i++){
        int P;cin>>P;
        if(P<=A){
            q1++;
        }else if(P<=B){
            q2++;
        }else{
            q3++;
        }
    }
    cout<<min(min(q1,q2),q3)<<endl;
}


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

signed main(){
  int A;
  cin>>A;
  cout<<A+pow(A,2)+pow(A,3)<<endl;
  return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define FR first
#define SE second

using namespace std;

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

namespace SETS {

int fa[100005],size[100005];

void init(int n) {
  for(int i=1;i<=n;i++) {
  	fa[i]=i;
  	size[i]=1;
  }
}

int find_father(int x) {
  return (fa[x]==x)?x:fa[x]=find_father(fa[x]);
}

void merge(int x,int y) {
  x=find_father(x);y=find_father(y);
  if (x==y) return;
  fa[x]=y;
  size[y]+=size[x];
}

}

pr e[100005];

int main() {
  int n,k;
  ll m;
  scanf("%d%d%d",&n,&m,&k);
  SETS::init(n);
  int cnt=0;
  for(int i=1;i<=k;i++) {
  	int x,y,z;
  	scanf("%d%d%d",&x,&y,&z);
  	x++;y++;
  	if (!z) SETS::merge(x,y);
  	else e[++cnt]=pr(x,y);
  }
  for(int i=1;i<=cnt;i++)
    if (SETS::find_father(e[i].FR)==SETS::find_father(e[i].SE)) {
    	puts("No");
    	return 0;
	}
  int s=n;
  for(int i=1;i<=n;i++)
    if (SETS::find_father(i)==i) s-=SETS::size[i]-1;
  if ((s<=2||m==n-1)&&cnt) {
  	puts("No");
  	return 0;
  }
  puts((((ll)s*(s-1)>>1)+n-s>=m)?"Yes":"No");
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using  unll = unsigned long long;

int main() {
  unll n;
  cin >> n;
  
  if( n <= 1000000 ){
    for(unll i=1;i<=n+1;i++){ 
      if( i*i > n ){
        cout << (i-1)*(i-1) << endl;
        return 0;
      }
    }
  }else{
    for(unll i=1001;i<n;i++){
      if( i*i > n ){
        cout << (i-1)*(i-1) << endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}
ll gcd(ll(a), ll(b)) {
	ll c = a;
	while (a % b != 0) {
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}



int main() {

	ll N, A , B,an=0,c;
	cin >> N >> A >> B;

	rep(i, N) {
		c = i + 1;
		ll k = 0;
			rep(j, 6) {
				k += c % 10;
				c /= 10;
			}
			if (A <= k && k <= B) {
				an+=i+1;
		}
	}
	cout << an << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a,b,c,d;
    int answer1, answer2;

    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    scanf("%d", &d);

    if(a > b) {
        answer1 = b;
    }
    else if(a < b) {
        answer1 = a;
    }

    if(c > d) {
        answer2 = d;
    }
    else if(c < d) {
        answer2 = c;
    }

    printf("%d\n" ,answer1 + answer2);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,x;cin >> n >> x;
	ll g=gcd(n,x);
	cout << 3*(n-g) << endl;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=1000000007;

int power[1000];

int N;
int sum[5],cnt[5];

int table[205][1005];
int table2[205][205];
int C[500][500];
int F[500];

int calc(){
    memset(table,0,sizeof(table));
    table[0][0]=1;
    for(int i=1;i<5;i++){
        for(int j=0;j<cnt[i];j++){
            for(int k=N;k>=0;k--){
                for(int l=0;l<N*4;l++){
                    table[k+1][l+i]=(table[k+1][l+i]+table[k][l])%mod;
                }
            }
        }
    }

    int ret=0;
    for(int z=0;z<=cnt[0];z++){
        for(int c=0;c<N-cnt[0];c++){
            for(int s=0;s<N*4;s++){
                int t=table[c][s]*C[cnt[0]][z]%mod;
                t=t*F[c+z]%mod;
                int lc=N-cnt[0]-1-c;
                int lz=cnt[0]-z;
                t=t*table2[lc][lz]%mod;
                ret=(ret+t*power[s+z])%mod;
            }
        }
    }

    return ret;
}

signed main(){
    power[0]=1;
    for(int i=1;i<1000;i++)power[i]=power[i-1]*10%mod;
    C[0][0]=1;
    for(int i=1;i<500;i++){
        C[i][0]=C[i][i]=1;
        for(int j=1;j<i;j++)C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;
    }
    F[0]=1;
    for(int i=1;i<500;i++)F[i]=F[i-1]*i%mod;

    for(int i=0;i<=200;i++){
        for(int j=0;j<=200;j++){
            table2[i][j]=1;
            if(i){
                int s=i+j-1;
                for(int k=0;k<=s;k++){
                    int t=C[s][k]*F[k]%mod;
                    t=t*i%mod;
                    table2[i][j]=(table2[i][j]+t)%mod;
                }
            }
        }
    }

    cin>>N;
    rep(i,N){
        int a;
        cin>>a;
        if(a==0){
            cnt[0]++;
        }
        else{
            stringstream ss;
            ss<<a;
            int d=ss.str().size();
            sum[d]+=a;
            cnt[d]++;
        }
    }

    int ans=0;
    for(int i=1;i<5;i++){
        if(cnt[i]==0)continue;
        cnt[i]--;
        int tmp=calc();
        cnt[i]++;
        ans=(ans+tmp*sum[i])%mod;
    }

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

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd


int solve(int a)
{
    int cnt = 0;
    while (a) {
        cnt++;
        a /= 10;
    }
    return cnt % 2;
}

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

    Int(n);
    int ans = 0;

    Rep(i, n+1) {
        ans += solve(i);
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<random>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#define endl "\n"
#define fi first
#define se second
#define db double
#define gcd __gcd
#define pb push_back
#define mp make_pair
#define lowbit(x) (x & (-x))
#define PII  pair<int, int> 
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << endl
#define rep(i, a, b) for(__typeof(b) i = a; i <= (b); i++)
#define Rep(i, a, b) for(__typeof(a) i = a; i >= (b); i--)
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
template<class T> inline T qmin(T a, T b) { return a < b ? a : b; }
template<class T> inline T qmax(T a, T b) { return a > b ? a : b; }
typedef long long ll;
typedef unsigned long long ull;
const db eps = 1e-9;
const db PI = acos(-1);
const int inf = 0x3f3f3f3f;
const int mod = (int)1e9 + 7;
const int maxn = (int)1e5 + 5;//remember to modify it, No RE or MLE
const ll INF = 0x3f3f3f3f3f3f3f3f;
using namespace std;
ll qpow(ll x, ll y) { ll ret = 1; for( ; y; y >>= 1, x = (x * x) % mod) if(y & 1) ret = (ret * x) % mod; return ret; }

inline int read(){
	char ch = getchar();
	int x = 0, f = 1;
	while(ch < '0' || ch > '9'){
		if(ch == '-') f = -1;
		ch = getchar();
	}
	while('0' <= ch && ch <= '9'){
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}

int n, W;
int w[105], v[105];
ll dp[maxn];

int main()
{
	n = read(), W = read();
	rep(i, 1, n) w[i] = read(), v[i] = read();
	memset(dp, 0x3f, sizeof dp);
	dp[0] = 0;
	rep(i, 1, n){
		Rep(j, maxn - 1, v[i]){
			dp[j] = qmin(dp[j], dp[j-v[i]] + w[i]);
		}
	}
	Rep(i, maxn - 1, 0){
		if(dp[i] <= W) return 0 * printf("%d\n", i);
	}
	return 0;
}

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

int main(){
    int n, ans = 1;
    cin >> n;
    vector<int> d(n);

    for(int i = 0; i < n; ++i){
        cin >> d.at(i);
    }
    sort(d.begin(),d.end());
    reverse(d.begin(),d.end());
    for(int i = 0; i < n; ++i){
        if(i>0 && d.at(i-1) != d.at(i))
            ans++;
    }
    cout << ans << endl;
}


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

"""
・ダイクストラ(優先度付きキュー)
"""

from heapq import heappop, heappush

# 今回はダイクストラするので、データの持ち方は隣接リスト
N = int(input())
nodes = [[] for _ in range(N+1)]
for i in range(N-1):
    a, b, c = map(int, input().split())
    # nodes[出発ノード](到着ノード, コスト))
    nodes[a].append((b, c))
    nodes[b].append((a, c))

def dijkstra(nodes, start):
    # 最短距離メモ
    memo = [float('inf')] * (len(nodes))
    # 訪問済メモ
    visited = [False] * (len(nodes))
    # スタート位置
    que = [(0, start)]
    memo[start] = 0
    # キューが空になるまで
    while len(que) != 0:
        # startからの距離, 現在のノード
        dist, cur = heappop(que)
        # 訪問済にする
        visited[cur] = True
        # 出発ノードcurの到着ノードでループ
        for i in range(len(nodes[cur])):
            nxt, cost = nodes[cur][i]
            # 訪問済ではない時だけ
            if not visited[nxt]:
                memo[nxt] = min(memo[cur] + cost, memo[nxt])
                # 現在の移動距離をキューの優先度として、早い方から先に処理するようにする
                heappush(que, (memo[nxt], nxt))
    # ノードstartからの最短距離リストを返却
    return memo

Q, K = map(int, input().split())
# 引数：(ノードの隣接リスト, 出発ノード)
memo = dijkstra(nodes, K)

for i in range(Q):
    x, y = map(int, input().split())
    print(memo[x] + memo[y])


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

int main() {
  
  int n;
  cin>>n;
  vector<int> h(n);
  rep(i,n) cin>>h[i];
  ///////////
  int mx=0;
  
  rep(i,n-1){
    int cnt=0;
  			while(i<n-1&&h[i]>=h[i+1]){
  			  cnt++;
              i++;
 			 }
    
   // cout<<cnt<<endl;
    mx=max(mx,cnt);
  }
  cout<<mx<<endl;
}

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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            var X = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var a = X[0];
            var b = X[1];
            var c = X[2];
            var d = (0);
            while (true)
            {
                if (a == b+1)
                    break;
                var x = c % a;
                if (x == 0)
                {
                    d = d + 1;
                }
                a = a + 1;
            }
            Console.WriteLine(d);
        }
    }
}

Measured memory_bytes: 9564
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

H, W, K = LI()
c = [[0 for j in range(W)] for i in range(H)]

for h in range(H):
    c[h] = list(str(input()))

# print(c)
for h in range(H):
    for w in range(W):
        if c[h][w] == ".":
            c[h][w] = 0
        else:
            c[h][w] = 1 


"""
2 ** (H + W)通り試せば良い
"""
ans = 0
# 10進数のnを2進数のリストに変換


def n2kdigit(n,k):
    digits = [0 for i in range(H + W)]
    tmp = 0
    while n > 0:
        digits[tmp] = n % k
        n = n // k
        tmp += 1

    return digits

for i in range(2 ** (H + W)):
    cnt = 0
    c_ = copy.deepcopy(c)
    digits = n2kdigit(i, k = 2)
    for j, digit in enumerate(digits):
        if digit == 1:
            if j >= H:
                for h in range(H):
                    # print(j - H -1)
                    c_[h][j - H - 1] = 0
            else:
                "Hを示す"
                c_[j] = [0 for k in range(W)]
    # print(c_)
    for h in range(H):
        cnt += sum(c_[h])
    if cnt == K:
        ans += 1

print(ans)




Measured memory_bytes: 10928
#include <stdio.h>

int main()
{
	char c1[4];
	char c2[4];
	
	scanf("%s",c1);
	scanf("%s",c2);
	
	if(c1[0]==c2[2]&&c1[1]==c2[1]&&c1[2]==c2[0])
	{
		printf("YES\n");
	}
	else
	{
		printf("NO\n");
	}
	return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;

int main(){
	int n, k, c[10], i;
	for(; cin >> n >> k, n; ){
		for( i = n; i--; )
			cin >> c[i];
		sort( c, c + n );
		set<int> s;
		do{
			int t = 0;
			for( i = k; i--; )
				t = t * ( c[i] > 9 ? 100 : 10 ) + c[i];
			s.insert(t);
		} while( next_permutation( c, c + n ) );
		cout << s.size() << endl;
	}
}

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

int main() {
  char N;
  long long X=0;
  long long M;
  string Y;
  cin >> Y;
  for (long long i=0;i<size(Y);i++) {
    N=Y.at(i);
    M=N-'0';
    X+=M;
    X=X%9;
  }
  if (X%9==0) {
    cout << "Yes" << endl;
  }
  if (X%9!=0) {
    cout << "No" << endl;
  }
}

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

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

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
int main() {
	int a,b,c,d;
	cin>>a>>b>>c>>d;

	if(abs(a-b)<=d&&abs(b-c)<=d||abs(a-c)<=d){
		printf("Yes");
	}
	else{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
#define INF 2000'000'000
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef tree<int, null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int grid[3000][3000];
ll dp[3000][3000][3];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	//freopen("in", "r", stdin);//freopen("out", "w", stdout);
	ll r, c, cnt;
	cin >> r >> c >> cnt;
	for(int i,j,v; cnt-- && cin >> i >> j >> v; ){
		grid[i-1][j-1] = v;
	}
	constexpr int mx = 3000-1;
	for(int i = mx; i >= 0; i--){
		for(int j = mx; j >= 0; j--){
			for(int k = 2; k >= 0; k--){
				ll cur = grid[i][j];
				if(i != mx)
					cur = max(cur, dp[i+1][j][0] + grid[i][j]);
				if(j != mx){
					cur = max(cur, dp[i][j+1][k]);
					if(k != 2){
						cur = max(cur, dp[i][j+1][k+1] + grid[i][j]);
					}
				}
				dp[i][j][k] = cur;
			}
		}
	}
		
	cout << dp[0][0][0] << endl;
	
	return 0;
}


Measured memory_bytes: 249608
import java.io.PrintWriter
import java.util.*

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (A, B) = nextLongList()
    val ans = primefact(gcd(A, B)).keys.size + 1
    println(ans)
}

tailrec fun gcd(a: Long, b: Long): Long {
    if (a < b) return gcd(b, a)
    if (b == 0L) return a
    if (a <= 0L) throw IllegalArgumentException()
    return gcd(b, a % b)
}

fun primefact(n: Long): HashMap<Long, Int> {
    val map = HashMap<Long, Int>()
    var tmp = n
    for (i in 2L..(Math.sqrt(n.toDouble()).toLong() + 1)) {
        if (tmp % i == 0L) {
            var cnt = 0
            while (tmp % i == 0L) {
                tmp /= i
                cnt++
            }
            map[i] = cnt
        }
    }
    if (tmp != 1L) {
        map[tmp] = 1
    }
    return map
}

Measured memory_bytes: 37916
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int solve(vector<vector<int> > a, int r, int c,bool rc[]){
	for(int i=0;i<r;++i){
		if(rc[i]==true)
			for(int j=0;j<c;++j) a[i][j]=(a[i][j]==1)?0:1;
	}
	int ret=0;
	for(int i=0;i<c;++i){
		int sum=0;
		for(int j=0;j<r;++j){
			sum+=a[j][i];
		}
		ret+=(sum>r/2)?sum:r-sum;
	}
	return ret;
}

int main(void){
  int r,c;
  while(cin>>r>>c,r||c){
    vector<vector<int> > a(r);
    for(int i=0;i<r;++i){
      a[i]=vector<int>(c);
    }
    for(int i=0;i<r;++i){
      for(int j=0;j<c;++j) cin>>a[i][j];
    }
    bool rc[r];
    int ans=0;
    for(int i=0;i<(1<<r);++i){
    	int b=i;
    	bool rc[r];
    	for(int j=0;j<r;++j){
    		rc[j]=(b%2)?true:false;
    		b/=2;
    	}
    	int t=solve(a,r,c,rc);
    	ans=max(t,ans);
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_d() {
	ll n, m, x, k;
	ll ans = 0;
	cin >> n >> k;

	V a(n);
	V e(n + 5);
	rep(i, n) {
		cin >> a[i];
		e[i + 1] = a[i];
	}

	ll before = 0;
	ll now = 1;
	vector<bool> visited(n + 5, false);
	while (1) {
		visited[now] = true;
		now = e[now];
		before++;
		if (visited[now]) {
			break;
		}
	}

	ll loop = 0;
	visited = vector<bool>(n + 5, false);
	ll lnow = now;
	while (1) {
		visited[lnow] = true;
		lnow = e[lnow];
		loop++;
		if (visited[lnow]) {
			break;
		}
	}

	now = 1;
	if (k <= before) {
		rep(i, k) {
			now = e[now];
		}
	}
	else {
		k -= before;
		if (k > loop) {
			k = k % loop;
		}
		rep(i, k) {
			lnow = e[lnow];
		}
		now = lnow;
	}


	cout << now << "\n";

}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed;
	//cout << setprecision(7);

	solve_abc_d();

	return 0;
}


Measured memory_bytes: 6368
inp = input().split()
abc = list(map(int, inp))

def quicksort(list):
    if len(list) < 2:
        return list
    else:
        pivot = list[0]
        #pivotよりも小さい要素を全て含んだ部分配列
        less = [i for i in list[1:] if i <= pivot]
        #pivotよりも大きい要素を含んだ部分配列
        greater = [i for i in list[1:] if i > pivot]

        return quicksort(less) + [pivot] + quicksort(greater)

sorted = quicksort(abc)
print(sorted[0],sorted[1],sorted[2])


Measured memory_bytes: 5604
#include <iostream>
#include <vector>
#include <cmath>
int main()
{
    int N;
    std::cin >> N;
    std::vector<int> W(N);
    for (int i = 0; i < N; i++) {
        std::cin >> W[i];
    }

    std::vector<int> S(N+1);
    S[0] = 0;
    for (int i = 1; i <= N; i++) {
        S[i] = S[i-1] + W[i-1];
    }

    int ans = 100000;
    for (int t = 0; t < N; t++) {
        int left = S[t];
        int right = S[N] - S[t];
        if (std::abs(left - right) < ans) {
            ans = std::abs(left - right);
        }
    }

    std::cout << ans << std::endl;

    
    return 0;
}


Measured memory_bytes: 256
import math

a,b = map(int,input().split())
s = 0

for i in range(2000,2,-1):
    if (math.floor(i*0.08) == a) and (math.floor(i*0.1) == b):
        s = i

if s != 0:
    print(s)
else:
    print('-1')


Measured memory_bytes: 2940
N , K = map(int,input().split())
B = {}
C = {}
D = {0}
A = list(map(int,input().split()))
place = 0
num = 0
C[0] = 0
while True:
    place = int(A[place]) - 1
    num += 1   
    if place in D:
        Y = int(num) - int(C[place])
        break
    elif num == K:
        break
    else:
        B[num] = place
        C[place] = num
        D.add(place)
try:
    X = (K - num) % Y
    print(B[C[place] + X] + 1)
except:
    print(place+1)


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

#define INF (1<<29)

int G[100][100], n;

int prim(){
  int p[100], d[100], c[100];
  int u;

  for(int i = 0; i < n; i++){
    d[i] = INF;
    p[i] = -1;
    c[i] = 0;
  }

  d[0] = 0;

  while(1){
    int minv = INF;
    u = -1;
    for(int i = 0; i < n; i++){
      if(minv > d[i] && c[i] != 2){
        u = i;
        // cout << u << endl;
        minv = d[i];
      }
    }

    if(u == -1) break;
    c[u] = 2;
    for(int v = 0; v < n; v++){
      if(c[v] != 2 && G[u][v] != INF){
        if(d[v] > G[u][v]){
          d[v] = G[u][v];
          p[v] = u;
          c[v] = 1;
        }
      }
    }
  }

  int sum = 0;
  for(int i = 0; i < n; i++){
    if(p[i] != -1) sum+=G[i][p[i]];
    // cout << p[i] << endl;
  }
  return sum;
}


  int main(){

    cin >> n;
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        int v;
        cin >> v;
        G[i][j] = v;
        if(v == -1) G[i][j] = INF;
      }
      // cout << endl;
    }

    cout << prim() << endl;

  }

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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    int ans[n+1];
    rep(i,n+1){
        ans[i]=0;
    }
    int r=0,l=0,now;
    rep(i,n-1){
        if(s[i]=='R'&&s[i+1]=='R'){
            r++;
        }
        else if(s[i]=='R'&&s[i+1]=='L'){
            now = i;
            ans[now]+=r/2+1;
            ans[now+1]+=(r+1)/2+1;
            r=0;
        }
        else if(s[i]=='L'&&s[i+1]=='L'){
            l++;
        }
        else if(s[i]=='L'&&s[i+1]=='R'){
            ans[now]+=(l+1)/2;
            ans[now+1]+=l/2;
            l=0;
        }
    }
    ans[now]+=(l+1)/2;
    ans[now+1]+=l/2;
    rep(i,n){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
#include"bits/stdc++.h"
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if((a==1 && b==2) || (a==2 && b==1))
		cout<<"3"<<endl;
	if((a==1 && b==3) || (a==3 && b==1))
		cout<<"2"<<endl;
	if((a==2 && b==3) || (a==3 && b==2))
		cout<<"1"<<endl;
	return 0;
}

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

int main(){
  int N;
  int C[500],S[500],F[500];
  int cnt;

  cin >> N;
  for(int i = 1; i < N; i++){
    cin >> C[i] >> S[i] >> F[i];
  }

  for(int i = 1; i < N; i++){
    cnt = 0;
    cnt += S[i] + C[i];

    for(int j = i; j < N-1; j++){
      if(cnt<S[j+1]) cnt = S[j+1];
      else if (cnt%F[j+1]==0);
      else cnt = cnt + F[j+1] -cnt%F[j+1];
      cnt += C[j+1];
    }

    cout << cnt << endl;
  }
  cout << 0 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <sstream>
#include <set>
#include <tuple>
#include <algorithm>
#include <memory>
#include <numeric>
#include <queue>
#include <functional>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <sstream>
#include <iomanip>

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

const ll INF = 1LL << 60;
const ll MOD = 1000000007;

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

	ll N, K;
	cin >> N >> K;

	vector<ll> V(N);
	for (ll i = 0; i < N; ++i) cin >> V[i];

	vector<ll> Vinv = V;
	reverse(Vinv.begin(), Vinv.end());

	ll ans = -INF;

	//for (ll push_num = 0; push_num <= min(K, N); ++push_num)
	for (ll push_num = 0; push_num <= K; ++push_num)
	{
		ll actuial_action = K - push_num;
		if (actuial_action >= N) actuial_action = N;

		for (ll lc = 0; lc <= actuial_action; ++lc)
		{
			for (ll rc = 0; rc <= actuial_action - lc; ++rc)
			{
				vector<ll> bads;

				ll point = 0;
				for (ll i = 0; i < lc; ++i)
				{
					//bool flag = false;
					//for (ll j = i; j < lc; ++j)
					//{
					//	if (V[j] > 0) flag = true;
					//}
					//if (!flag) break;

					//if ((V[i] >= 0))
					{
						point += V[i];
						if (V[i] < 0) bads.push_back(V[i]);
					}
				}

				for (ll i = 0; i < rc; ++i)
				{
					//bool flag = false;
					//for (ll j = i; j < rc; ++j)
					//{
					//	if (Vinv[j] > 0) flag = true;
					//}
					//if (!flag) break;

					//if ((Vinv[i] >= 0) || (rc - i > 1))
					//if ((Vinv[i] >= 0))
					{
						point += Vinv[i];
						if (Vinv[i] < 0) bads.push_back(Vinv[i]);
					}
				}

				//if (lc > 0)
				//{
				//	if (V[lc - 1] < 0)
				//	{
				//		point -= V[lc - 1];
				//	}
				//}
				//if (rc > 0)
				//{
				//	if (Vinv[rc - 1] < 0)
				//	{
				//		point -= Vinv[rc - 1];
				//	}
				//}


				sort(bads.begin(), bads.end());
				//reverse(bads.begin(), bads.end());

				for (ll i = 0; i < min(push_num, (ll)bads.size()); ++i)
					//for (ll i = 0; i <= min(push_num, (ll)bads.size() - 1); ++i)
				{
					point -= bads[i];
				}

				//cout << lc << "," << point << endl;

				ans = max(ans, point);
			}
		}

	}
	cout << ans << endl;

	//system("pause");
}


Measured memory_bytes: 256