akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 998244353;
const int INF = 2e18;

signed main() {
    vector<string> S(3);
    cin >> S;
    vector<vector<vector<bool>>> check(3, vector<vector<bool>>(3, vector<bool>(6005, true)));
    {
        // before calc
        auto beforeCalc = [&](int i, int j) {
            string a = S[i], b = S[j];
            for (int start = 0; start < a.length(); start++) {
                bool ok = true;
                for (int now = 0; start + now < a.length() && now < b.length(); now++) {
                    if (a[start + now] != b[now] && a[start + now] != '?' && b[now] != '?') {
                        ok = false;
                        break;
                    }
                }
                check[i][j][start] = ok;
            }
        };
        for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) {
            if (i == j) continue;
            beforeCalc(i, j);
        }
    }
    int ans = 0;
    for (int i = 0; i < 3; i++) ans += S[i].length();
    vector<int> temp = {0, 1, 2};
    do {
        for (int x = 0; x < S[temp[0]].length(); x++) {
            for (int y = x; y - x < S[temp[1]].length() || y < S[temp[0]].length(); y++) {
                bool ok = true;
                ok &= check[temp[0]][temp[1]][x];
                if (y < S[temp[0]].length()) ok &= check[temp[0]][temp[2]][y];
                if (y - x < S[temp[1]].length()) ok &= check[temp[1]][temp[2]][y - x];
                if (ok) {
                    int res = S[temp[0]].length();
                    res = max(res, x + (int)S[temp[1]].length());
                    res = max(res, y + (int)S[temp[2]].length());
                    ans = min(ans, res);
                }
            }
        }
    } while (next_permutation(temp.begin(), temp.end()));
    cout << ans << endl;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	long long a[3];
	cin >> a[0] >> a[1] >> a[2];
	if (a[0] % 2 == 0 || a[1] % 2 == 0 || a[2] % 2 == 0)cout << 0 << endl;
	else {
		sort(a, a + 3);
		cout << a[0] * a[1] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys
import  math
import fractions
from collections import defaultdict
import copy
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
A=nl()
ans=0
now=A[0]
for i in range(1,N):
    if(now<A[i]):
        now=A[i]
        continue
    else:
        ans+=now-A[i]

print(ans)

    
    

Measured memory_bytes: 33108
/*
现在你有一棵树, 节点已经被染上颜色, 非黑(B)即白(W)
你可以从任意一个节点出发, 并执行操作: 

将所在节点的颜色反转 or 
走到下一个节点, 并反转它的颜色

问最少操作多少次, 能使得树是黑涩的(即无白色节点)
*/
#include<bits/stdc++.h>
using namespace std;

const int N=1e5+5;

long long ans,cost[N],Min;

int root,n,cnt,to[N<<1],nxt[N<<1],head[N],du[N];

bool Del[N],vis[N],val[N];

char c[N];

queue<int>que;

void add(int x,int y){
	to[++cnt]=y;nxt[cnt]=head[x];head[x]=cnt;
}

void sol(int x,int f){
	ans+=val[x]+2;
	cost[x]=val[x]?-2:0;
	for(int i=head[x];i;i=nxt[i])
		if(to[i]!=f&&!Del[to[i]]){
			sol(to[i],x);
			Min=min(Min,cost[x]+cost[to[i]]);
			cost[x]=min(cost[x],cost[to[i]]+(val[x]?-2LL:0LL));
		}
}


int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
		du[x]++;du[y]++;
	}
	scanf("%s",c+1);
	for(int i=1;i<=n;i++){
		if(du[i]==1&&c[i]=='B') que.push(i);
	}
	while(!que.empty()){
		int x=que.front();que.pop();
		Del[x]=1;
		for(int i=head[x];i;i=nxt[i]){
			du[to[i]]--;
			if(c[to[i]]=='B'&&du[to[i]]==1&&!Del[to[i]]) que.push(to[i]);
		}
	}
	for(int i=1;i<=n;i++)
		if(!Del[i]) {root=i;break;}
	if(!root) printf("0\n");
	else {
		for(int i=1;i<=n;i++)
			if(!Del[i])
				val[i]=(du[i]&1)^(c[i]=='W');
		sol(root,0);
		printf("%lld\n",ans+Min-2);
	}
	return 0;
}

Measured memory_bytes: 7680
#include <iostream>
#include <cstring>
#include <cstdio>

struct Node{
	int key;
	Node *prev, *next;
};
Node *nil;

void insertNode(int key){
	Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	nil->next->prev = x;
	x->next = nil->next;
	nil->next = x;
	x->prev = nil;
}

Node* searchNode(int key){
	Node *cur = nil->next;
	while(cur->key != key && cur != nil){
		cur = cur->next;
	}
	return cur;
}

void deleteNode(Node *t){
	if(t != nil){
		t->prev->next = t->next;
		t->next->prev = t->prev;
		free(t);
	}
}

void deleteFirst(){
	deleteNode(nil->next);
}

void deleteLast(){
	deleteNode(nil->prev);
}

int main(void){
	int n, key,i;
	char command[20];
	std::cin >> n;
	nil = (Node *)malloc(sizeof(Node));
	nil->next=nil;
	nil->prev=nil;
	Node *cur;

	for(i=0;i<n;i++){
		std::cin >> command;
		if(command[0]=='i') {
			std::cin >> key;
			insertNode(key);
		}
		else{
			if(std::strlen(command) > 6){
				if(command[6]=='F') deleteFirst();
				else if(command[6] = 'L') deleteLast();
			}
			else{
				std::cin >> key;
				deleteNode(searchNode(key));
			}
		}
	}
	
	cur = nil->next;
	while(cur->next != nil){
		std::printf("%d ",cur->key);
		cur = cur->next;
	}
	std::printf("%d\n",cur->key);
	
	return 0;
}

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

int main()
{
    int N,K;
    cin >> N >> K;
    int d[K];
    int A[K][N];
    for(int i=0;i<K;i++){
        cin >> d[i];
        for(int j=0;j<d[i];j++){
            cin >> A[i][j];
        }
    }
    int p[N];
    for(int i=0;i<N;i++)p[i]=1;
    for(int i=0;i<K;i++){
        for(int j=0;j<d[i];j++){
            if(p[A[i][j]-1]==1){
                p[A[i][j]-1]=0;
            }
        }
    }
    int count=0;
    for(int i=0;i<N;i++){
        if(p[i]==1)count++;
    }
    cout << count << endl;
}

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

int main() {
	long long N, A[100000], PCount = 0, MCount = 0, sum = 0;
	bool plus = true;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		if (plus) {
			if (sum + A[i] > 0) {
				sum += A[i];
			}
			else {
				PCount += 1 - (sum + A[i]);
				sum = 1;
			}
		}
		else {
			if (sum + A[i] < 0) {
				sum += A[i];
			}
			else {
				PCount += 1 + (sum + A[i]);
				sum = -1;
			}
		}
		plus = !plus;
	}
	sum = 0, plus = false;
	for (int i = 0; i < N; i++) {
		if (plus) {
			if (sum + A[i] > 0) {
				sum += A[i];
			}
			else {
				MCount += 1 - (sum + A[i]);
				sum = 1;
			}
		}
		else {
			if (sum + A[i] < 0) {
				sum += A[i];
			}
			else {
				MCount += 1 + (sum + A[i]);
				sum = -1;
			}
		}
		plus = !plus;
	}
	cout << min(PCount, MCount);
}

Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))
odd = 0
even = 0
four = 0

for i in a:
    if i % 4 == 0:
        four += 1
    elif i % 2 == 0:
        even += 1
    elif i % 2:
        odd += 1

if odd > four:
    if not (odd -1 == four and even == 0):
        print("No")
        exit()
print("Yes")

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

int main () {
  string s, ans = "Yes";
  cin >> s;
  
  if (s.size()%2 != 0) {
    ans = "No";
  }
  else {
    for (int i=1; i<s.size(); i+=2) {
      if (s[i-1]!='h' || s[i]!='i') {
        ans = "No";
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3620
EPS = 1e-10
def cross(p, q)
  x0 = p[2] - p[0]
  y0 = p[3] - p[1]
  x1 = q[2] - q[0]
  y1 = q[3] - q[1]
  x2 = q[0] - p[0]
  y2 = q[1] - p[1]
  return if (x0 * y1 - x1 * y0).abs < EPS
  r = (y1 * x2 - x1 * y2) / (x0 * y1 - x1 * y0)
  x = p[0] + r * x0; y = p[1] + r * y0
  return unless x.abs < 100.0 && y.abs < 100.0
  $ans += 1 if judge(x, y)
  $cp << [x, y]
end
def judge(x, y)
  $cp.all?{ |p, q| Math.sqrt((p - x) ** 2 + (q - y) ** 2 ) >= EPS }
end
while n = gets.to_i
  break if n == 0
  ls = n.times.map{ gets.split.map(&:to_f) }
  $ans = 1
  (0...n).each do |i|
    $cp = []
    (0...i).each do |j|
      cross(ls[i], ls[j])
    end
    $ans += 1
  end
  p $ans
end

Measured memory_bytes: 8912
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

ll d;
ll c[29];
ll a[369][29];
ll t[369];
ll b[29];

int main()
{
    scanf("%lld", &d);
    for(ll i = 1; i <= 26; i++)
    {
        scanf("%lld", &c[i]);
    }
    for(ll i = 1; i <= d; i++)
    {
        for(ll j = 1; j <= 26; j++)
        {
            scanf("%lld", &a[i][j]);
        }
    }
    ll ans = 0;
    for(ll i = 1; i <= d; i++)
    {
        ll mx = -4e18, mi = 0;
        for(ll ii = 1; ii <= 26; ii++)
        {
            t[i] = ii;
            ll ans2 = 0;
            ll tt = b[t[i]];
            b[t[i]] = i;
            for(ll j = 1; j <= 26; j++)
            {
                ans2 -= (i - b[j]) * c[j];
            }
            ans2 += a[i][t[i]];
            if(mx < ans2) mx = ans2, mi = ii;
            b[t[i]] = tt;
        }
        t[i] = mi;
        b[t[i]] = i;
        for(ll j = 1; j <= 26; j++)
        {
            ans -= (i - b[j]) * c[j];
        }
        ans += a[i][t[i]];
        printf("%lld\n", mi);
    }
    return 0;
}


Measured memory_bytes: 3888
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define NFOR(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); --i)
#define rep(i, a) for (ll i = 0; i < a; i++)
#define endl "\n"
#define fi first
#define se second
#define MOD 1000000007
#define inf 1e12
#define pb push_back
#define Case cout<<"Case #"<<++cas<<": ";
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(v) v.begin(),v.end()

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;

#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}

void solve() {
	ll mod = 1000000007;
	ll h, w;
	cin >> h >> w;
	vl dp(w, 0);
	dp[0] = 1;	
	rep(i, h) {
		rep(j, w) {
			char c;
			cin >> c;
			if (c == '.')
				dp[j] = (dp[j] + ((j >= 1) ? dp[j-1] : 0)) % mod;
			else dp[j] = 0;
		}
	}

	cout << dp[w - 1] << endl;
}

int main()
{
    fastio;
    ll t  = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}


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

int main(){
    ll n,k;
    cin >> n >> k;
    ll ans=0;
    
    while(n!=0){
        n=n/k;
        ans++;
    }
    
    cout << ans << endl;

    return 0;
}

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

constexpr int MAX = 10000;

int a, b, c;
int p, q, r, s;
int x, y;

inline bool check_and_print(int p, int q, int r, int s) {
	if(p * r != a || p * s + r * q != b || q * s != c) return false;
	cout << p << " " << q << " " << r << " " << s << endl;
	return true;
}

inline int calc(int p, int x) {
	return (p * x) / (2 * a);
}

inline bool ok(int p, int r) {
	if(check_and_print(p, calc(p, x), r, calc(r, y))) return true;
	if(p > r && check_and_print(p, calc(p, y), r, calc(r, x))) return true;
	return false;
}

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

	while(cin >> a >> b >> c && a) {
		const int D = b * b - 4 * a * c;
		const int sqrt_D = sqrt(D);

		if(sqrt_D * sqrt_D == D) {
			x = b + sqrt_D;
			y = b - sqrt_D;

			for(int i = 1; i * i <= a; ++i) {
				if(a % i == 0 && ok(a / i, i)) goto success;
			}
		}

		cout << "Impossible" << endl;
		continue;

	success:;
	}

	return EXIT_SUCCESS;
}

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

bool my_cmp(const tuple<string,int,int> &lhs,const tuple<string,int,int> &rhs){
  if (std::get<0>(lhs) != std::get<0>(rhs)) return std::get<0>(lhs) < std::get<0>(rhs);
  return std::get<1>(lhs) > std::get<1>(rhs);
}

int main() {
  int N; cin >> N;
  vector<tuple<string,int,int>> v;
  for(int i=0;i<N;i++){
    string s; int a;
    cin >> s >> a;
    v.push_back(make_tuple(s,a,i+1));
  }

  sort(v.begin(),v.end(),my_cmp);

  for(int i=0;i<N;i++){
    cout << get<2>(v[i]) << endl;
  }
}

Measured memory_bytes: 256
d='URLD'
m={'U':0,'R':1,'D':2,'U':3}
m=dict(zip(d,range(4)))
v={'L':'R','R':'L','D':'U','U':'D'}
v=dict([(d[i],d[3-i]) for i in range(4)])
v=dict(zip(d,d[::-1]))
h,w,n=map(int,input().split())
b=[h,w,w,h]
r,c=map(int,input().split())
o=[h-r+1,c,w-c+1,r]
s=input()
t=[v[i] for i in input()]
a=1
for j,i in m.items():
    c=o[i]
    for k in range(n):
        c+=(s[k]==j)
        if c>b[i]:
            a=0
        if c>1:
            c-=(t[k]==j)
if a:
    print('YES')
else:
    print('NO')


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

int main() {
  int n;
  cin>>n;
  int d = n % 10;
  if (d == 3) {
    cout<<"bon"<<endl;
  } else if (d <= 1 || d == 6 || d == 8) {
    cout<<"pon"<<endl;
  } else {
    cout<<"hon"<<endl;
  }
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;
//あとでやる https://atcoder.jp/contests/abc114/tasks/abc114_d
int main(){
    int N;
    cin>>N;
    vi prime{2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
    //for(int i=0;i<prime.size();i++)cout<<prime[i]<<" ";
    //cout<<endl;
    vi pow_count(prime.size(),0);
    for(int j=1;j<=N;j++){
        for(int i=0;i<prime.size();i++){
            int x=j;
            while(x%prime[i]==0){
                x/=prime[i];
                pow_count[i]++;
            }
        }
    }
    //for(int i=0;i<prime.size();i++)cout<<pow_count[i]<<" ";
    //cout<<endl;
    int ans=0;
    for(int i=0;i<prime.size();i++){
        if(pow_count[i]<2)continue;
        for(int j=0;j<prime.size();j++){
            if(i==j)continue;
            if(pow_count[j]<4)continue;
            for(int k=j+1;k<prime.size();k++){
                if(i==k)continue;
                if(pow_count[k]<4)continue;
                ans++;
            }
        }
    }
    for(int i=0;i<prime.size();i++){
        if(pow_count[i]<24)continue;
        for(int j=0;j<prime.size();j++){
            if(i==j)continue;
            if(pow_count[j]<2)continue;
            ans++;
        }
    }
    for(int i=0;i<prime.size();i++){
        if(pow_count[i]<14)continue;
        for(int j=0;j<prime.size();j++){
            if(i==j)continue;
            if(pow_count[j]<4)continue;
            ans++;
        }
    }
    if(pow_count[0]>=74)ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	if(b>a)return 0;
	if(a==b)return 1;
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int g(int x){
	x=modpow(x,MOD-2);
	return x;
}
string s,t;
signed main(){
	cin>>s>>t;
	int ans=0;
	if(s[0]==t[0])ans++;
	if(s[1]==t[1])ans++;
	if(s[2]==t[2])ans++;
	cout<<ans<<endl;
	return 0;
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll calc(ll n)
{
    ll s = 0;
    while (n > 0)
    {
        s += n % 10;
        n /= 10;
    }
    return s;
}

int main()
{
    ll N;
    cin >> N;
    ll min = INF;
    FOR(i, N, 1)
    {
        ll a = i;
        ll b = N - a;
        min = std::min(min, calc(a) + calc(b));
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=200005;
pin a[maxn];
int n;
i64 ans=1ll<<62;
inline void solve1(){
	int mini=1e9,maxi=0;
	rep(i,1,n)mini=min(mini,a[i].w1),mini=min(mini,a[i].w2);
	rep(i,1,n)maxi=max(maxi,a[i].w1),maxi=max(maxi,a[i].w2);
	int prmin=1e9,prmax=0;
	rep(i,1,n+1){
		if(i!=1){
			ans=min(ans,1ll*(maxi-mini)*(max(prmax,a[i].w1)-min(prmin,a[n].w1)));
		}
		prmax=max(prmax,a[i].w2);
		prmin=min(prmin,a[i].w2);
	}
}
inline void solve2(){
	int mini=1e9,maxi=0;
	rep(i,1,n)mini=min(mini,a[i].w1),mini=min(mini,a[i].w2);
	rep(i,1,n)maxi=max(maxi,a[i].w1),maxi=max(maxi,a[i].w2);
	int prmin=1e9,prmax=0;
	rep(i,1,n){
		if(i!=1){
			ans=min(ans,1ll*(maxi-min(prmin,a[n].w1))*(max(prmax,a[i].w1)-mini));
		}
		prmax=max(prmax,a[i].w2);
		prmin=min(prmin,a[i].w2);
	}
	ans=min(ans,1ll*(prmax-prmin)*(a[1].w1-a[n].w1));
}
int main(){
	read(n);
	rep(i,1,n)read(a[i].w1),read(a[i].w2);
	rep(i,1,n)if(a[i].w1<a[i].w2)swap(a[i].w1,a[i].w2);
	sort(a+1,a+1+n);reverse(a+1,a+1+n);
	solve1();
	solve2();
	printf("%lld\n",ans);
	return 0;
}


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

    class Program
    {
        static void Main()
        {
            var nm = Console.ReadLine().Split(' ');
            var n = int.Parse(nm[0]);
            var m = int.Parse(nm[1]);

            var nC = 0;
            var mC = 0;

            if (n > 1)
            {
                nC = n * (n - 1) / 2;
            }
            if (m > 1)
            {
                mC = m * (m - 1) / 2;
            }


            Console.WriteLine((nC + mC).ToString());
        }
    }

Measured memory_bytes: 27492
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
	let code = read::<String>().chars().collect::<Vec<char>>();
    let mut c = code[0].clone();
    
    for i in 1..code.len() {
        if c == code[i] {
            println!("Bad");
            return;
        }
        c = code[i].clone();
    }
    println!("Good");
}


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

int main(){
    int n,m;
    cin>>n>>m;
    priority_queue<pair<long long,int>> pq;
    for(int i=0;i<n;++i){
        int a;
        cin>>a;
        pq.push(make_pair(a,1));
    }
    for(int i=0;i<m;++i){
        int b;
        long long c;
        cin>>b>>c;
        pq.push(make_pair(c,b));
    }

    long long ans=0;
    int cur=0;
    while(n>cur){
        pair<long long,int> p=pq.top();
        pq.pop();
        int t=cur+p.second>n?n-cur:p.second;
        cur+=t;
        ans+=p.first*t;
    }

    cout<<ans<<endl;
}

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

bool solve() {
    int a, b, c;
    std::cin >> a >> b >> c;
    if (a == 0) return false;

    std::vector<int> ans(a + b + c, 2);
    std::vector<std::vector<int>> outs;

    int q;
    std::cin >> q;
    while (q--) {
        int x, y, z, r;
        std::cin >> x >> y >> z >> r;
        --x, --y, --z;

        if (r == 1) {
            ans[x] = ans[y] = ans[z] = 1;
        } else {
            outs.push_back({x, y, z});
        }
    }

    for (const auto& v : outs) {
        std::vector<int> out;
        for (auto x : v) {
            if (ans[x] != 1) out.push_back(x);
        }
        if (out.size() == 1) ans[out.front()] = 0;
    }

    for (auto a : ans) std::cout << a << "\n";

    return true;
}

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

    while (solve()) {}

    return 0;
}



Measured memory_bytes: 3212
#C'
from collections import Counter

n=int(input())  #数値入力 「N」だけの入力のとき
count_by_kw = Counter()
for i in range(n):
    count_by_kw[''.join(sorted(input()))]+=1

cnt=0
for val in count_by_kw.values():
    cnt+=val*(val-1)//2    
    
print(cnt)

Measured memory_bytes: 18232
V, E = map(int, raw_input().split())
G = [[float("inf")] * V for i in xrange(V)]
for i in xrange(V):
    G[i][i] = 0
for i in xrange(E):
    s, t, d = map(int, raw_input().split())
    G[s][t] = d

for k in xrange(V):
    for i in xrange(V):
        for j in xrange(V):
            G[i][j] = min(G[i][j], G[i][k] + G[k][j])

for i in xrange(V):
    if G[i][i] < 0:
        print "NEGATIVE CYCLE"
        exit()
    for j in xrange(V):
        if G[i][j] == float("inf"):
            G[i][j] = "INF"

for line in G:
    print " ".join(map(str, line))

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

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());
    vector<pair<int, int>> op;
    if (A[0] <= 0) {
        int pos = N-2;
        while (A[pos] > 0) {
            op.push_back({A[0], A[pos]});
            A[0] -= A[pos];
            pos--;
        }
        for (int i = pos; i >= 0; i--) {
            op.push_back({A[N-1], A[i]});
            A[N-1] -= A[i];
        }
        cout << A[N-1] << endl;
        for (pair<int, int> p : op) printf("%d %d\n", p.first, p.second);
    }
    else {
        for (int i = 1; i <= N-2; i++) {
            op.push_back({A[0], A[i]});
            A[0] -= A[i];
        }
        op.push_back({A[N-1], A[0]});
        A[N-1] -= A[0];
        cout << A[N-1] << endl;
        for (pair<int, int> p : op) printf("%d %d\n", p.first, p.second);
    }
    return 0;
}

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,arr[100007],m,n,coun=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    cin>>m;
    for(int i=0;i<m;i++)
    {
        cin>>a>>b;
        for(int j=0;j<n;j++){
        if(a-1==j)
        {
            coun+=b;
            continue;
        }
        coun+=arr[j];
        }
        cout<<coun<<endl;
        coun=0;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cstdlib>

using namespace std;

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



  while(true){
    if( a < b){
      int tmp = a;
      a = b;
      b = tmp;
    }

    if( a >= b && a >=1 && b>=1){
      int tmp = a;
      a = b;
      b = tmp%a;
    }else{
      break;
    }
  }

  int n = max(a,b);
  int res = 0;
  for(int i=1;i<=n;i++){
    if(a%i == 0 && b%i == 0) res = i;
  }
  cout << res << endl;
  
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
int p[100001], s[100001];
void make(int v){
	p[v] = v;
	s[v] = 1;
}

int find(int v){
	if(p[v]==v) return v;
	return p[v] = find(p[v]);
}

void merge(int a, int b){
	a = find(a);
	b = find(b);
	if(a==b) return ;
	if(s[a]<s[b]) swap(a, b);
	s[a]+=s[b];
	p[b] = a;
}
#define ll long long
int main() {
	ll n, m;
	cin>>n>>m;
	for(int i=1;i<=n;i++) make(i);
	for(int i=0;i<m;i++){
		int t1, t2;
		cin>>t2>>t1;
		merge(t1, t2);
	}
	set<int> t;
	for(int i=1;i<=n;i++) t.insert(find(i));
	cout<<t.size()-1;
}

Measured memory_bytes: 8316
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	X, Y, Z := sc.nextInt(), sc.nextInt(), sc.nextInt()
	X -= Z

	fmt.Fprintln(wtr, X/(Y+Z))
	wtr.Flush()
}


Measured memory_bytes: 640
using System;
using System.IO;

namespace A
{
    class A
    {
        static void Main(string[] args)
        {
            
            int[] stac = new int[500];
            int i =0, j=1;
            string a;
            string[] str = new string[500];
            a = Console.ReadLine();
            str = a.Split(' ');
            for (i=0; i<str.Length; i++)
            {
                if (str[i]=="+")
                {
                    stac[j - 2] = stac[j - 1] + stac[j - 2];
                    j--;
                }
                else if (str[i]=="-")
                {
                    stac[j - 2] = stac[j - 2] - stac[j - 1];
                    j--;
                }
                else if (str[i]=="*")
                {
                    stac[j - 2] = stac[j - 1] * stac[j - 2];
                    j--;
                }
                else
                {
                    stac[j] = int.Parse(str[i]);
                    j++;
                }
            }
            Console.WriteLine(stac[j-1]);

        }
    }
}



Measured memory_bytes: 9240
/**
*    author:  Taichicchi
*    created: 10.09.2020 20:27:09
**/

#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int main() {

    int N, M, C;

    cin >> N >> M >> C;

    vector<int> B(M);

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

    ll cnt = 0;

    int a;

    vector<int> A(M);
    for( int i = 0 ; i < N ; ++i ) {
        A.clear();
        ll q = 0;
        for(int j = 0; j < M ; ++j ) {
            cin >> a;
            q += a * B[j];
        }
        q += C;
        if(q > 0){
            cnt += 1;
        }
    }

    cout << cnt << endl;

    return 0;
}

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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define o cout<<"BUG"<<endl;
#define	IOS ios_base::sync_with_stdio(0);
#define en "\n"
#define FOR(i, j, n) for(int j = i; j < n; ++j)
#define forn(i, j, n) for(int j = i; j <= n; ++j)
#define nfor(i, j, n) for(int j = n; j >= i; --j)
#define sortv(vv) sort(vv.begin(), vv.end())
#define all(v) v.begin(), v.end()
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>


using namespace std;
const ll maxn=1e5+100,inf=1e18,LOG=23,mod=1e9+7;
int block = 300, timer = 0;
const ld EPS = 1e-7;

#define bt(i) (1 << (i))
//#define int ll

ll n, k;

main()
{
	cin >> n >> k;
	n %= k;
	cout << min(n, k-  n);
}

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

using namespace std;

int a[100005],b[100005];

int main()
{
	int n;
	cin>>n;
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	for(int i=1;i<=n/2;i++)
	{
		int x,y;
		cin>>x>>y;
		a[x]++;
		b[y]++;
	}
	int maxa=0,maxb=0;
	int maxaa,maxbb;
	for(int i=1;i<=100000;i++)
	{
		if(maxa<a[i]) maxa=a[i],maxaa=i;
		if(maxb<b[i]) maxb=b[i],maxbb=i;
	}
	if(maxaa!=maxbb) cout<<(n-maxa-maxb);
	else
	{
		int maxaaa=0,maxbbb=0,maxaaaa,maxbbbb;
		for(int i=1;i<=100000;i++)
		{
			if(i!=maxaa && maxaaa<a[i]) maxaaa=a[i],maxaaaa=i;
			if(i!=maxbb && maxbbb<b[i]) maxbbb=b[i],maxbbbb=i;
		}
		if(maxaaa<maxbbb){
			cout<<n-maxa-maxbbb;
		}
		else{
			cout<<n-maxaaa-maxb;
		}
	}
	
	return 0;
}


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

int main(){
  char a[6];
  string c = "NO";
  for(int i=0;i<6;i++) cin >> a[i];
  if(a[0]==a[5]&&a[2]==a[3]&&a[1]==a[4]) c = "YES";
  cout << c << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>

using namespace std;

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

  std::vector<std::pair<long, long> > a;

  for (int i = 1; i <= n; i++) {
    int index;
    cin >> index;
    a.push_back(std::make_pair(index, 1));
  }

  for (int i = 0; i < m; i++) {
    int b, c;
    cin >> b >> c;
    a.push_back(std::make_pair(c, b));
  }

  std::sort(a.begin(), a.end(), greater<pair<long,long> >());

  long ans = 0;
  for (int i = 0; i < a.size(); i++) {
    if (n == 0) {
      break;
    }

    if (n > a[i].second) {
      ans = ans + a[i].first * a[i].second;
      n = n - a[i].second;
    } else {
      ans = ans + a[i].first * n;
      break;
    }
  }

  cout << ans << "\n";

}


Measured memory_bytes: 6256
/* - - - - - - - - - - - - - - -
	User : 		VanishD
	problem :	[arc99C]
	Points : 	
- - - - - - - - - - - - - - - */
# include <bits/stdc++.h>
# define 	N 		710
# define 	ll 		long long
using namespace std;
const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
const ll  infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
int read(){
	int tmp = 0, fh = 1; char ch = getchar();
	while (ch < '0' || ch > '9'){ if (ch == '-') fh = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9'){ tmp = tmp * 10 + ch - '0'; ch = getchar(); }
	return tmp * fh;
}
int use[N], n, m, f[N][N], mp[N][N], num0[N], num1[N], id, flag;
void dfs(int x, int tag){
	if (tag == 0) 
		num0[id]++; else num1[id]++;
	use[x] = tag + 1;
	for (int i = 1; i <= n; i++){
		if (mp[x][i] == 0) continue;
		if (use[i] != 0){
			if (use[i] == tag + 1){
				flag = false; break;
			}
		}
		else dfs(i, tag ^ 1);
	}
}
int main(){
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read(), m = read();
	for (int i = 1; i <= n; i++)	
		for (int j = 1; j <= n; j++)
			if (i != j) mp[i][j] = true;
	for (int i = 1; i <= m; i++){
		int u = read(), v = read();
		mp[u][v] = mp[v][u] = false;
	}
	flag = true;
	for (int i = 1; i <= n; i++)
		if (!use[i]){
			id++;
			dfs(i, 0);
		}	
	if (flag == false){
		puts("-1");
		return 0;
	}
	f[0][0] = true;
	int tot = 0;
	for (int i = 1; i <= id; i++){
		int nex = tot + num0[i] + num1[i];
		for (int j = 0; j <= n; j++)
			if (f[tot][j] == true){
				if (j + num0[i] <= n) f[nex][j + num0[i]] = true;
				if (j + num1[i] <= n) f[nex][j + num1[i]] = true;
			}
		tot = nex;
	}
	int ans = inf;
	for (int i = 0; i <= n; i++)
		if (f[n][i] == true)
			ans = min(ans, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2);
	printf("%d\n", ans);
	return 0;
}


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

int main() {
    int A, B;
    cin >> A >> B;

    if(A >= 13)
        cout << B << endl;

    else if(A >= 6)
        cout << B / 2 << endl;

    else
        cout << 0 << endl;
    
    return 0;  

}

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

int main() {
	ios_base::sync_with_stdio( false );

	int A, B;
	cin >> A >> B;

	if( A == 1 ) {
		cout << (B == 2 ? 3 : 2) << endl;
	}
	else if( A == 2 ) {
		cout << (B == 1 ? 3 : 1) << endl;
	}
	else {
		cout << (B == 1 ? 2 : 1) << endl;
	}

	return 0;
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
		int N;
	cin >> N;
	vec(A)
		vec(B)
		vec(C)
	fx(N) {
		vecp(A)
	}
	fx(N) {
		vecp(B)
	}
	fx(N-1) {
		vecp(C)
	}
	int ans = 0;
	fx(N) {
		ans += B.at(A.at(x)-1);
		if (x+1<N&&A.at(x)+1==A.at(x+1)) {
			ans+= C.at(A.at(x)-1);
		}
	}
	ce(ans)
    return 0;
}



Measured memory_bytes: 256
/* Comparing Strings */

#include <iostream>
using namespace std;

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

  if(a<b){
    for(int i=0;i<b;i++){
      cout << a;
    }
  }
  else{
    for(int i=0;i<a;i++){
      cout << b;
    }
  }

  cout << endl;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var a, b int
	var s string
	fmt.Scan(&a, &b, &s)

	result := "No"
	if string(s[a]) == "-" {
		for i := 0; i < a; i++ {
			if string(s[i]) == "0" || string(s[i]) == "1" || string(s[i]) == "2" || string(s[i]) == "3" || string(s[i]) == "4" || string(s[i]) == "5" || string(s[i]) == "6" || string(s[i]) == "7" || string(s[i]) == "8" || string(s[i]) == "9" {
				result = "Yes"
			} else {
				result = "No"
				fmt.Println(result)
				return
			}
		}
		for i := a + 1; i < a+b; i++ {
			if string(s[i]) == "0" || string(s[i]) == "1" || string(s[i]) == "2" || string(s[i]) == "3" || string(s[i]) == "4" || string(s[i]) == "5" || string(s[i]) == "6" || string(s[i]) == "7" || string(s[i]) == "8" || string(s[i]) == "9" {
				result = "Yes"
			} else {
				result = "No"
				fmt.Println(result)
				return
			}
		}
	} else {
		result = "No"
		fmt.Println(result)
		return
	}
	fmt.Println(result)

}


Measured memory_bytes: 512
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int num, sum = 0;
	cin >> num;
	int high, low;
	for (int i = 0; i < num; i++) {
		cin >> low >> high;
		sum += (high - low + 1); 
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import static java.math.BigInteger.*;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		while(!"0".equals(str = br.readLine())){
			System.out.println(sum(str));
		}
	}

	private static int sum(String str) {
		BigInteger n = new BigInteger(str);
		if(n.compareTo(TEN) < 0){
			return Integer.parseInt(n.toString());
		}else{
			return Integer.parseInt(n.remainder(TEN).toString()) + sum(n.divide(TEN).toString());
		}
	}
}

Measured memory_bytes: 61636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int n;
map<int,int> cnt;
double dp[310][310][310];

double dfs(int a,int b,int c){
  if(dp[a][b][c]>=0) return dp[a][b][c];
  if(a==0 && b==0 && c==0) return 0.0;
  double ret=n;
  if(a-1>=0) ret+=a*dfs(a-1,b,c);
  if(b-1>=0) ret+=b*dfs(a+1,b-1,c);
  if(c-1>=0) ret+=c*dfs(a,b+1,c-1);
  ret/=(double)(a+b+c);
  return dp[a][b][c]=ret;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n){
      int a;
      cin>>a;
      cnt[a]++;
    }
    rep(i,310)rep(j,310)rep(k,310) dp[i][j][k]=-1;
    cout<<setprecision(30)<<dfs(cnt[1],cnt[2],cnt[3])<<endl;
}

Measured memory_bytes: 233088
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long h,w;
    cin >> h >> w;
    long long s = h*w;
    if(h==1||w==1){
        cout << 1 << endl;
        return 0;
    }else if(s%2!=0){
        cout << (s+1)/2 << endl;
    }else{
        cout << s/2 << endl;
    }
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  int n, r;
  cin >> n >> r;

  int ans = 0;
  if (n >= 10) {
    ans = r;
  } else {
    ans = 100 * (10 - n) + r;
  }

  cout << ans << ln;

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    double sum = 0;

    for (int i = 0; i < n; i++) {
      double x = sc.nextDouble();
      String u = sc.next();
      if (u.equals("JPY")) {
        sum += x;
      } else {
        sum += 380000.0 * x;
      }
    }

    System.out.println(sum);

  }
}

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


int main() 
{
    int n;
    cin >> n;
    vector<int> b(n);
    rep(i, n) cin>>b[i];
    int next = 1, ans = 0;
    rep(i,n)
    {
        if(b[i]==next)
        {
            next++;
        }
        else
        {
            ans += 1;
        }
    }
    if(ans==n)
        ans = -1;
    cout << ans << endl;



    return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<string>
#include<cstring>
using namespace std;
int main()
{
	int n,m,x[100]={0},y[100]={0},num[100]={0},count=0;
	cin>>n>>m;
	for (int i=1;i<=m;i++){
		cin>>x[i]>>y[i];
		num[x[i]]++;num[y[i]]++;
	}
	for (int i=1;i<=n;i++)
		if (num[i]==1){
			num[i]=0;
			count++;
			for (int j=1;j<=m;j++)
				if (x[j]==i){
					num[y[j]]--;
					i=0;
					x[j]=0;y[j]=0;
					break;
				}
				else if (y[j]==i){
					num[x[j]]--;
					x[j]=0;y[j]=0;
					i=0;
					break;
				}
		}
	cout<<count;
	return 0;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

bool cmp(pair<int, int> a, pair<int, int> b) {
  if (a.S == b.S) return a.F < b.F;
  return a.S < b.S;
}

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

  vector<pair<int, int>> vp;
  rep (i, m) {
    int a, b;
    cin >> a >> b;
    vp.eb(mp(a, b));
  }

  sort(all(vp), cmp);

  int ans = 0;
  int t = 1;
  rep (i, sz(vp)) {
    if (t <= vp[i].F) {
      ans++;
      t = vp[i].S;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 1400
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

const int maxn=1e3+10,dx[]={1,1,1,0,-1,-1,-1,0},dy[]={1,0,-1,-1,-1,0,1,1};
int n,m;
char s[maxn][maxn];

int main(){
	cin>>n>>m;
	for(int i=1;i<=n;++i)
		cin>>(s[i]+1);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=m;++j)
			if(s[i][j]=='.'){
				s[i][j]='0';
				for(int d=0;d<8;++d)
					if(s[i+dx[d]][j+dy[d]]=='#')
						++s[i][j];
			}
	for(int i=1;i<=n;++i)
		cout<<(s[i]+1)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, x=0, m=0;
  string s;
  cin >> n >> s;
  for(int i=0; i<n; i++){
    if(s[i]=='I'){
      x++;
      if(m<x)m=x;
    }else{
      x--;
    }
  }
  cout << m << endl;
  return 0;
}


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

using namespace std;


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if(fopen(".inp", "r")) freopen(".inp", "r", stdin);
    int x, y;
    cin >> x >> y;
    for(int i=0 ; i<=x ; ++i) {
        int k = i*2 + (x-i)*4;
        if(k==y) return cout << "Yes", 0;
    }
    cout << "No";

    return 0;
}


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

 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 
	char ch;
	cin >> ch;

	if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
		cout << "vowel\n";
	}
	else {
		cout << "consonant\n";
	}
 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll       long long
#define DS       pair<int, int>
#define READ(f)  freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

const int N = 30;
const int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    int n, m;
    cin >> n >> m;
    string x = "", y = "";
    for (int i = 0; i < m; i++) {
        x += (char)(n + '0');
    }
    for (int i = 0; i < n; i++) {
        y += (char)(m + '0');
    }
    if (x <= y) {
        cout << x << endl;
    } else {
        cout << y << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  long long i, j, n, ans = 1;
  bool p[1010];
  for(i = 0; i < 1010; ++i) p[i] = true;
  p[0] = p[1] = false;
  for(i = 2; i < 33; ++i) if(p[i]) for(j = i * 2; j < 1010; j += i) p[j] = false;
  scanf("%lld", &n);
  for(i = 2; i <= n; ++i) if(p[i]) {
    long long cnt = 0, tmp = n;
    while(tmp) cnt += tmp / i, tmp /= i;
    ans *= cnt + 1, ans %= 1000000007;
  }
  printf("%lld", ans); 
  return 0;
}

Measured memory_bytes: 128
def gcd(a, b):
    sm = min(a, b)
    la = max(a, b)
    if la % sm == 0:
        return sm
    else:
        return gcd(sm, la % sm)


N = int(input())
A = [int(input()) for _ in range(N)]

ans = 1
for a in A:
    ans = a * ans // gcd(a, ans)
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {

	  String ans="";
	  long sum = 0;
	  Scanner sc = new Scanner(System.in);

	  char[] charArray = sc.next().toCharArray();

	  for(int bit = 0; bit < Math.pow(2, charArray.length -1) ; bit++) {
		  ans = String.valueOf(charArray[0]);
		  for(int i = 0 ; i < charArray.length - 1 ;i++) {
			  if((1 & (bit >> i)) == 1) {
				 ans += ",";
			  }
			  ans += String.valueOf(charArray[i+1]);
		  }
		  String num[] = ans.split(",");
			  for(int i = 0; i < num.length;i++) {
				  sum += Long.valueOf(num[i]);
		  }
	  }
	  System.out.println(sum);
	  sc.close();

  }

}

Measured memory_bytes: 26068
import java.util.*;
public class Main
{
  	public static void main(String args[])
    {
      	Scanner sc = new Scanner(System.in);
      	int t = sc.nextInt();
      	int n = sc.nextInt();
      	if(t % n==0)
          	System.out.println(t/n);
     	else
          	System.out.println((t/n) + 1);
    }
}

Measured memory_bytes: 21332