akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

// bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
//     return arg1.first > arg2.first;
// }

int main(void) {
    vector<int> dish(5);
    vector<int> dish10(5);
    vector<int> mod(5);

    for(int i=0;i<5;i++) {
        cin >> dish.at(i);
        mod.at(i) = dish.at(i) % 10;
        dish10.at(i) = dish.at(i) - mod.at(i);
        if(mod.at(i)!=0) dish10.at(i) += 10;
    }

    for(int i=0;i<5;i++) {
        if(mod.at(i)==0) mod.at(i) = 99;
    }
    sort(mod.begin(), mod.end());

    int ans=0;
    for(int i=0;i<4;i++) {
        if(mod.at(0)==dish.at(i)%10) {
            for(int j=0;j<5;j++) {
                if(j==i) continue;
                ans += dish10.at(j);
            }
            ans += dish.at(i);
            cout << ans << endl;
            return 0;
        }
    }
    ans = dish10.at(0)+dish10.at(1)+dish10.at(2)+dish10.at(3);
    ans += dish.at(4);

    cout << ans << endl;

    return 0;
}


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

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	int w,a,b,t;
	cin>>w>>a>>b;
	t=min(a,b)+w;
	if (t>=max(a,b)){
		cout<<"0";
	}
	else {
		cout<<max(a,b)-t;
	}
	return 0;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
a = list(map(int,input().split()))

count = Counter(a)

cnt = 0
for i in count.items():
    if i[0] > i[1]:
        cnt += i[1]
    elif i[0] <= i[1]:
        cnt += i[1] - i[0]

print(cnt)

Measured memory_bytes: 22320
#include<bits/stdc++.h>
using namespace std;
map<pair<int,int>,int> g;
long long c[10];
long long  h,w,n;
int main()
{
    cin>>h>>w>>n;
    c[0]=(h-2)*(w-2);
    for(int i=1;i<=n;i++)
    {
        int x,y;cin>>x>>y;
        for(int j=x;j<=x+2;j++)
            for(int k=y;k<=y+2;k++)
                if(j>=3&&j<=h&&k>=3&&k<=w)
        {
            c[g[make_pair(j,k)]]--;
            g[make_pair(j,k)]++;
            c[g[make_pair(j,k)]]++;
        }
    }
    for(int i=0;i<=9;i++) cout<<c[i]<<endl;
    return 0;
}

Measured memory_bytes: 56448
n,m = map(int, input().split())
edges = []
for i in range(m):
    a, b, c = map(int, input().split())
    edges.append([a-1, b-1, -c])


inf=float("inf")
dist=[inf for i in range(n)]
dist[0]=0
flag = False
for i in range(2*n):
    for edge in edges:
        if edge[0] != inf and dist[edge[1]] > dist[edge[0]] + edge[2]:
            dist[edge[1]] = dist[edge[0]] + edge[2]
            if i >= n-1 and edge[1] == n-1:
                flag = True
                break
if flag:
    print("inf")
else:
    print(-dist[n-1])

Measured memory_bytes: 3316
#include <iostream>
using namespace std;
int main(void){
    // Here your code !
    int a,b,c,res = 0;
    cin >> a >> b >> c;
    
    for(int i = 0; i < a; i++){
        int d;
        cin >> d;
        if(b > d || d >= c){
            res++;
        }
    }
    
    
    cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    int cnt = 0, ans = 0;
    for (int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        if(a == b) cnt++;
        else cnt = 0;
        ans = max(ans, cnt);
    }
    if(ans >= 3) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int main () {
	int a, b;
	cin >> a >> b;
	if (a > b) {
		if (b == 1) {
			cout << "Bob";
		} else {
			cout << "Alice";
		}
	} else if (a < b) {
		if (a == 1) {
			cout << "Alice";
		} else {
			cout << "Bob";
		}
	} else {
		cout << "Draw";
	}
	return 0;
}

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

int main() {

  int N;
  cin >> N;

  string S;
  cin >> S;

  // Wの数の累積和
  vector<int> W(N+1);

  for (int i = 0; i < N; i++) {
    if (S[i] == 'W') {
      if (i == 0) {
        W[i] = 1;
      } else {
        W[i] = 1 + W[i - 1];
      }
    } else {
      if (i == 0) {
        W[i] = 0;
      } else {
        W[i] = W[i - 1];
      }
    }
  }

  int answer = N;
  
  for (int i = 0; i < N; i++) {
    // iより東にいて、東を向いている人は西を向く必要がある
    int count_ = 0;
    if (i != 0) {
      count_ += W[i-1];
    }
    // iより西にいて、西を向いている人は東を向く必要がある
    if (i != N - 1){
      count_ += (N - i - 1) - (W[N-1] - W[i]);
    }
    answer = min(answer, count_);
  }

  cout << answer << endl;

  return 0;

}

Measured memory_bytes: 1796
#include <bits/stdc++.h>
typedef long long ll;
#define fr first
#define sc second
#define int ll

using namespace std;
const int MN = 2e5+7;
const int MOD = 1e9+7;

int n, h[MN], a[MN], bit[MN];

void upd(int idx, int val){
    for(; idx < n; idx = idx | (idx+1)){
        bit[idx] = max(bit[idx], val);
    }
}

int ask(int r){
    int ret = -1;
    for(; r >= 0; r = (r & (r + 1)) - 1)
        ret = max(ret, bit[r]);
    return ret;
}

signed main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        x--;
        h[x] = i;
    }
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        int s = ask(h[i]) + a[h[i]];
        //cout << i << " : " << s << endl;
        upd(h[i], s);
    }
    cout << ask(n-1);
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
const int MAX = 1500 * 1000;

void countLength(vector<int>& cnt, vector<int>& v){
    cnt.assign(MAX+1, 0);
    rep(i, (int)v.size()){
        int L = 0;
        for(int j=i; j<(int)v.size(); ++j){
            L += v[j];
            cnt[L]++;
        }
    }
}

int solve(vector<int>& h, vector<int>& w){
    vector<int> cntH, cntW;
    countLength(cntH, h); countLength(cntW, w);
    int res = 0;
    rep(i, (int)cntH.size())res += cntH[i] * cntW[i];
    return res;
}

int main(){
    int N, M;
    while(cin >> N >> M, N|M){
        vector<int> h(N), w(M);
        rep(i, N)cin >> h[i];
        rep(i, M)cin >> w[i];
        cout << solve(h, w) << '\n';
    }
    return 0;
}

Measured memory_bytes: 12800
<?php
list($n, $k, $q) = array_map("intval", explode(" ", trim(fgets(STDIN))));
for($i = 0; $i < $n; $i++){
  $map[$i] = 0;
}
for($i = 0; $i < $q; $i++){
  $map[intval(fgets(STDIN))-1]++;
}
for($i = 0; $i < $n; $i++){
  echo $k - $q + $map[$i] > 0 ? "Yes": "No" ,"\n";
}


Measured memory_bytes: 10744
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long,long long> ii; 	
typedef complex<long double> com;

const ll mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    bool first = true;
    while (true){
        if (first) c -= b;
        else a -= d;
        if (c <= 0){
            cout << "Yes" << endl;
            return 0;
        }
        if (a <= 0){
            cout << "No" << endl;
            return 0;
        }
        first = !first;
    }
}

Measured memory_bytes: 3640
n = gets.chomp.to_i
arr = gets.chomp.split(' ').map(&:to_i)
i = 0
s1 = []
s2 = []
while i < n
  if arr.sum/2 <= s1.sum
    s2 << arr[i]
  else
    s1 << arr[i]
  end
  i += 1
end
if (s1.sum-s2.sum).abs > ((s1.sum-s1[-1])-(s2.sum+s1[-1])).abs
  p ((s1.sum-s1[-1])-(s2.sum+s1[-1])).abs
else
  p (s1.sum-s2.sum).abs
end

Measured memory_bytes: 14244
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {


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

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];

        for(int i=0; i<n; i++){
            array[i] = sc.nextInt();
        }

        double max = 0;
        double min = Math.pow(10, 9);

        for(int i: array){
            if(i > max){
                max = i;
            }

            if(i < min){
                min = i;
            }
        }

        System.out.println((int)max - (int)min);
    }

//    void dfs(int from, List<Integer> list, boolean[] reachedNodes){
////        System.out.println(eachCount);
//        int eachCount = 0;
//        for(boolean b: reachedNodes){
//            if(b){
//                eachCount++;
//            }
//        }
//        if(eachCount == N){
//            count++;
//            return;
//        }
////
//        for(int i: list){
//            if(reachedNodes[i]){
//                continue;
//            }
//            reachedNodes[i] = true;
////            System.out.println(String.format("%s %s", from+1, i+1));
//            dfs(i, map.get(i), reachedNodes);
//            reachedNodes[i] = false;
//        }
//    }

//    void dfs(int from, List<Integer> toList, boolean[] eachReachedNode, boolean[][] threwEdge, boolean countedFlug) {
//
//        reachedNode[from] = true;
//        eachReachedNode[from] = true;
//
//        for (int i : toList) {
//            if ((threwEdge[from][i] || threwEdge[i][from])) {
//                continue;
//            } else if(eachReachedNode[i] && !countedFlug){
////                System.out.println(String.format("%s %s", from , i));
//                count++;
//                countedFlug = true;
//                threwEdge[from][i] = true;
//                threwEdge[i][from] = true;
////                return;
//            } else {
//                if(map.get(i) == null){
//                    return;
//                } else {
//                    threwEdge[from][i] = true;
//                    threwEdge[i][from] = true;
//                    dfs(i, map.get(i), eachReachedNode, threwEdge, countedFlug);
//                }
//            }
//        }
//    }
//    void dfs(int from, int to) {
//
//        if (from > 100 || to > 100 || reachedArray[from][to]) {
//            return;
//        }
//
//        reachedArray[from][to] = true;
//
//        if (hasArray[from][to]) {
//            count++;
//        }
//        dfs(to, to + 1);
//        dfs(to + 1, to);
//    }
}


//class Gcd {
//    public static int gcd(int a, int b){
//        if (b == 0) return a;
//        return gcd(b, a % b);
//    }
//
//    public static int lcm(int a, int b){
//        return a * b / gcd(a, b);
//    }
//}

Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,w;cin>>n>>w;
    long long int wt[n],vl[n];
    for(int i=0;i<n;i++){
        cin>>wt[i]>>vl[i];
    }
    long long ans[w+1]={0};
    for(long long int i=0;i<n;i++){
        for(long long int j=w;j>=wt[i];j--){
            ans[j]=max(ans[j],vl[i]+ans[j-wt[i]]);
        }
    }
    cout<<ans[w];
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int const none = 0, black = 1, white = 2;

    int const N = 13;
    int const dir_x[N] = { 1, 0, 1,-1, 1, 0,-1, 1, 0,-1, 1, 0,-1};
    int const dir_y[N] = { 0, 1, 1, 1, 1, 1, 1, 0, 0, 0,-1,-1,-1};
    int const dir_z[N] = { 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1};

    for(;;) {
        int n, m, p;

        cin >> n >> m >> p;
        if ( n == 0 && m == 0 && p == 0 ) {
            break;
        }

        int b[7][7][7] = {};
        int turn = black, winner = none, last = 0;

        for( int times=0; times<p; ++times ) {
            int in_x, in_y;
            cin >> in_x >> in_y;
            if ( winner != none )
                continue;

            //
            in_x = in_x - 1;
            in_y = in_y - 1;

            //
            for( int i=0; i<n; ++i ) {
                if ( b[in_x][in_y][i] == none ) {
                    b[in_x][in_y][i] = turn;
                    break;
                }
            }

            //
            for( int iz=0; iz<n; ++iz ) {
                for( int iy=0; iy<n; ++iy ) {
                    for( int ix=0; ix<n; ++ix ) {

                        
                        for( int i=0; i<N; ++i ) {
                            int x = ix, y = iy, z = iz;

                            int num = 0, ret = b[x][y][z];
                            for( int j=0; j<n; ++j ) {
                                if ( ret == b[x][y][z] && b[x][y][z] != none ) {
                                    ++num;
                                    if ( num == m ) {
                                        winner = ret; 
                                        last = times + 1;
                                        goto finish;
                                    }

                                } else {
                                    num = 0;
                                    ret = b[x][y][z];
                                }
                            
                                x += dir_x[i]; y += dir_y[i]; z += dir_z[i];
                                if ( ( x < 0 || x >= n ) || ( y < 0 || y >= n ) || ( z < 0 || z >= n ) ) {
                                    break;
                                } 
                            }
                        }


                    }
                }
            }

            turn = ( turn == black ) ? white : black;

        finish:
            ;
        }


        if ( winner == black ) {
            cout << "Black " << last << endl;

        } else if ( winner == white ) {
            cout << "White " << last << endl;

        } else {
            cout << "Draw" << endl;
        }
    }
}

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

struct data {
  long long num, lef, righ;
};

bool operator<(const data &l, const data &r) {
  return l.num < r.num;
}

long long n;
vector<data> v;
vector<long long> pre, in, pos;
set<int> st;

void solve(int p);

int main() {
  cin >> n;
  v.resize(n);
  for(int i = 0; i < n; ++i)
    cin >> v[i].num >> v[i].lef >> v[i].righ;
  sort(v.begin(), v.end());

  for(int i = 0; i < n; ++i) {
    st.insert(v[i].lef);
    st.insert(v[i].righ);
  }
  for(int i = 0; i < n; ++i)
    if(st.find(i) == st.end()) solve(i);

  cout << "Preorder" << endl;
  for(int i = 0; i < n; ++i) {
    cout << " ";
    cout << pre[i];
  }
  cout << endl;
  cout << "Inorder" << endl;
  for(int i = 0; i < n; ++i) {
    cout << " ";
    cout << in[i];
  }
  cout << endl;
  cout << "Postorder" << endl;
  for(int i = 0; i < n; ++i) {
    cout << " ";
    cout << pos[i];
  }
  cout << endl;

  return 0;
}

void solve(int p) {
  pre.push_back(p);
  if(v[p].lef != -1) solve(v[p].lef);
  in.push_back(p);
  if(v[p].righ != -1) solve(v[p].righ);
  pos.push_back(p);
}


Measured memory_bytes: 3140
'use strict';
function Main(inputs) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  const input = inputs.split("\n");
  const n = Number(input[0]);
  const ab = input.slice(1, n + 1).map((o) => ({
    a: Number(o.split(' ')[0]),
    b: Number(o.split(' ')[1]),
  }));
  let time = 0;
  const ok = ab.sort((o1, o2) => o1.b - o2.b).every((o) => {
    time += o.a;
    return time <= o.b;
  });
  console.log(ok ? 'Yes' : 'No');
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 65820
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Calc c = new Calc();
		c.abc118C();
	}
}

class Calc{
	void abc118A() {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(b%a == 0) {
			System.out.println(a+b);
		}else {
			System.out.println(b-a);
		}
	}

	void abc118B() {
		Scanner sc = new Scanner(System.in);
		int like=0, cnt=0;
		boolean check = false;
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] k = new int[n];
		int[][] food = new int[n][30];
		for(int i=0 ; i<n ; i++) {
			k[i] = sc.nextInt();
			for(int j=0 ; j<k[i] ; j++) {
				food[i][j] = sc.nextInt();
			}
		}
		for(int i=1 ; i<=m ; i++) {
			//縦列
			for(int j=0 ; j<n ; j++) {
				//横一列
				for(int p=0 ; p<k[j] ; p++) {
					if( i == food[j][p] ) {
						like ++;
					}
				}
			}
			if(like == n) {
				cnt++;
			}
			like = 0;
		}
		System.out.println(cnt);
	}

	void abc118C() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a[] = new int[n];
		for (int i=0 ; i<n ; i++) {
			a[i] = sc.nextInt();
		}
		int temp = a[0];
		for(int i=1 ; i<n ; i++) {
			temp = euclid(temp, a[i]);
		}
		System.out.println(temp);
	}

	int euclid(int a, int b) {
		int temp;
		while( (temp = a%b) != 0 ) {
			a = b;
			b = temp;
		}
		return b;
	}
}

Measured memory_bytes: 51240
#include <cstdio>
#include <stdio.h>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <queue>
#include <string>
#include <map>
#include <iostream>
using namespace std;

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

    bool four = false;
    for(int i = 0; i < N; i++) {
        char c;
        cin >> c;
        if(c == 'Y') {
            four = true;
            break;
        }
    }

    if(four) {
        printf("Four\n");
    } else {
        printf("Three\n");
    }
    return 0;
}

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

#define _GLIBCXX_DEBUG

//vector<int> A(M), B(M);
//vector<vector<char>> answer(N, vector<char>(N, '-'));

int main() {
  int a, b, c;
  int ans;
  
  cin >> a >> b >> c;
  
  if(a == b && a != c) cout << "Yes" << endl;
  else if(a == c && a != b) cout << "Yes" << endl;
  else if(c == b && a != c) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3532
import sys
sys.setrecursionlimit(int(1e6))

N = int(input())
a = [0] * N
for i in range(N):
  a[i] = int(input())

#デバッグポイントを設置
#import pdb;pdb.set_trace()

a_pass = [False] * N
ans = -1
if (not 2 in a):
  ans = -1
else:
  ans = 0
  next_pos = 0
  crnt_pos = 0
  for i in range(N):
    if a_pass[next_pos]:
      ans = -1
      break
    elif next_pos == (2-1):
      break
    else:
      crnt_pos = next_pos
      next_pos = a[crnt_pos] - 1
      a_pass[crnt_pos] = True
      ans += 1
  else:
    ans = -1
  
print(ans)


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

namespace _051_DifferentialII
{
	class Program
	{
		static void Main ( string[] args )
		{
			int dataCount = int.Parse (Console.ReadLine ());

			for (int lp = 0; lp < dataCount; lp++)
			{
				string inputStr = Console.ReadLine ();

				string max = new string (inputStr.OrderByDescending (item => item).ToArray ());
				string min = new string (max.Reverse ().ToArray ());

				int maxValue = int.Parse (max);
				int minValue = int.Parse (min);

				Console.WriteLine (maxValue - minValue);
			}
		}
	}
}

Measured memory_bytes: 9984
#include <iostream>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int p[N];
  for (int i = 1; i <= N; i++) {
    cin >> p[i];
  }
  
  int k = 0;
  for (int j = 1; j <= N; j++) {
    if (j != p[j]) k += 1;
  }
  
  if (k <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
// *st.find_by_order(index), 0-based
// order_of_key(e)

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int X; cin>>X; cout<<8 - int((X-400)/200)<<"\n";
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,x;
  cin>>n>>x;
  int mini=1e8;
  for(int i=0;i<n;i++){
    int m;
    cin>>m;
    x-=m;
    mini=min(mini,m);
  }
  cout<<n+x/mini<<endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c=0;
  cin>>a>>b;
  if(a<b){c=b;while(c>0){cout<<a;c--;}}
  else{c=a;while(c>0){cout<<b;c--;}}
  cout<<endl;
}

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




    int main(){
        
        int n;
        std::cin >> n;
        std::vector<int> d(n);
        for (int i = 0; i < n; ++i)
        {
            std::cin >> d[i];
        }
        int ans = 0;
        for (int i = 0; i < n; ++i){
            for (int j = i + 1 ; j < n; ++j)
            {
                ans += d[i] * d[j];
            }
        }
        std::cout << ans << "\n";
        return 0;
    }


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Linq;
class Program
{
    static void Main()
    {
        int[] inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int w = inputs[0], h = inputs[1];
        while (!(w == 0 && h == 0))
        {
            int[][] c = new int[h][];
            for (int i = 0; i < h; i++)
                c[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

            UnionFind uf = new UnionFind(h * w);
            for (int i = 0; i < h * w; i++)
            {
                int x = i / w;
                int y = i % w;
                if (c[x][y] == 0)
                    continue;
                int[] dxs = { -1, 0, 1 };
                int[] dys = { -1, 0, 1 };
                foreach (var dx in dxs)
                {
                    foreach (var dy in dys)
                    {
                        try
                        {
                            if (c[x + dx][y + dy] == 1)
                                uf.Unite(i, w * (x + dx) + y + dy);
                        }
                        catch
                        {
                            continue;
                        }
                    }
                }
            }
            int count_sea = 0;
            foreach (var l in c)
                foreach (var i in l)
                    if (i == 0)
                        count_sea++;
            HashSet<int> hs = new HashSet<int>();
            for (int i = 0; i < h * w; i++)
                hs.Add(uf.Root(i));

            Console.WriteLine(hs.Count - count_sea);

            inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();
            w = inputs[0];
            h = inputs[1];
        }
    }
}
class UnionFind
{
    private int[] 親; //親[i] : iの親の番号

    public UnionFind(int N) //コンストラクタ、すべてが根として初期化
    {
        親 = new int[N];
        for (int i = 0; i < N; i++)
            親[i] = i;
    }

    public int Root(int x) //xの属する木の根を返す
    {
        if (親[x] == x) return x;
        return 親[x] = Root(親[x]);
    }

    public void Unite(int x, int y) //xとyの木を統合
    {
        int rx = Root(x);
        int ry = Root(y);
        if (rx == ry) return;
        親[rx] = ry;
    }

    public bool Same(int x, int y) //xとyが同じ木に属するかどうかを返す
    {
        return Root(x) == Root(y);
    }
}


Measured memory_bytes: 20916
def powmod(x, y, mod):
    res = pow(x, y) % mod
    return res

N = int(input())
mod = pow(10, 9) + 7
# (x + y) mod z = (x mod z + y mod z) mod z
ans = powmod(10, N, mod) - 2 * powmod(9, N, mod) + powmod(8, N, mod)
ans = ans % mod
print(ans)

Measured memory_bytes: 82748
#include <iostream>
#include <set>
#include <cassert>
using namespace std;

const int MAXN=310;
struct Node {
	Node *before=NULL,*next=NULL;
	int key;
	Node(int v) {
		key = v;
	}
}*tail[MAXN];

set<Node*> position[MAXN];
void removeNode(Node *p) {
	if (p->before)
		p->before->next = p->next;
	if (p->next)
		p->next->before = p->before;
	delete p;
}
void pushback(int no,int val) {
	Node *p = new Node(val);
	p->before = tail[no];
	if (tail[no])
		tail[no]->next = p;
	tail[no] = p;
	position[val].insert(p);
}
int n,m;
void debug() {
	for (int i=0; i<n; i++,cout<<endl) {
		cout<<"tail "<<i<<" :";
		for (Node *p=tail[i]; p; p=p->before) {
			if (p->before)
				assert(p->before->next==p);
			cout<<p->key<<" - ";
		}
	}
	cout<<endl;
}
int main()
{
	memset(tail,0,sizeof(tail));
	cin>>n>>m;
	for (int i=0;i<n;i++) {
		int tmp[MAXN];
		for (int j=0;j<m;j++)
			cin>>tmp[j];
		for (int j=m-1;j>=0;j--)
			pushback(i,tmp[j]);
	}
	int ans=MAXN;
	for (int t=0,cnt[MAXN],anst=MAXN; t<m&&tail[0]; t++,anst=MAXN) {
		memset(cnt,0,sizeof(cnt));
		for (int i=0;i<n;i++)
			cnt[tail[i]->key]++;
		int mmax=0;
		set<int> maxsport;
		for (int i=1;i<=m;i++) {
			if (cnt[i] > mmax) {
				maxsport.clear();
				mmax = cnt[i];
			}
			if (cnt[i] == mmax)
				maxsport.insert(i);
		}
		if (ans > mmax)
			ans = mmax;
		for (int i=0;i<n;i++) {
			for (Node *p=tail[i]; p&&(maxsport.find(p->key)!=maxsport.end()); p=p->before)
				tail[i] = p->before;
		}
		for (auto it=maxsport.begin(); it!= maxsport.end(); it++) {
			for (auto p=position[*it].begin(); p!=position[*it].end(); p++ )
				removeNode(*p);
		}
	}
	cout<<ans<<endl;
}

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

int main() {
  int R, G, B, N;
  cin >> R >> G >> B >> N;
  int ans = 0;
  for(int r = 0; r <= (N+R-1)/R; r++) {
    for (int g = 0; g <= (N+G-1)/G; g++) {
      int b = N - r * R - g * G;
      if (b < 0)continue;
      if (b % B == 0) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3576
from collections import Counter


def d(P):
    c = Counter()
    i = 2
    while (P > 1):
        if P % i == 0:
            c.update([i])
            P //= i
            i -= 1
        i += 1
        if i > P ** 0.5:
            c.update([P])
            break
    return c


def solve(N, P):
    c = d(P)
    ans = 1
    for k in [k for k, v in c.items() if v >= N]:
        ans *= k ** (c[k] // N)
    return ans

if __name__ == "__main__":
    N, X = tuple(map(int, input().split(" ")))
    print(solve(N, X))


Measured memory_bytes: 3436
import java.security.KeyStore.TrustedCertificateEntry
import java.util
import java.util.{ArrayList, Collections, Comparator, List => JList}

import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.util.{Failure, Success, Try}

object Main{
  val LINE_SEPARATOR = "\n"
  def main(args: Array[String]): Unit = {
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString(LINE_SEPARATOR);
      println(solve(input).trim());
    }
  }

  def init (nRows: Int, nCols: Int, default: Int) = Array.tabulate(nRows,nCols)( (x,y) =>  default)

  def sortIgnoreCase1(list: JList[String]): JList[String] = {
    val r = new ArrayList[String](list)
    Collections.sort(r, new Comparator[String] {
      override def compare(o1: String, o2: String): Int = o1.compareToIgnoreCase(o2)
    })
    r
  }

  def solve(input: String): String = {
    input.split("").last.toInt match {
      case 3 => "bon"
      case 0 | 1 | 6 | 8 => "pon"
      case 2 | 4 | 5 | 7 | 9 => "hon"
      case _ => "error"
    }
  }

  val tests=List(
    """16""".stripMargin -> """pon""".stripMargin,
    """2""".stripMargin -> """hon
                                     |""".stripMargin
  )

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}
      .zipWithIndex.map{
      case ((input,outputExpect),i)=>{
        val output=solve(input).trim();
        s"test${i+1}:"+(if(output==outputExpect){
          "Passed"
        }else{
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }}
      .mkString("\n");
  }
}

Measured memory_bytes: 55108
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i < (int)(n); i++)
typedef long long 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;}

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return y;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int count = 1;
  while(true){
    int x;
    cin >> x;
    if(x == 0) return 0;
    printf("Case %d: %d\n",count, x );
    count++;
  }
}






Measured memory_bytes: 3040
/*
Problem :
Algorithm :
Status :
*/
#include <bits/stdc++.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int INF = 0x3f3f3f3f;
const int MAXN = 1e6 + 5;
const int MOD = 1e9 + 7;

int X,Y;
int fac[MAXN],inv[MAXN];

int power(int x,int y){
	int res = 1;
	while(y){
		if(y & 1)
			res = 1ll * res * x % MOD;
		x = 1ll * x * x % MOD;
		y >>= 1;
	}
	return res;
}

int C(int x,int y){
	if(x < y)
	    return 0;
	return 1ll * fac[x] * inv[x - y] % MOD * inv[y] % MOD;
}

int main(){
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    fac[0] = 1;
	for(int i = 1;i < MAXN;i++)
	    fac[i] = 1ll * fac[i - 1] * i % MOD;
	inv[MAXN - 1] = power(fac[MAXN - 1],MOD - 2);
	for(int i = MAXN - 2;i >= 0;i--)
	    inv[i] = 1ll * inv[i + 1] * (i + 1) % MOD;
	scanf("%d%d",&X,&Y);
	if((2 * X - Y) % 3 != 0){
		puts("0");
		return 0;
	}
	int a = (2 * X - Y) / 3;
	int b = X - 2 * a;
	if(a < 0 || b < 0){
		puts("0");
		return 0;
	}
	printf("%d\n",C(a + b,b));
	return 0;
}
/*
2a + b = X
a + 2b = Y
3a = 2X - Y
*/

Measured memory_bytes: 8064
require "set"

n,m = gets.split.map(&:to_i)

g = Array.new(n){ Set.new }
m.times do |i|
  a, b = gets.split.map(&:to_i)
  g[a] << b
  # g[b] << a
end

ans = 0
(2..n).to_a.permutation do |per|
  
  per.unshift(1)
  flag = true
  (n-1).times do |i|
    
    a, b = per[i], per[i+1]
    a, b = b, a if a > b
    
    if !g[a].include?(b)
      flag = false
      break
    end
  end
  ans += 1 if flag
end

puts ans

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

int main(){
    int n; cin>>n;
    queue<string> title;
    queue<int> length;
    for(int i=0; i<n; i++){
        string t; int l; cin>>t>>l;
        title.push(t);
        length.push(l);
    }
    string x; cin >>x;
    int ans = 0;
    while(true && title.size()>0){
        if(title.front()==x){
            title.pop(); length.pop(); break;
        }
        else title.pop(); length.pop();
    }
    while(true && length.size()>0){
        ans+=length.front();
        length.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    int a, b;
    cin >> a ;
    //*/
    
    /*
    vector<int> a(3);
    cin >> a.at(0) >> a.at(1) >> a.at(2) ;
    
    sort(a.begin(), a.end());
    */
    
    //*
    if( a % 10 == a / 100 % 10 ){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    //*/
    
    //cout << ( a - 1 ) * ( b - 1 ) << endl;

    return 0; 
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N;
    cin >> N;
    bool f = false;
    rep(i,N) {
        char C;
        cin >> C;
        if (C == 'Y') {
            f  = true;
            break;
        }
    }
    if (f) {
        cout << "Four" << endl;
    } else {
        cout << "Three" << endl;
    }
}


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

public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		int N = sc.nextInt();
		ArrayList<Integer> kouho = new ArrayList<>();
		for(int i = 0 ; i < 26 ; i++){
			for(int j = 0 ; j < 18 ; j++){
				kouho.add(4*i+7*j);
			}
		}
		if(kouho.indexOf(N) == -1)
			System.out.println("No");
		else
			System.out.println("Yes");
	}
}


Measured memory_bytes: 21844
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 1000000;
const int mod = 1000000007;
const int INF = 1 << 30;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define fi first
#define se second
#define pb push_back
#define fix(n) fixed<<setprecision(n)
#define itr vector<ll>::iterator
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
ll n, v[110],col[9],ct=0,ct2=0;
int main() {
	cin >> n;
	rep(i, n) { cin >> v[i]; int num = v[i] / 400; if (num >= 8)num = 8,++ct2; else if (!col[num])++ct; col[num] = 1; }
	if (ct2 == n)cout << 1 << " " << min((ll)8, n) << endl;
	else {
		cout << ct << " " << ct + ct2 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;
int main(){
    int n,k;
    cin>>n;
    cin>>k;
    int hoge=1;
    rep(i,0,n-1){
        if(hoge*2<hoge+k) hoge = hoge*2;
        else hoge = hoge + k;
    }
    cout<<hoge<<endl;
    return 0;
}

Measured memory_bytes: 888
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    usize n, m;
    std::cin >> n >> m;

    vec<usize> pbl(n), cnt(n, 1);
    pbl.at(0) = true;
    while (m--) {
        usize u, v;
        std::cin >> u >> v;
        u--, v--;
        pbl.at(v) |= pbl.at(u);
        cnt.at(u)--;
        cnt.at(v)++;
        if (!cnt.at(u)) pbl.at(u) = false;
    }

    usize ans = 0;
    for (usize i=0; i<n; i++) {
        ans += pbl.at(i) && cnt.at(i);
    }
    std::cout << ans << '\n';
}


Measured memory_bytes: 1792
a = input()
input_list = []
for k in a:
    input_list.append(int(k))
n=3
bag = []
fomul_list = []
for i in range(2 ** n):
    sum = input_list[0]
    fomul = str(input_list[0])
    for j in range(3):
        if (i >> j)&1:
            sum += input_list[j+1]
            fomul = fomul + "+" + str(input_list[j+1])
        else:
            sum -= input_list[j+1]
            fomul = fomul + "-" + str(input_list[j+1])
    bag.append(sum)
    fomul_list.append(fomul)
print(fomul_list[bag.index(7)] + "=7")

Measured memory_bytes: 38448
def main():
    n = int(input())
    alp = "zabcdefghijklmnopqrstuvwxy"
    res = ""
    for i in range(1,100):
        if(n<=26**i):
            n-=1
            for j in range(i):
                res+=chr(ord("a")+n%26)
                n//=26

            break
        else:
            n-=26**i
    print(res[::-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main() { 
    ll a,b,x;
    cin >> a >> b >> x;
    ll p,q;
    if(a == 0){
        cout << b/x + 1 << endl;;
    }
    else{
        p = (a-1)/x;
        q = b / x;
        cout << q - p << endl;
    }

}


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

int c[1401][1401];
int dp[1401][1401];

int main(){
	int H,W;
	cin >> H >> W;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			cin >> c[i][j];
		}
	}
	int ans = 0;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			dp[i][j] = (c[i][j]+1)%2;
			ans |= dp[i][j];
		}
	}
	for(int i=1;i<H;i++){
		for(int j=1;j<W;j++){
			if(c[i][j]) dp[i][j] = 0;
			else {
				dp[i][j] = min(dp[i-1][j-1],min(dp[i-1][j],dp[i][j-1])) + 1;
				ans = max(ans,dp[i][j]);
			}
		}
	}
	cout << ans*ans << endl;
}

Measured memory_bytes: 16488
#include <algorithm>
#include <iostream>
#include <stdio.h>

#define MAX_N 100'000

using namespace std;

int D[MAX_N];

int main() {
  int N;
  cin >> N;
  int res = 0;
  for (int i = 0; i < N; ++i) {
    cin >> D[i];
  }
  sort(D, D + N);
  res = D[(N - 1) / 2 + 1] - D[(N - 1) / 2];
  printf("%d\n", res);
}

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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    int a, b, c, d, n, x, y;

    cin >> a >> b >> c >> d;

    auto Yes = [&](bool t){
        cout << (t ? "Yes" : "No") << endl;
    };
    auto YES = [&](bool t){
        cout << (t ? "YES" : "NO") << endl;
    };
    cout << min(a, b) + min(c, d) << endl;
}


Measured memory_bytes: 256
#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA cerr << "AAAAA" << endl
#define debug_ cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                     \
    cout << #v << endl;                  \
    for (int i = 0; i < v.size(); i++) { \
        cout << v[i] << " ";             \
    }                                    \
    cout << endl;
#define debug_vec2(v)                           \
    cout << #v << endl;                         \
    for (int i = 0; i < v.size(); i++) {        \
        for (int j = 0; j < v[i].size(); j++) { \
            cout << v[i][j] << " ";             \
        }                                       \
        cout << endl;                           \
    }

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

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

template <typename T>
void quit(T a) {
    cout << a << endl;
    exit(0);
}

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>;  // クラスカル法とかで、{cost, {from,
                                       // to}}的に使う。
const ll LINF = 10010020030040056ll;
const int INF = 1001001001;
const double pi = acos(-1);

int main() {
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for (int i = 0; i < 3; i++) {
        if (s[i] == t[i]) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
def solve(A, n):
    s = min(A)
    ans = 0

    B = A[:]
    V = [False for i in A]
    B = sorted(B)
    T = [0 for i in range(VMAX+1)]
    for i in range(n):
        T[B[i]] = i

    for i in range(n):
        if V[i]:
            continue
        cur = i
        S = 0
        m = VMAX
        an = 0

        while True:
            V[cur] = True
            an += 1
            v = A[cur]
            m = min(m, v)
            S += v
            cur = T[v]
            if V[cur]:
                break
        ans += min(S + (an - 2) * m, m + S + (an + 1) * s)
    return ans

MAX = 1000
VMAX = 10000


n = int(input())
A = list(map(int, input().split()))

ans = solve(A, n)
print(ans)

Measured memory_bytes: 7900
#include<iostream>

using namespace std;

int main(){
	int a, b, add, sub, pro;
	cin >> a >> b;
	
	add = a + b;
	sub = a - b;
	pro = a * b;
	
	int max;
	if(add < sub){
		max = sub;
	}else{
		max = add;
	}

	if(max < pro){
		max = pro;
	}

	cout << max << endl;
	
	return 0;
}

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

int main(void){
    int n, k;
    cin >> n >> k;
    set<int> st;
    rep1(i,n) st.insert(i);
    rep(i,k){
        int d;
        cin >> d;
        rep(j,d){
            int a;
            cin >> a;
            st.erase(a);
        }
    }
    cout << st.size() << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll  long long
#define PB push_back
#define ld long double
#define ff first
#define ss second
# define st(v) (v).begin(),(v).end()
#define   pr pair<int,int>
using namespace std::chrono;
const int N = 1e5+4 , M=N,inf=(int)1e9;
const ll mod=1e9+7;
int fastAbs(int n) { return (n ^ (n >> 31)) - (n >> 31); }
ll multiply(ll a, ll b){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
int ans ;
//map< pair<int,int> , int > mp;
const int dx[4] = {1,0,0,-1};
const int dy[4] = {0,-1,1,0};
void solve(){
    ll n ;
    cin >> n ;
    vector < ll > factor ;
    for( ll i = 1 ; i * i <= n ; i++){
        if(n%i==0){
            factor.PB(i);
            if( i != n/i ){
                factor.PB(n/i);
            }
        }
    }
    ll sum = 0 ;
    for( int i = 1 ; i < factor.size() ; i++){
        ll q = n / (factor[i]-1) ;
        ll r = n  % (factor[i]-1) ;
        if(q==r)
            sum+=(factor[i]-1);
    }
    cout << sum ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q=1;
    //cin >> q;
    while(q--)
        solve();
}
/*
    update - o(1) - log time
*/


Measured memory_bytes: 384
using System;

namespace practice
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split();
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int sum = a + b;
            if (sum >= 10)
            {
                Console.WriteLine("error");
            }
            else
            {
                Console.WriteLine(sum);
            }

        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
const int lim = int(1e5 + 1);

typedef pair<int, int> P;

//個数、数字
vector<P> odd(lim), eve(lim);

int main(){
    int n;
    cin >> n;
    for(int i=0; i<n; i++){
        int num;
        cin >> num;
        if(i%2 == 0){
            eve[num].first++;
            eve[num].second = num;
        }
        else{
            odd[num].first++;
            odd[num].second = num;
        }
    }
    
    //降順ソート
    sort(eve.rbegin(),eve.rend());
    sort(odd.rbegin(),odd.rend());


    if(odd[0].second != eve[0].second) cout << (n/2 - odd[0].first) + (n/2 - eve[0].first) << endl;
    else cout << min((n/2 - eve[0].first) + (n/2 - odd[1].first), (n/2 - eve[1].first) + (n/2 - odd[0].first)) << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

struct Work {
  int no;
  ll limit;

  bool operator<(const Work& rhs) const { return limit < rhs.limit; }
};

int main() {
  int n;
  cin >> n;
  vector<ll> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i];

  vector<Work> wl(n);
  for (int i = 0; i < n; i++) {
    Work w = {i, b[i]};
    wl[i] = w;
  }
  sort(wl.begin(), wl.end());

  int t = 0;
  for (int i = 0; i < n; i++) {
    int no = wl[i].no;
    t += a[no];
    if (t > wl[i].limit) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}


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

using namespace std;

int main(int args, char* argv[]){
  std::string s;
  std::cin >> s;
  
  if(s.length() != 6){
	std::cout<< "No";
    return 0;
  }
  
  for(char c : s){
    if(c < 'a' && c > 'z'){
      std::cout << "No";
      return 0;
    }
  }
  
  
  if(s[2]==s[3] && s[4]==s[5]){
    std::cout << "Yes";
    return 0;
  }
  
  std::cout << "No";
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    string S;
    cin>>S;
    int ans;
    if(S=="RRR"){
        ans=3;
    }else if(S=="RRS"||S=="SRR"){
        ans=2;
    }else if(S=="SSS"){
        ans=0;
    }else{
        ans=1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
    using namespace std;
    typedef long long int ll;
     
    int main() {
    	#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
        #endif
     
        ll n,m,no,sum=0;

        cin>>n>>m;
        for(int i = 1; i <= m; i++)
        {
        	cin>>no;
        	sum += no;
        }
        no = n-sum;
        if(no < 0)
        	cout<<"-1";
        else
        	cout<<no;
        
        return 0;
    }

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stdlib.h>
using namespace std;

#define INF 1e9
#define PI 3.141592653589793238
#define N 1000000010
#define mod 1000000007
#define REP(inc, bgn, end) for(int inc=bgn; inc<end; inc++)
typedef long long ll;

int main() {
    ll a,b,c,d; cin>>a>>b>>c>>d;
    ll ans=-1000000000000000000;
    ans=max(ans, a*c);
    ans=max(ans, b*d);
    ans=max(ans, a*d);
    ans=max(ans, b*c);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3636