akhauriyash/Code-Regression huggingface dataset:
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
int  main(){
	// #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
	ll n,a,b,c,d,e;
	cin>>n>>a>>b>>c>>d>>e;
	vector<ll>v(5);
	v[0]=ceil(n/(long double)a);
	ll ma=v[0];
	ma=max(ma,(ll)ceil(n/(long double)b));
	v[1]=ma;
	ma=max(ma,(ll)ceil(n/(long double)c));
	v[2]=ma;
	ma=max(ma,(ll)ceil(n/(long double)d));
	v[3]=ma;
	ma=max(ma,(ll)ceil(n/(long double)e));
	v[4]=ma;
	cout<<v[4]+4<<endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int[] H = new int[N];
		for (int i = 0; i < N; ++i) {
			H[i] = sc.nextInt();
		}
		
		int result = 0;
		int i = 0;
		int temp = 0;
		while(i < N - 1) {
			if (H[i] >= H[i+1]) {
				temp++;
			} else {
				result = Math.max(result, temp);
				temp = 0;
			}
			i++;
		}
      result = Math.max(result, temp);
		
		System.out.println(result);
		
	}
	
	private static int kaijo(int x) {
		int result = 1;
		for(int i = 1; i <= x; ++i) result *= 2;
		return result;
	}

}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


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

int main() {
  string a, b;
  cin >> a >> b;
  
  if (a == "H" && b == "H") cout << "H"  << endl;
  else if (a == "D" && b == "D") cout << "H"  << endl;
  else cout << "D"  << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n;
  cin>>n;
  int ans=0;
  for(int i=0; i<n; i++){
    int a;
    cin>>a;
    while(a%2==0){
      ans++;
      a/=2;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>

int n;
long long int a[3000];
long long int dp[3001][3002][2];
bool check[3001][3002][2];
long long int f();
long long int max(long long int a, long long int b){
    return (a >= b) ? a : b;
}
long long int min(long long int a, long long int b){
    return (a <= b) ? a : b;
}

int main(int argc, char const *argv[])
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%lld", &a[i]);
    }
    for (int i = 0; i < 3001; i++)
    {
        for (int j = 0; j < 3002; j++)
        {
            for (int k = 0; k < 2; k++)
            {
                dp[i][j][k] = 0;
                check[i][j][k] = (i == j) ? true : false;
            }
            
        }
        
    }
    printf("%lld\n", f(0, n, 0));

    return 0;
}

long long int f(int left, int right, int tern)
{
    long long int tmp;    
    if (check[left][right][tern])
        return dp[left][right][tern];
    check[left][right][tern] = true;
    if(tern == 0){
        tmp = max(f(left + 1, right, tern ^ 1) + a[left], f(left, right - 1, tern ^ 1) + a[right - 1]);
    } else {

        tmp = min(f(left + 1, right, tern ^ 1) - a[left], f(left, right - 1, tern ^ 1) - a[right - 1]);
        
    }
    dp[left][right][tern] = tmp;
    return tmp;
}

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

int main() {
    string S; cin >> S;
    int N = S.size();
    int ans = 999;
    for(int i = 0; i <= N - 3; i++){
        int num;
        num = ((S[i] - '0') * 100 + (S[i+1] - '0') * 10 + (S[i+2] - '0'));
        ans  = min(ans,abs(num-753));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
# ボールAとボールBをN個の箱に入れる
# A,Bを1つずつ同じ箱に入れることがあってもよい。
# まずAをN個の箱に1つずつ入れる
# その上で、BをN個の箱に1つずつ入れる（すでにAが入っているかどうか、区別する必要がない）
# AとBの個数の組み合わせを列挙し、そのすべてについて(N C (Aの個数)) * (N C (Bの個数))を計算した和が答え

import sys
readline = sys.stdin.readline

N,A,B,K = map(int,readline().split())

DIV = 998244353
n = (10 ** 6) * 2 # PyPyじゃないと通らない。 * 5が限界くらい
g1 = [1] * 2 + [0] * (n - 2) # 元テーブル
g2 = [1] * 2 + [0] * (n - 2) #逆元テーブル
inverse = [0, 1] + [0] * (n - 2) #逆元テーブル計算用テーブル

for i in range(2, n):
  g1[i] = (g1[i - 1] * i) % DIV
  inverse[i] = (-inverse[DIV % i] * (DIV // i)) % DIV
  g2[i] = (g2[i - 1] * inverse[i]) % DIV

def nCr(n, r, DIV):
  if (r < 0 or r > n):
    return 0
  r = min(r, n-r)
  return g1[n] * g2[r] * g2[n-r] % DIV

# AとBを足してKになる組み合わせを探索する
ans = 0
for a in range(N + 1):
  rest = K - a * A
  if rest < 0:
    break # a * Aの時点で負の数。これ以上の探索も不要。
  if rest % B != 0:
    continue # 組み合わせを作れない
  b = rest // B
  if b > N:
    continue # 箱に入れられない
  # この時点で、Aがa個とBがb個で作れることが確定する
  # (N C (Aの個数)) * (N C (Bの個数))
  ans += (nCr(N, a, DIV) * nCr(N, b, DIV)) % DIV
  ans %= DIV
  
print(ans)


Measured memory_bytes: 171948
import java.io.*;

public class Main {

  public static void main(String[] args) throws IOException {
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
      String[] numbers = reader.readLine().split(" ");
      int h = Integer.parseInt(numbers[0]);
      int w = Integer.parseInt(numbers[1]);
      int a = h * w;
      int c = (h*2) + (w*2);
      System.out.println(String.format("%s %s", a, c));
    }
  }
}

Measured memory_bytes: 24488
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
using namespace std;
typedef long long ll;
int main() {
  std::cout << std::fixed << std::setprecision(10);
  int N, K;
  cin >> N >> K;

  double p = 0;
  FOR(i, 1, N + 1) {
    int now = i;
    double tmp = 1.0 / N;
    while (now < K) {
      now *= 2;
      tmp /= 2;
    }
    p += tmp;
  }
  cout << p;
  return 0;
}

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

int main() {
	string s, t;
	cin >> s >> t;
	for (int i = s.length() - t.length(); i >= 0; i--) {
		string ss = s.substr(i, t.length());
		bool ac = true;
		for (int j = 0; j < t.length(); j++) {
			if (ss.at(j) != t.at(j)) {
				if (ss.at(j) != '?')ac = false;
			}
		}
		if (ac) {
			s = s.substr(0, i) + t + s.substr(i + t.length());
			for (int j = 0; j < s.length(); j++) {
				if (s.at(j) == '?')s.at(j) = 'a';
			}
			cout << s << endl;
			return 0;
		}
	}
	cout << "UNRESTORABLE" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N - 1);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++) {
    cin >> B.at(i);
  }
  for (int i = 0; i < N - 1; i++) {
    cin >> C.at(i);
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += B.at(A.at(i) - 1);
  }
  for (int i = 0; i < N - 1; i++) {
    if (A.at(i) + 1 == A.at(i + 1)) {
      ans += C.at(A.at(i) - 1);
    }
  }
  cout << ans << endl;
}

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

#define MOD 1000000007

using namespace std;

string replace_with_str(string str, string str_from, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(str_from, pos), pos != string::npos) {
        str.replace(pos, str_from.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main(int argc, char const *argv[]){
    unsigned long ans = 0;
    int N, K;
    cin >> N >> K;

    if(N == 1){
        printf("%d\n",K);
        return 0;
    }

    ans = K * pow((K-1), (N-1));
    printf("%lu\n", ans);
    return 0;
}

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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int a, b; cin >> a >> b;
    int k; cin >> k;

    REP(i, k) {
        if (i % 2 == 0) {
            if (a % 2) {
                a--;
                b += a / 2;
                a /= 2;
            } else {
                b += a / 2;
                a /= 2;
            }
        } else {
            if (b % 2) {
                b--;
                a += b / 2;
                b /= 2;
            } else {
                a += b / 2;
                b /= 2;
            }
        }
    }

    cout << a << ' ' << b << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int x,y;
int main()
{
	scanf("%d%d",&x,&y);
	if(x==y) puts("0");
	else if(y>x) printf("%d\n",min(y-x,abs(y+x)+1));
	else printf("%d\n",min(abs(x+y)+1,2+abs(x-y)));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

vector<int> zalgorithm(const string &S) {
    // return Z[i]: the length of common string between S & S[i:]
    int N = (int)S.size();
    vector<int> Z(N, 0);
    Z[0] = N;
    int i = 1;
    int j = 0;
    while (i < N) {
        while (i + j < N && S[j] == S[i + j]) {
            j++;
        }
        Z[i] = j;
        if (j == 0) {
            i++;
        } else {
            int k = 1;
            while (i + k < N && k + Z[k] < j) {
                Z[i + k] = Z[k];
                k++;
            }
            i += k;
            j -= k;
        }
    }
    return Z;
}

int main() {
    int N;
    cin >> N;
    string str;
    cin >> str;
    int ans = 0;
    REP(i, N) {
        string S = str.substr(i, N - i);
        vector<int> A = zalgorithm(S);
        int n = S.size();
        REP(j, n) {

            int len = A[j];
            chmin(len, j);
            chmax(ans, len);
        }
    }

    cout << ans << endl;
    return 0;
}


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

int main(){
  int n, t, a, h, ans;
  double anst = 1000000;

  cin >> n >> t >> a;

  for(int i=0; i<n; ++i){
    cin >> h;
    if(anst > abs(a - (t - h*0.006))){
      ans = i+1;
      anst = abs(a - (t - h*0.006));
    }
  }

  cout << ans << endl;
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 2e3 + 5;

int n;
int g[MAXN][MAXN];
int ans[MAXN][MAXN], top_ans[MAXN];
int used[MAXN];
int v[MAXN];

int tmp[MAXN], tmp_top;

void dfs(int s){
	used[s] = 1;
	ans[s][top_ans[s]++] = s;
	REPN(i, 1, n){
		if (g[s][i] && !used[i]){
			dfs(i);
			REPN(j, 1, top_ans[s]){
				tmp[j] = ans[s][j];
			}
			tmp_top = top_ans[s];
			top_ans[s] = 1;
			for(int i1 = 0, i2 = 1; i1 < top_ans[i] || i2 < tmp_top; ){
				if (i1 == top_ans[i] || i2 < tmp_top && tmp[i2] > ans[i][i1]){
					ans[s][top_ans[s]++] = tmp[i2++];
				} else {
					ans[s][top_ans[s]++] = ans[i][i1++];
				}
			}
		}
	}
}

void solve(){
	scanf("%d", &n);
	REPN(i, 1, n){
		scanf("%d", &v[i]);
	}
	sort(v + 1, v + n + 1);
	REPN(i, 1, n){
		g[0][i] = 1;
		REPN(j, i + 1, n){
			if (gcd(v[i], v[j]) > 1){
				g[i][j] = g[j][i] = 1;
			}
		}
	}
	dfs(0);
	REPN(i, 1, n){
		printf("%d ", v[ans[0][i]]);
	}
	putchar('\n');
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 31744
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int a[] = new int[n];
		int count = 0;
		int x = Integer.MAX_VALUE;

		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
		}

		for(int i=0;i<n;i++) {
			x=Math.min(x, a[i]);
			if(x==a[i]) {
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 64568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;



int main()
{
	int w,h,n,a,b,c,l,r,u,d;
	cin>>w>>h>>n;
	l=0,r=w,u=h,d=0;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b>>c;
		if(c==1)l=max(a,l);
		else if(c==2)r=min(a,r);
		else if(c==3)d=max(b,d);
		else u=min(b,u);
	}
	if(l<r&&d<u)cout<<(r-l)*(u-d)<<endl;
	else cout<<0<<endl;
	return 0;
}

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

string a,b="CF";
int al,bl;

int main()
{
    getline(cin,a);
    al=a.length();
    for(int i=0;i<al;i++)
        if(a[i]==b[bl]){
            bl++;
            if(bl==2)
                break;
        }
    if(bl==2) cout<<"Yes";
    else cout<<"No";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll ans[110][110];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	vector<ll>c(n - 1), s(n - 1), f(n - 1);
	rep(i, n - 1) {
		cin >> c[i] >> s[i] >> f[i];
	}
	rep(i, n - 1) {
		ll time = s[i] + c[i];
		for (ll j = i + 1;j < n - 1;++j) {
			if (time <= s[j]) {
				time = s[j];
			}
			else {
				time = s[j] + (time - s[j] + f[j] - 1) / f[j] * f[j];
			}
			time += c[j];
		}
		cout << time << endl;
	}
	cout << 0 << endl;
	return 0;
}


Measured memory_bytes: 3628
import java.util.*

fun main(args: Array<String>) {
    val (MAX_Y, MAX_X) = readLine()!!.split(" ").map(String::toInt)
    val (SY, SX) = 0 to 0
    val (GY, GX) = MAX_Y - 1 to MAX_X - 1
    val array = Array(MAX_Y) {
        readLine()!!.toCharArray()
    }

    val INF = Integer.MAX_VALUE

    val dx = intArrayOf(1, 0, -1, 0)
    val dy = intArrayOf(0, 1, 0, -1)


    fun bfs(): Int {
        val d = Array(MAX_Y) {
            IntArray(MAX_X) { INF }
        }
        val queue: Queue<Pair<Int, Int>> = ArrayDeque()

        queue.add(SX to SY)
        d[SY][SX] = 0

        while (queue.isNotEmpty()) {
            val (x, y) = queue.poll()

            if (x == GX && y == GY) {
//                println("x:$x , y:$y")
                break
            }

            for (i in 0..3) {
                val nx = x + dx[i]
                val ny = y + dy[i]
//                println("nx:$nx , ny:$ny")

                if (nx in 0 until MAX_X && ny in 0 until MAX_Y && array[ny][nx] != '#' && d[ny][nx] == INF) {
                    queue.add(nx to ny)
                    d[ny][nx] = d[y][x] + 1
                }
            }
//            d.joinToString(System.lineSeparator()) {
//                it.map { if (it == INF) -1 else it }
//                    .map { "%3d".format(it) }
//                    .joinToString { it }
//            }.let(::println)

        }
        return d[GY][GX]
    }


    val moveCount = bfs()
    if (moveCount == INF) {
        println(-1)
        return
    }

    println(MAX_X * MAX_Y - array.map { it.count { it == '#' } }.sum() - (moveCount + 1))

}



Measured memory_bytes: 37892
N = int(input())
A = list(map(int,input().split()))
lgcd = [0]*N
rgcd = [0]*N
from fractions import gcd
#def gcd(a,b):
#    if b == 0:return a
#    else:return gcd(b, a%b)

temp_lgcd = A[0]
for i in range(N):
    temp_lgcd = gcd(temp_lgcd,A[i])
    lgcd[i] = temp_lgcd

temp_rgcd = A[-1]
for i in range(N-1,-1,-1):
    temp_rgcd = gcd(temp_rgcd,A[i])
    rgcd[i] = temp_rgcd

ans = 0
for i in range(N):
    if i == 0:
        calc_gcd = rgcd[1]
    elif i == N-1:
        calc_gcd = lgcd[-2]
    else:
        calc_gcd = gcd(lgcd[i-1],rgcd[i+1])
    ans = max(ans,calc_gcd)
print(ans)

Measured memory_bytes: 14584
using System;
using System.Collections.Generic;

class main
{
	static void Main(string[] args)
	{
		int N = Int(Str());

		int ans = N % 1000;
		if(ans != 0)
		{
			ans = 1000 - ans;
		}
		Console.WriteLine(ans);
		Console.ReadLine();
	}

	static string Str()
	{
		return Console.ReadLine().Trim();
	}
	static string[] StrArr()
	{
		return Console.ReadLine().Trim().Split(' ');
	}
	static int[] IntArr()
	{
		string[] strArr = StrArr();
		int len = strArr.Length;

		int[] intArr = new int[len];
		for(int i = 0;i < len; i++)
		{
			intArr[i] = Int(strArr[i]);
		}

		return intArr;
	}

	static int Int(string Str)
	{
		return int.Parse(Str);
	}
}



Measured memory_bytes: 27540
N, M = [int(x) for x in input().split()]

P = [0] * (N + 1)           #各問題のペナルティの回数を記録
ok = [False] * (N + 1)      #その問題でACが出たかどうか記録

correct = 0                 #正答数を記録
penalty = 0                 #ペナルティ数を記録
for i in range(M):
    query = input().split()
    p = int(query[0])
    S = query[1]
    if ok[p] == False:
        if S == 'AC':
            ok[p] = True
            correct += 1
            penalty += P[p]
        else: # S = 'WA'
            P[p] += 1

print(correct, end=' ')
print(penalty)

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

int main(){
  ll a,b,k;
  cin >> a >> b >> k;
  if(a >= k) cout << a-k << ' ' << b << endl;
  else if(a < k && a+b >= k) cout << 0 << ' ' << b-(k-a) << endl;
  else cout << 0 << ' ' << 0 << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb                      push_back
#define MOD                     1000000007
#define endl                    "\n"

using namespace std;	
int main() {

	  int n;
	  cin>>n;
	  int arr[n][3];
	  for(int i=0;i<n;i++)
	  {
	  	for(int j=0;j<3;j++)
        {
          cin>>arr[i][j];
        }
      }
  int dp[n][3];
  for(int j=0;j<3;j++)
    dp[0][j]= arr[0][j];
  for(int i=1;i<n;i++)
  {
    dp[i][0]= max(dp[i-1][1],dp[i-1][2])+arr[i][0];
     dp[i][1]= max(dp[i-1][0],dp[i-1][2])+arr[i][1];
     dp[i][2]= max(dp[i-1][1],dp[i-1][0])+arr[i][2];
    
  } int maxi = INT_MIN;
  for(int j=0;j<3;j++)
    maxi = max(maxi,dp[n-1][j]);
  cout<<maxi<<endl;
	}


Measured memory_bytes: 5968
#include <stdio.h>

int
main(int argc, char *argv[])
{
        int H, W;
        int i, j;

        while (scanf("%d %d", &H, &W), (H != 0) || (W != 0)) {
                for (i = 0; i < H; i++) {
                        for(j = 0; j < W; j++)
                                if (i == 0 || i == H - 1)
                                        printf("#");
                                else if (j == 0 || j == W - 1)
                                        printf("#");
                                else
                                        printf(".");
                        printf("\n");
                }
                printf("\n");
        }
        return 0;
}

Measured memory_bytes: 572
a, b = map(int, input().split())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    divisors.sort()
    return divisors


i_min = min(a, b)
i_max = max(a, b)

yaku_list = make_divisors(i_min)

kouyaku_list = []
for i in yaku_list:
    if i_max % i == 0:
        kouyaku_list.append(i)

for i in range(len(kouyaku_list) - 1):
    if kouyaku_list[i] == 1:
        continue
    if kouyaku_list[i] != -1:
        for j in range(i + 1, len(kouyaku_list)):
            if kouyaku_list[j] % kouyaku_list[i] == 0:
                kouyaku_list[j] = -1

print(len(kouyaku_list) - kouyaku_list.count(-1))


Measured memory_bytes: 39536
#include<bits/stdc++.h>
using namespace std;
int q, n, p,res;
vector<int> t(3);
int f(int i, int j, int k){
    
    if(i!=j && i!=j && j!=k)return 6;
    t[0] = i;
    t[1] = j;
    t[2] = k;
    sort(t.begin(), t.end());
    if(t[0] == t[2])return 1;
    if(t[0] == t[1] || t[1] == t[2])return 3;
    
}
int main(){
    
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
  
    
    
    n = 10000;
    cin>>n;
    vector<int> a(n+1, 0);
    for(int i=1;i<=n;i++){
        for(int j=i;j<=n;j++){
            if(i*i+j*j+i*j>n)break;
            for(int k=j;k<=n;k++){
                int t = i*i+j*j+k*k+i*k+i*j+k*j;
                if(t>n)break;
                if(t <= n){
                    a[t] += f(i, j, k);
                }
                
            }
        }
    }
    for(int i=1;i<=n;i++)
        cout<<a[i]<<'\n';

}

Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}


ll n, k[100005];
int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> k[i];
	}
	--k[0];
	for (int i = 1; i < n; ++i) {
		if (k[i] > k[i - 1]) { --k[i]; }
	}


	for (int i = 1; i < n; ++i) {
		if (k[i] < k[i - 1]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;


}


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

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

Measured memory_bytes: 256
import sys
flag = 1
f_month={}
n_month={}
for line in sys.stdin:
    if line == '\n':
	flag = 0
    elif flag==1:
        temp = map(int,line.split(","))
	if temp[0] in f_month:
            f_month[temp[0]] = f_month[temp[0]]+1
	else:
            f_month[temp[0]] = 1
    else:
	temp = map(int,line.split(","))
	if temp[0] in f_month:
            if temp[0] in n_month:
		n_month[temp[0]] = n_month[temp[0]]+1
    	    else:
		n_month[temp[0]] = f_month[temp[0]]+1
for k, v in sorted(n_month.items()):
    print k, v

Measured memory_bytes: 4248
let split str delim =
  let rec doit s acc =
    match
      try Some (String.index s delim)
      with _ -> None
    with
    | None -> s :: acc
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s2 (s1 :: acc)
  in
  List.rev (doit str [])

let () =
  let l = read_line () in
  match List.map int_of_string (split l ' ') with
  | [] | [_] | _::_::[] -> exit 1
  | n :: m :: l :: _ ->
      let a = Array.make_matrix n m 0 in
      let b = Array.make_matrix m l 0 in
      for i = 1 to n do
        let row = read_line () in
        let row = Array.of_list (List.map int_of_string (split row ' ')) in
        for j = 1 to m do
          a.(i-1).(j-1) <- row.(j-1)
        done;
      done;
      for i = 1 to m do
        let row = read_line () in
        let row = Array.of_list (List.map int_of_string (split row ' ')) in
        for j = 1 to l do
          b.(i-1).(j-1) <- row.(j-1)
        done;
      done;
      for i = 1 to n do
        for j = 1 to l do
          let c = ref 0 in
          for k = 1 to m do
            c := !c + a.(i-1).(k-1) * b.(k-1).(j-1)
          done;
          if j = 1 then Printf.printf "%d" !c
          else Printf.printf " %d" !c
        done;
        print_newline ();
      done

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

int main(){
    vector<int> vec;
    int s;

    for(int i = 0; i < 5; i++){
        cin >> s;
        vec.push_back(s);
    }


    for(int i = 0; i < 5; i++){
        if(vec[i] == 0){
            cout << i + 1<< endl; 
            break;
        }
    }

}

Measured memory_bytes: 3592
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
//#include<unordered_map>
using namespace std;
#define ll long long
#define dd cout<<endl
const long long int inf = 1e18+7;
const int mod = 998244353;

using namespace std;

inline ll int max(ll int a,ll int b) { return a>b?a:b; }
inline ll int min(ll int a,ll int b) { return a<b?a:b; }

const int maxn=1e7+10;

bool vis[maxn];
int prime[maxn];

int t[maxn],e[maxn];

inline void pre(int n)
{
	int cnt=0;
    t[1]=1;
    for(int i=2;i<=n;++i)
    {
        if(!vis[i])
        {
            prime[++cnt]=i;
            t[i]=2;
            e[i]=1;
        }
        for(int j=1;j<=cnt;++j)
        {
            if(i*prime[j]>n) break;
            vis[i*prime[j]]=true;
            if(i%prime[j]==0)
            {
                t[i*prime[j]]=t[i]/(e[i]+1)*(e[i]+2);
                e[i*prime[j]]=e[i]+1;
                break;
            }
            else 
            {
                t[i*prime[j]]=t[i]*2;
                e[i*prime[j]]=1;
            }
        }
    }
}

int main()
{
	int n;
	
	scanf("%d",&n);
	
	pre(n+5);
	
	ll int ans=0;
	
	for(int i=1;i<=n;i++)
	{
		ans+=1LL*i*t[i];
	}
	
	printf("%lld\n",ans);
	
	return 0;
}

Measured memory_bytes: 94252
#include <iostream>
#include <map>

using namespace std;

#define repd(i, a, b) for(int i=a; i<b; i++)
#define rep(i, a) repd(i, 0, a)
#define ll long long 

int main(){
  int n;
  cin >> n;
  map<int, int> mp;
  rep(i, n){
    int a;
    cin >> a;
    mp[a]++;
  }
  ll ans = 0;
  for(auto m: mp){
    if(m.first <= m.second){
      ans += m.second - m.first;
    }else{
      ans += m.second;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4736
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
vector<int>E[1010];
int n,m,b[200020][2];
bool vis[1010],f[200020][2];
int q[1010],h,t,l[1010],r[1010];
int st[1010],tp;
void work(int v)
{
	tp=0;
	for(auto u:E[v])st[++tp]=u;
	int x,y;
	memset(vis+1,0,n);vis[v]=1;
	for(int i=1;i<=tp;++i)
		if(!vis[x=st[i]])
		{
			h=0,t=1,q[t]=x,vis[x]=1,l[x]=i;
			while(h<t)
			{
				x=q[++h];
				for(auto y:E[x])if(!vis[y])vis[y]=1,q[++t]=y,l[y]=i;
			}
		}
	memset(vis+1,0,n);vis[v]=1;
	for(int i=tp;i;--i)
		if(!vis[x=st[i]])
		{
			h=0,t=1,q[t]=x,vis[x]=1,r[x]=i;
			while(h<t)
			{
				x=q[++h];
				for(auto y:E[x])if(!vis[y])vis[y]=1,q[++t]=y,r[y]=i;
			}
		}
	for(int i=1;i<=m;++i)if(b[i][0]==v)f[i][0]=l[b[i][1]]!=r[b[i][1]];
}
int main()
{
	scanf("%d %d",&n,&m);
	int x,y;
	for(int i=1;i<=m;++i)scanf("%d %d",&x,&y),E[x].emplace_back(y),b[i][0]=x,b[i][1]=y;
	for(int i=1;i<=n;++i)
	{
		memset(vis+1,0,n);h=0,t=1;q[t]=i;vis[i]=1;
		while(h<t)
		{
			x=q[++h];
			for(auto y:E[x])if(!vis[y])vis[y]=1,q[++t]=y;
		}
		for(int j=1;j<=m;++j)if(b[j][1]==i)f[j][1]=vis[b[j][0]];
	}
	for(int i=1;i<=n;++i)work(i);
	for(int i=1;i<=m;++i)
		if(f[i][0]!=f[i][1])printf("diff\n");
		else printf("same\n");
	return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
using namespace std;
int main(void){
    int N;
    cin>>N;
    int L[N];
    for(int i=0;i<N;i++){
        cin>>L[i];
    }
    int max=L[0];
    for(int i=0;i<N;i++){
       if(max<L[i]){max=L[i];}
    }
    int sum=0;
    for(int i=0;i<N;i++){
        sum+=L[i];
    }
    sum-=max;
    if(sum>max){cout<<"Yes";}
    else {cout<<"No";}
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
#define MOD 1000000007
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))

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

	char s[4];
	cin>>s;
	sort(s, s+4);
	if(s[0]==s[1] && s[2]==s[3] && s[2]!=s[1])
		cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 256
#pragma comment (linker, "/STACK:256000000")
#define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()
void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(100);
}
#define int ll
void solve(){
	int n, k, s;
	cin >> n >> k >> s;
	int fail = s + 1;
	if (fail >= 1e6) fail = s - 2;
	REP(i, k) {
		cout << s << " ";
	}
	REP(i, n - k) {
		cout << fail << " ";
	}
	cout << endl;
}

#undef int

int main() {
	init();
	solve();
}


Measured memory_bytes: 1280
#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=1; i<=(n); ++i)
#define drep(i,n) for(int i=(n)-1; i>=0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define v(T) vector<T>
#define imposs {cout<<"-1\n";return 0;}
#define LL_MAX LLONG_MAX
#define LL_MIN LLONG_MIN

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef set<int> si;
typedef multiset<int> msi;
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

int n, m, q;
int a[50], b[50], c[50], d[50];

int A[11];
int ans;

void solve(int i) {
  if (i == n) {
    int score = 0;
    rep(j,q)if(A[b[j]-1] - A[a[j]-1] == c[j]) score += d[j];
    ans = max(ans, score);
    return;
  }
  int s = 1;
  if (i>0) s = A[i-1];
  for (int j=s; j<=m; ++j) {
    A[i] = j;
    solve(i+1);
  }
  return;
}

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

  cin >> n >> m >> q;
  rep(i,q) cin >> a[i] >> b[i] >> c[i] >> d[i];
  ans = 0;
  solve(0);
  cout << ans << '\n';
  return 0;
}


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

int main(){
  int x,n;
  cin>>x>>n;
  vector<int>a(101);
  vector<int>b(101);
  
  for(int i=1;i<=n;i++){
    cin>>a[i];
    b[a[i]]++;
  }
  
  int ans;
  
  for(int i=0;i<=100;i++){
    if(!b[x-i]){
      ans=x-i;
      break;
    }
    else if(!b[x+i]){
      ans=x+i;
      break;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3636
using System;

namespace ALDS1_4_B_binary_
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            string[] S = getsplit();
            int[] s2 = Array.ConvertAll(S, int.Parse);            
            Console.ReadLine();
            string[] T = getsplit();
            int count=0;

            foreach (var t in T)
                if (BinarySearch(s2, getint(t)))
                    count++;

            Console.WriteLine(count);
        }

        public static string[] getsplit()
        {
            string[] x = Console.ReadLine().Split(' ');
            return x;
        }
        public static int getint(string a)
        {

            if (a == null || a.Length == 0)
            {
                int x = int.Parse(Console.ReadLine());
                return x;
            }
            else
            {
                int x = int.Parse(a);
                return x;
            }
        }

        static bool BinarySearch(int[] a,int key)
         {
            int left = 0;
            int right = a.Length;

            while (left<right)
            {
                int mid = (left + right) / 2;
                if (a[mid] == key)
                {
                    return true;
                }
                else if (key < a[mid])
                {
                    right = mid;
                }
                else
                {
                    left = mid + 1;
                }
            }
            return false;
         }
    }
}

Measured memory_bytes: 18848
#include<iostream>
#include<vector>
#include<stack>
#define MAX 999999
#define NIL -1
using namespace std;


int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r,int c)
{
  stack<int> s;
  s.push(r);
  color[r]=c;
  
  while(!s.empty())
    {
      int u=s.top(); s.pop();
      for(int i=0;i<G[u].size();i++)
	{
	  int v=G[u][i];
	  if(color[v]==NIL)
	    {
	      color[v]=c;
	      s.push(v);
	    }
	}
    }
}

void assign()
{
  int id=1;

  
  for(int i=0;i<n;i++) color[i]=NIL;
  for(int u=0;u<n;u++)
    {
      if(color[u] == NIL)  dfs(u,id++);
    }
}



int main(){

  
  int s,t,m,q;

  cin>>n>>m;

  for(int i=0;i<m;i++)
    {
      cin>>s>>t;
      G[s].push_back(t);
      G[t].push_back(s);
    }

  assign();

  cin >> q;

  for(int i=0;i<q;i++)
    {
      cin>>s>>t;
      if(color[s]==color[t])
	{
	  cout << "yes" << endl;
	}
      else{
	  cout << "no" <<endl;
	}
    }

  return 0;
}



Measured memory_bytes: 30104
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<functional>
#include<map>
#include<unordered_set>
using namespace std;
//int p = 998244353;
int p = 1000000007;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define rep(i,n) for(int i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define qin pair<int,pin>
#define V vector
#define Endl endl
#define veb vector<bool>
#define rev(s) reverse(s.begin(),s.end())
int max_kai = 150000;
vel kai(max_kai, 1);
vel inv_kai;
int rui(int a, int n) {
	if (n == 0) { return 1; }
	int x = rui(a, n / 2);
	x *= x; x %= p;
	if (n % 2 == 1) { x *= a; x %= p; }
	return x;
}
int inv(int a) { return rui(a, p - 2); }
void make_kai() {
	for (int i = 1; i < max_kai; i++) { kai[i] = kai[i - 1] * i; kai[i] %= p; }
	inv_kai = kai;
	rep(i, max_kai) { inv_kai[i] = inv(kai[i]); }
}
int nCr(int n, int r) {
	int a = kai[n] * inv_kai[r]; a %= p;
	a *= inv_kai[n - r]; a %= p;
	return a;
}
vel pa;
int root(int x) {
	if (pa[x] == -1) { return x; }
	int ans = root(pa[x]); pa[x] = ans;
	return ans;
}
void marge(int x, int y) {
	x = root(x);
	y = root(y);
	if (x != y) {pa[x] = y;}
}
#define lower(h,val) lower_bound(h.begin(),h.end(),val)-h.begin()
#define upper(h,val) upper_bound(h.begin(),h.end(),val)-h.begin()
int num_lp(int a, vel &nex) {
	unordered_set<int> se;
	int ans = 0;
	while (true) {
		if (se.find(a) != se.end()) {
			break;
		}
		se.insert(a);
		a = nex[a];
		ans++;
	}
	return ans;
}
int find_cr(int a, vel &nex) {
	unordered_set<int> se;
	while (true) {
		if (se.find(a) != se.end()) {break;}
		se.insert(a);
		a = nex[a];
	}
	return num_lp(a, nex);
}
int inf = 2000000000;
vvel dp;
int solve(vvel &sum, int i, int j, bool is_f) {
	int h = sum.size(); h--;
	int w = sum[0].size();
	if (i == h || j == w) { return 0; }
	if (dp[i][j] == inf) {
		int ans1 = solve(sum, i + 1, j, !is_f);
		int ans2 = solve(sum, i, j + 1, !is_f);
		ans2 += sum[i][j];
		if (is_f) {
			dp[i][j] = min(ans1, ans2);
		}
		else {
			dp[i][j] = max(ans1, ans2);
		}
	}
	return dp[i][j];
}
int rui10(int a) {
	if (a == 0) { return 1; }
	return 10 * rui10(a - 1);
}
int gcd(int a, int b) {
	if (a < b) { swap(a, b); }
	if (b == 0) { return a; }
	return gcd(b, a%b);
}
vel mul(vel &a, vel &b) {
	int n = a.size();
	vel c(n,-1);
	rep(i, n) {
		rep(j, n) {
			if (a[i] >= 0 && b[j] >= 0) {
				mmax(c[(i + j) % n], a[i] + b[j]);
			}
		}
	}
	return c;
}
vel rui(vel &a, int n) {
	if (n == 1) { return a; }
	vel b = rui(a, n / 2);
	b = mul(b, b);
	if (n % 2 == 1) {
		b = mul(b, a);
	}
	return b;
}
signed main(){
	int n; cin >> n;
	rep(i, n) {
		int k, p; cin >> k >> p;
		if (k%p == 0) { cout << p << endl; }
		else { cout << k % p << endl; }
	}
	return 0;
}


Measured memory_bytes: 3716
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#define inf 0x3f3f3f3f
#define MN 10005
using namespace std;
inline int in(){
    int x=0;bool f=0;char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
struct st{
	int v,id;
}c[MN];
priority_queue<int,vector<int>,greater<int> >q;
int a[MN],t[MN];
int n,k,Q,mn;
int main()
{
	n=in();k=in();Q=in();mn=inf;
	for (int i=1;i<=n;++i) a[i]=in();
	for (int i=1;i<=n;++i){
		while (!q.empty()) q.pop();
		for (int hd=1,tl=0;hd<=n;hd=tl){
			for (;a[hd]<a[i]&&hd<=n;++hd);
			for (tl=hd;a[tl]>=a[i]&&tl<=n;++tl);
			if (tl-hd<k) continue;
			for (int j=hd;j<tl;++j) t[j-hd]=a[j];sort(t,t+tl-hd);
			for (int j=0;j<=tl-hd-k;++j) q.push(t[j]);
		}
		for (int j=1;j<Q;++j)
		if (q.empty()) continue;else q.pop();
		if (q.empty()) continue;
		int u=q.top();q.pop();mn=min(mn,u-a[i]);
	}printf("%d",mn);return 0;
}

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

void solve(std::string S)
{
    int cnt = 0;
    for (size_t i = 0; i < S.length(); i++)
    {
        if (S[i] == 'o')
        {
            cnt++;
        }
    }
    cout << 700 + 100 * cnt << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')

def main():
    N,K = MI()
    price_list = LI()
    price_list.sort()
    count = 0
    ans = 0
    for p in price_list:
        ans+=p
        count+=1
        if count == K:
            print(ans)
            break


if __name__ == '__main__':
    main()


Measured memory_bytes: 10968
import numpy as np

N, D = map(int, input().split())
table = [[int(i) for i in input().split()] for n in range(N)]

count = 0
for i in range(N):
    a = np.array(table[i])
    for j in range(i+1, N):
        b = np.array(table[j])
        u = b - a
        if np.linalg.norm(u).is_integer():
            count += 1

print(count)


Measured memory_bytes: 14436
import Control.Monad
import Control.Applicative
import Control.Exception
import Text.Parsec hiding ((<|>))

powm b 0 m r = r
powm b e m r | e `mod` 2 == 1 = powm (b * b `mod` m) (e `div` 2) m (r * b `mod` m)
powm b e m r = powm (b * b `mod` m) (e `div` 2) m r

solve p exp = fromRight $ parse expr "" exp
 where 
  fromRight (Right x) = x
  chr x y = char x *> pure y
  pf f x y = (x `f` y) `mod` p
  add = chr '+' $ pf (+)
  sub = chr '-' $ pf (-)
  mul = chr '*' $ pf (*)
  pdiv x 0 = throw DivideByZero
  pdiv x y = x * powm y (p-2) p 1 `mod` p
  div = chr '/' pdiv
  number = read <$> many1 digit
  par = between (char '(') (char ')')
  expr = chainl1 term (add <|> sub)
  term = chainl1 factor (mul <|> div)
  factor = number <|> par expr

main = do
 l <- getLine
 let (p,_:exp) = break (==':') l
 let p' = read p
 when (p' /= 0) $ do 
  let exp' = filter (/=' ') exp
  let s = exp' ++ " = " ++ show (solve p' exp') ++ " (mod " ++ p ++ ")"
  catch (putStrLn s)
   $ \DivideByZero -> putStrLn "NG"
  main

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

int main() {
   string s;
   cin >> s;
   int n = s.size();

   for(int i=0; i<n; i++) {
      if(s[i] != s[n-1-i]) {
         cout << "No" << endl;
         return 0;
      }
   }
   int m = (n-1) / 2;
   int l = (n+3) / 2;

   for(int i=0; i<m; i++) {
      if(s[i] != s[m-1-i]) {
         cout << "No" << endl;
         return 0;
      }
   }

   for(int i=l; i<n-l+1; i++) {
      if(s[l] != s[n-l-i+1]){
         cout << "No" << endl;
         return 0;
      }
   }
   cout << "Yes" << endl;
}

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

#define INF 1e9
using namespace std;

int main() {

    string S; cin >> S;

    bool ok = true;
    int c_count = 0;
    for (int i = 0; i < S.size(); ++i) {
        if (i == 0) {
            if (S[i] != 'A') {
                ok = false;
            }
            continue;
        }

        if (i >= 2 && i <= S.size()-2) {
            if (S[i] == 'C') {
                ++c_count;
            }
            continue;
        }

        if (!islower(S[i])) {
            ok = false;
            break;
        }
    }

    if (ok && c_count == 1) {
        puts("AC");
    } else {
        puts("WA");
    }
}

Measured memory_bytes: 256
A, B, C, D, E, F = map(int, input().split())
water = 1
sugar = -1
for w_a in range(0, F + 1, 100 * A):
    for w_b in range(0, F - w_a + 1, 100 * B):
        new_w = w_a + w_b
        if new_w == 0:
            continue
        G = min(F - new_w, new_w * E // 100)
        for s_c in range(0, G + 1, C):
            for s_d in range(0, G - s_c + 1, D):
                new_s = s_c + s_d
                if sugar * new_w < new_s * water:
                    water = new_w
                    sugar = new_s
print(water + sugar, sugar)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int read() {
	int q=0;char ch=' ';
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
	return q;
}
const int mod=1e9+7,N=52,M=105;
int n,m,K,ans=1,tot=1,tim,top;
int bin[M],h[N],ne[M<<1],to[M<<1],fac[M<<1],ni[M<<1];
int vis[N],st[M<<1],low[N],dfn[N],orz[M<<1];
void add(int x,int y) {to[++tot]=y,ne[tot]=h[x],h[x]=tot;}
int qm(int x) {return x>=mod?x-mod:x;}
int ksm(int x,int y) {
	int re=1;
	for(;y;y>>=1,x=1LL*x*x%mod) if(y&1) re=1LL*re*x%mod;
	return re;
}
int gcd(int x,int y) {return y?gcd(y,x%y):x;}
int C(int d,int u) {return 1LL*fac[d]*ni[u]%mod*ni[d-u]%mod;}
void tarjan(int x) {
	dfn[x]=low[x]=++tim;
	for(RI i=h[x];i;i=ne[i]) {
		if(orz[i]) continue;
		orz[i]=orz[i^1]=1,st[++top]=i;
		if(!dfn[to[i]]) {
			tarjan(to[i]),low[x]=min(low[x],low[to[i]]);
			if(low[to[i]]>=dfn[x]) {
				int cir=1,js=0,re=0;
				for(RI j=top;st[j+1]!=i;--j,++js)
					if(vis[to[st[j]]]) cir=0;
					else vis[to[st[j]]]=1;
				if(cir) {
					for(RI i=0;i<js;++i) re=qm(re+bin[gcd(i,js)]);
					ans=1LL*ans*re%mod*ksm(js,mod-2)%mod;
				}
				else ans=1LL*ans*C(js+K-1,js)%mod;
				while(st[top+1]!=i) vis[to[st[top]]]=0,--top;
			}
		}
		else low[x]=min(low[x],dfn[to[i]]);
	}
}
int main()
{
	int x,y;
	n=read(),m=read(),K=read();
	bin[0]=1;for(RI i=1;i<=m;++i) bin[i]=1LL*bin[i-1]*K%mod;
	fac[0]=1;for(RI i=1;i<=m+K;++i) fac[i]=1LL*fac[i-1]*i%mod;
	ni[m+K]=ksm(fac[m+K],mod-2);
	for(RI i=m+K-1;i>=0;--i) ni[i]=1LL*ni[i+1]*(i+1)%mod;
	for(RI i=1;i<=m;++i) x=read(),y=read(),add(x,y),add(y,x);
	for(RI i=1;i<=n;++i) if(!dfn[i]) tarjan(i);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256