akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

////////////////////////////////////////////////////////

const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 

int main() {
    ll n, s; cin >> n >> s;
    Vl a(n);
    rep(i, 0, n) cin >> a[i];
    vector<mint> dp(s+1, 0);
    dp[0] = 1;
    rep(i, 0, n){
        vector<mint> p(s+1, 0);
        swap(dp, p);
        rep(j, 0, s+1){
            dp[j] += p[j]*2;
            if(j + a[i] <= s) dp[j+a[i]] += p[j];
        }
    }
    co(dp[s]);

    return 0;
}


Measured memory_bytes: 3672
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAX_N 100000
int x[MAX_N];
 
int main() {
    int n, a, b, c, d, e, maxn = 0;;
    while (true) {
        for (int i = 0; i < MAX_N; i++) {
            x[i] = 0;
        }
        cin >> n; maxn = 0;
        if (n == 0) { break; }
        for (int i = 0; i < n; i++) {
            scanf("%02d:%02d:%02d", &a, &b, &c);
            d = a * 3600 + b * 60 + c;
            scanf("%02d:%02d:%02d", &a, &b, &c);
            e = a * 3600 + b * 60 + c;
            x[d]++; x[e]--;
        }
        for (int i = 1; i < 99999; i++) {
            x[i] += x[i - 1];
            maxn = max(maxn, x[i]);
        }
        cout << maxn << endl;
    }
}


Measured memory_bytes: 3432
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  ll ans = 800 * N - 200 * (N / 15);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define endl '\n'
typedef pair<int, int> P;
typedef long long ll;
set<P> Check;
int H[300005],W[300005];
int main(){
    //cin.tie(0);
    //ios_base::sync_with_stdio(false);
    int h,w,m;
    cin >> h >> w;
    cin >> m;
    for(int i=0;i<m;i++){
        int x,y;
        cin >> x >> y;
        Check.insert(make_pair(x,y));
        H[x]++;
        W[y]++;
    }
    int hmax=0,wmax=0;
    for(int x=1;x<=h;x++){
        if(H[x]>hmax) hmax=H[x];
    }
    for(int y=1;y<=w;y++){
        if(W[y]>wmax) wmax=W[y];
    }
    //cout << "max " << hmax <<  " " << wmax <<endl;
    int hnum=0,wnum=0;
    vector<int> hval,wval;
    for(int x=1;x<=h;x++){
        if(H[x]==hmax){
           hval.push_back(x);
           hnum++; 
           //cout << x << " "; 
        }
    }
    //cout <<endl;
    for(int y=1;y<=w;y++){
        if(W[y]==wmax){
            wval.push_back(y);
            wnum++;
            //cout << y << " ";
        }
    }
    //cout << endl;
    //cout << "cal" << endl;
    for(int i=0;i<hnum;i++){
        for(int j=0;j<wnum;j++){
            //cout <<hval[i] << " " << wval[j] <<endl;
            if(Check.count(make_pair(hval[i],wval[j]))==0){
                cout << hmax+wmax;
                //cout << "hello";
                return 0;
            }
        }
    }
    cout << hmax+wmax-1;
    return 0;
}


Measured memory_bytes: 23860
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayList<Double> list = new ArrayList<Double>();
		
		while(sc.hasNext()){
			list.add(sc.nextDouble());
		}
		Collections.sort(list);
		double sub = list.get(list.size()-1) - list.get(0);
		System.out.println(sub);
	}
}

Measured memory_bytes: 18664
N,K,Q = [int(i) for i in input().split()]
ans_data = [int(input()) for i in range(Q)]
data = [K-Q for i in range(N)]

for i in range(Q):
    data[ans_data[i]-1] += 1
    
#print(data)

for i in range(N):
    if data[i] > 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 11788
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)
#define rrep(i,a,b) for(int (i)=int(a);(i)>=int(b);(i)--)

#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "

#define llint long long int

#define INF (long long)(1e9+1)
#define MOD (long long)(1e9+7)
#define INF64 (long long)(1e18+1)

#define F first
#define S second

#define Pii  pair<int,int>
#define Pll  pair<long long,long long>
#define Piii pair<int,pair<int,int>>
#define Plll pair<long long,pair<long long,long long>>

#define Vll(a,b,c)    vector<vector<long long>> (a)((b),vector<long long>((c))
#define Vlll(a,b,c,d) vector<vector<vector<long long>>> (a)((b),vector<vector<long long>>((c),vector<long long>((d)))

#define MAX_N 1000000

int main (void)
{
  //INPUT
  string S;
  cin >> S;


  //SOLVE
  string ans;
  llint buf=0;
  rep(i,0,S.length()) {
    if ((i%2) == 1) {
      if ((S[i] == 'L') || (S[i]=='U') || (S[i]=='D')) {
        buf++;
      } else {
        buf=-1;
        break;
      }

    } else {
        if ((S[i] == 'R') || (S[i]=='U') || (S[i]=='D')) {
          buf++;
        } else {
          buf=-1;
          break;
        }

    }
  }

  if (buf==S.length()) {
    ans = "Yes";
  } else {
    ans = "No";
  }


  //OUTPUT
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
const main = (inputs) => {
  var k = inputs[0].split(" ")[0]-0;
  var x = inputs[0].split(" ")[1]-0;
  var ans = [];
  for(var i=x-k+1;i<x+k;i++) ans.push(i);
  console.log(ans.join(" "));
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,j,k,l;
    char c[234],d[234];
    scanf("%d %s %s",&n,&c,&d);
    for(i=0;i<n;i++)
        printf("%c%c",c[i],d[i]);
}


Measured memory_bytes: 256
n, x, y = map(int, input().split())
cnt = [0] * n
# 漸化式が建てられそうでめんどくさい場合は、片方を固定する
# 端点を固定する 1..n-2 から順に大きい頂点に向かって伸びていく
for i in range(n - 1):
    for j in range(i + 1, n):
        if i <= x - 1:
            if j <= x - 1:  # 1 idx
                cnt[j - i] += 1
            elif j <= y - 1:
                cnt[min(j - i, x + y - i - j - 1)] += 1
            else:
                cnt[x - y - i + j + 1] += 1
        elif x - 1 < x <= y - 1:
            if j <= y - 1:
                cnt[min(j - i, 1 + (i - x + 1) + (y - 1 - j))] += 1
            else:
                cnt[min((j - i), 1 + (i - x + 1) + (j - y + 1))] += 1
        else:
            cnt[j - i] += 1

for i in range(1, n):
    print(cnt[i])


Measured memory_bytes: 3444
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const ll mod = 1000000007;
const int MAX_V = 8;

int n, m, ans = 0;
Graph G(MAX_V, vector<int>(MAX_V));
vector<int> visited(MAX_V);

void check() {

    int flag = 1;
    rep(i, n) {
        if(!visited[i]) {
            flag = 0;
        }
    }
    
    if(flag) {
        ans++;
    }
}

void dfs(int v) {

    check();
    
    rep(u, n) {
        if(G[v][u] && !visited[u]) {
            visited[u] = 1;
            dfs(u);
            visited[u] = 0;
        }
    }

}

int main() {

    cin >> n >> m;

    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--;  b--;
        G[a][b] = G[b][a] = 1;
    }

    visited[0] = 1;    

    dfs(0);

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

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

int main(void){
	int A,B,K;
	scanf("%d %d", &A,&B);
	K =( A + B )/ 2;
	if (abs(A - K) == abs(B - K)) {
		printf("%d", K);
	}
	else {
		puts("IMPOSSIBLE");
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
long long a[300009];
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    long long  n,i,j,ans=0LL;
    cin >> n;
    for(i=0;i<n;i++)
    {
        cin >> a[i];
        if(a[i-1] && a[i])
        {
            ans++;
            a[i]--;
        }
        ans+=(a[i]/2);
        a[i]%=2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,s,t) for(int i=s;i<=(t);++i) 
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define mp(a,b) make_pair(a,b) 
using namespace std;
const int N=3e5+50; 
int n,a[N]; 

bool chk(int x){
	if(x==1){rep(i,2,n)if(a[i]<=a[i-1])return false; return true; }
	set<pair<int,int>> s; 
	rep(j,2,n){
		if(a[j]<=a[j-1]){
			while(!s.empty()&&(s.rbegin()->first>=a[j]))s.erase(*s.rbegin()); 
			dec(i,a[j]-1,0){
				if(s.empty()||s.rbegin()->first!=i){
					s.insert(mp(i,1));
					break;
				}
				if(s.rbegin()->second+1<x){
					auto t=*s.rbegin(); s.erase(*s.rbegin()); ++t.second; s.insert(t); 
					break;
				}else{
					s.erase(*s.rbegin()); 
				}
			}
			if(s.empty())return false;
		}}
	return true;
}

int main() {
	scanf("%d", &n); 
	rep(i,1,n) scanf("%d",a+i); 
	int l=0,r=n; 
	while(r-l>1){
		int mid=(l+r)>>1;
		if(chk(mid))r=mid;
		else l=mid;
	}
	printf("%d\n",r); 
	return 0;
}

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"

void Main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &x : a) {
    cin >> x;
  }
  set<int> s;
  for (const auto &x : a) {
    s.insert(x);
  }

  if (s.size() > 3) {
    cout << "No\n";
    return;
  } 
  if (s.size() == 1 && s.count(0) == 1) {
    cout << "Yes\n";
    return;
  }
  else if (s.size() == 2) {
    int c1 = 0;
    int c2 = 0;
    for (const auto &x : a) {
      if (x == 0)
        ++c1;
      else
        ++c2;
    }
    if (c2 == c1 * 2) {
      cout << "Yes\n";
      return;
    }
  } else if (s.size() == 3) {
    int c1 = 0;
    int c2 = 0;
    int c3 = 0;
    vector<int> val;

    for (const auto &x : s) {
      val.push_back(x);
    }

    for (const auto &x : a) {
      if (x == val[0])
        ++c1;
      if (x == val[1])
        ++c2;
      if (x == val[2])
        ++c3;
    }
    if (c1 == c2 && c2 == c3 && (val[0] ^ val[1]) == val[2]) {
      cout << "Yes\n";
      return;
    }
  }
  cout << "No\n";
  return;
}

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


Measured memory_bytes: 4224
#include <iostream>

using namespace std;

void solve()
{
	int a, b, n;
	while(cin >> a >> b >> n)
	{
		int k = a % b;
		int ans = 0;
		for(int i = 0; i < n; ++i)
		{
			k *= 10;
			ans += k / b;
			k %= b;
		}
		cout << ans << endl;
	}
}

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

Measured memory_bytes: 1160
#include<stdio.h>
int main(void)
{
    int n,m,i,a;
	while(1){
	    scanf("%d %d",&n,&m);
		if(n==0&&m==0) break;
		a=0;
		if(n<m){
		i=n;
		n=m;
		m=i;
	}
		while(1){
		    i=n%m;
			n=m;
			m=i;
			a++;
			if(m==0) break;
		}
		printf("%d %d\n",n,a);
	}
	return 0;
}

Measured memory_bytes: 2592
n=int(input())
a=[input().split() for i in range(n)]
for i in range(n):
    a[i][1]=int(a[i][1])
b=sorted(a,key=lambda x:x[1],reverse=True)    
b=sorted(b,key=lambda x:x[0])
for i in b:
    print(a.index(i)+1)

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline

H, W = map(int, input().split())
Cy, Cx = map(int, input().split())
Dy, Dx = map(int, input().split())
Board = [input().rstrip() for _ in range(H)]







Cy -= 1
Cx -= 1
Dy -= 1
Dx -= 1

dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]
vst = [[-1] * W for _ in range(H)]

def BFS(y, x, C):
    vst[y][x] = C
    q = [(x, y)]
    for x1, y1 in q:
        for i in range(4):
            x2 = x1 + dx[i]
            y2 = y1 + dy[i]
            if 0 <= x2 < W and 0 <= y2 < H and vst[y2][x2] < 0 and Board[y2][x2] == '.':
                vst[y2][x2] = C
                q.append((x2, y2))

count = 0
for i in range(H):
    for j in range(W):
        if vst[i][j] < 0 and Board[i][j] == '.':
            BFS(i, j, count)
            count += 1




adj = [set() for _ in range(count)]
vst_g = [False] * count

for i in range(H):
    for j in range(W):
        if Board[i][j] == '.':
            cur = vst[i][j]
            for x in [-2, -1, 0, 1, 2]:
                for y in [-2, -1, 0, 1, 2]:
                    x1 = x + j
                    y1 = y + i
                    if 0 <= x1 < W and 0 <= y1 < H and Board[y1][x1] == '.':
                        if vst[y1][x1] != cur:
                            adj[cur].add(vst[y1][x1])



vst_g = [-1] * count
vst_g[vst[Cy][Cx]] = 0
q = [vst[Cy][Cx]]


for u in q:
    for v in adj[u]:
        if vst_g[v] < 0:
            vst_g[v] = vst_g[u] + 1
            q.append(v)

print(vst_g[vst[Dy][Dx]])

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define show(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define show(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<62;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int a,b;
    cin >> a >> b;
    if(a<=0 and 0<=b){
        cout << "Zero" << endl;
        return;
    }
    if(0<a){
        cout << "Positive" << endl;
        return;
    }
    if((b-a+1)%2==0) cout << "Positive" << endl;
    else cout << "Negative" << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program{
	static void Main(){
		long[] n=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
		string s=Console.ReadLine();
		string t=Console.ReadLine();
		long ans=n[0]*n[1]/gcd(n[0],n[1]);
		if(ans==n[0]*n[1]){
			Console.WriteLine(s[0]==t[0]?ans:-1);
		}
		else{
			var hs=new Dictionary<long,char>();
			long q=ans/n[0];
			for(int i=0;i<n[0];i++){hs.Add(i*q,s[i]);}
			q=ans/n[1];
			for(int i=0;i<n[1];i++){
				if(hs.ContainsKey(i*q)&&hs[i*q]!=t[i]){
					ans=-1;
					break;
				}
			}
			Console.WriteLine(ans);
		}
	}
	static long gcd(long a,long b){
		long c=Math.Max(a,b)%Math.Min(a,b);
		b=Math.Min(a,b);
		while(c!=0){
			a=b%c;
			b=c;
			c=a;
		}
		return b;
	}
}

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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



int main()
{
	ll N, M;
	cin >> N >> M;
	vector<ll> S(N), T(M);
	REP(i, N)cin >> S[i];
	REP(i, M)cin >> T[i];

	vector<vector<ll>> dp(N + 1, vector<ll>(M + 1, 0));
	REP(i, N + 1)dp[i][0] = 1;
	REP(j, M + 1)dp[0][j] = 1;
	FOR(i, 1, N + 1)FOR(j, 1, M + 1) {
		dp[i][j] = dp[i][j - 1] + dp[i - 1][j];
		if (S[i - 1] != T[j - 1])dp[i][j] -= dp[i - 1][j - 1];
		((dp[i][j] %= MOD) += MOD) %= MOD;
	}
	cout << dp.back().back() << endl;
	return 0;
}


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

int main()
 {
   int a[100];
   for(int i=0;i<=9;i++)
    {
     cin>>a[i];
     }
    for(int j=0;j<=9;j++) {
     for(int k=0;k<=9;k++)
     {
         if(a[j]>a[k])
         {
             int t;
             t=a[j];
             a[j]=a[k];
             a[k]=t;
         }
     }
    }
     for(int g=0;g<=2;g++)
     {
         printf("%d\n",a[g]);
     }

 return 0;
 }



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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; --i)
#define repr(i, j) FOR(i, j, 0)
#define INF INT_MAX

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<P, int> Pi;

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

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

#define MAX_N 40

int n;
ll w[MAX_N], v[MAX_N];
ll W;

P ps[1 << (MAX_N/2)];

int main() {
	scanf("%d %lld", &n, &W);
	rep(i, n) scanf("%lld %lld", &v[i], &w[i]);
	int n2 = n / 2;
	rep(i, 1 << n2) {
		ll sw = 0, sv = 0;
		rep(j, n2) {
			if (i & (1 << j)) {
				sw += w[j];
				sv += v[j];
			}
		}
		ps[i] = P(sw, sv);
	}
	sort(ps, ps + (1 << n2));
	int m = 1;
	FOR(i, 1, 1 << n2) {
		if (ps[m - 1].second < ps[i].second) ps[m++] = ps[i];
	}
	ll res = 0;
	rep(i, 1 << (n - n2)) {
		ll sw = 0, sv = 0;
		rep(j, n - n2) {
			if ((i >> j) & 1) {
				sw += w[n2 + j];
				sv += v[n2 + j];
			}
		}
		if (sw <= W) {
			ll tv = (lower_bound(ps, ps + m, P(W - sw, LLONG_MAX)) - 1)->second;
			res = max(res, sv + tv);
		}
	}
	printf("%lld\n", res);
	return 0;
}

Measured memory_bytes: 19608
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <assert.h>
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 FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    REP(i,n) cin >> s[i];

    int ans = 0;
    REP(a,n){
        bool ok = true;
        REP(i,n) REP(j,n){
            if (s[(i+a) % n][j] != s[(j+a) % n][i]) ok = false;
        }
        if (ok) ans += n - a;
    }
    FOR(b,1,n-1){
        bool ok = true;
        REP(i,n) REP(j,n){
            if (s[i][(j+b) % n] != s[j][(i+b) % n]) ok = false;
        }
        if (ok) ans += n - b;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstring>

using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const int SIZE = 300;
const int N = 1000002;
int p[SIZE+1];
int dp1[N], dp2[N];

void make_pollock (void )
{
	memset (p, 0, sizeof (p ) );

	for (int i = 0; i <= SIZE; i++ )
		p[i] = i*(i+1LL)*(i+2LL)/6LL;
}

void make_dp (void )
{
	fill (dp1, dp1+N, INF );
	fill (dp2, dp2+N, INF );

	dp1[0] = 0;
	for (int i = 1; i <= SIZE; i++ ){
		int m = p[i];
		for (int j = m; j <= N; j++ )
			dp1[j] = min (dp1[j], dp1[j-m]+1 );
	} // end for

	dp2[0] = 0;
	for (int i = 1; i <= SIZE; i++ ){
		if (p[i] % 2 == 0 ) continue;
		int m = p[i];
		for (int j = m; j <= N; j++ )
			dp2[j] = min (dp2[j], dp2[j-m]+1 );
	} // end for	
}
	
int main()
{
	make_pollock();
	make_dp ();

	int n;
	while (cin >> n && n )
		cout << dp1[n] << ' ' << dp2[n] << endl;
	
	return 0;
}

Measured memory_bytes: 8568
#include<iostream>
#include<string>
#include<vector>
#include<set>

#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)

using namespace std;

set<int> solve(const string &str){
  vector<set<int> > nums;
  set<int> ret;
  vector<char> ops;

  int p = 0;

  while(p < str.size()){
    if(str[p] == '('){
      int lev = 1;
      int pp  = ++p;
      for(; lev > 0; ++p){
        if(str[p] == '(') ++lev;
        else if(str[p] == ')') --lev;
      }
      nums.push_back(solve(str.substr(pp, p - pp)));
    }else if(isdigit(str[p])){
      set<int> num;
      int tmp = 0;
      for(; isdigit(str[p]); ++p){
        tmp *= 10; tmp += str[p] - '0';
      }
      num.insert(tmp);
      nums.push_back(num);
    }else{
      ops.push_back(str[p++]);
    }
  }

  const int n = nums.size();
  vector<vector<set<int> > > memo(n, vector<set<int> >(n));

  for(int i = 0; i < n; i++)
    memo[i][i] = nums[i];

  for(int len = 1; len < n; len++){
    for(int i = 0; i + len < n; i++){
      for(int last = 0; last < len; last++){
        FOR(it1, memo[i][i+last]){
          FOR(it2, memo[i+last+1][i+len]){
            switch(ops[i + last]){
            case '+':
              memo[i][i+len].insert(*it1 + *it2); break;
            case '-':
              memo[i][i+len].insert(*it1 - *it2); break;
            case '/':
              if(*it2 != 0) memo[i][i+len].insert(*it1 / *it2); break;
            case '*':
              memo[i][i+len].insert(*it1 * *it2); break;
            }
          }
        }
      }
    }
  }

  return memo[0][n-1];
}

int main(){
  string str;
  while(cin >> str, str[0] != '#')
    cout << solve(str).size() << endl;
  return 0;
}

Measured memory_bytes: 0
#131

n,l = map(int, input().split())

mn = 0
if n + l -1 < 0:
    mn = max([i + l -1 for i in range(1, n+1)])
elif 1 + l - 1 >= 0:
    mn = min([i + l -1 for i in range(1, n+1)])

print(sum(i + l - 1 for i in range(1, n+ 1)) - mn)

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

int main()
{
	int num = 0;
	int an[5];
	int bn[5];
	int cn[5];
	int max;
	
	for(int i = 0; i < 5; i++){
		cin >> an[i];
	}


	max = 0;

	for(int i = 0; i < 5; i++){

		bn[i] = (int) (((double)an[i] / 10.0) + 0.9) * 10;
		num += bn[i];
		cn[i] = bn[i] - an[i];
		if(max < cn[i]) max = cn[i];
	}

	num -= max;

	cout << num << endl;


	return 0;
}

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

int main (){
  int S, S_1, S_2, S_3;
  cin >> S;
  S_1 = S / (60 * 60);
  S_2 = (S - S_1 * 3600) / 60;
  S_3 = S - S_1 * 3600 - S_2 * 60;

  cout << S_1 << ":" << S_2 << ":" << S_3 << endl;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(long long i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    ll ans=1,bad=1;
    rep(i,n){
        ans*=3;
        if(a[i]%2==0) bad*=2;
    }
    cout<<ans-bad<<endl;
    return 0;
}

Measured memory_bytes: 3628
import Control.Arrow
import Data.List
import qualified Data.ByteString.Char8 as B
import Control.Monad
import qualified Data.IntMap as IM

main :: IO ()
main = breads >>= main'
    where
        main' nm = breads >>= main'' nm
        main'' [n, m] ps = replicateM m breads >>= print . solve n m ps

solve :: Int -> Int -> [Int] -> [[Int]] -> Int
solve n m ps xys = fst . foldl' ff (0, uft) $ zip [0..] ps
    where
        uft = foldl' (\acc [x, y] -> unionNodes (x - 1) (y - 1) acc) (makeTree n) xys
        ff (acc, t) (i, p)
            | b = (acc + 1, s)
            | otherwise = (acc, s)
            where
                (b, s) = isSame i (p - 1) t

newtype UFTree = UFTree (IM.IntMap (Int, Int))
    deriving (Show, Eq)
    
makeTree :: Int -> UFTree
makeTree n = UFTree . IM.fromList . zip [0..n] $ zip (repeat 0) [0..]

findRoot :: Int -> UFTree -> (Int, UFTree)
findRoot v t@(UFTree vs)
    | v == root = (v, t)
    | otherwise = (vr, UFTree u)
    where
        (rank, root) = vs IM.! v 
        (vr, UFTree s) = findRoot root t
        u = IM.update (return . second (const vr)) v s
        
unionNodes :: Int -> Int -> UFTree -> UFTree
unionNodes a b t 
    | c == d = t
    | ra < rb = UFTree $ IM.update (return . second (const d)) c vs
    | ra > rb = UFTree $ IM.update (return . second (const c)) d vs
    | otherwise = UFTree $ IM.update (\(x, _) -> return (x + 1, c)) d vs
    where
        (c, s) = findRoot a t
        (d, UFTree vs) = findRoot b s
        ra = fst $ vs IM.! c
        rb = fst $ vs IM.! d
        
isSame :: Int -> Int -> UFTree -> (Bool, UFTree)
isSame a b t = (c == d, u)
    where
        (c, s) = findRoot a t
        (d, u) = findRoot b s
        

breads :: IO [Int]
breads = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

Measured memory_bytes: 63868
#include<bits/stdc++.h>
using namespace std;
int n;
char s[1010101];
int a[1010101];
int b[1010101];
int main()
{
	scanf("%s", s + 1);
	n = strlen(s + 1);
	for(int i = 1; i <= n; i++)
	{
		if(s[i] == '1')
			a[i] = 1;
		else
			a[i] = -1;
		a[i] += a[i-1];
	}
	b[n] = a[n];
	for(int i = n - 1; i >= 0; i--)
		b[i] = max(b[i+1], a[i]);
	
	int c = 0, mi = 0;
	for(int i = 1; i <= n; i++)
	{
		if(s[i] == '?' && c + 2 + b[i] <= b[0])
			c += 2;
		mi = min(mi, a[i] + c); 
	}
	int ans = 1e7;
	ans = min(ans, b[0] - mi);
	c = 0, mi = 0;
	for(int i = 1; i <= n; i++)
	{
		if(s[i] == '?' && c + 2 + b[i] <= b[0] + 1)
			c += 2;
		mi = min(mi, a[i] + c); 
	}
	ans = min(ans, b[0] + 1 - mi);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 12644
while True:
    H,M = map(int,input().split())
    if H == 0 and M == 0:
        break
    for i in range(H):
        for j in range(M):
            if i == 0 or i == H-1 or j == 0 or j == M-1:
                print("#",end = "")
            else:
                print(".",end = "")
        print()
    print()
    


Measured memory_bytes: 7008
s = input()

front = s[0:2]
back = s[2:4]

a = 0
b = 0
if 1 <= int(front) <= 12:
    a = 1
if 1 <= int(back) <= 12:
    b = 1

if a == 1 and b==1:
    print("AMBIGUOUS")
elif a == 1:
    print("MMYY")
elif b == 1:
    print("YYMM")
else:
    print("NA")

    

Measured memory_bytes: 38256
package main

import "fmt"

func main() {
        var n int
        fmt.Scanf("%d", &n)
        var s string
        fmt.Scanf("%s", &s)

        for _, r := range s {
                c := r + rune(n)

                if c > rune(90) {
                        c -= rune(26)
                }
                fmt.Print(string(c))
        }
}

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

int main()
{
  int n;cin>>n;string s;cin>>s;
  int i;
  int ans=0;
  for(i=0;i<n-2;i++)
  {
    if(s.at(i)=='A'&&s.at(i+1)=='B'&&s.at(i+2)=='C')ans++;
  }
  cout<<ans<<endl;
}

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

int main() {
	string s; cin >> s;
	for(int i=1;i<=s.size();i++) {
		if(i%2==0) {
			if(s[i-1]!='L'&&s[i-1]!='U'&&s[i-1]!='D') {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			if(s[i-1]!='R'&&s[i-1]!='U'&&s[i-1]!='D') {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	int n, m;
	while(cin >> n >> m, n, m) {
		vi a(n);
		rep(i, n) cin >> a[i];
		int ans = -1;
		rep(i, n) rep(j, i) if(a[i] + a[j] <= m) {
			if(ans < a[i] + a[j]) ans = a[i] + a[j];
		} 
		if(ans == -1) cout << "NONE" << endl;
		else cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3012
#include <bits/stdc++.h>
using namespace std;
#define F first 
#define S second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> pi;
ll h, w, ans, cur;
char grid[50][50];
ll dist[25][25];
deque<pi> starting;
queue<pi> q;
bool visited[40][40];
ll dx[] = {0, 1, -1, 0};
ll dy[] = {1, 0, 0, -1};
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> h >> w;
	for (ll i = 0; i < h; i++){
		for (ll j = 0; j < w; j++){
			cin >> grid[i][j];
			if (grid[i][j] == '.')starting.pb(mp(i, j));
		}
	}
	while (starting.size()){
		pi topp = starting.front();
		starting.pop_front();
		q.push(topp);
		ans = max(ans, cur);
    // cout << cur << '\n';
		cur = 0;
    memset(visited,0,sizeof(visited));
    visited[topp.F][topp.S]=1;
		memset(dist, 0, sizeof(dist));
		while (!q.empty()){
			pi fron = q.front();
			q.pop();
			for (ll i= 0; i < 4; i++){
				ll nx = fron.F + dx[i], ny = fron.S+dy[i];
				if (nx < 0 || ny < 0 || nx >= h || ny >= w || grid[nx][ny] == '#'||visited[nx][ny])continue; 
        visited[nx][ny]=1;
				dist[nx][ny] = dist[fron.F][fron.S] +1;
				cur = max(cur, dist[nx][ny]);
				q.push(mp(nx, ny));
		}

	}

	
}
cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

// long long gcd(long long a, long long b){
//     if (a < b){
//         a ^= b;
//         b ^= a;
//         a ^= b;
//     }
//     return b ? gcd(b, a % b) : a;
// }

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

int main(){
    
    int n;
    cin >> n;
    double x[n+1],y[n+1],ans=0;
    for(int i=1;i<=n;i++){
        cin >> x[i] >> y[i];
    }
    vector<int> a(n);
    for(int i=0;i<n;i++){
        a[i] = i+1;
    }
    do{
        for(int i=0;i<n-1;i++){
            ans += sqrt((x[a[i]]-x[a[i+1]])*(x[a[i]]-x[a[i+1]])+(y[a[i]]-y[a[i+1]])*(y[a[i]]-y[a[i+1]]));
        }
    }while(next_permutation(a.begin(),a.end()));
    
    for(int i=n;i>0;i--){
        ans /= i;
    }
    cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;

void main() {
    int L = readln.chomp.to!int;
    double A = readln.chomp.to!double;
    double B = readln.chomp.to!double;
    double C = readln.chomp.to!double;
    double D = readln.chomp.to!double;
    writeln(L-max((A/C).ceil, (B/D).ceil));
}

Measured memory_bytes: 2544
import numpy as np

n = input()
k = int(input()) + 1
d = len(n)
dp0 = np.zeros((d, k), dtype=int)
dp1 = np.zeros((d, k), dtype=int)
dp0[0][0] = 1
dp0[0][1] = int(n[0]) - 1
dp1[0][1] = 1
for i in range(d - 1):
    for j in range(k):
        dp0[i + 1][j] = dp0[i][j]
        if j > 0:
            dp0[i + 1][j] += 9 * dp0[i][j - 1]
        m = int(n[i + 1])
        if m > 0:
            dp0[i + 1][j] += dp1[i][j]
            if j > 0:
                dp0[i + 1][j] += (m - 1) * dp1[i][j - 1]
                dp1[i + 1][j] = dp1[i][j - 1]
            else:
                dp1[i + 1][j] = 0
        else:
            dp1[i + 1][j] = dp1[i][j]
print(dp0[d - 1][k - 1] + dp1[d - 1][k - 1])

Measured memory_bytes: 12488
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K, A, B;
  cin >> K >> A >> B;
  
  if (A % K == 0) {
    cout << "OK" << endl;
  }
  else {
    int n;
    n = A % K;
    if ((A + K - n) <= B) {
      cout << "OK" << endl;
    }
    else{
      cout << "NG" << endl;
    }
  }
}

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

using namespace std;

int cost[100005];
int dp[100005];

int main(){
    ios::sync_with_stdio(0); cin.tie();
     
    int N, a;
    cin >> N ;
    for(int i = 0 ;i < N+1 ; i++) dp[i] = 1000000002; //set value
    for(int i=0;i<N;i++){
        cin >> a;
        cost[i] = a;
    }
    dp[0] = 0;
    
    for(int i = 1 ; i < N ; i++){
        for(int j = 1; j < 3 ; j++){
            
            if( i - j >= 0 ) {
              dp[i] = min( dp[i], dp[i-j] + abs(cost[i] - cost[i-j])); 
                             }
            else
                break;
            
            
        }
    }
    cout << dp[N-1];
    
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <deque>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, up) for (ll i = 0; i < up; ++i)
#define repp(i, up) for (ll i = 0; i <= up; ++i)
#define rrep(i, lo, up) for (ll i = lo; i < up; ++i)
#define rrepp(i, lo, up) for (ll i = lo; i <= up; ++i)

#define rdi(i) ll i; scanf("%lld", &i)
#define rds(s) string s; cin >> s
#define rdc(c) char c; cin >> c

#define INF 10000000000
#define MOD 1000000007

ll gcd(ll a, ll b)
{
    if (a < b) {
        return gcd(b, a);
    }
    ll r;
    while (r = a % b) {
        a = b;
        b = r;
    }
    return b;
}

int main()
{
    ll n, k;
    cin >> n >> k;
    ll result = 0;
    rrepp(i, k, n + 1) {
        result = (result + (n * (n + 1) / 2 - (n - i) * (n - i + 1) / 2) - i * (i - 1) / 2 + 1) % MOD;
    }
    cout << result << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a;
    cin >> a;
    cout << a+ a*a + a*a*a << "\n";
    return 0;
}

Measured memory_bytes: 3640
#include <chrono>
#include <iostream>
#include <random>
#include <vector>

using namespace std;

constexpr int d = 365;
constexpr int t = 26;

int64_t evaluate(const vector<int64_t>& cs, const vector<vector<int64_t>>& ss, vector<int>& state)
{
    int64_t sum = 0;

    vector<int> last(t, -1);

    for (int i = 0; i < d; i++)
    {
        sum += ss[i][state[i]];
        last[state[i]] = i;

        for (int j = 0; j < t; j++)
        {
            sum -= cs[j] * (i - last[j]);
        }
    }

    return sum;
}

void solve(const vector<int64_t>& cs, const vector<vector<int64_t>>& ss, vector<int>& state, mt19937_64& mt)
{
    const auto start = chrono::system_clock::now();

    uniform_int_distribution<int> day_rand(0, d - 1);
    uniform_int_distribution<int> type_rand(0, t - 1);

    auto eval = evaluate(cs, ss, state);

    int counter = 0;
    while (true)
    {
        const int change_pos = day_rand(mt);
        int to_type = type_rand(mt);
        while (state[change_pos] == to_type)
        {
            to_type = type_rand(mt);
        }
        const auto from_type = state[change_pos];
        state[change_pos] = to_type;

        const auto after_eval = evaluate(cs, ss, state);

        if (eval < after_eval)
        {
            eval = after_eval;
        }
        else
        {
            state[change_pos] = from_type;
        }

        if (counter++ % 1000 == 0)
        {
            const auto end = chrono::system_clock::now();
            const auto duration = chrono::duration_cast<chrono::milliseconds>(end - start).count();
            if (duration > 1900)
            {
                break;
            }
        }
    }
}

int main()
{
    {
        int _;
        cin >> _;
    }

    vector<int64_t> cs(d);
    for (auto& c : cs)
    {
        cin >> c;
    }
    vector<vector<int64_t>> ss(d, vector<int64_t>(t));
    for (auto& row : ss)
    {
        for (auto& e : row)
        {
            cin >> e;
        }
    }

    mt19937_64 mt(0);
    uniform_int_distribution<int> rand(0, t - 1);

    vector<int> state(d);
    for (int i = 0; i < d; i++)
    {
        state[i] = rand(mt);
    }

    solve(cs, ss, state, mt);

    for (int i = 0; i < d; i++)
    {
        cout << (state[i] + 1) << endl;
    }
}

Measured memory_bytes: 3268
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

int main() {
    long long n, a, o = 0;
    cin >> n;
    map<int, int> cnt;
    map<int, int> used;
    vector<int> s(n);
    for (int  i = 0; i < n; i++){
        cin >> a;
        cnt[a]++;
        s[i] = a;
    }
    for (int i = 0; i < n; i++){
        if (s[i] < cnt[s[i]] && used[s[i]] < 1){
            o = o + cnt[s[i]] - s[i];
            used[s[i]]++;
        }else if (s[i] != cnt[s[i]] && used[s[i]] < 1){
            o = o + cnt[s[i]];
            used[s[i]]++;
        }
    }
    cout << o << endl;
}

Measured memory_bytes: 9728
using static System.Math;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var x = int.Parse(line[0]);
        var n = int.Parse(line[1]);
        if (n == 0) { Console.WriteLine(x); goto exit; }
        line = Console.ReadLine().Trim().Split(' ');
        var p = Array.ConvertAll(line, int.Parse);
        getAns(x, n, p);
    exit:;
    }
    static void getAns(int x, int n, int[] p)
    {
        var c = new bool[102];
        for (int i = 0; i < n; i++) c[p[i]] = true;
        var r = 0; var L = 0;
        for (int i = x; i <= 101; i++)
            if (!c[i]) { r = i; break; }
        for (int i = x; i >= 0; i--)
            if (!c[i]) { L = i; break; }
        Console.WriteLine(Abs(x - L) <= Abs(x - r) ? L : r);
    }
}


Measured memory_bytes: 27396
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>

using namespace std;
using ll = long long;

int main()
{
	int A, B;
	cin >> A >> B;
	cout << (A >= 13 ? B : (A <= 5 ? 0 : B / 2));
	return 0;
}


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

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

	int n, q;
	string s;
	cin >> n >> q >> s;

	vector <int> sm(n, 0);
	for (int i = 1; i < n; i++) {
		sm[i] = sm[i - 1];
		if (s[i - 1] == 'A' && s[i] == 'C') {
			sm[i]++;
		}
	}

	for (int i = 0; i < q; i++) {
		int l, r;
		cin >> l >> r;
		l--; r--;
		cout << sm[r] - sm[l] << '\n';
	}

	return 0;
}



Measured memory_bytes: 1488
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] a = new int[n][m];
        int[] b = new int[m];
        int[] c = new int[n];
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                a[i][j] = sc.nextInt();
            }
        }
        for(int i=0;i<m;i++){
            b[i] = sc.nextInt();
        }
        sc.close();
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                c[i] = c[i] + a[i][j] * b[j]; 
           }
        }
        for(int i=0;i<n;i++){
            System.out.println(c[i]);
        }
    }
}




Measured memory_bytes: 40352
import java.util.Scanner;
import java.util.Stack;

class Main {

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        System.out.println(Math.max(A * B, C * D));
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;

    // 二次元ベクターの基本
    /*
    vector<vector<int>> dp; // 宣言
    dp.resize(n); // 1次元めの要素数決定
    dp[i].push_back(int); // プッシュバック
    rep(i,n){
        sort(dp[i].begin(),dp[i].end()); // 二次元めで昇順ソート
    }
    */

    // 整数スキャン（複数）
    /*
    int x;
    scanf("%d",&x);
    int y;
    scanf("%d",&y);
    int z;
    scanf("%d",&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s;
    cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s;
        cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    int n[5] = {};
    rep(i,6){
        int x;
        cin >> x;
        n[x]++;
    }

    rep(i,5){
        if(n[i]>2){
            cout << "NO" << endl;
            return 0;
        }
    }

    
    cout << "YES" << endl;
    return 0;
}
 
 


Measured memory_bytes: 256
N, M = list(map(int,input().split()))
a = [False for i in range(N)]
wa = [0 for i in range(N)]
for i in range(M):
  p, s = input().split()
  pi = int(p)-1
  if s=="AC":
      a[pi] = True
  elif not a[pi]:
      wa[pi] += 1
print(sum([1 for ai in a if ai]), sum([wa[i] for i in range(N) if a[i]]))

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

#define UTIDOME 100000000
#define DECIMAL 10

int k;

int main(void){
    cin >> k;
    
    int amariTmp = 7 % k, amari = amariTmp;
    if(amari == 0){
        cout << 1 << endl;
        return 0;
    }
    for (int i = 2; i <= UTIDOME; i++){
        amariTmp = (amariTmp * DECIMAL) % k; 
        amari = (amari + amariTmp) % k;
        if(amari == 0){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}



Measured memory_bytes: 3632
#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 pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
ll n,k;

int main(){
	cin >> n >> k;
	
	ll pos = k;
	REP(i,0,n-1) pos*=(k-1);
	cout << pos << endl;
	return 0;
}


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

int main(int argc, const char * argv[]) {



    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    /////////////////////
    int K,A,B,flug=0;

    cin>>K>>A>>B;

    for(;A<=B;A++){
        if(A%K==0){
            flug=1;
        }
    }
    if(flug==1){
        cout<<"OK"<<endl;
    }
    else{
        cout<<"NG"<<endl;
    }


    return 0;
}


Measured memory_bytes: 3652
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <tuple>
#include <stack>
#include <bitset>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll MAX_X = 1001;
const ll MAX_Y = 1001;
const ll MAX_Z = 1001;
const ll INF = 30000000001;
ll A[MAX_X];
ll B[MAX_Y];
ll C[MAX_Z];
struct Data { ll P; ll i; ll j; ll k; };
vector<Data> v_add;

bool compare(const Data &d1, const Data &d2) {
  return d1.P < d2.P;
}

bool check_add(Data d) {
  for(ll i = 0; i < v_add.size(); i++) {
    if(d.P == v_add[i].P && d.i == v_add[i].i && d.j == v_add[i].j && d.k == v_add[i].k) return true;
  }
  return false;
}

int main() {

  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  ll X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  for(ll i = 0; i < X; i++) cin >> A[i];
  for(ll i = 0; i < Y; i++) cin >> B[i];
  for(ll i = 0; i < Z; i++) cin >> C[i];

  vector<ll> v;
  priority_queue<Data, vector<Data>, decltype(&compare)> pq(compare);
  
  sort(A, A + X, greater<ll>());
  sort(B, B + Y, greater<ll>());
  sort(C, C + Z, greater<ll>());

  Data d;
  d.P = A[0] + B[0] + C[0];
  d.i = 0;
  d.j = 0;
  d.k = 0;
  pq.push(d);
  v_add.push_back(d);

  for(ll i = 0; i < K; i++) {

    Data d = pq.top();
    pq.pop();
    cout << d.P << endl;

    Data newd;
    if(d.i + 1 < X) {
      newd.P = A[d.i + 1] + B[d.j] + C[d.k];
      newd.i = d.i + 1;
      newd.j = d.j;
      newd.k = d.k;
      if(!check_add(newd)) {
	pq.push( newd );
	v_add.push_back(newd);
      }
    }

    if(d.j + 1 < Y) {    
      newd.P = A[d.i] + B[d.j + 1] + C[d.k];
      newd.i = d.i;
      newd.j = d.j + 1;
      newd.k = d.k;
      if(!check_add(newd)) {
	pq.push( newd );
	v_add.push_back(newd);      
      }
    }

    if(d.k + 1 < Z) {    
      newd.P = A[d.i] + B[d.j] + C[d.k + 1];
      newd.i = d.i;
      newd.j = d.j;
      newd.k = d.k + 1;
      if(!check_add(newd)) {
	pq.push( newd );
	v_add.push_back(newd);      
      }
    }
  }
  
  return 0;
}


    


Measured memory_bytes: 3408