akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  ll A,B;
  cin >> A >> B;
  cout << A*B <<endl;
    return 0;
}


Measured memory_bytes: 3612
using System;

namespace ConsoleApplication18
{
    class Program
    {
        static void Main(string[] args)
        {
            int H = 1;
            int W = 1;
            for ( int a = 0 ; a < 5; )
            {
            string[] str = Console.ReadLine().Split(' ');
            H = int.Parse(str[0]);
            W = int.Parse(str[1]);
                if (H == 0 && W == 0)
                {
                    break;
                }
                else
                {
                    for (int I = 0; I < H ; I++)
                    {
                        if (I == 0)
                        {
                            for (int i = 0; i < W; i++) 
                            {
                                Console.Write("#");
                            }
                        }
                        else if (I > 0 && I < H - 1)
                        {
                            Console.Write("#");
                            for (int i = 2; i < W; i++)
                            {
                                Console.Write(".");
                            }
                            Console.Write("#");
                        }
                        else if (I == H - 1)
                        {
                            for (int i = 0; i < W; i++)
                            {
                                Console.Write("#");
                            }
                            Console.WriteLine("");
                        }
                        
                        Console.WriteLine("");
                    }
                    
                } 
             }
        }
    }
}

Measured memory_bytes: 8744
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <time.h>
#include <complex>
using namespace std;
using ll=long long;
using pl  = pair<ll,ll>;
using pii  = pair<int,int>;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll A,B,C,D,E,F,G,H,L,N,M,P,Q,R,W,X,Z;
string S,T,U;
vector<ll> V(100007);

int main(){
  cin >> S >> T >> A >> B >> U ;
  X=0;
  if(S.size()!=U.size()){
    cout << A << " " << B-1 << endl;
    return 0;
  }
  rep(i,S.size()){
    if(S[i]!=U[i]){
      cout << A << " " << B-1 << endl;
      return 0;
    }
  }
  cout << A-1 << " " << B << endl;
  return 0;
}

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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  lli n, m;
  while (cin >> n >> m) {
    vector<pair<lli, lli>> v(n);
    cin >> v;
    sort(v.begin(), v.end());

    lli x = 0;
    each (i, v) {
      if (m == 0) break;
      lli y = min(m, i.second);
      x += y * i.first;
      m -= y;
    }
    cout << x << endl;
  }
  
  return 0;
}


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

int main(){
  char C;
  cin >> C;
  string A = "abcdefghijklmnopqrstuvwxyz";
  int j = 0;
  for(int i=0;i<26;i++){
    if(C==A.at(i)){
      j = i+1;
      break;
    }
  }
  cout << A.at(j);
}

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

int main()
{
    int unit_price;
    int sale_num;
    char ch;
    int count = 0;
    int sum = 0;
    int total_sale_num = 0;
    while(cin >> unit_price >> ch >> sale_num)
    {
        sum += unit_price * sale_num;
        total_sale_num += sale_num;
        count++;
    }
    cout << sum << endl;
    cout << round((double)total_sale_num / count) << endl;
    return 0;
}


Measured memory_bytes: 3340
//#pragma comment(linker, "/STACK:102400000,102400000")
//#include <initializer_list>
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <cassert>
//#include <unordered_map>
//#include <unordered_set>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define eps 1e-8
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define slla(n) scanf("%lld", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define DE(val) cout<<#val<<": "<<val<<endl;
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); repp(i,1,___T)

const int dx44[5] = { 0,-1,-1,1,1 };
const int dy44[5] = { 0,-1,1,-1,1 };

const int dx4[5] = { 0,-1,0,1,0 };
const int dy4[5] = { 0,0,1,0,-1 };
const int dx8[9] = { 0,-1,0,1,0,1,1,-1,-1 };
const int dy8[9] = { 0,0,1,0,-1,1,-1,1,-1 };
const int maxn = 2e5 + 50;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
ll po(ll a, ll b, ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } else { return gcd(b%a, a); } }
void YES() { puts("YES"); exit(0); }
void Yes() { puts("Yes");}// exit(0); }
void NO() { puts("NO"); exit(0); }
void No() { puts("No");}// exit(0); }
void one() { puts("-1"); exit(0); }

int n;

int cal(int x,int y)
{
    if(x%y==0)
    {
        return x/y;
    } else{
        return cal(x - max(x%y/(x/y+1),1)*(x/y+1),y);
    }
}

void solve()
{
    sa(n);
    int ans = 0;
    repp(i,1,n)
    {
        int x,y;
        sa(x),sa(y);
        ans ^= cal(x,y);
    }
    if(ans)
    {
        puts("Takahashi");
    }
    else
    {
        puts("Aoki");
    }
}

int main(){

    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

const int MOD = 1e9 + 7; // change if needed

struct Modint {
  ll val;
  
  Modint (ll _val = 0)
    : val(_val % MOD) {}

  Modint operator+ (Modint other) const {
    return Modint(val + other.val);
  }

  void operator+= (Modint other) {
    val += other.val;
    val %= MOD;
  }

  Modint operator- () const {
    return Modint(MOD - val);
  }

  Modint operator- (Modint other) const {
    return Modint(val + MOD - other.val);
  }

  void operator-= (Modint other) {
    val += MOD - other.val;
    val %= MOD;
  }

  Modint operator* (Modint other) const {
    return Modint(val * other.val);
  }

  void operator*= (Modint other) {
    val *= other.val;
    val %= MOD;
  }

  bool operator== (Modint other) const {
    return val == other.val;
  }

  bool operator!= (Modint other) const {
    return val != other.val;
  }
};

Modint exp (Modint a, ll k) {
  if (k == 0) {
    return Modint(1);
  } else if (k % 2 == 0) {
    Modint half = exp(a, k / 2);
    return half * half;
  } else {
    return a * exp(a, k - 1);
  }
}

Modint inv (Modint a) {
  return exp(a, MOD - 2);
}

ostream& operator<< (ostream& out, Modint p) {
  out << p.val;
  return out;
}

typedef long long ll;

ll gcd (ll p, ll q) {
  if (q == 0) return p;
  return gcd(q, p % q);
}

int main () {
  ll h, w, t;
  cin >> h >> w >> t;

  ll ex = gcd(t, h) * gcd(t, w); // # of independent cases
  h /= gcd(t, h);
  w /= gcd(t, w);

  ll clc = gcd(h, w);
  Modint ans = exp(Modint(2), clc) - Modint(2); // in these cases only one possibility
  ans += exp(Modint(2), h);
  ans += exp(Modint(2), w);
  ans -= Modint(1);

  ans = exp(ans, ex);
  cout << ans << endl;
}


Measured memory_bytes: 3580
n,l = map(int,input().split())
taste_list = list(map(lambda x:l+x-1, list(range(1,n+1))))
pre_sum = sum(taste_list)

min_sum = 10000000
n_taste_list = list(map(abs, taste_list))

for i in taste_list:
    if abs(min_sum) > abs(i):
        min_sum = i

print(sum(taste_list)-min_sum)

Measured memory_bytes: 3064
import heapq as hq

N, D, A = map(int,input().split())
m = []
for i in range(N):
    hq.heappush(m, tuple(map(int,input().split())))
ans = 0
dmg = 0; d = []
while m:
    X, H = m[0] # 
    if not d or (X <= d[0][0]):
        if dmg >= H:
            hq.heappop(m)
        else:
            k = (H - dmg + A - 1) // A
            ans += k
            dmg += k * A
            hq.heappush(d, (X + 2 * D, - k * A))
    else:
        dmg += d[0][1]
        hq.heappop(d)
    # print(dmg, m, d) #DB

print(ans)

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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

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

int n, m;
map<int, int> app;

int main() {
	scanf("%d", &n);
	fori(i, 0, n) {
		int cur;
		scanf("%d", &cur);
		app[cur]++;
	}
	scanf("%d", &m);
	fori(i, 0, m) {
		int cur;
		scanf("%d", &cur);
		if(app[cur] > 0) {
			app[cur]--;
		}
		else {
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	return 0;
}



Measured memory_bytes: 11648
import heapq as h
import sys

input=sys.stdin.readline

N,Q=map(int,input().split())
a=[0 for i in range(0,N-1)]
b=[0 for i in range(0,N-1)]
for i in range(0,N-1):
    a[i],b[i]=map(int,input().split())
p=[0 for i in range(0,Q)]
x=[0 for i in range(0,Q)]
for i in range(0,Q):
    p[i],x[i]=map(int,input().split())
hen=[[] for i in range(0,N+1)]
for i in range(0,N-1):
    hen[a[i]].append(b[i])
    hen[b[i]].append(a[i])
subscore=[0 for i in range(0,N+1)]
for i in range(0,Q):
    subscore[p[i]]+=x[i]

ans=[0 for i in range(0,N+1)]
flag=[0 for i in range(0,N+1)]
q=[]
q.append(1)
h.heapify(q)
sub=[]
h.heapify(sub)
while q!=[]:
    while q!=[]:
        x=h.heappop(q)
        ans[x]+=subscore[x]
        flag[x]=1
        for p in hen[x]:
            if flag[p]==0:
                h.heappush(sub,p)
                ans[p]=ans[x]
        if q==[]:
            q=sub
            sub=[]
            h.heapify(sub)
            break
ans[0]=-1
ans.remove(-1)
print(*ans)

Measured memory_bytes: 103684
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        String AtCoder = sc.next();
        String s = sc.next();
        String Contest = sc.next();

        String AsC = AtCoder.substring(0, 1) + s.substring(0, 1) + Contest.substring(0, 1);

        System.out.println(AsC);

    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<52;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

int n;

int main(){
	cin>>n;
	ll ans=1;
	for(int i=1;i<=n;i++) (ans*=i)%=mod;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int a, b, c, d;
    
    scanf("%1d%1d%1d%1d", &a, &b, &c, &d);
    
    if(a==b && b==c) printf("Yes");
    else if(b==c && c==d) printf("Yes");
    else printf("No");
}

Measured memory_bytes: 128
#include <stdio.h>
 
int main(void){
    int a,b;
   char op;
        while(1){
          scanf("%d %c %d",&a,&op,&b);
           if( op =='?')
               break;
           else if( op == '+')
               printf("%d\n",a+b);
           else if( op == '-')
               printf("%d\n",a-b);
           else if( op == '*')
               printf("%d\n",a*b);
           else if( op == '/')
               printf("%d\n",a/b);
           }
              return 0;
}


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

using namespace std;

#define MOD 1000000007
#define ll long long int
#define ld long double
#define pb push_back
#define mkp make_pair
#define pii pair<int, int> 
#define pll pair<long long int, long long int>
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define fi first
#define sc second
#define deb 0

int C[1000000], G[1000000];

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

	int n, m, i, j, k;
	cin >> n >> m;
	while (m--) {
		cin >> i >> j;
		if (i == 1) {
			C[j] = 1;
		}
		if (j == 1) {
			C[i] == 1;
		}
		if (i == n) {
			G[j] = 1;
		}
		if (j == n) {
			G[i] = 1;
		}
	}

	for (i = 2; i < n; ++i) {
		if (C[i] && G[i]) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;

	return 0;
}

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

int main() {
  string s;
  cin >> s;
  deque<char> d;
  for(int i=0;i<s.size();i++){
    d.push_back((char)s.at(i));
  }
  
  int q;
  cin >> q;
  bool flip = false;
  
  for(int i=0;i<q;i++){
    int t;
    cin >> t;
    if(t==1) {
      flip = !flip;
    }else{
      int f;
      char c;
      cin >> f >> c;
      if(flip) f = 3-f;
      if(f == 1){
        d.push_front(c);
      }else{
        d.push_back(c);
      }
    }
  }
  
  string ans="";
  for(auto c : d){
    ans += c;
  }
  if(flip){
    reverse(ans.begin(),ans.end());
  }
  
  cout << ans << endl;
  
  return(0);
}

Measured memory_bytes: 4256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;

signed main() {
    int n;
    cin >> n;
    int a[n];
    rep (i, 0, n) cin >> a[i];
    int b[n] = {};
    rep (i, 0, n) {
        if (i % 2 == 1) {
            b[0] -= a[i];
        } else {
            b[0] += a[i];
        }
    }
    b[0] /= 2;
    rep (i, 1, n) { b[i] = a[i - 1] - b[i - 1]; }
    rep (i, 0, n) { cout << 2 * b[i] << " "; }
    cout << "\n";
}

Measured memory_bytes: 5128
#include <stdio.h>
int main(){
  long long int k,i,n=0;
  scanf("%lld",&k);
  
  for(i=1; i<=10000000;i++){
    n=10*n+7;
    n=n%k;
    if(n==0){
      printf("%lld",i);
      return 0;
    }
  }
  printf("-1");
  return 0;
}


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

int main()
{
	int size;
	cin >> size;
	int nums[size];
	for (int i=1; i<=size; i++)
	{
		cin >> nums[size-i];
	}
	for (int i=0; i<size-1; i++)
	{
		cout << nums[i] << ' ';
	}
	cout << nums[size-1] << endl;
	return 0;
}

Measured memory_bytes: 3076
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        String t = sc.next();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < n; i++) {
            sb.append(s.substring(i, i+1) + t.substring(i, i+1));
        }
        System.out.println(sb.toString());
        sc.close();

    }

}


Measured memory_bytes: 22868
// Date: 2020-03-28

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define IO freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout)
#define FIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i, a, b) for(int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for(int i = int(b); i >= int(a); --i)
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(),(x).end()
#define D(x) cout << #x << " = " << x << endl;
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {LL a=1; while(y){ if(y&1) a=a*x%MOD; x=x*x%MOD; y>>=1; } return a;}

int a[N];
int main() {
    FIO;
    int k, n;
    cin >> k >> n;
    rep(i, 1, n) cin >> a[i];
    int ans = min(a[n]-a[1], k-(a[2]-a[1]));
    chkmin(ans, k-(a[n]-a[n-1]));
    rep(i, 2, n-1) {
        chkmin(ans, k-(a[i+1]-a[i]));
        chkmin(ans, k-(a[i]-a[i-1]));
        chkmin(ans, a[i]-a[1]+a[n]-a[1]);
        chkmin(ans, a[n]-a[i]+a[n]-a[1]);
    }
    cout << ans;

    return 0;
}

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

double ceil(double);

int main() {
  int n; cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++) cin >> p[i];
  int ans =0;
  for (int i=0; i < n-2; i++) {
    if (p[i] < p[i+1] && p[i+1] < p[i+2]) ans++;
    else if (p[i] > p[i+1] && p[i+1] > p[i+2]) ans++;
  }
  cout << ans << endl;
  return 0;

}

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

public class Main {
	char[][] map;
	int height;
	int width;
	class Pair {
		int x, y;
		Pair(int x, int y){
			this.x = x;
			this.y = y;
		}
		@Override
		public String toString(){
			return "(" + x + ", " + y + ")";
		}
	}
	public void bfs(boolean[][] used, int h, int w){
		Queue<Pair> queue = new ArrayDeque<Pair>();
		queue.add(new Pair(w, h));
		while( queue.size() > 0 ){
			Pair p = queue.poll();
			for(int i = -1; i <= 1; i++){
				for(int j = -1; j <= 1; j++){
					if( i*j != 0 || (i == 0 && j == 0) ){
						continue;
					}
					int x = p.x+j;
					int y = p.y+i;
					if( x < 0 || x >= width || y < 0 || y >= height ){
						continue;
					}
					if( used[y][x] || (map[y][x] != map[h][w]) ){
						continue;
					}
					used[y][x] = true;
					queue.add(new Pair(x, y));
				}
			}
		//	System.out.println(queue);
		}
	}
	public void dfs(boolean[][] used, int h, int w){
		for(int i = -1; i <= 1; i++){
			for(int j = -1; j <= 1; j++){
				if( i*j != 0 || (i==0 && j==0) ){
					continue;
				}
				int x = w+j;
				int y = h+i;
				if( x < 0 || x >= width || y < 0 || y >= height ){
					continue;
				}
				if( used[y][x] || (map[h][w] != map[y][x]) ){
					continue;
				}
				used[y][x] = true;
				dfs(used, y, x);
			}
		}
	}
	public void solve() throws IOException {
		height = 0;
		width = 0;
		while( true ){
			height = nextInt();
			width = nextInt();
			if( height == 0 && width == 0 ){
				break;
			}
			map = new char[height][width];
			for(int i = 0; i < height; i++){
				map[i] = nextToken().toCharArray();
			}
			boolean[][] used = new boolean[height][width];
			int ans = 0;
			for(int i = 0; i < height; i++){
				for(int j = 0; j < width; j++){
					if( !used[i][j] ){
						ans++;
						used[i][j] = true;
						bfs(used, i, j);
					}
				}
			}
			writer.println(ans);
		}
		writer.flush();
	}
	public static void main(String[] args){
		new Main().run();
	}
	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;
	
	public void run() {
		try{
			reader = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch(Exception e){
			e.printStackTrace();
			System.exit(1);
		}
	}
	public String nextToken() throws IOException {
		if( tokenizer == null || !tokenizer.hasMoreTokens() ){
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
}

Measured memory_bytes: 24264
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) ((int)(a).size())
typedef long long int64;
const int maxn = 200009;
int F[maxn << 2], G[maxn << 2];
void chmin(int &a,int b){
  if(a==0)a=b;
  else a=min(a,b);
}
void upd(int rt, int l, int r, int ll, int rr, int v, int A[]) {
  if (ll <= l && rr >= r) {
    chmin(A[rt], v);
    return;
  }
  if (A[rt]) {
    chmin(A[rt << 1], A[rt]);
    chmin(A[rt << 1 | 1], A[rt]);
    A[rt] = 0;
  }
  int mid = (l + r) >> 1;
  if (ll <= mid) upd(rt << 1, l, mid, ll, rr, v, A);
  if (rr > mid) upd(rt << 1 | 1, mid + 1, r, ll, rr, v, A);
}
int query(int rt, int l, int r, int p, int A[]) {
  if (l == r) {
    return A[rt];
  }
  int mid = (l + r) >> 1;
  if (A[rt]) {
    chmin(A[rt << 1 | 1], A[rt]);
    chmin(A[rt << 1], A[rt]);
    A[rt] = 0;
  }
  if (p <= mid) return query(rt << 1, l, mid, p, A);
  return query(rt << 1 | 1, mid + 1, r, p, A);
}
int main() {
#ifdef LOCAL
  freopen(".a.in", "r", stdin);
#endif
  ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);
  int n,q;
  cin >> n >> q;
  int64 res = 1ll * (n - 2) * (n - 2);
  upd(1, 2, n, 2, n, n, G);
  upd(1, 2, n, 2, n, n, F);
  while (q--) {
    int op, x;
    cin >> op >> x;
    if (op == 1) {
      int it = query(1, 2, n, x, G);
      res -= it - 2;
      if (it != 2) upd(1, 2, n, 2, it - 1, x, F);
    } else {
      int it = query(1, 2, n, x, F);
      res -= it - 2;
      if (it != 2) upd(1, 2, n, 2, it - 1, x, G);
    }
  }
  cout << res;
  return 0;
}
//2020.09.19 20:35:48


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

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

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
const long long INF = 1LL << 60;

// prime factorization (素因数分解)
// key: value of prime factor
// value: number of prime factor
map<ll, ll> prime_factorization(ll n) {
  std::map<ll, ll> prime_factors;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      prime_factors[i]++;
      n /= i;
    }
  }
  if (n != 1)
    prime_factors[n] = 1;
  return prime_factors;
}

vector<map<ll, ll>> m(51);

// 階乗の素因数分解
void init() {
  REP(i, 51) {
    m[i] = m[i - 1];
    auto primes = prime_factorization(i);
    FORm(it, primes) {
      m[i][it->first] += it->second;
    }
  }
}

ll combination(ll n, ll k) {
  auto mp = m[n];
  FORm(it, m[k]) {
    mp[it->first] -= it->second;
  }
  FORm(it, m[n - k]) {
    mp[it->first] -= it->second;
  }
  ll ans = 1;
  FORm(it, mp) {
    rep(i, it->second) {
      ans *= it->first;
    }
  }
  return ans;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(6);

  ll n, a, b;
  cin >> n >> a >> b;

  vll v(n);
  rep(i, n) {
    cin >> v[i];
  }
  sort(all(v), greater<ll>());

  ld max_ave = 0;
  ll ptn = 0;
  for (ll i = a; i <= b; i++) {
    ld value = accumulate(v.begin(), v.begin() + i, 0ll);
    chmax(max_ave, value / i);
  }

  init();

  for (ll i = a; i <= b; i++) {
    ld value = accumulate(v.begin(), v.begin() + i, 0ll);
    if (value / i >= max_ave) {
      ll end_val = v[i - 1];
      ll l = -1;
      ll r = -1;
      rep(i, n) {
        if (v[i] == end_val) {
          if (l == -1) {
            l = i;
          }
          r = i;
        }
      }
      ll comb_n = r - l + 1;
      ll comb_c = i - l;
      ptn += combination(comb_n, comb_c);
    }
  }

  cout << max_ave << endl;
  cout << ptn << endl;

  return 0;
}


Measured memory_bytes: 256
def main():
  s=input()
  #while s%10==0:
  #    s//=10
  #s=9**100
  #s=str(s)
  lens=len(s)

  d=int(s[0])
  p=11-int(s[0])

  for c in s[1:]:
      j=int(c)
      a=min(d+j,p+j)
      b=min(d+11-j,p+9-j)
      d,p=a,b

  print(min(d,p))

if __name__ == '__main__':
    main()

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

using namespace std;

const int dx[] = {0,0,1,-1};
const int dy[] = {1,-1,0,0};

int w,h;

#define MAX 9999

int check(int maps[21][21],int x,int y,int cnt)
{
  //cerr<<x<<" "<<y<<" "<<cnt<<endl;

  //4方向に動かす
  if(cnt>10)
    return MAX;

  int ans=MAX;

  for(int st=0;st<4;st++)
    {
      int nx=x+dx[st];
      int ny=y+dy[st];
      if(nx<0 || nx>=h || ny<0 || ny>=w ||
         maps[nx][ny]==1)
        continue;

      while(nx>=0 && nx<h && ny>=0 && ny<w )
        {
          if(maps[nx][ny]==3)
            {
              return cnt;

              ans=min(ans,cnt);
              break;
            }
          if(maps[nx][ny]==1)
            {
              int nmap[21][21];
              for(int i=0;i<21;i++)
                for(int j=0;j<21;j++)
                  {
                    nmap[i][j]=maps[i][j];
                  }
              nmap[nx][ny]=0;

              ans=min(ans,check(nmap,nx-dx[st],ny-dy[st],cnt+1));
              break;
            }
          nx+=dx[st];
          ny+=dy[st];
        }
    }
  return ans;
}


int main()
{
  for(;cin>>w>>h,w;)
    {
      int x,y;

      int maps[21][21];
      for(int i=0;i<h;i++)
        for(int j=0;j<w;j++)
          {
            cin>>maps[i][j];
            if(maps[i][j]==2)
              {
                x=i;
                y=j;
              }

          }
      int ans=check(maps,x,y,1);
      if(ans==MAX)
        ans=-1;
      cout<<ans<<endl;
    }

}

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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}

vector<int> adj[100005];
int indeg[100005], dp[100005];

int helper(int node){

    if(dp[node] != -1)
        return dp[node];

    int best = 0;
    for(int nx : adj[node])
        best = max(best, 1 + helper(nx));

    dp[node] = best;

    return best;

}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, m, a, b; cin >> n >> m;

    for(int i = 0; i < m; ++i){
        cin >> a >> b;
        ++indeg[b];
        adj[a].push_back(b);
    }

    for(int i = 0; i <= n; ++i)
        dp[i] = -1;

    int best = 0;

    for(int i = 1; i <= n; ++i){
        if(indeg[i] != 0) continue;
        best = max(best, helper(i));
    }

    cout << best << "\n";

    return 0;

}


Measured memory_bytes: 11264
package main

import "fmt"

func main() {
	arr := make([]int, 2)
	for i := 0; i < 2; i++ {

		if _, err := fmt.Scan(&arr[i]); err != nil {
			panic(err)
		}
	}

	if arr[1]%2 == 0 {

		if arr[1] >= 2*arr[0] && arr[1] <= arr[0]*4 {

			fmt.Print("Yes")
		} else {
			fmt.Print("No")
		}

	} else {
		fmt.Print("No")
	}

}


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

#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define MAXN 10005
#define MAXM 100005
#define pi 3.14159265359

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpii;
typedef long long ll;
typedef priority_queue<int> pqi;
typedef priority_queue<pii, vpii, greater<pii> > dij;

ll H, W;

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

	cin >> H >> W;

	if(H == 1 || W == 1)
		cout << 1 << "\n";
	else{
		ll ans = (H*W+1)/2;
		cout << ans << "\n";
	}

	return 0;		
}


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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define endl "\n"
#define all(v) v.begin(), v.end()
#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 1e5 + 5;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    //-freopen("input.txt", "r", stdin);
  #endif // LOCAL
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while (1) {
    c -= b;
    if (c <= 0) return cout << "Yes" << endl,0;
    a -= d;
    if (a <= 0) return cout << "No" << endl,0;
  }
  return 0;
}



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

bool bingo(bool mat[3][3]) {
  int i;
  rep (i, 3) {
    if (mat[i][0] && mat[i][1] && mat[i][2])
      return true;
    if (mat[0][i] && mat[1][i] && mat[2][i])
      return true;
  }
  if (mat[0][0] && mat[1][1] && mat[2][2])
    return true;
  if (mat[0][2] && mat[1][1] && mat[2][0])
    return true;
  return false;
}
int main() {
  int a[3][3], i, j, k;
  bool mat[3][3] = {false};
  rep (i, 3) {
    rep (j, 3)
      cin >> a[i][j];
  }
  int N; cin >> N;
  vector<int> b(N);
  rep (i, N)
    cin >> b.at(i);
  rep (i, N) {
    rep (j, 3) {
      rep (k, 3) {
        if (a[j][k] == b.at(i))
          mat[j][k] = true;
      }
    }
  }

  cout << (bingo(mat) ? "Yes" : "No") << endl;
  return 0;
}


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

int main(void) {
    int N, x = 0, ans = 0;
    string S;
    cin >> N >> S;

    for(char s : S) {
        if(s == 'I') {
            ans = max(++x, ans);
        }
        else {
            x--;
        }
    }

    cout << ans << endl;
    return 0;
}

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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> p(N);
  for(int i=0;i<N;i++){
    cin >> p.at(i);
  }
  sort(p.begin(),p.end());
  int sum=0;
  for(int i=0;i<K;i++){
    sum+=p.at(i);
  }
  cout << sum <<endl;
}

Measured memory_bytes: 3532
#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];
  }
  int m = *max_element(a.begin(), a.end());
  vector<int> b(n);
  copy(a.begin(), a.end(), b.begin());
  sort(b.begin(), b.end());
  int l = b[n - 2];
  for(int i = 0; i < n; i++){
    if(a[i] != m){
      cout << m << endl;
    }else{
      cout << l << endl;
    }
  }
}

Measured memory_bytes: 4784
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) < (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;
using unit= unsigned;
using ull = unsigned long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vvi = vector<vi>;
using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T>bool chmax(T &a, const T &b){ if (a<b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if (b<a){ a = b; return 1; } return 0; }
template<class T>T gcd(T a, T b){ if (b==0){ return a; }else{ return gcd(b, a%b); }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
constexpr double eps = 1e-10;
constexpr int inf = INT_MAX / 2;
constexpr ll infl = 1LL << 60;

void _main() {
  int N, M;
  cin >> N >> M;
  priority_queue<P> que;
  rep(i, 0, N) {
    int a; cin >> a;
    que.push({a, 1});
  }
  rep(i, 0, M) {
    int b, c; cin >> b >> c;
    que.push({c, b});
  }

  ll ans = 0;
  rep(i, 0, N) {
    P p = que.top(); que.pop();
    ans += p.fi;
    --p.se;
    if (p.se != 0) {
      que.push(p);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  int X, N;
  cin >> X >> N;
  vector <int> d(102);  //現れたら1
  rep(i,N){
    int p;
    cin >> p;
    d[p] = 1;
  }
  P ans(999, -1);  //差分と位置のペア
  for (int i = 0; i <= 101; i++){
    if (d[i] == 1) continue;
    int dif = abs(X-i);
    ans = min(ans, P(dif, i));
  }
  cout << ans.second << endl;

  return 0;
}


Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>
#include<string>
#define int long long
using namespace std;
signed main() {
	int n, p = -1; cin >> n;
	int x[105], y[105], h[105];
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> h[i];
		if (h[i] != 0)p = i;
	}
	for (int X = 0; X <= 100; X++) {
		for (int Y = 0; Y <= 100; Y++) {
			int H = abs(x[p] - X) + abs(y[p] - Y) + h[p];
			if (H <= 0)continue;
			bool flag = 1;
			for (int i = 0; i < n; i++)
				if (h[i] != max(H - abs(X - x[i]) - abs(Y - y[i]), (int)0))flag = 0;
			if (flag) {
				cout << X << ' ' << Y << ' ' << H << endl;
				cin >> n;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include <memory.h>
int main(void){
int card[4][14],have,num,i=0,j=0;
char id;
memset(card,0,sizeof(card));
scanf("%d",&have);
for(i=0;i<have;i++){
scanf("%*c%c %d",&id,&num);
if(id=='S')
        card[0][num]=1;
else if(id=='H')
        card[1][num]=1;
else if(id=='C')
        card[2][num]=1;
else
        card[3][num]=1;
}


for(i=0;i<=3;i++){
 for(j=1;j<=13;j++){
if(i==0) id='S';
if(i==1) id='H';
if(i==2) id='C';
if(i==3) id='D';
  if(card[i][j]==0) printf("%c %d\n",id,j);
 }
}

}



Measured memory_bytes: 2068
#AGC031 A Colorful Subsequence
# Answer
N = int(input())
S = input()
alpha = [0]*26
mod = 10**9+7

for n in S:
    num = ord(n)-97
    alpha[num] += 1
    
ans = 1
for i in range(26):
    ans *= (alpha[i]+1)

ans %= mod
print(ans-1)

Measured memory_bytes: 3188
class Dice
  V={N:0,E:1,S:2,W:3}
  def initialize(label)
    @label=label
    @top=1
    @around=[5,3,2,4] # U R D L
    # 右に転がす場合
    # 対角値(レフト,idx3)が上面(top)になる
    # 右(idx1)にもともと上面だった値（top）が入る
    # その対角面(右,idx1)には対角値（合計7になる値）が入る
    # 1 => [5,3,2,4]
    # 4 => [5,1,2,6]
    # 下に転がす場合
    # 1 => [5,3,2,4]
    # 5 => [6,3,1,4]
  end
  def move(v)
    # v = U,R,D,L
    #     N,E,S,W
    #     0,1,2,3
    vn=V[v.to_sym] # 移動方向のインデックス数値
    rn=(vn+2)%4 # 対角のインデックス数値（2を足す。4を超えていた場合は剰余）
    @top,@around[vn]=@around[rn],@top
    @around[rn]=7-@around[vn]
  end
  def puts_top
    puts @label[@top-1]
  end
end
def code_run
  label=$stdin.gets.split.map(&:to_i)
  vector=$stdin.gets.chomp
  d=Dice.new(label)
  vector.chars do |c|
    d.move(c)
  end
  d.puts_top
end

code_run


Measured memory_bytes: 6872
#include<stdio.h>
#include<math.h>
#define N 100

float inf = INFINITY;

int minof(int x, int y){
  if(x < y)return (x);
  else return (y);
}

int main(){
  int n, i, k, j, l;
  int p[N+1];
  int m[N+1][N+1];

  scanf("%d", &n);

  for(i = 1; i <= n; i++){
    scanf("%d%d", &p[i-1], &p[i]);
  }

  for(i = 0; i <= n; i ++){
    m[i][i] = 0;
  }

  for(l = 2; l <= n; l++){
    for(i = 1; i <= n - l + 1; i++){
      j = i + l - 1;
      m[i][j] = 1<<21; // 2^21を代入
      for(k = i; k <= j - 1; k++){
        m[i][j] = minof(m[i][j], m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j]);
      }
    }
  }

  printf("%d\n", m[1][n]);
  return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define ll long long 
#define fi first
#define se second

using namespace std;

int n;
string t; 
char f; 

void flsh() {
    cout << endl;
}

int main() {
    cin >> n;
    cout << "?";
    for (int i = 1; i <= n; i++) 
        cout << ' ' << i;
    flsh();

    cin >> t;
    f = t[0];
    int st = 1, dr = n + 1, mid;
    while (st + 1 < dr) {
        mid = (st + dr) / 2;
        cout << "?";
        for (int i = mid; i < mid + n; i++) 
            cout << ' ' << i;
        flsh();

        cin >> t;
        if (t[0] == f) 
            st = mid;
        else dr = mid;
    }

    string ans = "";
    for (int i = 1; i <= 2 * n; i++) {
        cout << "? " << i;
        if (i >= dr + n - 1 || i < dr) {
            for (int j = dr; j < dr + n - 1; j++) 
                cout << ' ' << j;
        }
        else {
            for (int j = 1; j <= 2 * n; j++)
                if (j >= dr + n || j < dr - 1)
                    cout << ' ' << j;
        }
        flsh();
        
        cin >> t;
        ans += t[0];
    }

    cout << "! " +  ans;
    flsh();
    
    return 0;
}

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



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


    long long ans = N-1;
    for(long long i = 2; i*i <= N; ++i){
        if( N%i == 0){
            long long m = i-1;
            if( N/i == N%m ) ans += m;
            m = N/i-1;
            if( i == N%m ) ans += m;
        }
    }
    if( N == 2 ) cout << 0 << endl;
    else cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main() {
    char S[101];
    long K;
    scanf("%s%ld", S, &K);
 
    for (int i = 0; ; i++) {
        if (S[i] != '1' || i == K - 1) {
            printf("%c\n", S[i]);
            return 0;
        }
    }
}

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

int main() {
    int n;
    cin >> n;
    bool a[4][14];
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 14; j++) {
            a[i][j] = 0;
        }
    }
    char m, M;
    int k;
    for (int i = 0; i < n; i++){
        cin >> m >> k;
        if (m == 'S') a[0][k] = 1;
        if (m == 'H') a[1][k] = 1;
        if (m == 'C') a[2][k] = 1;
        if (m == 'D') a[3][k] = 1;
    }
    for (int i = 0; i < 4; i++){
        for (int j = 1; j < 14; j++){
            if (a[i][j] == 0){
                if (i == 0) M = 'S';
                if (i == 1) M = 'H';
                if (i == 2) M = 'C';
                if (i == 3) M = 'D';
                cout << M << " " << j << "\n";
            }
        }
    }

    return 0;
}

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


int main() {
    int a,b,k;
    cin >> a >> b >> k;
    int min_value = min(a,b);
    int memo = 0;
    vector<int> lcd;
    rep(i,min_value+1){
        if(a%(i+1)==0 && b%(i+1) == 0)lcd.push_back(i+1);
    }
    sort(lcd.begin(),lcd.end(),greater<int>());
    cout << lcd[k-1] << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <iostream>
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <numeric>
#include <vector>
#include <cmath>
using namespace std;


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

   double arr[n] ;
   int sum =0;
   for(int x=0; x<n; x++) {
    int bruh;
    cin>> bruh;
    arr[x] = bruh;
    sum += bruh;
   }
   int count = 0;
   double ratio = 1.0/(4*m);
 //  cout << ratio << endl;
   for(int x=0; x<n; x++){
    double result = arr[x]/sum * 1.0;
//        cout << result << endl;
    if(result>=ratio){
  //      cout << result << endl;
        count++;
    }

   }

   if(count >=m){
    cout << "Yes" << endl;
   }else if(count< m){
    cout << "No" << endl;
   }


}


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

int biscuit(int a[3]){ 
  int output;
  output = (a[2]/ a[0]) * a[1];
  return output;
}

int main(){
  int l, i = 0, a[3];
  while(std::cin >> l){
    a[i] = l;
    i++;
  }
  std::cout <<  biscuit(a) << std::endl ;
  return 0;
}


Measured memory_bytes: 256
using System;

namespace ABC121
{
    class A
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            int H = int.Parse(input[0]);
            int W = int.Parse(input[1]);

            input = Console.ReadLine().Split();
            int h = int.Parse(input[0]);
            int w = int.Parse(input[1]);

            Console.WriteLine((H * W) - (h * W) - ((H - h) * w));
        }
    }
}


Measured memory_bytes: 13140
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var sw = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray();
            Console.WriteLine(sw[0] > sw[1] ? "safe" : "unsafe");
        }
    }
}

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

int main(){
  int E,Y;
  cin>>E>>Y;

  int wa[4]={44,14,63,28};

  if(E == 0){
    if(1989<=Y)
      cout<<'H'<<Y-1989+1<<endl;
    else if(1926<=Y)
      cout<<'S'<<Y-1926+1<<endl;
    else if(1912<=Y)
      cout<<'T'<<Y-1912+1<<endl;
    else
      cout<<'M'<<Y-1868+1<<endl;
  }
  else{
    int year=Y-1;
    for(int i=0; i<E-1; i++){
      year+=wa[i];
    }
    cout<<year+1868<<endl;
  }
  return 0;
}

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

int main()
{
	int i;
	int count[26]={0};
	string ss,ss2;

	while(!cin.eof())
	{
		getline(cin,ss2);

		ss = ss + ss2 ;

	}

	for(i=0;i<(int)ss.size();i++)
	{
		if(((int)ss[i] >=65)&&((int)ss[i]<=90))
		{
			ss[i] = ss[i] + 32;
		}

		if(((int)ss[i] >=97)&&((int)ss[i]<=122))
		{
			count[((int)ss[i]-97)]++;
		}
	}
	
	for(i=0;i<26;i++)
	{
		cout << (char)(97+i) << " : " << count[0+i] << endl ; 
	
	}
	return 0;
}

Measured memory_bytes: 1188
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

bool is(ll x, ll y, string a, string b){
    if((y-x)&1)return a == b;
    else return a != b;
}
int main(){
    ll n;
    string l, r;
    cin >> n;
    ll left = 0, right = n-1;
    cout << left << endl << flush;
    cin >> l;
    cout << right << endl << flush;
    cin >> r;
    if(l=="Vacant" || r=="Vacant")return 0;
    ll in;
    left++;
    rep(i, 18){
        in = (right + left)/2;
        cout << in << endl << flush;
        string ins;
        cin >> ins;
        if(ins=="Vacant")return 0;
        if(is(left, in-1, ins, l))right=in-1, r=ins;
        else left=in+1, l=ins;
    }
    return 0;
}

Measured memory_bytes: 852
#pragma GCC optimize("Ofast")
#include  "bits/stdc++.h"
using namespace std;
#define I_AM_SPEED  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define printclock  cerr <<"Time : "<<(double)clock()/(double)CLOCKS_PER_SEC<<" sec\n";
#define mp(a , b)   make_pair(a , b)
#define eb(a)       emplace_back(a)
#define SZ(n)      ((int)(n).size())
#define all(n)     (n).begin(), (n).end()
#define anal         '\n'
#define mod 1000000007
#define fst first
#define sec second
#define pr(n) cerr << n  << " ";
//const double PI = acos(-1.0);
typedef long long ll;
typedef unsigned long long ull;

//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
  


//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
      
int main(){
I_AM_SPEED;
#ifndef ONLINE_JUDGE  
        freopen("input.in", "r", stdin);
        freopen("output.in", "w", stdout);
#endif 

//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
      
      int n;
      cin >> n;
      cout << n*n << anal;


//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
//printclock; 
return  0 ;      
}        



      

Measured memory_bytes: 3640
#include<stdio.h>
int main(void){
  int n;
  scanf("%d",&n);
  switch(n%10){
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:printf("hon"); break;
    case 0:
    case 1:
    case 6:
    case 8:printf("pon"); break;
    case 3:printf("bon");

  }
  return 0;
}

Measured memory_bytes: 1688
#include<stdio.h>

int main(){
    int a,b,op,answer,i;
    for(i=1;i<20000;i++){
        scanf("%d %s %d",&a,&op,&b);
        if(op=='+'){
            answer=a+b;
        }else if(op=='-'){
            answer=a-b;
        }else if(op=='*'){
            answer=a*b;
        }else if(op=='/'){
            answer=a/b;
        }else{
            exit(0);
        }
        printf("%d\n",answer);
    }
}


Measured memory_bytes: 2052