akhauriyash/Code-Regression huggingface dataset:
#line 1 "../lib/set.hpp"

#ifndef COMPRO_SET
#define COMPRO_SET

class Set {
private:
  int val;

public:
  Set(const int S) : val(S) {}

  bool operator==(const Set rhs) const { return val == rhs.val; }

  Set complement() const { return Set(~val); }

  Set intersection(const Set T) const { return Set(val & T.val); }

  Set unionSet(const Set T) const { return Set(val | T.val); }

  Set differenceSet(const Set T) const { return intersection(T.complement()); }

  bool has(const int i) const { return unionSet(toSet(i)) == *this; }

  int count() const { return __builtin_popcount(val); }

  int toInt() const { return val; }

  static Set toSet(int i) { return Set(1 << i); }
};

#endif
#line 1 "../lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>

using namespace std;

#line 3 "tmp.cpp"

struct edge {
  int to;
  int cost;
};

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

  int v, e;
  cin >> v >> e;

  vector<vector<edge>> g(v);

  REP(i, e) {
    int s, t, d;
    cin >> s >> t >> d;
    g[s].push_back({t, d});
  }

  int INF = 1e9;
  vector<vi> dp((1 << v), vi(v, INF));

  dp[(1 << v) - 1][0] = 0;
  for (int s = (1 << v) - 2; s >= 0; s--) {
    REP(i, v) {
      for (const auto u : g[i]) {
        Set S(s);
        if (!S.has(u.to)) {
          Set nS = S.unionSet(Set::toSet(u.to));
          dp[s][i] = min(dp[s][i], dp[nS.toInt()][u.to] + u.cost);
        }
      }
    }
  }

  cout << (dp[0][0] == INF ? -1 : dp[0][0]) << endl;

  return 0;
}



Measured memory_bytes: 6316
n=int(input())
a=list(map(int,input().split()))

count=0
wa={}
for j in range(1,n):
  if j+a[j-1] not in wa:
    wa[j+a[j-1]]=1
  else:
    wa[j+a[j-1]]+=1
  
  sa=j+1-a[j]
  if sa in wa:
    count+=wa[sa]

print(count)

Measured memory_bytes: 40476
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Char
import Data.Int
import Data.Foldable
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Debug.Trace

solve :: Int -> Int -> VU.Vector Int -> VU.Vector (Int, Int) -> Int
solve !n !m !an !bcs = (\(acc, an) -> acc + sum an) $ foldr
  ( \(!b, !c) (!acc, !an) -> if null an
    then (acc, an)
    else
      let (an1 , an2 ) = splitAt b an
          (an1t, an1d) = span (< c) an1
          an'          = an1d ++ an2
          isFin        = null an' || head an' >= c
      in  ( acc + length an1t * c + if isFin then sum an' else 0
          , if isFin then [] else an'
          )
  )
  (0, an')
  bcs'
 where
  an' = sort $ VU.toList an

  bcs' =
    sortBy (\(b1, c1) (b2, c2) -> compare (c1, b1) (c2, b2)) $ VU.toList bcs

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  (n, m) <-
    (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
  an  <- VU.unfoldrN n readInt <$> B.getLine
  bcs <-
    VU.replicateM m
    $   (\vec -> (vec VU.! 0, vec VU.! 1))
    .   VU.unfoldrN 2 readInt
    <$> B.getLine
  print $ solve n m an bcs


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

int main()
{
  int N, K;
  string S;
  char c;
  
  cin >> N >> K;
  cin >> S;
  
  c = S.at(K - 1);
  if(c > 90)
  {
    c -= 0x20;
  }else
  {
    c += 0x20;
  }

  S.at(K - 1) = c;

  cout << S << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') f=-1,c=getchar();
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=5000+10,mod=1e9+7;
int Begin[maxn],sz[maxn],Next[maxn<<1],to[maxn<<1],e;
int dp[maxn][maxn],tmp[maxn],fac[maxn];
void add_edge(int x,int y){
	to[++e]=y;
	Next[e]=Begin[x];
	Begin[x]=e;
}
void dfs_init(int x,int ff){
	sz[x]=1;
	dp[x][1]=1;
	for(int i=Begin[x];i;i=Next[i]) if(to[i]!=ff){
		dfs_init(to[i],x);
		REP(j,0,sz[x]+sz[to[i]]) tmp[j]=0;
		REP(k,0,sz[x]) REP(j,0,sz[to[i]]) tmp[k+j]=(tmp[k+j]+(ll)dp[x][k]*dp[to[i]][j])%mod;
		sz[x]+=sz[to[i]];
		REP(j,0,sz[x]) dp[x][j]=tmp[j];
	}
	REP(i,2,sz[x]) dp[x][0]=(dp[x][0]-(ll)dp[x][i]*fac[i])%mod;
}
int main(){
	int n=read();
	REP(i,1,n-1){
		int x=read(),y=read();
		add_edge(x,y),add_edge(y,x);
	}
	fac[2]=1;
	REP(i,4,n) if(i%2==0) fac[i]=(ll)fac[i-2]*(i-1)%mod;
	dfs_init(1,0);
	printf("%d\n",(mod-dp[1][0])%mod);
	return 0;
}

Measured memory_bytes: 97280
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <set>
#include <tuple>

using namespace std;

long long MOD = 1000000007;

int main(){
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;

    vector<long long> A(X,0);
    vector<long long> B(Y,0);
    vector<long long> C(Z,0);
    for(int i=0; i<X; i++){
        cin >> A[i];
    }
    for(int i=0; i<Y; i++){
        cin >> B[i];
    }
    for(int i=0; i<Z; i++){
        cin >> C[i];
    }

    sort(A.rbegin(), A.rend());
    sort(B.rbegin(), B.rend());
    sort(C.rbegin(), C.rend());

    priority_queue<long long> que;
    set<tuple<long long, int, int, int>, greater<tuple<long long, int, int, int>> > st;

    st.insert(make_tuple(A[0]+B[0]+C[0], 0, 0, 0));

    while(K>0){
        auto r = st.begin();
        long long ans = get<0>(*r);
        int i,j,k;
        i=-get<1>(*r);
        j=-get<2>(*r);
        k=-get<3>(*r);

        cout << get<0>(*r) << endl;
        if(i+1<X){
            st.insert(make_tuple(A[i+1]+B[j]+C[k], -(i+1), -j, -k));
        }
        if(j+1<Y){
            st.insert(make_tuple(A[i]+B[j+1]+C[k], -i, -(j+1), -k));
        }
        if(k+1<Z){
            st.insert(make_tuple(A[i]+B[j]+C[k+1], -i, -j, -(k+1)));
        }
        K--;
        st.erase(*r);
    }

}

Measured memory_bytes: 640
n=int(input())
l=[int(input()) for i in range(n)]
l.sort()
s=sum(l)
for i in range(n):
    if s%10!=0:
        print(s)
        break
    else:
        if l[i]%10!=0:
            s-=l[i]
else:
    print(0)

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

int main(){
	int n;
  	cin>>n;
  	
  	int flag=0;
  	if(n%10==7 || (n/10)%10==7 || n/100==7) flag=1;
      
  	if(flag==1){
    	cout<<"Yes"<<endl;
    }else if(flag==0){
    	cout<<"No"<<endl;	
    }
  	return 0;
}

Measured memory_bytes: 3632
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    intmax_t N, P[(int)2e5];
    intmax_t ans = 0;

    scanf("%jd", &N);
    for (size_t i = 0; i < N; i++) {
        scanf("%jd", &P[i]);
    }

    intmax_t min = P[0];
    for (size_t i = 0; i < N; i++) {
        if (P[i] <= min) {
            ans++;
            min = P[i];
        }
    }

    printf("%jd\n", ans);

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll mod = 1e9+7;
ll INF = 1e17;
/*ll gcd(ll a,ll b)
{
    if(a==0)
    return(b);
    return(gcd(b%a,a));
}*/
/*ll power(ll a,ll b,ll p)
{
	ll res=1;
	a%=p;
	while(b>0)
	{
		if(b&1)
		res=res*a%p;
		a=a*a%p;
		b>>=1;
	}
	return(res);
}*/
/*void dfs(ll x)
{
	vis[x]=true;
	for(ll i=0;i<v[x].size();i++)
	{
		if(vis[v[x][i]]==false)
		dfs(v[x][i]);
	}
}*/
/*ll b_search(ll arr[],ll n,ll s)
{
	ll l=0,r=n-1;
	while(l<=r)
	{
		ll mid=l+(r-l)/2;
		if(arr[mid]==s)
		return(mid);
		if(arr[mid]<s)
		l=mid+1;
		else
		r=mid-1;
	}
	return(-1);
}*/
void solve()
{
	ll n;
	cin>>n;
	ll c=n/500;
	n=n%500;
	ll c1=n/5;
	cout<<c*1000+c1*5<<endl;
}
int main()
{
	IOS
	ll t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
    return(0);
}


Measured memory_bytes: 256
import java.util.*;

// A - ABC Swap
// 練習としてやってみる。2020/4/12
public class Main {

	public static void main(String[] args) {

		// スペース区切りの整数３つ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		// 箱Ａと箱Ｂを入れ替える
		int tmp;
		tmp = a;
		a = b;
		b = tmp;

		// 箱Ａと箱Ｃを入れ替える
		tmp = a;
		a = c;
		c = tmp;

		System.out.println(a + " " + b + " " + c);

	}

}


Measured memory_bytes: 39480
import java.util.Scanner;

class Main{
public static void main(String[] args){

 int a;
 int b;
 int c;
 int d;
Scanner s = new Scanner(System.in);
    a=s.nextInt();
    b=s.nextInt();
    c=a*b;
    d=a*2+b*2;
System.out.println(c+" "+d);

}
}



Measured memory_bytes: 25996
import collections

N=int(input())
X=list(map(int,input().split()))
X.sort(reverse=True)
max=X[0]
min=X[len(X)-1]
power=0
minpower=float("inf")
for i in range(min,max+1,1):
    for j in range(N):
        power=power+(i-X[j])*(i-X[j])

    if minpower>power:
        minpower=power
    power=0
print(minpower)



Measured memory_bytes: 39024
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    ll N,A,B;
    cin >> N >> A >> B;

    if ( (B-A) %2 == 0 ) {
        OUT((B-A)/2)
    } else {
        ll ans = max(B-1,N-A); 
        // A=1
        ll lb = B- (A-1);
        ans = min(ans,(lb-1-1)/2+A);

        ll ra = A+ N-B;
        ans = min(ans,(N-ra-1)/2+N-B+1);

        cout << ans << '\n';
    }

    return 0;
}


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

#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define debug_interval ','
#define debug_toggle false

typedef long long ll;

inline ll toInt(string s){ll v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
inline ll gcd(ll a,ll b){return a?gcd(b%a,a):b;}
template<class...A> inline void debug(){cout<<endl;}
template<class...A> inline void debug_rest() {cout<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cout<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cout<<first,debug_rest(rest...);}

int n,da,db,adam,h,ans,cut;
vector<int> a,b;

int main(){
  ios::sync_with_stdio(false);
  cin>>n>>h;
  for(int i=0;i<n;i++){
    cin>>da>>db;
    a.pub(da);
    b.pub(db);
  }
  sort(all(a));
  sort(all(b));
  adam=a.back();
  while(adam<b.back()&&h>0){
      h-=b.back();
      b.pob();
      ans++;
  }
  if(h%adam==0&&h>0)cut=h/adam;
  else if(h>0)cut=h/adam+1;
  debug(ans,cut,adam,h);
  cout<<ans+cut<<endl;
}

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

using namespace std;

int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int sum = 0;
    for (int i = 1; i <= n; i ++)
    {
        for (int j = 1; j <= n; j ++)
        {
            for (int k = 1; k <= n; k ++)
            {
                gcd(i, gcd(j, k));
                sum += gcd(i, gcd(j, k));
            }
        }
    }
    cout << sum;
}


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

int main(){
  int a[12] = {1,3,1,2,1,2,1,1,2,1,2,1}, x, y;
  cin >> x >> y;
  
  if(a[x-1] == a[y-1]) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())
tmp = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if i*500+j*100+k*50==x:
                tmp+=1

print(tmp)


Measured memory_bytes: 3060
import sys
from math import sqrt

def solve():
    is_prime = eratos(10**6 + 1)

    while 1:
        a, d, n = map(int, sys.stdin.readline().split())

        if a == d == n == 0:
            return

        cnt = 0

        while cnt < n:
            cnt += is_prime[a]
            a += d

        print(a - d)

def eratos(n):
    s = [True] * n
    s[0] = s[1] = False

    for p in range(2, int(sqrt(n)) + 1):
        if s[p]:
            for q in range(p*p, n, p):
                s[q] = False

    return s

if __name__ == '__main__':
    solve()

Measured memory_bytes: 15132
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  string s, ans;
  int w;
  cin >> s >> w;
  for (int i = 0; i < s.size(); i+=w) {
    ans += s[i];
  }
  cout << ans << endl;
  return 0;
}

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

    cout << N - i + 1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define ft first
#define sd second
#define get(t, x) get<x>(t)
#define pb push_back
#define len length
#define dbgn(x) cerr << #x << ": " << x << '\n'
#define dbg(x) cerr << #x << ": " << x << ' '
#define MAX 1100000

using namespace std;
using namespace __gnu_pbds;

using lli = long long int;
using pll = pair<lli, lli>;
using pii = pair<int, int>;
using mii = map<int, int>;
using ti3 = tuple<int, int, int>;
using pqpi_min = priority_queue<pii, vector<pii>, greater<pii>>;
using ost = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T>
void print(T* a, int sz) {for(int i=0;i<sz;++i) cerr<<a[i]<<' ';cerr<<endl;}
istream &operator>>(istream &is, pii &p) {is >> p.ft >> p.sd;return is;}
ostream &operator<<(ostream &os, const pii &p) {os << "[" << p.ft << ", " << p.sd << ']'; return os;}
//int+string
//cin.ignore();

constexpr int M = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;

void solve()
{
    int x,n,i;
    set<int> v;
    cin>>n;
    for(i=0;i<n;++i) cin>>x,v.insert(x);
    cout<<v.size();
}   
int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define sz(x) ( (int)(x).size() )
using LL = long long;

const int mod = 1e9 + 7;
mt19937 rng( (int)chrono::steady_clock::now().time_since_epoch().count() );

struct Mint {
  int a;
  Mint(int _a = 0) : a(_a) {}
  friend ostream& operator << (ostream &out, const Mint &_) {
    out << _.a;
    return out;
  }

  bool operator == (const Mint &_) const { return a == _.a; }
  bool operator ! () const { return !a; }

  Mint operator + (const Mint &_) const {
    int ret = a + _.a;
    return ret < mod ? Mint(ret) : Mint(ret - mod);
  }
  Mint operator - (const Mint &_) const { return *this + Mint(mod - _.a); }
  Mint operator * (const Mint &_) const { return Mint( (int)( (LL)a * _.a % mod) ); }
  friend Mint& operator += (Mint &a, const Mint &b) { return a = a + b; }
  friend Mint& operator -= (Mint &a, const Mint &b) { return a = a - b; }
  friend Mint& operator *= (Mint &a, const Mint &b) { return a = a * b; }
  Mint& operator ++ () { return *this = *this + Mint(1); }
  Mint& operator -- () { return *this = *this - Mint(1); }

  template<class T> Mint binPow(T exp) const {
    Mint ret(1), c = *this;
    for (; exp; exp >>= 1, c *= c) if (exp & 1) ret *= c;
    return ret;
  }
};

int main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  #ifdef FourLeafClover
  freopen("input", "r", stdin);
  #endif // FourLeafClover

  int n; cin >> n;

  vector<Mint> f(n);
  f.back() = Mint(n);

  vector<Mint> suff(n);
  suff.back() = f.back();
  for (int i = n - 2; ~i; --i) {
    f[i] += f[i + 1];
    f[i] += Mint(n - 1) * Mint(n - 1);
    if (i + 3 < n) {
      f[i] += suff[i + 3];
      f[i] += Mint(n - 1 - (n - (i + 3) ) );
    }
    else f[i] += Mint(n - 1);

    suff[i] = suff[i + 1] + f[i];
  }

  cout << f[0] << '\n';

  return 0;
}



Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char a[200010];
int main()
{
    scanf("%s",a);
    int len=strlen(a);
    ll cnt=0,sum=0;
    for(int i=0;i<len;i++)
    {
        if(a[i]=='B')
            cnt++;
        else if(a[i]=='W')
            sum+=cnt;
    }
    printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	
	char x,y;
	cin>>x>>y;
	if(x==y){
		cout<<'='<<endl;
	}
	
	else if(x<y){
		cout<<'<'<<endl;
	}
	
	else if(x>y){
		cout<<'>'<<endl;
	}
	
}


Measured memory_bytes: 256
a = int(input())
ar = list(map(int,input().split(" ")))
br = list(map(int,input().split(" ")))
cr = list(map(int,input().split(" ")))
count = sum(br)
for i in range(a-1):
    if ar[i+1] - ar[i] == 1:
        count += cr[ar[i]-1]
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <numeric>
#include <functional>
#include <stack>

int main (){
	int a;
	std::string s;

	std::cin >> a >> s;
	int start = s.length() / 2;

	if (a <= 1 || a % 2 == 1) {
		std::cout << "No" << std::endl;
		return 0;
	}

	for (size_t i = 0; i < s.length() / 2; i++)
	{
		if (s[i] != s[start]) {
			std::cout << "No" << std::endl;
			return 0;
		}
		start++;
	}

	std::cout << "Yes" << std::endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
 
public class Main{
 
	public static void main(String[] $){
		Scanner s = new Scanner(System.in);
        int K = s.nextInt();
        int A = s.nextInt();
        int B = s.nextInt();
        boolean S = false;

        for(int i = A; i <= B; i++){
            if(i % K == 0){
                S = true;
            }
        }

        

        if(S){
            System.out.println("OK");
        }else{
            System.out.println("NG");
        }
	}
} 

Measured memory_bytes: 35756
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 1
#define INF (1LL<<50)

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

signed main(){
 
	lli n,k;
	cin>>n>>k;
	vector<lli> a(n);
	lli maxA=0;
	REP(i,0,n){
		cin>>a[i];
		maxA = max(maxA,a[i]);
	}

	lli num = gcd(max(a[0],a[1]),min(a[0],a[1]));
	REP(i,2,n)num = gcd(max(num,a[i]),min(num,a[i]));

	if(k>maxA){
		cout<<"IMPOSSIBLE"<<endl;
	}
	else if(k%num==0){
		cout<<"POSSIBLE"<<endl;
	}
	else{
		cout<<"IMPOSSIBLE"<<endl;
	}

	return 0;
}

Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;
	int m, t, p, r;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			m = sc.nextInt(); t = sc.nextInt(); p = sc.nextInt(); r = sc.nextInt();
			if( (m|t|p|r) == 0 ) break;
			T[] team = new T[t];
			for(int i=0;i<t;i++) team[i] = new T(i+1);
			for(int i=0;i<r;i++) {
				int m = sc.nextInt(), t = sc.nextInt(), p = sc.nextInt(), j = sc.nextInt();
				team[t-1].solve(p, m, j);
			}
			sort(team);
			System.out.print(team[0].id);
			for(int i=1;i<t;i++) System.out.print((team[i].sol == team[i-1].sol && team[i].pen == team[i-1].pen? "=": ",") + team[i].id);
			System.out.println();
		}
	}
	
	class T implements Comparable<T> {
		int id, sol, pen;
		int[] pt;
		T(int id) {
			this.id = id;
			sol = 0; pen = 0;
			pt = new int[p];
		}
		
		void solve(int p, int t, int j) {
			if(j == 0) {
				sol++; pen += t + pt[p-1] * 20;
			}
			else {
				pt[p-1]++;
			}
		}

		public int compareTo(T o) {
			if( sol != o.sol ) return o.sol - sol;
			if( pen != o.pen ) return pen - o.pen;
			return o.id - id;
		}
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 60744
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;



const ll mod=1e9+7;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(ll n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (ll i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (ll i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(ll n, ll k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint p(ll n, ll k) {
    return fact[n]*ifact[n-k];
  }
} c(1000005);

int main(){
    ll n;
    cin >> n;
    mint a=10;
    mint b=9;
    mint c=8;
    mint d=2;
    mint ans=a.pow(n)-d*b.pow(n)+c.pow(n);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 18640
#include <bits/stdc++.h>
using namespace std;
long long N,a,b,ans=0,i;
void dz(int i,int ns,int ne)
{
	for(i=ns;i<ne;i++)
	{
		cin>>b;
		if(a>b) 
		ans+=a-b;
		else 
    	a=b;
	}
}
int main() 
{	
	cin>>N>>a;
	dz(i,1,N);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3604
N, M = map(int, input().split())

S = [[0] * N for _ in range(M)]

for i in range(M):
    a = [int(i) for i in input().split()]
    for j in a[1:]:
        S[i][j-1] = 1

P = [int(i) for i in input().split()]

ans = 0

for i in range(2**N):
    K = [0] * M
    for j in range(N):
        if i >> j & 1:
            for k in range(M):
                if S[k][j] == 1:
                    K[k] += 1
    c = 0
    for j in range(M):
        if K[j]%2 == P[j]:
            c += 1
    if c == M:
        ans += 1

print(ans)


Measured memory_bytes: 42352
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int len=s.length();
    int ans=len;
    for (int i=0; i<len; i++)
    {
        if (s[i]=='-') ans-=2;;
    }
    cout<<ans;
    return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if ( A + B > C + D ) {
    cout << "Left" << endl;
  }
  else if ( A + B == C + D ) {
    cout << "Balanced" << endl;   
  }
  else if ( A + B < C + D ) {
    cout << "Right" << endl;
  }
  
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type Record struct {
	ID     int
	Number int
}

type Records []Record

func (r Records) Len() int {
	return len(r)
}

func (r Records) Less(i, j int) bool {
	return r[i].Number < r[j].Number
}

func (r Records) Swap(i, j int) {
	r[i], r[j] = r[j], r[i]
}

func readf(sc *bufio.Scanner) float64 {
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	a := make(Records, n)
	for i := range a {
		sc.Scan()
		a[i].ID = i + 1
		a[i].Number, _ = strconv.Atoi(sc.Text())
	}

	sort.Sort(Records(a))

	for i := range a {
		fmt.Printf("%d ", a[i].ID)
	}
	fmt.Println()
}


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


int main(){
	int w , n;
	int d1 , d2;
	cin >> w >> n;
	vector<int> ans(w+1);
	for(int i=1 ; i<=w ; i++){
		ans[i]=i;
	}
	for(int i=0 ; i<n ; i++){
		scanf("%d,%d" , &d1 , &d2);
		swap(ans[d1] , ans[d2]);
	}
	for(int i=1 ; i<=w ; i++){
		cout << ans[i] << endl; 
	}
	return 0;
}

Measured memory_bytes: 1244
#include <iostream>
using namespace std;
long long int a[100006];
int main () {
	int N, zero=0;
	cin >> N;
	for (int i=0; i<N; i++) {
		cin >> a[i];
		if (a[i]==0) {
			zero++;
		}
	}
	if (zero>0) {
		cout << "0" << endl;
		return 0;
	}
	long long int sum=1;
	for (int i=0; i<N; i++) {
		if (a[i]<=1000000000000000000/sum) {
			sum*=a[i];
		}
		else {
			cout << "-1" << endl;
			return 0;
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 4372
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.141592

typedef struct tuple{
  double x;
  double y;
}Coord;

int drawKoch(int n,Coord p1,Coord p2){
  Coord s,t,u;

  if(n == 0) return 0;  

  // calcurate
  s.x = (p1.x*2 + p2.x) / 3;
  s.y = (p1.y*2 + p2.y) / 3;
  t.x = (p1.x + p2.x*2) / 3;
  t.y = (p1.y + p2.y*2) / 3;
  u.x = (t.x - s.x) * cos(PI/3) - (t.y - s.y) * sin(PI/3) + s.x;
  u.y = (t.x - s.x) * sin(PI/3) + (t.y - s.y) * cos(PI/3) + s.y;

  // recursive plot
  drawKoch(n-1,p1,s);
  printf("%lf %lf\n",s.x,s.y);
  drawKoch(n-1,s,u);
  printf("%lf %lf\n",u.x,u.y);
  drawKoch(n-1,u,t);
  printf("%lf %lf\n",t.x,t.y);
  drawKoch(n-1,t,p2);

  return 1;
}

int main(){
  int n,tmp;
  Coord p1 = {0,0}, p2 = {100,0};

  // input
  scanf("%d",&n);

  // plot
  printf("%lf %lf\n",p1.x,p1.y);
  tmp = drawKoch(n,p1,p2);
  printf("%lf %lf\n",p2.x,p2.y);

  return 0;
}

Measured memory_bytes: 636
S = input()
T = input()

found = []
for i in range(len(S) - len(T) + 1):
    for cs,ct in zip(S[i:],T):
        if cs != '?' and cs != ct:
            break
    else:
        found.append(i)

if not found:
    print('UNRESTORABLE')
    exit()

ans = 'z' * 51
for i in found:
    tmp = S[:i] + T + S[i+len(T):]
    ans = min(ans, tmp.replace('?', 'a'))
print(ans)


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

int main(){
    int N, M; cin >> N >> M;
    vector<pair<ll, ll>> v(N);
    for(int i = 0; i < N; i++){
        ll A, B; cin >> A >> B;
        v[i] = make_pair(A, B);
    }
    sort(v.begin(), v.end());

    ll ans = 0;
    int m = 0, j = 0;
    for(int i = 0; i < N; i++){
        ans += v[i].first * v[i].second;
        m += v[i].second;
        if(m > M){
            ans -= v[i].first * v[i].second;
            m -= v[i].second;
            j = i;
            break;
        }
    }
    ans += v[j].first * (M - m);
    
    cout << ans << endl;
}

Measured memory_bytes: 1792
# 163_b
N,M=map(int,input().split())
A=input().split()
for i in range(len(A)):
    A[i]=int(A[i])
if (1<=N and N<=10**6)and(1<=M and M<= 10**4):
    for j in range(len(A)):
        N-=A[j]
    if N >= 0:
        print(N)
    if N < 0:
        print('-1')

Measured memory_bytes: 9612
from string import ascii_lowercase as lc
from bisect import bisect_left

keta = [
  26,
  702,
  18278,
  475254,
  12356630,
  321272406,
  8353082582,
  217180147158,
  5646683826134,
  146813779479510,
  3817158266467286
]

n = int(input())
if n <= 26:
    print(lc[n-1])
    exit(0)
    
name = []
ind = bisect_left(keta, n)
n -= keta[ind-1] + 1
for i in range(ind):
    rem  = n % 26
    name.append(rem)
    n //= 26
name.append(n)
name.reverse()
#print(name)
print(''.join(lc[i] for i in name))

Measured memory_bytes: 9896
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <deque>

using namespace std;

#define FOR(i, start, end) for(ll i = (start); i < (end); i++)
#define rep(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ctoi(c) c - '0'
#define tos(s) to_string(s)

typedef long long ll;

int main() {
    int d, t,s;
    cin >> d >> t >> s;
    if (s*t >= d) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

/*
ACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACAC                                                                              
                                   ******,  .,, .,, ,,,    ****.**              
                                   ** . .,,,,,,,,,,,,,,,,,,,,,. .,*             
                                   **,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.            
                                .,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.        
                                .,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.        
                    ****      ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,      
              ***************,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,    
         ********************,,,,,,,,,,,,,,@@@,,,,,,,,,,,/@@@,,,,,,,,,,,,,,,    
        ******************,,,,,,,,,,,,,,,,,,(,,.         ,,,,,,,,,,,,,,,,,,,    
       ********************,,,,,,,,,,,*,,,,,.     %&&&     .,,,,*,,,,,,,,,,,,.  
       ***,,,,,,,,,,,,,,*,,,,,,,,,,,,,,,,,,,,               ,,,,,,,,,,,,,,,,,   
       ,,,,,,,,,,,,,,,,,,,**,,,,,,,,,,.......      ##(     ........,,,,,,,,,,.  
     .,,,,,,,,,,,,,,,,,,**,,,,,,,,,,..............    ..............,,,,,,,,    
    .,,,,,,,,,,,,,,,,,,,**,,,,,,,,,.................................,,,,,,,,,   
   ,,,,,,,,,,,,,,,,,,,,***,,,,,,,....................................,,,,,,,,,  
   ,,,,,,,,,,,,,,,,,,,,**,,,,,,,,.....................................,,,,,,,   
   ,,,,,,,,,,,,,,,,,,,,,**,,,,,,,,....................................,,,,,,,   
   ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.....................................,,,,,     
   ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,...................................,.,,,,,     
    ,,,,,,,,,,,,,,,,,,,,,,,,,,,,.....................................,,,        
     ,,,,,,,,,,,,,,,,,,,,,,,,,,,,....................................,,,        
      ,,,,,,,,,,,,,,,,,,,,,,,,,,,,...................................,          
       ..,,,,,,,,,,,,,,,,,,,,,,,,,,.................................,           
       .........**.....       ,,,,,..............................               
        .......*......                  ****,**,       ,..****                  
        .......*,....                   .......        ......                   
          .......*....                   .....          .....                   
                                         ......          .....                  
*/

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

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

    vector<int> av;
    int aMax = 0;

    for(int i=0; i<n; ++i){
        int a;
        cin >> a;
        if(a > aMax) aMax = a;
        av.push_back(a);
    }

    vector<bool> b;
    b.resize(aMax+1);
    fill(b.begin(), b.end(), true);

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

    for(int i=0; i<n; ++i){
        if(!b[av[i]]) continue;
        for(int j=2; j<=aMax/av[i]; ++j){
            b[av[i]*j] = false;
        }

        if(i<n-1 && av[i]==av[i+1]){
            b[av[i]] = false;
        }
    }

    int count = 0;
    for(int i=0; i<n; ++i){
        if(b[av[i]]) ++count;
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 4236
a = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
b = input()
c = []
d = len(b)

for i in range(int(d)):
  c.append(b[i])

e = list(set(c))
f = sorted(e)
g = len(f)
h = int(0)

if g != 26:
  for i in range(int(g)):
    if f[i] == a[i]:
      h = h + 1
    else:
      print(a[i])
      break
else:
  print("None")
  
if h == g:
  print(a[h])

Measured memory_bytes: 74428
import itertools
n,m,q = map(int,input().split())
num_ls = [[0,0,0,0] for _ in range(q)]
for i in range(q):
    num_ls[i] = list(map(int,input().split()))

a_base = [i for i in range(1,m+1)]
a_ls = []
for A in itertools.combinations_with_replacement(a_base, n):
    istarget = True
    for i in range(n-1):
        if A[i] > A[i+1]:
            istarget = False
    if istarget:
        a_ls.append(list(A))
ans = 0
for A in a_ls:
    value_of_A = 0
    for a,b,c,d in num_ls:
        if A[b-1] - A[a-1] == c:
            value_of_A += d
    ans = max(ans, value_of_A)
print(ans)

Measured memory_bytes: 22928
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] w = new int[n];
		int[] e = new int[n];
		int countw = 0;
		int counte = 0;
		char[] s = sc.next().toCharArray();
		for(int i = 0; i < n; i++) {
			if(s[i]=='W') {
				countw++;
				w[i]+=countw;
				e[i] = counte;
			}
			else if(s[i]=='E') {
				counte++;
				e[i]+=counte;
				w[i] = countw;
			}
		}
		int min = e[n-1]-e[0];
		for(int i = 1; i < n-1; i++) {
			int now = (w[i-1])+(e[n-1]-e[i]);
			//System.out.println(now);
			min = Math.min(now, min);
		}
		min = Math.min(w[n-2], min);
		System.out.println(min);
	}
}

Measured memory_bytes: 45188
#include<bits/stdc++.h>
using namespace std;
int main(){
	unsigned long long n,a[200001],sum=0,flag=1;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		if(a[i]==flag) flag++;
		else sum++;
	}
	if(sum==n) cout<<"-1";
	else cout<<sum;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

vector<int> G[2002];

int calc(int v, int pre, int d){
	int res = 0;

	if (d < 0) res++;

	rep (i, G[v].size()){
		int u = G[v][i];
		if (u == pre) continue;
		res += calc(u, v, d - 1);
	} // end rep

	return res;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, K; cin >> N >> K;
	rep (i, N) G[i].clear();
	
	rep (i, N-1){
		int a, b; cin >> a >> b; 
		--a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	} // end rep

	int res = N;
	if (K % 2 != 0){
		rep (i, N){
			rep (j, G[i].size()){
				int u = G[i][j];
				res = min (res, calc(i, u, K / 2) + calc(u, i, K / 2));
			} // end rep
		} // end rep
	}else{
		rep (i, N){
			res = min(res, calc(i, -1, K / 2));
		} // end rep
	} // end if

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define bitCount(num)  __builtin_popcount(num)
#define pb push_back
#define ll long long
#define bye return 0;
#define f(i,a,b) for( long long i=a;i<b;i++)
#define testCases long long t;cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define newLine <<"\n"
#define all(x) (x).begin(), (x).end()
#define vll vector<long long>

int main()
{
    fast
   int n;
   cin>>n;
   vector<ll> h(n,0);
   f(i,0,n) cin>>h[i];
   ll ans=0;
   f(i,1,n)
   {
   	if(h[i]<h[i-1]) 
   		{
   			ans+=(h[i-1]-h[i]);
   			h[i]=h[i-1];
   		}
   }
   cout<<ans<<endl;
    bye
}

Measured memory_bytes: 4776
n = int(input())
ss = {}
for _ in range(n):
  s = input()
  S = []
  for c in s:
    S.append(c)
  S.sort()
  s = ''.join(S)
  if s in ss:
    ss[s] += 1
  else:
    ss[s] = 1

def func(n):
  if n ==1:
    return 0
  return n*(n-1)//2
    
ans = 0
for key in ss:
  ans += func(ss[key])
    
    
    
print(ans)



Measured memory_bytes: 17804
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>

using namespace std;
typedef long long int ll;typedef pair<int, int> P;
const long long mod = 1e9 + 7;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }


int main(void) {
	int a, b; cin >> a >> b;
	cout << max(a - (b * 2), 0) << endl;
	return 0;
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
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; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end

struct max_flow {
    struct Edge { int to, cap, rev; };
    int V; vector<vector<Edge>> G; vector<int> itr, level;
public:
    max_flow(int V) : V(V) { G.assign(V, vector<Edge>()); }
    void add_edge(int from, int to, int cap) {
        G[from].push_back({ to, cap, (int)G[to].size() });
        G[to].push_back({ from, 0, (int)G[from].size() - 1 });
    }
    void bfs(int s) {
        level.assign(V, -1); queue<int> q;
        level[s] = 0; q.push(s);
        while (!q.empty()) {
            int v = q.front(); q.pop();
            for (auto& e : G[v]) {
                if (e.cap > 0 && level[e.to] < 0) {
                    level[e.to] = level[v] + 1;
                    q.push(e.to);
                }
            }
        }
    }
    int dfs(int v, int t, int f) {
        if (v == t) return f;
        for (int& i = itr[v]; i < (int)G[v].size(); ++i) {
            Edge& e = G[v][i];
            if (e.cap > 0 && level[v] < level[e.to]) {
                int d = dfs(e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d, G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    int run(int s, int t) {
        int ret = 0, f;
        while (bfs(s), level[t] >= 0) {
            itr.assign(V, 0);
			while ((f = dfs(s, t, inf)) > 0) ret += f;
        }
        return ret;
    }
};

int main(){
    int n,m; scanf("%d%d",&n,&m);
    vector<vector<int>> a(n);
    rep(i,0,n){
        a[i].resize(m);
        rep(j,0,m)scanf("%d",&a[i][j]);
    }
    int b[110][110],c[110][110];
    rep(rot,0,m){
        max_flow g(2*n+2);
        rep(i,0,n)rep(j,0,m)if(a[i][j]){
            int val=(a[i][j]-1)/m;
            g.add_edge(i,val+n,1);
        }
        rep(i,0,n){
            g.add_edge(2*n,i,1);
            g.add_edge(i+n,2*n+1,1);
        }
        int maxx=g.run(2*n,2*n+1);
        cerr<<maxx<<endl;
        rep(i,0,n){
            int p;
            for(auto e:g.G[i])if(e.cap==0)p=e.to-n;
            rep(j,0,m){
                if(a[i][j]>=p*m+1&&a[i][j]<=p*m+m){
                    b[i][rot]=a[i][j];
                    a[i][j]=0; break;
                }
            }
        }
    }
    rep(i,0,m){
        vector<int> s(n);
        rep(j,0,n)s[j]=b[j][i];
        sort(ALL(s));
        rep(j,0,n)c[j][i]=s[j];
    }
    rep(i,0,n){
        rep(j,0,m)printf("%d ",b[i][j]);
        puts("");
    }
    rep(i,0,n){
        rep(j,0,m)printf("%d ",c[i][j]);
        puts("");
    }
    return 0;
}

Measured memory_bytes: 736
fun main(args: Array<String>) {
    abc154d()
}

fun abc154d() {
    val (n, k) = readLine()!!.split(' ').map { it.toInt() }
    val pList = readLine()!!.split(' ').map { it.toInt() }

    val list = pList.map { 0.5 + it.toDouble() / 2 }

    val cSum = DoubleArray(n + 1)
    for (i in 0 until n) cSum[i + 1] = cSum[i] + list[i]

    var answer = 0.0

    for (i in 0..n - k) {
        answer = Math.max(answer, cSum[i + k] - cSum[i])
    }

    return println(answer)
}


Measured memory_bytes: 62028
a = int(input())
A = []
for i in range(a):
    x,L = map(int,input().split())
    A.append([x+L,x-L])
A.sort()
# print(l)
res = 1
t = A[0]
for i in range(1,a):
    l = A[i]
    if t[0] <= l[1]:
        t = l
        res+=1
print(res)




Measured memory_bytes: 20064
n, k = map(int,input().split())
s = input()

s = s+"a" #拡張して扱いやすくする

lst = [i for i in s]

ans = 0
memo1 = 0
memo2 = 0
for i in range(n):
    if lst[i] == lst[i+1]:
        ans += 1
    elif lst[i] == "L" and lst[i+1] == "R":
        memo1 += 1
    elif lst[i] == "R" and lst[i+1] == "L":
        memo2 += 1
        
ans += 2*min(k,memo1,memo2)
num = min(k,memo1,memo2)

jdg = False
jdg2 = False

if memo1 >= num+1 and lst[n-1] == "R" and num < k:
    ans += 1
    jdg = True
if jdg:
    if memo2 >= num+2 and lst[0] == "L" and num < k+1:
        ans += 1
        jdg2 = True
else:
    if memo2 >= num+1 and lst[0] == "L" and num < k:
        ans += 1
        jdg2 = True
        
if not(jdg):
    if memo2 >= num+1 and lst[n-1] == "L" and num < k:
        ans += 1
        jdg = True
    if jdg:
        if memo1 >= num+2 and lst[0] == "R" and num < k+1:
            ans += 1
            jdg2 = True
    else:
        if memo1 >= num+1 and lst[0] == "R" and num < k:
            ans += 1
            jdg2 = True
    
elif not(jdg2):
    if memo2 >= num+1 and lst[n-1] == "L" and num < k:
        ans += 1
        jdg = True
    if jdg:
        if memo1 >= num+2 and lst[0] == "R" and num < k+1:
            ans += 1
            jdg2 = True
    else:
        if memo1 >= num+1 and lst[0] == "R" and num < k:
            ans += 1
            jdg2 = True
    
    

print(ans)
        
        
    

Measured memory_bytes: 4212
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/
const int MAXN = 210000;
const ll MOD = 1e9 + 7;

vector<pair<int, int>> vv;

vector<pair<int, int>> gg;
int n, m;
int gl[MAXN];
int gr[MAXN];
vector<int> go[MAXN];
ll rmq[MAXN * 4];

int get(const vector<int> &v, int x) {
	return lower_bound(v.begin(), v.end(), x) - v.begin();
}

void add(int v, int tl, int tr, int x, ll y) {
	rmq[v] = (rmq[v] + y) % MOD;
	if (tl + 1 == tr)
		return;
	int m = (tl + tr) >> 1;
	if (x < m)
		add(v * 2 + 1, tl, m, x, y);
	else
		add(v * 2 + 2, m, tr, x, y);
}

ll getsum(int v, int tl, int tr, int l, int r) {
	if (r <= tl || tr <= l)
		return 0;
	if (l <= tl && tr <= r) {
		return rmq[v];
	}
	int m = (tl + tr) >> 1;
	return (getsum(v * 2 + 1, tl, m, l, r) + getsum(v * 2 + 2, m, tr, l, r)) % MOD;
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		int x;
		cin >> x;
		vv.emplace_back(x, 0);
	}
	for (int i = 0; i < m; ++i) {
		int x;
		cin >> x;
		vv.emplace_back(x, 1);
	}
	sort(vv.begin(), vv.end());
	int pr = -1;
	for (int i = 0; i < vv.size(); ++i) {
		if (vv[i].second)
			pr = i;
		else {
			if (pr != -1)
				gl[i] = vv[i].first - vv[pr].first;
		}
	}
	pr = -1;
	for (int i = vv.size() - 1; i >= 0; --i) {
		if (vv[i].second)
			pr = i;
		else {
			if (pr != -1)
				gr[i] = vv[pr].first - vv[i].first;
		}
	}
	vector<int> vl, vr;
	for (int i = 0; i < vv.size(); ++i) {
		if (gl[i] && gr[i]) {
			vl.push_back(gl[i]);
			vr.push_back(gr[i]);
		}
	}
	sort(ALL(vl));
	vl.resize(unique(ALL(vl)) - vl.begin());
	sort(ALL(vr));
	vr.resize(unique(ALL(vr)) - vr.begin());
	for (int i = 0; i < vv.size(); ++i) {
		if (gl[i] && gr[i]) {
			gl[i] = get(vl, gl[i]);
			gr[i] = get(vr, gr[i]);
			go[gl[i]].push_back(gr[i]);
		}
	}
	int sz = vr.size() + 1;
	add(0, 0, sz, 0, 1);
	for (int i = 0; i < vl.size(); ++i) {
		sort(ALL(go[i]));
		go[i].resize(unique(ALL(go[i])) - go[i].begin());
		reverse(ALL(go[i]));
		for (int j: go[i]) {
			add(0, 0, sz, j + 1, getsum(0, 0, sz, 0, j + 1));
		}
	}
	cout << getsum(0, 0, sz, 0, sz) << "\n";
	return 0;
}




Measured memory_bytes: 15604
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;


int main(){
    int a, b;
    cin >> a >> b;
    int ans = -1000000;

    ans = max(ans, a + b);
    ans = max(ans, a - b);
    ans = max(ans, a * b);
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val a = (1..n).map { sc.nextInt() }
    val LtoR = Array(n) {0L}
    repeat(n) {
        val v = a[it] - 1
        if (it - v >= 0) LtoR[it - v]++
    }
    val ans = (0 until n).map {
        val to = it + a[it] + 1
        if (to < n) LtoR[to] else 0L
    }.sum()
    println(ans)
}

Measured memory_bytes: 67836
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let a: Vec<usize> = (0..n).map(|_| read()).collect();

    // 大きい順
    let mut vec: Vec<usize> = vec![];
    vec.push(a[0]);
    for i in 1..n {
        if vec[vec.len()-1] >= a[i] {
            vec.push(a[i]);
            continue;
        }
        let mut ok = vec.len();
        let mut ng = 0;
        while ng + 1 < ok {
            let mid = (ok + ng) / 2;
            if vec[mid] < a[i] {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        if vec[ng] < a[i] {
            vec[ng] = a[i];
        } else {
            vec[ng+1] = a[i];
        }
    }
    println!("{}", vec.len());
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 6396
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int D, T, S;
	cin >> D >> T >> S;

	int ans = S * T;
	if(ans < D){
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 3616