akhauriyash/Code-Regression huggingface dataset:
x1, y1, x2, y2 = map(int,input().split())

x3 = x2 - (y2-y1)
x4 = x1 - (y2-y1)
y3 = y2 - (x1-x2)
y4 = y1 - (x1-x2)

print('{0} {1} {2} {3}'.format(x3,y3,x4,y4))

Measured memory_bytes: 2940
package main

import (
	"fmt"
)

func main() {

	var N,A,B int

	fmt.Scan(&N,&A,&B)

	absum := A+B

	result := (N/absum) * A

	if  N%absum < A{

		result += N%absum
	
	}else{

		result += A

	}



	fmt.Println(result)

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string S;
    cin >> S;
    bool flag = true;
    sort(S.begin(),S.end());
    for(int i = 1; i < S.size(); i++){
        if(S.at(i-1) == S.at(i)){
            flag = false;
            break;
        }
    }
    if(flag == true) cout << "yes" << endl;
    else cout << "no" << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long H[] = new long[N];
    for(int i=0;i<N;i++){
      H[i]=sc.nextLong();
    }
    //後ろからどん欲に
    for(int i=N-1;i>0;i--){
      if(H[i-1]-H[i]>=2){
        System.out.println("No");
        return;
      }else if(H[i-1]-H[i]==1){
        H[i-1]=H[i-1]-1;
      }else{
        continue;
      }
    }
    System.out.println("Yes");
  }
  

  
}


Measured memory_bytes: 51036
import math

N, K = map(int, input().split())

prob = 0
for i in range(1, N+1):
    k = math.log2(K/i)
    if k != int(k):
        k = int(k) + 1

    if i >= K:
        prob += 1/N
    else:
        prob += 1/N * (1/2)**k

print(prob)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
int const N = 202000;
char s[N];
deque<int>nex[26];
bool vis[N];
vector<int>ans;
int seg[N*4] , k;
int get(int node , int start , int end){
	if(end < k)return 0;
	if(start >= k)return seg[node];
	int mid = (start+end)/2;
	return get(node*2,start,mid) + get(node*2+1,mid+1,end);
}
int up(int node , int start , int end){
	if(start==end)seg[node] = 1;
	else{
		int mid = (start+end)/2;
		if(mid >= k)up(node*2,start,mid);
		else up(node*2+1,mid+1,end);
		seg[node] = seg[node*2] + seg[node*2+1];
	}
}
int main()
{
	
	scanf("%s",s);
	int len = strlen(s);
	int frq[26];
	memset(frq,0,sizeof frq);
	for(int i = 0 ; i < len ; i++){
		nex[s[i]-'a'].push_back(i);
		frq[s[i]-'a']++;	
	}
	bool odd = 0;
	for(int i = 0 ; i < 26 ; i++){
		if(frq[i]%2==1)if(!odd)odd = 1;else {puts("-1");return 0;}
	}
	string s1 = "";
	int l = 0 , r = len-1;
	ans.resize(len);
	for(int i = 0 ; i < len ; i++){
		if(vis[i])continue;
		if(frq[s[i]-'a']<=1)continue;
		ans[l] = nex[s[i]-'a'].front()+1;
		ans[r] = nex[s[i]-'a'].back()+1;
		vis[ans[r]-1] = 1;
		nex[s[i]-'a'].pop_back();
		nex[s[i]-'a'].pop_front();
		l++;
		r--;
		frq[s[i]-'a']-=2;
	}
	if(odd)for(int i = 0 ; i < 26 ; i++)
		if(frq[i]==1)ans[l] = nex[i].front()+1;
	ll res = 0;	
	for(int i = 0 ; i < len ; i++){
		k = ans[i];
		res += get(1,1,len);
		up(1,1,len);
	}
	printf("%lld\n", res);
	return 0;

}

Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=998244353;

int D,c[26],s[200000][26],t[200000];

int main(){
	cin>>D;
	for(int i=0;i<26;i++){
		cin>>c[i];
	}
	for(int i=0;i<D;i++){
		for(int j=0;j<26;j++){
			cin>>s[i][j];
		}
	}
	for(int i=0;i<D;i++){
		cin>>t[i];
		t[i]--;
	}
	int res=0;
	int l[26];
	for(int i=0;i<26;i++){
		l[i]=-1;
	}
	for(int i=0;i<D;i++){
		l[t[i]]=i;
		res+=s[i][t[i]];
		for(int j=0;j<26;j++){
			res-=c[j]*(i-l[j]);
		}
		cout<<res<<endl;
	}
}


Measured memory_bytes: 3628
using System;
using System.Linq;

class Program {
  static void Main() {
    var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
    var ans = 0;
    for (int i = 0; i < 2; i++) {
      if (a[0] > a[1]) ans += a[0]--;
      else ans += a[1]--;
    }
    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 13396
import sys
sys.setrecursionlimit(10**6)

n = int(input())
g = [[] for _ in range(n)]
color = [-1] * n
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    g[u].append([v, w])
    g[v].append([u, w])


def dfs(u, c):
    color[u] = c
    for v, w in g[u]:
        if color[v] != -1:
            continue
        if w % 2 == 0:
            nc = c
        else:
            nc = 1 - c
        dfs(v, nc)


dfs(0, 0)
for ans in color:
    print(ans)


Measured memory_bytes: 85204
import java.util.Scanner;
import java.util.Arrays;
import java.util.stream.Stream;
import java.util.stream.IntStream;
import java.lang.StringBuilder;

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

    int N = sc.nextInt();

    int[] a = new int[N];

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

    long opCnt = 0;
    for (int i = 0; i < N; i++) {
      int tmp = a[i];
      while(tmp % 2 == 0){
        tmp = tmp / 2;
        opCnt++;
      }
    }

    System.out.println(opCnt);
  }
}


Measured memory_bytes: 37144
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <ctime>
#include <cstring>
using namespace std;

int n;
int way[30];

int main(void){

	cin >> n;
	while(n != 0){

		for(int i = 0; i < n; i++){
			way[i] = 0;
		}
		
		way[0] = 1;
		way[1] = 2;
		way[2] = 4;

		for(int i = 3; i < n; i++){
			way[i] = way[i - 1] + way[i - 2] + way[i - 3];
		}

		double ans = way[n - 1] / 3650.0;

		cout << ceil(ans) << endl;

		cin >> n;
	}

    return 0;
}

Measured memory_bytes: 1236
#include <stdio.h>

int main()
{
  int i, cnt, a, b, c;
  cnt = 0;

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

  for (i = a; i <= b; i++) {
    if ((c % i) == 0) {
      cnt++;
    }
  }

  printf("%d\n", cnt);

  return 0;
}

Measured memory_bytes: 596
N = int(input())
D = list(map(int, input().split()))
# N = 4
# D = [0, 3, 2, 1, 2, 2, 1]

from collections import Counter
import sys

C = Counter(D)

if C[0] != 1:
    print(0)
elif D[0] != 0:
    print(0)
else:
    CL = sorted(C.items())
    num_prev = -1
    val_prev = 1
    ans = 1
    for item in CL:
        num = item[0]
        val = item[1]
        if num != num_prev + 1:
            print(0)
            sys.exit()
        else:
            ans *= val_prev**val
            num_prev = num
            val_prev = val
    print(ans%998244353)

Measured memory_bytes: 92884
//This is the Property of Rishabh Agarwal
#include <bits/stdc++.h> 
#define F first 
#define S second 
#define MAX 10000003 
using namespace std; 
 
typedef long long int ll; 
const ll mod = 1000000007;
ll isPalindrome(string str) 
{ 
    int l = 0; 
    int h = str.length() - 1; 
  
    while (h > l) 
    { 
        if (str[l++] != str[h--]) 
        { 
            return 0; 
        } 
    } 
    return 1;
} 
vector<pair<ll,ll> >f;
vector<ll>v;
int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long double l;
    cin>>l;
    l=(long double)l/(3.000000000000);
    l=l*l*l;
    cout<<setprecision(10)<<l<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
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;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

const string YES = "YES";
const string NO = "NO";

void solve(long long N, std::vector<long long> A){
  set<ll> s;
  REP(N){
    s.insert(A[i]);
  }
  if(s.size()==A.size()){
    cout<<YES<<endl;
  }else{
    cout<<NO<<endl;
  }
}

int main(){
  cout<<setprecision(1000);
  cin.tie(0);
  ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 11264
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  int n,y;
  cin>>n>>y;
  for (int i = 0; i <= n; ++i)
  {
    for (int j = 0; j <= n-i; ++j)
    {
      if(10000*i+5000*j+1000*(n-i-j)==y) 
      {
        cout<<i<<" "<<j<<" "<<n-i-j<<endl;
        return 0;
      }
    }
  }
  cout<<-1<<" "<<-1<<" "<<-1<<endl;
}

Measured memory_bytes: 256
N = int(input())
CSF = [list(map(int, input().split())) for i in range(N-1)]
for i in range(N-1):
    ans = 0
    for j in range(i, N-1):
        C, S, F = CSF[j]
        if ans < S:
            ans = S
        else:
            diff = ans - S
            if diff % F != 0:
                ans += F - (diff % F)
        ans += C
    print(ans)
print(0)


Measured memory_bytes: 43116
import math
import sys
MAX_INT = int(10e9)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
a = IL()
aa = sorted(a)

cnt = 0
for i in range(N):
    if a[i] != aa[i]:
        cnt += 1

if cnt == 2 or cnt == 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)//rep(i,回数){処理}
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
	//入力
	int n, m, k; cin >> n >> m >> k;
	vector<int> a(n);
	vector<int> b(m);
	rep(i, n)cin >> a[i];
	rep(i, m)cin >> b[i];
	//計算
	ll t = 0;
	rep(i, m) t += b[i];
	int j = m; int ans = 0;
	rep(i, n + 1) {
		while (j > 0 && t > k) {
			j=j-1;t=t- b[j];
		}
		if (t > k) { break; }
		ans = max(ans, i + j);
		if (i == n) { break; }
		t = t + a[i];
	}
	//答えを出力
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4744
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

a,b=mp()
print(max(a+b,a-b,a*b))

Measured memory_bytes: 10356
// This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int mod=998244353;

int n,x[222],y[222],pw[222],all[222];
int main()
{
	pw[0]=1;for(int i=1;i<222;i++)pw[i]=pw[i-1]*2%mod;
	get1(n);
	for(int i=1;i<=n;i++)get2(x[i],y[i]);
	int ans=(pw[n]+mod-1)%mod;
	ans=(ans+mod-n)%mod;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			int cnt=0;
			for(int k=1;k<=n;k++)if((x[i]-x[j])*(y[i]-y[k])==(x[i]-x[k])*(y[i]-y[j]))cnt++;
			all[cnt]++;
		}
	}
	for(int i=2;i<=n;i++)
	{
		all[i]=all[i]*2/i/(i-1);
//		printf("i = %d %d\n",i,all[i]);
		ans=(ans+mod-1ll*all[i]*(pw[i]+mod-i-1))%mod;
	}
	printendl(ans);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n,m,a[100][100],b[100],c[100];
    cin >> n >> m;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin >> a[i][j];
        }
    }
    for(int i=0;i<m;i++){
        cin >> b[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            c[i] += a[i][j]*b[j];
        }
    }
    for(int i=0;i<n;i++){
        cout << c[i] << endl;
    }
}


Measured memory_bytes: 3116
n,m,x,y = map(int,input().split())
xi = list(map(int,input().split()))
yi = list(map(int,input().split()))
an = 0
for i in range(x+1,y+1):
    if max(xi) < i <= min(yi):
        an+=1
    
if an > 0:
    print("No War")
else:
    print("War")

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int abs(int a) {
  return (a < 0) ? -a : a;
}

int main() {
  int N;
  int W[100], w;
  int sum = 0, min = 100000;

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> w;
    sum += w;
    W[i] = sum;
  }

  for (int i = 0; i < N; i++) {
    if (abs(2*W[i]-sum) < min) {
      min = abs(2*W[i]-sum);
    }
  }
  cout << min << endl;

  return 0;
}


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

const int NUM = 100;

int main(){
  int x[NUM], y[NUM];

  int num = 0;
  while(true){
    cin >> y[num] >> x[num];

    if(x[num] == 0 && y[num] == 0){
      break;
    }

    ++num;
  }

  int counter = 0;
  for(int i=0;i<num;++i){
    for(int k=0;k<y[i];++k){
      if(k % 2 == 0){
        counter = 0;
      }else{
        counter = 1;
      }     
      for(int l=0;l<x[i];++l){

	
	if(counter % 2 == 0){
	  cout << "#";
	}else {
	  cout << ".";
	}

	++counter;
      }
      
      cout << endl;
    }

    cout  << endl;
  }
  
}



Measured memory_bytes: 3076
#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 repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); 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;

const int MAX_N = 1e5 + 10;
vi es[MAX_N];

ll dp[MAX_N][2];
bool used[MAX_N][2];

ll calc(int cur, int par, bool white) {
    if(used[cur][white]) return dp[cur][white];
    used[cur][white] = true;
    auto& ret = dp[cur][white] = 1LL;
    for(auto&& to : es[cur]) if(to != par) {
        if(white) (ret *= (calc(to, cur, 0) + calc(to, cur, 1))%MOD)%=MOD;
        else (ret *= (calc(to, cur, 1))) %= MOD;
    }
    return ret;
}

int main() {
    int n;
    cin >> n;
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        es[a].pb(b);
        es[b].pb(a);
    }
    cout << (calc(0, -1, 0) + calc(0, -1, 1)) % MOD << endl;
    // rep(i, n) {
    //     cout << i+1 << " " << dp[i][0] << " " << dp[i][1] << endl;
    // }
    return 0;
}

Measured memory_bytes: 15872
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from pprint import pprint
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, A):
    B = [0] * (N + 1)
    bm = Counter()
    bm[0] += 1
    for i in range(1, N+1):
        B[i] = A[i-1] + B[i-1]
        bm[B[i] % M] += 1

    ans = 0
    for v in bm.values():
        if v > 1:
            ans += (v*(v-1))//2

    return ans


def main():
    N, M = read_int_n()
    A = read_int_n()

    print(slv(N, M, A))


if __name__ == '__main__':
    main()


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


int main() {
  string S;
  cin >> S;
  
  vector<int> Color;
  int N = S.size();
  
  rep(i,N){
    int tmp = S.at(i) - 48;
    Color.push_back(tmp);
  }

  //101010...か010101...のどちらか。
  //不一致が少ない方を出力する。
  int ans1 = 0;
  int tmp = 0;
  rep(i,N){
    if(Color.at(i) != tmp) ans1++;
    tmp++;
    tmp %= 2;
  }
  
  int ans2 = 0; 
  tmp = 1;
  rep(i,N){
    if(Color.at(i) != tmp) ans2++;
    tmp++;
    tmp %= 2;
  }
  
  cout << min(ans1,ans2) << endl;
  return 0;
}

Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,ans=0,ma=0,f=0;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    ma=max(ma,a);
    if(ans==0)ans=a;
    else ans=__gcd(ans,a);
    if(a==k)f=1;
  }
  if((k%ans==0&&ma>k)||f)cout<<"POSSIBLE"<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
  return 0;
}


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

int solve(){
  int n;
  string s;
  cin >> n >> s;
  if(n%2!=0){
    cout << "No" << endl;
    return 0;
  }
  
  for(int i=0; i<n/2; i++){
    if(s[i]!=s[i+n/2]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n, k;
    cin >> n >> k;
    vec a(n);
    rep(i, n) cin >> a[i];

    int res = 1;
    n -= k;
    res += (n + k - 2) / (k-1);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#include<time.h>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<(ll)m; i++)
#define FOR(i,n,m) for(long long i=n; i<(ll)m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

class RMQ {
#define RMQ_MAX ((1ll<<60)-1)
public:
	RMQ(int n) {
		_n=1;
		while(_n<n) _n*=2;
		_dat.resize(2*_n-1);
		for(int i=0;i<2*_n-1;++i) _dat[i]=0;
	}
	int size() {
		return _n;
	}
	void update(int k,long long a) {
		k+=_n-1;
		_dat[k]=a;
		while(k>0) {
			k=(k-1)/2;
			_dat[k]=max(_dat[k*2+1],_dat[k*2+2]);
		}
	}
	// return the minimum number in [a,b)
	// external call should be written like query(a,b,0,0,_n)
	ll query(int a,int b,int k=0,int l=0,int r=-1) {
		if(r==-1) r=_n;
		if(r<=a||b<=l) return 0;
		if(a<=l&&r<=b) return _dat[k];
		else {
			ll vl=query(a,b,k*2+1,l,(l+r)/2);
			ll vr=query(a,b,k*2+2,(l+r)/2,r);
			return max(vl,vr);
		}
	}
private:
	int _n;
	vector<ll> _dat;
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,c;
	cin>>n>>c;
	vector<P> z(n);
	REP(i,n) cin>>z[i].first>>z[i].second;
	sort(ALL(z));
	ll ans=0;
	ll buf=0;
	ll pos=0;
	REP(i,n) {
		buf-=z[i].first-pos;
		pos=z[i].first;
		buf+=z[i].second;
		ans=max(ans,buf);
	}
	RMQ rmq(n+10);
	buf=0;
	REP(i,n) {
		buf+=z[n-1-i].second;
		rmq.update(n-1-i,buf-(c-z[n-1-i].first));
	}
	buf=0;
	REP(i,n) {
		buf+=z[i].second;
		ans=max(ans,buf-2*z[i].first+rmq.query(i+1,n+5));
	}
	vector<P> w(n);
	REP(i,n) w[i]=z[n-1-i];
	REP(i,n) w[i].first=c-w[i].first;
	buf=0;
	pos=0;
	REP(i,n) {
		buf-=w[i].first-pos;
		pos=w[i].first;
		buf+=w[i].second;
		ans=max(ans,buf);
	}
	buf=0;
	REP(i,n) {
		buf+=w[n-1-i].second;
		rmq.update(n-1-i,buf-(c-w[n-1-i].first));
	}
	buf=0;
	REP(i,n) {
		buf+=w[i].second;
		ans=max(ans,buf-2*w[i].first+rmq.query(i+1,n+5));
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 5504
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] x = new int[m];
		int[] y = new int[m];
		int[] z = new int[m];
		for (int i = 0; i < m; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
			z[i] = sc.nextInt();
		}
		UnionFind uf = new UnionFind(n);
		for (int i = 0; i < m; i++) {
			uf.unite(x[i] - 1, y[i] - 1);
		}
		TreeSet<Integer> set = new TreeSet<>();
		for (int i = 0; i < n; i++) {
			set.add(uf.find(i));
		}
		System.out.println(set.size());
	}
}
class UnionFind {
	int[] par;
	int[] rank;
	int[] size;

	UnionFind(int n) {
		par = new int[n];
		rank = new int[n];
		size = new int[n];
		for (int i = 0; i < n; i++) {
			par[i] = i;
			rank[i] = 0;
			size[i] = 1;
		}
	}

	int find(int x) {
		if (par[x] == x) {
			return x;
		}
		return par[x] = find(par[x]);
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) {
			return;
		}
		if (rank[x] < rank[y]) {
			par[x] = y;
			size[y] += size[x];
		} else {
			par[y] = x;
			size[x] += size[y];
			if (rank[x] == rank[y]) {
				rank[x]++;
			}
		}
	}

	boolean same(int x, int y) {
		return find(x) == find(y);
	}

	int size(int x) {
		return size[find(x)];
	}
}

Measured memory_bytes: 93696
#include<iostream>
using namespace std;
int main(){

  int x, a, b;

  cin >> x >> a >> b;

  if(b-a<=x && b-a<=0){
    cout << "delicious" << endl;
  }else if(b-a<=x && b-a>0){
    cout << "safe" << endl;
  }else if(b-a>x){
    cout << "dangerous" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> PII;
#define MOD (1000000007ll)

int main(void){
	int n,i,z=0;
	string a,b;
	bool flag = false;
	cin >> a >> b;
	n = a.length();
	for(i=0; i<n; i++){
		z *= 10;
		z += a[i]-'0';
	}
	n = b.length();
	for(i=0; i<n; i++){
		z *= 10;
		z += b[i]-'0';
	}
	for(i=0; i<z; i++){
		if(i*i==z){
			flag = true;
			break;
		}
	}
	cout << ((flag)?"Yes":"No") << endl;
	return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left
N = int(input())
A = list(map(int,input().split()))
A.sort()
n = A.pop()
index = bisect_left(A, n//2)
if index == 0:
    r = A[0]
elif index == N-1:
    r = A[N-2]
else:
    if abs(n//2-A[index]) <= abs(n//2-A[index-1]):
        r = A[index]
    else:
        r = A[index - 1]
print(*[n,r])

Measured memory_bytes: 14056
// Petr's solution.
// http://petr-mitrichev.blogspot.com/2017/07/a-week-with-two-trees.html
#include <bits/stdc++.h>

using namespace std;

vector<vector<int>> treeA, treeB;
vector<bool> visited;
vector<vector<int>> unpaired;
vector<vector<int>> pairs;
vector<int> color;

void visit(int v, int p, vector<vector<int>> &tree) {
  visited[v] = true;
  for (int w : tree[v]) {
    if (!visited[w]) {
      visit(w, v, tree);
    }
  }
  // If this is an odd vertex, add it to the unpaired vector.
  if (!(tree[v].size() & 1)) {
    unpaired[v].push_back(v);
  }
  // Greedy pairing.
  int offset = 0;
  for (int i = 0; i + 1 < (int)unpaired[v].size(); i += 2, offset += 2) {
    int a = unpaired[v][i];
    int b = unpaired[v][i + 1];
    pairs[a].push_back(b);
    pairs[b].push_back(a);
  }
  // If there is a vertex left unpaired, push it to the parent.
  if (p != -1 && offset < (int)unpaired[v].size()) {
    unpaired[p].push_back(unpaired[v][offset]);
  }
}

void bicolor(int v, int c) {
  color[v] = c;
  for (int w : pairs[v]) {
    if (color[w] == -2) {
      bicolor(w, -c);
    }
  }
}

int main() {
  // Reads both trees.
  int n;
  scanf("%d", &n);
  treeA.resize(n);
  treeB.resize(n);
  int rootA, rootB;
  for (int i = 0; i < n; i++) {
    int p;
    scanf("%d", &p);
    if (p != -1) {
      p--;
      treeA[p].push_back(i);
    } else rootA = i;
  }
  for (int i = 0; i < n; i++) {
    int p;
    scanf("%d", &p);
    if (p != -1) {
      p--;
      treeB[p].push_back(i);
    } else rootB = i;
  }

  // Check for impossible case with not matching parities.
  for (int i = 0; i < n; i++) {
    if ((treeA[i].size() & 1) != (treeB[i].size() & 1)) {
      printf("IMPOSSIBLE\n");
      return 0;
    }
  }
  printf("POSSIBLE\n");

  // Pair odd vertices on both trees.
  visited.assign(n, false);
  unpaired.assign(n, vector<int>());
  pairs.resize(n);
  visit(rootA, -1, treeA);
  visited.assign(n, false);
  unpaired.assign(n, vector<int>());
  visit(rootB, -1, treeB);

  // Assign -1 & 1 as a bicoloring.
  color.assign(n, -2);
  for (int i = 0; i < n; i++) {
    if (treeA[i].size() & 1) {
      color[i] = 0;
    } else if (color[i] == -2) {
      bicolor(i, -1);
    }
  }

  //Print the result.
  for (int i = 0; i < n; i++) {
    if (i) printf(" ");
    printf("%d", color[i]);
  }
  printf("\n");
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) cin >> S.at(i);

  set<string> SE;
  for (int i = 0; i < N; i++) SE.insert(S.at(i));

  cout << SE.size() << "\n";
}

Measured memory_bytes: 25168
program abc145f
    implicit none
    integer N,K
    integer,allocatable::H(:)
    integer(16) ans
    integer(16),allocatable::DP(:,:)
    integer i,j,l

    read*,N,K
    allocate(H(0:N),DP(0:N,0:N))
    H(0)=0
    read*,H(1:N)
    DP=huge(dp)/2
    dp(0,0)=0
    do i=1,N
        do j=1,N
            do l=0,i-1
                dp(i,j)=min(dp(i,j),dp(l,j-1)+max(0,H(i)-H(l)))
            end do
        end do
    end do
    ans=huge(ans)
    do i=0,N
        ans=min(ans,dp(i,N-K))
    end do
    print"(i0)",ans
    
end program abc145f

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

int main() {
    int n, k; cin >> n >> k;

    vector<bool> has(n, false);
    while (k--) {
        int d; cin >> d;
        while (d--) {
            int a; cin >> a;
            has[a - 1] = true;
        }
    }

    int ans = 0;
    for (auto e : has) ans += !e;

    cout << ans << endl;
}



Measured memory_bytes: 3604
from collections import defaultdict
d = defaultdict(int)
S=input()
S=S[::-1]
i=1
x=0
MOD=2019
for s in S:
  x+=(int(s)*i)%MOD
  x%=MOD
  d[x]+=1
  i*=10
  i%=MOD
ans=0
for k in d.values():
  ans=ans+k*(k-1)//2
print(ans+d[0])

Measured memory_bytes: 9784
N = int(input())
S = list(map(int, list(input())))
t = {}
for i in range(N):
    t.setdefault(S[i], []).append(i)
ans = 0
for i in range(10):
    if i not in t:
        continue
    ti = t[i][0]
    for j in range(10):
        if j not in t:
            continue
        tj = -1
        for jj in t[j]:
            if ti < jj:
                tj = jj
                break
        else:
            continue
        for k in range(10):
            if k not in t:
                continue
            tk = -1
            for kk in t[k]:
                if tj < kk:
                    ans += 1
                    break
print(ans)

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

 
int main() {
  int N;
  cin >> N;
  VI A(N), B(N);
  REP(i,N) {
    cin >> A.at(i);
  }
  B.at(0) = A.at(0);
  FOR(i,1,N) {
    B.at(0) += pow(-1,i)*A.at(i);
  }
  FOR(i,1,N) {
    B.at(i) = A.at(i-1)*2-B.at(i-1);
  }
  REP(i,N-1) {
    cout << B.at(i) << " ";
  }
  cout << B.at(N-1) << endl;
  return 0;
}

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

int main(void){
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int far = a[0] + k - a[n-1];
    rep(i,n-1){
        far = max(far, a[i+1] - a[i]);
    }
    cout << k - far << endl;
    return 0;
}


Measured memory_bytes: 1024
# AOJ 0612
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0612

castle = []
cmp = []
h = w = 0
left = 0

def initial():
    global h, w, left
    left = h * w
    for i in range(0, h):
        left -= castle[i].count(0)
    for i in range(0, h):
        c = []
        for j in range(0, w):
            if castle[i][j] == 0:
                c.append(-99)
            else:
                a  = castle[i - 1][j - 1:j + 2].count(0)
                a += castle[i][j - 1: j + 2].count(0)
                a += castle[i + 1][j - 1: j + 2].count(0)
                c.append(a)
        cmp.append(c)

def wave(xy):
    global h, w, left
    z = []
    xy1 = []
    for i, j in xy:
        if castle[i][j] > 0 and castle[i][j] <= cmp[i][j]:
            castle[i][j] = 0
            left -= 1
            z.append((i, j))
    for i, j in z:
        cmp[i - 1][j - 1] += 1
        cmp[i - 1][j    ] += 1
        cmp[i - 1][j + 1] += 1
        cmp[i    ][j - 1] += 1
        cmp[i    ][j    ] = -99
        cmp[i    ][j + 1] += 1
        cmp[i + 1][j - 1] += 1
        cmp[i + 1][j    ] += 1
        cmp[i + 1][j + 1] += 1
        y = [(i - 1, j - 1), (i - 1, j), (i - 1, j + 1),
             (i, j - 1), (i, j + 1),
             (i + 1, j - 1), (i + 1, j), (i + 1, j + 1)]
        xy1 += y
    return xy1
        
def solve():
    global h, w, left
    initial()
    p_left = left + 1
    count = 0
    xy = [ (i, j) for j in range(1, w) for i in range(1, h)]
    while True:
        count += 1
        xy1 = wave(xy)
        if p_left == left:
            break
        p_left = left
        xy = xy1
    return count - 1

h, w = map(int, input().split())
for _ in range(0, h):
    c = input().strip()
    castle.append([int(x) if x != '.' else 0 for x in c])
ans = solve()
print(ans)


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

using namespace std;


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

    vector<int> gem;
    vector<int> val;

    int n;
    cin >> n;

    for(int i = 0 ; i < n; ++i)
    {
        int g, v;
        cin >> g;
        gem.push_back(g);
    }

    for(int i = 0 ; i < n; ++i)
    {
        int v;
        cin >> v;
        val.push_back(v);
    }

    int x = 0;
    int y = 0;

    for(int i = 0 ; i < n; ++i)
    {
        if(gem[i] >= val[i])
        {
            x += gem[i];
            y += val[i];
        }
    }

    cout << x - y << endl;

    return 0;
}


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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
using ll = long long;
using pi = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll LINF = 1ll * INF * INF;

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


Measured memory_bytes: 384
// AOJ 2039: Space Coconut Crab II
// 2017.11.6 bal4u@uu
//
// a + b + c = T
// a <= b <= c
// a + b > c

#include <stdio.h>
#include <stdlib.h>
#define TM 0
#if TM
#include <time.h>
#endif

#define MAX  15000
char tbl[MAX+1] = {1,1,0,0};		// zero: if prime
int p[1755] = {						// p[29] = 113 <= sqrt(MAX), max sz = 1754
  2,  3,  5,  7, 11, 13, 17, 19, 23, 29, 
 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 
 73, 79, 83, 89, 97,101,103,107,109,113 }; int sz;
char p2[30001];

void mkprime()
{
	int i, j, k;
	for (i = 0; i <= 29; i++) {
		k = p[i];
		for (j = k<<1; j < MAX; j += k) tbl[j] = 1;
	}
	for (sz = 29, i = 113; i <= MAX; i += 2) if (!tbl[i]) p[sz++] = i;
}

int bsch(int x)
{
	int m, l = 0, r = sz;

    while (l < r) {
        m = (l + r) >> 1;
        if (p[m] <= x) l = m + 1; else r = m;
    }
	return l-1;
}

int main()
{
	int T, i, j, k, m, ans;
#if TM
	clock_t start, end;
	start = clock();
#endif
	mkprime();
	while (scanf("%d", &T) && T > 0) {
		if (!(T & 1)) {			// even T
			k = (T>>1)-1;
			if (k > 2 && !(k & 1)) putchar('0');
			else                   putchar('1' - tbl[k]);
			putchar('\n');
		} else {				// odd T
			ans = 0;
			for (i = 0; ; i++) {
				m = bsch((T-p[i]) >> 1);
				if (m < i) break;
				for (j = i; j <= m; j++) {
					k = p[i] + p[j];
					if (T-k < p[j]) break;
					if (k < T && !tbl[T-k] && (k<<1) > T) ans++;
				}
			}
			printf("%d\n", ans);
		}
	}
#if TM
	end = clock();
	printf("time %lf\n", (double)(end-start)/CLOCKS_PER_SEC);
#endif
	return 0;
}

Measured memory_bytes: 1752
n = int(input())
a = list(map(int, input().split()))

d = dict()
for i in a:
    d[i] = d.get(i, 0) + 1


ans = 0
for i in d.items():
    if i[0] > i[1]:
        ans += i[1]
    elif i[0] < i[1]:
        ans += i[1] - i[0]

print(ans)

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

int main() {
  string s;
  cin >> s;
  string ans = "No";
  sort(s.begin(), s.end());
  if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) {
    ans = "Yes";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

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

    long ans = 0;
    for(int b=1; b<=N; b++){
        int d1 = (N/b)*max(b-K, 0);
        int d2 = max(N%b-K+1, 0);
        ans += d1 + d2;
        if(K == 0)ans--;
    }

    cout << ans << endl;

    return 0;
}


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

int b[25], a[25];

int main() {
  int ans = 0;
  int n, m, c; cin >> n >> m >> c;
  for (int i = 1; i <= m; i++) cin >> b[i];
  for (int j = 1; j <= n; j++) {
    for (int i = 1; i <= m; i++) cin >> a[i];
    int v = 0;
    for (int i = 1; i <= m; i++) v += a[i] * b[i];
    v += c;
    if (v > 0) ans++;
  }
  cout << ans << endl;
}

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

signed main(){
  int N;
  cin>>N;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  sort(v.begin(),v.end());
  int ans=0;
  int ans2=0;
  if(N%2){
    for(int i=0;i<N/2-1;i++)ans-=v[i]*2;
    ans-=v[N/2-1];
    ans-=v[N/2];
    for(int i=N/2+1;i<N;i++)ans+=v[i]*2;
    for(int i=0;i<N/2;i++)ans2-=v[i]*2;
    ans2+=v[N/2];
    ans2+=v[N/2+1];
    for(int i=N/2+2;i<N;i++)ans2+=v[i]*2;
    cout<<max(ans,ans2)<<endl;
  }
  else{
    for(int i=0;i<N/2-1;i++)ans-=v[i]*2;
    ans-=v[N/2-1];
    ans+=v[N/2];
    for(int i=N/2+1;i<N;i++)ans+=v[i]*2;
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 1024
n, y = map(int, input().split())

ans = [-1] * 3
i = 0

while i <= n:
    j = 0
    while j <= n-i:
        if i*10000 + j*5000 + (n-i-j)*1000 == y:
            ans[0] = i
            ans[1] = j
            ans[2] = n-i-j
        j += 1
    i += 1

print(ans[0], ans[1], ans[2])

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


   main(){
  int x;
  int i = 0;
  int n[100]; 
  char s[100];

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
n[i-2] = n[i-1] + n[i-2];
 i = i - 1;
    } else if ( s[0] == '-' ){
n[i-2] = n[i-2] - n[i-1];
 i = i - 1;
    } else if ( s[0] == '*' ){
n[i-2] = n[i-1] * n[i-2];
 i = i - 1;
    } else {
      n[i] = atoi(s);
      i = i + 1;
    }
  }
printf("%d\n",n[i-1]);
  return 0;
}

Measured memory_bytes: 548
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        char[][] mapA = new char[n][n];
        char[][] mapB = new char[n][n];
        for(int i = 0; i < n; i++){
            mapA[i] = sc.next().toCharArray();
        }
        for(int i = 0; i < m; i++){
            mapB[i] = sc.next().toCharArray();
        }
        int len = n-m+1;
        for(int i = 0; i < len; i++){
            for(int j = 0; j < len; j++){
                boolean bool = true;
                for(int k = 0; k < m; k++){
                    for(int l = 0; l < m; l++){
                        if(mapA[i+k][j+l] != mapB[k][l]){
                            bool = false;
                            break;
                        }
                    }
                    if(!bool) break;
                }
                if(bool){
                    System.out.println("Yes");
                    return;
                }
            }
        }
        System.out.println("No");
    }
}


Measured memory_bytes: 22740
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE MagicHash             #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE MultiWayIf            #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}

import           Control.Applicative
import           Control.Exception
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString             as B
import qualified Data.ByteString.Char8       as C
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import qualified Data.Foldable               as F
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import qualified Data.List                   as L
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           GHC.Exts
import           Unsafe.Coerce

main :: IO ()
main = do
    [n, q] <- map read.words <$> getLine :: IO [Int]
    cs <- C.getLine
    lrs <- U.unfoldrN q parseInt2 <$> C.getContents
    putStr.unlines.map show.U.toList $ solve n cs lrs

solve :: Int -> C.ByteString -> U.Vector (Int, Int) -> U.Vector Int
solve n cs lrs = U.map (uncurry query) lrs
  where
    table :: U.Vector Int
    !table = U.scanl' (+) 0 . U.generate n $ \i ->
        if  | i > 0 -> fromEnum $ C.index cs (i - 1) == 'A' && C.index cs i == 'C'
            | otherwise -> 0
    {-# NOINLINE table #-}

    query l r = table U.! r - table U.! l

-------------------------------------------------------------------------------
type Parser a = C.ByteString -> Maybe (a, C.ByteString)

parseInt :: Parser Int
parseInt = C.readInt . C.dropWhile isSpace

parseInt2 :: Parser (Int, Int)
parseInt2 = runStateT $
    (,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)

parseInt3 :: Parser (Int, Int, Int)
parseInt3 = runStateT $
    (,,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)

parseInt4 :: Parser (Int, Int, Int, Int)
parseInt4 = runStateT $
    (,,,) <$> StateT (C.readInt . C.dropWhile isSpace)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)
        <*> StateT (C.readInt . B.unsafeTail)

Measured memory_bytes: 5756
import java.util.*;
public class Main {
	int ans, w,h;
	char [][] data;
	int [] vx = {0,1,0,-1};
	int [] vy = {1,0,-1,0};
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			w = sc.nextInt();
			h = sc.nextInt();
			if((w|h) == 0) break;
			data = new char[h][w];
			int sx = -1, sy = -1;
			for(int i = 0; i < h; i++){
				String s = sc.next();
				for(int j = 0 ; j < w; j++){
					data[i][j] = s.charAt(j);
					if(data[i][j] == '@'){
						data[i][j] = '.';
						sx = j;
						sy = i;
					}
				}
			}
			ans = 0;
			dfs(sx, sy);
			System.out.println(ans);
		}
	}

	private void dfs(int sx, int sy) {
		ans++;
		data[sy][sx] = '*';
		for(int i = 0 ; i < 4; i++){
			int yy = sy + vy[i];
			int xx= sx + vx[i];
			
			if(0 <= yy&& yy < h && 0<= xx && xx < w){
				if(data[yy][xx] == '.'){
					dfs(xx,yy);
				}
			}
		}
		
	}

	private int solvec(int n) {
		int a = n / 500;
		if(n % 500 != 0) a++;
		int aa = a / 3;
		int aaa = a% 3;
		double sum = (double)850 * aa * 3 * 88 / 100 + 850 * aaa;
		return (int)sum;
	}

	private int solveb(int n) {
		int a = n / 300;
		if(n % 300 != 0) a++;
		int aa = a / 4;
		int aaa = a% 4;
		double sum = (double)550 * aa * 4 * 85 / 100 + 550 * aaa;
		return (int)sum;
	}

	private int solvea(int n) {
		int a = n / 200;
		if(n % 200 != 0) a++;
		int aa = a / 5;
		int aaa = a% 5;
		double sum = (double)380 * aa * 5 * 8 / 10 + 380 * aaa;
		return (int)sum;
	}

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

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
lint mod = 1000000007;

int app() {
  int n,k;
  cin>>n>>k;

  lint sum=0;
  rep_range(i,k,n+2){
    sum += ((lint) i)*(n+1-i) +1;
    sum%=mod;
  }
  return sum;
}

int main(){cout<<app()<<endl;return 0;}


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

int main() {
  string s;
  int N, r = 0, b = 0;
  cin >> N >> s;
  for(int i = 0; i < N; i++) {
    if (s.at(i) == 'R') r++;
    else b++;
  }
  if (r > b) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define lld long double
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

lli pre;

typedef struct cake{
	lli a,b,c;

	lli rtn(){
		return a+b+c;
	}
};

bool ope(const cake &l,const cake &r){
	if(DEBUG)cout<<"pre="<<pre<<endl;
	lli i = ((pre&(1LL))==0)?1:-1;
	lli j = ((pre&(1LL<<1))==0)?1:-1;
	lli k = ((pre&(1LL<<2))==0)?1:-1;
	if(DEBUG)cout<<"ohuton"<<endl;
	if(DEBUG)cout<<"i="<<i<<" j="<<j<<" k="<<k<<endl;
	return (i*l.a+j*l.b+k*l.c) < (i*r.a+j*r.b+k*r.c);
}


signed main(){

	lli n,m;
	cin>>n>>m;

	vector<cake> v;
	REP(i,0,n){
		lli x,y,z;
		cin>>x>>y>>z;
		v.push_back({x,y,z});
	}

	lli ans = -INF;
	REP(j,0,8){
		pre = j;
		sort(v.begin(),v.end(),ope);

		if(DEBUG){
			REP(i,0,n)cout<<"i="<<i<<" va="<<v[i].a<<" vb="<<v[i].b<<" vc="<<v[i].c<<endl;
			cout<<endl;
		}

		lli sum = 0;
		lli xSum=0,ySum=0,zSum=0;
		REP(i,0,m){
			xSum += v[i].a;
			ySum += v[i].b;
			zSum += v[i].c;
		}
		ans = max(abs(xSum)+abs(ySum)+abs(zSum),ans);
	}

	cout<<ans<<endl;

	return 0;
}

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

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

int main()
{
    int N;
    cin >> N;
    int d[N];
    repeat(i, N) cin >> d[i];
    int ans = 0;
    repeat(i, N) for (int j = i + 1; j < N; j++){
        ans += d[i] * d[j];
    }
    cout << ans << endl;
}


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

#define _CRT_SECURE_NO_WARNINGS

#define FOR(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1; i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

using namespace std;

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

using LL = long long int;
using LD = long double;

const int INF = (1 << 30) - 1;
const LL INF64 = ((LL)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

using pii = pair<int, int>;
using pll = pair<LL, LL>;
using pdd = pair<double, double>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<LL>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;

int N = 0, E = 0, S = 0, W = 0;

bool check() {
	if (0 < N && S == 0) {
		return false;
	}
	if (0 < S && N == 0) {
		return false;
	}


	if (0 < W && E == 0) {
		return false;
	}
	if (0 < E && W == 0) {
		return false;
	}

	return true;
}

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

	string s;
	cin >> s;

	REP(i, s.size()) {
		if (s[i] == 'N') {
			N++;
		} else if (s[i] == 'E') {
			E++;
		} else if (s[i] == 'S') {
			S++;
		} else {
			W++;
		}
	}

	cout << (check() ? "Yes" : "No") << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    int n;
    string a, b, c;
    cin >> n >> a >> b >> c;

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if(a[i] == b[i] && b[i] == c[i]) continue;
        else if (a[i] == b[i] || b[i] == c[i] || c[i] == a[i]) ++ans;
        else ans += 2;
    }

    cout << ans << endl;
}

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

int main()
{
  int n;

  cin >> n;

  vector<int> h(n);

  int ans = 1;

  rep(i, n)
  {
    cin >> h.at(i);
  }

  int max_h = h.at(0);

  for (int i = 1; i < n; i++)
  {
    max_h = max(max_h, h.at(i));

    // cout << max_h << endl;

    if (max_h == h.at(i))
    {
      ans += 1;
    }
  }

  cout << ans;
}


Measured memory_bytes: 3624