akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;
typedef long long ll;

int main(){
  int n, m;
  int a[60], b[60], c[60], d[60];
  int k[60], l, h;

  cin>>n>>m;
  for(int i=0; i<n; ++i){
    cin>>a[i]>>b[i];
  }
  for(int j=0; j<m; ++j){
    cin>>c[j]>>d[j];
  }
  for(int i=0; i<n; ++i){
    for(int j=0; j<m; ++j){
      k[j] = abs(a[i]-c[j]) + abs(b[i]-d[j]);
      if(j==0){
        h = k[j];
        l = j;
      }else{
        if(k[j]<h){
          h = k[j];
          l = j;
        }
      }
    }
    cout<<l+1<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
#define INF 99999999
typedef std::pair<int,int> pii;

int main(){
    int N;
    std::cin >> N;
    std::vector<int> a(N), b(N), c(N);
    for (int i = 0; i < N; i++) {
        std::cin >> a[i];
    }
    for (int i = 0; i < N; i++) {
        std::cin >> b[i];
    }
    for (int i = 0; i < N; i++) {
        std::cin >> c[i];
    }
    std::sort(a.begin(), a.end());
    std::sort(b.begin(), b.end());
    std::sort(c.begin(), c.end());
    long long ans = 0,x,y;
    decltype(b)::iterator it1,it2;
    for (int i = 0; i < N; i++) {
        int cur_b = b[i];
        it1 = std::upper_bound(c.begin(), c.end(), cur_b);
        it2 = std::lower_bound(a.begin(), a.end(), cur_b);
        x = N - (it1 - c.begin());
        y= (it2 - a.begin());
        ans += x * y;
    }
    std::cout << ans << std::endl;
    return 0;
}

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

def main():
    n = int(input())
    x_list = list(map(int, input().split()))
    x_min = min(x_list)
    x_max = max(x_list)
    p_list = list()

    for i in range(x_min, x_max + 1):
        power = sum(map(lambda x: pow(x - i, 2), x_list))
        p_list.append(power)
    
    print(min(p_list))

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int N;
	cin >> N;

	int A[200000];
	rep(i, N) cin >> A[i];

	int kei = 0;
	rep(i, N) {
		kei ^= A[i];
	}
	ce(kei);
	rep(i, N) {
		co(kei ^ A[i]);
	}




	Would you please return 0;
}

Measured memory_bytes: 4344
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>

using namespace std;
typedef long long ll;
ll N;

int main(){

    ll N = 0;
    cin >> N;
    vector<ll > A(N);

    vector<ll > even;

    //偶数だけ取り出す
    for(ll i = 0; i < N; i++){
        cin >> A[i];
        if(A[i] % 2 == 0){
            even.push_back(A[i]);
        }
    }

    
    sort(even.begin(), even.end());

    if(even.size() == 0){
        cout << "0" << endl;
        return 0;
    }

    ll ans = 0;
    ll three_count = 0;
    for(ll i = 0; i < even.size(); i++){
        ll cn = 0;
        //cout << max( 3 * three_count, (ll)1) * even[i]<< endl;
        for(ll j = even[i]; j > 0; j /= 2){
            
            if(j % 2 == 1){
                break;
            }

            cn++;
            
        }
        
        ans += cn; 
        
        //cout << even[i] << " " <<  ans << " " << cn << endl;
        //cout << three_count << endl;
    }

    cout << ans << endl;
    /* 
    ll cn = 0;
    for(ll i = 1000000000; i > 0; i /= 2){
        cn++;
    }
    cout << cn << endl;
    */
}

Measured memory_bytes: 512
def is_prime(n):
    n = abs(n)
    if n == 2:
        return True
    if n < 2 or n % 2 == 0:
        return False
    return pow(2, n - 1, n) == 1

cnt = 0
for i in range(int(input())):
    if is_prime(int(input())):
        cnt += 1
print(cnt)


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

int main(){
  int h,w;
  cin>>h>>w;
  vector<string> s(h);
  for(int i=0;i<h;i++)cin>>s[i];
  bool f=true;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#'){
        int p=0;
        if(i-1>=0&&s[i-1][j]=='#')p++;
        if(j-1>=0&&s[i][j-1]=='#')p++;
        if(i+1<h&&s[i+1][j]=='#')p++;
        if(j+1<w&&s[i][j+1]=='#')p++;
        if(p==0)f=false;
      }
    }
  }
  if(f){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}


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

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define FOR(i,a,n) for(int i=a;i<n;i++)

typedef long long ll;
typedef pair<int, int> ii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fll;


ll dp[105][100005];
int n, w;
vector<pair<ll, ll>> v;

ll solve(int pos, int peso) {
	if(peso < 0) return -LINF;
	if(pos >= n or peso == 0) return 0;
	if(dp[pos][peso] != -1) return dp[pos][peso];

	return dp[pos][peso] = max(v[pos].s + solve(pos+1, peso-v[pos].f), solve(pos+1, peso));
}


int main() { _
	cin >> n >> w;
	v.resize(n);

	FOR(i,0,n) cin >> v[i].f >> v[i].s;
	memset(dp, -1, sizeof(dp));
/*
	vector<vector<ll>> dp(n+5, vector<ll>(w+5, 0));
	for(ll i = n-1; i >= 0; i--) {
		for(ll j = 0; j <= w; j++) {
			if(j < v[i].f) dp[i][j] == dp[i+1][j];
			else dp[i][j] = max(v[i].s + dp[i+1][j-v[i].f], dp[i+1][j]);
		}
	}
*/
	//cout << dp[0][w] << endl;
	cout << solve(0, w) << endl;
	return 0;
}



Measured memory_bytes: 85676
#########行列読み込み ##############################################
"""
from sys import stdin
n = int(stdin.readline().rstrip())
data = [stdin.readline().rstrip().split() for _ in range(n)]
print(data)
print(*data, sep='\n')
"""
##################################################################
#########入力系####################################################
"""
s =input()
s=list(input())
a=int(input())
x,y = map(int,input().split())	
li = input().split()	
li = list(map(int,input().split()))	
li = input().split('T')	
"""
##################################################################

K = int(input())
S=list(input())

if len(S)<=K:
    for i in S:
        print(i,end="")
else:
    S_ = []
    S_ = S[0:K]
    S_.append("...")
    #print(S_)
    for j in S_:
        print(j,end ="")


    





Measured memory_bytes: 61940
/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/
/*-------------------------------@greenindia-----------------------------------*/
//
//		  _____       _           _        _
//		 / ____|     | |         (_)      | |
//		| (___   __ _| |__  _   _ _       | | __ _ _ __   __ _
//		 \___ \ / _` | '_ \| | | | |  _   | |/ _` | '_ \ / _` |
//		 ____) | (_| | |_) | |_| | | | |__| | (_| | | | | (_| |
//		|_____/ \__,_|_.__/ \__,_| |  \____/ \__,_|_| |_|\__,_|
//		                        _/ |
//		                       |__/
/*---------------------- Magic. Do not touch.-----------------------------*/
/*------------------------------God is Great/\---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl;
#define int long long int
#define double long double
#define PI acos(-1)

void print1d(const vector<int>& vec) {for (auto val : vec) {cout << val << " ";} cout << endl;}

void print2d(const vector<vector<int>>& vec) {for (auto row : vec) {for (auto val : row) {cout << val << " ";} cout << endl;}}

signed main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("error.txt", "w", stderr);
// #endif
	crap;

	int n,m;
	cin>>n>>m;

	cout << n*(n-1)/2 + m*(m-1)/2 << endl;

	return 0;
}






Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#pragma region defins
#define ll long long
#define loop(i,n) for (int i = 0; i < n; i++)
#define loops(i,f,n) for (int i = (f); i < n; i++)
#define INF 100000000000000
#define sort(a) sort(a.begin(),a.end())
#define rsort(a) sort(a.rbegin(),a.rend())
using namespace std;
#pragma endregion
int n, s, ans;
void dfs(int num, int sum, int count)
{
    //cout << "num:" << num << " sum:" << sum << " count:" << count << endl;
    if (sum == s&&count == n)
    {
        ans++;
        //cout << "ans: " << ans << endl;
    }
    if (sum > s || num == 10 || count == n)return;
    dfs(num + 1, sum + num, count + 1);
    dfs(num + 1, sum, count);
}
 
int main()
{
    while (1)
    {
        cin >> n >> s;
        if (n == 0 && s == 0)break;
        else
        {
            ans = 0;
            dfs(0, 0, 0);
            cout << ans << endl;
        }
    }
}


Measured memory_bytes: 2988
li = [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]
s = int(input())

print(li[s-1])

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;

int main() {
	int n;
	cin >> n;
	
	vector<int>b(n - 1);
	for (int i = 0; i < n - 1; i++)cin>>b[i];
	vector<int>a(n);
	
	for (int i = 1; i <n-1; i++)a[i] = min(b[i - 1], b[i]);
	a[0] = b[0];
	a[n - 1] = b[n - 2];

	int t = 0;
	for (int i = 0; i < n; i++) { t += a[i]; //cout << a[i] << " ";
}
	cout << t << endl;
	return 0;


}

Measured memory_bytes: 256
import heapq


def solve(string):
    n, m, *ab = map(int, string.split())
    ab = sorted([(a, b) for a, b in zip(*[iter(ab)] * 2)])
    hq, index, cap, count, ans = [], 0, 1, m, 0
    while index < n:
        _a, _b = ab[index]
        if _a > m:
            break
        if _a <= cap:
            heapq.heappush(hq, -_b)
            index += 1
        else:
            ans += -heapq.heappop(hq) if len(hq) > 0 else 0
            count -= 1
            cap += 1
    ans += sum([-heapq.heappop(hq) for _ in range(count) if len(hq) > 0])
    return str(ans)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))


Measured memory_bytes: 25580
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>

using namespace std;

#define int long long
#define ll long long
#define double long double
#define pii pair<int, int>
#define vec vector
#define u_map unordered_map
#define u_set unordered_set
#define str string
#define all(el) el.begin(), el.end()
#define allr(el) el.rbegin(), el.rend()
#define sz(el) (int)el.size()
#define f first
#define s second
#define pb push_back
#define in insert
#define mp make_pair
#define endl "\n"
#define forn(i, n) for (int i = 0; i < n; ++i)

inline int maxi(int &a, int b) { if (b > a) { a = b; return 1; } return 0; }

inline int mini(int &a, int b) { if (b < a) { a = b; return 1; } return 0; }

inline int maxi(double &a, double b) { if (b > a) { a = b; return 1; } return 0; }

inline int mini(double &a, double b) { if (b < a) { a = b; return 1; } return 0; }

int bin_pow(int x, int p) {
    if (p < 0) {
        return 0;
    }
    if (p == 0) {
        return 1;
    }
    if (p % 2 == 0) {
        int ans = bin_pow(x, p / 2);
        return ans * ans;
    }
    return x * bin_pow(x, p - 1);
}

int gcd(int a, int b) {
    if (!b) {
        return a;
    }
    return gcd(b, a % b);
}

signed main() {

    int n;
    cin >> n;
    multiset<int> hv;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        auto pos = hv.upper_bound(-x);
        if (pos == hv.end()) {
            ans++;
        } else {
            hv.erase(pos);
        }
        hv.in(-x);
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 7868
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
    string S;
    cin >> S;
    if (S[0] == 'R') {
        if (S[1] == 'R') {
            if (S[2] == 'R') cout << 3 << endl;
            else cout << 2 << endl;
        }
        else cout << 1 << endl;
    }
    else {
        if (S[1] == 'R') {
            if (S[2] == 'R') cout << 2 << endl;
            else cout << 1 << endl;
        }
        else {
            if (S[2] == 'R') cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
}

















Measured memory_bytes: 3592
object Main extends App {
  val str = io.StdIn.readLine()
  val len = str.length
  var sum: Long = 0
  for (i <- 1 to 1 << (len-1)) {
    var j = i
    var begin = 0
    for (end <- 1 until len) {
      if ((j & 1) == 1) {
        sum += str.substring(begin, end).toLong
        begin = end
      }
      j = j >> 1
    }
    sum += str.substring(begin).toLong
  }
  println(sum)
}

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

int main() {
  int A, B;
  cin >> A >> B;
  if ((A + B) % 2 == 1) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }
  if (A < B) cout << A + (B - A) / 2 << endl;
  else cout << B + (A - B) / 2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
#include<deque>
#include<queue>
#include<set>
#include <functional>

//マクロ
#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 RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)

#define All(a) (a).begin(),(a).end()

//定数
#define INF 1e9
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数
vector<int> l;

//使用する関数
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;
}


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

	ll lim;
	REPS(i, 10000000) {
		if ((ll)i*i >= n) {
			lim = i;
			break;
		}
	}
	
	ll a=0, b;
	RREPS(i, lim) {
		if (n%i == 0) {
			a = i; b = n / i;
			break;
		}
	}
	
	if (a == 0) {
		a = 1, b = n;
	}

	cout << a + b - 2 <<endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
ll k,s;
cin >>k>>s;
ll ans = 0;
for (ll i = 0; i < k + 1; i++) {
    for (ll j = 0; j < k + 1;j++){
        ll z = s - i - j;
        if (0 <= z && z <= k) ans++;
    }
}
cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

#define N 100
#define Gard 100000001
#define Nothing -1
#define Initial 0
#define Medium 1
#define End 2

int main(){
  int loop,Min=0,judge,result=0,temp=0;
  int i,j;
  int Graph[N][N];
  int Ver[N];
  int Pdisc[N];
  int Fin[N];
  
  scanf("%d",&loop);
  for(i=0;i<loop;i++){

    for(j=0;j<loop;j++){
      scanf("%d",&Graph[i][j]);
    }
  }

  for(i=0;i<loop;i++){
    Ver[i]=Gard;
    Pdisc[i]=Nothing;
    Fin[i]=Initial;
  }

  Ver[0]=0;

  while(1){
    Min=Gard;
    judge=Nothing;
    
    for(i=0;i<loop;i++){

      if((Fin[i]!=End) && (Ver[i]<Min)){
	Min=Ver[i];
	judge=i;
      }
    }

    if(judge==Nothing){
      break;
    }

    Fin[judge]=End;

    for(i=0;i<loop;i++){

      if((Fin[i]!=End) && (Graph[judge][i]!=Nothing)){
	if(Graph[judge][i]<Ver[i]){
	  Ver[i]=Graph[judge][i];
	  Pdisc[i]=judge;
	  Fin[i]=Medium;
	}
      }
    }
    
  }


  for(i=0;i<loop;i++){

    if(Pdisc[i]!=Nothing){
      temp=Pdisc[i];
      result+=Graph[i][temp];
    }
  }


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



Measured memory_bytes: 2036
import java.util.*;

public class Main{
    public static void main(String[] args){
        
        Scanner scan = new Scanner(System.in);
        String N = scan.next();
        
        String[] n = N.split("",0);
        int[] l = new int[10];
		
		int b = Integer.parseInt(N);
        
        for(int i=0;i<n.length;i++){
            l[i] = Integer.parseInt(n[i]);
        }
        
		int a = 0;
        for(int j=0;j<n.length;j++){
            a += l[j];
        }
		
		int ans = b % a;
        
        if(ans == 0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10;
int n , x[N] , y[N];

void check(bool ok) {
  if(!ok) {
    puts("-1");
    exit(0);
  }
}

int main(){
  scanf("%d",&n);
  rep(i,0,n) scanf("%d%d",x+i,y+i);
  check(x[0] == 0 && y[1] == 0 && x[1] > 0 && x[1] == y[0]);
  rep(i,2,n) check(x[i] > 0 && y[i] > 0);
  map<pii,int> S;
  rep(i,0,n) S[mp(x[i],y[i])]++;
  rep(i,0,n) {
    if(x[i]) check(S.count(mp(x[i]-1,y[i]-1))||S.count(mp(x[i]-1,y[i]))||S.count(mp(x[i]-1,y[i]+1)));
    if(y[i]) check(S.count(mp(x[i]-1,y[i]-1))||S.count(mp(x[i],y[i]-1))||S.count(mp(x[i]+1,y[i]-1)));
  }
  int res = 2 * n - 2;
  vector<pair<pii,int> > pts;
  for(auto e : S) pts.pb(e);
  sort(all(pts),[&](pair<pii,int> a,pair<pii,int> b){
      int sa=a.fi.fi+a.fi.se;
      int sb=b.fi.fi+b.fi.se;
      if(sa!=sb) return sa < sb;
      return a.fi.fi < b.fi.fi;
      });
  int remain = 0;
  rep(i,0,sz(pts)) {
    int x , y , cnt;
    tie(x , y) = pts[i].fi;
    cnt = pts[i].se;
    int match = min(remain , cnt);
    res -= match;
    if(S.count(mp(x - 1 , y - 1))) {
      int link = cnt - match;
      res -= link;
      cnt -= link;
    }
    if(i + 1 < sz(pts) && x + 1 == pts[i+1].fi.fi && y - 1 == pts[i+1].fi.se)
      remain = cnt;
    else
      remain = 0;
  }
  printf("%d\n",res);
  return 0;
}


Measured memory_bytes: 8952
a = int(input())
s = 0
p =[int(input()) for _ in range(a)]
p.append(0)
for i in range(a):
    s +=p[i]//2
    if p[i+1] >=1 and p[i]%2 == 1:
        s +=1
        p[i+1] -=1
    
print(s)

Measured memory_bytes: 7072
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;

int main(){
  int n;
  int l[10];
  int sum=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>l[i];
  }
  sort(l,l+n,greater<int>());
  repi(i,1,n){
    sum+=l[i];
  }
  if(sum>l[0]) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <tr1/unordered_map>
#include <map>
#include <string>

using namespace std;
using namespace tr1;

typedef long long LL;

struct Dict {
    map<string,int> dict;
    int id;

    Dict() : id(0) {}

    int get(const string &str) {
        if(dict.count(str)) return dict[str];
        return dict[str] = id++;
    }
};

struct Hasher {
    size_t operator ()(const pair<int,LL> &key) const {
        return key.first + key.second;
    }
};

unordered_map<pair<int,LL>,int,Hasher> memo;
int ans = 0;
void dfs(int pos, LL mask, int acc, const vector<int> &power, const vector<LL> &graph) {
    const int N = power.size();
    if(pos == N) {
        ans = max(ans, acc);
        return;
    }

    // テ」ツ?禿」ツつ古」ツ?凝」ツつ嘉・ツ?暗」ツ?ョテ・ツ渉ッティツδステ」ツ?ェテ」ツつづ」ツ?ョテ」ツつ津・ツ?ィテ」ツ?ヲテ・ツ渉姪」ツ?」テ」ツ?ヲテ」ツつづッツシツ古、ツサツ甘」ツ?セテ」ツ?ァテ」ツ?ョテヲツ慊?ィツ可ッティツァツ」テ」ツつ津ィツカツ?」ツ?暗」ツつ嘉」ツつ古」ツ?ェテ」ツ??」ツ?ェテ」ツつ嘉ヲツ楪敕・ツ按暗」ツつ?
    int expected = acc;
    for(int i = pos; i < N; ++i) {
        if(!(mask & (1LL<<i))) expected += power[i];
    }
    if(expected <= ans) return;

    pair<int,LL> key(pos, mask);
    if(memo.count(key) && memo[key] >= acc) return;
    memo[key] = acc;
    dfs(pos+1, mask, acc, power, graph);
    if(!(mask & (1LL<<pos))) {
        dfs(pos+1, mask | graph[pos], acc + power[pos], power, graph);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    while(true) {
        int N;
        cin >> N;
        if(!N) break;

        vector<int> power(N);
        vector<LL> graph(N);
        Dict dict;
        for(int i = 0; i < N; ++i) {
            int B, C;
            string cn;
            cin >> cn >> B >> C;
            int cid = dict.get(cn);
            power[cid] = B;
            while(C--) {
                string neighbor;
                cin >> neighbor;
                int nid = dict.get(neighbor);
                graph[cid] |= 1LL << nid;
            }
            graph[cid] |= 1LL << cid;
        }
        memo.clear();
        ans = 0;
        dfs(0, graph[0], power[0], power, graph);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 52360
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <cmath>
#include <set>

using namespace std;

int a, b;

int calc(int a, int b) {
	int ret = 2e9 + 7;
	// 0
	if (a <= b) ret = min(ret, b - a);
	// 1
	if (b >= -a) {
		ret = min(ret, 1 + b - -a);
	}
	if (-b >= a) {
		ret = min(ret, -b - a + 1);
	}
	// 2
	if (-b >= -a) {
		ret = min(ret, 1 + -b - -a + 1);
	}
	return ret;
}

int main() {
	scanf("%d %d", &a, &b);
	printf("%d\n", calc(a, b));
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,n) for(int i=(a); i<(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
int main() {
  int N; cin >> N;
  vi a(N);
  rep(i,N){ int d; cin >> d; a[i] = d;}
  int ave = 0;
  rep(i,N) ave += a[i];
  ave /= N;  
  int ans = 1e9+7;
  int tans = 0;
  for(int i = ave-1; i< ave+2; i++){
    rep(j,N) tans += (a[j]-i)*(a[j]-i);
    ans = min(ans, tans);
    tans = 0;
  }    
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

namespace AOJ0051
{
    class Program
    {
        static void Main()
        {
            foreach (var numbers in ReadInputs())
            {
                var max = int.Parse(string.Join("", numbers.OrderByDescending(i => i)
                    .Select(i => i.ToString(CultureInfo.InvariantCulture)).ToArray()));
                var min = int.Parse(string.Join("", numbers.OrderBy(i => i)
                    .Select(i => i.ToString(CultureInfo.InvariantCulture)).ToArray()));

                Console.WriteLine(max - min);
            }
        }

        public static IEnumerable<int[]> ReadInputs()
        {
            var count = int.Parse(Console.ReadLine() ?? "");
            for (var i = 0; i < count; i++)
            {
                yield return (Console.ReadLine() ?? "").ToCharArray()
                    .Select(c => int.Parse(c.ToString(CultureInfo.InvariantCulture))).ToArray();
            }
        }
    }
}

Measured memory_bytes: 6444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
#define SUM(v) accumulate(all(v), 0LL)

typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_;

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

#define TOSTRING(x) string(#x)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os  << "["; for(auto _: v) os << _ << ", "; os << "]"; return os; };
template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]" << endl; return os; }

#define DUMPOUT cerr
void dump_func(){ DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#ifdef DEBUG
#define dbg(...) dump_func(__VA_ARGS__)
#define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__)
#else
#define dbg(...)
#define dump(...)
#endif

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const long double PI = acos(-1.0);

/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/


int main() {
    ll a, b;
    ll c, d;
    cin >> a >> b;
    cin >> c >> d;
    ll ans = -INFLL;
    chmax(ans, a * c);
    chmax(ans, a * d);
    chmax(ans, b * c);
    chmax(ans, b * d);
    if(a <= 0 && 0 <= b)chmax(ans, 0LL);
    if(c <= 0 && 0 <= d)chmax(ans, 0LL);
    cout << ans << endl;
}


Measured memory_bytes: 3648
//S.G.N.//
#include <bits/stdc++.h>
using namespace std;
typedef vector< long long > vi;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define fr(n) for(ll i=0;i<n;i++)
#define tr(a) for(auto it=a.begin();it!=a.end();it++)
#define N 998244353445 
#define PI 3.1415926535897932384
#define F first
#define S second
#define mp make_pair
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
void solve()
{
 ll n;
 cin>>n;
 ll a[n],b[n],c[n],dp1[n],dp2[n],dp3[n];
 fr(n)
 cin>>a[i]>>b[i]>>c[i];
 dp1[0]=a[0];
 dp2[0]=b[0];
 dp3[0]=c[0];
 rep(i,1,n)
 {
  dp1[i]=a[i]+max(dp2[i-1],dp3[i-1]);
  dp2[i]=b[i]+max(dp1[i-1],dp3[i-1]);
  dp3[i]=c[i]+max(dp1[i-1],dp2[i-1]);

 }
 cout<<max(dp1[n-1],max(dp2[n-1],dp3[n-1]))<<endl;
}
int main()
{
  
  #ifndef ONLINE_JUDGE
     * freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif
  FAST
  ll test;
  test=1;
  //cin>>test;
  while(test--)
  {
    solve();
  }
  return 0;
}

Measured memory_bytes: 8320
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	string ans;
	if(a >= 0 && b >= 0) ans = "Positive";
	else if(a < 0 && b >= 0) ans = "Zero";
	else{
		a = -a;
		b = -b;
		if((a-b)%2 == 0) ans = "Negative";
		else ans = "Positive";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int mod = 1000000007;

int main() {
    int N;
    cin >> N;
    ll ans = 1;
    
    for (ll i=1; i<=N; i++){
        ans *= i;
        ans %= mod;
    }
    cout << ans << endl;
}

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

#define nl '\n'
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: ", cout << to_string(__VA_ARGS__) << endl
/*compact version*/
template <typename T, size_t N> int SIZE(const T (&t)[N]) { return N; } template<typename T> int SIZE(const T &t) { return t.size(); } string to_string(string &s, int x1 = 0, int x2 = 1e9) { return '"' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) : "") + '"'; } string to_string(const char* s) { string tmp(s); return to_string(tmp); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(char c) { return string({c}); } template<size_t N> string to_string(bitset<N> &b, int x1 = 0, int x2 = 1e9) { string t = ((x1 < b.size()) ? (b.to_string()).substr(x1, x2 - x1 + 1) : ""); reverse(begin(t), end(t)); return '"' + t + '"'; } template <typename A, typename... C> string to_string(A (&v), int x1 = 0, int x2 = 1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if (l_v_l_v_l == 0) res += nl; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2 - x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if (e != l) { if (rnk > 1) { res += nl; t_a_b_s = l_v_l_v_l; }; } else { t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if (l_v_l_v_l == 0) res += nl; return res; }
/*end of compact version*/


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
#endif

    int t = 1;
    // cin >> t;

    while (t--) {
        int n, m;
        cin >> n >> m;
        if (m >= n) cout << "unsafe" << endl;
        else cout << "safe" << endl;

    }

    return 0;
}

Measured memory_bytes: 3656
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	if !scanner.Scan() {
		fmt.Fprintf(os.Stderr, "No stdin passed.")
		os.Exit(1)
	}

	strs := strings.Split(scanner.Text(), " ")
	if len(strs) != 2 {
		fmt.Fprintf(os.Stderr, "Wrong number of arguments")
		os.Exit(1)
	}

	a, _ := strconv.Atoi(strs[0])
	b, _ := strconv.Atoi(strs[1])

	if a&b&1 == 1 {
		fmt.Printf("Odd")
	} else {
		fmt.Printf("Even")
	}
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   int N;
   cin >> N;
   int D[N];
   int cnt[N];
   memset(cnt,0,sizeof(cnt));
   long long ans=1;
   int mod = 998244353;
   int M=0;
   bool ok = true;
   for(int i=0;i<N;i++){
      cin >> D[i];
      if(i==0&&D[i]!=0) ok=false;
      if(i!=0&&D[i]==0) ok=false;
      M = max(M,D[i]);
      cnt[D[i]]++;
   }
   if(ok==false){
      cout << 0 << endl;
      return 0;
   }
   for(int i=2; i<=M; i++){
      for(int j=0; j<cnt[i]; j++){
         ans *= cnt[i-1];
         ans %= mod;
      }
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    char b,A,C,G,T;
    cin >>b;
    if(b=='A'){
        cout << 'T'<<endl;
    }
    else if(b=='C'){
        cout <<'G'<<endl;
    }
    else if(b=='T'){
        cout <<'A'<<endl;
    }
    else if(b=='G'){
        cout << 'C'<<endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int N,S[1<<17],vis[1<<17];
long ans;
main()
{
	cin>>N;
	for(int i=0;i<N;i++)cin>>S[i];
	for(int i=1;i<N;i++)
	{
		long now=0;
		int L=0,R=N-1;
		while(R>i&&vis[R]<i)
		{
			ans=max(ans,now+=S[L]+S[R]);
			L+=i;R-=i;vis[L]=i;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
namespace mp = boost::multiprecision;
// mp::cpp_int
// mp::cpp_dec_float_100



int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
  
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);  rep(i, 0, n) cin >> a[i];
  
  sort(all(a));
  ll ans = 10000000000;
  rep(i, 0, n-k+1) {
    ll x = a[i+k-1]-a[i];
    ans = min(ans, x);
  }
  cout << ans << "\n";
}

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

string a;
int c, mx;
int main() {
	cin >> a;
	if(a[0] == 'R') mx = c = 1;
	for(int i=1; i<3; i++) {
		if(a[i]=='R') {
			if(a[i-1]=='R') c++;
			else c = 1;
		} else c = 0;
		mx = max(mx, c);
	}
	cout << mx;
	return 0;
}


Measured memory_bytes: 3520
from collections import deque
N,K = map(int,input().split())
R,S,P = map(int,input().split())
Tlist = input()
Answer = 0
def po(x):
    if x == 's':
        return R
    elif x == 'r':
        return P
    else:
        return S
for i in range(K):
    TK = list(Tlist[i::K]).copy()
    TK.append('')
    T2 = TK[0]
    sig = 2
    for i in range(1,len(TK)):
        T1 = T2
        T2 = TK[i]
        if T1 == T2 and i != len(TK)-1:
            sig += 1
        else:
            Answer += po(T1)*(sig//2)
            sig = 2
print(Answer)

Measured memory_bytes: 10896
using System.Linq;
using static System.Math;
using System;

public class hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            string[] line = Console.ReadLine().Trim().Split(' ');
            var a = Array.ConvertAll(line, int.Parse);
            var asum = (long)a.Sum();
            line = Console.ReadLine().Trim().Split(' ');
            var b = Array.ConvertAll(line, int.Parse);
            Array.Sort(b);
            Array.Reverse(b);
            var ans = getAns(b, asum, n);
            Console.WriteLine(ans);
        }
    }
    public static long getAns(int[] b, long asum, int n)
    {
        var ans = asum * n;
        for (int i = 0; i < n - 1; i++)
        {
            asum += b[i];
            var w = (n - i - 1) * asum;
            ans = Max(ans, w);
        }
        return ans;
    }
}


Measured memory_bytes: 38068
#!/usr/bin/env python3
import sys
from itertools import chain


def solve(N: int, K: int, A: "List[int]"):
    M = [-1 for _ in range(N)]
    M[0] = 0
    current = 1
    n = 1
    while n <= K:
        current = A[current - 1]
        if M[current - 1] == -1:  # 一度も通ったことがない
            M[current - 1] = n  # n ステップ目に通った事を記録
        else:
            loop_len = n - M[current - 1]  # ループの長さ
            rest = K - n  # 残り長さ
            rest = rest % loop_len  # 残り長さをループの余剰にする
            K = n + rest
        n += 1
    return current


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    # N, K, A = map(int, line.split())
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    answer = solve(N, K, A)
    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38040
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n, c[510], s[510], f[510];

int iceil(int a, int b) {
    // ceil(a/b)
    return (a + b - 1) / b;
}

int main() {
    cin >> n;
    rep(i, n-1) cin >> c[i] >> s[i] >> f[i];

    for (int i = 0; i < n; i++) {
        int t = 0;
        for (int j = i; j < n-1; j++) {
            if (t < s[j]) t = s[j];
            else if (t % f[j] != 0) t = t + f[j] - t % f[j];
            t += c[j];
        }
        cout << t << endl;
    }
}


Measured memory_bytes: 256
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let n: usize = sc.read();
    let mut ab: Vec<(usize, usize)> = (0..n).map(|_| (sc.read(), sc.read())).collect();
    let mut cd: Vec<(usize, usize)> = (0..n).map(|_| (sc.read(), sc.read())).collect();
    ab.sort();
    cd.sort();

    let mut ans = 0;
    let mut prd = vec![false; n];
    for i in 0..n {
        let mut p = None;
        for j in 0..n {
            if ab[j].0 >= cd[i].0 {
                break;
            }
            if !prd[j] && ab[j].1 < cd[i].1 {
                p = Some(p.map_or((j, ab[j].1), |(jy, y)| {
                    if y > ab[j].1 {
                        (jy, y)
                    } else {
                        (j, ab[j].1)
                    }
                }));
            }
        }
        if let Some((j, _)) = p {
            ans += 1;
            prd[j] = true;
        }
    }

    format!("{}\n", ans)
}
fn main() {
    let mut buf = String::new();
    use std::io::{Read, Write};
    std::io::stdin().read_to_string(&mut buf).unwrap();
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<'a>(std::str::SplitWhitespace<'a>);
impl<'a> Scanner<'a> {
    fn from_str(src: &str) -> Scanner {
        Scanner(src.split_whitespace())
    }
    fn get(&mut self) -> &str {
        self.0.next().unwrap()
    }
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.get().parse().ok().unwrap()
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
#define MAX 2000

int solve(int, int);
int A[MAX],n;

int main(){
  int q, i, m[MAX];
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    scanf("%d", &A[i]);
  scanf("%d", &q);
  for(i = 0; i < q; i++)
    scanf("%d", &m[i]);

  for(i = 0; i < q; i++){
    if(solve(0, m[i]) == 1)
      printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

int solve(int i, int m){
  int res = 0;
  if(m == 0)
    return 1;
  if(i >= n)
    return 0;
  res = solve(i + 1, m - A[i]) || solve(i + 1, m);
  return res;
}

Measured memory_bytes: 588
#include <bits/stdc++.h>
#define endl    '\n'
using namespace std;

typedef long long ll;

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

    int cnt;
    int n;
    int l[4], s[4];
    int l_num, s_num;

    cin >> n;

    while (n != 0) {
        cnt = 0;

        if (n % 1111 == 0) {
            cout << "NA";
        } else {
            while (n != 6174) {
                l_num = s_num = 0;

                for (int i = 3; i >= 0; --i) {
                    s[i] = n % 10;
                    n /= 10;
                }

                sort(s, s + 4);
                s_num += s[0] * 1000;
                s_num += s[1] * 100;
                s_num += s[2] * 10;
                s_num += s[3];

                l_num += s[3] * 1000;
                l_num += s[2] * 100;
                l_num += s[1] * 10;
                l_num += s[0];

                n = l_num - s_num;
                cnt++;
            }

            cout << cnt;
        }
        cout << endl;

        cin >> n;
    }

    return 0;
}




Measured memory_bytes: 3128
n=int(input())

b=list(map(int,input().split()))

a=[0]*(n+1)
a[0]=b[0]
a[1]=b[0]
for i in range(1,n-1):
  a[i+1]=b[i]
  if a[i]>b[i]:
    a[i]=b[i]

print(sum(a))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define rep(i,n) for (ll i = 0; i < n; i++)
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>
#define vvl vector<vector<ll>> //a(縦行,vector<ll>(横列));
#include<algorithm>//__gcd(a,b)
#include <iostream>
#include <vector>
#include <cstdlib>
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

int main(){
  string s;cin>>s;
  string t;cin>>t;
  bool ans =1;
  rep(i,s.size())if(s[i]!=t[i]){ans=0;}
  if(ans&&t.size()!=s.size()+1){ans=0;}

  if(ans){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

int K, N;

int main(int argc, char **argv) {
    std::cin >> K >> N;

    if (K == 1) {
        int length = N % 2 == 0 ? N / 2 : N / 2 + 1;
        for (int i = 1; i <= length; i++) {
            std::cout << 1 << " ";
        }
        std::cout << std::endl;
        return 0;
    } else if (K % 2 == 0) {
        for (int i = 1; i <= N; i++) {
            if (i == 1) {
                std::cout << K / 2 << " ";
            } else {
                std::cout << K << " ";
            }
        }
        std::cout << std::endl;
        return 0;
    } else {
        std::vector<int> ret;
        for (int i = 1; i <= N; i++) {
            ret.push_back(K / 2 + 1);
        }
        const int target_rel = N % 2 == 0 ? N / 2 : N / 2 + 1;
        for (int j = N; target_rel < j; j--) {
            if (ret[ret.size() - 1] == 1) {
                ret.pop_back();
            } else {
                ret[ret.size()-1] = ret[ret.size()-1] - 1;
                while (ret.size() < N) {
                    ret.push_back(K);
                }
            } 
        }

        for (int i = 0; i < ret.size(); i++) {
            std::cout << ret[i] << " ";
        }
        return 0;
    }

    //return 0;

}


Measured memory_bytes: 3568
#include <vector>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <map>
#include <complex>
#include <ctime>
#include <numeric>
#include <set>

using namespace std;

typedef long long ll;
const ll M=1e6+5;

typedef struct node{
    int s, e, val, pos;
    bool operator<(const node& n) const{
        if(e != n.e) return e < n.e;
        return val > n.val;
    }
    node(){};
    node(int ss, int ee, int v, int p){
        s = ss, e = ee, val = v, pos = p;
    }
}node;

int occs[M], tree[M], n, ans[M];

void update(int x, int val){
    while(x <= n){
        tree[x] += val;
        x += x & -x;
    }
}

int query(int x){
    int ret = 0;
    while(x > 0){
        ret += tree[x];
        x -= x & -x;
    }
    return ret;
}

int main()
{
    
    int q, s, e;
    vector<node> v;
    scanf("%d", &n);
    scanf("%d", &q);
    for(int i = 1; i <= n; i++){
        scanf("%d", &s);
        v.push_back(node(i, i, s, -1));
    }
    for(int i = 0; i < q; i++){
        scanf("%d %d", &s, &e);
        v.push_back(node(s, e, 0, i));
    }
    
    sort(v.begin(), v.end());
    
    for(int i = 0;i < v.size(); i++){
        if(v[i].val == 0){
            ans[v[i].pos] = query(v[i].e) - query(v[i].s - 1);
        }else{
            if(occs[v[i].val] != 0) update(occs[v[i].val], -1);
            update(v[i].s, 1);
            occs[v[i].val] = v[i].s;
        }
    }
    
    for(int i = 0; i < q; i++){
        printf("%d\n", ans[i]);
    }
    
    return 0;
}



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

int main()
{
    int a,b,k;
    cin >> a >> b >> k;
    int cnt = 0;
    int ans = 1;
    for(int i=min(a,b);i>=1;--i)
    {
        if(a%i==0 && b%i==0)
        {
            cnt++;
            ans = i;
        }
        if(cnt==k)
        {
            break; 
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

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

int main(){
    int x;
    cin >> x;
    if(x){
        cout << 0;
    }else{
        cout << 1;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3628
import heapq
N,M = map(int,input().split())
AB = sorted([list(map(int,input().split())) for _ in range(N)])

option = []
ans = 0
j = 0
for i in range(1,M+1):
    while j != N and AB[j][0] <= i: 
        heapq.heappush(option,-AB[j][1])
        j += 1
    if len(option) != 0:
        ans -= heapq.heappop(option)
print(ans)

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

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int numAC = 0;
		int numWA = 0;
		int numTLE = 0;
		int numRE = 0;

		int n = in.nextInt();
		while (n-- > 0) {
			String s = in.next();
			if (s.equals("AC"))
				numAC++;
			else if (s.equals("WA"))
				numWA++;
			else if (s.equals("TLE"))
				numTLE++;
			else
				numRE++;
		}

		System.out.println("AC x " + numAC);
		System.out.println("WA x " + numWA);
		System.out.println("TLE x " + numTLE);
		System.out.println("RE x " + numRE);
	}
}



Measured memory_bytes: 58804