akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
#include <tuple>
#include <iomanip>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define MOD 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
#define LLINF 1LL<<60
const double PI = 3.14159265358979323846;

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

	int N; cin >> N;
	int M = N;
	int sum = 0;
	while (M > 0) {
		sum += M % 10;
		M /= 10;
	}

	if (N % sum == 0) cout << "Yes" << endl;
	else cout << "No" << endl;



	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.PriorityQueue;

public class Main {

	public static void main(String[] args) throws IOException {
		// 入力行数 <= 1E5 → buff使うと実行時間半減した
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] inputs;
		inputs = br.readLine().split(" ");
		int n = Integer.parseInt(inputs[0]);
		int m = Integer.parseInt(inputs[1]);
		
		// 遅延日数ごとに仕事をグルーピング
		@SuppressWarnings("unchecked") ArrayList<Integer>[] jobs = new ArrayList[m + 1]; 
		for ( int i = 0; i <= m; i++ ) {
			ArrayList<Integer> a = new ArrayList<>();
			a.add(0); // ダミー要素
			jobs[i] = a;
		}
		for ( int i = 0; i < n; i++ ) {
			inputs = br.readLine().split(" ");
			int d = Integer.parseInt(inputs[0]);
			int f = Integer.parseInt(inputs[1]);
			if ( d > m ) continue; // 遅延日数的に候補になりえない仕事は除外
			jobs[d].add(f);
		}

		long earn = 0;		
		PriorityQueue<Integer> jobPool = new PriorityQueue<Integer>(Collections.reverseOrder());

		// m日目をゼロとして考え後退していく days:残り日数
		for ( int thatDay = 0; thatDay <= m; thatDay++ ) {
			jobPool.addAll(jobs[thatDay]);
			earn += (long) jobPool.poll();
		}

		System.out.println(earn);
		br.close();
	}
}

Measured memory_bytes: 56764
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007
//#define DEBUG

//qsort用、昇順
int compare_int(const void *a, const void *b)
{
	return *(int*)a-*(int*)b;
}
//qsort(array, 10, sizeof(int), compare_int)



int main(){
	char str[8];
	int ren=0, max=0;
	scanf("%s", str);

	for(int i=0; i<3; i++){
		if(str[i] == 'R'){
			ren++;
			if(ren>max) max = ren;
		}
		else{
			ren = 0;
		}

	}

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



Measured memory_bytes: 1720
#B
n = int(input())
p = list(map(int,input().split()))
cnt = 0
i = 0
for i in range(n - 2):
    if p[i] < p[i + 1] < p[i + 2] or p[i] > p[i + 1] > p[i + 2]:
        cnt += 1
print(cnt)


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

int main(){
	using ll = long long int ;
	int n ; cin >> n ;
	vector<ll> a(n) ;
	vector<ll> b(n) ;
	vector<ll> c(n) ;
	ll sum_a = 0 ;
	for(int i=0;i<n;i++){
		cin >> a.at(i) ;
		sum_a += a.at(i) ;
	}
	ll sum_b = 0 ;
	for(int i=0;i<n;i++){
		cin >> b.at(i) ;
		sum_b += b.at(i) ;
		c.at(i) = a.at(i)-b.at(i) ;
	}
	if(sum_a<sum_b){
		cout << -1 << endl ;
		return 0 ;
	}
	sort(c.begin(),c.end()) ;
	ll cnt,sum ;
	cnt = sum = 0 ;
	for(int i=0;i<n;i++){
		if(c.at(i)<0){
			cnt++ ;
			sum += -1*c.at(i) ;
		}else{
			break ;
		}
	}
	for(int i=n-1;i>=0;i--){
		if(sum>0){
			cnt++ ;
			sum -= c.at(i) ;
		}
	}
	cout << cnt << endl ;
}


Measured memory_bytes: 2560
#include<iostream>
#include<deque>
#include<algorithm>
#include<functional>
#include<string>
#include<unordered_map>
#include<map>
#include<cstdio>
#include<set>
using namespace std;

int main() {
	string a;
	cin >> a;
	if (a.length() == 2) {
		if (a[0] == a[1]) { puts("1 2"); }
		else puts("-1 -1");
		return 0;
	}
	for (int i = 0; i < a.length() - 2; i++) {
		if (a[i] == a[i + 1] || a[i] == a[i + 2] || a[i + 1] == a[i + 2]) {
			cout << i + 1 << " " << i + 3 << endl;
			return 0;
		}
	}
	puts("-1 -1");
}

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

int main() {
    int N;
    cin >> N;
  	vector<int> X(N);
    for(int i=0;i<N;i++) cin >> X.at(i);
    int hp_min=10000000, tmp=0;

    for(int i=1;i<=100;i++){
        tmp=0;//体力の総和
        //それぞれの人の消費する体力を求める：(X(j)-i)^2
        for(int j=0;j<N;j++){
            tmp += (X.at(j)-i)*(X.at(j)-i);
        }
        if(tmp < hp_min) hp_min = tmp;
    }

    cout << hp_min << endl;

    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define reg register
typedef long long ll;

const int maxn = 105;

int N;
int P[maxn];

ll Ans;

struct Node{ int x, y; } A[maxn];

int main(){
        scanf("%d", &N);
        for(reg int i = 1; i <= N; i ++) scanf("%d%d", &A[i].x, &A[i].y);
        for(reg int i = 1; i <= N; i ++) P[i] = i;
        srand(19260817);
        for(reg int i = 1; i <= 10000; i ++){ 
                std::random_shuffle(P+1, P+N+1);
                int x = 0, y = 0;
                ll cur = 0;
                for(reg int j = 1; j <= N; j ++){
                        int id = P[j];
                        int x1 = x + A[id].x, y1 = y + A[id].y;
                        ll tmp = 1ll*x1*x1 + 1ll*y1*y1;
                        if(tmp > cur) x = x1, y = y1, cur = tmp;
                }
                Ans = std::max(Ans, cur);
        }
        printf("%.48lf\n", sqrt(1.0*Ans));
        return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()

using namespace std;
typedef long long ll;

template<typename T>
T gcd(T a, T b) {
    if (a % b == 0) {
        return(b);
    }
    else {
        return(gcd(b, a % b));
    }
}


template<typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

int main(void) {
    map<string, int>m;
    int n;
    cin >> n;
    string s;
    rep(i, n) {
        cin >> s;
        ++m[s];
    }
    cout << "AC x " << m["AC"] << endl
        << "WA x " << m["WA"] << endl
        << "TLE x " << m["TLE"] << endl
        << "RE x " << m["RE"] << endl;
}

/*

*/


Measured memory_bytes: 3636
#include <iostream>
#include <iterator>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <numeric>
#include <iomanip>
#include <limits>
#include <set>
#include <map>
#include <type_traits>
#include <cstdint>
#include <queue>
#define _USE_MATH_DEFINES
#include <math.h>

typedef long long ll;

using namespace std;

//素因数分解
void factoring(ll n, map<ll, ll>& mp) {
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			mp[i]++;
			n /= i;
		}
	}
	if (n != 1) mp[n]++;
}

//絶対値
template<class T, class U = std::make_unsigned_t<T>>
U SafeAbs( T x ) {
    return x < 0 ? -static_cast<uintmax_t>(x) : x;
}

//最大・最小
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//xのn乗
ll mod_pow(ll x, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
//xの逆元
ll mod_inv(ll x, ll mod) {//O(log(mod))
    return mod_pow(x, mod - 2, mod);
}

//nCr
ll ncr(ll n, ll r, ll mod){
	ll res=1;
	ll num=1,den=1;
	for(ll i=n;i>=n-r+1;i--){
		(den*=i)%=mod;
	}
	for(ll i=1;i<=r;i++){
		(num*=i)%=mod;
	}
	
	res=den*mod_inv(num,mod);

	return res%mod;
}


//二分探索
bool isOk(ll index, ll key,vector<ll> &a, bool g){
	if(g){
		if(a[index]<key){
			return true;
		}
	}
	else{
		if(a[index]>key){
			return true;
		}
	}
	return false;
}

ll bin_search(ll key, vector<ll> &a, bool g){
	
	ll l=-1;
	ll r=a.size();

	if(g){
		l=a.size();
		r=-1;
	}

	while(abs(r-l)>1){
		ll mid = (l+r)/2;
		if(isOk(mid, key, a, g)){
			r=mid;
		}
		else{
			l=mid;
		}
	}
	return r;
}


//深さ優先探索
void dfs(vector<string> &m,vector<vector<bool>> &seen, ll x, ll y, ll h, ll w){

	seen[y][x]=true;

	
	for(ll i=0;i<4;i++){
		ll nx=x,ny=y;
		if(i==0){ //up
			ny=y-1;
		}
		else if(i==1){ //down
			ny=y+1;
		}
		else if(i==2){ //right
			nx=x+1;
		}
		else{ //left
			nx=x-1;
		}

		if(nx<0 || nx>=w || ny<0 || ny>=h){
			continue;
		}
		if(seen[ny][nx]){
			continue;
		}
		
		if(m[ny][nx]=='#'){
			continue;
		}

		dfs(m,seen,nx,ny,h,w);
	}
}


void solve(){
	ll n;
	cin>>n;

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

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

	vector<pair<ll,ll>> b;
	ll count=0;
	for(ll i=0;i<n-2;i++){
		count++;
		if(a[i]!=a[i+1]){
			b.push_back(make_pair(count,a[i]));
			count=0;
		}
	}
	b.push_back(make_pair(count+1,a[n-2]));

	vector<ll> c(n,0);
	for(ll i=0;i<b.size();i++){
		c[b[i].second-1]=b[i].first;
	}

	for(ll i=0;i<n;i++){
		cout<<c[i]<<endl;
	}

}

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


Measured memory_bytes: 9528
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int i,j,l,r,m=2019,c[2019]={0};
	cin>>l>>r;
	if(r-l<2018)for(i=l;i<=r;i++)c[i%2019]=1;
	else for(i=0;i<2019;i++)c[i]=1;
	for(i=0;i<2018;i++)for(j=i+1;j<2019;j++)if(c[i]&&c[j])m=min(m,i*j%2019);
	cout<<m<<endl;
	return 0;
}

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

using namespace std;

int main(){
 int n;
  cin >> n;
  int ans=0;
  for(int i=0;i<n;i++){
   int inp;
    cin >> inp;
    while(inp%2==0){ans++;inp/=2;}
  }
  cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 200009
#define ll long long
using namespace std;
ll s1,s2,m=1e9+7;
ll fat[2000009];
ll power(ll x,ll y)
{
    if(y==0)return 1;
    ll p=power(x,y/2)%m;
    p=(p*p)%m;
    return (y%2==0)? p : (x*p)%m;
}
ll modinv(ll a)
{
    return power(a,m-2);
}
int x,y;
int main()
{
    cin>>x>>y;
    while(x>0||y>0)
    {
        if(y>x)
        {
            swap(x,y);
            swap(s1,s2);
        }
        s1++;
        x-=2;
        y-=1;
    }
    if(x<0||y<0)
    {
        cout<<0;
        return 0;
    }
    if(s1<s2)swap(s1,s2);
    fat[1]=1;
    fat[0]=1;
    for(int i=2;i<2000009;i++)
    {
        fat[i]=fat[i-1]*i;
        fat[i]%=m;
    }
    s1+=s2;
    cout<<(fat[s1]*modinv((fat[s1-s2]*fat[s2])%m))%m;
}


Measured memory_bytes: 15872
import numpy as np
from itertools import combinations


n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]
n_idx = [i for i in range(1, n+1)]
price_lst = []
for i in range(1, n+1):
    idx_lst = list(combinations(n_idx, i))
    for idx_tup in idx_lst:
        ans = np.array([0] * m)
        price = 0
        for idx in idx_tup:
            ans += np.array(ca[idx-1][1:])
            price += ca[idx-1][0]
        if all(ans >= x):
            price_lst.append(price)
if len(price_lst) > 0:
    print(min(price_lst))
else:
    print(-1)


Measured memory_bytes: 27560
from itertools import combinations_with_replacement
N,M, Q = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(Q)]
ans = 0


for i in combinations_with_replacement(range(1,M+1), N):
    X = list(i)
    
    ans_1 = 0
    for k in S:
      if X[k[1]-1] - X[k[0]-1] == k[2]:
        ans_1 += k[3]
    if ans_1 > ans:
        ans = ans_1
      
print(ans)


Measured memory_bytes: 68248
#include <iostream>

int main() {
	int a,b;
	std::cin >> a >> b;
	if ((a / 10 >= 1) || (b / 10 >= 1)) {
		std::cout << "-1" << std::endl;
	} else {
		std::cout << a * b << std::endl;
	}
	return 0;
}

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

int main() {
  string s; cin >> s;
  int a = s[0] - '0';
  int b = s[1] - '0';
  int c = s[2] - '0';
  int d = s[3] - '0';

  char op[] = {'+', '-'};

  for(int i = 0; i < 2; i++) {
      for(int j = 0; j < 2; j++) {
          for(int k = 0; k < 2; k++) {
              int ans = a;
              if(op[i] == '+') ans += b;
              if(op[i] == '-') ans -= b;
              if(op[j] == '+') ans += c;
              if(op[j] == '-') ans -= c;
              if(op[k] == '+') ans += d;
              if(op[k] == '-') ans -= d;
              if(ans == 7) {
                  cout << a << op[i] << b << op[j] << c << op[k] << d << "=7" << endl;
                  return 0;
              }
          }
      }
  }
}


Measured memory_bytes: 256
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         String s = infile.readLine();
         String t = infile.readLine();/*
         int N = s.length();
         int M = s.length();
         Node[][] dp = new Node[N+1][M+1];
         for(int i=0; i <= N; i++)
            for(int j=0; j <= M; j++)
               dp[i][j] = new Node(-1, -1, 0);
         for(int i=1; i <= N; i++)
            for(int j=1; j <= M; j++)
            {
               if(s.charAt(i-1) == t.charAt(j-1))
               {
                  int len = dp[i-1][j-1].length+1;
                  if(len > dp[i][j].length)
                     dp[i][j] = new Node(i-1, j-1, len);
               }
               else
               {
                  int len = dp[i][j-1].length;
                  if(len > dp[i][j].length)
                     dp[i][j] = new Node(i, j-1, len);
                  len = dp[i-1][j].length;
                  if(len > dp[i][j].length)
                     dp[i][j] = new Node(i-1, j, len);
               }
            }*/
         System.out.println(solve(s,t));
      }
      public static String solve(String s, String t)
      {
   		if(s.length() == 0 || t.length() == 0) 
            return "";
   		int m = s.length();
   		int n = t.length();
   		int[][] dp = new int[m+1][n+1];
   		for (int i = 1; i <= m; i++) 
   			for (int j = 1; j <= n; j++) 
            {
   				if(s.charAt(i-1) == t.charAt(j-1)) 
                  dp[i][j] = dp[i-1][j-1] + 1;
   				else 
                  dp[i][j] = Math.max(dp[i-1][j], dp[i][j-1]);
   			}
   		int i = m, j = n;
   		StringBuilder sb = new StringBuilder();
   		while(i >= 1 && j >= 1)
         {
   			if(dp[i][j] == dp[i][j-1]) 
               j--;
   			else if(dp[i][j] == dp[i-1][j]) 
               i--;
   			else 
            {
   				sb.append(s.charAt(i-1));
   				i--;
   				j--;
   			}
   		}
   		return sb.reverse().toString();
   	}
   }
   class Node
   {
      public int length;
      public int x;
      public int y;
      
      public Node(int a, int b, int c)
      {
         x = a;
         y = b;
         length = c;
      }
   }

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

int main(){
  int N, A;
  cin >> N >> A;
  vector<int> x(N);
  for (int i=0; i<N; i++) cin >> x[i];
  int X = *max_element(x.begin(),x.end());
  vector<int> y(N);
  for (int i=0; i<N; i++) y[i] = x[i] - A;
  vector<vector<long long> > dp(N+1, vector<long long>(2*N*X));
  for (int j=0; j<N+1; j++){
    for (int t=0; t<2*N*X; t++){
      if ((j==0) && (t==N*X)) dp[j][t] = 1;
      else if ((j>0) && ((t-y[j-1]<0) || (t-y[j-1]>2*N*X))) dp[j][t] = dp[j-1][t];
      else if ((j>0) && ((-1<t-y[j-1]) && (t-y[j-1]<2*N*X+1))) dp[j][t] = dp[j-1][t] + dp[j-1][t-y[j-1]];
      else dp[j][t] = 0;
    }
  }
  cout << dp[N][N*X] -1 << endl;
}


Measured memory_bytes: 2304
#!/usr/bin/env python3
#coding: utf-8

# Volume0 - 0002 (http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0002)

while 1:
    try:
        i = input()
        l = i.split(" ")
        s = int(l[0]) + int(l[1])
        ans = len(str(s))
        print(ans)
    except:
        break

Measured memory_bytes: 6720
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    """
    OPT[N][W] = maximum value obtained with first N items and weights up to W
    OPT[N][W] = max(OPT[N-1][W-w[N]]+v[N], OPT[N-1][W])
    OPT[0][0] = 0
    """
    N, W = read_ints()
    w, v = [], []
    for _ in range(N):
        w0, v0 = read_ints()
        w.append(w0)
        v.append(v0)
    OPT = [[0]*(W+1) for _ in range(N+1)]
    for i in range(1, N+1):
        for j in range(1, W+1):
            OPT[i][j] = OPT[i-1][j]
            if j-w[i-1] >= 0:
                OPT[i][j] = max(OPT[i][j], OPT[i-1][j-w[i-1]]+v[i-1])
    return OPT[-1][-1]


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 118512
#include <bits/stdc++.h>
using namespace std;
#define int long long

int n,ans,sum,fix;
int two[100],v[123456];

signed main(){
  two[0]=1;for(int i=1;i<100;i++)two[i]=two[i-1]*2;
  cin>>n;
  for(int i=0;i<n;i++)cin>>v[i];
  for(int i=0;i<n;i++)sum^=v[i];
  for(int i=0;i<n;i++)v[i]&=(~sum);
  for(int i=59;i>=0;i--){
    bool f=false;
    for(int j=fix;j<n&&!f;j++) if(v[j]&two[i]) f=true,swap(v[fix++],v[j]);
    if(f) for(int j=0;j<n;j++) if((v[j]&two[i])&&(j!=fix-1)) v[j]^=v[fix-1];
  }
  for(int i=0;i<n;i++)ans^=v[i];
  cout<<ans*2+sum<<endl;
}


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

int partition(int a[], int l, int r);
void quick_sort(int a[], int l, int r);

int main(){
  int n, k;
  int *h;
  int i;
  long long n_attack = 0;
  
  scanf("%d %d", &n, &k);

  if((h = (int *)malloc(sizeof(int)*n)) == NULL){
    printf("malloc");
    return 0;
  }
  
  for(i=0; i<n; i++){
    scanf("%d", &h[i]);
  }
  
  quick_sort(h, 0, n-1);
  
  for(i=0; i<n; i++){
    if(i < k){
      continue;
    }
    n_attack += h[n-i-1];
  }
  
  printf("%ld", n_attack);
  return 0;
}

int partition(int a[], int l, int r){
  int i, j, pivot, t;
  
  i = l-1;
  j = r;
  pivot = a[r];
  for(;;){
    while(a[++i] < pivot){
      ;
    }
    
    while(i < --j && pivot < a[j]){
      ;
    }
    
    if(i >= j){
      break;
    }
    
    t = a[i];
    a[i] = a[j];
    a[j] = t;
  }
  
  t = a[i];
  a[i] = a[r];
  a[r] = t;
  
  return i;
}

void quick_sort(int a[], int l, int r){
  int v;
  
  if(l >= r){
    return;
  }
  
  v = partition(a, l, r);
  quick_sort(a, l, v-1);
  quick_sort(a, v+1, r);
}


Measured memory_bytes: 896
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let a = read::<String>();
  let b = read::<String>();
  let c = read::<String>();
  let As = a.chars().nth(0).unwrap();
  let Al = a.chars().nth(a.len() - 1).unwrap();
  let Bs = b.chars().nth(0).unwrap();
  let Bl = b.chars().nth(b.len() - 1).unwrap();
  let Cs = c.chars().nth(0).unwrap();
  let Cl = c.chars().nth(c.len() - 1).unwrap();

  println!("{}", if Al == Bs && Bl == Cs { "YES" } else { "NO" });
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll n;cin >>n;
    vector<ll>a(n);
   unordered_map<ll,int>mp;
    for (int i = 0; i < n; ++i) {
        cin >>a[i];
        mp[a[i]]++;
    }
    sort(all(a));
    vector<bool>ch(n,true);
    for (int i = 0; i < n; ++i) {
        if(mp[1]>0){
            if(a[i]!=1) {
                ch[i] = false;
            }
        }
        for (ll j = 2; j*j <=a[i]; ++j) {
            if(a[i]%j==0){
                if(mp[j]>0||mp[a[i]/j]>0){
                    ch[i]=false;
                }
            }
        }
    }
    ll ans=0;
    for (int i = 0; i < n - 1; ++i) {
        if(a[i]==a[i+1]){
            ch[i]=ch[i+1]=false;
        }
    }
    for (int i = 0; i < n; ++i) {
        if(ch[i])ans++;
    }
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 33264
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main()
{
    int i = 0, a = 1, b = 0, x = 0, jishu = 0, total = 0, y = 0;
    cin >> a >> b;
    y = b;
    while(y > 0)
    {

        y /= 10;
        jishu++;
    }
    for(i = 1; i <= jishu; i++)
    {
        a *= 10;
    }
    total = a + b;
    for(i = 1; i <= 1000; i++)
    {
        if(total == i * i)
        {
            cout << "Yes";
            x = 0;
            break;
        }
        if(total != i * i)
        {
            x = 1;
        }
    }
    if(x == 1)
    {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>

using namespace std;

#define max_x 1000000000

int N;
int X;

int gcd(int a, int b){
  if(b==0) return a;
  return gcd(b, a%b);
}

int main(int argc, char const *argv[]) {
  scanf("%d %d\n", &N, &X);

  int x[N];
  int idx_xmin = 0; int idx_xmax = 1;
  int xmin = max_x; int xmax = 0;
  for (int i = 0; i < N; i++) {
    scanf("%d", &x[i]);
    if(i < N - 1){
      scanf(" ");
    }
    if(x[i] > X){ // diff
      x[i] = x[i] - X;
    } else {
      x[i] = X - x[i];
    }

    if(N == 1){
      printf("%d\n", x[i]);
      return 0;
    }

    if(x[i] > xmax){
      xmax = x[i];
      idx_xmax = i;
    }
    if(x[i] < xmin){
      xmin = x[i];
      idx_xmax = i;
    }
  }

  vector<int> divs;

  //printf("%d %d\n", x[idx_xmin], x[idx_xmax]);
  // sukukamo
  for (int divnum = 1; divnum <= xmin; divnum++) {
    if(x[idx_xmin] % divnum == 0 && x[idx_xmax] % divnum == 0){
      //printf("divs : %d\n", divnum);
      divs.push_back(divnum);
    }
  }
  /*
  if(x[idx_xmax] % xmin == 0){
    //printf("divs : %d\n", xmin);
    divs.push_back(xmin);
  }
  */
  for (int i = 0; i < N; i++) {
    if(i==idx_xmin || i==idx_xmax) continue;
    for(int n = divs.size()-1; n >= 0; n--){
      //printf("divs : %d\n", divs[n]);
      if(x[i]%divs[n] != 0){
        divs.erase(divs.begin() + n);
      }
    }
  }

  printf("%d\n", divs.back());
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll n;
ll a[101010];
ll sum;

int main(){
  cin>>n;
  repl(i,1,n+1)cin>>a[i];
  rep(i,n+1){
    ll d=abs(a[i+1]-a[i]);
    sum+=d;
  }
  repl(i,1,n+1){
    ll d=abs(a[i]-a[i-1])+abs(a[i+1]-a[i])-abs(a[i+1]-a[i-1]);
    cout<<sum-d<<endl;
  }
  return 0;
}


Measured memory_bytes: 2048
# include <cmath>
# include <iostream>
# include <queue>
# include <set>
# include <stack>
# include <string>
# include <vector>
# include <cmath>


using namespace std;


int main() {
    double a, b, x; cin >> a >> b >> x;
    double s = x/a;
    double rad;

    if (s >= a*b/2) {  // triangle
        double h = (a*b-s)*2/a;
        rad = atan2(h, a);
    }
    else {  // rectangle
        double w = s*2/b;
        rad = atan2(b, w);
    }

    double ans = rad/(2*acos(-1))*360;
    printf("%.10f\n", ans);
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define mp	    make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define MOD        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define N	 100
void solve(){
	int a, b, c, d;
	cin>>a>>b>>c>>d;
	int st = max(a, c);
	int en = min(b, d);
	cout<<max(0,en-st)<<endl;
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    t =1;
//     cin>>t;
    while(t--){
        solve();
    }
    return 0;
}



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

public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		int n = Integer.parseInt(str);

		for(int i=0; i<n; i++){
			int c=0;
			double x[] = new double[2];
			double y[] = new double[2];
			double r[] = new double[2];
			String strArray[] = br.readLine().split(" ");

			for(int j=0; j<2; j++){
				x[j] = Double.parseDouble(strArray[c]);
				y[j] = Double.parseDouble(strArray[c+1]);
				r[j] = Double.parseDouble(strArray[c+2]);
				c += 3;
			}
			Judge(x,y,r);
		}
	}

	static void Judge(double x[], double y[], double r[]){
		double d = Math.sqrt(Math.pow(x[0]-x[1], 2) + Math.pow(y[0]-y[1], 2));

		if(r[0]+r[1]<d){
			System.out.println(0);
		}else if(Math.abs(r[0]-r[1]) <= d && d <= r[0]+r[1]){
			System.out.println(1);
		}else if(d < Math.abs(r[0]-r[1])){
			System.out.println(r[0]>r[1] ? 2 :-2);
		}

	}
}

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

int main(void) {
	int R, G, B, N;
	cin >> R >> G >> B >> N;

	int ans = 0;
	for (int i = 0; i <= N / R; ++i) {
		for (int j = 0; j <= N - (i * R); j += G) {
			int b_cnt = N - (i * R) - j;
			if (b_cnt % B == 0)
				++ans;
		}
	}

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


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
int main(){
  int n;
  cin>>n;
  ll K=0;
  for(int i=0;i<n;i++){
    int a;cin>>a;
    if(a%2)K++;
  }
  if(K%2)
    cout<<"NO"<<endl;
  else
    cout<<"YES"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    char x[1001] = {};
    int sum;
    while(1){
        sum = 0;
        scanf( "%s\n" , x );
        if( x[0] == '0' && x[1] == '\0' )break;
        for( int i = 0 ; x[i] != '\0'; i++ ){
            
            sum += x[i] - '0';
        }
        printf( "%d\n" , sum );
    }
}


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

int main() {
 	int N,x=0,b=0;
     string s;
  cin>>N>>s;
      for(int i=0;i<N;i++){
        if(s[i]=='I')
          x++;
        else
          x--;
        b=max(b,x);
      }
  cout<<b<<endl;
}

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

using namespace std;

int main(){
        string s;
        int n,Red=0;
        cin>>n>>s;
        for(int i=0; i<n; i++){
                if(s[i]=='R') Red++;
        }
        if(Red>n-Red)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
        return 0;
}


Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

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

		int[] dix ={-1,0,1,0};
		int[] diy ={0,1,0,-1};


		final int INF = 100000;

		LinkedList<Integer> nexti = new LinkedList<Integer>();
		LinkedList<Integer> nextj = new LinkedList<Integer>();

		int[][] A = new int[H][W];

		for(int i=0;i<H;i++){
			String S=scan.next();
			for(int j=0;j<W;j++){
				String s = S.substring(j,j+1);
				if(s.equals("S")){
					A[i][j]=0;
					nexti.add(i);
					nextj.add(j);
				}else if(s.equals(".")){
					A[i][j]=INF;
				}else{
					A[i][j]=-1;
				}
			}
		}




//MAP探索　1階目のループで1を記入
		for(int w=0;w<K;w++){
			int loop = nexti.size();
			for(int cnt=0;cnt<loop;cnt++){
				int i = nexti.poll();
				int j = nextj.poll();//次に探索できるi,j

				for(int x=0;x<4;x++){

						if(i+dix[x]>=0&&i+dix[x]<H&&j+diy[x]>=0&&j+diy[x]<W&&A[i+dix[x]][j+diy[x]]==INF){
							A[i+dix[x]][j+diy[x]] = w+1;
							nexti.add(i+dix[x]);
							nextj.add(j+diy[x]);
						}
				}
			}
		}

int min=INF;
//0以上K以下でゴールに最も近い点を探す
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(A[i][j]>=0&&A[i][j]<INF){
					min = Math.min(min, i);
					min = Math.min(min, H-i-1);
					min = Math.min(min, j);
					min = Math.min(min, W-j-1);
				}
			}
			}

		int ans =1+(min+K-1)/K;



		System.out.println(ans);



	}

}


Measured memory_bytes: 60816
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int n,x[101],y[101],h[101];
int tx,ty,th;
int main(){
    cin>>n;
    rep(i,n){
        cin>>x[i]>>y[i]>>h[i];
        if(h[i]!=0) tx=x[i],ty=y[i],th=h[i];
    }
    int ah;
    rep(i,101)rep(j,101){
        ah=abs(i-tx)+abs(j-ty)+th;
        bool flag=true;
        rep(k,n){
            int tmp=ah-abs(i-x[k])-abs(j-y[k]);
            if(tmp>0){
                if(tmp!=h[k]){
                    flag=false;
                    break;
                }
            }
            else{
                if(h[k]!=0){
                    flag=false;
                    break;
                }
            }
        }
        if(flag){
            cout<<i<<" "<<j<<" "<<ah<<endl;;
        }
    }
    return 0;
}

Measured memory_bytes: 256
function main(input) {
    input = input.split("\n");
    var N = parseInt(input[0]);
    var Aarray = input[1].split(" ");
    var A = [];
    for (var i = 0; i < N; i++) {
        var a = parseInt(Aarray[i], 10);
        A.push(a);
    }
    var Ap = new Map();
    var Am = new Map();
    var Aplist = [];
    for (var i = 0; i < N; i++) {
        var Ap_tmp = Ap.get(A[i] + i + 1);
        if (Ap_tmp == undefined) {
            Aplist.push(A[i] + i + 1);
            Ap_tmp = 1;
        }
        else
            Ap_tmp++;
        Ap.set(A[i] + i + 1, Ap_tmp);
        var Am_tmp = Am.get(-A[i] + i + 1);
        if (Am_tmp == undefined)
            Am_tmp = 1;
        else
            Am_tmp++;
        Am.set(-A[i] + i + 1, Am_tmp);
    }
    var ans = 0;
    for (var i = 0; i < Aplist.length; i++) {
        var Ap_key = Aplist[i];
        if (Am.get(Ap_key) != undefined)
            ans += Ap.get(Ap_key) * Am.get(Ap_key);
    }

    console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 83928
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <set>
#include <unordered_set>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <numeric>

using namespace std;

typedef long long ll;

#define forn(i, n) for(int i = 0; i < (int)(n);++i)
#define fore(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define fi first
#define se second
#define pb push_back
#define pll pair<ll,ll>
#define vi vector<int>
#define vb vector<bool>
#define vvi vector<vi>
#define vpll vector<pll>
#define vll vector<ll>
#define vvll vector<vll>
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()


void fastik() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

//ifstream &cin
void solve() {

}

int main() {
    fastik();
    //ifstream cin("input.txt");
    /*ll t = 1;
    cin >> t;
    while (t--) {
        solve();
    }*/
    ll n;
    cin >> n;
    vll a(n, 0);
    multiset<ll> s;
    set<ll> ss;
    forn(i, n) {
        cin >> a[i];
        s.insert(a[i]);
        ss.insert(a[i]);
    }
    ll x;
    ll cnt;
    vll ans(ll(2e+5) + 1, 0);
    forn(i, n) {
        if(ans[a[i]]){
            cout << ans[a[i]] << '\n';
            continue;
        }
        for (auto it = ss.rbegin(); it != ss.rend(); ++it) {
            x = *it;
            if (x != a[i]) {
                cout << x << '\n';
                ans[a[i]] = x;
                break;
            } else if ((x == a[i] && s.count(a[i]) > 1)) {
                cout << x << '\n';
                ans[a[i]] = x;
                break;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 19712
from math import sqrt
from itertools import permutations
N=int(input())
xy=[list(map(int,input().split())) for _ in range(N)]
ans=0
cnt=0
for i in permutations(range(N)):
  d=0
  for j in range(N-1):
    dx=xy[i[j+1]][0]-xy[i[j]][0]
    dy=xy[i[j+1]][1]-xy[i[j]][1]
    d+=sqrt(dx**2+dy**2)
  ans+=d
  cnt+=1
print(ans/cnt)

Measured memory_bytes: 9224
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}



int main(){
    const ll S=539;
    const ll MAX=730;
    ll N,M;
    while(cin>>N>>M,N){
        ll r;
        cin>>r;
        vector<vector<ll>> A(M,vector<ll>(MAX,0));
        for(int i=0;i<r;i++){
            ll t,n,m,s;
            cin>>t>>n>>m>>s;
            m--; n--;
            t-=S;
            if(s){
                A[m][t]++;
            }
            else{
                A[m][t]--;
            }
        }
        for(int i=0;i<M;i++){
            for(int j=1;j<MAX;j++){A[i][j]+=A[i][j-1];}
            for(int j=0;j<MAX;j++){A[i][j]=(A[i][j]>0?1:0);}
            for(int j=1;j<MAX;j++){A[i][j]+=A[i][j-1];}
        }
        ll q;
        cin>>q;
        while(q--){
            ll s,e,m;
            cin>>s>>e>>m;
            s-=S; e-=S;
            m--;
            cout<<A[m][e-1]-A[m][s-1]<<endl;
        }
    }
    
    
    return 0;
}



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

long lucas_dp[100];

long lucas(long n) {
    if(lucas_dp[n] != 0)
        return lucas_dp[n];

    long l = lucas(n - 1) + lucas(n - 2);
    lucas_dp[n]= l;
    return l;
}

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    long n;
    cin >> n;
    // long lucas[100];
    lucas_dp[0] = 2;
    lucas_dp[1] = 1;
    // for(int i =2;i<=n;i++){
        // lucas[i] = lucas[i-1]+lucas[i-2];
    // }
    cout<<lucas(n)<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main() {
    int a,b,c,d,e;
    d = 0;
    e = 0;//文字数を代入,dは5の回数、eは７の回数
    cin >> a >> b >> c;
    if (a == 5){
        d++;
    } else if (a == 7) {
        e++;
    }
    if (b == 5){
        d++;
    } else if (b == 7){
        e++;
    }
    if (c == 5){
        d++;
    } else if(c == 7) {
        e++;
    }
    if (d == 2 && e == 1){
        cout << "YES" << endl;
    } else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<bits/stdc++.h>
#define ll long long int
#define hell 1000000007LL
using namespace std;
ll power(ll x, ll y){ 
    if(y==0)
     return 1;
    else
    {
        ll p=power(x,y/2);
        if(y%2==0)
         return (p*p)%hell;
        else
        return (x*((p*p)%hell))%hell;
    }}
ll gcd(ll x,ll y)
{
    if(y==0)
     return x;
    else
    return gcd(y,x%y);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    ll a,b;
    cin>>a>>b;
    cout<<max(max(a+b,2*a-1),2*b-1);}

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

const long long INF = 1LL << 60;

template <class T> bool chmin(T& a, T b)
{
  if (a > b) {
    a = b; return true;
  } else return false;
}

template <class T> bool chmax(T& a, T b)
{
  if (a < b) {
    a = b; return true;
  } else return false;
}

int main() 
{
  int N, K;
  cin >> N >> K;
  vector<long long> h(N + K);
  for (int i = 0; i < N; i++) cin >> h.at(i);
  
  vector<long long> dp(N + K, INF);
  dp.at(0) = 0;
  
  for (int i = 0; i < N; i++)
  {
    for (int j = 1; j <= K; j++)
    {
      chmin(dp.at(i + j), dp.at(i) + abs(h.at(i + j) - h.at(i)));
    }
  }
  
  int ans = dp.at(N - 1);
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

typedef pair <int,int> pii;
typedef vector <pii> vpii;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef long long int lli;
typedef vector <lli> vlli;
typedef vector <vlli> vvlli;
typedef vector <string> vs;
typedef vector <bool> vb;

#define rep(i, n) for( i = 0; i < (n); ++i)
#define repA(i, a, n) for( i = a; i <= (n); ++i)
#define repD(i, a, n) for( i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sortr(x) sort(x.begin(),x.end(),greater <int> ())
#define mod 1000000007
#define ff first
#define ss second
#define fill(a,c)  memset(a, c, sizeof (a))
#define formap(i,v) for(auto &i: v)
#define dbg(x) cout << #x << " = " << x << '\n'
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;
#define dbgstl(v) cout<<#v<<" = \n"; { int c=0; formap(it,v) \
cout<<"    "<<#v<<"["<< ++c <<"] = "<<it<<endl;} cerr<<endl
#define dbgstlp(v) cout<<#v<<" = \n"; { int c=0; formap(it,v) \
cout<<"    "<<#v<<"["<< ++c <<"] = "<<it.first<<" , "<<it.second<<endl;} cerr<<endl
#define PI  3.14159265358979323846
#define pb push_back

int count (int x){
    int cnt=0;
    while (x>0){
        cnt+=(x%2);
        x=x/2;
    }
    return cnt;
}

int main() {
    cin.sync_with_stdio(0);cin.tie(0);
    cin.exceptions(cin.failbit);
    
    
    int i,j,k,n,cnt=0,x,y,l,p;
    string s;
    cin>>n;
    cin>>s;
    rep(i,n){
        if (s[i]=='1')cnt++;
    }
    
    if (cnt==0){
         rep(i,n){
              cout<<1<<endl;
         }
         return 0;
    }
    if (cnt==1){
         rep(i,n){
              if (s[i]=='1')cout<<0<<endl;
              else {
                   if ((s[n-1]=='1')^ (i==n-1))cout<<2<<endl;
                   else  cout<<1<<endl;
              }
         }
         return 0;
    }
    
    vi val(cnt+1,0);
    val[1]=1;val[0]=0;
    repA(i,2,cnt){
        val[i]=val[(i%count(i))]+1;
    }
    x=1,k=0,l=0,y=1;
    repD(i,n-1,0){
        if (s[i]=='1'){
            k+=x;
            k=k%(cnt+1);
            l+=y;
            if (cnt>1)l=l%(cnt-1);
        }
        x=(x*2)%(cnt+1);
        if (cnt>1)y=(y*2)%(cnt-1);
    }
    
    
    
    x=1,y=1;
    vi ans(n);
    repD(i,n-1,0){
        if (s[i]=='1'){
           p= l-y;
           if  (p<0)p+=cnt-1;
           ans[i]=1+val[p];
            
        }
        else{
            p=k+x;
            p=p%(cnt+1);
            ans[i]=1+val[p];
        }
        x=(x*2)%(cnt+1);
        if (cnt>1)y=(y*2)%(cnt-1);
    }
    //reverse(all(ans));
    rep(i,n)cout<<ans[i]<<endl;
    
    
    
    
    
    
    
    
    
     
   
   
	return 0;
}


Measured memory_bytes: 4664
#include<bits/stdc++.h>
#define ll long long
#define REP(i, n) for (int i=0; i<n; ++i)
#define print(x) cout << x << endl;

using namespace std;

void solve() {
    int N, M, C;
    cin >> N >> M >> C;
    vector<int> B(M);
    REP(i, M) cin >> B[i];
    vector<vector<int> > A(N, vector<int>(M));
    REP(i, N) {
        REP(j, M) cin >> A[i][j];
    }
   
    int ans = 0;
    REP(i, N) {
        int total = 0;
        REP(j, M) {
            total += A[i][j] * B[j];
        }
        total += C;
        if (total > 0) ans += 1;
    }
    print(ans);
}

int main() {

    solve();
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<set>
#include<cstdlib>
#include<chrono>

using namespace std;

int d, c[100], s[400][100];
int sat;
int m, t[400];
set<int> app[100];

int last(int d, int i) {
  return *(--app[i].upper_bound(d));
}

int next(int d, int i) {
  return *app[i].upper_bound(d);
}

int random(int x, int y) {
  return rand() % (y - x + 1) + x;
}

int main() {
  scanf("%d", &d);
  for (int i = 1; i <= 26; i++) {
    scanf("%d", &c[i]);
    app[i].insert(0);
    app[i].insert(d+1);
  }
  for (int i = 1; i <= d; i++) {
    for (int j = 1; j <= 26; j++) {
      scanf("%d", &s[i][j]);
    }
  }
  for (int i = 1; i <= d; i++) {
    int best = -2e9, best_j = 0;
    for (int j = 1; j <= 26; j++) {
       int tmp = 0;
       tmp += s[j][t[j]];
       for (int k = 1; k <= 26; k++) {
         if (j == k) {
           continue;
         }
         tmp -= c[k] * (i - last(i, k));
       }
       if (tmp > best) {
         best = tmp;
         best_j = j;
       }
    }
    t[i] = best_j;
    sat += s[i][t[i]];
    app[t[i]].insert(i);
    for (int j = 1; j <= 26; j++) {
      sat -= c[j] * (i - last(i, j));
    }
  }
  auto start = chrono::steady_clock::now();
  auto end = chrono::steady_clock::now();
  while (chrono::duration_cast<chrono::nanoseconds>(end - start).count() < 1.9e9) {
    int best = -2e9, best_i = 0, best_j = 0;
    for (int i = 1; i <= d; i++) {
      for (int j = 1; j <= 26; j++) {
        if (j == t[i]) {
          continue;
        }
        int tmp = 0;
        tmp -= s[i][t[i]];
        tmp -= c[t[i]] * (next(i, t[i]) - i) * (i - last(i - 1, t[i]));

        tmp += s[i][j];
        tmp += c[j] * (next(i, j) - i) * (i - last(i, j));
        if (tmp > best) {
          best = tmp;
          best_i = i;
          best_j = j;
        }
      }
    }
    if (best > 0) {
      app[t[best_i]].erase(best_i);
      app[best_j].insert(best_i);
      t[best_i] = best_j;
      sat += best;
    } else {
      break;
    }
    end = chrono::steady_clock::now();
  }
  for (int i = 1; i <= d; i++) {
    printf("%d\n", t[i]);
  }
}


Measured memory_bytes: 3484
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>
using namespace std;

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

    int ans = 0;

   ans = (X / 500) * 1000;

   X -= 500 * (X / 500);

   ans += (X / 5) * 5;

   cout << ans << endl;
    
}

Measured memory_bytes: 256
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
const ll MAX_N = 1e5;
ll N;
ll h[MAX_N];
ll dp[MAX_N+1]; // メモ化テーブル
 
// i番目以降の品物から重さの総和がj以下になるように選ぶ
void rec(ll i){
	if (i==0) dp[i] = 0;
	else if (i==1) dp[i] = abs(h[1]-h[0]);
	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
	return;
}


vector<ll> a;

// 二分探索 drken
// https://qiita.com/drken/items/97e37dd6143e33a64c8c
// index が条件を満たすかどうか
bool isOK(ll index, ll key) {
    if (a[index] >= key) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
int binary_search(int key) {
    int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int right = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while (right - left > 1) {
        int mid = left + (right - left) / 2;

        if (isOK(mid, key)) right = mid;
        else left = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    return right;
}



int main() {
	// 入力
	ll N;
	cin >> N;
	ll A[N];
	for (ll i = 0; i < N; ++i) cin >> A[i];
 
	
	// 解法
	REP(i,N){
		ll tmp = binary_search(A[i]);
		// cout << tmp << endl;
		if (tmp==0){
			// a.pb(A[i]);
			a.insert(a.begin(), A[i]);
		}
		else{
			a[tmp-1] = A[i];
		}
		// printf("%lld : ", A[i]);
		// REP(i, a.size()) printf("%lld ", a[i]);
		// printf("\n");
	}
	cout<< a.size()<<endl;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/


int n;

void solve(){
    vector<pair<double,string>> v(n);
    rep(i,n){
        string l;
        cin >> l;
        int p,a,b,c,d,e,f,s,m;
        cin >> p >> a >> b >> c >> d >> e >> f >> s >> m;
        double ti = a + b + c + m * (d+e);
        double mo = s * f * m - p;
        double x = mo/ti;
        v[i] = make_pair(-x,l);
    }
    sort(all(v));
    //reverse(all(v));
    rep(i,n){
        cout << v[i].se << endl;
    }
}

int main(){
    while(1){
        cin >> n;
        if(n==0) break;
        solve();
        cout << "#" << endl;
    }
}

Measured memory_bytes: 3160