akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;
const double PI = 3.1415926535;
const int MOD = 1000000007; // 計算してからmodで割る ans = (ans * a) % mod
#define int long long
template <typename T = long long > T in () { T x; cin >> x; return(x);}
// int a = in() のように使うlong long以外の型の時はstirng s = in<string>()のように型を指定する

signed main(void){
    int n = in();
    map<string, int> mp;
    REP(i, n){
        string s; cin >> s;
        mp[s]++;
    }
    int maxv = 0;
    for(auto p : mp) maxv = max(maxv, p.second);
    for(auto p : mp) if(p.second == maxv) cout << p.first << endl;
}

Measured memory_bytes: 25216
using System;

public class Hello
{
    public static void Main()
    {
        int num = int.Parse(Console.ReadLine());
        string[] x = Console.ReadLine().Split(' ');
        string[] y = Console.ReadLine().Split(' ');

        // p1-p3,???????¨????
        double p1 = 0;
        double p2 = 0;
        double p3 = 0;
        double p = 0;
        for (int i = 0; i < num; i++)
        {
            double diff = Math.Abs(double.Parse(x[i]) - double.Parse(y[i]));
            p1 += diff;
            p2 += Math.Pow(diff, 2.0);
            p3 += Math.Pow(diff, 3.0);
            p = Math.Max(p, diff);
        }

        Console.WriteLine(p1.ToString("F6"));
        Console.WriteLine(Math.Pow(p2, 1.0 / 2.0).ToString("F6"));
        Console.WriteLine(Math.Pow(p3, 1.0 / 3.0).ToString("F6"));
        Console.WriteLine(p.ToString("F6"));
    }
}

Measured memory_bytes: 9384
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b; cin>>a>>b;
  if(a>=1&&a<=100&&b>=1&&b<=100)
   cout<< a*b <<'\n';
 return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <deque>
using namespace std;

#define next '\n'
#define sp " "
#define print(x) cout << (x)
#define println(x) cout << (x) << next
#define stop return(0)
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(e, elem) for(auto& (e) : (elem))
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define all(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e);
using ll = long long;
using ull = unsigned long long;

int main(){
    int n, k;
    string s;
    cin >> n >> s >> k;

    char c = s[k - 1];

    rep(i, n){
        if(s[i] != c){
            s[i] = '*';
        }
    }

    println(s);
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a,b,x,i,w=0;
	
	scanf("%d %d %d", &a,&b,&x);

// misal 4 23 7 (a b x)
//  7, 14, 21
// ada 3
    w=x;
for(i=0; x<a; i++){
	x+=w;}
    	
    //skrg x=14
    
for(i=0; x<=b; i++){
	x+=w;
}
printf("%d",i);

}

    
    	
    


Measured memory_bytes: 1704
n,c = map(int,input().split())

x = []
v = []
array1 = []
array2 = []

for i in range(n):
  a,b = map(int, input().split())
  x.append(a)
  v.append(b)
  
rx = []
rv = []
for i in reversed(range(len(x))):
  rx.append(c-x[i])
  rv.append(v[i])
  
count = x[0]
array1.append(v[0] - x[0])
for i in range(1,n):
  array1.append(v[i]-x[i]+array1[i-1]+count)
  count = x[i]
  
count = rx[0]
array2.append(rv[0] - rx[0])
for i in range(1,n):
  array2.append(rv[i]-rx[i]+array2[i-1]+count)
  count = rx[i]

num = 0
max_array = []
for i in range(len(array1)-1):
  num = max(num, array1[i])
  max_array.append(num)

max_array = list(reversed(max_array))

num = 0
rmax_array = []
for i in range(len(array2)-1):
  num = max(num, array2[i])
  rmax_array.append(num)
  
rmax_array = list(reversed(rmax_array))
  
  
ans = 0
for i in range(n):
  if i != n-1:
    tmp = max(array1[i], array1[i]-x[i]+rmax_array[i])
    ans = max(ans, tmp)
  else:
    ans = max(ans, array1[i])
  
for i in range(n):
  if i != n-1:
    tmp = max(array2[i], array2[i]-rx[i]+max_array[i])
    ans = max(ans, tmp)
  else:
    ans = max(ans, array2[i])
    
print(ans)

Measured memory_bytes: 77400
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class T> inline T GCD_L(T a,T b){
  T r;
  while(a){
    r=b;
    b=a;
    a=r%a;
  }
  return b;
}
int N;
int X;
int A;
int main(){
  int Lj4PdHRW, res=0;
  rd(N);
  rd(X);
  for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
    rd(A);
    res =GCD_L(res, abs(X-A));
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// int N, X, A;
// {
//   int res = 0;
//   rd(N,X);
//   rep(N){
//     rd(A);
//     res = gcd(res, abs(X-A));
//   }
//   wt(res);
// }


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <chrono>
#include <sstream>
#include <iomanip>
#define INF 1 << 30
#define MOD 1000000007;
#define pi 3.14159265358979
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define reu(i, l, r) for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define D(x) cout << x << endl
#define d(x) cout << x
#define all(x) (x).begin(), (x).end()
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define mp(x, y) make_pair((x), (y))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
static const int dx[] = {0, 0, 1, -1};
static const int dy[] = {-1, 1, 0, 0};

struct place {
  int x;
  int y;
};

int main() { 
  int n, m;
  cin >> n >> m;
  vector<place> a(n);
  vector<place> c(m);
  for (int i = 0; i < n; i++) {
    cin >> a[i].x >> a[i].y;
  }
  for (int i = 0; i < m; i++) {
    cin >> c[i].x >> c[i].y;
  }

  for (int i = 0; i < n; i++) {
    int mind = INF;
    int minj = -1;
    for (int j = 0; j < m; j++) {
      if (mind > abs(a[i].x - c[j].x) + abs(a[i].y - c[j].y)) {
        mind = abs(a[i].x - c[j].x) + abs(a[i].y - c[j].y);
        minj = j;
      }
    }
    D(minj + 1);
  }


  return 0;
}



Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[][] a = new int[3][3];
		for (int i = 0; i < 3; i++)
			Arrays.setAll(a[i], idx -> sc.nextInt());
		
		boolean[][] opened = new boolean[3][3];
		
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			int b = sc.nextInt();
			open(a, opened, b);
		}
		
		String ans = isBingo(opened) ? "Yes" : "No";
		System.out.println(ans);
		
		sc.close();
	}
	
	
	static boolean isBingo(boolean[][] opened) {
		outer:
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < opened[i].length; j++) {
				if (!opened[i][j]) continue outer;
			}
			return true;
		}
	
		outer:
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < opened[i].length; j++) {
				if (!opened[j][i]) continue outer;
			}
			return true;
		}
		
		
		boolean flg = true;
		for (int i = 0; i < 3; i++) {
			if (!opened[i][i]) flg = false;
		}
		if (flg) return true;
		
		flg = true;
		for (int i = 0; i < 3; i++) {
			if (!opened[i][2 - i]) flg = false;
		}
		return flg;
	}
	
	static void open(int[][] a, boolean[][] opened, int b) {
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (a[i][j] == b) {
					opened[i][j] = true;
					return;
				}
			}
		}
	}
}




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

#define int long long int

int32_t main()
{
  int n,m;
  cin>>n>>m;
  //int a,b;

  //set<int> s;
  int a[m],b[m];
  int l,r;
  int ans=0;
  //map<int,int> mp;
  for(int i=0;i<m;++i)
  {
     cin>>a[i]>>b[i];
     if(i==0)
     {
       l=a[i];
       r=b[i];
     }  
     else
     {
       if(min(r,b[i]) < max(l,a[i]))
       {
          cout<<0<<endl;
          return 0;
       }
       else
       {
          l=max(l,a[i]);
          r=min(r,b[i]);
       }
     }
  }

  ans=r-l+1;
  cout<<ans<<endl;


  

  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int N=500+5;
long long n,a[N][N],g[2][N][N],f[N][N],cnt,sum=0x3f3f3f3f3f3f3f3f;
void init(){
	scanf("%lld",&n);
	for(int i=0;++i<=n;) for(int j=0;++j<=n;i==j?:scanf("%lld",&a[i][j]));
}
long long gg(int k,int lx,int ly,int rx,int ry){
	return g[k][rx][ry]-g[k][lx-1][ry]-g[k][rx][ly-1]+g[k][lx-1][ly-1];
}
void work(){
	for(int i=0;++i<=n;){
		for(int j=0;++j<=n;i>=j?:g[0][i][j]=a[i][j],g[0][i][j]+=g[0][i][j-1]);
		for(int j=0;++j<=n;g[0][i][j]+=g[0][i-1][j]);
	}
	for(int i=0;++i<=n;){
		for(int j=0;++j<=n;i<=j?:g[1][i][j]=a[i][j],g[1][i][j]+=g[1][i][j-1]);
		for(int j=0;++j<=n;g[1][i][j]+=g[1][i-1][j]);
	}
	memset(f,0x3f,sizeof(f));
	f[0][0]=0;
	for(int i=-1;++i<=n;) for(int j=-1;++j<max(i,1);) for(int h=i;++h<=n;
		cnt=f[i][j]+gg(1,h+1,j+1,n,i)+gg(0,i+1,i+1,h,h),f[h][i]=min(f[h][i],cnt));
	for(int i=0;++i<=n;sum=min(sum,f[n][i]));
}
void prin(){
	printf("%lld",sum);
}
int main(){
	init();
	work();
	prin();
	return 0;
}

Measured memory_bytes: 8192
import numpy as np
a, b, h, m = map(int, input().split())
t = abs(6 * m - 30 * (h + m / 60))
t = min(360 - t, t)
t = np.deg2rad(t)
c = (a**2 + b**2 - 2 * a * b * np.cos(t))**0.5
print(c)


Measured memory_bytes: 27208
n = int(input())
a = list(map(int, input().split()))

ai = max(a)
a.sort(key=lambda x: abs(ai//2 - x))
aj = a[0]
for i in a:
    if ai==i: continue
    else:
        aj = i
        break

print('{} {}'.format(ai, aj))

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

cities = []
for i in range(M):
    p, y = map(int, input().split(' '))
    cities.append([p, y, i])

cities = sorted(cities, key=lambda x: x[1])
cities = sorted(cities, key=lambda x: x[0])

p = cities[0][0]
cnt = 1
for i in range(M):

    if (cities[i][0] == p):
        cities[i].append(str(p).zfill(6) + str(cnt).zfill(6))
        cnt += 1
    else:
        p = cities[i][0]
        cnt = 1
        cities[i].append(str(p).zfill(6) + str(cnt).zfill(6))
        cnt += 1

cities = sorted(cities, key=lambda x: x[2])

for i in range(M):
    print(cities[i][3])


Measured memory_bytes: 35548
#include <map>
#include <algorithm>
#include <set>
#include <iostream>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
 
    map<int, set<int>> b;
    int h, w, n;
    cin >> h >> w >> n;

    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        b[y].insert(x);
    }

    int ans = h;

    int x = 1, y = 1;

    while (true) {

        auto it = b[y].upper_bound(x);

        int bot = (it == b[y].end()? h + 1: *it);

        ans = min(ans, bot - 1);

        if (x == h || b[y].count(x + 1)) {
            break;
        }
        x++;
        if (!b[y + 1].count(x))
            y++;
    }

    cout << ans << endl;



}


Measured memory_bytes: 26368
import java.util.*;

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

        if((b-a) <= 0){
            System.out.println("delicious");
        } else if((b-a) > 0 && (b-a) <= x){
            System.out.println("safe");
        } else {
            System.out.println("dangerous");
        }
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }
}


Measured memory_bytes: 21716
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
import math

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n = int(rl())
	ans = 0
	for i, a in enumerate(rli(), 1):
		if i % 2 == 1 and a % 2 == 1:
			ans += 1
	print(ans)
	stdout.close()

if __name__ == "__main__":
	main()

Measured memory_bytes: 65104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ld a, b, H, M;
    cin >> a >> b >> H >> M;

    ld th = abs(2 * PI * (M / 60 - H / 12 - M / 720));
    cout << sqrtl(a * a + b * b - 2 * a * b * cosl(th)) << endl;
}

Measured memory_bytes: 4184
#include <iostream>

using namespace std;

int minus_manzoku(int c[], int last[], int d)
{
    int sum = 0;
    int i;
    for (i = 0; i < 26; i++) {
        sum += c[i] * (d - last[i]);
    }
    return sum;
}

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

    int c[26];
    int last[26];
    int i;
    for (i = 0; i < 26; i++) {
        cin >> c[i];
        last[i] = 0;
    }

    int s[D][26];
    int t[D];
    int j;
    for (i = 0; i < D; i++) {
        int max = 0;
        for (j = 0; j < 26; j++) {
            cin >> s[i][j];
            if (max < s[i][j]) {
                max = s[i][j];
                t[i] = j + 1;
            }
        }
    }

    for (i = 0; i < D; i++) {
        cout << t[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3656
n,m,c = map(int,input().split())
B = list(map(int,input().split()))

ans=0
for _ in range(n):
    A = list(map(int,input().split()))
    sum=c
    for a_i,b_i in zip(A,B):
        sum+=a_i*b_i
    if sum>0:
        ans+=1
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
struct curling{ int nx, ny; vector<P> del; };
int d1[4] = { 0,1,0,-1 };
int d2[4] = { 1,0,-1,0 };
int main() {
	int w, h;
	while (cin >> w >> h , w) {
		int fie[22][22];
		rep(i, 22) {
			rep(j, 22) {
				fie[i][j] = -1;
			}
		}
		int sx, sy, gx, gy;
		rep1(i, h) {
			rep1(j, w) {
				cin >> fie[i][j];
				if (fie[i][j] == 2) {
					sx = i; sy = j;
					fie[i][j] = 0;
				}
				if (fie[i][j] == 3) {
					gx = i; gy = j;
					fie[i][j] = 0;
				}
			}
		}
		queue<curling> q; q.push({ sx,sy,{} });
		int chk = 100;
		rep1(out, 10) {
			int len = q.size();
			rep(i, len) {
				curling cop = q.front(); q.pop();
				int x = cop.nx; int y = cop.ny;
				vector<P> del = cop.del;
				int l = del.size();
				rep(j, l) {
					fie[del[j].first][del[j].second] = 0;
				}
				rep(k, 4) {
					int nx = x; int ny = y;
					if (fie[nx + d1[k]][ny + d2[k]] == -1 || fie[nx + d1[k]][ny + d2[k]] == 1) {
						continue;
					}
					while (fie[nx][ny] == 0) {
						nx += d1[k]; ny += d2[k];
						if (nx == gx && ny == gy) {
							chk = min(chk, out);
						}
					}
					if (fie[nx][ny] == 1) {
						vector<P>nex = del;
						nex.push_back({ nx,ny });
						q.push({ nx - d1[k],ny - d2[k],nex });
					}
				}
				rep(j, l) {
					fie[del[j].first][del[j].second] = 1;
				}
			}
		}
		if (chk == 100) {
			cout << -1 << endl;
		}
		else {
			cout << chk << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 12172
#include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;

Int solve(Int n){
	vector<vector<Int>> a(n, vector<Int>(n+1));
	for(Int i=0; i<n; ++i)
		for(Int j=0; j<n+1; ++j)
			cin >> a[i][j];
	Int m = 1<<n;
	vector<Int> dp(m, 1e9);
	dp[0] = 0;
	for(Int i=0; i<m; ++i){
		for(Int j=0; j<n; ++j){
			if(((i>>j)&1) == 0){
				Int c = a[j][0];
				for(Int k=0; k<n; ++k)
					if(((i>>k)&1) == 1)
						c = min(c, a[j][k+1]);
				dp[i|(1<<j)] = min(dp[i|(1<<j)], dp[i]+c);
			}
		}
	}
	return dp[m-1];
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	while(1){
		Int n; cin >> n;
		if(n == 0) return 0;
		cout << solve(n) << "\n";
	}
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<P> a;
    ll x,y;
    rep(i,n){
      cin>>x>>y;
      a.push_back(P(x,y));
    }
    if(n==1){
      cout<<1<<endl;
      return 0;
    }
    map<P,ll> cnt;
    rep(i,n)rep(j,n){
      if(i==j) continue;
      cnt[P(a[i].first-a[j].first,a[i].second-a[j].second)]++;
    }
    ll now=-1,p,q;
    for(auto itr:cnt){
      if(now<itr.second){
        now=itr.second;
      }
    }
    cout<<n-now<<endl;
}

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

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define inf (0x3f3f3f3f)

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

template<class T>inline T read(T &_) {
	T __ = getchar(), ___ = 1; _ = 0;
	for (; !isdigit(__); __ = getchar()) if (__ == '-') ___ = -1;
	for (; isdigit(__); __ = getchar()) _ = (_ << 3) + (_ << 1) + (__ ^ 48);
	return _ *= ___;
}

template<class T>inline bool chkmax(T &_, T __) { return _ < __ ? _ = __, 1 : 0; }
template<class T>inline bool chkmin(T &_, T __) { return _ > __ ? _ = __, 1 : 0; }

inline void proStatus() {
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>());
}

int a[501][501];

int main() {

	int k = read(k);

	if (k <= 500) {
		cout << k << endl;
		for (int i = 1; i <= k; ++ i)
			for (int j = 1; j <= k; ++ j)
				printf("%d%c", i, j == k ? '\n' : ' ' );
		return 0;
	}

	int n = ((k + 3) / 4) << 1;
	cout << n << endl;
	for (int i = 1; i <= n; ++ i)
		for (int j = 1; j <= n; ++ j) {
			a[i][j] = (i + j) % n + (i & 1 ? 0 : n) + 1; 
			if (a[i][j] > k) a[i][j] -= n;
			printf("%d%c", a[i][j], j == n ? '\n' : ' ');
		}


	/*int n = k / 2, m = k & 1;
	  cout << (n + m) << endl;
	  for (int i = 1; i <= n + m; ++ i)
	  for (int j = 1; j <= n; ++ j) 
	  a[i][j] = (i & 1) * n + j;
	  if (m) for (int j = 1; j <= n + m; ++ j) 
	  a[j][n + m] = k;

	  for (int i = 1; i <= n + m; ++ i)
	  for (int j = 1; j <= n + m; ++ j) 
	  printf("%d%c", a[i][j], j == n + m ? '\n' : ' ');*/

	return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <list>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit)

int main()
{
    list<int> A;
    int n;
    auto it = A.end();
    cin >> n;
    repi(i, n, 0)
    {
        int op, x, d;
        cin >> op;
        if (op == 0)
        {
            cin >> x;
            A.insert(it,x);
            it--;
        }
        else if (op == 1)
        {
            cin >> d;
            advance(it,d);
        }
        else if (op == 2)
        {
            it = A.erase(it);
        }
    }
    repm(i,A){
        cout << *i << endl;
    }
    return 0;
}


Measured memory_bytes: 18544
#include<cstdio>
#include<algorithm>
using namespace std;
const int N = 300303;
int cnt[N],s[N],len,n,k;
int main() {
	scanf("%d%d",&n,&k);
	for (int i=1; i<=n; i++) {int x; scanf("%d",&x); cnt[x]++;}
	for (int i=1; i<=n; i++) if (cnt[i]) s[++len]=cnt[i];
	sort(s+1,s+len+1);
	if (k>=len) {puts("0"); return 0;}
	int ans=0; for (int i=1; i<=len-k; i++) ans+=s[i];
	printf("%d",ans);
	return 0; 
}

Measured memory_bytes: 1664
program test
implicit none
integer::N,i,dt,dd,check
integer,allocatable::x(:),y(:),t(:)
read(*,*)N
allocate(x(0:N),y(0:N),t(0:N))
x(0)=0
y(0)=0
t(0)=0
check=0
do i=1,N
	read(*,*)t(i),x(i),y(i)
	dd=abs(x(i)-x(i-1))+abs(y(i)-y(i-1))
    dt=abs(t(i)-t(i-1))
    if(mod(dd,2)==mod(dt,2) .and. dd<=dt)then
    	check=check
    else
    	check=check+1
        exit
    end if
end do
if(check==0)then
	print*,'Yes'
else 
	print*,'No'
end if
end program

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes                \
    cout << "Yes" << endl; \
    return 0;
#define No                \
    cout << "No" << endl; \
    return 0;
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

template <typename T>
void print(const T &v);

int N, M, Q;
vector<vector<int>> pt;

void dps(int depth, vector<int> v)
{
    if (depth == N)
    {
        pt.push_back(v);
        return;
    }
    for (int i = v[v.size() - 1]; i <= M; i++)
    {
        vector<int> cp = v;
        cp.push_back(i);
        dps(depth + 1, cp);
    }
    return;
}

int main()
{
    ll A, B, N;
    cin >> A >> B >> N;
    ll x = B - 1;
    x = min(x, N);
    cout << ((A * x) / B) - (A * (x / B)) << endl;
    return 0;
    // while (true)
    // {
    //     ll x = (B + A - 1) / A;
    //     cout << ((A * x) / B) - (x / B) << endl;
    // }
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << " ";
        cout << v[i];
    }
    cout << endl;
}


Measured memory_bytes: 3628
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {
        // write your code here
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            if (n == 0) break;
            int[] temp = new int[n];
            int sum = 0;
            for (int i = 0; i < n; i++) {
                temp[i] = sc.nextInt();
            }
            Arrays.sort(temp);
            for (int i = 1; i < n - 1; i++) {
                sum += temp[i];
            }
            System.out.println(sum / (n - 2));
        }
    }
}

Measured memory_bytes: 20968
N = int(input())
a = list(map(int,input().split()))
b = []
c = 0

for i in range(N):
  if a[i] == c+1:
    b.append(c+1)
    c += 1

if c != 0:
  print(N-len(b))
elif c == 0:
  print(-1)

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  string s;
  cin >> s;
  bool c = false;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'C') c = true;
    if (c && s[i] == 'F') {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


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

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N, vector<int>(M));
    rep(i,N){
        cin >> C[i];
        rep(j,M) cin >> A[i][j];
    }

    int ans = INF;
    rep(s,1<<N){
        int cost = 0;
        vector<int> d(M);
        rep(i,N) {
            if (s>>i&1) {
                cost += C[i];
                rep(j,M) d[j] += A[i][j];
            }
        }
        bool OK = true;
        rep(i,M) if(d[i]<X) OK = false;
        if (OK) ans = min(ans, cost);
    }
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);


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

  int k, t;
  cin >> k >> t;

  priority_queue<int> a;
  rep(i, t) {
    int tmp;
    cin >> tmp;
    a.push(tmp);
  }

  int prev = 0;
  while (!a.empty()) {
    int x = a.top(); a.pop();
    if (prev != 0) a.push(prev);
    x--;
    prev = x;
  }

  cout << prev << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
	double a,b,c,h;
	
	scanf("%lf %lf %lf",&a,&b,&c);
	
	h=b*sin(M_PI*c/180);
	
	printf("%f\n",a*h/2);
	printf("%f\n",a+b+sqrt(( a-(b*cos(M_PI*c/180)) )*( a-(b*cos(M_PI*c/180)) )+h*h));
	printf("%f\n",h);
	
	return 0;
}

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

int main() {
  int N,M,Q,I=1,Z=0;
  cin>>N>>M>>Q;
  vector<int> A(Q);
  vector<int> B(Q);
  vector<int> C(Q);
  vector<int> D(Q);
  for(int i=0;i<Q;i++){
    cin>>A.at(i)>>B.at(i)>>C.at(i)>>D.at(i);
    A.at(i)--,B.at(i)--;
  }
  vector<int> q(N+M-1);
  for(int i=0;i<N+M-1;i++){
    if(i>=M-1){
      q.at(i)=1;
    }
    else{
      I*=N+M-1-i;
      I/=1+i;
    }
  }
  
  for(int i=0;i<I;i++){
    vector<int> p;
    int a=1,X=0;
    for(int j=0;j<N+M-1;j++){
      if(q.at(j)==1){
        p.push_back(a);
      }
      else{
        a++;
      }
    }
    for(int j=0;j<Q;j++){
      if(p.at(B.at(j))-p.at(A.at(j))==C.at(j)){
        X+=D.at(j);
      }
    }
    Z=max(Z,X);
    if(i!=I-1){
      next_permutation(begin(q),end(q));
    }
  }
  cout<<Z<<endl;
  
}

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

static const long long MOD=1e9+7;

int n,k;
vector<vector<int>> g;

long long dfs(int k, int v, int p){ 
    int color=(p==-1)?k-1:k-2;
    //cout<<"color: "<<color<<endl;
    if(k<g[v].size()) return 0;
    long long res=1;
    for(auto nv: g[v]){
        if(nv==p) continue;
        res*=color--;
        res%=MOD;
    }
    for(auto nv: g[v]){
        if(nv==p) continue;
        res*=dfs(k,nv,v);
        res%=MOD;
    }
    //cout<<"k: "<<k<<" v: "<<v<<" p: "<<p<<endl;
    //cout<<"res: "<<res<<endl;
    return res;
}

int main(){
    cin>>n>>k;
    g.resize(n);
    for(int i=0;i<n-1;++i){
        int a,b;
        cin>>a>>b;
        --a,--b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    long long res=(k*dfs(k,0,-1))%MOD;
    cout<<res<<endl;
}

Measured memory_bytes: 13464
import java.util.*;

public class Main {
    public static void main(String[] args) {
        ArrayList<String[]> list = new ArrayList<String[]>();
        int[][] tramp = new int[4][14];
        //S:0 H:1 c:2 D:3
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int n = Integer.parseInt(line);
        for(int i = 0; i < n; i++) {
            String line1 = sc.nextLine();
            String[] linesp1 = line1.split(" ");
            list.add(linesp1);
        }

        for(int i = 0; i < list.size(); i++) {
            String mark = list.get(i)[0];
            int num = Integer.parseInt(list.get(i)[1]);
            if(mark.equals("S")) {
                tramp[0][num] = 1;
            }else if(mark.equals("H")) {
                tramp[1][num] = 1;
            }else if(mark.equals("C")) {
                tramp[2][num] = 1;
            }else if(mark.equals("D")) {
                tramp[3][num] = 1;
            }
        }
        
        for(int i = 0; i < 4; i++) {
            for(int j = 1; j <= 13; j++) {
                
                if(tramp[i][j] != 1) {
                    if(i == 0) {
                        System.out.println("S " + j);
                    } else if(i == 1) {
                        System.out.println("H " + j);
                    } else if(i == 2) {
                        System.out.println("C " + j);
                    } else if(i == 3) {
                        System.out.println("D " + j);
                    } 
                }
                
            }
        }
        
        
    }
}


Measured memory_bytes: 26352
import math
n, d = map(int, input().split())
x = []
cnt = 0
for i in range(n):
    x.append(list(map(int, input().split())))
for i in range(n):
    for j in range(i+1, n):
        l = sum((x[i][k]-x[j][k])**2 for k in range(d))
        if math.sqrt(l).is_integer():
            cnt += 1
print(cnt)

Measured memory_bytes: 3064
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

K, A, B = map(int, input().split())

bis = 1
do = 0
if B <= A+2:
    bis += K
else:
    bis += A-1
    do += A-1
    remain_do = K - do
    if remain_do % 2 == 0:
        AB = remain_do//2
        bis += (B-A)*AB
    else:
        AB = remain_do//2
        bis += (B-A)*AB
        bis += 1
print(bis)


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, c, solveCnt = 0, result = 0;
    cin >> n >> m >> c;
    int amat[n][m] = {0}, bmat[m] = {0};
    for (int i = 0; i < m; i++)
        cin >> bmat[i];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            cin >> amat[i][j];
    for (int i = 0; i < n; i++){
        result = 0;
        for (int j = 0; j < m; j++){
            result += amat[i][j] * bmat[j];
        }
        if(result + c > 0)
            solveCnt++;
    }
    cout << solveCnt << "\n";
    return 0;
}


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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define DUP(x, y) (((x) + (y) - 1) / (y))

using ll = std::int64_t;
using vint = std::vector<int>;
using vll = std::vector<ll>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

void Main() {
    int n, m;
    cin >> n >> m;
    vint v(m, 0);
    rep(i, n) {
        int k;
        cin >> k;
        rep(j, k) {
            int x;
            cin >> x;
            ++v[x - 1];
        }
    }

    int ans = 0;
    rep(i, m) {
        if (v[i] == n)++ans;
    }
    cout << ans << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
using namespace std;
int N;
int MOD = 1e9 + 7;
int main(){
    cin >> N;
    long long ans = 1;
    rep1(i,N) ans = (ans % MOD) * i;
    cout << ans % MOD << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
ll N;
  cin >>N;
  ll data[2][N];
  rep(i,2) {
    rep(j,N) {
cin >>data[i][j];
    }
  }
  vl vec(N);
  rep(i,N) {
    ll sum=0;
    rep(k,i+1) {
      sum+=data[0][k];
    }
   
    repl(j,i,N) {
      sum+=data[1][j];
    }
    
    
    vec.at(i)=sum;
  }
  
  
 
  sort(all(vec));
  cout<<vec.at(N-1)<<endl;
}
  
  

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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  bool f = false;
  for (int i = 0; i < n; i++) {
    string tmp;
    cin >> tmp;
    if (tmp == "Y") {
      cout << "Four" << endl;
      return 0;
    }
  }

  cout << "Three" << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s = sc.next();
    String t = sc.next();
    for(int i = 0;i<n;i++){
      System.out.print(s.substring(i,i+1));
      System.out.print(t.substring(i,i+1));
    }
    System.out.println("");
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000000000000000000

int main(){
    int N; cin >> N;
    long long A[N],ans = 1;
    int z = 0;

    for(int i = 0; i < N;i++){
        cin >> A[i];
    }

    for(int i = 0;i < N;i++){
     if(A[i] == 0){
        z++;
     }
    }

    if(z > 0){
     cout << 0 << endl;
     return 0;
    }

    for(int i = 0;i < N;i++){
        if(A[i] <= MAX/ans){
            ans *= A[i];
        }else{
            cout << -1 << endl;
            return 0;
        }
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 4376
#include <stdio.h>
 
int main(int argc, char **argv)
{
    int a, b, c;
 
    scanf("%d %d %d", &a, &b, &c);
    int i;
 
    for (i=0; a<=b; a++) {          
        if (c % a == 0) i++;        
    }
    printf("%d\n", i);
 
    return 0;
}

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

int main(){
  int a,b;cin>>a>>b;
  
  int ans=0;
  
  for(int i=1;i<=1000;i++){
    if(((int)(i*0.08)==a)&&((int)(i*0.1)==b)){cout<<i<<endl;return 0;}
  }
  
  cout<<-1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 10000000000000009
//#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl


signed main(){
    int N,W;
    cin >> N >> W;
    int w[114],v[514];
    int V=0;
    REP(i,N){
        cin >> w[i] >> v[i];
        V=max(V,v[i]);
    }
    int dp[114514];
    REP(i,N*V+1){
        dp[i]=INF;
    }
    dp[0]=0;
    
    for(int i=0;i<N;i++){
        for(int j=N*V;j>=v[i];j--){
            dp[j]=min(dp[j],dp[j-v[i]]+w[i]);
        }
    }
    int Ans=0;
    REP(i,N*V+1){
        if(dp[i]!=INF && dp[i]<=W){
            Ans=i;
        }
    }
    cout << Ans << endl;
    
    /*REP(i,N*V){
        if(dp[i]==INF){
            cout << "INF ";
        }else{
            cout << dp[i] << " " ;
        }
    }*/
    return 0;
}   


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

bool valid(int x){
    bool res = false;
    for(int i=0;i*i<=x/2;i++){
        int j = int(sqrt(x-i*i)+.01);
        res |= i*i + j*j == x;
    }
    return res;
}

int solve(){
    int m, n;
    cin >> m >> n;
    int A = m*m + n*n;
    bool prime = true;
    for(int i=2;i*i<=A;i++){
        if(A%i==0){
            if(valid(i)&&valid(A/i)) prime = false;
        }
    }
    cout << (prime ? 'P' : 'C') << endl;
    return 0;
}

int main(){
    // while(solve()==0);
    int t; cin >> t; for(;t>0;t--) solve();
    return 0;
}



Measured memory_bytes: 2976
{-# OPTIONS_GHC -O #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ViewPatterns #-}

import Control.Monad
import Data.List
import Data.Bits ((.&.), popCount)
import qualified Data.ByteString.Char8 as B

main = do
    n <- readLn :: IO Int
    --
    ss <- replicateM n $ sum.zipWith (\p b -> b * p) (iterate (*2) 1).unfoldr (B.readInt.B.dropWhile(==' ')) <$> B.getLine
    --
    vs <- replicateM n $ unfoldr (B.readInt.B.dropWhile(==' ')) <$> B.getLine
    --
    print $ maximum $ map (f 0 ss vs) [1..1023]
    --
    where
        f a [] _ _ = a
        f a (s:ss) (v:vs) i = f (a + (v !! (popCount (s .&. i)))) ss vs i

Measured memory_bytes: 1020
#include <iostream>
using namespace std;
int main(void){
    int x,n;
    cin>>x>>n;
    int P[n];
    int a=300;
    int answer=100000;
    for(int i=0;i<n;i++){
        cin>>P[i];
    }
    bool flag=true;
    for(int i=-100;i<1000;i++){
        for(int j=0;j<n;j++){
            if(P[j]==i){
                flag=false;
            }
        }
        if(flag){
            if(a>abs(x-i)){
                a=abs(x-i);
                answer=i;
            }
        }
        flag=true;
    }
    cout<<answer<<endl;
    
}


Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
using namespace std;
main(){
  long long n;
  int k;
  long long x,y;
  //タイルは(1,1)から(n,n)まで
  cin>>n>>k;
  for(int i=0;i<k;i++){
    cin>>x>>y;
    if(x<n/2&&y<n/2){
      cout<<((min(x,y)-1)%3)+1<<endl;
    }
    else if(x>=n/2&&y<n/2){
      cout<<((min(n-x+1,y)-1)%3)+1<<endl;
    }
    else if(x<n/2&&y>=n/2){
      cout<<((min(x,n-y+1)-1)%3)+1<<endl;
    }
    else{
      cout<<((min(n-x+1,n-y+1)-1)%3)+1<<endl;
    }
  }
}

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

#define ALL(a) (a).begin(), (a).end()
#define llong long long

using namespace std;

// root ::= '(' node ')[' inum '](' node ')'
// node ::= ep | '(' node ')[' inum '](' node ')'

struct node{
	int n;
	unique_ptr<node> left, right;
	node() = default;
	node(node&& c):n(c.n),left(move(c.left)),right(move(c.right)){}
	node(int n_):n(n_){}

	bool operator==(const node &rhs)const {
		return *left == *(rhs.left) && *right == *(rhs.right);
	}
	void print(){
		cout << "(";
		if(left)left->print();
		cout << ")[" << n << "](";
		if(right)right->print();
		cout << ")";
	}
};

struct parser{
	string str;
	parser(const string &str_):str(str_){}
	node parse(){return root(); }
	node root(){
		node ret;
		size_t idx = 0;
		assert(str[idx] == '(');
		ret.left = child(++idx);
		assert(str[idx] == ')');
		idx += 2;
		assert(isdigit(str[idx]));
		ret.n = inum(idx);
		assert(str[idx] == ']');
		idx += 2;
		ret.right = child(idx);
		assert(str[idx] == ')');
		return ret;
	}

	unique_ptr<node> child(size_t &idx){
		if(str[idx] == ')')return nullptr;
		assert(str[idx] == '(');
		unique_ptr<node> ret(new node());
		ret->left = child(++idx);
		assert(str[idx] == ')');
		idx += 2;
		assert(isdigit(str[idx]));
		ret->n = inum(idx);
		assert(str[idx] == ']');
		idx += 2;
		ret->right = child(idx);
		assert(str[idx] == ')');
		idx++;
		return ret;
	}

	int inum(size_t &idx){
		int i = idx;
		while(isdigit(str[idx]))idx++;
		return stoi(str.substr(i, idx-i));
	}
};

node gattai(const node &left, const node &right){
	node ret(left.n + right.n);
	if(left.left && right.left){
		ret.left = unique_ptr<node>(new node(gattai(*left.left, *right.left)));
	}
	if(left.right && right.right){
		ret.right = unique_ptr<node>(new node(gattai(*left.right, *right.right)));
	}
	return ret;
}

signed main(){
	string s1,s2; cin >> s1 >> s2;
	parser p1(s1),p2(s2);
	node l(p1.parse()), r(p2.parse());
	auto ans = gattai(l,r);
	ans.print();
	cout << endl;


	return 0;
}




Measured memory_bytes: 3252
#include<stdio.h>
#include<string.h>
int main(void)
{
	int s,d,f,g,i;
	char a[10001];
	while(scanf("%s",a)!=EOF){
		s=0;
		d=0;
		for(i=0;i<strlen(a);i++){
			if(a[i]=='J'&&a[i+1]=='O'&&a[i+2]=='I'){
				s++;
			}
			if(a[i]=='I'&&a[i+1]=='O'&&a[i+2]=='I'){
				d++;
			}
		}
		printf("%d\n",s);
		printf("%d\n",d);
		
	}
	return 0;
}

Measured memory_bytes: 980
N = int(input())
list = [int(i) for i in input().split()]
sortlist = sorted(list, reverse=True)
Alice = 0
Bob = 0

for i in range(N):
    if i % 2 == 0:
        Alice += sortlist[i]
    else:
        Bob += sortlist[i]

print(Alice - Bob)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#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 rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-6;
const ll LINF = 100200300400500600ll;
const int INF = 1001001001;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
const int dx[4] = {0,1,0,-1};
const int dy[4] = {-1,0,1,0};
const int mod = 1000000007;

void Main(){
  int n;
  cin>>n;
  v(pll) a(n);
  cin>>a;
  sort(a.begin(),a.end(),
    [](auto x, auto y){
      return(x.se<y.se);
    }
  );
  ll time=0;
  int ok = 1;
  rep(i,n){
    time+=a[i].first;
    if(time>a[i].second) ok=0;
  }
  if(ok){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }


} signed main(int argc,char** argv)
{fastio; myio; myloopset Main();}


Measured memory_bytes: 3456
h,w,k=map(int,input().split())
l=[list(input()) for i in range(h)]

count=[]
for i in range(h):
  L=[0]
  for j in range(w):
    L.append(int(l[i][j])+L[-1])
  count.append(L)

b=[]
for i in range(2**(h-1)):
  b.append(format(i,'0'+str(h-1)+'b'))

ans=[]
cut=0
for i in range(len(b)):
  cutct=0
  cut=0
  f=0
  for j in range(1,w+1):
    ct=[]
    for j2 in range(h):
      ct.append(count[j2][j]-count[j2][cut])
    check=[]
    x=ct[0]
    for j3 in range(h-1):
      if b[i][j3]=='0':
        x+=ct[j3+1]
      else:
        check.append(x)
        x=ct[j3+1]
    check.append(x)
    if max(check)>k:
      if cut-j<=1:
        ctcheck=[]
        for j2 in range(h):
          ctcheck.append(count[j2][j-1]-count[j2][cut])
        check=[]
        x=ctcheck[0]
        for j3 in range(h-1):
          if b[i][j3]=='0':
            x+=ctcheck[j3+1]
          else:
            check.append(x)
            x=ctcheck[j3+1]
        check.append(x)
        if max(check)>k:
          f=1
      cut=j-1
      cutct+=1
  ct1=0
  for j4 in range(h-1):
    if b[i][j4]=='1':
      ct1+=1
  if f==0:
    ans.append(cutct+ct1)
print(min(ans))

Measured memory_bytes: 59996
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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 gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;

int const D = 60;
int const MAX_N = 200005;
int to[D][MAX_N]; // to[i][v] := v から 2のi乗個先の頂点

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

int n; ll k;
cin >> n >> k;
rep(i,n) {
    cin >> to[0][i];
    to[0][i]--;
}

rep(i,D-1) {
    rep(j,n) {
        to[i+1][j] = to[i][to[i][j]];
    }
}

int v = 0;
drep(i,D) {
    ll l = 1ll << i;
    if(l <= k) {
        v = to[i][v];
        k -= l;
    }
}

cout << v+1 << endl;
return 0;
}

Measured memory_bytes: 50480
#include <stdio.h>

int main(void)
{
    int A, B, C;
    char c;
    
    
    scanf("%d%c%d%c%d", &A, &c, &B, &c, &C);
    
    
    if(A == B && A == C && B == C)
        printf("Yes\n");
    else
        printf("No\n");
    
    //system("pause");
    
    return 0;
}


Measured memory_bytes: 128