akhauriyash/Code-Regression huggingface dataset:
def big_array(N: int, K: int, queries: list)->int:
    d = {}
    for a, b in queries:
        d.setdefault(a, 0)
        d[a] += b

    count = 0
    ans = 0
    for k, v in sorted(d.items()):
        count += v
        if K <= count:
            ans = k
            break
    return ans


if __name__ == "__main__":
    N = 0
    N, K = map(int, input().split())
    queries = [tuple(map(int, input().split())) for _ in range(N)]
    ans = big_array(N, K, queries)
    print(ans)


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

int main() {
  //入力
  int N, M;
  cin >> N >> M;

  vector<int> count(M, 0);
  for (int i = 0; i < N; i++) {
    int K;
    cin >> K;
    for (int j = 0; j < K; j++) {
      int A;
      cin >> A;
      A--;
      ++count[A];
    }
  }
  //処理
  int ans = 0;
  for (int i = 0; i < M; i++) {
    if (count[i] == N) {
      ans++;
    }
  }
  //出力
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import sys
from functools import lru_cache
sys.setrecursionlimit(10 ** 7)
@lru_cache(maxsize=None)
def dfs(N,A,B,C,D):
  ans=N*D
  for x, y in [(2, A), (3, B), (5, C)]:
    if N%x==0:
      N0=N//x
      a=dfs(N0,A,B,C,D)+y
      ans=min(a,ans)
    elif x<=N:
      z=N%x
      N0=(N-z)//x
      N1=(N-z+x)//x
      a=dfs(N0,A,B,C,D)+z*D+y
      b=dfs(N1,A,B,C,D)+((x-z)*D)+y
      ans=min(a,b,ans)
  return ans
T=int(input())
for _ in range(T):
  N,A,B,C,D=map(int,input().split())
  print(dfs(N,A,B,C,D))

Measured memory_bytes: 29712
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str;
        StringBuilder sb = new StringBuilder();
        int m,f,r;
        while(true){
            str = br.readLine().split(" ");
            m = Integer.parseInt(str[0]);
            f = Integer.parseInt(str[1]);
            r = Integer.parseInt(str[2]);
            if(m == -1 && f == -1 && r == -1) break;
            if(m == -1 || f == -1){
                sb.append("F\n");
            }else if(m+f >= 80){
                sb.append("A\n");
            }else if(65 <= m+f){
                sb.append("B\n");
            }else if(50 <= m+f){
                sb.append("C\n");
            }else if(30 <= m+f){
                if(r >= 50) sb.append("C\n");
                else sb.append("D\n");
            }else{
                sb.append("F\n");
            }
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 24180
program ABC156C
    implicit none
    integer(8)::N,i,j,hp_min,hp
    integer(8),allocatable,dimension(:)::X
    read(5,*)N
    allocate(X(N))
    read(5,*)(X(i),i=1,N)

    hp_min=1000000000
    do i=minval(X),maxval(X)
        hp=0
        do j=1,N
            hp=hp+(X(j)-i)**2
        end do
        hp_min=min(hp_min,hp)
    end do

    print'(i0)',hp_min
end program ABC156C

Measured memory_bytes: 768
a,b,c,d,n,*A=`dd`.split.map &:to_i;e=f=1;a>c&&(a,c,e=c,a,-1);b>d&&(b,d,f=d,b,-1);V=[];A.each_slice(2){|x,y|(a..c)===x&&(b..d)===y&&V<<[x*e,y*f]};D=[];n=-1;V.sort.map{|x,y|D[D.bsearch_index{|e|e>y}||n+=1]=y};n+=1;p 1e2*(c-a+d-b)-20*n+5*(n+(n>[c-a,d-b].min ? 1:0))*Math::PI

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

int main() {
    int N;
    cin >> N;
    rep(i, N){
        int a;
        cin >> a;
        if(a % 2 == 0){
            if(a % 3 != 0 && a % 5 != 0){
                cout << "DENIED";
                return 0;
            }
        }
    }
    cout << "APPROVED";
}


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

int main(void)
{
    int n;
    cin >> n;
    int i = 1;
    while(true)
    {
        int x = i;
        if(x % 3 == 0)
        {
            cout << " " << i;
        }
      	else
        {
        	while(true)
        	{
            	if(x % 10 == 3)
            	{
                	cout << " " << i;
                	break;
            	}
            	x /= 10;
            	if(!(x))break;
        	}
        }
        if(!(++i <= n))break;
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3116
//Author : Sukarna Paul

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1)
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;




int main(){
    IOS
    //freopen("output.txt","w",stdout);
    string s;
    cin>>s;
    int len=s.length();
    //cout<<s[len/2];
    string s1(s.begin(),s.begin()+len/2);
    string s3(s1.rbegin(),s1.rend());
    string s2(s.begin()+len/2 +1,s.end());
    string s4(s2.rbegin(),s2.rend());
    //cout<<s1<<" "<<s2;
    //cout<<s3<<" "<<s4;
    string sp(s.rbegin(),s.rend());
    if(s1==s3 && s2==s4 && s==sp){
        cout<<"Yes\n";

    }
    else{
        cout<<"No\n";
    }

}


Measured memory_bytes: 256
#include <iostream>

int main()
{
  int k, a, b;
  std::cin >> k >> a >> b;
  std::string res = "NG";
  
  for(std::size_t i = a; i <= b; ++i)
  {
    if((i % k) == 0)
    {
      res = "OK";
      break;
    }
  }
  std::cout << res;
  return 0;
}

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

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#endif

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;i++)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;i++)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

#define int ll

main()
{
  vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
  while(1){
    int h,w; cin >> w >> h;
    if(h == 0) break;

    vvi d(h,vi(w,-1)), in(2*h-1,vi(w));
    rep(i,sz(in)){
      if(i & 1) rep(j,w) cin >> in[i][j];
      else rep(j,w-1) cin >> in[i][j];
    }

    queue<pii> q;
    q.push(pii(0,0));
    d[0][0] = 0;

    while(not q.empty()){
      pii p = q.front();
      q.pop();

      rep(i,4){
	int nx = p.fst + dx[i], ny = p.snd + dy[i];
	if(0 <= nx and nx < h and 0 <= ny and ny < w and d[nx][ny] == -1){
	  dump(nx,ny);
	  bool f = true; // 移動できるかどうか
	  
	  if(p.fst == nx and in[2 * nx][min(p.snd, ny)] == 1) // y方向
	    f = false;
	  else if(p.snd == ny and in[p.fst + nx][ny] == 1) // x方向
	    f = false;
	    
	  if(f){
	    d[nx][ny] = d[p.fst][p.snd] + 1;
	    q.push(pii(nx,ny));
	  }
	}
      }
    }
    dump(d);
    cout << d[h-1][w-1] + 1 << endl;
  }
}



Measured memory_bytes: 3144
#include<stdio.h>

void call(int);

int main(){
  int n;
  scanf("%d", &n);

  call(n);
  return 0;
}

void call(int n){
  int i;
  int x;

  for(i = 1; i <= n; i++){
    x = i;
    if(x % 3 == 0){
      printf(" %d", i);
    }
    else if(x % 10 == 3){
      printf(" %d", i);
    }
    else {
      while(x != 0){
	if(x % 10 == 3){
	  printf(" %d", i);
	  break;
	}
	x /= 10;
      }
    }
  }

  printf("\n");
}


Measured memory_bytes: 2128
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }

int main() {
    ll n,x;
    cin >> n >> x;
    vector<ll> a(n,0);
    rep(i,n)cin >> a.at(i);
    sort(a.begin(),a.end());
    ll ans = 0;
    rep(i,n){
        if(x - a.at(i) >= 0){
            ans++;
        }
        x -= a.at(i);
    }
    if(x > 0)--ans;
    cout << max(ans,0LL) << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
int copy(int x){
	return x;
}

int main(){
	int n;cin>>n;
	vector<vector<int>> a(n);
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n - 1; j++) {
			int x;cin>>x;x--;a[i].pb(x);
		}
		a[i].pb(-1);
	}
	vector<int> now(n);
	vector<int> cnt(n,0);
	vector<bool> used(n,false);
	queue<int> q;
	for(int i = 0; i < n; i++) {
		now[i] = a[i][0]; 
		q.push(i);
	}
	int i = 0;
	int ans = 0;
	while(i <= n * (n - 1) / 2){
		i++;
		bool flag = true;
		int q_size = q.size();
		int j = 0;
		while(j < q_size) {
			int top = q.front();
			q.pop();
			if (now[top] != -1 && now[now[top]] == top && used[now[top]] == false && used[top] == false){//やりたい同士のとき
				int tmp = copy(now[top]);
				cnt[top]++;
				cnt[tmp]++;
				now[top] = a[top][cnt[top]];
				now[tmp] = a[tmp][cnt[tmp]];
				used[top] = true;
				used[tmp] =true;
				q.push(top);
				q.push(tmp);
				// for(int i = 0; i < n; i++) {
				// 	cout << now[top] << endl;
				// }
			}
			j++;
		}
		for(int i = 0; i < n; i++) {
				used[i] = false;
			}
			for(int i = 0; i < n; i++) {
				if (now[i] != -1){
					flag = false;
				}
			}
			ans++;
			if (flag){
				cout << ans << endl;
				return 0;
			}
		
	}
	
	for(int i = 0; i < n; i++) {
		if (now[i] != -1){
			cout << -1 << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 6400
n,m=map(int,input().split())
s=input() ;a=len(s)
t=input() ;b=len(t)
def gcd(a,b):
    if b==0: return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return a*b//gcd(a,b)
L=lcm(len(s),len(t))

d={}
now=0
for i in range(0,L,L//a):
    d[i]=s[now]
    now+=1
now=0
for j in range(0,L,L//b):
    if d.get(j, t[now])!=t[now]:
        print(-1);exit()
    now+=1
print(L)

Measured memory_bytes: 91648
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nkq = readln.split.to!(long[]);
    auto N = nkq[0];
    auto K = nkq[1];
    auto Q = nkq[2];
    int[] as;
    as.length = N;
    foreach (_; 0..Q) {
        ++as[readln.chomp.to!int - 1];
    }
    foreach (a; as) {
        writeln(K - (Q - a) > 0 ? "Yes" : "No");
    }
}

Measured memory_bytes: 3964
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=100000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int n,m;
char s[N],t[N];

int main()
{
    n=read();m=read();
    scanf("%s%s",s+1,t+1);
    int d=__gcd(n,m),ok=1,d1=n/d,d2=m/d;
    rep(i,1,d)
    {
        int p1=(i-1)*d1+1,p2=(i-1)*d2+1;
        if (s[p1]!=t[p2]) {ok=0;break;}
    }
    if (ok) printf("%lld",1ll*n*m/d);
    else puts("-1");
    return 0;
}

Measured memory_bytes: 3864
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> N(n);
    for(int i=0;i<n;i++) cin>>N[i];
    int ans=0;
    vector<int> C(n);
    for(int i=0;i<n;i++) C[N[i]-1]=i+1;
    int ptr = 0;
    long cc;
    while (ptr < n) {
        cc = C[ptr];
        int e = 0;
        while (ptr < n&&C[ptr]>=cc){
            cc=C[ptr];
            e++, ptr++;
       }
        if(ans<e) ans=e;
    }
    cout<<n-ans;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    int h_;
    cin >> h_;
    h[i] = h_;
  }
  vector<int> dp(n);
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  for (int i = 2; i < n; i++) {
    dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
  }
  cout << dp[n - 1] << '\n';
  return 0;
}

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

typedef long long ll;
const int mod = 1000000007;
const int MAX_N = 100005;

ll fact[MAX_N];         // 階乗
ll ifact[MAX_N];        // 階乗の逆元

// x^nを求める繰り返し二乗法(累乗の高速化)
// フェルマーの小定理より、逆元を計算するときに用いる。
ll mod_pow(ll x, int n){
    if(n == 0)      return 1;

    ll res = 1;
    while(n > 0){
        if(n & 1)   res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }

    return res;
}

// 階乗とその逆元テーブルを(0-n)まで埋める
void table(int n){
    fact[0] = 1;    // i^0 = 1;
    for(int i = 1; i <= n; ++i){
        fact[i] = fact[i - 1] * i % mod;
    }

    // フェルマーの小定理を利用して、右端の逆元を求める
    // 階乗の(mod-2)乗
    ifact[n] = mod_pow(fact[n], mod - 2);

    // 逆元の性質を利用して、テーブルを埋める
    for(int i = n; i >= 1; --i){
        ifact[i - 1] = ifact[i] * i % mod;
    }
}

// nCrを求める
ll combination(int n, int r){
    if(n < 0 || r < 0 || n < r)     return 0;

    return fact[n] * ifact[r] % mod * ifact[n - r] % mod;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, id1 = 0, id2 = 0;
    cin >> n;
    vector<int> a(n+1), cnt(n+1, 0);
    for(int i = 0; i < n+1; ++i){
        cin >> a[i];
        ++cnt[a[i]];
        
        if(cnt[a[i]] == 2)      id2 = i;   
    }
    for(int i = 0; i < n+1; ++i){
        if(a[i] == a[id2]){
            id1 = i;
            break;
        }
    }
    
    table(n+2);
    
    // 重複している数字をxとして、xの左にある数字の個数
    // a = [...x.....x...]
    int num1 = id1;
    // xの右側にある数字の個数
    int num2 = n - id2;

    // 重複している数字：x
    for(int i = 1; i <= n+1; ++i){        // 数字をi個取る
        ll res = (ll)(combination(n + 1, i) - combination(num1 + num2, i - 1) + 2 * mod) % mod;
        
        cout << res << "\n";
    }
}

Measured memory_bytes: 3584
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<iomanip>
#include<vector>
#define rep(i,n) for(ll i=0;i<(n);i++)
using namespace std;
using ll=long long;



int main(){
	const ll M = 100000;
	ll n, m,ans=0,tmp=0,t=0;
	pair<ll,ll> p[M];

	cin >> n >> m;
	rep(i, n)cin >> p[i].first >> p[i].second;
	sort(p, p + n);
	
	for (t = 0; t < n; t++) {
		if (tmp >= m)break;
		tmp += p[t].second;
	}
	rep(i, t)ans += p[i].first*p[i].second;
	ans -= p[t - 1].first*(tmp-m);

	cout << ans;
}

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

using namespace std;

int n, m;
int step[1001][1001];
char s[2];
int ans;

int di[4] = {-1, 0, 1, 0};
int dj[4] = {0, 1, 0, -1};

ifstream fin("date.in");

queue < pair <int, int> > coada;

bool OK(int i,int j)
{
    if (i < 1 || i > n)
        return false;
    if (j < 1 || j > m)
        return false;
    if (step[i][j] != -1)
        return false;
    return true;
}

void bfs()
{
    while (!coada.empty())
    {
        int i = coada.front().first;
        int j = coada.front().second;
        coada.pop();
        for (unsigned int directie = 0; directie < 4; directie++)
        {
            int inext = i + di[directie];
            int jnext = j + dj[directie];
            if (!OK(inext, jnext))
                continue;
            coada.push(make_pair(inext, jnext));
            step[inext][jnext] = step[i][j] + 1;
            if (step[inext][jnext] > ans)
                ans = step[inext][jnext];
        }
    }
}

int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            cin >> s[0];
            if (s[0] == '#')
            {
                step[i][j] = 0;
                coada.push(make_pair(i, j));
            }
            else
                step[i][j] = -1;
        }
    }
    bfs();
    cout << ans;
    return 0;
}


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

int main(void) {

    int N;
    int K;
    long long h[100010];
    long long dp[100010];
    long long tmp;
    long long tnp;

    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> h[i];
    }

    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);

    for (int i = 2; i <= min(K,N-1); i++) {
        tmp = abs(h[i] - h[0]);
        for (int j = 1; j < i; j++) {
            tnp = dp[i-j] + abs(h[i] - h[i-j]);
            if (tnp < tmp) {
                tmp = tnp;
            }
        }
        dp[i] = tmp;
    }

    for (int i = K+1; i < N; i++) {
        tmp = 10000000000;
        for (int j = 1; j <= K; j++) {
            tnp = dp[i-j] + abs(h[i] - h[i-j]);
            if (tnp < tmp) {
                tmp = tnp;
            }
        }
        dp[i] = tmp;
    }

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

    return 0;

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  int N;
  cin >> N;
  vector<vector<int>> F(N,vector<int>(10));
  REP(i, N){
    REP(j, 10){
      cin >> F.at(i).at(j);
    }
  }
  vector<vector<int>> P(N,vector<int>(11));
  REP(i, N){
    REP(j, 11){
      cin >> P.at(i).at(j);
    }
  }
  
  int MAX = -INF;
  FOR(i,1,1024){
    int sum = 0;
    int z = i;
    REP(j,N){
      int x = z;
      int cnt = 0;
      REP(k,10){
        int y = x%2;
        x/=2;
        if(F.at(j).at(k)==1&&y==1){
          cnt++;
        }
      }
      sum+=P.at(j).at(cnt);
    }
    MAX=max(MAX,sum);
  }

  cout << MAX << endl;
}

Measured memory_bytes: 3632
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left, bisect_right #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass

table = primes(10**5+10)
# print(table)
set_table = set(table)

kisuu = [v for v in table if (v+1)//2 in set_table]

Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    print(bisect_right(kisuu, r) - bisect_left(kisuu, l))
    



Measured memory_bytes: 63064
//Saurabh Srivastava//
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lb;
#define pb push_back
#define pf push_front
#define mk make_pair
#define f(i,j,n) for(int i=j;i<n;i++)
#define r(i,n,j) for(int i=n-1;i>=j;i--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define Test int t;cin>>t;while(t--)
#define mod 1000000007
#define MIN INT_MIN
#define MAX INT_MAX
#define all(container) container.begin() , container.end()
#define sz(container) (int)container.size()
#define pii pair <int , int>
#define pll pair <long long int , long long int>
#define setp(x) setprecision(x)
int main(){
	int n;
  cin >> n;
  vector<int> v1(n),v2(n),v3(n-1);
  f(i,0,n)
    cin >> v1[i];
  f(i,0,n)
    cin >> v2[i];
   f(i,0,n-1)
    cin >> v3[i];
  int a=0;
  f(i,0,n){
  	a+=v2[v1[i]-1];
    if(i>0){
      if(v1[i]-v1[i-1]==1)
        	a+=v3[v1[i]-2];
  }
    
}cout << a << endl;}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <unordered_map>
#include <string>

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()

using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

string s;
ll N, K, A[200005], F[200005];
vector<pair<ll, ll>> R; //value, count

int main(void)
{
    cin >> N >> K;
    for (ll i = 0; i < N; i++) scanf("%lld", &A[i]);
    for (ll i = 0; i < N; i++) scanf("%lld", &F[i]);
    sort(A, A+N);
    sort(F, F+N, greater<ll>());

    ll l = -1, r = 1e18;
    while(r-l>1) {
        ll m = (l+r) / 2;
        ll k = 0;
        for(int i=0; i<N; i++) {
            ll t = A[i]*F[i] - m;
            if (t>0) k += (t+F[i]-1)/F[i];
        }
        if (k<=K) r = m;
        else l = m;
    }
    printf("%lld\n", r);




    return 0;
}


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

int main() {
	std::ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
	ll n, m, x;
	ll L = 1;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> x;
		x /= 2;
		L = L * x / __gcd(L, x);
		if (L > 1e18) {
			cout << 0 << endl;
			return 0;
		}
	}
	L /= x;
	m /= x;
	if (L % 2 == 0 || L > m) {
		cout << 0 << endl;
	} else {
		ll st = 1, en = m;
		while (st < en) {
			ll mid = st + (en - st + 1) / 2;
			if ((2 * mid - 1) * L <= m)
				st = mid;
			else
				en = mid - 1;
		}
		cout << st << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; } value
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  if(a * b == 2) cout << 3 << endl;
  if(a * b == 3) cout << 2 << endl;
  if(a * b == 6) cout << 1 << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
    private static MyScanner scanner;

    public static void main (String[] args){
        Main instance = new Main();
        scanner = instance.new MyScanner();
        instance.solve();
    }

    private void solve() {
        try {
            int N = scanner.nextInt();
            long power = 1l;
            for (int i = 1; i <= N; i++) {
                power *= i;
                power = power % 1000000007;
            }
            System.out.println(power);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";

        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String line = br.readLine();
            while (line.equals("")) {
                line = br.readLine();
            }
            s = line.split(reg, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }

        public long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 21204
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>

using namespace std;

void solve(long long N, vector<long long> a){
    bool odd;
    long long odd_v = 0;
    long long even_v = 0;
    int r;
    int l = 0;
    vector<int> ret;
    for (int i = 0; i < N; i++) {
        if (a[i] > 0) {
            if (i%2 == 0) {
                even_v += a[i];
            } else {
                odd_v += a[i];
            }
        }
    }
    if (even_v == 0 && odd_v == 0) {  // when all negative
        long long ret_v = (long long)-1e11;
        int ret_idx;
        for (int i = 0; i < N; i++) {
            if (a[i] > ret_v) {
                ret_v = a[i];
                ret_idx = i;
            }
        }
        std::cout << ret_v << std::endl;
        std::cout << N-1 << std::endl;
        for (int i = N; i > ret_idx+1; i--) {
            std::cout << i << std::endl;
        }
        for (int i = 0; i < ret_idx; i++) {
            std::cout << 1 << std::endl;
        }
        return;
    }

    if (even_v > odd_v) {
        odd = false;
    } else {
        odd = true;
    }
    while (r < N) {
        if (odd) {
            if (a[l] < 0 || l%2 == 0) {
                ret.push_back(1);
                l++;
            } else {
                r = l+2;
                break;
            }
        } else {
            if (a[l] < 0 || l%2 == 1) {
                ret.push_back(1);
                l++;
            } else {
                r = l+2;
                break;
            }
        }
    }
    while (r < N-1) {
        if(a[r] < 0) {
            ret.push_back(3);
            r += 2;
        } else {
            ret.push_back(2);
            r += 2;
        }
    }
    if (r == N-1) {
        if (a[r] < 0) {
            ret.push_back(3);
            ret.push_back(2);
        } else {
            ret.push_back(2);
        }
    } else {
        ret.push_back(2);
    }
    if (odd) {
        std::cout << odd_v << std::endl;
    } else {
        std::cout << even_v << std::endl;
    }
    std::cout << ret.size() << std::endl;
    for (int i = 0; i < ret.size(); i++) {
        std::cout << ret[i] << std::endl;
    }
}

int main(){	
    struct timeval start,end;
    long long span;
    gettimeofday(&start,NULL);

    long long N;
    scanf("%lld",&N);
    vector<long long> a(N-1+1);
    for(int i = 0 ; i <= N-1 ; i++){
    	scanf("%lld",&a[i]);
    }
    solve(N, a);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{

	public static void main(String[] args) {


		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();

		int count=0;
		
		for(int i = 3;i <= N;i=i+2){
			int y = 0;
			for(int j = 1;j <= i;j++){
				if(i % j==0){
					y++;
				}
				
			}
			if(y == 8){
				count++;
			}
			
		}
		
		System.out.println(count);
		

	}



}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    vector<ll> A(N);
    vector<ll> num(100002);
    ll sum = 0;
    rep(i,N){
        cin>>A[i];
        num[A[i]]++;
        sum+=A[i];
    }
    ll Q;
    
    cin>>Q;
    vector<ll>B(Q);
    vector<ll>C(Q);

    rep(i,Q){
        ll b,c;
        cin>>b>>c;
        sum+=c*num[b];
        sum-=b*num[b];
        num[c]+=num[b];
        num[b] = 0;
        cout<<sum<<endl;
    }
    


    return 0;
    

}

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

int main(){
	int N, A[110], v, j;
	cin>>N;
	for(int i = 0; i < N; i++) cin>>A[i];
	for(int k = 0; k < N; k++){
		cout<<A[k];
		if(k < N - 1)cout<<" ";
	}
	cout<<endl;
	
	for(int i = 1; i < N; i++){
		v = A[i];
		j = i - 1;
		while (j >= 0 && A[j] > v){	
			A[j + 1] = A[j];
			j--;
		}
		A[j+1] = v;
		for(int k = 0; k < N; k++){
			cout<<A[k];
			if(k < N - 1)cout<<" ";
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3076
#include <iostream>
using namespace std;
int main(){
    int N;
    cin >> N;
    int T[N];
    int Total = 0;
    for(int i = 0; i < N; i++){
        cin >> T[i];
        Total += T[i];
    }

    int M, Ans;
    cin >> M;
    int P, X;
    for(int i = 0; i < M; i++){
        cin >> P >> X;
        Ans = Total - T[P - 1] + X;
        cout << Ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int a = n / 100;
    // 5 * aまでは増加可能
    if (n <= a * 100 + 5 * a) {
        cout << "1\n";
    } else {
        cout << "0\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int n,a[20],b[20],c[19],i,r=0;
int main(){
    scanf("%d",&n);
    for(i=0;i<n;)scanf("%d",&a[i++]);
    for(i=0;i<n;){scanf("%d",&b[i]);r+=b[i++];}
    for(i=0;i<n-1;)scanf("%d",&c[i++]);
    for(i=0;i<n-1;i++)if(a[i+1]-a[i]==1)r+=c[a[i]-1];
    printf("%d",r);
    return 0;
}

Measured memory_bytes: 128
//freopen("in.in","r",stdin);
//freopen("out.out","w",stdout);
#include<bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define fastIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define debug freopen("in.in","r",stdin);freopen("out.out","w",stdout)
const int oo = 1e7;
#define LSOne(S) (S & (-S))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<vector<int> > vvi;
const int N = 105,K = 1e5 + 10;
const ll mod = 1e9 + 7;
ll dp[2][K];
ll prefSum[2][K];
ll n,k;
vector<int> input;


ll fixMod(ll x){
    return ((x % mod) + mod) % mod;
}
int sm(int i, int j, int k){
    int to = max(j-k -1, -1);
    ll tmp = prefSum[i][j];
    if (to != -1){
        tmp -= prefSum[i][to];
    }
    return fixMod(tmp);
}
int main() {
    fastIO;
    cin >> n >> k;
    input.resize(n);
    for (int i = 0 ; i < n; ++i){
        cin >> input[i];
    }
    dp[1][0] = 1;
    for (int i = 0 ; i < k + 2; ++i){
        prefSum[0][i] = 1;
        prefSum[1][i] = 1;
    }
    for (int i = n-1; i >=0 ; --i){
        int sum = 0;
        for (int j = 0; j <=k; ++j){
            int indx = i %2;
            dp[indx][j] = sm(1-indx, j, input[i]);
            prefSum[indx][j] = (dp[indx][j] + sum) % mod;
            sum = prefSum[indx][j];
        }
    }
    cout << dp[0][k];
    return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <vector>
#include <limits.h>
const long long INF = LLONG_MAX / 2;
#define FOR(i, r, n) for(int i=(r); i<(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ll long long int
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

using namespace std;
ll ans = 0, sum = 0, n, k, t;
string s;

ll x, y;

vector<ll> v;

int main() {
	cin >> n >> k >> x >> y;
	if (n < k) {
		ans = n*x;
	}
	else {
		ans = k*x + (n - k)*y;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
A, B, C, K = map(int, input().split())
ans = 0

if K >= A:
    ans += A
    K -= A
else:
    ans += K
    K = 0

if K >= B:
    K -= B
else:
    K = 0

if K >= C:
    ans -= C
else:
    ans -= K
    K = 0
print(ans)

Measured memory_bytes: 9188
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


/*
AC
*/

ll n,m,sum=0,x[100010];
vector<ll> v;


int main(void){
	cin>>n>>m;
	rep(i,m)cin>>x[i];
	sort(x,x+m);
	// rep(i,m)cout<<x[i]<<endl;
	//
	reg(i,1,m-1){
		v.push_back(x[i]-x[i-1]);
		sum+=x[i]-x[i-1];
	}
	// cout<<sum<<endl;
	//
	sort(v.begin(),v.end());
	// rep(i,m-1)cout<<v[i]<<endl;
	if(n-1>=m-1){
		sum=0;
	}else{
		rep(i,n-1){
			sum-=v[m-2-i];
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 2168
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
    int k,cnt=8;
    char s[20];
    scanf("%s",s);
    k=strlen(s);
    for(int i=0;i<k;i++){
        if(s[i]=='x'){
            cnt--;
        }
    }
    if(cnt>0){
        printf("YES\n");
    }
    else{
        printf("NO\n");
    }
}

Measured memory_bytes: 128
def dfs(u, g, visited):
    visited[u] = True

    for v in range(len(g)):
        if visited[v]:
            continue
        if g[u][v]:
            dfs(v, g, visited)


def solve():
    [N, M] = [int(x) for x in input().split()]

    import collections

    edges = []
    g = [[False] * N for _ in range(N)]
    for i in range(M):
        a, b = [int(x) for x in input().split()]
        edges.append((a-1, b-1))
        g[a-1][b-1] = g[b-1][a-1] = True

    ans = 0
    for e in edges:
        g[e[0]][e[1]] = g[e[1]][e[0]] = False

        # print(g)
        visited = [False] * N

        dfs(0, g, visited)
        # print(visited)
        ans += not all(visited)

        g[e[0]][e[1]] = g[e[1]][e[0]] = True
    return ans


def main():
    print(solve())


if __name__ == '__main__':
    main()


Measured memory_bytes: 3440
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations

def main():
    s1, s2, s3 = input().upper().split()

    print(s1[0] + s2[0] + s3[0])

if __name__ == '__main__':
    main()

Measured memory_bytes: 10300
#include<bits/stdc++.h>
#define rep(i,s,n) for(int i = s;i<n;i++)
#define long long ll
using namespace std;
struct Num{
    int ai;
    int aj;
    int de;
};
int main()
{
    int n;
    while(cin>>n){
       // vector<int> a;
        int a[n];
        rep(i,0,n){
           // a.push_back(n);
            cin>>a[i];
        }
        //sort(a.begin(),a.end());
        sort(a,a+n);
        int num =a[n-1];
        int t = num/2;
        //int no = lower_bound(a,a+n,t);
        int no = (lower_bound(a, a + n, t))-a;
        if(n==2) cout<<a[1]<<" "<<a[0]<<endl;
        else{
        int s = abs(a[no]-t);
        int s2 = abs(a[no-1]-t);
        int ab;
        int nn;
        if(s==s2){
            ab = s;
            nn =no;
        }else if(s>s2){
            ab = s2;
            nn = no-1;
        }else{
            ab =s;
            nn = no;
        }
        cout<<num<<" "<<a[nn]<<endl;
        }
    }
}


Measured memory_bytes: 640
import math
n = int(input())
arr = [int(x) for x in input().split()]

dp = [0]*n
for i in range(n):
    if i>=2:
        dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i-2]-arr[i]))
    elif i==1:
        dp[i] = abs(arr[i]-arr[i-1])
    else:
        dp[i] = 0
print(dp[n-1])


Measured memory_bytes: 14104
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;

int main(){
    ll N; cin >> N;
    vector<ll> a(N);
    ll target = 0;
    set<ll> st;
    for(int i=0;i<N;++i){
        cin >> a[i];
        if(a[i] >= 3200){
            target++;
            continue;
        }
        st.insert(a[i]/400);
    }
    ll ans1 = st.size();
    ll ans2 = ans1 + target;
    if(ans1 == 0)ans1++;
    cout << ans1 << " " << ans2 << endl;
}

Measured memory_bytes: 256
from fractions import gcd


def lcm(a, b):
    """
    aとbの最小公倍数を計算します。
    """
    return a * b // gcd(a, b)


N, M = map(int, input().split())
S = input()
T = input()

ans = lcm(N, M)

c = dict()
for i in range(N):
    c[i * ans // N] = S[i]
for i in range(M):
    val = c.get(i * ans // M)
    if val is not None and val != T[i]:
        print(-1)
        exit(0)
print(ans)

Measured memory_bytes: 17492
N = int(input())


def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


count = 0
for i in range(1, N+1, 2):
    if len(make_divisors(i)) == 8:
        count += 1

print(count)


Measured memory_bytes: 61952
#include <algorithm>
#include <iostream>
#define N 20
using namespace std;

int main(){
  int m,n,u,l,ans[N];
  string d[18]={"","Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan","Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts"};
  while(1){
    cin>>m>>n;
    if(!m&&!n) break;
    for(int i=0;i<N;i++) ans[i]=0;
    ans[0]=m;
    n--;
    l=1;
    while(n--){
      u=0;
      for(int i=0;i<l;i++){
	ans[i]=u+ans[i]*m;
	u=0;
	if(ans[i]>=10000) l=max(l,i+2),u=ans[i]/10000,ans[i]%=10000;
      }
    }
    for(int i=l;i>=0;i--){
      if(!ans[i]) continue;
      cout<<ans[i]<<d[i];
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#: Author - Soumya Saurav
import sys,io,os,time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect,math,heapq
alphabet = "abcdefghijklmnopqrstuvwxyz"

input = sys.stdin.readline

########################################
d ,t , s = map(int , input().split())
if d/t <= s:
	print("Yes")
else:
	print("No")










Measured memory_bytes: 67164
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
int main(){
 
   int N,M,K;
   cin >> N >> M;
   int like[M];

   for(int j=0;j<M;j++) like[j]=0;

   for(int i=0;i<N;i++){
   	 cin >> K;
     int a;
   	 for(int j=0;j<K;j++){
   	 	cin >> a;
   	 	like[a-1]++;
   	 }
   }

   int ans = 0;
   for(int j=0;j<M;j++){
   	  if(like[j]==N) ans++;
   }

   cout << ans <<endl;  

  return 0;
}

Measured memory_bytes: 256
/// Contest : Codecraft-18 and Codeforces Round #458 (Div. 1 + Div. 2, combined)... Problem: A
/// 20-01-2018
/// MD:NUR ALAM
/// Eastern University of Bangladesh

#include "bits/stdc++.h"

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = (a); i < (b); ++i)
#define fo(i, a, b) for (int i = (a); i <(b); ++i)
#define fors(i, s) for (int i = 0; s[i]; ++i)
#define rs(x) scanf("%s", (x))
#define mp make_pair
#define pb push_back
#define mso(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define len(X) strlen(x)

using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef long double lu;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpll;
typedef pair<int,int> Pll;
typedef map<string,int>msi;
typedef set<int>se;

template<class t> void _r(t &x) { cin >> x; }
void _r(int &x) { scanf("%d", &x); }
void _r(int64_t &x) { scanf("%lld", &x); }
void _r(double &x) { scanf("%lf", &x); }
void _r(char &x) { scanf(" %c", &x); }
void _r(char *x) { scanf("%s", x); }
void r() {}
template<class t, class... u> void r(t &head, u &... tail) { _r(head); r(tail...); }
template<class t> void _w(const t &x) { cout << x; }
void _w(const int &x) { printf("%d", x); }
void _w(const int64_t &x) { printf("%lld", x); }
void _w(const double &x) { printf("%.16f", x); }
void _w(const char &x) { putchar(x); }
void _w(const char *x) { printf("%s", x); }
template<class t,class u> void _w(const pair<t,u> &x) {_w(x.f); putchar(' '); _w(x.s);}
void w() {}
template<class t, class... u> void w(const t &head, const u &... tail) { _w(head); putchar(sizeof...(tail) ? ' ' : '\n'); w(tail...); }
template<class t, class... u> void debug(const t &head, const u &... tail) {
#ifdef HOME
#endif
}

///------------------------------------------------------------------------------------------------------------------------------------

int main()
{
   set<int>s;
   int n;
   r(n);
   ll a[n];
   fo(i,0,n)
   {
       r(a[i]);
   }
   fo(i,0,n)
   {
       s.insert(a[i]);
   }
   cout<<s.size()<<endl;

}


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

typedef long long int lli;

using namespace std;

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

	int N, M,ans=0; cin >> N >> M;
	vector<int> ver(N);
	for (int i = 0; i < N; i++) { cin >> ver[i]; }

	for (int A = 0; A <= N; A++) {
		for (int B = 0; B <= N; B++) {
			if (A + B > N || A + B > M) { continue; }
			vector<int> S;
			for (int i = 0; i < A; i++) { S.push_back(ver[i]); }
			for (int i = 0; i < B; i++) { S.push_back(ver[N - i - 1]); }
			sort(S.begin(), S.end());
			int sum = 0;
			for (int i = 0; i < S.size(); i++) { sum += S[i]; }
			int cnt = M - (A + B);
			for (int i = 0; i < S.size(); i++) {
				if (S[i] >= 0) { break; }
				if (cnt) {
					cnt--;
					sum -= S[i];
				}
			}
			ans = max(ans, sum);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <climits>
using namespace std;

bool comp(pair<int, string> a, pair<int, string> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}


 
int main(){
    int w,h,n;
    cin >> w >> h >> n;

    long double x0 = 0,x1 = w,y0 = 0,y1 = h;

    for(int i = 0; i < n; ++i){
        double x,y;
        int a;
        cin >> x >> y >> a;

        switch(a){
            case 1:
                if(x > x0)
                    x0 = x;
                break;
            case 2:
                if(x < x1)
                    x1 = x;
                break;
            case 3:
                if(y > y0)
                    y0 = y;
                break;
            case 4:
                if(y < y1)
                    y1 = y;
                break; 
        }
    }
    if(x0 < x1 && y0 < y1)
        cout << (x1 - x0)*(y1 - y0) << endl;
    else
        cout << 0 << endl;
    

}

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

int main() {
  string S; cin >> S;
  for(int i = 0; i < S.size()-1; ++i) {
    if(S[i] == S[i+1]) {
      cout << "Bad" << endl;
      return 0;
    }
  }
  cout << "Good" << endl;

  return 0;
}

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

int main() {
	int N; cin >> N;
	map<int, vector<int>> mp;
	int get[100010];
	int a, b;
	for(int i=1; i<N; ++i){
	    cin >> a >> b;
	    mp[a].push_back(b);
	    mp[b].push_back(a);
	    get[i]=0;
	}
	get[1]=1;
	get[N]=2;
	int F=0, S=0;
	vector<int> B{1}, Bnext, W{N}, Wnext;
	while(F+S+2!=N){
	    for(int i=0; i!=B.size(); ++i){
	        for(int j=0; j!=mp[B[i]].size(); ++j){
	            if(!get[mp[B[i]][j]]){
	                ++F;
	                get[mp[B[i]][j]]=1;
	                Bnext.push_back(mp[B[i]][j]);
	            }
	        }
	    }
	    for(int i=0; i!=W.size(); ++i){
	        for(int j=0; j!=mp[W[i]].size(); ++j){
	            if(!get[mp[W[i]][j]]){
	                ++S;
	                get[mp[W[i]][j]]=2;
	                Wnext.push_back(mp[W[i]][j]);
	            }
	        }
	    }
	    B=Bnext; Bnext.erase(Bnext.begin(), Bnext.end());
	    W=Wnext; Wnext.erase(Wnext.begin(), Wnext.end());
	}
	if(F>S) cout << "Fennec" << endl;
	else cout << "Snuke" << endl;
	return 0;
}


Measured memory_bytes: 11520
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;

int main(){

    //フィボナッチ数列を使ってやってみる
    // An = An-1 + An-2

    int n,m; cin>>n>>m;

    vector<int> pattern(n+1,0);

    vector<bool> broke(n+1,true);

    for(int i=0; i<m; i++){
        int d; cin>>d;
        broke[d] = false;
    }

    pattern[0] = 1;

    if(broke[1]) pattern[1] = 1;

    for(int i=2; i<=n; i++){
        
        if(broke[i-1]) pattern[i] += pattern[i-1];

        if(broke[i-2]) pattern[i] += pattern[i-2];

        pattern[i] %= mod;
    }

    cout<<pattern[n]<<endl;

    return 0;

}

Measured memory_bytes: 640
n = int(input())
s = [input() for _ in range(n)]
j = [0]*4

for i in range(n):
    if s[i] == "AC":
        j[0] += 1
    elif s[i] == "WA":
        j[1] += 1
    elif s[i] == "TLE":
        j[2] += 1
    else :
        j[3] += 1

l = ["AC", "WA", "TLE", "RE"]
for i in range(4):
    print("{} x {}".format(l[i], j[i]))

Measured memory_bytes: 16320
#include <stdio.h>
int main(void){

char x;
int a=0,b,c;

while(1){
for(c=1;c<=1001;c++){
x=getchar();

if(x=='1'){b=1;}
if(x=='2'){b=2;}
if(x=='3'){b=3;}
if(x=='4'){b=4;}
if(x=='5'){b=5;}
if(x=='6'){b=6;}
if(x=='7'){b=7;}
if(x=='8'){b=8;}
if(x=='9'){b=9;}
if(x=='0'){b=0;}
if(x=='\n'){break;}

a+=b;

}
if(a==0){break;}
printf("%d\n",a);
a=0;
}
return 0;
}

Measured memory_bytes: 524