akhauriyash/Code-Regression huggingface dataset:
#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>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
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-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int dx[6] = { 0,-1,-1,0,1,1 };
int dy[6] = { -1,-1,0,1,1,0 };
vector<int> G[60];
P inv[60];
void init() {
	map<P, int> mp;
	int cnt = 1;
	rep(i, 10) {
		rep(j, i + 1) {
			mp[{i, j}] = cnt; inv[cnt] = { i,j };
			cnt++;
		}
	}
	rep(i, 10) {
		rep(j, i + 1) {
			rep(k, 6) {
				int nx = i + dx[k];
				int ny = j + dy[k];
				if (mp[{nx, ny}]) {
					G[mp[{i, j}]].push_back(mp[{nx, ny}]);
				}
			}
		}
	}
}
int n, c;
int x[10][10];
int score() {
	int sup = n * (n + 1) / 2;
	int res = 0;
	bool used[60];
	fill(used, used + 60, false);
	rep1(i, sup) {
		if (used[i])continue;
		int key = x[inv[i].first][inv[i].second];
		if (!key)continue;
		queue<int> q; used[i] = true; q.push(i);
		int sum = 1; bool exi0 = false;
		while (!q.empty()) {
			int nex = q.front(); q.pop();
			rep(j, (int)G[nex].size()) {
				int v = G[nex][j];
				if (v > sup)continue;
				int nc = x[inv[v].first][inv[v].second];
				if (nc== 0) {
					exi0 = true;
				}
				if (used[v]||nc!=key)continue;
				used[v] = true; sum++; q.push(v);
			}
		}
		if (!exi0) {
			if (key == c)res -= sum;
			else res += sum;
		}
	}
	return res;
}
void turn() {
	int ma = -100;
	rep(i, n) {
		rep(j, i + 1) {
			if (x[i][j] == 0) {
				x[i][j] = c;
				ma = max(ma, score());
				x[i][j] = 0;
			}
		}
	}
	cout << ma << endl;
}
int main(){
	init();
	while (cin >> n >> c,n) {
		rep(i,n){
			rep(j, i + 1) {
				cin >> x[i][j];
			}
		}
		turn();
	}
	return 0;
}


Measured memory_bytes: 3024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using ll = long long;
using namespace std;

int main(void) {
    int n, k;
    cin >> n >> k;

    vector<ll> x(n);

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

    // exhaustive search
    ll minv = 1LL<<60;
    // cout << "init" << minv << endl;
    for(int i = 0; i + k - 1 < n; ++i) {

        // cout << i << endl;

        ll left = x[i];
        ll right = x[i+k-1];

        // cout << "l:" << left  << endl;
        // cout << "r:" << right << endl;

        // if (left < 0 && right < 0) {
        //     minv = min({minv, left});
        // } else if (left >=0 && right >= 0) {
        //     minv = min({minv, right});
        // } else {
        //     minv = min({minv, min({2*abs(left)+abs(right), 2*abs(right)+abs(left)})});
        // }

        minv = min (minv, min(abs(left),abs(right))+right-left);
        // cout << "ans:" << (left < 0 && right >= 0 ? 2 * llabs(left)+llabs(right) : right) << endl;
        // cout << "minv:" << minv << endl;
    }

    cout << minv << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>

using namespace std;
// for loop
#define F(i, L, R) for(int i = L; i < R; i++)
#define FE(i, L, R) for(int i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(int i = L; i > R; i--)
#define FRE(i, L, R) for(int i = L; i >= R; i--)

// data types
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

int main() {
    int n;
    cin >> n;
    int ans = 0;
    int k;
    F(i, 0, n){
       cin >> k;
       int j = 2;
       while(j <= sqrt(k)){
           if(k % j == 0){
               // k is not prime number
               ans++;
               break;
           }
           j++;
       }
    }
    cout << n - ans << endl;
}



Measured memory_bytes: 3112
N = gets.chop.to_i
X = gets.chop.split(' ').map(&:to_i)

def cons(p, x)
  return (p - x).abs ** 2
end

def main(n, x)
  min = x.min
  max = x.max

  array = []

  (min..max).each do |i|
    total = 0
    x.each do |j|
      total += cons(i, j)
    end

    array.push(total)
  end

  return array.min
end

puts main(N, X)


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
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;}
int const INF = 1001001001;


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

int a,b; cin >> a >> b;
if(a % 3 == 0 || b % 3 == 0 || (a+b) % 3 == 0) cout << "Possible" << endl;
else cout << "Impossible" << endl;

return 0;
}

Measured memory_bytes: 384
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	vector<vector<int>> grid(3, vector<int>(3));

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> grid[i][j];
		}
	}

	bool flag = true;

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {

			int i_ = (i + 1) % 3;
			int j_ = (j + 1) % 3;

			if ((grid[i][j] - grid[i_][j] != grid[i][j_] - grid[i_][j_]) ||
				(grid[i][j] - grid[i][j_] != grid[i_][j] - grid[i_][j_])) {
				flag = false;
				break;
			}
		}
	}

	if (flag) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = [int(_x) for _x in input().split()]

    kabu = 0
    kin = 1000
    for i in range(N):
        if kabu > 0:
            kin = kin + A[i] * kabu
            kabu = 0
        if i < N-1:
            if A[i] < A[i+1]:
                kabu = int(kin/A[i])
                kin = kin - A[i] * kabu
    print(kin)

main()


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

bool isPrime(int n){
    for(int i=2; i<n; i++){
        if((n%i)==0) return false;
    }
    return true;
}

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

    vector<bool> prime(100001, false);
    for(int i=2; i<=100000; i++){
        prime[i] = isPrime(i);
    }

    while(m+a+b != 0){
        int area = 0;
        int x,y;
        for(int i=1;i<=sqrt(m); i++){
            if(!prime[i]) continue;
            for(int j=m/i; j>0; j--){
                if(!prime[j]) continue;
                 if(i*j <= m && (double)i/j >= (double)a/b && (double)i/j <= 1){
                     if(area < i*j){
                         x=i;
                         y=j;
                         area = i*j;
                     }
                 }
            }
        }
        cout << x << " " << y << endl;
        cin >> m >> a >> b;
    }
}



Measured memory_bytes: 3100
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
 
#define endl "\n"
 
#define ll long long
#define MOD 1000000007
 
#define OJ \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
 
const double PI = 3.1415926535897932238460;
 
const int mxN= 102; 
bool arr[mxN];

int main(){
    int x, n, p;
    cin >> x >> n;
    int maxD= 101;
    int ans;
    int a =n;
    while (n--)
    {
        cin >>p;
        arr[p]= true;
    }
    for (int i=0; i<mxN; i++)  
        if (!arr[i]) if(abs(x-i)< maxD)maxD= abs(x-i), ans=i;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int cnt[4]={};
  int a[3];
  while(cin>>a[0]>>a[1]>>a[2]){
    sort(a,a+3);
    if(a[2]>=a[1]+a[0])break;
    for(int i=0;i<3;i++)a[i]*=a[i];
    cnt[0]++;
    if(a[2]==a[1]+a[0])cnt[1]++;
    else if(a[2]<a[1]+a[0])cnt[2]++;
    else cnt[3]++;
  }
  cout<<cnt[0]<<" "<<cnt[1]<<" "<<cnt[2]<<" "<<cnt[3]<<endl;
  return 0;
}



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

int main(){
	int n;
	cin >> n;
	int a[n];
	for(int i = 0;i < n;i++) scanf("%d",&a[i]);
	int maxn = 0;
	int sum = 0;
	for(int i = 1;i < n;i++){
		if(a[i] <= a[i-1]) sum++;
		else sum = 0;
		if(sum > maxn) maxn = sum;
	}
	cout << maxn << endl;
	return 0;
}

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

int main() {
  static const long double pi = 3.141592653589793;
  long double A , B , H , M;
  cin >> A >> B >> H >> M;
  long double S , L;
  S = (H*60+M)*pi/360;
  L = M*pi/30;
  cout << fixed << setprecision(13);
  cout << sqrt(A*A + B*B - 2*A*B*cos(abs(S-L))) << endl;
}

Measured memory_bytes: 4168
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b+c<=21)cout<<"win"<<endl;
    else cout<<"bust"<<endl;
    return 0;
}


Measured memory_bytes: 3556
def solve():
    MOD = 10**9 + 7

    S = int(input())

    N = S//3

    dp = [[0]*(S+1) for _ in range(N+1)]
    dp[0][0] = 1
    for i in range(1, N+1):
        for j in range(3, S+1):
            dp[i][j] = (dp[i][j-1] + dp[i-1][j-3]) % MOD

    ans = sum([dp[i][S] for i in range(N+1)]) % MOD
    print(ans)


solve()


Measured memory_bytes: 70876
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;

int main(){
   long long N,K;
   cin >> N >> K;
   long long A[N];
   long long F[N];
   for(int i=0;i<N;i++) cin>>A[i];
   for(int i=0;i<N;i++) cin>>F[i];
   sort(A,A+N);
   reverse(A,A+N);
   sort(F,F+N);
   long long left = -1;
   long long right = 1000000000000LL;
   while(right-left > 1){
      long long mid = (left+right)/2;
      long long score = 0;
      for(int i = 0 ; i <N ; i++){
         long long tmp = mid/F[i];
         score += max(A[i]-tmp,0LL);
      }
      if(score <= K){
         right = mid;
      }
      else{
         left = mid;
      }
   }
   cout << right << endl;
   return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).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; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

const int MX = 2005;
bool d[3][3][MX];

int main() {
    vector<string> s(3);
    rep(i,3) cin >> s[i];
    sort(s.begin(), s.end());
    int ans = MX*3;
    do {
        rep(i,3)rep(j,3)rep(k,s[i].size()) {
            if (i >= j) continue;
            bool ok = true;
            for (int ni = k; ni < s[i].size(); ni++) {
                int nj = ni - k;
                if (nj >= s[j].size()) break;
                if (s[i][ni] == '?' || s[j][nj] == '?') continue;
                if (s[i][ni] != s[j][nj]) ok = false;
            }
            d[i][j][k] = ok;
        }
        auto f = [&](int i, int j, int k) {
            if (k >= s[i].size()) return true;
            return d[i][j][k];
        };

        rep(x,MX)rep(y,MX) {
            if (!f(0,1,x)) continue;
            if (!f(1,2,y)) continue;
            if (!f(0,2,x+y)) continue;
            int now = 0;
            now = max<int>(now, s[0].size());
            now = max<int>(now, x+s[1].size());
            now = max<int>(now, x+y+s[2].size());
            ans = min(ans, now);
        }
    } while (next_permutation(s.begin(), s.end()));

    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int n;
int s[111];

int main()
{
	cin >> n;
	int sum = 0;

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

	if (sum % 10 != 0) {
		cout << sum << endl;
	}
	else {
		sort(s + 0, s + n);
		for (int i = 0;i < n;i++) {
			if (s[i] % 10 != 0) {
				cout << sum - s[i] << endl;
				return 0;
			}
		}

		cout << 0 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
N=int(input())
P=0
for i in range(N):
  P+=(i+1)*(i+2)//2
u,v=0,0
for i in range(N-1):
  u,v=map(int,input().split())
  u,v=min(u,v),max(u,v)-1
  P-=u*(N-v)
print(P)


Measured memory_bytes: 69712
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
#include <climits>
using namespace std; 
#define ll long long int

struct pt{
    ll a, b, c;
};

int main(){
    ll n, ma, mb;
    cin >> n >> ma >> mb;
    vector<pt> p(n);
    for(int i = 0; i < n; ++i) cin >> p[i].a >> p[i].b >> p[i].c;
    vector<vector<vector<ll> > > d(n + 1, vector<vector<ll> >(401, vector<ll>(401, 1e9)));
    d[0][0][0] = 0;
    for(int i = 0; i < n; ++i)
        for(int j = i; j >= 0; --j)
            for(int x = 0; x + p[i].a <= 400; ++x)
                for(int y = 0; y + p[i].b <= 400; ++y){
                    d[j + 1][x + p[i].a][y + p[i].b] = min(d[j + 1][x + p[i].a][y + p[i].b], d[j][x][y] + p[i].c);
                }
    
    ll ans = 1e9;
    for(int i = 1; i <= 40; ++i){
        if(ma * i > 400 || mb * i > 400) break;
        for(int j = 1; j <= n; ++j){
            ans = min(ans, d[j][ma * i][mb * i]);
        }
    }
    cout << (ans == 1e9? -1:ans);
}


Measured memory_bytes: 53504
//
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define MOD 1000000007
#define PI 3.14159265
#define EPS 1e-9
#define Pi acos(-1.0)
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;

/*CODE START HERE*/

int n, x, ma, mi;

int main(){
    ios::sync_with_stdio(0);
    cin >> n;
    ma = -1;
    mi = INF;
    forn(i,n){
        cin >> x;
        ma = max(ma,x);
        mi = min(mi,x);
    }
    cout << ma-mi << "\n";
    return 0;
}

Measured memory_bytes: 256
s = str(input())
for i in range(0,8):
    if i//4%2==0:
        x = "+"
    else:
        x = "-"
    if i//2%2==0:
        y = "+"
    else:
        y = "-"
    if i%2==0:
        z = "+"
    else:
        z = "-"
    ans = s[0]+x+s[1]+y+s[2]+z+s[3]
    if eval(ans)==7:
        print(ans+"=7")
        exit()


Measured memory_bytes: 3060
import numpy as np
N, K = map(int, input().split())

probability = 0


if N < K:
    for i in range(1,N+1):
        score = i
        cnt = 0
        while score <= K -1:
            score *= 2
            cnt += 1
        probability += (1/N) * ((1/2)**cnt)
else:
    probability += (N-K+1)/N
    for i in range(1,K):
        score = i
        cnt = 0
        while score <= K -1:
            score *= 2
            cnt += 1
        probability += (1/N) * ((1/2)**cnt)

print(probability)

Measured memory_bytes: 14420
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
using namespace std;
 
struct status{
    int idx_node;
    vector<int> children;
    int visited = 0;
    int depth = -1;
};
 
deque<int> schedule; 
vector<status> graph;

int depth = 1;
void bfs(){
    if (schedule.size()>1){
        
        int now_node = schedule.front();
        schedule.pop_front();
        
        switch(now_node){
            case 0: {
                ++depth;
                schedule.push_back(0);
                break;
            }
            default: {
                for(auto& next_node:graph[now_node-1].children){
                    if(graph[next_node-1].visited) continue;
                    
                    graph[next_node-1].visited = 1;
                    graph[next_node-1].depth = depth;  
                    schedule.push_back(next_node);
                }
            }
        }
        bfs();
    }
}
 

int main(void){cin.tie(0);ios::sync_with_stdio(false);
 
    //stdi
    int nb_nodes; cin >> nb_nodes;
    graph.resize(nb_nodes);
    for(auto& times:graph){
        int idx_node; cin >> idx_node; graph[idx_node-1].idx_node = idx_node;
        int nb_edges; cin >> nb_edges; graph[idx_node-1].children.resize(nb_edges);
        for(auto& a:graph[idx_node-1].children){
            cin >> a;
        }
        sort(graph[idx_node-1].children.begin(),graph[idx_node-1].children.end());
    }
    
    //bfs
    schedule.push_back(1);
    schedule.push_back(0);
    bfs();
    graph[1-1].depth = 0;
     
    //stdo
    for(auto& a:graph){
        cout<<a.idx_node<<" "
            <<a.depth<<"\n";
    }
}

Measured memory_bytes: 3180
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int main(){
  int A, B, C, res;
  rd(A);
  rd(B);
  rd(C);
  if(A > B){
    swap(A, B);
  }
  if(B > C){
    swap(B, C);
  }
  if(A > B){
    swap(A, B);
  }
  ;
  res = 2*C-A-B;
  if(res%2){
    res += 3;
  }
  wt_L(res/2);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190822-2

// --- original code ---
// {
//   int A, B, C, res;
//   rd(A,B,C);
//   sortE(A,B,C);
//   res = 2C-A-B;
//   if(res%2) res += 3;
//   wt(res/2);
// }


Measured memory_bytes: 256
n=int(input())
A=list(map(int, input().split()))
d={}
c=0

for i,a in enumerate(A):
  if i+a not in d:
    d[i+a]=1
  else:
    d[i+a]+=1
  if i-a in d:
    c+=d[i-a]

print(c)

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

public class Program
{
    #region Standard I/O
    readonly TextReader input;
    readonly TextWriter output;

    X[] ReadLine<X>(Func<string, X> func)
    {
        return input.ReadLine().Split(' ').Select(func).ToArray();
    }

    void WriteLineOne(object obj)
    {
        output.WriteLine("{0}", obj);
    }

    void WriteLineMany(params object[] objects)
    {
        output.WriteLine(string.Join(" ", objects.Select(obj => obj.ToString())));
    }
    #endregion

    int n;
    string[] ss;

    void Read()
    {
        n = ReadLine(int.Parse)[0];
        ss = Enumerable.Range(0, n).Select(_ => input.ReadLine()).ToArray();
    }

    static IEnumerable<char> Alphabets()
    {
        for (var c = 'a'; c <= 'z'; c++)
        {
            yield return c;
        }
    }

    string Solve()
    {
        var minCounts = Alphabets().ToDictionary(c => c, _ => int.MaxValue);

        foreach (var s in ss)
        {
            var counts = s.GroupBy(c => c).ToDictionary(g => g.Key, g => g.Count());

            foreach (var c in Alphabets())
            {
                var k = counts.ContainsKey(c) ? counts[c] : 0;
                minCounts[c] = Math.Min(minCounts[c], k);
            }
        }

        return new string(Alphabets().SelectMany(c => Enumerable.Repeat(c, minCounts[c])).ToArray());
    }

    public void Run()
    {
        Read();
        WriteLineOne(Solve());
    }

    public Program(TextReader input, TextWriter output)
    {
        this.input = input;
        this.output = output;
    }

    public static void Main(string[] args)
    {
        new Program(Console.In, Console.Out).Run();
    }
}


Measured memory_bytes: 13660
#include <iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  const int N=n;
  int v[N];
  int c[N];
  int total=0;
  for(int i=0;i<N;i++)cin>>v[i];
  for(int i=0;i<N;i++){
    cin>>c[i];
  v[i]-=c[i];
  if(v[i]>0)total+=v[i];
}
cout<<total<<endl;
  return 0;
}


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

using namespace std;

int main(){
	int n;
	cin >> n;
	int a[100000];
	for(int i=0;i<n;i++){
		cin >> a[i];
		a[i]--;
	}
	int ans = 0;
	for(int i=0;i<n;i++){
		if(i == a[a[i]]) ans++;
	}
	cout << ans/2 << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define MAX 200005
using namespace std;
const ll MOD=1e9+7;

ll gcd(ll a, ll b) {
  if(a==0) return b;
  if(a>b) return gcd(a%b, b);
  else return gcd(b%a, a);
}
ll lcm(ll a, ll b) {
  return a*b/gcd(a,b);
}

int main(){
  int a,b;
  cin >> a >> b;
  if(b%a==0){
    cout << a+b << endl;
  }else{
    cout << b-a << endl;
  }
}


Measured memory_bytes: 256
import sys
n = int(input())
a = list(map(int, input().split()))
if a.count(0) > 0:
    print(0)
    sys.exit()
b = 1
for i in range(n):
    b*=a[i]
    if b > 10**18:
        print("-1")
        sys.exit()
print(b)

Measured memory_bytes: 21644
l = input().split()
N = int(l[0])
M = int(l[1])

C = []

for i in range(M):
    l = input().split()
    C.append([int(x) - 1 for x in l])

# print(N, M, C)

def visit(s, G, visited):
    # print(s, G, visited)
    visited.add(s)
    for g in G:
        if g[0] in visited:
            n = g[1]
            G.remove(g)
            return visit(n, G, visited)
        elif g[1] in visited:
            n = g[0]
            G.remove(g)
            return visit(n, G, visited)
    return

ans = 0
for i in range(M):
    D = []
    for j in range(M):
        if i != j:
            D.append(C[j])
    visited = set()
    visit(0, D, visited)
    # print(i, len(visited))
    if len(visited) != N:
        ans += 1

print(ans)


Measured memory_bytes: 43244
#include <iostream>

using namespace std;

int main(void)
{
  string s;
  int i;
  
  cin >> s;
  
  for(i=0; i<=3; i++){
    cout << s[i];
  }
  
  cout << " ";
  
  for(i=4; i<=11; i++){
    cout << s[i];
  }
  
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<memory.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int n,m;
  cin >> n >> m;
  int cnt[n]={};
  bool flag[n]={};
  flag[0]=true;
  rep(i,n)cnt[i]++;
  rep(i,m){
    int x,y;
    cin >> x >> y;
    x--,y--;
    if(flag[x])flag[y]=true;
    if(cnt[x]==1)flag[x]=false;
    cnt[x]--;
    cnt[y]++;
  }
  ll ans=0LL;
  rep(i,n)if(flag[i])ans++;
  cout << ans << endl;
return 0;}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
typedef vector<int> vi;
typedef vector<ll> vl;
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}

int main (){
    int n;
    cin >> n;
    vi a(n);
    int ans;
    rep(i,n) cin >> a[i];
    rep(i,n){
        if(i==0) ans=a[i];
        else{
            ans=gcd(ans,a[i]);
        }
    }
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());

string a[]={"abcde","fghij","klmno","pqrst","uvwxy","z.?! "};

int main(){
	string s;
	while(cin>>s){
		stringstream ss;
		if(s.size()%2){
			cout<<"NA\n";
			continue;
		}
		bool f=false;
		rep(i,s.size()){
			int x=s[i]-'0'-1,y=s[i+1]-'0'-1;
			if(!(-1<x&&x<6)||!(-1<y&&y<5)){
				// cout<<x<<" "<<y<<endl;
				f=true;
				break;
			}
			ss<<a[x][y];
			i++;
		}
		if(f){
			cout<<"NA\n";
			continue;
		}
		string tmp;
		getline(ss,tmp);
		cout<<tmp<<endl;
	}
}

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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int conv[26] = {
  '2','2','2',
  '3','3','3',
  '4','4','4',
  '5','5','5',
  '6','6','6',
  '7','7','7','7',
  '8','8','8',
  '9','9','9','9'
};

int n;
vector<string> word;
vector<string> num;
string seq;
vector<string> ans;

string tonum(string s) {
  string res = "";
  rep(i, s.size()) res += conv[s[i]-'a'];
  return res;
}

bool input() {
  cin >> n;
  if(n == 0) return false;

  word.clear();
  word.resize(n);
  num.clear();
  num.resize(n);
  rep(i, n) {
    cin >> word[i];
    num[i] = tonum(word[i]);
  }

  cin >> seq;
}

void solve(int idx, string t) {
  if(idx == seq.size()) {
    ans.push_back(t+".");
    return;
  }
  rep(i, n) {
    if(seq.substr(idx, num[i].size()) != num[i]) continue;
    solve(idx+num[i].size(), (t.empty() ? word[i] : t+" "+word[i]));
  }
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(input()) {
    ans.clear();
    solve(0, "");
    for(string s : ans) cout << s << endl;
    cout << "--" << endl;
  }

  return 0;
}

Measured memory_bytes: 3256
using System;
using System.Linq;
class Program
{
    static void Main()
    {
        string str = Console.ReadLine();
        double a = double.Parse(str.Split(' ')[0]);
        double b = double.Parse(str.Split(' ')[1]);
        double c = double.Parse(str.Split(' ')[2]);
        c = Math.PI * (c / 180);
        double d = a * b * 0.5 * Math.Sin(c);
        double e = a + b + (Math.Sqrt(a * a + b * b - 2 * a * b * Math.Cos(c)));
        double f = b * Math.Sin(c);
 
        Console.WriteLine(d);
        Console.WriteLine(e);
        Console.WriteLine(f);
    }    
}

Measured memory_bytes: 5748
#require 'prime'
#require 'openssl'
MOD=10**9+7;  cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.chomp.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def ar2(s1,s2,de=nil) Array.new(s1){Array.new(s2,de)} end
def ar3(s1,s2,s3,de=nil) Array.new(s1){Array.new(s2){Array.new(s3,de)}} end

def desc(ar) ar.sort!{|x,y| y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+).to_i end
def ceil(a,b) (a.to_f/b).ceil end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end
def rui(ar) s=[0]; ar.size.times{|i| s<<s[-1]+ar[i]}; s end
def rev_rui(ar) s=[0]; ar.size.times.reverse_each{|i| s<<s[-1]+ar[i]}; s end

def puts_yesno(b) puts(b ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def pu(h) begin; require './../nemi_lib/debug.rb'; puts_val(h); rescue LoadError; end; end
########### ( ˘ω˘ )ｽﾔｧ… ###########
a,b,n=gsmi
x=min(b-1,n)
ans=(a.to_f*x/b).floor-a*(x.to_f/b).floor
puts ans

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

int main() 
{
	int ar[5],i,flag = 0;
	char br[5];
	cin>>br;
	for(i=0;i<4;i++)
	{
		ar[i] = br[i] - 48;
	}
	for(i=0;i<4;i++)
	{
		if(ar[i]==ar[i+1])
		{
			flag = 1;
			break;
		}
	}
	if(flag==0)
	{
		cout<<"Good"<<endl;
	}
	else if(flag==1)
	{
		cout<<"Bad"<<endl;
	}
	
	return 0;
}

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

#define ll long long

#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fill(ar,val) memset(ar, val, sizeof(ar))
#define fill0(ar) fill((ar), 0)
#define debug(x) cout<<#x<<": "<<x<<endl

#define ld double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<int> vi;

#define INF 1000000000000000000

ll h,w;
ll n;
ll r[3001];
ll c[3001];
ll ans[3005];
ll fact[500005];
ll mod = 1000000007;
pair<ll, ll> p[3005];

ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
} 

ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
    ll res = (x%m + m) % m; 
    return res; 
} 

ll cntWays(ll x1, ll y1, ll x2, ll y2)
{
    ll xx = fact[x2-x1 + y2-y1];
    ll yy1 = fact[x2-x1];
    ll yy2 = fact[y2-y1];

    ll yy = (yy1*yy2)%mod;

    yy = modInverse(yy,mod);

    ll ways = ((xx%mod)*(yy%mod))%mod;

    return ways;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> h >> w >> n;

    rep(i,n)
    {
        cin >> r[i] >> c[i];
        p[i] = mp(r[i],c[i]);
    }

    sort(p, p+n);
    ans[0] = 0;
    fact[0] = 1;
    p[n] = mp(h,w);

    fr(i,1,500004)
    {
        fact[i] = ((fact[i-1]%mod) * (i%mod))%mod;
    }

    fr(i,1,n+1)
    {
        ans[i] = cntWays(1,1,p[i-1].ff,p[i-1].ss);
        // cout << ans[i] << endl;
    }

    fr(i,1,n)
    {
        fr(j,i+1,n+1)
        {
            if(p[j-1].ss >= p[i-1].ss)
            {
                ll xx = ((ans[i]%mod) * (cntWays(p[i-1].ff, p[i-1].ss, p[j-1].ff, p[j-1].ss)%mod))%mod;
                ans[j] = ans[j] - xx;
                ans[j] = ((ans[j] + mod))%mod;
            }
        }
    }

    cout << ans[n+1] << endl;
}

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

#define rep( i, n ) for( int i = 0; i < ( n ); i++ )
#define PI 3.14159265
typedef long long ll;

int main( void ) {
    while( 1 ) {
        string s;
        int    m;
        int    sl = s.length();
        cin >> s;

        if( s == "-" ) break;

        cin >> m;
        while( m-- ) {
            int h;
            cin >> h;
            string t = s.substr( 0, h );
            s.erase( 0, h );
            s += t;
        }
        cout << s << endl;
    }

    return 0;
}



Measured memory_bytes: 3212
n = int(input())
a = [0] + list(map(int,input().split())) + [0]
ans = 0
for i in range(n+1):
  ans += abs( a[i+1] - a[i] )
for i in range(n):
  now = ans
  now -= abs( a[i+2] - a[i+1] ) + abs( a[i+1] - a[i] ) - abs( a[i+2] - a[i] )
  print(now)

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

using namespace std;

int n;
long long c;
long long h[1000010];
long long dp[1000010];

struct Line{
    long long m, c;

    long double getX(Line o){
        return (long double) (c - o.c) / (o.m - m);
    }

    long long getY(long long x){
        return m*x + c;
    }
};

vector<Line> ch;

bool good(Line a, Line b, Line c){
    return a.getX(b) > b.getX(c);
}

void insert(Line l){
    while(ch.size() > 1 && !good(ch[ch.size() - 2], ch.back(), l)) ch.pop_back();
    ch.emplace_back(l);
}

long long query(long long x){
    int l, r, m, opt;
    l = 0, r = ch.size() - 2;
    opt = ch.size() - 1;

    while(l <= r){
        m = (l + r) >> 1;

        if(ch[m].getY(x) > ch[m + 1].getY(x)){
            l = m + 1;
        } else r = m - 1, opt = m;
    }

    return ch[opt].getY(x);
}

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

    for(int i = 1; i <= n; i++) scanf("%lld", &h[i]);

    //Convex Hull Technique
    //dp[i] = min {dp[j] + (h[i] - h[j]) ^ 2 + c}
    //      = h[i]^2 + min {dp[j] + h[j]^2 + c - 2 * h[i] * h[j]}
    //Hence, m = h[i], x = - 2 * h[j], c = dp[j] + h[j]^2 + c
    for(int i = 2; i <= n; i++){
        insert(Line({h[i - 1], dp[i - 1] + h[i - 1] * h[i - 1] + c}));
        dp[i] = h[i] * h[i] + query(-2*h[i]);
    }

    cout << dp[n] << endl;
    
    return 0;
}

Measured memory_bytes: 11888
_n, m = gets.split.map(&:to_i)
py = []
numbers = []
m.times do |i|
  py.push gets.split.map(&:to_i) + [i]
end
py_hash = py.group_by { |e| e.first }
py_hash.each do |pref, cities|
  sorted_cities = cities.sort_by { |c| c[1] }
  sorted_cities.each_index do |i|
    numbers[sorted_cities[i][2]] = format("%06d%06d", pref, i+1)
  end
end
numbers.each do |num|
  puts num
end


Measured memory_bytes: 33916
#include <bits/stdc++.h>
#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++)
#define INF LLONG_MAX
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n, k; cin >> n >> k;
    vector<ll> v(n);
    REP(i, n) cin >> v[i];
    ll min_dist = INF;
    REP(i, n - k + 1) {
        ll minv = v[i];
        ll maxv = v[i+k-1];
        ll dist = maxv - minv;
        dist += min(abs(minv), abs(maxv));
        min_dist = min(min_dist, dist);
    }
    cout << min_dist << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;

class calculation{
private:
	int top;
	int *s;
public:
	calculation();
	~calculation();
	void push(int x);
	int pop();
};

calculation::calculation(){
	s = new int[1000];
	top = 0;
}

calculation::~calculation(){
	delete [] s;
}

void calculation::push(int x){
	s[++top] = x;
}

int calculation::pop(){
	top--;
	return s[top+1];
}

int main()
{
	char str[100];
	int a,b;
	calculation mycalculation;

	while( scanf("%s",str)!=EOF ){
		if(str[0]=='+'){
			a = mycalculation.pop();
			b = mycalculation.pop();
			mycalculation.push(a+b);
		}else if(str[0]=='-'){
			a = mycalculation.pop();
			b = mycalculation.pop();
			mycalculation.push(b-a);
		}else if(str[0]=='*'){
			a = mycalculation.pop();
			b = mycalculation.pop();
			mycalculation.push(a*b);
		}else{
			mycalculation.push(atoi(str));
		}
	}

	cout<<mycalculation.pop()<<endl;

	return 0;
}

Measured memory_bytes: 1200
#include<stdio.h>

#define M 10
#define SML 1
#define MID 2
#define BIG 3

//Array out of Exception (=0)
int aoe(int a, int b){
  if(a>=0&&b>=0&&a<=9&&b<=9)
    return 1;
  return 0;
}

int e,c;

int main(){
  int p[M][M]={};
  int x,y,s;

  while(scanf("%d,%d,%d",&x,&y,&s)!=EOF){
    if(s==BIG){
      if(aoe(x-2,y)) p[x-2][y]++;
      if(aoe(x+2,y)) p[x+2][y]++;
      if(aoe(x,y-2)) p[x][y-2]++;
      if(aoe(x,y+2)) p[x][y+2]++;
    }
    if(s!=SML){
      if(aoe(x-1,y-1)) p[x-1][y-1]++;
      if(aoe(x+1,y-1)) p[x+1][y-1]++;
      if(aoe(x-1,y+1)) p[x-1][y+1]++;
      if(aoe(x+1,y+1)) p[x+1][y+1]++;
    }
    p[x][y]++;
    if(aoe(x-1,y)) p[x-1][y]++;
    if(aoe(x+1,y)) p[x+1][y]++;
    if(aoe(x,y-1)) p[x][y-1]++;
    if(aoe(x,y+1)) p[x][y+1]++;
  }  
  for(x=0;x<M;x++){
    for(y=0;y<M;y++){
      if(!p[x][y])
	e++;
      if(c<p[x][y])
	c=p[x][y];
    }
  }
  printf("%d\n%d\n",e,c);
  return 0;
}

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

int main(){
  int n,t[100001],x[100001],y[100001];
  int i,flag,temp;
  int my_x,my_y;

  scanf("%d",&n);

  my_x = 0;my_y = 0;
  flag = 1;

  t[0] = 0;
  for(i = 1;i <= n;i++){
    scanf("%d %d %d",&t[i],&x[i],&y[i]);
  }

  for(i = 1;i <= n && flag == 1;i++){
    temp = abs(x[i] - my_x) + abs(y[i] - my_y);
    if(temp <= (t[i] - t[i-1]) && (temp - (t[i] - t[i-1]) == 0 || (temp - (t[i] - t[i-1])) % 2 == 0)){
      my_x = x[i];
      my_y = y[i];
    }else{
      flag = 0;
    }
  }

  if(flag == 1){
    printf("Yes\n");
  }else{
    printf("No\n");
  }

  return(0);
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main(void){
    int N,K;
    cin >> N >> K;
    int x[N];
    for(int i=0;i<N;i++)cin>>x[i];
    vector<int> y,z;
    for(int i=0;i<N;i++){
        if(x[i] < 0){
            y.push_back(x[i]);
        }
        else{
            z.push_back(x[i]);
        }
    }
    sort(y.begin(),y.end(),greater<>());
    int ans = 2100000000;
    if(z.size() >= K){
        ans = min(ans,z[K-1]);
    }
    if(y.size() >= K){
        ans = min(ans,abs(y[K-1]));
    }
    
    for(int i=0;i<K;i++){
        int tmpans;
        if(i < z.size() && K - i - 2 < y.size()){
            tmpans = z[i]*2+abs(y[K-i-2]);
            ans = min(ans,tmpans);
        }
        if(i < y.size() && K-i-2 < z.size()){
            tmpans = abs(y[i]*2)+z[K-i-2];
            ans = min(ans,tmpans);
        }
    }
    cout << ans;
}


Measured memory_bytes: 3880
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#define ll long long
using namespace std;

int main(){
 int N;cin>>N;
 int cnt=0;
 for(int x=0;x<=25;x++){
     if((N-4*x)%7==0 and N-4*x>=0){
         cnt++;
         break;
     }
 }
if(cnt) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
const int a_day = 86400;
const int earl = 10800;

int main(){
    int N;
    cin>>N;
    int wake_up[86400]={};
    int now=0;
    for(int i=0;i<N;i++){
        int a,b;
        cin>>a>>b;
        int t = (now + a)%a_day;
        wake_up[t]++;
        now = (now + a + b)%a_day;
    }
    int res = 0;
    for(int t=0;t<=earl;t++){
        res += wake_up[t];
    }
    int tmp = res;
    for(int t=1;t<a_day;t++){
        int s = (t + earl)%a_day;
        tmp = tmp + wake_up[s] - wake_up[t-1];
        res = max(res, tmp);
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 640
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def solve():
    s = input()
    if s == "ABC":
        print("ARC")
    else:
        print("ABC")

    return 0

if __name__ == "__main__":# {{{
    solve()

# vim: set foldmethod=marker: }}}


Measured memory_bytes: 79608
#include<bits/stdc++.h>
using namespace std;
int n;
const long long MOD=1e9+7;
int a[1200];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		a[i]=i+1;
	long long ans=1;
	for(int i=2;i<=n;i++)
	{
		int cnt=0;
		for(int j=0;j<n;j++){
			while(a[j]%i==0)
				a[j]/=i,cnt++;
		}
		ans=(ans*(cnt+1))%MOD;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import Control.Monad
squares=[x*x|x<-[0..1000]]
main=do
 [n,d]<-map read.words<$>getLine
 xs<-replicateM n(map read.words<$>getLine)
 print$length[1|i<-[0..n-2],j<-[i+1..n-1],(sum$map(^2)$zipWith(-)(xs!!i)(xs!!j))`elem`squares]

Measured memory_bytes: 1020
#include <iostream>
#include <cstdio>
#include <cctype>

using namespace std;

inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while (!isdigit(ch)) f=ch=='-'?-1:f,ch=getchar();
	while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*f;
}

const int N=100000;
const int E=N<<1;

int f[N],g[N],last[N];
int tov[E],nxt[E];
int n,tot;

inline void insert(int x,int y){tov[++tot]=y,nxt[tot]=last[x],last[x]=tot;}

void dp(int x,int fa=0)
{
	f[x]=g[x]=0;
	for (int i=last[x],y;i;i=nxt[i])
		if ((y=tov[i])!=fa) dp(y,x),f[x]+=g[y];
	for (int i=last[x],y;i;i=nxt[i])
		if ((y=tov[i])!=fa) g[x]=max(g[x],f[x]-g[y]+f[y]+1);
	g[x]=max(f[x],g[x]);
}

int main()
{
	scanf("%d",&n);
	for (int i=1,x,y;i<n;++i) scanf("%d%d",&x,&y),insert(x,y),insert(y,x);
	dp(1);
	if ((g[1]<<1)!=n) printf("First\n");
	else printf("Second\n");
	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(1){
        int n,m;
        cin >> n >> m;
        if(n == 0 && m == 0){
            break;
        }
        vvi vec(n,vi(m));
        string s;
        rep(i,n){
            cin >> s;
            rep(j,m){
                vec[i][j] = s[j]-'0';
            }
        }
        int ans = 0;
        if(n <= 10){
            rep(i,(1 << n)){
                vi v(m,0);
                rep(j,n){
                    if((i >> j)&1){
                        rep(k,m){
                            v[k] ^= vec[j][k];
                        }
                    }
                }
                bool flag = true;
                rep(j,m){
                    if(v[j] != 0){
                        flag = false;
                        break;
                    }
                }
                if(flag){
                    cmx(ans,__builtin_popcount(i));
                }
            }
            cout << ans << "\n";
        }else{
            vl val(n);
            rep(i,n){
                // svec(vec[i]);
                rep(j,m){
                    val[i] += ((ll)vec[i][j] << j);
                }
            }
            // svec(val);
            map<ll,int> mp;
            mp[0] = 0;
            rep(i,n){
                map<ll,int> mp2;
                each(it,mp){
                    mp2[it.fi] = max(mp[it.fi],mp2[it.fi]);
                    mp2[it.fi^val[i]] = max(it.se+1,mp2[it.fi^val[i]]);
                }
                mp = mp2;
            }
            cout << mp[0] << "\n";
        }
    }
    return 0;
}



Measured memory_bytes: 134132
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define vi vector<int>
#define vl vector<ll>
#define vp vector<pi>
#define vpl vector<pl>
#define pb push_back
#define INF 1000000005
#define LINF 1000000000000000005

int a,b,c;

int32_t main(){
    /*seed_seq seq{
        (uint64_t) chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count(),
        (uint64_t) __builtin_ia32_rdtsc(),
        (uint64_t) (uintptr_t) make_unique<char>().get()
    };
    mt19937 rng(seq);*/
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();

    cin >> a >> b >> c;
    if(a==b && b==c) cout << "Yes";
    else cout << "No";
}


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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i, n) cin >> d.at(i);
  
  sort(d.begin(), d.end());
  int cnt = d.at(d.size()/2) - d.at(d.size()/2-1);
  cout << cnt << endl;
}

Measured memory_bytes: 640