akhauriyash/Code-Regression huggingface dataset:
n = int(input())

a = list(map(int, input().split()))

b = list(map(int, input().split()))

c = list(map(int, input().split()))

ans = 0
ans = sum(b)

for i in range(n-1):
    if a[i]+1 == a[i+1]:
        ans += c[a[i]-1]

print(str(ans))

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

int n;

int Query(int x) {
  static char str[13];
  printf("%d\n", x);
  fflush(stdout);
  scanf("%s", str);
  if (!strcmp(str, "Vacant")) exit(0);
  if (!strcmp(str, "Male")) return 0;
  return 1;
}

int main() {
  scanf("%d", &n);
  int l = 0, r = n - 1, t0 = Query(l);
  while (l <= r) {
    int m = (l + r) >> 1;
    if (((m & 1) ^ Query(m)) == t0)
      l = m + 1;
    else r = m - 1;
  }
  return 0;
}

Measured memory_bytes: 760
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var xn = Console.ReadLine().Split()
                .Select(int.Parse)
                .ToArray();
            int x = xn[0];
            int n = xn[1];

            if (n == 0)
            {
                Console.WriteLine(x);
            }

            else
            {
                var p = Console.ReadLine().Split()
                    .Select(int.Parse)
                    .ToArray();

                int result1 = 0;
                int result2 = 0;

                for (int i = 0; i < 100; i++)
                {
                    if (p.Contains(x - i))
                        continue;
                    else
                    {
                        result1 = x - i;
                        break;
                    }
                }

                for (int i = 0; i < 100; i++)
                {
                    if (p.Contains(x + i))
                        continue;
                    else
                    {
                        result2 = x + i;
                        break;
                    }
                }

                if (x - result1 <= result2 - x)
                    Console.WriteLine(result1);
                else
                    Console.WriteLine(result2);
            }
        }
    }
}


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

bool is_heiho(int n){
	for(int i = 0; i * i <= n; i++){
		if(i * i == n){
			return true;
		}
	}
	return false;
}

int main(){
	int a, b, c;
	scanf("%d%d", &a, &b);
	if(b < 10){
		c = a * 10 + b;
	}
	else if(b < 100){
		c = a * 100 + b;
	}
	else{
		c = a * 1000 + b;
	}
	if(is_heiho(c)){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define vi vector<int>
#define vl vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>

int main(){
    int n;
    int ans=0;
    cin>>n;

    rep(i,n+1){
        if(i==0)continue;
        if(i>=10 && i<=99)continue;
        if(i>=1000 && i<=9999)continue;
        if(i>=100000 && i<=999999)continue;
        if(i>=10000000 && i<=99999999)continue;
        ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<vector>
#include<queue>
#include<stdio.h>
#include<map>
#include<set>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#define mp make_pair
using namespace std;
typedef long long ll;
inline ll in()
{
    ll res=0,p=1;
    char c=getchar();
    while(c<'0'||c>'9') {if(c=='-') p=-1; c=getchar();}
    while(c>='0'&&c<='9') res=res*10+c-48,c=getchar();
    return p*res;
}
void out(ll x)
{
    if (x>9) out(x/10);
    putchar(x%10+48);
}
void outc(ll x)
{
    if (x<0){
        putchar('-');
        out(-x);
    }else out(x);
    putchar(32);
}
void outn(ll x)
{
    if (x<0){
        putchar('-');
        out(-x);
    }else out(x);
    putchar(10);
}
const int mod = 1e9 + 7, inf = 0x3f3f3f3f;
//const double pi = acos(-1.0);
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int dx[4] = {0, 0, -1, 1}, dy[4] = {1, -1, 0, 0};

int gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll quickpow(ll x, int k)
{
    ll res = 1;
    while(k){
        if(k & 1) res = (res * x) % mod;
        k >>= 1, x = (x * x) % mod;
    }
    return res;
}
//ll C(int n, int m){return (fac[n] * quickpow((fac[m] * fac[n - m]) % mod, mod - 2)) % mod;}
//Unaccepted
const int maxn = 2e5 + 10;
int a[maxn], pre[maxn], suf[maxn];
int main()
{
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    pre[1] = a[1];
    suf[n] = a[n];
    for (int i = 2; i <= n; ++i){
        pre[i] = max(pre[i - 1], a[i]);
    }
    for (int i = n - 1; i >= 1; --i){
        suf[i] = max(suf[i + 1], a[i]);
    }
    for (int i = 1; i <= n; ++i){
        cout << max(pre[i - 1], suf[i + 1]) << '\n';
    }
	return 0;
}


Measured memory_bytes: 4096
import java.util.*;

/**
 * PrintAFrame
 */
public class Main {

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

        out_of_loop: while (true) {
            int a = Integer.parseInt(sc.next());
            int b = Integer.parseInt(sc.next());

            if (a == 0 && b == 0) {
                break out_of_loop;
            }

            for (int i = 0; i < a; i++) {
                for (int j = 0; j < b; j++) {
                    if (j == 0 || j == b - 1 || i == 0 || i == a - 1) {
                        System.out.print("#");
                    } else {
                        System.out.print(".");
                    }
                }
                System.out.println("");
            }
            System.out.println("");
        }
        sc.close();
    }
}


Measured memory_bytes: 35136
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
#define int long long
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int power(int x, int y, int p)  
{  
    int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}
signed main()
{
    #ifdef _SUBLIME
    ifstream cin("input.txt");
    ofstream cout("output.txt");
    #endif
    int n,a,b,c;
    cin>>n;
    a = power(10,n,1000000007);
    a = (a - 2ll*power(9,n,1000000007))%(1000000007ll);
    a = (a + power(8,n,1000000007))%(1000000007ll);
    a = (a + 1000000007ll)%(1000000007ll);
    cout<<a<<endl;
    return 0;
}

Measured memory_bytes: 3556
import copy
num =int(input())

l = input().split()

def ccompare( p, q):
    return ord(p[1]) - ord(q[1])


def bsort(l):
    a = copy.copy(l)
    for i in range(len(a)):
        for j in reversed(range(i+1,len(a))):
            if ccompare(a[j],a[j-1]) < 0:
                tmp = a[j-1]
                a[j-1] = a[j]
                a[j] = tmp
    return a
def ssort(l):
    b = copy.copy(l)
    for i in range(len(b)):
        minj = i
        for j in range(i,len(b)):
            if ccompare(b[j], b[minj]) < 0:
                minj = j
        tmp = b[minj]
        b[minj] = b[i]
        b[i] = tmp
    return b
    
def show(lst):
    for i in range(len(lst)):
        print(lst[i], end="")
        if i < len(lst)-1:
            print(" ", end="")
        else:
            print()

def complist(s,t):
    for i in range(len(s)):
        if s[i] != t[i]:
            return False
    return True

bres = bsort(l)
sres = ssort(l)
show(bres)
print("Stable")
show(sres)
if complist(bres, sres):
    print("Stable")
else:
    print("Not stable")



Measured memory_bytes: 6344
import math
from functools import reduce

n = int(input())
ans = 0

for i in range(1,n+1):
  sign = 1
  for j in range(i,n+1):
    if sign != 1:
      sign = 2
    for k in range(j,n+1):
      if sign == 1:
        judge = 1
        sign = 2
      elif sign == 2:
        judge = 3
        if i != j:
          sign = 0
      elif sign == 0:
        judge = 6
      
      ans = ans + judge*reduce(math.gcd, [i,j,k])
#      print(i,j,k)
      

print(ans)

Measured memory_bytes: 9552
from sys import stdin
input = stdin.readline().split()
N, L = int(input[0]), int(input[1])
val = 0
for i in range(1,N+1):
    # print(L + i - 1)
    val +=  L + i - 1
# print(val)
if L <= 0 and (L + N - 1) >= 0:
    print(val)
elif L <= 0 and (L + N - 1) < 0:
    print(val - L - N + 1)
else:
    print(val - L)

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

const int N = 1002;

int n,m,ans;
char g[N][N];
vector<pair<int,int>> src;
int d[N][N];
bool vis[N][N];

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

void bfs(vector<pair<int,int>> s){
    queue<pair<int,int>> q;
    for(int i=0;i<s.size();i++){
        q.push(s[i]);
        vis[s[i].first][s[i].second] = 1;
        d[s[i].first][s[i].second] = 0;
    }
    while(!q.empty()){
        int x = q.front().first;
        int y = q.front().second;
        q.pop();
        for(int i=0;i<4;i++){
            if(!vis[x + dx[i]][y + dy[i]] && g[x + dx[i]][y + dy[i]] != '#'){
                q.push({x + dx[i], y + dy[i]});
                vis[x + dx[i]][y + dy[i]] = 1;
                d[x + dx[i]][y + dy[i]] = d[x][y] + 1;
                ans = max(ans, d[x + dx[i]][y + dy[i]]);
            }
        }
    }
}

int main(){
    /*#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
    #endif*/
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;

    cin>>n>>m;
    for(int i=0;i<=n+1;i++){
        for(int j=0;j<=m+1;j++){
            g[i][j] = '#';
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>g[i][j];
            if(g[i][j] == '#'){
                src.push_back({i, j});
            }
        }
    }

    bfs(src);

    cout<<ans;

    return 0;
}

Measured memory_bytes: 29928
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
ll modpow(ll a, ll b, ll m) {
    if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll h = modpow(a, b / 2, m);
        return h * h % m;
    } else {
        return a * modpow(a, b - 1, m) % m;
    }
}
ll comb(ll a, ll b, ll m) {
    if (b > a - b) {
        return comb(a, a - b, m);
    }
    ll c = 1, d = 1;
    REP(i, b) {
        c *= (a - i);
        d *= (b - i);
        c %= m;
        d %= m;
    }
    return c * modpow(d, m - 2, m) % m;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N);
    ll res0 = 0;
    REP(i, N) {
        cin >> A[i];
        if (i % 2 == 0) {
            res0 += A[i];
        } else {
            res0 -= A[i];
        }
    }
    vector<ll> res(N, 0);
    res[0] = res0;
    FOR(i, 1, N, 1) {
        res[i] += A[i - 1] * 2 - res[i - 1];
    }
    REP(i, N) {
        cout << res[i] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin>>s;
  vector<int> v;
  for(int i=0;i<s.size();i++){
    if(s[i]=='0')v.push_back(0);
    if(s[i]=='1')v.push_back(1);
    if(s[i]=='B'){
      if(v.size()>0)v.pop_back();
    }
  }
  for(int i=0;i<v.size();i++)cout<<v[i];
  cout<<endl;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void) {
  int i, j, k, n, w;
  scanf("%d%d", &n, &w);
  int dp[w + 1], v[n], we[n];
  for(i = 0; i <= w; ++i) dp[i] = 0;
  for(i = 0; i < n; ++i) scanf("%d%d", &v[i], &we[i]);
  for(i = 0; i < n; ++i) for(j = 0; j < w; ++j) if(j + we[i] <= w && dp[j + we[i]] < dp[j] + v[i]) dp[j + we[i]] = dp[j] + v[i];
  int ans = 0;
  for(i = 0; i <= w; ++i) if(ans < dp[i]) ans = dp[i];
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 2780
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>

#define rep(i,n) for((i)=0;i<(int)(n);i++)
#define max(a,b) (a < b ? b : a)
#define min(a,b) (a > b ? b : a)

using namespace std;


int main() {
	int A,B,T;
  cin >> A >> B >> T;
  cout << T/A *B;


}


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

template<int D, typename T>
struct vec : public vector<vec<D - 1, T>> {
  static_assert(D >= 1, "vector dimension must be greater than zero!");
  template<typename... Args>
  vec(int n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)) {
  }
};
template<typename T>
struct vec<1, T> : public vector<T> {
  vec(int n = 0, const T& val = T()) : vector<T>(n, val) {
  }
};

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int N, M, K;
  cin >> N >> M >> K;
  vec<2, int> g(N + 1, M + 1, 0);

  for(int i = 0; i < K; ++i) {
    int r, c, v;
    cin >> r >> c >> v;
    g[r][c] = v;
  }

  auto maxf = [](auto& x, auto y) {
    x = max(x, y);
  };

  vec<2, long long> dp(M + 1, 4);
  for(int i = 1; i <= N; ++i) {
    vec<2, long long> new_dp(M + 1, 4);
    for(int j = 1; j <= M; ++j) {
      auto x = *max_element(dp[j].begin(), dp[j].end());
      for(int k = 0; k <= 3; ++k) {
        maxf(new_dp[j][k], new_dp[j - 1][k]);
        maxf(new_dp[j][k], x);
        if(k) maxf(new_dp[j][k], g[i][j] + new_dp[j - 1][k - 1]);
        if(k) maxf(new_dp[j][k], g[i][j] + x);
      }
    }
    swap(dp, new_dp);
  }

  cout << *max_element(dp[M].begin(), dp[M].end()) << '\n';
}

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

int main(){
	string a = "keyence" ;
  	string s ;
  	cin >> s ;
  	int j = 0 ;
  	int k = 0 ;
  	bool ok = false ;
  	for(int b = 0 ; b <(int) s.size() ; b++){
    	if(s[b] == a[j])
          j++ ;
      	else
          break ;
    }
  	for(int b = 0 ; b < (int) s.size() ; b++){
    	if(s[s.size()-1 - b] == a[6-k])
          	k++ ;
        else
        	break ;
    }
    cerr << (j+k) << endl ;
  	if(j+k >= 7)
      cout << "YES\n" ;
  	else
      cout << "NO\n" ;
}


Measured memory_bytes: 256
def examA():
    S = SI(); N = len(S)
    prev = S[0]; cur = ""
    k = 0; ans = 1
    while(k<N-1):
        k +=1
        cur += S[k]
        if cur==prev:
            continue
        prev = cur
        cur = ""
        ans +=1
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,inf
mod = 10**9 + 7
inf = 10**18

if __name__ == '__main__':
    examA()


Measured memory_bytes: 4008
n = int(input())
s = [0, 0, 0]
ans = 'Yes'
for i in range(n):
  l = list(map(int, input().split()))
  diff_t = l[0] - s[0]
  diff_x = abs(s[1] - l[1])
  diff_y = abs(s[2] - l[2])
  s = [l[0], l[1], l[2]]
  if diff_x + diff_y > diff_t or (diff_t - diff_x - diff_y) % 2 != 0:
    ans = 'No'
print(ans)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
    int N;
    string S;
    int ans = 0;
    cin >> N >> S;
    for(int i=0;i<N-2;i++){
        if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C')ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  vector<string> vs;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 1; j <= k; j++) {
      string str = s.substr(i, j);
      vs.push_back(str);
    }
  }
  sort(vs.begin(), vs.end());
  vs.erase( unique(vs.begin(),vs.end()), vs.end());
  cout<< vs[k - 1] << endl;
}


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

int main()
{
    const int N = 3000;
    vector<int> x(N);
    vector<int> y(N);
    for (size_t i = 0; i < N; i++)
    {
        cin >> x[i];
        cin >> y[i];

        if (x[i] == 0 && y[i] == 0)
        {
            break;
        }
    }

    for (size_t i = 0; i < N; i++)
    {
        if (x[i] == 0 && y[i] == 0)
        {
            break;
        }

        if (x[i] < y[i])
        {
            cout << x[i] << " " << y[i] << endl;
        }
        else
        {
            cout << y[i] << " " << x[i] << endl;
        }
    }
}



Measured memory_bytes: 3028
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

double startTime;
double getCurrentTime() {
	return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}

const int N = (int)1e6 + 7;
char s[N];
int a[N];
int n;

int main()
{
	startTime = (double)clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	scanf("%s", s);
	for (int i = 0; i < n; i++)
		a[i] = (int)(s[i] - '1');
	bool only02 = true;
	for (int i = 0; i < n; i++)
		only02 &= (a[i] != 1);
	if (!only02) {
		int ans = 0;
		for (int i = 0; i < n; i++)
			if ((i & (n - 1)) == i)
				ans ^= a[i] & 1;
		printf("%d\n", ans);
		return 0;
	}
	int ans = 0;
	for (int i = 0; i < n; i++)
		if ((i & (n - 1)) == i)
			ans ^= a[i] & 2;
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 5120
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> pippi;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<62;
int iinf=1<<30;
double pi=3.141592653589793238462643383279L;
double eps=1e-8;
#define rep(i,m,n) for(int i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
//#define endl "\n"
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<int,int,custom_hash>
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    if(k<0)return 0;
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll a,v,b,w;cin>>a>>v>>b>>w;
    ll t;cin>>t;
    ll d=abs(a-b);
    ll vd=w-v;
    if(vd>=0){
        cout<<"NO"<<endl;
        return 0;
    }
    if(-vd*t>=d)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


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

int main(){
  int N, C, K; cin >> N >> C >> K;
  vector<int> A(N);
  rep(i,N){
    cin >> A[i];
  }
  
  sort(A.begin(), A.end());
  int res = 0;
  for (int i = 0; i < N;){
    res++;
    int start = i;
    while (i < N && A[i] - A[start] <= K && i - start < C) ++i;
  }
  
  cout << res << endl;
    
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class354
    {
        static void Main()
        {
            var r = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int A = r[0], B = r[1], C = r[2], X = r[3], Y = r[4];
            if (A + B > 2*C)
            {
                Console.WriteLine(Math.Min(Math.Min(X,Y)*2*C+(X>Y?(X-Y)*A:(Y-X)*B),Math.Max(X,Y)*2*C));

            }
            else
            {
                Console.WriteLine(X*A+Y*B);
            }
        }
    }
}


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


int main(){
    ll n,k,x,y;
    cin>>n>>k>>x>>y;
    ll ans=0;
    for(int i=1;i<=n;i++){
        if(i<=k) ans+=x;
        else ans+=y;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3552
n,q=map(int,input().split())
s=input()
a=[0]
current=0
for i in range(n-1):
  if s[i]=='A' and s[i+1]=='C':
    current+=1
  a.append(current)
for i in range(q):
  x,y=map(int,input().split())
  if y==1:
    print(0)
    continue
  print(a[y-1]-a[x-1])

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

int main()
{
  long long N,K,result=0;
  cin >> N >> K;
  long long H[N];
  for(long long i=0;i<N;i++){
    cin >> H[i];
  }
  sort(H,H+N);

  for(long long i=0;i<N-K;i++){
    result += H[i];
  }

  cout << result << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>

int main(void){

int a,b,c,x,y;

scanf("%d%d%d%d%d",&a,&b,&c,&x,&y);

if(a+b < c*2){
printf("%d",a*x + b*y);
}

else{
if (x < y) {
if(2*c < b){
printf("%d",y*2*c);
}
else{
int min = x; int z = y-x;
printf("%d",min*2*c + z*b);
}
}

else {
if(2*c < a){
printf("%d",x*2*c);
}
else{
int min = y; int z = x-y;
printf("%d",min*2*c + z*a);
}
}
}
return 0;

}

Measured memory_bytes: 128
'use strict'

function Main(input) {
  const S = input.split('\n')[0];
  const T = input.split('\n')[1];

  const T2 = T + T;

  

  if (T2.indexOf(S) !== -1) {
    console.log('Yes');
  } else {
    console.log('No');
  }

}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 21064
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define INF 1e9+7
#define LLINF 1e18
using namespace std;
const ll MOD = 1e9 +7;




int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;
    cin>>a>>b;
    if(a<=0 && b>=0){
        cout <<"Zero"<<endl;
    }
    else if(a<0 &&b<=0){
        if((b-a)%2==0) cout<<"Negative"<<endl;
        else cout<<"Positive"<<endl;
    }
    else if(a==0 &&b>0){
        cout <<"Zero"<<endl;
    }
    else if(a>0 &&b>0){
        cout<<"Positive"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
def calc_divisor(x):
    divisor = []
    for i in range(1, int(x ** 0.5) + 1):
        if x % i == 0:
            divisor.append(i)
            if i != x // i:
                divisor.append(x // i)
    return divisor


N = int(input())
ans = len(calc_divisor(N - 1)) - 1

cand = sorted(calc_divisor(N))[1:]
for k in cand:
    x = N
    while x % k == 0:
        x //= k
    if x % k == 1:
        ans += 1

print(ans)


Measured memory_bytes: 65720
import java.util.*;
 public class Main {
    public static void main(String[] args) {
        Scanner sc = new  Scanner(System.in);
      String s = sc.next();
      String t = sc.next();
      int count =0;
      for(int i=0;i<s.length();i++){
         outer: for(int j =i;j<s.length();j++){
              if(s.charAt(i)!=t.charAt(j)){
                  count++;
               break outer;
              }else{
                  break outer;
              }
          }
      }
      System.out.println(count);
        
    


}

    }
    


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

using namespace std;

#define int long long

const int INF = 1e18;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    vector <int> a(t);
    for (int& it : a) {
        cin >> it;
    }
    sort(a.begin(), a.end());
    int n = a[t - 1], m = a[0];
    for (int i = 1; i + 1 < t; ++i) {
        if (abs(n - 2 * a[i]) < abs(n - 2 * m)) {
            m = a[i];
        }
    }
    cout << n << " " << m << "\n";
    return 0;
}

Measured memory_bytes: 1024
def mod(i,j):
    if i%j == 0:
        return [str(0), i//j]
    else:
        return [str(-(i%j)),(i//j)+1]

n = int(input())
w = ""
if n == 0:
    w = 0
else:
    while n != 0:
        i,j = mod(n,-2)
        w = i + w
        n = j
print(w)

Measured memory_bytes: 9212
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>


using namespace std;

int main()
{
    int k[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int n;
    cin >> n;
    cout << k[n-1] << endl;

}



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

class Dice {

public:

  int a1, a2, a3, a4, a5, a6;

  string D;

  Dice(int x) {

    a1 = a2 = a3 = a4 = a5 = a6 = x;

  }

  void rotateFront() {

    int newa1 = a5;
    
    a5 = a6;

    a6 = a2;

    a2 = a1;

    a1 = newa1;

  }

  void rotateRight() {

    int newa1 = a3;

    a3 = a6;

    a6 = a4;

    a4 = a1;

    a1 = newa1;

  }

};

int main(void) {

  Dice d1(0);

  int i;

  cin >> d1.a1 >> d1.a2 >> d1.a3 >> d1.a4 >> d1.a5 >> d1.a6;

  cin >> d1.D;

  for(i = 0; i < d1.D.size(); i++) {

    if(d1.D[i] == 'S') {

      d1.rotateFront();

    } else if (d1.D[i] == 'N') {

      d1.rotateFront();
      d1.rotateFront();
      d1.rotateFront();

    } else if (d1.D[i] == 'W') {

      d1.rotateRight();

    } else if (d1.D[i] == 'E') {

      d1.rotateRight();
      d1.rotateRight();
      d1.rotateRight();

    }

  }

  cout << d1.a1 << endl;

  return 0;

}

Measured memory_bytes: 1204
#include <stdio.h>

int max(int a, int b)
{
    if (a > b)
    {
        return a;
    }
    if (b > a)
    {
        return b;
    }
}
int main()
{
    int n;
    scanf("%d", &n);
    int a[n][3], b[n][3];
    for (int i = 0; i < n; i++)
    {
        scanf("%d%d%d", &a[i][0], &a[i][1], &a[i][2]);
    }
    b[0][0]=a[0][0];
    b[0][1]=a[0][1];
    b[0][2]=a[0][2];
    for (int i = 1; i < n; i++)
    {
        b[i][0]=a[i][0]+max(b[i-1][1],b[i-1][2]);
        b[i][1]=a[i][1]+max(b[i-1][0],b[i-1][2]);
        b[i][2]=a[i][2]+max(b[i-1][0],b[i-1][1]);
    }
    int ans = max(b[n-1][0],max(b[n-1][1],b[n-1][2]));

    printf("%d\n", ans);
}

Measured memory_bytes: 2560
#include "stdio.h"

int main()
{
	int input = 0;
	int a[3];
	int buff = 0;

	int i = 0;
	for(i = 0; i < 3; i++)
	{
		scanf("%d", &input);
		if(input < 1 || input > 10001)
		{
			return 0;
		}
		else
		{
			a[i] = input;
		}
	}

	while(a[0] > a[1] || a[1] > a[2])
{
	if(a[0] > a[1])
	{
		buff = a[1];
		a[1] = a[0];
		a[0] = buff;
	}
	if(a[0] > a[2])
	{
		buff = a[2];
		a[2] = a[0];
		a[0] = buff;
	}
	if(a[1] > a[2])
	{
		buff = a[2];
		a[2] = a[1];
		a[1] = buff;
	}
}

	printf("%d %d %d\n", a[0], a[1],a[2]);
	return 0;
}


Measured memory_bytes: 2096
//There was and will always be only one Chester. RIP legend
//--------------------Life is beautiful--------------------
#include<bits/stdc++.h>
using namespace std;
#define Nilesh ios_base::sync_with_stdio(false);
int fa[200005];
int main()
{
	Nilesh
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
    {
        cin>>a[i];
        fa[a[i]]++;
    }
    int cnt=0;
    int bharo[200005]={0};
    int k1=0;
    for(int i=1;i<=200000;i++)
    {
        if(fa[i]!=0)
        {
            cnt++;
            bharo[k1++]=fa[i];
        }
    }
   // cout<<cnt<<endl;
    sort(bharo,bharo+k1);
    int answer=0;
    if(cnt>k)
    {
        for(int i=0;i<k1;i++)
        {

            answer+=bharo[i];
           // cout<<"added "<<bharo[i]<<endl;
            cnt--;
            if(cnt==k)
                break;

        }
    }
    cout<<answer;

}


Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

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

int main(){
	int n, x, ans = 0;
	cin >> n >> x;
	vector<int> a(n), b(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
		b[i] = abs(x - a[i]);
	}
	ans = b[0];
	for(int i = 1; i < n; i++){
		ans = gcd(ans, b[i]);
	}
	cout << ans << endl;
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int w,h,x,y; cin>>w>>h>>x>>y;
	cout<<setprecision(10)<<0.5*w*h<<' '<<(2*x==w&&2*y==h?1:0)<<endl;

	return 0;
}


Measured memory_bytes: 256
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::f64::consts::PI;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn count(x: i64, y: i64, map: &HashSet<(i64, i64)>) -> usize {
    let mut ans = 0;
    for i in 0..3 {
        for j in 0..3 {
            if map.contains(&(x+i, y+j)) {
                ans += 1;
            }
        }
    }
    ans
}


fn main() {
    let line: Vec<i64> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let h = line[0];
    let w = line[1];
    let n = line[2] as usize;

    let mut map = HashSet::with_capacity(n);
    for i in 0..n {
        let line: Vec<i64> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
        let a = line[0];
        let b = line[1];
        map.insert((a, b));
    }
    let mut memo = vec![HashSet::new(); 10];
    for &(x, y) in map.iter() {
        for i in -2..3 {
            for j in -2..3 {
                let x = x + i;
                let y = y + j;
                if 1 <= x && x <= h-2 && 1 <= y && y <= w-2 {
                    let c = count(x, y , &map);

                    memo[c].insert((x, y));
                }
            }
        }
    }
    let mut ans = (h-2) * (w-2);
    for i in 1..10 {
        ans -= memo[i].len() as i64;
    }
    println!("{}", ans);

    for i in 1..10 {
        println!("{}", memo[i].len());
    }
}


Measured memory_bytes: 73832
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

ll gcm(ll a,ll b);

int main(){
  vint dx = {0,-1,1,0};
  vint dy = {-1,0,0,1};

  int h,w;
  cin >> h >> w;
  vstring s(h);
  rep(i,h) cin >> s[i];
  bool ans = true;
  rep(i,h){
    rep(j,w){
      if(s[i][j] == '#'){
        bool ok = false;
        rep(t,4){
          int x = i + dx[t];
          int y = j + dy[t];
          if(0 <= x && x < h && 0 <= y && y < w){
            if(s[x][y] == '#'){
              ok = true;
            }
          }
        }
        if(!(ok)){
          ans = false;
          break;
        }
      }
    }
    if(!(ans)) break;
  }
  if(ans) cout << "Yes" << endl; else cout << "No" << endl;
}







Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,m,i,j,k,a[55][55];
char c;
int dx[9]={0,-1,-1,-1,0,0,1,1,1},dy[9]={0,-1,0,1,-1,1,-1,0,1};
int main()
{
	cin>>n>>m;
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=m;j++)
		{
			cin>>c;
			if (c=='#') a[i][j]=-1;
		}
	}
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=m;j++)
		{
			if (a[i][j]==-1) continue;
			for (k=1;k<=8;k++)
			{
				if (a[i+dx[k]][j+dy[k]]==-1)
				{
					a[i][j]++;
				}
			}
		}
	}
	for (i=1;i<=n;i++)
	{
		for (j=1;j<=m;j++)
		{
			if (a[i][j]==-1)
			{
				cout<<'#';
			}
			else cout<<a[i][j];
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main (){
	int k,a,b, i;
	int sum=0;
	scanf("%d",&k);
	scanf("%d %d", &a,&b );
	
	for(i = a; i<=b; i++){
		if(i%k == 0){
			printf("OK");
			return 0;
		}
		else{
			continue;
		}
	}
	
	printf("NG");
	return 0;
	
	
	
}

Measured memory_bytes: 1724
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <regex>
#include <bitset>
#include <string>
#include <vector>
#include <iomanip>
#include <sstream>
#include <utility>
#include <iterator>
#include <algorithm>
#include <functional>
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define pq priority_queue<int,vector<int>,greater<int>>
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define INF 9999999999
#define F first
#define S second

using namespace std;

typedef pair<int, int> pi;
typedef pair<int, pi> pp;

int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

int main() {
	string s;
	cin >> s;
	s.size() == 3 ? cout << s[2] << s[1] << s[0] << endl : cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
def cal(i,j):
    if i==1 and j==1: return "R"
    elif i==1 and j==0: return "U"
    elif i==0 and j==1: return "D"
    elif i==0 and j==0: return "L"



import sys

N=int(input())


a=[list(map(int,input().split())) for i in range(N)]
mod=sum(a[0])%2
for i in range(N):
    if sum(a[i])%2!=mod:
        print(-1)
        sys.exit()

if mod==0:
    a=[[ a[i][0]-1 ,a[i][1] ] for i in range(N)]

if mod==0:
    print(32)
    print(1,end=" ")
    for i in range(30): print(2**i, end=" ")
    print(2**30)
else:
    print(31)
    for i in range(30): print(2**i, end=" ")
    print(2**30)

for i in range(N):
    [x,y]=a[i]
    u=bin((x+y+2**31-1)//2)[2:].zfill(31)
    v=bin((x-y+2**31-1)//2)[2:].zfill(31)
    
    if mod==0: s="R"
    else: s=""

    for i in range(30,-1,-1): s=s+cal( int(u[i]),int(v[i]) )
    
    print(s)

Measured memory_bytes: 3444
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in); 
		
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		if(a==b&&b==c&&c==a) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
	}

}

Measured memory_bytes: 23124
#include<stdio.h>
int main(void)
{
	int datap[3],a,b;
	int ih;
	int i,j;
	int x;
	int min=2000;
		for(i=0;i<3;i++){
			scanf("%d",&datap[i]);
				if(min>datap[i]){
					min=datap[i];
				}
		}			
		scanf("%d %d",&a,&b);
		if(a>b){
			j=b;
		}
		else if(a==b){
			j=a;
		}
		else{
			j=a;
		}
	ih=min+j-50;
	printf("%d\n",ih); 
	return 0;
}

Measured memory_bytes: 1020
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  int N, M; 
  cin >> N >> M;

  vector<int> A(N);
  REP(i, N){
    cin >> A[i];
    if(i != 0) A[i] += A[i-1];
    A[i] %= M;
  }

  map<int, int> cnt;
  REP(i, N) cnt[A[i]]++;

  int ans = 0;
  for(auto p : cnt){
    ans += (p.second-1)*p.second/2;
    if(p.first == 0) ans += p.second;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 4992
#include<stdio.h>
#define MAX 9999999

int H, A[MAX];

void maxHeapify (int i) {
  int l, r, largest = 0, cp;
  l = 2 * i;
  r = 2 * i + 1;
  if ( l <= H && A[l] > A[i] ) largest = l;
  else largest = i;
  if ( r <= H && A[r] > A[largest] ) largest = r;
  if ( largest != i ){
    cp = A[i]; 
    A[i] = A[largest]; 
    A[largest] = cp;
    maxHeapify(largest);
  }
}

void buildMaxHeap(int H) {	
	int i;
	for ( i = H/2; i >= 1; i-- ) maxHeapify(i);
}

int main(void) {
  scanf("%d", &H);
  int i;
  for ( i = 1; i <= H; i++ ) scanf("%d", &A[i]);
  
  buildMaxHeap(H);

  for ( i = 1; i <= H; i++ ) {
    printf(" %d", A[i]);
  }
  printf("\n");
  

  
  return 0;
}


Measured memory_bytes: 3680
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(b%a == 0) {
            System.out.println(a + b);
        } else {
            System.out.println(b - a);
        }
    }
}


Measured memory_bytes: 21972
#include <iostream>
#include <string>

using namespace std;

int main() {
    int score_taro = 0;
    int score_hanako = 0;

    string s_taro, s_hanako;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> s_taro >> s_hanako;
        if (s_taro > s_hanako) score_taro += 3;
        else if (s_taro < s_hanako) score_hanako += 3;
        else {score_taro++; score_hanako++;}
    }
    cout << score_taro << ' ' << score_hanako << endl;
    return 0;
}


Measured memory_bytes: 3192
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

typedef long long ll;

const int N=3e5+5,Mo=998244353;

int n,r,g,b,rg,rb,gb;
char s[N];

int main() {
	scanf("%d",&n);
	scanf("%s",s+1);
	int ans=1;
	fo(i,1,3*n) {
		if (s[i]=='R') {
			if (gb) {ans=(ll)ans*gb%Mo;gb--;continue;}
			if (g) {ans=(ll)ans*g%Mo;rg++;g--;continue;}
			if (b) {ans=(ll)ans*b%Mo;rb++;b--;continue;}
			r++;
		}
		if (s[i]=='G') {
			if (rb) {ans=(ll)ans*rb%Mo;rb--;continue;}
			if (r) {ans=(ll)ans*r%Mo;rg++;r--;continue;}
			if (b) {ans=(ll)ans*b%Mo;gb++;b--;continue;}
			g++;
		}
		if (s[i]=='B') {
			if (rg) {ans=(ll)ans*rg%Mo;rg--;continue;}
			if (r) {ans=(ll)ans*r%Mo;rb++;r--;continue;}
			if (g) {ans=(ll)ans*g%Mo;gb++;g--;continue;}
			b++;
		}
	}
	fo(i,1,n) ans=(ll)ans*i%Mo;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define int long long
using namespace std;
const int N = 3e5 + 5, mod = 998244353;
int read() {
	int x = 0, f = 1; char ch;
	while(! isdigit(ch = getchar())) (ch == '-') && (f = -f);
	for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 3) + (x << 1) + (ch ^ 48));
	return x * f;
}
template <class T> T Max(T a, T b) { return a > b ? a : b; }
template <class T> T Min(T a, T b) { return a < b ? a : b; }
int n, len, sp;
int ksm(int x, int y) {
	int res = 1;
	for( ; y; x = x * x % mod, y >>= 1) {
		if(y & 1) res = res * x % mod;
	}
	return res;
}
struct poly {
	int v[N];
	int & operator [] (int x) {return v[x];}
	void fwt(int len) {
		for(int l = 2; l <= len; l <<= 1)
			for(int i = 0, m = l >> 1; i < len; i += l)
				for(int j = i, t; j < i + m; ++ j) 
					t = v[j + m], v[j + m] = (v[j] - t + mod) % mod, v[j] = (v[j] + t) % mod;
	}
	void ifwt(int len) {
		fwt(len);
		int inv = ksm(len, mod - 2);
		for(int i = 0; i < len; ++ i) v[i] = v[i] * inv % mod;
	}
} e, p, s;
signed main() {
	n = read(); len = 1 << n;
	for(int i = 0; i < len; ++ i) sp += (p[i] = read());
	sp = ksm(sp, mod - 2);
	for(int i = 0; i < len; ++ i) p[i] = p[i] * sp % mod;
	p[0] --;
	if(p[0] < 0) p[0] += mod;
	s[0] = len - 1;
	for(int i = 1; i < len; ++ i) s[i] = mod - 1;
	p.fwt(len); s.fwt(len);
	for(int i = 1; i < len; ++ i) e[i] = s[i] * ksm(p[i], mod - 2) % mod;
	e.ifwt(len);
	int x = mod - e[0];
	for(int i = 0; i < len; ++ i) printf("%lld\n", (x + e[i]) % mod);
	return 0;
}


Measured memory_bytes: 9472
def solve():
    n = int(input())
    if n == 0: return False

    ok = [5, 7, 5, 7, 7]

    inputs = [input() for x in range(n)]

    for i in range(n):
        target = 0
        cnt = i
        for v in ok:
            while target < v:
                s = inputs[cnt]
                target += len(s)
                cnt += 1
            if target != v:
                break
            else:
                target = 0
        else:
            print(i + 1)
            return True
    return True
while solve(): pass

Measured memory_bytes: 7732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
const ll INF=1e18+7;
const ll MOD=1e9+7;

int main(){
		ios::sync_with_stdio(false);
		cin.tie(0);
		string s;
		cin>>s;
		ll k,w=0;
		cin>>k;
		ll ans = 0;
		FOR(i,0,s.size()){
			ans++;
			if(s[i]!='1')ans += k;
			if(ans>=k){
				cout<< s[i] <<endl;
				return 0;
			}
		}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define N 200005
ll inf = 1e14;
ll mod = 1e9 + 7;
char en = '\n';

ll abs1(ll x) {
  if (x < 0)
    return -x;
  return x;
}
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

ll dp[N];
pair<ll, ll> arr[N];
ll fact[N];
ll ifact[N];

ll nCr(ll n, ll r) {
  if (n < r)
    return 0;
  return fact[n] * ifact[r] % mod * ifact[n - r] % mod;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  fact[0] = ifact[0] = 1;
  for (ll i = 1; i < N; i++) {
    fact[i] = (i * fact[i - 1]) % mod;
    ifact[i] = power(fact[i], mod - 2, mod);
  }
  memset(dp, 0, sizeof(dp));

  ll h, w, n;
  cin >> h >> w >> n;

  for (ll i = 1; i <= n; i++) {
    cin >> arr[i].first >> arr[i].second;
  }

  n++;
  arr[n].first = 1, arr[n].second = 1;
  sort(arr + 1, arr + n + 1);

  for (ll i = n; i >= 1; i--) {
    dp[i] = nCr((h - arr[i].first) + (w - arr[i].second), (w - arr[i].second));

    for (ll j = i + 1; j <= n; j++) {
      if (arr[j].first >= arr[i].first && arr[j].second >= arr[i].second) {
        dp[i] -=
            nCr((arr[j].first - arr[i].first) + (arr[j].second - arr[i].second),
                (arr[j].second - arr[i].second)) *
            dp[j] % mod;
        if (dp[i] < 0)
          dp[i] += mod;
      }
    }
  }

  cout << dp[1] << en;
  return 0;
}


Measured memory_bytes: 5888
n = int(input())
a = [int(x) for x in input().split()]
mod = 10**9+7
res = [0]*(max(a)+1)
ma = 0
for i in a:
    for j in range(2,int(i**0.5)+1):
        cnt = 0
        while i%j==0:
            i//=j
            cnt+=1
        res[j] = max(res[j],cnt)
    if i!=1:
        res[i] = max(res[i],1)

d = 1
for i in range(max(a)+1):
    if res[i]>0:
        d=d*i**res[i]%mod
ans = 0
for i in range(n):
    m = pow(a[i],mod-2,mod)
    ans = (ans+(d*m)%mod)%mod
print(ans)

Measured memory_bytes: 52572
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;

class P{
public:
	int x,y,cost;
	P(int _x,int _y,int _cost){
		x = _x;
		y = _y;
		cost = _cost;
	}
};

int w,h,cnt;
int t[22][22]; //-1 : ó«, -2 : Ç, 0 : {bg, 1Èã : ê
int g[12][12];
bool closed[22][22];
int dx[] = {-1,1,0,0};
int dy[] = {0,0,-1,1};

void minDist(int sx,int sy){
	queue<P> q;
	q.push(P(sx,sy,0));
	memset(closed,0,sizeof(closed));
	closed[sy][sx] = true;

	while(!q.empty()){
		P p = q.front(); q.pop();

		if(t[p.y][p.x] >= 0){
			g[t[sy][sx]][t[p.y][p.x]] = p.cost;
		}

		for(int i=0;i<4;i++){
			int nx = p.x + dx[i];
			int ny = p.y + dy[i];
			if(nx>=0 && w>nx && ny>=0 && h>ny && t[ny][nx]>=-1 && !closed[ny][nx]){
				closed[ny][nx] = true;
				q.push(P(nx,ny,p.cost+1));
			}
		}
	}
}

int main(void){
	char buff[22];

	while(scanf("%d%d",&w,&h),w||h){
		cnt = 0;
		for(int i=0;i<h;i++){
			scanf("%s",buff);
			for(int j=0;j<w;j++){
				if(buff[j] == '.') t[i][j] = -1;
				else if(buff[j] == 'x') t[i][j] = -2;
				else if(buff[j] == 'o') t[i][j] = 0;
				else t[i][j] = ++cnt;
			}
		}

		memset(g,-1,sizeof(g));
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(t[i][j] >= 0){
					minDist(j,i);
				}
			}
		}

		int ans = 999999999;
		int pass[cnt+1];
		for(int i=0;i<=cnt;i++) pass[i] = i;
		do{
			int sum = 0;
			int i;
			for(i=0;i<cnt;i++){
				if(g[pass[i]][pass[i+1]] == -1) break;
				sum += g[pass[i]][pass[i+1]];
			}
			if(i == cnt && sum < ans) ans = sum;
		}while(next_permutation(pass+1,pass+1+cnt));

		printf("%d\n",ans==999999999 ? -1 : ans);
	}

	return 0;
}

Measured memory_bytes: 936
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, a, b) for(ll i = ll(a); i <= ll(b); i++)
int main()
{
	ll n,m,x,cnt_O=0,cnt_N=0;
	vector<ll> a;
	cin>>n>>m>>x;
	a.resize(m);
	REP(i,0,m-1)
	{
		cin>>a[i];
	}
	REP(i,0,m-1)
	{
		if(x<a[i])
			cnt_O++;
		else
			cnt_N++;
	}
	cout<<min(cnt_O,cnt_N);
}

Measured memory_bytes: 256