akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  vector<ll> T(N), A(N), t_num(N), a_num(N);
  for (int i = 0; i < N; ++i) {
    ll t, a;
    cin >> t >> a;
    T[i] = t;
    A[i] = a;
    if (i == 0) {
      t_num[i] = t;
      a_num[i] = a;
    }
  }
  
  for (int i = 1; i < N; ++i) {
    ll last_t = t_num[i - 1];
    ll last_a = a_num[i - 1];
    ll t_rate = T[i];
    ll a_rate = A[i];
    ll div_t = (last_t + (t_rate - 1)) / t_rate;
    ll div_a = (last_a + (a_rate - 1)) / a_rate;
    ll div = max(div_t, div_a);
    t_num[i] = t_rate * div;
    a_num[i] = a_rate * div;
  }
  cout << t_num[N - 1] + a_num[N - 1] << endl;
}


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

int main()
{
    size_t H, W, K, x1, y1, x2, y2;
    cin >> H >> W >> K >> x1 >> y1 >> x2 >> y2;
    x1--;
    y1--;
    x2--;
    y2--;
    vector<string> c(H);
    for (string &s : c)
    {
        cin >> s;
    }

    size_t INIT = H * W + 5;
    vector<vector<size_t>> dp(H, vector<size_t>(W, INIT));
    dp[x1][y1] = 0;
    queue<pair<size_t, size_t>> q;
    q.push(make_pair(x1, y1));
    vector<pair<int, int>> diff{
        make_pair(0, 1),
        make_pair(1, 0),
        make_pair(0, -1),
        make_pair(-1, 0),
    };
    while (!q.empty())
    {
        size_t x = q.front().first;
        size_t y = q.front().second;
        q.pop();
        for (pair<int, int> d : diff)
        {
            for (size_t k = 1; k <= K; k++)
            {
                size_t x_next = x + k * d.first;
                size_t y_next = y + k * d.second;
                if (x_next < H && y_next < W)
                {
                    if (c[x_next][y_next] == '@')
                    {
                        break;
                    }
                    if (dp[x][y] + 1 < dp[x_next][y_next])
                    {
                        dp[x_next][y_next] = dp[x][y] + 1;
                        q.push(make_pair(x_next, y_next));
                    }
                    else
                    {
                        if (dp[x][y] + 1 > dp[x_next][y_next])
                        {
                            break;
                        }
                    }
                }
                else
                {
                    break;
                }
            }
        }
    }
    if (dp[x2][y2] == INIT)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << dp[x2][y2] << endl;
    }
}


Measured memory_bytes: 20012
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	int MOD = 1000000007;
	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int a[] = new int[n+1];
		int ind[] = new int[n+1];
		int l=-1;
		int r=-1;
		Arrays.fill(ind, -1);
		for(int i=0; i<n+1; i++) {
			a[i]=sc.nextInt();
			if(ind[a[i]]>=0) {
				l=ind[a[i]];
				r=i;
			}
			ind[a[i]]=i;
		}

		init(n+1);

		for(int k=1; k<=n+1; k++) {
			long ans = ((combi(n+1, k) + MOD) - combi(l + n-r, k-1)) % MOD;
			System.out.println(ans);
		}
		sc.close();
	}

	long fact[];
	long ifact[];
	private long combi(int n, int k) {
		if(k<0 || k>n) return 0;
		return (((fact[n] * ifact[k]) % MOD) * ifact[n-k]) % MOD;
	}

	private void init(int n) {
		fact = new long[n+1];
		ifact = new long[n+1];

		fact[0]=1;
		for(int i=1; i<=n; i++) {
			fact[i] = (fact[i-1] * i) % MOD;
		}
		ifact[n] = pow(fact[n], MOD-2);
		for(int i=n; i>=1; i--) {
			ifact[i-1] = (ifact[i] * i) % MOD;
		}
	}

	private long pow(long x, int n) {
		if(n==0) return 1;
		long ret = pow(x, n/2);
		if(n%2==0) {
			ret = (ret * ret) % MOD;
		}else {
			ret = (((ret * ret) % MOD) * x) % MOD;
		}
		return ret;
	}

}


Measured memory_bytes: 65856
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n,a,b;
    cin>>n>>a>>b;
    int ans=0;
    for(int i=1;i<=n;i++){
        int sum=0;
        string s=to_string(i);
        for(int j=0;j<s.size();j++){
            sum+=s[j]-'0';
        }
        if(a<=sum&&sum<=b)ans+=i;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
def examB():
    N = I(); A = [I() for _ in range(N)]
    ans = 0; cur= 0
    for i in A:
        if i==0:
            ans += cur//2
            cur = 0
        else:
            cur += i
    ans += cur // 2
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examB()


Measured memory_bytes: 44252
import sys
import string

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    N = I()
    ans = []
    alpha = string.ascii_lowercase
    while N:
        ans.append(alpha[(N-1)%26])
        if N % 26 == 0:
            N = N // 26 - 1
        else:
            N = N // 26
    ans.reverse()
    answ = ""
    for a in ans:
        answ += a
    print(answ)



if __name__ == '__main__':
    main()

Measured memory_bytes: 78276
def fac(x):
    a=1
    for i in range(2,x+1):
        a*=i
    return(a)
def npr(x,x1):
    return fac(x)//(fac(x-x1)*fac(x1))
n,m=map(int,input().split())
ans=npr(n,2)+npr(m,2)
print(ans)

Measured memory_bytes: 3060
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define fo(i, n1, n, x) for(int i = n1; i <= n; i += x)
#define foo(i, n, n1, x) for(int i = n; i >= n1; i -= x)
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

const int N = 1e5 + 11, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


typedef pair <int, int> pii;
typedef pair <ll, ll> pll;


mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n, col[N], ans[N], mx;
vector <pii> g[N];
void dfs(int v, int pr, int cl) {
    int cur = 0;
    for (pii to : g[v]) {
        if (to.F == pr) continue;
        ++cur;
        if (cur == cl) ++cur;
//        cout << "Ch" << cur << " " << to.S;
        ans[to.S] = cur;
        dfs(to.F, v, cur);
    }
    chmax(mx, cur);
}
main() {
    file("stars");
    ios;
    cin >> n;
    fo(i, 1, n - 1, 1) {
        int u, v;
        cin >> u >> v;
        g[u].pb({v, i});
        g[v].pb({u, i});
    }
    dfs(1, 1, 0);
    cout << mx << "\n";
    fo(i, 1, n - 1, 1) cout << ans[i] << "\n";
    cerr << "\nTime elapsed: " << (clock() + 0.0) / CLOCKS_PER_SEC;
    return 0;
}
/**

*/


Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  
  vector<int> button(N);
  for(int i = 0; i < N; i++){
    cin >> button.at(i);
  }
  
  int num = 1, count = 0;
  for(int i = 0; i <= N; i++){
    num = button.at(num - 1);
    count++;
    
    if(num == 2){
      break;
    }
  }
  
  if(count > N){
    count = -1;
  }
  
  cout << count << endl;
  
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define int ll
#define pb push_back
using pii = pair<int,int>;
const int N = 105;
const int Inf = 1e9+7;
#ifndef M_PI
#define M_PI 3.1415926535
#endif

void io()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cerr.tie(NULL);
//		cout << setprecision(10) << fixed;
}

int dp[N][N], b[N], e[N];

signed main()
{
	io();
	int n, k;
	cin >> k;
	queue<int> q;
	for (int i = 1; i < 10; ++i)
	{
		q.push(i);
	}
	for (int i = 1; i < k; ++i)
	{
		int x = q.front();
		q.pop();
		if (x % 10)
			q.push(10 * x + x % 10 - 1);
		q.push(10 * x + x % 10);
		if (x % 10 != 9)
			q.push(10 * x + x % 10 + 1);
	}
	cout << q.front();
}


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

#define ll long long
#define ar array
 
using namespace std;


int main() {
	
	int a,b;
	
	cin>>a >>b;
	
	if(a>=13){
		cout << b <<endl;
	}else if(a<=5){
		b=0;
		cout <<b<<endl;
	}else{
		cout << b/2 <<endl;
	}
   	return 0;
}

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

int main() {
  string s;
  int n;
  cin >> n >> s;
  rep(i,s.size()){
    if(s[i]+n<='Z') s[i] += n;
    else s[i]=s[i]+n-('Z'-'A'+1);
  }
  cout << s << endl;
}


Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n;
vector<int> a;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    ll ans=1;
    for(ll i=1;i<=n;i++){
        ans*=i;
        ans%=MOD;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        
        PriorityQueue q = new PriorityQueue(Collections.reverseOrder());

        for(int i=0; i<N; i++){
            q.add(sc.nextInt());
        }

        for(int i=0; i<M; i++){
            q.add((int)(q.poll())/2);
        }

        long res=0;

        while(!q.isEmpty()){
            res=res+(int)q.poll();
        }



        System.out.println(res);
        
        
        
        
        }
    }

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

int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  sort(A.begin(), A.end());
  long long ans = 1;
  for (int i = 0; i < N - 1; i++) {
    if (A[i + 1] <= A[i] * 2) {
      ans++;
    } else
      ans = 1;
    A[i + 1] += A[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i= a ; i < b ; ++i)
#define rep(i,n) fo(i,0,n)
#define pln(n) printf("%lld",n)
#define sll(n) scanf("%lld",&n)
#define ss(n) scanf("%s",n)
#define vi vector < int >
#define pii pair < int , int >
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define dbg3(x,y,z) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) <<" , "<< #z <<": "<<(z)<<endl; }
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define vll vector<long long>
#define vvll vector<vector<long long>>
#define vvvll vector<vector<vector<ll>>>
#define si set<int>
#define tr(c, it) \
for(decltype(c.begin()) it = c.begin(); it!= c.end(); it++)
#define pis pair<int,string>
#define present(c, x) (c.find(x) != c.end())
#define cpresent(c, x) (find(all(c),x) != c.end())
#define  ones(x)  __builtin_popcount(x)
using namespace std;

int main(){
    string a;
    cin >> a;
    if(a == "ABC"){
        cout <<"ARC";
    }
    else cout << "ABC";

}

Measured memory_bytes: 3552
/*
    Author - Param Kothari
    Ah shit, here we go again
*/
 
/* Ordered Set Implementaton:

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;

typedef tree<
    int,
    null_type,
    less<int>,
    rb_tree_tag,
    tree_order_statistics_node_update>
ordered_set;
*/

#include <bits/stdc++.h>
 
using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair 
 
typedef long long ll;
typedef long double ld;

void solve(){
    int n, x, y;
    cin >> n >> x >> y;
    int a[n + 1][n + 1] = {0};
    for(int i = 1; i <= n; i++){
        for(int j = i + 1; j <= n; j++){
            a[i][j] = min(j - i, abs(i - x) + 1 + abs(y - j));
            a[j][i] = a[i][j];
        }
    }
    ll count[n + 1] = {0};
    for(int i = 1; i <= n; i++){
        for(int j = i + 1; j <= n; j++){
            count[a[i][j]]++;
        }
    }
    for(int i = 1; i < n; i++){
        cout << count[i] << "\n";
    }
    return;
}
 
int main(){
    IOS;
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 15872
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
    int N, X, Y;
    cin >> N >> X >> Y;
    vector<int> dist(N);
    for(int i = 1; i <= N; i++){
        for(int j = i + 1; j <= N; j++){
            int d = min(abs(i-j), abs(i-X) + 1 + abs(j-Y));
            d = min(d, abs(i-Y) + 1 + abs(j-X));
            dist[d]++;
        }
    }

    for(int i = 1; i < N; i++){
        cout << dist[i] << endl;
    }
}

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

using namespace std;

typedef pair<int,int> pii;
int trmp;
pii deck[4][13];

pii analysis(string &s){
	int a,b;
	if(s[0]>='0'&&s[0]<='9')a=s[0]-'0';
	else if(s[0]=='T')a=10;
	else if(s[0]=='J')a=11;
	else if(s[0]=='Q')a=12;
	else if(s[0]=='K')a=13;
	else if(s[0]=='A')a=14;
	if(s[1]=='S')b=0;
	else if(s[1]=='H')b=1;
	else if(s[1]=='D')b=2;
	else if(s[1]=='C')b=3;
	return pii(a,b);
}

int main(){
	char ch;
	while(cin>>ch&&ch!='#'){
		if(ch=='S')trmp=0;
		else if(ch=='H')trmp=1;
		else if(ch=='D')trmp=2;
		else if(ch=='C')trmp=3;
		for(int i=0;i<4;i++){
			for(int j=0;j<13;j++){
				string s;
				cin>>s;
				deck[i][j]=analysis(s);
			}
		}
		int fst=0;
		int cnt=0;
		int cnt2=0;
		for(int i=0;i<13;i++){
			int winIdx=fst;
			pii p=deck[fst][i];
			for(int j=0;j<4;j++){
				if(j==fst)continue;
				if(deck[j][i].second==trmp){
					if(p.second!=trmp||p.first<deck[j][i].first){
						p=deck[j][i];
						winIdx=j;
					}
				}
				else if(p.second!=trmp&&p.second==deck[j][i].second){
					if(p.first<deck[j][i].first){
						p=deck[j][i];
						winIdx=j;
					}
				}
			}
			if(winIdx==0||winIdx==2)cnt++;
			else cnt2++;
			fst=winIdx;
		}
		if(cnt>cnt2)cout<<"NS "<<abs(cnt-6)<<endl;
		else cout<<"EW "<<abs(cnt2-6)<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
import Data.Array (Array, listArray, (!))
import Data.List (sort)

main = do
  [n,k] <- map read . words <$> getLine
  hs <- listArray (1,n) . sort . map read . lines <$> getContents
  print $ minimum [(hs!j) - (hs!i) | i <- [1..n-k+1], let j=i+k-1]


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

int main(){
  string s;
	cin >> s;
  if( s[0] == 'R' && s[1] == 'R' && s[2] == 'R' ) cout << 3 << endl;
  else if( ( s[0] == 'R' && s[1] == 'R' ) || ( s[1] == 'R' && s[2] == 'R' ) ) cout << 2 << endl;
  else{
    for( char cc : s ){
      if( cc == 'R' ) {
        cout << 1 << endl;
        return 0;
      }
    }
    cout << 0 << endl;
  }
  return 0;
}
      

Measured memory_bytes: 3572
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }

template <class T, class T2>
void group(T &xs, vector<pair<T2, int> > &result) {
  int i=0, j;
  while (i<xs.size()) {
    j=i;
    while (j < xs.size() and xs[j] == xs[i]) j++;
    result.push_back({ xs[i], j-i });
    if (j==i) i++;
    i=j;
  }
}

void solve() {
  string s;
  cin >> s;
  vector<pair<char, int> > G;
  group(s, G);
  int n = 0;
  for (auto &&g: G) if (n < g.second) n = g.second;
  if (n >= 3) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef string str;
typedef vector<char> vc;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define all(a) a.begin(), a.end()

template <typename T>
T Sum(vector<T> n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (accumulate(n.begin() + a, n.end(), 0));
  }
  else
  {
    return (accumulate(n.begin() + a, n.begin() + b, 0));
  }
}
template <>
ld Sum(vector<ld> n, ll a, ll b)
{
  if (b == 0)
  {
    return (accumulate(n.begin() + a, n.end(), 0));
  }
  else
  {
    return (accumulate(n.begin() + a, n.begin() + b, 0));
  }
}

template <typename T>
void Sort(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (sort(n.begin() + a, n.end()));
  }
  else
  {
    return (sort(n.begin() + a, n.begin() + b));
  }
}

template <typename T>
void Reve(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (reverse(n.begin() + a, n.end()));
  }
  else
  {
    return (reverse(n.begin() + a, n.begin() + b));
  }
}

template <typename T>
void V(T &n)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i];
  }
}

template <typename T, typename U>
void V2(T &n, U &m)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i] >> m[i];
  }
}

template <typename T, typename U, typename W>
void V3(T &n, U &m, W &p)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i] >> m[i] >> p[i];
  }
}

void fYn(bool a)
{
  if (a)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  exit(0);
}
//最大公約数
ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}
//最小公倍数
ll lcm(ll a, ll b)
{
  return a * b / gcd(a, b);
}
//複数個の最小公倍数
ll nlcm(vector<ll> numbers)
{
  ll res;
  res = numbers[0];
  for (ll i = 1; i < numbers.size(); i++)
  {
    res = lcm(res, numbers[i]);
  }
  return res;
}
//累乗(xのn乗%mod)
ll mod_pow(ll x, ll n, ll mod = MAX)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

//大文字->小文字(+32)
//少数はなるべく整数に

void Main()
{
  ll a, b;  cin >> a >> b;
  vll v(3);
  v[0] = a + b;
  v[1] = a - b;
  v[2] = a * b;
  Sort(v);
  fin(v[2])
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    string S, T;
    cin >> S >> T;
    ll N = (ll)S.size();

    Vi nums_S(26), nums_T(26);
    for (ll i = 0; i < N; i++) {
        ++nums_S[S[i] - 'a'];
        ++nums_T[T[i] - 'a'];
    }
    sort(nums_S.begin(), nums_S.end());
    sort(nums_T.begin(), nums_T.end());

    if (nums_S == nums_T) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

Measured memory_bytes: 916
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int dp[12][12], sm[12], ac, k;
int main(){
	scanf("%d", &k);
	fill(dp[0], dp[0]+10, 1);
	sm[0] = 9;
	for(int i=1; i<12; i++) rep(j,10){
		dp[i][j] = (j?dp[i-1][j-1]:0) + dp[i-1][j] + (j==9?0:dp[i-1][j+1]);
		if(j) sm[i] += dp[i][j];
	}

	for(int i=0; i<12; ac += sm[i++]) if(ac + sm[i] >= k){
		int u = 1;
		for(; ac+dp[i][u] < k; ac += dp[i][u++]);
		printf("%d",u);
		for(int ii=i-1; ii>=0; ii--){
			for(int uu=max(u-1,0); uu<=min(u+1,9); ac += dp[ii][uu++]) if(ac+dp[ii][uu] >= k){
				printf("%d",uu);
				u=uu;
				break;
			}
		}
		break;
	}
	puts("");
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 3e5+100;
int a[maxn],n,mp[maxn],f[maxn],l=1,r,cnt,sum;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),r=max(r,a[i]);
	for(int i=1;i<=n;i++) mp[a[i]]++;
	for(int i=1;i<=r;i++) if(mp[i]) cnt++;
	for(int i=1;i<=r;i++) if(mp[i]>=3){
		if(mp[i]&1) mp[i]=1;
		else mp[i]=2;
	}
	for(int i=1;i<=r;i++){
		if(mp[i]==2) sum++;
	}
	if(sum&1) cnt--;
	cout<<cnt;
	return 0;
}

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

using namespace std;
int t[105],a[105],b[105];
int main()
{
    int i,j,m,n,x=0;
    cin >> n;
    for(i=0;i<n;i++)
    {
        cin >> t[i];
        x+=t[i];
    }
    cin >> m;
    for(i=0;i<m;i++)
    {
        cin >> a[i] >> b[i];
        cout << x-t[a[i]-1]+b[i] << endl;
    }
    return 0;
}


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

int getHeadNum(int n) {
  while(n/10>0){
    n /= 10;
  }
  return n;
}
int getFooterNum(int n) {
  return n%10;
}

int main(){
  int N;
  cin >> N;
  
  long long memo[10][10];
  for (int i = 0; i < 10; i++){
    for (int j = 0; j < 10; j++){
      memo[i][j]=0;
    }
  }
  
  for (int i = 1; i <= N; i++) {
    memo[getHeadNum(i)][getFooterNum(i)]++;
  }
  
  long long ans = 0;
  for (int i = 1; i < 10; i++){
    for (int j = 1; j < 10; j++){
      ans += memo[i][j]*memo[j][i];
    }
  }
  
  cout << ans << endl;
  return 0;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
  ll n;
  cin >> n;
  vector<ll> ruiseki(n + 1, 0);
  REP(i, n)
  {
    ll w;
    cin >> w;
    ruiseki[i + 1] = ruiseki[i] + w;
  }
  ll res = pow(10, 9);
  REP(i, n)
  {
    ll s1 = ruiseki[i + 1];
    ll s2 = ruiseki[n] - ruiseki[i + 1];
    res = min(abs(s2 - s1), res);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    int max = a + b;
    if (max < a - b)
    {
        max = a - b;
    }
    if (max < a * b)
    {
        max = a * b;
    }
    printf("%d",max);
}


Measured memory_bytes: 128
s = input()
ans = 0

plus_minus = [[]]
for i in range(len(s) - 1):
  new = []
  for element in plus_minus:
    new.append(element + [0]) 
    new.append(element + [1])
    plus_minus = new
    
for element in plus_minus:
  formula = s
  plus_num = 0
  for i in range(0, len(s) - 1):
    if element[i] == 1:
      formula = (formula[:i + 1 + plus_num] + "+" + formula[i + 1 + plus_num:])
      plus_num += 1
  ans += eval(formula)
print(ans)

Measured memory_bytes: 39152
#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int inf=1e9+7;
signed main(){
    int n,k,a,b;
    cin>>n>>k;
    while(cin>>a>>b)
        cout<<min({a-1,b-1,n-a,n-b})%3+1<<endl;
}



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

int solve(int n) {
	vector<bool> v;
	vector<int> prime;
	if (n == 0)return 0;
	else if (n == 1)return 0;
	else if (n == 2)return 1;
	else {
		v.push_back(false);//0
		v.push_back(false);//1
		for (int i = 2; i <= n; i++) {
			v.push_back(true);
		}
		for (int i = 2; i <= (int)pow(n, 0.5) + 1; i++) {
			if (v[i] == true) {
				for (int j = i * 2; j <= n; j += i) {
					v[j] = false;
				}
			}
		}
		//cout << "v.size()=" << v.size() << endl;
		for (int i = 0; i < v.size(); i++) {
			if (v[i] == true) {
				prime.push_back(i);
			}
		}
		return prime.size();
	}

}

int main()
{
	int n;
	while (cin >> n) {
		int ans = solve(n);
		cout << ans << endl;
	}

    return 0;
}

Measured memory_bytes: 2184
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1e17 - 10;
const double PI = acos(-1);
#define fir first
#define sec second
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, s, t, q, ans, sum[1000000], a[1000][1000];
struct Edge { LL to,cost; };
string str, ss;
Pll P[1000000];
bool f[30];
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}
int main() {
	cin >> h >> w>>s;
	rep(i, h) {
		rep(j, w) {
			cin >> a[i][j];
			P[a[i][j]] = Pll(i + 1, j + 1);
		}
	}
	rep(i,h*w+1) {
		if (i >= s)
			sum[i] = abs(P[i].fir - P[i - s].fir) + abs(P[i].sec - P[i - s].sec)
			+ sum[i - s];
	}
	cin >> q;
	rep(i,q) {
		cin >> n >> m;
	
		cout << sum[m]-sum[n] << endl;
	}
	return 0;
}


Measured memory_bytes: 8704
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

class Main{
	static class FastReader{
		BufferedReader br;
		StringTokenizer st;
		public FastReader(){
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		public String next() {
			while(st==null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch(IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
	public static void main(String[] args) {
		FastReader ob = new FastReader();
		int n = ob.nextInt();
		String s = ob.next(),t=ob.next(),ans="";
		int i=0,j=0;
		boolean flag=true;
		while(i<n || j<n) {
			if(flag) {
				ans+=s.charAt(i);
				i++;
				flag=false;
			}
			else {
				ans+=t.charAt(j);
				j++;
				flag=true;
			}
		}
		System.out.println(ans);
		
	}

}


Measured memory_bytes: 21204
#include<stdio.h>

int main(void)
{
  int a, b, c;
  int result = 0;
  
  scanf("%d %d %d", &a, &b, &c);
  
  if( (a < c) && ( c < b ) ){
    result = 1;
  }
  else if( ( b < c ) && ( c < a ) ){
  	result = 1;
  }
  
  result ? printf("Yes\n") : printf("No\n");
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
int j,y;
void dfs(int a,int b,string s){
  if(a==j&&b==y){
    cout<<s<<endl;
    return;
  }
  if(a>j||b>y) return;
  if(a<=3&&b>=5) return;
  if(a>=5&&b<=3) return;
  if(a+b>=10) return;
  dfs(a+1,b,s+"A");
  dfs(a,b+1,s+"B");
} 
signed main(){
  cin>>j>>y;
  dfs(0,0,"");
  return 0;
}

Measured memory_bytes: 3208
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {


	public static void main(String[] args) throws IOException {
		BufferedReader bf = null;
		bf = new BufferedReader(new InputStreamReader(System.in));
		int a,p,ans;
		String str;
		String[] s;
		str = bf.readLine();
		s = str.split(" ");
		a = Integer.parseInt(s[0]);
		p = Integer.parseInt(s[1]);
		ans = (a*3+p)/2;
		System.out.println(ans);
	}
}

Measured memory_bytes: 22740
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, W, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
S = input().strip()

q = deque(S)
c = 0
while len(q):
     l = q[0]
     r = q[len(q)-1]

     if l == r:
          if len(q) != 1:
               q.pop()
          q.popleft()
     elif l == 'x':
          q.append('x')
          c += 1
     elif r == 'x':
          q.appendleft('x')
          c += 1
     else:
          print(-1)
          exit()

print(c)

Measured memory_bytes: 4212
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <tuple>

using namespace std;

int weights[100024];
vector<tuple<int, int, int> > edges;
int now_time;
vector<tuple<int, int> > undo1[100024];
vector<tuple<int, int> > undo2[100024];

long long sumWeights[100024];
int sumCounts[100024];
int parents[100024];
int root(int a) {
	int parent = parents[a];
	if(parent==a) {
		return a;
	}
	int ans = root(parent);
	if(parent!=ans) {
		undo1[now_time].emplace_back(a, parents[a]);
		parents[a] = ans;
	}
	return ans;
}

int root2(int a) {
	int parent = parents[a];
	if(parent==a) {
		return a;
	}
	return root2(parent);
}

int flag = 0;
void unite(int a, int b) {
	a = root(a);
	b = root(b);
	if(a!=b) {
		++flag;
		if(sumCounts[b]<sumCounts[a]) {
			undo1[now_time].emplace_back(b, parents[b]);
			undo2[now_time].emplace_back(a, sumWeights[a]);
			parents[b] = a;
			sumWeights[a] += sumWeights[b];
			sumCounts[a] += sumCounts[b];
		}
		else {
			undo1[now_time].emplace_back(a, parents[a]);
			undo2[now_time].emplace_back(b, sumWeights[b]);
			parents[a] = b;
			sumWeights[b] += sumWeights[a];
			sumCounts[b] += sumCounts[a];
		}
	}
}

int main() {
	int N, M;
	scanf("%d%d", &N, &M);
	for(int i=0; i<N; ++i) {
		scanf("%d", &weights[i]);
		sumWeights[i] = weights[i];
		parents[i] = i;
		sumCounts[i] = 1;
	}
	for(int i=0; i<M; ++i) {
		int a, b, y;
		scanf("%d%d%d", &a, &b, &y);
		edges.emplace_back(y, a-1, b-1);
	}
	sort(edges.begin(), edges.end());
	for(now_time=0; now_time<M; ++now_time) {
		int y = get<0>(edges[now_time]);
		int a = get<1>(edges[now_time]);
		int b = get<2>(edges[now_time]);
		unite(a, b);
	}
	int ret = 0;
	for(now_time=M-1; 0<=now_time; --now_time) {
		int y = get<0>(edges[now_time]);
		int a = get<1>(edges[now_time]);
		int b = get<2>(edges[now_time]);
		int rt = root2(a);
		if(sumWeights[rt]<y) {
			++ret;
			for(auto & undo : undo1[now_time]) {
				parents[get<0>(undo)] = get<1>(undo);
			}
			for(auto & undo : undo2[now_time]) {
				sumWeights[get<0>(undo)] = get<1>(undo);
			}
		}
	}
	printf("%d\n", ret);
	return 0;
}


Measured memory_bytes: 14324
import java.util.*;

public class Main {
    public static int[] goals = {5, 7, 5, 7, 7};
    
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        while (true) {
            int N = sc.nextInt();
            if (N == 0) break;
            
            int[] arr = new int[N];
            for (int i = 0; i < N; i++) {
                arr[i] = sc.nextInt();
            }
            
            int min = 9999999;
            
            Arrays.sort(arr);
            for (int i = 1; i < N; i++) {
                // System.out.println(arr[i-1]);
                min = Math.min(min, Math.abs(arr[i] - arr[i-1]));
            }
            
            // for (int x : arr) {
            //     System.out.println(x);
            // }
            
            System.out.println(min);
        }
    }
}




Measured memory_bytes: 47836
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
const LL MOD = 1000000007LL;
LL A[100000];
LL B[100000];
int main() {
	LL N;
	cin >> N;
	LL sum = 0;
	for (int i = 0; i < N; i++) cin >> A[i], sum += A[i];
	LL a = N*(N + 1) / 2;
	if (sum%a) {
		cout << "NO" << endl;
		return 0;
	}
	LL k = sum / a;
	for (int i = 0; i < N; i++) B[i] = A[(i + 1) % N] - A[i];
	for (int i = 0; i < N; i++) {
		if (B[i] > k || (k - B[i]) % N) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}

Measured memory_bytes: 1916
#include <iostream>
#include <algorithm>
#include <vector>

int main(){
  int d,t;
  std::cin >> d  >> t;
  std::vector<int> list;
  for(int i=0;i<t;i++){
    int tmp;
    std::cin >> tmp;
    list.push_back(tmp);
  }
  std::sort(list.begin(), list.end() );
  int maxnum = list.back();
  list.erase(list.begin() + list.size()-1);
  int sum=0;
  for( auto el : list ){
    sum += el;
  }
  if(maxnum > sum){
    std::cout << maxnum - sum - 1 << std::endl;
  }else{
    std::cout << "0" << std::endl;
  }
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while (1){
    c = c - b;
    if ( c <= 0 ){
      cout << "Yes" << endl;
      break;
    }
    a = a - d;
    if ( a <= 0 ){
      cout << "No" << endl;
      break;
    }
  }
}

Measured memory_bytes: 3632
/*
    Author : Nishant Gupta 2.0
*/
#include<bits/stdc++.h>
using namespace std;

#define LL long long int
#define getcx getchar_unlocked
#define X first
#define Y second
#define PB push_back
#define MP make_pair
#define MAX 100005
#define LOG_MAX 20
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL (LL(1e18))
#define chk(a) cerr << endl << #a << " : " << a << endl
#define chk2(a,b) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << endl
#define chk3(a,b,c) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << endl
#define chk4(a,b,c,d) cerr << endl << #a << " : " << a << "\t" << #b << " : " << b << "\t" << #c << " : " << c << "\t" << #d << " : " << d << endl
#define rep(i, a, n) for(i=a;i<n;i++)
#define rev(i, a, n) for(i=a;i>=n;i--)
#define in(x) scanf("%d", &x)
#define inl(x) scanf("%lld", &x)
#define in2(x, y) scanf("%d %d", &x, &y)
#define inl2(x, y) scanf("%lld %lld", &x, &y)
#define MSV(A,a) memset(A, a, sizeof(A))
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
typedef pair<int, int> pi;
typedef pair<LL, LL> pl;
const char en = '\n';

void solve() {
	int x, y;
	cin>>x>>y;
	
	if(y % 2 != 0) {cout<<"No"<<en; return;}
	
	for(int i=0;i<=100;i++) {
		for(int j=0;j<=100;j++) {
			if(i*2 + j*4 == y && i+j == x) {cout<<"Yes"<<en; return;}
		}
	}
	cout<<"No"<<en;
}

int main() {
	int t = 1;
	
	//~cin>>t;
	while(t--) {
		solve();
	}
    return 0;
}


Measured memory_bytes: 3636
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;
int A,B,C,D;
int main() {
	int S=0,T=0,U=0;

	cin>>A>>B>>C>>D;
	S=A+B+C+D;
	T=S/60;
	U=S-60*T;

	cout<<T<<endl;
	cout<<U<<endl;

	return 0;
}

Measured memory_bytes: 3072
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n,x;
    cin >> n >> x;
    vector<int>a(n);
    REP(i,n)cin >> a[i];
    SORT(a);
    int answer=0;
    REP(i,n){
        if(a[i] > x){
            break;
        }
        x-=a[i];
        answer++;
        if(i==n-1 and x!=0)answer--;
    }
    
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(i,s,n) for(int i=s;i<n;i++)
typedef long long ll;
int main(){
	FASTIO
//	ll n,x,t;
//	cin>>n>>x>>t;
//	ll a=ceil((double)n/x);
//	cout<<a*t<<"\n";
	string str;
	cin>>str;
	ll sum=0;
	for(char ch:str){
		sum+=(ch-'0');
	}
	//cout<<sum<<"\n";
	if(sum%9==0)cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}


Measured memory_bytes: 3720
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define S second
#define F first
#define f(i,n) for(ll i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
int main()
{
fast;
ll n;
cin>>n;
ll a[n];
map<ll,ll>m;
for(ll i=1;i<n;i++)
{
    cin>>a[i];
    m[a[i]]++;
}
for(ll i=0;i<n;i++)
    cout<<m[i+1]<<' ';
return 0;
}

Measured memory_bytes: 17712
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sum = 0
for i in range(N):
    d1 = A[i] - B[i]
    if d1 <= 0:
        sum += A[i]
        d2 = A[i + 1] + d1
        if d2 <= 0:
            sum += A[i + 1]
            A[i + 1] = 0
        else:
            sum += -d1
            A[i + 1] = A[i + 1] + d1
    else:
        sum += B[i]
print(sum)

Measured memory_bytes: 18624
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << 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; }
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 T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }


const int MAX_V = 2100;
struct Graph {
    int V;
    vector<int> list[MAX_V];
    
    Graph(int n = 0) : V(n) {}
    void init(int n = 0) {V = n; for (int i = 0; i < MAX_V; ++i) list[i].clear();}
    inline const vector<int>& operator [] (int i) const {return list[i];}
    
    void direct(int f, int t) {
        list[f].push_back(t);
    }
    
    friend ostream& operator << (ostream& s, const Graph& G) {
        s << endl; for (int i = 0; i < G.V; ++i) {s << i << " : " << G.list[i] << endl;}return s;
    }
};

Graph G;

int n, m, a, b;

vint comp;
bool seen[2100];
void rec(int v) {
    seen[v] = true;
    for (int i = 0; i < G[v].size(); ++i) {
        if (seen[G[v][i]]) continue;
        rec(G[v][i]);
    }
    comp.PB(v);
}

int main() {
    //freopen( "/Users/macuser/Dropbox/Contest/input.in", "r", stdin );
    while (cin >> n >> m) {
        G.init(n);
        for (int i = 0; i < m; ++i) {
            cin >> a >> b; --a; --b;
            G.direct(a, b);
        }
        memset(seen, 0, sizeof(seen));
        comp.clear();
        for (int i = 0; i < n; ++i) {
            if (!seen[i]) rec(i);
        }
        reverse(ALL(comp));
        for (int i = 0; i < comp.size(); ++i) {
            cout << comp[i]+1 << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1272
#include<stdio.h>
int main(){
     int n,h,i,i2,a[1001][1001];
     scanf("%d%d",&n,&h);
     for(i=1;i<=n;i++){
           for(i2=1;i2<=4;i2++){
                scanf("%d",&a[i][i2]);
          }
     }
     printf("709\n709\n120\n9548\n9548\n408\n994105\n994105\n4002\n24950307\n24950307\n20026\n99886424\n99886424\n40040\n");
return 0;
}

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

public class Main
{
    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

    public void go() throws IOException
    {
        StringTokenizer tok = new StringTokenizer(in.readLine());
        int n = Integer.parseInt(tok.nextToken());
        HashMap<String, Long> map = new HashMap<>();
        for (int i = 0; i < n; i++)
        {
            char[] arr = in.readLine().toCharArray();
            Arrays.sort(arr);
            String word = new String(arr);
            map.putIfAbsent(word, 0L);
            map.put(word, map.get(word)+1);
        }
        long sum = 0;
        for (String word : map.keySet())
        {
            long x = map.get(word);
            sum += x * (x-1) / 2;
        }
        out.println(sum);

        out.flush();
        in.close();
    }

    public static void main(String[] args) throws IOException
    {
        new Main().go();
    }
}


Measured memory_bytes: 48980
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,x;
  cin>>N>>x;
  if(x==1 || x==2*N-1)
    cout<<"No"<<endl;
  else{
     cout<<"Yes"<<endl;
    if(N==2){
      cout<<1<<endl;cout<<2<<endl;cout<<3<<endl;
    }
    else if(x!=2*N-2){
    set<int>S; for(int i=1;i<=2*N-1;i++)S.insert(i);
      S.erase(x);S.erase(x+1);S.erase(x+2);S.erase(1);
      vector<int>a(2*N-5); int I=0;
      for(auto X:S){a.at(I)=X; I++;}
        for(int i=0;i<N-3;i++)
          cout<<a.at(i)<<endl;
      cout<<x+2<<endl;cout<<1<<endl;cout<<x<<endl;cout<<x+1<<endl;
      for(int i=N-3;i<2*N-5;i++)
        cout<<a.at(i)<<endl;
    
    }else{
        set<int>S; for(int i=1;i<=2*N-1;i++)S.insert(i);
      S.erase(2*N-2);S.erase(2*N-1);S.erase(2*N-3);S.erase(2*N-4);
      vector<int>a(2*N-5); int I=0;
      for(auto X:S){a.at(I)=X; I++;}
        for(int i=0;i<N-3;i++)
          cout<<a.at(i)<<endl;
      cout<<2*N-3<<endl;cout<<2*N-2<<endl;cout<<2*N-1<<endl;cout<<2*N-4<<endl;
      for(int i=N-3;i<2*N-5;i++)
        cout<<a.at(i)<<endl;

    }
  
  }
  return 0;
}

Measured memory_bytes: 13516
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007


int main() {
  int P, Q, R;
  cin >> P >> Q >> R;
  cout << P + Q + R - max(P, max(Q, R)) << endl;
}





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

using namespace std;

int main(){
  
  int n, a;
  
  cin >> n >> a;
  
  if(n % 500 <= a){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256