akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next()); 
        int[][] a = new int[4][13];
        for (int k = 0; k < n; k++) {
            String suit = sc.next();
            int rank = Integer.parseInt(sc.next());
            switch (suit) {
                case "S" :
                    a[0][rank-1] = 1;
                    break;
                case "H" :
                    a[1][rank-1] = 1;
                    break;
                case "C" :
                    a[2][rank-1] = 1;
                    break;
                case "D" :
                    a[3][rank-1] = 1;
                    break;
                default :
                    break;
            }
        } 
        for (int i = 0; i < 4; i++)
            for (int j = 0; j < 13; j++)
                if (a[i][j] == 0)
                    switch  (i) {
                        case 0 :
                            System.out.print("S ");
                            System.out.println(j+1);
                            break;
                        case 1 :
                            System.out.print("H ");
                            System.out.println(j+1);
                            break; 
                        case 2 :
                            System.out.print("C ");
                            System.out.println(j+1);
                            break;
                        case 3 :
                            System.out.print("D ");
                            System.out.println(j+1);
                            break;
                        default :
                            break;
                    }
    }
}


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

int main() {
  long long N;
  cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  cout<<a[N/2]-a[N/2-1];
  

}

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

int dp[100005][3];

int main(){
    
    int n; 
    cin>>n;
    
    int v[n][3];
    for(int i=0; i<n; i++){
        for(int j=0; j<3; j++)
            cin>>v[i][j];
    }
    
    dp[0][0] = v[0][0];
    dp[0][1] = v[0][1];
    dp[0][2] = v[0][2];
    
    for(int i=1; i<n; i++){
        
        for(int j=0; j<3; j++){
            int x = INT_MIN;
            for(int k=0; k<3; k++){
            if(j!=k){
            dp[i][j] = max((dp[i-1][k])+v[i][j],x);
            x = dp[i][j];
            }
            }
        }
        
    }
 //   cout<<dp[n-1][0]<<" "<<dp[n-1][1]<<" "<<dp[n-1][2]<<endl;
    
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
    
}

Measured memory_bytes: 5908
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int A, B;
    cin >> A >> B;
    if(A <= 9 && B <= 9)
    {
        cout << A * B << endl;
    }
    else
    {
        cout << "-1" << endl;       
    }
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{   char a[100000];
    long long int n=0,i,j=0,b,s=0,m=0;
           cin>>a;
           for(i=0;i<strlen(a);i++){
             if(a[i]=='+'){
                s++;
             }
            else
                s--;

           }
      cout<<s<<endl;

return 0;
}


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

#define   ll    long long int

ll n, k;
vector<int> good[22];
vector<int> bad[22];

int main( )
{
    int isGood[22];
    int n, i, j, k, x, y, l, c;
    cin >> n;
    int a;
    for (i = 1; i <= n; i++)
    {
        cin >> a;
        while (a--)
        {
            cin >> x >> y;
            if (y == 0)
                bad[i].push_back(x);
            else
                good[i].push_back(x);
        }
    }
    int mx = 0;
    for (i = 1; i <= (1 << n); i++)
    {
        memset(isGood, 0, sizeof isGood);
        c = 0;
        for (j = 0; j < n; j++)
        {
            if ( (i & (1 << j))  != 0 )
            {
                isGood[j + 1] = 1;
                c++;
            }
        }
        //cout << i << "  " << c << '\n';
        int fl = 1;
        for (j = 1; fl == 1 && j <= n; j++)
        {
            if (isGood[j] == 1)
            {
                for (k = 0; fl == 1 && k < (int) good[j].size( ); k++)
                {
                    if (isGood[good[j][k]] == 0)
                    {
                        fl = 0;
                        break;
                    }
                }
                for (k = 0; fl == 1 && k < (int) bad[j].size( ); k++)
                {
                    if (isGood[bad[j][k]] == 1)
                    {
                        fl = 0;
                        break;
                    }
                }
            }
        }
        //cout << fl << ' ' << c << '\n';
        if (fl == 1)
            mx = max(mx, c);
    }
    cout << mx << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<cstdlib>
#include<math.h>
using namespace std;

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; }

typedef pair<int, int> pii;



int main() {
	
	int n;
	
	long long cnt[100001] = { 0 }, a[100001] = { 0 },ans=0;
	

	cin >> n;
	vector<string> s(n);

	for (int i = 0; i < n; i++) {
		cin >> s[i];
		sort(s[i].begin(),s[i].end());
		
	}

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

	int p = 0;
	
	for (int i = 0; i < n-1; i++) {
		int cmp = 0;
		for (int j = 0; j < 10; j++) {
			
			if (s[i][j] == s[i+1][j])cmp++;
			
				
			
		}
		if (cmp == 10)cnt[p]++;
		else p++;
	}
	for (int i = 0; i < n; i++) {
		ans += (cnt[i] + 1)*cnt[i]/2;
	}

	cout << ans << endl;
	
	



	return 0;
}


Measured memory_bytes: 8064
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
 
int main(void){
char s[100];
scanf("%s",s);
for(int i=0;s[i]!='\0';i++){
    if(i%2==0){
        if(s[i]!='h'){printf("No\n");return 0;}
    }
    else{
        if(s[i]!='i'){printf("No\n");return 0;}
    }
    if(s[i]!='h'&&s[i]!='i'){printf("No\n");return 0;}
    if(s[strlen(s)-1]!='i'){printf("No\n");return 0;}
}
 
printf("Yes\n");
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

int main() {
    long int n, W;
    cin >> n >> W;
    vector<int> w(n), v(n);
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
        cin >> v[i];
    }
    vector<vector<long int>> KS(n + 1, vector<long int>(W + 1));
    for (int i = 0; i <= n; ++i) {
        KS[i][0] = 0;
    }
    for (int j = 0; j <= W; ++j) {
        KS[0][j] = 0;
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= W; ++j) {
            if (j >= w[i - 1])
                KS[i][j] = max(KS[i - 1][j], KS[i - 1][j - w[i - 1]] + v[i - 1]);
            else
                KS[i][j] = KS[i - 1][j];
        }
    }
    printf("%li", KS[n][W]);
}



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

using namespace std;

#define forn(i,n) for ( int i=0 ; i < n ; i++ )
#define all(a) (a).begin(), (a).end()
#define lb lower_bound
#define ub upper_bound
#define vi vector<int >
#define pii pair<int, int>
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SQ(a) (a)*(a)
#define ll long long
#define lli long long int
#define ull unsigned long long
#define endl '\n'
#define Pi(a) printf("%d\n",a);
#define debug2(a,b) printf("%d\t%d\n",a,b);
#define debug1(a) printf("%d\n",a);
#define Si(a) scanf("%d",&a);
#define mod 1000000007
#define w(n) while(n--)



int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	//code
	int arr[3];
	forn(i,3) cin >> arr[i];
	sort(arr,arr+3);
	cout << abs(arr[1]-arr[0])+abs(arr[2]-arr[1]);
	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll,ll> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n), gcd_left(n), gcd_right(n);
    rep (i, n) cin >> a[i];
    gcd_left.front() = a.front();
    rep (i, n - 1) gcd_left[i + 1] = gcd(gcd_left[i], a[i + 1]);
    rep (i, n) eprintf("%d ", gcd_left[i]); eprintf("\n");
    gcd_right.back() = a.back();
    reprev (i, n - 1) gcd_right[i] = gcd(gcd_right[i + 1], a[i]);
    rep (i, n) eprintf("%d ", gcd_right[i]); eprintf("\n");
    int ans = max(gcd_left[n - 2], gcd_right[1]);
    rep (i, n - 2) chmax(ans, gcd(gcd_left[i], gcd_right[i + 2]));
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1408
import java.util.*;

public class Main {
  private static int N;
  private static long K;
  private static int[] A;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    N = sc.nextInt();
    K = sc.nextLong();
    A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = Integer.parseInt(sc.next());
    }
    Arrays.sort(A);
    
    long ok = -1_000_000_000_000_000_005L;
    long ng = 1_000_000_000_000_000_005L;
    while (ok+1 < ng) {
      long m = (ok+ng)/2;
      if (isOk(m)) {
        ok = m;
      } else {
        ng = m;
      }
    }
    System.out.println(ok);
  }
  private static boolean isOk(long x) {
    long count = 0;
    for (int i = 0; i < N; i++) {
      count += calcCount(i, x);
      if (count >= 2*K) return false;
    }
    return count/2 < K;
  }
  private static int calcCount(int idx, long x) {
    int ok;
    int ng;
    if (A[idx] >= 0) {
      long max = (long)A[idx]*A[N-1];
      long min = (long)A[idx]*A[0];
      if (max < x) {
        return N-1;
      }
      if (x <= min) {
        return 0;
      }
      ok = 0;
      ng = N-1;
    } else {
      long max = (long)A[idx]*A[0];
      long min = (long)A[idx]*A[N-1];
      if (max < x) {
        return N-1;
      }
      if (x <= min) {
        return 0;
      }
      ok = N-1;
      ng = 0;
    }
    while ((A[idx] >= 0 && ok+1 < ng)
          || (A[idx] < 0 && ng+1 < ok)) {
      int m = (ok+ng)/2;
      if ((long)A[idx]*A[m] < x) {
        ok = m;
      } else {
        ng = m;
      }
    }
    if (A[idx] >= 0) {
      return idx <= ok ? ok : ok+1;
    } else {
      return idx >= ok ? N-ok-1 : N-ok;
    }
  }
}

Measured memory_bytes: 51160
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	for (int k = 2; k * (k - 1) / 2 <= n; k++) {
		if (k * (k - 1) / 2 == n) {
			cout << "Yes\n";
			cout << k << endl;
			vector<vector<int>> ans(k);
			int c = 0;
			for (int i = 0; i < k; i++) {
				for (int j = i + 1; j < k; j++) {
					ans[i].push_back(c);
					ans[j].push_back(c);
					c++;
				}
			}
			for (auto t : ans) {
				cout << t.size() << ' ';
				for (auto x : t) {
					cout << x + 1 << ' ';
				}
				cout << '\n';
			}
			return 0;
		}
	}
	cout << "No\n";
}

Measured memory_bytes: 4248
fun intList() = readLine()?.split(" ")?.map(String::toInt) ?: TODO()
fun main(args: Array<String>) {
    val (n, y) = intList()
    0.until(Math.min(n, y / 10000) + 1).forEach { i ->
        if (i * 10000 == y && i == n) {
            println("$i 0 0")
            return
        }
        0.until(Math.min(n - i, y / 5000) + 1).forEach { j ->
            if (i * 10000 + j * 5000 == y && i + j == n) {
                println("$i $j 0")
                return
            }
            val s = n - i - j
            val v = i * 10000 + j * 5000 + s * 1000
            if (v == y) {
                println("$i $j $s")
                return
            }
        }
    }
    println("-1 -1 -1")
}

Measured memory_bytes: 40272
//----------ACCIDENTAL COMPETITIVE PROGRAMMER---------------------

#include<bits/stdc++.h>

/*
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
*/
using namespace std;

#define LL long long
#define LD long double
#define PB push_back
#define MP make_pair


const LL MOD = (1e9) + 7 ;
const LD EPS = 0.0000001 ;
const int N = 100000 + 50;

LL cache[N];
LL height[N];
int n;

LL solve(int idx)
{
	if (idx == n)
		return 0;
	LL &ans = cache[idx];
	if (ans != -1)
		return ans;
	ans = 0;
	ans = solve(idx + 1) + abs(height[idx] - height[idx + 1]);
	if (idx + 2 <= n)
		ans = min(ans, solve(idx + 2) + abs(height[idx] - height[idx + 2]));
	return ans;
}


int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    for (int i = 0 ; i < N; i++)
    	cache[i] = -1;
    cin >> n;
    for (int i = 1; i <= n; i++)
    	cin >> height[i];

    cout << solve(1) << endl;

	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <map>
#include <algorithm>
#include <stack>
#include <cstring>

#define ll long long
#define MP make_pair
#define PB push_back
#define P push
#define f first
#define se second
#define S size()
#define B begin()
#define E end()
#define PI acos(-1)
#define fscan1(n)  scanf("%d",&(n));
#define fscan2(n,m)  scanf("%d %d",&(n),&(m));
#define fscan3(n,m,k)  scanf("%d %d %d",&(n),&(m),&(k));

const int N = 1e5 + 100;
const int M = 2e5 + 100;
const ll oo = 1e18;

int n, m, k, t, q, h, a, b, c, w, x, y, z;
using namespace std;


ll dp[105][N];

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

	vector<pair<int, int> >v(n + 1);

	for(int i = 1; i <= n; i++){
		cin >> v[i].f >> v[i].se;
	}

	sort(v.B, v.E);

	for(int i =1; i <= n; i++){
		x = v[i].f;
		y = v[i].se;
		for(int j = 1; j <= m; j++){
			dp[i][j] = max(dp[i][j - 1], (j - x < 0) ? 0 : dp[i - 1][j - x] + y);

			dp[i][j] = max(dp[i][j], dp[i - 1][j]);
		}
	}


	cout << dp[n][m] << endl;


	
	

	
	


	return 0;
 }




Measured memory_bytes: 79360
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

/*
200 380
300 550
500 850
1000 1520
1200 1870
1500 2244
*/

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector< vector<int> > dp(5000+1, vector<int>(6+1, 1000000));
		int w[6] = {200, 300, 500, 1000, 1200, 1500};
		int v[6] = {380, 550, 850, 1520, 1870, 2244};
		dp[0][0] = 0;
		dp[200][1] = 380;
		dp[300][2] = 550;
		dp[500][3] = 850;
		dp[1000][4] = 1520;
		dp[1200][5] = 1870;
		dp[1500][6] = 2244;
		for (int i = 0; i < 6; i++) {
			for (int j = 0; j <= n; j+=100) {
				if (j < w[i]) {
					dp[j][i+1] = dp[j][i];
				} else {
					dp[j][i+1] = min(dp[j][i], dp[j-w[i]][i+1]+v[i]);
				}
			}
		}
		cout << dp[n][6] << endl;
	}
	return 0;
}

Measured memory_bytes: 1528
while 1:
    n = int(input())
    if n == 0:break

    mark = (1,1,1,1,
            1,-1,1,-1,
            1,-1,-1,1,
            1,1,-1,-1)
    k = (0,1,2,3,
            1,0,3,2,
            2,3,0,1,
            3,2,1,0)

    for i in range(n):
        result = [0 for i in range(4)]
        inp = list(map(int,input().split()))
        
        for x_i,x in enumerate(inp[:4]):
            for y_i ,y in enumerate(inp[4:]):
                idx = x_i*4 + y_i 
                #print(mark[k[idx]])# * (x*y))

                result[k[idx]] += (mark[idx] * (x*y))

        print(' '.join(map(str,result)))

Measured memory_bytes: 6732
N, M = map(int, input().split())
ITEMS = list(map(int, input().split())) 
MAX = sum(ITEMS)
def solve():
    count = 0
    for item in reversed(list(sorted(ITEMS))):
        if item >= MAX * (1 / (4 * M)):
            count += 1
        if count >= M:
            print("Yes")
            return 
    
    print("No")
    
solve()

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

#define MAX 500000
#define SENTINEL 2000000000

int num = 0;
void merge(int A[],int left,int mid,int right);
void mergesort(int A[],int left,int right);

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

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

  
  mergesort(A,0,n);

  for(int i = 0;i < n; i++) {
    if(i) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << num << endl;

 
}

  void merge(int A[],int left,int mid, int right) {
    int n1 = right - mid;
    int n2 = mid - left;
    int L[MAX / 2 + 2],R[MAX / 2 + 2];
    for(int i = 0; i < n1;i ++) {
      R[i] = A[mid + i];
    }
    for(int i = 0;i < n2; i++) {
      L[i] = A[left + i];
    }

    R[n1] = SENTINEL;
    L[n2] = SENTINEL;
    int i = 0,j = 0;
    for(int k = left; k < right; k++) {
      num++;
      if(L[i] <= R[j]) {
        A[k] = L[i];
        i++;
      }else {
        A[k] = R[j];
        j++;
      }
    }


  }

  void mergesort(int A[],int left,int right) {
    if(left + 1 < right) {
      int mid = (left + right) / 2;
      mergesort(A,left,mid);
      mergesort(A,mid,right);
      merge(A,left,mid,right);
    }
  }



Measured memory_bytes: 7000
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
 
using namespace std;
using ll = long long;
 
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

#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, n, k) for(int i = 0; i < n; i += k)


int main()
{
    ll a, b, c;

    cin >> a >> b >> c;

    if(a == b && b == c){
        if(a % 2 == 0){
            cout << -1 << endl;
            return 0;
        }
        else{
            cout << 0 << endl;
            return 0;
        }
    }

    ll ans = 0;
    while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0){
        ans++;

        ll tmp1, tmp2;
        tmp1 = a / 2;
        tmp2 = b / 2;

        a = c / 2 + tmp2;
        b = tmp1 + c / 2;
        c = tmp1 + tmp2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dif(int a, int b)
{
    int ans=a-b;
    if(ans<0) ans*=-1;
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, h[100005],i,j;
    int f1,f2;
    cin>>N;
    for(i=0;i<N;i++)
        cin>>h[i];
    int M[100005]={0};
    M[N-2]=dif(h[N-1],h[N-2]);
    for(i=N-3;i>=0;i--)
    {
        f1=dif(h[i+1],h[i])+M[i+1];
        f2=dif(h[i+2],h[i])+M[i+2];
        M[i]=min(f1,f2);
    }
    cout<<M[0]<<endl;
    return 0;
}

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

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

  if (a < b) {
    cout << "a < b" << endl; 
  }
  else if (a > b) {
    cout << "a > b" << endl;
  }
  else if (a == b) {
    cout << "a == b" << endl;
  }
}


Measured memory_bytes: 3112
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class DBrickBreak {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int n = s.nextInt(), cur = 1;
            for (int i = 0; i < n; i++) if (s.nextInt() == cur) cur++;
            w.println(cur == 1 ? -1 : n - cur + 1);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 24276
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>

using namespace std;

int main() {
	string S; cin >> S;
	vector<int> v;
	int n = S.length();
	{
		int t = 0;
		char c = '\0';
		for (int i = 0; i <= n; i++) {
			if (i == n || S[i] != c) {
				int l = i - t;
				if (l > 0) {
					v.push_back(l);
				}
				if (i < n) {
					t = i;
					c = S[i];
				}
			}
		}
	}

	int K = 0;
	bool flag = false;
	for (auto itr = v.begin(); itr != v.end(); itr++) {
		int x = *itr;
		switch (x % 3) {
		case 0:
			K += 2 * (x / 3);
			break;
		case 1:
			K += 2 * (x / 3) + 1;
			flag = false;
			break;
		case 2:
			K += 2 * (x / 3) + 1;
			if (flag) {
				flag = false;
				K++;
			}
			else {
				flag = true;
			}
		}
	}

	cout << K << endl;
	return 0;
}


Measured memory_bytes: 1532
#include <iostream>
#include <cstdio>
 
using namespace std;
 
int main() {
    int a,b;
    int d,r;
    double f;
 
    cin >> a >> b;
 
    d = a / b;
    r = a % b;
    f = (double)a / (double)b;
 
    cout << d << " " << r << " " << flush;
    printf("%7f\n", f);
    return 0;
}

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

#define endl "\n"
#define for(i,a,b) for(int i = a;i<b;i++)


int main()
{
 
 int n,l;
 cin>>n>>l;
 string a[n];
 for(i,0,n) cin>>a[i];
 for(i,0,n-1){
     for(j,i+1,n){
         if(a[i]>a[j]){
             swap(a[i],a[j]);
         }
     }
 }
 for(i,0,n) cout<<a[i];
return 0;
   
}

Measured memory_bytes: 3632
/*
AizuOnline A0116
Title rectangle search
13/02/27 TE
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
#define MAXBANLEN 500
#define max(x,y) (((x)>(y))?(x):(y))
#define min(x,y) (((x)<(y))?(x):(y))
int H,W;
char ban[MAXBANLEN][MAXBANLEN+1];
int runlen[MAXBANLEN];
int limit_x[MAXBANLEN][MAXBANLEN+1];
//
void printlimitx()
{
  int i,j;
  for(i=0;i<H;i++)
    {
      for(j=0;j<W;j++)
	printf("%d",limit_x[i][j]);
      printf("\n");
    }
}
int       calc_limit_x()
{
  int i,j;

  for(i=0;i<H;i++)
    for(j=W-1;j>=0;j--)
      limit_x[i][j]=0;

  for(i=0;i<H;i++)
    for(j=W-1;j>=0;j--)
      if(ban[i][j]=='.')
	if(j==W-1 || ban[i][j+1]=='*')
	  limit_x[i][j]=1;
	else
	  limit_x[i][j]=limit_x[i][j+1]+1;
}
int getylimit(int y,int x)
{
  int i;

  for(i=y+1;i<H;i++)
    if(ban[i][x]=='*')
      return(i-1);
  return(H-1);
}
/*
int getxlimit(int y,int x)
{
  int i;
  //printf("GX %d %d\n",y,x);fflush(stdout);
  for(i=x+1;i<W;i++)
    {
      //printf("%d %c\n",i,ban[y][i]);
    if(ban[y][i]=='*')
      return(i);
    }
  return(W);
 
  }
*/
int getxlimit(int y,int x)
{
  return(limit_x[y][x]);
}
int min_runlen(int y0)
{
  int i,minl;

  minl=W+1;
  for(i=0;i<=y0;i++)
    minl=min(minl,runlen[i]);

  return(minl);
}
void printrunlen(int ymax)
{
  int i;
  for(i=0;i<=ymax;i++)
    printf("%d: %d\n",i,runlen[i]);
  fflush(stdout);
}
int getmaxrect_s(int y,int x)
{
  int i,j,ymax,ret;

  //printf("B %d %d\n",y,x);fflush(stdout);
  ymax=getylimit(y,x);
  //printf("YM %d\n",ymax);fflush(stdout);
  for(i=y;i<=ymax;i++)
     runlen[i-y]=getxlimit(i,x);
  ret=0;
  //printrunlen(ymax-y);
  
  for(i=0;i<=ymax-y;i++)
    ret=max(ret,(i+1)*min_runlen(i));
  
  //printf("%d\n",ret);

  return(ret);
}
int getmaxrect()
{
  int maxr,i,j,menseki;

  maxr=0;
  for(i=0;i<H;i++)
    for(j=0;j<W;j++)
      if(ban[i][j]=='.')
	{
	  menseki=getmaxrect_s(i,j);
	  //printf("A %d %d %d\n",i,j,menseki);
	  maxr=max(maxr,menseki);
	}
  return(maxr);
}
main()
{
  int i,ret;

  while(EOF!=scanf("%d %d",&H,&W) && (W || H))
    {
      for(i=0;i<H;i++)
	scanf("%s",&(ban[i][0]));

      calc_limit_x();
      //printlimitx();
      ret=getmaxrect();

      printf("%d\n",ret);
    }

return(0);
}

Measured memory_bytes: 1828
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

int main() {
	int A, P;
	cin >> A >> P;

	int n = A * 3 + P;
	n /= 2;

	cout << n << endl;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

const ll MOD = (ll)(1e9 + 7);

const int SZ = 312345;
ll inv[SZ];
ll fact[SZ];
ll fact_inv[SZ];
ll choose(int n, int r) {
  if (n < 0 || r < 0 || n < r) return 0;
  return fact[n] * fact_inv[n-r] % MOD * fact_inv[r] % MOD;
}

ll two[SZ];

const int MAX_N = 212345;
ll C[MAX_N];

int main2() {
  int N = nextInt();
  REP(i, N) C[i+1] = nextInt();
  sort(C+1, C+N+1);
  // pv(C+1, C+N+1);
  ll ans = 0;
  ll Q = two[N-1];
  for (int i = N; i >= 1; i--) {
    // for (int k = 1; k <= N-i+1; k++) {
    //   Q += k * choose(N-i, k-1) % MOD;
    //   // cout << k << " * " << "choose(" << N-i << ", " << k-1 << ")" << endl;
    //   Q %= MOD;
    // }
    // Q *= two[i-1];
    // Q %= MOD;
    // cout << Q << " * " << C[i] << endl;
    ans += Q * C[i] % MOD;
    ans %= MOD;
    Q += two[N-2];
    Q %= MOD;
  }
  REP(i, N) {
    ans = (ans * 2) % MOD;
  }
  cout << ans << endl;
  return 0;
}

int main() {

  inv[1] = 1;
  for (int i = 2; i < SZ; i++) inv[i] = inv[(int) (MOD % i)] * (MOD - MOD / i) % MOD;
  fact[0] = 1;
  for (int i = 1; i < SZ; i++) fact[i] = fact[i-1] * i % MOD;
  fact_inv[0] = 1;
  for (int i = 1; i < SZ; i++) fact_inv[i] = fact_inv[i-1] * inv[i] % MOD;
  two[0] = 1;
  for (int i = 1; i < SZ; i++) two[i] = two[i-1] * 2 % MOD;

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 11520
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define sz(x) ((int)x.size())

vector<int> a(1<<16, 0), masksum(1<<16, 0);
int r[20][20];

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            cin >> r[i][j];
    for(int i = 0; i < (1<<n); i++)
        for(int j = 0; j < n; j++)
            for(int k = j+1; k < n; k++)
                if(((1<<j)&i) && ((1<<k)&i))
                    masksum[i] += r[j][k];
    int mx = 0;
    for(int i = 0; i < (1<<n); i++)
    {
        int mask = (1<<n)-i-1, submask = mask;
        while(submask)
        {
            a[i|submask] = max(a[i|submask], a[i] + masksum[submask]);
            submask = (submask-1)&mask;
        }
    }
    cout << a[(1<<n)-1] << endl;
}

Measured memory_bytes: 4172
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    char s[101]={};
    scanf("%s",s);
    int k=strlen(s);
    if(k<=n)
        cout<<s<<endl;
    else if(k>n){
      for(int i=0;i<n;i++){
        printf("%c",s[i]);}
        cout<<"..."<<endl;
    }
    return 0;
}

Measured memory_bytes: 3688
s = list(input())

c = 0
n = [] 
ans = [] 
for i in range(len(s)):
    if s[i] == "," or s[i] == "." or s[i] == " ":
        if c >= 3 and c <= 6:
            ans = ans + n + [" "] 
        n.clear()
        c = 0

    else:
        n.append(s[i])
        c += 1
del ans[-1] 
for i in range(len(ans)) :
    print(ans[i], end="")
print()


Measured memory_bytes: 5592
#include <iostream>
using namespace std;
int main()
{
    int A, B, C;
    cin >> A >> B >> C;

    int num5 = 0;
    int num7 = 0;
    if (A == 5) {
        num5++;
    }
    else {
        num7++;
    }

    if (B == 5) {
        num5++;
    }
    else {
        num7++;
    }

    if (C == 5) {
        num5++;
    }
    else {
        num7++;
    }

    if (num5 == 2 && num7 == 1) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
/*
  Fuad Ashraful Islam
  University of Asia Pacific,Bangladesh
  Date:15 th March 2020
  Todo--
*/
#include<bits/stdc++.h>
#define all(o) (o).begin(),(o).end()
using namespace std;

int n,k,m,tc,cs=1,len;
const int N=1e5+5;
typedef long long ll;
void scan(int &x)
{
  scanf("%d",&x);
}

 
void Solve()
{
  ll h,w;
   cin>>h>>w;

   if(h==1||w==1)
   {
     cout<<1<<endl;
     return;
   }

   if(h%2==0&&w%2==0)
   {
     ll r=h/2;
     r*=w;
     cout<<r<<endl;
   }
   else if(h%2==1&&w%2==1)
   {
      ll r=(h/2+1)*(w/2+1);
      r+=(h/2)*(w/2);
      cout<<r<<endl;
   }
   else
   {
    if(h%2==1)swap(h,w);

    ll r=(h/2)*w;
    cout<<r<<endl;
   }
 
}
int main()
{
  ios_base::sync_with_stdio(false);cin.tie(nullptr); cout.tie(nullptr);
  Solve();
 return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	int n; cin >> n;
	int mi = 10000; int ma = 0;
	rep(i, n) {
		int a; cin >> a;
		mi = min(mi, a);
		ma = max(ma, a);
	}
	cout << ma - mi << endl;
	return 0;
}

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

using namespace std;

long long f(long long n, long long d) {
    return n * (n-1) / 2 * d;
}

long long q(pair<long long, long long> & p, long long step) {
    return (p.second - p.first) / step + 1;
}

int main() {
    ios_base::sync_with_stdio(false);
    cout.precision(15);
    cout << fixed;
    cin.tie(0);

    long long n, x, d;
    cin >> n >> x >> d;

    long long sumd = f(n, d);

    vector<pair<long long, long long> > v;
    for (long long k = 0; k <= n; k++) {
        long long me = k * x;
        long long him = (n-k) * x;

        long long me1 = f(k, d);
        long long e1 = me1 - (sumd - me1);

        long long him1 = f(n-k, d);
        long long e2 = (sumd - him1) - him1;

        v.push_back({me - him + min(e1, e2), me - him + max(e1,e2)});
    }

    long long mod = 2*abs(d);
    if (d == 0) mod = 1;

    long long ans = 0;
    map<long long, vector<pair<long long, long long> > > dupa;
    for (auto p : v) {
        long long md = (p.first % mod + mod) % mod;
        dupa[md].push_back(p);
    }

    for (auto z : dupa) {
        auto v = z.second;
        sort(v.begin(), v.end());
        pair<long long, long long> lst = v[0];
        for (int i = 1; i < v.size(); i++) {
            auto p = v[i];
            if (p.first <= lst.second) {
                lst.first = min(lst.first, p.first);
                lst.second = max(lst.second, p.second);
            } else {
                ans += q(lst, mod);
                lst = p;
            }
        }
        ans += q(lst, mod);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 25452
//Abhigyan's Code:
             
    //YOU DON'T DARE TO COPY :) 

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long int ll;
    typedef unsigned long long int ull;
    #define checker cout<<"CHECKED" 
    #define modulo 1000000007
  
    int main()
    {
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
     
    ll n , k ;
    cin >> n>> k ;

    vector<ll> vec(n) ;
    
    for(auto &z : vec)
      cin >> z ;

    bool dp[k+1] = {false} ;

    for(ll i = 1 ; i <= k ;i++)
    {
      for(ll j = 0; j < n ; j++)
      {
        if(i - vec[j] < 0 )
          break ;
        if(dp[i - vec[j]] == false )
        {
          dp[i] = true ;
          break ;
        }
      }
    }

    if(dp[k])
      cout << "First";
    else
      cout << "Second";


    return 0;

   }   

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

class MyClass
{
    public static bool Check(int m, int[] a)
    {
        if (a.Length == 1)
        {
            return m == 0 || a[0] == m;
        }
        else
        {
            var b = new int[a.Length - 1];
            for (int i = 0; i < a.Length - 1; i++)
            {
                b[i] = a[i + 1];
            }
            return Check(m, b) || Check(m - a[0], b);
        }
    }

    public static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var q = int.Parse(Console.ReadLine());
        var M = Console.ReadLine().Split().Select(int.Parse).ToArray();
        foreach (var m in M)
        {
            Console.WriteLine(Check(m, A) ? "yes" : "no");
        }
    }
}


Measured memory_bytes: 24296
// ref: https://img.atcoder.jp/abc112/editorial.pdf
// ref: https://drken1215.hatenablog.com/entry/2018/11/06/120600

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

vector<int> divisors(int n){
    vector<int> divs;
    for(int i=1; i*i<n; ++i){
        if(n%i!=0){ continue; }
        
        divs.push_back(i);
        int tmp = n/i; if(tmp!=i){ divs.push_back(tmp); }
    }
    sort(divs.begin(), divs.end(), greater<int>());
    return divs;
}

int main(){
//    ios_base::sync_with_stdio(false);
//    cin.tie(NULL);
    
    int N, M; cin >> N >> M;
    
    vector<int> divs = divisors(M);
    
    int ans=1;
    for(uint i=0; i<divs.size(); ++i){
        if( divs[i] <= M/N ){ ans=divs[i]; break; }
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val k = sc.nextInt()
    val p = Array(n) { sc.nextInt() - 1 }
    val c = Array(n) { sc.nextLong() }
    var ans = Long.MIN_VALUE
    for (i in 0 until n) {
        val lst = mutableListOf(c[i])
        var x = p[i]
        while (x != i) {
            lst.add(c[x])
            x = p[x]
        }
        val l = lst.count()
        val sum = lst.sum()
        if (sum > 0) {
            val r = (k - 1) % l + 1
            var max = -Long.MAX_VALUE
            var sum2 = 0L
            for (j in 0 until r) {
                sum2 += lst[j]
                max = maxOf(max, sum2)
            }
            val v = sum * ((k - 1) / l) + max
            ans = maxOf(ans, v)
        } else {
            val r = minOf(l, k)
            var max = -Long.MAX_VALUE
            var sum2 = 0L
            for (j in 0 until r) {
                sum2 += lst[j]
                max = maxOf(max, sum2)
            }
            ans = maxOf(ans, max)
        }
    }
    println(ans)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 57704
#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()

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

    // start
    int a, b;
    cin >> a >> b;
    cout << (b % a == 0 ? a + b : b - a) << endl;
    // end

    return 0;
}


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

int main() {
    int n; cin >> n;
    string s, t;
    cin >> s >> t;
    int longest = 0;
    for (int i=0; i<n; ++i) {
        if (s.substr(i) == t.substr(0, n-i)) {
            longest = n-i;
            break;
        }
    }
    cout << 2*n-longest << endl;
}

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

int main(){
	int n, num, s;
	cin >> n;
	if(n > 52) return -1;
	char suit;
	bool allcards[4][13] = {false};
	//pair<char, int> card[n] = new pair<char, int>[n];
	for(int i = 0; i < n; i++){
		cin >> suit >> num;
		switch(suit){
			case 'S': s = 0; break;
			case 'H': s = 1; break;
			case 'C': s = 2; break;
			case 'D': s = 3; break;
		}
		allcards[s][num - 1] = true;
	}
	
	for(int i = 0; i < 4; i++){
		for(int j = 0; j < 13; j++){
			if(allcards[i][j] == false){
				switch(i){
					case 0: suit = 'S'; break;
					case 1: suit = 'H'; break;
					case 2: suit = 'C'; break;
					case 3: suit = 'D'; break;
				}
				cout << suit << ' ' << j + 1 << endl;
			}
		}
	}
}

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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(x) x.begin(), x.end()

const long long INF = 1LL<<60;
const int mod = 1000000007;

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; }

ll N;
vector<ll> A;
map<ll, int> cnt;

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    cin >> N;
    A.resize(N + 1);
    REP(i,N) cin >> A.at(i);

    ll ans = 0;

    REP(i, N) {
        ans += cnt[i - A.at(i)];
        cnt[i + A.at(i)]++;
    
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 27412
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s,t,ans="";
    long long i,j;
    cin >> s >> t;
    auto dp = vector<vector<int>>(t.length()+1, vector<int>(s.length() + 1, 0));
    for (i=0; i< t.length()+1; i++){
        for (j=0; j< s.length()+1; j++){
            if (s[j] == t[i] and j != s.length() and i != t.length())
                dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j] + 1);
            if (j != s.length())
                dp[i][j+1] = max(dp[i][j], dp[i][j+1]);
            if (i != t.length())
                dp[i+1][j] = max(dp[i][j], dp[i+1][j]);
        }
    }

    i = t.length();
    j = s.length();
    while ( ans.length() != dp[t.length()][s.length()] ){
        if (dp[i-1][j-1] + 1 == dp[i][j] && s[j-1] == t[i-1]){
            ans = s[j-1] + ans;
            i--;j--;
        } else if(dp[i-1][j] <= dp[i][j-1])
            j--;
        else
            i--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 35584
#include<iostream>
using namespace std;
int main()
	{
		int a = 0, b = 0, sum, result = 0;
		
		while (cin >>a>>b)
		{

			result = 0;
			sum = a + b;
			while (sum > 0){
				sum /= 10;
				result++;
			}
			cout <<result<<endl;
		}
		return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<stdlib.h>

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

void run(void){
  int n;
  scanf("%d%*d",&n);
  int *a=(int *)calloc(n,sizeof(int));
  int *min=(int *)calloc(n+1,sizeof(int))+1;
  min[-1]=1000000000;
  int p=0;
  int i;
  for(i=0;i<n;i++){
    scanf("%d",a+i);
    min[i]=MIN(min[i-1],a[i]);
    p=MAX(p,a[i]-min[i]);
  }
  int ans=0;
  for(i=0;i<n;i++){
    if(a[i]-min[i]==p){
      ans++;
    }
  }
  printf("%d\n",ans);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

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

    ll ans = -(1LL<<59);
    for(int i=0; i<N; i++) cin >> a[i] >> b[i] >> c[i];
    vector<ll> v(N);
    for(int bit=0; bit<1<<3; bit++){
        for(int i=0; i<N; i++){
            ll tmp = 0;
            if(bit&1<<0) tmp += a[i];
            else tmp -= a[i];

            if(bit&1<<1) tmp += b[i];
            else tmp -= b[i];

            if(bit&1<<2) tmp += c[i];
            else tmp -= c[i];

            v[i] = tmp;
        }

        sort(v.begin(), v.end(), greater<ll>());
        ll sum = 0;
        for(int i=0; i<M; i++) sum += v[i];
        ans = max(ans, sum);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
case = 0
while True:
    W = int(input())
    if W == 0:
        break
    N, case = int(input()), case + 1
    items = [[0,0]] + [list(map(int, input().split(','))) for _ in range(N)]
    C = [[0 for _ in range(W+1)] for _ in range(N+1)]
    for i in range(1, N+1):
        for w in range(1, W+1):
            if items[i][1] <= w:
                C[i][w] = max(items[i][0]+C[i-1][w-items[i][1]], C[i-1][w])
            else:
                C[i][w] = C[i-1][w]
    maxv = max(C[-1])
    print("Case {0}:\n{1}\n{2}".format(case, maxv, C[-1].index(maxv)))

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

int main(){
	int n, t, a, h, ans=0;
	double dt = 10000;
	cin >> n >> t >> a;
	for(int i=0; i<n; i++){
		cin >> h;
		double temp = abs(a-t+h*0.006);
		if(dt > temp){
			dt = temp;
			ans = i+1;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256