akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppll pair <pll, pll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#pragma 03
using namespace std;
using namespace __gnu_pbds;
ll dp[1000005][2];
int main(){
	string n; cin >> n;
	n.pb(0); reverse(n.begin(), n.end());
	dp[0][0] = 0;
	dp[0][1] = 11;
	for (ll i = 1; i<n.length(); i++){
		ll cur = n[i] - '0';
		dp[i][1] = min(dp[i-1][1] + 9 - cur, dp[i-1][0] + 11 - cur);
		dp[i][0] = min(dp[i-1][1] + cur, dp[i-1][0] + cur);
	}
	cout << min(dp[n.length() - 1][0], dp[n.length() - 1][1]);
}

Measured memory_bytes: 17028
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  string X;
  cin >> X;
  int SCount = 0;
  int ans = X.size();
  for (char c : X)
  {
    if (c == 'S')
      SCount++;
    else if (c == 'T' && SCount > 0)
    {
      SCount--;
      ans -= 2;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
N = int(input())
a = list(map(int,input().split()))
S = 1000
K = 0
b = 1
last = 0
			
for i in range(N):
	if i != N-1:
		if a[i]<=a[i+1]:
			S += a[i]*K
			K = S // a[i]
			S -= K*a[i]

		else:
			S += a[i]*K
			K = 0
	else:

		S += a[i]*K
print(S)


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

int main(){
    int L, R, ans=2e9, tmp;
    vector<int> v(3000, 0);
    cin >> L >> R;

    if(R-L >3000){
	cout << 0<<endl;
	return 0;	
    }

    for(int i=L; i<=R; i++){
	tmp = i%2019;
	v[tmp]++;
    }

    for(int i=0; i<=2019; i++){
    	for(int j=0; j<=2019; j++){
	    if(v[i]==0 || v[j]==0)
		continue;
	    else if(i==j && v[i]==1)
		continue;
    	    tmp = (i*j)%2019;
    	    ans = min(ans, tmp);
    	}	
    }
    cout << ans << endl;
}




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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n;
  cin >> n;
  
  ll ans = 0, now = 0;
  for (ll i = 1; i <= n; i++) {
    now += i;
    ans += now;
  }
  //cout << ans << endl;
  
  for (int i = 0; i < n - 1; i++) {
    ll u, v;
    cin >> u >> v;
    if (u > v) swap(u, v);
    ans -= u * (n - v + 1);
    //cout << ans << endl;
  }
  
  cout << ans << '\n';
}

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

const int maxV=51;
int dp[maxV][maxV][maxV*maxV];

signed main(){
	int n,a;cin>>n>>a;
	vector<int> x(n);
	for(auto&& w:x)cin>>w;

	fill(dp[0][0],dp[maxV][0],0);
	dp[0][0][0]=1;

	for(int i=0;i<n;i++){
		for(int j=0;j<=i;j++){
			for(int s=0;s<maxV*maxV;s++){
              if(dp[i][j][s]==0)continue;
				dp[i+1][j][s]+=dp[i][j][s];
				dp[i+1][j+1][s+x[i]]+=dp[i][j][s];
			}
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)ans+=dp[n][i][i*a];
	cout<<ans<<endl;

}

Measured memory_bytes: 53120
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>

using namespace std;

int main()
{
    int A, B, T;
    cin >> A >> B >> T;
    int z = A+B+T;
    if(z >= 22)
    {
        cout << "bust" << endl;
    }
    else
    {
        cout << "win" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int n,S[10000],q,T[500],C,i,j;
    
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&S[i]);
    }
    scanf("%d",&q);
    for(i=0;i<q;i++)
    {
        scanf("%d",&T[i]);
    }
    
    C=0;
    for(i=0;i<q;i++)
    {
        for(j=0;j<n;j++)
        {
            if(T[i]==S[j])
            {
                C++;
                break;
            }
        }
    }
    
    printf("%d\n",C);
    
    return 0;
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	string s; cin>>s;
	string t=s;
	int n=s.size();
	reverse(all(t));
	if(n%2==1){
		n++;
	}
	int ans=0;
	rep(i,0,n/2){
		if(s[i]!=t[i]){
			++ans;
		}
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define F               first
#define S               second
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18 + 1
#define endl            '\n'
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define forI(i,a,n)     for(int i=a;i<=n;i++)
#define forD(i,a,n)     for(int i=n;i>=a;i--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
void init(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

void solve(){
    int N, W;   cin>>N>>W;
    pii wv[N+1];    forI(i, 1, N) cin>>wv[i].ff>>wv[i].ss;

    int V = N*1000, dp[N+1][V+1];

    forI(i, 0, V)   dp[1][i] = inf;
    dp[1][0] = 0;
    dp[1][wv[1].ss] = wv[1].ff;

    forI(i, 2, N){
        forI(j, 0, V){
            dp[i][j] = dp[i-1][j];
            if(wv[i].ss > j)    continue;
            dp[i][j] = min(dp[i][j], wv[i].ff + dp[i-1][j - wv[i].ss]);
        }
    }

    int ans = 0;
    forI(i, 0, V)   if(dp[N][i] <= W)   ans = i;

    cout<<ans<<endl;
}

int32_t main(){
    init();
    // w(t) 
    solve();
    return 0;
}

Measured memory_bytes: 81744
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>
#include <type_traits>

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define all(n) std::begin(n), std::end(n)
#define rall(n) std::rbegin(n), std::rend(n)
#define debug(var) std::cout << #var << ": " << var << "\n"
using Int = int64_t;
constexpr Int INF = INT_MAX;
constexpr Int mod = 1e9 + 7;


void init() {
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
}

void calc() {

	Int A, B, C; std::cin >> A >> B >> C;
	std::cout << std::min(B / A, C);

}


int main() {

	init();
	calc();

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		System.out.println(z + " " + x + " " + y);
	}
}


Measured memory_bytes: 23252
# coding: utf-8
import sys

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))


def main():
    n = ni()%10
    if n in [2,4,5,7,9]:
        print('hon')
    elif n in [0,1,6,8]:
        print('pon')
    else:
        print('bon')
    return


if __name__ == '__main__':
    main()

Measured memory_bytes: 61680
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var N = Sarray()[0];
            var si = new long[N];
            for (var i = 0; i < N; ++i)
                si[i] = Sarray()[0];
            var ans = si.Sum();
            if (ans % 10 == 0)
            {
                var m = si.Where(s => s % 10 != 0);
                if (m.Count() != 0)
                    ans -= m.Min();
                else
                    ans = 0;
            }
            WriteLine(ans);
        }


        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 28312
#include <bits/stdc++.h>
#define inf 1000000000 //1E+9
#define mod 1000000007
using namespace std;

int main(){
	int n;cin>>n;
	int a[n];for(int i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	cout<<a[n-1]<<" ";

	double M=double(a[n-1])/2.0;
	double m=inf;
	for(int i=0;i<n;i++){
		if(abs(M-double(a[i])) < m) m=abs(M-double(a[i]));
		else{cout<<a[i-1]<<endl;return 0;}
	}

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());




int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    string x;
    cin >> x;
    if(x[2] == x[3] && x[4] == x[5])cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int n,m,x;
	int a[103];
	int cost;
	scanf("%d%d%d",&n,&m,&x);
	for (cost = 0; cost < m; ++cost)
	{
	  scanf("%d",&a[cost]);
		if(a[cost] > x)	break;
	}
	printf("%d\n", (cost < m - cost) ? cost : m - cost);
	return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int k, t; cin>>k>>t;
    int asum = 0, amax = 0;
    for(int i=0; i<t; i++){
        int a; cin>>a;
        asum += a;
        chmax(amax, a);
    }
    asum -= amax;

    cout << max(0, amax - 1 - asum) << endl;

    return 0;
}

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

typedef pair<int,int> P;

#define INF P(999999, 999999)

int N, D;
int p[100][100];
int rev[100][100];
P dp[100][100];

void solve(){
  memset(rev, -1, sizeof(rev));
  for(int i = 0; i <= D; i++){
    for(int j = 0; j <= N; j++){
      dp[i][j] = INF;
    }
  }

  dp[D][N] = P(0, 0);

  for(int i = D; i > 0; i--){
    for(int j = 0; j <= N; j++){
      if(dp[i][j] == INF) continue;

      for(int k = 0; k < N; k++){
        P np = dp[i][j];
        np.first += p[i - 1][k];
        np.second += (k != j);

        if(dp[i - 1][k] > np){
          dp[i - 1][k] = np;
          rev[i - 1][k] = j;
        }
      }
    }
  }

  int sj = 0;

  for(int j = 0; j < N; j++){
    if(dp[0][sj] > dp[0][j]){
      sj = j;
    }
  }

  cout << dp[0][sj].first << " " << dp[0][sj].second - 1 << endl;

  for(int i = 0; i < D; i++){
    cout << sj + 1 << endl;
    sj = rev[i][sj];
  }
}

int main(){
  while(cin >> N >> D){
    for(int i = 0; i < N; i++){
      for(int j = 0; j < D; j++){
        cin >> p[j][i];
      }
    }
    solve();
  }
}

Measured memory_bytes: 1312
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define all_acc(x) (x).begin(),(x).end(),0LL
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;

int accumulate(int* a,int n){
    return accumulate(a,a+n,0LL);
}

int accumulate(vector<int> a){
    return accumulate(a.begin(),a.end(),0LL);
}

signed main(){ 
   int a;
   cin>>a;

   cout<<a+pow(a,2)+pow(a,3)<<endl; 
}  

Measured memory_bytes: 4228
#include"stdio.h"
#include"stdlib.h"

int partition(int *A,int p,int r)
{
  int x=A[r];
  int i=p-1;
  int j;
  int buf;
  for(j=p;j<r;j++)
    {
      if(A[j]<=x)
        {
          i++;
          buf=A[i];
          A[i]=A[j];
          A[j]=buf;
        }
    }
  buf=A[i+1];
  A[i+1]=A[r];
  A[r]=buf;
  return i+1;
}
int main()
{
  int n;
  int *A;
  int i;
  int k;
  scanf("%d",&n);
  A=(int*)malloc(sizeof(int)*n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }
  k=partition(A,0,n-1);
  if(k==0)
    {
      printf("[%d]",A[0]);
    }
  else printf("%d",A[0]);
  for(i=1;i<n;i++)
    {
      if(i==k)
        {
          printf(" [%d]",A[i]);
        }
      else printf(" %d",A[i]);
    }
  printf("\n");
}


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

using namespace std;

typedef long long ll;

int N;
ll T[1001],A[1001];

int main() {
  cin >> N;

  for(int i = 0; i < N; i++) cin >> T[i] >> A[i];

  for(int i = 1; i < N; i++) {
    if(T[i-1] <= T[i] && A[i-1] <= A[i]) continue;
    else if(T[i-1] > T[i] && A[i-1] <= A[i]) {
      ll tmp = 0;
      if(T[i-1] % T[i] != 0) tmp++;
      tmp += T[i-1] / T[i];
      T[i] *= tmp;
      A[i] *= tmp;
   
    }
    else if(A[i-1] > A[i] && T[i-1] <= T[i]) {
      ll tmp = 0;
      if(A[i-1] % A[i] != 0) tmp++;
      tmp += A[i-1] / A[i];
      T[i] *= tmp;
      A[i] *= tmp;
    }
    
    else {
      if(T[i-1] / T[i] > A[i-1] / A[i]) {
	ll tmp = 0;
	if(T[i-1] % T[i] != 0) tmp++;
	tmp += T[i-1] / T[i];
	T[i] *= tmp;
	A[i] *= tmp;
      }
      else {
	ll tmp = 0;
	if(A[i-1] % A[i] != 0) tmp++;
	tmp += A[i-1] / A[i];
	A[i] *= tmp;
	T[i] *= tmp;
      }
    }
  }
  cout << T[N-1] + A[N-1] <<endl;
}
       


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

#define MAX_N 100000
typedef long long int ll;

ll a[MAX_N];

ll solv(int n) {
  if(n == 1) return a[0];

  for (int i = 1; i < n; ++i) {
    a[i] = a[i] % a[0];
  }
  std::sort(a, a + n);
  int zeroCount = 0;
  for (int i = 0; i < n; ++i) {
    if(a[i] == 0) zeroCount++;
  }
  n -= zeroCount;
  for (int i = 0; i < n; ++i) {
    a[i] = a[i + zeroCount];
  }

  return solv(n);
}

int main() {
  int n;

  std::cin >> n;
  for(int i = 0; i < n; ++i) std::cin >> a[i];
  std::sort(a, a + n);

  std::cout << solv(n) << std::endl;
  return 0;
}

Measured memory_bytes: 1024
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	H, W := sc.nextInt(), sc.nextInt()
	if H%3 == 0 || W%3 == 0 {
		fmt.Println(0)
		return
	}
	ans := divide(H, W)
	ans2 := divide(W, H)
	fmt.Println(min(ans, ans2))
}

func divide(h, w int) int {
	var dividePoint, rec1, rec2, rec3 int
	if h%3 == 1 {
		dividePoint = h / 3
	} else {
		dividePoint = h/3 + 1
	}
	rec1 = w * dividePoint
	rec2, rec3 = divideToTwo(h-dividePoint, w)
	ans := max(rec1, rec2, rec3) - min(rec1, rec2, rec3)
	rec2, rec3 = divideToTwo(w, h-dividePoint)
	ans2 := max(rec1, rec2, rec3) - min(rec1, rec2, rec3)
	return min(ans, ans2)
}

func divideToTwo(h, w int) (int, int) {
	total := h * w
	if h%2 == 0 {
		return total / 2, total / 2
	}
	rec := h * (w / 2)
	return rec, total - rec
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const double pi=acos(-1);

int main(){
  rep(i,MOD){
    int m,f,r;
    cin >> m >> f >> r;
    if(m==-1 && f==-1){
      return 0;
    }
    else if(m==-1 || f==-1){
      cout << 'F' << endl;
    }
    else{
      if(m+f>=80) cout << 'A' << endl;
      else if(m+f>=65) cout << 'B' << endl;
      else if(m+f>=50) cout << 'C' << endl;
      else if(m+f>=30){
        if(r>=50) cout << 'C' << endl;
        else cout << 'D' << endl;
      }
      else cout << 'F' << endl;
    }
  }
      
  return 0;

      
}



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

int main(){
    string S; cin >> S;
    int cntg = 0, cntp = 0, ans = 0;

    int N = S.size();
    for(int i = 0; i < N; i++){
        if(S[i] == 'g'){
            if(cntp < cntg){
                ans++;
                cntp++;
            }else{
                cntg++;
            }
        }else{
            if(cntp < cntg){
                cntp++;
            }else{
                ans--;
                cntg++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
N = int(input())
X = list(map(int, input().split()))

argsort = [[x, i] for i, x in enumerate(X)]
argsort.sort()

indices = {(i + 1): x for i, (x, _) in enumerate(argsort)}

argsort = [[i, j] for j, [_, i], in enumerate(argsort)]
argsort.sort()

ranks = [j + 1 for _, j in argsort]

median = N // 2
for i in range(0, N):
    r = ranks[i]
    if r <= median:
        print(indices[median + 1])
    else:
        print(indices[median])


Measured memory_bytes: 119608
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt(); //跳ねる回数
		int X = sc.nextInt(); //領域

    int total = 0;
    int ans = 1;
    for(int i = 0; i < N; i++){
      total += sc.nextInt();
      if(total > X){
        break;
      }
      ans++;
    }

    System.out.println(ans);
	}
}

Measured memory_bytes: 23124
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <math.h>

typedef struct {
    int64_t A;
    int64_t B;
    int64_t s;
} dish_t;

int compare (const void *a, const void *b)
{
    if(((dish_t *)a)->s - ((dish_t *)b)->s < 0)
        return 1;
    if(((dish_t *)a)->s - ((dish_t *)b)->s > 0)
        return -1;
    return 0;
}

int main (int argc, char const *argv[])
{
    int64_t N;
    dish_t dish[(int)1e5];
    int64_t i, takahashi = 0, aoki = 0;

    scanf("%"PRId64, &N);

    for (i = 0; i < N; i++) {
        scanf("%"PRId64"%"PRId64, &dish[i].A, &dish[i].B);
        dish[i].s = dish[i].A + dish[i].B;
    }

    qsort(dish, N, sizeof(dish_t), compare);

    for (i = 0; i < N; i++) {
        if (i % 2) { /* 青木さん食べる */
            aoki      += dish[i].B;
        } else { /* 高橋くん食べる */
            takahashi += dish[i].A;
        }
    }

    printf("%"PRId64"\n", takahashi - aoki);
}


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

#define int long long
#define pb push_back
#define f first
#define s second
#define all(container) container.begin(),container.end()

#define fast ios::sync_with_stdio(0); cin.tie(0)
#define print(...) __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1> void __f(const char* name, Arg1&& arg1){
    cout << name << ": " << arg1 << '\n';
}

template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

int32_t main(){
    
    fast;
    int n; cin >> n;

    int ans = (n*(n-1))/2;

    cout << ans << '\n';
    
 
    return 0;
} 

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

int main()
{
    i64 n, m, c;
    cin >> n >> m >> c;
    vector<i64> B(m);
    for (i64 i = 0; i < m; i++)
        cin >> B[i];
    vector<vector<i64>> a(n, vector<i64>(m));
    for (i64 i = 0; i < n; i++)
        for (i64 j = 0; j < m; j++)
            cin >> a[i][j];
    i64 ans = 0;
    for (i64 i = 0; i < n; i++)
    {
        i64 tmp = c;
        for (i64 j = 0; j < m; j++)
            tmp += a[i][j] * B[j];
        if (0 < tmp)
            ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from collections import deque
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

ans=deque()
used=[0]*(10**6)
n,m=map(int,input().split())
data=reversed([int(input()) for i in range(m)])
for  di in data:
    if not used[di]:
        ans.append(di)
    used[di]=1
plusans=[i for i in range(1,n+1) if not  used[i]]
ans+=plusans
for i in ans:
    print(i)





Measured memory_bytes: 23760
#include <iostream>
#include <algorithm>
#define INF 2000000000
using namespace std;

int dp[1010][1010];//[M??\??????][N??????]?????´???
int dst[1010];
int sky[1010];

int main(){
	int N,M;//N+1????????°M??\??°
	cin>>N>>M;
	for(int i=0;i<N;i++){
		cin>>dst[i];
	}
	for(int i=0;i<M;i++){
		cin>>sky[i];
	}
	for(int i=0;i<=M;i++){
		for(int j=0;j<=N;j++){
			dp[i][j]=INF;
		}
	}
	dp[0][0]=0;

	for(int i=0;i<M;i++){
		for(int j=0;j<N;j++){
			if(dp[i][j]!=INF){
				dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
				dp[i+1][j+1]=dp[i][j]+sky[i]*dst[j];
			}
		}
		dp[i+1][N]=min(dp[i+1][N],dp[i][N]);
	}
	cout<<dp[M][N]<<endl;
	return 0;

}

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

using namespace std;

string s;
long long i;

int main()
{
    cin >> s;
    for (i ; i < s.size() ; i++) {
        if (i%2==0 and s[i]=='L'){
            cout<<"No";
            return 0;
        }
        if (i%2==1 and s[i]=='R'){
            cout<<"No";
            return 0;
        }
    }
    cout << "Yes";
}


Measured memory_bytes: 256
fun main(args : Array<String>) {
    val num = readLine()!!.toInt()

    val ans = num.toString().toCharArray().map {
        if (it == '1') {
            '9'
        } else if (it == '9') {
            '1'
        } else {
            it
        }
    }.joinToString("")

    println(ans)
}


Measured memory_bytes: 31900
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(vector<T> &x) {
	int n = x.size();
	rep(i,n) {
		cout << x[i];
		if (i!=n-1) cout<<" ";
		else cout << endl;
	}
}

template<typename T>
void print(vector<vector<T>> &x) {
	int n = x.size();
	rep(i,n) {
		rep(j,x[i].size()) {
			cout << x[i][j] << " ";
		}
		cout << endl;
	}
}

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


int main(int argc, char const *argv[]) {
	int n,m; cin>>n>>m;
	vector<ll> a(n);
	vector<P> b(m);
	rep(i,n) cin>>a[i];
	sort(a.begin(), a.end());
	rep(i,m) cin>>b[i].second>>b[i].first;
	sort(b.begin(), b.end(), greater<>());

	int ind = 0;
	ll ans = 0;

	rep(i,n) {
		if (a[i] < b[ind].first) {
			ans += b[ind].first;
			if (--b[ind].second <= 0) ++ind;
		}
		else ans += a[i];
	}

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

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

long long int gcd(long long int , long long int);
long long int gcd(long long int [], long long int);

//最大公約数を求める(二変数)
long long int gcd(long long int a, long long int b){
    long long int r;
    while(1){
        if(a < b){
            long long int tmp = a;
            a = b;
            b = tmp;
        }
        r = a % b;
        if(r == 0){
            return b;
        }
        a = r;
    }
}

//最大公約数を求める(多変数)
long long int gcd(long long int a[], long long int size){
    long long int x = a[0];
    for(long long int i=1; i<size; i++){
        x = gcd(x, a[i]);
    }
    return x;
}

int main(){
    int N;
    long long int xList[100000] = {0};
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> xList[i];
    }
    cout << gcd(xList, N);
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {

	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		Arrays.sort(arr);
		long a = 0;
		long b = 0;
		for (int i = n - 1; i > 0; i--) {
			if (arr[i] == arr[i - 1]) {
				if (a == 0) {
					a = arr[i];
					i -= 1;
				} else {
					b = arr[i];
					break;
				}
			}
		}
		System.out.println(a * b);
	}
}


Measured memory_bytes: 47628
N = gets.to_i
A = Array.new(N)
X = []
N.times do |i|
    A[i] = gets.to_i
    X.push i+1 if A[i] == 2
end
if X.empty? then
    puts '-1'
    exit
end
button = 1
num = 0
th = 10**5
loop do
    num += 1
    before = button
    button = A[button-1]
    break if button == 2
    if num >= th || before == button then
        num = -1
        break
    end
end
puts num

Measured memory_bytes: 2812
alp=["a", "b", "c", "d" ,"e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q","r", "s", "t", "u", "v", "w", "x", "y", "z"]

s=input()
l=len(s)

for i in range(l):
    if s[i] in alp:
        alp.remove(s[i])

if len(alp)==0:
    print("None")
else:
    print(alp[0])


Measured memory_bytes: 9056
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  string s;
  cin>>s;
  for(char c='a';c<='z';c++){
    if(count(s.begin(),s.end(),c)) continue;
    cout<<c<<endl;
    return 0;
  }
  cout<<"None"<<endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>

using namespace std;
int main(){

    int n,count=0,temp=0;
    char cc;
    cin>>n;
    
    
    string s1;
    cin>>s1;

    for (int i = 0; i < n-2; i++)
    {
        if (s1[i] == 'A')
        {
            if (s1[i+1] == 'B')
            {
                if (s1[i+2] == 'C')
                {
                    //cout<<"hi"<<endl;
                    count++;
                }
                
            }
            
        }
        
        
    }

    
    
    
    
    
    cout<<count;
    

}

Measured memory_bytes: 256
x = gets.strip.to_i
if    x < 600 then ans = 8
elsif x < 800 then ans = 7
elsif x < 1000 then ans = 6
elsif x < 1200 then ans = 5
elsif x < 1400 then ans = 4
elsif x < 1600 then ans = 3
elsif x < 1800 then ans = 2
else ans = 1
end
p ans


Measured memory_bytes: 14332
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;
#define ll long long
#define pb push_back

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  
  cout << (a*b)/2 << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main(){
	while (1){
		queue<int> q;
		map<int,lint> m;
		bool f[4010] = {};
		int n;
		cin >> n;
		if (n == 0) break;
		int a, b, c;
		rep(i, 0, n){
			cin >> a >> b >> c;
			q.push(a);
			m[a] += (lint)b*c;
		}
		int ct = 0;
		while (!q.empty()){
			int x = q.front(); q.pop();
			if (m[x] >= 1000000 && f[x]==0){
				o(x); ct++; f[x] = 1;
			}
		}
		if (ct == 0){
			o("NA");
		}
	}

}

Measured memory_bytes: 1284
def num_ways_for_sum(target, elems, start_idx, end_idx, cache):
    if start_idx > end_idx:
        if target == 0:
            return 1
        else:
            return 0

    cur_ways = 0
    cache_key = (target, start_idx, end_idx)
    if cache_key in cache:
        cur_ways = cache[cache_key]
    else:
        cur_ways += num_ways_for_sum(target + elems[start_idx], elems, start_idx + 1, end_idx, cache)
        cur_ways += num_ways_for_sum(target, elems, start_idx + 1, end_idx, cache)
        cache[cache_key] = cur_ways
    return cur_ways

if __name__ == '__main__':
    n, a = list(map(int, input().split(' ')))
    xs = list(map(int, input().split(' ')))
    diffs = []
    for x in xs:
        diffs.append(x - a)

    print(num_ways_for_sum(0, diffs, 0, len(xs) - 1, {}) - 1)

Measured memory_bytes: 5604
#include <stdio.h>
#include <math.h>
#define N_MAX 10000

int isPrime(int x)
{
  int i;
  if (x <= 3) {
    return 1;
  } else if (x % 2 == 0) {
    return 0;
  } else {
    for (i = 3; i <= sqrt(x); i = i + 2) {
      if (x % i == 0) {
        return 0;
      }
    }
    return 1;
  }
}

int main(int argc, char *argv[])
{
  int i, j, n, x;
  int answer = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &x);
    answer = answer + isPrime(x);
  }
  printf("%d\n", answer);
  return 0;
}


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

using ll = long long;
// #define int long long

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))

bool IsPrime(int);
int Factorial(int);
int NPR (int, int);
int NCR (int, int);

/***** MAIN *****/
signed main() {
  string s;
  cin >> s; 
  int sLen = s.length();
  int ans = 0;
  REP(i,sLen/2) {
    if(s[i] != s[sLen - 1 - i]) ans++;
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/

bool IsPrime(int a) {
  if(a <= 1) return false;
  if(a == 2) return true;
  if(a%2 == 0) return false;
  for(int i = 3; i*i <= a; i+=2) {
    if(a%i==0) return false;
  }
  return true;
}

int Factorial(int n){
  int ans = 1;
  while(n > 1){
    ans *= n;
    --n;
  }
  return ans;
}

int NPR(int n, int r) {
  return Factorial(n)/Factorial(n-r);
}

int NCR (int n, int r){
  return NPR(n,r)/Factorial(r);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		int ttl[] = new int[6];
		
		ttl[0] = Math.abs(a-b);
		ttl[0] = ttl[0] + Math.abs(b-c);
		ttl[1] = Math.abs(a-c);
		ttl[1] = ttl[1] + Math.abs(c-b);
		ttl[2] = Math.abs(b-a);
		ttl[2] = ttl[2] + Math.abs(a-c);
		ttl[3] = Math.abs(b-c);
		ttl[3] = ttl[3] + Math.abs(c-a);
		ttl[4] = Math.abs(c-a);
		ttl[4] = ttl[4] + Math.abs(b-c);
		ttl[5] = Math.abs(c-b);
		ttl[5] = ttl[5] + Math.abs(b-a);
		
		int min = ttl[0];
		for(int i=0; i<5; i++){
			if (min > ttl[i]){
				min = ttl[i];
			}
		}
		
		
		System.out.println(min);
		
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>

typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
  
using namespace std;
 
const ll inf = 1e18;
const ll N = 3e5;
const ll bits = 20;
const ld pi = 3.14159265358979323846;
const ll mod = 1e9+7;
const ll p = 29;

int main(){

    FASTIO;
    PRECISION; 
    
    int n,m;
    cin>>n>>m;

    vector<int>dp(n+2,0);

    for(int i=0;i<m;i++){
        int l,r;
        cin>>l>>r;
        dp[l]++;
        dp[r+1]--;
    }
    int ans = 0;
    for(int i=1;i<=n;i++){
        dp[i]+=dp[i-1];
        if(dp[i]==m) ans++;
    }
    cout<<ans<<"\n";
}


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

public class Main {
	public static void main(String[] args) {
		FastScanner fs = new FastScanner();
		int x = fs.nextInt();
		int n = fs.nextInt();
		ArrayList<Integer> array = new ArrayList<>();
		array.add(x);
		for (int i = 1; i <= n / 2 + 1; i++) {
			array.add(x - i);
			array.add(x + i);
		}
		for (int i = 0; i < n; i++) {
			array.remove((Integer) fs.nextInt());
		}

		System.out.println(array.get(0));
	}

}

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: 32464
var n,i:Longint;
s,a:int64;
function gcd(a,b:int64):int64;
begin
if b=0 then gcd:=a else gcd:=gcd(b,a mod b);
end;
begin
read(n);
s:=1;
for i:=1 to n do begin
read(a);
s:=s div gcd(s,a)*a;
end;
writeln(s);
end.

Measured memory_bytes: 128
def main():
    N, K = map(int, input().split())
    A = [1] + list(map(int, input().split()))
    for i in range(K+1, N+1):
        if A[i] > A[i-K]:
            print("Yes")
        else:
            print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 31660
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e10
using namespace std;
typedef pair<ll, ll> P;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

ll gcd(ll a, ll b) {
	if (b > a) {
		ll tmp = b;
		b = a;
		a = tmp;
	}
	if (a%b == 0)return b;
	else return gcd(b, a%b);
}

int main(void){
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	cout << H * W - h*W - w*H + h*w << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())

C = []
S = []
F = []

for i in range(N - 1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)


def next(s, t):
    # 始発
    if t < S[s]:
        t = S[s]

    # タイムラグ
    elif t % F[s]:
        t += F[s] - t % F[s]

    # 列車の移動時間
    t += C[s]

    return t


def main():
    # 出発駅
    for i in range(N - 1):
        t = next(i, 0)

        # 途中駅
        for j in range(i + 1, N - 1):
            t = next(j, t)

        print(t)

    print(0)

    return


main()


Measured memory_bytes: 3188
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "YES"; }
  string_type do_falsename() const { return "NO"; }
};

template <typename Cost>
struct Edge {
  int from, to;
  Cost cost;
  Edge(int s, int t, Cost c) : from(s), to(t), cost(c) {}
};

template<typename Cost> using Graph = vector<vector<Edge<Cost>>>;

template <typename Cost>
void add_edge(Graph<Cost> &g, int from, int to, Cost cost) {
  g[from].emplace_back(from, to, cost);
}

template <typename Cost>
vector<Cost> dijkstra(const Graph<Cost> &g, int s, Cost zero = 0) {
  vector<Cost> d(g.size(), ll(1e18));
  d[s] = zero;
  using P = pair<Cost,int>;
  priority_queue<P, vector<P>, greater<P>> que;
  que.push(P(zero, s));
  while (!que.empty()) {
    Cost dist = que.top().first;
    int v = que.top().second;
    que.pop();
    if (d[v] < dist) continue;
    for (const auto &e: g[v]) {
      if (d[e.to] <= d[v] + e.cost) continue;
      d[e.to] = d[v] + e.cost;
      que.push(P(d[e.to], e.to));
    }
  }
  return d;
}

void solve(ll N, vector<ll> a, vector<ll> b, vector<ll> c, ll Q, ll K, vector<ll> x, vector<ll> y) {
  Graph<ll> g(N);
  REP(i,N-1) {
    add_edge(g, a[i] - 1, b[i] - 1, c[i]);
    add_edge(g, b[i] - 1, a[i] - 1, c[i]);
  }
  auto dist = dijkstra(g, K - 1);
  REP(i,Q) {
    int s = x[i] - 1, t = y[i] - 1;
    cout << dist[s] + dist[t] << endl;
  }
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll Q;
	ll N;
	ll K;
	scanf("%lld", &N);
	vector<ll> a((N-1)-1+1);
	vector<ll> b((N-1)-1+1);
	vector<ll> c((N-1)-1+1);
	for (int i = 0 ; i <= (N-1)-1 ; i++) {
	  scanf("%lld", &a[i]);
	  scanf("%lld", &b[i]);
	  scanf("%lld", &c[i]);
	}
	scanf("%lld", &Q);
	vector<ll> x(Q-1+1);
	vector<ll> y(Q-1+1);
	scanf("%lld", &K);
	for (int i = 0 ; i <= Q-1 ; i++) {
	  scanf("%lld", &x[i]);
	  scanf("%lld", &y[i]);
	}
	solve(N, a, b, c, Q, K, x, y);
	return 0;
}


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

namespace AtCoderExamCS
{
    class Program
    {
        static void Main(string[] args)
        {
            int N, answer = 0;

            N = int.Parse(Console.ReadLine());
            for (int i = 1; i <= 10; i++)
            {
                if (N == 0)
                {
                    break;
                }
                if (N <= i * 1000)
                {
                    answer = i * 1000 - N;
                    break;
                }
            }

            Console.WriteLine(answer);
        }
    }
}


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

int main(void){
    int N;
    cin >> N;
    int ans = 0;
    int n = -1;
    int m = 1000000000;
    for(int i = 0; i < N; i++){
        int H;
        cin >> H;
        if(H <= m){
            m = H;
            n++;
            ans = max(ans, n);
        }else{
            m = H;
            n = 0;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;


long long search(int max_val, int num, vector<int>& a, vector<int>& b, vector<int>& c, vector<int>& d, vector<int> tmp, int cursor) {
  if (cursor == num) {
    long long score = 0;
    for (int i = 0; i < a.size(); ++i) {
      if (tmp[b[i] - 1] - tmp[a[i] - 1] == c[i])
        score += d[i];
    }
    return score;
  } else {
    long long score = 0;
    int i;
    if (tmp.size() == 0)
      i = 1;
    else
      i = tmp.back();
    for (; i <= max_val; ++i) {
      vector<int> new_tmp = tmp;
      new_tmp.push_back(i);
      score = max(score, search(max_val, num, a, b, c, d, new_tmp, cursor + 1));
    }
    return score;
  }
}


int main(int argc, char* argv[]) {
  int N, M, Q;
  cin >> N >> M >> Q;

  vector<int> a(Q);
  vector<int> b(Q);
  vector<int> c(Q);
  vector<int> d(Q);
  for (int i = 0; i < Q; ++i) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }

  vector<int> tmp;
  long long ret = search(M, N, a, b, c, d, tmp, 0);

  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 3632
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  string s,t; cin >> s >> t; ll ans = 0;
  ll n = s.size();
  
  rep(i,n){
    if(s[i] != t[i]) ans++;
  }
  
  cout << ans << endl;
  
  
}

Measured memory_bytes: 3916
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    b = [0] * n
    for i in range(n):
        mod = n - i
        x = 1
        tmp = 0
        while x * mod <= n:
            tmp += b[x * mod - 1]
            x += 1
        if tmp % 2 != a[mod - 1]:
            b[mod - 1] = 1

    ans_m = 0
    ans_b = []
    for i in range(n):
        if b[i] > 0:
            ans_m += 1
            ans_b.append(i + 1)
    print(ans_m)
    if len(ans_b) > 0:
        print(*ans_b)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 66684