akhauriyash/Code-Regression huggingface dataset:
from collections import deque

S = input()
Q = int(input())

q = deque(S)

parity = 0
for i in range(Q):
    T = input().split()
    if len(T) == 1:
        parity = (parity + 1) % 2
        #q.reverse()
    else:
        F = int(T[1])
        C = T[2]

        if parity == 0:
            if F == 1:
                q.appendleft(C)
            else:
                q.append(C)
        else:
            if F == 1:
                q.append(C)
            else:
                q.appendleft(C)

if parity == 1:
    q.reverse()

print(''.join(q))


Measured memory_bytes: 8564
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# include <stack>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

int main() {
	ll n, k, bpk=0, cpk=0, counter=0;
	cin >> n >> k;
	vector<ll> modcount(k,0);
	for (int i = 1; i <= n; i++) {
		modcount[i % k]++;//a
}
	rep(a, k) {
		bpk = (k - a) % k;
		cpk = (k - a) % k;
		if ((bpk + cpk) % k == 0) {
			counter += modcount[a] * modcount[bpk] * modcount[cpk];
		}
	}
	cout << counter << endl;
}



Measured memory_bytes: 1792
n = int(input())
S = []
T =[]

for _ in range(n):
    s = input()
    S.append(s)
    
m = int(input())
for _ in range(m):
    t = input()
    T.append(t)

from collections import Counter
cnt_s = Counter(S)
cnt_t = Counter(T)
ans = []
'''
for ks,vs in cnt_s.items():
    for kt,vt in cnt_t.items():
        if ks == kt:
            vs = vs - vt
'''

ans = cnt_s - cnt_t

if len(ans.values()) == 0:
    print(0)
else:
    print(max(ans.values()))

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

const int N = 20;
int n;

long long dp[N][N];
vector <int> r;
vector <int> b;
string s;

int get(int x, int y) {
	return (x >> y) & 1;
}
long long f(int mask) {
	r.clear();
	b.clear();
	for (int i = 0; i < n; i++) {
		if (get(mask, i))
			r.push_back(i);
		else
			b.push_back(i);
	}
//	cout << 73 << " " << r.size() << " " << b.size() << endl;
	for (int i = 0; i <= n; i++) {
	    for (int j = 0; j <= n; j++) {
	        dp[i][j] = 0;
	    }
	}
	dp[0][0] = 1;
	for (int i = 0; i <= r.size(); i++) {
		for (int j = 0; j <= b.size(); j++) {
		 //  cout << i << " " << j << " " << dp[i][j] << endl;
	//		dp[i][j] = 0;
			if (i > 0 && s[r[i - 1]] == s[2 * n - i - j])
	        	dp[i][j] += dp[i - 1][j];
	        
			if (j > 0 && s[b[j - 1]] == s[2 * n - i - j])
				dp[i][j] += dp[i][j - 1];
//			cout << i << " " << j << " " << dp[i][j] << endl;
		}
	}
	
//	cout << mask << " " << dp[(int) r.size()][(int) b.size()] << endl;
	return dp[(int) r.size()][(int) b.size()];
}
int main() {
	cin >> n;
	cin >> s;
	long long ans = 0;
//	for (int i = n; i < 2 * n; i++)
//	    t.push_back(s[i - n]);
	for (int i = 0; i < (1 << n); i++) {
		ans += f(i);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseFloat(x) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n,m=parseMap(split(readline()))
    city=Tuple{Int,Int,Int}[]
    for i in 1:m
        p,y=parseMap(split(readline()))
        push!(city,(p,y,i))
    end
    sort!(city,by=x->x[2])
    sort!(city,by=x->x[1])
    ans=["" for i in 1:m]
    res=1
    for i in 1:m
        if i==1 || city[i-1][1]!=city[i][1]
            res=1
        else
            res+=1
        end
        ans[city[i][3]]=lpad(city[i][1],6,"0")*lpad(res,6,"0")
    end
    println(join(ans,"\n"))
end
main()

Measured memory_bytes: 222456
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int prex = 0, prey = 0, pret = 0;
		int nStep = in.nextInt();
		while(0 != nStep--) {
			int t = in.nextInt();
			int x = in.nextInt();
			int y = in.nextInt();
			if(Math.abs(x - prex) + Math.abs(y - prey) > t - pret) {
				System.out.println("No");
				return;
			}
			if((Math.abs(x - prex) + Math.abs(y - prey)) % 2 != (t - pret) % 2) {
				System.out.println("No");
				return;
			}
			prex = x; prey = y; pret = t;
		}
		System.out.println("Yes");
	}

}


Measured memory_bytes: 86920
//By Don4ick
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qwer1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

const int N = 2005;

using namespace std;

int n, m, q, a[N][N], b[N][N], c[N][N], d[N][N];

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

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	cin >> n >> m >> q;
	forn(i, n)
	{
		string s;
		cin >> s;
		for (int j = 1; j <= m; j++)
		{
			a[i][j] = s[j - 1] - '0';
		}
	}
	forn(i, n)
	{
		forn(j, m)
		{
			b[i][j] = b[i - 1][j] + b[i][j - 1] - b[i - 1][j - 1] + a[i][j];
			c[i][j] = c[i][j - 1] + c[i - 1][j] - c[i - 1][j - 1];
			d[i][j] = d[i][j - 1] + d[i - 1][j] - d[i - 1][j - 1];
			if (a[i][j] == a[i - 1][j] && a[i][j])
				c[i][j]++;
			if (a[i][j] == a[i][j - 1] && a[i][j])
				d[i][j]++;
		}
	}
	forn(i, q)
	{
		int x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		int res = b[x2][y2] - b[x1 - 1][y2] - b[x2][y1 - 1] + b[x1 - 1][y1 - 1];
		res -= c[x2][y2] - c[x1][y2] - c[x2][y1 - 1] + c[x1][y1 - 1];
		res -= d[x2][y2] - d[x2][y1] - d[x1 - 1][y2] + d[x1 - 1][y1];
		printf("%d\n", res);
	}

	return 0;
}


Measured memory_bytes: 64640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
#define ll long long

using namespace std;

const int mod=1e9+7;
int n,m;
ll dp[52][52][2660]={0};

int main()
{
    int i,j,k;
    cin>>n>>m;
    dp[0][0][0]=1;
    //dp[0][1][1]=1;
    for(i=0;i<n;i++)
    {
        for(j=0;j<i+1;j++)
            for(k=0;k<m+1;k++)
            {
                //if(k+2*j>n*n)
                    //continue;
                ll now=dp[i][j][k];

                (dp[i+1][j+1][k+(j+1)*2]+=now)%=mod;
                (dp[i+1][j][k+j*2]+=now)%=mod;
                if(j>0)
                    (dp[i+1][j-1][k+(j-1)*2]+=now*j*j%mod)%=mod;
                (dp[i+1][j][k+j*2]+=now*j*2%mod)%=mod;
            }
    }
    int ans=0;
    printf("%lld\n",dp[n][0][m]%mod);
    return 0;
}


Measured memory_bytes: 53504
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;

template <typename T1, typename T2>
string print_iterable(T1 begin_iter, T2 end_iter, int counter) {
    bool done_something = false;
    stringstream res;
    res << "[";
    for (; begin_iter != end_iter and counter; ++begin_iter) {
        done_something = true;
        counter--;
        res << *begin_iter << ", ";
    }
    string str = res.str();
    if (done_something) {
        str.pop_back();
        str.pop_back();
    }
    str += "]";
    return str;
}

vector<int> SortIndex(int size, std::function<bool(int, int)> compare) {
    vector<int> ord(size);
    for (int i = 0; i < size; i++) ord[i] = i;
    sort(ord.begin(), ord.end(), compare);
    return ord;
}

template <typename T>
bool MinPlace(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool MaxPlace(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <typename Container>
int SZ(const Container& S) { return S.size(); }

template <typename S, typename T>
ostream& operator <<(ostream& out, const pair<S, T>& p) {
    out << "{" << p.first << ", " << p.second << "}";
    return out;
}

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

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file

    #define dbg_var(x) clog << #x  << ": " << x << endl;
    #define dbg_array(x, len) clog << #x << ": " << print_iterable(x, x+len, -1) << endl;
#else
    #define dbg_var(x)
    #define dbg_array(x, len)
#endif

///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////

const int MAXN = 55;
int N;
bool occ[24];
int D[MAXN];
int curr = 100;
int best = 0;

void dfs(int v) {
    if (curr <= best) return;
    if (v == N) {
        best = max(best, curr);
        return;
    }
    vector<int> pos = {D[v]};
    if (D[v] != 0) pos.push_back(24-D[v]);
    for (int p : pos) {
        if (occ[p]) continue;
        int curr_prec = curr;
        for (int i = 0; i < 24; i++) {
            int d = abs(i-p);
            if (occ[i]) curr = min(curr, min(d, 24-d));
        }
        occ[p] = 1;
        dfs(v+1);
        occ[p] = 0;
        curr = curr_prec;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Remove in problems with online queries!

    cin >> N;
    for (int i = 0; i < N; i++) cin >> D[i];
    if (N > 23) {
        cout << 0 << "\n";
        return 0;
    }
    occ[0] = 1;
    dfs(0);
    cout << best << "\n";
}



Measured memory_bytes: 256
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		n: usize,
		k: isize,
		x: [isize; n],
	}

	let mut ans = 0;
	for i in 0..n {
		ans += min(x[i], (k-x[i]).abs()) * 2;
	}
	println!("{}", ans);
}



Measured memory_bytes: 2136
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    int N, K;
    cin >> N >> K;
    int ans = K;
    for (int i = 1; i < N; i++) {
        ans *= K - 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int donutcount,cakecount,N;
    cin >> N;
    for(donutcount=0;N>=donutcount*4;donutcount++){
        for(cakecount=0;N>=cakecount*4+donutcount*7;cakecount++){
            if(N==cakecount*4+donutcount*7){
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,i;scanf("%d",&n);
  int a[n],b[n];
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);b[i] = a[i];
  }
  sort(b,b+n,greater<int>());
  for(i=0;i<n;i++){
    if(a[i]==b[0]) printf("%d\n",b[1]);
    else printf("%d\n",b[0]);
  }
}

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

#define fi first
#define se second
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );

const long long N = 300200;
const long long Q = 100000001;
const long long mod = 1e9 + 7;
const long long MAGIC = 30;

using namespace std;

int k;
string s;
vector < string > v;

void solve()
{
        cin >> s >> k;
        for(int i = 0; i < s.size(); i++){
                string t = "";
                for(int j = 0; i + j < s.size() && j < k; j++){
                        t += s[i + j];
                        v.push_back(t);
                }
        }
        sort(v.begin(), v.end());
        for(int i = 0; i < v.size(); i++){
                if(i > 0 && v[i - 1] == v[i]){
                        continue;
                }
                k--;
                if(k == 0){
                        cout << v[i] << "\n";
                }
        }
}

bool mtest = false; int main()
{
        //fin("input.txt");
        //fout("output.txt");
        //fin("maze.in");
        //fout("maze.out");
        ios_base::sync_with_stdio(0);
        int TE = 1;
        if(mtest)
                cin >> TE;
        while(TE--)
                solve();
        return 0;
}


Measured memory_bytes: 1660
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

struct T
{
	int x,y;
	T(int x, int y) : x(x), y(y) {}
};

int count_bits(int x) {
	int count = 0;
	if(x&1) count++;
	while(x>>=1) if(x&1) count++;
	return count;
}

signed main() {
	debug(count_bits(5));
	int n;
	std::cin >> n;
	std::vector<std::vector<T> > a(n,std::vector<T>());
	rep(i,n) {
		int m;
		std::cin >> m;
		rep(j,m) {
			int x,y;
			std::cin >> x >> y;
			a[i].emplace_back(x-1,y);
		}
	}

	int max = 0;
	for(int x=0;x<(1<<n);x++) {
		// check if valid
		bool valid = true;
		rep(i,n) {
			if(x>>i&1) for(auto t:a[i]) {
				if((x>>t.x&1)!=t.y) {
					valid = false;
					break;
				}
			}
			if(!valid) break;
		}
		if(!valid) continue;
		max = std::max(max, count_bits(x));
	}
	print(max);

	return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
#include <math.h>
#include <sstream>
#include <iterator>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
// 大きい順
#define rall(v) v.rbegin(), v.rend()
#define vi vector<int>
#define vl vector<ll>
const  long long INF = 1LL << 60;
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;
}



int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}

bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された

    if(n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である

    // 6の倍数前後の数を使って試し割りをする
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }

    return true;
}

map<ll,ll> mp;

auto findFactors(ll num){
	
    ll i;
    while (num % 2 == 0){ // 偶数の素数は2のみ
        if(mp.count(2)){
			mp[2] = mp[2] + 1;
		}
		else{
			mp[2] = 1;
		}
        num /= 2;
    }
    for (i = 3; i <= num; i++){ // 他の素数で割っていく
        while (num % i == 0){
			if(mp.count(i)){
			mp[i] = mp[i] + 1;
		}
		else{
			mp[i] = 1;
		}
            num /= i;
        }
    }
    return 0;
}
ll kaizyou(ll n){
    if(n == 1){
        return 1;
    }
    else{
        return (n * kaizyou(n-1)) % 1000000007;
    }
}

int main(){
ll N; cin >> N;
vl A(N);
map<ll,ll> mp;
rep(i,N){
    ll a; cin >> a;
    A[i] = a;
    if(!mp.count(a)) mp[a] = 1;
    else mp[a] += 1;
}

map<ll,ll> q;
ll sum = 0;
for(auto u: mp){
    q[u.first] = 0;
    if(u.second >= 2){
        ll l = u.second * (u.second - 1) / 2;
        q[u.first] = l - (u.second -1 ) * (u.second - 2) / 2;
        sum += l;
    }
}

rep(i,N){
    cout << sum  - q[A[i]] << endl;
}
}

Measured memory_bytes: 18944
#include <iostream>
using namespace std;
int main(void){
    //
    int a,b;
    
    cin>>a>>b;
    
    int ans=max(a,b);
    
    if(a>=b){
        a--;
    }
    
    else{
        b--;
    }

ans =ans+max(a,b);
cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
import static java.lang.Math.min;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while (!(line = br.readLine()).equals("0")) {

			//
			int n = Integer.parseInt(line);
			int[][] grid = new int[n + 2][n + 2];

			for (int i = 0; i < n; i++) {
				line = br.readLine();
				for (int j = 0; j < n; j++) {
					grid[i + 1][j + 1] = line.charAt(j) == '.' ? 1 : 0;
				}
			}

			//
			int max = 0;
			for (int i = 1; i < n + 1; i++) {
				for (int j = 1; j < n + 1; j++) {
					if (grid[i][j] != 0) {
						int min;
						min = (int) min(grid[i - 1][j - 1], grid[i - 1][j]);
						min = (int) min(min, grid[i][j - 1]);
						grid[i][j] += min;
						if (grid[i][j] > max) {
							max = grid[i][j];
						}
					}
				}
			}
			System.out.println(max);

		}

	}

}

Measured memory_bytes: 50224
#include <cstdio>
#include <vector>

int vis[100005];

std::vector<int> edges[100005];

int dfs(int node,int c=1){
  int size=1;
  vis[node]=c;
  for(int child:edges[node]){
    if(!vis[child]) size+=dfs(child,c^3);
    if(vis[child]&c) vis[node]=3;
  }
  return size;
}

int main(){
  int N,M;
  scanf("%d %d",&N,&M);
  for(int i=0;i<M;i++){
    int U,V;
    scanf("%d %d",&U,&V);
    U--,V--;
    edges[U].push_back(V);
    edges[V].push_back(U);
  }
  int nccs=0;
  int bipart=0;
  int solo=0;
  for(int i=0;i<N;i++){
    if(!vis[i]){
      if(dfs(i)==1){
	solo++;
      }else{
	bipart+=(vis[i]!=3);
	nccs++;
      }
    }
  }
  printf("%lld\n",1LL*nccs*nccs+1LL*bipart*bipart+1LL*N*N-1LL*(N-solo)*(N-solo));
  return 0;
}


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

int main() {
  int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int n = 0;
  cin >> n;
  cout << a[n-1] << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<sstream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<numeric>
#include<complex>

using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define np string::npos
#define X real()
#define Y imag()
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define repc(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

typedef long long ll ;
typedef deque<int> di ;
typedef deque<ll> dl ;
typedef map<string,int> dict;
typedef complex<double> comd;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
const double PI = acos(-1.0) ;
double eps = 1e-10 ;

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

bool Check(di mem){
  int i =0;
  repa(n,mem){
    if(n == 1){
      ++ i ;
    }
  }
  return i != 1;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m,pos;
  while(cin >> n >> m){
    if(n + m == 0){
      break ;
    }
    di mem(n,1);
    pos = n - 1;
    while(Check(mem)){
      rep(i,m){
        ++pos;
        if(pos >= n){
          pos = 0;
        }
        while(mem[pos] == 0){
          ++pos;
          if(pos >= n){
            pos = 0;
          }
        }
      }
      mem[pos] = 0;
    }
    cout << 1 + find(all(mem),1) - mem.begin() << endl;
  }
  return 0;
}

Measured memory_bytes: 3096
while True:
    a, op, b = tuple(input().split())
    a = int(a)
    b = int(b)

    if op == "+":
        print(a+b)
    elif op == "-":
        print(a-b)
    elif op == "*":
        print(a*b)
    elif op == "/":
        print(a//b)
    else:
        break


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
const int mod = 1e9 + 7;
const int INF = 1e9;
const double pi = acos(-1.0);
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
int main(){
    int n, k; cin >> n >> k;
    vll p(n);
    rep(i,n)cin >> p[i];
    sort(all(p));       
    ll sum = 0;
    rep(i,k)sum += p[i];
    cout << sum << endl;
    return 0;
}  

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

using namespace std;

int main()
{
    string s ;
    cin>>s ;
    int ans = 0 ;
    for(int i = 0 ; i < s.size() ; ++i)
    {
        for(int j = i ; j < s.size() ; ++j)
        {
            if(s[j] != 'A' && s[j] != 'C' & s[j] != 'G' && s[j] != 'T')
                break;
            ans = max(ans , j-i+1) ;
        }
    }
    return cout<<ans<<"\n" , 0 ;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<ll, int> mp;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<ll> a(n + 1), b(n);
	vector<ll> p(n), tmp(n);
	for (int i = 0; i < n + 1; i++) cin >> a[i];
	for (int i = 0; i < n; i++) cin >> b[i];
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] <= b[i]) {
			sum += a[i];
			b[i] -= a[i];
			a[i] = 0;
		}
		else {
			sum += b[i];
			a[i] -= b[i];
			continue;
		}
		if (a[i + 1] <= b[i]) {
			sum += a[i + 1];
			a[i + 1] = 0;
		}
		else {
			sum += b[i];
			a[i + 1] -= b[i];
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
string s,t;
signed main(){
    cin>>s>>t;
    int l=s.size();
    if(t.substr(0,l)==s)puts("Yes");
    else puts("No");
    return 0;
}


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

#include <set>
#include <iterator>
using namespace std;
// using namespace __gnu_pbds;


#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF (ll)1e17
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )
#define maxbits 9
#define maxmask (1ll<<maxbits)
// typedef tree<pll, null_type, less<pll>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
const int  N=1e6 +10, M=(ll)1e9+1 ;
const int mod =998244353 ,sz=5, MAX=(ll)1e6+10;
string fir="Monocarp",sec="Bicarp";

vector<ll> divisors(ll n){
	vl a;
	if(n==1)
		return a;
	for(ll i=2;i*i<=n;i++){
		if(n%i==0){
			a.pb(i);
			if(i!=n/i)
				a.pb(n/i);
		}
	}
	a.pb(n);
	return a;
}
void work(){
	ll n;
	cin >> n;

	ll ans=0;
	vl a=divisors(n-1);
	ans=a.size();
	a=divisors(n);
	for(ll i=0;i<a.size();i++){
		ll x=n;
		while(x%a[i]==0){
			x/=a[i];
		}

		if(x%a[i]==1)
			ans++;
	}
	cout << ans;
	return;

}

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

	// precomp();
	ll t;
	// cin >> t;
	t=1;
	while(t--){
	        work();
	
	}
return 0;
}
	

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
using namespace std;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef vector<PII> VP;

int n, m, k;
VP road[3010];
int s[3010];
int ans = 0;

priority_queue<PII, VP, greater<PII> > sr;
bool visited[3010];
int dist[3010];

int dijk()
{
  int ret;
  for(int i = 0; i < k; i++)
    sr.push(MP(0, s[i]));
  
  while(!sr.empty()){
    PII now = sr.top();
    sr.pop();

    if(!visited[now.second]){
      visited[now.second] = true;
      dist[now.second] = now.first;
      ret = now.first;
      for(int i = 0; i < road[now.second].size(); i++)
	if(!visited[road[now.second][i].second])
	  sr.push(MP(now.first + road[now.second][i].first, road[now.second][i].second));
    }
  }
  
  return ret;
}

int main()
{
  scanf("%d%d%d", &n, &m, &k);
  for(int i = 0; i < m; i++){
    int a, b, l;
    scanf("%d%d%d", &a, &b, &l);
    road[a].PB(MP(l, b));
    road[b].PB(MP(l, a));
  }
  
  for(int i = 0; i < k; i++)
    scanf("%d", &s[i]);

  ans = dijk();

  for(int i = 1; i <= n ; i++)
    for(int j = 0; j < road[i].size(); j++)
      if(abs(dist[i] - dist[road[i][j].second]) < road[i][j].first){
	int longest = (road[i][j].first - abs(dist[i] - dist[road[i][j].second])) / 2 + max(dist[i], dist[road[i][j].second]);
	if((road[i][j].first - abs(dist[i] - dist[road[i][j].second])) % 2)
	  longest++;

	ans = max(ans, longest);
      }
  
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 4952
from collections import deque
h, w = map(int, input().split())
s = [input() for _ in range(h)]

def bfs(sy, sx):
    dst = [[-1]*w for _ in range(h)]
    dst[sy][sx] = 0
    que = deque([])
    que.append([sy, sx])

    while que:
        y, x = que.popleft()
        dx = [0,1,0,-1]
        dy = [1,0,-1,0]
        for i in range(4):
            ny = y+dy[i]
            nx = x+dx[i]
            if ny < 0 or ny >= h or nx < 0 or nx >= w:
                continue
            if s[ny][nx] == '#':
                continue
            if dst[ny][nx] != -1:
                continue

            dst[ny][nx] = dst[y][x] + 1
            maxd[0] = dst[y][x] + 1
            que.append([ny, nx])



ans = -float('inf')
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            continue
        maxd = [0]
        bfs(i, j)
        ans = max(ans, maxd[0])
print(ans)

Measured memory_bytes: 3316
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<algorithm>
#include<cmath>
using namespace std;

typedef long long int llint;

int main(){
	int N,K;
	vector<int> H;
	cin >> N >> K;
	for(int i=0;i<N;i++){
		int h;
		cin >> h;
		H.push_back(h);
	}
	sort(H.begin(),H.end());
	int minHd=H[K-1]-H[0];
	for(int i=0;i<N-K+1;i++){
		if(minHd>H[K+i-1]-H[i]){
			minHd=H[K+i-1]-H[i];
		}
	}

	cout << minHd << endl;
	return 0;
}


Measured memory_bytes: 892
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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; }

int N;
long long L[100]={};

int main(){
    cin>>N;
    L[0]=2;
    L[1]=1;
    repi(i,2,N+1){
        L[i]=L[i-1]+L[i-2];
    }
    out(L[N]);
}


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

int main() {
    int n; cin >> n;
    int a[200010] = {};
    for (int i = 1; i < n; i++) {
        int x; cin >> x;
        a[x]++;
    }
    for (int i = 1; i <= n; i++) {
        cout << a[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 4416
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int n;
  cin >> n;
  
  int i = 1;
  int64_t power = 1;
  while(i <= n){
    power = power * i % 1000000007;
    i++;
  }
  
  cout << power << endl;
  
}

Measured memory_bytes: 3632
k, a, b = map(int, input().split())

have = 1
if b - a > 2 and k >= a + 1:
    k -= a + 1
    have = b
    have += (b - a) * (k // 2)
    k %= 2
    have += k
    print(have)
else:
    print(have + k)

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>

using namespace std;

bool is_perfect_square(int n)
{
	if (n < 0)
		return false;

	int root(round(sqrt(n)));
	return n == root * root;
}

int main()
{
	int a, b;

	cin >> a >> b;

	int res = 1;
	int tmp = b;
	while (tmp)
	{
		res *= 10;
		tmp /= 10;
	}

	res = res * a + b;

	if (is_perfect_square(res))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 384
import sys
from functools import lru_cache
sys.setrecursionlimit(2*10**5)

# 入力
N, M = map(int, input().split())
A = list(map(int, input().split()))

INF = 10**15
# 各数字の消費マッチ棒
C = (100, 2, 5, 5, 4, 5, 6, 3, 7, 6)


# N=nのときの解に対応するベクトルを返す
@lru_cache(maxsize=None)
def dfs(n):
    return (
        [-INF for _ in range(9)] if n < 0 else
        [0 for _ in range(9)] if n == 0 else
        max(
            (
                [
                    t + 1 if i == a else t
                    for i, t in enumerate(dfs(n - C[a]), start=1)
                ]
                for a in A
            ),
            key=lambda x: [sum(x)] + list(reversed(x))
        )
    )


# 出力
ans = ''.join(str(a) * dfs(N)[a - 1] for a in sorted(A, reverse=True))
print(ans)


Measured memory_bytes: 26056
//author:Deshansh Garg
#include<bits/stdc++.h>
typedef long long int lli;
using namespace std;

    
int main()
{
lli n,w;
cin>>n>>w;
lli wt[n],val[n];
for(lli i=0;i<n;i++) 
{cin>>wt[i]>>val[i];
}
lli grid[n+1][w+1];
for(lli i=0;i<=n;i++)
{
  for(lli j=0;j<=w;j++)
  {
    if(i==0 || j==0) grid[i][j]=0;
    else if(wt[i-1]<=j)
    {
      grid[i][j]=max(val[i-1]+grid[i-1][j-wt[i-1]],grid[i-1][j]);
    }
    else grid[i][j]=grid[i-1][j];
  }

}
cout<<grid[n][w]<<endl;
 
}

Measured memory_bytes: 79104
k,s = [int(i) for i in input().split()]
def a(n):
  return int(n * (n + 1) / 2)
  
if s <= k:
  print(a(s + 1))
elif s >= 2 * k and s <= 3 * k:
  print(a(3 * k - s + 1))
elif s > k and s < 2 * k:
  print(a(s + 1) - 3 * a(s - k))
else:
  print(0)

Measured memory_bytes: 3060
s = input()
q = int(input())
swc = 0
top = ""
bot = ""
for i in range(q):
	a = list(map(str, input().split()))
	if a[0] == "1":
		if swc == 0:
			swc = 1
		else:
			swc = 0
	else:
		if swc == 0:
			if a[1] == "1":
				top += a[2]
			else:
				bot += a[2]
		else:
			if a[1] == "1":
				bot += a[2]
			else:
				top += a[2]
if swc == 0:
	top = ''.join(list(reversed(top)))
	print (top + s + bot)
else:
	bot = ''.join(list(reversed(bot)))
	s = ''.join(list(reversed(s)))
	print (bot + s + top)


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

int main() {
    long n, ans = 0;
    cin >> n;
    bool odd = false;
    vector<long> data(n);
    for (int i = 0; i < n; i++) {
        cin >> data.at(i);
        if (data.at(i) % 2 == 1) {
            odd = true;
            break;
        }
    }
    while (odd != true) {
        for (int i = 0; i < n; i++) {
            data.at(i) /= 2;
            if (data.at(i) % 2 == 1) {
                odd = true;
                ans++;
                break;
            }
        }
        if (odd == false) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 1e9+7;



int main(){
    ll N; cin >> N;
    vector<ll> V1(N), V2(N);
    for(int i = 0; i < N; i++) cin >> V1[i] >> V2[i];
    bool flag = false;
    for(int i = 0; i < N-2; i++){
        if(V1[i] == V2[i] && V1[i+1] == V2[i+1] && V1[i+2] == V2[i+2]) {
            flag = true;
        }
    }

    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n, k;
    cin >> n >> k;

    map<ll, ll> mp;
    ll a;
    REP(i, n){
        cin >> a;
        mp[a]++;
    }

    ll t = mp.size() - k;
    if(t <= 0){
        cout << 0 << endl;
        return 0;
    }
    vll mem;
    for(auto v : mp) mem.push_back(v.second);
    VSORT(mem);
    ll res = 0;
    REP(i, t) res += mem[i];
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 14964
#include <iostream>
#include <string>

using namespace std;

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

  short int k;
  cin >> k;

  string s;
  cin >> s;

  switch(s[k-1]) {
    case 'A':
      s[k-1] = 'a';
      break;
    case 'B':
      s[k-1] = 'b';
      break;
    case 'C':
      s[k-1] = 'c';
      break;
  }

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    rep(test,t){
        int n,m,a,b;
        cin>>n>>m>>a>>b;
        cout<<floor_sum(n,m,a,b)<<"\n";
    }
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
const int N(1e6 + 5);
unordered_map<int, int> freq;
int n, x, d, p;
bool ok(true), curr;
int main() {
    DAU
    cin >> n;
    vector<vector<int>> factori(n + 1);
    vector<int> v(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> x;
        v[i] = x;
        d = 2;
        while (x != 1) {
            p = 0;
            while (x % d == 0)
                x /= d, p = 1;
            if (p) {
                ++freq[d];
                factori[i].emplace_back(d);
            }
            if (d == 2)
                d = 3;
            else d += 2;
            if (d * d > x)
                d = x;
        }
    }
    for (int i = 1; i <= n && ok; ++i)
        for (const int& d : factori[i])
            if (freq[d] != 1) {
                ok = false;
                break;
            }
    if (ok) {
        cout << "pairwise coprime";
        PLEC
    }
    d = v[1];
    for (int i = 2; i <= n; ++i)
        d = __gcd(d, v[i]);
    if (d == 1)
        cout << "setwise coprime";
    else cout << "not coprime";
    PLEC
}


Measured memory_bytes: 76116
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pie 3.142857143
#define ll long long int
#define fr(i,a,n) for(ll i=a;i<n;i++)
#define vi vector<int>
#define vlli vector<ll>
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fv(i,a) for(auto i:a)
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define frv(i,c) for(auto i = c.begin(); i != c.end(); i++)
const int N = 1e5 + 7;
vi d(N, -1);
vi h;
int dppp(int k)
{

	if (d[k] == -1)
	{
		if (k == 0)
			d[k] = 0;
		else if (k == 1)
			d[k] = abs(h[1] - h[0]);
		else
			d[k] = (min(dppp(k - 1) + abs(h[k] - h[k - 1]), dppp(k - 2) + abs(h[k] - h[k - 2])));

	}
	return d[k];
}
void solve()
{
	ll n;
	cin >> n;

	fr(i, 0, n)
	{
		int x;
		cin >> x;
		h.pb(x);

	}
	int c = dppp(n - 1);
	cout << c << endl;
}


int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen ("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t;
	//cin>>t;
	t = 1;
	while (t--)
	{
		solve();
	}


	return 0;
}

Measured memory_bytes: 6480
#include <iostream>

using namespace std;

int h,w,c[1401][1401],dp[1401][1401];

int dfs(int x,int y) {
	if(x <= 0 || y <= 0) return 0;
	if(dp[y][x] == -1) {
		if(c[y][x]) dp[y][x] = 0;
		else {
			dp[y][x] = min(dfs(x-1,y-1),min(dfs(x,y-1),dfs(x-1,y)))+1;
		}
	}
	return dp[y][x];
}

int main(){
	cin >> h >> w;
	for(int y = 1;y <= h;y++) for(int x = 1;x <= w;x++) cin >> c[y][x];
	for(int i = 0;i < 1401;i++)for(int j=0;j<1401;j++) dp[i][j] = -1;
	int res = 0;
	for(int i = 1;i <= h;i++) for(int j = 1;j <= w;j++) res = max(res,dfs(j,i));
	cout << res*res << endl;
}



Measured memory_bytes: 18436
import java.util.Scanner;

class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        sc.close();
        if(Character.isUpperCase(str.charAt(0))){
            System.out.println("A");
        }
        else{
            System.out.println("a");
        }
    }
}

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

#define GO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int

const int maxr = 1e5 + 5;


int32_t main()
{
	GO;
	int a, b;
	cin >> a >> b;
	if (a != 1 && b != 1)
		cout << 1 << endl;
	else if (a != 2 && b != 2)
		cout << 2 << endl;
	else
		cout << 3 << endl;

	return 0;
}

//!

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

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a + b > c + d)
        cout << "Left";
    if (a + b == c + d)
        cout << "Balanced";
    if (a + b < c + d)
        cout << "Right";
}


Measured memory_bytes: 256
#include<bits/stdc++.h> //ABC 161_b
using namespace std;
int n,m,a[105],sum,num;
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	double x=sum/(4.0*m);
	for(int i=1;i<=n;i++){
		if(a[i]>=x)
		num++;
	}
	if(num>=m)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using bint = boost::multiprecision::cpp_int;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repSE(i,s,n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll INF = 1e18;
ll dp[200002][4];

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    int k = 1 + N%2;
    rep(i,N+1) rep(j,k+1) dp[i][j] = -INF;
    dp[0][0] = 0;
    rep(i,N) rep(j,k+1) {
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]);
        ll now = dp[i][j];
        if ((i+j)%2 == 0) now += A[i];
        dp[i+1][j] = max(dp[i+1][j], now);
    }
    cout << dp[N][k] << endl;
    return 0;
}


Measured memory_bytes: 10388
#include <bits/stdc++.h>
using namespace std;
bool A[105][105],V[105]={0};
int d[105],n;
queue<int> B;

void bfs(){
	B.push(1);
	d[1] = 0;
	V[1] = 1;
	while(!B.empty()){
		int v = B.front();
		B.pop();
		for(int i=1;i<=n;i++)
			if(A[v][i] && !V[i]){
				d[i] = d[v]+1;
				V[i] = 1;
				B.push(i);
			} 
	}
}
int main()
{	
	memset(A,0,sizeof(A));
	int v,u,du;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>v>>du;
		while(du--)
			cin>>u,
			A[v][u] = 1;
	}
	bfs();
	for(int i=1;i<=n;i++)
		if(!V[i]) d[i] = -1;
	for(int i=1;i<=n;i++)
		printf("%d %d\n",i,d[i]);
	return 0;
}


Measured memory_bytes: 3200
#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 ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;

int main() {
  ll n;
  cin >> n;
  for (int i = 1; i < 10; i++) {
    if (n % i == 0 && n / i < 10) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int main(){
    string s;
    cin >> s;
    puts(s == "AAA" || s == "BBB" ? "No" : "Yes");
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
using namespace std;
#define INF 1000000007
#define ll long long
#define rep(i_, __start, __end) for(ll i_=(ll)__start; i_<(ll)__end; i_++)
#define print(_a) cout << _a << endl;
#define printarray(a, len) rep(ii,0,len) cout << a[ii] << " ";
#define printarray2(aa, len) rep(ij,0,len) printarray(aa[ij], aa[ij].size()); print("");
 
int main(){
    ll n, l, a, b, c, ans=0;
    cin >> n;
    vector<ll> list;
    rep(i, 0, n){
      cin >> l;
      list.push_back(l);
    }
    sort(list.begin(), list.end());
    //printarray(list, n);
 
    rep(i, 0, n-2){
      a = list[i];
      rep(j, i+1, n-1){
        b = list[j];
        for(ll k=n-1; k>j; k--){
          c = list[k];
          if(c < a + b){
            ans++;
          }
        }
 
      }
    }
 
    print(ans);
  
  return 0;
}

Measured memory_bytes: 256
#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 n;
int x[110][2],y[110][2];

void solve(){
  cin >> n;
  vector<P> v;
  rep(i,n){
    v.push_back(P(i,0));
    v.push_back(P(i,1));
  }
  rep(i,n){
    cin >> x[i][0] >> y[i][0];
  }
  rep(i,n){
    cin >> x[i][1] >> y[i][1];
  }
  sort(v.begin(),v.end(),[](P a,P b){
    return x[a.first][a.second]<x[b.first][b.second];
  });
  set<int> se={};
  int ans=0;
  rep(i,2*n){
    int s=v[i].first,t=v[i].second;
    if(t==0){
      se.insert(y[s][t]);
    }
    else{
      auto it=se.lower_bound(y[s][t]);
      if(it==se.begin()) continue;
      it--;
      ans+=1;
      se.erase(it);
    }
  }
  cout << ans << endl;
}

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

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpll = vector<pll>;
using vs = vector<string>;
template <typename T>
using ost = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;
#define forn(i,n) for(int i=0; i<int(n); ++i)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define ff first
#define ss second

int digsum(int x) {
    int ans = 0;
    for (; x; x/=10) ans += x%10;
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int best = 999;
    for (int a=1; a<n; a++)
        best = min(best, digsum(a)+digsum(n-a));
    cout << best << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ull            unsigned long long int
#define ll             long long int
#define pb(x)          push_back(x)
#define mp(a,b)        make_pair(a,b)
#define li(ini)        for(ull i=ini;;i++)
#define lfi(i,ini,r)   for(ull i=ini;i<r;i++)
#define lfd(i,ini,r)   for(ull i=ini;i>=r;i--)
#define lit(it,v)      for(auto it=v.begin();it!=v.end();it++)
#define l(v)           for(ull b:v)
#define sorta(v)       sort(v.begin(),v.end())
#define sortd(v)       sort(v.begin(),v.end(),greater<>())
#define vf(i)          v[i].first
#define vs(i)          v[i].second
#define fast_io        ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define en             "\n"
#define sr(s)          reverse(s.begin(),s.end())


using namespace std;

vector<ll>v;
vector<ll>s;

int main()
{
    //fast_io

    ll x=0,res=0,t=0,i=0,j=0,m=0,n=0,a=0,b=0,c=0,d=0,sum=0,flag=0,flag1=1,cont=0,k=0;
      v.clear();
    lfi(i,0,4)
    {
        cin>>x;
        v.pb(x);
    }
    lfi(i,0,3)
    {
        if(v[i]<=v[3])
        {
            if(i==0)
            {
                sum+=v[i];
                v[3]=v[3]-v[i];
            }
            else if(i==2)
            {
                sum-=v[i];
                v[3]=v[3]-v[i];
            }
            else
            {
                v[3]=v[3]-v[i];
            }
           //cout<<sum<<" "<<v[3]<<en;
        }
        else
        {
            if(i==0)
            {
                sum+=v[3];
                v[3]=0;

            }
            else if(i==2)
            {
                sum-=v[3];
                v[3]=0;

            }

           //cout<<sum<<" "<<v[3]<<en;

        }
    }
    cout<<sum<<en;

    return 0;
}


Measured memory_bytes: 3636