akhauriyash/Code-Regression huggingface dataset:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter
#from heapq import heappush, heappop
#import numpy as np
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
#from scipy.sparse import csr_matrix
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

H, W = na()
a = [na() for _ in range(H)]
N = 0
ans = []
for y in range(H):
    for x in range(W):
        #print(y, x, a[y][x])
        if a[y][x] % 2 == 0:
            continue
        else:
            nx = x + 1
            ny = y + 1
            if 0 <= nx < W and a[y][nx] % 2 == 1:
                N += 1
                a[y][nx] += 1
                a[y][x] -=1
                ans.append((y+1, x+1, y+1, nx+1))
            elif 0 <= ny < H and a[ny][x] % 2 == 1:
                N += 1
                a[ny][x] += 1
                a[y][x] -=1
                ans.append((y+1, x+1, ny+1, x+1))
            elif 0 <= ny < H:
                N += 1
                a[ny][x] += 1
                a[y][x] -=1
                ans.append((y+1, x+1, ny+1, x+1))
            elif 0 <= nx < W:
                N += 1
                a[y][nx] += 1
                a[y][x] -=1
                ans.append((y+1, x+1, y+1, nx+1))
print(N)
for x in ans:
    print(*x)

Measured memory_bytes: 32092
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int X,Y,k;
  cin>>X>>Y;
  
  
  if(X%Y==0){
    cout<<-1<<endl;
	return 0;
  }
  
  for(k=1;k<Y;k++){
    if((k*X)%Y!=0){
      cout<<k*X<<endl;
    	return 0;
    }
  }
    cout<<-1<<endl;
	return 0;
}
  

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

int main(){
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  rep(i,n)std::cin >> a[i];


  long long money=1000;
  long long has=0;
  rep(i,n-1){
    if(a[i+1]>a[i] && money>=a[i]){
      has+=money/a[i];
      money-=money/a[i]*a[i];
    }
    else if(a[i+1]<a[i]){
      money+=has*a[i];
      has=0;
    }

  }

  money+=has*a[n-1];

  std::cout << money << '\n';


  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ll long long int
#define N (ll)(1e9+7)
#define T int
#define P pair<T,T>
#define umap unordered_map<T,T>
#define uset unordered_set<T>
#define rep(i,n) for(i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define print(v) for(auto x:v) cout<<x<< " "
#define pb push_back
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int i;
    double v[n];
    rep(i,n)
    	cin>>v[i];
    sort(v,v+n);
    double sum=v[0];
    for(i=1;i<n;i++)
    {
    	sum=(sum+v[i])/2;
    }
    printf("%.10f\n",sum);
    return 0;
}


Measured memory_bytes: 256
n1,n2,n3,n4,n5,n6=map(int,raw_input().split())
act=raw_input()
for i in act:
    if i=="N":
        n11=n1
        n1=n2
        n2=n6
        n6=n5
        n5=n11
    elif i=="S":
        n11=n1
        n1=n5
        n5=n6
        n6=n2
        n2=n11
    elif i=="E":
        n11=n1
        n1=n4
        n4=n6
        n6=n3
        n3=n11
    else :
        n11=n1
        n1=n3
        n3=n6
        n6=n4
        n4=n11
print(n1)




Measured memory_bytes: 4656
n = int(input())
c = [int(input()) for _i in range(n)]
c.append(-1)
dic = {}
dp = [0 for _i in range(n+1)]
dp[n] = 1
mod = 10**9 +7
for i in range(n):
    if c[i-1] != c[i]:
        if c[i] in dic:
            dp[i] = (dp[i-1] + dic[c[i]])%mod
        else:
            dp[i] = dp[i-1]
        dic[c[i]] = dp[i]
    else:
        dp[i] = dp[i-1]
    
print(dp[n-1]%mod)

Measured memory_bytes: 85668
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0) 
#define setbit0(n, i) ((n) & (~(1LL << (i)))) 
#define setbit1(n, i) ((n) | (1LL << (i))) 
#define togglebit(n, i) ((n) ^ (1LL << (i))) 
#define lastone(n) ((n) & (-(n))) 
char gap = 32;
template<typename T> 
ostream& operator<<(ostream &os, const vector<T> &v) { 
    os << '{'; 
    for (const auto &x : v) os << gap << x;
        return os << '}'; 
}
template<typename A, typename B> 
ostream& operator<<(ostream &os, const pair<A, B> &p) {
        return os << '(' << p.first << gap << p.second << ')';
}

template <class T>
void read(T &x) {
    char c;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        ;
    for (x = 0; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + (c & 15);
}
#define ll long long 
#define lll __int128_t
#define pb push_back
#define mp make_pair
typedef pair < int,int> ii;
typedef vector<ii> vii;
typedef vector<ll>vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;
ll dp[101][100005];
ll n,w;
ll weights[1000];
ll value[1000];
ll recurse(ll pos,ll totalweight){
    if(pos>n)
        return 0;
    if(dp[pos][totalweight]!=-1)
        return dp[pos][totalweight];
    ll maxi = recurse(pos + 1, totalweight);
    if(totalweight+weights[pos]<=w){
        maxi = max(maxi, recurse(pos + 1, totalweight + weights[pos]) + value[pos]);
    }
    return dp[pos][totalweight] = maxi;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    memset(dp, -1, sizeof(dp));
    cin >> n >> w;
    ll i, j, k, l;
    for (i = 1; i <= n;i++){
        cin >> weights[i] >> value[i];
    }
    cout << recurse(1, 0);
    return 0;
}

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

int main() {
    int w, h, n;
    cin >> w >> h >> n;
    int ans = 0;
    int px, py;
    cin >> px >> py;
    for (int i = 1; i < n; i++) {
        int x, y;
        cin >> x >> y;
        if ((x - px) * (y - py) > 0) {
            ans += max(abs(x - px), abs(y - py));
        }
        else {
            ans += abs(x - px) + abs(y - py);
        }
        px = x, py = y;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define debugArray(x, n)                                      \
  cerr << __LINE__ << ": " << #x << " = {";                   \
  for (long long hoge = 0; (hoge) < (long long)(n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];                   \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N;
  cin >> N;
  int P[N * N];
  for (int i = 0; i < N * N; i++) cin >> P[i], P[i]--;
  auto node = [&](int i, int j) { return N * i + j; };
  auto ij = [&](int v) { return make_pair(v / N, v % N); };
  pair<int, int> dir[4] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
  int cost[N * N];
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cost[node(i, j)] = min({i + 1, N - i, j + 1, N - j});
    }
  }
  bool rem[N * N];
  fill(rem, rem + N * N, true);
  // debugArray(cost, N * N);
  int ans = 0;
  for (int p : P) {
    rem[p] = false;
    queue<int> que;
    que.push(p);
    while (!que.empty()) {
      int v = que.front();
      que.pop();
      bool update = false;
      int ci, cj;
      tie(ci, cj) = ij(v);
      for (int d = 0; d < 4; d++) {
        int ni = ci + dir[d].first, nj = cj + dir[d].second;
        int c = 0;
        if (!(ni < 0 || N <= ni || nj < 0 || N <= nj)) c = cost[node(ni, nj)];
        if (cost[v] > c + rem[v]) {
          update = true;
          cost[v] = c + rem[v];
        }
      }
      if (!update) continue;
      for (int d = 0; d < 4; d++) {
        int ni = ci + dir[d].first, nj = cj + dir[d].second;
        if (ni < 0 || N <= ni || nj < 0 || N <= nj) continue;
        que.push(node(ni, nj));
      }
    }
    ans += cost[p];
    // debugArray(cost, N * N);
  }

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


Measured memory_bytes: 5832
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt() * 2;
        int[] l = IntStream.rangeClosed(1, k).toArray();
        int m = sc.nextInt();
        while (m-- > 0) {
            int n = sc.nextInt();
            int[] t = new int[k];
            if (n == 0) {
                for (int i = 0; i < k; i++) {
                    t[i] = l[(i % 2 == 0 ? i : k + i) / 2];
                }
            } else {
                for (int i = 0; i < k; i++) {
                    t[i] = l[(i + n) % k];
                }
            }
            l = t;
        }
        for (int i : l) {
            System.out.println(i);
        }
    }
}



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

int main(void) {

	int S,h,m,s;

	scanf("%d",&S);

	h=S/3600;
	m=(S-h*3600)/60;
	s=S-(h*3600)-m*60;

	printf("%d:%d:%d\n",h,m,s);

	return 0;
}

Measured memory_bytes: 592
import java.util.*;

public class Main {
	//0327 start
	
	class E{
		int from, to;

		public E(int from, int to) {
			this.from = from;
			this.to = to;
		}
		
	}
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			ArrayList<ArrayList<E>> pass = new ArrayList<ArrayList<E>>();
			for(int i = 0 ; i <= 100; i++){
				pass.add(new ArrayList<Main.E>());
			}
			
			while(true){
				int a = sc.nextInt(), b = sc.nextInt();
				if((a|b) == 0) break;
				pass.get(a).add(new E(a, b));
				pass.get(b).add(new E(b, a));
			}
			
			boolean res = isEuler(pass, 1, 2);
			System.out.println(res ? "OK" : "NG");
		}
	}
	private boolean isEuler(ArrayList<ArrayList<E>> pass,int start, int goal) {
		for(int i = 0; i < pass.size(); i++){
			if(i == start || i == goal) continue;
			if(pass.get(i).size() % 2 != 0){
				return false;
			}
		}
		if(pass.get(start).size() % 2 == pass.get(goal).size() % 2 && pass.get(start).size() % 2 == 1){
			return true;
		}
		return false;
	}
	public static void main(String [] args){
		new Main().doit();
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define MOD 1000000007
#define DEBUG 0
#define REP(i,n) for(int i=0;i<n;i++)

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

	string str;
	cin>>str;

	lli cnt = 0;
	lli needleft=0;

	REP(now,n){
		if(str.at(now)=='(')cnt++;
		else{
			if(cnt!=0){
				cnt--;
			}
			else{
				needleft++;
			}
		}
	}
	lli needright=cnt;
	string ans="";
	REP(i,needleft)ans = "("+ans;
	ans = ans+str;
	REP(i,needright)ans = ans + ")";

	cout<<ans<<endl;

	return 0;
}
 

Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;

int n,m;
vector<int> adj[MAXN];

bool done[MAXN];
int top[MAXN],ntop;
int dp[MAXN];

void dfstop(int at) {
	done[at]=true;
	REPSZ(i,adj[at]) { int to=adj[at][i]; if(!done[to]) dfstop(to); }
	top[ntop++]=at;
}

int solve() {
	ntop=0; REP(i,n) done[i]=false;
	REP(i,n) if(!done[i]) dfstop(i);
	//printf("top:"); REP(i,n) printf(" %d",top[i]+1); puts("");
	REP(i,n) {
		int at=top[i]; dp[at]=0;
		REPSZ(j,adj[at]) { int to=adj[at][j]; dp[at]=max(dp[at],dp[to]+1); }
	}
	int ret=0; REP(i,n) ret=max(ret,dp[i]); return ret;
}

void run() {
	scanf("%d%d",&n,&m);
	REP(i,m) { int a,b; scanf("%d%d",&a,&b); --a,--b; adj[a].PB(b); }
	printf("%d\n",solve());
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 8704
<?php
fscanf(STDIN, "%d", $n);
for($i = 0; $i < 10000; $i++){
    if($i*($i+1)/2 >= $n){
        $N = $i;
        $over = $i*($i+1)/2 - $n;
        break;
    }
}
for($i = 1; $i <= $N; $i++){
    if($i != $over)echo $i,"\n";
}


Measured memory_bytes: 4728
#!/usr/bin/python
# -*- Coding: utf-8 -*-


N, M, C = map(int, input().split())
Bn = list(map(int, input().split()))
listA =[]

for i in range(N):
    listA.append(input().split())


cnt = 0
for i in range(N):
    tmp = 0
    for j in range(M):
        tmp += int(listA[i][j]) * int(Bn[j])

    if tmp + int(C) > 0:
        cnt += 1

print(cnt)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
long long f[1001][1001]={0},n,m,i,j;
char a[1001][1001];
int main()
{
	scanf("%lld %lld",&n,&m);
	for(i=1;i<=n;i++)
	{
		getchar();
		for(j=1;j<=m;j++)
			scanf("%c",&a[i][j]);
	}
	for(i=1;i<=n;i++)
	{	
		for(j=1;j<=m;j++)
		{
			if(i==1&&j==1)
				f[i][j]=1;
			else if(a[i][j]=='#')
				f[i][j]=0;
			else
			{
				f[i][j]=f[i-1][j]+f[i][j-1];
				f[i][j]%=1000000007;
			}
		}
	}
	printf("%lld",f[n][m]%1000000007);
	return 0;
}

Measured memory_bytes: 9088
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			String number = sc.nextLine();
			long sum = 0;

			if(number.equals("0")) break;
			else {
				for(int i=0;i<String.valueOf(number).length();i++) {
					int j = i;
					sum += Integer.parseInt(String.valueOf(number).substring(i,j+1));
				}
			}
			System.out.println(sum);
		}
	}
}



Measured memory_bytes: 26844
N,C = map(int,input().split())
XV = [tuple(map(int,input().split())) for _ in range(N)]


# 順方向,逆方向の累積和
VF,VB = [0]*(N+1),[0]*(N+1)
for i in range(N):
    VF[i+1] += VF[i]+XV[i][1]
for i in range(N):
    VB[N-i-1] += VB[N-i]+XV[N-1-i][1]
# 移動距離を減算
for i in range(N):
    VF[i+1] -= XV[i][0]
for i in range(N):
    VB[N-i-1] -= (C-XV[N-1-i][0])
# 食べに行くと損する場合を除くために単調増加に
for i in range(N):
    if VF[i+1] < VF[i]:
        VF[i+1] = VF[i]
for i in range(N):
    if VB[N-1-i] < VB[N-i]:
        VB[N-1-i] = VB[N-i]

# 順方向,逆方向で全部食べた場合で初期化
ans = 0
ans = max(ans, VF[N], VB[0])

# 反転 : 順方向→逆方向
for i in range(1,N):
    ans = max(ans, VF[i], VF[i]+VB[i]-XV[i-1][0])

# 反転 : 逆方向→順方向
for i in range(1,N):
    ans = max(ans, VB[i], VB[i]+VF[i]-(C-XV[i][0]))

print(ans)

Measured memory_bytes: 26172
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    int A[N];
    REP(i,N){
        cin >> A[i];
    }

    int odd_num = 0, even_num = 0;
    
    REP(i, N){
        if (A[i]%2 == 0){
            even_num++;
        }
        else{
            odd_num++;
        }
    }

    if (odd_num%2 != 0){
        cout << "NO" << endl;
    }
    else{
        cout << "YES" << endl;
    }
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using edge = pair<ll, P>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

ll dp[100005][13];

void Main() {
    string s;
    cin >> s;
    int N = s.size();
    dp[0][0] = 1;
    rep(i, N) {
        if (s[i] == '?') {
            rep(j, 10) {
                rep(k, 13) {
                    dp[i + 1][(10 * k + j) % 13] += dp[i][k];
                    dp[i + 1][(10 * k + j) % 13] %= MOD;
                }
            }
        } else {
            int j = s[i] - '0';
            rep(k, 13) {
                dp[i + 1][(10 * k + j) % 13] += dp[i][k];
                dp[i + 1][(10 * k + j) % 13] %= MOD;
            }
        }
    }
    cout << dp[N][5] << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


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

using ll = long long int;
using P = pair<ll, ll>;
using P3 = pair<int, P>;
using PP = pair<P, P>;
constexpr int INF = 1 << 30;
constexpr ll MOD = ll(1e9) + 7;
constexpr int di[] = {0, 1, 0, -1};
constexpr int dj[] = {1, 0, -1, 0};


int main() {
    int n;
    cin >> n;
    vector<vector<int> > d(n, vector<int>(n)), need(n, vector<int>(n, 1));
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin >> d[i][j];
        }
    }
    bool update = false;
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(d[i][j] > d[i][k]+d[k][j]){
                    update = true;
                }else if(d[i][j] == d[i][k]+d[k][j] && k != i && k != j){
                    need[i][j] = false;
                }
            }
        }
    }
    if(!update){
        ll sum = 0;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){
                if(need[i][j]) sum += d[i][j];
            }
        }
        cout << sum << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
int n,m;
int main()
{
	scanf("%d%d",&n,&m);
	printf("%d\n",max(n+m,max(n-m,n*m)));
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    public static  void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int x=sc.nextInt();
        int hap=x/500;
        int s=0;
        s=hap*1000;
        int rem=x%500;
        int re=5*(rem/5);
        System.out.println(s+re);

    }
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(){
    cout << "Yes" << endl;
}

void no (){
    cout << "No" << endl;
}

ll cel (ll a, ll b){
    if (a % b == 0) return a / b;
    else return a / b + 1;
}

ll gcds(ll a, ll b){
    ll c = a % b;
    while (c != 0){
        a = b;
        b = c;
        c = a % b;
    }
    return b;
}

vector<int> dx = {0,1,0,-1};
vector<int> dy = {1,0,-1,0};

int main() {
    int a, b, c; cin >> a >> b >> c;
    if (a <= b * c) yes();
    else no();
}


Measured memory_bytes: 3628
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), k = sc.nextInt();
        SUSHI[] sushi = new SUSHI[n];
        for (int i = 0; i < n; i++) {
            sushi[i] = new SUSHI(sc.nextInt() - 1, sc.nextLong());
        }
        Arrays.sort(sushi);

        long ans = 0, sumOfDelicious = 0;
        boolean[] used = new boolean[n];
        PriorityQueue<SUSHI> queue = new PriorityQueue<>(Comparator.reverseOrder());
        long kind = 0;

        for(int i = 0; i < n; i++) {
            SUSHI s = sushi[i];
            if(i < k) {
                sumOfDelicious += s.delicious;
                if(used[s.type]) {
                    queue.offer(s);
                } else {
                    kind++;
                    used[s.type] = true;
                }
                ans = Math.max(ans, sumOfDelicious + kind * kind);
            } else if(!queue.isEmpty() && !used[s.type]) {
                sumOfDelicious -= queue.poll().delicious;
                sumOfDelicious += s.delicious;
                used[s.type] = true;
                kind++;
                ans = Math.max(ans, sumOfDelicious + kind * kind);
            }
        }
        System.out.println(ans);
    }
}

class SUSHI implements Comparable<SUSHI> {
    int type;
    long delicious;

    SUSHI(int t, long d) {
        type = t;
        delicious = d;
    }

    @Override
    public int compareTo(SUSHI o) {
//        return this.delicious == o.delicious
//                ? Integer.compare(this.type, o.type)
//                : Long.compare(o.delicious, this.delicious);
        return Long.compare(o.delicious, this.delicious);
    }
}


Measured memory_bytes: 92112
n=int(input()); c=0
a=[int(x) for x in input().split()]
if 0 in a: 
    print(0)
else:
    p=1; m=10**18
    for i in a:
        if(p*i>m):
            c=1;break
        else: 
            p*=i
    if(c==0):
        print(p)
    else:
        print(-1)

Measured memory_bytes: 84780
s=list(input())
if (s[0]=='R' and s[1]=='R' and s[2]=='R'):
  print(3)
elif ((s[0]=='R' and s[1]=='R') or (s[2]=='R' and s[1]=='R')):
  print(2)
elif (s[0]=='S' and s[1]=='S' and s[2]=='S'):
  print(0)
else:
  print(1)


Measured memory_bytes: 61660
sum_list=[]
while True:
    num=input()
    if num=='0':
        break
    num_list=list(num)
    for i in range(0,len(num_list)):
        num_list[i]=int(num_list[i])
    sum_list.append(sum(num_list))

for i in sum_list:
    print(i)

Measured memory_bytes: 7640
from collections import deque
h,w = list(map(int, input().split()))
s = ['#'*(w+2)]
[s.append('#'+input()+'#') for _ in range(h)]
s.append('#'*(w+2))
whitecount = 0
for i in s:
    whitecount += i.count('.')

ans = 0
queue = deque([[1,1]])
cost = [[1]*(w+2) for _ in range(h+2)]
visited = [[False]*(w+2) for _ in range(h+2)]
while queue:
    x,y = queue.popleft()
    visited[y][x] = True
    hjkl = [[x-1,y], [x,y-1], [x+1,y], [x,y+1]]
    for dx,dy in hjkl:
        if (s[dy][dx]=='.') and (visited[dy][dx]==False) and ([dx,dy] not in queue):
            queue.append([dx,dy])
            cost[dy][dx] = cost[y][x] + 1

if visited[h][w]:
    print(whitecount - cost[h][w])
else:
    print(-1)

Measured memory_bytes: 3316
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        var nk = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var n = nk[0];
        var k = nk[1];
        //にんげん
        var a = Console.ReadLine().Split().Select(long.Parse).OrderByDescending(x => x).ToArray();
        //ごはん
        var f = Console.ReadLine().Split().Select(long.Parse).OrderBy(x => x).ToArray();

        var valid = long.MaxValue / 2; ;
        long invalid = -1;
        while (valid - invalid > 1)
        {
            var mid = (valid + invalid) / 2;
            if (Achivable(k, mid, a, f)) valid = mid;
            else invalid = mid;
        }
        Console.WriteLine(valid);
    }

    static bool Achivable(long k, long score, long[] a, long[] f) => a.Zip(f, (x, y) => Max(0, (x * y - score + y - 1) / y)).Sum() <= k;    
}


Measured memory_bytes: 48020
#include <iostream>
#include <string>
#include <set>
#include <algorithm> // std::reverse

using std::cout;
using std::cin;
using std::endl;
using std::string;
using std::set;

int main(void) {
    int m;
    int size;
    cin >> m;
    string str;
    for (int input = 0; input < m; input++) {
        cin >> str;
        size = str.size();
        set<string> string_set;
        for (int sep = 0; sep < size - 1; sep++) {
            string left;
            string left2;
            string right;
            string right2;
            left = str.substr(0 , sep + 1);
            right = str.substr(sep + 1 , size - sep - 1);
            left2 = left;
            right2 = right;

            std::reverse(left2.begin(), left2.end());
            std::reverse(right2.begin(), right2.end());

            string_set.insert(left + right);
            string_set.insert(left + right2);
            string_set.insert(left2 + right);
            string_set.insert(left2 + right2);
            string_set.insert(right + left);
            string_set.insert(right + left2);
            string_set.insert(right2 + left);
            string_set.insert(right2 + left2);
        }
        cout << string_set.size() << endl;

        /*
        // c++11
        for(auto itr = string_set.begin(); itr != string_set.end(); ++itr) {
            std::cout << *itr << "\n";      // ????????¬???????????????????????????????????¨???
        }
        */
    }

    return 0;
}

Measured memory_bytes: 3180
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
typedef long long ll;

using namespace std;

struct Point { int x, y; };
struct Edge { int from, to, cost; };
struct gNode { int from, to, cost; };
struct tNode { int value; int parent; vector<int> child; };

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

int gcd(int a, int b){ return a % b == 0 ? b : gcd(b, a%b); }
int lcm(int a, int b){ return a * b/ gcd(a, b); }
int extgcd(int a, int b, int& x, int& y){
	int d = a;
	if(b != 0){
		d = extgcd(b, a%b, y, x);
		y -= (a/b) * x;
	} else{
		x = 1; y = 0;
	}
	return d;
}
ll mod_pow(ll x, ll n){
	if(n == 0) return 1;
	ll res = mod_pow(x*x % MOD, n/2);
	if(n & 1) res = res * x % MOD;
	return res;
}



int main(void){
	int n, W; cin >> n >> W;
	vint w(n), v(n);
	rep(i, n) cin >> w[i] >> v[i];

	static ll dp[110][SIZE]; //dp[品物][容量] = 価値
	dp[0][w[0]] = v[0];
	rep2(i, 1, n){
		rep(j, W){
			if(dp[i-1][j] != 0){
				if(j + w[i] <= W) dp[i][j+w[i]] = max(dp[i][j+w[i]], dp[i-1][j] + v[i]);
			}
			dp[i][j] = max(dp[i][j], dp[i-1][j]);
		}
		dp[i][0+w[i]] = max(dp[i][w[i]], dp[i-1][0] + v[i]);
	}

	ll ans = 0;
	rep(j, W+1){
		ans = max(ans, dp[n-1][j]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 79360
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	S := nextString()

	n := len(S)
	hitachi := true
	if n >= 2 && n%2 == 0 {
		i := 0
		for i < n-1 {
			if S[i] == 'h' && S[i+1] == 'i' {
				i += 2
				continue
			} else {
				hitachi = false
				break
			}
		}
	} else {
		hitachi = false
	}

	if hitachi {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
package main

import (
	"fmt"
	"math"
)

func main() {
	a()
}

func a() {
	var n float64
	var x float64
	var t float64

	fmt.Scanf("%f %f %f", &n, &x, &t)
	num := math.Ceil(n / x)
	fmt.Printf("%.0f", t*num)
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    int n,r;cin>>n>>r;

    if(n>=10)cout<<r<<"\n";
    else cout<<r+100*(10-n)<<"\n";

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
#define rep(i,b) for(int i = 0; i < b; i++)
#define pb push_back
#define back(x) x[x.size()-1]
inline bool vowel(char c){return c=='a'||c=='i'||c=='u'||c=='e'||c=='o';}
inline bool voiceless(char c){return c=='k'||c=='s'||c=='t'||c=='h'||c=='p';}

string in;
vector<string> compose(){
	int n=in.size();
	vector<string> res;
	string tmp;
	rep(i,n){
		tmp.pb(in[i]);
		if(vowel(in[i])){
			if(i<n-1&&(in[i+1]=='a'||in[i+1]=='i'||in[i+1]=='u')){
				tmp.pb(in[++i]);
			}
			res.pb(tmp);
			tmp="";
		}
		else{
			if(in[i]=='\''){
				res.pb(tmp);
				tmp="";
			}
			else if(in[i] == 'n' && (i == n-1 || !vowel(in[i+1]) && in[i+1] != 'y')){
				res.pb(tmp);
				tmp="";
			}
		}
	}
	return res;
}
int main(){
	while(cin>>in,in!="#"){
		vector<string> v=compose();
		int n=v.size();
		bool flag=0;
		rep(i,n){
			bool res=!flag;
			if(res){
				res=0;
				int vw=0;
				rep(j,v[i].size())if(vowel(v[i][j]))vw++;
				if(voiceless(v[i][0])&&vw==1){
					if((back(v[i])=='i'||back(v[i])=='u')&&
							(i==n-1||voiceless(v[i+1][0])))res=1;
					if((back(v[i])=='a'||back(v[i])=='o')&&i<n-1&&
							voiceless(v[i+1][0])&&(v[i+1][1]=='y'?v[i+1][2]:v[i+1][1])==back(v[i]))res=1;
				}
			}
			flag=res;
			if(res){
				bool ok=0;
				rep(j,v[i].size())if(!ok&&vowel(v[i][j])){
					cout<<"("<<v[i][j]<<")";
					ok=1;
				}
				else cout<<v[i][j];
			}
			else cout<<v[i];
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1192
//by xay5421 2449670833@qq.com
#include<set>
#include<map>
#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#define int long long
#define debug(...) fprintf(stderr,__VA_ARGS__)
//#define debug(...) ((void)0)
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;typedef unsigned long long ull;typedef std::pair<int,int> pii;
template<typename T>void rd(T&x){int f=0,c;while((c=getchar())<48||57<c)f^=!(c^45);x=(c&15);while(47<(c=getchar())&&c<58)x=x*10+(c&15);if(f)x=-x;}
template<typename T>inline void pt(T x){if(x<0)x=-x,putchar('-');if(x>9)pt(x/10);putchar(x%10+48);}
template<typename T>inline void pt(T x,int c){pt(x),putchar(c);}
template<typename T>inline T max(const T&x,const T&y){return x<y?y:x;}
template<typename T>inline T min(const T&x,const T&y){return x<y?x:y;}

const int N=105;

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

signed main(){
	scanf("%s",s+1),rd(K);
	n=strlen(s+1);
	rep(i,1,n)t[i]=s[i];
	int flag=1;
	rep(i,2,n)if(s[i]!=s[i-1]){
		flag=0;
		break;
	}
	if(flag){
		pt(n*K/2,'\n');
		return 0;
	}
	int ans=0;
	for(int i=1;i<=n;++i){
		if(s[i]==s[i-1]){
			++ans;
			s[i]=' ';
		}
	}
	if(s[1]==s[n]){
		rep(i,1,n)s[i]=t[i];
		s[1]=' ';
		int res=1;
		rep(i,1,n){
			if(s[i]==s[i-1]){
				++res;
				s[i]=' ';
			}
		}
		pt(ans+res*(K-1),'\n');
		return 0;
	}
	ans=ans*K+(s[1]==s[n])*(K-1);
	pt(ans,'\n');
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#pragma warning(disable:4996)

int main() {
	int n = 0;
	bool flag = 0;
	scanf("%d", &n);
	for (int i = 1; i < 10; i++) {
		if ((10 > n/i) && (n%i == 0)) {
			flag = 1;
			break;
		}
	}
	if (flag == 1) {
		printf("Yes");
	}
	else {
		printf("No");
	}

	return 0;
}

Measured memory_bytes: 128
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
int calc(int x,int lg){
	return lg+lg+__builtin_popcount(x-(1<<lg));
}
int l;
int main(){
	cin>>l;int lg;
	for(int i=0;i<=20;i++){
		if((1<<i)<=l)lg=i;
	}
	cout<<lg+1<<" "<<calc(l,lg)<<endl;
	int n=lg+1;
	for(int i=1;i<n;i++)cout<<i<<" "<<i+1<<" "<<(1<<i-1)<<endl;
	for(int i=1;i<n;i++)cout<<i<<" "<<i+1<<" "<<0<<endl;
	int L=1<<lg,R=l;
	for(int i=n-1;i>=1;i--){
		int cnt=1<<i-1;
		if(R-L>=cnt){
			cout<<i<<" "<<n<<" "<<L<<endl;
			L+=cnt;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <tuple>
#include <utility>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <map>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};

int main()
{
    int p;
    cin>>p;
    cout << p/500*500<<endl;
    return 0;
}



Measured memory_bytes: 3120
#include <iostream>
using namespace std;
int main(){
    
    int a,b;
    string op;
    
    while(1){
        cin >> a >> op >> b;
        
        if(op == "?") break;
        else if(op == "+") cout << a+b << endl;
        else if(op == "-") cout << a-b << endl;
        else if(op == "*") cout << a*b << endl;
        else if(op == "/") cout << a/b << endl;
        
    }
    
    return 0;
}


Measured memory_bytes: 3096
#include <iostream>
using namespace std;
int Digit(int a,int b){
    int ans,sum;
    ans = 0;
    sum = a+b;
    while(sum!=0){
        sum = sum/10;
        ans++;
    }
    return ans;
}

int main(){
    int x,y;
    int ans;

    while(cin >> x >> y){
    ans=Digit(x,y);
    cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
using namespace std;
int Prefix[100005];

int main(){
    int N , M , i , l , r;
    scanf( "%d%d" , &N , &M );
    fill( Prefix , Prefix + 100004 , 0 );

    for( i = 1 ; i <= M ; ++i ){
        scanf( "%d%d" , &l , &r );
        ++Prefix[l];
        --Prefix[r + 1];
    }   

    int Ans = 0;

    for( i = 1 ; i <= 100000 ; ++i ){
        Prefix[i] += Prefix[i - 1];
        if( Prefix[i] == M ) ++Ans;
    }

    printf( "%d\n" , Ans );
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  vector<int> p(n);
  
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }

  int count = 0;
  int min_num = 1e9+7;
  for (int i = 0; i < n; i++) {
    if (min_num >= p[i]) {
      count++;
      min_num = min(min_num, p[i]);
    }
  }

  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main() {
	string S;
	string SS[3];
	SS[0] = "Sunny";
	SS[1] = "Cloudy";
	SS[2] = "Rainy";
	cin >> S;
	int n = 0;
	rep(i, 3) {
		if (S == SS[i])
			n = i;
	}
	n++;
	n %= 3;
	cout << SS[n] << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;



signed main(){

    int N; cin >> N;
    string X; cin >> X;
    int cnt = 0;
    REP(i, N) cnt += X[i] - '0';

    int np = cnt + 1, nm = cnt - 1;
    int sp = 0, sm = 0, rp = 1, rm = 1;
    IREP(i, N){
        if(X[i] == '1'){
            (sp += rp) %= np;
            if(nm) (sm += rm) %= nm;
        }

        (rp *= 2) %= np;
        if(nm) (rm *= 2) %= nm;
    }

    vec ans(N);
    rp = 1, rm = 1;
    IREP(i, N){
        if(X[i] == '0'){
            int tmp = (sp + rp) % np;
            int c = 1;
            while(tmp){
                tmp %= __builtin_popcountll(tmp);
                c++;
            }
            ans[i] = c;
        }else{
            if(nm == 0) ans[i] = 0;
            else{
                int tmp = ((sm - rm) % nm + nm) % nm;
                int c = 1;
                while(tmp){
                    tmp %= __builtin_popcountll(tmp);
                    c++;
                }
                ans[i] = c;
            }
        }

        (rp *= 2) %= np;
        if(nm) (rm *= 2) %= nm;
    }
    REP(i, N) cout << ans[i] << endl;

    return 0;
}


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

using namespace std;

#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define vi vector<int>

#define ll long long int

int ctoi(char c) {return c-'0';}
int ord(char c) {return c-'a';}
int len(string s) {return s.length();}
int itoc(int i) {return i+'a';}


int main() {
float N;
cin>>N;
cout<<ceil(N/2)<<endl;
return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>

using namespace std;
typedef long long ll;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 2019;
// const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
// istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
// ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
	string S;
	cin >> S;
	
	int N = S.length();
	mint mod2019[200001];
	mod2019[0] = 0;
	
	for(int i = 0; i < N; i++){
		int n = (int)(S[N-1-i]-48);
		mint ten = 10;
		mod2019[i+1] = mod2019[i] + n * ten.pow(i).x;
		// cout << n << " " <<  mod2019[i+1].x << endl;
	}
	
	vector<int> modCount[2019];
	modCount[0].push_back(0);
	for(int i = 1; i <= N; i++){
		modCount[mod2019[i].x].push_back(i);
	}
	
	ll ans = 0;
	for(int i = 0; i < 2019; i++){
		// if(modCount[i].size() > 0){cout << "*" << i << " " << modCount[i].size() << endl;}
		ans += modCount[i].size() > 0 ? (modCount[i].size()-1) * modCount[i].size() / 2 : 0;
	}
	
	cout << ans << endl;
	
	return 0;
}


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

int main() {

  while( true ) {

  long long int n;
  cin >> n;
  if ( n == 0 ) break;

  long long int a = 0, b = 0;
  for ( long long int i = 0; i < n; i++ ) {

    long long int in_a, in_b;
    cin >> in_a >> in_b;

    if ( in_a > in_b ) {
      a += in_a + in_b;
    }else if ( in_a < in_b ) {
      b += in_a + in_b;
    }else {
      a += in_a;
      b += in_b;
    }

  }

  cout << a << " " << b << endl;

  }

  return 0;

}

Measured memory_bytes: 1156
n,m=gets.chomp.split.map(&:to_i)
k = []
s = []
flag = [0,1,2,4,8,16,32,64,128,256,512]
m.times do
  ks = gets.chomp.split.map(&:to_i)
  k << ks[0]
  s << ks[1,ks.size-1]
end
p = gets.chomp.split.map(&:to_i)
ans = 0
0.upto(2**n-1) do |i|
  c = 0
  0.upto(m-1) do |j|
    c_on = 0
    s[j].each do |k|
      c_on += 1 if i & flag[k] == flag[k]
    end
    if c_on % 2 == p[j]
      c += 1
    else
    end
  end
  ans += 1 if c == m
end
puts ans

Measured memory_bytes: 1788
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve();
			Console.Out.Flush();
		}

		const int mod = 1000000007;  // 10^9+7
		static int Mod(long x, int m) { return (int)((x % m + m) % m); }
		static long Mod(long x, long m) { return (x % m + m) % m; }

		static public void Solve()
		{
			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();

			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int h = vs[0];
			int w = vs[1];
			string[] s = new string[h];
			for (int i = 0; i < h; i++) {
				s[i] = Console.ReadLine();
			}

			string ans = "Yes";
			for (int y = 0; y < h; y++) {
				for (int x = 0; x < w; x++) {
					if (s[y][x] == '#') {
						if (x > 0 && s[y][x - 1] == '#') {
						} else if (x < w - 1 && s[y][x + 1] == '#') {
						} else if (y > 0 && s[y - 1][x] == '#') {
						} else if (y < h - 1 && s[y + 1][x] == '#') {
						} else {
							ans = "No";
						}
					}
				}
			}
			Console.WriteLine(ans);

		}
	}
}


Measured memory_bytes: 28296
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int s = sc.nextInt();
    int count=4;
    while(s!=4&&s!=2&&s!=1){
      count++;
      s=calc(s);
    }
    System.out.println(count);
  }
  static int calc(int n){
    if(n%2==0){
      return n/2;
    }
    return 3*n+1;
  }
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, ans = 0;
  string s;
  vector<char> c;
  cin >> s;
  rep(i, s.size()) if (s[i] != 'x') c.push_back(s[i]);
  bool ok = false;
  for (int i = 0; i < c.size() / 2; ++i) {
    if (c[i] == c[c.size() - 1 - i])
      continue;
    else
      ok = true;
  }

  if (s.size() == 1) {
    puts("0");
    return 0;
  }

  if (ok) {
    puts("-1");
    return 0;
  }
  deque<char> dqf, dqb;
  int i = 0, j = s.size() - 1;
  do {
    if (s[i] == s[j]) {
      dqf.push_back(s[i]);
      dqb.push_front(s[j]);
      i++, j--;
    } else {
      if (s[i] == 'x') {
        dqf.push_back(s[i]);
        dqb.push_front('x');
        i++;
        ans++;
      } else {
        dqf.push_back('x');
        dqb.push_front(s[j]);
        j--;
        ans++;
      }
    }
  } while (i <= j);

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


Measured memory_bytes: 640
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18

N = int(sys.stdin.readline())
P = list(map(int, sys.stdin.readline().split()))


def ok(i):
    return P[i - 1] <= P[i] < P[i + 1] or P[i + 1] <= P[i] < P[i - 1]


ans = 0
for i in range(1, N - 1):
    ans += ok(i)
print(ans)


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

int main(){
  string S;
  int Q;
  cin >> S >> Q;
  bool flag=true;
  string fr="";
  string ta="";
  for(int i=0; i<Q; i++){
    int q; cin >> q;
    if(q==1){
      flag = !flag;
    }else{
      int f;
      char c;
      cin >> f >> c;
      if(flag){
        if(f==1){
          fr += c;
        }else{
          ta += c;
        }
      }else{
        if(f==1){
          ta+=c;
        }else{
          fr+=c;
        }
      }
    }
  }
  reverse(fr.begin(),fr.end());
  S = fr+S+ta;
  if(flag){
    cout << S << endl;
  }else{
    reverse(S.begin(), S.end());
    cout << S << endl;
  }
  return 0;
}

Measured memory_bytes: 1348