akhauriyash/Code-Regression huggingface dataset:
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;// 998244353;// ;
constexpr long long INF = numeric_limits<LL>::max() / 2;
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourd; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<vector<LL>>g;
vector<edge>edges;
vector<LL>v;
map<LL, LL>ma;
set<Pll>st;
LL h, w, n, m, k, t, s, p, q, last, cnt, sum, ans, dp[210000],a[210000], b[210000];
string str, ss;
bool f;
char c;
vector<LL> kossaraju(vector<vector<LL>>&g) {
	LL n = g.size();
	vector<vector<LL>>rev(n);
	vector<LL>ret(n);
	vector<LL>ver;
	vector<bool>used(n);
	function<void(LL)>dfs1 = [&](LL cur) {
		used[cur] = 1;
		rep(i, g[cur].size()) {
			if (!used[g[cur][i]])
				dfs1(g[cur][i]);
		}
		ver.push_back(cur);
	};
	function<void(LL, LL)>dfs2 = [&](LL cur, LL root) {
		used[cur] = 1;
		ret[cur] = root;
		rep(i, rev[cur].size()) {
			if (!used[rev[cur][i]])
				dfs2(rev[cur][i], root);
		}
	};
	rep(i, n) rep(j, g[i].size()) rev[g[i][j]].push_back(i);
	rep(i, n) if (!used[i])dfs1(i);
	rep(i, n) used[i] = 0;
	Rrep(i, n)if (!used[ver[i]])dfs2(ver[i], ver[i]);
	return ret;
}
int main() {
	cin >> n>>m;
	g.resize(n);
	rep(i, m) {
		LL x, y;
		cin >> x >> y;
		g[x].push_back(y);
	}
	vector<LL>V = kossaraju(g);
	cin >> q;
	rep(i, q) {
		LL x, y;
		cin >> x >> y;
		if (V[x] == V[y])cout << 1 << endl;
		else cout << 0 << endl;
	}
	return 0;
}


Measured memory_bytes: 5000
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;


int main(){
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    sort(A.begin(),A.end());
    int cntmi = 0;
    ll sum = 0;
    rep(i,N){
        if(A[i] < 0) cntmi++;
        sum += abs(A[i]);
    }
    ll ans = 0;

    if(cntmi == 0){
        ans = sum - 2 * A[0];
        cout << ans << endl;
        rep(i,N-2){
            cout << A[i] << " " << A[i+1] << endl;
            A[i+1] = A[i] - A[i+1];
        }
        cout << A[N-1] << " " << A[N-2] << endl;;
    }
    else if(cntmi != N){
        ans = sum;
        cout << ans << endl;
        int r;
        rep(i,N){
            if(A[i] >= 0){
                r = i;
                break;
            }
        }
        repr(i,r-1,N-2){
            cout << A[i] << " " << A[i+1] << endl;
            A[i+1] = A[i] - A[i+1];
        }
        cout << A[N-1] << " " << A[N-2] << endl;;
        if(cntmi >= 2){
            A[r-1] = A[N-1] - A[N-2];
            for(int i = r-1; i >= 1; i--){
                cout << A[i] << " " << A[i-1] << endl;
                A[i-1] = A[i] - A[i-1];
            }
        }
    }
    else{
        ans = sum + 2 * A[N-1];
        cout << ans << endl;
        for(int i = N-1; i >= 1; i--){
            cout << A[i] << " " << A[i-1] << endl;
            A[i-1] = A[i] - A[i-1];
        }
    }

}


Measured memory_bytes: 2304
x,y = map(int, input().split())

if 4*x < y:
    print("No")
    exit()

if 2*x == y:
    print("Yes")
    exit()
elif 4*x == y:
    print("Yes")
    exit()

if y % 2 != 0:
    print("No")
    exit()
    
a = 2*x
b = 4*x

if a <= y and b >=y:
    print("Yes")
    exit()

print("No")

Measured memory_bytes: 9200
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;

class Sobaya
{
    static void Main(){
      new Sobaya().calc();
      return;
    }
      
    Scanner cin;
    
    void calc(){
        cin = new Scanner();
        string s = cin.next();
        long n = cin.nextInt();
        int l = s.Count();
        List<int> ms = new List<int>();
        int now = 0;
        char prev = s[0];
        while(true){
            if(now == s.Count()) break;
            int temp=0;
            while(true){
                if(now == s.Count()){
                    ms.Add(temp);
                    break;
                }
                if(s[now]!=prev){
                    ms.Add(temp);
                    temp = 0;
                }
                temp++;
                
                

                prev = s[now];
                now++;
            }
        }
        //foreach(int a in ms) Console.WriteLine(a);
        int z = ms.Count;
        if(ms.Count==1){
            Console.WriteLine((n*ms[0])/2);
        }else if(s[0]==s[l-1]){
            long ans=0;
            for(int i=1;i<=z-2;i++){
                ans += (ms[i]/2)*n;
            }
            
            ans += (ms[0]+ms[z-1])/2*(n-1);
            ans += ms[0]/2;
            ans += ms[z-1]/2;
            Console.WriteLine(ans);
        }else{
            long ans=0;
            for(int i=0;i<=z-1;i++){
                ans += (ms[i]/2L)*n;
                //Console.WriteLine((ms[i]/2L)*n);
            }
            Console.WriteLine(ans);
        }
    }
}




class Scanner
{
    string[] s;
    int i;
 
    char[] cs = new char[] { ' ' };
 
    public Scanner()
    {
        s = new string[0];
        i = 0;
    }
 
    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }
 
    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }
 
    public long nextLong()
    {
        return long.Parse(next());
    }
 
    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }
 
    public double nextDouble()
    {
        return double.Parse(next());
    }
 
 
    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 11220
def main():
    import sys
    input = sys.stdin.buffer.readline
    H, W, D = (int(i) for i in input().split())
    A = [[int(i) for i in input().split()] for j in range(H)]
    Q = int(input())
    LR = [[int(i) for i in input().split()] for j in range(Q)]

    B = [0]*(H*W+1)
    pos = {A[i][j]: (i+1, j+1) for i in range(H) for j in range(W)}

    for i in range(D+1, H*W+1):
        y, x = pos[i - D]
        ny, nx = pos[i]
        power = abs(nx - x) + abs(ny - y)
        B[i] = B[i - D] + power

    for le, ri in LR:
        print(B[ri] - B[le])


if __name__ == '__main__':
    main()


Measured memory_bytes: 75356
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

int main(){
  ll N,H,W;
  cin >> N >> H >> W;
  cout << (N+1-H)*(N+1-W) << endl;
}

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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(ALL(a));

    int c = 0;
    while (c < n && x > 0) {
        if (a[c] > x) {
            break;
        }
        x -= a[c];
        c++;
    }

    if (c == n && x != 0) {
        c = max(0, c - 1);
    }

    cout << c << endl;
}


Measured memory_bytes: 256
s = list(input())
f = {
    "N": False,
    "S": False,
    "W": False,
    "E": False
}
for i in s:
    f[i] = True

if (f["N"] ^ f["S"]):
    print("No")
elif (f["W"] ^ f["E"]):
    print("No")
else:
    print("Yes")


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, i, j, ans = 1;
	cin >> n;
	vector<ll> div(n+1, 1);
	for(i=2; i<=n; ++i) {
		div[i]++;
		ans += (div[i])*i;
		for(j=2*i; j<=n; j += i) {
			div[j]++;
		}
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 81308
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
	int [][][]kanri =new int[5][4][11];
	int tou,kai,heya,nin,x;
	Scanner sc = new Scanner(System.in);
	int n=sc.nextInt();
	for(x=1;x<=n;x++){
		tou=sc.nextInt();kai=sc.nextInt();
		heya=sc.nextInt();nin=sc.nextInt();
		kanri[tou][kai][heya]=kanri[tou][kai][heya]+nin;
	}
	for(tou=1;tou<=4;tou++){
		for(kai=1;kai<=3;kai++){
			for(heya=1;heya<=10;heya++){System.out.print(" "+kanri[tou][kai][heya]);}
			if(tou!=4&&kai==3){System.out.print("\n"+"####################");}
			System.out.print("\n");
		}
	}
	}
}

Measured memory_bytes: 21052
s = list(input())
K = int(input())
n = len(s)

s1 = list(set(s.copy()))
s1.sort()
for i in range(5):
  s.append('')

if(len(s1) >=3):  n1 = 3
else:  n1 = len(s1)
first = []
for i in range(n1):
  first.append(s1[i])

s2 = []
for i in range(n):
  for j in first:
    if(s[i] == j):
      s2.append(s[i]),s2.append(s[i]+s[i+1]),s2.append(s[i]+s[i+1]+s[i+2])
      s2.append(s[i]+s[i+1]+s[i+2]+s[i+3]),s2.append(s[i]+s[i+1]+s[i+2]+s[i+3]+s[i+4])
s2 = list(set(s2))
s2.sort()
ans = s2[K-1]
print(ans)

Measured memory_bytes: 4468
n,*q=`dd`.split.map &:to_i;j=[0];n.times{|i|j[q[i]]=i+1};t=f=0;n.downto(2).map{|i|x=j[f];y=j[i-1];z=j[i];(z>y)^(y>x)^(x>z)&&(t+=1)&f=i};p t

Measured memory_bytes: 32164
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	getline(cin,s);
	int len = s.size();
	string left = s.substr(0,(len-1)/2);
	string right = s.substr((len+1)/2,(len-1)/2);
	string s1,left1,right1;
	s1=s;
	left1=left;
	right1=right;
	reverse(s1.begin(), s1.end());
	reverse(left1.begin(), left1.end());
	reverse(right1.begin(), right1.end());
	if(s==s1&&left1==left&&right==right1){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#ifdef LOCAL_EXEC
#include "include.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define trace(...)
#endif

using LL = long long;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	int n, k; cin >> n >> k;

	if (k > (n + 1) / 2) {
		cout << -1 << endl;
		return 0;
	}

	int a = k + n / 2, b = k + 2 * n - 1, c = k + 3 * n - 1;
	for (int i = 0; i < n; i++) {
		cout << a << ' ' << b << ' ' << c << '\n';
		if (a == k + n - 1) {
			a = k;
			b = k + 2 * n - 2;
		} else {
			a++;
			b -= 2;
		}
		c--;
	}

	return 0;
}


Measured memory_bytes: 2304
import java.util.*;
  
public class Main {
    Scanner sc = new Scanner(System.in);
  
    public static void main(String[] args) {
        new Main(); 
    }
  
    public Main() {
        new A().doIt();
    }
    class A{
        void doIt(){
        	long n = sc.nextLong();
        	long num = 3;
        	for(int i = 1;i < 21;i++){
        		if(n <= num){
        			System.out.println(i);
        			break;
        		}
        		num *= 3;
        	}
        }
    }
}

Measured memory_bytes: 26204
#include <stdio.h>

#define N_max 100

int main(){
  int i,j,minj,change,N,array[N_max],count=0;
  
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&array[i]);
  }

  for(i=0;i<N;i++){
    minj = i;
    for(j=i;j<N;j++){
      if(array[j]<array[minj]){
	minj = j;
      }
    }
    if(array[i]==array[minj]){
      continue;
    }
    change = array[i];
    array[i] = array[minj];
    array[minj] = change;
    count++;
  }

  for(i=0;i<N-1;i++){
    printf("%d ",array[i]);
  }
  printf("%d\n",array[N-1]);
  printf("%d\n",count);
  
  return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>

#define rep(i,x) for(int i = 0; i < x; i++)
#define rrep(i,x) for(int i = 1; i <= x; i++)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using ll = long long;
using namespace std;
const int INF = 1001001001;
const ll LINF = 1002003004005006007;

int main(){
    int h, n; cin >> h >> n;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    vector<int> dp(h + 10, INF);
    dp[0] = 0;
    rep(i, n + 1)rep(j, h + 1){
        if (j - a[i] >= 0) dp[j] = min(dp[j], dp[j - a[i]] + b[i]);
        else dp[j] = min(dp[j], b[i]);
    }
    cout << dp[h] << endl;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
//typedef long long int;
const ll M = 1000000007;
ll A, B, C, D, G, H, N, L, K, P, Q, R, W, X, Y, Z;
string S, T;

signed main(){
	std::cin >> N;
	if(N%10==3){std::cout << "bon" << std::endl;}
	else if(N%10==0||N%10==1||N%10==6||N%10==8){std::cout << "pon" << std::endl;}
	else {std::cout << "hon" << std::endl;}
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  if(B < A) {
    ll tmp = B;
    B = A;
    A = tmp;
  }
  ll ans = longinf;
  if((B-A)%2==0) ans = min((B-A)/2, ans);
  ans = min((A+B-1)/2, ans);
  ans = min((2*N-A-B+1)/2, ans);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define ll long long  
#define ld long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define S second
#define F first
#define die() return 0;
 
 
#define md          1000000007
#define fmd         998244353 
#define M           3011
#define N            18
ll exp(ll a,ll b){if(b<0)return 0;ll r=1;while(b){if(b&1)r=r*a%md,r%=md;a=a*a%md;b/=2;}return r;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll F[M],IV[M];

map<pair<ll,ll>,ll>  mp;
int solve(){
    ll n,i,j,k,m,x,y,z;
    cin>>n;
    ll ans=0;
    for(i=0;i<n;++i){
    	cin>>x>>y;
    	if(x==0&&y==0){
    		ans++;
    		continue;
    	}
    	else if(x==0){
    		mp[{0,1}]++;
    	}
    	else if(y==0){
    		mp[{1,0}]++;
    	}
    	else{
    		ll g=gcd(abs(x),abs(y));
    		x/=g;y/=g;
    		ll sign=-1;
    		if((x>0&&y>0)||(x<0&&y<0))sign=1;

    		mp[{abs(x),sign*abs(y)}]++;
    	}
    }
    set<pair<ll,ll> > done;
    ll p=1ll;
    for(auto _x:mp){
    	ll cnt=_x.S;
    	ll a=_x.F.F,b=_x.F.S;
    	ll ao,bo;
    	if(a==0){
    		ao=1,bo=0;
    	}
    	else if(b==0){
    		ao=0,bo=1;
    	}
    	else{
    		ao=abs(b),bo=a;
    		if(b>0)
    			bo=-bo;
    	}
    	if(done.find({ao,bo})!=done.end())
    			continue;
    	done.insert({a,b});
    	done.insert({ao,bo});
    	p=p*(exp(2,mp[{a,b}])+exp(2,mp[{ao,bo}])-1);
    	p%=md;
    }
    p=(p-1+md)%md;
 	cout<<p+ans<<"\n";

 
	die();
 
}
void prec(){
	F[0]=IV[0]=1;
	for(int i=1;i<M;++i){
		F[i]=F[i-1]*i%md,F[i]%=md;
		IV[i]=IV[i-1]*exp(i,md-2)%md,IV[i]%=md;
	}
} 
 
int main(){
 
 
#ifndef ONLINE_JUDGE
    double _tBeg=clock();
#endif
 
     
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 
    int t;
    t=1;;
    // prec();
    // cin>>t;
 
    while(t--){
 
        solve();
    }
 
 
 
 
 
 
#ifndef ONLINE_JUDGE
    double _tEnd=clock();
    // printf("\ntotal time %.6f\n",(_tEnd-_tBeg)/CLOCKS_PER_SEC);
#endif
 
    die();
}

Measured memory_bytes: 53516
import numpy as np

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

A = np.zeros((N), dtype=np.int)
*A[:], = map(int, input().split())
A[:] -= 1 # 0ベースに変更

visited = np.zeros((N), dtype=np.bool)
recent_turn = np.zeros((N), dtype=np.int64)

here = 0
rest_turn = K

while rest_turn > 0:
	if visited[here]:
		# 周回スキップ実装
		interval = recent_turn[here] - rest_turn
		rest_turn %= interval
		if rest_turn == 0:
			break
	else:
		# ソシャゲ周回
		visited[here] = True
	
	recent_turn[here] = rest_turn
	here = A[here]
	rest_turn -= 1

# 1ベースに戻す
print(here + 1)


Measured memory_bytes: 51056
from collections import Counter
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n = I()
a = LI()
q = I()
bcs = LIR(q)
sum_a = sum(a)
counter = Counter(a)
for b, c in bcs:
    sum_a += c * counter[b] - b * counter[b]
    print(sum_a)
    counter[c] += counter[b]
    counter[b] = 0


Measured memory_bytes: 40324
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp4
{
    class Program
    {
        /// <summary>
        ///  Let f(n) be the following function: f(n)=n/2 if n is even, and f(n)=3n+1 if n is odd.
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        public static double f(double n)
        {
            if(n % 2 == 0)
            {
                return n / 2;
            }
            else
            {
                return (3 * n) + 1;
            }
        }

        /// <summary>
        /// gets the min unless a is -1
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static double GetMin(double a, double b)
        {
            if (a == -1)
            {
                return b;
            }else if (a < b)
            {
                return a;
            }
            else
            {
                return b;
            }
        }

        /// <summary>
        /// main
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            var min = -1;
            var s = Console.ReadLine();

            var a = new List<double>();
            a.Add(double.Parse(s));

            // 0 index added above
            int i = 1;

            do
            {
                var next = f(a[i-1]);

                if (a.Contains(next))
                {
                    min = i + 1;
                }
                else
                {
                    a.Add(next);
                }

                i++;
            } while (min == -1);

            Console.WriteLine(min);

            Console.ReadLine();

        }
    }
}


Measured memory_bytes: 13152
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;
static const double EPS = 1e-10;
static const double BIGEPS = 1e-12;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SS stringstream
#define DBG1(a) rep(_X,sz(a)){printf("%d ",a[_X]);}puts("");
#define DBG2(a) rep(_X,sz(a)){rep(_Y,sz(a[_X]))printf("%d ",a[_X][_Y]);puts("");}
#define bitcount(b) __builtin_popcount(b)

int m[3] = {0};

int is(double a){
	if(abs(a) < EPS)return 1;
	if(a < 0)return 0;
	if(a > 0)return 2;
}

double mysqrt(double x){
	double l = 0 , r = x;
	for(int i = 0 ; i < 64 ; i++){
		double m = (l+r) / 2.0;
		if(m * m < x) l = m;
		else r = m;
	}
	return l;
}

double solve(double a,double b,double c,double d){
	//cout << a << " " << b << " " << c << " " << d << endl;
	if(a < 0){ a *= -1; b *= -1; c *= -1; d *= -1;}
	if(abs(a) < EPS){
		if(c * c - 4 * b * d < -EPS)return 0.0;
		double one = ( -c + mysqrt(c*c-4*b*d)  )/(2*b);
		double two = ( -c - mysqrt(c*c-4*b*d)  )/(2*b);
		//cout << one << "<>" << two << endl;
		m[is(one)]++;
		m[is(two)]++;
		return 0.0;
	}
	
	double l = -1000.0 , r = 1000.0;
	for(int i=0;i<64;i++){
		double x = (l+r)/2.0;
		double res = a*x*x*x+b*x*x+c*x+d;
		if(res>0){
			r = x;
		}else{
			l = x;
		}
	}
	if(l >= 1000-EPS || l <= -1000+EPS)return 0.0;
	return l;
}
int main(){
	int N; cin >> N;
	while(N--){
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		m[0] = m[1] = m[2] = 0;
		double n = solve(a,b,c,d);
			m[is(n)]++;
		//cout << n << endl;
		solve(0,a,a*n+b,n*(a*n+b)+c);	
		cout << m[2] << " " << m[0] << endl;
	}
}

Measured memory_bytes: 0
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
using namespace std;

char s[256];
int a[256];
int main() {
        cin >> s;
        int l = 1;
        for (int i = 0; s[i]; i ++) {
                int p = s[i];
                a[p] = 1;
                l ++;
        }
        for (int k = 'z'; k >= 'a'; k --) {
                if (!a[k]) {
                        s[l ++] = k;
                }
        }
        if (next_permutation(s, s + l)) {
                cout << s << endl;
        } else {
                cout << -1 << endl;
        }
        return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=10000;
const ll INF=1000000010;
const int MAX=100001;
int dx[8]={0,1,0,-1,1,-1,1,-1};
int dy[8]={1,0,-1,0,1,-1,-1,1};
int main(){
    int n;
    while(cin>>n,n){
        int t[17][17];
        for(int i=1;i<=n;i++){
            for(int j=0;j<=n;j++){
                cin>>t[i][j];
            }
        }
        int dp[1<<16];
        for(int i=0;i<(1<<n);i++)dp[i]=INF;
        dp[0]=0;
        for(int i=0;i<(1<<n);i++){
            for(int j=1;j<=n;j++){
                if(i&(1<<(j-1)))continue;
                int mi=t[j][0];
                for(int k=1;k<=n;k++){
                    if(i&(1<<(k-1))){
                        mi=min(mi,t[j][k]);
                    }
                }
                dp[i|(1<<(j-1))]=min(dp[i|(1<<(j-1))],dp[i]+mi);
            }
        }
        cout<<dp[(1<<n)-1]<<endl;
    }
	return 0;
}



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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed up
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed up
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed down
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed down
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
//    cout << fixed << setprecision(15);

    i32 a,b; cin >> a >> b;
    cout << max<i32>({a+b, a-b, a*b}) << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define fi first
#define se second
#define pr(x) cerr<<#x<<"="<<(x)<<endl
#define pri(x,lo) {cerr<<#x<<"={";for (int ol=0;ol<=lo;ol++)cerr<<x[ol]<<",";cerr<<"}"<<endl;}
#define inf 100000000
#define N 1000
ll a,i,n,o,ans;
vector<ll> s;
int main()
{
	scanf("%lld",&n);
	for (i=1;i<=n;i++)
	{
		scanf("%lld",&o);
		o-=i;
		s.pb(o);
	}
	sort(s.begin(),s.end());
	a=s[n/2];
	for (auto i:s) ans+=abs(i-a);
	printf("%lld\n",ans);
}	

Measured memory_bytes: 2420
N, X = map(int, input().split())
h = [int(input()) for _ in range(N)]
h.sort()
ans = 10 ** 9
for i in range(N - (X - 1)):
  if h[i + (X - 1)] - h[i] < ans:
    ans = h[i + (X - 1)] - h[i]
print(ans)

Measured memory_bytes: 7484
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

void solve() {
	int x; cin >> x;
	int ans = 1;
	rep(i, 3)ans *= x;
	cout << ans << endl;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
	return 0;
}



Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

const int INF = 1001001001;

double f(int v, int s, int e, double t) {
    if (t < s) return v + (s - t);
    else if (s <= t && t <= e) return v;
    else return v + (t - e);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vi t(n), v(n);
    rep(i, n) cin >> t[i];
    rep(i, n) cin >> v[i];
    vi smt(n+1, 0);
    rep(i, n) smt[i+1] = smt[i] + t[i];
    vector<double> ans(2*smt[n]+1, INF);
    rep(i, sz(ans)) {
        double t = i / 2.0;
        chmin(ans[i], t);
        rep(j, n) {
            chmin(ans[i], f(v[j], smt[j], smt[j+1], t));
        }
        chmin(ans[i], smt[n] - t);
    }
    double dist = 0;
    rep(i, sz(ans) - 1) {
        dist += (ans[i] + ans[i+1]) / 4.0;
    }
    cout << fixed << setprecision(15) << dist << endl;
    
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
using namespace std;
string grid[100];
int d[100][100];
int move_x[2] = {1, 0};
int move_y[2] = {0, 1};
int main(){
  int H;
  int W;
  cin >> H >> W;
  for(int i = 0; i < H; i++){
    cin >> grid[i];
  }
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      d[i][j] = INT_MAX;
    }
  }

  priority_queue <pair<int, pair<int, int> >, vector <pair<int, pair<int, int> > >, greater<pair<int, pair<int, int> > > > pq;
  pq.push(make_pair(0, make_pair(0, 0)));
  d[0][0] = 0;
  
  while(!pq.empty()){
    auto cur = pq.top();
    int cur_d = cur.first;
    int cur_x = cur.second.first;
    int cur_y = cur.second.second;
    pq.pop();

    if(d[cur_x][cur_y] < cur_d){
      continue;
    }

    for(int i = 0; i < 2; i++){
      int next_x = cur_x + move_x[i];
      int next_y = cur_y + move_y[i];
      if(0 <= next_x && next_x < H && 0 <= next_y && next_y < W){
        if(grid[cur_x][cur_y] == '#' && grid[next_x][next_y] == '.'){
          if(cur_d + 1 < d[next_x][next_y]){
            d[next_x][next_y] = cur_d + 1;
            pq.push(make_pair(cur_d + 1, make_pair(next_x, next_y)));
          }
        } else if(cur_d < d[next_x][next_y]){
          d[next_x][next_y] = cur_d;
          pq.push(make_pair(cur_d, make_pair(next_x, next_y)));
        }
      }
    }
  }
  if(grid[H - 1][W - 1] == '#'){
    cout << d[H - 1][W - 1] + 1 << endl;
  } else {
    cout << d[H - 1][W - 1] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 2;
ll INF = 1e18;
const int MAX = 1e7;
long long fac[MAX], finv[MAX], inv[MAX];
V vec2(MAX);
// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
    rep3(i,1,MAX+1){
        ll sum=0;
        ll temp=i;
        while(temp%2==0){
            temp/=2;
            sum++;
        }
        vec2[i]+=vec2[i-1]+sum;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    if(vec2[n]>vec2[n-k]+vec2[k]){
        return 0;
    }else{
        return 1;
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    string s;
    cin>>s;
    V vec(n-1);
    rep(i,n-1){
        ll a=s[i]-'0';
        ll b=s[i+1]-'0';
        vec[i]=abs(a-b);
    }
    bool f=true;
    rep(i,n-1){
        if(vec[i]==1){
            f=false;
            break;
        }
    }
    COMinit();
    if(!f){
    //    cout<<"hello"<<endl;
        ll sum=0;
        rep(i,n-1){
         //   cout<<n-2<<" "<<i<<" "<<COM(n-2,i)<<endl;
            sum+=COM(n-2,i)*vec[i];
            sum%=2;
        }
        cout<<sum%2<<endl;
        return 0;
    }
    rep(i,n-1){
        if(vec[i]==2){
            vec[i]=1;
        }
    }
    ll sum=0;
    rep(i,n-1){
        sum+=COM(n-2,i)*vec[i];
        sum%=2;
    }
    if(sum%2==1){
        cout<<2<<endl;
    }else{
        cout<<0<<endl;
    }
    return 0;
  /*  ll sum=0;
    for(auto i:vec){
        cout<<i<<" ";
    }
    cout<<endl;
    rep(i,n-1){
        sum+=vec[i];
    }
    if(sum%2==1){
        cout<<1<<endl;
    }else{
        cout<<0<<endl;
    }*/
    
}


Measured memory_bytes: 321692
#include <stdio.h>
//#define scanf scanf_s
typedef long long int lli;

// ITP1_4_A
// 2つの整数a,bを読み込み、a/b, a%b, a/b(float)を出力
int main()
{
	lli iInputA, iInputB;

	scanf("%lld %lld", &iInputA, &iInputB);

	printf("%lld %lld %lf\n", iInputA/iInputB, iInputA%iInputB, (double)iInputA/iInputB);

	return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;



int main(void) {
    int h, w;
    cin >> h >> w;
    int n;
    cin >> n;
    vector<int> a(n + 1);
    rep (i, n) cin >> a[i + 1];

    vector<vector<int>> grid(h, vector<int>(w));

    int now = 1;
    rep (i, h) {
        if (i % 2 == 0) {
            for (int j = 0; j < w; j++) {
                if (a[now] == 0) now++;
                grid[i][j] = now;
                a[now]--;
            }
        }
        else {
            for (int j = w - 1; j >= 0; j--) {
                if (a[now] == 0) now++;
                grid[i][j] = now;
                a[now]--;
            }
        }
    }

    rep (i, h) {
        rep (j, w) cout << grid[i][j] << " ";
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x)
#define abs(x,y) (max(x,y)-min(x,y))
#define mp make_pair
#define fi first
#define se second
using namespace std;
bool i[111100];
vector<int> ii;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=1,e=1,f=0,g=1,h=1,j;
  cin >>a>>b;
  for(int n=0;n<a;n++){
    cin >>c;
    if(c>=b) f++;
  }
  cout <<f<<'\n';
  return (0);
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

/*
 * To execute Java, please define "static void main" on a class
 * named Solution.
 *
 * If you need more classes, simply define them inline.
 */

class Main {
  public static void main(String[] args) {
    int sevenCounter = 0;
    int fiveCounter = 0;
    
//     BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
//     try {
//            StringTokenizer token = new StringTokenizer(br.readLine());
    
    Scanner sc = new Scanner(System.in);
    
    
    for (int i = 0; i< 3; i++) {
      while (sc.hasNext()) 
      {
        if (sc.nextInt() == 7)
        sevenCounter++;
       else 
        fiveCounter++; 
      }
    }
      
//     } catch (IOException ex) {
      
      
//     }
    
   
    
    if (sevenCounter == 1 && fiveCounter == 2) {
      System.out.println("YES"); 
    } else {
        System.out.println("NO"); 
    }
  }
}


Measured memory_bytes: 9556
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


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

  vi snk(n);
  rep(i, k){
    int d;
    cin >> d;
    rep(i, d){
      int a;
      cin >> a;
      snk[a-1]++;
    }
  }

  int ans = 0;
  rep(i, n){
    if (snk[i] == 0) ans++;
  }

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

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

int main(){
    long long i;
    long long N;
    long long duration=0;
    long long flg=0;
    cin>>N;
    //{締め切り,コスト}
    vector<vector<long long>>C(N,vector<long long>(2));

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

    sort(C.begin(),C.end());

    for(i=0;i<N;i++){
        duration+=C[i][1];
        if(duration>C[i][0]){
            flg=1;
            break;
        }
    }

    //if(duration>C[N-1][0])flg=1;

    if(flg==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 11136
/**
*	  Name: Ajay Subhash Jadhav
*	  Institute: International Institute of Technology Hyderabad 
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <string.h>
#define LL long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int,int>
#define vi vector<int>
#define vii vector<ppi>
#define vll vector<LL>
#define mp make_pair
using namespace std;

void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void inputread()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
}
int gcd(int a,int b)
{
	if(b==0)
		return a;
	return gcd(b,a%b);
}
int main(){
      
  fastio();
  int n,m,i,j,t;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)
  {
  	cin>>a[i];
  }
  int g=a[0];
  for(i=1;i<n;i++)
  {
  	g=gcd(g,a[i]);
  }
  cout<<g<<"\n";
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
using namespace std;
int Fj(int x) {
	int tot=0;
	while (x) {
		tot+=x%10;
		x/=10;
	}
	return tot;
}
int n,ans=10000000;
int main() {
	cin>>n;
	for (int i=1;i<=n/2;i++) {
		int one=Fj(i);
		int two=Fj(n-i);
		if (one+two<ans) ans=one+two;
	}
	cout<<ans;
}

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

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

  int days = 0;

  rep(i, m) {
    int a;
    cin >> a;
    days += a;
  }

  cout << max(-1, n - days) << endl;

  return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define Would
#define you
#define please

int main() {
	//おまじない
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string S;
	int P[52][52] = {};
	int H, W;
	cin >> H >> W;

	rep(i, H) {
		cin >> S;
		rep(ii, W) {
			if (S[ii] == '#') P[i + 1][ii + 1] = 1;
		}
	}

	int kotae = 1;
	rep(i, H) {
		rep(ii, W) {
			if (P[i][ii] == 1 && P[i - 1][ii] == 0 && P[i + 1][ii] == 0 && P[i][ii - 1] == 0 && P[i][ii + 1] == 0 ) kotae = 0;
		}
	}
	if (kotae == 1)	co("Yes");
	else co("No");
	Would you please return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}


int A[12][12];
int C[12];

int main2() {
  int N = nextInt();
  int M = nextInt();
  int X = nextInt();

  REP(i, N) {
    C[i] = nextInt();
    REP(j, M) {
      A[i][j] = nextInt();
    }
  }

  int ans = 1001001001;

  for (int set = 0; set < (1 << N); set++) {
    vector<int> x(M);
    int price = 0;
    REP(i, N) if (set >> i & 1) {
      REP(j, M) x[j] += A[i][j];
      price += C[i];
    }
    if (*min_element(ALL(x)) >= X)
      chmin(ans, price);
  }

  if (ans == 1001001001)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

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

int main() {
    int i,j;
    int H,W;
    cin >> H>>W;
    vector<vector<char>> a(H,vector<char>(W));
    vector<vector<char>> o(H+2,vector<char>(W+2));
    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            cin>>a.at(i).at(j);
        }
    }
    for(i=0;i<H+2;i++){
        for(j=0;j<W+2;j++){
            if((i==0 || i==H+1) || (j==0 || j==W+1)){
                o.at(i).at(j) = '#';
                //cout<< i<<j<<'#' <<endl;
            }else{
                o.at(i).at(j) = a.at(i-1).at(j-1);
                //cout<< i<<j<<o.at(i).at(j) <<endl;
            }
        }

    }
    for(i=0;i<H+2;i++){
        for(j=0;j<W+2;j++){
            cout<< o.at(i).at(j) <<flush;
        }
        cout<<endl;
    }
}

Measured memory_bytes: 3584
package main

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

func main() {
	scn := bufio.NewScanner(os.Stdin)
	scn.Split(bufio.ScanWords)
	nextInt := func() int { scn.Scan(); r, _ := strconv.Atoi(scn.Text()); return r }
	w := bufio.NewWriter(os.Stdout)

	a := []int{0}

loop:
	for {
		switch scn.Scan(); scn.Text() {
		case "insert":
			a = insert(a, nextInt())
		case "extract":
			var max int
			a, max = extract(a)
			fmt.Fprintln(w, max)
		case "end":
			break loop
		}
	}

	w.Flush()
}

func insert(a []int, k int) []int {
	a = append(a, k)
	upheap(a, len(a)-1)
	return a
}

func upheap(a []int, i int) {
	p := i / 2
	if p < 1 {
		return
	}

	if a[i] > a[p] {
		a[i], a[p] = a[p], a[i]
		upheap(a, p)
	}
}

func extract(a []int) ([]int, int) {
	ret := a[1]
	a[1] = a[len(a)-1]
	a = a[:len(a)-1] // Shorten

	downheap(a, 1)

	return a, ret
}

func downheap(a []int, i int) {
	l := i * 2
	r := l + 1
	largest := i
	if l < len(a) && a[i] < a[l] {
		largest = l
	}
	if r < len(a) && a[largest] < a[r] {
		largest = r
	}
	if largest != i {
		a[i], a[largest] = a[largest], a[i]
		downheap(a, largest)
	}
}



Measured memory_bytes: 24456
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define ma LONG_LONG_MAX
#define fi first
#define mod 1000000007
#define sec second
ll n,m;
char a[1001][1001];
ll dp[1001][1001];
ll recur(ll x,ll y)
{
	if(dp[x][y]!=-1)
	{
		return dp[x][y];
	}
	if(x==n-1 && y==m-1)
	{
		dp[x][y]=1;
		return 1;
	}
	ll ans=0;
	if(x+1<n && a[x+1][y]=='.')
	{
		ans=(ans%mod+recur(x+1,y)%mod)%mod;
	}
	if(y+1<m  && a[x][y+1]=='.')
	{
		ans=(ans%mod+recur(x,y+1)%mod)%mod;
	}
	dp[x][y]=ans;
	return dp[x][y];
}
int main()
{
	cin>>n>>m;
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<m;j++)
		{
			cin>>a[i][j];
			dp[i][j]=-1;
		}
	}
	cout<<recur(0,0);
}



Measured memory_bytes: 9088
# B Magic2
A, B, C = map(int, input().split())
K = int(input())
for i in range(K + 1):  # range()は0からなので+1
    for j in range(K + 1):
        for k in range(K + 1):
            if i + j + k <= K:  # K回以内
                if A * (2 ** i) < B * (2 ** j):
                    if B * (2 ** j) < C * (2 ** k):
                        print("Yes")
                        exit()
print("No")


Measured memory_bytes: 9124