akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int t1,t2,r1,r2;
    cin >> t1 >> t2 >> r1 >> r2;
    if(r1 == -1 || r2 == -1){
        if(t1 < t2){
            cout << "Alice" << endl;
        }else if(t1 > t2){
            cout << "Bob" << endl;
        }else{
            cout << "Draw" << endl;
        }
    }else{
        if(r1 < r2){
            cout << "Bob" << endl;
        }else if(r1 > r2){
            cout << "Alice" << endl;
        }else{
            cout << "Draw" << endl;
        }
    }
}



Measured memory_bytes: 3120
#include <stdio.h>
#define N 20
int main(){
  int i,n=0;
  double dx[N],dy[N];
  double x,y,sum=0;
  while (scanf("%lf,%lf",&dx[n],&dy[n])!=EOF)
    n++;
  dx[n]=dx[0];
  dy[n]=dy[0];
  for (i=0;i<n;i++)
    sum+=(dx[i]-dx[i+1])*(dy[i]+dy[i+1]);
  printf("%f\n",sum/2);
  return 0;
}

Measured memory_bytes: 652
S = input()

L = []
for i in range(len(S)):
    if(S[i] in 'ACGT'):
        count = 1
        L.append(1)
        for j in range(i + 1, len(S)):
            if (S[j] in 'ACGT'):
                count += 1
            else:
                L.append(count)
                break
            if (j + 1 == len(S)):
                L.append(count)
                break
    else:
        continue

if (len(L) == 0):
    print('0')
else:
    print(max(L))


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    
    long long ans = 0;
    // for(int i = 0; i < N; ++i){
    //     cout << i+1 << " ";
    // }
    // cout << "\n";
    // for(int i = 0; i < N; ++i){
    //     if(i == N-1){
    //         cout << 1;
    //     }else{
    //         cout << i+2 << " ";
    //     }
    // }
    // cout << "\n";
    for(int i = 1; i < N; ++i){
        ans += i;
        // ans += i%(i+1);
        // cout << i%(i+1) << " ";
    }
    // cout << 0 << endl;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
  ll N,K; cin>>N>>K;
  vector<P> A(N);
  for(int i=0;i<N;i++){
    int a,b; cin>>a>>b;
    A[i].first = a;
    A[i].second = b;
  }
  sort(A.begin(),A.end());
  ll cnt = 0;
  int ans = 0;
  for(int i=0;i<N;i++){
    cnt += A[i].second;
    if(cnt >= K){
      ans = A[i].first;
      break;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Bit
{
    int n;
    vector<int> data;
public:
    Bit(){
    }
    Bit(int n){ // コンストラクタ
        this->n = n;
        data.assign(n+1, 0);
    }
    void add(int k, int x){ // k番目の要素にxを加算する
        ++ k;
        while(k <= n){
            data[k] += x;
            k += k & -k;
        }
    }
    int sum(int k){ // 区間[0,k]の総和を返す
        ++ k;
        int ret = 0;
        while(k > 0){
            ret += data[k];
            k -= k & -k;
        }
        return ret;
    }
    int sum(int a, int b){ // 区間[a,b]の総和を返す
        return sum(b) - sum(a-1);
    }
    int upper_bound(int x){ // 総和が初めてxを超える位置を返す（ただし、各位置の数値が非負数であることを前提とする）
        int b = 1;
        while(b < n)
            b *= 2;
        int a = 0;
        while(b > 0){
            if(a+b <= n && x >= data[a+b]){
                x -= data[a+b];
                a += b;
            }
            b /= 2;
        }
        return (a < n)? a : -1;
    }
    int lower_bound(int x){ // 総和が初めてx以上になる位置を返す（ただし、各位置の数値が非負数であることを前提とする）
        return upper_bound(x-1);
    }
};

int lim;
vector<int> n;
map<int, int> m;
Bit b;

void eraseNode(int t)
{
    m.erase(n[t]);
    b.add(t, -1);
    ++ lim;
}

void addNode(int x, int t)
{
    n[t] = x;
    m[x] = t;
    b.add(t, 1);
    -- lim;
    if(lim < 0)
        eraseNode(b.lower_bound(1));
}

int main()
{
    for(;;){
        int q;
        cin >> q >> lim;
        if(q == 0)
            return 0;

        n.assign(q, -1);
        m.clear();
        b = Bit(q);

        for(int t=0; t<q; ++t){
            int query, x;
            cin >> query >> x;
            if(query == 0){
                addNode(x, t);
            }else if(query == 1){
                int y = b.lower_bound(x);
                eraseNode(y);
            }else if(query == 2){
                int y = b.lower_bound(x);
                cout << n[y] << endl;
            }else{
                eraseNode(m[x]);
            }
        }

        cout << "end" << endl;
    }
}

Measured memory_bytes: 6088
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

signed main(){
      
  int a, b; cin >> a >> b;
  int c = a + b;
  if(c % 2 == 1) cout << "IMPOSSIBLE" << endl;
  else cout << c / 2 << endl;
    
  return 0;
}


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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);



void dfs(ll i, int d, vector<ll> &A) {
    A.push_back(i);
    if (d==10) {
        return;
    }
    else {
        int tmp = i%10;
        for (int j = max(tmp-1,0); j<=min(9,tmp+1); j++) {
            dfs(i*10+j,d+1,A);
        }
    }
}

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

    vector<ll> A; 
    rep(i,9) {
        dfs(i+1,1,A);
    }
    sort(A.begin(),A.end());
    cout << A[N-1] << endl;
}

Measured memory_bytes: 5324
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    string s;
    cin >> s;
    int a = 0, z = 0;
    REP(i, s.size()) {
        if (s[i] == 'A') {
            a = i;
            break;
        }
    }
    RREP(i, s.size()) {
        if (s[i] == 'Z') {
            z = i;
            break;
        }
    }
    cout << z - a + 1 << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <memory>
#include <string>
#include <vector>

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

using namespace std;

int main() {
    string x;
    cin >> x;
    for (auto ch : x) {
        if (ch == '7') {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}



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

# define fr first
# define sc second
# define pb push_back
# define ll long long
# define mk make_pair
# define sz(s) (int)s.size()
# define all(s) s.begin(), s.end()

using namespace std;

const int N = 2e5+10;
const int inf = 1e9+7;

int n, a[N], b[N], c[N];
ll x[N], y[N], z[N];

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)scanf("%d", &a[i]);
    for(int i = 1; i <= n; i++)scanf("%d", &b[i]);
    for(int i = 1; i <= n; i++)scanf("%d", &c[i]);
    sort(a + 1, a + n + 1);
    sort(b + 1, b + n + 1);
    sort(c + 1, c + n + 1);
    z[n] = 1;
    for(int i = n; i > 1; i--)
        z[i - 1] = z[i] + 1;
    for(int i = n; i >= 1; i--) {
        int j = upper_bound(c + 1, c + n + 1, b[i]) - c;
        y[i] = z[j];
        if(i < n) y[i] += y[i + 1];
    }
    for(int i = n; i >= 1; i--) {
        int j = upper_bound(b + 1, b + n + 1, a[i]) - b;
        x[i] = y[j];
        if(i < n) x[i] += x[i + 1];
    }
    cout << x[1] << endl;
}


Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const long long INF = 1LL << 60;
const double PI = 3.14159265358979323846;
typedef long long ll;

int main(void) {
  int n;
  cin >> n;
  int a, b, c, dpA[100001], dpB[100001], dpC[100001];
  cin >> a >> b >> c;
  dpA[0] = a;
  dpB[0] = b;
  dpC[0] = c;
  for (int i = 1; i < n; i++) {
    cin >> a >> b >> c;
    dpA[i] = max(dpB[i - 1], dpC[i - 1]) + a;
    dpB[i] = max(dpC[i - 1], dpA[i - 1]) + b;
    dpC[i] = max(dpA[i - 1], dpB[i - 1]) + c;
  }
  int ans = max(max(dpA[n - 1], dpB[n - 1]), dpC[n - 1]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int main(){
	int n, t;
	scanf("%d", &t); 
	int ans = 0;
	n = t;
	while(n){
		ans += n%10;
		n /= 10;
	}
	if(t % ans == 0)
		printf("Yes\n");
	else
		printf("No\n");
return 0;
} 

Measured memory_bytes: 256
A,B,C = map(int,input().split())
K = int(input())
cb = 0
cc =0
while B<=A:
  B=B*2
  cb =cb +1
  
while C<=B:
  C = C*2
  cc = cc+1
if cb+cc > K:
  print('No')
else:
  print('Yes')

Measured memory_bytes: 9048
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<int> > Graph;
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; }

// Sieve of Eratosthenes
struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};
ll n;
bool solve(ll y){
    ll temp = n;
    while(temp%y==0){
        temp/=y;
    }
    temp%=y;
    if(temp==1){
        return true;
    }
    return false;
}
vector<ll> f(ll n){
    vector<ll> factor;
    for(ll i=1;i*i<=n;i++){
        if(n%i!=0)continue;
        factor.push_back(i);
        if(i*i!=n)factor.push_back(n/i);
    }
    return factor;
}

int main(){
    cin >> n;
    Sieve si(1e6);
    vector<ll> fo;
    fo=f(n-1);
    vector<ll> po;
    po=f(n);
    ll ans = fo.size();
    ans--;
    rep(i,po.size()){
        if(po[i]==1)continue;
        if(solve(po[i]))ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7752
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<numeric>
#include<iomanip>
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define ll long long
const double pi = 3.141592653589793;

using namespace std;

//最大公約数
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);
}

//階乗
ll fact(ll a) {
	int ans = 1;
	for (int i = 1; i <= a; i++) {
		ans *= i;
	}
	return ans;
}

//コンビネーション
ll combi(ll a, ll b) {
	return fact(a) / (fact(b) * fact(a - b));
}

int main() {
	int x, n;
	cin >> x >> n;
	vector<int>p(n);
	rep(i, n)cin >> p[i];

	vector<int>np(100 + 10);
	rep(i, np.size())np[i] = i;
	rep(i, p.size())np[p[i]] = 100000;

	int MIN = 100000;
	int ans = 0;
	rep(i, np.size()) {
		int temp = abs(np[i] - x);
		if (temp < MIN) {
			MIN = temp;
			ans = i;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;

int main() {
  int n;
  cin >> n;
  ll total = 0;
  vector<int> t(n);
  rep(i, n) {
    cin >> t[i];
    total += t[i];
  }

  int m;
  cin >> m;
  vector<int> p(m);
  vector<int> x(m);
  rep(i, m) cin >> p[i] >> x[i];
  rep(i, m) { cout << total - (t[p[i] - 1] - x[i]) << endl; }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
*/#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")    
using namespace std;
/*namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;
*/#define lli long long int
#define uli unsigned long long int
#define INF 9999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(50) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 10000010
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  long long A,B,C,D,E,F,N,K,M,Z,sum=0,num=0,flag=0;string S,T;
  cin >> A >> B >> C >> K;
  rep(i,0,8)rep(j,0,8)rep(k,0,8){
    if(i+j+k>K)continue;
    if((A<<i)<(B<<j)&&(B<<j)<(C<<k))flag=1;
  }
  if(flag)Out("Yes");
  else Out("No");
}

Measured memory_bytes: 3604
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      n: usize,
      k: usize,
      a: [usize; n]
   }
   let mut high = 1e9 as usize;
   let mut low = 0;
   while high - low != 1 {
      let mid = (high + low) / 2;
      let x: usize = a.iter().map(|&a| (a - 1) / mid).sum();
      if x <= k {
         high = mid;
      } else {
         low = mid;
      }
   }
   println!("{}", high);
}


Measured memory_bytes: 5340
A = int(input())
B = int(input())

if (A==1 and B ==2) or (A==2 and B==1):
    print('3')

elif (A==1 and B==3) or (A==3 and B==1):
    print('2')

elif (A==2 and B==3) or (A==3 and B==2):
    print('1')

Measured memory_bytes: 9088
n, m = map(int, input().split())
A = [[0 for i in range(m)] for j in range(n)]
b = [0 for i in range(m)]
c = [0 for i in range(n)]

i = 0
while i < n:
    l = list(map(int, input().split()))
    A[i] = l
    i += 1

i = 0
while i < m:
    l = int(input())
    b[i] = l
    i += 1

i = 0
j = 0
while i < n:
    while j < m:
        c[i] += A[i][j] * b[j]
        j += 1
    i += 1
    j = 0

for i in c:
    print(i)

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

using namespace std;

typedef long long lol;
const int N = 5e5 + 5;
int _w; 

int n;
lol A[N] , B[N] , C[N];

bool crs( int a , int b , int c ) {
  return ( b - a ) * ( A[c] - A[a] ) >= ( c - a ) * ( A[b] - A[a] );
}

int main( void ) {
  _w = scanf("%d",&n);
  for( int i = 1 ; i <= n ; ++i ) _w = scanf("%lld",A+i) , A[n + i] = A[i];
  for( int i = 1 ; i <= n ; ++i ) _w = scanf("%lld",B+i) , B[n + i] = B[i];
  lol mx = -1;
  for( int i = 1 ; i <= n ; ++i ) mx = max( mx , A[i] );
  for( int i = 1 , cur ; i <= n ; ++i ) if( A[i] == mx ) {
    cur = 0;
    for( int j = i ; j <= n ; ++j ) A[cur] = A[n + j] , B[cur] = B[n + j] , ++cur;
    for( int j = 1 ; j < i ; ++j ) A[cur] = A[n + j] , B[cur] = B[n + j] , ++cur;
    A[cur] = mx , B[cur] = B[n + i];
    break;
  }
  for( int i = 2 ; i <= n ; ++i ) {
    C[i] = (C[i - 1] + B[i - 1]) * 2 - C[i - 2];
    A[i] -= C[i];
  }
  static int S[N] , tp;
  tp = 0;
  for( int i = 0 ; i <= n ; ++i ) {
    while( tp > 1 && crs( S[tp - 1] , S[tp] , i ) ) --tp;
    S[++tp] = i;
  }
  long long ans = 0 , x;
  for( int i = 2 ; i <= tp ; ++i ) {
    x = S[i] - S[i - 1];
    ans += A[S[i - 1]] * ( x + 1 ) + A[S[i]] * ( x - 1 );
  }
  for( int i = 2 ; i < n ; ++i ) 
    ans += 2 * C[i];
  printf("%.12lf",double(ans)/(2.0*n));
  return 0;
}


Measured memory_bytes: 12264
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    String n = sc.next();
    long sum = 0;
    for (int i = 0; i < n.length(); i++) {
      sum += Integer.parseInt(n.substring(i, i + 1));
    }
    pw.println(sum % 9 == 0 ? "Yes" : "No");
  }
}


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

const int N = 100000;

int n, m;
long long ans;
char s[N + 5], t[N + 5];

int main() {

    scanf("%d%d%s%s", &n, &m, s, t);
    ans = 1ll * n * m / std::__gcd(n, m);

    for(int i = 0; i < n; ++i) if(1ll * i * m % n == 0) {
        int j = 1ll * i * m / n;

        if(s[i] != t[j]) {
            puts("-1");
            return 0;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
long long a[1000100],b[1000100];
int main()
{
	int n;scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%lld",&a[i]);
	long long l=2,r=2;
	for (int i=n;i>=1;i--)
	{
		if ((l/a[i]==r/a[i])&&(l%a[i]))
		{
			printf("-1\n");
			return 0;
		}
		if (l%a[i]) l=(l/a[i]+1)*a[i];
		if (r%a[i]) r=r/a[i]*a[i];
		r=r+a[i]-1;
	}
	cout<<l<<' '<<r<<endl;
}

Measured memory_bytes: 4352
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
    int n, m, i, j, tmp;
    int[] a, b;
    for(;;){
      n = sc.nextInt(); m = sc.nextInt();
      if(n == 0 && m == 0)break;
      a = new int[m]; b = new int[m];
      for(i = 0;i < m;i++)b[i] = i + 1;
      for(i = 0;i < n;i++)for(j = 0;j < m;j++)a[j] += sc.nextInt();
      for(i = 0;i < m - 1;i++)for(j = 0;j < m - 1 - i;j++)if(a[j] < a[j + 1]){
        tmp = a[j]; a[j] = a[j + 1]; a[j + 1] = tmp;
        tmp = b[j]; b[j] = b[j + 1]; b[j + 1] = tmp;
      }
      for(i = 0;i < m - 1;i++)out.print(b[i] + " ");
      out.println(b[i]);
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 69692
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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 input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<P> d(n);
    rep(i,n) cin>>d[i].first>>d[i].second;
    rep(i,n-2) {
        if (d[i].first == d[i].second && d[i+1].first == d[i+1].second && d[i+2].first == d[i+2].second) {
            cout << "Yes" << '\n';
            return 0;
        }
    }

    cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 3608
#!/usr/bin/env python3

import collections


def solve(k, ps):
    ctr = collections.Counter(p[0] for p in ps)
    ans = 0
    while len(ctr) >= k:
        mc = (char for char, _ in ctr.most_common(k))
        ctr.subtract(mc)
        ans += 1
        ctr = collections.Counter(dict(
                                  item for item in ctr.items() if item[1]))
    return ans


def main():
    n, k = map(int, input().split())
    ps = [input() for _ in range(n)]
    print(solve(k, ps))


if __name__ == '__main__':
    main()


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

long long n,num;
long long a[50];

inline void dfs(long long now,long long dep)
{
	if(dep==n+1){
		if((now&1)==0)num++;
		return;
	}
	dfs(now*(a[dep]),dep+1);
	dfs(now*(a[dep]-1),dep+1);
	dfs(now*(a[dep]+1),dep+1);
}

int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	dfs(1,1);
	cout<<num<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
atoz = [chr(i) for i in range(97,97+26)]

S = input()

if len(S) < 26:
    for a in atoz:
        if not a in S:
            print(S+a)
            break
else:
    right = S[-1]
    for i in reversed(range(len(S))):
        s = S[i]
        if s < right:
            for j in range(ord(s),ord(s)+26):
                if chr(j) in S[i+1:]:
                    print(S[:i]+chr(j))
                    break
            sys.exit()
        else:
            right = max(s,right)
    print(-1)


Measured memory_bytes: 4200
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
using namespace std;
int main(){
    int N,K;
    cin >> N >> K;
    
    if(K==1){
        cout << 0 << endl;
    }else{
    cout << N-K << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL               long long
#define PB               push_back
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<LL> cnt(N + 1);
  for (int i = 1; i < sqrt(N); i++) {
    for (int j = 1; j < sqrt(N); j++) {
      for (int k = 1; k < sqrt(N); k++) {
        int v = i * i + j * j + k * k + i * j + j * k + k * i;
        if (v <= N) cnt[v]++;
      }
    }
  }
  for (int i = 1; i <= N; i++) cout << cnt[i] << endl;
  return 0;
}

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

struct Mat{
	  int r,l;
};

int main(){

	  int n; cin >> n;
	  vector<Mat> Mats(n);
	  for(int i=0; i<n; i++)
			cin >> Mats[i].r >> Mats[i].l;

	  int dp[n][n] = {};
	  for(int i=0; i<n; i++)
			for(int j=0; j<n; j++)
				  if(i==j) dp[i][j] = 0;
				  else dp[i][j] = INT_MAX;

	  for(int k=1; k<n; k++){
			for(int i=0; i+k<n; i++){
				  for(int j=i; j<i+k; j++){
						int num_prod = Mats[i].r * Mats[j+1].r * Mats[i+k].l;
						dp[i][i+k] = min(dp[i][i+k], dp[i][j] + dp[j+1][i+k] + num_prod);
				  }
			}
	  }
	  
	  cout << dp[0][n-1] << endl;
	  
			
}

Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n,m;
    cin>>n>>m;
    vector<int> c;
    vector<int> d(200001,0);
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        if(a==1)c.push_back(b);
        if(b==n)d[a]++;
    }
    bool flag=false;
    for(int i=0;i<c.size();i++){
            if(d[c[i]])flag=true;
    }
    if(flag)cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}


Measured memory_bytes: 1660
using LIB;
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        while (true)
        {
            int[] n = io.r<int>(' ');
            if (n[0] == n[1] && n[0] == 0) { break; }
            for (int i = 0; i < n[0]; i++)
            {
                for (int j = 0; j < n[1]; j++)
                {
                    if (i == 0 || i == n[0] - 1 || j == 0 || j == n[1] - 1)
                    {
                        io.w("#", false);
                    }
                    else
                    {
                        io.w(".", false);
                    }
                }
                io.w("");
            }
            io.w("");
        }
        io.wflush();
    }
}

namespace LIB
{
    public class io
    {
        private const int WMAX = 1000;
        private static StringBuilder S = new StringBuilder();
        public static T r<T>() { return util.parse<T>(r()); }
        public static T[] r<T>(char s = ' ') { return r().Split(s).Select(util.parse<T>).ToArray(); }
        public static T[] r<T>(int l) { T[] r = new T[l]; for (int i = 0; i < l; i++) { r[i] = r<T>(); } return r; }
        public static T[][] r<T>(int l, char s = ' ') { T[][] r = new T[l][]; for (int i = 0; i < l; i++) { r[i] = r<T>(s); } return r; }
        private static string r() { return Console.ReadLine(); }
        public static void w(object v, bool lf = true) { S.Append(util.parse<string>(v)); if (lf == true) { S.Append('\n'); } if (S.Length >= WMAX) { wflush(); } }
        public static void wflush() { Console.Write(S.ToString()); S.Length = 0; }
    }
    public class util
    {
        public static T parse<T>(object value) { return (T)(Convert.ChangeType(value, typeof(T))); }
    }
    public class memo<Key, Result>
    {
        private Dictionary<Key, Result> R;
        public memo() { R = new Dictionary<Key, Result>(); }
        public Result exec(Key k, Func<Key, Result> f) { Result r; if (R.ContainsKey(k)) { r = R[k]; } else { r = f(k); R.Add(k, r); } return r; }
    }
}

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

int main(){
    int x[5];
    int i;

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

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


Measured memory_bytes: 3572
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		String N = sc.next();
		long t = 0L;
		for (int i = 0; i < N.length(); i++) {
			t += Long.parseLong(N.substring(i, i + 1));
		}
		System.out.println((t % 9 == 0) ? "Yes" : "No");
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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

Measured memory_bytes: 44092
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    for (ll i = 0; i < n; i++)
    {
        ll h;
        cin >> h;
        if (h >= k)
        {
            ans++;
        }
    }
    cout << ans << endl;
}

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

long long N, K, A[200009], B[200009], maxn;

int main() {
	cin >> N >> K;
	for (int i = 1; i <= N; i++) {
		cin >> A[i]; B[i] = max(A[i], 0LL);
	}
	for (int i = 1; i <= N; i++) A[i] += A[i - 1];
	for (int i = 1; i <= N; i++) B[i] += B[i - 1];

	for (int i = 1; i <= N - K + 1; i++) {
		long long E1 = B[N] - (B[i + K - 1] - B[i - 1]);
		maxn = max(maxn, E1);
		maxn = max(maxn, E1 + A[i + K - 1] - A[i - 1]);
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 1792
if __name__ == "__main__":
    building_num = 4
    floor_num = 3
    room_num = 10
    info = [
        [[0] * room_num for floor in range(floor_num)] 
        for building
        in range(building_num)
    ]

    notices_num = int(input())
    for i in range(notices_num):
        b, f, r, n = map(lambda x: int(x), input().split())
        info[b - 1][f - 1][r - 1] += n

    for building in range(building_num):
        for floor in range(floor_num):
            print("".join([f" {elem}" for elem in info[building][floor]]))
        if building != building_num - 1:  # Skip the last line #.
            print("#" * 20)



Measured memory_bytes: 5620
//import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;

public class Main<T> {
	public static void main(String[] args) throws NumberFormatException, IOException {
		//System.setIn(new FileInputStream("./input.txt"));
		Reader r = new InputStreamReader(System.in);
		int n = r.read() - 0x30;
		//n = 5;
		//long start = System.nanoTime();
		
		Point[] p = Koch(n);
		//System.out.println((start - System.nanoTime())/ 1000 + " us");
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < p.length; ++i){
			sb.append(p[i] + "\n");
		}
		System.out.println(sb);
	}

	public static Point[] Koch(int n) {
		Point[] p, p2;
		if(n == 0){
			p = new Point[2];
			p[0] = new Point(0.0, 0.0);
			p[1] = new Point(100.0, 0.0);
			return p;
		}else{
			p = Koch(n-1);
			p2 = new Point[(p.length - 1)*4 + 1];
			for(int i = 0; i < p.length; ++i) {
				// left edge
				p2[i*4] = new Point(p[i].x, p[i].y);
				if(i == p.length - 1){
					break;
				}
				// 3 middle points
				double mx = (p[i+1].x - p[i].x);
				double my = (p[i+1].y - p[i].y);
				
				p2[i*4 + 1] = new Point(mx / 3.0 + p[i].x, my / 3.0 + p[i].y);
				p2[i*4 + 2] = new Point(mx / 2.0 - my / (2.0 * 1.7320508) + p[i].x,
						my / 2.0 + mx / (2.0 * 1.7320508) + p[i].y);
				p2[i*4 + 3] = new Point(mx * 2.0 / 3.0 + p[i].x, my * 2.0 / 3.0 + p[i].y);
			}
			return p2;
		}
	}

	
}
class Point {
	public double x;
	public double y;
	@Override
	public String toString(){
		return String.format("%.5f %.5f", x, y);
	}
	public Point(double x, double y){
		this.x = x;
		this.y = y;
	}
}

Measured memory_bytes: 41004
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  vector<ll> v(n);
  rep(i, 0, n) cin >> v[i];
  sort(v.begin(), v.end());

  ll acc = v[0];
  int ans = 0;
  rep(i, 1, n) {
    if (acc * 2 < v[i])
      ans = i;
    acc += v[i];
  }
  cout << n - ans << endl;
}


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

int main(void) {
  string s;
  cin >> s;
  
  int count=0,tmp=0;
  for (int i=0;i<s.size();i++) {
    tmp=0;
    if (s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G') {
      tmp++;
      for (int j=i;j<s.size();j++) {
    	if (s[j+1] == 'A' || s[j+1] == 'T' || s[j+1] == 'C' || s[j+1] == 'G') {
      		tmp++;
        } else { break; }
      }
      count = max(count,tmp);
    }
  }
      
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
#define int long long
#define m_p make_pair
#define mod 1000000007
#define rep(i,n)  for(int i=0; i<(int)(n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>vec[i];
using namespace std;

int jousu(int, int);
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int kurai(int x00, int y00) {
	int z00 = (x00 % jousu(10, y00)) / jousu(10, y00 - 1);
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}


signed main() {
	int n;
	cin >> n;
	cout << n * (n - 1) / 2 << endl;
}


Measured memory_bytes: 256
#お札が合計N枚ある時に合計金額がY円になる枚数の組み合わせ　存在しない場合は（-1,-1,-1）
  
n,y=map(int,input().split())
a,b,c=-1,-1,-1

for i in range(n+1):
	for j in range(n-i+1):
		if 10000*i + 5000*j + 1000*(n-i-j) ==y:
			a,b,c=i,j,(n-i-j)

print(a,b,c)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(){
        int *x; 
        int _x[10];
        x = _x; 
        int in = 0;
        while(cin >> in){
                if(!in){
                        cout << *(x-1) << endl;
                        x--;
                }else{
                        *x = in; 
                        x++;
                }   
        }   
}

Measured memory_bytes: 0
#include <stdio.h>

int main(){
  int n;
  if(scanf("%d",&n)==1){}
  int v[n],c[n];int i;
  for(i=0;i<n;i++){
    if(scanf("%d",&v[i])==1){}
  }
  for(i=0;i<n;i++){
    if(scanf("%d",&c[i])==1){}
  }
  int sum=0;
  for(i=0;i<n;i++){
    if(v[i]-c[i]>0){
      sum+=v[i]-c[i];
    }
  }
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <bitset>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)

int M, N, D, S[32][32];
bitset<640> bits[640];

bool solve(int n) {
    int h = 0;
    rep(k, n) {
        int ix = -1;
        for(int i=h; i<n; i++) if(bits[i][k]) { ix=i; break; }
        if(ix==-1) continue;
        if(h!=ix) swap(bits[h], bits[ix]);
        rep(i, n) if(i!=h) if(bits[i][k]) bits[i] ^= bits[h];
        h++;
    }
    for(int i=h; i<n; i++) if(bits[i][n]) return false;
    return true;
}

int main() {
    for(;;) {
        scanf("%d%d%d", &M, &N, &D);
        if(M==0 && N==0 && D==0) return 0;
        rep(i, N) rep(j, M) scanf("%d", S[i]+j);
        const int n = N*M;
        rep(i, N) rep(j, M) {
            const int ix = i*M+j;
            bits[ix].reset();
            bits[ix].set(ix);
            if(S[i][j]) bits[ix].set(n);
            rep(x, N) rep(y, M) if(abs(i-x)+abs(j-y)==D) bits[ix].set(x*M+y);
        }
        printf("%d\n", (int)solve(n));
    }
}

Measured memory_bytes: 0
#include<stdio.h>


int main(void){


  int cup[3], c;
  char x[5];

  cup[0]=1;
  cup[1]=cup[2]=0;


  while(scanf("%s", x)!=EOF){
    c=cup[x[0]-'A'];
    cup[x[0]-'A']=cup[x[2]-'A'];
    cup[x[2]-'A']=c;    
  }

  if(cup[0]==1){
    printf("A\n");
  }
  else if(cup[1]==1){
    printf("B\n");
  }
  else{
    printf("C\n");
  }


  return(0);
}



Measured memory_bytes: 2056
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 //Compiler version g++ 6.3.0

 int main()
 {
 	string x,y,z;
 	cin >> x>>y>>z;
 	if(x[x.size()-1]==y[0]&&y[y.size()-1]==z[0]){
 		cout << "YES" << endl;
 	}else{
 		cout << "NO" << endl;
 	}
 }

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		int ans = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int q = sc.nextInt();
		String S = sc.next();
		String[] s = S.split("");
		int[][] qs = new int[q][2];
		for(int i=0; i<q; i++){
			qs[i][0] = sc.nextInt();
			qs[i][1] = sc.nextInt();
		}
		
		int[] acs = new int[n];
		int a = 0;
		for(int i=0; i<n; i++){
			if(a == 1 && s[i].equals("C")){
				acs[i] = acs[i-1] + 1;
			}
			else{
				if(i == 0){
					acs[i] = 0;
				}
				else{
					acs[i] = acs[i-1];
				}
			}
			
			if(s[i].equals("A")){
				a = 1;
			}else{
				a = 0;
			}
		}
		
		for(int i=0; i<q; i++){
			System.out.println(acs[qs[i][1]-1]-acs[qs[i][0]-1]);
		}
		
	}
}


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

int main(){
  int n,k,i;
  vector<int> b(200100);
  cin >> n >> k;

  for(i = 0 ; i < n ; i++){
    int s;
    cin >> s;
    b.at(s)++;
  }
  
  sort( b.begin(),b.end() );
  reverse( b.begin(),b.end() );
  int sum = 0;
  for(i = k ; i < n ; i++)	sum += b.at(i);
  
  cout << sum << endl;
  
}   

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

using namespace std;

const int inf = 1e9 + 7;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector <int> a(n);
    for (int &x : a) cin >> x;
    vector <int> dp(n);
    dp[0] = 0;
    dp[1] = abs(a[1] - a[0]);
    for (int i = 2; i < n; i++) {
        dp[i] = dp[i - 2] + abs(a[i] - a[i - 2]);
        dp[i] = min(dp[i], dp[i - 1] + abs(a[i] - a[i - 1]));
    }
    cout << dp[n - 1] << '\n';
    return 0;
}


Measured memory_bytes: 1024
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

#define INF 100000

long long gcd(long long x,long long y){
  if(x%y == 0) return y;
  else return gcd(y,x%y);
}

int main(){
  long long n,m;
  string s,t;
  cin >> n >> m;
  cin >> s >> t;
  long long g = gcd(n,m);
  long long L = n*m/g;
  long long p,q;
  p = n/g;
  q = m/g;
  bool flag = true;
  for(int i=0;i<g;i++){
    if(s[i*p] != t[i*q]){
      flag = false;
    }
  }
  if(flag) cout << L << endl;
  else cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 512
use std::cmp::*;
use std::io::*;

mod enumeration {
    pub struct Enumeration {
        fact: Vec<u64>,
        finv: Vec<u64>,
        modulo: u64,
    }
    impl Enumeration {
        pub fn new(n: usize, modulo: u64) -> Enumeration {
            let mut fact: Vec<u64> = vec![1; n];
            let mut inv: Vec<u64> = vec![1; n];
            let mut finv: Vec<u64> = vec![1; n];
            for i in 2..n {
                fact[i] = fact[i - 1] * (i as u64) % modulo;
                inv[i] = modulo - (modulo / (i as u64)) * inv[(modulo as usize % i)] % modulo;
                finv[i] = inv[i] * finv[i - 1] % modulo;
            }
            Enumeration {
                fact: fact,
                finv: finv,
                modulo: modulo,
            }
        }
        pub fn c(&self, n: usize, k: usize) -> u64 {
            if n < k {
                return 0;
            }
            self.fact[n] * self.finv[n - k] % self.modulo * self.finv[k] % self.modulo
        }
    }
}

fn mod_pow(mut x: u64, mut e: u64, m: u64) -> u64 {
    let mut res = 1;
    while e > 0 {
        if e & 1 == 1 {
            res = res * x % m;
        }
        x = x * x % m;
        e >>= 1;
    }
    res
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let m: u64 = itr.next().unwrap().parse().unwrap();
    let k: u64 = itr.next().unwrap().parse().unwrap();

    const MOD: u64 = 998244353;
    let e = enumeration::Enumeration::new(n, MOD);
    let mut ans = 0;
    for i in 0..=k {
        // m * (m-1)^(n-i-1) * (n-1)Ci
        ans += m * mod_pow(m - 1, n as u64 - i - 1, MOD) % MOD * e.c(n - 1, i as usize) % MOD;
        ans %= MOD;
    }
    println!("{}", ans);
}


Measured memory_bytes: 6684
n, m = map(int, input().split())
max_l = 0
min_r = n
for i in range(m):
  l, r = map(int, input().split())
  if l > max_l:
    max_l = l
  if r < min_r:
    min_r = r
ans = min_r - max_l + 1
if ans < 0:
  ans = 0
print(ans)

Measured memory_bytes: 43480
#include<stdio.h>
#include<math.h>
#define N 10000000

int isprime(int);

int main(){
  int i,j;
  int count=0;
  int flag;
  int n;
  
  
  while(1){
    count=0;
    scanf("%d",&n);
    if(n==0)break;
    
    for(i=n+1;i<=2*n;i++){
      if(isprime(i)==1){
	count++;
      }   
    }
    printf("%d\n",count);
  }
  
  return 0;
}

int isprime(int x){
  int i=3;
  
  if(x==2) return 1;
  
  if(x<2||x%2==0)return 0;

  while(i<=sqrt(x)){
    if(x%i==0) return 0;
    i+=2;
  }

  return 1;
}

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

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    for (int i = 0; i < tx - sx; ++i) cout << 'R';
    for (int j = 0; j < ty - sy; ++j) cout << 'U';
    for (int k = 0; k < tx - sx; ++k) cout << 'L';
    for (int l = 0; l < ty - sy; ++l) cout << 'D';
    cout << 'D';
    for (int i = 0; i < tx - sx + 1; ++i) cout << 'R';
    for (int j = 0; j < ty - sy + 1; ++j) cout << 'U';
    cout << 'L';
    cout << 'U';
    for (int k = 0; k < tx - sx + 1; ++k) cout << 'L';
    for (int l = 0; l < ty - sy + 1; ++l) cout << 'D';
    cout << 'R' << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        System.out.println(calc(N));
        sc.close();
        return;
    }

    static String calc(long N) {
        if (N == 0) {
            return "";
        }
        N--;
        return calc(N / 26) + (char) ('a' + N % 26);
    }
}


Measured memory_bytes: 39216
#include <iostream>
#include <algorithm>
#include <string>
#include <cctype>
using namespace std;

typedef unsigned int uint;

const int M = 9;

uint Nd[M];

uint toDec(const string &s) {
  uint res = 0u;
  for(int i = s.size()-1, j = 0; i >= 0; --i, j += 4) {
    uint v = 0;
    if(isalpha(s[i])) v = s[i]-'a'+10;
    else v = s[i] - '0';
    res += ( v<<j );
  }
  return res;
}

string toHex(uint v) {
  if(v == 0) return "0";
  string res = "";
  while(v) {
    uint t = ( v & ((1u<<4u)-1u) );
    if(t < 10) res += (char)(t+'0');
    else res += (char)(t-10+'a');
    v = (v>>4);
  }
  reverse(res.begin(), res.end());
  return res;
}

int main() {
  int T;
  cin >> T;
  while(T--) {
    for(int i = 0; i < M; ++i) {
      string tmp;
      cin >> tmp;
      Nd[i] = toDec(tmp);
    }
    uint K = 0;
    for(int b = 0; b < 32; ++b) {
      uint S = 0;
      for(int i = 0; i < M-1; ++i) {
        S += Nd[i] ^ K;
      }
      if(((S>>b)&1u) != ((Nd[M-1]>>b)&1u)) {
        K |= (1u<<b);
      }
    }
    cout << toHex(K) << endl;
  }
  return 0;
}

Measured memory_bytes: 1208