akhauriyash/Code-Regression huggingface dataset:
def gcd(x, y):
    '''??????????????????????????????
    x>=y?????¨??????gcd(x, y)??¨gcd(y, x%y)?????????????????¨????????¨??????'''

    if x < y:
        tmp = x
        x = y
        y = tmp

    while y > 0:
        tmp = x % y
        x = y
        y = tmp

    return x
    
def test():
    '''??? input =
    147 105
    ->
    21'''

    x, y = map(int, input().split())

    result = gcd(x, y)
    print(result)

if __name__ == '__main__':
    test()

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

int main() {
  int N, x;
  cin >> N >> x;
  int a[100100];
  for (int i = 1; i <= N; i++) cin >> a[i];

  long long ans = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] + a[i + 1] > x) {
      ans += a[i] + a[i + 1] - x;
      a[i + 1] = x - a[i];
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 640
function Main(input) {
    let l = 0;
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});
    let n = parseInt(input[l][0],10);
    while(n !== 0){
        
        let arr_xyzr = [];
        for (let i = 0; i < n; i++){
            arr_xyzr.push(input[l + 1 + i].map(e => parseFloat(e, 10)));
        }

        // console.log(arr_xyzr);

        // let lVl = parseInt(input[0][0], 10);
        // let lEl = parseInt(input[0][1], 10);

        let graph = [];
        for (let i = 0; i < n - 1; i++){
            let tmp =[];
            tmp[0] = i;
            for (let j = i + 1; j < n; j++){
                tmp[1] = j;
                tmp[2] = Math.max(0, Math.sqrt(Math.pow((arr_xyzr[j][0] - arr_xyzr[i][0]), 2) + Math.pow((arr_xyzr[j][1] - arr_xyzr[i][1]), 2) + Math.pow((arr_xyzr[j][2] - arr_xyzr[i][2]), 2)) - arr_xyzr[i][3] - arr_xyzr[j][3]);
                graph.push(tmp.slice());
            }
        }
        graph.sort((a, b) => a[2] - b [2]);
        // console.log(graph);
        let uf = new UnionFind(n);
        let ans = 0;
        for (let i = 0; i < graph.length; i++){
            if (uf.find(graph[i][0]) !== uf.find(graph[i][1])) {
                uf.union(graph[i][0], graph[i][1])
                ans += graph[i][2];
            }
        }
        console.log(ans.toFixed(3));

        l += n + 1;
        n = parseInt(input[l][0],10);
    }

}

function UnionFind (n) {
    this.parents = [];
    for (let i = 0; i < n; i++) {
        this.parents.push(-1);
    }
}

UnionFind.prototype.find = function (x) {
    if (this.parents[x] < 0) return x;
    return this.parents[x] = this.find(this.parents[x]);    
}

UnionFind.prototype.union = function (x, y) {
    x = this.find(x);
    y = this.find(y);
    if (x === y) return;
    if (this.parents[x] > this.parents[y]) [x, y] = [y, x];
    
    this.parents[x] += this.parents[y];
    this.parents[y] = x;
}

UnionFind.prototype.size = function (x) {
    x = this.find(x);
    while (x >= 0) {
        x = this.parents[x];
    }
    return x * -1;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));



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

using namespace std;

int main()
{
    char line[50];
    cin.getline(line,50);
    char a,b,c,d;
    int count=0;
    for(int i=0;i<strlen(line);i++)
    {
        if(line[i]==' ')
        {
            if(count==0)
            {
            a=line[i-1];
            b=line[i+1];
            count=1;
            }
            else
            {
              c=line[i-1];
              d=line[i+1];
            }
        }
    }
    if(a==b && c==d)
    {
        cout<<"YES";
    }
    else{
        cout<<"NO";
    }
    return 0;
}



Measured memory_bytes: 3608
"""
0-1ナップザック
dp[i][j]...i個目までの宝で重さjの時の価値の最大
wi = wlst[i]...i個目の重さ
vi = vlst[i]...i個目の価値
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - wi] + vi)  (wi <= j)
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])                          (wi >  j)
"""


def main():
  case = 0

  while True:
    w = int(input())
    if not w:
      break
  
    case += 1
  
    n = int(input())
  
    vlst = [0]
    wlst = [0]
  
    for _ in range(n):
      vin, win = map(int, input().split(","))
      vlst.append(vin)
      wlst.append(win)

    dp = [[0 for _ in range(w + 1)] for _ in range(n + 1)]
    
    for i in range(1, n + 1):
      vi, wi = vlst[i], wlst[i]
      dpi = dp[i]
      dpim = dp[i - 1]
      for j in range(1, w + 1):
        if j >= wi:
          dpi[j] = max(dpim[j], dpi[j - 1], dpim[j - wi] + vi)
        else:
          dpi[j] = max(dpim[j], dpi[j - 1])
  
    print("Case " + str(case) + ":")
    print(dp[n][w])

    for i in range(w, -1, -1):
      if dp[n][i] != dp[n][w]:
        print(i + 1)
        break

main()


Measured memory_bytes: 16340
n = gets.to_i
h = gets.split.map(&:to_i)
dp = Array.new(n, 0)
dp[0] = 0
dp[1] = (h[1] - h[0]).abs
2.upto(n.pred) do |i|
  dp[i] = [dp[i - 1] + (h[i] - h[i - 1]).abs, dp[i - 2] + (h[i] - h[i - 2]).abs].min
end
puts dp[n - 1]

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

int N;


void solve_1(){
	cout << N*(N-1)/2 - (N-1)/2 << endl;

	for(int i=1;i<=N;i++){
		for(int j=i+1;j<=N;j++){
			if(i+j==N) continue;
			cout << i << " " << j << endl;
		}
	}
}

void solve_2(){
	cout << N*(N-1)/2 - N/2 << endl;

	for(int i=1;i<=N;i++){
		for(int j=i+1;j<=N;j++){
			if(i+j==N+1) continue;
			cout << i << " " << j << endl;
		}
	}
}



int main(){
	cin >> N;
	if(N%2==1) solve_1();
	else solve_2();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
 
int main(){
  int N;
  cin>>N;
  VI A(N),B(N);
  rep(i,N) cin>>A[i];
  rep(i,N) cin>>B[i];
  ll SA=0,SB=0;
  rep(i,N) SA+=A[i];
  rep(i,N) SB+=B[i];
  SB-=SA;
  ll cnt=0;
  ll cnt2=0;
  rep(i,N){
    if(A[i]>B[i]) cnt+=A[i]-B[i];
    else if(A[i]<B[i]) cnt2+=(B[i]-A[i]+1)/2;
  }
  if(cnt<=SB and cnt2<=SB) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 384
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		long startTime = System.currentTimeMillis();
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		long L = sc.nextLong();
		long[][] dist = new long[N][N];
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				if (i == j)
					continue;
				dist[i][j] = Long.MAX_VALUE / 3;
			}
		}
		for (int i = 0; i < M; ++i) {
			int A = sc.nextInt();
			int B = sc.nextInt();
			--A;
			--B;
			long C = sc.nextLong();
			if (C <= L) {
				dist[A][B] = C;
				dist[B][A] = C;
			}
		}
		for (int middle = 0; middle < N; ++middle) {
			for (int i = 0; i < N; ++i) {
				for (int j = 0; j < N; ++j) {
					dist[i][j] = Math.min(dist[i][j], dist[i][middle] + dist[middle][j]);
				}
			}
		}
		long[][] cnt = new long[N][N];
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				if (dist[i][j] <= L)
					cnt[i][j] = 1;
				else
					cnt[i][j] = Long.MAX_VALUE / 3;
			}
		}
		for (int middle = 0; middle < N; ++middle) {
			for (int i = 0; i < N; ++i) {
				for (int j = 0; j < N; ++j) {
					cnt[i][j] = Math.min(cnt[i][j], cnt[i][middle] + cnt[middle][j]);
				}
			}
		}
		int Q = sc.nextInt();
		for (int q = 0; q < Q; ++q) {
			int s = sc.nextInt() - 1;
			int t = sc.nextInt() - 1;
			if (cnt[s][t] == Long.MAX_VALUE / 3) {
				System.out.println(-1);
			} else {
				System.out.println(cnt[s][t] - 1);
			}
		}
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 91192
#include <bits/stdc++.h>
#define read(x) scanf("%d",&x)
typedef long long ll;
using namespace std;
const int maxn = 2e5 + 10;

string s;
int k;

int main()
{
    cin>>s;
    cin>>k;
    int n = s.size();
    if(n==1){
        cout<<k/2<<endl;
        return 0;
    }
    if(s[0]==s[n-1]){
        int head = 0, tail = 0, phead=0,ptail=0;
        int check =0;
        for(int i=0;i<n;i++){
            if(s[i]==s[0]){
                head++;
                check++;
            }
            else {
                phead = i;
                break;
            }
        }
        if(check==n){
            cout<<1ll*n*k/2<<endl;
            return 0;
        }

        for(int i=n-1;i>=0;i--){
            if(s[i]==s[0])
                tail++;
            else{
                ptail = i;
                break;
            }
        }
        int tmp = 1;
        int res = 0;
        for(int i=phead;i<ptail;i++){
            if(s[i]==s[i+1]){
                tmp++;
            }else{
                res += tmp/2;
                tmp =1;
            }
        }
        res += tmp/2;
        //cout<<res<<endl;
        cout<<(1ll*head/2+1ll*res*k+1ll*tail/2+1ll*(head+tail)/2*(k-1))<<endl;
    }else{
        int tmp = 1;
        int res = 0;
        for(int i=0;i<n-1;i++){
            if(s[i]==s[i+1]){
                tmp++;
            }else{
                res += tmp/2;
                tmp=1;
            }
        }
        res += tmp/2;
        cout<<1ll*res*k<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include <bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
 
int main(){
    int n;
    cin >> n;
    int ans = 0;
    REP(i, 1, n){
        int nokori = n - i;
        if(i<nokori) ans ++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    string s;
    int k;
    cin>>s>>k;
    if(k==1) cout<<s[0]<<endl;
    else{
        rep(i,s.size()){
            if(k-1==i){
                cout<<s[i]<<endl;
                break;
            }else{
                if(s[i]!='1'){
                    cout<<s[i]<<endl;
                    break;
                }
            }
        }
    }
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    if (n == 25) {
        cout << "Christmas" << endl;
    } else if (n == 24) {
        cout << "Christmas Eve" << endl;
    } else if (n == 23) {
        cout << "Christmas Eve Eve" << endl;
    } else if (n == 22) {
        cout << "Christmas Eve Eve Eve" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
use std::io;
use std::cmp;

fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s).ok();
    let n = s.trim().parse::<i32>().ok().unwrap();
    s = String::new();
    io::stdin().read_line(&mut s).ok();
    let v: Vec<i32> = s.split_whitespace().map(|cs| cs.parse().ok().unwrap()).collect();
    let mut r: i32 = 0;
    let mut p: i32 = 0;
    for i in 1..n {
        if v[i as usize] <= v[(i-1) as usize] {
            p += 1;
            r = cmp::max(r, p);
        } else {
            p = 0;
        }
    }

    println!("{}", r);
}

Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
  
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 6005, D = 9005, Z = 3001;
ll dp[N][D];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, m;
    cin >> n >> m;

    n *= 3;

    dp[0][Z] = 1;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < D; j++) {
            if (dp[i][j]) {
                if (j + 1 < D) {
                    dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % m;
                }
                if (j > 0 && i + 2 <= n) {
                    dp[i + 2][j - 1] = (dp[i + 2][j - 1] + dp[i][j] * (i + 1)) % m;
                }
                if (i + 3 <= n) {
                    dp[i + 3][j] = (dp[i + 3][j] + dp[i][j] * (i + 2) % m * (i + 1)) % m;
                }
            }
        }
    }

    // cout << dp[2][Z - 1] << "\n";



    ll ans = 0;

    for (int j = Z; j < D; j++) {
        ans = (ans + dp[n][j]) % m;
    }

    cout << ans;

    return 0;   
}   

Measured memory_bytes: 420480
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>

auto& in = std::cin;
auto& out = std::cout;

int32_t H,W;
std::string map[510];
std::string map2[510];
std::string map3[510];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> H>>W;
	map2[0].assign(W, '#'); map2[1].assign(W, '.');
	map3[0].assign(W, '.'); map3[1].assign(W, '#');
	for (int32_t i = 2; i < H; i++) {
		map2[i] = map2[i - 2];
		map3[i] = map3[i - 2];
	}
	for (int32_t i = 0; i < H; i++) {
		map2[i][0] = map3[i][W - 1] = '#';
		map2[i][W - 1] = map3[i][0] = '.';
	}

	for (int32_t i = 0; i < H; i++)
	{
		in >> map[i];
		for (int32_t j = 0; j < W; j++) {
			if (map[i][j] == '#') {
				map2[i][j] = map3[i][j] = '#';
			}
		}
	}

	for (int32_t i = 0; i < H; i++) {
		out << map2[i] << endl;
	}
	out << endl;
	for (int32_t i = 0; i < H; i++) {
		out << map3[i] << endl;
	}

	return 0;
}
#endif


Measured memory_bytes: 1664
#include<stdio.h>
int main(){
int a[5],b[5],x,y,hit=0,blow=0,c[15],i;
while(1){
for(i=0;i<10;i++){
c[i]=0;
}
scanf("%d %d\n",&x,&y);
if(x==0 && y==0){
break;
}
for(i=0;i<4;i++){
a[i]=x%10,b[i]=y%10;
x=x/10,y=y/10;
}
for(i=0;i<4;i++){
if(a[i]==b[i]){
hit++;
}
}
for(i=0;i<4;i++){
c[a[i]]++,c[b[i]]++;
}
for(i=0;i<10;i++){
if(c[i]==2){
blow++;
}
}
blow=blow-hit;
printf("%d %d\n",hit,blow);
hit=0,blow=0;
}
return 0;
}


Measured memory_bytes: 2040
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>
#include <stack>
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
#define rep(i,n) for(int i=0;i<(int)(n);++i)

ll nn,m;
vector<vector<int> > g;
vector<ll> p,q;

template<typename T> class segtree{
private:
    int n,sz;
    vector<T> node;
public:
    segtree(){}
    segtree(vector<T>& v) : sz((int)v.size()){
        n = 1;
        while(n < sz){
            n *= 2;
        }
        node.resize(2*n-1, numeric_limits<T>::max());
        for(int i = 0; i < sz; i++){
            node[i+n-1] = v[i];
        }
        for(int i=n-2; i>=0; i--){
            node[i] = node[i*2+1]*node[i*2+2]%m;
        }
    }
    void update(int k,T a){
    	k += n-1;
    	node[k] = a;
    	while(k>0){
            k = (k-1)/2;
            node[k] = node[2*k+1]*node[2*k+2]%m;
    	}
    }
    T query(int a,int b,int k=0,int l=0,int r=-1){
        if(r < 0) r = n;
    	if(r <= a || b <= l){
            return 1;
    	}
    	if(a <= l && r <= b){
            return node[k];
    	}else{
            T vl = query(a,b,2*k+1,l,(l+r)/2);
            T vr = query(a,b,2*k+2,(l+r)/2,r);
            return vl*vr%m;
    	}
    }
    void print(){
        for(int i = 0; i < sz; i++){
            cout<<query(i,i+1)<< " ";
        }
        cout<<endl;
    }
};

map<int,segtree<ll> > sg;
vector<map<ll,int> > mp;

ll dfs(int k,int pre){
    ll tmp = 1;
    int cnt = 0;
    vector<ll> v;
    for(auto x:g[k]){
        if(x!=pre){
            tmp *= (dfs(x,k)+1)%m;
            tmp %= m;
            mp[k][x] = cnt;
            cnt++;
            v.PB(p[x]+1);
        }
    }
    segtree<ll> sgt(v);
    sg[k] = sgt;
    return p[k] = tmp;
}
void dfs2(int k,int pre){
    if(k==0){
        q[k] = 1;
    }else{
        ll tmp = 1;
        tmp *= sg[pre].query(0,mp[pre][k]);
        tmp %= m;
        tmp *= sg[pre].query(mp[pre][k]+1,mp[pre].size());
        tmp %= m;
        q[k] = (tmp*q[pre]+1)%m;
    }
    for(auto x:g[k]){
        if(x!=pre){
            dfs2(x,k);
        }   
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> nn >> m;
    
    mp.resize(nn);
    g.resize(nn);
    p.resize(nn);
    q.resize(nn);
    rep(i,nn-1){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(0,-1);
    dfs2(0,-1);
    rep(i,nn){
        if(i==0)cout << p[0]%m << "\n";
        else cout << (p[i]*q[i])%m << "\n";
    }
    return 0;
}

Measured memory_bytes: 40960
import java.util.*;
public class Main{
	public static void main(String[] args){
          Scanner sc= new Scanner(System.in);
          int n = sc.nextInt();
          int x = sc.nextInt();
          int t = sc.nextInt();
          int time = 0;
          while(n>0){
            n = n-x;
            time += t;
          }
         System.out.println(time);
  	}
}

Measured memory_bytes: 35656
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
int n;

vector<int> sieve(int n) {
  vector<int> is_prime(n + 1);

  for(int i=0; i<=n; i++) is_prime[i] = 0;
  is_prime[0] = is_prime[1] = 1;

  for(int i=2; i<=n; i++) {
    for(int j=i; j<=n; j+=i) is_prime[j]++;
  }

  return is_prime;
}

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

  cin >> n;

  ll ans = 1;

  vector<int> prime = sieve(n);
  FOR(i, 2, n + 1) {
    ans += ((ll)prime[i] + 1) * i;
  }

  cout << ans << endl;
}


Measured memory_bytes: 42268
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,k,x=0;
  cin >> n >> k;
  int a[n],b[n];
  pair<int,int> p[1000000];
  for(int i=0;i<n;i++){
    cin >> a[i] >> b[i];
    p[i]=make_pair(a[i],b[i]);
  }
  sort(p,p+n);
  for(int i=0;i<n;i++){
    x+=p[i].second;
    if(x>=k){
      cout << p[i].first << endl;
      return 0;
    }
  }
}


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

int main(){
    int N;
    cin >> N;
    vector<int> C(N-1),S(N-1),F(N-1);   
    rep(i,N-1){
        cin >> C[i] >> S[i] >> F[i];
    }

    rep(i,N){
        int t = 0;
        for(int j = i; j < N-1; j++){
            if(t < S[j])t = S[j];
            else if(t%F[j] == 0);
            else t = t + F[j] - t % F[j];
            t += C[j];
        }
        cout << t << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef long int li;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<ll, ll>P;
#define PI 3.14159265359
#define MOD 998244353
const int MAX = 510000;

int main() {
  ll N;cin>>N;
  vector<int>C(N);
  vector<int>S(N);
  vector<int>F(N);
  rep(i,N-1){cin>>C[i+1]>>S[i+1]>>F[1+i];}
  for(int i=1;i<N;i++){
  	ll time=S[i]+C[i];
  	for(int j=i+1;j<N;j++){
    	if(S[j]>=time){time=S[j]+C[j];}
      	else{
        	ll x=time/F[j];
        	ll y=time%F[j];
          	if(y==0){time=(F[j]*x)+C[j];}
          	else{time=(F[j]*(x+1))+C[j];}
        }
    }
    cout<<time<<endl;
  }
  cout<<0;
}

Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,A,B=MI()
    print(min(A,B), max(0,A+B-N))

if __name__ == '__main__':
    main()

Measured memory_bytes: 38512
n,m=map(int,input().split())
a={int(input()) for i in range(m)}
dp=[0]*(n+2)
num=10**9+7
dp[0]=1
for i in range(n):
    if i in a:
        dp[i]=0
    else:
        dp[i]=dp[i]%num
        if i<n:
            dp[i+1]+=dp[i]
            dp[i+2]+=dp[i]
print(dp[-2]%num)

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


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

	vector<pair<string, LL>> st(n);
	LL sum = 0;
	for (auto &e : st) {
		cin >> e.first >> e.second;
		sum += e.second;
	}

	string s;
	cin >> s;
	LL cnt = 0;
	for (LL i = 0; i < n; ++i) {
		cnt += st[i].second;
		if (st[i].first == s) {
			break;
		}

	}

	cout << sum-cnt << endl;

}

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

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

int main()
{
    int k;cin>>k;
    ll ans=0;
    repd(i,1,k+1){
        repd(j,1,k+1){
            repd(l,1,k+1){
                ans += gcd(i,gcd(j,l));
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include <iostream>

int main() {
	int n;
	
	while (std::cin >> n, n) {
		int ans = 0;

		for (int i = 0; i < n / 4; ++i) {
			int x;
			std::cin >> x;

			ans += x;
		}

		std::cout << ans << std::endl;
	}
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#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 itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;


int main(){
    int d;
    cin >> d;
    if(d==25) cout << "Christmas" << endl;
    else if(d == 24) cout << "Christmas Eve" << endl;
    else if(d==23) cout << "Christmas Eve Eve" << endl;
    else cout << "Christmas Eve Eve Eve" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int area(int d)
{
    int i,s,sum=0;
    
    for(i=1;i<=(600-d)/d;i++)
    {
        s=((i*d)*(i*d))*d;
        sum=sum+s;
    }
    return sum;
}

int main(void){
    int d;
    
    while(scanf("%d",&d)!=EOF)
    {
        printf("%d\n",area(d));
    }
    
    return 0;
}



Measured memory_bytes: 2044
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long LL;
int main() {
    int n,k;
    scanf("%d%d",&n,&k);
    if(n%k==0)
        printf("0\n");
    else
        printf("1\n");
    return 0;
}


Measured memory_bytes: 128
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = ins()
nrev = n[::-1]
m = len(n)
l = [0]*(m+1)
r = [0]*(m+1)
r[m] = 1
for k in range(m,0,-1):
    p = int(nrev[k-1])
    l[k-1] = min(l[k]+p, r[k]+10-p)
    if k>0:
        r[k-1] = min(l[k]+p+1, r[k]+10-p-1)
print(l[0])


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

inline int powi(int x,int y) {int p=1; while(y--) p*=x; return p;}

int main()
{
    int A,B,C,K; cin >>A>>B>>C>>K;
    
    cout << A + B + C + max({A, B, C}) * (powi(2, K) - 1) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solveA();
		// new Main().solveB();
		// new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		int numRating = 0;

		try {
			scanner = new Scanner(System.in);
			numRating = scanner.nextInt();

			if (numRating < 1200) {
				System.out.println("ABC");
			} else if (numRating < 2800) {
				System.out.println("ARC");
			} else {
				System.out.println("AGC");
			}

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 21716
import itertools

n, m = map(int, input().split())
h = [[0]*n for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    h[a-1][b-1] = 1
    h[b-1][a-1] = 1

ans = 0
x = list(itertools.permutations(range(1, n+1)))
for i in range(len(x)):
    if x[i][0] == 1:
        for j in range(n-1):
            if h[x[i][j]-1][x[i][j+1]-1] == 0:
                break
        else:
            ans += 1
print(ans)

Measured memory_bytes: 14008
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define INF (ll)1000000007
// chmax chmin
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; }

typedef VVI Edge;
Edge e(8);
int ans = 0;

void dfs(int node, set<int> s){

    for(auto child : e[node]){
        if(s.find(child)!=s.end()){
            s.erase(child);
            dfs(child, s);
            s.insert(child);
        }
    }

    if(s.size() == 0) ans++;
}

int main(void){

    int N, M;
    cin >> N >> M;
    int a[M], b[M];
    REP(i,M){
        cin >> a[i] >> b[i];
        e[a[i]-1].push_back(b[i]-1);
        e[b[i]-1].push_back(a[i]-1);
    }

    set<int> s;
    REP(i,N) s.insert(i);
    s.erase(0);
    dfs(0, s);

    cout << ans << endl;

    return 0;
}

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

int main(){
    int a; cin >> a;
    int b; cin >> b;
    int ans;
    if(a >= 13){
        ans = b;
    }
    else if(6 <= a <= 12){
        ans = b/2;
    }
    if(a <= 5){
        ans = 0;
    }
    cout << ans << endl;
}

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

int main(){
  vector<vector<vector< int > > > vec(4, vector<vector< int > >(3, vector< int >(10, 0)));
  int N;
  cin >> N;
  int b, f, r, v;
  for(int i = 0; i < N; i++){
    cin >> b >> f >> r >> v;
    vec.at(b - 1).at(f - 1).at(r - 1) += v;
  }

  for(int i = 0; i < 4; i++){
    for(int j = 0; j < 3; j++){
      for(int k = 0; k < 10; k++){
        cout << " " << vec.at(i).at(j).at(k);
        if(k == 9){
          cout << endl;
        }
      }
    }
    if(i != 3){
      cout << "####################" << endl;
    }
  }
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
long long A[2003];
int main(){
  int n;
  cin>>n;
  for(int i = 0 ; i < n ; i ++)cin>>A[i];
  long long ans = 0;
  sort(A,A+n);
  for(int i = 0 ; i < n ; i ++){
    for(int j = i + 1 ; j < n ; j ++){
      int l = j+1,r = n-1,temp = j;
      while(l <= r){
        int mid = (l+r)/2;
        if(A[i]+A[j] > A[mid]){
          temp = mid;
          l = mid+1;
        }
        else r = mid-1;
      }
      ans += temp-j;
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

vector <int> v;
int hom;

int main(){
        while(cin >> hom){
                v.push_back(hom);
        }
        sort(v.begin(), v.end() );
        for(int i=v.size()-1;i>v.size()-4;i--){
                cout << v[i] << endl;
        }
}

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

public class Main {

    private static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(final String[] args) throws IOException {
        FastReader in = new FastReader();
        PrintWriter out = new PrintWriter(System.out, true);

        int a = in.nextInt();
        int b = in.nextInt();

        if (a <= 8 && b <= 8) {
            out.println("Yay!");
        } else {
            out.println(":(");
        }
    }

}


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

int main() {
  int N;
  cin >> N;
  vector<int> p(N);
  for (int i = 0; i < N; ++i) cin >> p[i], --p[i];
  int res = 0;
  for (int i = 1; i+1 < N; ++i) {
    vector<int> q = {p[i-1], p[i], p[i+1]};
    sort(q.begin(), q.end());
    if (p[i] == q[1]) ++res;
  }
  cout << res << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
int tent(vector<pair<int, int>> v) {
    int res = 0;
    for(int i = 0; i < v.size(); i++) {
        for(int j = 0; j < i; j++) {
            if(v[j].second > v[i].second) {
                res++;
            }
        }
    }
    return res;
}
int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> a(n), b(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i].first;
        a[i].second = i;
    }
    for(int i = 0; i < n; i++) {
        cin >> b[i].first;
        b[i].second = i;
    }
    int ans = 114514;
    for(int k = 0; k < (1 << n); k++) {
        int bit = k;
        vector<pair<int, int>> odd, even;
        for(int i = 0; i < n; i++) {
            if(bit % 2 == 0) {
                if(i % 2 == 0) {
                    even.push_back(a[i]);
                } else {
                    even.push_back(b[i]);
                }
            } else {
                if(i % 2 == 0) {
                    odd.push_back(b[i]);
                } else {
                    odd.push_back(a[i]);
                }
            }
            bit /= 2;
        }
        if(odd.size() == n / 2) {
            sort(all(odd));
            sort(all(even));
            vector<pair<int, int>> v(n);
            for(int i = 0; i < n; i++) {
                if(i % 2 == 0) {
                    v[i] = even[i / 2];
                } else {
                    v[i] = odd[i / 2];
                }
            }
            bool flag = true;
            for(int i = 0; i < n - 1; i++) {
                if(v[i].first > v[i + 1].first) {
                    flag = false;
                    break;
                }
            }
            if(flag) {
                /*
                for(auto e : v) {
                    cout << e.first << " ";
                }
                cout << endl;
                for(auto e : v) {
                    cout << e.second << " ";
                }
                cout << endl;
                cout << tent(v) << endl;
                */
                ans = min(ans, tent(v));
            }
        }
    }
    if(ans == 114514) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define PI 3.1415926535
int dim;
 
 
void Koch(double, double, double, double, int);
 
 
int main(){
  int i;
  double x1=0,y1=0,x2=100,y2=0;
   
  scanf("%d",&dim);
 
  printf("%1.8f %1.8f\n",x1,y1);
   
  if(0<=dim || dim<=6){
    Koch(x1,y1,x2,y2,dim);
  }
   
  printf("%1.8f %1.8f\n",x2,y2);
   
  return 0;
}
 
 
 
 
 
void Koch(double x1, double y1, double x2, double y2, int dim)
{
  double x3=0, y3=0, x4=0, y4=0, x5=0, y5=0;
  double s , c;
   
  if(dim != 0){
    s = sin(PI/3);
    c = cos(PI/3);
 
 
 
  x3 = ( 2*x1 +   x2 ) / 3;
  y3 = ( 2*y1 +   y2 ) / 3;
  x5 = (   x1 + 2*x2 ) / 3;
  y5 = (   y1 + 2*y2 ) / 3;
  x4 = x3 + (x5-x3)*c + (y5-y3)*s;
  y4 = y3 - (x5-x3)*s + (y5-y3)*c;
  Koch( x1, y1, x3, y3, dim-1 );
  printf("%1.8f %1.8f\n",x3,fabs(y3));
  Koch( x3, y3, x4, y4, dim-1 );
  printf("%1.8f %1.8f\n",x4,fabs(y4));
  Koch( x4, y4, x5, y5, dim-1 );
  printf("%1.8f %1.8f\n",x5,fabs(y5));
  Koch( x5, y5, x2, y2, dim-1 );
}
  return;
}

Measured memory_bytes: 644
//#define _USE_MATH_DEFINES
#include <iostream>
//#include <stdio.h>
//#include <iomanip>
//#include <vector>
//#include <string>
//#include <algorithm>
//#include <functional>
//#include <cmath>

using namespace std;


int main(){

	int n;
	int cnt;

	while (cin >> n){
		cnt = 0;
		for (int i = 0; i < 10; i++){
			for (int j = 0; j < 10; j++){
				for (int k = 0; k < 10; k++){
					for (int l = 0; l < 10; l++){
						if ((i + j + k + l) == n) cnt++;
					}
				}
			}
		}
		cout << cnt << endl;
	}


	return 0;
}

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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    ll n,a=0,b=0,c=0,d=0;
    string s;
    cin >> n;

    for(int i=1; i<=n; i++)
    {
        cin >> s;
        if (s=="AC") a++;
        else if (s=="TLE") b++;
        else if (s=="WA") c++;
        else d++;
    }

    cout << "AC x " << a << '\n';
    cout << "WA x " << c << '\n';
    cout << "TLE x " << b << '\n';
    cout << "RE x " << d << '\n';

    return 0;
}

Measured memory_bytes: 3652
def calc_fee(l):
    s = 0
    for i in range(len(l)-1):
        s += abs(l[i+1] - l[i])
    return s

n = int(input())
A = [0] + [int(n) for n in input().split()] + [0]


total_fee = calc_fee(A)

for i in range(1, n+1):
    price = total_fee - (abs(A[i] - A[i-1]) + abs(A[i+1] - A[i]))  + abs(A[i+1] - A[i-1])
    print(price)

Measured memory_bytes: 14048
from sys import stdin
import sys
A,B = map(int, stdin.readline().rstrip().split())
sys.setrecursionlimit(2000)
def search(x):
    p = (x*0.08)//1
    q = (x*0.10)//1
    if p==A and q==B:
        print(x)
        exit()
    elif p > A and q > B:
        print(-1)
    else:
        search(x+1)

search(1)


Measured memory_bytes: 3828
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long[] values = new long[] { 1, 0, -1 };

            long result = 0;
            for (int i = 0; i < 3; i++)
            {
                if (inputLongArray[3] <= 0) break;

                var kIsBigger = inputLongArray[i] <= inputLongArray[3];
      
                var iteration = kIsBigger ? inputLongArray[i] : inputLongArray[3];
                result += GetSum(iteration, values[i]);
                inputLongArray[3] = inputLongArray[3] - inputLongArray[i];
            }

            Console.WriteLine(result.ToString());

            Console.Out.Flush();
        }

        static long GetSum(long itrNum, long val) 
        {
            long result = 0;
            for (int i = 0; i < itrNum; i++)
            {
                result += val;
            }

            return result;
        }
    }
}


Measured memory_bytes: 28188
#include <stdio.h>
#include <string.h>

#define TOP 1
#define NORTH 2
#define EAST 3
#define WEST 4
#define SOUTH 5
#define BOTTOM 6

struct dice {
  int num[6 + 1];
  int top, n, e, w, s, bottom;
  int tmp;
};

void dice_init(struct dice *d);
void dice_move(struct dice *d, char move);
void dice_move_str(struct dice *d, const char *str);
int dice_label(struct dice *d, int n);
int dice_location(struct dice *d, int label);
int dice_judge(struct dice *d1, struct dice *d2);

int main(int argc, char *argv[])
{
  struct dice d1, d2;
  int i, j;
  char *set[] = {"S", "", "WS", "ES", "SS", "N"};
  int res = 0;

  dice_init(&d1);
  dice_init(&d2);

  for (i = 1; i <= 6; i++) scanf("%d", &(d1.num[i]));
  for (i = 1; i <= 6; i++) scanf("%d", &(d2.num[i]));

  for (i = 0; i < 6; i++) {
    dice_init(&d2);
    dice_move_str(&d2, set[i]);

    for (j = 0; j < 4; j++) {
      dice_move(&d2, 'W');
      if ((res = dice_judge(&d1, &d2)) == 1) break;
    }
    if (res == 1) break;
  }

  if (res == 1) printf("Yes\n");
  else printf("No\n");

  return 0;
}

void dice_init(struct dice *d)
{
  d->top = 1;
  d->n = 5;
  d->e = 3;
  d->w = 4;
  d->s = 2;
  d->bottom = 6;
}

void dice_move(struct dice *d, char move)
{
  switch (move) {
  case 'N':
    d->tmp = d->top;
    d->top = d->s;
    d->s = d->bottom;
    d->bottom = d->n;
    d->n = d->tmp;
    break;

  case 'E':
    d->tmp = d->top;
    d->top = d->w;
    d->w = d->bottom;
    d->bottom = d->e;
    d->e = d->tmp;
    break;

  case 'W':
    d->tmp = d->top;
    d->top = d->e;
    d->e = d->bottom;
    d->bottom = d->w;
    d->w = d->tmp;
    break;

  case 'S':
    d->tmp = d->top;
    d->top = d->n;
    d->n = d->bottom;
    d->bottom = d->s;
    d->s = d->tmp;
    break;

  default:
    break;
  }
}

void dice_move_str(struct dice *d, const char *str)
{
  int i;

  for (i = 0; i < strlen(str); i++) dice_move(d, str[i]);
}

int dice_label(struct dice *d, int n)
{
  int i;

  for (i = 6; i > 0; i--) {
    if (d->num[i] == n) return i;
  }
  return i;
}

int dice_location(struct dice *d, int label)
{
  if (d->top == label) return TOP;
  else if (d->n == label) return NORTH;
  else if (d->e == label) return EAST;
  else if (d->w == label) return WEST;
  else if (d->s == label) return SOUTH;
  else if (d->bottom == label) return BOTTOM;
  else return 0;
}

int dice_judge(struct dice *d1, struct dice *d2)
{
  int correspond = 0;

  if (d1->num[d1->top] == d2->num[d2->top]) correspond++;
  if (d1->num[d1->n] == d2->num[d2->n]) correspond++;
  if (d1->num[d1->e] == d2->num[d2->e]) correspond++;
  if (d1->num[d1->w] == d2->num[d2->w]) correspond++;
  if (d1->num[d1->s] == d2->num[d2->s]) correspond++;
  if (d1->num[d1->bottom] == d2->num[d2->bottom]) correspond++;

  if (correspond == 6) return 1;
  else return 0;
}

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

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

    deque<int> d;
    for (int i = 0; i < N; i++) {
        int p = lower_bound(d.begin(), d.end(), A[i]) - d.begin();
        if (p == 0) {
            d.push_front(A[i]);
        } else {
            d[p - 1] = A[i];
        }
    }

    cout << d.size() << endl;
    return 0;
}

Measured memory_bytes: 1024
N = int(input())
sl, tl = [], []
for _ in range(N):
    s, t = input().split()
    sl.append(s)
    tl.append(int(t))
X = input()
ind = sl.index(X)
if ind == N - 1:
    print(0)
else:
    print(sum(tl[ind + 1:]))


Measured memory_bytes: 3060
#include <stdio.h>
#include <string.h>

int max(int a, int b)
{
    if (a > b){
        return (a);
    }
    return (b);
}

int main(void)
{
    int len[100001], dp[100001];
    int mlen;
    int n, r;
    int i, j;
    int ans;
    
    scanf("%d%d", &n, &mlen);
    
    for (i = 0; i < n; i++){
        scanf("%d", &len[i]);
    }
    
    r = n;
    
    memset(dp, 0, sizeof(dp));
    ans = 0;
    while (r){
        for (i = 0; i < n; i++){
            if (i != 0 && i != n - 1){
                if (dp[i] == 0 && (len[i - 1] < len[i] || dp[i - 1] != 0) && (len[i + 1] < len[i] || dp[i + 1] != 0)){
                    dp[i] = (mlen - len[i]) + max(dp[i - 1], dp[i + 1]);
                    ans = max(ans, dp[i]);
                    r--;
                }
            }
            else if (i == 0){
                if (dp[i] == 0 && (len[i + 1] < len[i] || dp[i + 1] != 0)){
                    dp[i] = (mlen - len[i]) + dp[i + 1];
                    ans = max(ans, dp[i]);
                    r--;
                }
            }
            else {
                if (dp[i] == 0 && (len[i - 1] < len[i] || dp[i - 1] != 0)){
                    dp[i] = (mlen - len[i]) + dp[i - 1];
                    ans = max(ans, dp[i]);
                    r--;
                }
            }
        }
    }
    
    printf("%d\n", ans);
    
    return (0);
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <ctime>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

bool in(ll y, ll x, ll h, ll w){
    return 0 <= y && y < h && 0 <= x && x < w;
}

bool removed[505][505];

int main(){
    ll n; cin >> n;
    ll N = n * n;
    vl p(N); rep(i,N) cin >> p[i];
    vvl a(n,vl(n,linf));
    rep(i,n){
        rep(j,n){
            chmin(a[i][j], i);
            chmin(a[n-i-1][j], i);
            chmin(a[j][i], i);
            chmin(a[j][n-i-1], i);
        }
    }
    ll ans = 0;
    rep(i,N){
        p[i]--;
        ll sy = p[i] / n;
        ll sx = p[i] % n;
        ans += a[sy][sx];
        removed[sy][sx] = true;
        queue<P> q;
        rep(j,4){
            ll ny = sy + dy[j];
            ll nx = sx + dx[j];
            if(in(ny,nx,n,n) && a[ny][nx] > a[sy][sx]){
                a[ny][nx] = a[sy][sx];
                q.emplace(ny,nx);
            }
        }
        while(!q.empty()){
            P p = q.front(); q.pop();
            ll y = p.first;
            ll x = p.second;
            rep(j,4){
                ll ny = y + dy[j];
                ll nx = x + dx[j];
                if(in(ny,nx,n,n) && a[ny][nx] > a[y][x] + !removed[y][x]){
                    a[ny][nx] = a[y][x] + !removed[y][x];
                    q.emplace(ny,nx);
                }
            }
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 7360
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,k = inpl()
a = inpl()
k -= 1
print((n-1+k-1)//k)

Measured memory_bytes: 95324