akhauriyash/Code-Regression huggingface dataset:
#include<iostream>

using namespace std;

int main() {
	
	int type, year;
	
	cin >> type >> year;
	
	switch(type) {
		
		case 0:
		if( 1868 <= year && year <= 1911)
		cout << "M" << year - 1868  + 1 << "\n";
		
		if( 1912 <= year && year <= 1925)
		cout << "T" << year - 1912  + 1 << "\n";
		
		if( 1926 <= year && year <= 1988)
		cout << "S" << year - 1926  + 1 << "\n";
		
		if( 1989 <= year && year <= 2016)
		cout << "H" << year - 1989  + 1 << "\n";
		
		break;
		
		case 1:
		cout << 1868 + year - 1 << "\n";
		break;
		
		case 2:
		cout << 1912 + year - 1 << "\n";
		break;
		
		case 3:
		cout << 1926 + year - 1 << "\n";
		break;
		
		default:
		cout << 1989 + year - 1 << "\n";
		break;	
		
	}
	
	return 0;
}


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


int main (){
    string str;int k;cin>>str>>k;
    int len=str.length();
    set<string>s;
    for(int i=0;i<len;i++){
        string tmp;
        tmp+=str[i];
        s.insert(tmp);
        if(s.size()>k) s.erase(--s.end());
        for(int j=i+1;j<i+k+1&&j<len;j++){
            tmp+=str[j];
            s.insert(tmp);
            if(s.size()>k) s.erase(--s.end());
        }
    }
    set<string>::reverse_iterator it=s.rbegin();
    cout<<*it<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

typedef pair<ll,pll> ppll;

string tos(ll n) {
  string res;
  while(n) {
    res=(char)((int)(n%10)+'0')+res;
    n/=10;
  }
  ll zn=6-res.size();
  for(ll i=0;i<zn;i++) {
    res='0'+res;
  }
  return res;
}

int main() {
  ll n,m;
  cin >> n >> m;
  mat k(n);
  vector<ppll> s(m);
  for(ll i=0;i<m;i++) {
    ll p,y;
    cin >> p >> y;
    p--;
    s[i]=ppll(y,pll(p,i));
  }
  sort(s.begin(),s.end());
  for(ll i=0;i<m;i++) {
    k[s[i].second.first].push_back(s[i].second.second);
  }
  vector<string> ans(m);
  for(ll i=0;i<n;i++) {
    string pre=tos(i+1);
    for(ll j=0;j<k[i].size();j++) {
      string num=tos(j+1);
      ans[k[i][j]]=pre+num;
    }
  }
  for(ll i=0;i<m;i++) {
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 14720
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

int A, B;

int main() {
    cin >> A >> B;
    if (A == 1) A = 14;
    if (B == 1) B = 14;
    cout << (A > B ? "Alice" : A < B ? "Bob" : "Draw") << endl;
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  bool result = true;
  
  string x = s;
    reverse(x.begin(), x.end());
  if(s != x) {
   result = false;
  }
  
  string a = s.substr(0,(s.size() / 2));
  string y =  a;
  reverse(y.begin(), y.end());
  if (a != y) {
   result = false;
  }
  
  string b = s.substr((s.size() + 3) / 2 -1, s.size() -1);
  string z = b;
  reverse(z.begin(), z.end());
  if (z != b) {
   result = false;
  }
  
  if (result) {
    cout << "Yes";
  }
   else {
   cout << "No";
   }
}


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

namespace Programminng
{
    class AOJ_Volume0029
    {
        public static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            string len_max = s[0], ans = s[0];
            int count_max = 0;
            Dictionary<string, int> map = new Dictionary<string,int>();

            for (int i = 0; i < s.Length; i++)
            {
                if (len_max.Length < s[i].Length)
                {
                    len_max = s[i];
                }

                try{
                    map.Add(s[i], 1);
                }catch{
                    map[s[i]]++;
                }

                if (map[s[i]] > count_max)
                {
                    count_max = map[s[i]];
                    ans = s[i];
                }
            }

            Console.WriteLine(ans + " " + len_max);
        }
    }
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> nl(N + 1);
    rep(i, M) {
        int X, Y, Z;
        cin >> X >> Y >> Z;
        nl[X].push_back(Y);
        nl[Y].push_back(X);
    }

    int ans = 0;
    unordered_set<int> seen;
    stack<int> st;
    rep2(i, 1, N + 1) {
        if (seen.find(i) == seen.end()) {
            ans++;
            st.push(i);
            while (st.size() > 0) {
                int v = st.top();
                st.pop();
                for (int &next_v : nl[v]) {
                    seen.insert(v);
                    if (seen.find(next_v) == seen.end()) {
                        st.push(next_v);
                    }
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 10256
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
using namespace std;
typedef long long LL;
template<typename T>inline T chkmax(T A,T B){return A>B?A:B;}
template<typename T>inline T chkmin(T A,T B){return A<B?A:B;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
int n,x,k,now,Max;
int main()
{
	read(n);read(k);
	read(now);
	Max=now;
	For(i,2,n)read(x),now=__gcd(now,x),Max=chkmax(Max,x);
	if(k%now==0&&Max>=k)puts("POSSIBLE");
	else puts("IMPOSSIBLE");
	return 0;
}


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

// iterator
#define REP(i,init, n) for(lli i=init;i<n;i++)
#define REPE(i,init, n) for(lli i=init;i<=n;i++)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;

int main() {
    lli n;
    cin1(n);
    lli p[n+1];
    REPE(i, 1, n) {
        cin >> p[i];
    }

    lli s = 0;
    lli ans = 0;
    bool chosen = false;
    REPE(i, 1, n) {
        if (p[i] == i) {
            if (!chosen) {
                s = i;
                chosen = true;
            }
            else {
                ans += i - s;
                chosen = false;
            }
        }
        else {
            if (chosen && p[i] != s) {
                ans += i - s;
                chosen = false;
            }
        }
    }
    if (chosen)
        ans++;
    cout << ans << endl;
}


// 1 3 4 5 2 6
// 1 3 4 5 6 2
// 1 3 4 6 5 2
// 1 3 6 4 5 2
// 1 6 3 4 5 2
// 6 1 3 4 5 2
// 6 3 1 4 5 2
// 6 3 4 1 5 2
// 6 3 4 5 1 2
// 6 3 4 5 2 1


// 3 1 4 5 2 6
// 3 1 4 5 2 6
// 3 1 4 5 6 2

// 3 2 1 4 5 6 7


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

using namespace std;

bool isPrime(long long int n){
    for(long long int i = 2; (i*i) <= n; i++){
        if((n%i) == 0){
            return false;
        }
    }
    return true;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    long long int a, res;

    cin>>a;
    
    res = a-1;
    for(long long int i = 1; i <= sqrt(a); i++){
        if(a % i == 0){
            if(res > ((i-1)+((a/i)-1))){
                res = min(res, ((i-1)+((a/i)-1)));
            }
        }
    }
    cout<<res;

    cout<<endl;

    return 0;
}

Measured memory_bytes: 384
n,m = map(int, input().split())
h = list(map(int, input().split()))
adjacent_list = [[] for i in range(n+1)]
def check(node):
    now = h[node-1]
    for i in adjacent_list[node]:
        if now <= h[i-1]:
            return False
    return True
for i in range(m):
    a,b = map(int, input().split())
    adjacent_list[a].append(b)
    adjacent_list[b].append(a)
ans = 0
for i in range(1,n+1):
    if check(i):
        ans += 1
print(ans)

Measured memory_bytes: 94472
import sys
input = sys.stdin.buffer.readline
import itertools

def to_str(string, array):
    for i in array:
        string += str(i)
    return string

def main():
    n = int(input())
    p = list(map(int,input().split()))
    q = list(map(int,input().split()))

    p_str = ""
    q_str = ""
    p_str = to_str(p_str, p)
    q_str = to_str(q_str, q)
    
    arr = [i+1 for i in range(n)]

    nums = list(itertools.permutations(arr))
    nums_str = []
    for e in nums:
        temp = ""
        temp = to_str(temp, e)
        nums_str.append(temp)

    nums_str.sort()

    a = nums_str.index(p_str) + 1
    b = nums_str.index(q_str) + 1
    print(abs(a-b))

if __name__ == '__main__':
    main()

Measured memory_bytes: 16816
MAX = 4*10**5
bikkuri=[1]
mod = 10**9+7
for i in range(1,MAX+1):
    bikkuri.append((bikkuri[-1]*i)%mod)

def Comb(n,k):
    ans = bikkuri[n]*pow(bikkuri[k],mod-2,mod)*pow(bikkuri[n-k],mod-2,mod)
    ans %=mod
    return ans
    
n,k = map(int,input().split())
if n-1 <= k:
    ans = Comb(2*n-1,n)
    print(ans)
else:
    tmp = 0
    for i in range(k+1):
        tmp += Comb(n,i)*Comb(n-1,i)
        tmp %= mod
    print(tmp)

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

typedef long long ll;
typedef long double ld;

#define n1		      "\n"
#define B                     begin()
#define E                     end()
#define F                     first
#define S                     second
#define pb                    push_back
#define pf                    push_front
#define popb                  pop_back()
#define popf                  pop_front()

const int BIG=1e5+55;
const int BIGG=1e9+7;
const ll BIGGE=1e12+55;
const double SML=(1e-7);

using namespace std;

    int k;
    ll sum;

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);
    cout.tie(NULL);
    cin >>k;
    for (int i=1; i<=k; i++)
        for (int j=1; j<=k; j++) {
             int x = __gcd(i,j);
             for (int l=1; l<=k; l++)
                sum += __gcd(x,l);
        }
    cout <<sum;


    return 0;
}


Measured memory_bytes: 3660
import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static final int MOD = 1_000_000_007;
    public static void main(String[] args) {
        Scanner sc = new Scanner(new BufferedInputStream(System.in));
        int n= nextInt(sc);
        long[] a = toArray(sc.nextLine());
        long[] count = new long[60];
        for (int j = 0; j < count.length ; j++) {
            for (int i = 0; i < n; i++) {
                long res = (a[i] >> j) & 1;
                if(res == 1) count[j]++;
            }
        }
        long sum = 0L;
        long prod = 1L;
        for (int i = 0; i < count.length; i++) {
            sum = ( (sum%MOD) + ((count[i]*(n-count[i]))%MOD) * (prod%MOD) )%MOD ;
            prod*=2;
        }

        System.out.println(sum);
    }

    private static int nextInt(Scanner sc) {
        return Integer.valueOf(sc.nextLine());
    }
    private static long[] toArray(String text) {
        return Arrays.stream(text.split(" ")).mapToLong(Long::valueOf).toArray();
    }
}

Measured memory_bytes: 129804
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    ll h,n,ans{},a;
    in>>h>>n;
    fr(i,n) in>>a,ans+=a;
    cout<<(ans>=h?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int N;
vector<int>A;

int main(void)
{
	cin >> N;
	for (int i = 0; i < N; ++i) {
		int a;
		cin >> a;
		A.push_back(a);
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < i; ++j) {
			int dif = abs(A[i] - A[j]);
			if (dif % (N - 1) == 0) {
				cout << A[i] << " " << A[j] << endl;
				return 0;
			}
		}
	}
	return 0;
}



Measured memory_bytes: 3160
#include<bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define pb push_back

using namespace std;

const int N=2e5+5;

ll k,n,a[N],ans;

int main()
{
    cin >> k >> n;
    for (int i=0;i<n;i++)
    {
        cin >> a[i];
    }
    for (int i=1;i<n;i++)
    {
        ans=max(ans,a[i]-a[i-1]);
    }
    ans=max(k+a[0]-a[n-1],ans);
    cout << k-ans << endl;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include <string.h>
int main()
{
    char s[150];
    int i,e;
    gets(s);
    e=strlen(s);
    for(i=0;i<e;i++){
         if(i%2==0){
            if(s[i]=='R'||s[i]=='U'||s[i]=='D'){
                continue;
            }
            else{
                break;
            }
        }
        else{
        	if(s[i]=='L'||s[i]=='U'||s[i]=='D'){
                    continue;
            }
            else{
                break;
            }
       }
    }
    if(i==e){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

int main() {
  ll N, M;
  cin >> N >> M;
  vec<pair<ll, ll>> X(N);
  REP(i, N) cin >> X[i].first >> X[i].second;
  sort(ALL(X));
  ll res = 0, cans = 0;
  REP(i, N) {
    if (cans == M)
      break;
    const auto tmp = cans;
    cans = min(M, cans + X[i].second);
    res += (cans - tmp) * X[i].first;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 4756
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rush() int T;scanf("%d",&T);while(T--)
#define mm(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define pf(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define p_f(a) printf("%d ",a)
#define fi first
#define se second
#define db double
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const db eps=1e-9;
int n;
int main()
{
	cin>>n;
	cout<<n*n<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
   int n ;
   cin >> n ;
   int y=0;
  
  for (int i = 0; i < n; i++) {
   string s;
   cin >> s ;
    if ( s == "Y") {
      y = 1;
    }
  }
  
    if ( y == 1) {
      cout << "Four" << endl;
    }
    else {
      cout << "Three" << endl;
    }
}

Measured memory_bytes: 3640
fn gcd<T>(a: T, b: T) -> T
where
    T: Copy + std::cmp::PartialEq + std::ops::Rem<Output = T> + std::convert::From<u8>,
{
    if b == T::from(0u8) {
        a
    } else {
        gcd(b, a % b)
    }
}

fn factor(mut n: usize) -> Vec<(usize, usize)> {
    let mut ret = vec![];
    for i in 2.. {
        if i * i > n {
            break;
        }
        let mut cnt = 0;
        while n % i == 0 {
            cnt += 1;
            n /= i;
        }
        if cnt != 0 {
            ret.push((i, cnt));
        }
    }
    if n != 1 {
        ret.push((n, 1));
    }
    ret
}

fn main() {
    proconio::input! {
        n: usize,
        a_s: [usize; n],
    }
    let mut gcdval = a_s[0];
    let mut set = std::collections::HashSet::<usize>::new();
    for (item, _num) in factor(a_s[0]) {
        set.insert(item);
    }
    let mut pairwise_coprime = true;
    for &a in a_s[1..].iter() {
        gcdval = gcd(gcdval, a);
        let f = factor(a);
        for (item, _num) in f {
            if set.contains(&item) {
                pairwise_coprime = false;
            } else {
                set.insert(item);
            }
        }
    }
    let ans = if pairwise_coprime {
        "pairwise coprime"
    } else if gcdval == 1 {
        "setwise coprime"
    } else {
        "not coprime"
    };
    println!("{}", ans);
}


Measured memory_bytes: 18408
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
int N, Q;
const int NQmax = 2e5;
ll S[NQmax], T[NQmax], X[NQmax], D[NQmax];

int main(){
	cin >> N >> Q;
	for(int i=0; i<N; i++) cin >> S[i] >> T[i] >> X[i];
	for(int i=0; i<Q; i++) cin >> D[i];

	vector<pair<int, int> > v;
	for(int i=0; i<N; i++){
		v.push_back({S[i]-X[i], i});
	}
	for(int i=0; i<Q; i++){
		v.push_back({D[i], i+N});
	}
	sort(v.begin(), v.end());

	priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > que;
	ll ans = 0;
	for(int i=0; i<N+Q; i++){
		int x = v[i].first;
		int j = v[i].second;
		if(j < N){
			que.push({X[j], j});
		} else {
			j -= N;
			while(!que.empty() && T[que.top().second]-X[que.top().second]<=x) que.pop();
			if(que.empty()){
				cout << -1 << endl;
			} else {
				cout << que.top().first << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 14956
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>

using namespace std;

int main() {
  int32_t n, m;
  cin >> n >> m;
  vector<vector<int32_t>> edge(n, vector<int32_t>());
  vector<int32_t> degree(n, 0);
  for (int32_t i = 0; i < m; ++i) {
    int32_t x, y;
    cin >> x >> y;
    --x;
    --y;
    edge[x].push_back(y);
    ++degree[y];
  }

  vector<int32_t> dp(n, 0);
  deque<int32_t> q;
  for (int32_t i = 0; i < n; ++i) {
    if (degree[i] == 0) {
      q.push_back(i);
    }
  }
  while (!q.empty()) {
    int32_t v = q.front();
    q.pop_front();
    for (int32_t w : edge[v]) {
      dp[w] = max(dp[w], dp[v] + 1);
      --degree[w];
      if (degree[w] == 0) {
        q.push_back(w);
      }
    }
  }

  auto itr = max_element(dp.begin(), dp.end());
  cout << *itr << endl;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int inf = 0x3f3f3f3f,oo = inf;
#define pi 3.14159265358979323846
#define IL inline
#define RG register
#define rep(i,a,b) for(RG int i=(a);i<(b);++i)
#define Rep(i,a,b) for(RG int i=(a);i<=(b);++i)
#define Dep(i,a,b) for(RG int i=(a);i>=(b);--i)
#define pc putchar
/*char __wzp[1<<15|1],*__S=__wzp+32768;
#define gc() (__S>=__wzp+32768?(__wzp[fread(__wzp,sizeof(char),1<<15,stdin)]=EOF),*((__S=__wzp)++):*(__S++))*/
#define gc getchar
IL ll read(){
    RG ll x=0;char f=0;RG char c=gc();
    for(;!isdigit(c);c=gc())f|=(c=='-');
    for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
    return f?-x:x;
}
IL double readdb(){
    RG double x=0,p=0.1;RG char f=0,c=gc();
    for(;!isdigit(c);c=gc())f|=(c=='-');
    for(;isdigit(c);c=gc())x=x*10+(c^48);
    if(c=='.')for(c=gc();isdigit(c);c=gc(),p/=10)x=x+(c^48)*p;
    return f?-x:x;
}
IL void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);pc(x%10+'0');}
IL void writeln(ll x){write(x);puts("");}
IL void writeln(ll x,char c,ll y){write(x);pc(c);writeln(y);}
IL void writeln(ll x,char c,ll y,char d,ll z){write(x);pc(c);write(y);pc(d);writeln(z);}
#define debug(x) printf(#x" = %d\n",x);
#define rd() read()
#define rdb() readdb()
#define mem(x,v) memset(x,v,sizeof(x))
#define pb push_back
#define mp make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-(x)))
#define fin(x) freopen(#x".in","r",stdin)
#define fout(x) freopen(#x".out","w",stdout)
#define y1 ____y1
#define hash __hash
#define union _union
const int maxn = 500009;
set<int> f,b;
vector<int> g[maxn];
int p[maxn],q[maxn],deg[maxn],n,k;
int main(){
	n = rd(),k = rd();
	Rep(i,1,n) q[p[i] = rd()] = i;
	rep(i,1,k) f.insert(p[i]);
	Rep(i,1,n){
		if(i+k-1<=n) f.insert(p[i+k-1]);
		if(i) f.erase(p[i-1]);
		b.insert(p[i]);
		if(i>k) b.erase(p[i-k]);
		set<int>::iterator cur;
		cur = f.upper_bound(p[i]);
		if(cur != f.end()) g[q[*cur]].pb(i),deg[i]++;
		cur = b.upper_bound(p[i]);
		if(cur != b.end()) g[q[*cur]].pb(i),deg[i]++;
	}
	f.clear();
	Rep(i,1,n) if(!deg[i]) f.insert(-i);
	int top=0;
	while(f.size()){
		int u = -(*f.begin());
		p[++top] = u;
		f.erase(f.begin());
		for(unsigned i=0;i<g[u].size();++i)
			if(--deg[g[u][i]]==0) f.insert(-g[u][i]);
	}
	Rep(i,1,n) q[p[i]]=n-i+1;
	Rep(i,1,n) writeln(q[i]);
}

Measured memory_bytes: 60800
#import sys
#input = sys.stdin.readline
import random
import bisect
#from statistics import mean, median, variance, stdev

#template input

def IT(): #整数1個
    return int(input())
def IL(): #整数複数
    return [int(_) for _ in input().split()]
def IS(): #文字列複数
    return [_ for _ in input().split()]
def ILS(n): #整数1つ　縦にズラーってなってるやつ
    return [int(input()) for _ in range(n)]
def SLS(n): #文字列　縦にズラーってなってるやつ
    return [input() for _ in range(n)]
def ILSS(n): #整数複数　縦にズラーってなってるやつ
    return [[int(_) for _ in input().split()] for j in range(n)]

#template technique
def bit_full_search(ss):
    n = len(ss)
    for i in range(1 << n):
        s = ""
        for j in range(n + 1):
            if ((1 & i >> j) == 1):
                s += ss[j]
        print(s)
def bit_full_search2(A):
    #https://blog.rossywhite.com/2018/08/06/bit-search/
    value = []
    for i in range(1 << len(A)):
        output = []

        for j in range(len(A)):
            if ((i >> j) & 1) == 1:
                #output.append(A[j])
                output.append(A[j])
        value.append([format(i, 'b').zfill(16), sum(output)])

    value.sort(key=lambda x:x[1])
    bin = [value[k][0] for k in range(len(value))]
    val = [value[k][1] for k in range(len(value))]
    return bin, val
def matching_bisect(list1_val, list2_val, n):
    #2分探索
    j = 0
    for i in range(len(list1_val)):
        j = bisect.bisect_left(list2_val, n - list1_val[i])
        if j < len(list2_val):
            if list1_val[i] + list2_val[j] == n:
                #ans = list2_bin[j] + list1_bin[i]
                break
    return j

"""ここからメインコード"""

def main():

    a,b,k = IL()
    c = 0
    for i in range(101, 0, -1):
        if (a)%i == 0 and (b)%i == 0:
            #print(i)
            c += 1
            if c == k:
                print(i)
                break








main()


Measured memory_bytes: 5352
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	int n, k, d;

	cin >> n >> k;
	vector<bool> usable(10, true);
	for (int i = 0; i < k; i++) {
		cin >> d;
		usable[d] = false;
	}

	while(1) {
		int tmp = n;
		bool ok = true;
		while (tmp > 0) {
			if (!usable[tmp % 10]) {
				ok = false;
				break;
			}
			tmp /= 10;
		}
		if (ok) {
			break;
		}

		n++;
	}

	cout << n << endl;
	return 0;
}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>

#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;


int i = 0;
string W;
string T;
map<string,int> Map;

int main()
{
  cin >>W;
  transform(W.begin(),W.end(),W.begin(),::toupper);
  while(cin>>T,T !="END_OF_TEXT"){
    transform(T.begin(),T.end(),T.begin(),::toupper);
    if(W == T){
      i = ++Map[T];
  }
  }
      cout <<i<<endl;

  return 0;
}

Measured memory_bytes: 1200
N, K = map(int, input().split())
x = list(map(int, input().split()))
 
ans = 3 * (10 ** 8) + 1
for i in range(N - K + 1):
    l = x[i]
    r = x[i+K-1]
    ans = min([ans, abs(l) + r - l, abs(r) + r - l])
 
print(ans)

Measured memory_bytes: 14252
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var line = Console.ReadLine().Split(' ');
        var ans = 0;
        for(var i = 1; i <= n; i++)
        {
            if(i % 2 == 1 && int.Parse(line[i - 1]) % 2 == 1)
            {
                ans++;
            }
        }



        Console.WriteLine(ans);
        Console.ReadLine();
    }
}



Measured memory_bytes: 17808
#include <iostream>
using namespace std;
long long int ans1, ans2, sum1, sum2;
int n, i;
long long int a[100005];
int main()
{
    cin >> n;
    for (i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    if (a[1] >0)
    {
        sum1 = a[1];
        ans2= a[1] + 1;
        sum2 = -1;
    }
    else if (a[1] == 0)
    {
        sum1 = 1;
        ans1 = ans2 = 1;
        sum2 = -1;
    }
    else
    {
        sum1 = 1;
        ans1 = abs(a[1]) + 1;
        sum2 = a[1];
    }
    for (i = 2; i <= n; i++)
    {
        if (sum1 > 0)
        {
            if (a[i] + sum1 >= 0)
            {
                ans1 += a[i] + sum1 + 1;
                sum1 = -1;
            }
            else
            {
                sum1 += a[i];
            }
        }
        else
        {
            if (a[i] + sum1 <= 0)
            {
                ans1 += abs(sum1 + a[i]) + 1;
                sum1 = 1;
            }
            else
            {
                sum1 += a[i];
            }
       }
    }
    if (sum1 == 0)
    {
        ans1++;
    }
    for (i = 2; i <= n; i++)
    {
        if (sum2 > 0)
        {
            if (a[i] + sum2 >= 0)
            {
                ans2 += a[i] + sum2 + 1;
                sum2 = -1;
            }
            else
            {
                sum2 += a[i];
            }
        }
        else
        {
       if (a[i] + sum2 <= 0)
            {
                ans2 += abs(sum2 + a[i]) + 1;
                sum2 = 1;
            }
            else
                sum2 += a[i];
        }
    }
    if (sum2 == 0)
    {
        ans2++;
    }
    cout << min(ans1, ans2) << endl;
    return 0;
}



Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int K = scanner.nextInt();
    char[] s = scanner.next().toCharArray();
    int diff = 0;
    int score = 0;
    for (int i = 0; i < N - 1; i++) {
      if (s[i] != s[i + 1]) diff++;
      else score++;
    }
    System.out.println(score + Math.min(diff, K * 2));
  }
}


Measured memory_bytes: 27032
def main():
    n, m = map(int, input().split())
    x = [None] * m
    y = [None] * m
    for i in range(m):
        x[i], y[i] = map(int, input().split())

    ball = [1] * n
    red = [False] * n
    red[0] = True
    for i in range(m):
        if red[x[i]-1]:
            red[y[i]-1] = True
        ball[x[i]-1] -= 1
        ball[y[i]-1] += 1
        if ball[x[i]-1] == 0:
            red[x[i]-1] = False

    print(sum(red))

if __name__ == '__main__':
    main()


Measured memory_bytes: 12404
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

struct Item
{
	int Index;
	char Digit;
};

struct Item A[6];
int N;
int M;

int main()
{
	scanf("%d %d", &N, &M);
	for(int i=1; i<=M; i++)
	{
		scanf("%d %c", &A[i].Index, &A[i].Digit);
		A[i].Index--;
	}
	int start, end;
	if(N==1) 
	{
		start = 0;
		end = 9;
	}
	else if(N==2)	
	{
		start = 10;
		end = 99;
	}
	else if(N==3)
	{
		start = 100;
		end = 999;
	}
	for(int i=start; i<=end; i++)
	{
		char S[4];
		sprintf(S, "%d", i);
		bool OK = true;
		for(int j=1; j<=M; j++)
		{
			if(S[A[j].Index] != A[j].Digit)
			{
				OK = false;
			}
		}
		if(OK)
		{
			printf("%d", i);
			return 0;
		}
	}
	printf("-1");
	return 0;
}

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

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int x; cin >> x;
	int ans = 0, cur = 0;
	while(cur < x)
		ans++, cur+=ans;
	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2000000)
input = sys.stdin.readline
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.parents = [i for i in range(n+1)]
        #dist[x]はxとその親との間の距離を保持している
        self.dist = [0]*(n+1)
    def find(self,x):
        if self.parents[x]==x:
            return x
        else:
            a = self.parents[x]
            self.parents[x]=self.find(self.parents[x])
            self.dist[x] += self.dist[a]
            return self.parents[x]
    def unite(self,l,r,d):
        rRoot = self.find(r)
        lRoot = self.find(l)
        if rRoot == lRoot:
            if self.dist[l] - self.dist[r] != d:
                print("No")
                exit()
        else:
            #rRootとlRoot、どちらが親になるべきか決める
            newLDist = d + self.dist[r]
            if newLDist>=self.dist[l]:
                self.parents[lRoot] = rRoot
                self.dist[lRoot] = newLDist-self.dist[l]
            else:
                self.parents[rRoot] = lRoot
                self.dist[rRoot] = self.dist[l]-newLDist

N,M = map(int,input().split())
tree = UnionFind(N)
for _ in range(M):
    l,r,d = map(int,input().split())
    tree.unite(l,r,d)
print("Yes")

Measured memory_bytes: 88224
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e2+5;
int n, m, f[N][N]; char a[N][N];
int main()
{
    scanf("%d%d", &n, &m); for(int i = 1; i <= n; ++i) scanf("%s", a[i]+1);
    memset(f, 0x3f, sizeof(f)), f[1][1] = a[1][1] == '#';
    for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j)
    {
        if(i != n) f[i+1][j] = min(f[i+1][j], f[i][j]+(a[i][j] != '#'&&a[i+1][j] == '#'));
        if(j != m) f[i][j+1] = min(f[i][j+1], f[i][j]+(a[i][j] != '#'&&a[i][j+1] == '#'));
    }
    printf("%d\n", f[n][m]);
    return 0;
}

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

uint64_t solve(vector<int>&v,uint64_t sum=1,int i=0,int size=0){
	if(i==3)return sum;
	else if(size==v.size())return 0;
	return solve(v,sum*v.at(size),i+1,size+1)+solve(v,sum,i,size+1);
}

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	vector<int>a(5,0);
	for(int i=0;i<n;++i){
		string s; cin>>s;
		if(s.front()=='M')++a.at(0);
		else if(s.front()=='A')++a.at(1);
		else if(s.front()=='R')++a.at(2);
		else if(s.front()=='C')++a.at(3);
		else if(s.front()=='H')++a.at(4);
	}
	vector<int>v;
	for(auto&i:a)if(i>0)v.emplace_back(i);
	cout<<solve(v)<<"\n"s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

ll N, X, D, res;
map<int, vector<pair<ll, ll>>>mp;

int main() {
	cin >> N >> X >> D;
	if (D == 0) {
      	if(X==0)cout<<1<<endl;
      	else cout << N + 1 << endl;
		return 0;
	}
	if (D < 0) {
		X += (N - 1)*D;
		D = -D;
	}
	for (ll i = 0; i <= N; i++) {
		ll L = i*X + i*(i - 1) / 2 * D;
		ll R = i*X + i*(2 * N - i - 1) / 2 * D;
		mp[abs(X)*i%D].push_back({ L,R });
	}
	for (auto a : mp) {
		vector<pair<ll, ll>>v = a.second;
		sort(v.begin(), v.end());
		ll mx = -llmax;
		for (pair<ll, ll>p : v) {
			if (mx < p.first) {
				res += (p.second - p.first) / D + 1;
			}
			else if (mx < p.second) {
				res += (p.second - mx) / D;
			}
			mx = max(mx, p.second);
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 22144
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long double ld;

using namespace std;


int main() {
	string s;
	cin >> s;
	string t;
	for (int i = 0; i < (int)s.size(); ++i) {
		if ((int)t.size() != 0 && t.back() == 'S' && s[i] == 'T')
			t.pop_back();
		else
			t += s[i];
	}
	cout << t.size() << "\n";
	return 0;
}




Measured memory_bytes: 776
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
# include <random>
# include <chrono>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2147483647;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))),(c).end())
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, a;

int main() {
	cin >> n >> a;
	cout << n*n - a << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
const ll MOD = 1e9+7;
ll po(ll a, ll b){return b ? (b & 1 ? a : 1) * po(a * a % MOD, b / 2) % MOD : 1;}
int main(){
    string s;
    cin >> s;
    ll dp[s.size() + 1][3];
    for(ll i = 0; i <= s.size(); i++) for(ll j = 0; j < 3; j++) dp[i][j] = 0;
    ll q = 0;
    ll ans = 0;
    for(ll i = 0; i < s.size(); i++){
        char c = s[i];
        for(ll j = 0; j < 3; j++) dp[i + 1][j] = dp[i][j];
        switch(c){
            case 'A':
                dp[i + 1][0] += po(3, q);
                break;
            case 'B':
                dp[i + 1][1] += dp[i][0];
                break;
            case 'C':
                ans = (ans + dp[i][1]) % MOD;
                break;
            case '?':
                dp[i + 1][0] = dp[i][0] * 3 + po(3, q);
                dp[i + 1][1] = dp[i][1] * 3 + dp[i][0];
                ans = (3 * ans + dp[i][1]) % MOD;
                q++;
                break;
        }
        for(ll j = 0; j < 3; j++) dp[i + 1][j] %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2816
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var s = cin.Read;
            var cnt_1 = s.Count(x => x == '1');
            WriteLine(cnt_1);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 11348
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
    int k,min_;
    int sum=0, mul=1;
    cin >> k;
    for (int i=1; i<=k; i++){
        for (int j=1; j<=k; j++){
            for (int l=1; l<=k; l++){
                int i1 = i;
                int j1 = j;
                int l1 = l;
                mul = 1;
                
                for (int m=2; m<=k;){
                    if( i1 % m == 0 && j1 % m == 0 && l1 % m == 0 ){
                        mul = mul*m;
                        i1 = i1 / m;
                        j1 = j1 / m;
                        l1 = l1 / m;
                    }
                    else m++;
                    if( i1 < m || j1 < m || l1 < m ) break;
                }
                sum += mul;
                
            }
        }
    }
    
    cout << sum << endl;
    return 0;
}

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

using namespace std;

int main (void) {
    int N;
    cin >> N;
    vector<int> A(N);
    for ( int i = 0; i < N; i++ ) cin >> A.at(i);

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

    sort(A.begin(), A.end());

    int b = A.at(N/2);
    long long ans = 0;
    for ( int i = 0; i < N; i++ ) ans += abs(A.at(i) - b);

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


Measured memory_bytes: 4052
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX_V 300
#define INF 1e9
const double EPS = 1e-8;
typedef vector<double> vec;
typedef vector<vec> mat;
typedef pair<double,int> P;
 
struct edge{
    int to,cap,rev;
    double cost;
    edge(int to,int cap,int rev,double cost) :
	to(to),cap(cap),rev(rev),cost(cost) {}
};
 
int V;
vector<edge> G[MAX_V];
double dist[MAX_V],h[MAX_V];;
int prevv[MAX_V],preve[MAX_V];
 
void add_edge(int from,int to,int cap,double cost){
    G[from].push_back(edge(to,cap,G[to].size(),cost));
    G[to].push_back(edge(from,0,G[from].size()-1,-cost));
}
 
double min_cost_flow(int s,int t,int f){
    double res = 0;
    fill(h,h+V,0);
    while(f > 0){
	priority_queue<P,vector<P>,greater<P> > Q;
	fill(dist,dist+V,INF);
	dist[s] = 0;
	Q.push(P(0,s));
	while(!Q.empty()){
	    P p = Q.top(); Q.pop();
	    int v = p.second;
	    if(dist[v] < p.first) continue;
	    for(int i = 0 ; i < (int)G[v].size() ; i++){
		edge &e = G[v][i];
		if(e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to] + EPS){
		    dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
		    prevv[e.to] = v;
		    preve[e.to] = i;
		    Q.push(P(dist[e.to],e.to));
		}
	    }
	}
	if(dist[t] == INF){
	    return -1;
	}
	for(int v = 0 ; v < V ; v++){
	    h[v] += dist[v];
	}
	int d = f;
	for(int v = t ; v != s ; v = prevv[v]){
	    d = min(d,G[prevv[v]][preve[v]].cap);
	}
	f -= d;
	res += d*h[t];
	for(int v = t ; v != s ; v = prevv[v]){
	    edge &e = G[prevv[v]][preve[v]];
	    e.cap -= d;
	    G[v][e.rev].cap += d;
	}
    }
    return res;
}
 
vec gauss_jordan(const mat &A,const vec &b){
    int n = A.size();
    mat B(n,vec(n+1));
    for(int i = 0 ; i < n ; i++){
	for(int j = 0 ; j < n ; j++){
	    B[i][j] = A[i][j];
	}
    }
    for(int i = 0 ; i < n ; i++){
	B[i][n] = b[i];
    }
    for(int i = 0 ; i < n ; i++){
	int pivot = i;
	for(int j = i ; j < n ; j++){
	    if(abs(B[j][i]) > abs(B[pivot][i])){
		pivot = j;
	    }
	}
	swap(B[i],B[pivot]);
	if(abs(B[i][i]) < EPS) return vec();
	for(int j = i+1 ; j <= n ; j++){
	    B[i][j] /= B[i][i];
	}
	for(int j = 0 ; j < n ; j++){
	    if(i != j){
		for(int k = i+1 ; k <= n ; k++){
		    B[j][k] -= B[j][i]*B[i][k];
		}
	    }
	}
    }
    vec x(n);
    for(int i = 0 ; i < n ; i++){
	x[i] = B[i][n];
    }
    return x;
}
 
void init(){
    for(int i = 0 ; i < MAX_V ; i++){
	G[i].clear();
    }
}
 
int main(){
    int Tc;
    cin >> Tc;
    while(Tc--){
	int N,s,t,F;
	init();
	cin >> N >> s >> t >> F;
	mat a(N,vec(N)); vec c(N);
	for(int i = 0 ; i < N ; i++){
	    for(int j = 0 ; j < N ; j++){
		cin >> a[i][j];
	    }
	    cin >> c[i];
	}
	vec res = gauss_jordan(a,c);
	for(int i = 0 ; i < N ; i++){
	    int M,d[N],f;
	    cin >> M;
	    for(int j = 0 ; j < M ; j++){
		cin >> d[j];
	    }
	    for(int j = 0 ; j < M ; j++){
		cin >> f;
		add_edge(i,d[j],f,abs(res[i]-res[d[j]]));
	    }
	}
	V = N;
	double ans = min_cost_flow(s,t,F);
	if(ans == -1){
	    printf("impossible\n");
	}else{
	    printf("%.6f\n",ans);
	}
    }
    return 0;
}

Measured memory_bytes: 3828
#include<cstdio>
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if((a+b)%2==0){
		printf("%d\n",(a+b)/2);
	}else{
		printf("%d\n",(a+b+1)/2);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>

using namespace std;
int A[1000000+10], n;

int binarySearch(int k){
	int low = 0;
	int high = n;
	int mid;
	while( low < high){
		mid = (low + high)/2;
		if(A[mid] == k) return 1;
		else if(A[mid] > k) high = mid;
		else low = mid+1;
	}
	return 0;
}
int main(){
	int sum = 0;
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		scanf("%d", &A[i]);
	}
	int m, t;
	scanf("%d", &m);
	for(int i=0; i<m; i++){
		scanf("%d", &t);
		if( binarySearch(t) ) sum++;
	}
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 3512
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void print_YES_NO(bool answer){cout<<(answer?"YES":"NO")<<endl;}
void print_Yes_No(bool answer){cout<<(answer?"Yes":"No")<<endl;}
void print_POSSIBLE_IMPOSSIBLE(bool answer){cout<<(answer?"POSSIBLE":"IMPOSSIBLE")<<endl;}

priority_queue<P,vector<P>,greater<P> > q1;

int main(){
	int n;
	int a,b,c;
	int i,j,k;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a>>b;
		q1.push(make_pair(b,a));
	}
	c=0;
	for(i=0;i<n;i++){
		a=q1.top().first,b=q1.top().second,q1.pop();
		c+=b;
		if(a<c)break;
	}
	print_Yes_No(i==n);
}


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

#define     __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define dbg cout << "dbg\n"
#define nll cout << "\n"
#define ll long long
#define MAX 100002
#define log_size 18
#define MOD 1000000007
#define INF 10000000000
#define ii pair<ll,ll>
#define presion cout << fixed << setprecision(6)



int main(){
	string s;
	cin >> s;
	int ans = 1;
	if(s == "RRR"){
		ans = 3;
	}
	if(s == "RRS"){
		ans = 2;
	}
	if(s == "SRR"){
		ans = 2;
	}
	if(s == "SSS"){
		ans = 0;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3592
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1111111111;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int D, G;
	cin >> D >> G;

	vector<pair<int, int>> prob(D);
	for (int i = 0; i < D; i++) {
		cin >> prob[i].first >> prob[i].second;
		prob[i].second += (i + 1) * prob[i].first * 100;
	}

	int ans = INF;
	for (int bit = 0b0; bit < (1 << D); bit++) {

		int score = 0, num = 0;
		vector<int> memo;
		for (int i = 0; i < D; i++) {
			if (bit & (1 << i)) {
				num += prob[i].first;
				score += prob[i].second;
				memo.emplace_back(i);
			}
		}
		if (score < G) continue;

		ans = min(ans, num);
		for (int i = 0; i < (int)memo.size(); i++) {
			int tmp = (G - (score - prob[memo[i]].second) - 1) / (100 * (memo[i] + 1)) + 1;
			if (0 < tmp && tmp < prob[memo[i]].second) {
				ans = min(ans, num + tmp - prob[memo[i]].first);
			}
		}

	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();

            var startIndex = -1;
            var endIndex = -1;
            for (var i = 0; i < s.Length; i++)
            {
                if (startIndex == -1)
                {
                    if (s[i] == 'A')
                    {
                        startIndex = i;
                    }
                }
                else
                {
                    if (s[i] == 'Z')
                    {
                        endIndex = i;
                    }
                }
            }

            var output = endIndex - startIndex + 1;
            Console.WriteLine(output);
        }
    }
}


Measured memory_bytes: 11616
N=int(input())
P=list(map(int,input().split()))
ans = 0
for i in range(N):
    if i == 0:
        ans += 1
        mini = P[0]
    else:
        if mini >= P[i]:
            mini = P[i]
            ans += 1
        #print(P[0:i+1],P[i],min(P[0:i+1]),i)
        #if min(P[0:i+1]) == P[i]:
            #ans += 1
print(ans)


Measured memory_bytes: 99848
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

if a[-1] == 0:
    print(0)
    exit(0)

mul = 1
for e in a:
    mul *= e
    if mul > (10 ** 18):
        print(-1)
        exit(0)

print(mul)


Measured memory_bytes: 21716