akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 0) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL sum = a;
    LL res = 1;
    while(b){
        if(b&1){
            res = (res * sum)%MOD;
        }
        sum = (sum * sum) % MOD;
        b>>=1;
    }
    return res;
}

int cb(int x){
    int res = 0;
    while(x){
        if(x&1)++res;
        x>>=1;
    }
    return res;
}

int main(){
    int N;
    cin >> N;
    --N;
    vector<int> C(N), S(N), F(N);
    REP(i, N){
        cin>>C[i]>>S[i]>>F[i];
    }
    REP(i, N){
        int time = 0;
        for(int j=i;j<N;++j){
            if(S[j]>time)time=S[j];
            time=(time+F[j]-1)/F[j]*F[j];
            time+=C[j];
        }
        cout << time << endl;
    }   
    cout << 0 << endl;
    return 0;
}


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

int min(int x,int y){
  if(x>y) return y;
  else return x;
}
int main(){
  int n,p[N+1],m[N+1][N+1];
  int i,j,k,l;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d %d",&p[i-1],&p[i]);
  }
  for(i=1;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);
      for(k=i;k<=j-1;k++){
        m[i][j]=min(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: 2112
#include <stdio.h>
#include <memory.h>
#include <stdlib.h>

int c(const void *v1,const void *v2){
    return *((int *)v2+3)-*((int *)v1+3);
}

int main(void){
    int line[301],line1[3],map[1000][4];
    int i,o,N,sum,sum1;

    for(;sum=0,scanf("%d %d %d",&line1[0],&line1[1],&line1[2]),line1[0]+line1[1]+line1[2];){
        sum1=line1[0]+line1[1]+line1[2];
        for(i=1;i<=sum1;i++)
            line[i]=2;
        scanf("%d",&N);
        for(i=0;i<N;i++)
            scanf("%d %d %d %d",&map[i][0],&map[i][1],&map[i][2],&map[i][3]);
        qsort(map,N,sizeof(int)*4,c);
        for(i=0;i<N;sum=0,i++){
            if(map[i][3])
                line[map[i][0]]=line[map[i][1]]=line[map[i][2]]=1;
            else{
                for(o=0;o<3;o++)
                    if(line[map[i][o]] == 1)
                        sum++;
                if(sum == 2)
                    for(o=0;o<3;o++)
                        if(line[map[i][o]] == 2)
                            line[map[i][o]]=0;
            }
        }
        for(i=1;i<=sum1;i++)
            printf("%d\n",line[i]);
    }
    return 0;
}

Measured memory_bytes: 1712
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
int a[maxn];
int num[maxn];
int num1[maxn];
int sum1[maxn];
long long sum[maxn];
int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		sum[i]=sum[i-1]+num[a[i]];
		num[a[i]]++;
	}
	for(int i=1;i<=n;i++)
	{
		long long ans=0;
		ans=sum[n]-(num[a[i]]-1);
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 6784
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define ll long long

int main() {
  int a;cin>>a;
  string s;cin>>s;
  if(a>=3200)
    cout<<s;
  else
    cout<<"red";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, k, q;
    cin >> n >> k >> q;

    vl cnt(n);
    rep(i, q) {
        ll a;
        cin >> a;
        a--;
        cnt[a]++;
    }

    rep(i, n) {
        if(q - cnt[i] < k) {
            out("Yes");
        }
        else {
            out("No");
        }
    }
    
    re0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define invrep(i,n) for(int i = (int)(n); i > 0; i++)
using ll = long long;

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

    string j = "";
    rep(i, s.size()) j += t[i];

    if (s == j) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

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

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

    int res = 0;
    for (int i = 0; i < 1000; i++) {
        vector<int> nums{i / 100, (i / 10) % 10, i % 10};
        int cnt = 0;
        for (int j = 0; j < N; j++) {
            if (S[j] - '0' == nums[cnt]) {
                cnt++;
                if (cnt == 3) break;
            }
        }
        if (cnt == 3) res++;
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    b = list(map(int, input().rstrip('\n').split()))
    a = [10 ** 6] * n
    for i in range(len(b)):
        a[i] = min(a[i], b[i])
        a[i+1] = min(a[i+1], b[i])
    print(sum(a))


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38500
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define REP(i,a,b) for (auto i = a; i != b; i++)
#define ll long long int
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define pb push_back
#define SQ(a) (a)*(a)
 
using namespace std;


int main()
{
    std::ios::sync_with_stdio(false);
    int T = 1;
    //cin>>T;
    for(int t = 1;t<=T;t++)
    {
       	ll x,k,d;
       	cin>>x>>k>>d;
       	ll val1 = abs(x/d);
       	//cout<<val1<<endl;
       	if(k > val1)
       	{
       		ll y = val1*d;
       		k = k - val1;
       		if(k % 2 == 0)
       			cout<<min(abs(x - y),abs(x+y))<<endl;
       		else 
       			cout<<min(min(abs(x - y - d),abs(x - y + d)),min(abs(x + y + d),abs(x + y - d)))<<endl;
       	}
       	else
       	{
       		cout<<min(abs(x - k*d),abs(x + k*d))<<endl;
       	}
       	
    }

    return 0;
}


Measured memory_bytes: 3696
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <boost/range/adaptors.hpp>
#include <iomanip>
#include <tuple>
#include <numeric>

int main() {
    int N;
    int M;
    std::cin >> N >> M;

    std::vector<int> A(N, 0);
    for (int i = 0; i < N; ++i) {
        std::cin >> A[i];
    }
    std::sort(A.begin(), A.end());
    int sum = std::accumulate(A.begin(), A.end(), 0);
    if (A[N - M] * 4 * M >= sum) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }

    // for (int i = 0; i < N; ++i) {
    //     std::cout << A[i] << " ";
    // }
    // std::cout << std::endl;
    // std::cout << A[N - M] << std::endl;

    return 0;
}

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

int main() {
	int a, b,c,d;
	cin>>a>>b>>c>>d;
	if(a>=c && b <=d) cout<< b-a;
	else if(c>=a && d <=b) cout<< d-c;
	else if(d<a) cout<<0;
	else if(b<c) cout<<0;
	else if(a>c) cout<<d-a;
	else cout<<b-c;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}




#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


  








int main() {
  int n;
  vector<long long> a;

    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    map<long long, long long> ma;
    for (int i = 0; i < n; ++i) ma[a[i]]++;
    long long res = 0;
    for (auto it : ma) res += it.second * (it.second - 1) / 2;
    for (int i = 0; i < n; ++i) {
      
        long long val = ma[a[i]];
        long long before = val * (val - 1) / 2;
        long long after = (val - 1) * (val - 2) / 2;
        cout << res + after - before << endl;
    }
}

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




int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    string str;
    cin>>str;
    if(str.back()=='s')str+="es";
    else str+="s";
    cout<<str<<endl;
    return 0;
}



Measured memory_bytes: 3652
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits>


int main(){
    long N,T,X;
    std::cin >> N >> X >> T;
    if(N%X==0){
        std::cout << T*(N/X) << std::endl;
    }else{
        std::cout << T*(N/X)+T << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    string s;
    cin>>s;
    for(ll i=0;i<s.size();i++){
        if((i%2==0&&s[i]=='L')||(i%2!=0&&s[i]=='R')){
            cout<<"No"<<endl;
            break;
        }
        if(i==s.size()-1) cout<<"Yes"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
from decimal import Decimal
import math
X = int(input())

start = Decimal("100")

risi = Decimal("1.0100000")
year = 1

while(True):
    start = math.floor(Decimal(start) * Decimal(risi))
    #print(start)
    if(start >= X):
        break
    year += 1
    
    
print(year)

Measured memory_bytes: 10072
while True :
    a = list(map(int,input().split()))
    if a[0] == 0:
        break
    else:
        max_sum = 0
        s = 0
        table = []
        for i in range(a[1]):
            table.append(list(map(int,input().split())))
        for i in range(a[0]):
            s = 0
            for j in range(a[1]):
                s += table[j][i]
            max_sum = max(s,max_sum)
        print(max_sum)


Measured memory_bytes: 7664
from itertools import product
from operator import and_
N = int(input())
F = [tuple(map(lambda s: s=="1", input().split())) for _ in range(N)]
P = [tuple(map(int, input().split())) for _ in range(N)]
print(max(sum(P[i][sum(map(and_, F[i], prod))] for i in range(N)) for prod in product((True, False), repeat=10) if sum(prod)))

Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {
    public static void main(String[] args ) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] A = new int[100];
        for(int i = 0; i < N; i++)
            A[i] = scanner.nextInt();

        int count = 0;
        boolean flag = true;
        while(flag){
            flag = false;
            for(int i = 0; i < N - 1; i++){
                if(A[i] > A[i+1]){
                    int tmp = A[i];
                    A[i] = A[i+1];
                    A[i+1] = tmp;
                    flag = true;
                    count++;
                }
            }
        }
        for(int i = 0; i < N; i++){
            System.out.print(A[i]);
            if(i != N-1) System.out.print(" ");
        }


        System.out.println("\n" + count);
    }
}



Measured memory_bytes: 26284
import java.util.HashSet;
import java.util.Set;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] contests = {111, 222, 333, 444, 555, 666, 777, 888, 999};
        int ans = 111;
        
        for (int i = 0; i < contests.length; i++) {
            if (n <= contests[i]) {
                ans = contests[i];
                break;
            }
            
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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 hr() { cerr << "--------------" << endl; }
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int n, m;
   cin >> n >> m;
   int ans = n * (n - 1) / 2 + m * (m - 1) / 2;
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MAX 200
#define inf 1<<29
#define linf 1e18
#define eps (1e-8)
#define mod 1000000007
#define pi M_PI
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.9f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<double,int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpi;

int V,m,a;
vector<int> G[MAX];
vector<int> rG[MAX];
vector<int> vs;
bool used[MAX];
int cmp[MAX];
double p[MAX],ip[MAX];

void init(){
  FOR(i,0,MAX){
    G[i].clear();
    rG[i].clear();
    p[i]=1.0;
    ip[i]=0.0;
  }
}

void add_edge(int from, int to){
  G[from].push_back(to);
  rG[to].push_back(from);
}
  
void dfs(int v){
  used[v] = true;
  for(int i = 0;i < G[v].size();i++){
    if(!used[G[v][i]])dfs(G[v][i]);
  }
  vs.push_back(v);
}
  
void rdfs(int v,int k){
  used[v] = true;
  cmp[v] = k;
  for(int i = 0;i < rG[v].size();i++){
    if(!used[rG[v][i]]) rdfs(rG[v][i],k);
  }
}
  
void scc(){
  memset(used,0,sizeof(used));
  vs.clear();
  for(int v = 0;v < V;v++){
    if(!used[v]) dfs(v);
  }
  memset(used,0,sizeof(used));
  int k = 0;
  for(int i = vs.size() - 1;i >= 0;i--){
    if(!used[vs[i]])rdfs(vs[i],k++);
  }
  return;
}

void solve(){
  double res=1.0;
  map<int,vector<int> > mp;
  FOR(i,0,V)mp[cmp[i]].pb(i);
  FOR(i,0,V)FOR(j,0,V)if(cmp[i]==cmp[j])p[i]*=ip[j];
  FOR(i,0,V){
    vector<int> v=mp[i];
    if(v.size()==0)continue;
    bool flag=true;
    FOR(j,0,v.size()){
      int now=v[j];
      FOR(k,0,rG[now].size()){
        int next=rG[now][k];
        if(cmp[next]!=i)flag=false;
      }
    }
    if(flag)res*=(1.0-p[v[0]]);
  }
  pd(res);
}

int main()
{
  while(1){
    cin>>V;
    if(V==0)break;
    init();
    FOR(i,0,V){
      cin>>ip[i]>>m;
      FOR(j,0,m){
        cin>>a;
        add_edge(i,a-1);
      }
    }
    scc();
    solve();
  }
  return 0;
}

Measured memory_bytes: 3352
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

typedef long double ld;

#define int long long

const ld pi = acos(-1);
const int N = 2e5 + 8;

namespace Fenwick {
    int f[N];

    int get(int x) {
        int ans = 0;
        for (int i = x; i >= 0; i = (i & (i + 1)) - 1) {
            ans = max(ans, f[i]);
        }
        return ans;
    }

    void set(int x, int val) {
        for (int i = x; i < N; i = (i | (i + 1))) {
            f[i] = max(f[i], val);
        }
    }
}

int lis(vector<pair<int, int>>  v) {
    vector<int> sn;
    for (auto t : v) {
        sn.push_back(t.second);
    }
    sort(sn.begin(), sn.end());
    sn.resize(unique(sn.begin(), sn.end()) - sn.begin());
    vector<int> a;
    for (auto t : v) {
        a.push_back(lower_bound(sn.begin(), sn.end(), t.second) - sn.begin());
    }
    int n = (int)a.size();
    for (auto t : a) {
        int val = 1 + Fenwick::get(t - 1);
        Fenwick::set(t, val);
    }
    return Fenwick::get(n);
}

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

    cout << fixed << setprecision(16);

    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    if (x1 > x2) {
        swap(x1, x2);
        swap(y1, y2);
    }

    int mny = min(y1, y2);
    int mxy = max(y1, y2);
    int n;
    cin >> n;
    vector<pair<int, int>> a;
    while (n--) {
        int x, y;
        cin >> x >> y;
        if (x1 <= x && x <= x2 && mny <= y && y <= mxy) {
            a.push_back({x, y});
        }
    }
    if (x1 == x2) {
        ld diff = ((pi * 10) - 20);
        cout << (ld)(mxy - mny) * 100 + diff * (a.size()) << endl;
        return 0;
    }   
    if (y1 == y2) {
        ld diff = ((pi * 10) - 20);
        cout << (x2 - x1) * 100 + diff * (a.size()) << endl;
        return 0;
    }
    sort(a.begin(), a.end());
    // cerr << x1 << ' ' << y1 << endl;
    // for (auto t : a) {
    //     cerr << t.first << ' ' << t.second << endl;
    // } 
    // cerr << x2 << ' ' << y2 << endl;
    ld ans = (ld)100 * ((x2 - x1) + abs(y2 - y1));
    if (y1 > y2) reverse(a.begin(), a.end());
    int add = lis(a);
    ans -= 20 * add;
    ans += (ld)add * ((2 * pi * 10) / 4);
    if (add == min(abs(x1 - x2), abs(y1 - y2)) + 1) {
        ans += (pi * 10 - 20);
        ans += (20 - ((2 * pi * 10) / 4));
    }
    cout << ans << endl;

    
}   


Measured memory_bytes: 14316
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void){
	string S;
	while(cin >> S){
		int cost = 0;
		string str = S;
		if(S == "6174"){
			cout << cost << endl;
			continue;
		}
		if(S == "0000")break;
		if(StrToInt(S) % 1111 == 0){
			cout << "NA" << endl;
			continue;
		}
		while(1){
			cost++;
			vector<int> v;
			rep(i,4){
				int a = str[i]-'0';
				v.push_back(a);
			}
			sort(v.begin(), v.end(), greater<int>());
			int L = v[0] * 1000 + v[1] * 100 + v[2] * 10 + v[3];
			sort(v.begin(), v.end());
			int S = v[0] * 1000 + v[1] * 100 + v[2] * 10 + v[3];
			int sum = L - S;
			//cout << "L:" << L << " S:" << S << endl;
			//cout << "cost:" << cost << " " << sum << endl;
			if(sum == 6174){
				cout << cost << endl;
				break;
			}
			str = IntToStr(sum);
			if(sum < 1000)str = '0'+str;
			if(sum < 100)str = '0'+str;

		}


	}
	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

Measured memory_bytes: 1264
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll p=pow(10,9)+7;
ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      
    x = x % p;  
   while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p; 
    } 
    return res; 
} 

ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,j,k;
   cin>>n>>k;
   ll arr[n];
   for(i=0;i<n;i++)
   cin>>arr[i];
  ll dp[k+1];
  memset(dp,0,sizeof(dp));
  for(i=1;i<=k;i++)
  {
      
      for(j=0;arr[j]<=i&&j<n;j++)
      {
          if(!dp[i-arr[j]])
          {
              
              dp[i]=1;
              break;
          }
      }
      
  }
  if(dp[k])
  cout<<"First";
  else
  cout<<"Second";
   
  return 0;
    
}
    



Measured memory_bytes: 1024
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

const ll INF = 1001001001001001001;
signed main(){
    int n; cin >> n;
    vector<string> s;
    rep(i,n){
        string a; cin >> a;
        s.push_back(a);
    }
    sort(ALL(s)); //=sort(s.begin(),s.end())
    
    int x=1;
    int res=1;
    rep(i,n){
        if(i==0) continue;
        if(s[i-1]==s[i]){
            res++;
            x=max(x,res);
        }
        else{
            res=1;
        }
    }
    //cout << res << endl;
    res=1;
    rep(i,n){
        if(i==0){
            if(x==1) cout << s[0] << endl;
            continue;
        }
        if(s[i-1]==s[i]){
            res++;
        }
        else{
            res=1;
        }
        if(res==x){
            cout << s[i] << endl;
        }
    }
    
}


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

using namespace std;
int main(){
	string s;
	cin >> s;
	int i,n = s.size();
	for(i=0;i<n;i++){
		if((i&1) && s[i]=='R'){
			cout << "No" << endl;
			return 0;
		}
		if(((i&1)==0) && s[i]=='L'){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		if(x*n<y){
			System.out.println(x*n);
		}
		else{
			System.out.println(y);
		}
	}
}

Measured memory_bytes: 24148
from math import factorial


def perm(r, c):
    return factorial(r) // factorial(r - c)


def comb(r, c):
    return perm(r, c) // factorial(c)


N, P = map(int, input().split())
a = list(map(int, input().split()))
a = list(map(lambda x: x % 2, a))
a = list(sorted(a))

cnt_0 = a.count(0)
cnt_1 = a.count(1)

ans = 0
if P == 0:
    for j in range(0, cnt_1 + 1, 2):
        ans += comb(cnt_1, j) * (2 ** cnt_0)
else:
    # P == 1
    for j in range(1, cnt_1 + 1, 2):
        ans += comb(cnt_1, j) * (2 ** cnt_0)
print(ans)


Measured memory_bytes: 3064
import sys

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    A = [int(a) - 1 for a in input().split()]
    Dist = [-1] * N
    Dist[0] = 0
    now = 0
    for i in range(min(N, K)):
        nextN = A[now]
        if Dist[nextN] == -1:
            Dist[nextN] = i + 1
            now = nextN
        else:
            Left = K - i - 1
            mod = Left % (i + 1 - Dist[nextN])
            snow = nextN
            for j in range(mod):
                snow = A[snow]
            print(snow + 1)
            break
    else:
        for i, d in enumerate(Dist):
            if d == K: 
                print(i + 1)
                break
    return  0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 30928
#include <iostream>
#include <list>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <chrono>
#include <math.h>
using namespace std;

using lli = long long int;
using Vint = std::vector<int>;
using Vlli = std::vector<lli>;
using Wint = std::vector<Vint>;
using Wlli = std::vector<Vlli>;
using Vbool = std::vector<bool>;
using pii = std::pair<int, int>;
using pll = std::pair<lli, lli>;

constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {std::make_pair(1, 0), std::make_pair(-1, 0), std::make_pair(0, 1), std::make_pair(0, -1)};
constexpr char BR = '\n';

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(ele, vec) for(auto &(ele) : (vec))
#define vREPcopy(ele, vec) for(auto (ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())



template <class T> inline int argmin(std::vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(std::vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline void chmax(T &a, T b){a = max(a, b);}
template <class T> inline void chmin(T &a, T b){a = min(a, b);}
inline int BitI(int k){return 1 << k;}
inline lli BitL(int k){return 1L << k;}
inline int toInt(string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline int toInt(const string s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(const string s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
template <class T> inline std::string toString(T n){
  if(n == 0) return "0";
  std::string res = "";
  if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;}
  std::reverse(res.begin(), res.end()); return '-' + res;}
  while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




int main(void){
  int n; cin >> n;
  string s; cin >> s;
  int black = 0, white = 0;
  REP(i, n){
    if(s.at(i) == '#') black++;
    else white++;
  }
  int res = INFi;
  int til_black = 0, til_white = 0;
  rREP(i, n){
    int tmp = til_white + (black - til_black);
    chmin(res, tmp);
    if(s.at(i) == '#') til_black++;
    else til_white++;
  }
  int tmp = til_white + (black - til_black);
  chmin(res, tmp);
  printf("%d\n", res);
  return 0;
}

Measured memory_bytes: 832
from math import ceil
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
F = sorted(list(map(int, input().split())), reverse=True)

K = min(K, sum(A))
X = [[a, f] for a, f in zip(A, F)]

ok, ng = 10 ** 12 + 1, -1
while abs(ok - ng) > 1:
    m = (ok + ng) // 2
    k_cost = 0
    for a, f in X:
        if a * f <= m:
            continue
        else:
            k_cost += max(0, ceil(-(m / f - a)))

    if k_cost <= K:
        ok = m
    else:
        ng = m

print(ok)


Measured memory_bytes: 131916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
  int n,minj;
  cin >> n;
  vector<pair<int,int>> p(n);
  for(int i = 0;i<n;i++)
  {
      int a;
      cin >> a;
      p[i] = make_pair(a,i+1);
  }
  sort(p.begin(),p.end());
  for(int i = 0; i < n; i++) cout<<p[i].second<<' ';
  cout<<"\n";
  return 0;
}



Measured memory_bytes: 1536
(X,K,D) = map(int,input().split())
X = abs(X)
if X-K*D>0:
    print(X-K*D)

else:
    if K%2==0:
        print(min(abs(X%(2*D)),abs(X%(2*D)-2*D)))
    else:
        print(min(abs((X+D)%(2*D)),abs((X+D)%(2*D)-2*D)))


Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define LL long long
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define FOD(i,a,b) for(int i=a; i>=b; i--)
#define pa pair<int,int>
#define fi first
#define se second
#define MOD xxx
#define getbit(n,i) ((n>>(i-1))&1)
#define offbit(n,i) ((n^(1<<(i-1))
#define onbit(n,i) (n|(1<<(i-1)))
#define cntone(x) (__builtin_popcount(x))

using namespace std;
long double a,b;
int main()
{
    cin >> a >> b;
    cout << (long long)(a*b);
	return 0;
}


Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
long long int l,a,b,e;
int main()
{   
    cin>>a>>b;e=a;l=b;
     while(b)
    {int r=a%b;
     a=b;
     b=r;}
     cout<<(e/a)*l;
    return 0;
}

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

int route(int x0, int y0, int t0, int t1, int x1, int y1) {
  int x, y, t;
  if (x0<x1) x=x1-x0;
  else x=x0-x1;
  if (y0<y1) y=y1-y0;
  else y=y0-y1;
  t=t1-t0;
  if (x+y<=t && (t-(x+y))%2==0) return 1;
  else return 0;
}

int main() {
  
  int N;
  cin >> N;
  
  int s=0;
  int ox, oy, ot;
  for (int i=0; i<N; i++) {
    int t, x, y;
    cin >> t >> x >> y;
    if (i==0) {
      ox=0;
      oy=0;
      ot=0;
    }
    s=route(ox, oy, ot, t, x, y);
    if (s==0) break;
    ox=x;
    oy=y;
    ot=t;
  }
  
  if (s==1) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
 

N, Q = map(int, input().split())

T = [[]for i in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    T[a-1].append(b-1)
    T[b-1].append(a-1)

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

def dfs(x, p):
    for j in T[x]:
        if j == p:
            continue
        X[j] += X[x]
        dfs(j, x)

dfs(0, -1)

for i in range(N):
    print(X[i], end =" ")


Measured memory_bytes: 227804
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
	int i,l,sum=0,sum1=0;
	char a[10003];
	gets(a);
	l=strlen(a);
	for(i=0;i<l;i++)
	{
		sum+=a[i]-48;
	sum1+=(a[i]-48)*pow(10,l-i-1);
	}
	if(sum1%sum==0)
	printf("Yes");
	else
	printf("No");
	//if()
	//scanf("%d %d",);
	return 0;
}

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

typedef long long ll;

int a[100009][3];
int dp[100009][3];

int main()    
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i][0]>>a[i][1]>>a[i][2];

    for(int i=0;i<3;i++)
        dp[0][i] = a[0][i];

    //cout<<dp[0][0]<<" "<<dp[0][1]<<" "<<dp[0][2]<<endl;

    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            int mx = -1;
            for(int k=0;k<3;k++){
                if(j==k) continue;
                dp[i][j] = max(dp[i][j],a[i][j]+dp[i-1][k]);
            }
        }
        //cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;
    }

    int ans = max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    cout<<ans;

}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

int main() {
	ll n;
	cin >> n;
	vector<ll> vs(n);
	rep(i, n) cin >> vs[i];
	int q;
	cin >> q;
	vector<ll> qs(q);
	rep(i, q) cin >> qs[i];

	vector<set<ll>> ss(n + 1);
	ss[0].insert(0);
	rep(i, n) {
		for (auto p : ss[i]) {
			ss[i + 1].insert(p);
			ss[i + 1].insert(p + vs[i]);
		}
	}
	rep(i, q) {
		if (ss[n].count(qs[i])) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 3380
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  int a,b; cin>>a>>b;
  cout<<(a-1)*(b-1)<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

void merge_sort(int x[], int n)
{
	static int y[200001] = {};
	if (n == 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p] < x[q])? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, N, M, D[200001], T[200001];
	scanf("%d", &N);
	for (i = 0; i < N; i++) scanf("%d", &(D[i]));
	scanf("%d", &M);
	for (i = 0; i < M; i++) scanf("%d", &(T[i]));
	
	merge_sort(D, N);
	merge_sort(T, M);
	
	int j;
	for (i = 0, j = 0; j < M; j++) {
		while (i < N && D[i] < T[j]) i++;
		if (i == N || D[i] > T[j]) break;
		else i++;
	}
	
	if (j == M) printf("YES\n");
	else printf("NO\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 2560
import math
a, b, c = map(int, input().split())

S = 0.5*math.sin(math.radians(c))*a*b
L = (a**2+b**2-2*a*b*math.cos(math.radians(c)))**0.5 + a + b
h = 2*S/a
print(S,L,h)


Measured memory_bytes: 5720
#include <bits/stdc++.h>
using namespace std;
const int M = 52;

int k[100];

int main()
{
	int ctoi[256];
	char itoc[52];
	for (int i = 0; i < 26; i++){
		ctoi['A' + i] = i;
		itoc[i] = 'A' + i;
	}
	for (int i = 0; i < 26; i++){
		ctoi['a' + i] = 26 + i;
		itoc[26 + i] = 'a' + i;
	}
	
	int n;
	while (cin >> n, n){
		for (int i = 0; i < n; i++){
			cin >> k[i];
		}
		
		string s;
		cin >> s;
		for (int i = 0; i < s.size(); i++){
			s[i] = itoc[(ctoi[s[i]] - k[i % n] + M) % M];
		}
		cout << s << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <stdlib.h>
using namespace std;

int main(){
  int x,a,b;cin>>x>>a>>b;
  int xa = abs(x-a);
  int xb = abs(x-b);
  string str;
  if(xa<xb){
    str = "A";
  }else{
    str = "B";
  }
  cout<<str<<endl;
}

Measured memory_bytes: 256
program abc121d
  integer(8) a, b
  read *, a, b
  if (a > 0) a = a - 1
  print *, xor(f(a), f(b))
contains
  recursive function f(n) result(res)
    integer(8), intent(in) :: n
    integer(8) res
    res = merge(n, xor(n, f(n - 1)), mod(n, 4) == 0)
  end function f
end program abc121d


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
const int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, int b, int _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

void solve() {
  deque<char> deq;
  string s;
  cin >> s;
  rep(i, sz(s)) deq.push_back(s[i]);

  int q;
  cin >> q;
  int key = 0;
  while (q--) {
    int x;
    cin >> x;
    if (x == 1) {
      key ^= 1;
      continue;
    }

    int f; char c;
    cin >> f >> c;
    if ((key == 0 && f == 1) || (key == 1 && f == 2)) deq.push_front(c);
    else deq.push_back(c);
    // cout << key << " "; rep(i, sz(deq)) cout << deq[i]; cout << endl;
  }
  if (key == 0) { rep(i, sz(deq)) cout << deq[i]; cout << endl; }
  else { for (int i = sz(deq) - 1; i >= 0; --i) cout << deq[i]; cout << endl; }
}


Measured memory_bytes: 976
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int ar[3][10] = {
                {0, 0, 0, 0, 0, 0, 1, 1, 1, 2 },
                {1, 1, 1, 2, 2, 3, 2, 2, 3, 3 },
                {2, 3, 4, 3, 4, 4, 3, 4, 4, 4 }
    };

    int n;
    cin >> n;

    LL m, a, r, c, h;
    m = a = r = c = h = 0;
    for( int i = 0; i < n; ++i ) {
        string s;
        cin >> s;
        if( s[0] == 'M' ) ++m;
        if( s[0] == 'A' ) ++a;
        if( s[0] == 'R' ) ++r;
        if( s[0] == 'C' ) ++c;
        if( s[0] == 'H' ) ++h;
    }

    LL tmp[5];
    tmp[0] = m; tmp[1] = a; tmp[2] = r; tmp[3] = c; tmp[4] = h;

    LL ans = 0;
    for( int i = 0; i < 10; ++i ) {
        ans +=  tmp[ar[0][i]] * tmp[ar[1][i]] * tmp[ar[2][i]];

    }

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


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder {
  public class Program {
    public static void Main (string[] args) {
      new Program ().Solve (new ConsoleInput (Console.In, ' '));
    }
    public void Solve (ConsoleInput cin) {
      var a = cin.ReadInt;
      var b = cin.ReadInt;
      var c = cin.ReadInt;
      if (a == b && b == c) {
        WriteLine ("No");
      } else if (a != b && b != c && a != c) {
        WriteLine ("No");
      } else {
        WriteLine ("Yes");
      }

    }
  }

  public class ConsoleInput {
    private readonly System.IO.TextReader _stream;
    private char _separator = ' ';
    private Queue<string> inputStream;
    public ConsoleInput (System.IO.TextReader stream, char separator = ' ') {
      this._separator = separator;
      this._stream = stream;
      inputStream = new Queue<string> ();
    }
    public string Read {
      get {
        if (inputStream.Count != 0) return inputStream.Dequeue ();
        string[] tmp = _stream.ReadLine ().Split (_separator);
        for (int i = 0; i < tmp.Length; ++i)
          inputStream.Enqueue (tmp[i]);
        return inputStream.Dequeue ();
      }
    }
    public string ReadLine { get { return _stream.ReadLine (); } }
    public int ReadInt { get { return int.Parse (Read); } }
    public long ReadLong { get { return long.Parse (Read); } }
    public double ReadDouble { get { return double.Parse (Read); } }
    public string[] ReadStrArray (long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
    public int[] ReadIntArray (long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
    public long[] ReadLongArray (long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
  }
}

Measured memory_bytes: 11220
# Problem https://atcoder.jp/contests/abc053/tasks/abc053_b
# Python 1st Try
import copy


class Problem:
    def __init__(self, stringdata):
        self.stringdata = stringdata

    def solver(self):
        strcont = copy.copy(self.stringdata)
        result = 0
        rightposition = 0
        leftposition = len(strcont)
        j = 0
        while True:
            if strcont[j] == 'A':
                rightposition = j
                break
            else:
                j = j + 1
        j = leftposition - 1
        while True:
            if strcont[j] == 'Z':
                leftposition = j
                break
            else:
                j = j - 1

        result = leftposition - rightposition + 1
        return result


if __name__ == "__main__":
    s = input()
    print("{}".format(Problem(s).solver()))


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

int main(){
  string s,t; cin>>s>>t;
  for(int i=0;i<s.size();i++){
    if(s[i]!=t[i]){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 3608
import sys
input=sys.stdin.readline
import math

A,B = (int(x) for x in input().rstrip('\n').split())
c = math.gcd(A,B)
if c==1:
  print(1)
else:
  ps=[]
  d = math.floor(math.sqrt(c))
  for i in range(2,d+2):
    if c%i==0:
      if all(i%x!=0 for x in ps):
        ps.append(i)
        while c % i ==0:
          c = c//i
  if c > 1:
    ps.append(0)
  print(len(ps)+1)

Measured memory_bytes: 9212
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        m: usize,
        mut v: [usize1; m]
    }
    v.sort_by(|x, y| y.cmp(&x));
    let tab = [2, 5, 5, 4, 5, 6, 3, 7, 6];
    let mut dig: Vec<usize> = vec![0; m];
    for i in 0..m {
        dig[i] = tab[v[i]];
    }
    let mut dp: Vec<Vec<usize>> = vec![Vec::new(); n + 1];
    dp[0] = vec![0; 9];
    for i in 0..n {
        if dp[i].len() == 0 {
            continue;
        }
        for j in 0..m {
            if i + dig[j] > n {
                continue;
            }
            let mut t = dp[i].clone();
            t[j] += 1;
            dp[i + dig[j]] = max_digs(dp[i + dig[j]].clone(), t);
        }
    }
    print_digs(&dp[n], &v);
}

fn max_digs(x: Vec<usize>, y: Vec<usize>) -> Vec<usize> {
    let xsum: usize = x.iter().clone().sum();
    let ysum: usize = y.iter().clone().sum();
    if xsum > ysum {
        return x;
    } else if xsum < ysum {
        return y;
    }
    for i in 0..x.len() {
        if x[i] > y[i] {
            return x;
        } else if x[i] < y[i] {
            return y;
        }
    }
    x
}

fn print_digs(x: &Vec<usize>, v: &Vec<usize>) {
    for i in 0..x.len() {
        for j in 0..x[i] {
            print!("{}", v[i] + 1);
        }
    }
    println!("");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
vector<int> ki[220000],ans;
void dfs(int now,int last = -1){
    for(int next:ki[now]){
        if(next == last)continue;
        ans[next] += ans[now];
        dfs(next,now);
    }
}
int main()
{
    int n,q;
    cin >> n >> q;
    ans.resize(n);
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        --a;--b;
        ki[a].push_back(b);
        ki[b].push_back(a);
    }
    rep(i,q){
        int p,x;
        cin >> p >> x;
        --p;
        ans[p]+=x;

    }
    dfs(0);
    rep(i,n)cout << ans[i] << endl;
    return 0;
}

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

int main(void) {
  string n;
  cin >> n;
  vector<long long> r(10, 0);
  for (const char &a : n) {
    r[(a - '0')]++;
  }

  long long summary = 0;
  for (int i = 1; i < 9; ++i) {
    summary += i * (r[i] % 9);
  }

  cout << (summary % 9 == 0 ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 3688
use proconio::input;

fn main() {
    input!(n: usize, a: [u32; n]);
    let mut a_sorted = a.clone();
    a_sorted.sort();
    let l = a_sorted[n / 2 - 1];
    let r = a_sorted[n / 2];
    for x in a {
        println!("{}", if x <= l { r } else { l });
    }
}


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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;


signed main() {
    int A, B;
    cin >> A >> B;
    for (int i = 0; i <= 10000; ++i) {
        if ((int) i * 8 / 100 == A && (int) i / 10 == B) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256