akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

int a[4][4] = {};
bool b[4][4] = {};

bool judge(){
    if(b[1][1] == true and b[1][2] == true and b[1][3] == true) return true;
    if(b[2][1] == true and b[2][2] == true and b[2][3] == true) return true;
    if(b[3][1] == true and b[3][2] == true and b[3][3] == true) return true;
    if(b[1][1] == true and b[2][1] == true and b[3][1] == true) return true;
    if(b[1][2] == true and b[2][2] == true and b[3][2] == true) return true;
    if(b[1][3] == true and b[2][3] == true and b[3][3] == true) return true;
    if(b[1][1] == true and b[2][2] == true and b[3][3] == true) return true;
    if(b[1][3] == true and b[2][2] == true and b[3][1] == true) return true;
    return false;
}
int main() {
   
    for (int i=1;i<=3;i++){
        for (int j=1;j<=3;j++){
            cin >> a[i][j];
        }
    }
    int n;
    cin >> n;
    vector <int> v;
    for (int i=0;i<n;i++){
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    for (int x=0;x<n;x++){
        for (int i=1;i<=3;i++){
            for (int j=1;j<=3;j++){
                if(a[i][j] == v[x]){
                    b[i][j] = true;
                }
            }
        }
    }
    cout << (judge() ? "Yes" : "No") << endl;


}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();

        if (a >= 13){
            System.out.println(b);
        }else if (6 <= a & a <= 12){
            System.out.println(b/2);
        }else if (a <= 5){
            System.out.println(0);
        }
    }
}


Measured memory_bytes: 23124
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALLOF(c) (c).begin(), (c).end()
const ll mod=10e9+7;
ll ABS(ll a){return max(a,-a);}


int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    int d=b+c-a;
    if(d<0) d=0;
    cout<<d<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int n,q;
vector<int>v[1919];
int z,t,x;
int main(){
    cin>>n>>q;
    while(q--){
        cin>>z>>t;
        if(z==0){
            cin>>x;
            v[t].push_back(x);
        }
        if(z==1){
            rep(i,v[t].size()){
                cout<<v[t][i];
                if(i!=v[t].size()-1)cout<<" ";
            }
            cout<<endl;
        }
        if(z==2)v[t].clear();
    }
    return 0;
}


Measured memory_bytes: 5852
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>

using namespace std;

int main(){
  int N,M,X;
  cin >> N >> M >> X;
  vector<int> A(M);
  for(int i=0;i<M;i++){
    cin >> A.at(i);
  }
  
  int right=0,left=0;
  for(int i=X;i<=N;i++){
    for(int j=0;j<M;j++){
      if(A.at(j)==i)  right++;
    }
  }
  
  for(int i=X;i>=0;i--){
    for(int j=0;j<M;j++){
      if(A.at(j)==i)  left++;
    }
  }
  cout << min(right,left) << endl;
  

  return 0;
}


Measured memory_bytes: 256
//To debug :  g++ -g file.cpp -o code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807;
#define big1 LONG_MAX
#define big2 INT_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 INT_MIN
#define sma3 -1000000000;
#define mp make_pair
#define dub double
#define ivec vector<int>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
 



int dfsrec(vector<int> *adj,int nod,bool *vis,int *ans)
{
	vis[nod]=true;

	int temp=0,max;

	int i=0,siz = adj[nod].size();

	for(i=0;i<siz;++i)
	{
		if(!vis[adj[nod][i]])
		{
			max = dfsrec(adj,adj[nod][i],vis,ans)+1;
			if(max>temp)
				temp = max;
		}
		else
		{
			max = ans[adj[nod][i]]+1;
			if(max>temp)
				temp = max;
		}

	}

	//cout<<nod<<" "<<temp<<"\n";

	ans[nod]=temp;

	return (temp);

}


int dfs(vector<int> *adj,int n,bool *vis,int *ans)
{
	//Now check if each node is visited and if not call dfsrec

	int i;



	for(i=0;i<n;++i)
	{
		if(!vis[i])
		{
			dfsrec(adj,i,vis,ans);
		}

	}

	int max,temp=-1;

	for(i=0;i<n;++i)
	{
		max=ans[i];
		if(max>temp)
			temp=max;
	}

	return temp;


}


int main()
{

	FAST

	int n,m,i,a,b;
	cin>>n>>m;
	vector<int> vec[n];

	for(i=0;i<m;++i)
	{
		cin>>a>>b;
		vec[a-1].pb(b-1);
	}

	bool vis[n]={0};
	int ans[n]={0};

	cout<<dfs(vec,n,vis,ans);

	return 0;
}

Measured memory_bytes: 11648
from bisect import bisect_right as br

def quad_primes(n):
  is_prime = [True] * (n + 1)
  is_prime[0] = is_prime[1] = False
  for i in range(2, int(n ** (1 / 2)) + 1):
    if is_prime[i]:
      for j in range(i * i, n + 1, i):
        is_prime[j] = False

  return [i + 8 for i in range(n - 7) if is_prime[i] and is_prime[i + 2] and is_prime[i + 6] and is_prime[i + 8]]

quad = quad_primes(10000000)

while True:
  n = int(input())
  if n == 0:
    break
  print(quad[br(quad, n) - 1])


Measured memory_bytes: 83712
import java.util.*;
import java.io.*;
import java.lang.*;

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

        int n = sc.nextInt();

        int ans = 0;

        for (int i = 0; i<n; i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            ans += b - a + 1;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 39808
#!python3

# input
A, B, C, D, E, F = list(map(int, input().split()))


def main():
    ans = (0, 0, 0)
    for a in range(0, F + 1, 100 * A):
        for b in range(0, F + 1, 100 * B):
            if a == 0 and b == 0:
                continue
            water = a + b
            if water > F:
                break
            s = min(F - water, water // 100 * E)
            sugar = 0
            for c in range(0, s + 1, C):
                t = s - c
                sugar = max(sugar, c + (t // D) * D)
            ans = max(ans, (sugar / water, water + sugar, sugar))
    
    print(ans[1], ans[2])


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

using Edge = pair<int,int>;
using Graphy = vector<vector<Edge> >;

int n;
Graphy g;

void dfs(int v, int p, int pc, vector<int> &res) {
  int c = 1;
  if (c == pc) c++;
  for (auto e : g[v]) {
    if (e.first == p) continue;
    res[e.second] = c;
    dfs(e.first, v, c, res);
    c++;
    if (c == pc) c++;
  }
}

int main() {
  cin >> n;
  g.assign(n, vector<Edge>());
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    g[a].emplace_back(b,i);
    g[b].emplace_back(a,i);
  }
  int mc = 0;
  rep(i,n) {
    mc = max(mc,(int)g[i].size());
  }
  vector<int> res(n-1,-1);

  dfs(0,-1,-1,res);

  cout << mc << endl;
  for (auto u : res) cout << u << endl;

  return 0;
}


Measured memory_bytes: 8320
#include<stdio.h>

int main()
{
    int i,a,b,c,temp,result,max;

    scanf("%d%d%d",&a,&b,&c);
    if((a>=1 && a<=100) && (b>=1 && b<=100) &&(c>=1 && c<=100)){
        if(a<b && a<c){
            temp=a;
        }
        else if(b<c && b<a){
            temp=b;
        }
        else{
            temp=c;
        }
        if(a>b && a>c){
            max=a;
        }
        else if(b>a && b>c){
            max=b;
        }
        else{
            max=c;
        }
        result=max-temp;
        printf("%d\n",result);
    }
}


Measured memory_bytes: 128
/*
 * I'm strong. Stronger than all of you. Extremely strong.
 * I can kill all those Titans there. Even if I'm alone.
 * You're either incompetent or you're spineless cowards.
 * How pathetic.
 * You can sit here and suck on your fingers. Yeah, do that.
 * ~ Mikasa Ackerman
 */

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector<VI> VVI;

typedef long long int LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(), a.end()
#define SET(a, b) memset(a, b, sizeof(a))
#define si(n) scanf("%d", &n)
#define dout(n) printf("%d\n", n)
#define sll(n) scanf("%lld", &n)
#define lldout(n) printf("%lld\n", n)

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define fast_io                     \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL)

#define endl '\n'
const int N = 1e5;
int a[N], b[N];
int n, k;
LL bestans = 0;
void solve(int tk) {
  LL ans = 0;
  for (int i = 0; i < n; i++)
    if ((a[i] & tk) == a[i]) ans += b[i];
  bestans = max(ans, bestans);
}
int main() {
  fast_io;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
  int tk;
  int all = 0;
  for (int i = 0; i < 32; i++) {
    if (((1 << i) & k) != 0) {
      tk = (k ^ (1 << i)) | all;
      solve(tk);
    }
    all |= (1 << i);
  }
  solve(k);
  cout << bestans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 1e6+10;
const int MAXM = 1e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXM][MAXM];
int indegree[MAXN];
bool vis[MAXN];
int depth[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;

    for(int i=1;i<=n;i++)
        for(int j=1;j<n;j++){
            cin>>x;
            a = min(i,x);
            b = max(i,x);
            cur = (a-1)*n+b;
            A[i][j] = cur;
        }

    graph = vector<vector<int> > (n*n+1);

    for(int i=1;i<=n;i++)
        for(int j=1;j<n-1;j++)
        {
            x = A[i][j]; y = A[i][j+1];
            graph[x].push_back(y);
            indegree[y]++;
        }

    for(int i=1;i<=n;i++)
        for(int j=1;j<n;j++)
            if(!vis[A[i][j]]&&!indegree[A[i][j]]){
                que.push(A[i][j]);
                vis[A[i][j]] = true;
            }

    int there;

    while(!que.empty()){
        cur = que.front();
        que.pop();

        depth[cur]++;
        cnt++;

        mx = max(mx,depth[cur]);

        for(int i=0;i<graph[cur].size();i++)
        {
            there = graph[cur][i];
            indegree[there]--;
            depth[there] = max(depth[there],depth[cur]);
            if(!indegree[there])
                que.push(there);
        }
    }

    if(cnt<n*(n-1)/2)cout<<"-1\n";
    else cout<<mx<<"\n";

    return 0;
}


Measured memory_bytes: 52096
#include <stdio.h>
#include <ctype.h>

int main() {
	int n, k;
	char s[55];
	scanf("%d %d", &n, &k);
	scanf("%s", s);
	for (int i = 1; i <= n; i++) {
		if (i == k)
			s[i - 1] = tolower(s[i - 1]);
		putchar(s[i - 1]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
class Stack
  def initialize
    @arr = []
  end

  def push(x)
    @arr.push(x)
  end

  def pop
    @arr.pop
  end
end

def poland(arr)
  stack = Stack.new
  for s in arr
    if s == '+' then
      b = stack.pop
      a = stack.pop
      c = a + b
      stack.push(c)
    elsif s == '-' then
      b = stack.pop
      a = stack.pop
      c = a - b
      stack.push(c)
    elsif s == '*' then
      b = stack.pop
      a = stack.pop
      c = a * b
      stack.push(c)
    else
      stack.push(s.to_i)
    end
  end
  puts stack.pop
end

arr = STDIN.gets.split(' ')
poland(arr)

Measured memory_bytes: 8672
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+7;
char s[maxn];
int main()
{
    ios::sync_with_stdio(false);
    //string s;
    cin>>s;
    int a=0;
    int sum=0;
    for(int i=1;i<strlen(s)-1;i++){
        if(s[a]!=s[i+1]){
            sum++;
        }
        else{
            a=i+1;
            i++;
        }
    }
    if(sum%2==0) cout<<"Second"<<endl;
    else cout<<"First"<<endl;
    return 0;
}


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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug if(true)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

int main(){
	int n,i,j;
	int a[200001];
	scanf("%d",&n);
	for(i=0;i<n;i++){scanf("%d",&a[i]);}
	int maks[200001];
	int minim[200001];
	maks[0] = minim[0] = a[0];
	for(i=1;i<n;i++){
		maks[i] = max(a[i], maks[i-1]);
		minim[i] = min(a[i], minim[i-1]);
	}
	int cnt = 0;
	for(i=0;i<n;i++){
		if(minim[i] >= a[i] && maks[i] >= a[i]){
			cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
};

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int H, N;
    int sum = 0;
    cin >> H >> N;
    int data[N];
    for (int i = 0; i < N; i++){
        cin >> data[i];
    }
    for (int i = 0; i < N; i++){
        sum += data[i];
    }
    if(sum >= H)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <iostream>

using namespace std;

const int N = 1e5 + 5;
const int64_t LINF = 1e18;

int n, h[N];
int64_t dp[N];

int main()
{
//    freopen("input.inp", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> h[i];
    dp[1] = 0;
    for (int i = 2; i <= n; ++i)
        dp[i] = LINF;
    for (int i = 1; i < n; ++i)
    {
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
        if (i + 2 <= n)
            dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
    }
    cout << dp[n];
    return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>

int main(){
  int a,b,c,n;

  scanf("%d",&n);

  while(n--){
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);

    if( a*a + b*b == c*c ||
        b*b + c*c == a*a ||
        c*c + a*a == b*b){
      printf("YES\n");
    }else{
      printf("NO\n");
    }
  }
  return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1100000000000000000

int beki(int a,int b,int M = modulo){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=((long long)x*a)%M;
		}
		a=((long long)a*a)%M;
		b>>=1;
	}
	return x;
}


int gyakugen(int a){
	return beki(a,modulo-2);
}

int main(){
	
	int N,K;
	cin>>N>>K;
	
	vector<int> Y;
	for(int i=1;i*i<=N;i++){
		if(N%i==0){
			Y.push_back(i);
			if(i*i!=N)Y.push_back(N/i);
		}
	}
	
	sort(Y.begin(),Y.end());
	vector<int> c(Y.size(),0);
	
	for(int i=0;i<Y.size();i++){
		c[i] = beki(K,(Y[i]+1)/2);
		
		for(int j=0;j<i;j++){
			if(Y[i]%Y[j]==0){
				int x = c[j];
				c[i] = mod(c[i]-x);
			}
		}
	}
	
	int ans = 0;
	
	for(int i=0;i<Y.size();i++){
		if(Y[i]%2==0)ans = mod(ans + mod(Y[i] * c[i]/2));
		else ans = mod(ans + mod(Y[i] * c[i]));
	}
	
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main() {
  int n, m ,l;
  scanf("%d %d %d", &n, &m, &l);
  long int a[n][m], b[m][l];
  long int c[n][l];
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < l; j++)
    {
      c[i][j] = 0;
    }
  }
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < m; j++)
    {
      scanf("%ld", &a[i][j]);
    }
  }
  for (int i = 0; i < m; i++)
  {
    for (int j = 0; j < l; j++)
    {
      scanf("%ld", &b[i][j]);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      for (int k = 0; k < m; k++) {
        c[i][j] += a[i][k] * b[k][j];
      }
      printf("%ld", c[i][j]);
      if (j != l - 1)
        printf(" ");
    }
    printf("\n");
  }
}


Measured memory_bytes: 2948
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vector<ll>>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  string s;
  cin >> s;
  s[3]='8';
  cout << s << endl;

}

Measured memory_bytes: 3612
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let ms = [0,1,3,1,2,1,2,1,1,2,1,2,1];
    let (x, y) = get!(usize, usize);
    println!("{}", if ms[x] == ms[y] { "Yes" } else { "No" });
}

Measured memory_bytes: 4352
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int bubbleSort(int a[], int n) {
    int sw = 0;
    bool flag = 1;
    for(int i = 0; flag; i++) {
        flag = 0;
        for(int j = n-1; j >= i+1; j--) {
            if(a[j] < a[j-1]) {
                swap(a[j], a[j-1]);
                flag = 1;
                sw++;
            }
        }
    }

    return sw;
}

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, n) {
        cin >> a[i];
    }

    int sw = bubbleSort(a, n);

    rep(i, n) {
        if(i) {
            cout << " ";
        }
        cout << a[i];
    }
    cout << "\n";
    
    cout << sw << endl;

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e8) + 5;
const int MAX_A = int(15e6);
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
string dir = "RDLU";
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
    ll n, x[105], y[105], z[105];
    cin >> n;
    REP(i,n) cin >> x[i] >> y[i] >> z[i];
    REP(i,101){
        REP(j,101){
            bool ok = true;
            ll h = -1;
            REP(k,n){
                if(z[k] > 0){
                    h = abs(x[k] - i) + abs(y[k] - j) + z[k];
                    break;
                }
            }
            REP(k,n){
                if(h == -1) h = abs(x[k] - i) + abs(y[k] - j) + z[k];
                ll nh = max(h - abs(x[k] - i) - abs(y[k] - j), 0ll);
                if(z[k] != nh){
                    ok = false;
                    break;
                }
            }
            if(ok && h > 0){
                cout << i << " " << j << " " << h << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;

        for (int i = 0; i < n; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();

            ans += (r - l + 1);
        }

        System.out.println(ans);
    }
}

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

int main(void){
    int r,n,left,right,height;
    double minh;
    map<int,int> s;

    while(1){
        /* ????????? */
        rep(i,21)s[i]=s[-i]=0;

        /* ??\??? */
        cin>>r>>n;
        if(r==0&&n==0)break;
        minh = 21;
        while(n--){
            cin>>left>>right>>height;
            for(int i=left;i<right;++i){
                if(s[i]<height)s[i]=height;
            }
        }

        rep(i,r)minh = min(minh,min(s[i],s[-i-1])-sqrt(r*r-i*i));
        printf("%.4f\n",minh+r);
    }

    return 0;
}

Measured memory_bytes: 1228
//Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
#define PI             acos(-1.0)
#define IOS            ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ms(a,b)         memset(a, b, sizeof(a))
#define filein      freopen("input.txt", "r", stdin);
#define fileout     freopen("output.txt", "w", stdout);
#define debug       cout<<"Hello, i am in here."<<endl;
#define bit_cnt(mask) __builtin_popcountll(mask)
#define ll long long int
#define dst(u,v,x,y) sqrt((x*1.0-u*1.0)*(x*1.0-u*1.0)+(y*1.0-v*1.0)*(y*1.0-v*1.0))
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}
template <class T> inline T bpow(T p,T e){ll ret = 1;for(; e > 0; e >>= 1){if(e & 1) ret = (ret * p);p = (p * p);}return (T)ret;}
using namespace std;
const int MOD = (int)1e9+7;
ll Gcd(ll a, ll b)
{
    if (!a)
       return b;
    return Gcd(b%a,a);
}
void solve()
{
   ll n,m;
   cin>>n>>m;
   if(n==0)
   {
     cout<<0<<endl;
     return ;
   }
    if(n==m)
    {
      cout<<0<<endl;
      return;
    }
    ll x=(n/m);
    cout<<min(abs(n-x*m),abs(n-((x+1)*m)))<<endl;
    return;

}
int  main()
{
    IOS
    solve();
    return 0;
}


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

long long n, m;
vector<long long> a;
map<long long, long long> cnt;

long long solve();

int main() {
  cin >> n >> m;
  a.resize(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 0, sum = 0;
  for(int i = 0; i < n; ++i) {
    sum += a[i];
    sum %= m;
    if(sum == 0) ++ans;
    ans += cnt[sum];
    ++cnt[sum];
  }
  return ans;
}

Measured memory_bytes: 4992
h,w = map(int, input().split())
l = [input() for _ in range(h)]
l.insert(0,'#'*(w+2))
l.append('#'*(w+2))

for i in range(1,h+1):
    x = list(l.pop(i))
    x.insert(0,'#')
    x.append('#')
    l.insert(i,''.join(x))

for j in range(h+2):
    print(l[j])


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

const int64_t MAX = 100000;
int64_t L[MAX];
int64_t R[MAX];
int I[MAX];
int64_t n;
int64_t L2[MAX];
int64_t R2[MAX];

bool cmp(int a, int b)
{
    if (R[a] == R[b])
    {
        if (L[a] == L[b]) return a<b;
        else return L[a] < L[b];
    }
    else return R[a] < R[b];
}

int main()
{
    std::ios_base::sync_with_stdio(0);
    std::cin >> n;
    for (int i=0;i<n;++i) std::cin >> L[i] >> R[i];
    for (int i=0;i<n;++i) I[i] = i;
    std::sort(I, I+n, cmp);
    int64_t result = 0;

    L2[n-1] = L[I[n-1]];
    R2[n-1] = R[I[n-1]];
    for (int i=n-2;i>=0;--i)
    {
        L2[i] = std::max(L[I[i]], L2[i+1]);
        R2[i] = std::min(R[I[i]], R2[i+1]);
    }

    int64_t zero = 0;

    int64_t ll=L[I[0]], rr=R[I[0]];
    result = std::max(zero, rr-ll+1) + std::max(zero, R2[1]-L2[1]+1);
    for (int i=0;i<n;++i)
    {
        result = std::max(result, R[I[i]]-L[I[i]]+1+ std::max(zero, R2[0]-L2[0]+1));
    }
    for (int i=1;i<n-1;++i)
    {
        // std::clog << ll << " : " << rr << "     " << L2[i+1] << " : " << R2[i+1] << std::endl;
        ll = std::max(L[I[i]], ll);
        rr = std::min(R[I[i]], rr);
        result = std::max(result, std::max(zero, rr-ll+1) + std::max(zero, R2[i+1]-L2[i+1]+1));
    }
    // std::clog << ll << " : " << rr << "     " << L2[n-1] << " : " << R2[n-1] << std::endl;
    std::cout << result;
    return 0;
}

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

int N, K;
vector<int> d;
vector<vector<int>> A;

void input() {
    cin >> N >> K;
    d.resize(K);
    A.resize(K, vector<int>());
    for(int i = 0; i < K; i++) {
        cin >> d[i];
        A[i].resize(d[i]);
        for(int j = 0; j < d[i]; j++) {
            cin >> A[i][j];
        }
    }
}

void solve() {
    int ans = 0;
    for(int i = 1; i <= N; i++) {
        bool have = false;
        for(auto v : A) {
            for(auto p : v) {
                if(p == i) have = true;
            }
        }
        if(!have) ans++;
    }
    cout << ans << endl;
}

int main() {
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3668
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    sum_ = 0
    min_ = 101
    for i in range(N):
        tmp = int(input())
        sum_ += tmp
        if tmp % 10 != 0:
            min_ = min(min_, tmp)
    if sum_ % 10 == 0:
        if min_ != 101:
            print(sum_ - min_)
        else:
            print(0)
    else:
        print(sum_)

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
import math
import calendar
import fractions
import itertools

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
seq = [i for i in range(1, n + 1)]
all_iter = list(itertools.permutations(seq))
# print(all_iter)

ans = 0
for i in range(len(all_iter)):
    item = all_iter[i]
    if item == p and item == q:
        ans = 0
    elif item == p:
        ans += i
    elif item == q:
        ans -= i
print(abs(ans))


Measured memory_bytes: 10040
#pragma GCC optimize(3)
#pragma comment(linker,"/stack:96777216")
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<functional>
#include<utility>
#include<algorithm>
#include<sstream>
#include<cstring>
#include<cmath>
#include<cctype>
#include<exception>
#include<climits>
#include<cfloat>
#include<iomanip>
#include<bitset>
#include<streambuf>
#include<cstdlib>
#include<ctime>
//#include"functions.h"
//#include"highprecision.h"
#define pb push_back
#define pf push_front
#define ppb pop_back
#define mp make_pair
#define np next_permutation
#define fi first
#define sc second
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int> >
#define vpi vector<pair<int,int> >
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pff pair<float,float>
#define pdd pair<double,double>
#define psi pair<string,int>
#define pis pair<int,string>
#define ppi pair<pii,int>
#define pdi pair<pii,pii>
#define LN 84757
#define INF 1e9
#define LLINF 1e18
#define MAXINT 0x7fffffff
#define MAXLL 0x7fffffffffffffff
#define EPS 1e-5
#define DEPS 1e-9
#define LDEPS 1e-13
#define MOD 1000000007
#define E 2.7182818284
#define PI 3.1415926535
#define rep(a,b) for(int a=0;a<b;a++)
#define forn(a,n) for(int a=1;a<=n;a++)
#define forr(a,n) for(int a=n;a>=1;a--)
#define repn(a,n,p) for(int a=0;a<n;a+=p)
#define repr(a,n) for(int a=n-1;a>=0;a--)
#define foreach(a,b) for(__typeof(b.begin())a=b.begin();a!=b.end();a++)
#define fillemp(a) memset(a,0,sizeof(a))
#define fillinf(a) memset(a,0x3f,sizeof(a))
#define frestream freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define stdf(a,b) freopen(a,"r",stdin);freopen(b,"w",stdout);
#define inputf(a) freopen(a,"r",stdin);
#define outputf(a) freopen(a,"w",stdout);
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define MOD 1000000007
typedef long long ll;
typedef long double ld;
using namespace std;

struct min_segment_tree{
	int n,seg[1<<19-1];
	void init(int n_){
		n=1;
		while(n<n_)n*=2;
		rep(i,2*n-1)seg[i]=INF;
	}
	void upd(int k,int a){
		k+=n-1;
		seg[k]=a;
		while(k){
			k=(k-1)/2;
			seg[k]=min(seg[k*2+1],seg[k*2+2]);
		}
	}
	int que(int a,int b,int k,int l,int r){
		if(r<=a||b<=l)return INF;
		if(a<=l&&r<=b)return seg[k];
		else{
			int vl=que(a,b,k*2+1,l,(l+r)/2);
			int vr=que(a,b,k*2+2,(l+r)/2,r);
			return min(vl,vr);
		}
	}
};
struct max_segment_tree{
	int n,seg[1<<19-1];
	void init(int n_){
		n=1;
		while(n<n_)n*=2;
		rep(i,2*n-1)seg[i]=-INF;
	}
	void upd(int k,int a){
		k+=n-1;
		seg[k]=a;
		while(k){
			k=(k-1)/2;
			seg[k]=max(seg[k*2+1],seg[k*2+2]);
		}
	}
	int que(int a,int b,int k,int l,int r){
		if(r<=a||b<=l)return -INF;
		if(a<=l&&r<=b)return seg[k];
		else{
			int vl=que(a,b,k*2+1,l,(l+r)/2);
			int vr=que(a,b,k*2+2,(l+r)/2,r);
			return max(vl,vr);
		}
	}
};
int main(){
	ll n=100ll,x;
	int ans=0;
	cin>>x;
	while(n<x){
		ans++;
		n=n+n/100ll;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3632
N = int(input())
PRE = [int(i) for i in input().split()]
IN = [int(i) for i in input().split()]
POST = []

pos = 0

def rec(left, right):
    global pos
    if right <= left:
        return
    root = PRE[pos]
    pos += 1
    mid = IN.index(root)
    rec(left, mid)
    rec(mid + 1, right)
    POST.append(root)

rec(0, N)
print(*POST)


Measured memory_bytes: 5604
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    double a, b, x;
    cin >> a >> b >> x;

    x /= a;

    double ans;
    if(a * b / 2 >= x){
        double c = x * 2 / b;
        ans = atan2(b, c) / M_PI * 180;
    }else{
        x = a * b - x;
        double c = x * 2 / a;
        ans = atan2(c, a) / M_PI * 180;
    }
    cout << fixed << setprecision(10) << ans << endl;

    return 0;
}


Measured memory_bytes: 888
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n,k = map(int, input().split())
a = [None]*n
for i in range(n):
    a[i] = list(map(int, input().split()))
    
### 行列積 matrix multiplication
### 繰り返し2乗法

M = 10**9+7
def mul(a,b):
    """行列a,bの積
    aかbがNone のとき、単位行列として扱う
    """
    if a is None:
        return b
    elif b is None:
        return a
    n,m = len(a), len(a[0])
    k,l = len(b), len(b[0])
    # k==m
    out = [[0]*l for _ in range(n)]
    for i in range(n):
        for j in range(l):
            for p in range(m):
                out[i][j] += a[i][p]*b[p][j]
                out[i][j] %= M
    return out

# path^hを求める
i = 0
ans = None
tmp = a
while k>0:
    if k&1:
        ans = mul(ans, tmp)
    tmp = mul(tmp, tmp)
    k = k>>1
print(sum(sum(item)for item in ans) % M)

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



int main(void){
    int n,m,d;
    scanf("%d%d%d",&n,&m,&d);
    double ans;
    double N,M,D;
    N=(double)n;M=(double)m;D=(double)d;
    ans=((N-D)/(N*N));
    if(d!=0)ans*=2.0f;
    ans*=(M-1);
    printf("%.10f",ans);
    return 0;
}


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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    VL a(n);
    REP(i, n) cin >> a[i];
    sort(ALL(a), greater<ll>());
    
    VPL cb(m);
    REP(i, m) {
        ll b, c;
        cin >> b >> c;
        cb[i] = PL(c, b);
    }
    sort(ALL(cb), greater<PL>());

    VL a_alt;
    REP(i, m) {
        if(a_alt.size() >= n) break;
        REP(j, cb[i].second) a_alt.push_back(cb[i].first);
    }

    ll ans = 0;
    int a_i = 0;
    int a_alt_i = 0;
    REP(i, n) {
        if(a[a_i] < a_alt[a_alt_i]) {
            ans += a_alt[a_alt_i];
            a_alt_i++;
        } else {
            ans += a[a_i];
            a_i++;
        }     
    }
    cout << ans << ln;
    return 0;
}


Measured memory_bytes: 4852
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:1024000000")
#pragma warning( disable : 6031)
#pragma warning( disable : 4244)
#pragma warning( disable : 26451)
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)

using namespace std;

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

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef vector<ll> vl;
typedef vector<vector<long long>> vvl;
typedef tuple<int, int, int> tiii;
const long long mod = int(1e9) + 7;
const int INF = 1e9;

struct HASH {
	size_t operator()(const pair<int, int>& x)const {
		return (size_t)x.first * 37U + (size_t)x.second;
	}
};

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	int h, w, n;
	cin >> h >> w >> n;
	cout << (n + max(h, w) - 1) / max(h, w);
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import bisect

def main():
  N = int(input())
  L = list(sorted(map(int,input().split())))
  res = 0
  for i in range(N-2):
    x = L[i]
    for j in range(i+1,N-1):
      y = L[j]
      res += bisect.bisect_left(L,x+y) - j - 1


  print(res)
  return

main()


Measured memory_bytes: 9280
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
int like[100001];

typedef ll IS_PRIME_TYPE;
bool is_prime(IS_PRIME_TYPE n){
	bool f = true;
	if(n == 2)
		return true;
	if(n % 2 == 0)
		return false;
	for(IS_PRIME_TYPE i = 3;i <= (int)(sqrt(n) + 0.1);i += 2){
		if(n % i == 0){
			f = false;
			break;
		}
	}
	return f;
}

int main(){
	like[0] = 0;
	like[1] = 0;
	FOR(i,2,100001){
		like[i] = ((i % 2 == 1) && is_prime(i) && is_prime((i + 1) / 2));
	}

	REP(i,100000) {
		like[i + 1] += like[i];
	}

	int q;
	cin >> q;
	REP(i,q) {
		int l,r;
		cin >> l >> r;

		cout << like[r] - like[l - 1] << endl;
	}
	return 0;
}


Measured memory_bytes: 1024
A,B = map(int,input().split())
S = str(input())

flg = True
skip = A
cnt=0

if len(S) != A+B+1:
    flg=False
    

for i in range(len(S)):
    
    if cnt == A:
        if S[cnt]!= "-":
            flg = False
    else:
        if S[cnt] == "-":
            flg = False

    cnt+=1
    
if flg ==True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
int main(void)
{
    long long N, x, a[101], i, num=0, ans, judge=0;

    cin >> N >> x;

    for(i=1; i<=N; i++){
        cin >> a[i];
    }

    sort(a+1, a+N+1);

    for(i=1; i<=N; i++){
        num += a[i];

        if(num > x){
            ans = i-1;

            judge = 1;

            break;
        }
    }

    if(judge == 0){
        if(num == x){
            ans = N;
        }
        
        else{
            ans = N-1;
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import math
d,g=map(int,input().split())
p,c=[],[]
for i in range(d):
    P,C=map(int,input().split())
    p.append(P)
    c.append(C)
#print(p,c)
ans=float('inf')
for i in range(2**d):
    cnt=0
    score=0
    maxim = 0  # 解かれていない中で最大の配点のやつ
    for j in range(d):
        #ボーナスもらう問題
        if (i>>j)&1:
            cnt+=p[d-1-j]
            score+=(d-j)*100*p[d-1-j]+c[d-1-j]
        else:
            maxim=max(maxim,d-1-j)

    left=g-score
    if left<=0:
        ans=min(ans,cnt)
    else:
        if left<=100*(maxim+1)*(p[maxim]-1):
            count=math.ceil(left/(100*(maxim+1)))
            ans=min(ans,cnt+count)

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=200005;

int n,m,a[N],b[N],t[N];

int read()
{
    int x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

int main()
{
	n=read();m=read();
	for (int i=1;i<=n;i++) a[i]=read(),t[a[i]]++;
	int tot=0;
	for (int i=1;i<=n;i++) if (t[i]) b[++tot]=t[i];
	sort(b+1,b+tot+1);
	int ans=0;
	for (int i=1;i<=tot-m;i++) ans+=b[i];
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 2560
n, x = map(int, input().split())
a=list(map(int, input().split()))
a.sort()

cnt=0
for i in range(n):
    if x < a[i] or (i==n-1 and x!=a[i]):
        break
    else:
        x-=a[i]
        cnt+=1


print(cnt)


Measured memory_bytes: 2940
/*																													   
 Templatka c++ Kacper Fis																							   																											   //
*/																													  
																								   
#include <bits/stdc++.h>																							   
																													   
using namespace std; 																								   
		
const double eps = 1e-9;																							   
const int INF = 1000000001;																						   
const float PI = 3.14;																								   
typedef long long LL;																								   
																													   
typedef vector<int> vi;																								   
typedef list<int> li;																								   
typedef queue<int> qi; 																								   
typedef pair<int,int> ii; 																							   
typedef map<string,int> msi; //np msi['nazwa'] = 'liczba'															   
typedef vector<ii> vii; //vector par<int>, do tworzenia tablicy dla grafów wagowych #dijkstra #Bellman_Ford			   
typedef priority_queue< ii, vector<ii>, greater<ii> > pq; //kolejka priorytetowa vectorów par(top()=min) #dijkstra	   
																													   																				   
vector<ii>::iterator iter;																							   
																													   																				   
#define print_list(x) for(it = (x).begin(); it != (x).end(); it++) {cout << *it << " ";}							   
#define print_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++) {cout << *it2 << " ";}						   
#define search_list(x) for(it = (x).begin(); it != (x).end(); it++)													   
#define search_vector(x) for(it2 = (x).begin(); it2 != (x).end(); it2++);											   
#define pb(x) push_back(x) 																							   
#define pf(x) push_front(x)																							   
#define mp(x, y) make_pair(x, y)                                                                                       
///////////////////////////////////////////////GLOBAL DEFINITIONS////////////////////////////////////////////////////////


///////////////////////////////////////////////////FUNCTIONS/////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////MAIN////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])																					 
{ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);                  												       
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   
	int a,b;
	cin >> a >> b;
	string s1, s2;
	string one = to_string(a);
	string two = to_string(b);
	s1 = "";
	s2 = "";
	for(int i = 0; i < b; i++){
		s1 += one;
	}
	for(int i = 0; i < a; i++){
		s2 += two;
	}
	 
	
	if(s1 < s2){
		cout << s1 << '\n';
	}
	else cout << s2 << '\n';
	
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key)
    return u;
  if(k < u->key)
    return treeSearch(u->left,k);
  else
    return treeSearch(u->right,k);

}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL ){
    y = x;
    if(z->key < x->key)
      x = x->left;
    else
      x = x->right;
  }


  if(y == NIL)
    root = z;
  else if(z->key < y->key)
    y->left = z;
  else
    y->right = z;

}

void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u != NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



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

#define rep(i, ss, ee) for (int i = ss; i < ee; ++i)
using namespace std;
int N;
string s;
void input() { cin >> N >> s; }
void solve() {
  int a = 0, b = 0, ans;
  rep(i, 0, N) if (s[i] == 'R') a++;
  ans = max(a, b);
  rep(i, 0, s.size()) {
    if (s[i] == 'R')
      a--;
    else
      b++;
    int now = max(a, b);
    ans = min(ans, now);
  }
  cout << ans << endl;
}

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

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
int main() {
int N,a1,a2,a3,a4;
cin >>N;
a1 = (N-N%1000)/1000;
a2 = (N-1000*a1-N%100)/100;
a3 = (N-1000*a1-100*a2-N%10)/10;
a4 = N-1000*a1-100*a2-10*a3;
if(((a1==a2)&&(a2==a3))||((a2==a3)&&(a3==a4))){
cout<< "Yes" <<endl;
}

else{
cout<< "No"<<endl;
}
}

Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int n, prefix[300009], suffix[300009]; string s;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> n >> s;
	for (int i = 0; i < n; ++i) {
		prefix[i + 1] = prefix[i] + (s[i] == 'W');
	}
	for (int i = n - 1; i >= 0; --i) {
		suffix[i] = suffix[i + 1] + (s[i] == 'E');
	}
	int ret = n;
	for (int i = 0; i < n; i++) {
		ret = min(ret, prefix[i] + suffix[i + 1]);
	}
	cout << ret << '\n';
	return 0;
}

Measured memory_bytes: 2964
let [|N;A;B|] =
    stdin.ReadLine().Split()
    |> Array.map int

[|1..N|]
|> Array.filter (fun x ->
    let sum = x/10000 + x%10000/1000 + x%1000/100 + x%100/10 + x%10
    sum >= A && sum <= B)
|> Array.sum
|> stdout.WriteLine

Measured memory_bytes: 29484
# coding: utf-8
# Your code here!

def down(i,t):
    max = 0
    for k in range(26):
        max += c[k+1]*(i-last[k+1])
    return max

def manzoku(i,t):
    return s[i][t-1]-down(i+1,t)

last = { 1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0,
         8:0, 9:0, 10:0, 11:0, 12:0, 13:0, 14:0, 15:0,
        16:0, 17:0, 18:0, 19:0, 20:0, 21:0, 22:0, 23:0,24:0, 25:0, 26:0
        }

# 日数
D = int(input())

line = input().split(" ")
c = [0]
for i in range(26):
    c.append(int(line[i]))

s = []
for i in range(D):
    line = input().split(" ")
    sSub = []
    for j in range(26):
        sSub.append(int(line[j]))
    s.append(sSub)

m = 0
for i in range(D):
    t = int(input())
    last[t] = i+1
    m += manzoku(i,t)
    print(m)
    

Measured memory_bytes: 74212
d1={'a':0,
'b':25,
'c':24,
'd':23,
'e':22,
'f':21,
'g':20,
'h':19,
'i':18,
'j':17,
'k':16,
'l':15,
'm':14,
'n':13,
'o':12,
'p':11,
'q':10,
'r':9,
's':8,
't':7,
'u':6,
'v':5,
'w':4,
'x':3,
'y':2,
'z':1}
d2=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','a']
s=list(input())
k=int(input())
lens=len(s)
ans=''
ind=1
for i in s:
  if ind==lens:
    ans+=d2[(d2.index(i)+k)%26]
  elif k>=d1[i]:
    k-=d1[i]
    ans+='a'
  else:
    ans+=i
  ind+=1
print(ans)

Measured memory_bytes: 4152