akhauriyash/Code-Regression huggingface dataset:
/*  ex7_3
    B30095    */
#include <stdio.h>
#include <stdlib.h>

void print_compressed(char ** grid, int rows, int cols);

int main(void){
    int rows, cols, isRowEmpty, isColEmpty, i, j;
    char ** grid;
    
    scanf("%d %d", &rows, &cols);
    
    // memory allocation
    grid = (char **)malloc(rows * sizeof(char *));
    if(grid == NULL){
        fprintf(stderr, "memory allocation error");
        return -1;
    }

    for(i = 0; i < rows; i++){
        grid[i] = (char *)malloc(cols * sizeof(char));
        if(grid[i] == NULL){
            fprintf(stderr, "memory allocation error");
            return -1;
        }
    }

    // input grid
    for(i = 0; i < rows; i++){
        for(j = 0; j < cols; j++){
            scanf(" %c", &(grid[i][j]));
        }
    }

    print_compressed(grid, rows, cols);

    // memory deallocation
    for(i = 0; i < rows; i++){
        free(grid[i]);
    }
    free(grid);

    return 0;
}


void print_compressed(char ** grid, int rows, int cols){
    int isRowEmpty, isColEmpty, i, j;

    // substitue empty rows with whitespaces
    for(i = 0; i < rows; i ++){
        isRowEmpty = 1;
        
        // check if the row is empty
        for(j = 0; j < cols; j++){
            if(grid[i][j] == '#') {
                isRowEmpty = 0;
            }
        }

        // fill in empty rows with whitespaces
        if(isRowEmpty){
            for(j = 0; j < cols; j++){
                grid[i][j] = ' ';
            }
        }
    }

    // substitue empty columns with whitespaces
    for(j = 0; j < cols; j ++){
        isColEmpty = 1;
        
        // check if the column is empty
        for(i = 0; i < rows; i++){
            if(grid[i][j] == '#') {
                isColEmpty = 0;
            }
        }

        // fill in empty columns with whitespaces
        if(isColEmpty){
            for(i = 0; i < rows; i++){
                grid[i][j] = ' ';
            }
        }
    }


    // print compressed result
    for(i = 0; i < rows; i++){
        isRowEmpty = 1;

        for(j = 0; j < cols; j++){
            if(grid[i][j] == '#') isRowEmpty = 0;
            if(grid[i][j] != ' ') printf("%c", grid[i][j]);
        }

        if(!isRowEmpty) printf("\n");  // new line should not be printed when the row is empty
    }
}

Measured memory_bytes: 1676
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	int N;
	cin >> N;
	string S;
	cin >> S;

	int ans = 0;
	for (int ii = 0; ii < 10; ++ii){
		for (int jj = 0; jj < 10; ++jj){
			for (int kk = 0; kk < 10; ++kk){
				vector <int> v;
				v.push_back(ii);
				v.push_back(jj);
				v.push_back(kk);
				int idx = 0;
				for (int ss = 0; ss < N; ++ss){
					int num = S[ss] - '0';
					if (v[idx]==num){
						idx++;
						if (idx==3){
							break;
						}
					}
				}
				if (idx==3){
					ans++;
				}
			}
		}
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3652
import numpy as np
N = int(input())
dp = np.zeros((N+1, 5, 5, 5), dtype = np.int64)
#dp[文字列の長さ][3文字前][2文字前][1文字前]
#0:dummy A:1, C:2, G:3, T:4
p = 10**9 + 7
dp[0, 0, 0, 0] = 1
for n in range(N):
  for i in range(5):#3文字前
    for j in range(5):
      for k in range(5):
        for l in range(1, 5):#今回追加する文字#0 : dummmyは初期条件の為なので回さない
          if j == 1 and k == 3 and l == 2:continue #AGC
          if j == 3 and k == 1 and l == 2:continue #GAC
          if j == 1 and k == 2 and l == 3:continue #ACG
          if i == 1 and k == 3 and l == 2:continue #A?GC
          if i == 1 and j == 3 and l == 2:continue #AG?C
          dp[n+1, j, k, l] += dp[n, i, j, k]
          dp[n+1, j, k, l] %= p
ans = 0
for i in range(1, 5):
  for j in range(1, 5):
    for k in range(1, 5):
      ans += dp[N, i, j, k]
      ans %=  p
print(ans)


Measured memory_bytes: 12488
#最大公約数
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

#最小公倍数
def lcm(a, b):
    return a * b // gcd(a, b)

A, B, C, D = map(int, input().split())

A = A -1
c_num = B//C - A//C
d_num = B//D - A//D
    
lcm_num = lcm(C, D)

cd_num = B//lcm_num - A//lcm_num
    
print(B - A - c_num - d_num + cd_num)

Measured memory_bytes: 3064
#include <cstdio>

int main(){
    int H,W;
    for(int c = 1;; c++){
        scanf("%d %d",&H,&W);
            if(H == 0 && W == 0){
                break;
            }
            
            for(int i = 1; i <= H; i++){
                if(i % 2 == 1){
                    for(int j = 1; j <= W; j++){
                        if(j % 2 == 1){
                            printf("#");
                        }else if(j % 2 == 0){
                            printf(".");
                        }
                    }
                    printf("\n");
                }else if(i % 2 == 0){
                    for(int j = 1; j <= W; j++){
                        if(j % 2 == 1){
                            printf(".");
                        }else if(j % 2 == 0){
                            printf("#");
                        }
                    }
                    printf("\n");
                }
            }
            printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2596
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
 int main(){
   int k;
   cin>>k;
   int x=7%k;
  set<int>s;
   int i=1;
   while(s.count(x)==0){
     if(x==0){
     cout<<i<<endl;
       return 0;
     }
    s.insert(x);
   x=(x*10+7)%k;
     i++;
   }
   cout<<-1<<endl;
}

Measured memory_bytes: 50504
/*input
6
abcadc
*/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define MAX 10005
#define endl "\n"
#define mp make_pair
#define pb push_back
#define int long long
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define vi vector<int>
#define mii map<int,int>
#define pii pair<int,int>
#define len(x) (x.size())
#define read(x) scanf("%lld",&x)
#define all(a) a.begin(),a.end()
#define write(x) printf("%lld",x)
#define f(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) for(int i=0;i<a;i++)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define T int tc;cin>>tc;for(int t=1;t<=tc;t++)
#define set_arr(arr,i) memset(arr,i,sizeof(arr))
#define trace1(x)							cerr << #x << ": " << x << endl;
#define trace2(x, y)						cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)						cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       			cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    			cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) 			cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
using namespace std;

void solve(){
	int n;
	string s;
	cin>>n>>s;
	if(n&1) {
		cout<<"No";
		return;
	}
	else{
		if(s.substr(0,n/2)==s.substr(n/2))cout<<"Yes";
		else cout<<"No";
	}
}

signed main(){
	ios_base::sync_with_stdio(false);	
	cin.tie(0);
	cout.tie(0);
 	solve();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#define nmax_def 220000
using namespace std;
typedef long long ll;

int main() {
	int i, j;
	pair<int, int> BA[nmax_def];
	int N;
	bool ans = true;
	int timenow = 0;
	cin >> N;
	for (i = 0; i < N; i++)
		cin >> BA[i].second >> BA[i].first;
	sort(BA, BA + N, less<pair<int, int> >());
	i = 0;
	while (1)
	{
		if (i >= N)
			break;
		timenow += BA[i].second;
		if (timenow > BA[i].first)
		{
			ans = false;
			break;
		}
		i++;
	}
	if (ans)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 1920
package main

import (
	"fmt"
	"math"
)

func CircleProb(r float64) {
	fmt.Printf("%8.6f %8.6f\n", r * r * math.Pi, 2 * r * math.Pi)
}

func main(){
	var r float64
			fmt.Scan(&r)
	CircleProb(r)
}


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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

const int INF = 4444444;
char A[2005], B[2005];
int n;
int goleft[2005], goright[2005];

int z(int i){
	return (i % n + n) % n;
}

pair<int, int> needy[2005];
int p;

int gogogo(int displace){
	int rightmost = -1, ret = INF;
	
	for(int i = p; i >= 1; i--){
		int cost = p + needy[i].first;
		int cp = z(displace - needy[i].first);
		if(rightmost >= 0){
			cost += needy[i].first + rightmost;
			cp = z(displace + rightmost);
		}
		ret = min(ret, cost + min(cp, n - cp));
		rightmost = max(rightmost, needy[i].second);
	}
	
	return ret;
}

int eval(int displace){
	p = 0;
	for(int i = 0; i < n; i++){
		int ind = z(i + displace);
		if(A[ind] != B[i]){
			needy[++p] = {ind - goleft[ind], goright[ind] - ind};
		}
	}
	
//	printf("displace = %d\n", displace);
//	for(int i = 1; i <= p; i++){
//		printf("  [%d,%d]\n", needy[i].first, needy[i].second);
//	}
	if(p == 0){
		return min(displace, n - displace);
	}
	
	int ret = INF;
	
	// go left then right
	sort(needy + 1, needy + p + 1);
	int ret1 = gogogo(displace);
	
	// go right then left
	for(int i = 1; i <= p; i++){
		swap(needy[i].first, needy[i].second);
	}
	sort(needy + 1, needy + p + 1);
	int ret2 = gogogo(-displace);
	
	return min(ret1, ret2);
}

int main(){
	scanf("%s %s", A, B);
	n = strlen(A);
	bool allzero = true;
	for(int i = 0; i < n; i++){
		if(B[i] == '1'){
			allzero = false;
			break;
		}
	}
	
	if(allzero){
		for(int i = 0; i < n; i++){
			if(A[i] == '1'){
				printf("-1\n");
				return 0;
			}
		}
		printf("0\n");
		return 0;
	}
	
	for(int i = 0; i < n; i++){
		goleft[i] = i;
		while(B[z(goleft[i])] == '0'){
			goleft[i]--;
		}
		goright[i] = i;
		while(B[z(goright[i])] == '0'){
			goright[i]++;
		}
	}
	
	int ans = INF;
	
	for(int i = 0; i < n; i++){
		ans = min(ans, eval(i));
	}
	
	printf("%d\n", ans);
	return 0;
}

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

int n, m, q;
vector<int> a,b,c,d;
int ans;

void dfs(vector<int> A){
	if(A.size() == n+1){
		int now = 0;
		rep(i, q){
			if(A.at(b.at(i)) - A.at(a.at(i)) == c.at(i)) now += d.at(i);
		}
		ans = max(ans, now);
		return;
	}

	A.push_back(A.back());

	while(A.back() <= m){
		dfs(A);
		A.back()++;
	}
}

int main(){
	cin >> n >> m >> q;
	a = b = c = d = vector<int>(q);
	rep(i, q) cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);

	dfs(vector<int>(1,1));
	
	cout << ans << endl;
	return 0;
}

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

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

        for(int i=1;i<=n;i++){
            if(sum(i)>=a && sum(i)<=b){
                ans=ans+i;
            }
        }
        System.out.println(ans);
    }

    private static int sum(int i) {
        int ans=0;
        while(i!=0){
            int t=i%10;
            ans=ans+t;
            i=i/10;
        }
        return ans;
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
const int inf = 1e18 + 7;
const int N = 1e6 + 7;
const int md = 1e9 + 7;
void sol() {
  int a, n;
  int prod = 1;
  int ok = 1, f = 0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a;
    if(a == 0) {
      f = 1;
    }
    if(!f) {
      int v = (int)1e18 / prod;
      
      if(a > v) {
        ok = 0;
      }
      if(ok)
        prod *= a;
    }
  }
  if(f) {
    cout << 0 << '\n';
  }
  else if(ok) {
    cout << prod << "\n";
  }
  else cout << -1 << '\n';
}

int32_t main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  //cin >> T; 
  for(int t = 1; t <= T; t++) {
    //cout << "Case #" << t << ": ";
    sol();
  }
  return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>
#include<math.h>
#include<float.h>

int main(void){
  int k,n;
  double xa,ya,ra,xb,yb,rb;
  double d[4];
  scanf("%d",&n);
  int ans[n];

  for(k=1;k<=n;k++){
    scanf("%lf %lf %lf %lf %lf %lf",&xa,&ya,&ra,&xb,&yb,&rb);
    d[0] = sqrt(pow(xb-xa,2.0) + pow(yb-ya,2.0));
    d[1] = ra + rb;
    d[2] = ra - rb; //B???A???????????????
    d[3] = rb - ra; //A???B???????????????

    if(d[0] > d[1]){
      printf("0\n");
    }else if(d[2]>d[0]){
      printf("2\n");
    }else if(d[3]>d[0]){
      printf("-2\n");
    }else{
      printf("1\n");
    }
  }
  return 0;
}

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

using namespace std;


#define MOD 1000000007
#define ll long long int
#define ff first
#define ss second
#define N 1000001


template <typename T,typename G>
ostream& operator << (ostream& out, const pair<T,G> &a) 
{return out<<"( "<<a.ff<<", "<<a.ss<<")";}

template <typename T>
ostream& operator << (ostream& out, const vector<T> &a) 
{out<<"[ ";for(const auto &i:a)out<<i<<", ";return out<<"]"<<endl;}

template <typename T>
ostream& operator << (ostream& out, const set<T> &a) 
{out<<"{ ";for(const auto &i:a)out<<i<<", ";return out<<"}"<<endl;}

template <typename T,typename G>
ostream& operator << (ostream& out, const map<T,G> &a) 
{out<<"< ";for(const auto &i:a)out<<i<<", ";return out<<">"<<endl;}
    

void solve()
{
	ll n,w;
	cin>>n>>w;
	ll wgh[n+1],val[n+1];
	memset(wgh,0,sizeof wgh);
	memset(val,0,sizeof val);
	ll tot=0;
	for(ll i=1;i<=n;i++)
	{
		cin>>wgh[i]>>val[i];
		tot+=val[i];
	}

	ll dp[n+1][tot+1];
	memset(dp,0,sizeof dp);

	for(ll i=1;i<=tot;i++)
		dp[0][i]=INT_MAX;
	for(int i=0;i<=n;i++)
		dp[i][0]=0;

	for(ll i=1;i<=n;i++)
	{
		for(ll j=1;j<=tot;j++)
		{
			if(val[i]>j)
				dp[i][j]=dp[i-1][j];
			else
				dp[i][j]=min(dp[i-1][j],dp[i-1][j-val[i]]+wgh[i]);
		}
	}
	ll ans=0;
	for(ll j=0;j<=tot;j++)
		if(dp[n][j]<=w)
			ans=max(ans,j);

	cout<<ans<<"\n";
}	


int32_t main()
{
	
 
    //your code goes here...
    int t=1;
   // cin>>t;
    while(t--)
    {
        solve();
    }    
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
#define all(v) v.begin(),v.end()
typedef vector<int> vi;
typedef vector<ll> vl;
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;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}

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


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
# int(input()) # 入力が1つ
a, b = map(int, input().split()) # 入力が複数

n = 1
t = 0
for i in range(2, 1000):
    if (n - i) - a == n - b:
        t = n
        break
    n += i
ans = t - a
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric> 
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, d; 
	while(cin >> n >> d, n | d)
	{
		int num[110], capa[110][10010];
		int sum = 0;
		for(int i = 0; i < n; i++)
		{
			cin >> num[i];
			sum += num[i];
			for(int j = 0; j < num[i]; j++)
			{
				cin >> capa[i][j];
				//累積をとる
				if(j > 0) capa[i][j] += capa[i][j - 1];
			}
		}
		bool ok = true;
		for(int i = 0; i < sum; i++)
		{
			bool dispose = false;
			for(int j = 0; j < n; j++)
			{
				if(num[j] == 0) continue;
				num[j]--;
				int min_num = INF, max_num = -INF;
				//最大値と最小値の差を求める
				for(int k = 0; k < n; k++)
				{
					min_num = min(capa[k][num[k] - 1], min_num);
					max_num = max(capa[k][num[k] - 1], max_num);
				}
				if(max_num - min_num <= d)
				{
					dispose = true;
					break;
				}
				//条件を満たさないのであれば元に戻す
				num[j]++;
			}
			//一つもなければ
			if(dispose == false)
			{
				ok = false;
				break;
			}
		}
		cout << (ok ? "Yes" : "No") << endl;
	}
	return 0;
}


Measured memory_bytes: 3528
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

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

int main(){
	string str = "__23456789TJQKA";
	map<char, int> m;
	rep(i, str.size()) m[str[i]] = i;

	char tr;
	while (cin >> tr, tr != '#'){
		vector<char> suite[4];
		vector<int> num[4];

		rep(i, 4) rep(j, 13){
			string s;
			cin >> s;
			num[i].push_back(m[s[0]]);
			suite[i].push_back(s[1]);
		}

		int cnt[2] = {};
		int led = 0;
		rep(i, 13){
			char leds = suite[led][i];
			P tbest = MP(-1, -1);
			P lbest = MP(-1, -1);
			rep(j, 4){
				if (suite[j][i] == tr){
					tbest = max(tbest, MP(num[j][i], j));
				}
				else if (suite[j][i] == leds){
					lbest = max(lbest, MP(num[j][i], j));
				}
			}
			int won = -1;
			if (tbest.first >= 0){
				won = tbest.second;
			}
			else{
				won = lbest.second;
			}
			++cnt[won & 1];
			led = won;
		}
		int team = cnt[1] > 6;
		cout << (team ? "EW " : "NS ") << cnt[team] - 6 << endl;
	}

	return 0;
}

Measured memory_bytes: 1216
#include<cstring>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for (int i=(a);i<(b);i++)
#define per(i,a,b) for (int i=(b)-1;i>=a;i--)
#define sz(a) (int) a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
//-----
const double eps = 1e-8;
const int inf = 0x7f7f7f7f;
const int N=1e5+5;
const int mod=1e9+7;
vector<pii> p;
vector<int> e[N];
int main()
{
	
	ll n; cin>>n;
	ll m = 1;
	while(m * (m-1) / 2 < n) m++;
	if(m*(m-1)/2 != n) {
		cout<<"No"<<endl;
		return 0; 
	}
	//printf("Yes\n%d\n",m);
	cout<<"Yes"<<endl<<m<<endl;
	int d = 1;
	rep(i,1,m+1) {
		rep(j,i+1,m+1) {
			e[i].pb(d);
			e[j].pb(d);
			d++;
		}
	}
	rep(i,1,m+1) {
		cout<<m-1;
		rep(j,0,m-1) cout<<' '<<e[i][j];
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

int main() {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    c *= 2;
    ll ans = 1e11;
    for (int i = 0, n = max(x, y); i <= n; i++) {
        ll t = i * c + max(0, x - i) * a + max(0, y - i) * b;
        ans = min(ans, t);
    }
    cout << ans << endl;
}

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

using namespace std;

int main(){
    int N,T;
    vector<int> time;
    cin>>N>>T;
    for(int i = 0; i < N; i++){
        int t;
        cin>>t;
        time.push_back(t);
    }

    int tot = 0;
   
   /*
    9 10
    0 3 5 7 100 110 200 300 311
   */

    int nex = 1;
    if(N==1) tot = T;
    for(int i = 0; i < N-1; i++){
        if(time[i]+T >= time[nex]){
            tot+= time[nex] - time[i];
        }
        else if(time[nex] < time[i]+T){
            tot += T;
        }
        else{
            tot+=T;
        }
        if(i == N - 2) tot+=T;
        nex++;
    }
    cout<<tot<<endl;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp> // Common file
    #include <ext/pb_ds/tree_policy.hpp>
    #include <functional> // for less

    using namespace std;
    #define md 1000000007
    #define itn int
    #define pb push_back
    #define mp make_pair
    // #define ull unsigned long long int
    #define ll long long 
    #define int ll
    #define ppi pair<int, int>
    #define ppl pair<ll, ll>
    #define vi vector<int>
    #define all(x) x.begin(), x.end()
    #define ff first
    #define lb lower_bound
    #define ub upper_bound
    #define ss second
    #define inf 1e9
    #define enld '\n'
    #define cuot cout
    #define trace1(x) cerr << #x << ": " << x << endl
    #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
    #define trace3(x, y, z)                                                        \
      cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": "    \
           << z << endl
    #define trace4(a, b, c, d)                                                     \
      cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
           << c << " | " << #d << ": " << d << endl
    #define trace5(a, b, c, d, e)                                                  \
      cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
           << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
    #define trace6(a, b, c, d, e, f)                                               \
      cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": "   \
           << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | "   \
           << #f << ": " << f << endl
    #define trace(v)                                                               \
      for (auto it = v.begin(); it != v.end(); it++)                               \
        cerr << *it << " ";                                                        \
      cerr << endl;
    #define linf 1e18
    #define reset(x) memset(x, 0, sizeof(x))
    #define rep(i, a, b) for (int i = a; i < b; i++)

    using namespace __gnu_pbds;

    typedef tree<int, null_type, less<int>, rb_tree_tag,
                 tree_order_statistics_node_update>
        oset;

    void fastio() {
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
    }
    int n,M;
    double p[3000];
    double dp[3000][3000];

    double go(int i,int t){
        if(t>M)return 0.0;
        if(i>=n)return 1.0;
        if(dp[i][t]>-1.0)return dp[i][t];
        return dp[i][t]=p[i]*go(i+1,t)+(1-p[i])*go(i+1,t+1);
    }

    void solve()
    {  
        cin>>n;
        rep(i,0,3000)rep(j,0,3000)dp[i][j]=-1.0;
        rep(i,0,n)cin>>p[i];
        M=n/2;
        cout<<fixed<<setprecision(10)<<go(0,0)<<endl;
    }


    signed main() {
      fastio();
      int t;
      t = 1;
      // cin >> t;
      for (int i = 1; i <= t; i++) {
        // cout << "Case #" << i << ": ";
        solve();
      }
      return 0;
    }


Measured memory_bytes: 70912
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header

int main() {
	int n, m;
	cin >> n >> m;
	vector<string> a(n);
	rep(i,n) cin >> a[i];
	vector<string> b(m);
	rep(i,n) cin >> b[i];
	bool ok=true;
	for(int j=0; j+m<n+1; j++){//heigh
		for(int i=0; i+m<n+1; i++){//wide
			rep(k,m){
				if(a[j+k].substr(i,m) == b[k]) ;
				else{
					ok = false;
					break;
				}
			}
			if(ok){
				cout << "Yes" << endl;
				return 0;
			}
			ok = true;
		}
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define sz(x)             (int)((x).size())
#define int               long long
#define M                 1000000007
#define MM                998244353
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount

template<typename T1,typename T2>
std::istream& operator>>(std::istream& in,pair<T1,T2> &a)
{
	in>>a.fr>>a.sc;
	return in;
}
template<typename T1,typename T2>
std::ostream& operator<<(std::ostream& out,pair<T1,T2> &a)
{
	out<<a.fr<<" "<<a.sc;
	return out;
}
#ifdef demoralizer
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
int a[25][25];
int n;
int dp[1<<21];

int calc(int p,int m){
	// if(p==n) return 1;
	int &ans=dp[m];
	if(ans!=-1)return ans;
	ans=0;
	rep(i,0,n){
			// trace(p,m,i,(m&(1<<i) == 0),a[p][i]);
		if(a[p][i] && ((m&(1<<i)) == 0)){
			if(p==n-1){
				ans=1;
				break;
			}
			ans=(ans+calc(p+1,m^(1<<i)))%M;
		}
	}
	return ans;
}
void solve(){
	mem1(dp);
	cin>>n;
	rep(i,0,n){
		rep(j,0,n){
			cin>>a[i][j];
		}
	}
	cout<<calc(0,0);
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SEIVE
		seive();
	#endif
	#ifdef NCR
		init();
	#endif
	#ifdef DSU
		cleardsu(MAXDSUSIZE);
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 16640
n, a, b = map(int, input().split())
p = 10**9 + 7
def comb(n, r, p):
  X, Y = 1, 1
  for i in range(r):
    X *= n-i
    Y *= i+1
    X %= p
    Y %= p
  return int(X * pow(Y, p-2, p))
ans = pow(2, n, p) - comb(n, a, p) - comb(n, b, p) - 1
print(ans % p)

Measured memory_bytes: 38512
#include <bits/stdc++.h>
using namespace std;
long long  n;
long long  a[100000];
long long  dp[100000];
long long  inf = INT_MAX;

long long  recur(long long  i){
    if(i == n-1)  return 0;
    if(dp[i] != -1) return dp[i];
    else {
        if(i + 1 < n) dp[i] = recur(i+1) + abs(a[i] - a[i+1]);
        if(i + 2 < n) dp[i] = min(dp[i], recur(i+2) + abs(a[i] - a[i+2]));
        return dp[i];
    }
}

int main(){
    cin>>n;
    for(long long  i = 0 ; i < n; i++)cin>>a[i];
    memset(dp, -1, sizeof dp);
    cout<<recur(0);
}


Measured memory_bytes: 4992
using System;
using System.Linq;

namespace ITP1_4_C_Simple_Calculator
{
    class Class1
    {
        public static void Main()
        {
            while (true)
            {
                string[] s = Console.ReadLine().Split(' ');
                int a = int.Parse(s[0]);
                int b = int.Parse(s[2]);
                char op = Convert.ToChar(s[1]);

                if (op == '?') break;
                else if (op == '+')
                {
                    Console.WriteLine(a + b);
                }
                else if (op == '-')
                {
                    Console.WriteLine(a - b);
                }
                else if (op == '*')
                {
                    Console.WriteLine(a * b);
                }
                else if (op == '/')
                {
                    Console.WriteLine(a / b);
                }
            }
        }
    }
}



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

vector<int> G[100000];
bool flag = false;
int a = 0, b = 0;
int color[100000];

void dfs(int n, int c) {
	color[n] = c;
	if (c - 1) {
		b++;
	}
	else {
		a++;
	}
	for (auto v : G[n]) {
		if (color[v] == 0) {
			dfs(v, 3 - c);
		}
		else if (color[v] == c) {
			flag = true;
		}
	}
}

int main()
{
	cin.sync_with_stdio(false);
	ll V, E;
	cin >> V >> E;
	for (int i = 0, a, b; i < E; i++) {
		cin >> a >> b;
		G[a - 1].push_back(b - 1);
		G[b - 1].push_back(a - 1);
	}
	ll x = 0;
	vector<ll> d;
	for (int i = 0; i < V; i++) {
		if (color[i] == 0) {
			dfs(i, 1);
		}
		if (a != b) {
			d.push_back(abs(a - b) * 2);
			x += abs(a - b);
		}
		a = b = 0;
	}
	sort(d.begin(), d.end());
	ll ma = 0;
	vector<int> dp(x * 2 + 1); dp[0] = 1;
	for (auto bi : d) {
		for (int i = min(x * 2 - bi, ma); i >= 0; i--) {
			if (dp[i]) {
				dp[i + bi] = 1;
				ma = max(ma, i + bi);
			}
		}
	}
	ll res = 0;
	while (dp[x - res] == 0 && dp[x + res] == 0) res++;
	cout << (flag ? -1ll : (V + res) * (V - res) / 4 - E) << endl;
	return 0;
}

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

int n, q, b;
char str[600000];
int bucket[2000][26];

int get_q(int l, int r){
    int cnt[26], c=0;
    for(int i=0; i<26; ++i) cnt[i] = 0;
    if(l/b == r/b){
        for(int i=l; i<=r; ++i) cnt[str[i]-'a']++;
        for(int i=0; i<26; ++i) c += cnt[i]?1:0;
        return c;
    }
    int lb = (l+b-1)/b;
    int rb = (r<b-1)?-1:((r-b+1)/b);
    //printf("\n\n%d %d\n\n", lb, rb);
    for(int i=lb; i<=rb; ++i){
        for(int j=0; j<26; ++j) cnt[j] += bucket[i][j];
    }
    for(int i=l; i<lb*b && i<=r; ++i) cnt[str[i]-'a']++;
    for(int i=(rb+1)*b; i<=r; ++i) cnt[str[i]-'a']++;
    for(int i=0; i<26; ++i) c += cnt[i]?1:0;
    return c;
}

int main()
{
    int i, j;
    scanf("%d\n%s\n%d", &n, str, &q);
    for(b=1;b*b<n;++b);
    for(int i=0; i<n; ++i){
        ++bucket[i/b][str[i]-'a'];
    }
    for(;q--;){
        int t; scanf("\n%d", &t);
        if(t==1){
            int x; char y;
            scanf(" %d %c", &x, &y); --x;
            --bucket[x/b][str[x]-'a'];
            str[x] = y;
            ++bucket[x/b][str[x]-'a'];
        }
        else{
            int x, y;
            scanf(" %d %d", &x, &y);
            printf("%d\n", get_q(x-1, y-1));
        }
    }
}

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


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

#define INF bit(60)

#define DBGP 1


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

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

li a[] = {300000, 200000, 100000};

int main() {
    li x , y;
    cin >> x >> y;
    x--;
    y--;
    li res = a[x] + a[y];
    if (max(x, y) == 0) {
        res += 400000;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int n;
int A[2000];

int solve(int, int);

int main(){
int i,j,m,q;

scanf("%d",&n);

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

scanf("%d",&q);

for(i = 0; i < q; i++){
    scanf("%d",&m);
if(solve(0,m)==1){
printf("yes\n");
}
else printf("no\n");
  }
return 0;
}

int solve(int i, int m){
int x;
if(m==0){
  return 1;
}
if(i>=n){
  return 0;
}
x=solve(i + 1, m) || solve(i + 1,m - A[i]);
return x;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
#define pi 3.1415926535
vector<vector<int>> v, vis;
int h, w, h1, h2, w1, w2;
int dx[] = {0, -1, 0, 1};
int dy[] = { -1, 0, 1, 0};
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin >> h >> w;
	cin >> h1 >> w1 >> h2 >> w2; map<pair<int, int>, int> mp;
	v.resize(h + 1);
	vis.resize(h + 1);
	for (int i = 0; i <= h; i++)
	{
		vis[i].resize(w + 1, -1);
		v[i].resize(w + 1, 0);
	}
	for (int i = 1; i <= h; i++)
	{
		for (int j = 1; j <= w; j++)
		{
			mp[mk(i, j)] = -1;
			char c;
			cin >> c;
			if (c == '.')
				v[i][j] = 1;
		}
	}
	set<pair<int, pair<int, int>>> s; vis[h1][w1] = 0; mp[mk(h1, w1)] = 0;
	s.insert(mk(0, mk(h1, w1)));
	while (s.size())
	{
		auto it = s.begin();
		int a = it->ff;
		int b = it->ss.ff;
		int c = it->ss.ss;
		s.erase(it);
		for (int i = 0; i < 4; i++)
		{
			if (b + dx[i] >= 1 && b + dx[i] <= h && c + dy[i] >= 1 && c + dy[i] <= w && v[b + dx[i]][c + dy[i]] == 1)
			{
				if (vis[b + dx[i]][c + dy[i]] == -1)
				{
					s.insert(mk(a, mk(b + dx[i], c + dy[i])));
					mp[mk(b + dx[i], c + dy[i])] = a; vis[b + dx[i]][c + dy[i]] = a;
				}
				else if ((mp[mk(b + dx[i], c + dy[i])] > a))
				{
					int x = mp[mk(b + dx[i], c + dy[i])];
					auto it = s.find(mk(x, mk(b + dx[i], c + dy[i])));
					s.erase(it);
					s.insert(mk(a, mk(b + dx[i], c + dy[i])));
					mp[mk(b + dx[i], c + dy[i])] = a;
				}
			}
		}
		for (int i = b - 2; i <= b + 2; i++)
		{
			for (int j = c - 2; j <= c + 2; j++)
			{
				if (i >= 1 && i <= h && j >= 1 && j <= w && v[i][j] == 1)
				{
					if (vis[i][j] == -1)
					{
						s.insert(mk(a + 1, mk(i, j)));
						mp[mk(i, j)] = a + 1; vis[i][j] = a + 1;
					}
					else if ((mp[mk(i, j)] > a + 1))
					{
						int x = mp[mk(i, j)];
						auto it = s.find(mk(x, mk(i, j)));
						s.erase(it);
						s.insert(mk(a + 1, mk(i, j)));
						mp[mk(i, j)] = a + 1;
					}
				}
			}
		}


	}
	/*for (int i = 1; i <= h; i++)
	{
		for (int j = 1; j <= w; j++)
		{
			cout << mp[mk(i, j)] << " ";
		}
		cout << endl;
	}*/
	cout << mp[mk(h2, w2)];
	return 0;
}



Measured memory_bytes: 74260
#include <iostream>
#define MAX 100010

using namespace std;
typedef long long ll;

ll n,k,ans,na,r;

int main()
{
    cin>>n>>k;
    for(ll b=k+1;b<=n;b++){
      r=(n-(b-1))%b;
      na=(n-(b-1))/b+1;
      ans+=(b-1-k+1)*na;
      if(n%b>=k&&r)ans+=n%b-k+1;
      if(k==0)ans--;
      //cout<<ans<<'\n';
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    string s;
    cin>>s;
    ll ans =0;
    for(auto x: s){
        string t(1,x);
        //cout<<stoi(t)<<" ";
        ans+= stoi(t);
    }
   // cout<<endl<<ans<<endl;
    if(ans%9==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No";
    }
}


Measured memory_bytes: 3696
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    int X; cin >> X;

    vi a;
    a.push_back(1);
    for(int b = 2; b*b <= X; b++) {
        int t = b*b;
        while(t <= X) {
            a.push_back(t);
            t *= b;
        }
    }

    sort(a.begin(), a.end(), greater<int>());

    int ans = a[0];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(n)]


def dfs(i, a, b, c):
    if n == i:
        if 1 > a or 1 > b or 1 > c:
            return 10 ** 18
        return abs(A - a) + abs(B - b) + abs(C - c)

    res = dfs(i + 1, a, b, c)
    res = min([res, dfs(i + 1, a + l[i], b, c) + (10 if a != 0 else 0)])
    res = min([res, dfs(i + 1, a, b + l[i], c) + (10 if b != 0 else 0)])
    res = min([res, dfs(i + 1, a, b, c + l[i]) + (10 if c != 0 else 0)])
    return res


print(dfs(0, 0, 0, 0))


Measured memory_bytes: 3064
#include	<stdio.h>

#define		PAI	3.14159265359

int		main(void)
{
	double	r;
	double	s,l;

	scanf("%lf",&r);

	s	=	PAI*r*r;
	l	=	2*PAI*r;

	printf("%f %f\n",s,l);

	return(0);
}	

Measured memory_bytes: 1080
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b,c,ans=1e9,num=0,suma=0,sumb=0,sumc=0;
    cin>>n>>a>>b>>c;
    int l[n];
    for(int i=0;i<n;i++){
        cin>>l[i];
    }
    for(int i=0;i<(1<<(n*2));++i){
        int v;
        int w=i;
        for(int j=0;j<n;j++){
            v=w%4;
            w/=4;
            if(v==0){
                if(suma){
                    num+=10;
                }
                suma+=l[j];
            }
            else if(v==1){
                if(sumb){
                    num+=10;
                }
                sumb+=l[j];         
            }
            else if(v==2){
                if(sumc){
                    num+=10;
                }
                sumc+=l[j];
            }
        }
        num+=(abs(a-suma)+abs(b-sumb)+abs(c-sumc));
        if(suma&&sumb&&sumc){
            ans=min(ans,num);
        }
        num=suma=sumb=sumc=0;
    }
    cout <<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

int main() {
    int x;
    std::cin >> x;
    int k;
    std::cin >> k;
    std::vector<int> rot(k + 1);
    rot[0] = 0;
    for (int i = 1; i <= k; ++i) {
        std::cin >> rot[i];
    }
    std::vector<int> lb, ub;
    lb.push_back(0);
    ub.push_back(x);
    std::vector<std::pair<int, int>> vals;
    vals.push_back({0, x});
    for (int i = 1; i <= k; ++i) {
        int d = rot[i] - rot[i - 1];
        if (i % 2) {
            lb.push_back(lb[i - 1] - std::min(0, vals[i - 1].first - d));
            // ub.push_back(ub[i - 1] - std::max(0, vals[i - 1].second - d));
            ub.push_back(ub[i - 1]);
            ub[i] = std::max(ub[i], lb[i]);
            vals.push_back({std::max(0, vals[i - 1].first - d),
                            std::max(0, vals[i - 1].second - d)});
        } else {
            //lb.push_back(lb[i - 1] + std::min(x, vals[i - 1].first + d));
            lb.push_back(lb[i - 1]);
            ub.push_back(ub[i - 1] + std::min(0, x - (vals[i - 1].second + d)));
            ub[i] = std::max(ub[i], lb[i]);
            vals.push_back({std::min(x, vals[i - 1].first + d),
                            std::min(x, vals[i - 1].second + d)});
        }
    }
    rot.push_back(1000000001);
    lb.push_back(lb[rot.size() - 2]);
    ub.push_back(ub[rot.size() - 2]);
    vals.push_back(vals[rot.size() - 2]);

    int q;
    std::cin >> q;
    for (int i = 0; i < q; ++i) {
        int t, l;
        std::cin >> t >> l;
        int crot = std::lower_bound(rot.begin(), rot.end(), t) - rot.begin();
        if (t != 0)
            --crot;
        int ans;
        ans = std::min(ub[crot] - lb[crot], std::max(0, (l - lb[crot]))) + vals[crot].first;
        if (crot % 2 == 0) {
            ans = std::max(0, ans - (t - rot[crot]));
        } else {
            ans = std::min(x, ans + (t - rot[crot]));
        }
        std::cout << ans << "\n";
    }
}


Measured memory_bytes: 3424
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int a[maxn];
int main()
{
	#ifdef TEST
		freopen("input.txt","r",stdin);
    #endif
	int n,m,T;
	int a,b,c;
	cin>>a>>b>>c;
	int ans=0;
	ans+=b;
	if(c<=b) ans+=c,c=0;
	else ans+=b,c-=b;
	ans+=min(c,a);
	c-=min(c,a);
	if(c>0) ans+=1;
	cout<<ans<<endl;
	
}



Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<cstring>

using namespace std;

const double EPS = 1e-9;

struct Data{int S,A,C;};
vector<int> I;
int N;
void input(){
  I.resize(N+1);
  for(int i = 1; i <= N; i++) cin >> I[i];
}

double calc(int S, int A, int C){
  vector<int> R(N+1),O(N+1);
  R[0] = S;
  for(int i = 1; i <= N; i++) R[i] = (A*R[i-1]+C)%256;
  for(int i = 1; i <= N; i++) O[i] = (I[i]+R[i])%256;

  int app[256];
  memset(app,0,sizeof(app));
  for(int i = 1; i <= N; i++) app[O[i]]++;

  double res = 0;
  for(int i = 0; i < 256; i++)
    if(app[i] > 0) res += (double)app[i]*(log((double)app[i])-log((double)N));
  return -res;
}

void solve(){
  double H = -1;
  Data ans;
  for(int i = 0; i < 16; i++)
    for(int j = 0; j < 16; j++)
      for(int k = 0; k < 16; k++){
	double tmp = calc(i,j,k);
	if(fabs(tmp-H) < EPS) continue;
	if(H == -1 || tmp < H){
	  H = tmp;
	  ans = (Data){i,j,k};
	}
      }

  cout << ans.S << " " << ans.A << " " << ans.C << endl;
}


int main(){
  
  while(cin >> N && N){
    input();
    solve();
  }
  return 0;
}

Measured memory_bytes: 1260
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;



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

    int h,w;
    cin>>h>>w;
    vvi v(h,vi (w));
    rep(i,h)rep(j,w)cin>>v[i][j];
    vvi ans;
    for(int i=0;i<h-1;i++){
        for(int j=0;j<w;j++){
            if(v[i][j]%2==1){
                v[i+1][j]++;
                vi t;
                t.push_back(i+1);
                t.push_back(j+1);
                t.push_back(i+2);
                t.push_back(j+1);
                ans.push_back(t);
            }
        }
    }
    for(int i=0;i<w-1;i++){
        if(v[h-1][i]%2==1){
            v[h-1][i+1]++;
            vi t;
            t.push_back(h);
            t.push_back(i+1);
            t.push_back(h);
            t.push_back(i+2);
            ans.push_back(t);
        }
    }
    cout<<ans.size()<<endl;
    for(int i=0;i<ans.size();i++){
        cout<<ans[i][0]<<" "<<ans[i][1]<<" "<<ans[i][2]<<" "<<ans[i][3]<<endl;
    }

//////////////////////////////////////////////////////
return 0;}

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

namespace AtCoder.Contest.B
{
	class Program
	{
		public static void Main(string[] args)
		{
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);

			Scanner cin = new Scanner();

			int n = cin.nextInt();
			int[] a = cin.ArrayInt(n);
			int[] b = cin.ArrayInt(n);
			int[] c = cin.ArrayInt(n - 1);

			int ans = 0;

			for (int i = 0; i < n; i++)
			{
				ans += b[a[i] - 1];
				if (i != 0 && a[i] == a[i - 1] + 1) ans += c[a[i - 1] - 1];
			}
			Console.WriteLine(ans);
			Console.Out.Flush();
		}
	}

	class Scanner
	{
		string[] s;
		int i;

		char[] cs = new char[] { ' ' };

		public Scanner()
		{
			s = new string[0];
			i = 0;
		}

		public string next()
		{
			if (i < s.Length) return s[i++];
			string st = Console.ReadLine();
			while (st == "") st = Console.ReadLine();
			s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
			if (s.Length == 0) return next();
			i = 0;
			return s[i++];
		}

		public int nextInt()
		{
			return int.Parse(next());
		}

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextInt() + add;
			}
			return Array;
		}

		public long nextLong()
		{
			return long.Parse(next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextLong() + add;
			}
			return Array;
		}

		public double nextDouble()
		{
			return double.Parse(next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++)
			{
				Array[i] = nextDouble() + add;
			}
			return Array;
		}
	}
}

Measured memory_bytes: 27508