akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll mod(ll ans)
{
    if(ans<0)
    {
        return mod((ans%1000000007)+1000000007);
    }
    else
        return (ans%1000000007);
}
int main()
{
    ll t,n,i,j,k,l,x,y,pos=0,neg=0;
    cin>>n>>l;
    vector<ll>vpos,vneg;
    for(i=0; i<n; i++)
    {
        cin>>k;
        if(k<0)
        {
            k=-k;
            vneg.push_back(k);
            neg++;
        }
        else
        {
            vpos.push_back(k);
            pos++;
        }
    }
    if(neg>0)
        sort(vneg.begin(),vneg.end());
    if(pos>0)
        sort(vpos.begin(),vpos.end());
    ll ans=1;
    if(neg==0)
    {
        for(i=0; i<l; i++)
        {
            ans*=vpos[pos-1];
            ans=mod(ans);
            pos--;
        }
    }
    else if(pos==0)
    {
        if(l%2==0)
        {
            for(i=0; i<l;i++)
            {
                ans*=(-vneg[neg-1]);
                ans=mod(ans);
                neg--;
            }
        }
        else
        {
            for(i=0; i<l; i++)
            {
                ans*=(-vneg[i]);
                ans=mod(ans);
            }
        }
    }
    else
    {
        if(l%2==1)
        {
            ans=vpos[pos-1];
            pos--;
            l--;
        }
        while(l>1&&(pos>=2||neg>=2))
        {
            ll mpos=0;
            if(pos>=2)
            {
                mpos=vpos[pos-1]*vpos[pos-2];
            }
            ll mneg=0;
            if(neg>=2)
            {
                mneg=vneg[neg-1]*vneg[neg-2];
            }
            if(mpos>mneg)
            {
                mpos=mod(mpos);
                ans*=mpos;
                ans=mod(ans);
                pos-=2;
            }
            else
            {
                mneg=mod(mneg);
                ans*=mneg;
                ans=mod(ans);
                neg-=2;
            }
            l-=2;

        }
        while(l>0)
        {
            if(pos>0)
            {
                ans*=vpos[pos-1];
                ans=mod(ans);
                pos--;
                l--;


            }
            else if(neg>0)
            {
                ans*=(-vneg[neg-1]);
                ans=mod(ans);
                neg--;
                l--;

            }
        }
    }
        //ans=mod(ans);
        cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 5444
/*
オーダー
10**6	余裕を持って間に合う	
10**7	おそらく間に合う	余裕を持って間に合う
10**8	非常にシンプルな処理でない限り厳しい	おそらく間に合う
10**9		非常にシンプルな処理でない限り厳しい
logn	:OK
n		:10^7
nlogn	:10^6
n**2	:10^4
n**3	:300
2**n	:20
n!		:10



// 各桁の和を計算する関数
int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) { // n が 0 になるまで
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート

int num[110] = {0};  // バケット
for (int i = 0; i < N; ++i) {
    num[d[i]]++;  // d[i] が 1 個増える
}

map<string, int> mp; // 連想配列 map<キー型, 値型> オブジェクト名
for (int i = 0; i < N; ++i) {
    auto itr = mp.find(s[i]);        // s[i] が設定されているか？
    if(itr != mp.end() ) {
         mp[s[i]] += 1;
    }
    else {
         mp[s[i]] += 1 ;
    }
}
stack<int> s;	//intをデータとするスタックを用意
s.push(1);		//{} -> {1}
printf("%d\n", s.top());	// 3
s.pop();

queue<int> que;	//intをデータとするキューを用意
que.push(1);		//{} -> {1}
printf("%d\n", que.front());	// 1
que.pop();
*/

#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18
// int 
// // 各桁の和を計算する関数
// int findSumOfDigits(int n) {
//   int amari = 0;
//   int keta = 0;
//   while (n > 0) { // n が 0 になるまで
//     amari += n % 2;
//     if (keta%2==0)
//     n /= 10;
//   }
//   return sum;
// }
 
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}

// const ll MAX_N = 1e5;
// ll N;
// ll h[MAX_N];
// ll dp[MAX_N+1]; // メモ化テーブル
 
// // i番目以降の品物から重さの総和がj以下になるように選ぶ
// void rec(ll i){
// 	if (i==0) dp[i] = 0;
// 	else if (i==1) dp[i] = abs(h[1]-h[0]);
// 	else dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]));
// 	return;
// }
 
 
int main() {
	// 入力
	ll N,M,C;
	cin >> N>>M>>C;
	ll B[M];
	REP(i,M) cin>>B[i];
	ll A[N][M];
	REP(i,N){
		REP(j,M){
			cin>>A[i][j];
		}
	}
	
	// 解法
	ll count = 0;
	REP(i,N){
		ll ans = C;
		REP(j,M){
			ans += A[i][j]*B[j];
		}
		if (ans>0) count++;
	}
	
	//出力
	cout << count << endl;
}


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

int main() {
    /* 入力受け取り */
    int n, Q;
    cin >> n >> Q;
    vector<long long> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i];

    /* Q 回分のクエリを処理 */
    for (int j = 0; j < Q; ++j) {
        long long x; cin >> x; // 各クエリ x

        /* 合計値 */
        long long res = 0;

        /* 区間の左端 left で場合分け */
        int right = 0;     // 毎回 right を使い回すようにする
        long long sum = 0; // sum も使い回す
        for (int left = 0; left < n; ++left) {
            /* sum に a[right] を加えても大丈夫なら right を動かす */
            while (right < n && sum + a[right] <= x) {
                sum += a[right];
                ++right;
            }

            /* break した状態で right は条件を満たす最大 */
            res += (right - left);

            /* left をインクリメントする準備 */
            if (right == left) ++right; // right が left に重なったら right も動かす
            else sum -= a[left]; // left のみがインクリメントされるので sum から a[left] を引く
        }

        cout << res << endl;
    }
}


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

int main()
{
    int n, w[102];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> w[i];
    }
    int ans = 10000000;
    for(int i = 0; i < n; i++){
        int s1 = 0, s2 = 0;
        for(int j = 0; j < i; j++){
            s1 += w[j];
        }
        for(int j = i; j < n; j++){
            s2 += w[j];
        }
        ans = min(ans, abs(s1 - s2));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll ara[200002];
vector<ll>seq;
map<ll,ll>mp;

int main()
{
    ll n,i,a,k;
    cin>>n>>k;
    for(i=1;i<=n;i++)scanf("%lld",&ara[i]);
    a=ara[1],i=0;
    while(mp[a]==0)
    {
        mp[a]=++i;
        seq.push_back(a);
        a=ara[a];
    }
    if(k<=seq.size())printf("%lld\n",seq[k-1]);
    else
    {
//        for(auto it : seq)cout<<it<<"** ";
//        cout<<endl;
        mp[a]--;
        k-=mp[a];
        i=seq.size()-mp[a];
        k%=i;
        if(k==0)k=seq.size()-1;
        else k=mp[a]+k-1;
        printf("%lld\n",seq[k]);
    }
    return 0;
}


Measured memory_bytes: 18600
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
using namespace std;
int main() {
	string C;
	int N;
	int count1R = 0;
	int count2R = 0;
	int ans;
	cin >> N >> C;
	for (int i = 0; i < N; i++) {
		if (C.at(i) == 'R') {
			count1R++;
		}
	}
	for (int i = 0; i < count1R; i++) {
		if (C.at(i) == 'R') {
			count2R++;
		}
	}
	ans = count1R - count2R;
	cout << ans;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
 
int main() 
{
    int N, D, X;
    cin >> N >> D >> X;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    
    int ans = 0;
    for (int i = 1; i <= D; i++) {
        for (int j = 0; j < N; j++) {
            int cho = A[j] * i + 1;
            if (cho <= D) {
                ans++;
            }
        }
    }
    cout << ans + N + X << endl;
}

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

int main(){

    int count=1;
    int n;
    int h[20]={0};

    std::cin>>n;
   
    for(int i=0;i<n;i++){
        std::cin>>h[i];
      
    }

    for(int num=1;num<n;num++){ //今何番目を見てるか
        int high[20]={0};
    
        for(int i=0;i<n;i++){
            high[i]=h[i];
          
        }

        std::sort(high,high+num+1);

        if(high[num]==h[num]){
            count++;
           
        }
       
    }

    std::cout<<count<<std::endl;

    return 0;
}


Measured memory_bytes: 256
import sys

def mmul(a,b):
	return ((a%m)*(b%m))%m

def madd(a,b):
	return (a%m+b%m)%m

def msub(a,b,):
	return (a%m-b%m+m)%m

N=int(sys.stdin.readline())

A=[int(i) for i in sys.stdin.readline().split()]

m=pow(10,9)+7

pre=[0]

for h in range(N):
	pre.append(madd(A[h],pre[h]))

ans=0

for p in range(N-1):
	val=mmul(A[p],msub(pre[N],pre[p+1]))
	ans=madd(ans,val)

print(ans)



Measured memory_bytes: 31280
import java.util.*;
import java.io.*;

public class Main {
    static int mod;
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
        int n = sc.nextInt(); mod = 998244353;
        int s = sc.nextInt(); int [] a = new int[n + 1];
        for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
        long [][] dp = new long[n + 1][s + 1];
        dp[0][0] = 1;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= s; j++) {
                dp[i][j] = (2 * dp[i - 1][j]) % mod;
                if (j - a[i] >= 0) dp[i][j] = (dp[i - 1][j - a[i]] + dp[i][j]) % mod;
            }
        }
        out.println(dp[n][s]);
        out.close();
    }

    static int pow(long b, int e) {
        long ans = 1;
        while (e > 0) {
            if (e % 2 == 1)
                ans = ans * b % mod;
            e >>= 1;
            b = b * b % mod;
        }
        return (int) ans;
    }


    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }


    }

}

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

int main() {
  int x,n;
  cin>>n>>x;
  int l[105],d[105];
  for (int i=1; i<=n; i++) 
    cin>>l[i];
  d[1]=0;
  int ans=1;
  for (int i=2; i<=n+1; i++) {
    d[i]=d[i-1]+l[i-1];
    if (d[i]<=x) ans++;
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define All(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main() {
  Cin(int, n);
  Cins(int, n, vi);

  int ans = 0;
  for (int i = 1; i < n - 1; ++i) {
    vector<int> tmp = {vi[i - 1], vi[i], vi[i + 1]};
    sort(All(tmp));
    if (tmp[1] == vi[i]) ans++;
  }

  cout << ans << endl;
  return;
}

int main() {
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)

/////////////////////////////////////////////////////////

void Main(){
  string N; cin >> N;
  int A, B, C, D;
  A = N[0] - '0';
  B = N[1] - '0';
  C = N[2] - '0';
  D = N[3] - '0';
  for(int flag = 0; flag < (1 << 3); flag++){
    int sum = A;
    if(flag & 1 << 0) sum += B;
    else sum -= B;
    if(flag & 1 << 1) sum += C;
    else sum -= C;
    if(flag & 1 << 2) sum += D;
    else sum -= D;
    if(sum != 7) continue;
    cout << A;
    if(flag & 1 << 0) cout << "+";
    else cout << "-";
    cout << B;
    if(flag & 1 << 1) cout << "+";
    else cout << "-";
    cout << C;
    if(flag & 1 << 2) cout << "+";
    else cout << "-";
    cout << D;
    cout << "=7" << endl;
    return;
  }
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout << std::fixed << std::setprecision(15);

  Main();
}


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

using namespace std;

int main() {
	int price;
	int priceC;
	int pay = 0;
	int n;
	int k;
	vector<bool> dl(10, true);

	cin >> price >> n;;
	priceC = price;
	for (int i = 0; i < n; i++) {
		cin >> k;
		dl[k] = false;
	}

	int r;
	bool flg;
	int i = 0;
	do{
		flg = false;
		r = price % 10;
		for (int j = r; j < 10; j++) {
			if (dl[j]) {
				pay += (j*pow(10, i));
				flg = true;
				break;
			}
		}
		if (flg == false) {
			price += 10;
			for (int j = 0; j <= r; j++) {
				if (dl[j]) {
					pay += (j*pow(10, i));
					break;
				}
			}
		}
		if(pay%(int)pow(10,i+1)>priceC% (int)pow(10, i + 1)){
			pay -= pay%(int)pow(10, i);
			for (int k = 0; k < i; k++) {
				for (int j = 0; j < 10; j++) {
					if (dl[j]) {
						pay += j*pow(10,k);
						break;
					}
				}
			}

		}
		price /= 10;
		i++;
	}while (price != 0);

	cout << pay << endl;

}

Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>

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

int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}

//-----------------------ここから-----------

int main(void){
    int m, d;
    cin >> m >> d;

    int ans = 0;
    for(int i = 2; i <= m; i++){
        for(int j = 20; j <= d; j++){
            int one = j % 10;
            int ten = j / 10;
            if(one == 1) continue;
            if(i == one * ten){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

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

int main() {
  int N,sum;
  cin >> N;
  sum = 0;
  for (int i=0;i<N;i++){
    int l,r;
    cin >> l >> r;
    sum+=r-l+1;
  }
  cout << sum << endl;
  return 0;
}


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

using namespace std;
int main()
{
    string s;
    cin>>s;
    string prev,p;
    long long count=1;
    prev=s[0];
    for(int i=1;i<s.length();i++)
    {
        p=s[i];
        if(p!=prev)
        {
            count++;
            prev=p;
        }
        else if(i!=s.length()-1 && p==prev)
        {
            prev=p+s[i+1];
            i++;
            count++;
        }
        //cout<<prev<<' ';
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
     
    using namespace std;
     
    typedef long long ll;
     
    const ll MOD = 1000000007;
     
    int main(){
        cin.tie(0);
        ios_base::sync_with_stdio(false);
        int n; cin >> n;
        vector<ll> x, y, h;
        vector<ll> ox, oy;
        for(int i=0;i<n;i++){
            ll tx, ty, th; cin >> tx >> ty >> th;
            if(th == 0){
                ox.push_back(tx);
                oy.push_back(ty);
            }else{
                x.push_back(tx); y.push_back(ty); h.push_back(th);
            }
        }
        ll in_size = x.size();
        ll out_size = ox.size();
        for(ll cx=0;cx<=100;cx++){
            for(ll cy=0;cy<=100;cy++){
                bool pos = true;
                ll predh = abs(x[0] - cx) + abs(y[0] - cy) + h[0];
                for(ll i=1;i<in_size;i++){
                    ll p = abs(x[i] - cx) + abs(y[i] - cy) + h[i];
                    if(p != predh){
                        pos = false;
                        break;
                    }
                }
                for(ll i=0;i<out_size;i++){
                    if(predh - abs(ox[i] - cx) - abs(oy[i] - cy) > 0){
                        pos = false;
                        break;
                    }
                }
                if(pos){
                    cout << cx << " " << cy << " " << predh << endl;
                }
            }
        }
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int x, a, b;
  cin >> x >> a >> b;
  int ans = x - a;
  ans %= b;

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


Measured memory_bytes: 3592
//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 1000000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 1000000000
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
	if(x==0)
	return "0";
	string ret="";
	while(x){
		ret=ret+(char)(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
string add(string a,string b){
	if(a=="")
	a="0";
	if(b=="")
	b="0";
	if(a.length()<b.length())
	swap(a,b);
	while(b.length()<a.length()){
		b='0'+b;
	}
	for(int i=0;i<a.length();i++){
		a[i]=a[i]+(b[i]-'0');
	}
	bool big=false;
	for(int i=a.length()-1;i>=0;i--){
		if(big){
			a[i]++;
		}
		big=false;
		if(a[i]>'9'){
			a[i]=a[i]-10;
			big=true;
		}
	}
	if(big)
	a='1'+a;
	return a;
}
string mul(string a,string b){
	vector<int> va,vb;
	if(a=="0" || b=="0")
	return "0";
	string ans;
	for(int i=0;i<a.length();i++){
		va.push_back(a[i]-'0');
	}
	for(int i=0;i<b.length();i++){
		vb.push_back(b[i]-'0');
	}
	reverse(va.begin(),va.end());
	reverse(vb.begin(),vb.end());
	vector<int> res;
	res.clear();
	res.resize(1005);
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			res[i+j]+=(va[i]*vb[j]);
		}
	}
	for(int i=0;i<1005;i++){
		if(res[i]>9){
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	for(int i=0;i<1005;i++){
		ans+=(res[i]+'0');
	}
	reverse(ans.begin(),ans.end());
	int k=0;
	while(ans[k]=='0'){
		k++;
	}
	ans=ans.substr(k);
	return ans;
}
bool is_prime(int n){
	if(n<2)
    return false;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
    return false;
    return true;
}
int n;
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
    cin>>n;
    if(n<=999)
    cout<<"ABC";
    else
    cout<<"ABD";
	//system("pause");
	return 0;
}

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

int main() {
	long n,m,i,j,k,ans,cur,res;
	cin >> n >> m;
	if(n<=m){
		cout << "unsafe" << endl;
	}else{
		cout << "safe" << endl;
	}
	return 0;
}


Measured memory_bytes: 3636
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const double PI = acos(-1.0);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

struct RandomNumberGenerator {
  mt19937 mt;

  RandomNumberGenerator() : mt(chrono::steady_clock::now().time_since_epoch().count()) {}

  int operator()(int a, int b) { // [a, b)
    uniform_int_distribution< int > dist(a, b - 1);
    return dist(mt);
  }

  int operator()(int b) { // [0, b)
    return (*this)(0, b);
  }
};

RandomNumberGenerator RNG;
const unsigned long long base = RNG(10,1<<30);

template <typename S>
struct RollingHash {
    typedef unsigned long long ull;

    const ull MASK30 = (1ull << 30) - 1;
    const ull MASK31 = (1ull << 31) - 1;
    const ull mod = (1ull << 61) - 1;
    const ull POSITIVIZER = mod * 3;

    vector<ull> hash,power;

    RollingHash(const S &s) {
        int sz = s.size();
        hash.assign(sz + 1,0);
        power.assign(sz + 1,1);
        for (int i = 0; i < sz; i++) {
            power[i+1] = CalcMod(Mul(power[i],base));
            hash[i+1] = CalcMod(Mul(hash[i],base) + s[i]);
        }
    }

    ull get(int l, int r) { // [l,r) (0-indexed)
        ull res;
        res = CalcMod(hash[r] + POSITIVIZER - Mul(hash[l],power[r-l]));
        return res;
    }

	int LCP(RollingHash &b, int l1, int r1, int l2, int r2) {
		int len = min(r1 - l1, r2 - l2);
    	int low = -1, high = len + 1;
    	while(high - low > 1) {
      		int mid = (low + high) / 2;
      		if(get(l1, l1 + mid) == b.get(l2, l2 + mid)) low = mid;
      		else high = mid;
    	}
    	return (low);
	}

    ull Mul (ull a, ull b) {
        ull au = a >> 31;
        ull ad = a & MASK31;
        ull bu = b >> 31;
        ull bd = b & MASK31;
        ull mid = ad * bu + au * bd;
        ull midu = mid >> 30;
        ull midd = mid & MASK30;
        return (au * bu * 2 + midu + (midd << 31) + ad * bd);
    }

    ull CalcMod(ull val) {
        val = (val & mod) + (val >> 61);
        if (val > mod) val -= mod;
        return val;
    }
};

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<ll> A(N),B(N);
    rep(i,N) cin >> A[i];
    rep(i,N) cin >> B[i];

    vector<ll> P(2*N),Q(N);
    rep(i,2*N) P[i] = A[i%N]^A[(i+1)%N];
    rep(i,N) Q[i] = B[i%N]^B[(i+1)%N];
    RollingHash<vector<ll>> RHA(P),RHB(Q);
    vector<pll> ans;
    rep(i,N) {
        if (RHA.get(i,i+N)==RHB.get(0,N)) {
            ans.emplace_back(i,A[i]^B[0]);
        }
    }

    for (auto i : ans) cout << i.first << " " << i.second << ln;
}


Measured memory_bytes: 24300
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
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;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
#define INT_MAX 1<<30
const ll mod = 1e9+7;


int main(){
	ll n; cin >> n;
	vl a(n); rep(i,n) cin >> a[i];
	bool flag = false;
	rep(i,n) if(a[i]&1) flag = true;
	if(flag) puts("first");
	else puts("second");
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
from heapq import heapify, heappop, heappush
from collections import defaultdict
from itertools import accumulate
import sys
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))

N, K = inpl()
A = sorted(inpl())

MOD = 10**9 + 7
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
 
size = N + 1
g1, g2, inverse = [0]*size, [0]*size, [0]*size
 
g1[:2] = [1, 1] # 元テーブル
g2[:2] = [1, 1] #逆元テーブル
inverse[:2] = [0, 1] #逆元テーブル計算用テーブル
 
for i in range(2, size):
    g1[i] =  ( g1[i-1] * i ) % MOD 
    inverse[i] = (-inverse[MOD % i] * (MOD//i) ) % MOD 
    g2[i] =  (g2[i-1] * inverse[i]) % MOD

ans = 0
for i in range(N-K+1):
    if N-i-1 < K-1:
        break
    ans = (ans + (A[-i-1] - A[i])*cmb(N-1-i, K-1, MOD))%MOD
print(ans)

Measured memory_bytes: 63472
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
#define MOD 1000000007
#define int long long

signed main(){
    int a,b,k;cin>>a>>b>>k;
    if(a<k){
        k-=a,a=0;
        b-=k;if(b<0)b=0;
    }else a-=k;
    cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
#![allow(unused_imports)]

//input
use proconio::input;
use proconio::marker::{Bytes, Chars};
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
use std::collections::HashSet;
//use std::collections::VecDeque;
//use std::collections::BinaryHeap;

//use std::cmp::*;

fn main() {
    input! {
        x: i64,
        n: usize,
    }

    if n == 0 {
        println!("{}", x);
        return;
    }

    input! {
        p:[i64;n]
    }

    let dic: HashSet<i64> = p.into_iter().collect();

    for i in 0.. {
        if !dic.contains(&(x - i)) {
            println!("{}", x - i);
            return;
        }
        if !dic.contains(&(x + i)) {
            println!("{}", x + i);
            return;
        }
    }
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int mod=998244353;
inline void add(int &a,int b){
    a+=b;
    if(a>=mod)a-=mod;
}
int mpow(int n,int m){
    int ret=1;
    while(m){
        if(m&1)ret=ret*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return ret;
}
const int FACT_SIZE=1111111;
int fact[FACT_SIZE];
int inv[FACT_SIZE];
struct fact_exec{
    fact_exec(){
        fact[0]=1;
        for(int i=1;i<FACT_SIZE;i++)fact[i]=fact[i-1]*i%mod;
        inv[FACT_SIZE-1]=mpow(fact[FACT_SIZE-1],mod-2);
        for(int i=FACT_SIZE-2;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;
    }
}factexec;
int nCk(int n,int k){
    if(n<0|k<0||k>n)return 0;
    return fact[n]*inv[k]%mod*inv[n-k]%mod;
}
int nPk(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return fact[n]*inv[n-k]%mod;
}


int calc(int L,int u,int d){
    if(L==0){
        return u==0&&d==0;
    }

    return nCk(L-1+u+d,u+d);
}

int solve(string A,string B,int L,int R){
    int ret=0;

    int sum=0;
    int u=0,d=0;

    int U=count(all(A),'1');
    int D=count(all(B),'1');

    for(int i=0;i<A.size();i++){
        if(A[i]=='0'&&B[i]=='0')continue;
        add(sum,calc(L,u,d));
        if(A[i]=='1'&&B[i]=='1')sum=sum*2%mod;
        u+=A[i]=='1';
        d+=B[i]=='1';
        add(ret,sum*calc(R,U-u,D-d)%mod);
    }
    return ret;
}

signed main(){
    int N,M;
    string A,B,C,D;
    cin>>N>>M>>A>>B>>C>>D;

    int ans=0;
    add(ans,solve(A,B,count(all(C),'1'),count(all(D),'1')));
    add(ans,solve(C,D,count(all(A),'1'),count(all(B),'1')));


    if(count(all(A),'1')+count(all(B),'1')+count(all(C),'1')+count(all(D),'1')==0){
        ans=1;
    }

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


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

int main()
{
    int a,b;
    cin>>a>>b;
    if(a>b || a==b)
    {
        for(int i=1;i<=a;i++)
            cout<<b;
        return 0;
    }
    if(a<b)
    {
        for(int i=1;i<=b;i++)
            cout<<a;
        return 0;
    }
}

Measured memory_bytes: 256
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
# MOD = 10**9+7
# MOD = 998244353

n = int(input())
a = n%10

if a in [2,4,5,7,9]:
    print("hon")
elif a in [0,1,6,8]:
    print("pon")
elif a == 3:
    print('bon')


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


const int N = 5005, INF = 1e18;



int n, A, B, a[N], dp[N];

main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> A >> B;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    int ans = INF;
    for(int i = 1; i <= n; i++){
        int cur = 0;
        dp[i] = INF;
        for(int j = i - 1; j >= 0; j--){
            if(a[i] > a[j]){
                dp[i] = min(dp[i], dp[j] + cur * A + (i - j - 1 - cur) * B);
            }
            else{
                cur += 1;
            }
        }
        ans = min(ans, dp[i] + (n - i) * B);
    }
    a[n + 1] = INF;
    for(int i = n; i >= 1; i--){
        int cur = 0;
        dp[i] = INF;
        for(int j = i + 1; j <= n + 1; j++){
            if(a[i] < a[j]){
                dp[i] = min(dp[i], dp[j] + cur * B + (j - i - 1 - cur) * A);
            }
            else{
                cur += 1;
            }
        }
        ans = min(ans, (i - 1) * A + dp[i]);
    }
    cout << ans;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define N 1001
#define mod 1000000007
#define ll long long
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define prob "H"
#define fast ios_base:: sync_with_stdio(1); cin.tie(nullptr); cout.tie(nullptr);
#define io freopen(prob".inp","r",stdin); freopen(prob".out","w",stdout);
using namespace std;
int n,m;
char a[N][N];
ll f[N][N];
void read()
{
  cin>>n>>m;
  for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++) cin>>a[i][j];
}
queue<int>q;
int ans=0;
void solve()
{
  f[1][1]=1;
  for(int i=1;i<=n;i++)
  {
    for(int j=1;j<=m;j++)
    {
      if(i==1&&j==1) continue;
      if(a[i][j]=='.')
        f[i][j]=(f[i][j-1]+f[i-1][j])%mod;
    }
  }
  cout<<f[n][m];
}
int main()
{
  fast
 // io
  read();
  solve();
}



Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, a, b;
    cin >> n >> a >> b;
    lint ret = n / (a + b) * a;;
    ret += min(a, n % (a + b));
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Obj{
	String s;
	int val, idx;

	Obj(String s, int val, int idx){
		this.s = s;
		this.val = val;
		this.idx = idx;
	}

	public String toString(){
		return "" + this.idx;
	}
}
public class Main{
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		String s;
		int val;
		ArrayList<Obj> list = new ArrayList<>();
		for(int i = 0; i < n; i++){
			s = in.next();
			val = in.nextInt();
			list.add(new Obj(s, val, i+1));
		}

		Collections.sort(list, new Comparator<Obj>() {
			@Override
			public int compare(Obj o1, Obj o2){
				if( o1.s.equals(o2.s) ){
					return o2.val - o1.val;
				}else{
					return o1.s.compareTo(o2.s);
				}
			}
		});
		for(int i = 0; i < n; i++)
			System.out.println(list.get(i));
	}
}

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

int main(){
    int n,k;
    set <int> st;
    scanf("%d %d",&n, &k);

    while(k--){
        int a;
        scanf("%d",&a);

        while(a--){
            int s;
            scanf("%d",&s);
            st.insert(s);
        }
    }

    int len=st.size();
    printf("%d\n",n-len);

    return 0;
}


Measured memory_bytes: 3796
// 標準入力から一行を読み取り、指定の型に変換する
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

// ユークリッドの互除法
fn gcd(x: u64, y: u64) -> u64 {
    let mut low: u64 = 0;
    let mut high: u64 = 0;

    if x > y { 
        high = x;
        low = y;
    } else {
        low = x;
        high = y;
    }

    if low == 0 { high }
    else { gcd(high%low, low) }
}

use std::cmp::*;

fn main() {
    let n: usize = read();
    let a: Vec<u64> = read_vec();

    let mut accum_gcd_l = vec![0_u64; n];
    let mut accum_gcd_r = vec![0_u64; n];

    // 累積GCDの計算
    for i in 1..n
    {
        accum_gcd_l[i]         = gcd(accum_gcd_l[i - 1], a[i - 1]);
        accum_gcd_r[n - i - 1] = gcd(accum_gcd_r[n - i], a[n - i]);
    }

    let mut max_lr_gcd = 1;

    // GCDの最大値を計算 iが置き換えるaのインデックス
    for i in 0..n
    {
        let gcd_lr = gcd(accum_gcd_l[i], accum_gcd_r[i]);
        max_lr_gcd = max(gcd_lr, max_lr_gcd);
    }

    println!("{}", max_lr_gcd);
}


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

using namespace std;
using ll = long long;

#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define REP(i,n) FOR(i, 0, n)
#define FORR(i,n,a) for(int i=(n); i>=(a); i--)
#define REPR(i,n) FOR(i, n, 0)

#define ALL(o) (o).begin(), (o).end()

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

const ll MOD = 1000000007;

typedef std::tuple<int, int> myt;

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

	long ans = n*(n-1)/2;

	cout << ans << endl;

}



Measured memory_bytes: 256
#include <iostream>

#include <cstdio>
#include <algorithm>
#include <climits>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>

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

using namespace std;

char S[11];

int main()
{
    scanf("%s", S);
    long long int sum = 0;
    int pow2 = 1;
    REP(i, strlen(S)-1)
        pow2 *= 2;

    REP(i, pow2) {
        long long int tmp = S[0]-48;
        int j = 0;
        long long int tmp_sum = 0;
        while (j<strlen(S)-1) {
            if(i & 1<<j) {
                tmp_sum += tmp;
                tmp = 0;
            }
            tmp *= 10;
            tmp += S[j+1]-48;
            j++;
        }
        tmp_sum += tmp;
        sum += tmp_sum;
    }
    cout << sum << endl;
    return 0;
}


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

using namespace std ;

int x ;

int main() {
	scanf( "%d" , &x ) ;
	int sum = 0 ;
	for( int i = 1 ; ; i ++ ) {
		sum += i ;
		if( sum >= x ) {
			printf( "%d\n" , i ) ;
			return 0 ;
		}
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
    int A,B,C,D,E,x,y,cou=0,v[3];
    char S[3],s[3],X,Y;
    scanf("%d %d %d",&A,&B,&C);
    if(-B+C<=0){
        printf("delicious");
    }else if(-B+C<=A){
        printf("safe");
    }else{
        printf("dangerous");
    }
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

/**
 * Created by oka on 2018/06/10.
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        int ret = 0;
        for (int i = b - a - 1; i > 0; i--) {
            ret += i;
        }
        System.out.println(ret - a);
    }
}


Measured memory_bytes: 21844
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N,M=map(int,input().split())
uf=UnionFind(N)
for i in range(M):
    a,b,=map(int,input().split())
    uf.union(a-1,b-1)

total=uf.group_count()
print(total-1)


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

int main(){
    int x;
    char s[200];
    signed long long stack[200];
    int esp=0;

    while( scanf("%s",s) != EOF){
        if(s[0] == '+'){
            esp--;
            stack[esp-1] += stack[esp];
        } else if(s[0] == '-'){
            esp--;
            stack[esp-1] -= stack[esp];
        } else if(s[0] == '*'){
            esp--;
            stack[esp-1] *= stack[esp];
        } else {
            x = atoi(s);
            stack[esp] = x;
            esp++;
        }
    }

    printf("%lld\n", stack[0]);

    return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;
 
int main(){
    ll l,r;
    cin>>l>>r;
    
    ll ans=3000;
    for(int i=l;i<=min(r,l+3000);i++){
        for(int j=i+1;j<=min(r,l+3000);j++){
            ll tmp=((i%2019)*(j%2019))%2019;
            ans=min(ans,tmp);
        }
    }

    cout<<ans<<endl;
}

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

int main(void){
    int N,A,B,sum=0;
    cin>>N>>A>>B;

    for(int i=1;i<=N;i++){
        int a=0,n=i;
        while(n!=0){
            a+=n%10;
            n/=10;
        }
        if(a>=A&&a<=B)
            sum+=i;
    }

    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int r = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int x = Integer.parseInt(sc.next());
		
		for(int i = 0; i < 10; ++i) {
		    int tmp = r * x -d;
		    System.out.println(tmp);
		    
		    x = tmp;
		}
	}
}

Measured memory_bytes: 22996
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

int main(void){
  string n;
  cin >> n;
  replace(n.begin(), n.end(), '1', ' ');
  replace(n.begin(), n.end(), '9', '1');
  replace(n.begin(), n.end(), ' ', '9');
  cout << n << endl;  
  return 0;
}


Measured memory_bytes: 256
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N, K, R, S, P = in.nextInt
  val T = in.next

  case class Rsp(r: Int, s: Int, p: Int)

  def score(i: Int, pre: Rsp): Int = {
    if (i >= N) pre.r max pre.s max pre.p
    else {
      val cur = curScore(i)
      score(i + K, Rsp(
        math.max(pre.s + cur.r, pre.p + cur.r),
        math.max(pre.r + cur.s, pre.p + cur.s),
        math.max(pre.r + cur.p, pre.s + cur.p)))
    }
  }

  def curScore(i: Int): Rsp = T.charAt(i) match {
    case 'r' => Rsp(0, 0, P)
    case 's' => Rsp(R, 0, 0)
    case 'p' => Rsp(0, S, 0)
  }

  println((0 until K).map(i => score(i + K, curScore(i))).sum)
}

Measured memory_bytes: 39220
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <limits.h>
#include <map>
#include <numeric>

namespace test {
	std::string to_string (char val) {
		return std::string (1, val);
		// return std::string{val};
	}
	//if( str.find ("r") != string::npos)
}

using namespace std;
typedef long long int llint;

int main (void) {
	string o,e; cin >> o >> e;
	for (int i = 0; i < o.size () + e.size (); i++) {
		if (i % 2 == 0) {
			cout << o[i/2];
		}
		else {
			cout << e[i/2];
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
readInt() = parse(Int,readline())

sigma(a,n) = (n+1)n*a

function solve()
    ans = 0
    N = readInt()
    f = fill(0, N)
    for i in 1:N
        ans += sigma(i,div(N,i))
    end
    println(div(ans,2))
end

solve()

Measured memory_bytes: 236632
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<string> a(3);
  for(int i = 0; i < 3; i++) cin >> a[i];
	for(int i = 0; i < 3; i++) reverse(a[i].begin(), a[i].end());
  int now = 0;
  while(true){
  	if(a[now].empty()){
    	cout << char(now + 'A') << endl;
      return 0;
    }
    char c = a[now].back();
    a[now].pop_back();
    now = c - 'a';
  }
  assert(0);
}


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


int main() {

	int N,K;
	cin>>N>>K;
	int A[N+10];
	for (int i = 1; i <=N; ++i)
	{
		cin>>A[i];
	}

	for (int i = K+1; i <= N; ++i)
	{
		if (A[i]-A[i-K]>0)
		{
			cout<<"Yes"<<endl;
		}
		else cout<<"No"<<endl;
	}



return 0;
}


Measured memory_bytes: 4400
import bisect
import collections
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

N = int(input())
S1 = list(input())
S2 = list(input())
a = []
now = 0
while now < N:
    if S1[now] == S2[now]:
        a.append("s")
        now += 1
    else:
        a.append("d")
        now += 2

for i in range(len(a)):
    if i == 0:
        if a[i] == "s":
            ans = 3
        else:
            ans = 6
    else:
        if a[i-1] == "s":
            ans *= 2
        else:
            if a[i] == "d":
                ans *= 3

print(ans%MOD)

Measured memory_bytes: 38444
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(long long)>
using namespace std;
#define All(v) (v).begin(),(v).end()
const long long mod = 1000000007;
const long long inf = mod*mod;
const long long d5 = 114514;
const double EPS = 1e-10;
const double INF = 1e+10;
const double PI = acos(-1.0);
signed main(){
    long long n,k;
    cin>>n>>k;
    long long res = 0;
    unordered_map<long long,long long> d;
    for(long long i=1;i<=n;i++){
        d[i%k]++;
    }
    for(auto i:d){
        if(2*i.first%k==0){
            res+=i.second*i.second*i.second;
        }
    }
    cout<<res<<endl;
}

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

void solve()
{
    string s;
    cin >> s;
    for (char &c : s) {
        if (c == '?') {
            c = 'D';
        }
    }
    /* int cnt = 0; */
    /* for (char &c : s) { */
    /*     if (c == 'D') { */
    /*         ++cnt; */
    /*     } */
    /* } */
    /* for (int i = 0; i < s.size() - 1; ++i) { */
    /*     if (s[i] == 'P' && s[i + 1] == 'D') { */
    /*         ++cnt; */
    /*     } */
    /* } */
    cout << s << endl;
}

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

    /* int T; */
    /* cin >> T; */
    /* for (int t = 0; t < T; ++t) { */
        solve();
    /* } */
    return 0;
}


Measured memory_bytes: 3740
#include<stdio.h>
#define N 100000
#define M 50000

//int binarySearch(int [],int,int);
int main(){
    int A[N],A2[M],i,n,q,x,count=0;
    
    scanf("%d",&n);
   
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
     scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&A2[i]);
    }
   
    for(i=0;i<q;i++){
        int key=A2[i];
        int right=n;
        int left=0;
      
                while(left<right){
                    int mid=(left+right)/2;
       
            if(A[mid]==key) {
                count++;
                break;}
            if(key<A[mid]) right=mid;
            else left = mid+1;;
        }
    }
    printf("%d\n",count);
    
    return 0;
}


Measured memory_bytes: 2312
#include <iostream>
#include <deque>

#define MAX_N 100010
#define ll long long
using namespace std;
//dp[i][j] i+1個取って、最後がa[j-m]
ll n,k,m,dp[310][2*MAX_N], a[MAX_N],b[2*MAX_N],deq[2*MAX_N];

void solve(int j){
	int s = 0, t = 0;
	for(int i = 0;i<m+n;i++){
		while(s<t && dp[j-1][deq[t-1]]<dp[j-1][i]){
			t--;
		}
		deq[t++]= i;
		if(i-m+1>=0){
			b[i-m+1] = dp[j-1][deq[s]];//先頭を取り出すのでb[i]が最小値(i>=0 && i<=n-m) b=min(i<=x<=i+m-1)a[x]
			if(deq[s]==i-m+1){
				s++;
			}
		}
	}
}

int main(){
	ll i,j;
	cin >> n >> m >> k;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	
	for(i=0;i<=m+n;i++){
		for(j=0;j<k;j++){
			dp[j][i] = 0;
		}
	}
	
	for(i=0;i<n;i++){
		dp[0][m+i] = a[i];
	}
	
	for(j=1;j<=k;j++){
		solve(j);
		for(i=m;i<m+n;i++){
			if(i-m<j){
				dp[j][i] = 0;
			}else{
				dp[j][i] = b[i-m]+(j+1)*a[i-m];
			}
		}
	}
	
	ll ans = 0;
	for(i=m;i<m+n;i++){
		ans = max(ans,dp[k-1][i]);
	}
	cout << ans << endl;
}

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

int main(){
  string table="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  for(;;){
    int n;
    cin>>n;
    if(n==0) break;
    int cnt[26];
    for(int i=0;i<26;i++)
      cnt[i]=0;
    char c[n];
    for(int i=0;i<n;i++)
      cin>>c[i];
    char max_char;
    for(int i=0;i<n;i++){
      cnt[c[i]-'A']++;
      int max=0;
      for(int j=0;j<26;j++)
	if(cnt[j]>max){
	  max=cnt[j]; max_char=table[j];
	}
      bool jud=true;
      int max_num=0;
      for(int j=0;j<26;j++){
	if(cnt[j]==max) max_num++;
	else if(cnt[j]+n-(i+1)>=max){
	  jud=false; break;
	}
      }
      if(jud){
	if(max_num==1){
	  cout<<max_char<<" "<<i+1<<endl; break;
	}
	if(i==n-1){
	  cout<<"TIE"<<endl;
	}
      }
    }
  }
}


Measured memory_bytes: 3140