akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream> 
#include <algorithm>
#include <bits/stdc++.h>
#include<unordered_map> 
using namespace std; 
typedef long long ll;
 
#define umap unordered_map
#define f first
#define s second
 
#define for0(i, a, b) for (long long i = (a); i < (b); i++)
#define for1(i, a) for (long long i = 0; i < (a); i++)
#define ford1(i,a,b) for (long long i = (b)-1; i >= (a); i--)
#define ford(i,a) for (long long i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define rep(i,a,b) for (long long i = a; i < b; i++)
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define sstr substr
typedef vector<ll> vi;
typedef vector<string> vis;
typedef priority_queue <int, vector<int>, greater<int> > minheap;
// typedef unordered_map<string, int> umap; 

 
int main()
{   
    unordered_map<string, int> umap; 
    ll x,y,a,b,c;
    cin >> x;
    cin >> y;
    cin >> a;
    cin >> b; 
    cin >> c;
    minheap vec_a;
    minheap vec_b;
    minheap vec_c;
    ll temp;
    for0(i , 0, a){
        cin >> temp;
        vec_a.push(temp);
    }
    for0(i , 0, b){
        cin >> temp;
        vec_b.push(temp);
    }
    for0(i , 0, c){
        cin >> temp;
        vec_c.push(temp);
    }

    ll diffa = a - x;
    for0(i, 0 , diffa){
        vec_a.pop();
    }
    
    ll diffb = b - y;

    for0(i, 0, diffb){
        vec_b.pop();
    }

    ll tempa;
    ll tempb;

    while (true){
        
        if (vec_c.size() == 0){
            break;
        }
        if ( vec_a.size() == 0 && vec_b.size() == 0 ){
            break;
        }
        if ( vec_a.size() == 0 && vec_b.size() !=0 && vec_b.top() < vec_c.top() ) {
            temp = vec_c.top();
            vec_c.pop();
            vec_b.pop();
            vec_b.push(temp);
            continue;
        }

        if ( vec_a.size() == 0  && vec_b.size() !=0 && vec_b.top() > vec_c.top() ) {
            vec_c.pop();
            continue;
        }

        if ( vec_b.size() == 0 && vec_a.size() !=0 && vec_a.top() < vec_c.top() ) {
            temp = vec_a.top();
            vec_c.pop();
            vec_a.pop();
            vec_a.push(temp);
            continue;
        }

        if ( vec_b.size() == 0  && vec_a.size() !=0 && vec_a.top() > vec_c.top() ) {
            vec_c.pop();
            continue;
        }
        
        if (vec_a.top() <= vec_b.top() && vec_a.top() < vec_c.top()){
            temp = vec_c.top();
            vec_c.pop();
            vec_a.pop();
            vec_a.push(temp);
        }
        else if (vec_a.top() > vec_b.top() && vec_b.top() < vec_c.top()){
            temp = vec_c.top();
            vec_c.pop();
            vec_b.pop();
            vec_b.push(temp);
        } else{
            vec_c.pop();
        }


    }

    ll finalans = 0 ;
    while( vec_a.size()){
        finalans += vec_a.top();
        vec_a.pop();
    }
    while (vec_b.size()){
        finalans += vec_b.top();
        vec_b.pop();
    }

    cout<<finalans<<endl;


    
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  
  int n = -1;
  for(int i = 0;i < s.size();i++){
    if(s.at(i)=='A'){
      n = i;
      break;
    }
  }
  
  int m = -1;
   for(int j = 0;j < s.size();j++){
    if(s.at(j)=='C'){
      m = j;
      if(n+1==m){
        break;
      }
    }
  }
  
  if(n >= 0 && m >= 0 && n+1==m){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)


int main(void){
    int a[200],key,n;

    scanf("%d",&n);

    REP(i,n){
        scanf("%d",&a[i]);
    }
    REP(i,n)
        if(i < n - 1)
            printf("%d ",a[i]);
        else
            printf("%d\n",a[i]);

    REP(i,n - 1){
        key = a[i + 1];
        int j = i;
        while(j >= 0 && a[j] > key){
            a[j + 1] = a[j];j--;
        }
        a[j + 1] = key;
        REP(k,n){
            if(k < n - 1)
                printf("%d ",a[k]);
            else
                printf("%d\n",a[k]);
        }
    }
}

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

int main(){
    int N;
    cin >> N;
    map<string, int> m;
    priority_queue<int> pq;
    vector<string> S;
    rep(i, N){
        string s;
        cin >> s;
        if(m[s] == 0) S.push_back(s);
        m[s]++;
        pq.push(m[s]);
    }
    int max = pq.top();
    vector<string> ans;
    for(string s: S) if(m[s] == max) ans.push_back(s);
    sort(ans.begin(), ans.end());
    for(string s: ans) cout << s << endl;
    return 0;
}

Measured memory_bytes: 29296
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int n,m,q;
int g[510][510];
int dp[510][510];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>m>>q;
    rep(i,m){
      int l,r;
      cin>>l>>r;
      g[l][r]++;
    }
    FOR(i,1,510){
      FOR(j,1,510){
        dp[i][j]=dp[i][j-1]+g[i][j];
      }
    }
    rep(i,q){
      int p,q;
      cin>>p>>q;
      int ans=0;
      FOR(i,p,q+1){
        ans+=dp[i][q]-dp[i][p-1];
      }
      cout<<ans<<endl;
    }
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  vector<int> v(2*a-1);
  for (int i=0; i<2*a-1; i++) {
    v.at(i)=b-a+1+i;
  }
  for (int i=0; i<2*a-1; i++) {
    cout << v.at(i) << " ";
  }
  return 0;
}


Measured memory_bytes: 256
<?php
list($h, $w) = ints();
for ($i = 0; $i < 10; ++$i)
    foreach (ints() as $j => $v) $d[$i][$j] = $v;
warshallFloyd(10);
$ans = 0;
for ($i = 0; $i < $h; ++$i)
    foreach (ints() as $v) $ans += $v !== -1 ? $d[$v][1] : 0;
echo $ans;

function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

function warshallFloyd($n)
{
    global $d;
    for ($k = 0; $k < $n; ++$k) { // 経由点
        for ($i = 0; $i < $n; ++$i) { // 始点
            for ($j = 0; $j < $n; ++$j) { // 終点
                $d[$i][$j] = min($d[$i][$j], $d[$i][$k] + $d[$k][$j]);
            }
        }
    }
}


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

int n,ans,c[500000][2],ma;
string s;

int  main()
{
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s;
        for(int i=0;i<s.length()-1;i++){
            if(s[i]=='A'&&s[i+1]=='B')ans++;
        }
        if(s[0]=='B')c[i][0]=1;
        if(s[s.length()-1]=='A')c[i][1]=1;
    }
    int ch=0,chc=0;
    for(int i=0;i<n;i++){
        if(c[i][0]==1)ch++;
        if(c[i][1]==1)chc++;
    }

    for(int i=0;i<n;i++){
        if(c[i][0]==1){
            if(c[i][1]==1)ma=max(ma,min(chc-1,ch));
            else ma=max(ma,min(chc,ch));//chc or ch
        }
        if(c[i][1]==1){
            if(c[i][0]==1)ma=max(ma,min(ch-1,chc));
            else ma=max(ma,min(ch,chc));//chc or ch
        }
    }



    cout<<ans+ma<<endl;
}


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

int main()
{
  vector<int> v;
  int A, B, C;
  cin >> A >> B >> C;
  v.push_back(A);
  v.push_back(B);
  v.push_back(C);
  sort(v.begin(),v.end());
  cout << v[0] + v[1] << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Author: zhang
 * Time: 8/12/2017
 * Description:
 */
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        System.out.println(fib(n));
    }

    public static int fib(int n){
        if(n ==0 || n == 1){
            return 1;
        }else {
            int[] store ={1,1};
            int sum = 1;
            for (int i = 2; i < n; i++) {
                sum = store[0]+store[1];
                store[0] = store[1];
                store[1] = sum;
//                i++;

            }
            return store[0]+store[1];
        }
    }
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define INF LLONG_MAX/2
#define PI acos(-1.0)
//#define MOD 1000000007

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
typedef priority_queue<int> PQi;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vout(Vs &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());} //vectorの同じ要素消す
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();} //intの桁数
int digitsum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;} //桁和
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int count(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} //vector aにおけるxの個数
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);
    int k,a,b;
    cin>>k>>a>>b;
    bool ans=false;
    REP(i,a,b+1){
        if(i%k==0) ans=true;
    }
    if(ans) cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
    return 0;
}


Measured memory_bytes: 3668
using System;


namespace B_005_56
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            new Logic_A().Start();//OK

        }

        public class Logic_A
        {
            public void Start()
            {
                var str = Console.ReadLine().Split(' ');
                var a = str[0];
                var b = str[1];

                Console.WriteLine((a == "H" && b == "H" || a == "D" && b == "D") ? "H" : "D");
            }
        }
    }
}

Measured memory_bytes: 13140
n,q = map(int,input().split())
s = input()
s_num = []
sa = [0]
count = 0
for i in range(1,len(s)):
  if s[i] == "C"and s[i-1] == "A":
    count += 1
    sa.append(count)
  else:
    sa.append(count)
    
for i in range(q):
  l,r = map(int,input().split())
  print(sa[r-1] - sa[l-1])
  

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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;i++)
#define rep2(i, m, n) for(int i=m;i<n;i++)
#define rrep(i, n, m) for(int i=n;i>=m;i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

ll dp[100005][13];

void Main() {
    int n;
    cin >> n;
    priority_queue<double> V;
    for (int i = 0; i < n; ++i) {
        int v;
        cin >> v;
        V.push(-v);
    }

    while (V.size() != 1) {
        double a = V.top();
        V.pop();
        double b = V.top();
        V.pop();
        V.push((a + b) / 2);
    }
    cout << abs(V.top()) << endl;
}

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


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
typedef complex<ld> Point;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

int main() {
    string s;
    ll k;
    cin >> s >> k;
    vi len;
    int cnt = 0;
    rep(i, s.size()) {
        cnt++;
        if (i == (int)s.size() - 1) {
            len.push_back(cnt);
            break;
        }
        if (s[i] != s[i + 1]) {
            len.push_back(cnt);
            cnt = 0;
        }
    }
    // debug(len.size());
    // rep(i, len.size()) {
    //     debug(len[i]);
    // }

    ll ans = 0;
    if (s.front() == s.back()) {
        repeat(i, 1, (int)len.size() - 1) {
            ans += (len[i] / 2) * k;
        }
        ans += ((len.front() + len.back()) / 2) * (k - 1);
        ans += len.front() / 2;
        ans += len.back() / 2;
        if (len.size() == 1) ans /= 2;
    } else {
        rep(i, len.size()) {
            ans += (len[i] / 2) * k;
        }
    }
    out(ans);
    return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
  int N, M;
  cin >> N >> M;

  vector<int> C;
  int c;

  for (int i = 0; i < N; ++i) {
    cin >> c;
    C.push_back(c);
  }

  int dp[N + 1];
  memset(dp, -1, sizeof(dp));
  dp[0] = 0;

  for (int n = 1; n <= N; ++n) {
    for (int i = 0; i < M; ++i) {
      int c = C[i];
      int v = n - c;

      if (v < 0) continue;

      int cnt = dp[v] + 1;

      if (dp[n] == -1) {
        dp[n] = cnt;
      } else {
        dp[n] = min(dp[n], cnt);
      }
    }
  }

  cout << dp[N] << endl;

  return 0;
}



Measured memory_bytes: 3484
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 40005
#define eps 1e-12
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
	res = 0;T f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		res = res * 10 + c - '0';
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0) {x = -x;putchar('-');}
	if(x >= 10) {
		out(x / 10);
	}
	putchar('0' + x % 10);
}
const int MOD = 998244353;
int N,M;
int a[305][305];
int b[305][305],cnt;
int inc(int a,int b) {
	return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
	return 1LL * a * b % MOD;
}
void update(int &x,int y) {
	x = inc(x,y);
}
int fpow(int x,int c) {
	int res = 1,t = x;
	while(c) {
		if(c & 1) res = mul(res,t);
		t = mul(t,t);
		c >>= 1;
	}
	return res;
}
void Solve() {
	read(N);read(M);
	for(int i = 1 ; i <= N ; ++i) {
		for(int j = 1 ; j <= M ; ++j) {
			read(a[i][j]);
		}
	}
	for(int i = 1 ; i <= N ; ++i) {
		for(int j = 1 ; j <= M ; ++j) {
			if(a[i][j]) {
				if(!b[j][j]) {
					for(int k = 1 ; k <= M ; ++k) b[j][k] = a[i][k];
					++cnt;
					break;
				}
				else {
					for(int k = 1 ; k <= M ; ++k) a[i][k] ^= b[j][k];
				}
			}
		}
	}
	int ans = inc(fpow(2,N),MOD - fpow(2,N - cnt));
	ans = mul(ans,fpow(2,M - 1));
	out(ans);enter;
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	Solve();
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		String[] arrInt = (new BufferedReader(new InputStreamReader(System.in))).readLine().split(" ");

		int a = Integer.parseInt(arrInt[0]);
		int b = Integer.parseInt(arrInt[1]);
		int c = Integer.parseInt(arrInt[2]);
		if(a < b && b < c) System.out.println("Yes");
		else System.out.println("No");
	}
}

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

int main() {
    int n, q;
    cin >> n >> q;
    stack<int> st[n];

    for(int i = 0; i < q; i++) {
        int p;
        cin >> p;
        if(p == 0) {
            int t, x;
            cin >> t >> x;
            st[t].push(x);
        }
        else if(p == 1) {
            int t;
            cin >> t;
            if(st[t].size() == 0){
                continue;
            }
            cout << st[t].top() << endl;;
        }
        else {
            int t;
            cin >> t;
            if(st[t].size() == 0){
                continue;
            }
            st[t].pop();
        }
    }

}


Measured memory_bytes: 4288
import itertools

n,m = map(int,input().split())
s = [list(map(int,input().split()))[1:] for i in range(m)]
#print(s)
p = list(map(int,input().split()))
ans = 0
for i in itertools.product(range(2),repeat=n):
    c = 0
    st = 0
    for j in s:
        t = p[st]
        st += 1
        for k in j:
            t += i[k-1]
        if t%2 == 0:
            c += 1
    if c == m:
        ans += 1

print(ans)

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

int main()
{
  char a;
  vector<char> x(3);
  for (int i = 0; i < 3; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      cin >> a;
      if (i == j)
        x[i] = a;
    }
  }
  for (int i = 0; i < 3; i++)
    cout << x[i];
  cout << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] a = new int[n];
        long[] num = new long[n + 1];

        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
            num[a[i]]++;
        }

        long[] ncr = new long[n + 1];
        long[] ncr1 = new long[n + 1];
        long sum = 0;

        for(int i = 1; i <= n; i++){
            ncr[i] = num[i] * (num[i] - 1) / 2;
            ncr1[i] = (num[i] - 1) * (num[i] - 2) / 2;
            sum += ncr[i];
        }

        for(int i = 0; i < n; i++){
            System.out.println(sum - ncr[a[i]] + ncr1[a[i]]);
        }

    }
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

ll x, y, z;
int n;
ll r;

inline bool check(ll x, ll y){ return x * x + y * y < 4 * r * r; }

int main()
{
  while(~scanf(" %lld %lld %lld", &x, &y, &z) && x && y && z){
    scanf(" %d", &n);
    while(n--){
      scanf(" %lld", &r);
      bool ok = false;
      ok |= check(x, y) | check(y, z) | check(z, x);
      puts(ok ? "OK" : "NA");
    }
  }

  return 0;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
#define lld long long int
#define vec vector<lld>
#define pll pair<lld,lld>
#define pb push_back
#define ss second
#define ff first
#define mp make_pair
#define mod 1000000007
#define answer cout<<endl<<"answer : ";
#define maxn 100005
#define messi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main() {messi lld t=1;//cin>>t;
    while(t--)
    {
        lld n=0,m=0,k=0,i=0,j=0,p=0,q=0,x=0,y=0,z=0,ans=0,cnt=0;string s;bool flag=false;
        cin>>n; double a[n]; for(i=0;i<n;i++) cin>>a[i];
        double lund;
        for(i=0;i<n;i++)
            lund+=((double)1)/((double)a[i]);
        double chut;
        chut = (double)1/(double)lund;
        cout<<chut<<endl;

    }
	return 0;
}
/*  CODED BY:-
 ________________________________________
|            __        __                |
|  /\   /\  |__)  /\  |  \ |__| \ /  /\  |
| /~~\ /~~\ |  \ /~~\ |__/ |  |  |  /~~\ |
|________________________________________|

*/


Measured memory_bytes: 3852
#include<iostream>
#include<sstream>
#include<string>

using namespace std;

int main() {
	int n;
	string str, strd;
	stringstream ss;
	static const string empty_string;
	
	while(1) {
		cin >> n;
		if(!n) break;
		cin >> str;

		while(n--) {
			strd = str;
			str = empty_string;

			int c = 0, num = -1;
			for( int i=0; strd[i]; i++) {
				if( num!=strd[i]-'0') {
					if(c) {
						ss << c << num;
						str += ss.str();
						ss.str(empty_string);
					}
					num = strd[i] - '0'; c=1;
				}else c++;
			}
			if(c) {
				ss << c << num;
				str += ss.str();
				ss.str(empty_string);
			}
		}
		cout << str << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1360
from collections import deque
N,K = map(int,input().split(" "))
q = deque()
line = input().split(" ")
for i in range(K):
  q.append(int(line[i]))
for i in range(K,N):
  x = q.popleft()
  y = int(line[i])
  if x < y:
    print("Yes")
  else:
    print("No")
  q.append(y)

Measured memory_bytes: 31444
n, x = map(int, raw_input().split())
ans = x
while 0 < x < n:
    k = x / (n-x)
    rest = x % (n-x)
    ans += 2*k*(n-x)
    if rest:
        ans += n-x + rest
    n, x = n-x, n-x-rest
print ans


Measured memory_bytes: 2568
#include<iostream>
#include<vector>
#include<utility>
using namespace std;
using ll = long long;

vector<pair<ll,ll> > primeFactorize(ll x) {
  vector<pair<ll,ll> > res;
  for (ll i=2;i*i<=x;i++) {
    ll ex=0;
    while (x%i == 0) {
      ex++;
      x/=i;
    }
    if (ex>0) res.push_back({i, ex});
  }
  if (x>1) res.push_back({x, 1});

  return res;
}

int main() {
  ll N,i,j,ans=0;
  cin>>N;
  vector<pair<ll,ll> > pF = primeFactorize(N);
  for (i=0;i<pF.size();i++) {
    for (j=1;j<=pF[i].second;j++) {
      pF[i].second -= j;
    }
    ans += (j-1);
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

typedef long long       ll;

#define all(x)            (x).begin(),(x).end()
#define Sort(x)            sort(all(x))
#define A               first
#define B               second
#define sep             ' '
#define fast_io         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random     mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count())

const int MAX1 = 1e3+10,
         Md = 1e9+7,
		 Base = 257;

ll n, m, sum, ans, res, adad;

int main(){
    fast_io;
    cin >> n >> m;
    if (n == m){
    	cout << n+1 << endl;
    	return 0;
	}
    ans = 1e18;
    for (ll i = 2; i <= sqrt(n); ++i){
    	res = n;
    	sum = 0;
    	while (res){
    		sum += res%i;
    		res /= i;
		}
		if (sum == m)	ans = min(ans, i);
	}
	adad = n-m;
	for (ll i = 1; i <= sqrt(n)+10; ++i){
		if (adad%i == 0){
			ll x = adad/i+1;
			ll a = i;
			ll b = m-a;
			// cout << x << sep << a << sep << b << sep << (b > 0) << endl;
			if (x >= 2 && 1.0*x*x/n > 1 && b >= 0 && a+b == m && a*x+b == n && a < x && b < x)
				ans = min(ans, x);
		}
	}
	if (ans == 1e18)	cout << -1;
	else	cout << ans;
    return 0;
}
/*               now or never                 */


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
    int a, b, c;
    double rad;
    double PI = acos(-1);
    cin >> a >> b >> c;
    rad = c * PI / 180;
    
    printf("%lf\n", a * b * sin(rad) / 2);
    printf("%lf\n", a + b + sqrt(a * a + b * b - 2 * a * b * cos(rad)));
    printf("%lf\n", b * sin(rad));
    return 0;
}


Measured memory_bytes: 3492
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
#define LL long long
#define MOD 100000
#define inf (1<<30)


int n, h[100002], ans = 1, now;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++)cin >> h[i];
	now = h[n - 1];
	for (int i = n - 2; i >= 0; i--) {
		if (h[i] > h[i + 1] + 1) {
			ans = -1; break;
		}
		else if (h[i] == h[i + 1] + 1) 
			h[i]--;
		else now = h[i];
	}
	
	cout << (ans > 0 ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main()

{
  int a,b,c;

  //金額
  scanf("%d", &a);

  //一円玉の枚数
  scanf("%d", &b);

  c= a%500;

  //判定
  if ( c <= b)
       printf("Yes\n");

  else printf("No\n");

  return 0;

}

Measured memory_bytes: 128
import math
n, k = map(int, input().split())

s = 0
d = 1 / n
for i in range(1, n+1):
    if i >= k:
        s += d
    else:
        a = math.ceil(math.log2(k / i))
        s += d * pow(0.5, a)
print(s)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
constexpr i64 INF = 1010000000000000017LL;
constexpr i64 MOD = 1000000007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x; 
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x; 
        return true;
    }
    return false;
}
template<typename Val>
bool bitcheck(Val bit, size_t idx) {
    return bit & (1 << idx);
}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr); ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH) cout << unitbuf;
    }
} PROCON_INIT;

void solve() {
    int a; cin >> a;
    cout << a * (1 + a * (1 + a)) << endl;
}

signed main() {
    solve();
    return 0;
}

Measured memory_bytes: 3636
#include <cmath>
#include <functional>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>

using namespace std;

typedef long long ll;

#ifdef iq
  mt19937 rnd(228);
#else
  mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

int main() {
#ifdef iq
  freopen("a.in", "r", stdin);
#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n, a, b, c , d;
  cin >> n >> a >> b >> c >> d;
  n--;
  ll need_sum = b - a;
  for (int l = 0; l <= n; l++) {
    ll vl = -d * l + c * (n - l);
    ll vr = -c * l + d * (n - l);
    if (vl <= need_sum && need_sum <= vr) {
      cout << "YES\n";
      return 0;
    }
  }
  cout << "NO\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n; cin >> n;
    string in; cin >> in;
    int sum = 0;
    vi a(n); rep(i, n) a[i] = (in[i] == 'E'), sum += a[i];

    int res = sum;
    rep(i, n){
        if(a[i]) sum--;
        chmin(res, sum);
        if(not a[i]) sum++;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 1812
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int H,W;
  cin>>H>>W;
  vector<string>s(H);
  for(int i=0;i<H;i++){
    cin>>s[i];
  }
  vector<vector<int>>sum(H,vector<int>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(s[i][j]=='.'){
        int start=j;
        int cnt=0;
        while(j<W&&s[i][j]=='.'){
          cnt++;
          j++;
        }
        for(int k=start;k<j;k++){
          sum[i][k]+=cnt;
        }
      }
    }
  }
  for(int j=0;j<W;j++){
    for(int i=0;i<H;i++){
      if(s[i][j]=='.'){
        int start=i;
        int cnt=0;
        while(i<H&&s[i][j]=='.'){
          cnt++;
          i++;
        }
        for(int k=start;k<i;k++){
          sum[k][j]+=cnt;
        }
      }
    }
  }
  int ans=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      chmax(ans,sum[i][j]-1);
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 26448
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
const int inf = 1 << 30;
const ll linf = 1e18;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

ll N, M;
ll sum;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        ll A;
        cin >> A;
        sum += A;
    }
    cout << max(N - sum, -1LL) << endl;
    return 0;
}

Measured memory_bytes: 3656
import sys
from collections import Counter

N, M = map(int, input().split())
KA_list = []
for i in range(N):
    for j in input().split()[1:]:
        KA_list.append(j)
c = Counter(KA_list)

ans = 0
for k, v in c.items():
    if v == N:
        ans += 1

print(ans)


Measured memory_bytes: 3316
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

std::string S;
int w;

int main()
{
	in >> S >> w;
	for (int i = 0; i < S.length(); i += w) out << S[i];
	out << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<math.h>

using namespace std;
#define INF 1<<30
#define MAX 100005
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

typedef long long ll;

int main()
{
    FASTIO
   
    int n;
    cin >> n;
    vector<int> H(n+10, 0);
    for(int i = 0; i < n; i++) cin >> H[i];

      vector<int> ans(n+5, INF);
    ans[0] = 0;
    for(int i = 0; i < n; i++){
      ans[i+1] = min(ans[i+1], ans[i] + abs(H[i+1] - H[i]));
      ans[i+2] = min(ans[i+2], ans[i] + abs(H[i+2] - H[i]));
    }
    cout << ans[n-1]<<endl;
   
    return 0;
}

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

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

	int N;
	cin >> N;

	int result = 0;

	for( int i = 1; i <= N; i += 2 ) {
		int x = 0;

		for( int j = 1; j <= i; ++j ) {
			if( i % j == 0 ) { x += 1; }
		}

		if( x == 8 ) { result += 1; }
	}

	cout << result << endl;
	return 0;
}


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

// 解答を見れば分かるけど、自力では思いつける気がしない。。
int main() {
    int n, m;
    cin >> n >> m;

    vector<long long> X(m);
    for(int i=0; i<m; ++i) {
        cin >> X[i];
    }
    sort(X.begin(), X.end());

    vector<long long> diff;
    for(int i=1; i<X.size(); ++i) {
        diff.push_back(X[i]-X[i-1]);
    }
    sort(diff.begin(), diff.end(), greater<long long>());

    long long res = X.back() - X[0];
    for(int i=0; i< min((int)diff.size(), n-1); ++i) {
        res -= diff[i];
    }
    cout << res << endl;

}


Measured memory_bytes: 2168
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
	
		Scanner stdIn = new Scanner(System.in);
		
		String s = stdIn.next();
		String[] fig;
		int count = 0;
		int max = 0;
		
		fig = s.split("");
		
		for (int i = 0; i < s.length(); ++i) {
			if (fig[i].equals("A")||fig[i].equals("T")||fig[i].equals("G")||fig[i].equals("C")) {
				++count;
				if (max < count) {
					max = count;
				}
			} else {
				count = 0;
			}
		}
		
		System.out.println(max);
		
	}
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
#include <algorithm>
#define Freopen(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout);
#define int long long
using namespace std;
signed main()
{
	char s[10];
	scanf("%s",s);
	printf("A%cC\n",s[1]=='R'?'B':'R');
	return 0;
}

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

using namespace std;
static const int MAX=101;
bool Visited[MAX]; //??\?????????????¢??????????
vector<int> Adjacency[MAX];
int dTime[MAX]; int fTime[MAX]; //?¢??????°??¶??´????¢?????????¶??´
void dfs(int i,int& clock) //??¶????????°?????\???????????¨
{
    clock++;
    Visited[i]=true;
    dTime[i]=clock; //???????????°??¶??´
    for(int j=0;j<Adjacency[i].size();j++)
    {
        if(Visited[Adjacency[i][j]]==true) continue;
        dfs(Adjacency[i][j],clock);
    }
    clock++; //???????????????????¢????
    fTime[i]=clock;
}

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++) Visited[i]=false;

    for(int i=1;i<=n;i++)
    {
        int p;cin>>p;
        int num;
        cin>>num;

        for(int j=0;j<num;j++)
        {
            int t;
            cin>>t;
            Adjacency[p].push_back(t);
        }
    }
    int clock=0;
    for(int i=1;i<=n;i++)  //???????????????????????°DFS?£?????????????
    {
        if(Visited[i]==false) dfs(i,clock);
    }
    for(int i=1;i<=n;i++)
        cout<<i<<' '<<dTime[i]<<' '<<fTime[i]<<endl;
}

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

int main() {
	int a, b, c, k, sum = 0;
	cin >> a >> b >> c >> k;
	if (k - a > 0) {
		sum += a;
		k -= a;
	}
	else {
		sum += k;
		k = 0;
	}
	if (k - b > 0) {
		k -= b;
	}
	else {
		k = 0;
	}
	if (k > 0) {
		sum -= k;
	}
	cout << sum;
}

Measured memory_bytes: 3160
#include<iostream>
#include<algorithm>
//#include<cmath>
using namespace std;
int main() {
	int i;
	int A[10001];
	for (i = 0; cin >> A[i]; i++);
	sort(A, A + i);
	cout << A[i - 1] << endl << A[i - 2] << endl << A[i - 3] << endl;
	return 0;
}

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

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

    long ans = 0;
    for (long i = 0; i < n; ++i){
        long x = i + 1;
        if (x%3!=0 && x%5!=0){
            ans+=x;
        }
    }
    cout << ans << endl;
}


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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  
  //find (a*i) % b = c
  
  for(int i = 1; i <= b; i++)
  {
    if(a*i % b == c)
    {
      cout << "YES" << endl;
      return 0;
    }
  }
  
  cout << "NO" << endl;
  return 0;
}

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

using namespace std;

int main()
{
    int n, m;
    long long ans;
    const long long d = 1000000007;
    cin >> n >> m;
    if(abs(n - m) > 1){
        ans = 0;
    }
    else {
        ans = (n == m) ? 2 : 1;
        for(int i=n; i>0; --i){
            ans *= i;
            ans = ans % d;
        }
        for(int i=m; i>0; --i){
            ans *= i;
            ans = ans % d;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const ll LLINF = 1LL<<60;
/* -- template -- */
const ll MOD = 1e9 + 7;

ll add(ll a, ll b){
    return (a + b)%MOD;
}
int main(){
    string S; cin >> S;
    ll dp[S.size() + 1][4];
    dp[0][0] = 1;
    dp[0][1] = dp[0][2] = dp[0][3] = 0;
    //dp[i + 1][0] : i文字目まで見たときの全ルート数
    //dp[i + 1][1] : i文字目まで見たときのAが登場する数
    //if(S[i] == 'A' || S[i] == '?')dp[i + 1][1] += dp[i][1] + dp[i][0]
    //dp[i + 1][2] : i文字目まで見たときのABが登場する数
    //if(S[i] == 'B' || S[i] == '?')dp[i + 1][2] += dp[i][2] + dp[i][1]
    //dp[i + 1][3] : i文字目まで見たときのABCが登場する数
    //if(S[i] == 'C' || S[i] == '?')dp[i + 1][3] += dp[i][3] + dp[i][2]
    rep(i, S.size()){
        rep(j, 4){
            if(S[i] == '?'){
                dp[i + 1][j] = (3 * dp[i][j]) % MOD;
            }else{
                dp[i + 1][j] = dp[i][j];
            }
        }
        bool flg = (S[i] == '?');
        if(S[i] == 'A' || flg){
            dp[i + 1][1] = (dp[i + 1][1] + dp[i][0])%MOD;
        }
        if(S[i] == 'B' || flg){
            dp[i + 1][2] = (dp[i + 1][2] + dp[i][1])%MOD;
        }
        if(S[i] == 'C' || flg){
            dp[i + 1][3] = (dp[i + 1][3] + dp[i][2])%MOD;
        }
    }
    cout << dp[S.size()][3] << endl;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef pair<double,int>Q;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,v,x[200005];
int go[200005][20],go2[200005][20];
int dp[(1<<20)],dp2[(1<<20)];
int used[200005];
P p[200005];

int main(){
	cin>>n>>v;
	repn(i,n)cin>>x[i];
	vector<int>vi;
	while(1){
		vi.pb(v);
		if(v == 0) break;
		v/=2;
	}
	rep(j,vi.size()){
		vector<int>vec;
		repn(i,n-1){
			if(x[i+1]-x[i] > vi[j]){
				vec.pb(i);
			}
		}
		vec.pb(n);
		repn(i,n){
			int e = vec[POSL(vec,i)];
			go[i][j] = e;
			if(j==0) p[i].sc = e;
		}
	}
	rep(j,vi.size()){
		vector<int>vec;
		vec.pb(1);
		repn(i,n-1){
			if(x[i+1]-x[i] > vi[j]){
				vec.pb(i+1);
			}
		}
		repn(i,n){
			int e = vec[POSU(vec,i)-1];
			go2[i][j] = e;
			if(j==0) p[i].fi = e;
		}
	}
	//repn(i,n)cout<<p[i].fi<<" "<<p[i].sc<<endl;
	rep(i,(1<<20)) dp[i] = -INF;
	dp[0] = 0;
	int z = vi.size();
	for(int mask=0;mask<(1<<z);mask++){
		if(dp[mask] < 0) continue;
		for(int i=0;i<z;i++){
			if(((mask>>i)&1)) continue;
			int NXT = go[dp[mask]+1][i];
			if(dp[mask]==n) NXT=n;
			dp[mask+(1<<i)] = max(dp[mask+(1<<i)],NXT);
		}
	}
	rep(i,(1<<20)) dp2[i] = INF;
	dp2[0] = n+1;
	//int z = vi.size();
	for(int mask=0;mask<(1<<z);mask++){
		if(dp2[mask] > n+1) continue;
		for(int i=0;i<z;i++){
			if(((mask>>i)&1)) continue;
			int NXT = go2[dp2[mask]-1][i];
			if(dp2[mask]==1) NXT=1;
			dp2[mask+(1<<i)] = min(dp2[mask+(1<<i)],NXT);
		}
	}
	vector<P>L;
//	bool allok = 0;
	for(int mask=0;mask<(1<<z);mask++){
		if(mask%2 == 1) continue;
		int mask2 = (1<<z)-2-mask;
		int x = dp[mask];
		int y = dp2[mask2];
		//cout<<x<<y<<endl;
		if(x+1>y-1) used[1] += 1;
		else{
			int L = p[x+1].fi;
			int R = p[x+1].sc;
			if(L<=x+1 && y-1<=R){
				used[L]++;
				used[R+1]--;
			}
		}
	}
	for(int i=2;i<=n;i++) used[i]+=used[i-1];
	for(int i=1;i<=n;i++){
		puts(used[i]?"Possible":"Impossible");
	}
}

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

const int N = 1e5 +1;
int dp[N];

int main(){
	int n,k;
	cin >> n >> k;
	int arr[n];
	memset(dp,1000000,sizeof(dp));
	for(int i=0;i<n;i++) cin >> arr[i];
	dp[0] = 0;
	for(int i=0;i<n;i++){
		for(int j=i-1;j>=max(i-k,0);j--){
			dp[i] = min(dp[i],dp[j]+abs(arr[i]-arr[j]));
		}
	}
	cout << dp[n-1];
return 0;
}



Measured memory_bytes: 4384
main :: IO ()                                                                                                              
main = getLine >> getLine >>= \s -> print . minimum . f s $ (length . filter (=='E') . tail $ s)                           
                                                                                                                           
f :: String -> Int -> [Int]                                                                                                
f [_] a = [a]                                                                                                              
f (s:t:ss) n                                                                                                               
  | s == 'E' && t == 'E' = n : f (t:ss) (n-1)                                                                              
  | s == 'W' && t == 'W' = n : f (t:ss) (n+1)                                                                              
  | otherwise = n : f (t:ss) n

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

vector<int> arr;
int n;

int main(void){
  while(cin >> n, n){
    int num;
    arr.clear();
    for(int i = 0; i < n; i++){
      cin >> num;
      arr.push_back(num);
    }
    int search, cnt = 0;
    cin >> search;
    int lb = 0, ub = n - 1;
    while(lb <= ub){
      int mid = (lb + ub) / 2;
      cnt++;
      if(arr[mid] == search){
        break;
      }if(arr[mid] > search){
        ub = mid - 1;
      }else{
        lb = mid + 1;
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

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

public class Main{
    public static void main(String[] args)throws Exception{
        Scanner sc=new Scanner(System.in);
        int k=sc.nextInt();
        int n=sc.nextInt();
        int[] ary=new int[n];
        int distance=0;
        ary[0]=sc.nextInt();
        for(int i=1;i<n;i++){
            ary[i]=sc.nextInt();
            distance=(int)Math.max(distance,ary[i]-ary[i-1]);
        }
        distance=(int)Math.max(distance,k-ary[n-1]+ary[0]);
        System.out.println(k-distance);
    }
}

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

int main(){

  for(int n,ans;cin>>n,n;){
    
    ans = 0;

    int sqrt_n = (int)sqrt(n); 

    for(int i=sqrt_n;i>=0;--i){
      for(int j=i;j>=0;--j){
        for(int k=j;k>=0;--k){
          for(int l=k;l>=0;--l){
            if(n == i*i + j*j + k*k + l*l){
              ++ans;
            }
          }
        }
      }
    }

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		int c = stdIn.nextInt();
		if (a < b && b < c) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}
}

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

using namespace std;

int main(){
    int N,M,num=0;
    long long int ans=0;
    cin >> N >> M;
    vector<pair<int,int>> ab(N);
    for(int i=0;i<N;i++){
        cin >> ab[i].first >> ab[i].second;  
    }

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

    for(int i=0;i<M;i++){
        ans += ab[num].first;
        ab[num].second--;
        if(ab[num].second==0){
            num++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
A=LIST()

cnt=mx=0
for i in range(N):
    if A[i]>=mx:
        mx=A[i]
        cnt+=1
print(cnt)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long int
#define ldouble long double
#define vin vector<int>
#define pqueue priority_queue
#define rep(a,n) for(int i=(a);i<(n);i++)
#define INF (int)1000000007

//setprecision()<<

using namespace std;

void fin(int n,vin &a){
    rep(0,n){
        cin>>a.at(i);
    }
}

signed main(){
    typedef pair<int,int> P;
    int N,M;
    cin>>N>>M;
    cout<<(N*(N-1))/2+(M*(M-1))/2<<endl;

    return 0;
}

Measured memory_bytes: 256