akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(){
	int n ,m;
	scanf("%d%d",&n,&m);
	m=(m*2)+1;
	if(n%m==0){
		printf("%d",n/m);
	}
	if(n%m!=0){
		printf("%d",(n/m)+1);
	}
}

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

int n,m,q,a[M_SIZE],b[M_SIZE],c[M_SIZE],d[M_SIZE],A[M_SIZE];
int dfs(int now_index, int before_A_val){
    int ret = 0;
    if(now_index == n){ // 全部決めた！計算するぞ
        rep(i,q) if(A[b[i]]-A[a[i]] == c[i]) ret += d[i];
        return ret;
    }
    for(int i = 0; before_A_val + i <= m; ++i){
        A[now_index] = before_A_val+i;
        ret = max(ret, dfs(now_index+1, A[now_index])); // 各分岐の最大が、欲しい！
    }
    return ret;
}

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

    cin >> n >> m >> q;
    rep(i,q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--; // 0-indexedに直しましょう
    }
    
    cout << dfs(0, 1) << endl; // ここsabaっぽくてかわいい
}

Measured memory_bytes: 3680
while True:
    H, W = [int(i) for i in input().split()]
    if H == W == 0: break
    
    for i in range(H):
        if i == 0 or i == H-1:
            print(W*'#')
        else:   
            print('#' + '.'*(W-2) + '#')
        
    print()
            


Measured memory_bytes: 5616
n=int(input())
#a,b=map(int,input().split())
#c=list(map(int,input().split()))
#print(n,a,b,c)
s=list(input())
t=[]
ll=['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']

for i in s:
  tmp=ll.index(i)
  t.append(ll[(tmp+n)%26])
#print(s)
print("".join(t))

Measured memory_bytes: 3188
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;

int main(){
  int n;
  cin >> n;
  vector<int> x(n);
  rep(i, n) cin >> x[i];
  vector<int> y = x;
  sort(ALL(y));
  int midl = y[n / 2 - 1];
  int midr = y[n / 2];
  if (midl == midr){
    rep(i, n) cout << midl << endl;
    return 0;
  }
  rep(i, n){
    if (x[i] <= midl) cout << midr << endl;
    else cout << midl << endl;
  }
}


Measured memory_bytes: 3840
/*
 * wafuIroha.cpp
 *
 *  Created on: 2020/02/23
 *      Author: black
 */
#include <iostream>
#include <string>
using namespace std;

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

	if (a < b){
		if (a+w >= b){
			cout << 0 << endl;
		}
		else{
			cout << b-(a+w) << endl;
		}
	}
	else{
		if (a <= b+w){
			cout << 0 << endl;
		}
		else{
			cout << a-(b+w) << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 256
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  int x, a, b;
  cin >> x>>a>>b;
  x-=a;
  cout << x%b << endl;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

data = np.fromstring(read(), np.int64, sep=' ')

N, K  = data[:2]
P = np.hstack([[0], data[2:] + 1])

Pcum = P.cumsum()
x = Pcum[K:] - Pcum[0:-K]
print(x.max() / 2)


Measured memory_bytes: 18620
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<algorithm>
#define inf 32767
using namespace std;

int main(int argc,char* argv[]){
  int n,N,i,j;
  char x;
  char tab[50][2];
  
  while(cin>>n && n){
    for(i=0;i<n;i++){
      for(j=0;j<2;j++){
	while(cin>>x && (x=='\n' || x==' ')){}
	tab[i][j]=x;
      }
    }

    cin>>N;
    for(i=0;i<N;i++){
      while(cin>>x && (x=='\n' || x==' ')){}

      for(j=0;j<n;j++){
	if(x==tab[j][0]){
	  x=tab[j][1];
	  break;
	}
      }
      printf("%c",x);
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1144
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;

int Parent(int n, vector<int> &p) {
	if (p[n] == n)
		return n;
	return p[n] = Parent(p[n], p);
}

int main(void) {
	ll num;
	int m, i, a, b;
	cin >> num >> m;
	vector<ll> ans(m), s(num + 1, 1);
	vector<int> fr(m), to(m), p(num + 1);
	for (i = 0; i < m; i++)
		cin >> fr[i] >> to[i];
	for(i = 0; i<= num; i++)
		p[i] = i;
	ans[m - 1] = num * (num - 1) >> 1;
	for (i = m - 1; i > 0; i--) {
		a = Parent(fr[i], p);
		b = Parent(to[i], p);
		if (a == b)
			ans[i - 1] = ans[i];
		else {
			p[max(a, b)] = min(a, b);
			ans[i - 1] = ans[i] - s[a] * s[b];
			s[min(a, b)] += s[max(a, b)];
		}
	}
	for (i = 0; i < m; i++)
		cout << ans[i] << "\n";
	return 0;
}

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

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    int cnt = 0;
    vector<string> vec(h);
    rep(i, h) cin >> vec[i];
    for (int bit = 0; bit < (1<<h); ++bit) {
        set<int> H;
        for (int i = 0; i < h; ++i) {
            if (bit & (1<<i)) { // 列挙に i が含まれるか
                H.insert(i);
            }
        }
        for (int bit = 0; bit < (1<<w); ++bit) {
            set<int> W;
            for (int i = 0; i < w; ++i) {
                if (bit & (1<<i)) { // 列挙に i が含まれるか
                    W.insert(i);
                }
            }
            int tmp = 0;
            rep(i, h){
                rep(j, w){
                    if(H.find(i) == H.end() && W.find(j) == W.end()){
                        if(vec[i][j] == '#') tmp++;
                    }
                }
            }
            if(tmp == k) cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3628
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
#define gcd(a,b) __gcd(a,b)
#define ll long long int
#define ld double
#define pi pair<ll,ll>
#define pb push_back
#define pf push_front
#define pu push
#define po pop
#define fi first
#define se second
#define mk make_pair
#define ve vector
#define lr(n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define be begin
#define sz(a) (ll)a.size()
#define INF 1e18
 
typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
 
ll mod=1e9+7;
// ll gcd(ll a, ll b){
//     if(a<b) swap(a,b);
//     if(b==0) return a;
//     return gcd(b,a%b);
// }
 
// ll fun(ll x, ll y){
//     ll rem=1;
//     while(y!=0){
//         if(y%2==1){
//             rem=(rem*x)%mod;
//         }
//         x=(x*x)%mod;
//         y/=2;
//     }
//     return rem;
// }

ll dp[100001]={0};

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,k;
	cin>>n>>k;
	ve<ll>ar(n);
	lr(n){
		cin>>ar[i];
	}
	dp[0]=0;
	for(ll i=1;i<=k;i++){
		dp[i]=0;
		for(ll j:ar){
			if(i-j<0) break;
			if(dp[i-j]==0) dp[i]=1;
		}
	}
	if(dp[k]) cout << "First\n";
	else cout << "Second\n";
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
using namespace std;
typedef long long lint;
typedef long double ld;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=200010;
int main(){
	int n=ni;
	ld a=ni,d=ni,ans=0;
	a-=d;
	for(;n>=1;n--){
		ans+=a+(n+0.5)*d;
		ld na=a+(a*2+d*3)/(n<<1),nd=(1+2.0/n)*d;
		a=na,d=nd;
	}
	printf("%.15Lf\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define iinf 2000000000
#define linf 1000000000000000000LL
#define ulinf 10000000000000000000ull
#define MOD1 1000000007LL
#define mpr make_pair
typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned long UL;
typedef unsigned short US;
typedef pair < int , int > pii;
clock_t __stt;
inline void TStart(){__stt=clock();}
inline void TReport(){printf("\nTaken Time : %.3lf sec\n",(double)(clock()-__stt)/CLOCKS_PER_SEC);}
template < typename T > T MIN(T a,T b){return a<b?a:b;}
template < typename T > T MAX(T a,T b){return a>b?a:b;}
template < typename T > T ABS(T a){return a>0?a:(-a);}
template < typename T > void UMIN(T &a,T b){if(b<a) a=b;}
template < typename T > void UMAX(T &a,T b){if(b>a) a=b;}
int n,a[2005],s;
bitset < 5000000 > B;
int main(){
    // inputting start
    // 数据结构记得初始化！ n，m别写反！
    scanf("%d",&n);
	int i,j,k;
	B.reset();
	B[0]=1;
	for(i=0;i<n;++i){
		scanf("%d",a+i);
		B|=(B<<a[i]);
		s+=a[i];
	}
    #ifdef LOCAL
        TStart();
    #endif
    // calculation start
    // 数据结构记得初始化！ n，m别写反！
	for(i=(s+1)/2;!B[i];++i);
	printf("%d\n",i);
    #ifdef LOCAL
        TReport();
    #endif
    return 0;
}

Measured memory_bytes: 2176
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1;
	while (b) {
		if (b & 1) { res = res * a%MOD; }
		a = a * a%MOD;
		b >>= 1;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑


string ans = "Brown";
int main() {
	long long a, b;
	cin >> a >> b;
	if (abs(a - b) >= 2) { ans = "Alice"; }
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int d = scanner.nextInt();
    int g = scanner.nextInt();
    int[] p = new int[d + 1];
    int[] c = new int[d + 1];
    for (int i = 1; i <= d; i++) {
      p[i] = scanner.nextInt();
      c[i] = scanner.nextInt();
    }

    int[][] m = new int[d + 1][1001];
    for (int i = 1; i <= d; i++) {
      for (int j = 1; j <= 1000; j++) {
        for (int k = 0; k <= p[i] && k <= j; k++) {
          int score = i * k * 100;
          if (k == p[i]) score += c[i];
          score += m[i - 1][j - k];
          if (score > m[i][j]) m[i][j] = score;
        }
      }
    }

    for (int i = 1; i <= 1000; i++) {
      if (m[d][i] >= g) {
        System.out.println(i);
        return;
      }
    }
  }
}


Measured memory_bytes: 23764
from itertools import permutations

N = int(input())
P = [int(i) for i in input().split()]
Q = [int(i) for i in input().split()]
Ps = "".join(map(str, P))
Qs = "".join(map(str, Q))

Dict = []
for w in permutations(range(1, N+1)):
    Dict.append("".join(map(str, w)))

for i, w in enumerate(Dict):
    if w == Ps: a = i
    if w == Qs: b = i
print(abs(a - b))

Measured memory_bytes: 6040
#include <iostream>

using namespace std;
typedef long long ll;

int main()
{
  ll Q, H, S, D, N;
  cin >> Q >> H >> S >> D >> N;

  if (2*Q < H) H = 2*Q;
  if (2*H < S) S = 2*H;
  if (2*S < D) D = 2*S;
  cout << (N/2)*D + (N%2)*S << endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
TXY = [list(map(int, input().split())) for _ in range(N)]
TXY.insert(0,[0,0,0])

point_a, point_b = 0, 0
for i in range(N):
    if TXY[i+1][0] - TXY[i][0] < abs(TXY[i+1][1] - TXY[i][1]) + abs(TXY[i+1][2] - TXY[i][2]):
        point_a += 1

for i in range(N):
    if point_a == 0 and ((TXY[i+1][0] - TXY[i][0]) % 2 != (abs(TXY[i+1][1] - TXY[i][1]) + abs(TXY[i+1][2] - TXY[i][2])) %2) :
        point_b += 1

if point_a == 0 and point_b == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 27300
#include <bits/stdc++.h>
#define mp make_pair
#define pii pair<int,int>
typedef long long ll;
using namespace std;
int n,a[200005];
map <long long,int> ml;
long long cnt,sum;
int main(){
	ml[0]++;
	cin>>n;
	for (int i=0;i<n;i++) cin>>a[i];
	for (int i=0;i<n;i++){
		cnt+=a[i];
		sum+=ml[cnt];
		ml[cnt]++;
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 13568
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    int a; cin >> a;
    rep(i,100000){
        rep(j,10000){
            if(i*4 + j*7 == a)return puts("Yes")*0;
        }
    }
    cout << "No" << endl;
}




Measured memory_bytes: 256
import math
import sys
sys.setrecursionlimit(100000)

#S     G     S
#RRR..RLL...LRR...

s = list(input())
leng = len(s)
tmp = "R"
s[0] = "S"

for i in range(1,leng):
    if s[i] == "L":
        if tmp == "R":
            s[i] = "G"
        tmp = "L"
    else:
        if tmp == "L":
            s[i] = "S"
        tmp = "R"
lis = [0]*(leng)
tmp_s = 0
tmp_g = leng - 1

for i in range(1,leng):
    if s[i] == "G":
        tmp_g = i
    if s[i] == "S" or i == leng-1:
        if i == leng-1:
            i += 1
        if (tmp_g - tmp_s) % 2 == 0:
            lis[tmp_g-1] = math.floor((i - tmp_s)/2)
            lis[tmp_g] = math.floor((i - tmp_s)/2 + 0.5)
        else:
            lis[tmp_g-1] = math.floor((i - tmp_s)/2 + 0.5)
            lis[tmp_g] = math.floor((i - tmp_s)/2)
        tmp_s = i
        continue

    continue

print (*lis)

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

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))

#define DIVUP(x, y) (((x) + ((y) - 1)) / (y))
#define DIVOFF(x, y) (((x) + ((y) / 2)) / (y))
#define REMAINDER(x, y) ((x) % (y))

int N;
long ans{1};

int main() {
  scanf("%d", &N);
  for (int i{1}; i <= N; ++i) {
    ans *= i;
    ans %= 1000000007;
  }

  printf("%ld\n", ans);
  return 0;
}


Measured memory_bytes: 384
fun main(args: Array<String>) {
    codefestival2017qualc_b()
}

// (ai, ai-1, ai-2)の3パターン^10の全探索
fun codefestival2017qualc_b() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(' ').map { it.toLong() }

    var answer = 0L
    for (i in 0 until Math.pow(3.0, n.toDouble()).toLong()) {
        val any = aList.mapIndexed { index, l ->
            when ((i / Math.pow(3.0, index.toDouble())).toLong() % 3) {
                0L -> l - 1
                1L -> l
                else -> l + 1
            }
        }.any { it % 2 == 0L }

        if (any) answer++
    }

    println(answer)
}


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

using namespace std;

int main()
{

  while(1)
  {
	 int n;

	 cin >> n;
 
	 if(n == 0)break;

	 int Max = 0; 
	 int Min = 1001;
	 int Sum = 0;

	 for(int i = 0;i < n;i++)
	 {
	   int tmp;
	   cin >> tmp;
	   Sum += tmp;
	   Max = max(tmp,Max);
	   Min = min(tmp,Min);
	 }

	 Sum = Sum - Max - Min; 

	 cout << Sum/(n-2) << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

int main()
{

	string S;
	cin >> S;

	if (S[0] == 'Y' && S[1] == 'A' && S[2] == 'K' && S[3] == 'I') {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	

	
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ll long long int
#define l(i,a,b) for(ll i=a;i<b;i++)
using namespace std;
int main(){
		ll k,x;
		cin>>x>>k;
		if(500*x>=k) cout<<"Yes\n";
		else cout<<"No\n";
}

Measured memory_bytes: 3556
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
using ll = long long;
 
int main() {
	int a,b,x;
	cin >> a >> b >> x;
	if ((a + b) >= x && a <= x) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}


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

class Main {
    public static void result(int data[][], int check) {
        if (check == 4) {
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 10; j++) {
                    System.out.printf(" %d", data[i][j]);
                }
                System.out.print("\n");
            }
        } else {
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 10; j++) {
                    System.out.printf(" %d", data[i][j]);
                }
                if (i == 2) {
                    System.out.print("\n####################\n");
                } else {
                    System.out.print("\n");
                }
            }
        }
    }

    public static void main(String[] args) {
        int first[][] = new int[3][10];
        int second[][] = new int[3][10];
        int third[][] = new int[3][10];
        int forth[][] = new int[3][10];

        int b, f, r, v, rep;
        String data[];
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        try {
            rep = Integer.parseInt(br.readLine());
            while (rep-- > 0) {
                data = br.readLine().split(" ");
                b = Integer.parseInt(data[0]);
                f = Integer.parseInt(data[1]);// 행
                r = Integer.parseInt(data[2]);// 렬
                v = Integer.parseInt(data[3]);

                if (b == 1) {
                    first[f - 1][r - 1] += v;
                } else if (b == 2) {
                    second[f - 1][r - 1] += v;
                } else if (b == 3) {
                    third[f - 1][r - 1] += v;
                } else if (b == 4) {
                    forth[f - 1][r - 1] += v;
                }
            }
            result(first, 1);
            result(second, 2);
            result(third, 3);
            result(forth, 4);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}


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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,M=4,3
nodes=[[] for i in range(N)]
for i in range(M):
    a,b=MAP()
    nodes[a-1].append(b-1)
    nodes[b-1].append(a-1)

if all(len(nodes[i])<=2 for i in range(N)):
    YES()
else:
    NO()


Measured memory_bytes: 3064
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    vector<ll> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }
    ll odd = 0;
    for (int i=0; i<n; i++) {
        if (a.at(i)%2 == 1) {
            odd++;
        }
    }
    if (odd%2 == 0) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <cctype>
#include <queue>
#include <string>
#include <vector>
#include <map>

using namespace std;

int main()
{
    int a,b[5];
    for(a=0;a<3;a++)
    {
        cin>>b[a];
    }
    sort(b,b+3);
    if(b[0]!=5||b[1]!=5||b[2]!=7)
        cout<<"NO"<<endl;
    else
        cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define rep(i,n) for(int i=0; i<n; ++i)
#define cout(x) cout<<x<<endl
#define all(v) v.begin(), v.end()
using namespace std;
//型エイリアス
using vi = vector<int>;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
const ll inf = 1e18;
const int N = 2e5 + 10;


int main(){
    vi x(5);
    rep(i,5) cin >> x[i];

    rep(i,5){
        if(x[i]==0){
            cout(i+1);
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 3596
N, a, b = map(int, input().split())
M = 1000000007


def mod_comb_k(n, k):
    n_P_n_k = 1
    fact_k = 1
    for i in range(k):
        n_P_n_k = n_P_n_k * (n - i) % M
        fact_k = fact_k * (i + 1) % M
    return n_P_n_k * pow(fact_k, M-2, M)

ans = (pow(2, N, M) - 1 - mod_comb_k(N, a) - mod_comb_k(N, b)) % M
print(ans)

Measured memory_bytes: 3060
using System;
using System.Linq;
using System.Collections.Generic;

class MyClass
{
    public static void Main(string[] args)
    {
        var list = new LinkedList<string>();
        var n = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++)
        {
            var input = Console.ReadLine().Split();
            switch (input[0])
            {
                case "insert":
                    list.AddFirst(input[1]);
                    break;
                case "delete":
                    list.Remove(input[1]);
                    break;
                case "deleteFirst":
                    list.RemoveFirst();
                    break;
                case "deleteLast":
                    list.RemoveLast();
                    break;
                default:
                    break;
            }
        }
        Console.WriteLine(string.Join(" ", list));
    }
}


Measured memory_bytes: 118940
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K,x,sum = 0;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> x;
    if(pow(x,2) <= pow(K-x,2)){
      sum += 2 * x;
    }else{
      if(K-x >= 0){
        sum += 2*(K-x);
      }else{
        sum -= 2*(K-x);
      }
    }
  }
  cout << sum << endl;
}

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

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N), B(N);
    rep(i, N) cin >> A[i] >> B[i];

    ll ans = 0;
    for (int i = N - 1; i >= 0; --i) {
        ans += (B[i] - (A[i] + ans) % B[i]) % B[i];
    }

    cout << ans << endl;

    return 0;
}

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

using i64 = int64_t;

using Board = vector<vector<vector<int>>>;

constexpr int EMPTY = 0;
constexpr int BLACK = 1;
constexpr int WHITE = 2;
constexpr int WALL = 3;

Board create_board(int n){
    Board res(n+2, vector<vector<int>>(n+2, vector<int>(n+2, EMPTY)));
    for(int i=0;i<=n+1;++i){
        for(int j=0;j<=n+1;++j){
            res[0][i][j] = WALL;
            res[n+1][i][j] = WALL;
            res[i][0][j] = WALL;
            res[i][n+1][j] = WALL;
            res[i][j][0] = WALL;
            res[i][j][n+1] = WALL;
        }
    }
    return res;
}

void put_ball(int n, int x, int y, int color, Board &board){
    int z = n;
    while(board[z][y][x] == EMPTY)z--;
    board[z+1][y][x] = color;
}

void print_board(int n, const Board &board){
    string str = ".xo";
    cout << "**************" << endl;
    for(int z=1;z<=n;++z){
        cout << "-------- z = " << z << " --------" << endl;
        for(int y=1;y<=n;++y){
            for(int x=1;x<=n;++x){
                cout << str[board[z][y][x]];
            }
            cout << endl;
        }
    }
}

bool is_over(int n, int m, int color, const Board &board){
    int dx[13] = {1, -1, 0, 1, -1, 0, 1, -1, 0, 1, -1, 0, 1};
    int dy[13] = {0, 1, 1, 1, -1, -1, -1, 0, 0, 0, 1, 1, 1};
    int dz[13] = {0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1};
    for(int z=1;z<=n;++z){
        for(int y=1;y<=n;++y){
            for(int x=1;x<=n;++x){
                if(board[z][y][x] != color)continue;
                for(int d=0;d<13;++d){
                    int nx = x, ny = y, nz = z;
                    int cnt = 0;
                    do{
                        nx += dx[d];
                        ny += dy[d];
                        nz += dz[d];
                        cnt++;
                    }while(board[nz][ny][nx] == color);
                    if(cnt >= m)return true;
                }
            }
        }
    }
    return false;
}

int main(){
    int n, m, p;
    while(cin >> n >> m >> p, n > 0){
        Board board = create_board(n);
        int color = BLACK;
        int winner = 0, turn = 0;
        for(int i=1;i<=p;++i){
            int x, y;
            cin >> x >> y;
            put_ball(n, x, y, color, board);
            if(winner == 0 && is_over(n, m, color, board)){
                winner = color;
                turn = i;
            }
            color ^= 3;
        }
        //print_board(n, board);
        if(winner == 0)cout << "Draw";
        else cout << (winner == BLACK ? "Black" : "White") << " " << turn;
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 3132
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace  std;


int main() {
	int N;
	cin >> N;
	vector<int> data(N);
	for (int i = 0; i < N; i++) {
		cin >> data.at(i);
	}
	bool accept = true;
	for (int i = 0; i < N; i++) {
		if (data.at(i) % 2 == 0) {
			if (data.at(i) % 3 == 0) {
				continue;
			}
			else if (data.at(i) % 5 == 0) {
				continue;
			}
			else {
				accept = false;
			}
		}
	}
	if (accept == true) {
		cout << "APPROVED" << endl;
	}
	else {

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

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

  int a,b,n=0,sum=0;
  double avg = 0;

  while(scanf("%d,%d",&a,&b)!=EOF){
    sum += a*b;
    avg += (double)b;
    n++;
  }
  printf("%d\n%.0f\n",sum,(avg/n)+0.5);
  return (0);
}

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

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair
using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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

int gcd(int a, int b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));}

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

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

vector<pair<ll, int>> prime_div(ll n){
  vector<pair<ll, int>> res;
  for (ll i=2; i*i <= n;i++){
    if (n%i == 0){
      int a = 0;
      while(n%i == 0){
        n /= i;
        a++;
      }
      pair<ll, int> tmp;
      tmp.first = i;
      tmp.second = a;
      res.push_back(tmp);
    }
  }
  if (n != 1){
    pair<ll, int> now;
    now.first = n;
    now.second = 1;
    res.push_back(now);}
  return res;
}


// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  int a, b, m;
  cin >> a >> b >> m;
  vector<int> re(a), de(b);
  REP(i, a) cin >> re[i];
  REP(i, b) cin >> de[i];
  vector<int> x(m), y(m), c(m);
  REP(i, m) cin >> x[i] >> y[i] >> c[i];
  int ans = 1000000;
  REP(i, m){
    int val = re[x[i]-1] + de[y[i]-1] - c[i];
    ans = min(ans, val);
  }
  sort(re.begin(), re.end());
  sort(de.begin(), de.end());
  int val = re[0] + de[0];
  ans = min(val, ans);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 5296
#include <math.h>
#include <iostream>
using namespace std;

int main(){
	int n ;cin >> n;
  	int a[2000000];
  	int cnt[2000000] = {};
  	int c = 0;
  	for (int i=1 ; i < n; i++){
    	cin >> a[i];
    	c = a[i];
      	cnt[c]++;
    }
  	for (int i = 1; i < n+1 ; i++){
    cout << cnt[i] << endl;
    }
  
  
}

Measured memory_bytes: 12220
#pragma region ヘッダー
#define _CRT_SECURE_NO_WARNINGS

#ifdef _____MY_DEBUG_____
#define VS_ENDPAUSE()	(system("pause"))
#define DEBUG_OUT(...)  (printf(__VA_ARGS__))
#else
#define VS_ENDPAUSE()
#define DEBUG_OUT(...)
#endif

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

using namespace std;
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef signed long long int64;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
typedef unsigned long long uint64;
//#define int int64

#ifndef INT8_MIN
#define INT8_MIN	(-127)
#endif
#ifndef INT8_MAX
#define INT8_MAX	( 128)
#endif
#ifndef UINT8_MAX
#define UINT8_MAX	( 255)
#endif
#ifndef INT16_MIN
#define INT16_MIN	(-32768)
#endif
#ifndef INT16_MAX
#define INT16_MAX	( 32767)
#endif
#ifndef UINT16_MAX
#define UINT16_MAX	( 65535)
#endif
#ifndef INT32_MIN
#define INT32_MIN	(-2147483648)	// -2 * 10^9
#endif
#ifndef INT32_MAX
#define INT32_MAX	( 2147483647)	//  2 * 10^9
#endif
#ifndef UINT32_MAX
#define UINT32_MAX	( 4294967295)	//  4 * 10^9
#endif
#ifndef INT64_MIN
#define INT64_MIN	(-9223372036854775808)	// -9 * 10^18
#endif
#ifndef INT64_MAX
#define INT64_MAX	( 9223372036854775807)	//  9 * 10^18
#endif
#ifndef UINT64_MAX
#define UINT64_MAX	( 18446744073709551615)	// 18 * 10^18
#endif

void func(void);
#pragma endregion

int32 main(void)
{
    func();
    VS_ENDPAUSE();
    return 0;
}

//DEBUG_OUT("----\n");

void func(void)
{
    int M;
    cin >> M;
    cout << (24 + (24 - M)) << endl;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
char judge(int,int);
int main()
{
  int m,f,r;
  while(1){
    cin>>m>>f>>r;
    if(m==-1 && f==-1 && r==-1)break;
    if(m==-1 || f==-1)cout<<'F'<<endl;
    else cout<<judge(m+f,r)<<endl;
  }
  return 0;
}

char judge(int s,int r){
  if(s<30)return 'F';
  else if(s<50 && r>=50)return 'C';
  else if(s<50 && r<50)return 'D';
  else if(s<65)return 'C';
  else if(s<80)return 'B';
  else return 'A';
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 100010;

int f[N];
int n, m;

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

int main()
{
    scanf("%d%d", &n, &m);

    for (int i = 1; i <= n; i ++ ) f[i] = i;
    for (int i = 1; i <= m; i ++ )
    {
        int x, y;
        scanf("%d%d", &x, &y);

        if (find(x) != find(y))
            f[find(x)] = find(y);
    }

    int res = 0;
    for (int i = 1; i <= n; i ++ )
        if (f[i] == i)
            res ++;

    printf("%d\n", res - 1);
    return 0;
}

Measured memory_bytes: 4208
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using vc=vector<char>;
using vvc=vector<vc>;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using tiii = tuple<int,int,int>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int MOD=1e9+7;

ll power(ll a, int b) {
  if(!b) return 1;
  ll c = power(a, b/2);
  if(b%2) return c*c%MOD*a%MOD;
  return c*c%MOD;
}

int main() {
  int N;
  cin >> N;
  vi A(N);
  int AM=1;
  rep(i,N) {
    cin >> A[i];
    AM=max(AM,A[i]);
  }
  
  vector<bool> is_prime(AM+1, true);
  is_prime[0]=false; is_prime[1]=false;
  for(int i=2; i*i<=AM; i++) {
    if(!is_prime[i]) continue;
    for(int j=2; i*j<=AM; j++) is_prime[i*j]=false;
  }
  vi index(AM+1),prime;
  rep(i,AM+1) {
    if(is_prime[i]) prime.push_back(i);
  }
  
  rep(i,N) {
    if(is_prime[A[i]]) {
      index[A[i]]=max(index[A[i]],1);
      continue;
    }
    int num=A[i];
    for(int p:prime) {
      int count=0;
      while(!(num%p)) {
        num/=p;
        count++;
      }
      index[p]=max(index[p],count);
      if(num==1) break;
    }
  }
  
  ll lcm=1;
  for(int p:prime)
    (lcm*=power(p,index[p]))%=MOD;
  ll ans=0;
  rep(i,N)
    (ans+=lcm*power(A[i],MOD-2))%=MOD;
  
  cout << ans << endl;
}

Measured memory_bytes: 7920
def prepare(s,t):
  list_s = list(s)
  list_t = list(t)
  num = len(list_s)
  x = 0
  for i in range(num):
    if list_s[i] != list_t[i]:
      x += 1
  print(x)
s = str(input())
t = str(input())
prepare(s,t)



Measured memory_bytes: 12500
import sys
sys.setrecursionlimit(10000)

N,M = map(int, input().split())
a = [int(input()) for i in range(M)]

def fib(n):
        a, b = 0, 1
        for i in range(n):
            a, b = b, a + b
        return b if n >= 0 else 0

if M == 0:
    ans = fib(N) % (10**9+7)

else:
    ans = fib(a[0]-1)
    for i in range(M-1):
        ans = (ans * fib(a[i+1]-a[i]-2))%(10**9+7)

    ans = (ans * fib(N-a[-1]-1))%(10**9+7)

print(ans)

Measured memory_bytes: 7080
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
from collections import defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
X = readInts()
nya = sorted(X)
m1 = nya[n//2-1];m2 = nya[n//2]
# このどちらか
# 適当に取り出して、そいつが中央値1以下ならm2,
for x in X:
    if x <= m1:
        print(m2)
    else:
        print(m1)


Measured memory_bytes: 26540
#include <iostream>
using namespace std;
#define rep(i,n)	for(int i=0;i<n;i++)
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;	cin>>n;
	int s[n];
	rep(i,n)	cin>>s[i];
	int q;	cin>>q;
	int t,cou=0;
	rep(i,q){
		cin>>t;
		rep(j,n){
			if(s[j]==t){
				cou++;
				break;
			}
		}
	}
	cout<<cou<<endl;
	return 0;
}

Measured memory_bytes: 1232
#include <stdio.h>

typedef long long int ll;

int mod = 1000000007;

int dp[1001][1001];

int main(){
  int i, j, k, n, ans;

  for(i=2;i<=1000;i++){
    if(dp[i][0]) continue;
    for(j=i;j<=1000;j+=i) dp[j][0]=1;
    for(k=i;k<=1000;k*=i){
      for(j=k;j<=1000;j+=k){
        dp[j][i]++;
      }
    }
  }

  scanf("%d", &n);

  for(j=2;j<=n;j++){
    for(i=j;i<n;i++){
      dp[n][j] += dp[i][j];
    }
  }

  ans = 1;
  for(j=2;j<=n;j++){
    ans = (ll) ans * (dp[n][j]+1) % mod;
  }

  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

int main(){
	int n, d;
	cin >> n >> d;
	cout << (n+d*2)/(d*2+1) << endl;
	return 0;
}



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

using namespace std;
using ll = long long;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;
#define popcnt __builtin_popcount

ll x;

ll cmp(ll a, ll b){
    if(a>=x&&b>=x){
        return max(a, b)-x;
    }
    else if(a<x&&b<x){
        return x-min(a, b);
    }else{
        return min(2*abs(a-x)+abs(b-x), abs(a-x)+2*abs(b-x));
    }
}

int main() {
    int a, b, q;
    cin >> a >> b >> q;
    vector<ll> s(a), t(b);
    for (int i = 0; i < a; i++)cin >> s[i];
    for (int i = 0; i < b; i++)cin >> t[i];
    sort(all(s));
    sort(all(t));

    for (int qi = 0; qi < q; qi++) {
        cin >> x;
        ll ans = 1e15;
        auto mn_s = lower_bound(s.begin(), s.end(), x);
        auto mn_t = lower_bound(t.begin(), t.end(), x);

        ll s1 = ((mn_s != s.end()) ? *(mn_s) : s[a - 1]), s2 = ((mn_s != s.begin()) ? *(mn_s - 1) : s[0]),
                t1 = ((mn_t != t.end()) ? *(mn_t) : t[b - 1]), t2 = ((mn_t != t.begin()) ? *(mn_t - 1) : t[0]);

        ans = min(ans, cmp(s1, t1));
        ans = min(ans, cmp(s1, t2));
        ans = min(ans, cmp(s2, t1));
        ans = min(ans, cmp(s2, t2));

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>
istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >> p.second;
	return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
	rep(i, v.size()) { is >> v[i]; }
	return is;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);
int main() {
	int n;
	ll ans = 0LL;
	cin >> n;
	V a(n);
	cin >> a;
	map<ll,int> b;
	rep(i, n) {
		
			
		//	clog << b << endl;
		//	ans += distance(lower_bound(all(b), -a[i] + (i+1) ),
		//	                upper_bound(all(b), -a[i] + (i+1) ));
		//	clog << ans << endl;
		    ans += b[i + 1 - a[i]];
		    b[a[i] + (i + 1)]++;
		    //		clog << b.back() << endl;
	}
//	clog << a << endl;
//	sort(all(a));
//	clog << a << endl;
	cout << ans << endl;
}
/*
j-i== A_i + A_j
A_i+i== j-A_j
*/

Measured memory_bytes: 27480
use std::io::prelude::*;

fn main() {
    let stdin = std::io::stdin();
    let mut reader = std::io::BufReader::new(stdin.lock());
    let mut s = String::new();
    reader.read_line(&mut s).unwrap();
    let mut n: usize = s.trim().parse().unwrap();

    while n % 111 != 0 {
        n += 1;
    }
    println!("{}", n);
}



Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

int main() {
  ll h,w,q;
  cin >> h >> w >> q;
  vector<string> s(h);
  for(ll i=0;i<h;i++) cin >> s[i];
  mat V(h+1,vec(w+1));
  mat Eh(h,vec(w));
  mat Ew(h,vec(w));
  for(ll i=0;i<h;i++) {
    for(ll j=0;j<w;j++) {
      V[i+1][j+1]=s[i][j]=='1';
    }
  }
  for(ll i=0;i<h;i++) {
    for(ll j=0;j<w;j++) {
      if(i) {
        if(s[i][j]=='1'&&s[i-1][j]=='1') Eh[i][j]++;
      }
      if(j) {
        if(s[i][j]=='1'&&s[i][j-1]=='1') Ew[i][j]++;
      }
    }
  }
  for(ll i=0;i<=h;i++) {
    for(ll j=0;j<w;j++) {
      V[i][j+1]+=V[i][j];
      if(i==h) continue;
      if(j+1==w) continue;
      Eh[i][j+1]+=Eh[i][j];
      Ew[i][j+1]+=Ew[i][j];
    }
  }
  for(ll i=0;i<h;i++) {
    for(ll j=0;j<=w;j++) {
      V[i+1][j]+=V[i][j];
      if(j==w) continue;
      if(i+1==h) continue;
      Eh[i+1][j]+=Eh[i][j];
      Ew[i+1][j]+=Ew[i][j];
    }
  }
  vec lx(q),ly(q),hx(q),hy(q);
  for(ll i=0;i<q;i++) {
    cin >> ly[i] >> lx[i] >> hy[i] >> hx[i];
    ly[i]--,lx[i]--,hy[i]--,hx[i]--;
  }
  for(ll i=0;i<q;i++) {
    ll ans=V[hy[i]+1][hx[i]+1]-V[hy[i]+1][lx[i]]-V[ly[i]][hx[i]+1]+V[ly[i]][lx[i]];
    ll y=Eh[hy[i]][hx[i]]-Eh[ly[i]][hx[i]];
    if(lx[i]) y+=-Eh[hy[i]][lx[i]-1]+Eh[ly[i]][lx[i]-1];
    ll x=Ew[hy[i]][hx[i]]-Ew[hy[i]][lx[i]];
    if(ly[i]) x+=-Ew[ly[i]-1][hx[i]]+Ew[ly[i]-1][lx[i]];
    ans-=y;
    ans-=x;
    cout << ans << endl;
  }
}

Measured memory_bytes: 111220
#include <stdio.h>
int main() {
  int N;
  char s1[101];
  char s2[301];
  scanf("%d", &N);
  scanf("%s", s1);
  char *head = s2+100;
  char *tail = s2+100;
  int balance = 0;
  for (int i = 0; i < N; ++i) {
    balance += (s1[i] == '(' ? 1 : -1);
    if (balance < 0) {
      ++balance;
      *(--head) = '(';
    }
    *(tail++) = s1[i];
  }
  while (balance > 0) {
    *(tail++) = ')';
    --balance;
  }
  *tail = 0;
  printf("%s\n", head);
  return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}



signed main(){
	
	ll n;
	cin >> n;
	
	rep(i,1,10){
		if(n / i <= 9 && n % i == 0){
			cout << "Yes" << endl;
			return 0;
		}
	}
	
	cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
ll sum=0;
ll A[100005];
ll B[100005];

ll calc(ll a,ll d,ll n){
  return (a+a+d*(n-1))*n/2;
}
int main(){
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>A[i];
    sum+=A[i];
  }
  if( sum%calc(1,1,N) != 0 ){
    cout<<"NO"<<endl;
    return 0;
  }
  ll cc=0;
  ll cnt=sum/calc(1,1,N);
  for(int i=0;i<N;i++){
    B[i]=(A[(i+1)%N]-A[i]);
    ll dist=cnt-B[i];
    if(dist<0 || dist%N!=0){
      cout<<"NO"<<endl;
      return 0;
    }
    cc+=dist/N;
  }
  if(cc==cnt)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include<algorithm>
#include <cmath>
#include <vector>
 
using namespace std;
typedef pair<int, int> PII;
 
int main() {
    string s;
    cin >> s;
    int n;
    int len = s.size();
    cin >> n;
    vector<pair<int, char> > f;
    for (int i = 1; i <= n; ++i) {
        int op;
        cin >> op;
        if (op == 1) {
            f.emplace_back(1, '0');
        } else {
            int k;
            cin >> k;
            string cur;
            cin >> cur;
            f.emplace_back(k + 1, cur[0]);
        }
    }
    int num = 0;
    for (auto i : f) {
        if (i.first == 1) {
            num++;
            continue;
        }
        if (num % 2 == 0) {
            if (i.first == 2) s.insert(0, 1, i.second);
            else s.push_back(i.second);
        } else {
            if (i.first == 3) s.insert(0, 1, i.second);
            else s.push_back(i.second);
        }
    }
    if (num % 2)
        reverse(s.begin(), s.end());
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3572
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
using namespace std;
struct node{
    int u,w;
};
node p;
vector<node>q[100005];
int visit[100005];
int dis[100005],flag;
void query(int x){
    if(flag==1) return ;
    for(int i=0;i<q[x].size();i++){
        node y=q[x][i];
        if(visit[y.u]==1){
            if(dis[y.u]!=dis[x]+y.w) {
                flag=1;
                return ;
            }
            else continue;
        }
        visit[y.u]=1;
        dis[y.u]=dis[x]+y.w;
        query(y.u);
    }

}
int main(){
    int n,m,k,u,w;
    while(scanf("%d%d",&n,&m)!=EOF){
        memset(visit,0,sizeof(visit));
        for(int i=0;i<m;i++){
            scanf("%d%d%d",&k,&u,&w);
            p.u=u,p.w=w;
            q[k].push_back(p);
            p.u=k,p.w=-w;
            q[u].push_back(p);
        }
        for(int i=0;i<n;i++){
            if(visit[i]==0){
                flag=0;
                query(i);
            }
            if(flag==1){
                printf("No\n");
                break;
            }

        }
        if(flag==0) printf("Yes\n");
    }
    return 0;
}



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

int main(){
  	int n,memo = 0,l,r;
  	cin >> n;
  
  	rep(i,0,n){
      cin >> l >> r;
      memo += abs(r-l)+1;
    }
  
  	cout << memo << endl;
  	return 0;
}

Measured memory_bytes: 256
#include <iostream>
  #include <string>
  #include <vector>
  #include <algorithm>
  using namespace std;
  typedef long long ll;
  #define rep(i,n) for (int i=0;i < (int)(n);i++)

  char a[51][51];
  char b[51][51];

  int main(){
    int n,m;
    cin >> n >> m;
    rep(i,n){
      rep(j,n) cin >> a[i][j];
    }
    rep(i,m) rep(j,m) cin >> b[i][j];
    
    bool exit = false;
    for (int h=0;h < n;h++){
      for (int w=0; w < n;w++){
        if (h + m > n || w+m > n) continue;
        
        bool can = true;
        for (int i=0;i < m;i++){
          for (int j=0;j < m;j++){
            if (a[i+h][j+w] != b[i][j]) {
             can=false;
            }
          }
        }
        if (can) exit = true;
      }
    }

    if (exit) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
  }


Measured memory_bytes: 256