akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

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

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    cin >> N;

    vector<ll> A(N);
    vector<ll> B(N);

    REP(i, N){
        cin >> A[i];
    }
    REP(i, N){
        cin >> B[i];
    }

    ll plus = 0;
    ll minus = 0;
    REP(i, N){
        if(A[i] < B[i]){
            plus += (B[i] -A[i])/2;
        }
        else{
            minus += A[i] - B[i];
        }
    }
    if(plus >= minus){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

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

int main(void){

	int n,k,count = 0;
    cin >> n >> k;

    for(int i = 0; i<n; i++){
        int h;
        cin >> h;

        if(h >= k){
            count++;
        }
    }
    cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
A, B = map(int, input().split())
if A == 1 and B != 1:
    print("Alice")
elif A != 1 and B == 1:
    print("Bob")
elif A == 1 and B == 1:
    print("Draw")
elif A > B:
    print("Alice")
elif A < B:
    print("Bob")
else:
    print("Draw")
    

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
using namespace std;
bool palin(string s)
{
	int i;
	for(i=0;i<s.size();i++)
	{
		if(s[i]!=s[s.size()-i-1])
		{
			return false;
		}
	}
	return true;
}
int main(){
	int n,a,b;
	string s;
	cin>>s;
	n=s.size();
	a=(n-1)/2;
	b=(n+3)/2-1;
	if(palin(s)&&palin(s.substr(0,a))&&palin(s.substr(b)))
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl; 
	}
	return 0;
}

Measured memory_bytes: 256
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cpp,赤波線出るけどコンパイルできる

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll a,b,d,n,maxi=0,f=0,mini=INF,sum=0;
    ll w=0,h,x,y,k;
    //string str[3];
    string str;
    ll e=0;
    ll m;
	cin>>n>>m;
    sum+=m*1900;
    sum+=(n-m)*100;
    sum*=pow(2,m);
    cout<<sum<<endl;

    return 0;
}



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

int main() {
	int n, a;
	long min, max, sum;
	min =1000000;
	max =-1000000; 
	sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
        {
		cin >> a;
		if (min >a)
                 min = a;
		if (max < a)
                max = a;
		sum = a + sum;
	}
	cout << min << " " << max << " " << sum << endl;
	return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(void)
{
  int a, b;
  cin >> a >> b;
  double x = double(a) / double(b);
  cout << a / b << ' ' << a % b << ' ';
  cout << fixed << setprecision(5) << x << endl;
  return 0;
}



Measured memory_bytes: 3264
#include<stdio.h>

main(){
    int k,n,l[50],buf;
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%d[i]",&l[i]);
    }    
    
    
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            if(l[i] < l[j]){
                buf = l[j];
                l[j] = l[i];
                l[i] = buf;
            }
        }

    }
    buf=0;
    for(int i=0;i<k;i++){
        buf = buf + l[i];
    }   
    printf("%d",buf);
}

Measured memory_bytes: 128
def countnum(n):
    count = 0
    for val in range(1,n+1):
        if n % val == 0:
            count += 1
    return count

N = int(input())
count = 0
for v in range(1, N+1):
    if (v % 2 == 1) and (countnum(v) == 8):
        count += 1

print(count)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;
long long cnt[100010] = {};
int main(){
    long long i,n,q; cin >> n;
    for(i=0;i<n;i++){
        int a; cin >> a; cnt[a]++;
    }
    cin >> q;
    long long ans = 0;
    for(i=0;i<=100000;i++){
        ans += i*cnt[i];
    }
    for(i=0;i<q;i++){
        long long b,c; cin >> b >> c;
        ans = ans + (c - b)*cnt[b];
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << ans << endl;
    }
}

Measured memory_bytes: 4400
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    a = LI()

    return JA(a[2:] + a[:2], " ")


print(main())





Measured memory_bytes: 5584
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int k = Integer.parseInt(sc.next());

        // 主処理
        int[] array = new int[] { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4,
                1, 4, 1, 51 };
        int result = array[k - 1];

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 21716
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int n, read_value;
	static int[] generation;;
	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}
	static boolean read(){
		n = sc.nextInt();
		if(n == 0)
			return false;
		generation = new int[7];
		for(int i = 0; i < n; i++){
			read_value = sc.nextInt();
			if(read_value < 10){
				generation[0]++;
			}else if(read_value < 20){
				generation[1]++;
			}else if(read_value < 30){
				generation[2]++;
			}else if(read_value < 40){
				generation[3]++;
			}else if(read_value < 50){
				generation[4]++;
			}else if(read_value < 60){
				generation[5]++;
			}else{
				generation[6]++;
			}
		}
		return true;
	}
	static void solve(){
		for(int i = 0; i < 7; i++)
			System.out.println(generation[i]);
	}
}

Measured memory_bytes: 13000
#include <stdio.h>
#include <algorithm>

using namespace std;

int table[2001][2001];

int main(){
  for(int i=0; i < 2001; i++){
    for(int j=0; j < 2001; j++){
      table[i][j] = 0;      
    }
  }

  int N, K;
  scanf("%d %d\n", &N, &K);
  int stars = 0;
  for(int i=0; i < N; i++){
    int x, y;
    char b;
    scanf("%d %d %c\n", &x, &y, &b);
    //        printf("%d %d %c", x, y, b);
    if(b == 'W'){
      x += K; /* 白は等価な黒に */
    }
    x = x % (2*K);
    y = y % (2*K);
    //    printf("%d %d\n", x, y);
    for(int yoko=y+1; yoko <= 2*K; yoko++){
      table[x][yoko] += 1;
    }
    /* tate[x][yoko]でx列で，yoko番目に横の線を入れたときにそこから上の希望の数を数える */

    if((0 <= x && x < K && 0 <= y && y < K) || (K <= x && x < 2*K && K <= y && y < 2*K)){
      stars++;
    }
  }

  // printf("----\n");
  // for(int y=0; y <= 2*K; y++){
  //   for(int x=0; x < 2*K; x++){
  //     printf("%d", table[x][y]);
  //   }
  //   printf("\n");
  // }
  // printf("----\n");

  int max_now = stars;
  //  printf("stars: %d\n", max_now);
  for(int yoko=0; yoko < K; yoko++){
    stars = 0;
    for(int x=0; x < K; x++){
      stars += table[(x+K)%(2*K)][yoko] + (table[x][yoko+K] - table[x][yoko]) + (table[(x+K)%(2*K)][2*K] - table[(x+K)%(2*K)][yoko+K]);
    }
    for(int tate=1; tate <= 2*K; tate++){
      /* tateとyokoの交点から左下が黒だとする */
      int top_incr = table[(tate-1) % (2*K)][yoko];
      int top_decr = table[(tate-1+K) % (2*K)][yoko];
      int mid_incr = table[(tate-1+K) % (2*K)][yoko+K] - table[(tate-1+K) % (2*K)][yoko];
      int mid_decr = table[(tate-1) % (2*K)][yoko+K] - table[(tate-1) % (2*K)][yoko];
      int bot_incr = table[(tate-1) % (2*K)][2*K] - table[(tate-1) % (2*K)][yoko+K];
      int bot_decr = table[(tate-1+K) % (2*K)][2*K] - table[(tate-1+K) % (2*K)][yoko+K];

      stars = stars + top_incr + mid_incr + bot_incr - top_decr - mid_decr - bot_decr;
      max_now = max(stars, max_now);
      //      printf("*%d, %d, %d, %d, %d, %d\n", top_incr, mid_incr, bot_incr, top_decr, mid_decr, bot_decr);
      //      printf("%d %d %d\n", tate, yoko, stars);
    }
  }
  printf("%d\n", max_now);

  return 0;
}


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

#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 foreach(it, v) for(typeof(v.begin()) it=v.begin(); it!=v.end(); ++it)
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second

typedef unsigned int uint;
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef set<int> si;

int  H, W;
int N, sr, sc;
string S, T;

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

  cin >> H >> W >> N;
  cin >> sr >> sc;
  cin >> S >> T;

  int l, r;
  l = 1; r = W;
  drep(i, N) {
    if (T[i] == 'L') r = min(r+1, W);
    else if (T[i] == 'R') l = max(l-1, 1);
    if (S[i] == 'L') l = l+1;
    else if (S[i] == 'R') r = r-1;
    if (l > r) {
      cout << "NO\n";
      return 0;
    }
  }
  if (sc < l || r < sc) {
    cout << "NO\n";
    return 0;
  }


  l = 1; r = H;
  drep(i, N) {
    if (T[i] == 'U') r = min(r+1, H);
    else if (T[i] == 'D') l = max(l-1, 1);
    if (S[i] == 'U') l = l+1;
    else if (S[i] == 'D') r = r-1;
    if (l > r) {
      cout << "NO\n";
      return 0;
    }
  }
  if (sr < l || r < sr) {
    cout << "NO\n";
    return 0;
  }

  cout << "YES\n";
  return 0;
}


Measured memory_bytes: 920
//Author: AnandRaj uux
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define forn(i,f,n) for(int i=f;i<f+n;i++)
#define rforn(i,l,n) for(int i=l;i>l-n;i--)
#define all(v) v.begin(),v.end()
#define prin(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int i=f;i<f+n;i++) cin>>V[i]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "

const int MOD = 1e9+7,MAX = 1e5+5;
/////////////////FastExp///////////////////
ll powN(ll a,ll p)
{
	if(p==0) return 1;
	ll z=powN(a,p/2);
	z=(z*z)%MOD;
	if(p%2) z=(z*a)%MOD;
	return z;
}
/////////////////FastExp///////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX+1, true);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
        	for (j = i * i; j <= MAX; j += i)
            	is_prime[j] = false;
    	}
	}
}
//////////////////Sieve////////////////////

int main()
{
	int k,n;
	cin>>k>>n;
	vi A(n);
	take(A,0,n);
	int gap=0;
	for(int i=0;i<n-1;i++)
	{
		gap=max(gap,A[i+1]-A[i]);
		//cout<<gap<<endl;
	}
	gap=max(gap,k-A[n-1]+A[0]);
	cout<<k-gap<<endl;
}		

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define oo 0x3f3f3f3f

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    vector<int>A(n);
    for(int&x:A)cin>>x;
    sort(A.rbegin(),A.rend());

    ll sum = A[0];
    int left = n-2;

    for(int i=1; i<n && left > 0; i++)
        for(int j=0; j<2 && left > 0; j++)
            sum+=A[i],left--;
    cout<<sum;
}


Measured memory_bytes: 3988
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func stringsFiledsToInts() []int {
	sc.Scan()
	r := []int{}
	ss := strings.Fields(sc.Text())
	for _, s := range ss {
		i, e := strconv.Atoi(s)
		if e != nil {
			panic(e)
		}
		r = append(r, i)
	}
	return r
}

func main() {
	inputs := stringsFiledsToInts()
	A := inputs[0]
	B := inputs[1]

	fmt.Print(A * B)
}


Measured memory_bytes: 1756
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define MAX_N 10000000
#define ll longlong
using namespace std;
int main() {
    string s;
    cin>>s;
    if(s=="Sunny")
    cout<<"Cloudy"<<endl;
    else if(s=="Cloudy")
    cout<<"Rainy"<<endl;
    else if(s=="Rainy")
    cout<<"Sunny"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int Stack[110];

int sp = 0;

int main() {
	int N;
	while (1) {
		if (scanf("%d", &N) == EOF)break;
		if (N) {
			Stack[sp] = N;
			sp++;
		}
		else {
			sp--;
			printf("%d\n", Stack[sp]);
		}
	}


	return 0;
}


Measured memory_bytes: 1976
#include <stdio.h>
#include <math.h>

int main(void)
{
    int H, W;
    int h, w;
    int dia;
    int min_h, min_w, min_dia;
    
    while (1){
        scanf("%d%d", &H, &W);
        if (H == 0 && W == 0){
            break;
        }
        
        dia = H * H + W * W;
        
        min_h = min_w = 150;
        min_dia = min_h * min_h + min_w * min_w;
        
        h = 1;
        w = sqrt(dia);
        
        while (h < w){
            while ((dia > (h * h + w * w)) ||
                   (dia == (h * h + w * w)) && (h < H)){
                w++;
            }

//printf("<%d %d>\n", h, w);

            while (dia < (h * h + w * w) ||
                (dia == (h * h + w * w)) && h > H){
                w--;
            }
            w++;
            if (h >= w){
                w = h + 1;
            }

//printf("[%d %d]\n", h, w);

            
            if (min_dia > (h * h + w * w)){
                min_h = h;
                min_w = w;
                min_dia = min_h * min_h + min_w * min_w;
            }
            else if (min_dia == (h * h + w * w) && (h < min_h)){
                min_h = h;
                min_w = w;
                min_dia = min_h * min_h + min_w * min_w;
            }
//printf("<<%d %d>>\n", min_h, min_w);
            h++;
        }
        printf("%d %d\n", min_h, min_w);
    }
    return (0);
}

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

int main() {
  int a, b, k; cin >> a >> b >> k;
  if (b - a + 1 <= 2 * k) {
    for (int i = a; i <= b; ++i) cout << i << endl;
  }
  else {
    for (int i = a; i <= a + k - 1; ++i) cout << i << endl;
    for (int i = b - k + 1; i <= b; ++i) cout << i << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  int N; cin >> N;
  vi b(N), ans;
  bool ok = true;
  for (int i = 0; i < N; i++) {
    cin >> b[i];
    if (b[i] > i+1) ok = false;
  }
  if (!ok) {
    cout << "-1" << endl;
    return 0;
  }
  while (ans.size() < N) {
    for (int i = N-1; i >= 0; i--) {
      if (b[i] == 0) continue;
      int cnt = 0;
      for (int j = 0; j < i; j++) {
        if (b[j] == 0) cnt++;
      }
      int num = i - cnt + 1;
      // printf("i = %d, b[i] = %d, cnt = %d\n", i+1, b[i], cnt);
      if (b[i] == num) {
        ans.pb(num);
        b[i] = 0;
        break;
      }
    }
  }
  reverse(ans.begin(), ans.end());
  for (int i = 0; i < N; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] strArray = br.readLine().split("\\s");
        Integer[] intArray;
        intArray = new Integer[strArray.length];
        String strComp = null;
        for (int i = 0; i < strArray.length; i++) {
            intArray[i] = Integer.valueOf(strArray[i]);
        }
        switch (intArray[0].compareTo(intArray[1])) {
            case 1:
                strComp = ">";
                break;
            case -1:
                strComp = "<";
                break;
            case 0:
                strComp = "==";
                break;
        }
        System.out.println("a " + strComp + " b");
    }
}

Measured memory_bytes: 17092
# -*- coding: utf-8 -*-

# input
N, M, X = map(int, input().split())
A = list(map(int, input().split()))

# solve
cost = [0] * (N + 1)
for i in range(M):
    cost[A[i]] = 1

# output
print(min(sum(cost[:X]), sum(cost[X + 1:])))


Measured memory_bytes: 3060
#include <cstdio>
#include <set>

using namespace std;

long long n;

bool test(long long n, long long k) {
  while (n >= k) {
    if (n%k == 0) n /= k;
    else n %= k;
  }
  return n == 1;
}

long long extgcd(long long a, long long b, long long&x, long long& y) {
  long long d = a;
  if (b != 0) {
    d = extgcd(b, a%b, y, x);
    y -= (a / b) * x;
  } else {
    x = 1;
    y = 0;
  }
  return d;
}

int main(void) {
  scanf("%lld", &n);
  if (n == 2) {
    puts("1");
    return 0;
  }

  long long res = 0;
  set<long long>ss;
  for (long long i = 2; i * i <= n; i++) {
    if (test(n, i)) {
      long long x, y;
      extgcd(n, i, x, y);
      // printf("%lld %lld %lld\n", i, x, y);
      if (y != 1) {
        ss.insert(-y);
      }
      ss.insert(i);
      res += 1;
    }
  }
  // printf("res1: %zd\n", ss.size() + 2);
  printf("%zd\n", ss.size() + 2);

  /*
  long long res2 = 0;
  for (long long i = 2; i <= n; i++) {
    if (test(n, i)) {
      printf("%lld\n", i);
      res2 += 1;
    }
  }
  printf("res2: %lld\n", res2);
  */
  return 0;
}


Measured memory_bytes: 256
N,M,X,Y = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int,input().split()))
xmax = max(x)
ymin = min(y)
if xmax<ymin and X<ymin and xmax<Y:
    print("No War")
else:
    print("War")

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

bool isSame(string s){
    if(s[0] != '.')
        return false;
    for(int i=0;i<s.size()-1;i++){
        if(s[i] != s[i+1])
            return false;
    }
    return true;
}

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

    int h, w;
    cin >> h >> w;
    string str[h];
    vector <bool> row(h, false);
    vector <bool> col(w, false);

    for(int i=0;i<h;i++){
        cin >> str[i];
        if(isSame(str[i]))
            row[i] = true;
    }

    for(int i=0;i<w;i++){
        string s;
        for(int j=0;j<h;j++){
            s+=str[j][i];
        }
        if(isSame(s)){
            col[i] = true;
        }
    }
    for(int i=0;i<h;i++){
        string s;
        for(int j=0;j<w;j++){
            if(!row[i] && !col[j]){
                s+=str[i][j];
                cout << str[i][j];
            }
        }
        if(!row[i])
            cout << '\n';
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main(){
  int n, a;
  cin >> n >> a;
  //if(pow(x,a)<pow(x,b)){cout<<'A'<<endl;}
  //else{cout<<'B'<<endl;}
  cout << n*n-a << endl;
  return 0;
}

Measured memory_bytes: 256
while True:
    n = int(input())
    if n == 0: break
    table = []
    for _ in range(n):
        num = list(map(int, input().split()))
        num.append(sum(num))
        table.append(num)
    vertical = []
    for t in zip(*table):
        vertical.append(sum(t))
    table.append(vertical)
    for tab in table:
        for t in tab:
            print('{:>5d}'.format(t), end='')
        print()



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

#define rip(i,n,s) for (int i=(s);i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
typedef long long ll;

int main(){
    int n,w;
    cin >> n >> w;
    vector<pair<double,int> > da(n);
    vector<int> g(n);
    int W,v;
    rip(i,n,0){
        cin >> v >> W;
        g[i]=W;
        da[i].first=(double)v/W;
        da[i].second=i;
    }
    sort(all(da));
    reverse(all(da));
    int now=0;
    double ans=0;
    while(w>0 && now<n){
        if(g[da[now].second]<w){
            ans+=(double)da[now].first*g[da[now].second];
            w-=g[da[now].second];
        }
        else{
            ans+=(double)da[now].first*w;
            w=0;
        }
        now++;
    }
    printf("%.7f\n",ans);
}


Measured memory_bytes: 4676
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using i64 = int64_t;

int main() {
    string s, t;
    cin >> s;
    s.insert(0, "a"); s.push_back('a');
    const int N = s.size();
    vector<int> v(N, 0);
    for (int j = 0; j < s.size(); ++j) {
        if (s[j] != 'x') {
            v[j] = 1;
            t.push_back(s[j]);
        }
    }
    const int M = t.size();

    for (int j = 1; j < N; ++j) v[j] += v[j-1];

    bool pal = true;
    for (int j = 0; j < M/2; ++j) {
        if (t[j] != t[M-1-j]) {
            pal = false; break;
        }
    }

    if (!pal) {
        cout << -1 << endl;
        return 0;
    }

    int l = lower_bound(begin(v), end(v), (M+1)/2) - begin(v);
    int r = lower_bound(begin(v), end(v), M/2+1) - begin(v);

    int ans = 0;
    while (l > 0 && r < N-1) {
        int nl = lower_bound(begin(v), end(v), v[l]-1) - begin(v);
        int nr = lower_bound(begin(v), end(v), v[r]+1) - begin(v);

        ans += abs(abs(l - nl) - abs(nr - r));
        l = nl; r = nr;
    }
    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 1088
using System;
using System.IO;
using System.Collections.Generic;
using System.Numerics;

namespace abc138
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            solve_abc138A();
        }

        public static void solve_abc138A()
        {
            int a = Convert.ToInt32(Console.ReadLine());
            string s = Console.ReadLine();

            Console.WriteLine(a >= 3200 ? s : "red");
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t X;
  cin >> X;
  int64_t x,y,z;
  x = X/500LL;
  y = (X - 500LL * x)/5LL;
  int64_t happy;
  happy = 1000LL * x + 5LL * y;
  cout << happy << endl;
}

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


 struct Point {double x,y;};

void koch(int,struct Point,struct Point);
int main(){
 struct Point p1,p2;
  int n;

  scanf("%d",&n);
  p1.x=0;
  p1.y=0;
  p2.x=100;
  p2.y=0;

  printf("%.8f %.8f\n",p1.x,p1.y);
  koch(n,p1,p2);
  printf("%.8f %.8f\n",p2.x,p2.y);

  
  return 0;
}
void koch(int n,struct Point p1,struct Point p2){
 struct Point s,u,t;
  double th=M_PI * 60.0/180.0;
  if(n==0)return;
  s.x=(2*p1.x+p2.x)/3.0;
  s.y=(2*p1.y+p2.y)/3.0;
  t.x=(p1.x+2*p2.x)/3.0;
  t.y=(p1.y+2*p2.y)/3.0;
  u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
  u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;

  koch(n-1,p1,s);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%.8f %.8f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%.8f %.8f\n",t.x,t.y);
  koch(n-1,t,p2);
}



Measured memory_bytes: 2732
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  string s;
  cin >> s;
  if(s.at(2) == s.at(3) && s.at(4) == s.at(5)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import numpy as np
import itertools as ittr

def test_switch(e_balls, sw, p):
    for i, e_ball in enumerate(e_balls):
        eb = np.asarray(e_ball)
        si = sw[eb - 1]
        
        if p[i] != (np.sum(si == 1) % 2):
            return False
    
    return True

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

e_balls = []

for m in range(M):
    i = input().split()
    s = [int(si) for si in i[1:]]
    e_balls.append(s[:])

p = [int(pi) for pi in input().split()]

cnt = 0

for sw in ittr.product([0, 1], repeat = N):
    if test_switch(e_balls, np.array(sw), p):
        cnt += 1

print(cnt)

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

int main(void){
  int a[1001], b[1001];
  int n,m;
  
  cin >> n;
  for (int i=0; i<n; i++) cin >> a[i];
  cin >> m;
  for (int i=0; i<m; i++) cin >> b[i];
  a[n] = b[m] = -1; // 番兵
  for (int i=0; true; i++){
    if (a[i]==-1 && b[i]==-1){ // A = B
      cout << 0 << endl; break;
    } else if (a[i]<b[i]){
      cout << 1 << endl; break;
    } else if (a[i]>b[i]){
      cout << 0 << endl; break;
    }
  }
  return 0;
}
  
  



Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define all(v) v.begin(),v.end()
#define PI acos(-1)
#define EPS 1e-15


int main() {
	int n;
	cin >> n;
	int a;
	cin >> a;
	cout << n*n - a << endl;
	return 0;
}





Measured memory_bytes: 256
n = int(input())
t = 2*n
a = int(t**0.5)
if a*(a+1) != t:
    print("No")
    exit()

print("Yes")
print(a+1)
count = [0]*n
ans = [[] for i in range(a+1)]
now = a
p = [0]*(a+1)
for i in range(a):
    ans[i].append(i+1)
    ans[i+1].append(i+1)
    count[i] += 2
for i in range(a+1):
    if i >= 2:
        for j in range(i-1):
            while count[ans[j][p[j]]-1] ==2:
                p[j] += 1
            x = ans[j][p[j]]
            ans[i].append(x)
            count[x-1] +=1
        x = len(ans[i])
        for j in range(a-x):
            ans[i].append(now+1)
            count[now]+=1
            now += 1
    else:
        x = len(ans[i])
        for j in range(a-x):
            ans[i].append(now+1)
            count[now]+=1
            now += 1
    
for i in range(a+1):
    print(a,*ans[i])


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

int main(){
	int N;
	cin >> N;
	vector<ll> A(N), A1(N);
	for (int i = 0;i < N;i++) {
		cin >> A[i];
		A1[i] = A[i];
	}

	//最初に負
	ll neg = 0;
	for (int i = 0;i < N;) {
		if (A1[i] >= 0) {
			neg += A1[i] + 1;
			A1[i] = -1;
		}
		i++;
		if (i == N)break;
		A1[i] += A1[i - 1];
		if (A1[i] <= 0) {
			neg += 1 - A1[i];
			A1[i] = 1;
		}
		i++;
		if (i == N)break;
		A1[i] += A1[i - 1];
	}

	//最初に正
	ll pos = 0;
	for (int i = 0;i < N;) {
		if (A[i] <= 0) {
			pos += 1 - A[i];
			A[i] = 1;
		}
		i++;
		if (i == N)break;
		A[i] += A[i - 1];
		if (A[i] >= 0) {
			pos += A[i] + 1;
			A[i] = -1;
		}
		i++;
		if (i == N)break;
		A[i] += A[i - 1];
	}
	cout << min(pos, neg) << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LL long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
//
int main(){
  int N;
  int A[100];
  cin>>N;
  FOR(i,0,N){
    cin>>A[i];
  }
  bool F=true;
  int ans=0;
  while(F){
    F=false;
    ROF(i,1,N){
      if(A[i]<A[i-1]){
        swap(A[i],A[i-1]);
        ans++;
        F=true;
      }
    }
  }
  FOR(i,0,N){
    if(i!=0){
      cout<<" ";
    }
    cout<<A[i];
  }
  cout<<endl;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
int h,d;
int main()
{
	cin>>h>>d;
	if(h%d==0)
	{
		cout<<h/d<<endl;
		return 0;
	}
	else 
	{
		cout<<h/d+1<<endl;
		return 0;
	}
	return 0;
 } 

Measured memory_bytes: 256
//
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define maxnn 500000
ll a[maxnn],n;
ll sum1[maxnn];
ll sum2[maxnn];
ll ans=10000000000000;
void   isok()
{
	int fla=0;
	ll tmp=0;
	ll tmpp=ans+10000000;
	for(int i=1;i<n;i++)
	{
		tmp=0;
		{
			tmp=abs(sum1[i]-sum2[i]);
			tmpp=min(tmpp,tmp);
			continue;
		}
	}
	if(ans>tmpp) {fla=1;ans=tmpp;}

}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=n;i++)
	{
		sum1[i]=sum1[i-1]+a[i];	
	}
	for(int i=n;i>=1;i--)
	{
	
		sum2[i]=sum2[i+1]+a[i];
	
	}
	for(int i=n;i>=1;i--)
	{
		sum2[i]-=a[i];
	}
	isok();
	cout<<ans;
}

Measured memory_bytes: 9984
#include<stdio.h>
int main(void)
{
	int a[3],b,c,d[9999],X;
	for(;;)
	{
		scanf("%d %d %d",&a[0],&a[1],&a[2]);
		if(a[0]==0&&a[1]==0&&a[2]==0)
			break;
		if(a[0]>=a[1]&&a[0]>=a[2])
			X=a[1]*a[1]+a[2]*a[2];
		else if(a[1]>=a[0]&&a[1]>=a[2])
			X=a[0]*a[0]+a[2]*a[2];
		else
			X=a[0]*a[0]+a[1]*a[1];
		scanf("%d",&b);
		for(c=0;c<b;c++)
			scanf("%d",&d[c]);
		for(c=0;c<b;c++)
			if(d[c]*d[c]*4>X)
				printf("OK\n");
			else
				printf("NA\n");		
	}
	return 0;
}

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

int main()
{
    int n;
    cin>>n;
    int p,m,x,r,T[n];

    for(int i=0;i<n;i++)
    {
        cin>>T[i];
    }
    cin>>m;
    for(int i=0;i<m;i++)
    {
        int sum=0;
        cin>>p>>x;
        r=T[p-1];
        T[p-1]=x;

        for(int j=0;j<n;j++)
        {
            sum+=T[j];
        }
        cout<<sum<<endl;
        T[p-1]=r;
    }
}



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

int main() {
  string s;
  long n;
  cin >> n;
  cin >> s;
  char c;
  for(long i=0; i<s.length(); i++){
  	c = (char)s[i];
  	c+=n;
    if(c>'Z') c-=26;
  	s[i] = c;
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>

using namespace std;


int GetMaximumDifference(const int*Array, const int Num) {
	int min = *Array;
	int max = *(Array + 1) - min;

	for (int i = 1; i < Num; i++) {
		if (max < *(Array + i) - min)max = *(Array + i) - min;
		if (min > *(Array + i))min = *(Array + i);
	}
	return max;
}

int main() {
	int n;
	int R[200000];

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> R[i];
	}

	cout << GetMaximumDifference(R, n) << endl;

	return 0;
}

Measured memory_bytes: 1940
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)

def main():
    N = cin.int()
    info = cin.intListList(N)
    X,Y,H = [0,0,0]
    for i in info:
        if i[2] > 0:
            X = i[0]
            Y = i[1]
            H = i[2]
    for x in range(101):
        for y in range(101):
            h = abs(x - X) + abs(y - Y) + H
            if h > 0:
                ok = True
                for i in range(N):
                    a = max(0,h - abs(x - info[i][0]) - abs(y - info[i][1]))
                    if info[i][2] != a:
                        ok = False
                if ok:
                    print("{} {} {}".format(x,y,h))
                    return
if __name__ == "__main__":
    main()


Measured memory_bytes: 43888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define repr(i, a, n) for (ll i = n - 1; (ll)a <= i; i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 + 99);
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
template <typename T, typename U>
void chmin(T &t, const U &u)
{
   if (t > u)
      t = u;
}
template <typename T, typename U>
void chmax(T &t, const U &u)
{
   if (t < u)
      t = u;
}
template <typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T>
T mpow(T a, T n)
{
   T res = 1;
   for (; n; n >>= 1)
   {
      if (n & 1)
         res = res * a;
      a = a * a;
   }
   return res;
}

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

signed main()
{
   ll n, k;
   cin >> n >> k;
   vector<ll> a(n), f(n);
   rep(i, 0, n) cin >> a[i];
   sort(all(a));

   rep(i, 0, n) cin >> f[i];
   sort(all(f));
   reverse(all(f));

   ll ng = -1, ok = LINF;

   while (abs(ok - ng) > 1)
   {
      ll mid = (ok + ng) / 2;

      ll mon=k;
      rep(i,0,n){
         if(a[i]*f[i]>mid)mon-=(a[i]*f[i]-mid+f[i]-1)/f[i];
      }
      if (mon>=0)
         ok = mid;
      else
         ng = mid;
   }

   cout << ok << endl;
}

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

int main(){
    int n,ans = 0;
    cin >> n;
    vector<int> p(n);
    for(int i = 0;i < n;i ++){
        cin >> p[i];
    }
    for(int i = 0;i < n-2;i ++){
        if((p[i]<p[i+1] && p[i+1]<p[i+2]) || (p[i]>p[i+1] && p[i+1]>p[i+2])) ans ++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const ll mod = 1e9+7;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }




int main()
{
 
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	
	VI a(n);
	rep(i, n) cin >>a[i];
	
	int rx = max_element(all(a)) - a.begin();
	int rn = min_element(all(a)) - a.begin();
	vector<pii> ans;
	
	if(!(a[rn] >=0 || a[rx] <=0)){
		if(abs( a[rx]) >= abs(a[rn])){
			rep(i, n) if(a[i] < 0){
				a[i] += a[rx]; 
				ans.emplace_back(rx, i);
			}
		}else{
			rep(i, n) if(a[i] > 0){
				a[i] += a[rn]; 
				ans.emplace_back(rn, i);
			}
		}
	}

	if(accumulate(all(a), 0LL)>0){
		rep(i, n-1){
			ans.emplace_back(i, i+1);
			a[i+1] +=a[i];
		}
	}else{
		repr(i, n-1, 1){
			ans.emplace_back(i,i-1);
			a[i-1] +=a[i];
		}
	
	}
	
	//for(auto x :a) printf("%d, ",x); puts("end");
	cout << sz(ans) <<"\n";
	for(auto x:ans) cout <<x.first+1 <<" "<<x.second+1<<"\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
long long n,arr1[10000000],arr2[10000000];
int main(){
	scanf("%ld",&n);
	for(int i=0;i<n+1;i++){
		scanf("%ld",&arr1[i]);
	} 
	for(int i=0;i<n;i++){
		scanf("%ld",&arr2[i]);
	}
	long long sum=0;
	
	for(int i=0;i<n;i++){
		if(arr1[i]<arr2[i]){
			arr2[i]=arr2[i]-arr1[i];
			sum+=arr1[i];
			arr1[i]=0;
			if(arr1[i+1]<arr2[i]){
				sum+=arr1[i+1];
				arr2[i]=arr2[i]-arr1[i+1];
				arr1[i+1]=0;
			}else{
				sum+=arr2[i];
				arr1[i+1]=arr1[i+1]-arr2[i];
				arr2[i]=0;
			}
		}else{
			sum+=arr2[i];
			arr1[i]=arr1[i]-arr2[i];
			arr2[i]=0;
		}
	} 
	printf("%ld",sum);
	return 0;
}

Measured memory_bytes: 3072
#include <iostream>
#include <string>
using namespace std;
int main(){
    string a;
    cin >> a;
    if(a == "MON"){
        cout << 6 << endl;
    } else if (a == "TUE"){
        cout << 5 << endl;
    } else if (a == "WED"){
        cout << 4 << endl;
    } else if (a == "THU"){
        cout << 3 << endl;
    } else if (a == "FRI"){
        cout << 2 << endl;
    } else if (a == "SAT"){
        cout << 1 << endl;
    } else if (a == "SUN"){
        cout << 7 << endl;
    }
    return 0;
}

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

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

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

    string s;
    cin >> s;

    vector<int> l(q), r(q);
    rep(i, q){
        cin >> l[i] >> r[i];
    }

    vector<int> v(n, 0);

    int cnt = 0;
    string t;
    t = s[0];
    for (int i = 1; i < n; i++) {
        if (t+s[i]=="AC"){
            cnt++;
        }

        v[i] = cnt;
        t = s[i];
    }

    rep(i, q){
        cout << v[r[i] - 1] - v[l[i] - 1] << endl;
    }
}

Measured memory_bytes: 2176
import sys
import itertools
# import numpy as np
import time
import math
import heapq
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
INF = 10 ** 9 + 7

# map(int, input().split())
# list(map(int, input().split()))

while True:
    N = int(input())
    if N == 0:
        break
    times = [0] * (24 * 60 * 60 + 1)
    for i in range(N):
        line = input().split()
        start, end = 0, 0
        for j in range(2):
            h, m, s = map(int, line[j].split(":"))
            seconds = h * 60 * 60 + m * 60 + s
            if j == 0:
                start = seconds
            else:
                end = seconds
        times[start] += 1
        times[end] -= 1
    for i in range(1, 60 * 60 * 24 + 1):
        times[i] += times[i - 1]
    print(max(times))


Measured memory_bytes: 10040
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll INM = 114514;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
//ll dx[4] = {1, 0, -1, 0};
//ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	ll w, h;
	cin >> w >> h;
	vector<P> p;
	ll x;
	for (int i = 0; i < w; i++) {
		cin >> x;
		p.emplace_back(x, 0);
	}
	for (int i = 0; i < h; i++) {
		cin >> x;
		p.emplace_back(x, 1);
	}
	ll cntW = 0;
	ll cntH = 0;
	sort(p.begin(), p.end());
	ll ans = 0;
	int n  = w + h;
	for (int i = 0; i < n; i++) {
		ll a, b;
		tie(a, b) = p[i];
		if (b == 0) {
			cntW++;
			ans += (h - cntH + 1) * a;
		} else {
			cntH++;
			ans += (w - cntW + 1) * a;
		}
	}
	dump(ans);
	return 0;
}


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

typedef long long ll;

const ll MOD = ll(1e9 + 7);
const int MAX_N = int(1e5) + 5;
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)

ll power(ll x, ll n) {
    ll res = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            res = res * x % MOD;
        }
        x = x * x % MOD;
        n >>= 1;
    }
    return res;
}

ll N, Q, a[MAX_N]{}, c[MAX_N]{}, q[MAX_N];

int main() {
    string s;
    cin >> s;
    N = s.size();
    REP(i, N) {
        if (s[i] == 'A') a[i + 1]++;
        a[i + 1] += a[i];
        if (s[N - i - 1] == 'C') c[i + 1]++;
        c[i + 1] += c[i];
        if (s[i] == '?') q[i + 1]++;
        q[i + 1] += q[i];
    }
    ll ans = 0;
    Q = q[N];
    FOR(i, 1, N-1) {
        if (s[i] == 'B' || s[i] == '?') {
            ll X = Q - (s[i]=='?'?1:0);
            ans += (a[i])*(c[N-i])%MOD*power(3,X)%MOD;
            ans %= MOD;
            ans += (q[i])*(c[N-i])%MOD*power(3,X-1)%MOD;
            ans %= MOD;
            ans += (a[i])*(q[N]-q[i+1])%MOD*power(3,X-1)%MOD;
            ans %= MOD;
            ans += (q[i])*(q[N]-q[i+1])%MOD*power(3,X-2)%MOD;
            ans %= MOD;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2816
#include<iostream>
#include<cmath>

using namespace std;

int main(void){
  int N,Q;
  long K;
  cin >> N >> K >> Q;
  N++;
  int *p = new int[N+1];
  for (int i = 0; i<N;i++){
    p[i] = 0;
  }

  int qi; 
  for (int i = 0; i<Q;i++){
    cin >> qi; 
    p[qi] +=1;
  }

  /*
  for (int i = 1; i<N;i++)
    cout<< (K-(Q-p[i]));
  cout<< endl;
  */
  for (int i = 1; i<N;i++){
    if (0< (K-(Q-p[i])) )
      cout<<"Yes"<<endl;
    else 
      cout<<"No"<<endl;
  }
}


Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <string>
#include <memory.h>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <time.h>
#include <assert.h>
#include <cmath>
#include <stack>
#include <string.h>
#include <sstream>
#include <algorithm>
using namespace std;
typedef long long ll;
int n, a, b;
char dp[101][101][201][2];
int calc(int a, int b, int rem, bool t) {
	if (!rem)
		return true;
	auto &ret = dp[a][b][rem][t];
	if (ret != -1)
		return ret;
	ret = false;
	if (!t) {
		if (a - 1 != b && a - 1 >= 0)
			ret = !calc(a - 1, b, rem - 1, !t);
		if (!ret && a + 1 != n && a + 1 != b)
			ret = !calc(a + 1, b, rem - 1, !t);
	}
	else {
		if (b - 1 != a && b - 1 >= 0)
			ret = !calc(a, b - 1, rem - 1, !t);
		if (!ret && b + 1 != n && b + 1 != a)
			ret = !calc(a, b + 1, rem - 1, !t);
	}
	return ret;
}
int main()
{
	cin >> n >> a >> b;
	--a; --b;
	memset(dp, -1, sizeof(dp));
	if (calc(a, b, 200, 0)) {
		puts("Alice");
	}
	else {
		bool A = true, B = true;
		if (a - 1 != b && a - 1 >= 0 && !calc(a - 1, b, 200, 1))
			A = false;
		if (a + 1 != b && a + 1 < n && !calc(a + 1, b, 200, 1))
			B = false;
		if (A&&B)
			puts("Borys");
		else
			puts("Draw");
	}
	return 0;
}

Measured memory_bytes: 4224
def solve():
    N = int(input())

    d = [[0] * 10 for i in range(10)]

    for num in range(1,N+1):
        num = str(num)
        f = int(num[0])
        e = int(num[-1])
        d[f][e] += 1
        
    ans = 0
    for i in range(10):
        for j in range(10):
            ans += d[i][j] * d[j][i]

    print(ans)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 40428
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.Map

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  private[this] val N = in.next().toInt
  private[this] val S = in.next()

  private[this] val left = S.substring(0, N)
  private[this] val right = S.substring(N, 2*N).reverse

  private[this] val dp1: Map[(String, String), Long] = Map()
  private[this] val dp2: Map[(String, String), Long] = Map()

  for(k <- 0 until Math.pow(2, N).round.toInt) {
    val tmp = k.toBinaryString
    val cond: String = "0"*(N - tmp.length) + tmp

    val l1 = new StringBuilder()
    val l2 = new StringBuilder()
    val r1 = new StringBuilder()
    val r2 = new StringBuilder()
    for(i <- 0 until N) {
      if(cond(i) == '0') {
        r1.append(left(i))
        r2.append(right(i))
      }
      else {
        l1.append(left(i))
        l2.append(right(i))
      }
    }

    val key1 = (l1.toString, r1.toString)
    val key2 = (l2.toString, r2.toString)
    if(dp1.contains(key1)) {
      dp1(key1) += 1
    }
    else {
      dp1 += ((key1, 1))
    }

    if(dp2.contains(key2)) {
      dp2(key2) += 1
    }
    else {
      dp2 += ((key2, 1))
    }
  }

  // val _ = ???

  var ans = 0L
  for((key, v1) <- dp1) {
    if(dp2.contains(key)) {
      ans += v1 * dp2(key)
    }
  }
  println(ans)
}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}



Measured memory_bytes: 203468
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long lint;
typedef vector<lint> vlint;
typedef vector<vlint> vvlint;
typedef pair<lint, lint> plint;
typedef double ld;

template<class T> bool chmin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool chmax(T &a, T b) { return a < b ? (a = b, true) : false; }



int main() {
    ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a, b;
	cin >> a >> b;
	cout << a * b - a - b + 1 << '\n';
	return 0;
}



Measured memory_bytes: 256