akhauriyash/Code-Regression huggingface dataset:
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      n: usize,
      m: usize,
      xy: [(usize, usize); m]
   }
   let mut to = vec![vec![]; n];
   let mut d = vec![0; n];
   for (x, y) in xy {
      to[x - 1].push(y - 1);
   }
   let mut ans = 0;
   for v in 0..n {
      dfs(v, &mut d, &to);
      ans = std::cmp::max(ans, d[v]);
   }
   println!("{}", ans);
}

fn dfs(v: usize, d: &mut Vec<usize>, to: &Vec<Vec<usize>>) {
   if d[v] == 0 {
      let mut x = 0;
      for &u in to[v].iter() {
         dfs(u, d, to);
         x = std::cmp::max(x, d[u] + 1);
      }
      d[v] = x;
   }
}


Measured memory_bytes: 15228
#include<iostream>
using namespace std;
using ll = long long;

int N, W;
ll w[110], v[110], INF = 1000000000000, dp[100100], V_SUM, ans = 0;

int main(){
	cin >> N >> W;
	for (int i = 0; i < N; i++)cin >> w[i] >> v[i], V_SUM += v[i];
	for (int i = 0; i <= V_SUM; i++)dp[i] = INF;
	dp[0] = 0;
	for (int i = 0; i < N; i++){
		for (int j = V_SUM; j >= 0 && j >= v[i]; j--){
			dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
		}
	}
	for (int i = 0; i <= V_SUM; i++)ans = (dp[i] <= W ? i : ans);
	cout << ans << endl;
}

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

using namespace std;

long a[3][1111], d[111111];
int main() {
	int x[3], k, c = 0;
	cin >> x[0] >> x[1] >> x[2] >> k;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < x[i]; j++)
			scanf("%ld", a[i] + j);
		sort(a[i], a[i] + x[i], greater<long>());
	}
	for (int i = 1; i <= x[0]; i++) {
		if (i > k) break;
		for (int j = 1; j <= x[1]; j++) {
			if (i*j > k) break;
			long b = a[0][i - 1] + a[1][j - 1];
			for (int l = 1; l <= x[2]; l++) {
				if (i*j > k / l) break;
				d[c++] = b + a[2][l - 1];
			}
		}
	}
	nth_element(d, d + k, d + c, greater<long>());
	sort(d, d + k, greater<long>());
	for (int i = 0; i < k; i++)
		cout << d[i] << '\n';
	cout << flush;
	return 0;
}


Measured memory_bytes: 1152
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, islice
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')

N, W = MAP()
wv = [LIST() for _ in range(N)]

dp = np.zeros(W+1, dtype=np.int64)
for w, v in wv:
	np.maximum(dp[w:], dp[:-w]+v, out=dp[w:])

print(dp[W])


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

int N;

int main() {
    cin >> N;

    int ans;
    for (int i = 7; i >= 0; i--) {
        if ((int)pow(2, i) <= N) {
            ans = (int)pow(2, i);
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
S = input()
A,B,C,D = int(S[0]),int(S[1]),int(S[2]),int(S[3])
#adhoc
if A+B+C+D == 7:
    print(str(A)+"+"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
elif A+B+C-D == 7:
    print(str(A)+"+"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif A+B-C+D == 7:
    print(str(A)+"+"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
elif A-B+C+D == 7:
    print(str(A)+"-"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
elif A+B-C-D == 7:
    print(str(A)+"+"+str(B)+"-"+str(C)+"-"+str(D)+"=7")
elif A-B+C-D == 7:
    print(str(A)+"-"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif A-B-C+D == 7:
    print(str(A)+"-"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
elif A-B-C-D == 7:
    print(str(A)+"-"+str(B)+"-"+str(C)+"-"+str(D)+"=7")

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] vs = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
            int A = vs[0];
            int B = vs[1];
            int C = vs[2];

            int ans = Math.Max(0, C - (A - B));
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11348
typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;

int main() {
    string t;
    std::cin >> t;
    for (int i = 0; i < t.size(); i++) {
        if(t[i]=='?')t[i]='D';
    }
    std::cout << t << std::endl;
}


Measured memory_bytes: 3728
from functools import reduce

def main():
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    a = a.replace(',',' ')
    print(a)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    vi cnt(26,0);
    string  s; cin >> s;
    int ans=100;
    for (int i=25;i>=0;i--){
        int cur=0;
        char ch=i+'a';
        for (int j=0,t=0;j<sz(s);j++){
            if (s[j] == ch) t=0;
            else t++;
            cur = max(cur,t);
        }
        ans = min(ans,cur);
    }
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}
/*
    serval -> srraa -> rrra -> rrr;
*/


Measured memory_bytes: 3592
#include "bits/stdc++.h"
 
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll,ll>;
using str = string;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;


signed main(){
    llin(n);
    vll a(n);
    map<ll,ll> m;
    ll k=0;
    FOR(i,0,n-1){
        cin >>a[i];
        if(m[a[i]]>0){
            m[a[i]]=m[a[i]]+1;
        }else{
            m[a[i]]=1;
        }
    }
    rSORT(a);
    FOR(i,0,n-1){
        FOR(j,0,50){
            if (a[i]<ll(pow(2,j))){
                if(ll(pow(2,j))!=ll(a[i]*2)){
                    while(m[ll(pow(2,j))-a[i]]>0&&m[a[i]]>0){
                     k++;
                     m[ll(pow(2,j))-a[i]]=m[ll(pow(2,j))-a[i]]-1;
                     m[a[i]]=m[a[i]]-1;
                 }
                }else{
                    while(m[ll(pow(2,j))-a[i]]>1){
                     k++;
                     m[a[i]]=m[a[i]]-2;
                 }
                }
                break;
            }
        }
    }
    sal(k);
}


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

int n,m;

int main() {
  cin >> n >> m;
  if (n == m) {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
// atcoder/abc150/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

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

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

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

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

  int n, m;
  while (cin >> n >> m) {
    vector<lli> a(n);
    cin >> a;
    each (i, a) i /= 2;

    set<int> s;
    each (i, a) s.insert(__builtin_ctzll(i));
    if (s.size() != 1) {
      cout << 0 << endl;
      continue;
    }

    lli x = 1;
    each (i, a) {
      x = (x * i) / __gcd(x, i);
    }
    lli z = (m / x + 1) / 2;
    cout << z << endl;
  }

  return 0;
}


Measured memory_bytes: 1024
n = int(input())
L = list(map(int, input().split()))
L.insert(0, 0)
L.append(0)
S = 0
for i in range(1, n + 2):
    S += abs(L[i] - L[i - 1])
T = [0] * n
for j in range(1, n + 1):
    T[j - 1] = abs(L[j + 1] - L[j - 1]) - abs(L[j] - L[j - 1]) - abs(L[j + 1] - L[j])
for k in range(n):
    print(S + T[k])


Measured memory_bytes: 14048
import numpy as np
#import functools
#import operator
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as comb_with
#from itertools import permutations as perm
#import collections as C #most_common
import math
#import sympy

#N = int(input())
X,K,D= map(int,input().split())
#L = list(map(int,input().split()))
#S = str(input())
#T = str(input())
c,C=0,0

X=abs(X)

if X-D*K>=0:
    print(X-D*K)

else:
    x = math.ceil(X/D)

    if x%2==0:
        if K%2==0:
            print(abs(X-D*x))
        else:
            print(abs(X-D*(x-1)))

    else:
        if K%2==0:
            print(abs(X-D*(x-1)))
        else:
            print(abs(X-D*x))


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

int main(){
  int n,m;
  cin >> n >> m;
  int t[n];
  int a[30][30];
  for(int i=0;i<n;i++){
    cin >> t[i];
    for(int j=0;j<t[i];j++){
      cin >> a[i][j];
    }
  }
  int ans=0;
  for(int i=1;i<=m;i++){
    int count=0;
    for(int j=0;j<n;j++){
      for(int k=0;k<t[j];k++){
        if(i==a[j][k]){
          count++;
        }
      }
    }
    if(count==n){
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const int INTMAX = 2147483647;
const int INTMIN = -2147483648;
const unsigned int UINTMAX = 4294967295;
const long LONGMAX = 9223372036854775807;
const long LONGMIN = -9223372036854775808;
const unsigned long ULONGMAX = 18446744073709551615;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

int dig(int n, int a) {return n/(int)pow(10,a)%10;}
int digl(long n, int a) {return n/(long)pow(10,a)%10;}
int digsum(int n) {int r=0;REP(i,10){r+=dig(n,i);}return r;}
int digsuml(long n) {int r=0;REP(i,19){r+=digl(n,i);}return r;}
int dignum(int n) {return n?to_string(n).length():0;}
int dignuml(long n) {return n?to_string(n).length():0;}

int main(){
  int n,k,max=1,min=10e9;
  cin >> n;
  REP(i,n){
    cin >> k;
    if(k>max)max=k;
    if(k<min)min=k;
  }
  cout << max-min;
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    N = II()
    A = LI()
    Q = II()
    memo = {}
    sm = 0
    for a in A:
        memo[a] = memo.get(a, 0) + 1
        sm = sm + a
    # print(memo, sm)
    for i in range(Q):
        b, c = MI()
        cnt = memo.get(b, 0)
        if cnt == 0:
            print(sm)
            continue
        sm = sm - b * cnt + c * cnt
        memo[b] = 0
        memo[c] = memo.get(c, 0) + cnt
        print(sm)


if __name__ == '__main__':
    solve()


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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<60;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

ll s;

ll Count(ll x){
	ll cnt=x/3*4+x/5*4,n=1;
	if(cnt>s) return cnt;
	rep(i,0,18){
		ll a;
		if(n*10>x){
			a=x;
			cnt+=(x-n+1-(a/3-(n-1)/3)-(a/5-(n-1)/5)+(a/15-(n-1)/15))*(i+1);
			break;
		}
		a=n*10-1;
		cnt+=(i+1)*(a-n+1-(a/3-(n-1)/3)-(a/5-(n-1)/5)+(a/15-(n-1)/15));
		if(cnt>s) return cnt;
		n*=10;
	}

	dump(cnt);
	return cnt;
}


void Solve(){
	cin >> s;

	ll lb=0,ub=INF_;
	while(ub-lb>1){
		dump(lb);
		dump(ub);
		ll m=(lb+ub)/2;
		if(Count(m)<s) lb=m;
		else ub=m;
	}
	dump(lb);
	dump(ub);

	string ans;
	rep(i,1,21){
		if((lb+i)%3==0&&(lb+i)%5==0) ans+="FizzBuzz";
		else if((lb+i)%3==0) ans+="Fizz";
		else if((lb+i)%5==0) ans+="Buzz";
		else{
			stringstream ss;
			ss << (lb+i);
			string tmp;
			ss >> tmp;
			ans+=tmp;
		}
	}
	dump(ans);
	dump(Count(lb));
	cout << ans.substr(s-Count(lb)-1,20) << endl;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	Solve();
	return 0;
}

Measured memory_bytes: 1220
import bisect
N = int(input())

six = []
nine = []

now = 6
while now < 100001:
  six.append(now)
  now *= 6
  
now = 9
while now < 100001:
  nine.append(now)
  now *= 9  

#print(six, nine)  
#[6, 36, 216, 1296, 7776, 46656] [9, 81, 729, 6561, 59049]

def coin(n):
  if n < 6:
    return n
  else:
    index_six = bisect.bisect_right(six, n)
    index_nine = bisect.bisect_right(nine, n)
    #print(n, index_six, index_nine, count)
    #print(n, n - six[index_six - 1], n - nine[index_nine - 1])
    if n - six[index_six - 1] >= 0:
      alpha = coin(n - six[index_six - 1]) + 1
    else:
      alpha = 10 ** 7
    if n - nine[index_nine - 1] >= 0:
      beta = coin(n - nine[index_nine - 1]) + 1
    else:
      beta = 10 ** 7
    return min(alpha, beta)
  
print(coin(N))  
    
    
    
    
  
  
  
  

Measured memory_bytes: 9012
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 1000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

signed main(void) {
    int N;
    cin >> N;
    double sum = 0;
    rep(i, N) {
        double x;
        string u;
        cin >> x >> u;
        if (u == "JPY") {
            sum += x;
        } else {
            sum += 380000.0 * x;
        }
    }
    printf("%.7lf\n", sum);
    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

fn main() {
  let n = read::<String>();
  let mut ans = String::new();

  for i in n.chars() {
    if i == '9' {
      ans.push('1')
    } else if i == '1' {
      ans.push('9')
    } else {
      ans.push(i)
    }
  }

  println!("{}", ans);

}



Measured memory_bytes: 4352
# -*- coding: utf-8 -*-

N,x = list(map(int, input().rstrip().split()))
a_list = list(map(int, input().rstrip().split()))
#-----

cnt=0
if a_list[0] > x:
    cnt += (a_list[0] - x)
    a_list[0] = x

for i in range(1,len(a_list)):
    sum2 = a_list[i-1] + a_list[i]
    if sum2 > x:
        diff = sum2 - x
        
        # a_list[i-1] < x のため、a_list[i]のみ操作
        a_list[i] -= diff
        cnt += diff
        
print(cnt)


Measured memory_bytes: 14052
#include<stdio.h>

#define MAX 25

typedef struct{
  int l,r,par;
} node;

node data[MAX];

void init(int);
void preorder(int);
void inorder(int);
void postorder(int);

int main(){
  int num,i,id,left,right;
  int p;

  scanf("%d",&num);
  init(num);

  for(i = 0;i < num;i++){
    scanf("%d%d%d",&id,&left,&right);

    if(left != -1){
      data[id].l = left;
      data[left].par = id;
    }
    if(right != -1){
      data[id].r = right;
      data[right].par = id;
    }
  }

  for(i = 0;i < num;i++){
    if(data[i].par == -1){
      p = i;
      break;
    }
  }

  puts("Preorder");
  preorder(p);
  puts("");

  puts("Inorder");
  inorder(p);
  puts("");

  puts("Postorder");
  postorder(p);
  puts("");

  return 0;
}

void init(int num){
  int i;

  for(i = 0;i < num;i++){
    data[i].par = data[i].l = data[i].r = -1;
  }
}

void preorder(int p){
  if(p != -1){
    printf(" %d",p);
    preorder(data[p].l);
    preorder(data[p].r);
  }
}

void inorder(int p){
  if(p != -1){
    inorder(data[p].l);
    printf(" %d",p);
    inorder(data[p].r);
  }
}

void postorder(int p){
  if(p != -1){
    postorder(data[p].l);
    postorder(data[p].r);
    printf(" %d",p);
  }
}



Measured memory_bytes: 2036
_ = gets.to_i
a,b = gets.split.map(&:to_i)
s = gets.split.map(&:to_i)
x = s.count{_1 <= a}
y = s.count{_1 >= (b + 1)}
z = s.count - x - y
c = [x, y, z]
num = 0
while c.count{_1 <= 0} == 0
  num += 1
  c = c.map{_1 - 1}
end
puts num


Measured memory_bytes: 14272
#include <bits/stdc++.h>
#define REP(i,n) for (long long i=0;i<(n);i++)
#define FOR(i,a,b) for (long long i=(a);i<(b);i++)
#define RREP(i,n) for(long long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl
#define dump(x)  cerr << #x << " => " << (x) << endl
#define dumpP(p) cerr << "( " << p.first << " , " << p.second << " )" << ends
#define SORT(c) sort((c).begin(),(c).end())
#define MIN(vec) *min_element(vec.begin(), vec.end())
#define MAX(vec) *max_element(vec.begin(), vec.end())
#define UNIQ(vec) vec.erase(unique(vec.begin(), vec.end()),vec.end()) //ソートの必要あり
#define IN(n,m)  (!(m.find(n) == m.end()))
#define ENUM(m) for (auto itr = m.begin(); itr != m.end(); ++itr)
#define dump_MAP(m) for(auto itr = m.begin(); itr != m.end(); ++itr) { cerr << itr->first << " --> "  << itr->second << endl; }
#define FINDL(vec,x) (lower_bound(vec.begin(),vec.end(),x) - vec.begin())
#define FINDU(vec,x) (upper_bound(vec.begin(),vec.end(),x) - vec.begin())
#define ROUND(N) setprecision(N)
#define ROUND_PRINT(N,val) cout << fixed;cout << setprecision(N) << val << endl
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define INARR(h,w,x,y) (0 <= y && y < h && 0 <= x && x < w)

using namespace std;
constexpr int dx[4] = {0,1,0,-1};
constexpr int dy[4] = {1,0,-1,0};
constexpr long double pi = M_PI;
constexpr double eps = 1e-10;
constexpr long mod = 1000000007;
constexpr short shINF = 32767;
constexpr long loINF = 2147483647;
constexpr long long llINF = 9223372036854775807;
typedef long long LL;
typedef vector<bool> VB;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<LL,LL> pr;
typedef vector<pr> VP;
struct Order {
	bool operator() (pr const& a,pr const& b) const {
		return a.first > b.first || ((a.first == b.first) && (a.second > b.second));
	}
};

VVI arr;
vector<VB> used;
long H,W;
void dfs(int x,int y) {
	if (!INARR(H,W,x,y)) return;
	if (used[y][x] || !arr[y][x]) return;
	else {
		used[y][x] = true;
		REP(i,4) dfs(x+dx[i],y+dy[i]);
	}
}
int main(void) {
	while (1) {
	cin >> W >> H;
	if (W == 0 && H == 0) break;
	arr = VVI(H,VI(W));
	used = vector<VB>(H,VB(W,false));
	char s;
	int x,y;
	REP(i,H) {
		REP(j,W) {
			cin >> s;
			if (s == '#') arr[i][j] = 0;
			else arr[i][j] = 1;
			if (s == '@') {
				x = j;y = i;
			}
		}
	}
	dfs(x,y);
	long cnt = 0;
	REP(i,H) REP(j,W) if (used[i][j]) cnt++;
	cout << (cnt) << endl;

	}
}





Measured memory_bytes: 3104
n=int(input())
A=input()
if(n%2==0):
    i=0
    j=n//2
    flag=True
    while(i<n//2):
        if(A[i]!=A[j]):
            # print("No")
            flag=False
            break
        i+=1
        j+=1
    if(flag):
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 3060
S = input()

word_list = ['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']

for i in word_list:
    if i not in S:
        print(i)
        exit()

print('None')

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

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

	int			n;
	int			max;
	int			second_max;
	cin >> n;
	vector<int>	A(n);
	vector<int>	B(n);

	/* rep(i, n) */
	/* 	cin >> A.at(i); */
	for (int &a : A)
		cin >> a;
	B = A;
	sort(B.begin(), B.end(), greater<>());
	max = B.at(0);
	second_max = B.at(1);
	rep(i, n)
	{
		if (A.at(i) != max)
			cout << max << endl;
		else
			cout << second_max << endl;
	}
}


Measured memory_bytes: 3200
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;

#include <bits/stdc++.h>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace std;
const long long N=200005, INF=2000000000000000000;
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }


int32_t main()
{
    IOS;
    int n,m;
    cin>>n>>m;
    vi v[N];
    bool visit[N];
    int par[N];
    fill(visit, false);
    fill(par, -1);
    while(m--)
    {
        int a,b;
        cin>>a>>b;
        v[a].pb(b);
        v[b].pb(a);
    }
    queue <int> q;
    q.push(1);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        //visit[u]=true;
        int l=v[u].size();
        for(int i=0;i<l;i++)
        {
            if(!visit[v[u][i]])
            {
                visit[v[u][i]]=true;
                q.push(v[u][i]);
                par[v[u][i]]=u;
            }
        }
    }
    int f=0;
    for(int i=2;i<=n;i++)
    {
        if(!visit[i])
        {
            f=1;
            break;
        }
    }
    if(f==1)
    cout<<"No";
    else
    {
        cout<<"Yes\n";
        for(int i=2;i<=n;i++)
        cout<<par[i]<<"\n";
    }
}

Measured memory_bytes: 16352
n = int(input())
a = n % 10
b = (n // 10) % 10
c = n // 100
n = 100 * c + 10 * b + a

if c < b or c < a:
    print(100 * (c + 1) + 10 * (c + 1) + c +1)
else:
    print(100 * c + 10 * c + c)


Measured memory_bytes: 2940
#include <iostream>
int main() {
  int n, a, m=1001001001, c;
  std::cin >> n;
  while(std::cin >> a) {
    c = 0;
    while((a&1)==0){++c;a=a>>1;}
    m = (c<m?c:m);
  }
  std::cout << m << "\n";
}
  

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int N,i;
  scanf("%d",&N);
  int A[N];

  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  int minv = A[0],maxv = A[1]-A[0];

  for(i=1;i<N;i++){
    if(maxv < A[i]-minv){
      maxv = A[i]-minv;
    }else{
      maxv = maxv;
    }
    if(minv < A[i]){
      minv = minv;
    }else{
      minv = A[i];
    }
  }

  printf("%d\n",maxv);
  return 0;
}



Measured memory_bytes: 2520
n = int(input())
s = list(input() for _ in range(n))
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
    if s[i] == "AC":
        ac += 1
    elif s[i] == "WA":
        wa += 1
    elif s[i] == "TLE":
        tle += 1
    else:
        re += 1
print("AC x " + str(ac))
print("WA x " + str(wa))
print("TLE x " + str(tle))
print("RE x " + str(re))

Measured memory_bytes: 16308
n = int(input())
nums = list(map(int,input().split(" ")))
nums.sort()
total = 0
for i in range(n-1,-1,-1):
    l = 0
    r = i-1
    while l < r:
        if nums[l] + nums[r] > nums[i]:
            total += r - l
            r -= 1
        else:
            l += 1
print(total)

Measured memory_bytes: 3188
function main(arg) {
	arg = arg.trim().split('\n');
	var h = arg[1].split(' ').map(str => parseInt(str, 10)),
        n = parseInt(arg[0], 10),
        out = 0, cnt = 0;
  	for (var i = 0; i < n-1; i++) {
    	if (h[i] >= h[i+1]) {
          cnt++;	
        } else {
          cnt = 0;
        }
      	if (out < cnt) {
          out = cnt
        }
    }
  	
  console.log(out)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define sz size()
#define endl "\n"
#define pb push_back
#define pp pop_back
#define mp make_pair
#define REP(I,n) for(int I = 0; I < n; I++)
#define REP_1(I,n) for(int I = 1; I <= n; I++)
#define w(t) int t; cin>>t; while(t--)

#define MOD 1000000007
#define INF 1e9 + 7

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef map<int,int> mii;
typedef map<string,int> msi;
typedef map<int,string> mis;
typedef set<int> si;
typedef set<string> ss;

typedef long long ll; 

ll getadd(ll x) {
	int m1 = INT_MIN,m2 = INT_MAX;
	while(x > 0) {
		int r = x % 10;
		x /= 10;
		m1 = max(m1,r);
		m2 = min(m2,r);
	}
	return m1*m2;
}
string repeat(string s,int num) {
	string res;
	while(num--)
		res = res + s + ' ';
	return res;
}
void solve() {
	ll a,b;
	cin>>a>>b;

	cout<<a*b;
	
}
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	solve();	
}
 

Measured memory_bytes: 3664
<?php
define('MOD', 998244353);
//$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
list($N,$M,$K) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$s = trim(fgets(STDIN));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));

$c = new combinationsnk(200005);
$ans = 0;
$col = $M;
for($x = $N-1;$x >=0 ;--$x) {
  $now = $col;
  $now = mulm($now,$c->calc($N-1,$x));
  if ($x <= $K) {$ans = addm($ans,$now);}
  $col = mulm($col,$M-1);
  //printf("col %d now %d ans %d x%d\n",$col,$now,$ans,$x);
}
printf("%d\n",$ans);


//https://atcoder.jp/contests/abc145/submissions/8474723

//足し算
function addm($a, $b){
    return ($a + $b) % MOD;
}
//引き算
function subm($a, $b){
    return ($a + MOD - $b) % MOD;
}
//掛け算
function mulm($a, $b){
    return ($a * $b) % MOD;
}
//割り算
function divm($a, $b){
    return mulm($a, powerm($b, MOD - 2));
}
//累乗
function powerm($a, $b){
    if($b == 0)return 1;
    if($b & 1)return (powerm($a, $b>>1)**2 % MOD) * $a % MOD;
    return powerm($a, $b>>1)**2 % MOD;
}
//階乗
function factorialm($a){
    if($a == 0)return 1;
    return factorialm($a - 1) * $a % MOD;
}
//順列
function nPm($n, $m){
    if($m == 0)return 1;
    return nPm($n, $m - 1) * ($n - $m + 1) % MOD;
}
//組み合わせ
function nCm($n, $m){
    $m = min($m, $n-$m);
    return divm(nPm($n, $m), factorialm($m));
}

//解説のcombinationを移植
Class combinationsnk {
  private $fact;
  private $ifact;
  public function __construct(int $n) {
    $this->fact[0]=1;
    for($i=1;$i<=$n;$i++) $this->fact[$i]=mulm($this->fact[$i-1],$i);
    $this->ifact[$n]=powerm($this->fact[$n],MOD-2);
    for ($i = $n; $i >= 1; --$i) $this->ifact[$i-1] = mulm($this->ifact[$i],$i);
  }
  public function calc(int $n,int $k)
  {
    if ($k < 0 || $k > $n) return 0;
    return mulm(mulm($this->fact[$n],$this->ifact[$k]),$this->ifact[$n-$k]);
  }
}


Measured memory_bytes: 34168
n = int(input())
A = [0] + [int(i) for i in input().split()] + [0]
amt = 0

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

Measured memory_bytes: 14048
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define eps 1e-6
#define mp make_pair
const long long INF=1e18+2;
const int MX=1002;
int N, M, k;
vector<char> v;
int main()
{
   string s;cin>>s;
   for(int i=0;i<s.size();i++)
   {
       if(s[i] == 'T' && v.size() && v.back() == 'S') v.pop_back();
       else v.pb(s[i]);
   }
   cout<<(int)v.size()<<"\n";
    return 0;
}


Measured memory_bytes: 772
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	string S;
	cin >> S;
	int cnt[26] = { 0 };
	REP(i, S.size()) {
		cnt[S[i] - 'a']++;

	}
	REP(i, 26) {
		if (cnt[i]==0) {
			cout << (char)(i + 'a') << endl;
			return 0;
		}
	}
	cout << "None" << endl;
	return 0;
}



Measured memory_bytes: 512
import bisect
import itertools

N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))

A = []
for i in range(1,N+1):
  A.append(i)
B = list(itertools.permutations(A))
C = []
for b in B:
  d = 0
  for bb in b:
    d *= 10
    d += bb
  C.append(d)
C.sort()

p = 0
for pp in P:
  p *= 10
  p += pp
q = 0
for qq in Q:
  q *= 10
  q += qq
a = bisect.bisect_left(C,p)
b = bisect.bisect_left(C,q)
print(abs(a-b))

Measured memory_bytes: 47980
var input = ""
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
 
process.stdin.on('end', function() {
  input = input.split("\n");
  i = 0
  while (input[i] != 0) {
    arr = input[i].split(" ");
    if (arr[0] != 0 || arr[1] != 0) {
      ho = "";
      hi = "";

      for (j = 0; j < arr[1]; j++) {
        ho = ho + "#";
        if (j == 0 || j == arr[1] - 1) {
          hi = hi + "#";
        } else {
          hi = hi + ".";
        }
      }

      for (k = 0; k < arr[0]; k++) {
        if (k == 0 || k == arr[0] - 1) {
          console.log(ho);
        } else {
          console.log(hi);
        }
      }
      console.log("");
    }
    i++;
  }
});

Measured memory_bytes: 9712
using System;
using static System.Console;
public class A
{
  static void Main()
  {
    var s = Array.ConvertAll(ReadLine().Split(), int.Parse);
    if (s[0] == s[1])
      WriteLine(s[0] + s[1]);
    else
      WriteLine(Math.Max(s[0], s[1])*2-1);
  }
}

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


int main(){
	int n, mini = INT_MAX, maxi = 0;
	cin >> n;
	rep(i,n){
	    int t;
	    cin >> t;
	    mini = min(mini, t);
	    maxi = max(maxi, t);
	}
	cout << maxi - mini << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
typedef long long int lld;
typedef unsigned long long int llu;
#define MAX(x,y) (x > y ? x : y)
#define MIN(x,y) (x < y ? x : y)
#define INF (long long int)(9223372036854775807)
#define IINF (int)(2147483647)

int main(void) {
  int n;
  double pi = 3.141592653589;
  scanf("%d", &n);
  printf("%lf\n", n * pi * 2.0);
}

Measured memory_bytes: 1752
#include <bits/stdc++.h>
using namespace std;
int INF=1e9+7;
long long DP[1005][1005];
int main(){
  int H,W;cin>>H>>W;
  DP[1][1]=1;
  for(int i=0;i<H;i++){
    string S;cin>>S;
    for(int j=0;j<W;j++){
      DP[i+1][j+1]%=INF;
      if(S.at(j)=='.'){DP[i+1][j+2]+=DP[i+1][j+1];DP[i+2][j+1]+=DP[i+1][j+1];}
    }
  }
  cout<<DP[H][W]<<endl;
}

Measured memory_bytes: 11388
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<pii> ab(n);
    REP(i,n) cin >> ab[i].second >> ab[i].first;
    sort(ALL(ab));
    int now = 0;
    bool ok = true;
    REP(i,n) {
        now += ab[i].second;
        if (now > ab[i].first) {
            ok = false;
            break;
        }
    }

    ATYN(ok)

    return 0;
}

Measured memory_bytes: 1792
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;
 
#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first                 
#define  s              second
#define  endl           "\n"
#define  pb             push_back  
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";cout<<endl;
#define  deb1(a)        cout<<a<<endl;
#define  deb2(a,b)      cout<<a<<" "<<b<<endl;
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<endl;
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()           
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   N     =  1e5+5;
const ll   mod   =  998244353;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;

int test = 1, n, ans = 0, p[N], sz[N];
vpll X, Y;
vector <pair<ll,pll>> edges;

void make(ll n){
	for(int i = 1; i <= n; i++){
		p[i] = i;
		sz[i] = 1;
	}
}

int find(ll x){
	return (p[x] == x)? x: p[x] = find(p[x]);
}

void merge(ll x, ll y){
	ll a = find(x);
	ll b = find(y);
	if(a != b){
		if(sz[a] >= sz[b]) swap(a,b);
		p[a] = b;
		sz[b] += sz[a];
	}
}

void solve(){
	cin>>n;
	for(int i = 1; i <= n; i++){
		int x, y; cin>>x>>y;
		X.pb({x,i});
		Y.pb({y,i});
	}
	sort(all(X)); sort(all(Y));
	for(int i = 1; i < n; i++){
		edges.pb({X[i].f-X[i-1].f,{X[i].s,X[i-1].s}});
		edges.pb({Y[i].f-Y[i-1].f,{Y[i].s,Y[i-1].s}});
	}
	sort(all(edges));
	make(n);
	for(auto it : edges){
		int x = it.s.f, y = it.s.s;
		if(find(x) != find(y)){
			ans += it.f;
			merge(x,y);
		}
	}
	deb1(ans)
}

int main(){
	GODSPEED;
	//cin>>test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}

Measured memory_bytes: 14080
#!/usr/bin/env pypy
 
import sys
inp = sys.stdin.readline
out = print
MAX = 10**9
 
n, k = map(int, inp().split())
cost = list(map(int, inp().split()))
dp = [MAX] * (n)
dp[0] = 0
 
for i in range(1, n):
    for j in range(max(0, i-k), i+1):
                dp[i] = min(dp[i] ,dp[j] + abs(cost[i] - cost[j]))
 
print(dp[-1])

Measured memory_bytes: 84876
#include<iostream>
using namespace std;
int main(){
    string s;
    int a = 700;
    cin >> s;
    
    for(int i = 0; i < 3; i++){
        if(s.at(i) == 'o'){
            a += 100;
        }
    }
    cout << a << endl;

    return 0;
}

Measured memory_bytes: 256
//Created by:Coding_lover(27-07-2020 07:26:31)
#include <bits/stdc++.h>
#define ll long long
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define INF LLONG_MAX
#define f first
#define s second
#define LB lower_bound
#define UB upper_bound
#define pi pair<long long,long long>
#define pii pair<long long,pi>
#define pb push_back
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define vc vector
#define vll vector<long long>
#define rep(i, a, n) for (ll i = a; i < (long long)n; ++i)
#define repe(i, a, n) for (ll i = a; i <= (long long)n; ++i)
#define repr(i, n, a) for (ll i = n; i > (long long)a; --i)
#define repre(i, n, a) for (ll i = n; i >= (long long)a; --i)
#define dbg(x) cout<<"Debugging "<<#x<<":"<<endl;cout<<#x<<" = "<<x<<endl
#define dbgv(v) cout<<"Debugging "<<#v<<":"<<endl; for(ll i=0;i<v.size();i++){cout<<v[i]<<" ";}cout<<endl;
using namespace std;
int main() {
  FASTER;
  ll t=1;
  //cin >> t;
  while (t--) {
  	string s,t;
  	cin>>s>>t;
  	ll s1=sz(s);
  	ll s2=sz(t);
  	ll dp[s2+1][s1+1];
  	memset(dp,0,sizeof dp);
  	for(ll i=0;i<=s2;++i)
  	{
  		for(ll j=0;j<=s1;++j)
  		{
  			if(i==0 or j==0)dp[i][j]=0;
  			else
  			{
  				if(s[j-1]==t[i-1])
  				{
  					dp[i][j]=1+dp[i-1][j-1];
  				}
  				else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
  			}
  		}
  	}
  	//cout<<dp[s2][s1]<<endl;
  	ll i=s2,j=s1,index=dp[s2][s1]-1;
  	char ans[dp[s2][s1]];
  	while(i>0 and j>0){
  		if(s[j-1]==t[i-1]){ans[index]=s[j-1];i-=1;j-=1;index--;}
  		else
  		{
  			if(dp[i-1][j]>dp[i][j-1])i-=1;
  			else j-=1;
  		}
  	}
  	for(ll i=0;i<dp[s2][s1];++i)cout<<ans[i];
  	cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 73972
a, b, k = gets.split.map(&:to_i) 
 
ans_arr = []
(a..a+k-1).each do |i|
	ans_arr << i
	if i >= b
		break
	end
end
 
(-b..-b+k-1).each do |i|
	ans_arr << -i
	if -i <= a
		break
	end
end
 
ans_arr.uniq!
ans_arr.sort!
 
ans_arr.each do |n|
	puts n
end

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

typedef long long ll;

const int INF = 100000000;

int main() {
    int N, M;
    int ans = 0;
    cin >> N >> M;
    vector<vector<int>>s(M);
    vector<int>p(M);

    for (int i = 0; i < M; i++) {
        int k;
        cin >> k;
        vector<int>v(k);
        for (int j = 0; j < k; j++) {
            cin >> v[j];
        }
        s[i] = v;
    }

    for (int i = 0; i < M; i++) {
        cin >> p[i];
    }

    for (int bits = 0; bits < (1<<N); bits++) {
        bool ok = true;
        vector<int>v;
        for (int i = 0; i < N; i++) {
            if (bits & (1<<i)) {
                v.push_back(i+1);
            }
        }

        for (int i = 0; i < M; i++) {
            int sum = 0;
            for (int j = 0; j < s[i].size(); j++) {
                for (int k = 0; k < v.size(); k++) {
                    if (s[i][j] == v[k]) {
                        sum++;
                    } 
                }
            }
            if (sum % 2 != p[i]) {
                ok = false;
            }
        }
        if (ok) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    ll A, B;
    cin >> A >> B;
    if (A + B < 24) {
        cout << A + B << endl;
    }
    else {
        cout << A + B - 24 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }




int N;
int a[210000];

int main() {
  while (cin >> N) {
	for (int i = 0; i < N; ++i) cin >> a[i], --a[i];

	int s = 0;
	int iter = 0;
	for (iter = 0; iter < N*2; ++iter) {
	  if (s == 1) break;
	  s = a[s];
	}

	if (iter == N*2) cout << -1 << endl;
	else cout << iter << endl;
  }
}


Measured memory_bytes: 768