akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3

import sys

input = iter(sys.stdin.read().splitlines()).__next__


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

S = set(list(range(1, N+1)))
for k in range(K):
   d = int(input())
   A = list(map(int, input().split()))
   for x in A:
      if x in S:
         S.remove(x)

print(len(S))




Measured memory_bytes: 9128
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
using VVI = vector<vector<long long int> >;

// 二つの値の最大値を求める関数
Int Max(const Int a, const Int b) {
    if (a >= b) {
        return a;
    } else {
        return b;
    }
}
// 分数の Ceil を求める関数
UInt Ceil(const UInt a, const UInt b) {
    if (a % b == 0) {
        return a / b;
    } else {
        return a / b + 1;
    }
}

int main(void) {
    Int array[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    Int k;
    cin >> k;
    --k;
    cout << array[k] << endl;
    return 0;
}


Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>
#include<string.h>
#include<string>

using namespace std;

int a[3];
int ans = 0;
int main()
{
	int maxindex;
	int ma = -1;
	int minindex;
	int mi = 100;
	for (int i = 0; i < 3; i++)
	{
		cin >> a[i];
		if (a[i] > ma)
		{
			maxindex = i;
			ma = a[i];
		}
		if (a[i] < mi)
		{
			minindex = i;
			mi = a[i];
		}		
	}
	for (int i = 0; i < 3; i++)
	{
		if (i != minindex && i != maxindex)
		{
			ans += (a[maxindex] - a[i]);
			int number = a[maxindex] - (a[minindex] + ans);
			if (number & 1 == 1)
			{
				ans += (number / 2 + 2);
			}
			else
			{
				ans += (number / 2);
			}
		}
	}
	cout << ans;
	return 0;
 }

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read


#p,n,k,b,*a = [int(i) for i in read().split()]

n = int(input())
from math import gcd
print(sum(gcd(gcd(a,b),c) for a in range(1,n+1) for b in range(1,n+1) for c in range(1,n+1)))



Measured memory_bytes: 68292
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
//template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
//template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll mod=1e9;


int main()
{
    ll s;
    cin >> s;
    ll p=(s-1)/mod+1;
    ll q=p*mod-s;
    cout << 0 <<" "<< 0 <<" "<<  mod <<" " << 1 <<" "<<  q <<" "<< p << endl;
    return 0;
} 

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

using namespace std;

const int maxn = 2000 + 10;
int n, k, dis[maxn], ansall = maxn;
bool mark[maxn];
deque < int > deq;
vector < int > adj[maxn];

int bfs( int v )
{
  int ans = 0;
  mark[v] = 1, deq.push_back(v), dis[v] = 0;
  while( deq.size() )
  {
    for( int i = 0; i < adj[deq.front()].size(); i++ )
    {
      if( mark[adj[deq.front()][i]] == 0 )
      {
        dis[adj[deq.front()][i]] = dis[deq.front()]+1;
        if( dis[adj[deq.front()][i]] > k/2 )
        {
          ans++;
        }

        deq.push_back(adj[deq.front()][i]);
        mark[adj[deq.front()][i]] = 1;
      }
    }
    deq.pop_front();
  }

  for( int i = 0; i < maxn; i++ )
    mark[i] = 0;

   return ans;
}

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

    cin >> n >> k;
    if( k % 2 == 0 )
    {
      int u, v;
      for( int i = 0; i < n-1; i++ )
      {
        cin >> u >> v;
        adj[u-1].push_back(v-1);
        adj[v-1].push_back(u-1);
      }
      for( int i = 0; i < n; i++ )
      {
        ansall = min( ansall, bfs(i) );
      }
    }
    else
    {
      pair < int, int > e[n];
      for( int i = 0; i < n-1; i++ )
      {
        cin >> e[i].first >> e[i].second;
        e[i].first--, e[i].second--;
        adj[e[i].first].push_back(e[i].second);
        adj[e[i].second].push_back(e[i].first);
      }

      k--;
      for( int i = 0; i < n-1; i++ )
      {
        mark[e[i].first] = 1;
        int k1 = bfs(e[i].second);
        mark[e[i].second] = 1;
        int k2 = bfs(e[i].first);
        ansall = min( ansall, k1+k2 );
      }
    }

    cout << ansall;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
   int a,b;
   cin>>a>>b;
   int N;
   if(b<10) N=a*10+b;
   else if(b==100) N=a*1000+b;
   else N=a*100+b;
   bool c=false;
   for(int i=1;i<=1000;i++){
       if(i*i==N) c=true;
   }
   if(c==true) cout<<"Yes";
   else cout<<"No";
   return 0;
}

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

int main()
{
	int q, lim, query, x;
	vector<int> List;
	vector<int>::iterator it;
	while(scanf("%d %d", &q, &lim) && q > 0)
	{
		for(int f1 = 1; f1 <= q; f1++){
			scanf("%d %d",&query, &x);
			switch(query)
			{
				case 0:
					List.push_back(x);
					if((int)List.size() > lim){
						List.erase(List.begin());
					}
				break;
				case 1:		
					List.erase((List.begin() + (x - 1)));
				break;
				case 2:
					if(x <= (int)List.size() / 2)
						it = List.begin() + (x - 1);
					else
						it = List.end() - (List.size() - (x - 1));
					printf("%d\n", *it);
				break;
				default:
					it = List.erase(find(List.begin(), List.end(), x));
				break;
			}
		}
		printf("end\n");
		List.clear();
	}
	return 0;
}

Measured memory_bytes: 1720
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int H, W;
int N;
int A[10000];
int C[100][100];

P next(int x, int y) {
  if (y % 2 == 0) {
    if (x == W-1) {
      y++;
    }
    else {
      x++;
    }
  }
  else {
    if (x == 0) {
      y++;
    }
    else {
      x--;
    }
  }
  return P(x, y);
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> H >> W >> N;
  rep(i, N) cin >> A[i];
  int x = 0, y = 0;
  rep(i, N) {
    rep(_, A[i]) {
      C[x][y] = i+1;
      P p = next(x, y);
      x = p._1;
      y = p._2;
    }
  }
  rep(i, H) {
    rep(j, W) {
      cout << C[j][i];
      if (j == W-1)cout<<"\n";
      else cout << " ";
    }
  }
  return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;


const int SIZE = 1e5+100;
string s;

int main(){
    int ans = 1000;
    cin >> s;
    for(int i = 0; i < s.length()-2; i++){
        string mem;
        for(int j = i; j < i+3; j++){
            mem += s[j];
        }
        int a = atoi(mem.c_str());
        ans = min(ans,abs(753-a));
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int a, b;
	char op;
	scanf("%d %c %d", &a, &op, &b);
	if (op == '+') {
		printf("%d\n", a + b);
	} else {
		printf("%d\n", a - b);
	}
	return 0;
}

Measured memory_bytes: 128
#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 D = 60;
const int MAX_N = 200005;
int to[D][MAX_N];

int main()
{
    int n;
    ll k;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> to[0][i];
        to[0][i]--;
    }
    rep(i, D - 1) rep(j, n) to[i + 1][j] = to[i][to[i][j]];

    int v = 0;
    for (int i = D - 1; i >= 0; i--)
    {
        ll l = 1ll << i;
        if (l <= k)
        {
            v = to[i][v];
            k -= l;
        }
    }
    cout << v + 1 << endl;
    return 0;
}


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            for (var i = 0; i < S.Length - 1; i++)
            {
                var chk = S[i];
                for(var j = i + 1; j < S.Length; j++)
                {
                    if (S[i] == S[j])
                    {
                        Console.WriteLine("No");
                        return;
                    }
                }
            }
            Console.WriteLine("Yes");
        }
    }
}

Measured memory_bytes: 11092
num, total = [int(x) for x in input().split()]

for c_10000 in range(num+1):
    for c_5000 in range(num+1-c_10000):
        if (10000 * c_10000 + 5000 * c_5000 + 1000 * (num - c_10000 - c_5000)) == total:
            print('{} {} {}'.format(c_10000, c_5000, num - c_10000 - c_5000))
            exit()

print('-1 -1 -1')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

int A, B, M;
vector<int> a, b;

void _main() {
    cin >> A >> B >> M;
    a.resize(A); b.resize(B);
    REP (i, A) cin >> a[i];
    REP (i, B) cin >> b[i];
    int ans = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
    REP (i, M) {
        int x, y, c;
        cin >> x >> y >> c;
        x--; y--;
        ans = min(ans, a[x] + b[y] - c);
    }
    cout << ans << endl;
}

signed main(signed argc, char **argv) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

Measured memory_bytes: 1792
m={"E":[3,1,0,5,4,2], "N":[1,5,2,3,0,4], "W":[2,1,5,0,4,3], "S":[4,0,2,3,5,1]}
d=map(int, raw_input().split())
nd=[0]*6
dir=raw_input()
for i in range(len(dir)):
    x=dir[i]
    for j in range(6):
        nd[j]=d[m[x][j]]
    d=list(nd)
print d[0]

Measured memory_bytes: 6468
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>
#include <cmath>

using namespace std;
typedef long long ll;

#define cout (cout << setprecision(12))

int main() {
    string s;
    cin >> s;
    auto before = s[0];
    bool flag = false;
    for (int i = 1; i < s.size(); i++) {
        auto after = s[i];
        if (before != after) {
            flag = true;
            break;
        }
    }
    if (flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

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

using ll = long long int;
using pll = pair<ll, ll>;

const ll mod = static_cast<ll>(1e9) + 7;

ll N, K;

const ll MAXN = 100000;
vector<ll> G[MAXN];
bool visited[MAXN];

ll solve(ll p, ll d, ll v)
{
    visited[p] = true;

    ll ans = K - min(d, 2LL) - v;

    ll index = 0;

    for (ll i=0,n=G[p].size();i<n;++i)
    {
        const ll to = G[p][i];
        if (visited[to]) { continue; }

        const ll res = solve(to, d + 1, index);
        ++index;

        ans = (ans * res) % mod;
    }

    return ans % mod;
}

int main()
{
    cin >> N >> K;

    rep (i, N - 1)
    {
        ll a, b;
        cin >> a >> b;

        --a;
        --b;

        G[a].push_back(b);
        G[b].push_back(a);
    }

    const ll ans = solve(0, 0, 0);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 11648
#include <bits/stdc++.h> //全てのヘッダファイルをインクルード
 
//ループ
#define rep(i, n) for(int i = 0; i < (n); i++) //普通のループ
#define repr(i, n) for(int i = n; i >= 0; i--) //逆ループ
 
//型名省略
typedef long long ll;
//値
static const ll MX = 100005;
static const ll MX_ll = 1e18;
const double PI = acos(-1); //π
 
using namespace std;
 
//ソート
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 
//#include "./lib/generic/search.h"

//文字列入力した小数値を小数点なくして返す
int changeDoubleToInt(string decimal){ 
    decimal.erase(1, 1); //小数点削除
    int n_decimal = atoi(decimal.c_str()); //c_strでchar*に変換後、atoiでintに変換
    return n_decimal;
}

//最大公約数
int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
}

//素数判定(True/Falseを返却)
int IsPrime_tf(ll num){
    if (num < 2) return false; //0、1は素数でない
    else if (num == 2) return true; //2は素数
    else if (num%2==0) return false; // 偶数はあらかじめ除く
    for (ll i = 3; i*i <= num; i += 2){ //チェックは2～√nで十分
        if (num % i == 0) return false; //素数でない
    }
    return true; //素数である
}

//素数判定(割れる値を返却)
ll IsPrime_value(ll num){
    if (num < 2) return -1; //0、1は素数でない
    else if (num == 2) return 2; //2は素数
    for (ll i = 2; i*i <= num; i += 1){ //チェックは2～√nで十分
        if (num % i == 0) return i; //素数でない
    }
    return num; //素数である
}

int main(){
   int s;
   cin >> s;
   int h = (s/60)/60;
   int m = (s-h*60*60)/60;
   int s_ = s-h*60*60-m*60;
   cout << h << ":" << m << ":" << s_ << endl;
   return 0;
}


Measured memory_bytes: 3100
#99c
import math

N = int(input()) #<=100000

#引き算を足し算で下から求める

#直で引き出せる一覧のsetを作る。
single_withdraw_set = set()
single_withdraw_set.add(1)
single_withdraw_set |= {6**i for i in range(1,2 + int(math.log(N,6)))}
single_withdraw_set |= {9**i for i in range(1,2 + int(math.log(N,9)))}
#print(single_withdraw_set)

#何回で引き出せるかのdict。この後の計算でマイナス値を参照するので、あらかじめ作っておく。
withdraw_dict = {int(-i):10**9+7 for i in range(1,1 + max(single_withdraw_set)) }
withdraw_dict[0] = 0

#最低の引き出し回数を1円から計算していく
for i in range(1,N+1):
    if i in single_withdraw_set:
        #1回で引き出せるsetにあるなら当然1回
        withdraw_dict[i] = 1
    else:
        #なければ (現状の値 - 1回で引き出し可能な値)の中で1番少ない値 + 1 
        withdraw_dict[i] = 1 + min([withdraw_dict[i-j] for j in single_withdraw_set])
    
    #print(i,":",withdraw_dict[i])
    
#print(withdraw_dict)
print(withdraw_dict[N])

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

using namespace std;

#define ll long long
#define pi pair<int, int>
#define pb push_back
#define fr first
#define sc second
#define endl '\n'

const int mxn = 1e6 + 5;
const ll MOD =  1e9 + 7;
int arr[mxn];
int n, m, k, q;
string s, t;

void solve() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(max(a * c, a * d), max(b * c, b * d)) << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    //cin >> T;
    while(T--) solve();
    return 0;
}


Measured memory_bytes: 3648
package main

import (
	"fmt"
)

func main(){
	var s string
	fmt.Scan(&s)

	count:=0
	for index,v := range(s){
		if string(v) =="R"{
			count ++
		}else if index!=0 && count!=0{
			break
		}
	}
	fmt.Println(count)
}


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

int main(void){
    int h, w;
    cin >> h >> w;
    vector<vector<char>>pic(h+2,vector<char>(w+2));
    for (int i = 0; i < h+2; i++){
        for (int j = 0; j < w+2;j++){
            if ((i == 0) || (i == h + 1) || (j == 0) || (j == w + 1)){
                pic.at(i).at(j) = '#';
            }else
            cin >> pic.at(i).at(j);
        }
    }
    for (int i = 0; i < h + 2;i++){
        for (int j = 0; j < w + 2;j++){
            cout << pic.at(i).at(j);
            }
        cout << endl;
    }

    return 0;
    }

Measured memory_bytes: 256
import numpy as np

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
next_ = 0
for i in range(N):
    num_monster = max(A[i] - next_, 0)
    if num_monster <= B[i]:
        ans += num_monster + min(next_, A[i])
        next_ = B[i] - num_monster
    else:
        ans += B[i] + min(next_, A[i]) 
        next_ = 0
ans += min(next_, A[N])

print(ans)


Measured memory_bytes: 43072
#include<iostream>

using namespace std;

int main(){
	int a, b;
	string sle;
	cin >> a;
	cin >> b;
	if (a < b) sle = "a < b";
	else if (a > b) sle = "a > b";
	else if (a == b) sle = "a == b";
	cout << sle << endl;
	return 0;
}


Measured memory_bytes: 3156
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long double N;
  cin >> N;
  REP(i, 100000) {
    if ((ll)((long double)i * 1.08) == N) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 100100100100100;
const ll mod = 1000000007;
int main(){
ll n;
cin>>n;
ll res=n/11*2,check=n%11;
if(check!=0){
    if(check<=6)res++;
    else res+=2;
}
cout<<res<<endl;
}


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

using namespace std;

int main(){
  string s;
  cin >> s ;
  int k;
    if(s == "SUN" )
      k=7;
    if(s== "MON" )
      k=6;
    if(s=="TUE" )
      k=5;
    if(s== "WED" )
      k=4;
    if( s== "THU" )
      k=3;
    if(s== "FRI" )
      k=2;
    if(s== "SAT" )
      k=1;
  cout <<k << endl;
  return 0;
}

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

#define pb push_back
#define pob pop_back
#define mp make_pair
#define f first
#define s second

typedef long long ll;
const ll INF = 1e18;
const ll mod = 1e9 + 7;

void solve(){
	string str;
	cin>>str;
	if(str[0] == str[1] || str[1] == str[2] || str[2] == str[3]) cout<<"Bad\n";
	else cout<<"Good\n";
}

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


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


using namespace std;

long long a[101];
long long n;

long long memo[101][21];

long long fanc(long long lo,long long sum)
{
	if (sum < 0 || 20 < sum){ return 0; }

	if (lo == 0){ return fanc(lo+1,a[lo]); }

	if (lo == n - 1){ return (a[lo] == sum); }

	if (memo[lo][sum] != -1)
	{
		return memo[lo][sum];
	}
	else
	{
		return memo[lo][sum] = fanc(lo + 1, sum + a[lo]) + fanc(lo + 1, sum - a[lo]);
	}
}

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

	memset(memo,-1,sizeof(memo));

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

	cout << fanc(0,0) << "\n";
	return 0;
}

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

string pls(string a,string b)
{
	string ret;
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	if(a.size()<b.size())swap(a,b);
	while(b.size()  !=a.size()  )b+='0';
	while(ret.size()!=a.size()+1)ret+='0';
	for(int i=0;i < a.size(); i++){
		ret[i] = a[i] + b[i] + ret[i] - '0'*3;
		if(ret[i]>9){
			ret[i] = '0' + ret[i]%10;
			ret[i+1] = '1';
		}else{
			ret[i]= '0' + ret[i];
		}
	}
	reverse(ret.begin(),ret.end());
	if(~ret.find_first_not_of('0'))return ret.substr(ret.find_first_not_of('0'),ret.size()-ret.find_first_not_of('0'));
	else return "0";
}

bool func(vector<string> f , int n)
{
	for(int i=0;i<3;i++){
		for(int j=0;j<f[i].length();j++){
			if(f[i][j]=='X'){
				f[i][j]='0'+n;
			}
		}
	}
	return ( pls(f[0],f[1]) == f[2] );
}

int main()
{
	bool flag;
	int ret;
	vector<string> m;
	string s,t;
	while(cin >> s){
		s+=" ";
		m.clear();
		flag = false;
		ret = -1;
		
		for(int i=0;i<s.length();i++){
			if(s[i]>='0' && s[i]<='9' || s[i]=='X'){
				t+=s[i];
			}else{
				if(t.size()>=2 && t[0] == 'X')flag = true;
				m.push_back(t);
				t.clear();
			}
		}
		for(int i=(flag?1:0);i<10;i++){
			if(func(m,i))ret=i;
		}
		if(~ret)cout << ret << endl;
		else cout << "NA" << endl;
	}
}

Measured memory_bytes: 0
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

h,w,d = inpl()
n = h*w
di = dict()
for i in range(h):
    x = inpl()
    for j in range(w):
        di[x[j]-1] = (i,j)
a = []
for i in range(d):
    tmp = [0]
    for j in range(i,n,d):
        if j == i:
            px,py = di[j]
            continue
        nx,ny = di[j]
        tmp.append(abs(nx-px)+abs(ny-py))
        px,py = nx,ny
    a.append(list(itertools.accumulate(tmp)))

q = inp()
for _ in range(q):
    l,r = inpl()
    l,r = l-1, r-1
    now = l%d
    print(a[now][(r-now)//d] - a[now][(l-now)//d])

Measured memory_bytes: 37352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll mod=INF;

int main() {
    int n;
    cin >> n;
    vector<pair<int,int>> e(n);
    rep(i,n) cin >> e[i].first >> e[i].second;
    vector<pair<int,int>> a(2*n);
    rep(i,n){
        a[2*i]=mk(e[i].first,0);
        a[2*i+1]=mk(e[i].second,1);
    }
    sort(all(a));
    int f=0,g=0;
    if (n%2==1){
        int s,d;
        rep(i,2*n){
            if (a[i].second==0) f++;
            else g++;
            if (f==(n+1)/2){
                s=a[i].first;
                f++;
            }
            if (g==(n+1)/2){
                d=a[i].first;
                g++;
            }
        }
        cout << d-s+1 << endl;
    }
    if (n%2==0){
        int ss,dd,s,d;
        rep(i,2*n){
            if (a[i].second==0) f++;
            else g++;
            if (f==(n+1)/2){
                s=a[i].first;
                f++;
            }
            if (f==(n+1)/2+2){
                ss=a[i].first;
                f++;
            }
            if (g==(n+1)/2){
                d=a[i].first;
                g++;
            }
            if (g==(n+1)/2+2){
                dd=a[i].first;
                g++;
            }
        }
        cout << d+dd-s-ss+1 << endl;
    }

}


Measured memory_bytes: 8012
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define each(i, mp) for(auto& i:mp)

const int INF = 1001001001;

int main() {
  string s;
  cin >> s;
  // string coffee = "coffee";

  if (s[2] == s[3] && s[4] == s[5])
  cout << "Yes" << endl;
  else
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
S = input().replace(" ", "")
K = int(input())

str1 = S
str2 = S * 2
str3 = S * 3
str4 = S * 4
n1 = 0
n2 = 0
n3 = 0
n4 = 0
ln1 = []
ln2 = []
ln3 = []
ln4 = []

for c in str1:
  ln1.append(c)
for i in range(len(ln1)):
  if i == 0:
    pass
  elif ln1[i-1] == ln1[i]:
    n1 += 1
    ln1[i] = "A"
    
for c in str2:
  ln2.append(c)
for i in range(len(ln2)):
  if i == 0:
    pass
  elif ln2[i-1] == ln2[i]:
    n2 += 1
    ln2[i] = "A"
    
for c in str3:
  ln3.append(c)
for i in range(len(ln3)):
  if i == 0:
    pass
  elif ln3[i-1] == ln3[i]:
    n3 += 1
    ln3[i] = "A"
    
for c in str4:
  ln4.append(c)
for i in range(len(ln4)):
  if i == 0:
    pass
  elif ln4[i-1] == ln4[i]:
    n4 += 1
    ln4[i] = "A"
  
if len(S) == 1:
  print(K//2)
elif n1 == (n2 - n1) and (n2 - n1) == (n3 - n2):
  print(int(n1 * K))
elif n1 != (n2 - n1) and (n2 - n1) == (n3 - n2) and n1 == (n4 - n3):
  if K >= 3:
    print(int(n1 + (n3 - n1) * (K - 1)//2 - 1))
  elif K == 2:
    print(int(n2))
  else:
    print(int(n1))
elif n1 != (n2 - n1) and (n2 - n1) == (n3 - n2):
  if K >= 3:
    print(int(n1 + (n3 - n1) * (K - 1)//2))
  elif K == 2:
    print(int(n2))
  else:
    print(int(n1))
else:
  if K % 2 == 1:
    print(int(n1 + (n3 - n1) * (K - 1)//2))
  else:
    print(int(n2 * K / 2))


Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
int main(){
    int N, ans=10001;
    cin >> N;
    vector<int> W(N), sum(N);
    cin >> W[0]; sum[0]=W[0];
    for(int i = 1; i < N; i++){
        cin >> W[i]; sum[i] = sum[i-1] + W[i];
    }
    for(int i = 0; i < N-1; i++){
        if(ans > abs(2 * sum[i] - sum[N-1])) ans = abs(2 * sum[i] - sum[N-1]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
long long a,b,c,d;
long long func(long long x)
{
	long long aa=(a+x-1ll)/x*x,bb=b/x*x;
	return (bb-aa)/x+1ll;
}
long long gcd(long long a,long long b) 
{
    return b>0?gcd(b,a%b):a;
}
int main()
{
	cin>>a>>b>>c>>d;
	cout<<b-a+1ll-func(c)-func(d)+func(c*d/gcd(c,d))<<endl;
	return 0;
}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int h,w,n;cin>>h>>w>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  int dp[100][100];
  int i=0,j=0;
  rep(k,n){
    int l=k+1;
    while(a[k]>0){
        dp[i][j]=l;
        a[k]--;
        j++;
        if(j==w)i++,j=0;
    }
  }
  rep(l,h){
      if(l&1)rep(r,w)cout<<dp[l][r]<<' ';
      else rep(r,w)cout<<dp[l][w-r-1]<<' ';
      cout<<endl;
  }
  return 0;
  }


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		if(a < b){
			System.out.println("a < b");
		} else if(a > b){
			System.out.println("a > b");
		}else{
			System.out.println("a == b");
		}
	}

}

Measured memory_bytes: 17224
#include<iostream>
#include<bits/stdc++.h>
#include<climits>
#include<math.h>

#define forn(x,n,s) for(int i = x; i < n; i += s )
#define forr(x,n,s) for(int i = x; i>=n; i -= s)
#define PI 3.14159265358979323846264338327950L
#define MOD 1e9+7

using namespace std;

void go(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  #ifndef ONLINE_JUDGE
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
  #endif
} 

int main(){
    go(); 

    // code here
    int n,m;cin>>n>>m;
    long long cnt = 0;
    forn(0,m,1){
        int inp;cin>>inp;
        cnt += inp;
    }
    if(cnt>n) cout<<-1;
    else cout<<(n-cnt);

    
} 



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

int modulo(int a[], int n)
{
 int sum=0;
  for(int i=0;i<n;i++)
    sum+=a[i]-1;
  return sum;
}
int main()
{
 int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
 int result = modulo(arr,n);
  cout<<result;
}

Measured memory_bytes: 3576
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))

A2 = abs(A)
x = min(A2)
A3 = A < 0
if sum(A3) % 2 == 0:
    print(sum(A2))
else:
    print(sum(A2)-2*x)



Measured memory_bytes: 23256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<char,int>;


// UnionFind木(サイズ持ち)
class UnionFind {
    public : 

        vector<int> par;

        UnionFind(int N){
            par = vector<int>(N, -1);
        }

        int parent(int x){
            return par[x];
        }

        int root(int x){
            if(par[x] < 0)return x;
            return par[x] = root(par[x]);
        }

        int size(int x){
            return -par[root(x)];
        }

        void connect(int x, int y){
            int rx = root(x);
            int ry = root(y);
            if(rx == ry)return;

            if(size(rx) < size(ry))swap(rx, ry);

            par[rx] += par[ry];
            par[ry] = rx;

            return;
        }

        bool same(int x, int y){
            return root(x) == root(y);
        }
};

int main(){
   int n, m;
   cin >> n >> m;
   UnionFind uf(n);

   rep(i, m){
       int x, y, z;
       cin >> x >> y >> z;
       x--;y--;
       uf.connect(x, y);
   }

   map<int, int>mp;
   rep(i, n){
       mp[uf.root(i)]++;
   }
   int res = 0;
   for(auto m : mp)res++;
   cout << res << endl;
}



Measured memory_bytes: 5376
import java.util.*;
 
public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	int n = scan.nextInt();
      	int l = scan.nextInt();
      	int[] arr = new int[n];
      	int sum = 0;
      	int min = 0;
      	for(int i = 0; i<n; i++){
        	arr[i] = l + i ;
          	sum += arr[i];
        }
      if(l >= 0){
        System.out.print(sum - l);
      }
     
      else{
        if(n + l > 0){
      		min = sum;
      		
        }
        else{
        	min = sum - (n + l - 1);
        }
        System.out.print(min);
      }
      	
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
//#define local
int main()
{
#ifdef local
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif
    long long n,k,a,b,la=0,lb=0;
    cin>>n>>la>>lb;
    while(--n)
    {
        cin>>a>>b;
        if(a<la||b<lb)
        {
            k=max(la/a+(la%a?1:0),lb/b+(lb%b?1:0));
            la=a*k,lb=b*k;
        }
        else la=a,lb=b;
    }
    cout<<la+lb<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>

using namespace std;
static const int N=100;
static const int INFTY=(1<<21);

int n,M[N][N];
int d[N];

void bfs(int s){
  queue<int> q;
  q.push(s);
  for(int i=0;i<n;i++) d[i]=INFTY;
  d[s]=0;
  int u;
  while(!q.empty()){
    u=q.front(); q.pop();
    for(int v=0;v<n;v++){
      if(M[u][v]==0) continue;
      if(d[v]!=INFTY) continue;
      d[v]=d[u]+1;
      q.push(v);
    }
  }
  for(int i=0;i<n;i++){
    cout << i+1 << " " << ((d[i]==INFTY)?(-1):d[i]) << endl;
  }
}

int main(){
  int u,k,v;
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      M[i][j]=0;
    }
  }

  for(int i=0;i<n;i++){
    cin>>u>>k;
    u--;
    for(int j=0;j<k;j++){
      cin>>v;
      v--;
      M[u][v]=1;
    }
  }

  bfs(0);

  return 0;
}

Measured memory_bytes: 3112
K = int(input())

# キューに候補の値を順に入れていく方法で解く
from collections import deque
d = deque()

# 事前に１桁のを入れる
for i in range(1,10):
    d.append(i)

x = 0
# 取り出しをK回行う
for i in range(K):
    x = d.popleft()
    # 次の候補を入れる
    # xの右に末尾プラマイ１をくっつけた値を入れる
    # ただし、末尾0のときと、９のときは例外あり
    tmp = x%10
    if tmp != 0:
        d.append(10*x + (tmp-1))
    d.append(10*x + tmp)
    if tmp != 9:
        d.append(10*x + (tmp+1))

print(x)

Measured memory_bytes: 40816
#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<w ; i++){
            cout<< "#";
        };
        cout << endl;
        for (int j=0; j<h-2 ; j++){
            cout<<"#";
            for (int i=0; i<w-2 ; i++){
            cout<< ".";
        };
        cout << "#"<<endl;
        };
    for (int i=0; i<w ; i++){
            cout<< "#";
    };
    cout << endl;
     cout <<endl;
    }

    return 0;
    }



Measured memory_bytes: 3076
#include<iostream>
#include<stack>
#include<string>
#include <sstream>

using namespace std;
string s;
int idx;
int term();
int expr();
int fact();
int number();

// <term> = <fact> { (‘*’|‘/’) <fact> } 
int term(){
  int res = fact();
  while(s[idx] == '*' || s[idx] == '/'){
    char op = s[idx++];
    int tmp = fact(); 
    if(op == '*')
      res *= tmp;
    else res /= tmp;
  }
  return res;
}


// <expr> = <term> { (‘+’|‘-’) <term> }
int expr(){
  int res = term();
  while(s[idx] == '+' || s[idx] == '-'){
    char op = s[idx++];
    int tmp = term();
    if(op == '+') res += tmp;
    else res -= tmp;
  }
  return res;
}


// <number> = { <digit> }
// <digit> = ‘0’ | ‘1’ | ... | ‘9’
int number(){
  int res = 0;
  while('0' <= s[idx] && s[idx] <= '9'){
    res = res*10 + s[idx] - '0';
    idx++;
  }
  return res;
}

// <fact> = ‘(’ <expr> ‘)’ | <number> 
int fact(){ 
  int res; 
  if(s[idx] == '('){
    idx++; 
    res = expr();
    //assert( s[idx] == ')' ); 
    idx++;
  } 
  else{ 
    res = number(); 
  } 
  return res;
}


int main()
{
  int n;
  
  cin>>n;
  for(;n--;)
    {
      idx=0;
      cin>>s;
      cout << expr()<<endl;
    }
}

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

int main() {
  int n, cu = 0;
  cin >> n;
  int x[n];
  for(int i = 0; i < n; i++) {
    cin >> x[i];
    cu += x[i];
  }
  int p = cu / n + 1;
  int c = 0, pp = cu / n, cc = 0;
  for(int i = 0; i < n; i++) {
    c += (x[i] - p) * (x[i] - p);
    cc += (x[i] - pp) * (x[i] - pp);
  }
  cout << min(c, cc);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;


int main(){
	long long int r,a,b,x;
	long long int tmp;
	
	cin >> a >> b;
	
	x=a*b;
	
	if(a<b){
		tmp = a;
		a = b;
		b = tmp;
	}

	
	r = a % b;
	while(r!=0){
		a = b;
		b = r;
		r = a % b;
	}
	
	cout << x/b << endl;
	
	return 0;
}

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

int main(){
    int n,ans=0;
    cin>>n;
    vector<int> b(n);
    for(int i=0;i<n-1;i++) cin>>b[i];
    for(int i=0;i<n-2;i++){
        ans += min(b[i],b[i+1]);
    }
    ans += b[0]+b[n-2];
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> VI;
typedef vector<long long int> VLLI;
typedef vector<pair<int, int> > VPI;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll, ll> PLL;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

int main() {
    vector<string> map = {"pon", "pon", "hon", "bon", "hon", "hon", "pon", "hon", "pon", "hon"};
    int n;
    cin >> n;
    cout << map[n%10] << '\n';
}



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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vii;

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 GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };


// ────────────────────────────────────────────────────

int main() {
	int n; cin >> n;
	vi k(n), p(n);

	rep(i, n) {
		cin >> k[i] >> p[i];
	}

	rep(i, n) {
		if (k[i] % p[i] == 0) cout << p[i] << endl;
		else cout << k[i] % p[i] << endl;
	}
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1 << 30;

using namespace std;

using ll = long long;
using P = tuple<int, int>;
using iarr = valarray<int>;

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    if(a == b && b == c){
        cout << 1 << endl;
    }else if(a == b || b == c || c == a){
        cout << 2 << endl;
    }else{
        cout << 3 << endl;
    }

    return 0;
}



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

const int N = (int) 2e5 + 5;

int n;
long long a[N], s[N];

int main() {
	//freopen(".inp", "r", stdin); freopen(".out", "w", stdout);
	ios_base :: sync_with_stdio(false); cin.tie(NULL);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		a[i] -= i;
	}
	sort(a + 1, a + 1 + n);
	for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];
		if (n == 1) return cout << 0, 0;
	int mid = n / 2;
	long long ans = a[mid] * mid - s[mid] + s[n] - s[mid] - a[mid] * (n - mid);
	if (mid + 1 < n) {
		mid++; 
		ans = min(ans, a[mid] * mid - s[mid] + s[n] - s[mid] - a[mid] * (n - mid));
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
string a[100];
int dp[100][100],h,w;
const int inf=0x3f3f3f3f;
int main(){
	cin>>h>>w;
	for(int i=0;i<h;i++) cin>>a[i];
	dp[0][0]=(a[0][0]=='#');
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			if(i+j!=0)
			{
				dp[i][j]=inf;
				if(i>0) dp[i][j]=min(dp[i][j],dp[i-1][j]+(a[i][j]=='#'&&a[i-1][j]=='.'));
				if(j>0) dp[i][j]=min(dp[i][j],dp[i][j-1]+(a[i][j]=='#'&&a[i][j-1]=='.'));
			}
	cout<<dp[h-1][w-1]<<endl;
	return 0;
}


Measured memory_bytes: 256
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
INF = 10**18

N=ri()
pri = [0]*101

for i in range(1,N+1):
    b = 2
    while b*b <= i:
        while i%b == 0:
            i //= b
            pri[b] += 1
        b += 1
    if i > 1:
        pri[i] += 1

exp = []
for i in range(101):
    if pri[i] > 0:
        exp += [pri[i] + 1]

exp.sort()
exp_len = len(exp)
import bisect
cnt_75 = exp_len - bisect.bisect_left(exp,75)
cnt_25 = exp_len - bisect.bisect_left(exp,25)
cnt_15 = exp_len - bisect.bisect_left(exp,15)
cnt_5 = exp_len - bisect.bisect_left(exp,5)
cnt_3 = exp_len - bisect.bisect_left(exp,3)
ans = 0

ans += cnt_75
ans += cnt_25*cnt_3 - cnt_25
ans += cnt_15*cnt_5 - cnt_15
ans += cnt_5*(cnt_5-1)/2*cnt_3 - cnt_5*(cnt_5-1)/2*2
ans = int(ans)

print(ans)




Measured memory_bytes: 3064
n=int(input())
s=input()
l=[chr(i) for i in range(65, 65+26)]
ln=[chr(65+i%26) for i in range(n, n+26)]
mydict={}
for i in range(26):
    mydict[l[i]]=ln[i]
print(s.translate(str.maketrans(mydict)))

Measured memory_bytes: 38384
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define LLIandI pair<long long int , int>
#define ll long long

int main(){
    int N,T;
    scanf("%d %d",&N,&T);
    int ans=1145141919;
    rep(i,N){
        int c,t;
        scanf("%d %d",&c,&t);
        if(t<=T)ans=min(ans,c);
    }
    if(ans<1002)printf("%d\n",ans);
    else printf("TLE\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
long long int dis[500][500];
long long int arr[500][500];
#define inf 1e15+7
int main()
{
    int n,m,l;
    cin>>n>>m>>l;
    long long int a,b,c;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(i==j)
            {
                dis[i][j]=0;
                arr[i][j]=0;
            }
            else
            {
                dis[i][j]=inf;
                arr[i][j]=inf;
            }
        }
    }
    for(int i=0;i<m;i++)
    {
        cin>>a>>b>>c;
        dis[a][b]=c;
        dis[b][a]=c;
    }
    for(int k=1;k<=n;k++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                if(dis[i][j]> dis[i][k]+dis[k][j]) dis[i][j]=dis[i][k]+dis[k][j];
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(dis[i][j]<=l && i!=j) arr[i][j]=1;
        }
    }
    for(int k=1;k<=n;k++)
    {
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
              arr[i][j]=min(arr[i][j],arr[i][k]+arr[k][j]);
            }
        }
    }
    int q;
    cin>>q;
    int ss,tt;
    while(q--)
    {
        cin>>ss>>tt;
        if(arr[ss][tt]>=inf) cout<<"-1"<<endl;
        else cout<<arr[ss][tt]-1<<endl;
    }

}


Measured memory_bytes: 2816
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        try {
            String[] str = br.readLine().split(" ");
            int[] ary = new int[str.length];
            for(int i = 0; i < ary.length; i++) {
                ary[i] = Integer.parseInt(str[i]);
            }
            Arrays.sort(ary);
            for(int i = 0; i < ary.length; i++) {
                if(i > 0) {
                    System.out.print(" ");
                }
                System.out.print(ary[i]);
            }
            System.out.println();
        } catch(IOException e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 16896
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int n;
    cin >> n;

    vector<int> p(n),q(n);
    for(auto &x:p)cin >> x;
    for(auto &x:q)cin >> x;

    vector<int> perm(n,0);
    for(int i=0;i<n;i++){
        perm[i]=i;
    }

    int a=-1,b=-1;
    int count=1;
    do{
        if(a!=-1 && b!=-1)break;

        for(int i=0;i<n;i++){
            if(a!=-1)break;
            if(p[i]!=perm[i]+1)break;
            if(i==n-1)a=count;
        }
        for(int i=0;i<n;i++){
            if(b!=-1)break;
            if(q[i]!=perm[i]+1)break;
            if(i==n-1)b=count;
        }

        count++;
    }while(next_permutation(perm.begin(),perm.end()));

    cout << abs(a-b) << endl;

    return 0;
}


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

int main(){
  int64_t N;
  cin >> N;
  int64_t l = int(sqrt(N));
  int64_t sum = pow(10,12) + 500;
  for(int i = 1; i <= l; i++){
    if(N % i == 0){
      sum = min((N/i) + i, sum);
    }
  }
  cout << sum - 2 << endl;
}

Measured memory_bytes: 256