akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

immutable mod = 10^^9 + 7;
immutable inf = 2 * 10^^9;

void main() {
    int n, k;
    scan(n, k);

    auto x = new int[](n), y = new int[](n);

    foreach (i ; 0 .. n) {scan(x[i], y[i]);}

    long ans = long.max;
    bool[] mask = new bool[](n);

    void dfs(int xl, int xr, int yb, int yt, int take) {
        if (take == k || take == 4) {
            int cnt;

            foreach (i ; 0 .. n) {
                if (xl <= x[i] && x[i] <= xr && yb <= y[i] && y[i] <= yt) cnt++;
            }

            if (cnt >= k) {
                ans = min(ans, 1L * (xr - xl) * (yt - yb));
            }

            return;
        }

        foreach (i ; 0 .. n) {
            if (!mask[i]) {
                mask[i] = 1;
                dfs(min(xl, x[i]), max(xr, x[i]), min(yb, y[i]), max(yt, y[i]), take + 1);
                mask[i] = 0;
            }
        }
    }

    dfs(inf, -inf, inf, -inf, 0);

    writeln(ans);
}



void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        String s;
        long k;

        Scanner sc = new Scanner(System.in);
        s = sc.nextLine();
        k = sc.nextLong();

        long change = 0;
        int continueCount = 1;
        char check = ' ';
        for (int i = 0; i <= s.length(); i++) {
            int j = i;
            if (i == s.length()) {
                j = 0;
            }
            if (s.charAt(j) == check) {
                continueCount++;
            } else {
                if (continueCount > 0)
                    change += continueCount / 2;
                continueCount = 1;
            }
            check = s.charAt(j);
        }

        boolean bellows = false;
        boolean startEndian = false;
        boolean endian = false;
        boolean single = false;
        if (continueCount > 0 && continueCount == s.length() + 1 && continueCount % 2 == 0) {
            change += continueCount / 2;
            bellows = true;
        } else if (continueCount > 0 && continueCount != s.length() + 1 && continueCount % 2 == 0) {
            int ii = 0;
            int startCount = 1;
            while (true) {
                if (s.charAt(ii) == s.charAt(ii+1)) startCount++;
                else break;
                ii++;
            }
            if (startCount % 2 == 1) {
                change += continueCount / 2;
                startEndian = true;
            }
            else {
                change += (continueCount - 1) / 2;
            }
        } else if (continueCount > 0 && continueCount % 2 == 1) {
            change += continueCount / 2;
        } else if (continueCount > 0 && s.length() == 1) {
            change += continueCount / 2;
            single = true;
        } else if (continueCount > 0) {
            change += continueCount / 2;
            endian = true;
        }

        long ans = change * k;
        if (single) {
            ans /= 2;
        } else if (endian) {
            ans--;
        } else if (startEndian) {
            ans--;
        } else if (bellows) {
            ans -= k / 2;
            if (k % 2 == 1) ans--;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
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;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
ll n,m,a,b;
int main(){
    cin>>n>>a>>b;
    if((b-a)%2==0){
        cout<<(b-a)/2<<endl;
    }
    else{
        if((a-1)>=(n-b)){
            cout<<min(n-a,(b-a-1)/2+n-b+1)<<endl;
        }
        else{
            cout<<min(b-1,a+(b-a-1)/2)<<endl;
        }
    }
    return 0;
}




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

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

using namespace std;
typedef long long ll;

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

    int odd = 0;

    rep(i, n) {
        int ai;
        cin >> ai;

        if (ai % 2 != 0) {
            odd++;
        }
    }

    if (odd % 2 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3620
import sys
input = sys.stdin.readline
K = int(input())
S = list(input())[: -1]
mod = 10 ** 9 + 7

class Factorial:
  def __init__(self, n, mod):
    self.f = [1]
    for i in range(1, n + 1):
      self.f.append(self.f[-1] * i % mod)
    self.i = [pow(self.f[-1], mod - 2, mod)]
    for i in range(1, n + 1)[: : -1]:
      self.i.append(self.i[-1] * i % mod)
    self.i.reverse()
  def factorial(self, i):
    return self.f[i]
  def ifactorial(self, i):
    return self.i[i]
  def combi(self, n, k):
    return self.f[n] * self.i[n - k] % mod * self.i[k] % mod
###
f = Factorial(10 ** 6 * 3, mod)
res = 0
for i in range(K + 1):
  #i ko migi soto
  t = f.combi(len(S) - 1 + K - i, len(S) - 1) * pow(25, K - i, mod) % mod
  t = t * pow(26, i, mod) % mod
  res += t
  res %= mod
print(res)

Measured memory_bytes: 269348
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;

typedef long long ll;
typedef long double ld;

int MOD=1000000007;

int main(){
  ll N;
  cin >> N;
  if(N%10==7 || N/10%10==7 || N/100%10==7)
  cout << "Yes" << endl;
  else cout << "No" << endl; 
}


Measured memory_bytes: 3596
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication20
{
    class Program
    {
        static void Main(string[] args)
        {
           var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
           var b = Console.ReadLine().Split().Select(int.Parse).ToArray();
           var c = Console.ReadLine().Split().Select(int.Parse).ToArray();
           var d = Console.ReadLine().Split().Select(int.Parse).ToArray();
           var e = Console.ReadLine().Split().Select(int.Parse).ToArray();
           var f = Console.ReadLine().Split().Select(int.Parse).ToArray();
           var g = Console.ReadLine().Split().Select(int.Parse).ToArray();
           Console.WriteLine(a[0] - a[1]);
           Console.WriteLine(b[0] - b[1]);
           Console.WriteLine(c[0] - c[1]);
           Console.WriteLine(d[0] - d[1]);
           Console.WriteLine(e[0] - e[1]);
           Console.WriteLine(f[0] - f[1]);
           Console.WriteLine(g[0] - g[1]);
        }
    }
}

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

int main(){
  int H, W;
  cin >> H >> W;
  char A[H][W];
  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      cin >> A[i][j];
    }
  }
  bool B[H][W];

  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      B[i][j]=false;
    }
  }

  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      if (A[i][j]=='#'){
        if(i-1>=0){
          if(A[i-1][j]=='#') B[i][j]=true;
        }
        if(j-1>=0){
          if(A[i][j-1]=='#') B[i][j]=true;
        }
        if(j+1<W){
          if(A[i][j+1]=='#') B[i][j]=true;
        }
        if (i+1<H){
          if(A[i+1][j]=='#') B[i][j]=true;
        }
      }
    }
  }
  int cnt=0;
  for (int i=0; i<H; i++){
    for (int j=0; j<W; j++){
      if (A[i][j]=='#'&&B[i][j]==false){
        cnt++;
      }
    }
  }
  if (cnt>0) cout << "No" << endl;
  else cout << "Yes" << endl;
}

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


int main(){
  int n;
  cin >>n;
  ll a[n];
  int minus=0;
  ll g=10000000000;
  rep(i,n){
    cin >> a[i];
    if(a[i]<0)minus++;
    chmin(g,abs(a[i]));
  }
  ll ans=0;
  if(minus%2==0){
    rep(i,n)ans+=abs(a[i]);
    cout << ans <<endl;
  }else{
    rep(i,n)ans+=abs(a[i]);
    ans-=g*2;
    cout << ans << endl;
  }
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

//main code

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	VL a(n);
	cin >> a;
	VL rui(n+1,0);
	for (int i = 0; i < n; i++) {
		rui[i+1] = rui[i] + a[i];
	}
	map<LL,LL> mp;
	for (int i = 0; i < n; i++) {
		mp[rui[i+1]]++;
	}
	LL ans = 0;
	for (auto&& var : mp) {
		LL m = var.second;
		if (var.first == 0) {
			ans += m;
		}
		ans += m*(m-1)/2;
	}
	cout << ans << endl;
	return 0;
}


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

const int N = 100005;

int w, h, p[N], q[N];
vector < pair<int, int> > vec;
long long res;
int cnt[2];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> w >> h;
	for (int i = 0; i < w; ++i) {
		cin >> p[i];
		vec.push_back(make_pair(p[i], 0));
	}
	for (int i = 0; i < h; ++i) {
		cin >> q[i];
		vec.push_back(make_pair(q[i], 1));
	}

	sort(vec.begin(), vec.end());
	cnt[0] = w + 1;
	cnt[1] = h + 1;

	for (auto e : vec) {
		int val = e.first;
		int t = e.second;
		res += 1LL * cnt[t ^ 1] * val;
		cnt[t]--;
	}

	cout << res << endl;
}

Measured memory_bytes: 2932
#include <cstdio>
#include <cstring>
#include <algorithm>
#define NMAX 100
using namespace std;

int main(void){
  char st[NMAX];
  int c[2][26];
  int len, mx=0, t;
  
  scanf("%d", &len);
  scanf("%s",st);
  for (int i=0; i<len-1; i++){
    memset(c, 0, sizeof(c));
    for (int j=0; j<len; j++){
      c[j<i][st[j]-'a']++;
    }
    t = 0;
    for (int j=0; j<26; j++){
      if (c[0][j]&&c[1][j]) t++;
    }
    mx = max(mx, t);
  }
  printf("%d\n",mx);
  return 0;
}

Measured memory_bytes: 128
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

const ll MOD = 1000000007;

class RangeMaximumQuery {
public:
  int N;
  vector<int> dat;

  RangeMaximumQuery(int _N, int init_value) {
    this->N = 1;

    while (N < _N) {
      N *= 2;
    }

    for (int i = 0; i < 2 * N; ++i) {
      dat.push_back(init_value);
    }
  }

  void update(int idx, int val) {
    idx += N - 1;
    dat[idx] = val;

    while (idx > 0) {
      idx = (idx - 1) / 2;

      if (dat[idx * 2 + 1] > dat[idx * 2 + 2]) {
        dat[idx] = dat[idx * 2 + 1];
      } else {
        dat[idx] = dat[idx * 2 + 2];
      }
    }
  }

  int find_max(int l, int r) {
    return query(l, r, 0, 0, N - 1);
  }

private:

  int query(int a, int b, int idx, int l, int r) {
    if (r < a || b < l) return 0;

    if (a <= l && r <= b) {
      return dat[idx];
    } else {
      int vl = query(a, b, idx * 2 + 1, l, (l + r) / 2);
      int vr = query(a, b, idx * 2 + 2, (l + r) / 2 + 1, r);

      return (vl > vr) ? vl : vr;
    }
  }
};

const int MAX_N = 300'010;

int main() {
  int N, K;
  cin >> N >> K;
  RangeMaximumQuery rmq(MAX_N, 0);

  int a;
  int max_a = 0;
  for (int i = 0; i < N; ++i) {
    cin >> a;
    max_a = max(max_a, a);
    int left = max(0, a - K);
    int right = min(MAX_N, a + K);
    int v = rmq.find_max(left, right);
    rmq.update(a, v + 1);
  }

  cout << rmq.find_max(0, max_a) << endl;

  return 0;
}


Measured memory_bytes: 7468
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	readb(n, m);
	int ch[n + 1] = {};
	
	FOR (i, 1, m)
	{
	    readb(x, y);
	    if (x == 1) ch[y]++;
	    else if (y == n) ch[x]++;
	}
	
	FOR (i, 2, n - 1)
	    if (ch[i] == 2)
	        {cout << "POSSIBLE"; return 0;}
	
	cout << "IMPOSSIBLE";
}















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


long long con(long long n){
    return n*(n-1)/2;
}

int main(){
    long long N;
    cin >> N;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin >>A.at(i);
      	A.at(i)--;
    }
    vector<int> cnt(N);

    for(int i=0;i<N;i++) cnt.at(A.at(i))++; 

    long long sum = 0;
    for(int i=0;i<N;i++){
        sum += con(cnt.at(i));
    }
    for(int i=0;i<N;i++){
        long long ans = sum - con(cnt.at(A.at(i))) + con(cnt.at(A.at(i))-1);
        cout << ans <<endl;
    }
  return 0;

}


Measured memory_bytes: 4096
n = gets.to_i
a = gets.split.map &:to_i

c = []
max = 1000000000
min = -100000
a.each_with_index do |ai, i|
    ci = a[i] - i - 1
    c[i] = ci
    max = [max, ci].max
    min = [min, ci].min
end

best = nil
target = min + 1
dif = max - min
while true
    sum1 = 0
    plus = 0
    minus = 0
    c.each do |ci|
        sum1 += (ci - target).abs
        plus += (ci - (target + 1)).abs
        minus += (ci - (target - 1)).abs
    end
    if sum1 > plus
        dif /= 2
        dif = 1 if dif == 0
        target += dif
    elsif sum1 > minus
        dif /= 2
        dif = 1 if dif == 0
        target -= dif
    else
        puts sum1
        exit
    end
end

Measured memory_bytes: 21516
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF = 0X3F3F3F3F;
const ll N = 1e5+7;
#define mem(a, b) memset(a, b, sizeof(a))
#define IOS() std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
int main()
{
	IOS();
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b+c>=22) cout<<"bust\n";
	else cout<<"win\n"; 
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,D,x[16][16],c,i,j,k,s=0,p,l=0;
    cin>>N>>D;
    for(i=0;i<N;i++)
    {
        for(j=0;j<D;j++)
        {
            cin>>x[i][j];
        }
    }
    for(i=0;i<N-1;i++)
    {
        for(j=i+1;j<N;j++)
        {
            s=0;
            for(k=0;k<D;k++)
            {
                s+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            }
            p=sqrt(s);
            if((p*p)==s)
            {
                l++;
            }
        }
    }

    cout<<l<<endl;




    return 0;
}


Measured memory_bytes: 256
def dist(a,b):
    return ((a[0]-b[0])**2+(a[1]-b[1])**2)**0.5


n=int(input())
data=[]
for i in range(n):
    x,y=map(float,input().split())
    data.append((x,y))

now=(500.,500.)
move=1
for i in range(200000):
    max_dist=0
    max_dist_point=-1
    for j in range(len(data)):
        d=dist(now,data[j])
        if d>max_dist:
            max_dist=d
            max_dist_point=j
    target=data[max_dist_point]
    now=(now[0]+(target[0]-now[0])*move,now[1]+(target[1]-now[1])*move)
    move*=0.999
max_dist=0
for j in range(len(data)):
    d=dist(now,data[j])
    if d>max_dist:
        max_dist=d
print(max_dist)





Measured memory_bytes: 42832
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <map>
#include <list>
#include <math.h>
#include <algorithm>
#include <chrono>
#include <random>
#include <queue>
#include <fstream>
#include <iterator> // std::back_inserter
#include <chrono>
#include <string>
#include <stdio.h>
#include <iomanip>
#include <float.h>
#include <cassert>
#include <functional>

using namespace std;

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

    cin >> N >> K;

    while(pow(K,ans) <= N){
        ans++;
    }

    cout << ans;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

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

  return 0;
}


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

using namespace std;

#define I32MAX 2147483647L

int main()
{
    int n;
    cin >> n;
    int d[n];
    set<int> s;
    for(int i=0; i<n; i++)
    {
        cin >> d[i];
        s.insert(d[i]);
    }
    for(int i=0; i<n; i++)
    {
        if(d[i]!=0)
        {
            for(int j=i+1; j<n; j++)
            {
                long long x = 0;
                bool valid = true;
                for(int p=i; p<=j; p++)
                {
                    x = x *10 + d[p];
                    if(x>I32MAX)
                    {
                        valid = false;
                        break;
                    }
                }
                if(valid) s.insert(x);
            }
        }
    }
    for(int i=0; ; i++)
    {
        if(s.find(i)==s.end())
        {
            cout << i << endl;
            break;
        }
    }
}

Measured memory_bytes: 3352
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <limits.h>
//#include <math.h>

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

int main() {
  char s[5001];
  scanf("%s", s);
  int k, l=strlen(s);
  scanf("%d", &k);
  char sub[k*l][6]; int idx = 0;
  for (int i=0; i<l; i++) {
    for (int j=0; j<k && j+i<l; j++) {
      for (int m=0; m<j+1; m++) {
        sub[idx][m] = s[i+m];
        sub[idx][m+1] = '\0';
      }
      idx++;
    }
  }
  qsort(sub, idx, sizeof(char)*6, acs);
  int i=1;
  for (int cnt=1; cnt<k; i++) {
    if (strcmp(sub[i-1], sub[i])==0) continue;
    cnt++;
  }
  printf("%s\n", sub[i-1]);
  return 0;
}


Measured memory_bytes: 508
import java.util.*;
import java.util.Collections;
import java.util.stream.Collectors;
 
public class Main {
 
  public static void main(String[] args) {

	Scanner s = new Scanner(System.in);
		int num = s.nextInt();
		Double r = (double) num;
	System.out.println(2*3.14*r);
  }
}

Measured memory_bytes: 35888
#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;

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

int dp[500000][55];
int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);

    int N;
    cin >> N;
    vector<int> A(N), B(N);
    REP(i, N) { cin >> A.at(i); }
    REP(i, N) { cin >> B.at(i); }

    // 初期化
    REP(bit, 1 << N) {
        REP(i, 55) { dp[bit][i] = INF; }
    }
    dp[0][0] = 0;

    REP(bit, 1 << N) {
        int S_size = 0;
        REP(i, N) {
            int mask = 1 << i;
            if (bit & mask) {
                S_size++;
            }
        }

        vector<pair<int, int>> invS; // first:もともと何番目か、second:カードの現在地
        int now = S_size;
        REP(i, N) {
            int mask = 1 << i;
            if ((bit & mask) == 0) {
                invS.emplace_back(i, now);
                now++;
            }
        }
        // cout << "bit:" << bit << endl;
        REP(last, 51) {
            for (auto v : invS) {
                int i = v.first;
                int now = v.second;
                int i_val;
                if (abs(i - S_size) % 2 == 0) {
                    i_val = A[i];
                } else {
                    i_val = B[i];
                }
                if (i_val >= last) {
                    /*debug
                    if (dp[bit | (1 << i)][i_val] > dp[bit][last] + abs(now - S_size)) {
                        cout << "min last:" << last << " i:" << i << " now:" << now << " i_val:" << i_val
                             << " abs(now - S_size):" << abs(now - S_size) << endl;
                    } else {
                        cout << "no last:" << last << " i:" << i << " now:" << now << " i_val:" << i_val << endl;
                    }*/
                    chmin(dp[bit | (1 << i)][i_val], dp[bit][last] + abs(now - S_size));
                }
            }
        }
    }

    /*
    REP(i, 1 << N) { cout << i << "  "; }
    cout << endl;
    REP(j, 51) {
        REP(i, 1 << N) { cout << dp[i][j] << "  "; }
        cout << endl;
    }
    */

    int ans = INF;
    REP(i, 55) { chmin(ans, dp[(1 << N) - 1][i]); }

    if (ans == INF) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 57600
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int H = scan.nextInt();
        int W = scan.nextInt();
        int K = scan.nextInt();
        int[][] blacks = new int[H][W];
        for (int i = 0; i < H; i++) {
            char[] t = scan.next().toCharArray();
            for (int j = 0; j < W; j++) {
                if (t[j] == '#') blacks[i][j] = 1;
            }
        }
        int max_h = pow(2, H);
        int max_w = pow(2, W);
        int ans = 0;
        for (int i = 0; i < max_h; i++) {
            for (int j = 0; j < max_w; j++) {
                int count = 0;
                for (int row = 0; row < H; row++) {
                    if (((i >> row) & 1) == 1) continue;
                    for (int column = 0; column < W; column++) {
                        if (((j >> column) & 1) == 1) continue;
                        count += blacks[row][column];
                    }
                }
                if (count == K) ans += 1;
            }
        }
        System.out.println(ans);
    }
    private int pow(int base, int count) {
        if (count == 0) return 1;
        if (count % 2 == 1) return base * pow(base, count - 1);
        int t = pow(base, count / 2);
        return t * t;
    }
}


Measured memory_bytes: 35792
#include <iostream>
using namespace std;
int main(){
  int H,W;
  while (1) {
    cin >> H >> W;
    if (H == 0 && W == 0)break;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}

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

int main() {
  int64_t a,b;
  cin >> a >> b;
  int64_t ans=0;
  rep2(i,1,b+1){
    if(a*i%b==0){
      ans=a*i;
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a, b, n;
	
	scanf("%d", &n);
	
	if (n == 1) {
		printf("Hello World\n");
	} else if (n == 2) {
		scanf("%d", &a);
		scanf("%d", &b);
		a = a + b;
		printf("%d", a);
	}
	
	return 0;
}
				


Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

template <typename T>
vector<pair<T, int>> prime_factorization(T val) {
  vector<pair<T, int>> res;
  for (T i = 2; i * i <= val; ++i) {
    if (val % i != 0) continue;
    int exponent = 0;
    while (val % i == 0) {
      ++exponent;
      val /= i;
    }
    res.emplace_back(i, exponent);
  }
  if (val != 1) res.emplace_back(val, 1);
  return res;
}

int main() {
  ll n; cin >> n;
  int ans = 0;
  for (auto [ignore, e] : prime_factorization(n)) {
    for (int i = 1; ; ++i) {
      if (e < i) break;
      ++ans;
      e -= i;
    }
  }
  cout << ans << '\n';
  return 0;
}


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

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define all(X) X.begin(),X.end()

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   str.substr (x) : returns a substring str[x],... end of string
   str.find(qtr) : returns the first occurenece of qtr in str.
   builtin functions :
   __builtin_popcount(n) : no. of set bits in n.
   __builtin_parity(n) : parity of no. of set bits
   __builtin_clz(n) : no. of leading zeros before 1
   __builtin_ctz(n) : no of zeros from last to first occurrence of 1
*/

const int M = (1<<20)+5;
const int md = 998244353;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

ll binlen(ll a)
{
	ll v = 0;
	for(ll i=0;i<61;++i)
	{
		v += (1ll<<i);
		if(a<=v) return i;
	}
}

ll ar[M],cnt[M];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll i,n,m=1,mx=0;
	cin >> n;
	for(i=1;i<=n;++i)
	{
		cin >> ar[i];
		cnt[ar[i]]++;
		mx = max(mx,ar[i]);
	}
	for(i=2;i<=mx;++i)
	{
		m = 1ll*m*pwr(cnt[i-1],cnt[i],md)%md;
	}
	if(ar[1] == 0 && cnt[0] == 1)
		cout << m << endl;
	else
		cout << 0 << endl;
}

Measured memory_bytes: 3072
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main() {
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    double distance = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
    printf("%.5lf\n", distance);

    return 0;
}



Measured memory_bytes: 3208
#include<bits/stdc++.h>
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define loop(i,m,n) for(lli i=m;i<=n;i++)
#define loopr(i,m,n) for(lli i=m;i>=n;i--)
#define pb push_back
#define vi vector<int>
#define ff first
#define ss second
#define ii pair<int,int>
#define vii vector<ii>
#define INF 1000000000
#define mod 1000000007
#define siz 1000001
#define endl "\n"
const double PI=3.14159265358979323846264338327950288419716939937510;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;

int main()
{
	int i,j,n,m,ans=INT_MAX;
	string s,t;
	cin>>s>>t;
	n=s.size();
	m=t.size();
	for (i = 0; i <= n - m; i++)
    {
        int needchange = 0;
        for (j = 0; j < t.length(); j++)
        {
            if (s[i+j] != t[j])
            {
                needchange++;
            }
        }
            ans = min(ans, needchange);
    }
    cout<<ans<<endl;
    return 0;
}
/*
cabacc
abc

codeforces
atcoder
*/


Measured memory_bytes: 3604
#include <cstdio>
#include <cstring>
#include <algorithm>
#define rr register int
using namespace std;
char a[101];
int main()
{
    scanf("%s",a);
    bool flag=0;
    int len=strlen(a);
    for(rr i=0;i<len;++i)
    {
    	if(a[i]=='C')flag=1;
    	if(flag&&a[i]=='F')
    	{
    		puts("Yes");
    		return 0;
    	}
    }
    puts("No");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main(){
    cin>>N>>K;
    /*vec a(N);
    rep(i,N){
        cin>>a[i];
        if(a[i] == 1) M = i;
    }*/
    cout<<1 + (N - 2) / (K - 1)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
using namespace std;
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;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
    int n;
    cin >> n;
    vector<int> A(n);
    rep(i,n) cin >> A[i];
    sort(all(A));
    int dis = 0;
    dis = A[A.size()-1] - A[0];
    cout << dis << "\n";

}


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

using namespace std;

using llint = long long int ;
using ullint = unsigned long long int;


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

    int a,b;

    cin >> a >> b;

    int ans = a*b;
    if(a<=0 || 10<=a)
        ans = -1;
    if(b<=0 || 10<=b)
        ans = -1;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const long long MOD = 998244353;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using ll = long long;
using pLL = std::pair<ll, ll>;
#define SORT(v) std::sort(v.begin(), v.end())
#define RSORT(v) std::sort(v.rbegin(), v.rend())
constexpr auto PI = 3.14159265358979323846264338327950L;
int N,M,Q;
vector<int> a, b, c, d;
int score(const vector<int> &A) {
    int res = 0;
    for (int i = 0; i < Q; ++i) if (A[b[i]] - A[a[i]] == c[i])res += d[i];
    return res;
}
int dfs(vector<int> &A) {
    if (A.size() == (size_t)N) {
        return score(A);
    }
    int res = 0;
    int prev_last = (A.empty() ? 0 : A.back());
    for (int add = prev_last; add < M; ++add) {
        A.push_back(add);
        res = max(res,dfs(A));
        A.pop_back();
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M >> Q;
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    vector<int> A;
    for (int i = 0; i < Q; ++i) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        --a[i];
        --b[i];
    }
    cout << dfs(A) << endl;
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
    int64_t K, A, B;
    cin >> K >> A >> B;
    if (A % K == 0 || B % K == 0) {
        cout << "OK" << endl;
    } else if((B / K) - (A / K) >= 1) {
        cout << "OK" << endl;
    } else {
        cout << "NG" << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

#define MAX_N 100

int main(){
  int N,u,k,v,i,j;
  int G[MAX_N][MAX_N];
  for (i = 0 ; i < MAX_N ; i++) {
    for (j = 0 ; j < MAX_N ; j++) {
      G[i][j] = 0;
    }
  }
  scanf("%d",&N);
  for(i = 0 ; i < N ; i++){
    scanf("%d%d",&u,&k); u--;
    for(j = 0 ; j < k ; j++){
      scanf("%d",&v); v--;
      G[u][v] = 1;
    }
  }
  for(i = 0 ; i < N ; i++){
    for(j = 0 ; j < N ; j++){
      printf("%d%c",G[i][j],(j < N-1 ? ' ' : '\n'));
    }
  }
  return 0;
}

Measured memory_bytes: 640
import sys

cin = sys.stdin
# N = int(cin.readline())
N, B = list(map(int, cin.readline().split()))

MOD = int(1e9+7)


def C(N, K):
    if K*2>N:
        K = N-K
    acc = 1
    for i in range(0, K):
        acc = acc * (N-i) // (i+1)
    return acc % MOD


for p in range(1, B+1):
    R = N - B
    if R+1 < p:
        print(0)
        continue
    # base split for B for p parts
    R1 = R - (p - 1) # base split each use 1
    # base split C(B-1, p-1)
    # R1 possible place p+1
    # C( R1 + p, p)
    ttl = C(B-1, p-1) * C(R1+p, p)
    print(ttl % MOD)


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

int main(){
	int N,K;
	cin >> N >> K;
	vector<ll> H(N);
	for(int i = 0;i<N;++i){
		cin >> H.at(i);
	}
	sort(H.begin(),H.end());
	reverse(H.begin(),H.end());
	//0-indexed
	int i = 0;
	i += K;
	ll sum = 0;
	for(;i<N;++i){
		sum += H.at(i);
	}
	cout << sum << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>

#include <string.h>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <cstdio>
using namespace std;
#define PI acos(-1,0)
#define eps 1e-10
#define ll long long
#define mst(ss,b) memset((ss),(b),sizeof(ss))

int main()
{
    int a;
    cin>>a;
    cout<<"ABC"<<a<<endl;
    return 0;
}

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

import static java.lang.Integer.parseInt;

/**
 * Graph I - Connected Components
 */
public class Main {

	static final int NIL = -1;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		Main main = new Main();

		line = br.readLine();

		int n, m;
		n = parseInt(line.substring(0, line.indexOf(' ')));
		m = parseInt(line.substring(line.indexOf(' ') + 1));

		Vertex[] G = new Vertex[n];
		int color = 0;

		for (int i = 0; i < n; i++) {
			G[i] = main.new Vertex();
		}

		for (int i = 0; i < m; i++) {
			line = br.readLine();
			int s, t;
			s = parseInt(line.substring(0, line.indexOf(' ')));
			t = parseInt(line.substring(line.indexOf(' ') + 1));
			G[s].es.add(G[t]);
			G[t].es.add(G[s]);
		}

		for (int i = 0; i < n; i++) {
			if (G[i].color == NIL) {
				G[i].color = color++;
				Deque<Vertex> stack = new ArrayDeque<>();
				stack.push(G[i]);
				while (!stack.isEmpty()) {
					Vertex s = stack.pop();
					for (Vertex t : s.es) {
						if (t.color == NIL) {
							t.color = G[i].color;
							stack.push(t);
						}
					}
				}
			}
		}


		int q = parseInt(br.readLine());
		StringBuilder sb = new StringBuilder();

		for (int i = 0; i < q; i++) {
			line = br.readLine();
			int s, t;
			s = parseInt(line.substring(0, line.indexOf(' ')));
			t = parseInt(line.substring(line.indexOf(' ') + 1));
			if (G[s].color == G[t].color) {
				sb.append("yes\n");
			} else {
				sb.append("no\n");
			}
		}

		System.out.print(sb.toString());
	}

	class Vertex {
		int color = NIL;
		List<Vertex> es = new ArrayList<>();
	}
}

Measured memory_bytes: 72500
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

priority_queue<int, vector<int>, greater<int> > pq;
vector<int> v;

int vec[100000];
map<int, int> ma;

int main() {
	int n;
	scanf("%d", &n);

	int mav = 0;

	for (int i = 0; i < n; i++) {
		scanf("%d", &vec[i]);
		ma[vec[i]]++;
		ma[vec[i] - 1]++;
		ma[vec[i] + 1]++;

		mav = max(mav, ma[vec[i]]);
		mav = max(mav, ma[vec[i] - 1]);
		mav = max(mav, ma[vec[i] + 1]);
	}

	printf("%d", mav);
}

Measured memory_bytes: 5120
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<limits>
#include<string.h>
#include<vector>
#include<stack>
#include<queue>
using namespace std;

int main()
{
    int n;
    cin>>n;
    vector<char> c(n);
    vector<int> d(n);
    int count=0;
    for (int i = 0; i < n; i++)
    {
        cin>>c.at(i);
        if (c.at(i)=='W')
        {
            d.at(i)=1;
        }else
        {
            d.at(i)=0;
            count++;
        }
        
    }
    int count2=0;
    int count3=0;
    for (int i = 0; i < count; i++)
    {
        if (d.at(i)==1)
        {
            count2++;
        }
        
    }
    for (int i = count; i < n; i++)
    {
        if (d.at(i)==0)
        {
            count3++;
        }
        
    }
    cout<<max(count2,count3)<<endl;
    

    
    


    
    

    return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

signed main()
{
    int x, a, b;
    cin >> x >> a >> b;
    int dist_a = abs(x - a);
    int dist_b = abs(x - b);
    printf("%c\n", (dist_a < dist_b) ? 'A' : 'B');
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 40005
#define eps 1e-12
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
	res = 0;T f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		res = res * 10 + c - '0';
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0) {x = -x;putchar('-');}
	if(x >= 10) {
		out(x / 10);
	}
	putchar('0' + x % 10);
}

int64 A,M;
int64 phi(int64 x) {
	int64 t = x;
	for(int i = 2 ; i <= x / i ; ++i) {
		if(x % i == 0) {
			t = t / i * (i - 1);
			while(x % i == 0) x /= i;
		}
	}
	if(x > 1) t = t / x * (x - 1);
	return t;
}
int64 gcd(int64 a,int64 b) {
	return b == 0 ? a : gcd(b,a % b);
}
int64 fpow(int64 x,int64 c,int64 M) {
	int64 res = 1,t = x;
	while(c) {
		if(c & 1) res = res * t % M;
		t = t * t % M;
		c >>= 1;
	}
	return res;
}
void exgcd(int64 a,int64 b,int64 &x,int64 &y) {
	if(b == 0) {x = 1;y = 0;}
	else {
		exgcd(b,a % b,y,x);
		y -= a / b * x;
	}
}
int64 mul(int64 a,int64 b,int64 M) {
	int64 res = 0,t = a;
	while(b) {
		if(b & 1) res = (res + t) % M;
		t = (t + t) % M;
		b >>= 1;
	}
	return res;
}
int64 Calc(int64 a,int64 m) {
	if(m == 1) return 100;
	int64 eu = phi(m),g = gcd(eu,m);
	int64 y = Calc(a,g);
	int64 a1 = fpow(a,y,m),a2 = y % eu;
	int64 x,t;
	exgcd(m,eu,x,t);
	int64 mod = m * eu / g;
	x = (x % (eu / g) + eu / g) % (eu / g);
	x = x * (a2 - a1) / g;
	x = (x % mod + mod) % mod;
	x = (mul(x,m,mod) + a1) % mod;
	while(x < 100) x += mod;
	return x;
}
void Solve() {
	read(A);read(M);
	int64 x = Calc(A,M);
	out(x);enter;
	//if(fpow(A,x,M) == x % M) {puts("YES");}
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	int Q;
	read(Q);
	while(Q--) Solve();
}


Measured memory_bytes: 256
// --------------
// Tejas Pandey  |
// 21 - 06 - 19  |
// Atcoder #131  |    |
// --------------

#include <bits/stdc++.h>
using namespace std;

#define mod 1000000007
typedef long long int ll;
ll gcd (ll a, ll b)
{
	if(a%b)
	return gcd(b,a%b);
	else
	return b;
}
int main (void)
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ll a,b,c,d;
	cin >> a >> b >> c >> d;
	ll lcm = (c*d)/gcd(c,d);
	ll t1 = a%c ? -a/c+b/c : -a/c+b/c+1;
	ll t2 = a%d ? -a/d+b/d : -a/d+b/d+1;
	ll t3 = a%lcm ? -a/lcm+b/lcm : -a/lcm+b/lcm+1;
	cout << (b - a + 1) - (t1 + t2 - t3);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	while(cin>>n,n) 
	{
		int f[n][n];
		for(int i = 0; i < n; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				f[i][j]=-1;
			}
		}

		int x=n/2,y=n/2+1;
		f[y][x]=1;
		for(int i = 1; i < n*n; ++i)
		{
			++x; ++y;
			while(x<0||n<=x||n<=y||f[y][x]!=-1) 
			{
				if(x<0) x=n-1;
				else if(n<=x) x=0;
				else if(n<=y) y=0;
				else
				{
					--x; ++y;
				}
			}
			f[y][x]=i+1;
		}
		for(int i = 0; i < n; ++i)
		{
			for(int j = 0; j < n; ++j)
			{
				printf("%4d",f[i][j]);
			}
			cout<<endl;
		}
	}
  return 0;
}

Measured memory_bytes: 1192
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  cin>>str;
  int flag[500]={};
  for(int i=0;i<str.size();i++)
    flag[str[i]]=1;
  if((flag['N']&&flag['S']&&flag['W']&&flag['E'])||(flag['N']&&flag['S']&&!flag['E']&&!flag['W'])||(!flag['N']&&!flag['S']&&flag['E']&&flag['W']))
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

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 U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

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

	int64 N;
	cin >> N;
	vector<int64> A(3*N);
	auto dp = make_v<int64>(N, N);
	auto dp2 = make_v<int64>(N);
	fill_v<int64>(dp, -INF);
	fill_v<int64>(dp2, -INF);
	for (auto& x : A) {
	  cin >> x; x--;
	}

	using T = tuple<int, int, int>;
	dp[A[0]][A[1]] = dp[A[1]][A[0]] = 0;
	dp2[A[0]] = dp2[A[1]] = 0;
	int64 sum = 0, mx = 0;
	for (int64 i = 2; i + 2 < 3*N; i += 3) {
    vector<T> upd;
	  int64 mx2 = 0;
	  if (A[i] == A[i+1] && A[i+1] == A[i+2]) {
	    sum += 1;
	    continue;
	  }
	  // 余ってる2つと3つのうちの1つが等しいときのやつ
	  REP(j, 3) {
	    upd.emplace_back(A[i+j], A[i+(j+1)%3], max(dp[A[i+(j+2)%3]][A[i+(j+2)%3]] + 1, mx));
      upd.emplace_back(A[i+(j+1)%3], A[i+j], max(dp[A[i+(j+2)%3]][A[i+(j+2)%3]] + 1, mx));
	    chmax(mx2, max(dp[A[i+(j+2)%3]][A[i+(j+2)%3]] + 1, mx));
	  }

	  // 余ってるうちの1つと3つのうちの2つ
	  REP(j, 3) {
	    REP(k, N) {
	      int score = (A[i+j] == A[i+(j+1)%3]);
	      upd.emplace_back(A[i + (j+2)%3], k, max(dp[A[i+j]][k] + score, dp2[k]));
        upd.emplace_back(k, A[i + (j+2)%3], max(dp[A[i+j]][k] + score, dp2[k]));
        chmax(mx2, dp[A[i+j]][k] + score);
	    }
	  }
	  for (auto &x : upd) {
	    int a, b, c;
	    tie(a, b, c) = x;
	    chmax(dp[a][b], c);
	    chmax(dp2[a], c);
	    chmax(dp2[b], c);
	  }
	  chmax(mx, mx2);
	}
	int64 res = 0;
	REP(i, N) {
	  REP(j, N) {
	    chmax(res, dp[i][j] + sum + (i == j && i == A.back()));
	  }
	}
	cout << res << endl;
}


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

int main(){
  int R;
  cin >> R;
  if(R < 1200){
    cout << "ABC" << endl;
  }else if(R < 2800){
    cout << "ARC" << endl;
  }else{
    cout << "AGC" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256