akhauriyash/Code-Regression huggingface dataset:
while 1:
    n = int(input())
    if n == 0:
        break

    result = []
    for i in range(n):
        data = list(map(str, input().split()))
        name = data.pop(0)
        win = data.count("0")
        lose = data.count("1")
        result.append([name, win, lose])

    result = sorted(result, key=lambda x: (-x[1], x[2]))

    for r in result:
        print(r[0])



Measured memory_bytes: 5604
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

N,K = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

def count_nbd(x,R,parent):
    # parentを含まない部分木
    # xを含む、xから半径R内の点の個数を数える
    count = 0
    visited = [False] * (N+1)
    visited[x] = True
    visited[parent] = True
    count += 1
    q = [x]
    for _ in range(R):
        qq = []
        for y in q:
            for z in graph[y]:
                if visited[z]:
                    continue
                visited[z] = True
                qq.append(z)
                count += 1
        q = qq
    return count

if K&1:
    # 辺の中点に中心がある場合
    R = (K-1)//2
    x = max(count_nbd(x,R,y) + count_nbd(y,R,x) for x,y in AB)
else:
    # 頂点が中心
    R = K//2
    x = max(count_nbd(x,R,0) for x in range(1,N+1))

answer = N-x
print(answer)

Measured memory_bytes: 3572
using System;

namespace A____Fighting_over_Candies
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var a = int.Parse(input[0]);
            var b = int.Parse(input[1]);
            var c = int.Parse(input[2]);
            if (a == b + c || b == a + c || c == a + b)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 13140
import java.util.HashMap;
import java.util.Scanner;

public class Main{

	int p;
	String input;
	HashMap<String, Integer> dict = new HashMap<String, Integer>();

	void run(){
		Scanner in = new Scanner(System.in);
		String line;
		for(;;){
			line = in.next();
			if(line.equals("END_OF_FIRST_PART")) break;
			int w = in.nextInt();
			dict.put(line, w);
		}
		for(;;){
			input = in.next();
			if(input.equals("0")) return ;
			p = 0;
			int ans = mol();
			System.out.println(ans>=0?""+ans:"UNKNOWN");
		}
	}

	int mol(){
		if(p == input.length() || input.charAt(p)==')'){
			return 0;
		}
		int r = mol1();
		if(r==-1) return -1;
		if(p < input.length()){
			int b = mol();
			if(b==-1) return -1;
			r += b;
		}
		return r;
	}

	int mol1(){
		if(input.charAt(p)=='('){
			p++;
			int r = mol();
			if(r==-1) return -1;
			p++;
			r *= num();
			return r;
		}
		else{
			int r = atom();
			if(r == -1) return -1;
			if(p < input.length() && Character.isDigit(input.charAt(p))){
				r *= num();
			}
			return r;
		}
	}

	int atom(){
		StringBuffer bf = new StringBuffer();
		bf.append(input.charAt(p++));
		if(p<input.length() && Character.isLowerCase(input.charAt(p))){
			bf.append(input.charAt(p++));
		}
		String at = bf.toString();
		if(dict.containsKey(at)){
			return dict.get(at);
		}
		else return -1;
	}

	int num(){
		int r = input.charAt(p++) - '0';
		if(p < input.length() && Character.isDigit(input.charAt(p))){
			r = 10*r + input.charAt(p++) - '0';
		}
		return r;
	}

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

Measured memory_bytes: 12000
/*B - Trick or Treat*/
#include <bits/stdc++.h>
using namespace std;

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

	int candies;
	int ans = 0;
	int stores;
	int cant;
	int s;

	cin >> stores >> candies;

	map <int, int> have;

	for (int i = 1; i <= stores; ++i)
	{
		have[i] = 0;
	}


	for (int i = 0; i < candies; ++i)
	{
		cin >> cant;

		for (int i = 0; i < cant; ++i)
		{
			cin >> s;
			have[s]++;		
		}	
	}

	map <int, int>:: iterator it;

	for (it = have.begin() ; it != have.end() ; ++it)
	{
		if(it-> second == 0)
			ans++;
	}

	cout << ans;

	return 0;	
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define INF 1000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll mod = 1000000007;
  ll N;
  cin >> N;
  vector<ll> T(N);
  vector<ll> A(N);
  for (ll i = 0; i < N; ++i)
  {
    cin >> T.at(i);
  }
  for (ll i = 0; i < N; ++i)
  {
    cin >> A.at(i);
  }
  vector<ll> low(N);
  for (ll i = 0; i < N; ++i)
  {
    low.at(i) = min(A.at(i), T.at(i));
  }
  vector<bool> revealed(N, false);
  revealed.at(0) = true;
  if (N == 1)
  {
    if (A.at(0) != T.at(N - 1))
    {
      cout << 0 << endl;
      return 0;
    }
  }
  else
  {
    if (T.at(N - 2) != T.at(N - 1))
    {
      if (A.at(N - 1) != T.at(N - 1))
      {
        cout << 0 << endl;
        return 0;
      }
    }
    if (A.at(0) != A.at(1))
    {
      if (A.at(0) != T.at(0))
      {
        cout << 0 << endl;
        return 0;
      }
    }
  }
  for (ll i = 1; i < N; ++i)
  {
    if (T.at(i) != T.at(i - 1))
    {
      revealed.at(i) = true;
    }
  }
  for (ll i = 0; i < N; ++i)
  {
    if (revealed.at(i))
    {
      if (T.at(i) > A.at(i))
      {
        cout << 0 << endl;
        return 0;
      }
    }
  }

  revealed.at(N - 1) = true;
  for (ll i = N - 2; i >= 0; --i)
  {
    if (A.at(i) != A.at(i + 1))
    {
      if (T.at(i) < A.at(i))
      {
        cout << 0 << endl;
        return 0;
      }
      if (revealed.at(i))
      {
        if (A.at(i) != T.at(i))
        {
          cout << 0 << endl;
          return 0;
        }
      }
      revealed.at(i) = true;
    }
  }

  ll ans = 1;
  for (ll i = 0; i < N; ++i)
  {
    if (revealed.at(i))
    {
      continue;
    }
    ans = (ans * low.at(i)) % mod;
  }
  cout << ans << endl;

  // for (ll i = 0; i < N; ++i)
  // {
  //   if (revealed.at(i))
  //   {
  //     cout << "T";
  //   }
  //   else
  //   {
  //     cout << "F";
  //   }
  // }
  // cout << endl;
}


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

int main() {
  int n, sum = 0;
  cin >> n;
  int d[n];
  REP(i, n) cin >> d[i];
  REP(i, n-1) {
    FOR(j, i+1, n) sum += d[i]*d[j];
  }
  cout << sum << endl;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  string temps;
  
  vector<string> T(H + 2);
  
  T.at(0) = ".";
  T.at(H + 1) = ".";
  for (int j = 1; j <= W + 1; j++) {
    T.at(0) += '.';
    T.at(H + 1) += '.';
  }

  for (int i = 1; i <= H; i++) {
    T.at(i) = ".";
    cin >> temps;
    T.at(i) += (temps + '.');
  }
  
  for (int i = 1; i <= H ; i++) {
    for (int j = 1; j <= W; j++) {
      if (T.at(i).at(j) == '#') {
        cout << '#'; 
      } else {
        int count = 0;
        if (T.at(i - 1).at(j - 1) == '#') {
          count++;
        }
        if (T.at(i - 1).at(j) == '#') {
          count++;
        }
        if (T.at(i - 1).at(j + 1) == '#') {
          count++;
        }
        if (T.at(i).at(j - 1) == '#') {
          count++;
        }
        if (T.at(i).at(j + 1) == '#') {
          count++;
        }
        if (T.at(i + 1).at(j - 1) == '#') {
          count++;
        }
        if (T.at(i + 1).at(j) == '#') {
          count++;
        }
        if (T.at(i + 1).at(j + 1) == '#') {
          count++;
        }
        cout << count;
      }
    }      
  cout << endl;
  }
}

Measured memory_bytes: 256
/*************************************************************************
>>> Author: WindCry1
>>> Mail: lanceyu120@gmail.com
>>> Website: https://windcry1.com
>>> Date: 12/20/2019 2:28:02 AM
*************************************************************************/
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <iostream>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <stack>
#include <bitset>
#include <iomanip>
#include <list>
#include <sstream>
#include <fstream>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
#define ll long long
#define ull unsigned long long
#define DEBUG(x) cout<<#x<<" : "<<x<<endl;
#define lowbit(x) x&(-x)
#define ls(u) u<<1
#define rs(u) u<<1|1
using namespace std;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const double clf = 1e-8;
const int MMAX = 0x7fffffff;
const int INF = 0x3f3f3f3f;
const ll mod = 1e9+7;
const int dir[4][2]={-1,0,1,0,0,-1,0,1};
ostream& operator <<(ostream &out, pii &p){
	return out<<p.first<<" "<<p.second;
}
istream& operator >>(istream &in, pii &p){
	return in>>p.first>>p.second;
}
int cnt[70];
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//ifstream cin("C:\\Users\\LENOVO\\Desktop\\in.txt");
	//ofstream cout("C:\\Users\\LENOVO\\Desktop\\out.txt");
	ll n,t;cin>>n;
	for(int i=0;i<n;i++) {
		cin>>t;
		for(int j=0;j<62;j++){
			cnt[j]+=t&(1LL<<j)?1:0;
		}
	}
	ll res=0;
	for(int i=0;i<62;i++){
		res=(res+(((cnt[i]%mod*((n-cnt[i])%mod))%mod)*((1LL<<i)%mod))%mod)%mod;
	}
	cout<<res%mod<<endl;
	return 0;
}

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

int main() {
  const int inf = 100000000;
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++) cin >> s.at(i);
  vector<vector<int>> cost(h * w, vector<int>(h * w, inf));
  for (int i = 0; i < h * w; i++) {
    cost.at(i).at(i) = 0;
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w - 1; j++) {
      if (s.at(i).at(j) == '.' && s.at(i).at(j + 1) == '.') {
        cost.at(i * w + j).at(i * w + j + 1) = 1;
        cost.at(i * w + j + 1).at(i * w + j) = 1;
      }
    }
  }
  for (int i = 0; i < h - 1; i++) {
    for (int j = 0; j < w; j++) {
      if (s.at(i).at(j) == '.' && s.at(i + 1).at(j) == '.') {
        cost.at(i * w + j).at((i + 1) * w + j) = 1;
        cost.at((i + 1) * w + j).at(i * w + j) = 1;
      }
    }
  }
  for (int k = 0; k < h * w; k++) {
    for (int i = 0; i < h * w; i++) {
      for (int j = 0; j < h * w; j++) {
        cost.at(i).at(j) = min(cost.at(i).at(j), cost.at(i).at(k) + cost.at(k).at(j));
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < h * w; i++) {
    for (int j = 0; j < h * w; j++) {
      if (cost.at(i).at(j) != inf) ans = max(ans, cost.at(i).at(j));
    }
  }
  cout << ans << endl;
}


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

int main()
{
 string str ;
 cin >> str ;
 int flag = 0 ;
 for(int i = 0 ; i < str.size() ; i++)
 {
  if(str[i] == '9')
 {
  flag = 1 ; 
  break;
  }
}
 flag ? cout << "Yes\n" : cout << "No\n" ;
return 0 ;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll MOD = 1E+09 + 7;
const ll INF = 1E18;
const int MAX_N = 1E+05;

int N;

ll A[4][MAX_N + 1], dp[4][MAX_N + 1];

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

    cin >> N;

    for (int i = 1; i <= 3; i++) {
        for (int j = 1; j <= N; j++) {
            cin >> A[i][j];
        }
    }
    for (int i = 1; i <= 3; i++) {
        sort(A[i] + 1, A[i] + N + 1);
    }

    /*
    for (int i = 1; i <= 3; i++) {
        cout << "i = " << i << "\n";
        for (int j = 1; j <= N; j++) {
            cout << A[i][j] << " ";
        }
        cout << "\n";
    }
    */

    for (int i = 1; i <= N; i++) {
        dp[1][i] = i;
    }
    for (int i = 2; i <= 3; i++) {
        for (int j = 1; j <= N; j++) {
            dp[i][j] = dp[i][j - 1] + dp[i - 1][lower_bound(A[i - 1] + 1, A[i - 1] + N + 1, A[i][j]) - A[i - 1] - 1];
        }
    }

    /*
    for (int i = 1; i <= 3; i++) {
        cout << "i = " << i << "\n";
        for (int j = 1; j <= N; j++) {
            cout << "j = " << j << ", dp = " << dp[i][j] << "\n";
        }
    }
    */

    /*
    for (int i = 1; i <= N; i++) {
        cout << "i = " << i << ", BC = " << BC[i] << "\n";
    }
    */

    /*
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cout << "i = " << i << ", j = " << j << ", dp = " << dp[i][j] << "\n";
        }
    }
    */

    cout << dp[3][N] << "\n";

    return 0;
}

Measured memory_bytes: 8336
s = input()
s = s.split()


a = [1,3,5,7,8,10,12]
b = [4,6,9,11]
c = [2]

if(int(s[0]) in a and int(s[1]) in a):
    print("Yes")
elif(int(s[0]) in b and int(s[1]) in b):
    print("Yes")
elif(int(s[0]) in c and int(s[1]) in c):
    print("Yes")
else:
    print("No")

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

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<29;

class mint {
public:
    long long x;
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    //mint operator-() const{ return mint(-x);}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

};
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  int N, K; cin >> N >> K;
  vector<int> a(N + 1);
  rep(i, N + 1) a[i] = i;
  vector<ll> s(N + 2, 0);
  rep(i, N + 1) s[i + 1] = s[i] + a[i];

  mint res = 0;
  mint max, min;
  for (int i = K; i < N + 2; ++i){
    if (i != N + 1) max = s[N + 1] - s[N + 1 - i];
    else max = s[N + 1];
    min = s[i] - s[0];
    res += max - min + 1;
  }
  cout << res.x << endl;
}


Measured memory_bytes: 5540
# coding: utf-8
N, K = gets.split(" ").map{|e| e.to_i}
H = gets.split(" ").map{|e| e.to_i}
ans = 0

# Hの中でK以上の値の数を数える
H.each do |i|
  ans += 1 if i >= K
end
puts ans
  


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

int n, z, w, a[2005];
int main()
{
   cin >> n >> z >> w;
   for (int i = 1; i <= n; i++)
      cin >> a[i];

   if (n == 1)
      cout << abs(a[1] - w);
   else
       cout << max(abs(a[n] - a[n - 1]), abs(a[n] - w));
   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAXN 500005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,k,a[MAXN];
string str;
int maxl[MAXN],maxr[MAXN];
int main()
{
    cin>>str;
    n=(int)str.size();
    maxl[0]=0; maxr[n]=0;
    for(int i=0;i<n;i++)
    {
        if(str[i]=='<') maxl[i+1]=maxl[i]+1; else maxl[i+1]=0;
    }
    for(int i=n-1;i>=0;i--)
    {
        if(str[i]=='>') maxr[i]=maxr[i+1]+1; else maxr[i]=0;
    }
    ll sum=0;
    for(int i=0;i<=n;i++) sum+=max(maxl[i],maxr[i]);
    printf("%lld\n",sum);
    return 0;
}


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



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

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

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

























int main(){
    ll a, p;
    cin >> a >> p;
    cout << (a * 3 + p) / 2 << endl;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < (n); i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define REP(i, vec) for(auto i = vec.begin(); i != vec.end(); ++i)

const int mod = 1000000007;
const int inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

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; }
template<class T> inline T GCD(T a, T b) { return b ? GCD(b, a % b) : a; }
template<class T> inline T LCM(T a, T b) { return (a + (b - 1)) / b; }

int round_int(int a, int b) { return (a + (b - 1)) / b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int main() {
	ll x;
	cin >> x;

	ll ans = 1000 * (x / 500);
	x %= 500;
	ans += 5 * (x / 5);
	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();
    int M = sc.nextInt();
    int[] A = new int[M];
    int sum = 0;
    
    for(int i = 0; i < M; i++){
      A[i] = sc.nextInt();
      sum = sum + A[i];
    }
    if(N >= sum)
      System.out.println(N-sum);
    else
      System.out.println(-1);
  }
}

Measured memory_bytes: 46188
#include<iostream>
#include<stdio.h>
#include<cmath>
using namespace std;


int main()
{
    int n_;
    cin >> n_;
    int sum = 0, n = n_;
    while (n > 0)
    {
        sum += n % 10;
        n /= 10;
    }
    if (n_ % sum == 0) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    long inputN, inputA, inputB;
    long lastRowABalls, aBallsInRow;
    
    scanf("%ld %ld %ld", &inputN, &inputA, &inputB);
    
    // Count balls in the last row
    lastRowABalls = (inputN % (inputA + inputB));
    
    // if there are some B balls in the last row, makes it to only count A balls
    if(lastRowABalls > inputA)
    {
        lastRowABalls = inputA;
    }
    
    // Count all A balls until the last row
    aBallsInRow = (inputN / (inputA + inputB)) * inputA;
    
    aBallsInRow += lastRowABalls;
    
    printf("%ld \n", aBallsInRow);
    
    return 0;
}


Measured memory_bytes: 128
import collections

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

N = int(input())
if N < 105:
    print(0)
    exit(0)
else:
    cnt = 1
    for i in range(107, N+1, 2):
        x = 1
        c = collections.Counter(prime_factorize(i))
        li = c.values()
        for j in li:
            j += 1
            x *= j
        if x == 8:
            cnt += 1
    print(cnt)

Measured memory_bytes: 38384
from itertools import product

N, M, X = map(int, input().split())

a = []
c = []

for i in range(N):
    lst = list(map(int, input().split()))
    a.append(lst[1:])
    c.append(lst[0])

ans = []
for b in product([0, 1], repeat=N):
    total = 0
    lrn = [0] * M
    for k, i in enumerate(b):
        total += i * c[k]
        for j in range(M):
            lrn[j] += a[k][j]*i

    if min(lrn) >= X:ans.append(total)
print(-1 if ans==[] else min(ans))

Measured memory_bytes: 9260
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

vector<int> MostFrequent(const map<int, int>& m) {
  int result = 0;
  for (auto it : m) result = max(result, it.second);
  vector<int> a;
  for (auto it : m) if (it.second == result) a.push_back(it.first);
  return a;
}

int SecondFrequent(const map<int, int>& m) {
  int result = 0;
  for (auto it : m) result = max(result, it.second);
  int result2 = 0;
  for (auto it : m) {
    if (it.second == result) continue;
    result2 = max(result2, it.second);
  }
  return result2;
}

int main()
{
  int n;
  cin >> n;
  map<int, int> m[2];
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    m[i % 2][a]++;
  }
  vector<int> even = MostFrequent(m[0]);
  vector<int> odd = MostFrequent(m[1]);
  if (even.size() > 1 || odd.size() > 1 || even[0] != odd[0]) {
    cout << n - m[0][even[0]] - m[1][odd[0]] << endl;
    return 0;
  }
  cout << n - m[0][even[0]] - max(SecondFrequent(m[0]), SecondFrequent(m[1])) << endl;
  return 0;
}


Measured memory_bytes: 5504
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;

  map<ll, ll> em, om;
  rep(i, n) {
    ll a;
    cin >> a;
    if (i & 1)
      om[a]++;
    else
      em[a]++;
  }
  vP ev, ov;
  ev.push_back({0, INF});
  ov.push_back({0, INF});
  for (P p : em) ev.push_back({p.second, p.first});
  for (P p : om) ov.push_back({p.second, p.first});
  rSort(ev), rSort(ov);

  ll ans;
  if (ev[0].second != ov[0].second) {
    ans = (n + 1) / 2 - ev[0].first;
    ans += n / 2 - ov[0].first;
  } else {
    ans = INF;
    ll tmp;
    tmp = (n + 1) / 2 - ev[0].first;
    tmp += n / 2 - ov[1].first;
    chmin(ans, tmp);
    tmp = (n + 1) / 2 - ev[1].first;
    tmp += n / 2 - ov[0].first;
    chmin(ans, tmp);
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

void p(const vector<int> &v)
{
    for (size_t i = 0; i < v.size() - 1; ++i) {
        printf("%d ", v[i]);
    }
    printf("%d\n", v[v.size() - 1]);
}

int main()
{
    int N;
    scanf("%d", &N);
    vector<int> v;
    int t;
    for (int i = 0; i < N; ++i) {
        scanf("%d", &t);
        v.push_back(t);
    }
    p(v);
    for (size_t i = 1; i < v.size(); ++i) {
        int e = v[i];
        int j = i - 1;
        while (j >= 0 && v[j] > e) {
            v[j + 1] = v[j];
            --j;
        }
        v[j + 1] = e;
        p(v);
    }
}

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

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


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

  int h, w, n;
  cin >> h >> w >> n;
  int sr, sc;
  cin >> sr >> sc;
  string s, t;
  cin >> s >> t;

  int ny = sr;
  int nx = sc;

  for (int i = 0; i < n; i++) {
    if(s[i] == 'R'){
      if(nx == w){
        // cout << ny << endl;
        // cout << nx << endl;
        cout << "NO" << endl;
        return 0;
      }else{
        nx++;
      }
    }
    if(t[i] == 'L'){
      if(nx != 1){
        nx--;
      }
    }

    if(s[i] == 'D'){
      if(ny == h){
        cout << "NO" << endl;
        return 0;
      }else{
        ny++;
      }
    }
    if(t[i] == 'U'){
      if(ny != 1){
        ny--;
      }
    }
  }

  ny = sr;
  nx = sc;

  for (int i = 0; i < n; i++) {
    if(s[i] == 'L'){
      if(nx == 1){
        cout << "NO" << endl;
        return 0;
      }else{
        nx--;
      }
    }
    if(t[i] == 'R'){
      if(nx != w){
        nx++;
      }
    }

    if(s[i] == 'U'){
      if(ny == 1){
        cout << "NO" << endl;
        return 0;
      }else{
        ny--;
      }
    }
    if(t[i] == 'D'){
      if(ny != h){
        ny++;
      }
    }
  }

  cout << "YES" << endl;

}


Measured memory_bytes: 920
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,k = inpl()
a = inpl()
if k in a:
    print('POSSIBLE')
    quit()
if k > max(a):
    print('IMPOSSIBLE')
    quit()
if 1 in a:
    print('POSSIBLE')
    quit()
a.sort()
tmp = a[1] - a[0]
for i in range(1,n-1):
    tmp = fractions.gcd(a[i+1]-a[i], tmp)
    if tmp == 1:
        break
tmp = fractions.gcd(tmp,a[0])
if tmp == 1 or k%tmp == 0: 
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 84716
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            bool[] isLeapYear = new bool[3000];

            for (int i = 0; i < 3000; i += 4) isLeapYear[i] = true;
            for (int i = 0; i < 3000; i += 100) isLeapYear[i] = false;
            for (int i = 0; i < 3000; i += 400) isLeapYear[i] = true;

            bool flg = true;

            while (true)
            {
                StringBuilder sb = new StringBuilder();

                string[] input = Console.ReadLine().Split(' ');
                int a = int.Parse(input[0]);
                int b = int.Parse(input[1]);

                if (a == 0 && b == 0) break;

                if (!flg) Console.WriteLine();
                else flg = false;

                a = a % 4 == 0 ? a : (a / 4 + 1) * 4;

                int cnt = 0;

                for (int i = a; i <= b; i += 4)
                {
                    if (isLeapYear[i])
                    {
                        sb.AppendLine(i.ToString());
                        cnt++;
                    }
                }

                if (cnt == 0) Console.WriteLine("NA");
                else Console.Write(sb);
            }
        }
    }
}

Measured memory_bytes: 9252
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.*;

public class Main {

	public static void main(String[] args)throws Exception  {
		// TODO ?????????????????????????????????????????????

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String[] ln = line.split(" ");
        BigDecimal a = new BigDecimal(new Integer(ln[0]));
        BigDecimal b = new BigDecimal(new Integer(ln[1]));
        System.out.println(a.divideToIntegralValue(b).toPlainString() + " " + a.remainder(b).toPlainString() + " " + a.divide(b,10,RoundingMode.HALF_UP).toPlainString());

	}

}

Measured memory_bytes: 24636
// C++ 14
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(ll __x = __start; __x < __end; __x++)


int main() {
  ll n, k; cin >> n >> k;
  vector<ll> A(n);
  loop(i,0,n) cin >> A[i];
  ll ans = 0;
  loop(i,0,n-1) {
    if (A[i] + A[i+1] <= k) continue;
    {
      ll d = min(A[i+1], A[i]+A[i+1]-k);
      A[i+1] -= d;
      ans += d;
    }
    if (A[i] + A[i+1] <= k) continue;
    {
      ll d = min(A[i], A[i]+A[i+1]-k);
      A[i] -= d;
      ans += d;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3984
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int a[5],k;
	rep(i,5) scan(a[i]);
	scan(k);
	if(a[4]-a[0]<=k) prin("Yay!");
	else prin(":(");
	return 0;
}


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


    vector<int> a;
    long long int anum[200010];
    long long int a_0[200010];
    long long int a_1[200010];
    long long int ans=0;
    int n=0;

int main(void){
    cin >> n;
    for(long long int i=0; i<n;i++){
        long long int tmp=0;
        cin >> tmp;
        a.push_back(tmp);
        anum[tmp]++;
    }

//    cout << endl;
 //   for(int i=0; i<n; i++){
 //       cout << anum[i] << " " << endl;
 //   }
//    cout << endl;

    for(long long int i=0; i<=200005; i++){
        if( (anum[i] == 0 ) ||
            (anum[i] == 1 ) ){
            a_0[i] = 0;
            a_1[i] = 0;
        }
        a_0[i] = (anum[i] * (anum[i] -1)) /2;
        if( (anum[i] == 0 ) ||
            (anum[i] == 1 ) ||
            (anum[i] == 2 )  ) {
            a_1[i] = 0;
        }
        a_1[i] = ((anum[i]-1) * (anum[i] -2)) /2;
    }

    for(long long int i=0; i<=200005; i++){
        ans += a_0[i];
    }
    for(long long int i=1; i<=n; i++){
        long long int tmpans = ans;
        tmpans -= a_0[a[i-1]];
        tmpans += a_1[a[i-1]];
        cout << tmpans << endl;
    }

    return 0;
}

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

#define ll long long
#define ld long double
#define eb emplace_back
#define fi first
#define se second

using namespace std;

const int nm = (1 << 18) + 2;
const int mm = 100002;
const int nm2 = (1 << 9) + 2;

int n, w[nm], v[nm];
int f[nm2][mm];
int m;

int solve(int u, int l) {
	if (u < nm2) {
		return f[u][l];
	}
	int res = solve(u >> 1, l);
	if (w[u] <= l) {
		res = max(res, solve(u >> 1, l - w[u]) + v[u]);
	}
	return res;
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
#endif
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d%d", &v[i], &w[i]);
	}
	for (int i = 1; i < nm2 && i <= n; ++i) {
		for (int j = 1; j < mm; ++j) {
			f[i][j] = f[i >> 1][j];
			if (w[i] <= j) {
				f[i][j] = max(f[i][j], f[i >> 1][j - w[i]] + v[i]);
			}
		}
	}
	scanf("%d", &m);
	while (m--) {
		int u, l;
		scanf("%d%d", &u, &l);
		printf("%d\n", solve(u, l));
	}
#ifdef LOCAL
	cout << setprecision(6) << fixed << (double) clock() / CLOCKS_PER_SEC << "\n";
#endif
}


Measured memory_bytes: 206164
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
struct edge { int to; int cost; };
int main() {
	int n;
	while (cin >> n, n) {
		vector<edge>G[801]; int p[801] = {}; int d[801] = {};
		for (int i = 2; i <= n; i++) {
			cin >> p[i];
		}
		int dissum = 0;
		for (int i = 2; i <= n; i++) {
			cin >> d[i]; dissum += d[i];
		}
		for (int i = 2; i <= n; i++) {
			G[i].push_back({ p[i],d[i] });
			G[p[i]].push_back({ i, d[i] });
		}
		int con[801] = {};
		for (int i = 1; i <= n; i++) {
			con[i] = G[i].size();
		}
		int csum = 0;
		for (int i = 1; i <= n; i++) {
			if (con[i] == 1) {
				csum += 2 * G[i][0].cost;
				int x = G[i][0].to;
				int len = G[x].size();
				for (int j = 0; j < len; j++) {
					if (G[x][j].to == i) {
						G[x].erase(G[x].begin() + j); break;
					}
				}
				G[i].erase(G[i].begin());
			}
		}
		int chk;
		for (int i = 1; i <= n; i++) {
			if (con[i] > 1)chk = i;
		}
		int ma, hasi1;
		ma = 0; hasi1 = chk;
		vector<int>v; v.push_back(chk);
		int D[801];
		fill(D, D + 801, (int)MOD);
		D[chk] = 0;
		while (!v.empty()) {
			int now = v[0]; v.erase(v.begin());
			int len = G[now].size();
			for (int i = 0; i < len; i++) {
				if (D[now] + G[now][i].cost < D[G[now][i].to]) {
					D[G[now][i].to] = D[now] + G[now][i].cost;
					v.push_back(G[now][i].to);
					if (ma < D[G[now][i].to]) {
						ma = D[G[now][i].to];
						hasi1 = G[now][i].to;
					}
				}
			}
		}
		ma = 0;
		v.clear(); v.push_back(hasi1);
		for (int i = 0; i < 801; i++) {
			D[i] = (int)MOD;
		}
		D[hasi1] = 0;
		while (!v.empty()) {
			int now = v[0]; v.erase(v.begin());
			int len = G[now].size();
			for (int i = 0; i < len; i++) {
				if (D[now] + G[now][i].cost < D[G[now][i].to]) {
					v.push_back(G[now][i].to);
					D[G[now][i].to] = D[now] + G[now][i].cost;
					if (ma < D[G[now][i].to]) {
						ma = D[G[now][i].to];
					}
				}
			}
		}
		cout << dissum * 3 - csum - ma << endl;
	}
	return 0;
}


Measured memory_bytes: 3204
#include<iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>

using namespace std;

int main()
{
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;

    if (a == 0) {
        cout << 1;
    }
    if (b == 0) {
        cout << 2;
    }if (c == 0) {
        cout << 3;
    }if (d == 0) {
        cout << 4;
    }if (e == 0) {
        cout << 5;
    }

    return 0;
}

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

#define mod 998244353
int n,x[205],y[205];

int qpow(int x,int y){
	int ans=1;
	while(y){
		if(y&1)ans=1LL*ans*x%mod;
		y>>=1,x=1LL*x*x%mod;
	}
	return ans;
}

bool check(int i,int j,int k){
	int a=1LL*(y[j]-y[i])*(x[k]-x[j])%mod;
	int b=1LL*(y[k]-y[j])*(x[j]-x[i])%mod;
	return a==b;
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d",x+i,y+i);
	int ans=((qpow(2,n)-(1LL*n*(n-1)>>1)%mod-n-1)%mod+mod)%mod;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			int sum=0;
			for(int k=j+1;k<=n;k++){
				if(k==i||k==j)continue;
				if(check(i,j,k))sum++;
			}
			ans=(ans-qpow(2,sum)+1+mod)%mod;
		}
	}
	printf("%d",ans);
	
} 

Measured memory_bytes: 256
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	n = I()
	t_list = LI()
	m = I()
	px_list = LIR(m)

	original_time = sum(t_list)
	for p, x in px_list:
		print(original_time - t_list[p-1] + x, end='\r\n')


if __name__ == '__main__':
    main()

Measured memory_bytes: 27092
#include<bits/stdc++.h>
using namespace std;
typedef		 long long int    ll;
typedef		vector<ll>      vll;
#define     fi              first
#define     print(v)        for(ll i:v) cout<<i<<ss
#define     se              second
#define		pb              push_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		ss              ' '
#define     pii             pair<ll,ll>
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
const double eps = 1e-8;




int main()
{
//    ios::sync_with_stdio(0);
//    cin.tie(0);
    ll n,x,y;
    cin>>n>>x>>y;
    cout<<((n+(x-1))/x)*y<<nn;



}


/* Final check before submit :

1. array size or integer overflow,like uninitialised 0 index.

2. Think twice,code once.check all possible counter test case.

3. Be careful about corner case! n=1?k=1? something about 0?

4. avoid stupid mistake!complexity(t/m)?precision error?submit same code twice?

5. if got WA than remember that you are missing something common.
   *** Be confident!!! who knows? may be your one step back to AC ***
4. minus mod ans=(ans-k+mod)%mod;

*/






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

int main(){
    int n, cnt = 0, maxim = 0;
    cin >> n;
    ll h[n];
    rep(i,n) cin >> h[i];
    ll prev = h[0];

    for(int i = 1; i < n; i++){
        if(h[i] <= prev) cnt++;
        else{
            maxim = max(maxim, cnt);
            cnt = 0;
        }
        prev = h[i];
    }
    maxim = max(maxim, cnt);

    cout << maxim << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
  int N;
  cin >> N;
  for(int i=1; i<10; i++){
    for(int j=1; j<10; j++){
      if(i*j == N){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
   return 0;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "2" ].solve == 2 );
	assert( [ "1" ].solve == 0 );
	assert( [ "869121" ].solve == 2511445 );
}



import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	
	const M = 10L ^^ 9 + 7;
	auto ans = ModWorld!M( 0L );
	if( 2 <= n )
	{
		ans = ModWorld!M( 10L ) ^^ n;			// 全パターン
		ans -= ModWorld!M( 9L ) ^^ n * 2;		// 0or9が一つも含まれないパターン
		ans += ModWorld!M( 8L ) ^^ n;			// 0and9が一つも含まれないパターン
	}
	return ans;
}

// モジュラ整数型（n mod M）
struct ModWorld( long M )
{
	long n;
	
	this( long n ){ this.n = n % M; }
	void opUnary( string OP )() if( OP == "++" ){ this.n = ( this.n + 1 ) % M; }
	void opUnary( string OP )() if( OP == "--" ){ this.n = ( this.n + M - 1 ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "+"  ){ this.n = ( this.n + r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "-"  ){ this.n = ( this.n + M - r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "*"  ){ this.n = ( this.n * r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "/"  ){ this *= r ^^ ModWorld( M - 2 ); }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "^^" )
	{
		auto a = this.n;
		this.n = 1L;
		for( auto i = r.n; 0 < i; i >>= 1 )
		{
			if( i & 1 ) this.n = ( this.n * a ) % M;
			a = ( a * a ) % M;
		}
	}
	auto opBinary( string OP )( ModWorld r ){ auto l = this; l.opOpAssign!OP( r ); return l; }
	auto opEquals( ModWorld r ){ return this.n == r.n; }
	
	void opAssign( long r ){ this.n = r % M; }
	void opOpAssign( string OP )( long r ){ this.opOpAssign!OP( ModWorld( r ) ); }
	auto opBinary( string OP )( long r ){ return this.opBinary!OP( ModWorld( r ) ); }
	auto opBinaryRight( string OP )( long l ){ return ModWorld( l ).opBinary!OP( this ); }
	auto opEquals( long r ){ return this.n == r; }
	
	auto toString(){ return this.n.to!string; }
}


Measured memory_bytes: 2884
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, K: int):
    def rec(n: int):
        if n >= K:
            return 0
        return rec(n*2)+1
    
    ans = 0
    for i in range(1, N+1):
        ans += 1/N * pow(1/2, rec(i))
    print(ans)
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define N 100001
int a[N], n, m;
int main() {
    scanf("%d%d", &n, &m);
    int add = 0;
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i < n; i++)
        if (a[i] + a[i + 1] >= m) add = i;
    if (add) {
        puts("Possible");
        for (int i = 1; i < add; i++) printf("%d\n", i);
        for (int i = n - 1; i > add; i--) printf("%d\n", i);
        printf("%d\n", add);
    } else
        puts("Impossible");
    return 0;
}

Measured memory_bytes: 1152
n,m,k = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
if sum(A)+sum(B)<=k:
    print(n+m)
    exit()

for i in range(1,n):
    A[i] += A[i-1]
for i in range(1,m):
    B[i] += B[i-1]

from bisect import bisect_right
ans = bisect_right(B,k)
for i in range(n):
    if A[i]>k:
        break
    ans = max(ans, i+1+bisect_right(B,k-A[i]))
print(ans)

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

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

using namespace std;


int main()
{
int A,B;
cin>>A>>B;
if(B%A==0){
    cout<<A+B<<endl;
    return 0;
}else{
    cout<<B-A<<endl;
    return 0;
}
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();

    sc.close();

    String s = String.valueOf(N);

    String[] S = s.split("");

    int a = 0;

    for (int i = 0; i < S.length; i++) {
      a += Integer.valueOf(S[i]);
    }

    if (N % a == 0) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
    
  }

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
 
int d;
vector<int> c(26);
vector<vector<int>> s(400, vector<int>(26));
 
int get_score(vector<int> t){
    vector<int> cnt(26, 0);
    int ans = 0;
    rep(i, d){
        int l = i + 1 - cnt[t[i]];
        ans -= (l * (l-1) / 2) * c[t[i]];
        ans += s[i][t[i]];
        cnt[t[i]] = i+1;
    }
    rep(i, 26){
        int l = d + 1- cnt[i];
        ans -= (l * (l-1) / 2)* c[i];
    }
    return ans;
}
 
int main() {
    cin >> d;
    rep(i, 26)cin >> c[i];
    rep(i, d)rep(j, 26)cin >> s[i][j];
    //-----code------//
    vector<int> t(d);
    rep(i, d){cin >> t[i]; t[i]--;}
    int m;
    cin >> m;
    rep(i, m){
        int D, q;
        cin >> D >> q;
        t[D-1] = q-1;
        cout << get_score(t) << endl;
    }
}


Measured memory_bytes: 3612
'''
7 0 1
6   2
5 4 3
'''
dx=[1,0,-1,0,1,-1,1,-1]
dy=[0,1,0,-1,1,1,-1,-1]

while True:
    h,w=map(int,input().split())
    if h==0:
        break
    field=[list(input()) for i in range(h)]
    allword=set()
    answord=set()
    for i in range(h):
        for j in range(w):
            s=field[i][j]
            if s in allword:
                answord.add((len(s),s))
            else:
                allword.add(s)
            for k in range(8):
                used=[[False for _ in range(w)]for _ in range(h)]
                s=field[i][j]
                used[i][j]=True
                while True:
                    i=(i+dy[k])%h
                    j=(j+dx[k])%w
                    if used[i][j]:
                        break
                    s+=field[i][j]
                    if s in allword:
                        answord.add((len(s),s))
                    else:
                        allword.add(s)
    print(sorted(answord,key=lambda x:(-x[0],x[1]))[0][1] if answord and sorted(answord,key=lambda x:(-x[0],x[1]))[0][0]>1 else 0 )








Measured memory_bytes: 39892
N = int(input())
votedict = {}
Max = -1
for _ in range(N):
    S = input()
    if S in votedict:
        votedict[S] += 1
        Max = max(votedict[S],Max)
    else:
        votedict[S] = 1

if Max == -1:
    Max = 1

maxvote = []

for k,v in votedict.items():
    if v == Max:
        maxvote.append(k)

maxvote.sort()

for i in maxvote:
    print(i)

Measured memory_bytes: 35272