akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
int main()
{
    ll n;
    cin>>n;
    ll a,val;
    for(ll i=0;i<n;i++)
    {
        cin>>a;
        if(i==0)
            val=a;
        else
            val=gcd(val,a);
    }
    cout<<val<<endl;
    return 0;
}


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

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            char[] o = in.next().toCharArray();
            char[] e = in.next().toCharArray();
            String ans = "";

            for (int i = 0; i < Math.max(o.length, e.length); i++) {
                ans += i < o.length ? o[i] : "";
                ans += i < e.length ? e[i] : "";
            }
            out.println(ans);

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll x[5] = {};
  for (int i = 0; i < 5; i++) {
    cin >> x[i];
  }

  for (int i = 0; i < 5; i++) {
    if (i + 1 != x[i]) {
      cout << i + 1 << ln;
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 3592
from itertools import accumulate
N, K = map(int, input().split())
A = list(map(int, input().split()))


# 連続する部分列の和を計算
A_acc = [0] + list(accumulate(A))
SubArraysSums = []
for i in range(1, N + 1):
    for j in range(i, N + 1):
        SubArraysSums.append(A_acc[j] - A_acc[i - 1])
SubArraysSums.sort()


ans = 0
tmp = []
for i in reversed(range(40)):
    for s in SubArraysSums:
        if (1 << i) & s:
            tmp.append(s)

    if len(tmp) >= K:
        ans += (1 << i)
        SubArraysSums = tmp
    tmp = []

print(ans)


Measured memory_bytes: 69756
n,q=map(int,input().split()) 
s=input()
area=[]
for i in range(q):
    start,end=map(int,input().split())
    area.append([start,end])
num=[0,0]
total=0
for i in range(n-1):
    if s[i]=="A" and s[i+1]=="C":
        total+=1
    num.append(total)
for i in range(q):
    print(num[area[i][1]]-num[area[i][0]])

Measured memory_bytes: 22924
N = int(input())
A = [0]
A = A + list(map(int,input().split()))
A.append(0)
SA = 0
for i in range(N+1):
    SA += abs(A[i]-A[i+1])
for i in range(1,N+1):
    X = abs(A[i-1]-A[i])+abs(A[i+1]-A[i])
    Y = abs(A[i-1]-A[i+1])
    print(SA-X+Y)


Measured memory_bytes: 86112
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define hi cout<<'h'<<'i'<<'\n' 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)
bool vis[20][20];
int lvl[20][20];
int main()
{
    int n,i,j,t;
    boost;
    int r,c;
    cin>>r>>c;
    pii mv[4]={{-1,0},{0,1},{1,0},{0,-1}};
    string arr[r];
    rep(i,0,r)cin>>arr[i];

    int ans=0;
    rep(i,0,r)
    {
        rep(j,0,c)
        {
            if(arr[i][j]=='.')
            {
                clean(vis);
                queue<pii> q;
                
                q.push({i,j});
                vis[i][j]=1;
                lvl[i][j]=0;
                while(!q.empty())
                {
                    pii s=q.front();
                    q.pop();
                    for(auto z:mv)
                    {
                        int x=s.F+z.F;
                        int y=s.S+z.S;
                        if(x>=0 && x<r && y>=0 && y<c && arr[x][y]=='.' && !vis[x][y])
                        {
                            vis[x][y]=1;
                            lvl[x][y]=1+lvl[s.F][s.S];
                            ans=max(ans,lvl[x][y]);
                           // cout<<x<<" "<<y<<' '<<lvl[x][y]<<'\n';
                            q.push({x,y});
                        }
                    }
                }
                
            }
        }
    }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner stdIn= new Scanner(System.in);
        String x = stdIn.next();
        if(x.equals("ABC")){
            System.out.println("ARC");
        }else{
            System.out.println("ABC");
        }
    }
}


Measured memory_bytes: 35132
#include <stdio.h>
int main (void){
 int num;
  scanf("%d",&num);
  if(num <= 999){
    printf("ABC");
  } else if(1000 <= num && num <= 1998){
    printf("ABD");
  } else {
    printf("回数の範囲外です");
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;

int main(){
  long long int k, a, b;
  cin >> k >> a >> b;
  long long int ans=k+1, x=((k-a+1)/2)*(b-a)+a;
  if((k-a+1)%2==1)x++;
  ans=max(ans, x);

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


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


int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c>=22){
        cout << "bust" << endl;
    }else{
        cout << "win" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pa;
const int maxn=2e5+7;
const int mod=1e9;
int n,t,m;
char a[maxn];
int main()
{
    int s=0;
    scanf("%d%d",&n,&m);
    while(n){
        n/=m;
        s++;
    }
    printf("%d\n",s);
    return 0;
}


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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> cnt(M);
  for(int i = 0; i < N; i++){
    int K;
    cin >> K;
    for(int j = 0; j < K; j++){
      int A;
      cin >> A;
      A--;
      cnt[A]++;
    }
  }

  int ans = 0;
  for(int i = 0; i < M; i++){
    if(cnt[i] == N){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <string>
#include<string.h>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
const int maxn=2e5+10;
multiset<int > msd,mst;
int main(){
    int n,m;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int x;
        scanf("%d",&x);
        msd.insert(x);
    }
    scanf("%d",&m);
    for(int i=0;i<m;i++){
        int x;
        scanf("%d",&x);
        mst.insert(x);
    }
    bool flag=true;
    for(auto it=mst.begin();it!=mst.end();it++){
        auto f=msd.find(*it);
        if(f!=msd.end()) msd.erase(f);
        else{
            flag=false;
            break;
        }
    }
    if(flag) printf("YES\n");
    else printf("NO\n");
    return 0;
}
/*
A
string s;
int main(){
    cin>>s;
    //string t="FESTIVAL";
    int len=s.length();
    cout<<s.substr(0,len-8)<<endl;
	return 0;
}

*/


Measured memory_bytes: 18944
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    VI  p(n);
    REP(i,0,n) cin >> p[i];
    int minv = p[0];
    int ans = 1;
    REP(i,1,n) {
        if (p[i] < minv) {
            ++ans;
            minv = p[i];
        }
    }
    cout << ans << endl;
}

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

Measured memory_bytes: 1024
# 実装する
# BCをXとしたとき、AとXだけが含まれる部分列は操作終了後に左側にX右側にAが詰まる
# AXXAAXのときはXXXAAAになる Aが右側に移動すると考える
# Aの移動距離 部分列長6にAが3個ある それぞれのAの初期位置から最終的に移動する位置までの距離
# （Aの初期位置位置[1 4 5]が最終的に[4 5 6]にくるのでその差）
# しゃくとりっぽい操作でいけそう
s = input()
t = s.replace("BC", "X", len(s))
ans = 0
left, right = 0, 0
while left < len(t):
    # 部分列の左端を見つける
    if t[left] not in ["A", "X"]:
        left += 1
        continue
    a_indicies = []
    a_count = 0
    a_idx = 0
    if t[left] == "A":
        a_indicies.append(a_idx)
        a_count += 1
    right = left + 1
    a_idx += 1
    while right < len(t) and t[right] in ["A", "X"]:
        if t[right] == "A":
            a_indicies.append(a_idx)
            a_count += 1
        right += 1
        a_idx += 1
    # leftからrightまでの部分列にAしか含まれていないorXしか含まれていない場合は考えない
    if right - left != a_count and a_count != 0:
        for i in range(a_count):
            ans += ((right - left) - (a_count - i)) - a_indicies[i]  # 適当
    left = right + 1
print(ans)

Measured memory_bytes: 17124
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
string c[] = {"w","","k","s","t","n","h","m","y","r"};
string s;
int main(void){
  cin >> s;
  for(int i = 0; i < (int)s.size(); i+=2){
    if(s[i] == '0' && s[i+1] == 'U'){
      cout << "nn";
      continue;
    }
    cout << c[s[i]-'0'];
    switch(s[i+1]){
    case 'T': cout << 'a'; break;
    case 'L': cout << 'i'; break;
    case 'U': cout << 'u'; break;
    case 'R': cout << 'e'; break;
    case 'D': cout << 'o'; break;
    }
  }
  cout << endl;
}

Measured memory_bytes: 1196
//2714 ???????????\ 1b
import java.util.Scanner;
public class Main{
    int zyo=0;
    
    public void solve(){
        Scanner sc=new Scanner(System.in);
        int x=sc.nextInt();
        zyo=x*x*x;
        System.out.println(zyo);
    }
    
    public static void main(String[] args){
        Main obj=new Main();
        obj.solve();
    }
}

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

using namespace std;
double pi=3.1415926535;
int main()
{
    int x,a,b,v;
    double t,tant,pans,ans;
    cin >> a >> b >> x;
    v=a*a*b;
	if(x>=v/2)
	{
		t=(double)(2*v-2*x)/(a*a);
		tant=(double)t/a;
		pans=atan(tant);
		ans=(double)pans*180/pi;
	}
	else if(x<v/2)
	{
		t=(double)2*x/(a*b);
		tant=(double)b/t;
		pans=atan(tant);
		ans=(double)pans*180/pi;
	}
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}


Measured memory_bytes: 384
function Main(input) {

	var str  = input;
  var min = 753;
  var possib = 0;
  var anse = 0;
  for(var i = 0; i < str.length - 2 ; i++){
    var possib = parseInt(str[i] + "" +str[i+1]+ '' + str[i+2]);
    if(Math.abs(possib - 753) < min){
      min = Math.abs(possib - 753);
      anse = possib;
    }
  }
	console.log(min);
}

//Main("1234567876");
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
LL n,sum[110][6],W,w[6],cnt=1,c1=0,c2=0,c3=0,c4=0;
LL res=0,ans=0;
struct Node{
    int w,v;
}a[110];

bool cmp(Node x,Node y){
    if(x.w<y.w) return true;
    if(x.w==y.w && x.v>y.v) return true;
    return false;
}

LL getsum(int i,int j,int k,int l){
    return (sum[i][1]+sum[j][2]+sum[k][3]+sum[l][4]);
}

int main(){
    scanf("%lld%lld",&n,&W);
    for(int i=1;i<=n;i++){
        scanf("%d%d",&a[i].w,&a[i].v);
    }
    sort(a+1,a+1+n,cmp);
    w[cnt]=a[1].w;
    for(int i=1;i<=n;i++){
        if(a[i].w!=w[cnt])
            w[++cnt]=a[i].w;
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i].w==w[1]){
            sum[++c1][1]=sum[c1-1][1]+a[i].v;
        }
        else if(a[i].w==w[2]){
            sum[++c2][2]=sum[c2-1][2]+a[i].v;
        }
        else if(a[i].w==w[3]){
            sum[++c3][3]=sum[c3-1][3]+a[i].v;
        }
        else
            sum[++c4][4]=sum[c4-1][4]+a[i].v;
    }
    for(int i=c1+1;i<=n;i++)
    {
        sum[i][1]=sum[i-1][1];
    }
    for(int i=c2+1;i<=n;i++)
    {
        sum[i][2]=sum[i-1][2];
    }
    for(int i=c3+1;i<=n;i++)
    {
        sum[i][3]=sum[i-1][3];
    }
    for(int i=c4+1;i<=n;i++)
    {
        sum[i][4]=sum[i-1][4];
    }
    LL k,m;
    LL tem=(W/w[1])+1;
    m=n < tem ? n : tem;
    for(int i=0;i<=m;i++){
        for(int j=0;i+j<=m;j++)
            for(int k=0;i+j+k<=m;k++)
            {
                res=i*w[1]+j*w[2]+k*w[3];
                if(res>W) continue;
                else if(res <= W)
                {
                    int l=0;
                    if(w[4]!=0) l=(W-res)/w[4];
                    ans=max(ans,getsum(i,j,k,l));
                }
            }
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
using namespace std;
vector<int> use_prime;
void eratos(bool cp_list[],int max){
  for(int i=2;i<max;i++){
    cp_list[i]=true;
  }
  for(int i=2;i<=max;i++){
    if(cp_list[i]){
      for(int j=i;j<=max;j+=i){
        cp_list[j]=false;
      }
      if(i%5==1) use_prime.push_back(i);
    }
  }
}
int main(){
  int n;
  bool pr_list[60000];
  cin >> n;
  eratos(pr_list,55555);
  for(int i=0;i<n;i++){
    cout << use_prime[i]<<" ";
  }
  cout << "\n";
}


Measured memory_bytes: 256
/*  Success may not come to me immediately,
 *  but it will come definitely....
 */
#include<bits/stdc++.h>
//=====================================================================
using namespace std;
//=====================================================================
#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
//=====================================================================
#define li      int64_t
#define ld      double_t
#define ulli    uint64_t
//=====================================================================
#define rep(i,a,b)  for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define repi(i,v)   for(i=v.begin();i!=v.end();i++)
#define repir(i,v)  for(i=v.rbegin();i!=v.rend();i++)
#define elif        else if
#define mset(a,b)   memset(a,b,sizeof(a))
#define nl          cout<<'\n'
//=====================================================================
typedef vector<li>       vli;
typedef vector<string>   vstr;
typedef pair<li,li>      pli;
typedef pair<li,pli >    ppli;
typedef pair<li,ppli >   pppli;
typedef vector<pli >     vpl;
typedef vector<ppli >    vppli;
typedef vector<pppli >   vpppli;
//=====================================================================
#define pb  push_back
#define pob pop_back
#define pf  push_front
#define pof pop_front
#define all(v)  v.begin(),v.end()
#define itr iterator
#define rtr reverse_iterator
#define sz  size()
#define lb  lower_bound
#define ub  upper_bound
#define bs  binary_search
#define mp  make_pair
#define F   first
#define S   second
//=====================================================================
#define mod (li)(1e9+7)
#define inf (li)(1e18)
#define MX1 (li)(1e5+5)
#define MX2 (li)(1e6+5)
#define pi  acos(-1)
//=====================================================================
li power(li a,li b){li ans=1;while(b){if(b&1){ans=(ans*a)%mod;}
a=(a*a)%mod;b>>=1;}return ans;}
//=====================================================================
li mmi(li n){return power(n,mod-2);}
//=====================================================================
li two(li n){return (1LL<<n);}
//=====================================================================
void onbit(li &n,li x){n|=two(x);}
//=====================================================================
void offbit(li &n,li x){n&=~two(x);}
//=====================================================================
li cntbit(li n){li res=0;while(n and ++res)n-=n&-n;return res;}
//=====================================================================
li dx[]={-1,0,1,0},dy[]={0,-1,0,1};
//=====================================================================
/*------------------------MAIN CODE BEGINS NOW!------------------------*/

li n,k,a[105];

void solve(){
  li i;cin>>n>>k;
  rep(i,1,n+1) cin>>a[i];
  li ans=0;
  rep(i,1,n+1){
    ans+=min(2*a[i],2*(abs(k-a[i])));
  }
  cout<<ans;
}

int main(){
  opt
  #ifndef ONLINE_JUDGE
  #endif
  li t=1;
  //cin>>t;
  while(t--){
    solve();
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

int main() {
    int r;
    cin >> r;
    if(r < 1200){
        cout << "ABC" << endl;
    }else if(r < 2800){
        cout << "ARC" << endl;
    }else{
        cout << "AGC" << endl;
    }
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int b, a, ans;
	cin >> a >> b;
	if(a>=13) ans = b;
	else if(a>=6 && a<=12) ans = b/2;
	else ans = 0;
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <limits>
#include <string>
#include <bitset>
#include <functional>
#include <iomanip>

using namespace std;
using lint = long long;
using vb = vector<bool>;
using vi = vector<int>;
using vl = vector<int>;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
using pqi = priority_queue<int>;
using pql = priority_queue<lint>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define repf(i, f, n) for (int i = (f); i < (n); i++)
#define mp(x, y) make_pair((x), (y))
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define foreach(it, x) for (auto it = (x).begin(); it != (x).end(); it++)
#define space (char)0x20

constexpr lint MOD = 1e9 + 7;
int A, B, C, D, E, F, G, H, I, J, K, L, M, N;
int O, P, Q, R, S, T, U, V, W, X, Y, Z;
// string s;
lint ans = 0LL;
vl a, b, c;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	cin >> X >> Y >> A >> B >> C;

    a.resize(A);
    b.resize(B);
    c.resize(C);
    rep(i, A) cin >> a[i];
    rep(i, B) cin >> b[i];
    rep(i, C) cin >> c[i];
    sort(allr(a));
    sort(allr(b));
    sort(allr(c));

    rep(i, X) ans += a[i];
    rep(i, Y) ans += b[i];

    int ai = X - 1;
    int bi = Y - 1;
    int ci = 0;

    while (true) {
        if (ci >= C) break;

        if (ai >= 0 && bi >= 0) {
            if (c[ci] < min(a[ai], b[bi])) break;
            if (a[ai] <= b[bi]) {
                ans -= a[ai];
                ai--;
            } else {
                ans -= b[bi];
                bi--;
            }
        } else if (ai >= 0) {
            if (c[ci] < a[ai]) break;
            ans -= a[ai];
            ai--;
        } else if (bi >= 0) {
            if (c[ci] < b[bi]) break;
            ans -= b[bi];
            bi--;
        } else {
            break;
        }

        ans += c[ci];
        ci++;
    }

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

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 500 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int d[5];

int main() {
    for(int i = 0; i < 3; ++i) {
        int u, v;
        scanf("%d%d", &u, &v);
        ++d[u];
        ++d[v];
    }
    int odd = 0;
    for(int i = 1; i <= 4; ++i) {
        if(d[i]&1) ++odd;
    }
    if(odd == 2) puts("YES");
    else puts("NO");
    return 0;
}


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

int main(void)
{
  char s[11];
  
  scanf("%s", s);
  
  if (strcmp(s, "hi") == 0 || strcmp(s, "hihi") == 0 || strcmp(s, "hihihi") == 0 || strcmp(s, "hihihihi") == 0 || strcmp(s, "hihihihihi") == 0)
    puts("Yes");
  else
    puts("No");
  
  return 0;
}


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

const int MAXN = 22;
typedef long long ll;
#define f first
#define s second
const ll mod = 1e9+7;

int arr[MAXN][MAXN];
ll dp[MAXN][1<<MAXN];

int main(){
    int N,cur;
    scanf("%d",&N);
    for (int i=0;i<N;i++){
        for (int j=0;j<N;j++){
            scanf("%d",&arr[i][j]);
        }
    }
    dp[0][0] = 1;
    for (int i=0;i<(1<<N);i++){
        cur = 0;
        for (int j=0;j<N;j++){
            if (i&(1<<j)) cur++;
        }
        for (int j=0;j<N;j++){
            if (!(i&(1<<j))&&arr[cur][j]){
                dp[cur+1][i|(1<<j)] += dp[cur][i];
                dp[cur+1][i|(1<<j)] %= mod;
            }
        }
    }
    printf("%d\n",dp[N][(1<<N)-1]%mod);
}

Measured memory_bytes: 321792
#include<iostream>
#include<queue>
#include<algorithm>
#include<cstdio>
#include<map>

using namespace std;

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

class puzzle
{
public:
	int f[8];
	int space;
	int count;
	bool operator<(const puzzle &p)const
	{
		for(int i=0;i<8;i++)
		{
			if(f[i]==p.f[i])continue;
			return f[i]<p.f[i];
		}
		return false;
	}
};

bool is(puzzle p)
{
	for(int i=0;i<8;i++)
	{
		if(p.f[i]!=i)return false;
	}
	return true;
}

int encode(puzzle p)
{
	int ans=0;
	for(int i=0;i<8;i++)
	{
		ans+=p.f[i];
		ans*=10;
	}
	return ans/10;
}

map<int,int>V;

void bfs(puzzle p)
{
	queue<puzzle>q;
	V[encode(p)]=1;
	p.count=1;
	q.push(p);
	
	while(!q.empty())
	{
		puzzle u=q.front();q.pop();
		int sx=u.space/4;
		int sy=u.space%4;
		for(int r=0;r<4;r++)
		{
			int tx=sx+dx[r];
			int ty=sy+dy[r];
			if(tx<0||ty<0||tx>=2||ty>=4)continue;
			puzzle v=u;
			swap(v.f[u.space],v.f[tx*4+ty]);
			v.space=tx*4+ty;
			if(V[encode(v)]==0)
			{
				v.count=V[encode(v)]=u.count+1;
				
				q.push(v);
			}
		}
	}
	return;
}

int main()
{
	puzzle ans;
	for(int i=0;i<8;i++)ans.f[i]=i;
	ans.space=0;
	bfs(ans);
	int a[8];
	while(~scanf("%d%d%d%d%d%d%d%d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7]))
	{
		puzzle in;
		for(int i=0;i<8;i++)
		{
			if(a[i]!=0)in.f[i]=a[i];
			else
			{
				in.f[i]=0;
				in.space=i;
			}
		}
		cout<<V[encode(in)]-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 4176
#B - Five Dishes 
import itertools
ABCDE = [int(input()) for _ in range(5)]
def calc(food):
    time = 0
    for i in food:
        if time % 10 != 0:
            while time % 10 != 0:
                time += 1    
        time += i
    return time
FOOD = list(itertools.permutations(ABCDE))

mini = 650
for j in FOOD:
        ans = calc(list(j))
        if mini > ans:
            mini = ans

print(mini)

Measured memory_bytes: 64100
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int, input().split())) for l in range(D)]
t = [int(input()) for i in range(D)]
score = 0
last = [0]*26

def score_down(d):
    ans = 0
    for i in range(26):
        ans += c[i]*(d - last[i])
    return ans

for d in range(len(t)):
    i = t[d] - 1
    last[i] = d+1
    score += s[d][i]
    score -= score_down(d+1)
    print(score)

Measured memory_bytes: 9392
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  if (( N % 10 ) == ((( N - ( N % 10)) / 10 ) % 10 ) 
      && ( N % 10 ) == ((( N - ( N % 100)) / 100 ) % 10 ))
    cout << "Yes" << endl;
  else if (( N / 1000 ) == ((( N - ( N % 10)) / 10 ) % 10 ) 
      && ( N / 1000 ) == ((( N - ( N % 100)) / 100 ) % 10 ))
    cout << "Yes" << endl;
  else
    cout << "No" <<endl;
}

Measured memory_bytes: 256
func readInts() -> [Int]{
    return readLine()!.split(separator: " ").map{Int($0)!};
}
let a = readInts();
let N = a[0], M = a[1];
var A: Array<Array<Int>> = Array();
for i in 0 ..< M {
    let b = readInts();
    A.append([Int]());
    for j in 0 ..< N {
        A[i].append(0);
    }
    for j in 1 ... b[0] {
        A[i][b[j]-1] = 1;
    }
}
var answer = 0;
let p = readInts();
for bit in 0 ..< (1<<N) {
    var rock = 0;
    var check: Array<Int> = Array(repeating: 0, count: 12);
    for i in 0 ..< N {
        if bit & 1<<i > 0 {
            check[i] = 1;
        }
    }
    for i in 0 ..< M {
        var count = 0;
        for j in 0 ..< N {
            if check[j] == 1 && A[i][j] == 1 {
                count += 1;
            }
        }
        if count % 2 == p[i] {
            rock += 1;
        }
    }
    if rock == M {
        answer += 1;
    }
}
print(answer);

Measured memory_bytes: 8252
#include <iostream>
using namespace std;
int main(void){
    int n,c;
    cin>>n>>c;
    int i;
    int s=0;
    for(i=0;i<c;i++){
        int p;
        cin>>p;
        s=s+p;
    }
    if(s%(n+1)==0)  cout<<s/(n+1);
    else    cout<<s/(n+1)+1;
    cout<<endl;
}


Measured memory_bytes: 3104
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
int main() {
	int x, h, m, s;
	cin >> x;
	h = x / 3600;
	x = x % 3600;
	m = x / 60;
	x = x % 60;
	s = x;
	cout << h << ":" << m << ":" << s << endl;
	return 0;
}


Measured memory_bytes: 3116
/**
 * @author torith
 * @date 2018-11-09
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;

    string ans = "";
    while(N != 0){
        int r = N % 2;
        if(N % 2 == 0) ans = "0" + ans;
        else ans = "1" + ans;

        if(r < 0) r = 1;

        N = (N - r) / (-2);
    }

    if(ans.size() == 0) cout << "0" << "\n";
    else cout << ans << "\n";

    return 0;
}



Measured memory_bytes: 256
function main(input) {
    input=input.split(" ");
    var N = parseInt(input[0],10);
    var Y = parseInt(input[1],10);
    //console.log(input);
    var result =''
   for (var x=0;x<=N; x++){
     for(var y=0;y<=(N-x);y++){
     var z=(N-x-y)
      if(10000*x+5000*y+1000*z===Y){
        console.log(x+' '+y+' '+z);
        result='OK';
        break;
      }
     }
     if (result ==='OK'){
     break;
     }
   }
   if (result ===''){
     console.log('-1 -1 -1')
   }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7756
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> a(M);
  vector<int> b(M);
  for(int i=0;i<M;i++){
    cin >> a.at(i) >> b.at(i);
  }

  vector<int> ans(N,0);
  for(int i=0;i<M;i++){
    int x = a.at(i);
    int y = b.at(i);
    ans.at(x-1)++;
    ans.at(y-1)++;
  }
  
  for(int i=0;i<N;i++){
    cout << ans.at(i) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include<cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include<iostream>
#include<list>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include <vector>

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

using namespace std;

int main() {
	int N, A[2][100], S[2][100];
	cin >> N;
	REP(j, 2) {
		REP(i, N) {
			cin >> A[j][i];
		}
	}

	REP(i, N) {
		REP(j, 2) {
			if (i == 0 && j == 0) {
				S[j][i] = A[j][i];
			}
			else if (j == 0) {
				S[j][i] = S[j][i-1] + A[j][i];
			}
			else if (i == 0 && j == 1) {
				S[j][i] = S[j-1][i] + A[j][i];
			}
			else {
				S[j][i] = max(S[j][i-1], S[j-1][i]) + A[j][i];
			}
		}
	}

	cout << S[1][N - 1] << endl;

	return 0;
}

Measured memory_bytes: 256
from sys import stdin
from heapq import heappush, heappop

class Dijkstra:
    def __init__(self, N):
        self.N = N # #vertices
        self.E = [[] for _ in range(N)]

    def add_edge(self, init, end, weight, undirected=False):
        self.E[init].append((end, weight))
        if undirected: self.E[end].append((init, weight))
    
    def distance(self, s):
        INF = float('inf')
        E, N = self.E, self.N
        self.dist = dist = [INF] * N # the distance of each vertex from s
        self.prev = prev = [-1] * N # the previous vertex of each vertex on a shortest path from s
        dist[s] = 0
        n_visited = 1 # #(visited vertices)
        heap = []
        heappush(heap, (0, s))
        while heap:
            d, v = heappop(heap)
            if dist[v] < d: continue
            for u, c in E[v]:
                temp = d + c
                if dist[u] > temp:
                    dist[u] = temp; prev[u] = v
                    heappush(heap, (temp, u))
            n_visited += 1
            if n_visited == N: break
        return dist
    
    def shortest_path(self, t):
        P = []
        prev = self.prev
        while True:
            P.append(t)
            t = prev[t]
            if t == -1: break
        return P[::-1]


def get_result(data):
    N, M = data[0]
    A = data[1:]
    solver = Dijkstra(N)
    for val in A:
        solver.add_edge(val[0]-1, val[1]-1, 1, undirected=True)
    solver.distance(0)
    prev = solver.prev
    print('Yes')
    for p in prev[1:]:
        print(p + 1)
    return None

if __name__ == '__main__':
    raw_data = [val.rstrip() for val in stdin.readlines()]
    data = [list(map(int, val.split(' '))) for val in raw_data]
    get_result(data)

Measured memory_bytes: 113232
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define for_t int t;cin>>t;while(t--)
#define MOD 1000000007
#define fi first
#define se second
#define le length
#define debug(n1) cout << n1 << endl
#define set_bits(n) __builtin_popcount(n);
#define rep(i , j , n) for(ll i = j ; i <= n ; i++)
#define per(i , j , n) for(ll i = j ; i >= n ; i--)
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef map<int, int>mapp;
int main() {
    SPEED;
    string s;
    string t;
    cin>>s;
    cin>>t;
    int ans =0;
    if(s[0]==t[0]){
        ans++;
    }
    if(s[1]==t[1]){
        ans++;
    }
    if(s[2]==t[2]){
        ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <stdio.h>

long int factorial(int);

int main(void) 
{
	int n;

	scanf("%d", &n);

	printf("%ld\n", factorial(n));

	return 0;
}

long int factorial(int n) 
{
	if (n > 1) 
		return (n * factorial(n - 1));
	else 
		return n;
}

Measured memory_bytes: 592
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1e16;
ll fac[MAX], finv[MAX], inv[MAX];
//ダイクストラ法は負の経路があるとき使えない→ベルマンフォード法
//単一終点ならedgeの向きを逆にして考える
int main(){
  ll v;cin>>v;
  vector<vp> g(v);vll dis(v,MOD),prev(v,-1);
  rep(i,0,v-1){
    ll s,t,d;cin>>s>>t>>d;
    s--;t--;
    g[s].push_back(make_pair(t,d));
    g[t].push_back(make_pair(s,d));
  }
  ll q,k;cin>>q>>k;
  vll x(q),y(q);
  rep(i,0,q){
    cin>>x[i]>>y[i];
    x[i]--;y[i]--;
  }
  priority_queue<P,vector<P>,greater<P> > pq;
  dis[k-1]=0;
  pq.push(make_pair(dis[k-1],k-1));
  while(!pq.empty()){
    P p=pq.top();
    pq.pop();
    ll from=p.second;
    if(dis[from]<p.first)continue;
    for(auto &edge:g[from]){
      if(dis[edge.first]>dis[from]+edge.second){
        dis[edge.first]=dis[from]+edge.second;
        prev[edge.first]=from;
        pq.push(make_pair(dis[edge.first],edge.first));
      }
    }
  }
  rep(i,0,q){
    cout<<dis[x[i]]+dis[y[i]]<<endl;
  }
}





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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cerr <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}

#define CD complex<double>
#define PDD pair<double, double> 
using namespace std;

const int max_n = 6e5+10;

int n;
string s;
map<pair<string,int> , lint> ans[2];


int main() {
	cin >> n >> s;
	FOR(u,0,2) {
		FOR(i,0,1<<n) {
			string s1 ="", s2 = "";
			FOR(j,0,n) {
				if (i&(1<<j)) s1 = s1 + s[j];
				else s2 = s2 + s[j];
			}
			reverse(all(s2));
			ans[u][{s1+s2,s1.length()}]++;
		}
		reverse(all(s));
	}
	lint res = 0;
	FORE(i,ans[0]) {
		string u = i->st.st;
		int len = i->st.nd;
		reverse(all(u));
		res += (i->nd * 1LL * ans[1][{u,n-len}]);
	}
	cout << res << endl;
}





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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#pragma GCC optimize ("-O3")

using namespace std;

#define DUMPOUT cout
#define dump(...) if(DEB) DUMPOUT<<"  "<<#__VA_ARGS__<<" :["<<__LINE__<<":"<<__FUNCTION__<<"]"<<endl<<"    "; if(DEB) dump_func(__VA_ARGS__)
template<typename T1,typename T2>ostream& operator << (ostream& os, pair<T1,T2> p){cout << "(" << p.first << ", " << p.second << ")"; return os;}
template<typename T>ostream& operator << (ostream& os, vector<T>& vec) { os << "{"; for (int i = 0; i<vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "}"; return os; }
template<typename T>ostream& operator << (ostream& os, set<T>& st){cout << "{"; for(auto itr = st.begin(); itr != st.end(); itr++) cout << *itr << (next(itr)!=st.end() ? ", " : ""); cout << "}"; return os;}
template<typename T1,typename T2>ostream& operator << (ostream& os, map<T1,T2> mp){cout << "{"; for(auto itr = mp.begin(); itr != mp.end(); itr++) cout << "(" << (itr->first) << ", " << (itr->second) << ")" << (next(itr)!=mp.end() ? "," : ""); cout << "}"; return os; }

void dump_func(){DUMPOUT << endl;}
template <class Head, class... Tail>void dump_func(Head&& head, Tail&&... tail){ DUMPOUT << head; if (sizeof...(Tail) == 0) { DUMPOUT << " "; } else { DUMPOUT << ", "; } dump_func(std::move(tail)...);}
template<class T> inline bool chmax(T& a,T const& b){if(a>=b) return false; a=b; return true;}
template<class T> inline bool chmin(T& a,T const& b){if(a<=b) return false; a=b; return true;}


void solve(long long N, long long A, long long B, std::vector<long long> t){
  int cnt = 0;
  rep(i,N) if(t[i]>=A&&t[i]<B) cnt++;
  cout << N-cnt << endl;
}

int main(){
    long long N;
  scanf("%lld",&N);
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  std::vector<long long> t(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&t[i]);
  }
    solve(N, A, B, std::move(t));
    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define print(x) cout << x << endl

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

ll MOD = 1000000007;


int main()
{
    ll K;
    cin >> K;
    ll sum = 0;
    rep(i, K)
    {
        rep(j, K) {
            rep(k, K) {
                sum += gcd(i + 1, gcd(j + 1, k + 1));
            }
        }
    }
    print(sum);
    return 0;
}


Measured memory_bytes: 3576
#include <iostream>
using namespace std;
int main(void){
    int n,kari,count = 0,minj;
    cin >> n;
    int l[n];
    for(int i = 0; i < n; i++){
        cin >> l[i];
    }
    
    for(int i = 0; i <= n - 1 ; i++){
        minj  = i;
        for(int j = i; j <= n - 1; j++){
            if(l[j] < l[minj]){
                minj = j;
            }
        }
        kari = l[i];
        l[i] = l[minj];
        l[minj] = kari;
        if(i != minj){
            count++;
        }
    }
    
    for(int k = 0; k < n-1; k++){
        cout << l[k] << " ";
    }
    cout << l[n-1] << endl;
    cout << count << endl;
}
    



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

int main() {
    string s;
    cin >> s;
    if (s.size() >= 4 && s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I') {
        puts("Yes");
    } else {
        puts("No");
    }
}


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

#define N 100010
int n;

void P(int x, int y) {
	printf("%d %d\n", x, y);
}

int main() {
	while (scanf("%d", &n) != EOF) {
		int m = 1;
		while (m < n) m <<= 1;
		if (n < 3 || m == n) puts("No");
		else {
			puts("Yes");
			P(1, n + 2); P(n + 2, 3);
			P(3, n + 1); P(n + 1, 2);
			P(2, n + 3);
			for (int i = 4; i < n; i += 2) {
				P(i, n + 1); P(i, n + i + 1);
				P(i + 1, n + 1); P(n + i, i + 1);
			}
			if (n % 2 == 0) {
				for (int i = 2; i < n; ++i) {
					if ((n ^ (i ^ 1)) < n) {
						int a = i;
						int b = n ^ i ^ 1;
						P(n, a); P(n + n, b);
						break;
					}
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 2816
n = int(input())
ans = 0
for j in range(1,n+1):
  if j %2 ==0:
    continue
  div = []
  for i in range(2,j+1):
    if j % i ==0:
      count = 0
      while j%i==0:
        j = j//i
        count += 1
      div.append(count)
    if j == 1:
      break
  if div == [1,1,1] or div == [1,3] or div ==[3,1]:
    ans += 1
    
print(ans)




Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), q = sc.nextInt();
		String s = sc.next();
		int ac[] = new int[n];
		String tmp = "AC", tmp2 = "";
		for (int i = 0; i < n - 1; ++i) {
			ac[i + 1] = ac[i];
			tmp2 = s.substring(i,  i + 2);
			if (tmp2.equals(tmp)) 
				ac[i + 1] = ac[i] + 1;
		}
		for (int i = 0; i < q; ++i) {
			int l = sc.nextInt(), r = sc.nextInt();
			int ans = ac[r - 1] - ac[l - 1];
			System.out.println(ans);
		}
		sc.close();

	}

}


Measured memory_bytes: 64912
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int N = ni();
        int[] A = new int[N];
        for ( int i = 0; i < N; i++) {
            A[i] = ni();
        }
        ArrayList<Integer> list = new ArrayList<>();
        list.add(A[N-1]);
        for (int j = N-2; j >=0; j--) {
            int index = Collections.binarySearch(list, A[j],(x, y) -> x.compareTo(y) > 0 ? 1 : -1);
            if(index<0) index = ~index;
            if(index == list.size()) list.add(A[j]);
            else list.set(index,A[j]);
            // System.out.println(list.toString());
        }
 
        long ans = list.size();
        out.println(ans);
    }

    final int mod = 1000000007;
    int mul(int x, int y){
        return (int)((x * 1L * y) % mod);
    }
    int add(int x, int y) {
        x += y;
        return x >= mod ? (x - mod) : x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        return x >= mod ? (x - mod) : x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 55420
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
typedef long long ll;
typedef long double ld;
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))

int main() {
	int k; char s[101] = { '\0' };
	scanf("%d\n%s",&k,s);
	if (strlen(s) <= k)printf("%s", s);
	else { rep(i, k)printf("%c", s[i]); printf("..."); }
}

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	string s ;
	cin >> s ;
//3文字見ればいいんじゃない？
	for(int i = 0 ; i < s.size() ; i ++ ){
		if( i + 2 >= s.size()) break;
		if(s[i] == s[i+1] || s[i] == s[i+2] || s[i+1] == s[i+2]){
			cout <<i+1 << " " << i + 3 << endl;
			return 0 ;
		}
	}
	for(int i = 0 ; i < s.size() ; i ++){
		if(i+1 >= s.size() ) break;
		if(s[i]==s[i+1]){
			cout << i +1 << " " << i + 2 << endl;
			return 0 ;
		}
	}
	cout << "-1 -1" << endl;
}


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

int main() {
	string s;
	ll n;
	cin >> n;
	map<string, ll> words;
	for (ll i = 0; i < n; ++i) {
		cin >> s;
		sort(s.begin(), s.end());
		if (words.count(s) == 0) words.emplace(s, 1);
		else words.at(s)++;
	}
	ll ans = 0;
	for (const auto& itr : words) {
        ans += itr . second * (itr . second - 1) / 2;
	}
	cout << ans << endl;
}


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

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ar array
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll mod = 1e9 + 7;
const ll inf = 2e9 + 5;
double PI = 3.14159265358979323846;


void solve() {

    int n, W;
    cin >> n >> W;
    ll wt[n], val[n];
    for (int i = 0; i < n; i++) {
        cin >> wt[i] >> val[i];
    }

    ll dp[n + 1][W + 1];
    memset(dp, 0, sizeof(dp));

    // dp[i][j] = maximum value possible with frst i elements and the capacity of 
    // the knapsack is j

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= W; j++) {
            if (j - wt[i-1] >= 0) {
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - wt[i-1]] + val[i-1]);
            }else{
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    cout << dp[n][W] << endl;


}

int32_t main()
{
    IOS
    // int T; cin >> T; while (T--)
    solve();
    return 0;
}


Measured memory_bytes: 82420
#include <iostream>
using namespace std;
#define MAX 100

int main()
{
	int g[MAX][MAX] = { 0 };
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int id, k;
		cin >> id >> k;
		for (int j = 0; j < k; j++) {
			int c;
			cin >> c;
			g[id - 1][c - 1] = 1;
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cout << g[i][j];
			if (j < n - 1) {
				cout << " ";
			}
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3156
/* ex3_2
    nnasy */

#include <stdio.h>

int main(void) {
    int num;    //整数変数の宣言
    scanf("%d", &num);    //numに入力

    switch(num%10){    //numの一の位の値を比較する
        case 0:
        case 1:
        case 6:
        case 8:
            printf("pon\n");    //numの一の位が0,1,6,8ならば pon を出力            
            break;
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            printf("hon\n");    //numの一の位が2,4,5,7,9ならば hon を出力
            break;
        case 3:
            printf("bon\n");    //numの一の位が3ならば bon を出力
            break;
        default:
            printf("nonValid\n");    //0もしくは負の値をnumに入力したとき
            break;
    }

    return 0;
}

Measured memory_bytes: 1656