akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiWayIf #-}

import Control.Applicative
import Control.Monad
import Control.Monad.Primitive
import Data.Array.IO
import Data.Array
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed.Mutable as V
import Data.Maybe

readIntBS = fst . fromJust . BS.readInt
modifyArray arr i f = readArray arr i >>= \x -> writeArray arr i (f x)

main = do
  [n,k] <- map read . words <$> getLine :: IO [Int]

  field <- V.replicate ((k+1)*(2*k+1)) 0 :: IO (V.MVector RealWorld Int)

  let
    readV field (x,y) = V.read field (x+y*(2*k+1))
    writeV field (x,y) a = V.write field (x+y*(2*k+1)) a
    modifyV field (x,y) f = readV field (x,y) >>= \a -> writeV field (x,y) (f a)
    func arr x0 y0 x1 y1 = do
      a <- readV arr (x1,y1)
      b <- readV arr (x1,y0-1)
      c <- readV arr (x0-1,y1)
      d <- readV arr (x0-1,y0-1)
      return $ a-b-c+d

  replicateM_ n $ do
    (x,y,c) <- (\[x,y,c] -> (readIntBS x, readIntBS y, BS.head c)) . BS.words <$> BS.getLine :: IO (Int,Int,Char)
    if
      | odd (y `div` k) -> modifyV field ((if c=='W' then x else x+k)`mod`(2*k)+1, y`mod`k+1) (+1)
      | otherwise -> modifyV field ((if c=='B' then x else x+k)`mod`(2*k)+1, y`mod`k+1) (+1)

  --forM_ [1..k] $ \j -> do
  --  print =<< unwords . map show <$> (forM [1..2*k] $ \i -> readV field (i,j))

  forM_ [1..k] $ \j -> do
    forM_ [2..2*k] $ \i -> do
      readV field (i-1,j) >>= \x -> modifyV field (i,j) (x+)

  forM_ [1..2*k] $ \i -> do
    forM_ [2..k] $ \j -> do
      readV field (i,j-1) >>= \x -> modifyV field (i,j) (x+)

  --forM_ [0..k] $ \j -> do
  --  print =<< unwords . map show <$> (forM [0..2*k] $ \i -> readV field (i,j))

  print =<< maximum . map (\x -> max x (n-x)) <$>
    (forM [(x,y) | x<-[1..k], y<-[1..k]] $ \(x,y) -> do
        sum <$> sequence
          [func field 1 1 (x-1) (y-1),
           func field x y (x+k-1) k,
           func field (x+k) 1 (2*k) (y-1)]
    )


Measured memory_bytes: 242300
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

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

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

int main() {
    int sum = 0;
    for (int i = 0; i < 4; i++) {
        int t; cin >> t;
        sum += t;
    }

    cout << sum / 60 << endl;
    cout << sum % 60 << endl;

    return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int R;

int main(void){
    
    scanf("%d", &R);
    if(R < 1200) printf("ABC\n");
    else if(R < 2800) printf("ARC\n");
    else printf("AGC\n");
    
    return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

string a, b;
const ll N = 3010;
ll dp[N][N];

ll rec(ll i, ll j) {
	if (i == sz(a) || j == sz(b)) return 0;
	if (dp[i][j] != -1) return dp[i][j];

	if (a[i] == b[j]) return dp[i][j] = 1 + rec(i+1,j+1);
	return dp[i][j] = max(rec(i+1,j), rec(i,j+1));
}


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> a >> b;
	memset(dp,-1,sizeof dp);
	
	ll i = 0, j = 0;
	while (i < sz(a) && j < sz(b)) {
		if (a[i] == b[j]) {
			cout << a[i];
			i++, j++;
		} else {
			if (rec(i,j) == rec(i+1,j)) i++; else j++;
		}
	}
	cout << endl;
}



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

const long long INF = 1e18;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  int si, sj, ti, tj;
  cin >> si >> sj >> ti >> tj;
  --si; --sj; --ti; --tj;
  vector<string> g(h);
  for (int i = 0; i < h; ++i) cin >> g[i];

  auto toId = [&](int i, int j, int v) {
    return (i*w+j)*4 + v;
  };
  auto modCeilK = [&](long long x) {
    return (x + k - 1) / k * k;
  };

  vector<long long> dist(h*w*4, INF);
  priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> q;
  auto push = [&](int i, int j, int v, long long x) {
    int id = toId(i, j, v);
    if (dist[id] <= x) return;
    dist[id] = x;
    q.emplace(x,id);
  };
  for (int v = 0; v < 4; ++v) push(si, sj, v, 0);
  while (!q.empty()) {
    long long d = q.top().first;
    int id = q.top().second;
    q.pop();
    if (dist[id] != d) continue;
    int i = id / w / 4;
    int j = id /4 % w;
    int v = id % 4;
    for (int nv = 0; nv < 4; ++nv) {
      push(i, j, nv, modCeilK(d));
      int ni = i+di[v], nj = j+dj[v];
      if (0 <= ni && ni < h && 0 <= nj && nj < w) {
        if (g[ni][nj] == '.') {
          push(ni, nj, v, d+1);
        }
      } 
    }
  }

  long long ans = INF;
  for (int v = 0; v < 4; ++v) ans = min(ans, dist[toId(ti, tj, v)]);
  if (ans == INF) cout << -1 << endl;
  else {
    ans = modCeilK(ans)/k;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 43576
#include<bits/stdc++.h>
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long int

using namespace std;

void solve()
{
	int d,t,s;
	cin>>d>>t>>s;

	if(t*s>=d)
		cout<<"Yes";
	else
		cout<<"No";





}
signed main()

{
	FAST_IO;
	int t = 1;

	// cin>>t;

	while(t--)
	{
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 3648
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

from collections import defaultdict

n,m=map(int,input().split())
visited=[0]*n
d=defaultdict(list)
def dfs(n):
    visited[n]=1
    #print(visited)
    for i in d[n]:
        if visited[i]==0:
            dfs(i)

for i in range(m):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    d[a].append(b)
    d[b].append(a)

r=-1
for i in range (n):
    if visited[i]==0:
        dfs(i)
        r+=1
print(r)

Measured memory_bytes: 49408
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<unordered_set>
int c[10000];
typedef std::vector<std::vector<int>> graph;
int farthest(graph &g,int e){
    std::queue<int> q;
    std::unordered_set<int> s;
    q.push(e);
    s.emplace(e);
    int last;
    while(!q.empty()){
        last=q.front();
        q.pop();
        for(auto itr=g[last].begin();itr!=g[last].end();itr++){
            if(s.find(*itr)==s.end()){
                s.emplace(*itr);
                q.push(*itr);
            }
        }
    }
    return last;
}
int d[10000];
int score(graph &g){
    int f=farthest(g,0);
    std::stack<int> st;
    for(int i=0;i<(int)g.size();i++){
        d[i]=-1;
    }
    st.push(f);
    d[f]=c[0];
    int cnt=1,sum=0;
    while(!st.empty()){
        int i=st.top();
        st.pop();
        for(auto itr=g[i].begin();itr!=g[i].end();itr++){
            if(d[*itr]==-1){
                d[*itr]=c[cnt];
                cnt++;
                sum+=std::min(d[i],d[*itr]);
                st.push(*itr);
            }
        }
    }
    return sum;
}
int main(){
    int n;
    scanf("%d",&n);
    graph g(n);
    for(int i=1;i<n;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        g[a-1].push_back(b-1);
        g[b-1].push_back(a-1);
    }
    for(int i=0;i<n;i++)scanf("%d",&c[i]);
    std::sort(c,c+n,[](int a,int b){return a>b;});
    int m=score(g);
    printf("%d\n",m);
    for(int i=0;i<n-1;i++){
        printf("%d ",d[i]);
    }
    printf("%d\n",d[n-1]);
    return 0;
}

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();
		int X = A + B;

		if (X % 2 == 0) {

			System.out.println(X / 2);

		} else {

			System.out.println(X / 2 + 1);

		}
	}
}


Measured memory_bytes: 23764
import sys
from itertools import combinations
import math


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


N = I()
A = LI()

A.sort()
A = A[::-1]
alice = 0
bob = 0
flag = 0
for i in A:

    if flag % 2 == 0:
        alice += i
    else:
        bob += i
    flag += 1
print(alice-bob)


Measured memory_bytes: 38360
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#define ll long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,0,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int main(){
  int A;
  string S;
  cin>>A>>S;
  if(A>=3200) cout<<S<<endl;
  else cout<<"red"<<endl;
}

Measured memory_bytes: 256
N, K = list(map(int, input().split()))
M = abs(N - K)
mini = M + 1

if (not N < K):
    if (N%K == 0):
        print(0)
    else:
        M = (N % K)
        while (M < mini):
            mini = min(mini, M)
            M = abs(M - K)
        print(mini)

else:
    while (M < mini):
        mini = min(mini, M)
        M = abs(M - K)
    print(mini)


Measured memory_bytes: 3060
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    //    ifstream in("input.txt");
    //    cin.rdbuf(in.rdbuf());
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, i;
    cin >> n >> i;
    
    cout << n - i + 1 << endl;
    
    return 0;
}

Measured memory_bytes: 256
/*
"Won't stop untill I'm Phenomenal"
- Phenomenal, EMINEM
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define ff first
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define ss second
#define all(c) c.begin(),c.end()
#define endl "\n"
#define test() int t; cin>>t; while(t--)
#define fl(i,a,b) for(int i = a ; i <b ;i++)
#define get(a) fl(i,0,a.size())  cin>>a[i];
#define pra(a) fl(i,0,a.size()) cout<<a[i]<<" ";	cout<<endl;
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
const ll INF = 2e18;
const int inf = 2e9;
const int mod1 = 1e9 + 7;

vector<ll> fac,ifac;
//ll binexpomodulo(ll x, ll y){ll res =1;x%=mod;if(!x)return 0;while(y){if(y&1){mul(res, x);}mul(x,x);y>>=1;}return res;}
ll binmodulo(ll x, ll y){
    x%=mod1;
    if(x==0){
        return 0;
    }
    
    ll res = 1;
    while(y){
        if(y&1){
            res = res*x%mod1;
        }
        y/=2;
        x = x*x%mod1;
    }
    return res;
}
void precompute(ll n){
    fac.resize(n+1,1);
    ifac.resize(n+1);
    for(int i =1; i < n+1; i++){
        fac[i] = i*fac[i-1]%mod1;
    }
    ifac[n] = binmodulo(fac[n], mod1-2);
    for(int i = n-1; i >=0; i--){
        ifac[i] = (i+1)*ifac[i+1]%mod1;
    }
}
ll ncr(ll n, ll r){
    return fac[n]*ifac[n-r]%mod1*ifac[r]%mod1;
}
//vector<ll> fac, ifac; void precompute(ll n){fac.resize(n+1,1);ifac.resize(n+1);for(ll i = 2; i<=n;i++){	fac[i] = (fac[i-1]*i)%mod;}ifac[n] = binexpomodulo(fac[n],mod-2);for(ll i = n-1; i>=0; i--)ifac[i] = (ifac[i+1]*(i+1))%mod;}ll nCr(ll n, ll r){return fac[n]*(ifac[n-r])%mod * (ifac[r])%mod;}
int main(){
    Shazam;
    ll s; cin>>s;
    precompute(5*s+100);
    if(s < 3){
        cout<<0<<endl;
        return 0;
    }
    ll ans = 0;
    auto add = [&](ll &a, ll b){
        a+=b;
        while(a>=mod1){
            a-=mod1;
        }
    };
    for(ll tot = 1; tot <= s/3; tot++ ){
        add(ans, ncr(s-3*tot + tot - 1, tot-1));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3780
/*
* @author:  codancer
* @createTime:  2020-02-09, 20:01:05
*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define pb push_back
#define SZ(x) ((int)(x).size())
#define fi first
#define se second
typedef vector<int> VI;
typedef pair<int,int> pii;
int main(){
	string S,T;
	int a,b;
	string U;
	cin>>S>>T>>a>>b>>U;
	if(S==U) a--;
	else b--;
	cout<<a<<' '<<b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
//int MAX;
//int ANS;
//void bfs (int a,int b,int c,int ans)
//{
//        if(a==b&&a==c)
//        {
//                ANS=min(ANS,ans);
//                return;
//        }
//        if(a>MAX||b>MAX||c>MAX)
//        {
//                return;
//        }
//        else
//        {
//                bfs(a+2,b,c,ans+1);
//                bfs(a,b+2,c,ans+1);
//                bfs(a,b,c+2,ans+1);
//                bfs(a+1,b+1,c,ans+1);
//                bfs(a+1,b,c+1,ans+1);
//                bfs(a,b+1,c+1,ans+1);
//        }
//}
//int main ()
//{
//       int a,b,c,ans;
//       while(cin>>a>>b>>c)
//       {
//               ANS=999999;
//               MAX=max(a,b);
//               MAX=max(MAX,c);
//               MAX++;
//               bfs(a,b,c,0);
//               cout<<ANS<<endl;
//       }
//}



int main ()
{
        int a[5],ans;
        while(cin>>a[0]>>a[1]>>a[2])
        {
                ans=0;
                sort(a,a+3);
                while(!(a[0]==a[1]&&a[0]==a[2]))
                {
                        while(a[0]+2 <= a[2] )
                        {
                                if(a[0]==a[1]&&a[0]==a[2])
                                {
                                        break;
                                }
                                a[0]+=2;
                                ans++;
                        }
                        while(a[1]+2 <= a[2] )
                        {
                                if(a[0]==a[1]&&a[0]==a[2])
                                {
                                        break;
                                }
                                a[1]+=2;
                                ans++;
                        }
                        if(a[0]==a[1]&&a[0]==a[2])
                        {
                                break;
                        }
                        if(a[0]==a[1])
                        {
                                ans++;
                                break;
                        }
                        else
                        {
                                ans+=2;
                                break;
                        }
                }
                cout<<ans<<endl;
        }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
static const ll maxLL = (ll)1 << 62;
 
int main() {
   int n;
   cin>>n;
  
  long long L[88];
  L[0]=2;
  L[1]=1;
  
  for(int i=2;i<=n;i++){
      L[i]=L[i-2]+L[i-1];
  }
  if(n==0) cout<<'2'<<endl;
  else if(n==1) cout<<'1'<<endl;
  else cout<<L[n]<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define CEVCOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void){


    int N, K; cin >> N >> K;
    V h(N); VECCIN(h);
    int ans = 0;
    for(int i = 0 ; i < N ; i++)
      if(h[i] >= K) ans += 1;

    SCOUT(ans) << endl;

    return 0;
}


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

using lint = long long;
const lint MOD = 1e9 + 7;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<lint> num(26);
    for (int i = 0; i < n; i++) {
        int c = s[i] - 'a';
        num[c]++;
    }
    lint ans = 1;
    for (int i = 0; i < 26; i++) {
        ans = ans * (num[i] + 1) % MOD;
    }
    ans -= 1;
    if (ans < 0) {
        ans += MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
#define f first
#define s second
#define pb push_back

int n;
string res, ans;
char st;
vector<int> v;

char query(vector<int> &v) {
	string ret;
	cout << "? ";
	cout.flush();
	for (auto it:v) cout << it << " ";
	cout << "\n";
	cout.flush();
	v.clear();
	cin >> res;
	if (res == "-1") exit(0);
	return res[0];
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	FOR(i, 1, 2*n) ans += " ";
	FOR(i, 1, n) v.pb(i);
	st = query(v);
	int upper = n+1, lower = 1;
	while (upper - lower > 1) {
		int mid = (upper + lower)/2;
		FOR(i, mid, mid+n-1) v.pb(i);
		if (query(v) != st) upper = mid;
		else lower = mid;
	}
	ans[upper + n - 1 - 1] = (st == 'R' ? 'B' : 'R');
	ans[upper - 1 - 1] = st;
	FOR(i, 1, 2*n) {
		if (ans[i-1] != ' ' or (i >= upper and i < upper + n - 1)) continue;
		if (i < upper - 1) {
			v.pb(i);
			FOR(j, upper, upper + n - 2) v.pb(j);
		} else {
			FOR(j, upper, upper + n - 2) v.pb(j);
			v.pb(i);
		}
		ans[i-1] = query(v);
	}
	vector<int> vv; vv.clear();
	int nr = 0, nb = 0;
	FOR(i, 0, 2*n-1) {
		if (ans[i] == ' ' or vv.size() == n-1) continue;
		if (ans[i] == 'B' and nb < (n-1)/2) {vv.pb(i+1); nb++;}
		else if (ans[i] == 'R' and nr < (n-1)/2) {vv.pb(i+1); nr++;}
	}
	FOR(i, upper, upper + n - 2) {
		v = vv; v.pb(i);
		ans[i-1] = query(v);
	}
	cout << "! " + ans << "\n";
	cout.flush();
	exit(0);
}


Measured memory_bytes: 724
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  string s;std::cin >> s;
  std::cout << (s=="ABC"?"ARC":"ABC") << '\n';
  return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
using namespace std;
typedef long long ll;
typedef vector<int>VI;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define reprev(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define fi first
#define se second
#define MAX 100100//5
#define MAX_N 200100
#define MAX_B 1001001//6
#define MAX_S 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MOD 1000000007
#define INF 1 << 29
#define INFTY 1000000000000000000LL
#define MAX_INT INT_MAX
#define MAX_LL 
int n,m;
int k[11];
int s[11][11];
int p[11];
int main(){
    cin>>n>>m;
    rep(i,m){
        cin>>k[i];
        rep(j,k[i])cin>>s[i][j];
    }
    rep(i,m)cin>>p[i];
    int ans=0;
    for(int bit=0;bit<(1<<n);bit++){
        bool can=true;
        vector<int>v;
        rep(i,n)if(bit&(1<<i))v.push_back(i+1);
        sort(ALL(v));
        rep(i,m){
        int count=0;
        rep(j,k[i]){
            if(binary_search(ALL(v),s[i][j]))count++;
        }
        if(count%2==p[i])continue;
        else {can=false;break;}
        }
        if(can){ans++;}
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.nio.Buffer;
import java.util.*;
import java.io.*;

public class Main {
    static int [][]map=new int[100001][3];
    static int [][]ans=new int[100001][3];
    static int dp(int N,int position){
        if(N<=0||position<0) return 0;
        if(ans[N][position]!=0) return ans[N][position];
        ans[N][position]=Math.max(ans[N][position],map[N][position]+dp(N-1,((position+1)%3)));
        ans[N][position]=Math.max(ans[N][position],map[N][position]+dp(N-1,((position+2)%3)));

        return ans[N][position];
    }
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        for(int i=1;i<=N;i++){
            for(int j=0;j<3;j++){
                map[i][j]=sc.nextInt();
            }
        }
        int k=0;
        for(int i=0;i<3;i++){
            k=Math.max(k,dp(N,i));
        }
        System.out.println(k);

    }
}

Measured memory_bytes: 115560
def abc133_c():
    L, R = map(int, input().split())
    # 区間の幅が673あれば、673の倍数と3の倍数が含まれて、2019の倍数が作れる
    if R - L > 673: return 0
    # それ以外は試す
    ans = 2019
    for i in range(L, R+1):
        for j in range(L, i):
            m = i * j % 2019
            ans = min(m, ans)
    return ans

print(abc133_c())

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    try {
      int childrenNum = stdIn.nextInt();
      if (childrenNum < 1 || childrenNum > 100) return;
      int[][] childrenSnack = new int[childrenNum + 1][2];
      int snackNum = stdIn.nextInt();
      if (snackNum < 1 || snackNum > 100) return;
      for (int snackCnt = 0; snackCnt < snackNum; snackCnt++) {
        int havingSnackNum = stdIn.nextInt();
        if (havingSnackNum < 1 || havingSnackNum > childrenNum) return;
        for (int cnt = 0; cnt < havingSnackNum; cnt++) {
          int temphavingChild = stdIn.nextInt();
          childrenSnack[temphavingChild][0] = childrenSnack[temphavingChild][0] + 1;
        }
      }
      int notHavingNum = 0;
      for (int searchCnt = 1; searchCnt <= childrenNum; searchCnt++) {
        if (childrenSnack[searchCnt][0] == 0) notHavingNum++;
      }
      System.out.println(notHavingNum);
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      stdIn.close();
    }
  }
}

Measured memory_bytes: 46148
#include <bits/stdc++.h>
using namespace std;
int main(){
	char a,b;
	cin>>a>>b;
	if(a=='H'&&b=='H')cout<<"H"<<endl;
	if(a=='H'&&b=='D')cout<<"D"<<endl;
	if(a=='D'&&b=='H')cout<<"D"<<endl;
	if(a=='D'&&b=='D')cout<<'H'<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
int a[N],vis[N];
int main()
{
    int n,m;scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)a[i]=1;
    vis[1]=1;
    while(m--)
    {
        int x,y;scanf("%d%d",&x,&y);a[y]++;
        if(a[x]==1)
        {
            if(vis[x])vis[y]=1,vis[x]=a[x]=0;
            else vis[x]=a[x]=0;
        }
        else
        {
            if(vis[x])vis[y]=1,a[x]--;
            else a[x]--;
        }
    }
    int ans=0;for(int i=1;i<=n;i++)ans+=vis[i];
    cout<<ans<<endl;
}


Measured memory_bytes: 4736
n, k = map(int, input().split())
ab_lst = []

for i in range(n):
    ab_lst.append(tuple((map(int, input().split()))))

ab_lst.sort(key=lambda tup: tup[0])

for i in range(len(ab_lst)):
    k -= ab_lst[i][1]
    if k <= 0:
        print(ab_lst[i][0])
        break


Measured memory_bytes: 18192
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N = int(input())
MOD = 10**9+7
AB = []
x = 0
y = 0
d = defaultdict(int)
ch = defaultdict(int)
flag = 0
for _ in range(N):
    a,b = map(int,input().split())
    if a == 0 and b == 0:
        flag += 1
    elif a == 0:
        d[(0,1)] += 1
        AB.append([0,1])
    elif b == 0:
        d[(1,0)] += 1
        AB.append([1,0])
    else:
        dd = math.gcd(abs(a),abs(b))
        a //= dd
        b //= dd
        if a < 0:
            a *= -1
            b *= -1
        d[(a,b)] += 1
        AB.append([a,b])
n = len(AB)
ans = 1
if n > 0:
  for i in range(n):
      a,b = AB[i]
      if ch[(a,b)] == 1:
          continue
      m = d[(a,b)]
      if b > 0:
          l = d[(b,(-1)*a)]
          ch[(a,b)] = 1
          ch[(b,(-1)*a)] = 1
      elif a == 0 or b == 0:
          l = d[(b,a)]
          ch[(a,b)] = 1
          ch[(b,a)] = 1
      else:
          l = d[((-1)*b,a)]
          ch[(a,b)] = 1
          ch[((-1)*b,a)] = 1
      ans *= (pow(2,m,MOD)+pow(2,l,MOD)-1)
      ans = ans % MOD
ans = ans % MOD
ans = ans -1 + flag
ans = ans % MOD
print(ans)


Measured memory_bytes: 184604
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,long long> pint;
typedef long long ll;
const ll mod= 1e9+7;
const ll  longinf = 1LL<<60;
const int inf=1e9+7;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};


int main(){
  string s;
  cin>>s;
  int n=s.size();
  cout<<s[0]<<n-2<<s[n-1]<<endl;

  return 0;
  }

Measured memory_bytes: 256
inf=10**17

def tp(a,b):
    return min(a,b,inf)
def tt(a,b):
    return min(a+b,inf)
def tpdot(A,B):#N正方行列のみにかけ算を許す
    N=len(A)
    C=[[inf]*N for i in range(N)]
    for i in range(N):
        for j in range(N):
            num=inf
            for k in range(N):
                t=tt(A[i][k],B[k][j])
                num=tp(num,t)
            C[i][j]=num
    return C
def tpeye(N):
    C=[[inf]*N for i in range(N)]
    for i in range(N):
        C[i][i]=0
    return C
def tppower(A,k):
    N=len(A)
    S,T=tpeye(N),A
    x=k
    while x>0:
        if x%2==1:
            S=tpdot(S,T)
        x=x//2
        T=tpdot(T,T)
    return S

H,W=map(int,input().split())
A=[[0]*10 for i in range(10)]
for j in range(10):
    C=[int(i) for i in input().split()]
    for k in range(10):
        A[j][k]=C[k]
#print(A)
A=tppower(A,10)
ans=0
for j in range(H):
    C=[int(i) for i in input().split()]
    for k in range(W):
        if C[k]!=-1:
            ans+=A[C[k]][1]
#print(A)
print(ans)

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


int main() {

    string s;
    cin >> s;
    if (s[0] != s[1] && s[1] != s[2] && s[0] != s[2]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n;
	int i;
	int cnt;
	
	while (1){
		scanf("%d", &n);
		if (n == 0){
			break;
		}
	
		cnt = 0;
		while (n != 1){
			if (n % 2 == 0){
				n /= 2;
			}	
			else {
				n = n * 3 + 1;
			}
			cnt++;
		}
		printf("%d\n", cnt);
	}
	
	
	return (0);
}

Measured memory_bytes: 600
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<map>
#include<utility>
#include<stdlib.h>
#include<ctime>
using namespace std;



int main()
{
	long long int a, v, b, w, t;
	cin >> a >> v >> b >> w >> t;
	if (b > a)
	{

		a = a + v * t;
		b = b + w * t;
		if (a >= b)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	else
	{
		a = a - v * t;
		b = b - w * t;
		if (a <= b)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 3632
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
   int n; cin >> n;
   map<string, int> mp;
   rep(i, n){
       string s; cin >> s;
       mp[s]++;
   }
   cout << "AC x " << mp["AC"] << ln;
   cout << "WA x " << mp["WA"] << ln;
   cout << "TLE x " << mp["TLE"] << ln;
   cout << "RE x " << mp["RE"] << ln; 
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
/*bool is(long long a){
    if(a==2) return true;
    if(a<=1||a%2==0) return false;
    for(int i=3;i*i<=a;i+=2){
        if(a%i==0) return false;
    }
    return true;
}*/
queue<pair<int,int>> q;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    //cout.setf(ios_base::fixed,ios_base::floatfield);
    int n,m;
    cin>>n>>m;
    int t[n+1]={};
    for(int i=1;i<=n;i++){
        cin>>t[i];
    }
    int a,b;
    int l[n+1]={};
    
    for(int i=0;i<m;i++){
        cin>>a>>b;
        if(t[a]>t[b]){
            l[b]+=1;
        }else if(t[a]<t[b]){
            l[a]+=1;
        }else{
            l[a]+=1;
            l[b]+=1;
        }
    }
    int z=0;
    for(int i=1;i<=n;i++){
        if(l[i]==0) z++;
    }
    cout<<z<<'\n';
    return 0;
}

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

const int INF = 1<<28;
const int MAXN = 1000001;
const int di[] = {0,1,0,-1};
const int dj[] = {1,0,-1,0};
bool isPrime[MAXN];
int I[MAXN], J[MAXN];

const int OFFSET = 500;
const int H = 1111;
const int W = 1111;
int G[H][W];
int m, n;
pair<int, int> dp[H][W];

int main() {
  fill(isPrime, isPrime+MAXN, true);
  isPrime[0] = isPrime[1] = false;
  for(int i = 2; i < MAXN; ++i) {
    if(!isPrime[i]) continue;
    for(int j = i*2; j < MAXN; j += i) {
      isPrime[j] = false;
    }
  }

  {
    map<int, map<int, int> > G;
    G[0][0] = 1;
    I[1] = 0, J[1] = 0;
    int pi = 0, pj = 0, d = 2;
    for(int num = 2; num < MAXN; ++num) {
      for(int k = 0; k < 4; ++k) {
        int nd = (d + k + 2) % 4;
        int ni = pi + di[nd];
        int nj = pj + dj[nd];
        if(G[ni][nj]) continue;
        G[ni][nj] = num;
        pi = ni, pj = nj, d = nd;
        I[num] = pi, J[num] = pj;
        break;
      }
    }
  }

  fill(G[0], G[H], INF);
  for(int i = 1; i < MAXN; ++i) {
    I[i] += OFFSET;
    J[i] += OFFSET;
    G[I[i]][J[i]] = i;
  }

  while(cin >> m >> n && (m|n)) {
    int si = I[n], sj= J[n];
    fill(dp[0], dp[H], make_pair(-1, -1));
    dp[si][sj] = make_pair(isPrime[G[si][sj]], 
                           isPrime[G[si][sj]] * G[si][sj]);
    pair<int, int> res = dp[si][sj];
    for(int i = si; i+1 < H; ++i) {
      for(int j = 0; j < W; ++j) {
        if(dp[i][j].first == -1) continue;
        for(int d = -1; d <= 1; ++d) {
          int ni = i + 1;
          int nj = j + d;
          if(nj < 0 || nj >= W) continue;
          if(G[ni][nj] > m) continue;
          dp[ni][nj]
            = max(dp[ni][nj],
                  make_pair(dp[i][j].first + isPrime[G[ni][nj]],
                            max(dp[i][j].first, isPrime[G[ni][nj]]*G[ni][nj])));
          res = max(res, dp[ni][nj]);
        }
      }
    }
    cout << res.first << " " << res.second << endl;
  }
  return 0;
}

Measured memory_bytes: 71420
S = input()
So = [S[i] for i in range(0, len(S), 2)]
Se = [S[i] for i in range(1, len(S), 2)]
anso = True
anse = True
for s in So:
    if s=="R" or s=="U" or s=="D":
        anso = True
    else:
        anso = False
        break
for s in Se:
    if s=="L" or s=="U" or s=="D":
        anse = True
    else:
        anse = False
        break
if anso and anse:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
import java.util.Scanner;
import java.util.ArrayList;
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
    Scanner input=new Scanner(System.in);
    ArrayList<String> list=new ArrayList<String>();
    int cases=input.nextInt();
    if(cases>=1 && cases<=1000)
    {
    for(int i=0;i<cases;i++)
    {
      int a=input.nextInt();
      int b=input.nextInt();
      int c=input.nextInt();
      if(a>=1 && b>=1 && c>=1 && a<=1000 && b<=1000 && c<=1000)
      {
         ArrayList<Integer> list1=new ArrayList<Integer>();
         list1.add(a);
         list1.add(b);
         list1.add(c);
         Collections.sort(list1);
         Double d=Math.pow(list1.get(0),2);
         Double e=Math.pow(list1.get(1),2);
         Double f=Math.pow(list1.get(2),2);
         if(d+e==f)
         {
         list.add("YES");
         }else
        list.add("NO");
      }
    }
    for(int i=0;i<list.size();i++)
    {
    System.out.println(list.get(i));
    }
    }
  }
}

     

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

tmp , near = map(int, input().split())

height = [int(x) for x in input().split()]

num = 0

box=[]

for x in height:
    av =tmp - x*0.006
    result = abs(av-near)
    box.append(result)
    
    
    
print(box.index(min(box))+1)
    


Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll MOD = 1000000007;  // 1e9 + 7

// Digit DP.

// In each digit, x and y is in one of the three.
// - x=0, y=0
// - x=0, y=1 (In this case, most significant bit must appear in the left bits)
// - x=1, y=1

// (digit)
// (L <= x is already satisfied by the left bits)
// (y <= R is already satisfied by the left bits)
// (most significant bit already appeared)
ll dp[61][2][2][2];

int main(int argc, char** argv) {
  ll L, R;
  cin >> L >> R;

  dp[60][0][0][0] = 1;
  for (ll i = 59; i >= 0; --i) {
    ll lb = (L >> i) & 1;
    ll rb = (R >> i) & 1;
    rep(j, 2) rep(k, 2) rep(s, 2) { // previous state
      ll pre = dp[i+1][j][k][s];
      rep(x, 2) rep(y, 2) {
        if (x && !y) { continue; } // x 1, y 0

        int nj = j, nk = k, ns = s; // next state.

        // Calculate the next state.
        if (!s && x != y) { continue; }
        if (x && y) { ns = 1; } // x = 1, y = 1, bit appeared
        // j: L <= x
        if (!j && !x && lb) { continue; } // x = 0, lb = 1, invalid
        if (x && !lb) { nj = 1; } // x = 1, lb = 0, L <= x is satisfied
        // k: y <= R
        if (!k && y && !rb) { continue; } // y = 1, rb = 0, invalid
        if (!y && rb) { nk = 1; } // y = 0, rb = 1, y <= R is satisfied
        dp[i][nj][nk][ns] += pre;
        dp[i][nj][nk][ns] %= MOD;
      }
    }
  }
  ll ans = 0;
  rep(j, 2) rep(k, 2) rep(s, 2) {
    ans += dp[0][j][k][s];
    ans %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct UnionFind{
    vector<int> data;
    UnionFind(int size) : data(size, -1) {}
    bool unionSet(int x,int y){
        x=root(x);y=root(y);
        if(x==y)return 0;
        if(data[y]<data[x])swap(x,y);
        data[x]+=data[y],data[y]=x;
        return 1;
    }
    bool findSet(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0 ? x : data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};
int main(){
	int n,m;
	while(cin>>n>>m,n){
		vp ti(n+1,{1,-1});
		vvi cost(n,vi(n,inf));
		rep(i,n){
			int a;cin>>a;
			ti[i]={a*-1,i};
		}
		sort(all(ti));
		int t=0;
		UnionFind uf(n);
		vi used(n);
		vvi G(m,vi(3));
		rep(i,m){
			int a,b,c;
			cin>>a>>b>>c;
			a--;b--;
			G[i]={a,b,c};
			cost[a][b]=cost[b][a]=c;
		}
		int T=-1;
		while(t!=n){
			used[ti[t].second]=true;
			while(ti[t].second==ti[t+1].second){
				t++;
				used[ti[t].second]=true;
			}
			rep(i,m)if(used[G[i][0]]&&used[G[i][1]])uf.unionSet(G[i][0],G[i][1]);
			t++;
			if(uf.size(ti[0].second)!=t)T=t;
		}
		if(uf.size(0)!=n){
			cout<<0<<endl;
			continue;
		}
		used=vi(n);
		int sum=0;
		vi d(n,inf);
		d[ti[0].second]=0;
		rep(j,n){
			int v=-1;
			if(T==-1||ti[T].first<ti[j].first){
				rep(i,n)if(used[ti[i].second]==0&&ti[i].first==ti[j].first&&(v==-1||d[v]>d[ti[i].second]))v=ti[i].second;
			}else
				rep(i,n)if(used[ti[i].second]==0&&ti[i].first<=ti[T].first&&(v==-1||d[v]>d[ti[i].second]))v=ti[i].second;
			used[v]=true;
			sum+=d[v];
			rep(i,n)d[i]=min(d[i],cost[v][i]);
		}
		cout<<sum<<endl;
	}
}






Measured memory_bytes: 4132
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    
    int G = A[0];
    REP(i, N) G = GCD(G, A[i]);
    int M = 0;
    rep(i, N) M = max(M, A[i]);
    cout << (K % G || M < K ? "IMPOSSIBLE\n" : "POSSIBLE\n");
    return 0;
}


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

int main()
{
    int n = 0, a[105];

    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];

     int st = 0;
    for (int i = 0; i < n-1; i++)
    {
        int minj = i;
        for (int j = i; j < n; j++)
        {
            if (a[j] < a[minj])
            {
                minj = j;
            }
        }
        int temp = a[i];
        a[i] = a[minj];
        a[minj] = temp;

        if (i != minj) st++;
    }

    for (int i = 0; i < n; i++)
    {
        if (i)
            cout << " ";
        cout << a[i];
    }
    cout<<endl;

    cout<<st<<endl;
    return 0;
}


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

#define ii pair<int, int>
#define LL long long int 
#define x first
#define y second
#define vi vector<int>
#define mp make_pair
#define pb push_back
#define INF int(1e9)

using namespace std;

int main () {
    ios_base::sync_with_stdio(false);
    int n, x;
    cin >> n >> x;
    if(n*500 >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
 
int main(void){
    double x1,x2,y1,y2,x,y;
     
    scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
    x = x2 - x1;
    y = y2 - y1;
     
    printf("%lf\n" , sqrt(x*x+y*y));
     
    return 0;
}


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

#define mod 1000000007
#define INF 1000000000

#define mp make_pair
#define pb push_back
#define mt make_tuple
#define eb emplace_back
#define all(x) begin(x), end(x)
#define len(x) ((int)(x).size())
#define contains(a, x) (a.find(x) != end(a))
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define F(i,a,b) for(int i = (int)(a); i < (int)(b); ++i)
#define RF(i,a,b)for(int i = (int)(a); i >= (int)(b); --i)

using dbl = double;
using ll = long long;
using ull = unsigned ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pi = pair<int,int>;

#define log(x) cout << x << endl;
#define fast() {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

int main() {

	ll n, k, a, b;
	cin >> n >> k;

	map<int, ll> cnt;
	set<int> seen;

	vi ar;
	rep (i, n) {
		cin >> a >> b;
		if (!contains(seen, a)) {
			ar.eb(a);
			seen.emplace(a);
		}
		cnt[a] += b;
	}
	sort(all(ar));

	ll l = 0;
	rep (i, n) {
		l += cnt[ar[i]];
		if (l >= k) {
			log(ar[i]);
			break;
		}
	}

	return 0;
}



Measured memory_bytes: 7420
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>

#define pb push_back
#define mp make_pair

using namespace std;

template<typename T>inline void upmin(T &x,T y) { y<x?x=y:0; }
template<typename T>inline void upmax(T &x,T y) { x<y?x=y:0; }

typedef unsigned int u32;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod pi=acos(-1);
const int oo=1<<30;
const LL OO=1e18;

const int N=2e5+100;

int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}

char s[N];
int v[N],siz[N],lc[N],rc[N],key[N],sum[N];
int cnt[N];
inline void update(int k) {
	siz[k]=siz[lc[k]]+1+siz[rc[k]];
	sum[k]=sum[lc[k]]|sum[rc[k]]|1<<v[k];
}
inline int merge(int x,int y) {
	if (!x||!y) return x|y;
	if (key[x]>key[y]) {
		rc[x]=merge(rc[x],y);
		update(x);
		return x;
	} else {
		lc[y]=merge(x,lc[y]);
		update(y);
		return y;
	}
}
inline PR split(int k,int s) {
	if (!k) return mp(0,0);
	PR p;
	if (s<=siz[lc[k]]) {
		p=split(lc[k],s);
		lc[k]=p.second,p.second=k;
	} else {
		p=split(rc[k],s-siz[lc[k]]-1);
		rc[k]=p.first,p.first=k;
	}
	update(k);
	return p;
}
int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1),i,k,c,rk,T,rt=0;PR pr;LL ans=0;
	for (i=1;i<=n;i++) siz[i]=1,key[i]=rand(),++cnt[v[i]=s[i]-'a'],sum[i]=1<<v[i],rt=merge(rt,i);
	for (T=0;T<26;T++) if (cnt[T]&1) break;
	for (i=T+1;i<26;i++) if (cnt[i]&1) return puts("-1"),0;
	while (siz[rt]>1) {
		for (k=rt;lc[k];k=lc[k]);c=1<<v[k];
		for (k=rt,rk=1;;)
			if (sum[rc[k]]&c) rk+=siz[lc[k]]+1,k=rc[k];
			else if ((1<<v[k])==c) break;
			else k=lc[k];
		pr=split(rt,rk+=siz[lc[k]]);
		if (rk==1) {
			k=pr.first;
			pr=split(pr.second,1);
			rt=merge(merge(pr.first,k),pr.second);
			ans++;
		} else {
			ans+=n-rk;
			k=pr.second,pr=split(pr.first,siz[pr.first]-1);
			rt=merge(split(pr.first,1).second,k);
			n-=2;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5120
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n;
llong a[200005];

int main() {
    cin >> n;
    for (int i = 0; i < n - 1; i++) {
        llong par;
        cin >> par;
        a[par]++;
    }

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

    return 0;
}


Measured memory_bytes: 5112
def partition(array, p, r)
    x = array[r][1]
    i = p-1
    (p..(r-1)).each do |j|
        if array[j][1] <= x
            i += 1
            tmp = array[i]
            array[i] = array[j]
            array[j] = tmp
        end
    end
    tmp = array[i+1]
    array[i+1] = array[r]
    array[r] = tmp
    i+1
end

def quicksort(array, p, r)
    if p < r
        q = partition(array, p, r)
        quicksort(array, p, q-1)
        quicksort(array, q+1, r)
    end
    array
end

n = gets.to_i
array1 = []
array2 = []
n.times do
    line = gets.chomp.split(" ")
    e = [line[0], line[1].to_i]
    array1.push(e)
    array2.push(e)
end
sorted1 = quicksort(array1, 0, n-1)
sorted2 = array2.sort_by {|e| e[1] }
puts sorted1==sorted2 ? "Stable" : "Not stable"
sorted1.each do |e|
    puts "#{e[0]} #{e[1]}"
end


Measured memory_bytes: 23460
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 1 << 21;
using pii = std::pair<int, int>;
#define SORT(v) std::sort(v.begin(), v.end())

int main(void) {
	long long N,X,Y,H,ans_x=0,ans_y=0,ans_h=0;
	std::cin >> N;
	std::vector<long long> x(N), y(N), h(N);
	for (int i = 0; i < N; ++i) {
		std::cin >> x[i] >> y[i] >> h[i];
		if (h[i] >= 1) {
			X = x[i];
			Y = y[i];
			H = h[i];
		}
	}
	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			long long V = H + std::abs(X - i) + std::abs(Y - j);
			V = std::max(V, 0LL);
			bool flag = true;
			for (int k = 0; k < N; k++) {
				long long VV = V - std::abs(x[k] - i) - std::abs(y[k] - j);
				VV = std::max(VV, 0ll);
				if (h[k] != VV) {
					flag = false;	
				}
			}
			if (flag == true) {
				std::cout << i << " " << j << " " << V << std::endl;
				return 0;
			}	
		}
	}
	return 0;
}


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

using namespace std;

const double eps = 1e-14;

#define RAD_TO_DEG (180/(4*atan(1)))

struct pol {
	int x, y;
	double ang;
};

int main(void) {
	int n;
	scanf("%d", &n);
	vector <pol> pv;
	for (int i = 0; i < n; i++) {
		int x, y;
		scanf("%d %d", &x, &y);
		if (!x && !y) continue;
		pv.push_back({
			x, y,
			atan2((double) y, (double) x)
		});
	}
	sort(pv.begin(), pv.end(), [&](const pol &a, const pol &b) {
		return a.ang < b.ang;
	});
	int k = pv.size();
	for (int i = 0; i < k; i++) {
		pv.emplace_back(pv[i]);
	}
	double ans = 0.0;
	for (int i = 0; i < k; i++) {
		long long int x = 0, y = 0;
		for (int j = 0; j < k; j++) {
			x += pv[i + j].x;
			y += pv[i + j].y;
			ans = max(ans, sqrt((double) x * x + (double) y * y));
		}
	}
	printf("%.12f", ans);
	return 0;	
}

Measured memory_bytes: 384