akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h" 
using namespace std;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rerep(i,a,n) for(ll i=n;i>=a;i--)
#define elif else if
#define all(s) s.begin(),s.end()
typedef long long ll;
int gcd(int a,int b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    else return gcd(b,a%b);
}
int main(){
    ll ans=0;
    ll k;
    cin>>k;
    rep(a,1,k+1){
        rep(b,1,k+1){
            rep(c,1,k+1){
                ans+=gcd(a,gcd(b,c));
            }
        }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 3632
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9 + 7;
const int N = 20335;
const int K = 700 ;
int binpow(int x, int y){
    int res = 1;
    while(y){
        if (y % 2) res = res * x % mod;
        x = x * x % mod;
        y /= 2;
    }
    return res;
}
int solve(int h, int w){
    int g = __gcd(h, w);
    return (binpow(2, h) + binpow(2, w) - 1 + binpow(2, g) - 2 + mod) % mod;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int h, w, t;
    cin >> h >> w >> t;
    int H = __gcd(h, t);
    int W = __gcd(w, t);
    int ans = binpow(solve(h / H, w / W), H * W);
    cout << ans;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

bool used[26];    


int main(){
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        used[s[i]-'a'] = true;
    }
    int cnt = 0;
    for(int i = 0; i < 26; i++){
        if(used[i]) cnt++;
    }
    if(cnt == 2){
        cout << "Second" << endl;
    }else{
        if(s[0] == s[s.size()-1]){
            if(s.size()%2== 0){
                cout << "First" << endl;
            }else{
                cout << "Second" << endl;
            }
        }else{
            if(s.size()%2== 0){
                cout << "Second" << endl;
            }else{
                cout << "First" << endl;
            }
        }
    }
}

Measured memory_bytes: 888
fn main() {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  let mut s1: Vec<char> = buf.trim().chars().collect();

  if (s1[0] == s1[2] && s1[1] == s1[2]) || (s1[1] == s1[3] && s1[1] == s1[2]) {println!("Yes");} else {println!("No");}
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  ll N;
  cin >> N;

  // N-1の約数の個数
  ll cnt1 = 1;
  ll num = N-1;
  for(ll i = 2; i * i <= N-1; i++){
    if(num%i==0){
      
      ll cnt = 0;
      while(num % i == 0){
        num /= i;
        cnt++;
      }
      cnt1 = cnt1 * (cnt+1);
    }
  }
  if(num > 1){
    cnt1 = cnt1*2;
  }

  ll cnt2 = 0;
  for(ll i = 2; i * i <= N; i++){
    ll num = N;

    if(N % i == 0){
      while(num % i == 0){
        num /= i;
      }

      if(num % i == 1){
        // cout << i << endl;
        cnt2++;
      }
    }
  }

  cout << cnt1 + cnt2 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  long long num, max, a, b=0;
  cin >> num >> max;
  vector<long long> list2;
  for (long long i=0; i<num; i++) {cin >> a; list2.push_back(a);}
  sort(list2.begin(),list2.end());
  reverse(list2.begin(),list2.end());
  for (long long i=0; i<max; i++) {b+=list2[i];}
  cout << b;}

Measured memory_bytes: 3612
s = list(input())
a = ['A', 'C', 'G', 'T']
ans = 0

for i in range(len(s)):
    for j in range(i + 1, len(s) + 1):
        f = True
        for ss in s[i:j]:
            if ss not in a:
                f = False

        if f:
            ans = max(ans, len(s[i:j]))

print(ans)

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

using namespace std;

int a[22],b[22],c[22];
int n;

int main()
{
	cin >> n;
	int ans=0;
	for(int i=1;i<=n;i++) cin >> a[i];
	for(int i=1;i<=n;i++) cin >> b[i];
	for(int i=1;i<=n-1;i++) cin >> c[i];
	for(int i=1;i<=n;i++)
	{
		ans+=b[a[i]];
		if(i>1&&a[i]==a[i-1]+1)
			ans+=c[a[i]-1];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

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

  cout << (n%500 <= a ? "Yes" : "No") << endl;

  return 0;
}


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

using namespace std;

int gcd(int x, int y)
{
	return y == 0 ? x : gcd(y, x % y);
}

int main()
{
	int x, y;
	scanf("%d %d", &x, &y);
	
	printf("%d\n", gcd(x, y));
	
	return 0;
}


Measured memory_bytes: 3216
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

bool is_pop(int s, int n) {
	return static_cast<bool>(s & (1 << n));
}

int count(VI2D& c, int row, int column) {
	int h = c.size();
	int w = c[0].size();
	int ret = 0;
	REP(i, h) {
		REP(j, w) {
			if(c[i][j] == 1 && (!is_pop(row, i) && !is_pop(column, j))) {
				ret++;
			}
		}
	}
	return ret;
}

int main() {
	int h, w, k;
	cin >> h >> w >> k;
	VI2D c(h, VI(w));
	REP(i, h) {
		string line;
		cin >> line;
		REP(j, w) { c[i][j] = line[j] == '.' ? 0 : 1; }
	}

	int result = 0;
	REP(row, (1 << h)) {
		REP(column, (1 << w)) {
			if(count(c, row, column) == k) {
				result++;
			}
		}
	}
	cout << result << endl;
	return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using llong = long long;
using P = pair<int, int>;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   string s;
   cin >> s;
   rep(i, s.size()) { s[i] = 'x'; }
   cout << s << endl;
   return 0;
}

Measured memory_bytes: 256
n=int(input())
edge=[[] for _ in range(n+1)]
for i in range(n):
  v,k,*u=list(map(int,input().split()))
  edge[v]=u
d=[0]*(n+1)
f=[0]*(n+1)
def dfs(now,t):
  d[now]=t
  vis.append(now)
  for i in edge[now]:
    if i not in vis:
      t=dfs(i,t+1)
  f[now]=t+1
  return t+1
vis=[]
t=1
for i in range(1,n+1):
  if i not in vis:
    t=dfs(i,t)+1
for i in range(1,n+1):
  print(i,d[i],f[i])


Measured memory_bytes: 5716
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    C = [list(map(int, input().split())) for _ in range(3)]

    a = [f_inf] * 3
    b = [f_inf] * 3
    a[0] = 0
    for j in range(3):
        b[j] = C[0][j] - a[0]

    for i in range(3):
        a[i] = C[i][0] - b[0]

    for i in range(3):
        for j in range(3):
            if C[i][j] != a[i] + b[j]:
                print("No")
                exit()

    print("Yes")


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3064
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());

		HashSet<Integer> aSet = new HashSet<>();
		HashSet<Integer> bSet = new HashSet<>();

		for (int i=0; i<m; i++){
			int a = Integer.parseInt(sc.next());
			int b = Integer.parseInt(sc.next());
			if ( a == 1){
				bSet.add(b);
			}
			if ( b == n){
				aSet.add(a);
			}
		}
		aSet.retainAll(bSet);

		if (aSet.size() == 0){
			System.out.println("IMPOSSIBLE");
		}else {
			System.out.println("POSSIBLE");
		}
	}
}


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

int main(void){
    int a, b;
    int s = 0;
    int i = 1;
    cin >> a >> b;
    
    while(i <= 2){
    if(a >= b){
        s += a;
        a -= 1;
    }
    else{
        s += b;
        b -= 1;
    }
    i++;
    }
    cout << s << endl;

return 0;
}

Measured memory_bytes: 256
module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let rec solve x (acc, m) =
  IntMap.fold (fun a n (acc, m) ->
    if x - a < a then (acc, m)
    else if x - a = a then
      (acc + n / 2, IntMap.add a (n mod 2) m)
    else
      match IntMap.find (x - a) m with
      | exception Not_found -> (acc, m)
      | n' -> (acc + min n n', IntMap.add a (n - min n n') (IntMap.add (x - a) (n' - min n n') m))) m (acc, m)

let () = Scanf.scanf "%d\n" @@ fun n ->
  Printf.printf "%d\n" @@ fst @@
  Array.fold_right solve (Array.init 31 (( lsl ) 1))
  (0,
    Array.fold_left (fun m a -> IntMap.add a (1 + try IntMap.find a m with Not_found -> 0) m) IntMap.empty @@
    Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a)


Measured memory_bytes: 23424
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

int main() {
	int n; std::cin >> n;
	std::vector<int> nums(n); for (auto& num : nums) std::cin >> num;
	std::vector<int> colors(n, -1);
	for (const auto& num : nums) {
		*(std::lower_bound(colors.begin(), colors.end(), num) - 1) = num;
	}
	auto i = 0;
	for (; i < n && colors[i] == -1; ++i) {}
	std::cout << n - i << std::endl;
}

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

int main(){
    int h,w;
    
    while(1){
        cin >> h >> w;
        
        if (h == 0 && w == 0) { break; }
        
        for (int i = 0; i < h; i++){
            for (int j=0; j < w; j++){
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main(void) {
  int i,j;
  int n;
  cin>>n;
  if(n<1200)
    cout<<"ABC"<<endl;
  else
    cout<<"ARC"<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;
int main(){
    int n,d;
    cin >> n>>d;
    if(n%(2*d+1)==0){
        cout<<(n/(2*d+1))<<endl;
    }else{
        cout<<(n/(2*d+1))+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import math
a,b,c=map(int,input().split())
sinc=math.sin(math.radians(c))
cosc=math.cos(math.radians(c))
s=1/2*a*b*sinc
l=math.sqrt(a**2+b**2-2*a*b*cosc)+a+b
h=s*2/a
print(s)
print(l)
print(h)


Measured memory_bytes: 5704
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
#include<set>

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
 
#define sPRINT(str) printf(#str "\n")
#define yOUT sPRINT(Yes)
#define nOUT sPRINT(No)
#define YOUT sPRINT(YES)
#define NOUT sPRINT(NO)
 
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
 
using namespace std;

int main(void)
{   
    long long n, inp, cnt1=0, cnt2=0;
    cin >> n;
    REP(i, n){
        cin >> inp;
        if(inp % 4 == 0){
            cnt1++;
        }
        else if(inp % 2 == 0){
            cnt2++;
        }
    }


    if(n/2 <= cnt1 + cnt2 / 2){
        yOUT;
    }
    else{
        nOUT;
    }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

typedef tuple<int, int, int> T;

int main(){
    int N, Q; cin >> N >> Q;
    vector<T> a(N);
    vector<int> ans(Q, -1);

    for(int i=0; i<N; i++){
        int s,t,x; cin >> s >> t >> x;
        s -= x;
        t -= x;
        a[i] = make_tuple(x, s, t);
    }
    sort(a.begin(), a.end());

    set<pair<int, int>> s;
    for(int i=0; i<Q; i++){
        int d; cin >> d;
        s.insert(make_pair(d, i));
    }

    for(int i=0; i<N; i++){
        int x, l, r;
        tie(x, l, r) = a[i];
        auto itr = s.lower_bound(make_pair(l, -1));
        while(itr != s.end()){
            if(itr->first >= r) break;
            ans[itr->second] = x;
            s.erase(itr++);
        }
    }

    for(auto e:ans) cout << e << endl;
}

Measured memory_bytes: 14336
def getN():
    return int(input())

def getMN():
    a = input().split()
    b = [int(i) for i in a]
    return b[0],b[1]

def getlist():
    a = input().split()
    b = [int(i) for i in a]
    return b


h,w = getMN()
pos = ["."]*(w*h+5000)
cur = 1

class unionfind():
    def __init__(self,n):
        self.par = [i for i in range(n+1)]
        self.rank = [0]*(n+1)
        self.childnum = [1] * (n + 1)
        self.childb = [0 if pos[i] == "." else 1 for i in range(n+1)]

    def find(self,x):
        if self.par[x] == x:
            return x
        else:
            #print(x, ":", self.par[x])
            self.par[x] = self.find(self.par[x])
            return self.find(self.par[x])

    def union(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.childnum[y] += self.childnum[x]
            self.childb[y] += self.childb[x]

        else:
            self.par[y] = x
            self.childnum[x] += self.childnum[y]
            self.childb[x] += self.childb[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
    def same_check(self,x,y):
        return self.find(x) == self.find(y)


for i in range(h):
    posin = input()
    for j in range(w):
        if posin[j] == "#":
            pos[j+(i)*w] = "#"

uf = unionfind(h*w+1)

unionlog = []

for i in range(h):
    for j in range(w):
        nn = j+(i)*w
        now = pos[nn]

        if j != w-1:
            nr = j + (i) * w + 1
            right = pos[nr]
            if right != now:
                if not uf.same_check(nn,nr):
                    uf.union(nn,nr)
                    unionlog.append("union:{},{}".format(nn,nr))
        if i != h-1:
            nd = j + (i + 1) * w
            down = pos[nd]
            if down != now:
                if not uf.same_check(nn,nd):
                    uf.union(nn,nd)
                    unionlog.append("union:{},{}".format(nn,nd))


a = 0
#print("\n".join(unionlog))

#print("s",uf.childnum)
#print(uf.childb)
#print([uf.find(i) for i in range(9)])
ans = 0

for parnum in list(set([uf.find(i) for i in range(h*w)])):
    #print(parnum)
    b = uf.childb[parnum]
    w = uf.childnum[parnum] - b
    #print(b,w)
    ans +=  b*w

print(ans)

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

int main(){
  int A,B;
  char op;
  cin >> A >> op >> B;
  
  if (op == '+'){
    cout << A + B << endl;
  }
  
  else if (op == '-'){
    cout << A - B << endl;
  }
  
 
}
  

Measured memory_bytes: 256
#abc088 c
a=[]
for i in range(3):
    line=list(map(int,input().split()))
    a.append(line)
r=[]
g=[]
for i in range(3):
    x=a[0][i]
    r.append(x)
    y=a[i][0]-a[0][0]
    g.append(y)
g[0]=0
flag=True
for i in range(3):
    for j in range(3):
        if a[i][j]!=(g[i]+r[j]):
            flag=False
            break
if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#if 0
????????£????????????20m
que
#endif

#include <queue>
#include <string>
#include <iostream>
using namespace std;

int main(){
	int n,q;
	queue<string>name;
	string a;
	queue<int>time;
	int b;
	queue<string>result_name;
	queue<int>result_time;
	int count=0; //????????????
	cin >> n >> q;
	for(int i=0; i<n; ++i){
		cin >> a >> b;
		name.push(a);
		time.push(b);
	}
	while(! name.empty()){ //name???????´??????????????????????
		if(time.front()<=q){ //1?????????????????????????????´???
			count+=time.front();
			result_name.push(name.front());
			result_time.push(count);
			name.pop();
			time.pop();
		}else{ //???????????????
			count+=q;
			name.push(name.front()); //???????°??????????
			time.push(time.front()-q); //??¢????????????????????????????????????????°?
			name.pop();
			time.pop();
		}
	}
	for(int i=0; i<n; i++){  //??¨?????¨???
		cout << result_name.front() << " "<< result_time.front() <<endl;
		result_name.pop();
		result_time.pop();
	}
}

Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    if(t%10==2||t%10==4||t%10==5||t%10==7||t%10==9)
    {
        cout<<"hon"<<endl;
    }
    else if(t%10==0||t%10==1||t%10==6||t%10==8)
    {
        cout<<"pon"<<endl;
    }
    else if(t%10==3)
    {
        cout<<"bon"<<endl;
    }
}

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

int main() {
  int a,b,c,d,e,k; cin >>a>>b>>c>>d>>e>>k;
  bool ans = true;
  
  if (e - a > k) ans = false;
  
  if (ans) cout << "Yay!" << endl;
  else cout << ":(" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}
 ll V,E,r;
 vector<vector<pair<ll,ll>>> G(100010);
 vector<ll> d(100010,INF);
void dijkstra(){
    
    d[r] = 0;
    priority_queue<Pi> pque;
    pque.push(mp(0,r));
    while(!pque.empty()){
        Pi p = pque.top();
        pque.pop();
        ll pos=p.second,cost=-p.first;
        if( cost > d[pos] )continue;
        rep(i,G[pos].size()){
            ll  to = G[pos][i].first;
            ll newcost = cost + G[pos][i].second;
            if(newcost < d[to]){
                d[to] = newcost;
                pque.push(mp(-d[to],to));
            }
        }

    }

}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

int main() {
   
    cin >> V>>E>>r;
    

    rep(i,E){
        ll a,b,c;
        cin >>a>>b>>c;
        G[a].pb(make_pair(b,c));
    }
    dijkstra();

    rep(i,V){
        if(d[i] == INF){
            cout <<"INF"<<endl;
        }else{
            cout << d[i] << endl;
        }
    }
    

    
    return 0;
    

}



Measured memory_bytes: 19480
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    cout << (n % k == 0 ? 0 : 1) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int A[1000000], n;

/* 二分探索 */
int binarySearch(int key) {
    int left = 0;
    int right = n;
    int mid;

    while (left < right) {
        mid = (left + right) / 2;
        if (key == A[mid]) return (1);      /* keyを発見  */
        
        if (key >  A[mid]) {
            left = mid + 1;  /* 後半を探索 */
        }
        else if (key < A[mid]) {
            right = mid;
        } 
    }
    return (0);
}

int main()
{
    int i, q, k, sum = 0;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }

    scanf("%d", &q);
    for (i = 0; i < q; i++) {
        scanf("%d", &k);
        if (binarySearch(k)) {
            sum++;
        }
    }
    printf("%d\n", sum);

    return (0);
}


Measured memory_bytes: 2136
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N, K;
ll arr[100005];

int main() {
	scanf("%lld %lld", &N, &K);
	ll cnt = 0;
	for(int i = 0; i < N; i++) {
		scanf("%lld", &arr[i]);
		if(arr[i] >= K) {
			cnt++;
		}
	}
	printf("%lld\n", cnt);


	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define lson now<<1
#define rson now<<1|1
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int mod=1e9+7;
const double eps = 1e-10;
const double pi=acos(-1.0);
const int maxn=2e5+10;
const ll inf=0x3f3f3f3f;
//int a[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    string s;
    cin>>s;
    reverse(all(s));
    int n=s.length();s[n]='0';
    ll ans=0;
    for(int i=0;i<n;i++){
        int x=s[i]-'0';
        if(10-x<x)ans+=10-x,s[i+1]++;
        else if(x==5){
            if(s[i+1]-'0'>=5)ans+=10-x,s[i+1]++;
            else ans+=10-x;
        }
        else ans+=x;
    }
    ans+=s[n]-'0';
    cout<<ans<<endl;
}



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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define forn(i,n) for(ll i=0;i<n;i++)
#define fore(i,a,b) for(ll i=a;i<=b;i++)
#define ford(i,n) for(ll i=n-1;i>=0;i--)
#define fi first
#define se second
#define endl "\n"
#define all(a) a.begin(),a.end()
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.14159265

/******************************************************************************************************/
void file(){
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
}
/******************************************************************************************************/

const ll nax=2e5+1,mod=1e9+7;



int main(){

    sync
   // file();
    
    string s,t;
    cin>>s>>t;
    int n1 = s.size();
    while(s.size()<=t.size()) s+=s;
    s+=s;

    int n,m;
    n = s.size();
    m = t.size();

    int lps[m];
    lps[0] = 0;
    int pre = 0 ,itr = 1;
    while(itr<m){
        if(t[itr]==t[pre]){
            pre++;
            lps[itr] = pre;
            itr++;
        }
        else{
            if(pre!=0) pre = lps[pre-1];
            else lps[itr] = 0,itr++;
        }
    }
    itr = 0;
    int itr_ = 0;
    vector<int> in_deg(n1,0);
    vector< vector<int> > g(n1);
    while(itr<n){
        if(s[itr] == t[itr_]){
            itr++;
            itr_++;
        }
        else{
            if(itr_!=0){
                itr_ = lps[itr_-1];
            }
            else{
                itr++;
            }
        }
        if(itr_==m){
            int u = itr-m+1;
            u%=n1;
            int v1 = (itr+1)%n1;
            g[u].pb(v1);
            in_deg[v1]++;
        }
    }
    queue<int> q;
    forn(i,n1) if(in_deg[i]==0) q.push(i);
    int ans = 0;
    int cnt = 0;
    while(!q.empty()){
        ans++;
        queue<int> qq;

        while(!q.empty()){
            int u = q.front();
            cnt++;
            for(auto it:g[u]){
                in_deg[it]--;
                if(in_deg[it]==0) qq.push(it);
            }
            q.pop();
        }
        q = qq;
    }
    
    if(cnt!=n1){
        cout<<-1;
    }
    else{
        cout<<ans-1;
    }

    

  return 0;
}

Measured memory_bytes: 34780
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cstring> 
#include<cassert>
#include<cmath>
#include<sstream>
#include<fstream>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<stack>
#include<bitset>
using namespace std;
vector<pair<int,long long> > nei[1000005];
long long dis[1000005];
int N;
void built(int v,int l,int r,int fa){
	if(fa!=-1){
		nei[N+fa].push_back(make_pair(N+v,0));
//		cout<<N+fa<<"---------------->"<<N+v<<endl;
	} 
	if(l==r) {
		nei[N+v].push_back(make_pair(l,0));
//		cout<<N+v<<"---------------->"<<l<<endl;
		return;
	}
	int mid=l+r>>1;
	built(v<<1,l,mid,v);
	built(v<<1|1,mid+1,r,v);
}
void modify(int v,int l,int r,int nl,int nr,int from,long long w){
	if(l>=nl&&r<=nr){
		nei[from].push_back(make_pair(N+v,w));
//		cout<<from<<"----------->"<<l<<","<<r<<" "<<w<<" "<<N+v<<endl;
		return;
	}
	int mid=l+r>>1;
	if(mid>=nl) modify(v<<1,l,mid,nl,nr,from,w);
	if(mid<nr)  modify(v<<1|1,mid+1,r,nl,nr,from,w);
}
int main(){
	int n,m;
	scanf("%d %d",&n,&m);N=n+5;
	built(1,0,n+2,-1);
	
	for(int i=0;i<m;i++){
		int x,y;
		int c;
		scanf("%d %d %d",&x,&y,&c);
		x--,y--;
		modify(1,0,n+2,x+1,y,x,c);
	}
	priority_queue<pair<long long,int> > q;
	q.push(make_pair(0,0));
	fill(dis,dis+1000000,1e18);
	dis[0]=0;
	while(!q.empty()){
		int v=q.top().second;
		long long w=-q.top().first;
	//	cout<<w<<endl;
		q.pop();
		if(w!=dis[v]) continue;
		if(v==n-1){
			cout<<w;
			return 0;
		}
	//	cout<<v<<":"<<w<<endl;
		for(int i=0;i<nei[v].size();i++){
			int u=nei[v][i].first;
			long long co=nei[v][i].second;
		//	cout<<u<<" "<<co<<endl;
			if(co+w<dis[u]){
				
				dis[u]=co+w;
				q.push(make_pair(-dis[u],u));
			}
		}
	}
	cout<<-1;
	return 0;
}

Measured memory_bytes: 73080
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
const ll nmax=8;
bool graph[nmax][nmax];
ll dfs(ll v,ll N,bool visited[nmax]){
   bool all_visited=true;
   for(ll i=0;i<N;++i){
     if(visited[i]==false)all_visited=false;
   }
   if(all_visited){
     return 1;
    }
ll ret=0;
for(ll i=0;i<N;++i){
  if(graph[v][i]==false) continue;
  if(visited[i]) continue;
  visited[i]=true;
  ret+=dfs(i,N,visited);
  visited[i]=false;
  }
  return ret;
} 
int main()
{
    ll N,M;
    cin>>N>>M;
    if(N%2==1){
        rep(i,M){
            cout<<i+1<<" "<<N-1-i<<endl;
        }
    }
    else{
        rep(i,M){
            if(4*i+4<=N)cout<<i+1<<" "<<N-i<<endl;
            else cout<<i+2<<" "<<N-i<<endl;
        }
    }
}

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

int n;
int k;
int answer;

vector<int> d;

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n >> k;

	int dt;
	for(int i=0; i<k; i++) {
		cin >> dt;
		d.push_back(dt);
	}

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

	for(answer = n; answer < 1e6; answer++) {
		int t = answer;
		bool fahne = true;
		while(t && fahne) {
			if(binary_search(d.begin(), d.end(), t%10)) {
				fahne = false;
			}
			t /= 10;
		}
		if(fahne) break;
	}

	cout << answer << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long N;
long long ans = 0;

void flag(long long M, bool ok1, bool ok2, bool ok3) {
    if (M > N) return;
    if (ok1) {
        if(ok2) {
            if(ok3) {
                ans++;
            }
        }
    }
    flag(10*M+3, true, ok2,  ok3);
    flag(10*M+5, ok1,  true, ok3);
    flag(10*M+7, ok1,  ok2, true);
}
  
int main() {
    cin >> N;
    flag(0, false , false , false);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;
ll n,k,a[10];
set<ll> s;
vector<ll> v;
ll num1,num2,num3,num4;
int main()
{while(1){
	scanf("%lld%lld",&n,&k);
	s.clear();
	if(!n) return 0;
	for(ll i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	if(k==2){
		for(ll i=0;i<n;i++){
		num1=a[i];
			for(ll j=0;j<n;j++){
				if(i==j) continue;
				if(a[j]<10){
					num2=num1*10+a[j];
				}
				else{
					num2=num1*100+a[j];
				}
				s.insert(num2);
			}
			
		}
	}
	else if(k==3){
		for(ll i=0;i<n;i++){
		num1=a[i];
			for(ll j=0;j<n;j++){
				if(i==j) continue;
				if(a[j]<10){
					num2=num1*10+a[j];
				}
				else{
					num2=num1*100+a[j];
				}
				for(ll l=0;l<n;l++){
					if(i==l||j==l) continue;
					if(a[l]<10){
						num3=num2*10+a[l];
					}
					else{
						num3=num2*100+a[l];
					}
					s.insert(num3);
				}
			}
		}
	}
	else{
		for(ll i=0;i<n;i++){
		num1=a[i];
			for(ll j=0;j<n;j++){
				if(i==j) continue;
				if(a[j]<10){
					num2=num1*10+a[j];
				}
				else{
					num2=num1*100+a[j];
				}
				for(ll l=0;l<n;l++){
					if(i==l||j==l) continue;
					if(a[l]<10){
						num3=num2*10+a[l];
					}
					else{
						num3=num2*100+a[l];
					}
					for(ll t=0;t<n;t++){
						if(t==i||t==j||t==l) continue;
						if(a[t]<10){
							num4=num3*10+a[t];
						}
						else{
							num4=num3*100+a[t];
						}
						s.insert(num4);
					}
				}
			}
		}
	}
	cout<<s.size()<<endl;
}}

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

int main(void){
  int x;
  cin >> x;
  ll ans = 0;
  ans += (x / 500) * 1000;
  x %= 500;
  ans += (x / 5) * 5;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
int main()
{
	int n; cin>>n;
	double x[6], y[6];
	for(int i=0; i<3; i++){
		x[i]=y[i]=-1e10, x[i+3]=y[i+3]=1e10;
	}
	for(int i=0; i<n; i++){
		char d; double xi, yi; cin>>xi>>yi>>d;
		if(d=='R'){
			x[0]=max(x[0], xi), x[3]=min(x[3], xi), y[2]=max(y[2], yi), y[5]=min(y[5], yi);
		}else if(d=='L'){
			x[1]=max(x[1], xi), x[4]=min(x[4], xi), y[2]=max(y[2], yi), y[5]=min(y[5], yi);
		}else if(d=='U'){
			y[0]=max(y[0], yi), y[3]=min(y[3], yi), x[2]=max(x[2], xi), x[5]=min(x[5], xi);
		}else{
			y[1]=max(y[1], yi), y[4]=min(y[4], yi), x[2]=max(x[2], xi), x[5]=min(x[5], xi);
		}
	}
	double ans=1e18;
	for(ll i=0; i<=400000000; i++){
		double t=(double)i/2;
		double xmx=max({x[0]+t, x[1]-t, x[2]}), xmn=min({x[3]+t, x[4]-t, x[5]});
		double ymx=max({y[0]+t, y[1]-t, y[2]}), ymn=min({y[3]+t, y[4]-t, y[5]});
		ans=min(ans, (xmx-xmn)*(ymx-ymn));
	}
	printf("%.10lf\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vll a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    map<ll, ll> acnt;
    for (ll i = n - 1; i >= 0; i--) {
        acnt[a[i] - i]++;
    }

    ll ans = 0;
    for (ll i = 0; i < n; i++) {
        acnt[a[i] - i]--;
        if (acnt[a[i] - i] == 0) acnt.erase(a[i] - i);
        if (acnt.find(-a[i] - i) != acnt.end()) ans += acnt[-a[i] - i];
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 16328
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    char str[30]={0};
    scanf("%s", str);

    set<char> zz;
    long i;
    for(i=0; i<strlen(str); i++) {
        zz.insert(str[i]);
    }
    if(zz.size()==strlen(str)) {
        printf("yes\n");
    }
    else {
        printf("no\n");
    }
    return 0;
}


Measured memory_bytes: 256
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let x: usize = sc.read();
    for i in 1.. {
        let t = x * i;
        if t % 360 == 0 {
            println!("{}", i);
            return;
        }
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 2132
#include <stdio.h>
#define N_MAX 15
#define M_MAX 15000000

int memo[N_MAX][3][3],ismemoized[N_MAX][3][3];

int main(){
  int card[15],n,m,i,j,from,to,rest,cnt,ans;

  while(1){
    scanf("%d %d",&n,&m);
    ans = m+1;

    if(n==0&&m==0) return 0;

    for(i=0; i<3; i++){
      int t1,t2;
      scanf("%d",&t1);
      for(j=0; j<t1; j++){
	scanf("%d",&t2);
	card[t2-1] = i;
      }
    }

    for(i=0; i<=2; i+=2){
      from = i; cnt = 0;
      for(j=1; j<=n; j++){
	to = card[j-1];
	rest = 3-(from+to);

	switch(abs(from-to)){
	case 1:
	  cnt += move(n-j,from,rest) + 1;
	  from = rest;
	  break;
	case 2:
	  cnt += move(n-j,from,to) + move(n-j,to,from) + 2;
	  break;
	}
      }
      ans = (ans>cnt)?cnt:ans;
    }

    printf("%d\n",(ans==m+1)?-1:ans);
  }
}

int move(num,from,to){
  int rest = 3-(from+to),ans;

  if(ismemoized[num][from][to])
    return memo[num][from][to];

  if(num==0)
    ans = 0;
  else if(num==1)
    ans = abs(from-to);
  else
    switch(abs(from-to)){
    case 0:
      ans = 0;
      break;
    case 1:
      ans = move(num-1,from,rest)+move(num-1,rest,to)+1;
      break;
    case 2:
      ans = move(num,from,rest)+move(num,rest,to);
      break;
    }

  ans = (ans<=M_MAX)?ans:(M_MAX+1);

  ismemoized[num][from][to] = 1;
  memo[num][from][to] = ans;
  return ans;
}

Measured memory_bytes: 0
import java.util.ArrayDeque;
import java.util.Queue;
import java.util.Scanner;

/**
 * ZAKIREN第5章
 *
 * @author K.Yamauchi
 *
 */
public class Main {

	/** 入力用 */
	private static Scanner scan = new Scanner(System.in);

	/** 出力用 */
	private static StringBuilder stringBuilder = new StringBuilder();

	/**
	 * メイン。
	 * @param args
	 */
	public static void main(String[] args) {

		// １行目の読み込み
		String[] firstLine = scan.nextLine().split(" ");
		int size = Integer.parseInt(firstLine[0]);

		// 2行目以降（プロセスとクオンタム）の読み込み
		String[] processes = new String[size];
		for (int i = 0; i < size; i++) {
			processes[i] = scan.nextLine();
		}

		// 読み込み終了
		scan.close();
		scan = null;

		// 計算を実行
		calculation(size, Integer.parseInt(firstLine[1]), processes);

		// 結果出力
//		System.out.println(stringBuilder.toString());

	}

	/**
	 *
	 * @param size
	 * @param quantum
	 * @param processes
	 */
	private static void calculation(int size, int quantum, String[] processes) {

		// 計算用キュー
		Queue<String> queue = new ArrayDeque<>();

		// キューにプロセスを設定
		for (int i = 0; i < size; i++) {
			queue.add(processes[i]);
		}

		// 経過時間
		int elapsedTime = 0;

		// キューの中身がなくなるまで計算
		while (!queue.isEmpty()) {
			// キューからプロセスを一つ取得
			String[] process = queue.poll().split(" ");
			// 取得したプロセスの残り時間
			int remainedTime = Integer.parseInt(process[1]);

			if (remainedTime <= quantum) {
				// プロセスの残り時間がクオンタム以下であれば、そのプロセスは終了
				stringBuilder.append(process[0] + " " + (elapsedTime + remainedTime) + "\n");
				System.out.println(process[0] + " " + (elapsedTime + remainedTime));
				elapsedTime -= (quantum - remainedTime);
			} else {
				// プロセスの残り時間がクオンタムより大きければ、クオンタム分残り時間を減らし、再度キューに登録
				remainedTime -= quantum;
				queue.add(process[0] + " " + remainedTime);
			}
			elapsedTime += quantum;
		}

	}

}



Measured memory_bytes: 111212
#include <iostream>
#include <stdio.h>
#include <vector>

#define MAX_N 100

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> B;
  for (int i = 0; i < N; ++i) {
    int b;
    cin >> b;
    B.push_back(b - 1);
  }
  vector<int> res;
  for (int i = 0; i < N; ++i) {
    for (int j = B.size() - 1; j >= 0; --j) {
      if (B[j] == j) {
        res.push_back(j);
        B.erase(B.begin() + j);
        break;
      }
    }
  }
  if (B.size() == 0) {
    for (int i = res.size() - 1; i >= 0; --i) {
      printf("%d\n", res[i] + 1);
    }
  } else {
    printf("-1\n");
  }
}

Measured memory_bytes: 3244
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <float.h>

#pragma region 定義
typedef long long  ll;
typedef unsigned long long  ull;


#define _itoa(A,N) sprintf(A, "%d", N);

int i_dsort(const void* a, const void* b);
int i_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);

int s_asort(const void* a, const void* b);
int s_dsort(const void* a, const void* b);

//昇順
int s_asort(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(strcmp((char*)b, (char*)a));
}

int i_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int i_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}

int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}
// puts("Yes\n") puts("No\n")
// scanf("%d.%d") 浮動小数点入力を整数２つで得る


//#define pai  3.1415926535 
//#define  _USE_MATH_DEFINES でM_PIが使える

#define deg_rad(X)  (X*(M_PI/180))


int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}
#define _abs(x) ((x)>0?(x):-(x))
#define _min(x,y) ((x)<(y)?(x):(y))
#define _max(x,y) ((x)<(y)?(y):(x))

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}

//素因数分解　pf素数が入る　pc 素数の数
ll _pfact(ll a);
static ll pf[100000000];
static ll pc;

ll _pfact(ll a) {
	long i, r;
	if (a % 2 == 0) {
		pf[pc] = 2; pc++;
		return(_pfact(a / 2));
	}
	r = sqrt(a);
	for (i = 3; i <= r; i += 2) {
		if (a % i == 0) {
			pf[pc] = i; pc++;
			return(_pfact(a / i));
		}
	}
	if (a != 1) {
		pf[pc] = a; pc++;
	}
	return 0;

}


#pragma endregion

//ABC  100-C *3 or /2
int _div2(int a);
int _div2(int a) {
	int cnt = 0;
		while (1) {
			a /= 2;
			cnt++;
			if (a % 2)break;
		}
		return cnt;
}

int main(void) {
	int     i,n,a;
	long    sum=0;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a);
		if (a % 2)continue;

		sum += _div2(a);
	}
	printf("%d\n",sum);
    
	return 0;
}


Measured memory_bytes: 2152
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int* a = new int[200000];
  for(int i=0;i<n;i++) cin >> a[i];
  int sum = 0;
  int r=0;
  long count = 0;
  for(int l=0;l<n;l++){
    while(r<n&&(sum^a[r])==sum+a[r]){
      sum += a[r];
      r++;
    }
    count += r-l;
    sum -= a[l];
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>

using namespace std;


int main()
{
	string a ;
	string out;
	cin >> a;
	for (unsigned int i = 0; i < a.size(); i++)
	{
		if (a[i]=='0')
		{
			out.append("0");
		}
		else if (a[i] == '1')
		{
			out.append("1");
		}
		else if (a[i] == 'B')
		{
			try
			{
				out.erase(out.length() - 1);
			}
			catch (const std::exception&)
			{

			}
			
		}
	}
	//cout << a<<endl;
	cout << out;
	//cin >> a;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long n, q, b, c, ans, i, j, k, x;
	cin >> n;
	map<int, int> ct;
	ans = 0;
	for (i =0 ; i < n; i++) {
		cin >> x;
		ct[x]++;
		ans += x;
	}

	cin >> q;
	while (q--) {
		cin >> b >> c;
		ans += (long long)(c - b) * ct[b];
		ct[c] += ct[b];
		ct.erase(b);
		cout << ans << "\n";
	}



	return 0;
}


Measured memory_bytes: 6160
#include<iostream>
#include<algorithm>
typedef long long ll;
using namespace std;

int main(){
    ll N, A, B;
    cin >> N >> A >> B;
    if((B-A)%2 == 0){
        cout << (B-A)/2 << endl;
    }else{
        ll extra = min(A, N-B+1);
        cout << ((B-A)+2*extra-1)/2 << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;

ll K;
ll N = 50;
ll a[60];

int main()
{
  scanf( "%lld", &K );

  ll add = K/N;
  K %= N;

  rep( i, N )
    a[i] = i+add;

  rep( i, K )
  {
    rep( j, N )
    {
      a[j] += (i==j ? N : -1);
      //printf( "(%d,%d)\n", i, j );
    }
  }

  printf( "%lld\n", N );

  rep( i, N )
    printf( "%lld%c", a[i], i==N-1?'\n':' ' );

  return 0;
}

Measured memory_bytes: 256