akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int A;
		int B;
		int i;
		Scanner sc = new Scanner(System.in);
		A = sc.nextInt();
		B = sc.nextInt();
		sc.close();
		for (i = 0; i < 10001; i++) {
			if ((int) (i * 0.08) == A && (int) (i * 0.1) == B) {
				System.out.println(i);
				return;
			}
		}
		System.out.println("-1");
	}

}

Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
typedef long long ll;
int N[maxn];
int main()
{
	int a,b,c,d;
	int n,k;cin>>n>>k;
	cout<<n-k+1<<endl;
	return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

int main() {
	char x, y;
	cin >> x >> y;
	if (x < y)
		cout << '<' << endl;
	else if (x > y)
		cout << '>' << endl;
	else
		cout << '=' << endl;
}

Measured memory_bytes: 3640
#include <iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  int a[N];
  for(int i=0;i<N;i++){
    cin >> a[i];
  }
  
  int count = 0;
  bool f = true;
  
  while(f){
    for(int j=0;j<N;j++){
      if(a[j]%2!=0){
        f = false;
        break;
      }
      else{
        a[j]=a[j]/2;
      }
      
      if(j==N-1){
          count++;
      }
    }
  }
  
  cout << count << endl;
    
}


Measured memory_bytes: 256
# D
import math
S = input()
SS = list(S)
index_num_kugiri = [-1]
index_num_soko = []
for i in range(len(SS) - 1):
    if SS[i] == 'L' and SS[i+1] == 'R':
        index_num_kugiri.append(i)
    if SS[i] == 'R' and SS[i+1] == 'L':
        index_num_soko.append(i)
index_num_kugiri.append(len(S)- 1)
ans = []
for k in range(0, len(index_num_soko)):
    if index_num_soko[k] % 2 == index_num_kugiri[k+1]  % 2:
        tmp1 = math.ceil((index_num_kugiri[k+1] - index_num_kugiri[k] ) / 2)
        tmp2 = index_num_kugiri[k+1] - index_num_kugiri[k]  - tmp1
    else:
        tmp1 = math.floor((index_num_kugiri[k+1] - index_num_kugiri[k] ) / 2)
        tmp2 = index_num_kugiri[k+1] - index_num_kugiri[k]  - tmp1
    ans.append([index_num_soko[k], tmp1])
    ans.append([index_num_soko[k], tmp2])
tugi = False
tmp = 0
final_ans = []
for i in range(len(S)):
    if tugi:
        tugi = False
        final_ans.append(ans[tmp][1])
        tmp += 1
        continue
    if i in index_num_soko:
        final_ans.append(ans[tmp][1])
        tmp += 1
        tugi = True
        continue
    else:
        final_ans.append(0)
        
print(' '.join(map(str, final_ans)))

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

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

    vector<pair<int, int>> v(n);
    vector<int> srt(n);
    for (int i = 0; i < n; i++)
        cin >> v[i].second;

    for (int i = 0; i < n; i++){
        cin >> v[i].first;
        srt[i] = v[i].first;
    }

    sort(v.begin(), v.end());
    sort(srt.begin(), srt.end());
    
    int cnt = 0;
    for (int i = 0; i < n && cnt <= n - 2; i++){
        if (v[i].first < v[i].second){
            int x = lower_bound(srt.begin(), srt.end(), v[i].second) - srt.begin();
            bool change = false;
            for (int j = x; j < n; j++){
                if (v[j].first != v[j].second){
                    cnt += 1;
                    swap(v[j].second, v[i].second);
                    change = true;
                    break;
                
                }
            }

            if (!change){
                cout << "No\n";
                return 0;
            }
        }

        if (v[i].first < v[i].second)
            i--;
    }

    if (cnt > n - 2)
        cout << "No\n";
    else
        cout << "Yes\n";

    return 0;
}


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

using namespace std;
using ll = long long;

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

  ll n;
  cin >> n;

  // 約数の数
  vector<ll> f(1e7 + 1, 1ll);
  for (ll i = 2; i <= n; i++) {
    ll j = i;
    while (j <= n) {
      f[j]++;
      j += i;
    }
  }

  ll ans = 0ll;
  for (ll i = 1; i <= n; i++) {
    ans += i * f[i];
  }

  cout << ans  << endl;

  return 0;
}


Measured memory_bytes: 81340
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<deque>
#include<map>
using namespace std;
typedef long long ll;

int main() {
    int n; cin >> n;
    int q; cin >> q;
    vector<vector<int>> next(n);
    for (int i = 0; i < n-1; i++)
    {
        int a, b; cin >> a >> b;
        a--; b--;
        next[a].push_back(b);
        next[b].push_back(a);
    }

    vector<ll> cnt(n);
    for (int i = 0; i < q; i++)
    {
        int p, x; cin >> p >> x;
        p--;
        cnt[p] += x;
    }

    auto rec = [&](auto &&rec, int now, int before) -> void {
        for (auto v : next[now]) {
            if (v == before) continue;
            cnt[v] += cnt[now];
            rec(rec, v, now);
        }
    };
    
    rec(rec, 0, 0);

    for(int i = 0; i < n; i++) {
        printf("%d%c", cnt[i], (i==(n-1))? '\n' : ' ');
    }    
    return 0;
}

Measured memory_bytes: 21504
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef unordered_map<string, ll> mpsl;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

ll inl() {
    ll x;
    cin >> x;
    return (x);
}

string ins() {
    string x;
    cin >> x;
    return (x);
}

struct abc {
    ll sum, ia, ib, ic;
};

bool operator<(const abc &abc1, const abc &abc2) {
    return abc1.sum < abc2.sum;
};

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        ll x = inl(), y = inl(), z = inl(), k = inl();
        vl a(x), b(y), c(z);
        rep(i, x) a[i] = inl();
        rep(i, y) b[i] = inl();
        rep(i, z) c[i] = inl();

        sort(all(a), greater<>());
        sort(all(b), greater<>());
        sort(all(c), greater<>());
        PQ<abc> que;
        que.push({a[0] + b[0] + c[0], 0, 0, 0});
        vl ans;

        set<ll> s;
        rep(i, k) {
            abc v = que.top();
            que.pop();
            ans.eb(v.sum);

            if (v.ia != x - 1) {
                ll na = v.ia + 1;
                ll hash = (na << 20) + (v.ib << 10) + v.ic;
                if (s.find(hash) == s.end()) {
                    s.insert(hash);
                    que.push({a[na] + b[v.ib] + c[v.ic], na, v.ib, v.ic});
                }
            }
            if (v.ib != y - 1) {
                ll nb = v.ib + 1;
                ll hash = (v.ia << 20) + (nb << 10) + v.ic;
                if (s.find(hash) == s.end()) {
                    s.insert(hash);
                    que.push({a[v.ia] + b[nb] + c[v.ic], v.ia, nb, v.ic});
                }
            }
            if (v.ic != z - 1) {
                ll nc = v.ic + 1;
                ll hash = (v.ia << 20) + (v.ib << 10) + nc;
                if (s.find(hash) == s.end()) {
                    s.insert(hash);
                    que.push({a[v.ia] + b[v.ib] + c[nc], v.ia, v.ib, nc});
                }
            }
        }
        rep(i, k) cout << ans[i] << endl;


#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 768
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 998244353;
int n;
vector<int> G[200010];
int d1[200001] = {0};
int d2[200001] = {0};
void dfs1(int s,int dis){
    for(auto x:G[s]){
        if(d1[x] == INF){
            d1[x] = dis+1;
            dfs1(x,dis+1);
        }
    }
}
void dfs2(int s,int dis){
    for(auto x:G[s]){
        if(d2[x] == INF){
            d2[x] = dis+1;
            dfs2(x,dis+1);
        }
    }
}
signed main(){
    cin >> n;
    if(n == 1){
        cout << "First" << endl;
        return 0;
    }
    rep(i,n){
        int a,b;
        cin >> a >> b;
        G[a-1].pb(b-1);
        G[b-1].pb(a-1);
    }
    rep(i,n){
        d1[i] = INF;
        d2[i] = INF;
    }
    d1[0] = 0;
    dfs1(0,0);
    int m = -1;
    int u = -1;
    rep(i,n){
        if(d1[i] > m){
            m = d1[i];
            u = i;
        }
    }
    d2[u] = 0;
    dfs2(u,0);
    int m1 = -1;
    rep(i,n){
        if(d2[i] > m1){
            m1 = d2[i];
        }
    }
    if(m1%3 == 1)cout << "Second" << endl;
    else cout << "First" << endl;
    cerr << m1 << endl;


    return 0; 
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://agc033.contest.atcoder.jp/tasks/agc033_a

Measured memory_bytes: 23680
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define BITS(n, num) std::bitset<(n)>((num)).to_string()
#define REV <T> greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  char b;
  cin >> b;
  if (b == 'A')
    cout << 'T' << endl;
  else if (b == 'T')
    cout << 'A' << endl;
  else if (b == 'G')
    cout << 'C' << endl;
  else if (b == 'C')
    cout << 'G' << endl;

  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"io"
	"os"
	"sort"

)

func main() {
	solve(os.Stdin, os.Stdout)
}

type inInfo struct {
	in    int
	after int
}

type inInfoSorter []*inInfo

func (a inInfoSorter) Len() int      { return len(a) }
func (a inInfoSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a inInfoSorter) Less(i, j int) bool {
	switch {
	case a[i].in > a[j].in:
		return true
	case a[i].in < a[j].in:
		return false
	case a[i].after > a[j].after:
		return true
	default:
		return false
	}
}

func sum(w []int) int {
	s := 0
	for _, v := range w {
		s += v
	}
	return s
}

type ptr []int

func (x ptr) top(i int) int {
	ptrs := []int(x)
	var his []int
	cur := i
	for ; cur >= 0 && ptrs[cur] != cur; cur = ptrs[cur] {
		his = append(his, cur)
	}
	for _, v := range his {
		ptrs[v] = cur - 1
	}
	if cur >= 0 {
		ptrs[cur] = cur - 1
	}
	return cur
}

func solve(stdin io.Reader, stdout io.Writer) {
	var n, m int
	var infos []*inInfo

	fmt.Fscanln(stdin, &n, &m)

	for i := 0; i < n; i++ {
		var info inInfo
		fmt.Fscanln(stdin, &info.after, &info.in)
		infos = append(infos, &info)
	}

	sort.Sort(inInfoSorter(infos))

	var ans = make([]int, m)
	var p = make([]int, m)
	for i := range p {
		p[i] = i
	}

	for _, w := range infos {
		i := ptr(p).top(m - w.after)
		if i >= 0 {
			ans[i] = w.in
		}
	}

	fmt.Fprintln(stdout, sum(ans))

}



Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

	ll N; cin >> N;
	ll ans = 0LL;
	rep1(i,N) ans += i;
	cout << ans << endl;
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	for(LL i = 1; i <= 10000; i++){
		if(i*(i+1) >= 2*n){
			for(int j = i; j >= 1; j--){
				if(n >= j){
					cout << j << endl;;
					n -= j;
				}
			}
			break;
		}
	}
}


Measured memory_bytes: 384
H,W=map(int,input().split()) # H=縦（行）、W=横（列）
L=[ input() for i in range(H)]

def DFS():
  cond = True
  for i in range(H):
    for j in range(W):
      if L[i][j] != '#':
        #print('continue')
        continue
      IND=[(i,j-1), (i,j+1), (i-1,j), (i+1,j)]
      #print(IND)
      conds = []
      for (y, x) in IND:
        if x < 0 or y < 0 or x >= W or y >= H:
          conds.append('.')
        elif L[y][x] == '.':
          conds.append('.')
        else:
          #print(L[y][x], (y,x))
          conds.append('#')
      #print(conds, (i,j))
      if conds.count('#') == 0:
        return 'No'
  return 'Yes'

print(DFS())


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

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };
	static final int INF = Integer.MAX_VALUE / 3;
	static final long LINF = Long.MAX_VALUE / 3;

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
		int k = fs.nextInt() - 1;
		System.out.println(a[k]);

	}

	//MOD culculations
	static long plus(long x, long y) {
		long res = (x + y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long sub(long x, long y) {
		long res = (x - y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long mul(long x, long y) {
		long res = (x * y) % mod;
		return res < 0 ? res + mod : res;
	}

	static long div(long x, long y) {
		long res = x * pow(y, mod - 2) % mod;
		return res < 0 ? res + mod : res;
	}

	static long pow(long x, long y) {
		if (y < 0)
			return 0;
		if (y == 0)
			return 1;
		if (y % 2 == 1)
			return (x * pow(x, y - 1)) % mod;
		long root = pow(x, y / 2);
		return root * root % mod;
	}
}

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

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

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

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

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

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

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

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

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

Measured memory_bytes: 20948
S = input()
N = len(S)

def palind(word):
  word = word.lower()
  return word[::-1] ==word

num1 = int((N-1)/2)
num2 = int((N+3)/2)

text1 =S[0::num1]
text2 =S[num2-1::]

if palind(S) == True and palind(text1) == True and palind(text2) == True:
  print("Yes")
else:
  print("No")




Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD (long long)(1e9+7)
int main(){
	ll n,m;
	cin>>n>>m;
	vector<ll>x(m);
	vector<ll>between(m-1);
	for(int i=0;i<m;i++){
		cin>>x[i];
	}
	sort(x.begin(),x.end());
	for(int i=1;i<m;i++)between[i-1]=abs(x[i]-x[i-1]);	
	sort(between.begin(),between.end());
	
	if(n>m){//コマがmより大きいと0になるよ
		cout<<0<<endl;
	}
	else{
		ll ans=0;
		for(int i=0;i<m-n;i++)ans+=between[i];
		cout<<ans<<endl;
	}
}

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

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

 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

ll tmax = 0;
ll tmin = 0;

int hoge(vector<ll> &A, ll t) {
    int ans = 0;
    rep(i,A.size()) {
        if (A[i]>t) {
            ans += A[i]/t;
        }
    }
    return ans;
}

int main(){
    int N,K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i,N) {
        ll a;
        cin >> a;
        A[i] = a;
        tmax = max(tmax,a);
    }

    while(tmax-tmin>1) {
        ll mid = (tmax+tmin)/2;
        if (hoge(A,mid)<=K) {
            tmax = mid;
        }
        else {
            tmin = mid;
        }
    }
    if (hoge(A,tmax)<=K) {
        cout << tmax << endl;
    }
    else {
        cout << tmin << endl;
    }

}


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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

string alphabet = "abcdefghijklmnopqrstuvwxyz";

int main(int argc, char **argv)
{
	string s; cin >> s;
	ll N = (ll)s.size();

	ll res{INF};
	for (auto &w : alphabet)
	{
		ll tmp{0};

		for (ll i = 0; i < N;)
		{
			ll k = i + 1;
			if (w != s[i])
			{
				while (k < N && w != s[k]) {++k;};
				tmp = max(tmp, k-i);
			}
			i = k;
		}

		res = min(res, tmp);
	}
	std::cout << res << std::endl;
}

Measured memory_bytes: 256
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
bl = [0 for i in range(n)]
bl[0] = a[0]
br = [0 for i in range(n)]
br[0] = a[n - 1]
for i in range(1, n):
    bl[i] = max(bl[i - 1],a[i])
a.reverse()
for i in range(1, n):
    br[i] = max(br[i - 1],a[i])
br.reverse()
print(br[1])
for i in range(1, n - 1):
    print(max(bl[i - 1],br[i + 1]))
print(bl[n - 2])

Measured memory_bytes: 15696
#include<stdio.h>
int main()
{
  int N,K,p=1;
  scanf("%d", &N);
  scanf("%d", &K);
  for(int i=0;i<N;i++){
    if(p<K) p*=2;
    else p+=K;
  }    
  printf("%d\n",p);
  return 0;
}

Measured memory_bytes: 128
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		double ans1 = (double)W*H/ 2;
		int ans2 = 0;
		if (W == x*2 && H == y*2) {
			ans2 = 1;
		}
		System.out.println(ans1 + " " + ans2);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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

Measured memory_bytes: 21076
#include<stdio.h>
int main(){
  int a, b, d, r;
  double f;
  scanf("%d %d", &a, &b);
  d = a / b;
  r = a % b;
  f = (double)a / b;
  printf("%d %d %lf\n", d, r, f);
  return 0;
}


Measured memory_bytes: 2104
s = input()
f = True
for i in range(len(s)):
    if i%2 == 0:#iが偶数ならs[i]は奇数番目
        if s[i] == 'L':#奇数番目にL来たらFalse
            f = False
            break
    
    else:
        if s[i] == 'R':
            f = False
            break
if f:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  vector<int> W(N);
  int sum=0,a=0,b=0;
  for (int i = 0; i < N; i++) {
    cin>>W[i];
    sum+=W[i];
  }
  for(int i=0;i<N;i++){
    a+=W[i];
    if(a>=sum/2){
      cout<<min(2*a-sum,sum-2*b);
      break;
    }
    b+=W[i];
  }    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
    int a[100][100];
    int b[100][100];
    long int c[100][100]={0};
    int n,m,l;
    int i,j,k;
     
    scanf("%d %d %d",&n,&m,&l);
     
       //??????A?????\???  n*m
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
       //??????B?????\???  m*l
    for(j=0;j<m;j++){
        for(k=0;k<l;k++){
            scanf("%d",&b[j][k]);
        }
    }
     
       //?????? C   n*l
    for(i=0;i<n;i++){
        for(k=0;k<l;k++){
            for(j=1;j<=m;j++){
                c[i][k]+=(a[i][j-1]*b[j-1][k]);
            }
        }
    }
     
    for(i=0;i<n;i++){
        for(k=0;k<l;k++){
            printf("%ld",c[i][k]);
            if(k!=l-1)   printf(" ");
        }
        printf("\n");
    }
     
    return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<math.h>
#include <string.h>
using namespace std;
int main(){
	int i,j,m,n,r,l;
	LOOP:
	while(cin>>n>>m){
		char a[n][n],b[m][m];
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				cin>>a[i][j];
			}
		}
		for(i=0;i<m;i++){
			for(j=0;j<m;j++){
				cin>>b[i][j];
			}
		}
		int flag=0;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(a[i][j]==b[0][0]){
					flag=1;
					if(flag){
						for(r=0;r<m;r++){
							for(l=0;l<m;l++){
								if(a[i+r][j+l]!=b[r][l]){
									flag=2;
									break;
								}
							}
						}
					}
				}
				if(flag==1){
					cout<<"Yes"<<endl;
					goto LOOP;
				}
			}
		}
		if(flag!=1){
			cout<<"No"<<endl;
		}
	}
	return 0;
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
//const int INF = INT_MAX  ;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

const int mod = 1000000007;

typedef pair<int, char> PC;

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

    vector<PC> seq_counts;
    char prev = s[0];
    int seq = 1;
    for (int i = 1; i < s.size(); i++) {
        char now = s[i];
        if (now != prev) {
            seq_counts.emplace_back(seq, prev);
            prev = now;
            seq = 1;
        } else {
            seq++;
        }
    }
    seq_counts.emplace_back(seq, prev);

    queue<PC> left;
    queue<PC> center;
    queue<PC> right;

    for (auto p : seq_counts) {
        right.push(p);
    }

    int count = 0;
    int ans = 0;
    int c_count = 0; // 直立カウント
    while (!right.empty()) {
        auto next = right.front(); // 次に入れたい
        if (next.second == '1') {
            right.pop();
            center.push(next);
            count += next.first;
            ans = max(ans, count);
            continue;
        }
        // 次に入れたいのは直立

        if (c_count == k) {
            // 一番左だけ取り出せばいい時と、二回連続で取り出さないといけないと気があるが、
            // whileで上手くいく
            auto pop = center.front();
            if (pop.second == '1') {
                center.pop();
                count -= pop.first;
                continue;
            } else {
                center.pop();
                count -= pop.first;
                c_count--;
                continue;
            }
        }

        right.pop();
        center.push(next);
        count += next.first;
        ans = max(ans, count);
        c_count++;

    }

    cout << ans << endl;

}



Measured memory_bytes: 2036
#include<iostream>
#include<string>
#include<vector>
#include <cctype>
using namespace std;
int main(void){
string w;
char c;
cin>>w;
bool ans=true;
if(w.size()<6)ans=false;
int t=0;
for(int i=0;i<w.size();i++){
	c=w[i];
 if (std::isdigit(static_cast<unsigned char>(c)))t++;
}
if(t==0)ans=false;
t=0;
for(int i=0;i<w.size();i++){
if(w[i]>='a'&&w[i]<='z')t++;
}
if(t==0)ans=false;
t=0;
for(int i=0;i<w.size();i++){
if(w[i]>='A'&&w[i]<='Z')t++;
}
if(t==0)ans=false;
if(ans)cout<<"VALID"<<endl;
else cout<<"INVALID"<<endl;
return 0;

}

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

int main(){
	vector<int> count;
	while(1){
		int n,x,cnt=0;
		cin>>n>>x;
		if(n==0 && x==0) break;
		for(int i=1; i<=n; i++){
			for(int j=i+1; j<=n; j++){
				for(int k=j+1; k<=n; k++){
					if(i+j+k==x) cnt++;
				}
			}
		}
		count.push_back(cnt);
	}
	for(int i=0; i<count.size(); i++){
		cout<<count[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int n;
    cin >> n;
    int t = n;
    int r = 0;
    while(t>0){
        r += t%10;
        t/=10;
    }
    if(n%r==0) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll INF = 1ll << 35;
int a[100], b[100];
ll dp[100][100];
ll rec(int x, int y){
  if(x == y) return 0;
  if(~dp[x][y]) return dp[x][y];
  ll ret = INF;
  for(int i = x; i < y; i++){
    ret = min( ret, rec( x, i) + rec( i + 1, y) + a[x] * b[i] * a[i + 1] * b[y]);
  }
  return dp[x][y] = ret;
}

int main(){
  int n;
  cin >> n;
  fill_n( *dp, 100 * 100, -1);
  for(int i = 0; i < n; i++){
    cin >> a[i] >> b[i];
  }
  cout << rec( 0, n - 1) << endl;
}

Measured memory_bytes: 1240
// atcoder/abc176/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  int n;
  while (cin >> n) {
    vec<int> a(n);
    cin >> a;

    lli x = 0;
    int mx = 0;
    each (i, a) {
      if (mx <= i) mx = i;
      else {
        x += abs(mx - i);
        mx = max(mx, i);
      }
    }
    cout << x << endl;
  }

  return 0;
}


Measured memory_bytes: 3956
def partition(A, p, r):
    x = A[r]
    i = p - 1

    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    A[i+1], A[r] = A[r], A[i+1]
    return i + 1


if __name__ == '__main__':
    import sys

    n = int(input())
    A = list(map(int, sys.stdin.readline().split()))
    q = partition(A, 0, n - 1)
    end = ' '
    for i in range(n):
        if i == n - 1:
            end = '\n'
        if i == q:
            print('[{}]'.format(A[i]), end=end)
        else:
            print(A[i], end=end)



Measured memory_bytes: 15740
#include<bits/stdc++.h>
using namespace std;
long long D[301][301];
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, M, L;
    cin >> N >> M >> L;
    for (int i = 0; i < M; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        D[a][b] = c;
        D[b][a] = c;
    }
    int Q;
    cin >> Q;
    vector<pair<int, int> > ST(Q);
    for (auto & st : ST) {
        cin >> st.first >> st.second;
    }
    for (int k = 1; k < N+1; ++k) {
        for (int i = 1; i < N+1; ++i) {
            if (k == i) continue;
            for (int j = 1; j < N+1; ++j) {
                if (k == j || i == j || D[i][k] == 0 || D[k][j] == 0) continue;
                if (!D[i][j] || D[i][j] > D[i][k] + D[k][j]) {
                    D[i][j] = D[i][k] + D[k][j];
                }
            }
        }
    }
    for (int i = 1; i < N+1; ++i) for (int j = 1; j < N+1; ++j) {
        if (D[i][j]) {
            if (D[i][j] <= L) {
                D[i][j] = 1;
            } else {
                D[i][j] = 0;
            }
        }
    }
    for (int k = 1; k < N+1; ++k) {
        for (int i = 1; i < N+1; ++i) {
            if (k == i) continue;
            for (int j = 1; j < N+1; ++j) {
                if (k == j || i == j || D[i][k] == 0 || D[k][j] == 0) continue;
                if (!D[i][j] || D[i][j] > D[i][k] + D[k][j]) {
                    D[i][j] = D[i][k] + D[k][j];
                }
            }
        }
    }
    for (auto st : ST) {
        printf("%lld\n", D[st.first][st.second] ? D[st.first][st.second]-1 : -1);
    }
    return 0;
}


Measured memory_bytes: 1920
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;


LL solve(long long N, std::vector<long long> a){
	vector<LL> s;
	while(a.size()>1){
		s.clear();
		for(int i=1;i<a.size();i++){
			s.push_back(abs(a[i]-a[i-1]));
		}
		a.swap(s);
	}
	cout << a[0] << endl;
	return a[0];
}
int g(int a,int b)
{
	if(a==0){
		if(b==0){
			return 1;
		}
		return 0;
	}
	int u=1;
	while(u*2<=a){
		u*=2;
	}
	a-=u;
	if(b>a){
		b-=u;
	}
	if(b<0){
		return 0;
	}
	return g(a,b);
}
LL f(vector<LL> a){
	vector<LL> s;
	while(a.size()>1){
		s.clear();
		LL m=0;
		for(int i=1;i<a.size();i++){
			s.push_back(abs(a[i]-a[i-1]));
			m=max(m,s.back());
		}
		a.swap(s);
		if(m<=2){
			break;
		}
	}
	//cerr << a.size() << endl;
	//exit(0);
	if(a.size()==1){
		//cerr << "bbb" << endl;
		cout << a[0] << endl;
		return a[0];
	}
	int m=a.size()-1;
#if 0
	for(int i=0;i<a.size();i++){
		cout << a[i];
	}
	cout << endl;
#endif
	LL ret1=0;
	LL ret2=0;
	int cnt1=0;
	for(int i=0;i<a.size();i++){
		if(a[i]==2){
			ret2^=g(m,i);
		}
		else if(a[i]==1){
			ret1^=g(m,i);
			cnt1++;
		}
		//cout << g(m,i);
	}
	//cout << endl;
	if(cnt1==0){
		ret1=2*ret2;
	}
	cout << ret1 << endl;
	return ret1;
}


const int L=1e6+1;
char in[L];
int main(){
#if 0
	for(int i=0;i<12;i++){
		for(int j=0;j<=i;j++){
			cerr << g(i,j);
		}
		cerr << endl;
	}
#endif

    long long N;
    scanf("%lld",&N);
	vector<LL> a;
#if 1
	scanf("%s",in);
	for(int i=0;i<N;i++){
		a.push_back(in[i]-'0');
		//a.push_back(rand_dist(rand_src));
		//cerr << a.back();
	}
#else
	std::mt19937 rand_src(12345);
	for(int N=1;N<100;N++){
		a.clear();
		std::uniform_int_distribution<int> rand_dist(1, 3);
		for(int i=0;i<N;i++){
			a.push_back(rand_dist(rand_src));
		}
		if(solve(N, a)!=f(a)){
			assert(false);
			for(auto v:a){
				cerr << v;
			}
			//cerr << endl;
			//cerr << solve(N,a) << endl;
			//cerr << f(a) << endl;
			return 0;
		}
	}
#endif
	//cerr << endl;
	f(a);



    return 0;
}


Measured memory_bytes: 31080
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d, L, R;
  cin >> a >> b >> c >> d;
  L = a + b;
  R = c + d;
  if (L == R) {
    cout << "Balanced" << endl;
  }
  else if (L >= R){
    cout << "Left" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
//後日挑戦
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
ll v[3005][3005];
ll dp[3005][3005][4];
int main() {
    int r,c,k;
    cin >> r >> c >> k;
    
    rep(i,k){
        int x,y,z;
        cin >> x >> y >> z;
        x--;y--;
        v[x][y]=z;
    }
    rep(i,r)rep(j,c){
       for(int k=2;k>=0;k--){
           chmax(dp[i][j][k+1],dp[i][j][k]+v[i][j]);
       } 
       rep(k,4){
           chmax(dp[i+1][j][0],dp[i][j][k]);
           chmax(dp[i][j+1][k],dp[i][j][k]);
       }
    }
    ll ans=0;
    rep(k,4) chmax(ans,dp[r-1][c-1][k]);
    cout << ans << endl;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    int n; cin >> n;
    vector<int> t(n + 1);
    vector<pair<int, int> > p(n + 1);
    t[0] = 0;
    p[0] = make_pair(0, 0);
    for(int i = 1; i < n + 1; i++){
        cin >> t[i];
        int x, y; cin >> x >> y;
        p[i] = make_pair(x, y);
    }

    bool flag = true;
    for(int i = 1; i < n + 1; i++){
        int tmp = t[i] - t[i - 1];
        int nx = abs(p[i].first - p[i - 1].first);
        int ny = abs(p[i].second - p[i - 1].second);
        if(tmp < nx || tmp < ny) {
            flag = false;
            break;
        }
        if(tmp % 2 != 0 && (nx + ny) % 2 != 0) continue;
        if(tmp % 2 == 0 && (nx + ny) % 2 == 0) continue;
        flag = false;
        break;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 1408
from math import gcd

N, M = map(int, input().split())
A = list(map(int, input().split()))
B = [a//2 for a in A]
LCM = 1
for i in range(N):
    LCM = LCM * B[i] // gcd(LCM, B[i])
for i in range(N):
    if LCM // B[i] % 2 == 0:
        print(0)
        exit()
print((M//LCM + 1)//2)

Measured memory_bytes: 91128
A, B, C, X, Y = list(map(int, input().split()))
a, b, c = X, Y, 0
if A + B > 2*C:
    tmp = min(a, b)
    a -= tmp
    b -= tmp
    c = 2*tmp

    if a > 0:
        if A > 2*C:
            c += 2*a
            a = 0
    elif b > 0:
        if B > 2*C:
            c += 2*b
            b = 0

print(a*A + b*B + c*C)


Measured memory_bytes: 3060
while True:
  try:
    xa, ya, xb, yb, xc, yc, xd, yd = map(float, input().split())
  except:
    break
  abx = xb - xa
  aby = yb - ya
  cdx = xd - xc
  cdy = yd - yc
  if abs(abx * cdx + aby * cdy) < 10**(-10):
    print("YES")
  else:
    print("NO")


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a*b/gcd(a, b);
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<ll> A(N);
    vector<ll> B(N);

    REP(i, N){
        cin >> A[i] >> B[i];
    }

    ll count = 0;
    ll button = 0;
    for(ll i= N-1; i>=0; i--){
        count = button + A[i];
        // cout << "count:" << count << " A[i]:" << A[i] <<  " B[i]:" << B[i] << endl;

        if(count % B[i] != 0){
            button += B[i] - (count % B[i]);
        }
        // cout << button << endl;
    }
    cout << button << endl;
    return 0;
}

Measured memory_bytes: 1920
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define p 998244353

int MOD(int a){
	a %= p;
	return a >= 0 ? a : a + p;
}

int power(int a, int N){
	if(N == 0){
		return 1;
	}
	else if(N % 2 == 0){
		return power(MOD(a * a), N / 2);
	}
	else{
		return MOD(a * power(a, N - 1));
	}
}

int inverse(int a){
	return power(a, p - 2);
}

signed main(){
	int N, i, j;
	char *S = (char *)malloc(sizeof(char) * 2002);
	scanf("%s", &S[1]);
	for(N = 0; S[N + 1] != '\0'; N++);
	int *R = (int *)malloc(sizeof(int) * (N + 1));
	int *B = (int *)malloc(sizeof(int) * (N + 1));
	R[0] = 0;
	B[0] = 0;
	for(i = 1; i <= N; i++){
		R[i] = R[i - 1];
		B[i] = B[i - 1];
		if(S[i] == '0'){
			R[i] += 2;
		}
		else if(S[i] == '1'){
			R[i] += 1;
			B[i] += 1;
		}
		else{
			B[i] += 2;
		}
	}
	int **dp = (int **)malloc(sizeof(int *) * (2 * N + 1));
	for(i = 0; i <= 2 * N; i++){
		dp[i] = (int *)malloc(sizeof(int) * (2 * N + 1));
		for(j = 0; j <= 2 * N; j++){
			dp[i][j] = 0;
		}
	}
	dp[0][0] = 1;
	for(i = 1; i <= 2 * N; i++){
		for(j = 0; j <= i; j++){
			if(i >= N || (j <= R[i] && i - j <= B[i])){
				dp[i][j] = MOD((j > 0 ? dp[i - 1][j - 1] : 0) + dp[i - 1][j]);
			}
		}
	}
	printf("%lld\n", dp[2 * N][R[N]]);
	return 0;
}

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

public class Solver
{
    public const int MaxType = 26;
    public int Days;
    public long[] Downs;
    public long[][] Scores;
    public void Init()
    {
        Days = int.Parse(Console.ReadLine());
        Downs = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        Scores = new long[Days][];
        for (int i = 0; i < Days; i++)
        {
            Scores[i] = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
    }

    public long CalcScore(int[] plan)
    {
        long score = 0;
        var last = new int[MaxType];
        for (int d = 1; d <= Days; d++)
        {
            var i = d - 1;
            var type = plan[i];
            last[type] = d;
            score += Scores[i][type];
            score -= last.Select((la, index) => Downs[index] * (d - la)).Sum();
        }

        return score;
    }

    public int[] Solve()
    {
        var plan = new int[Days];
        var last = new int[MaxType];
        for (int d = 1; d <= Days; d++)
        {
            var i = d - 1;
            var bestIndex = 0;
            var bestScore = long.MinValue;
            for (int t = 0; t < MaxType; t++)
            {
                var score = Scores[i][t];
                score -= last.Select((la, index) => Downs[index] * (index == t ? 0 : d - la)).Sum();
                if (bestScore < score)
                {
                    bestIndex = t;
                    bestScore = score;
                }
            }
            Console.Error.WriteLine(bestScore);
            plan[i] = bestIndex;
            last[bestIndex] = d;
        }

        return plan;
    }

}

public static class Solution
{
    public static void Main()
    {
        var solver = new Solver();
        solver.Init();
        var answer = solver.Solve();
        Console.WriteLine(string.Join(Environment.NewLine, answer.Select(i => i + 1)));
    }
}

Measured memory_bytes: 30716
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector as V

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n,m,k] <- getIntList
    print . sumMod $ map (\i -> mulMod (comb (n-1) i) (mulMod m  (powerMod (m-1) (n-1-i)))) [0..k]
    
moduloN :: Int
moduloN = 998244353

modN = flip mod moduloN

finv :: Int -> Int
finv k = finvs V.! k
    where finvs :: V.Vector Int
          finvs = V.generate (2 * 10 ^ 5 + 1) finv'
              where finv' 0 = 1
                    finv' n = modN $ finvs V.! (n - 1) * inv n

inv :: Int -> Int
inv k = invs V.! k
    where inv' 1 = 1
          inv' n = modN (-(invs V.! r) * q)
              where (q, r) = moduloN `divMod` n
          invs :: V.Vector Int
          invs = V.generate (2 * 10 ^ 5 + 1) inv'

fact :: Int -> Int
fact k = facts V.! k
    where fact' 0 = 1
          fact' n = modN $ n * (facts V.! (n - 1))
          facts :: V.Vector Int
          facts = V.generate (2 * 10 ^ 5 + 1) fact'

comb :: Int -> Int -> Int
comb n k | n < 0 || k < 0 || n < k = 0
         | otherwise = modN $ modN (fact n * finv k) * finv (n - k)

plusMod x y = modN $ x + y
sumMod xs = foldl' plusMod 0 xs

mulMod x y = modN $ x * y

powerMod x 0 = 1
powerMod x y
    | even y = mulMod t t
    | otherwise = mulMod x $ mulMod t t
    where
        t = powerMod x $ div y 2

Measured memory_bytes: 33156
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mx2 102
#define mx3 1003
#define mx4 10004
#define mx5 100005
#define mx6 1000006
#define mod 1000000007
#define PI 3.14159265
#define fo(i,n) for(int i=0 ; i<n ; i++)
#define Fo(i,k,n) for(int i=k ; i<n ; i++)
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pair<int,int>,int> piii;

int n , ans , sum , a , b ,arr[mx5];
string str;
 
int main() {
	ios::sync_with_stdio(false);
	//int t;cin>>t;while(t--)
	{
		cin>>n;
		
		if(n%2==0)
		{
			
			printf("%.6f",(float)1/2);
		}
		else
		{
			float a = (n/2+1)/(float)(n);
			printf("%.6f",a);
		}
	}
	return 0;
}


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

#define N 10010
int n, a[N], b[N];
bool isprime(int x) {
	for (int i = 2; 1ll * i * i <= x; ++i) {
		if (x % i == 0) {
			return false;
		}
	}
	return true;
}
int gcd(int a, int b) {
	return b ? gcd(b, a % b) : a;
}
bool ok(int p) {
	if (a[0] % p) {
		return false;
	}
	for (int i = 0; i <= n; ++i) {
		b[i] = a[i];
	}
	for (int i = n; i >= p - 1; --i) {
		(b[i - (p - 1)] += b[i]) %= p;
		b[i] = 0;
	}
	for (int i = 0; i <= n; ++i) {
		if (b[i] % p) {
			return false;
		}
	}
	return true;
}

int main() {
	while (scanf("%d", &n) != EOF) {
		int G = 0; 
		for (int i = 0; i <= n; ++i) {
			scanf("%d", a + i);
			G = gcd(G, abs(a[i]));
		}
		reverse(a, a + 1 + n); 
		vector <int> res;
		for (int i = 2; 1ll * i * i <= G; ++i) {
			if (G % i == 0) {
				res.push_back(i); 
				while (G % i == 0) {
					G /= i;
				}
			}
		}
		if (G > 1) {
			res.push_back(G);
		}
		for (int i = 2; i <= n; ++i) {
			if (isprime(i) && ok(i)) {
				res.push_back(i);
			}
		}
		sort(res.begin(), res.end());
		res.erase(unique(res.begin(), res.end()), res.end());
		for (auto it : res) {
			printf("%d\n", it);
		}
	//	puts("------------");
	}
	return 0;
}


Measured memory_bytes: 384