akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
import re
import bisect
from datetime import datetime as dt

N, Q = map(int, raw_input().split())
S = raw_input()
S += ' '
l = []
r = []
for i in range(Q):
    a = map(int, raw_input().split())
    l.append(a[0])
    r.append(a[1])

count = 0
d = [0 for i in range(N+1)]
for i in range(N):
    if S[i]+S[i+1] == 'AC':
        count += 1
    d[i + 1] = count

for i in range(Q):
    print '{}'.format(d[r[i]-1] - d[l[i]-1])


Measured memory_bytes: 14832
#include <bits/stdc++.h>
using namespace std;
typedef long long				ll;
typedef pair<int,int >			pii;
#define V						vector
#define SYNC					ios_base::sync_with_stdio(0);cin.tie(0);
#define rep(i,b)				for(int i=0;i<b;i++)
#define repn(i,n)				for(int i=1;i<=n;i++)
#define ALL(x)					(x).begin(),(x).end()
#define fi						first
#define se						second
#define pb						push_back
#define dzx						cerr<<"here";
const ll MOD=1e9+7,INF=9e18;
const int inf=2e9;
/* Equinox */
int a[501][501];
int p[501];
int f[501];
int m,n;
bitset<501> v;
int removemax(){
	int mx=-inf;
	int mi=-1;
	for(int i=0;i<m;i++){
		if(f[i]>=mx){
			mx=f[i];
			mi=i;
		}
	}	
	f[mi]=0;
	v[mi]=0;
	for(int i=0;i<n;i++){
		if(a[i][p[i]]==mi){
			while(v[a[i][p[i]]]==0){
				p[i]++;
			}
			f[a[i][p[i]]]++;
		}
	}
	mx=-inf;
	mi=-inf;
	for(int i=0;i<m;i++){
		if(f[i]>=mx){
			mx=f[i];
			mi=i;
		}
	}
	return mx;
}
int main(){SYNC
	v.set();
	int ans=-inf;
	cin>>n>>m;
	memset(f,0,sizeof f);
	memset(p,0,sizeof p);
	rep(i,n){
		rep(j,m){
			cin>>a[i][j];
			a[i][j]--;
		}
		f[a[i][0]]++;
	}
	rep(i,m){
		ans=max(ans,f[i]);
	}
	rep(i,m-1){
		ans=min(ans,removemax());
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define ll long long

using namespace std;
int main(){
    ll a,b;
    cin>>a>>b;
    ll ans = b;
    for(int i=0;i<a-1;i++){
        ans*=(b-1);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(*array)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1000100100;

int main() {
    string S;
    cin >> S;

    vector<bool> flags(26, false);
    REP(i, S.length()) {
        flags[(int)S[i] - (int)'a'] = true;
    }

    REP(i, 26) {
        if(!flags[i]) {
            cout << (char)((int)'a' + i) << endl;
            return 0;
        }
    }
    cout << "None" << endl;

    return 0;
}

Measured memory_bytes: 3732
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <utility>

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

using namespace std;

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

const int INF = 1001001001;

signed main()
{
    int n;
    cin >> n;
    
    vi hist(100001);
    
    rep(i, n){
        int a;
        cin >> a;
        hist[a]++;
    }
    
    int ans = 0;
    reps(i, 1, hist.size()-2){
        ans = max(ans, hist[i-1] + hist[i] + hist[i+1]);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 640
/*
ID: 5ak0
PROG:
LANG: C++11
*/

#include <bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define mpr make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9 + 7, MAXN = 1e5 + 10;

int n, a[MAXN];
ll sum[MAXN];

int main(){
    #ifndef SAKO
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);
    #endif // SAKO
    ios_base::sync_with_stdio(0);

    cin >> n;
    for (int i = 1; i <= n; ++i)
      cin >> a[i];
    int ans = 0;
    sort (a + 1, a + n + 1);
    for (int i = 1; i <= n; ++i)
        sum[i] = sum[i - 1] + a[i];
    reverse(a + 1, a + n + 1);
    reverse(sum + 1, sum + n + 1);
    for (int i = 1; i <= n; ++i)
        if (a[i] > sum[i + 1] * 2){
            cout << i;
            return 0;
        }

    return 0;
}


Measured memory_bytes: 1408
/*input
7
1 1 1 1 1 1 1
*/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>

using namespace std; 

int GCD(int x,int y){return y?GCD(y,x%y):x;}
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,a,b) for(int i=(a);i<(b);i++)
#define repm(i,a,b) for(int i=(a);i>(b);i--)
#define rept(v) for(auto it=v.begin();it<v.end();it++)
#define all(v) v.begin(),v.end()
const int INF = 1<<30;
typedef long long ll;
typedef pair<int,int> pii;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	sort(all(a));
	reverse(all(a));
	ll ans=0;
	rep(i, n-1) {
		ans+=a[(i+1)/2];
	}
	cout << ans;
	return 0;
}

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

int main(){
  vector<int> a(9);
  int n;
  string ans = "No";
  for(int i=0;i<9;i++){
    cin >> a[i];
  }
  cin >> n;
  vector<int> b(n);
  for(int i=0;i<n;i++){
    cin >> b[i];
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<9;j++){
      if(b[i]!=a[j]){
      }else{
        a[j]=0;
        break;
      }
    }
  }
  if(((a[0]==a[1])&&(a[1]==a[2]))||((a[3]==a[4])&&(a[4]==a[5]))||((a[6]==a[7])&&(a[7]==a[8]))||((a[0]==a[3])&&(a[3]==a[6]))||((a[1]==a[4])&&(a[4]==a[7]))||((a[2]==a[5])&&(a[5]==a[8]))||((a[0]==a[4])&&(a[4]==a[8]))||((a[2]==a[4])&&(a[4]==a[6]))){
    ans = "Yes";
  }
  cout << ans;
}




Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int w,h,n;
    cin>>w>>h>>n;
    int minx=0,miny=0,maxx=w,maxy=h;
    for(int i=0;i<n;i++){
        int a,b,c;
        cin>>a>>b>>c;
        if(c==1){
            minx=max(a,minx);
        }
        else if(c==2){
            maxx=min(a,maxx);
        }
        else if(c==3){
            miny=max(b,miny);
        }
        else{
            maxy=min(b,maxy);
        }
    }
    w=maxy-miny;
    h=maxx-minx;
    cout<<w*h*(w>0 && h>0)<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<cmath>
#include<cstdio>

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

using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(int argc, const char * argv[]) {
    int N=0;
    int L[101];
    int Ans=0;

    cin >> N;

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

    sort(L, L+N);

    for(int i=0; i<N-2; i++){
        for(int j=i+1; j<N-1; j++){
            for(int k=j+1; k<N; k++){

                if(L[i]<L[j] && L[j]<L[k]){
                    int l = L[i] + L[j] + L[k];
                    int r = max(L[k], max(L[j], L[i]));

                    if(r<l-r) Ans++;
                }

            }
        }
    }

    cout << Ans << endl;

    return 0;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> P(N);
  for (int i = 0; i < N; i++) {
    cin >> P.at(i);
  }
  priority_queue<int> p;
  for (int i = 0; i < N; i++) {
    p.push(P.at(i));
  }
  for (int i = 0; i < M; i++) {
    int m = p.top();
    m /= 2;
    p.pop();
    p.push(m);
  }
  long long int count = 0;
  for (int i = 0; i < N; i++) {
    count += p.top();
    p.pop();
  }
  cout << count << endl;
}




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

int main(){
  int n;
  string s[200001];
  cin >> n;
  for(int i=0;i<n;i++)cin >> s[i];

  sort(s, s+n);
  int mx=0, count=0;
  for(int i=0;i<n-1;i++){
    if(s[i]==s[i+1]){
      count++;
      mx=max(mx, count);
    }else{
      count=0;
    }
  }
  
  //cout << "mx:" << mx << endl;
  if(mx==0){
    for(int i=0;i<n;i++)cout << s[i] << endl;
  }else{
    count = 0;
    for(int i=0;i<n-1;i++){
      if(s[i]==s[i+1]){
        count++;
        if(mx==count){
          cout << s[i] << endl;
        }
      }else{
        count=0;
      }
    }
  }
  
  return 0;
}


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

using namespace std;

const int MAXN = 205;

int n, sol;
int a[MAXN];

int main () {
    cin >> n;
    for (int i=0; i<2*n; i++) {
        cin >> a[i];
    }
    sort(a, a + 2*n);
    for (int i=0; i<2*n; i += 2) {
        sol += a[i];
    }
    cout << sol;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    int e;
    int m;
    while(true){
        cin >> e;
        if(e == 0) break;
        m = 100000000;
        for(int z = 0;; z++){
            int xy = e - z * z * z;
            if(xy < 0) break;
            for(int y = 0;; y++){
                int x = xy - y * y;
                if(x < 0) break;
                m = min(m, x + y + z);
            }
        }
        cout << m << endl;
    }
}



Measured memory_bytes: 3024
/*
 * B.c
 *
 *  Created on: 2019/02/17
 *      Author: X250
 */


#include <stdio.h>

int main(void) {
	int N,M,K,A,F[30],i,j,ans=0;
	for(i=0;i<30;i++)F[i]=0;
	scanf("%d%d",&N,&M);
	for(i=0;i<N;i++) {
		scanf("%d",&K);
		for(j=0;j<K;j++) {
			scanf("%d",&A);
			F[A-1]++;
		}
	}
	for(i=0;i<M;i++)if(F[i]==N)ans++;
	printf("%d",ans);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> d(m, vector<int>(n));
    for(int i = 0; i < m; i++)
    {
        int k;
        cin >> k;
        for(int j = 0; j < k; j++)
        {
            int x;
            cin >> x;
            d[i][x-1] = 1;
        }
    }
    vector<int> p(m);
    for(int i = 0; i < m; i++)
    {
        cin >> p[i];
    }
    vector<int> s(n);
  int ans = 0;
    for(int i = 0; i < 1<<n; i++)
    {
        for(int j = 0; j < n; j++)
        {
            s[j] = 0;
        }
        for(int j = 0; j < n; j++)
        {
            if(i >> j & 1)
            {
                s[j] = 1;
            }
        }
        bool ok = true;
        for(int j = 0; j < m; j++)
        {
            int tmp = 0;
            for(int x = 0; x < n; x++)
            {
                if(d[j][x] == 1 && s[x] == 1)
                {
                    tmp++;
                }
            }
            if(tmp % 2 != p[j])
            {
                ok = false;
            }
        }
        if(ok)
        {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
// ABC156C - Rally

#include <bits/stdc++.h>
using namespace std;

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

	vector<int> X(N);
	for (int i = 0; i < N; i++) {
		cin >> X.at(i);
	}

	sort(X.begin(), X.end());

	int minimum = 100000000, temp_min;
	for (int i = X.at(0); i <= X.at(N - 1); i++) {
		temp_min = 0;
		for (int j = 0; j < N; j++) {
			temp_min += (X.at(j) - i) * (X.at(j) - i);
		}
		minimum = min(minimum, temp_min);
	}

	cout << minimum << endl;
}


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

typedef pair<int,int> pi;
typedef vector<int> vi;
 
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define pb push_back
#define debug(...) " [ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "

template<typename T> void max_self(T &a, T b) { a = max(a,b); return;}
template<typename T> void min_self(T &a, T b) { a = min(a,b); return;}
 
const int nax = 2e6 + 5;
const int mod = 1e9 + 7;

int modExpo(int a,int b,int c){
	
	a = a % c;	
	if(b == 0) return 1;
	else if((b % 2) == 0) return modExpo((a * a) % c,b / 2,c) % c;
	else return (a * modExpo((a * a) % c,b / 2,c) % c) % c;
}

void multiply(int a[][55], int b[][55],int n) { 
    
    int mul[55][55]; 
    for(int i = 0; i < n; i++){ 
        for(int j = 0; j < n; j++){ 
            mul[i][j] = 0; 
            for(int k = 0; k < n; k++) 
                mul[i][j] = (mul[i][j] % mod +  ((a[i][k] % mod) * (b[k][j] % mod)) % mod) % mod; 
        } 
    } 
  
    for(int i = 0; i < n; i++) 
        for(int j = 0; j < n; j++) 
            a[i][j] = mul[i][j]; 
} 

int solve(int arr[][55],int n,int k){
	
	int mult[55][55];
	memset(mult,0,sizeof(mult));
	
	for(int i = 0; i < n; ++i) mult[i][i] = 1;
	
	while(k){
		if(k & 1) multiply(mult,arr,n);
		multiply(arr,arr,n);
		k /= 2;
	}
		
	int ans = 0;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < n; ++j){
			ans = ((ans % mod) + (mult[i][j] % mod)) % mod;
		}
	}
	
	return ans;
}

signed main(){
	
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int t = 1;
	//cin >> t;
	while(t--){
		int n, k;
		cin >> n >> k;
		
		int arr[55][55];
		for(int i = 0; i < n; ++i){
			for(int j = 0; j < n; ++j){
				cin >> arr[i][j];
			}
		}
		
		cout << solve(arr,n,k);
	}
	
	return 0;
}


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

ll calc(ll now) {
  if (now == 1) return 1;
  return calc(now/2) * 2 + 1;
}

int main(){ 
  ll h;
  cin >> h;
  cout << calc(h) << endl;
  return 0;
} 

Measured memory_bytes: 256
using System;

namespace Csharp_Test
{
    class Program
    {
        static void Main(string[] args)
        {
            
            string temp = Console.ReadLine();
            
            long N = long.Parse(temp);

            int S = 0;
            for (int i = 0; i < temp.Length; i++)
            {
                S += temp[i] - '0';
            }

            string ans = (N % S == 0) ? "Yes" : "No";
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 11092
s = input()

d = [0 for i in range(len(s) + 1)]
i = len(s) - 1
deg = 1
while i >= 0:
    d[i] = (int(s[i]) * deg + d[i + 1]) % 2019
    deg = (deg * 10) % 2019
    i -= 1

#print(d)

cnt = [0 for i in range(2019)]
for i in d:
    cnt[i] += 1

res = 0
for i in cnt:
    res += i * (i - 1) // 2

print(res)


Measured memory_bytes: 86124
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 605;
const int MOD = 1000000009;
const int POW = 131;
int add(int a, int b){
    return (a + b) % MOD;
}
int sub(int a, int b){
    return (a - b + MOD) % MOD;
}
int mul(int a, int b){
    return (long long) a * b  % MOD;
}
char a[MAXN][MAXN];
int n;
int rh[MAXN][MAXN], ch[MAXN][MAXN];
int hpow[MAXN];
int get_r(int row, int c1, int c2){
    return sub(rh[row][c2], mul(hpow[c2 - c1 + 1], rh[row][c1 - 1]));
}
int get_c(int col, int r1, int r2){
    return sub(ch[col][r2], mul(hpow[r2 - r1 + 1], ch[col][r1 - 1]));
}
bool check(int row, int col, int len){
    int dif = row - col;
    int row_h = get_r(row, col + 1, col + len);
    int col_h = get_c(col, row + 1, row + len);
    return row_h == col_h;
    /*printf("%d %d %d\n", row_h, col_h, dif);
    if(dif < 0){
        printf("%d %d = \n", mul(col_h, hpow[-dif]), row_h);
        return (mul(col_h, hpow[-dif]) == row_h);
    } else {
        printf("%d %d = \n", mul(row_h, hpow[dif]), col_h);
        return (col_h == mul(row_h, hpow[dif]));
    }*/
}
void row_hash(){
    for(int r = 1; r <= 2 * n; r++){
        rh[r][0] = 0;
        for(int i = 1; i <= 2 * n; i++){
            rh[r][i] = add(mul(POW, rh[r][i - 1]), a[r][i]);
        }
    }
}
bool check_field(int r, int c){
    //printf("Checking %d %d\n", r, c);
    for(int l = 0; l < n; l++){
        if(!check(r + l, c + l, n - l - 1)) {
            //printf("Fails for %d %d %d\n", r + l, c + l, n - l - 1);
            return false;
        }
    }
    return true;
}
void col_hash(){
    for(int c = 1; c <= 2 * n; c++){
        ch[c][0] = 0;
        for(int i = 1; i <= 2 * n; i++){
            ch[c][i] = add(mul(POW, ch[c][i - 1]), a[i][c]);
        }
    }
}
int main(){
    hpow[0] = 1;
    for(int i = 1; i < MAXN; i++) hpow[i] = mul(hpow[i - 1], POW);
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        scanf("%s", a[i] + 1);
    }
    for(int i = n + 1; i <= 2 * n; i++){
        strcpy(a[i] + 1, a[i - n] + 1);
    }
    for(int i = n + 1; i <= 2 * n; i++){
        for(int j = 1; j <= 2 * n; j++) {
            a[j][i] = a[j][i - n];
        }
    }
    //for(int i = 1; i <= 2 * n; i++) printf("%s\n", a[i] + 1);
    row_hash();
    col_hash();
    /*for(int i = 1; i <= 2 * n; i++){
        for(int j = 1; j <= 2 * n; j++){
            printf("%d ", rh[i][j]);
        }
        printf("\n");
    }
    puts("------");
    for(int i = 1; i <= 2 * n; i++){
        for(int j = 1; j <= 2 * n; j++){
            printf("%d ", ch[i][j]);
        }
        printf("\n");
    }*/
    int ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(check_field(i, j)) ++ans;
        }
    }
    printf("%d\n", ans);
    return 0;
}


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

int main() {
	priority_queue<int> pq;
	// your code goes here
	int n;
	int ans = 0;
	cin >> n;
	for (int i = 0; i < 2*n; i++) {
		int l;
		cin >> l;
		pq.push(l);
	}
	while(pq.size() > 0) {
		int a,b;
		a = pq.top();
		pq.pop();
		b = pq.top();
		pq.pop();
		ans += min(a,b);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if a==b:
    print("YES")
    sys.exit()
if a<b and a+v*t>=b+w*t:
    print("YES")
elif a>b and a-v*t<=b-w*t:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 9192
#!/usr/bin/env ruby
require 'set'

n = gets.chomp.to_i

dict = Set.new
n.times do
  action, str = gets.chomp.split
  str = str.tr('ACTG', '1234')
  if action == 'insert'
    dict << str
  else
    puts dict.include?(str) ? 'yes' : 'no'
  end
end

Measured memory_bytes: 44888
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
using namespace std;

bool compare(const pair<ll,ll>&a,const pair<ll,ll>&b)
{
    return a.second<b.second;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll tests=1;
    //cin>>tests;
    while(tests--)
    {
        ll a,b,c;
        cin>>a>>b>>c;
        ll cnt5=0,cnt7=0;
        if(a==5) cnt5++;
        if(a==7) cnt7++;
        if(b==5) cnt5++;
        if(b==7) cnt7++;
        if(c==5) cnt5++;
        if(c==7) cnt7++;
        if(cnt5==2 && cnt7==1) cout<<"YES";
        else cout<<"NO";
    }
    
    return 0;
}


Measured memory_bytes: 256
/*
Author :: Shahadat Hossain Nirob
............SUST_MATH14..........
*/
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <vector>

#define Long long long
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define II() ( { int a ; read(a) ; a; } )
#define LL() ( { Long a ; read(a) ; a; } )
#define DD() ({double a; scanf("%lf", &a); a;})
#define DB if(0) 
#define D(x) cout << #x " is " << x << endl
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef vector<PII> VII;
typedef vector<string> VS;

const int INF = 2000000009;
const int MX = 200005;
const double EPS = 1e-9;
const int MOD = 1000000007;

template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

template<class T>inline bool read(T &x){
    int c=getchar();int sgn=1;
    while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}
    for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; 
    x*=sgn; return ~c;
}

#define nl puts ("")
#define sp printf ( " " )
#define phl printf ( "hello\n" )
#define ff first
#define ss second
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define MP make_pair
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define SQ(x) ((x)*(x))
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define ALL(x) (x).begin(),(x).end()
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define SZ(x) ((vlong)(x).size())
#define NORM(x) if(x>=mod)x-=mod;
#define MOD(x,y) (((x)*(y))%mod)
#define ODD(x) (((x)&1)==0?(0):(1))

typedef string st;
typedef vector<st> vs;
#define rep(i, n) for(int i = 0; i < n; i++)
#define fogg(i,a,b) for(int i = (a); i <= (b); i++)
#define ford(i,a,b) for(int i = (a); i >= (b); i--)
#define test int t; cin >> t; while(t--)
#define endl '\n'
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


struct abcd
{
	string s;
	int score;
	int idx;

};
bool cmp(abcd a,abcd b)
{
	if(a.s != b.s)	return a.s < b.s;
	return a.score>b.score;
}
int main()
{
	// #ifndef ONLINE_JUDGE
 //    freopen("input.txt","r",stdin);
 //    freopen("output.txt","w",stdout);
 //    #endif
    int n=II();
    abcd arr[n+5];
    rep(i,n)
    {
    	cin >> arr[i].s;
    	cin >> arr[i].score;
    	arr[i].idx=i+1;
    }
    sort(arr,arr+n,cmp);
    rep(i,n)
    	cout << arr[i].idx <<endl;
    
	
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int d[510][510];
int main()
{
	int N, M, Q;
	cin >> N >> M >> Q;
	for (int i = 0; i < M; i++) {
		int L, R;
		cin >> L >> R;
		L--; R--;
		d[L][R]++;
	}
	for (int i = 0; i < N; i++) {
		for (int j = 1; j < N; j++) {
			d[i][j] += d[i][j - 1];
		}
	}
	for (int j = 0; j < N; j++) {
		for (int i = N - 2; i >= 0; i--) {
			d[i][j] += d[i + 1][j];
		}
	}
	while (Q--) {
		int p, q;
		cin >> p >> q;
		p--; q--;
		cout << d[p][q] << endl;
	}
}


Measured memory_bytes: 4488
#include <iostream>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <unordered_map>
#include <random>
#include <queue>
#include <iomanip>

#define BIG 1000000007
#define LLMAX 9223372036854775807
#define LLMIN (-9223372036854775808)
#define long long long

using namespace std;



int main() {
    long n;
    cin >> n;
    n = n * 180 - 360;
    cout << n << endl;
}







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

int main() {
 
  int X,Y;
  int A,B,D,C,count; // A 万の位　B　千の位　　C　十の位　D　余り
    cin>>X>>Y;
  count =0; // for文の中に入れてはダメ　ループしても０に更新されてしまう。

    for(int i=X;i<=Y;i++)
    {
        A= i/10000;
        B=i/1000%10;
        C=i/10%10;
        D=i%10;
       
        if(A==D && B==C)
        {
           count++; 
            
        }
        
    }
    
    cout<<count<<endl;
    
    
    
}


Measured memory_bytes: 256
#include<stdio.h>

#define PASSED 'P'

int main(void) {
    int height, width, x, y;
    while(1) {
        scanf("%d %d", &height, &width);
        if(height == 0 && width == 0) break;

        char tiles[height][width];
        char buf[width];
        for(y = 0; y < height; y++) {
            scanf("%s", buf);
            for(x = 0; x < width; x++) {                                                                           
                tiles[y][x] = buf[x];
            }   
        }   

        char curr_tile = ' ';
        x = 0;
        y = 0;
        while(curr_tile != '.' && curr_tile != PASSED) {
            curr_tile = tiles[y][x];
            if(curr_tile == '>')         tiles[y][x++] = PASSED;
            else if(curr_tile == '<')    tiles[y][x--] = PASSED;
            else if(curr_tile == '^')    tiles[y--][x] = PASSED;
            else if(curr_tile == 'v')    tiles[y++][x] = PASSED;
            else if(curr_tile == '.')    printf("%d %d\n", x, y); 
            else if(curr_tile == PASSED) printf("LOOP\n");
        }   
    }   

    return 0;
}

Measured memory_bytes: 624
#include <stdio.h>

int	main(void)
{
  	long long   x;
 	int	num;
  	long long   f00;
  	long long	f;
  
  	num = scanf("%lld", &x);
  	if (num != 1)
      	return (0);
  
  	f00 = x / 500;
  	f = (x - 500 * f00) / 5;
  
  	printf("%lld", f00 * 1000 + f * 5);
  	return (0);
}

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

int main(){
	int n, m;
	cin >> n >> m;
	int maxl=0, minr=1e9;
	for (int i =0; i< m ; i++){
		int l,r;
		cin >> l >> r;
		maxl=max(l,maxl);
		minr=min(r,minr);
	}
	int count = 0;
	for (int i=1; i <= n; i++){
		if (i>=maxl && i <= minr) count++;
		
	}
	cout << count;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        String words=scan.next(),operationCode,repwords;
        int result,code1,code2;
        int n=scan.nextInt();
        
        for(int i=0; i<n; i++){
            operationCode=scan.next();
            code1=scan.nextInt();
            code2=scan.nextInt();
            StringBuffer strline;
            
            switch(operationCode){
                case "print":
                    System.out.println(words.substring(code1,code2+1));
                    break;
                case "reverse":
                    strline = new StringBuffer(words.substring(code1,code2+1));
                    words=words.substring(0, code1)+strline.reverse().toString()+words.substring(code2+1);
                    break;
                case "replace":
                    repwords=scan.next();
                    words=words.substring(0, code1)+repwords+words.substring(code2+1);
                    break;
            }
        }
    }
}


Measured memory_bytes: 29660
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  LL N, K; cin >> N >> K;
  if (K == 0) {
    cout << N * N << endl;
    return 0;
  }
  LL cnt = 0;
  for (int b = K + 1; b <= N; ++b) {
    LL x = N / b;
    LL r = N % b;
    cnt += x * (b - K) + max(0LL, r - K + 1);
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3628
import math
#import decimal
#decimal.getcontext().prec = 12

#getcontext().prec=20
a,b,h,m=map(int,input().split())
#a=decimal.Decimal(a)
#b=decimal.Decimal(b)
#h=decimal.Decimal(h)
#m=decimal.Decimal(m)

#print(a,b,h,m)

#ang1=decimal.Decimal(360*(h/12)+30*m/60)
#ang2=decimal.Decimal(360*m/60)
#ang=decimal.Decimal(abs(ang1-ang2))
ang1=360*(h/12)+30*m/60
ang2=360*m/60
ang=abs(ang1-ang2)
#print(ang)
if ang>=180.0:
#    ang=ang-180.0
    ang=360.0-ang

#print(ang)
#ans = ((a)**2 + (b)**2 - decimal.Decimal(2.0)*(a)*(b)*decimal.Decimal(math.cos(math.radians(ang))))
ans = a**2 + b**2 - 2.0*a*b*math.cos(math.pi*ang/180.0)
ans = math.sqrt(ans)
#print(math.cos(math.radians(ang)))

print(ans)

Measured memory_bytes: 9328
#include <bits/stdc++.h>
#define reps(i,j,k) for(int i = j; i < k; ++i)
#define rep(i,j) reps(i,0,j)
#define pb push_back
#define fr first
#define fs fr
#define sc second
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> Pii;
typedef pair<int,int> pii;
typedef long long ll;

/*
template<class T> &ostream<<(ostream &out, const vecotr<T> &v){
	out << "{";
	rep(i,v.size()) out << v[i] << ", ";
	return out << "}" << endl;
}
*/
struct data{
	int team;
	int ac;
	int score;
	data(){}
	data(int team,int ac,int score){
		this->team = team;
		this->ac = ac;
		this->score = score;
	}
	bool operator<(const data &a)const{
		if(ac == a.ac && score == a.score){
			return team < a.team;
		}
		else if(ac == a.ac){
			return score < a.score;
		}
		else{
			return ac > a.ac;
		}
	}
};
int main(){
	int T,P,R;
	while(cin >> T >> P >> R,(T|P|R)){
		vector < data > D(T);
		rep(i,T){
			D[i] = data(i,0,0);
		}
		int wrong[55][10810] = {{}};
		rep(i,R){
			int t_id,p_id,t;
			string msg;
			cin >> t_id >> p_id >> t >> msg;
			--t_id;--p_id;
			if(msg == "WRONG"){
				wrong[t_id][p_id]++;	
			}
			else{
				D[t_id] = data(t_id,D[t_id].ac+1,D[t_id].score+wrong[t_id][p_id]*1200+t);
			}
		}
		sort(D.begin(),D.end());
		rep(i,T){
			cout << D[i].team+1 << " " << D[i].ac << " " << D[i].score << endl;
 		}

	}
	return 0;
}

Measured memory_bytes: 5528
#include <cstdio>

using namespace std;

int x[100000];
int y[100000];

int main() {
    int n, m, mod = 1000000007, i;
    long long xs = 0, ys = 0;
    
    scanf("%d %d", &n, &m);
    
    for (i = 0; i < n; i++) scanf("%d", &x[i]);
    for (i = 0; i < m; i++) scanf("%d", &y[i]);
    
    for (i = 0; i < n - 1; i++) xs += (long long)(x[i + 1] - x[i]) * (i + 1) % mod * (n - i - 1) % mod;
    for (i = 0; i < m - 1; i++) ys += (long long)(y[i + 1] - y[i]) * (i + 1) % mod * (m - i - 1) % mod;
    
    xs %= mod;
    ys %= mod;
    
    printf("%lld\n", xs * ys % mod);
    
    return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
#define MAX 11
bool e[MAX][MAX];
int mod_pow(int x,int n,int mod){
  int res=1;
  while(n>0){
    if(n&1) (res*=x)%=mod;
    (x*=x)%=mod;
    n>>=1;
  }
  return res;
}
int I[1<<MAX],bn[1<<MAX];
bool check(int n,int k){
  int g=0;
  int MOD=10009;
  for(int i=0;i<(1<<n);i++){
    if(bn[i]%2==0) g+=mod_pow(I[i],k,MOD);
    else g-=mod_pow(I[i],k,MOD);
  }
  return (g%MOD+MOD)%MOD!=0;
}
int paint(int n){
  vector<int> N(1<<n);
  for(int i=0;i<n;i++){
    int bit=(1<<i);
    for(int j=0;j<n;j++)
      if(e[i][j]) bit|=(1<<j);
    N[i]=bit;
  }
  memset(I,0,sizeof(I));
  I[0]=1;
  for(int S=1;S<(1<<n);S++){
    bn[S]=__builtin_popcountll(S);
    int v=0;
    while(!((S>>v)&1)) v++;
    I[S]=I[S-(1<<v)]+I[S&~N[v]];
  }
  int l=0,r=n;
  while(l+1<r){
    int m=(l+r)/2;
    if(check(n,m)) r=m;
    else l=m;
  }
  return r;
}
//END CUT HERE



#define EPS (1e-10)

struct Point{
  double x,y;
  Point(){}
  Point(double x,double y) :x(x),y(y){}
  Point operator+(Point p) {return Point(x+p.x,y+p.y);}
  Point operator-(Point p) {return Point(x-p.x,y-p.y);}
  Point operator*(double k){return Point(x*k,y*k);}
  Point operator/(double k){return Point(x/k,y/k);}
};

typedef Point Vector;
typedef vector<Point> Polygon;


double norm(Vector a){
  return a.x*a.x+a.y*a.y;
}
double abs(Vector a){
  return sqrt(norm(a));
}
double cross(Vector a,Vector b){
  return a.x*b.y-a.y*b.x;
}

bool calc(Point a1,Point a2,Point b1,Point b2){
  if(abs(cross(a2-a1,b1-a1))>EPS) return 0;
  if(abs(cross(a2-a1,b2-a1))>EPS) return 0;
  double ml=0;
  ml=max(ml,abs(a1-a2));
  ml=max(ml,abs(a1-b1));
  ml=max(ml,abs(a1-b2));
  ml=max(ml,abs(a2-b1));
  ml=max(ml,abs(a2-b2));
  ml=max(ml,abs(b1-b2));
  return (ml+EPS<abs(a1-a2)+abs(b1-b2));
}


signed main(){
  int n;
  while(cin>>n,n){
    Polygon p[n];
    string name[n];
    map<string,int> m;
    for(int i=0;i<n;i++){
      cin>>name[i];
      if(!m.count(name[i])){
	int k=m.size();
	m[name[i]]=k;
      }
      int x,y;
      while(cin>>x,~x){
	cin>>y;
	p[i].push_back(Point(x,y));
      }
    }
    memset(e,0,sizeof(e));
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	if(name[i]==name[j]) continue;
	for(int k=0;k<(int)p[i].size();k++){
	  for(int l=0;l<(int)p[j].size();l++){
	    e[m[name[i]]][m[name[j]]]|=
	      calc(p[i][k],p[i][(k+1)%p[i].size()],
		   p[j][l],p[j][(l+1)%p[j].size()]);
	    e[m[name[j]]][m[name[i]]]|=
	      calc(p[i][k],p[i][(k+1)%p[i].size()],
		   p[j][l],p[j][(l+1)%p[j].size()]);
	  }
	}
      }
    }
    cout<<paint(m.size())<<endl;
  }
  return 0;
}

/*
  verified on 2017/12/12
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1254
*/

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

template <class Abel> struct BIT {
    vector<Abel> dat;
    Abel UNITY_SUM = 0;                     // to be set

    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) {
        dat.resize(n + 1);
        for (int i = 0; i < (int)dat.size(); ++i) dat[i] = UNITY_SUM;
    }

    /* a is 1-indexed */
    inline void add(int a, Abel x) {
        for (int i = a; i < (int)dat.size(); i += i & -i)
            dat[i] = dat[i] + x;
    }

    /* [1, a], a is 1-indexed */
    inline Abel sum(int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i)
            res = res + dat[i];
        return res;
    }

    /* [a, b), a and b are 1-indexed */
    inline Abel sum(int a, int b) {
        return sum(b - 1) - sum(a - 1);
    }

    /* k-th number (k is 0-indexed) */
    int get(long long k) {
        ++k;
        int res = 0;
        int N = 1; while (N < (int)dat.size()) N *= 2;
        for (int i = N / 2; i > 0; i /= 2) {
            if (res + i < (int)dat.size() && dat[res + i] < k) {
                k = k - dat[res + i];
                res = res + i;
            }
        }
        return res + 1;
    }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    BIT<int> bit(n);
    rep(i, 0, q) {
      int com, x, y;
      cin >> com >> x >> y;
      if (com) {
        cout << bit.sum(x, y+1) << endl;
      } else {
        bit.add(x, y);
      }
    }
    return 0;
}




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

int main (void){
    int a,b;
    string st;
    
    cin >> a >> b;
    
    st = to_string(a) + to_string(b);

    double f = sqrt(stoi(st));
    if (f - floor(f) > 0) cout << "No"<< endl;
    else cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    def input():
        return sys.stdin.readline()[:-1]

    N = int(input())
    S = input()

    if S[0]!='B' or S[-1]!='B':
        print(0)
        exit()

    mod = 10**9 + 7
    cnt = 1
    pre = 'B'
    d = 1 #1がleft
    ans = 1

    for i in range(1,N*2):
        if S[i-1]==S[i]:
            if d:
                d = 0
                ans *= cnt
                ans %= mod
                cnt -= 1
            else:
                d = 1
                cnt += 1
        else:
            if d:
                cnt += 1
            else:
                ans *= cnt
                ans %= mod
                cnt -= 1

    for i in range(1,N+1):
        ans *= i
        ans %= mod
    if cnt!=0:
        print(0)
        exit()

    print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 40048
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ERemOfSumIsNum solver = new ERemOfSumIsNum();
        solver.solve(1, in, out);
        out.close();
    }

    static class ERemOfSumIsNum {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int[] a = in.readIntArray(n);
            for (int i = 0; i < n; i++)
                a[i] %= k;
            long[] prefix = new long[n + 1];
            for (int i = 0; i < n; i++) {
                prefix[i + 1] = prefix[i] + a[i];
            }
            for (int i = 0; i <= n; i++) {
                prefix[i] = ((prefix[i] - i) % k + k) % k;
            }

            HashMap<Long, Integer> count = new HashMap<>();
            count.put(0L, 1);
            long answer = 0;
            for (int i = 1; i <= n; i++) {
                if (i - k >= 0) {
                    count.merge(prefix[i - k], -1, Integer::sum);
                }
                answer += count.getOrDefault(prefix[i], 0);
                count.merge(prefix[i], 1, Integer::sum);
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] readIntArray(int n) {
            int[] x = new int[n];
            for (int i = 0; i < n; i++) {
                x[i] = nextInt();
            }
            return x;
        }

    }
}



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

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  
  int an = 0, bn = 0, cn = 0;
  if (a < k) {
    an = a;
    if (b < k-an) {
      bn = b;
      if (c < k-an-bn) {
        cn = c;
      } else {
        cn = k-an-bn;
      }
    } else {
      bn = k-an;
    }
  } else {
    an = k;
  }
  cout << an - cn << endl;
}
        

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  ll n,k;
  cin>>n>>k;

  if(k==1){
    cout << 0 << endl;
    return 0;
  }

  vector<ll> p(n);
  rep(i,n){
    cin>>p[i];
    p[i]--;
  }

  vector<ll> rui(n+1);
  rui[0]=0;
  rep(i,n){
    rui[i+1]=(rui[i]+p[i])%k;
  }

  ll ans=0;
  map<ll,ll> ama;
  ama[0]=1;

  rep(i,n){
    if(i>=k-1){
      ama.at(rui[i-k+1])--;
    }
    if(ama.count(rui[i+1])) {
      ans+=ama.at(rui[i+1]);
      ama.at(rui[i+1])++;
    }
    else ama[rui[i+1]]=1;
  }

  cout << ans << endl;
}

Measured memory_bytes: 18772
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stdlib.h>

using namespace std;

int main() {
    int n,k;
    cin >> n >> k;
    int l[n];
    for(int i = 0; i < n; i++) {
        cin >> l[i];
    }
    sort(l, l+n, greater<int>());
    int snake = 0;
    for(int i = 0; i < k; i++) {
        snake += l[i];
    }
    cout << snake;
    return 0;
}



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

//A+B=N;
int N, A, B;

int digitsSum(int x){
    if(x/10==0) return x;
    return digitsSum(x/10) + x%10;
}

int main()
{
    cin>>N;

    int mi = 1000000000;
    for (int A = 1; A <= N-1; A++)
    {
        B = N-A;
        mi = min(mi, digitsSum(A) + digitsSum(B));
    }
    
    
    cout << mi << endl;

    return 0;
}


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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define X first
#define Y second
#define pb push_back
#define make_unique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define int long long

const LL mod = 1e9 + 7;


template<class T>
istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; }

template<class T, class U>
istream& operator >> (istream& in, pair<T, U> & v){ in >> v.X >> v.Y;return in; }

template<class T, class U>
ostream& operator << (ostream& out, pair<T, U> & v){ out << v.X << " " << v.Y;return out; }

void chkmax(int &a, int b) {
    a = max(a, b);
    return;
}

void chkmin(int &a, int b) {
    a = min(a, b);
    return;
}

LL ppow (LL x, LL s) {
    if (!s) return 1;
    if (!(s - 1)) return x % mod;
    if (s % 2) return (x * ppow (x, s - 1)) % mod;
    LL b = ppow (x, s / 2);
    return (b * b) % mod;
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("ILUXA.in", "r", stdin);

    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;
    map<int,vector<int> > ind;
    for (int i = 0;i < n;i++) {
        ind[a[i]].pb(i);
    }

    int ans = n;

    int lst = -1;
    for (int i = 1;i <= n;i++) {
        int j = int32_t(upper_bound(all(ind[i]), lst) - ind[i].begin());
        if (j == ind[i].size()) {
            break;
        }
        ans--;
        lst = ind[i][j];
    }
    cout << ((n == ans) ? (-1) : (ans));

    return 0;
}


Measured memory_bytes: 23680
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  n <- getl toInt
  solve n <$> getl (wrds toInt) <*> getl toInt <*> replicateM n (getl toInt) >>= print

solve :: Int -> [Int] -> Int -> [Int] -> Int
solve n [a,b] c ds = f a c (sortBy (flip compare) ds)
  where
    f :: Int -> Int -> [Int] -> Int
    f m c [] = truncate (fromIntegral c / fromIntegral m)
    f m c (x:xs)
      | m * x > b * c = f (m+b) (c+x) xs
      | otherwise = f m c xs

toInt :: String -> Int
toInt = read

wrds :: (String -> a) -> String -> [a]
wrds f = map f . words

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 4188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0 ; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const ll MOD = 1000000007;
const ll INF = 100000000000000000;
/* END OF TEMPLATE */

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n;
    cin >> n;
    cout << 180 * (n-2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て
// next_permutation(all(x))

int		main(void)
{
	int table[3][3];
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
			cin >> table[i][j];
	}

	int A[3];
	for (int i = 0; i < 3; i++)
		A[i] = table[0][i];
	int B[3];
	for (int i = 0; i < 3; i++)
		B[i] = table[i][0] - A[0];

	bool ans = true;
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			if (table[i][j] != A[j] + B[i])
				ans = false;
		}
	}
	cout << (ans ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
import java.util.*;

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

        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int X = sc.nextInt();
        int Y = sc.nextInt();

        int more = X > Y ? X : Y;
        int less = X < Y ? X : Y;
        int diff = more - less;
        int sum = 0;

        if ((A + B) > 2 * C) {
            sum += 2 * C * less;
        } else {
            sum += A * less + B * less;
        }

        if (X > Y) {
            if (A < 2 * C) {
                sum += diff * A;
            } else {
                sum += 2 * C * diff;
            }
        } else {
            if (B < 2 * C) {
                sum += diff * B;
            } else {
                sum += 2 * C * diff;
            }
        }

        System.out.println(sum);
    }
}



Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

__int128_t INF = 1000000000000000000;
int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  __int128_t ans = 1;
  bool f = false;
  bool g = false;
  re(i, n) {
    ll a;std::cin >> a;
    ans *= (__int128_t)a;
    if(a==0) f = true;
    if(ans > INF) g = true;
  }
  if(f){
    std::cout << 0 << '\n';
    return 0;
  }
  if(g){
    std::cout << -1 << '\n';
    return 0;
  }
  std::cout << (ll)ans << '\n';
  return 0;
}


Measured memory_bytes: 3156