akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
#include <iomanip>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int b, r, g, c, s, t;
	while(cin >> b >> r >> g >> c >> s >> t && (b || r || g || c || s || t))
		cout << 100 + b * 15 + r * 15 + g * 7 + c * 2 - (t - b * 5 - r * 3 - s) * 3 - (b * 5 + r * 3) * 2 + (b * 5 + r * 3) * 15 << endl;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define reppe(i,a,b) for(int i = (int)(a) ; i <= (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repme(i,a,b) for(int i = (int)(a) ; i >= (int)(b) ; --i)

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int N; cin >> N;
    string S; cin >> S;
    int count = 0;
    repp(i, 1, N) {
        if (S[i] == S[i-1]) ++count;
    }
    cout << N - count << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
	int A[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}; 
	int K; cin >> K; cout << A[K-1] << endl; 
}

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    int maxi = 0;
    int maxIndex = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        if(maxi < a[i]){
            maxi = a[i];
            maxIndex = i;
        }
    }

    int half = maxi / 2;

    int best = 1e9;
    int bestIndex = 0;
    for(int i = 0; i < n; i++){
        if(a[i] == maxi) continue;
        if(best > abs(a[i] - half)){
            best = abs(a[i] - half);
            bestIndex = i;
        }
    }

    cout << a[maxIndex] << " " << a[bestIndex] << endl;

    
}

Measured memory_bytes: 640
#include <stdio.h>
 
int main(void)
{
    int r, c, i, j;
    int elements[101][101] = { 0 };
 
    scanf("%d %d", &r, &c);
    
	for (j = 0; j < r; j++)
	{
        for (i = 0; i < c; i++)
		{
            scanf("%d", &elements[j][i]);
            elements[j][c] += elements[j][i];
            elements[r][i] += elements[j][i];
        }
    }
    
	for (i = 0; i < c; i++)
	{
        elements[r][c] += elements[r][i];
    }
    
	for (j = 0; j <= r; j++)
	{
        for (i = 0; i <= c; i++)
		{
            printf("%d", elements[j][i]);
            
			if (i < c)
			{
                printf(" ");
            }
			else
			{
                printf("\n");
            }
        }
    }
    
	return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <algorithm>
typedef long long ll;
using namespace std;

int a[310][310];
ll mod=998244353, beki[310];

int main(void){
    int N, M;
    cin >> N >> M;
    for(int i=0; i<N; ++i){
        for(int j=0; j<M; ++j){
            cin >> a[i][j];
        }
    }
    beki[0]=1;
    for(int i=1; i<310; ++i){
        beki[i]=(beki[i-1]*2)%mod;
    }
    int cnt=0;
    for(int i=0; i<N; ++i){
        int piv=cnt;
        while(piv<M){
            if(a[i][piv]==1) break;
            ++piv;
        }
        if(piv<M){
            for(int j=0; j<N; ++j){
                swap(a[j][cnt], a[j][piv]);
            }
            for(int j=cnt+1; j<M; ++j){
                if(a[i][j]==1){
                    for(int k=0; k<N; ++k){
                        a[k][j] ^= a[k][cnt];
                    }
                }
            }
            ++cnt;
        }
    }
    ll ans=(beki[M]+mod-beki[M-cnt])%mod;
    (ans *= beki[N-1]) %= mod;
    cout << ans << endl;
    return 0;
}


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

int main ()
{
	string s;  cin>>s;
	
	if(s=="Sunny"){
		cout<<"Cloudy"<<endl;
	}
	else if(s=="Cloudy"){
		cout<<"Rainy"<<endl;
	}
	else cout<<"Sunny"<<endl;


}



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

using namespace std;
typedef long long ll;

#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define MAX_N 100000

// xのe乗 % MOD
ll binpow(ll x, ll e)
{
  ll a = 1, p = x;
  while(e > 0)
  {
    if(e%2 == 0) {p = (p*p) % MOD; e /= 2;}
    else {a = (a*p) % MOD; e--;}
  }

  return a % MOD;
}

int main(void)
{
  int n;
  vector<int> a;
  cin >> n;
  for(int i=0; i<n; i++) {
    int temp; cin >> temp;
    a.push_back(temp);
  }

  vector<int> v;
  if(n%2==1) {
    v.push_back(0);
    for(int i=2; i<n; i+=2) {
      v.push_back(i); v.push_back(i);
    }
  } else {
    for(int i=1; i<n; i+=2) {
      v.push_back(i); v.push_back(i);
    }
  }

  sort(a.begin(), a.end());
  sort(v.begin(), v.end());
  //for(int i=0; i<n; i++) cout << a[i] << " " << v[i] << endl;

  bool flag = true;
  for(int i=0; i<n; i++) {
    if(a[i] != v[i]) {flag = false; break;}
  }

  //cout << "flag:" << flag << endl;

  if(flag) {
    ll ans = binpow(2, (ll)(n/2));
    cout << ans << endl;
  } else {
    cout << 0 << endl;
  }

  return 0;
}

Measured memory_bytes: 1400
n,k = map(int,input().split())
ls_h = list(map(int,input().split()))
temp_min = 99999999
ls_cos = [0]*n
ls_cos[1] = abs(ls_h[1]-ls_h[0])
# print(ls_h)
for i in range(min(k,n)):
    ls_cos[i] = abs(ls_h[i]-ls_h[0])

k = min(k,n)
for i in range(k,n):
    temp_min = 10**11
    for j in range(1,k+1):
        # print(i,j)
        temp_min = min(temp_min,ls_cos[i-j]+abs(ls_h[i]-ls_h[i-j]))
    ls_cos[i] = temp_min
#     print(ls_cos)
# print(ls_cos)
# if 99999999 in ls_cos:
#     print(ls_cos[9999999])
print(ls_cos[-1])



Measured memory_bytes: 52448
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = 1e9 + 7;

int s;
long long ans, fac[5000];

long long quickpow(long long b, long long e)
{
	return e ? ((e & 1 ? b : 1)*quickpow(((b%MOD)*(b%MOD)) % MOD, e >> 1)) % MOD : 1;
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	fac[0] = 1;
	for (int i = 1; i < 5000; i++) {
		fac[i] = i * fac[i - 1];
		fac[i] %= MOD;
	}
	cin >> s;
	for (int i = 1; i <= s / 3; i++) {
		int tmp = s - i * 3;
		long long cur = fac[tmp + i - 1];
		cur *= quickpow(fac[i - 1], MOD - 2);
		cur %= MOD;
		cur *= quickpow(fac[tmp], MOD - 2);
		cur %= MOD;
		ans += cur;
		ans %= MOD;
	}
	cout << ans << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 3664
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class Main{

	public static void main(String[] args) throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer in=new StringTokenizer(br.readLine());
        int A =Integer.parseInt(in.nextToken());
        int B =Integer.parseInt(in.nextToken());
        in = null;
		br=null;
		int ans = A + Math.abs(B);
		System.out.println(Math.max(ans, A * B));

	}



}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<char> vchar;
typedef vector<vector<char>> vvchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef priority_queue<long long> prque;
#define ain(i,n,a) for(long long i=0;i<(long long)(n);i++){cin>>a[i];}
#define aout(i,n,a) for(long long i=0;i<(long long)(n);i++){if(i){cout<<" ";}cout<<a[i];if(i==n-1){cout<<endl;}}
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define vsort(v) sort((v).begin(),(v).end())
#define vrsort(v) sort((v).rbegin(),(v).rend())
#define vreverse(v) reverse((v).begin(),(v).end())
#define pf(a) push_front(a)
#define pb(a) push_back(a)
#define INF 1998021900
#define MOD 1000000007
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //input
  string s;cin>>s;ll i,j,sz,h;sz=s.size();
  //caricurate
  vvll dp(sz,vll(13,0));//dp[文字目][余り]
  if(s[0] !='?'){
    dp[0][(s[0]-48)]=1;
  }else{
    rep(j,10){dp[0][j]=1;}
  }
  for(i=1;i<sz;i++){
    if(s[i] !='?'){
      rep(j,13){
        dp[i][(j*10+(s[i]-48))%13]+=dp[i-1][j];dp[i][(j*10+(s[i]-48))%13]%=MOD;
      }
    }else{
      rep(j,13){
        rep(h,10){
          dp[i][(j*10+h)%13]+=dp[i-1][j];dp[i][(j*10+h)%13]%=MOD;
        }
      }
    }
  }
  //output
  cout<<dp[sz-1][5]%MOD<<endl;
}

Measured memory_bytes: 13648
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    W, a, b = li_input()

    if a > b:
        a,b = b,a

    print(max(b - (a + W), 0))


main()


Measured memory_bytes: 5412
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Contests
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var ul = Console.ReadLine().Split(' ').Select((x) => int.Parse(x)).Aggregate(Tuple.Create(0, 10000), (a, x) =>
            {
                var u = Math.Max(a.Item1, x);
                var l = Math.Min(a.Item2, x);
                return Tuple.Create(u, l);
            });
            Console.WriteLine(ul.Item1 - ul.Item2);
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main()
{
    long long n, m;
    cin >> n;
    for (long long i = sqrt(n); 0 < i; i--)
    {
        if (n % i == 0)
        {

            m = n / i;
            n = i;
            break;
        }
    }
    cout << n + m - 2;
}

Measured memory_bytes: 256
S = input()

total_sum = 0

def pros(last_str, cur, remain):
  global total_sum
  if len(remain) == 1:
    total_sum += cur + int(last_str + remain[0])
  else:
    pros(last_str + remain[0], cur, remain[1:])
    pros('', cur + int(last_str + remain[0]), remain[1:])
pros('', 0, S)
print(total_sum)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <map>
#include <stack>
using namespace std;

int main() {
    map<char, char> m;
    m[')'] = '(';
    m[']'] = '[';
    while(1){
        string str;
        getline(cin, str);
        // cout << str << endl;
        if(str == ".") break;
        stack<char> s;
        bool flag = false;
        for(auto c : str){
            if(c == '(' || c == '['){
                s.push(c);
            }
            if(c == ')' || c == ']'){
                if(s.size() > 0){
                    char taiou = s.top();
                    s.pop();
                    if(m[c] != taiou){
                        cout << "no" << endl;
                        flag = true;
                        break;
                    }
                }else{
                    cout << "no" << endl;
                    flag = true;
                    break;
                }
            }
        }

        if(!flag){
            if(s.size() == 0){
                cout << "yes" << endl;
            }else{
                cout << "no" << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3052
#include <iostream>
int main(){
    int n, x, t;
    std::cin >>n >>x >>t;
    int t_sum;

    if (n%x==0){
        t_sum= int(n/x)*t;
    }else{
        t_sum=int(n/x)*t+t;
    }
    std::cout <<t_sum<<std::endl;

    return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
int main(void){
 int i, j, k;
 int n, x;
 int count;
 
 while(1){
     scanf("%d %d",&n, &x);
     if(n == 0 && x == 0)break;
     count = 0;
     for(i = 1;3*i+3<=x;i++){
         for(j = i+1;i+2*j+1<=x;j++){
             for(k = n;k > j;k--){
                 if(x == i+j+k){
                     count++;
                     break;
                 }else if(x >=i+j+k){
                     break;
                 }
             }
         }
     }
     printf("%d\n",count);
 }
    return 0;
}



Measured memory_bytes: 2704
#include <stdio.h>
#include <vector>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
 
//I imitated Ant Book version 1: P.84.
 
int n,q,com,x,y;
int rnk[100002],parent[100002];
 
int find(int x){
    if(x == parent[x])return x;
    else{
        return parent[x] = find(parent[x]);
    }
}
 
bool isSame(int x,int y){
    return find(x) == find(y);
}
 
void unite(int x,int y){
    x = find(x);
    y = find(y);
 
    if(x == y)return;
 
    if(rnk[x] < rnk[y]){
        parent[x] = y;
    }else{
        parent[y] = x;
        if(rnk[x] == rnk[y])rnk[x]++;
    }
}
 
int main(){
 
    scanf("%d %d",&n,&q);
    vector <int> p;
    REP(i,n){
      int c;
      cin >> c;
      p.pb(c);
    }
    for(int i = 0; i < n; i++){
        rnk[i] = 0;
        parent[i] = i;
    }
 
    for(int i = 0; i < q; i++){
        scanf("%d %d",&x,&y);
 
	if(isSame(x,y))continue;
	unite(x,y);
    }
    int sum = 0;
    REP(i,n){
      if(isSame(p[i],i+1)){
	sum++;
      }
      
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 1528
#include <iostream>
using namespace std;
int main(void){
	long long  n;
	cin >>n;
	long long  min=n+1;
	long long  tmp;
	for(long long i=1;i*i<=n;i++){
		long long  j;
		if(n%i==0){
			j = n/i;
			tmp  = j+i-2;
		}
		if(min>tmp)min=tmp;
	}
	cout <<min<<endl;
	return 0;

}

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

int main(){
  string s;
  cin >> s;
  int ans=0,c;
  for(int i=0;i<s.size();i++){
    c=0;
    while(i+c<s.size()&&(s.at(c+i)=='A'||s.at(c+i)=='C'||s.at(c+i)=='G'||s.at(c+i)=='T'))
      c++;
    ans=max(ans,c);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3580
n,m=map(int,input().split())
ab=[list(map(int,input().split()))for i in range(m)]
ans=[0]*n
edge=[[]for _ in range(n)]
for a,b in ab:
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)
visited={0}
stack=[0]
for i in stack:
  for j in edge[i]:
    if j in visited:continue
    stack.append(j)
    visited.add(j)
    ans[j]=i+1
print("Yes")
print(*ans[1:])

Measured memory_bytes: 78948
from math import sqrt
def divisors(n):
    divisors = []
    for i in range(1, int(sqrt(n))+1):
        q, r = divmod(n, i)
        if r == 0:
            divisors.append(i)
            if i != q:
                divisors.append(q)
    divisors.sort()
    return divisors

n, m = map(int, input().split())
ans = 1
for a in divisors(m)[1:]:
    if a*n <= m:
        ans = a
print(ans)

Measured memory_bytes: 9204
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        int[] nums = new int[N];
        for (int i = 0; i < N; i++) {
            nums[i] = Integer.parseInt(in.next());
        } 

        int res = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i + 1; j < N; j++) {
                res += (nums[i] * nums[j]);
            }
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
 
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 1000100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
 
ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll H,W,h,w;
    cin >> H >> W >> h >> w;
    
    cout << (H-h)*(W-w) << endl;
    
    
 
    return 0;
}



Measured memory_bytes: 256
object Main extends App {
  override def main(args: Array[String]): Unit = {
    val listAll = io.Source.stdin.getLines.toList
    val list = listAll.drop(1)
    val w = listAll(0)
//    println(listAll)
    val res = list.takeWhile(_ != "END_OF_TEXT").
      foldLeft(0)((z, str) => {
//       println(str)
        z + str.split(' ').count(_.equalsIgnoreCase(w))
      })

    println(res)
  }
}

Measured memory_bytes: 43852
#include <bits/stdc++.h>
using namespace std;
using unWeightedGraph = vector<vector<int>>;

int N, M;

int dfs(unWeightedGraph graph, vector<bool> visited, int v) {
    bool all_visited = true;
    for (int i = 0; i < N; i++) {
        if (!visited[i]) all_visited = false;
    }
    if (all_visited) return 1;

    int ret = 0;
    for (int i = 0; i < N; i++) {
        if (graph[v][i] == 0) continue;
        if (visited[i]) continue;

        visited[i] = true;
        ret += dfs(graph, visited, i);
        visited[i] = false;
    }
    return ret;
}

int solve() {
    unWeightedGraph graph(N, vector<int>(N));
    int a, b;
    for (int i = 0; i < M; i++) {
        cin >> a >> b;
        a--, b--;
        graph[a][b] = 1;
        graph[b][a] = 1;
    }
    vector<bool> visited(N, false);
    visited[0] = true;
    return dfs(graph, visited, 0);
}

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

    cin >> N >> M;
    cout << solve() << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }

void color(LL cur, LL parent, map<pair<LL,LL>, LL>& col, vector<vector<LL>>& edge){
    LL c = 0;
    for(LL next: edge[cur]){
        if(next == parent) continue;
        ++c;
        if(c == col[pair<LL,LL>(parent,cur)]) ++c;
        col[pair<LL,LL>(cur, next)] = c;
        col[pair<LL,LL>(next, cur)] = c;
        color(next, cur, col, edge);
    }
}

int main(){
    LL n;
    cin >> n;
    vector<vector<LL>> edge(n);
    vector<pair<LL,LL>> data;
    for(LL i = 0; i < n-1; ++i){
        LL a, b;
        cin >> a >> b;
        --a; --b;
        data.emplace_back(a, b);
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    map<pair<LL,LL>, LL> col;
    color(0, -1, col, edge);
    vector<LL> ans(n-1);
    for(LL i = 0; i < n-1; ++i){
        ans[i] = col[data[i]];
    }
    cout << *max_element(ans.begin(), ans.end()) << endl;
    for(LL i = 0; i < ans.size(); ++i){
        cout << ans[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 21360
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
int main(){
	int H,W;cin>>H>>W;
	int A[H][W] = {}; int a;
	rep(i,0,H)rep(j,0,W){ cin>>a; A[i][j] += a; }
	rep(i,0,H)rep(j,0,W){ cin>>a; A[i][j] -= a; }
	bool dp[H+1][W+1][12801] = {}; dp[0][1][0] = 1;
	rep(i,1,H+1)rep(j,1,W+1){
        int t = abs(A[i-1][j-1]);
		rep(k,0,12801){
			if(k + t <= 12800) dp[i][j][k+t] |= dp[i-1][j][k] | dp[i][j-1][k];
            dp[i][j][abs(k - t)] |= dp[i-1][j][k] | dp[i][j-1][k];
		}
	}
	rep(i,0,12801){
		if(dp[H][W][i]){
            cout<<i<<endl;
            break;
        }
	}
}

Measured memory_bytes: 82304
package main

import (
	"fmt"
)

func main() {
	var friendsCnt, minLength int

	fmt.Scanf("%d %d", &friendsCnt, &minLength)

	var friendsTalls = make([]int, friendsCnt)

	var passedFriendsCnt int;

	for index := 0; index < friendsCnt; index++ {
		fmt.Scan(&friendsTalls[index])
		if friendsTalls[index] >= minLength {
			passedFriendsCnt++
		}
	}

	fmt.Printf("%d\n", passedFriendsCnt)
}


Measured memory_bytes: 5504
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	
	//文字列から10進数に変換するときはparseIntを使います
	var n = parseInt(input[0], 10);
    var x = input[1].split(" ");
    var min = 0;
    var maxx = 0;
    for(var i = 0;i<n;i++){
        if(maxx<x[i]){
            maxx = x[i];
        }
    }
    for(var j=1;j<=maxx;j++){
        var s = 0;
        for(var k = 0;k<n;k++){
            s=s+((x[k]-j)*(x[k]-j));
        }
        if(min==0 || min >s){
            min=s;
        }
    }
    //出力
    console.log('%d',min);
	
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#define _USE_MATH_DEFINES

typedef long long ll;
const ll MD = 1000000007;

#include <iostream>
#include <math.h>
#include <climits>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <map> 
#include <set>
#include <string>
using namespace std;

/* sample input

*/

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

	cout << min({ a + b, b + c, c + a });
}

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

#define LL long long
#define RG register

using namespace std;
template<class T> T gi() {
	T x = 0; bool f = 0; char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') f = 1, c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f ? -x : x;
}
const int N = 5e3 + 10, Mod = 1e9 + 7;
struct node { int to, nxt; } g[N << 1];
int lst[N], gl;
void add(int x, int y) { g[++gl] = (node) {y, lst[x]}, lst[x] = gl; }
int siz[N], f[N][N], C[N][N], F[N], fac[N], ifac[N];
void pls(int &x, int y) { x += y; if (x >= Mod) x -= Mod; }
int fpow(int a, int b) {
	int res = 1;
	for (; b; b >>= 1, a = 1ll * a * a % Mod)
		if (b & 1) res = 1ll * res * a % Mod;
	return res;
}
void dfs(int u, int ff) {
	siz[u] = 1; f[u][1] = 1;
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (v == ff) continue;
		dfs(v, u);
		/*for (int z = 0; z <= min(siz[u], siz[v]); z++) {			
			for (int j = 0; j <= siz[u] - z; j++)
				for (int k = 0; k <= siz[v] - z; k++)
					pls(F[j + k], 1ll * f[u][j] * f[v][k] % Mod * ifac[z] % Mod);
			for (int j = 1; j <= siz[u] - z; j++) f[u][j - 1] = 1ll * f[u][j] * j % Mod;
			for (int j = 1; j <= siz[v] - z; j++) f[v][j - 1] = 1ll * f[v][j] * j % Mod;
			f[u][siz[u] - z] = f[v][siz[v] - z] = 0;
		}*/
		for (int j = 0; j <= siz[u]; j++) {
			for (int k = 1; k <= siz[v]; k++)
				pls(F[j + k], 1ll * f[u][j] * f[v][k] % Mod);
			pls(F[j], Mod - 1ll * f[u][j] * f[v][0] % Mod);
		}
		siz[u] += siz[v];
		for (int j = 0; j <= siz[u]; j++) f[u][j] = F[j], F[j] = 0;	   
	}
	if (u != 1) f[u][0] = 0;
	for (int i = 2, k = 2; i <= siz[u]; i += 2, k = 2 * k % Mod)
		pls(f[u][0], 1ll * fac[i] * fpow(k, Mod - 2) % Mod * ifac[i / 2] % Mod * f[u][i] % Mod);

/*printf("u = %d\n", u);
	for (int i = 0; i <= siz[u]; i++)
		printf("%d ", f[u][i]);
		puts("");*/
}
int main() {
	int n = gi<int>();
	for (int i = 1, x, y; i < n; i++) {
		x = gi<int>(), y = gi<int>();
		add(x, y), add(y, x);
	}
	for (int i = 0; i <= n; i++) C[i][0] = 1;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= i; j++)
			C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % Mod;
	fac[0] = 1;
	for (int i = 1; i <= n; i++) fac[i] = 1ll * fac[i - 1] * i % Mod;
	ifac[n] = fpow(fac[n], Mod - 2);
	for (int i = n; i >= 1; i--) ifac[i - 1] = 1ll * ifac[i] * i % Mod;
	dfs(1, 0);
	printf("%d\n", f[1][0]);
	return 0;
}


Measured memory_bytes: 194688
#include <stdio.h>
#include <string.h>

#define M  1000010
#define L 12

char H[M][L];



int getC(char c){
  if ( c == 'A') {
      return 1;
  }
  else if ( c == 'C'){
      return 2;
  }
  else if ( c == 'G'){
   return 3;
  }
  else if ( c == 'T') {
      return 4;
  }
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getC(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return (key % (M-1)) +1; }

int find(char str[]){
  int key,i,j;

  key = getKey(str);
  for(i = 0; i < M; i++){
    j = (h1(key) + i*h2(key)) % M;
    if(H[j][0] == '\0') return 0;
    else if(strcmp(H[j],str) == 0){
      return 1;
      break;
    }
  }
}



int insert(char str[]){
  int key,i,j;

  key = getKey(str);
  for(i = 0; i < M; i++){
    j = (h1(key) + i*h2(key)) % M;
    if(H[j][0] == '\0'){
      strcpy(H[j], str);
      break;
    }
  }
  return 0;
}


int main(){
  int i, n, h;
  char str[L], ab[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s %s", ab, str);
    if ( ab[0] == 'i' ){
      insert(str);
    } else {
      if (find(str)){
        printf("yes\n");
      }    else {
        printf("no\n");
      }
    }
  }

  return 0;
}



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

//vector…可変長、データの大きさに合わせてサイズを変える
//list…双方向リスト、要素を挿入、削除の多いとき
//forward_list
//array…固定長配列
//set…集合
//multiset
//bitset…2進数、固定長ビット列
//map…連想配列、キーと値を関連付ける
//multimap
//deque
//stack…FILO
//queue…FIFO
//priority_queue…格納された最大値から順に取り出す
//pair…二つの値を一組
//tuple…複数の値を一組

template<typename T>
void remove(std::vector<T>& vector, char index) {
    vector.erase(vector.begin() + index);
}

template<class T>
T ma(std::vector<T> &v) {
    T maxi = 0;
    for(auto &i:v) maxi = max(maxi, i);
    return maxi;
}

template<class T>
T mi(std::vector<T> &v) {
    T mini = 0;
    for(auto &i:v) mini = min(mini, i);
    return mini;
}

template <class T>
T pow(T x, T y, T n = numeric_limits<T>::max()) {
    if(y == 0) return 1;
    if(y % 2 == 0) return pow((x * x) % n, y / 2);
    return (x * pow(x, y - 1)) % n;
}

#define rep(i, n, m) for (int i = n; i <= m; i++)
#define Rep(i, n, m) for (int i = m; i >= 1; i--)

typedef long long ll;
typedef unsigned long long ull;

ull ans = 0;
/*
int gcd(int x, int y) {
    if (x < y) swap(x, y);
    return !y ? x : gcd(x % y, y);
}
*/
int main() {
    int n;
    cin >> n;
    vector<tuple<string, int, int> > a;
    rep(i, 1, n) {
        string s;
        int p;
        cin >> s >> p;
        p = -p;
        a.push_back(tie(s, p, i));
    }

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

    rep(i, 0, n-1) {
        string s;
        int p;
        int id;
        tie(s, p, id) = a[i];
        cout << id << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <stack>
#include <queue>
#include <set>

#define mod 1000000007
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
using ll = long long;
using pii = pair<int, int>;
int x[1000001];
int main(){
    int K;
    cin >> K;
    x[1]=7%K;
    for(int i=2; i<=K; i++) x[i]=(x[i-1]*10+7)%K;
    for(int j=1; j<=K; j++){
        if(x[j]==0) {
            cout << j;
            return 0;
        }
    }
    cout << (-1);
    return 0;
}

Measured memory_bytes: 7500
def main():
    S = input()
    T = input()

    cond = 1 <= len(S) <= 10
    cond = cond and (len(T) == len(S) + 1)
    cond = cond and (T[:-1] == S)

    print('Yes' if cond else 'No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9100
import heapq
N, M = list(map(int, input().split()))
days = [[] for _ in range(M + 1)]
for i in range(N):
    a, b = list(map(int, input().split()))
    if a > M: continue
    days[a].append(b)

reward = []
heapq.heapify(reward)

total = 0
for i in range(M)[::-1]:
    tasks = days[M - i]
    for task in tasks:
        heapq.heappush(reward, -1 * task)

    if len(reward) > 0:
        total += heapq.heappop(reward) * (-1)

print(total)

Measured memory_bytes: 23748
"""何回でも同じ荷物を選べるナップザック問題"""
def main():
    N,W = map(int, input().split())
    v,w = [],[]
    for i in range(N):
        a,b = map(int, input().split())
        v.append(a)
        w.append(b)
    # dp[i][j] = i種類の荷物から、容量がjとなるような価値の最大合計値
    dp = [[0]*(W+1) for _ in range(N+1)]
    for i in range(1,N+1):
        for j in range(W+1):
            if j-w[i-1]>=0:
                dp[i][j] = max(dp[i][j], dp[i-1][j-w[i-1]]+v[i-1])
                dp[i][j] = max(dp[i][j], dp[i][j-w[i-1]]+v[i-1])
            dp[i][j] = max(dp[i][j], dp[i-1][j])
    print(dp[N][W])

main()



Measured memory_bytes: 41904
let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let es = Array.make n [] in
  for i = 0 to m - 1 do
    Scanf.scanf "%d %d\n" @@ fun a b ->
      es.(a - 1) <- b - 1 :: es.(a - 1);
      es.(b - 1) <- a - 1 :: es.(b - 1)
  done;
  let rs = Array.make n min_int in
  let cs = Array.make n 0 in
  Scanf.scanf "%d\n" @@ fun q ->
    let rec dfs d c v =
      if rs.(v) < d && 0 <= d then begin
        rs.(v) <- d;
        if cs.(v) = 0 then
          cs.(v) <- c;
        List.iter (dfs (d - 1) c) es.(v)
      end in
    let vdcs = Array.init q @@ fun _ -> Scanf.scanf "%d %d %d\n" @@ fun v d c -> v, d, c in
    List.iter (fun (v, d, c) -> dfs d c (v - 1)) (List.rev (Array.to_list vdcs));
    Array.iter (Printf.printf "%d\n") cs



Measured memory_bytes: 18944
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		while ((line = br.readLine()) != null) {
			int s = 0;
			if(line.length()==0)break;
			char[] c = line.replace("CD", "CCCC").replace("CM", "DCCCC").replace("D", "CCCCC").replace("XL", "XXXX").replace("XC", "LXXXX").replace("L", "XXXXX").replace("IV", "IIII").replace("IX", "VIIII").replace("V", "IIIII").toCharArray();
			for (int i = 0; i < c.length; i++) {
				switch (c[i]) {
				case 'M':
					s += 1000;
					break;
				case 'C':
					s += 100;
					break;
				case 'X':
					s += 10;
					break;
				case 'I':
					s += 1;
					break;
				default:
					break;
				}
			}
			System.out.println(s);
		}

	}
}

Measured memory_bytes: 9796
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Net.Http.Headers;
using System.Security.Cryptography;

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

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

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

			string s = Console.ReadLine();

			if (s.EndsWith("s")) {
				Console.WriteLine(s + "es");
			} else {
				Console.WriteLine(s + "s");
			}

		}
	}
}


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

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int best = 0;
	for (int i = 0; i < n - 1; i++) {
		if (min(best, a.back() - best) < min(a[i], a.back() - a[i])) {
			best = a[i];
		}
	}
	cout << a.back() << ' ' << best << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() {
	char a[110];
	scanf("%s", a + 1);
	int n = strlen(a + 1);
	int pp = 0;
	for(int i = 2; i <= n; i++)
		if(a[i] != '9') 
			pp = 1;
	cout << a[1] - '0' - pp + (n - 1) * 9;
	return 0;
}

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



int main()
{
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (r <= x && x <= W - r && r <= y && y <= H -r ){
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

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

#define MOD 1000000007
#define MAXN 200009

std::vector < int > a[MAXN], g[MAXN];
struct myc {int x, y;} dp[MAXN];
bool term[MAXN], trim[MAXN], viz[MAXN];
int n, k, v[MAXN], t[MAXN], ans, put2[MAXN];
int stanga[MAXN], dreapta[MAXN];

inline void calc() {
    int cnt = 0;
    for (int i = 0; i < k; i++) {
        if (a[v[i]].size() == 0) {
            dp[v[i]].x = 1;
            dp[v[i]].y = 1;
            cnt++;
        } else {
            dp[v[i]].y = dp[v[i]].x = 0;
            int prod = 1;
            for (int j = 0; j < (int)a[v[i]].size(); j++) {
                dp[v[i]].y += dp[a[v[i]][j]].y;
                prod = 1LL * prod * (put2[dp[a[v[i]][j]].y] - dp[a[v[i]][j]].x + MOD) % MOD;
                stanga[j] = prod;
            }
            prod = 1;
            for (int j = a[v[i]].size() - 1; j >= 0; j--) {
                prod = 1LL * prod * (put2[dp[a[v[i]][j]].y] - dp[a[v[i]][j]].x + MOD) % MOD;
                dreapta[j] = prod;
            }
            for (int j = 0; j < (int)a[v[i]].size(); j++) {
                int left = 1, right = 1;
                if (j > 0)
                    left = stanga[j - 1];
                if (j + 1 < (int)a[v[i]].size())
                    right = dreapta[j + 1];
                dp[v[i]].x = (dp[v[i]].x + 1LL * dp[a[v[i]][j]].x * left % MOD * right) % MOD;
            }
            a[v[i]].clear();
        }
        if (v[i] != t[v[i]])
            a[t[v[i]]].push_back(v[i]);
    }
    ans = (ans + 1LL * dp[0].x * put2[n + 1 - cnt]) % MOD;
}

void dfs(int x) {
    if (term[x] == 1) {
        for (auto &y : g[x]) {
            viz[y] = 1;
            term[y] = 1;
            v[k++] = y;
        }
        term[x] = 0;
        if (g[x].size() > 1 || x == 0) {
            viz[x] = 1;
            trim[x] = 1;
            v[k++] = x;
        } else if (g[x].size() == 1) {
            trim[x] = 1;
            viz[x] = 0;
        } else {
            trim[x] = 0;
            viz[x] = 0;
        }
    } else {
        int cnt = 0;
        trim[x] = 0;
        for (auto &y : g[x]) {
            dfs(y);
            cnt += trim[y];
            trim[x] |= trim[y];
        }
        if (cnt > 1 || x == 0) {
            viz[x] = 1;
            v[k++] = x;
        } else viz[x] = 0;
    }
}

int main() {
    scanf("%d", &n);

    put2[0] = 1;
    for (int i = 1; i <= n + 1; i++)
        put2[i] = 2 * put2[i - 1] % MOD;

    for (int i = 1; i <= n; i++) {
        scanf("%d", &t[i]);
        g[t[i]].push_back(i);
    }

    k = 1;
    v[0] = 0;
    viz[0] = 1;
    term[0] = 1;
    while (k) {
        calc();
        k = 0;
        dfs(0);
        if (k == 1 && term[0] == 0)
            k = 0;
        for (int i = k - 1; i >= 0; i--)
            while (viz[t[v[i]]] == 0)
                t[v[i]] = t[t[v[i]]];
        for (int i = 0; i < k; i++)
            if (term[v[i]] == 0)
                g[v[i]].clear();
        for (int i = 0; i < k; i++)
            if (t[v[i]] != v[i])
                g[t[v[i]]].push_back(v[i]);
    }

    printf("%d\n", ans);

    return 0;
}


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

#define MOD 1000000007
#define MAX 100005
#define ll long long
#define slld(t) scanf("%lld",&t)
#define sd(t) scanf("%d",&t)
#define pd(t) printf("%d\n",t)
#define plld(t) printf("%lld\n",t)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define mp(a,b) make_pair(a,b)
#define FF first
#define SS second
#define pb(x) push_back(x)
#define vi vector<int>
#define vpii vector<pii >
#define vll vector<ll>
#define clr(x) memset(x,0,sizeof(x))

using namespace std;

ll S(ll l,ll c){
	ll k=l/c;
	ll ans=(2*k-1)*c;
	if(k*c==l) return ans;
	return ans+c+S(c,l-k*c);
}

int main(){
	ll n,x;
	cin>>n>>x;
	
	ll ans=n+S(n-x,x);
	plld(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 2005
#define ll long long
const ll mod=1e9+7;
int a[11][11];
int n,d;
bool ok(int x,int y)
{
    int sum=0;
    for(int i=1;i<=d;i++)
        sum+=(a[x][i]-a[y][i])*(a[x][i]-a[y][i]);

    if(sqrt(sum)-(int)sqrt(sum)<1e-6)
        return true;
    return false;
}
int main()
{
    scanf("%d%d",&n,&d);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=d;j++)
        scanf("%d",&a[i][j]);
    }
    int cnt=0;
    for(int i=1;i<n;i++)
        for(int j=i+1;j<=n;j++)
    {
        if(ok(i,j))cnt++;
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   long N = sc.nextLong();
   long s1 = N;
   long s2 = 1;
   for(long i = (long)Math.abs(Math.sqrt(N));i>=1;i--)
   {
    	if(N%i==0) 
       	{
       	  	s1 = i;
         	s2 = N/s1;
     		break;
 		}
   }
   System.out.println(s1+s2-2);
 }
}

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

struct P{
	double x,y,z;
};
double dot(P a,P b){
	return a.x * b.x + a.y * b.y + a.z * b.z;
}
double abs(P a){
	return sqrt(a.x*a.x+a.y*a.y+a.z*a.z);
}
P sub(P a,P b){
	a.x -= b.x;
	a.y -= b.y;
	a.z -= b.z;
	return a;
}
P pls(P a,P b){
	a.x += b.x;
	a.y += b.y;
	a.z += b.z;
	return a;
}
P mul(double v,P a){
	a.x *= v;
	a.y *= v;
	a.z *= v;
	return a;
}

double dist(P a,P b,P c){
	P e = sub(b,a);
	e = mul(1./abs(e),e);
	P v = sub(c,a);
	P pdl = pls(a,mul(dot(e,v),e));
	if( fabs(abs(sub(pdl,a))+abs(sub(pdl,b))-abs(sub(a,b))) > 1e-8 ) return 1e9;
	return abs(sub(c,pdl));
}
P p[50];
long long l[50],r[50];
int main(){
	int N,Q;
	cin >> N >> Q;
	for(int i = 0 ; i < N ; i++) cin >> p[i].x >> p[i].y >> p[i].z >> r[i] >> l[i];
	for(int i = 0 ; i < Q ; i++){
		P p1,p2;
		cin >> p1.x >> p1.y >> p1.z;
		cin >> p2.x >> p2.y >> p2.z;		
		long long ans = 0;
		for(int j = 0 ; j < N ; j++){
			if( dist(p1,p2,p[j]) < r[j] + 1e-8 ) ans += l[j];
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1236
// inputに入力データ全体が入る
function Main(input) {
  var H,W,h,w;
  H = Number(input.split('\n')[0].split(' ')[0]);
  W = Number(input.split('\n')[0].split(' ')[1]);
  h = Number(input.split('\n')[1].split(' ')[0]);
  w = Number(input.split('\n')[1].split(' ')[1]);

  console.log((H-h)*(W-w));
  
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
n = gets.to_i
s = gets.chomp
x=Array.new(n,0)
y=Array.new(n,0)
n.times do |i|
    next if i==0
    x[i]=x[i-1]
    x[i]+=1 if s[i-1]=='W'
    y[n-i-1]=y[n-i]
    y[n-i-1]+=1 if s[n-i]=='E'
end
ans = 10**9
n.times do |i|
    ans = [ans,x[i]+y[i]].min
end
puts ans

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

using namespace std;

int main() {
    int grid[3][3];
    int x;
    for (auto &i : grid)
        for (int &j : i) {
            cin >> x;
            j = x;
        }

    bool andGrid[3][3];
    for (auto &i : andGrid) for (bool &j : i) j = false;

    int n;
    cin >> n;
    while (n--) {
        cin >> x;

        for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) if (grid[i][j] == x) andGrid[i][j] = true;
    }

    bool ans = false;
    if (andGrid[0][0] && andGrid[0][1] && andGrid[0][2]) ans = true;
    else if (andGrid[1][0] && andGrid[1][1] && andGrid[1][2]) ans = true;
    else if (andGrid[2][0] && andGrid[2][1] && andGrid[2][2]) ans = true;
    else if (andGrid[0][0] && andGrid[1][0] && andGrid[2][0]) ans = true;
    else if (andGrid[0][1] && andGrid[1][1] && andGrid[2][1]) ans = true;
    else if (andGrid[0][2] && andGrid[1][2] && andGrid[2][2]) ans = true;
    else if (andGrid[0][0] && andGrid[1][1] && andGrid[2][2]) ans = true;
    else if (andGrid[0][2] && andGrid[1][1] && andGrid[2][0]) ans = true;

    cout << (ans ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
Ai = list(map(int, input().split()))

Bi = []
for i in range(N):
    Bi.append(Ai[i] - (i + 1))
Bi.sort()
b = Bi[len(Bi) // 2]
ans = 0
for i in range(N):
    ans += abs(Ai[i] - (b + i + 1))
print(ans)

Measured memory_bytes: 26708
#include<iostream>
#include<vector>
#include<string>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
typedef pair<int,string> P;
int main(){
  int n,t,h1,m1,h2,m2;
  char s1[51],s2[51];
  scanf("%d %d",&n,&t);
  vector<P> p;
  string o,o2;
  cin >> o >> o2;
  for(int i=0;i<n-1;i++){
    scanf("%d:%d %s %d:%d %s",&h1,&m1,s1,&h2,&m2,s2);
    int minute = (h2*60+m2)-(h1*60+m1);
    if(t <= minute) p.push_back(P(minute,s1));
  }
  cin >> o >> o2;
  cout << p.size() << endl;
  for(int i=0;i<p.size();i++){
    cout << p[i].second << " " << p[i].first << endl;
  }
}

Measured memory_bytes: 1252
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

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

vector<int> g[24][4]; // 0?????????, ??????????????¶????????????
int maps[10][10];
int m, n;
int cnt;

typedef pair<int, int> pii;

int main() {
	while (cin >> m >> n, m || n) {
		REP(i, 24) REP(j, 4) g[i][j].clear();
	
		REP(i, n) REP(j, m) scanf("%d", &maps[i][j]);
		
		
		cnt = 1;
		REP(i, n) {
			REP(j, m) {
				int tmp = -1;
				switch(maps[i][j]) {
					case 1: tmp = cnt++; break;
					case 2: tmp = 0; break;
				}
				maps[i][j] = tmp;
			}
		}
		
		REP(i, n) REP(j, m) {
			int from = maps[i][j];
			if (from != -1) {
				int tmp = 0;
				REP(k, n) if (maps[k][j] != -1) {
					if (k == i) {tmp++; continue;}
					g[from][tmp].push_back(maps[k][j]);
				}
				tmp = 2;
				REP(k, m) if (maps[i][k] != -1) {
					if (k == j) {tmp++; continue;}
					g[from][tmp].push_back(maps[i][k]);
				}
				reverse(g[from][0].begin(), g[from][0].end());
				reverse(g[from][2].begin(), g[from][2].end());
			}
		}
		
		map<int, int> now[24]; // [?????¨?????????][?????????????????¶?????¶???] = ????????????????????°
		now[0][0] = 1;
		
		int ans = 0;
		REP(i, cnt) {
			map<int, int> next[24];
			REP(j, cnt) {
				for (map<int, int>::iterator it = now[j].begin(); it != now[j].end(); ++it) {
					int bit = (*it).first;
					
					REP(k, 4) REP(l, g[j][k].size()) {
						int nextPos = g[j][k][l];
						int nextBit = bit | (1<<nextPos);
						
						if ((bit >> nextPos) & 1) continue;
						if (nextPos == 0 && nextBit != (1<<cnt) - 1) continue;
						
						next[nextPos][nextBit] += (*it).second;
						
						break;
					}
				}
			}
			REP(j, cnt) now[j] = next[j];
		}
		
		cout << now[0][(1<<cnt)-1] << endl;
		
	}
	return 0;
}

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

int bubbleSort(int A[], int N){
  int sw = 0;
  for(int i = 0; i < N; i++)
    for(int j = N - 1; j > i; j--){
      if(A[j] < A[j-1]){
        swap(A[j], A[j-1]);
        sw++;
    }
  }
  return sw;
}


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

  int sw =  bubbleSort(A, N);
  
  for(int i = 0; i < N; i++){
    if(i) cout << ' ';
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;
  
  return 0;
}





Measured memory_bytes: 3108