akhauriyash/Code-Regression huggingface dataset:
import math


def modpow(val, n, mod):
    ret = 1
    while n:
        if n & 1:
            ret = (ret * val) % mod
        val = (val * val) % mod
        n = n >> 1
    return ret


n = int(input())
ab = []
for i in range(n):
    a, b = map(int, input().split())
    ab.append((a, b))

my_dict = dict()

ab_mod = []
for item in ab:
    a, b = item
    if a == 0 and b == 0:
        ab_mod.append((0, 0))
    elif a == 0:
        ab_mod.append((0, 1))
    elif b == 0:
        ab_mod.append((1, 0))
    else:
        gcd = math.gcd(abs(a), abs(b))
        if a < 0:
            a = -a
            b = -b
        ab_mod.append((a // gcd, b // gcd))

for item in ab_mod:
    if item not in my_dict:
        my_dict[item] = 1
    else:
        my_dict[item] += 1


if (0, 0) in my_dict:
    num_dame = my_dict.pop((0, 0))
else:
    num_dame = 0

num_total = n - num_dame
dame_tuple = []

for item in my_dict:
    a, b = item
    val1 = my_dict[item]
    if (b, -a) in my_dict:
        val2 = my_dict[(b, -a)]
        dame_tuple.append((val1, val2))
        num_total -= (val1 + val2)

ret = 1

ret *= modpow(2, num_total, 10 ** 9 + 7)


for item in dame_tuple:
    val1, val2 = item
    zenbu = modpow(2, val1 + val2, 10 ** 9 + 7)
    dame1 = modpow(2, val1, 10 ** 9 + 7) - 1
    dame2 = modpow(2, val2, 10 ** 9 + 7) - 1
    ret *= (zenbu - (dame1 * dame2))

ret -= 1

print((ret + num_dame) % (10 ** 9 + 7))


Measured memory_bytes: 77992
#include<bits/stdc++.h>
using namespace std;
#define lld long long int
void deepu()
{
	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);
	freopen("error.txt","w",stderr);
	#endif
}

int main() 
{ 
	// deepu();
	  
	  int m1,d1,m2,d2;
	  cin>>m1>>d1>>m2>>d2;
	  if(m1==m2)
	  	cout<<"0\n";
	  else
	  	cout<<"1\n";
   
 	return 0;
}



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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int ans = 0;
  for (int i=0; i<A+1; i++) {
    for (int j=0; j<B+1; j++) {
      for (int k=0; k<C+1; k++) {
        if (500*i+100*j+50*k==X) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
using namespace std;
typedef long long ll;

vector<pair<int, int>> to[100010];
bool visited[100010];
ll dist[100010];
ll gcd(ll a, ll b)
{
   if (b == 0)
   {
       return a;
   }
    return gcd(b, a%b);
}
void dfs(int now, ll d) {
  visited[now] = true;
  dist[now] = d;
  for (auto p : to[now]) {
    if (visited[p.first]) continue;
    dfs(p.first, d + p.second);
  }
}

int main() {
    int n,m;
    cin >> n;
    int k = n%1000;
    if(!k) {
        cout << k << endl;
        return 0;
    }
    int v = 1000-k;
    cout << v << endl;
   
    
    
    return 0;
}


Measured memory_bytes: 5980
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

/**
 * Elementary Number Theory - Extended Euclid Algorithm
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int a, b;
			a = parseInt(line.substring(0, line.indexOf(' ')));
			b = parseInt(line.substring(line.indexOf(' ') + 1));

			int[] res = egcd(a, b);

			System.out.println(res[0] + " " + res[1]);

		}//end while
	}//end main

	static int[] egcd(int a, int b) {

		int x1 = 1, y1 = 0, r1 = a;
		int x2 = 0, y2 = 1, r2 = b;
		int x3, y3, r3;

		while (true) {
			int q = r1 / r2;
			r3 = r1 % r2;
			x3 = x1 - q * x2;
			y3 = y1 - q * y2;
			if (r3 == 0) break;
			x1 = x2;
			y1 = y2;
			r1 = r2;
			x2 = x3;
			y2 = y3;
			r2 = r3;
		}

		return new int[]{x2, y2};
	}

}

Measured memory_bytes: 24452
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class E1Or2 {
        int[] rep;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt(), m = in.nextInt();
            rep = new int[n];
            for (int i = 0; i < n; i++) {
                rep[i] = i;
            }

            for (int i = 0; i < m; i++) {
                int x = in.nextInt(), y = in.nextInt(), z = in.nextInt();
                x--;
                y--;
                union(x, y);
            }


            for (int i = 0; i < n; i++) {
                rep(i);
            }


            HashSet<Integer> distinct = new HashSet<>();
            for (int r : rep) {
                distinct.add(r);
            }

            out.println(distinct.size());
        }

        int rep(int x) {
            if (rep[x] == x) {
                return x;
            }

            int r = rep(rep[x]);
            rep[x] = r;
            return r;
        }

        void union(int x, int y) {
            if (Math.random() < 0.5) {
                rep[rep(x)] = rep(y);
            } else {
                rep[rep(y)] = rep(x);
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



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

struct UnionFind{
private:
  vector<int> data;
public:
  int N;
  UnionFind(int n) : data(n, -1), N(n){}
  bool unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return false;
    --N;
    if(data[y] < data[x]) swap(x,y);
    data[x] += data[y];
    data[y] = x;
    return x != y;
  }
  bool same(int x, int y){ return find(x) == find(y); }
  int find(int x){
    if(data[x] < 0) return x;
    return data[x] = find(data[x]);
  }
  int size(int x){ return -data[find(x)]; }
};

int main(){
  int N, M;
  cin >> N >> M;
  UnionFind uf(N);
  for(int i = 0; i < M; ++i){
    int a, b;
    cin >> a >> b;
    --a,--b;
    uf.unite(a,b);
  }
  int ans = 0;
  for(int i = 0; i < N; ++i)
    ans = max(ans,uf.size(i));
  cout << ans << endl;
}


Measured memory_bytes: 4044
//#####   #####   #####   #####   #####   #       #####   #   #//
//#   #   #   #   #       #       #   #   #       #   #   ## ##//
//#####   #####   #####   #       #####   #       #####   # # #//
//##      #   #       #   #       #   #   #       #   #   #   #//
//# #     #   #       #   #       #   #   #       #   #   #   #//
//#  #    #   #       #   #       #   #   #       #   #   #   #//
//#   #   #   #   #####   #####   #   #   #####   #   #   #   #//


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ppb pop_back
#define cs(n) cout<<n<<" "
#define cn(n) cout<<n<<"\n"
#define rep(i,j,k) for(int i=j;i<k;i++)
#define rrep(i,j,k) for(int i=j;i>=k;i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
ll bin(ll a, ll b, ll mod)
{
	if (b == 0)
		return 1;
	if (b % 2 == 0)
		return bin((a * a) % mod , b / 2 , mod) % mod;
	return ((a % mod) * (bin((a * a) % mod , b / 2 , mod) % mod)) % mod;
}
void solve()
{
	int n;
	cin >> n;
	int ar[n];
	int c0 = 0, c1 = 0;
	rep(i, 0, n) {
		char ch;
		cin >> ch;
		ar[i] = (ch == 'W' ? 0 : 1);
		if (ar[i] == 0) c0++; else c1++;
	}
	int i = 0, j = n - 1, ans = 0;;
	while (i < j) {
		while (ar[j] != 1 && j > 0) {
			j--;
		}
		if (ar[i] == 1) {
			i++;
			continue;
		}
		if (i >= j) {
			break;
		}
		ar[i] = 1;
		ar[j] = 0;
		i++;
		j--;
		ans++;
	}
	cout << ans;
}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r" , stdin);
	freopen("output.txt" , "w" , stdout);
#endif
	fastio;
	int t;
	t = 1;
	//cin>>t;
	while (t--)
	{
		solve();
	}
#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
	return 0;
}

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

string o, e;
string ans = "";

int main(){
  cin >> o >> e;
  for(int i = 0; i < e.size(); i++){
    cout << o[i] << e[i];
  }
  if(o.size() != e.size()){
    cout << o[o.size()-1];
  }
  cout << endl;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN,'%d %d',$x,$y);
if($x < $y)
{
  $z = $x;
  $x = $y;
  $y = $z;
}

while($y > 0)
{
  $r = $x % $y;
  $x = $y;
  $y = $r;
}

echo $x . "\n";

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

using namespace std;

int a[200001];

int main () {
	int n;
	cin >> n;
	for (int i = 1;i <= n;i ++) cin >> a[i];
	long long ans = 0;
	for (int i = 1;i <= n;i ++) {
		ans += (a[i] / 2);
		a[i] %= 2;
		if (!a[i] || !a[i + 1]) continue;
		a[i] = 0;
		a[i + 1] --;
		ans ++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 640
x, n=map(int, input().split())
if n==0:
    print(x)
    exit()
else:
    dic=list(map(int, input().split()))

if x not in dic:
    print(x)
else:
    for i in range(1, 101):
        a=x-i
        b=x+i
        if a not in dic and b not in dic:
            print(min(a,b))
            exit()
        if a not in dic:
            print(a)
            exit()
        if b not in dic:
            print(b)
            exit()

Measured memory_bytes: 61876
def resolve():
    N = int(input())
    B = list(map(int, input().split()))
    ans = []
    while B:
        for i in range(len(B) - 1, -1, -1):
            if B[i] == i + 1:
                ans.append(i + 1)
                del B[i]
                break
        else:
            print(-1)
            return 
    print(*ans[::-1], sep='\n')



if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9128
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)

	s := []int{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}

	k := getInt()

	out(s[k-1])
}


Measured memory_bytes: 640
import java.util.*;
import java.math.BigDecimal;

public class Main{
	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		
		long A = sc.nextLong();
		BigDecimal b1 = new BigDecimal(sc.next());
		BigDecimal b2 = new BigDecimal(100.0);
		long B = b1.multiply(b2).longValue();
		System.out.println((A*B)/100);
		
		sc.close();
	}
}

Measured memory_bytes: 36060
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import numpy as np
import queue

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))
N,M = LI()

um = [[] for i in range(M)]
for i in range(M):
    um[i] = LI()

S,T = LI()
S -= 1
T -= 1
routes = [[] for i in range(N)]

for i in range(M):
    u,m = um[i]
    u -= 1
    m -= 1
    routes[u].append(m)

used = [[mod,mod,mod] for i in range(N)]

from collections import deque

# q = queue.Queue()
q = deque()
q.append((S,0))
# Deep First Serch
while q:
    now, cost = q.popleft()
    for route in routes[now]:
        n_state = (cost + 1) % 3
        if used[route][n_state] == mod:
            used[route][n_state] = cost + 1
            q.append((route,cost+1))


# print(used)
try:
    ans = used[T][0]
    if ans == mod:
        ans = -1
    else:
        ans = ans/3
except:
    ans = -1
print(int(ans))


Measured memory_bytes: 67792
#include <stdio.h>

int main(void){
    int charge,value;
    float tax=1.08;
    
    scanf("%d",&charge);
    
    value=(int)((charge/tax)+0.9);
    
    if (charge==(int)(value*tax)) {
        printf("%d\n",(int)value);
    } else {
        printf(":(\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007

int c[4];

int main(){
	string s;
	cin >> s;
	for(int i=0;i<s.size();i++){
		c[s[i]-'a']++;
	}
	int ma = max(c[0],max(c[1],c[2]));
	bool flag = 1;
	for(int i=0;i<3;i++){
		if(abs(ma-c[i])>1){
			flag = 0;
		}
	}
	if(flag){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 512
/*
ID: sstfmsc1
TASK: milk2
LANG: C++
*/
#include <bits/stdc++.h>
 
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define forin(i, n) for ( int i = 0; i < (int)n; ++i )
#define MAXN 5
#define MAXS 10000
#define INF 1000000
typedef long long ll;
const char nl = '\n';
ll MOD = (ll)(1e9 + 7);
int modk( int k, int x ) { return ( ( x % k ) + k ) % k; }

void solve()
{
	ll x, k, d; cin >> x >> k >> d;

	ll moves = ll(abs(x) / d);

	if ( moves > k )
	{
		cout << abs( abs(x) - abs(k * d) );
	}
	else
	{
		bool flag = ( ( k - moves ) % 2 == 0 );
		ll ans = abs(x) % d;
		cout << ( (flag) ? ans : min( abs(ans - d), abs(ans + d) ) );
	}
	
	cout << nl;
    return;
}
 
int main()
{
    //freopen("input.in", "r", stdin);
    //freopen("milk2.out", "w", stdout);
    //IOS
	//int q;
    //while( q-- )
    solve();
        
    return 0;
}

Measured memory_bytes: 3560
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
string st[110];
int w,h;
int main()
{
    cin>>w>>h;
    for(int i=1;i<=w;i++)
    {
    	cin>>st[i];
    }
    for(int i=1;i<=w;i++)
    {
    	cout<<st[i]<<endl;
    	cout<<st[i]<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int n, m;   cin >> n >> m;
    int l = 1, r = n;
    for (int i = 1; i <= m; i++)
    {
        int tl, tr; cin >> tl >> tr;
        l = max(l, tl);
        r = min(r, tr);
    }
    if (l <= r)
    {
        cout << r - l + 1;    
    }
    else    cout << 0;
    getchar(); getchar();
    return 0;
}

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


using namespace std;

int main()
{
    long long a,b,t=0;
    cin>>a>>b;
    while(a <= b){
        t++;
        a*=2;
    }
    cout<<t;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>




using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	// ユークリッドの方法
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}//gcd
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a'+1;
    if((in < 1) || (in > 26)){
        ans = 100;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}





int main(){
  int K;
  int A[3];
  cin>>A[0]>>A[1]>>A[2]>>K;
  sort(A,A+3);
  for(int i=0;i<K;i++){
    A[2]*=2;

  }
  cout<<A[0]+A[1]+A[2]<<endl;





  



}


  

Measured memory_bytes: 256
// RAM RAM

#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define ppb pop_back
#define vi vector<int>
#define mp make_pair
#define arrayin(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define N 55

using namespace std;


int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);

    string a,b,c;cin>>a>>b>>c;
    reverse(a.begin(),a.end());
    reverse(b.begin(),b.end());
    reverse(c.begin(),c.end());

    char turn ='a';
    while(true){
    	if(turn=='a'){
    		if(a.length()==0){
    			break;
    		}
    		turn=a[a.length()-1];
    		a.pop_back();
    	}else if(turn == 'b'){
    		if(b.length()==0){
    			break;
    		}
    		turn=b[b.length()-1];
    		b.pop_back();
    	}else{
    		if(c.length()==0){
    			break;
    		}
    		turn=c[c.length()-1];
    		c.pop_back();
    	}
    }
    cout<<(char)toupper(turn)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int t; //１日の目標時間
    int n; // 勉強の回数
    int s[22], f[22]; //毎回の勉強開始時刻と終了時刻

    while(true){
        cin >> t;
        if(t == 0) break;

        cin >> n;
        for(int i = 0; i < n; i++){
            cin >> s[i] >> f[i];
        }
        
        int time = 0; //１日に勉強した合計時間
        for(int i = 0; i < n; i++){
            time += f[i] - s[i];
        }
        if(time >= t) 
            cout << "OK" << endl;
        else{
            cout << t - time << endl;
        }
    }
}


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

using namespace std;

int main()
{
    int N;
    vector<int> a;    
    cin >> N;
    a.resize(N, 0);
    for(int i = 0; i < N; ++i) { cin >> a[i];}

    int count = 0;
    for(int i = 0; i < N; i += 2)
    {
        if(a[i] % 2 == 1)    
        {
            count++;    
        }
    }
    
    cout << count << endl;

    return 0;    
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <ctype.h>
#include <math.h>
using namespace std;
 
int findSum(int n){
    int sum=0;
    while(n>0){
        sum+=n%10;
        n/=10;
    }
  return sum;
}

int main(){
    int N,A,B;
    cin>>N>>A>>B;
    int ans=0;

    for(int i=1;i<=N;++i){
        int sum=findSum(i);
        if(sum<=B&&A<=sum)ans+=i;
    }
    cout<<ans<<endl;
}

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

int main()
{
    long long int n;
    cin>>n;
    string s;
    cin>>s;
    if(s.size()<=n) cout<<s;
    else{
        for(int i=0; i<n; i++){
            cout<<s[i];
        }
        cout<<"...";
    }
}


Measured memory_bytes: 3628
N, X, Y = map(int, input().split())
dic = {key: 0 for key in range(1, N)}
for i in range(1, N+1):
    for j in range(1, N+1):
        if(i < j):
            key = min(abs(j - i), abs(X - i)+1+abs(j - Y),
                      abs(Y - i) + 1 + abs(j - X))
            dic[key] += 1
for ans in dic.values():
    print(ans)


Measured memory_bytes: 48860
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int H,A;
    cin>>H>>A;
    cout<<(H+A-1)/A<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
  int i,j,k,l,n,r[10000],m[100][100];
 
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d %d",&r[i-1],&r[i]);
  }
 
  for(i=1;i<=n;i++){
    m[i][i] = 0;
  }
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j = i + l -1;
      m[i][j] = 500000000;
      for(k=i;k<=j-1;k++){
    if(m[i][j] >= m[i][k]+m[k+1][j]+r[i-1]*r[k]*r[j]){
      m[i][j] = m[i][k]+m[k+1][j]+r[i-1]*r[k]*r[j];
    }
      }
    }
  }
 
  printf("%d\n",m[1][n]);
 
  return 0;
 
}

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

typedef long long ll;
typedef pair<int,int> P;
ll const mod = 1e9+7;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    ll n,k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0;i < n;++i) cin >> a[i];
    ll ans = 0;
    for (int i = 0;i < n;++i) {
        ll b = 0;
        for (int j = i+1;j < n;++j) {
            if (a[i] > a[j]) b++;
        }
        ll c = 0;
        for (int j = 0;j < n;++j) {
            if (a[i] > a[j]) c++;
        }
        (ans += b*k%mod+c*(k*(k-1)/2%mod)%mod) %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
cands = '753'

def dfs(s):
    if int(s)>N:
        return 0
    if '7' in s and '5' in s and '3' in s:
        ret = 1
    else:
        ret = 0
    for c in cands:
        ret += dfs(s+c)
    return ret

print(dfs('0'))


Measured memory_bytes: 50012
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
typedef long long li;

const int maxn = 18, mod1 = 1e9 + 7, mod2 = 1e9 + 9, base = 31;

int n;
char s[maxn * 2 + 1];
map< pair<li, li>, int > f;

int main(void) {
  scanf("%d%s", &n, s);
  for (int x = 0; x < 1 << n; ++x) {
    int g1 = 1, g2 = 1, h1 = 1, h2 = 1;
    for (int i = 0; i < n; ++i) {
      if (x >> i & 1) {
        g1 = ((li)g1 * base + s[i] - 'a') % mod1;
        g2 = ((li)g2 * base + s[i] - 'a') % mod2;
      } else {
        h1 = ((li)h1 * base + s[i] - 'a') % mod1;
        h2 = ((li)h2 * base + s[i] - 'a') % mod2;
      }
    }
    li key1 = (li)g1 * mod2 + g2, key2 = (li)h1 * mod2 + h2;
    ++f[make_pair(key1, key2)];
  }
  reverse(s, s + 2 * n);
  li ans = 0;
  for (int x = 0; x < 1 << n; ++x) {
    int g1 = 1, g2 = 1, h1 = 1, h2 = 1;
    for (int i = 0; i < n; ++i) {
      if (x >> i & 1) {
        g1 = ((li)g1 * base + s[i] - 'a') % mod1;
        g2 = ((li)g2 * base + s[i] - 'a') % mod2;
      } else {
        h1 = ((li)h1 * base + s[i] - 'a') % mod1;
        h2 = ((li)h2 * base + s[i] - 'a') % mod2;
      }
    }
    li key1 = (li)g1 * mod2 + g2, key2 = (li)h1 * mod2 + h2;
    ans += f[make_pair(key1, key2)];
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 33024
h,w = map(int, input().split( ))
s = [input() for _ in range(h)]

inf = 10**5

cost = [[inf]*w for _ in range(h)]
if s[-1][-1]==".":
    cost[-1][-1]=0
else:
    cost[-1][-1]=1

for i in range(h-1,-1,-1):
    for j in range(w-1,-1,-1):
        if i==h-1 and j==w-1:
            continue
        if s[i][j]=="#":
            if j==w-1:
                pass
            else:
                if s[i][j+1]=="#":
                    cost[i][j]=cost[i][j+1]
                else:
                    cost[i][j]=cost[i][j+1]+1
            if i==h-1:
                pass
            else:
                if s[i+1][j]=="#":
                    cost[i][j]=min(cost[i][j],cost[i+1][j])
                else:
                    cost[i][j]=min(cost[i][j],cost[i+1][j]+1)
        else:
            if j<w-1:
                cost[i][j]=cost[i][j+1]
            if i<h-1:
                cost[i][j]=min(cost[i][j],cost[i+1][j])
print(cost[0][0])
                
        

Measured memory_bytes: 41968
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
getline(cin,s);
int n=s.size();
for(int i=0;i<n;i++){
	if(s.at(i)=='?'){
		if(i-1>-1 && s[i-1]=='P'){
			//cout<<"sdf\n";
			s.at(i)='D';	
		}
		else if(i+1<n && (s[i+1]=='D' || s[i+1]=='?')){
			s.at(i)='P';
		}
		else{
			s.at(i)='D';
		}
	}
}
cout<<s<<"\n";
return 0;
}

Measured memory_bytes: 3720
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>

template <class T>
inline void read(T &x) {
    x = 0;
    int f = 0;
    char ch = getchar();
    while (!isdigit(ch))    { f |= ch == '-'; ch = getchar(); }
    while (isdigit(ch))     { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
    x = f ? -x : x;
    return;
}

int ans[2010];
int n, x, y, k, s, sum;

int main() {
    read(n), read(x), read(y);
    for (int i = 1; i <= n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            ++ans[std::min(j - i, abs(i - x) + 1 + abs(y - j))];
        }
    }
    for (int i = 1; i < n; ++i) printf("%d\n", ans[i]);
    return 0;
}

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

int main() {
  long n,k;
  cin >> n >> k;
  long a=0;
  for (long i=k; i<n+2; i++){
    a+= i*(2*n-i+1)/2 - i*(i-1)/2 + 1;
  }
  long ans = a % 1000000007;
  cout << ans << endl;
}

Measured memory_bytes: 3588
bingo = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
number = [int(input()) for _ in range(N)]

check = [[0 for _ in range(3)] for _ in range(3)]

for i in range(N):
  for j in range(3):
    for k in range(3):
      if bingo[j][k] == number[i]:
        check[j][k] = 1
        
ans = 'No'
for i in range(3):
  if check[i][0] == 1 and check[i][1] == 1 and check[i][2] == 1:
    ans = 'Yes'
    
for i in range(3):
  if check[0][i] == 1 and check[1][i] == 1 and check[2][i] == 1:
    ans = 'Yes'
    
if check[0][0] == 1 and check[1][1] == 1 and check[2][2] == 1:
  ans = 'Yes'
  
if check[0][2] == 1 and check[1][1] == 1 and check[2][0] == 1:
  ans = 'Yes'
  
print(ans)


Measured memory_bytes: 3064
n,h=int(input()),list(map(int,input().split()));dp=[0]*n;dp[1]=abs(h[1]-h[0])
for i in range(2,n):dp[i]=min(dp[i-2]+abs(h[i-2]-h[i]),dp[i-1]+abs(h[i-1]-h[i]))
print(dp[-1])

Measured memory_bytes: 13928
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
 
using namespace std;
int N, M;
string S;

int main()
{
  int n;
  int ret=0;

  cin >> N >> M;

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define de(x) cout<<#x<<"="<<x<<endl
const int N=1e6+7;
const long long mod=1e9+7;
char s1[55],s2[55];
long long a[55],ans;
int main(){
	int n;
	cin>>n;
	scanf("%s %s",&s1,&s2);
	int p=0;
	for(int i=0;i<n;i++){
		if(s1[i]==s1[i+1]){
			a[p++]=2;i++;
		}else a[p++]=1;
	}
	if(a[0]==2)ans=6;
	else ans=3;
	for(int i=1;i<p;i++){
		if(a[i-1]==1)ans=(ans*2)%mod;
		else if(a[i-1]==2&&a[i]==2){
			ans=(ans*3)%mod;
		}
	}
	cout<<ans<<endl;

}


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

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

    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    cout << a[n-1] - a[0] << endl;
    return 0;
}

Measured memory_bytes: 256
n,q = map(int,input().split())

ki = [[] for _ in range(n)] 
for _ in range(n - 1):
    a, b = map(int, input().split())
    ki[a - 1].append(b-1)
    ki[b - 1].append(a-1)

counter = [0 for _ in range(n)] 

for _ in range(q):
    p, x = map(int, input().split())
    counter[p-1] += x

qux = [0]
flag = [False] * n
flag[0] = True

while qux:
    x = qux.pop()
    for ko in ki[x]:
        if not flag[ko]:
            counter[ko] += counter[x]
            qux.append(ko)
            flag[x] = True

print(" ".join(map(str,counter)))

Measured memory_bytes: 66848
#include <cstdio>
#include <stack>

using namespace std;

int n;
int a[10000];
int i = 0;

int main(void)
{
	stack<int> s;
	while(scanf("%d", &n) != EOF){
		if(n == 0){
			a[i] = s.top();
			s.pop();
			i++;
		}
		else{
			s.push(n);
		}
	}
	
	for(int j = 0; j < i; j++){
		printf("%d\n", a[j]);
	}
	
	return 0;
}

Measured memory_bytes: 1040
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<ll> p(n,0), dis(n,0);
    rep(i,n){ 
        cin >> p[i];
        dis[i] = p[i] - (i+1);
       //cout << dis[i] << " ";
    }

    //cout << endl;
    ll cnt = 0;
    ll zero_cnt = 0;
    rep(i,n){
        if(dis[i] == 0){//pi == i
            zero_cnt++;
        }else{//pi != i
            if(zero_cnt>1){
                if(zero_cnt % 2== 0) cnt += (zero_cnt/2);
                else cnt += ((zero_cnt)/2 + 1);
            }
            else if(zero_cnt == 1)
                cnt += 1;
            
            zero_cnt = 0;
        }
    }

    if(zero_cnt>1){
        if(zero_cnt % 2== 0) cnt += (zero_cnt/2);
        else cnt += ((zero_cnt)/2 + 1);
    }else if(zero_cnt == 1){
        cnt += 1;
    }
            
    cout << cnt <<endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 2010;
int n;
char s[N];
bitset<N> canBeat[N];
bitset<N> lft[N], rgt[N];

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		scanf("%s", s);
		for (int j = 0; j < i; j++)
			if (s[j] == '0')
				canBeat[j][i] = 1;
			else
				canBeat[i][j] = 1;
	}
	for (int i = 0; i < n; i++) {
		lft[i][i] = 1;
		rgt[i][i] = 1;
	}
	for (int len = 2; len <= n; len++) {
		for (int l = 0; l + len <= n; l++) {
			int r = l + len - 1;
			if ((lft[l + 1] & rgt[r] & canBeat[l]).any())
				rgt[r][l] = 1;
			if ((lft[l] & rgt[r - 1] & canBeat[r]).any())
				lft[l][r] = 1;
		}
	}
/*
	bitset<N> w = lft[0] & rgt[n - 1];
	for (int i = 0; i < n; i++)
		printf("%d", (int)w[i]);
	printf("\n");
*/
	printf("%d\n", (int)((lft[0] & rgt[n - 1]).count()));

	return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
int a[200001],c[200002],n,k;
int main(){
	cin>>n>>k;
	register int i,j,t,s,f;
	for(i=1;i<=n;++i){
		cin>>a[i];
		
	}
	for(j=1;j<=k;++j){
		memset(c,0,sizeof(c));
		for(i=1;i<=n;++i){
			++c[max(1,i-a[i])];
			--c[min(n+1,i+a[i]+1)];
		}
		s=0,f=1; 
		for(i=1;i<=n;++i){
			a[i]=s+=c[i];
			if(a[i]<n)f=0;
			//cout<<c[i]<<" ";
		}
		if(f)break;
		//cout<<endl;
		//for(i=1;i<=n;++i)cout<<a[i]<<" ";
		//cout<<endl;
	}
	for(i=1;i<=n;++i){
		cout<<a[i]<<" ";
	}
	
}

Measured memory_bytes: 5164
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define CR cerr<<endl;
#define MOD 1000000007
#define INF 9223372036854775807
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));
signed main(){
	int n; cin >> n;
	vector<int> p(20);
	REP(i, n) cin>> p[i];

	int counter = 0;
	FOR(i, 0, n-2){
		if(p[i] <= p[i+1] and p[i+1] < p[i+2]) ++counter;
		else if(p[i] > p[i+1] and p[i+1] >= p[i+2]) ++counter;
	}

	cout << counter << endl;
}

Measured memory_bytes: 256
// abc157_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, M;
    cin >> N >> M;

    vector<int> d(N, -1);

    REP(i, M) {
        int s, c;
        cin >> s >> c;
        s--;
        if (s >= N) {
            print(-1);
            return 0;
        }

        if (d[s] == -1){
            d[s] = c;
        } else{
            if (d[s] != c){
                print(-1);
                return 0;
            }
        }
    }

    if (N == 1){
        int x = d[0] != -1 ? d[0] : 0;
        print(x);
        return 0;
    }

    if (d[0] == 0){
        print(-1);
        return 0;
    }

    int ans = 0;
    REP(i, N){
        int x;
        if (i == 0){
            x = d[i] != -1 ? d[i] : 1;
        } else{
            x = d[i] != -1 ? d[i] : 0;
        }
        ans = ans * 10 + x;
    }
    print(ans);


    return 0;
}


Measured memory_bytes: 256
from collections import Counter

n = int(input())
a = list(map(int, input().split()))
re = [0] * (n+1)

c = Counter(a)   # c: Counter({1: 3, 2: 2})など
for k, v in c.items():
    re[k] = v*(v-1) // 2

total = sum(re)
for i in a:
    print(total - re[i] + (c[i]-1)*(c[i]-2) // 2)

Measured memory_bytes: 26780
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s, t; cin >> s >> t;
	int ans = 1e9;
	for (int i = 0; i <= s.size() - t.size(); i++) {
		int diff = 0;
		for (int j = 0; j < t.size(); j++)
			if (s[i + j] != t[j]) diff++;
		ans = min(ans, diff);
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename T> void vdeb(T v){
    cout << "#vector set debug" << endl;
    for(auto vv : v) cout << vv << " ";
    cout << endl;
}
template<typename T1, typename T2> void adeb(T1 arr[], T2 n){
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}
template<typename T1> void mdeb(T1 mp){
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
void ans(bool b){ cout << (b ? "Yes" : "No") << endl; }
void ans2(bool b){ cout << (b ? "YES" : "NO") << endl; }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};


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

    ll n;
    cin >> n;

    ll l = 1, r = 10000000;
    ll res = inf;
    while(l + 1 < r){
        ll c = (r + l) / 2;
        ll sum = c * (c+1) / 2;
        if(sum >= n){
            res = min(res, c);
            r = c;
        }else{
            l = c;
        }
    }

    //cout << res << endl;
    
    ll sum = res * (res+1) / 2;
    //cout << sum sp c sp n << endl;

    vector<ll> v;
    repr(i, res, 1){
        if(sum - n < i) v.push_back(i);
        else sum -= i;
    }

    for(auto const& e : v){
        cout << e << endl;
    }

    return 0;
}


Measured memory_bytes: 384
arr=[int(input()),int(input()),int(input()),int(input()),int(input())]
min=99
min_index=-1
for i,t in enumerate(arr):
    t_mod10 = t % 10
    if t_mod10 != 0 and t_mod10 < min:
        min = t_mod10
        min_index = i

sum = 0
for i,t in enumerate(arr):
    if i == min_index:
        sum += t
    else:
        sum += (t + 9) // 10 * 10

print(sum)

Measured memory_bytes: 3064
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

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

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    LL ans = 0;
    rep(i, n) {
        LL a_ = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        LL c_ = n - (upper_bound(c.begin(), c.end(), b[i]) - c.begin());
        ans += a_ * c_;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N; cin >> N;
    vector<int> X(N), Y(N);
    for(int i = 0; i < N; ++i){
        cin >> X[i];
        Y[i] = X[i];
    }
    sort(X.begin(), X.end());
    //for(int i = 0; i < X.size(); ++i) cout << X[i] << " ";
    //cout << endl;
    int target = X[N/2 - 1];
    for(int i = 0; i < N; ++i){
        int now = Y[i];
        if(now <= target){
            if(N != 2) cout << X[N/2] << '\n';
            else cout << X[1] << '\n';
        }
        else{
            cout << target << '\n';
        }
    }
    return 0;
}

Measured memory_bytes: 4768
#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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
using pl = pair<ll,ll>;
signed main(){
	ll n,x; cin>>n>>x;
	vl a(n);
	rep(i,0,n)cin>>a[i];
	vl b=a;
	rep(i,1,n){
		if(a[i]+a[i-1]<=x)continue;
		ll k=(a[i]+a[i-1])-x;
		if(a[i]<k){
			k-=a[i];
			a[i]=0;
			a[i-1]-=k;
		}
		else{
			a[i]-=k;
		}
	}
	ll ans=0;
	rep(i,0,n)ans+=b[i]-a[i];
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int main(int argc, char *argv[])
{
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);

    int N, K;
    cin >> N >> K;

    vector<int> arr(N);
    for (int i = 0; i < N; i++)
        cin >> arr[i];

    vector<int> dp(N, 0);
    for (int i = 1; i < N; i++)
    {
        dp[i] = dp[i - 1] + abs(arr[i] - arr[i - 1]);
        for (int j = 2; j <= K && i >= j; j++)
            dp[i] = min(dp[i], dp[i - j] + abs(arr[i] - arr[i - j]));
    }

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


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        int[][] table = new int[r + 1][c + 1];
        for (int i = 0; i < r; i++) {
            int sum = 0;
            for (int j = 0; j < c; j++) {
                table[i][j] = sc.nextInt();
                sum += table[i][j];
                System.out.print(String.format("%d ", table[i][j]));
            }
            table[i][c] = sum;
            System.out.println(sum);
        }
        for(int j = 0; j < c; j++){
            int sum = 0;
            for(int i = 0; i < r; i++){
                sum += table[i][j];
            }
            table[r][j] = sum;
            System.out.print(String.format("%d ", sum));
        }
        int sum = 0;
        for(int j = 0; j < c; j++){
            sum += table[r][j];
        }
        System.out.println(sum);
    }
}



Measured memory_bytes: 52480
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

//文字列入れ替え、逆順に表示、文字列を配列にひとつずつcharに
public class Main {

    public static void main(String[] args) throws IOException {
        // TODO 自動生成されたメソッド・スタブ
        BufferedReader  br = new  BufferedReader(new InputStreamReader(System.in));

        String inputStr = br.readLine();
        int num = Integer.parseInt(br.readLine());

        for(int i = 0;i < num;i++){
            String[] input = br.readLine().split(" ");
            int beginIndex = Integer.parseInt(input[1]);
            int endIndex = Integer.parseInt(input[2]);

            switch(input[0]){
            case "print":
                System.out.println(inputStr.substring(beginIndex,endIndex+1));
                break;
            case "reverse":
                int cycle = (endIndex - beginIndex)/2;
                char[] inputChar = inputStr.toCharArray();
                for(int j = 0 ;j <= cycle ;j++){
                    char tmp = inputStr.charAt(beginIndex + j);
                    inputChar[beginIndex + j] = inputChar[endIndex - j];
                    inputChar[endIndex - j] = tmp;
                }
                inputStr = String.valueOf(inputChar);
                break;
            case "replace":
                StringBuilder sb = new StringBuilder(inputStr);
                sb.replace(beginIndex, endIndex + 1, input[3]);
                inputStr = sb.toString();
                break;
            }
        }

    }

}



Measured memory_bytes: 24868
#include <bits/stdc++.h>
#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)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int h, w, k;
    cin >> h >> w >> k;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    auto ans = make_vec<int>(h, w);
    vector<int> cnt(h);
    rep(i, h) rep(j, w) if (s[i][j] == '#') cnt[i]++;
    int num = 1;
    rep(i, h) {
        if (!cnt[i]) continue;
        int now = 0;
        rep(j, w) {
            if (s[i][j] == '#') {
                now++;
                ans[i][j] = num;
                if (now != cnt[i]) num++;
            } else {
                ans[i][j] = num;
            }
        }
        num++;
    }
    for (int i = h-2; i >= 0; --i) if (ans[i][0] == 0) {
        rep(j, w) ans[i][j] = ans[i+1][j];
    }
    for (int i = 1; i < h; ++i) if (ans[i][0] == 0) {
            rep(j, w) ans[i][j] = ans[i-1][j];
        }
    rep(i, h) rep(j, w) {
        cout << ans[i][j] << (j == w-1 ? '\n' : ' ');
    }
}


Measured memory_bytes: 3764
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
const long long MAX = (ll)1e5+100;

int main(void) {
   ll N,M;
   cin>>N>>M;
   vector<ll> A(N);
   rep(i,0,N) cin>>A[i];
   // sort(A.begin(),A.end());
   multimap<ll,ll> vB;
   rep(i,0,M) {
      ll b,c;
      cin>>b>>c;
      vB.insert(make_pair(c,b));
   }
   rep(i,0,N) {
      vB.insert(make_pair(A[i],1));
   }
   auto itr = vB.end();
   itr--;
   ll now = 0;
   ll ans = 0;
   while(1) {
      ll n_this = min(N-now, (*itr).second);
      // cout<<n_this<<" "<<(*itr).first<<endl;
      now += n_this;
      ans += n_this * (*itr).first;
      if (now == N) break;
      itr--;
   }
   cout<<ans<<endl;


   return 0;
}

Measured memory_bytes: 13568
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String o = sc.next();
        String e = sc.next();
        int indexO = 0;
        int indexE = 0;
        while (indexO < o.length() || indexE < e.length()) {
            if(indexO < o.length()) {
                System.out.print(o.substring(indexO,indexO+1));
            }
            if(indexE < e.length()) {
                System.out.print(e.substring(indexE,indexE+1));
            }
            indexO++;
            indexE++;
        }
        System.out.println();
    }
}

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

int main(void)
{
    int x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    cout << x << " " << y << " " << z << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void bfs(int s,vector<int> a[],int arr[])
{
    queue<int> q;
    arr[s] = 0;
    q.push(s);
    while(!q.empty())
    {
        int t = q.front();
        q.pop();
        for(int i=0;i<a[t].size();i++)
        {
            if(arr[a[t][i]] == 0)
            {
                q.push(a[t][i]);
                arr[a[t][i]] = t;
            }
        }
    }

}

int main()
{
  int n,m;
  cin>>n>>m;
  vector<int> a[n+1];
  int arr[n+1] = {};
  while(m--)
  {
    int c,d;
    cin>>c>>d;
    a[c].push_back(d);
    a[d].push_back(c);
  }
  bfs(1,a,arr);
  for(int i=2;i<n+1;i++)
    if(arr[i] == 0)
    {
        cout<<"No";
        return 0;
    }
  cout<<"Yes"<<endl;
  for(int i=2;i<n+1;i++)
    cout<<arr[i]<<endl;

}



Measured memory_bytes: 10356
a=0;b=0;c=0
10.times do
  line=gets
  datum=line.chomp!.to_i
  if datum>a
    c=b;b=a;a=datum
  elsif datum>b
    c=b;b=datum
  elsif datum>c
    c=datum
  end
end
puts a
puts b
puts c


Measured memory_bytes: 6864