akhauriyash/Code-Regression huggingface dataset:
from __future__ import division
import math

def cross(p1,p2):
    a,b,c,d=p1[0],p1[1],p2[0],p2[1]
    t=pow(a,2)+pow(c,2)+pow(d,2)-pow(b,2)-2*a*c
    alpha=4*(pow(b-d,2)+pow(c-a,2))
    beta=4*(t*(b-d)-2*b*pow(c-a,2))
    gamma=pow(t,2)+4*pow(b,2)*pow(c-a,2)-4*pow(c-a,2)
    judge=pow(beta,2)-4*alpha*gamma
    EPS=1e-5
    if c==a:
        y=(pow(a,2)+pow(b,2)-pow(c,2)-pow(d,2))/(2*(b-d))
        bd=pow(b-d,2)
        a1=4*bd
        b1=-8*a*bd
        c1=4*a*a*bd+pow(a*a-b*b-c*c-d*d+2*b*d,2)-4*bd
        inroot=pow(b1,2)-4*a1*c1
        if inroot<0:
            return None
        x1=(-b1+math.sqrt(inroot))/(2*a1)
        x2=(-b1-math.sqrt(inroot))/(2*a1)
        return ((x1,y),(x2,y))

    if judge>EPS:
        y1=(-beta+math.sqrt(judge))/(2*alpha)
        y2=(-beta-math.sqrt(judge))/(2*alpha)
        x1=(2*(b-d)*y1+pow(c,2)+pow(d,2)-pow(a,2)-pow(b,2))/(2*(c-a))
        x2=(2*(b-d)*y2+pow(c,2)+pow(d,2)-pow(a,2)-pow(b,2))/(2*(c-a))
        return ((x1,y1),(x2,y2))
    elif -EPS<=judge<=EPS:
        y=-beta/(2*alpha)
        x=(2*(b-d)*y+pow(c,2)+pow(d,2)-pow(a,2)-pow(b,2))/(2*(c-a))
        return ((x,y),)
    else:
        return None

def maxNum(P,L):
    ans=1
    for x,y in P:
        cnt=0
        for px,py in L:
            d=math.sqrt(pow(px-x,2)+pow(py-y,2))
            if d<=1:
                cnt+=1
        ans=max(ans,cnt)
    return ans

while True:
    n=input()
    if n==0:break
    L=[map(float,raw_input().split(",")) for i in range(n)]
    P=[]
    for i in range(n-1):
        for j in range(i+1,n):
            points=cross(L[i],L[j])
            if points:
                P.extend(points)
    print maxNum(P,L)

Measured memory_bytes: 4692
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll inf = numeric_limits<ll>::max()/3;
const ll mod = 1e9+7;


int main(void) {
  int a,b,c;
  cin >> a >> b >> c;
  if(a == b && b == c) {
    puts("Yes");
  } else {
    puts("No");
  }
  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.math, std.string, std.range, std.array,
       std.algorithm;

void main(){
    auto buf = readln().strip().split().map!(to!int)().array();

    if(buf[0]%2 == 0 || buf[1]%2 == 0 || buf[2]%2 == 0) {
        writeln(0);
        return;
    }

    sort(buf);

    writeln(cast(long)buf[0]*buf[1]);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
typedef long long ll;
const int INF = 1000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007ll;


int main(){
	int a,b,c;
	std::cin >> a>>b>>c;
	if(b-a==c-b)std::cout << "YES" << std::endl;
	else std::cout << "NO" << std::endl;
	
}


Measured memory_bytes: 256
import itertools
N,M,X = map(int,input().split())
A = []
for i in range(N):
    a = list(map(int,input().split()))
    A.append(a)
ans = 10 ** 10
Z = [0,1]
Y = list(itertools.product(Z,repeat=N))
for y in Y:
    tmp = [0 for i in range(M)]
    ctmp = 0
    for i in range(N):
        if y[i] == 1:
            ctmp += A[i][0]
            for j in range(M):
                tmp[j] += A[i][j+1]
    check = 0
    for k in tmp:
        if k < X:
            check = 1
    if check == 0:
        if ctmp < ans:
            ans = ctmp
if ans == 10 ** 10:
    ans = -1
print(ans)

Measured memory_bytes: 9648
b=[1]*500000
for i in range(3,999,2):
 if b[i//2]:b[i*i//2::i]=[0]*len(b[i*i//2::i])
def p(x):
 if x<5*1e5:return b[x]
 x=2*x+1
 for i in range(3,int(x**.5+1),2):
  if x%i==0:return 0
 return 1
print(sum(p(int(input()))for _ in[0]*int(input())))


Measured memory_bytes: 11812
from collections import Counter

MOD = 10 ** 9 + 7

N = int(input())
A = sorted(list(map(int, input().split())))

C = Counter(A)

b = 1 if N % 2 == 0 else 0

for key, value in C.items():
    if b == 0 and key == b and value != 1:
        print(0)
        exit()

    if key != b and value != 2:
        print(0)
        exit()
    b += 2

print(2 ** (N // 2) % MOD)


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

const int nIMPOS = -1;
struct StDist
{
  int m_nDist;
  int m_nMeTo;

  StDist(int nDist) : m_nDist(nDist), m_nMeTo(0)
  { }
};

void fnInput(vector<vector<int>>& rvvnAdjcy, vector<StDist>& rvoDist)
{
  int nxSiz;
  cin >> nxSiz;

  rvvnAdjcy.resize(nxSiz + 1, vector<int>(nxSiz + 1, 0));
  for (int i = 0; i < nxSiz; ++i)
  {
    int nx, nySiz;
    cin >> nx >> nySiz;
    for (int j = 0; j < nySiz; ++j)
    {
      int ny;
      cin >> ny;
      rvvnAdjcy[nx][ny] = 1;
    }
  }
  StDist oDist(nIMPOS);
  rvoDist.resize(nxSiz + 1, oDist);
}

void fnBreadthFirstSearch(const vector<vector<int>>& cnrvvnAdjcy, 
                          queue<int>& rqnBFSrch, vector<StDist>& rvoDist)
{
  while (rqnBFSrch.size())
  {
    int nx = rqnBFSrch.front(); rqnBFSrch.pop();
    if (rvoDist[nx].m_nMeTo)  continue; 

    rvoDist[nx].m_nMeTo = 1;
    for (int ny = 1; ny < cnrvvnAdjcy[nx].size(); ++ny)
      if (cnrvvnAdjcy[nx][ny])
      {
        int nDist = rvoDist[nx].m_nDist + 1;
        if (rvoDist[ny].m_nDist == nIMPOS)
          rvoDist[ny].m_nDist = nDist;
        else
          rvoDist[ny].m_nDist = min(rvoDist[ny].m_nDist, nDist);

        rqnBFSrch.push(ny);
      }
  }
}

void fnResult(const vector<StDist>& cnrvoDist)
{
  for (int i = 1; i < cnrvoDist.size(); ++i)
    cout << i <<  " " << cnrvoDist[i].m_nDist << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> vvnAdjcy;
  queue<int>  qnBFSrch;
  vector<StDist> voDist;

  fnInput(vvnAdjcy, voDist);

  voDist[1].m_nDist = 0;
  qnBFSrch.push(1);
  fnBreadthFirstSearch(vvnAdjcy, qnBFSrch, voDist);
  fnResult(voDist);

  return 0;
}

Measured memory_bytes: 3200
import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            long one = sc.nextLong();
            long zero = sc.nextLong();
            long minus = sc.nextLong();
            long nums = sc.nextLong();
            if(one >= nums){
              System.out.println(nums);
            } else if(one + zero >= nums){
              System.out.println(one);
            } else {
              System.out.println(one + ((nums-one-zero)*-1));
            }
          }
        }

Measured memory_bytes: 35772
#include<stdio.h>
#include<string.h>
int main()
{
    char s[100001],ck;
    int len,i,count;
    while(gets(s)!='\0')
    {
        count=0;
        len=strlen(s);
        ck=s[len-1];
        for(i=len-2;i>=0;i--)
        {
            if(ck!=s[i])
               {
                   ck=s[i];
                   count++;
               }
        }
        printf("%d\n",count);
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

using namespace std;

int main(){
    int n,m,l;
    scanf("%d %d %d",&n,&m,&l);
    int a[n][m];
    int b[m][l];
    long long int total[n][l];
    
    for(int i=0; i<n; i++){
        for(int j=0; j<l; j++){
            total[i][j] = 0;
        }
    }
    
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            scanf("%d",&a[i][j]);
        }
    }
    
    for(int i=0; i<m; i++){
        for(int j=0; j<l; j++){
            scanf("%d",&b[i][j]);
        }
    }
    
    for(int i=0; i<n; i++){
        for(int k=0; k<l; k++){
            for(int j=0; j<m; j++){
                total[i][k] += a[i][j]*b[j][k];
            }
        }
    }
    
    for(int i=0; i<n; i++){
        for(int j=0; j<l-1; j++){
            printf("%lld ",total[i][j]);
        }
        printf("%lld\n",total[i][l-1]);
    }
}



Measured memory_bytes: 2776
package main
 
import (
	"fmt"
)
 
func main() {
	var a, b, c, d int
	fmt.Scanf("%d %d %d %d", &a, &b, &c, &d)
	slice := []int{a * c, a * d, b * c, b * d}
	max := sortAsc(slice)[len(slice) - 1]
	fmt.Printf("%d\n", max)
}

func sortAsc(slice []int) []int{
	for{
		flag := true
		for i:= 0; i < len(slice) -1; i++ {
			if slice[i] > slice[i + 1]{
				slice[i + 1] = slice[i]
				flag = false
			}
		}
		if flag {
			break
		}
	} 

	return slice
} 

Measured memory_bytes: 1832
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

void put_uint(int n) {
    if(!n) {
        putchar_unlocked('0');
        return;
    }
    char buf[11];
    int i = 0;
    while(n) buf[i++] = (char)(n % 10 + '0'), n /= 10;
    while(i--)putchar_unlocked(buf[i]);
}

// positive only
int get_uint() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) {
        n = 10 * n + (c & 0xf);
        c = getchar_unlocked();
    }
    return n;
}
int get_str(char *str) {
    int c;
    while((c = getchar_unlocked()) > 32) *str++ = (char)c;
    *str = 0;
    return c;
}

typedef struct ListKey {
    int num;
} ListKey;
bool listkey__equal(ListKey *a, ListKey *b) {
    return a->num == b->num;
}
typedef struct ListDat {
    ListKey key;
    struct ListDat *prev;
    struct ListDat *next;
} ListDat;
typedef struct List {
    size_t len;
    ListDat *hdr;
} List;
#define list_init(l) ((l) ? ((l)->len = 0, (l)->hdr = NULL) : 0)
#define list_len(l) ((l) ? (l)->len : 0)
#define list_delete_first(l) ((l)->len ? list__delete((l), (l)->hdr->next) : 0)
#define list_delete_last(l) ((l)->len ? list__delete((l), (l)->hdr->prev) : 0)
void list_insert(List *l, ListKey x) {
    ListDat *new_dat = malloc(sizeof(ListDat));
    if(l->len) {
        new_dat->next = l->hdr->next;
        l->hdr->next->prev = new_dat;
        l->hdr->next = new_dat;
    } else {
        l->hdr = malloc(sizeof(ListDat));
        l->hdr->prev = l->hdr->next = new_dat;
        new_dat->next = l->hdr;
    }
    new_dat->key = x;
    new_dat->prev = l->hdr;
    l->len++;
}
void list__delete(List *l, ListDat *a) {
    a->prev->next = a->next;
    a->next->prev = a->prev;
    free(a);
    l->len--;
}
void list_delete(List *l, ListKey x) {
    for(ListDat *it = l->hdr->next; it != l->hdr; it = it->next) {
        if(listkey__equal(&x, &it->key)) {
            list__delete(l, it);
            break;
        }
    }
}
void list_print(List *l) {
    for(ListDat *it = l->hdr->next; it != l->hdr->prev; it = it->next) {
        put_uint(it->key.num);
        putchar_unlocked(' ');
    }
    put_uint(l->hdr->prev->key.num);
    putchar_unlocked('\n');
}
int main(int argc, char **argv) {
    int n = get_uint();
    List l;
    list_init(&l);
    for(int i = 0; i < n; ++i) {
        char str[16];
        get_str(str);
        if(strlen(str) == 6 && strncmp(str, "insert", 6) == 0) {
            ListKey key;
            key.num = get_uint();
            list_insert(&l, key);
        } else if(strlen(str) == 6 && strncmp(str, "delete", 6) == 0) {
            ListKey key;
            key.num = get_uint();
            list_delete(&l, key);
        } else if(strlen(str) == 11 && strncmp(str, "deleteFirst", 11) == 0) {
            list_delete_first(&l);
        } else if(strlen(str) == 10 && strncmp(str, "deleteLast", 10) == 0) {
            list_delete_last(&l);
        }
    }
    list_print(&l);
    return 0;
}



Measured memory_bytes: 32792
#include<bits/stdc++.h>
using namespace std;
map<string, int> m;
int main()
{
	int n;
	scanf("%d",&n);
	while(n--)
	{
		int t;
		int x;
		string y;
		cin >> t >> y;
		if(t == 0)
		{
			scanf("%d",&x);
			m[y] = x;
		}
		else if(t == 1) printf("%d\n",m[y]);
	}
	return 0;
}


Measured memory_bytes: 27992
s=list(input())
cnt=100
for i in range(26):
    x=chr(97+i)
    if x not in s:
        continue
    tmp=0
    dummy=s+[]
    while len(set(dummy))>1:
        tmp+=1
        newdum=[]
        for j in range(len(dummy)-1):
            if dummy[j]==x or dummy[j+1]==x:
                newdum.append(x)
            else:
                newdum.append(dummy[j])
        dummy=[]+newdum
    cnt=min(cnt,tmp)
print(cnt)

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

using namespace std;

const int maxN = 1e5 + 2;
int n , maximumcost = 0;
int a[maxN];

int main()
{
    cin >> n;
    a[0] = 0;
    for (int i = 1 ; i <= n ; i ++)
    {
        cin >> a[i];
        maximumcost += abs(a[i - 1] - a[i]);
    }
    maximumcost += abs(a[n] - 0);
    a[n+1] = 0;
    for (int i = 1 ; i <= n ; i++)
    {
        int k = maximumcost;
        k = k - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs (a[i-1] - a[i+1]);
        cout << k << '\n';
    }
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

int c[3][3];

int main() {
    rep(i, 3) {
        rep(j, 3) {
            cin >> c[i][j];
        }
    }

    if (c[0][1] - c[0][0] == c[1][1] - c[1][0] && c[1][1] - c[1][0] == c[2][1] - c[2][0]
     && c[0][2] - c[0][1] == c[1][2] - c[1][1] && c[1][2] - c[1][1] == c[2][2] - c[2][1]){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = sorted(LIST())
b = sorted(LIST())
c = sorted(LIST())

ans = 0
for x in b:
    i = bisect_left(a, x)
    j = n - bisect_right(c, x)
    ans += i * j
print(ans)

Measured memory_bytes: 31296
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
ans=0
for i in range(n-1):
    if a[i]+1==a[i+1]:
        ans+=c[a[i]-1]
ans+=sum(b)
print(ans)

Measured memory_bytes: 38384
#include<iostream>
#include<cmath>
#include<map>
#include<deque>
#include<string>
#include<algorithm>

#define all(x) (x).begin(),(x).end()
#define puts(x) cout<< x << endl;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define fore(i,a) for(auto i:a)
#define ll long long
using namespace std;
ll a,b,k;
int main(){
    cin>>a>>b>>k;
    if(a>=k){
        printf("%lld %lld",a-k,b);
    }else if(b+a-k>=0){
        printf("%d %lld",0,b+a-k);
    }else{
        printf("0 0");
    }
}

Measured memory_bytes: 256
//In The Name Of The God

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define F first
#define S second
#define X first.first
#define Y first .second
#define A second.first
#define B second.second
#define mp make_pair
#define pb push_back
#define pf push_front
#define P push
#define pob pop_back
#define pof pop_front
#define PO pop
#define rep(i,j,k) for(int i = j ; i <= k ; ++ i)
#define rrep(i,j,k) for(int i = j ; i>=k ; --i)
#define FR(i,j,k) for(int i = j ; i < k ; ++ i )
#define rFR(i,j,k) for(int i = j ; i > k ; -- i )
#define lb(x) x&-x
#define p2(x) (1LL<<x)
#define SZ size()
#define LB lower_bound
#define UB upper_bound
#define IT iterator
#define RIT reverse_iterator
#define E end()
#define BE begin()
#define RE rend()
#define RBE rbegin()
#define UN unsigned

typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll ;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
typedef pair<pii,pii> ppp;
typedef pair<int,pll> pipl;
typedef pair<pll,int> ppli ;
typedef pair<pll,pll> plpl ;
typedef pair<ll,pii> lpip;
typedef pair<pii,ll> lppi;
typedef pair<pii,pii> lppp;
typedef pair<ll,pll> lpipl;
typedef pair<pll,ll> lppli ;
typedef pair<pll,pll> lplpl ;
typedef vector<int> vi ;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef set<int> sti;
typedef set<ll> stl;
typedef set<pii > stpi;
typedef set<pll> stpl;
typedef vi::IT vit;
typedef vl::IT vlt;
typedef vpi::IT vpit;
typedef vpl::IT vplt;
typedef sti::IT stit;
typedef stl::IT stlt;
typedef stpi::IT stpit;
typedef stpl::IT stplt;
typedef vpi::RIT rvpit;
typedef vpl::RIT rvplt;
typedef sti::RIT rstit;
typedef stl::RIT rstlt;
typedef stpi::RIT rstpit;
typedef stpl::RIT rstplt;

const int MAXN = 500000;
const int SUPERN = 5000000;
const int MAXS = 325;
const int SUPERS = 1000;
const int MD = 1e9+7;
//......Structures.......

//......Variables........
int cnt[MAXN],x,n,re;
//......Funcs............
ll sum(ll a,ll b)
{
    return (a+b)%MD;
}
ll mu(ll a,ll b)
{
    return (a*b)%MD;
}
ll mn(ll a,ll b)
{
    return(a-b+MD)%MD;
}
//......Code.............
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n;
    rep(i,1,n)
    {
        cin>>x;
        cnt[x]++;cnt[x+1]++;
        cnt[x-1]++;
        re=max(max(re,cnt[x]),max(cnt[x-1],cnt[x+1]));
    }
    cout<<re;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)
vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  int n,count=0;
  cin >> n;
  
  rep(i,n){
    if(i<10){
      count++;
    }
    else if(100<=i && i<1000){
      count++;
    }
    else if(10000<=i && i<100000){
      count++;
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define SIZE 3
#define N 3
int main(void) {
    int i,j,flag;
    char board[SIZE*SIZE];
    while (scanf("%s\n",board)!=EOF) {
        flag =0;
        for(i=0;i<SIZE*SIZE;i++){
            if (i+(N-1)*SIZE<=i%SIZE+SIZE*(SIZE-1)) {
            	if (board[i]=='o'||board[i]=='x') {
                    for(j=0;j<N-1;j++) {
                        if (board[i+j*SIZE]!=board[i+(j+1)*SIZE]) break;
                        if (j==N-2) flag=1;
                    }
                }
            }
            if (i+N-1<=(i/SIZE)*SIZE+(SIZE-1)&&flag==0) {
                if (board[i]=='o'||board[i]=='x') {
                    for(j=0;j<N-1;j++) {
                        if (board[i+j]!=board[i+(j+1)]) break;
                        if (j==N-2) flag=1;
                    }
                }
            }
            if (i+(N-1)*(SIZE+1)<=SIZE*SIZE-1&&flag==0) {
                if (board[i]=='o'||board[i]=='x') {
                    for(j=0;j<N-1;j++) {
                        if (board[i+j*(SIZE+1)]!=board[i+(j+1)*(SIZE+1)]) break;
                        if (j==N-2) flag=1;
                    }
                }
            }
            if (i+(N-1)*(SIZE-1)<=SIZE*(SIZE-1)&&((i+(N-1)*(SIZE-1))/SIZE-i/SIZE==N-1)&&flag==0) {
                if (board[i]=='o'||board[i]=='x') {
                    for(j=0;j<N-1;j++) {
                        if (board[i+j*(SIZE-1)]!=board[i+(j+1)*(SIZE-1)]) break;
                        if (j==N-2) flag=1;
                    }
                }
            }
            if (flag==1) {
                printf("%c\n",board[i]);
                break;
            } else if (i==SIZE*SIZE-1) {
                printf("d\n");
            }
        }
    }
    return 0;
}

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

int countDivisors(int x) {
    int ans = 0;
    for (int i = 1; i <= x; ++i) if (x % i == 0) ans++;
    return ans;
}

int main() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i += 2) if (countDivisors(i) == 8) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main {

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

        long tmp = sc.nextLong();
        for (int i = 1; i < N; i++) {
            long value = sc.nextLong();
            long gcd = gcd(tmp, value);
            tmp = (Math.max(value, tmp) / gcd) * Math.min(value, tmp);
        }
        System.out.println(tmp);
    }

    static long gcd (long a, long b) {return b > 0 ? gcd(b,a%b) : a; }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define line printf("-----------------------------\n")
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
int n;
vector<int> v;
ll dp[4][4000];
ll call(int ind,int cnt)
{

    if(cnt==n ) return 1;
    if(ind>=3) return 0;
    int a=0,b=0;
    ll &ret=dp[ind][cnt];
    if(ret!=-1) return ret;
    for(int i=0;i<=n/v[ind];i++)
    {
            if(cnt+v[ind]*i<=n) a+=call(ind+1,cnt+v[ind]*i);
            else break;
    }
    return ret=a;
}
int   main()
{
    memset(dp,-1,sizeof dp);
    for(int i=0;i<3;i++)
    {
        int x;
        scanf("%d",&x);  v.pb(x);
    }
    scanf("%d",&n);
    ll d=call(0,0);
    printf("%lld\n",d);
}


Measured memory_bytes: 384
#include <bits/stdc++.h> 
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=100005;

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

	int a,b,m;
	cin>>a>>b>>m;
	int A[a],B[b];
	for(int i=0;i<a;i++) cin>>A[i];
	for(int i=0;i<b;i++) cin>>B[i];
	int mn=*min_element(A,A+a);
	int mn1=*min_element(B,B+b);
	int ans=mn+mn1;
	for(int i=0;i<m;i++)
	{
		int x,y,c;
		cin>>x>>y>>c;
		x--; y--;
		ans=min(ans,A[x]+B[y]-c);
	}
	cout<<ans;
}
// When you want to succeed as bad as you want to breathe, only then you’ll Be Successful!
// No Matter,How Fast You Are Driving If You Are Driving in a Wrong Direction You Will Never Reach Your Destination
// When failures hit you, you hit the failures back with Bounce Back!
// When you face failures, Don’t change your goal, Change your strategy!

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N, M, ans =0;
  std::cin >> N >> M;
  vvl ab = vv(N, 2, 0, ll);
  for(int i=0;i<N;i++) std::cin >> ab[i][0] >> ab[i][1];
  sort(ab.begin(), ab.end());
  multiset<ll> amari;
  int now = 0;
  for(int i=0;i<=M;i++){
    while(now<N&&ab[now][0] <= i){
      amari.insert(ab[now][1]);
      now++;
    }
    auto las = amari.end();
    if(amari.size()!=0){
      las--;
      ans += (*las);
      amari.erase(las);
    }

  }
  std::vector<ll> dp(M+1, 0);
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 11136
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

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

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)
ll a[100009],b[100009],c[100009];
ll dp[100009][4];

ll DP(ll n,ll type)
{
    if(dp[n][type]!=-1)
    {
        return dp[n][type];
    }
    if(n==0)
    {
        if(type==1)
        {
            return dp[n][type] = a[n];
        }
        else if(type==2)
        {
            return dp[n][type] = b[n];
        }
        else if(type==3)
        {
            return dp[n][type] = c[n];
        }
    }

    if(type==1)
    {
        return dp[n][type] = a[n] + max(DP(n-1,2),DP(n-1,3));
    }
    else if(type==2)
    {
        return dp[n][type] = b[n] + max(DP(n-1,1),DP(n-1,3));
    }
    else if(type==3)
    {
        return dp[n][type] = c[n] + max(DP(n-1,1),DP(n-1,2));
    }
}
int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    cin>>n;
    rep0(i,n)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    memset(dp,-1,sizeof dp);
    x = max(DP(n-1,1),DP(n-1,2));
    x = max(x,DP(n-1,3));
    cout<<x<<endl;
    return 0;
}



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

#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  string s;
  cin >> s;
  int ans = 0;
  rep(i, 4) ans += s[i] == '+' ? 1 : -1;
  cout << ans << endl;
}


Measured memory_bytes: 256
/*You must start someday...*/

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

#define EPS (1e-9)
#define ll long long int
#define ull unsigned long long
#define pi (acos(-1.0))
#define endl "\n"
#define all(v) v.begin(),v.end()
#define printa(a,L,R) for(int i=L;i<R;i++) cout<<a[i]<<(i==R-1?'\n':' ')
#define precise(n) cout << fixed << setprecision(n)
#define show(a) cout << (#a) << " is " << (a) << endl;
#define pcase cout<<"Case "<<++cs<<": "
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
const int mod=1e9+7;
const int mx=1e5+10;
long long int bigmod(long long int a,long long int b,long long int c)
{
    if(b==0)
    {
        return 1;
    }
    if(b%2==0){
        long long int value = bigmod(a,b/2,c);
        return (value * value)%c;
    }
    else if (b%2==1){
        long long int x,y;
        x=a%c;
        y=bigmod(a,b-1,c);
        return (x*y)%c;
    }
}
ll binpow(ll base, ll exp){ll res = 1;while(1){ if(exp&1) res*=base;exp>>=1;if(!exp)break;base*=base;}return res;}
vector<int> adj[mx];
int vis[mx],indegree[mx],dist[mx];
void dfs(int s)
{
    vis[s]=1;
    
    for(int v: adj[s])
    {
        dist[v]=max(dist[v],dist[s]+1);
        indegree[v]--;
        if(!vis[v]&&!indegree[v])
            dfs(v);
    }

    

}
void solve()
{
    int n,k,m;
    cin >> n >> m;
    
    ll sum=0,last=0;
    for (int i = 0; i < m; ++i )
    {
            int u,v,w;
            cin >> u >> v;
            adj[u].push_back(v);
            ++indegree[v];

    }
    int c=0;
    int ans=0;
    for (int i = 1; i <= n; ++i )
    {
            if(!vis[i]&&!indegree[i]) dfs(i);
    }
    for (int i = 0; i <=n; ++i )
    {
            ans=max(ans,dist[i]);
    }

    cout << ans << endl;



    
}

int main(int argc, char const *argv[])
{
    FAST
    int t,cs=0;
    t=1;
    while(t--)
    {
      //pcase;
      solve();
    } 
    

    return 0;
}

Measured memory_bytes: 9984
from collections import Counter
N = input()
A = list(map(int, input().split()))
C = Counter(A)
M = [0, 0]
for k, v in C.items():
    if v < 2: continue
    M.append(k)
    if v >= 4:
        M.append(k)
    M.sort(reverse=True)
    M = M[:2]
print(M[0]*M[1])

Measured memory_bytes: 18600
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
int main()
{	
    int n,i,ans=0,ant=0;
	char str[110000];
	scanf("%s",&str);
	n=strlen(str);
	for(i=0; i<n-1; i++)
	{
		if(str[i]!=str[i+1])
		 ans+=1;
	}

	  printf("%d",ans);
	
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(
					System.in));
			String line = br.readLine();
			int i = line.length();
			StringBuilder sb = new StringBuilder();
			while (i > 0) {
				sb.append(line.substring(i - 1, i));
				i--;
			}
			System.out.println(sb);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 23912
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
 
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
 
  int ans = 0;
  rep(i, n - 2) {
    if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') ++ans;
  }
 
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//inline int in() { int x; scanf("%d",&x); return x;}
template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  string s;
  cin >> s;
  int n = s.size();
  int ans = 0;
  for (int l = 0; l < n; ++l) {
    for (int r = l+1; r <= n; ++r) {
      bool ok = true;
      for (int i = l; i < r; ++i) {
        if (s[i] != 'A' && s[i] != 'C' && s[i] != 'G' && s[i] != 'T') {
          ok = false;
          break;
        }
      }
      if (ok) ans = max(ans, r-l);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
long long int n,ans=0;
  cin >> n;
  long long int a[300010];
  
  for (int i=0;i<3*n;i++)
    cin >> a[i];
  sort(a,a+3*n,greater<int>());
 
  
  for (int i=0;i<n;i++)ans+=a[1+2*i];
  cout << ans <<endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
 
#define left nadnlassad
#define right asdaslknd
#define y1 kjdajasjdsas
#define nxt accepted
#define prev why_would_you_call_when_you_are_high
 
#define pb push_back
#define mp make_pair
#define mt make_tuple
 
#define f first
#define s second
 
#define ll long long
#define ld long double
#define ull unsigned ll
 
#define _hash pair<ll, ull>
#define pii pair<int, int>
#define uint unsigned int
#define puu pair<uint, uint>
 
#define sqr(x) ((x) * 1LL * (x))
 
#define vec vector<int>
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
#define endl "\n"
#define _bits(x) __builtin_popcountll(x)
 
using namespace std;
 
void rf() {
    #define fname "sparse"
    #ifdef SONY
        freopen("input.txt", "r", stdin);
        //freopen("output1.txt", "w", stdout);
    #else
       // freopen(fname".in", "r", stdin);
       // freopen(fname".out", "w", stdout);
    #endif //SONY
}
 
const int nx[8] = {2, -2, -2, 2, 1, 1, -1, -1};
const int ny[8] = {1, 1, -1, -1, 2, -2, -2, 2};
const int Nx[4] = {0, 0, -1, 1};
const int Ny[4] = {1, -1, 0, 0};
 
const ll LINF = (ll) 5e18;
const int INF = 1e9 + 7;
 
const int N = 3e5 + 1;
const int MAXN = 1e6 + 50;
const double EPS = 1e-9, PI = 3.14159265359;
int n;
int a[N];
  
int main() {
    srand(time(0));
    //ios_base::sync_with_stdio(0), cin.tie(0);
    rf();
    scanf("%d", &n);
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        if (a[i - 1] && a[i]) {
            a[i]--;
            ans++;    
        }
        ans += a[i] / 2;
        a[i] %= 2;
    }     
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int K, N;
	cin >> K >> N;
	vector<int>A(N);

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

	A.push_back(A[0] + K);
	int L = 0;

	for (int i = 0; i < N; i++){
		L = max(L, A[i + 1] - A[i]);
	}
	cout << K - L << endl;

	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int[] a= new int[4];
		for(int i=3;i>=0;i--){
			int x=n%10;
			a[i]=x;
			n=n/10;
		}
		System.out.println(a[0]+test(a,0,a[0],String.valueOf(a[0])));

	}

	public static String test(int a[],int i,int Ans,String str){
		if(i==2){
			if(Ans+a[i+1]==7){
				return new String("+"+a[i+1]+"=7");
			}
			if(Ans-a[i+1]==7){
				return new String("-"+a[i+1]+"=7");
			}
			return "";
		}else{
			if(!str.equals("")){
				if(!test(a,i+1,Ans+a[i+1],str).equals("")){
					return new String("+"+a[i+1]+test(a,i+1,Ans+a[i+1],str));
				}
				if(!test(a,i+1,Ans-a[i+1],str).equals("")){
					return new String("-"+a[i+1]+test(a,i+1,Ans-a[i+1],str));
				}
			}
			return "";
		}
	}

}


Measured memory_bytes: 21972
import bisect
a, b, c, d, e, f = map(int, input().split())
a = a * 100
b = b * 100
g = f * e // 100
wtr = [0] * f
sgr = [0] * g
wtr[0] = 1
sgr[0] = 1
wtr_l = []
sgr_l = []


def comb(lmt, tgt, lis):
    for i in range(lmt - tgt):
        if lis[i] != 0:
            lis[i + tgt] = 1


comb(f, a, wtr)
comb(f, b, wtr)
comb(g, c, sgr)
comb(g, d, sgr)

for i, w in enumerate(wtr):
    if i == 0:
        continue
    elif w == 1:
        wtr_l.append(i)

for j, s in enumerate(sgr):
    if s == 1:
        sgr_l.append(j)

res = -1
ans = []
for wt in wtr_l:
    pct = min(f - wt, wt * e // 100)
    sid = bisect.bisect_left(sgr_l, pct)
    if pct in sgr_l:
        sgr_max = sgr_l[sid]
    else:
        sgr_max = sgr_l[sid - 1]
    pct_max = 100 * sgr_max / (wt + sgr_max)
    if pct_max > res:
        res = pct_max
        ans.append((wt + sgr_max, sgr_max))
print(*ans[-1])


Measured memory_bytes: 3188
#include <iostream>
using namespace std;
int main() {
    long long n; cin >> n;
    if (n % 2) cout << "0\n";
    else {
        long long ans = 0;
        n /= 2;
        while (n > 0) ans += n /= 5;
        cout << ans << endl;
    }
}


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

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

const int N = 2e5+10 , mod = 1e9+7;

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int n;
   cin >> n;
   int f[N];
   f[0] = 0;
   for(int i = 1 ; i < N ; i++){
      f[i] = f[i % __builtin_popcount(i)] + 1;
   }
   string x;
   cin >> x;
   int cnt = 0;
   for(int i = 0 ; i < n ; i++)
      cnt += (x[i] == '1');
   if(cnt == 0){
      for(int i = 0 ; i < n ; i++)
         cout << 1 << "\n";
      return 0;
   }
   if(cnt == 1){
      for(int i = 0 ; i < n ; i++){
         if(x[i] == '1')
            cout << 0 << "\n";
         else if(i == n - 1 || x[n - 1] == '1')
            cout << 2 << "\n";
         else
            cout << 1 << "\n";
      }
      return 0;
   }
   int pw1[n] , pw2[n];
   int val1 = 0 , val2 = 0;
   for(int i = n - 1 , cur1 = 1 , cur2 = 1 ; i >= 0 ; i-- , cur1 = (cur1 * 2) % (cnt - 1) , cur2 = (cur2 * 2) % (cnt + 1)){
      pw1[n - 1 - i] = cur1;
      pw2[n - 1 - i] = cur2;
      if(x[i] == '1'){
         val1 = (val1 + cur1) % (cnt - 1);
         val2 = (val2 + cur2) % (cnt + 1);
      }
   }

   for(int i = 0 ; i < n ; i++){
      int add = -1 , newVal = -1;
      if(x[i] == '0'){
         add = pw2[n - 1 - i];
         newVal = val2;
         newVal = (newVal + add) % (cnt + 1);
      }
      else{
         add = (cnt - 1) - pw1[n - 1 - i];
         newVal = val1;
         newVal = (newVal + add) % (cnt - 1);
      }
      cout << f[newVal] + 1 << "\n";
   }
   return 0;
}


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

int n;

void solve(vector<int>& sq, int idx)
{
  bool output = true;
  for (int i = 0; i < n-1; ++i) {
    if (sq[i] < sq[i+1]) {
      output = false;
      break;
    }
  }

  if (output) {
    printf("%d", sq[0]);
    for (int i = 1; i < n; ++i) {
      if (sq[i] == 0)
	break;
      printf(" %d", sq[i]);
    }
    puts("");
  }

  int init = 1;
  if (idx != 0 && sq[idx-1] < sq[idx])
    init = sq[idx] - sq[idx-1];

  for (int i = init; sq[idx]-i > 0; ++i) {
    sq[idx] -= i;
    sq[idx+1] += i;
    solve(sq, idx+1);
    sq[idx+1] -= i;
    sq[idx] += i;
  }
}

int main()
{
  while (~scanf("%d", &n)) {
    if (n == 0)
      break;
    vector<int> sq(n, 0);
    sq[0] = n;
    solve(sq, 0);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
#define PB push_back

#define N 100'005
int n;
int a[N][3];
int p[N][3];

int main(){
	scanf("%d", &n);
	REP(i, n) REP(j, 3) scanf("%d", a[i]+j);
	REP(j, 3) p[0][j] = a[0][j];
	FOR(i, 1, n){
		REP(j, 3){
			p[i][j]=INT_MIN;
			REP(k, 3) if(j!=k){
				LAR(p[i][j], p[i-1][k]+a[i][j]);
			}
		}
	}
	printf("%d\n", max(max(p[n-1][0], p[n-1][1]), p[n-1][2]));
}


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

int main() {
    
    int a, b;
    string op;
    cin >> a >> op >> b;

    int ans;

    if(op == "+"){
        ans = a + b;
    }
    else if(op == "-"){
        ans = a - b;
    }



    cout << ans << endl;

    return 0;

}





Measured memory_bytes: 3588
// C - Replacing Integer
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main(){
    ll n, k;
    cin >> n >> k;
    ll t = n%k;
    ll ans = min(t, k-t);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
s = input()
k = int(input())

ans = ''

for i in range(len(s)-1):
    a = 123-ord(s[i])
    if a==26:
        a=0
    if a<=k:
        ans += 'a'
        k-=a
    else:
        ans += s[i]

ans += chr((ord(s[-1])+k-97)%26+97)

print(ans)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INF = 1ll << 60;

int main() {
  vector<int> v(4);
  for (int i = 0; i < 4; i++) { cin >> v[i]; }
  sort(v.begin(), v.end());
  if (v[0] == 1 && v[1] == 4 && v[2] == 7 && v[3] == 9)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


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

int main(){
  int64_t N;
  cin >> N;
  double s=sqrt(N*1.0);
  int S=int(s);
  int64_t MIN=10000000000000;
  for(int64_t i = 1; i<s+1; i++){
    if(N%i==0){
      MIN=min(MIN,N/i+i-2);
    }
  }
  
  cout << MIN << endl;
}

Measured memory_bytes: 384
N,X = map(int,input().split())
L = [0] + [int(x) for x in input().split()]

D = [0] * (N+2)
answer = 1
for n in range(2,N+2):
  D[n] = D[n-1] + L[n-1]
  if D[n] <= X:
    answer += 1
    
print(answer)

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

#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define each(it,v) for(auto &it : v)
#define all(v) (v).begin(),(v).end()
#define mod 1e9+7

using namespace std;
using vi = vector<int>;
using vl = vector<long>;
using P = pair<int,int>;

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

        vi v(n*3);
        each(it,v)cin>>it;

        sort(all(v));

        long ans=0;
        rep(i,n)
        {
                ans+=v[i*2+n];
        }
        cout<<ans<<endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;

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

    int n, a;
    cin >> n >> a;

    if(n % 500 <= a){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
# # # coding=utf-8
# # # Author: lee215

get = lambda: int(raw_input().strip())

import collections


def valid(S):
    if "AGC" in S:
        return False
    for i in xrange(len(S)):
        S2 = S[:i] + S[i:i + 2][::-1] + S[i + 2:]
        if "AGC" in S2:
            return False
    return True


N = get()
# N = 100
mod = 10**9 + 7
count = collections.Counter({"": 1})
for _ in xrange(N):
    count2 = collections.Counter({"": 0})
    for pre in count:
        for X in "AGCT":
            cur = pre + X
            if valid(cur):
                count2[cur[-3:]] += count[pre] % mod
    count = count2


print sum(count.values()) % mod


Measured memory_bytes: 2812
#include <stdio.h>

int main() {
    int a, b, max;
    scanf("%d %d", &a, &b);
    for (int i=0; i<3; ++i) {
        if (i==0) {
            max = a+b;
        } else {
            if (a-b > max)  max = a-b;
            if (a*b > max)  max = a*b;
        }
    }
    printf("%d\n", max);
    return 0;
}


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

int n, k, q;

int main() {
  cin >> n >> k >> q;
  vector<int> a(q);
  rep (i, q) {
    cin >> a.at(i);
  }
  vector<int> score(n, 0);
  rep (i, q) {
    score.at(a.at(i) - 1)++;
  }
  rep (i, n) {
    cout << (score.at(i) > q-k ? "Yes" : "No") << endl;
  }
  return 0;
}


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

using namespace std;

int main(){
    int n; cin >> n;
    bool flag = false;
    for(int i = 0; i < n; i++){
        char c; cin >> c;
        if(c == 'Y'){
            flag = true;
            break;
        }
    }
    if(flag){
        cout << "Four" << endl;
    }
    else{
        cout << "Three" << endl;
    }

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a), i##_end_ = (b); i <= i##_end_; ++i)
#define drep(i, a, b) for(int i = (a), i##_end_ = (b); i >= i##_end_; --i)
#define clear(a, b) memset((a), (b), sizeof(a))
typedef long long LL;
int read() {
	int x = 0, flag = 1;
	char ch = getchar();
	while(!isdigit(ch)) {
		if(ch == '-') flag = -1;
		ch = getchar();
	}
	while(isdigit(ch)) {
		x = x * 10 + ch - 48;
		ch = getchar();
	}
	return x * flag;
}

#define Maxn 100009
struct node{
	int id, val;
}a[Maxn];
int n, b[Maxn];
int cmp(node a, node b) {
	return a.val < b.val;
}
int ans;
int main() {
#ifdef Qrsikno
	freopen("AGC003_3.in", "r", stdin);
	freopen("AGC003_3.out", "w", stdout);
#endif
	n = read();
	rep(i, 1, n) a[i].id = i, a[i].val = read();
	sort(a + 1, a + n + 1, cmp);
	rep(i, 1, n) a[i].val = a[i].id, a[i].id = i;
	sort(a + 1, a + n + 1, cmp);
	rep(i, 1, n)
		ans += (i & 1) ^ (a[i].id & 1);
	printf("%d\n", ans >> 1);
	return 0;
}


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

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(void) {
  int yama[51], tmp[51];

  int n, r;
  while (cin >> n >> r, (n || r)) {
    // initialization
    for (int i=0; i<n; i++) {
      yama[i] = i + 1;
    }

    // shuffle
    for (int i=0; i<r; i++) {
      int p, c;
      cin >> p >> c;

      for (int j=0; j<c; j++) {
        tmp[c-1-j] = yama[n-p-j];
      }
      for (int j=n-p+1; j<n; j++) {
        yama[j-c] = yama[j];
      }
      for (int j=0; j<c; j++) {
        yama[n-c+j] = tmp[j];
      }
    }

    cout << yama[n-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 3056