akhauriyash/Code-Regression huggingface dataset:
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <queue>
#include <math.h>
#include <map>

#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;


int main() {
    FASTIO
    int n,m;cin >> n >> m;
    vector<pair<long long,long long>> v(n);
    for(int i=0;i<n;i++){
        cin >> v[i].first >> v[i].second;
    }
    sort(v.begin(),v.end());
    int cnt=0;
    long long total=0;
    while(m > 0){

        if(m >= v[cnt].second){
            total += v[cnt].second*v[cnt].first;
            m -= v[cnt].second;
            cnt++;
        }
        else{
            total += m*v[cnt].first;
            m = 0;
        }
    }
    cout << total;
}

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

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

	int dp[3];
	cin >> dp[0] >> dp[1] >> dp[2];
	for (int i = 1; i < n; ++i) {
		int tmp[3] = {dp[0], dp[1], dp[2]};
		int a, b, c;
		cin >> a >> b >> c;
		dp[0] = max(tmp[1], tmp[2]) + a;
		dp[1] = max(tmp[2], tmp[0]) + b;
		dp[2] = max(tmp[0], tmp[1]) + c;
	}
	int ans = max({dp[0],dp[1],dp[2]});

	cout << ans << endl;
	return 0;
}

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  
  if(a==5&&b==5&&c==7||a==5&&b==7&&c==5||a==7&&b==5&&c==5){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}


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

using namespace std;

#define ll long long int
#define MOD 1000000007
#define mt make_tuple
#define eb emplace_back
#define error(args...){string _s = #args; replace(_s.begin(),_s.end(),',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it,args);}
void err(istream_iterator<string> it){}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args){cerr<<*it<<" = "<<a<<endl; err(++it,args...);}



int main()
{
    ll t,i,j,k,l,n,m;
    vector<ll> V;
    cin>>k>>l>>j;
    V.push_back(j);
    V.push_back(k);
    V.push_back(l);
    sort(V.begin(),V.end());
    cout<<min(V[2]-V[0],min(V[2]+V[1]-2*V[0],2*V[2]-V[0]-V[1]));
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin python3
# -*- coding: utf-8 -*-

from collections import Counter

def main():
    mod = 10**9+7
    N = int(input())
    S = list(input())
    S = Counter(S)
    ret = 1
    for i,c in S.items():
        ret *= (c+1)
        ret %= mod
    print((ret-1)%mod)

if __name__ == '__main__':
    main()

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

int N;
int power[] = {1,2,4,8,16,32,64};
int ans = 1;

int main() {
  cin >> N;
  
  if ( N >= power[6] ) {
    ans = power[6];
  }
  else if (N >= power[5] ) {
    ans = power[5];
  }
  else if (N >= power[4] ) {
    ans = power[4];
  }
  else if (N >= power[3] ) {
    ans = power[3];
  }
  else if (N >= power[2] ) {
    ans = power[2];
  }
  else if (N >= power[1] ) {
    ans = power[1];
  }
  else {
    ans = power[0];
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def modpow(x, n, m):
    res = 1
    while n > 0:
        if n % 2 == 1:
            res = (res * x) % m
        x = (x * x) % m
        n >>= 1
    return res

def combination(n, r, m):
    res = 1
    r = min(r, n - r)

    for i in range(1, r + 1):
        res = res * (n - r + i) % m
        res = res * modpow(i, m - 2, m) % m
    return res

mod = 10**9 + 7
n, a, b = map(int, input().split())
total = modpow(2, n, mod) - 1

total = (total - combination(n, a, mod) - combination(n, b, mod)) % mod

print(total)

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

int main() {
	string s,t;
	cin >> s >> t;
	int ans = 0;
	rep(i,3) {
		if(s[i]==t[i]) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

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

    private void run(){
        int N = sc.nextInt();
        int M = sc.nextInt();

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

        if(N < 0)N = -1;

        System.out.println(N);
        sc.close();
    }
}

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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] tmpArray = br.readLine().split(" ");
		int a = Integer.parseInt(tmpArray[0]);
		int b = Integer.parseInt(tmpArray[1]);
		
		if(b == 1){
			System.out.println(0);
			return;
		}
		
		for(int i = 1; ; i++){
			if((a - 1)*(i - 1) + a >= b){
				System.out.println(i);
				return;
			}
		}
	}

}


Measured memory_bytes: 22228
#include <bits/stdc++.h>
using namespace std;
bool vis[105][105];
char s[105][105];
int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	for(int i=1;i<=n;i++){
		scanf("%s", s[i]+1);
	}
 
	for(int i=1;i<=n;i++){
		bool ok = 1;
		for(int j=1;j<=m;j++){
			if(s[i][j] == '#') ok = 0;
		}
		if(!ok) continue;
		for(int j=1;j<=m;j++){
			vis[i][j] = 1;
		}
	}
 
	for(int i=1;i<=m;i++){
		bool ok = 1;
		for(int j=1;j<=n;j++){
			if(s[j][i] == '#') ok = 0;
		}
		if(!ok) continue;
		for(int j=1;j<=n;j++){
			vis[j][i] = 1;
		}
	}
 
	for(int i=1;i<=n;i++){
		bool ok = 0;
		for(int j=1;j<=m;j++){
			if(!vis[i][j]) printf("%c", s[i][j]), ok = 1;
		}
		if(ok) printf("\n");
	}
}

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

using namespace std;

int main(){
    int N,M;
    string s[100],t[100];
    cin >> N;
    for (int i=0;i<N;i++) cin >> s[i];
    cin >> M;
    for (int i=0;i<M;i++) cin >> t[i];

    int ans=0;
    for (int i=0;i<N;i++){
	int S=0,T=0;
	for (int j=0;j<N;j++){
	    if (s[i] == s[j]) S++;
	}
	for (int j=0;j<M;j++){
	    if (s[i] == t[j]) T++;
	}
	if ((S-T) > ans) ans=S-T;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>

#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)
#define all(a) a.begin() , a.end()
#define F first
#define S second

using namespace std;
using ll = long long;
using namespace __gnu_pbds;

template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 3e5 + 10 , inf = 2e9 + 7;
const ll INF = 1e18 ,   mod = 1e9+7 , P = 6547;

void solve() {
    int n;
    cin >> n;
    int mx = 0;
    ll ans = 0;
    for(int i = 1; i <= n; i ++) {
        int x;
        cin >> x;
        if(mx > x) {
            ans += mx - x;
        }
        mx = max(mx , x);
    }
    cout << ans;
}
/*
*/
main() {
    ios;
    int tt = 1;
    //cin >> tt;
    while(tt --) {
        solve();
    }
    return 0;
}


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

using namespace std;

typedef long long int ll;

void solve()
{
	ll a, b, v, w, x;
	cin >> a >> v >> b >> w >> x;
	ll sum = abs(b - a);
	for(int i = 0; i < x; i++)
	{
		sum += w - v;
		if(sum <= 0)
		{
			cout << "YES\n";
			return;
		}
	}
	cout << "NO\n";
}

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



Measured memory_bytes: 3628
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner input =new Scanner(System.in);
		int n=input.nextInt();
		int[] arr=new int[n];
		int[] temp=new int[arr.length];
		int tem,c=0;;
		for(int i=0;i<arr.length;i++)
		{
			arr[i]=input.nextInt();
			temp[i]=arr[i];
		}
		input.close();
		Arrays.sort(temp);	
          
		for(int j=0;j<arr.length;j++)
		{
			if(arr[j] != temp[j]) 
			{
				c++;
			}
		
	   }

		if(c<3) 
		{
			System.out.println("YES");
		}
		else
		{
			System.out.println("NO");
		}	
		System.exit(0);
		
	}
}


Measured memory_bytes: 35888
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e5+1;
int n, m;
vector<int>adj[N];

int dp[N]={};

void dfs(int x, int e)
{
	dp[x]=1;
	for(auto y:adj[x])
	{
		if(y!=e)
		{
			dfs(y, x);
			dp[x]=(dp[x]*(dp[y]+1))%m;
		}
	}
}
void dfs2(int x, int e, int preva)
{
    dp[x]=(dp[x]*(preva+1))%m;
    int l=adj[x].size();
    int pref[l], suf[l];
    int pp=1, ps=1;
    for(int i=0; i<l; ++i)
    {
        int y=adj[x][i];
        if(y!=e)
        {
            pp=(pp*(dp[y]+1))%m;
        }
        pref[i]=pp;
    }
    for(int i=l-1; i>=0; --i)
    {
        int y=adj[x][i];
        if(y!=e)
        {
            ps=(ps*(dp[y]+1))%m;
        }
        suf[i]=ps;
    }
    for(int i=0; i<l; ++i)
    {
        int y=adj[x][i];
        if(y!=e)
        {
            int nexta=1;
            if(i!=0)
                nexta=(nexta*pref[i-1])%m;
            if(i!=l-1)
                nexta=(nexta*suf[i+1])%m;
            nexta=(nexta*(preva+1))%m;
            dfs2(y, x, nexta); 
        }
    }
}

int32_t main()
{
	cin>>n>>m;
	for (int i = 0; i < n-1; ++i)
	{
		int u, v;
		cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	dfs(1, 0);
	dfs2(1, 0,(int) 0);
	
	for(int i=1; i<=n; ++i)
		cout<<dp[i]<<'\n';
}

Measured memory_bytes: 21248
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 k = Integer.parseInt(tok.nextToken());
        int x = Integer.parseInt(tok.nextToken());
        for (int i = x-k+1; i <= x+k-1; i++)
        {
            out.print(i);
            if (i != x+k-1)
                out.print(" ");
        }

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

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


Measured memory_bytes: 22612
#include"bits/stdc++.h"
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;
int64_t i,j,k;//preparation for
int main(){
    int a,b;
    cin>>a;
    b=pow(a,2)+a+1;
    cout<<a*b;
    
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  double a;
  cin >> a;
  
  cout << 3.0*a*a << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////



int main() {
	
	ll N;
	cin >> N;
	vector<pair<ll, ll>> R(N + 1);


	repn(i, N) {
		ll x, l;
		cin >> x >> l;
		R[i] = { x + l,x - l };
	}

	sort(++R.begin(), R.end());

	ll ans = 0;
	ll bound = -INF;

	repn(i, N) {
		if (R[i].second >= bound) {
			ans++;
			bound = R[i].first;
		}
	}

	cout << ans;
	system("PAUSE");
}


Measured memory_bytes: 2040
#include <stdio.h>
#include <stdlib.h>
#define N 200001

int asc(const void* a, const void* b) {
    return *(int*)a - *(int*)b;
}

int main(void) {
	int n, k;
	int h[N];
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; i++)
        scanf("%d", &h[i]);
    qsort(h, n, sizeof(int), asc);
    long long sum = 0;
    for (int i = 0; i < n - k; i++)
        sum += h[i];
    printf("%lld\n", sum);
}

Measured memory_bytes: 1788
import java.util.*;

public class Main{
    
    /////////////////////////////////
    //                             //
    //  @ Author: Ali Mohammed Ali //
    //                             //
    /////////////////////////////////
    
    public static void main(String[] args) {
        
        Scanner in = new Scanner(System.in);
        
        int A,B,C;
        int sum5 = 0;
        int sum7 = 0;
        
        A = in.nextInt();
        B = in.nextInt();
        C = in.nextInt();
        
        if (A == 5)
            sum5++;
        else if (A == 7)
            sum7++;
        
        if (B == 5)
            sum5++;
        else if (B == 7)
            sum7++;
        
        if (C == 5)
            sum5++;
        else if (C == 7)
            sum7++;
        
        if (sum5 == 2 && sum7 == 1)
            System.out.println("YES");
        else
            System.out.println("NO");
  
    } // End of Main method
    
  } // End of class

Measured memory_bytes: 27100
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
char c,h;
int hs(char x,char y)
{
	char zt;
	if(x>y) zt='>';
	if(x<y) zt='<';
	if(x==y) zt='=';
	return zt;
}
int main()
{
    cin>>c>>h;
    cout<<char(hs(c,h))<<endl;
    
    return 0;
}

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

using namespace std;

int main() {
    long long x = 0;
    cin >> x;

    int counter = 0;
    long long sum = 100;

    while(sum < x){
        sum *= 1.01;
        counter ++;
    }
    
    cout << counter << endl;
    return 0;
}

Measured memory_bytes: 3652
#include <math.h>
#include <time.h>
#include <ctype.h>
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include<iomanip>

#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)

using namespace std;

ll power(ll a, ll b, ll m)
{
	if (b == 0)
		return(1);
	ll sol = power(a, b / 2, m);
	sol = (sol * sol) % m;
	if (b % 2 == 1)
		sol = (sol * a) % m;
	return(sol);
}

ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	else
	{
		return gcd(b, a % b);
	}
}
int n;
ll k,sum;
vector <ll>a;
ll  f[200005];
bool chk(ll val)
{
	vector<ll>cnt;
	cnt.clear();
	for (int i = 0; i < n; i++)
	{
		cnt.pb(val / f[i]);
	}
	sort(cnt.begin(), cnt.end());
	ll gg = 0;
	for (int i = 0; i < n; i++)
	{
		if (a[i] - cnt[i] >= 0)
			gg += a[i] - cnt[i];
	}
	if (gg <= k)
		return true;
	return false;
}
void solve()
{
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		ll x;
		cin >> x;
		a.pb(x);
		sum += a[i];
	}
	for (int i = 0; i < n; i++)
	{
		cin >> f[i];
	}
	sort(a.begin(), a.end());
	ll lo = 0, hi = 1000000000000000000, mid, ans = 0;;
	while (lo <= hi)
	{
		mid = (lo + hi) / 2;
		if (chk(mid))
		{
			ans = mid;
			hi = mid - 1;
		}
		else
			lo = mid + 1;
	}
	cout << ans;
}
int main()
{
	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

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

 
int main() {
  int a,b,c,d,winner=0;
  cin >>a>>b>>c>>d;
  for(int i=0;i<1000;i++){
    c-=b;
    if(c<=0){
      cout << "Yes" << endl;
      break;
    }
    a-=d;
    if(a<=0){
      cout << "No" << endl;
      break;
    }
  }
      
}

Measured memory_bytes: 3632
//g++ -std=c++17 -Wshadow -Wall -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g PROGRAM -o OUTPUT -DLOCAL -lasan -lubsan
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define alli(a, n, k) (a + k), (a + n + k)
#define FP(i, a, b, k) for (__typeof(a) i = a; i < b; i += k)
#define FS(i, a, b, k) for (__typeof(a) i = a; i > b; i -= k)
#define IT(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template <class T>
inline T gcd(T x, T y)
{
    if (!y)
        return x;
    return gcd(y, x % y);
}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;


inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

vector<string> split(char d,string s)
{
    stringstream ss(s);
    string t;
    vector<string> words;
    while(getline(ss,t,d))
    {
        words.pb(t);
    }

    return words;
}
void constructXOR(VII &A, int n)
{
    // calculate xor of array
    int XOR = 0;
    for (int i = 0; i < n; i++)
        XOR ^= A[i];

    // update array
    for (int i = 0; i < n; i++)
        A[i] = XOR ^ A[i];
}
int main(int argc, char *argv[])
{
#ifdef LOCAL
    auto start = chrono::high_resolution_clock::now();
#endif
    
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    VII arr(n);
    for(auto &x:arr)
        cin >> x;

    constructXOR(arr, n);
    for(auto x:arr)
        cout << x << ' ';

#ifdef LOCAL
    auto end = chrono::high_resolution_clock::now();
    double time_taken =
        chrono::duration_cast<chrono::nanoseconds>(end - start).count();

    time_taken *= 1e-9;

    cerr << "\nTime taken by program is : " << fixed
         << time_taken << setprecision(9);
    cerr << " sec" << endl;
#endif
    return 0;
}


Measured memory_bytes: 3980
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    it.next();
    let w = std::mem::size_of::<usize>() * 8;
    let mut dp = vec![0usize; (2000 * 2000 + 1 + w - 1) / w];
    let mut sum = 0;
    dp[0] = 1;
    for s in it {
        let a: usize = s.parse().unwrap();
        let (q, r) = (a / w, a % w);
        if r == 0 {
            for i in (0..(sum / w + 1)).rev() {
                dp[i + q] |= dp[i];
            }
        } else {
            for i in (0..(sum / w + 1)).rev() {
                dp[i + q + 1] |= dp[i] >> (w - r);
                dp[i + q] |= dp[i] << r;
            }
        }
        sum += a;
    }
    let mut ans = (sum + 1) / 2;
    loop {
        let (q, r) = (ans / w, ans % w);
        if (dp[q] >> r) & 1 == 1 {
            println!("{}", ans);
            return;
        }
        ans += 1;
    }
}

fn main() {
    run();
}


Measured memory_bytes: 4476
/* Date: 01/04/2020
 * Author: @codingoo
 * Problem Name: Bounding
 * Platform: AtCoder
 */
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    int n, x;
    cin >> n >> x;
    vi d(n+1);
    d[0] = 0;
    rep(i, 0, n) {
        int val;
        cin >> val;
        d[i+1] = d[i] + val;
    }
    int cnt = 0;
    rep(i, 0, n+1) {
        if (d[i] <= x)
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
W,H,N = gets.split.map(&:to_i)
x_left = 0
x_right = W
y_bottom = 0
y_top = H
N.times do |i|
    x,y,a = gets.split.map(&:to_i)
    case a
    when 1
        x_left = x if x_left < x
    when 2
        x_right = x if x < x_right
    when 3
        y_bottom = y if y_bottom < y
    when 4
        y_top = y if y < y_top
    end
end
x = x_right - x_left
y = y_top - y_bottom
x = 0 if x < 0
y = 0 if y < 0
puts x*y

Measured memory_bytes: 1788
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
const long long inf=1e9+7;
const long long mod=1e9+7;
const int64_t CYCLES_PER_SEC=2800000000;
//
inline uint32_t Xor128(){
	static uint32_t x=123456789;
	static uint32_t y=362436069;
	static uint32_t z=521288629;
	static uint32_t w=88675123;
	uint32_t t=x^(x<<11);
	x=y;y=z;z=w;
	return w=(w^(w>>19))^(t^(t>>8));
}
struct Timer{
	int64_t start;
	Timer(){reset();}
	void reset(){start=getcycle();}
	void plus(double a){start-=(a*CYCLES_PER_SEC);}
	inline double get(){return (double)(getcycle()-start)/CYCLES_PER_SEC;}
	inline int64_t getcycle(){
		uint32_t low,high;
		__asm__ volatile ("rdtsc":"=a"(low),"=d"(high));
		return ((int64_t)low)|((int64_t)high<<32);
	}
};
//
int n;
int l[2001];
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>l[i];
	}
	sort(l,l+n);
	l[n]=1e9+7;
	int ans=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			ans+=(lower_bound(l,l+n,l[i]+l[j])-l)-1-j;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
n  =int(input())
s = input()
x = 0
c = 0
x1 = 0
t = []
for i in s:
	if i=='I':
		c+=1
	if c>x:
		x =c
	elif i=='D':
		c-=1
	if c>x1:
		x1=c

	t.append(max(x1,x))
print(max(t))


Measured memory_bytes: 9124
k, a, b = map(int, input().split())
breakonly = k + 1
if a <= b-2:
    k = k + 1 - a
    ans = k // 2 * (b - a)
    ans += max(0, k - (k // 2 * 2)) 
    print(ans + a)
else:
    print(breakonly)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;

int main()
{

    int n;
    long long int k;
    cin>>n>>k;

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

    set<int> s;
    vector<int> v;

    int town=0;

    while(s.find(town)==s.end())
    {
        s.insert(town);
        v.push_back(town);
        town=a[town];
    }

    int start=-1,end=v.size();

    for(int i=0; i<v.size(); i++)
    {
        if(v[i]==town)
        {
            start=i;
            break;
        }
    }

    if(k<v.size())
    {
        cout<<v[k]+1<<endl;
    }
    else
    {
        int diff=end-start;
        long long int r=(k-start)%diff;
        cout<<v[start+r]+1<<endl;
    }

    return 0;
}


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

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  string S;
  cin >> S;
  int cnt1[N], cnt2[N];
  cnt1[0] = (S[0] == '#');
  cnt2[N-1] = (S[N-1] == '.');
  for(int i=1; i<N; ++i){
   cnt1[i] = (S[i] == '#') + cnt1[i-1]; 
  } 
  for(int i=N-2; i>=0; --i){
    cnt2[i] = (S[i] == '.') + cnt2[i+1]; 
  }
  int res = 1e9;
  for(int i=0; i<N-1; ++i){
       res = min(res, cnt1[i]+cnt2[i+1]);
  }
  res = min({res, cnt1[N-1], cnt2[0]});
  cout << res << "\n";
  return 0;
}

Measured memory_bytes: 2196
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<map>
using namespace std;
int main()
{
    int n,i,t=0,c=0,a[100005];
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    for(i=0; i<n; i++)
    {
        if(a[i]==a[i+1])
        {
            c++;
        }
        else
        {
            if(c%2==0)
                t++;
            c=0;
        }



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


Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 100000000
#define INFLL 100000000000
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};



int A, B;

int main () {
  cin >> A >> B;

  cout << ((B * 2 > A) ? 0 : (A - 2 * B)) << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main(){
    long long n,m;
    cin >> n >> m;
    vector<long long> da(n);
    for(int i=0;i<n;i++){
        cin >> da[i];
    }
    vector<long long> su(n+1,0);
    map<long long,long long> co;
    co[0]=1;
    for(int i=0;i<n;i++){
        su[i+1]=su[i]+da[i];
        if(co.count(su[i+1]%m)){
            co[su[i+1]%m]++;
        }
        else{
            co[su[i+1]%m]=1;
        }
    }
    long long ans=0;
    for(auto i:co){
        ans=(long long)ans+i.second*(i.second-1)/2;
    }
    cout << ans << endl;

}

Measured memory_bytes: 5760
def bottom(lv, k):
    if lv == 0:
        return 1
    n = 2**(lv+2) - 3
    prev_pat = 2**lv-1
    if k-1 == 0:
        return 0
    elif 0 < k-1 < n//2:
        return bottom(lv-1, k-1)
    elif k-1 == n//2:
        return prev_pat + 1
    elif n//2 < k-1 < n-1:
        return prev_pat + 1 + bottom(lv-1, k-(n//2+1))
    elif k-1 == n-1:
        return 2**(lv+1)-1

n, k = list(map(int, input().split()))

print(bottom(n, k))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int n,x,l,ans=1,i,p=0;
	scanf("%d%d",&n,&x);
	for(i=0;i<n;i++){
		scanf("%d",&l);
		p+=l;
		if(p<=x){
			ans++;
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Main sol = new Main();
		System.out.println(sol.solve());
	}

	private int solve() {
		int MOD = (int)1e9+7;
		Scanner sc  = new Scanner(System.in);
		//String S = sc.nextLine();
		//int N = Integer.parseInt(""+S.charAt(0));
		//int M = Integer.parseInt(""+S.charAt(2));
		int N = sc.nextInt();
		int M = sc.nextInt(); 
		sc.nextLine();
		StringBuilder buf = new StringBuilder();
		char [][] grid = new char[N+1][M+1];
		for(int i=0;i<N;i++){
			String line = sc.nextLine();
			for(int j=0;j<line.length();j++){
				grid[i+1][j+1] = line.charAt(j);
			} 
		}

		int [][] dp = new int[N+1][M+1];
		dp[N][M] = 1;
		for(int i=N;i>=1;i--){
			for(int j=M;j>=1;j--){
				if (i==N&& j==M) continue;
				if (grid[i][j]=='#') dp[i][j]=0;
 				else dp[i][j] = ((i==N ? 0 : dp[i+1][j]) + (j==M ? 0 : dp[i][j+1]))%MOD; 
			}
		}


		return dp[1][1];

	}

	private void print(int N, int M, char[][] grid) {
		for(int i=1;i<=N;i++){
			for(int j=1;j<=M;j++){
				System.out.printf("%c", grid[i][j]);
			}
			System.out.println();
		}
	}

}

Measured memory_bytes: 50836
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define EPS 1e-10
using namespace std;
typedef long long llong;
#define N 105000
int main() {
	vector<bool>f(N, true);
	f[0] = false;
	f[1] = false;
	vector<int>prime;
	for (int i = 2; i <= sqrt(N); i++) {
		if (f[i]) {
			for (int j = 2; i*j < N; j++) {
				f[i*j] = false;
			}
		}
	}
	for (int i = 0; i < N; i++) {
		if (f[i]) {
			prime.push_back(i);
		}
	}

	int n, p;
	while (cin >> n >> p, p != -1) {
		auto it = upper_bound(prime.begin(), prime.end(), n);
		vector<int>ans(10000,100000000);

		for (int cnt = 0, i = 0; i < 100; i++) {
			for (int j = i; j < 100; j++) {
				ans[cnt++] = *(it + i) + *(it + j);
			}
		}
		sort(ans.begin(), ans.end());

		cout << ans[p - 1] << endl;


	}
	return 0;
}

Measured memory_bytes: 3136
N,K = map(int, input().split())
S = list(input())
target = S[K-1]
if target == "A":
    S[K-1] = "a"
elif target == "B":
    S[K-1] = "b"
else:
    S[K-1] = "c"

for str in S:
    print(str, end="")


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
public class Main {
	public static void main(final String[] args){
    
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = 0;
    if(a % 2 == 0){
        b = a/2;
    }else{
        b = a/2 + 1;
    }

    System.out.println((double)b/a);


    
    


    


    
    


    
	}
}

Measured memory_bytes: 23252
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

ll Max=-1,Min=1e9+1;
       
int main(){
    ll b,x=0,y=0,n,m,k,w,sum=0;
    string s,t;
    bool f=true;
    cin >> n >> k;
    VL a(n);
    rep(i,n){
        cin >> a[i];
    }
    sort(ALL(a));
    rep(i,n-k+1){
        if(Min > a[i+k-1]-a[i])
            Min = a[i+k-1]-a[i];
    }
    cout << Min << endl;
    return 0;
}



Measured memory_bytes: 1024
#include<stdio.h>
int a,imput[10],x1,x2=0,i,flg=1;
int main(void)
{
    scanf("%d",&a);
    for(;a>0;a--)
    {
        for(i=0;i<10;i++)
        {
           scanf("%d",&imput[i]);
        }
        x1=imput[0];
        for(i=1;i<10;i++)
        {
            if(x1<imput[i])
            {
                x1=imput[i];
            }else if(x2==0)
                {
                    x2=imput[i];
                }
             else if(x2<imput[i])
                {
                    x2=imput[i];
                }
                else {printf("NO\n");break;}
        }
        if(i==10){printf("YES\n");}
        func();
    }
    return 0;
}
void func(void)
{
    x1=0;
    x2=0;
    for(i=0;i<10;i++)
    {
        imput[i]=0;
    }
}

Measured memory_bytes: 580
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < (i##_MACRO); i++)
#define RANGE(i, a, b) for(int i = (a), i < (b), i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), a + n
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

const int MAX = 10000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if(n < k)
		return 0;
	if(n < 0 || k < 0)
		return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

double degree2radian(double degree) {
	return degree * PI / 180;
}

int main() {
	int x, y;
	scanf("%d %d", &x, &y);

	double nx, ny;
	nx = (2 * y - x) / 3.0;
	ny = y - 2 * nx;

	if(abs(nx - static_cast<int>(nx)) > EPS ||
	   abs(ny - static_cast<int>(ny)) > EPS) {
		puts("0");
		return 0;
	}

	COMinit();

	printf("%lld\n", COM(static_cast<int>(nx) + static_cast<int>(ny),
						 static_cast<int>(ny)));

	return 0;
}

Measured memory_bytes: 234624
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var d = new Dictionary<ulong, int>();
        string[] line = Console.ReadLine().Trim().Split(' ');
        var h = int.Parse(line[0]);
        var w = int.Parse(line[1]);
        var n = int.Parse(line[2]);
        for (int i = 0; i < n; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var a = int.Parse(line[0]) - 1;
            var b = int.Parse(line[1]) - 1;
            putDict(d, h, w, a, b);
        }
        var ret = new long[10];
        var rsum = 0;
        foreach (var x in d)
        {
            ret[x.Value]++;
            rsum++;
        }
        ret[0] = (long)(w - 2) * (h - 2) - rsum;
        foreach (var x in ret) Console.WriteLine(x);
    }
    public static void putDict(Dictionary<ulong, int> d, int h, int w, int a, int b)
    {
        if (a - 2 >= 0)
        {
            if (b - 2 >= 0) putDict2(d, a - 2, b - 2);
            if (b - 1 >= 0 && b + 1 < w) putDict2(d, a - 2, b - 1);
            if (b + 2 < w) putDict2(d, a - 2, b);
        }
        if (a - 1 >= 0 && a + 1 < h)
        {
            if (b - 2 >= 0) putDict2(d, a - 1, b - 2);
            if (b - 1 >= 0 && b + 1 < w) putDict2(d, a - 1, b - 1);
            if (b + 2 < w) putDict2(d, a - 1, b);
        }
        if (a + 2 < h)
        {
            if (b - 2 >= 0) putDict2(d, a, b - 2);
            if (b - 1 >= 0 && b + 1 < w) putDict2(d, a, b - 1);
            if (b + 2 < w) putDict2(d, a, b);
        }
    }
    public static void putDict2(Dictionary<ulong, int> d, int a, int b)
    {
        var nk = (ulong)a * 100000000000 + (ulong)b;
        //var nk = (ulong)a * 0x9ddfea08eb382d69 + (ulong)b;
        //var v = 0;
        //d.TryGetValue(nk, out v);
        //Console.WriteLine(nk);
        //d[nk] = v + 1;
        if (d.ContainsKey(nk)) d[nk]++;
        else d[nk] = 1;
    }
}

Measured memory_bytes: 58812
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;


#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pii pair<int,int>
#define pf push_front
#define mp make_pair
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%lld",&t)
#define p(t) printf("%lld\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define bits(x) __builtin_popcountll(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<pii,vector<pii>,greater<pii> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define spitr set<pii>:: iterator
#define mitr map<int,int>:: iterator

int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}


typedef tree<pii, null_type, less<pii>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;


#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

const int N=2e5+5;
int dp[N];

int32_t main()
{
	fast;
	int n,k;cin>>n>>k;
	vip v(k);
	for(int i=0;i<k;i++)
		cin>>v[i].ff>>v[i].ss;

	dp[n]=1;
	for(int i=n-1;i>=1;i--)
	{
		for(int j=0;j<k;j++)
		{
			int l=v[j].ff;
			int r=v[j].ss;

			if(i+l>n)
				continue;
			int st=i+l;
			int en=min(n,i+r);
			int num=(dp[st]-dp[en+1]+BIG)%BIG;
			dp[i]+=num,dp[i]%=BIG;

		}
		dp[i]+=dp[i+1];
		dp[i]%=BIG;
	}

	int ans=(dp[1]-dp[2]+BIG)%BIG;

	cout<<ans<<endl;
}


Measured memory_bytes: 5216
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = list(inputs[0])
    min_diff = -1
    for i in range(0, len(S)-2):
        value = int(S[i] + S[i+1] + S[i+2])
        diff = abs(753 - value)
        if min_diff == -1 or diff < min_diff:
            min_diff = diff
    return min_diff


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3316
/// Bismillahir Rahmanir Rahim
//Author: Tanvir Hussain
//ICE,NSTU
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

using namespace std;

const long long MOD = 1000000007;
#define SET(x) memset(x, 0, sizeof(x))
#define SET2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define SETBOOL(x) memset(x,false,sizeof(x))
#define CLR(x) memset(x, -1, sizeof(x))
#define mp make_pair
#define PII pair<int, int>
#define pf printf

#define sf scanf

#define ALL(x) x.begin(),x.end()
#define pb push_back

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define np std::string::npos
#define for0(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=n-1;i>=0;i--)
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define cases(cs,t) for(int cs=1;cs<=t;cs++)
#define PI acos(-1)
#define no1 __builtin_popcount
#define BOUNDARY(i, j) ((i >= 0 && i < row) && (j >= 0 && j < column))
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const int maxx=100005;

//this fuction sorts vector pair according to first element in descending order.
bool sortinrev(const pair<int,int> &a,const pair<int,int> &b)
{
    return a.first>b.first;
}

template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}
double sq(double x) {return x*x;}
int ext_gcd(int a, int b, int & x, int & y) {
    //for finding modular inverse
    //if its return 1 ,then a has a mod inverse x mod b.
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    int x1, y1;
    int d = ext_gcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

int main()

{
    IOS;
    //freopen("input.txt", "r", stdin);
     //freopen("output.txt", "w", stdout);
     int n;
     while(cin>>n){
        ll sum=0;
        for(int i=1;i<=n;i++){
            if(i%3==0) continue;
            if(i%5==0) continue;
            sum+=i;
        }
        cout<<sum<<endl;
     }

     return 0;

}
///Alhamdulillah


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

int main(){
  int a = 0;
  std::string s = "";
  std::cin >> a;
  std::cin >> s;
  
  if(a >= 3200){
  	std::cout << s;
  }else{
    std::cout << "red";
  }
  std::cout << '\n';
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define sz(x) (int) (x.size())
#define pii pair<int, int>
#define w first
#define s second.first
#define v second.second

const int N = 1e3 + 10, S = 2e4 + 10;
int dp[N][S] = {0};
signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    vector<pair<int, pii>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].w >> a[i].s >> a[i].v;
        a[i].w += a[i].s;
    }
    sort(a.rbegin(), a.rend());
    for (int i = 0; i < n; ++i) {
        a[i].w -= a[i].s;
    }
    for (int i = 0; i <= a[0].s; i++) {
        dp[0][i] = a[0].v;
    }
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < S; j++) {
            dp[i][j] = dp[i - 1][j];
        }
        for (int j = a[i].w; j < S && j - a[i].w <= a[i].s; j++) {
            dp[i][j - a[i].w] = max(dp[i][j - a[i].w], dp[i - 1][j] + a[i].v);
        }
    }
    int ans = 0;
    for (int i = 0; i < S; i++) {
        ans = max(ans, dp[n - 1][i]);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 157952
a = int(input())
ar = []
for i in range(a):
    l = list(map(int,input().split(" ")))
    ar.append(l)
ar.reverse()
count = 0
for r in ar:
    x = r[0] + count
    y = r[1]
    m = x % y
    if m != 0:
        count += y - m
print(count)

Measured memory_bytes: 27380
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define all(v)    ((v.begin()),(v.end()))
#define sz(v)     ((int)(v.size()))
#define forv(i, v) for(int i = 0; i < sz(v); ++i)
#define forn(i,n)   for(int i = 0; i < (int)(n); i++)
using namespace std;

typedef long long       ll;
typedef long double     ld;
typedef vector<int>     vi;
typedef vector<double>  vd;
typedef vector< vi >    vii;
typedef vector< vd >    vdd;
typedef vector<string>  vs;

int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

ll modExp(ll base, ll power) {
	if (power == 0) return 1;
	ll cur = modExp(base, power / 2);
	cur = cur * cur;
	if (power & 1) cur = cur * base;
	cur %= MOD;
	return cur;
}

int main()
{
	fast;
	int n;
	cin >> n;
	int p;
	cin >> p;
	string s; cin >> s;
	if (p == 5 || p == 2) {
		ll ans = 0;
		for (int i = 0; i  < n; i++) {
			if ((s[i] - '0') % p == 0) ans += (i + 1);
		}
		cout << ans << endl;
		return 0;
	}

	ll count[p];
	for (int i = 0; i < p; i++) count[i] = 0;
	count[0] = 1;
	int cur = 0;
	MOD = p;
	for (int i = 0; i < n; i++) {
		cur *= 10; cur += s[i] - '0'; cur %= MOD;
		int val = modExp(10, n - 1 - i) * cur; val %= MOD;
		count[val]++;
	}

	ll ans = 0;
	for (int i = 0 ; i  < p; i++) {
		ans += (count[i] * (count[i] - 1)) / 2;

	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 720
//verma_ankit484

#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
const int mod = (int) 1e9+7;

using namespace std;
//using namespace __gnu_pbds;

//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>


int32_t main() {
  IOS
  #ifdef AV
  freopen("input.txt", "r", stdin);
  #endif
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> r(n, 0), g(n, 0), b(n, 0);
  int rr = 0, gg = 0, bb = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'R') rr++;
    else if (s[i] == 'G') gg++;
    else bb++;
    r[i] = rr, b[i] = bb, g[i] = gg;
  }
  int ans = 0;
  for (int i = 0; i < n - 2; i++) {
    for (int j = i + 1; j < n - 1; j++) {
      if (s[i] == s[j]) continue;
      if (s[i] != 'G' and s[j] != 'G') {
        ans += g[j + 1];
        int d = j - i;
        if (j + d < n and s[j + d] == 'G') ans--;
      }
      else if (s[i] != 'B' and s[j] != 'B') {
        ans += b[j + 1];
        int d = j - i;
        if (j + d < n and s[j + d] == 'B') ans--;
      }
      else if (s[i] != 'R' and s[j] != 'R'){
        ans += r[j + 1];
        int d = j - i;
        if (j + d < n and s[j + d] == 'R') ans--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

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

	ll n; cin >> n;
	vl x(n);
	FOR(i,0,n) cin >> x[i], x[i]--;
	
	vl a(n*n,-1);
	FOR(i,0,n) a[x[i]] = i;
	
	vector<pll> vq1;
	FOR(i,0,n) FOR(j,0,i) vq1.eb(x[i],i);
	sort(all(vq1));
	queue<pll> q1;
	for (auto p: vq1) q1.push(p);
	
	queue<ll> q2;

	FOR(i,0,n*n) {
		if (a[i] == -1) {
			if (sz(q1)) {
				a[i] = q1.front().yy;
				if (i >= q1.front().xx) {
					cout << "No" << endl;
					return 0;
				}
				q1.pop();
			} else if (sz(q2)) {
				a[i] = q2.front();
				q2.pop();
			} else {
				cout << "No" << endl;
				return 0;
			}
		} else {
			FOR(j,a[i]+1,n) q2.push(a[i]);
		}
	}
	
	cout << "Yes" << endl;
	FOR(i,0,n*n) cout << a[i]+1 << " \n"[i+1==n*n];

}



Measured memory_bytes: 7536