akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

int n;
int a,b;

int f(int n){
  if(n==0) return 0;
  return n%10 + f(n/10);
}

int main(){

  cin>>n;

  int ans = inf;
  FOR(i,1,n){
    a = f(i);
    b = f(n-i);
    ans = min(ans,a+b);
  }

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np
input = sys.stdin.readline
N = int(input())
T, A = [int(x) for x in input().split()]
H = np.array([int(x) for x in input().split()], np.int64)
H = -0.006 * H
H += T
H = abs(H - A)
minH = H.min()
ans = np.where(H == minH)[0][0] + 1
print(ans)

Measured memory_bytes: 12496
import sys
from string import digits

k = int(sys.stdin.readline().rstrip())

def main():
    if k <= 9:
        print(k)
        return
    res = list(digits[1:])
    r = k - 9
    nex = []
    while True:
        for n in res:
            o = ord(n[-1])
            for i in range(-1, 2):
                d = chr(o + i)
                if d < '0' or d > '9': continue
                nex.append(n + d)
                r -= 1
                if not r:
                    print(nex[-1])
                    return
        res = nex.copy()
        nex.clear()

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 9048
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define mp make_pair
#define timer ((double)clock() / CLOCKS_PER_SEC)
#define endl "\n"
#define spc " "
#define d1(x) cerr<<#x<<":"<<x<<endl
#define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;

const int N = (int)(1e6 + 5);
const int LOG = (int)(20);

int n, ans;
string s1, s2;

int main() {
	fast_io();
	// freopen("inp.in", "r", stdin);
	
	cin >> s1 >> s2;
	for(int i = 0; i < 3; i++)
		if(s1[i] == s2[i])
			ans++;
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i < n; i++)
#define rep3(i, n) for(int i = n-1; i >= 0; i--)
#define rep4(i, x, n) for(int i = x; i > n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e15;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    map<char, int> mp;
    rep(i, alpha.size()) mp[alpha[i]] = i;
    int N;
    string S;
    cin >> N >> S;
    ll count[26];
    fill_n(count, 26, 1);
    rep(i, N){
        int j = mp[S[i]];
        count[j]++;
    }
    ll ans = 1;
    rep(i, 26){
        ans *= count[i];
        ans %= MOD;
    }
    ans--;
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main(){
	int n;
	int A, B;
	int sum_A, sum_B;
	while (cin >> n, n != 0){
		sum_A = 0;
		sum_B = 0;
		for (int i = 0; i < n; i++){
			cin >> A >> B;
			if (A > B) sum_A += A + B;
			else if (A < B) sum_B += A + B;
			else{
				sum_A += A;
				sum_B += B;
			}
		}
		cout << sum_A << " " << sum_B << endl;
	}
}

Measured memory_bytes: 3064
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<vector<int>> v;
    for(int i=0;i<n;i++)
    {
        int x,y,z;
        cin>>x>>y>>z;
        v.push_back({x,y,z});

    }
   long dp[n][3];
   dp[0][0]=v[0][0];
   dp[0][1]=v[0][1];
   dp[0][2]=v[0][2];
   for(int i=1;i<n;i++)
   {
       for(int j=0;j<3;j++){
        dp[i][j]=v[i][j]+max(dp[i-1][(((j-1)+3)%3)],dp[i-1][(((j+1)+3)%3)]);
       }
   }
    long ans=max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    cout<<ans;

    return 0;
}


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

int main() {
	int h,w;cin >> h>>w;
	for (int i=0;i<h;++i){
		string s;cin>>s;
		cout << s << endl;
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
typedef long long int lli;
const lli mod = 1e9+7;
using namespace std;

int main()
{
	fast;
	
	int x,y,z;cin>>x>>y>>z;
	cout<<z<<" "<<x<<" "<<y<<"\n";
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

int main(){
  int N, T;
  cin >> N >> T;
  vector<ll> A;
  rep(i,N){
    ll a;
    cin >> a;
    A.push_back(a);
  }
  map<ll,ll> memo;
  ll mn = 10000000000000LL;
  rep(i,N){
    if(mn < A[i]){
      memo[A[i]-mn]++;
    }
    mn = min(mn, A[i]);
  }
  ll ret = 0;
  FOR(it,memo){
    if(it->first > ret) ret = it->first;
  }
  cout << memo[ret] << endl;
  
  return 0;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;



template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
  void add(int i, T x=1) {
    for (; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};

ll n;
vll a;


ll isOk(ll mid){
  // 中央値がmidに成り得る => "過半数"の区間が、mid以下の要素が"過半数"を占めている
  // NOTE: mid以下という条件にすると、midが中央値に成り得るにはmid以下の個数が半数より多い必要がある
  
  vll s(n+1); // 数列aにおいてmid以下である要素数の累積和
  rep(i,n){
    s[i+1]=s[i];
    if(a[i]<=mid) s[i+1]++;
    else s[i+1]--;
  }
  
  // midが中央値に成り得る区間の数を以下の方針で数え上げる
  // i<jかつs_j-s_i>=0なるi,jの組数を求める
  // jを固定して、s_j>=s_iなるiの個数の和を求める
  BIT<ll> bit(n*2+10);
  ll cnt=0;
  rep(i,n+1){
    // 累積和s_iは負の値を取る可能性があるのでオフセットを付ける必要がある
    // s_iは最小で-nとなるので、n+1のオフセットを付ける
    // s_j-s_i>=0である区間が、半分以上の要素がmid以下である区間なので、
    // 今見ている累積和(mid以下の要素数)がs_jのとき、先頭からの累積和がs_j以下である区間数を数える
    cnt+=bit.sum((s[i]+n+1)-1);
    bit.add(s[i]+n+1);
  }
  
  // cout<<cnt<<' '<<(n*(n+1)/2)/2<<endl;
  
  // 区間数の過半数。このborder以上の数の区間が条件を満たすならmidは中央値である可能性がある
  return cnt>(n*(n+1)/2)/2;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n;
  a.resize(n);
  rep(i,n) cin>>a[i];
  
  
  ll ok=1e9, ng=0;
  while(abs(ok-ng)>1){
    ll mid=(ok+ng)/2;
    if(isOk(mid)) ok=mid;
    else ng=mid;
  }
  cout<<ok<<endl;
}

Measured memory_bytes: 3456
import java.util.*;

class Main {
    static long p(long x,int k){
        long c=1;
        long lim=Long.MAX_VALUE/x;
        for(int j=0;j<k;++j){
            c*=x;
            if(c>=lim)return lim;
        }
        return c;
    }
    static long rt(long n,int e){
        long x=(long)Math.pow(n,1.0/e);
        long m=0;
        for(long i=Math.max(x-8,1);i<=x+8;++i){
            long c=p(i,e);
            if(c<=n)m=i;
        }
        return m;
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        long n=scan.nextLong();
        long a=scan.nextLong();
        long m=n;
        for(int k=2;k<=40;++k){
            long x=rt(n,k);
            for(int b=0;b<=k;++b){
                long p=p(x,b),q=p(x+1,k-b);
                if(p>=(n+q-1)/q)
                    m=Math.min(m,x*b+(x+1)*(k-b)+(k-1)*a);
            }
        }
        System.out.println(m);
    }
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    string s;
    cin >> s;

    int l = s.size();
    ll ans = 0, count = 0;
    if(l<3){
        cout << 0 << endl;
        return 0;
    }

    if(s[0] == 'A')
        count++;
    if(s[1] == 'A')
        count++;

    for(int i=2;i<l;i++){
        if(s[i] == 'A'){
            if(s[i-2] == 'A' && s[i-1] != 'A')
                count = 1;
            else
                count++;
        }
        if(s[i-2] == 'A' && s[i-1] != 'A' && s[i] != 'A'){
            if(s[i-2] == 'A' && s[i-1] == 'B' && s[i] == 'C'){
                ans++;
                s[i-2] = 'B';
                s[i-1] = 'C';
                s[i] = 'A';
                ans += count - 1; 
            }else{
                count = 0;
            }
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 640
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;

class ARegistration {
public:
	void solve(std::istream& in, std::ostream& out) {
        string s, t;
        in >> s >> t;
        t.pop_back();
        if (s == t) out << "Yes" << endl;
        else out << "No" << endl;
	}
};


int main() {
	ARegistration solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int x, y, z;
int value;

int main() {
  cin >> x >> y >> z;
  value = x;
  x = y;
  y = value;
  
  value = x;
  x = z;
  z = value;
  
  cout << x << " " << y << " " << z << endl;
}

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

int main(){
    int n;cin>>n;
    int flag=1;
    for(int i=0;i<n;i++){
        int a;cin>>a;
        if(a%2==0){
            if(a%3==0 or a%5==0){
                continue;
            }
            else flag=0;
        }
    }
    if(flag) cout<<"APPROVED"<<endl;
    else cout<<"DENIED"<<endl;
}


Measured memory_bytes: 256
/*
AtCoder Beginner Contest 092 A - Traveling Budget 結果:
*/

#include<stdio.h>

//#define DEBUG1

int main() {
	int a, b, c, d;
	int ans = 0;
		scanf("%d %d %d %d", &a, &b, &c, &d);
#ifdef DEBUG1
		printf("%d\n%d\n%d\n%d\n", a, b, c, d);
#endif
		if (a > b) {
			ans += b;
		}
		else
		{
			ans += a;
		}
		if (c > d) {
			ans += d;
		}
		else
		{
			ans += c;
		}
	printf("%d\n", ans);
#ifdef DEBUG1
	getch();
#endif
	return 0;
}

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

int main(){
    int n; cin >> n;
    set<string> s;
    rep(i, n){
        string x; cin >> x;
        s.insert(x);
    }
    cout << s.size() << endl;
    return 0;
}


Measured memory_bytes: 19184
#include <stdio.h>
#include <stdlib.h>

int comp(const void *a, const void *b) { return *(int *)b - *(int *)a; }

int N, A[100000];

int main(void) {
	int i, len[2] = {0};
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	qsort(A, N, sizeof(int), comp);

	for (i = 0; i < N - 1; i++) {
		if (A[i] == A[i + 1]) {
			if (len[0] == 0) {
				len[0] = A[i];
			}
			else {
				len[1] = A[i];
				break;
			}
			i++;
		}
	}

	printf("%lld", (long long int)len[0] * len[1]);
	return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

using namespace std;

typedef long long ll;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>pb_ds;

#define IN freopen("in.txt","r",stdin)
#define OUT freopen("out.txt","w",stdout)
#define pi pair<int,int>
#define F first
#define S second
#define pb push_back
#define pp pop_back
#define mod 1000000007
#define pai acos(-1)
#define N 1005

int n,m;
char s[N][N];
int cost[N][N];

bool valid(int x,int y){
   return x>=1&&x<=n&&y>=1&&y<=m;
}

int main ()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int sx,sy,dx,dy;
   cin>>n>>m>>sx>>sy>>dx>>dy;
   for(int i=1;i<=n;i++){
      for(int j=1;j<=m;j++){
         cin>>s[i][j];
         cost[i][j]=INT_MAX;
      }
   }
   priority_queue<pair<int,pi>>pq;
   cost[sx][sy]=0;
   pq.push({cost[sx][sy],{sx,sy}});
   while(!pq.empty()){
      auto tp=pq.top();pq.pop();
      int w=-tp.F,x=tp.S.F,y=tp.S.S;
      if(cost[x][y]<w) continue;
      for(int i=-2;i<=2;i++){
         for(int j=-2;j<=2;j++){
            int nx=x+i,ny=y+j;
            if(valid(nx,ny)&&s[nx][ny]=='.'){
               if((i==0&&j==1)||(i==1&&j==0)||(i==-1&&j==0)||(i==0&&j==-1)) w=0;
               else w=1;
               if(cost[nx][ny]>cost[x][y]+w){
                  cost[nx][ny]=cost[x][y]+w;
                  pq.push({-cost[nx][ny],{nx,ny}});
               }
            }
         }
      }
   }
   cost[dx][dy]=(cost[dx][dy]==INT_MAX)?-1:cost[dx][dy];
   cout<<cost[dx][dy]<<endl;
   return 0;
}



Measured memory_bytes: 8596
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>

// 和の符号のパターンはpos,neg,...かneg,pos,...のどちらかなので両方探索して小さいほうをとる

long long mysign(long long n){
	if (n>0)return 1;
	else if (n<0)return -1;
	return 0;
}

long long myabs(long long n){
	return (n>0)?n:(-n);
}

long long calc(long long *a,int n, long long cost, long long tgt_sgn)
{
	int i;
	long long sum = 0;
	long long bias = 0;
	for (i=0;i<n;i++){
		sum += a[i];
		long long sum_eval = sum + bias;
		if (tgt_sgn != mysign(sum_eval)){
			bias += tgt_sgn - sum_eval;
			cost += myabs(tgt_sgn - sum_eval);
		}
		tgt_sgn *= -1;
	}
	return cost;
}

int main(void)
{
	int n;
	scanf("%d\n",&n);
	long long a[n];
	int i;
	for (i=0;i<n;i++){
		scanf("%lld ",&a[i]);
	}
	long long ret;
	long long r0,r1;
	r0 = calc(a,n,0, 1);
	r1 = calc(a,n,0,-1);
	if (r0 < r1)ret = r0;
	else ret = r1;
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 896
// ProblemURL : https://atcoder.jp/contests/abc051/tasks/abc051_c
// ---------------------------------------------
package main

import (
	"fmt"
	"strings"
)

func main() {
	var sx, sy, tx, ty int
	fmt.Scan(&sx, &sy, &tx, &ty)

	diffX := tx - sx
	diffY := ty - sy
	ans := ""

	ans += strings.Repeat("R", diffX)
	ans += strings.Repeat("U", diffY)
	ans += strings.Repeat("L", diffX)
	ans += strings.Repeat("D", diffY)
	ans += "D"
	ans += strings.Repeat("R", diffX+1)
	ans += strings.Repeat("U", diffY+1)
	ans += "L"
	ans += "U"
	ans += strings.Repeat("L", diffX+1)
	ans += strings.Repeat("D", diffY+1)
	ans += "R"

	fmt.Println(ans)
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] a = new int[n];
        int sum = 0;
        for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(sc.next());
            sum += a[i];
        }
        
        int count = 0;
        for(int i = 0; i < n; i++){
            if(4*a[i]*m >= sum) count++;
        }
        
        if(count >= m){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23116
// Created by code_sm
//
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp> 
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> pseudo_set;
#define ll long long
#define vi vector<int>
#define si set<int> 
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define chotu 1000000007
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) s.size()
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
void solve()
{
fastio
	int n,k;
	cin>>n>>k;
	ll p[n];
for(auto &x:p)
	cin>>x;
sort(p,p+n);
int sum=0;
for(int i=0;i<k;i++)
sum+=p[i];
cout<<sum;
}
int main()
{
//code
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
fastio	
int t;
t=1;
while(t--)
{
	solve();
	cout<<endl;
}
}


Measured memory_bytes: 3616
/** 
 * THIS IS MOOONI'S CODE !
 * HACK IT IF YOU CAN !
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  if ((int) s.size() % 2 == 1) {
    cout << "No" << '\n';
    return 0;
  }
  for (int i = 1; i < (int) s.size(); i += 2) {
    if (s[i] != 'i' || s[i - 1] != 'h') {
      cout << "No" << '\n';
      return 0;
    }
  }
  cout << "Yes" << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;

int main(int argc, char *argv[]){
    long long x,k,d,a;
    cin >> x >> k >> d;
    if(x<0) x*=-1;
    if(x/d>=k){
        for(int i=0;i<k;i++){
            x-=d;
        }
        cout << x << endl;
        return 0;
    }
    a=x/d;
    if((k-a)%2==0){
        for(int i=0;i<a;i++){
            x-=d;
        }
    }else{
        for(int i=0;i<a+1;i++){
            x-=d;
        }
        x*=-1;
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    vector<int> p(n);
    for(int i = 0; i < n; i++) cin >> p[i];
    sort(p.begin(), p.end());
    int ans = 0;
    for(int i = 0;i <k ;i++){
        ans += p[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3512
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
string s[10005];
int main() 
{
	int n;
    cin>>n;
    int flag=0;
    while (n!=0)
    {
        int m=n%10;
        if (m==7)
        {
            flag=1;
            break;
        }
        n=n/10;
    }
    if (flag)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 3868
from collections import defaultdict

max_ = 55555
primes = defaultdict(list)
is_prime = [True]*(max_+1)

for i in range(2,max_+1):
    if is_prime[i]:
        primes[i%5].append(i)
        for j in range(max_//i+1):
            is_prime[j*i] = False
#for key, value in primes.items():
#    print(key, len(value))

n = int(input())
print(" ".join(map(str, primes[1][:n])))

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

using namespace std;

void __print(int x) { cerr << x; }

void __print(long x) { cerr << x; }

void __print(long long x) { cerr << x; }

void __print(unsigned x) { cerr << x; }

void __print(unsigned long x) { cerr << x; }

void __print(unsigned long long x) { cerr << x; }

void __print(float x) { cerr << x; }

void __print(double x) { cerr << x; }

void __print(long double x) { cerr << x; }

void __print(char x) { cerr << '\'' << x << '\''; }

void __print(const char *x) { cerr << '\"' << x << '\"'; }

void __print(const string &x) { cerr << '\"' << x << '\"'; }

void __print(bool x) { cerr << (x ? "true" : "false"); }

template<typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}

template<typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i: x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}

void _print() { cerr << "]\n"; }

template<typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define int long long
#define INF 1e18
#define MOD 1e9+7
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

#define PI 3.14159265359

inline void solve() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int t = 60 * c + d;
    double h = (t / 2.0);
    double m = (6.0 * t);
    h = h - (int) (h / 360) * 360;
    double angle = max(h, m) - min(m, h);
    double ans = sqrt(a * a * 1.0 + b * b * 1.0 - 2.0 * a * b * cos((angle * PI) / 180.0));
    printf("%.10lf", ans);
}

signed main() {
    IOS
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 4220
#include <iostream>
#include <cstdlib>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  stack<int> h_pos;
  stack<pair<int, int> > each_pond;
  char ch;
  int pos = 0;
  int A = 0;
  int depth = 0;
  while (cin >> ch) {
    pos++;
    if (ch == '\\') {
      h_pos.push(pos);
    } else if (ch == '/' && h_pos.size() > 0)  {
      int eq_pos = h_pos.top();
      h_pos.pop();
      int area = pos - eq_pos;
      A += area;
      while(each_pond.size() > 0 && each_pond.top().first > eq_pos) {
        area += each_pond.top().second;
        each_pond.pop();
      }
      each_pond.push(make_pair(eq_pos, area));
    }
  }
  ///print
  cout << A << endl;
  cout << each_pond.size();
  vector<int> each_pond_vec;
  while(!each_pond.empty()) {
    each_pond_vec.push_back(each_pond.top().second);
    each_pond.pop();
  }
  reverse(each_pond_vec.begin(), each_pond_vec.end());
  for (int i = 0; i < each_pond_vec.size(); i++) {
    cout << " " << each_pond_vec[i];
  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 3212
n,a,b,c = map(int,input().split())
l = [int(input()) for _ in range(n)]
INF = 10**9

def dfs(cur, a_tmp, b_tmp, c_tmp):
    if cur == n:
        return abs(a_tmp-a)+abs(b_tmp-b)+abs(c_tmp-c)-30 if min(a_tmp,b_tmp,c_tmp) > 0 else INF
    ret0 = dfs(cur+1, a_tmp, b_tmp, c_tmp)
    ret1 = dfs(cur+1, a_tmp+l[cur], b_tmp, c_tmp)+10
    ret2 = dfs(cur+1, a_tmp, b_tmp+l[cur], c_tmp)+10
    ret3 = dfs(cur+1, a_tmp, b_tmp, c_tmp+l[cur])+10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0,0,0,0))

Measured memory_bytes: 3064
#include <iostream>
         
        using namespace std;
         
        int main()
        {
        long long N, cur_p = 1;
        cin >> N;
        for (long long i = 1; i <= N; i++)
        {
         cur_p = cur_p * i % 1000000007;
         
        }
         
        cout << cur_p;
         
        return 0;
        }

Measured memory_bytes: 256
#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;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

int main(){
    string s; cin >> s;
    int cnt1 = 0, cnt2 = 0;
    rep(i, s.size()){
        if(i % 2 == 1 && s[i] != '1') cnt1++;
        if(i % 2 == 0 && s[i] != '0') cnt1++;
    }
    rep(i, s.size()){
        if(i % 2 == 1 && s[i] != '0') cnt2++;
        if(i % 2 == 0 && s[i] != '1') cnt2++;
    }
    cout << min(cnt1, cnt2) << endl;
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
int main(){
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	
	if((x+r)<=W && (y+r)<=H && (x-r)>=0 && (y-r)>=0){
		printf("Yes\n");
	}else{
		printf("No\n");
	}

	
	
	return 0;
} 


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

namespace ABC073A
{
    class Program
    {
        static void Main(string[] args)
        {
            int N;
            String a;
            N = int.Parse(Console.ReadLine());
            if(N%10==9||N/10==9|| N % 10 == 9 && N / 10 == 9)
            { a = "Yes"; }
            else { a = "No"; }
            Console.WriteLine(a);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 13140
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
bool pt(double px,double py,double qx,double qy,double rx,double ry,double sx,double sy){
  if(((rx-qx)*(py-qy)-(px-qx)*(ry-qy)<=0&&(sx-rx)*(py-ry)-(px-rx)*(sy-ry)<=0&&(qx-sx)*(py-sy)-(px-sx)*(qy-sy)<=0)||
     ((rx-qx)*(py-qy)-(px-qx)*(ry-qy)>=0&&(sx-rx)*(py-ry)-(px-rx)*(sy-ry)>=0&&(qx-sx)*(py-sy)-(px-sx)*(qy-sy)>=0))
    return 1;
  return 0;
}
int main(){
  double px,py,qx,qy,rx,ry,sx,sy;
  while(cin>>qx>>qy>>rx>>ry>>sx>>sy>>px>>py){
    if(pt(px,py,qx,qy,rx,ry,sx,sy))
      cout<<"YES"<<endl;
    else
      cout<<"NO"<<endl;
  }
  return 0;
}

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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int n; cin >> n;
    vector<ll> a(n);
    ll ans = 0;
    int micnt=0;
    bool minu=true;
    rep(i,0,n){
        cin >> a[i];
        ans += abs(a[i]);
        if(a[i]==0) minu=false;
        if(a[i]<0){ micnt++; a[i] *= -1; }
    }
    if(micnt%2==0) minu=false;
    if(minu == false){ cout << ans << endl; return 0;}
    sort(all(a));
    cout << ans -a[0] * 2 << endl; 


}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main(void){
    int N,M;
    cin>>N>>M;
    vector<tuple<ll,ll>> X(N);
    for(int i=0;i<N;i++){
        ll a,b;
        cin >> a>>b;
        X[i]=make_tuple(a,b);
    }
    sort(X.begin(),X.end());
    ll ans=0;
    ll tmp=0;
    for(int i=0;i<N;i++){
        if (tmp+get<1>(X[i])>M){
            ans+=(M-tmp)*get<0>(X[i]);
            break;
        }
        ans+=get<0>(X[i])*get<1>(X[i]);
        tmp+=get<1>(X[i]);
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int main(){
  int n,res = 0;
  bool flag = true;
  queue<int> que;
  cin >> n;
  for(int i = 0;i < n;i++){
    int a;cin >> a;
    que.push(a);
  }
  for(int i = 1;i <= n && !que.empty();i++){
    while(que.front() != i && !que.empty()){
      que.pop();
      res++;
    }
    if(i == 1 && que.empty())flag = false;
    if(!que.empty())que.pop();
  }
  if(!flag)cout << -1;
  else cout << res;
  return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define forin(i,array) for(auto& x:array)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mod 1000000007
#define inf 2000000009


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;

int ans,n;

void func(ll x,int counter){
    if(x>n)return;
    if(counter==7)ans++;
    func(x*10+3,counter|4);
    func(x*10+5,counter|2);
    func(x*10+7,counter|1);
}

int h[103][103];
int limit[103][103];

int main(){
    int n;
    cin>>n;
    rep(i,101)rep(j,101)h[i][j]=-1;
    rep(j,101)rep(k,101)limit[j][k]=inf;
    rep(i,n){
        int x,y,z;
        cin>>x>>y>>z;
        if(z==0){
            rep(j,101)rep(k,101){
                limit[j][k]=min(limit[j][k],abs(j-x)+abs(k-y));
            }
        }
        else{
            rep(j,101)rep(k,101){
                int height=z+abs(j-x)+abs(k-y);
                if(h[j][k]==-1)h[j][k]=height;
                else if(h[j][k]==-2)continue;
                else if(h[j][k]!=height)h[j][k]=-2;
            }
        }
    }
    rep(j,101)rep(k,101){
        if(h[j][k]>=1 && h[j][k]<=limit[j][k])cout<<j<<" "<<k<<" "<<h[j][k]<<endl;
    }
    
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>

using namespace std;

#define ll long long
#define db double
#define clr(a, b) memset(a, b, sizeof(a))

const int maxn = 2e3 + 10;
const int inf = 0x7ffffff;

int ans[maxn];
void solve()
{
    int N, x, y;
    cin >> N >> x >> y;
    for (int i = 1; i <= N;i++)
    {
        for (int j = i + 1; j <= N;j++)
        {
            /*
            if(i>=y)
               ans[j - i]++;
            else if(x<=i && j>=y)
                ans[min(j - y + 1 + i - x, j - i)]++;
            else if(x>=i && j>=y)
                ans[j - y + 1 + x - i]++;
            else if(i<=x && j>=x)
                ans[min(j - i, x - i + y - j + 1)]++;
            else
                ans[j - i]++;*/
            if(i>=x)
            {
                if(i>=y)
                    ans[j - i]++;
                else if(j>=y)
                    ans[min(j - y + 1 + i - x, j - i)]++;
                else if(j<=y)
                    ans[min(j - i, y - j + 1 + i - x)]++;
            }
            else if(x<=j)
            {
                if(j>=y)
                    ans[j - y + 1 + x - i]++;
                else if(y>=j)
                {
                    ans[min(j - i, x - i + y - j + 1)]++;
                }
            }
            else
                ans[j - i]++;

        }
    }
    for (int i = 1; i <= N-1;i++)
        cout << ans[i] << "\n";
}

int main()
{
    //freopen("out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T = 1;
    //cin >> T;
    while(T-- > 0)
        solve();

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
int dp[100000][3];

int main(){
  int n;cin>>n;
  int f[100000][3];
  REP(i,n) cin>>f[i][0]>>f[i][1]>>f[i][2];
  REP(i,n) REP(j,3) dp[i][j]=(i?max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]):0)+f[i][j];
  cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
}

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

using namespace std;

long b[1111];
int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		b[i + 1] = b[i] + a;
	}
	vector<long> v;
	for (int i = 0; i < n; i++) {
		for (int j = i; j < n; j++)
			v.push_back(b[j + 1] - b[i]);
	}
	auto it = v.begin();
	sort(it, v.end());
	long l = 0;
	for (int i = 50; i--;) {
		auto j = lower_bound(it, v.end(), l | 1l << i);
		if (v.end() - j >= k) {
			it = j;
			l |= 1l << i;
			continue;
		}
		for (; j != v.end(); ++j)
			*j ^= 1l << i;
		sort(it, v.end());
	}
	cout << l << endl;
	return 0;
}


Measured memory_bytes: 6128
import sys


def floor_sum(n, m, a, b):
    ans = n*(b//m)
    b %= m
    while True:
        ans += (n-1)*n*(a//m)//2
        a %= m
        if a*n+b < m:
            return ans
        y_max = (a*n + b)//m
        b -= y_max*m  # now we have x_max = -(b//a)
        ans += (n + b//a)*y_max
        n = y_max
        b %= a
        m, a = a, m


input = sys.stdin.buffer.readline
t = int(input())
for _ in range(t):
    n, m, a, b = map(int, input().split())
    print(floor_sum(n, m, a, b))


Measured memory_bytes: 9264
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定
#include <list> //前後に数値を入れれる配列



#define REP(i,m,n) for(int i = (int) (m);i < (int) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = 3.141592653589793; //円周率

//常設関数↓

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

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

//degree → radian
ll chg_DegRad(int deg) {
	return deg * PI / 180.0;
}

//radian → degree
ll chg_RadDeg(int rad) {
	return rad * 180.0 / PI;
}

//提出コード↓

ll n, k,ans;
ll a[100100];
ll ret;

int main() {

	cin >> n >> k;
	rep(i, n) cin >> a[i];
	if ((n - 1) % (k - 1) == 0) ans = (n - 1) / (k - 1);
	else ans = (n - 1) / (k - 1) + 1;
	cout << ans << endl;
	


	




	return 0;
}



Measured memory_bytes: 1024
#include <stdio.h>
#define N 50
int n,A[N];
int so(int,int);
int main(){
  int q,i,m;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&m);
    if(so(0,m))printf("yes\n");
    else printf("no\n");
    
}
  return 0;
  
}
int so(int i,int m){
  if(m==0)return 1;
  if(i>=n)return 0;
  int p =so(i+1,m)||so(i+1,m-A[i]);
  return p;
}



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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

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

    int n, r; std::cin >> n >> r;
    std::cout << (n < 10 ? r + 100*(10-n) : r) << "\n";
}


Measured memory_bytes: 256
using System;
using System.Numerics;

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            var _ = Console.ReadLine().Split();
            var a = BigInteger.Parse(_[0]);
            var b = BigInteger.Parse(_[1]);
            var c = BigInteger.Parse(_[2]);
            var d = BigInteger.Parse(_[3]);

            var cc = (b / c) - ((a - 1) / c);
            var dd = (b / d) - ((a - 1) / d);

            var e = Lcm(c, d);
            var ee = (b / e) - ((a - 1) / e);

            Console.WriteLine(b - a - cc - dd + ee + 1);
        }

        static BigInteger Lcm(BigInteger m, BigInteger n){
        	return (m * n) / Gcd(m, n);
        }

        static BigInteger Gcd(BigInteger m, BigInteger n)
        {
	        while (m % n != 0){
        		var temp = n;
		        n = m % n;
		        m = temp;
	        }
        	return n;
        }
    }
}


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

int i,root,depth[200005]={0},mmax=0;
vector<int> g[200005];
bool used[200005]={0};

void dfs(int v){
	used[v]=true;
	for(int j=0;j<g[v].size();j++){
		if(!used[g[v][j]]){
			depth[g[v][j]]=depth[v]+1;
			dfs(g[v][j]);
		}
	}
}
 
int main (void){
	int n,a,b;
	cin >> n;
	for(i=1;i<n;i++) {
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	depth[1]=0;
	dfs(1);
	mmax=-1;
	for(i=1;i<=n;i++){
		if(mmax<depth[i]){
			mmax=depth[i];
			root=i;
		}
	}
	for(i=1;i<=n;i++) {
		used[i]=false;
		depth[i]=0;
	}
	depth[root]=0;
	dfs(root);
	mmax=-1;
	for(i=1;i<=n;i++){
		if(mmax<depth[i]){
			mmax=depth[i];
			root=i;
		}
	}
	if(mmax%3==1) cout << "Second" << endl;
	else cout << "First" << endl;
	return 0;
}


Measured memory_bytes: 21504
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

vector<string> board(70);
string memo[70][70];
int W, H;

inline bool isDigit(int x, int y)
{
    if ('0' <= board[y][x] && board[y][x] <= '9')
        return true;
    else
        return false;
}

int main()
{
    while (cin >> W >> H, W || H) {
        // Input
        for (int i = 0; i < H; ++i) {
            cin >> board[i];
            for (int j = 0; j < W; ++j)
                memo[i][j] = board[i][j];
        }

        // Solve
        for (int y = H - 1; y >= 0; --y) {
            for (int x = W - 1; x >= 0; --x) {
                if (isDigit(x, y)) {
                    for (int d = 0; d < 2; ++d) {
                        int nx = x + dx[d];
                        int ny = y + dy[d];

                        if (nx < 0 || nx >= W || ny < 0 || ny >= H)
                            continue;
                        if (!isDigit(nx, ny))
                            continue;
                        string cmp = board[ny][nx] + memo[y][x];
                        if (cmp.size() > memo[ny][nx].size() ||
                            (cmp.size() == memo[ny][nx].size() && cmp > memo[ny][nx]))
                            memo[ny][nx] = cmp;
                    }
                }
            }
        }

        // Remove leading zero
        for (int y = 0; y < H; ++y)
            for (int x = 0; x < W; ++x) {
                int index = 0;
                while (memo[y][x][index] == '0')
                    index++;
                memo[y][x] = memo[y][x].substr(index);
            }

        string ans;
        for (int y = 0; y < H; ++y)
            for (int x = 0; x < W; ++x)
                if (isDigit(x, y) && ((memo[y][x].size() > ans.size()) ||
                                      (memo[y][x].size() == ans.size() && memo[y][x] > ans)))
                    ans = memo[y][x];
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1400
#include <stdio.h>

int main(void) {
  char s[100001];
  int N , Q;
  int l, r;
  int AC[100001] = {0}, count = 0;
  int i;

  scanf("%d %d", &N, &Q);
  scanf("%s", s);

  for(i = 0; s[i] != '\0'; ++i) {
    if(s[i] == 'A') {
      if(s[i + 1] == 'C') {
        ++count;
      }
    }
    AC[i] = count;
  }

  for(i = 0; i < Q; ++i) {
    scanf("%d %d", &l, &r);
    if(l == 1)  printf("%d\n", AC[r - 2]);
    else  printf("%d\n", AC[r - 2] - AC[l - 2]);
  }

  return 0;
}

Measured memory_bytes: 1280
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int maxc;
vector<int> ans;

void dfs(const vv<pair<int, int>>& graph, int v, int p, int cp) {
    int c = cp == 1 ? 2 : 1;
    for (auto&& u : graph[v]) {
        if (u.first == p) continue;
        ans[u.second] = c;
        dfs(graph, u.first, v, c);
        if (++c == cp) c++;
    }
}

int main() {
    int N;
    cin >> N;
    vv<pair<int, int>> graph(N);
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].emplace_back(b, i);
        graph[b].emplace_back(a, i);
    }

    maxc = 0;
    int root = -1;
    rep(i, N) {
        if (chmax(maxc, (int)graph[i].size())) root = i;
    }

    ans.resize(N - 1);
    dfs(graph, root, -1, -1);
    write(maxc);
    for (int c : ans) write(c);
}

Measured memory_bytes: 8320
#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 is(a, b) a == b
#define len(v) ll(v.size())

const ll INF = 1LL << 58;

class UnionFind {
public:
	vector<int> par;//親の番号
    vector<int> rank;//木の深さ
 
	UnionFind(int n){//全ての要素に対して自身が根となるように初期化, 木の深さは0になる
		rep(i,n){
            par.push_back(i);
            rank.push_back(0);
        }
	}
 
	int find(int x) {//木の根を求める
		if(par[x]==x){
            return x;
        }else{
            return par[x]=find(par[x]);
        }
	}
 
	void unite(int x,int y){//xとyの属する集合を併合
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(rank[x]<rank[y]){//木の深さが小さい方を大きい方へ繋げる
            par[x]=y;
        }else{
            par[y]=x;
            if(rank[x]==rank[y]) rank[x]++;
        }
    }

    bool same(int x,int y){//xとyが同じ集合に属するか否か
        return find(x)==find(y);
    }
};
//x以下の要素への最小index, ソートしてから使ってね
template <class T> 
int former(const vector<T> &v, T x){
  return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
//x以上の要素への最小index
template <class T> 
int latter(const vector<T> &v, T x){
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}
//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}
//nCk
template <class T>
T comb(T n,T k){
    T ans=1;
    FOR(i,n-k+1,n+1){
        ans*=i;
    }
    FOR(i,1,k+1){
        ans/=i;
    }
    return ans;
}
//a,bの最大公約数
template <class T>
T gcd(T a,T b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}
//素因数分解
template <class T>
map<T,T> prime_factor(T x){
    map<T,T> ans;
    for(T i=2;i*i<=x;i++){
        while(x%i==0){
            x/=i;
            ans[i]++;
        }
    }
    if (x!=1){
        ans[x]=1;
    }
    return ans;
}
//約数列挙
template <class T>
vector<T> divisor(T x){
    vector<T> res;
    for(T i=1;i*i<=x;i++){
        if(x%i==0){
            res.push_back(i);
            if(i!=x/i){
                res.push_back(x/i);
            }
        }
    }
    return res;
}
//素数判定
template <class T>
bool is_prime(T x){
    for(T i=2;i*i<=x;i++){
        if(x%i==0){
            return false;
        }
    }
    return x!=1;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<pair<int,int>> r;
    vector<pair<int,int>> b;
    rep(i,n){
        int x,y;
        cin>>x>>y;
        r.push_back(make_pair(y,x));
    }
    rep(i,n){
        int k,l;
        cin>>k>>l;
        b.push_back(make_pair(k,l));
    }
    int ans=0;
    sort(begin(b),end(b));//x座標が小さい順にソート
    sort(begin(r),end(r),greater<pair<int,int>>());
    int m=n;
    rep(i,n){
        rep(j,m){
            if(b[i].first-r[j].second>0 && b[i].second-r[j].first>0){
                r.erase(begin(r)+j);
                ans++;
                m--;
                break;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int D, G, p[11], c[11];
    cin >> D >> G;
    for(int i = 0; i < D; ++i){
        cin >> p[i] >> c[i];
    }

    int ans = 1e9;
    for(int mask = 0; mask < (1 << D); ++mask){
        int s = 0, num = 0, rest_max = -1;
        for(int i = 0; i < D; ++i){
            if(mask >> i & 1){
                s += 100 * (i+1) * p[i] + c[i];
                num += p[i];
            }else{
                rest_max = i;
            }
        }
        if(s < G){
            int s1 = 100 * (rest_max + 1);
            int need = (G - s + s1 - 1) / s1;
            if(need >= p[rest_max]){
                continue;
            }
            num += need;
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
}

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

typedef  long long ll;
//forループ
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//
//
#define int long long

using namespace std;

int ctoi(char c) {
 switch (c) {
 case '0': return 0;
 case '1': return 1;
 case '2': return 2;
 case '3': return 3;
 case '4': return 4;
 case '5': return 5;
 case '6': return 6;
 case '7': return 7;
 case '8': return 8;
 case '9': return 9;
 default: return 0;
 }
}


 ll a,b,c,s,t,x,y,z;
 ll A,B,C,S,T,X,Y,Z;

 ll count;

 long double pi=3.14159265358979323846;

 string N,M;

unsigned long long D;

signed main(){

	cin>>a>>b>>x>>y;

	for(;;){
		x-=b;
		if(x<=0){
	cout<<"Yes";
	break;
}
		a-=y;
		if(a<=0){
	cout<<"No";
	break;
}
	}

	return 0;

}


Measured memory_bytes: 3636
#include "bits/stdc++.h"

//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

//#define int long long
#define ll long long

ll INF = (1LL << 60);
int mod = 998244353;
using P = pair<ll, ll>;
double PI = 3.1415926535;
signed main() {
	int a, b; cin >> a >> b;
	cout << a * b << endl;
	return 0;
}



Measured memory_bytes: 3616
n = int(input())
xl = list(map(int, input().split()))
yl = list(map(int, input().split()))

d1, d2, d3, dinf = 0, 0, 0, 0
for i in range(n):
    d1 += abs(xl[i] - yl[i])
    d2 += (xl[i] - yl[i])**2
    d3 += (abs(xl[i] - yl[i]))**3
    dinf_ = abs(xl[i] - yl[i])
    if dinf_ > dinf:
        dinf = dinf_

print('{}\n{}\n{}\n{}'.format(d1, d2**(1/2), d3**(1/3), dinf))



Measured memory_bytes: 5648
#include <stdio.h>

int main() {

	int a, b;

	scanf("%d %d", &a, &b);

	if (a > b) {
		printf("a > b\n");
	}else if(a < b) {
		printf("a < b\n");
	}else {
		printf("a == b\n");
	}

	return 0;
}


Measured memory_bytes: 2104