akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.lang.*;
import java.util.*;
import java.math.*;

class Solver extends Main{
	Solver(){
		
	}
}//Solver_end

@SuppressWarnings("unchecked")
class Main{
	static int imax=Integer.MAX_VALUE;
	static long lmax=Long.MAX_VALUE;
	
	public static void main(String[] args) throws FileNotFoundException{
		Scanner sc=new Scanner(System.in);
		
		String[] data=readlnS(sc, "");
		List<String> str=new ArrayList<String>();
		
		for(int i=0; i<data.length; i++){
			str.add(data[i]);
		}
		
		int ans=0;
		boolean fnd=false;
		
		while(str.size()>2 && fnd==false){
			str.remove(str.size()-1);
			str.remove(str.size()-1);
			
			String[] lary=new String[str.size()/2];
			String[] rary=new String[str.size()/2];
			
			for(int i=0; i<str.size()/2; i++){
				lary[i]=str.get(i);
			}
			for(int i=0; i<str.size()/2; i++){
				rary[i]=str.get(i+(str.size()/2));
			}
			
			String l=Arrays.toString(lary);
			String r=Arrays.toString(rary);
			
			if(l.equals(r)){
				fnd=true;
				puts(str.size());
			}
		}
	}//main_end
	
//---------------------------------------------------------------------------
	static int readI(Scanner sc){
		return Integer.parseInt(sc.nextLine().trim());
	}
	static long readL(Scanner sc){
		return Long.parseLong(sc.nextLine().trim());
	}
	static String readS(Scanner sc){
		return sc.nextLine().trim();
	}
	static int[] readlnI(Scanner sc, String dl){
		return Arrays.stream(sc.nextLine().trim().split(dl)).mapToInt(Integer::parseInt).toArray();
	}
	static long[] readlnL(Scanner sc, String dl){
		return Arrays.stream(sc.nextLine().trim().split(dl)).mapToLong(Long::parseLong).toArray();
	}
	static String[] readlnS(Scanner sc, String dl){
		return sc.nextLine().trim().split(dl);
	}
	@SuppressWarnings("unchecked")
	static <T> void puts(T... args){
		for(int i=0; i<args.length-1; i++){
			System.out.printf("%s ",args[i]);
		}
		System.out.println(args[args.length-1]);
	}
	static void puts(int[] ary){
		for(int i=0; i<ary.length-1; i++){
			System.out.printf("%d ",ary[i]);
		}
		System.out.println(ary[ary.length-1]);
	}
	static void puts(long[] ary){
		for(int i=0; i<ary.length-1; i++){
			System.out.printf("%d ",ary[i]);
		}
		System.out.println(ary[ary.length-1]);
	}
	static void bs(){
		System.out.println("");
	}
	static int sum(int[] ary){
		int sum=0;
		for(int i=0; i<ary.length; i++) sum+=ary[i];
		return sum;
	}
	static long sum(long[] ary){
		long sum=0;
		for(int i=0; i<ary.length; i++) sum+=ary[i];
		return sum;
	}
	static void tblSort(int[][] tbl){
		Arrays.sort(tbl, new Comparator<int[]>(){
			@Override
			public int compare(int[] a, int[] b){
				if(a[0]==b[0]){
					return b[1]-a[1];
				}else{
					return b[0]-a[0];
				}
			}
		});
	}
}


Measured memory_bytes: 23764
n,k=map(int,input().split())
h=list(map(int,input().split()))
s=[float("INF")]*n
s[0]=0
for i in range(n):
    for j in range(k+1):
        if i+j<n:
            s[i+j]=min(s[i]+abs(h[i+j]-h[i]),s[i+j])
        else:
            break
print(s[-1])

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

int main(){
    int n;
    cin >> n;
    vector<pair<int,int>> v[n];
    for(int i = 0; i < n; i++){
        int x;  cin >> x;
        while(x-- > 0){
            int a, b;
            cin >> a >> b;
            v[i].push_back({a-1,b});
        }
    }
    int ret = 0;
    for(int i = 1; i < 1<<n; i++){
        vector<int> stat(n, 0);
        int tmp = 0;
        for(int j = 0; j < n; j++){
            if((i>>j)&1)    stat[j] = 1, tmp++;
            else            stat[j] = -1;
        }
        bool valid = true;
        for(int j = 0; j < n; j++){
            if((i>>j)&1){
                for(pair<int,int> p : v[j]){
                    valid &= (p.second==0 && stat[p.first]==-1) || (p.second==1 && stat[p.first]==1);
                }
            }
        }
        if(valid)   ret = max(ret, tmp);
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

from operator import itemgetter

n = readint()

ans = 10**10

only = [[[]for i in range(2*10**5+1)]for j in range(4)]
plus = [[[]for i in range(4*10**5+1)]for j in range(4)]
minus = [[[]for i in range(4*10**5+1)]for j in range(4)]
a = ['D','U','L','R']
for i in range(n):
    x,y,z = readstrs()
    x = int(x)
    y = int(y)
    b = a.index(z)
    if b<2:
        only[b][x].append(y)
    else:
        only[b][y].append(x)
    plus[b][x+y].append(x)
    minus[b][x-y].append(x)

for m in [0,2]:
    for i in range(2*10**5+1):
        a = only[m][i]
        b = only[m+1][i]
        if a and b:
            a.sort()
            b.sort()
            k = 0
            j = 0
            while k<len(a) and j<len(b):
                if a[k]>b[j]:
                    ans = min(ans,(a[k]-b[j])/2)
                    j += 1
                else:
                    k += 1

for p,q in [[2,1],[0,3]]:
    for i in range(4*10**5+1):
        a = minus[p][i]
        b = minus[q][i]
        if a and b:
            a.sort()
            b.sort()
            k = 0
            j = 0
            while k<len(a) and j<len(b):
                if a[k]>b[j]:
                    ans = min(ans,a[k]-b[j])
                    j += 1
                else:
                    k += 1

for p,q in [[1,3],[2,0]]:
    for i in range(4*10**5+1):
        a = plus[p][i]
        b = plus[q][i]
        if a and b:
            a.sort()
            b.sort()
            k = 0
            j = 0
            while k<len(a) and j<len(b):
                if a[k]>b[j]:
                    ans = min(ans,a[k]-b[j])
                    j += 1
                else:
                    k += 1

if ans == 10**10:
    print('SAFE')
else:
    print(int(ans*10))


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

int main(){

  long long int n,a,b;
  long long int ans,amariblue;
  cin>>n>>a>>b;
  ans=n/(a+b)*a;
  amariblue=min(n%(a+b),a);
  ans+=amariblue;

  cout<<ans<<endl;

  return 0;
}

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

#define REP(i, n) for(int i = 0;i < n;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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define M_PI 3.14159265358979323846
#define ALL(X) (X).begin(),(X).end()

#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 0};
int dy[]={0, 1, 0, -1, 0};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
 
std::string pad(int num){ char buffer[4]; std::snprintf(buffer, sizeof(buffer), "%03d", num); return buffer;}
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll N,A,B;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path p = __FILE__;
        fs::path input,output;
        input = output = p.parent_path();
        input += string("/input/") + string(p.stem()) + string(".txt");
        output += string("/output/") + string(p.stem()) + string(".txt");
        freopen(input.c_str(), "r", stdin);
        freopen(output.c_str(), "w", stdout);
    #endif
    cin >> N >> A >> B;
}

void solve(){
    ll n;
    n = N/(A+B);
    ll res = N%(A+B);
    ll ans = n*A + min(res,A);
    cout << ans << endl;    
}   

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    string S;
    cin >>S;
    int z,n;
    cin>>z;
    n=S.size();
    for(int i=0;i<N;i++){
        if(S.at(i)!=S.at(z-1)){
            S.at(i)='*';
        }
    }
    cout << S<<endl;
    
    
    
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))
H.reverse()
res = 0
for i in range(N - 1):
    if H[i] >= H[i + 1]:
        continue
    elif H[i] + 1 == H[i + 1]:
        H[i + 1] -= 1
    else:
        print('No')
        res = 100
        break
if res == 0:
    print('Yes')


Measured memory_bytes: 14396
#include <stdio.h>
#define NUMBER 100

int check_bingo(int a[3][3])
{
    int c = -1;
    int i;
    for (i = 0;i < 3;i++){
        if ((a[i][0] == 0 && a[i][1] == 0 && a[i][2] == 0) || (a[0][i] == 0 && a[1][i] == 0 && a[2][i] == 0) || (a[1][1] == 0 && a[2][2] == 0 && a[0][0] == 0) || (a[2][0] == 0 && a[1][1] == 0 && a[0][2] == 0)){
            c = 1;
            break;
        }
    }
    return c;
}


int main(void)
{
    int a[3][3];
    int n;
    int b[NUMBER];
    int i,j,k;
    
    for (i = 0;i < 3;i++){
            scanf("%d %d %d",&a[i][0],&a[i][1],&a[i][2]);
    }
    scanf("%d",&n);
    for (i = 0;i < n;i++){
        scanf("%d",&b[i]);
    }
    
    for (i = 0;i < n;i++){
        for (j = 0;j < 3;j++){
            for (k = 0;k < 3;k++){
                if (b[i] == a[j][k]){
                    a[j][k] = 0;
                }
            }
        }
    }
    
    if (check_bingo(a) == 1){
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	a := iSScan(n)
	x := make([]int, 100003)
	for _, v := range a {
		x[v]++
		x[v+1]++
		x[v+2]++
	}
	fmt.Println(max(x))
}


Measured memory_bytes: 3948
s= input();
q = int(input());
flag = 0;
fornt = "";
back = "";
while(q>0):
    q-=1;
    ls = list(map(str,input().split(" ")));
    if(ls[0]=='1'):
        flag +=1;
    else:
        if(flag%2 == 1):
            if(ls[1]=='2'):
                fornt=ls[2]+fornt;
            else:
                back=back+ls[2];
        else:
            
            if(ls[1]=='1'):
                fornt=ls[2]+fornt;
            else:
                back=back+ls[2];
s = fornt+s+back
if(flag%2==0):
    print(s);
else:
    print(s[::-1])

Measured memory_bytes: 224464
N,K = map(int, input().split())
P = list(map(int, input().split())) 
tmp=sum(P[:K])
maxN=tmp
for i in range(1,N-K+1):
  tmp=tmp-P[i-1]+P[i+K-1]
  if tmp>=maxN:
    maxN=tmp
print((maxN+K)/2)

Measured memory_bytes: 24804
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 200000000
#define mod 1000000007
#define INF2 1000000000000000000

int dp[1010][(1<<12)];
bool key[1010][12];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    int a[1010] = {};
    rep(i, M) {
        int b; cin >> a[i] >> b;
        rep(j, b) {
            int c; cin >> c;
            key[i][c - 1] = true;
        }
    }
    rep(i, 1010) rep(j, (1<<12)) dp[i][j] = INF;
    dp[0][0] = 0;
    rep(i, M) {
        rep(j, (1<<N)) {
            int bit = j;
            rep(k, 12) bit = (bit | (key[i][k] << k));
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            dp[i + 1][bit] = min(dp[i + 1][bit], dp[i][j] + a[i]); 
        }
    }
    if (dp[M][(1 << N) - 1] == INF) {
        cout << -1 << endl;
    } else {
        cout << dp[M][(1 << N) - 1] << endl;
    }
    // rep(i, M) {
    //     rep(j, 3) cout << dp[i][j] << " ";
    //     cout << endl;
    // }



    return 0;
}


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

int a[100001];
bool f[100001];

int main() {
    int n;
    cin >> n;
    fill(f,f+n+1,false);

    for(int i=1;i<=n;i++){
        scanf(" %d",&a[i]);
    }
    int next = 1,count = 0;

    while(1){
        if(next == 2){
            cout << count << endl;
            break;
        }
        if(f[next]){
            cout << -1 << endl;
            break;
        }
        f[next] = true;
        next = a[next];
        count++;
    }

    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
template <typename X>
struct RMQ{
  vector<X> dat;
  int n;
  X init;
  
  RMQ(int _n,X _init)
  {
    n = 1;
    init = _init;
    while(n < _n) n *= 2;
    dat.resize(2*n-1);
    rep(i,2*n-1){
      dat[i] = init;
    }
  }
  
  void update(int k,X a)
  {
    k += n - 1;
    dat[k] = a;
    while(k > 0){
      k = (k - 1)/2;
      dat[k] = min(dat[2*k+1],dat[2*k+2]);
    }
  }
  
  X query(int a,int b,int k,int l,int r)
  {
    if(r<=a||b<=l) return init;

    if(a<=l&&r<=b) return dat[k];
    else{
      X vl = query(a,b,2*k+1,l,(l+r)/2);
      X vr = query(a,b,2*k+2,(l+r)/2,r);
      return min(vl,vr);
    }
  }
};
int _n,q;
bool com[100010];
int x[100010],y[100010];
const ll AMAX = (ll)(1<<30)*2 - 1;
int main()
{
  cin >> _n >> q;
  rep(i,q) cin >> com[i] >> x[i] >> y[i];

  RMQ<ll> r(_n,AMAX);

  rep(i,q){
    if(com[i]){
      ll res = r.query(x[i],y[i]+1,0,0,r.n);
      cout << res << "\n";
    }
    else r.update(x[i],(ll)y[i]);
  }

  
  return 0;
}



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

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

    // solution comes here
    string S;
    cin >> S;

    ll N=S.size(), n=0;
    rep(i, N) n += ('0'==S[i]);

    cout << 2*min(n, N-n) << nl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define repl(i, l, r) for (int i = l; i < r; ++i)
#define rep(i, n) repl(i, 0, n)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using G = vector<vector<int>>;
const int MOD = 998244353;
const int INF = 1001001001;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, -1, 0, 1};

int main()
{
    int n;
    cin >> n;
    int cnt = 0;
    ll ans = 0;
    int mi = INF;
    rep(i, n) {
        int a;
        cin >> a;
        if(a < 0) ++cnt;
        ans += (ll) abs(a);
        mi = min(mi, abs(a));
    }
    if(cnt % 2) cout << ans - 2 * mi << endl;
    else cout << ans << endl;
    return 0;
}

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

int main()
{
	int n, k;
	cin >> n >> k;
	int a[n];
	for(int i = 0; i < n; i ++)
	cin >> a[i];
	sort(a, a + n);
	int sum = 0;
	for(int i = 0; i < k; i ++)
	sum += a[i];
	cout << sum;
	return 0;
}


Measured memory_bytes: 3148
s = input()
a = [str(c) for c in s]


b = a[0::2]
c = a[1::2]


if "L" in b:
    d = False
else:
    d = True


if "R" in c:
    f = False
else:
    f = True

if d and f:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
using namespace std;
const int mod=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    vector<int> t(n);
    rep(i,0,n-1){
        cin >> s[i] >> t[i];
    }
    string x;
    cin >> x;
    int ans = 0;
    bool flg = false;
    rep(i,0,n-1){
        if(flg){ans += t[i];}
        if(x == s[i]){flg = true;}
    }

    cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 256
N = int(input())
T, A = map(int, input().split())
X = list(map(int, input().split()))

s = 10000

for i in range(N):
  x = T - X[i] * 0.006
  if abs(A - x) < s:
    ans = i
    s = abs(A - x)
print(ans+1)


Measured memory_bytes: 9240
#include <iostream>

using namespace std;

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

    if (a >= b) {
        for (int i = 0; i < a; i++) { cout << b; }
    } else {
        for (int i = 0; i < b; i++) { cout << a; }
    }

    cout << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
divis=[]
for i in range(1,int(m**0.5)+1):
	if m%i==0:
		divis.append(i)
		if i!=m//i:
			divis.append(m//i)
ans=1
for i in divis:
	if i<=m//n:
		ans=max(ans,i)
print(ans)

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

using FLOAT = long double;
const FLOAT EPS = 1e-10;
const FLOAT INF = 1e12;
typedef complex<FLOAT> P;

inline bool EQ(FLOAT a, FLOAT b) { return abs(a - b) < EPS; }
inline bool EQV(P a, P b) { return EQ(a.real(), b.real()) && EQ(a.imag(), b.imag()); }
FLOAT cross(const P & a, const P & b) {
	return imag(conj(a) * b);
}

FLOAT dot(const P & a, const P & b) {
	return real(conj(a) * b);
}

struct L : public vector<P> {
	L(const P& a, const P& b) {
		push_back(a); push_back(b);
	}
};

int ccw(P a, P b, P c) {
	b -= a; c -= a;
	if (cross(b, c) > EPS) return +1;
	if (cross(b, c) < -EPS) return -1;
	if (dot(b, c) < 0) return +2;
	if (norm(b) < norm(c)) return -2;
	return 3;
}

bool okcross;

P crosspoint(const L & l, const L & m) {
	okcross = true;
	FLOAT A = cross(l[1] - l[0], m[1] - m[0]);
	FLOAT B = cross(l[1] - l[0], l[1] - m[0]);
	if (abs(A) < EPS && abs(B) < EPS) return m[0];
	if (abs(A) < EPS) {
		okcross = false;
		return m[0];
	}
	return m[0] + B / A * (m[1] - m[0]);
}

double x1[3], yy1[3], x2[3], yy2[3];
P q[3];

int dfs(P p1, P p2, P p3,int dist) {
	if(dist >= 5) return 100;
	//cout << p1.real() << " " << p1.imag() << " " << p2.real() << " " << p2.imag() << " " << p3.real() << " " << p3.imag() << " " << dist << endl;
	bool f = true;
	P p[3] = { p1,p2,p3 };
	for(int i = 0;i < 3;i++){
		bool f2 = false;
		for(int j = 0;j < 3;j++){
			if(EQV(p[i],q[j])) f2 = true;
		}
		if(!f2) f = false;
	}
	if(f) return 0;
	
	int ans = 8;
	for (int i = 0; i < 3; i++) {
		bool flag = true;
		for(int j = 0;j < 3;j++){
			if(EQV(p[i],q[j])) flag = false;
		}
		if(!flag) continue;
		for (int j = 0; j < 3; j++) {
			flag = true;
			for(int k = 0;k < 3;k++){
				if(EQV(p[k],q[j])) flag = false;
			}
			if(!flag) continue;
			if (abs(ccw(p[i], p[(i + 2) % 3] - p[(i + 1) % 3] + p[i], q[j])) >= 2) {
				//cout << i << ":" << j << endl;
				P tmp = p[i];
				p[i] = q[j];
				ans = min(ans, dfs(p[0], p[1], p[2],dist + 1) + 1);
				p[i] = tmp;
			}else{
				//cout << i << " " << j << endl;
				P tmp = crosspoint(L(p[(i + 1) % 3], p[(i + 1) % 3] - p[(i + 2) % 3] + p[i]), L(p[(i + 2) % 3], p[(i + 2) % 3] + q[j] - p[i]));
				if(okcross){
					P tmppi = p[i], tmppj = p[(i + 1) % 3];
					p[i] = q[j];
					p[(i + 1) % 3] = tmp;
					ans = min(ans, dfs(p[0], p[1], p[2],dist + 2) + 2);
					p[i] = tmppi;
					p[(i + 1) % 3] = tmppj;
				}
				tmp = crosspoint(L(p[(i + 2) % 3], p[(i + 2) % 3] - p[(i + 1) % 3] + p[i]), L(p[(i + 1) % 3], p[(i + 1) % 3] + q[j] - p[i]));
				if(okcross){
					P tmppi = p[i], tmppj = p[(i + 2) % 3];
					p[i] = q[j];
					p[(i + 2) % 3] = tmp;
					ans = min(ans, dfs(p[0], p[1], p[2],dist + 2) + 2);
					p[i] = tmppi;
					p[(i + 2) % 3] = tmppj;
				}
			}
		}
	}
	return ans;
}

int main() {
	while (cin >> x1[0] >> yy1[0]) {
		for (int i = 1; i < 3; i++) cin >> x1[i] >> yy1[i];
		for (int i = 0; i < 3; i++) cin >> x2[i] >> yy2[i];
		q[0] = P(x2[0], yy2[0]);
		q[1] = P(x2[1], yy2[1]);
		q[2] = P(x2[2], yy2[2]);
		int ans = dfs(P(x1[0], yy1[0]), P(x1[1], yy1[1]), P(x1[2], yy1[2]),0);
		if (ans >= 5) cout << "Many" << endl;
		else cout << ans << endl;
	}
}


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

struct info {
    int a, b, c, d;
};

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    vector<info> v(q);
    for (int i = 0; i < q; i++) {
        info in;
        cin >> in.a >> in.b >> in.c >> in.d;
        v[i] = in;
    }
    queue<vector<int>> que;
    que.push({1});
    int cur_mx = 0;
    while (!que.empty()) {
        vector<int> front = que.front();
        que.pop();
        int sz = front.size();
        if (sz == n) {
            int score = 0;
            for (int i = 0; i < q; i++) {
                int a = v[i].a;
                int b = v[i].b;
                int c = v[i].c;
                int d = v[i].d;
                if (front[b - 1] - front[a - 1] == c) {
                    score += d;
                }
            }
            cur_mx = max(cur_mx, score);
        } else {
            int last = front[sz - 1];
            for (int i = last; i <= m; i++) {
                vector<int> nw = front;
                nw.push_back(i);
                que.push(nw);
            }
        }
    }
    cout << cur_mx;
    return 0;
}

Measured memory_bytes: 6636
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1000000;
const int mod = 998244353;
const ll INF = 1LL << 60;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define fix(n) fixed<<setprecision(n)
#define itr vector<ll>::iterator
ll n, k, d[11];
bool f(){
	ll m = n;
	bool a = 1;
	while (m > 0) {
		ll num = m % 10;
		m /= 10;
		if (d[num])a = 0;
	}
	return a;
}
int main() {
	cin >> n >> k;
	ll a;
	rep(i, k) {
		cin >> a;
		d[a] = 1;
	}
	while (1) {
		if (f())break;
		++n;
	}
	cout << n << endl;
	return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;



int main(){
	string s;
	cin>>s;
	
	vector<string> tb;
	for (int i = 0; i < pow(2,s.size()-1) ; i++){
		string t=s;
		int cnt=0;
		//cout<<bitset<9>(i)<<endl;
		for (int j = 0; j <= 8 ; j++){
			if(i&(1<<j)){
				t.insert(j+1+cnt,"+");
				cnt++;
			}
		}
		tb.push_back(t);
	}
	
	ll ans=0;
	for (int i = 0; i < pow(2,s.size()-1); i++){
		ll cur=0;
		for (int j = 0; j < tb[i].size(); j++){
			if(tb[i][j]=='+'){
				ans+=cur;
				cur=0;
			}else{
				cur=cur*10+(tb[i][j]-'0');
			}
		}
		ans+=cur;
	}


	cout<<ans<<endl;

	return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b; cin>>a>>b;
    if (a>b) swap(a,b);
    if ((b-a)%2==0){
        cout<<a+(b-a)/2<<endl;
    }else{
        cout<<"IMPOSSIBLE\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    vector<int> res(10010);
    int se = 0;
    for(int i = 0; i < res.size(); i++) {
        int tmp;
        cin >> tmp;
        if(tmp == 0) {
            se = i;
            break;
        }
        res[i] = tmp;
    }
    for(int i = 1; i<=se;i++) {
        cout << "Case " << i << ": " << res[i-1] << endl;
    }
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    double a[n];
    rep(i,n) cin >> a[i];
    double ans = 0;
    rep(i,n) ans += 1.0/a[i];
    ans = 1.0/ans;
    printf("%.9f",ans);
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define MAXN 200000+9
using namespace std;

int n,m;
struct E{
	int next,to;
}edge[MAXN<<1];
int edge_num;
int head[MAXN];

void addedge(int x,int y){
	edge[++edge_num].next=head[x];
	edge[edge_num].to=y;
	head[x]=edge_num;
}

int main(){
	scanf("%d%d",&n,&m);
	int i,j;
	for(i=1;i<=m;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		addedge(a,b);
		addedge(b,a);
	}
	for(i=2;i<n;i++){
		bool pd1=0,pdn=0;
		for(j=head[i];j;j=edge[j].next){
			if(edge[j].to==1)
				pd1=1;
			if(edge[j].to==n)
				pdn=1;
		}
		if(pd1==1 && pdn==1){
			printf("POSSIBLE\n");
			return 0;
		}
	}
	printf("IMPOSSIBLE\n");
	return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    cout << 48 - N << endl;
}


Measured memory_bytes: 256
def gcd(a, b):
  if b==0:
    return a
  return gcd(b, a%b)

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

A, B = [int(x) for x in input().split()]
print(saishoukoubaisu(A, B))


Measured memory_bytes: 2940
#include<stdio.h>	

#define MAXLENGTH 100000

int Max(long int max, long int a)
{
	long int t;

	if (max < a)
	{
		t = max;
		max = a;
		a = t;
	}

	return max;
}

int Min(long int min, long int a)
{
	long int t;

	if (min > a)
	{
		t = min;
		min = a;
		a = t;
	}

	return min;
}

int main(void)
{
	int n, i;
	long int sum = 0, max = -1000000, min = 1000000;
	long int a[MAXLENGTH];

	scanf("%d", &n);

	for (i = 0; i < n; i++)
	{
		scanf("%ld", &a[i]);
		sum += a[i];

		max = Max(max, a[i]);
		min = Min(min, a[i]);
	}

	printf("%ld %ld %ld\n", min, max, sum);
}



Measured memory_bytes: 2108
#include<stdio.h>
int main(){

  int i,j,a[101][101],b[1001],n,m;
  int sum;
  scanf("%d%d",&n,&m);

  for(i=0;i<n;i++){
    for(j=0;j<m;j++){

      scanf("%d",&a[i][j]);
    }
  }
  for(i=0;i<m;i++){
    scanf("%d",&b[i]);
  }

  for(i=0;i<n;i++){
    sum=0;
    for(j=0;j<m;j++){
      sum+= a[i][j]*b[j];
    }
    printf("%d\n",sum);
  }

  return 0;
}



Measured memory_bytes: 2104
//C
#include <cassert>
//#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//ここまで標準include

using namespace std;

long aCb(long a, long b) {
	long out = 1;
	for (long i = 1; i <= b; i++) {
		out = out * (a + 1 - i) / i;
	}
	return out;
}

long long gcd(long long a, long long b) {
	long long r = -1;
	if (a < b) {
		swap(a, b);
	}
	while (r != 0) {
		r = a % b;
		if (r == 0) {
			return b;
		}
		else {
			a = b;
			b = r;
		}
	}
}

long long lcm(long long a, long long b) {
	return a * b / gcd(a, b);
}

int main() {
	int x;
	cin >> x;
	if (x < 1200) {
		cout << "ABC" << endl;
	}
	else {
		cout << "ARC" << endl;
	}
}


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

class SLEqual
    {
        static void Main()
    {
        var st = Console.ReadLine();
        int a = int.Parse(st.Split(' ')[0]);
        int b = int.Parse(st.Split(' ')[1]);
        int c = int.Parse(st.Split(' ')[2]);
        int tmp;
        if (a < b)
        {
            if (b > c)
            {
                tmp = b; b = c; c = tmp;
            }
        }
        else
        {
            tmp = a; a = b; b = tmp;

            if (b > c)
            {
                tmp = b; b = c; c = tmp;
                if (a > b)
                {
                    tmp = a; a = b; b = tmp;
                }
            }
        }
            Console.WriteLine(a+" "+b+" "+c);

        }
    }

Measured memory_bytes: 5612
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

// conversion
//------------------------------------------
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

// math
//-------------------------------------------
template <class T> inline T sqr(T x) { return x * x; }

// typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

// container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c)                                                             \
  for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;

const long long MOD = 1000000007;

void solve(long long N, long long M, std::vector<long long> a) {
  vector<long long> dp(N+1);
  vector<int> broken(N+1);
  REP(i,N+1){
    dp[i]=0;
  }
  dp[0] = dp[1] = 1;
  for(int i=0; i<N+1; i++){
    broken[i]=0;
  }
  for(int i=0; i<M; i++){
    broken[a[i]]=1;
  }
  
  for(int i=2;i < N+1; i++){
    if(broken[i-1]==0)dp[i]=(dp[i]+dp[i-1])%1000000007;
    if(broken[i-2]==0)dp[i]=(dp[i]+dp[i-2])%1000000007;
  }
  // REP(i, N+1){
  //   cout<<dp[i]<<endl;
  // }
  cout<<dp[N]<<endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> a(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &a[i]);
  }
  solve(N, M, std::move(a));
  return 0;
}


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

int compare(int a, int b){
   if(a>b) return -1;
   if(a==b) return 0;
   if(a<b) return 1;
}
int main() {
int N; cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++) cin >> A.at(i);
  //増加から分ける
  int ans=0;
  int count =0;
  int cur = 0;

  for(int i=0; i<N-1; i++){
    if (count == 0 || cur == 0){
      count++;
      cur = compare(A.at(i),A.at(i+1));
      continue;
    }
    if (A.at(i) != A.at(i+1) && compare(A.at(i),A.at(i+1)) != cur){
      count = 0;
      ans++;
    }
  }
  cout << ans +1 << endl;
  
}

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

#define mod 1000000007

using namespace std;
typedef long long ll; 
 
int main(void){
	
	int N, D;
	
	cin >> N >> D;
	
	if(N % (2 * D + 1) == 0)
		cout << N / (2 * D + 1);
	else
		cout << N / (2 * D + 1) + 1;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<queue> 
using namespace std;
//int n,a[200005],ans;5000; 
char s[10];
int main(){
//	freopen("x.txt","r",stdin);
	scanf("%s",s);
	if(s[2]==s[3]&&s[4]==s[5]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 3736
//
//  main.cpp
//  atcoder
//
//  Created by Hisaki Kobayashi on 2020/04/14.
//  Copyright © 2020 Hisaki Kobayashi. All rights reserved.
//

#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
typedef long long ll;
using namespace std;


int main(int argc, const char * argv[]) {
    
//    // input from txt （提出時にこの箇所は削除すること）
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());
//
    ll N , K;
    cin >> N >> K;
    vector<double> s(N+1); s[0] = 0;
    vector<double> p(N+1); p[0] = 0;
    for(ll i=0;i<N;i++){
        cin >> p[i+1];
        s[i+1] = s[i] + p[i+1];
    }
    
    ll max_expect = 0;
    ll i_save=0;;
    for(ll i=1;i<=N-K+1;i++){
        if(max_expect < s[i+K-1] - s[i-1]){
            max_expect = s[i+K-1] - s[i-1];
            i_save = i;
        }
    }
    double sum=0.0;
    for(ll i=0;i<K;i++){
//        cout << "p[i_save] : " << p[i_save+i] << endl;
//        sum += (p[i_save+i] + 1.0) / 2.0;
        sum += p[i_save+i] + 1.0;
    }
    sum /= 2.0;
    cout <<fixed <<setprecision(10) <<sum << endl;
//    cout << "save_i : " << i_save << endl;
   
    return 0;
}


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

using namespace std;

typedef long long int li;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}
    
int main()
{    
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);

        li a,b,c;

        cin>>a>>b>>c;

        if(a+b+c>=22)
            cout<<"bust";
        else
            cout<<"win";

    return 0;
}

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

int n;
int a[100000];
bool f = 0;

int main()
{
	cin >> n;

	for (int i = 0; i < n; i++)
		cin >> a[i];

	sort(a, a + n);

	if (n % 3 == 0) {
		if (a[0] == a[n / 3 - 1] && a[n / 3] == a[n / 3 * 2 - 1] && a[n / 3 * 2] == a[n - 1])
			if((a[0] ^ a[n / 3]) == a[n / 3 * 2])
				f = 1;
	}
	else if (a[n - 1] == 0)
		f = 1;

	if(f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 640
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

enum P = 10L^^9+7;

void main()
{
    auto N = readln.chomp.to!int;
    auto ts = readln.split.to!(int[]);
    auto as = readln.split.to!(int[]);

    auto xs = new long[](N);
    foreach (i; 0..N) {
        if (i == 0 || ts[i] > ts[i-1]) {
            xs[i] = -ts[i];
        } else {
            xs[i] = ts[i];
        }
    }
    foreach_reverse (i; 0..N) {
        if (i == N-1 || as[i] > as[i+1]) {
            if (xs[i] == -as[i] || xs[i] >= as[i]) {
                xs[i] = -as[i];
            } else {
                writeln(0);
                return;
            }
        } else {
            xs[i] = min(xs[i], as[i]);
        }
    }
    auto r = 1L;
    foreach (x; xs) {
        r = (r * max(1, x)) % P;
    }
    writeln(r);
}

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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define pb push_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;


void solve(){

    int n;
    cin >> n;
    ll k;
    cin >> k;

    vi a(n, 0);
    int tmp;
    rep(i,0,n){
        cin >> tmp;
        a[i] = tmp-1;
    }

    vi isVisited(n, -1);
    int cnt = 0, s = 0;
    while(1){
        if(isVisited[s] != -1) break;
        isVisited[s]=cnt;
        ++cnt;
        s=a[s];
    }

    int cycle = cnt-isVisited[s];
    if(k > isVisited[s]+cycle){
        k -= isVisited[s];
        k = k%cycle+isVisited[s];
    }

    s=0;
    while(k--){
        s=a[s];
    }

    cout << s+1 << "\n";

    return;
}

/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/
int main(){

    fast_io;
    int t=1;
    // cin >> t;

    while(t--){
        solve();
    }

    cpuTime();
return 0;
}


Measured memory_bytes: 4832
N = int(input())
L = []
for _ in range(N):
    L.append(int(input()))
def lcm(x, y):
    if x > y:
        x,y = y,x
    if x == 0:
        return y
    r = y % x
    return lcm(r,x)
def gcd(x,y):   
    return   x*y // lcm(x,y)

ans = L[0]
for x in L:
    ans = gcd(ans,x)
print(ans)

Measured memory_bytes: 3064
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;

template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


bool solve(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        --a[i];
    }

    map<vector<int>, int> range, v_range;
    vector<int> start(n);
    iota(start.begin(), start.end(), 0);

    queue<vector<int>> que;
    que.push(start);
    while(!que.empty()){
        auto pos = move(que.front());
        que.pop();
        int d = range[pos];
        for(int l = 0; l < n; ++l)
            for(int r = l + 2; r <= n; ++r){
                reverse(next(pos.begin(), l), next(pos.begin(), r));
                if(range.find(pos) == range.end()){
                    range[pos] = d + 1;
                    if(d + 1 < 4)
                        que.push(pos);
                }
                reverse(next(pos.begin(), l), next(pos.begin(), r));
            }
    }
    for(auto& p : range){
        vector<int> w(n);
        for(int i = 0; i < n; ++i)
            w[i] = a[p.first[i]];
        v_range[move(w)] = p.second;
    }
    int ans = 9;
    for(auto& p : range){
        if(v_range.find(p.first) == v_range.end())
            continue;
        chmin(ans, p.second + v_range[p.first]);
    }
    cout << ans << endl;

    return false;
}

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



Measured memory_bytes: 66844
def read_input():
    n = int(input())
    slist = []
    for i in range(n):
        slist.append(input())

    return n, slist

def submit():
    n, slist = read_input()

    ab_in = 0
    x_a = 0
    b_x = 0
    b_a = 0

    for s in slist:
        for s1,s2 in zip(s, s[1:]):
            if s1 == 'A' and s2 == 'B':
                ab_in += 1

        if s[0] == 'B' and s[-1] == 'A':
            b_a += 1
        elif s[0] == 'B':
            b_x += 1
        elif s[-1] == 'A':
            x_a += 1

    chain_ab = 0

    # b_aをつなげる
    if b_a > 0:
        chain_ab += b_a - 1
        if x_a > 0:
            chain_ab += 1
            x_a -= 1

        if b_x > 0:
            chain_ab += 1
            b_x -= 1

    print(ab_in + chain_ab + min(x_a, b_x))


if __name__ == '__main__':
    submit()


Measured memory_bytes: 46296
n=input()
d=list(map(int,input().split()))
dic={}
for i in d:
    if i in dic:
        dic[i]+=1
    else:
        dic[i]=1
m=input()
t=list(map(int,input().split()))
for i in t:
    if i in dic and dic[i]>0:
        dic[i]-=1
    else:
        print("NO")
        exit()
else:
    print("YES")

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/e.in", "r", stdin);
//  freopen("../IO/e.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}

constexpr int P = 1000'000'007;

int64_t gcd(int64_t a, int64_t b) {
  while (b != 0) {
    tie(a, b) = make_pair(b, a % b);
  }
  return a;
}

void solve(std::istream &in, std::ostream &out) {
  int n;
  in >> n;
  int z = 0;
  map<pair<int64_t, int64_t>, pair<int, int>> m1;
  for (int i = 0; i < n; ++i) {
    int64_t x, y;
    in >> x >> y;
    if (x == 0 && y == 0) {
      ++z;
      continue;
    }
    if (y < 0) {
      x = -x;
      y = -y;
    }
    int64_t g = gcd(abs(x), abs(y));
    x /= g;
    y /= g;
    if (x > 0) {
      m1[{x, y}].first++;
    } else {
      m1[{y, -x}].second++;
    }
  }
  vector<int> p2(1, 1);
  while (p2.size() < n + 100) {
    p2.push_back(p2.back() * 2 % P);
  }
  int64_t res = 1;
  for (auto &[x, y] : m1) {
    auto [c1, c2] = y;
    res *= (p2[c1] + p2[c2] - 1);
    res %= P;
  }
  out << (z + res + P - 1) % P << '\n';
}


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


int main() {

  int n;
  cin >> n;

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

  int m;
  cin >> m;

  vector<int> b(m);
  for (int i = 0; i < m; i++) {
    cin >> b[i];
  }

  int count = 0;

  while(1) {

    if (a.size() == count && b.size() == count) {
      cout << 0 << endl;
      return 0;
    }

    if (a.size() == count) {
      cout << 1 << endl;
      return 0;
    }

    if (b.size() == count) {
      cout << 0 << endl;
      return 0;
    }

    if (a[count] == b[count]) {
      count++;
    } else {
      if (a[count] < b[count]) {
        cout << 1 << endl;
      } else {
        cout << 0 << endl;
      }
      return 0;
    }

  }

}


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

int main(){
    int x, y, z;
    cin >> x >> y >> z;
    int ans = 0;
    x -= (y + 2*z);
    while(x >= 0){
        ans++;
        x -= (y + z);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int[] A = new int[N + 2];
		A[0] = 0;
		A[N + 1] = 0;
		for (int i = 1; i <= N; i++) {
			A[i] = in.nextInt();
		}
		int[] B = new int[N + 1];
		int sum = 0;
		for (int i = 0; i <= N; i++) {
			B[i] = Math.abs(A[i] - A[i + 1]);
			sum += B[i];
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 1; i <= N; i++) {
			int ans = sum;
			ans = ans + Math.abs(A[i - 1] - A[i + 1]) - (B[i] + B[i - 1]);
			sb.append(ans);
			sb.append("\n");
		}
		System.out.println(sb.toString());
		in.close();
	}
}

Measured memory_bytes: 53548
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORit(it,a) for(auto it=a.begin();it!=a.end();it++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define vec vector
#define pb push_back
#define pop pop_back
#define all(x) x.begin(),x.end()
#define testcases ll t;cin>>t;while(t--)
#define mem(a,k) memset(a,k,sizeof(a))
#define F first
#define S second
#define MP(x,y) make_pair(x,y)
#define rt return
#define br break
#define ct continue
#define elif else if
#define ii pair<ll,ll>
#define arrin(a,n,index) for(int i=index;i<n;i++)cin>>a[i]
#define vecin(a,n,index) for(int i=index;i<n;i++)cin>>a[i]
#define arrout(a,n,index) for(int i=index;i<n;i++)cout<<a[i]<<" ";cout<<endl;
#define vecout(a,n,index) for(int i=index;i<n;i++)cout<<a[i]<<" ";cout<<endl;
//ll mod = 1000000007;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
	// START FROM HERE :)
	string s, t;
	cin >> s ;
	cin >> t;
	int m = s.length(), n = t.length();
	int k = 1000;
	FOR(i, 0, m - n + 1) {
		int cnt = 0;
		FOR(j, i, i + n) {
			if (s[j] != t[j - i])cnt++;
		}
		k = min(k, cnt);
	}
	cout << k << endl;

}

Measured memory_bytes: 3656