akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define FOR(x,a,b) for(int x=a;x<b;x++)
#define REP(x,b) for(int x=0;x<b;x++)
#define FORSIZE(x,A) for(int x=0;x<A.size();x++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define SORT(x) sort(x.begin(),x.end())
#define RSORT(x) sort(x.rbegin(),x.rend())
#define rsort(x,n) sort(x, x+n, greater<int>())
#define REV(x) reverse(x.begin(),x.end())
using namespace std;
typedef long long ll;
inline int toInt(std::string s) {int v; std::istringstream sin(s);sin>>v;return v;}
template<class T> inline std::string toString(T x) {std::ostringstream sout;sout<<x;return sout.str();}

int main( int argc, const char* argv[] )
{
    vector<int> heights(10);
    REP(i, 10) cin >> heights[i];
    RSORT(heights);
    REP(i, 3) cout << heights[i] << endl;
    return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int main() {
    
    int N;
    long long Y;
    cin >> N >> Y;
    
    Y /= 1000;
    
    for ( int i = 0; i <= N; i++ ) {
    for ( int j = 0; j <= N; j++ ) {
        if ( i+j > N ) { continue; }
        if ( ( i*10 + j*5 + N-i-j ) == Y ) { cout << i << " "<< j << " " << N-i-j << endl; return 0; }
    }
    }
    
    cout << "-1 -1 -1" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define gcd(x,y) __gcd(x,y)
#define PI 3.14159265
#define count_ones __builtin_popcountl
const int N=1e5+20,MOD=(int)(1e9)+7;
const int oo = 0x3f3f3f3f;
typedef long long ll;
using namespace std;
void boost(){
	ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
}
/* -------------------------------------- */

/* -------------------------------------- */
int main() {
	boost();
	int a,b,c;cin>>a>>b>>c;
	cout<<((c-a+b) > 0 ? c-a+b : 0);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <sstream>
using namespace std;

set<string> S;
set<string> F;

void init() {
  S.clear();
  F.clear();
}

void insert(string &s) {
  F.insert(s);
  for(int i = 1; i < s.size(); ++i) {
    if(s[i-1] == '/') {
      S.insert(s.substr(0,i));
      //      cout << s.substr(0,i) << endl;
    }
  }
}

bool isValid(const string &s) {
  if(s[(int)s.size()-1] != '/' && F.count(s)) return true;
  if(s[(int)s.size()-1] == '/' && S.count(s)) return true;
  if(s[(int)s.size()-1] != '/' && S.count(s+"/")) return true;
  return false;
}

string cut(string s) {
  string sum = "";
  string tmp = "";
  for(int begin = 0, i = 1; i <= s.size(); ++i) {
    if(i == s.size() || s[i-1] == '/') {
      string t = s.substr(begin,i-begin);
      begin = i;
      if(t == "../" || t == "..") {
	if(sum.size() <= 1) return "";
	int j;
	for(j = (int)sum.size()-2; j >= 0 && sum[j] != '/'; --j);
	sum = sum.substr(0,j+1);
      } else if(t != "./" && t != ".") {
	sum += t;
      }
      if(!isValid(sum)) return "";
    }
  }
  return sum;
}

int main() {
  int n, m;
  while(cin >> n >> m && (n|m)) {
    init();
    for(int i = 0; i < n; ++i) {
      string s;
      cin >> s;
      insert(s);
    }
    for(int i = 0; i < m; ++i) {
      string s, t;
      cin >> s >> t;
      s = cut(s);
      t = cut(t);
      if(s == "" || t == "") {
	cout << "not found" << endl;
      } else {
	vector<string> v[2];
	if(s[(int)s.size()-1] != '/') {
	  v[0].push_back(s);
	  s += '/';
	}
	v[0].push_back(s+"index.html");
	if(t[(int)t.size()-1] != '/') {
	  v[1].push_back(t);
	  t += '/';
	}
	v[1].push_back(t+"index.html");
	bool flag = false;
	int p = 0;
	for(int i = 0; i < v[0].size() && !flag; ++i) {
	  for(int j = 0; j < v[1].size() && !flag; ++j) {
	    if(F.count(v[0][i])) p |= 1;
	    if(F.count(v[1][j])) p |= 2;
	    if(F.count(v[0][i]) && F.count(v[1][j]) && v[0][i] == v[1][j]){ 
	      flag = true;
	    }
	  }
	}
	if(p != 3) cout << "not found" << endl;
	else if(flag) cout << "yes" << endl;
	else cout << "no" << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<iostream>
using namespace std;
const int maxn=900;
#define ULL unsigned long long
ULL maxSize = 4000007;
ULL seedx = 233;
ULL seedy = 23333;
struct HashString {
	ULL xp[maxn];
	ULL yp[maxn];
	ULL H[maxn][maxn];
	char s[maxn][maxn];
	int x,y;
	void init(int n, int m) {
		xp[0] = yp[0] = 1;
		x = n,y = m;
		for(int i = 1; i <= x; i++) xp[i] = xp[i - 1]*seedx;
		for(int i = 1; i <= y; i++) yp[i] = yp[i - 1]*seedy;
		return;
	}
	void initHash() {
		for(int i = 0; i < x; i++) {
			H[i][0] = s[i][0] - 'A' + 1;
			for(int j = 1; j < y; j++)
				H[i][j] = H[i][j - 1]*seedy + s[i][j] - 'A' + 1;
		}
		for(int i = 1; i < x; i++)
			for(int j = 0; j < y; j++)
				H[i][j] += H[i - 1][j]*seedx;
		return;
	}
	ULL askHash(int x1, int y1, int x2, int y2) {
		ULL ret = H[x2][y2];
		if(x1 > 0) ret -= H[x1 - 1][y2]*xp[x2 - x1 + 1];
		if(y1 > 0) ret -= H[x2][y1 - 1]*yp[y2 - y1 + 1];
		if(x1 > 0 && y1 > 0) ret += H[x1 - 1][y1 - 1]*xp[x2 - x1 + 1]*yp[y2 - y1 + 1];
		return ret;
	}
} s1,s2;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin>>n;
	s1.init(2*n,2*n);
	s2.init(2*n,2*n);
	for(int i=0; i<n; i++)cin>>s1.s[i];
	for(int i=n; i<2*n; i++) {
		for(int j=0; j<n; j++) {
			s1.s[j][i]=s1.s[j][i-n];
		}
	}
	for(int i=n; i<2*n; i++) {
		for(int j=0; j<2*n; j++) {
			s1.s[i][j]=s1.s[i-n][j];
		}
	}
	for(int i=0; i<2*n; i++) {
		for(int j=0; j<2*n; j++) {
			s2.s[i][j]=s1.s[j][i];
		}
	}
	s1.initHash();
	s2.initHash();
	int ans = 0;
	for(int i = 0; i<n; i++) {
		for(int j = 0; j<n; j++) {
			if(s1.askHash(i,j,i+n-1,j+n-1) == s2.askHash(j,i,j+n-1,i+n-1))
				ans ++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 13056
import sys
input = sys.stdin.readline
import numpy as np

N,MOD = map(int,input().split())

"""
余事象を調べる。包除の原理を使う。
A[n] = （1,2,...,n）が1杯以下、他は何でも良い
B[n,l] : (1,2,...,n) をlグループに分ける方法の個数
A[n]
・0杯のグループあり
・なし
"""

B = np.zeros((N+1,N+1), dtype=np.int64)
B[0,0] = 1
for n in range(1,N+1):
    # 1番を単独で使う
    B[n,1:] = B[n-1,:-1]
    # 1番をどこかに混ぜてもらう
    B[n,1:] += B[n-1,1:] * np.arange(1,N+1) % MOD
    B[n] %= MOD

# 2^{kl}
pow_2 = np.ones((N+1,N+1), dtype=np.int64)
for n in range(1,N+1):
    pow_2[1,n] = 2 * pow_2[1,n-1] % MOD
for n in range(2,N+1):
    pow_2[n] = pow_2[n-1] * pow_2[1] % MOD

pow_pow = np.zeros(N+1, dtype = np.int64)
pow_pow[0] = 2
for n in range(1,N+1):
    pow_pow[n] = pow_pow[n-1] ** 2 % MOD

A = (B[:,1:] * (pow_2[::-1,1:] + pow_2[::-1,:-1] * np.arange(1,N+1) % MOD) % MOD).sum(axis = 1)
A %= MOD
A *= pow_pow[::-1]
A %= MOD

fact = [1] * (N+1)
fact_inv = [1] * (N+1)
for n in range(1,N+1):
    fact[n] = fact[n-1] * n % MOD
fact_inv[N] = pow(fact[N],MOD-2,MOD)
for n in range(N,0,-1):
    fact_inv[n-1] = fact_inv[n] * n % MOD
fact = np.array(fact, dtype = np.int64)
fact_inv = np.array(fact_inv, dtype = np.int64)

comb = fact_inv * fact_inv[::-1] % MOD * fact[N] % MOD

A[::2] *= (-1)
A *= comb
A %= MOD
answer = pow(2,pow(2,N,MOD-1),MOD) - A.sum()
answer %= MOD
print(answer)

Measured memory_bytes: 293928
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int K = sc.nextInt();
        int T = sc.nextInt();
        int[] a = new int[T];
        for (int i=0; i<T; i++) {
            a[i] = sc.nextInt();
        }

        System.out.println(solve(K, T, a));
    }

    private static int solve(int K, int T, int[] a) {
        int max = 0;
        for (int i=0; i<T; i++) {
            max = Math.max(max, a[i]);
        }
        if (max <= K/2) return 0;


        return 2*max - K - 1;
    }
}

Measured memory_bytes: 21844
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int h = sc.nextInt();
		int w = sc.nextInt();
		int ch = sc.nextInt()-1;
		int cw = sc.nextInt()-1;
		int dh = sc.nextInt()-1;
		int dw = sc.nextInt()-1;
		char[][] grid = new char[h][w];
		for(int i = 0; i < h; i++){
			grid[i] = sc.next().toCharArray();
		}
		/*
		for(int i = 0; i < h; i++){
			for(int j = 0; j < w; j++){
				System.out.print(grid[i][j]);
			}
			System.out.println();
		}
		*/
		
		// 計算
		long result = 0;
		int INF = 1001001001;
		int[] dist = new int[h*w];
		Arrays.fill(dist, INF);
		dist[ch*w+cw] = 0;
		ArrayDeque<Integer> q = new ArrayDeque<Integer>();
		q.addFirst(ch*w+cw);
		int[] dx = {-1, 0, 1, -1, 1, -1, 0, 1, -2, -2, -2, -2, -2, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2}; 
		int[] dy = {-1, -1, -1, 0, 0, 1, 1, 1, -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, -2, -1, 0, 1, 2, -2, -1, 0, 1, 2};
		while(!q.isEmpty()){
		    int index = q.pollFirst();
		    int now = dist[index];
    		int i = index/w;
    		int j = index%w;
    		for(int k = 0; k < dx.length; k++){
    		    int ni = i + dx[k];
    		    int nj = j + dy[k];
    		    int c = 1;
    		    if(abs(dx[k]) + abs(dy[k]) == 1) c = 0;
    		    if(0 <= ni && ni < h && 0 <= nj && nj < w){
    		        if(grid[ni][nj] == '.'){
    		            if(now + c < dist[ni*w+nj]){
    		                dist[ni*w+nj] = now + c;
    		                if(c == 0){
    		                    q.addFirst(ni*w+nj);
    		                }else{
    		                    q.addLast(ni*w+nj);
    		                }
    		            }
    		        }
    			}
    		}
		}
		
		if(dist[dh*w+dw] == INF){
		    result = -1;
		}else{
		    result = dist[dh*w+dw];
		}
		//System.out.println(Arrays.toString(dist));
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}


Measured memory_bytes: 50964
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())
 
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
 
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
 
INF = float('inf')
 
def solve():
    S = list(map(int, list(input())))
 
    S = S[::-1]
    # print(S)
    n = len(S)
    mod = 2019
 
    #
    A = [0] * (n)
    a = 1
    for i in range(n):
        A[i] = S[i] * a
        a = a * 10 % mod
    # print(A)
 
    # 累積和
    R = [0] * (n+1)
    for j in range(n):
        R[j+1] = (R[j] + A[j]) % mod
    # print(R)
 
    # 個数を数える
    cnt = {}
    ans = 0
    for l in range(0, n+1):
        r = R[l]
        ans = ans + cnt.get(r, 0)
        cnt[r] = cnt.setdefault(r, 0) + 1
    print(ans)
 
if __name__ == '__main__':
    solve()

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

int main() {
    ll m, n;
    cin >> n >> m;
    ll a[n][3];
    rep(i, n) {
        rep(j, 3) {
            cin >> a[i][j];
        }
    }

    ll maxn = -(1LL << 60);

    rep(i, 8) {
        vector<ll> vec;
        ll sgn[3];
        rep(k, 3) {
            if (((1 << k) & i) == 0) {
                sgn[k] = 1;
            } else {
                sgn[k] = -1;
            }
        }
        rep(j, n) {
            ll s = 0;
            rep(k, 3) {
                s += sgn[k] * a[j][k];
            }
            vec.push_back(s);
        }
        sort(vec.begin(), vec.end());
        reverse(vec.begin(), vec.end());

        ll ans = 0;
        rep(j, m) {
            ans += vec[j];
        }
        maxn = max(maxn, ans);
    }

    cout << maxn << endl;

    return 0;
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-


N = int(input())

tmp = 0
for i in range(1,13):
  
  tmp += 26**i
  if ( N <= tmp ):
    fct = i
    break


pre_N = N
ans_num = []

for i in range(fct):
  div = 26 ** ( fct - (i+1) )
  Q = pre_N // div
  R = pre_N %  div
  pre_N = R
  ans_num.append(Q)
  
  #print(i+1,Q,R)


#print(ans_num)
for i in range(0,fct-1):
  if ( ans_num[i]==27 ):
    ans_num[i] += -1
    ans_num[i+1] += 26

for i in range(0,fct-1):
  if ( ans_num[fct-(i+1)] <= 0 ):
    ans_num[fct-(i+1)-1] += -1
    ans_num[fct-(i+1)] += 26
#print(ans_num)

ans = []
for i in range(fct):
  chara = chr(ans_num[i]+96)
  ans.extend( chara )

print(''.join(ans))

Measured memory_bytes: 9108
while True:
    try:
        a, b = list(map(int, input().split()))
    except:
        break
    done = {}
    i = 0
    flag = -1
    while a != 0:
        a *= 10
        if a in done:
            flag = done[a]
            break
        else:
            done[a] = i
        print(str(a//b), end = "")
        a = a % b
        if a == 0:
            break
        i += 1
    print()
    if flag > -1:
        print(" " * flag + "^" * (i-flag))

Measured memory_bytes: 7644
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

int main(){
  int N, M;
  cin >> N >> M;

  if(N>M){
    swap(N, M);
  }

  if (N==1 && M==1){
    cout << 1 << endl;
  }
  else if (N==1 && M!=1){
    cout << M-2 << endl;
  }
  else {
    cout << (long long)(N-2)*(M-2) << endl;
  }

  return 0;
}


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

long long n, m, d;

int main() {
	cin >> n >> m >> d;
	long long V = (n - d) * 2; if (d == 0) V /= 2;
	long double E = 1.0L*V / (1.0L*n*n);
	printf("%.12Lf\n", 1.0L*(m - 1)*E);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#include <iostream>
 
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define FOR(i, a, b) for(int i = a;i < b;++i)
#define ALL(x) (x).begin(),(x).end()
#define INF 999999999
using namespace std;
#define lint long long
 
int main()
{
 char S[7];
  cin >> S;
  if(S[2] == S[3]){
   if(S[4] == S[5]){
     cout << "Yes";
   }else{
    cout << "No";
   }
  }else{
    cout << "No";
  }
  return 0;
}

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

using namespace std;


int main(){
    int N,H,buf;
    int i;
    vector<int> A;

    cin>>H>>N;
    for(i=0;i<N;i++){
        cin>>buf;
        A.push_back(buf);
    }
    for(i=0;i<N;i++){
        H-=A[i];
    }
    if(H<=0){
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 892
import java.util.*;
import java.lang.*;
import java.io.*;
 
public class Main{
  public static void main (String[] args){
 
	int A,B,C;
//	int[] MAX = new int[3];
//	int max = 0;
 
	Scanner sc = new Scanner (System.in);
		A=sc.nextInt();

/* 
	for(int i = 0; i < MAX.length; i++)
		max = Math.max(max,MAX[i]);
 
		System.out.println(ax);
 
	}
*/
	if(A%10==1){
	  A=A+8;
	}else{
	  A=A-8;
	}
	if((A%100)/10==1){
	  A+=80;
	}else{
	  A-=80;
	}
	if(A/100==1){
	  A+=800;
	}else{
	  A-=800;
	}
  
        System.out.println(A);

  }
}

Measured memory_bytes: 23764
fun main(args: Array<String>) {
    readLine()!!
    val y = readLine()!!.split(" ").map { it.toInt() }

    print(abc136c(y))
}

fun abc136c(y: List<Int>): String {

    var ans = "Yes"
    var max = y[0]

    for (i in 0 until y.size - 1) {
        if (((y[i] - y[i + 1]) > 1) || (((y[i] - y[i + 1]) == 1) && max > y[i + 1])) {
            ans = "No"
            break
        } else if ((y[i] - y[i + 1]) == 1) {
            max = y[i] - 1
        }
    }
    return ans
}


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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;

void solve(){
    string s;
    cin>>s;
    int ans=1;
    rep(i,1,sz(s)){
        if(s[i]==s[i-1]){
            if(i+1<sz(s)){
                ans++,i++;
                s[i]='#';
            }
        }
        else ans++;
    }
    cout<<ans<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 720
t = list(input())
t.reverse()

tmptmp = "P"
for i in range(len(t)):
    if i == 0:
        tmp = t[i]
        continue
    if tmp == "?" and tmptmp != "D":
        t[i-1] = "D"
    elif tmp == "?" and tmptmp == "D" and t[i] != "D":
        t[i-1] = "D"
    elif tmp == "?" and tmptmp == "D" and t[i] == "D":
        t[i-1] = "P"
    tmptmp = t[i-1]
    tmp = t[i]

t.reverse()

if len(t) > 1:
    if t[0] == "?" and t[1] == "D":
        t[0] = "P"
    elif t[0] == "?" and t[1] == "P":
        t[0] = "D"

if len(t) == 1:
    t[0] = "D"

t = "".join(t)
print(t)


Measured memory_bytes: 10708
/*
 * 2546.cc: Chocolate
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_M = 100;
const int MAX_N = 100;

/* typedef */

/* global variables */

int as[MAX_M][MAX_N] = {};

/* subroutines */

/* main */

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

  for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++) cin >> as[i][j];

  int sum = 0;
  for (int j = 0; j < n; j++) as[0][j] ^= 1;

  for (int i = 0; i < m; i++) {
    as[i][0] ^= 1;
    as[i][n - 1] ^= 1;

    int maxc = 0, c = 0;
    for (int j = 0; j < n; j++) c += as[i][j];

    for (int k = 0; k < n; k++) {
      int ck = c + (as[i][k] ? -1 : 1);
      if (maxc < ck) maxc = ck;
      //printf("i=%d, k=%d: c=%d\n", i, k, c);
    }
    sum += maxc;
  }

  printf("%d\n", sum);
  return 0;
}

Measured memory_bytes: 1184
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
using namespace std ; 
int main(){
	ios_base::sync_with_stdio(0) ; 
	cin.tie(0) ; 
	ll n , a , b  , m = 0 ; 
	cin>> n >> a >> b ; 
	ll x = a + b ; 
	ll c = n / x ; 
	if(n%x >= a){
		c++ ; 
	}
	else 
	m = n%x ; 
	
	cout<<c*a + m <<endl;
	
	
	
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,p;
long long ans;

int main(){
	scanf("%lld",&n);
	long long k=sqrt(n);
	for(long long i=1;i<=k;i++){
		if(n%i==0){
			p=n/i-1;
			if(p>i) ans+=n/i-1; 
		}
	}
	printf("%lld\n",ans);
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <atcoder/dsu>

int main()
{
	int N, Q;
	scanf("%d%d", &N, &Q);
	atcoder::dsu d(N);
	for (int i = 0; i < Q; ++i) {
		int t, u, v;
		scanf("%d%d%d", &t, &u, &v);
		if (t == 0) {
			d.merge(u, v);
		} else {
			printf("%d\n", d.same(u, v));
		}
	}
	return 0;
}


Measured memory_bytes: 3612
a,b,k = gets.chomp.split.map(&:to_i)
ai = gets.chomp.split.map(&:to_i)
bi = gets.chomp.split.map(&:to_i)
aiSum,biSum = [0],[0]
for i in 0..ai.count - 1 do
  if ai[i] + aiSum[i] > k
    break
  end
  aiSum[i + 1] = ai[i] + aiSum[i]
end
for j in 0..bi.count - 1 do
  if bi[j] + biSum[j] > k
    break
  end
  biSum[j + 1] = bi[j] + biSum[j]
end

num = 0
best = biSum.count - 1
for i in 0..aiSum.count - 1 do
  while biSum[best] > k - aiSum[i]
    best -= 1
  end
  if num < i + best
    num = i + best
  end
end
puts num


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    rep(i, q)
    {
        ll x;
        cin >> x;

        ll ans = 0;
        ll su = 0;
        int right = 0;
        for (int left = 0; left < n; left++)
        {
            while (right < n && su + a[right] <= x)
            {
                su += a[right];
                right++;
            }
            ans += right - left;
            if (right == left)
            {
                right++;
            }
            else
            {
                su -= a[left];
            }
        }
        cout << ans << endl;
    }

    return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rrepn(i, n) for (int i = ((int)(n)); i > 0; --i)
#define SZ(x) ((int)(x).size())
template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
vector<pair<string, P>> vec;
// vector<vector<int>> data(3, vector<int>(4));

std::pair<std::vector<ll>, std::vector<ll>> prime_factor_decomp(ll n) {
    std::vector<ll> p, e;
    ll m = n;
    for (ll i = 2; i * i <= n; i++) {
        if (m % i != 0) continue;
        int c = 0;
        while (m % i == 0) c++, m /= i;
        p.push_back(i);
        e.push_back(c);
    }
    if (m > 1) {
        p.push_back(m);
        e.push_back(1);
    }
    return std::make_pair(p, e);
}

void solve(long long N) {
    if (N == 1) {
        cout << "0" << endl;
        return;
    }
    vector<ll> d = prime_factor_decomp(N).second;
    ll res = 0;
    rep(i, (ll)d.size()) {
        ll t = 1;
        while (true) {
            if (d[i] >= t) {
                d[i] -= t;
                res++;
                t++;
            } else {
                break;
            }
        }
    }
    cout << res << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3700
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iterator>  // std::back_inserter
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define alf(i) for (char i = 'a';i < 'z'; ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll n; cin >> n;
  vll a(n), b(n);
  map<ll, ll> flag;
  ll ans = 0;
  rep(i, n)
  {
    ll A;
    cin >> A;
    a[i] = A + 1 + i;
    b[i] = i + 1 - A;
    if(flag.count(b[i])) flag[b[i]]++;
    else flag[b[i]] = 1;
  }
  reverse(all(a));
  rep(i, n)
  {
    if(flag.count(a[i])) ans += flag[a[i]];
  }
  fin(ans);
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}


Measured memory_bytes: 18256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  int L[20]={0};
  int ma=0;
  int sum=0;
  for(int i=1;i<=N;i++){
    cin >> L[i];
    sum+=L[i];
    ma=max(L[i],ma);
  }
  if(sum-ma>ma){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int a, b[101];
	int taste=0;
	scanf("%d", &a);
	for (int t = 0; t < a; ++t) {
		scanf("%d", &b[t]);
	}
	for (int i = 0; i < a; ++i) {
		for (int k = 0; k < i; ++k) {
			taste += b[i] * b[k];
		}
	}
	printf("%d", taste);
}


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

#define mod 1000000007

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

using namespace std;
typedef long long ll;
const long long INF = 1LL << 60;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

 
int main(void){
	
	int N;
	
	cin >> N;
	
	ll dp[100010];

	rep(i, 100010)
		dp[i] = 10000000000;
		
	ll h[N];
	
	rep(i, N)
		cin >> h[i];

	dp[0] = 0;

	rep(i, N) {
		chmin(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
		chmin(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
	}

	cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
/// >>In The Name Of God
/// >>ALIREZANA

#include <bits/stdc++.h>
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define sz(x) (int)(x).size()
#define smin(x,y) (x) = min(x,y)
#define smax(x,y) (x) = max(x,y)
#define all(x) (x).begin(),(x).end()
#define _ ios_base::sync_with_stdio(0)\
                ,cin.tie(0),cout.tie(0);

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int maxn = 2*1000+10;
const ll  mod = 1e9+7;
ll dp[maxn][maxn], ans[maxn][maxn];
ll a[maxn], b[maxn];

int main()
{_
    int n, m;   cin >> n >> m;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i <= m; i++)
        cin >> b[i];

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m;j ++){
            if(a[i] == b[j])
                dp[i][j] = 1+ans[i-1][j-1]+dp[i][j-1], ans[i][j] = dp[i][j] + ans[i-1][j];
            else
                dp[i][j] = dp[i][j-1], ans[i][j] = dp[i][j] + ans[i-1][j];
            dp[i][j] %= mod;
            ans[i][j] %= mod;
        }

    }
    cout << (dp[n][m]+ans[n-1][m]+1)%mod;
    return 0;
}


Measured memory_bytes: 63232
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

double dp[901][501][303];

signed main()
{
	IO_OP;
	
	int n, sum = 0;
	cin >> n;
	int cnt[3] = {};
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		sum += x;
		cnt[x - 1]++;
	}
	for(int k = 0; k * 3 <= sum; k++)
		for(int j = 0; k * 3 + j * 2 <= sum; j++)
			for(int i = 0; i + k * 3 + j * 2 <= sum; i++) {
				if(i == 0 && j == 0 && k == 0) {
					dp[i][j][k] = 0;
				} else {
					int left = n - i - j - k;
					double c = 1 - (double) left / n;
					dp[i][j][k] = (1 + (i ? dp[i - 1][j][k] : 0.) * i / n +
								   (j ? dp[i + 1][j - 1][k] : 0.) * j / n +
								   (k ? dp[i][j + 1][k - 1] : 0.) * k / n) / c;
				}
			}

	
	cout << fixed << setprecision(10) << dp[cnt[0]][cnt[1]][cnt[2]] << endl;


}



Measured memory_bytes: 486624
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <queue>
#include <stack>
#define rep(i, a, n) for(int (i) = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int (i) = (int)(a);(i) <= (int)(n);++(i))
#define repr(i, a, n) for(int (i) = (int)(a);(i) > (int)(n);--(i))
#define reper(i, a, n) for(int (i) = (int)(a);(i) >= (int)(n);--(i))
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, n) &((x)[0]), &((x)[n])
#define SUBIF(a, b, x) ((x) ? (b) : (a))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define pb push_back
#define EPS (1e-20)
#define INF 2147483647
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using namespace std;


int N, K;
MII cnt;
multimap<int, int> cntInv;


int solve(){
	int ans = 0;
	for(PII p : cnt) cntInv.emplace(p.second, p.first);
	for(auto p : cntInv){
		if(SIZE(cnt) <= K) break;
		cnt.erase(p.second);
		ans += p.first;
	}
	return ans;
}


signed main(){
	cin >> N >> K;
	rep(i, 0, N){
		int A;
		cin >> A;
		cnt[A]++;
	}

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 18944
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll minn(ll x, ll y){
    if(x<y)
        return x;
    return y;
}
ll maxx(ll x, ll y){
    if(x>y)
        return x;
    return y;
}
ll n, a[100009],b[100009],c[100009],i;
int main() {
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a[i]>>b[i]>>c[i];
    }
    for(i=1;i<n;i++){
        a[i] += maxx(b[i-1],c[i-1]);
        b[i] += maxx(a[i-1],c[i-1]);
        c[i] += maxx(a[i-1],b[i-1]);
    }
    cout<<maxx(a[n-1],maxx(b[n-1], c[n-1]));
    return 0;
}


Measured memory_bytes: 2560
#include <algorithm>
#include <array>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

ll choose(vector<int> &ch_pos, int i, int j) {
  auto it = upper_bound(ch_pos.begin(), ch_pos.end(), j);
  ll ans = distance(it, ch_pos.end());
  bool found = binary_search(it, ch_pos.end(), 2 * j - i);
  if (found) {
    ans = max(0ll, ans - 1);
  }

  return ans;
}

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

  array<vector<int>, 256> ch_pos;
  for (int i = 0; i < n; i++) {
    ch_pos[s[i]].push_back(i);
  }

  array<char, 3> kinds{'B', 'G', 'R'};
  ll ans = 0;
  do {
    for (int i : ch_pos[kinds[0]]) {
      for (int j : ch_pos[kinds[1]]) {
        if (i < j) {
          ans += choose(ch_pos[kinds[2]], i, j);
        }
      }
    }
  } while (next_permutation(kinds.begin(), kinds.end()));
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const ll inf=1e9+7;
const ll mod=998244353;
signed main(){
    int n;cin>>n;
    int ng=-1,ok=n;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    while(ok-ng>1){
        int mid=ng+(ok-ng)/2;
        map<ll,ll>ma;
        bool f=1;
        int la=0;
        rep(i,n){
            if(la<a[i]){
                la=a[i];
            }else{
                if(mid==0){
                    f=0;break;
                }
                for(auto e:ma){
                    if(e.fi>=-a[i])break;
                    ma.erase(e.fi);
                }
                ll now=1;
                ll z=-a[i];
                while(now==1){
                    if(ma[z]==mid&&z<0){
                        ma.erase(z);
                        z++;
                    }else{
                        ma[z]++;
                        now=0;
                    }
                }
                if(ma[0]>0){
                    f=0;
                    break;
                }
                la=a[i];
            }
        }
        if(f)ok=mid;
        else ng=mid;
    }
    cout<<ok+1<<endl;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;


int main()
{
	int64_t n;
	cin >> n;
	vector<int64_t> a(n);
	vector<int64_t> data(n);
	for (int i = 0; i < n; i++) {
		int64_t a_in;
		cin >> a_in;
		a.at(i) = a_in;
		data.at(a_in - 1) += 1;
	}

	int64_t all = 0;
	for (int i = 0; i < n; i++) {
		all += data.at(i) * (data.at(i) - 1) / 2;
	}

	for (int i = 0; i < n; i++) {
		int64_t ans = all;
		ans -= data.at(a.at(i) - 1) - 1;
		cout << ans << endl;
	}

}



Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i = (int)(n)-1; i>=0; --i)
#define For(i,a,b) for(auto i=(a);i<=(b);++i)
#define rFor(i,a,b) for(auto i=(b);i>=(a);--i)
#define call(var) cerr<<#var<<"="<<var<<"\n";
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const double pi = acos(-1);
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}
template<class T> istream& operator>>(istream& is, vector<T>& a){rep(i,a.size()) is >> a[i]; return is;}
template<class T> ostream& operator<<(ostream& os, vector<T>& a){rep(i,a.size()) os << a[i] << " "; return os;}
template<class T, class U> istream& operator>>(istream& is, pair<T,U>& p){is >> p.first >> p.second; return is;}
template<class T, class U> ostream& operator<<(ostream& os, const pair<T,U>& p){os << "("<< p.first << "," << p.second << ")"; return os;}
template<class T, class U> ostream& operator<<(ostream& os, const map<T,U>& mp){for(auto& t : mp) os << t.first << " " << t.second << "\n"; return os;}

int main(){
    int n;cin >> n;
    cout << dup(n, 1000) * 1000 - n  << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
using namespace std;
typedef long long LL;
int main(int argc, char* argv[])
{
	const LL MOD=1000000000+7;
	int N,i;
	cin>>N;
	vector<LL> A(N);
	LL hj=0;
	for (i=0;i<N;i++){
		cin>>A[i];
		hj+=A[i];
		hj%=MOD;
	}
	LL Sum=0;
	for (i=0;i<N-1;i++){
		hj-=A[i];
		if (hj<0){
			hj+=MOD;
		}
		LL B=A[i]*hj;
		B%=MOD;
		Sum+=B;
		Sum%=MOD;
	}
	cout<<Sum<<endl;
	return 0;
}

Measured memory_bytes: 4340
R,G,B,N = map(int, input().split())

ans = 0
L = sorted([R,G,B], reverse=True)
for i in range(N//L[0]+1):
    for j in range((N-i*L[0])//L[1]+1):
        if (N-i*L[0]-j*L[1])%L[2] == 0:
                ans += 1

print(ans)

Measured memory_bytes: 41436
#include <stdio.h>

int main(void) {
  int h = 0;
  int w = 0;
  int i = 0;
  int j = 0;

  scanf("%d", &h);
  scanf("%d", &w);

  while (!((h == 0) && (w == 0))) {
    for(i = 0; i < h; i++) {
      for(j = 0; j < w; j++) {
	if ((i % 2) == 0) {
	  if ((j % 2) == 0) {
	    printf("#");
	  } else {
	    printf(".");
	  }
	} else {
	  if ((j % 2) == 0) {
	    printf(".");
	  } else {
	    printf("#");
	  }
	}
      }
      printf("\n");
    }

    printf("\n");
          
    scanf("%d", &h);
    scanf("%d", &w);    
  }
  
  return 0;
}

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

using namespace std;

int pow3[16];
int n, m;

void calc_pow3()
{
    pow3[0] = 1;

    for (int i = 1; i <= 15; ++i) {
        pow3[i] = pow3[i - 1] * 3;
    }
}

int solve(int n, int m)
{
    int c[16];
    for (int i = 0; i < 3; ++i) {
        int j;

        cin >> j;

        int temp;
        for (int k = 0; k < j; ++k) {
            cin >> temp;
            
            c[n - temp] = i;
        }
    }

    int ans = 0;
    int d;
    int p = 0;

    for (int i = n - 1; i >= 0; --i) {
        d = abs(c[i] - p);
        
        ans += pow3[i] * d;
        
        if (d == 1) p = 2 - p;


    }

    int ans2;

    ans2 = pow3[n] - 1 - ans;

    ans = min(ans, ans2);

    ans = (ans > m) ? -1: ans;

    return ans;
}

int main()
{
    calc_pow3();
    
    int n, m;

    while (cin >> n >> m) {
        if (n == 0 && m == 0) break;

        cout << solve(n, m) << endl;
    }

    return 0;
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

int main()
{
	int r, g, b, n;
	cin >> r >> g >> b >> n;

	int ans = 0;
	for (int i = 0; i <= n; i+=r) {
		for (int j = 0; i + j <= n; j+=g) {
			if ((n - i - j) % b == 0) {
				ans++;
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
/* template.cpp(shinobu_menkoi) {{{ */
#include <bits/stdc++.h>
using namespace std;

// clang-format off
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (lint i = (a); i < (lint)(n); i += (s))
#define rrep(...) GET_MACRO(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rrep1(a) rrep2(_, a)
#define rrep2(i, a) rrep3(i, a, 0)
#define rrep3(i, a, n) rrep4(i, a, n, 1)
#define rrep4(i, a, n, s) for (lint i = (a); i >= (lint)(n); i -= (s))
#define each(i, ctn) for (auto &&i : (ctn))

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(v) begin(v), end(v)
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'
#define TEMP_T template <class T>
#define TEMP_TU template <class T, class U>

TEMP_T using vec = vector<T>;
TEMP_T using heap = priority_queue<T>;
TEMP_T using minheap = priority_queue<T, vec<T>, greater<T>>;
using lint = long long;
using ulint = unsigned long long;
using ld = long double;
using vi = vec<int>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<int, int>;
using vs = vec<string>;

TEMP_TU ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << p.fi << " " << p.se; }
TEMP_TU istream &operator>>(istream &is, pair<T, U> &p) { return is >> p.fi >> p.se; }

const int INF{1001001001};
const lint LINF{1001001001001001001ll};
const int MOD{(int)1e9 + 7};
const double EPS{1e-9};
const double PI{acos(-1)};
const int dx[]{0, 1, 0, -1, 1, -1, 1, -1}, dy[]{1, 0, -1, 0, 1, -1, -1, 1};

inline bool inside(int y, int x, int h, int w) { return y >= 0 && x >= 0 && y < h && x < w; }
TEMP_T inline bool chmin(T &a, const T &b) { if (a > b) a = b; return a > b; }
TEMP_T inline bool chmax(T &a, const T &b) { if (a < b) a = b; return a < b; }
TEMP_T inline void print(const T &x) { cout << x << '\n'; }
TEMP_T inline void print(const vec<T> &v, string d = "\n") { rep(i, v.size()) cout << v[i] << (i == (lint)v.size() - 1 ? "\n" : d); }
template <class T = int> inline T in() { T x; cin >> x; return x; }
template <class T = string> vec<T> split(const string &s, char d = ',') {
  vec<T> v; stringstream ss(s); for (string b; getline(ss, b, d); ) {
    stringstream conv(b); T t; conv >> t; v.eb(t); } return v;
}
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } pre__;
// clang-format on
/* }}} */

int res = 0;
int n;
vi v;

signed main() {
  cin >> n;
  v.resize(n);
  rep(i, n) cin >> v[i];

  int mini = std::accumulate(all(v), 0);
  int maxi = mini;
  each(i, v) if (i % 10 != 0) chmin(mini, i);
  print(maxi % 10 != 0 ? maxi : maxi - mini);
}


Measured memory_bytes: 256
#define rep(i,x) for (int i = 0; i < x; i++)
#define mod 1000000007
#define MOD 998244353
#define INF (1<<31)-1
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;


int main() {
	string a;
	cin >> a;
	int ans = 0;
	string s = "ATGC";
	int cnt = 0;
	rep(i, a.size()) {
		int cnt2 = 0;
		rep(j, 4) {
			if (s[j] == a[i]) {
				cnt2++;
			}
		}
		if (cnt2 > 0) {
			cnt++;
			ans = max(ans, cnt);
		}
		else {
			cnt = 0;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main()
{
    IO;
    int n;
    cin >> n;
    vector<int> v, in;
    for(int i = 1; i <= n; i++)
    {
        int a;
        cin >> a;
        v.push_back(a);
        in.push_back(a);
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < in.size(); i++)
    {
        int curr = in[i];
        if(curr != v[v.size() - 1])
            cout << v[v.size() - 1] << endl;
        else
            cout << v[v.size() - 2] << endl;
    }
    return 0;
}


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

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



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cctype>
#include<stack>
using namespace std;
typedef long long ll;
int main()
{
    string a,b;
    string c;
    cin>>a>>b;
    int i=0;
    for(i=0;i<min(a.length(),b.length());i++)
    {
        c+=a[i];
        c+=b[i];
    }
    for(;i<a.length();i++)
        c+=a[i];
    for(;i<b.length();i++)
        c+=b[i];
    cout<<c<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define setpre(n) cout << fixed << setprecision(n)
#define tr(c) for(const auto& x : c )cout << x << " "; cout << "\n";
#define PI acos(-1LL)


#ifdef LOCAL
string to_string(const string& s){
    return '"' + s + '"';
}
string to_string(const char* s) {
    return to_string((string) s);
}
string to_string(bool b) {
    return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename T>
string to_string(T v){
    bool first = true;
    string res = "{";
    for(const auto& x: v){
        if(!first) res+=", ";
        first = false;
        res+=to_string(x);
    }
    res+="}";
    return res;
}
void bug() { cerr << endl; }
template<typename Head, typename... Tail>
void bug(Head H, Tail... T) {
    cerr << " " << to_string(H);
    bug(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", bug(__VA_ARGS__);
#else
#define debug(...) 11;
#endif


const int M = 1000000007;
const int N = 2e6 + 5;
const long long INF = 2e17 + 12;


void solve() {
    int d,t, s;
    cin >> d >> t >> s;
    if(s*t >= d){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }
}
signed main(){
    FAST
#ifdef TIMER
    clock_t start;
    double duration;
    start = clock();
#endif
    int tc = 1;
//    TODO: check for tc
//    cin >> tc;
    for (int t = 1; t <= tc; t++) {
        solve();
    }
#ifdef TIMER
    duration = (clock() - start) / (double) CLOCKS_PER_SEC;
    cerr <<"\n\nTotal time elapsed: "<< duration <<"sec\n";
#endif
}


Measured memory_bytes: 3632
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>


using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long S){
  ll c = 1000000000;
  ll y;
  if(S%c==0) {
    y = S/c;
  } else {
    y = (S/c)+1;
  }
  ll x = c*y-S;
  std::cout << 0 << " " << 0 << " " << c << " " << 1 << " " << x <<" "<< y << std::endl;
    
}

int main(){
  long long S;
  scanf("%lld",&S);
  solve(S);
  return 0;
}



Measured memory_bytes: 256