akhauriyash/Code-Regression huggingface dataset:
use std::cmp;
use std::collections::*;
use std::io::{self, Read};

fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock());

    let h: usize = sc.read().unwrap();
    let w: usize = sc.read().unwrap();

    let mut b = Vec::with_capacity(h);
    for _ in 0..h {
        let mut bb = Vec::with_capacity(w);
        for _ in 0..w {
            let ayx: u8 = sc.read().unwrap();
            bb.push(ayx);
        }
        b.push(bb);
    }

    let mut m: Option<(usize, usize)> = None;
    let mut r = Vec::new();
    for i in 0..h {
        for jj in 0..w {
            let j = if i % 2 == 0 { jj } else { w - jj - 1 };
            // println!("{:?}", (j, i));

            if let &Some((pi, pj)) = &m {
                // 移動中
                r.push((pi, pj, i, j));
                if b[i][j] % 2 == 0 {
                    m = Some((i, j));
                } else {
                    m = None;
                }
            } else if b[i][j] % 2 == 1 {
                // 移動開始
                m = Some((i, j));
            }
        }
    }

    println!("{}", r.len());
    for (pi, pj, i, j) in r {
        println!("{} {} {} {}", pi + 1, pj + 1, i + 1, j + 1);
    }
}

struct Scanner<R: Read> {
    reader: R,
}

impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: std::str::FromStr>(&mut self) -> Option<T> {
        self.reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse()
            .ok()
    }

    fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Option<Vec<T>> {
        (0..n).map(|_| self.read()).collect()
    }

    fn read_vec2d<T: std::str::FromStr>(&mut self, m: usize, n: usize) -> Option<Vec<Vec<T>>> {
        (0..m).map(|_| self.read_vec(n)).collect()
    }

    fn read_board(&mut self, n: usize) -> Option<Vec<Vec<char>>> {
        (0..n)
            .map(|_| {
                self.read::<String>()
                    .map(|s| s.chars().collect::<Vec<char>>())
            })
            .collect()
    }
}


Measured memory_bytes: 12792
import sys
N,M=map(int,input().split())
ai=[0for i in range(N)]
bi=[0for i in range(N)]
ci=[0for i in range(M)]
di=[0for i in range(M)]
disti=[10**9 for i in range(N)]
checki=[0 for i in range(N)]

for i in range(N):
    ai[i],bi[i]=map(int,input().split())
for i in range(M):
    ci[i],di[i]=map(int,input().split())
    
for i in range(N):
    for j in range(M):
        dist=abs(ai[i]-ci[j])+abs(bi[i]-di[j])
        if(disti[i]>dist):
            disti[i]=dist
            checki[i]=j+1
            
for i in checki:
    print(i)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/





int N, M;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M;

    int time = 1900 * M + 100 * (N - M);
    int x = 1;
    rep(i, 0, M) x *= 2;

    int ans = time * x;
    cout << ans << endl;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

unsigned long long gcd(unsigned long long a, unsigned long long b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

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

int main()
{
  unsigned long long A, B, C, D;
  cin >> A >> B >> C >> D;
  unsigned long long x = lcm(C,D);
  unsigned long long ac,ad,ax;
  if(A%C==0){
    ac = A/C;
  }else{
    ac = A/C+1;
  }
  if(A%D==0){
    ad = A/D;
  }else{
    ad = A/D+1;
  }
  if(A%x==0){
    ax = A/x;
  }else{
    ax = A/x+1;
  }
  unsigned long long a = B/C-(ac)+1;
  unsigned long long b = B/D-(ad)+1;
  unsigned long long c = B/x-(ax)+1;
  cout << B-A+1-a-b+c << endl;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
    void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
    void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
cerr << #__VA_ARGS__ << ": ";             \
debug(__VA_ARGS__);                       \
cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
    void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
    void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
    void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int dp[5001][5001];

int main() {
  in(int, n);
  in(string, s);
  int ans = 0;
  for (int i = n - 1; i >= 0; --i) {
    for (int j = n - 1; j >= 0; --j) {
      if (s[i] == s[j]) {
        dp[i][j] = dp[i + 1][j + 1] + 1;
        ans = max(ans, min(abs(i - j), dp[i][j]));
      }
    }
  }
  out(ans);
}


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

template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u);
    }
    ModInt pow(long long e){
        long long a = 1, p = x;
        while(e > 0) {
            if (e & 1) {a = (a * p) % mod; e--;}
            else {p = (p * p) % mod; e /= 2;}
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

constexpr int MOD = 1000000007;

int main() {
	int n, k;
	cin >> n >> k;
	cout << ModInt<MOD>(k).pow(n) << '\n';
	return 0;
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) cout << (x) << endl;
#define sz(x) int(x.size())
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int dp[3100][3100] = {0};

int main(void){
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    string s,t;
    cin >> s >> t;
    rep(i,s.size()){
      rep(j,t.size()){
        if(s[i] == t[j]) chmax(dp[i+1][j+1], dp[i][j] + 1);
        chmax(dp[i+1][j+1], dp[i+1][j]);
        chmax(dp[i+1][j+1], dp[i][j+1]);
      }
    }

    string res = "";
    int i = sz(s), j = sz(t);
    while(i > 0 && j > 0){
      if(dp[i][j] == dp[i-1][j]){
        --i;
      }

      else if (dp[i][j] == dp[i][j-1]) {
          --j;
      }

      else{
        res = s[i-1] + res;
        --i, --j;
      }
    } 
    cout << res << endl;

}

Measured memory_bytes: 37120
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let n = nextInt()
    let h = nextIntArray()
    let prevMax = 0
    let ans = 0
    for(let i=0;i<h.length;i++){
        if(h[i] >= prevMax) ans++
        prevMax = Math.max(prevMax, h[i])
    }
    console.log(ans)
}
Main()


Measured memory_bytes: 29580
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String str[] = br.readLine().split(" ");

		int a = Integer.parseInt(str[0]);
		int b = Integer.parseInt(str[1]);
		int c = Integer.parseInt(str[2]);

		if (b / a > c)
			System.out.println(c);
		else
			System.out.println(b / a);
	}
}


Measured memory_bytes: 32700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))


int main(){
    int n;  cin >> n;
    vector<ll> a(4, 0);
    ll x, y, z, res=1;
    REP(i, n){
        int t, cnt=0, id=0;  cin >> t;
        if(t==a[1]){
            cnt += 1; id=1;
        } 
        if(t==a[2]){
            cnt += 1; id=2;
        } 
        if(t==a[3]){
            cnt += 1; id=3;
        } 
        if(id==0){
            cout <<  0 << endl;
            return 0;
        }
        a[id] += 1;
        res *= cnt;
        res %= MOD;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
vector<vector<int>> v(21);
ll dp[22][1<<21];
ll mod=1e9+7;
int n;
void dfs(int d, int mask){
    if(d==n){
        dp[n][mask]=1;
        return ;
    }
    ll s=0;
    for(auto x : v[d]){
        if( (mask&(1<<x)) ==0){
            if(dp[d+1][mask|(1<<x)]==-1) dfs(d+1,mask|(1<<x));
            s=(s+dp[d+1][mask|(1<<x)])%mod;
        }
    }
    dp[d][mask]=s;
}
int main() {/*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif*/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            int a; cin>>a; 
            if(a==1) v[i].push_back(j);
        }
    }
    for(int i=0;i<22;i++){
        for(int j=0;j<(1<<21);j++){
            dp[i][j]=-1;
        }
    }
    dfs(0,0);
    cout<<dp[0][0];
}

Measured memory_bytes: 360832
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
#define inf 1000000000
using namespace std;

const int maxn = 210000;

int n,m;
int A[maxn],B[maxn],C[maxn];

struct node{int x,i;};
inline bool operator <(const node x,const node y){return x.x<y.x;}
set<node>S;
set<node>::iterator it;

int p[maxn],q[maxn];
struct L{int l,i;};
vector<L>vl[maxn];
inline bool operator <(const L x,const L y){return x.l>y.l;}
priority_queue<L>q1;
struct R{int r,i;};
vector<R>vr[maxn];
inline bool operator <(const R x,const R y){return x.r<y.r;}
priority_queue<R>q2;

bool use[maxn],flag;
int ans[maxn],re;

int solve(const int k,const int ad){ return ans[k]==-1?-1:n-ans[k]+ad; }

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d",&A[i],&B[i]);
	for(int i=0;i<=n;i++) scanf("%d",&C[i]); sort(C,C+n+1);
	for(int i=0;i<=n;i++) if(!i||C[i]!=C[i-1]) S.insert((node){C[i],i});
	S.insert((node){inf+1,n+1});
	
	for(int i=1;i<=n;i++)
	{
		it=S.lower_bound((node){A[i],0});
		A[i]=(*it).i; p[A[i]]++;
		it=S.lower_bound((node){B[i],0});
		B[i]=(*it).i;
		
		if(A[i]>B[i])
		{
			swap(A[i],B[i]); B[i]--;
			vl[B[i]].push_back((L){A[i],i});
			vr[A[i]].push_back((R){B[i],i});
		}
	}
	for(int i=0;i<=n;i++) p[i]--;
	for(int i=1;i<=n+1;i++) p[i]+=p[i-1];
	
	int ad=0;
	for(int i=n+1;i>=0;i--)
	{
		ad+=q[i]; p[i]+=ad; q[i]=0;
		for(int j=0;j<vl[i].size();j++) q1.push(vl[i][j]);
		
		if(p[i]<-1&&i!=n+1)
		{
			while(!q1.empty()&&p[i]<-1)
			{
				const L now=q1.top(); q1.pop();
				if(now.l>i) break;
				use[now.i]=true;
				p[i]++; ad++; if(now.l) q[now.l-1]--;
				if(B[now.i]>i) q[i+1]++,q[B[now.i]+1]--;
				re++;
			}
			if(p[i]<-1) { flag=true; break; }
		}
	}
	if(flag) for(int i=0;i<=n+1;i++) ans[i]=-1;
	else
	{
		ad=0;
		for(int i=0;i<=n;i++) ad+=q[i],q[i]=0,p[i]+=ad;
		ad=0;
		for(int i=0;i<=n;i++)
		{
			ans[i]=re;
			ad+=q[i]; p[i]+=ad;
			for(int j=0;j<vr[i].size();j++) if(!use[vr[i][j].i]) q2.push(vr[i][j]);
			
			if(p[i]<0)
			{
				while(!q2.empty()&&p[i]<0)
				{
					const R now=q2.top(); q2.pop();
					if(now.r<i) break;
					ad++; p[i]++; q[now.r+1]--;
					re++;
				}
				if(p[i]<0)
				{
					for(int j=i+1;j<=n+1;j++) ans[j]=-1;
					break;
				}
			}
		}
		if(ans[n+1]!=-1) ans[n+1]=re;
	}
	
	scanf("%d",&m);
	while(m--)
	{
		int x,y; scanf("%d%d",&x,&y);
		it=S.lower_bound((node){x,0}); x=(*it).i;
		it=S.lower_bound((node){y,0}); y=(*it).i;
		printf("%d\n",max(solve(x,1),solve(y,0)));
	}
	
	return 0;
}


Measured memory_bytes: 26612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(j, m) for (int j = 0; j < (int)(m); j++)
#define rep2(i, l, n) for (int i = l; i < (int)(n); i++)


int main() {
    int A,B;
    cin >> A >> B;
    int P;
    if (B/10 == 0) {
        P = 10;
    }
    else if (B == 100) {
        P = 1000;
    }
    else {
        P = 100;
    }
    int N = P*A + B;
    int i = 1;
    int flag = 0;
    while (i*i <= N) {
        if (i*i == N) {
            cout << "Yes" << endl;
            flag++;
        }
        i++;
    }
    if (flag == 0) {
        cout << "No" << endl;
    }
}



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

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

using namespace std;

typedef long long ll;
vector<char> op[2];

class Parsing{
private:
  string parse;
  int pos;
public:
 
  Parsing(string s){
    parse = s;
    pos = 0;
  }

  void reset(){ pos = 0; }

  ll eval(ll a,ll b,char o){ return (o=='+')?a+b:a*b; }

  int fact(){
    ll p=0;
    while('0' <= parse[pos] && parse[pos] <= '9'){
      p *= 10LL;
      p += (ll)( parse[pos]-'0' );
      pos++;
    }
    return p;
  }
 
 ll term(){
    ll p = fact();
    while( 1 ){
      int index = -1;
      rep(i,op[0].size()) if( op[0][i] == parse[pos] ) { index = i; break; }
      if( index == -1 ) break;
      ++pos;
      ll q = fact();
      p = eval(p,q,op[0][index]);
    }
    return p;
  }
 
 ll expression(){
   ll p = term();
    while( 1 ){
      int index = -1;
      rep(i,op[1].size()) if( op[1][i] == parse[pos] ) { index = i; break; }
      if( index == -1 ) break;

      ++pos;
      ll q = term();
      p = eval(p,q,op[1][index]);

    }
    return p;
  } 
 
};


int main(int argc,char* argv[]){
  string s;
  getline(cin,s);
  ll bob;
  cin >> bob;
  Parsing parser(s);
  op[0].push_back('*');
  op[1].push_back('+');
  ll result1 = parser.expression();
  parser.reset();
  rep(i,2) op[i].clear();
  op[0].push_back('+');
  op[0].push_back('*');
  ll result2 = parser.expression();
  bool flag1 = ( bob == result1 );
  bool flag2 = ( bob == result2 );
  if( flag1 && !flag2 ) puts("M");
  else if( !flag1 && flag2 ) puts("L");
  else if( flag1 && flag2 ) puts("U");
  else puts("I");
  return 0;
}

Measured memory_bytes: 1216
#include <cstdio>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>

using namespace std;

#define rep(i,a,n) for(int (i)=a;(i)<(int)(n);(i)++)
#define rrep(i,a,n) for(int (i)=(n)-1;(i)>=a;(i)--)
#define all(x) (x).begin(),(x).end()

typedef long long ll;

const int INF = 1e9;

int main() {
    int n;
	while (scanf("%d", &n) != EOF) {
		vector<int> list;
		int x = 512;
		while (n > 0) {
			if (n >= x) {
				list.push_back(x);
				n -= x;
			}
			x >>= 1;
		}
		reverse(all(list));
		for (int i = 0; i < list.size(); i++) {
			if (i > 0) cout << " ";
			cout << list[i];
		}
		cout << endl;
	}
}

Measured memory_bytes: 3132
#include<stdio.h>
#include<string>
#include<stack>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
	int x1,x2,y1,y2;
	scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
	int x3 = x2 - (y2-y1);
	int y3 = y2 + (x2-x1);
	int x4 = x1 - (y2-y1);
	int y4 = y1 + (x2-x1);
	printf("%d %d %d %d\n",x3,y3,x4,y4);
	return 0;
}


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

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void solve(long long N) {
    cout << (1000 - N % 1000) % 1000 << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


Measured memory_bytes: 3744
#include<bits/stdc++.h>
#include<iostream>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<int,ll>Pil;
typedef pair<int,Pil>Piil;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	int x,y,sx,sy,cost;
};

int main() {

	while(1){
		int n,x;
		cin>>n>>x;
		if(n==0&&x==0)return 0;
		int t=0;
		for(int i=1; i<n-1; i++){
			for(int j=i+1; j<n; j++){
				for(int k=j+1; k<n+1; k++){
					if(i+j+k==x){
						t++;
					}
				}
			}
		}
		cout<<t<<endl;
	}


	return 0;
}



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

int t=0;

int main()
{
	string s,s2;
  	cin>>s>>s2;
  
  	for (int i=0;i<s.size();++i){
     	if (s[i]==s2[i])
          	continue;
     	else
          	t++;
    }
  	cout<<t<<endl;
}

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

int main()
{
	char s[5] = {};
    std::cin >> s;
    
    int n = 0;
    for(int i = 0;i < 4;i++){
    	if(s[i] == '+'){
        	n++;
        }
        else{
        	n--;
        }
    }
    
    std::cout << n;
}

Measured memory_bytes: 256
{-# LANGUAGE OverloadedStrings #-}
import Data.IORef
import Control.Monad
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as BC

data Deque a = BD !Int [a] !Int [a]
  deriving Show

check :: Int -> [a] -> Int -> [a] -> Deque a
check lf f lr r
  | lf > 3*lr + 1, i <- div (lf + lr) 2, (f',f'') <- splitAt i f = BD i f' (lf + lr - i) (r ++ reverse f'')
  | lr > 3*lf + 1, j <- div (lf + lr) 2, (r',r'') <- splitAt j r = BD (lf + lr - j) (f ++ reverse r'') j r'
  | otherwise = BD lf f lr r
{-# INLINE check #-}

cons :: a -> Deque a -> Deque a
cons x (BD i xs j ys) = check (i + 1) (x : xs) j ys

snoc :: Deque a -> a -> Deque a
snoc (BD i xs j ys) x = check i xs (j + 1) (x : ys)

reverseQueue :: Deque a -> Deque a
reverseQueue (BD i xs j ys) = BD j ys i xs

toList :: Deque a -> [a]
toList (BD _ xs _ ys) = xs ++ reverse ys

main = do
    refStr <- B.getLine >>= newIORef . B.foldl' snoc (BD 0 [] 0 [])
    count <- readLn
    replicateM_ count $ do
        input <- BC.words <$> B.getLine
        case input of
            "1" : _ -> modifyIORef' refStr reverseQueue
            "2" : end : chr : _ -> 
                if end == "1"
                    then modifyIORef' refStr (cons (B.head chr))
                    else modifyIORef' refStr (`snoc` (B.head chr))
    readIORef refStr >>= B.putStrLn . B.pack . toList

Measured memory_bytes: 48508
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int N=110;
char ss[N];
int main()
{
    scanf("%s",ss+1);
    int n=strlen(ss+1);
    int f=1;
    for(int i=1;i<=n/2;i++)
    {
        if(ss[i]!=ss[n-i+1])
        {
            f=0;
            break;
        }
    }
    int m=(n-1)/2;
    for(int i=1;i<=m/2;i++)
    {
        if(ss[i]!=ss[m-i+1])
        {
            f=0;
            break;
        }
    }
    m=(n+3)/2;
    for(int i=m;i<=(n-m+1)/2;i++)
    {
        if(ss[i]!=ss[n-i+m])
        {
            f=0;
            break;
        }
    }
    if(f==0)
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
import math
import queue
import bisect
import heapq
import time

mod = 1e9+7

def swap(a,b):
    return (b,a)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def main():
    a,b = map(int,input().split())
    g = gcd(a,b)
    g_l = divisors(g)
    ans = 1
    for i in g_l:
        if is_prime(i):
            ans += 1
    print(ans)
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 39788
import java.util.*;

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

    int N = sc.nextInt();
    int M = sc.nextInt();
    int Q = sc.nextInt();

    int[][] n_matrix = new int[N+1][N+1];

    for (int i = 0; i < M; i++) {
      n_matrix[sc.nextInt()][sc.nextInt()]++;
    }

    for (int i = N-1; i > 0; i--) {
      for (int j = 1; j <= N; j++) {
        n_matrix[i][j] += n_matrix[i+1][j] + n_matrix[i][j-1] - n_matrix[i+1][j-1];
      }
    }

    int[] answers = new int[Q];

    for (int i = 0; i < Q; i++) {
      int ans = n_matrix[sc.nextInt()][sc.nextInt()];
      answers[i] = ans;
    }

    for (int i = 0; i < Q; i++) {
      System.out.println(answers[i]);
    }
  }
}


Measured memory_bytes: 153632
input_list = list(map(int, input().split()))
count = input_list[0]
y = input_list[1]
flag = False
for l in range(count + 1):
    for m in range(count - l + 1):
        n = count - l - m
        if 10000 * l + 5000 * m + 1000 * n == y:
            print(l, m, n)
            flag = True
            break
        if flag:
            break
    if flag:
        break
if flag == False:
    print(-1, -1, -1)

Measured memory_bytes: 40684
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main (){
    ll k,n;cin>>n>>k;
    vector<ll> V(n);
    for(int i=0;i<n;i++){
            cin>>V[i];
    }
    sort(V.rbegin(),V.rend());
    ll sum=accumulate(V.begin(),V.end(),0LL);
    for(int i=0;i<min(k,n);i++){
            sum-=V[i];
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define SUM(v) accumulate(v.begin(),v.end(),lli(0))
#define rev(n,d) for(int i=n;i>=d;i--)
#define FOR0(n) for(int i=0;i<n;i++)
#define FOR(a,n) for(int i=a;i<n;i++)
#define FORQ(a,n) for(int i=a;i<=n;i++)
#define inf 1000000009
#define inff 0x3f3f3f3f
#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define mem(ar,x) memset(ar,x,sizeof ar)
#define present(container, element) (container.find(element) != container.end())
#define max3(a,b,c) return (lli(a)>lli(b)?(lli(a)>lli(c)?a:c):(lli(b)>lli(c)?b:c))
#define max4(a,b,c,d) return (max3(a,b,c)>lli(d)?(max3(a,b,c)):d)
#define min3(a,b,c) return (lli(a)<lli(b)?(lli(a)<lli(c)?a:c):(lli(b)<lli(c)?b:c))
#define min4(a,b,c,d) return (max3(a,b,c)<lli(d)?(max3(a,b,c)):d)
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<int,pii>ppii;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<pii>vpii;
const int N=100005;
int dr8[]={0,0,1,-1,1,1,-1,-1};
int dc8[]={1,-1,0,0,-1,1,-1,1};
int dr4[]={0,1,-1,0};
int dc4[]={1,0,0,-1};
lli get(lli n);
int main(){
	fast
	int l,r,d;
	cin>>l>>r>>d;
	int an=0;
	FORQ(l,r) if(i%d==0) an++;
	cout<<an;
}



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

int main(){
    int n,m;
    cin >> n >> m;
    int l=1, r=1e5;
    while(m--){
        int x,y;
        cin>>x>>y;
        l = max(l,x);
        r = min(r,y);
    }
    cout << max(0, r-l+1) << endl;
}


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

int main() {
  long double x,n=100;
  cin >> x;
  for(long i=1;true;i++) {
    n*=1.01;
    n=floor(n);
    if(n>=x) cout << i << endl;
    if(n>=x) break;
  }
}

Measured memory_bytes: 3728
from collections import Counter
N = int(input())
D = list(map(int, input().split()))
MOD = 998244353

# 厳密にはmax(D)+1の長さがあれば正常系は通るが、余分に取っておく
count = [0] * N
for d in D:
    count[d] += 1

def calc():
    if D[0] != 0:
        return 0
    ret = 1
    for i in range(N):
        if i == 0:
            if count[i] >= 2:
                return 0
        else:
            ret *= (count[i-1] ** count[i]) % MOD
            ret %= MOD
    return ret

print(calc())


Measured memory_bytes: 14780
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rept(i,s,n) for (int i = (s); i < (n); ++i)

#include <iostream>
#include <cmath>
#include <bitset>
#include <algorithm>
using namespace std;

int main() {

  int n;
  cin >> n;

  cout << "ABC" << n << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
int ret=0;
int x[30];
int y[30];
int r[30];
int c[30];
int used;
set<int>dp;
int n;
int now;
void solve(){
	if(dp.count(used))return;
	dp.insert(used);
	ret=max(ret,now);
	int can[30];
	for(int i=0;i<n;i++)can[i]=0;
	for(int i=0;i<n;i++){
		if(used&(1<<i))continue;
		can[i]=1;
		for(int j=i+1;j<n;j++){
			if(!(used&(1<<j))&&(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])<(r[i]+r[j])*(r[i]+r[j]))can[i]=0;
		}
	}
	for(int i=0;i<n;i++)for(int j=i+1;j<n;j++){
		if(can[i]&&can[j]&&c[i]==c[j]){
			now+=2;
			used+=(1<<i)+(1<<j);
	//		used[i]=used[j]=1;
			solve();
			used-=(1<<i)+(1<<j);
	//		used[i]=used[j]=0;
			now-=2;
		}
	}
}
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=a-1;i>=0;i--)scanf("%d%d%d%d",x+i,y+i,r+i,c+i);
		ret=0;n=a;
	//	used=vector<int>(a);
		used=0;
		dp.clear();
		now=0;
		solve();
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 50108
<?php
	fscanf(STDIN,'%d%d',$n,$m);
	for($i=0;$i<$n;$i++){
		$L=explode(' ',fgets(STDIN));
		for($j=1;$j<=$L[0];$j++){
			$c[0+$L[$j]]++;
		}
	}
	for($i=1;$i<=$m;$i++){
		$a+=$c[$i]==$n;
	}
	echo $a;

Measured memory_bytes: 3828
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <cmath>
#include <climits>
#include <cstdint>
using namespace std;

inline namespace atcoder {
    template <typename T, size_t Depth>
    struct vector_helper { using type = vector<typename vector_helper<T, Depth - 1>::type>; };
    template <typename T>
    struct vector_helper<T, 0> { using type = T; };
    template <typename T, size_t Depth>
    using vector_t = typename vector_helper<T, Depth>::type;

    template <typename T> using vec = vector_t<T, 1>;
    template <typename T> using vvec = vector_t<T, 2>;
    template <typename T> using vvvec = vector_t<T, 3>;
}

int main() {
    int n; cin >> n;
    int cp = n;
    int sum = 0;
    while (n) {
        sum += n % 10;
        n /= 10;
    }
    cout << (cp % sum ? "No" : "Yes") << endl;
}



Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    ll n, m;
    cin>>n>>m;
    ll temp[2];
    ll min = INT_MAX;
    ll max = INT_MIN;
    while(m--){
        cin>>temp[0]>>temp[1];
        if(temp[0] > max){
            max = temp[0];
        }
        if(temp[1] < min) {
            min = temp[1];
        }
    }
    if(max > min){
        cout<<0<<endl;
    } else {
      cout << min - max + 1 << endl;
    }
}



Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int main(){
	int n, t;
	cin >> n >> t;
	int ans = 10000;
	REP(i, n) {
		int a, b;
		cin >> a >> b;
		if (b <= t) {
			ans = min(ans, a);
		}
	}
	if (ans == 10000) {
		cout << "TLE" << endl;
		return 0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_set>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


int main() {
	ll h, a;
	cin >> h >> a;
	cout << (h + a - 1) / a << endl;
}


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

using namespace std;

vector<int> R(13);
vector<vector<int> > A(13, vector<int>(13));
vector<int> H(13, 0);
int main()
{
    int N,M,X;
    cin>>N>>M>>X;
    bool tr;
    for(int i=0; i<N; i++)
      {
        cin>>R[i];
        for(int j=0; j<M; j++)
            {
                cin>>A[i][j];
            }
      }
     int ans1=INT_MAX;
     int ans;
    for(int i=1; i<(1<<N); i++)
    {
        ans=0;
        tr=true;
        for(int u=0; u<H.size(); u++)
            H[u]=0;
        for(int j=0; j<N; j++)
        {
            if((i & (1<<j)) != 0)
            {
                ans+=R[j];
                for(int k=0; k<M; k++)
                {
                    H[k]=H[k]+A[j][k];
                }
            }
        }
        for(int i=0; i<M; i++)
            if(H[i]<X)
            {
                tr=false;
                break;
            }
        if(tr==true)
        ans1=min(ans, ans1);

    }
    if(ans1==INT_MAX)
        cout<<-1<<'\n';
    else cout<<ans1<<'\n';
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n, k;
	cin >> n >> k;
	n -= n / k * k;
	cout << min(n, k - n);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
	ll s;
	cin>>s;
	
	const int v=1000000000;
	
	int x=(v-s%v)%v;
	int y=(s+x)/v;
	
	cout<<"0 0 1000000000 1 "<<x<<" "<<y<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef long double     ld;
typedef string          str;
#define all(x)			(x).begin(),(x).end()
#define Sort(x)			sort(all(x))
#define A               first
#define B               second
#define sep             ' '
#define endl            '\n'
#define fast_io         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int MAX1 = 5e5 + 7;

ll a, b, c, T, d, e, l, r, x, y, z, mid, cnt, flag, mod = 1e9+7;
vector <ll> vec;

bool prime(ll n){
	for (int i = 2; i <= sqrt(n); ++i){
		if (n%i == 0)	return false;
	}
	return true;
}

int main(){
	cin >> a >> b;
	for (int i = 1; i < sqrt(a); ++i){
		if (a%i == 0){
			if (prime(i))	vec.push_back(i);
			if (prime(a/i))	vec.push_back(a/i);
		}
	}
	if (sqrt(a) == int(sqrt(a)) && prime(int(sqrt(a))))	vec.push_back(int(sqrt(a)));
	for (int i = 0; i < vec.size(); ++i){
		// cout << i << endl;
		if (b%vec[i] == 0)	++cnt;
	}
	cout << cnt;
    return 0;
}
/*                          now or never                         */


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

int main() {
  ll a, b, x;
  cin >> a >> b >> x;
 
  ll ans = b/x + 1;
  if (a > 0) ans -= (a-1)/x + 1;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vi vector<int>
#define vivi vector<vi>
const int INF = 1<<29;
typedef long long ll;

int dp[100][2][100];//dp[keta][未満である][0でない数の個数]

struct UnionFind {
  vi parent;
  UnionFind(int N) : parent(N) {
    rep(i, N)parent[i] = i;
  }

  int getRoot(int child){
    return ((parent[child] == child) ? child : parent[child] = getRoot(parent[child]));
  }
  void unite(int x, int y){
    int root_x = getRoot(x);
    int root_y = getRoot(y);
    if(root_x == root_y)return;
    parent[root_x] = parent[root_y];
  }
  bool isSame(int x, int y){
    return getRoot(x) == getRoot(y);
  }
};

int main(){
    string S, T;cin >> S >> T;
    string ans;
    int ansi = -1;
    bool okFlg;
    for(int i = 0;i < S.size() - T.size() + 1;++i){
        okFlg = true;
        for(int j = 0;j < T.size();++j){
            if(S[i + j] == '?')continue;
            if(S[i + j] != T[j])okFlg = false;
        }
        if(okFlg)ansi = i;
    }
    for(int i = 0;i < S.size();++i){
        if(S[i] == '?')S[i] = 'a';
    }
    if(ansi != -1)
        for(int i = 0;i < T.size();++i){
            S[i + ansi] = T[i];
        }
    cout << ((ansi != -1) ? S : "UNRESTORABLE");
}


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

using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ll long long
#define li long int

#define pb push_back
#define m <i> map<int>
#define v <i> vector<int>

const int MX = 1e6;
const int MOD = 1e9 + 7;
const string ALPHA = "abcdefghijklmnopqrstuvwxyz";
const double PI = 3.1415926535;

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

int main()
{
  IOS;
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans=(ll)n/(a+b)*a;
  ll r=n%(a+b);
  ans+=min(r,a);
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3648
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		foreach(var k in K){
			long ans = 0;
			long ms = 0;
			long cs = 0;
			long mcs = 0;
			int l = 0;
			int r = 0;
			for(r = 0;r < k;r++){
				if(S[r] == 'M'){
					ms++;
				}
				if(S[r] == 'C'){
					mcs += ms;
					cs++;
				}
			}
//Console.WriteLine("ms:{0} mcs:{1} cs:{2}",ms, mcs, cs);			
			for(l=0;l<N;l++){
				if(S[l] == 'D'){
					ans += mcs;
				}
				
				if(S[l] == 'M'){
					mcs -= cs;
					ms--;
				}
				if(S[l] == 'C'){
					cs--;
				}
				
				if(r < N){
					if(S[r] == 'M'){
						ms++;
					}
					if(S[r] == 'C'){
						mcs += ms;
						cs++;
					}
					r++;
				}
//Console.WriteLine("ms:{0} mcs:{1} cs:{2}",ms, mcs, cs);			
			}
			
			Console.WriteLine(ans);
		}
		
	}
	int N;
	String S;
	int Q;
	int[] K;
	public Sol(){
		N = ri();
		S = rs();
		Q = ri();
		K = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}



class BIT{
	int MM;
	int n;
	long[] bit;
	public BIT(int n_){
		n = n_;
		MM = 1 << 2;
		while(MM < n * 2) MM <<= 1;
		bit = new long[MM + 1];
	}
	//1-origin!!
	public void Add(int i, long x){
		while(i <= n){
			bit[i] += x;
			i += (i&-i);
		}
	}
	
	// i=>sum(a_1,...,a_i)
	// i=0 -> return 0;
	public long Sum(int i){
		long s = 0;
		while(i > 0){
			s += bit[i];
			i -= (i&-i);
		}
		return s;
	}
}




Measured memory_bytes: 14816
#include <stdio.h>
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>

using namespace std;

int main(){
	int N;
	cin >> N;
	int t = 0;
	int x = 0;
	int y = 0;
	int flag = 1;
	for(int i = 0; i < N; i++){
		int nextt, nextx, nexty;
		cin >> nextt >> nextx >> nexty;
		int dist = abs(x-nextx) + abs(y-nexty);
		if(nextt-t < dist){
			flag = 0;
			break;
		}
		if(dist%2 != (nextt-t)%2){
			flag = 0;
			break;
		}
		t = nextt;
		x = nextx;
		y = nexty;
	}
	if(flag == 1){
		cout << "Yes\n";
	}
	else{
		cout << "No\n";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cout << #x << " = " << x << '\n'
#define debug_arr(a , n) for(int i = 0 ; i < n ; i++)cout << a[i] << " "
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<ll> 
#define inf 1000000000
#define mod 1000000007

ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 0 ; i < n ; i++)
    {
        cin >> a[i];
    }
    for(int i = 0 ; i < n ; i++)
    {
        if(a[i]%2 == 0)
        {
            if((a[i]%3) && (a[i]%5))
            {
                cout << "DENIED\n";
                return 0;
            }
        }
    }
    cout << "APPROVED\n";
    return 0;
}

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

int main()
{
    int n, x, count;
    while(1)
    {
        count = 0;
        cin >> n >> x;
        if(n == 0 && x == 0) break;
        for(int i=1;i<=n-2;i++)
        {
            for(int j=i+1;j<=n-1;j++)
            {
                for(int k=j+1;k<=n;k++){
                    if(i + j + k == x) count++;
                }
            }
        }
        cout << count << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int q = sc.nextInt();
    String s = sc.next();
    int count = 0;
    int[] a = new int[n];
    int[] ans = new int[q];
    for(int i = 1;i < n;i++){
      if(s.charAt(i-1) == 'A' && s.charAt(i) == 'C'){
        count++;
        a[i] = count;
      }
      else{
        a[i] = count;
      }
    }
    for(int i = 0;i < q;i++){
      int l = sc.nextInt();
      int r = sc.nextInt();
      ans[i] = a[r-1] - a[l-1];
    }
    for(int i = 0;i < q;i++){
      System.out.println(ans[i]);
    }
  }
}


Measured memory_bytes: 73780
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)

	board := strings.Split(s, "")
	var groupCount int
	lastCell := ""
	for _, cell := range board {
		if cell == lastCell {
			continue
		}
		groupCount++
		lastCell = cell
	}
		fmt.Println(groupCount-1)
}



Measured memory_bytes: 4196
#include<stdio.h>
#include<iostream>
#include<cmath>

using namespace std;

int main(void) {

	int n, a, b, k, sum,wa,l,tmp;
	sum = 0;

	cin >> n >> a >> b;

	for (k = 1; k <= n; k++) {
		wa = 0;
		tmp = k;
		while(1) {
			wa += (tmp % 10);
			tmp = tmp / 10;
			if (tmp == 0)break;
		}
		if (wa >= a && wa <= b) {
			sum += k;

			//printf("n=%d,wa=%d,sum=%d\n", k, wa, sum);
		}
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    cin>>s>>t;

    for(int i=0;i<s.size();i++){
        if(s[i]!=t[i]){
            cout<<"No\n";
            return 0;
        }    
    }
    cout<<"Yes\n";
    
    return 0;
}

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

using namespace std;

int p[1000010];
vector<int> v;

int main() {
    
    for (int i = 2; i * i < 1000000; ++i) 
        for (int j = i + i; j < 1000000; j += i)
            p[j] = 1;

    for (int i = 2; i < 1000000; ++i)
        if(!p[i]) v.push_back(i);

    int x;
    cin >> x;
    
    int pos = lower_bound(v.begin(), v.end(), x) - v.begin();
    cout << v[pos] << "\n";
    return 0;
}


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

int main() {
  int64_t n, m, a, r, c, h;
  m = a = r = c = h = 0;
  int64_t ans = 0;
  cin >> n;
  string tmp;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    if (tmp[0] == 'M') ++m;
    if (tmp[0] == 'A') ++a;
    if (tmp[0] == 'R') ++r;
    if (tmp[0] == 'C') ++c;
    if (tmp[0] == 'H') ++h;
  }
  ans += m*a*r;
  ans += m*a*c;
  ans += m*a*h;
  ans += m*r*c;
  ans += m*r*h;
  ans += m*c*h;
  ans += a*r*c;
  ans += a*r*h;
  ans += a*c*h;
  ans += r*c*h;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 888