akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  int a, b;
  cin >> a >> b;
  if(a+b >= 10) cout << "error" << endl;
  else cout << a+b << endl;
}






Measured memory_bytes: 256
class Dice:
    def __init__(self):
        self.u=1
        self.w=2
        self.s=3
        self.e=4
        self.n=5
        self.d=6
        self.dic={"W":0,"S":1,"E":2,"N":3}
     
    def __init__(self,u,w,s,e,n,d):
        self.u=u
        self.w=w
        self.s=s
        self.e=e
        self.n=n
        self.d=d
        self.dic={"W":0,"S":1,"E":2,"N":3}
 
    def rot(self,way):
        if isinstance(way,str):
            way=self.dic[way]
 
        if(way==0):
            c=self.u
            self.u=self.e
            self.e=self.d
            self.d=self.w
            self.w=c
        elif way==1:
            c=self.u
            self.u=self.n
            self.n=self.d
            self.d=self.s
            self.s=c
        elif way==2:
            c=self.u
            self.u=self.w
            self.w=self.d
            self.d=self.e
            self.e=c
        else :
            c=self.u
            self.u=self.s
            self.s=self.d
            self.d=self.n
            self.n=c
 
u,s,e,w,n,d=map(int,input().split())
dice=Dice(u,w,s,e,n,d)
st=input()
for c in st:
    dice.rot(c)
print(dice.u)


Measured memory_bytes: 5608
#include <iostream>
using namespace std;
const int MOD = 10000;
int memo[4][4][105] = {};
int schedule[105] = {};
int N, K;
int calc(int dby, int yesterday, int today){
	if (today == N) return 1;
	if (memo[dby][yesterday][today] > 0) return memo[dby][yesterday][today];

	if (schedule[today] != 0){
		if (dby == yesterday && yesterday == schedule[today]) return 0;
		return calc(yesterday, schedule[today], today + 1);
	}

	int ans = 0;
	for (int i = 1; i <= 3; i++){
		if (dby == yesterday && yesterday == i) continue;
		ans = (ans + calc(yesterday, i, today + 1)) % MOD;
	}
	memo[dby][yesterday][today] = ans;
	return ans;
}
int main(){
	cin >> N >> K;
	for (int i = 0; i < K; i++){
		int A, B;
		cin >> A >> B;
		schedule[A-1] = B;
	}
	cout << calc(0, 0, 0) << endl;
	return 0;
}

Measured memory_bytes: 1168
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int N;
long long sum;


long long gcd (long long a,long long b){
    if(a < b){
        return gcd(b,a);
    } else if(b == 0){
        return a;
    } else {
        long long c = a % b;
        return gcd(b,c);
    }
}


int main() {
    cin >> N;
    for (int i = 0;i<N;i++){
        for (int j = 0;j<N;j++){
            for (int k = 0;k<N;k++){
                sum += gcd(gcd(i+1,j+1),k+1);
                
            }
        }
    }
    cout << sum << endl;
}




Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#define RAND(x) ((a*(x)+b)%c)
using namespace std;

int main(){
  int n,a,b,c,x;
  while(cin>>n>>a>>b>>c>>x && n){
    vector<int> vec(n);
    for(int i=0;i<n;i++){
      cin>>vec[i];
    }
    int i=0;
    int counter=0;
    for(i=0;i<10001;i++){
      if(vec[counter]==x){
	counter++;
      }
      if(counter==n) break;
      x=RAND(x);
    }
    if(i==10001)
      cout<<-1<<endl;
    else
      cout<<i<<endl;
  }
  return 0;
}

Measured memory_bytes: 1196
from sys import stdin

SECONDS_PER_HOUR = 3600
SECONDS_PER_MINUTE = 60

S = int(stdin.readline().rstrip())

h, m = divmod(S, SECONDS_PER_HOUR)
m, s = divmod(m, SECONDS_PER_MINUTE)

print("{}:{}:{}".format(h, m, s))



Measured memory_bytes: 5596
from collections import Counter

def main():
    n, k, q = map(int, input().split())
    a = [int(input()) for i in range(q)]
    a_c = Counter(a)
    for i in range(1, n+1):
        if 0 < k + a_c.get(i, 0) - q:
            print('Yes')
        else:
            print('No')
    # そもそも全員からq引いて当たった人に1引くってやればもっと簡単な実装になる

if __name__ == '__main__':
    main()

Measured memory_bytes: 16620
N = int(input())
A = list(map(int, input().split()))
signal = 0
ans = 0
for i in range(N):
  if i == 0:
    signal += A[i]
  else:
    if A[i] < signal:
      ans += signal-A[i]
    else:
      signal = A[i]

print(ans)



Measured memory_bytes: 32236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

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

  int tm = 0;
  int fm = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] % 4 == 0) {
      fm++;
    } else if (a[i] % 2 == 0) {
      tm++;
    }
  }

  if(tm > 0) --tm;

  int h = (n - tm) / 2;

  string ans = "Yes";
  if (fm < h) {
    ans = "No";
  }

  cout << ans << endl;

  return 0;
}

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

int vector_finder(vector<int> vec, int number) {
  auto itr = find(vec.begin(), vec.end(), number);
  size_t index = distance( vec.begin(), itr );
  if (index != vec.size()) {
    return 1;
  }
  else {
    return 0;
  }
}


int main() {
  int x,n;
  cin >> x >> n;
  int ansa,ansb;
  ansa = -1000;
  ansb = 1000;
  
  vector<int> p(n);
  
  for(int i = 0; i < n; i++){
    cin >> p.at(i);
  }
  
  if(n==0){
    cout << x << endl;
  }
  else if(vector_finder(p,x)==0){
    cout << x << endl;
  }
  else{
    for(int i = 1; i < x; i++){
      if(vector_finder(p,i)==0){
        ansa = i;
      }
    }
    for(int i = x+1; i < 100; i++){
      if(vector_finder(p,i)==0){
        ansb = i;
        break;
      }
    }
    
    if(ansa==-1000 && ansb==1000){
      if(x<=101-x){
        cout << 0 << endl;
      }
      else{
        cout << 101 << endl;
      }
    }
    else if(ansa==-1000 && ansb!=1000){
      if(x<=ansb-x){
        cout << 0 << endl;
      }
      else{
        cout << ansb << endl;
      }
    }
    else if(ansa!=-1000 && ansb==1000){
      if(x-ansa<=101-x){
        cout << ansa << endl;
      }
      else{
        cout << 101 << endl;
      }
    }
    else if((x-ansa)<=(ansb-x)){
    cout << ansa << endl;
    }
    else{
      cout << ansb << endl;
    }
    
  }
}

Measured memory_bytes: 3632
#include<stdio.h>

int main(void)
{
  //nを入力
  int n;
  scanf("%d",&n);

  
  int i,w[n];
  for(i=0;i<n;i++)
    scanf("%d",&w[i]);

  int t,s1,s2,sub,ans=100;
  for(t=0;t<n;t++){
    s1 = 0;  s2 = 0;

    for(i=0;i<n;i++){
      
      if(t>=i)
        s1 += w[i];
      else
        s2 += w[i];
    }

    
    sub = s1-s2;
    if(sub<0)
      sub = -sub;

      if(sub<ans)
      ans = sub;
  }

  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

class Program
{
    static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
    static Scan sc = new Scan();
    static void Main()
    {
        var a = sc.IntArr;
        Prt(a.Sum() - a.Max());
        sw.Flush();
    }
    static void Prt(string a) { sw.WriteLine(a); }
    static void Prt<T>(IEnumerable<T> a) { Prt(string.Join(" ", a)); }
    static void Prt(params object[] a) { Prt(string.Join(" ", a)); }
}
class Scan
{
    public int Int { get { return int.Parse(Str); } }
    public long Long { get { return long.Parse(Str); } }
    public double Double { get { return double.Parse(Str); } }
    public string Str { get { return Console.ReadLine().Trim(); } }
    public int[] IntArr { get { return StrArr.Select(int.Parse).ToArray(); } }
    public long[] LongArr { get { return StrArr.Select(long.Parse).ToArray(); } }
    public double[] DoubleArr { get { return StrArr.Select(double.Parse).ToArray(); } }
    public string[] StrArr { get { return Str.Split(new []{' '}, System.StringSplitOptions.RemoveEmptyEntries); } }
}


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

//#pragma gcc optimize("O3,unroll-loop")
//#pragma gcc target("sse,sse2,sse3,ssse3,sse4,avx,avx2,fma,abm,mmx,popcnt,tune=native")
//#define int long long
//#define double long double

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

    string a, b;
    cin >> a >> b;

    int ans = 1e9;
    for (int i = 0; i + b.size() <= a.size(); i++)
    {
        int cnt = 0;
        for (int j = 0; j < b.size(); j++)
            cnt += (a[i + j] != b[j]);
        ans = min(ans, cnt);
    }
    cout << ans << '\n';

    return 0;
}

//      *   *  *****  *   *  *   *   ****  ****    ****     **    **
//     *   *  *      **  *  *   *  *      *   *  *        * *   * *
//    *****  *****  * * *  *   *  *      ****   *       *  *     *
//   *   *      *  *  **  *   *  *      *  *   *       *****    *
//  *   *  *****  *   *   ***    ****  *   *    ****     *   *****

//      *****  *****  *   *  *      *****  *   *  *****  *****
//        *   *   *  *   *  *        *    **  *    *    *   *
//       *   *   *  *****  *        *    * * *    *    *****
//   *  *   *   *    *    *        *    *  **    *    *
//  ****   *****    *    *****  *****  *   *    *    *


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

using namespace std;

struct Point {
	double x, y, z;

	friend istream& operator>>(istream& is, Point& p) {
		is >> p.x >> p.y >> p.z;
		return is;
	}

	double abs() { return sqrt(x * x + y * y + z * z); }
};

double dot(Point a, Point b) { 
	return a.x * b.x + a.y * b.y + a.z * b.z;
}

int main() {
	int n, m;
	while (cin >> n, n) {
		vector<Point> s(n);
		for (int i = 0; i < n; ++i) cin >> s[i];
		cin >> m;
		vector<Point> t1(m);
		vector<double> t2(m);
		for (int i = 0; i < m; ++i) cin >> t1[i] >> t2[i];
		int ans = 0;
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < m; ++j) {
				if (acos(dot(s[i], t1[j]) / s[i].abs() / t1[j].abs()) <= t2[j]) {
					ans++;
					break;
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 3376
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
      
      Scanner sc = new Scanner(System.in);
      
      int array[] = new int[3];
      array[0] = sc.nextInt();
      array[1] = sc.nextInt();
      array[2] = sc.nextInt();
      int x;

      x = array[0] - array[1] - array[2];
      if(x < 0){
        x = Math.abs(x);
      } else {
        x = 0;
      }
      System.out.println(x);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
ll LCM(ll a, ll b){
    return a/GCD(a,b)*b;
}
int main(){
    int N;
    cin>>N;
    string s;
    cin>>s;
    int ans=0;
    rep(i,N){
        if(i+1<N && s[i]==s[i+1]){
            int j=i+1;
            while(s[i]==s[j] && j<N){
                j++;
            }
            i=j-1;
            ans++;
        }else{
            ans++;
        }
    }
    cout<<ans<<endl;
}

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

int main()
{
    long long n;
    long long m;
    long long q;
    cin >> n >> m >> q;
    long l[m];
    long r[m];
    long pp[m];
    long qq[m];
    
    long ta[n+1][n+1];
    for(int i=0; i<n+1; i++){
        for(int j=0;j<n+1;j++){
            ta[i][j]=0;
        }
    }
    for(int i=0;i<m;i++){
        cin >> l[i] >> r[i] ;
    }
    for(int i=0;i<q;i++){
        cin >> pp[i] >> qq[i] ;
    }
    for(int k =0; k<m; k++){
        for(int i=r[k];i<=n;i++){
            ta[l[k]][i] +=1;
        }
    }
    /*
        for (int i=0; i<=n;i++){
            for (int j=0; j<=n;j++){
//                cout << ta[i][j] ;
            }
        }
    */
    long answer =0;
    for (int i =0;i<q;i++){
        answer = 0;
        for(int j = pp[i]; j<=qq[i];j++){
            answer += ta[j][qq[i]] - ta[j][pp[i]-1];
        }

        cout << answer <<endl;
    }
}



Measured memory_bytes: 9088
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    N = int(input())
    W = list(map(int, input().split()))
    S = [0 for _ in range(N)]
    S[0] = W[0]
    for i in range(1, N):
        S[i] = S[i-1] + W[i]

    n = 1000
    for i in range(1, N):
        n = min(n, abs(S[i] - (S[N-1]-S[i])))
    print(n)

main()


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

int main(){
  vector<int> a{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;
  
  cout << a[k - 1];
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define abs(a) ((a)<0 ? -(a) : (a))

int main(){
  long long int x, y;  scanf("%lld%lld", &x, &y);
  long long int ans = 0;
  if(abs(y) - abs(x) > 0){
    if((x >= 0 && y >= 0) || (x < 0 && y < 0)){
      ans = abs(y) - abs(x) + (x<0 ? 2 : 0) + (y==0 ? -1 : 0);
    }else{
      ans = abs(y) - abs(x) + 1;
    }
  }else if(abs(y) == abs(x)){
    ans = ((x>=0 && y>=0) || (x<0 && y<0)) ? 0 : 1;
  }else{
    if(x >= 0 && y >= 0){
      ans = abs(x) - abs(y) + 2 + (y==0 ? -1 : 0);
    }else if(x < 0 && y < 0){
      ans = abs(x) - abs(y);
    }else{
      ans = abs(x) - abs(y) + (y==0 ? 0 : 1);
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 128
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const [A, B, C] = input[0];

  return A[A.length - 1] === B[0] && B[B.length - 1] === C[0] ? "YES" : "NO";
};

console.log(main(read()));


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

int main() {
	int n; cin>>n;
	string s[n]; int a[n],p[n];
	for(int i=0;i<n;i++) {
		cin>>s[i]>>p[i]; a[i]=i+1;
	}
	for(int i=0;i<n;i++) {
		for(int j=0;j<i;j++) {
			if(s[j]>s[i]) {
				string temp;
				temp=s[j]; s[j]=s[i]; s[i]=temp;
				int t; t=a[i]; a[i]=a[j]; a[j]=t;
				t=p[i]; p[i]=p[j]; p[j]=t;
			}
			if(s[j]==s[i]) {
				if(p[j]<p[i]) {
					string temp;
					temp=s[j]; s[j]=s[i]; s[i]=temp;
					int t; t=a[i]; a[i]=a[j]; a[j]=t;
					t=p[i]; p[i]=p[j]; p[j]=t;
				}
			}
		}
	}
	for(int i=0;i<n;i++) cout<<a[i]<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] r = new int[n];
		for(int i = 0; i < m; i++){
		    int a = sc.nextInt()-1;
		    int b = sc.nextInt()-1;
		    r[a]++;
		    r[b]++;
		}
		
		
		// 計算
		//String result = "No";
		
		// 出力
		for(int i = 0; i < n; i++){
		    System.out.println(r[i]);
		}
		//System.out.println(result);
	}
}


Measured memory_bytes: 23120
#include<bits/stdc++.h>
#define N 1005
using namespace std;
int n,m,sum,a[N];
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    cin>>m;
    while(m--){
        int p,x;
        cin>>p>>x;
        cout<<sum-a[p]+x<<endl;
    }
    return 0;
}

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

int puzzle[9][9];
 
void field(int x, int &to, int &from)
{
    if (0 <= x && x < 3) {
	to = 0;
	from = 3;
    } else if (3 <= x && x < 6) {
	to = 3;
	from = 6;
    } else {
	to = 6;
	from = 9;
    }
}
 
bool check1(int x, int y)
{
    for (int i = x-1; i >= 0; i--) {
	if (puzzle[x][y] == puzzle[i][y]) return 0;
    }
    for (int i = x+1; i < 9; i++) {
	if (puzzle[x][y] == puzzle[i][y]) return 0;
    }
    return 1;
}
 
bool check2(int x, int y)
{
    for (int i = y-1; i >= 0; i--) {
	if (puzzle[x][y] == puzzle[x][i]) return 0;
    }
    for (int i = y+1; i < 9; i++) {
	if (puzzle[x][y] == puzzle[x][i]) return 0;
    }
    return 1;
}
 
bool check3(int x, int y)
{
    int sx, tx, sy, ty;
 
    field(x, sx, tx);
    field(y, sy, ty);
    for (int i = sx; i < tx; i++) {
	for (int j = sy; j < ty; j++) {  
	    if (x == i && y == j) continue;
	    if (puzzle[x][y] == puzzle[i][j]) return 0;
	}
    }
    return 1;
}
 
int main()
{
    int T;
 
    cin >> T;
    for (int t = 0; t < T; t++) {
	if(t) cout << endl;
	for (int i = 0; i < 9; i++) {
	    for (int j = 0; j < 9; j++) {
		cin >> puzzle[i][j];
	    }
	}
 	char ch[9][9];
	for (int i = 0; i < 9; i++) {
	    for (int j = 0; j < 9; j++) {
		ch[i][j] = ' ';
	    }
	}
 	for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9; j++) {
		if (check1(i, j) && check2(i, j) && check3(i, j)) continue;
		ch[i][j] = '*';
	    }
	}
        for (int i = 0; i < 9; i++) {
	    for (int j = 0; j < 9; j++) {
		cout << ch[i][j] << puzzle[i][j];
	    }
	    cout << endl;
	}
    }
    return 0;
}

Measured memory_bytes: 3076
K, N = map(int,input().split())
A = list(map(int,input().split()))

max_result = A[0]+K-A[N-1]

for i in range (N-1):
    
    before = A[i]
    after = A[i+1]
    diff = after - before
    if diff>=max_result:
        max_result = diff

print(K-max_result)

Measured memory_bytes: 26444
from collections import deque

N,Q=map(int,input().split())
E={i:set() for i in range(1,N+1)}
for _ in range(N-1):
    a,b=map(int,input().split())
    E[a].add(b)
    E[b].add(a)

F=[0]*(N+1)
for _ in range(Q):
    p,x=map(int,input().split())
    F[p]+=x

T=[False]*(N+1)
T[1]=True
R=deque([1])

G=[0]*(N+1)
G[1]=F[1]
while R:
    u=R.popleft()
    for v in E[u]:
        if not T[v]:
            G[v]=G[u]+F[v]
            T[v]=True
            R.append(v)

for i in range(1,N+1):
    print(G[i])


Measured memory_bytes: 178520
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL K;

LL ans = 0;

void solve(){
	set<LL> lunlun[11];//i桁のルンルン数をlunlun[i]に格納する
	for(LL i=1;i<=9;i++){
		lunlun[1].insert(i);
	}
	//ばらまくイメージ
	for(LL d=1;d<=9;d++){
		for(LL num : lunlun[d]){
			LL tail = num%10;
			LL basenum = num*10;
			if(tail-1>=0) lunlun[d+1].insert(basenum + tail - 1);
			lunlun[d+1].insert(basenum + tail);
			if(tail+1<=9) lunlun[d+1].insert(basenum + tail + 1);
		}
	}
	LL lunlun_index_accum[11];
	lunlun_index_accum[0] = 1;
	for(int i=1;i<=10;i++){
		lunlun_index_accum[i] = lunlun_index_accum[i-1] + lunlun[i].size();
	}
	for(int i=1;i<=10;i++){
		if(K - lunlun_index_accum[i]<0){
			auto iter = lunlun[i].begin();
			for(int a=0;a<K-lunlun_index_accum[i-1];a++){
				iter++;
			}
			ans = *iter;
			break;
		}
	}
}

int main(){
    cin >> K;
 
    solve();

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

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

using namespace std;

#define ios         ios_base::sync_with_stdio(false);
#define ll          long long
#define ld          long double
#define db(x)       cout << "[" << #x << ": " << (x) << "]\n"
#define db2(x,y)    cout << "[" << #x << ": " << (x) << "]  [" << #y << ": " << (y) << "]\n"
#define db3(x,y,z)  cout << "[" << #x << ": " << (x) << "]  [" << #y << ": " << (y) << "]  [" << #z << ": " << (z) << "]\n"
#define cn          107
#define sn          1007
#define bn          200007
#define M           1000000007
#define inf         LLONG_MAX



int main()
{
        ios;
        ll n; cin >> n;
        string s; cin >> s;
        if(n%2) { cout << "No"; exit(0);}
        for(ll i = 0; i < n/2; i++)
        {
                if(s[i] == s[i+n/2]) continue;
                cout << "No"; exit(0);
        }
        cout << "Yes";
}



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

using namespace std;
int n, a[350];
double f[305][305][305];

double fDP(int x, int y, int z, int n){
    
    if(x<0 || y<0 || z<0) {
        return 0;
    }
    if(x==0 && y==0 && z==0){
        return 0;
    }
    if(f[x][y][z] > 0){
        return f[x][y][z];
    }
    int N = x + y + z;
    
    double val = n + x * fDP(x-1,y,z,n) + y * fDP(x+1, y-1, z,n) + z * fDP(x, y+1, z-1, n);
    
    f[x][y][z] = val*(1.0) / N;
    
    return f[x][y][z];
}

/*double f(int x, int y, int z, int n){ //recrusvie
    if(x<0 || y<0 || z<0){
        return 0.0;
    }
    if(x==0 && y==0 && z==0){
        return 0.0;
    } 
    double p0, p1, p2, p3;

    p0 = (n - x - y - z)*(1.0) / n;
    p1 = x * (1.0) / n;
    p2 = y * (1.0) / n;
    p3 = z * (1.0) / n;
    // cout <<p0<<" "<<p1<< " "<<p2 << " "<<p3 << "\n";
    
    return (1+(f(x-1,y,z,n)*p1 + f(x+1,y-1,z,n)*p2 + f(x,y+1,z-1,n)*p3)*(1.0)) / (1 - p0);
 }
*/

int main() {
    int n;
    scanf("%d", &n);
    int x, y, z; x = y = z = 0;
    for(int i = 1; i<=n; i++){
        cin >> a[i];
        if(a[i] == 1) x++;
        else if(a[i] == 2) y++;
        else z++;
    }
    // cout << x << " " << y << " " << z << "\n";
    double answer = fDP(x,y,z,n);
    printf("%.10lf\n", answer);
}

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

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  if(A==B && A!=C){
    cout << "Yes" << endl;
    return 0;
  }
  if(A==C && A!=B){
    cout << "Yes" << endl;
    return 0;
  }
  if(B==C && A!=B){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
startWith :: String -> String -> Bool
startWith [] _ = True
startWith _ [] = False
startWith (x:xs) (y:ys) | x /= y = False
                        | otherwise = startWith xs ys

solv' :: Int -> Int-> String -> String -> Bool
solv' i n x y | i > n = False
              | (startWith x y) = True
              | otherwise = solv' (i+1) n x (tail y)

solv :: String -> String -> String
solv x y | solv' 0 (length y) x (y++y) = "Yes"
         | otherwise = "No"

main = do
  r <- getLine
  c <- getLine
  putStrLn $ solv c r

Measured memory_bytes: 3548
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	int n, m, i, j, k, x, y;
	cin >> n >> m;
	vector<string> s(n);
	for (i = 0; i < n; i++) cin >> s[i];
	vector<vector<bool>> b(n, vector<bool>(m, false));
	b[0][0] = true; 
	x = 0; y = 0;
	while (1) {
		if ((x < n - 1) && (s[x + 1][y] == '#')) {
			b[x + 1][y] = true;
			x++;
			continue;
		}
		if ((y < m - 1) && (s[x][y + 1] == '#')) {
			b[x][y + 1] = true;
			y++;
			continue;
		}
		break;
	}


	bool valid = true;
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			if ((s[i][j] == '#') && (!b[i][j])) valid = false;
		}
	}
	if (valid) cout << "Possible\n";
	else cout << "Impossible\n";

	return 0;
}


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

using ll    = long long;
using ull   = unsigned long long;
using veci  = vector<int>;
using vecll = vector<ll>;
#define EPS (1e-7)
#define INF (1e9)
#define PI  (acos(-1))
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define REP(i,n) for(int i= 0;i<(int)(n);++i)
#define pb push_back

veci enum_div(int n){
	veci ret;
	ret.pb(1);
	for(int i=1;i*i<n;i++){
		if(n%i==0){
			ret.pb(i);
			if(i != n/i){ret.pb(n/i);}
		}
	}
	ret.pb(n);
	return ret;
}
int gcb(int a,int b){return ((b == 0)? a : gcb(b,a%b));}
int gcd(int a,int b){return (a*b) / gcb(a,b);}

int main(){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    if(s == "abc"){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int A, B, sum, sub, mul;
    cin >> A >> B;
    sum = A + B;
    sub = A - B;
    mul = A * B;
    if(sum == sub && A > 0)
        cout << sum;
    else if(sum == sub && A < 0)
        cout << mul;
    else if(sum > sub && sum > mul)
        cout << sum;
    else if(sub > sum && sub > mul)
        cout << sub;
    else
        cout << mul;
    return 0;
}

Measured memory_bytes: 256
let n = read_int ()
let ss, cs, a_s = Array.(make (n + 1) 0, make (n + 1) 0, init n @@ fun _ -> Scanf.scanf " %d" (+) 0)
let g n i = if i < n then ss.(i) <- ss.(i) + 1
let f g n = let rec f i = if i * i <= n then (if n mod i = 0 then (g n i; if i <> n / i then g n (n / i)); f (i + 1)) in f 1
let _ = for i = n downto 1 do if n / i = 1 then cs.(i) <- a_s.(i - 1) else if ss.(i) mod 2 <> a_s.(i - 1) then cs.(i) <- 1; if cs.(i) = 1 then f g i done; Array.(print_int (fold_left (+) 0 cs); iteri (fun i c -> if c = 1 then Printf.printf (if i = 1 then "\n%d" else " %d") i) cs); print_newline ()

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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define All(v) (v).begin(), (v).end()
#define Pb(i) push_back(i)

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

    string s1,s2,s3;
    cin >> s1 >> s2 >> s3;
    cout << s1[0] << s2[0] << s3[0];
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > 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; }
const ll INF = 1e9;


int main(){
    ll n,m;
    cin >> n >> m;
    ll ans = 0;
    ans += min(n,m/2);
    n-=ans;m-=ans*2;
    if(n){
        cout << ans << endl;
        return 0;
    }
    ans += m/4;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long int;
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; }
const ll INF = 1e10;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;

int main() {
    int a,b = 10,c = 0;
    rep(i,5) {
        cin >> a;
        if (a%10 != 0){
            chmin(b,a%10);
            a = (a/10+1)*10;
        }
        c += a;
    }
    PRINT(c-10+b);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(ll i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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 Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;


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

	ll n;
	cin >> n;
	vector<ll> a(n);
	vector<vector<ll>> k(n, vector<ll>(100,0));
	vector<ll> kk(100);
	rep(i, n)
	{
		cin >> a[i];
		ll tmp = a[i];
		ll j = 0;
		while (tmp)
		{
			k[i][j]=(tmp % 2);
			tmp /= 2;
			kk[j] += k[i][j];
			j++;
		}
	}

	for (ll i = 0; i < n; i++)
	{
		ll ans = 0;
		for (int j = 99; j >= 0; j--)
		{
			if (kk[j] % 2)
			{
				if (k[i][j] == 1)
				{
					ans += 0LL << j;
				}
				else
				{
					ans += 1LL << j;
				}
			}
			else
			{
				if (k[i][j] == 1)
				{
					ans += 1LL << j;
				}
				else
				{
					ans += 0LL << j;
				}
			}
		}
		if (i != n - 1)
			cout << ans << " ";
		else
			cout << ans << endl;
	}


	return 0;
}

Measured memory_bytes: 168996
import itertools

A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = []
for _ in range(N):
    b = int(input())
    B.append(b)

hit = []
for i in range(3):
    hit.append((A[i][0], A[i][1], A[i][2]))
    hit.append((A[0][i], A[1][i], A[2][i]))
hit.append((A[0][0], A[1][1], A[2][2]))
hit.append((A[0][2], A[1][1], A[2][0]))

yes = False
for p in itertools.permutations(B, 3):
    if p in hit:
        print("Yes")
        yes = True
        exit()

if not yes:
    print("No")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int main(){
	int n;
	int q;
	cin >> n >> q;
	vector<LL > c;
	for(int i = 0; i < q; i++){
		LL a;
		cin >> a;
		c.push_back(a);
	}
	LL m = 2e18;
	vector<LL> b;
	for(int i = q-1; i >= 0; i--){
		if(c[i] < m){
			b.push_back(c[i]);
			m = c[i];
		}
	}
	if(n < m){
		b.push_back(n);
		m = n;
	}
	map<LL,LL> freq;
	freq[b[0]] = 1;
	//cout << b[0] << endl;
	for(int i = 1; i < b.size(); i++){
		/*for(map<LL,LL>::iterator it = freq.begin(); it != freq.end(); it++){
			cout << it->first << " " << it->second << endl;
		}*/
		while(freq.rbegin()->first > b[i]){
			LL d = freq.rbegin()->first;
			//cout << b[i] << " " << d << endl;
			LL a = freq.rbegin()->second;
			//cout << d << " " << a << " " << endl;
			freq[b[i]] += (d/b[i])*a;
			freq[d%b[i]] += a;
			freq[d] = 0;
			freq.erase(d);
		}
	}
	LL diff[n+5];
	for(int i = 0; i <= n+3; i++){
		diff[i] = 0;
	}
	/*for(map<LL,LL>::iterator it = freq.begin(); it != freq.end(); it++){
		cout << it->first << " " << it->second << endl;
	}*/
	while(!freq.empty() && freq.rbegin()->first > 0){
		LL d = freq.rbegin()->first;
		LL a = freq.rbegin()->second;
		diff[d] += a;
		freq[d] = 0;
		freq.erase(d);
	}
	for(int i = m; i >= 1; i--){
		diff[i] = diff[i] + diff[i+1];
	}
	for(int i = 1; i <= n; i++){
		cout << diff[i] << endl;
	}
}


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


int main() {
  int N, M;
  cin >> N >> M;
  vector<int> count(N);
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    count.at(x - 1) = count.at(x - 1) + 1;
    count.at(y - 1) = count.at(y - 1) + 1;
  }
  for (int i = 0; i < N; i++) {
    cout << count.at(i) << endl;
  }

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>

using namespace std;


int main()
{
	int r;
	int ans;

	cin >> r;	

	ans = 3 * r * r;

	printf("%d",ans);


	//printf("No");


	return 0;
}



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

class Program
{
	static void Main(string[] args)
	{
        int n = int.Parse(Console.ReadLine());
        int[] a = new int[n];
        string[] s = Console.ReadLine().Split(' ');

		for (int i = 0; i < n; i++)
		{
            a[i] = int.Parse(s[i]);
        }

		for (int k = 0; k < n-1; k++)
		{
			Console.Write("{0} ", a[k]);
		}

        Console.WriteLine("{0}", a[n - 1]);

        for (int i = 1; i < n;i++)
        {
            int v = a[i];
            int j = i - 1;
            while(j>=0&&a[j]>v)
            {
                a[j + 1] = a[j];
                j--;
            }
            a[j + 1] = v;

			for (int k = 0; k < n-1; k++)
			{
                Console.Write("{0} ",a[k] );

			}
            Console.WriteLine("{0}", a[n-1]);
        }

		

	}
}

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

int main() {
    string s;
    cin >> s;
    int len = s.length();
    int tot=0, l=0;
    rep(i,0,len) {
        if (s[i]=='A' or s[i]=='T' or s[i]=='C' or s[i]=='G' ) 
            l++;
        else l=0;
        tot = max(l,tot);
    }
    cout << tot << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n;
int seq[100010];
int skip[100010];
bool visit[100010];
bool checked[100010];

int Skip(int x) {
  if (skip[x] != -1) { return skip[x]; }
  if (checked[x]) { return skip[x] = -2; }
  checked[x] = true;
  return skip[x] = seq[x] == 0 ? x : Skip(x + seq[x]);
}

int main() {
  while (scanf("%d", &n) > 0) {
    MEMSET(skip, -1);
    MEMSET(visit, false);
    MEMSET(checked, false);
    REP(i, n) {
      scanf("%d", &seq[i]);
    }
    queue<pair<int, int> > que;
    que.push(make_pair(Skip(0), 0));
    visit[Skip(0)] = true;
    while (!que.empty()) {
      int x = que.front().first;
      int cost = que.front().second;
      que.pop();
      if (x == n - 1) {
        printf("%d\n", cost);
        break;
      }
      FOREQ(i, 1, 6) {
        int nx = min(Skip(x + i), n - 1);
        if (nx == -2) { continue; }
        if (visit[nx]) { continue; }
        visit[nx] = true;
        que.push(make_pair(nx, cost + 1));
      }
    }
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,m,ans;
int tmp,tmp2;
int main(){
	scanf("%lld%lld",&n,&m);
	if (n==m) return puts("1"),0;
	for (int i=0;i<=60;i++)
		if (((n>>i)&1)^((m>>i)&1)) tmp=i;
	n&=(1ll<<(tmp+1))-1;
	m&=(1ll<<(tmp+1))-1;
	ll ans=(1ll<<(tmp+1))-n;
	for (int i=0;i<tmp;i++)
		if (m&(1ll<<i)) tmp2=i+1;
	if (n>(1ll<<tmp2)-1)
		ans-=(n-(1ll<<tmp2));
	printf("%lld\n",ans);
}

Measured memory_bytes: 256
def sides(a,b,c):
  if a + b > c:
    return True
  return False
res = 0
N = int(input())
nums = list(map(int,input().split()))
nums = sorted(nums)
for x in range(N-2):
  for y in range(x+1,N-1):
    for z in range(y+1,N):
      if nums[x] != nums[y] and nums[x] != nums[z] and nums[y] != nums[z] and sides(nums[x],nums[y],nums[z]):
        res += 1
print(res)

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using namespace std;
int main(){
	int d,e,f,a,b,c,q,ans=0;
	cin>>a>>b>>c>>q;
	for(d=0;d<=a;d++)
	for(e=0;e<=b;e++)
	for(f=0;f<=c;f++){
		if(d*500+e*100+f*50==q) ans++; 
	}		
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <deque>

using namespace std;

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

const ll N = 1010;
const ll INF = 1e9;
const ll dx[] = { 1, 0, -1, 0 };
const ll dy[] = { 0, -1, 0, 1 };

ll h, w;
ll sx, sy, tx, ty;
char c[N][N];
ll dist[N][N];

void bfs01() {
	deque<PLL> q;
	q.push_back(make_pair(sx, sy));

	for (ll y = 1; y <= h; y++) {
		for (ll x = 1; x <= w; x++) {
			dist[x][y] = INF;
		}
	}

	dist[sx][sy] = 0;

	while (q.size()) {
		ll x = q.front().first, y = q.front().second; q.pop_front();

		for (ll i = 0; i < 4; i++) {
			ll nx = x + dx[i], ny = y + dy[i];
			
			if (nx <= 0 || nx > w || ny <= 0 || ny > h) {
				continue;
			}

			if (c[nx][ny] != '.') {
				continue;
			}

			if (dist[nx][ny] > dist[x][y]) {
				dist[nx][ny] = dist[x][y];
				q.push_front(make_pair(nx, ny));
			}
		}

		for (ll i = -2; i <= 2; i++) {
			for (ll j = -2; j <= 2; j++) {
				ll nx = x + i, ny = y + j;

				if (nx <= 0 || nx > w || ny <= 0 || ny > h) {
					continue;
				}

				if (c[nx][ny] != '.') {
					continue;
				}

				if (dist[nx][ny] > dist[x][y] + 1) {
					dist[nx][ny] = dist[x][y] + 1;
					q.push_back(make_pair(nx, ny));
				}
			}
		}
	}
}

int main() {
	cin >> h >> w;
	cin >> sy >> sx >> ty >> tx;

	for (ll y = 1; y <= h; y++) {
		for (ll x = 1; x <= w; x++) {
			cin >> c[x][y];
		}
	}

	bfs01();

	if (dist[tx][ty] > INF / 2) {
		cout << "-1" << endl;
	}
	else {
		cout << dist[tx][ty] << endl;
	}

	return 0;
}

Measured memory_bytes: 12520
#!/usr/bin/env python3
n = int(input())
d = list(map(int, input().split()))
m = int(input())
t = list(map(int, input().split()))
d.sort()
t.sort()

idx_d, idx_t = 0, 0
while idx_t < m and idx_d < n:
    if d[idx_d] == t[idx_t]:
        idx_d += 1
        idx_t += 1
    elif d[idx_d] > t[idx_t]:
        print("NO")
        exit()
    else:
        idx_d += 1
if idx_t < m - 1:
    print("NO")
else:
    print("YES")


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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#pragma GCC                   target ("avx2")
#pragma GCC                   optimize("Ofast")
#pragma GCC                   optimization ("O3")
#pragma GCC                   optimization ("unroll-loops")
#pragma GCC                   target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define mod                   1000000007
#define INF                   1000000000000000000
#define int                   long long
#define PI                    3.141592653
#define Author                std::ios_base::sync_with_stdio(0);
#define ABHISHEK_SHARMA       cout.tie(0);
#define IIIT_ALLAHABAD        cin.tie(0);
#define all(v)                v.begin(),v.end()
#define pb(a)                 push_back(a)
#define lb(v,t)               lower_bound(all(v),t)-v.begin()
#define ub(v,t)               upper_bound(all(v),t)-v.begin()

clock_t time_p=clock();

void abhishhh1(){
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(double)(time_p)/(1.0*CLOCKS_PER_SEC)<<"\n";
}

void solve() {
    int n, k;
    cin>>n>>k;
    vector<int>v;
    int mp[n+1];
    memset(mp,0,sizeof(mp));
    int a[n+1];
    for(int i=1; i<=n; i++){
        cin>>a[i];
    }
    v.push_back(1);
    mp[1]=1;
    int counter=0, index;
    while(true){
        int next=a[v[counter]];
        counter++;
        if(counter==k){
            cout<<next<<"\n";
            return;
        }
        if(mp[next]!=0){
            index=mp[next];
            break;
        }
        else{
            mp[next]=counter+1;
            v.push_back(next);
        }
    }
    k-=(index-1);
    int loop=counter-index+1;
    int rest=k%loop;
    cout<<v[index+rest-1]<<"\n";
}

signed main(){
    //file reader-writer

    //Booster
    Author
    ABHISHEK_SHARMA
    IIIT_ALLAHABAD
    //Driver Code here
    int t=1;
    //cin>>t;
    for(int i=1; i<=t; i++){
        //cout<<"Case #"<<i<<": ";
        solve();
    }
    abhishhh1();
}

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

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,d1,d2;
	cin >> n >> d1 >> d2;
	vector<int> sqrt(4 * n * n,-1);
	for (int i = 0;i < 2 * n;i++) {
		sqrt[i * i] = i;
	}
	vector<vector<int>> alive(2 * n,vector<int>(2 * n,1));
	auto solve = [&](int d) {
		vector<vector<int>> dead(2 * n,vector<int>(2 * n,0));
		for (int i = 0;i < 2 * n;i++) {
			for (int j = 0;j < 2 * n;j++) {
				if (!alive[i][j] || dead[i][j]) continue;
				vector<pair<int,int>> pq = {make_pair(i,j)};
				dead[i][j] = 1;
				for (int i = 0;i < (int)pq.size();i++) {
					pair<int,int> now = pq[i];
					for (int nx = 0;nx < 2 * n;nx++) {
						int D = d - (now.first - nx) * (now.first - nx);
						if (D >= 0 && D < 4 * n * n && sqrt[D] != -1) {
							D = sqrt[D];
							int ny = now.second - D;
							if (ny >= 0 && ny < 2 * n && alive[nx][ny] && !dead[nx][ny]) {
								pq.emplace_back(nx,ny);
								dead[nx][ny] = 3 - dead[now.first][now.second];
							}
							if (D) {
								ny = now.second + D;
								if (ny >= 0 && ny < 2 * n && alive[nx][ny] && !dead[nx][ny]) {
									pq.emplace_back(nx,ny);
									dead[nx][ny] = 3 - dead[now.first][now.second];
								}
							}
						}
					}
				}
				vector<int> cnt(4);
				for (auto&x : pq) cnt[dead[x.first][x.second]]++;
				int cc = cnt[1] > cnt[2] ? 1 : 2;
				for (auto&x : pq) {
					if (dead[x.first][x.second] != cc) {
						alive[x.first][x.second] = 0;
					}
				}
			}
		}
	};
	solve(d1);solve(d2);
	int rem = n * n;
	for (int i = 0;i < 2 * n;i++) {
		for (int j = 0;j < 2 * n;j++) {
			//cout << alive[i][j] <<" ";
			if (alive[i][j] && rem) {
				--rem;
				cout << i <<" " << j <<"\n";
			}
		}
		//cout << endl;
	}
	assert(!rem);
}

Measured memory_bytes: 10480
from collections import deque

def main():
    N = int(input())
    path = [[] for _ in range(N)]
    ab = []
    ans = {}
    visited = [False] * N
    visited[0] = True
    for _ in range(N-1):
        a, b = map(int, input().split())
        path[a-1].append(b-1)
        # path[b-1].append(a-1)
        ab.append((a-1, b-1))
    
    que = deque([(0, 0)])
    while que:
        k = 1
        pre, c = que.popleft()
        for next_node in path[pre]:
            if visited[next_node]:
                continue
            
            if c == k:
                k += 1
            visited[next_node] = True
            ans[(pre, next_node)] = k
            que.append((next_node, k))
            k += 1
            

    print(max(ans.values()))
    for key in ab:
        print(ans[key])

if __name__ == '__main__':
    main()

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

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<long long,long long> pll;

#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define int long long
#define sz(v) (int)v.size()
#define inf 2147483647
#define llinf 9223372036854775807
#define all(v) v.begin(),v.end()
#define bp(n) __builtin_popcountll(n)
#define f(i,l,r) for(long long i=l;i<=r;i++)
#define rf(i,r,l) for(long long i=r;i>=l;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }


const int N=1e5+5,mod=1e9+7,bit=61;

int dp[N];
int a[101];
int n,k;

int solve(int stones)
{
    if(stones < a[1])
    {
        return 0;
    }
    assert(stones >= 0);
    int &ans=dp[stones];
    if(ans!=-1)
    {
        return ans;
    }
    ans=0;
    for(int i=1;i<=n;i++)
    {
        if(stones - a[i] < 0)
        {
            continue;
        }
        if(solve(stones-a[i])==0)
        {
            ans=1;
            break;
        }
    }
    return ans;
}

signed main()
{
    fast;

    int t=1;
    //cin>>t;
    while(t--)
    {
        cin>>n>>k;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        memset(dp,-1,sizeof(dp));
        if(solve(k))
        {
            cout<<"First"<<endl;
        }
        else
        {
            cout<<"Second"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 9056
import numpy as np

N, K = map(int, input().split())

times = np.zeros(N + 1, dtype=np.float)

for i in range(1, N + 1):
	if i < K:
		times[i] = np.ceil(np.log2(K / i))
	else:
		times[i] = 0


print(np.sum(0.5 ** times[1:] / N))


Measured memory_bytes: 14812
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int MAXN=1e5;
char s[MAXN];

int main()
{
    while(scanf("%s",s+1)!=EOF)
    {
        int len=strlen(s+1);
        int ans=len;
        for(int i=1;i<len;i++)
        {
            if(s[i]!=s[i+1])
                ans=min(ans,max(i,len-i));
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 384