akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;

using namespace std;

typedef struct Pt
{
  ll x, y;
} Pt;

double dist(Pt p1, Pt p2)
{
  int dx = p1.x - p2.x;
  int dy = p1.y - p2.y;
  return sqrt((dx * dx) + (dy * dy));
}

int main()
{
  int n;
  cin >> n;
  vector<Pt> town(n);
  vector<int> ns(n);
  int pat = 1;
  rep(i, n)
  {
    pat *= (i+1);
    ns[i] = i;
    cin >> town[i].x >> town[i].y; 
  }
  double sum = 0;
  do
  {
    for(int i = 0; i < n - 1; ++i)
    {
      sum += dist(town[ns[i]], town[ns[i+1]]);
    }
  }while(next_permutation(ns.begin(), ns.end()));

  printf("%.10f\n", sum / pat);

  return 0;
}


Measured memory_bytes: 256
import sys
c=[list(map(int,input().split())) for i in range(3)]
a = [0]*3
b = [0]*3

a = [c[0][i] for i in range(3)]
b = [c[i][0]-a[0] for i in range(3)]

for i in range(3):
    for j in range(3):
        if a[j] + b[i] != c[i][j]:
            print("No")
            sys.exit()

print("Yes")


Measured memory_bytes: 3064
// include
#include <cstdint>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <array>

// ============================================
int main() {
  int X, N;
  std::cin >> X >> N;
  std::vector<int> a(N);

  
  for (int i = 0; i < N; i++) {
    std::cin >> a[i];    
  }
  auto beginIt = a.begin();
  auto endIt = a.end() = a.end();
  
  for (int i = 0; i < 100; ++i) {
    int xm = X - i;
    int xp = X + i;
    if (std::find(beginIt, endIt, xm) == endIt) {
      
      std::cout << xm << std::endl;
      return 0;
      
    } else if (std::find(beginIt, endIt, xp) == endIt) {
      
      std::cout << xp << std::endl;
      return 0;
      
    }
  }
  
  return 0;
}


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

using ll = long long;

template<typename T>
T gcd(T a, T b)
{
	if (a < b)	return gcd(b, a);
	T r;
	while ((r = a % b))
	{
		a = b;
		b = r;
	}
	return b;
}

template<typename T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}

template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
	x = 1;
	y = 0;
	T x0 = 0, y0 = 1;
	while (b != 0)
	{
		T q = a / b;
		a -= q * b;
		swap(a, b);
		x -= q * x0;
		swap(x, x0);
		y -= q * y0;
		swap(y, y0);
	}
	return a;
}

template<typename T>
T inv_mod(T a, T mod)
{
	T t1, t2;
	ext_gcd(a, mod, t1, t2);
	t1 %= mod;
	if (t1 < 0)		t1 += mod;
	return t1;
}

template<typename T>
T combination_large(T n, T k, T mod)
{
	if (n < k || n < 0 || k < 0)	return 0;
	vector<T> inv(n + 1, 1), fact(n + 1, 1), fact_inv(n + 1, 1);
	for (T i = 2; i <= n; ++i)
	{
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = (fact[i - 1] * i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

template<typename T>
T combination(T n, T k, T mod = 1)
{
	vector<vector<T>> table(n + 1, vector<T>(k + 1, 1));
	for (T i = 1; i <= n; ++i)
	{
		table[i][0] = 1;
		for (T j = 1; j <= n; ++j)
		{
			table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % mod;
		}
	}
}

int main(int, char**)
{
	int a, b, c, d;
	a = cin.get() - '0';
	b = cin.get() - '0';
	c = cin.get() - '0';
	d = cin.get() - '0';
	cin.ignore();
	for (int i = 0; i < 0b1000; ++i)
	{
		int total = a;
		char op[3];
		if ((i & 0b1) != 0)
		{
			total += b;
			op[0] = '+';
		}
		else
		{
			total -= b;
			op[0] = '-';
		}
		if ((i & 0b10) != 0)
		{
			total += c;
			op[1] = '+';
		}
		else
		{
			total -= c;
			op[1] = '-';
		}
		if ((i & 0b100) != 0)
		{
			total += d;
			op[2] = '+';
		}
		else
		{
			total -= d;
			op[2] = '-';
		}
		if (total == 7)
		{
			cout << a << op[0] << b << op[1] << c << op[2] << d << "=7" << endl;
			return 0;
		}
	}
	return 0;
}


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

int main(){
    int A[101][101];
    
    int r,c;
    cin>>r>>c;
    for(int i=0; i<r; i++){
        for(int j=0; j<c; j++){
            cin>>A[i][j];
        }
    }
    
    for(int i=0; i<=r; i++){
        A[i][c]=0;
    }
    for(int j=0; j<=c; j++){
        A[r][j]=0;
    }
    
    for(int i=0; i<r; i++){
        for(int j=0; j<c; j++){
            A[i][c]+=A[i][j];
            A[r][j]+=A[i][j];
            A[r][c]+=A[i][j];
        }
    }
    
    for(int i=0; i<=r; i++){
        for(int j=0; j<=c; j++){
            if(j) cout<<" ";
            cout<<A[i][j];
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL;

const int maxm = 2e5+5;

double ex[1005];
int buf[maxm];

void prework() {
    double sum = 0;
    for(int i = 1; i <= 1000; ++i) {
        sum += i;
        ex[i] = (double) sum / i;
    }
    return;
}

void run_case() {
    prework();
    int N, K;
    cin >> N >> K;
    double ans = 0, tmp = -1.0;
    for(int i = 0; i < N; ++i) cin >> buf[i];
    for(int i = 0; i < K; ++i) ans += ex[buf[i]];
    for(int i = K; i < N; ++i) {
        tmp = max(tmp, ans);
        ans += ex[buf[i]], ans -= ex[buf[i-K]];
    }
    tmp = max(tmp, ans);
    cout.setf(ios_base::showpoint);cout.precision(8);
    cout << tmp;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 1024
// C - Sugar Water
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

void solve(int w1,int w2, int s1, int s2, int solute, int
volume){
	set<int> X, Y;
	int end = volume/100 + 1;
	rp(i, 1, end){
		rp(j, 0, end){
			int x = w1*i + w2*j;
			if(0 < x && x < end) X.insert(x);
		}
	}

	end = volume + 1;
	rp(i, 0, end){
		rp(j, 0, end){
			int y = s1*i + s2*j;
			if(y < end) Y.insert(y);
		}
	}

	int WS = w1*100, S = 0;
	double maxper = 0.0;
	for(auto x:X){
		int maxsol = solute * x;
		for(auto y:Y){
			int ws = x * 100 + y;
			if(ws <= volume && y <= maxsol){
				double per = 100.0*y/ws;
				if(maxper < per){
					maxper = per;
					WS = ws;
					S = y;
				}
			}
		}
	}
	printf("%d %d\n",WS,S);
}

int main(){
	int a,b,c,d,e,f; cin>>a>>b>>c>>d>>e>>f;
	solve(a,b,c,d,e,f);
}

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

const int MOD = 1e9 + 7;

int main(){
	
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	
	map<char,int> mep;
	
	for(char c = 'a' ; c <= 'z' ; c ++)
		mep[c] = 100;
	
	for(int i = 0 ; i < n ; i ++){
		
		string s;
		cin >> s;
		map<char,int> cnt;
		
		for(int j = 0 ; j < (int)s.size() ; j ++)
			cnt[s[j]]++;
		
		for(char c = 'a'; c <= 'z' ; c ++)
			mep[c] = min(mep[c], cnt[c]);
		
	}
	
	for(char c = 'a' ; c <= 'z' ; c ++){
		for(int i = 0 ; i < mep[c] ; i ++)
			cout << c;
	}
	
	cout << "\n";
	
	return 0;
}

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

using namespace std;
const int N = 1e5 + 3;
int n, a[N], b[N];
int main() {
#ifndef ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
#endif
	scanf("%d", &n);
	for (int i = 0; i <= n; ++i)
		scanf("%d", a + i);
	for (int i = 0; i < n; ++i)
		scanf("%d", b + i);
	long long res = 0;
	for (int i = 0; i <= n; ++i) {
		int goneNow = min(a[i], b[i]);
		res += goneNow;
		b[i] -= goneNow;
		int goneNext = min(a[i + 1], b[i]);
		res += goneNext;
		a[i + 1]-=goneNext;
	}
	printf("%lld\n", res);
	return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li d;
li c[111];
li s[444][33];

li last[33];

int main() {
    cin >> d;
    rep(i, 26) {
        cin >> c[i];
        last[i] = -1;
    }
    rep(i, d) {
        rep(j, 26) {
            cin >> s[i][j];
        }
    }

    li res = 0;
    rep(i, d) {
        li dd;
        cin >> dd;
        dd--;
        res += s[i][dd];
        last[dd] = i;
        rep(j, 26) {
            res -= (i - last[j]) * c[j];
        }
        cout << res << endl;
    }

    return 0;
}

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

int main(void){
    int n;
    cin >> n;
    int max_ = 0, min_ = MOD;
    vector<int> a(n);
    rep(i, n){
        cin >> a.at(i);
        max_ = max(a.at(i), max_);
        min_ = min(a.at(i), min_);
    }
    
    cout << max_ - min_ << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<map>
using lint=int64_t;
using namespace std;

int main()
{
	lint N,M;
	lint A[100010]={};

	cin >> N >> M;
	for(lint i=1;i<=N;i++)
	{
		cin >> A[i];
		A[i]+=A[i-1];
	}

	map<lint,lint> m;
	for(lint i=1;i<=N;i++)
		m[A[i]%M]++;
	m[0]++;

	lint ans=0;
	for(auto&& i:m)
		ans+=(i.second*(i.second-1))/2;

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


Measured memory_bytes: 4992
#include <iostream>
using namespace std;
int main(void){
  int a,b,c,ans=0,ans2=0;
  char ch;
  while(cin>>a>>ch>>b>>ch>>c){
    if(a*a +b*b == c*c)
         ans = ans + 1;
    if(a == b)
    ans2 = ans2 + 1;
    }
    cout << ans << endl;
    cout << ans2 << endl;
    return 0;
  }


Measured memory_bytes: 3112
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;

	static void solve() {
		int[] a=ir.nextIntArray(3);
		Arrays.sort(a);
		out.println(a[0]+a[1]==a[2]?"Yes":"No");
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


Measured memory_bytes: 22996
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    x, a, b = i_map()

    if abs(x-a) > abs(x-b):
        print('B')
    else:
        print('A')

if __name__ == '__main__':
    main()


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

int		main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int H, W;
	cin >> H >> W;
	vector<vector<char>> grid(H, vector<char>(W));
	rep(i, H) rep(j, W) cin >> grid.at(i).at(j);
	vector<int> skip_row, skip_col;
	rep(row, H) {
		if (count(grid.at(row).begin(), grid.at(row).end(), '#') == 0)
			skip_row.push_back(row);
	}
	bool skip;
	rep(col, W) {
		skip = true;
		rep(row, H) {
			if (grid.at(row).at(col) == '#') {
				skip = false;
				break;
			}
		}
		if (skip)
			skip_col.push_back(col);
	}
	bool new_line;
	rep(row, H) {
		new_line = true;
		rep(col, W) {
			if (count(skip_row.begin(), skip_row.end(), row)) {
				new_line = false;
				break;
			}
			if (count(skip_col.begin(), skip_col.end(), col))
				continue;
			cout << grid.at(row).at(col);
		}
		if (new_line)
			cout << "\n";
	}
}


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t x, y, z;
  std::cin >> x >> y >> z;
  std::swap(x, y);
  std::swap(x, z);
  std::cout << x << " " << y << " " << z << std::endl;
  return 0;
}


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

int main(){
    ll n,c;
    cin>>n>>c;
    ll rx[n],lx[n],rsum[n],lsum[n];
    for(int i=0;i<n;i++){
        cin>>rx[i]>>rsum[i];
        lx[n-i-1]=c-rx[i];
        lsum[n-i-1]=rsum[i];
    }
    for(int i=1;i<n;i++){
        rsum[i]+=rsum[i-1];
        lsum[i]+=lsum[i-1];
    }
    ll ans,rmax[n]={},lmax[n]={};
    rmax[0]=max(0LL,rsum[0]-rx[0]);
    for(int i=1;i<n;i++){
        rmax[i]=max(rmax[i-1],rsum[i]-rx[i]);
    }
    lmax[0]=max(0LL,lsum[0]-lx[0]);
    for(int i=1;i<n;i++){
        lmax[i]=max(lmax[i-1],lsum[i]-lx[i]);
    }
    ans=max(rmax[n-1],lmax[n-1]);
    for(int i=0;i<n-1;i++){
        ans=max(ans,rsum[i]-2*rx[i]+lmax[n-i-2]);
    }
    for(int i=0;i<n-1;i++){
        ans=max(ans,lsum[i]-2*lx[i]+rmax[n-i-2]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int INF = 1e9+7;
typedef pair<int,int> P;
int main() {
    int N;
    cin >> N;
    vector<P>AB(N);
    for(int i = 0; i < N; i++) {
        int A,B;
        cin >> A >> B;
        AB[i].first = B;
        AB[i].second = A;
    }
    sort(AB.begin(),AB.end());
    int cnt = 0;
    for(int i = 0; i < N; i++) {
        cnt+=AB[i].second;
        if(cnt > AB[i].first) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <stack>
#include <stdio.h>
using namespace std;
#define maxx 110000
typedef long long ll;

int main()
{
    int a,b;
    cin>>a>>b;
    if(a==b)
    cout<<a+b<<endl;
    else
    cout<<2*max(a,b)-1<<endl;
    return 0;
}

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

int main() {
  
int n,x;
cin>>n>>x;
int vec[n];
for(int i=0;i<n;i++){
  cin>>vec[i];
}
int sum=0,count=1;
for(int i=0;i<n;i++){
  sum=sum+vec[i];
  if(x<sum){
    break;
  }
  count++;
}

cout<<count<<endl;

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

public class Prog
{
    public void run()
    {
        bool goal = true;
        var input = Console.ReadLine().Split();
        int N = int.Parse(input[0]);
        int A = int.Parse(input[1]);
        int B = int.Parse(input[2]);
        int C = int.Parse(input[3]);
        int D = int.Parse(input[4]);
        string S = Console.ReadLine();
        if(C > D)
        {
            goal = false;
        }
        string X = S.Substring(A - 1, C - A + 1);
        string Y = S.Substring(B - 1, D - B + 1);
        if (goal)
        {
            if (X.Contains("##") == false && Y.Contains("##") == false)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
        else
        {
            string Z = S.Substring(B - 2, D - B + 3);
            if (X.Contains("##") == false && Z.Contains("...") == true)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
    public static void Main()
    {
        //var input = Console.ReadLine().Split();
        //int[] X = Array.ConvertAll(input, int.Parse);
        var prog = new Prog();
        prog.run();
    }
}

//Array.ConvertAll(int.Parse)

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

int main(){
   int n;
   cin >> n;
   int i = n;
   while (1){
      if (i%2 == 0 && i%n == 0){
         cout << i << endl;
         return 0;
      }
      i++;
   }
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val S = readLine()!!

    val A = "ABC"

    var res = 0L

    for (i in S.indices) {
        if (i + 3 > S.length) continue

        if (S.substring(i, i + 3) == A)
            res++
    }

    println(res)
}


Measured memory_bytes: 33780
#include <bits/stdc++.h>
using namespace std;
int main() {
   const double pi=3.14159265358979323846;
   long double A,B,H,M;
   cin >> A >> B >> H >> M;
   long double r = pi*(H/6.0 + M/(12*30.0))-pi*(M/30.0);
   if(r>pi) r = pi*(M/30.0) - pi*(H/6.0 + M/(12*30.0));
   cout << setprecision(20) <<(double)sqrt(A*A + B*B -2*A*B*cos(r));
}

Measured memory_bytes: 4172
#include <bits/stdc++.h>
#define ll long long
#define ui unsigned int
#define ull unsigned long long
#define bug(x) cerr << '\n' << (#x) << " = " << (x) << endl;
#define REP0(i, n) for(int i = 0, _n = (n); i < _n; ++i)
#define REP1(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define REPB0(i, n) for(int i = (n) - 1; i >= 0; --i)
#define REPB1(i, n) for(int i = (n); i > 0; --i)
#define FOR(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define FORB(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define X first
#define Y second

using namespace std;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef pair<double, double> dd;
typedef pair<float, float> ff;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int k, x;
	cin >> k >> x;
	FOR(i, x - k + 1, x + k - 1) cout << i << ' ';
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <limits>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}

int128_t L, R; 

int main(int argc, char **argv) {
    std::cin >> L >> R;
    
    if (2019 <= R - L) {
        std::cout << 0 << std::endl;
        return 0;
    } else {
        int ret = 2019;
        for (int i = L; i < R; i++) {
            for (int j = i + 1; j <= R; j++) {
                ret = std::min(ret, ((i%2019)*(j%2019))%2019);
            }
        }
        std::cout << ret << std::endl;
        return 0;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using P = pair<int, int>;
constexpr int INF = 1e9;

int main() {
    int t, n;
    while(cin >> t >> n, t || n) {
        vector<vector<int>> v(121, vector<int>(121, INF));
        for(int i=0; i<n; ++i) {
            int x, y;
            cin >> x >> y;
            v[x+60][y+60] = INF+1;
        }
        int sx, sy;
        cin >> sx >> sy;
        sx += 60;
        sy += 60;
    
        queue<P> que;
        que.push(make_pair(sx, sy));
        v[sx][sy] = 0;
        int dx[6] = {0, 1, 0, -1, 1, -1}, dy[6] = {1, 0, -1, 0, 1, -1};
        while(!que.empty()) {
            P p = que.front();
            que.pop();
            for(int i=0; i<6; ++i) {
                int nx = p.first + dx[i],
                    ny = p.second + dy[i];
                if(0 <= nx && nx < 121 && 0 <= ny && ny < 121 && v[nx][ny] == INF) {
                    que.push(make_pair(nx, ny));
                    v[nx][ny] = v[p.first][p.second] + 1;
                }
            }
        }
        int ret = 0;
        for(int i=0; i<v.size(); ++i) {
            for(int j=0; j<v[i].size(); ++j) {
                if(v[i][j] <= t) {
                    ret++;
                } 
            }
        }
        cout << ret << endl;
    }
}


Measured memory_bytes: 3204
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){
    int N;
    string s;

    cin >> N >> s;

    int ma = 0;

    for(int i = 1; i < N - 1; i++){
        map<char,int> mr, ml;
        string l = s.substr(0, i);
        string r = s.substr(i);

        int sum = 0;

        for(int j = 0; j < l.length(); j++){
            mr[l[j]] = 1;
        }

        for(int j = 0; j < r.length(); j++){
            if(mr[r[j]] == 1 && ml[r[j]] == 0){
                sum++;
                ml[r[j]] = 1;
            }
        }



        ma = max(sum, ma);
    }

    cout << ma << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Random;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		PrintWriter pw=new PrintWriter(System.out);
		int A=sc.nextInt();
		int B=sc.nextInt();
		int C=sc.nextInt();
		pw.println(Math.min(B/A, C));
		pw.close();
	}

	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public int nextInt() {
    	return Integer.parseInt(next());
    }
    
    public long nextLong() {
    	return Long.parseLong(next());
    }
}

Measured memory_bytes: 23252
#include<stdio.h>

int main(void){
  int a[3][3],b[11];
  int n,i,j,k,s=0;
/*入力部*/
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      scanf("%d",&a[i][j]);
    }
  }

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&b[i]);
  }

  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      for(k=0;k<n;k++){
        if(a[i][j]==b[k]){
          a[i][j]=0;
        }
      }
    }
  }

  i=0;

  while(i<3){
    if((a[i][0]==0)&&(a[i][1]==0)&&(a[i][2]==0)) {
      s=1;
      break;
    }else if((a[0][i]==0)&&(a[1][i]==0)&&(a[2][i]==0)) {
      s=1;
      break;
    }else if((a[i][0]==0)&&(a[i][1]==0)&&(a[i][2]==0)) {
      s=1;
      break;
    }else if((a[0][0]==0)&&(a[1][1]==0)&&(a[2][2]==0)) {
      s=1;
      break;
    }else if((a[2][0]==0)&&(a[1][1]==0)&&(a[0][2]==0)) {
      s=1;
      break;
    }
    i++;
  }

  if(s==0)  puts("No"); else  puts("Yes");
  
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
  
int main(){
  
int a,b,c,n,i;

scanf("%d\n", &n);

for(i=0;i<n;i++)
{
  scanf("%d %d %d\n", &a,&b,&c);

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

Measured memory_bytes: 580
import java.io.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {


		String[] O=toStringArray(nextString());
		String[] E=toStringArray(nextString());

		String ans="";
		for(int i=0;i<O.length+E.length;i++){
			if(i%2==1)
				ans+=E[i/2];
			else
				ans+=O[i/2];
		}
		System.out.println(ans);
	}




	public static String[] toStringArray(String s){
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for(int i=0;i<tmp.length;i++){
			tmp[i]=String.valueOf(c[i]);
		}
		return tmp;
	}
	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 20948
//デバッグ用ロジック削除
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    int ans = 0;
    for (int i=0;i<(S.length()/2);i++){
      if (S.charAt(i)!=S.charAt(S.length() -1 -i)){
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

typedef long long ll;

const ll INF = 2000000000;

struct Rec {
    ll x1, y1, x2, y2;

    Rec(ll x1 = 0, ll y1 = 0, ll x2 = 0, ll y2 = 0) : x1(x1), y1(y1), x2(x2), y2(y2) {
    }
};

struct Event {
    int type; //start 0, end 1
    int id;
    ll x;

    Event(int id, int type, ll x) : id(id), type(type), x(x) {
    }
};

struct EventCmp {

    bool operator()(const Event& a, const Event& b) {
        return (a.x < b.x) || (a.x == b.x && a.type > b.type);
    }
};

struct IntervalCmp {
    vector<Rec> recs;

    IntervalCmp(vector<Rec>& recs) : recs(recs) {
    }

    bool operator()(const int& a, const int& b) {
        return recs[a].y1 < recs[b].y1;
    }
};

ll intervalLength(vector<int>& intervals, vector<Rec>& recs, vector<bool>& flags) {
    ll start = -INF, end;
    ll total = 0;


    for (int idx : intervals) {
        if (flags[idx]) {
            Rec& cur = recs[idx];
            if (start == -INF) {
                start = cur.y1;
                end = cur.y2;
            }
            else if (cur.y1 <= end) {
                end = max(end, cur.y2);
            } else {
                total += end - start;
                start = cur.y1;
                end = cur.y2;
            }
            //cout << "s/e " << start << " " << end << endl;
        }
    }
    if (start != -INF) {
        total += end - start;
    }
    return total;
}

int main() {
    int n;
    cin >> n;
    vector<Rec> recs(n);
    vector<Event> events;

    for (int i = 0; i < n; i++) {
        Rec& rec = recs[i];
        cin >> rec.x1 >> rec.y1 >> rec.x2 >> rec.y2;
        events.push_back(Event(i, 0, rec.x1));
        events.push_back(Event(i, 1, rec.x2));
    }

    vector<int> intervals(n);
    for (int i = 0; i < n; i++) {
        intervals[i] = i;
    }

    sort(events.begin(), events.end(), EventCmp());
    sort(intervals.begin(), intervals.end(), IntervalCmp(recs));

    //    for (int i = 0; i < n; i++) {
    //        cout << recs[i].x1 << " " << recs[i].y1 << " " << recs[i].x2 << " " << recs[i].y2 << endl;
    //    }

    int lastX = 0;
    ll lastLen = 0;
    ll area = 0;

    vector<bool> flags(n, false);
    for (Event event : events) {
        //cout << "event " << event.type << " " << event.id << " " << event.x << endl;
        area += (event.x - lastX) * lastLen;
        lastX = event.x;
        if (event.type == 0) {
            flags[event.id] = true;
        } else {
            flags[event.id] = false;
        }
        lastLen = intervalLength(intervals, recs, flags);
    }
    cout << area << endl;
}

Measured memory_bytes: 3940
N = int(input())
A = list(map(int, input().split()))
mod = 10**9+7
 
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
 
a = 1
for i in range(N):
    a = lcm(a, A[i])
 
ans = 0
for i in range(N):
    ans += a * pow(A[i], mod-2, mod)
 
print(ans % mod)

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

#define fi first
#define se second
#define U unsigned
#define P std::pair<int,int>
#define LL long long
#define pb push_back
#define MP std::make_pair
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define FOR(i,a,b) for(int i = a;i <= b;++i)
#define ROF(i,a,b) for(int i = a;i >= b;--i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl

const int MAXN = 2e5 + 5;
const int ha = 998244353;

int sm[MAXN];
inline int qpow(int a,int n=ha-2){
	int res = 1;
	while(n){
		if(n & 1) res = 1ll*res*a%ha;
		a = 1ll*a*a%ha;
		n >>= 1;
	}
	return res;
}
int fac[MAXN],inv[MAXN];
inline int C(int n,int m){
	if(n < m) return 0;
	if(!m) return 1;
	return 1ll*fac[n]*inv[m]%ha*inv[n-m]%ha;
}
int f[MAXN][2];
int main(){
	fac[0] = 1;FOR(i,1,MAXN-1) fac[i] = 1ll*fac[i-1]*i%ha;
	inv[MAXN-1] = qpow(fac[MAXN-1]);
	ROF(i,MAXN-2,0) inv[i] = 1ll*inv[i+1]*(i+1)%ha;
	int n,m,K;scanf("%d%d%d",&n,&m,&K);int ans = 0;
	FOR(k,0,K){
		//(1,0) -> (n,k)
		//(1,0) n-k-1
		//(1,1) k
		(ans += 1ll*C(n-1,k)*m%ha*qpow(m-1,n-k-1)%ha) %= ha;
		// (ans += 1ll*C(n,k)*qpow(m-1,n-k)%ha)%=ha;
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)

using ll = long long;

ll r,s,p;
vector<ll> y,x,d;

signed main() {
  cin >> r >> s >> p;

  y.resize(p);x.resize(p);
  rep(i,p) cin >> y[i] >> x[i];

  d.resize(p);

  rep(i,p) {
    d[i] = abs(x[i] - s) + ((x[i] <= s) ? 1 : 0);
    d[i] += r - y[i] + 1;
  }

  sort(d.begin(),d.end(),greater<ll>());

  ll ans = 0;

  rep(i,p) {
    ans = max(ans,d[i] + i);
  }

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



Measured memory_bytes: 14312
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <iomanip>
#include <queue>
#include <map>
#include <set>
#include <random>
#include <sstream>
#include <stack>
#include <deque>

using namespace std;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

int H, W;

int main() {
  cin >> H >> W;
  int c[26] = {};
  rep(i,H) rep(j,W) {
    char d;
    cin >> d;
    c[d-'a']++;
  }
  int four = (H / 2) * (W / 2);
  int two = (H % 2 == 1) * (W / 2) + (W % 2 == 1) * (H / 2);
  // cout << four << " " << two << endl;
  rep(i,26) {
    four -= c[i] / 4;
    c[i] %= 4;
    if (four < 0) {
      c[i] += -four * 4;
      four = 0;
    }
    if (four == 0) break;
  }
  if (four > 0) {
    cout << "No" << endl;
    return 0;
  }
  rep(i,26) {
    two -= c[i] / 2;
    c[i] %= 2;
    if (two < 0) {
      c[i] += -two * 2;
      two = 0;
    }
    if (two == 0) break;
  }
  if (two > 0) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;

public class Main {
	public static void main(String[] args) {
		FastReader r = new FastReader();		
		int[] arr = r.ria();
		String[] lines = r.rsaml(arr[0]);
		StringBuilder sb = new StringBuilder();
		sb.append(al(String.join("", Collections.nCopies(arr[1]+2, "#"))));
		for(int i = 0; i<lines.length; i++)
		{
			for(int c = 0; c<lines[i].length(); c++)
			{
				if(c==0) sb.append("#");
				sb.append(lines[i].charAt(c));
				if(c==lines[i].length()-1) sb.append("#");
			}
			sb.append(al(""));
		}
		sb.append(al(String.join("", Collections.nCopies(arr[1]+2, "#"))));
		print(sb.toString());
	}

	public static void rolling(int[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}
	
	public static void rolling(long[] arr) {
		if (arr.length < 2)
			return;
		for (int i = 1; i < arr.length; i++)
			arr[i] += arr[i - 1];
	}

	public static void reverse(int[] arr) {
		for (int i = 0; i < arr.length / 2; i++) {
			int temp = arr[i];
			arr[i] = arr[arr.length - 1 - i];
			arr[arr.length - 1 - i] = temp;
		}
	}
	
	public static String al(String s) {
		return s + "\n";
	}

	public static void print(String s) {
		System.out.println(s);
	}

	public static void print(long s) {
		System.out.println(s);
	}

	public static void print(int s) {
		System.out.println(s);
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		int ri() {
			return Integer.parseInt(str());
		}

		long rl() {
			return Long.parseLong(str());
		}

		double rd() {
			return Double.parseDouble(str());
		}

		String str() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		String[] rsa() {
			return str().split(" ");
		}

		int[] ria() {
			String[] s = rsa();
			int[] arr = new int[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(s[i]);
			return arr;
		}

		long[] rla() {
			String[] s = rsa();
			long[] arr = new long[s.length];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(s[i]);
			return arr;
		}

		char[] rca() {
			String s = str();
			char[] arr = new char[s.length()];
			for (int i = 0; i < arr.length; i++)
				arr[i] = s.charAt(i);
			return arr;
		}
		
		String[] rsaml(int m) {
			String[] arr = new String[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = str();
			return arr;
		}

		int[] riaml(int m) {
			int[] arr = new int[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Integer.parseInt(str());
			return arr;
		}

		long[] rlaml(int m) {
			long[] arr = new long[m];
			for (int i = 0; i < arr.length; i++)
				arr[i] = Long.parseLong(str());
			return arr;
		}
	}
}

class Node {
	public int val;
	public boolean visited;
	public Node(int v) { val=v; }
}

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int solve(vector<vll> &c, vector<pii> &m, int s, int e1) {
  int e = e1 - 1;
  if (c[s][e1] != 0) return c[s][e1];
  
  if (e1 - s == 2) {
    c[s][e1] = m[s].first * m[s].second * m[e].second;
    return c[s][e1];
  }

  ll n_calc = LLONG_MAX;
  for (int i = s + 1; i < e1; i++) {
    ll total = 0;
    
    if (i - s > 1) {
      c[s][i] = solve(c, m, s, i);
      total += c[s][i];
    }
    
    if (e1 - i > 1) {
      c[i][e1] = solve(c, m, i, e1);
      total += c[i][e1];
    }

    total += m[s].first * m[i].first * m[e].second;
    
    n_calc = min(n_calc, total);
  }

  c[s][e1] = n_calc;
  return c[s][e1];
}

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

  vector<pii> m(n);
  rep(i, n) cin >> m[i].first >> m[i].second;

  if (n == 1) {
    cout << 0 << endl;
    return 0;
  }

  vector<vll> c(n + 1, vll(n + 1, 0));
  cout << solve(c, m, 0, n) << endl;
}



Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define sz(x) int(x.size())
using ll = long long;
const ll LLINF = numeric_limits<long long>::max();
const int mod = 1000000007;
const int INF = 1001001001;

int main()
{
    ll x;
    cin >> x;

    ll a=100;
    ll d=0;
    while(1){
        d++;
        a *=1.01;
        if(a>=x) break;
    }
    cout << d;
    return 0;
}

Measured memory_bytes: 3604
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder.ABC079.C
{
    class Program
    {
        static void Main ()
        {
            var inputs = Console.ReadLine ().Select (elem => int.Parse (elem.ToString ()))
                .ToArray ();
            const int aim = 7;
            int result = 0;
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    for (int k = 0; k < 2; k++)
                    {
                        if (i == 0) result = inputs[0] + inputs[1];
                        else result = inputs[0] - inputs[1];
                        if (j == 0) result += inputs[2];
                        else result -= inputs[2];
                        if (k == 0) result += inputs[3];
                        else result -= inputs[3];
                        if (result == aim)
                        {
                            var ops = new char[] { '+', '-' };
                            Console.WriteLine (inputs[0].ToString () + ops[i] + inputs[1] + ops[j] + inputs[2] + ops[k] + inputs[3] + "=7");
                            return;
                        }
                    }
                }
            }
        }
    }
}

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

int main() {
  int N, A;
  cin >> N >> A;
  
  if (N % 500 == 0 || N <= A) {
     cout << "Yes" << endl;
  }
  
  else if (N % 500 <= A) {
    cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }
  
}  

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort

s = []
k = m.times.
  map { gets.split.map(&:to_i) }.
  sort_by { |b, c| -c }.
  each { |b, c| s.push(*([c] * b)); break if s.size >= n }

a.size.times do |i|
  a[i] = [a[i],s[i]].compact.max
end

puts a.reduce(&:+)

Measured memory_bytes: 21024
#include<iostream>
template<class T> T gcd(T a,  T b) {return b ? gcd(b, a % b) : a;}
template<class U> U lcm( U m, U n ){if((0 == m )||( 0 == n ))return 0; return ((m / gcd(m, n)) * n); }
int main(){
    long long a,b,c,d;
    std::cin >> a >> b >> c >> d;
    long long LCM = lcm(c,d);
    long long c_inA = (a-1) / c, d_inA = (a-1)/d;
    long long gcd_inA = (a-1) / LCM ;
    long long  sum = c_inA + d_inA - gcd_inA;
    std::cout << (b - a + 1) - ((b) / c + (b)/d - (b) / LCM - sum) << std::endl;
}



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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 998244353
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	int n;cin>>n;
	vl d(n+1,0);
	for(int i=0;i<n;++i){
		int a;cin>>a;
		d[a]++;
        if(i==0&&a!=0){
        cout<<0<<endl;
        return 0;
        }
	}
	if(d[0]!=1){
		cout<<0<<endl;
		return 0;
	}
	ll ans=1;
	for(int i=1;i<n;++i){
		for(int j=0;j<d[i];++j){
			ans*=d[i-1];
			ans%=MOD;
		}
	}
	cout<<ans%MOD<<endl;
}


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

int main(){
	int N;
	cin>>N;
	int h[101],m[101];
	for(int i=0;i<N;i++){
		cin>>h[i]>>m[i];
	}
	h[N]=24;
	m[N]=0;
	int M;
	cin>>M;
	int k[101],g[101];
	for(int j=0;j<M;j++){
		cin>>k[j]>>g[j];
	}
	k[M]=24;
	g[M]=0;
	for(int i=0,j=0;i<N||j<M;){
		if((h[i]==k[j])&&(m[i]==g[j])){
			cout<<h[i]<<':'<<m[i]/10<<m[i]%10;
			i++;
			j++;
		}else if((h[i]<k[j])||((h[i]==k[j])&&(m[i]<g[j]))){
			cout<<h[i]<<':'<<m[i]/10<<m[i]%10;
			i++;
		}else{
			cout<<k[j]<<':'<<g[j]/10<<g[j]%10;
			j++;
		}
		if((i==N)&&(j==M)){
			cout<<endl;
		}else{
			cout<<' ';
		}
	}
	
	return 0;
}

Measured memory_bytes: 3084
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    let max_n = 21;
    let mut right = 0;
    let mut check = vec![false; max_n];
    let mut ans = 0;
    //rightの初期位置決める rightは条件をみたせなかった最初の位置
    'outer: for i in 0..n {
        let mut tmp = vec![false; max_n];
        for j in 0..max_n {
            if (a[i] >> j) & 1 != 0 {
                if check[j] {
                    right = i;
                    break 'outer;
                }
                tmp[j] = true;
            }
        }
        for j in 0..max_n {
            check[j] |= tmp[j];
        }
        if i == n - 1 {
            right = n;
        }
    }
    ans += right;
    //println!("right {}", right);
    for l in 0..n - 1 {
        for i in 0..max_n {
            if (a[l] >> i) & 1 != 0 {
                check[i] = false;
            }
        }
        'r: for r in right..n {
            let mut tmp = vec![false; max_n];
            for i in 0..max_n {
                if (a[r] >> i) & 1 != 0 {
                    if check[i] {
                        right = r;
                        break 'r;
                    }
                    tmp[i] = true;
                }
            }
            // rが検査に通った
            for j in 0..max_n {
                check[j] |= tmp[j];
            }
            if r == n - 1 {
                right = n;
            }
        }
        ans += right - l - 1;
        //println!("l: {} ans {} right: {}", l, ans, right);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4780