akhauriyash/Code-Regression huggingface dataset:
s = input()
t = input()

s_dash = ''.join(sorted(s))
t_dash = ''.join(sorted(t)[::-1])

test = [s_dash, t_dash]

if s_dash == t_dash:
    print("No")
else:
    if sorted(test)[0] != s_dash:
        print("No")
    else:
        print("Yes")


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

int main(){
  map<string, int> ma;
  int n;
  long long aw=0;
  string a;
  cin>>n;
  
  for(int i=0; i<n; i++){
    cin>>a;
    sort(a.begin(), a.end());
    aw +=ma[a];
    ma[a]++;
  }
  
  cout<<aw<<endl;

    
}


Measured memory_bytes: 11136
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

bool dp[30001][4][1000];

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

	int N;
	cin >> N;

	string S;
	cin >> S;

	dp[0][0][0] = true;

	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j <= 3; j++)
		{
			for (int k = 0; k < 1000; k++)
			{
				if (!dp[i][j][k]) continue;

				dp[i + 1][j][k] = true;
				if (j <= 2)
				{
					dp[i + 1][j + 1][k * 10 + (S[i] - '0')] = true;
				}
			}
		}
	}

	int result = 0;
	for (int i = 0; i < 1000; i++)
	{
		if (dp[N][3][i])
		{
			result++;
		}
	}

	cout << result;

	return 0;
}


Measured memory_bytes: 117504
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
         String s = sc.next();
         int result = 0;
        for(int i = 0;i<n-2;i++){
            String sub = s.substring(i,i+3);
            if(sub.equals("ABC")){
                result++;
            }
        }
        System.out.println(result);
        sc.close();
    }
}

Measured memory_bytes: 22868
#include <iostream>
#include<algorithm>
#include <vector>
#include <string>
#include <stdio.h>
#include <cstdio>
#include <ctype.h>
#include <cstdlib>
using namespace std;

int main() {
	string a,b,c;
		char d,e,f;
		cin >> a >> b >> c;
		d=toupper(a[0]);
		e=toupper(b[0]);
		f=toupper(c[0]);
		cout<<d<<e<<f<<endl;

	return 0;
}

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

// 最小公倍数
unsigned lcm(unsigned a, unsigned b){
    return a / gcd(a, b) * b; 
}

void rerio(int hp, string s){
    if(hp == 0) print(s);
    else{
        for(char c = 'a'; c <= 'c'; c++) rerio(hp -1, s + c);
    }
}

int main(){
    int N;
    cin >> N;
    vector<int>A(N);
    REP(i, N) cin >> A[i];
    vector<int>B(N);
    REP(i, N) cin >> B[i];
ll S = 0;
vector<int>X;
int cnt = 0;
    REP(i, N){
        if(A[i] < B[i]){
            S += B[i] - A[i];
            cnt++;
        }    
        else X.push_back(A[i] - B[i]);
    }
if(cnt == 0){
    print(0);
    return 0;
}
sort(all(X));
reverse(all(X));
REP(i, X.size()){
    if(S <= 0) break;
    S -= X[i];
    cnt++;
}
if(S <= 0)print(cnt);
else print(-1);
}


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

using namespace std;
using ll = long long;

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

  int n;
  cin >> n;

  switch (n % 10) {
  case 2:
  case 4:
  case 5:
  case 7:
  case 9:
    cout << "hon\n";
    break;
  case 0:
  case 1:
  case 6:
  case 8:
    cout << "pon\n";
    break;
  default:
    cout << "bon\n";
    break;
  }

  return 0;
}


Measured memory_bytes: 3620
S = input()
n = len(S)

S00 = S[:]
S01 = S00[::-1]
S10 = S[:(n-1)//2]
S11 = S10[::-1]
S20 = S[(n+3)//2-1:]
S21 = S20[::-1]

if S00 == S01 and S10 == S11 and S20 == S21:
    print("Yes")
else:
    print("No")


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



int main(){
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	int x = abs(tx-sx);
	int y = abs(ty-sy);

	cout << string(y, 'U') << string(x, 'R') << string(y, 'D') << string(x, 'L')<<"";
	cout << string(1, 'L') << string(y+1,'U') << string(x+1, 'R') << string(1, 'D') << string(1, 'R') << string(y+1, 'D') << string(x+1, 'L') << string(1, 'U');

	return 0;
}


Measured memory_bytes: 256
n,p = map(int,input().split())

i = 2
factors = []
factor_sub = set()
if n == 1:
    print(p)
elif p > 1:
    while i * i <= p:
        if p % i:
            i += 1
        else:
            p //=i
            factors.append(i)
            factor_sub.add(i)
    if p > 1:
        factors.append(p)
    if len(factors) < n:
        print('1')
    else:
        ans = 1
        for c in factor_sub:
            temp = factors.count(c)
            while temp >= n:
                ans *= c
                temp -= n
        print(int(ans))
else:
    print('1')

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

#ifdef DEBUG
#define FAST ;
#else
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#endif
#define _ <<' '<<
#define Fr(i, s, e) for(auto i = s; i < e; ++i)
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MAX = 1e6+5;
constexpr ll INF = 2134567890;
constexpr ll MOD = 1e9+7;

ll fpow(ll b, ll a, ll MOD = MOD) {
    b %= MOD;
    ll r = 1;
    for(; a; b=b*b%MOD, a>>=1)
        a&1 && (r = r*b%MOD);
    return r;
}

signed main() {
    FAST;

    string S;
    cin >> S;
    ll ans = 0, cnt, sum;
    const int sz = S.size();
    Fr(i, 0, sz) Fr(j, i+1, sz+1) {
        sum = 0;
        Fr(k, i, j) sum = sum*10+S[k]-'0';
        cnt = (1<<max(0,i-1))*(1<<max(0,sz-1-j));
        //cerr _ i _ sz-j _ sum _ cnt _ endl;
        ans = ans+sum*cnt;
    }
    cout << ans << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    for(int &x:a){
        cin>>x;
    }
    vector<bool> dp(k+1);
    for(int i=1;i<=k;i++){
        for(int j=0;j<n;j++){
            if(i>=a[j] && !dp[i-a[j]])
                dp[i]=true;
        }
    }
    if(dp[k]) cout<<"First";
    else cout<<"Second";
}


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

int n, k, i, j;
int h [100005];
int dp [100105];

int main ()
    {
    scanf ("%d%d",&n,&k);
    for (i=1; i<=n; i++)
        scanf ("%d",&h[i]);
    fill (dp+2, dp+n+1, 1000000001);
    for (i=1; i<=n; i++)
        for (j=1; j<=k; j++)
            dp[i+j]=min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
    printf ("%d\n",dp[n]);
    return 0;
    }


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
vector<int> pos;
int main(){
  string a,b;
  int i;
  cin>>a>>b;
  int l1=a.size(),l2=b.size();
  char ch=a[0];
  for(i=0;i<l2;i++)
    if(b[i]==ch)
      pos.push_back(i);
  i=0;
  while(i<pos.size()){
    int j=(pos[i]+1)%l2,s=1;
    while(s<l2){
      if(b[j]!=a[s]){
        break;
      }
      j=(j+1)%l2;
      s++;
    }
    if(s==l2){
      cout<<"Yes";
      return 0;}
    i++;
  }
  cout<<"No";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  string s[n];
  for(int i=0;i<n;i++) cin>>s[i];
  int op[n],cl[n];
  int op2[n],cl2[n];
  memset(op,0,sizeof(op));
  memset(cl,0,sizeof(cl));
  memset(op2,0,sizeof(op2));
  memset(cl2,0,sizeof(cl2));
  for(int i=0;i<n;i++){
    for(int j=0;j<(int)s[i].size();j++){
      if(s[i][j]=='(') op[i]++;
      else op[i]--;
      cl[i]=min(cl[i],op[i]);
    }
    for(int j=(int)s[i].size()-1;j>=0;j--){
      if(s[i][j]==')') op2[i]++;
      else op2[i]--;
      cl2[i]=min(cl2[i],op2[i]);
    }
  }
  int tmp=0;
  bool f=1;
  bool used[n];
  memset(used,0,sizeof(used));
  while(1){
    int idx=-1;
    for(int i=0;i<n;i++){
      if(used[i]) continue;
      if(tmp+cl[i]<0) continue;
      if(idx<0||op[idx]<op[i]) idx=i;
    }
    if(idx<0||op[idx]<0) break;
    tmp+=op[idx];
    used[idx]=1;
  }
  int tmp2=0;
  while(1){
    int idx=-1;
    for(int i=0;i<n;i++){
      if(used[i]) continue;
      if(tmp2+cl2[i]<0) continue;
      if(idx<0||op2[idx]<op2[i]) idx=i;
    }
    if(idx<0||op2[idx]<0) break;
    tmp2+=op2[idx];
    used[idx]=1;
  }
  //cout<<tmp<<" "<<tmp2<<endl;
  f&=tmp==tmp2;
  for(int i=0;i<n;i++) f&=used[i];
  //for(int i=0;i<n;i++) cout<<used[i];cout<<endl;
  //for(int i=0;i<n;i++) if(!used[i]) cout<<i<<":"<<s[i]<<" "<<op[i]<<" "<<cl[i]<<endl;
  cout<<(f?"Yes":"No")<<endl;
  return 0;
}

Measured memory_bytes: 3184
MOD = 1000000007

def main():
	n = int(input())
	a = list(map(int,input().split()))
	h = [-1,-1,-1]
	ans = 1
	for i in range(n):
		# print(i)
		ans = ans*h.count(a[i]-1) % MOD
		for j in range(3):
			if h[j] == a[i]-1:
				h[j] = a[i]
				break
	hn = h.count(-1)
	if hn == 0:
		if h[0] == h[1] and h[1] == h[2]:
			pass
		elif h[0] != h[1] and h[1] != h[2] and h[2] != h[0]:
			pass
		else:
			pass
	elif hn == 1:
		pass
	elif hn == 2:
		pass
	print(ans)

main()

Measured memory_bytes: 14396
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

signed main()
{
    int n;
    cin >> n;
    vi a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    sort(all(a));
    reverse(all(a));
    vector<ll> b;
    rep(i, n - 1)
    {
        if (a[i] == a[i + 1])
        {
            b.push_back(a[i]);
            i++;
        }
    }
    if (b.size() > 1)
    {
        cout << b[0] * b[1] << endl;
    }
    else
    {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 4252
#include <stdio.h>

int T[100];
int P[100];
int X[100];

int main(void) {
    int N, M;
    scanf("%d", &N);
    for (int i = 0; i < N; i ++) scanf("%d", &T[i]);
    scanf("%d", &M);
    for (int i = 0; i < M; i ++) scanf("%d %d", &P[i], &X[i]);
    int sum = 0;
    for (int i = 0; i < N; i ++) sum += T[i];
    for (int i = 0; i < M; i ++) {
        printf("%d\n", sum - T[P[i] - 1] + X[i]);
    }
}

Measured memory_bytes: 128
#include<cstdio>
#include<map>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=2000005;
int n;
int a[MAXN],b[MAXN],c[MAXN],d[MAXN];
map<int,int>f;
int fa[MAXN],cnt=0,ans=0;
int find(int x)
{
	if(x==fa[x])
		return x;
	return fa[x]=find(fa[x]);
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		a[n+1]^=a[i];
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);
		b[n+1]^=b[i];
	}
	n++;
	for(int i=1;i<=n;i++)
	{
		c[i]=a[i];
		d[i]=b[i];
	}
	sort(c+1,c+n+1);
	sort(d+1,d+n+1);
	for(int i=1;i<=n;i++)
	{
		if(c[i]!=d[i])
		{
			printf("-1\n");
			return 0;
		}
	}
	if(n==1)
	{
		printf("0\n");
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i]!=b[i]||i==n)
		{
			if(i!=n)
				ans++;
			if(!f[a[i]])
				f[a[i]]=++cnt;
			if(!f[b[i]])
				f[b[i]]=++cnt;
		}
	}
	for(int i=1;i<=cnt;i++)
		fa[i]=i;
	for(int i=1;i<=n;i++)
		if(a[i]!=b[i])
			fa[find(f[a[i]])]=find(f[b[i]]);
	for(int i=1;i<=cnt;i++)
		if(fa[i]==i)
			ans++;
	printf("%d\n",ans-1);
}

Measured memory_bytes: 17152
import numpy as np
N = int(input())
A = np.array(input().split(), dtype = np.int32)
B = np.array(input().split(), dtype = np.int32)

bit = 1 << 28
mask = 2 * bit - 1

ans = 0
while bit:
    A &= mask
    B &= mask
    A.sort()
    B.sort()
    x1, x2, x3 = (np.searchsorted(B, v - A).sum() for v in [bit, 2 * bit, 3 * bit])
    zero_cnt = x1 + (x3 - x2)
    if (N - zero_cnt) % 2:
        ans += bit
    bit >>= 1
    mask >>= 1

print (ans)



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

using namespace std ;

#define inf 0x3f3f3f3f
#define ll long long

ll n , s ;

ll f( ll b , ll n ) {
	return n < b ? n : f( b , n / b ) + n % b ;
}

int main() {
	scanf( "%lld%lld" , &n , &s ) ;
	if( s > n ) return puts( "-1" ) , 0 ;
	if( s == n ) return printf( "%lld\n" , n + 1 ) , 0 ;
	ll m = sqrt( n ) + 1 ;
	for( ll i = 2 ; i <= m ; i ++ ) {
		if( f( i , n ) == s ) 
			return printf( "%lld" , i ) , 0 ;
	}
	ll ans = 1e11 ; n -= s ;
	for( ll i = 1 ; i * i <= n ; i ++ ) {
		if( n % i == 0 ) {
			ll b = n / i + 1;
			if( f ( b , n + s ) ==  s ) ans = min ( ans , b ) ;
		}
	}
	printf( "%lld\n" , ans != 1e11 ? ans : -1 ) ;
	return 0 ;
} 

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;

int subordinates[200001];

int main()
{
    int N, i, A;

    scanf("%d", &N);
    memset(subordinates, 0, sizeof subordinates);
    for(i = 2; i <= N; ++i){
        scanf("%d", &A);
        ++subordinates[A];
    }
    for(i = 1; i <= N; ++i)
        printf("%d\n", subordinates[i]);

    return 0;
}


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

#ifdef DEBUG
#include "../include/debug.hpp"
#else
#define debug(...) 42
#endif

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

    int N;
    cin >> N;

    vector<long long> A(N);
    for (int i=0; i<N; ++i) cin >> A[i];
    sort(A.begin(), A.end());

    vector<long long> ac(N+1);
    ac[0] = 0;
    for (int i=0; i<N; ++i) {
        ac[i+1] = ac[i] + A[i];
    }

    int cnt = 1;
    for (int i=N-2; i>=0; --i) {
        if (A[i+1] <= ac[i+1]*2) {
            cnt ++;
        } else {
            break;
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 1792
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))
num = abs(A - T + H[0]*0.006)
ans = 1
for i in range(1,N):
    if num > abs(A-T+H[i]*0.006):
        num = abs(A-T+H[i]*0.006)
        ans = i+1
print(ans)

Measured memory_bytes: 9236
//reference to
//http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=1724480#1

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll r;
  ll n;
  while(cin >> r >> n ,r || n){
    vector<ll> a(45,0);
    ll l,u,h;
    rep(i,n){
      cin >> l >> u >> h; 
      l += 20;
      u += 20;
      REP(j,l,u){
        a[j] = max(a[j],h);
      }
    } 
    double ans = 11000;
    rep(i,40){
      int x=abs(i-20)+(i-20>=0?0:-1);
      if(x>=r)continue;
      double tmp=r-sqrt(1.0*(r*r-x*x));
      ans = min(ans,a[i]+tmp);
    }
    std::fcout(10) << ans << std::endl;
  }
  return 0;
}

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

using namespace std;

int main(){
  int n;
  cin >> n;
  bool flag=false;
  long long total;
  cin >> total;

  int a=0;
  int b=0;
  int c=0;

  if(total > n*10000){
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
  }
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
      if(total==10000*i+5000*j+1000*(n-i-j)){
        a=i;
        b=j;
        c=n-i-j;
        if(c<0){
          continue;
        }
        flag=true;
        break;
      }
    }
    if(flag){
      break;
    }
  }

  if(flag){
    cout << a << " " << b << " " << c << endl;
  }
  else{
    cout << -1 << " " << -1 << " " << -1 << endl;
  }


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
signed main() {
	int n, k; cin >> n >> k;
	int ans = 1;
	for (int i = 0; i < n; i++) {
		ans *= k;
		ans %= 1000000007;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3076
use std::io::prelude::*;

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

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

    println!("{}", a[n - 1] - a[0]);
}


Measured memory_bytes: 4476
#include <bits/stdc++.h>
#define il inline
#define RG register
#define ll long long
#define N (500005)

using namespace std;

vector<int> vec[26];

int f[N],g[26],n,ans;
char s[N];

il int gi(){
  RG int x=0,q=1; RG char ch=getchar();
  while ((ch<'0' || ch>'9') && ch!='-') ch=getchar();
  if (ch=='-') q=-1,ch=getchar();
  while (ch>='0' && ch<='9') x=x*10+ch-48,ch=getchar();
  return q*x;
}

int main(){
  scanf("%s",s+1),n=strlen(s+1);
  for (RG int i=n,res;i;--i){
    res=n; for (RG int j=0;j<26;++j) res=min(res,g[j]);
    f[i]=res+1,g[s[i]-'a']=f[i],vec[s[i]-'a'].push_back(i);
  }
  ans=n; for (RG int i=0;i<26;++i) ans=min(ans,g[i]);
  for (RG int i=ans;i;--i)
    for (RG int j=0,pos;j<26;++j)
      if (!vec[j].empty() && f[vec[j][vec[j].size()-1]]==i){
	putchar('a'+j),pos=vec[j][vec[j].size()-1];
	for (RG int k=0;k<26;++k)
	  while (!vec[k].empty() && vec[k][vec[k].size()-1]<=pos) vec[k].pop_back();
	break;
      }
  for (RG int i=0;i<26;++i) if (vec[i].empty()){ putchar('a'+i); break; } return 0;
}


Measured memory_bytes: 2304
#include <iostream>

int main()
{
    int n;

    std::cin >> n;

    int a[201] = {0};

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

    int count = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] == 8 && i % 2 == 1) {
            count++;
        }
    }

    std::cout << count << std::endl;

    return 0;
}


Measured memory_bytes: 504
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

int main(){
	int n, m, a, b, c;
	int visit[101][50];
	int step[50];
	while(cin >> n >> m >> a >> b >> c){
		vector< vector<int> > g(n);
		for(int i=0;i<m;i++){
			int p, q;
			cin >> p >> q;
			g[p-1].push_back(q-1);
		}
		vector< vector<int> > reachA(n), reachB(n), reachC(n);
		for(int i=0;i<n;i++){
			memset(visit, 0, sizeof(visit));
			visit[0][i] = 1;
			for(int j=0;j<100;j++){
				for(int k=0;k<n;k++){
					if(!visit[j][k]) continue;
					for(int& t : g[k]) visit[j+1][t] = 1;
				}
			}
			for(int j=0;j<n;j++){
				if(visit[a][j]) reachA[i].push_back(j);
				if(visit[b][j]) reachB[i].push_back(j);
				if(visit[c][j]) reachC[i].push_back(j);
			}
		}
		for(int i=0;i<n-1;i++) step[i] = 10000;
		step[n-1] = 0;
		while(true){
			bool update = false;
			for(int i=0;i<n;i++){
				int sa = 10000, sb = 10000, sc = 10000;
				for(int t : reachA[i]) sa = min(sa, step[t]);
				for(int t : reachB[i]) sb = min(sb, step[t]);
				for(int t : reachC[i]) sc = min(sc, step[t]);
				int nextStep = max(sa, max(sb, sc)) + 1;
				if(nextStep < step[i]){
					update = true;
					step[i] = nextStep;
				}
			}
			if(!update) break;
		}
		if(step[0] == 10000) cout << "IMPOSSIBLE" << endl;
		else cout << step[0] << endl;
	}
}

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

int N;
int main(){
    cin >> N;
    int res = N%10;
    if(res==2 || res==4 || res==5 || res== 7 || res == 9){
        cout << "hon" << endl;
    }else if(res==0 || res==1 || res==6 || res==8) cout << "pon" << endl;
    else cout << "bon" << endl;
    return 0;
    
}

Measured memory_bytes: 3036
/*
power code taken from geeks for geeks
*/
// cout << setprecision (2) << fixed << 1.2;

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;


const ll INF = 1e18 + 5;
const ll MAX_N = 1e5 + 5;
const ll MODD = 1e9 + 7;
const ld PI = 3.14159265358979323846;

ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
double max(double a,double b){return a>b?a:b;}
double min(double a,double b){return a<b?a:b;}

ll modd(ll a){if(a<0LL) return a*-1LL;return a;}
ld modd(ld a){if(a<0.0) return a*-1.0;return a;}

ll modulo(ll a){return (a + MODD) % MODD; }

ll power(ll k, ll p){
    if (p == 0)
        return 1LL;
 
    ll P = power(k, p/2LL);
    P = (P * P) % MODD;
 
    if (p % 2 == 1)
        P = (P * k) % MODD;
 
    return P;
}


struct p_str {
    ll a, b;
};



void solve() {
    ll k;
    cin >> k;


    ll num = 7;
    for(ll i = 1; i <= k + 1; i++) {
        if(num % k == 0) {
            cout << i << endl;
            return;
        }
        num = ((num * 10LL) % k + 7LL) % k;
        num = num % k;

        // cout << "num " << num << endl;
    }
    cout << "-1\n";
}


int main(){


  


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

    ll t=1;

    // cin>>t;


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

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>

using namespace std;

int main() {
  int h,w;
  cin >> h >> w;
  vector<vector<int>> a(h, vector<int> (w,0));
  vector<string> ans;

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

  for (int i=0; i<h; i++) {
    bool isodd = (accumulate(a[i].begin(),a[i].end(),0L) %2);
    for (int j=0; j<w; j++) {
      if (isodd && a[i][j]%2 && i+1<h ) {
        a[i+1][j]++;

        ans.push_back(
        to_string(i+1) + " " + to_string(j+1) + " " +
        to_string(i+2) + " " + to_string(j+1));
        isodd = false;
        continue;
      }

      if (a[i][j]%2 && j+1<w) {
        a[i][j+1]++;
        ans.push_back(
        to_string(i+1) + " " + to_string(j+1) + " " +
        to_string(i+1) + " " + to_string(j+2));
      }
    }

  }

  cout << ans.size() << endl;
  for (auto s : ans) {
    cout << s << endl;
  }
}

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

const int MAXN = 1e5+10;
int n, st[MAXN]; // 0 is ???, 1 is male, 2 is female

set<int> unq;
map<int, int> qs;
int query(int i) {
	if (qs.count(i)) return qs[i];
	unq.erase(i);
	cout << i <<endl;
	string s;
	cin >> s;
	if (s[0] == 'V') exit(0);
	if (s[0] == 'M') return qs[i] = st[i] = 1;
	return qs[i] = st[i] = 2;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for(int i=0;i<n;i++) unq.insert(i);
	srand(999420);
	int q0 = query(0);
	int q1 = query(n-1);
	int lo = 0, hi = n-1; // double inclusive ? 
	while(true) {
		int guess = (lo+hi)/2;
		//cerr << " " << lo << " " << hi << " " << guess << endl;
		auto closeit = unq.lower_bound(guess);
		if (*closeit > hi) closeit--;
		guess = *closeit;
		query(guess);
		auto it = qs.lower_bound(guess);
		auto pit = it;
		auto nit = it;
		pit--;
		nit++;
		if (abs(nit->second - it->second)%2 != abs(nit->first-it->first)%2) {
			lo = it->first;
			hi = nit->first;
		}
		if (abs(pit->second - it->second)%2 != abs(pit->first-it->first)%2 && 
				it->first - pit->first < hi-lo) {
			lo = pit->first;
			hi = it->first;
		}
	}
}


Measured memory_bytes: 5588
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll N, ans;
    char C;
    scanf("%s", &C);
    C++;
    cout << C << endl;
    return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	vector<vector<int>> d(c, vector<int>(c));
	for (int i = 0; i < c; i++) {
		for (int j = 0; j < c; j++) {
			cin >> d[i][j];
		}
	}

	vector<vector<int>> a(n, vector<int>(n));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
			--a[i][j];
		}
	}

	//塗り替える先の色を決めて、集める
	//a[j][k]を決めた色にするのはd[a[j][k]][i]
	//全てのaの要素について、(i+j)%3で分類して集める

	vector<vector<int>> cost(3, vector<int>(c));
	for (int i = 0; i < c; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				cost[(j+k) % 3][i] += d[a[j][k]][i];
			}
		}
	}

	int res = INF;

	//(i+j)%3の余り0,1,2の類に対して
	//色の割当てを全探索

	for (int c1 = 0; c1 < c; c1++) {
		for (int c2 = 0; c2 < c; c2++) {
			for (int c3 = 0; c3 < c; c3++) {
				if (c1==c2 || c2==c3||c1==c3)continue;
				int cnt = 0;

				cnt += cost[0][c1];
				cnt += cost[1][c2];
				cnt += cost[2][c3];

				res = min(res, cnt);
			}

		}

	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
#define SG getchar()
#define P putchar
using namespace std;
signed main()
{
	while(1){char c(SG);if(c-10){P(c);}else{break;}if(!(SG-10)){break;}}
	return putchar(10),0;
}

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

int main()
{
    int q,t,f;
    char w;
    string ws;
    bool b;
    deque<char> s;
    cin >> ws >> q;
    for(auto c:ws)s.push_back(c);
    rep(i, q)
    {
        cin >> t;
        if (t == 2)
        {
            cin >> f >> w;
            if(b) f=3-f;
            if (f == 1)
                s.push_front(w);
            else{
                s.push_back(w);
            }
        }
        else b=!b;
    }
    if(b) reverse(s.begin(),s.end());
    string ans;
    for(auto a:s){
        ans += a;
    }
    cout <<ans << endl;
}


Measured memory_bytes: 1412
#include<stdio.h>

long x[100005];
long y[100005];
long flag[100005];

int main(){
	long n, m, i;
	scanf("%ld%ld", &n, &m);
	for(i = 0 ; i < m; i++) scanf("%ld%ld", &x[i], &y[i]);
	
	long nbox[100005] = {0};
	for(i = 0; i < n; i++) nbox[i] = 1;	
	
	flag[0] = 1;
	for(i = 0; i < m; i++){
		if(nbox[x[i]-1] >= 1){
			nbox[x[i]-1]--;
			nbox[y[i]-1]++;
			
			if(flag[x[i]-1] == 1 && flag[y[i]-1] == 0)
				flag[y[i]-1] = 1;
			if(nbox[x[i]-1] == 0) flag[x[i]-1] = 0;
			
		}
	}
	 
	long tbox = 0;
	for(i = 0; i < n; i++) if(flag[i] == 1) tbox++;
	printf("%ld\n", tbox);	
	return 0;
}

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

ll fcount(ll arr[], ll n, int b, ll val[])
{
	ll c=0;
	ll diff=0;
	for(ll i=0;i<n;i++)
	{	
		if(arr[i]+diff==0)
		{
			if(b==1){
				//arr[i]+=1;
				diff +=1;
				c +=1;
			}
			else{
				//arr[i]-=1;
				diff -=1;
				c+=1;
			}
			//b=(b+1)%2;
		}
		else if(arr[i]+diff>0&&b==0)
		{
			ll temp=diff;
			diff -= (arr[i]+diff+1);
			c += arr[i]+temp+1;
			//b=(b+1)%2;
		}
		else if(arr[i]+diff<0&&b==1)
		{
			ll temp = diff;
			diff +=-(arr[i]+diff)+1;
			c += -(arr[i]+temp)+1;
			//b=(b+1)%2;

		}
	//	else
		b=(b+1)%2;
	//	cout<<diff<<" "<<b<<" "<<c<<"\n";
	}
	//cout<<"\n";
	return c;
}

int main()
{
	ll n;
	cin>>n;
	ll arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	ll c=0;
	ll diff=0,b=-1;
	ll prefix[n];
	prefix[0]=arr[0];
	for(int i=1;i<n;i++)
	{
		prefix[i]=prefix[i-1]+arr[i];
	}
	//for(int i=0;i<n;i++)
		//cout<<prefix[i]<<" ";
	//cout<<"\n";
	cout<<min(fcount(prefix,n,1,arr),fcount(prefix,n,0,arr))<<"\n";

}

Measured memory_bytes: 5196
#include <bits/stdc++.h>
typedef long long       ll;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define fore(i, b, e)      for(int i = b; i < e; i++)
#define forr(i, b, e)      for(int i = b; i < e; i++)
#define forg(i, b, e, m)  for(int i = b; i < e; i+=m)
#define F first
#define S second
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;

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

typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int INF = int(1e9 + 7);
const double PI = acos(-1);
const double EPS = 1e-9;
#define tam 1234567

int main()
{
    char chr;
    int cond=0;
   forr(i,0,3)
   {
    cin>>chr;
    if (chr=='A')
        cond|=1;
    else
        cond|=2;
   }
   if (cond==3)
    cout<<"Yes\n";
    else
    cout<<"No\n";

}
// PLUS ULTRA!

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int D[200010];
    rep(i, N) cin >> D[i];
    map<int, int> mp;
    rep(i, N) mp[D[i]]++;
    int M; cin >> M;
    rep(i, M) {
        int t; cin >> t;
        mp[t]--;
        if(mp[t] < 0) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}


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

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

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let n:i64 = read();
    let an = read_vec::<i64>();
    let mut ans:Vec<(_,_)> = an.into_iter().fold(HashMap::new(),|mut map ,x|{
        let y = map.get(&x).map(|i| i+1).unwrap_or(1);
        map.insert(x,y);
        map
    }).into_iter().collect::<Vec<(_,_)>>()
    .into_iter()
    .filter(|x| x.1 >= 2)
    .collect();
    if ans.len() < 2 {
        println!("0");
        return;
    }
    ans.sort_by_key(|x| x.0);
    if ans.iter().enumerate().any(|(i,x)| x.1 >= 4 && i == ans.len()-1 ){
        println!("{}",ans.last().unwrap().0 * ans.last().unwrap().0);
        return;
    }
    println!("{}",ans.last().unwrap().0 * ans[ans.len()-2].0);
}

Measured memory_bytes: 12756
import numpy as np

D=int(input())
*c,=map(int,input().split())
c=np.array(c,dtype=int)
s=[]
for i in range(D):
    *x,=map(int,input().split())
    s.append(x)

s=np.array(s,dtype=int).reshape((D,26))
dt=[]
cnt=np.array([0]*26)

for d in range(D):
    y=np.argmax(c*(d-cnt))
    cnt[y]=d+1
    dt.append(y+1)

for i in dt:
    print(i)


Measured memory_bytes: 27348
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    String s, p;
    char[] sch, pch;
    int i, j, n, sm, pm;

    s = sc.next();
    p = sc.next();
    sm = s.length();
    pm = p.length();
    sch = new char[sm];
    pch = new char[pm];
    for(i = 0;i < sm;i++){
      sch[i] = s.charAt(i);
    }
    for(i = 0;i < pm;i++){
      pch[i] = p.charAt(i);
    }

    n = 0;
    for(i = 0;i < sm;i++){
      n = 0;
      for(j = 0;j < pm;j++){
        if(sch[(i + j) % sm] == pch[j]){
          n++;
        }
      }
      if(n == pm)break;
    }

    if(n != pm){
      System.out.println("No");
    }else{
      System.out.println("Yes");
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 17324
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

int main()
{
    string s;
    cin >> s;
    int k = 0;
    char pre = s[0];
    int cnt = 1;
    bool two = false;
    while(true){
        if(cnt > s.size()) break;
        if(two || pre != s[cnt]){
            k++;
            pre = s[cnt];
            cnt++;
            two = false;
        }else{
            two = true;
            k++;
            cnt+=2;
        }
    }
    cout << k;
}


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

int main(void){
    int n,m;
    cin>>n>>m;
    vector<vector<int> > A(110,vector<int>(110));
    vector<int> b(110),ans(110);
    
    
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>A.at(i).at(j);
        }
    }
    for(int i=0;i<m;i++){
        cin>>b.at(i);
    }
    
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            ans.at(i)+=A.at(i).at(j)*b.at(j);
        }
        cout<<ans.at(i)<<endl;
    }
    
}



Measured memory_bytes: 3196
import java.util.Scanner;

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

        while (true) {
            int n = inScanner.nextInt();
            int p = inScanner.nextInt();

            if (n == 0 && p == 0) {
                break;
            }

            int[] ninzu = new int[n];
            int i = 0;
            while (!isWin(ninzu) || p > 0) {
                if (i >= n) {
                    i = 0;
                }

                if (p <= 0) {
                    p += ninzu[i];
                    ninzu[i] = 0;
                }
                else {
                    p -= 1;
                    ninzu[i] += 1;
                }
                i++;
            }

            System.out.println(i -1);
        }
    }

    public static boolean isWin(int[] son) {
        int ii = 0;
        for (int i = 0; i < son.length; i++) {
            if (son[i] != 0) {
                ii++;
            }
        }

        if (ii == 1)
            return true;
        else
            return false;
    }
}

Measured memory_bytes: 27044
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int n,m,b;
  cin >> n >> m>>b;

  cout << n*m/2 << endl; 
  return 0;
}


Measured memory_bytes: 256
// AtCoder template
// 見た奴全員saba!
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

vector<vector<int>> graph(8);
int ans = 0;
bool visited[8];
int n;
int dfs(int now, int depth){
    visited[now] = true;
    if(depth == n) return 1;
    int ret = 0;
    rep(i,graph[now].size()){
        int next = graph[now][i];
        if(visited[next] || next == 0) continue;
        ret += dfs(next, depth+1);
        visited[next] = false;
    }
    return ret;
}

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

    int m; cin >> n >> m;
    
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    
    
    rep(i,n) visited[i] = false;
    ans += dfs(0,1);
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//V,P(大文字)使用不可

const ll INF=1000000000000000000;

ll dp[110][2][110];

signed main(){
    string s;
    cin>>s;
    ll k;
    cin>>k;
    ll m=s.size();
    V<int> n;
    for(auto a:s) n.push_back(a-'0');
    dp[0][0][0]=1;
    for(int i=0;i<m;i++){
        for(int smaller=0;smaller<2;smaller++){
            for(int j=0;j<=k;j++){
                if(dp[i][smaller][j]==0) continue;
                if(smaller==0){
                    for(int l=0;l<=n[i];l++){
                        if(l==0){
                            if(n[i]!=0) dp[i+1][1][j]+=dp[i][smaller][j];
                            else dp[i+1][0][j]+=dp[i][smaller][j];
                        }else if(l<n[i]) dp[i+1][1][j+1]+=dp[i][smaller][j];
                        else{
                            if(n[i]==0) dp[i+1][0][j]+=dp[i][smaller][j];
                            else dp[i+1][0][j+1]+=dp[i][smaller][j];
                        }
                    }
                }else{
                    for(int l=0;l<=9;l++){
                        if(l) dp[i+1][1][j+1]+=dp[i][smaller][j];
                        else dp[i+1][1][j]+=dp[i][smaller][j];
                    }
                }
            }
        }
    }
    cout<<dp[m][0][k]+dp[m][1][k]<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

typedef double LD;
typedef long long ll;
typedef pair<ll, ll> PII;
typedef pair<LD, LD> PDD;
typedef vector<ll> VI;
typedef vector<PII> VPII;
typedef vector<VI> VVI;
#define MP make_pair
#define	pb push_back
#define x first
#define y second
#define next fake_next

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(ll i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i, 0, t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (ll)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define count jaskdasbj
const LD PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000;
ll gcd(ll a , ll b)
{
	if(!a)
		return b;
	return gcd(b % a , a);
}
int main()
{
	//freopen("input.txt" , "r" , stdin);
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int T;
	cin >> T;
	while(T--)
	{
		//cout << "Test: ";
		ll A , B , C , D;
		cin >> A >> B >> C >> D;
	//	cout << A << " " << B << " " << C << " " << D << endl;
		if(A < B)
		{
			cout << "No" << endl;
			continue;
		}
		if(B > D)
		{
			cout << "No" << endl;
			continue;
		}
		if(B <= C + 1)
		{
			cout << "Yes" << endl;
			continue;
		}

		A %= B;
		D %= B;

		ll x = gcd(D , B);
		ll prevA = A;
		A += ((B - A) / x) * x;
		if((B - A) % x == 0 && A != prevA)
		{
			A -= x;

		}
		if(A > C)
		{
			cout << "No" << endl;
		}
		else
			cout << "Yes" << endl;

	}


	return 0;
}


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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  ll a; cin >> a;
  cout << a * a * a + a * a + a << endl;
}


Measured memory_bytes: 3580
#include <iostream>
#include<stdio.h>
#include<string.h>
int count = 0;

int main() {
    char S[200000];
    int count[2019];

    for(int i = 0; i < 2019;++i){
        count[i] = 0;
    }

    scanf("%s",S);

    int num = strlen(S);
    int ruiseki[num + 1];
    ruiseki[num] = 0;
    int digit = 1;


    for(int i = num - 1; i >= 0; i--){
        ruiseki[i] = (ruiseki[i + 1] + digit *(S[i] - '0'))% 2019;
        digit = digit * 10%2019;
    }
    for(int i = 0; i < num + 1;i ++){
        count[ruiseki[i]]++;
    }

    int ans = 0;
    for(int i = 0; i < 2019; i++){
        ans += (count[i]-1)*count[i]/2;
    }
    printf("%d",ans);
    return 0;


}



Measured memory_bytes: 4792
//F5で実行 Shift+F5で停止
//F9でブレークポイント
#include<cmath>
#include<bits/stdc++.h>
#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 fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
//Shift+PageUpで上部の大半を選択できる
// 1e18 = 10の18乗

int N;
int A[100];
int K, M;
string S;
bool ok = false;
string ans;

//ｎ科目のテスト、ｋ点満点、目標ｍ点以上
//ｎ－１科目のテストはすでに受けて、Ai点だった。
//あと１科目のテストが何点なら、平均点がｍ点以上になるか
void _main() {
	cin >> N;

	//１～９
	rep(i, 1, 10) {
		rep(j, 1, 10) {
			if (N % i == 0 && N / i == j) {
				ok = true;
			}
		}
	}


	cout << (ok ? "Yes":"No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using l1 = long long;
#define rep(i,n) for(int i=0,i<(n);++i)
int main(){
    l1 a,b,c,k;
    cin>>a>>b>>c>>k;
    l1 ans=0;
    if(a>=k){
        cout<<k;
        return 0;
    }else{
        ans+=a;
        k-=a;
    }

    if(b>=k){
        cout<<ans;
        return 0;
    }else{
        k-=b;
    }

    cout<<ans-k;
    return 0;
}

Measured memory_bytes: 3596
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

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

        int n = sc.nextInt();
        int k = sc.nextInt();
        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < k; i++) {
            int d = sc.nextInt();
            for (int j = 0; j < d; j++) {
                set.add(sc.nextInt());
            }
        }

        System.out.println(n - set.size());
    }
}

Measured memory_bytes: 46184
#include <iostream>

using namespace std;

int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  int N, M;
  int n[50] = {};
  cin >> N >> M;
  for (int i=0; i<M; ++i) {
    int a, b;
    cin >> a >> b;
    ++n[a-1];
    ++n[b-1];
  }
  for (int i=0; i<N; ++i) cout << n[i] << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
    int n,m;cin>>n>>m;
    vector<vector<char>> vn(n,vector<char>(n));
    vector<vector<char>> vm(m,vector<char>(m));
    rep(i,n)rep(j,n)cin>>vn[i][j];
    rep(i,m)rep(j,m)cin>>vm[i][j];
    rep(i,n-m+1)rep(j,n-m+1){
        bool flag=true;
        rep(x,m)rep(y,m)if(vn[x+i][y+j]!=vm[x][y])flag=false;
        if(flag==true){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
ll n,x,ans = 0;
ll solve(ll a, ll b){
    if(b==0){
        ans -= a;
        return ans;
    }
    ans += a/b*2*b;
    solve(b,a%b);
}

int main(){
    cin >> n >> x;
    ans += n;
    solve(max(x,n-x),min(x,n-x));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fast_io {cin.sync_with_stdio(0); cout.sync_with_stdio(0);}
#define out(x,y) {cout<<x<<y;}
using ll = int;


int main(){
	fast_io;
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll  i = 0;
	while(true){
		if(i%2==0){
			c = c-b;
			if(c<=0)break;
		}
		else{
			a = a-d;
			if(a<=0)break;
		}
		i++;
	}
	if(i%2==0){
		cout<<"Yes\n";
	}
	else cout<<"No\n";
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>

using namespace std;

const int H_MAX = 505;
const int W_MAX = 505;

int f[H_MAX][W_MAX];

int main() {
    int H, W;

    cin >> H >> W;

    vector< int > y_src, x_src, y_dst, x_dst;

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> f[i][j];
        }
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W - 1; j++) {
            bool flag = false;
            if (!flag && f[i][j] % 2 != 0) {
                flag = true;
            } else if (flag && f[i][j] % 2 == 0) {
                flag = false;
            }

            if (flag) {
                f[i][j]--;
                f[i][j + 1]++;
                y_src.push_back(i);
                x_src.push_back(j);
                y_dst.push_back(i);
                x_dst.push_back(j + 1);
            }
        }
    }

    for (int i = 0; i < H - 1; i++) {
        bool flag = false;
        if (!flag && f[i][W - 1] % 2 != 0) {
            flag = true;
        } else if (flag && f[i][W - 1] % 2 == 0) {
            flag = false;
        }

        if (flag) {
            f[i][W - 1]--;
            f[i + 1][W - 1]++;
            y_src.push_back(i);
            x_src.push_back(W - 1);
            y_dst.push_back(i + 1);
            x_dst.push_back(W - 1);
        }
    }

    cout << y_src.size() << endl;
    for (int i = 0; i < y_src.size(); i++) {
        cout << y_src[i] + 1 << " " << x_src[i] + 1 << " ";
        cout << y_dst[i] + 1 << " " << x_dst[i] + 1 << endl;
    }

    // int cnt = 0;
    // for (int i = 0; i < H; i++) {
    //     for (int j = 0; j < W; j++) {
    //         if (f[i][j] % 2 != 0) cnt++;
    //     }
    // }

    // cout << cnt << endl;
}


Measured memory_bytes: 5220