akhauriyash/Code-Regression huggingface dataset:
//                                  _                 ______   ______   ______   ______
//                                 | |               |  __  | |  __  | |  __  | |____  |
//    __ _   ____    _____    _  _ | |____           | |__| | | |__| | | |__| |      | |
//  / _` | |  __| /  __  |  / _` | |  __  |          |____  | |____  | |____  |      | |
// | (_| | | |    | |  | | | (_| | | |__| |  ______   ____| |  ____| |  ____| |      | |
//  \__,_| |_|    |_|  |_|  \__,_| |______| |______| |______| |______| |______|      |_|

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

#define ll long long
#define endl '\n'
#define REP(i, n) for(int i=0; i<n; i++)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9+7;

void FAST(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main(){
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// freopen("error.txt", "w", stderr);
  // #endif
  FAST();
  //Code goes past here:

  string str;
  int t, f;
  char ch;
  ll i, q;

  cin>>str>>q;

  bool todo = 0;
  vector<char> v[2];

  while(q--){
    cin>>t;

    if(t==1)
      todo = !todo;

    else if(t==2){
      cin>>f>>ch;
      --f;
      v[f^todo].push_back(ch);
    }
  }

  string ans;
  for(i = v[0].size()-1; ~i ; --i)   ans += v[0][i];
  ans += str;

  for(char c: v[1])   ans += c;

  if(todo)  reverse(ans.begin(), ans.end());

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1448
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	bool is_visited = false;
} node;
typedef struct {
	int to;
	int cost;
	P <int, int> change;
} edge;

int main( void ){
	int N; cin >> N;
	vector <int> A( N + 1 ), B( N );
	rep( i, 0, N + 1 ) cin >> A[ i ];
	rep( i, 0, N ) cin >> B[ i ];
	ll sum = 0;
	rep( i, 0, N ){
		int killable = B[ i ];
		if (A[ i ] <= B[ i ]){
			sum += A[ i ];
			B[ i ] -= A[ i ];
		}
		else {
			sum += B[ i ];
			continue;
		}
		if (A[ i + 1 ] <= B[ i ]){
			sum += A[ i + 1 ];
			A[ i + 1 ] = 0;
			B[ i ] -= A[ i + 1 ];
		}
		else {
			sum += B[ i ];
			A[ i + 1 ] -= B[ i ];
		}
	}
	cout << sum << endl;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

vector<int> pri;

void mplist(LLi x){
	int flag, sqx;
	pri.emplace_back(2);

	for(int i=3;i<=x;i+=2){
		flag=0;
		sqx=(int)sqrt(x)+1;
		for(int j=1;j<(int)pri.size();j++){
			if(i%pri[j]==0){
				flag=1;
				break;
			}
			if(sqx<pri[j]) break;
		}
		if(flag==0) pri.emplace_back(i);
	}
}

bool isp(LLi x){
	//if(x==1) return false;//1を素数としないなら有効化
	auto ub = upper_bound(all(pri), x);
	auto lb = lower_bound(all(pri), x);

	//xがでかいときは素数リストで割ってみる
	if(lb==pri.end()){
		for(int i=1;i<(int)pri.size();i++){
			if(x%pri[i]==0) return false;
			if(x<pri[i]*pri[i]) return true;
		}
		cout<< "isp: pri size is small" <<endl;
	}

	return ub!=lb;
}

int main(){
  
  LLi x;
  cin>> x;
  
  mplist(101000);
  
  auto lb = lower_bound(all(pri), x);
  cout<< pri[lb-pri.begin()] <<endl;
  
  return 0;
}
  

Measured memory_bytes: 384
from collections import deque

S = deque(input())
Q = int(input())
Query = [input().split() for _ in range(Q)]

reverse = False
for query in Query:
    if query[0] == '1':
        reverse = not reverse
    else:
        if query[1] == ('2' if reverse else '1'):
            S.appendleft(query[2])
        else:
            S.append(query[2])
print(''.join(reversed(S) if reverse else S))


Measured memory_bytes: 44788
import os

import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N, M = list(map(int, sys.stdin.buffer.readline().split()))
H = list(map(int, sys.stdin.buffer.readline().split()))
AB = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(M)]


class UnionFind:
    def __init__(self, size=None, nodes=None):
        """
        size か nodes どっちか指定。
        nodes は set、size は list を使う。
        :param int size:
        :param collections.Iterable nodes:
        """
        assert size is not None or nodes is not None
        if size is not None:
            self._parents = [i for i in range(size)]
            self._ranks = [0 for _ in range(size)]
            self._sizes = [1 for _ in range(size)]
        else:
            self._parents = {k: k for k in nodes}
            self._ranks = {k: 0 for k in nodes}
            self._sizes = {k: 1 for k in nodes}

    def unite(self, x, y):
        """
        x が属する木と y が属する木を併合
        :param x:
        :param y:
        """
        x = self.root(x)
        y = self.root(y)
        if x == y:
            return

        # rank が小さい方が下
        if self._ranks[x] > self._ranks[y]:
            # x が root
            self._parents[y] = x
            self._sizes[x] += self._sizes[y]
        else:
            # y が root
            self._parents[x] = y
            self._sizes[y] += self._sizes[x]
            if self._ranks[x] == self._ranks[y]:
                self._ranks[y] += 1

    def root(self, x):
        """
        x が属する木の root
        :param x:
        """
        if self._parents[x] == x:
            return x
        self._parents[x] = self.root(self._parents[x])
        return self._parents[x]

    def size(self, x):
        """
        x が属する木のノード数
        :param x:
        """
        return self._sizes[self.root(x)]

# uf = UnionFind(size=N)
# for a, b in AB:
#     a -= 1
#     b -= 1
#     uf.unite(a, b)
#
# maxes = [0] * N
# for i, h in enumerate(H):
#     maxes[uf.root(i)] = max(maxes[uf.root(i)], h)
#
# ok_cnt = [0] * N
# for i, h in enumerate(H):
#     if maxes[uf.root(i)] == h:
#         ok_cnt[uf.root(i)] += 1
# print(ok_cnt)

ok = [True] * N
for a, b in AB:
    a -= 1
    b -= 1
    if H[a] <= H[b]:
        ok[a] = False
    if H[a] >= H[b]:
        ok[b] = False
print(ok.count(True))


Measured memory_bytes: 90200
#include <bits/stdc++.h>
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--)
 
int main() {
  string s;
  int num = 0;
  int numb = 0;
  int numc = 0;
  cin >> s;
  rep(i,3) {
    if (s[i] == 'a') {
      num ++;
    }
    else if (s[i] == 'b') {
      numb ++;
    }
    else numc ++;
  }
  if (num == 1) {
    if (numb == 1) {
      if (numc == 1) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  
  cout << "No" << endl;
}

Measured memory_bytes: 256
N = int(input())
B = list(map(int, input().split()))
A_rev = []
import sys
while(len(B)):
    max = -1
    for i in range(len(B)):
        if B[i] == i+1:
            max = i
    if max == -1:
        print(-1)
        sys.exit()
    A_rev.append(B[max])
    B.pop(max)
for a in A_rev[::-1]:
    print(a)


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

int main(){
    int x1,y1,x2,y2,x3,y3,x4,y4;
    cin >> x1 >> y1 >> x2 >> y2;
    int dx=abs(x1-x2);
    int dy=abs(y1-y2);
    int x=x2-x1,y=y2-y1;
    x3=x2-y,y3=y2+x;
    x4=x1-y,y4=y1+x;
    cout <<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define ENDL cout << endl
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1000000000;

int main() {
    int S, W;
    cin >> S >> W;
    if (S <= W) {
        COUT("unsafe");
    } else {
        COUT("safe");
    }
    return 0;
}

Measured memory_bytes: 3588
#pragma optimize("unroll-loops,no-stack-protector")
#include <bits/stdc++.h>
using namespace std;
// using namespace __gnu_pbds;
// #include <ext/pb_ds/assoc_container.hpp>
// typedef tree<int,null_type,less<int>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define Max(a,b,c) max(a,max(b,c))
#define Min(a,b,c) min(a,min(b,c))
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define pc(x)  __builtin_popcount (x)
#define vl vector< ll >
#define sorts(v) sort(v.begin(),v.end())
#define sortg(v) sort(v.begin(),v.end(),greater<ll>())
#define ss second
#define ff first
#define ll long long
#define ld long double
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1e18)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod 1000000007
#define mem(x,y) memset(x,y,sizeof(x))
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define gcd __gcd
#define primeDEN 727999983
#define nx_pe next_permutation(s.begin(),s.end())
#define cl cout<<"\n"
#define sp(x) setprecision(x)



void solve()
{
   ll n;
   cin>>n;
   ll a[n];
   rep(i,n)cin>>a[i];
   ll p=0;
   ll eve=0;
   rep(i,n)
   {
       p=gcd(a[i],p);
       if(a[i]%2==0)eve++;
   }
    ll flag=0;
    if(eve>=2)flag=1;
    map<ll,ll>m;
   if(eve<=1)
   {
       rep(i,n)
       {
           ll x=a[i];
           for(ll j=2;j*j<=x;++j)
           {
               if(x%j==0)
               {
                   m[j]++;
                   while(x%j==0)
                   {
                       x/=j;
                   }
               }
           }
           if(x>1)m[x]++;
       }
       for(auto y:m)
       {
           if(y.ss>1)
           {
               flag=1;
               break;
           }
       }
   }
   
   if(flag==0)
   {
        cout<<"pairwise coprime\n";
        return ;
   }


   if(p==1)
   {
       cout<<"setwise coprime\n";
       return ;
   }

   cout<<"not coprime\n";

}


    
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("ouput.txt", "w", stdout) ;
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL) ; cout.tie(NULL) ;
    std::ios::sync_with_stdio(false);
    ll te=1;
    // cin>>te;
    while(te--){
        solve();
    }
    
}


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

int main() {
  string r="",s,t;
  cin>>s>>t;
  for(int i=0;i<200;i++){
    r+=s.back();
    r+=s.substr(0,s.size()-1);
    if(r==t){
      cout<<"Yes"<<endl;
      return 0;
    }
    s=r;
    r="";
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define INF 100000
using namespace std;

//グラフと計算回数を引数にとる深さ優先探索関数
bool dfs(vector<vector<int> > &grid, int n);

//グラフ上のqueenが置けない場所を更新する関数
void init(vector<vector<int> > &grid, int line, int row);

//グラフ上のqueenが置けない場所を元に戻す関数
void cleanup(vector<vector<int> > &grid, int line, int row);

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

  //8*8のint配列を生成、0:何もなし、1:何もないが置けない、2:queenがいる、を表す
  vector<vector<int> > grid;
  for(int i=0; i<8; i++){
    vector<int> tempv;
    for(int j=0; j<8; j++){
      tempv.push_back(0);
    }
    grid.push_back(tempv);
  }

  //初期のqueenの位置を読み込み
  for(int i=0; i<n; i++){
    int p, q; cin >> p >> q;
    init(grid, p, q);//指定された場所にqueenをおく
  }

  dfs(grid, 8-n);//深さ優先で解を探索し、結果を出力

  return 0;
}

bool dfs(vector<vector<int> > &grid, int n){
  //もし追加で6体のqueenをおくことができればそれが解なので出力
  if(n==0){
    for(int i=0; i<8; i++){
      for(int j=0; j<8; j++){
        if(grid[i][j]>=INF){
          cout << 'Q' ;
        }
        else cout << '.' ;
      }
      cout << endl;
    }
    return true;
  }

  //gird上の各点についてdfs
  for(int i=0; i<8; i++){
    for(int j=0; j<8; j++){
      //もしqueenをおくことができるならば置いてdfs
      if(grid[i][j]==0){
        grid[i][j]+=INF;

        init(grid, i, j);
        if(dfs(grid, n-1)) return true;
        cleanup(grid, i, j);
      }
    }
  }
  return false;
}

void init(vector<vector<int> > &grid, int line, int row){
  //queenが置けない場所を更新
  for(int i=0; i<8; i++){
    for(int j=0; j<8; j++){
      if(grid[i][j]>=INF) continue;
      if(i==line) grid[i][j]+=1;
      else if(j==row) grid[i][j]+=1;
      else if(i+j==line+row) grid[i][j]+=1;
      else if(i-j==line-row) grid[i][j]+=1;
    }
  }
  //指定箇所にqueenをおく
  grid[line][row]=INF;
}

void cleanup(vector<vector<int> > &grid, int line, int row){
  //queenが影響を及ぼす場所を探索
  for(int i=0; i<8; i++){
    for(int j=0; j<8; j++){
      if(grid[i][j]>=INF) continue;
      if(i==line) grid[i][j]-=1;
      else if(j==row) grid[i][j]-=1;
      else if(i+j==line+row) grid[i][j]-=1;
      else if(i-j==line-row) grid[i][j]-=1;
    }
  }
  //指定箇所からqueenを除去
  grid[line][row]-=INF;
}



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

#define For(i, j, k) for (int i = j; i <= k; ++ i)
#define Forr(i, j, k) for (int i = j; i >= k; -- i)

using namespace std;

typedef long long ll;

inline int read() {
	int x = 0, p = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') p = -1;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x * p;
}

inline void File() {
	freopen("C.in", "r", stdin);
	freopen("C.out", "w", stdout);
}

const int N = 1e5 + 10;
int n, a[N], L;

int main() {
	n = read(), L = read();
	For(i, 1, n) a[i] = read();

	int flag = 0, p;
	For(i, 1, n - 1) if (a[i] + a[i + 1] >= L) { flag = 1, p = i; break; }
	if (!flag) return puts("Impossible"), 0;
	
	puts("Possible");
	For(i, 1, p - 1) printf("%d\n", i);
	Forr(i, n - 1, p + 1) printf("%d\n", i);
	cout << p << endl;
	return 0;
}


Measured memory_bytes: 1152
n, q = map(int, input().split())

A = [[] for _ in range(n)]


for _ in range(q):

    command, *list_num = input().split()

    t = int(list_num[0])

    if   command == "0":
        x = int(list_num[1])
        A[t].append(x)
    elif command == "1":
        print(*A[t])
    elif command == "2":
        A[t].clear()
    else:
        raise



Measured memory_bytes: 29764
#include<iostream>
#include<cstdio>
#include<queue>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
struct P{
  int tx,ty;
  int kx,ky;
  int cost;
  P(int _tx, int _ty, int _kx, int _ky, int _cost) : tx(_tx), ty(_ty), kx(_kx), ky(_ky), cost(_cost) {};
};
int hx,hy,rx,ry;
int X,Y;
int mas[110][110];
bool d[51][51][51][51];
int dx[4] = {0,1,0,-1},dy[4] = {1,0,-1,0};
int bfs();
int main(){
  while(1){
    scanf("%d %d",&X,&Y);
    if(X == 0 && Y == 0)break;
    scanf("%d %d",&hx,&hy);
    scanf("%d %d",&rx,&ry);
    for(int i = 1; i <= Y; i++){
      for(int j = 1; j <= X; j++){
	scanf("%d",&mas[i][j]);
      }
    }
    int ans = bfs();
    if(ans == -1)cout << "NA" << endl;
    else cout << ans << endl;
  }
}
int bfs(){
  queue<P> que;
  memset(d,0,sizeof(d));
  que.push(P(hx,hy,rx,ry,0));
  d[hx][hy][rx][ry] = 0;
  while(!que.empty()){
    P p = que.front();
    que.pop();
    if(p.cost >= 100)return -1;
    if(p.tx == p.kx && p.ty == p.ky){
      return p.cost;
    }
    for(int i = 0; i < 4; i++){
      int nx = p.tx + dx[i], ny = p.ty + dy[i];
      int ux = p.kx - dx[i], uy = p.ky - dy[i];
      if(nx > 0 && ny > 0 && ux > 0 && uy > 0 && nx <= X && ny <= Y && ux <= X && uy <= Y && mas[ny][nx] != 1 && mas[uy][ux] != 1 && d[nx][ny][ux][uy] == 0){
	que.push(P(nx,ny,ux,uy,p.cost + 1));
	d[nx][ny][ux][uy] =  1;
      }
      else if((nx <= 0 || nx > X || ny <= 0 || ny > Y || mas[ny][nx] == 1) && ux <= X && uy <= Y && ux > 0 && uy > 0 && mas[uy][ux] != 1 && d[p.tx][p.ty][ux][uy] == 0){
	que.push(P(p.tx,p.ty,ux,uy,p.cost + 1));
	d[p.tx][p.ty][ux][uy] = 1;
      }
      else if((ux <= 0 || ux > X || uy <= 0 || uy > Y || mas[uy][ux] == 1) && nx <= X && ny <= Y && nx > 0 && ny > 0 && mas[ny][nx] != 1 && d[nx][ny][p.kx][p.ky] == 0){
	que.push(P(nx,ny,p.kx,p.ky,p.cost + 1));
	d[nx][ny][p.kx][p.ky] = 1;
      }
    }
  }
  return -1;
}

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

int gcd(int x, int y)
{
  if (y == 0)
  {
    return x;
  }
  else
  {
    return gcd(y, x % y);
  }
}

int main()
{
  int K;
  cin >> K;
  
  int sum = 0;
  for (int i = 1; i <= K; i++)
  {
    for (int j = 1; j <= K; j++)
    {
      for (int k = 1; k <= K; k++)
      {
        int d = i;
		
        if (1 != d)
        {
          d = gcd(j, d);
        }
        else
        {
          sum += d;
          continue;
        }
        
        if (1 != d)
        {
          d = gcd(k, d);
        }
        else
        {
          sum += d;
          continue;
        }
        
        sum += d;
      }
    }
  }
  
  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int ans[10007];
int main() {
	for(int x=1; x<=100;x++) {
	for(int y=1; y<=100;y++) {
	for(int z=1; z<=100;z++) {
		int a=x+y,b=y+z,c=x+z;
		int t=a*a+b*b+c*c;
		if(t<=20000 && t%2==0) ans[t/2]++;
	}
	}
	}
	int n; scanf("%d", &n);
	for(int i=1; i<=n; i++) printf("%d\n", ans[i]);
}


Measured memory_bytes: 1716
n, m = map(int, input().split())
ab = []
for i in range(n):
    a, b = map(int, input().split())
    ab.append([a, b])
cd = []
for i in range(m):
    c, d = map(int, input().split())
    cd.append([c, d])
ans = []
w = 1000000000000000000000
num = 0
for i in range(n):
    for x in range(m):
        result = abs(ab[i][0] - cd[x][0]) + abs(ab[i][1] - cd[x][1])
        if result < w:
            w = result
            num = x + 1
    ans.append(num)
    w = 1000000000000000000
for i in ans:
    print(i)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) {}
    void init(int n) { par.assign(n, -1); }

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

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

    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
        if(x == y)
            return false;
        if(par[x] > par[y])
            swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

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

const int m = 100100;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    UnionFind uf(2 * m);
    for(int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        uf.merge(x, y + m);
    }
    map<int, int> mpx, mpy;
    for(int i = 0; i < m; i++) {
        mpx[uf.root(i)]++;
    }
    for(int i = m; i < 2 * m; i++) {
        mpy[uf.root(i)]++;
    }
    ll ans = 0;
    for(int i = 0; i < m; i++) {
        ans += (ll)mpx[i] * mpy[i];
    }
    cout << ans - n << endl;
}

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

int main() {
	int n, m;
	ll l;
	cin >> n >> m >> l;
	//warflo
	vector<vector<ll>>dp(n, vector<ll>(n,100000000000));
	for (int i = 0; i < m; i++) {
		ll a, b, c;
		cin >> a >> b >> c;
		if (c <= l) {
			a--;
			b--;
			dp.at(a).at(b) = c;
			dp.at(b).at(a) = c;
		}
	}
	for (int i = 0; i < n; i++)dp.at(i).at(i) = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++)dp.at(j).at(k) = min(dp.at(j).at(k), dp.at(j).at(i) + dp.at(i).at(k));
		}
	}
	vector<vector<ll>>dpf(n, vector<ll>(n,100000000000));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (dp.at(i).at(j) == 0) dpf.at(i).at(j) = 0;
			else if (dp.at(i).at(j) <= l)dpf.at(i).at(j) = 1;
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++)dpf.at(j).at(k) = min(dpf.at(j).at(k), dpf.at(j).at(i) + dpf.at(i).at(k));
		}
	}
	int q;
	cin >> q;
	for (int i = 0; i < q; i++) {
		int s, t;
		cin >> s >> t;
		s--;
		t--;
		if (dpf.at(s).at(t) > 1000000)dpf.at(s).at(t) = 0;
		cout <<dpf.at(s).at(t) -1 << endl;
	}
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
    #define N 2009
    using namespace std;
     
    int m,n,ans,a[N][N],b[N][N],c[N],q[N],lf[N],rg[N];
    char s[N];
    int main(){
    	scanf("%d%d",&m,&n);
    	int i,j,k;
    	for (i=1; i<=m; i++){
    		scanf("%s",s+1);
    		for (j=1; j<=n; j++) a[i][j]=(s[j]=='#');
    	}
    	for (i=1; i<=m; i++)
    		for (j=2; j<=n; j++)
    			b[i][j]=(a[i][j]^a[i+1][j])==(a[i][j-1]^a[i+1][j-1])?b[i-1][j]+1:0;
    	for (i=1; i<=m; i++)
		{
    		for (j=2; j<=n; j++) c[j]=1+b[i-1][j];

    		q[k=1]=1; c[1]=-2; c[n+1]=-1;
    		for (j=2; j<=n+1; j++){
    			for (; c[j]<=c[q[k]]; k--) rg[q[k]]=j;
    			lf[j]=q[k]; q[++k]=j;
    		}
    		for (j=2; j<=n; j++){

    			ans=max(ans,c[j]*(rg[j]-lf[j]));
    		}
    	}
    	printf("%d\n",max(ans,max(m,n)));
    	return 0;
    }

Measured memory_bytes: 31872
#include <bits/stdc++.h>
    
#define int long long
    
#define REP(i,n) for(int i=0;i<n;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 pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
    
using namespace std;
    
int dy[4]={1, 0, -1, 0};
int dx[4]={0, 1, 0, -1};

int n, m;
int v[3] = {-1, -1, -1};

int32_t main(){
    int n;
    cin >> n;
    
    vector<int> C(n), S(n), F(n);
    REP(i, n-1){
        cin >> C[i] >> S[i] >> F[i];
    }

    C[n-1]=S[n-1]=F[n-1]=0;

    REP(i, n){
        int sum=S[i];
        REP(j, n-1){
            if(j<i) continue;

            if(sum<S[j]){
                sum=S[j];
            }
            else if(sum>S[j]){
                int cnt=S[j];
                while(sum>cnt) cnt+=F[j];
                sum=cnt;
            }

            sum+=C[j];
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int K = int.Parse(input[0]);
    int X = int.Parse(input[1]);
    var xlist = new List<string>();
    for (int i = X-K+1; i <= X+K-1; i++)
    {
      if(i >= -1000000 && i <= 1000000)
        xlist.Add(i.ToString());
    }
    Console.WriteLine(string.Join(" ", xlist));
  }
}

Measured memory_bytes: 13396
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>  
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

ll mpow(ll a, ll b){
	if(b >= (MOD-1)) b %= (MOD-1);
	if(b==0) return 1;
	ll t1 = mpow(a,b/2);
	t1 *= t1;
	t1 %= MOD;
	if(b%2) t1 *= a;
	t1 %= MOD;
	return t1;
}

ll mpow(ll a, ll b, ll p){
	if(b==0) return 1;
	ll t1 = mpow(a,b/2,p);   t1 *= t1;
	t1 %= p;
	if(b%2) t1 *= a;
	t1 %= p;
	return t1;
}
ll modinverse(ll a, ll m){
	ll m0 = m; 
    ll y = 0, x = 1; 
    if (m == 1) return 0; 
    while (a > 1){
        ll q = a / m; 
        ll t = m; 
        m = a % m, a = t; 
        t = y; 
        y = x - q * y; 
        x = t; 
    }
    if (x < 0) x += m0; 
    return x; 
}
ll range(ll l, ll r){
	return l + rand()%(r-l+1);
}
     
void solve(){
	ll n,a,b;cin>>n>>a>>b;
	if((b-a)%2 == 0)
	{
		cout<<(b-a)/2<<ln;
	}
	else
	{
		ll q1 = 0, q2 = 0;
		q1 = a; q1 += (b-a-1)/2;
		q2 = n-b+1; q2 += (b-a-1)/2;
		cout<<min(q1,q2)<<ln;
	}
}
 
int main()
{
	fast_cin();
    ll t=1;
    //cin>>t;
    forn(i,t) {
    	// cout << "Case #" << i+1 << ": ";
    	solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<map>
using namespace std;
typedef long long ll;
int main(){
  ll a,b;
  cin>>a>>b;
  for(int i=0;i<=100000;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;
typedef long long ll;
typedef long double ld;
using pll=pair<ll,ll>;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i,l,r) for(ll i = (l); i <= (ll)(r); i++)
#define rep3(i,l,r) for(ll i = (l); i >= (ll)(r); i--)
#define dup(x,y) (((x)+(y)-1)/(y)) //a/bの除算の切り上げ
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; }
const int inf = 1001001001;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const ld pi = acos(-1);
 
// union by size + path having
class UnionFind {
public:
   vector <ll> par; // 各元の親を表す配列
   vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)
 
   // Constructor
   UnionFind(ll sz_): par(sz_),siz(sz_, 1LL){
       for (ll i=0; i<sz_; i++) par[i]=i; // 初期では親は自分自身
   }
   void init(ll sz_){
       par.resize(sz_);
       siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
       for (ll i=0; i<sz_; i++) par[i]=i; // 初期では親は自分自身
  }
 
   // Member Function
   // Find
   ll root(ll x){ // 根の検索
      while (par[x]!=x){
           x=par[x]=par[par[x]]; // x の親の親を x の親とする
       }
       return x;
  }
 
   // Union(Unite, Merge)
   bool unite(ll x, ll y){
       x=root(x);
       y=root(y);
       if (x==y) return false;
       // merge technique（データ構造をマージするテク．小を大にくっつける)
       if (siz[x]<siz[y]) swap(x, y);
       siz[x]+=siz[y];
       par[y]=x;
       return true;
  }
 
  bool same(ll x, ll y){ // 連結判定
       return root(x)==root(y);
  }
 
  ll size(ll x){ // 素集合のサイズ
      return siz[root(x)];
  }
};
 
ll modpow(ll x, ll n){
   x=x%mod;
   if(n==0) return 1;  //再帰の終了条件
 
   else if(n%2==1){
       return (x*modpow(x, n-1))%mod;  //nが奇数ならnを1ずらす
   }
   else return modpow((x*x)%mod, n/2)%mod;  //nが偶数ならnが半分になる
}
 
ll com(ll n, ll k){
   ll x=1;
   for(int i=n-k+1; i<=n; i++){
      x=x*i%mod;
   }
 
   ll y=1;
   for(int i=1; i<=k; i++){
       y=y*i%mod;
   }
   y=modpow(y, mod-2);
 
   return x*y%mod;
}
 
bool is_prime(const unsigned n){
   switch(n){
       case 0: // fall-through
       case 1: return false;
       case 2: // fall-through
       case 3: return true;
  } // n>3 が保証された
 
   if(n%2==0 || n%3==0) return false;
   // nは2と3のいずれの倍数でもないことが保証された
   // これよりnは(6の倍数)-1か(6の倍数)+1である
 
   // 6の倍数前後の数を使って試し割りをする
   for(unsigned i = 5; i*i<=n; i+=6) {
       if(n%i==0) return false; // (6の倍数)-1
       if(n%(i+2)==0) return false; // (6の倍数)+1
   }
 
   return true;
}
 
int digsum(int n){
   int res=0;
   while(n > 0) {
       res+=n%10; //ここをres++;に変えたら桁数を求める関数になる,res+=n%10;なら格桁の和
       n/=10;
   }
   return res;
}
vector<ll> divisor(ll n){
   vector<ll> ret;
   for(ll i=1; i*i<=n; i++){
       if(n%i==0){
           ret.push_back(i);
           if(i*i!=n) ret.push_back(n/i);
       }
   }
   sort(ret.begin(),ret.end());
   return ret;
}
 
int main(){

    ll n,ans=0;
    cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
        ans^=a[i];
    }
    rep(i,n){
        ll b=ans^a[i];
        cout << b << endl;
    }

 
}

Measured memory_bytes: 4776
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
struct edge{
    ll now,to,cost;
    edge(ll now,ll to,ll cost):now(now),to(to),cost(cost) {}
};
int main(){
 int n,m;
 cin>>n>>m;
 V<edge> e;
 for(int i=0;i<m;i++){
     ll a,b,c;
     cin>>a>>b>>c;
     e.emplace_back(a-1,b-1,-c);
 }
 V<ll> d(n,inf);
 d[0]=0;
  for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
          if(d[e[j].now]>=inf)continue;
          chmin(d[e[j].to],d[e[j].now]+e[j].cost);
      }
  }
  for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
          if(d[e[j].now]>=inf)continue;
          if(chmin(d[e[j].to],d[e[j].now]+e[j].cost)){
              d[e[j].to]=-inf;
          }
      }
  }
  if(d[n-1]<=-inf)cout<<"inf"<<"\n";
  else cout<<-d[n-1]<<"\n";
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
#define PI  3.141592653589793238
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    vector<int> ar[n+5];
    for(int i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        ar[x].push_back(y);
        ar[y].push_back(x);
    }
    int id[n+5];
    for(int i=2;i<=n;i++)
        id[i]=-1;
    queue< pair<int,int> > que;
    que.push({1,0});
    bool visited[n+5]={0};
    while(!que.empty())
    {
        int front= que.front().first;
        int par = que.front().second;
        que.pop();
        for(int i=0;i<ar[front].size();i++)
        {
            if(!visited[ar[front][i]])
            {
                que.push({ar[front][i],front});
                id[ar[front][i]]=front;
                visited[ar[front][i]]=1;
            }
        }
    }
    for(int i=2;i<=n;i++)
    if(id[i]==-1)
    {
        cout<<"No"<<endl;
        return 0;
    }


        cout<<"Yes"<<endl;
        for(int i=2;i<=n;i++)
        cout<<id[i]<<endl;
}


Measured memory_bytes: 10760
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b;
  cin>>a>>b;
  string str;
  string tmp;
  str="";
  if(a-b>0){
  	for(int i=0;i<a;i++){
  	  tmp=to_string(b);
  	  str+=tmp;
  	}
  }else{
  	for(int i=0;i<b;i++){
  	  tmp=to_string(a);	
  	  str+=tmp;
  	}
  }
  cout<<str<<endl;
 }


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string s1,s2;
    int ans = 0x3f3f3f3f;
    int i,j;int temp;
    cin >> s1 >> s2;
    int len1 = s1.length();
    int len2 = s2.length();
    for(i = 0;i <= len1 - len2;i++) {
        temp = 0;
        for(int j = 0;j < len2;j++) {
            if(s1[i+j]!=s2[j]) {
                temp++;
            }
        }
        ans = min(ans,temp);
    }
    printf("%d\n",ans);
    return 0;
}


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

#define REP(i,s,n) for(int i=s; i<n; ++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

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

int main(){

	string s;
	cin >> s;
	vector<int> cnt(3, 0);

	rep(i, s.size()) cnt[s[i] - 'a']++;
	if(abs(cnt[0] - cnt[1]) <= 1 && abs(cnt[1] - cnt[2]) <= 1 && abs(cnt[0] - cnt[2]) <= 1) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}


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

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

    // int N;
    int N;
    string S;
    cin >> N >> S;
    // for(int i=0;i<N;i++) cin >> S[i];
    S.push_back('#');

    int slime_num = 0;
    // vector<string> new_slime;

    for(int i=0;i+1<S.size();i++){
        if(S[i] != S[i+1]){
            // new_slime.push_back(S[i]);
            slime_num++;
        }
    }
    // cout << new_slime.size();
    cout << slime_num << endl;
}

Measured memory_bytes: 512
n = int(input())

ans = []

while (n != 0):
	r = n % 2
	if r < 0:
		r += 2

	n = (n - r) // (-2)
	ans.append(r)

if ans == []:
	ans.append(0)
ans = ans[::-1]

print(*ans, sep='')

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

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

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, a, b;
  
  cin >> n >> a >> b;
  
  int plan1 = n * a;
  
  if (plan1 > b) {
  	cout << b << endl;
  } else {
  	cout << plan1 << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main()
{
	ll l,r;
	cin >> l >>r;
	r=min(l+4038,r);
	//cout<<r<<endl;
	ll ans = 2019;
	for(ll i = l ; i < r; ++i)
	{
		for(ll j=l+1;j <= r;++j)
		{
			ans = min((1LL)*ans, (1LL)*(j*i)%2019);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL<<61;

int main(){
  ll n, k; cin >> n >> k;
  vector<ll> A(n);
  for(int i = 0; i < n; i++) cin >> A[i];
  sort(A.begin(), A.end());
  ll left = -INF, right = INF;
  while(right - left > 1){
    ll x = (right+left)/2;
    ll s = 0, t = 0;
    for(int i = 0; i < n; i++){
      if(A[i] > 0){
        int l1 = -1, r1 = n;
        while(r1 - l1 > 1){
          int m = (r1 + l1) / 2;
          if(A[i] * A[m] <= x) l1 = m; 
          else r1 = m;
        }
        s += r1;
      }
      else if(A[i] < 0){
        int l1 = -1, r1 = n;
        while(r1 - l1 > 1){
          int m = (r1 + l1) / 2;
          if(A[i] * A[m] <= x) r1 = m;
          else l1 = m;
        }
        s += n - r1;
      }
      else if(x >= 0) s += n;
      if(A[i] * A[i] <= x) t++;
    }
    ll num = (s - t) / 2;
    if(num >= k) right = x;
    else left = x;
  }
  cout <<  right << endl;
}

Measured memory_bytes: 4796
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int N;
  cin>>N;
  vector<ll> X(N),L(N);
  rep(i,N) cin>>X[i]>>L[i];
  vector<pair<ll,ll>> PP(N);
  rep(i,N) PP[i]=make_pair(X[i]+L[i],X[i]-L[i]);
  sort(all(PP));
  int ans=0;
  ll LL=-1e9-1;
  rep(i,N){
    if(LL<=PP[i].second){
      ans++;
      LL=PP[i].first;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int h1,m1,h2,m2,k;
    
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    
    int hh = h2 - h1;
    int mm = hh * 60 + m2 - m1;
    
    int ans = mm - k;
    if (ans <= 0) ans = 0;
    
    cout << ans << endl;
    
    return 0;
}


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

using namespace std;

typedef unsigned int uint;
typedef long long int llint;
typedef unsigned long long int ullint;

//#define DEBUG

#ifdef DEBUG
#define dump(i) cout << "[*] " #i " : " << i << endl;
#define debug(i) i
#else
#define dump(i)
#define debug(i)
#endif
#define rep(i, max) for (int i = 0; i < (max); ++i)

inline void solve() {
  string s;
  cin >> s;
  char c[0xff] = {};
  rep(i, 3) {
    c[s[i]]++;
  }

  if (c['a'] == c['b'] && c['b'] == c['c']) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

int main() {
        /*
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        cout.tie(nullptr);
        //*/
#ifdef DEBUG
        clock_t _begin = clock();
#endif

        solve();

#ifdef DEBUG
        cerr << "[*] time : " << (double)(clock() - _begin) * 1000 / CLOCKS_PER_SEC << " [ms]" << endl;
#endif
        return 0;
}

Measured memory_bytes: 256
N, K, Q = list(map(int, input().split()))
A = []
for i in range(Q):
    A.append(int(input()))

import numpy as np
A = np.array(A) - 1

score = np.ones(shape=(N,)) * (K - Q)
for q in range(Q):
    score[A[q]] += 1

for n in range(N):
    print('Yes' if score[n]>0 else 'No')

Measured memory_bytes: 17884
N,K = map(int,input().split())
A = [-1] + [int(i) for i in input().split()]
deta = [False for i in range(N+1)]
i = 1
tele = 1
telelist = [1]
while not deta[A[i]]:
    telelist.append(A[i])
    deta[A[i]] = True
    i = A[i]

k = 0
for s in telelist:
    if s == A[i]:
        break
    k += 1
if K<=k:
    print(telelist[K])
else:
    l = len(telelist)-k
    K -= k
    s = K%l
    print(telelist[k+s])

Measured memory_bytes: 32332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

template<class T> inline bool chmin(T &a,T b){
    if (a>b){
        a=b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T &a,T b){
    if (a<b){
        a=b;
        return true;
    }
    return false;
}

int main(){
    ll N;
    cin >> N;
    vector<Pll> RL(N);
    rep(i,N){
        ll L,R;
        cin >> L >> R;
        RL[i]=Pll(R,L);
    }
    sort(RL.begin(),RL.end());
    vector<ll> Ll(N,0),Lr(N,0);
    Ll[0]=RL[0].second,Lr[N-1]=RL[N-1].second;
    rep2(i,1,N){
        Ll[i]=max(Ll[i-1],RL[i].second);
        Lr[N-1-i]=max(Lr[N-i],RL[N-1-i].second);
    }
    ll ans=0;
    rep(i,N-1){
        chmax(ans,max((ll)0,max((ll)-1,RL[0].first-Ll[i])+1)+max((ll)0,max((ll)-1,RL[i+1].first-Lr[i+1])+1));
    }
    rep2(i,1,N-1){
        chmax(ans,RL[i].first-RL[i].second+1+max((ll)-1,RL[0].first-max(Ll[i-1],Lr[i+1]))+1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

const int mod = 1e9 + 7;
const int mod2 = 998244353;

void fact_init(int n);
ll exp(ll taban, ll us, ll md);
ll ebob(ll a, ll b);
ll ekok(ll a, ll b);
ll komb(ll a, ll b);

vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n){
    fact.resize(n+5);
    inv_fact.resize(n+5);
    fact[0] = inv_fact[0] = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = (fact[i-1] * i) % mod;
        inv_fact[i] = exp(fact[i], mod-2, mod);
    }
}
ll exp(ll taban, ll us, ll md) {
    ll carpan = taban % md;
    if(carpan == 0) return 0;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % md;
        temp /= 2;
        carpan = (carpan*carpan) % md;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}

ll komb(ll a, ll b){
    if(a < b) return 0;
    return fact[a] * (inv_fact[a-b] * inv_fact[b] % mod) % mod;
}

const int N = 1e3 + 5;
int h, w, ch, cw, dh, dw;
char g[N][N];
bool check(int r, int c){
	return r >= 1 && r <= h && c >= 1 && c <= w && g[r][c] != '#';
}
int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
	cin>>h>>w>>ch>>cw>>dh>>dw;
	for(int i = 1; i <= h; i++){
		for(int j = 1; j <= w; j++) cin>>g[i][j];
	}
	priority_queue<pair<int, pii>> q;
	int cost[h+1][w+1];
	for(int i = 1; i <= h; i++){
		for(int j = 1; j <= w; j++) cost[i][j] = 1e9;
	}
	cost[ch][cw] = 0;
	q.push({0, {ch, cw}});
	while(!q.empty()){
		int cur_cost = -q.top().first;
		pii rc = q.top().second;
		int r = rc.first, c = rc.second;
		q.pop();
		//cout<<r<<" "<<c<<"\n";
		for(int i = -1; i <= 1; i++){
			for(int j = -1; j <= 1; j++){
				if(i && j || (!i && !j)) continue;
				if(!check(r + i, c + j)) continue;
				if(cost[r+i][c+j] <= cur_cost) continue;
				cost[r+i][c+j] = cur_cost;
				q.push({-cur_cost, {r+i, c+j}});
			}
		}
		for(int i = -2; i <= 2; i++){
			for(int j = -2; j <= 2; j++){
				if(!i && !j) continue;
				if(!check(r + i, c + j)) continue;
				if(cost[r+i][c+j] <= cur_cost + 1) continue;
				cost[r+i][c+j] = cur_cost + 1;
				q.push({-cur_cost - 1, {r+i, c+j}});
 			}
		}
	}
	if(cost[dh][dw] == 1e9) cost[dh][dw] = -1;
	cout<<cost[dh][dw];
}

Measured memory_bytes: 8524
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
class Main {
    public static void main(String[] args) throws Exception {
        // ??\???????????????
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int length = Integer.parseInt(br.readLine());
        String[] sarray = br.readLine().split(" ",length);
        // ???????????????????????????  
        bubbleSort(sarray , length);
          
    }
    
    public static void bubbleSort(String[] sarray , int length) {
        String str;
        StringBuilder sb = new StringBuilder();
        boolean flag = true;
        int cnt = 0;
        int k = 0;
        
        while ( flag == true ){
            flag = false;
            // ????????????????????????
            for ( int j = length - 1 ; j > k ; j--){
                if( Integer.parseInt(sarray[j]) < Integer.parseInt(sarray[j - 1]) ) {
                    str = sarray[j];
                    sarray[j] = sarray[j - 1];
                    sarray[j - 1] = str;
                    
                    cnt = cnt + 1;
                    flag = true;
                }
            }
            k = k++;
        }
        for ( int i = 0 ; i < length ; i++){
            if ( i > 0 ){
                sb = sb.append(" ");
            }
            sb = sb.append(sarray[i]);
        }
        System.out.println(sb);
        System.out.println(cnt);
    }
};


Measured memory_bytes: 25456
#include <bits/stdc++.h>
#include <iostream>
#include <ctime>
using namespace std;
#define _LL long long
#define rep(i, n) for (_LL i = 0; i < (_LL)(n); i++)
#define vecrep(itr, v) for (auto itr = (v).begin(); itr != (v).end(); itr++)

_LL kouyaku(_LL a, _LL b)
{
    if( b == 0 ) return a;
    if( a == 1 || b == 1 ) return 1;
    if( b > a ) return kouyaku(b, a);
    return kouyaku(b, a % b);
}

void bunkai(vector<pair<_LL, _LL>> &e, _LL n)
{
    for( _LL i = 2; i * i <= n; i++ )
    {
        if( n % i != 0 ) continue;
        int c = 0;
        while( n % i == 0 ) { n /= i; c++; }
        e.emplace_back(i, c);
    }
    if( n != 1) e.emplace_back(n, 1);
}

int main()
{
    _LL a, b; cin >> a >> b;
    _LL n = kouyaku(a, b);
    vector<pair<_LL, _LL>> e;
    bunkai(e, n);
    cout << e.size() + 1;
    return 0;    
}

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void pout(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void pout(const T &value, const Args&... args){std::cout << value << " ";pout(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  int N, M, X;
  while(cin >> N >> M >> X){

    vector<int> C(N);
    vector<vector<int>> A(N, vector<int>(M));
    REP(i,N){
      cin >> C[i];
      cin >> A[i];
    }

    int ans = INT_MAX;

    REP(i,1<<N){
      int t = 0;
      vector<int> b(M);

      REP(j,N){
        if(i & bit(j)){
          t += C[j];
          REP(k,M){
            b[k] += A[j][k];
          }
        }
      }

      if(all_of(ALL(b), [X](int p){return p >= X;})){
        chmin(ans, t);
      }
    }
    
    
    pout(ans == INT_MAX ? -1 : ans);
  }

  return 0;
}


Measured memory_bytes: 3664