akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.first+a.second > b.first+b.second; }

int main() {
	SS(ll,n);
	ll ans=1;
	for(int b=1;b<=n;b++){
		for(int p=2;p<=n;p++){
			if(pow(b,p)<=n){
				ans=max(ans,(ll)pow(b,p));
			}
			else break;
		}
	}
	p(ans);
}


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

const int M=3005;
const int MO=998244353;

inline int add(int x,int y)
{
	x+=y;
	if(x>=MO) x-=MO;
	return x;
}

inline int mul(int x,int y)
{
	return 1LL*x*y%MO;
}

int a[M];
int dp[M];

int main()
{
	int n,s; scanf("%d%d",&n,&s);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	dp[0]=1;
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		//cout<<i<<endl;
		dp[0]=i;
		if(a[i]<=s)
			ans=add(ans,mul(dp[s-a[i]],n-i+1));
		for(int j=s;j>=a[i];j--)
			dp[j]=add(dp[j],dp[j-a[i]]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    int N,i,j,min,tmp;
    scanf( "%d" , &N );
    int cnt = 0;
    int a[N];
    
    for( i = 0 ; i < N ; i++ ){
        scanf( "%d" , &a[i] );
    }

    for( i = 0 ; i < N ; i++ ){
        min = i;
        for( j = i ; j < N ; j++ ){
            if( a[min] > a[j] ){
                min = j;
            }
        }
        if( a[i] != a[min] ){
            cnt++;
        }
        tmp = a[i];
        a[i] = a[min];
        a[min] = tmp;
    }

    for( i = 0 ; i < N ; i++ ){
        if( i != 0 ){
            printf( " " );
        }
        printf( "%d" , a[i] );
    }
    
    printf("\n");
    printf( "%d\n" , cnt );
    
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


int main(){
    double r;cin >> r;
    cout << setprecision(30) << fixed << 2 * r * acos(-1) << endl;
    return 0;
}


Measured memory_bytes: 3788
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 65000;
typedef long long llong;

main(){
  llong n, totalp, totalj;
  llong P[MAX], J[MAX];
  int tcase = 0;
  while(1){
    cin >> n;
    if ( n == 0 ) break;
    tcase++;
    totalp = 0;
    for ( int i = 0; i < n; i++ ) {
      cin >> P[i];
      totalp += P[i];
    }
    for ( int i = 0; i < n-1; i++ ) {
      cin >> J[i];
    }

    llong maxv = 0;
    sort(J, J+(n-1));
    reverse(J, J+(n-1));
    totalj = 0;
    for ( llong j = 0, t = n; t >= 1; t--, j++ ){
      llong v = t*(totalj + totalp);
      totalj += J[j];
      maxv = max(v, maxv);
    }
    cout << maxv << endl;
  }
}

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

#define i64 long long int

i64 n;

int main() {
	cin>>n;
	if(n%2) {
		cout<<0<<endl;
		return 0;
	}
	n/=2;
	
	i64 ans = 0LL;
	while(n>0) {
		n/=5;
		ans += n;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
// Lets go to the next level 
// AIM Expert at CF *__* asap 
// Hit A,B,C and if possible D faster and reach Expert
// Remember you were also a novice when you started, 
// hence never be rude to anyone who wants to learn something
// Never open a ranklist untill and unless you are done with solving problems, wastes 3/4 minuts 
// Donot treat CP as a placement thing, love it and enjoy it, you will succeed for sure.  
#include "bits/stdc++.h"
//#include <algorithm>
#define ll long long 
#define mod 1000000007
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define umap unordered_map
#define uset unordered_set
#define lb lower_bound
#define ub upper_bound
#define endll "\n";
#define all(x) (x).begin(), (x).end()
#define forr(it,x) for(auto it=x.begin();it!=x.end();it++)
#define for1(i,a,b) for(int i=a;i<b;i++)
#define for2(i,a,b) for(int i=a;i>=b;i--)
#define for3(i,a,b) for(long long int i=a;i<b;i++)
#define for4(i,a,b) for(long long int i=a;i>=b;i--)
#define pp pair<int,int>
#define ld long double
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpp vector<pp>
#define vi vector<int>
#define vpll vector<pll>
#define vld vector<ld>
#define vvld vector<vld>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define vvpp vector<vpp>
#define I insert
#define mem(a,x) memset(a,x,sizeof(a))
#define p_queue(a) priority_queue<a,vector<a>,greater<a>>
using namespace std;
//const int dx[8]={1,0,-1,0,1,1,-1,-1},dy[8]={0,1,0,-1,-1,1,-1,1};
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1}; 
const int N=2e5+5;
/*vector<bool> p(N+1, true);
void sieve()
{
  p[0] = p[1] = false;
  int i,j;
  for (i = 2; i*i <= N; i++) 
  {
      if (p[i]) 
      {
          for (j = i * i; j <=N; j += i)
            {
        p[j] =false;
        }
      }
  }
}*/
/*int power(int a, int b){
    int res = 1;
    while(b > 0){
        if(b % 2){
            res = 1LL * res * a % mod;
        }
        a = 1LL * a * a % mod;
        b /= 2;
    }
    return res;
}*/
/*int gcd(int a,int b){
    if(a<b) swap(a,b);
    a%=b;
    if(a==0) return b;
    return gcd(b,a);
}*/
/*int lcm(int a,int b){
   return (a*1LL*b)/gcd(a,b);
}*/
int a[N];
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    string s;cin>>s;
    int ans=0,cnt=0;
    for1(i,0,s.length()){
      if(s[i]=='R'){
         cnt++;
      }
      else{
         cnt=0;
      }
      ans=max(ans,cnt);
    }
    cout<<ans<<endll;
    return 0;
}

/*

*/




Measured memory_bytes: 3628
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int

ans = nil
N.step(999) do |n|
  a, b, c = n.to_s.split('')
  if a == b && b == c
    ans = n
    break
  end
end

puts ans


Measured memory_bytes: 14392
#include<bits/stdc++.h>
#define ii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define int long long int
#define modulo 1000000007
using namespace std;

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,ans=INF;
    cin>>n;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            ans=min(ans,i-1+n/i-1);
        }
    }
    cout<<ans;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9+7;

bool used[880];
vector<vector<pair<ll,ll>>> v(880);
int tmp;
ll ret;

void dfs(int p,ll dist){
    used[p] = true;
    if(ret < dist){
        ret = dist;
        tmp = p;
    }
    for(auto i:v[p]){
        if(!used[i.first]) dfs(i.first,i.second+dist);
    }
}



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

    int n;
    while(cin>>n){
        if(n==0) break;
        ll p[n-1], d[n-1];
        ll ans = 0;
        ll cnt[n]={};
        for(int i=0;i<n-1;i++) {
            cin>>p[i];
            p[i]--;
            cnt[p[i]]++;
        }
        cnt[0]--;
        for(int i=0;i<810;i++) used[i] = false;
        vector<vector<pair<ll,ll>>> a(880);
        v = a;
        for(int i=0;i<n-1;i++){
            cin>>d[i];
            ans += d[i];
        }
        int k;

        for(int i=0;i<n-1;i++){
            if(cnt[i+1] && cnt[p[i]]){
                v[i+1].push_back(make_pair(p[i],d[i]));
                v[p[i]].push_back(make_pair(i+1,d[i]));
                ans += 2*d[i];
                k = i+1;
            }
        }

        ll tyokkei;
        ret = 0;
        dfs(k,0);
        for(int i=0;i<810;i++) used[i] = false;
        dfs(tmp,0);
        tyokkei = ret;

        ans -= ret;
        cout << ans << endl;

    }
    
}


Measured memory_bytes: 3260
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        String[] a = new String[n];
        String[] b = new String[m];
        Arrays.setAll(a, i -> sc.next());
        Arrays.setAll(b, i -> sc.next());
        sc.close();

        // 主処理
        boolean judge = false;
        for (int i = 0; i <= n - m; i++) {
            int startIndex = 0;
            int index = a[i].indexOf(b[0], startIndex);
            while (0 <= index && index <= n - m) {
                boolean isSame = true;
                for (int j = 1; j < m; j++) {
                    if (index != a[i + j].indexOf(b[j], startIndex)) {
                        isSame = false;
                        break;
                    }
                }
                if (isSame) {
                    judge = true;
                    break;
                } else if (index < n - 1) {
                    startIndex = index + 1;
                    index = a[i].indexOf(b[0], startIndex);
                }
            }
        }
        String result = judge ? "Yes" : "No";

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 35612
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
s=input()
n=len(s)
res=900
for i in range(n-2):
    if abs(753-int(s[i:i+3]))<res:
        res=abs(753-int(s[i:i+3]))
print(res)

Measured memory_bytes: 65168
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int []h = new int[n];
		
		for(int i = 0; i < n; i++) {
			h[i] = stdIn.nextInt();
		}
		
		int cnt = 0;
		int max = 0;
		
		
		for(int i = 0; i < n-1; i++) {
			if(h[i]>= h[i+1]) {
				cnt++;
				max = Math.max(cnt, max);
			}else {
				cnt = 0;
			}
		}
		
		System.out.println(max);
	}
	
	
	
	
	
}


Measured memory_bytes: 52076
def dfs(u, visited, g):
	visited[u] = True
	for v in g[u]:
		if visited[v] == True:
			continue
		dfs(v, visited, g)

def resolve():
	n, m = map(int, input().split())

	edges = []
	ans = 0
	for _ in range(m):
		a, b = map(int, input().split())
		edges.append([a-1, b-1])

	for i in range(m):
		visited = [False]*n
		g = [[] for _ in range(n)]
		e = edges[:i] + edges[i+1:]
		for i in range(m-1):
			g[e[i][0]].append(e[i][1])
			g[e[i][1]].append(e[i][0])

		dfs(0, visited, g)
		if len(visited) != visited.count(True):
			ans += 1

	print(ans)
resolve()

Measured memory_bytes: 42716
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int h,w,m;
vector<int> yoko[300010],tate[300010];

void solve(){
  cin >> h >> w >> m;
  rep(i,m){
    int u,v;cin >> u >> v;u--;v--;
    yoko[u].push_back(v);
    tate[v].push_back(u);
  }
  sort(tate,tate+w,[](auto a,auto b){return a.size()>b.size();});
  int siz=tate[0].size();
  int id=0;
  vector<int> cnt(h,0);
  while(tate[id].size()==siz){
    for(int t:tate[id]){
      cnt[t]+=1;
    }
    id++;
  }
  //cout << siz << endl;
  //cout << id << endl;
  int ans=0;
  rep(i,h){
    int res=yoko[i].size()+siz;
    if(cnt[i]==id)  res-=1;
    ans=max(res,ans);
  }
  cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 37256
def dfs(v):
    if len(set(visited)) == 1 and visited[0]:
        return 1
    count = 0
    for p in points[v]:
        if not visited[p]:
            visited[p] = True
            count += dfs(p)
            visited[p] = False
    else:
        return count


n,m = [int(x) for x in input().split()]
points = [[] for _ in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    points[a-1].append(b-1)
    points[b-1].append(a-1)

visited = [False]*n
visited[0] = True

print(dfs(0))


Measured memory_bytes: 3064
///بِسْمِ الّٰلهِ الرَّحْمٰنِ الرَحِيْمِ
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1.0)
int main()
{
     ios_base::sync_with_stdio(false);cin.tie(NULL);
      int i,n,t,j=0,p,x,a=0,b,l=0,r=0,y,k,c,sum=0,m,d;
     cin>>n;
     cout<<360/__gcd(360,n)<<endl;

     return EXIT_SUCCESS;
}



Measured memory_bytes: 3652
import sys
input = sys.stdin.readline
import heapq

def suc(s):
    return s + str(int(s[-1]) + 1)

def prev(s):
    return s + str(int(s[-1]) - 1)

def f(k):
    pq = list(range(1, 10))
    heapq.heapify(pq)
    i = 0
    while i < k:
        a = heapq.heappop(pq)
        yield a

        i += 1
        a_ = str(a)
        if a_[-1] < "9":
            down = int(suc(a_))
            heapq.heappush(pq, down)

        if a_[-1] > "0":
            up = int(prev(a_))
            heapq.heappush(pq, up)

        flat = int(a_ + a_[-1])
        heapq.heappush(pq, flat)

def main():
    k = int(input())
    ans = list(f(k))
    print(ans[-1])




main()

Measured memory_bytes: 14632
#include<stdio.h>

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

  int d[c+1][c+1];
  for(int i = 1;i <= c;i ++){
    for(int j = 1;j <= c;j ++){
      scanf("%d",&d[i][j]);
    }
  }

  int k[n+1][n+1];
  int waru1[31] = {0} , waru2[31] = {0} , waru0[31] = {0};
  for(int i = 1;i <= n;i ++){
    for(int j = 1;j <= n;j ++){
      scanf("%d",&k[i][j]);
      if((i+j)%3 == 1){
        waru1[k[i][j]] ++;
      }
      else if((i+j)%3 == 2){
        waru2[k[i][j]] ++;
      }
      else{
        waru0[k[i][j]] ++;
      }
    }
  }

  /*while(flag == 1){
    flag = 0;
    for(int i = 1;i <= c;i ++){
      for(int j = 1;j <= c;j ++){
        for(int k = 1;k <= c;k ++){
          if(d[i][j] > d[i][k] + d[k][j]){
            d[i][j] = d[i][k] + d[k][j];
            flag = 1;
          }
        }
      }
    }
  }*/

  int min = 1000000000;
  for(int i = 1;i <= c;i ++){
    for(int j = 1;j <= c;j ++){
      for(int x = 1;x <= c;x ++){
        if(i != j && j != x && x != i){
          int tas = 0;
          for(int y = 1;y <= c;y ++){
            tas += waru1[y] * d[y][i];
            tas += waru2[y] * d[y][j];
            tas += waru0[y] * d[y][x];
          }
          
          if(min > tas){
            min = tas;
          }
        }
      }
    }
  }

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

  return 0;
}

Measured memory_bytes: 2668
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

int main(){
    string s,t;
    cin >> s;
    cin >> t;
  
    int ns = s.length();
    int nt = t.length();
  
    int nMax = 0;
    for(int i = 0; i < ns - nt + 1; i++){
        int nTmp = 0;
        for(int j = 0; j < nt; j++){
            if(s[i + j] == t[j]){
                nTmp++;
            }
        }
        nMax = max(nMax, nTmp);
    }
    printf("%d", nt - nMax);
    return 0;
}


Measured memory_bytes: 3260
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<pii,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?9e18:1e9;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};
int n;
vi in;
vvi G;
vi cyc;
pii dfs(int a){
	vi t;
	t.pb(inf);
	rep(i,G[a].size()){
		int to=G[a][i];
		if(cyc[to])continue;
		t.pb(dfs(to).first);
	}
	sort(all(t));
	pii out;
	int j;
	rep(i,t.size())if(t[i]!=i){
		out.first=i;
		t.pb(i);
		j=i;
		break;
	}
	sort(all(t));
	loop(i,j,t.size())if(t[i]!=i){
		out.second=i;
		t.pb(i);
		break;
	}
	return out;
}
int main(){
	cin>>n;
	in=vi(n);
	rep(i,n)cin>>in[i];
	rep(i,n)in[i]--;
	G=vvi(n);
	rep(i,n)G[in[i]].pb(i);
	cyc=vi(n);
	int t=0;
	while(cyc[t]==0){
		cyc[t]=true;
		t=in[t];
	}
	cyc=vi(n);
	while(cyc[t]==0){
		cyc[t]=true;
		t=in[t];
	}
//	rep(i,n)cout<<" "<<cyc[i];cout<<endl;
	vp num(n,{-1,-1});
	rep(i,n)if(cyc[i]){
		num[i]=dfs(i);
	}
//	rep(i,n)cout<<" "<<num[i].first<<" "<<num[i].second<<endl;
	rep(i,n)if(cyc[i]){
		int t=i;
		int nu=num[i].first;
		while(in[t]!=i){
			t=in[t];
			if(num[t].first==nu)nu=num[t].second;
			else nu=num[t].first;
		}
		if(num[i].first!=nu){
			cout<<"POSSIBLE"<<endl;
			return 0;
		}
		t=i;nu=num[i].second;
		while(in[t]!=i){
			t=in[t];
			if(num[t].first==nu)nu=num[t].second;
			else nu=num[t].first;
		}
		if(num[i].first==nu){
			cout<<"POSSIBLE"<<endl;
			return 0;
		}
		cout<<"IMPOSSIBLE"<<endl;
		return 0;
	}
}







Measured memory_bytes: 13184
class Float
  def minus(other)
    return other - self
  end
  def divide(other)
    return other / self
  end
end
def main(input =STDIN)
  operater = {"+" => :+, "-" => :minus, "*" => :*, "/" => :divide}
  while arg = input.gets
    express = arg.chomp.split(" ")
    stack = []
    while (char = express.shift)
      if operater.key?(char)
        stack.push(stack.pop.send(operater[char], stack.pop))
      else
        stack.push(char.to_f)
      end
    end
    puts stack
  end
end
main

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

int main() {
    string s, t;
    cin >> s >> t;
    
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    
    cout << ((s < t) ? "Yes" : "No") << endl;
    return 0;
}

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

int main() {
    string ans;
    int Q;
    cin >> ans >> Q;
    int r = 1;
    rep(i,Q){
        int T;
        cin >> T;
        if(T==1){
            r *= -1;
        } else if (T==2){
            int f;
            string c;
            cin >> f >> c;
            if(f==1){
                if(r==1){
                    ans.insert(0,c);
                } else {
                    ans += c;
                }
            } else {
                if(r==1){
                    ans += c;
                } else {
                    ans.insert(0,c);
                }
            }
        }
    }
    if(r==-1) reverse(ALL(ans));
    cout << ans << endl;

}

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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    int T[N]; rep(i, N) cin >> T[i];
    int base = 0; rep(i, N) base += T[i];
    int Q; cin >> Q;
    rep(i, Q){
        int p, x; cin >> p >> x;
        p--;
        cout << base - T[p] + x << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{

int n;
cin>>n;
int a[200000+15];
for(int i=0;i<n;i++)
    {
     cin>>a[i];
     a[i]-=i+1;
    }

sort(a,a+n);
int cnt=a[(n-1)/2];
long long ans=0;
for(int i=0;i<n;i++)
    ans+=max(a[i]-cnt,cnt-a[i]);
cout<<ans;

return 0;
}

Measured memory_bytes: 1024
n = int(input())
s = input()

l1 = l2 = length = 0

while l2 + length < n:
    #print("s[l1:l2]" , s[l1:l2])
    #print("s[l2:]" , s[l2:])
    if s[l1:l2] in s[l2:]:
        length = l2 - l1
        l2 += 1 
    else:
        l1 += 1
        l2 = l1 + length + 1
print(length)

Measured memory_bytes: 3060
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<pair<int, pair<int, int>>> con(N);
    int s, t, x;
    for (int i = 0; i < N; i++) {
        scanf("%d%d%d", &s, &t, &x);
        con[i] = make_pair(x, make_pair(s - x, t - x - 1));
    }
    set<pair<int, int>> D;
    vector<int> ans(Q);
    int d;
    for (int i = 0; i < Q; i++) {
        scanf("%d", &d);
        D.insert(make_pair(d, i));
        ans[i] = -1;
    }

    sort(con.begin(), con.end());
    for (int i = 0; i < N; i++) {
        int X = con[i].first;
        int L = con[i].second.first;
        int R = con[i].second.second;
        if (D.empty()) {
            break;
        }
        auto it = D.lower_bound({L, -1});
        while (it != D.end() && (*it).first <= R) {
            ans[(*it).second] = X;
            D.erase(it++);
        }
    }
    for (int i = 0; i < Q; i++) {
        cout << ans[i] << "\n";
    }
    return 0;
}



Measured memory_bytes: 14336
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))
"""
N = int(input())
S = [0 for i in range(N)]
ans = {
    "AC":0,
    "WA":0,
    "TLE":0,
    "RE":0
}
for i in range(N):
    S[i] = str(input())
    ans[S[i]] += 1

for key in ans.keys():
    print(key + " x " + str(ans[key]))
"""
N = int(input())
S = []
for i in range(N):
    S.append(str(input()))

cnt = {
    "AC":0,
    "WA":0,
    "TLE":0,
    "RE":0
}
for s in S:
    cnt[s] += 1

for key in cnt.keys():
    print("{} x {}".format(key, cnt[key]))


Measured memory_bytes: 17908
import math
import sys
import itertools

def main():
  f = input().split()

  while len(f) > 1:

    len_f = len(f)

    for i in range(len_f):
      if f[i] == '+' or f[i] == '-' or f[i] == '*':
        index = i
        operator = f[i]
        break

    if operator == '+':
      r = int(f[index-2]) + int(f[i-1])
    elif operator == '-':
      r = int(f[index-2]) - int(f[index-1])
    elif operator == '*':
      r = int(f[index-2]) * int(f[index-1])
    else:
      print('invalid input')
      sys.exit(1)

    f = f[:index-2] + [str(r)] + f[index+1:]

  print(f[0])

if __name__ == '__main__':
  main()


Measured memory_bytes: 5704
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <queue>
#include <math.h>
#define ll long
#define INF 1000000000
#define N 10000000
using namespace std;

int main(){
    ll n;
    cin>>n;
    map<ll,ll> data;
    
    for (ll i=0; i<n-1; i++){
        ll s;
        cin>>s;
        data[s]++;
    }
    
    for (ll i=1; i<=n; i++) cout<<data[i]<<endl;
}


Measured memory_bytes: 16056
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;


static class P
{
    static void Main()
    {
        var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nm[0];
        var m = nm[1];
        List<int>[] neighbors = Enumerable.Repeat(0, n).Select(_ => new List<int>()).ToArray();
        for (int i = 0; i < m; i++)
        {
            var uv = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
            neighbors[uv[0]].Add(uv[1]);
        }
        var sg = Console.ReadLine().Split().Select(x => int.Parse(x) - 1).ToArray();
        var s = sg[0];
        var g = sg[1];
        bool[][] arrived = new bool[][]
        {
            new bool[n],
            new bool[n],
            new bool[n]
        };
        arrived[0][s] = true;
        List<int> nextVertexes = new List<int>() { s };
        for (int iteration = 1; ; iteration++)
        {
            for (int hop = 0; hop < 3; hop++)
            {
                var newNext = new List<int>();
                var nextPlace = (hop + 1) % 3;
                foreach (var vertex in nextVertexes)
                {
                    foreach (var neighbor in neighbors[vertex])
                    {
                        if (arrived[nextPlace][neighbor]) continue;
                        arrived[nextPlace][neighbor] = true;
                        newNext.Add(neighbor);
                    }
                }
                nextVertexes = newNext;
            }
            if (arrived[0][g])
            {
                Console.WriteLine(iteration);
                return;
            }
            if (nextVertexes.Count == 0)
            {
                Console.WriteLine(-1);
                return;
            }
        }
    }
}


Measured memory_bytes: 29176
n, a, b = gets.split.map &:to_i
x = 0
y = 0
gets.chomp.each_char do |c|
  case c
    when 'a'
    if x < a + b
      x += 1
      puts :Yes
    else
      puts :No
    end
    when 'b'
    if x < a + b and y < b
      x += 1
      y += 1
      puts :Yes
    else
      y += 1
      puts :No
    end
    when 'c'
    puts :No
  end
end

Measured memory_bytes: 14448
n,m = map(int,input().split())
action = [list(input().split()) for _ in range(m)]
answer_dict = {}
score = 0
penalty = 0

for a in action:
    if a[1] == 'WA' and a[0] not in answer_dict:
        answer_dict[a[0]] = 1
    elif a[1] == 'WA' and answer_dict[a[0]] != 'Done':
        answer_dict[a[0]] += 1
    elif a[1] == 'AC':
        if a[0] in answer_dict and answer_dict[a[0]] != 'Done':
            score += 1
            penalty += answer_dict[a[0]]
            answer_dict[a[0]] = 'Done'
        elif a[0] not in answer_dict:
            score += 1
            answer_dict[a[0]] = 'Done'

print(score,penalty)


Measured memory_bytes: 35260
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        int a = inp.nextInt();
        int b = inp.nextInt();
        if (a > b) System.out.println(a - 1);
        else System.out.println(a);
        inp.close();
    }
}


Measured memory_bytes: 21076
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    N, M = [int(x) for x in input().split()]
    AB = [[int(x) for x in input().split()] for _ in range(M)]

    uf = UnionFind(N)

    for a, b in AB:
        uf.union(a - 1, b - 1)

    print(uf.group_count() - 1)


if __name__ == '__main__':
    main()


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cerr << (*begin) << " ";
    *begin++;
  }
  cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cerr << " " << Array[i][j];
    }
    cerr << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

signed main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;

  int ans = 0;
  for (int r = 0; r <= N; r++) {
    for (int g = 0; g <= N; g++) {
      int sum = r*R + g*G - N;
      sum = -sum;
      if (sum % B == 0) {
        int t = sum / B;
        if (t >= 0 and t <= N) {

        ans++;
        }
      }
    }
  }

  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 256
def kazu(S,T):
  s = len(S)
  t = len(T)
  anss = []
  for j in range(s - t + 1):
    ans = 0
    U = S[j:j+t]
    for k in range(t):
      if U[k] == T[k]:
        ans += 1
    anss.append(ans)
  print(t-max(anss))
  

S = input()
T = input()
kazu(S,T)

Measured memory_bytes: 9124
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

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

	int n;
	cin >> n;
	vector<pair<ll, ll>> xy(n);
	rep(i, n) cin >> xy[i].first >> xy[i].second;

	if (n == 1) {
		cout << 1 << endl;
		return 0;
	}

	sort(allof(xy), [](pair<ll, ll>x, pair<ll, ll>y) {
		return x.first < y.first;
	});

	map<pair<ll, ll>, ll> mp;

	rep(i, n) {
		mp[{xy[i].first, xy[i].second}] = 1;
	}

	ll ans = inf;

	vector<ll> pd(n * n + 1, 0), qd(n * n + 1, 0);
	int index = 0;
	rep(i, n) {
		rep(j, n) {
			if (i == j) continue;
			pd[index] = xy[i].first - xy[j].first;
			qd[index] = xy[i].second - xy[j].second;
			index++;
		}
	}

	rep(j, index) {
		// 順に後ろを見ていく
		ll tmp = 0;
		rep(i, n) {
			if (mp[{xy[i].first - pd[j], xy[i].second - qd[j]}] != 1) tmp++;
		}
		ans = min(ans, tmp);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4096
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize, a: [f64; n]);

    let mut sum = 0.0;
    for v in a {
        sum += 1_f64 / v;
    }
    println!("{}", 1_f64 / sum);
}


Measured memory_bytes: 2172
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n,a,b,sa=0,sb=0,sum=1;
	cin>>n>>a>>b;
	string s;
	cin>>s;
	r(i,n){
		if(s[i]=='a'){
			if(sa+sb<a+b){
				sa++;
				cout<<"Yes"<<endl;
			}
			else cout<<"No"<<endl;
		}
		if(s[i]=='b'){
			if(sa+sb<a+b&&b>=sum){
				sb++;
				cout<<"Yes"<<endl;
			}
			else cout<<"No"<<endl;
			sum++;
		}
		if(s[i]=='c') cout<<"No"<<endl;
	}
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define input(array) repi(array##_itr, array) { cin >> *(array##_itr); }
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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 long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	int ans=0;
	cin >>n;
	Vi a(n);
	input(a);
	rep(i, n) {
		if (i % 2 == 0 and a[i] % 2 == 1) {
			ans++;
		}
	}
	cout<<ans<<endl;
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vchar = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
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;}
ll mod = 1000000007;

int main(){
  ll n, W;
  cin >> n >> W;
  vll w(n), v(n);
  rep(i, 0, n) cin >> w.at(i) >> v.at(i);
  vvll dp(n + 1, vll(W + 1, 0));
  rep(i, 1, n + 1) rep(j, 0, W + 1){
    if(j - w.at(i - 1) >= 0) chmax(dp.at(i).at(j), dp.at(i - 1).at(j - w.at(i - 1)) + v.at(i - 1));
    chmax(dp.at(i).at(j), dp.at(i - 1).at(j));
  }
  cout << dp.at(n).at(W) << endl;
}

Measured memory_bytes: 80256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn combinations(n: i64, r: i64) -> i64 {
	let mut factorialN = 1;
	for i in 0..r {
    	factorialN = factorialN * (n - i);
    }
    let mut factorialR = 1;
    for i in 0..r {
    	factorialR = factorialR * (r - i);
    }
    let ans: i64 = factorialN / factorialR;
    return ans;
}

fn main() {
	let a: i64 = read();
    let b: i64 = read();
    let evenAddEvenCount: i64 = combinations(a, 2);
    let oddAddOddCount: i64 = combinations(b, 2);
    println!("{}", evenAddEvenCount + oddAddOddCount);
}

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

int main()
{
   vector<int> arr(5);
   for(int i = 0; i < 5; i++) cin >> arr[i];
   
   sort(arr.begin(), arr.end(), [](int a, int b) {
       return ((a-1)%10) < ((b-1)%10);
   });
   int sum = 0;
   for(int i = 4; i > 0; i--) {
       sum += arr[i] + 9;
       sum -= sum % 10;
   }
   sum += arr[0];
   cout << sum;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int n, d;
int nd;
int r;

void solve(){
    r = d*2 + 1;
    nd = n/r;
    if(n%r != 0){
        cout << nd+1 << endl;
    }else {
        cout << nd << endl;
    }
}

int main(){
    cin >> n >> d;
    solve();
}

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

using namespace std;

int main() {
	string S;
	cin >> S;

	sort(S.begin(), S.end());
	
	if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
W,H,N = map(int,input().split())
X1,X2,Y1,Y2 = 0,W,0,H
for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        X1 = max(x,X1)
    elif a == 2:
        X2 = min(x,X2)
    elif a == 3:
        Y1 = max(y,Y1)
    elif a == 4:
        Y2 = min(y,Y2)
print(max(0,(X2-X1))*max(0,(Y2-Y1)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr <<__LINE__<< ": " << #x << " = " << x << endl
#define debug_vec(v) cerr<<__LINE__<<": "<<#v<<" = ";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
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 int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;


void solve() {
    int n;
    cin >> n;
    vector<int> A(n);
    for(auto &a : A) cin >> a;
    ll ans = -LINF;
    if (n % 2 == 0) {
        ll sum = 0;
        for (int i = 1; i < n; i+=2) sum += A[i];
        chmax(ans, sum);
        for (int i = 0; i < n; i+=2){
            sum += A[i] - A[i + 1];
            chmax(ans, sum);
        }
        cout << ans << endl;
        return;
    } else {
        n /= 2;
        ll dp[n + 1][3];
        rep(i, n + 1) rep(j, 3) dp[i][j] = -LINF;
        dp[0][0] = dp[0][1] = dp[0][2] = 0LL;
        rep(i, n) {
            chmax(dp[i + 1][0], dp[i][0] + A[2 * i]);
            chmax(dp[i + 1][1], max(dp[i][0], dp[i][1]) + A[2 * i + 1]);
            chmax(dp[i + 1][2], max({dp[i][0], dp[i][1], dp[i][2]}) + A[2 * i + 2]);
        }
        cout << *max_element(dp[n], dp[n] + 3) << endl;
        return;
    }
}

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


Measured memory_bytes: 6360
n = int(input())
a=list(map(int,input().split()))
cnt,cnt2,cnt4=0,0,0
for val in a:
    if val%4==0:
        cnt4+=1
    elif val%2==0:
        cnt2+=1
    else:
        cnt+=1
if cnt2==0:
    if cnt4>=cnt-1: print("Yes")
    else: print("No")
else:
    if cnt4>=cnt: print("Yes")
    else: print("No")

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

int main()
{
    int n, k;
    string s;
    cin >> n;
    cin >> s;
    cin >> k;
    char s_k = s.at(k - 1);
    rep(i, n)
    {
        if (s.at(i) != s_k)
        {
            s.at(i) = '*';
        }
    }
    cout << s << endl;
}

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

//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
//typedef unsigned long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
typedef pair<int, int> P;
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 100;
//const ll INF = (1ll << 31) - 1;
const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
//typedef pair<int, int> P;
//typedef pair<double, double> P;

//bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;


ll gcd(ll x, ll y) {
    if (x > y) swap(x, y);
    ll m = 1;
    while (m != 0) {
        m = y % x;
        y = x;
        x = m;
    }
    return y;
}


ll lcd(ll x, ll y) {
    return x / gcd(x, y) * y;
}

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

    vector<ll> numbers(n);
    rep(i, n) cin >> numbers[i];
    ll ans = numbers.front();
    for (ll a : numbers) ans = lcd(ans, a);
    cout << ans << endl;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
long long int s,i,a,b,a1,b1;
int main()
{

    scanf("%lld",&s);
    while(s!=0)
    {
       s=s*2;
       for(i=1;i<=sqrt(s);i=i+1)
       {
           if(s%i==0)
           {
               b=i;
               a=(s/i)-i+1;
               a=a/2;
               if((a*2+b-1)*b==s)
               {
                   a1=a;
                   b1=b;
               }
           }
       }
       printf("%lld %lld\n",a1,b1);
       scanf("%lld",&s);
    }
    return 0;
}



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

int main()
{
  int n;
  cin >> n;
  vector<int> a;
  vector<int> a_o;
  for(int i = 0; i < n; i++){
    int x;
    cin >> x;
    a_o.push_back(x);
  }
  a = a_o;
  sort(a.begin(),a.end(),greater<int>());
  for(int i = 0; i < n; i++){
    int ans = (a[0] == a_o[i])? a[1] : a[0];
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3316
// Print Test Cases
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_3_B
//
// Accepted

use std::io::{BufRead, stdin};

fn main() {
    let stdin = stdin();
    let mut stdin = stdin.lock();

    loop {
        let mut buf = String::new();
        stdin.read_line(&mut buf).unwrap();

        let mut data = buf.split_whitespace();

        let x: i32 = data.next().unwrap().parse().unwrap();
        let y: i32 = data.next().unwrap().parse().unwrap();

        if x == 0 && y == 0 {
            break;
        }

        if x < y {
            println!("{} {}", x, y);
        } else {
            println!("{} {}", y, x);
        }
    }
}


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

char determineGrade(int mid, int fin, int mak) {
  if (mid == -1 || fin == -1) return 'F';

  int total = mid + fin;
  if (total >= 80) return 'A';
  if (total >= 65) return 'B';
  if (total >= 50) return 'C';
  if (total >= 30) {
    if (mak >= 50) return 'C';
    return 'D';
  }
  return 'F';
}

int main() {
  int buf[3] = {}, cnt = 0;
  while (cin >> buf[cnt++]) {
    if (cnt % 3 != 0) continue;
    cnt = 0;

    int mid = buf[0], fin = buf[1], mak = buf[2];
    if (mid + fin + mak == -3) return 0;
    cout << determineGrade(mid, fin, mak) << endl;
  }
  return 0;
}



Measured memory_bytes: 3120
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left
import random
from itertools import permutations, accumulate, combinations
import sys
import string


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 10 ** 9 + 7


n, m = LI()


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

    divisors.sort()
    return divisors



min_d = min([d for d in make_divisors(m) if d >= n])
print(m // min_d)




Measured memory_bytes: 41840
n = input()
lst = [int(e) for e in input().split()]

count = 0
m = 0
f = True
while(f):
    f = False
    for i in range(m,len(lst)):
        if(lst[i]%2 == 0):
            m = i
            f = True
            break
    if(f):
        count += 1
    else:
        break

    lst[m] = int(lst[m]/2)

print(count)

Measured memory_bytes: 4148