akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
#define fl(i,a,n) for(int i=a;i<=n;i++)
#define pb push_back
#define pob pop_back
#define int long long int
#define ff first
#define ss second
#define pi 3.1415926535898
#define vi vector<int>
#define mi map<int,int>
#define umi unordered_map<int,int>
#define endl "\n"
#define w(x) int x; cin>>x; while(x--)
#define db(x) cout<<(#x)<<" "<<(x)<<"\n";
#define ios ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;
//using namespace boost::multiprecision;
int mod=1000000007;
int gcd(int a,int b){
     return (b == 0) ? a :gcd(b, a % b);
}
int lcm(int a,int b){
    return (a*b)/gcd(a,b);
}
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
int32_t main(){
    
    ios
    //c_p_c();
    //w(t)
    {
        map<string,int>mp;
        mp["SUN"]= 0;
        mp["MON"]= 1;
        mp["TUE"]=2;
        mp["WED"]=3;
        mp["THU"]= 4;
        mp["FRI"]= 5;
        mp["SAT"]= 6;
        string s;
        cin>>s;
        fl(i,0,s.length()-1){
            s[i]=toupper(s[i]);
        }
        cout<<abs(7-mp[s]);

    }

    return 0;
}



Measured memory_bytes: 256
N, M = map(int,input().split(" "))
nm = [[0 for i in range(N)] for j in range(N)]
for i in range(M):
  x,y = (map(int,input().split(" ")))
  nm[x-1][y-1]=1
  nm[y-1][x-1]=1

cnt = [0]
def dfs(V, s):
  V[s]=1
  if sum(V)==N:
    cnt[0] += 1
  for i in range(N):
    if nm[i][s]==1 and V[i]==0:
      dfs(V,i)
  V[s]=0
  
dfs([0]*N,0)
print(cnt[0])

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define re register
#define ll long long
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
int n;
int main(){
	ll sum=0;
	int h=gi();n=gi();
	for(int i=1;i<=n;i++)sum+=gi();
	if(sum<h)puts("No");
	else puts("Yes");
	return 0;
}


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

namespace AtCoder {
    class Program {
        static void Main(string[] args) {
            var input = Console.ReadLine().First();
            var intAscii = (int)input;
            int nextAscii = intAscii + 1;
            char nextChar = (char)nextAscii;
            Console.WriteLine(nextChar);
        }
    }
}


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

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;

template <class T> vector<T> make_v(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto make_v(size_t N,T... t){return vector<decltype(make_v(t...))>(N,make_v(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    string S; cin >> S;
    S = "." + S;
    int N = S.size();
    vector<int> dp1(N,0),dp2(N,0);

    for(int i = 0; i < N; ++i){
        if(i+1<N && S[i]!=S[i+1]) chmax(dp1[i+1],dp1[i]+1);
        if(i+1<N) chmax(dp1[i+1],dp2[i]+1);
        if(i+2<N) chmax(dp2[i+2],dp1[i]+1);
    }

    cout << max(dp1[N-1],dp2[N-1]) << endl;
    return 0;
}


Measured memory_bytes: 2112
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from scipy.sparse.csgraph import floyd_warshall
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush, heapify
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

def main():
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    a.sort()
    ans = 1
    cnt = 0
    l = 0
    r = n-1
    x = bisect.bisect_left(a,0)
    y = bisect.bisect_right(a,0)
    flag = 0
    if n == 1:
        print(a[0]%mod)
        return
    if n == 2:
        if k == 1:
            print((max(a[0],a[1]))%mod)
        else:
            print(a[0]*a[1]%mod)
        return
    if k == n:
        if x%2 == 0:
            flag = 1
    elif k == n-1:
        if x == n:
            if k%2 == 0:
                flag = 1
        else:
            if x%2 == 1:
                flag = 1
            else:
                if x != n:
                    flag = 1
    else:
        if x == n:
            if k%2 == 0:
                flag = 1
        else:
            flag = 1
    if flag:
        while True:
            if a[l+1] >= 0:
                ans *= a[r]
                ans %= mod
                cnt += 1
                r -= 1
            else:
                if a[l]*a[l+1] >= a[r]*a[r-1] and cnt < k-1:
                    ans *= a[l]
                    ans *= a[l+1]
                    ans %= mod
                    cnt += 2
                    l += 2
                else:
                    ans *= a[r]
                    ans %= mod
                    cnt += 1
                    r -= 1
            if cnt == k:
                break
        print(ans)
    else:
        if 0 in a:
            print(0)
            return
        for i in range(n):
            a[i] = abs(a[i])
        a.sort()
        for i in range(k):
            ans *= a[i]
            ans %= mod
        ans *= -1
        ans %= mod
        print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 99644
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 2e5 + 7, MOD = 1000 * 1000 * 1000 + 7;
int pref[N], dp[N];
struct Aoki {
    int x, v;
} a[N];  
bool comp(Aoki a, Aoki b) {
    return a.x < b.x;
}   
int mod(int n) {
    n %= MOD;
    if (n < 0)
        return n + MOD;
    else
        return n;
}   
int maxl[N];

int post[N];

int n;

int getl(int x) {
    int l = -1, r = n;
    while (l < r - 1) {
        int m = (l + r) >> 1;
        if (pref[m] >= x)
            r = m;
        else
            l = m;   
    }
    return r;
}   

int getr(int x) {
    int l = -1, r = n;
    while (l < r - 1) {
        int m = (l + r) >> 1;
        if (post[m] <= x)
            l = m;
        else
            r = m;
    }   
    return l;
}   

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i].x >> a[i].v;
    }   
    sort(a, a + n, comp);
    for (int i = 0; i < n; ++i)
        maxl[i] = -1;

    pref[0] = a[0].v;
    for (int i = 1; i < n; ++i)
        pref[i] = max(pref[i - 1], a[i].v);
    post[n - 1] = a[n - 1].v;
    for (int i = n - 2; i >= 0; --i)
        post[i] = min(post[i + 1], a[i].v);

    for (int i = 0; i < n; ++i) {
        int l = getl(a[i].v);
        int r = getr(a[i].v);
        /*
        int l = i, r = i;
        for (int j = i; j >= 0; --j) 
            if (a[j].v >= a[i].v)
                l = j;
        for (int j = i; j < n; ++j)
            if (a[j].v <= a[i].v)
                r = j;
        */
        maxl[r] = max(maxl[r], l);                
    }   
    for (int i = 1; i < n; ++i)
        maxl[i] = max(maxl[i], maxl[i - 1]);
    dp[0] = 1;
    pref[0] = 0;
    pref[1] = 1;
    for (int i = 1; i < n; ++i) {
        if (maxl[i - 1] == -1)
            dp[i] = (pref[i] + 1) % MOD;
        else
            dp[i] = mod(pref[i] - pref[maxl[i - 1]]);
        pref[i + 1] = (pref[i] + dp[i]) % MOD;
    }   
    int ans = 0;
    for (int i = maxl[n - 1]; i < n; ++i)
        ans = mod(ans + dp[i]);
    cout << ans << endl;
}   

Measured memory_bytes: 9600
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int W,H,x,y,r;
    cin>>W>>H>>x>>y>>r;
    if (0+r<=x && x<=W-r && 0+r<=y && y<=H-r)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3100
/**
 	Template created by Danel Batyrbek
 	All rights are reserved 2017 (lol)
*/

#include <bits/stdc++.h>

#define speed_up ios_base :: sync_with_stdio(0);cin.tie(0)
#define fr first
#define sc second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define debug(x) cerr << x << '\n';
#define YES "YES"
#define NO "NO"
#define skip continue
#define left(x) x << 1
#define rght(x) x << 1 | 1
#define forn(x, y, z) for(int x = y; x <= z; ++ x)
#define for1(x, y, z) for(int x = y; x >= z; -- x)
#define fname ""
using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef double ld;

const int N = 1e5 + 10;
const int mod = 1e9 + 7;
const int N3 = 1e3 + 10;
const int INF = 2e9 + 10;
const ll LINF = 2e18;

ll a, b, n;

int main(){
#ifndef DEBUG
	if(fname != ""){
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	}
#endif	
	cin >> n >> a >> b;
	ll val = a * (n - 2);
	cout << max(b * (n - 2) - val + 1, 0ll);
	return 0;
}

Measured memory_bytes: 256
def test():
    n,q = map(int,input().split())
    s = input()
    t = [0] * (n+1)
    for i in range(n):
        t[i+1] = t[i] + (1 if s[i:i+2] == "AC" else 0)
    for i in range(q):
        l,r = map(int,input().split())
        print(t[r-1]-t[l-1])


if __name__ == "__main__":
    test()


Measured memory_bytes: 9284
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  int T;
  const int M = 30000;
  bool nonprime[M+1] = {};
  nonprime[0] = nonprime[1] = true;
  vector<int> pv;
  for(int i = 2; i <= M; i++){
    if(nonprime[i]) continue;
    pv.push_back(i);
    for(int j = i * i; j <= M; j += i){
      nonprime[j] = true;
    }
  }
  int N = pv.size();
  while(cin>>T && T){
    int ans = 0;
    for(int i = 0; i < N && pv[i] < T; i++){
      for(int j = i; j < N && pv[i] + pv[j] < T; j++){
        int a = pv[i], b = pv[j];
        int c = T - a - b;
        if(c < b || nonprime[c]) continue;
        if(abs(a - b) < c && c < a + b) ans++;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 964
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <cstring>
#define INF 0x3f3f3f

using namespace std;
const int MAX_V=100001;
struct node
{
    int to, dis, cost, next;
}edge[MAX_V];

int head[MAX_V], d[MAX_V], mcost[MAX_V];//mcoat一个?点??一条?
bool vis[MAX_V];
int n, m, cnt;

void add_edge(int u, int v, int d, int c)
{
    edge[cnt].to=v;
    edge[cnt].dis=d;
    edge[cnt].cost=c;
    edge[cnt].next=head[u];
    head[u]=cnt++;
}

int spfa(int x)
{
    d[x]=0;         //必?！！！
    queue<int> que;
    que.push(x);
    vis[x]=true;
    while(!que.empty())
    {
        int u=que.front();
        que.pop();
        vis[u]=false;
        for(int i=head[u]; i!=-1; i=edge[i].next)
        {
            node e = edge[i];
            if(d[e.to] > d[u]+e.dis)
            {
                mcost[e.to]=e.cost;     ////??最小花?
                d[e.to] = d[u]+e.dis;
                if(!vis[e.to])
                {
                    que.push(e.to);
                    vis[e.to]=true;
                }
            }
            else if(d[u]+e.dis==d[e.to] && e.cost<mcost[e.to])   ////??最小花?
                {
                    mcost[e.to]=e.cost;
                }
        }
    }
    int ans=0;
    for(int i=1; i<=n; i++)
    {
     //   printf("\n%d\n", mcost[i]);
        ans+=mcost[i];
    }
    return ans;
}

int main()
{
    while(scanf("%d %d", &n, &m) && (m+n))
    {
        cnt=0;          //从0?始！！！
        memset(head, -1, sizeof(head)); //初始化在前面！！！！
        for(int i=0; i<m; i++)
        {
            int u, v, d, c;
            scanf("%d %d %d %d", &u, &v, &d, &c);
            add_edge(u,v,d,c);
            add_edge(v,u,d,c);      //双向的路！！！
        }

        //初始化
        memset(mcost, 0, sizeof(mcost));
        fill(d, d+n+1, INF);
        fill(vis, vis+n+1, false);

        int ans=spfa(1);
        printf("%d\n", ans);
    }

    return 0;
}

Measured memory_bytes: 4768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
 
int PF(int num)
{
  int count = 0;
  while(num%2 == 0){
    num /=2;
    count++;
  }
 return count;
}
 
int main(){
  int N;
  vector<int> v;
  //int a=1000000;
  //int c = 0;
  
  cin >> N;
  
  int k = 100;
  for(int i = 0; i <N ; i++){
      cin >> k;
      int p = PF(k);
      //cout << p <<endl;
      v.push_back(p);
  }
   cout << *min_element(v.begin(), v.end()) << endl;
}

Measured memory_bytes: 256
#!perl
use strict;
use warnings;
use utf8;
use feature qw/say/;
 
my $S_a = <STDIN>;
my $S_b = <STDIN>;
my $S_c = <STDIN>;
 
chomp $S_a;
chomp $S_b;
chomp $S_c;
 
my $cards = +{};
$cards->{a} = [split(//, $S_a)];
$cards->{b} = [split(//, $S_b)];
$cards->{c} = [split(//, $S_c)];
 
my $current_player = 'a';
while ( scalar @{$cards->{$current_player}} > 0) {
    $current_player = shift @{$cards->{$current_player}};
}
 
say uc $current_player;


Measured memory_bytes: 768
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    
      string s,t;
  cin>>s;
  cin>>t;
  int i;
  char temp;
  int cnt=0;
  int flag=0;
  
  if(s==t)
     printf("Yes");
     
 else
 {
  while(cnt!=s.length())
  {
      temp=s[s.length()-1];
     for(i=s.length()-1;i>0;--i)
     {
        s[i]=s[i-1];
     }
     
     s[0]=temp;
     
    
    if(s==t)
    {
      flag=1;
      break;
    }
    cnt++;
  }
  
 if(flag==1)
      printf("Yes");
  
  else
      printf("No");
 }
}

Measured memory_bytes: 256
import sys
from fractions import gcd
from itertools import groupby as gb
from itertools import permutations as perm
from collections import Counter as C
from collections import defaultdict as dd
sys.setrecursionlimit(10**5)

s = input()
s = sorted(s)
g = gb(s)
l = len(s)

res = l * (l - 1) // 2 + 1
for k, v in g:
    p = len(list(v))
    res -= p * (p - 1) // 2
print(res)


Measured memory_bytes: 8360
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int N; cin >> N;
	vector<int> A(N + 1, 0);
	for (int i = 1; i <= N; ++i){
		cin >> A[i];
	} // end for

	int total = 0;
	for (int i = 1; i <= N+1; ++i){
		total += abs(A[i % (N+1)] - A[(i-1) % (N+1)]);
	} // end for
//	cerr << total << endl;

	vector<int> diff(N + 1, 0);
	for (int i = 0; i < N; ++i){
//		diff[i+1] = abs(A[i+2] - A[i]) - (abs(A[i+2] - A[i+1]) + abs(A[i+1] - A[i])); 
		diff[(i+1) % (N+1)] = abs(A[(i+2) % (N+1)] - A[i % (N+1)]) - (abs(A[(i+2) % (N+1)] - A[(i+1) % (N+1)]) + abs(A[(i+1) % (N+1)] - A[i%(N+1)]));
//		cerr << diff[(i+1) % (N+1)] << endl;
	} // end for

	for (int i = 1; i <= N; ++i){
		int res = total;
		res += diff[i];
		cout << res << endl;
	} // end for

	return 0;
}

Measured memory_bytes: 2176
#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>>;


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

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

}

//最小公倍数
ll lcm(ll a,ll 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;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}









int main() {
 ll n;
 cin >> n;
 ll a[n+1],ans = 0,sum=0,x[n];

 rep (i,n){
   cin >> a[i];
   sum += a[i];
   sum %= MOD;
   x[i] = sum;
 }
 rep (i,n-1){
   ans += x[i] * a[i+1];
   ans %= MOD;
 }
 cout << fixed << setprecision(0) << fmod(ans,MOD) << endl;
}


Measured memory_bytes: 6972
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var abcd = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int left = abcd[0] + abcd[1], right = abcd[2] + abcd[3];

            if (left > right)
                Console.WriteLine("Left");
            else if (right > left)
                Console.WriteLine("Right");
            else
                Console.WriteLine("Balanced");
        }

    }
}


Measured memory_bytes: 11348
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;
vector<map<ll,ll>>dp;
ll n,m;
vector<vector<ll>> edge;
vector<ll>lmul,rmul;
unordered_map<ll,int>ma;
ll dfs0(ll par,ll node)
{
  if(dp[node].count(par))return dp[node][par];
  ll res=1;
  for(auto nn:edge[node])
  {
    if(nn==par)continue;
    res=(ll)res*(dfs0(node,nn)+1)%m;
  }
  dp[node][par]=res;
  return res;
}
ll dfs(ll par,ll node)
{
  //cout<<par<<" "<<node<<endl;
  if(dp[node].count(par))return dp[node][par];
  if(edge[node].size()==1&&par!=-1)return 1;
  ll mul=1;
  vector<ll>lmul(edge[node].size()),rmul(edge[node].size());
  unordered_map<ll,int>ma;
  lmul.assign(edge[node].size(),0);
  rmul.assign(edge[node].size(),0);
  
  ma.clear();
  int cnt=0;
  for(auto itr=edge[node].begin();itr!=edge[node].end();itr++)
  {
    ma[*itr]=cnt++;
    lmul[ma[*itr]]=mul;
    mul=mul*(dfs(node,*itr)+1)%m;
  }
  mul=1;
  for(auto itr=edge[node].rbegin();itr!=edge[node].rend();itr++)
  {
    rmul[ma[*itr]]=mul;
    mul=mul*(dfs(node,*itr)+1)%m;
  }
  for(ll nn:edge[node])
  {
    dp[node][nn]=lmul[ma[nn]]*rmul[ma[nn]]%m;
  }
  dp[node][-1]=mul;
  return dp[node][par];
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin>>n>>m;
  edge.resize(n);
  dp.resize(n);
  rep(i,n-1)
  {
    ll a,b;
    cin>>a>>b;
    a--;b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  dfs0(-1,0);
  rep(i,n)
  {
    cout<<dfs(-1,i)<<"\n";
  }
  cout<<flush;
  return 0;

}


Measured memory_bytes: 42112
function Main(input) {
  // 数字
  var N = parseInt(input[0], 10);
  var S = input[1];
  var K = parseInt(input[2], 10);
  // 文字
  // var A = input[0];

  var changeStr = S.charAt(K - 1);
  var str = '';

  for (var i = 0; i < S.length; i++) {
    if (S.charAt(i) !== changeStr) {
      str += '*';
    } else {
      str += changeStr;
    }
  }
  console.log(str);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 21064
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();
		StringBuilder buf = new StringBuilder();
		StringBuilder buf2 = new StringBuilder();
		buf.append(str);
		int q = scan.nextInt();
		boolean invert = false;
		for (int i = 0; i<q; i++) {
			int a = scan.nextInt();
			if (a == 1) {
				invert = !invert;
			} else {
				int b = scan.nextInt();
				str = scan.next();
				char[] c = str.toCharArray();
				if (b == 1) {
					if (!invert) {
						buf2.append(c[0]);
					} else {
						buf.append(c[0]);
					}
				} else {
					if (invert) {
						buf2.append(c[0]);
					} else {
						buf.append(c[0]);
					}
				}
			}
		}
		if (invert) {
			System.out.println(new String(buf.reverse())+new String(buf2));
 		} else {
 			System.out.println(new String(buf2.reverse())+new String(buf));
 		}
	}
}


Measured memory_bytes: 122752
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#define ll long long
using namespace std;
const ll inf=0x3f3f3f3f3f3f3f3f;
ll cost[2010];
ll res[2010]; 
int main()
{
	ll n,x;
	cin>>n>>x;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&cost[i]);
		res[i]=cost[i];
	}
	ll ans=1e15;
	for(int k=0;k<n;k++)//xiugai k ci
	{
		ll temp=0;
		for(int i=1;i<=n;i++)//mei ge slime
		{
			ll low;
			if(i<=k)
			{
				low=min(res[i],cost[n-(k-i)]);
			}
			else
			{
				low=min(res[i],cost[i-k]);
			}
			res[i]=low;
			temp+=low;
		}
		temp+=k*x;
		ans=min(ans,temp);
	}
	printf("%lld",ans);
} 

Measured memory_bytes: 256
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7
N = 10**4
g1 = [1, 1]
g2 = [1, 1]
inverse = [0, 1]
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
N,K=map(int,input().split())
mod=10**9+7
ans=0
k=N-K
for i in range(K):
  ans=cmb(N-K+1,i+1,mod)*cmb(K-1,i,mod)
  print(ans%mod)

Measured memory_bytes: 10404
[n,a,b]=require('fs').readFileSync('/dev/stdin','utf8').split(' ').map(n=>n|0)
for(c=0,i=0;++i<=n;a<=r&&r<=b&&(c+=i))
	r=(i+'').split('').map(n=>n|0).reduce((a,b)=>a+b)
console.log(c)

Measured memory_bytes: 10856
package main

import (
	"fmt"
)

func doubleFactorial(n int) int {
	if n&1 == 1 {
		return 0
	}

	var c, m int
	m = 10
	for n >= m {
		c += n / m
		m *= 5
	}
	return c
}

func main() {
	var n int
	fmt.Scan(&n)
	fmt.Println(doubleFactorial(n))
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
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; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main(){
    int n;cin >> n;
    if(n<10)cout << n <<endl;
    else if(n>=10 and n<100)cout << 9 <<endl;
    else if(n>=100 and n<1000)cout << n-99+9 <<endl;
    else if(n>=1000 and n<10000)cout << 909 << endl;
    else if(n>=10000 and n<100000)cout << n-9999+909 <<endl;
    else cout << 90000+900+9 <<endl;
    return 0;
}

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


 


int main()
{
  long long h , n;
  cin >> h>> n; 

  long long sum = 0;

  for(int i= 0 ; i < n ;i++)
  {
    int a ;
    cin >> a;
    sum += a ;

  }

  if( sum >= h)
  {
    cout <<"Yes";
  }else{
    cout <<"No";
  }

  return 0;
}


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

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

void split( vector<int>& vi, string in ) {
    int i=0;
    while( i < in.length() ) {
        int x = 0;
        while( i < in.length() && in[i]!=' ' ) {
            x *= 10;
            x += in[i]-'0';
            i++;
        }
        vi.push_back(x);
        i++;
    }
}

int main(){
    string in;
    while( getline(cin, in), !(in.length()==1 && in[0]=='0') ) {
        vector<int> vi;
        split( vi, in );
        int score=0, one=0;
        rep(i, vi.size()) {
            if( vi[i] == 1 ) {
                one++;
                score += 1;
            } else {
                score += min(10, vi[i]);
            }
        }
        while( one && score+10<=21 ) {
            score += 10;
            one--;
        }
        cout << (score<=21 ? score : 0) << endl;
    }
    return 0;
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
#include<string.h>
#define ll long long
#define pf printf
#define sf scanf
#define ff first
#define ss second
#define clr clear()
#define sz size()
#define pb push_back
#define mk make_pair
#define pi acos(-1)
#define inf 20000000000000000
#define mod 1000000007
#define ull unsigned long long int
#define f(i,k,n) for(i=k;i<n;i++)
#define fr(i,n,k) for(i=n;i>=k;i--)
#define ent(a) scanf("%lld",&a)
#define ent2(a,b) scanf("%lld%lld",&a,&b)
#define ent3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define mem(a) memset(a,0,sizeof(a))
#define vec(v,s) vector<ll>v[s]
#define arr(a,s) ll a[s];
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
//knight and king//
int dr[]= {2,2,-2,-2,1,-1,1,-1};
int dc[]= {1,-1,1,-1,2,2,-2,-2};
int dr1[]= {0,0,1,1,1,-1,-1,-1};
int dc1[]= {1,-1,1,0,-1,0,1,-1};
int dr2[]= {0,0,1,-1};
int dc2[]= {1,-1,0,0};
////////////////////////////
using namespace std;
#define ma 1000005
ll a[ma],mark[ma];
int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);cout.tie(0);
   ll i,j,x,y,n;
   while(cin>>n)
   {
      for(i=1;i<=n;i++)
      {
          cin>>x;
          mark[x]++;
      }
      for(i=1;i<=1000000;i++)
      {
          if(mark[i]==0)continue;
          for(j=i;j<=1000000;j+=i)
          {
              a[j]+=mark[i];
          }
      }
      ll ans=n;
      for(i=1;i<=1000000;i++)
      {
          if(mark[i]==0)continue;
          //cout<<mark
          if(a[i]>1)ans-=mark[i];
      }
      cout<<ans<<endl;
   }
   return 0;

}




Measured memory_bytes: 19188
import math

s = input().split()

a = int(s[0])
b = int(s[1])
c = int(s[2])
sin = math.sin(math.radians(c))
cos = math.cos(math.radians(c))

S = 0.5*a*b*sin 
d = math.sqrt((b*sin)**2+(a-b*cos)**2)
L = a+b+d
h = b*sin
print(S)
print(L)
print(h)


Measured memory_bytes: 5712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll n,rem;
  cin>>n;
  string ans="";
  while(n)
  {
      rem=n%26;
      if(rem==0){rem=26;n--;}
      ans+=rem+'a'-1;
      n=n/26;
  }
  reverse(ans.begin(),ans.end());
  cout<<ans<<"\n";
  return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int n,k,s,co;
void f(int a,int c,int sum){
  if(c==n){
    if(sum==s)co++;
    return;
  }
  loop(i,a,k+1){
    if(sum+i>s)break;
    f(i+1,c+1,sum+i);
  }
}
int main(){
  while(cin>>k>>n>>s,n+k+s){
    co=0;
    f(1,0,0);
    cout<<co<<endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
	int N;
	cin >> N;

	int min = 0, max = 0;
	int min_idx = 0, max_idx = 0;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		if (min > A) {
			min = A; min_idx = i;
		}

		if (max < A) {
			max = A; max_idx = i;
		}
	}

	cout << 2 * N - 1 << endl;
	if (abs(min) < abs(max)) {
		for (int i = 0; i < N; i++) {
			//A[i] += max;
			cout << max_idx + 1 << " " << i + 1 << endl;
		}

		for (int i = 0; i < N - 1; i++) {
			//A[i + 1] += A[i];
			cout << i + 1 << " " << i + 2 << endl;
		}
	} else {
		for (int i = 0; i < N; i++) {
			//A[i] += min;
			cout << min_idx + 1 << " " << i + 1 << endl;
		}

		for (int i = N - 1; i >= 1; i--) {
			//A[i - 1] += A[i];
			cout << i + 1 << " " << i << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>


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

  int a[20];
  int b[20];
  int c[19];

  for(int i = 1; i <= n; i++){
	  scanf("%d",&a[i]);
  }
  for(int i = 1; i <= n; i++){
	  scanf("%d",&b[i]);
  }
  for(int i = 1; i < n; i++){
	  scanf("%d",&c[i]);
  }

  int ans = 0;
  int now_ind = 0;
  int prev_ind = 0;

  /*満足度の集計*/
  for(int i = 1; i <= n; i++){
	  prev_ind = a[i-1];
	  now_ind = a[i];
	  //Bの満足度を加算
	  ans += b[now_ind];

	  /* Cの条件
	   * そのとき追加
	   * */
	  int judge_c = (i > 1) && (now_ind - prev_ind == 1);
	  if(judge_c){
		  ans += c[prev_ind];
	  }
  }
  printf("%d\n", ans);


  return 0;
}


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


using namespace std;


struct Node {
	int key;
	Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k) 
{
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = new Node;
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL) {
		y = x;
		if (z->key < x->key) {
			x = x->left;
		}
		else {
			x = x->right;
		}
	}

	z->parent = y;

	if (y == NIL) {
		root = z;
	}
	else {
		if (z->key < y->key) {
			y->left = z;
		}
		else {
			y->right = z;
		}
	}

}

void inorder(Node *u) {
	if (u == NIL) {
		return;
	}

	inorder(u->left);
	cout << " " <<u->key;
	inorder(u->right);
}


void preorder(Node *u) {
	if (u == NIL) {
		return;
	}

	cout << " " << u->key;
	preorder(u->left);
	preorder(u->right);
}


int main(void)
{
	int n;
	string command;
	int key;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> command;

		if (command == "insert") {
			cin >> key;
			insert(key);
		}
		else if (command == "print") {
			inorder(root);
			cout << endl;
			preorder(root);
			cout << endl;

		}

	}

	return 0;

}

Measured memory_bytes: 26576
#include<stdio.h>
#include<string.h>
void ope(char *p,int ln){
    int i;
    char lol = p[ln-1];
    for(i=ln-1;i>0;i--){
    p[i] = p[i-1];
    }
    p[0]=lol;
    p[ln]='\0';

}
/*void reverse(char *p,int ln){
    int i=0,j=ln-1;
    char lol;
    for(i=0,j=ln-1;j>i;i++,j--){
    //	printf("%c\n",p[i]);
    lol=p[i];
    p[i]=p[j];
    p[j]=lol;
  //  printf("%d\t%c\n",j,p[j]);
    }
    p[ln]='\0';

}*/
int main(){
	int i;
    char s[110];
    char t[110];
    gets(s);
    gets(t);
    int ln=strlen(t);
    //printf("%s\n",s);
    	//i=strcmp(s,t);
    //	printf("%d\n",i);
    //reverse(t,ln);
    //printf("%s\n",t);
    //int i;
    
    if(strcmp(s,t)==0){
    
    printf("Yes\n");
    return 0;
    }
    else{
    for(i=0;i<ln;i++){
    ope(s,ln);
    //printf("%s\n",t);
    if(strcmp(s,t)==0){
        printf("Yes\n");
        return 0;
    }

    }
    printf("No\n");

    }



    return 0;
    }


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

int main() {
  std::string input;
  std::cin >> input;
  int max_c = 0;
  int cnt = 0;
  for (int i=0; i<input.size(); i++) {
    if (input[i]=='A' || input[i]=='T' ||input[i]=='G' ||input[i]=='C'){
      cnt += 1;
      max_c = std::max(cnt, max_c);
    } else {
      max_c = std::max(cnt, max_c);
      cnt = 0;
    }
  }
  std::cout << max_c << std::endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		
		int[] dp = new int[n + 1];
		Arrays.fill(dp, 0);
		System.out.println(fib(n, dp));
		scan.close();
	}

	public static int fib(int i, int[] dp) {
		if (dp[i] != 0) {
			return dp[i];
		}
		
		if (i == 0 || i == 1) {
			return dp[i] = 1;
		}else{
			return dp[i] = fib(i - 1, dp) + fib(i - 2, dp);
		}
		
	}
}

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

int main() {
    int r, d;
    cin >> r >> d;
    vector<int> x(11);
    cin >> x.at(0);
    rep(i, 10) x.at(i + 1) = r * x.at(i) - d;
    rep(i, 10) cout << x.at(i + 1) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
int abs(int a,int b){
  int c=max(a,b)-min(a,b);
  return c;
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  double a,b=0;
  string c;
  int d;
  cin>>d;
  for(int i=0;i<d;i++){
    cin>>a>>c;
    if(c=="JPY") b+=a;
    else{
      a*=380000.0;
      b+=a;
    }
  }
  cout<<b<<"\n";
}


Measured memory_bytes: 256
from collections import Counter
from itertools import accumulate
from math import factorial
from sys import stdin


def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))


def main():
    _ = int(stdin.readline().rstrip())
    Ai = [int(x) for x in stdin.readline().rstrip().split()]
    Si = [0] + list(accumulate(Ai))
    result = 0
    c = Counter(Si)
    for k, v in c.items():
        if v == 1:
            continue
        result += combinations_count(v, 2)
    print(result)


if __name__ == "__main__":
    main()


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

bool solve() {
    string g;
    cin >> g;
    if(g == "#") return false;
    int y, m, d;
    cin >> y >> m >> d;
    if(y >= 32 || (y == 31 && m >= 5)) {
        g = "?";
        y -= 30;
    }
    cout << g << ' ' << y << ' ' << m << ' ' << d << endl;
    return true;
}

int main() {
    while(solve());
    return 0;
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i = 0, i_len = n; (i) < (i_len); ++(i))
#define repp(i,n) for(int i = 1, i_len = n; (i) <= (i_len); ++(i))
#define per(i,n) for(int i = n-1; (i) >= 0; --(i))
#define perr(i,n) for(int i = n; (i) > 0; --(i))
#define sz(x) ((int)(x).size())
#define popcnt __builtin_popcount
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).begin(),(v).end(),greater<>()
#define debug(x) cerr << #x << ':' << x << '\n'
#define Pi 3.1415926535
#define MOD 1000000007
using namespace std;
using ll = long long;
using pint = pair<int,int>;
using itn = int;
using vint = vector<int>;
template<class T,class S> inline bool chmax(T& a, S b){if(a<b){a = b; return true;} return false;}
template<class T,class S> inline bool chmin(T& a, S b){if(a>b){a = b; return true;} return false;}
template<class T> T gcd(T a, T b){return b?gcd(b,a%b):a;}
template<class T> T lcm(T a, T b){return a*b/gcd(a,b);}
void yes(){cout << "Yes" << '\n';}
void no(){cout << "No" << '\n';}

int solve(){
    string s; cin >> s;
    cout << s << (s[s.size() - 1] == 's' ? "es" : "s") << endl;
    return 0;
}

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


Measured memory_bytes: 3652
n=input()
op_cnt=len(n)-1
for i in range(2**op_cnt):
    s=n[0]
    for j in range(op_cnt):
        if ((i>>j)&1):
            s+="+"
        else:
            s+="-"
        s+=n[j+1]
    if eval(s)==7:
        print(s+"=7")
        exit()


Measured memory_bytes: 3060
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from math import factorial


def comb(n, r):
    nf = factorial(n)
    rf = factorial(r)
    nrf = factorial(n - r)
    return int(nf / (rf * nrf))


n, a, b = map(int, input().split())
goods = list(reversed(sorted([int(x) for x in input().split()])))

avg, total = sum(goods[:a]) / a, 0

lastcount, lastindex = 0, 0
for i, val in enumerate(goods):
    if val == goods[a - 1]:
        lastcount += 1
        if i < a:
            lastindex += 1

if goods[0] != goods[a - 1]:
    total += comb(lastcount, lastindex)
else:
    for i in range(a - 1, b):
        if goods[a - 1] != goods[i]: break
        total += comb(lastcount, i + 1)

print("{}\n{}".format(avg, total))


Measured memory_bytes: 3192
#include<iostream>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;

int main(){
  int n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  int cnt = 0;
  rep(i,n-1){
    if(s[i]==s[i+1])cnt++;
  }
  int ans = min(cnt+2*k,n-1);
  cout << ans << endl;
}


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

int main() {
    int N;
    cin >> N;
    int SN = 0;
    int M = N;
    while(M > 0){
        SN += M % 10;
        M /= 10;
    }
    if (N % SN == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
	return 0;
}

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

template <
    typename TYPE,
    std::size_t SIZE>
std::size_t a_len(const TYPE (&array)[SIZE])
{
    return SIZE;
}

using namespace std;
using ll = long long int;
using vi = vector<ll>;

#define REPS(a, i, n) for (ll(i) = a; (i) < (n); ++(i))
#define REP(i, n) REPS(0, i, n)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 912345678;


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

    map<char,int> a;
    REP(i,4){
        a[s[i]]++;
    }
    bool ok =true;
    for(auto x:a){
        if(x.second != 2){
            ok = false;
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N,M;cin >> N >> M;
  //first:報酬．second:日程
  vector<PII> v(N);
  rep(i,N)cin >> v[i].second >> v[i].first;
  sort(all(v),greater<PII>());
  set<int> st;
  rep(i,M)st.insert(-i);
  int ans = 0;
  rep(i,N){
    auto it = st.lower_bound(-(M-v[i].second));
    if(it == st.end())continue;
    st.erase(it);
    ans += v[i].first;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<pii>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

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

    int H, W, N;
    cin >> H >> W >> N;
    if (H < W)
        swap(H, W);
    cout << (N + H - 1) / H << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ":" << x << "\n"
using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>;

int cost(vector<int> &h, int i, int j) {
	return abs(h[i] - h[j]);
}

int main () {
	const int INF = pow(10, 9);
	int N; cin >> N;
	vi h(N); rep(i, N) cin >> h[i];
	vi dp(N, INF); dp[0] = 0; // 足場i(0-ind)までたどり着くための最小コスト
	rep2(i, 1, N) dp[i] = min(dp[max(i - 2, 0)] + cost(h, i, max(i - 2, 0)), dp[i - 1] + cost(h, i, i - 1));
	cout << dp[N - 1] << endl;
}

Measured memory_bytes: 1024
N, M, X = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]

final = 1000000000

for i in range(1, 2**N):
    ans = 0
    rikai = [0]*M
    for j in range(N):
        if ((i >> j) & 1):
            for k in range(1, M+1):
                rikai[k-1] += A[j][k]
            ans += A[j][0]
    if all(el >= X for el in rikai):
        final = min(final, ans)

if final == 1000000000:
    print(-1)
else:
    print(final)


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

template<typename T>
class RollingHash{
  public:
    const int K = 2;
    vector<T> M, B;
    vector<vector<T>> hash, p;

    RollingHash(){}

    RollingHash(const string &s, vector<T> b={107,10007}){
      init(s, b);
    }

    void init(const string &s,
        vector<T> b={107, 10007},
        vector<T> m={10001237, 1000000009}){

      M = m; B = b;
      hash.resize(K); p.resize(K);

      int n = s.size();
      for(int i = 0; i < K; i++){
        hash[i].assign(n+1, 0); 
        p[i].assign(n+1, 1);

        for(int j = 0; j < n; j++){
          hash[i][j+1] = (hash[i][j]*B[i] + s[j])%M[i];
          p[i][j+1] = p[i][j]*B[i]%M[i];
        }
      }
    }

    vector<T> find(int l, int r){
      vector<T> res(K);
      for(int i = 0; i < K; i++){
        T tmp = hash[i][r] + M[i] - hash[i][l]*p[i][r-l]%M[i];
        res[i] = tmp >= M[i] ? tmp-M[i] : tmp;
      }
      return res;
    }
};

int n;
string s;
RollingHash<int> rh;

bool check(int len){
  if(len == 0) return true;
  map<vi, int> memo;
  for(int i = n-len; i >= 0; i--){
    vi t = rh.find(i, i+len);
    if(memo.count(t) > 0){
      if(memo[t] >= i+len){
        return true;
      }
    }else{
      memo[t] = i;
    }
  }
  return false;
}

signed main(){
  cin >> n >> s;
  rh.init(s);

  int l = 0, r = n;
  while(r-l > 1){
    int m = (l+r)/2;
    if(check(m)) l = m;
    else r = m;
  }
//  rep(i, 0, n) if(check(i)) chmax(l, i);

  cout << l << endl;

  return 0;
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

string s;

int x, y;

bool check(vector<int>& dir, int goal, int start) {
  set<int> last;

  last.insert(start);

  for (auto& e : dir) {
    set<int> cur;

    for (auto& d : last) {
      cur.insert(d + e);
      cur.insert(d - e);
    }

    last = cur;
  }

  return last.find(goal) != last.end();
}

int main(void) {
  // Here your code !
  cin >> s;

  if (s.back() == 'F') s.push_back('T');

  scanf("%d %d", &x, &y);

  vector<int> dir_x;
  vector<int> dir_y;

  int parity = 0;
  int cur = 0;

  for (auto& e : s) {
    if (e == 'T') {
      if (parity % 2 == 0) {  // direction: x
        dir_x.push_back(cur);
      } else {  // direction: y
        dir_y.push_back(cur);
      }
      cur = 0;
      parity += 1;
    } else {
      cur += 1;
    }
  }

  int beg_x = 0;
  int beg_y = 0;

  if (s[0] == 'F') {
    beg_x += dir_x[0];
    dir_x.erase(dir_x.begin());
  }

  if (check(dir_x, x, beg_x) && check(dir_y, y, beg_y)) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}


Measured memory_bytes: 640
package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

var sc = newScanner()

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

func main() {
	s := scanString()
	answer := s[:3]
	fmt.Println(answer)
}

func debug(a ...interface{}) {
	fmt.Println(a...)
}


Measured memory_bytes: 1760
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;


static class P
{
    static void Main()
    {
        long n = long.Parse(Console.ReadLine());
        long a = long.Parse(Console.ReadLine());
        long b = long.Parse(Console.ReadLine());
        long c = long.Parse(Console.ReadLine());
        long d = long.Parse(Console.ReadLine());
        long e = long.Parse(Console.ReadLine());
        var hoge = Min(Min(Min(Min(a, b), c), d), e);
        Console.WriteLine(n / hoge + (n % hoge == 0 ? 0 : 1) + 4);
    }
}


Measured memory_bytes: 13140
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		for(int i=1; i<1300; i++){
			if(i*8/100==a && i/10==b){
				System.out.println(i);
				return;
			}
		}
		System.out.println(-1);
	}
}


Measured memory_bytes: 23764