akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
	int n,k,x;
	cin>>n>>k;
	vector<int>v;
	for(int i=0;i<n;i++)
		{  cin>>x;
			v.push_back(x);
		}
			int a[n];
			a[0]=0;
			a[1]=abs(v[1]-v[0]);
			for(int i=2;i<n;i++)
			{   a[i]=INT_MAX;
					for(int j=1;j<=k;j++)
					{
						if(i-j>=0)
						{
							a[i]=min(a[i],a[i-j]+abs(v[i]-v[i-j]));
						}
						else
						break;
					}
				
			}
     cout<<a[n-1];
	return 0;
}

Measured memory_bytes: 1272
n = int(input())
import math
r = math.sqrt(n)
l1 = []
l2 = []
for i in range(1, int(r+1)):
    if n % i == 0:
        a = i
        b = n / i
        if a <= b:
            l1.append([str(a), str(int(b))])

for j in l1:
    u = j[0]
    v = j[1]
    if len(u) >= len(v):
        f = len(u)
    else:
        f = len(v)
    l2.append(f)

print(min(l2))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,x,n) for(ll i=x;i<n;i++) 
#define sort(v) sort(v.begin(),v.end());
const ll mod = 1E9+7;

int main()
{
   // ll n;
   // cin>>n;
   // string ans;
   // while(n!=0){
   //    ll r = n%26 - 1;
   //    char x = char(r+97);
   //    ans+=x;
   //    n = (n-r)/26;
   // }
   // reverse(ans.begin(),ans.end());
   // cout<<ans<<endl;
   ll n,k;
   cin>>n>>k;
   vector<ll> v(n);
   loop(i,0,n)cin>>v[i];
   sort(v);
   ll ans = 0;
   loop(i,0,k)ans+=v[i];
   cout<<ans;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;

int arr[100005];

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++)
        scanf("%d", &arr[i]);

    printf("%d\n", (n-2) / (k-1) + 1);
    return 0;
}


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

int main()
{
	int n;
	cin>>n;
	int k;
	cin>>k;
	int h[n];int cost[n];
	for(int i=0;i<n;i++)
	{
		cin>>h[i];
	}
	for(int i=0;i<=min(k,n-1);i++)
	{
		cost[i]=abs(h[i]-h[0]);
	}
	for(int i=k+1;i<n;i++)
	{
		cost[i]=abs(h[i]-h[i-1])+cost[i-1];
		for(int j=2;j<=k;j++)
		{
			cost[i]=min(cost[i],abs(h[i]-h[i-j])+cost[i-j]);
		}
	}
	cout<<cost[n-1]<<endl;
	return 0;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    ll a[100000], b[100000];
    ll cnt = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = n - 1; i >= 0; i--) {
        // cntはこれまでに加えた値の総数
        // b[i] - (a[i] + cnt)%b[i]
        // b - (a + これまでに加えた総数) modulo b
        // これは後いくらでbになるかという値
        // これを更にbで割ることで1のときにmodule 1で答えが1になることを阻止する
        cnt += (b[i] - (a[i] + cnt) % b[i]) % b[i];
    }
    cout << cnt << endl;
    return 0;
}

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

int main(){
  int S;
  cin >> S;
  
  int h,m,s;
  h = S/3600;
  m = (S - h*3600)/60;
  s = S - h*3600 - m*60;
  
  cout << h << ":" << m << ":" << s << endl;
    
  return 0;
}



Measured memory_bytes: 3088
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#include<bitset>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	string N;
	int ans=0;
	scan(N);
	rep(i,4) if(N[i]=='2') ans++;
	prin(ans);
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
typedef pair < short , short > Pi;
#define y first
#define x second
#define INF ( 1 << 30 )
#define SQR(x) ((x)*(x))
Pi p[500000];
int main(){
  int n;
  scanf("%d", &n);
  for(int i = 0 ; i < n ; i++ ){
    scanf("%hd %hd", &p[i].x, &p[i].y);
  }
  sort( p, p + n);
  int ret = INF;
  for(int i = 0 ; i < n ; i++ ){
    for(int j = i + 1 ; j < n ; j++ ){
      if( SQR(p[i].y - p[j].y) >= ret) break;
      ret = min( ret, SQR(p[i].x - p[j].x) + SQR(p[i].y - p[j].y));
    }
  }
  printf("%d\n", ret);
}

Measured memory_bytes: 2980
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
typedef long long ll;
typedef pair<int, int> P;

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

    int mx = 0;
    int mx2 = 0;
    int cnt = -1;

    rep(i, n) {
        mx = max(mx, a[i]);
    }
    rep(i, n) {
        if (mx == a[i]) cnt++;
    }
    if (cnt > 0) {
        rep(i, n) {
            cout << mx << endl;
        }
        return 0;
    }
    rep(i, n) {
        if (a[i] == mx) continue;
        mx2 = max(mx2, a[i]);
    }
    rep(i, n) {
        if (a[i] == mx) {
            cout << mx2 << endl;
        }
        else {
            cout << mx << endl;
        }
    }


}

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

int main(){
   string s;
   cin >> s;
   int count[2]={0,0};
   for(int i=0; i<2; i++){
       for(int j=0; j<s.size(); j++){
//          cout << (s.at(j)-'0'+i+j)%2 << endl;
           if((s.at(j)-'0'+i+j)%2==0) count[i]++;
       }
   }
   cout << min(count[0],count[1]) << endl;
}

Measured memory_bytes: 3736
using System;
using System.Linq;
 
class P{
  static void Main(){
    int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();
    Console.WriteLine(n[0] ==n[1] + n[2]||n[1] == n[0] + n[2]||n[2] == n[0] + n[1] ? "Yes" : "No");
  }
}

Measured memory_bytes: 13396
// https://atcoder.jp/contests/abc132/tasks/abc132_a
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func readLine() string {
	scanner.Scan()
	return scanner.Text()
}

func main() {
	s := strings.Split(readLine(), "")
	m := make(map[string]bool)
	uniq := []string{}

	for _, elem := range s {
		if !m[elem] {
			m[elem] = true
			uniq = append(uniq, elem)
		}
	}

	if len(uniq) == 2 {
		fmt.Fprintf(writer, "Yes")
	} else {
		fmt.Fprintf(writer, "No")
	}
	writer.Flush()
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, h;
  in(n);
  vector<ll> s(n), t(n), u(n), a(100009, 0);
  rep(i, n){
    in(s[i]);
  }
  rep(i, n){
    h = s[i];
    a[h]++;
    a[h + 1]++;
    a[h + 2]++;
  }
  h = 0;
  rep(i, 100009)
    h = max(h, a[i]);
  out(h);
  memi;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define frn(i,a,b) for(ll i=a;i<b;i++)
#define forn(i,a,b) for(ll i=a;i<=b;i++)
#define frt(i,a,b) for(auto it=a;it!=b;it++)
#define MP make_pair
#define F first
#define S second
#define PB push_back
#define SQ(a) (a)*(a)
#define SUM(n) ((n)*(n+1))/2
#define SqSUM(n) ((n)*(n+1)*(2*n+1))/2
#define GMSUM(a,r,n) (a*pow(r,n)-a)/(r-1)
#define ciel(x, y) (((x) / (y)) + ((x) % (y) != 0))
#define tc(tt) \
    int tt;    \
    cin >> tt; \
    for (int _tt = 0; _tt < tt; _tt++)
#define input(v,n) for(ll i = 0 ; i<n ; i++) cin>>v[i]
#define output(v,n) for(ll i = 0 ; i<n ; i++) cout<<v[i]<<" "
#define endl '\n'
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl
#define dbg(x) cerr << #x << "is" << (x) << endl
#define leadzero(a) __builtin_clz(a)      // count leading zeroes
#define trailzero(a) __builtin_ctz(a)     // count trailing zeroes
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
const long long int md = 998244353;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pi;
typedef vector<ll> vi;
typedef vector<vector<ll, ll> > vvi;
    // typedef bitset<5> bst;
typedef priority_queue<int, vector<int>, greater<int>> min_heap;
typedef priority_queue<int, vector<int>> max_heap;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
    indexed_set;
const ll MAX = LONG_MAX;
const ll lrg = 1000000007;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,m;
    cin>>n>>m;
    if(m!=n)
        cout<<"No";
    else if(m==n && m>=0)
        cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
	using namespace std;
	int main()
	{
		int a,b,w,c=0;
		scanf("%d%d%d",&w,&a,&b);
		if(b>(a+w))
        {
            c=b-(a+w);
            printf("%d",c);
        }
        else if(a>(b+w))
        {
            c=a-(b+w);
            printf("%d",c);
        }
        else
            printf("%d",c);
	}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};


int main(){
    int h,w;cin >> h >> w;
    vector<vector<int>> a(h,vector<int> (w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int b;cin >> b;
            a[i][j] = abs(a[i][j]-b);
        }
    }
    bitset<30000> bi[h+1][w+1];
    bi[0][0][15000] = 1;
    for (int k = 0; k <= h+w-2; k++) {
        for (int i = max(0,k-h+1); i <= min(w-1,k); i++) {
            int x = i, y = k-i;
            bi[y+1][x] = bi[y+1][x] | (bi[y][x] >> a[y][x]);
            bi[y+1][x] = bi[y+1][x] | (bi[y][x] << a[y][x]);
            bi[y][x+1] = bi[y][x+1] | (bi[y][x] >> a[y][x]);
            bi[y][x+1] = bi[y][x+1] | (bi[y][x] << a[y][x]);
        }
    }
    int ans = INF;
    for (int i = 0; i < 30000; i++) {
        if(bi[h][w-1][i]) ans = min(ans, abs(15000 - i));
    }
    for (int i = 0; i < 30000; i++) {
        if(bi[h-1][w][i]) ans = min(ans, abs(15000 - i));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 24320
#include <bits/stdc++.h>
// U - Grouping

using namespace std;

int a[18][18];
long long dp[65540];
long long val[65540];

int main() {
    int N,i,j,k;

    scanf("%d",&N);

    for (i = 0;i < N;i++) {
        for (j = 0;j < N;j++)
            scanf("%d",&a[i][j]);
    }

    for (i = 0;i < (1 << N);i++) {
        for (j = 0;j < N;j++) {
            if (i & (1 << j)) {
                for (k = j + 1;k < N;k++) {
                    if (i & (1 << k))
                        val[i] += a[j][k];
                }
            }
        }
    }

    for (i = 0;i < (1 << N);i++) {
        for (j = i;j > 0;j = (j - 1) & i)
            dp[i] = max(dp[i],val[j] + dp[i ^ j]);
    }

    printf("%lld\n",dp[(1 << N) - 1]);

    return 0;
}


Measured memory_bytes: 1280
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main
{
    public static void main(String[] args)
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int n = in.nextInt();
            int A[][] = new int[n + 1][n + 1];
            for (int i = 1; i <= n; i++)
            {
                int j = in.nextInt();
                for (int z = 1; z <= j; z++)
                {
                    int t[] = CPUtils.readIntArray(2, in);
                    if (t[1] == 1)
                    {
                        A[i][t[0]] = 1;
                    } else
                    {
                        A[i][t[0]] = -1;
                    }
                }
            }
            int answer = 0;
            AA:
            for (int bits = 1; bits < (1 << n); bits++)
            {
                Set<Integer> U = new HashSet<>();
                Set<Integer> H = new HashSet<>();
                for (int i = 1; i <= n; i++)
                {
                    //nth bit in integer
                    int p = (bits >> (i - 1)) & 1;
                    if (p == 1)
                        H.add(i);
                    else
                        U.add(i);
                }
                for (int i = 1; i <= n; i++)
                {
                    //can skip unkind
                    if (U.contains(i)) continue;

                    for (int t = 1; t <= n; t++)
                    {
                        if (A[i][t] != 0)
                        {
                            if ((A[i][t] == 1 && U.contains(t)) || (A[i][t] == -1 && H.contains(t)))
                            {
                                U.clear();
                                H.clear();
                                continue AA;
                            }
                        }
                    }
                }
                answer = Math.max(answer, Integer.bitCount(bits));
                U.clear();
                H.clear();
            }
            out.print(answer);
        }

    }

    static class CPUtils
    {
        public static int[] readIntArray(int size, Scanner in)
        {
            int[] array = new int[size];
            for (int i = 0; i < size; i++)
            {
                array[i] = in.nextInt();
            }
            return array;
        }

    }
}



Measured memory_bytes: 42312
#include <bits/stdc++.h>
using namespace std;
#define int long long
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
#define MP make_pair
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

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

    vint coin;
    coin.PB(1);
    int six=6, nine=9;
    while(six<=n) {coin.PB(six); six*=6;}
    while(nine<=n) {coin.PB(nine); nine*=9;}
    //rep(i,7) cout<<m[i]<<' ';
    vint dp(n+10,INF);
    dp[0]=0;
    //dp[1]=1;
    FOR(i,1,n+1){
        for(int c:coin){
            if(i-c>=0) chmin(dp[i],dp[i-c]+1);
        }
    }
    //FOR(i,1,n+1) cout<<dp[i]<<' ';
    cout<<dp[n]<<endl;
    
}

Measured memory_bytes: 1148
import math

N = 10 ** 9 + 7
X, Y = map(int, input().split())
B3 = 2 * X - Y
if B3 % 3:
    print(0)
    exit()
B = B3 // 3
A = X - 2 * B
if A < 0 or B < 0:
    print(0)
    exit()

# count = 1
# for i in range(A + 1, A + B + 1):
#     count *= i
# for i in range(1, A + 1):
#     count //= i
# print(count % N)

# def combinations_count(n, r):
#     return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
#
# print(combinations_count(A + B, A) % N)

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

print(cmb(A + B,A) % N)






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

int main()
{
	char str[200], pal[200];
	int j, ans;

	while (cin >> str){
		j = 0;
		for (int i = strlen(str) - 1; i >= 0; i--){
			pal[j] = str[i];
			j++;
		}
		pal[j] = '\0';
		if (strcmp(pal, str) == 0) ans++;
		
	}
	cout << ans << endl;
	return(0);
}

Measured memory_bytes: 1140
#include<cmath>
#include<queue>
#include<stack>
#include<deque>
#include<vector>
#include<cstdio>
#include<set>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define per(i,a,b) for(long long int i=a;i<=b;++i)
#define rep(i,a,b) for(long long int i=a;i>=b;--i)
#define inf 0xf3f3f3f
#define ll long long 
using namespace std;
ll p[300005];
int main(){
	ll n,k;
	cin>>n>>k;
	per(i,1,n) cin>>p[i];
	sort(p+1,p+n+1);
//	per(i,1,n) cout<<p[i]<<"% ";
	ll sum=0;
	if(k>=n) cout<<"0";
	else{
		per(i,1,n-k) sum+=p[i];
	    cout<<sum;
	}
	return 0;
}

Measured memory_bytes: 1792
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::BTreeMap;

fn main() {
    input!(h: usize, w: usize, n: usize, ass: [usize; n]);

    let mut graph = vec![vec![0usize; w]; h];
    let mut ny = 0;
    let mut nx = 0i64;
    let mut rev = false;
    for (i, &a) in ass.iter().enumerate() {
        let num = i + 1;
        for _ in 0..a {
            if nx >= w as i64 {
                nx -= 1;
                ny += 1;
                rev = true;
            } else if nx < 0 {
                nx += 1;
                ny += 1;
                rev = false;
            }
            graph[ny][nx as usize] = num;

            if rev {
                nx -= 1;
            } else {
                nx += 1;
            }
        }
    }

    for i in 0..h {
        for j in 0..w {
            if j == w - 1 {
                print!("{}", graph[i][j]);
            } else {
                print!("{} ", graph[i][j]);
            }
        }
        println!("");
    }
}


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

int main(void){
    
    int N,len;
    cin >> N;
    len = N * 0.9;
    
    for(int i=len;i<=N;i++){
        if((int)(i* 1.08) == N){
            cout << i <<endl;
            break;
        }
       
       if(i == N) cout << ":(" <<endl;
    }
    
}

Measured memory_bytes: 3612
import sys
from collections import deque

sys.setrecursionlimit(10000)
INF = float('inf')

K = int(input())

# ある数に 1 を足すと各桁の和は 1 増える
# ある数に 10 を掛けると各桁の和は 0 増える
# mod K の世界で同じことやっても同じなので
# このグラフ上で 1 から 0 への最短距離が答え。

distances = [INF for _ in range(K)]

# 01BFS
remains = deque()
remains.append((1, 1))
while distances[0] == INF:
    d, mod_k = remains.popleft()
    distances[mod_k] = d
    if distances[(mod_k + 1) % K] == INF:
        remains.append((d + 1, (mod_k + 1) % K))
    if distances[mod_k * 10 % K] == INF:
        remains.appendleft((d, mod_k * 10 % K))
print(distances[0])


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

int main() {
	int N;
	cin >> N;
	vector<int>C(N - 1), S(N - 1), F(N - 1);
	for (int i = 0; i < N - 1; i++) cin >> C[i] >> S[i] >> F[i];

	for (int start = 0; start < N - 1; start++) {
		int time = 0;
		for (int i = start; i < N - 1; i++) time = (time < S[i] ? S[i] : (time + F[i] - 1) / F[i] * F[i]) + C[i];
		cout << time << endl;
	}
	cout << 0 << endl;
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;

typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

int main(void){
    int h, w;
    cin >> h >> w;
    REP(i, h) {
        string s;
        cin >> s;
        cout << s << endl;
        cout << s << endl;
    }
    return 0;
}

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

vector<string> s = {"dream", "dreamer", "erase", "eraser"};
string S;

bool DFS(int n) {
  if(n == S.size()) return true;
  for(string i : s) {
    if(n + i.size() <= S.size() && S.substr(n, i.size()) == i) {
      if(DFS(n + i.size())) return true;
    }
  }
  return false;
}

int main() {
  cin >> S;
  cout << (DFS(0) ? "YES" : "NO") << endl;
}

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

int main() {
  
  int H, W;
  cin >> H >> W;
  
  vector<string> str(H);
  for(int i=0; i<H; i++){ cin >> str[i]; }
  
  vector<bool> row(H, false);
  vector<bool> col(W, false);
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(str[i][j]=='#'){
        row[i]=true;
        col[j]=true;
      }
    }
  }
  
  for(int i=0; i<H; i++){
    if(row[i]){
      for(int j=0; j<W; j++){
        if(row[i] && col[j]){
          cout << str[i][j];
        }
      }
      cout << endl;
    }
  }
  
}



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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 211111

const int INF = 1 << 30 ;
typedef long long ll ;
typedef pair < int , int > pii ;


int main() {
  int n ,a;
  deque<int>deq ;
  scanf("%d", &n) ;

  for(int i = 0 ;i<n ;i++){
    scanf("%d", &a) ;
    if(i&1) deq.push_front(a) ;
    else deq.push_back(a) ;
  }

  if(!(n&1)){
  for(auto it = deq.begin() ; it!= deq.end() ;it++){
    printf("%d ", *it) ;
  }
  }
  else 
    for(auto it = deq.rbegin() ; it!=deq.rend() ; it++){
      printf("%d ", *it) ;
    }

  return 0 ;
}

Measured memory_bytes: 2944
#include <stdio.h>
#include <math.h>

int main(void)
{
	int h, w;
	int i, j;

	for (;scanf("%d%d", &h, &w),h+w;){
		for (i = 1; i <= h; i++){
			for (j = 1; j <= w; j++)putchar(i>1&&j>1&&i<h&&j<w?'.':'#');
			puts("");
		}
		puts("");
	}
	return (0);
}

Measured memory_bytes: 588
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scn = new Scanner(System.in)) {
			int N = scn.nextInt();
			int[] Ai = new int[N];
			int[] Sumi = new int[N];

			int sum = 0;
			for(int i = 1; i < N; i++) {
				Ai[i] = scn.nextInt();
			}


			for(int i = 1; i < N; i++) {
				Sumi[Ai[i]-1]++;
			}


			for(int i = 0; i < N; i++) {
				System.out.println(Sumi[i]);
			}
		}
	}
}

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

int main(){
  int n;
  while(cin >> n){
    int a,b, k_a;
    vector<int> v(n);
    cin >> a >> b;
    cin >> k_a;
    for(int i=0;i<n;i++) cin >> v[i];

    sort(v.begin(),v.end());

    int ans = k_a / a, sum = 0;
    for(int i=1;i<=n;i++){
      sum += v[n-i];
      ans = max(ans,(k_a+sum)/(a+i*b));
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define F first
#define S second
#define bitcnt(v) __builtin_popcount(v)
#define all(v) v.begin(), v.end()


void solution(){


	int n, W; cin >> n >> W;

	vector<int> w(n);
	vector<int> v(n);

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

	//  dp[i][w] = v[i] + dp[i-1][w-w[i]]

	vector<vector<ll>> dp(n+1, vector<ll>(W+1,0LL));

	ll ans = 0LL;

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= W; j++){
			dp[i][j] = dp[i-1][j];
			if(j - w[i-1] >= 0)
				dp[i][j] = max(dp[i][j], (ll)v[i-1] + dp[i-1][j-w[i-1]]);
			ans = max(ans, dp[i][j]);
		}
	}

	cout << ans << endl;
}	


int main(){ 

	fio; // fast input output
	int t;
	t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++){
		// GOOGLE //
		// cout << "Case #" << i << ": ";
		solution();
	} 
	return 0;
}

Measured memory_bytes: 83032
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){


  int n,w;
  cin>>n>>w;
  int kuri = 1000 * n + 1;
  int dp[kuri];
  REP(i,kuri){
    dp[i] = w+1;
  }
  dp[0] = 0;
  REP(i,n){
    int x,y;
    cin>>x>>y;
    for(int j = kuri-1;j>= 0;j--){
      if(dp[j]<=w){
        dp[j+y] = min(dp[j+y],dp[j] + x);
      }
    }
  }
  int ans = w+1;
  for(int i=1000*n;i>=0;i--){
    if(dp[i]<=w){
      ans = i;
      break;
    }
  }


  cout<<ans<<endl;
 

  return 0;
}

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

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int inf = 1000000;

int N, M;
int t[100];
int main(int argc, const char * argv[]) {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> t[i];
  }

  cin >> M;
  vector<pair<int, int> > vec;
  for (int i = 0; i < M; i++) {
    int f, s;
    cin >> f >> s;
    f--;
    vec.push_back({f, s});
  }
  
  for (int i = 0; i < vec.size(); i++) {
    int time = 0;
    for (int j = 0; j < N; j++) {
      if (j == vec[i].first) {
        time += vec[i].second;
      } else {
        time += t[j];
      }
    }
    cout << time << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 405;

ll mod_pow(ll a,ll b)
{
    a %= MOD;
    ll res = 1;
    while(b){
        if(b & 1){
            res = res * a % MOD;
        }
        a = a * a % MOD;
        b >>= 1;
    }
    return res;
}

ll add(ll x,ll y)
{
    return (x + y)%MOD;
}

ll sub(ll x,ll y)
{
    return (x+MOD-y)%MOD;
}

ll mul(ll x,ll y)
{
    return x*y%MOD;
}

int sm[MAX_N][MAX_N];
int dp[MAX_N][MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,c;
    cin >> n >> c;
    vi a(n),b(n);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n){
        cin >> b[i];
    }
    rep(i,400){
        rep(j,401){
            sm[i+1][j] = add(sm[i][j],mod_pow(i+1,j));
        }
    }
    dp[0][0] = 1;
    rep(i,n){
        rep(j,c+1){
            rep(k,c+1-j){
                dp[i+1][j+k] = add(dp[i+1][j+k],mul(sub(sm[b[i]][k],sm[a[i]-1][k]),dp[i][j]));
            }
        }
    }
    cout << dp[n][c] << "\n";
    return 0;
}


Measured memory_bytes: 1536
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    p = string_to_int(inputs[0])

    diff_point = []
    for i, num in enumerate(range(1, len(p)+1)):
        if num != p[i]:
            diff_point.append(i)
    if len(diff_point) == 2 or len(diff_point) == 0:
        return "YES"
    return "NO"


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;

int A,B,K;

int main()
{
  cin >> A >> B >> K;
  int C = min(A,B);
  int cnt = 0; // 何個目か？
  while (true) {
    if (A % C == 0 && B % C == 0) {
      ++cnt;
      if (cnt == K) break;
    }
    --C;
  }
  cout << C << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;int d[1<<18],n,q,r,x,y,i;int m(int l,int r,int k){return (x<=l&&r<=y)?d[k]:(y<=l||r<=x)?INT_MAX:min(m(l,(l+r)/2,k*2+1),m((l+r)/2,r,k*2+2));}int main(){cin>>n>>q;r=2;while(r<n)r*=2;n=r,r*=2;while(r--)d[r]=INT_MAX;while(q--){scanf("%d%d%d",&r,&x,&y);if(r){y++;cout<<m(0,n,0)<<endl;}else{i=x+n-1,d[i]=y;while(i)i=(i-1)/2,d[i]=min(d[i*2+1],d[i*2+2]);}}return 0;}

Measured memory_bytes: 4132
N = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

tn1 = make_divisors(N-1)
cnt = len(tn1) - 1

tn = make_divisors(N)
for i in range(1, len(tn)):
  t = 1
  k = N
  while(k % tn[i] == 0):
    k = N // (tn[i] ** t)
    t += 1
  if(k%tn[i] == 1):
    cnt += 1
print(cnt)

Measured memory_bytes: 3316
N = int(input())
A = list(map(int, input().split()))

MOD = 10**9 + 7
# MOD = 10

sum_A = 0
for i in range(N):
    sum_A += A[i]
    # sum_A %= MOD
 
ans = (sum_A * sum_A) # % MOD

for i in range(N):
    ans -= (A[i] * A[i]) # % MOD
    # ans %= MOD

ans //= 2
ans %= MOD

print(ans)


Measured memory_bytes: 31496
import Data.Char (toLower)

cal :: Char -> String -> Int
cal c s = length . filter (==c) . map toLower $ s

solv :: String -> String
solv l = concat . map (\(a, n) -> a : " : " ++ (show (cal a l)) ++ "\n") $ allA
  where allA = zip ['a'..'z'] (repeat 0)

main = getContents >>= putStr . solv

Measured memory_bytes: 4048
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.B
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var S = ReadText();

            var exist = new HashSet<char>();
            for (int i = 0; i < S.Length; i++)
            {
                if (exist.Contains(S[i])) return "no";
                exist.Add(S[i]);
            }
            return "yes";
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 26044
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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 INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string a,b; cin >> a >> b;
    if (a.size() > b.size() ) {
        ct("GREATER");
        return 0;
    }
    if (b.size() > a.size()) {
        ct("LESS");
        return 0;
    }
    if (a.size() == b.size()) {
        if (a > b) ct("GREATER");
        if (a < b) ct("LESS");
        if (a ==b) ct("EQUAL");
    }
}



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

const int mod = 1000000007;
long long cb[2000][1000] = {0};
long long comb(int n, int k){
    if(k > n-k) k=n-k;
    if(n==0) return 1;
    if(k==0) return 1;
    if(k==1) return n;
    if(k==2) return n*(n-1)/2; 
    if(cb[n-1][k-1] != 0) return cb[n-1][k-1];
    long long ret;
    ret = comb(n-1,k) + comb(n-1,k-1);
    ret %= mod;
    cb[n-1][k-1] = ret;
    return ret;
}

int main(){
    int n,k;
    scanf("%d %d",&n,&k);
    if(k==1) {
        printf("%d\n",n);
        return 0;
    }
    if(n==k) {
        printf("1\n");
        for(int i=1; i<=k-1; i++){
            printf("0\n");
        }
        return 0;
    }
    if(k==n-1) {
            printf("2\n");
            printf("%d\n",k-1);
        for(int i=3; i<=k; i++){
            printf("0\n");
        }
        return 0;
    }
    for(int i=1; i<=k; i++){
        long long b = comb(k-1,i-1);
        long long r = 0;
        if(0<= i-2 && i-2 <= n-k-1) r += comb(n-k-1,i-2);
        if(0<= i-1 && i-1 <= n-k-1) r += 2*comb(n-k-1,i-1);
        if(0<= i && i<= n-k-1) r+= comb(n-k-1,i);
        printf("%lld\n",(b*r)%mod);
    }
    return 0;
}



Measured memory_bytes: 14848
// in the name of Allah ;
#include<bits/stdc++.h>
using namespace std ;
const int maxn = 1e2 + 10 ; 
long long  arr[maxn] , n , x  , ans = 0 ;
int main()
{
	cin >> n >> x ;
	for ( int i = 0 ; i < n ; i++ ) 
		cin >> arr[i] ;
	sort ( arr , arr+n ) ;
	for ( int i = 0 ; i < n ; i++ ) 
	{
		x -= arr[i] ;
		if ( x < 0 ) 
			ans++ ;
	}
	if ( ans > 0 ) 
		cout << n - ans << endl;
	else if ( x > 0 ) 
		cout << n-1 << endl;
	else
		cout << n << endl;
}


Measured memory_bytes: 256
import bisect

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

A.sort()
B.sort()
C.sort()
ans = 0
for b in B:
    a = bisect.bisect_left(A, b)
    c = len(C) - bisect.bisect_right(C, b)
    ans += a * c

print(ans)

Measured memory_bytes: 23360
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <fstream>
#include <vector>
#include <memory>
#include <map>
#include <random>
#include <set>
#include <numeric>
#include <iomanip>
#include <bitset>

using namespace std;

const long long oo = 1e18;

class Graph {
    int n;
    vector<vector<pair<long long, int>>> g;
public:
    Graph(int n) : n(n), g(n) {

    }

    void addEdge(int from, int to, long long weight) {
        g[from].push_back({weight, to});
        g[to].push_back({weight, from});
    }

    vector<long long> Dijkstra(int start) {
        vector<long long> ans(n, +oo);
        ans[start] = 0;
        set<pair<long long, int>> pq;
        pq.insert({0, start});

        while (!pq.empty()) {
            auto edge = *pq.begin();
            pq.erase(pq.begin());

            for (auto e:g[edge.second]) {
                if (ans[e.second] > ans[edge.second] + e.first) {
                    pq.erase({ans[e.second], e.second}); // delete old
                    ans[e.second] = ans[edge.second] + e.first;// relax, take it easy
                    pq.insert({ans[e.second], e.second}); // add new
                }
            }
        }
        return ans;
    }
};

void run(istream &cin, ostream &cout) {
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    s--; t--;
    int from,to;
    long long a, b;
    Graph yen(n), minyen(n);
    for(int i =0 ; i < m; i++){
        cin >> from >> to >> a >> b;
        from--; to--;
        yen.addEdge(from, to, a);
        minyen.addEdge(from, to, b);
    }
    auto dist = yen.Dijkstra(s);
    auto dist2 = minyen.Dijkstra(t);
    for(int i = 0; i < n; i++){
        dist[i] += dist2[i];
    }

    long long ten15 = 1'000'000'000'000'000;
    long long cost = ten15 - dist[n-1];
    vector<long long> ans;
    for(int i = n-1; i >= 0; i--){
        cost = max(cost, ten15 - dist[i]);
        ans.push_back(cost);
    }
    reverse(ans.begin(), ans.end());
    for(auto x:ans){
        cout << x << endl;
    }



}

int main() {
#ifdef  LOCAL
    ifstream cin("input.txt");
    ofstream cout("output.txt");
#else
    cin.tie(0);
    ios::sync_with_stdio(0);
#endif
    run(cin, cout);
    return 0;
}

Measured memory_bytes: 19072
#include <cstdio>

using namespace std;

typedef long long ll;

int main()
{
    ll n, a;
    ll mod = 2;
    ll odd = 0;
    ll even = 0;

    scanf("%lld", &n);

    while (n--) {
        scanf("%lld", &a);

        if (a % mod == 0) even++;
        else odd++;

        if (2 <= odd) {
            even++;
            odd = 0;
        }

        if (2 <= even) even--;
    }

    if (even + odd == 1) printf("YES\n");
    else printf("NO\n");

    return 0;
}


Measured memory_bytes: 256
N = int(input())
A, B = [], []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

s = 0
ans = 0
for i in range(N)[::-1]:
    a = (-(A[i]+s)) % B[i]
    s += a
    ans += a

print(ans)

Measured memory_bytes: 56568
import java.util.*;
import static java.lang.Math.*;
public class Main {
	final Scanner sc=new Scanner(System.in);
	final int INF=1<<26;
	final int[] vx={0,1,0,-1}, vy={1,0,-1,0};
	public static void main(String[] args) {
		new Main().A();
	}
	void A(){
		final int[] xdis={-1,0,1,0}, ydis={0,-1,0,1};
		while(true){
			int n= sc.nextInt();
			if(n == 0) break;
			HashMap<Integer, Integer[] > map = new HashMap<Integer, Integer[]>();
			Integer [] first = {0,0};
			map.put(0, first);
			for(int i=1; i < n; i++){
				int ni = sc.nextInt();
				int di = sc.nextInt();
				Integer [] now = map.get(ni);
				int newx = now[0] + xdis[di];
				int newy = now[1] + ydis[di];
				Integer [] newarray = {newx, newy};
				map.put(i, newarray);
			}
			first = map.get(0);
			int minx =first[0];
			int maxx = minx;
			int miny = first[1];
			int maxy = first[1];
			for(Integer now: map.keySet()){
				Integer [] nowarray = map.get(now);
				int x = nowarray[0];
				int y = nowarray[1];
				minx = Math.min(minx, x);
				maxx = Math.max(maxx, x);
				miny = Math.min(miny, y);
				maxy = Math.max(maxy, y);
				
			}
			int resx = maxx - minx +1;
			int resy = maxy - miny + 1;
			System.out.println(resx + " " + resy );
		}
	}
	
	void B(){
		while(true){
			int W=sc.nextInt(),H=sc.nextInt();
			boolean[][] ww=new boolean[W*2+2][H*2+2],hh=new boolean[W*2+2][2*H+2];
			for(int i=1; i<=H; i++){
				for(int x=1; x<W; x++)	ww[2*x+1][2*i]=sc.nextInt()==0;
				if(i<H)	for(int y=1; y<=W; y++)	hh[2*y][2*i+2]=sc.nextInt()==0;
			}
			
			
			PriorityQueue<CB> open=new PriorityQueue<CB>();
			open.add(new CB(1,1,0));
			int[][] close=new int[W][H];
			for(int i=0; i<W; i++)	for(int j=0; j<H; j++)	close[i][j]=INF;
			int ans=INF;
			while(!open.isEmpty()){
				CB now=open.poll();
				for(int i=0; i<4; i++){
					int xx=now.x+vx[i],yy=now.y+vy[i];
					if(!(0<xx && xx<=W && 0<yy && yy<=H))	continue;
					int x2=(now.x+xx)/2,y2=(now.y+yy)/2;
					if(!(ww[x2][y2] && hh[x2][y2]))	continue;
					if(xx==W && yy==H){
						ans=min(ans,now.s+1);
						continue;
					}
					open.add(new CB(xx,yy,now.s+1));
					close[xx][yy]=now.s+1;
				}
			}
			System.out.println((ans>=INF?0:ans));
		}
	}
	class CB implements Comparable<CB>{
		int x,y,s;
		CB(int x,int y,int s){this.x=x; this.y=y;this.s=s;}
		@Override public int compareTo(CB o) {
			if(this.s<o.s)	return -1;
			if(this.s>o.s)	return 1;
			return 0;
		}
	}
	
}

Measured memory_bytes: 12000
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int a = sc.nextInt();
        // スペース区切りの整数の入力
        int b = sc.nextInt();
        StringBuilder ab = new StringBuilder();
        StringBuilder ba = new StringBuilder();
        for(int i=0;i<a;i++){
            ab.append(b);
        }
        for(int i=0;i<b;i++){
            ba.append(a);
        }
        String abs = ab.toString();
        String bas = ba.toString();
        if(abs.compareTo(bas) < 0){
            System.out.println(abs);
        }else{
            System.out.println(bas);
        }

    }
}

Measured memory_bytes: 21844
s = int(input())
ans = 0

def c(m, r):
    if r > m//2:
        r = m - r
    ans = 1
    for i in range(r):
        ans *= m - i
        ans //= i + 1
    return ans

for i in range(1, s//3 + 1):
    ans += c(s - 3*i + i - 1, i-1)
    ans %= 10**9 + 7

print(ans)

Measured memory_bytes: 9000
#include "bits/stdc++.h"
using namespace std;
int main()
{
	int n, a, b, c[3] = {0, 0, 0};
	scanf("%d%d%d", &n, &a, &b);
	for(int i = 0, j; i < n; ++i)
	{
		scanf("%d", &j);
		if(j <= a)
		{
			++c[0];
		}
		else if(j <= b)
		{
			++c[1];
		}
		else
		{
			++c[2];
		}
	}
	printf("%d\n", *min_element(c, c + 3));
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int a[100005],N,K;
int cnt[50];

int f(int x){
    int ret=0;
    REP(i,N) ret+=x^a[i];
    return ret;
}

signed main()
{   
    cin>>N>>K;
    REP(i,N) cin>>a[i];

    REP(i,N){
        REP(j,50){
            if((a[i]>>j)&1) cnt[j]++;
        }
    }
    
    int ans=f(K),tmp=0;
    for(int i=49;i>=0;i--){
        if((K>>i)&1){
            int sum=tmp+(1LL<<i)*cnt[i];
            for(int j=i-1;j>=0;j--){
                sum+=(1LL<<j)*max(cnt[j],N-cnt[j]);
            }
            ans=max(ans,sum);
            tmp+=(1LL<<i)*(N-cnt[i]);
        }
        else{
            tmp+=(1LL<<i)*cnt[i];
        }
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = (int)1.01e4;
const int N = 1 << 18;



int main() {
#ifdef HOME
    freopen("in", "r", stdin);
#endif

    vector<int> a(4);
    ll n;
    while (cin >> a[0] >> a[1] >> a[2] >> a[3]) {
        cin >> n;
        n *= 4;
        for (int i = 1; i < 4; i++) a[i] = min(a[i], a[i - 1] * 2);

        ll ans = 0;
        for (int i = 3; i >= 0; i--) {
            int k = 1 << i;
            ans += n / k * a[i];
            n %= k;
        }
        cout << ans << endl;
    }

#ifdef HOME
    cerr << clock() / (double)CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

Measured memory_bytes: 256
# B
from collections import Counter
mod = 998244353
n = int(input())
dli = list(map(int, input().split()))
for ind in range(len(dli)):
    if (ind == 0):
        if (dli[ind] != 0):
            print(0)
            exit()
    else:
        if (dli[ind] == 0):
            print(0)
            exit()

count = Counter(dli)
# 木である条件
for ind, key in enumerate(count.keys()):
    if ind != key:
        print(0)
        exit()

sort = sorted(count.items(), key=lambda x:x[0])

tmp = []
for ind in range(len(sort)-1):
    mae = sort[ind][1]
    next = sort[ind+1][1]

    tmp.append(int(mae**next))

total = 1
for t in tmp:
    total *= t
print(total%mod)

Measured memory_bytes: 21972
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc142_a.cpp
 * time   : Sat May  2 13:39:59 2020
 * quest  : A - Odds of Oddness
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  cout << ((n % 2) ? (n / 2 + 1) / float(n) : 0.5) << "\n";
  return 0;
}


Measured memory_bytes: 256