akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int a,b; cin >> a >> b;
    cout << a*b - a - b + 1 << endl;
}




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

int main(){
        int n,Num4=0,odd=0,Eve=0;
        long long int a;

        cin>>n;
        for(int i=0; i<n; ++i) {
                cin>>a;
                if(a%2==1)odd++;
                else if(a%4==0) Num4++;
                else Eve++;
        }

        if(Eve!=0)Num4--;

        if(odd-1<=Num4)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 256
n,y=map(int,input().split())
count=0
for i in range(n+1):
    for j in range(n+1-i):
        z=n-i-j
        if 10000*i+5000*j+1000*z==y:
            print(i,j,z)
            count+=1
            break
    else:
        continue
    break
if count==0:
    print(-1,-1,-1)

Measured memory_bytes: 9204
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
print(0 if n%1000 == 0 else 1000-n%1000)







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

using namespace std;

bool solve(int *a) {
    for (int i = 0; i < 26; i++) {
        if (a[i] % 2) return false;
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string w;
    cin >> w;
    int n = w.length();
    int a[26] = {};
    for (int i = 0; i < n; i++) a[w[i] - 'a']++;
    cout << (solve(a) ? "Yes\n" : "No\n");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;




ll dp[1111][11111];

int main(void) {
  ll i, j, k;
  ll H, N;
  ll a[1111], b[1111];
  cin >> H >> N;
  
  for(i=0; i<N; i++) {
    cin >> a[i] >> b[i];
  }
  
  for(i=0; i<=N; i++)
    for(j=0; j<=H; j++)
      dp[i][j]=INF;
  
  dp[0][0]=0;
  for(i=0; i<N; i++) {
    for(j=0; j<=H; j++) {
      chmin(dp[i+1][j], dp[i][j]);
      chmin(dp[i][min(H, j+a[i])], dp[i][j]+b[i]);
    }
  }
  
  pt(dp[N][H]);
  
}





Measured memory_bytes: 88192
//============================================================================
// Name        : tokuteigai.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int a,b,c,d;
	cin>>a>>b>>c;
	d=a+b;
	if(a>=c){
		cout<<"0"<<endl;
	}
	else if(d>=c){
		cout<<c-a<<endl;
	};
	if(d<c){
	cout<<"NA"<<endl;
	}
	return 0;
}



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

int main(void){
    int n,m;
    short int *x;
    int size=0;
    int i,j;
    int cnt;
    
    while(1){
        scanf("%d %d\n",&n,&m);
        if(n==0&&m==0)break;
     
        if(size<n){
            size=n;
            x=(short int*)malloc(sizeof(short int)*size);
        }
        for(i=0;i<n;i++)x[i]=0;
        
        j=0;
        for(i=1;i<n;i++){
            cnt=1;
            while(cnt<=m){
                j++;
                if(j>=n)j=0;
                if(x[j]==0)cnt++;
            }
            x[j]=1;
        }
        
        
        for(i=0;i<n;i++){
            if(x[i]==0){
                if(i==0)printf("%d\n",n);
                else printf("%d\n",i);
                break;
            }
        }
    }
    
    return 0;
}



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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

string s;

int main(void) {
  // Here your code !
  cin >> s;

  for (int i = 0; i < s.size(); i += 2) {
    if (!(s[i] == 'R' || s[i] == 'U' || s[i] == 'D')) {
      printf("No\n");
      return 0;
    }
  }

  for (int i = 1; i < s.size(); i += 2) {
    if (!(s[i] == 'L' || s[i] == 'U' || s[i] == 'D')) {
      printf("No\n");
      return 0;
    }
  }

  printf("Yes\n");

  return 0;
}


Measured memory_bytes: 256
# 山手線は34.5Km
# 一周一時間かかる
# 駅は29駅ある
import itertools
while True:
    n = int(input())  # n <= 10000
    if n == 0:
        break
    timestamps = [0 for _ in range(24 * 60 * 60 + 1)]
    for _ in range(n):
        start, end = input().split()
        start_h, start_m, start_s = map(int, start.split(":"))
        start_h = start_h * 60 * 60
        start_m = start_m * 60
        start_time = start_h + start_m + start_s
        end_h, end_m, end_s = map(int, end.split(":"))
        end_h = end_h * 60 * 60
        end_m = end_m * 60
        end_time = end_h + end_m + end_s
        timestamps[start_time + 1] += 1
        timestamps[end_time + 1] -= 1
    timestamps = list(itertools.accumulate(timestamps))
    print(max(timestamps))



Measured memory_bytes: 9636
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

const int MAXN = 1<<17;
int N = 1<<17;
struct Node { 
	ll val;
} SEG[10000000];

int e = 0;
int LFT[10000000], RGT[10000000];

int roots[MAXN];
    
int build(int l = 0, int r = N - 1) {
	//build from L to R inclusive. 
	int x = ++e;
	if (l == r){
		SEG[x].val = 0;
		LFT[x] = -1;
		RGT[x] = -1;
		return x;
	}
	int mid = (l + r)/2;
	LFT[x] = build(l, mid);
	RGT[x] = build(mid + 1, r);
	return x;
}

int upd(int cur, int pos, int set, int l = 0, int r = N - 1) {
	//set a[pos] = set in the root cur
	if (r < pos || pos < l) return cur;
	int x = ++e;
	//we're creating a new node
	if (l == r){
		SEG[x].val = SEG[cur].val+set;
		return x;
	}
	int m = (l+r)/2;
	LFT[x] = upd(LFT[cur], pos, set, l, m);
	RGT[x] = upd(RGT[cur], pos, set, m + 1, r);
	SEG[x].val = SEG[LFT[x]].val + SEG[RGT[x]].val;
	return x;
}

ll query(int cur, int L, int R, int l = 0, int r = N - 1){
	if (r < L || R < l) return 0LL;
	int m = (l + r)/2;
	if (L <= l && r <= R) return SEG[cur].val;
	return query(LFT[cur], L, R, l, m) + query(RGT[cur], L, R, m + 1, r);
}


int n,M;
vi todo[MX];

void solve(int x) {
    int ans = 0;
    for (int i = x; i <= M; i += x) {
        ans += query(roots[i-x+1],0,i);
        //cout << "AH " << i-x+1 << " " << i << " " << p.query(i-x+1,0,i) << "\n";
    }
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> M;
    F0R(i,n) {
        int a,b; cin >> a >> b;
        todo[a].pb(b);
    }
    vi emp;
    roots[M+1] = build();
    FORd(i,1,M+1) {
        roots[i] = roots[i+1];
        roots[i] = upd(roots[i],i,sz(todo[i]));
        for (int j: todo[i]) {
            //cout << "HI " << i << " " << j << "\n";
            //cout << "AA " << i << " " << query(roots[i],0,N-1) << " " << N << "\n";
            roots[i] = upd(roots[i],j+1,-1);
            //cout << "BB " << query(roots[i],0,N-1) << "\n";
        }
    }
    
    FOR(i,1,M+1) solve(i);
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 128512
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second

int n, k;

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

    for(int i = 0; i < n-k; ++i){
        if(a[i] < a[i+k]){
            cout << "Yes\n";
        }
        else{
            cout << "No\n";
        }
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3980
import java.util.*;
 
class Main {
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        while (true) {
                                int H = sc.nextInt(), W = sc.nextInt();
                                if (H == 0 && W == 0) {
                                        break;
                                }
                                for (int i = 0; i < H; i++) {
                                        for (int j = 0; j < W; j++) {
                                                if (i == 0 || j == 0 || i == H - 1 || j == W - 1) {
                                                        System.out.print("#");
                                                } else {
                                                        System.out.print(".");
                                                }
                                        }
                                        System.out.println("");
                                }
                                System.out.println("");
                        }
                }
        }
}


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

using namespace std;

int n,a,b;

int main()
{
    cin>>n;
    a=n%10;
    b=n/10;
    if(a==9||b==9)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;

}


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

int main(){

    int n;
    cin >> n;

    vector<long long>v(n);
    cin >> v[0];
    for(int i = 1; i < n; i++){
        cin >> v[i];
        v[i] += v[i-1];
    }

    long long min = 99999999999;
    for(int i = 0; i < n-1; i++){
        long long temp = abs(v[n-1] - v[i] - v[i]) ;
        if(temp < min) min = temp;
    }


    cout << min << endl;

}

Measured memory_bytes: 1792
#include <iostream>
#define inf (int)(1e9)
using namespace std;
int main()
{
    int n, m, cnt = 0, flag = 0, left = -1, right = inf, l, r;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        cin >> l >> r;
        left = max(left, l);
        right = min(right, r);
        if (left > right)
            flag = 1;
    }
    if (!flag)
    {
        cnt = (right - left + 1);
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

ll calc(ll a) {
  if (a <= 0) return 0;
  int now = 1;
  ll ret = 0;
  while((1LL<<now) <= a) {
    ll s = 1LL<<now;
    ll t = 1LL<<(now+1);

    ll tmp = (a+1)%t;
    if (tmp <= s) {
      now++;
      continue;
    }
    tmp = tmp-s;
    if (tmp&1) {
      ret += s;
    }
    now++;
  }

  ll r = a%4;
  if (r == 1 || r == 2) {
    ret++;
  }
  return ret;
}


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

  ll a, b; cin >> a >> b;
  //debug(calc(b));
  cout << (calc(b) ^ calc(a-1)) << endl;
}


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

using namespace std;
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;
typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,a,b) for (ll i=(a); i<(b); i++)
typedef pair<ll,ll> PLL;
// }}}

ull x,y;

bool f(ll n){
    // return x*pow(2,n-1) <= y;
    return x * (1ULL<<(n-1)) <= y;
}

signed main() {
    cin>>x>>y;
    ll L=1, R=63;
    while(L+1<R){
        ll M = (L+R)/2;
        if (f(M)){
            L=M;
        }else{
            R=M;
        }
    }
    cout<<L<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
using pii = pair<i32, i32>;
using vi32 = vector<i32>;
using vu32 = vector<u32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf64 = vector<f64>;
using vf80 = vector<f80>;
using vstr = vector<string>;
using vpii = vector<pii>;
using vvi32 = vector<vi32>;
using vvu32 = vector<vu32>;
using vvi64 = vector<vi64>;
using vvu64 = vector<vu64>;
using vvf64 = vector<vf64>;
using vvf80 = vector<vf80>;

template<typename T, typename S> bool amax(T &x, S y) { if (x < y) { x = y; return 1; } return 0; }
template<typename T, typename S> bool amin(T &x, S y) { if (y < x) { x = y; return 1; } return 0; }

deque<int> deq;

void rec(int x) {
  deq.push_front(x);
  if (x == 1) {
    return;
  } else if (x % 2 == 1) {
    rec(x - 1);
  } else {
    rec(x / 2);
  }
}

struct edge {
  int from, to, cost;
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  cerr << fixed << setprecision(16);
  int l;
  cin >> l;
  rec(l);
  vector<edge> e;
  int now = 1;
  for (auto d: deq) {
    if (d == 1) continue;
    if (d % 2 == 1) {
      e.push_back({1, now, d - 1});
    } else {
      for (auto &v: e) {
        v.cost *= 2;
      }
      e.push_back({now, now + 1, 1});
      e.push_back({now, now + 1, 0});
      now++;
    }
  }
  cout << now << " " << e.size() << endl;
  for (auto &v: e) {
    cout << v.from << " " << v.to << " " << v.cost << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
import bisect
input = sys.stdin.readline
 
def main():
    n=int(input())
    a = list(map(int,input().split()))
    s=[0, 0, 0, 0, 0, 0, 0, 0, 0]
    for i in range(n):
        if(a[i]>=3200):
            s[8]+=1
        else:
            s[(a[i]//400)]=1
    ans=0
    for i in range(8):
        ans+=s[i]
    M=ans+s[8]
    if(ans==0):
        ans=1
    print(ans,M)
    
    
main()


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c, d, N, ans=0, L, X;
    vector<int> v(3);
    char tmp, tmp2;
    string S, S2, S3;
    bool flag=true;
    
    cin >> N;

    // ans = a<=b ? a:a-1;

    
    ans = 3*N*N;
    cout << ans<< endl;

    // if(S[1]==S[2] &&(S[0]==S[1] | S[2]==S[3]))
    // 	cout << "Yes" <<endl;
    // else
    // 	cout << "No" <<endl;

    // string S;
    // cin >>S;
    // // cout << S + "pp"<<endl;
    // if(flag)
    // 	puts("Yes");
    // else
    // 	puts("No");
}



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

int main() {

  int n;
  while(1) {
  cin >> n;
  if(n == 0) break;

  int cnt = 0;
  int ans[1001];
    int id[1001],p[1001],q[1001],r[1001];
  for(int i=0;i<n;i++) {
    cin >> id[i] >> p[i] >> q[i]>> r[i];
  }
  int P,Q,R,C;
  cin >> P >> Q>>R>>C;

  int flg = 0;
  for(int i=0;i<n;i++){ 
    int cal = 4*p[i]+9*q[i]+4*r[i];
    if(P<p[i]||Q<q[i]||R<r[i]||C<cal) continue;
    cout << id[i]<<endl;
    flg = 1;
  }
  if(flg == 0) cout << "NA"<<endl;

  }

  return 0;
}

Measured memory_bytes: 1176
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N;cin>>N;
  ll a[N];
  ll i,j;
  rep(i,N) cin>>a[i];
  ll m1=0,m2=0;
  ll cnt=0;
  rep(i,N){
    m1=max(m1,a[i]);
  }
  rep(i,N){
    if(a[i]==m1) cnt++;
    else{
      m2=max(m2,a[i]);
    }
  }
  if(cnt>1){
    rep(i,N){
      cout<<m1<<endl;
    }
  }
  else{
    rep(i,N){
    if(a[i]==m1) cout<<m2<<endl;
    else cout<<m1<<endl;
    }
  }
}


Measured memory_bytes: 3200
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#define inf 0x3f3f3f3f
using namespace std;

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a&1||b&1||c&1)
	{
		cout<<"0"<<endl;
		return 0;
	}
	int aa=0,bb=0,cc=0;
	int cnt = 0;
	while(cnt<=10000)
	{	
		if(aa%2||bb%2||cc%2)
		{
			break;
		}
		aa=((b/2)+(c/2));
		bb=((a/2)+(c/2));
		cc=((a/2)+(b/2));
		a/=2;b/=2;c/=2;
		cnt++;
	
	}
	if(cnt>10000)
	{
		cout<<"-1"<<endl;
	}
	else
	cout<<cnt<<endl;
	
	return 0;
}

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

int main(){
  int n,r,b;
  char s;
  cin >> n;
  
  r=0;b=0;
  for( int i=0; i<n; i++){
    cin >> s;
    if( s == 'R') r++;
    else         b++;
  }
  
  if( r > b ) cout << "Yes" << endl;
  else        cout << "No"  << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int k,s,cnt=0;
int main(){
    cin>>k>>s;
    for(int x=0;x<=k;x++){
        for(int y=0;y<=k;y++){
            if(s-x-y>=0&&s-x-y<=k) cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int k = sc.nextInt();
    List<String> sub = new ArrayList<String>();
    String c;
    int count;
    for(int i = 0;i < s.length();i++){
      count = 0;
      for(int j = i+1;j <= s.length();j++){
        c = s.substring(i,j);
        if(!sub.contains(c)){
          sub.add(c);
        }
        count++;
        if(count == k){
          break;
        }
      }
    }
    Collections.sort(sub);
    System.out.println(sub.get(k-1));
  }
}

Measured memory_bytes: 26196
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <cassert>
using namespace std;
using vi = vector<int>;

int a[101010];

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
    
    int cnt = 0;
    int crt = 0;
    for (int z = 0; z < 101010; z++) {
        cnt++;
        crt = a[crt];
        if (crt == 1) {
            break;
        }
    }
    if (cnt > 100000) {
        cout << -1 << endl;
    } else {
        cout << cnt << endl;
    }
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	scanf("%d%d", &n,&k);
	int i = n / 2;
	if (n % 2) i++;
	
	if(i < k)
		printf("NO\n");
	else
		printf("YES\n");	
	
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var A, B int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d", &A, &B)

	fmt.Println((A - 1) * (B - 1))
}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int N;
    cin >> N;

    vi s(N);
    for (int i = 0; i < N; i++) {
        cin >> s[i];
    }

    vi t(N, -1);

    ll ans = 0;
    for (int amb = 1; amb <= (N - 1); amb++) {
        ll cand = s[0] + s[N-1];
        for (int km1 = 1; km1 * amb < N - 1; km1++) {
            int A = N - 1 - km1 * amb;
            int B = A - amb;
            int K = km1 + 1;

            if (B <= 0) break;

            bool fail = false;
            for (int u : { km1 * amb, A }) {
                if (t[u] == amb) {
                    fail = true;
                    break;
                } else {
                    cand += s[u];
                    t[u] = amb;
                }
            }
            if (fail) break;

            ans = max(ans, cand);
        }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
#include <complex>
using namespace std;
typedef long long LL;

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

	sort(d.begin(),d.end());
	d.erase(unique(d.begin(),d.end()),d.end());
	/*for (int i = 1; i < d.size(); i++) {
		if (d[i] == d[i - 1]) {
			d.erase(d.begin()+i);
			i=1;
		}
	}*/

	cout <<d.size()<<endl;

    return 0;
}

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

using namespace std;

int main(){
	long long n;
	cin >> n;
	vector<long long> vec(n,0);
	for(int i=0;i<n;i++)cin >> vec[i];
	
	sort(vec.begin(),vec.end());
	
	int op=0,op_a=0;
	while(op<n-1){
		for(int i=1+op;i<n;i++){
			vec[i]=vec[i]%vec[op_a];
			if(vec[i]==0)op++;		
		}
		sort(vec.begin(),vec.end());
		op_a=op;
	}
	cout << vec[op];
}

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

int main(){
  long long n, total=0;
  cin >> n;
  int line[n];
  for(int i=0;i<n;i++){
    cin >> line[i];
  }
  for(int i=0;i<n-1;i++){
    for(int j=i+1;j<n;j++){
      total += line[i]*line[j];
    }
  }
  cout << total << endl;
}

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

int main() {
 int n;
 cin >> n;
 int c1 = n / 1000;
 int c2 = n % 1000 / 100;
 int c3 = n % 100 / 10;
 int c4 = n % 10;
 if((c1 == c2 && c2 == c3) || (c2 == c3 && c3 == c4)){
  cout << "Yes" << endl;
 } else {
  cout << "No" << endl;
 }
}

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

#define ll long long int
#define ld long double
#define PRECISION 15
#define DEFAULT_MIN 10000000
#define DEFAULT_MAX -10000000
using namespace std;

int main(){
    int n, l, ans = 0, min = DEFAULT_MIN, tmp = 0;
    cin >> n >> l;
    int val[n];
    for(int i=0; i<n; i++){
        val[i] = i+l;
        ans += i+l;
    }
    for(int i=0; i<n; i++){
        if(abs(val[i]) < min){
            min = abs(val[i]);
            tmp = val[i];
        }
    }
    ans -= tmp;
    cout << ans << endl;
    return 0;
}


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

bool check(const std::vector<int> a) {
	const int n = a.size();
	const int min = *std::min_element(a.cbegin(), a.cend());
	const int max = *std::max_element(a.cbegin(), a.cend());
	if (max - min >= 2) {
		return false;
	}
	if (min == max && (min == n - 1 || min <= n / 2)) {
		return true;
	}
	const int c = max;
	int x = 0, y = 0;
	for (const auto &e : a) {
		if (e == c) {
			++y;
		}
		else {
			++x;
		}
	}
	if (y == 1) {
		return false;
	}
	return x + 1 <= c&&c <= x + y / 2;
}

int main() {
	int n;
	std::cin >> n;
	std::vector<int> a(n);
	for (auto &e : a) {
		std::cin >> e;
	}
	std::cout << (check(a) ? "Yes" : "No") << std::endl;
	return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<ll> vecll;
typedef vector<string> vecs;
template<class T,class U> using Hash=unordered_map<T,U>;
 
#define REP(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define RREP(i, a, n) for(ll i = n-1; i >= (ll)(a); i--)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, 0, n)
#define MD 1000000007
#define _SPLIT " "
 
template<class T> T read(){T a;cin >> a;return a;}
template<class T> void read(T& a){cin >> a;}
template<class T,class ...Args> void read(T& a, Args&... args){cin >> a; read(args...);} 
template<class T> void rarr(T a, int n){for(int i = 0; i < n; i++) {cin >> a[i];}}
template<class T> void write(T a){cout << setprecision(24) << a << endl;}
template<class T,class ...Args> void write(T a, Args... args){cout << setprecision(24) << a << _SPLIT; write(args...);}
template<class T> void warr(vector<T> a, const char* c = " "){cout << a[0];for(int i = 1; i < (int)a.size(); i++)cout << c << a[i];cout << endl;;}
template<class T> void warr(T a, int n, const char* c = " "){cout << a[0];for(int i = 1; i < n; i++)cout << c << a[i];cout << endl;}
void split(string s, string delim, veci& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(atoi(s.substr(pos).data()));break;}else {result.push_back(atoi(s.substr(pos, p - pos).data()));}pos = p + delim.size();}}
void split(string s, string delim, vecs& result){result.clear();string::size_type pos = 0;while(pos != string::npos){string::size_type p = s.find(delim, pos);if(p == string::npos){result.push_back(s.substr(pos));break;}else {result.push_back(s.substr(pos, p - pos));}pos = p + delim.size();}}
ll gcd(ll a, ll b){while(true){ll k = a % b;if(k == 0)return b;a = b;b = k;}}
ll comb(ll n, ll m){ll p=1;m=min(m,n-m);for(ll i=1;i<=m;i++){p*=n-i+1;p/=i;}return p;}

int main(void)
{
    int k,n,res=0;
    read(n,k);
    res=k;
    rep(i,n-1)res*=k-1;
    write(res);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int a[m]={0};
    int x,y;
    int k=n;
    while (n--)
    {
        cin>>x;
        while (x--)
        {
            cin>>y;
            y--;
            a[y]++;
        }


    }
    int count=0;
    for (int i = 0; i < m; ++i) {
        if(a[i]==k)
        {
            count++;
        }
    }
    cout<<count;
}


Measured memory_bytes: 256
/*
	ID:greenty2
	LANG:C++
	TASK:
	*/
	#include<bits/stdc++.h>
	using namespace std;
	int a[105];
	int book[10];
	int pd(int x)
	{
		if(x<=399)
		return 1;
		if(x<=799)
		return 2;
		if(x<=1199)
		return 3;
		if(x<=1599)
		return 4;
		if(x<=1999)
		return 5;
		if(x<=2399)
		return 6;
		if(x<=2799)
		return 7;
		if(x<=3199)
		return 8;	 
	}
	int main()
	{
			int n;
			cin>>n;
			int tot=0;
			for(int i=1;i<=n;i++)
			{
				cin>>a[i];
				if(a[i]<3200)
				{
					int t=pd(a[i]);
					book[t]=1;
				}
				else
				{
					tot++;
				}
			}
			int all=0;
			for(int i=1;i<=8;i++)
			{
				all+=book[i];
			}
			int all2=all+tot;
			if(all==0)
			all=1;
			cout<<all<<" "<<all2<<endl; 
			
	}

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

int main(){
	int m;
	string s;
	int h;
	while(1){
		cin >> s;
		if(s == "-") break;
		cin >> m;
		for(int i = 0; i < m; i++){
			cin >> h;
			for(int k = 0; k < h; k++){
				s += s[0];
				s.erase(0,1);
			}
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 3220
import java.util.Scanner

/**
  * Created by goryudyuma on 2017/07/16.
  */


object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val N = sc.nextInt()
    val K = sc.nextInt()
    val arr: Array[Int] = new Array[Int](N)

    for (i <- 0 until N) {
      arr(i) = sc.nextInt()
    }
    val sortedArr = arr.sorted.reverse

    var ans = 0
    for (i <- 0 until K) {
      ans += sortedArr(i)
    }

    println(ans)
  }
}


Measured memory_bytes: 27196
#include <iostream>
#include <vector>

using namespace std;

static int W, H;
static vector<string> field;

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

int dfs(int x, int y) {
    if (x < 0 || x >= W || y < 0 || y >= H || field[y][x] == '#')
        return 0;

    field[y][x] = '#';
    int sum = 0;
    for (int k = 0; k < 4; k++) {
        sum += dfs(x + dx[k], y + dy[k]);
    }

    return sum + 1;
}

int main() {
    for (;;) {
        cin >> W >> H;
        if (W == 0) break;

        field.resize(H);
        int sx, sy;
        for (int y = 0; y < H; y++) {
            cin >> field[y];
            for (int x = 0; x < W; x++) {
                if (field[y][x] == '@') {
                    sx = x;
                    sy = y;
                    field[y][x] = '.';
                }
            }
        }

        cout << dfs(sx, sy) << endl;
    }
}

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

int main(){
    long long n,in;scanf("%lld",&n);
    vector<int> a;
    for(long long i=0;i<n*3;i++){
        scanf("%lld",&in);
        a.push_back(in);
    }
    sort(a.begin(),a.end());
    long long ans=0;
    for(long long i=n;i<n*3;i+=2)
        ans+=a[i];
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) begin(v), end(v)
#define allg(v) begin(v), end(v), greater<int>()



int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  string s;
  cin >> s;
  
  //vector<int> a(n);  rep(i, 0, n) cin >> a.at(i);
  
  cout << (s.find("AC") == string::npos ?"No" :"Yes") << "\n";
  
  //cout << fixed << setprecision(10) << n << "\n";

}


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

int main(void)
{
    int n, d;
    cin >> n >> d;
    vector<vector<int>> x(n, vector<int> (d));
    rep(i, n)rep(j, d)
    {
        cin >> x[i][j];
    }
    int ans = 0;
    rep(i, n)rep(j, n)
    {
        if(i >= j) continue;
        int sum = 0;
        rep(k, d){
            sum += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
        }
        int tmp = sqrt(sum);
        if(tmp*tmp == sum) ans++;
        //if(tmp*tmp == sum) cout << i << " " << j << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		int a = A-1; //等差
		int x = 0;
		while(a*x +1 < B) {
			x++;
		}
		
		System.out.println(x);
		
		sc.close();	
	}
}

Measured memory_bytes: 21844
S=input()
if S[0]=='A' and S.count('C', 2, len(S)-1)==1:
  L = list(S)
  del L[S.find('C', 2, len(S)-1)]
  del L[0]
  for i in L:
    if i.isupper() is True:
      A = 'WA'
      break
    else:
      A = 'AC'
  print(A)
else:
  print('WA')

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

AP = True
for aa in a:
    if aa % 2 == 0:
        if aa % 3 != 0 and aa % 5 != 0:
            AP = False

if AP:
    print('APPROVED')
else:
    print('DENIED')

Measured memory_bytes: 2940
#include<stdio.h>

#define S_SIZE 100001

char s[S_SIZE];

typedef struct{
  char c;
  struct Deque *prev;
  struct Deque *next;

} Deque;

int main(void) {
  int query_size,str_size;
  int reverse = 0;
  Deque *head,*tail,*tmp;
  head = (Deque *)malloc(sizeof(Deque));

  scanf("%s",s);
  scanf("%d",&query_size);

  head->c = s[0];
  head->next = NULL; head->prev = NULL;
  tail = head;

  str_size = strlen(s);
  for(int i = 1;i < str_size;i++) {
    tmp = (Deque *)malloc(sizeof(Deque));
    tmp->c = s[i];
    head->next = tmp;
    tmp->next = NULL;
    tmp->prev = head;
    head = tmp;
  };

  for(int i = 0;i < query_size;i++) {
    int t,f;
    char c;
    scanf("%d",&t);

    if(t==1) {
      reverse = (reverse == 0)? 1:0;
      continue;
    }
    scanf("%d %c",&f,&c);
    tmp = (Deque *)malloc(sizeof(Deque));
    tmp->c = c;
    if((f==1 && reverse == 1) || (f==2 && reverse == 0)) {
      // 末尾追加
      head->next = tmp;
      tmp->next = NULL;
      tmp->prev = head;
      head = tmp;
    } else {
      // 先頭追加
      tail->prev = tmp;
      tmp->next = tail;
      tmp->prev = NULL;
      tail = tmp;
    }
  }

  if(reverse == 0) {
    for(Deque *d = tail;d != NULL;d = d->next) {
      printf("%c",d->c);
    }
  } else {
    for(Deque *d = head;d != NULL;d = d->prev) {
      printf("%c",d->c);
    }
  }
}


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

int main(){
  string s;
  cin>>s;
  bool ans=true;
  int cnt=0;
  for(int i=0;i<s.size();i++){
    if(isupper(s[i])) cnt++;
  }
  if(cnt!=2) ans=false;
  cnt=0;
  if(s[0]!='A') ans=false;
  for(int i=2;i<s.size()-1;i++){
    if(s[i]=='C') cnt++;
  }
  if(cnt!=1) ans=false;
  if(ans) cout<<"AC"<<endl;
  else cout<<"WA"<<endl;
}


Measured memory_bytes: 3640
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int n1 = n / 1000;
		int n2 = n % 1000 / 100;
		int n3 = n % 1000 % 100 / 10;
		int n4 = n % 1000 % 100 % 10;
		boolean ans = false;
		if (n2 == n3 && (n1 == n2 || n3 == n4)) {
			ans = true;
		}
		System.out.println(ans ? "Yes" : "No");
	}
}


Measured memory_bytes: 35828
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

ll mpow(ll x, ll n) { ll y = 1; for (; n; n /= 2) { y = n % 2 ? y * x % MOD : y; x = x * x % MOD; } return y; }

int N;
vv<int> tree;
vector<int> subt;

void dfs_pre(int v, int p) {
    subt[v] = 1;
    for (int u : tree[v]) {
        if (u == p) continue;
        dfs_pre(u, v);
        subt[v] += subt[u];
    }
}

ll dfs(int v, int p) {
    ll inv2 = mpow(2, MOD - 2);

    int pt = N - 1;
    for (int u : tree[v]) {
        if (u == p) continue;
        pt -= subt[u];
    }

    ll res = 1;
    res = (res - mpow(inv2, N - 1) + MOD) % MOD;
    res = (res - mpow(inv2, N - 1 - pt) * (1 - mpow(inv2, pt) + MOD) % MOD + MOD) % MOD;
    for (int u : tree[v]) {
        if (u == p) continue;
        res = (res - mpow(inv2, N - 1 - subt[u]) * (1 - mpow(inv2, subt[u]) + MOD) % MOD + MOD) % MOD;
    }
    res = res * inv2 % MOD;

    for (int u : tree[v]) {
        if (u == p) continue;
        res = (res + dfs(u, v)) % MOD;
    }
    return res;
}

int main() {
    cin >> N;
    tree.resize(N);
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    
    subt.resize(N);
    dfs_pre(0, -1);
    write(dfs(0, -1));
}

Measured memory_bytes: 23168
s = input()[::-1]

counts = [0] * 2019
counts[0] = 1

num = 0
d = 1

for char in s:
	num += int(char) * d
	num %= 2019
	d *= 10
	d%= 2019
	counts[num] += 1

ans = 0
for cnt in counts:
	ans += cnt * (cnt - 1) // 2

print(ans)



Measured memory_bytes: 68496
//17D8104027L , Nishimura Tatsuya , sbten_der
# include<iostream>
# include<cmath>
using namespace std;
#define N 10000
int main()
{
    int n, a[N];
    cin >> n;
    int cnt = n;
    for(int i=0; i<n; i++) cin >> a[i];
    for(int j=0; j<n; j++){
        int i = 2;
        do{
            if(a[j] != 2 && a[j] % i == 0){
                cnt--;
                break;
            }
            i++;
        }while( i<=(int)sqrt(a[j]));
    }
    cout << cnt <<"\n";
    return 0;
}



Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define fir first
#define sec second
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
#define N 100005
vector<int> G[N];
int n,x,y;
int dep[N];
int maxd[N],fa[N];
void dfs(int u,int Fa)
{
//	printf("%d %d\n",u,Fa);
	dep[u]=dep[Fa]+1;
	fa[u]=Fa;
	for(int v:G[u])
	{
		if(v==Fa) continue;
		dfs(v,u);
		if(maxd[v]>maxd[u]) maxd[u]=maxd[v];
	}
	if(dep[u]>maxd[u]) maxd[u]=dep[u];
}

signed main()
{
#ifdef __LOCAL__
	freopen("in.txt","r",stdin);
#endif
	cin>>n>>x>>y;
	for(int i=1;i<n;i++)
	{
		int u=read(),v=read();
		G[u].pb(v),G[v].pb(u);
	}
	dfs(y,0);
//	cout<<"Passed\n";
	int go=(dep[x]-2)/2;
	int xx=(dep[x]-1)%2;
//	cout<<dep[x]<<endl;
	for(int i=1;i<=go;i++) x=fa[x];
	int res=maxd[x]-dep[x];
//	cout<<dep[x]<<endl;
//	cout<<res<<endl;
	if(xx) cout<<go+res<<endl;
	else cout<<go+res+1<<endl;
#ifdef __LOCAL__
	printf("Time Used : %d\n",clock());
#endif
	return 0;
}



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

int main(){
    int N, M;
    int a[50],b[50];
    int m[50] = {0};
    cin >> N >> M;
    for (int i=1; i<M+1; i++) {
        cin >> a[i] >> b[i];
        m[a[i]] += 1; 
        m[b[i]] += 1;
    }
    for (int i=1; i<N+1; i++) {
        cout << m[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

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

    int cmn = 0;
    for(int i=0; i<s.size(); i++){
        bool flg = true;
        for(int j=0; j<N-i; j++) if(s[i+j] != t[j]) flg = false;
        if(flg){
            cout << 2*N-(N-i) << endl;
            return 0;
        }
    }

    cout << 2*N << endl;
}

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

const ll MAXN = 100000;

ll N, ans=0, tmp1=1000000005, tmp2=0;
vector<ll> A(MAXN, 0);

signed main(){
    cin >> N;
    for(int i=0;i<N;i++) {
        cin >> A[i];
        ans += abs(A[i]);
        tmp1 = min(tmp1, abs(A[i]));
        if(A[i]<0) tmp2++;
    }
    if(tmp2%2==1) ans -= 2*tmp1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
 
ll pwr(ll base, ll p, ll mod=MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}
 
 
ll gcd(ll a, ll b){
    if(b == 0)  return a;
    return gcd(b, a%b);
}

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

    ll n, a, b;
    cin>>n>>a>>b;

    if(a > b){
    	cout<<"0";
    	return 0;
    }

    if(n == 1){
    	if(a == b)	cout<<"1";
    	else	cout<<"0";
    	return 0;
    }
 
 	cout<<(a+b+(n-2)*b) - (a+b+(n-2)*a) + 1;
    return 0;
}
 
 
 



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

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

# 余り0以上は全ての組
if K == 0:
    print(N*N)
    exit()

ans = 0
# 割られる数でループ
for i in range(1, N+1):
    # 割られる数がK以下ならmodしてKはあり得ない
    if i <= K:
        continue
    # 確実に入る分
    ans += N // i * (i-K)
    # 最後の分を調整
    ans += max(N % i - K + 1, 0)
print(ans)


Measured memory_bytes: 2940
//第8回シンデレラガール総選挙は是非本田未央ちゃんに投票をお願いします！
//ファンのことも他のアイドルの子たちのことも本当に大事にしてて、今まで周りに色んなものを与えてくれました。
//今度は私たちが未央ちゃんにお返しをする番です。みんなでガラスの靴を履かせてあげましょう！
// #本田未央を一番星に #本田未央を令和のシンデレラガールに #第8回シンデレラガール総選挙
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
lint dp[200100];
int ne[200100],mn[200100],c[200100];
int main()
{
	int inf=200100,n;
	cin>>n;rep(i,n) cin>>c[i];
	rep(i,n+10) mn[i]=inf;
	for(int i=n-1;i>=0;i--){
		ne[i]=mn[c[i]];
		mn[c[i]]=i;
	}
	memset(dp,0,sizeof(dp));
	dp[0]=1;
	lint mo=1000000007;
	rep(i,n){
		dp[i]%=mo;
		dp[i+1]+=dp[i];
		if(ne[i]<inf && ne[i]>i+1) dp[ne[i]]+=dp[i];
	}
	cout<<dp[n]%mo<<endl;
}


Measured memory_bytes: 4096
// 2020-07-24 05:57:33
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int n;
  cin >> n;
  multiset<int> zero;
  zero.insert(0);
  zero.insert(0);
  zero.insert(n+1);
  zero.insert(n+1);
  vector<int> mp(n+1, 0);
  rep(i, n) {
    ll p;
    cin >> p;
    mp[p] = i+1;
  }
  ll ans = 0;
  REPCM(x_, n, 1) {
    ll x = x_, idx = mp[x];
    ll l2, l1, r1, r2;
    {
      auto itr = zero.upper_bound(idx);
      r1 = *itr;
      r2 = *(next(itr));
      itr--;
      l1 = *itr;
      l2 = *(prev(itr));
    }
    ans += x * ((l1 - l2) * (r1 - idx) + (idx - l1) * (r2 - r1));
    zero.insert(idx);
  }
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 8268
#include <stdio.h>

#include <iostream>
#include <vector>
#include <array>

constexpr int64_t MOD = 1'000'000'007;
constexpr int64_t help = 1;

int main() {
	int64_t n;

	std::cin >> n;

	std::array<uint64_t, 62> bits{};
	for (int64_t i = 0; i < n; i++) {
		int64_t d;
		std::cin >> d;
		for (int64_t b = 0; b < 62; b++) {
			bits[b] += !!(d & (help << b));
		}
	}

	int64_t ans = 0;

	for (int64_t b = 0; b < 62; b++) {
		int64_t p = (help << b) % MOD;
		ans += (bits[b]*(n-bits[b]) % MOD) * p;
		ans %= MOD;
	}

	std::cout << ans;
  return 0;
}


Measured memory_bytes: 3576
#include <iostream>

using namespace std;

int main()
{
    float n,t,a,x,indx,minn=1000000;
    float b=0.006;
    cin>>n>>t>>a;
    for(int i=0; i<n; i++){
        cin>>x;
        if((a-(t-x*b))*(a-(t-x*b))<minn){
            minn=(a-(t-x*b))*(a-(t-x*b));
            indx=i+1;
        }

    }
    cout<<indx;
    return 0;

}


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

const ll INF = 1LL << 60;
const int mod = 1e9 + 7;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

ll X, Y;
int main() {
    cin >> X >> Y;
    combination comb = combination(1e6 + 10);

    // 可能かどうか
    ll tmp_1 = -1;
    ll tmp_2 = -1;
    for (int i = 0; i <= X; i++) {
        ll tmp_y = i * 2;
        ll tmp_x = i * 1;

        ll rest_y = Y - tmp_y;
        ll rest_x = X - tmp_x;
        if (rest_x == rest_y * 2) {
            tmp_1 = i;
            tmp_2 = rest_y;
            break;
        }
    }
    if (tmp_1 == -1) {
        cout << 0 << endl;
        return 0;
    }

    mint ans = comb(tmp_1 + tmp_2, tmp_1);
    cout << ans << endl;
}

Measured memory_bytes: 15872