akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;

int main()
{
    long a, b, x;  cin >> a >> b >> x;
    if (a == 0)  cout << b / x + 1 << endl;
    else  cout << b / x - (a - 1) / x << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

const int infI=1e9+5;
const long long infL=1e16;
const int MOD=1e9+7;
const int MAX=2e5+5;

#define mp make_pair
#define in &
#define pb push_back
#define ii pair<int,int>
#define iii pair<ii,int>
#define ll long long
#define pll pair<ll,ll>
#define vvl vector<vector<ll> >
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define eb emplace_back
#define forn(i,a,b) for(ll i=a;i<b;i++)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define endl '\n'
#define popb pop_back()
#define se second
#define fi first
#define debug(x) cerr<<x<<endl
#define test(t) int t;cin>>t;while(t--)
#define fordebug(x) cerr<<x<<" "

ll power(ll a,ll b){
    if(b==0){
        return 1;
    }
    if(b==1){
        return a;
    }
    ll temp=power(a,b/2);
    temp=(temp*temp)%MOD;
    if(b%2){
        temp=(temp*a)%MOD;
    }
    return temp;
}

//only use if mod is prime
ll mod_inv(ll a,ll mod){
    a%=mod;
    return power(a,mod-2);
}

void extended_gcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return;
    }
    ll x1,y1;
    extended_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-((a/b)*y1);
    return;
}

//TLE can also occur if vectors are not passed by reference

int main(){
    fastio;
    vl f;
    ll n;
    cin>>n;
    ll temp = n-1;
    for(ll i = 1;i*i<=n-1;++i){
        if(temp%i==0){
            f.pb(i);
            if(i*i!=temp){
                f.pb(temp/i);
            }
        }
    }
    ll ans = f.size();
    temp = n;
    f.clear();
    for(ll i = 2;i*i<=n;++i){
        if(temp%i==0){
            f.pb(i);
            if(i*i!=temp){
                f.pb(temp/i);
            }
        }
    }
    for(auto x:f){
        temp = n;
        while(temp%x==0){
            temp/=x;
        }
        if(temp%x==1){
            ++ans;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 384
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
	sc.Scan()

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

	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextF64() float64 {
	sc.Scan()

	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}
func f(x int) int {
	if x == 1 {
		return 1
	}
	return f(x/2)*2 + 1
}

func main() {
	sc.Split(bufio.ScanWords)

	var cnt int
	n := nextInt()
	var a []int
	for i := 0; i < n; i++ {
		a = append(a, nextInt())
	}

	for {
		for i := 0; i < len(a)-1; i++ {
			if a[i]%2 == 0 {
				a[i] /= 2
			} else {
				fmt.Println(cnt)
				return
			}

		}
		cnt++
	}
}


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

int main() {
  int n,m;
  cin>>n>>m;
  vector<int> a(m);
  
  vector<long long> dp(n+100);
  vector<bool> dd(n+100,true);
  for(int i=0;i<m;i++){
    cin>>a[i];
    dd[a[i]]=false;
  }
  dp[0]=1;
  if(a.size()==0) dp[1]=1;
  else{
    
  if(a[0]==1) dp[1]=0;
  else dp[1]=1;
  }
  for(int i=1;i<n+3;i++){
   
    if(dd[i+1]) dp[i+1]=dp[i]+dp[i-1];
    dp[i+1]%=(1000000000+7);
  }
  cout<<dp[n]<<endl;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <stack>
#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <climits>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	const char* str[] = {
		"0111111",
		"0000110",
		"1011011",
		"1001111",
		"1100110",
		"1101101",
		"1111101",
		"0100111",
		"1111111",
		"1101111"
	};
	int n;
	while(scanf("%d", &n), ~n){
		char s[] = "0000000";
		rep(i, n){
			int a;
			scanf("%d", &a);
			rep(i, 7){
				if(s[i] != str[a][i])
					putchar('1');
				else
					putchar('0');
				s[i] = str[a][i];
			}
			puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 1016
from sys import stdin


def main():
    N, L = [int(x) for x in stdin.readline().rstrip().split()]
    spam = [L + i - 1 for i in range(1, N + 1)]
    ham = [abs(x) for x in spam]
    if min(ham) in spam:
        print(sum(spam) - min(ham))
    else:
        print(sum(spam) + min(ham))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

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

  int n;
  cin >> n;
  VI a(n);
  REP(i, n) cin >> a[i];

	using D = uniform_int_distribution<ll>;
  random_device rd;
  mt19937 gen(rd());

  map<int, int> hash;
  REP(i, n) {
    if(hash.find(a[i]) != hash.end()) continue;
	  hash[a[i]] = D(0,LLINF)(gen);
  }

  int x = 0, y = 0;
  VI ans;
  REP(i, n) {
    x += hash[a[i]];
    y += hash[a[n-i-1]];
    if(x == y) ans.PB(i+1);
  }

  REP(i, ans.size()) {
    cout << ans[i] << (i==ans.size()-1?"\n":" ");
  }

  return 0;
}



Measured memory_bytes: 6920
#include<cstdio>

using namespace std;

int check(int n, int m){
	int o = (n % 2 == 0) + (m % 2 == 0);
	int e = (n % 2 == 1) + (m % 2 == 1);
	return (o == 1) && (e == 1);
}

int main(){
	int k; scanf("%d", &k);
	int res = 0;
	for(int i = 1; i <= k; i++) for(int j = i + 1; j <= k; j++){
		if(check(i, j)) res++;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define db cout<<"db: "
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define all(v) v.B,v.E
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)

int main()
{
    int n,i,j,t;
    boost;
    cin>>n;
    int ans=0;      
    rep(i,1,n+1)
    {
        cin>>j;
        if(i%2 and j%2) ans++;
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 3632
/* HARDWORK IS THE KEY TO SUCCESS.
   RATING IS TEMPORARY , KNOWLEDGE IS PERMANENT.!!!*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define T int t = 1; cin>>t; while(t--)
#define ain ll n,k,i; cin>>n; ll a[n]; for(i=0; i<n; i++) cin>>a[i]
#define matin ll m,n; cin >> n >> m; ll a[n + 1][m + 1]; for(ll i=1;i<=n;i++) for(ll j=1;j<=m;j++) cin>>a[i][j];
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define I insert
#define pb push_back

const ll maxs = 1e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;
inline ll add(ll a, ll b) { return (mod + a + b) % mod;}
inline ll sub(ll a, ll b) {return (a - b + mod) % mod;}
inline ll mul(ll a, ll b) {return (1ll * a * b) % mod;}
ll fastpow(ll x, ll y) {
    ll res = 1; x = x % mod; while (y > 0) { if(y & 1) res = (res * x) % mod; y = y >> 1;x = (x * x) % mod;}return res;}
ll inv(ll x) {
    return fastpow(x, mod - 2);
}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int a,b,c,d,e;
    cin >> a >> b >> c >> d >> e;
    if(a == 0)
    cout << 1;
    else if(b == 0)
    cout << 2;
    else if(c == 0)
    cout << 3;
    else if(d == 0)
    cout << 4;
    else if(e == 0)
    cout << 5;
   
}



Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main() {
    int N, X; cin >> N >> X;
    int count = 1;
    int sum = 0;
    for(int i = 0; i < N; i++) {
        int tmp; cin >> tmp;
        sum += tmp;
        if(sum > X) {
            break;
        } else {
            ++count;
        }
    }

    cout << count << endl;
}


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

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef long double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }


int main() {

    int N; cin >> N;
    double total;
    vector<double> V;
    forn(i, N) {
        double v; cin >> v;
        V.pb(v);
    }
    sort(V.begin(), V.end());
    forn(i, N-1) {
        total = (V[0]+V[1]) / 2;
        V.erase(V.begin() + 0);
        V.erase(V.begin() + 0);
        V.begin() = V.insert(V.begin(),total);
        
    }
    cout << V[0] << endl;

}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
#define all(x) (x).begin(),(x).end()
using namespace std;
signed main(){
	int a,b;
	cin>>a>>b;
	cout<<max({a+b,a-b,a*b})<<endl;
	return 0;
}


Measured memory_bytes: 256
from collections import deque

n=int(input())

g=[[] for _ in range(n+1)]

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

c=sorted(list(map(int,input().split())))
print(sum(c[:-1]))

q=deque([1])
visit=[0]*(n+1)
ans=['']*(n+1)

while len(q)>0:
    u=q.popleft()

    visit[u]=1

    ans[u]=str(c.pop())

    for v in g[u]:
        if visit[v]:
            continue

        q.append(v)

print(' '.join(ans[1:]))

Measured memory_bytes: 76784
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int n, m, ans, a[100], b[100];
bool g[51][51], d[51];

bool dfs(int v) {
    d[v] = true;
    bool all_visited = true;
    rep(i, 0, n) {
        if (!d[i]) {
            all_visited = false;
            break;
        }
    }
    if (all_visited) return true;

    bool flag = false;
    rep(i, 0, n) {
        if (!d[i] && g[v][i])
            flag = dfs(i);
    }
    return flag;
}

int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> n >> m;
    rep(i, 0, m) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        g[a[i]][b[i]] = g[b[i]][a[i]] = true;
    }
    
    rep(i, 0, m) {
        g[a[i]][b[i]] = g[b[i]][a[i]] = false;
        if (!dfs(0)) ans++;
        g[a[i]][b[i]] = g[b[i]][a[i]] = true;        
        rep(i, 0, n) d[i] = false;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n;
	scanf("%d", &n);
	ll ans=1;
	for(int i=1;i<=n;i++){
		ll tmp;
		scanf("%lld", &tmp);
		ll g=__gcd(ans, tmp);
		ans=ans/g*tmp;
	}
	printf("%lld\n", ans);
}



Measured memory_bytes: 256
#include <math.h>
#include <assert.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <array>
#include <random>
#include <chrono>
#include <climits>
#include <bitset>
using namespace std ;
#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
//const int N = 3e5+7 ;
//const int INF = 1e18 ;
//const int MOD = 1e9 + 7 ;

void solve(){
    int n ;
    cin >> n ;
    vector<int> a(n) ;
    for(int i = 0 ; i < n ; i++){
    	cin >> a[i] ;
    }
    int ret = 1000 ;
    int cur = 0 ;
    for(int i =1 ; i < sz(a) ; i++){
    	if(a[i]>a[i-1]){
    		int dif = a[i]-a[i-1] ;
    		int buy = ret/a[i-1];
    		int rem = ret - buy * a[i-1] ;
    		ret = rem + buy*a[i] ;
    	}
    }
    cout << ret << endl ;
}

int32_t main(){
    FAST_IO ;
    int t = 1 ;
//  cin >> t ;
    while(t--){
        solve() ;
    }
}


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

int main() {
  int N;
  cin>>N;
  
  int ans=0;
  for(int i=N; ;++i){
  	if(i%111==0){
      ans=i;
      break;
    }
  }
  
  cout<<ans<<endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
  int k, n;
  cin >> k >> n;
  int ans = k;
  int first;
  cin >> first;
  int before = first;
  int max_dis = 0;
  repd(i, 1, n){
    int a;
    cin >> a;
    max_dis = max(abs(a - before), max_dis);
    if(i == n-1){
      max_dis = max(abs(first + k-a), max_dis);
    }
    before = a;
  }
  ans -= max_dis;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int i,m,n,c=0,s=0,l;
  cin>>n>>m;
  int a[n];
  for(i=0;i<n;i++)
  {
    cin>>a[i];
    s=s+a[i];
  }
  l=ceil(s/(4.0*m));
  sort(a,a+n);
  for(i=n-1;i>=0;i--)
  {
    if(a[i]>=l)
      c++;
    else
      break;
  }
  if(c>=m)
    cout<<"Yes\n";
  else
    cout<<"No\n";
  return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  zero
//
//  Created by 叶金炜 on 2019/4/2.
//  Copyright © 2019 okstal. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int main() {
    int n=1,x;
    while(cin>>x&&x!=0)
    {
        cout<<"Case "<<n<<": "<<x<<endl;
        n++;
    }
    return 0;
}



Measured memory_bytes: 2996
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;


int main()
{
	int n, t;
	cin >> n >> t;
	vector<int>a(n);
	vector<int>b(n);

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

	int ans = 0;

	for (int i = 1;i < n;i++)
	{
		if (a[ans] > a[i])
		{
			if (b[i] <= t)
			{
				ans = i;
			}
		}
	}

	if (ans == 0)
	{
		if (b[0] > t)
		{
			cout << "TLE" << endl;
			return 0;
		}
	}

	cout << a[ans] << endl;
}

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

struct Dice{
	int num[6];
};

void move(struct Dice *dice, string str){
	int store[6];

	for(int i=0;i<str.length();i++){
		for(int j=0;j<6;j++){
			store[j] = (*dice).num[j];
		}
		switch(str[i]){
		case 'N':
			(*dice).num[0] = store[1];
			(*dice).num[1] = store[5];
			(*dice).num[5] = store[4];
			(*dice).num[4] = store[0];
			break;
		case 'E':
			(*dice).num[0] = store[3];
			(*dice).num[3] = store[5];
			(*dice).num[5] = store[2];
			(*dice).num[2] = store[0];
			break;
		case 'S':
			(*dice).num[0] = store[4];
			(*dice).num[4] = store[5];
			(*dice).num[5] = store[1];
			(*dice).num[1] = store[0];
			break;
		case 'W':
			(*dice).num[0] = store[2];
			(*dice).num[2] = store[5];
			(*dice).num[5] = store[3];
			(*dice).num[3] = store[0];
			break;
		}
	}
}

int main(){
	struct Dice dice;
	int q, front, top;
	for(int i=0;i<6;i++){
		cin>>dice.num[i];
	}

	cin>>q;
	for(int i=0;i<q;i++){
		cin>>top>>front;
		int x;

		for(int j=0;j<6;j++){
			if(dice.num[j] == top)   x = j;
		}

		switch(x){
		case 0:
			break;
		case 1:
			move(&dice, "N");
			break;
		case 2:
			move(&dice, "W");
			break;
		case 3:
			move(&dice, "E");
			break;
		case 4:
			move(&dice, "S");
			break;
		case 5:
			move(&dice, "NN");
			break;
		}

		for(int j=1;j<5;j++){
			if(dice.num[j] == front) x = j;
		}

		switch(x){
		case 1:
			x = 2;
			break;
		case 2:
			x = 4;
			break;
		case 3:
			x = 1;
			break;
		case 4:
			x = 3;
			break;
		}

		cout<<dice.num[x]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include <stdio.h>

#define MOD_BY 1000000007
#define BUFFER_SIZE 100

char A[BUFFER_SIZE];
char B[BUFFER_SIZE];
char C[BUFFER_SIZE];

/* [pos][carry] */
int memo[BUFFER_SIZE][2];

int search(int pos,int carry) {
	int ret=0;
	int a,b;
	int amin,amax,bmin,bmax;
	if(pos<0)return (carry==0?1:0);
	if(memo[pos][carry]>0)return memo[pos][carry]-1;
	if(A[pos]=='?'){amin=0;amax=9;} else amin=amax=A[pos]-'0';
	if(B[pos]=='?'){bmin=0;bmax=9;} else bmin=bmax=B[pos]-'0';
	for(a=amin;a<=amax;a++) {
		for(b=bmin;b<=bmax;b++) {
			int c=a+b+carry;
			int cv=c%10,cc=c/10;
			/* zero at first digit is not arrowed */
			if(pos==0 && (a==0 || b==0 || cv==0))continue;
			if(C[pos]=='?' || C[pos]==cv+'0') {
				ret+=search(pos-1,cc);
				if(ret>=MOD_BY)ret-=MOD_BY;
			}
		}
	}
	memo[pos][carry]=ret+1;
	return ret;
}

int main(void) {
	while(scanf("%s",A)==1) {
		int i;
		if(A[0]=='0')break;
		if(scanf("%s%s",B,C)!=2)break;
		for(i=0;i<BUFFER_SIZE;i++) {
			memo[i][0]=memo[i][1]=0;
		}
		for(i=0;A[i]!='\0';i++);
		printf("%d\n",search(i-1,0));
	}
	return 0;
}

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

int main(){
    int n = 0;
    char str[10001];
    scanf("%d %s",&n,str);
    int len = strlen(str);
    for (int i = 0; i < len; i++){
        str[i] += n;
        if(str[i] > 'Z'){
            str[i] -= 26;
        }
    }
    printf("%s\n",str);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
//cout << setprecision(20) << 

int D = 365;
vector<int> c(27);
vector<vector<int>> s(D + 1);

ll calc_score(vector<int> &t) {
    ll satisfy = 0;
    vector<int> last(27, 0);
    for (int i = 1; i <= D; ++i) {
        int con = t[i];
        // add satisfy
        satisfy += s[i][con];
        // update last
        last[con] = i;
        // sub satisfy
        for (int j = 1; j <= 26; ++j) {
            satisfy -= c[j] * (i - last[j]);
        }
    }
    return satisfy;
}

int main() {
    clock_t start = clock();

    cin >> D;
    for (int i = 1; i <= 26; ++i) cin >> c[i];
    for (int i = 1; i <= D; ++i) {
        vector<int> v(27);
        for (int j = 1; j <= 26; ++j) cin >> v[j];
        s[i] = v;
    }

    // output
    vector<int> ans(D + 1);
    vector<int> last(27, 0);
    ll satisfy = 0;
    for (int i = 1; i <= D; ++i) {
        ll best_contest = 0;
        ll best_score = -999999999;
        vector<int> c_last = last;
        for (int j = 1; j <= 26; ++j) {
            ll tmp_satisfy = satisfy;
            int con = j;
            // add satisfy
            tmp_satisfy += s[i][j];
            // update last
            c_last[con] = i;
            // sub satisfy
            for (int j = 1; j <= 26; ++j) {
                tmp_satisfy -= c[j] * (i - c_last[j]);
            }
            if (tmp_satisfy > best_score) {
                best_contest = j;
                best_score = tmp_satisfy;
            }
        }
        // actual update
        int con = best_contest;
        last[con] = i;
        ans[i] = con;
    }

    // random
    // cout << "random" << endl;
    // clock_t end = clock();
    // double time = static_cast<double>(end-start) / CLOCKS_PER_SEC * 1000.0;
    ll best_score = calc_score(ans);
    random_device rd{};
    for (int i = 0; i < 5000; ++i) {
        // random
        ll times = rd() % 100;
        vector<int> c_ans = ans;
        for (int j = 0; j < times; ++j) {
            ll day = rd() % 360 + 1;
            ll con = rd() % 25 + 1;
            c_ans[day] = con;
        }
        ll score = calc_score(c_ans);
        if (score > best_score) ans = c_ans;
        // end = clock();
        // time = static_cast<double>(end-start) / CLOCKS_PER_SEC * 1000.0;
    }

    // output
    for (int i = 1; i <= D; ++i) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 3712
while 1:
    N = int(raw_input())
    if N == 0: break
    free = [map(int,raw_input().split())[1:] for i in xrange(N)]
    have = [set([i]) for i in xrange(N)]
    for day in xrange(1,31):
        gather = set([])
        come = [i for i in xrange(N) if day in free[i]]
        for i in come:
            gather |= have[i]
        if len(gather) == N:
            print day
            break
        for i in come:
            have[i] = gather.copy()
    else:
        print -1
    

Measured memory_bytes: 4340
H, W = map(int, input().split())
f = [list(input()) for _ in range(H)]

for y in range(H):
    for x in range(W):
        if f[y][x] == '#':
            flag = 0
            for dy, dx in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
                ny, nx = y + dy, x + dx
                if 0 <= nx < W and 0 <= ny < H:
                    if f[ny][nx] == '#':
                        flag = 1
            if flag == 0:
                print('No')
                exit()
print('Yes')

Measured memory_bytes: 3064
import javax.swing.*;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int count = sc.nextInt();
        int maxWeight = sc.nextInt();
        long[] weights = new long[count];
        int[] values = new int[count];
        for (int i = 0; i < count; i++) {
            weights[i] = sc.nextLong();
            values[i] = sc.nextInt();
        }
        int maxValue = 100001;
        long[][] res = new long[count][maxValue];
        boolean[][] b = new boolean[count][maxValue];
        for (int i = 0; i < count; i++) {
            for(int j= 0; j < maxValue; j++) {
                res[i][j] = Integer.MAX_VALUE;
            }
        }
        for (int i = 0; i < maxValue; i++) {
            b[0][i] = true;
        }
        res[0][values[0]] = weights[0];
        res[0][0] = 0;
        long result = calculate(res, weights, values, count - 1, maxValue - 1,b);
        int min = 0;
        for (int i = 0 ; i < count; i++) {
            for (int j = 0 ; j < maxValue; j++) {
                if (calculate(res, weights, values,  i, j,b) <= maxWeight) {
                    min = Math.max(j, min);
                }

            }
        }
        System.out.println(min);
    }

    public static long calculate(long[][] res, long[] weights, int[] values, int index, int value, boolean[][] b) {
        if (index == 0) {
            return res[index][value];
        }
        if (b[index][value]) {
            return res[index][value];
        }
        int curValue = values[index];
        long mesame = Integer.MAX_VALUE;
//        if (value > 0) {
//            mesame = calculate(res, weights, values, index, value - 1, b);
//        }
        long without = calculate(res, weights, values, index - 1, value, b);
        long with = Integer.MAX_VALUE;
        if (value >= curValue) {
            with = calculate(res,weights, values, index -1, value - curValue, b) + weights[index];
        }
        res[index][value] = Math.min(Math.min(without, with), mesame);
        b[index][value] = true;
        return res[index][value];
    }
}

Measured memory_bytes: 129748
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;

using ll = long long;

ll A, B, V, W, T;

int main()
{
    cin >> A >> V >> B >> W >> T;
    ll D = abs(A-B);
    if(D <= T*V - T*W)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3
#define LINF 0x3f3f3f3f3f3f3f
#define MAXN int(2*1e5)+5
#define fim '\n'
#define ll long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << fim
#define debug2(x, y) cout << "DEBUG " << x << " " << y << fim
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< fim
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << fim
#define max3(x, y, z) max(x, max(y, z))
#define ull unsigned long long
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<unsigned ll, pair<int, int> > piii;
typedef pair<pair<int, int>, int> piii2;
typedef tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll mod = 1e9+7;

int main() {
	FAST;
	ll n;
	cin >> n;
	ll ans = n;
	for(long long i = 1; i*i <= n; i++) {
		if(n%i) continue;
		ans = min(ans, n/i);
	}
	cout << ans+(n/ans)-2 << endl;
}


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

int main(){
  int n,k,i,x,a=0;
  cin>>n>>k;
  for(i=0;i<n;i++){
    cin>>x;
    if(k-x<x)a+=k-x;
    else a+=x;
  }
  cout<<a*2<<endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
visit = [1]

for i in range(n):
    visit.append(a_list[visit[-1] - 1])

for i in range(n - 1):
    if visit[-1]  == visit[n - i - 1]:
        break
s = i + 1

for i in range(n - s):
    if visit[i] == visit[i + s]:
        break

if k < i:
    print(visit[k])
else:
    print(visit[i + (k - i) % s])

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int n;
string s[15];



inline string cmp(string a,string b){
	if(a=="") return b;
	if(b=="") return a;
	if(a.size()<b.size()) return a;
	if(b.size()<a.size()) return b;
	return min(a,b);
}

int main(void){
	while(cin >> n,n){
		rep(i,n) cin >> s[i];

		bool rm[15];
		int rel[15][15];

		rep(i,n) rm[i]=false;
		rep(i,n)rep(j,n) rel[i][j]=0;

		rep(i,n)rep(j,n){
			if(i>=j) continue;
			if(s[i].find(s[j])!=string::npos) rm[j]=true;
			if(s[j].find(s[i])!=string::npos) rm[i]=true;
			if(s[i]==s[j]) rm[i]=false;
		}
		rep(i,n)rep(j,n){
			if(i==j) continue;
			if(rm[i]||rm[j])
				rel[i][j]=0;
			else{
				int m=min(s[i].size(),s[j].size());
				for(int k=m-1;k>=1;--k){
					if(s[i].substr(s[i].size()-k,k)==s[j].substr(0,k))
						rel[i][j]=k,k=0;
				}
			}
		}

		vi a;
		rep(i,n) if(!rm[i]) a.pb(i);
		n=a.size();
		string dp[1<<10][10];
		rep(i,1<<n)rep(j,n) dp[i][j]="";
		rep(i,n) dp[1<<i][i]=s[a[i]];

		range(mask,1,1<<n)rep(i,n){
			if(!(mask&(1<<i))) continue;
			rep(j,n){
				if(mask&(1<<j)) continue;
				int prev=a[i],cur=a[j];
				string res=dp[mask][i];
				int k=rel[prev][cur];
				res+=s[cur].substr(k,s[cur].size()-k);
				dp[mask|(1<<j)][j]=cmp(dp[mask|(1<<j)][j],res);
			}
		}
		string ans="";
		rep(i,n) ans=cmp(ans,dp[(1<<n)-1][i]);
		cout << ans << endl;
	}
	return 0;
}

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

using ll = long long;

const ll MOD = 1000000007;

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

    int d;
    cin >>d;
    
    if (d == 22) cout << "Christmas Eve Eve Eve\n";
    else if (d == 23) cout << "Christmas Eve Eve\n";
    else if (d == 24) cout << "Christmas Eve\n";
    else if (d == 25) cout << "Christmas\n";

    return 0;
}


Measured memory_bytes: 256
N = int(input())

BA = 0
BX = 0
XA = 0

ans = 0

for i in range(N):
    S = input()
    if S[0] == 'B' and S[-1] == 'A':
        BA += 1
    elif S[0] == 'B':
        BX += 1
    elif S[-1] == 'A':
        XA += 1

    for a, b in zip(S, S[1:]):
        # print(a, b)
        if a == 'A' and b == 'B':
            ans += 1

# print(BA, BX, XA, ans)

if BA == 0:
    ans += min(BX, XA)
else:
    if BX == 0 and XA == 0:
        ans += BA - 1
    else:
        ans += BA + min(BX, XA)

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
  int n,l;cin>>n>>l;
  vector<int> a(n);
  vector<int> b(n);
  int ans;
  for(int i=0;i<n;++i) a[i] = abs(l+i);
  sort(a.begin(),a.end());
  for(int i=0;i<n;++i) b[i] = l+i;
  for(int i:b) ans += i;
  if(b[b.size()-1]<=0) ans += a[0];
  else ans -= a[0];
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

ll s(ll n){
	ll ret=0;
	while(n){
		ret+=n%10;
		n/=10;
	}
	return ret;
}
int main(){
 	ll n;cin>>n; 
 	cout<<(n%s(n)?"No":"Yes")<<endl;
  return 0;
}

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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll A, B, M;
    cin >> A >> B >> M;

    vector<int> arrayA(A);
    vector<int> arrayB(B);

    int amin = INT_MAX;
    int bmin = INT_MAX;
    REP(i, A){
        int a;
        cin >> a;
        arrayA[i] = a;
        amin = min(amin,a);
    }
    REP(i, B){
        int b;
        cin >> b;
        arrayB[i] = b;
        bmin = min(bmin,b);
    }

    int curmin = amin + bmin;

    int cmin = INT_MAX;
    REP(i, M){
        int a, b, c;
        cin >> a >> b >> c;
        cmin = min( cmin, arrayA[a-1] + arrayB[b-1] - c);
    }

    curmin = min(cmin, curmin);
    cout << curmin << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int a[300010];
int k, n;
int nokori;

int main()
{
	read(k, n);
	if(k%2 == 0){
		printf("%d ", k/2);
		for(int i=2; i<=n; ++i) printf("%d ", k);
		putchar(10);
		return 0;
	}
	for(int i=1; i<=n; ++i) a[i]=(k+1)/2;
	nokori = n - (n+1)/2;
	int lst = n;
	
	while(nokori){
		//printf("Nokori %2d # ", nokori); for(int i=1; i<=lst; ++i) printf("%d ", a[i]); putchar(10);
		if(a[lst] == 0){
			if(a[lst-1] == 1){
				--lst;
				--nokori;
				a[lst] = 0;
				continue;
			}
			--a[lst-1];
			for(int i=lst; i<=n; ++i) a[i]=k;
			lst = n;
			--nokori;
			continue;
		}
		int he=min(a[lst], nokori);
		nokori -= he;
		a[lst] -= he;
	}
	if(a[lst] == 0) --lst;
	for(int i=1; i<=lst; ++i) printf("%d ", a[i]);
	return 0;
}


Measured memory_bytes: 3456
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cstdlib>

#define int long long
using namespace std;

int A, B, Q, s[100010], t[100010], x[100010];

bool isOK(int index, int key, int a[]) {
	if (a[index] >= key) return true;
	else return false;
}

// 汎用的な二分探索のテンプレ
int binary_search(int key, int a[],int SIZE) {
	int left = 0; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = SIZE+1; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

							   /* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key,a)) right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return left;
}




signed main()
{
	cin >> A >> B >> Q;
	for (int i = 1; i < A+1; i++) {
		cin >> s[i];
	}
	s[0] = -1000000000000;
	s[A + 1] = 1000000000000;
	for (int i = 1; i < B+1; i++) {
		cin >> t[i];
	}
	t[0] = -1000000000000;
	t[B + 1] = 1000000000000;
	for (int i = 0; i < Q; i++) {
		cin >> x[i];
	}

	int S, T;

	for (int i = 0; i < Q; i++) {
		S = binary_search(x[i], s, A);
		T = binary_search(x[i], t, B);
		cout <<
			min({abs(x[i]-s[S])+abs(s[S]-t[T]),
				abs(x[i]-s[S])+abs(s[S]-t[T+1]),
				abs(x[i] - s[S+1]) + abs(s[S+1] - t[T]),
				abs(x[i] - s[S+1]) + abs(s[S+1] - t[T + 1]),
				abs(x[i] - t[T]) + abs(s[S] - t[T]),
				abs(x[i] - t[T]) + abs(s[S+1] - t[T]),
				abs(x[i] - t[T + 1]) + abs(s[S] - t[T+1]),
				abs(x[i] - t[T + 1]) + abs(s[S + 1] - t[T + 1])
				})
			<< endl;

	}

	//system("pause");
    return 0;
}



Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,o,e) for(int i=o;i<e;i++)
#define int long long int

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n;
	cin>>n;
	int a[n];
	FOR(i,0,n)
	{
		cin>>a[i];
	}
	int max=a[0];
	int t=0;
	FOR(i,1,n)
	{
		if(a[i]<max)
		{
			t+=(max-a[i]);
		}
		else if(a[i]>max)
		{
			max=a[i];
		}
	}
	cout<<t;

	return 0;
}

Measured memory_bytes: 5220
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll x,y;

int main(void){
	scanf("%lld %lld",&x,&y);
	ll cnt=0;
	while(x<=y){
		cnt++;
		x*=2LL;
	}
	printf("%lld\n",cnt);
	return 0;
}

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

int main() {
	int n, t;
	cin >> n >> t;
	pair<int, int> dat[n];
	for (int i = 0; i < n; i++) {
		cin >> dat[i].first >> dat[i].second;
	}
	sort(dat, dat + n);
	for (auto e : dat) {
		if (e.second <= t) {
			cout << e.first << endl;
			return 0;
		}
	}
	cout << "TLE" << endl;
	return 0;
}

Measured memory_bytes: 256
//48
#include<iostream>

using namespace std;

int main(){
  int cho=0,hishi=0;
  for(int a,b,c;((cin>>a).ignore()>>b).ignore()>>c;){
    hishi+=a==b;
    cho+=c*c==a*a+b*b;
  }
  cout<<cho<<endl<<hishi<<endl;
  return 0;
}

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

int main(){
    int N, cnt = 0;
    string A, B, C;

    cin >> N;
    cin >> A >> B >> C;
    for (int i = 0; i < N; i++){
        if(A[i] == B[i] && A[i] == C[i])
            continue;
        else if(A[i] != B[i] && B[i] != C[i] && C[i] != A[i])
            cnt += 2;
        else
            cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
from itertools import accumulate #list(accumulate(A))

N, K = mi()
S = input()

len_list = []
ind = 0
if S[0] == '0':
    #len_list[0] = 0
    len_list.append(0)
    #ind += 1

cnt = 1
for i in range(1, N):
    if S[i] != S[i-1]:
        #len_list[ind] = cnt
        len_list.append(cnt)
        #ind += 1
        cnt = 1
    else:
        cnt += 1
#len_list[ind] = cnt
len_list.append(cnt)

l_list = len(len_list)
wa = [0] + list(accumulate(len_list))
ans = 0
i = 1
l_wa = len(wa)
while True:
    if i+2*K >= l_wa:
        ans = max(ans, wa[l_wa-1] - wa[i-1]) 
        break
    #if i == 0:
        #ans = wa[i+2*K+1]
    ans = max(ans, wa[i+2*K] - wa[i-1]) 
    i += 2
print(ans)

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

//.define
// #define FILE_IN_OUT
#define RET(_x)                       return cout << (_x) << '\n', 0;
#define all(_obj)                     std::begin(_obj), std::end(_obj)
#define loop(_n)                      for (int i = 0; i < (_n); ++i)
#define ceilDiv(_dividend, _divider)  (((_dividend) - 1LL + (_divider)) / (_divider))
#define has(_obj, _val)               ((_obj).find(_val) != (_obj).end())
#define sz(_obj)                      static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x)                     std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x)                     {}
#endif
#define endl "\n"
template<typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
    for (Tp current = _begin; current != _end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll  = long long;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<const int>(1e9 + 7);

//.data
int arr[100000];
int dp[101005];

//.code
int main() {
#ifdef FILE_IN_OUT
    std::ifstream cin ("input.txt",  std::ios::in);
    std::ofstream cout("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif

    int n, k;
    cin >> n >> k;
    loop(n) {
        cin >> arr[i];
    }
    memset(dp, INF, sizeof(dp));
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 1; j <= k; ++j) {
            dp[i + j] = min(dp[i + j], dp[i] + abs(arr[i + j] - arr[i]));
        }
    }
    cout << dp[n - 1] << endl;

#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}


Measured memory_bytes: 1152
#include <vector>
#include <algorithm>
#include <cstdio>
int x[100001],d[100001],c[100001];

int lis(int n){
	int i,j,I;
/*
	for(i=-1;I=0,++i<n;d[i]=I+1)
		for(j=i-1;~j;j--)
			if(x[j]<x[i]&&I<d[j])I=d[j];
*/
	// http://stackoverflow.com/questions/6129682/longest-increasing-subsequenceonlogn
	int sz = 1;
	c[1] = x[0];
	d[0] = 1;
	for(i=0;++i<n;){
		if(x[i] < c[1]){
			c[1] = x[i];
			d[i] = 1;
		}else if(x[i] > c[sz]){
			c[sz+1] = x[i];
			d[i] = sz+1;
			sz++;
		}else{
			int k = std::lower_bound(c,c+sz,x[i])-c;
			c[k] = x[i];
			d[i] = k;
		}
	}
	for(i=j=0;i<n;i++)
		if(d[i]>d[j])j=i;
	return d[j];
}

int n;
int main(){
	for(;;){
		n=0;
		std::vector<std::pair<int,int>>v;
		int a,b;
		for(int k=0;k<2;k++){
			int n0;
			if((!~scanf("%d",&n0)||!n0) && k==0)return 0;
			for(n+=n0;n0--;){
				scanf("%d%d",&a,&b);
				v.emplace_back(a,-b);
			}
		}
		std::sort(v.begin(),v.end());
		for(int i=0;i<n;i++)x[i]=-v[i].second;
		printf("%d\n",lis(n));
	}
}

Measured memory_bytes: 2580
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0 ; i<n ; i++){
    cin>>a[i];
  }

  long long sum=0;
  int mi=a[0],ma=a[0];
  for(int i=0;i<n;i++){
    sum=sum+a[i];
    ma=max(ma,a[i]);
    mi=min(mi,a[i]);
  }
  cout<<mi<<" "<<ma<<" "<<sum<<endl;
  
  return 0;
}



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

int main() {
	int n, m;	cin >> n >> m;
	vector<int> k(n);
	vector<vector<int>> a(n);
	for (int i = 0; i < n; i++) {
		cin >> k[i];
		for (int j = 0; j < k[i]; j++) {
			int tmp;
			cin >> tmp;
			a[i].push_back(tmp - 1);
		}
	}

	int count = 0;
	bool not_found = false;
	for (int i = 0; i < m; i++) {
		not_found = false;
		for(int j = 0; j < n; j++){
			auto itr = find(a[j].begin(), a[j].end(), i);
			if (itr == a[j].end()) {
				not_found = true;
				break;
			}
		}
		if (not_found == false) {
			count++;
		}
	}
	cout << count;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,x;cin>>N>>x;
  vector<int> a(N);
  for(int i=0;i<N;i++)cin>>a.at(i);
  sort(a.begin(),a.end());
  int count=0;
  for(int i=0;i<N;i++){
    if(x>=a.at(i)){
      count++;
      x-=a.at(i);
    }
    else break;
  }
  if(x==0)cout<<count<<endl;
  else if(count<N)cout<<count<<endl;
  else cout<<count-1<<endl;
}

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

typedef long long ll;
const ll INF = 1e18;
const int BIG = 1e9 + 555;
const int maxN = 100 * 1000 + 9;

int n;
string s[maxN];

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

	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> s[i];
		sort(s[i].begin(), s[i].end());
	}

	sort(s + 1, s + n + 1);

	ll cur = 1;
	ll ans = 0;
	for(int i = 2; i <= n; i++){
		if(s[i] != s[i - 1]){
			ans += (cur * (cur - 1)) / 2;	
			cur = 0;
		}

		cur++;
	}

	ans += (cur * (cur - 1)) / 2;

	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <cstring>
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define PI acos(-1.0)
typedef long long ll;
const int INF=0x3f3f3f3f;
//const ll INF=1000000000000000000;

//priority_queue<int, vector<int>, greater<int> >p;
int main()
{
    ll n,k;
    ll sum=0;
    scanf("%lld%lld",&n,&k);
    if(k==0)
    {
        printf("%lld\n",n*n);
        return 0;
    }
    for(int i=1;i<=n;i++)
    {
        if(i<=k)continue;
        ll t=i-k;
        sum+=(n/i)*t;
        if((n%i)-k>=0)sum+=(n%i)-k+1;
    }
    printf("%lld\n",sum);
    return 0;
}



Measured memory_bytes: 256
n = int(input())
g = [[0]*10 for _ in range(10)]
for i in range(1,1+n):
  a = int(str(i)[0])
  b = i%10
  g[a][b] += 1
ans = sum(g[a][b]*g[b][a] for a in range(10) for b in range(10))
print(ans)

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

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main() {
    int n; cin >> n;
    vector<int> a(n);
    for (int &ai: a) cin >> ai;
    vector<int> left(n + 1), right(n + 1);
    for (int i = 0; i < n; i++) left[i + 1] = gcd(left[i], a[i]);
    for (int i = n - 1; i >= 0; i--) right[i] = gcd(right[i + 1], a[i]);
    int ma = 0;
    for (int i = 0; i < n; i++) {
        ma = max(ma, gcd(left[i], right[i + 1]));
    }
    cout << ma << endl;
    return 0;
}

Measured memory_bytes: 1408
import * as fs from "fs";

const input = fs
  .readFileSync("/dev/stdin", "utf8")
  .split("\n")[1]
  .split(" ")
  .map(Number);
let ans = 0;
let max = input[0];
input.forEach((x,i) => {
  // 後ろの値が小さければ追加の処理;
  if(input[i] < max ) {
    ans +=  max - input[i];
  }else {
    // そうじゃない時は値を更新
  	max = input[i]
  }
});
console.log(ans);

Measured memory_bytes: 50544
#include<iostream>
#include<algorithm>

using namespace std;

int main()
{
	static bool era[10000000];
	era[0]=era[1]=true;
	for(int i=2;i<4000;i++){
		if(!era[i])	for(int j=i*i;j<=10000000;j+=i)	era[j]=true;
	}

	int sz=0,pq[1000];
	for(int i=8;i<=10000000;i++){
		if(!era[i-8] && !era[i-6] && !era[i-2] && !era[i])	pq[sz++]=i;
	}

	for(int n;cin>>n,n;)	cout<<*(upper_bound(pq,pq+sz,n)-1)<<endl;

	return 0;
}

Measured memory_bytes: 10000
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class C
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		int[] A = Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();

		var invA = new Dictionary<int, int>();
		for(int i = 0; i < N; i++)
			invA[A[i]] = i;

		Array.Sort(A);

		long ans = 0;
		for(int i = 0; i < N; i++)
			if((i + invA[A[i]]) % 2 == 1)
				ans++;

		Console.WriteLine(ans / 2);	
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
}


Measured memory_bytes: 23888
#include<iostream>
#include<string>
using namespace std;
int main()
{
  int K;
  cin >> K;

  int K_1 = int(K/2);
  if(K % 2 == 1){
    cout << (K_1+1)*K_1 << endl;
  }else{
    cout << K_1 * K_1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long i64;
using std::cout;
using std::endl;
using std::cin;

int main(){
	int n; cin >> n; std::vector<int> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	
	int now = 0, c = 0;
	std::vector<bool> used(n, false); used[0] = false;
	while(!used[now]) {
		used[now] = true; c += 1;
		
		now = a[now] - 1;
		if(now == 1) {
			cout << c << endl;
			return 0;
		}
	}
	
	cout << -1 << endl;
	return 0;
}


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

int main(){
	int n, m, sum;
	cin >> n >> m;
	int mat[n*m];
	int vec[m];
	for(int i =0; i < n*m; i++){
		cin >> mat[i];
	}
	for(int i = 0; i < m; i++){
		cin >> vec[i];
	}
	for(int y = 0; y < n; y++){
		sum = 0;
		for(int x = 0; x < m; x++){
			sum += mat[y*m+x] * vec[x];
		}
		cout << sum << endl;
	}
	return 0;
}	



Measured memory_bytes: 3108