akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <vector>
#include <list>
#include <math.h>
#include <iomanip>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;



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

  int num_zero = 0;
  int num_one = 0;

  rep(i,S.size()){
    if( S.at(i) == '0') num_zero++;
    if( S.at(i) == '1') num_one++;
  }

  cout << min(num_zero,num_one) * 2 << endl;


}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s;
    int data;
    for (int i = 0; i < 10000; i++){
        cin >> s;
        data = 0;
        if (s.size() == 1 && s[0] == '0')
            break;
        for (int j = 0; j < s.size(); j++){
            data += s[j] - 48;
        }
        cout << data << endl;
    }
}



Measured memory_bytes: 3128
mod = 10**9 + 7
A = [1, 1, 2, 3, 5, 8, 13, 21, 34]

H, W, K = map(int, input().split())
dp = [[0]*W for i in range(H + 1)]
dp[0][0] = 1

for h in range(1, H + 1):
    for i in range(W):
        dp[h][i] = dp[h - 1][i] * A[i] * A[W - i - 1]
        if i > 0:
            dp[h][i] += dp[h - 1][i - 1] * A[i - 1] * A[W - i - 1]
        if i < W - 1:
            dp[h][i] += dp[h - 1][i + 1] * A[i] * A[W - i - 2]
        dp[h][i] = dp[h][i] % mod

print(dp[H][K - 1])



Measured memory_bytes: 3064
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		String s = fs.next(), t = fs.next();
		int sl = s.length();
		int tl = t.length();
		TreeSet<String> ts = new TreeSet<>();
		for(int i=0;i<sl;i++) {
			if(i+tl>sl)break;
			boolean no = false;
			for(int j=0;j<tl;j++) {
				if(s.charAt(i+j)!='?'&&s.charAt(i+j)!=t.charAt(j)) {
					no = true;
					break;
				}
			}
			if(no)continue;
			StringBuilder sb = new StringBuilder();
			for(int j=0;j<sl;j++) {
				if(j<i) {
					if(s.charAt(j)=='?')sb.append('a');
					else sb.append(s.charAt(j));
				}
				else if(j<i+tl)sb.append(t.charAt(j-i));
				else {
					if(s.charAt(j)=='?')sb.append('a');
					else sb.append(s.charAt(j));					
				}
			}
			ts.add(sb.toString());
		}
		if(ts.size()==0)System.out.println("UNRESTORABLE");
		else System.out.println(ts.pollFirst());
	}
}


//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

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

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

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

	public double nextDouble() {
		return Double.parseDouble(next());
	}

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

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}

Measured memory_bytes: 21332
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> pi;
#define inf 1000000000000000000
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define f first
#define s second
#define pb push_back
#define mp make_pair

long double a, b;


int main()
{

cin >> a >> b;
cout << b*2 - a;






    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe
    
int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
string s1,s2,s3;
cin >> s1>>s2>>s3;
cout << 'A' << s2[0] << 'C' << endl;












  
 
//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 100;
const int MOD = 1e9 + 7;
#define LL long long
#define pI pair <LL, LL>
#define fr first
#define sc second
#define mp make_pair
LL f[N]; int tot;
vector <pI> S[N];
int q;

void print(vector <pI> a)
{
    for (int i = 0; i < a.size(); ++ i)
        cerr << a[i].fr << " " << a[i].sc << endl;
}
int main()
{
    f[0] = f[1] = 1; tot = 1;
    while (f[tot] + f[tot - 1] <= 5e18)
    {
        tot ++;
        f[tot] = f[tot - 1] + f[tot - 2];
    }
    S[1].push_back(mp(1, 2));
    S[1].push_back(mp(1, 3));
    S[1].push_back(mp(1, 4));
    for (int i = 2; i <= tot - 3; ++ i)
        for (int j = 0; j < S[i - 1].size(); ++ j)
            for (int k = 1; k * S[i - 1][j].sc + S[i - 1][j].fr <= f[i + 2]; ++ k)
                S[i].push_back(mp(S[i - 1][j].sc, k * S[i - 1][j].sc + S[i - 1][j].fr));
    scanf("%d", &q);
    while (q --)
    {
        LL x, y, ans = 0;
        scanf("%lld%lld", &x, &y);
        if (x > y) swap(x, y);
        int k = 1;
        while (f[k + 1] <= x && f[k + 2] <= y) k ++;
        for (int i = 0; i < S[k - 1].size(); ++ i)
            if (S[k - 1][i].sc <= x)
                ans += (y - S[k - 1][i].fr) / S[k - 1][i].sc;

        for (int i = 0; i < S[k - 1].size(); ++ i)
            if (S[k - 1][i].sc <= y)
                ans += (x - S[k - 1][i].fr) / S[k - 1][i].sc;
        if (x == 1) ans = y;
        if (x == 2 && y == 2) ans = 4;
        printf("%d %d\n", k, (int)(ans % MOD));
    }
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
#include <bitset>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S, T;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main(){
    cin>>N>>W;
    vec a(N);
    rep(i,N) cin>>a[i];
    ll m = a[0], d = 0;
    reps(i,1,N){
        d = max(d, a[i] - m);
        m = min(m, a[i]);
    }
    m = a[0];
    ll plus = 1, top = 0, ans = 0, temp = 0;
    a.push_back(-100);
    reps(i,1,N + 1){
        if(m > a[i]){
            if(top != 0) ans += top + temp;
            plus = 1;
            m = a[i];
            top = 0;
            temp = 0;
        }else if(m == a[i]){
            ++plus;
        }else if(m + d == a[i]){
            ++top;
            --plus;
        }
        temp = min(temp, plus);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)cin >> v[i];
    vector<int> sorted = v;
    sort(sorted.begin(), sorted.end());

    for (int i = 0; i < n; i++) {
        if (v[i] <= sorted[n / 2 - 1])cout << sorted[n / 2] << endl;
        else cout << sorted[n / 2 - 1] << endl;
    }
    return 0;
}

Measured memory_bytes: 3712
n = int(input())
a = [0]*(n+1)
for i in range(1, 102):
    for j in range(1, 102):
        for k in range(1, 102):
            if (i*i + j*j + k*k + i*j + j*k + i*k) <= n:
                a[i*i + j*j + k*k + i*j + j*k + i*k] +=1
                
for x in a[1:]:
    print(x)

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

using namespace std;

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

    vector<int> p(n);

    int min = 1000;
    int now = -1;

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

    p.push_back(102);

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

    now = -2;
    int minid=101;
    for(auto i:p){
        now++;
        while(now!=i){
            int tmp = abs(x-now);
            if(tmp < min){
                min = tmp;
                minid = now;
            }else if(tmp == min){
                if( now < minid){
                    minid = now;
                }
            }
            now++;
        }
    }

    cout << minid << endl;

}

Measured memory_bytes: 3628
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#define pb push_back
using namespace std;

inline char nc(){
  static char buf[100000],*p1=buf,*p2=buf;
  return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline void read(int &x){
  char c=nc(),b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}

const int N=200005;

int T[N<<2],F[N<<2];
inline void Build(int x,int l,int r){
  if (l==r) return void(T[x]=l);
  int mid=(l+r)>>1; Build(x<<1,l,mid); Build(x<<1|1,mid+1,r);
  T[x]=max(T[x<<1],T[x<<1|1]);
}
inline void Add(int x,int l,int r,int ql,int qr){
  if (ql<=l && r<=qr){
    T[x]++; F[x]++; return;
  }
  int mid=(l+r)>>1;
  if (ql<=mid) Add(x<<1,l,mid,ql,qr);
  if (qr>mid) Add(x<<1|1,mid+1,r,ql,qr);
  T[x]=F[x]+max(T[x<<1],T[x<<1|1]);
}
inline int Query(int x,int l,int r,int ql,int qr){
  if (ql<=l && r<=qr)
    return T[x];
  int mid=(l+r)>>1,ret=0;
  if (ql<=mid) ret=max(ret,Query(x<<1,l,mid,ql,qr));
  if (qr>mid) ret=max(ret,Query(x<<1|1,mid+1,r,ql,qr));
  return ret+F[x];
}

int n,m;
vector<int> R[N];

int main(){
  int x,y;
  read(n); read(m);
  for (int i=1;i<=n;i++) read(x),read(y),R[x].pb(y);
  int ans=0; Build(1,0,m+1);
  for (int i=0;i<=m;i++){
    for (int x:R[i])
      Add(1,0,m+1,0,x);
    ans=max(ans,Query(1,0,m+1,i+1,m+1)-i-m-1);
  }
  printf("%d\n",max(n-m,ans));
  return 0;
}


Measured memory_bytes: 14080
#include <stdio.h>
int main()
{
  int n, i, max=-1000000, min=1000000;
  double sum=0;
  scanf("%d",&n);

  int a;

  for(i=0;i<n;i++){
    scanf("%d",&a);
    if(a<min){min=a;}
    if(a>max){max=a;}
    sum = sum + a;
  }



  printf("%d %d %.0f\n", min, max, sum);

  return 0;
}

Measured memory_bytes: 632
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int gcd(int x, int y) {
	return y == 0 ? x : gcd(y, x%y);
}

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

	int N;
	cin >> N;
	vector<int> A(N);
	REP(i, N) cin >> A[i];
	int res = A[0];
	FOR(i, 1, N) res = gcd(res, A[i]);
	cout << res << "\n";

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll INF = 1LL << 62;
const int inf = 1 << 30;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b, c; cin >> a >> b >> c;
    string res = "No";
    if(a <= c and c <= b){
        res = "Yes";
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.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 long long int ll;
    
#define EPS (1e-7)
#define INF (1<<30)
#define LLINF (1LL<<60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    for(int i=0;i<s.size()-1;i++){
        if(s[i]==s[i+1]){
            cout<<"Bad"<<endl;
            return 0;
        }
    }
    cout<<"Good"<<endl;
}

Measured memory_bytes: 256
/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2020.08.12 18:44:24
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;

int main() {
    int n;cin >> n;
    string s;cin >> s;
    vector<int> t(n-1);
    bool two = true;
    for (int i = 0; i < n-1; i++) {
        t[i] = abs(s[i] - s[i+1]);
        if (t[i] == 1) two = false;
    }
    if (two) {
        for (int i = 0; i < n-1; i++) {
            t[i] /= 2;
        }
    }
    else {
        for (int i = 0; i < n-1; i++) {
            t[i] %= 2;
        }
    }
    int ans = 0;
    for (int i = 0; i <= n-2; i++) {
        if (t[i] == 1 && ((n-2)&i)==i) {
            ans ^= 1;
        }
    }
    if (two) {
        cout << ans * 2 << endl;
    }
    else {
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 8192
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){return "";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var W = one[1];
  var dp = new Array(N + 1);
  for(var i = 0; i < N + 1; i++){
    dp[i] = new Array(W + 1).fill(0);
  }
  
  for(var i = 1; i <= N; i++){
    var tmp = nextIntArray();
    var value = tmp[1];
    var weight = tmp[0];
    for(var j = 0; j <= W; j++){
      dp[i][j] = dp[i - 1][j];
    }
    for(var j = weight; j <= W; j++){
      dp[i][j] = Math.max(dp[i - 1][j],dp[i - 1][j - weight] + value);
    }
  }
  //myerr(dp);
  myout(dp[N][W]);
}

Measured memory_bytes: 190208
#include <iostream>

using namespace std;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int sum = 0;
    for (int i = 0; i <= n; ++i) {
        int v =  (i % 10) + ((i / 10) % 10) + ((i / 100) % 10) + ((i / 1000) % 10) + ((i / 10000) % 10);
        if (v >= a && v <= b) sum += i;
    }
    cout << sum << endl;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AOZ
{
	class MainClass
	{
		static void Main(string[] args)
		{
			var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			int n = input[0]; int m = input[1];
			var A = new int[n, m];
			for (int i = 0; i < n; i++)
			{
				var input2 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
				for (int j = 0; j < m; j++)
				{
					A[i, j] = input2[j];
				}
			}
			var b = new int[m];
			for (int i = 0; i < m; i++)
			{
				b[i] = int.Parse(Console.ReadLine());
			}
			for (int i = 0; i < n; i++)
			{
				int sum = 0;
				for (int j = 0; j < m; j++)
				{
					sum += A[i, j] * b[j];
				}
				Console.WriteLine(sum);
			}
		}
	}
}



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

int main() {
  string s,t;
  cin>>s>>t;
  int a,b;
  cin>>a>>b;
  string u;
  cin>>u;
  if(s==u){
    cout<<a-1<<endl;
    cout<<b<<endl;
  }
  else{
    cout<<a<<endl;
    cout<<b-1<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
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);
    
    printf("%d %d %d\n", a, b, c);
}



Measured memory_bytes: 3240
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<set>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#define max_n
using namespace std;
typedef long long ll;
map<int,int> mp;

int main ()
{
	ll m,n,ans=0;
	scanf("%lld %lld",&n,&m);
	for(int i=0;i<m;i++)
	{
		ll t1,t2;
		scanf("%lld %lld",&t1,&t2);
		mp[t1]++;
		mp[t2]++;
		if(mp[t1]%2==0&&mp[t2]%2==0)
			ans+=2;
		if(mp[t1]%2==1&&mp[t2]%2==1)
			ans-=2;
	}
	if(ans==0)
		cout<<"YES"<<endl;
	else
		cout<<"NO"<<endl;
	
	return 0;
}

Measured memory_bytes: 4352
import numpy as np
import sys
import math
import collections
read = sys.stdin.readline

N = int(read().rstrip())
A = list(map(int,read().rstrip().split()))
da = []
for i , a in enumerate(A):
    da.append([i,a])

dR = collections.defaultdict(int)
dL = collections.defaultdict(int)

ans = 0
for d in reversed(da):
    r = d[0] + d[1] + 1
    l = d[0] - d[1] + 1 

    dR[r] += 1

    ans += dL[r]

    dL[l] += 1  

print(ans)

Measured memory_bytes: 113124
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int N, K;
    cin >> N >> K;
    cout << N - K + 1 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define n_p next_permutation
#define p_p prev_permutation
#define in insert
#define rev reverse
#define pf push_front
#define pob pop_back
#define all(x) (x).begin(),(x).end()
#define pof pop_front
#define ios ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define scn scanf
#define prt printf
#define rep(i, a, n) for(int i = a; i < n; i++)
#define mod 998244353

using namespace std;

bool cmp(string s, string p) {
    return s.size() < p.size();
}

int main()
{
    int n;
    cin >> n;
    vector<int>h(n);
    vector<ll>dp(n);
    for(int i = 0; i < n; i++) {
        cin >> h[i];
    }
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for(int i = 2; i < n; i++) {
        dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
    }
    cout << dp[n - 1] << "\n";
    return 0;
}



Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MOD3 1000000000
#define MOD2 998244353 
float PHI = 1.6180339;
const float  PI_F=3.14159265358979f;
#define MAX 1000 m
#define endl "\n"    
#define manhunt 32 
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define pi 3.1415926535897932384626433
//typedef long long float;
#define int long long
//#define double long double
typedef pair<int, int> pii;
//#define float unsigned long long
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define CHAR_SIZE 26 

int modpow(int x, int n, int m) { if (n == 0) return 1%m; long long u = modpow(x,n/2,m); u = (u*u)%m; if (n%2 == 1) u = (u*x)%m; return u; } 


int add(int x, int y,int m) 
{
	x += y;
	if (x >= m) return x - m;
	return x;
}
int sub(int x, int y) 
{
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
int inv(int a, int m = MOD2)
{
	return modpow(a, m - 2, m);
}
int mul(int a, int b,int m) 
{
	return (long long) a * b % m;
}


int nCrModp(int n, int r, int p) 
{ 
    int C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; 
    for (int i = 1; i <= n; i++) 
    { 
        for (int j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 

bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
}

const int maxn=3e5+10;
int l[maxn+3];
int r[maxn+3];

int32_t main()
{
    /* freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout); */
    FAST
    cout << fixed << setprecision(12);

    int n;
    cin>>n;
    int arr[n+10];
    for(int i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    
    
    l[1]=arr[1];
    for(int i=2;i<=n;i++)
    {
        l[i]=l[i-1]^arr[i];
    }
    
    r[n]=arr[n];
    for(int i=n-1;i>=1;i--)
    {
        r[i]=r[i+1]^arr[i];
    }
    
    for(int i=1;i<=n;i++)
    {
        int val1=l[i-1];
        int val2=r[i+1];
        int ans=val1^val2;
        cout<<ans<<" ";
    }
    
    
    return 0;
}





Measured memory_bytes: 8264
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        var N = sc.nextInt();
        var D = sc.nextInt();
        var X = new int[N][];
        for (int i = 0; i < N; i++) {
            X[i] = sc.ArrayInt(D);
        }
        var ans = 0;
        for (int i = 0; i < N; i++) {
            for (int j = i+1; j < N; j++) {
                if (i == j) continue;
                double sum = 0;
                for (int k = 0; k < D; k++) {
                    sum += Math.Pow(Math.Abs(X[i][k] - X[j][k]), 2);

                }
                sum = Math.Sqrt(sum);
                if (sum - Math.Floor(sum) == 0) ans++;
            }
        }
        WriteLine(ans);
    }


}

class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <deque>
#include <utility>
#include <tuple>
#include <vector>

int main() {
  using namespace std;

  int H, W;
  cin >> H >> W;

  auto m = vector< vector< pair<int, char> > >(H, vector< pair<int, char> >(W));
  //最高スコアは (白の数) - (通過するマス目の数)
  int cnt_white = 0;
  for(auto &row: m)
    for(auto &cell: row) {
      char c;
      cin >> c;
      if(c == '.') cnt_white++;
      cell = make_pair(-1, c);
    }

  m[0][0].first = 1;
  auto g = make_pair(H - 1, W - 1);

  deque< pair<int, int> > q;
  q.push_back(make_pair(0,0));

  while(!q.empty()) {
    auto pos = q.front();
    q.pop_front();
    int len;
    char c;
    tie(len, c) = m[pos.first][pos.second];
    if(pos == g) {
      //goal!!
      cout << cnt_white - len << endl;
      return 0;
    }

    if(c == '#') continue;
    for(int i = 0; i < 4; i++) {
      pair<int, int> n;
      if(i < 2) {
        n = make_pair(2 * i - 1 + pos.first, pos.second);
      } else {
        n = make_pair(pos.first, 2 * i - 5 + pos.second);
      }
      int x, y;
      tie(x, y) = n;
      if(x < 0 || x >= H || y < 0 || y >= W) continue;
      auto& l = m[n.first][n.second].first;
      if(l >= 0) continue;

      l = len + 1;
      q.push_back(n);
    }
  }

  cout << "-1" << endl;
}


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

int main(){
  int N;
  cin >> N;
  
  int tmp = N;
  int count = 0;
  while ( tmp >= 1){
     count += tmp % 10;
     tmp /= 10;     
  }
  if ( N % count == 0) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();

    let mut ac: usize = 0;
    let mut wa: usize = 0;
    let mut tle: usize = 0;
    let mut re: usize = 0;
    for _ in 0..n {
        let s = iterator.next().unwrap();
        if s == "AC" {
            ac += 1;
        } else if s == "WA" {
            wa += 1;
        } else if s == "TLE" {
            tle += 1;
        } else if s == "RE" {
            re += 1;
        }
    }

    return format!("AC x {}\nWA x {}\nTLE x {}\nRE x {}", ac, wa, tle, re);
}


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

int main() {
  int n, k;
  long long res;
  cin >> n >> k;
  res = k;
  if(n!=1){
    for(int i=0;i<n-1;i++) {
      res *= k-1;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 20000  // スタックの最大値

typedef struct{
  int top;         // スタックポインタ(一番上の位置)
  int S[MAX];
}Stack;


// スタック st の初期化
void initialize(Stack *st)
{
  st->top = 0;
  st->S[st->top] = 0;
}

// スタック st が空かどうかを確認
int isEmpty(Stack *st)
{
  return st->top == 0;
}

// スタック st が一杯かどうかを確認
int isFull(Stack *st)
{  
  return st->top >= MAX - 1;
}

// スタック st に要素 x をプッシュ(一番上に要素を追加)
void push(int x, Stack *st)
{
  if (isFull(st)) 
    exit(1);

  st->top++;
  st->S[st->top] = x;
}

// スタック st から要素をポップ(一番上の要素を取り出す)
int pop(Stack *st) {
  if (isEmpty(st)) 
    exit(1);

  st->top--;
  return st->S[st->top+1];
}


int main(void)
{
  Stack st1;     // '\' の開始位置を格納するスタック
  Stack st2_j;   // 各水たまりの最も左の'\' の位置を格納するスタック
  Stack st2_a;   // 各水たまりの水量を格納するスタック

  // スタック初期化
  initialize(&st1);
  initialize(&st2_j);
  initialize(&st2_a);

  char c;
  int sum = 0;  // 水たまりの総水量

  // 地形を読み込み，各水たまりの水量を計算
  for (int i = 0; (c = getchar()) != EOF; i++) {
    if (c == '\\') {                                 // '\' が出た時の処理
      // 位置 i を st1 にプッシュ(write your code)
      push(i, &st1); 
    }else if (!isEmpty(&st1) && c == '/') {          // '/' が出た時の処理
      // 水たまりの総水量 sum を更新(write your code)
    	int j = pop(&st1);
      sum += i - j;
      // st2_j と st2_a を用いて水たまりの水量を更新 
      int a = i - j;   // 更新する水たまりの水量を a に格納していく
      while (!isEmpty(&st2_j) && st2_j.S[st2_j.top] > j) {  // 最も左の '\' の位置が j よりも大きい場合，以下を繰り返す
        // 水たまりの水量を求めていく (write your code)
      	a += pop(&st2_a);
      	pop(&st2_j);
      	
      }
      // 更新した水たまりの「最も左の'\' の位置」および「水量」を更新 (write your code)
    	push(j, &st2_j);
    	push(a, &st2_a);
    }
  }

  printf("%d\n", sum);       // 水たまりの総水量を出力
  printf("%d", st2_a.top);   // 水たまりの個数を出力

  // 各水たまりの水量を断面図の左から出力(スタックの底から出力)
  for (int i = 1; i <= st2_a.top; i++) 
    printf(" %d", st2_a.S[i]);  
  printf("\n");

  return 0;
}


Measured memory_bytes: 2108
#include <iostream>
using namespace std;
int main(){
    int a,b,c,in,t;
    a=b=c=0;
    for(int i=0;i<10;i++){
        cin>>in;
        if(in>a){
            t=a;
            a=in;
            in =t;
        }
        if(in>b){
            t=b;
            b=in;
            in =t;
        }
        if(in>c){
            t=c;
            c=in;
            in =t;
        }
    }
    cout<<a<<endl;cout<<b<<endl;cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int N;
string S;

class KMP {
public:
    KMP(const string &pat): pat(pat) {
        int n = pat.size();
        T.resize(n + 1, -1);
        for(int i = 0, j = -1; i < n; T[++i] = ++j) {
            while(j >= 0 && pat[i] != pat[j]) j = T[j];
        }
    }

    vector<int> operator()(const string &corp) {
        size_t corpPos = 0, patPos = 0;
        
        vector<int> ret;
        while(corpPos + patPos < corp.size()) {
            if(pat[patPos] == corp[corpPos + patPos]) {
                ++patPos;
                if(patPos < pat.size()) continue;
            }

            if(patPos == pat.size()) ret.push_back(corpPos);
            corpPos = corpPos + patPos - T[patPos];
            if(patPos > 0) patPos = T[patPos];
        }
        return ret;
    }

private:
    string pat;
    vector<int> T;
};

bool check(int left, int len) {
    if(left + len + len > N) return false;
    string pat = S.substr(left, len);
    KMP kmp(pat);
    vector<int> pos = kmp(S);
    if(pos.size() == 1) return false;
    return lower_bound(begin(pos), end(pos), pos[0] + len) != pos.end();
}

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

    int res = 0;
    for(int left=0; left+1<N; ++left) {
        int l = 0, r = N;
        while(r - l > 1) {
            int m = (l + r) / 2;
            if(check(left, m)) l = m;
            else r = m;
        }
        res = max(res, l);
    }
    cout << res << endl;
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

using llu = unsigned int;

llu power( llu b, llu i ){
    llu r = 1;
    while( i ){
        if( i&1 ) r *= b;
        i >>= 1;
        b *= b;
    }
    return r;
}

int main() {

    int N;
    Scd(N);

    char s[312][312];

    Rep(i,N) Scs(s[i]);

    llu hash = 0;
    llu roll = 1000000007;
    llu roll2 = 998244353;
    vector<vector<llu>> vh(N,vector<llu>(N,0)); // vertical hash
    vector<vector<llu>> hh(N,vector<llu>(N,0)); // horizontal hash
    vector<vector<llu>>vhh(N,vector<llu>(N,0)); // vertical hash hash
    vector<vector<llu>>hhh(N,vector<llu>(N,0)); // horizontal hash hash

    Rep(i,N){
        hash = 0;
        Rep(j,N) hash = hash*roll + s[i][j];
        Rep(j,N){
            hh[i][j] = hash;
            hash = hash*roll - s[i][j]*power(roll,N) + s[i][j];
        }
    }
    Rep(j,N){
        hash = 0;
        Rep(i,N) hash = hash*roll2 + hh[i][j];
        Rep(i,N){
            hhh[i][j] = hash;
            hash = hash*roll2 - hh[i][j]*power(roll2,N) + hh[i][j];
        }
    }
    Rep(j,N){
        hash = 0;
        Rep(i,N) hash = hash*roll + s[i][j];
        Rep(i,N){
            vh[i][j] = hash;
            hash = hash*roll - s[i][j]*power(roll,N) + s[i][j];
        }
    }
    Rep(i,N){
        hash = 0;
        Rep(j,N) hash = hash*roll2 + vh[i][j];
        Rep(j,N){
            vhh[i][j] = hash;
            hash = hash*roll2 - vh[i][j]*power(roll2,N) + vh[i][j];
        }
    }

    int ans = 0;
    Rep(i,N) Rep(j,N){
        // printf ("%020llu %020llu\n", vhh[i][j], hhh[i][j] );
        if( vhh[i][j] == hhh[i][j] ) ans++;
    }
    printf ("%d\n", ans );

    return 0;
}





Measured memory_bytes: 1792
import numpy as np
n,m,x = map(int,input().split())
c = []
for i in range(n):
  a = [int(i) for i in input().split()]
  c.append(a)
  
c = np.array(c)
ans = float('inf')
for i in range(1,2**n):
  chk = [0]*m
  cost = 0
  for j in range(n):
    if (i>>j)&1 == 1:
      cost += c[j][0]
      chk += c[j][1:]
  if min(chk) >= x:
    ans = min(ans,cost)
  
if ans == float('inf'):
  ans = -1
print(ans)


Measured memory_bytes: 27232
s=list(input())
n=len(s)
n1=n2=n3=0
for i in range(n):
    if s[i]=="a":
        n1+=1
    elif s[i]=="b":
        n2+=1
    elif s[i]=="c":
        n3+=1
if abs(n1-n2)>1 or abs(n1-n3)>1 or abs(n3-n2)>1: 
    print("NO")
else:
    print("YES")


Measured memory_bytes: 49392
#include <stdio.h>
#define max 100
#define INF 2147483647 
#define white 1
#define gray 2
#define black 3
typedef struct{
  int num; //頂点の番号を表す。
  int degree; //出次数を表す。
  int Adj[max]; //隣接リスト(隣接する頂点の番号のリスト)。
  int color;
  int d; //頂点1からその頂点までの距離を表す。
} node;
void enqueue(int);
int dequeue(void);
void bfs(node *, int);
int n, time, A[max+1][max+1];
int queue[max], head = 0, tail = 0;

int main()
{
  //幅優先探索のプログラム。
  int i, j;
  node node[max];
  
  for(i = 0 ; i <= max ; i++){
    for(j = 0 ; j <= max ; j++) A[i][j] = 0; }

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    scanf("%d%d",&node[i].num,&node[i].degree);
    for(j = 0 ; j < node[i].degree ; j++){
      scanf("%d",&node[i].Adj[j]);
      A[node[i].num][node[i].Adj[j]] = 1; }
  }

  bfs(node, 0);

  for(i = 0 ; i < n ; i++){
    if(node[i].d == INF) node[i].d = -1; //頂点1からたどり着けなかった頂点の距離を-1とする。
    printf("%d %d\n",node[i].num,node[i].d); }
  
  return 0;
}

void enqueue(int num)
{
  int next;

  next = (tail + 1) % max;
  
  if(next != head){
    queue[tail] = num;
    tail = next; }

}

int dequeue(void)
{
  int de = INF;

  if(head != tail){
    de = queue[head];
    head = (head + 1) % max;
    return de; }

  return de;
}

void bfs(node *node, int s)
{
  int i, j, u, index;

  for(i = 0 ; i < n ; i++){
    node[i].color = white;
    node[i].d = INF; }

  node[s].color = gray;
  node[s].d = 0;

  head = tail; //キューを空っぽにする。
  enqueue(s);

  while(head != tail){ //キューが空っぽになるまで
    u = dequeue();
    for(i = 0 ; i < node[u].degree ; i++){ 
      for(j = 0 ; j < n ; j++){ 
	if(node[u].Adj[i] == node[j].num) index = j; }
      if(node[index].color == white && A[node[u].num][node[index].num] == 1){
	node[index].color = gray;
	node[index].d = node[u].d + 1;
	enqueue(index); }
    }
    node[u].color = black; }
	
}


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


typedef long long ll;
struct NT{
  vector<bool>isprime;

  ll mod_mult(ll a, ll b, ll m) {
    ll res = 0;
    ll exp = a % m;
    while (b) {
      if (b & 1) {
        res += exp;
        if (res > m) res -= m;
      }
      exp <<= 1;
      if (exp > m) exp -= m;
      b >>= 1;
    }
    return res;
  }

  ll mod_exp(ll a, ll b, ll m) {
    ll res = 1;
    ll exp = a % m;
    while (b) {
      if (b & 1) res = mod_mult(res, exp, m);
      exp = mod_mult(exp, exp, m);
      b >>= 1;
    }
    return res;
  }

  bool miller_rabin(ll n, ll times) {
    if (n < 2) return false;
    if (n == 2) return true;
    if (!(n & 1)) return false;
    ll q = n-1;
    int k = 0;
    while (q % 2 == 0) {
      k++;
      q >>= 1;
    }
    for (int i = 0; i < times; i++) {
      ll a = rand() % (n-1) + 1;
      ll x = mod_exp(a, q, n);
      if (x == 1) continue;
      bool found = false;
      for (int j = 0; j < k; j++) {
        if (x == n-1) {
          found = true;
          break;
        }
        x = mod_mult(x, x, n);
      }
      if (found) continue;
      return false;
    }
    return true;
  }

  ll pollard_rho(ll n, int c) {
    ll x = 2;
    ll y = 2;
    ll d = 1;
    while (d == 1) {
      x = mod_mult(x, x, n) + c;
      y = mod_mult(y, y, n) + c;
      y = mod_mult(y, y, n) + c;
      d = __gcd((x-y >= 0 ? x-y : y-x), n);
    }
    if (d == n) return pollard_rho(n, c+1);
    return d;
  }
};

int sum;

int main(){
  NT N;
  ll n;
  cin>>n;
  while(n--){
    ll a;
    scanf("%ld",&a);
    if(N.miller_rabin(a,5))sum++;
  }
  cout<<sum<<endl;
}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main() {
  int n; cin>>n;
  deque<ll> deq;
  
  for(int i=0;i<n;i++){
    ll a; cin>>a;
    if(i%2==0) deq.push_back(a);
    else deq.push_front(a);
  }
  
  if(n%2==0){
    for(int i=0; i<n; i++){
      cout<<deq.front()<<" ";
      deq.pop_front();
    }
  }
  else{
    for(int i=0; i<n ;i ++){
      cout<<deq.back()<<" ";
      deq.pop_back();
    }
  }
  return 0;
  
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct LOC{
	LOC(int arg_row,int arg_col){
		row = arg_row;
		col = arg_col;
	}
	int row,col;
};

int H,W,K;
int POW[7];
char buf[10][10];
vector<LOC> V;

int main(){

	POW[0] = 1;
	for(int i = 1; i <= 6; i++){

		POW[i] = POW[i-1]*2;
	}

	scanf("%d %d %d",&H,&W,&K);

	for(int row = 0; row < H; row++){

		scanf("%s",buf[row]);
		for(int col = 0; col < W; col++){
			if(buf[row][col] == '#'){

				V.push_back(LOC(row,col));
			}
		}
	}

	int ans = 0,count;

	for(int r_state = 0; r_state < POW[H]; r_state++){
		for(int c_state = 0; c_state < POW[W]; c_state++){

			count = 0;
			for(int i = 0; i < V.size(); i++){
				if((r_state & POW[V[i].row]) != 0 || (c_state & POW[V[i].col]) != 0){

					//Do nothing

				}else{

					count++;
				}
			}
			if(count == K){

				ans++;
			}
		}
	}

	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 3832
import java.io.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
  
class Main{
      
static final PrintWriter out=new PrintWriter(System.out);
static final int INF=Integer.MAX_VALUE;
  
public static class Edge{
int to;
int cost;
public Edge(int to){
this.to=to; cost=0;
}
public Edge(int to,int cost){
this.to=to; this.cost=cost;
}
}
  
public static class Pair{
int x;
int y;
public Pair(int x,int y){
this.x=x; this.y=y;
}
public static final Comparator<Pair> DISTANCE_ORDER=new Comp();
private static class Comp implements Comparator<Pair>{
public int compare(Pair p1,Pair p2){
return (p1.x>p2.x)?1:(p1.x<p2.x)?-1:0;
}
}
}
  
public static class MyArrayList extends ArrayList<Edge>{}
  
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st;
String line="";
while((line=br.readLine())!=null&&!line.isEmpty()){
st=new StringTokenizer(line);
int n=Integer.parseInt(st.nextToken());
int k=Integer.parseInt(st.nextToken());
int[] c=new int[n];
int[] r=new int[n];
int[] dist=new int[n];
boolean[][] visited=new boolean[n][n];
MyArrayList[] array=new MyArrayList[n];
MyArrayList[] carray=new MyArrayList[n];
for(int i=0;i<n;i++){
st=new StringTokenizer(br.readLine());
c[i]=Integer.parseInt(st.nextToken());
r[i]=Integer.parseInt(st.nextToken());
array[i]=new MyArrayList();
carray[i]=new MyArrayList();
}
for(int i=0;i<k;i++){
st=new StringTokenizer(br.readLine());
int a=Integer.parseInt(st.nextToken())-1;
int b=Integer.parseInt(st.nextToken())-1;
array[a].add(new Edge(b));
array[b].add(new Edge(a));
}
for(int i=0;i<n;i++){
bfs(i,r[i],visited,array);
for(int j=0;j<n;j++){
if(visited[i][j]&&i!=j) carray[i].add(new Edge(j,c[i]));
}
}
dijkstra(dist,carray);
out.println(dist[n-1]);
}
out.flush();
}
  
public static void bfs(int s,int t,boolean[][] visited,MyArrayList[] array){
Arrays.fill(visited[s],false);
Deque<Pair> que=new ArrayDeque<Pair>();
que.offerLast(new Pair(s,0));
while(!que.isEmpty()){
Pair p=que.pollFirst();
int ns=p.x;
visited[s][ns]=true;
ArrayList<Edge> list=array[ns];
if(p.y==t) continue;
for(int i=0;i<list.size();i++){
Edge e=list.get(i);
if(!visited[s][e.to]) que.offerLast(new Pair(e.to,p.y+1));
}
}
}
  
public static void dijkstra(int[] dist,MyArrayList[] array){
PriorityQueue<Pair> pque=new PriorityQueue<Pair>(1,Pair.DISTANCE_ORDER);
Arrays.fill(dist,INF);
dist[0]=0;
pque.offer(new Pair(0,0));
while(!pque.isEmpty()){
Pair p=pque.poll();
int v=p.y;
ArrayList<Edge> list=array[v];
if(dist[v]<p.x||list.size()==0) continue;
for(int i=0;i<list.size();i++){
Edge e=list.get(i);
if(dist[e.to]>dist[v]+e.cost){
dist[e.to]=dist[v]+e.cost;
pque.offer(new Pair(dist[e.to],e.to));
}
}
}
}
}

Measured memory_bytes: 882352
n=int(input())
arr=[list(map(int,input().split())) for _ in range(n)]
arr=sorted(arr,key=lambda x:x[1])
sa=0
for i in range(n):
  sa+=arr[i][0]
  if sa>arr[i][1]:
    print('No')
    break
else:
  print('Yes')

Measured memory_bytes: 55260
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair< int, int> P;
struct edge{ll to, cost; };

static const double EPS = 1e-8;
static const double PI = 3.141592653589;
static ll INF = 999999999999;
int mod = 1000000007;

#define REP(i,n)	for(int i=0;i<(int)n;++i)
#define ALL(c)		(c).begin(),(c).end()
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define MIN(a,b)    (a) < (b) ? (a):(b)
#define MAX(a,b)    (a) > (b) ? (a):(b)
#define debug(x) cerr << #x << " = " << x << endl;
int dx[] = {1,-1,0,0,1,-1,1,-1};
int dy[] = {0,0,1,-1,-1,1,1,-1};

using namespace std;


int main() {
    int ans = 0;
    int N;
    cin >> N;

    for(int i = 1;i <= N; i++ ){
        ans += i;
    }



    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import math
n1 = int(input())
f1 = [str(input()) for _ in range(n1)]

ans_sum = 0
ans_exa = {}

for i in range(len(f1)):
    y1 = "".join(sorted(list(str(f1[i]))))
    if y1 in ans_exa:
        ans_sum = ans_sum + ans_exa[y1]
        ans_exa[y1] = ans_exa[y1] + 1
    else:
         ans_exa[y1] = 1

print(ans_sum)

Measured memory_bytes: 72920
#include <iostream>
#include <algorithm>
#include <utility>
#include <climits>
using namespace std;

typedef long long ll;
const ll INF = LLONG_MAX;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

const ll siz = 200;
ll n, x, a[4002], cnt[2002]{}, xmax = 0, bucket[siz];

void init() {
    fill(bucket, bucket + siz, INF);
    REP(i, n * 2) { bucket[i / siz] = min(bucket[i / siz], a[i]); }
}
//[l,r)
ll rmq(ll l, ll r) {
    ll res = INF;
    REP(i, siz) {
        if ((i + 1) * siz < l || i * siz >= r) continue;
        if (i * siz >= l && (i + 1) * siz < r) {
            res = min(res, bucket[i]);
        } else {
            FOR(j, max(l, i * siz), min(r, (i + 1) * siz)) {
                res = min(res, a[j]);
            }
        }
    }
    return res;
}

int main() {
    cin >> n >> x;
    REP(i, n) {
        cin >> a[i];
        a[i + n] = a[i];  // n->1のループをしやすくする
    }
    init();
    ll ans = INF;
    REP(t, n) {
        ll asum = 0;
        FOR(i, n, n * 2) { asum += rmq(i - t, i + 1); }
        ans = min(ans, asum + x * t);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384