akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) for (auto i = mp.begin(); i != mp.end(); ++i) { cout << i->first <<":"<<i->second << endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<" ";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    vector<ll> p(m);
    vector<string> s(m);
    rep(i,m){
        cin>>p[i];
        cin>>s[i];
    }
    vector<ll> wa(n,0);
    vector<ll> ac(n,0);
    ll ans=0;
    ll pena=0;
    for(ll i=0; i<m; i++) {
        if (s[i]=="AC" && ac[p[i]-1]==0) {
            ac[p[i]-1]=1;
//            dbg(ac[i]);
        } else if (s[i]=="WA" && ac[p[i]-1]==0){
            wa[p[i]-1] += 1;
//            dbg(wa[p[i]-1]);
        }
    }
    for(ll i=0; i<n; i++) {
        if(ac[i]==1) {
            pena += wa[i];
//            dbg(pena);
        }
    }
    ans = count(ac.begin(), ac.end(), 1);
    cout<<ans<<" "<<pena<<endl;
    return  0;
}


Measured memory_bytes: 8064
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

long long int gcd(long long int x, long long int y)
{
	if (y == 0) { return x; }
	return gcd(y, x % y);
}

int main(void)
{
	long long int h, w;
	cin >> h >> w;
	
	if (h == 1 || w == 1) { cout << 1 << endl; }
	else { cout << (h * w + 1) / 2 << endl; }
	return 0;
}


Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())
diff1 = x2 - x1
diff2 = y2 - y1
x3, y3 = x2 - diff2, y2 + diff1
x4, y4 = x3 - diff1, y3 - diff2
print(x3, y3, x4, y4)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,l,r) for (int i=l,i##end=r;i<=i##end;++i)
#define per(i,r,l) for (int i=r,i##end=l;i>=i##end;--i)
#define rep0(i,r) for (int i=0,i##end=r;i<i##end;++i)
#define ll long long
using namespace std;
ll M;
ll mul(ll x,ll y,ll m){
    ll s=0; for (;y;y>>=1,x=(x+x)%m) if (y&1) s=(s+x)%m;
    return s;
}
ll fpw(ll x,ll y,ll m){
    ll s=1; x%=m;
    for (;y;y>>=1,x=x*x%m) if (y&1) s=s*x%m;
    return s;
}
ll gcd(ll x,ll y){ return y==0?x:gcd(y,x%y); }
void exgcd(ll a,ll b,ll &x,ll &y){
    if (b==0){ x=1,y=0; return; }
    exgcd(b,a%b,y,x); y-=a/b*x;
}
ll phi(ll n){
    ll s=1;
    rep(i,2,sqrt(n))
        if (n%i==0){
            s*=i-1,n/=i; while (n%i==0) s*=i,n/=i;
            if (n==1) break;
        }
    return s*(n==1?1:n-1);
}
ll solve(ll a,ll m){
    if (m==1) return M;
    ll p=phi(m),g=gcd(m,p),_y=solve(a,g);
    ll pw=fpw(a,_y,m),c=_y%p-pw;
    //ans=m*x+pw=p*y+_y m*x-p*y=pw-_y
    //m*x-p*y=c
    ll x1,y1; exgcd(m,p,x1,y1);
    x1=(x1%(p/g)+(p/g))%(p/g)*(c/g);
    ll d=m*p/g; x1=(x1%d+d)%d;
    ll ans=(mul(x1,m,d)+pw)%d;
    if (ans<M) ans+=(M-ans+d-1)/d*d;
    while (ans<M) ans+=d;
    return ans;
}
int main(){
    int q; cin>>q;
    while (q--){
        ll a,m; cin>>a>>m; M=phi(m);
        ll s=solve(a,m); cout<<s<<endl;
    }
    return 0;
}
/*
1
123456789 987654321
*/


Measured memory_bytes: 256
n = int(input());

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
                
    return divisors

n_div = make_divisors(n)
list_ = []

for i in range(len(n_div)):
  list_.append(int(n_div[i] + (n / n_div[i])))

print(min(list_)- 2)


Measured memory_bytes: 9624
#include <iostream>
using namespace std;
int n;
int a[3100];
long long dp[3100][3100];
bool vis[3100][3100];
long long solve (int s, int e) {
	if (s == e) return a[s];
	if (vis[s][e]) return dp[s][e];
	vis[s][e] = true;
	dp[s][e] = max(a[s]-solve(s+1, e), a[e]-solve(s, e-1));
	return dp[s][e];
}
int main () {
	cin >> n;
	for (int i=0; i<n; i++) {
		cin >> a[i];
	}
	cout << solve(0, n-1) << endl;
}

Measured memory_bytes: 59316
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,card[101],c,j;   //nはカードの数, boxは比較するときの避難場
    cin >> n;
    
    for(int i = 0;i < n; i++){   //カードに値を入力
        cin >> c;
        card[i] = c;
        
        //cout << "card[" << i << "]" << card[i] << endl;
    }

    
    
    for(int i = 0; i < n;i++){    //左から比較していく
        int v = card[i];
        j = i - 1;
        
        while(j >= 0 && card[j] > v){
            card[j+1] = card[j];
            j--;
        }
        card[j+1] = v;
        
        for(int m = 0; m < n; m++){
            cout << card[m] << ((m == n-1)?'\n' : ' ');
        }
            
        
    }
        
    
}



Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include<functional>
#include <tuple>
#include <map>
#include<set>
#include <cmath>
#include <stack>
#include<cstdio>
#include<stdio.h>
using namespace std;

int main() {
	int n,i=0,cnt=0;
	cin >> n;
	bool f = true;
	vector<int> a(n);
	for (int j = 0;j < n;j++)cin >> a[j];
	while (f) {
		for (int j = 0;j < n;j++) {
			if (a[j] % 2 == 0)a[j] /= 2;
			else f = false;
		}
		if (f)cnt++;
	}
	cout << cnt << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<bool> a(1<<n);
  for(int i=0;i<(1<<n);i++){
    char c;
    cin>>c;
    a.at(i)=(c=='1');
  }
  vector<int> s;
  vector<bool> b(1<<n,1);
  for(int i=0;i<(1<<n);i++){
    if(a.at(i))
      continue;
    bool f=0;
    for(int x:s)
      if((x&i)==x)
        f=1;
    if(f)
      continue;
    s.push_back(i);
    for(int j=0;j<(1<<n);j++)
      b.at(j)=(b.at(j)&&((i&j)!=i));
  }
  if(a!=b){
    cout<<"Impossible"<<endl;
    return 0;
  }
  cout<<"Possible"<<endl;
  vector<vector<int>> c;
  for(int x:s){
    vector<vector<int>> cx;
    for(int i=0;i<n;i++,x/=2){
      if(x%2==0)
        continue;
      vector<vector<int>> ci;
      for(int j=0;j<n;j++){
        ci.push_back({j,0});
        if(i==j){
          ci.push_back({j,1});
          ci.push_back({j+1,1});
        }
      }
      for(int j=n;j>0;j--)
        ci.push_back({j,0});
      if(cx.empty()){
        cx=ci;
        continue;
      }
      vector<vector<int>> cxb=cx;
      vector<vector<int>> cib=ci;
      reverse(cxb.begin()+1,cxb.end());
      reverse(cib.begin()+1,cib.end());
      for(auto y:ci)
        cx.push_back(y);
      for(auto y:cxb)
        cx.push_back(y);
      for(auto y:cib)
        cx.push_back(y);
    }
    for(auto y:cx)
      c.push_back(y);
  }
  c.push_back({0,0});
  cout<<c.size()-1<<endl;
  for(auto x:c)
    cout<<x.at(0)<<' '<<x.at(1)<<endl;
}

Measured memory_bytes: 6028
import * as fs from 'fs'

const input = fs.readFileSync('/dev/stdin', 'utf8').split('\n')
const n = +input[0].split(' ')[0]
const k = BigInt(input[0].split(' ')[1])
const a = input[1].split(' ').map(x => +x)
let cur = 0
if (k <= n) {
  for (let i = 0; i < k; i++) {
    cur = a[cur] - 1
  }
} else {
  let visited = new Array(n).fill(-1)
  visited[0] = 0
  let teleport = 0
  let loop = 0
  for (let i = 0; i < n; i++) {
    cur = a[cur] - 1
    teleport = i + 1
    if visited[cur] >= 0 {
      loop = teleport - visited[cur]
      break
    } else {
      visited[cur] = teleport
    }
  }
  for (let i = 0; i < (k - BigInt(teleport)) % BigInt(loop); i++) {
    cur = a[cur] - 1
  }
}
console.log(cur + 1)

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

using ll = long long int;
const int mod = 1e9+7;
const int inf = 1e9+5;
vector<vector<ll>>score;
int main(){
	
	int H, W;
	cin>>H>>W;
	vector<string>grid(H);
	
	for(int i = 0; i < H; i++){
		//for(int j = 0; j < W; j++){
		cin>>grid[i];
		cerr<<grid[i]<<endl;
		//}
	}
	score.resize(H, vector<ll>(W));
	//vector<vector<ll>>score(H, vector<ll>(W));
	for(int i = 0; i < H; i++){
		if(grid[i][0] == '#'){
			break;
		}else{
			score[i][0] = 1LL;
		}
	}
	
	for(int i = 0; i < W; i++){
		if(grid[0][i] == '#'){
			break;
		}else{
			score[0][i] = 1LL;
		}
	}
	
	for(int i = 1; i < H; i++){
		for(int j = 1; j < W; j++){
			if(grid[i-1][j] != '#' && grid[i][j-1] != '#'){
				score[i][j] = score[i-1][j] + score[i][j-1];
				score[i][j] %= mod;
			}else if(grid[i-1][j] != '#'){
				score[i][j] = score[i-1][j];
			}else if(grid[i][j-1] != '#'){
				score[i][j] = score[i][j-1];
			}
		}
		//prev = score;
	}
	cout<<score[H-1][W-1]<<endl;
	return 0;
}


Measured memory_bytes: 9216
N = int(input())
a = list(map(int, input().split()))

def power_two_divisor(N):
    for i in range(30, -1, -1):
        if N % (2 ** i) == 0:
            return i
        
ans = 0
for e in a:
    ans += power_two_divisor(e)
    
print(ans)

Measured memory_bytes: 4148
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include <math.h>
#include <set>
#include <map>
#include <stdio.h>
#include <queue>
#include <iomanip>
#include <cstring>
#include <stack>
#include <chrono>
#include <unordered_map>
#include <stdlib.h>
#include <ctime>
using namespace std;
typedef long long ll;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define fi first
#define se second
#define pll pair<ll,ll>
#define forn(i,e) for(ll i = 1; i<=e; i++)
#define forsn(i,s,e) for(ll i = s; i<=e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
// freopen("input.txt","r", stdin);
// freopen("out.txt","w", stdout);
// auto start = chrono::high_resolution_clock::now();
// auto end = chrono::high_resolution_clock::now();
// double time_taken =chrono::duration_cast<chrono::nanoseconds>(end - start).count();
// time_taken *= 1e-9;
// cout << "Time taken by program is : " << fixed << time_taken << setprecision(9);
// cout << " sec" << endl;
int main()
{
    ll n;
    cin>>n;
    if(n%7==0)
        n=n/7;
    ll rem=1;
    bool ok=false;
    ll cnt=1;
    for(ll i=1;i<=n+10;i++){
        if(rem%n==0){
            ok=true;
            break;
        }
        rem=(rem*10+1)%n;
        cnt++;
    }
    if(!ok)
        cout<<-1<<endl;
    else{
        cout<<cnt<<endl;
    }
}


Measured memory_bytes: 3632
S = list(input())
K = int(input())
L = len(S)

if len(set(S)) == 1:
    print(L*K // 2)
    exit()

def n_changes(s):
    sc = s.copy()
    count = 0
    for i in range(1, len(sc)):
        if sc[i] == sc[i-1]:
            sc[i] = "X"
            count += 1
    return count

print(n_changes(S) + (K-1) * (n_changes(2*S) - n_changes(S)))


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

int main(){
    int a,b,c; cin >> a >> b >> c;
    cout << ((c - a + b > 0)? c - a + b : 0 )  << endl;
    return 0;
}

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

using namespace std;

signed main(){
    int n; cin >> n;
    vector<pair<int, int>> ab(n);
    for (int i = 0; i < n; ++i){
        cin >> ab[i].first >> ab[i].second;
    }
    sort(ab.begin(), ab.end());
    cout << ab[n - 1].first + ab[n - 1].second << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
#define D 1000000007
#define INF 1<<30

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int main()
{
    int N;
    cin >> N;
    vector<ll> A(N);
    ll sum = 0;
    REP(i,N){
        cin >> A[i];
        sum += A[i];
        sum %= D;
    }
    ll square = 0;
    REP(i,N){
        square += (A[i]*A[i]);
        square %= D;
    }
    ll invtwo = modinv(2,D);
    ll sumsq = (sum*sum)%D;
    ll sumpro = (((sumsq-square)%D)*invtwo)%D;
    if(sumpro<0){
        sumpro += D;
    }
    cout << sumpro << endl;
    return 0;
}

Measured memory_bytes: 4836
#include<iostream>
#include<math.h>
#include<cmath>
#include<iomanip>
#include<string.h>
#include<stdio.h>
#include <algorithm>
using namespace std;
int main()
{
	
	int n;
	cin>>n;
	if(n>=0&&n<1200)
	{
		cout<<"ABC";
	}
	if(n>=1200&&n<2800)
	{
		cout<<"ARC";
	}
	if(n>=2800&&n<=4208)
	{
		cout<<"AGC";
	}
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <list>
#include <set>
using namespace  std;

#define int long long int

constexpr int INF = std::numeric_limits<int>::max();

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

    int d; cin >> d;
    cout << "Christmas" << endl;

    for (int i = 0; i < 25 - d; i++) {
        cout << " Eve" << endl;
    }
    cout << endl;
}

Measured memory_bytes: 256
N=int(input())
a=list(map(int,input().split()))
b=[0,]*N
err=0
cnt=0
ans=1
for i in range(N):
    b[a[i]]+=1
if N%2 == 0:
    for i in range(1,N,2):
        if b[i]!=2:
            err=1
        cnt+=1
    for i in range(0,N,2):
        if b[i]!=0:
            err=1
else:
    if b[0]!=1:
        err=1
    for i in range(2,N,2):
        if b[i]!=2:
            err=1
        cnt+=1
    for i in range(1,N,2):
        if b[i]!=0:
            err=1
if err == 1:
    print("0")
else:
    for i in range(cnt):
        ans=(ans*2)%(10**9+7)
    print(str(ans))

Measured memory_bytes: 14008
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;
const long long mod=1'000'000'007ll;

int main(){
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    long long ans;
    if(s[0]==t[0])ans=3ll;
    else ans=6ll;
    for(int i=1;i<n;i++){
        if(s[i]==t[i] && s[i-1]==t[i-1]){
            ans*=2ll;
            ans%=mod;
        }
        if(s[i]!=t[i] && s[i-1]==t[i-1]){
            ans*=2ll;
            ans%=mod;
        }
        if(s[i]!=t[i] && s[i-1]!=t[i-1] && s[i]!=s[i-1]){
            ans*=3ll;
            ans%=mod;
        }
    }
    cout<<ans<<endl;
}

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

template<typename T, typename U> bool chmin(T &a, const U &b) {
	return (a > b ? a = b, true : false);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
	return (a < b ? a = b, true : false);
}

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;

double d[200010];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

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

	for(int i=0; i<n; i++){
		double tmp; cin>>tmp;

		d[i] = (tmp+1)/2;
	}

	double sum=0.0;
	for(int i=0; i<k; i++){
		sum += d[i];
	}
	/*cout<<sum<<endl;*/

	int p =0;
	double mx = sum;
	while(k+p<=n-1){
		sum =sum-d[p]+d[k+p];

/*		cout<<sum<<endl;*/

		mx = max(mx,sum);

		p++;

	}

	printf("%.6f",mx);



}


Measured memory_bytes: 1792
BlueN = int(input())
BlueList = []
for i in range(0,BlueN):
  BlueList.append(input())

RedN = int(input())
RedList = []
for i in range(0,RedN):
  RedList.append(input())

stocker = 0

for i in set(BlueList):
  if BlueList.count(i) * 1 + RedList.count(i) * -1 >= stocker:
    stocker = BlueList.count(i) * 1 + RedList.count(i) * -1

print(stocker)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >>N;
  if(N<10){
    cout<<N<<endl;
    return 0;
  }else if(N>=10&&N<100){
    cout<<9<<endl;
    return 0;
  }else if(N>=100&&N<1000){
    cout<<N-99+9<<endl;
    return 0;
  }else if(N>=1000&&N<10000){
    cout<<909<<endl;
    return 0;
  }else if(N>=10000&&N<100000){
    cout<<N-9999+909<<endl;
    return 0;
  }else if(N>=100000){
    cout<<90909<<endl;
    return 0;
  }
}

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

int main(){
  int ans=0;
  int a=0;
  for(int i=0;i<3;i++){
    char s;
    cin >> s;
    if(s=='S') a=0;
    else a++;
    ans=max(ans,a);
  }
  cout << ans << endl;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
  int a, b, c;
  cin>>a>>b>>c;
  if (c-a<=b && c >= a){
    cout<<"YES\n";
  }
  else{
    cout<<"NO\n";
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
//DEFINE and TYPEDEF--------------------------------------------------------------
 
#define timeKyaHorhaH 1.0 * clock() / CLOCKS_PER_SEC

#define FORG(i,a,n) for(lld i=a;i<n;i++) //for - general
#define FORZ(i,n) for(lld i=0;i<n;i++) //for - zero
#define FORGI(i,a,n,inc) for(lld i=a;i<n;i+=inc) //for - general incremental
#define FORZI(i,n,inc) for(lld i=0;i<n;i+=inc) //for - zero incremental
#define SPEEDUP ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define MEM(a,val) memset(a,val,sizeof(a));
 
#define SORTall(m) sort(m.begin(),m.end());
 
#define st first
#define nd second
#define pb push_back
 
typedef long long int lld;
typedef unsigned long long int ulld;

lld power(lld b, lld e)
{
    if(e==0)
        return 1;
    if(e%2==1)
        return b*power(b*b,(e-1)/2);
    else
        return power(b*b,e/2);
}
 
lld power(lld b, lld e, lld m)
{
	if(e==0)
		return 1;
	if(e%2==1)
		return b*power(((b%m)*(b%m))%m,(e-1)/2,m)%m;
	else
		return power(((b%m)*(b%m))%m,e/2,m)%m;
}
 
int nDig(lld n)
{
	if(n<0) 
		n*=-1;
	if(n==0)
		return 1;

    return floor(log10(n) + 1);
}

#define endl '\n'
#define mod 1000000007

//endl : changed to '\n', to flush comment that definition
//--------------------------------------------------------------------------------

void swagWaalaFunction()
{
	lld n,m,ans=0,x;
	cin>>n>>m;

	FORZ(i,m)
	{
		cin>>x;
		ans+=x;
	}

	if(ans<=n)
		cout<<n-ans;
	else
		cout<<-1;
	return;
}

int main()
{
    SPEEDUP;
 	lld t=1;
 	//cin>>t;

 	while(t--)
 		swagWaalaFunction();
	
	// cerr<<"\n"<<timeKyaHorhaH; 	
 	return 0;
}

Measured memory_bytes: 3700
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7

a.sort()

if n%2 == 1: 
    if a[0] != 0:
        print(0)
        exit()
    else:
        a.remove(0)
        tmp = 2
else:
    tmp = 1

for i in range(n//2):
    if tmp == a[0] and tmp == a[1]:
        a.remove(tmp)
        a.remove(tmp)
    else:
        print(0)
        exit()
    tmp += 2

if len(a) == 0:
    print((2**(n//2))%mod)
else:
    print(0)




Measured memory_bytes: 20444
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int a, b, c; cin >> a >> b >> c;
	int d = min(c, a + b + 1);
	cout << b + d << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    string s; cin >> s;
    for (int i=0; i<3; i++){
        if (s[i]== '1'){
            s[i] = '9'; 
        }
        else if (s[i] == '9'){
            s[i] = '1';
        }
    }
    cout << s << endl;
}

Measured memory_bytes: 256
H,W=map(int,input().split())
a=[]
for j in range(H):
    A=list(map(int,input().split()))
    a.append(A)

ans=0
ans_out=[]
for j in range(H):
    for i in range(W):
        if(a[j][i]%2!=0):
            if(i!=W-1):
                ans+=1
                a[j][i+1]+=1
                ans_out.append(str(j+1)+" "+str(i+1)+" "+str(j+1)+" "+str(i+2))
            else:
                if(j!=H-1):
                    a[j+1][i]+=1
                    ans+=1
                    ans_out.append(str(j+1)+" "+str(i+1)+" "+str(j+2)+" "+str(i+1))
print(ans)
for j in ans_out:
    print(j)

Measured memory_bytes: 16380
#include <iostream>
#define no(i, x) for(int i = 1; i < x; i++)
using namespace std;
 
int main() {
    int a[7], d[7];
    string q = "CCCCNCCCCNCCCCNCCCCNECCCCNNCCCC";
    no(i, 7) cin >> a[i];
    no(i, 7) cin >> d[i];
    for (int i = 0; i < q.length(); i++) {
        int g = 0;
        if (q[i] == 'N') {
            int o = d[1]; d[1] = d[2]; d[2] = d[6]; d[6] = d[5]; d[5] = o; 
        } else if (q[i] == 'E') {
            int o = d[1]; d[1] = d[4]; d[4] = d[6]; d[6] = d[3]; d[3] = o; 
        } else if (q[i] == 'C') {
            int o = d[2]; d[2] = d[3]; d[3] = d[5]; d[5] = d[4]; d[4] = o;
        }
        no(i, 7) {
            if (a[i] == d[i]) g++;
            if (g == 6) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 3204
N, M = map(int, input().split())
from collections import defaultdict
d = defaultdict(list)

for _ in range(M):
  A, B = map(int, input().split())
  d[A].append(B)
  d[B].append(A)

# print(d)

ans = [0] * (N+1)
visited = {1}

current = [1]
for _ in range(N):
  # print(current)
  nxt = []
  for e in current:
    for e2 in d[e]:
      if not e2 in visited:
        ans[e2] = e
        visited.add(e2)
        nxt.append(e2)
  if nxt:
    current = nxt
  else:
    break

if len(visited) == N:
  print('Yes')
  for i in range(2, 1+N):
    print(ans[i])
else:
  print('No')


Measured memory_bytes: 45176
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int[] L = new int[N];
      for(int i = 0; i < N; i++){
        L[i] = sc.nextInt();
      }
      Arrays.sort(L);
      
      // カウント
      int count = 0;
      if(N >= 3){
        for(int i = 0; i < N; i++){
          for(int j = i+1; j < N; j++){
            for(int k = j+1; k < N; k++){
              int a = L[i];
              int b = L[j];
              int c = L[k];
              
              if(isDif(a,b,c)){
                if(c < a+b){
                  count++;
                }
              }
            }
          }
        }
      }
      
      // 出力
      System.out.println(count);
    }
    
    // 3つの値が異なるか判定する関数
    public static boolean isDif(int a, int b, int c){
      boolean result = true;
      if(a == b){
        result = false;
      }else if(b == c){
        result = false;
      }else if(a == c){
        result = false;
      }
      
      return result;
    }
    

}

Measured memory_bytes: 36444
#include<stdio.h>

#define WHITE -1
#define GRAY -2
#define BLACK -3
#define MAX 100

int n, time, d[MAX+1], f[MAX+1], color[MAX+1], M[MAX+1][MAX+1];

void visit( int u )
{
  int v;

  color[u] = GRAY;
  d[u] = ++time;

  for( v=0; v<n; v++ )
    {
      if( M[u][v] == 0 ) continue;
      if( color[v] == WHITE )
	{
	  visit(v);
	}
    }
  color[u] = BLACK;
  f[u] = ++time;
}


void dfs()
{
  int u;

  for( u=0; u<n; u++ ) color[u] = WHITE;
  time = 0;

  for( u=0; u<n; u++ )
    {
      if( color[u] == WHITE ) visit(u);
    }
  for( u=0; u<n; u++ )
    {
      printf("%d %d %d\n", u+1, d[u], f[u]);
    }
}


int main()
{
  int i, j, u, v, k;

  scanf("%d", &n);

  for( i=0; i<n; i++ )
    {
      for( j=0; j<n; j++ )
	{
	  M[i][j] = 0;
	}
    }

  for( i=0; i<n; i++ )
    {
      scanf("%d%d", &u, &k);
      u--;
      for( j=0; j<k; j++ )
	{
	  scanf("%d", &v);
	  v--;
	  M[u][v] = 1;
	}
    }

  dfs();

  return 0;
}



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

int main()
{
    
    int N;
    string S;
    cin>>N>>S;
    
    vector<int> R;
    vector<int> G;
    vector<int> B;
    for(int i = 0; i < S.size(); i++){
        if(S[i] == 'R')
            R.push_back(i);
        else if(S[i] == 'G')
            G.push_back(i);
        else
            B.push_back(i);
    }
    //cout<<S<<endl;
    
    ll ans = 0;
    for(int i = 0; i < R.size(); i++){
        for(int j = 0; j < G.size(); j++){
            int right, left, diff;
            if(R[i] > G[j]){
                right = R[i];
                left = G[j];
            }else{
                right = G[j];
                left = R[i];
            }
            
            diff = right - left;
        
            ans += B.size();    
            if(diff%2 == 0){
                if(binary_search(B.begin(), B.end(), (left + diff/2)))
                    ans = ans - 1;
            }
            if(binary_search(B.begin(), B.end(), right + diff))
                ans = ans - 1;
            if(binary_search(B.begin(), B.end(), left - diff))
               ans = ans - 1;
        
        }
    }
    cout<<ans<<endl;
    
    return 0;

}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
} 
int main() {
   int n;cin>>n;
   vector<P> p(n);
   rep(i,n){
       int a,b;cin>>a>>b;
       p.at(i).second=a-b;
       p.at(i).first=a+b;
   }
   sort(ALL(p));
   ll hoji= -1*INF;
   int ans=0;
   rep(i,n){
       if(hoji<=p.at(i).second){hoji=p.at(i).first;ans++;}
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>

using namespace std;

bool S[60000]={true};

void set()
{
	fill(S,S+60000,true);
	for(int i=2;i<60000;i++)
	{
		if(S[i]==true)
		{
			for(int j=2;j*i<60000;j++)
			{
				S[j*i]=false;
			}
		}
	}
}

int main()
{
	int n;
	set();
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=n-1;true;i--)
		{
			if(S[i])
			{
				printf("%d ",i);
				break;
			}
		}
		for(int i=n+1;true;i++)
		{
			if(S[i])
			{
				printf("%d\n",i);
				break;
			}
		}
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
 
using namespace std;
 
int main() {
    int n;
    string tcard, hcard;
    int tcount = 0, hcount = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> tcard >> hcard;
        if (tcard == hcard) {
            tcount++;
            hcount++;
        } else if (tcard > hcard) {
            tcount += 3;
        } else {
            hcount += 3;
        }
    }
    cout << tcount << " " << hcount << endl;
    return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  bool flag = false;
  for(int i=1;i<10;i++){
    for(int j=1;j<10;j++){
      if (i*j == N) flag = true;
    }
  }
  if (flag){
    cout << "Yes";
  }else{
    cout << "No";
  }
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 3608
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
typedef long long ll;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N, M;
    cin >> N >> M;
    string s;
    cin >> s;

    using pii = pair<int, int>;
    vector<int> dp(N + 1, INF);
    // dp[i]:=i文字目から出発したときの最短距離
    multiset<int> st;
    st.insert(0);
    dp[N] = 0;
    for(int i = N - 1; i >= 0; i--) {
        if(s[i] != '1') {
            if(st.empty()) {
                cout << -1 << endl;
                return 0;
            }
            int p = *st.begin();
            dp[i] = p + 1;
            st.insert(p + 1);
        }
        if(N - i >= M) {
            if(dp[i + M] != INF) {
                auto itr = st.find(dp[i + M]);
                if(itr != st.end()) {
                    st.erase(itr);
                }
            }
        }
    }
    int now = dp[0];
    int nowidx = 0;
    rep(i, N + 1) {
        if(dp[i] < now) {
            now = dp[i];
            cout << i - nowidx << " ";
            nowidx = i;
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3328
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

//#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
//#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#include <array>
//#include <atomic>
#include <chrono>
//#include <condition_variable>
#include <forward_list>
//#include <future>
#include <initializer_list>
//#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
//#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>


using namespace std;

template<typename T>
class UF
{
public:
	UF ()
	{
		count = 0;
	}
	void push ( T a )
	{
		M[a] = count;
		V.push_back ( count );
		rank.push_back ( 0 );
		count++;
	}

	void unite ( T a , T b )
	{
		long long int x = find ( M[a] );
		long long int y = find ( M[b] );
		if( x == y )return;
		if( rank[x] < rank[y] )
		{
			V[x] = y;
		} else
		{
			V[y] = x;
			if( rank[x] == rank[y] )rank[x]++;
		}
	}
	void merge ( T a , T b )
	{
		unite ( a , b );
	}
	bool same ( T a , T b )
	{
		return find ( M[a] ) == find ( M[b] );
	}
	long long int group ()
	{
		set < long long int > S;
		for( long long int i = 0; i < V.size (); i++ )
		{
			S.insert ( find ( V[i] ) );
		}
		return S.size ();
	}

private:
	vector<long long int>V , rank;
	map < T , long long int>M;
	long long int count;

	long long int find ( long long int x )
	{
		if( V[x] == x )return x;
		else return V[x] = find ( V[x] );
	}
};

int main ()
{
	int V , d;
	int data[1001] = {};
	data[0] = 2;
	data[1] = 3;
	for( size_t i = 2; i < 1001; i++ )
	{
		data[i] = data[i - 1] + data[i - 2];
		data[i] %= 1001;
	}

	while( cin >> V >> d )
	{
		UF<int>* uf = new UF < int > ;
		set<int>S;
		for( size_t i = 0; i < V; i++ )
		{
			S.insert( data[i] );
		}
		for( auto x : S )
		{
			( *uf ).push ( x );
		}
		for( size_t i = 0; i < V; i++ )
		{
			for( size_t j = i + 1; j < V; j++ )
			{
				if( abs ( data[i] - data[j] ) < d )
				{
					( *uf ).merge ( data[i] , data[j] );
				}
			}
		}
		cout << ( *uf ).group () << endl;
		delete uf;
	}
}

Measured memory_bytes: 1256
#include <stdio.h>
#include <math.h>

const int inf = 2e9;

int n;
int a[100100][3], dp[100100][3];

int max(int a, int b) {
    return (a > b ? a : b);
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) scanf("%d", &a[i][j]);
    }
    for (int i = 0; i < 3; i++) dp[0][i] = a[0][i];
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j != k) dp[i][j] = max(dp[i][j], dp[i - 1][k] + a[i][j]);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < 3; i++) ans = max(ans, dp[n - 1][i]);
    printf("%d\n", ans);
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(){
  string S;
  cin >>S;
  int count = 0;
  for(int i=0; S[i]!='\0';i++){
    if(S[i] == 'x')count++;
  }
  if(count>= 8)cout << "NO" << endl;
  else cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<set>

using namespace std;

int N;
int a[100005], b[100005];

long long int c[100005];

int Q, K;

int x[100005], y[100005];

vector<int> Adj[100005];

long long int dis[100005];
set<int> S;
int check[100005];

int main(void) {

	cin >> N;
	int tmp_1;
	long long int tmp_2;
	for (int i = 1; i <= N - 1; i++) {
		cin >> tmp_1; a[i] = tmp_1;
		cin >> tmp_1; b[i] = tmp_1;
		cin >> tmp_2; c[i] = tmp_2;
	}

	cin >> Q >> K; 

	for (int i = 1; i <= Q; i++) {
		cin >> tmp_1; x[i] = tmp_1;
		cin >> tmp_1; y[i] = tmp_1;
	}

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

	for (int k = 1; k <= N - 1; k++) {
		Adj[a[k]].push_back(k);
		Adj[b[k]].push_back(k);
	}

	/*for (int k = 1; k <= N - 1; k++) {
		cout << "Adj[" << k << "]= ";
		for (int j = 0; j < (int)Adj[k].size(); j++) { cout << " " << Adj[k][j]; }
	}*/
	dis[K] = 0; check[K] = 1;

	S.insert(K);
	while (S.size() > 0) {
		int M = *(S.begin());
		for (int k = 0; k < (int)Adj[M].size(); k++) {
			int next = a[Adj[M][k]]; 
			if (next == M) { next = b[Adj[M][k]]; } 
			if (check[next] == 0) { dis[next] = dis[M] + c[Adj[M][k]]; check[next] = 1; S.insert(next); }
		}
		S.erase(M);
	}


	for (int i = 1; i <= N; i++) {
		//cout << i << "  dis= " << dis[i] << endl;
	}
	for (int i = 1; i <= Q; i++) {
		cout << dis[x[i]] + dis[y[i]] << endl;
	}

	//system("pause");
	return 0;
}

Measured memory_bytes: 15352
import math

t = int(input())
ans = t - 1

def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

flg = is_prime(t)

tmp = math.sqrt(t)
a = math.ceil(tmp)
#print(a)

if flg == True:
    ans = t -1
else:
    for i in range(0 , a + 1):
        if t % (a - i) == 0:
            syou = int(t/(a - i))
            ans = (a - i) + syou - 2
            break

# for i in range(0, a + 1):
#     if a * (a - i) == t:
#         ans = a + (a-i) -2
#         break

print(ans)




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

using namespace std;
using ll = long long;

#define MOD 998244353
template<int mod>
struct ModInt{
   int x;
   ModInt():x(0){}
   ModInt(long long y):x(y>=0?y%mod:(mod-(-y)%mod)%mod){}
   ModInt &operator+=(const ModInt &p){
       if((x+=p.x)>=mod)x-=mod;
       return *this;
   }
   ModInt &operator-=(const ModInt &p){
       if((x+=mod-p.x)>=mod)x-=mod;
       return *this;
   }
   ModInt &operator*=(const ModInt &p){
       x=(int)(1LL*x*p.x%mod);
       return *this;
   }
   ModInt &operator/=(const ModInt &p){
       *this*=p.inverse();
       return *this;
   }
   ModInt &operator^=(long long p){
       ModInt res = 1;
       for (; p; p >>= 1) {
           if (p & 1) res *= *this;
           *this *= *this;
       }
       return *this = res;
   }
   ModInt operator-()const{return ModInt(-x);}
   ModInt operator+(const ModInt &p)const{return ModInt(*this)+=p;}
   ModInt operator-(const ModInt &p)const{return ModInt(*this)-=p;}
   ModInt operator*(const ModInt &p)const{return ModInt(*this)*=p;}
   ModInt operator/(const ModInt &p)const{return ModInt(*this)/=p;}
   ModInt operator^(long long p)const{return ModInt(*this)^=p;}
   bool operator==(const ModInt &p)const{return x==p.x;}
   bool operator!=(const ModInt &p)const{return x!=p.x;}
   explicit operator int() const { return x; }
   ModInt operator=(const int p) {x = p; return ModInt(*this);}
   ModInt inverse()const{
       int a=x,b=mod,u=1,v=0,t;
       while(b>0){
           t=a/b;
           a-=t*b;
           std::swap(a,b);
           u-=t*v;
           std::swap(u,v);
       }
       return ModInt(u);
   }
   friend std::ostream &operator<<(std::ostream &os,const ModInt<mod> &p){
       return os<<p.x;
   }
   friend std::istream &operator>>(std::istream &is,ModInt<mod> &a){
       long long x;
       is>>x;
       a=ModInt<mod>(x);
       return (is);
   }
};
typedef ModInt<MOD> mint;


int main()
{
    int n, s; cin >> n >> s;
    vector<vector<mint>> dp(n + 1, vector<mint>(s + 1)); //dp[i][j] := i個目まで見た時にsumがjになる場合の数
    vector<int> a(n);
    for(int i = 0; i < n; i++)cin >> a[i];

    dp[0][0] = 1;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j <= s; j++) {
            dp[i + 1][j] += dp[i][j] * 2;
            if(j + a[i] <= s)dp[i + 1][j + a[i]] += dp[i][j];
        }
    }
    cout << dp[n][s] << endl;
}

Measured memory_bytes: 38904
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
graph=[0 for i in range(N+1)]

for i,value in enumerate(A):
    graph[i+1]=value

stack=[1]
visited=[0 for i in range(N+1)]
C=[]
ct=0
while stack:
    x=stack.pop()
    if visited[x]==0:
        ct+=1
        visited[x]+=1
        stack.append(graph[x])
        C.append(x)
        
stack=[graph[C[-1]]]
visited=[0 for i in range(N+1)]
counter=0
while stack:
    x=stack.pop()
    if visited[x]==0:
        visited[x]+=1
        stack.append(graph[x])
        counter+=1

if K>=(ct-counter):
    stack=[graph[C[-1]]]
    for i in range((K-(ct-counter))%(counter)):
        x=stack.pop()
        stack.append(graph[x])

    print(stack[0])
else:
    stack=[1]
    for i in range(K):
        x=stack.pop()
        stack.append(graph[x])

    print(stack[0])

Measured memory_bytes: 134412
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int A, B, K, i;
    int output[200];
    for (i = 0; i < 200; ++i)
    {
        output[i] = 0;
    }
    if(scanf("%d", &A) < 0) exit(1);
    if(scanf("%d", &B) < 0) exit(1);
    if(scanf("%d", &K) < 0) exit(1);
    int x, y;
    for (i = 0; i < K; ++i)
    {
        x = A + i;
        y = B - i;
        if (x >= y) {
            output[i] = x;
            break;
        } else if (x+1 == y) {
            output[i] = x;
            output[200 - i - 1] = y;
            break;
        } else {
            output[i] = x;
            output[200 - i - 1] = y;
        }
    }
    for (i = 0; i < 200; ++i)
    {
        if (output[i] != 0)
        {
            printf("%d\n", output[i]);
        }
    }

    return 0;
}

Measured memory_bytes: 128
S = list(map(str, input()))
q = int(input())
Q =[list(map(str, input().split())) for k in range(q)]
rev = False
f1 = []
f2 = []
def pls(n):
    global rev
    if n[0] == "1":
        rev = not rev
    else:
        if n[1] == "1":
            if rev:
                f2.append(n[2])
            else:
                f1.append(n[2])
        else:
            if rev:
                f1.append(n[2])
            else:
                f2.append(n[2])

for k in range(q):
    pls(Q[k])

if rev:
    S.reverse()
    f2.reverse()
    ans = f2 + S + f1
else:
    f1.reverse()
    ans = f1 + S + f2

print("".join(map(str, ans)))


Measured memory_bytes: 47440
#include <iostream>
#include <cmath>
using namespace std;
int main(){
    int x,y,z,idx=0,sum;
    int formula = 0;
    int n;cin>>n;
    int start = 1;
    while(start <= n){
            int sqr = sqrt(start);
            sum = 0;
            for(x=1;x<=sqr;x++){
                for(y=1;y<=sqr;y++){
                    for(z=1;z<=sqr;z++){
                        formula = (x*x)+(y*y)+(z*z)+(x*y)+(y*z)+(z*x);
                        if(formula == start)
                            sum++;
                        else if(formula > start)
                            break;
                    }
                }
            }
            cout<<sum<<endl;
            start++;
    }
    return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
long long a,k;
vector<int>n;
int main()
{
	cin>>a;
	for(int s=0;s<a;s++)
	{
		cin>>k;
		if((s+a+1)%2)n.push_back(k);
		else n.insert(n.begin(),k);
	}
	for(int s=0;s<a;s++)cout<<n[s]<<" ";
}


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


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


  int h1,m1,h2,m2,k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int hun = ((h2+24)*60 + m2 - ((h1*60)+m1))%(24*60);
  cout << hun - k << endl;
  
  
  return 0;
    

}


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

int main(){
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)scanf("%d",&arr[i]);
    long long dp[n][n];
    for(int i=0;i<n;i++)dp[i][i]=arr[i];
    for(int i=1;i<n;i++){
        for(int j=0;j<n-i;j++){
            dp[j][j+i] = max(arr[j+i]-dp[j][j+i-1],arr[j]-dp[j+1][j+i]);
        }
    }
    printf("%lld",dp[0][n-1]);
    return 0;
}

Measured memory_bytes: 49816
#include <bits/stdc++.h>
#include <numeric>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    string s;
    cin >> s;
    int a=0;
    for(int i=0;i<3;i++){
        if(s.at(i)=='1') a++;
    }
    cout << a << endl;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int a[3];
int main() {
    rep(i,3) cin >> a[i];
    sort(a,a+3);
    if (a[0] == 5 && a[1] == 5 && a[2] == 7) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3616
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


static int desc(const void *a, const void *b);
static int asc(const void *a, const void *b);

int main (void){
    int n,k,i,j;
    int x,y,z;
    int count = 0;
    double dx;
    int box[200001]={};
    char text[200001]={};
    char s[200001]={};
    char t[200001]={};
    char alf[256] = {"abcdefghijklmnopqrstuvwxyz"};
    char alfb[256] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
    char sample_text[256];
    i = 0;j = 0;
    // Input Area //
   // scanf("%d %d",x,y);
    scanf("%s",s);
    for (i = 0; i < strlen(s); i++){
        printf("x");
    }
    //scanf("%s",&sample_text);
    //scanf("%s",&text);

    /*
    scanf("%d",&n);
    for(i = 0; i < n; i++){
        scanf("%d",&box[i]);
    }
    for(i = 0; i < n; i++){
        printf("%d",box[i]);
    }
    printf("\n");
    qsort(box,n,sizeof(int),desc);
    
    */
    // Output Area //
    
    /*
    for(i = 0; i < n; i++){
        printf("%d",box[i]);
    }
    */

}

static int desc(const void *a, const void *b){
    return *(int *) b - *(int *) a;
}

static int asc(const void *a, const void *b){
    return *(int *) a - *(int *) b;
}


/* KonoLvBANK

配列降順ソート
qsort(box,n,sizeof(int),desc);
配列昇順ソート
qsort(box,n,sizeof(int),asc);

アルファベットを次の単語に変えるやつ
    while(1){
        if (text[i] == '\0'){
            break;
        }
        for(j = 0; j < 26; j++){
            if (text[i] == alf[j]){
                if (j != 25){
                    text[i] = alf[j + 1];
                }else{
                    text[i] = alf[0];
                }
                break;
            }
        }
        i++;
    }

*/


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

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

ll lcm(ll a, ll b){
  return a/gcd(a,b) * b;
}
ll func2(ll n){
  ll res = 0;
  while(n%2 == 0){
    n /= 2;
    res++;
  }
  return res;
}

ll zyou(ll a,ll b){//a＾b
  ll res = 1;
  for(int i = 1;i<=b;i++){
    res *= a;
  }
  return res;
}
struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t),weight(w){ }
};

typedef pair<int,int> P;
using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}


bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}

bool palin(string S){//回文判定
  int n = S.size();
  bool flag = true;
  if(n%2 == 0){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  else if(n%2 == 1){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  return flag;
}
int main(){
  int N;
  cin >> N;
  vector<ll> A(N);
  rep(i,N){
    cin >> A[i];
  }
  sort(A.begin(),A.end());
  A.push_back(0);
  vector<pair<ll,int>> p;
  int count = 1;
  rep(i,N){
    if(A[i] == A[i+1]) count++;
    else{
      p.push_back(make_pair(A[i],count));
      count = 1;
    }
  }

  sort(p.begin(),p.end());
  reverse(p.begin(),p.end());
  int c = 0;//同じ長さの辺が二つ以上ある組の数
  
  rep(i,p.size()){
    if(p[i].second >= 2) c++;
  }
  if(c < 2) cout << 0 << endl;
  else{
    vector<pair<ll,int>> p2;
    rep(i,p.size()){
      if(p[i].second >= 2) p2.push_back(p[i]);
    }
    if(p2[0].second >= 4) cout << p2[0].first * p2[0].first << endl;
    else cout << p2[0].first * p2[1].first << endl;
  }
 }

Measured memory_bytes: 4080