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

int n;
int b[4][4];
int a[4][4];
std::set<int> s;

void yes(){puts("Yes");exit(0);}

int main (){
        for (int i=1;i<=3;i++)
                for (int j=1;j<=3;j++)
                        std::cin >> a[i][j];
        std::cin >> n;
        for (int i=1,x;i<=n;i++){
                std::cin >> x;
                s.insert(x);
        }
        for (int i=1;i<=3;i++)
                for (int j=1;j<=3;j++)
                        b[i][j]=(s.find(a[i][j])!=s.end());
        for (int i=1;i<=3;i++){
                bool ok=true;
                for (int j=1;j<=3;j++)
                        ok&=b[i][j];
                if (ok)yes();
        }
        for (int i=1;i<=3;i++){
                bool ok=true;
                for (int j=1;j<=3;j++)
                        ok&=b[j][i];
                if (ok)yes();
        }
        if (b[1][1]&&b[2][2]&&b[3][3])yes();
        if (b[3][1]&&b[2][2]&&b[1][3])yes();
        puts("No");
        return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		char[] ch = scanner.next().toCharArray();
		int i = 0;
		for(int r = 0; r < 4; r++) {
			if(ch[r] == '+') {
				i++;
			}else {
				i--;
			}
		}
		System.out.println(i);
	}

}

Measured memory_bytes: 21716
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ld long double
#define int long long
#define dbgvi(x) cout << #x << " = "; for(int i = 0; i < (x.size()); ++i) cout << x[i] << " ";
using namespace std;

void no(){
    cout << "No\n";
}

void yes(){
    cout << "Yes\n";
}

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



void solve(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(b > a || b > d){
        no();
        return;
    }
    if(c >= b){
        yes();
        return;
    }
    int l = c + 1;
    int r = b - 1;
    if(l > r){
        yes();
        return;
    }
    l = (l - (a % b) + b) % b;
    r = (r - (a % b) + b) % b;
    if(l > r){
        r += b;
    }
    int g = gcd(b, d);
    int k = ((l + g - 1) / g) * g;
    if(k <= r){
        no();
        return;
    } else {
        yes();
        return;
    }
}


signed main(){
    int t = 1;
    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef DEBUG
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    cin >> t;
    //freopen("skyscraper.in", "r", stdin);
    //freopen("skyscraper.out", "w", stdout);
    //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, x;
    cin >> n >> x;
    int l[n];
    for (int i = 0; i < n;i++){
        cin >> l[i];
    }
    int ans = 0;
    int D = 0;
    ans++;
    for (int i = 0; i <n;i++){
        D += l[i];
        if(x < D){
            break;
        }
        ans++;
    }
    cout << ans << endl;
}


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

const int COLOR_NUM = 8;

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

  vector<int> clr(COLOR_NUM, 0);
  int clr_free = 0;
  while ( n-- > 0 ) {
    int rate;
    cin >> rate;
    int rank = rate/400;
    if ( rank < COLOR_NUM ) {
      clr[rank]++;
    } else {
      clr_free++;
    }
  }

  int mn = 0, mx = 0;
  for ( int i = 0; i < COLOR_NUM; i++ ) {
    if ( clr[i] > 0 ) { mn++; }
  }
  if ( mn == 0 && clr_free > 0 ) { mn = 1; clr_free--; }
  mx = mn + clr_free;

  cout << mn << ' ' << mx << endl;
  return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner stdin = new Scanner(System.in);
    while (true) {
      int a = stdin.nextInt();
      String op = stdin.next();
      int b = stdin.nextInt();
      if (op.equals("?")) {
        break;
      } else if (op.equals("+")) {
        System.out.println(a + b);
      } else if (op.equals("-")) {
        System.out.println(a - b);
      } else if (op.equals("*")) {
        System.out.println(a * b);
      } else {
        System.out.println(a / b);
      }
    }
  }

}

Measured memory_bytes: 18000
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <ctime>

#define inf 0x3f3f3f3f
#define Inf 0x3FFFFFFFFFFFFFFFLL
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, n) for (int i = 1; i <= (n); ++i)
#define clr(x, a) memset(x, (a), sizeof x)
using namespace std;
typedef long long ll;
int const N = 505;
char g[N][N];
int main() {
	int n, m; scanf("%d%d", &n, &m);
	rep(i, n) scanf(" %s", g[i]);
	rep(i, n) {
		rep(j, m - 1) {
			if (g[i][j] == '#') putchar('#');
			else if (i % 2 == 0 && j > 0) putchar('.');
			else putchar('#');
		}
		puts(".");
	}
	puts("");
	rep(i, n) {
		putchar('.');
		for (int j = 1; j < m; ++j) {
			if (g[i][j] == '#') putchar('#');
			else if (i % 2 != 0 && j < m - 1) putchar('.');
			else putchar('#');
		}
		puts("");
	}
	return 0;
}



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

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

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int N; cin >> N;
    pair<ll, ll> robot[N]; // <fin, start>
    rep(i, N){
        ll X, L; cin >> X >> L;
        robot[i] = make_pair(X+L, X-L);
    }

    sort(robot, robot+N);
    int ans = N;
    ll last_fin = robot[0].first;
    ll last_start = robot[0].second;
    for(int i = 1; i < N; i++){
        if(robot[i].second < last_fin) ans--;
        else{
            last_fin = robot[i].first;
            last_start = robot[i].second;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
	int main(){
		int a,b,c;
		cin >> a >> b >> c;
		if ( a > b )
			swap ( a , b );
		if ( a > c )
			swap ( a , c );
		if ( b > c )
			swap ( b , c );
		cout << a<<" " <<b<<" "<<c << endl;
	}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

int main(void) {
  using namespace std;

  uint N, K;
  cin >> N >> K;
  vector<string> D(K);
  for(uint i=0; i<D.size(); i++)
    cin >> D[i];

  for(uint i=N; i<=10*N; i++) {
    string I = to_string(i);
    bool satisfy = true;
    for(uint j=0; j<D.size(); j++) {
      if(I.find(D[j]) != string::npos){
        satisfy = false;
        break;
      }
    }
    if(satisfy) {
      cout << i << endl;
      return 0;
    }
  }
  
  return 0;
}


Measured memory_bytes: 256
mod = 10**9 + 7
def cmb(n,r,mod):
	a=1
	b=1
	r = min(r,n-r)
	for i in range(r):
		a = a*(n-i)%mod
		b = b*(i+1)%mod
	return a*pow(b,mod-2,mod)%mod

n,a,b = map(int,input().split())
count = 0
all = pow(2,n,mod) - 1
nCa = cmb(n,a,mod)
nCb = cmb(n,b,mod)
ans = all - (nCa + nCb)
while (ans < 0):
  ans += mod
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
  int n, k;
  char s[11];
  scanf("%d", &n);
  scanf("%s", &s);
  scanf("%d", &k);
  int i;
  char c = s[k - 1];
  for (i = 0; i < n; i++) {
    if (s[i] != c)
      s[i] = '*';
  }
  printf("%s", s);
  return 0;
}


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


int main() {
  
  long long N;
  

  cin >> N;

  string tmpStr;

  map<string, long long > score;  // string→count
  
  long long maxcount;
  
  for( long long i = 0; i<N;i++){
    cin >> tmpStr;
    score[tmpStr]++;
    if(maxcount < score[tmpStr]){
      maxcount = score[tmpStr];
    }
  }
  
  for (auto p : score) {
    auto k = p.first;
    auto v = p.second;
    if(p.second == maxcount){
    cout << k << endl;
    }
  }

  
}






Measured memory_bytes: 25216
n,m = map(int, input().split())
student = dict()
checkpoint = dict()
distance = dict()

for i in range(n):
    student[i] = list(map(int, input().split()))

for i in range(m):
    checkpoint[i] = list(map(int, input().split()))
    
for key in student:
    x1,y1 = student[key]
    minD = 10000000001
    minP = 10000000001
    for p in checkpoint:
        x2, y2 = checkpoint[p]
        d =  abs(x1 - x2) + abs(y1 - y2)
        if d < minD:
            minP = p
            minD = d
    print(minP+1)


        
    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#include<chrono>
#define ll long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define mt make_tuple
#define tc  ll t; cin>>t; while(t--)
#define io ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define F first
#define S second
#define vi vector<ll>
#define pii pair<ll,ll>
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define vii vector<pair<ll,ll>>
ll gcd(ll n,ll m)
{
    if(n==0)
            return m;
    return gcd(m%n,n);
}
bool ifprime(ll n)
{
if(n==1)
return false;
    ll i;
for(i=2;i*i<=n;i++)
{
if(n%i==0)
return false;
 
}
return true;
}
void disp(vi v)
{
    for(auto u:v)
    cout<<u<<" ";
    cout<<"\n";
}
void remleadzero(vector<int> &v)
{
    vector<int> u;
    int i=0;
    while(v[i]==0)
        i++;
    while(i<v.size())
    {
        u.push_back(v[i]);
        i++;
    }
    v=u;
}
#define mod 1000000007LL
/*
void myscanf(long long *n)
{
    register long long c=getchar_unlocked();
    *n=0;
    for(;(c<48 ||c>57);c=getchar_unlocked())
        ;
    for(;(c>47 && c<58);c=getchar_unlocked())
    {
        *n=(*n<<1)+(*n<<3)+(c&15);
    }
 
}
void fastscan(long long &number)
{
    bool negative = false;
    register long long c;
 
    number = 0;
 
    c = getchar_unlocked();
    if (c=='-')
    {
 
        negative = true;
 
        c = getchar_unlocked();
    }
 
 
    for (; (c>47 && c<58); c=getchar_unlocked())
        number = number *10 + c - 48;
 
 
    if (negative)
        number *= -1;
}
*/
ll fast_expo(ll n,ll m, ll md)
{
    ll a=1;
    while(m>0)
    {
        if(m&1) a=(a*n)%md;
        n=(n*n)%md;
        m/=2;
    }
    return a%md;
}
long long sqroot(long long n){
    long double N = n;
    N = sqrtl(N);
    long long sq = N-2;
    sq = max(sq,0LL);
    while(sq*sq<n){
        sq++;
    } 
    if((sq*sq)==n)
        return sq;
    return -1;
}

int main()
{
    io;
    int n;
    cin>>n;
    ll M;
    cin>>M;
    long long a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]>>=1;
    }
    long long L=a[0];
    for(int i=0;i<n;i++){
        L = (L/gcd(L,a[i]))*a[i];
        if(L>M){
            cout<<0;
            return 0;
        }
    }
    for(int i=0;i<n;i++){
        if(!((L/a[i])&1)){
            cout<<0;
            return 0;
        }
    }
    cout<<((M/L)+1)/2;
    return 0;
}


Measured memory_bytes: 1024
N = int(input())
array = list(map(int,input().split()))
x = array[0]
y = sum(array)-array[0]
ans = abs(x-y)
for i in range(1,N-1):
    x += array[i]
    y -= array[i]
    tmp = abs(x-y)
    if tmp < ans:
        ans = tmp
print(ans)

Measured memory_bytes: 23800
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
using ll = long long;
using vi = vector<ll>;
const int maxn = 1<<19, mod = 1e9 + 7;
string t;
int n, cnt[maxn], val[maxn], sz = 0;
int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin >> t;
	for(auto &i : t) {
		if(i == '1') ++sz, val[sz] = sz&1;
		else cnt[sz]++;
	}
	ll ans = 0;
	for(int i = 1; i <= sz; i++) ans += (i+1)/2;
	{
		int c[2], p = 0, rev = 0;
		c[0] = count(val+1, val+sz+1, 0);
		c[1] = count(val+1, val+sz+1, 1);
		for(int i = 0; i < sz; i++) {
			//cout << i << " " << c[0] << " " << c[1] << " " << p << '\n';
			if(cnt[i] && (val[i+1] ^ rev ^ 1)) {
				cnt[i]--;
				rev ^= 1;
				swap(c[0], c[1]);
				ans += p + c[1];
				//cout << c[0] << " " << c[1] << " " << p << '\n';
			}
			val[i+1] ^= rev;
			p += val[i+1];
			c[val[i+1]]--;
			//cout << i << " " << ans << '\n';
		}
	}
	{
		int c[2] = {0, 0}, x = count(val, val+sz+1, 1);
		for(int i = sz; i >= 0; i--) {
			if(cnt[i]&1) {
				swap(c[0], c[1]);
				ans += c[1] + x;
				cnt[i]--;
			}
			//cout << i << " " << ans << '\n';
			ans += (c[0] + c[1]) * 1ll * (cnt[i] / 2) + cnt[i] * 1ll * x;
			c[val[i]]++;
			x -= val[i];
			//cout << i << " " << ans << '\n';
		}
	}
	cout << ans;
}


Measured memory_bytes: 5144
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin>>n;
  vector<int> w(n);
  int R=0;
  rep(i,n){
    cin>>w.at(i);
    R+=w.at(i);
  }
  int ans=INT_MAX;
  int L;
  rep(i,n){
    ans=min(ans,abs(R-L));
    R-=w.at(i);
    L+=w.at(i);
  }
  cout<<ans<<endl;
}

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

    typedef long long int ll;
    #define pb         push_back
    #define mp         make_pair
    #define F          first
    #define S          second
    #define fl(i,a,b)  for(ll i=a;i<b;i++)
    #define pll        pair<ll,ll>
    #define pii        pair<int,int>
    #define all(v)     v.begin(),v.end()
    #define M 1000000007
    #define tr(v, it) for(auto it = v.begin(); it != v.end(); it++)
    using namespace std;



    int main()
    {

        ios_base::sync_with_stdio(false);
    	cin.tie(NULL);

         ll n,w;
         cin>>n>>w;
         ll val[n];
         ll weight[n];
         ll netval=0;
         for(int i=0; i<n; i++)
         {
             cin>>weight[i];
             cin>>val[i];
             netval+=val[i];
         }
         ll dp[n][netval+1];

         for(int i=0; i<n; i++)
         {
             for(int j=0; j<=netval; j++)
             {
                 if(i==0 && j==val[i])
                    dp[i][j]=weight[i];
                 else
                 dp[i][j]=-1;
             }
         }
          dp[0][0]=0;
        /* for(int i=0; i<n; i++)
         {
            for(int j=0; j<netval; j++)
            cout<<dp[i][j]<<" ";

            cout<<"\n";
         }
         */
         for(int i=1; i<n; i++)
         {
             for(int j=0; j<=netval; j++)
             {
                 if(dp[i-1][j]!=-1)
                 {
                     if(dp[i][j]==-1)
                        dp[i][j]=dp[i-1][j];
                     else
                     {
                         dp[i][j]=min(dp[i][j], dp[i-1][j]);

                     }

                     if(dp[i][j+val[i]]==-1)
                        dp[i][j+val[i]]= dp[i-1][j]+weight[i];
                     else
                        dp[i][j+val[i]]= min(dp[i-1][j]+weight[i], dp[i][j+val[i]]);

                // cout<<i<<" "<<j<<" "<<dp[i][j]<<"\n";
                  //cout<<i<<" "<<j+val[i]<<" "<<dp[i][j+val[i]]<<"\n";
                 }

             }
         }
         int result=INT_MIN;
         for(int i=0; i<=netval; i++)
         {
            // cout<<i<<" "<<dp[n-1][i]<<"\n";
             if(dp[n-1][i]<=w && dp[n-1][i]!=-1)
             {
                 if(i>result)
                    result=i;
             }
         }

        cout<<result;
       return 0;
    }


Measured memory_bytes: 81708
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var nm = arr.shift().split(" ").map(Number);
var n = nm[0];
var max = 0;
arr = arr.map(function(v){
   var ab = v.split(" ").map(Number);
   max = Math.max(max, n - ab[0]);
   return Math.max(0, n - ab[0]);
});
var sum = arr.reduce(function(a,b){
   return a+b;
});
console.log(sum-max);

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

int main() {

  int N, M;
  cin >> N >> M;

  vector<int> A(M);
  for (int i = 0; i < M; i++) {
    cin >> A[i];
  }

  // 昇順で確認する必要がある
  sort(A.begin(), A.end());

  vector<int> p = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

  // マッチをi本使ったときの桁数の最大値
  // 初期値は-1で埋めておく
  // 要素数は N + 7 (pの最大値) + α
  vector<int> dp(N+10, -1);

  dp[0] = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      int k = p[A[j]];
      dp[i + k] = max(dp[i + k], dp[i] + 1);
    }
  }

  // 残りのマッチの本数
  int remain = N;

  while (0 < remain) {

    // 答え
    int answer = 0;

    // 使うマッチの本数
    int use = 0;
    
    for (int i = 0; i < M; i++) {

      // 使いたいマッチの本数
      int k = p[A[i]];
      
      // マッチが使える場合
      if (k <= remain) {
      
        // kを使った後の残ったマッチの本数でも桁数が最大値が作れる場合はOK
        if (dp[remain - k] == dp[remain] - 1) {
          // OK場合でもMはできる限り大きい数にする
          answer = A[i];
          use = k;
        }

      }

    }

    // マッチの数を減らす
    remain -= use;

    cout << answer;
  
  }

  cout << endl;

  return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
 
    public static void main(String[] args) {
       int a,b,c;
       Scanner scan = new Scanner(System.in);
        
       a = scan.nextInt();
       b = scan.nextInt();
       c = scan.nextInt();
       if(a<b && b<c){
        System.out.println("Yes");
       }else{
        System.out.println("No");
       }
   }
 
}

Measured memory_bytes: 26236
using System;

namespace CantWaitForHolidays
{
    public enum Days
    {

        MON,
        TUE,
        WED,
        THU,
        FRI,
        SAT,
        SUN
    }

    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();
            Days result;
            Enum.TryParse(input, out result);
            var daysUntilSun = result - Convert.ToInt32(Days.SUN);
            var output = Math.Abs(Convert.ToInt32(daysUntilSun));

            if (output == 0)
            {
                output = Convert.ToInt32(Days.SUN + 1);
            }

            Console.WriteLine(output);
        }
    }
}

Measured memory_bytes: 13268
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

int main () {
	int n,i,count=0;
	int temp,temp1;
	string s;
	string bef = "Hoshino";
	string aft = "Hoshina";
	scanf("%d",&n);
	cin.ignore();
	for(i=0;i<n;i++)
	{
		getline(cin,s);
		string::size_type pos = s.find(bef);
		while(pos != string::npos){
			s.replace(pos, bef.size(), aft);
			pos = s.find(bef, pos + aft.size());
		}
		printf("%s\n",s.c_str());
	}
}

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

int main(){
 int64_t N,K;
 cin>>N>>K;
 
 if(K==1){
   cout<<N*N*N<<endl;
 }
 
 else if(K%2==1){
   cout<<(N/K)*(N/K)*(N/K)<<endl;
 }
 
 if(K%2==0){
  int64_t j=(2*N+K)/(2*K);
 
     cout<<(N/K)*(N/K)*(N/K)+j*j*j<<endl;
   
 }
}


Measured memory_bytes: 3624
#include<bits/stdc++.h> 
#define int long long
#define out(x) cout << #x << endl
using namespace std;
signed main()
{
    int t = 0, N; cin >> N;
    vector<pair<int, int>> v(N); for(int i = 0; i < N; i++) cin >> v[i].second >> v[i].first;
    sort(v.begin(), v.end());
    for(int i = 0; i < N; i++)
    {
        t += v[i].second;
        if(t > v[i].first)
        {
            out(No);
            return 0;
        }
    }
    out(Yes);
}

Measured memory_bytes: 3328
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 7;
int main(){
    int n;
    cin >> n;
    vi v;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        x--;
        v.pb(x);
    }
    int q = 0;
    int cnt = 0;
    for(int i = 0; i < v.size(); i++){
        if(v[i] != q){
            cnt++;
        }
        else{
            q++;
        }
    }
    if(cnt == n) cout << -1;
    else cout << cnt;
}

Measured memory_bytes: 1400
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
   int a,b,c,d,e,x,y,z,h,j,k;
   cin>>a>>b>>c>>d>>e>>x>>y>>z>>h>>j>>k;
   x=abs(a);
   y=x*c; h=b-a; j=h*e; z=b*e;
   if(a<0){
       k=y+d+z;
       cout<<k<<endl;
   }
   else if(a>0){
       cout<<j<<endl;;
   }
}



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

import sys
import os


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

S_num = N
c_num = M

# cが豊富にないとき
if c_num // 2 <= S_num:
    print(c_num // 2)
else:
    # まずS個作れる
    all = S_num
    # cを消費する
    c_num -= (2 * S_num)

    # 残りのcで何個作れるか
    all += c_num // 4

    print(all)

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

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

	for(int i=0; i<n; i++){
		int u, k, v;
		cin >> u >> k;
		for(int j=0; j<k; j++){
			cin >> v;
			matrix[u-1][v-1] = 1;
		}
	}
		
	for(int i=0; i<n; i++){
		cout << matrix[i][0];
		for(int j=1; j<n; j++){
			cout << " " << matrix[i][j];
		}
		cout << endl;
	}

	return 0;
}

	

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

using namespace std;

#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)

const int maxn = 1e5 + 5;
int N, A[maxn], B[maxn], Cnt;
map<int, int> mp;

int main() {
  //  freopen("c.in", "r", stdin);
  //  freopen("c.out", "w", stdout);
  scanf("%d", &N);
  foru(i, 1, N) scanf("%d", &A[i]);
  foru(i, 1, N) B[i] = A[i];
  sort(B + 1, B + N + 1);
  foru(i, 1, N) mp[B[i]] = i;
  foru(i, 1, N) A[i] = mp[A[i]];
  foru(i, 1, N) Cnt += (A[i] & 1) ^ (i & 1);
  printf("%d\n", Cnt >> 1);
  return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main(){
	fast;
	ll k,x; cin>>k>>x;
	(k*500>=x)?cout<<"Yes\n":cout<<"No\n";
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

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

    int main (){
        int n,a,b;
        cin >> n >> a >> b;
        string s;
        cin >> s;
        int cnt=0;
        int cntb=0;
        
        rep(i,s.size()){
            switch (s[i]){
            case 'a':
                if(cnt < a+b){
                cout << "Yes" << endl;
                cnt++;
                }
                else{
                    cout << "No" << endl;
                }
                break;
            case 'b':
            if(cnt<a+b && b > cntb){
                cout << "Yes" << endl;
                cnt++;
                cntb++;
            }
            else{
                cout  << "No" << endl;
            }
            
            break;
            case 'c':
            cout << "No" << endl;
            break;
            default:
                break;
            }
        }
        return 0;
    }

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> to[100005];
const int inf = 100000000;

int main() {
  int N,M;
  cin >> N >> M;
  int a,b;
  for(int i=0;i<M;i++){
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  queue<int> q;
  vector<int> dist(N,inf);
  vector<int> pre(N,-1);
  dist.at(0) = 0;
  q.push(0);
  while(!q.empty()){
    int v = q.front();
    q.pop();
    for(int u : to[v]){
      if(dist[u] != inf) continue;
      dist[u] = dist[v] + 1;
      pre[u] = v;
      q.push(u);
    }
  }
  
  cout << "Yes" << endl;
  
  for(int i=0;i<N;i++){
    if(i == 0) continue;
    int ans = pre[i];
    ans++;
    cout << ans << endl;
  }
  
  return(0);
}


Measured memory_bytes: 10616
n = int(input())

li = [ list(map(int,input().split())) for i in range(n) ]

dp = [[0 for i in range(3)] for j in range(n) ]

dp[0] = li[0]

for i in range(1,n):
    for j in range(0,3):
        for k in range(0,3):
            if k != j:
                if dp[i][k] < (dp[i-1][j] + li[i][k]):
                    dp[i][k] = dp[i-1][j] + li[i][k]

  
print(max(dp[-1]))

Measured memory_bytes: 50224
#include <stdio.h>

int main(void) {
 
	// ??°????????\???????????°????????????????????\???
	double ensyuritsu = 3.14159265358979323846;
	double num;
	scanf("%lf", &num);
 
	// ??\??????????????°????¨????????????????
	printf("%.6f %.6f\n", num*num*ensyuritsu, 2*num*ensyuritsu);
 	return 0;
}

Measured memory_bytes: 1796
object Main extends App {
  for(line <- io.Source.stdin.getLines()) {
    val numAry = line.split(' ').map { _.toInt }
    
    if(numAry(0) < numAry(1) && numAry(1) < numAry(2))
        println("Yes")
    else
        println("No")
  }
}


Measured memory_bytes: 43840
#include<bits/stdc++.h>
#define ll          long long int
#define ld          double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         1000000000000000000
#define MAXN        200005
#define LOG         20
#define mod         1000000007
using namespace std;
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,w,i,j,ans=0,total_value=0;
    cin>>n>>w;
    ll weight[n],value[n];
    for(i=0;i<n;i++){
        cin>>weight[i]>>value[i];
        total_value+=value[i];
    }
    ll dp[total_value+1];
    for(i=1;i<=total_value;i++){
        dp[i]=MAX;
    }
    dp[0]=0;
    for(i=0;i<n;i++){
        for(j=total_value;j>=value[i];j--){
            dp[j]=min(dp[j],dp[j-value[i]]+weight[i]);
        }
    }
    for(i=0;i<=total_value;i++){
        if(dp[i]<=w){
            ans=i;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0), cin.tie(0);
    string s1, s2;
    cin >> s1 >> s2;
    bool same = true;
    if (s1.size() + 1 != s2.size())
    {
        cout << "No";
        return 0;
    }
    for (int i = 0; i < s1.length(); i++)
    {
        if (s1[i] == s2[i])
            continue;
        else
        {
            same = false;
            cout << "No";
            return 0;
        }
    }
    if (same)
        cout << "Yes";
}

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

int main() {
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
    scanf("%d", &a[i]);
  vector<long long> pref_sum(n, a[0]), pref_xor(n, a[0]);
  for (int i = 1; i < n; ++i) {
    pref_sum[i] = pref_sum[i - 1] + a[i];
    pref_xor[i] = pref_xor[i - 1] ^ a[i];
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    int low = i, high = n;
    while (low + 1 < high) {
      int mid = (low + high) / 2;
      long long x = pref_sum[mid] - (i > 0 ? pref_sum[i - 1] : 0);
      long long y = pref_xor[mid] ^ (i > 0 ? pref_xor[i - 1] : 0);
      if (x == y)
        low = mid;
      else
        high = mid;
    }
    ans += low - i + 1;
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
vector<int> divisor(int n) {
  vector<int> res;
  for(int i=1; i*i<=n; i++) {
    if(n % i == 0) {
      res.push_back(i);
      if(i != n / i) res.push_back(n / i);
    }
  }
  return res;
}
int n;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;

  ll ans = 0;
  FOR(i, 1, n) {
    ans += divisor(i).size();
  }

  cout << ans << endl;
}


Measured memory_bytes: 3656
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::BTreeMap;

fn main() {
    input!(h: usize, w: usize, n: usize, mut ass: [usize; n]);

    let mut graph = vec![vec![0usize; w]; h];
    let mut dxy = vec![];
    for y in 0..h {
        if y % 2 == 0 {
            for x in 0..w {
                dxy.push((y, x));
            }
        } else {
            for x in (0..w).rev() {
                dxy.push((y, x));
            }
        }
    }

    let mut num = 0;
    for &(y, x) in dxy.iter() {
        graph[y][x] = num + 1;
        if ass[num] >= 1 {
            ass[num] -= 1;
        }
        if ass[num] == 0 {
            num += 1;
        }
    }

    for i in 0..h {
        for j in 0..w {
            if j == w - 1 {
                print!("{}", graph[i][j]);
            } else {
                print!("{} ", graph[i][j]);
            }
        }
        println!("");
    }
}


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

n = int(input())
flower = list(map(int, input().split()))

#左から水をやると考えたとき、1つ左のほうが自分以上だったら、その花を育てるために、自分にも十分な水がまかれている。
#1つ左が自分より低かったら、自分には、その高さの差だけの水が与えられる必要がある。
#それは、自分の1つ右の花から見ても同じこと。
#左の花から見た、自分の相対的な高さ　の和が、必要な水の量。
#最初の花を育てる水は、あらかじめ計上。

water = flower[0]

for i in range(1, n):
    if flower[i] > flower[i-1]:
        water += flower[i] - flower[i-1]

print(water)

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

#define F first
#define S second
#define prev azaza
#define MP make_pair
#define PB push_back

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 100111, inf = 1000111222;

vector<int> ai;
vector<int> bi;
priority_queue<pair<int, int>> s;

int a[max_n];
int b[max_n];
int n;
ll sa = 0, sb = 0;

int main()
{
    //freopen("input.txt", "r", stdin);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < n; ++i) {
        s.push(MP(a[i] + b[i], i));
    }
    for (int i = 0; i < n; ++i) {
        pair<int, int> val = s.top();
        s.pop();
        if (i % 2 == 0) {
            sa += a[val.S];
        } else {
            sb += b[val.S];
        }
    }
    cout << (sa - sb) << endl;


    return 0;
}





Measured memory_bytes: 2168
#include<bits/stdc++.h>
#define ll int
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define pii pair<ll,ll>

using namespace :: std;

const ll maxn=1e5+500;
const ll mod=1e9+7;
const ll inf=1e9+500;

ll a[maxn];
ll ans[maxn];
ll b[maxn];

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

    ll n,m;
    cin>>n>>m;
    for(ll i=0;i<m;i++){
        cin>>a[i];
    }
    if(n==1){
        cout<<a[0]<<endl<<1<<endl<<1;
        return 0;
    }
    if(m==1){
        cout<<a[0]<<endl<<2<<endl<<1<<' '<<a[0]-1<<endl;
        return 0;
    }
    sort(a,a+m);

    ll v=n%2;
    for(ll i=0;i<m;i++){
        v+=a[i]%2;
    }
    if(v>2){
        cout<<"Impossible";
        return 0;
    }

    if(n&1){
        for(ll i=0;i<m;i++){
            if(a[i]&1){
                ans[0]=a[i];
            }
        }
        ll cnt=1;
        for(ll i=0;i<m;i++){
            if(a[i]%2==0){
                ans[cnt++]=a[i];
            }
        }

        for(ll i=0;i<m;i++){
            cout<<ans[i]<<' ';
        }
        cout<<endl;

        cout<<m<<endl<<ans[0]+1<<' ';
        for(ll i=1;i+1<m;i++){
            cout<<ans[i]<<' ';
        }
        cout<<ans[m-1]-1;
    }else{
        if(v==0){
            ll cnt=0;
            for(ll i=0;i<m;i++){
                ans[cnt++]=a[i];
            }
            for(ll i=0;i<m;i++){
                cout<<ans[i]<<' ';
            }
            cout<<endl;

            cout<<m<<endl<<ans[0]+1<<' ';
            for(ll i=1;i+1<m;i++){
                cout<<ans[i]<<' ';
            }
            cout<<ans[m-1]-1;
        }else{
            ll cnt=0;
            for(ll i=0;i<m;i++){
                if(a[i]&1){
                    ans[cnt]=a[i];
                    cnt=m-1;
                }
            }
            if(ans[0]>ans[m-1])swap(ans[0],ans[m-1]);
            cnt=1;
            for(ll i=0;i<m;i++){
                if(a[i]%2==0){
                    ans[cnt++]=a[i];
                }
            }

            for(ll i=0;i<m;i++){
                cout<<ans[i]<<' ';
            }
            cout<<endl;
            if(ans[0]==1 && ans[m-1]==1){
                cout<<m-1<<endl;
                for(ll i=1;i+1<m;i++){
                    cout<<ans[i]<<' ';
                }
                cout<<2;
                return 0;
            }
            cout<<m<<endl<<ans[0]+1<<' ';
            for(ll i=1;i+1<m;i++){
                cout<<ans[i]<<' ';
            }
            cout<<ans[m-1]-1;
        }
    }
}


Measured memory_bytes: 256
H, W = [int(x) for x in input().split()]
M = [list(input()) for _ in range(H)]

def flip(arr):

    x = len(arr[0])
    y = len(arr)

    newArr = [[None] * y for _ in range(x)]
    for xi in range(x):
        for yi in range(y):
            newArr[xi][yi] = arr[yi][xi]
    return newArr

def main():

    m = M
    m = list(filter(lambda row: any([n == '#' for n in row]), m))
    m = flip(m)

    m = list(filter(lambda row: any([n == '#' for n in row]), m))
    m = flip(m)

    for row in m:
        print(''.join(row))
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
import java.util.*;

class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String ans = "APPROVED";

		for (int i=0; i<N; i++) {
			int A = sc.nextInt();
			if (A % 2 == 0) {
				if (A % 3 == 0 || A % 5 == 0) {
					ans = "APPROVED";
				} else {
					ans = "DENIED";
					break;
				}
			}
		}
		System.out.println(ans);
	}
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

constexpr int64 P = 1000000007;

struct FiniteField {
 private:
  int64 x;
 public:
  FiniteField(int64 x) : x(x) {
    if (x > P || x < 0) { cerr << "Invalied FiniteField!" << endl; exit(1); }
  }
  FiniteField() : x(0) {}
  int64 Value() const { return x; }
  inline FiniteField operator+(FiniteField o) const {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) const {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) const {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) const {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

template<typename T>
vector<vector<T>> Make2DVector(int d1, int d2, T default_value) {
  return vector<vector<T>>(d1, vector<T>(d2, default_value));
}

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

  int n, a, b;
  cin >> n >> a >> b;
  if (a > b) swap(a, b);

  auto dp1 = Make2DVector<FiniteField>(n + 1, b, 0);
  dp1[0][0] = 1;
  auto dp2 = vector<FiniteField>(n + 1, 0);
  dp2[0] = 1;
  auto dp3 = Make2DVector<FiniteField>(n + 1, b, 0);
  dp3[0][0] = 1;

  for (int i = 1; i <= n; i++) {
    if (i >= 2) {
      dp1[i][1] += dp2[i - 2];
      if (i - a - 1 >= 0) dp1[i][1] -= dp2[i - a - 1];
    }

    for (int j = 1; j < b; j++) {
      dp1[i][j] += dp1[i - 1][j - 1];

      if (i - a - 1 >= 0 && j - a - 1 >= 0) {
        dp1[i][j] += dp3[i - a - 1][j - a - 1];
      }
    }

    dp2[i] = dp2[i - 1];
    for (int j = 1; j < b; j++) {
      dp2[i] += dp1[i][j];
    }

    for (int j = 1; j < b; j++) {
      dp3[i][j] = dp3[i - 1][j - 1] + dp1[i][j];
    }
  }

  FiniteField r = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < b; j++) {
      int l = j;
      if (n - i >= a) {
        l += n - i;
      }
      if (l < b) {
        r += dp1[i][j];
      }
    }
  }

  FiniteField ans = 1;
  for (int i = 0; i < n; i++) ans *= 2;
  ans -= r;
  cout << ans.Value() << endl;
}

Measured memory_bytes: 394364
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll a, b, k;
    cin >> a >> b;
    if((-a - b) / 2 == (-b - a) / 2){
        k = abs(-a - b) / 2;
        if(abs(a - k) == abs(b - k))
            cout << k << endl;
        else
            cout << "IMPOSSIBLE" << endl;
    }
     else
        cout << "IMPOSSIBLE" << endl;



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  for(int i=sx; i<tx; i++){
    cout << "R";
  }
  for(int i=sy; i<ty; i++){
    cout << "U";
  }
  for(int i=sx; i<tx; i++){
    cout << "L";
  }
  for(int i=sy; i<ty; i++){
    cout << "D";
  }
  cout << "D";
  for(int i=sx; i<tx+1; i++){
    cout << "R";
  }
  for(int i=sy; i<ty+1; i++){
    cout << "U";
  }
  cout << "L";
  cout << "U";
  for(int i=sx; i<tx+1; i++){
    cout << "L";
  }
  for(int i=sy; i<ty+1; i++){
    cout << "D";
  }
  cout << "R";
  return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    map<int,int> l,r;
    rep(i,n){
        l[a[i]+i]++;
        r[i-a[i]]++;
    }
    int ans=0;
    for(auto e:l){
        ans+=e.se*r[e.fi];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 39056
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        init();
        int n = nextInt();
        long ans = 0;
        for (int i = 1; i <= n; i++) {
            String num = Integer.toString(i);
            int a = num.charAt(0) - '0';
            int b = num.charAt(num.length() - 1) - '0';
            int nums = numOfNums(n, b, a);
//            System.out.println(i + "->" + nums);
            ans += nums;
        }

        System.out.println(ans);
    }

    private static int numOfNums(int max, int a, int b) {
        if (a == 0 || b == 0) return 0;
        int maxLength = Integer.toString(max).length();
        int count = 0;
        if (a == b && a <= max) count++;

        for (int length = 2; length < maxLength; length++) {
            count += (int) Math.pow(10, length - 2);
        }
        if (maxLength == 1) return count;

        int pow10 = (int) Math.pow(10, maxLength - 1);
        int min = 0;
        int maxx = (int) Math.pow(10, maxLength - 2) - 1;

        while (min < maxx) {
            int mid = min + (maxx - min) / 2;
            int num = calcNum(a, b, mid, pow10);
            int num1 = calcNum(a, b, mid + 1, pow10);
            if (num <= max && num1 > max) break;
            if (num < max) min = mid + 1;
            if (num > max) maxx = mid - 1;
        }
//        if (a == 1 && b == 1) System.out.println(min + " " + maxx);
        int mid = min + (maxx - min) / 2;
        int num = pow10 * a + mid * 10 + b;
        if (num <= max) count += mid + 1;
        return count;
    }

    private static int calcNum(int a, int b, int mid, int pow10) {
        return pow10 * a + mid * 10 + b;
    }

    //Input Reader
    private static BufferedReader reader;
    private static StringTokenizer tokenizer;

    private static void init() {
        reader = new BufferedReader(new InputStreamReader(System.in));
        tokenizer = new StringTokenizer("");
    }

    private static String next() throws IOException {
        String read;
        while (!tokenizer.hasMoreTokens()) {
            read = reader.readLine();
            if (read == null || read.equals(""))
                return "-1";
            tokenizer = new StringTokenizer(read);
        }

        return tokenizer.nextToken();
    }

    private static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }
}

Measured memory_bytes: 38608
n,m=map(int,input().split())
wa=[0 for _ in range(n)]
ac=[0 for _ in range(n)]
for i in range(m):
	ps,s = input().split()
	p = int(ps)
	if s == "WA":
		if ac[p-1] == 0:
			wa[p-1] += 1
	if s == "AC":
		if ac[p-1] == 0:
			ac[p-1] = 1
wasum = 0
for i in range(n):
	if ac[i] == 1:
		wasum += wa[i]
print(sum(ac),wasum)

Measured memory_bytes: 4760
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ull;
#define MAX_WEIGHT 100005
#define NUM_OF_ITEM 102
lli dp[NUM_OF_ITEM][MAX_WEIGHT];
lli n, maxWeight;
lli w[NUM_OF_ITEM], v[NUM_OF_ITEM];

lli solve(lli i, lli cw){
    if(dp[i][cw] != -1) return dp[i][cw];
    if(i == n) return 0;
    lli ans1 = 0, ans2 = 0;
    if(cw + w[i] <= maxWeight){
        ans1 = v[i] + solve(i+1, cw + w[i]);
    }
    ans2 = solve(i+1, cw);
    return dp[i][cw] = max(ans1, ans2);
}

int main(){
    //freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int T=1, cs=1;
    //scanf("%d", &T);
    while(T--){

        memset(dp, -1, sizeof(dp));
        scanf("%lld %lld", &n, &maxWeight);
        for(lli i=0; i<n; i++){
            scanf("%lld %lld", &w[i], &v[i]);
        }
        //printf("Case %d: %lld\n", cs++, solve(0, 0));
        cout<<solve(0, 0)<<endl;

    }

    return 0;
}

Measured memory_bytes: 80000
n = gets.to_i
list = n.times.map do
  input = gets.split
  [input[0].to_f, input[1]]
end
res = 0.0
list.each do |item|
  if item[1] == "JPY"
    res += item[0]
  elsif
    res += item[0] * 380000
  end
end
puts res

Measured memory_bytes: 1788
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
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; }
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define DEBUG(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(int argc, const char * argv[]) {
  std::cout << std::fixed << std::setprecision(15);

  ll N; cin >> N;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];

  vector<ll> v;
  rep(bit, 1 << N){
    ll tmp = 0;
    rep(j, N){
      if(bit >> j & 1) tmp += A[j];
    }
    v.push_back(tmp);
  }
  sort(ALL(v));
  int q; cin >> q;
  rep(i, q){
    ll m; cin >> m;
    auto it = lower_bound(ALL(v), m);
    if(it != v.end()){
      if(*it == m)
        cout << "yes" << endl;
      else 
        cout << "no" << endl;
    }
    else{
      cout << "no" << endl;
    }
  }
}  



Measured memory_bytes: 11164
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 100005;

int main() {
    int n, d, x; cin >> n >> d >> x;
    int sum = x;
    rep(i,n) {
        int a; cin >> a;
        sum += (d-1)/a+1;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256