akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
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; }
/*
この問題の考察
(a,b) (b,c) (b,d)みたいになったとき、a,b,c,dは好きな位置における
つまりswapの繰り返しで任意の配置につける。
じゃあunionfindでグループを管理すればp[i]はその属するグループ内で
好きに動けるからp[i]の行きたい位置とp[i]の今いるグループが同じであればいい
 */


struct UnionFind{
    vector<ll> par;
    vector<ll> siz;

    void init(ll n){
        for(ll i=0;i<n;i++){
            par.push_back(i);
            siz.push_back(1);
        }
    }
    ll root(ll x){
        //根を返す
        if(par[x]==x){
            return x;
        }
        else{
            return (par[x]=root(par[x]));
        }
    }
    bool sameParent(ll x,ll y){
        return(root(x)==root(y));
    }
    void unite(ll x, ll y){
        x=root(x);y=root(y);
        if(x==y)    return;
        //データ構造->小を大にくっつける
        if(siz[x]<siz[y]) swap(x,y);
        siz[x] += siz[y];
        par[y]=x;
    }

    ll size(ll x){
        return siz[root(x)];
    }
};

int main(){
    int n,m;
    cin>>n>>m;
    ll p[n];
    rep(i,n){
        cin>>p[i];
        p[i]--;
    }
    UnionFind uf;
    uf.init(n);
    rep(i,m){
        ll x,y;
        cin>>x>>y;
        x--;y--;
        uf.unite(x,y);
    }
    ll ans=0;
    rep(i,n){
        if(uf.root(p[i])==uf.root(i)) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2804
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#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--)

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> toshi(N);
    vector<int> a(M),b(M);

    for(int i = 0;i < M;i++){
        cin >> a.at(i) >> b.at(i);
    }

    for(int i = 0;i < M;i++){
        toshi[a[i]-1]++;
        toshi[b[i]-1]++;
    }

    for(int i = 0;i < N;i++){
        cout << toshi[i] << endl;
    }



    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1ll<<30;
const ll longINF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//

int N, M;
vector<int> g[112345], rg[112345];
int indeg[112345]; // 入次数
int par[112345];

int main() {
	cin >> N >> M;
	REP(i, N - 1 + M) {
		int A, B;
		scanf("%d %d", &A, &B);
		A--; B--;
		g[A].emplace_back(B); indeg[B]++;
		rg[B].emplace_back(A);
	}
	
	int st;
	REP(i, N) if (rg[i].empty()) st = i;
	par[st] = 0;
	
	queue<int> que;
	que.push(st);
	
	while (!que.empty()) {
		int u = que.front(); que.pop();
		
		for (int v : g[u]) {
			if (indeg[v] == 1) {
				que.push(v);
				par[v] = u + 1;
			}
			else {
				indeg[v]--;
			}
		}
	}
	
	REP(i, N) printf("%d\n", par[i]);
	
	return 0;
}


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

int main(){
    int x, a, b;
    cin >> x >> a >> b;
    if(b-a <= 0)cout << "delicious";
    else if(b-a <= x)cout << "safe";
    else cout << "dangerous";
    cout << endl;

    return 0;
}


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

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

    int count = 0;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int k=0;k<=c;k++){
                if(i*500+j*100+k*50 == x){
                    count++;
                }
            }
        }
    }
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 256
#coding: utf-8
import math
import heapq
import bisect
from collections import Counter, deque
import itertools
#from scipy.misc import comb

MOD = 10**9+7

N = int(input())
A = list(map(int, input().split()))
A.sort()

c = sorted(list(Counter(A).items()))

ans = 1
if N%2 == 1:
    for i in range(len(c)):
        if i==0:
            if c[i][0] == 0 and c[i][1] == 1:
                ans = 1
            else:
                ans = 0
        else:
            if c[i][0] == i*2 and c[i][1] == 2:
                ans *= 2
                ans %= MOD
            else:
                ans = 0
else:
    for i in range(len(c)):
        if c[i][0] == i*2+1 and c[i][1] == 2:
            ans *= 2
            ans %= MOD
        else:
            ans = 0

print(ans)

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

int main() {
    ll n,x,i,t;
    cin>>n;
    ll a[n];
    
    for(i=0;i<n;i++)
        cin>>a[i];
    ll res=a[0];
    ll ans=0;
    for(i=1;i<n;i++)
    {
        if(a[i]<res)
        {
            ans+=res-a[i];
            a[i]=res;
        }
        res=a[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5196
import java.util.*;

public class Main {
	static boolean isDelimiter(char c){
		return c == ' ' || c == ',' || c == '.';
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String results = "" , word = "" , str = sc.nextLine();
		for (int i = 0; i < str.length(); i++ ) {
			if ( !isDelimiter(str.charAt(i)) )
				word += str.charAt(i);
			else{
				if ( 3 <= word.length() && word.length() <= 6 )
					results += word+" ";
				word = "";
			}
		}
		System.out.println(results.substring(0,results.length()-1));
	}
}

Measured memory_bytes: 11000
#include<bits/stdc++.h>
using namespace std;
int main()
{  int n,m,flag=0;
   char a[1009][1009]={'&'};
   cin>>n>>m;
   for(int i=1;i<=n;i++)
   {
     for(int j=1;j<=m;j++)   cin>>a[i][j]; 
   } 
   for(int i=1;i<=n;i++)
   {
     for(int j=1;j<=m;j++)   
	 {
	   if(a[i][j]=='#' && a[i-1][j]=='.' && a[i][j-1]=='.'
	   && a[i][j+1]=='.'  && a[i+1][j]=='.') 
	   {
	     flag=1;
	     cout<<"No"<<endl;
	     return 0;
	   }
	   if(a[i][j]=='#' && i==1 && j==1 && a[i][j+1]=='.'  && a[i+1][j]=='.') 
	   {
	     flag=1;
	     cout<<"No"<<endl;
	     return 0;
	   }
	   if(a[i][j]=='#' && i==n && j==m && a[i][j-1]=='.'  && a[i-1][j]=='.') 
	   {
	     flag=1;
	     cout<<"No"<<endl;
	     return 0;
	   }
	   if(a[i][j]=='#' && j==m && i==1 && a[i-1][j]=='.'  && a[i+1][j]=='.') 
	   {
	     flag=1;
	     cout<<"No"<<endl;
	     return 0;
	   }
	   if(a[i][j]=='#' && i==n && j==1 && a[i][j+1]=='.'  && a[i-1][j]=='.') 
	   {
	     flag=1;
	     cout<<"No"<<endl;
	     return 0;
	   }
	   if(a[i][j]=='#' && i==n && a[i][j-1]=='.' && a[i][j+1]=='.'  && a[i-1][j]=='.') 
	   {
	     flag=1;
	     cout<<"No"<<endl;
	     return 0;
	   }
	   if(a[i][j]=='#' && i==1 && a[i][j+1]=='.' && a[i][j-1]=='.'  && a[i+1][j]=='.') 
	   {
	     flag=1;
	     cout<<"No"<<endl;
	     return 0;
	   }
	   if(a[i][j]=='#' && j==m && a[i][j-1]=='.' && a[i-1][j]=='.'  && a[i+1][j]=='.') 
	   {
	     flag=1;
	     cout<<"No"<<endl;
	     return 0;
	   }
	   if(a[i][j]=='#' && j==1 && a[i+1][j]=='.' && a[i][j+1]=='.'  && a[i-1][j]=='.') 
	   {
	     flag=1;
	     cout<<"No"<<endl;
	     return 0;
	   }
	 } 
   } 
   if(flag==0)  cout<<"Yes"<<endl;
   return 0;
} 

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


int main(){
	LL N; cin >> N;
	LL ans = N;
	for(LL i = 1; i * i <= N; ++i){
		LL tmp;
		if(N % i == 0) tmp = i + N / i - 2;
		ans = min(ans, tmp);
	}
	cout << ans << endl;
}















Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main()
{
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    
    long long cdiv, ddiv, cddiv;
    long long cd;
  
    cdiv = b/c - a/c;
    if (a % c == 0) cdiv++;
  
    ddiv = b/d - a/d;
    if (a % d == 0) ddiv++;
    
    long long cc = c;
    long long dd = d;
    while (cc != dd) {
      if (cc > dd) {
        cc -= dd;
      } else {
        dd -= cc;
      }
    }
    cd = c * d / cc;
  
    cddiv = b/cd - a/cd;
    if (a % cd == 0) cddiv++;
  
    cout << b-a+1 - (cdiv+ddiv-cddiv) << endl;
    return 0;
}


Measured memory_bytes: 256
N,M = map(int, input().split())
l = [[] for i in range(N)]
for i in range(N):
    l[i] = [int(i) for i in input().split()]

sorted_l = sorted(l, key=lambda x: x[0]+x[1]+x[2], reverse=True)
count0 = 0
for i in range(M):
    count0 += sorted_l[i][0]+sorted_l[i][1]+sorted_l[i][2]

sorted_l = sorted(l, key=lambda x: x[0]+x[1]-x[2], reverse=True)
count1 = 0
for i in range(M):
    count1 += sorted_l[i][0]+sorted_l[i][1]-sorted_l[i][2]

sorted_l = sorted(l, key=lambda x: x[0]-x[1]+x[2], reverse=True)
count2 = 0
for i in range(M):
    count2 += sorted_l[i][0]-sorted_l[i][1]+sorted_l[i][2]

sorted_l = sorted(l, key=lambda x: x[0]-x[1]-x[2], reverse=True)
count3 = 0
for i in range(M):
    count3 += sorted_l[i][0]-sorted_l[i][1]-sorted_l[i][2]

sorted_l = sorted(l, key=lambda x: -x[0]+x[1]+x[2], reverse=True)
count4 = 0
for i in range(M):
    count4 += -sorted_l[i][0]+sorted_l[i][1]+sorted_l[i][2]

sorted_l = sorted(l, key=lambda x: -x[0]+x[1]-x[2], reverse=True)
count5 = 0
for i in range(M):
    count5 += -sorted_l[i][0]+sorted_l[i][1]-sorted_l[i][2]

sorted_l = sorted(l, key=lambda x: -x[0]-x[1]+x[2], reverse=True)
count6 = 0
for i in range(M):
    count6 += -sorted_l[i][0]-sorted_l[i][1]+sorted_l[i][2]

sorted_l = sorted(l, key=lambda x: -x[0]-x[1]-x[2], reverse=True)
count7 = 0
for i in range(M):
    count7 += -sorted_l[i][0]-sorted_l[i][1]-sorted_l[i][2]

print(max(abs(count0),abs(count1),abs(count2),abs(count3),abs(count4),abs(count5),abs(count6),abs(count7)))


Measured memory_bytes: 3328
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
//for(int i = 0; i<n; i++)
 
 
int main()
{
    int n;cin>>n;
    int i = 1;
    while((i+1)*(i+1) <= n){
        i++;
    }
    cout << i*i << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	if (A <= C && C <= B) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e3 + 5;
//head
int a[5], b[5];
bool cmp(int x, int y) {
    int p = x % 10, q = y % 10;
    if(p == 0) p += 10;
    if(q == 0) q += 10;
    return p > q;
}
int main() {
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    for(int i = 0; i < 5; ++i) {
        cin >> a[i];
    }
    sort(a, a + 5, cmp);
    int t = 0;
    for(int i = 0; i < 5; ++i) {
        if(t % 10 == 0) {
            t += a[i];
        }
        else {
            while(t % 10) ++t;
            t += a[i];
        }
    }
    cout << t << endl;
    return 0;
}


Measured memory_bytes: 256
def eratosthenes(n):
    """エラトステネスの篩 O(NloglogN)

    Args:
        n (int): 上限値 (n > 1)
    
    Returns:
        list: 問題に応じた返り値
            - 素数判定:      is_prime
            - 素数列挙:      [i for i in range(n+1) if is_prime[i]]
            - 最小素因数列挙: min_factor
    """
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    min_factor = [-1] * (n+1)
    min_factor[0] = 0
    min_factor[1] = 1

    for i in range(2, n+1):
        if is_prime[i]:
            min_factor[i] = i
            for j in range(i*2, n+1, i):
                is_prime[j] = False
                if min_factor[j] == -1:
                    min_factor[j] = i

    return min_factor


n = int(input())

l = eratosthenes(n)

res = 1
for i in range(2, n):
    d = dict()
    while i > 1:
        if l[i] not in d:
            d[l[i]] = 1
        else:
            d[l[i]] += 1
        i //= l[i]
    
    tmp = 1
    for v in d.values():
        tmp *= v + 1

    res += tmp

print(res)

Measured memory_bytes: 84152
#include <iostream>
#include <cstdio>

using namespace std;
int a;
int ans;
int main()
{
	cin >> a;
	while(a > 0) {
		if(a % 10 == 1) {
			ans++;
		}
		a /= 10;
	}
	cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SIZE(x) ((x).size())
#define PB push_back

using namespace std;

const int N = 100001;

int n, x;
int a[N];

bool read() {
    if (!(cin >> n >> x)) {
        return false;
    }
    for (int i = 0; i < n; i++) {
        cin >> a[i]; a[i] = abs(a[i] - x);
    }
    return true;
}

void solve() {
    sort(a, a + n);
    int A = a[0];
    for (int i = 1; i < n; i++) {
        A = __gcd(A, a[i]);
    }
    cout << A << endl;
}

int main(void) {
    while (read())
        solve();
    return 0;
}


Measured memory_bytes: 640
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (ll)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
void solve(){
	ll n,t;
	cin>>n;
	ll a[60]={0};
	int mx = 0;
	rep(i,0,n){
		cin>>t;
		int cnt=0;
		while(t){
			if(t&1)a[cnt]++;
			t>>=1;
			cnt++;
		}
		mx = max(mx,cnt);
	}
	ll ans=0;
	for(ll i=0;i<mx;i++)
	{
		ans+=(1LL<<i)%mod*(a[i]*(n-a[i])%mod);
		ans%=mod;
	}
	cout<<ans;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long int  ans=1;int n;
	cin>>n;char s[n];
	cin>>s;
	int a[26]={};
	for(int i=0;i<n;i++){
		a[(int)s[i]-'a']++;
	}
	for(int i=0;i<26;i++){
		ans*=(a[i]+1);
		ans%=1000000007;
	}
	cout<<ans-1<<endl;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };



signed main() {
	int N;
	vector<int>list;
	string S;
	int cnt = 1;


	cin >> N >> S;

	for (int i = 0; i < N - 1; i++) {
		if (S[i] != S[i + 1]) {
			cnt++;
		}
	}

	/*if (S[S.length() - 1] != S[S.length() - 2]) {
		cnt++;
	}*/

	cout << cnt << endl;


	
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main( ) {
    //freopen("B.01.in","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a,b;
    cin >> a >> b;
    cout << b*2-a << endl; 
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
    int main(){
      string s;
      cin >> s;
      int ans=700;
      rep(i,s.size()){
       if(s[i]=='o') ans+=100; 
      }
      cout << ans << endl;
      return 0;}

Measured memory_bytes: 256
# coding: utf-8
n = int(input().rstrip())
S = list(map(int,input().rstrip().split()))
q = int(input().rstrip())
T = list(map(int,input().rstrip().split()))
count = 0
for i in range(q):
    start = 0
    end = n - 1
    half = 0
    while start <= end:
        half = int((start + end)/2)
        if S[half] == T[i]:
            count += 1
            break
        elif S[half] > T[i]:
            end = half - 1
        else:
            start = half + 1

print(count)


Measured memory_bytes: 16708
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
using namespace std;


int main(){
    string s;
    cin >> s;
    bool c = false;

    for(int i=0; i<s.length(); i++){
        if(s[i]=='C'){
            c = true;
        }
        if(c and s[i] == 'F'){
            cout << "Yes";
            exit(0);
        }
    }
    cout << "No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

void solver(int n, vector<int> l) {
  int ans = 0;
  sort(ALL(l));

  REP(i,n) {
    for (int j = i+1; j < n; j++) {
      for (int k = j+1; k < n; k++) {
        int a = l[i], b = l[j], c = l[k];
        if (a == b || b == c || a == c) continue;
        if (c < a+b) ans++;
      }
    }
  }
  COUT(ans);
}

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

  solver(n,l);
  return 0;
}

Measured memory_bytes: 3584
let S = Array(readLine()!.characters)

let S_size = S.count

var ok:Bool = true

for i in 0..<S_size {
    if i % 2 == 0 {
        if S[i] == "L" {
            ok = false
        }
    }else{
        if S[i] == "R" {
            ok = false
        }
    }
}

if ok {
    print("Yes")
}else {
    print("No")
}

Measured memory_bytes: 3824
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  double xa,ya,ra,xb,yb,rb,d;
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> xa >> ya >> ra >> xb >> yb >> rb;
    d = sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
    // BがAの中にあるとき
    if(ra>rb && d < fabs(ra - rb)){
      cout << 2 << endl;
    } // AがBの中にあるとき
    else if(ra<rb && d < fabs(rb - ra)){
      cout << -2 << endl;
    } // 円周が交わってる
    else if(fabs(ra-rb) < d && d < ra + rb){
      cout << 1 << endl;
    } // 離れていないとき
    else if(d > ra + rb){
      cout << 0 << endl;
    }else {
      cout << 1 << endl;
    }
  }
}

Measured memory_bytes: 1232
cnv [] = []
cnv x@(xh:xs) =
  let l = length $ takeWhile (== xh) x
      r = drop l x
  in
    (show l)++[xh]++(cnv r)

ans 0 s = s
ans n s = ans (n-1) $ cnv s

play ("0":_) = []
play (n:s:r) =
  let n' = read n
      a  = ans n' s
  in
    a:(play r)

main = do
  c <- getContents
  let o  = play $ lines c
  mapM_ putStrLn o

Measured memory_bytes: 4024
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scn=new Scanner(System.in);
		long n=scn.nextLong();
//		if(n==1){
//			System.out.println(0);
//			return;
//		}
		long val = n;
		long count=0;
		long valx= (long)Math.sqrt(n);
		for(long i=2;i*i<=val;i++){
			//int j=1;
			long val2=i;
			while(n%val2==0 && n>0){
		//	System.out.println(val2+"A"+n);
				n/=val2;
				val2*=i;
				count++;
				
			}
			while(n%i==0){
				n/=i;
			}
			if(n==0){
				break;
			}
		}
		//boolean ch=isprime(n);
		//System.out.println(n);
		count+=n>valx?1:0;
		System.out.println(count);

	}
//	public static boolean isprime(long n){
//		for(int i=2;i*i<=n;i++){
//			if(n%i==0){
//				return false;
//			}
//		}
//	}

}

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

int main ()
{
    int n;
    cin>>n;
    int a;
    deque<int>b;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        int it= lower_bound(b.begin(),b.end(),a)-b.begin();
        if(!it)
            b.push_front(a);
        else
            b[it-1]=a;
    }
    cout<<b.size()<<endl;

    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

#define min(a,b) (a < b ? a : b)
#define max(a,b) (a < b ? b : a)
#define INF 2e9

int main(){
  int N,i,res = -INF,x,y = INF;
  scanf("%d",&N);
  for(i = 0 ; i < N ; i++){
    scanf("%d",&x);
    res = max(res,x-y);
    y = min(x,y);
  }
  printf("%d\n",res);
  return 0;
}

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

int main() {
	int n,k;
	cin >> n>>k;
	string s;
	cin >> s;
	if (s[k-1] == 'A')s[k-1] = 'a';
	else if (s[k-1] == 'B')s[k-1] = 'b';
	else if (s[k-1] == 'C')s[k-1] = 'c';
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()
cnt = [0]*(N)
for i in range(1,N):
	cnt[i] = cnt[i-1] + (1 if S[i-1:i+1] == "AC" else 0)
for i in range(Q):
	l, r = map(int, input().split())
	print(cnt[r-1] - cnt[l-1])

Measured memory_bytes: 9412
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <map>
#define for1(x,y) for(long long x = 1; x<ll(y); x++)
#define forn(x,y,z) for(long long x = y; x< ll(z); x++)
#define for0(x,y,z) for(long long x = y; x< ll(z); x++)
# define PII pair<int,int>
# define FF first
# define SS second
# define PB push_back

#define forn(x,y,z) for(long long x = y; x< ll(z); x++)
#define for0(x,y,z) for(long long x = y; x< ll(z); x++)
using namespace std;
typedef long long ll;
typedef long double ld;	

#define maxn 1000015
const double EPS = (1e-7), EPSm= (1e7);
const ll linf = (ll)1e17 + 5;
long double PI = 3.14159265359;
int dir[8][2]={{1,0},{-1,0},{0,1},{0,-1},{-1,-1},{1,1},{-1,1},{1,-1}};
	
const int MAXN = 1e5 + 10;
const int NINF = -1e5;
const int INF = 2000000000;

void solve()
{
	int n;
	cin>>n;
	string s;
	ll cnt=0,j=0;
	cin>>s;
	queue<int> w;
	forn(i,0,s.size()){
		if(s[i]=='W'){
			w.push(i);
		}
	}
	for(int i=s.size()-1;i>0;i--){
		if((s[i]=='R' && s[i-1]=='W') || (s[i]=='R' && s[i-1]=='R')){
				if(!w.empty()){
						j=w.front();
						if(j<i){
							w.pop();
							swap(s[i],s[j]);
							cnt++;
						}
				}
				else if(s[i]=='R' && s[i-1]=='W'){
					cnt++;
					s[i]='W';
				}
		}
	}
	cout<<cnt<<endl;
	return;
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	setprecision(20);
	int test;
	//cin >> test;
	//while(test--)
		solve();
	return 0;
}


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


int main(){
    ll A, B, C;
    cin >> A >> B >> C;
    ll count = 0;
    while(A % 2 == 0 && B % 2 == 0 && C % 2 == 0){
        ll tmp_A = A, tmp_B = B, tmp_C = C;
        A += tmp_B / 2 + tmp_C / 2;
        B += tmp_A / 2 + tmp_C / 2;
        C += tmp_A / 2 + tmp_B / 2;
        count ++;
        if(A == B && A == C){
            cout << -1 << endl; return 0;
        } 
    }
    cout << count << endl;
}

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

signed main() {
    int a,b;
    cin >> a >> b;

    if(a <= 0 && b >= 0) cout << "Zero" << endl;
    else if(a < 0 && b < 0){
        int n = b - a + 1;
        if(n % 2 == 0) cout << "Positive" << endl;
        else cout << "Negative" << endl;
    } else {
        cout << "Positive" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1<<30;

int main(){
  int n, m;cin>>n>>m;
  if(n>m)swap(n, m);
  if(n==1)cout<<(m==1?1:m-2)<<endl;
  else cout<<ll(n-2)*ll(m-2)<<endl;
}

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

int main() {
    int n;
    cin>>n;
    double pi;
    vector<double> curr(n+1), prev(n+1, 0);
    prev[0] = 1.0;
    for(int i=0; i<n; i++) {
        cin>>pi;
        curr[0] = prev[0] * (1.0 - pi);
        for(int j=1; j<=i; j++)
            curr[j] = prev[j] * (1.0 - pi) + prev[j-1] * pi;
        curr[i+1] = prev[i] * pi;
        prev = curr;
    }
    cout<< fixed << setprecision(10) <<
        accumulate(curr.begin() + (n+1)/2, curr.end(), 0.0) <<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>

using namespace std;
long long int gcd(long long int a, long long int b) {
	long long int tmp;
	long long int r = 1;
	if (b > a) {
		tmp = a;
		a = b;
		b = tmp;
	}
	r = a % b;
	while (r != 0) {


		a = b;
		b = r;
		r = a % b;

	}
	return b;
}

int main() {
	map<int, int> mp;
	long long int n, m=0,tmp=0,ax=0,k=0,t[500000],p[500000],x,y,res[5000],a,b,c,GCD;
	string str, str2[5000];
	cin >> n>>k>>t[0];
	ax = t[0];
	GCD = t[0];
	for (int i = 1; i < n; i++) {
		cin >> t[i];
		ax = max(ax, t[i]);
		GCD = gcd(GCD, t[i]);
	}
	if (ax < k) { cout << "IMPOSSIBLE"; return 0; }
	if((ax-k)%GCD==0){ cout << "POSSIBLE"; return 0; }
	else{ cout << "IMPOSSIBLE"; return 0; }
}

Measured memory_bytes: 2688
import math

n = int(input())
xy_list = []
#n = 3
#xy_list = [[0,0 ],[0 ,1],[1,0]]
for i in range(n):
  xy_list.append(list(map(int,input().split())))
counter = 0
for m in range(n-1):
  for l in range(m,n):
    x_l = xy_list[l][0]
    y_l = xy_list[l][1]
    x_m = xy_list[m][0]
    y_m = xy_list[m][1]
    counter += ((x_m - x_l)**2 + (y_m - y_l)**2)**0.5

print(counter*2/n)

Measured memory_bytes: 3188
import java.util.*;
import java.util.Arrays;
public class Main{
    
    public static void main(String[] args){
       Scanner sc = new Scanner(System.in);
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        System.out.println((int)Math.ceil((double)a/(double)(2*b+1)));
    }
   
    
       
    
}

Measured memory_bytes: 24916
#include<bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x)  (long long)(x).size()
#define sqr(x) (x)*(x)
#define sof sizeof
#define resz resize
#define ins insert
#define lowerB lower_bound
#define upperB upper_bound
#define mkp make_pair
#define mkt make_tuple
#define act(a,v) (get<(long long)a>(v))
#define mod 1000000007
#define mod1 998244353
#define N 200003
#define inf 1e18
#define minf -1e18
#define min3(a,b,c) min(a,min(b,c));
#define max3(a,b,c) max(a,max(b,c));
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define sumall(v) accumulate(all(v),(ll)0)
#define suma accumulate
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION(n) std::cout.unsetf ( std::ios::floatfield );std::cout.precision((ll)n)
#define PI M_PI
#define fi first
#define se second
#define here cout<<"RSSB"<<endl
#define showzero cout<<std::showpoint
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define br "\n"
#define spac " "
#define zero (ll)0
using namespace  std ;
typedef double db;
typedef long long ll ;
typedef vector<int>vi ;
//typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
typedef vector<pll>vpll;
typedef vector<string>vstr;
typedef vector<tuple<ll,ll,ll> >vtll;
typedef vector<bool>vbool ;
void READ(vll &v, ll n){ll a ;for(ll i=0 ; i<n ; i=i+1){cin>>a ;v.pb(a);}}
void PRINT(vll &v , ll a = 0){for(ll i=a ; i<v.size() ; i=i+1){/*v[i] = max((ll)0,v[i]);*/cout<<v[i]<<"\n" ;}cout<<"\n" ;}
double logy(ll n , ll b){if(b==0){return(-1);}if(n==1){return(0);}return((db)log10(n)/log10(b));}
long long power(long long k , long long n , long long m=mod){long long res = 1;while(n){if(n%2!=0){res = (res*k)%m ;}k = (k*k)%m ;n = n/2 ;}return(res) ;}
double power(double p , ll t){db q = 1;while(t){if(t%2){q*=p;}p*=p;t/=2;}return(q);}
ll dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
ll dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
vpll dr;
void call(){dr.pb(mkp(1,0));dr.pb(mkp(-1,0));dr.pb(mkp(0,1));dr.pb(mkp(0,-1));}
ll n,m,k;
bool ok = false;
vll v;
ll dp[3003][3003];
ll solve(ll i , ll j)
{
    if(j>k)
    {
        return(0);
    }
    if(j==k)
    {
        return(n-i+1);
    }
    if(i==n)
    {
        return((j==k));
    }
    if(dp[i][j]!=-1)
    {
        return(dp[i][j]);
    }
    ll ans = (((j==0)*(i+1) + (j!=0)*1)*solve(i+1,j+v[i])%mod1 + solve(i+1,j)%mod1)%mod1;
    dp[i][j] = ans;
    return(ans);
}
int main()
{
    FastIO ;
    PRECISION(20) ;
    ll a,b,c,d,i,j,t,x,y,z,x1,y1,z1,e,f;
    db p,q,r,u,w ;
    char ch,chr ;
    string str,st,str1,str2,str3,str4;
    //ll a1=0,a2=0,b1=0,b2=0,c1=0 ;
    //cin>>str>>str1;
    //call();
    //Constructive is Weak!!
    cin>>n>>k;
    READ(v,n);
    memset(dp,-1,sof(dp));
    a = solve(0,0);
    cout<<a;
}

Measured memory_bytes: 70912
#include <stdio.h>
#include <string.h>

int main() {
	int a;
	
	scanf("%d", &a);
	
	char b[a+1];
	int ac = 0, wa = 0, tle = 0, re = 0;
	
	for(int i = 0; i < a; i++) {	
		
		scanf("%s", &b);
		
		
		if(b[0] == 'A') {
		
			ac++;
		}
		else if(b[0] == 'W') {
			
			wa++;
		}
		else if(b[0] == 'T') {
			
			tle++;
		}
		else if(b[0] == 'R') {
			
			re++;
		}
	}
	printf("AC x %d\n", ac);
	printf("WA x %d\n", wa);
	printf("TLE x %d\n", tle);
	printf("RE x %d\n", re);
	
	return 0;
}



Measured memory_bytes: 1740
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	N, x := nextInt(), nextInt()
	l := nextInt()
	c := 0

	for i := 1; i < N; i++ {
		r := nextInt()
		if n := l + r - x; n > 0 {
			c += n
			if l = r - n; l < 0 {
				l = 0
			}
		} else {
			l = r
		}
	}
	fmt.Println(c)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


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

int n, a[1025][1025], vis[1025];
bool flag;
bool ok() {
  for (int i = 1; i <= n; i++)
    if (a[i][0] != n) return 0;
  return 1;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n - 1; ++j) cin >> a[i][j];
    a[i][0] = 1;
  }
  for (int z = 1; z <= 0x3f3f3f3f; z++) {
    if (ok()) {
      cout << z - 1 << '\n';
      return 0;
    }
    flag = 0;
    // memset(vis, 0, sizeof vis);
    for (int i = 1; i <= n; i++) {
      if (vis[i] == z || a[i][0] == n) continue;
      int x = a[i][a[i][0]];
      if (a[x][a[x][0]] == i && vis[i] != z && vis[x] != z) {
        a[i][0]++;
        a[x][0]++;
        vis[i] = vis[x] = z;
        flag = 1;
      }
    }
    if (!flag) {
      cout << -1 << '\n';
      return 0;
    }
  }
  return 0;
}


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

vector<int> ans;

bool func(vector<int> &a, int i, int x){ // a[i]を足すか引くかでxを作れるか判断
  if(i==a.size()-1){
    if(x-a[i]==0){
      ans.push_back(a[i]);
      return true;
    } else if(x+a[i]==0){
      ans.push_back(-a[i]);
      return true;
    }
    return false;
  }
  // a[i]を足した
  if(func(a,i+1,x-a[i])){
    ans.push_back(a[i]);
    return true;
  }
  // a[i]を引いた
  if(func(a,i+1,x+a[i])){
    ans.push_back(-a[i]);
    return true;
  }
  return false;
}

int main(){
  char A,B,C,D; cin >>A >>B >>C >>D;
  vector<int> a(4);
  a[0] = int(A)-48;
  a[1] = int(B)-48;
  a[2] = int(C)-48;
  a[3] = int(D)-48;

  func(a,1,7-a[0]);
  cout << a[0];
  if(ans[2]>=0) cout << "+"; cout << ans[2];
  if(ans[1]>=0) cout << "+"; cout << ans[1];
  if(ans[0]>=0) cout << "+"; cout << ans[0];
  cout << "=7" << endl;
  return 0;
}


Measured memory_bytes: 256
import heapq
n=int(input())
A=list(map(int,input().split()))
A_l=A[:n]
heapq.heapify(A_l)
A_l_sum=[sum(A_l)]
A_m=A[n:2*n]
for i in range(n):
    p=A_m[i]
    heapq.heappush(A_l,p)
    q=heapq.heappop(A_l)
    A_l_sum.append(A_l_sum[-1]+p-q)
A_r=A[2*n:3*n]
for i in range(n):
    A_r[i]*=-1
for i in range(n):
    A_m[i]*=-1
A_m=A_m[::-1]
heapq.heapify(A_r)
A_r_sum=[sum(A_r)]
for i in range(n):
    p=A_m[i]
    heapq.heappush(A_r,p)
    q=heapq.heappop(A_r)
    A_r_sum.append(A_r_sum[-1]+p-q)
ans=-float("INF")
for i in range(n+1):
    ans=max(ans,A_l_sum[i]+A_r_sum[-i-1])
print(ans)

Measured memory_bytes: 42684
#include<bits/stdc++.h>
using namespace std;
#define nl cout<<"\n";
#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
    su;
    int n;
    cin>>n;
    cout<<(n+1)*n/2;
    nl;
    return 0;
}


Measured memory_bytes: 256
use std::io;

#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split(' ')
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

fn main() {
    let s: Vec<char> = read_one::<String>().chars().collect();
    let mut buf = String::new();

    for c in s {
        match c {
            'B' => {
                if buf.len() > 0 {
                    buf.pop();
                }
            },
            _ => buf.push(c),
        }
    }

    let ans = buf.chars()
        .fold(String::from(""), |a, b| a + &b.to_string());

    println!("{}", ans);
}

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

int main() {
	int x, y;
	cin >> x >> y;
	string ans = "No";
	rep(i, x+1) {
		int t = 2 * i;
		int k = 4 * (x-i);
		if(y == t+k) ans = "Yes";
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>
int main()
{
  int N;
  char s[100002];
  scanf("%d", &N);
  scanf("%s", &s);
  
  int n;
  n = strlen(s);
  
  for(int i=0;i<n;i++){
    s[i]+=N;
    if(s[i] > 'Z')
      s[i]=s[i]-('Z'-'A'+1);
  }
  
  printf("%s", s);  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9 + 7;

int n;

int h[100001];
long long memo[100001];

int main () {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> h[i];
	for (int i = 0; i < n; i++)
		memo[i] = -1;
	memo[0] = 0;
	memo[1] = abs(h[1] - h[0]);
	for (int i = 2; i < n; i++) {
		if ((abs(h[i] - h[i - 1]) + memo[i - 1]) < (abs(h[i] - h[i - 2]) + memo[i - 2]))
			memo[i] = (abs(h[i] - h[i - 1]) + memo[i - 1]);
		else
			memo[i] = (abs(h[i] - h[i - 2]) + memo[i - 2]);
	}
	cout << memo[n - 1] << '\n';
	return 0;
}

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

using namespace std;
#define ll  long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
const ll maxn= 2e5+7;
const ll mod= 1e9+9 ;
const ll base=1e6+1000;


ll dd[maxn];
ll a[maxn];
ll f[maxn];
ll n1, x1, m1 ;
int sol1()
{
    ll n= n1;
    ll x=x1;
    ll m= m1;
 memset(dd,0,sizeof(dd));
     memset(a,0,sizeof(a));
     memset(f,0,sizeof(f));

     ll sum=x;
     dd[x]=1;
     ll pre=x;
     ll sl=1;
     a[sl]=x;
     f[sl]=x;

     if (x==0)
     {
         cout <<0;
         return 0;
     }
     while (1)
     {
        ll h=(pre*pre)%m;
        if (h==0||sl==n)
        {
            cout <<f[min(n,sl)];
          //  cout <<"WTF"<<endl;
            return 0;

        }
        if (dd[h])
        {
            //cout <<dd[h]<<endl;
            ll p=f[dd[h]-1];
           // cout <<sl<<endl;
            /*for (int i=1;i<=sl;i++)
            {
                cout <<a[i]<<" ";
            }
           // cout <<h<<" "<<dd[h] ;
            cout <<endl;*/
            n-=(dd[h]-1);

            ll len=sl-dd[h]+1;
            ll p1= n/len;
           ll cnt=p1*(f[sl]-f[dd[h]-1]);
           ll cl=n%len;
           cnt+=(f[dd[h]+cl-1]-f[dd[h]-1]);
           cnt+=p;
           //cout <<sl<<" "<<n<<" "<<cl<<endl ;
           cout <<cnt;
           return 0;
        }
        else
        {

            sl++;
            dd[h]=sl;
           // cout <<h<<" "<<dd[h]<<" "<<sl<<endl;
            a[sl]=h;
            f[sl]=f[sl-1]+a[sl];
            pre=h;
           // sum+=pre;
        }

     }
}
void sol2()
{
 ll n= n1;
    ll x=x1;
    ll m= m1;
    ll ans=x;

    for (int i=2;i<=n;i++)
    {
     ll h=(x*x)%m;
     x=h;
     ans+=x;
    }
    cout <<ans;

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
//freopen("test.txt","r", stdin);

    if (fopen("walk.in","r"))
    {
        freopen("walk.in","r", stdin);
        freopen("walk.out", "w",stdout);
    }

   /* srand(time(NULL));
    n1=(rand()*rand())%5;
    if (n1==0) n1+=3;
     m1=(rand()*rand())%20;
      x1=(rand()*rand())%m1;
      cout <<n1<<" "<<m1<<" "<<x1<<endl;

      sol1();
      cout <<endl;
      sol2();*/
      cin>>n1>>x1>>m1;
      sol1();

}


Measured memory_bytes: 8336
from collections import defaultdict


def submit():
    n = int(input())
    a = list(map(int, input().split()))

    j_aj = [(i + 1) - a[i] for i in range(n)]
    j_aj_cnt = defaultdict(int)    
    for j in j_aj:
        j_aj_cnt[j] += 1

    ans = 0
    for i in range(n):
        j_aj_cnt[j_aj[i]] -= 1
        t = (i + 1) + a[i]
        ans += j_aj_cnt[t]
    print(ans)


submit()    

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

int main(){
    int n; cin>>n;
    vector<int> b(n-1);
    for(int i=0;i<n-1;i++) cin>>b[i];

    int ans=b[0]+b[n-2];
    for(int i=1;i<n-1;i++){
        ans+=min(b[i],b[i-1]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	class Node {
		int key;
		Node left;
		Node right;

		public Node(int key) {
			this.key = key;
		}

	}

	Node root;

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

	private void run() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		while (n-- > 0) {
			char s = scanner.next().charAt(0);
			if (s == 'i') {
				insert(scanner.nextInt());
			} else if (s == 'p') {
				inorder(root);
				System.out.println();
				preorder(root);
				System.out.println();
			} else {
				Node node = find(scanner.nextInt());
				System.out.println(node != null ? "yes" : "no");
			}
		}
	}

	private Node find(int key) {
		Node x = root;
		while (x != null && x.key != key) {
			if (x.key > key)
				x = x.left;
			else
				x = x.right;
		}
		return x;
	}

	private void preorder(Node u) {
		if (u == null)
			return;
		System.out.print(" " + u.key);
		preorder(u.left);
		preorder(u.right);
	}

	private void inorder(Node u) {
		if (u == null)
			return;
		inorder(u.left);
		System.out.print(" " + u.key);
		inorder(u.right);
	}

	private void insert(int key) {
		Node y = null;
		Node x = root;
		Node z = new Node(key);

		while (x != null) {
			y = x;
			if (x.key > z.key)
				x = x.left;
			else
				x = x.right;
		}
		if (y == null)
			root = z;
		else if (y.key > z.key)
			y.left = z;
		else
			y.right = z;
	}
}

Measured memory_bytes: 282936
#include <stdio.h>
#define N 100

int main()
{
  int a[N],n,i,j,mini,count=0;

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    scanf("%d",&a[i]);
  }
  for(i = 0; i < n; i++){
    mini = i;
    for(j = i; j < n; j++){
      if(a[j] < a[mini])
	mini = j;
    }
    a[n] = a[i];
    a[i] = a[mini];
    a[mini] = a[n];
    if(i!=mini)
      count++;
  }
  for(i = 0; i < n; i++){
    if(i == n-1){
      printf("%d\n",a[i]);
      break;
    }
    printf("%d ",a[i]);
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 600
// failed to generate code

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

long long dp[20001];

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector< tuple<int,int,int> > itms;
    for(int i = 0 ; i < n ; i++){
        int w,s,v;
        cin >> w >> s >> v;
        itms.emplace_back(w + s , s, v);
    }
    sort(itms.begin(), itms.end());
    for(int i = 0 ; i < n ; i++){
        int w,s,v;
        tie(w,s,v) = itms[i];
        w -= s;

        for(int j = s + w ; j >= w ; j--){
            dp[j] = max(dp[j], dp[j - w] + v);
        }
    }
    cout << *max_element(dp, dp + 20001) << endl;
}


Measured memory_bytes: 384
s = str(input())
t = str(input())
cnt = 0
max = 0
for i in range(len(s)-len(t)+1):
  cnt = 0
  for j in range(len(t)):
    if s[j+i] == t[j]:
      cnt += 1
  if max < cnt:
    max = cnt
            
print(len(t)-max)

Measured memory_bytes: 9124
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;

int main(){
  int H,W;
  string s;
  cin >> H >> W;
  for(int i = 0; i < H; i++){
    cin >> s ;
    cout << s << endl << s << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  int n;
  cin >> n;
  if(n==1) cout << "Hello World" << endl;
  else{
    int a,b;cin >>a >> b;
    cout << a+b << endl;
  }
  
  return 0;
    

}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
struct node{
  struct node *r;
  struct node *l;
  struct node *p;
  int key;
};
typedef struct node * Node;
#define NIL NULL
Node root;

Node treeSearch(Node u,int k){
  if(u == NIL || k == u->key) return u;
  if(k < u->key) return treeSearch(u->l,k);
  else return treeSearch(u->r,k);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->l = NIL;
  z->r = NIL;
  while(x != NIL){
    y=x;
    if(z->key < x->key){
      x=x->l;
    }
    else {
      x=x->r;
    }
  }
  z->p = y;
  if(y == NIL){
    root = z;
  }
  else {
    if(z->key < y->key){
      y->l = z;
    }
    else {
      y->r = z;
    }
  }
}

void inorder(Node u){
  if(u != NIL){
    inorder(u->l);
    printf(" %d",u->key);
    inorder(u->r);
  }

}

void preorder(Node u){
  if(u != NIL){
    printf(" %d",u->key);
    preorder(u->l);
    preorder(u->r);
  }
}

int main(){
  int n,i,x;
  char com[20];
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",com);
    if(com[0] == 'f'){
    scanf("%d",&x);
    Node t = treeSearch(root, x);
    if(t != NIL) printf("yes\n");
    else printf("no\n");
    }
    else if(com[0] == 'i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(com[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
      
    }
  }
  return 0;
}



Measured memory_bytes: 20536
N, M = map(int, input().split())
s = [list(map(int, input().split()))[1:] for _ in range(M)]
p = list(map(int, input().split()))
count = 0
for i in range(2 ** N):
    for m in range(M):
        switch = 0
        for j in range(N):
            if (i >> j) & 1:
                if j + 1 in s[m]:
                    switch += 1
        if switch % 2 != p[m]:
            break
    else:
        count += 1
print(count)

Measured memory_bytes: 40560
#include <cstdio>
#define MAX 1000000
#define SQRT 1000
#define TRUE 1
#define FALSE 0
using namespace std;

int is_prime[MAX];
int prime_count[MAX];

void solve() {
  int cnt = 0;
  for (int i = 0; i < MAX; i++) {
    is_prime[i] = TRUE;
  }
  is_prime[0] = is_prime[1] = 0;
  for (int i = 2; i < MAX; ++i) {
    if (is_prime[i] == TRUE) {
      if (i < SQRT) {
        for (int j = i * i; j < MAX; j += i) {
          is_prime[j] = FALSE;
        }
      }
      cnt++;
    }
    prime_count[i] = cnt;
  }
}

int main() {
  solve();
  int n;
  while (~scanf("%d", &n)) {
    printf("%d\n", prime_count[n]);
  }
}


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

int main(){
  ll n,k;
  cin >> n >> k;
  int cnt = 0;
  while(n){
    cnt++;
    n /= k;
  }
  cout << cnt << endl;
}

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

typedef unsigned ui;
typedef long long ll;
typedef unsigned long long ul;

ll a[N], s[N];

ui st[1 << 19], m;
void modify(ui w) {
	w += m;
	do st[w]++; while (w >>= 1);
}

ui query(ui l, ui r) {
	ui res = 0;
	for (l += m - 1, r += m + 1; l ^ r ^ 1; l >>= 1, r >>= 1) {
		if (~l & 1) res += st[l ^ 1];
		if (r & 1) res += st[r ^ 1];
	}
	return res;
}

int main(void) {
	ios::sync_with_stdio(0); cin.tie(0);
#ifdef _DEBUG
	ifstream cin("1.in");
#endif
	ui n; ll k; cin >> n >> k;
	for (ui i = 1; i <= n; ++i) cin >> a[i];
	for (ui i = 1; i <= n; ++i) s[i] = a[i] + s[i - 1];
	for (ui i = 1; i <= n; ++i) a[i] = s[i] - k * i;
	vector<ll> sv; sv.push_back(0);
	for (ui i = 1; i <= n; ++i) sv.push_back(a[i]);
	sort(sv.begin(), sv.end()); sv.erase(unique(sv.begin(), sv.end()), sv.end());
	for (m = 1; m <= sv.size() + 2; m <<= 1);
	ul ans = 0;
	modify(lower_bound(sv.begin(), sv.end(), 0) - sv.begin() + 1);
	for (ui i = 1; i <= n; ++i) {
		ui w = lower_bound(sv.begin(), sv.end(), a[i]) - sv.begin() + 1;
		ans += query(1, w);
		modify(w);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n;
  cin >> n;
  cout << n * n << endl;
}

Measured memory_bytes: 256
M,D = map(int,input().split())

numOfSekinohi = 0

if D >= 22 and M >= 4:
  for i in range(4,M+1):
    for j in range(22,D+1):
      if i >= 4 and j//10 >=2 and j % 10 >= 2 and ( (j // 10) * (j % 10) ) == i :
        numOfSekinohi += 1
      
print(numOfSekinohi)
      

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

int main() {
  ll x; cin >>x;
  ll cnt = 0;
  rep(i,x+1){
    cnt+=i;
    if(x<=cnt){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3636