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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    int k;cin>>k;
    string s;cin>>s;
    int n=s.size();
    string t="...";
    int m=n-k;
    if(n<=k)cout<<s<<endl;
    else cout<<s.substr(0,k)+t<<endl;
}

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0169

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    while True:
        data = [int(x) for x in input().split()]
        if len(data) == 1 and data[0] == 0:
            break

        total = 0
        for d in data:
            if d > 10:
                total += 10
            else:
                total += d

        ace = data.count(1)
        for _ in range(ace):
            if total + 10 <= 21:
                total += 10

        if total > 21:
            total = 0

        print(total)


if __name__ == '__main__':
    main(sys.argv[1:])
    

Measured memory_bytes: 7708
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <limits.h>
//#include <math.h>

int main() {
  char s[5];
  scanf("%s", s);
  int ans = 0;
  for (int i=0; i<4; i++) {
    if (s[i] == '+') ans++;
    else if (s[i] == '-') ans--;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
gets
a = []
b = []
while gets
  l = $_.split.map(&:to_i)
  a << l[0]
  b << l[1]
end
a.reverse!
b.reverse!

push = 0
a.size.times{|i|
  next if a[i] == 0 || b[i] == 1 || a[i] == b[i] || (a[i] + push) % b[i] == 0 || a[i] % b[i] == 0 
  a[i] += push
  push += (b[i] - (a[i] % b[i]))
}
p push

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

int main() {
  int64_t n, ans = 0;
  cin >> n;
  for (int64_t i = 1; i <= n; i++) {
    if (i % 3 && i % 5) {
      ans += i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3624
import java.util.Scanner;

class Main{


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] p = new int[n];
		for(int i = 0;i < n;i++){
			p[i] = sc.nextInt();
		}
		UnionFind tree = new UnionFind(n+1);
		for(int i = 0;i < m;i++){
			int x = sc.nextInt();
			int y = sc.nextInt();
			tree.unite(x, y);
		}
		int ans = 0;
		for(int i = 0;i < n;i++){
			if(p[i] == i+1 || tree.same(p[i], i+1)){
				ans++;
			}
		}
		System.out.println(ans);
		
		






	}
}

class UnionFind{
	int[] parent;
	public UnionFind(int N){
		this.parent = new int[N];
		for(int i = 0; i < N;i++){
			parent[i] = i;
		}
	}
	public int root(int x){			//根要素を取得
		if(parent[x] == x){			//初期状態
			return x;
		}else{
			return parent[x] = root(parent[x]);    	//再帰によって根を取得
		}
	}
	public void unite(int x,int y){ 	//統合メソッド
		if(same(x,y)){					//同じ根なら終了
			return;
		}
		int xroot = root(x);
		int yroot = root(y);
		parent[xroot] = yroot;			//統合
		return;

	}

	public boolean same(int x,int y){			//根が同じか（同じグループに属しているか）を判定
		return(root(x) == root(y));
	}
}



class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}



Measured memory_bytes: 92480
int_list = []
for num in range(5):
    num1 = int(input())
    int_list.append(num1)
num2 = int_list[1] // int_list[3] + 1
num3 = int_list[2] // int_list[4] + 1
if num2 > num3:
    if int_list[1] % int_list[3] == 0:
        num2 -= 1
        i = int_list[0] - num2
    else:
        i = int_list[0] - num2
else:
    if int_list[2] % int_list[4] == 0:
        num3 -= 1
        i = int_list[0] - num3
    else:
        i = int_list[0] - num3
print(i)


Measured memory_bytes: 5596
from queue import Queue
N, M = [int(i) for i in input().split()]
al = [[] for _ in range(N + 1)]
for _ in range(M):
    A, B = [int(i) for i in input().split()]
    al[A].append(B)
    al[B].append(A)
q = Queue()
q.put(1)
seen = [False] * (N + 1)
seen[1] = True
while not q.empty():
    v = q.get()
    for nv in al[v]:
        if not seen[nv]:
            q.put(nv)
            seen[nv] = v
print("Yes")
for i in seen[2:]:
    print(i)

Measured memory_bytes: 98516
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


int main() {
   string nn;
 
   cin >> nn;
  
   const char* n = nn.c_str();
  
  
  
   int sum = 0;
   for(int i=0;i<nn.size()/2;i++){
     
     // cout << n[i] << n[nn.size()-1-i] << endl;
     
     string a(n, i,1);
     string b(n, nn.size()-1-i,1);
     
     // if(!strcmp(n[i], n[nn.size()-1-i])){
     //   sum++;
     // }
      //if(strcmp(n[i],n[nn.size()-1-i])==0){
        
     // cout << a << b << endl;
      if(a!=b){
        sum++;
      }
    
   }
   cout << sum << endl;
  
   
  return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V, string sep = " ", string end_ = "endl") {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << sep;
    }
    if(end_ == "endl")
        cout << endl;
    else
        cout << end_;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C;
    cin >> A >> B >> C;
    cout << min(A + B + 1, C) + B << endl;
}

Measured memory_bytes: 256
n,k = map(int, input().split())
r,s,p = map(int, input().split())
T = input()
P = []
# プレイヤーのだす手の制約を無しとしたときの最善手のスコアのリストを作成(K回前でも同じ手を出せたとするということ)
for i in range(n):
    if T[i] == 'r':
        P.append('p')
    elif T[i] == 's':
        P.append('r')
    elif T[i] == 'p':
        P.append('s')

# K回前と出す手がかぶるときはその出す手の後者のスコアを0とする
for i in range(n-k):
    if P[i] == P[i+k]:
        P[i+k] = 0

count = 0
for i in range(n):
    if P[i] == 'r':
        count += r
    elif P[i] == 's':
        count += s
    elif P[i] == 'p':
        count += p

print(count)

Measured memory_bytes: 4212
#int input
n = int(input())
values = [int(x) for x in input().split(" ")]
def count(values):
    from collections import defaultdict
    counter = defaultdict(int)
    for value in values:
        counter[value] += 1
    return counter
odd = 0
even = 0
c = count(values)
for number, amount in c.items():
    #print(number,amount)
    if amount % 2 == 0:
        even += 1
    else:
        odd += 1
#print(odd,even)
if even % 2 == 0:
    print(odd + even)
else:
    print(odd + even - 1)


Measured memory_bytes: 18528
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
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; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

int D;
vector<int> c;
vector<vector<int>> s;

int score(vector<int> &t){
  vector<int> last(26, -1);


  int ans = 0;
  REP(i, D){
    ans += s[i][t[i]-1];
    last[t[i]-1] = i;

    REP(j, 26){
      ans -= (i-last[j])*c[j];
    }
  }
  return ans;
}

signed main() {
  cin >> D;

  c.resize(26);
  REP(i, 26) cin >> c[i];

  s = vector<vector<int>>(D, vector<int>(26));
  REP(i, D) REP(j, 26) cin >> s[i][j];

  vector<int> last(26, -1);
  vector<int> ans(D);

  auto eval = [&](int d, int i){
    int ret = s[d][i];
    REP(j, 26){
      if(i == j) continue;
      ret -= (i-last[j])*c[j];
    }
    return ret;
  };

  auto f = [&](int d){
    int MAX = -INF;
    int ret = 0;

    REP(i, 26){
      int now = eval(d, i);
      /* cout << now; SPBR(i, 26); */
      if(chmax(MAX, now)) ret = i;
    }
    last[ret] = d;
    return ret+1;
  };

  REP(i, D){
    ans[i] = f(i);
    cout << ans[i] << "\n";
  }

  /* cout << score(ans) << "\n"; */

  return 0;
}

Measured memory_bytes: 3676
#include <stdio.h>

int main()
{
  int i, j;
  int n;
  long long int ans = 1;
  long long int a[100000] = {0};
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%lld", &a[i]);
    if(a[i] == 0){
      printf("0\n");
      return 0;
    }
  }
  for(i = 0; i < n; i++){
    if(a[i] <= 1000000000000000000 / ans){
      ans *= a[i];
    }else{
      printf("-1\n");
      return 0;
    }
  }
  printf("%lld\n", ans);
  
  return 0;
}

Measured memory_bytes: 2516
#!/usr/bin/env python3

import sys

DEBUG = False

def read(t):
    return t(sys.stdin.readline().rstrip())


def read_list(t, sep = " "):
    return [t(s) for s in sys.stdin.readline().rstrip().split(sep)]


def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)
    return


def main():
    k = read(int)
    a, b = read_list(int)
    for i in range(a, b + 1):
        if i % k == 0:
            print("OK")
            return
    print("NG")


if __name__ == "__main__":
    main()


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

using namespace std;
using ll = long long int;

int main(void) {
    cout << fixed << setprecision(16);

    ll n;
    cin >> n;
    vector<double> t(n+2), v(n+2);
    for(ll i=0; i<n; i++) cin >> t[i+1];
    for(ll i=0; i<n; i++) cin >> v[i+1];

    ll ts = accumulate(t.begin(), t.end(), 0ll);
    partial_sum(t.begin(), t.end(), t.begin());

    double s = 0, p = 0;
    for(ll i=0; i<=2*ts; i++) {
        double tc = 0.5*i;
        double k = p + 0.5;
        {
            ll j=0;
            while(t[j] < tc)
                k = min(k, (tc - t[j]) + v[j]), j++;
            k = min(k, v[j]);
            while(j < n+1)
                k = min(k, (t[j] - tc) + v[j+1]), j++;
        }
        s += (p + k) * 0.5 / 2;
        p = k;
    }
    cout << s << endl;
}


Measured memory_bytes: 256
/*******************************
 * written by Koki Riho
 * Rih0z https://github.com/Rih0z
 *******************************/

#include<iostream>
#include<map>
#include<vector>
#include<string>
#include<numeric>
#include<algorithm>
#include<cmath>

#define DEBUG false

#define FOR(i , a, b) for(size_t i = a ; i < b ; i++ )
#define REP(i,b) FOR(i , 0 , b)
#define RFOR(i,a,b) for(size_t i = a-1 ; i >= b ; i--)
#define RREP(i,a) RFOR(i,a,0)



typedef long long ll;
using namespace std;

double scandouble(void);
string scanString(void);

void scanLlArr(ll *a , double n);
void scanCharArr(char *string);

void prdoubledouble(double p);
void prdoubleLlArr(ll *a);
void prdoubleCharArr(char *string);


void perSum(ll *a , ll *sum ,double n);

/*************Global variable  **************/
double N ;
char str[26];
std::map<char,double> M ;
/*******************************/

int main(){

  cin >> N ;
  double count= 0 ;
  REP(i,10){
    double digit = pow(10,i);
    if(DEBUG){
      cout << "digit"<< "  " << digit << endl;
      cout << "N/digit"<< "  " << N/digit << endl;
    }
    if(static_cast<int>(N/digit) == 0 ){
      count--;
      break;
    }
    count++;
  }

  if(DEBUG){
    cout << "count"<< "  " << count << endl;
  }
  int sum= 0 ;
  double tmp = N ;
  for(double i = count ; i >= 0 ; i--){
    double digit = pow(10,i);
    sum += int(tmp/digit);
    int digitn = int(tmp/digit) * digit;
    tmp = tmp - digitn;
    if(DEBUG){
      cout << "tmp"<< "  " << tmp << endl;
      cout << "digit"<< "  " << digit << endl;
      cout << "sum"<< "  " << sum << endl;
      cout << "dititn"<< "  " << digitn << endl;
    }
  }
  string ans = "No";
  if((int)N%sum == 0 )
    ans = "Yes";
  cout << ans << endl ;
  return 0 ;
}

//各地点までの部分和を計算する
void perSum(ll *a , ll *sum ,int n){
  int i ;
  sum[0] = a[0];
  for(i = 1 ; i < n ; i++){
    sum[i] = a[i] + sum[i-1];
  }

}


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

using namespace std;

int main () {

	int N;
	cin >> N;

	int hpp, hp, hc, cpp, cp, cc;

	cin >> hpp >> hp;

	cpp = 0;
	cp = abs(hpp - hp);
	cc = cp;
	
	for (int i = 1; i <= N - 2; i++) {
		cin >> hc;
		cc = min(cpp + abs(hc - hpp), cp + abs(hc - hp));
		hpp = hp;
		hp = hc;
		cpp = cp;
		cp = cc;
	}
	
	cout << cc << endl;

}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

#define mod 1e9+7
#define ll long long int
#define epsilon 1e-7

ll mi(ll x, ll y){
    if(x<y)return x;
    return y;
}
int a[100000];
int b[100000];

int compare_int(const void *a, const void *b){
	ll *A = (ll *)a;
	ll *B = (ll *)b;
    return *A-*B;
}
int main(void){
    int n, m;
    scanf("%d %d", &n, &m);
    for(int i = 0;i < n;i++)scanf("%d", &a[i]);
    ll sum = 0;
    for(int i = 0;i < n;i++){
        sum += a[i];
        sum %= m;
        b[i] = sum;
    }
    qsort(b, n, sizeof(int), compare_int);
    int mem = 0;
    int count = 1;
    ll ans = 0;
    for(int i = 0;i < n;i++){
        if(mem == b[i])count++;
        else{
            ans += (ll)(count - 1) * count / 2;
            mem = b[i];
            count = 1;
        }
    }
    ans += (ll)(count - 1) * count / 2;
    printf("%lld\n", ans);
    return 0;
}


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

int main() {
	char a[3], b[3];
	cin >> a >> b;
	if (a[0] == b[2] && a[1] == b[1] && a[2] == b[0]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n,m=map(int,raw_input().split())
a=[]
for i in range(n):
    a.append([int(v) for v in raw_input().split()])
b=[]
for i in range(m):
    b.append(int(raw_input()))
for i in range(n):
    ans=0
    for j in range(m):
        ans+=a[i][j]*b[j]
    print ans

Measured memory_bytes: 4540
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int,int>;
template<typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a){
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os, vector<T> v){
    for(auto x:v)os << x << ' ';
    return os;
}
void debug(){cerr << '\n';}
template<typename H, typename... T>
void debug(H a, T... b){
    cerr << a;
    if(sizeof...(b))cerr << ", ";
    debug(b...);
}
int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<int> a;
    vector<int> b;
    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(i==0 or (i>0 and s[i] == s[i-1]))cnt++;
        else{
            a.push_back(cnt);
            b.push_back(s[i-1] == '0');
            cnt = 1;
        }
    }
    a.push_back(cnt);
    b.push_back(s[n-1] == '0');
    int ans = 0;
    int num = 0;
    int l = 0;
    int temp = 0;
    show(a);
    show(b);
    for(int i = 0; i < (int) a.size(); i++){
        num += b[i];
        temp += a[i];
        show(temp);
        show(num);
        if(num <= k){
            ans = max(ans, temp);
        }else{
            num -= b[l];
            temp -= a[l];
            l++;
            if(num <= k){
                ans = max(ans, temp);
            }else{
                num -= b[l];
                temp -= a[l];
                l++;
                ans = max(ans, temp);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1404
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1]; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1]; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define pb(x) push_back(x)
#define vi vector <int>
#define pi pair <int, int>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	string str;
	cin >> str;
	int a[200] = {};
	for (int i: str)
		a[i]++;
	
	for (int i: a)
		if (i != 0 && i != 2) {cout << "No"; return 0;}
	cout << "Yes";
}

Measured memory_bytes: 256
{-# LANGUAGE PartialTypeSignatures #-}
module Main (main) where

import Control.Monad
import qualified Data.ByteString.Char8 as C8
import qualified Data.Char as C
import qualified Data.List as L
import qualified Data.Set as Set

main :: IO ()
main = do
  [n,k] <- readInts
  replicateM k (readInts >> readInts) >>= output . solve n . concat

solve :: Int -> [Int] -> _
solve n = Set.size . (xs Set.\\) . Set.fromList
  where
    xs = Set.fromList [1..n]

output :: _ -> IO ()
output = print

-- utils
readInts :: IO [Int]
readInts = L.unfoldr (C8.readInt . C8.dropWhile C.isSpace) <$> C8.getLine


Measured memory_bytes: 4936
#include<iostream>
#include<string.h>
#include<algorithm>
#define ll long long 
#define r(i,n) for(ll i=0;i<n;i++)
#define rp(i,a,b) for(ll i=a;i<b;i++)
#define ret return 
#define elif else if
ll inf=100001;
using namespace std;
int main(){
	while(1){
	ll n,k;cin>>n>>k;
	ll dp[inf];
	r(i,inf){dp[i]=0;}
	ll a,b;
	r(i,n){
		cin>>a>>b;
		dp[a]+=b;
	}
	rp(i,1,inf){
		if(k<=dp[i]){cout<<i<<endl;break;}
		else{
			k-=dp[i];
		}
	}
		ret 0;
	}	
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int64;
const int64 INF = 1LL << 58;
typedef pair< int64, pair< int, int > > Pi;
 
struct edge
{
  int vv, time, cost, nxt_ptr;
 
  bool operator<(const edge &e) const
  {
    return (time < e.time);
  }
 
  bool operator<(int t) const
  {
    return (time < t);
  }
};
 
int main()
{
  int N, M, S, G;
  vector< edge > g[100000];
 
  cin >> N >> M >> S >> G;
  --S, --G;
 
  for(int i = 0; i < M; i++) {
    int u, v, t, c;
    cin >> u >> v >> t >> c;
    --u, --v;
    g[u].push_back((edge) {v, t, c});
  }
 
  for(int i = 0; i < N; i++) {
    sort(begin(g[i]), end(g[i]));
  }
 
  for(int i = 0; i < N; i++) {
    for(auto &e : g[i]) {
      e.nxt_ptr = lower_bound(begin(g[e.vv]), end(g[e.vv]), e.time + e.cost) - begin(g[e.vv]);
    }
  }
 
 
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  map< pair< int, int >, int64 > vv;
  que.emplace(g[S][0].time, make_pair(S, 0));
  vv[{S, 0}] = g[S][0].time;
 
  while(!que.empty()) {
    auto p = que.top();
    que.pop();
 
    int idx, now;
    tie(idx, now) = p.second;
 
    if(p.first > vv[{idx, now}]) continue;
 
    if(idx == G) {
      cout << p.first << endl;
      return (0);
    }
 
    if(now + 1 < g[idx].size()) {
      int64 nt = p.first + g[idx][now + 1].time - g[idx][now].time;
      if(!vv.count({idx, now + 1}) || nt < vv[{idx, now + 1}]) {
        vv[{idx, now + 1}] = nt;
        que.emplace(nt, make_pair(idx, now + 1));
      }
    }
 
    if(now < g[idx].size()) {
      auto &ee = g[idx][now];
      int64 nt = p.first;
      if(ee.vv != G) {
        if(ee.nxt_ptr >= g[ee.vv].size()) continue;
        nt += g[ee.vv][ee.nxt_ptr].time - (ee.time + ee.cost);
      }
      if(!vv.count({ee.vv, ee.nxt_ptr}) || nt < vv[{ee.vv, ee.nxt_ptr}]) {
        vv[{ee.vv, ee.nxt_ptr}] = nt;
        que.emplace(nt, make_pair(ee.vv, ee.nxt_ptr));
      }
    }
  }
 
}

Measured memory_bytes: 13688
import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		char s=sc.next().charAt(0);
		if(Character.isUpperCase(s)){
		 System.out.println("A");   
		}
		if(Character.isLowerCase(s)){
		 System.out.println("a");     
		}
	}
}

Measured memory_bytes: 35488
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

int N;

int solve1(vector<int> A) {
    vector<int> ans(N);
    ans[N / 2] = A[0];
    int l = 1;
    int r = N - 1;
    int center = N / 2;
    int cur = 1;
    while (center - cur >= 0) {
        if (center + cur > N - 1) {
            ans[center - cur] = cur % 2 == 1 ? A[r] : A[l];
            break;
        }
        if (cur % 2 == 1) {
            ans[center - cur] = A[r];
            ans[center + cur] = A[r - 1];
            r -= 2;
        } else {
            ans[center - cur] = A[l];
            ans[center + cur] = A[l + 1];
            l += 2;
        }
        cur++;
    }

    int res = 0;
    REP(i, N - 1) {
        res += abs(ans[i + 1] - ans[i]);
    }

    return res;
}

int solve2(vector<int> A) {
    vector<int> ans(N);
    ans[N / 2] = A[N - 1];
    int l = 0;
    int r = N - 2;
    int center = N / 2;
    int cur = 1;
    while (center - cur >= 0) {
        if (center + cur > N - 1) {
            ans[center - cur] = cur % 2 == 0 ? A[r] : A[l];
            break;
        }
        if (cur % 2 == 0) {
            ans[center - cur] = A[r];
            ans[center + cur] = A[r - 1];
            r -= 2;
        } else {
            ans[center - cur] = A[l];
            ans[center + cur] = A[l + 1];
            l += 2;
        }
        cur++;
    }

    int res = 0;
    REP(i, N - 1) {
        res += abs(ans[i + 1] - ans[i]);
    }

    return res;
}

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

    cin >> N;

    vector<int> A(N);
    REP(i, N) cin >> A[i];

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

    cout << max(solve1(A), solve2(A)) << endl;


    return 0;
}


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

int main(){
    int n; cin >> n;
    int digitSum = 0, m = n;
    while(m>0){
        digitSum += m % 10;
        m /= 10;
    }
    if(n % digitSum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int n,d,i,j,k,ans = 0;
double Distance;
struct node
{
	int a[11];
} point [11];

int main ()
{
	cin >> n >> d;
	
	for ( i = 1 ; i <= n ; ++ i )
		for ( j = 1 ; j <= d ; ++ j )
			cin >> point[i].a[j];
	
	for ( i = 1 ; i <= n ; ++ i )
	{
		for ( j = i + 1 ; j <= n ; ++ j )
		{
			Distance = 0;
			for ( k = 1 ; k <= d ; ++ k )
				Distance += ( point[i].a[k] - point[j].a[k] ) * ( point[i].a[k] - point[j].a[k] );
			if ( sqrt ( Distance * 1.0 ) == int ( sqrt ( Distance * 1.0 ) ) )
			   ++ ans;
		}
	}
	
	cout << ans << endl;
	
	return 0;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,ans;
    string s,t;
    cin>>n>>s>>t;
    ans=n;
    for(int i=0;i<n;i++){
        if(s.substr(i)==t.substr(0,n-i))break;
        ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3648
import sys
#import numpy as np
#import math
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
input=sys.stdin.readline

n,m=map(int,input().split())
node=[[] for _ in range(n)] 
for i in range(m):
    a,b=map(int,input().split())
    node[a-1].append(b)
    node[b-1].append(a)
d=deque()
d.append(1)
d.append(node[0][0])
s=set(d)
f=True
while True:
    f=True
    for i in node[d[0]-1]:
        if i not in s:
          d.appendleft(i)
          s.add(i)
          f=False
          break
    for i in node[d[-1]-1]:
        if i not in s:
            d.append(i)
            s.add(i)
            f=False
            break
    if f:
        print(len(d))
        print(*d)
        exit()

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

import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, M = map(int, input().split())

G = [[float('inf')] * N for i in range(N)]
edges = [None] * M
for i in range(M):
    a, b, c = map(int, input().split())
    G[a-1][b-1] = c
    G[b-1][a-1] = c
    edges[i] = (a-1, b-1, c)

# ワーシャルフロイドで全頂点の最短距離
for k in range(N):
    for i in range(N):
        for j in range(N):
            if i == j:
                G[i][j] = 0
            else:
                G[i][j] = min(G[i][j], G[i][k] + G[k][j])

ans = 0
for a, b, c in edges:
    # 最短距離ではない辺の数を数える
    if G[a][b] < c:
        ans += 1
print(ans)


Measured memory_bytes: 3444
n = int(input())
h = list(map(int, input().split()))

dp = [0] * (n+1)
for i in range(1, n):
  if i <= 2:
    dp[i] = abs(h[i] - h[0])
  else:
    dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]))
  
print(dp[n-1])
    

Measured memory_bytes: 13980
#include<bits/stdc++.h>
using namespace std;
#define lint long long
#define inf 100000000000000000
#define mod 1000000007
#define MAX 100005
#define pb push_back
#define vit vector<int>::iterator
typedef pair<lint,lint> pii;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    string S,T;
    cin>>S>>T;
    lint ans=0;
    for(lint i=0;i<S.size();i++){
        if(S[i]!=T[i]) ans++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define deb(x) cout << #x << " = "<< x << "\n";

signed main() {
//	freopen("in.txt", "r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int d, t, s;
	cin >> d >> t >> s;
	
	if(d <= s * t) cout << "Yes";
	else cout << "No";
	
	
	
	
}


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

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


Measured memory_bytes: 3632
s = input()
q = int(input())
swc = 0
top = ""
bot = ""
for i in range(q):
	a = list(map(str, input().split()))
	if a[0] == "1":
		if swc == 0:
			swc = 1
		else:
			swc = 0
	else:
		if swc == 0:
			if a[1] == "1":
				top += a[2]
			else:
				bot += a[2]
		else:
			if a[1] == "1":
				bot += a[2]
			else:
				top += a[2]
if swc == 0:
	print (top[::-1] + s + bot)
else:
	print (bot[::-1] + s[::-1] + top)

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

int main(){
    ll m;
    cin >> m;
    ll sum = 0;
    ll size = 0;
    for(int i = 0; i < m; i++){
        ll d, c;
        cin >> d >> c;
        sum += d*c;
        size += c;
    }
    cout << size-1+(sum-1)/9 << endl;
}

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

using namespace std;

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

    if(n%1000==0){
        cout << 0 << endl;
    }
    else{
        if(n<1000){
            cout << 1000-n << endl;
        }
        else{
            int t=((n/1000) + 1)*1000;
            cout << t-n << endl;
        }
    }

    return 0;
}

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

int main() {
  
  int N, A;//A is Alice's point. B is Bob's point.
  
  cin >> N;
  
  vector <int> a (N);
  
  //cout << N << endl;
  
  for (int i = 0; i < N; i++){
    
    cin >> a.at(i);
      
  }
  
  sort(a.begin(), a.end());
  
  A = 1;
  
  for (int i = 0; i < N; i++){
    
    if (i == 0)continue;
    
    if (a.at(i - 1) != a.at(i))A++;
    
  }
  
  cout << A << endl;
  
}


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

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: f64 = itr.next().unwrap().parse().unwrap();
    let m = n / 3.0;
    println!("{:.10}", m * m * m);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9;


int main(){
  int N;
  while(1){
    cin>>N;
    if(N==0){
      break;
    }
    int cnt=0;
    for(int i=1;i<N;i++){
      for(int j=2;j<N;j++){
        if(((2*i+j-1)*j)/2==N){
          cnt++;
          //cout<<i<<" "<<j<<endl;
        }
      }
    }
    cout<<cnt<<endl;
  }
  return 0;
}



Measured memory_bytes: 3068
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include <random>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,const vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,const pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

vvi to;
vi used;

int dfs(int v, int c) {
  if (used[v] != -1) {
    return used[v]==c;
  }
  used[v] = c;
  if (sz(to[v]) == 0) return 2;
  int res = 1;
  for (int u : to[v]) {
    if (!dfs(u,c^1)) res = 0;
  }
  return res;
}

int main() {
  int n,m;
  scanf("%d%d",&n,&m);
  to = vvi(n);
  rep(i,m) {
    int a,b;
    scanf("%d%d",&a,&b);
    --a; --b;
    to[a].pb(b);
    to[b].pb(a);
  }
  used = vi(n,-1);
  vl g(3);
  rep(i,n) {
    if (used[i] != -1) continue;
    g[dfs(i,0)]++;
  }
  // cout<<g<<endl;
  ll ans = 0;
  ans += g[0]*g[0];
  ans += g[0]*g[1]*2;
  ans += g[1]*g[1]*2;
  // cout<<g<<endl;
  ans += g[2]*n*2;
  ans -= g[2]*g[2];
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 9984
#!/usr/bin/env python3
# atcoder 
# Türkler var mı?
# Herkese memnün oldum
import sys
import math

iimr = lambda: map(int, sys.stdin.readline().rstrip().split())
readline = sys.stdin.readline
sys.setrecursionlimit(10 ** 8)

kame = 4
tsuru = 2

def 関数(x, y):
    if (x * 4) < y or (x * 2) > y:
        return "No"
    else:
        # C'est possible de diviser le y
        for a in range(x+1):
            for b in range(x+1):
                ax = a * 4
                bx = b * 2
                #print(ax,bx)
                if (bx + ax) == y and (a + b) == x:
                    #res = bx + ax
                    #print(ax, bx, "res=:{0}".format(res))
                    return("Yes")

    return("No")
                    

def çözmek():
    X,Y = map(int, sys.stdin.readline().split())

    res = []
    res.append(関数(X,Y))
    print(*res, sep="\n")

if __name__ == "__main__":
    çözmek()


Measured memory_bytes: 9224
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int k;
	cin>>n>>k;
	int a[n];
	int sum=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sum=sum+a[i];
	}
	double c= ((double)1/(4*k))*sum;
	int count=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]>=c)
		count++;
	}
	if(count>=k)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	
}

Measured memory_bytes: 3560
#include<iostream>
#include<queue>
#include<map>
#include<cstring>
using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> PP;

int bfs();
int n;
int bill[2][222];
bool flag[2][222];

int main(){
  while(1){
    memset(bill,0,sizeof(bill));
    cin >> n;
    if(n == 0) break;
    for(int i=0;i<n;i++){
      cin >> bill[0][i];
    }
    for(int i=0;i<n;i++){
      cin >> bill[1][i];
    }
    memset(flag,0,sizeof(flag));
    int ans = bfs();
    if(ans == -1) cout << "NA" << endl;
    else cout << ans << endl;
  }
}

int bfs(){
  queue<PP> que;
  que.push(PP(0,P(0,0)));
  que.push(PP(0,P(1,0)));
  while(!que.empty()){
    PP a = que.front();
    que.pop();
    int cou = a.first;
    int b = a.second.first;
    int k = a.second.second;
    if(bill[b][k] == 1){
      while(bill[b][k+1] == 1) k++;
    }
    else if(bill[b][k] == 2){
      while(bill[b][k] == 2) k--;
    }
    if(k == n-1) return cou;
    int v = 0;
    if(b == 0) v = 1;
    if(flag[v][k] == false){
      flag[v][k] = true;
      for(int i=0;i<3;i++){
	if(k+i < n){ 
	  que.push(PP(cou+1,P(v,k+i)));
	}
      }
    }
  }
  return -1;
}
    

Measured memory_bytes: 1220
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    vector<bool> o(n,true);
    rep(i,n) {
        cin >> p[i];
    }
    int ans = 0;
    rep(i,n) {
        if (p[i] == i+1) {
            if (i+1 < n) {
                swap(p[i],p[i+1]);
            } else {
                swap(p[i],p[i-1]);
            }
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3784
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {
    cout << std::fixed << std::setprecision(10);
    cin.tie(0);
    std::ios::sync_with_stdio(false);

    int n;
    double t, a;
    double h;
    cin >> n >> t >> a;
    int result;
    double best = 1000000;
    for (int i = 0; i < n; i++) {
        cin >> h;
        double temp = t - h * 0.006;
        double diff = a - temp;
        // cout << temp << " " << diff << endl;
        if (diff < 0)
            diff *= -1;
        if (diff < best) {
            best   = diff;
            result = i + 1;
        }
    }
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
int compare_int(const void *a, const void *b){
  return *(long int*)b - *(long int*)a; // 大きい順
}
// 公約数
long int gcd(long int a, long int b){
  if(b == 0){
    return a;
  }else{
    return gcd(b, a % b);
  }
}
// 最小公倍数 = a * b / 最大公約数
// 公倍数
long int lcm(long int a, long int b){
  return a * b / gcd(a, b);
}


// min
int main(void){
  int n;
  long int t[101];
  long int ans = 0;
  
  scanf("%d", &n);

  for(int i = 0; i < n; i++){
    scanf("%ld", &t[i]);
  }

  // 大きい順に並び替える
  qsort(t, n, sizeof(long int), compare_int);

  ans = t[0];
  for(int i = 1; i < n; i++){
    if(ans > t[i]){
      ans = ans / gcd(ans, t[i]) * t[i];
    }else{
      ans = t[i] / gcd(t[i], ans) * ans;
    }
  }
  
  printf("%ld\n", ans);
  return 0;
}


Measured memory_bytes: 128
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j + g] = A[j]
            j = j - g
            cnt += 1
        A[j + g] = v

def shellSort(A, n):
    global cnt
    G = []
    g = 1
    while g <= n:
        G.append(g)
        g = 3 * g + 1
    G = G[::-1]
    m = len(G)
    for i in range(m):
        insertionSort(A, n, G[i])
    return m, G, cnt, A

n = int(input())
A = []
for _ in range(n):
    A.append(int(input()))
cnt = 0
m, G, cnt, A = shellSort(A, n)
print(m)
for i in range(m):
    if i == m - 1:
        print(G[i])
    else:
        print(G[i], end=' ')
print(cnt)
for i in range(n):
    print(A[i])


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

int main() {
    int n;
    string s;
    cin >> n >> s;
    for (char i : {'S', 'W'}) {
        for (char j : {'S', 'W'}) {
            string result(n, 0);
            result[0] = i;
            result[1] = j;
            for (int k = 2; k < n; k++) {
                if (s[k - 1] == 'o' && result[k - 1] == 'S' || s[k - 1] == 'x' && result[k - 1] == 'W') {
                    result[k] = result[k - 2];
                } else {
                    if (result[k - 2] == 'S') {
                        result[k] = 'W';
                    } else {
                        result[k] = 'S';
                    }
                }
            }
            auto valid = [&](int i) {
                return (s[i] == 'o' && result[i] == 'S' || s[i] == 'x' && result[i] == 'W') && result[(i - 1 + n) % n] == result[(i + 1 + n) % n] || (s[i] == 'o' && result[i] == 'W' || s[i] == 'x' && result[i] == 'S') && result[(i - 1 + n) % n] != result[(i + 1 + n) % n];
            };
            if (valid(n - 1) && valid(0)) {
                cout << result;
                return 0;
            }
        }
    }
    cout << -1;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define dbg(x) cerr<<#x" = "<<x<<endl
#define rep(i,a,b) for(register int i=(a),i##_end=(b);i<=i##_end;++i)
#define per(i,a,b) for(register int i=(a),i##_st=(b);i>=i##_st;--i)
#define rpg(i,x) for(register int i=fir[x];i;i=e[i].nxt)
#define ull unsigned long long
#define fi first
#define se second
#define pb push_back
#define bin(i) (1<<i)
#define cla(x) memset(x,0,sizeof x)
#define meminf(x) memset(x,127,sizeof x)
typedef pair<int,int> pa;
typedef long long LL;
const int INF = 0x7fffffff;
const int oo = 0x3f3f3f3f;
const int L = 100000;
char ibuf[L],*ih=ibuf+L;
inline char gc(){return (ih==ibuf+L?fread(ibuf,1,L,stdin),ih=ibuf:0),*ih++;}
//#define  getchar() gc()
template<typename T>
inline void rd(T &x)
{
    x = 0 ; int f = 1; char CH = getchar();
    while(CH<'0'||CH>'9') {if(CH=='-')f=0;CH=getchar();}
    while(CH>='0'&&CH<='9') {x=(x<<3)+(x<<1)+(CH-48);CH=getchar();}
    x = f ? x : -x;	return;
}
LL x,y;
int main()
{
	rd(x),rd(y);
	LL tmp=x,cnt=0;
	while(tmp<=y) {tmp<<=1,cnt++;if(tmp<=0) break;}
	cout<<cnt;
}

Measured memory_bytes: 256
def frog(H,N):
    #print(H)
    DP = [0]*N
    DP[0] = 0
    DP[1] = abs(H[1]-H[0])
    for i in range(2,N):
        DP[i] = min(abs(H[i]-H[i-2])+DP[i-2],abs(H[i]-H[i-1])+DP[i-1])
    #print(DP)
    return DP[-1]    
if __name__ == '__main__':
    N = int(input())
    H = list(map(int,input().split()))
    ans = frog(H,N)
    print(ans)

Measured memory_bytes: 13928
#include <iostream>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int n, num;
char s;
int T[4][13];

int main(void) {
    cin >> n;
    for ( int i = 0; i < n; i++ ) {
        cin >> s >> num;
        if ( s == 'S' ) {
            T[0][num-1] = 1;
        } else if ( s == 'H' ) {
            T[1][num-1] = 1;
        } else if ( s == 'C' ) {
            T[2][num-1] = 1;
        } else if ( s == 'D' ) {
            T[3][num-1] = 1;
        } 
    }
    
    for( int k = 0; k < 4; k++ ) {
        for ( int j = 0; j < 13; j++){
            if ( k == 0 && T[0][j] == 0 ) {
                cout << 'S' << " " << j + 1 << endl;
            } else if( k == 1 && T[1][j] == 0 ) {
                cout << 'H' << " " << j + 1 << endl;
            } else if( k == 2 && T[2][j] == 0 ) {
                cout << 'C' << " " << j + 1 << endl;
            } else if( k == 3 && T[3][j] == 0 ) {
                cout << 'D' << " " << j + 1 << endl;
            } 
        }
    }
    
    return 0;
}


Measured memory_bytes: 3100
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class Main {

	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception addd) {
					addd.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception addd) {
				addd.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	
	public static FastReader sc = new FastReader();
 
	static int mod = (int) (1e9+7),MAX=(int) (2e5+100);
    static List<Integer>[] edges;
    static long[][][] dp;
    static int n,d;
    static char[] s;
    
	public static void main(String[] args) {
	
		s = sc.next().toCharArray();
		d = sc.nextInt();
		n = s.length;
		dp = new long[n+1][d][2];
		
		for(int i=0;i<dp.length;++i) {
			for(int j=0;j<dp[i].length;++j) Arrays.fill(dp[i][j], -1);
		}
	    long ans = (f(0,0,1) - 1 + mod)%mod;
	    out.print(ans);
		out.close();
   }

	private static long f(int i, int m, int l) {
		if(i == s.length) {
			if(m == 0) return 1;
			return 0;
		}
		if(dp[i][m][l] != -1) return dp[i][m][l];
		long o1 = 0;
		int end = (l==1)?s[i]-'0':9;
		for(int dig=0;dig<=end;++dig) {
			o1 = (o1 + f(i+1,(m+dig)%d,l&((dig == end)?1:0)))%mod;
		}
		return dp[i][m][l] = o1;
	}
	


    }



Measured memory_bytes: 88140
N=int(input())
l=input().split(' ')
l.sort()
count=0
i=0
while i <len(l):
    p=1
    while p < int(l[i]):
        if p+i == len(l):
            del l[i:i+p]
            count+=p
            p=0
            break
        elif l[i]!=l[i+p]:
            del l[i:i+p]
            count += p
            p=0
            break
        else:
            p+=1
    if p != 0:
        while i+p < N:
            if l[i] == l[i+p]:
                p+=1
            else:
                break
        del l[i+int(l[i]):i+p]
        count += p-int(l[i])
        i += int(l[i])
print(count)  

Measured memory_bytes: 11552
n = int(input())
ans = [n]
pay = []
for i in range(1, 10):
    if 6 ** i < 100000:
        pay.append(6 ** i)
    if 9 ** i < 100000:
        pay.append(9 ** i)
pay.sort(reverse=True)

def func(n, times):
    for i in range(len(pay)):
        n2 = n
        times2 = times
        if pay[i] <= n2:
            n2 -= pay[i]
            times2 += 1
            if ans[0] > times2 + n2:
                ans[0] = times2 + n2
            if n2 >= 6 and times2 < ans[0]:
                func(n2, times2)
            if n2 > pay[i]*2:
                break


func(n, 0)
print(ans[0])


Measured memory_bytes: 3064
//Utkarsh.25dec
#include <bits/stdc++.h>
#define ll long long int 
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
using namespace std;
const int N=100023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll n,w;
    cin>>n>>w;
    vector <pair<ll,ll>> v;
    ll dp[N+10];
    for(int i=1;i<=N;i++)
        dp[i]=1e18;
    dp[0]=0;
    rep(i,n)
    {
        ll a,b;
        cin>>a>>b;
        for(int j=N;j>=max((ll)0,b);j--)
        {
            dp[j]=min(dp[j],dp[j-b]+a);
        }
    }
    ll ans=0;
    for(int i=1;i<=N;i++)
    {
        if(dp[i]<=w)
            ans=i;
    }
    cout<<ans;
}
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
}

Measured memory_bytes: 3328
def fn(n):
    if n % 2 == 0:
        return n//2
    else:
        return 3*n + 1


s = int(input())

a = []
b = s
for i in range(10**6 + 1):
    if b not in a:
        a.append(b)
        b = fn(b)
    else:
        a.append(b)
        break
print(len(a))


Measured memory_bytes: 2940