akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var array = new int[N][];

            for (var i = 0; i < N; i++)
            {
                array[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
            }

            var sol = new Solve(N, array);
            Console.WriteLine(sol.Exec().Max());
        }
    }

    class Solve
    {
        public int N { get; set; }
        public int[][] array { get; set; }
        public int[][] dp { get; set; }
        public Solve(int N, int[][] array)
        {
            this.N = N;
            this.array = array;
            dp = new int[N + 10][];
            dp = dp.Select(z => z = new int[3]).ToArray();
        }

        public int[] Exec()
        {
            dp[0] = array[0];
            for (var i = 1; i < N; i++)
            {
                for (var j = 0; j < 3; j++)
                {
                    var max = 0;
                    // dpループ
                    for (var k = 0; k < 3; k++)
                    {
                        if (j != k)
                        {
                            max = Math.Max(array[i][j] + dp[i-1][k], max);
                        }
                    }
                    dp[i][j] = max;
                }
            }
            return dp[N - 1];
        }
    }
}

Measured memory_bytes: 28592
N = int(input())
A = []
for i in range(N):
  a, b = map(int, input().split())
  c = a + b
  A += [[a, b, c]]
  
A.sort(key=lambda x:x[2], reverse = True)

ans = 0
for i in range(len(A)):
  if i%2 == 0:
    ans += A[i][0]
  else:
    ans -= A[i][1]
print(ans)

Measured memory_bytes: 24412
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    # too slow
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def get_all_members(self):
        pare_d = {}
        for i in range(self.n):
            parent = self.find(i)
            pare_d.setdefault(parent,[])
            pare_d[parent].append(i)
        return list(pare_d.values())

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n,m = map(int, input().split())
uf = UnionFind(n)

for _ in range(m):
    a,b = map(int, input().split())
    uf.union(a-1,b-1)

all_g = uf.get_all_members()
max_len = 0
for g in all_g:
    max_len = max(max_len, len(g))

print(max_len)

Measured memory_bytes: 103756
#include <iostream>
#include <vector>

//#include <cstdio>

using namespace std;

static int inputArray(int A[], int num) {
  int max = 0;
  for (int i = 0; i < num; i++) {
    cin >> A[i];
    if (A[i] > max) {
      max = A[i];
    } 
  }
  return max;
}

static inline int f(int A[], int num, uint64_t P, int k) {
    int i = 0, v = 0;
    for (uint64_t total = 0; (v < k) && (i < num); i++) {
      total += A[i];
      if (total > P) {
        total = 0;
        i--;
        v++;
      }
    }
    return i;
}

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

  vector<int> w(n);
  uint64_t P = inputArray(&w[0], n);

  uint64_t left = 0;
  uint64_t mid;
  uint64_t right = 100000 * 10000;
  int v = 0;
  while (1 < right - left) {
    mid = (left + right) / 2;
    v = f(&w[0], n, mid, k);
    if (v >= n) {
      right = mid;
    } else {
      left = mid;
    }
  }

  cout << right << endl;

  return 0;
}



Measured memory_bytes: 3148
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll BIG=1e15;

ll dp[4][100001];
int main(){
    string S;
    cin>>S;
    dp[3][0]=1;
    for(int i=0;i<S.size();i++){
        for(int j=0;j<4;j++) dp[j][i+1]=dp[j][i];
        if(S.at(i)=='A') dp[0][i+1]+=dp[3][i];
        if(S.at(i)=='B') dp[1][i+1]+=dp[0][i];
        if(S.at(i)=='C') dp[2][i+1]+=dp[1][i];
        if(S.at(i)=='?') {
            dp[0][i+1]=dp[0][i]*3+dp[3][i];
            dp[1][i+1]=dp[1][i]*3+dp[0][i];
            dp[2][i+1]=dp[2][i]*3+dp[1][i];
            dp[3][i+1]=dp[3][i]*3;
        }
        for(int j=0;j<4;j++) {dp[j][i+1]=(dp[j][i+1])%mod; }
        
    }

    cout<<dp[2][S.size()]<<endl;
}

Measured memory_bytes: 3584
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  ll x;
  cin >> x;

  ll once = 1;
  ll cnt = 1;
  ll pos = 0;
  while(1)
  {
    pos += once;
    if(pos >= x)
    {
      break;
    }
    cnt++;
    once = cnt;
  }

  cout << cnt << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++) 
#define rep(i,n) for(int i = 0; i < (n); i++)
const int MOD = 1e9+7;
const int INF = 2e9;
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/while(min(a,b)>0){if(a<b)swap(a,b);a=a%b;}return max(a,b);}
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct Edge{int to,weight;};
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
/*----------------------------------------------*/
int dp[110][101010]; 
int w[110],v[110];

signed main(){
  int n,W;
  cin>>n>>W;
  rep(i,n) cin>>w[i]>>v[i];
  rep(i,110)rep(j,101010) dp[i][j]=INF;
  
  dp[0][0]=0;
  rep(i,n+1)rep(j,101010){
    if(j>=v[i]) chmin(dp[i+1][j],dp[i][j-v[i]]+w[i]);
    chmin(dp[i+1][j],dp[i][j]);
  }

  int ans=0;
  rep(j,101010) if(dp[n][j]<=W) ans=j;
  cout<<ans<<endl;
  // rep(i,n+1){
  //   rep(j,101010) if(dp[i][j]<INF) cout<<dp[i][j]<<"/"<<j<<" ";
  //   cout<<endl;
  // }
  return 0;
}


Measured memory_bytes: 87040
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int primedivisors(ll n){
    int ans=0;
    for(ll i=2;i<=sqrt(n);i++){
        if(n%i==0){
            int cnt=0;
            while(n%i==0){
                cnt++;
                n/=i;
            }
            int x=(-1+sqrt(1+8*cnt))/2;
            int y=(x*(x+1))/2;
            ans+=x;
        }
    }
    if(n!=1)ans++;
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	ll n;
	cin>>n;
	cout<<primedivisors(n);
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}
//char a[55][55];
int dx[] = {1,0,-1,0,1,1,-1,-1};
int dy[] = {0,1,0,-1,1,-1,-1,1};
int main()
{
	dhoom;
	string s , t;
	cin >> s >> t;
	reverse(s.begin(),s.end());
	if(s == t)
		cout << "YES" <<endl;
	else 
		cout << "NO" <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    ll a,b;
    cin>>a>>b;
    cout<<(a>=1&&b>=1&&a<=9&&b<=9?a*b:-1)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;
int main(){
  int n; cin >> n;
  int sum = 0;
  vector<int> a(n+2,0);
  for(int i=1;i<=n+1;i++){
    if(i<=n) cin >> a.at(i);
    sum += abs(a.at(i)-a.at(i-1));
  }

  for(int i=1;i<=n;i++){
    ll ans = 0;
    ans = sum - abs(a.at(i)-a.at(i-1)) - abs(a.at(i)-a.at(i+1)) + abs(a.at(i+1)-a.at(i-1));
    cout << ans << endl;
  }

}


Measured memory_bytes: 3784
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
A.sort()
A_max = A[-1]
dp = [1]*(A_max+1)
# dp[i] = 1: iはAのどの要素の倍数でもない
# dp[i] = 0: iはAの要素の倍数である
for a in A:
    if not dp[a]:
        continue
    y = a*2
    while y <= A_max:
        dp[y] = 0
        y += a
# Aの要素それぞれについて、dp[a] = 1ならよいが
# Aの要素ai,ajでai=ajとなる場合、上の篩では通過しているのに
# 条件を満たさない
cnt = dict(Counter(A))
ans = 0
for a in A:
    if cnt[a] >= 2:
        continue
    if dp[a]:
        ans += 1
print(ans)

Measured memory_bytes: 149876
#include<stdio.h>

int main(){
    int a,b,c,d;
    scanf("%d %d %d" ,&a,&b,&c);
    if(a > b){
      d = a;
      a = b;
      b = d;}

    if(b > c){
      d = c;
      c = b;
      b = d;}

    if(a > b){
      d = a;
      a = b;
      b = d;}
    
    printf("%d %d %d\n" ,a,b,c);  

return 0;
}

Measured memory_bytes: 1812
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

#define forin(i, f, t) for(auto i = f; i < t; i++)

using namespace std;
using ll = long long;

int erasePos(vector<bool> &list) {
    cerr << endl;
    forin(i, 0, list.size()) {
        if (list[i])
            continue;
        if (i == 0 || i == list.size() - 1) {
            list.erase(list.begin() + i);
            return i;
        } else {
            if ((list[i - 1] && list[i + 1]) ||
                (!list[i - 1] && !list[i + 1])) {
                if (list[i - 1])
                    list[i] = true;
                list.erase(list.begin() + i + 1);
                list.erase(list.begin() + i - 1);
                return i;
            }
        }
    }
    return 1;
}

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    forin(i, 0, n)
        cin >> a[i];
    ll sumO = 0, sumV = 0;
    vector<bool> posO(n, false), posV(n, false);
    bool exist = false;
    forin(i, 0, n) {
        if (a[i] <= 0)
            continue;
        exist = true;
        if (i % 2) {
            sumO += a[i];
            posO[i] = true;
        } else {
            sumV += a[i];
            posV[i] = true;
        }
    }
    auto pos = sumO > sumV ? posO : posV;
    auto sum = sumO > sumV ? sumO : sumV;
    if (!exist) {
        ll max = a[0];
        int maxi = 0;
        forin(i, 0, n) {
            if (a[i] > max) {
                max = a[i];
                maxi = i;
            }
        }
        sum = max;
        pos[maxi] = true;
    }
    
    cout << sum << endl;
    vector<int> erases;
    while (pos.size() > 1) {
        erases.push_back(erasePos(pos));
    }
    cout << erases.size() << endl;
    forin(i, 0, erases.size())
        cout << erases[i] + 1 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main()
{
    int a,b,i=1,x,s=1,y;
    scanf("%d%d",&a,&b);
    x=log10(b)+1;
    for(i=1;i<=x;i++)
        s=s*10;
    y=a*s+b;
    x=sqrt(y);
    if(x*x==y) printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

int main(void){
	int a,b,i,check,ct=0;
	
	while(scanf("%d %d",&a,&b)){
		if(a==0&&b==0)
		break;
		if(ct!=0)
		printf("\n");
		check = 0;
		if(a==b){
			if(a%4==0&&a%100!=0){
				printf("%d\n",a);
				check = 1;
			}
			else if(a%400==0){
				printf("%d\n",a);
				check = 1;
			}
		}
		else{
			for(i=a;i<=b;i++){
				if(i%4==0&&i%100!=0){
					printf("%d\n",i);
					check = 1;
				}
				else if(i%400==0){
					printf("%d\n",i);
					check = 1;
				}
			}
		}
		if(check==0)
		printf("NA\n");
		ct++;
	}
	return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
#define int long long int
using namespace std;
main() 
{
	// int t;
	// cin >> t;
	// while(t--)
	// {
		string str;
		cin >> str;
		if(str[1]=='B')
			cout << "ARC" << endl;
		else
			cout << "ABC" << endl;
	// }
	return 0;
}

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

namespace ABC085C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] NY = Console.ReadLine().Split(' ');
            Console.WriteLine(abc083c(NY));
          
        }
        static string abc083c(string[] NY)
        {
            
            int N = int.Parse(NY[0]), Y = int.Parse(NY[1]);
            int x, y, z;
            int sum = 0;
            string ans = "";
            for (int i = 0; i < N+1; i++)
            {
                x = i;
                for (int j = 0; j < N+1; j++)
                {
                    y = j;
                    z = N - x - y;
                    sum = x * 10000 + y * 5000 + z * 1000;
                     if (z >= 0 && sum == Y)
                    {
                        ans = x + " " + y + " " + z;
                        return ans;
                    }

                }
            }
            return "-1 -1 -1";
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int main() {
  long k,n,i,m;
  cin>>k>>n;
  vector<long> a(n+1);
  for(i=0;i<n;i++) cin>>a.at(i);
  a.at(n)=a.at(0)+k;
  m=0;
  for(i=0;i<n;i++) if (m<a.at(i+1)-a.at(i)) m=a.at(i+1)-a.at(i);
  cout<<k-m<<endl;
}

Measured memory_bytes: 1792
/**
*    Username : adhoc_king
*    Name : adhoc_king
*    Institute : IIT Bombay
*/

#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string>
// #include <deque>
// #include <queue>
// #include <array>
// #include <ctime>
// #include <list>
// #include <map>
// #include <set>
// #include <cassert>
// #include <complex>
// #include <sstream>
// #include <forward_list>
// #include <unordered_set>
// #include <unordered_map>

using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define scani(n) scanf("%d",&n);
#define EPS 1e-9
#define FOR(i,n) for(int i=0; i<n; i++)
#define X first
#define Y second
#define arrinput for(int i=0; i<n; i++) cin>>arr[i];
#define arrsum for(int i=0; i<n; i++) sum+=arr[i];
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<=n; i++)
#define forr(i,n) for(int i=n-1; i>=0; i--)
#define all(v) v.begin(), v.end()

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

const int MOD = 1e9+7;
const int n_ = 1e5+1000;
const long double PI = acos(-1.0);

ll gcd (ll a, ll b) {return ( a ? gcd(b%a, a) : b );}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power(ll a, ll n, ll mod) {ll p = 1;while (n > 0) {if(n%2) {p = p * a; p %= mod;} n >>= 1; a *= a; a %= mod;} return p % mod;}

bool vowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') return true;
    else return false;
}

// Union-Find Disjoint Sets Library written in OOP manner, using both path compression and union by rank heuristics
class UnionFind {                                              // OOP style
private:
    vi p, rank, setSize;                       // remember: vi is vector<int>
    int numSets;
public:
    UnionFind(int N) {
        setSize.assign(N, 1); numSets = N; rank.assign(N, 0);
        p.assign(N, 0); for (int i = 0; i < N; i++) p[i] = i; }
    int findSet(int i) { return (p[i] == i) ? i : (p[i] = findSet(p[i])); }
    bool isSameSet(int i, int j) { return findSet(i) == findSet(j); }
    void unionSet(int i, int j) { 
        if (!isSameSet(i, j)) { numSets--; 
        int x = findSet(i), y = findSet(j);
        // rank is used to keep the tree short
        if (rank[x] > rank[y]) { p[y] = x; setSize[x] += setSize[y]; }
        else                   { p[x] = y; setSize[y] += setSize[x];
                                 if (rank[x] == rank[y]) rank[y]++; } } }
    int numDisjointSets() { return numSets; }
    int sizeOfSet(int i) { return setSize[findSet(i)]; }
};

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

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n, a, b, c, d, e;
    cin>>n>>a>>b>>c>>d>>e;
    int mx = 0;
    mx = max(mx, (n+a-1)/a);
    mx = max(mx, (n+b-1)/b);
    mx = max(mx, (n+c-1)/c);
    mx = max(mx, (n+d-1)/d);
    mx = max(mx, (n+e-1)/e);
    cout<<mx+4;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    INIT;
    cin >> A >> B >> C;
    if (C - B == B - A) {
        cout << "YES" << endl;
    } else
        cout << "NO" << endl;
}

Measured memory_bytes: 3592
n, h = map(int, input().split())
arr = []
for _ in range(n) :
    a,b = map(int, input().split())
    arr.append((a,-1))
    arr.append((b,1))

cnt = 0
ans = 10**9 + 100
for p in reversed(sorted(arr)) :
    if p[1] == -1 :
        # a
        ans = min(ans, cnt + (h+p[0]-1)//p[0])
        break
    elif p[1] == 1 and h>0 :
        # b
        h -= p[0]
        cnt += 1
        if h <= 0 :
            h = 0
            ans = min(ans, cnt)

print(ans)


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

#define INF LONG_LONG_MAX

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vll f(n);
    rep(i,n)rep(j,10){
        int t; cin>>t;
        if (t) f[i] |= 1ll<<j;
    }
    vector<vll> p(n,vll(11));
    rep(i,n)rep(j,11){
        cin>>p[i][j];
    }
    ll ans=-INF;
    rep(s,1<<10){
        if (__builtin_popcountll(s)==0) continue;
        ll sum=0;
        rep(i,n){
            int cnt=0;
            rep(j,10){
                if (s>>j&1 && f[i]>>j&1) cnt++;
            }
            sum+=p[i][cnt];
        }
        chmax(ans,sum);
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

typedef unsigned long long int ll;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,m;
    cin >> n >> m;
    ll cc = 0;
    ll a[n];
    for(int i=0 ; i<n ; i++)
    {
        cin >> a[i];
        cc += a[i];
    }
    sort(a,a+n);
    reverse(a,a+n);
    bool f=0;
    for(int i=0 ; i<m ; i++)
    {
        if(a[i]*4*m < cc)
        {
            f=1;
            break;
        }
    }
    if(f)
        cout << "No\n";
    else
        cout << "Yes\n";
    return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
n = int(input())
a_array = [int(x) for x in input().split()]

ans = [[0 for x in range(w)] for y in range(h)]
index = 0
now = a_array[index]
reverse = True

for i in range(h):
    if reverse:
        w_range = [x for x in range(w)]
        reverse = False
    else:
        w_range = [x for x in reversed(range(w))]
        reverse = True
    for j in w_range:
        if now == 0:
            index += 1
            now = a_array[index]
        ans[i][j] = index+1
        now -= 1

for i in range(h):
    for j in range(w):
        print(ans[i][j], end=" ")
    print()

Measured memory_bytes: 3920
#include <stdio.h>
#define MAX 1000000
int main(void){
	char s[MAX], t[MAX];
	int n, i;
	int cnt = 0;
	scanf("%s\n", &s);
	scanf("%s", &t);
	//printf("%s %s", s, t);
  	n = strlen(s);
  	//printf("%d", n);
  	for (i = 0; i < n; i++){
		if (s[i] != t [i])
			cnt++;
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 2132
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	string version1;
	string version2;
	string original;
	int flag = 0;
	cin>>version1>>version2;
	original = version2;
	for(int i=0;i<=version1.size();i++)
	{
		int maintain= i;
		for(int j=0;j<=version1.size();j++)
		{
			version2[j] = version1[maintain];
			maintain = maintain + 1;
			if((maintain>=i+j)&&(maintain>=version1.size()))
			{
				maintain = maintain - version1.size();
			}
		}	
		for(int check=0;check<=version1.size();check++)
		{
			if(version2[check]==original[check])
			{
				flag = flag + 1;
			}
			if(flag==version1.size())
			{
				cout<<"Yes";
				cout<<endl;
				return 0;
			}
			
		}
		flag = 0;
		
	}
	cout<<"No";
	cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    string s;
    int k;
    cin>>s>>k;
    vector<char>a(s.size());
    vector<char>b(s.size());
    for(int i=0;i<s.size();i++){
        a.at(i)=s.at(i);
        b.at(i)=s.at(i);
    }
    int cnt=1;
    vector<string>vec;
    while(cnt<=k){
        for(int i=0;i<s.size()-cnt+1;i++){
            vec.push_back(s.substr(i,cnt));
        }
        cnt++;
    }
    sort(vec.begin(), vec.end());
    vector<int>tmp;
    for(int i=0;i<vec.size()-1;i++){
        if(vec.at(i)==vec.at(i+1)){
            tmp.push_back(i+1);
        }
    }
    for(int t=0;t<tmp.size();t++){
        vec.at(tmp.at(t))="zzzzzzzzzzzzzzzzzzz";
    }
    sort(vec.begin(), vec.end());
    // for(int i=0;i<k;i++){
    //     cout << vec.at(i) << endl;
    // }
    cout<<vec.at(k-1)<<endl;


    // for(int i=0;i<s.size();i++){
    //     cout<<a.at(i)<<endl;
    // }





    return 0;
}


Measured memory_bytes: 2172
#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>;

const int A = 1000005;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	vector<int> c(A);
	
	rep(i, n) {
		cin >> a[i];
		c[a[i]]++;
	}
	
	bool pairwise = true;
	for (int i = 2; i < A; ++i) {
		int cnt = 0;
		for (int j = i; j < A; j += i) {
			cnt += c[j];
		}
		if (cnt > 1) pairwise = false;
	}
	
	if (pairwise) {
		cout << "pairwise coprime\n";
		return 0;
	}
	
	int g = 0;
	rep(i, n) g = gcd(g, a[i]);
	if (g == 1) {
		cout << "setwise coprime\n";
		return 0;
	}
	
	cout << "not coprime" << '\n';
	
	return 0;
} 

Measured memory_bytes: 11100
n , a = map(int,input().split())
x = list(map(lambda x:int(x)-a,input().split()))
dp = [0 for i in range(4901)]
for i in x:
    if i < 0:
        for j in range(4901):
            if 0<=i+j<=4900:
                dp[j+i] += dp[j]
    elif i >= 0:
        for j in reversed(range(4901)):
            if 0<=i+j<=4900:
                dp[j+i] += dp[j]
    dp[i+2450] += 1
print(dp[2450])

Measured memory_bytes: 70592
//DuplexPrinting

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) int n;cin>>n;vector<int>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<int,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18


int main (){
    int n;cin>>n;
    cout<<n/2+n%2<<nnn;
    return 0;
}

Measured memory_bytes: 256
/*Author- Soumak Poddar*/

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

#define ll long long int
#define um unordered_map
#define mp make_pair
#define pb push_back

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

   #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("error.txt", "w", stderr);
      freopen("output.txt", "w", stdout);
   #endif
   
   int t=1;
   // cin>>t;
   while(t--)
   {
      solve();
      cout<<"\n";
   }
   cerr<<"Time Taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
   return 0;
}
void solve()
{
   ll n,w,we,val;
   cin>>n>>w;
   vector<ll> weight,value;
   for(ll i=0;i<n;i++)
   {
      cin>>we>>val;
      weight.pb(we);
      value.pb(val);
   }
   ll dp[n+1][w+1];
   for(ll i=0;i<=n;i++)
   {
      for(ll j=0;j<=w;j++)
      {
         //for weight == 0 and for item 0...
         if(i==0 or j==0)
            dp[i][j]=0;

         //considering the weight and not considering...max
         else if(weight[i-1]<=j)
         {
            dp[i][j]=max(dp[i-1][j],value[i-1]+dp[i-1][j-weight[i-1]]);
         }
         else
            dp[i][j]=dp[i-1][j];
      }
   }
   cout<<dp[n][w];
}

Measured memory_bytes: 82588
#include"iostream"
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
#include<list>
#include<map>
#include<string>
#include<algorithm> 
#include <queue> 
#include <sstream>
#include <fstream>
#include<cmath>
#define INF 100000000000
#define LL long long
using namespace std;
map<LL , LL> sm,tm;
vector<double> v;
long long N, M, K, ans,h[100];



int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	ans = h[0];
	for (int i = 1; i < N; i++) {
		if (h[i] <= h[i - 1]) {

		}
		else {
			ans += h[i] - h[i - 1];
		}
	}

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

Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <map>
#include <iomanip>
using namespace std;

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

    if (x == 0) {
        cout << 1 << endl;
    } else {
    	cout << 0 << endl;
    }

    return 0;
}



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

using namespace std;

int main(int argc,char** argv)
{

	string s;
	cin >> s;
	for(int i = 0; i < 3; i++){
		if(s[i]=='1'){
			s[i] = '9';
		}
		else{
			s[i] = '1';
		}
	}
	cout << s <<endl;

	return 0;

}

Measured memory_bytes: 256
from math import *
log = lambda *x: print(*x)

def cin(*fn, def_fn=str):
    i, r = 0, []
    if fn:
        def_fn = fn[0]
    for c in input().split(' '):
        r += [(fn[i] if len(fn) > i else def_fn) (c)]
        i += 1
    return r
##################################################

n, = cin(int)
h, = cin(int)
w, = cin(int)

tw, th = 0, 0

while h <= n:
    h += 1
    th += 1

while w <= n:
    tw += 1
    w += 1

log(th * tw)


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

public class Main {
	public static void main(String[] args)
			throws java.io.IOException{
		Scanner scan = new Scanner(System.in);
		int n  = scan.nextInt();
		scan.nextLine();
		for(int i=0;i<n;i++){
			int [] tri =new int[3];
			tri[0]=scan.nextInt();
			tri[1]=scan.nextInt();
			tri[2]=scan.nextInt();
			Arrays.sort(tri);
			if(Math.pow(tri[0],2)+Math.pow(tri[1], 2) == Math.pow(tri[2], 2))
				System.out.println("YES");
			else System.out.println("NO");
		} 
	}
}

Measured memory_bytes: 12000
var
    ans,k,tot1,tot2:int64;
    n:longint;
function s(x:int64):int64;
begin
    if x=0 then exit(0)
    else exit(x mod 10+s(x div 10));
end;
begin
    readln(n);
    ans:=1;k:=1;
    while n>0 do
        begin
            writeln(ans);
            tot1:=ans+k;
            tot2:=ans+k*10;
            if tot1*s(tot2)<=tot2*s(tot1) then ans:=tot1
            else
                begin
                    ans:=tot2;
                    k:=k*10;
                end;
            dec(n);
        end;
end.

Measured memory_bytes: 128
using System;
using System.IO;
 
class Program
{
    static void Solve()
    {
        var x = sc.Int();
        var a = sc.Int();
        var b = sc.Int();

        pr.WriteLine((x - a) % b);
    }
 
 
    static void Main(string[] args)
    {
        // pr.AutoFlush = true;
        Solve();
        pr.Flush();
    }
 
    static Scanner sc = new Scanner();
    static Printer pr = new Printer();
}
 
#region IO
class Scanner
{
    private int _i = 0; 
    private string[] line = new string[0];
 
    private T[] Enumerate<T>(int n, Func<T> f)
    {
        T[] ret = new T[n];
        for (int i = 0; i < n; i++)
            ret[i] = f();
        return ret;
    }
 
    public string Str()
    {
        if (line.Length <= _i)
        {
            line = Console.ReadLine().Split(' ');
            _i = 0;
        }
 
        return line[_i++];
    }
 
    public int Int() => int.Parse(Str());
    public long Long() => long.Parse(Str());
    public double Double() => double.Parse(Str());
    public int[] Int(int n) => Enumerate(n, Int);
    public long[] Long(int n) => Enumerate(n, Long);
    public double[] Double(int n) => Enumerate(n, Double);
    public string[] Str(int n) => Enumerate(n, Str);
}
 
class Printer : StreamWriter
{
    public Printer() : base(Console.OpenStandardOutput())
    {
        AutoFlush = false;
    }
}
#endregion

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

void solve() {
  string s;
  cin >> s;
  int n = sz(s);

  int dp[n + 1][2]; // 1:smaller
  fill_n(*dp, (n + 1) * 2, 0);
  dp[0][0] = 1;
  rep(i, n) rep(ai, 2) rep(bi, 2) rep(j, 2) {
    if (ai == 1 && bi == 1) continue;
    if (j == 0 && ai + bi > s[i] - '0') continue;

    add(dp[i + 1][j | (ai + bi < s[i] - '0')], dp[i][j]);
  }
  int ans = dp[n][0];
  add(ans, dp[n][1]);
  cout << ans << endl;
}


Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  ll n, d;
  cin >> n >> d;
  vector<ll> x(n, 0);
  vector<ll> y(n, 0);
  ll ans = 0;
  rep(i, n) {
    double v = 0;
    cin >> x.at(i) >> y.at(i);
    ll a = x.at(i) * x.at(i) + y.at(i) * y.at(i);
    v = sqrt(a);
    if (v <= d) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6428
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/

lint lcm(lint a, lint b) {
	//aとbの最小公倍数を返す
	if (a < b) return lcm(b, a);
	lint A = a;
	lint B = b;
	lint r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return (A / b) * B;
}

int main() {
	lint N;
	cin >> N;
	vector<lint>A(N);
	rep(i, N) {
		cin >> A[i];
	}
	int cnt = 1;
	rep(i, N) {
		if (A[i] == cnt) {
			cnt++;
		}
	}
	if (cnt == 1) {
		cout << -1 << endl;
	}
	else {
		cout << N - cnt + 1 << endl;
	}
}

Measured memory_bytes: 1792
class UnionFind:
    def __init__(self, n):
        self.root = [-1]*(n+1)
        self.rnk = [0]*(n+1)
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    def Unite(self, x, y):
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        if(x == y):
            return
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

n,m=map(int,input().split())
l=list(reversed([list(map(int,input().split())) for _ in [0]*m]))
uf=UnionFind(n)
ans=[0]*m
ans[0]=n*(n-1)//2
for i in range(m-1):
    if uf.isSameGroup(l[i][0],l[i][1]):
        ans[i+1]=ans[i]
    else:
        ans[i+1]=ans[i]-uf.Count(l[i][0])*uf.Count(l[i][1])
        uf.Unite(l[i][0],l[i][1])
for i in range(m):
    print(ans[~i])


Measured memory_bytes: 34160
import math
def sum_of(v_cnt, n):
    if v_cnt == 1:
        if 0 <= n <= 9:
            return 1
        else:
            return 0
    else:
        result = 0
        for v in range(10):
            result += sum_of(v_cnt - 1, n - v)
        return result

import sys
for line in sys.stdin:
    n = int(line)
    print sum_of(4, n)

Measured memory_bytes: 4336
use io::*;
use std::cmp;

fn main() {
    let input = read_string();
    let mut sc = Scanner::new(&input);
    let n: usize = sc.next();
    let t: usize = sc.next();
    let ts: Vec<usize> = sc.next_vec(n);
    let mut ans = t;
    for i in 1..n {
        ans += cmp::min(ts[i] - ts[i-1], t);
    }
    println!("{}",ans);
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }

        pub fn next_mat<T: FromStr>(&mut self, w: usize, h: usize) -> Vec<Vec<T>> {
            (0..h).map(|_| self.next_vec(w)).collect()
        }

        pub fn next_vec_char(&mut self) -> Vec<char> {
            self.next::<String>().chars().collect()
        }

        pub fn next_mat_char(&mut self, n: usize) -> Vec<Vec<char>> {
            (0..n).map(|_| self.next_vec_char()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N; cin>>N;
    vector<tuple<int,int,int>> Train(N-1);
    rep(n,0,N-1){
        int c,s,f; cin>>c>>s>>f;
        Train.at(n)=make_tuple(c,s,f);
    }

    vector<int> t(N,0);
    int idx=0;
    for(auto train:Train){
        int c,s,f;
        tie(c,s,f)=train;

        idx++;
        rep(i,0,idx){
            int st=ceil((double)t.at(i)/f)*f;
            st=max(st,s);
            t.at(i)=st+c;
        }
    }

    for(auto ans:t) cout<<ans<<endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc088/tasks/abc088_b

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int N;
    cin >> N;
    std::vector<int> values{};
    for(int i=0; i < N; ++i) {
        int x;
        cin >> x;
        values.emplace_back(x);
    }
    std::sort(values.begin(), values.end());
    int alice{}, bob{};
    while(!values.empty()) {
        alice += values.back();
        values.pop_back();
        if (!values.empty()) {
            bob += values.back();
            values.pop_back();
        }
    }
    cout << alice - bob << endl;
}


Measured memory_bytes: 256
import java.lang.Math.PI

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map(String::toInt) // list of ints
private fun readLongs() = readStrings().map(String::toLong) // list of longs

fun main(args: Array<String>) {
    val (n, m) = readLongs()
    val a = readLongs().sum()
    val x = n - a
    println(if (x >= 0) x else -1)
}

Measured memory_bytes: 39240
#define ll long long
#define ull unsigned long long
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
   int n,k,d,t;
   cin>>n>>k;
   set <int> s;
   for(int i=0;i<k;i++){
       cin>>d;
       for(int j=0;j<d;j++){
           cin>>t;
          s.insert(t);
       }
   }
   int count =0;
   for(int i=1;i<=n;i++){
       if(!(s.find(i)!=s.end()))
       count++;
   }
   cout<<count ;
    return 0;
}


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

int main(void){
    int i,j,n,k,w[100010],max=0;
    cin>>n>>k;
    
    for(i=0;i<n;i++){
        cin>>w[i];
        if(max<w[i])max=w[i];
    }
    
    int left=0,right=2000000000,mid;
    int tmp=0;
    while(right-left>1){
        mid=(left+right)/2;
        //cout<<left<<" "<<mid<<" "<<right;
        j=1;
        tmp=0;
        for(i=0;i<n;i++){
            if(tmp+w[i]<=mid){
                tmp+=w[i];
            }
            else{
                j++;
                tmp=w[i];
            }
        }
        if(j>k){
            left=mid;
            //cout<<" False"<<endl;
        }
        else{
            right=mid;
            //cout<<" True"<<endl;
        }
    }
    
    if(right<max)right=max;
    
    cout<<right<<endl;
    return 0;
}



Measured memory_bytes: 3484
#include<bits/stdc++.h>
using namespace std;
int ara_D[100][200];
int ara[100000];
char ara1[100000];
int main()
{
    int a,b,h,area;
    scanf("%d %d %d",&a,&b,&h);
    area=(a+b)*(h/2);
    printf("%d\n",area);
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

const int MAXN = 100005;
int n, v, p;
ll m;
vector<ll> a(MAXN);

bool ok(int t) {
    if(t<=p) return true;               // すでに圏内
    if(a[p-1]>a[t-1]+m) return false;   // mを加えても逆転できない
    if(n-t+p >= v) return true;         // 加算する問題の種類がp-1位まで、自分、自分以降の数以下
    ll add = (v-(n-t+p)) * m;           // add: 追い抜く必要がある問題に加算されるスコア
    ll mxt = a[t-1] + m;
    ll tmp = 0;
    for (int i = p-1; i < t-1; i++) {
        tmp += mxt - a[i];
        if (tmp >= add) return true;    // add を全部足しても、追い越せる
    }
    return false;
}

int main() {
	cin >> n >> m >> v >> p;
    rep(i,n) cin >> a[i];
    sort(a.begin(), a.end(), greater<ll>());

    ll ans;
    ll start = 1, end = n+1;
    while (start + 1 < end) {
        ans = (start + end) / 2;
        if (ok(ans)) start = ans;
        else         end   = ans;
    	// cout << start << ' ' << ans << ' ' << end << endl;
    }
    ans = (start + end) / 2;
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int INF = pow(2,29);
const int MOD = 1000000007;

int main() {
  ll N, M; cin >> N >> M;
  ll dp[M+1][N+1][N+1] = {}; dp[0][1][1] = 1;
  rep(i,M+1) rep(j,N+1) {
    if (i==0||j==0) continue;
    rep(k,j) {
      if(k==0) continue;
      dp[i][j][k] = dp[i-1][j-1][k] * (N-(j-1)) + dp[i-1][j][k] * (j-k);
      dp[i][j][k] %= MOD;
    }
    rep(k,j+1) {
      dp[i][j][j] += dp[i-1][j][k] * k;
      dp[i][j][j] %= MOD;
    }
  }
  // rep(i,M+1) { rep(j,N+1) { rep(k,N+1) cout << dp[i][j][k] << " "; cout << endl; } cout << endl; }
  ll result = dp[M][N][N];
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 213248