akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long ll;

const ll INF = 1ll << 60;
const int MAX_N = 100000;

ll A[MAX_N], D[MAX_N];
ll stops[MAX_N];

int main() {
	ll N, T, Q;
	cin >> N >> T >> Q;
	for (int i = 0; i < N; i++) {
		cin >> A[i] >> D[i]; 
		stops[i] = INF;
	}

	ll s = -INF;
	if (D[0] == 2) stops[0] = s;

	for (int i = 1; i < N; i++) {
		if (D[i - 1] == 1 && D[i] == 2) {
			s = (A[i] + A[i - 1]) / 2;

			for (int j = i - 1; j >= 0 && D[j] == 1; j--)
				stops[j] = s;
		}
		
		if (D[i] == 2) {
			stops[i] = s;
		}
	}

	for (int i = 0; i < Q; i++) {
		ll x;
		cin >> x;
		x--;
		ll ans;
		if (D[x] == 1) ans = min(A[x] + T, stops[x]);
		else ans = max(A[x] - T, stops[x]);
		cout << ans << endl;
	}
}

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

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		String s = sc.next();
		int a = 0;
		int b = 0;
		int c = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'a') {
				a++;
			} else if (s.charAt(i) == 'b') {
				b++;
			} else {
				c++;
			}
		}
		int max = Math.max(a, Math.max(b, c));
		if (max - a <= 1 && max - b <= 1 && max - c <= 1) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

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

Measured memory_bytes: 22740
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n, k = map(int, input().split())
    a = list(map(int, input().split()))

    s = sum(a)
    cand = [s]
    for i in range(2, int(s ** 0.5) + 1):
        if s % i == 0:
            cand.append(i)
            cand.append(s // i)
    cand.sort(reverse=True)

    for c in cand:
        arr = [a[i] % c for i in range(n)]
        arr.sort()
        sum_r = [0] * n
        sum_r[0] = arr[0]
        for i in range(1, n):
            sum_r[i] = sum_r[i - 1] + arr[i]
        for i in range(n - 1):
            if sum_r[i] <= k:
                sum_l = c * (n - i - 1) - sum_r[-1] + sum_r[i]
                if sum_r[i] == sum_l:
                    print(c)
                    exit()

    print(1)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 42076
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1 << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
bool solve(vector< int > &A) {
	sort(A.begin(), A.end());
	int maxa = A[N - 1], mina = (maxa + 1) / 2;
	map< int, int > m;
	rep(i, N) m[A[i]]++;
	if (m[maxa] < 2)
		return false;
	if (A[0] < mina)
		return false;
	if (maxa & 1) {
		if (m[mina] != 2)
			return false;
	} else {
		if (m[mina] != 1) {
			return false;
		}
	}
	for (int k = mina + 1; k < maxa; k++) {
		if (m[k] < 2)
			return false;
	}
	return true;
}
signed main() {
	cin >> N;
	vector< int > A(N);
	rep(i, N) cin >> A[i];
	string ans = solve(A) ? "Possible" : "Impossible";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-

n, m, X, Y = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]

maxx = max(x)
miny = min(y)
if X <= maxx < miny <= Y:
    print('No War')
else:
    print('War')


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

int main()
{
    int a,b;
    cin >> a >> b;

    if(a <= b)
    {
        for(int i=0; i<b; i++)
        {
            cout << a;
        }
    }
    else
    {
        for(int j=0; j<a; j++)
        {
            cout << b;
        }
    }
    



    return 0;
}

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

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

Measured memory_bytes: 3596
#include <iostream>
using namespace std;
int main(){
    string s;
    getline(cin,s);
    for (int i=0;i<s.size();i++){
        if(isupper(s[i]))
            s[i] = tolower(s[i]);
        else if (islower(s[i]))
            s[i] = toupper(s[i]);
    }
    cout<<s<<endl;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = int(n) - 1; (i) >= 0; -- (i))
#define ALL(x) begin(x), end(x)
using namespace std;

pair<string, string> solve(int n, int m, int k, string s, string t) {
    reverse(ALL(s));
    reverse(ALL(t));
    REP (i, m + k + 100) s.push_back('0');
    REP (j, n + k + 100) t.push_back('0');

    stack<int> stk;
    function<void (int, int)> go = [&](int i, int k1) {
        assert (k1 >= 0);
        if (not stk.empty()) {
            assert (stk.top() >= i);
            if (stk.top() == i) stk.pop();
        }

        if (s[i] == '1' and t[i] == '1') {
            if (k1 == 0) {
                // nop
            } else {
                s[i] = '0';
                t[i] = '0';
                int j = stk.empty() ? INT_MAX : stk.top();
                if (k1 < j - i) {
                    assert (s[i + k1] == '0');
                    assert (t[i + k1] == '0');
                    s[i + k1] = '1';
                    t[i + k1] = '1';
                } else {
                    stk.pop();
                    s[j] += 1;
                    t[j] += 1;
                    go(j, k1 - (j - i));
                }
            }

        } else if (s[i] == '1' and t[i] == '0') {
            stk.push(i);

        } else if (s[i] == '0' and t[i] == '1') {
            stk.push(i);

        } else if (s[i] == '0' and t[i] == '0') {
            // nop

        } else if (s[i] == '2' and (t[i] == '0' or t[i] == '1')) {
            s[i] = '0';
            s[i + 1] += 1;
            go(i + 1, k1);
            if (t[i] == '1') stk.push(i);

        } else if ((s[i] == '0' or s[i] == '1') and t[i] == '2') {
            t[i] = '0';
            t[i + 1] += 1;
            go(i + 1, k1);
            if (s[i] == '1') stk.push(i);

        } else {
            assert (false);
        }
    };
    REP_R (i, n + m) {
        go(i, k);
    }

    while (s.back() == '0') s.pop_back();
    while (t.back() == '0') t.pop_back();
    reverse(ALL(s));
    reverse(ALL(t));
    return make_pair(s, t);
}

int main() {
    int n, m, k; cin >> n >> m >> k;
    string s; cin >> s;
    string t; cin >> t;
    tie(s, t) = solve(n, m, k, s, t);
    cout << s << endl;
    cout << t << endl;
    return 0;
}


Measured memory_bytes: 16700
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    LL N,T;cin >> N >> T;
    vector<LL> t(N);
    rep(i,N)cin >> t[i] ;
    LL ans = 0;
    rep(i,N){
        if(i != N-1){
            if(t[i]+T <= t[i+1])ans += T;
            else ans += t[i+1] - t[i];
        }
        else ans += T;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main() {
    let x :i32 = read();
    let a :i32 = read();
    let b :i32 = read();
    let ans  = (x - a ) % b;
    println!("{}",ans);
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		int[] nums = new int[N];
		int[] nums2= new int[N];
		int cnt=0;

		for(int i=0;i<N;i++) {
			nums[i]=sc.nextInt();
			nums2[i]=nums[i];
		}
		Arrays.sort(nums2);

		for(int i=0;i<N;i++) {
			if(nums[i]!=nums2[i]) {
				cnt++;
			}
		}
		System.out.println(cnt<=2?"YES":"NO");
		sc.close();
	}
}

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

int main() {
	int a,b;
	cin >> a >> b;

	if(a < b){
		cout << "a < b" << endl;
	}else if(a > b){
		cout << "a > b" << endl;
	}else{
		cout << "a == b" << endl;
	}
	return 0;
}

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

int main(){
  long double l;
  cin >> l;
  cout <<fixed<<setprecision(7)<< l*l*l/27.0 << endl;
  return 0;
}

Measured memory_bytes: 256
import sys

n, y = list(map(int, sys.stdin.readline().strip().split(" ")))

t_list = []

for a in range(n + 1):
    for b in range(n-a+1):
        #t_list.append((n-i-j, j, i))
        c = n-a-b
        if 10000 * a + 5000 * b + 1000 * c == y:
            print(" ".join([str(a), str(b), str(c)]))
            sys.exit()

print("-1 -1 -1")


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define ll long long 
#define N 2005 
#define mod 1000000007
using namespace std ;

ll n , k , a[N] ;
ll ans , bi[N] , ni[N] , Sum[N] ;
ll sum1 , sum2 ;

int main() {
	scanf("%lld%lld", &n , &k );
	for( int i = 1 ; i <= n ; ++ i )
		scanf("%lld", &a[i] );
	for( int i = 1 ; i <= n ; ++ i ) {
		for( int j = 1 ; j <= n ; ++ j ) {
			if( a[j] > a[i] && j < i )
				sum1 ++ ;
			if( a[i] > a[j] && j < i )
				sum2 ++ ;
		}
	}
	ll K2 = (k-1)*k/2%mod ;
	ll K1 = (k+1)*k/2%mod ;
	ans = sum1*K1%mod+sum2*K2%mod ;
	ans %= mod ;
	printf("%lld", ans );
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define LIMIT(d_in, d_min, d_max) max(d_min, min(d_max, d_in))
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

//最大公約数
lint GCD(lint a, lint b)
{
	if (a == 0)
		return b;
	if (b == 0)
		return a;

	if (a < b)
		swap(a, b);

	for (;;)
	{
		lint m = a % b;
		if (m == 0)
			return b;
		a = b;
		b = m;
	}
}

void execute()
{
	int N;
	lint X;
	lint ans = 0;
	cin >> N >> X;

	for (int i = 0; i < N; i++)
	{
		lint city;
		cin >> city;
		ans = GCD(ans, abs(city - X));
	}

	cout << ans << endl;
	return;
}

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

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
// cities to vapori-
// corner cases // int vs ll // cin vs scanf // clear structures // statement // doublesz // math is your friend
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define sz(x) int(x.size())
#define fill(x,v) memset(x,v,sizeof(x))
#define REP(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){

	fastio;
	ll n,k;
	cin >> n >> k;
	n %= k;
	ll ans = min(n,k-n);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}
template<class A,size_t N,class T>void Fill(A(&a)[N],const T&v){fill((T*)a,(T*)(a+N),v);}

const int MOD = 1e9+7; //998244353;

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m=MOD){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m=MOD){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>Fac,Rac;void setF(int n,int m=MOD){Fac=Rac=V<ll>(++n);Fac[0]=1;FOR(i,1,n)Fac[i]=Fac[i-1]*i%m;Rac[n-1]=modInv(Fac[n-1],m);FORR(i,n-1,1)Rac[i-1]=Rac[i]*i%m;}
//ll comb(int a,int b,int m=MOD){return a<b||b<0?0:Fac[a]*Rac[b]%m*Rac[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int N = 2e3;
int n, x, y, d[N], ans[N];
V<int> e[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> x >> y;
  x--; y--;
  FOR(i, 1, n) e[i].pb(i-1), e[i-1].pb(i);
  e[x].pb(y), e[y].pb(x);
  FOR(i, 0, n){
    queue<int> q;
    fill(d, d+n, IINF);
    d[i] = 0;
    q.push(i);
    int s = 0;
    while(!q.empty()){
      int t = q.front();
      q.pop();
      ans[d[t]]++;
      for(int a:e[t]) if(d[t]+1<d[a]){
        d[a] = d[t]+1;
        q.push(a);
      }
    }
  }
  FOR(i, 1, n) cout << ans[i]/2 << endl;
}

Measured memory_bytes: 3792
#include <math.h>

#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;

int main() {
  int k, n;
  cin >> k >> n;
  vector<int> a(n + 1);
  rep(i, n) cin >> a[i];
  a[n] = a[0] + k;
  //最も長い隣接する区間を求める
  int dis = 0;
  rep(i, n) { dis = max(dis, a[i + 1] - a[i]); }

  cout << k - dis;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;

  int cnt = 0;
  while (a >= b) {
    b *= 2;
    cnt++;
  }
  while (b >= c) {
    c *= 2;
    cnt++;
  }
  if (cnt <= k) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

const int N = 410;
char C[N][N];
bool seen[N][N];

int h, w;
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1};

struct UnionFind{
    vector<long long> par;
    UnionFind(int N) : par(N){
        for(int i = 0; i < N; i++){
            par[i] = -1;
        }
    }
    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        else{
            if(par[rx] > par[ry]) swap(rx, ry);
            par[rx] += par[ry];
            par[ry] = rx;
       }
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
    void check(){
        for(auto x : par){
            cout << x << " ";
        }
        cout << endl;
    }
};

void dfs(int x, int y, char bef, UnionFind &uf){
    seen[x][y] = true;
    for(int i = 0; i < 4; i++){
        int nx = x + dx[i];
        int ny = y + dy[i];
        if(nx < 0 or ny < 0 or nx >= h or ny >= w){
            continue;
        }
        if(seen[nx][ny] or C[nx][ny] == bef){
            continue;
        }
        uf.unite(x * w + y, nx * w + ny);
        dfs(nx, ny, C[nx][ny], uf);
    }
}

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

    cin >> h >> w;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> C[i][j];
        }
    }

    UnionFind uf(h * w);
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(!seen[i][j]){
                dfs(i, j, C[i][j], uf);
            }
        }
    }

    map<int, long long> mp; // {root, black_num}
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            int r = uf.root(i * w + j);
            if(-uf.par[r] < 2) continue;
            if(C[i][j] == '.') continue;
            mp[r]++;
        }
    }

    long long ans = 0;
    for(auto x : mp){
        // cout << x.first << ' ' << x.second << endl;
        ans += (-uf.par[x.first] - x.second) * x.second;
    }

    cout << ans << endl;

    return 0;
}

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

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

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

	long long ans = 0;
	int high = 0;

	for (int i = 0; i < N; i++) {
		high = max(high, A[i]);
		int Q = high;
		ans += high - A[i];
	}

	cout << ans << endl;
	
}

Measured memory_bytes: 4044
N=int(input())
T,A=map(int,input().split())
H=list(map(int,input().split()))
p =abs(T-H[0]*0.006-A)
m=0
for i in range(N):    
    k=abs(T-H[i]*0.006-A)
    if k<p:
        p=k
        m=i 
print(m+1)

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

using namespace std;
#define rep(i,n) for (int i =0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
//int choose2(ll x){
	//	return x*(x-1)/2;}
const int INF = 1001001001;

int main() {
	int a,b,c;
	
	
	
	cin >>a >> b>> c;
	cout << c <<" "<< a <<" "<< b;

	
}

Measured memory_bytes: 256
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

class UF(object):
    def __init__(self,n):
        self.par = [i for i in range(n)]
        self.rank = [0]*n
        self.size = [1]*n

    # x が属する集合の代表値を返す
    def find(self,x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = y = self.find(self.par[x])
            return y

    # x と y の集合を結合する
    def union(self,x,y):
        px = self.find(x)
        py = self.find(y)
        if px != py:
            if self.rank[px] < self.rank[py]:
                px, py = py, px
            if self.rank[px] == self.rank[py]:
                self.rank[px] += 1
            self.par[py] = px
            self.size[px] += self.size[py]

    # x と y が同じ集合に属するか判定する
    def is_same(self,x,y):
        return self.find(x) == self.find(y)

    # x が属する集合の要素数を返す
    def get_size(self,x):
        return self.size[self.find(x)]

N,M,K = LI()
A,B = LIR(M,2)
C,D = LIR(K,2)
 
b = defaultdict(set)
t = defaultdict(set)
 
uf = UF(N)
 
for i in range(M):
    uf.union(A[i]-1,B[i]-1)
    t[A[i]-1].add(B[i]-1)
    t[B[i]-1].add(A[i]-1)
    
num = [0]*N
for i in range(K):
    if uf.is_same(C[i]-1, D[i]-1):
        num[C[i]-1] -= 1
        num[D[i]-1] -= 1
        
ans = []
for i in range(N):
    ans.append(uf.get_size(i)-1-len(t[i])+num[i])
print(*ans)

Measured memory_bytes: 130524
import sys
from collections import deque

v,e,r=map(int, input().split());

edge_info=[0]*v;
for i in range(v):
    edge_info[i] = []

for i in range(e):
    e1, e2, w = map(int, input().split());
    edge_info[e1].append((e2,w))

v_q=deque();

INF = 9999999999999999999
d = [INF for i in range(v)]
d[r] = 0
v_q.append((0,r))
while(len(v_q) != 0):
    cost,u = v_q.popleft()
    if(cost > d[u]):
        continue
    for j in range(len(edge_info[u])):
        e2,w = edge_info[u][j]
        alt = cost+w
        if(d[e2] > alt):
            d[e2] = alt
            v_q.append((alt,e2))

for i in range(v):
    if(d[i] != INF):
        print(d[i])
    else:
        print("INF")



Measured memory_bytes: 90060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void solve(){
   int n,l;
   cin>>n>>l;
   vector<string> vec;
   for(int i=0;i<n;i++){
       string x;
       cin>>x;
       vec.push_back(x);
   }
   sort(vec.begin(),vec.end());
   for(auto i:vec){
       cout<<i;
   }
   
}
int main(){
   int t=1;
//   cin>>t;
   while(t--){
       solve();
   }
   return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<math.h>
#include<vector>
using namespace std;

//true:10101... false:01010...
string StringAlt(string S, int N, bool b){
  for(int i=0; i<N; i++){
	if(b == true){
	  S+="1";
	  b = false; }
    else{
	  S+="0";
	  b = true;
	}
  }
  return S;
}

int main(){

  string S;
  cin >> S;

  vector<string> S_alt(2, "");
  vector<int> count(2, 0);
  S_alt.at(0) = StringAlt(S_alt.at(0), S.length(), false);
  S_alt.at(1) = StringAlt(S_alt.at(1), S.length(), true);

  for(int i=0; i<S.length(); i++){
	if(S[i]!=S_alt.at(0)[i]){
	  count.at(0)++;
	}
	if(S[i]!=S_alt.at(1)[i]){
	  count.at(1)++;
	}
  }
  cout << ((count.at(0) < count.at(1)) ? count.at(0) : count.at(1));
  return 0;
}

Measured memory_bytes: 768
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 ans = (b - a) * (b - a + 1) / 2 - b;
        System.out.println(ans);
    }
}

Measured memory_bytes: 35700
#include <stdio.h>
#define MAX 10000

int isPrime(int);

int main(){
  int N;
  int x,res = 0;
  int i;
  scanf("%d",&N);
  for(i = 0 ; i < N ; i++){
    scanf("%d",&x);
    if(isPrime(x)){
      ++res;
    }
  }
  printf("%d",res);
  printf("\n");
  return 0;
}

int isPrime(int x){
  int i;
  if(x < 2){ return 0; }
  for(i = 2 ; i*i <= x ; i++){
    if(x % i == 0){ return 0; }
  }
  return 1;
}



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

int main(){
    int count=0;
    int n;
    cin>>n;
    vector <int> a;
    for(int i=0;i<n;i++){
        int s;
        cin>>s;
        a.push_back(s);
    }

    for(int i=0;i<n;i++){
        if(a[a[i]-1]==i+1){
            count++;
        }
    }
    cout<<count/2<<endl;
    
}

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

int main(){
  int H,W;
  string main,a="#";
  cin>>H>>W;
  for(int i=0;i<W+2; i++)
    cout<<a;
  cout<<endl;
  for(int j=0; j<H; j++){
    cin>>main;
    cout<<a<<main<<a<<endl;
  }
    for(int i=0;i<W+2; i++)
    cout<<a;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int a[100005], b[100005], c[100005];
unsigned long long dp[100005];
int main(){
	int n;
	int i, j, k;
	unsigned long long ans=0;
	
	scanf("%d", &n);
	for(i=1; i<=n; i++)
		scanf("%d", &a[i]);
	for(i=1; i<=n; i++)
		scanf("%d", &b[i]);
	for(i=1; i<=n; i++)
		scanf("%d", &c[i]);
	
	sort(a+1, a+1+n);
	sort(b+1, b+1+n);
	sort(c+1, c+1+n);
	
	b[n+1]=a[n+1]=0x7fffffff;
	for(i=0,j=1; j<=n; j++){
		while(a[i+1]<b[j])
			i++;
		dp[j]=dp[j-1]+i;
	}
	for(j=0,k=1; k<=n; k++){
		while(b[j+1]<c[k])
			j++;
		ans+=dp[j];
	}
	printf("%llu", ans);
	return 0;
} 

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

using namespace std;
typedef long long ll;

#define LOOP(i, a, n) for (int i = (int)a; i < (int)n; ++i)
#define REP(i, n) LOOP(i, 0, n)
#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define MAX_N 399

int main(void) {
  vector<pair<int, int>> ans;
  while (true) {
    int num;
    cin >> num;
    if (num == 0)
      break;
    int board[MAX_N][MAX_N];
    fill(board[0], board[MAX_N], -1);
    board[199][199] = 0;
    for (int i = 1; i < num; i++) {
      int n, d;
      cin >> n >> d;
      for (int j = 0; j < 399; j++) {
        for (int k = 0; k < 399; k++) {
          // cout << "i:" << i << " j:" << j << " k:" << k << endl;
          if (board[j][k] == n) {
            switch (d) {
            case 0:
              board[j][k - 1] = i;
              break;
            case 1:
              board[j + 1][k] = i;
              break;
            case 2:
              board[j][k + 1] = i;
              break;
            case 3:
              board[j - 1][k] = i;
              break;
            }
          }
        }
      }
    }

    int left = 500, right = 0, up = 500, down = 0;
    for (int i = 0; i < 399; i++) {
      for (int j = 0; j < 399; j++) {
        if (board[i][j] != -1) {
          left = min(left, j);
          right = max(right, j);
          up = min(up, i);
          down = max(down, i);
          // cout << j << " " << i << endl;
          // cout << left << " " << right << " " << up << " " << down << endl;
        }
      }
    }

    ans.push_back(make_pair(right-left+1, down-up+1));
  }

  for(int i=0; i<ans.size(); i++) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }

  return 0;
}

Measured memory_bytes: 3696
#include <stdio.h>
int main(void){
     
    int h, w;
    int i, j;
     
    while(1) {
        scanf("%d %d", &h, &w);
        if(h==0 && w==0)
            break;
     
        for (i=0; i<h; i++) {
            for(j=0; j<w; j++) {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


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

int main() {
  int n;cin>>n;
  vector<tuple<string,int,int>> vec(n+1);
  for(int i=1;i<=n;i++){
    string s;cin>>s;
    int p;cin>>p;
    p=-p;
    vec[i]=make_tuple(s,p,i);
  }
  sort(all(vec));
  for(int i=1;i<=n;i++){
    cout<<get<2>(vec[i])<<endl;
  }
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rem(i, m, n) for (int i = m; i < (n); i++)
#define eps (1e-7)
#define inf (1e9)
#define pi (acos(-1))
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

    int x, y;
    cin >> x >> y;
    rep(i, x + 1)
    {
        int turtle = x - i;
        if (i * 2 + turtle * 4 == y)
        {
            cout << "Yes"
                 << "\n";
            return 0;
        }
    }
    cout << "No"
         << "\n";
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n; cin >> n;
	for(int a = 1; a <= 9; a++) {
		if(n % a) continue;
		int b = n / a;
		if(b < 10) return cout << "Yes" << endl, 0;
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int INF = 100000000;
int i,j,k;
int main(){
    string s,t;cin>>s>>t;

    vector<int> s_num(26,0),t_num(26,0);

    for(i=0;i<s.size();i++){//アルファベットの数の組み合わせが同じであれば可変
        s_num[(int)(s[i]-'a')]++;
        t_num[(int)(t[i]-'a')]++;
    }

    sort(s_num.begin(),s_num.end());//アルファベットの数の組が同じかを知りたいのでsort
    sort(t_num.begin(),t_num.end());

    bool canchange=true;
    for(i=0;i<26;i++){
        if(s_num[i]!=t_num[i]){canchange=false;}
    }

    if(canchange){cout<<"Yes"<<endl;}
    else{cout<<"No"<<endl;}
    return 0;
}

Measured memory_bytes: 776
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n;
int a[maxn];
int ans = 1;
int pre;
int main()
{
	//freopen("D:\\code\\text\\input.txt","r",stdin);
	//freopen("D:\\code\\text\\output.txt","w",stdout);
	n = readint();
	repd(i, 1, n)
	{
		a[i] = readint();
	}
	pre = a[1];
	repd(i, 2, n)
	{
		if (pre >= a[i])
		{
			ans++;
		}
		pre = min(pre, a[i]);
	}
	printf("%d\n", ans );
	return 0;
}




Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)

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

int main(){
  string s,t;
  cin >> s >>t;
  int a,b;
  cin >> a >>b;
  string u;
  cin >> u;
  if(u==s) cout<< a-1 << " " << b <<endl;
  else cout<< a << " " << b-1 <<endl;
}


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


int D;
int c[27];
int cc[27];
int s[366][27];
int last[27];
const ll inf=1e6;

int main(){
    cin >> D;
    for(int i=1; i<27; i++){cin >> c[i];}
    for(int i=1; i<D+1; i++){
        for(int j=1; j<27; j++){
            cin >> s[i][j];
        }
    }
    for(int i=0; i<27; i++){
        last[i]=0;
    }

    ll ans=0;
    for(int i=1; i<D+1; i++){
        int r=1;
        int Max=0;
        for(int j=1; j<26; j++){
            if(s[i][r]<s[i+1][j+1]){
                Max=s[i+1][j+1];
                r=j+1;
            }
        }
        //sort(s[i][1], s[i][26]);
        cout << r << endl;
        ans+=Max;
        for(int j=1; j<27; j++){
            if(j!=r){
                last[j]++;
            }
            cc[j]=c[j]*(i-last[j]);
            s[i+1][j]-=cc[j];
        }
    }
    if(ans+inf>=0){
        //cout << ans+inf << endl;
    }
    else{
        //cout << 0 << endl;
    }
    return 0;
}

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

typedef long long ll;
int N;
string S;
int main(){
  cin >> N >> S;
  if(N%2 != 0){
    cout << "No" << endl;
    return 0;
  }
  for(int i = N/2; i < N; ++i){
    if(S[i - N/2] != S[i]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
map<long,long>mp;
int main()
{
    long i,j,t,a,b,n,c,y,m,prev,sum,ans=1;
    t=1;
    // cin>>t;
    while(t--)
    {
       string s;
       cin>>n>>a>>b;
       if(abs(n-a)>abs(n-b))cout<<"B";
       else cout<<"A";
    }
}

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

struct MaxFlow{
  struct edge{ int to,cap,rev; }; //{行先,容量,逆辺}
  vector< vector<edge> > G; //隣接リスト
  vector<bool> visited; //dfsで既に調べたかのフラグ

  void init(int n){
    G.resize(n);
    visited.resize(n);
  }

  void add_edge(int from,int to,int cap){
    G[from].push_back({to,cap,(int)G[to].size()});
    G[to].push_back({from,0,(int)G[from].size()-1});
  }

  //増加パスを探す
  int dfs(int v,int t,int f){
    if(v == t) return f;
    visited[v] = true;
    for(auto &e : G[v]){
      if(!visited[e.to] && e.cap > 0){
        int d = dfs(e.to,t,min(f,e.cap));
        if(d > 0){
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

  //sからtへの最大流を求める
  int maxflow(int s,int t){
    int flow = 0;
    for(;;){
      fill(visited.begin(),visited.end(),false);
      int f = dfs(s,t,1LL<<60);
      if(f == 0) return flow;
      flow += f;
    }
  }

}flow;

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

  int V; cin >> V;
  flow.init(V+V+2);
  vector<int> a(V),b(V);
  for(int i = 0; i < V; i++){
    cin >> a[i] >> b[i];
    flow.add_edge(V+V+1,i,1);
  }
  for(int i = 0; i < V; i++){
    int c,d; cin >> c >> d;
    flow.add_edge(V+i,V+V,1);
    for(int j = 0; j < V; j++){
      if(c > a[j] && d > b[j]){
        flow.add_edge(j,V+i,1);
      }
    }
  }
  cout << flow.maxflow(V+V+1,V+V) << endl;

  return 0;
}


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

int main(void) {
    // insert code here...
    int num, A, B;
    cin >> num >> A >> B;
    int points[num];
    int group[3];
    for(int i = 0; i < 3; i++){
        group[i] = 0;
    }
    
    for(int i = 0; i < num; i++){
        int point;
        cin >> point;
        if(point > B){
            group[2] ++;
        }else if(point > A){
            group[1] ++;
        }else{
            group[0] ++;
        }
        
    }
    
    sort(group, group + 3);
    
    cout << group[0] << endl;
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main()
{
  ll n,m, k;  cin >> n >> m >> k;
  ll a = n -k ;
  if(a < 0)
  {
      cout << 0 << ' ';
      ll b = a + m;
      if(b < 0) cout << 0 << '\n';
      else cout << b << '\n';

  }
  else {
    cout << a << ' ';
    cout << m << '\n';
  }

}


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

using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

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

    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    string ans = "";
    for (int i = 0; i < 1; ++i) {
        ans += toupper(s1[0]);
    }
    for (int i = 0; i < 1; ++i) {
        ans += toupper(s2[0]);
    }
    for (int i = 0; i < 1; ++i) {
        ans += toupper(s3[0]);
    }
    cout << ans << "\n";
}












Measured memory_bytes: 3628
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 5100000;
const int MOD = 1000000007;


//エラトステネスの篩
int prime[MAX]; //i番目の素数
bool is_prime[MAX]; //素数かどうか
int euler[MAX];
ll farey[MAX];

void sieve(){
  for(int i = 0; i<=MAX; i++){
    euler[i] = i;
  }
  for(int i = 2; i<= MAX; i++){
      if(euler[i] == i){
        for(int j = i; j<=MAX; j+=i){
          euler[j] = euler[j]/i * (i-1);
        }
      }
  }
}

int main(){
  int N; cin>>N;
  farey[0] = 1, farey[1] = 2;
  sieve();
  for(int i = 2; i<=MAX; i++){
    farey[i] = farey[i-1] + euler[i];
  }
  vector<int> t(N);
  rep(i,N) cin>>t[i];
  rep(i,N) cout<<farey[t[i]]<<endl;
}



Measured memory_bytes: 62816
#include<stdio.h>
int main()
{
	int a,b;
	char op;
	scanf("%d %c %d",&a,&op,&b);
	if(op=='+')
	{
		printf("%d\n",a+b);
	}
	if(op=='-')
	{
		if(a<=b)
		{
			printf("-%d\n",b-a);
		}
		else
		{
			printf("%d\n",a-b);
		}
	}
	return 0;
}


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

int FindHead(int node, vector<int>& pre)
{
	int head = node;
	while (pre[head] != head)
		head = pre[head];
	while (pre[node] != head)
	{
		int cur = pre[node];
		pre[node] = head;
		node = cur;
	}
	return head;
}

int main()
{
	int N, K, L;
	cin >> N >> K >> L;
	vector<int> pre_road(N + 1);
	vector<int> pre_railway(N + 1);
	for (int i = 1; i <= N; i++)
	{
		pre_road[i] = i;
		pre_railway[i] = i;
	}
	
	for (int i = 0; i < K; i++)
	{
		int a, b;
		cin >> a >> b;
		int head1 = FindHead(a, pre_road);
		int head2 = FindHead(b, pre_road);
		if (head1 != head2)
			pre_road[head2] = head1;
	}
	
	for (int i = 0; i < L; i++)
	{
		int a, b;
		cin >> a >> b;
		int head1 = FindHead(a, pre_railway);
		int head2 = FindHead(b, pre_railway);
		if (head1 != head2)
			pre_railway[head2] = head1;
	}

	map<pair<int, int>, int> count_map;
	for (int i = 1; i <= N; i++)
	{
		int head1 = FindHead(i, pre_road);
		int head2 = FindHead(i, pre_railway);
		count_map[make_pair(head1, head2)] ++;
	}
	
	for (int i = 1; i <= N; i++)
	{
		int head1 = FindHead(i, pre_road);
		int head2 = FindHead(i, pre_railway);
		cout << count_map[make_pair(head1, head2)];
		if (i != N)
			cout << " ";
		else
			cout << endl;
	}
    return 0;
}

Measured memory_bytes: 13568
#pragma region Template
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define All(x) (x).begin(),(x).end()
#define COL(x) cout << x << endl
#define CO(x) cout << x
//#define int long long

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = INT64_MAX >> 1;
const int INF = INT_MAX >> 1;

inline int sqr(int x) { return (x * x); }
inline void printd(double x) { printf("%.10lf\n", x); }
inline void upsort(VI& x) { sort((x).begin(), (x).end()); }
inline void downsort(VI& x) { sort((x).begin(), (x).end(), greater<int>()); }
inline int absdiff(int a, int b) { return (a - b) * (static_cast<int>(a > b)*2 - 1); }
int gcd(int a, int b) { // 最大公約数
	if (a < b) return gcd(b, a);
	int r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
inline int lcm(int a, int b) { return a * b / gcd(a, b); } // 最小公倍数
#pragma endregion

signed main()
{	
	using UL = unsigned long;
	int N, M, X;
	cin >> N >> M >> X;
	VI C(N);
	VVI A(N, VI(M));
	rep(i, N) {
		cin >> C[i];
		rbf(a, A[i]) cin >> a;
	}

	int price = INF;
	VI rikai(M, 0);
	for (UL i = 0uL; i < (1uL << N); i++) {
		int sum = 0;
		bitset<12> sel(i);
		fill(All(rikai), 0);
		rep(j, N) {
			if (sel[j]) {
				rep(k, M) {
					rikai[k] += A[j][k];
				}
				sum += C[j];
			}
		}
		if (*min_element(All(rikai)) >= X) {
			price = min(price, sum);
		}
	}

	if (price == INF) COL(-1);
	else COL(price);
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
using P =pair<int,int>;
typedef long long ll;
 
int main() {

  int n, m;
  cin >> n >> m;
  int s[n];
  if (n == 1) s[0] = 0;
  else {
    s[0] = 1;
    for(int i = 1; i < n; ++i) s[i] = 0;
  }
 
  if(n == 1){
    rep(j, m) {
      int t, c;
      cin >> t >> c;
      --t;
      if(s[t] != 0 && s[t] != c) {
        cout << "-1" << endl;
        return 0;
      } else {
        s[t] = c;
      }
    }
    cout << s[0] << endl;
    return 0;
  }
 
  rep(j, m) {
    int t, c;
    cin >> t >> c;
    --t;
    if(t==0 && c==0){
      cout << "-1" << endl;
      return 0;
    }
    if(t == 0){
      if(s[t] != 1 && s[t] != c) {
        cout << "-1" << endl;
        return 0;
      } else {
        s[t] = c;
      }
    } else {
      if(s[t] != 0 && s[t] != c) {
        cout << "-1" << endl;
        return 0;
      } else {
        s[t] = c;
      }
    }
  }
  int ans = 0;
 
  for(int i = 0; i < n; ++i){
    ans = ans * 10 + s[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	vector<int> v(N);
	for (int i = 0; i < N; i++) cin >> v.at(i);

	int a, b;
	auto x = v;
	sort(v.begin(), v.end());
	a = v.at(N / 2 - 1);
	b = v.at(N / 2);

	for (int i = 0; i < N; i++) {
		if (x.at(i) <= a) cout << b << endl;
		else cout << a << endl;
	}
}

Measured memory_bytes: 4772
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int N;
    cin >> N;

    vector<char> C(2 * N);
    vector<int> A(2 * N);
    REP(i, 2 * N) cin >> C[i] >> A[i];

    vector<vector<int>> costb(2 * N, vector<int>(N + 2, 0));
    vector<vector<int>> costw(2 * N, vector<int>(N + 2, 0));
    vector<int> bpos(N + 1, -1);
    vector<int> wpos(N + 1, -1);

    REP(i, 2 * N) {
        if (C[i] == 'B') {
            costb[i][A[i]]++;
            bpos[A[i]] = i;
        }
        if (C[i] == 'W') {
            costw[i][A[i]]++;
            wpos[A[i]] = i;
        }
    }
    REP(i, 2 * N - 1) {
        FOR(j, 1, N) {
            costb[i + 1][j] += costb[i][j];
            costw[i + 1][j] += costw[i][j];
        }
    }
    REP(i, 2 * N) {
        REV(j, N - 1, 1) {
            costb[i][j] += costb[i][j + 1];
            costw[i][j] += costw[i][j + 1];
        }
    }

    vector<vector<int>> dp(N + 1, vector<int>(N + 1, INF));
    dp[0][0] = 0;
    REP(i, N + 1) {
        REP(j, N + 1) {
            if (i + 1 <= N) {
                int pos = bpos[i + 1];
                int cost = 0;
                if (pos > 0) {
                    cost += costb[pos - 1][i + 1] + costw[pos - 1][j + 1];
                }
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + cost);
            }
            if (j + 1 <= N) {
                int pos = wpos[j + 1];
                int cost = 0;
                if (pos > 0) {
                    cost += costb[pos - 1][i + 1] + costw[pos - 1][j + 1];
                }
                dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + cost);
            }
        }
    }

    cout << dp[N][N] << endl;

    return 0;
}


Measured memory_bytes: 157184