akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<set>
#include<map>
#include<bitset>
#include<ctime>
#include<queue>
using namespace std;
#define int long long
#define pii pair <int, int>
#define XX first
#define YY second

// constants:
const int mn = 200005;
const int mod = 1000000007;
const long long inf = 4444444444444444444;
const int sminf = 1111111111;
const bool is_multitest = 0;
const bool is_interactive = 0;

// i/o methods:
const bool input_from_file = 0;
const bool output_to_file = 0;
#define filename ""
#define in_extension "inp"
#define out_extension "out"

// data preprocessing: (e.g.: divisor generating, prime sieve)
void preprocess()
{
    
}

// global variables:
int x;
// main solution goes here:
void execute(int test_number)
{
    cin>>x;
    if (x < 600) cout<<8;
    else if (x<800) cout<<7;
    else if (x<1000) cout<<6;
    else if (x<1200) cout<<5;
    else if (x<1400) cout<<4;
    else if (x<1600) cout<<3;
    else if (x<1800) cout<<2;
    else cout<<1;
}
// REMEMBER TO CHOOSE TEST METHODS
// PLEASE REMOVE cout AND cerr DEBUG LINES BEFORE SUBMITTING PROBLEMS
// Solution by low_



















signed main()
{
#ifdef lowie
    if (!is_interactive)
    {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
#else
    if (input_from_file) freopen(filename"."in_extension, "r", stdin);
    if (output_to_file) freopen(filename"."out_extension, "w", stdout);
#endif
    if (!is_interactive)
    {
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }

    preprocess();
    int ntest;
    if (is_multitest) cin >> ntest;
    else ntest = 1;

    for (int testno = 1; testno <= ntest; testno++)
    // use for instead of while to serve facebook hacker cup test format
    {
        execute(testno); // only start coding in this function, not in main
    }
}
// Template by low_
// Contact me via mail: ttuandung1803@gmail.com
// ...or codeforces: www.codeforces.com/profiles/low_
// ...or if you're interested in food: www.instagram.com/lowie.exe/

Measured memory_bytes: 3648
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl

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

    auto f = [](int a){
        int tmp = a%10;
        int tmp2 = a;
        while(tmp2/10!=0){
            tmp2/=10;
        }

        pair<int, int> P;
        P = make_pair(tmp, tmp2);
        return P; 
    };

    map<pair<int, int>, int> mp;
    for(int i=1; i<=n; i++){
        pair<int, int> p = f(i);
        mp[p]++;
    }

    ll ans = 0;
    for(int i=1; i<=n; i++){
        pair<int, int> p = f(i);
        pair<int, int> q(p.second, p.first);
        ans += mp[q];
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
h = list(map(int, input().split()))
adj = [[] for i in range(n + 1)]
count = 0

def compare_height(adj, h, i):
    height = h[i - 1]
    if not adj[i]:
        return True
    for j in adj[i]:
        if h[j - 1] >= height:
            return False
    return True
#adj list
for i in range(m):
    a, b = map(int, input().split())
    adj[a].append(b)
    adj[b].append(a)
#compute number of peaks
for i in range(len(adj)):
    if i == 0:
        continue
    if compare_height(adj, h, i):
        count +=1
print(count)

Measured memory_bytes: 29312
#include <iostream>
#include <cstdio>

int main(){
	std::string name, ns[9];
	int am, pm, i=0, p[9] = {0}, pf[9] = {0};
	//input
	for(;i<9;i++){
		std::cin >> name >> am >> pm;
		ns[i] = name;
		p[i] = am + pm;
		pf[i] = am * 200 + pm * 300;
	}

	//output
	i = 0;
	for(;i<9;i++){
		std::cout << ns[i] << " " << p[i] << " " << pf[i] << std::endl;
	}
}

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

int d;
vector<int> c;
vector< vector<int> > s;

int satisfaction(const vector<int>& t) {
  vector<int> last(26, -1);
  int ans = 0;
  for (int i = 0; i < (int) t.size(); i++) {
    ans += s[i][t[i]];
    last[t[i]] = i;
    for (int j = 0; j < 26; j++) {
      ans -= c[j] * (i - last[j]);
    }
  }
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  srand(time(nullptr));
  cin >> d;
  c.resize(26);
  for (int i = 0; i < 26; i++) {
    cin >> c[i];
  }
  s.assign(d, vector<int>(26));
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }
  vector<int> t;
  for (int i = 0; i < d; i++) {
    vector<int> tmp = t;
    vector<int> best = {-1};
    for (int j = 0; j < 26; j++) {
      tmp.push_back(j);
      if (best[0] == -1 || satisfaction(tmp) > satisfaction(best)) {
        best = tmp;
      }
      tmp.pop_back();
    }
    swap(t, best);
  }
  for (int i = 0; i < 20000; i++) {
    int pos = rand() % d, x = rand() % 26;
    vector<int> tmp = t;
    tmp[pos] = x;
    if (satisfaction(tmp) > satisfaction(t)) {
      swap(t, tmp);
    } 
  }
  for (auto& x : t) {
    cout << x + 1 << '\n';
  }
  return 0;
}

Measured memory_bytes: 3788
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int[] a = new int[3];
    a[0] = sc.nextInt();
    a[1] = sc.nextInt();
    a[2] = sc.nextInt();
    Arrays.sort(a);
    int k = sc.nextInt();
    int ans = a[0] + a[1];
    for(int i = 0; i < k; i++) {
      a[2] *= 2;
    }
    ans += a[2];
    System.out.println(ans);
  }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pdd = pair<ld,ld>;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define endl '\n'
#define all(a) a.begin(),a.end()
#define sz(a) ((int)a.size())
#define F first
#define S second
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<(int)n;i++)
#define pb push_back
#define eb emplace_back
#define mp(a,b) make_pair(a,b)
#define cans cout<<ans<<endl
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
    out<<'('<<P.F<<','<<P.S<<')';
    return out;
}

//}}}
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}

const int maxn=1e5;

int dp[maxn];
int arr[maxn];

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

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

using namespace std;

using ll = long long;

bool was[26];
int main() {
#ifdef BZ
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    string s;
    cin >> s;
    for (char c : s) {
        was[c - 'a'] = true;
    }
    if (s.size() != 26) {
        int ptr = 0;
        while (was[ptr]) {
            ptr++;
        }
        cout << s << char(ptr + 'a') << endl;
    } else {
        for (int i = s.size() - 2; i >= 0; i--) {
            was[s[i + 1] - 'a'] = false;
            int ptr = s[i + 1] - 'a'  + 1;
            while (ptr < 26 && was[ptr]) {
                ptr++;
            }
            if (ptr != 26) {
                cout << s.substr(0, i + 1) << char(ptr + 'a') << endl;
                return 0;
            }
        }
        if (s[0] != 'z') {
            cout << char(s[0] + 1) << "\n";
            return 0;
        }
        cout << -1 << endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(v) (v).begin(),(v).end()
#define endl "\n"
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
#define vi vector<int>
#define pii pair<int,int>
#define mii map<int,int>
#define SET(A,VAL) memset(A, VAL, sizeof(A))
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
const int MAX = 1e6+8;
const int sz = 1e5+5;
void f_io(){
    IOS;
}

bool _prime(int n){
    for(int i=2;i*i<=n;i++) if(n%i == 0) return false;
    return true;
}

int32_t main(){
    f_io();
    int t = 1;
    //cin>>t;
    while(t--){
        int n;cin>>n;
        map<int,int> cnt;
        per(i,n,0){
            if(_prime(i)){
                cnt[i]++;
                continue;
            }
            rep(j,2,i){
                if(_prime(j) && i%j == 0){
                    int k = i;
                   while(k%j == 0) cnt[j]++, k /= j;
                }
            }
        }
        // cout<<-1,0;
        int ans = 1,m = 1e9+7;
        for(auto it : cnt){
            //trace2(it.ff,it.ss);
            if(it.ff == 1) continue;
            ans *= it.ss+1;
            ans %= m;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstring>

using namespace std;

int main(){
	int n;
	while(cin >> n, n){
		int I[256];
		for(int i=0;i<n;i++) cin >> I[i];
		double Hmin = -1;
		int mS, mA, mC;
		for(int S=0;S<16;S++){
			for(int A=0;A<16;A++){
				for(int C=0;C<16;C++){
					double tmpH = 0.0;
					int R = S;
					int O[256];
					memset(O, 0, sizeof(O));
					for(int i=0;i<n;i++){
						R = (A*R+C)%256;
						O[(I[i]+R)%256]++;
					}
					for(int i=0;i<256;i++){
						if(O[i]!=0){
							double d = (double)O[i]/n;
							tmpH -= d*log(d);
						}
					}
					if(Hmin<-0.5||tmpH+1e-8<Hmin){
						Hmin = tmpH;
						mS = S; mA = A; mC = C;
					}
				}
			}
		}
		cout << mS << " " << mA << " " << mC << endl;
	}
	return 0;
}

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

namespace AtCoder.BC081
{
    public class B
    {
        public static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var nums = new int[n];
            var count = 0;
            nums = Console.ReadLine().Split(" ").Select(n => int.Parse(n)).ToArray();

            while (nums.All(n => n % 2 == 0))
            {
                count++;
                nums = nums.Select(n => n / 2).ToArray();
            }
            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 28528
#include<bits/stdc++.h>
using namespace std;
int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
char in[12];
int main(){
  rd(in);
  in[3]++;
  wt_L(in);
  putchar_unlocked('\n');
  return 0;
}
// cLay varsion 20180107-1

// --- original code ---
// char in[12];
// {
//   rd(in);
//   in[3]++;
//   wt(in);
// }


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define eps 0.000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	int n;
	cin >> n;
	int maxe = 100000000;
	int mine = 0;
	REP(i, n) {
		int a;
		cin >> a;
		maxe = min(maxe, a);
		mine = max(mine, a);
	}
	cout << abs(mine - maxe) << endl;
	return 0;
}

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

void dfs ( int now, vector<vector<int>>& g, vector<bool>& flg, pair<int, int> p ) {
//    cout << now << endl;
    if ( flg[now] ) return;
    flg[now] = 1;
    for ( auto u : g[now] ) {
        if ( u == p.first && now == p.second || u == p.second && now == p.first ) continue;
        if ( flg[u] ) continue;
        dfs(u, g, flg, p);
    }
    return;
}

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    vector<pair<int, int>> pv(m);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
        pv[i] = make_pair(a, b);
    }
    int ans = 0;
    rep(i, m) {
        vector<bool> flg(n, 0);
        dfs(0, g, flg, pv[i]);
//        rep(j, n) {
//            cout << flg[j] << " ";
//        }
//        cout << endl;
        rep(j, n) {
            if ( !flg[j] ) {
//                cout << i << endl;
                ++ans;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const int INF = -100100100;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    vector<P> d(n);
    rep(i,n)cin >> d[i].second >> d[i].first;
    sort(d.begin(),d.end());
    int t = 0;
    bool ans = true;
    rep(i,n){        
        if(t+d[i].second<=d[i].first){
            t+=d[i].second;
        }else ans=false;
    }
    if(ans){
        cout<<"Yes" << endl;
        return 0;
    }else{
        cout <<"No" << endl;
        return 0;
    }
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main() {
    int N; cin >> N;
    vector<pair<int, int>> A(N);
    for (int i = 0; i < N; i++) {
        int p; cin >> p; A[i] = { p, i + 1 };
    }
    sort(begin(A), end(A));
    vector<int> L(N + 2), R(N + 2);
    for (int i = 0; i < N + 2; i++) {
        L[i] = max(i - 1, 0);
        R[i] = min(i + 1, N + 1);
    }
    long long ans = 0;
    for (auto &p : A) {
        int val, idx; tie(val, idx) = p;
        long long L1 = L[idx], L2 = L[L1];
        long long R1 = R[idx], R2 = R[R1];
        ans += ((L1 - L2) * (R1 - idx) + (idx - L1) * (R2 - R1)) * val;
        L[R1] = L1;
        R[L1] = R1;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 1792
//#pragma GCC target("avx2")
//#pragma GCC optimization("O3")
//#pragma GCC optimization("unroll-loops")
//assert(q==w) если q!=w --> runtime error
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define ub upper_bound
#define lb lower_bound
#define bit __builtin_popcount
#define memset(x) memset(x,0,sizeof(x))

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vector<int>> matrix;

inline void boost(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

const ll maxn=2e5+123;
const ll inf=1e9+123;
const ll linf=1e18+123;
const ll mod=1e9+7;
const double eps=1e-9;
const double pi=acos(-1);
int dx[8]={0,1,-1,0,1,-1,1,-1};
int dy[8]={1,0,0,-1,1,1,-1,-1};

int main(){
    boost();
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string s;
    cin>>s;
    int cntr=0;
    for(int i=0;i<s.size()/2;i++){
        if(s[i]!=s[s.size()-i-1]){
            cntr++;
        }
    }
    cout<<cntr;
	exit(0);
}


Measured memory_bytes: 256
n = gets.chomp.to_i

a = gets.chomp.split(" ").map(&:to_i)


result = Array.new(n)

mid = (n - 1) / 2
offset = 0

(0...n).each do |index|
  offset = (index + 1) / 2
  sym = (index % 2 == 1) ? 1 : -1
  result[mid + offset * sym] = a[index]
end

if n % 2 == 0
  puts result.reverse.join(" ")
else
  puts result.join(" ")
end


Measured memory_bytes: 28804
#include<iostream>
#include<limits>
// #include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<cmath>
#include<math.h>
#include<iomanip>  
#include<deque> 
#include<string> 
#include<string.h>
#include<map>
#include<unordered_map>
#include<utility>
#define ll long long
#define tc(t) long long t; cin >> t; while(t--)
#define V vector
#define Vp vector< pair<int,int> >
#define pb push_back
#define UM unordered_map
#define IT iterator
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define PQ priority_queue
#define _FI ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll MOD = 1e9+7;
const ll INF = INT_MAX;
const ll _INF= INT_MIN;
using namespace std;
bool flag=true;

vector<ll> SieveOfEratosthenes(int n) 
{ 
  vector<ll> result;
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        {  
            for (ll i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    for (ll p=2; p<=n; p++) 
       if (prime[p]) 
          result.push_back(p);
    return result;
}



int main()
{
 _FI
int a;
  cin>>a;
  
  ll ans= a+a*a+a*a*a;
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

const int INF = 1e9;

int n;
ll a, b;

vector<ll> v;

bool check(ll t){
    ll cnt = 0;
    rep(i, n){
        if(v[i] - b*t > 0){
            cnt += (v[i] - b*t) / (a-b);
            cnt += !!((v[i] - b*t) % (a-b));
        }
    }
    if(t >= cnt) return true;
    else return false;
}

int binary_search(){
    int ng = 0;
    int ok = INF;

    while(abs(ok - ng) > 1){
        int mid = (ok + ng) / 2;

        if(check(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main(){
    cin >> n >> a >> b;
    v.assign(n, 0);
    rep(i, n) cin >> v[i];
    int ans = binary_search();
    cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int count=0;
		while(cin.hasNext()){
			String str = cin.next();
			String re = "";
			for(int i = 0; i < str.length(); i++){
				re += str.charAt(str.length()-1-i);
			}
			if(re.equals(str)){
				count++;
			}
		}
		System.out.println(count);
	

	}

}

Measured memory_bytes: 11000
unittest
{
	assert( [ "3 2" ].parse.expand.solve == 9 );
	assert( [ "3 200" ].parse.expand.solve == 10813692 );
	assert( [ "100000 100000" ].parse.expand.solve == 742202979 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nk = input.front.split.to!( long[] );
	return tuple( nk[ 0 ], nk[ 1 ] );
}

auto solve( long n, long k )
{
	const M = 10L ^^ 9 + 7;
	
	// 最大公約数がdになるパターン数を計算
	auto ans = ModWorld!M( 0 );
	auto ps = new ModWorld!M[ k ];
	foreach_reverse( i, ref p; ps )
	{
		// 最大公約数がdになるには全要素がdの倍数であることが必要
		auto d = i + 1;
		p = ModWorld!M( k / d ) ^^ n;
		
		// 倍数パターンのうち、最大公約数がdの2倍以上になるものは除外
		for( auto j = i + d; j < k; j += d )
		{
			p -= ps[ j ];
		}
		ans += d * p;
	}
	return ans;
}

// モジュラ整数型（n mod M）
struct ModWorld( long M )
{
	long n;
	
	// 演算子オーバーロード
	void opUnary( string OP )() if( OP == "++" ){ this.n = ( this.n + 1 ) % M; }
	void opUnary( string OP )() if( OP == "--" ){ this.n = ( this.n + M - 1 ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "+"  ){ this.n = ( this.n + r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "-"  ){ this.n = ( this.n + M - r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "*"  ){ this.n = ( this.n * r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "/"  ){ this *= r ^^ ModWorld( M - 2 ); }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "^^" )
	{
		auto a = this.n;
		this.n = 1L;
		for( auto i = r.n; 0 < i; i >>= 1 )
		{
			if( i & 1 ) this.n = this.n * a % M;
			a = a ^^ 2 % M;
		}
	}
	auto opBinary( string OP )( ModWorld r )
	{
		auto t = this;
		t.opOpAssign!OP( r );
		return t;
	}
	
	// long型対応
	void opAssign( long r ){ this.n = r; }
	void opOpAssign( string OP )( long r ){ this.opOpAssign!OP( ModWorld( r ) ); }
	auto opBinary( string OP )( long r ){ return this.opBinary!OP( ModWorld( r ) ); }
	auto opBinaryRight( string OP )( long l ){ return ModWorld( l ).opBinary!OP( this ); }
	auto opEquals( long r ){ return this.n == r; }
	
	// format用出力
	string toString()
	{
		return this.n.to!string;
	}
}


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

using namespace std;
int n, v[10000];
int main()
{
	cin>>n;

	for(int i = 1; i <= n; i++) cin>>v[i];

	int ans = 2000000000;

	//sort(v + 1, v + n + 1);

	int sum = 0, tot = 0;

	for(int i = 1; i <= n; i++) tot += v[i];

	ans = tot;

	for(int i = 1; i <= n; i++)
	{
		sum += v[i];

		ans = min(ans, abs(tot - sum - sum));
	}

	cout<<ans<<"\n";
}

Measured memory_bytes: 256
import math
N = int(input())
goal = [0,0]
ans = 10**12
for i in range(1,int(math.sqrt(N))+1):
    if(N%i == 0):
        goal = [i,N//i]
        distance = goal[0]+goal[1]-2
        ans = min(ans,distance)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

void chmin(double &a, double b) { if (a > b) a = b; }



const int MAX = 100100;
const double INF = 1e10;
const double EPS = 1e-6;

int n, cn;
double p[MAX];
double cp[MAX];
int gap[MAX];

double dp[MAX];

int main() {
    while (cin >> n) {
        for (int i = 0; i < n; ++i) cin >> p[i];
        cn = 0;
        int next;
        for (int i = 0; i < n; i = next) {
            for (next = i+1; next < n; ++next)
                if ( abs(p[next] - 1.0) > EPS ) break;
            cp[cn] = p[i];
            gap[cn] = next-i-1;
            ++cn;
        }
            
        for (int i = 0; i < MAX; ++i) dp[i] = INF;
        dp[cn] = 0.0;
        for (int i = cn; i >= 0; --i) {
            double temp = 0.0;
            for (int j = i+1; j <= cn; ++j) {
                if (j - i >= 20) break;
                temp = (temp + 1.0) / cp[j-1] + gap[j-1];
                chmin(dp[i], dp[j] + temp + 1);
            }
        }
        
        printf("%.10f\n", dp[0] - 1);
    }
    
    return 0;
}


Measured memory_bytes: 3972
#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>

using namespace std;

long long N, M, H, W,re;
long long A[200001];
string S[100];
bool OK = true;
bool f;
vector <long long>vl;

int main() {
	cin >>H>>W;
	for (int i = 0; i < H; i++) {
		cin >> S[i];
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '#') {
				f = false;
			
				if (i > 0) {
					if (S[i - 1][j] == '#') {
						f = true;
					}
				}
				
				if (j > 0) {
					if (S[i][j - 1] == '#') {
						f = true;
					}
				}
				if ( j <W-1) {
					if (S[i][j + 1] == '#') {
						f = true;
					}
				}
				
				if (i <H-1) {
					if (S[i + 1][j] == '#') {
						f = true;
					}
				}
			


				if (f == false) {
					OK = false;
				}

			}


		}

	}


	if (OK) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  int w[n];
  int sum = 0;
  int max_w = 0;
  for (int i = 0; i < n; ++i) {
    cin >> w[i];
    sum += w[i];
    max_w = max(w[i], max_w);
  }
  int est = max(int(ceil(double(sum) / k)), max_w);
  while (true) {
    int nes_k = 1, cur_i = 0, cur_w = 0;
    while (true) {
      cur_w += w[cur_i];
      if (cur_w > est) {
        nes_k++;
        cur_w = 0;
        continue;
      }
      if (++cur_i == n) {
        break;
      }
    }
    if (nes_k <= k) {
      break;
    }
    est++;
  }
  cout << est << endl;
  return 0;
}



Measured memory_bytes: 3452
#include<stdio.h>
#include<math.h>
 
int main (void)
{
    int kazu;
    double x[100],y[100];
    int a;
    double A=0,B,C,D=0,E,F,G,H=0,I,sa[100];
     
 
    scanf("%d",&kazu);
 
    for(a=0;a<100;a++)
    {
        x[a]=0;
        y[a]=0;
        sa[a]=0;
    }
 
    for(a=0;a<kazu;a++)
    {
        scanf("%lf",&x[a]);
    }
    for(a=0;a<kazu;a++)
    {
        scanf("%lf",&y[a]);
    }
     
 
    for(a=0;a<kazu;a++)
    {
        B= x[a]-y[a];
        if(B<0)
        {
            B=-1*B;
        }
 
        A=A+B;
         
    }
 
    for(a=0;a<kazu;a++)
    {
        D=(x[a]-y[a])*(x[a]-y[a])+D;
        C=sqrt(D);
    }
 
    for(a=0;a<kazu;a++)
    {
		F=x[a] - y[a];
        if(F< 0)
        {
            F= -1*F;
        }
 
        G=pow(F,3);
		H=H+G;
    }
        E=pow(H,1.0/3.0);
 
 
      
 
      
    for(a=0;a<kazu;a++)
    {
        sa[a]=x[a]-y[a];
         
        if(sa[a]<0)
        {
            sa[a]=-1*sa[a];
        }
         
    }
         
    I = sa[0];
    for(a=0;a<kazu;a++)
    {
         
        if(I<sa[a])
        {
            I=sa[a];
        }
        else
        {
            I=I;
        }
     }
     
    printf("%f %f %f %f\n",A,C,E,I);
 
    return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define N 100005
#define inf 1e18
#define mem(a,b) memset(a,b,sizeof(a))
#define all(v) v.begin(),v.end()

using namespace std;

ll binomialCoeff(ll n,ll k)
{
    ll res = 1;
    if(k >n - k)
        k = n - k;
    for(int i = 0; i < k; ++i)
    {
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}

ll power(ll x,ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = power(x, y/2);
    if (y%2 == 0)
        return temp*temp;
    else
        return x*temp*temp;
}


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

void Sieve(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}

//***************************************************************************************************************************//

ll dp[3000000];

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
    int n;
    cin >> n;
    int arr[n][n];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
            cin >> arr[i][j];
    }
    ll mod = 1e9 + 7;
    mem(dp,0);
    dp[0]=1;
    for(int mask = 0;mask < (1<<n) - 1;mask++)
    {
        int a = __builtin_popcount(mask);
        for(int b = 0;b<n;b++)
        {
            if(arr[a][b] && !(mask & (1<<b)))
            {
                int m2 = mask ^ (1 << b);
                //cout << dp[m2] << "\n";
                dp[m2] += dp[mask];
                if(dp[m2] >= mod)
                    dp[m2] -= mod;
            }
        }
    }
    cout << dp[(1<<n)-1];
}


Measured memory_bytes: 23680
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in).useDelimiter("[^0-9]+");
		int c = 0;
		while (sc.hasNextInt()) {
			c += sc.nextInt();
		}
		System.out.println(c);
	}
}

Measured memory_bytes: 12000
# frozen_string_literal: true

X, K, D = gets.chomp.split.map(&:to_i)

count_moveing_to_near = X / D
nokori = K - count_moveing_to_near.abs
near_point = X - count_moveing_to_near * D

if nokori < 0
  if X >= 0
    puts (X - D * K).abs
  else
    puts (X + D * K).abs
  end
  exit
end

if X % D != 0

  if nokori == 0
    puts near_point.abs
  elsif nokori.odd? && near_point > 0
    puts (near_point - D).abs
  elsif nokori.odd? && near_point < 0
    puts (near_point + D).abs
  elsif nokori.even?
    puts near_point.abs
  end
else
  if nokori == 0
    puts near_point.abs
  elsif nokori.odd?
    puts D
  else
    puts 0
  end
end


Measured memory_bytes: 14408
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <tuple>

using namespace std;


int main(){
   long long n,m;
   cin>>n>>m;
   vector<long long> a(n),b(m),c(m);
   for(int i=0;i<n;i++)cin>>a[i];
   sort(a.begin(),a.end());

   vector<pair<long long,long long>> bc(m); 
   for(int i=0;i<m;i++){
       cin>>b[i]>>c[i];
       bc[i]=make_pair(c[i],b[i]);
   }
   sort(bc.begin(),bc.end());
   reverse(bc.begin(),bc.end());
   long long p=0;
   long long q=bc[p].second;
   for(int i=0;i<n;i++){
       if(q<=0){
           p++;
           q=bc[p].second;
       }
       if(a[i]<=bc[p].first){
           a[i]=bc[p].first;
           q--;
       }
       else break;
   }
   long long ans=0;
   for(int i=0;i<n;i++){
       ans+=a[i];
   }
   cout<<ans<<endl;


   
}

   


Measured memory_bytes: 4224
#include <stdio.h>
#include <stdlib.h>
#define N 1000000

// if (h2,w2) is bigger than (h1, w1) then return positive num;
int big(int h1,int w1,int h2,int w2){
  int d1, d2;
  d1 = h1*h1 + w1*w1;
  d2 = h2*h2 + w2*w2;
  if(d1==d2){
    return h2-h1;
  }
  return d2-d1;
}

int main(void){
  int n,i,j,d1,d2,mind,minw,minh;
  int h,w;
  while(1){
    scanf("%d %d",&h, &w);
    if(h==0 && w==0)break;
    d1 = h*h + w*w;
    minh=minw = 10000;
    for(i = 1 ; i <= 150 ; i++){
      for(j = i+1 ; j <= 150 ; j++){
	if(big(h,w,i,j) > 0){
	  if(big(i,j,minh,minw) > 0){
	    minh = i;
	    minw = j;
	  }
	}
      }
    }

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

Measured memory_bytes: 600
import math
a,b,h,m=map(int,input().split())
rad=abs(math.radians(30*(h+m/60)-6*m))
# if(rad>180):
#     rad=2*math.pi()-rad
ans=a**2+b**2-2*a*b*math.cos(rad)
print(math.sqrt(ans))

Measured memory_bytes: 9556
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
double dis(double ax,double ay,double bx,double by){
    return sqrt(abs(ax-bx)*abs(ax-bx)+abs(ay-by)*abs(ay-by));
}
int n,x[50],y[50];
int solve(double X){
    rep(i,n)for(int j=i+1;j<n;j++){
        double a=x[i],b=y[i],c=x[j],d=y[j];
        double mx=(a+c)/2,my=(b+d)/2,s=dis(a,b,mx,my);
        if(X<s) continue;
        double t=sqrt(X*X-s*s),dx=(d-b)/dis(a,b,c,d),dy=(a-c)/dis(a,b,c,d);
        double Ax=mx+dx*t,Ay=my+dy*t,Bx=mx-dx*t,By=my-dy*t;
        int Z=1;
        rep(k,n) if(k!=i&&k!=j&&dis(Ax,Ay,x[k],y[k])>X) Z=0;
        if(Z) return 1;
        Z=1;
        rep(k,n) if(k!=i&&k!=j&&dis(Bx,By,x[k],y[k])>X) Z=0;
        if(Z) return 1;
    }
    return 0;
}
double ok=1000,ng=0;
double search(){
    while(abs(ok-ng)>0.00000001){
        double mid=(ok+ng)/2;
        if(solve(mid)) ok=mid;
        else ng=mid;
    }
}
int main(){
    cin>>n;
    rep(i,n) cin>>x[i]>>y[i];
    search();
    cout<<setprecision(10)<<ok<<"\n";
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, K: int):
    if abs(N-K) > N:
        print(N)
    else:
        diff = max(N, K) - min(N, K)
        k = diff//min(N, K)
        MAX = max(N, K)-k*min(N, K)
        MIN = min(N, K)
        a1 = MAX
        a2 = abs(MAX-MIN)
        a3 = abs(a2 - MIN)
        print(min(a1, a2, a3))


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Text;

class TEST{
	static void Main(){
		
		SortedList<String,List<int>> mySL=new SortedList<String,List<int>>();
		while(true){
			var s=Console.ReadLine();
			if(s==null)break;
			var aa=s.Split(' ');
			if(mySL.ContainsKey(aa[0])==false){
				mySL.Add(aa[0],new List<int>());
			}
			mySL[aa[0]].Add(int.Parse(aa[1]));
		}
		foreach(String s in mySL.Keys){
			Console.WriteLine(s);
			mySL[s].Sort();
			//int[] t=new int[mySL[s].Count];
			//for(int i=0;i<mySL[s].Count;i++)t[i]=mySL[s][i];
			//t.Sort();
			//mySL[s]=t;
			for(int i=0;i<mySL[s].Count;i++){
				if(i!=mySL[s].Count-1)Console.Write("{0} ",mySL[s][i]);
				if(i==mySL[s].Count-1)Console.WriteLine("{0}",mySL[s][i]);
			}
			//for(int i=0;i<t.Length;i++){
			//	if(i!=t.Length-1)Console.Write("{0} ",t[i]);
			//	if(i==t.Length-1)Console.WriteLine("{0}",t[i]);
			//}
		}
	}
}

Measured memory_bytes: 7016
n,m,x = gets.split.map(&:to_i)
price = []
list = []
for i in 0..n-1 do
  a = gets.split.map(&:to_i)
  price.push(a[0])
  b = []
  for j in 1..m do
    b.push(a[j])
  end
  list.push(b)
end
min_price = 10**7
for i in 1..2**n-1 do
  temp_price = 0
  understand = Array.new(m,0)
  for j in 0..n-1 do
    if (i>>j)&1==1 then
      temp_price += price[j]
      for k in 0..m-1 do
        understand[k] += list[j][k]
      end
    end
  end
  flag = true
  for j in 0..m-1 do
    if understand[j]<x then
      flag = false
      break
    end
  end
  if flag&&min_price>temp_price then
    min_price = temp_price
  end
end
if min_price==10**7 then
  puts(-1)
else
  puts(min_price)
end


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

#define ll long long
#define inf 1e18


int main()
{
  ll n,k;
  cin>>n>>k;
  ll a[n+1];
  ll c[n+1];
  for(ll i=1;i<=n;i++)
      cin>>a[i];
  for(ll i=1;i<=n;i++)
      cin>>c[i];

  ll ans=-inf;
  for(ll i=1;i<=n;i++)
  {
    vector<ll>v;
    v.push_back(0);
    ll sum=c[i];
    ll j=a[i];
    ll len=1;    
    while(j!=i)
    {
      
      sum+=c[j];
      j=a[j];
      len++; 
    }
    ll path = 0;
    ll cnt = 0;
    ll now=i;
    while (true)
    {
      cnt++;
      path += c[now];
      if (cnt > k)break;
      ll score = path + max((ll)0, sum)*((k - cnt) / len);
      ans = max(ans, score);
      now = a[now];
      if (now == i)break;
    }
    
  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 3684
char buf[10000000],out[11];
sz;
cnt[60];
main()
{
	read(0,buf,10000000);
	int N=0;
	for(;;)
	{
		char k=buf[sz++];
		if(k<'0')break;
		N=N*10+k-'0';
	}
	for(;buf[sz]>='0';)
	{
		long A=0;
		for(;;)
		{
			char k=buf[sz++];
			if(k<'0')break;
			A=A*10+k-'0';
		}
		for(int i=0;i<60;i++)
		{
			cnt[i]+=A&1;
			A>>=1;
		}
	}
	long ans=0;
	for(int i=59;i>=0;i--)
	{
		ans=ans*2+(long)(N-cnt[i])*cnt[i];
		if(ans>3000000000000000000)ans%=1000000007;
	}
	ans%=1000000007;
	int outsz=10;
	do{
		out[--outsz]=ans%10+'0';
	}while(ans/=10);
	write(1,out+outsz,10-outsz);
}


Measured memory_bytes: 6272
#include <iostream>
#include <vector>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;

int main(){
    int h,w;	cin >> h >> w;
    vector<vector<char> >c(h, vector<char>(w));
    rep(i, h)	rep(j, w)   cin >> c[i][j];
    rep(i, h){
	rep(j, 2){
	    rep(k, w)	printf("%c", c[i][k]);
	    printf("\n");
	}
    }
}


Measured memory_bytes: 256
n=int(input())
H=list(map(int,input().split()))
ans=0
i=0
while sum(H)>0:
  ans+=1
  flag=False
  for i in range(n):
    if H[i]>0:
      H[i]-=1
      flag=True
    elif flag is True and H[i]==0:
      break
  # print(H)
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		vector<UL> V;
		{
			string S; cin >> S;
			rep(i, S.size()) V.push_back(S[i] - '0');
			reverse(V.begin(), V.end());
		}
		UL ans0 = 0, ans1 = 9;
		rep(i, V.size()) {
			UL p = V[i];
			UL buf0 = min(ans0 + p, ans1 + p + 1);
			UL buf1 = min(ans0 + 9 - p + 1, ans1 + 9 - p);
			ans0 = buf0; ans1 = buf1;
		}
		cout << min(ans0, ans1 + 1) << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 7548
import heapq
N = int(input())
a_ls = [int(i) for i in input().split()]
before = []
_sum_before = 0
before_scores = []
after = []
_sum_after = 0
after_scores = []
best = None
for i in range(2*N):
    _sum_before += a_ls[i]
    heapq.heappush(before, a_ls[i])
    _sum_after += a_ls[-i-1]
    heapq.heappush(after, -a_ls[-i-1])
    if i >= N:
        _sum_before -= heapq.heappop(before)
        _sum_after -= -heapq.heappop(after)
    if i >= N - 1:
        before_scores.append(_sum_before)
        after_scores.append(_sum_after)
after_scores = after_scores[::-1]
for i in range(N+1):
    score = before_scores[i] - after_scores[i]
    if best is None:
        best = score
    best = score if best < score else best
print(best)

Measured memory_bytes: 38288
loop do
    n, m = gets.split.map(&:to_i)
    break if n == 0 && m == 0
    h = n.times.map{gets.to_i}
    w = m.times.map{gets.to_i}
    hs = Hash.new(0)
    ws = Hash.new(0)
    n.times do |i|
        height = h[i]
        hs[height] += 1
        (i+1).upto(n-1) do |j|
            height += h[j]
            hs[height] += 1
        end
    end
    m.times do |i|
        width = w[i]
        ws[width] += 1
        (i+1).upto(m-1) do |j|
            width += w[j]
            ws[width] += 1
        end
    end
    ans = 0
    hs.each do |k,v|
        ans += v * ws[k]
    end
    puts ans
end

Measured memory_bytes: 51200
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp {
  char name[100];
  int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue() {
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

int min(int a, int b) { return a < b ? a : b; }

int main() {
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for(i = 1; i <= n; i++) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  head = 1; tail = n + 1;

  while(head != tail) {
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if (u.t > 0) enqueue(u);
    else {
      printf("%s %d\n", u.name, elaps);
    }
  }

  return 0;
}


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

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  
  vector<vector<int>> paint(N, vector<int>(3));
  for (int i = 0; i < N; i++) {
    cin >> paint.at(i).at(0) >> paint.at(i).at(1) >> paint.at(i).at(2);
  }
  
  int x_max = 0;
  int x_min = W;
  int y_max = 0;
  int y_min = H;
  for (int i = 0; i < N; i++) {
    if (paint.at(i).at(2) == 1) {
      if (x_max < paint.at(i).at(0)) x_max = paint.at(i).at(0);
    }
    else if (paint.at(i).at(2) == 2) {
      if (x_min > paint.at(i).at(0)) x_min = paint.at(i).at(0);
    }
    else if (paint.at(i).at(2) == 3) {
      if (y_max < paint.at(i).at(1)) y_max = paint.at(i).at(1);
    }
    else if (paint.at(i).at(2) == 4) {
      if (y_min > paint.at(i).at(1)) y_min = paint.at(i).at(1);
    }
  }
  
  if (x_min - x_max > 0 && y_min - y_max > 0) {
    cout << (x_min - x_max) * (y_min - y_max) << endl;
  }
  else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]

#[macro_use]
mod _input {
    use std::fmt;
    use std::io::{self, Read};
    use std::str::{self, FromStr};

    macro_rules! input {
        ($($name:ident : $t:tt),*,) => {
            input!($($name: $t),*)
        };
        ($($name:ident : $t:tt),*) => {
            let mut _scanned = ::_input::Scanned::new(::std::io::stdin(), 1024);
            $(
                let $name = unsafe { _read_value!(_scanned, $t) };
            )*
        };
    }

    macro_rules! _read_value {
        ($scanned:expr, ($($t:tt),*)) => {
            ($(_read_value!($scanned, $t)),*)
        };
        ($scanned:expr, [$t:tt; $n:expr]) => {
            (0..$n).map(|_| _read_value!($scanned, $t)).collect::<Vec<_>>()
        };
        ($scanned:expr, _bytes) => {
            _read_value!($scanned, String).into_bytes()
        };
        ($scanned:expr, _1based) => {
            _read_value!($scanned, usize) - 1
        };
        ($scanned:expr, $t:ty) => {
            $scanned.next::<$t>()
        };
    }

    pub struct Scanned {
        buf: Vec<u8>,
        pos: usize,
    }

    impl Scanned {
        pub fn new<R: Read>(mut input: R, estimated: usize) -> Self {
            let mut buf_ = Vec::with_capacity(estimated);
            let _ = io::copy(&mut input, &mut buf_).unwrap();
            debug_assert!(str::from_utf8(&buf_).is_ok());
            debug_assert!(buf_.iter().all(|&c| u32::from(c) <= 0x7F));
            Scanned { buf: buf_, pos: 0 }
        }

        #[inline]
        pub unsafe fn next<T: FromStr>(&mut self) -> T
        where
            T::Err: fmt::Debug,
        {
            let mut start = None;
            loop {
                match (self.buf[self.pos], start.is_some()) {
                    (b' ', true) | (b'\n', true) => break,
                    (_, true) | (b' ', false) | (b'\n', false) => self.pos += 1,
                    (_, false) => start = Some(self.pos),
                }
            }
            let target = &self.buf[start.unwrap()..self.pos];
            str::from_utf8_unchecked(target).parse().unwrap()
        }
    }
}

use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::{self, BufWriter, Read, Stderr, StderrLock, Stdout, StdoutLock, Write};
use std::num::{ParseFloatError, ParseIntError};
use std::ops::{
    Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
    Mul, MulAssign, Neg, Not, Rem, RemAssign, Sub, SubAssign,
};
use std::str::{self, FromStr};
use std::{char, cmp, f32, f64, fmt, i16, i32, i64, i8, mem, thread, u16, u32, u64, u8};

fn main() {
    input! {
        a: u32,
        b: u32,
        k: _1based,
    }
    let r = (1..101)
        .rev()
        .filter(|&n| a % n == 0 && b % n == 0 && a >= n && b >= n)
        .nth(k)
        .unwrap();
    println!("{}", r);
}


Measured memory_bytes: 4352
module Main where

  import           Control.Monad
  import           Data.List
  import           Data.Int
  import           Data.Ord
  import           Data.List.Split
  import           Data.Array.IO
  import qualified Data.Vector.Unboxed as V

  main :: IO ()
  main = do
    n <- readLn :: IO Int64
    as <- replicateM 5 readLn :: IO [Int64]
    let m = minimum as :: Int64
        (d,md) = n `divMod` m
        a = 5 + (d - 1) + (if md == 0 then 0 else 1) :: Int64
    print a


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

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

int main() {
    int H, W;
    cin >> H >> W;

    vector<string> Graph(H);
    rep(i,H) cin >> Graph.at(i);

    vector<vector<int>> dist(H, vector<int>(W, -1)); // -1: 未訪問
    dist[0][0] = 0;

    int ans = -1;
    int wall = 0;
    rep(i,H) rep(j,W) if (Graph.at(i).at(j) == '#') ++wall;


    vector<string> G = Graph;
    vector<vector<int>> reached = dist;
    queue<P> que;

    que.push(make_pair(0, 0));
    dist[0][0] = 0;

    while (!que.empty()) {
        P p = que.front();
        que.pop();
        for (int direction = 0; direction < 4; ++direction) {
            int nh = p.first + dx[direction];
            int nw = p.second + dy[direction];
            if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
            if (dist.at(nh).at(nw) > -1) continue;
            if (Graph.at(nh).at(nw) == '#') continue;
            dist.at(nh).at(nw) = dist.at(p.first).at(p.second) + 1;
            if (nh == H - 1 && nw == W - 1) {
                ans = dist.at(nh).at(nw);
                break;
            }
            que.push(make_pair(nh, nw));
        }
    }
    if (ans == -1) cout << ans << endl;
    else 
    cout << H * W - wall - (ans + 1) << endl;
}

Measured memory_bytes: 3628
fun main(args:Array<String>?): Unit {
    val leftHand = "qwertasdfgzxcvb"
    val isLeft = ('a' .. 'z').map{ it in leftHand }.toBooleanArray()
    while(true){
        val s = readLine()!!.trim()
        if (s == "#") return
        println((1 until s.length).count{i -> isLeft[s[i].toIndex] != isLeft[s[i - 1].toIndex]})
    }
}
val Char.toIndex
    get() = this - 'a'


Measured memory_bytes: 29516
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N;
  cin >> N;
  int ans = 0;
  repp(i, 1, N) {
    ans += i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())

ans = 1
k = 1
while(k * k <= M):
    if(0 == M % k):
        if(M >= N * k):
            ans = max(ans, k)
        k_ = M // k
        if(M >= N * k_):
            ans = max(ans, k_)
    k += 1

print(str(ans))


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

int main() {
  string S;
  cin >> S;
  int ans = 1e9;
  for (int i = 0; i + 2 < S.size(); i++) {
    ans = min(ans, abs(753 - stoi(S.substr(i, 3))));
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

int main() {
  /**
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
  **/
	FIO
	int n; cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) cin >> a[i];
	int ans = 0, k = 1;
    for (int i = 0; i < n; i++) {
    	if (a[i] == k) k++;
    	else ans++;
    }
    if (ans == n) cout << -1 << "\n";
    else cout << ans << "\n"; 
    return 0;
}

Measured memory_bytes: 4432
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val l = readLine()!!.split(' ').map(String::toLong)
    var vctr = 0
    var count = 1

    for (i in 0 until n - 1) {
        if (vctr == 0) {
            if (l[i] < l[i + 1]) {
                vctr = 1
            } else if (l[i] > l[i + 1]) {
                vctr = -1
            }
        } else if (vctr == 1) {
            if (l[i] > l[i + 1]) {
                vctr = 0
                count++
            }
        } else {
            if (l[i] < l[i + 1]) {
                vctr = 0
                count++
            }
        }
    }
    println(count)
}

Measured memory_bytes: 53804