akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

const int Nmax=8;
bool check_route(bool route[][Nmax],bool node[],int now);
bool check_node(bool node[]);
void print_route(bool route[][Nmax]);
int count=0;


int main(void){

//初期データの入力
	int N,M;
	cin>>N>>M;

	bool route[Nmax][Nmax];
	bool node[Nmax];

	int n1,n2;

	//ノードを訪れたかを初期化 範囲外のノードは最初からtrue
	for(int i=0;i<Nmax;i++){
		if(i<N) node[i]=false;
		else node[i]=true;
	}

	//ルートの初期化
	for(n1=0;n1<Nmax;n1++){
		for(n2=0;n2<Nmax;n2++){
			route[n1][n2]=false;
		}
	}

	//ルートの登録
	for(int i=0;i<M;i++){
		cin>>n1>>n2;
		route[n1-1][n2-1]=true;
		route[n2-1][n1-1]=true;
		
	}

//データ入力終了

	check_route(route,node,0);

	cout<<count<<endl;

}

//すべてのnodeに到達したならtrueを返す
bool check_node(bool node[]){

	for(int i=0;i<Nmax;i++){
		if(node[i]==false) return false;
	}

	return true;

}



//ルートの探索関数
bool check_route(bool route[][Nmax],bool node[],int now){

	int next;

	//現在地を到着済みに
	node[now]=true;

	//もしすべてのノードに到達したならば正解個数を1増やし終了
	if(check_node(node)==true){
		count++;
	}

	//もし行ってない場所にいける経路があるなら移動
	for(next=0;next<Nmax;next++){
		if( (node[next]==false) && (route[now][next])==true){
			route[now][next]=route[next][now]=false;
			check_route(route,node,next);
			route[now][next]=route[next][now]=true;
		}
	}

	//関数を抜けるときは到達をもとに戻しておく
	node[now]=false;
	return false;
}

void print_route(bool route[][Nmax]){

	for(int i=0;i<Nmax;i++){
		for(int j=0;j<Nmax;j++){
			cout<<route[i][j];
		}
		cout<<endl;
	}


}


Measured memory_bytes: 256
#include <atcoder/fenwicktree>
#include <cstdio>

using namespace std;
using namespace atcoder;

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

    fenwick_tree<long long> fw(n);
    for (int i = 0; i < n; i++) {
        int a;
        scanf("%d", &a);
        fw.add(i, a);
    }

    for (int i = 0; i < q; i++) {
        int t;
        scanf("%d", &t);
        if (t == 0) {
            int p, x;
            scanf("%d %d", &p, &x);
            fw.add(p, x);
        } else {
            int l, r;
            scanf("%d %d", &l, &r);
            printf("%lld\n", fw.sum(l, r));
        }
    }
}


Measured memory_bytes: 8212
#include<iostream>
#include<unordered_set>
#define N 105
#define UNDEFINED -1
static const int INF = (1<<21);

int n,a;
int d[N], p[N];
int G[N][N];

int prim() {
    int u, min;
    std::unordered_set<int> hasVisited;
    for(int i = 0; i < N; i++) {
        d[i] = INF;
        p[i] = UNDEFINED;
    }
    d[0] = 0;
    while(true) {
        min = INF;
        u = UNDEFINED;
        for(int i = 0; i < n; i++) {
            if(d[i] < min && hasVisited.find(i) == hasVisited.end()) {
                u = i;
                min = d[i];
            }
        }
        if (u == UNDEFINED) break;
        hasVisited.insert(u);
        for(int i = 0; i < n; i++) {
            if(hasVisited.find(i) == hasVisited.end() && G[u][i] != UNDEFINED) {
                if(d[i] > G[u][i]) {
                    d[i] = G[u][i];
                    p[i] = u;
                }
            }
        }
    }
    int sum = 0;
    for(int i = 0; i < n; i++) {
        if(p[i] != UNDEFINED) {
            sum += G[i][p[i]];
        }
    }
    return sum;
}

int main() {
    std::cin >> n;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {

            std::cin >> a;
            G[i][j] = a;
        }
    }
    std::cout << prim() << std::endl;
    return 0;
}



Measured memory_bytes: 3148
//
// Created by Geoffrey West on 12/22/18.
//

#include <iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    int x;
    while (n--){
        cin >> x;
        if (x % 2 == 1)
        {
            cout << "first" << endl;
            return 0;
        }
    }
    cout << "second" << endl;
    return 0;

}

Measured memory_bytes: 256
import itertools

number = input()
answer = int(number)
length = len(number)

empty = [""] * length
plus = ["+"] * length

results = []
for i in range(2**(length - 1)):
    calc = ""
    for j in range(length - 1):
        calc += number[j]
        if i & 1:
            calc += "+"
        i >>= 1
    f = calc + number[-1]
    results.append(eval(f))
print(sum(results))


Measured memory_bytes: 3064
n,m=map(int,input().split())

li=[list(map(int,input().split())) for i in range(n)]
lj=[list(map(int,input().split())) for i in range(m)]

for i in range(n):
    li_distance=[abs(lj[j][0]-li[i][0])+abs(lj[j][1]-li[i][1]) for j in range(m)]
    print(li_distance.index(min(li_distance))+1)
    


Measured memory_bytes: 3060
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n;

main(){
	ios::sync_with_stdio(false);
	while(cin >> n){
		vector<vector<ll> > dp(2, vector<ll>(n+1));
		dp[0][0] = 1;
		REP(i, n){
			char c;
			cin >> c;
			dp[1&i^1] = vector<ll>(n+1);
			if(c == 'U'){
				REP(j, n){
					(dp[1&i^1][j+1] += dp[1&i][j]) %= MOD;
					(dp[1&i^1][j] += dp[1&i][j]*j) %= MOD;
				}
			}else if(c == 'D'){
				REP(j, n){
					(dp[1&i^1][j] += dp[1&i][j+1]*(j+1) % MOD*(j+1)) %= MOD;
					(dp[1&i^1][j+1] += dp[1&i][j+1]*(j+1)) %= MOD;
				}
			}else{
				dp[1&i^1] = dp[1&i];
			}
		}
		cout << dp[n&1][0] << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
using System;
using System.Linq;

namespace AtCoder_practice0801
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] KX = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int K = KX[0];
            int X = KX[1];

            if (500 * K >= X)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


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

using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  string a[n];
  for(int i=0;i<(int)(n);i++){
    cin >> a[i];
    if(a[i].length()!=m){
      i--;
      continue;
    }
  }
  sort(a,a+n);
  for(int i=0;i<(int)(n);i++) cout << a[i];
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int top = 0, S[1000];
void push(int x) {
  S[++top] = x;
}
int pop(void) {
  top--;
  return S[top+1];
}
int main(void) {
  int a, b;
  top = 0;
  char s[100];
  while(scanf("%s",s) != EOF) {
    if(s[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    } else if(s[0] == '-') {
      b = pop();
      a = pop();
      push(a - b);
    } else if(s[0] == '*') {
      a = pop();
      b = pop();
      push(a * b);
    } else {
      push(atoi(s));
    }
  }
  printf("%d\n",pop());
  return 0;
}


Measured memory_bytes: 2148
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
long long mod=(long long)1e09+7;
int inf=1<<30;
long long llinf=1ll<<60;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
long long llin(void){
    long long i;scanf("%lld",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a<b?a:b;
}
int cmp(const void *a,const void *b){
    return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
    return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}
long long gcd(long long x,long long y){
    return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
    return x/gcd(x,y)*y;
}

// write codes below this
// when you use 'sort',
// make sure TYPE macro is correct
typedef struct{
    int id,ac,time,wa[301];
}data;
int main(void){
    int M,T,P,R,i,m,t,p,j;
    data team[50],tmp;
    while(1){
        M=in();
        T=in();
        P=in();
        R=in();
        if(!M)break;
        MEMSET(team);
        rep(i,T)team[i].id=i+1;
        rep(i,R){
            m=in();
            t=in();
            p=in();
            j=in();
            t--;
            if(!j){
                team[t].ac++;
                team[t].time+=m+team[t].wa[p]*20;
            }
            else
                team[t].wa[p]++;
        }
        for(i=0;i<T-1;i++){
            for(j=T-1;j>i;j--){
                if(team[j-1].ac<team[j].ac
                ||team[j-1].ac==team[j].ac&&team[j-1].time>team[j].time
                ||team[j-1].ac==team[j].ac&&team[j-1].time==team[j].time&&team[j-1].id<team[j].id){
                    tmp=team[j-1];
                    team[j-1]=team[j];
                    team[j]=tmp;
                }
            }
        }
        rep(i,T){
            printf("%d%c",team[i].id,i==T-1?'\n':team[i].ac==team[i+1].ac&&team[i].time==team[i+1].time?'=':',');
        }
    }
    return 0;
}


Measured memory_bytes: 2128
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
//#define ARRAY(type,n) (type *)malloc(sizeof(type)*n)
template<typename T>
T* ARRAY(int n){
	(T*)malloc(sizeof(T)*n);
}
template<typename T>
T** ARRAY2(int m,int n){
	T** type = (T**)malloc(sizeof(T*)*m);
	for(int i=0;i<m;i++){
		type[i]=(T*)malloc(sizeof(T)*n);
	}
	return type;
}

int main(void){
	string w;
	cin>>w;
	int a[26];
	rep(i,26){
		a[i]=0;
	}
	rep(i,w.length()){
		a[w[i]-'a']++;
	}
	rep(i,26){
		if(a[i]%2!=0){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

import static java.lang.System.in;

public class Main {
    static long mod = 1000000000+7;
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt();
        int[] p = new int[n];
        for(int i=0;i<n;i++) p[i]=sc.nextInt();
        int left = 0, mid = 0, right = 0;
        for(int w:p){
            if(w<=a) left++;
            else if(w>=b+1) right++;
            else mid++;
        }
        int ans = Math.min(left,Math.min(mid,right));
        System.out.println(ans);
    }
}


Measured memory_bytes: 23764
#include<iostream>
using namespace std;
int main()
{
  int count;
char S[3];
  cin>>S;
  if(S[0]=='S'){
    if(S[1]=='S'){
      if(S[2]=='S') count=0;
      else count=1;
    }
    else{
      if(S[2]=='S') count=1;
      else count=2;
    }
  }
    else{
      if(S[1]=='S') count=1;
      else{
        if(S[2]=='S') count=2;
        else count=3;
      }
    }
  cout<<count<<endl;
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 2e7 + 9, M = 1e7, OO = 0x3f3f3f3f;
int main()
{
int n,a[1001];
cin>>n;
for(int i=0;i<n;i++){
    cin>>a[i];
}
sort(a, a+n);
cout<<a[n-1]-a[0];

    return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
ans = 0
for b in range(K+1,N+1):
    ans += (b-K)*(int(N//b))
    last = int(N//b)
    if b*last + K <= N:
        ans += N- (b*last+K) +1
    if K == 0:
        ans -= 1
print(ans)

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

long N;
vector<long> data(100000);

long sequenceCount(int seihu) {
  long sum = 0, count = 0;
  for(int i = 0; i < N; i++) {
    if(sum + data.at(i) >= 0 && seihu == 1) {
      count += abs(-1 - sum - data.at(i));
      sum = -1;
      seihu = 0;
      continue;
    } else if(seihu == 1 && sum + data.at(i) < 0) {
      sum += data.at(i);
      seihu = 0;
      continue;
    }
    if(sum + data.at(i) <= 0 && seihu == 0) {
      count += abs(1 - sum - data.at(i));
      sum = 1;
      seihu = 1;
      continue;
    } else if(seihu == 0 && sum + data.at(i) > 0) {
      sum += data.at(i);
      seihu = 1;
      continue;
    }
  }
    return count;
}

int main (){
  cin >> N;
  long ans = 0;
  for(int i = 0; i < N; i++) {
    cin >> data.at(i);
  }
  ans = min(sequenceCount(0), sequenceCount(1));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
p=print
r=range
def a(i,j,k,l=0):p("+<"[l],i,j,k)
def b(i):a(i,i,i)
def d(x):
	a(x,3,x)
	for t in r(30):b(x+4);a(x+4,3,6),*map(b,[6]*(29-t));a(6,x,T:=x*60+35+t,1);a(x+4,T,x+4)
p(6484)
a(0,1,3)
a(2,3,3,1)
d(0)
d(1)
for t in r(60):b(2);[(a(34+t-s,95+s,5),a(3,5,6,1),a(2,6,2))for s in r(t)]

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
const int MAXN = 20000001;
const int mod = 1e9 + 7;

int f[MAXN];

lint ipow(int x, int p){
	lint ret = 1, piv = x;
	while(p){
		if(p & 1) ret = ret * piv % mod;
		piv = piv * piv % mod;
		p >>= 1;
	}
	return ret;
}

int occupy(int l, int c){
	if(l >= 9) return (9ll * ipow(10, l - 1) - c + mod + 1) % mod;
	if(l <= 7) return 0;
	if(l == 8){
		int s = max(20000001, 10000000 + c - 1);
		int e = 99999999;
		return max(e - s + 1, 0);
	}
}

int occupiable(int l, int c){
	if(l >= 9) return true;
	if(l <= 7) return false;
	if(l == 8) return c > 10000001 && c <= 90000000;
}

int main(){
	for(auto &i : {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000}) f[i]++;
	for(int i=1; i<MAXN; i++) f[i] += f[i-1];
	int s; cin >> s;
	int ptr = 0, sum = 0;
	lint ret = 0;
	for(int i=1; i<MAXN; i++){
		sum += f[i];
		while(sum > s){
			sum -= f[++ptr];
		}
		if(sum == s) ret++;
	}
	for(int i=1; i<=s; i++){
		int lv = s / i, rv = s / i + 1;
		int lc = i - s % i, rc = s % i;
		if(rc == 0){
			ret += occupy(lv, lc);
		}
		else{
			ret += occupiable(rv, rc);
		}
	}
	cout << ret % mod << endl;
}


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

using namespace std;

#define sz(x) (int) x.size()
#define all(a) a.begin(), a.end()

const int MAXN = 5050;
const int mod = (int) 1e9 + 7;

long long binpow(long long x, long long p) {
    if (p < 0) return 0;
  long long res = 1;
  while (p) {
    if (p & 1) {
      res = (res * x) % mod;
      p--;
    } else {
      x = (x * x) % mod;
      p /= 2;
    }
  }
  return res % mod;
}

int n, k;
int p[MAXN];
vector<int> g[MAXN];

int compsNum;
bool hasUnset[MAXN];
int comps[MAXN];
bool used[MAXN];

int color[MAXN];
int cycles = 0;

void dfs(int v) {
    color[v] = 1;
    if (p[v] != -1) {
        int to = p[v];
        if (color[to] == 0) {
            dfs(to);
        } else if (color[to] == 1) {
            cycles++;
        }
    }
    color[v] = 2;
}

void dfs2(int v) {
    used[v] = true;
    comps[compsNum]++;
    if (p[v] == -1)
        hasUnset[compsNum] = true;
    for (int to : g[v]) 
        if (!used[to])
            dfs2(to);
}

long long f[MAXN];
long long dp[MAXN][MAXN];

int main() {

    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &p[i]);
        if (p[i] != -1) {
            p[i]--;
            g[i].push_back(p[i]);
            g[p[i]].push_back(i);
        } else {
            k++;
        }
    }

    for (int i = 0; i < n; i++)
        if (color[i] == 0) {
            dfs(i);
        }

    for (int i = 0; i < n; i++) 
        if (!used[i]) {
            dfs2(i);
            if (hasUnset[compsNum]) {
                // cerr << comps[compsNum] << " ";
                // if (comps[compsNum] == 1)
                    // cycles++;
                compsNum++;
            } else {
                comps[compsNum] = 0;
                hasUnset[compsNum] = false;
            }
        }
    // cerr << endl;

    for (int i = 0; i < compsNum; i++) {
        dp[i][0] = 1;
        if (i == 0) {
            dp[i][1] = comps[i] % mod;
            continue;
        }
        for (int j = 1; j <= i + 1; j++) {
            dp[i][j] = (dp[i - 1][j] + 1ll * dp[i - 1][j - 1] * comps[i] % mod) % mod;
        }
    }

    // cerr << "Cycles " << cycles << endl;

    long long ans = binpow(n - 1, k) * n % mod;
    ans = (ans - 1ll * cycles * binpow(n - 1, k) % mod + mod) % mod;

    f[0] = 1;
    for (int i = 1; i <= n; i++)
        f[i] = 1ll * f[i - 1] * i % mod;

    for (int i = 2; i <= compsNum; i++) { 
        long long rem = 1ll * f[i - 1] * dp[compsNum - 1][i] % mod;
        rem = rem * binpow(n - 1, k - i) % mod;
        // cerr << "rc " << i << " " << dp[compsNum - 1][i] << endl;
        ans = (ans - rem + mod) % mod;
    }

    // cerr << ans << endl;

    for (int i = 0; i < compsNum; i++) {
        long long rem = comps[i] - 1;
        rem = rem * binpow(n - 1, k - 1) % mod;
        // cerr << rem << endl;
        ans = (ans - rem + mod) % mod;   
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 120696
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    n,m = LI()
    s = S()
    t = S()
    def gcd(a, b):
        while b:
            a, b = b, a % b
        return a
    g = gcd(n, m)
    l = n * m // g
    n_ = n // g
    m_ = m // g
    for i in range(g):
        if s[n_ * i] != t[m_ * i]:
            print(-1)
            return
    print(l)
    return


#main
if __name__ == '__main__':
    solve()


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

ll n,w,W,V,val;

main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>W;
	vector<ll>wt(n);
	vector<ll>v(n);
	ll k[n+1][W+1];
	for(int i=0;i<n;i++)
		cin>>wt[i]>>v[i];
	
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=W;j++)
		{
			if(i==0 || j==0)
				k[i][j]=0;
			else if(wt[i-1]<=j)
				k[i][j]=max(v[i-1]+k[i-1][j-wt[i-1]],k[i-1][j]);
			else
				k[i][j]=k[i-1][j];
		}
	}
	cout<<k[n][W];
}

Measured memory_bytes: 79232
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cstring>

using namespace std;
using ll = long long;
using pint = pair<int, int>;

ll INF = 1LL << 60;

int main() {
	int N;
	cin >> N;
	string c;
	cin >> c;
	
	string s;
	s = c;
	sort(s.begin(), s.end());
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		if (s[i] != c[i]) cnt++;
	}
	int ans = (cnt + 1) / 2;
	cout << ans << endl;
	return 0;
}

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

#define MAX 2000001
#define VMAX 10000

int C[VMAX];

void CountingSort(int A[],int B[],int n,int k){
  for(int i=0;i<k;i++){
    C[i]=0;
  }
  for(int i=0;i<n;i++){
    C[A[i]]++;
  }
  for(int i=0;i<k;i++){
    C[i]+=C[i-1];
  }
  for(int i=n-1;i>=0;i--){
    B[C[A[i]]-1] = A[i];
    C[A[i]]--;
  }
}

int main(){
  int A[MAX],B[MAX];
  int n,mx=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>A[i];
    mx=max(mx,A[i]);
  }
  CountingSort(A,B,n,VMAX+1);
  for(int i=0;i<n;i++){
    if(i) cout<<" "<<B[i];
    else cout<<B[i];
  }
  cout<<endl;
  return 0;
}
  



Measured memory_bytes: 18704
import java.awt.Point;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	static Queue<int[]> que = new ArrayDeque<>();
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		Point[] city = new Point[n];
		Arrays.setAll(city, i -> new Point(sc.nextInt(), sc.nextInt()));
		
		permutation(n);
		
		int cnt = 0;
		double sum = 0;
		while (!que.isEmpty()) {
			cnt++;
			int[] idx = que.poll();
			double dis = 0;
			
			for (int i = 0; i < n - 1; i++) {
				dis += city[idx[i]].distance(city[idx[i + 1]]);
			}
			
			sum += dis;
		}
		
		double ans = sum / cnt;
		System.out.println(ans);
		
		sc.close();
	}
	
	static void permutation(int n) {
		int[] perm = new int[n];
		boolean[] used = new boolean[n];
		buildPerm(getSeed(n), perm, used, 0);
	}
	
	static int[] getSeed(int n) {
		int[] reArr = new int[n];
		for (int i = 0; i < n; i++) reArr[i] = i;
		return reArr;
	}
	
	static void buildPerm(int[] seed, int[] perm, boolean[] used, int idx) {
		if (idx == seed.length) {
			que.add(Arrays.copyOf(perm, seed.length));
			return;
		}
		
		for (int i = 0; i < seed.length; i++) {
			if (used[i]) continue;
			perm[idx] = seed[i];
			used[i] = true;
			buildPerm(seed, perm, used, idx + 1);
			used[i] = false;
		}
	}
	
}



Measured memory_bytes: 34904
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t x,k,d;
  cin>>x>>k>>d;
  if(abs(x)/d>=k)
    cout<<abs(x)-d*k<<endl;
  else
    cout<<abs(abs(x)%d-((abs(x)/d)%2==k%2?0:d))<<endl;
    
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);	
	int a,b,c,d;
    cin>>a>>b>>c>>d;
    int begin = max(a,c);
    int end = min(b,d);
    cout<<max(0,end-begin);
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)
#define RREP(i, n) for(int i = (n)-1; i >= 0; --i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define PI 3.1415926
#define coutdb cout<<fixed<<setprecision(15)

const int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;

// typedef int_fast64_t ll;
#define int int_fast64_t

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

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

  int N, A[15], x[15][15], y[15][15]; cin >> N;
  REP(i, N){
  	cin >> A[i];
  	REP(j, A[i]){
      cin >> x[i][j] >> y[i][j];
      x[i][j]--;
    }
  }
  int ans = 0;
  REP(bit, (1<<N)){
  	int cnt = __builtin_popcount(bit);
    bool yes = 1;
  	REP(i, N){
  		if((bit>>i) & 1){
        REP(j, A[i]){
          if(y[i][j]==1 and (bit>>(x[i][j]) & 1)==0) yes &= 0;
          if(!y[i][j] and (bit>>(x[i][j]) & 1)==1) yes &= 0;
        }
      }
  	}
    if(yes) chmax(ans, cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n=int(input())
#n,m=map(int,input().split())
al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

al.sort()
ans="YES"
for i in range(1,n):
    if al[i]==al[i-1]:
        ans="NO"
        break
print(ans)


Measured memory_bytes: 26808
N = int(input())
A_list = list(map(int, input().split()))
B_list = list(map(int, input().split()))
answer_list = [0]*N

for i in range(N):
    temp = B_list[i]

    for j in range(i, i+2):
        if temp - A_list[j] <= 0:
            answer_list[i] += temp
            A_list[j] -= temp
            break
        else:
            answer_list[i] += A_list[j]
            temp -= A_list[j]
            A_list[j] -= A_list[j]

print(sum(answer_list))


Measured memory_bytes: 19116
/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1;
const double eps = 1e-6, ldeps = 1e-9;
struct Dbg {
static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto dud(C *x)->decltype(os << *x, 0);
template<class C> static char dud(...);
template<class C> typename enable_if<sizeof dud<C>(0)!=1, Dbg&>::type operator<<(const C &x) { os << x; return *this; }
template<class C> Dbg &dump(C b, C e) {
    *this << "\n[";
    int cur = 0;
    for (C i = b; i!=e and cur<26; i++, cur++) *this << ", "+2*(i==b) << *i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof dud<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<sizeof(C)!=1, Dbg&>::type operator <<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator <<(const pair<B, C> &x) {
    return *this << '{' << x.first << ", " << x.second << '}';
}
template<class C, size_t Y> struct TP {
    void operator()(Dbg& os, const C &t) { TP<C, Y-1>()(os, t); os << ", " << get<Y-1>(t); }
};
template<class C> struct TP<C, 1> { void operator()(Dbg& os, const C &t) { os << get<0>(t); } };
template<class... C> Dbg& operator<<(const tuple<C...> &t) {
    os << '{', TP<decltype(t), sizeof...(C)>()(*this, t); return *this << '}';
}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args ...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(string(#args)), args), dbg << endl
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxn = 100005;

char s[2][mxn];
int cb[2][mxn];

signed main() { ios::sync_with_stdio(0); cin.tie(NULL); cout.precision(11);
/*
aaa can be bbb, a can be aaaa, aaaa can be a. If we make convert all b to aa, maybe it's just about checking if the difference
of number of a is divisible by 3 or not.
*/
    for (int i = 0; i < 2; i++) {
        cin >> s[i];
        int n = sl(s[i]);
        for (int j = 0; j < n; j++) {
            cb[i][j+1] = cb[i][j]+(s[i][j]=='B');
        }
    }

    cin >> Q;
    while (Q--) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int cb0 = cb[0][b]-cb[0][a-1], cb1 = cb[1][d]-cb[1][c-1];
        int ca0 = (b-a+1)+cb0, ca1 = (d-c+1)+cb1;
        cout << ((ca0-ca1)%3 ? "NO\n" : "YES\n");
    }
}

Measured memory_bytes: 1536
import Control.Applicative
import Control.Monad
import Control.Monad.IO.Class
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Text.Printf
import Debug.Trace
import Data.Array.IArray
import Data.Array.IO
     
getInts :: IO [Int]
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine
     
inf = 1000000000
     
main = do
  [n,m] <- getInts
  dt <- newArray ((1,1),(n,n)) inf :: IO (IOArray (Int,Int) Int)
  es <- replicateM m getInts
  forM_ es $ \[a,b,c] -> do
    writeArray dt (a,b) c
    writeArray dt (b,a) c
  forM_ [1..n] $ \k ->
    forM_ [1..n] $ \i ->
      forM_ [1..n] $ \j -> do
        a <- readArray dt (i,k)
        b <- readArray dt (k,j)
        pv <- readArray dt (i,j)
        writeArray dt (i,j) (min pv (a+b))
  arr <- (flip filterM) es $ \[a,b,c] -> do
    v <- readArray dt (a,b)
    return $ v /= c
  print $ length arr


Measured memory_bytes: 78204
#include <iostream>

using namespace std;

int main()
{ int a,b,c,d,A,B,C,D;
cin>>a>>b>>c>>d;
cin>>A>>B>>C>>D;
if(a+b+c+d>=A+B+C+D){cout<<a+b+c+d<<"\n";}
else{cout<<A+B+C+D<<"\n";}
 return 0;
}

Measured memory_bytes: 1164
n = int(input())
d = sorted([int(i) for i in input().split()])
idx_p = int(len(d) / 2) - 1
idx_a = int(len(d) / 2)
if d[idx_p] != d[idx_a]:
	print (d[idx_a] - d[idx_p])
else:
	print (0)

Measured memory_bytes: 14396
#include "iostream"
#include "algorithm"
#include "vector"
#include "map"


typedef long long llint;

using namespace std;

// llint p[200000];
llint n;

int main() {
    cin >> n;
    vector <int> p(n + 1);
    vector <int> q(n + 1);

    for (int i = 1; i <= n; i++) {
        cin >> p[i];
        q[p[i]] = i;
    }

    int m = 0;
    int tmp = 1;
    for (int i = 1; i <= n; i++) {
        if (i == n) {
            m = max(m, tmp);
            break;
            // cout << "update:" << i << endl;
        }

        if (q[i] < q[i + 1]) {
            tmp++;
            // cout << "cnt_up:" << i << endl;
         } else {
            m = max(m, tmp);
            tmp = 1;
            // cout << "update:" << i << endl;
        }
    }

    cout << n - m << endl;
}


Measured memory_bytes: 1920
n=int(input())
P=list(map(int,input().split()))

M=[0]*n
M[0]=P[0]

for i in range(n-1):
  M[i+1]=min(M[i],P[i+1])

ans=0
for i in range(n):
  ans+=P[i]==M[i]

print(ans)

Measured memory_bytes: 75472
#include <stdio.h>
#include <iostream>

using namespace std;

#define SIZE 500

#define SIZE2 (200000 / SIZE + 10)

#define SIKI (SIZE * 3)

class point
{
public:
	int n;
	int d[SIKI + 1];
	int minw;
};

point m[SIZE2];

int p[200000];

int N;

void atu()
{
	int now = 0;
	for(int i = 0; i < SIZE2; i++)
	{
		for(int ii = 0; ii < m[i].n; ii++)
		{
			p[now] = m[i].d[ii];
			now++;
		}
	}
}

int getm(int x,int a,int b)
{
	int w = 2000000000;
	for(int i = a; i <= b; i++)
	{
		w = min(w,m[x].d[i]);
	}
	return w;
}

void bun()
{
	for(int i = 0; i < SIZE2; i++)
	{
		m[i].n = 0;
	}
	int now = 0;
	for(int i = 0; i < SIZE2; i++)
	{
		for(int ii = 0; ii < SIZE; ii++)
		{
			if(now >= N)
			{
				m[i].n = ii;
				goto aa;
			}
			m[i].d[ii] = p[now];
			now++;
			m[i].n++;
		}
	}
aa:
	for(int i = 0; i < SIZE2; i++)
	{
		m[i].minw = getm(i,0,m[i].n - 1);
	}
}

pair<int,int> findw(int a)
{
	int now = 0;
	for(int i = 0; i < SIZE2; i++)
	{
		if(now + m[i].n > a)
		{
			return make_pair(i,a - now);
		}
		now += m[i].n;
	}
}

void insert(int a,int x)
{
	pair<int,int> w = findw(a);
	for(int i = m[w.first].n; i > w.second; i--)
	{
		m[w.first].d[i] = m[w.first].d[i - 1];
	}
	m[w.first].d[w.second] = x;
	m[w.first].n++;
	if(m[w.first].n > SIKI + 1)
	{
		atu();
		bun();
	}
	else
	{
		m[w.first].minw = getm(w.first,0,m[w.first].n - 1);
	}
}

int erase(int a)
{
	pair<int,int> ww = findw(a);
	int w = m[ww.first].d[ww.second];
	for(int i = ww.second; i < m[ww.first].n - 1; i++)
	{
		m[ww.first].d[i] = m[ww.first].d[i + 1];
	}
	m[ww.first].n--;
	m[ww.first].minw = getm(ww.first,0,m[ww.first].n - 1);
	return w;
}

void shift(int a,int b)
{
	int w = erase(b);
	insert(a,w);
}

int minw(int a,int b)
{
	pair<int,int> aw = findw(a);
	pair<int,int> bw = findw(b);
	int w;
	if(aw.first == bw.first)
	{
		w = getm(aw.first,aw.second,bw.second);
	}
	else
	{
		w = min(getm(aw.first,aw.second,m[aw.first].n - 1),getm(bw.first,0,bw.second));
		for(int i = aw.first + 1; i < bw.first; i++)
		{
			w = min(w,m[i].minw);
		}
	}
	return w;
}

void oki(int a,int x)
{
	pair<int,int> w = findw(a);
	m[w.first].d[w.second] = x;
	m[w.first].minw = getm(w.first,0,m[w.first].n - 1);
}

int main()
{
	int q;
	scanf("%d%d",&N,&q);
	for(int i = 0; i < N; i++)
	{
		int w;
		scanf("%d",&w);
		p[i] = w;
	}
	bun();
	for(int i = 0; i < q; i++)
	{
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		if(a == 0)
		{
			shift(b,c);
		}
		else if(a == 1)
		{
			printf("%d\n",minw(b,c));
		}
		else
		{
			oki(b,c);
		}
	}
	return 0;
}

Measured memory_bytes: 4356
#include<cstdio>
using namespace std;
int n,ans;char a[105],b[105];
int main(){
	scanf("%d%s%s",&n,a+1,b+1);
	for (int i=1;i<=n;i++)
	for (int j=n-i+1,k=1;j<=n;j++,k++)
	if(a[j]^b[k]) break;else if(j==n) ans=i;
	printf("%d\n",2*n-ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int a,b;
int main()
{
    cin>>a>>b;
    if((a>=0&&b<=0)||(a<=0&&b>=0)) {cout<<"Zero"<<endl;return 0;}
    if(a>b) swap(a,b);
    long long ans = 0;
    for(int i =a;i<=b;i++) if(i<0) ans++;
    if(ans%2 == 0) cout<<"Positive";
    else cout<<"Negative";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n;
	cin >> n;
	
	vector<string> s(n);
	set<string> st;
	for(int i = 0; i < n; ++i) {
		cin >> s[i];
		st.insert(s[i]);
	}
	
	if( st.size() != n ) {
		cout << "No" << endl;
		return 0;
	}
	
	for(int i = 0; i < n - 1; ++i) {
		if( s[i].back() != s[i + 1].front() ) {
			cout << "No" << endl;
			return 0;
		}
	}
	
	cout << "Yes" << endl;
	
	return 0;
}


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

using namespace std;

#define ll long long 

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

	int n = s.length();

	int l = 0;
	int r = 0;

	while (s[l] == 'R')
	{
		l++;
	}

	vector<int> ans(n);
	for (int i = 0; i < n; i++)
	{
		if (s[i] == 'R')
		{
			while (s[l] == 'R' || l < i)
			{
				l++;
			}

			r = i;
			ll dis = l - i;

			if (dis % 2 == 0)
			{
				ans[l]++;
			}
			else
			{
				ans[l - 1]++;
			}
		}
		else
		{
			ll dis = i - r;
			if (dis % 2 == 0)
			{
				ans[r]++;
			}
			else
			{
				ans[r + 1]++;
			}
		}
	}

	for (int i = 0; i < n; i++)
	{
		cout << ans[i] << " ";
	}

	cout << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};

struct UnionFind {
    //自身が親であれば，その集合に属する頂点数に-1を掛けたもの
    //そうでなければ親のid
    vector<int> r;

    UnionFind(int n) {
        r = vector<int>(n, -1);
    }

    int root(int x) { //木の根を調べる（どのグループに属しているか）
        if (r[x] < 0) return x;
        return r[x] = root(r[x]);
    }

    bool unite(int x, int y) { //xとyの属する集合を併合
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (r[x] > r[y]) swap(x, y);
        r[x] += r[y];
        r[y] = x;
        return true;
    }

    int size(int x) { //xが属する集合の頂点数を調べる
        return -r[root(x)];
    }

    bool same(int x, int y) { //xとyが同じ集合に属するか否か
        return root(x) == root(y);
    }
};

int main() {
    int n,m; cin >> n >> m;
    int ans = 0;
    vector<int> a(m),b(m);
    rep(i,m) {
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }

    rep(i,m) { //i番目の辺を消す
        UnionFind UF(n);
        rep(j,m) {
            if (j==i) continue;
            UF.unite(a[j],b[j]);
        }
        rep(j,n-1) {
            if (!UF.same(0,j+1)) {
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i, n) for (int i = 0; i < int(n); i++)
#define FOR1(i, m, n) for (int i = int(m); i < int(n); i++)
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))

int main(int argc, char *argv[])
{
  int n;
  vector<uint32_t> a;

  cin >> n;

  FOR(i, n) {
    uint32_t tmp;
    cin >> tmp;
    a.push_back(tmp);
  }

  for (int i = n-1; i >= 0; i -= 2) {
    cout << a[i] << " ";
  }

  for (int i = n % 2; i < n; i += 2) {
    cout << a[i] << " ";
  }

  cout << endl;
  
  return 0;
}


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class ABC_A
    {
        static void Main(string[] args)
        {
            string[] rawinput = Console.ReadLine().Split();

            int[] input = rawinput.Select(int.Parse).ToArray();
            int inputMAX = input.Max();
            int inputMin = input.Min();

            Console.WriteLine(inputMAX - inputMin);
        }
    }
}


Measured memory_bytes: 11348
N = int(input())
A = list(map(int, input().split())) + [-1] + [-1]

money = 1000
stock = 0
buy_turn = True
ans = 0

for i, a in enumerate(A[:N]):
    ans = max(ans, money)
    if buy_turn:
        if A[i + 1] < A[i]:
            continue
        buy_turn = False
        stock += money // A[i]
        money = money % A[i]

    else:
        if A[i + 1] > A[i]:
            continue
        buy_turn = True
        money += A[i] * stock
        stock = 0
    ans = max(ans, money)

print(ans)


Measured memory_bytes: 9208
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
typedef long long int ll;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<double> vecd;
typedef vector<string> vecstr;
typedef vector<char> vecchar;
typedef vector<bool> vecbool;
typedef vector<vector<bool>> vec2bool;
typedef vector<vector<int>> vec2int;
typedef vector<vector<double>> vec2d;
typedef pair<int, int> P;
////////////////////////////////////////////////
void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
////////////////////////////////////////////////
struct edge {
  int to;
  int dist;
};
////////////////////////////////////////////////
int main() {
  init();
  int n, m;
  cin >> n >> m;
  vector<vector<edge>> G(n);
  REP(i, m) {
    int l, r, d;
    cin >> l >> r >> d;
    l--;
    r--;
    G[l].push_back(edge{r, d});
    G[r].push_back(edge{l, -d});
  }
  vecbool seen(n, false);
  vecint pos(n, 0);
  bool ok = true;
  REP(i, n) {
    if (seen[i]) continue;
    queue<int> q;
    q.push(i);
    while (!q.empty() && ok) {
      int now = q.front();
      q.pop();
      seen[now] = true;
      for (auto& e : G[now]) {
        int test = pos[now] + e.dist;
        if (seen[e.to]) {
          if (test != pos[e.to]) {
            ok = false;
            break;
          }
        } else {
          pos[e.to] = test;
          q.push(e.to);
          seen[e.to] = true;
        }
      }
    }
    if (!ok) {
      break;
    }
  }
  if (ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 9420
#include<stdio.h>
#include<stdlib.h>
int compare_int(const void *a,const void *b)
{
return *(int*)a - *(int*)b;
}
int main()
{
int N,K,i,ans=0;
int p[1000];
scanf("%d %d \n",&N,&K);
for(i=0;i<N;i++){
scanf("%d ",&p[i]);
}
qsort(p,N,sizeof(int),compare_int);
for(i=0;i<K;i++){
ans+=p[i];
}
printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 1740
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define ull unsigned long long
#define pii pair<int,int>
#define pb(x) push_back(x)
#define inf 0x3f3f3f3f
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define drep(i,a,b) for(int i=(a); i>=(b);i--)
 
const int maxn = 1e5 + 5;
const int maxm = 5000 + 5;
const int MOD = 998244353;
const int N = 1005;



int main()
{
   ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
  // #ifndef ONLINE_JUDGE 
   //freopen("input.txt", "r", stdin);
   //#endif // ONLINE_JUDGE 
  int m,d;
  cin >> m >> d;
  int ans = 0;
  rep(i,1,m) {
      rep(j,22,d){
          int t = j / 10;
          int tt = j % 10;
          if(tt < 2 || t < 2) continue;
          if(t * tt == i) {
              ans++;
              //cout << t << " " << tt << endl;
            }
      }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
/**************************************************************************
Coded by: Saba Karimi(_VINTAGE)
Institution: AIT PUNE
***************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
/**************************************************************************/
signed main()
{
   fast;
   int m,d;
   cin>>m>>d;
   int ans = 0;
   for(int i=1;i<=m;i++)
   {
        for(int j=1;j<=d;j++)
        {
            int d1 = j%10;
            int gh = j/10;
            int d2 = gh%10;
            if(d1>=2 && d2>=2 && (d1*d2)==i)
                ans++;
        }
   }
   cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
ostream& operator<<(ostream &out, string str) {
	for(char c : str) out << c;
	return out;
}
 
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
	return out << "(" << p.first << ", " << p.second << ")";
}
 
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
	out << "{";
	for(auto it = a.begin(); it != a.end(); it = next(it))
		out << (it != a.begin() ? ", " : "") << *it;
	return out << "}";
}
 
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
	cerr << a << ", ";
	dump(x...);
}
 
#ifdef DEBUG
#  define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#  define debug(...) false
#endif
 
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
 
template<class T> int size(T && a) { return a.size(); }
 
using LL = long long;
using PII = pair<int, int>;
 
mt19937 _gen(chrono::system_clock::now().time_since_epoch().count());
int rd(int a, int b) {
	return uniform_int_distribution<int>(a, b)(_gen);
}
 
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;

	vector<LL> a(n);
	LL tot_xor = 0;
	REP(i, n)  {
		cin >> a[i];
		tot_xor ^= a[i];
	}

	vector<int> cnt(60);
	for(int i = 60 - 1; i >= 0; i--) {
		for(LL x : a) if(x & (1LL << i))
			cnt[i] ^= 1;
	}

	LL index = 0;
	LL r = 0;
    for(int i = 60 - 1; i >= 0; i--) {
		if(cnt[i]) continue;
        LL maxInd = index; 
        LL maxEle = -1e18;
        for(int j = index; j < n; j++)  {
            if((a[j] & (1LL << i)) != 0 && a[j] > maxEle)
                maxEle = a[j], maxInd = j; 
        } 
  
        if(maxEle == (LL) -1e18)
        	continue; 
		r += (1LL << i);
  
        swap(a[index], a[maxInd]); 
        maxInd = index; 
  
        for(int j = 0; j < n; j++) {
            if (j != maxInd && (a[j] & (1LL << i)) != 0) 
				a[j] = a[j] ^ a[maxInd];
        } 
  
        index++; 
    } 

	debug(a);
  
    LL res = 0; 
    for (int i = 0; i < n; i++) 
        res ^= a[i]; 

	debug(res, r);

	cout << (res + (tot_xor ^ res)) << "\n";
}


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


int main(){
  int N,L;
  cin>>N>>L;
  vector<string> S(N);
  for(int i = 0;i<N;i++){
    cin>>S.at(i);
  }
  sort(S.begin(),S.end());
  for(int i = 0;i<N;i++){
    cout<<S.at(i);
  }


  //cout<<ans<<endl;

}


Measured memory_bytes: 256
# Palindrome-philia

# input
S = input()

# solve
if len(S) % 2 != 0:
    S = S[:len(S)//2] + S[len(S)//2 + 1:]

res = sum([i != j for i, j in zip(S[:len(S)//2], S[len(S)//2:][-1::-1])])

# output
print(res)

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int N;
	long long ans = 0;
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) {
		if (i % 3 && i % 5) ans += i;
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 1732
N = int(input())
A = []
for i in range(1,N+1):
    S,P = input().split()
    P = int(P)
    A.append((S,P,i))
A = sorted(A,key=lambda x:x[1],reverse=True)
A = sorted(A,key=lambda x:x[0])
for x in A:
    print(x[2])

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (3e9)

using namespace std;
typedef long long int ll;

template<typename T>
T gcd(T x, T y){
    if (y == 0) return x;
    else return gcd(y, x % y);
}
template<typename T>
T lcm(T x, T y){
    return (x / gcd(x, y)) * y;
}

ll A, B;
int main(void){
    cin >> A >> B;
    cout << lcm(A, B) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <set>
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>

using namespace std;

multiset <string> s;

int main()
{
	int X,Y,Z;
	scanf("%d%d%d",&X,&Y,&Z);
	for(int i = 1;i <= X; ++ i)
		s.insert("a");
	for(int i = 1;i <= Y; ++ i)
		s.insert("b");
	for(int i = 1;i <= Z; ++ i)
		s.insert("c");
	multiset <string>::iterator it;
	it = s.end();
	it--;
	while(s.size() > 1)
	{
		it = s.begin();
		string a = *it;
		s.erase(it);
		it = s.end();
		it--;
		string b = *it;
		s.erase(it);
		string c = a + b;
		s.insert(c);
	}
	cout<<*s.begin()<<endl;
 } 

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

int main(){
	ll n;
  cin>>n;
  ll def = 100;
  ll cnt = 0;
  while(1){
  	if(def>=n){
    	break;
    }
    def+= def/100;
    cnt++;
  }
  cout<<cnt;
}

Measured memory_bytes: 3496