akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

typedef struct{
  char suit;
  int val;
}Card;

Card L[MAX/2 + 2], R[MAX/2 + 2];

void merge(Card *, int, int, int, int);
void mergeSort(Card *, int, int, int);
int partition(Card *, int, int, int);
void quickSort(Card *, int, int, int);

int main(){
  int n = 0, v = 0;
  int i = 0;
  Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%s %d",S,&v);
    A[i].suit = B[i].suit = S[0];
    A[i].val = B[i].val = v;
  }

  mergeSort(A, n, 0, n);
  quickSort(B, n, 0, n-1);

  for(i = 0; i < n; i++){
    /*compare with merge and quick*/
    if(A[i].suit != B[i].suit)stable = 0;
  }

  if(stable == 1)printf("Stable\n");
  else printf("Not stable\n");
  
  for(i = 0; i < n; i++){
    printf("%c %d\n",B[i].suit,B[i].val);
  }
  
  return 0;
}

void merge(Card *A, int n, int left, int mid, int right){
  int i = 0, j = 0, k = 0;
  int n1 = mid - left;
  int n2 = right - mid;

  for(i = 0; i < n1; i++){
    
    L[i] = A[left + i];
    
  }
  for(i = 0; i < n2; i++){
    
    R[i] = A[mid + i];
    
  }

  L[n1].val = R[n2].val = SENTINEL;

  i = 0;

  for(k = left; k < right; k++){
    
    if(L[i].val <= R[j].val)A[k] = L[i++];
    else A[k] = R[j++];
    
  }
}

void mergeSort(Card *A, int n, int left, int right){
  int mid = 0;

  if(left+1 < right){
    
    mid = (left + right) / 2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
    
  }
}

int partition(Card *A, int n, int p, int r){
  int i = 0, j = 0;
  Card t, x;

  x = A[r];
  i = p-1;
  for(j = p; j < r; j++){
    if(A[j].val <= x.val){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i + 1];
  A[i + 1] = A[r];
  A[r] = t;

  return i + 1;
}

void quickSort(Card *A, int n, int p, int r){
  int q = 0;

  if(p < r){
    q = partition(A, n, p, r);
    quickSort(A, n, p, q-1);
    quickSort(A, n, q+1, r);
  }
}



Measured memory_bytes: 4044
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const long long MOD = 1000000007;


const int MAX = int(1e7)+5;

long long fac[MAX], finv[MAX], inv[MAX];

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

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

template< typename T >
T mod_pow(T x, T n, const T &p) {
  T ret = 1;
  while(n > 0) {
    if(n & 1) (ret *= x) %= p;
    (x *= x) %= p;
    n >>= 1;
  }
  return ret;
}


void solve(long long K, std::string S){
    ll N = S.size();
    ll ans =mod_pow(26ll,K+N,MOD);
    
    COMinit();
    for(ll i=0;i<N;i++){
        ll minus =COM(K+N,i)*mod_pow(25ll,K+N-i,MOD);
        minus %= MOD;
        ans = ans + MOD -minus;
        ans %=MOD;
    }
    cout << ans << endl;

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long K;
    scanf("%lld",&K);
    std::string S;
    std::cin >> S;
    solve(K, S);
    return 0;
}


Measured memory_bytes: 239720
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
int main(){
    string s;
    cin >> s;
    int n = (int) s.size();
    ll ans = 0;
    for(int i = 0; i < (1<<(n-1)); i++){
        ll num = 0;
        ll temp = 0;
        for(int j = 0; j < n; j++){
            if(j > 0 and (i&(1<<(j-1)))){
                num += temp;
                temp = 0;
            }
            temp = temp * 10 + s[j]-'0';
        }
        num += temp;
        ans += num;
    }
    cout << ans << endl;
}

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

int main(){
  ll A,B,M,ans,amin,bmin,i,h,x,y,c;
  cin >> A >> B >> M;
  amin=100000;
  bmin=100000;
  ll a[A],b[B];
  for(i=1;i<=A;i++){
    cin >> a[i];
    if(a[i]<amin)amin=a[i];
  }
  for(i=1;i<=B;i++){
    cin >> b[i];
    if(b[i]<bmin)bmin=b[i];
  }
  ans=amin+bmin;
  for(i=1;i<=M;i++){
    cin >> x >> y >> c;
    h=a[x]+b[y]-c;
    if(h<ans){
      ans=h;
    }
  }
  cout << ans;
}

Measured memory_bytes: 1792
H,W,A,B = map(int,input().split())

def init_fact(n,mod):
    fact,finv,inv = [1]*n,[1]*n,[1]*n
    for i in range(2,n):
        fact[i] = (fact[i-1]*i) % mod
        inv[i]  = mod - inv[mod%i] * (mod//i)%mod
        finv[i] = finv[i-1] * inv[i] % mod
    return (fact,finv,inv)

def nCr(n,r,mod,fact,finv):
    if n<r:
        return 0
    else:
        return fact[n] * (finv[r] * finv[n-r] % mod) % mod

modulo = 10**9+7
fact,finv,inv = init_fact(200000,modulo)

ans = 0
for i in range(H-A):
    ans += nCr(i+B-1,i,modulo,fact,finv) * nCr(H-i-1+W-B-1,W-B-1,modulo,fact,finv)
    ans %= modulo

print(ans)

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

int N, M;
vector<int> adj[100001];
int dist[100001];
bool visited[100001];
int maxDist = 0;

void _dfs();
int dfs(int u);

void _dfs()
{
	for (int i = 1, u, v; i <= M; ++i)
	{
		cin >> u >> v;
		adj[u].push_back(v);
	}

	memset(dist, 0, sizeof(dist));
	memset(visited, 0, sizeof(visited));

	for (int i = 1; i <= N; ++i)
		if (!visited[i])
			maxDist = max(dfs(i), maxDist);
}

int dfs(int u)
{
	visited[u] = true;

	for (int v : adj[u])
	{
		if (!visited[v])
			dist[u] = max(dist[u], 1 + dfs(v));
		else
			dist[u] = max(dist[u], 1 + dist[v]);
	}

	return dist[u];
}

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

	cin >> N >> M;
	_dfs();

	cout << maxDist << endl;

	return 0;
}

Measured memory_bytes: 7552
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (long long i = 0; i < n; i++)
#define RREP(i, n) for (long long i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (long long i = start; i < end; i++)
#define RFOR(i, start, end) for (long long i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    int N;
    cin >> N;
    int ans  = INF32;
    auto fun = [&](auto f, int sum, int cnt) {
        if (sum < 0)
            return;
        if (sum < 6) {
            cnt += sum;
            chmin(ans, cnt);
            return;
        }
        int six = 6;
        while (six * 6 <= sum) {
            six *= 6;
        }
        f(f, sum - six, cnt + 1);
        int nine = 9;
        while (nine * 9 <= sum) {
            nine *= 9;
        }
        f(f, sum - nine, cnt + 1);
        return;
    };
    fun(fun, N, 0);
    print(ans);

    return 0;
}

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

using namespace std;

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

    const int MOD = 1e9 + 7;
    const int MAX_N = 1e6 + 5;
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<int> cnt_factors(MAX_N);

    auto factorize = [&](int n) {
        int d = 2;
        while (d * d <= n) {
            int cnt = 0;
            while (n % d == 0) {
                n /= d;
                cnt++;
            }
            cnt_factors[d] = max(cnt_factors[d], cnt);
            d++;
        }
        if (n > 1) {
            cnt_factors[n] = max(cnt_factors[n], 1);
        }
    };

    for (int val : a) {
        factorize(val);
    }

    auto binPow = [](long long val, long long p, int mod) {
        long long ret = 1;
        while (p) {
            if (p & 1) {
                ret = (ret * val) % mod;
            }
            val = (val * val) % mod;
            p >>= 1;
        }
        return ret;
    };

    long long lcm = 1;
    for (int factor = 1; factor < MAX_N; ++factor) {
        lcm *= binPow(factor, cnt_factors[factor], MOD);
        lcm %= MOD;
    }
    long long ret = 0;
    for (long long val : a) {
        ret += lcm * binPow(val, MOD - 2, MOD);
        ret %= MOD;
    }
    cout << ret << '\n';

    return 0;
}


Measured memory_bytes: 7112
/*input
1
1

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 1034567891;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll n, d;
  cin >> n >> d;
  int ans = 0;
  d *= d;
  for (int i = 0; i < n; i++) {
    ll a, b;
    cin >> a >> b;
    ll x = a * a + b * b;
    ans += (x <= d);
  } 
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<int> a(6);
	vector<bool> dp(n + 1000);
	rep(i,6){
		a.at(i) = 100 + i;
	}
	dp[0] = 1;
	rep(i,n){
		if(dp[i]){
			rep(j,6) dp[i + a.at(j)] = true;
		}
	}
	if(dp[n]) cout << 1 << endl;
	else cout << 0 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

bool fc(vector<bool> &a, int now, map<int, bool> &mp){
  for(int i = now*2; i < a.size(); i += now){
    if(a.at(i) == true) mp[i] = true;
  }
  return true;
}

int main(){
  int n;
  cin >> n;
  vector<bool> a(1000002, false);
  map<int, bool> mp;
  set<int> rei;
  rep(i, n){
    int in;
    cin >> in;
    if(a.at(in) == false){
      a.at(in) = true;
      mp[in] = false;
    }else{
      mp[in] = true;
    }
  }

  int ans = 0;
  rep2(i, 1, a.size()){
    if(a.at(i) == true){
      fc(a, i, mp);
    }
  }
  for(auto p : mp){
    if(p.second == false) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 13124
#include<stdio.h>
int main(){
    unsigned short usW_D_cal;
    unsigned short usW_D_imput;
    unsigned short usW_C_i;
    scanf("%d", &usW_D_imput);
    for(usW_C_i = 1;usW_C_i <= usW_D_imput;usW_C_i++){
        if(usW_C_i % 3 == 0){
            printf(" %d", usW_C_i);
            continue;
        }
        usW_D_cal = usW_C_i;
        do{
            if(usW_D_cal % 10 == 3){
                printf(" %d", usW_C_i);
                break;
            }
        usW_D_cal /= 10;
        }while(usW_D_cal);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2040
N = int(input())
a = [int(i) for i in input().split()]
import collections
c = collections.Counter(a)
li = list(c.values())
lia = list(c.keys())
ans = 0
for i in range(len(li)) :
    if li[i] != lia[i] :
        if li[i] > lia[i] :
            ans += li[i] - lia[i]
        else :
            ans += li[i]
print(ans)

Measured memory_bytes: 18164
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main(void){
  int n;
  while(cin>>n,n){
    vector<pair<int,int> > v;
    for(int i=0,a,b;i<n;++i){cin>>a>>b;v.push_back(make_pair(b,a));}
    sort(v.begin(),v.end());
    bool f=false;
    for(int i=0,w=0;i<n;++i){
      w+=v[i].second;
      if(v[i].first<w){f=true;break;}
    }
    cout<<(f?"No":"Yes")<<endl;
  }
  return 0;
}

Measured memory_bytes: 1192
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

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

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


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

    ll sum = 0, ketaNum = 0,lastNum=0;
    while(N){
        ll dig = N % 10;
        sum = sum + dig;
        lastNum = N;
        N = N / 10;
        ketaNum++;
    }

    ll ans=0;
    if((sum-lastNum) == 9*(ketaNum-1)){
        ans = lastNum+(9*(ketaNum-1));
    }else{
        ans = lastNum+(9*(ketaNum-1))-1;
    }

    // cout << lastNum << endl;
    // cout << ketaNum << endl;
    // cout << sum-lastNum << endl;

    cout << ans << endl;
}




Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
using namespace std;

const int N=2e5+5;
int n,k,q,a[N];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>k>>q;
    for(int i=1;i<=n;i++) cin>>a[i];
    int res=1e9;
    for(int i=1;i<=n;i++)
    {
        int mn=a[i];
        vector<pii>seg;
        for(int j=1;j<=n;j++)
        {
            if(a[j]<mn) continue;
            int l=j,r=j;
            while(a[r]>=mn) r++;
            r--;
            seg.push_back(mp(l,r));
            j=r;
        }
        vector<int>avail;
        for(auto&x:seg)
        {
            int l=x.fi;
            int r=x.se;
            vector<int>val;
            for(int j=l;j<=r;j++) val.push_back(a[j]);
            sort(val.begin(),val.end());
            for(int j=0;j<r-l+1-k+1;j++) avail.push_back(val[j]);
        }
        sort(avail.begin(),avail.end());
        if(avail.size()>=q) res=min(res,avail[q-1]-a[i]);
    }
    cout<<res;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    ll N,M; cin >> N >> M;
    if(N == 1 && M == 1) cout << 1 << endl;
    else if(N == 1) cout << M-2 << endl;
    else if(M == 1) cout << N-2 << endl;
    else 
    cout << (N-2)*(M-2) << endl;
}

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

using namespace std;

class Solution {
public:
	/* time: O(1), space: O(1) */
	string weatherPrediction(const string& s) {
		if (s == "Sunny")
			return "Cloudy";
		else if (s == "Cloudy")
			return "Rainy";
		else
			return "Sunny";
	}
};

int main() {
	string s;
	cin >> s;

	Solution sol;
	string ans = sol.weatherPrediction(s);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
# import time
N, C = map(int, input().split())              # 同上。map関数を使うとこのように書ける

D = [[0 for i in range(C)] for j in range(C)]
c = [[0 for i in range(N)] for j in range(N)]
# iwakan = [[[0 for i in range(N)] for j in range(N)] for k in range(C)]

for i in range(C):
    D[i] = list(map(int, input().split()))

for i in range(N):
    c[i] = list(map(int, input().split()))

# まず違和感リストを作る。
# for i in range(C):
#     for j in range(N):
#         for k in range(N):
#             iwakan[i][j][k] = D[c[j][k] - 1][i]

'''
Gij0 : (i + j) % 3 == 0 となる場所
Gij1 : (i + j) % 3 == 1 となる場所
Gij2 : (i + j) % 3 == 2 となる場所
とした時に、
Gijnに属する場所全ての色をaに塗り替える場合の違和感の合計を
iwakan[n][a]とする。
iwakan[n][a]を全て求めるための計算量は、30*500*500 = 7500000
iwakan を用いて全ての色の塗り替えの組み合わせを求めるための計算量は
30 * 29 * 28 = 24360
'''

# t1 = time.time()

# Gijnに属する色の数を合計したリストを作る。
numOfColors = [[0 for i in range(C)] for j in range(3)]
for i in range(N):
    for j in range(N):
        if (i + j) % 3 == 0:
            numOfColors[0][c[i][j] - 1] = numOfColors[0][c[i][j] - 1] + 1
        if (i + j) % 3 == 1:
            numOfColors[1][c[i][j] - 1] = numOfColors[1][c[i][j] - 1] + 1
        if (i + j) % 3 == 2:
            numOfColors[2][c[i][j] - 1] = numOfColors[2][c[i][j] - 1] + 1

iwakan = [[0 for i in range(C)] for j in range(3)]
for i in range(3):
    for j in range(C):
        for a in range(C):
            iwakan[i][j] = iwakan[i][j] + numOfColors[i][a] * D[a][j]

# t2 = time.time()

sum_min = float("inf")
for i in range(C):
    for j in range(C):
        for k in range(C):
            if (i == j) or (j == k) or (k == i):
                pass
            else:
                sum_tmp = iwakan[0][i] + iwakan[1][j] + iwakan[2][k]
                if sum_min > sum_tmp:
                    sum_min = sum_tmp

# t3 = time.time()

print(sum_min)

# elapsed_time1 = t2 - t1
# elapsed_time2 = t3 - t2
# print(f'time1: {elapsed_time1}')
# print(f'time2: {elapsed_time2}')


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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "YES"
#define FALSE__ "NO"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

void init();
void solve();

signed main()
{
	init();
	solve();
}

int N, M;
vector<int> v;
vector<int> t;

void init()
{
	cin >> N >> M;
	v.RS(N, 0);
	t.RS(N, 1);
	v[0] = 1;
}

void solve()
{
	rep(i, M) {
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		v[y] = max(v[y], v[x]);
		t[x]--;
		t[y]++;
		if (t[x] == 0) v[x] = 0;
	}
	int res = 0;
	rep(i, N) {
		res += v[i];
	}
	cout << res << endl;
}





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

int main()
{
	int N;

	cin >> N;

	int *takoyaki = new int[N];

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

	int sum = 0;

	for (int i = 0; i < N - 1; i++) {
		for (int j = i + 1; j < N; j++) {
			sum += takoyaki[i] * takoyaki[j];
		}
	}

	cout << sum << endl;

	delete takoyaki;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
#define ll long long int
#define mod 1000000007
using namespace std;

int main()
{
    int n;
    cin >> n;
    int i;

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

Measured memory_bytes: 256
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<bits/stdc++.h>
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector>
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define rep1(i,n)  for(ll i=1; i<=n; i++)
#define rrep1(i,n) for(ll i=n; 1<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e18
using ll = long long;
using namespace std;
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; }

int main(){
  string s;  cin >> s;
  if(s == "SUN"){
    cout << 7;
  }else if(s == "SAT"){
    cout << 1;
  }else if(s == "FRI"){
    cout << 2;
  }else if(s == "THU"){
    cout << 3;
  }else if(s == "WED"){
    cout << 4;
  }else if(s == "TUE"){
    cout << 5;
  }else if(s == "MON"){
    cout << 6;
  }
}


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

int main() {
	int a,b,t,ans;
	

	cin >> a>>b>>t;
	ans = (double(t) + 0.5) / double(a);
	
	cout << ans*b << endl;
	return 0;
}

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

long long int Gcd(long long int a, long long int b)
{
	if (a < b) swap(a, b);
	if (b == 0) return a;
	return Gcd(a % b, b);
}

long long int Lcm(long long int a, long long int b)
{
	return a / Gcd(a, b) * b;
}

int main()
{
	int a[3];
	int m[3];
	while (true)
	{
		for (int i = 0; i < 3; i++) cin >> a[i] >> m[i];
		if (a[0] == 0 && a[1] == 0 && a[2] == 0 && m[0] == 0 && m[1] == 0 && m[2] == 0) return 0;

		int x = 1;
		int y = 1;
		int z = 1;
		long long int countX = 0;
		long long int countY = 0;
		long long int countZ = 0;

		while (true)
		{
			countX++;
			x = (a[0] * x) % m[0];
			if (x == 1) break;
		}
		while (true)
		{
			countY++;
			y = (a[1] * y) % m[1];
			if (y == 1) break;
		}
		while (true)
		{
			countZ++;
			z = (a[2] * z) % m[2];
			if (z == 1) break;
		}

		long long int lcm = Lcm(countX, countY);
		lcm = Lcm(lcm, countZ);
		cout << lcm << endl;
	}

	return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <queue>
#include <stack>
#include <deque>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <string>
#include <cmath>
#include <complex>
#include <functional>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cstdlib>
#include <cctype>

#define REP(i,m,n) for(int i=m;i<(int)n;i++)
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rrep(i,n) for(int i = 1; i <= n; i++)
#define drep(i,n) for(int i = n; i >= 0; i--)
#define rp(i,c) rep(i,(int)c.size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(u) (u).rbegin(),(u).rend()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
#define v_delete(a,b) (a).erase(remove((a).begin(), (a).end(), b), (a).end())
#define v_unique(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define VV(T) vector<vector< T > >
#define init(a,b) memset((a), (b), sizeof((a)))
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int inf=1<<28;
const double INF=1e10,EPS=1e-9;


template<class T>int SIZE(T a){return a.size();}
template<class T>string IntToString(T num){string res;stringstream ss;ss<<num;return ss.str();}
template<class T>T StringToInt(string str){T res=0;for(int i=0;i<SIZE(str);i++)res=(res*10+str[i]-'0');return res;}
template<class T>T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*b;}

template <class T> void input(T& a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }
template <class T> void input(T* a, int n) { for (int i = 0; i < n; ++i) cin >> a[i]; }

int chmax(int& a,int b){
	if(b > a){
		a=b;
	}
	return a;
}
int chmin(int& a,int b){
	if(b < a){
		a=b;
	}
	return a;
}
int dp[11][11]={inf};

int main(){
	int n;
	while(cin >> n,n){
		int mc=0;
		rep(i,11){
			rep(j,11){
				dp[i][j]=inf;
			}
		}
		rep(i,n){
			int a,b,c;
			cin >> a >> b >> c;
			chmax(mc,max(a,b));
			dp[a][b]=c;
			dp[b][a]=c;
		}
		mc++;
		rep(i,mc){
			rep(j,mc){
				rep(k,mc){
					dp[j][k]=min(dp[j][k],dp[i][j]+dp[i][k]);
				}
			}
		}
		int id;int ans=inf;
		rep(i,mc){
			int tmp=0;
			rep(j,mc){
				if(i==j)continue;
				tmp+=dp[i][j];
			}
			if(ans > tmp){
				id=i;
				ans=tmp;
			}
		}
		printf("%d %d\n",id,ans);
	}
	return 0;
}

Measured memory_bytes: 1144
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void solve(int N) {
    VI seg(100010, 0);
    REP(i, N) {
        int a, b;
        scanf("%d%d", &a, &b);
        seg[a]++;
        seg[b + 1]--;
    }
    REP(i, 100008) seg[i + 1] += seg[i];
    int ans = 0;
    FOR(i, 1, N + 2) {
        //cout << seg[i] << " ";
        if (seg[i] >= i - 1) ans = i - 1;
    } 
    cout << ans << endl;
    return;
}

signed main(void) {
    LL n, m, p, a, b, c, x, y, z, q;
    string s;
    bool f = false;
    while (cin >> n, n) {
        solve(n);
        return 0;
    }
}

Measured memory_bytes: 3452
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define repd(i,a,b) for (ll i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;
int main(void)
{
	int a, b;
	cin >> a >> b;
	if(a<b) rep(i, b) cout << a;
	else rep(i, a) cout << b;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
ll GCD(ll a, ll b)
{
    return b ? GCD(b, a % b) : a;
}
int main()
{
    int n;
    cin >> n;
    int x1[n + 10], x2[n + 10], x3[n + 10];
    for(int i = 0; i < n; i++)
    {
        scanf("%d", &x1[i]);
    }
    x2[0] = x1[0];
    int mmm = 0;
    if(GCD(2, 3))
        mmm++;
    if(GCD(3, 2))
        mmm++;
    for(int i = 1; i < n; i++)
    {
        if(GCD(3, 2))
            x2[i] = __gcd(x2[i - 1], x1[i]);
    }
    if(GCD(3, 2))
        mmm++;
    x3[n - 1] = x1[n - 1];
    if(GCD(3, 2))
        mmm++;
    for(int i = n - 2; i >= 0; i--)
    {
        if(GCD(3, 2))
            x3[i] = __gcd(x3[i + 1], x1[i]);
    }
    if(GCD(3, 2))
        mmm++;
    int ans = max(x3[1], x2[n - 2]);
    if(GCD(3, 2))
        mmm++;
    for(int i = 1; i < n - 1; i++)
    {
        if(GCD(3, 4))
            ans = max(__gcd(x2[i - 1], x3[i + 1]), ans);
    }
    if(GCD(3, 2))
        mmm++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
//#include <function>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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


int main() {

  int N ,K;
  cin >> N >> K;
  string sss;
  cin >> sss;
  int tmp, tmp1, tmp2;
  tmp = 0;
  vector<int> len_0, len_1;
  /*
  if (sss[0] == '1'){
    REP(i, N){
      if (sss[i] != '1') {
        tmp = i;
        break;
      }
    }
  }
  */
  tmp1 = 1;
  tmp2 = 0;
  for(int i = 0; i < N; i++){
    if (i != N - 1){
      if (sss[i] == '0'){
        if (tmp1 == 0) tmp2++;
        else {
          len_1.push_back(tmp2);
          tmp2 = 1;
          tmp1 = 0;
        }
      }else{
        if (tmp1 == 1) tmp2++;
        else {
          len_0.push_back(tmp2);
          tmp2 = 1;
          tmp1 = 1;
        }
      }
    }else{
      if (sss[i] == '0'){
        if (tmp1 == 0) {
          tmp2++;
          len_0.push_back(tmp2);
        }else {
          len_1.push_back(tmp2);
          tmp2 = 1;
          tmp1 = 0;
          len_0.push_back(1);
        }
      }else{
        if (tmp1 == 1) {
          tmp2++;
          len_1.push_back(tmp2);
        }
        else {
          len_0.push_back(tmp2);
          tmp2 = 1;
          tmp1 = 1;
          len_1.push_back(1);
        }
      }
    }
  }

  len_0.push_back(0);
  len_1.push_back(0);

  int tmp_max = len_1[0];
  REP(i, K){
    tmp_max += len_0[i];
    tmp_max += len_1[i+1];
    if (tmp_max == N) {
      cout << N << endl;
      return 0;
    }
  }
  int tmp_tmp = tmp_max;
  for(int i = 0; i < len_0.size() - K - 1; i++){
    tmp_tmp = tmp_tmp + len_0[i+K] + len_1[i+K+1] - len_0[i] - len_1[i];
    //cout << tmp_tmp << endl;
    tmp_max = max(tmp_tmp, tmp_max);
    if (tmp_max == N) {
      cout << N << endl;
      return 0;
    }
  }

  cout << tmp_max << endl;


  //for(auto aa: len_1) cout << aa << ":";
  //cout << endl;
  //for(auto aa: len_0) cout << aa << ":";
  return 0;
}


Measured memory_bytes: 1020
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }

int main(){
	
	ll N;
	cin >> N;
	
	for(ll h = 1; h <= 3500; h++){
		for(ll w = 1; w <= 3500; w++){
			ll left = 4 * h * w - N * w - N * h;
			ll right = N * h * w;
			if(left > 0 && right % left == 0){
				ll n = right / left;
				cout << h << " " << n << " " << w << endl;
				return 0;
			}
			
			
		}
	
	}
	
	
	
	
	
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
using namespace __gnu_pbds; 
#define mod 1000000007
#define int long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inp(n) for(i=0;i<n;i++) cin>>A[i];
#define inz(A) memset(A,0,sizeof(A))
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define T 1000000
#define F first
#define S second
#define pi pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define vp vector<pair< int,int> >
#define mpi map<pair<int,int> ,int>
#define mip map<int, pair<int,int> >
#define inf INT_MAX
#define inf1 LONGLONG_MAX
#define sz(v) v.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define deb(x) cout<<#x<<"is "<<x<<endl;
#define lower(s) transform(all(s),s.begin(),::tolower)
#define endl "\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, 
         tree_order_statistics_node_update> pbds;
   
/* brownsands :Arpit */			
 
void solve()
{  string s,s1="";int q,t,cnt=0,f;char ch;
   cin >> s;
   cin >> q;
   while(q--)
   {
      cin >> t;
      if(t==1)
      {
        // reverse(all(s));
        cnt++;
      }
      else
      {
         cin >> f >> ch;
         if(f==1)
         {  if(cnt%2==0){
            s1.pb(ch);}
            else
            {
               s.pb(ch);
            }
            
         }
         else
         {
            if(cnt%2!=0){
            s1.pb(ch);}
            else
            {
               s.pb(ch);
            }
         }
         
      }
      
   }
   reverse(all(s1));
   s=s1+s;
   if(cnt%2!=0)reverse(all(s));
   cout<<s;
}
signed main()
{
   boost
        int test=0,t;
		//cin>>t;
		t=1;
		while(test++ <t){
            //cout<<"Case "<<test<<": ";
            solve();
            //cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
               }		
} 

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;cin>>s;
  int a=0,b=0,c=0,d=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='N')a++;
    if(s[i]=='S')b++;
    if(s[i]=='E')c++;
    if(s[i]=='W')d++;
  }
  if((a>0&&b==0)||(b>0&&a==0)||(c>0&&d==0)||(d>0&&c==0))cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;


int main()
{
	int N;
	cin >> N;
	vector<int> H(N);
	for (auto &&h : H)
	{
		cin >> h;
	}

	bool ans = true;
	for (int i = H.size() - 1; i > 0; i--)
	{
		if (H[i-1] == H[i])
		{
			continue;
		}
		else if (H[i-1] - H[i] == 1)
		{
			H[i-1]--;
		}
		else if (H[i - 1] - H[i] > 1)
		{
			ans = false;
			break;
		}
	}

	if (ans)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}	

Measured memory_bytes: 640
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}


int main(void){
	int n,i;cin>>n;
	llint A,B,bmin=0,bmax=mod;cin>>A>>B;
	vector<llint>h(n);
	for(i=0;i<n;i++){cin>>h[i];}
	SO(h);
	while(bmax-bmin>1){
		llint bgen=(bmin+bmax)/2;
		llint aaa=0;
		for(i=0;i<n;i++){
			aaa+=max(0LL,(h[i]-B*bgen+A-B-1)/(A-B));
		}
		if(aaa>bgen){bmin=bgen;}
		else{bmax=bgen;}
	}
	cout<<bmax<<endl;
	return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
//using namespace __gnu_pbds;
#define rep(i,a,b) for(i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
//template<typename T>
//using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out <<  "(" << a.F << ", " << a.S << ")";
}
 
template<class A> ostream& operator << (ostream& out, const vector<A> &a) {
	out << "[";
	for (auto it = a.begin(); it != a.end(); ++it) {
		if (it != a.begin())
			out << ", ";
		out << *it;
	}
	return out << "]";
}
int main()
{
    boost;
    ll n,i,j,x,t,y,a,b;
	cin>>n>>a>>b;
	x=n/(a+b);
	n-=x*(a+b);
	y=min(n,a);
	cout<<(x*a+y);
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ListIterator;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.util.LinkedList;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.ni();
            LinkedList<Integer> b = new LinkedList<>();
            for (int i = 0; i < n; i++) {
                b.addLast(in.ni());
            }
            LinkedList<Integer> ans = new LinkedList<>();
            for (int i = 0; i < n; i++) {
                int ind = b.size();
                ListIterator<Integer> it = b.listIterator(ind);
                while (it.hasPrevious()) {
                    Integer num = it.previous();
                    if (num == ind) {
                        ans.addFirst(num);
                        it.remove();
                        break;
                    }
                    ind--;
                }
                if (ind == 0 && b.size() != 0) {
                    out.println(-1);
                    return;
                }
            }
            for (Integer num : ans) {
                out.println(num);
            }

        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String ns() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int ni() {
            return Integer.parseInt(ns());
        }

    }
}



Measured memory_bytes: 22484
N = int(input())
A = list(map(int, input().split()))
count = 0
sum = 0
for i in range(N-1):
    if sum * (A[i+1]-A[i]) >= 0:
        sum += A[i+1] - A[i]
    else:
        count += 1
        sum = 0
print(count+1)

    
  

Measured memory_bytes: 14224
import math
ans = []
while True:
    ufo = []
    n = raw_input().split()
    if n == ["0", "0"]:
        for an in ans:
            print an
        break
    else:
        R = int(n[0])
        for i in range(int(n[1])):
            m = [int(f) for f in raw_input().split()]
            ufo.append([math.sqrt(m[0] ** 2 + m[1] ** 2), math.sqrt(m[0] ** 2 + m[1] ** 2), (m[0], m[1]), m[2], m[3]])
        a = 0
        while len(ufo) > 0:
            flag = True
            for xs in ufo: xs[0] -= xs[4]
            ufo.sort()
            for xs in ufo[:]:
                if xs[0] <= R:
                    a += 1
                    ufo.remove(xs)
                    continue
                elif flag:
                    r = xs[1]
                    pos = xs[2]
                    ufo.remove(xs)
                    flag = False
                    continue
                else:
                    d = xs[0] / xs[1] * abs(pos[0] * xs[2][1] - pos[1] * xs[2][0]) / r
                    if d <= xs[3]:
                        if xs[0] * math.cos(math.atan2(xs[2][1], xs[2][0]) - math.atan2(pos[1], pos[0])) + math.sqrt(xs[3] ** 2 - d ** 2) > R:
                            ufo.remove(xs)
        else:
            ans.append(a)

Measured memory_bytes: 4544
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

void solve() {
	ll N;
	cin >> N;
	vector<string> vec(N);
	rep(i, N) {
		cin >> vec[i];
		sort(vec[i].begin(), vec[i].end());
	}

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

	ll tmp = 0;
	ll ans = 0;

	for (ll i = 1; i < N; i++) {
		if (vec[i] == vec[i - 1]) {
			tmp++;
		}
		else {
			ans += tmp * (tmp+1) / 2;
			tmp = 0;
		}
	}
	if (tmp != 0) ans += tmp * (tmp+1) /2;

	cout << ans;

}

int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int comp(const void* a, const void* b)
{ return *(int*)a > *(int*)b ; }

int findNumberOfTriangles(int arr[], int n)
{

	qsort(arr, n, sizeof( arr[0] ), comp);

	int count = 0;
	for (int i = 0; i < n - 2; ++i)
	{

		int k = i + 2;

		for (int j = i + 1; j < n; ++j)
		{

			while (k < n && arr[i] + arr[j] > arr[k])
			++k;
			if(k > j)
			count += k - j - 1;
		}
	}

	return count;
}

int main()
{   int t;
    cin>>t;
    int arr[t];
    for(int i=0;i<t;i++)
    {
        cin>>arr[i];
    }
	int size = t;

	cout<<findNumberOfTriangles( arr, size );

	return 0;
}



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

int main()
{
	string s;
	cin >> s;
	int f = 0;
	int a = 0, c = 0;
	int A = 1000, C = 1000;
	string ans = "";
	if (s.at(0)!='A')
	{
		ans = "WA";

	}
	else
	{
		for (int i = 2; i < s.size() - 1; i++)
		{

			if (s.at(i) == 'C')
			{
				c++;
				C = i;
			}
		}

		if (c != 1)
		{
			ans = "WA";
		}
		else
		{

			for (int j = 1; j < s.size(); j++)
			{

				if (isupper(s.at(j)))
				{
					f++;

				}
			}
			if (f > 1)
			{
				ans = "WA";

			}
			else
			{
				ans = "AC";
			}
		}
	}
	cout << ans << endl;
	

}

Measured memory_bytes: 256
import math
import sys
import numpy as np

def int_input():
    return map(int, input().split())

s = input()

flag = 0
if 1 <= int(s[:2]) <= 12: flag += 2
if 1 <= int(s[2:]) <= 12: flag += 1

ans = ["NA", "YYMM", "MMYY", "AMBIGUOUS"]
print(ans[flag])


Measured memory_bytes: 22272