akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
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;}

int main()
{
  int N;
  cin >> N;
  map<string,ll> M;
 
  REP(i,N){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    M[s]++;
  }
  
  ll ans = 0;
  for(auto m : M){
   ans += m.second*(m.second-1)/2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 11136
import sys
import os
import math
from decimal import Decimal

Q = 10 ** -14


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    a, b, c = list(map(int, sys.stdin.readline().split()))
    d = c - a - b
    if d > 0 and 4 * a * b < d**2:
        print('Yes')
    else:
        print('No')



if __name__ == '__main__':
    main()


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

int main()
{
 int t,i;
 double x1,y1,x2,y2,p,q,z;

              scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
              p=x2-x1;
              q=y2-y1;
              z=p*p+q*q;
              printf("%lf\n",sqrt(z));
              
 return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <algorithm>
#define F(i,a,n) for(int i = (a); i < (n); ++i)
using namespace std;
int N,M;
bool graph[51][51];
bool visited[51];
int ans = 0;
int dfs(int x){
  if(visited[x]){
    return 0;
  }
  visited[x] = true;
  F(i,1,N+1){
    if(graph[x][i]) dfs(i);
  }
}

int main(){
  cin >> N >> M;
  F(i,0,N+1)
    F(j,0,N+1) graph[i][j] = false;
  int input[M][2];
  F(i,0,M){
    int x,y;
    cin >> x >> y;
    input[i][0] = x;
    input[i][1] = y;
    graph[x][y] = true;
    graph[y][x] = true;
  }
  F(j,0,M){
    bool connected = true;
    graph[input[j][0]][input[j][1]]= false;
    graph[input[j][1]][input[j][0]]= false;
    F(i,0,N+1)  visited[i] = false;
    dfs(1);
    F(i,1,N+1){
      if(!visited[i]){
        connected = false;
      }
    }
    if(!connected) ans++;
    graph[input[j][0]][input[j][1]]= true;
    graph[input[j][1]][input[j][0]]= true;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# n,k = map(int,input().split())
# A = list(map(int,input().split()))
# c = 0
# from collections import Counter
# d = Counter()
# d[0] = 1
# ans = 0
# r = [0]*(n+1)
# for i,x in enumerate(A):
#     if i>=k-1:
#         d[r[i-(k-1)]]-=1#ここで範囲kからはみ出たものの数を減らす
#     c = (c+x-1)%k
#     ans += d[c]
#     d[c] += 1
#     r[i+1] = c
# print(ans)
n,k = map(int,input().split())
A = list(map(int,input().split()))
S = [0]
for a in A:
    S.append(S[-1] + a)
# print(S)
from collections import defaultdict
dic = defaultdict(int)
ans = 0

for i,s in enumerate(S):
    if i >=k:
        dic[(S[i-k] - (i-k))%k]-=1
    ans += dic[(S[i]- i)%k]
    # print(i,s,(S[i]- i)%k,dic[(S[i]- i)%k],ans)
    dic[(S[i]- i)%k] += 1
print(ans)



#(12-6)%4

Measured memory_bytes: 140444
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef unsigned long long ull;
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}

inline void solve(void){
  int N;
  in(N);
  vector<int>A(N),B(N),C(N-1);
  ins(A);
  ins(B);
  ins(C);
  ull ans=0;
  rep(i,N){
    ans+=B[A[i]-1];
    if(i>0&&A[i-1]+1==A[i])ans+=C[A[i-1]-1];
  }
  out(ans);
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include<stdio.h>


int main (){

  int S[10000],T[500];
  int s,t,i,j=0,k=0;
  
  

  scanf("%d",&s);

  for(i=0;i<s;i++)
    scanf("%d",&S[i]);

  scanf("%d",&t);

  for(i=0;i<t;i++)
    scanf("%d",&T[i]);

  for(i=0;i<t;i++){
    k = 0;
    S[s] = T[i];
    while(S[k]!=T[i])
      k++;
    if(k == s)continue;
    else j++;
  }

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



Measured memory_bytes: 2100
def main():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    m = [max(0, i-k) for i in range(2, n)]
    dp = [None]*n
    dp[0], dp[1] = 0, abs(h[0]-h[1])
    for i, (hi, mi) in enumerate(zip(h[2:], m), 2):
        di = 10**9
        for dj, hj in zip(dp[mi:i], h[mi:i]):
            d = dj + abs(hj-hi)
            if di > d:
                di = d
        dp[i] = di
    print(dp[-1])

if __name__ == "__main__":
    main()

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,t,a,hoge[100000],huga[100000],ans;
vector<int> v[100000];

#define P pair<int,int>

void kr(int s, int memo[100000]) {
    bool visited[100000] = {};
    priority_queue<P,vector<P>,greater<P>> pq;
    pq.push(mp(0,s));
    while(pq.size()) {
        int cost = pq.top().fi, to = pq.top().se;pq.pop();
        if (visited[to]) continue;
        visited[to] = true;
        memo[to] = cost;
        for(auto i : v[to]) pq.push(mp(cost+1, i));
    }
}

signed main() {
    cin >> n >> t >> a;
    --t, --a;
    rep(i,n-1) {
        int c,d;
        cin >> c >> d;
        --c, --d;
        v[c].pb(d);
        v[d].pb(c);
    }
    kr(t,huga);
    kr(a,hoge);
    rep(i,n) {
        if (huga[i] < hoge[i]) {
            ans = max(ans, huga[i]+(hoge[i]-huga[i]-1));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 10272
#include <stdio.h>
int main()
{
    int A, B, C, D;
    int use1, use2;
    scanf("%d%d%d%d", &A, &B, &C, &D);
    use1 = A;
    use2 = C;
    if (B < A)
        use1 = B;
    if (D < C)
        use2 = D;
    printf("%d", use1 + use2);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cmath>
using namespace std;
int main(){
        double x1,y1,x2,y2;
        scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
        double ans=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
        printf("%lf\n",ans);
        return 0;
}

Measured memory_bytes: 1224
"use strict"
function Main(input) {
  const args = input.trim().split('\n');
  const n = args[0];
  const p = args[1].split(' ').map(Number);

  let max = 1e10;
  let cnt = 0;

  for(let i=0; i<n; i++){
    if(p[i]<max) cnt++, max=p[i];
  }

  console.log(cnt);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define ll long long

using namespace std;

ll ans;

main()
{
    ll al, n, k;

    cin >> n >> k;

    al = n * n;

    for (ll i = 1; i <= n; i++)
    {
        ll cur = 0, l = i, r = n / i;

        cur += max(0ll, r * (i - k));

        if (n != i * r && (r * i) + k <= n){
            cur += (n - ((r * i) + k) + 1);
            if (k == 0)
                cur--;
        }


        ans += cur;
    }

    cout << ans;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e14;
using Graph = vector<vector<int>>;

signed main(){
  vector<vector<int>> A(3, vector<int>(3));
  for( int i = 0; i < 3; i++ ){
    for( int j = 0; j < 3; j++ ) cin >> A[i][j];
  }

  int N;
  cin >> N;
  for( int n = 0; n < N; n++ ){
    int B;
    cin >> B;
    for( int i = 0; i < 3; i++ ){
      for( int j = 0; j < 3; j++ ){
        if( A[i][j] == B ) A[i][j] = -1;
      }
    }
  }

  //横
  for( int i = 0; i < 3; i++ ){
    bool fg = 1;
    for( int j = 0; j < 3; j++ ){
      if( A[i][j] != -1 ) fg = 0;
    }
    if( fg ){
      cout << "Yes" << endl;
      return 0;
    }
  }

  //たて
  for( int i = 0; i < 3; i++ ){
    bool fg = 1;
    for( int j = 0; j < 3; j++ ){
      if( A[j][i] != -1 ) fg = 0;
    }
    if( fg ){
      cout << "Yes" << endl;
      return 0;
    }
  }

  //ななめ
  if( A[0][0] == -1 && A[1][1] == -1 && A[2][2] == -1 ){
    cout << "Yes" << endl;
    return 0;
  }
  if( A[0][2] == -1 && A[1][1] == -1 && A[2][0] == -1 ){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;




}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int n;
    cin >> n;

    vector<int> a(n);
    for(int in=0;in<n;in++) {
        cin >> a.at(in);
    }

    int ans = 0;
    for(int in=0;in<n;in++) {
        if(a.at(in)%2!=0) continue;
        while(a.at(in)%2==0) {
            a.at(in) /= 2;
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
int main(){
	int m,f,r;
	while (1){
		scanf("%d %d %d",&m,&f,&r);
		if (m+f+r==-3) break;
		if (m==-1 || f==-1) printf("F\n");
		else if (m+f>=80) printf("A\n");
		else if (m+f>=65) printf("B\n");
		else if (m+f>=50) printf("C\n");
		else if (m+f>=30 && r>=50) printf("C\n");
		else if (m+f>=30) printf("D\n");
		else if (m+f<30)  printf("F\n");
	}
	return 0;	
}

Measured memory_bytes: 584
// È¥°É£¡Æ¤¿¨Çð! °ÑAC´ø»ØÀ´£¡
//      ¤Ø¡¡¡¡¡¡¡¡¡¡£¯|
// ¡¡¡¡/£Ü7¡¡¡¡¡¡ ¡Ï£ß/
// ¡¡ /¡¡©¦¡¡¡¡ £¯¡¡£¯								AC		AC		AC		AC
//    ©¦¡¡Z £ß,£¼¡¡£¯¡¡¡¡ /`©c						AC		AC		AC		AC
//    ©¦¡¡¡¡¡¡¡¡¡¡©c¡¡¡¡ /¡¡¡¡¡µ					AC		AC		AC		AC
// ¡¡Y¡¡¡¡¡¡¡¡¡¡`¡¡ /¡¡¡¡/  /						AC		AC		AC		AC
// ¡¡Øé¡ñ¡¡.¡¡¡ñ¡¡¡¡¡´¡¡/¡¡/						AC		AC		AC		AC
// ¡¡()¡¡ ¤Ø¡¡¡¡¡¡¡¡|¡¡£Ü¡´							AC		AC		AC		AC
// ¡¡¡¡>- ._¡¡ ¥£¡¡ ©¦ £¯£¯							AC		AC		AC		AC
// ¡¡ / ¤Ø¡¡¡¡ /¡¡/£¼| £Ü£Ü							AC		AC		AC		AC
// ¡¡ ©c_/¡¡¡¡(_£¯¡¡ ©¦£¯£¯							AC		AC		AC		AC
// ¡¡¡¡ 7¡¡¡¡¡¡¡¡¡¡¡¡¡¡|£¯							AC		AC		AC		AC
// ¡¡¡¡ £¾¨Dr£þ£þ`-¨D£ß/							AC		AC		AC		AC
//**************************************Accepted*****************************************//

#include<bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define Unique(x) x.erase(unique(all(x)),x.end());

#define CIN_FILE "input.txt"
#define COUT_FILE "output.txt"

#define Pig (OO)

using namespace std;

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

const int Days[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};

inline int read()
{
	#define gc getchar
	int ans=0;
	bool f=1;
	char ch=gc();
	
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	
	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
	
	return f?ans:-ans;
	
	#undef gc
}

typedef long long ll;

const ll MOD=1000000007ll;

ll n,m,k;
ll a=1ll,b=1ll;
ll ans;

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	
	cin>>n>>m>>k;
	
	for(ll i=1;i<=k-2;i++)a=a*(n*m-i-1)%MOD,b=b*i%MOD;
	
	for(ll i=MOD-2;i>=1;i/=2)
	{
		if(i%2)a=a*b%MOD;
		
		b=b*b%MOD;
	}
	
	b=a*n%MOD*n%MOD;
	for(ll i=1;i<m;i++)ans+=b*i%MOD*(m-i)%MOD;
	b=a*m%MOD*m%MOD;
	for(ll i=1;i<n;i++)ans+=b*i%MOD*(n-i)%MOD;
	
	cout<<ans%MOD;
	
	//printf("Time used = %.12f",(double)(clock())/CLOCKS_PER_SEC);
	return 0;
}

/*  GOD BLESS  */


Measured memory_bytes: 256
while True:
       (H, W) = [int(x) for x in input().split()]
       if H == W == 0:
           break
       
       for hc in range(H):
             for wc in range(W):
                   if hc == 0 or hc == H - 1 or wc == 0 or wc == W - 1:
                         print('#', end='')
                   else:
                         print('.', end='')                                         
             print()     
       print()

Measured memory_bytes: 6808
#include<bits/stdc++.h>
using namespace std;
int main(){
  #define int long
  int X,Y;cin>>X>>Y;
  if(X==1&&Y==1)cout<<1000000;
  else{
    int sum=0;
    if(X==1)sum+=300000;
    if(X==2)sum+=200000;
    if(X==3)sum+=100000;
    if(Y==1)sum+=300000;
    if(Y==2)sum+=200000;
    if(Y==3)sum+=100000;
    cout<<sum;
  
  }

  
  
  
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define hii cout << "hii" << endl
#define int ll
#define endl '\n'
#define all(s) s.begin(), s.end()
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
 
 
const int N = 3e5 + 5;
const int MAXN = 1e5 + 5;
const int M = 1e5;
const int mod = 998244353;
const int MOD = 998244353;
const int INF = 1e15;
const int LG = 21;

int arr[N];
int brr[N];


void solve() 
{
	int n;
	cin >> n;
	map<int, int> mp;
	for(int i = 0; i < n; i++)
	{
		cin >> arr[i];
		brr[i] = i - arr[i];
		mp[brr[i]]++;
	}
	int ret = 0;
	for(int i = 0; i < n; i++)
	{
		mp[brr[i]]--;
		ret += mp[i + arr[i]];
	}
	cout << ret << endl;
}



 
 
int32_t main() 
{	
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	    int t = 1;
	    // cin >> t;
	while(t--)solve();
	return 0;
}


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

int main()
{
    int n;
    cin>>n;
    if(n%10 == 2 || n%10 == 4 || n%10 == 5 || n%10 == 7 || n%10 == 9){
            cout<<"hon"<<endl;
            return 0;
        }else if(n%10 == 0 || n%10 == 1 || n%10 == 6 || n%10 == 8){
            cout<<"pon"<<endl;
            return 0;
        }else{
            cout<<"bon"<<endl;
            return 0;
        }
}

Measured memory_bytes: 3624
#include <cmath>
#include <iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
#include <math.h>
#include <list>
#include <numeric>
using namespace std;

long long combi(long long n, long long k) {
  if (n == k || k == 0)
    return 1;
  else {
    return combi(n - 1, k - 1) + combi(n - 1, k);
  }
}

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

int main(){    
  long long X;
  cin >> X;
  long long Y=100,count=0;


  while(1){
    Y = Y * 1.01;
    count++;
    if(X<=Y){
      cout << count << endl;
      return 0;
    }
  }
 
}
 


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int time = scan.nextInt();
		int hour = time / 3600;
		time = time - hour * 3600;
		int min = time / 60;
		time = time - min * 60;
		int sec = time;
		
		System.out.println(hour + ":" + min + ":" + sec);
	}

}

Measured memory_bytes: 17164
///                ..:: In The Name Of God ::..
#include<bits/stdc++.h>

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define error(x) cerr << #x << " = " << (x) << endl;
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define Size(x) (int)(x).size()
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef double ld;
const int maxn = 1e5 + 10;
int arr[maxn];
int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    
    int a,b,k;
    cin >> a >> b >> k;
    vi res;
    for(int i=1;i<=min(a,b);i++){
    	if(b%i==0 and a%i==0)
    		res.pb(i);
    }
    reverse(all(res));
    cout << res[k-1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int N;
	scanf("%d",&N);

	int L[N];
	for(int i = 0; i < N; i++){
		scanf("%d",&L[i]);
		if(i > 0){
			L[i] += L[i-1];
		}
	}

	int length[N+1][N+1];

	for(int left = 0; left <= N-1; left++){
		for(int right = 1; right <= N; right++){
			if(left == 0){
				length[left][right] = L[right-1];
			}else{
				length[left][right] = L[right-1]-L[left-1];
			}
		}
	}

	int dp[N+1][N+1],ans = BIG_NUM;

	int min_length,value_1,value_2;

	for(int min_range_left = 0; min_range_left <= N-1; min_range_left++){
		for(int min_range_right = min_range_left+1; min_range_right <= N; min_range_right++){

			min_length = length[min_range_left][min_range_right];

			if((min_range_left > 0 && min_length > length[0][min_range_left]) ||
					(min_range_right <= N-1 && min_length > length[min_range_right][N]))continue;

			value_1 = value_2 = 0;

			if(min_range_left > 0){

				for(int left = 0; left <= min_range_left-1; left++){
					for(int right = left+1; right <= min_range_left; right++)dp[left][right] = BIG_NUM;
				}

				for(int len = 1; len <= min_range_left; len++){
					for(int left = 0;left <= min_range_left-1; left++){
						int right = left+len;
						if(right > min_range_left)break;

						for(int mid = left; mid <= right-1; mid++){
							if(mid == left){
								if(length[mid][right] >= min_length){
									dp[left][right] = min(dp[left][right],length[mid][right]);
								}
							}else{
								if(dp[left][mid] != BIG_NUM && dp[mid][right] != BIG_NUM){
									dp[left][right] = min(dp[left][right],max(dp[left][mid],dp[mid][right]));
								}
							}
						}
					}
				}

				value_1 = dp[0][min_range_left]-min_length;
			}

			if(min_range_right <= N-1){

				for(int left = min_range_right; left <= N-1; left++){
					for(int right = left+1; right <= N; right++)dp[left][right] = BIG_NUM;
				}

				for(int len = 1; min_range_right+len <= N; len++){
					for(int left = min_range_right;left <= N-1; left++){
						int right = left+len;
						if(right > N)break;

						for(int mid = left; mid <= right-1; mid++){
							if(mid == left){
								if(length[mid][right] >= min_length){
									dp[left][right] = min(dp[left][right],length[mid][right]);
								}
							}else{
								if(dp[left][mid] != BIG_NUM && dp[mid][right] != BIG_NUM){
									dp[left][right] = min(dp[left][right],max(dp[left][mid],dp[mid][right])); //分割した区間の大きい方
								}
							}
						}
					}
				}
				value_2 = dp[min_range_right][N]-min_length;
			}
			if(min_range_left != 0 || min_range_right != N){
				ans = min(ans,max(value_1,value_2));
			}
		}
	}

	printf("%d\n",ans);

	return 0;
}



Measured memory_bytes: 3228
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 100005
typedef long long ll;
struct point{int x,y,num;}a[N];
int f1[N],f2[N];
ll w1[N],w2[N],t1[N],t2[N];
int n,m,k;
inline int min(const int &a,const int &b){return a<b?a:b;}
inline bool cmp1(point a,point b){return a.x<b.x;}
inline bool cmp2(point a,point b){return a.y<b.y;}
int find1(int n)
{
	if(f1[n]==n) return n;
	int fa=find1(f1[n]);
	w1[n]+=w1[f1[n]];
	return f1[n]=fa;
}
int find2(int n)
{
	if(f2[n]==n) return n;
	int fa=find2(f2[n]);
	w2[n]+=w2[f2[n]];
	return f2[n]=fa;
}
inline bool merge1(int x,int y,int z)
{
	int t1=find1(x),t2=find1(y);
	if(t1!=t2)
	{
		f1[t1]=t2,w1[t1]=z+w1[y]-w1[x];
		return 1;
	}
	return w1[x]==z+w1[y];
}
inline bool merge2(int x,int y,int z)
{
	int t1=find2(x),t2=find2(y);
	if(t1!=t2)
	{
		f2[t1]=t2,w2[t1]=z+w2[y]-w2[x];
		return 1;
	}
	return w2[x]==z+w2[y];
}
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++) f1[i]=i;
	for(int i=1;i<=m;i++) f2[i]=i;
	for(int i=1;i<=k;i++)
	{
		scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].num);
		if(a[i].num<0) return puts("No"),0;
	}
	sort(a+1,a+k+1,cmp1);
	for(int i=1;i<k;i++)
	  if(a[i].x==a[i+1].x&&!merge2(a[i].y,a[i+1].y,a[i+1].num-a[i].num)) return puts("No"),0;
	sort(a+1,a+k+1,cmp2);
	for(int i=1;i<k;i++)
	  if(a[i].y==a[i+1].y&&!merge1(a[i].x,a[i+1].x,a[i+1].num-a[i].num)) return puts("No"),0;
	memset(t1,0x3f,sizeof(t1));
	memset(t2,0x3f,sizeof(t2));
	for(int i=1;i<=k;i++)
	{
		int fa=find1(a[i].x);
		t1[fa]=min(t1[fa],a[i].num+w1[a[i].x]);
	}
	for(int i=1;i<=n;i++)
	{
		int fa=find1(i);
		t2[fa]=min(t2[fa],-w1[i]);
	}
	for(int i=1;i<=n;i++)
	  if(f1[i]==i&&t1[i]+t2[i]<0) return puts("No"),0;
	puts("Yes");
	return 0;
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
#include <time.h>
using namespace std;
#include <math.h>
#define ll long long 
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define max1 1000007
long long int mod =1e9+7;


int main(){	
//ios_base::sync_with_stdio(false);
	int x,n;
	cin>>x>>n;
	vector<int> p;
	int vis[102]={0};
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		vis[a]=1;
	}
	for (int i = 0; i < 102; ++i)
	{
		if(vis[i])
			continue;
		p.push_back(i);
	}
	sort(p.begin(),p.end());
	int ind=lower_bound(p.begin(),p.end(),x)-p.begin();
	if(ind==0){
		cout<<p[ind]<<endl;
	}
	else{
		int a1=abs(x-p[ind]);
		int a2=abs(x-p[ind-1]);
		if(a1<a2){
			cout<<p[ind]<<endl;
		}
		else{
			cout<<p[ind-1]<<endl;
		}
	}



		
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
#define f(i,a,b) for(ll i=a;i<b;i++)
 

int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll n,m;
cin>>n>>m;
if(n%m==0)
cout<<0<<endl;
else if(n<=m){
	int x=m/2;
	if(n<=x)
	cout<<n<<endl;
	else
	cout<<min(n,abs(n-m))<<endl;	
	
}
else{
	ll y=n%m;
	cout<<min(n,abs(y-m))<<endl;
	
	
}
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define m_p make_pair
#define sz(x) (int)x.size()
#define out(x) cerr<<#x<<" = "<<x<<" "
#define outln(x) cerr<<#x<<" = "<<x<<endl
#define outarr(x,l,r) cerr<<#x"["<<l<<"-"<<r<<"] = "; for (int _i=l;_i<=r;++_i) cerr<<x[_i]<<" ";cerr<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define gc() getchar()
//char buf[1<<23],*p1=buf,*p2=buf;
//#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <class T> void read(T &x)
{
    x=0; char c=gc(); int flag=0;
    while (c<'0'||c>'9') flag|=(c=='-'),c=gc();
    while (c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=gc();
    if (flag) x=-x;
}
template <class T> T _max(T a,T b){return a>b ? a : b;}
template <class T> T _min(T a,T b){return a<b ? a : b;}
template <class T> bool checkmax(T &a,T b){return b>a ? a=b,1 : 0;}
template <class T> bool checkmin(T &a,T b){return b<a ? a=b,1 : 0;}
#define int long long
const int N=105;
int k,n,cnt,a[N];
char s[N];
void init()
{
	scanf("%s%lld",s+1,&k);
	n=strlen(s+1);
}

void solve()
{
	int len=1;
	for (int i=2;i<=n;++i)
	{
		if (s[i]==s[i-1])
		{
			++len;
		}
		else
		{
			a[++cnt]=len;
			len=1;
		}
	}
	if (len) a[++cnt]=len;
	if (cnt==1)
	{
		printf("%lld\n",(ll)n*k/2);
		return;
	}
	if (s[1]!=s[n])
	{
		ll ans=0;
		for (int i=1;i<=cnt;++i)
		{
			ans+=a[i]/2;
		}
		ans*=k;
		printf("%lld\n",ans);
	}
	else
	{
		if (k==1)
		{
			ll ans=0;
			for (int i=1;i<=cnt;++i)
			{
				ans+=a[i]/2;
			}
			printf("%lld\n",ans);
			return;
		}
		ll ans=0;
		for (int i=2;i<=cnt-1;++i)
		{
			ans+=a[i]/2;
		}
		ans*=k;
		ans+=a[1]/2; ans+=a[cnt]/2;
		ans+=(ll)(k-1)*((a[1]+a[cnt])/2);
		printf("%lld\n",ans);
	}
}

#undef int
int main()
{
    init();
	solve();
	return 0;
}


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

struct S{
  int h,p,q;
  S(){};
  S(int H,int P, int Q){ h=H; p=P; q=Q;};
};
int main(){
  int n,m,a;
  int h,p,q;
  S s[1000];
  while(cin>>n>>m>>a, n ){
    for( int i=0;i<m;i++ ){
      cin >> h >> p >> q;
      s[i] = S(h,p,q);
    }

    bool flag;
    do{
      flag = false;
      for( int i=1;i<m;i++ ){
	if( s[i-1].h < s[i].h ){
	  S tmp = s[i-1]; s[i-1] = s[i]; s[i] = tmp;
	  flag = true;
	}
      }
    }while(flag);


    int index=0;
    while( index<m ){
      for( ; index<m;index++ ){
	if( s[index].q == a || s[index].p == a )
	  break;
      }
      if( index==m )
	break;

      a = (s[index].q==a)?s[index].p:s[index].q;

      index++;
    }
    cout << a << endl;
  }
}

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

using namespace std;
#define pb push_back

typedef long long ll;

int n;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  string s;
  cin >> s;
  int ans = 0;
  for(int i = 0; i < s.size()/2; i++)
  {
    if(s[i] != s[s.size()-1-i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n,k; cin>>n>>k;
  vll l, r;
  rep(i,n){
    ll a; cin>>a;
    if(a<0) l.push_back(-a);
    else r.push_back(a);
  }
  
  while(l.size()<k) l.push_back(INF);
  while(r.size()<k) r.push_back(INF);
  vsort(l);
  
  ll ans=LINF;
  chmin(ans,l[k-1]);
  chmin(ans,r[k-1]);
  rep(i,k){
    if(k-i-2<0) continue;
    chmin(ans,l[i]*2+r[k-i-2]);
  }
  rep(i,k){
    if(k-i-2<0) continue;
    chmin(ans,r[i]*2+l[k-i-2]);
  }
  cout<<ans<<endl;
  
}

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

int main(){
    int n,ans=32;
    cin >> n;
    for(int i=0;i<n;i++){
        int a,cnt=0;
        cin >> a;
        for(cnt=0;a%2==0;cnt++){
            a/=2;
        }
        ans=min(ans,cnt);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,m;
int x[125252],y[125252];

ll calc(int a[125252],int n){
  ll ret = 0;
  REP(i,n-1){
    a[i] = a[i+1] - a[i];
  }
  n--;
  REP(i,n){
    ret += (ll)(i+1) * (n-i) % MOD * a[i] % MOD;
    ret %= MOD;
  }
  return ret;
}

int main(){
  scanf("%d%d",&n,&m);
  REP(i,n)scanf("%d",x+i);
  REP(i,m)scanf("%d",y+i);
  ll ans = calc(x,n) * calc(y,m) % MOD;
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int A,B,C;
  cin>>A>>B>>C;
  int K;
  cin>>K;
  while(B<=A)
  {
    B+=B;
    K--;
  }
  while(C<=B)
  {
    C+=C;
    K--;
  }
  if(K>=0)
    puts("Yes");
  else	puts("No");
  return 0;
}

Measured memory_bytes: 3632
import sys
input = sys.stdin.readline

def main():
  n = int(input())
  T = [[] for _ in range(n)]
  D = {}
  for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    T[a].append(b)
    T[b].append(a)
    D[(a, b)] = 1<<i
    D[(b, a)] = 1<<i
  m = int(input())

  def dfs(u, v):
    parent = [-1]*n
    seen = [False]*n
    stack = [u]
    seen[u] = True
    while stack:
      nv = stack[-1]
      if nv == v:
        return stack
      for i in T[nv]:
        if seen[i]:
          continue
        stack.append(i)
        seen[i] = True
        break
      else:
        stack.pop()

  E = [0]*m
  for i in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    edge = dfs(u, v)
    for j in range(len(edge)-1):
      E[i] |= D[(edge[j], edge[j+1])]

  ans = 0
  for i in range(2**m):
    s = 0
    for j in range(m):
      if i>>j & 1:
        s |= E[j]
    cnt = bin(i).count("1") % 2
    ans += (-1)**cnt * 2**(n-1-bin(s).count("1"))
  print(ans)
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 42876
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 1000000000000000;
#define MOD 1000000007LL;
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
typedef int64_t i64;

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

i64 N; cin>> N;
VI A(N); 
rep(i, 0, N) {
    cin >> A[i];
    A[i] -= i + 1;
}
sort(ALL(A));
int med0 = A[N/2], med1 = A[N/2 + 1];
i64 sad0 = 0, sad1= 0;
rep(i, 0, N) sad0 += abs(A[i] - med0);
rep(i, 0, N) sad1 += abs(A[i] - med1);

cout << min(sad0, sad1) << endl;



}
// 書いて考える
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



Measured memory_bytes: 1792
n=int(input())
word=input()
line=[]
for i in range(n):
    if(word[0]=='R'):
        line.append(1)
    else:
        line.append(0)
    word=word[1:]
x=0
y=n-1
ans=0
while(1):
    while(1):
        if(line[x]==0):
            break
        if(x>=y):
            break
        x+=1
    while(1):
        if(line[y]==1):
            break
        if(x>=y):
            break
        y-=1
    if(x>=y):
        break
    tmp=line[x]
    line[x]=line[y]
    line[y]=tmp
    ans=ans+1
print(ans)

Measured memory_bytes: 10740
from collections import Counter

n = int(input())
v = list(map(int, input().split()))

x = Counter(v[::2]).most_common(2)
y = Counter(v[1::2]).most_common(2)
ans = n
if x[0][0] == y[0][0]:
  if len(x) == len(y) == 1:
    ans = n//2
  else:
    s = max([a[1] for a in x]) + min([b[1] for b in y])
    t = min([a[1] for a in x]) + max([b[1] for b in y])
    ans -= max(s, t)
else:
  ans -= x[0][1] + y[0][1]
print(ans)

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

using namespace std;

#define db(x) cerr << #x << " = " << x << endl;
#define ll long long

#define INF 0x3f3f3f3f

int n, k;
vector<int> height;

vector<int> dp;

vector<int> vis;

int solve(int i)
{
    if(i == n - 1)
        return 0;

    /*(i == n - 2)
        return abs(height[i] - height[i + 1]);*/

    if(vis[i])
        return dp[i];

    vis[i] = 1;

    dp[i] = solve(i + 1) + abs(height[i] - height[i + 1]);

    for(int j = 2; j <= k && i + j < n; j++)
        dp[i] = min(dp[i], solve(i + j) + abs(height[i] - height[i + j]));

    return dp[i];
}

int main()
{
    scanf("%d%d", &n, &k);

    dp  = vector<int>(n);
    vis = vector<int>(n);

    for(int i = 0; i < n; i++)
    {
        int aux;
        scanf("%d", &aux);
        height.push_back(aux);
    }

    printf("%d", solve(0));
}



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



#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)

using namespace std;

template <class T>
using vec = std::vector<T>;
typedef long long ll;
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; }

const long long INF = 1LL<<60;

int lcm(int a,int b){
    //最小公倍数
    return a/__gcd(a,b) * b;
}

int s,w;

int main()
{
    cin>>s>>w;

    if(w>=s){
        cout<<"unsafe"<<endl;
    }else{
        cout<<"safe"<<endl;
    }
    return 0;

}




Measured memory_bytes: 3572
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        HashMap<Integer, Boolean> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int num = sc.nextInt();
            if (!map.containsKey(num)) {
                map.put(num, true);
            } else {
                map.put(num, !map.get(num));
            }
        }
        int cnt = 0;
        for (boolean b : map.values()) {
            if (b) cnt++;
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 63156
from itertools import accumulate
n = int(input())
A = list(map(int, input().split()))
L = [0]
R = []
min_L = float("inf")
for i, a in enumerate(A):
  b = A[-(i+1)]
  if i%2 == 0:
    L.append(a)
  else:
    R.append(a)
R.append(0)
L = list(accumulate(L))
R = list(accumulate(R[::-1]))[::-1]
ans = -float("inf")
if n%2:
  def f(A):
    temp = 0
    left = 0
    right = 0
    for i in range(2, n, 2):
      temp += A[i]
    res = max(ans, temp)
    for i in range(1, n//2):
      temp -= A[i*2]
      left, right = left+A[2*(i-1)], max(left, right)+A[2*(i-1)+1]
      res = max(res, temp+max(left, right))
    return res
  ans = max(f(A), f(A[::-1]))
  temp = 0
  for i in range(1, n, 2):
    temp += A[i]
  ans = max(ans, temp)
else:
  for l, r in zip(L, R):
    ans = max(ans, l+r)
print(ans)

Measured memory_bytes: 107980
#include <bits/stdc++.h>
#define i64 long long
#define maxn (int)(1e5)
#define pii pair<int,int>
#define L first 
#define R second
#define all(x) x.begin(),x.end()
using namespace std;

int main(){
	int n; cin>>n;
	int V[n], C[n];
	for(int i=0;i<n;i++) cin>>V[i];
	for(int i=0;i<n;i++) cin>>C[i];
	
	int ans=0;
	for(int i=0;i<n;i++){
		if(V[i]>=C[i]) ans+=(V[i]-C[i]); 
		//if their difference is positive, taking the ith item increases profit
	}
		
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
/**
 * Copyright (c) 2017, xehoth
 * All rights reserved.
 * 「ARC 071E」TrBBnsformBBtion 20-08-2017
 *
 * @author xehoth
 */
#include <bits/stdc++.h>

namespace Task {

#define long long long

const int MAXN = 1000000;

char s[MAXN + 1], t[MAXN + 1];

const int MOD = 1e9 + 7;
int qa[MAXN], qb[MAXN], n, x, y, X, Y;
char a[MAXN], b[MAXN];

inline void solve() {
    std::ios::sync_with_stdio(false), std::cin.tie(NULL), std::cout.tie(NULL);
    std::cin >> a + 1 >> b + 1;
    for (int i = 1; a[i]; i++) qa[i] = qa[i - 1] + a[i] - 'A' + 1;
    for (int i = 1; b[i]; i++) qb[i] = qb[i - 1] + b[i] - 'A' + 1;
    for (std::cin >> n; n--;) {
        std::cin >> x >> y >> X >> Y;
        puts((qa[y] - qa[x - 1]) % 3 == (qb[Y] - qb[X - 1]) % 3 ? "YES" : "NO");
    }
}

#undef long
}

int main() {
    Task::solve();
    return 0;
}

Measured memory_bytes: 7040
class Dijkstra:
  R = {}
  import heapq
  pop = heapq.heappop
  push = heapq.heappush
  
  def __init__(s, N):
    s.N = N

  def add(s, a, b, x):
    if a not in s.R: s.R[a] = {b: x}
    else: s.R[a][b] = x
    if b not in s.R: s.R[b] = {a: x}
    else: s.R[b][a] = x

  def exe(s, start):
    D = [-1] * s.N 
    q  = []
    s.push(q, [0, start])
    cnt = 0
    while cnt < s.N:
      if len(q) == 0:
        return None
      d, x = s.pop(q)
      if D[x] != -1: continue
      D[x] = d
      cnt += 1
      for i in s.R[x]:
        if D[i] != -1: continue
        j = s.R[x][i]
        s.push(q, [d + j, i])
    return D


N, M = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]

D = Dijkstra(N)

for a, b in AB:
  D.add(a - 1, b - 1, 1)

L = D.exe(0)

if L == None:
  print("No")
  exit()

R = {}

for i in range(N):
  if L[i] in R:
    R[L[i]].append(i)
  else:
    R[L[i]] = [i]

Ans = [0] * N
for i in R.keys():
  for j in R[i]:
    for k in D.R[j].keys():
      if L[k] == L[j] + 1:
        Ans[k] = j + 1

print("Yes")
for i in range(1, N):
  print(Ans[i])


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

#define fi first
#define se second
#define ep emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  ll a, b; cin >> a >> b;
  ll c = b - a;

  ll x = (c * (c + 1)) / 2;
  cout << x - b << endl;

  return (0);
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> p;
typedef vector<p> vp;
typedef tuple<int,int,int,vp> state;
#define rep(i,n)	for(int i=0;i<n;i++)
#define mp	make_pair
#define mt	make_tuple

map<state,int> dp;
vector<string> s;
int h,w;
const int dx[]={1,0,-1,0};
const int dy[]={0,1,0,-1};

void makeWall(){
	string a="";
	rep(i,s[0].size())	a+="#";
	s.insert(s.begin(),a);
	s.push_back(a);
	rep(i,s.size())	s[i]="#"+s[i]+"#";
}

int solve(int x,int y,int k,vp used){
	if(x==w&&y==h&&k==0)	return 0;
	state cur=mt(x,y,k,used);
	if(dp.find(cur)!=dp.end())	return dp[cur];
	int ret=INT_MIN;
	rep(d,4){
		int nx=x+dx[d];
		int ny=y+dy[d];
		int nk=k-(d>1);
		if(nk<0||s[ny][nx]=='#')	continue;
		vp nused;
		rep(i,used.size()){
			if((nx+ny)-(used[i].first+used[i].second)<=nk){
				nused.push_back(used[i]);
			}
		}
		int val=0;
		if(s[ny][nx]!='.'){
			auto it=lower_bound(nused.begin(),nused.end(),mp(nx,ny));
			if(it==nused.end()||*it!=mp(nx,ny)){
				val=s[ny][nx]-'0';
				nused.insert(it,mp(nx,ny));
			}
		}
		ret=max(ret,val+solve(nx,ny,nk,nused));
	}
	return dp[cur]=ret;
}

int main(){
	int k;	cin>>h>>w>>k;
	s.resize(h);
	rep(i,h)	cin>>s[i];
	makeWall();
	cout<<solve(1,1,k,vp())<<endl;
	return 0;
}
	

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

const int INF = 1001001001;

int main() {
  ll n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  ll s = 0, m = 1000;
  rep(i, n) {
    if (a[i] < a[i + 1]) {
      s += m / a[i];
      m -= a[i] * (m / a[i]);
    } else if (a[i] > a[i + 1]) {
      m += a[i] * s;
      s = 0;
    }
  }
  if (s > 0) m += a[n - 1] * s;
  cout << m << endl;
  return 0;
}


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

using namespace std;
int main()
{
    int k;
    string s;
    cin >> k >> s;

    if (s.length() <= k)
        cout << s << endl;

    else
    {
        s.erase(s.begin() + k , s.end());
        cout << s << "..." << endl;
    }
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
const int INFTY =2147483647;
int main(){
    int a,b,c,d;
    string ans ="Yes";
    cin>>a>>b>>c>>d;
    if(c/b+min(c%b,1)>a/d+min(a%d,1)) ans="No";
    cout<<ans<<endl;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
int N;
cin >> N;
int ans = 0;
vector<int> A(N);
for (int i = 0;i < N;i++) cin >> A.at(i);

vector<int> B(N);
for (int i = 0;i < N;i++){
cin >> B.at(i);
ans += B.at(i);
} 

vector<int> C(N-1);
for (int i = 0;i < N-1;i++) cin >> C.at(i);

for (int i = 0;i < N-1;i++) {
    if (A.at(i) == A.at(i+1) -1) {
        ans += C.at(A.at(i)-1);
    }

}

cout << ans << endl;

return 0;
}

Measured memory_bytes: 256
#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>
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)
int main()
{
	lint a,b;cin>>a>>b;
	if(a>0) cout<<"Positive"<<endl;
	else if(b<0){
		if((b-a)%2<1) cout<<"Negative"<<endl;
		else cout<<"Positive"<<endl;
	}
	else cout<<"Zero"<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class F
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		map = new int[n + 1].Select(_ => new List<int>()).ToArray();
		foreach (var r in new int[n - 1].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()))
		{
			map[r[0]].Add(r[1]);
			map[r[1]].Add(r[0]);
		}

		tour = new int[n + 1].Select(_ => new List<int>()).ToArray();
		Dfs(1, 0);

		var all = ((MInt)2).Pow(n - 1);
		MInt bSum = 0;
		foreach (var l in tour.Skip(1))
		{
			if (l.Count < 2) { bSum += all - 1; continue; }
			foreach (var c in Subtrees(l, n - 1))
				bSum += ((MInt)2).Pow(c) - 1;
		}
		Console.WriteLine(((n - (n + bSum) / all) / 2).V);
	}

	static List<int>[] map;
	static List<int>[] tour;
	static int c;
	static void Dfs(int p, int p0)
	{
		foreach (var x in map[p])
		{
			if (x == p0) continue;
			tour[x].Add(++c);
			Dfs(x, p);
			tour[p].Add(++c);
		}
	}

	static IEnumerable<int> Subtrees(List<int> l, int m)
	{
		for (int i = 0; i < l.Count; i++)
			yield return ((l[(i + 1) % l.Count] - l[i]) / 2 + m) % m;
	}
}

struct MInt
{
	const int M = 1000000007;
	public long V;
	public MInt(long v) { V = (v %= M) < 0 ? v + M : v; }

	public static implicit operator MInt(long v) => new MInt(v);
	public static MInt operator +(MInt x) => x;
	public static MInt operator -(MInt x) => -x.V;
	public static MInt operator +(MInt x, MInt y) => x.V + y.V;
	public static MInt operator -(MInt x, MInt y) => x.V - y.V;
	public static MInt operator *(MInt x, MInt y) => x.V * y.V;
	public static MInt operator /(MInt x, MInt y) => x * y.Inv();

	public MInt Pow(int i) => MPow(V, i);
	public MInt Inv() => MPow(V, M - 2);

	static long MPow(long b, int i)
	{
		for (var r = 1L; ; b = b * b % M)
		{
			if (i % 2 > 0) r = r * b % M;
			if ((i /= 2) < 1) return r;
		}
	}
}


Measured memory_bytes: 74908
a = []
b = []
for i in range(5):
    ai = int(input())
    a.append([ai,ai%10])
    if ai%10 == 0:
        a[i][1]=10

a.sort(key=lambda x: x[1])

time = 0
for i in range(1,5):
    time += (a[i][0]//10)*10
    if a[i][0]%10 != 0:
        time += 10

time += a[0][0]
print(time)


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

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;

    if (a >= 13) ans = b;
    else if (a >= 6 && a <= 12) ans = b/2;
    else ans = 0;

    cout << ans << endl;

}



Measured memory_bytes: 256