akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,K,C;
    cin>>N>>K>>C;
    string S;
    cin>>S;
    int dp1[N+10],dp2[N+10],lastI=1000000000;
    dp1[N]=0;
    for(int i=N-1;i>=0;i--){
        if(lastI-i>C && S.at(i)=='o'){
            lastI=i;
            dp1[i]=dp1[i+1]+1;
        }
        else{
            dp1[i]=dp1[i+1];   
        }
    }
    lastI=-1000000000;
    for(int i=0;i<N;i++){
        if(i-lastI>C && S.at(i)=='o'){
            lastI=i;
            if(i==0){
                dp2[i]=1;
            }
            else{
                dp2[i]=dp2[i-1]+1;
            }
        }
        else{
            dp2[i]=dp2[i-1];   
        }
    }
    for(int i=0;i<N;i++){
        if(i==0){
            if(dp1[i+1]<K){
                cout<<i+1<<endl;
            }
        }
        else if(i==N-1){
            if(dp2[i-1]<K){
                cout<<i+1<<endl;
            }
        }
        else{
            if(dp1[i+1]+dp2[i-1]<K){
                cout<<i+1<<endl;
            }
        }
    }
}

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


def main():
    N, K = map(int, input().split())
    X = list(map(int, input().split()))
    result = []

    for i in range(N - K + 1):
        l = X[i]
        r = X[i + K - 1]
        result.append(min(abs(l) + abs(r - l), abs(r) + abs(l - r)))

    print(min(result))


if __name__ == "__main__":
    main()


Measured memory_bytes: 14384
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    S=input()
    ans=0
    for s,t in zip(S,S[::-1]):
        ans+=s!=t

    print(ans//2)
resolve()

Measured memory_bytes: 38384
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

const int INF = 1e9;
const long long LINF = 1e18;

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

    if (A == 1 && B == 2) {
        cout << 3 << endl;
    } else if (A == 1 && B == 3) {
        cout << 2 << endl;
    } else if (A == 2 && B == 3) {
        cout << 1 << endl;
    } else if (A == 2 && B == 1) {
        cout << 3 << endl;
    } else if (A == 3 && B == 1) {
        cout << 2 << endl;
    } else if (A == 3 && B == 2) {
        cout << 1 << endl;
    } else {
        cout << "hoge" << endl;
    }

    return 0;
}


Measured memory_bytes: 888
import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(new BufferedInputStream(System.in));
		long a, b;
		while (scanner.hasNext()) {
			a = scanner.nextLong();
			b = scanner.nextLong();
			long gcd = gcd(a, b);
			System.out.println(gcd + " " + lcm(a, b, gcd));

		}
	}

	public static long gcd(long a, long b) {
		long max = Math.max(a, b);
		long min = Math.min(a, b);
		if (max % min == 0)
			return min;
		return gcd(min, max % min);
	}

	public static long lcm(long a, long b, long gcd) {
		return a * b / gcd;
	}
}

Measured memory_bytes: 12000
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const LL MOD = 1000000007LL;
int p[200000];
int bit[200001];
int n;
int sum(int i) {
	int s = 0;
	while (i > 0) {
		s += bit[i];
		i -= i&-i;
	}
	return s;
}
void add(int i, int x) {
	while (i <= n) {
		bit[i] += x;
		i += i&-i;
	}
}
int main() {
	string S;
	cin >> S;
	int S_cnt[26] = {};
	for (int i = 0; i < S.size(); i++) S_cnt[S[i] - 'a']++;
	int odd = 0;
	char m = 0;
	for (int i = 0; i < 26; i++) if (S_cnt[i] % 2 == 1) odd++, m = 'a' + i;
	if (odd > 1) {
		cout << -1 << endl;
		return 0;
	}
	string T = "";
	int T_cnt[26] = {};
	for (int i = 0; i < S.size(); i++) {
		if (T_cnt[S[i] - 'a'] < S_cnt[S[i] - 'a'] / 2) {
			T.push_back(S[i]);
			T_cnt[S[i] - 'a']++;
			if (T.size() == S.size() / 2) break;
		}
	}
	string t = T;
	reverse(t.begin(), t.end());
	if (m) T = T + string(1, m) + t;
	else T = T + t;
	vector<int> pos[26];
	int idx[26] = {};
	for (int i = 0; i < T.size(); i++) pos[T[i] - 'a'].push_back(i);
	for (int i = 0; i < S.size(); i++) p[i] = pos[S[i] - 'a'][idx[S[i] - 'a']++] + 1;
	LL ans = 0;
	n = S.size();
	for (int i = 0; i < n; i++) {
		ans += i - sum(p[i]);
		add(p[i], 1);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3344
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

  if(D[u]==0) printf("root, ");
  else if(T[u].l==NIL) printf("leaf, ");
  else printf("internal node, ");
  
  printf("[");
  for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if(i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
  
}

void calcDepth(int u, int p){
  D[u] = p;
  if(T[u].r!=NIL) calcDepth(T[u].r,p);
  if(T[u].l!=NIL) calcDepth(T[u].l,p+1);
}

int main(){
  int i, j, k;
  int n;
  int id, sib, child;
  int root = NIL;
  scanf("%d", &n);
  for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;
  
  for(i=0; i<n; i++){
    scanf("%d %d", &id, &k);
    for(j = 0, sib = NIL; j<k; j++){ //子を入力する (input children)
      scanf("%d", &child);
      T[child].p = id;
      if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)
      else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
      sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
    }
  }

  //根を求める (find the root)
  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }
  
  //それぞれのノードの深さを求める (find depth of each node)
  calcDepth(root, 0);

  //出力 (output)
  for(i=0; i<n; i++) print(i);
  
  return 0;
}      



Measured memory_bytes: 6412
#include<bits/stdc++.h>
using namespace std;
#define int long long int
 

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<setprecision(10)<<fixed;
	
	int h,a;
	cin>>h>>a;
	int t=h/a;
	if(h%a!=0)
		t++;
	cout<<t<<endl;
	return 0;
}



Measured memory_bytes: 256
// 
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define e_b emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    
    ll n;
    cin>>n;
    vector<ll> com(n);
    rep(i,n){
        cin>>com[i];
    } 
    sort(all(com),greater<ll>());
    ll max1=com[0],max2=com[1];
    ll total=max1;
    queue<ll> num;
    num.push(max2);
    int count=0;
    for(int i=2;i<n;i++){
        total+=max2;
        num.push(com[i]);
        count++;
        if(count==2){
            num.pop();
            max2=num.front();
            count=0;
        }
    }
    cout<<total<<endl;
    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long n, m, k;
    cin >> n >> m >> k;
    vector<long long> a(n), b(m);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }
    vector<long long> a2(n + 1), b2(m + 1);
    for (int i = 0; i < n; i++) {
        a2[i + 1] = a2[i] + a[i];
    }
    for (int i = 0; i < m; i++) {
        b2[i + 1] = b2[i] + b[i];
    }
    long long ans = 0;
    long long j = m;
    for (int i = 0; i < n + 1; i++) {
        if (a2[i] > k) {
            break;
        }
        while (b2[j] > k - a2[i]) {
            j -= 1;
        }
        ans = max(ans, i + j);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 9484
N,K = map(int,input().split())
td = [[int(i) for i in input().split()] for _ in range(N)]
td.sort(key=lambda x:x[1],reverse=True)
ans = 0
ls = set()
dl = []
for i in range(K):
    ans += td[i][1]
    if not td[i][0] in ls:
        ls.add(td[i][0])
    else:
        dl.append(td[i][1])
ans = ans + len(ls)**2
res = ans
for i in range(K,N):
    if not dl:
        break
    if td[i][0] in ls:
        continue
    ans += len(ls)*2+1
    ans += td[i][1]
    ans -= dl[-1]
    del dl[-1]
    res = max(res,ans)
    ls.add(td[i][0])
print(res)


Measured memory_bytes: 68312
import sys
def f(a,b,c):
    return a if a!="s"and a==b==c else 0
for s in sys.stdin:
    for i in range(3):
        c=f(*s[i:9:3])
        if c: break
        j=i*3
        c=f(*s[j:j+3])
        if c: break
    else:
        a=s[4]
        c=a if f(*s[0:9:4])or f(*s[2:7:2]) else "d"
    print c

Measured memory_bytes: 4220
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  100000000000007

int v[400][400];

int main(){
	/* int k = 353;*/
	int k = 43;
	int n = (k+1)*k+1;
	cout << n << " " << k+1 << endl;
	int x = 2;
	for(int i=0;i<=k;i++){
		for(int j=0;j<=k;j++){
			if(j==0){
				v[i][j] = 1;
			}else{
				v[i][j] = x;
				x++;
			}
		}
	}
	for(int i=0;i<=k;i++){
		for(int j=0;j<k;j++){
			cout << v[i][j] << " ";
		}
		cout << v[i][k] << endl;
	}
	VVI ans;	
	for(int j=0;j<k;j++){
		for(int p=1;p<=k;p++){
			VI a(k+1);
			a[0] = v[0][j+1];
			a[1] = v[1][p];
			int tmp = p-1;
			for(int c=2;c<=k;c++){
				a[c] = 2+k*c;
				tmp = (tmp+j)%k;
				a[c] += tmp;
			}
			ans.push_back(a);
		}
	}
	
	for(int i=0;i<ans.size();i++){
		for(int j=0;j<ans[i].size()-1;j++){
			cout << ans[i][j] << " ";
		}
		cout << ans[i][ans[i].size()-1] << endl;
	}

	return 0;
}

Measured memory_bytes: 1024
s = input()
k = int(input())
ans = 1
if k <= len(s):
    if s[:k] == "1" * k:
        ans = 1
    else:
        for i in range(len(s)):
            if s[i] != "1":
                ans = int(s[i])
                break
else:
    for i in range(len(s)):
        if s[i] != "1":
            ans = int(s[i])
            break
print(ans)

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

template <uint32_t mod>
class modint{
    uint64_t value;
public:
    constexpr modint(const int64_t x=0) noexcept: value(x % mod + (x < 0 ? mod : 0)){ }
    constexpr explicit operator uint64_t() const noexcept{ return value; }
    constexpr modint inverse() const noexcept{ return pow(*this, mod-2); }
    constexpr bool operator==(const modint &rhs) const noexcept{ return value == rhs.value; }
    constexpr bool operator!=(const modint &rhs) const noexcept{ return value != rhs.value; }
    constexpr modint operator+() const noexcept{ return modint(*this); }
    constexpr modint operator-() const noexcept{ return modint(mod - value); }
    constexpr modint operator+(const modint &rhs) const noexcept{ return modint(*this) += rhs; }
    constexpr modint operator-(const modint &rhs) const noexcept{ return modint(*this) -= rhs; }
    constexpr modint operator*(const modint &rhs) const noexcept{ return modint(*this) *= rhs; }
    constexpr modint operator/(const modint &rhs) const noexcept{ return modint(*this) /= rhs; }
    constexpr modint &operator+=(const modint &rhs) noexcept{
        if((value += rhs.value) >= mod) value -= mod;
        return *this;
    }
    constexpr modint &operator-=(const modint &rhs) noexcept{ return *this += mod - rhs.value; }
    constexpr modint &operator*=(const modint &rhs) noexcept{
        if((value *= rhs.value) >= mod) value %= mod;
        return *this;
    }
    constexpr modint &operator/=(const modint &rhs) noexcept{ return *this *= rhs.inverse(); }
    constexpr modint operator++(int) noexcept{
        modint ret(*this);
        if((++value) >= mod) value -= mod;
        return ret;
    }
    constexpr modint operator--(int) noexcept{
        modint ret(*this);
        if((value += mod - 1) >= mod) value -= mod;
        return ret;
    }
    constexpr modint &operator++() noexcept{ return *this += 1; }
    constexpr modint &operator--() noexcept{ return *this -= 1; }
    friend std::ostream &operator<<(std::ostream &os, const modint<mod> &x){ return os << x.value; }
    friend std::istream &operator>>(std::istream &is, modint<mod> &x){
        int64_t i;
        is >> i;
        x = modint<mod>(i);
        return is;
    }
    friend constexpr modint<mod> pow(const modint<mod> &x, uint64_t y){
        modint<mod> ret{1}, m{x};
        while(y > 0){
            if(y & 1) ret *= m;
            m *= m;
            y >>= 1;
        }
        return ret;
    }
};
constexpr int64_t mod = 1000000007;

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

    int n;
    cin >> n;
    static modint<mod> dp[1000000], sum[1000000];
    modint<mod> nsq = pow(modint<mod>{n-1}, 2);

    dp[0] = 1; dp[1] = n;
    sum[0] = 1; sum[1] = n+1;
    for(int i=2;i<=n;++i){
        dp[i] = dp[i-1] + nsq;
        if(i-3 >= 0) dp[i] += sum[i-3];
        dp[i] += n-1 - (i-3) - 1;
        sum[i] = sum[i-1] + dp[i];
    }
    cout << dp[n] << endl;

    return 0;
}

Measured memory_bytes: 15872
H,W = map(int,input().split())
c = []
dicta = {}
dicta[-1] = 0
for i in range(10):
    c.append(list(map(int,input().split())))
    dicta[i] = 0
c = [i for i in zip(*c)]
for i in range(H):
    a = list(map(int,input().split()))
    for i in a:
        dicta[i] += 1
dicta.pop(-1)
cost = [0 for i in range(10)]
def dijkstra_heap(start,node,cost):
    import heapq
    d = [float('inf') for i in range(node)]
    used = [False for i in range(node)]
    d[start] = 0
    d2 = [[0,start]]
    heapq.heapify(d2)
    while d2:
        c,v = heapq.heappop(d2)
        if used[v]:
            continue
        used[v] = True
        for j in range(node):
            d[j] = min(d[j],d[v]+cost[v][j])
            if not used[j]:
                heapq.heappush(d2,[d[j],j])
    return d

cost = dijkstra_heap(1,10,c)
ans = 0
for k,v in dicta.items():
    ans += v*cost[k]
print(ans)



Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main(){
	int n;scanf("%d",&n);
	bool flag=false;
	rep(i,n){
		int a;scanf("%d",&a);
		if(a%2)flag=true;
	}
	puts(flag?"first":"second");
}

Measured memory_bytes: 256
# ABC052 C - Factors of Factorial
n = int(input())
mod = 10**9 + 7

def factorization(n):
    retlist = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            retlist.append([i, cnt])

    if temp!=1:
        retlist.append([temp, 1])

    if retlist==[]:
        retlist.append([n, 1])

    return retlist

G = []
H = [0]*(n+1)

for i in range(1,n+1):
    FRA = factorization(i)
    for fra in FRA:
        G.append(fra)

for i in range(len(G)):
    H[G[i][0]] += G[i][1]

H = [int(h)+1 for h in H]
ans = 1
for i in range(len(H)):
    if i >=2:
        ans *= H[i]
        ans %= mod
print(ans)

Measured memory_bytes: 3188
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


n = ni()
a = list(li())

absmin = 10**18
mnscnt = 0
ans = 0

for ai in a:
    if ai < 0:
        mnscnt += 1

    absmin = min(absmin, abs(ai))
    ans += abs(ai)

if mnscnt % 2:
    print(ans - 2*absmin)
else:
    print(ans)

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

using namespace std;

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

int32_t main(){
	cin.tie(0); ios::sync_with_stdio(0);
	
	int n;
	cin >> n;
	ld h[n], t[n];
	for(int i = 0; i < n; i++){
		cin >> h[i];
		t[i] = 1 - h[i];
	}
	
	vector<ld> dp(n+1, 0);
	dp[0] = 1;
	for(int moeda = 0; moeda < n; moeda++){
		for(int heads = moeda + 1; heads >= 0; heads--){
			dp[heads] = dp[heads] * t[moeda];
			if(heads)
				dp[heads] += dp[heads-1] * h[moeda];
		}
	}
	ld ans = 0;
	
	for(int i = n / 2 + 1; i <= n; i++){
		ans += dp[i];
	}
	
	cout << setprecision(20) << ans << endl;
}


Measured memory_bytes: 384
N, M = map(int, input().split())

ac = [False] * N
wa = [0] * N
for _ in range(M):
    p, S = input().split()
    p = int(p) - 1
    if S == 'AC':
        ac[p] = True
    else:
        if not ac[p]:
            wa[p] += 1

a = 0
b = 0
for i in range(N):
    if ac[i]:
        a += 1
        b += wa[i]
print(*[a, b])


Measured memory_bytes: 4596
import math

n = int(input())

c = 0

k = int(math.log10(n)) 

for i in range(k+1):
    if i % 2 == 0 :
        if n < (10 ** (i+1)) :
            c = c + (n - 10 ** i) + 1
        else :
            c = c + (10 ** (i+1) - 10 ** i)

print(c)

Measured memory_bytes: 3060
n = gets.to_i
as = gets.split.map(&:to_i)
bcs = as.map { |a| [a + 1, a - 1] }.flatten

count = [*as, *bcs].each_with_object(Hash.new(0)) do |n, h|
  h[n] += 1
end.sort_by { |_, v| [-v] }

puts count[0][1]


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

const int INF = 1<<29;

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int change_d[5] = {0, 1, 2, 3, 0};
  while (true) {
    int w, h;
    cin >> w >> h;
    if (w == 0 && h == 0) break;
    int ope[31][31], dist[31][31][4], ch_cost[4];
    REP(i, h) REP(j, w) cin >> ope[i][j];
    REP(i, 4) cin >> ch_cost[i];
    REP(i, h) REP(j, w) REP(k, 4) dist[i][j][k] = INF;
    dist[0][0][1] = 0;
    priority_queue<T> pque;
    pque.push(T(0, 0, 1));
    while (!pque.empty()) {
      int d, r, c, dir;
      tie(d, r, dir) = pque.top(); pque.pop();
      d = -d, c = r % w, r /= w;
      //cout << c << ',' << r << ',' << dir << ':' << d << endl;
      if (dist[r][c][dir] < d) continue;
      int default_d = ope[r][c] != 4 ? (dir + change_d[ope[r][c]]) % 4 : 4;
      REP(i, 4) {
	int nd = (dir + i) % 4, nr = r + dr[nd], nc = c + dc[nd], cost = (nd == default_d ? 0 : ch_cost[i]);
	//cout << nr << ',' << nc << endl;
	if (0 <= nr && nr < h && 0 <= nc && nc < w && dist[nr][nc][nd] > d + cost) {
	  dist[nr][nc][nd] = d + cost;
	  pque.push(T(-dist[nr][nc][nd], nr * w + nc, nd));
	}
      }      
    }
    int ret = INF;
    REP(i, 4) ret = min(ret, dist[h-1][w-1][i]);
    cout << ret << endl;
  }
  return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (1e9)

ll n, k;
vector<ll> vec;

int check(ll p) {
  int j = 0;
  for(int i = 0; i < k; i++) {
    ll capa = p;
    while(j < vec.size()) {
      if(capa >= vec[j]) {
        capa -= vec[j];
        j++;
      } else break;
    }
  }
  if(j == vec.size()) return 1;
  else return 0;
}

int main() {
  cin >> n >> k;
  ll tmp;
  for(int i = 0; i < n; i++) {
    cin >> tmp;
    vec.push_back(tmp);
  }

  ll left = 0, right = 1e9, mid;
  while(left != right) {
    mid = (left + right) / 2;
    if(check(mid) == 1) right = mid;
    else left = mid + 1;
  }

  cout << left << endl;

  return 0;
}


Measured memory_bytes: 3940
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double a = Integer.parseInt(sc.next());
		double b = Integer.parseInt(sc.next());
		double c  = Integer.parseInt(sc.next());

		System.out.println((int)Math.min(Math.floor(b/a), c));
	}
}

Measured memory_bytes: 20820
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

n, y = MAP()
for i in range(y // 10000 + 1):
    for j in range((y - 10000 * i) // 5000 + 1):
        if y - 10000 * i - 5000 * j == 1000 * (n - i - j):
            print(i, j, n - i - j)
            exit()
print(-1, -1, -1)

Measured memory_bytes: 61928
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;

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

ll lcm(ll a,ll b){
    a / gcd(a,b) * b;
}
const ll mod = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    vector<pair<double,double>> p(n);
    double N_kai = n;

    for (int i = 0;i < n;i++){
        double x,y;
        cin >> x >> y;
        p[i] = make_pair(x,y);
        if (i == 0) continue;
        N_kai *= i;
    }

    sort(p.begin(),p.end());
    double sum = 0;
    int j = 0;
    do {
        for (int i = 0;i < n - 1;i++){
            sum += sqrt(pow(p[i].first - p[i+1].first,2) + pow(p[i].second - p[i+1].second,2));
        }
    }while(next_permutation(p.begin(),p.end()));

    cout << setprecision(10) << sum / N_kai * 1.0 << endl;
    
}   

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <time.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FFOR(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,b) FOR(i,0,b)
#define RREP(i,b) FFOR(i,1,b)
#define PB push_back
#define F first
#define S second
#define BE(c) c.begin(),c.end()
using namespace std;
typedef long long LL;
typedef int ut;
typedef long double ld;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut> VI;
typedef pair<pr,pr> ppr;
typedef priority_queue<pr,Vpr, greater<pr> > PQ;
const int SIZE=1e+5 + 1;
const ut INF=1<<30;
const ld eps=1e-6;
const LL mod=1e+9 + 7;

int tdx[] = {0, 1, 0, -1}, tdy[] = {-1, 0, 1, 0};
int kdx[] = {0, -1, 0, 1}, kdy[] = {1, 0, -1, 0};

int W, H;
int maze[64][64];

typedef struct State {
	int tx, ty, kx, ky, d;
	State(int tx, int ty, int kx, int ky, int d) : tx(tx), ty(ty), kx(kx), ky(ky), d(d){}
	
	bool operator < (const State s) const {
		if(tx != s.tx) return tx < s.tx;
		if(ty != s.ty) return ty < s.ty;
		if(kx != s.kx) return kx < s.kx;
		if(ky != s.ky) return ky < s.ky;
		return false;
	}
} State;

bool check(int x, int y){
	return x >= 0 && x < W && y >= 0 && y < H && maze[y][x] == 0;	
}

int main() {
	while(cin >> W >> H && W){
		int tx, ty, kx, ky;
		memset(maze, 0, sizeof(maze));
		cin >> tx >> ty >> kx >> ky;
		tx--; ty--; kx--; ky--;
		REP(i,H)REP(j,W)
			scanf("%d", &maze[i][j]);
			
		queue<State> que;
		que.push(State(tx, ty, kx, ky, 0));
		map<State, bool> visited;
		bool ok = false;
		while(!que.empty()){
			State s = que.front(); que.pop();
			if(s.d >= 100)
				continue;
			if(s.tx == s.kx && s.ty == s.ky){
				cout << s.d << endl;
				ok = true;
				break;
			}
			REP(i,4){
				int ntx = s.tx + tdx[i], nty = s.ty + tdy[i];
				int nkx = s.kx + kdx[i], nky = s.ky + kdy[i];
				if(!check(ntx, nty)){
					ntx = s.tx;
					nty = s.ty;
				}
				if(!check(nkx, nky)){
					nkx = s.kx;
					nky = s.ky;
				}
				State nState = State(ntx, nty, nkx, nky, 0);
				if(!visited[nState]){
					visited[nState] = true;
					nState.d = s.d + 1;
					que.push(nState);
				}
			}
		}
		if(!ok)
			cout << "NA" << endl;
	}
  return 0;
}

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

int main() {
    int x;
    scanf("%d", &x);
    int ans;
    if (x >= 400 && x <= 599) ans = 8;
    else if (x >= 600 && x <= 799) ans = 7;
    else if (x >= 800 && x <= 999) ans = 6;
    else if (x >= 1000 && x <= 1199) ans = 5;
    else if (x >= 1200 && x <= 1399) ans = 4;
    else if (x >= 1400 && x <= 1599) ans = 3;
    else if (x >= 1600 && x <= 1799) ans = 2;
    else if (x >= 1800 && x <= 1999) ans = 1;
    printf("%d\n", ans);
}

Measured memory_bytes: 3820
n=int(input())
a=[]
k=0

if n==0:
    print(0)

while k<1:
    if n==0:
        k=1
    else:
        if n%2==0:
            a.append(0)
            n=n/(-2)
        else:
            a.append(1)
            n=(n-1)/(-2)
            
for i in (reversed(a)):
    print(i,end="")

Measured memory_bytes: 38384
#include<iostream>
#include<vector>
#include<string>
#include<map>

#define four(x) (x*x*x*x)

using namespace std;

int calc(int x,int y){
    return x*x*x*x*x-y*y*y*y*y;
}

int ans(int x){

    //int x;
    //cin >> x;

    int sum = 0;

    for(int a=0;;a++){
        int foa = four(a);
        if(foa>x)break;
        for(int b=0;;b++){
            int fob = four(b);
            if(fob>x)break;
            if(calc(a,b) == x){
                printf("%d %d\n",a,b);
                return 0;
            }
            if(calc(a,-b) == x){
                printf("%d %d\n",a,-b);
                return 0;
            }

            if(calc(-a,b) == x){
                printf("%d %d\n",-a,b);
                return 0;
            }

            if(calc(-a,-b) == x){
                printf("%d %d\n",-a,-b);
                return 0;
            }


           // printf("%d %d\n",a,b);
           sum++;
        }
    } 
    puts("");

    return -1;
}

int main(){
    int x; cin >> x; ans(x);
    return 0;
}

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

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

using namespace std;

const int IINF = INT_MAX;
const int MAX_N = 50000;
int N,W,H,x[MAX_N],y[MAX_N],uf[MAX_N],masks[MAX_N],sz[MAX_N];
// ↑←↓→

int find(int x) {
  if( x == uf[x] ) return x;
  return uf[x] = find(uf[x]);
}

void unit(int x,int y){
  x = find(x), y = find(y);
  if( x != y ) uf[x] = y;
}

int main(){
  scanf("%d %d %d",&N,&W,&H);
  rep(i,N) { 
    scanf("%d %d",x+i,y+i);
    uf[i] = i, masks[i] = sz[i] = 0;

    if( y[i] == 1 ) masks[i] |= (1<<0);
    if( x[i] == 1 ) masks[i] |= (1<<1);
    if( y[i] == H ) masks[i] |= (1<<2);
    if( x[i] == W ) masks[i] |= (1<<3);
  }
  map<int,int> mp;
  rep(i,N){
    if( mp.count(x[i]) ) unit(find(mp[x[i]]),find(i));
    else                 mp[x[i]] = i;
  }
  mp.clear();
  rep(i,N){
    if( mp.count(y[i]) ) unit(find(mp[y[i]]),find(i));
    else                 mp[y[i]] = i;
  }

  map<int,int> bitmask;
  set<int> S;
  vector<int> group;
  rep(i,N) S.insert(find(i));
  rep(i,N) ++sz[find(i)];

  if( S.size() == 1 ) {
    printf("%d\n",sz[find(0)]-1);
    return 0;
  }

  rep(i,N) bitmask[find(i)] |= masks[i];
  for(set<int>::iterator it = S.begin(); it != S.end(); it++) group.push_back(*it);

  int ans = IINF;
  rep(i,4){
    int cost = (int)S.size()-1;
    rep(j,(int)group.size()){
      cost += sz[group[j]];
      if( (bitmask[group[j]]>>i) & 1 ) --cost; 
    }
    ans = min(ans,cost);
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 6124
#include <bits/stdc++.h>
typedef long long ll;
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define inf  300000
using namespace std;
const int maxn = 200005;
int n, a[maxn], b[maxn], c[maxn], pos[maxn];
int d1[maxn][20], d2[maxn][20];
vector<pair<int, int> > v;
struct intv{ 
    int l, r;
    int p;
    friend bool operator < (intv ob1, intv ob2){
        return ob1.p > ob2.p;
    }
};
priority_queue<intv> pq;
void RMQ_init(int A[], int d[][20]){
    for(int i = 0; i < n; i++) d[i][0] = A[i];
    for(int j = 1; (1<<j) <= n; j++)
        for(int i = 0; i + (1<<j) - 1 < n; i++)
            d[i][j] = min(d[i][j-1], d[i+(1<<(j-1))][j-1]);
}
int RMQ(int L, int R, int d[][20]){
    int k = 0;
    while((1<<(k+1)) <= R-L+1) k++;
    return min(d[L][k], d[R-(1<<k)+1][k]);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
/*    intv t1 , t2;
    t1 = {1,1,1};
    t2 = {1,1,2};
    pq.push(t1);
    pq.push(t2);
    while(!pq.empty()){
        cout << pq.top().p << endl;
        pq.pop();
    }*/
    cin >> n;
    for(int i = 0; i < n; i++) 
        {
            cin >> a[i];
            b[i] = c[i] = a[i];
            pos[a[i]] = i;
        }
    for(int i = 0; i < n; i++){
        if(i%2 != 0){
            b[i] = inf;
        }
        else{
            c[i] = inf;
        }
    }
    b[n] = c[n] = inf;
    RMQ_init(b,d1);
    RMQ_init(c,d2);
/*    cout << RMQ(0,n-1,d1);
    intv t = {0,n-1,RMQ(0,n-1,d1)};*/
    pq.push({0,n-1,RMQ(0,n-1,d1)});
    int k = n/2;
    while(k--){
        intv t =pq.top(); pq.pop();
        int l = t.l, r = t.r;
        int i, j, m1, m2;
        if(l % 2 == 0){
            m1 = t.p;
            if(m1 !=inf){
                i = pos[m1];
                if(i > l){
                    pq.push({l,i-1,RMQ(l,i-1,d1)});
                }
            }
            m2 = RMQ(i+1, r, d2);
            if(m2 != inf){
                j = pos[m2];
                if(j > i+1){
                    pq.push({i+1,j-1,RMQ(i+1,j-1,d2)});
                }
                if(j < r){
                    pq.push({j+1,r,RMQ(j+1,r,d1)});   
                }
            }
            v.pb({m1, m2});
        }
        else{
            m1 = t.p;
            if(m1 !=inf){
                i = pos[m1];
                if(i > l){
                    pq.push({l,i-1,RMQ(l,i-1,d2)});
                }
            }
            m2 = RMQ(i+1, r, d1);
            if(m2 != inf){
                j = pos[m2];
                if(j > i+1){
                    pq.push({i+1,j-1,RMQ(i+1,j-1,d1)});
                }
                if(j < r){
                    pq.push({j+1,r,RMQ(j+1,r,d2)});   
                }
            }
            v.pb({m1, m2});   
        }
    }
    for(int i = 0; i < v.size() - 1; i++){
        cout << v[i].fi << " " << v[i].se << " ";
    }
    cout << v[v.size()-1].fi << " " << v[v.size()-1].se;
    return 0;
}



Measured memory_bytes: 37388
import sys
from fractions import gcd
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

a, b, c, d = LI()
a = a-1

cd = int(c * d / gcd(c, d))
cs = b // c - a // c
ds = b // d - a // d
cds = b // (cd) - a // (cd)
print(b - a - cs - ds + cds)

Measured memory_bytes: 5076
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vec(k) vector<k>
#define vecvec(k) vector<vector<k> >
#define pai(k) pair<k,k>
#define mod 1000000007
#define mpai make_pair
#define p1 first
#define p2 second
#define umap(x,y) unordered_map<x,y>
ll dp[3001][3001];
ll solve(vector<ll>&arr, int n,int i, int j, bool turn)
{
	// this DP table is acctually for player 1 ..if the turn is 0 then player 2 turn will try to make player 1 total minimum.
	//


	if(i>j)
		return 0;

	if(dp[i][j]!=-1)
		return dp[i][j];

	if(turn==1)
 		dp[i][j]= max(arr[i]+solve(arr,n,i+1,j,0), arr[j]+solve(arr,n,i,j-1,0));// here arr[i] is added since it is pl1 turn
 	else
 		dp[i][j]=min(solve(arr,n,i+1,j,1), solve(arr,n,i,j-1,1)); // here arr[i] is not added since it will be added to score of player two but we are adding for player 1 only.



 	// else
 	// 	dp[i][j]=min(arr[i] +max(solve(arr,n,i+1,j-1,1),solve(arr,n,i+2,j,1)),
		// 				arr[j]  +max( solve(arr,n,i+1,j-1,1),solve(arr,n,i,j-2,1)));
 	return dp[i][j];

}

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


    ll n,x,sum=0;
    cin>>n;
    vec(ll) arr;
    for(int i=0;i<n;i++){
	cin>>x;
	arr.push_back(x);
	sum+=x;
}
memset(dp,-1,sizeof(dp));
ll ans=solve(arr, n,0,n-1,1);

 // cout<<ans<<"\n";
cout<<(2*ans-sum)<<"\n";

return 0;
}


Measured memory_bytes: 70912
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long int
#define tc int t; cin>>t; while(t--)
#define inn ll arr[n]; for(int i=0;i<n;i++) cin>>arr[i];
#define fora(i,n)for(ll i=0;i<n;i++)
#define forb(i,a,n) for(int i=a;i<n;i++)
#define MOD 1000000007
template<class T> T power(T N,T P){ return (P==0)?  1: N*power(N,P-1);}

int main()
{
 //THIS CODE IS CREATED BY ANSHJAIN18

  ll r;
  cin>>r;
  cout<<r*r;



return 0;


}

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

int main() {
    int n;
    cin >> n;
    long a[n], b[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    long ans = 0;
    long acc[n + 1];
    acc[n] = 0;
    for (int i = n; i > 0; i--) {
        acc[i - 1] = (b[i - 1] - (a[i - 1] + acc[i]) % b[i - 1]) % b[i - 1];
        ans += acc[i - 1];
        acc[i - 1] += acc[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
auto fl = [](auto a, auto b) { assert(b != 0); return a / b - (a % b != 0 && ((a >= 0) != (b >= 0)) ? 1 : 0); };
auto ce = [](auto a, auto b) { assert(b != 0); return a / b + (a % b != 0 && ((a >= 0) == (b >= 0)) ? 1 : 0); };
auto mo = [](auto a, auto b) { assert(b != 0); a %= b; if(a < 0) { a += abs(b); } return a; };
LL gcd(LL a, LL b) { return (b == 0 ? a : gcd(b, a % b)); }
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)

// ---- ----

int main() {
	int n, m;
	cin >> n >> m;
	
	cout << (n == m ? "Yes" : "No") << endl;
	
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

if A[0]>=2:
  print(-1)
  
elif A[0]==1:
  if N!=0:
    print(-1)
  else:
    print(1)
    
else:
  SA = sum(A)
  ans = 1
  parent = 1
  judge = True
  for i in range(1, N+1):
    num_leaf = A[i-1]
    num_child = 2*(parent - num_leaf)
    SA -= num_leaf
    if (num_child<A[i])or(num_child<1):
      judge = False
      break
      
    if num_child<=SA:
      parent = num_child
      ans += num_child
      
    else:
      parent = SA
      ans += SA

      
      
  if judge:
    print(ans)
  else:
    print(-1)

Measured memory_bytes: 92940
n=int(input())
list_judge=[]
for i in range (n):
  list_judge.append(str(input()))

acnum=list_judge.count("AC")
wanum=list_judge.count("WA")
tlenum=list_judge.count("TLE")
renum=list_judge.count("RE")

print("AC x ",acnum)
print("WA x ",wanum)
print("TLE x ",tlenum)
print("RE x ",renum)

Measured memory_bytes: 16136
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
#include <cstdint>
using namespace std;

#define H 50
#define W 50

char grid[H][W];
int h, w;

bool isOk(int i, int j)
{
	if( i > 0 && grid[i-1][j] == '#' ) {
		return true;
	}
	if( j > 0 && grid[i][j-1] == '#' ) {
		return true;
	}
	if( i+1 < h && grid[i+1][j] == '#' ) {
		return true;
	}
	if( j+1 < w && grid[i][j+1] == '#' ) {
		return true;
	}
	return false;
}

int main()
{
	int ans = 0;

	cin >> h >> w;
	for( int i = 0; i < h; i++ ) {
		for( int j = 0; j < w; j++ ) {
			cin >> grid[i][j];
		}
	}

	for( int i = 0; i < h; i++ ) {
		for( int j = 0; j < w; j++ ) {
			if( grid[i][j] == '#' ) {
				if( isOk(i, j) == false ) {
					ans = 1;
					goto exit;
				}
			}
		}
	}
exit:

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

	return 0;
}


Measured memory_bytes: 256
N = int(input())
S1 = input()
S2 = input()
i = 0
T = []
while i < N:
    if S1[i]==S2[i]:
        T.append("C")
    else:
        T.append("R")
        i += 1
    i += 1
Ans = 3 if T[0]=="C" else 6
for i in range(1,len(T)):
    if T[i-1] == "C":
        if T[i] == "C":
            Ans *= 2
        else:
            Ans *= 2
    else:
        if T[i] == "C":
            Ans *= 1
        else:
            Ans *= 3
    Ans %= 10**9+7
print(Ans)

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

int main() {
    int a, b;
    cin >> a >> b;

    int ans=0;
    for (int i=a; i<=b; i++) {
        string sbuff=to_string(i);
        
        if (sbuff[0]==sbuff[4] && sbuff[1]==sbuff[3]) {
            ans++;
        }
    }

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

Measured memory_bytes: 3704
#include<bits/stdc++.h>
using ll = int_fast64_t;

int n, q;
std::vector<ll> links[200000], ans(200000, 0), used(200000, 0);

void dfs(ll st){
        used[st] = 1;
        for(ll to: links[st]){
                if(used[to]) continue;
                ans[to] += ans[st];
                dfs(to);
        }
}

int main(){
        scanf("%d %d", &n, &q);
        for(int i=0; i<n-1; i++){
                ll a, b;
                scanf("%ld %ld", &a, &b);
                links[a-1].push_back(b-1);
                links[b-1].push_back(a-1);
        }

        for(int i=0; i<q; i++){
                ll p, x;
                scanf("%ld %ld", &p, &x);
                ans[p-1] += x;
        }

        dfs(0);
        for(int i=0; i<n; i++) printf("%ld ", ans[i]);
        puts("");
        return 0;
}

Measured memory_bytes: 22656
#include <iostream>
#include <algorithm>
using namespace std;
static const int N=100;
int main(){
    int n,p[N+1],m[N+1][N+1];
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>p[i-1]>>p[i];
    }
    for(int i=1;i<=n;i++)m[i][i]=0;
    for(int L=2;L<=n;L++){//因l(字母)1(数字）分不清，本人将其改?大写字母L 
        for(int i=1;i<=n-L+1;i++){
            int j=i+L-1;
            m[i][j]=(1<<21);//本人注解，相当于INF
            for(int k=i;k<=j-1;k++){
                m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
            } 
        }
    }
    cout<<m[1][n]<<endl;//本人注解，注意此?是1(数字)而不是l(字母) 
    return 0;
}

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

int main(){
    double n;
    cin>>n;
    double x = (n/1.08);
    if((int)(x*10) > 5){
        x= ceil(x);
    }
    else x = floor(x);
    //cout<<(x*1.08);
    if(int(x*1.08) != n)cout<<":(";
    else cout<<x;
    // if((int)((n-(n/1.08))*10)%10 <= 5)
    // cout<<ceil(n/1.08)<<endl;
    // else{
    //      cout<<":(";
    // }
}

Measured memory_bytes: 3904
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class QuestionD
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数の入力
            int n = int.Parse(Console.ReadLine());

            var leftRights = new List<int[]>();

            for(int i = 0; i < n; i++) {
                var intArray = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                var lr = new int[2] { intArray[0] - intArray[1], intArray[0] + intArray[1] };
                leftRights.Add(lr);
            }

            var robots = new List<int[]>();

            leftRights.Sort((l, r) => l[0] - r[0]);

            var robotsNum = 0;
            var lastRobotIndex = 0;
            robots.Add(leftRights[0]);

            for(int i = 1; i < n; i++) {
                if (leftRights[lastRobotIndex][1] <= leftRights[i][0]) {
                    lastRobotIndex = i;
                } else if (leftRights[lastRobotIndex][1] < leftRights[i][1]) {
                    robotsNum++;
                } else {
                    robotsNum++;
                    lastRobotIndex = i;
                }
            }

            Console.WriteLine(n - robotsNum);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 25008
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
int n;
ll H[5050],P[5050];
vector<pair<ll,int> > od;
ll dp[5050][5050];
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%lld%lld",&H[i],&P[i]);
	for(int i=0;i<n;i++)od.push_back(make_pair(H[i]+P[i],i));
	sort(od.begin(),od.end());
	memset(dp,0x3f,sizeof(dp));
	dp[0][0]=0;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<=i;j++)
		{
			if(dp[i][j]==linf)break;
			dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
			if(dp[i][j]<=H[od[i].second])
			{
				dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+P[od[i].second]);
			}
		}
	}
	for(int i=n;i>=0;i--)
	{
		if(dp[n][i]<linf)
		{
			printf("%d\n",i);
			return 0;
		}
	}
}

Measured memory_bytes: 199808
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;

int main()
{
  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    a[i]--;
  }
  ll cnt = 0;
  rep(i, n) {
    if (a[a[i]] == i) cnt++;
  }
  cout << cnt/2 << endl;

  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007

  
int32_t main()
{

int n;
  cin >> n;
  int arr[n+1];
  	
  int sum = 0;
  int squaredsum = 0;
  
  for(int i = 1; i <= n; i++)
  {
    cin >> arr[i];
   sum += arr[i];
    squaredsum += (arr[i]*arr[i]);
  }
  
  int ans = 1e18;

  
  for(int i = 1; i <= 100; i++)
  {
   ans = min(ans,squaredsum + n*i*i - 2*i*sum); 
  }
  cout << ans;
}

Measured memory_bytes: 256
number_of_masu, firstsunuke, firstfunuke, lastsunuke, lastfunuke = map(int, input().split())
s = str(input())
tobenaiflag = 0
nukaseruflag = 0
lastfunuke -= 1
lastsunuke -= 1
firstsunuke -= 1
firstfunuke -= 1
for i in range(firstsunuke, lastsunuke-1):
    if s[i] == '#' and s[i+1] == '#':
        tobenaiflag += 1
        break
for k in range(firstfunuke, lastfunuke-1):
    if s[k] == '#' and s[k+1] == '#':
        tobenaiflag += 1
        break
if lastfunuke < lastsunuke:
    for j in range(firstfunuke, lastfunuke+1):
        if s[j] == '.' and s[j-1] == '.' and s[j+1] == '.':
            nukaseruflag += 1
            break
else:
    nukaseruflag += 1
if number_of_masu == 4:
    print('Yes')
elif tobenaiflag == 0 and nukaseruflag == 1:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3636
#include <stdio.h>

int main(int argc, char const *argv[]) {
	char str[101];
	int n, m, k;
	int ans;

	fgets(str, 100, stdin);
	sscanf(str, "%d", &n);

	while (1) {
		int d100 = n / 100;
		int d10  = n / 10 % 10;
		int d1   = n % 10;

		if ( d100 == d10 && d10 == d1) {
			break;
		}

		n++;
	}

	printf("%d\n", n);

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    map<string, ll> mp;
    rep(i,N){
        string s;
        cin >> s;
        mp[s]++;
    }

    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
}

Measured memory_bytes: 3664
#include <iostream>
#include <stdio.h>

#include <vector>
#include <cctype>

using namespace std;

int main()
{
    char car;

    vector<char> arr;

    int i = 0;
    while (1) {
        car=cin.get();

        
        arr.push_back(car);
        
        if (isupper(arr[i])) {
            arr[i] = tolower(arr[i]);
        }
        else if (islower(arr[i])) {
            arr[i] = toupper(arr[i]);
        }
        else {
            arr[i] = arr[i];
        }

        std::cout << arr[i];

        if (car == '\n') {
            break;
        }
        i++;

    }
    
    return 0;
}


Measured memory_bytes: 3148