akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int mod = 1e9 + 7;
const int maxn = 200000 + 7;

long long inv[maxn], step[maxn];
long long pow_a[maxn], pow_b[maxn], pow_c[maxn], pow_ab[maxn];
long long inv_step[maxn];

long long C(int n, int m) {
    return step[n] * inv_step[m] % mod * inv_step[n - m] % mod;
}

int main() {
    step[0] = 1;
    for (int i = 1; i < maxn; i++) step[i] = step[i - 1] * i % mod;
    inv[0] = inv[1] = 1;
    for (int i = 2; i < maxn; i++) inv[i] = mod - (mod / i) * inv[mod % i] % mod;
    inv_step[0] = inv[0];
    for (int i = 1; i < maxn; i++) inv_step[i] = inv_step[i - 1] * inv[i] % mod;


    long long n, a, b, c;
    cin >> n >> a >> b >> c;
    pow_a[0] = pow_b[0] = pow_c[0] = pow_ab[0] = 1;
    for (int i = 1; i < maxn; i++) {
        pow_a[i] = pow_a[i - 1] * a % mod;
        pow_b[i] = pow_b[i - 1] * b % mod;
        pow_c[i] = pow_c[i - 1] * c % mod;
        pow_ab[i] = pow_ab[i - 1] * inv[a + b] % mod;
    }

    long long ans = 0;
    for (int i = n; i <= 2 * n - 1; i++) {
        long long tmp = C(i - 1, n - 1);

        tmp = tmp * (pow_a[n] * pow_b[i - n] % mod + pow_a[i - n] * pow_b[n] % mod) % mod * pow_ab[i] % mod;
        tmp = tmp * i % mod * 100 % mod * inv[100 - c] % mod;
        ans = (ans + tmp) % mod;
    }

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



Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
int w[10000001],d[100000001],cnt[20],res,n,st,sxr[100000001];
bool book[10000001];
int main()
{
    scanf("%d",&n);
    for(int i=1,u,v,va;i<n;i++)
    {
        scanf("%d%d%d",&u,&v,&va);
        w[u]^=va;
        w[v]^=va;
    }
    for(int i=0;i<n;i++)
        cnt[w[i]]++; 
    for(int i=1;i<=15;i++)
    {
        res+=cnt[i]/2;
        st|=(cnt[i]&1)<<(i-1); 
    }
    for(int i=1;i<(1<<15);i++)
        d[i]=d[i>>1]+(i&1);
    for(int i=1;i<(1<<15);i++)
        d[i]-=1;
    for(int i=1;i<(1<<15);i++)
        for(int j=0;j<15;j++)
            if((i>>j)&1)
                sxr[i]^=(j+1);
    for(int i=1;i<(1<<15);i++)
    {
        if(sxr[i]!=0)
            continue;
        for(int k=(i-1)&i;k;k=(k-1)&i)
            if(sxr[k]==0)
                d[i]=min(d[i],d[k]+d[i^k]);
    }
        printf("%d",res+d[st]);
    getchar();getchar();
}

Measured memory_bytes: 6400
'''input
101
86
119
108
57
'''

a=[]

for i in range(5):
	a.append(int(input()))
# print(a)
flag=[]

for i in range(5):
	if a[i]%10!=0:
		flag.append(a[i]%10)
	else:
		flag.append(-1)
# print(flag)

endInd=-1
end=float('inf')

for i in range(5):
	if flag[i]>0 and end>flag[i]:
		end=flag[i]
		endInd=i
# print(a[endInd])

if endInd==-1:
	print(sum(a))
else:
	s=a[endInd]
	# print(s)
	a.pop(endInd)
	flag.pop(endInd)
	# print(a)
	for i in range(4):
		if flag[i]>0:
			a[i]=(a[i]//10+1)*10
	# print(a)
	s+=sum(a)
	print(s)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int h,n;
    cin >> h >> n;
    int a;
    rep(i,0,n-1){
        cin >> a;
        h -= a;
    }
    if(h<=0)puts("Yes");
    else puts("No");

    return 0;
}


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

int main() {
  int n,CH; cin>>n>>CH;
  vector<int> s(n),t(n),c(n);
  rep(i, n) {
    cin>>s[i]>>t[i]>>c[i];
    s[i]--; c[i]--;
  }
  vector<int> y(100005, 0);
  rep(ch, CH) {
    vector<int> x(100005, 0);
    rep(i, n) {
      if (c[i]==ch) {
        x[s[i]]++;
        x[t[i]]--;
      }
    }
    rep(i, 100004) x[i+1]+=x[i];
    rep(i, 100002) {
      if (x[i]>0) y[i]++;
    }
  }
  int res=0;
  rep(i, 100002) res=max(res, y[i]);
  cout<<res<<endl;
}

Measured memory_bytes: 2176
# https://atcoder.jp/contests/abc096/tasks/abc096_c



H, W = gets.split.map(&:to_i)
sss = Array.new(H) { gets.chomp.chars }

blackable_count = 0
un_blackables = []

sss.each_with_index do |row, i|
  row.each_with_index do |elm, j|
    if elm == '#'
      if row.dig(j-1) == '#' or row.dig(j+1) == '#'
        blackable_count += 1
      else
        un_blackables << [i, j]
      end
    end
  end
end

un_blackables.each do |i, j|
  if sss.dig(i-1, j) == '#' or sss.dig(i+1, j) == '#'
    blackable_count += 1
  end
end
puts (sss.flatten.count('#') == blackable_count) ? 'Yes' : 'No'


Measured memory_bytes: 1916
n = int(input())
p = list(map(int, input().split()))
cnt = 0
for i in range(n - 2):
    three_num = p[i : i + 3]
    max_num = max(three_num)
    min_unm = min(three_num)
    if p[i + 1] != max_num and p[i + 1] != min_unm:
        cnt += 1

print(cnt)

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
INF = 100100

def prim(n: int, M: list):
    ans = 0
    visited = [False] * n
    d = [INF] * n
    p = [-1] * n
    d[0] = 0
    while True:
        mincost = INF
        for i in range(n):
            if not visited[i] and d[i] < mincost:
                mincost = d[i]
                u = i
        if mincost == INF:
            break
        ans += mincost
        visited[u] = True
        for v in range(n):
            if not visited[v] and M[u][v] != -1:
                if M[u][v] < d[v]:
                    d[v] = M[u][v]
                    p[v] = u
    return ans

def main():
    n = int(input())
    M = []
    for _ in range(n):
        Mi = list(map(int, input().split()))
        M.append(Mi)
    ans = prim(n,M)
    print(ans)

if __name__ == '__main__': main()


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

using namespace std;

const int maxn = 1e5 + 5;

struct Node {
      int v, e;
      Node(int v = 0, int e = 0)
            : v(v), e(e) {}
};

vector < vector <Node> > graph;
int value[maxn];
int mod;

void dfs(int u, int p, int val) {
      int ptr = 1;
      for (int i = 0; i < graph[u].size(); i++) {
            int v = graph[u][i].v;
            int e = graph[u][i].e;
            if (v == p) {
                  continue;
            }
            int nval = (val + ptr) % mod;
            ptr = (ptr + 1) % mod;
            value[e] = nval;
            dfs(v, u, nval);
      }
}

void Task() {
      int n;
      cin >> n;
      graph.resize(n + 1);
      for (int e = 1; e < n; e++) {
            int u, v;
            cin >> u >> v;
            graph[u].emplace_back(v, e);
            graph[v].emplace_back(u, e);
      }
      int root = 0;
      int maxDegree = 0;
      for (int i = 1; i <= n; i++) {
            if (graph[i].size() > maxDegree) {
                  maxDegree = graph[i].size();
                  root = i;
            }
      }
      mod = maxDegree;
      dfs(root, 0, 0);
      cout << maxDegree << endl;
      for (int i = 1; i < n; i++) {
            cout << value[i] + 1 << endl;
      }
}

signed main() {
      ios_base::sync_with_stdio(false);
      cin.tie(nullptr); cout.tie(nullptr);

      if (fopen("in.txt", "r")) {
            freopen("in.txt", "r", stdin);
      }

      int tc = 1;
      while (tc--) {
            Task();
      }
}


Measured memory_bytes: 11008
import heapq

class UnionFind():
  def __init__(self,n):
    self.n=n
    self.root=[-1]*(n+1)
    self.rank=[0]*(n+1)
  def FindRoot(self,x):
    if self.root[x]<0:
      return x
    else:
      self.root[x]=self.FindRoot(self.root[x])
      return self.root[x]
  def Unite(self,x,y):
    x=self.FindRoot(x)
    y=self.FindRoot(y)
    if x==y:
      return
    else:
      if self.rank[x]>self.rank[y]:
        self.root[x]+=self.root[y]
        self.root[y]=x
      elif self.rank[x]<=self.rank[y]:
        self.root[y]+=self.root[x]
        self.root[x]=y
        if self.rank[x]==self.rank[y]:
          self.rank[y]+=1
  def isSameGroup(self,x,y):
    return self.FindRoot(x)==self.FindRoot(y)
  def Count(self,x):
    return -self.root[self.FindRoot(x)]

n,m=map(int,input().split())
costs=list(map(int,input().split()))
if m==n-1:
  print(0)
  exit()
edges=[list(map(int,input().split())) for _ in range(m)]
uf=UnionFind(n)
for a,b in edges:
  uf.Unite(a,b)
qs=[[] for _ in range(n)]
roots=set()
for i in range(n):
  root=uf.FindRoot(i)
  roots.add(root)
  heapq.heappush(qs[root],costs[i])
remains=[]
ans=0
cnt=0
for root in roots:
  cost=heapq.heappop(qs[root])
  ans+=cost
  cnt+=1
  while len(qs[root])!=0:
    cost=heapq.heappop(qs[root])
    heapq.heappush(remains,cost)
while len(remains)!=0 and cnt<2*(n-m-1):
  cost=heapq.heappop(remains)
  ans+=cost
  cnt+=1
if cnt==2*(n-m-1):
  print(ans)
else:
  print('Impossible')

Measured memory_bytes: 41192
#include<stdio.h>
#include<stdlib.h>

int main(){
    int n,d,sum = 0,ads,ans = 0,minus;
    scanf("%d %d",&n,&d);
    int x[n][d];
    for(int i=0;i<n;i++){
      for(int j=0;j<d;j++){
        scanf("%d",&x[i][j]);
      }
    }
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
        for(int l=0;l<d;l++){
          minus = x[i][l] - x[j][l];
          ads = abs(minus);
          sum += minus*minus;
        }
        for(int k=0;k<=sum;k++){
          if(sum == k*k){
            ans += 1;
          }
        }
        sum = 0;
      }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int main() {
  int64_t n, min_num, max_num, sum_num;
  cin >> n;
  vector<int> vec(n);
  sum_num = 0;
  rep(i,n){
    cin >> vec.at(i);
    sum_num += vec.at(i);
  }
  SORT(vec);
  min_num = vec.at(0);
  max_num = vec.at(n-1);

  printf("%ld %ld %ld\n",min_num, max_num, sum_num);
}


Measured memory_bytes: 3312
if __name__ == "__main__":
    N, M, K = map(int, input().split())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]

    a, b = [0], [0]
    for i in range(N):
        a.append(a[i] + A[i])

    for i in range(M):
        b.append(b[i] + B[i])

    ans, j = 0, M
    for i in range(len(a)):
        if a[i] > K:
            break
        while a[i] + b[j] > K:
            j -= 1
        ans = max(ans, i + j)

    print(ans)

Measured memory_bytes: 47448
import java.util.Scanner;

public class Main {

    public Main() {
    }

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

    private Scanner sc;

    private void solve() {
        sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        int cnt = 0;
        for (int i = 0; i < N; i++) {
            int minj = i;
            for (int j = i; j < N; j++) {
                if (A[j] < A[minj]) {
                    minj = j;
                }
            }
            if (minj != i) {
                int tmp = A[i];
                A[i] = A[minj];
                A[minj] = tmp;
                cnt++;
            }
        }
        String ans = "";
        for (int num : A) {
            ans += num;
            ans += " ";
        }

        System.out.println(ans.trim());
        System.out.println(cnt);
    }
}

Measured memory_bytes: 26504
#include <algorithm>
#include <cctype>
#include <cstring>
#include <cstdio>
using namespace std;
typedef unsigned long long uint64;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 2e5+5, P = 1e9+7;
int n, a, b, c[N], w[N], s[N], minw[N], all, u, v;
uint64 fac[N], ans, inv[N], ifac[N];
int main()
{
    n = read(), a = read(), b = read();
    fac[0] = ifac[0] = fac[1] = ifac[1] = inv[1] = 1;
    for(int i = 1; i <= n; ++i) 
    {
        c[i] = read(), w[i] = read();
        if(!u||w[u] > w[i]) v = u, u = i;
        else if(!v||w[v] > w[i]) v = i;
        if(!minw[c[i]]) minw[c[i]] = w[i];
        else if(minw[c[i]] > w[i]) minw[c[i]] = w[i];
    }
    for(int i = 1, j = 2; i <= n; ++i, ++j)
    {
        inv[j] = inv[P%j]*(P-P/j)%P, fac[j] = fac[j-1]*j%P, ifac[j] = ifac[j-1]*inv[j]%P;
        if(w[i]+minw[c[i]] <= a) w[i] = minw[c[i]];
        if((c[u] == c[i]&&w[i]+w[v] <= b)||(c[u] != c[i]&&w[i]+w[u] <= b)) ++s[c[i]], ++all;
    }
    ans = fac[all];
    for(int i = 1; i <= n; ++i) ans = ans*ifac[s[i]]%P;
    printf("%llu\n", ans);
    return 0;
}

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

#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ll long long
#define ld long double
#define pb push_back
#define MOD 1000000007
#define LLMN LONG_LONG_MIN
#define LLMX LONG_LONG_MAX
#define LDMX LDBL_MAX
#define LDMN LDBL_MIN
#define MAX 1000000

ll mulmod(ll, ll);
ll fastpower(ll, ll);
void getprime(vector<ll>&);
void getfact(vector<ll>&, vector<ll>&);
ll ncr(ll, ll, vector<ll>&, vector<ll>&);

void solve()
{
    ll n, m, k;
    cin>>n>>m;
    bool f = false;
    for(ll i=0;i<=n;i++)
    {
        if(2*i + (n-i)*4 == m)
        {
            f = true;
            break;
        }
    }
    if(f)
        Yes();
    else
        No();
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll t = 1;
    //cin>>t;
    while(t--)
    {
        solve();        
    }
    return 0;
}

ll mulmod(ll a, ll b)
{
    ll res = 0; 
    a = a % MOD;
    while(b > 0)
    {
        if (b % 2 == 1)
            res = (res + a) % MOD;
 
        a = (a * 2) % MOD; 
        b /= 2;
    } 
    return res % MOD; 
}

ll  fastpower(ll a, ll n)
{
    ll res = 1;
    while(n > 0)
    {
        if(n % 2 != 0)
        {
            res = (res * a) % MOD;
        }
        n /= 2;
        a = (a * a) % MOD;
    }
    return res;
}

void getprime(vector<bool>&prime)
{
    prime[0] = false;
    prime[1] = false;
    
    for(ll i = 2;i <= MAX; i++)
    {
        if(prime[i])
        {
            for(ll j = i*i; j <= MAX; j += i)
                prime[j] = false;
        }
    }
}

void getfact(vector<ll> &fact, vector<ll> &ifact)
{
    fact[0] = 1;
    ifact[0] = 1;
    
    for(ll i = 1; i <= MAX; i++)
    {
        fact[i] = (fact[i-1] * i)%MOD;
        ifact[i] = (ifact[i-1] * fastpower(i, MOD -2) )%MOD;
    }
}

ll ncr(ll n, ll r, vector<ll>&fact, vector<ll>&ifact)
{
    ll res;
    res = (((fact[n] * ifact[r]) % MOD) * ifact[n-r]) % MOD;
    return res;
}


Measured memory_bytes: 3652
n,x,m = map(int, input().split())
visited=set()
from collections import defaultdict
ans=0
cnt=0
now=x
last=defaultdict(list)
while cnt!=n:
    cnt+=1
    if now in visited:
        break
    visited.add(now)
    last[now]=[ans,cnt]
    ans+=now

    now=(now**2) % m
    if now==0:
        print(ans)
        exit()

if cnt==n:
    print(ans)
    exit()

looplen=cnt-last[now][1]
looppoint=ans-last[now][0]
loopcnt,nokori = divmod(n-cnt,looplen)
ans+=(loopcnt*looppoint)
ans+=now

for i in range(nokori):
    now=(now**2) % m
    ans+=now

print(ans)

Measured memory_bytes: 82072
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main() {
  int N, K;
  cin >> N >> K;
  vector<ll> V(N);
  for(int i=0; i<N; i++)
    cin >> V[i];
  ll ans = 0;
  for(int i=0; i<=min(N, K); i++) {
    for(int j=0; j<=min(N, K)-i; j++) {
      vector<ll> tmp(i);
      copy(V.begin(), V.begin()+i, tmp.begin());
      vector<ll> tmp2(j);
      copy(V.end()-j, V.end(), tmp2.begin());
      tmp.insert(tmp.end(), tmp2.begin(), tmp2.end());

      // for(int k=0; k<tmp.size(); k++)
      // 	cout << tmp[k] << ' ';
      // cout << endl;

      sort(tmp.begin(), tmp.end());
      int tmp3 = lower_bound(tmp.begin(), tmp.end(), 0) - tmp.begin();
      ans = max(ans, accumulate(tmp.begin()+min(tmp3, K-i-j), tmp.end(), 0LL));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

struct Graph{
    int N;
    vector<vector<int>> adjlist;
    vector<int> dp;

    Graph(int n) : N(n), adjlist(n), dp(n, -1){}

    void setEdge(int a, int b){
        adjlist[a].push_back(b);
    }

    int dfs(int v){
        if(dp[v] != -1){
            return dp[v];
        }
        int res = 0;
        for(auto i : adjlist[v]){
            res = max(res, dfs(i) + 1);
        }
        return dp[v] = res;
    }
};

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

    Graph G(n);

    REP(i, m){
        int a, b;
        cin >> a >> b;
        G.setEdge(a-1, b-1);
    }

    int ans = 0;
    REP(i, n){
        ans = max(ans, G.dfs(i));
    }

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

Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    int N, ans = 0;
    cin >> N;
    for (int i = 0; i < 4; i++){
        if (N % 10 == 2){
            ans++;
        }
        N /= 10;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
import java.util.*;
import java.util.Map.Entry;
import java.io.*;

public class Main{
static int mod=(int)1e9+7;
static long dp[][]=new long[3001][3001];
public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n=scn.nextInt();
		char s[]=scn.next().toCharArray();
		dp[n][0]=(s[n-2]=='>')?1:0;
		dp[n][1]=(s[n-2]=='<')?1:0;
		for(int i=n-1;i>=2;i--){
			int tot=n-i+1;
			for(int g=0;g<=tot;g++){
				if(g==0){
					dp[i][g]=0;
					if(s[i-2]=='<'){
						continue;
					}
					for(int j=1;j<=tot;j++){
						dp[i][g]=(dp[i][g]+dp[i+1][tot-j])%mod;
					}
				}
				else{
					if(s[i-2]=='<'){
						dp[i][g]=(dp[i][g-1]+dp[i+1][g-1])%mod;
					}
					else{
						dp[i][g]=(dp[i][g-1]-dp[i+1][g-1]+mod)%mod;
					}
				}
				
				
			}
			
		}
		long ans=0;
		for(int i=1;i<=n;i++){
			ans=(ans+dp[2][n-i])%mod;
		}
		System.out.println(ans);

	}

}

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

using namespace std;
using ll = long long;

#define debug(x) cerr << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F;
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;

const int maxn = 2e5 + 10;

int dx[] = {0,1,-1,0};
int dy[] = {1,0,0,-1};


int main()
{
	ios::sync_with_stdio(false);
	int test = 1;
	while(test--)
	{
		int d,t,s;
		cin >> d >> t >> s;
		cout << (d <= t*s ? "Yes" : "No") << endl;
	}
	
	return 0;
}

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

int main(){
    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d;
    e=c/b;
    f=a/d;
    if(c%b!=0){
        e++;
    }
    if(a%d!=0){
        f++;
    }
    if(e<=f){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long i64;
typedef pair<i64,i64> P;


int a, b;
int n;

int main(){
	cin >> n >> a >> b;
	
	cout << min(n * a , b) << endl;
	
	
	return 0;
}

Measured memory_bytes: 764
#include<stdio.h>
int main(){
    long long int A,B,K;
    scanf("%lld%lld%lld",&A,&B,&K);
    if(K>A)
    {
        K=K-A;
        A=0;
        if(K>B)
        {
        K=K-B;
        B=0;
        }    
        else{
        B=B-K;  
        } 
    }
    else{
        A=A-K;
    }
    printf("%lld %lld\n",A,B);
    return 0;
}     
   
        
        
                 
        
 
       
     
               
                
   
      
        
   
        
        
  

Measured memory_bytes: 128
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
2
ABCXYZ
---+/
/+---test
0
ABCXYZ
---+/
/+---test
13
ABCDEFGHIJKLMNOPQRSTUVWXYZ
---+/

void main(string[] args) {
  const N = readln.chomp.to!long;
  auto  S = readln.chomp.map!(x => (x - 'A').to!long).array;

  foreach (ref c; S) {
    c = (c + N)%26;
  }

  S.map!(x => (x + 'A').to!char).to!string.writeln;
}


Measured memory_bytes: 380
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<string> S(N);
	for (int i = 0; i < N; i++) {
		cin >> S.at(i);
	}

	//ソート
	vector<string> S2(N);
	for (int i = 0; i < N; i++) {
		vector<char> C(S.at(i).length());
		for (int j = 0; j < S.at(i).length(); j++) {
			C.at(j) = S.at(i)[j];
		}
		sort(C.begin(), C.end());
		S2.at(i) = "";
		for (int j = 0; j < S.at(i).length(); j++) {
			S2.at(i) += C.at(j);
		}
	}

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

	long  cnt = 0;
	string s = "";
	long  same = 0;
	for (int i = 0; i < N; i++) {
		if (s == S2.at(i)) {
			same++;
		}
		else {
			cnt += (same * (same + 1)) / 2;
			same = 0;
			s = S2.at(i);
		}
	}

	cnt += (same * (same + 1)) / 2;

	cout << cnt << endl;

	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n), acc(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if(i == 0)acc[i] = a[i];
    else acc[i] = acc[i - 1] + a[i];
  }

  ll ans = 1e18;
  for (int i = 0; i < n - 1; i++) {
    ans = min(ans, abs(acc[n - 1] - 2 * acc[i]));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3328
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)











int main(){
    ll n;
    cin >> n;
    vector<ll> a(n), b(n), c(n - 1);
    REP(i, n) cin >> a[i];
    REP(i, n) cin >> b[i];
    REP(i, n - 1) cin >> c[i];
    ll ans = 0, t = -1;
    REP(i, n){
        ans += b[a[i] - 1];
        if(t + 1 == a[i]){
            ans += c[t - 1];
        }
        t = a[i];
    }
    cout << ans << endl;
}


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

int main() {

	int n; cin >> n;
	vector<int> b(n + 1, 100001);
	for (int i = 1; i < n; i++) {
		cin >> b[i];
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += min(b[i - 1], b[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
# tempt
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N,K = map(int,readline().split())
A = np.array(readline().split(),np.int64)
F = np.array(readline().split(),np.int64)

A.sort(); F.sort(); F=F[::-1]

Asum = A.sum()

def test(x):
    # 全員がx秒以下に収めるための必要コストがK以下である
    return Asum - np.minimum(A,x//F).sum() <= K

left = -1 # 不可能目標
right = 10**13 # 可能目標
while left+1 < right:
    mid = (left+right)//2
    if test(mid):
        right = mid
    else:
        left = mid

answer = right
print(answer)

Measured memory_bytes: 26192
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;



int main() {
    ios_base::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    rep(i,m) {
        int a;
        cin >> a;
        n-=a;
    }
    if (n<0) n=-1;
    cout << n << endl;
    return 0;   
}


Measured memory_bytes: 3652
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		int[][] adj = new int[n][n];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				adj[i][j] = sc.nextInt();
			}
		}
		
		boolean[] visited = new boolean[n];
		int[] costs = new int[n];
		Arrays.fill(costs, Integer.MAX_VALUE);
		costs[0] = 0;
		
		int cost = 0;
		for(int tt = 0; tt < n; tt++){
			int min = Integer.MAX_VALUE;
			int min_pos = -1;
			
			for(int i = 0; i < n; i++){
				if(!visited[i] && costs[i] < min){
					min = costs[i];
					min_pos = i;
				}
			}
			
			visited[min_pos] = true;
			cost += costs[min_pos];
			
			for(int next = 0; next < n; next++){
				costs[next] = Math.min(costs[next], adj[min_pos][next] < 0 ? Integer.MAX_VALUE : adj[min_pos][next]);
			}
		}
		
		System.out.println(cost);
		
	}

	public static class Scanner {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

		public void close() throws IOException {
			br.close();
		}
	}

}

Measured memory_bytes: 22264
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int a, b;
  cin >> a >> b;

  if (a + b >= 24){
    cout << a + b - 24 << endl;
  }else{
    cout << a + b << endl;
  }
}


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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n,a[2][100],i,j;
	cin>>n;
	for (i=0;i<2;i++){
		for (j=0;j<n;j++){
			cin>>a[i][j];
		}
	}
	for (i=0;i<2;i++){
		for (j=0;j<n;j++){
			if (i!=0||j!=0){
				if (i==0){
					a[i][j]+=a[i][j-1];
				}
				else if (j==0){
					a[i][j]+=a[i-1][j];
				}
				else {
					a[i][j]+=max(a[i-1][j],a[i][j-1]);
				}
			}
		}
	}
	cout<<a[1][n-1];
	return 0;
}

Measured memory_bytes: 256
import numpy as np
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

class Polynomial:
    def __init__(self,dim=0,const=1):
        self.values = [(dim,const)]
    def __add__(self,other):
        return self.values + other.values


class PolySolver:
    def __init__(self,size,init_val=1):
        self.size = size
        self.f = np.zeros(size, np.int64)
        self.f[0] = init_val


    def multiple(self,polynomial,MOD): # const1 * x^dim1 + const2 * x^dim2 + ... をfにかけ合わせる
        new_F = np.zeros(self.size, np.int64)
        for dim,const in polynomial:
            if dim != 0:
                g = np.zeros(self.size, np.int64)
                g[dim:] += self.f[:-dim] # dim分係数情報をずらす
            else:
                g = const * self.f.copy()

            new_F += g

        self.f = new_F
        self.f %= MOD
    
    def add(self,polynomial,MOD): # const1 * x^dim1 + const2 * x^dim2 + ... をfに足す
        for dim,const in polynomial:
            self.f[dim] += const
            self.f %= MOD

    def get_coefficient(self,dim):
        return self.f[dim]



INF=10**20
def main():
    N,S=mi()
    A=list(mi())
    MOD=998244353

    F = PolySolver(3010,init_val=0)
    ans = 0
    for i in range(N):
        f = Polynomial(dim=A[i]) + Polynomial(const=1)
        F.add(Polynomial(const=1).values,MOD)
        F.multiple(f,MOD)
        ans += F.get_coefficient(S)
    
    print(ans % MOD)
    


if __name__ == "__main__":
    main()


Measured memory_bytes: 27500
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a * 500 >= b) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 24148
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}

int main() {
    string S;
    cin >> S;
    vector<char> s;
    rep(i, S.size()) {
        if (S[i] == S[i + 1]) continue;
        s.push_back(S[i]);
        // cout << s[i] << ' ';
    }
    cout << s.size() - 1 << endl;
}


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

const int N = 1e5 + 5, mod = 1e9 + 7, inf = INT_MAX;

int par[N], rnk[N];
ll siz[N];

int findp(int x)
{
    return (par[x] == x? x: par[x] = findp(par[x]));
}

bool iscon(int x, int y)
{
    return (findp(x) == findp(y));
}

void con(int x, int y)
{
    int px = findp(x), py = findp(y);
    if (rnk[px] > rnk[py])
        par[py] = px;
    else if (rnk[px] < rnk[py])
        par[px] = py;
    else
        par[px] = py, rnk[px]++,
        siz[py] += siz[px];
}

int main()
{
    //ios::sync_with_stdio(false);cin.tie(nullptr);ios_base::sync_with_stdio(false);
    ll n, m;
    pair<int, int> a[N];
    cin >> n >> m;
    ll beg = n * (n - 1) / 2;
    for (int i = 1; i <= n; i++)
        siz[i] = 1, par[i] = i;
    stack<ll> s;
    for (int i = 0; i < m; i++)
        cin >> a[i].first >> a[i].second;
    for (int i = m--; i > -1; i--)
    {
        if (!iscon(a[i].first, a[i].second))
            beg -= siz[par[a[i].first]] * siz[par[a[i].second]],
                    con(a[i].first, a[i].second);
        s.push(beg);
    }
    s.pop();
    while (!s.empty())
        cout << s.top() << endl,
                s.pop();
    return 0;
}

Measured memory_bytes: 7028
N, M, X = map(int, input().split(' '))
price, exp, rst = [], [], -1
for i in range(N):
    ls = list(map(int, input().split(' ')))
    price.append(ls[0])
    exp.append(ls[1:])
for i in range(1 << N):
    price_combi, exp_combi, exp_rst, cnt = [], [], [0] * M, []
    for j in range(N):
        if (i >> j) & 1:
            price_combi.append(price[j])
            exp_combi.append(exp[j])
    for s in range(len(exp_combi)):
        for t in range(M):
            exp_rst[t] += exp_combi[s][t]
    [cnt.append(i) for i in exp_rst if i >= X]
    if len(cnt) == M:
        if rst == -1:
            rst = sum(price_combi)
        else:
            rst = min(rst, sum(price_combi))
print(rst)

Measured memory_bytes: 9252
K = gets.to_i

if K == 1
    puts 1
    exit
end

if K.even?
    puts -1
    exit
end

if K % 5 == 0
    puts -1
    exit
end

x = 7
result = 1
while x % K != 0 do
    while x < K do
        x = x * 10 + 7
        result += 1
    end
    x = x % K

end
puts result


Measured memory_bytes: 14308
#include <stdio.h>
int is_prime(int n){
	int i;
	for(i=2;i<n;i++){
		if(n%i==0)
			return 0;
	}
	return 1;
}

int main(void){
	int n,i;
	while(scanf("%d",&n)!=EOF){
		for(i=n-1;;i--){
			if(is_prime(i)){
				printf("%d ",i);
				break;
			}
		}
		for(i=n+1;;i++){
			if(is_prime(i)){
				printf("%d\n",i);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
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; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }


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

    int L = S/100;
    int R = S%100;

    if (1<=L && L<=12){
        if(1<=R && R<=12)cout << "AMBIGUOUS" << endl;
        else cout << "MMYY" << endl;
    }
    else{
        if(1<=R && R<=12)cout << "YYMM" << endl;
        else cout << "NA" << endl;
    }


}



Measured memory_bytes: 3568
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: Day of Takahashi
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  printf("%d\n", (a - 1) + (a <= b ? 1 : 0));
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 1000000000000


int main() {
	
	int N;
	scanf("%d",&N);
	
	vector<int> x(N);
	for(int i=0;i<N;i++){
		scanf("%d",&x[i]);
	}
	
	int L;
	scanf("%d",&L);
	
	vector<vector<int>> next(20,vector<int>(N));
	
	for(int i=0;i<N;i++){
		auto it = upper_bound(x.begin(),x.end(),x[i]+L);
		it--;
		
		next[0][i] = distance(x.begin(),it);
	}
	
	for(int i=1;i<20;i++){
		for(int j=0;j<N;j++){
			next[i][j] = next[i-1][next[i-1][j]];
		}
	}
	/*
	for(int i=0;i<5;i++){
		for(int j=0;j<N;j++){
			cout<<next[i][j]<<',';
		}
		cout<<endl;
	}
	*/
	int Q;
	scanf("%d",&Q);
	
	for(int i=0;i<Q;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		
		a--;b--;
		if(a>b)swap(a,b);
		
		int ans = 0;
		int now = a;
		for(int j=19;j>=0;j--){
			if(next[j][now]<b){
				ans |= (1<<j);
				now = next[j][now];
			}
		}
		
		printf("%d\n",ans+1);
	}
	
    return 0;
}


Measured memory_bytes: 9080
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    a=parseMap(split(readline()))
    ave=sum(a)/n
    ans=1
    for i in 1:n
        if abs(a[ans]-ave)>abs(a[i]-ave)
            ans=i
        end
    end
    println(ans-1)
end
main()

Measured memory_bytes: 111044
#include <bits/stdc++.h>
namespace Task {
const int MAXN = 200000;
int M;
inline void init(const int n) {
    for (M = 1; M < n + 2; M <<= 1)
        ;
}
struct SegmentTree {
    int d[MAXN * 4];
    inline void maintain(int k) { d[k] = std::min(d[k << 1], d[k << 1 | 1]); }
    inline void build() {
        for (register int i = M - 1; i; i--) maintain(i);
    }
    inline int query(int s, int t) const {
        register int ret = INT_MAX;
        for (s = s + M - 1, t = t + M + 1; s ^ t ^ 1; s >>= 1, t >>= 1) {
            (~s & 1) ? ret = std::min(ret, d[s ^ 1]) : 0;
            (t & 1) ? ret = std::min(ret, d[t ^ 1]) : 0;
        }
        return ret;
    }
};
SegmentTree even, odd;
int a[MAXN + 1], pos[MAXN + 1];
struct Node {
    int l, r, x;
    Node(int l, int r, int x) : l(l), r(r), x(x) {}
    inline bool operator<(const Node &b) const { return x > b.x; }
};
template <typename T>
class PriorityQueue : public std::priority_queue<T> {
   private:
#define super std::priority_queue<T>
   public:
    inline void reserve(const int n) { super::c.reserve(n); }
#undef super
};
inline void initRmq(const int n, const int *a) {
    init(n);
    for (register int i = 1; i <= n; i++) {
        if (i & 1) {
            odd.d[M + i] = a[i], even.d[M + i] = INT_MAX;
        } else {
            even.d[M + i] = a[i], odd.d[M + i] = INT_MAX;
        }
    }
    even.build(), odd.build();
}
inline void solve() {
    std::ios::sync_with_stdio(false), std::cin.tie(NULL), std::cout.tie(NULL);
    register int n;
    std::cin >> n;
    for (register int i = 1; i <= n; i++) std::cin >> a[i], pos[a[i]] = i;
    initRmq(n, a);
    static PriorityQueue<Node> q;
    q.reserve(n * 2);
    q.push(Node(1, n, odd.query(1, n)));
    const SegmentTree *t[2] = {&even, &odd};
    while (!q.empty()) {
        Node d = q.top();
        q.pop();
        register int l = d.l, r = d.r;
        register int p1 = pos[d.x], p2 = pos[t[~p1 & 1]->query(p1 + 1, r)];
        std::cout << a[p1] << ' ' << a[p2] << ' ';
        if (l < p1) q.push(Node(l, p1 - 1, t[l & 1]->query(l, p1 - 1)));
        if (p1 < p2 - 1)
            q.push(Node(p1 + 1, p2 - 1, t[~p1 & 1]->query(p1 + 1, p2 - 1)));
        if (p2 < r) q.push(Node(p2 + 1, r, t[~p2 & 1]->query(p2 + 1, r)));
    }
}
}
int main() {
    Task::solve();
    return 0;
}

Measured memory_bytes: 10368
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(n / 100 == n % 10) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 22612
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    string s;
    cin >> s;

    vector<int> ascii(4);
    for(int i = 0 ; i < 4 ; i++){
        ascii[i] = s[i];
    }

    sort(ascii.begin(), ascii.end());
    
    string ret("No");
    if((ascii[0] == ascii[1])
        && (ascii[2] == ascii[3])
        && (ascii[1] != ascii[2])){
            ret = "Yes";
    }
        
    cout << ret << endl;

    return 0;
}



Measured memory_bytes: 256
S = input()
Q = int(input())
query = [input().split() for _ in range(Q)]

switch = 1
top = []
bottom = []

for i in range(Q):
  if query[i][0] == "1":
    switch *= -1

  else:
    f = query[i][1]
    c = query[i][2]
    if switch == 1:
      if f == "1":
        top.append(c)
      else:
        bottom.append(c)
    else:
      if f == "1":
        bottom.append(c)
      else:
        top.append(c)

if switch == 1:
  ans = top[::-1] + list(S) + bottom
else:
  ans = bottom[::-1] + list(S)[::-1] + top
  
print("".join(ans))

Measured memory_bytes: 48300
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<bitset>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<set>
using namespace std;

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)

long long INF=1e9;
const long long mod=2019;
#define ll long long

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n;
    cin>>n;
    cout<<n*n*n<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <chrono>
#include <vector>

using namespace std;
typedef vector<int> targe_nodes;

int rec(vector<targe_nodes> &target_nodes_info, int v, int w, int cur, int p)
{
    if (cur == w)
    {
        return 1;
    }
    else if (cur == v)
    {
        return 0;
    }
    int cnt = 0;
    int next = target_nodes_info[cur][0] + target_nodes_info[cur][1] - p;
    cnt = rec(target_nodes_info, v, w, next, cur);
    return cnt;
}

int main()
{
    int N, M, a, b;
    cin >> N >> M;
    vector<targe_nodes> target_nodes_info(N + 1);
    for (int i = 0; i < M; i++)
    {
        cin >> a >> b;
        target_nodes_info[a].push_back(b);
        target_nodes_info[b].push_back(a);
    }
    int deg4_node_cnt = 0;
    int deg6_node_cnt = 0;
    for (int i = 1; i < N + 1; i++)
    {
        int deg_i = target_nodes_info[i].size();
        if (deg_i % 2 != 0)
        {
            cout << "No"
                 << "\n";
            return 0;
        }
        if (deg_i >= 6)
        {
            deg6_node_cnt += 1;
        }
        else if (deg_i == 4)
        {
            deg4_node_cnt += 1;
        }
    }

    if (deg6_node_cnt >= 1)
    {
        cout << "Yes"
             << "\n";
        return 0;
    }

    if (deg4_node_cnt >= 3)
    {
        cout << "Yes"
             << "\n";
        return 0;
    }
    else if (deg4_node_cnt == 2)
    {
        vector<int> deg4_node;
        for (int i = 1; i < N + 1; i++)
        {
            if (target_nodes_info[i].size() == 4)
            {
                deg4_node.push_back(i);
            }
        }
        int v = deg4_node[0];
        int w = deg4_node[1];
        int path_cnt = 0;
        for (int i = 0; i < 4; i++)
        {
            path_cnt += rec(target_nodes_info, v, w, target_nodes_info[v][i], v);
        }
        if (path_cnt == 4)
        {
            cout << "No"
                 << "\n";
            return 0;
        }
        else if (path_cnt == 2)
        {
            cout << "Yes"
                 << "\n";
            return 0;
        }
    }
    else if (deg4_node_cnt <= 1)
    {
        cout << "No"
             << "\n";
        return 0;
    }
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define loop(i, a, b) for (int i = a; i < (int)(b); i++)


int main() {
    int N, K;
    cin >> N;
    string S;
    cin >> S;
    cin >> K;

    char c = S[K - 1];
    string ans = "";
    for (char d : S) {
        if (c == d) {
            ans += c;
        } else {
            ans += "*";
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int n, a[100], i, j;
	
	scanf("%d", &n);

	for (i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}

	for (j = n-1; j >= 0; j--)
	{
		if (j < n-1)
		{
			printf(" ");
		}
		printf("%d", a[j]);
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 600
s = raw_input()
p = 0
ans = 0
while p < len(s):
    joi = 'JOI'
    cnt = [0] * 3
    for i in xrange(3):
        while p < len(s) and s[p] == joi[i]:
            cnt[i] += 1
            p += 1

    if cnt[0] >= cnt[1] and cnt[1] <= cnt[2]:
        ans = max(ans, cnt[1])

print ans

Measured memory_bytes: 5320
import java.util.*;
public class Main{
	public static void main(String args[]){  
  		Scanner sc = new Scanner(System.in);
      
      	int a = sc.nextInt();
      	int b = sc.nextInt();
      
      	if((a*b)%2==0){
          System.out.println("Even");
        } else{
          System.out.println("Odd");
        }
    }
}

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

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

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#define N 2005
using namespace std;

int n, x, w[N], b[N], dw[2*N][N], db[2*N][N], dp[N][N];
char c;
int main() {
	int i, j;
	cin>>n;
	for(i=1; i<=2*n; i++) {
		for(j=1; j<=n; j++) dw[i][j] = dw[i-1][j], db[i][j] = db[i-1][j];
		cin>>c>>x;
		if(c=='W') {
			w[x] = i;
			for(j=x; j; j--) dw[i][j]++;
		} else {
			b[x] = i;
			for(j=x; j; j--) db[i][j]++;
		}
	}
	memset(dp, 0x3f, sizeof(dp));
	dp[0][0] = 0;
	for(i=0; i<=n; i++) for(j=0; j<=n; j++) {
		if(i) dp[i][j] = min(dp[i][j], dp[i-1][j] + dw[w[i]][i+1] + db[w[i]][j+1]);
		if(j) dp[i][j] = min(dp[i][j], dp[i][j-1] + dw[b[j]][i+1] + db[b[j]][j+1]);
	}
	cout<<dp[n][n];
	return 0;
}

Measured memory_bytes: 78720
{-# LANGUAGE BangPatterns #-}

module Main
  ( main
  )
where

import           Control.Applicative
import           Control.Monad
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as MV
import           Control.Monad.ST
import           Data.Ord

parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine

main = do
  n <- readInt
  print $ (n + 1) `div` 2

Measured memory_bytes: 380
import java.util.*;

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

        int N = sc.nextInt();
        int[] H = new int[N];
        for(int i = 0; i < N; i++){
            H[i] = sc.nextInt();
        }
        sc.close();
        if(N!=1){
        int[] a  = new int[N-1];
        for(int i = 0; i < N-1; i++){
            if(i==0){
                if(H[i] >= H[i+1])
                    a[i] = 1;
                else
                    a[i] = 0;
            } else {
                if(H[i] >= H[i+1])
                    a[i] = a[i-1]+1;
                else
                    a[i] = 0;
            }
        }
        Arrays.sort(a);
        System.out.println(a[N-2]);
    } else
        System.out.println(0);
    }
}

Measured memory_bytes: 52428
#include <iostream>
#include <vector>
#include <stack>
#include <queue>

using namespace std;

static const long long FAR = (1LL << 29);
static const int N = 100000;

int n, m;
bool visited[N];
int p[N];

vector<int> G[N];
vector<int> sorted;

void bs(int i) {
	queue<int> q; q.push(i);
	visited[i] = true;

	while (!q.empty()) {
		int u = q.front(); q.pop();
		visited[u] = true;
		sorted.push_back(u);

		for (int i = 0; i < G[u].size(); ++i) {
			int v = G[u][i];
			p[v]--;
			if (p[v] == 0 && !visited[v]){
				q.push(v);
				visited[v] = true;
			}
		}
	}
}

void ts(){
	for (int i = 0; i < n; ++i){
		visited[i] = false;
		p[i] = 0;
	}

	for (int u = 0; u < n; ++u) {
		for (int i = 0; i < G[u].size(); ++i){
			int v = G[u][i];
			p[v]++;
		}
	}
	for (int i = 0; i < n; ++i){
		if (p[i] == 0 && !visited[i]) bs(i);
	}

	for (int i = 0; i < sorted.size(); ++i) cout << sorted[i] << endl;
}

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

	for (int i = 0; i < m; ++i) {
		int u, v; cin >> u >> v;
		G[u].push_back(v);
	}

	ts();

	return 0;
}

Measured memory_bytes: 6028