akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<fstream>
#include<time.h>
#include<iterator>
#include<random>

//#pragma warning( disable:4996 )
using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

int MOD = (ll)1000000000 + 7;

const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 500050;


int N, D[100];
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	REP(i, N) {
		cin >> D[i];
		D[i] = min(D[i], 24 - D[i]);
	}
	int ans = 0;
	if (N >= 24) {
		print(0);
		return 0;
	}
	else if (N >= 12) {
		map<int, int>mp;
		mp[0] = 1;
		REP(i, N) {
			mp[D[i]]++;
		}
		ans = 1;
		REP(i, 13) {
			if (mp[i] >= 3)ans = 0;
		}
		print(ans); return 0;
	}
	else {
		FOR(i,0, 1 << N) {
			multiset<int>st;
			st.insert(0);
			REP(j, N) {
				if (i&(1<< j)) {
					st.insert(24 - D[j]);
					//pe(24 - D[j]);
				}
				else {
					st.insert(D[j]);
					//pe(D[j]);
				}
			}
			//cout << endl;
			auto itr1 = st.begin(), itr2 = st.begin();
			itr2++;
			int res = INF;
			while (itr2 != st.end()) {
				int dif = 0;
				if (*itr1 == 0) {
					dif = min(*itr2, 24 - *itr2);
				}
				else if (*itr2 == 0) {
					dif = min(*itr1, 24 - *itr1);
				}
				else {
					dif = abs(*itr1 - *itr2);
				}
				res = min(res,dif);
				itr1++; itr2++;
			}
			res = min(res,min(*itr1, 24 - *itr1));
			ans = max(ans, res);
		}
	}
	print(ans);
}


Measured memory_bytes: 256
S = input().strip()
N = len(S)+1
A = [0 for _ in range(N)]
B = []
for i in range(N):
    if i==0 and S[i]=="<":
        B.append(0)
    elif i<N-2 and S[i]==">" and S[i+1]=="<":
        B.append(i+1)
    elif i==N-2 and S[i]==">":
        B.append(i+1)
for j in range(len(B)-1):
    ind0 = B[j]
    ind1 = B[j+1]
    c = ind0
    while S[c]=="<":
        A[c+1] = max(A[c+1],A[c]+1)
        c += 1
    c = ind1
    while S[c-1]==">":
        A[c-1] = max(A[c-1],A[c]+1)
        c -= 1
c = B[0]
if c>0:
    for i in range(c-1,-1,-1):
        A[i] = A[i+1]+1
c = B[-1]
if c<N-1:
    for i in range(c+1,N):
        A[i] = A[i-1]+1
print(sum(A))

Measured memory_bytes: 24092
#include<iostream>
int main(){
  int sec,h,m,s;
  std::cin >> sec;
  h = sec / 3600;
  m = (sec - h * 3600) / 60;
  s = sec - h * 3600 - m * 60;
  std::cout << h << ":" << m << ":" << s << std::endl;
}

Measured memory_bytes: 3108
#include<iostream>
using namespace std;
int main()
{
    long long n,sum=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        if(i%3!=0&&i%5!=0)
        {
            sum+=i;
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+10;
const ll mod = 998244353;
int main() {
    ios::sync_with_stdio(0);
    int n,m;
    cin>>n>>m;
    if(m>=n)
        cout<<"unsafe"<<endl;
    else
        cout<<"safe"<<endl;
    return 0;
}


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

int main() {
  int i, N, K, x, count=0, ans=0;
  
  cin >> N >> K;
  
  vector<int> num(N);
  vector<int> num2(N);

  rep(i,N) {
    cin >> x;
    num[x-1] +=1;
  }
  
  rep(i,N){
    if(num[i]!=0){
      num2[count] =num[i];
      count+=1;
    }
  }
  
  sort(num2.begin(),num2.begin()+count);
  for(i=0;count>K;i++){
    ans+=num2[i];
    count--;
  }
  cout << ans;
}

Measured memory_bytes: 4808
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve();
			Console.Out.Flush();
		}

		const int mod = 1000000007;  // 10^9+7
		static int Mod(long x, int m) { return (int)((x % m + m) % m); }
		static long Mod(long x, long m) { return (x % m + m) % m; }

		static public void Solve()
		{
			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();

			int n = int.Parse(Console.ReadLine());
			string s = Console.ReadLine();

			int ans = 0;
			HashSet<char> map = new HashSet<char>();
			for (int i = 1; i < n; i++) {
				int c = 0;
				map.Clear();
				for (int j = 0; j < n; j++) {
					if (j < i) {
						map.Add(s[j]);
					} else {
						if (map.Contains(s[j])) {
							map.Remove(s[j]);
							c++;
						}
					}
				}
				ans = Math.Max(ans, c);
			}
			Console.WriteLine(ans);

		}
	}
}


Measured memory_bytes: 27880
N = gets.to_i
txys = readlines.map { |l| l.chomp.split.map(&:to_i) }

pos = [0, 0, 0]
txys.each do |t, x, y|
  diff = (pos[1] - x).abs + (pos[2] - y).abs
  time = (pos[0] - t).abs
  if time == diff || time > diff && (time - diff).even?
    pos = [t, x, y]
    next
  else
    puts('No')
    exit
  end
end
puts('Yes')

Measured memory_bytes: 16636
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
set<string>S;
char in[20];
int main(){
	char las='a';
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%s",in);
		string tmp=in;
		if(S.count(tmp)){
			printf("No\n");return 0;
		}
		if(i&&las!=in[0]){
			printf("No\n");return 0;
		}
		S.insert(tmp);
		las=in[strlen(in)-1];

	}
	printf("Yes\n");
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
typedef pair<double,string> P;
double eps=1e-9;
bool comp(const P& l,const P& r){
	if(abs(l.fs-r.fs)<eps) return l.sc<r.sc;
	else return l.fs>r.fs;
}
int main(){
	while(true){
		int n;
		cin>>n;
		if(n==0) break;
		vector<P> vc;
		rep(i,n){
			string l;
			int p,a,b,c,d,e,f,s,m;
			cin>>l>>p>>a>>b>>c>>d>>e>>f>>s>>m;
			int ti=a+b+c+(d+e)*m,ri=f*m*s-p;
			vc.push_back(P((double)ri/ti,l));
		}
		sort(all(vc),comp);
		rep(i,n) cout << vc[i].sc<<endl;
		cout << "#\n";
	}
}

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

using namespace std;

int main(int argc, const char *argv[]) {
  int a, b, c, k;
  cin >> a >> b >> c >> k;

  while (k > 0 && a >= b) {
    b *= 2;
    k--;
  }

  while (k > 0 && b >= c) {
    c *= 2;
    k--;
  }

  if (b > a && c > b) {
    cout << "Yes" << '\n';
  } else {
    cout << "No" << '\n';
  }

  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ll long long int
#define vi         vector<int>
#define vll        vector<ll>
#define vpii       vector<pair<int,int>>
#define pr        pair<int,int>
#define vpll       vector<pair<ll,ll>>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(container) int((container).size())
#define mape map<int,int>
const ll mod=1e9+7;
const int N=1e6+5;
//cout << fixed << setprecision(6) <<
using namespace std;
bool b[N];
int main()
{
    map<int,int>m;
    FOR(i,1,N-1)
    b[i]=1;
    int n;
    cin>>n;
    int a[n+1],ans=0;
    FOR(i,1,n)
    {
      cin>>a[i];
      m[a[i]]++;
    }
    a[0]=0;
    sort(a,a+n+1);
    FOR(i,1,n)
    {
        if(b[a[i]] )
        {
            if(m[a[i]]==1)
            ans++;
            for(int j=a[i];j<=1e6+1;j+=a[i])
            b[j]=0;
        }
    }
    cout<<ans;
}

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

using namespace std;

int main() {
	int a,b,c,k; scanf("%d %d %d %d", &a,&b,&c,&k);

	int ans = 0;

	if(a >= k) {
		ans = k;
		k = 0;
	}
	else {
		ans = a;
		k -= a;
	}

	if(b >= k) k = 0;
	else {
		k -= b;
	}

	/*if(c >= k) {
		ans -= k;
		k = 0;
	}
	else {
		ans -= c;
		k -= a;
	}*/

	ans -= k;

	cout<<ans<<endl;	

	return 0;
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m,i,a[51],d,c;
string s;
int main(){
  for(cin>>n>>m;i<m;i++,a[c]++,a[d]++){
    cin>>c>>d;
  }
  for(i=1;i<=n;i++)cout<<a[i]<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

  // dataのすぐ左にあるaの要素のindexを返す
  static int binarysearch(long[] a, long data) {
    int ok = 0;
    int ng = a.length;
    int mid = (ok + ng) / 2;
    while (ng - ok > 1) {
      if (a[mid] < data) {
        ok = mid;
      } else {
        ng = mid;
      }
      mid = (ok + ng) / 2;
    }
    return ok;
  }

  static long calc(long[] s, long[] t, long x) {
    long[] a, b;
    long[] ans = new long[8];
    int ans_idx = 0;
    for (int i = 0; i < 2; i++) {
      if (i == 0) {
        a = s;
        b = t;
      } else {
        a = t;
        b = s;
      }
      for (int j = 0; j < 2; j++) {
        int apor = binarysearch(a, x) + j;
        long ax = a[apor];
        for (int k = 0; k < 2; k++) {
          int bpor = binarysearch(b, ax) + k;
          long bx = b[bpor];
          ans[ans_idx++] = Math.abs(x - ax) + Math.abs(ax - bx);
        }
      }
    }
    long min = Long.MAX_VALUE;
    for (int i = 0; i < 8; i++) {
      if (min > ans[i]) {
        min = ans[i];
      }
    }
    return min;
  }

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int a = scanner.nextInt();
    int b = scanner.nextInt();
    int q = scanner.nextInt();
    long[] s = new long[a + 2];
    long[] t = new long[b + 2];
    long[] x = new long[q];
    s[0] = Long.MIN_VALUE / 4;
    for (int i = 1; i < a + 1; i++) {
      s[i] = scanner.nextLong();
    }
    s[a + 1] = Long.MAX_VALUE / 4;
    t[0] = Long.MIN_VALUE / 4;
    for (int i = 1; i < b + 1; i++) {
      t[i] = scanner.nextLong();
    }
    t[b + 1] = Long.MAX_VALUE / 4;
    for (int i = 0; i < q; i++) {
      x[i] = scanner.nextLong();
    }
    scanner.close();

    for (int i = 0; i < x.length; i++) {
      System.out.println(calc(s, t, x[i]));
    }
  }
}


Measured memory_bytes: 99912
#ABC 173 C - H and V
import numpy as np

h,w,k = map(int,input().split())
c = np.zeros((h,w)).astype('str')
for i in range(h):
    s = input()
    for j,a in enumerate(s):
        c[i,j] = a
        
cnt = 0
for o in range(2**h):
    for l in range(2**w):
        black = 0
        for m in range(h):
            for n in range(w):
                if ((o>>m)&1==0) and ((l>>n)&1==0) and (c[m,n]=='#'):
                    black += 1
        if black == k:
            cnt += 1
print(cnt)

Measured memory_bytes: 27076
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define vll vector<long long>
#define ll long long
#define pii pair<int,int>
const int mod=1e9+7;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("inputf.txt","r",stdin);
    freopen("outputf.txt","w",stdout);
#endif
    
    int h,w;
    cin>>h>>w;
    char a[h][w];
    ll dp[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a[i][j];
            dp[i][j]=0;
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(i==0 && j==0) dp[i][j]=1;
            else if(i==0){
                if(a[i][j]=='#') dp[i][j]=0;
                else dp[i][j]=dp[i][j-1];
            }
            else if(j==0){
                if(a[i][j]=='#') dp[i][j]=0;
                else dp[i][j]=dp[i-1][j];
            }
            else{
                if(a[i][j]=='#') dp[i][j]=0;
                else dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
            }
            //cout<<dp[i][j]<<" ";
        }
        //cout<<"\n";
    }
    cout<<dp[h-1][w-1]<<"\n";
    return 0;
}

Measured memory_bytes: 12436
import sys
import collections

n = int(input())
a = list(map(int, sys.stdin.readline().split()))
c = collections.Counter(a)
ans = [0 for i in range(sorted(c.keys())[-1]+1)]

for i in c.keys():
    ans[i] = c[i]*(c[i]-1)//2

sans = sum(ans)
for i in a:
    print(sans - ans[i] + ans[i]*(c[i]-2)//c[i])


Measured memory_bytes: 25920
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int a[55],n,k,i,ans=0;
  cin >> n >>k;
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a,a+n,greater<int>());
  for(i=0;i<k;i++){
  ans=ans+a[i];
  }
  cout << ans << endl;
return 0;
}


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

int SumOfDigits(int n) {
    int sum = 0;
    while (n) {
        sum += n%10;
        n /= 10;
    }
    return sum;
}

int main() {
    int N, A, B; cin >> N >> A >> B;
    int total = 0;
    for (int i = 0; i <= N; i++) {
        int sum = SumOfDigits(i);
        if (A <= sum && sum <= B) {
            total += i;
        }
    }
    cout << total << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

dp = [False for _ in range(100001)]
def main():
    x = ri()
    lp = [100, 101, 102, 103, 104, 105]
    dp[0] = True
    for p in lp:
        for i in range(x+1):
            if not dp[i]:
                continue
            if i+p > x:
                continue
            dp[i+p] = True
    if dp[x]:
        print(1)
    else:
        print(0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3992
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
    int a,b[10],c=1,d=1,e=0;
    cin>>a;
    for(int i=0;i<8;i++){
        c=c*10;
        b[i]=a%c/d;
        d=d*10;
        e=e+b[i];
    }
    if(a%e==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    ll a,b;cin>>a>>b;
    ll ans=a+b;
    if (ans%2) cout << "IMPOSSIBLE" << endl;
    else cout << ans/2 << endl;
    return 0;
}

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

int main(){
    size_t X, Y, Z;
    cin >> X >> Y >> Z;
    vector<pair<long, long>> coins(X + Y + Z);
    long ans{0}, a;
    for(auto& i : coins){
        cin >> a >> i.first >> i.second;
        i.first -= a;
        i.second -= a;
        ans += a;
    }
    sort(begin(coins), end(coins), [](auto a, auto b){return a.first + b.second > a.second + b.first;});
    vector<long> c1{0}, c2{0};
    transform(cbegin(coins), cend(coins), back_inserter(c1), [](auto a){return a.first;});
    transform(crbegin(coins), crend(coins), back_inserter(c2), [](auto a){return a.second;});

    vector<long> A, B, C;
    priority_queue<long> p, q;
    auto f = [&p, &Y](auto a, auto i){
        p.push(-i);
        if(p.size() == Y + 1){
            a += p.top();
            p.pop();
        }
        return a += i;
    };
    partial_sum(cbegin(c1), cbegin(c1) + X + Y + 1, back_inserter(B), f);
    swap(p, q);
    swap(Y, Z);
    partial_sum(cbegin(c2), cbegin(c2) + X + Y + 1, back_inserter(C), f);
    transform(cbegin(B) + Z, cend(B), crbegin(C), back_inserter(A), plus<>());
    cout << *max_element(cbegin(A), cend(A)) + ans << endl;
}

Measured memory_bytes: 6772
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e18;

int x[200000], y[200000], n, mx = 0, mn = INF;
int solve1(){
	int a_max = 0, b_min = INF;
	for(int i = 0;i < n;i++){
		int a = min(x[i], y[i]);
		int b = max(x[i], y[i]);
		a_max = max(a_max, a);
		b_min = min(b_min, b);
	}
	return (a_max-mn)*(mx-b_min);
}

typedef pair<int,int> P;
#define fi first
#define se second
priority_queue<int, vector<int>, greater<int> > q;
priority_queue<int> q2;
int solve2(){
	vector<P> v;
	int tmx = 0, tmn = INF;
	for(int i = 0;i < n;i++){
		v.push_back(P(min(x[i], y[i]), i));
		tmx = max(tmx, min(x[i], y[i]));
		q.push(min(x[i], y[i]));
	}
	
	tmn = q.top();
	int res = tmx-tmn;
	sort(v.begin(), v.end());
	//v.push_back(P(max(x[v[0].se], y[v[0].se]), 0));
	
	for(int i = 0;i < n;i++){
		int t1 = max(x[v[i].se], y[v[i].se]);
		int t2 = min(x[v[i].se], y[v[i].se]);
		tmx = max(tmx, t1);
		if(q.top() == t2){
			q.pop();
			q.push(t1);
			tmn = q.top();
		}
		res = min(res, tmx-tmn);
		//printf("%lld %lld\n", tmx, tmn);
	}
	return (mx-mn)*res;
}

signed main(){
	scanf("%lld", &n);
	for(int i = 0;i < n;i++){
		scanf("%lld%lld", &x[i], &y[i]);
		mx = max({mx, x[i], y[i]});
		mn = min({mn, x[i], y[i]});
	}
	int res1 = solve1();
	int res2 = solve2();
	printf("%lld\n", min(res1, res2));
	return 0;
}


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

// 小数点以下桁数
// fixed << setprecision(i)

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

int lcm(int a, int b)
{
  return a * b / gcd(a, b);
}

int main()
{
  int k, ans = 0;

  cin >> k;
  for (int i = 1; i <= k; i++)
  {
    for (int j = 1; j <= k; j++)
    {
      for (int m = 1; m <= k; m++)
        ans += gcd(i, gcd(j, m));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int cnt = 0;
  rep(i,n) {
    if(a[i]!=1) cnt++;
  }
  cout << (cnt - 1) / (k - 1) + 1 << endl;
}

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

#define int long long
#define all(v) begin(v), end(v)
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,b) FOR(i,0,b)

const int INF=500000010;

int n,m;
int a[60],b[60],c[60],d[60];
int ans[51];
signed main(){
  cin>>n>>m;
  for(int i=1;i<=n;i++){
    cin>>a[i]>>b[i];
  }
  for(int i=1;i<=m;i++){
    cin>>c[i]>>d[i];
  }

  for(int i=1;i<=n;i++){
    int temp=INF;
    for(int j=1;j<=m;j++){

      int ret=abs(a[i]-c[j])+abs(b[i]-d[j]);
      //番号が小さいの優先なので等号なし
      if(ret<temp){
        ans[i]=j;
        temp=ret;
      }
    }
  }

  for(int i=1;i<=n;i++){
    cout<<ans[i]<<endl;
  }


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int Min(int n,int m){
  if(n<m) return n;
  else return m;
}
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<Min(a,b)+Min(c,d)<<"\n";
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        System.out.println(c);
        System.out.println(a);
        System.out.println(b);
        sc.close();
    }

}


Measured memory_bytes: 35800
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <class... T> void printl(T&&...){ }
template <class... T> void printc(T&&...){ }
template <class... T> void prints(T&&...){ }
template <class... T> void printd(T&&...){ }
#endif

int main(){
    ll x; cin >> x;
    cout << (x / 11 * 2) + (x % 11 > 6 ? 2 : x % 11 ? 1 : 0) << '\n';
    return 0;
}


Measured memory_bytes: 256
/*
    Author : manu_sy
*/
#include "bits/stdc++.h"
using namespace std;
 
/** Template Begins **/
#define int ll 
typedef long long        ll;
typedef pair<int,int>    PII;
 
#define IOS         ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl        '\n'
#define pb          push_back
#define F           first
#define S           second
#define mp          make_pair
#define all(a)      (a).begin(), (a).end()
#define FOR(i,a,b)  for(int i=a;i<=b;i++)
#define LP(i,n)     for(int i=0;i< n;i++)
 
/* Debug */
 
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.F << "," << P.S << ")";
} 
 
template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
 
template<class TH> void _dbg(const char *sdbg, TH h){ cerr << sdbg << '=' << h << endl; }
 
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',') cerr << *sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}
 
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif
 
/* Debug Ends */
 
const int N = 5e6+7;
 
/** Template Ends **/
int n, k, a[N];
 
signed main() {
 
    IOS;
    cin >> n >> k;
    LP(i,n) cin >> a[i];
    int lo = 1, hi = 1e9;
    auto f = [&] (int len) {
    	int cnt = 0;
    	LP(i,n) {
    		cnt += ((a[i] + len - 1) / len) - 1;
    	}
    	return (cnt <= k);
    };
    while (hi - lo > 1) {
    	int m = (hi + lo) / 2;
    	if (f(m))	hi = m;
    	else lo = m;
    }
    if (f(lo)) cout << lo << endl;
    else if (f(hi)) cout << hi << endl;
    else assert(false);
 
    return 0;
}























Measured memory_bytes: 4996
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vvchar vector<vector<char>>
#define vchar vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int h,n;cin>>h>>n;
    vint a(n),b(n);
    rep(i,n)cin>>a[i]>>b[i];

    //i-1番目までの魔法でhpjの魔物を倒すときの最小魔力
    vvint dp(n+10,vint(h+10,INF));
    dp[0][0]=0;
    
    

    for(int i=0; i<n; i++){
        for(int j=0; j<=h; j++){
            chmin(dp[i+1][j],dp[i+1][max(0LL,j-a[i])]+b[i]);
            chmin(dp[i+1][j],dp[i][j]);
        }
    }
    cout<<dp[n][h]<<endl;
}

Measured memory_bytes: 82360
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;
int v[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int a, b;
	a = 0, b = 0;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> v[i];
		if (v[i] > b) b = v[i];
		if (a < b) swap(a, b);
	}
	for (int i = 1; i <= n; i++)
	{
		if (v[i] == a) printf("%d\n", b);
		else printf("%d\n", a);
	}
	return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N;
	cin >> N;
	int A[100010] = {}; 
	for(int i = 0; i < N; i++){
		int a; 
		cin >> a;
		if(a == 0){
			A[a] ++; 	
			A[a+1] ++; 
			}
		else{
			A[a-1] ++; 
			A[a] ++;
			A[a+1] ++;
		}
	}
	int ans = 0; 
	for(int i = 0; i <= 100000; i++){
		ans = max(ans, A[i]); 
	}
	cout << ans << endl; 
}

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

using namespace std;

#define x first
#define y second

typedef pair<int, int> pii;

int main() {
  int n, m;
  cin >> n >> m;
  pii a[n], c[m];
  for (int i = 0; i < n; i++) {
    cin >> a[i].x >> a[i].y;
  }
  for (int j = 0; j < m; j++) {
    cin >> c[j].x >> c[j].y;
  }
  for (int i = 0; i < n; i++) {
    int dis = INT_MAX, indx = -1;
    for (int j = 0; j < m; j++) {
      int d = abs(a[i].x - c[j].x) + abs(a[i].y - c[j].y);
      if (d < dis) {
        dis = d;
        indx = j;
      }
    }
    cout << indx + 1 << endl;
  }
}


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

int main()
{
    int n,x,y;
    cin >> n >> x >> y;
    --x;
    --y;
    vector<vector<int>> mat(n,vector<int>(n,n+1));

    for(int i = 0; i < n-1; ++i)
    {
        for(int j = i+1; j < n; ++j)
        {
            mat[i][j] = j-i;
            mat[j][i] = j-i;
        }
    }
    mat[x][y] = 1;
    mat[y][x] = 1;
    vector<int> ex = {x,y};
    for(int e : ex)
    {
        for(int i = 0; i < n; ++i)
        {
            for(int j = 0; j < n; ++j)
            {
                if(i == j)
                {
                    continue;
                }
                if(mat[i][j] > mat[i][e]+mat[e][j])
                {
                    mat[i][j] = mat[i][e]+mat[e][j];
                }
            }
        }
    }

    vector<int> ans(n-1);
    for(int i = 0; i < n; ++i)
    {
        for(int j = i+1; j < n; ++j)
        {
            int t = mat[i][j];
            ans[t-1] += 1;
        }
    }

    for(int a : ans)
    {
        cout << a << endl;
    }
}

Measured memory_bytes: 16000
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define INF 1000000007
using namespace std;

long long nibutana(long long key, long long num);
long long nibutanc(long long key, long long num);

vector<long long> a,b,c;
int main(void) {
	long long n,temp;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> temp;
		a.push_back(temp);
	}
	for(int i=0; i<n; i++){
		cin >> temp;
		b.push_back(temp);
	}
	for(int i=0; i<n; i++){
		cin >> temp;
		c.push_back(temp);
	}
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	sort(c.begin(),c.end());
	long long ans=0;
	for(int i=0; i<n; i++){
		ans+=nibutana(b[i],n)*nibutanc(b[i],n);
	}
	cout << ans << endl;
	return 0;
}
long long nibutana(long long key, long long num){
	int ok=-1,ng=num;
	while(abs(ok-ng)>1){
		if(a[(ok+ng)/2]<key)ok=(ok+ng)/2;
		else ng=(ok+ng)/2;
	}
	return ok+1;
}
long long nibutanc(long long key, long long num){
	int ok=num,ng=-1;
	while(abs(ok-ng)>1){
		if(c[(ok+ng)/2]>key)ok=(ok+ng)/2;
		else ng=(ok+ng)/2;
	}
	return num-ok;
}

Measured memory_bytes: 3316
# coding: utf-8
# Your code here!
MOD = 10**9 + 7
N = int(input())
S = list(input())
if S[0] == "W" or S[2*N-1] == "W":
    print(0)
    exit()

L,R = [0], []
total = [0 for i in range(2*N)]
total[0] = 1
l,r = 1,0
prev = "L"
for i in range(1, 2*N):
    if S[i] == S[i-1]:
        if prev == "L":
            R.append(i)
            total[i] = total[i-1] - 1
            r += 1
            prev = "R"
        else:
            L.append(i)
            total[i] = total[i-1] + 1
            l += 1
            prev = "L"
    else:
        if prev == "L":
            L.append(i)
            total[i] = total[i-1] + 1
            l += 1
        else:
            R.append(i)
            total[i] = total[i-1] - 1
            r += 1
    if l < r:
        print(0)
        exit()

if not (len(L) == N and len(R) == N):
    print(0)
    exit()

def fact(n):
    ret = 1
    while n > 1:
        ret = (ret * n) % MOD
        n -= 1
    return ret
    
cnt = 1
for r in R:
    cnt = (cnt * (total[r] + 1)) % MOD
print(cnt * fact(N) % MOD)

Measured memory_bytes: 20788
#include<bits/stdc++.h>
const int M=1e9+7;// M=1e9+7;//M=300000;//
const int N=2e6+5;
typedef long long int ll;
using namespace std;
 
ll cnt(0),sum(0),n,m,x,y,t,i,j,temp,k,ans(0),mn(M),mx(-9e9);

ll pow_mod(ll a,ll b) //to calculate the power
{
	ll M=2e9+7;
	if(b==0)
	{
		return 1;
	}
	if(b==1)
	{
		return a%M;
	}
	ll res=1;
	while(b)
	{
		if(b%2==1)
		{
			res=(res*a)%M;
		}
		a=(a*a)%M;
		b/=2;
	}
	return res;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	for(i=-200;i<200;i++)
	{
		for(j=-200;j<200;j++)
		{
			x=pow_mod(i,5);
			y=pow_mod(j,5);
			if(x-y==n)
			{
				cout<<i<<" "<<j;
				return 0;
			}
		}
	}
	
}

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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(1e5) + 17;

int n, W;
int w[MAXN], v[MAXN];
ll dp[101][MAXN];

bool read() {
    if (!(cin >> n >> W))
        return false;

    forn (i, n)
        cin >> w[i + 1] >> v[i + 1];

    return true;
}

void solve() {
    for (int i = 0; i < n; ++i)
        for (int j = 0; j <= W; ++j) {
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);

            if (j + w[i + 1] <= W)
                dp[i + 1][j + w[i + 1]] = max(dp[i + 1][j], dp[i][j] + v[i + 1]);
        }

    ll res = 0;

    forn (i, W + 1)
        res = max(res, dp[n][i]);

    cout << res << endl;
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
#ifdef SEREZHKA
    freopen("file.in", "r", stdin);
#endif
    
    while (read())
        solve();
    
    return 0;
}



Measured memory_bytes: 78464
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
//#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
int a,b;
int main()
{
	ios::sync_with_stdio(false);
	cin>>a>>b;
	cout<<(b+a-1)/b<<'\n';
	cout<<flush;	 
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/ 

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    #define lmax LLONG_MAX
    #define lmin LLONG_MIN
    #define imax INT_MAX
    #define imin INT_MIN
    #define f(i,a,b) for(long long i=a;i<b;i++)
    #define tc long long t;cin>>t;while(t--)
    #define pb push_back
    #define mp make_pair
    #define gcd __gcd
    #define F first
    #define S second
    #define input(a,n) for(ll i=0;i<n;i++) cin>>a[i];
    #define output(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" ";
    #define up upper_bound
    #define lo lower_bound
    #define endl "\n"
    #define mem(a) memset(a,-1,sizeof(a))
    #define ll long long
    #define umap unordered_map


    int main(){
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif
        
        ll n;
        cin>>n;
        ll a[n];
        f(i,0,n){
            cin>>a[i];
        }
        ll ans=0;
        f(i,0,n-1){
            if(a[i]>a[i+1]){
                ans += a[i]-a[i+1];
                a[i+1]=a[i];
            }
        }

        cout<<ans<<endl;


        return 0;
    }

Measured memory_bytes: 5148
using System;
using System.Collections.Generic;
using System.Linq;

    class Program
    {
        static void Main(string[] args)
        {
            var Q = int.Parse(Console.ReadLine().Split(' ')[1]);
            var S = Console.ReadLine();
            var inputs = new List<List<int>>();
            for(var i = 0;i<Q;i++)
            {
                var tmp = Console.ReadLine().Split(' ').Select(s=>int.Parse(s)).ToList();
                inputs.Add(tmp);
            }
            var Ts = new int[S.Length];
            for(var i = 1;i<S.Length;i++)
            {
                if (S[i - 1] == 'A' && S[i] == 'C')
                {
                    Ts[i] = Ts[i - 1] + 1;
                }
                else
                    Ts[i] = Ts[i - 1];
            }
            foreach (var item in inputs)
                Console.WriteLine(Ts[item[1]-1] - Ts[item[0]-1]);
        }
    }

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n,k;
  cin >> n >> k;
  vl a(n);
  REP(i,n) cin >> a[i];

  vl rui(n+1,0);
  REP(i,n) {
    rui[i+1] = rui[i] + a[i];
  }
  //REP(i,rui.size()) cout << rui[i] << ",";
  //cout << endl;
  REP(i,rui.size()) rui[i] = (rui[i]-i+k)%k;

  //REP(i,rui.size()) cout << rui[i] << ",";
  //cout << endl;

  map<ll,ll> mp;

  FOR(i,1,min(n+1,k)){
    mp[rui[i]] += 1;
  }

  ll ans = 0;
  REP(i,n){
    ans += mp[rui[i]];
    //cout << ans << "  ";
    //REP(j,k){
    //  cout << j << ":" << mp[j] << ", ";
    //}
    //cout << endl;
    mp[rui[i+1]] --;
    if(i+k<n+1) mp[rui[i+k]] ++;
  }
  
  //cout << fixed << setprecision(10);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 15872
b,c;char *m[2]={"NO","YES"};main(a){for(scanf("%*d");~scanf("%d%d%d",&a,&b,&c);printf("%s\n",m[!!(a*a+b*b-c*c)+!!(a*a-b*b+c*c)+!!(a*a-b*b-c*c)<3]));return 0;}

Measured memory_bytes: 580
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,ll> pll;

using u64 = uint64_t;
using u128 = __uint128_t;

u64 binpower(u64 base, u64 e, u64 mod) {
    u64 result = 1;
    base %= mod;
    while (e) {
        if (e & 1)
            result = (u128)result * base % mod;
        base = (u128)base * base % mod;
        e >>= 1;
    }
    return result;
}

bool check_composite(u64 n, u64 a, u64 d, int s) {
    u64 x = binpower(a, d, n);
    if (x == 1 || x == n - 1)
        return false;
    for (int r = 1; r < s; r++) {
        x = (u128)x * x % n;
        if (x == n - 1)
            return false;
    }
    return true;
};

bool MillerRabin(u64 n) { // returns true if n is prime, else returns false.
    if (n < 2)
        return false;

    int r = 0;
    u64 d = n - 1;
    while ((d & 1) == 0) {
        d >>= 1;
        r++;
    }

    for (int a : {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37}) {
        if (n == a)
            return true;
        if (check_composite(n, a, d, r))
            return false;
    }
    return true;
}

int is_square(ll x){
	int sq = sqrt(x);
	rep(i,max(sq-4,0),sq+4){
		if(1LL * i * i == x)return i;
	}
	return -1;
}

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	const ll MAXN = 1e10 + 10;
	const int cube = cbrt(MAXN);
	int p[cube] = {};
	vector<int> primes;
	rep(i,2,cube){
		if(p[i] == false){
			primes.push_back(i);
			for(int j = i; j < cube; j += i){
				p[j] = 1;	
			}
		}
	}
	int n;
	cin >> n;
	vector<ll> v(n), r(n,1), comp(n,1);
	rep(i,0,n)cin >> v[i];	
	for(int p : primes){
		ll cp = 1LL * p * p * p;
		ll sq = 1LL * p * p;
		rep(i,0,v.size()){
			while(v[i] % cp == 0){
				v[i] /= cp;
			}
			if(v[i] % sq == 0){
				v[i] /= sq;
				r[i] *= sq;
				comp[i] *= p;
			}
			else if(v[i] % p == 0){
				v[i] /= p;
				r[i] *= p;	
				comp[i] *= sq;
			}
		}
	}
	map<ll, int> cnt;
	map<ll, ll> gcomp;
	int ans = 0;
	rep(i,0,n){
		ll fir = v[i];	
		ll fcomp = -1;
		if(MillerRabin(fir)){
			fcomp = fir * fir;
		}
		else fcomp = is_square(fir);
		if(fcomp != -1){
			gcomp[v[i] * r[i]] = comp[i] * fcomp;
			++cnt[v[i] * r[i]];
		}
		else{
			++ans;
		}
	}
	for(pll p : cnt){
		if(p.first == 1){
			ans += 1;	
		}
		else{
			auto it = cnt.find(gcomp[p.first]);
			if(it != cnt.end()){
				if(p.second > it->second){
					ans += p.second;
				}
				else if(p.second == it->second && p.first > it->first){
					ans += p.second;
				}
			}
			else{
				ans += p.second;
			}
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 13452
#include <iostream>

int main()
{
	long long N = 0, M = 0;
	std::cin >> N >> M;

	long long min = 1;
	long long max = N;

	for (int i = 0; i < M; i++){
		int L = 0, R = 0;
		std::cin >> L >> R;
		if (R <= max) max = R;
		if (min <= L) min = L;
	}
	
	int ans = (max - min >= 0) ? max - min + 1: 0;
	
	std::cout << ans << std::endl;

	return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;


int main(){
    ll x;cin >>x;
    vector<ll>sum(1e5+100,0);
    for (int i = 0; i < 1e5; ++i) {
        sum[i+1]=sum[i]+i+1;
    }
    for (int i = 0; i < 1e5; ++i) {
        if(sum[i]>=x){
            cout <<i<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
using namespace std;
using P = pair<int, int>;
using ll = long long;

const int M = 1000005;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    vector<int> cnt(M);
    for(int x:a){
        if(cnt[x] != 0){
            cnt[x] = 2;
            continue;
        }
        for(int i=x; i<M; i+=x) cnt[i]++;
    }
    int ans = 0;
    for(int x:a) if(cnt[x] == 1) ans++;

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

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

using namespace std;

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

int main() {
    int N, X;
    int ans;

    cin >> N >> X;
    for (int i = 0; i < N; i++) {
        int pos;
        int dis;
        cin >> pos;

        dis = abs(pos-X);
        if (i == 0) {
            ans = dis;
        } else {
            ans = gcd(dis, ans);
        }
    }

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


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

typedef pair< int, int > pii;
#define for_(i,a,b) for(int i=(a);i<(b);++i)

void maxUpdate(int& a, int b) {
	a = max(a, b);
}

int main() {
	int n, d, x;
	cin >> n >> d >> x;
	
	vector< vector< int > > p(d, vector< int >(n, 0));
	for_(i,0,d) for_(j,0,n) cin >> p[i][j];
	
	for_(i,0,d-1) {
		vector< int > dp(x+1, 0);
		for_(j,0,n) for_(k,0,x+1) if (k >= p[i][j]) maxUpdate(dp[k], dp[k - p[i][j]] + p[i+1][j] - p[i][j]);
		x += dp[x];
	}
	
	cout << x << endl;
}

Measured memory_bytes: 1324
n,k=map(int,input().split())
l=list(map(int,input().split()))
l1=[0]*(n+1)
l2=[1]
a=0
l1[1]=1
while 1:
    if l1[l[a]]==1:
        l2.append(l[a])
        break
    l2.append(l[a])
    l1[l[a]]=1
    a=l[a]-1
if k<=len(l2)-1:
    print(l2[k])
else:
    a=l2.index(l2[-1])
    b=len(l2)-a-1
    c=(k-len(l2)+1)%b
    print(l2[a+c])
    
    
    
    

    
    


    


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

int main() {
    int n, temp;
    bool flag = false;
    vector<vector<int>> bingo(3, vector<int>(3)), check(3, vector<int>(3, 0));
    rep(i, 3) rep(j, 3) cin >> bingo.at(i).at(j);
    cin >> n;
    rep(i, n) {
        cin >> temp;
        rep(j, 3) rep(k, 3) if(temp == bingo.at(j).at(k)) check.at(j).at(k) = 1;
    }
    rep(i, 3) {
        int r = 1, c = 1;
        rep(j, 3) r &= check.at(i).at(j);
        rep(j, 3) c &= check.at(j).at(i);
        if(r | c) flag = true;
    }
    int s = 1, t = 1;
    rep(i, 3) {
        s &= check.at(i).at(i);
        t &= check.at(i).at(2 - i);
    }
    if(s | t) flag = true;
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
if n == 0:
    if a[0] > 1:
        print(-1)
    else:
        print(a[0])
    exit()
if a[0] > 0:
    print(-1)
    exit()
l = [0] * (n + 1)
u = [0] * (n + 1)
l[n] = a[n]
u[n] = a[n]
for i in range(n, 0, -1):
    l[i - 1] = -(-l[i] // 2) + a[i - 1]
    u[i - 1] = u[i] + a[i - 1]
if l[0] > 1:
    print(-1)
    exit()
u[0] = 1
itr = 0
while True:
    update = False
    for i in range(n):
        if u[i] < l[i]:
            print(-1)
            exit()
        n_u = 2 * (u[i] - a[i])
        if n_u < u[i + 1]:
            update = True
            u[i + 1] = n_u
    if not update:
        break
    update = False
    for i in range(n, 0, -1):
        if u[i] < l[i]:
            print(-1)
            exit()
        n_u = u[i] + a[i - 1]
        if n_u < u[i - 1]:
            update = True
            u[i - 1] = n_u
    if not update:
        break
for i in range(n + 1):
    if u[i] < l[i]:
        print(-1)
        exit()
print(sum(u))


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

using namespace std;

#define ll long long
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop(i, a, n) for(int i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define vint vector<int>

int main(){
    int N; cin >> N;
    ll ans = 0;
    rep(i, N) ans += i;
    cout << ans << endl; 
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int TEN(int n) {return (n==0)?1:10*TEN(n-1);}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i]; a[i]--;
    }
    sort(begin(a), end(a), greater<int>());
    int pos = 0;
    while (true) {
        if (pos+1 >= n) break;
        if (pos+1 > a[pos+1]) break;
        pos++;
    }
    int u1 = a[pos] - pos;
    int pos2 = pos;
    while (true) {
        if (pos2+1 >= n) break;
        if (pos > a[pos2+1]) break;
        pos2++;
    }
    int u2 = pos2 - pos;
//    printf("%d %d\n", u1, u2);
    bool f1 = u1 % 2;
    bool f2 = u2 % 2;
    if (f1 or f2) {
        printf("First\n");
    } else {
        printf("Second\n");
    }
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

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

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

    int s1[100] ={0};
    int s2[100] ={0};
    int abs[100]={0};
    for(int t=1;t<n; t++){
        for(int i=0; i<t; i++){
            s1[t-1] += w[i];
            //printf("s1 %d\n",s1[t-1]);
        }
        for(int j=t; j<n; j++){
            s2[t-1] += w[j];
            //printf("s2 %d\n",s2[t-1]);
        }

        if(s1[t-1] > s2[t-1]){
            abs[t-1] = s1[t-1] - s2[t-1];
        }else{
            abs[t-1] = s2[t-1] - s1[t-1];
        }
//            printf("abs %d\n",abs[t-1]);
    }

    int ans=10000;
    for(int i=0; i<n-1;i++){
        if(ans>abs[i]){
            ans=abs[i];
//            printf("%d\n",ans);
        }
    }

    printf("%d",ans);


    return 0;
}

Measured memory_bytes: 128