akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define inf (long long)1e16
using namespace std;

struct data {
  long long p, d;
};

bool operator<(const data &l, const data &r) {
  if(l.d != r.d) return l.d > r.d;
  return l.p > r.p;
}

long long n;
long long dis[100005] = {0};
vector<data> edge[100005];
priority_queue<data> pq;

void solve();

int main() {
  cin >> n;
  for(int i = 0; i < n - 1; ++i) {
    long long x, y, d;
    cin >> x >> y >> d;
    --x, --y;
    edge[x].push_back({y, d});
    edge[y].push_back({x, d});
  }
  solve();
  for(int i = 0; i < n; ++i) cout << dis[i] % 2 << endl;
  return 0;
}

void solve() {
  for(int i = 0; i < n; ++i) dis[i] = inf;
  dis[0] = 0;
  pq.push({0, 0});
  while(pq.size() > 0) {
    data now = pq.top();
    pq.pop();
    for(int i = 0; i < edge[now.p].size(); ++i) {
      data nextp = now;
      nextp.d += edge[now.p][i].d;
      nextp.p = edge[now.p][i].p;
      if(nextp.d < dis[nextp.p]) {
        dis[nextp.p] = nextp.d;
        pq.push(nextp);
      }
    }
  }
}


Measured memory_bytes: 8704
#include <bits/stdc++.h>
using ll= long long ;
#define rep(i,n) for (ll i = 1; i<=(ll)(n); i++)
using namespace std;
using P = pair<ll,ll>;
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a, ll b){
    ll g=gcd(a,b);
    return a/g*b;
}

int main() {
    ll K;
    int sum=0;
    cin >> K;
    rep(i,K){
        rep(j,K){
            rep(m,K){
             sum=sum+ gcd(gcd(i,j),m);
            }

        }
    }

cout << sum << endl;
return 0;

}


Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

using ll = long long;
using p = pair<ll, ll>;

constexpr ll INF = 1LL << 62;
constexpr ll MOD = 1e9 + 7;

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

    ll H, W, N;
    cin >> H >> W >> N;

    vector<ll> A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }

    vector<vector<ll> > C(H, vector<ll>(W, 0));
    ll ptr = 0;
    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j < A[i]; j++) {
            ll h = ptr / W;
            ll w = ptr % W;
            if (h % 2) {
                w = W - w - 1;
            }

            C[h][w] = i + 1;

            ptr++;
        }
    }

    for (ll h = 0; h < H; h++) {
        for (ll w = 0; w < W; w++) {
            cout << C[h][w] << " \n"[w == W - 1];
        }
    }

    return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    string s;
    cin >> s;
    int res = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '?') {
            s[i] = 'D';
        } 
    }
    cout << s << endl;
}


Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,l,a,b=-1,c,s=0;
  ll i,j,k;
  cin >> n >> l;
  list<ll> q;
  queue<ll> ans;
  ll le=1,ri=n-1;
  bool f=false;
  for(i=0;i<n;i++){
    cin >> a;
    if(b!=-1)
      if(a+b>=l){
	f=true;
	c=i;
      }
    q.push_back(a);
    b=a;
  }
  if(!f){
    cout << "Impossible" << endl;
  }else{
    cout << "Possible" << endl;
    for(i=1;i<c;i++) cout << i << endl;
    for(i=n-1;i>c;i--) cout << i << endl;
    cout << c << endl;
  }
  return 0;
}

Measured memory_bytes: 3968
//default
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef pair<int, int> P_i;
typedef pair<double,double> P_d;
#define rep(i,n) for(int i=0;i<(n);++i)
#define alrep(i,j,n) for(int i=0;i<(n);++i)for(int j=i+1;j<(n);++j)
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
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; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;

signed main(){
  int N;
  cin >> N;
  int count=0;
  int ans=0;
  for(int i=1;i<=N;i++){
    int p;
    cin >> p;
    if(p==i){
      count++;
      if(count==2){
        ans--;
        count=0;
      }
      ans++;
    }
    else{
      count = 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Fri May 17 15:12:31 2019

@author: avina
"""
from fractions import gcd
n,m = map(int, input().split())
l = [abs(m - int(i)) for i in input().split()]

g =l[0]
for i in range(1,n):
    g = gcd(g,l[i])
print(g)

Measured memory_bytes: 16236
#include <bits/stdc++.h>
using namespace std;
 
const int ms = 1e5 + 17;
 
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    string  n;
    cin >> n;
 
    int val = n[0] - '0';
    bool OK = true;
    for(int i = 1; i < 3; ++i)
    {
        if(n[i] - '0' == val)
            continue;
        else
            OK = false;
    }
 
    if(OK)
        cout << "Yes\n";
    else
    {
        OK = true;
        int nv = n[1] - '0';
        for(int i = 2; i < n.size(); ++i)
        {
            if(n[i] - '0' == nv)
                continue;
            else
                OK = false;
        }
 
        if(!OK)
            cout << "No\n";
        else
            cout << "Yes\n";
    }
 
 
}

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

int main(){
    int N;
    cin >> N;
    string s;
    cin >> s;
    int ans = 0, x = 0;
    for (int i = 0; i < N; i++) {
        if (s[i] == 'I') x++;
        else x--;
        ans = max(ans, x);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using cd = complex <double>;
 
typedef pair <int, int> pii;
 
const long long Inf = 2e18;
const long long mod = 998244353;
const double Pi = acos(-1);
 
void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int n;
long long ans = 0;

int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		ans += 1ll * i * (n - i + 1); 
	}
	for(int i = 1; i <= n - 1; i++)
	{
		int u, v;
		cin >> u >> v;
		if(u > v)
		{
			swap(u, v);
		}
		ans -= 1ll * u * (n - v + 1);
	}	
	cout << ans;
}

Measured memory_bytes: 3640
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N;
  long long K;
  cin >> N >> K;
  vector<pair<int, int> > v;
  for (int i = 0; i < N; i++) {
    int a, b;
    cin >> a >> b;
    v.push_back(make_pair(a, b));
  }

  sort(v.begin(), v.end());
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    sum += v[i].second;
    if (sum >= K) {
      cout << v[i].first << endl;
      break;
    }
  }

  return 0;
}

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

int cnt[404040];
int offset = 201010;

int main() {
    string s;
    cin >> s;

    stack<char> prev;
    stack<int> state;
    int pointer = 0;
    ll ans = 0;

    for (char c : s) {
        if (c == '(') {
            cnt[pointer + offset]++;
            pointer++;
            prev.push(c);
        }
        else if (c == ')') {
            state.push(cnt[pointer + offset]);
            cnt[pointer + offset] = 0;
            pointer--;
            ans += cnt[pointer + offset];
            prev.push(c);
        }
        else {
            char p = prev.top(); prev.pop();
            if (p == '(') {
                pointer--;
                cnt[pointer + offset]--;
            }
            else {
                ans -= cnt[pointer + offset];
                pointer++;
                cnt[pointer + offset] = state.top(); state.pop();
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 4872
N , L = map(int,input().split())
if L + N - 1 >= 0 and L <= 0:
	print(int((2 * L + N - 1) * N / 2))
else:
	if L + N - 1 > 0:
		print(int(((2 * L + N - 1) * N / 2) -L))
	else:
		print(int(((2 * L + N - 1) * N / 2) - (L + N - 1)))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
using namespace std;
//using namespace __gnu_pbds;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long 
#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,arr,n) for(int i=arr;i<=n;i++)
#define repd(i,arr,n) for(int i=arr;i>=n;i--)
#define trav(arr,x) for(auto& arr:x)
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(arr) arr.size()
#define pi 3.14159265358979323846
#define MAX (1000*1000*1000+7)
#define vi vector<int>
#define pii pair<int,int>
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int,vi,greater<int> >
//#define endl "\n"
 
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
const int mod=1e10+7;
int power(int a,int b)
{
    int ans=1;
    while(b)
    {
        if(b&1)
        {
            ans=(ans*a);
        }
        a=(a*a);
        b>>=1;
    }
    return ans;
}

int32_t main()
{
    fast;

    int x,val;
    cin>>x;

    rep(i,1000)
    {
        rep(j,1000)
        {
            val=pow(i,5)-pow(j,5);
            if(val==x)
            {
                cout<<i<<" "<<j<<endl;
                return 0;
            }

            val=pow(i,5)+pow(j,5);
            if(val==x)
            {
                cout<<i<<" "<<j*-1<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 4024
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n;
  scanf("%d",&n);
  int64 *a=(int64 *)malloc(sizeof(int64)*n);
  int64 *b=(int64 *)malloc(sizeof(int64)*n);
  int i;
  for(i=0;i<n;i++) scanf("%lld%lld",a+i,b+i);
  int64 cnt=0;
  for(i=n-1;i>=0;i--){
    if((a[i]+cnt)%b[i]==0) continue;
    cnt+=b[i]-(a[i]+cnt)%b[i];
  }
  printf("%lld\n",cnt);
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
char a[1001],b[1001];
char max1=0,min1=127;
int main()
{
	scanf("%s\n",a);
	scanf("%s",b);
	if(strcmp(a,b)==0){
		printf("No\n");
		return 0;
	}
	for(int i=0;i<strlen(b);i++)
		if(b[i]>max1) max1=b[i];
	for(int i=0;i<strlen(a);i++)
		if(a[i]<min1) min1=a[i];
	if(min1<max1){
		printf("Yes");
		return 0;
	}
	if(strcmp(a,b)<0) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 256
/* author   : mpily :-()
title : Competing.cpp
time :Sun Jun 14 13:11:23 2020

*/
#include<climits>
#include<random>
#include<cassert>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<algorithm>
#include<utility>
#include<cstdint>
#include<queue>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdio>
//4611686018427387903
using namespace std;
void solve(int cnum){	
	int n;
	cin >> n;
	vector<int64_t> arr(n);
	for(int i = 0; i < n; ++i)
		cin >> arr[i];
	sort(arr.rbegin(),arr.rend());
	int64_t ans  = 0;
	int count = 0;
	bool rep = true;
	for(int i = 0; count < n-1; ++i,++count){
		ans+=arr[i];
		if(rep){
			rep = false;
		}
		else{ 
			i-=1;
			rep = true;
		}
	}
	cout << ans <<"\n";	
}
int main(){
	
	//ios_base::sync_with_stdio(false);
	//cin.tie(nullptr);
	//cout.tie(nullptr);
	//initprime();
	int t;
	int count = 1;
	for(t = 1;t--; solve(count),count++);
	return 0;
}

Measured memory_bytes: 4752
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
    int N = 0,as = 0,bs = 0;
    vector<unsigned int> a;
    cin >> N;
    for(unsigned int i = 0; i < N; i++){int ai;cin >> ai;a.push_back(ai);}
    
    for(unsigned int i = 0; i < N; i++){
        if(i % 2 == 0){
            bs += *max_element(a.begin(), a.end());
        }else{
            as += *max_element(a.begin(), a.end());
        }
        a.erase(max_element(a.begin(), a.end()));
    }
    
    cout << (as > bs ? as - bs : bs - as) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define BUILDING 4
#define FLOOR  	 3
#define ROOM	 10

void input(int cnt[][FLOOR][ROOM]){
	int max, b, f, r, v;
	scanf("%d", &max);
	while (max--){
		scanf("%d %d %d %d", &b, &f, &r, &v);
		cnt[b-1][f-1][r-1] += v;
	}
}
void output(int cnt[][FLOOR][ROOM]){
	unsigned int i, j, k;
	for (i = 0; i < BUILDING; i++){
		for (j = 0; j < FLOOR; j++){
			for (k = 0; k < ROOM; k++){
				if (!(k == ROOM))printf(" ");
				printf("%d",cnt[i][j][k]);
			}
			printf("\n");
			if ((j == FLOOR - 1)&&(i<BUILDING-1)){
				for (k = 0; k < ROOM*2; k++){
					printf("#");
				}
				printf("\n");
			}
		}
	}
}
int main(void){
	int cnt[BUILDING][FLOOR][ROOM] = { 0 };
	int(*pcnt)[FLOOR][ROOM] = cnt;
	input(pcnt);
	output(pcnt);
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define ll      long long
#define pii     pair<int, int>
#define f       first
#define s       second
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d ", a)
#define pfl(a) printf("%lld\n", a)
#define Case(a) printf("Case %d: ", a)

using namespace std;
int mp[2005][2005], cnt[2009], vis[2009], dis[2009];
int main()
{
//    int t;
//    cin>>t;
//
//    for(int tc = 1;tc<=t; tc++){
//
//    }
    int n, x, y;
    cin>>n>>x>>y;

    vector<int>g[n+9];
    for(int i=1;i<n;i++){
        g[i].push_back(i+1);
        g[i+1].push_back(i);
    }
    g[x].push_back(y);
    g[y].push_back(x);

    for(int i=1;i<=n;i++){
        memset(vis, 0, sizeof(vis));
        memset(dis, 0, sizeof(dis));
        queue<int>q;
        q.push(i);
        dis[i] = 0;
        vis[i] = 1;
        while(!q.empty())
        {
            int s = q.front();
            q.pop();
            for(int j=0;j<g[s].size();j++){
                if(vis[g[s][j]] == 0){
                    vis[g[s][j]] = 1;
                    dis[g[s][j] ] = dis[s] + 1;
                    q.push(g[s][j]);
                }
            }
        }

        for(int j=1;j<i;j++){
            mp[j][i] = dis[j];
        }

        for(int j=i+1;j<=n;j++){
            mp[i][j] = dis[i];
        }
    }

    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            cnt[mp[i][j]]++;
        }
    }

    for(int i=1;i<n;i++){
        cout<<cnt[i]<<endl;;
    }
}






Measured memory_bytes: 15488
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
	stdout     *bufio.Writer
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), math.MaxInt32)
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		return []byte(f1())
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func abs64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func gcd64(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd64(b, a%b)
}

// readString() string
// readInt() int
// readInt64() int64
// readFloat64() float64

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

func main() {
	defer stdout.Flush()
	s := readString()
	if s == "Sunny" {
		println("Cloudy")
	} else if s == "Cloudy" {
		println("Rainy")
	} else {
		println("Sunny")
	}
}

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


Measured memory_bytes: 640
#include<stdio.h>
int main(){
  int W, H, x, y, r;
  scanf("%d%d%d%d%d",&W, &H, &x, &y, &r);
  
  if(x+r <= W && y+r <= H && x-r >= 0 && y-r >= 0){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
 
  return 0;
   }

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll x,i;
int main(){
	cin>>x;
    while(1)
    {
    	bool f=1;
    	for(i=2;i*i<=x;i++)
    	 {
    	 	if(x%i==0){
    	 		f=0;break;
    	 	}
    	 }
    	 if(f==0)x++;
    	 else
    	   {cout<<x;return 0;
    	   }
    }
	return 0;
}


Measured memory_bytes: 256
s = list(input())
t = list(input())
ans = [-1, -1]
if len(t) <= len(s):
    for i in range(len(s) - len(t) + 1):
        c = 1
        for j in range(len(t)):
            if s[i + j] != "?" and t[j] != s[i + j]:
                c = 0
                break
        if c == 1:
            ans = [i, i + len(t)]

if ans != [-1, -1]:
    k = []
    for i in range(len(s)):
        if ans[0] <= i < ans[1]:
            k.append(t[i - ans[0]])
        else:
            if s[i] == "?":
                k.append("a")
            else:
                k.append(s[i])
    print("".join(k))
else:
    print("UNRESTORABLE")


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{
  
  int n,i;
  long sum=0,max,min,num;
  cin>>n;
  if(n==0)return 0;
  
  for(i=0; i<n; i++){
  
    cin>>num;
    if(i==0)max=min=num;
    if(num>max)max=num;
    if(num<min)min=num;
    sum+=num;
   
  }
  
  cout<<min<<" "<<max<<" "<<sum<<"\n";
  
}

Measured memory_bytes: 3100
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> m(n);
    ll sum = 0;
    ll minmun = 100000;
    rep(i,n)cin >> m[i], sum += m[i], minmun = min(minmun, m[i]);
    cout << n + (x-sum)/minmun;

}


Measured memory_bytes: 256
from math import gcd


N, *A = map(int, open(0).read().split())
acc_l = [0]
acc_r = [0]
for i in range(N):
    acc_l.append(gcd(acc_l[-1], A[i]))
    acc_r.append(gcd(acc_r[-1], A[N - i - 1]))

ans = 0
for i in range(N):
    ans = max(ans, gcd(acc_l[i], acc_r[N - i - 1]))
print(ans)


Measured memory_bytes: 21256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 1000010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;
vector<int> P;
bool is_prime[100010];

void Eratosthenes( const int N )
{
    rep(i, N) {
        is_prime[i] = true;//初期化
    }    
    for(int i=2; i<=N; i++) {
        if( is_prime[i] ){
            for(int j=2*i; j<=N; j+=i) {
                is_prime[j] = false;
            }
            P.push_back(i);
        }
    }
}

int main() {
    Eratosthenes(100010);

    int n, a;
    while (cin>>n, n) {
        int ans = 0;
        for(int i=0; P[i]<=n/2; ++i) {
            a = P[i];
            if(is_prime[n-a]) ++ans;
        }
        cout << ans << endl;
    }
}




Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;

int N, testi[17][17], ans;
int main(){
    for (int i = 0; i <= 15; i++) {
        for (int j = 0; j <= 15; j++) {
            testi[i][j]=2;
        }
    }
    scanf("%d", &N);
    for (int i = 0, a; i < N; i++) {
        scanf("%d", &a);
        for (int j = 0, x, y; j < a; j++) {
            scanf("%d %d", &x, &y); x--;
            testi[i][x] = y;
        }
    }
    vector<int> arr, honest;
    for (int i = 0; i < (1<<(N+1))-1; i++) {
        arr.clear(); honest.clear();
        for (int j = 0; j < N; j++) {
            if(((1<<j) & i)) {arr.emplace_back(1); honest.emplace_back(j);}
            else arr.emplace_back(0);
        }
        bool yes = true;
        for (int j = 0; j < honest.size() && yes; j++) {
            for (int k = 0; k < N && yes; k++) {
                if(testi[honest[j]][k]==2) continue;
                yes = arr[k]==testi[honest[j]][k];
            }
        }
        if(!yes) continue;
        ans = max(ans, int(honest.size()));
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define MAX 200005
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define f first
#define s second

ll n, m, i, j, k, t, l, r,tmp, ans, cnt,curr, flag, sum, mn, mx, mxi,x,pre,strt,en;
ll brr[MAX], arr[MAX], lst[MAX], dp[MAX];
string s;
queue<pair<pair<ll,ll> , ll > > q, q2;
pair<pair<ll,ll> , ll > pp;
map<ll, multiset<ll> > mpp;


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

        for(i=1;i<=n;i++){
            cin>>arr[i];
            brr[i] = lst[arr[i]];
            lst[arr[i]] = i;
        }
        dp[0]=1;
        for(i=1;i<=n;i++){
            if(!brr[i] || brr[i] == i-1)
                dp[i] = dp[i-1];
            else
                dp[i] = (dp[i-1] + dp[brr[i]])%MOD;
        }
        cout<<dp[n];



       
    
    return 0;   
}

Measured memory_bytes: 6528
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <stdio.h>
#include <unistd.h>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define itrep(itr, base) for (auto itr = base.begin(); itr != base.end(); itr++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl
#define PI 3.14159265359

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  int n;
  cin >> n;
  vector<int> c(n - 1);
  vector<int> s(n - 1);
  vector<int> f(n - 1);
  rep (i, n - 1) {
    cin >> c[i] >> s[i] >> f[i];
  }

  rep (i, n - 1) {
    int now = 0;
    for (int j = i; j < n - 1; j++) {
      if (now < s[j]) now = s[j];
      if (now % f[j] != 0) {
        now = (1 + (now / f[j])) * f[j];
      }
      now += c[j];
    }
    P(now);
  }
  P(0);


  return 0;
}


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

int main(void){
    int a,b;
    cin >> a;
    cin >> b;
    if (a<b) {
        cout <<"a < b";
    }
    else if (a>b) {
        cout <<"a > b";
    }
    else {
        cout <<"a == b";
    }
    cout <<endl;
    
    
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-12, PI = acos(-1);
const int N = 3e3 + 9, M = 1e7 + 9, OO = 1e9 + 7, MOD = 1e9 + 7, MOD2 = 998244353;
const ll INF = 2e18;

int main() {
	fastIO;
#ifdef LOCAL
	freopen("input.in", "rt", stdin);
#endif
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vector<ll> A, B, C;
	ll val;
	for (int i = 0; i < a; ++i) {
		cin >> val;
		A.push_back(val);
	}
	for (int i = 0; i < b; ++i) {
		cin >> val;
		B.push_back(val);
	}
	for (int i = 0; i < c; ++i) {
		cin >> val;
		C.push_back(val);
	}
	sort(all(A), greater<ll>());sort(all(B), greater<ll>());sort(all(C), greater<ll>());
	while((int)A.size() != x)
		A.pop_back();
	while((int)B.size() != y)
		B.pop_back();
	multiset<ll> stA = multiset<ll>(all(A));
	multiset<ll> stB = multiset<ll>(all(B));
	while(!C.empty()) {
		auto it1 = (*stA.begin());
		auto it2 = (*stB.begin());
		ll reqA = C.back() - it1, reqB = C.back() - it2;
		if(reqA <= 0 && reqB <= 0) {
			C.pop_back();
			continue;
		}
		if(reqA >= reqB) {
			stA.erase(stA.begin());
			stA.insert(C.back());
		} else {
			stB.erase(stB.begin());
			stB.insert(C.back());
		}
		C.pop_back();
	}
	ll total = 0;
	for(ll it: stA) total += it;
	for(ll it: stB) total += it;
	cout << total;
	return 0;
}


Measured memory_bytes: 10996
from functools import reduce
from fractions import gcd
mod = 10**9 + 7
n, *A = map(int, open(0).read().split())
if len(A) == 1:
    print(1)
else:
    l = reduce(lambda x, y: x*y // gcd(x, y), A) % mod
    s = 0
    for a in A:
        s += l * pow(a, mod-2, mod)
        s %= mod
    print(s)

Measured memory_bytes: 6084
import java.util.*;

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

        if(b != 1){
            for(i = 0;ans < b;i++){
                if(i == 0){
                    ans = a;
                }else{
                    ans += a-1;
                }
            }
            System.out.println(i);
        }else{
            System.out.println(0);
        }
    }
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n, nn;
    cin >> n;
    nn = n;
    int digit_sum = 0;
    while (n)
    {
        digit_sum += n % 10;
        n /= 10;
    }

    // cout << digit_sum << endl;
    if ((nn % digit_sum) == 0)
        cout << "Yes" << endl;
    else
    {
        cout << "No" << endl;
    }
}


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

class Program
{
    static void Main(string[] args)
    {
        new Magatro().Solve();
    }
}

public class Magatro
{
    private string S, T;
    private int Q;
    public void Solve()
    {
        S = Console.ReadLine();
        T = Console.ReadLine();
        int[] sArr = new int[S.Length + 1];
        for (int i = 1; i <= S.Length; i++)
        {
            sArr[i] = sArr[i - 1];
            sArr[i] += S[i-1] == 'A' ? 1 : 2;
        }
        int[] tArr = new int[T.Length + 1];
        for (int i = 1; i <= T.Length; i++)
        {
            tArr[i] = tArr[i - 1];
            tArr[i] += T[i-1] == 'A' ? 1 : 2;
        }
        Q = int.Parse(Console.ReadLine());
        for(int i = 0; i < Q; i++)
        {
            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            int c = int.Parse(s[2]);
            int d = int.Parse(s[3]);
            if ((sArr[b] - sArr[a - 1]) % 3 == (tArr[d] - tArr[c - 1]) % 3)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}

Measured memory_bytes: 16948
import kotlin.math.abs

fun longList() = readLine()?.split(" ")?.map(String::toLong) ?: TODO()
fun main() {
    data class Point(val x: Int, val y: Int, val h: Long)

    val n = readLine()?.toInt() ?: return
    val points = mutableListOf<Point>()
    repeat(n) {
        val (x, y, h) = longList()
        points.add(Point(x.toInt(), y.toInt(), h))
    }
    points.sortByDescending { it.h }

    0.until(101).forEach { x ->
        0.until(101).forEach { y ->
            run loop@{
                var d = -1L
                points.forEach {
                    val diff = it.h + abs(it.x - x) + abs(it.y - y)
                    if (d == -1L) {
                        d = diff
                    } else {
                        if (it.h > 0L && d != diff) {
                            return@loop
                        }
                        if (it.h == 0L && d > diff) {
                            return@loop
                        }
                    }
                }
                println("$x $y $d")
                return
            }
        }
    }
}

Measured memory_bytes: 38876
import itertools
from math import sqrt
def chunk(a):
    i = 0
    res = []
    while i < len(a):
        res.append(a[i])
        while i != len(a) - 1 and a[i + 1] == a[i] + 1:
            i += 1
        res.append(a[i] + 1)
        i += 1
    return res

def augment(g, src, dest):
    o = [None] * len(g)
    q = [(src, src)]
    while q:
        w = q.pop()
        if o[w[0]] is None:
            o[w[0]] = w[1]
            for s in g[w[0]]:
                if o[s] is None:
                    q.append((s, w[0]))
    if not o[dest]:
        return False
    i = dest
    while i != src:
        g[o[i]].discard(i)
        g[i].add(o[i])
        i = o[i]
    return True

def match(a):
    l = {}
    c = 0
    matches = 0
    for i, j in a:
        if i not in l:
            l[i] = c
            c += 1
        if j not in l:
            l[j] = c
            c += 1
    L = {v: k for k, v in l.items()}
    g = [set() for i in range(len(l) + 2)]
    src = len(l)
    dest = src + 1
    for i, j in a:
        g[src].add(l[i])
        g[l[i]].add(l[j])
        g[l[j]].add(dest)
    while augment(g, src, dest):
        matches += 1
    return matches

def prime(n):
    for i in range(2, min(n, int(sqrt(n) + 7))):
        if n % i == 0:
            return False
    return n > 1

def pairs(b):
    c = []
    for i in b:
        for j in b:
            if i % 2 == 0 and j % 2 == 1 and prime(abs(i - j)):
                c.append((i, j))
    return c

n = int(input())
a = list(map(int, input().split()))
b = chunk(a)
r = match(pairs(b))
e = len(list(filter(lambda x: x % 2 == 0, b)))
o = len(b) - e
print(int(r + 2 * ((e - r) // 2 + (o - r) // 2) + 3 * ((e - r) % 2)))

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

ll dp[300000][2] = {0};
ll sum[300000][2] = {0};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    ll n = s.size();
    dp[0][0] = 1;
    for (ll i = 0; i < n; i++)
    {
        ll sNum = s[i] - '0';
        ll tNum = t[i] - '0';
        if (t[i] != '?')
        {
            if (sNum == tNum)
            {
                (dp[i + 1][0] += dp[i][0]) %= MOD;
                (dp[i + 1][1] += dp[i][1]) %= MOD;
                (sum[i + 1][1] += (sum[i][1] * 10 % MOD + dp[i][1] * tNum % MOD) % MOD) %= MOD;
                (sum[i + 1][0] += (sum[i][0] * 10 % MOD + dp[i][0] * tNum % MOD) % MOD) %= MOD;
            }
            else if (sNum < tNum)
            {
                (dp[i + 1][1] += dp[i][1]) %= MOD;
                (sum[i + 1][1] += (sum[i][1] * 10 % MOD + dp[i][1] * tNum % MOD) % MOD) %= MOD;
            }
            else
            {
                (dp[i + 1][1] += dp[i][1]) %= MOD;
                (dp[i + 1][1] += dp[i][0]) %= MOD;
                (sum[i + 1][1] += (sum[i][1] * 10 % MOD + dp[i][1] * tNum % MOD) % MOD) %= MOD;
                (sum[i + 1][1] += (sum[i][0] * 10 % MOD + dp[i][0] * tNum % MOD) % MOD) %= MOD;
            }
        }
        else
        {
            for (ll j = 0; j <= 9; j++)
            {
                tNum = j;
                if (sNum == tNum)
                {
                    (dp[i + 1][0] += dp[i][0]) %= MOD;
                    (dp[i + 1][1] += dp[i][1]) %= MOD;
                    (sum[i + 1][1] += (sum[i][1] * 10 % MOD + dp[i][1] * tNum % MOD) % MOD) %= MOD;
                    (sum[i + 1][0] += (sum[i][0] * 10 % MOD + dp[i][0] * tNum % MOD) % MOD) %= MOD;
                }
                else if (sNum < tNum)
                {
                    (dp[i + 1][1] += dp[i][1]) %= MOD;
                    (sum[i + 1][1] += (sum[i][1] * 10 % MOD + dp[i][1] * tNum % MOD) % MOD) %= MOD;
                }
                else
                {
                    (dp[i + 1][1] += dp[i][1]) %= MOD;
                    (dp[i + 1][1] += dp[i][0]) %= MOD;
                    (sum[i + 1][1] += (sum[i][1] * 10 % MOD + dp[i][1] * tNum % MOD) % MOD) %= MOD;
                    (sum[i + 1][1] += (sum[i][0] * 10 % MOD + dp[i][0] * tNum % MOD) % MOD) %= MOD;
                }
            }
        }
    }
    cout << (sum[n][0] + sum[n][1]) % MOD << endl;
}


Measured memory_bytes: 9688
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    while (a%2 == 0) {
      a /= 2;
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3560
#include <stdio.h>
#include <math.h>
int main(void)
{
    long int s=1;
    int n,i;
    
    scanf("%d",&n);
    
    for(i=1;i<=n;i++){
        s=s*i%1000000007;
    }
    
    printf("%ld\n",s);
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;

//map<string>a
class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% mod + mod) % mod) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint & a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator-=(const mint & a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint & operator*=(const  mint & a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint & a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint & a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint & a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint & a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint & a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream & os, const mint & m) {
		os << m.x;
		return os;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
//組み合わせ
void recursive_comb(vector<int> indexes, int s, int rest, std::function<void(vector<int>)> f) {
	if (rest == 0) {
		f(indexes);
	}
	else {
		if (s < 0) return;
		recursive_comb(indexes, s - 1, rest, f);
		indexes[rest - 1] = s;
		recursive_comb(indexes, s - 1, rest - 1, f);
	}
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(vector<int>)> f) {
	vector<int>indexes(k);
	recursive_comb(indexes, n - 1, k, f);
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};

int main() {
	int a;
	cin >> a;
	cout << a * a + a + a * a * a;

	//cout << fixed << setprecision(10) << ans;
}


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

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int n = fs.nextInt();
		int a[] = fs.nextIntArray(n);
		for(int i=0;i<n;i++) {
			a[i] -= (i+1);
		}
		Arrays.sort(a);
		long sum[] = new long[n+1]; //絶対値の累積和
		for(int i=0;i<n;i++)sum[i+1]=sum[i]+a[i];
		
		long ans = Long.MAX_VALUE/2;
		
		if(n==1) {
			System.out.println(0);
			return;
		}
		
		for(int i=1;i<n;i++) {
			long sumL = sum[i];
			long sumR = sum[n] - sum[i];
			long tmp = sumR - sumL;
			int b1 = a[i-1];
			int b2 = a[i];
			int min = Integer.MAX_VALUE/2;
			if((long)b1 * b2 < 0)min = 0;
			else min = Math.min(b1, b2);
			int max = Math.max(b1, b2);
			if((long)2*i-n >= 0) {
				tmp = tmp + ((long)2*i - n) * min;
			}else {
				tmp = tmp + ((long)2*i - n) * max;
			}
			ans = Math.min(ans, tmp);
		}
		
		System.out.println(ans);
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

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

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

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

Measured memory_bytes: 48236
N, K = map(int, input().split())

d = []
sunuke = [0] * N
for i in range(K):
    d.append(int(input()))
    A = list(map(int, input().split()))
    for j in A:
        sunuke[j - 1] += 1

ans = []
for i in range(N):
    if sunuke[i] == 0:
        ans.append(i + 1)

print(len(ans))


Measured memory_bytes: 9192
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
constexpr int mod = 1e9 + 7;
int n;
char s[N];
void dfs(int d, int up)
{
	if(d==n)
	{
		s[d] = 0;
		cout << s << '\n';
		return;
	}
	for(int i=0; i<=up; i++)
	{
		s[d] = 'a' + i;
		dfs(d+1, up+(i==up));
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	dfs(0, 0);
	return 0;
}

Measured memory_bytes: 1536
#include<iostream>
int main()
{
 	int a, b;
  	std::cin >> a >> b;
  
  	int c = a * b;
  if(c % 2) {
    std::cout << "Yes" << std::endl;
  }
  else {
	std::cout << "No" << std::endl;
  }
}

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

int main()
{
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if (a + b < c + d)
    cout << "Right" << endl;
  else if (a + b > c + d)
    cout << "Left" << endl;
  else
    cout << "Balanced" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long dp[200001][16];
long long dp_[200001][16];

int main(){
    long long N;
    long long A[200001];
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    
    for(int i = 0; i < 16; i++){
        dp[N][i] = 0;
        dp[N-1][i] = i*2;
    }
    for(int i = N-2; i >= 0; i--){
        //cout << i << endl;
        long long cnt = 0;
        if(A[i+1] < A[i]){
            long long tmp = A[i+1];
            while(tmp < A[i]){
                tmp*=4;
                cnt++;
            }
            for(int j = 0; j <= 15; j++){
                if(j+cnt <= 15) dp[i][j] = dp[i+1][j+cnt] + 2*j;
                else dp[i][j] = dp[i+1][15] + 2*(N-i-1)*(j+cnt-15) + 2*j;
            }
        }else{
            long long tmp1 = A[i];
            while(4*tmp1 <= A[i+1]){
                tmp1*=4;
                cnt++;
                //cout << 'U' << endl;
            }
            for(int j = 0; j <= cnt; j++){
                dp[i][j] = dp[i+1][0] + 2*j;
            }
            for(int j = cnt+1; j <= 15; j++){
                dp[i][j] = dp[i+1][j-cnt] + 2*j;
            }
        }
        //cout << endl;
    }

    for(int i = 0; i < 16; i++){
        dp_[0][i] = 0;
        dp_[1][i] = 1+i*2;
    }
    for(int i = 2; i <= N; i++){
        //cout << i << endl;
        long long cnt = 0;
        if(A[i-2] < A[i-1]){
            long long tmp = A[i-2];
            while(tmp < A[i-1]){
                tmp*=4;
                cnt++;
                //cout << 'V' << endl;
            }
            for(int j = 0; j <= 15; j++){
                if(j+cnt <= 15) dp_[i][j] = dp_[i-1][j+cnt]+ 1 + 2*j;
                else dp_[i][j] = dp_[i-1][15] + 2*(i-1)*(j+cnt-15) + 1 + 2*j;
            }
        }else{
            long long tmp1 = A[i-1];
            while(4*tmp1 <= A[i-2]){
                tmp1*=4;
                cnt++;
                //cout << 'V' << endl;
            }
            for(int j = 0; j <= cnt; j++){
                dp_[i][j] = dp_[i-1][0] + 2*j + 1;
            }
            for(int j = cnt+1; j <= 15; j++){
                dp_[i][j] = dp_[i-1][j-cnt] + 2*j + 1;
            }
        }
        //cout << endl;
    }
    long long ans = __LONG_MAX__;
    for(int i = 0; i <= N; i++){
        long long min1, min2;
        min1 = dp[i][0];
        min2 = dp_[i][0];
        
        for(int j = 0; j <=15; j++){
            min1 = min(min1, dp[i][j]);
            min2 = min(min2, dp_[i][j]);
            //cout << dp[i][j] << ' ' << dp_[i][j] << endl;
            //cout << min1 << ' ' << min2 << endl;
        }
        //cout << min1 << ' ' << min2 << endl;
        ans = min(ans, min1+min2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 51840
# 入力
R, G, B, N = map(int, input().split())

# とりうるすべてのr, gの組に関して、条件を満たすbが存在するかを数え上げる
ans = sum(
    N - r * R - g * G >= 0 and (N - r * R - g * G) % B == 0
    for r in range(N // R + 1)
    for g in range((N - r * R) // G + 1)
)

# 出力
print(ans)

Measured memory_bytes: 40812
#include <stdio.h>

int main(void)
{
	char s[4];
	int i;
	int ans = 0;
	
	scanf("%s", s);
	
	for(i=0; i<4; i++){
		if(s[i] == '+')
			ans++;
		else
			ans--;
	}
	
	printf("%d", ans);
	
	
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define INF 1e9

int dp[1003][1003];
vector <pair<int, int> > l;

main(){
	int i,j,n,a,b,m=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a>>b;
		l.push_back(make_pair(b, a));
	}
	l.push_back(make_pair(0, 0));
	sort(l.begin(), l.end());
	for(i=0;i<=n;i++){
		for(j=0;j<=n;j++){
			dp[i][j] = (j)?INF:0;
		}
	}
	for(j=0;j<=n;j++){
		for(i=1;i<=n;i++){
			dp[i][j] = min(dp[i][j], dp[i-1][j]);
			if(dp[i-1][j]+l[i].second <= l[i].first){
				dp[i][j+1] = min(dp[i][j+1], dp[i-1][j] + l[i].second);
				m=max(m,j+1);
			}
		}
	}
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 0
n, a, b = gets.strip.split.map(&:to_i)
def digit_sum i
  sum = 0
  while i > 0 do
      sum += i % 10
      i /= 10
  end
  return sum
end
# n=140
p ans = (1..n)
        .map { |i| [i, digit_sum(i)] }
        .select { |d| a <= d[1] && d[1] <= b }
        .inject(0) { |sum, d| sum + d[0] }

Measured memory_bytes: 2172
A,B,C,D,E,F = map(int,input().split())

ans = 0
ansa = 0
ansb = 0


for a in range(0,(F//(100*A))+1):
    #水をa*A使う。
    for b in range(0,((F-100*a*A)//(100*B))+1):
        #水をb*B使う。
        #print(a,b)
        for pa in range((E*(a*A+b*B)//C) + 1):
            #print("お伝えするよ")
            limsug = F-100*(a*A+b*B)-pa*C
            if limsug>0:
                for ja in range((limsug//D)+1):

                    if a+b+pa+ja != 0:
                        nodo = 100*(pa*C+ja*D)/(100*(a*A+b*B)+pa*C+ja*D)
                        #print(a*A*100,b*B*100,pa*C,ja*D,nodo)

                        #print(a*A*100,b*B*100,pa*C,ja*D,nodo)
                        if nodo <= E and ans <= nodo and E*(a*A+b*B)>=pa*C+ja*D:
                            ans = nodo
                            ansa = 100*(a*A+b*B)+pa*C+ja*D
                            ansb = pa*C+ja*D


print(ansa,ansb)


Measured memory_bytes: 43244
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
const int mod = 1e9 + 7;
int main()
{
	int n,x,k(0);ll ans(1);
	scanf("%d",&n);
	for(register int i(1);i <= n;i++)
	{
		scanf("%d",&x),++k;
		if(x < (k << 1) - 1) {ans *= k,--k;if(ans >= mod) ans %= mod;}
	}
	while(k) {ans *= k,--k;if(ans >= mod) ans %= mod;}
	printf("%lld",ans);
	return 0;
}

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

#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
const string YES = "YES";
const string NO = "NO";

void solve(long long N, std::vector<long long> p){
    ll ans=0;
    rep(i,N){
        p[i]=p[i]-i-1;
        (p[i]==0)?0:ans++;
    }
    string d="";
    (ans<=2)?d=YES:d=NO;
    cout<<d<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
    }
    solve(N, std::move(p));
    return 0;
}


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

int main() {
	int i, j;
	int M, N;
	int *T, *D;
	cin >> N;
	T = new int[N];
	for (i = 0; i < N; i++)cin >> T[i];
	cin >> M;
	D = new int[M];
	for (i = 0; i < M; i++)cin >> D[i];
	sort(T, T + N);
	sort(D, D + M);
	i = j = 0;
	while (j < M) {
		if (T[i] == D[j]) {
			i++; j++;
		}
		else if (T[i] > D[j]) {
			cout << "NO" << endl;
			return 0;
		}
		else i++;
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<string.h>
int main()
{
	char num[1000];
	int sum;
	int i;
	
	while(1){
		sum = 0;
		scanf("%s",num);
		if(num[0] == '0'){
			break;
		}
	
	for(i = 0;i < strlen(num);i++)
		sum += num[i] - '0';
		 
	printf("%d\n",sum);
	}
 return 0;
}
	


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

bool isKaibun(string);

int main(){
  string s;
  cin >> s;
  
  string str1,str2;
  int n = s.size();
  str1 = s.substr(0,(n-1)/2);
  str2 = s.substr((n+3)/2-1);
  
  if(isKaibun(s) && isKaibun(str1) && isKaibun(str2)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

bool isKaibun(string s){
  string t(s.rbegin(),s.rend());
  if(s == t){
    return true;
  }else{
    return false;
  }
}

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

typedef long long ll;
#define PI 3.1415926535897932384626433
#define MOD 1000000007

int main(){
    string s;
    cin >> s;
    for (int i = 0; i < s.size()-1; i++){
        if(s[i] == s[i+1]){
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
    return 0;
}


Measured memory_bytes: 256