akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    R,C,K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    base=5000
    S=[]
    for i in range(K):
        r,c,v = map(int, input().split())
        r-=1
        c-=1
        S.append((r*base+c,v))

    S.sort(key=itemgetter(0))


    p=0
    dp=[[0] * 4 for _ in range(C)]
    dpi=[[0] * 4 for _ in range(C)]
    for i in range(R):
        for j in range(C):
            cv=0
            if p<K and i*base+j==S[p][0]:
                cv=S[p][1]
                p+=1
            if j>0:
                dpi[j]=copy(dpi[j-1])
            else:
                dpi[0]=[0] * 4 
            if i>0:
                dpi[j][0]=max(dp[j],dpi[j][0])
            if cv!=0:
                for k in range(2,-1,-1):
                    dpi[j][k+1]=max(dpi[j][k]+cv,dpi[j][k+1])
                #printe(dp)
            dp[j]=max(dpi[j])
    print(dp[-1])



if __name__ == "__main__":
    main()


Measured memory_bytes: 174060
#include<bits/stdc++.h>
#define N 2005
using namespace std;
int n,m;
char s[N][N];
int same[N][N];
int sta[N],top;
int main(){
    scanf("%d%d",&n,&m);
    int ans=max(n,m);
    for(int i=1;i<=n;i++){
        scanf("%s",s[i]+1);
        top=0;sta[0]=1;
        for(int j=2;j<=m+1;j++){
            same[i][j]=(s[i-1][j]^s[i-1][j-1]^s[i][j]^s[i][j-1])==0 ? same[i-1][j]+1:1;
            if(j==m+1) same[i][j]=0;
            while(top>0&&same[i][sta[top]]>same[i][j]) ans=max(ans,(j-sta[top-1])*same[i][sta[top]]),top--;
            sta[++top]=j;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 19840
#include <stdio.h>

int ans[210];
int a[210][3];
int cnt[3][100];

int main(void)
{
	int n;
	int i;
	int j;
	int q;

	scanf("%d", &n);
	for (i = 0; i < n; i++){
		for (j = 0; j < 3; j++){
			scanf("%d", &q);
			a[i][j] = q;
			cnt[j][q]++;
		}	
	}
	for (i = 0; i < n; i++){
		for (j = 0; j < 3; j++){
			if (cnt[j][a[i][j]] == 1){
				ans[i] += a[i][j];
			}
		}
		printf("%d\n", ans[i]);
	}

	return (0);
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int n;
    cin>>n;
    vector<int>v;
    vector<int>s(n+1,0);
    for(int i=0;i<n;i++)
    {
        int p;
        cin>>p;
        v.push_back(p);
    }
     s[1] = 0;
     s[2] = abs(v[1]-v[0]);

     for(int i=3;i<=n;i++)
     {
         s[i] = min((s[i-1]+abs(v[i-1]-v[i-2])),(s[i-2]+abs(v[i-1]-v[i-3])));
     }

     cout<<s[n]<<endl;

    return 0;
}

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

int main(){
    vector<vector<int>> v(3,vector<int>(3));
    int n;
    int b[n];
    rep(i,3){
        rep(j,3){
            cin >> v.at(i).at(j);
        }
    }
    cin >> n;
    rep(i,n) cin >> b[i];

    for(int i = 0;i<3;i++){
        for(int j = 0;j < 3;j++){
            for(int k = 0;k < n;k++){
                if(v[i][j] == b[k]){
                    v[i][j] = 0;
                    break;
                }
            }
        }
    }
    bool han = false;
    for(int i=0;i < 3;i++){
        if(v[i][0]==v[i][1]&&v[i][1]==v[i][2] || v[0][i]==v[1][i]&&v[1][i]==v[2][i] || v[0][0] == v[1][1] && v[1][1] == v[2][2] || v[0][2] == v[1][1]&&v[1][1] == v[2][0]){
            han = true;
            break;
        }
    }
    if(han) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int comb(int n, int r){
	int res = 1;
	for(int i = 1; i <= r; i++){
		res *= (n - i + 1);
		res /= i;
	}
	return res;
}
int main(){
	int N, P;
	int A;
	scanf("%d %d", &N, &P);
	int odd = 0, even = 0;
	for(int i = 0; i < N; i++){
		scanf("%d", &A);
		if(A % 2 == 0) even++;
		else if(A % 2 == 1) odd++;
	}
	long long int ans = 1;
	for(int i = 1; i <= even; i++) ans *= 2;
	long long  per_even = 0;
	if(P == 0){
		for(int i = 0; i <= odd; i += 2){
			per_even += comb(odd, i);
		}
	}else{
		for(int i = 1; i <= odd; i += 2){
			per_even += comb(odd, i);
		}
	}
	printf("%lld\n", ans * per_even);
	return 0;
}


Measured memory_bytes: 256
#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 <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define F first
#define S second


int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

main(){
  int n;
  while(cin>>n,n){
    long double x[n],y[n];
    rep(i,n){
      cin>>x[i];
      cin.get();
      cin>>y[i];
    }
    int ans=1;
    rep(i,n-1){
      for(int j=i+1;j<n;j++){
        long double dx=x[j]-x[i],dy=y[j]-y[i];
        if(dx*dx+dy*dy>4)continue;
        int tans=0;
        long double xm=(x[j]+x[i])/2,ym=(y[j]+y[i])/2;
        long double arufa=atan2(dy,dx),beta=acos(sqrt((dx*dx+dy*dy))/2.0);
        long double kx=x[i]+cos(arufa+beta),ky=y[i]+sin(arufa+beta);
        rep(j,n){
          if(kx<0 || kx>10 || ky<0 || ky>10)continue;
          dx=kx-x[j],dy=ky-y[j];
          if(dx*dx+dy*dy<=1+EPS)++tans;
        }
        ans=max(ans,tans);
        tans=0;
        kx=x[i]+cos(arufa-beta),ky=y[i]+sin(arufa-beta);
        rep(j,n){
          if(kx<0 || kx>10 || ky<0 || ky>10)continue;
          dx=kx-x[j],dy=ky-y[j];
          if(dx*dx+dy*dy<=1+EPS)++tans;
        }
        ans=max(ans,tans);
      }
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 1e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

vector<pii> query[MAXN];
ll tree[MAXN*4];
ll dp[MAXN];

void update(int L,int R,ll v)
{
    while(L<=R){
        if(L&1)tree[L] = min(tree[L],v),L++;
        if(!(R&1))tree[R] = min(tree[R],v),R--;
        L>>=1; R>>=1;
    }
    return;
}

ll getans(int tmp)
{
    ll res = LINF;
    while(tmp){
        res = min(res,tree[tmp]);
        tmp>>=1;
    }
    return res;
}

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

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

    cin>>n>>m;

    for(int i=0;i<m;i++){
        cin>>x>>y>>a;
        x--; y--;
        query[x].push_back(pii(y,a));
    }

    int base = 1;

    for(;base<n;base<<=1);

    for(int i=(base<<1)-1;i>=1;i--)
        tree[i] = LINF;

    for(int i=0;i<query[0].size();i++){
        update(base,base+query[0][i].f,query[0][i].s);
    }

    for(int i=1;i<n;i++){
        dp[i] = getans(base+i);
        for(int j=0;j<query[i].size();j++){
            update(base+i,base+query[i][j].f,(ll)query[i][j].s+dp[i]);
        }
    }

    if(dp[n-1]==LINF)cout<<"-1\n";
    else cout<<dp[n-1]<<"\n";

    return 0;
}


Measured memory_bytes: 9600
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
distance=[[99999999 for i in range(n)] for i in range(n)]
for i in range(n):
  distance[i][i]=0
for i in range(m):
  distance[l[i][0]-1][l[i][1]-1]=l[i][2]
  distance[l[i][1]-1][l[i][0]-1]=l[i][2]

for k in range(n):
  for i in range(n):
    for j in range(n):
      distance[i][j]=min(distance[i][k]+distance[k][j],distance[i][j])

ct=m
for k in range(m):
  for i in range(n):
    for j in range(n):
      if i!=j:
        if distance[i][j]==distance[i][l[k][0]-1]+l[k][2]+distance[l[k][1]-1][j]:
          ct-=1
          break
    else:
      continue
    break
print(ct)

Measured memory_bytes: 44268
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n, w;
  cin >> n >> w;
  vector<long long> dp(w + 1);
  vector<pair<long long, long long>> ps(n);
  vector<int> m(n);
  for (int i = 0; i < n; i++) {
    cin >> ps[i].first >> ps[i].second >> m[i];
  }
  for (int i = 0; i < n; i++)
    for (int k = 0; m[i] > 0; k++) {
      long long key = min(m[i], (int)(1 << k));
      m[i] -= key;
      for (int j = w; j >= 0; j--) {
        if (j + ps[i].second * key <= w) {
          dp[j + ps[i].second * key] =
              max(dp[j + ps[i].second * key], dp[j] + ps[i].first * key);
        }
      }
    }
  long long ans = 0;
  for (int i = 0; i <= w; i++)
    ans = max(ans, dp[i]);
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3180
#include <stdio.h>
int main(){
  int n;
  scanf("%d", &n);
  int min = 1000000000;
  int neg_num = 0;
  long long int ans = 0;
  int i;
  for(i=0;i<n;i++){
    int a;
    scanf("%d", &a);
    if (a < 0){
      neg_num++;
      a = (-1) * a;
    }
    ans += a;
    if(min > a){
      min = a;
    }
  }
  if (neg_num % 2 == 1){
    ans -= 2 * min;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

int main() {
  int a, b, c, d;
  int x,y;

  cin >> a >> b >> c >> d;

  x = (c+b-1)/b; y = (a+d-1)/d; 

  if(y >= x){
    cout << "Yes" <<endl;
  }else{
    cout << "No" <<endl;
  }

  return 0;
}


Measured memory_bytes: 3624
from bisect import bisect_left
MOD = 10 ** 9 + 7

n = int(input())
clst = []
last = [-1 for _ in range(2 * 10 ** 5)]
before = [-1 for _ in range(2 * 10 ** 5)]
for i in range(n):
    c = int(input())
    clst.append(c - 1)
    before[i] = last[c - 1]
    last[c - 1] = i
dp = [0 for _ in range(n)]
dp[0] = 1

for i in range(1, n):
    dp[i] = dp[i - 1]
    if before[i] != -1 and before[i] != i - 1:
        pos = before[i]
        dp[i] += dp[pos]
    dp[i] %= MOD
print(dp[-1])

Measured memory_bytes: 34256
/*
AuThOr Gwj
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define debug_pair(A) cerr<<A.FIR<<" "<<A.SEC<<endl;
#define biggest(A,B) A=max(A,B)
#define smallest(A,B) A=min(A,B)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int res[10001];
int main(){
	fastio;
	int n;
	cin>> n;
	rb(i,1,100)
		rb(j,1,100)
			rb(k,1,100){
				if(i*i+i*j+j*k+i*k+j*j+k*k<=10000){
					res[i*i+i*j+j*k+i*k+j*j+k*k]++;
				}
			}
		rb(i,1,n)
			cout<<res[i]<<endl;
	return 0;
}


Measured memory_bytes: 3640
// https://atcoder.jp/contests/aising2020/tasks/aising2020_a

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll L, R, D;
  cin >> L >> R >> D;

  ll res = R / D - (L - 1) / D;
  cout << res << "\n";
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
 
#define ll unsigned long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll> ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define tr1(x) cerr << #x << ": " << x << endl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<a.size();zz++) cerr<<a[zz]<<" ";cerr<<endl
#define mod 1000000007
#define inf 9999999999999999ll
#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll h,n;
    cin>>h>>n;
    vi a(n);
    ll sum=0;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    if(sum>=h)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {

    static int[][] dir = new int[][]{{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        boolean[][] a = new boolean[h][w];
        ArrayDeque<int[]> deq = new ArrayDeque<>();
        for (int i = 0; i < h; i++) {
            char[] s = sc.next().toCharArray();
            for (int j = 0; j < w; j++) {
                if(s[j] == '#') {
                    a[i][j] = true;
                    deq.add(new int[]{i, j});
                }
            }
        }
        boolean changed = true;
        int cnt = 0;
        while(changed){
            changed = false;
            ArrayDeque<int[]> nextDeq = new ArrayDeque<>();
            while(!deq.isEmpty()){
                int[] b = deq.poll();
                for(int[] d : dir){
                    int x = b[0] + d[0];
                    int y = b[1] + d[1];
                    if(x < 0 || h -1 < x || y < 0 || w -1 < y) continue;
                    if(a[x][y]) continue;
                    a[x][y] = true;
                    changed = true;
                    nextDeq.add(new int[]{x, y});
                }
            }
            if(changed) cnt++;
            deq = nextDeq;
        }
        System.out.println(cnt);
        sc.close();
    }

}


Measured memory_bytes: 70352
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,count=0,m;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>m;
    for(int j=2;j*j<=m;j++)
      if(m%j==0){
    count++;
    break;
      }
  }
  cout<<n-count<<endl;
  return 0;
}



Measured memory_bytes: 3072
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define repf(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define repfr(i, x, n) for (int i = (int)(x)-1; i >= (int)(n); i--)
#define INF 1e9
using ll = int64_t;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
#define waru 1000000007

std::int64_t gcd(std::int64_t a, std::int64_t b) {
  // a >= b && b != 0
  std::int64_t c;
  do {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb) {
  std::int64_t a = max(aa, bb);
  std::int64_t b = min(aa, bb);
  std::int64_t c;
  if (b == 0) {
    return -1;
  }
  do {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
void rle(std::vector<std::pair<char, std::int64_t>> &data, std::string str) {
  char now = str[0];
  std::int64_t count = 0;
  for (std::int64_t i = 0; i < str.size() + 1; i++) {
    if (i == str.size()) {
      data.push_back(make_pair(str[i - 1], count));
      break;
    } else if (now != str[i]) {
      data.push_back(make_pair(now, count));
      now = str[i];
      count = 0;
    }
    count++;
  }

  return;
}

#define MAX_NUM 1001

void Main() {
  //自動整形防止用コメント
  int n, d;
  int x[20][20];
  int ans = 0;
  cin >> n >> d;
  rep(i, n){
    rep(j, d){
      cin >> x[i][j]; 
    }
  }

  rep(i, n){
    repf(j, i, n){
      if (i==j)
      {
        continue;
      }

      int sum = 0;
      rep(k, d){
        int tmp = abs(x[i][k] - x[j][k]);
        sum += tmp * tmp;
      }

      rep(k, sum + 1){
        if (k * k == sum)
        {
          ans++;
        }
      }
    } 
  }

  std::cout << ans << std::endl;

  return;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
arr = gets.chomp.split(' ').map(&:to_i)

def insertion_sort(arr, n)
  (1..n-1).each do |i|
    v = arr[i]
    j = i - 1
    while j >= 0 && arr[j] > v
      arr[j + 1] = arr[j]
      j -= 1
    end
    arr[j + 1] = v
    print "#{arr.join(' ')}\n"
  end
end

print "#{arr.join(' ')}\n"
insertion_sort(arr, n)



Measured memory_bytes: 6948
/* Coached by Dukkha */
#include <stdio.h>
#include <string.h>

#define N 200000
#define A 26

int main() {
	static char s[N + 1], t[N + 1], st[A], ts[A];
	int n, i;

	scanf("%s%s", s, t);
	n = strlen(s);
	for (i = 0; i < n; i++) {
		int a, b;

		a = s[i] - 'a';
		b = t[i] - 'a';
		if (st[a] != 0 && st[a] != b || ts[b] != 0 && ts[b] != a) {
			printf("No\n");
			return 0;
		}
		st[a] = b;
		ts[b] = a;
	}
	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,cnt=0,id;
    cin>>n;
    for(int i=1;i<=n;++i){
        scanf("%d",&id);
        if(i%2 && id%2)
            cnt++;
    }
    cout<<cnt;
}


Measured memory_bytes: 3684
#include<stdio.h>

void swap(int *x, int *y) {
	int temp;

	temp = *x;
	*x = *y;
	*y = temp;
}

int partiton(int A[], int p, int r) {
	int x, i, j;

	x = A[r];
	i = p - 1;
	for (j = p; j < r; j++) {
		if (A[j] <= x) {
			i++;
			swap(&A[i], &A[j]);
		}
	}
	swap(&A[i + 1], &A[r]);
	return i + 1;
}

int main() {
	int n, i, flag;
	int A[100000];

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

	flag = partiton(A, 0, n - 1);
	for (i = 0; i < n; i++) {
		if (i == flag) {
			printf("[%d]", A[i]);
		}
		else {
			printf("%d", A[i]);
		}
		if(i < n-1){
		    printf(" ");
		}
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 2168
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
	int N;
	cin >> N;
	int h[100];
	for (int i = 0; i < N; i++) {
		cin >> h[i];
	}
	int ans = 0;
	int l=-1,r=-1;
	int min=1000;
	bool fin = 1;
 
 
	while (1) {
		//0がない区間を探す&最小値を求める
		for (int i = 0; i < N; i++) {
			if (h[i] == 0) {
				if (l != -1) {
					r = i - 1;
					break;
				}
			}
			else {
				if (l == -1) l = i;
				if (min > h[i])min = h[i];
			}
			if (i == N - 1)r = i;
		}
 
 
		for (int i=l; i < r + 1; i++) {
			h[i] -= min;
		}
 
 
		
 
		for (int i = 0; i < N; i++) {
			if (h[i] != 0)break;
			if (i == N - 1) fin = 0;
		}
 
 
 
 
		ans = ans + min;
		min = 1000;
		l = -1;
		r = -1;
 
 
		if (fin == 0) {
			break;
		}
 
	}
 
 
	cout << ans << endl;
 
 
}

Measured memory_bytes: 256
from collections import Counter
n=int(input())
a=[int(i) for i in input().split()]
b=[]
for i in range(n):
 if a[i]%4==0:
    b.append(2)
 elif a[i]%2==0:
    b.append(1)
 else:
    b.append(0)
c=Counter(b)
if c[2]-c[0]>=0:
  print("Yes")
elif c[2]-c[0]==-1:
  if c[1]==0:
    print("Yes")
  else:
    print("No") 
else:
  print("No")

Measured memory_bytes: 14636
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define mp make_pair
signed main(){
    int n; cin>>n;
    vi v(n);
    rep(i,n)cin>>v[i];
    int m;
    cin>>m;
    int ans=0;
    rep(i,m){
        int t;
        cin>>t;
        int imax=n-1;
        int imin=0;
        int mid;
        while(imax>=imin){
            mid=(imax+imin)/2;
            if(v[mid]>t)imax=mid-1;
            else if(v[mid]<t)imin=mid+1;
            else {
                ans++;
                break;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3488
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int N, H;
  cin >> N >> H;
  vector<ll> a(N), b(N);
  for (int i = 0; i < N; i++) cin >> a[i] >> b[i];
  sort(a.begin(), a.end(), greater<int>());
  sort(b.begin(), b.end(), greater<int>());

  ll sum = 0, cnt = 0, ans = 0;
  for (int i = 0; i < N; i++) {
    if (b[i] < a[0]) break;
    cnt++;
    sum += b[i];
    ans = ((H - sum) + (a[0] - 1)) / a[0];
    if (sum >= H) {
      cout << cnt << endl;
      return 0;
    }
  }

  if (ans == 0 && cnt == 0) {
    ans = (H + (a[0] - 1)) / a[0];
    cout << ans << endl;
  } else
    cout << ans + min(cnt, ll(b.size())) << endl;

  return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int H = sc.nextInt();
            int W = sc.nextInt();
            int h = sc.nextInt();
            int w = sc.nextInt();
            System.out.println(H*W - h*W - H*w + h*w);
          }
}

Measured memory_bytes: 23252
#include<iostream>
#include<string>
using namespace std;
string g[8];

void solve(int y, int x) {
	g[y][x] = '0';
	for (int i = -3; i < 4; i++) {
		if (y + i >= 0 && y + i < 8 && g[y + i][x] == '1') {
			solve(y + i, x);
		}
	}
	for (int i = -3; i < 4; i++) {
		if (x + i >= 0 && x + i < 8 && g[y][x + i] == '1') {
			solve(y, x + i);
		}
	}
}

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 8; j++) cin >> g[j];
		int x, y;
		cin >> x >> y;
		x--; y--;
		solve(y, x);
		cout << "Data " << i + 1 << ":" << endl;
		for (int j = 0; j < 8; j++) cout << g[j] << endl;
	}
}


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

int main(){
    using namespace std;
    constexpr unsigned long MOD = 998244353;
    unsigned long N;
    cin >> N;
    vector<unsigned long> X(N);
    {
        string S;
        cin >> S;
        transform(S.begin(), S.end(), X.begin(), [](auto i){return i & 1;});
        transform(S.begin(), S.end(), back_inserter(X), [](auto i){return ~i & 1;});
    }
    vector<unsigned long> pow2(N + 1);
    pow2[0] = 1;
    for(unsigned long i = 1; i <= N; ++i)pow2[i] = pow2[i - 1] * 2 % MOD;
    const auto& answer = [&](auto x) -> unsigned long{
        unsigned long ret{0}, out{3 * N + 1}, safe{3 * N};
        for(unsigned long i = 0, t; i < x; ++i){
            if(t = X[i])(ret += pow2[x - i - 1]) %= MOD;
            for(unsigned long j = i; j < 2 * N; j += x){
                if(X[j] > t){
                    safe = min(safe, j);
                    break;
                }
                if(X[j] < t){
                    out = min(out, j);
                    break;
                }
                t ^= 1;
            }
        }
        return (ret + (safe < out)) % MOD;
    };
    vector<unsigned long> factor;
    {
        unsigned long i{1};
        for(; i * i < N; ++i)if(!(N % i)){
            if(i & 1)factor.push_back(i);
            if((N / i) & 1)factor.push_back(N / i);
        }
        if(i * i == N && i & 1)factor.push_back(i);
    }
    sort(factor.rbegin(), factor.rend());
    vector<unsigned long> ans(N + 1);
    unsigned long a{0};
    for(const auto& i : factor)if(i & 1) ans[i] = answer(N / i);
    for(const auto& i : factor){
        for(unsigned long j = 2 * i; j <= N; j += i)ans[i] += MOD - ans[j];
        a += (N / i) * (ans[i] %= MOD) % MOD;
    }
    cout << (a * 2) % MOD << endl;
    return 0;
}

Measured memory_bytes: 6564
//I am so vegetable
//#define err
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define PB push_back
#define IN insert
#define ER erase
#define CT count
#define EP empty
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _rfor(i,a,b) for(int i = (a);i>(b);--i)
#define _sfor(p,st) for(auto &p:st)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const double eps = 1e-6;
const double pi = acos(-1.0);
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
ll qpow(ll x, ll y) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans *= x; x *= x; }return ans; }
ll qpow(ll x, ll y, int MOD) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans = ans*x%MOD; x = x*x%MOD; }return ans; }
void exgcd(ll a,ll b,ll &x,ll &y){
    if(!b){x=1;y=0;return;}
    exgcd(b,a%b,x,y);
    ll X=x;
    x=y; y=X-a/b*y;
}
ll inv(ll x, int mod = MOD) { return qpow(x, mod - 2) % mod; }
ll m_m(ll a){ return (a%MOD+MOD)%MOD; }

const int N = 1e7+5;
ll cnt[N];
int main() {
	//ofstream cout("E:\\acm dream\\out.txt",ios::out);
	FIO;
    #ifdef err
	double be = clock();
    #endif
    int n;cin>>n;
    _for(i,1,n+1){
        for(int j = i;j<=n;j+=i)++cnt[j];
    }
    ll ans = 0;
    _for(i,1,n+1)ans+=i*cnt[i];
    cout<<ans;
    #ifdef err
	double en = clock();
    cout<<"time: "<<fixed<<setprecision(8)<<en-be;
    #endif
	return 0;
}

Measured memory_bytes: 81688
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
 
public class Main {
	private static FastScanner sc = new FastScanner();
	
	public static void main(String[] args) {
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		if(Math.abs(A - B) % 2 == 0) {
			System.out.println("Alice");
		} else {
			System.out.println("Borys");
		}
	}
	
	static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}


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

	long long a[200000];
	long long ruisekiwa[200001];

int main() {

	int N;
	cin >> N;

	long long reiwa = 0;

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

	ruisekiwa[0] = 0;

	for (int i=1;i<=N;i++) {
		ruisekiwa[i] = ruisekiwa[i-1] + a[i-1];
	}

	sort(ruisekiwa,ruisekiwa+N+1);

	long long kazu = 1;
	for (int i=0;i<N;i++) {
		
		
		if(ruisekiwa[i] == ruisekiwa[i+1]){
			kazu++;
		}

		else {
			reiwa += kazu*(kazu-1)/2;
			kazu = 1;
		}
	//	cout << kazu << endl;
		
	}

	reiwa += kazu*(kazu-1)/2;

	cout << reiwa << endl;

	return 0;
}


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

int main()
{
    double x1, y1, x2, y2;

    cin >> x1 >> y1 >> x2 >> y2;

    cout << fixed << sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)) << endl;

    return 0;
}


Measured memory_bytes: 3284
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
long long combi(long long n,long long k){
    k = min(k,n-k);
    long long p = 1;
    for(long long i = n;i>=n-k+1;i--){
        p*=i;
        p%=MOD;
    }
    for(long long i = 0;i<k;i++){
        p*=modinv(i+1,MOD);
        p%=MOD;
        //p/=(i+1);
    }
    return p;
}
int main(){
    long long x,y;
    cin >> x >> y;
    long long sum = x+y;
    if(sum%3!=0){
        cout << 0 << endl;
        return 0;
    }
    long long sumturn = sum/3;
    long long turn = (2*sumturn)-x;
    if(turn<0 || turn>sumturn){
        cout << 0 << endl;
        return 0;
    }
    long long ans = combi(sumturn,turn);
    cout << ans%MOD << endl;
}

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

int main() {
    ll k; cin >> k;
    cout << 50 << endl;
    vector<ll> a(50);
    for(int i = 0; i < 50; i++) {
        a[i] = i;
        a[i] += k/50LL;
    }
    for(int i = 0; i < k%50LL; i++) {
        a[i] += 50LL;
        for(int j = 0; j <50; j++) {
            if(j==i)continue;
            a[j] -= 1LL;
        }
    }
    for(int i = 0; i < 50; i++) {
        cout << a[i] << " ";
    }
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}
struct multi {
  ll first;
  ll second;
  ll third;
  multi(ll first, ll second, ll third)
      : first(first), second(second), third(third) {}
};
bool multicomp(const multi &a, const multi &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vector<pll> P(N);
  REP(i, N) {
    ll x, y;
    cin >> x >> y;
    P[i] = make_pair(x, y);
  }
  sort(ALL(P));
  map<pll, ll> M;
  REP(i, N - 1) FOR(j, i + 1, N) {
    pll po = make_pair(P[j].first - P[i].first, P[j].second - P[i].second);
    if (M.find(po) == M.end()) {
      M[po] = 1;
    } else {
      M[po]++;
    }
  }
  ll ans = 0;
  AUTO(m, M) { ans = max(m.second, ans); }
  cout << min(N - ans, N) << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
struct __test {} test;
using namespace std;
template <typename T>const __test &operator<<(const __test& d,
const T& v) {return cerr << "\033[31m" << v << "\033[0m",d;}
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;

const int N = 505;
int a[N*N]={},ctr = 0;

void move() {
	while(a[++ctr] != 0);
}

vector<pii> v;

bool place(int x, int i, int t, bool w) {
	while(t--) {
		move();
		if(w && ctr > x) return false;
		if(!w && ctr < x) return false;
		a[ctr] = i;
	}
	return true;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int n,x;
	cin >> n;
	for(int i = 1; i <= n; ++i) {
		cin >> x;
		v.pb(pii(x,i));
	}
	sort(v.begin(),v.end());
	for(pii &p : v) {
		int x=p.fi,i=p.se;
		a[x] = i;
		if(!place(x,i,i-1,1)) {
			cout << "No\n";
			return 0;
		}
	}

	for(pii &p : v) {
		int x=p.fi,i=p.se;
		if(!place(x,i,n-i,0)) {
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
	for(int i = 1; i <= n*n; ++i) {
		cout << a[i] << " ";
	}
	cout << "\n";
	return 0;
}

Measured memory_bytes: 2176
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) {
        std::cout << i << ' ';
        vdeb(da[i]);
    }
    std::cout << '\n';
}

using namespace std;

int main() {
    ll a,v,b,w,t; cin >> a >> v >> b >> w >> t;
    ll dist = abs(a-b), sp = abs(v-w);
    if(sp*t >= dist && w < v) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()

using namespace std;

typedef long long ll;

int ans;
int N, H;
int a[100005], b[100005];

int main(void) {
    scanf("%d %d", &N, &H);
    int max_a = 0;
    rep(i, 0, N) {
        scanf("%d %d", &a[i], &b[i]);
        max_a = max(max_a, a[i]);
    }

    sort(b, b+N, greater<int>());

    rep(i, 0, N) {
        if (b[i] < max_a) break;
        H = H - b[i];
        ans++;
        if (H <= 0) break;
    }

    if (H > 0) ans += (H + max_a - 1) / max_a; 
  
    printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
int main(){
	int a;
	double PI=3.14159265359;
	while(scanf("%d",&a),~a){
		double x=1.0;
		double y=0.0;
		double r=PI/2;
		for(int i=0;i<a-1;i++){
			y+=sin(r);
			x+=cos(r);
			r=atan(y/x);
			if(x<0)r=r+PI;
			r+=PI/2;
		}
		printf("%.2lf\n%.2lf\n",x,y);
	}
}

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

int main(){
    int r, d;
    vector<long long int> x(11,0);
    cin >> r >> d >> x[0];

    for(int i=1; i<11; i++){
        x[i] = r*x[i-1] - d;
        cout << x[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int N = sc.nextInt();
		
		int[] d = new int[N];
		for (int i = 0; i < N; i++) {
			d[i] = sc.nextInt();
		}
        int ans = 0;
        for (int i = 0; i < N-2; i++) {
        int l = d[i];
        int m = d[i+1];
        int r = d[i+2];        
        if(((l > m) && (m > r)) || ((l < m) && (m < r))){
          ans++;
        }
        }
		System.out.println(ans);
	}		
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
int main(){
  int n;
  cin>>n;
  vi fb(n,0);
  rep(i,n){
    if((i+1)%3==0||(i+1)%5==0){
      fb[i]=0;
    }
    else fb[i]=(i+1);
  }
  ll ans =0;
  rep(i,n)ans+=fb[i];
  cout<<ans<<endl;

}


Measured memory_bytes: 7060
#include <bits/stdc++.h>
using namespace std;
 
 
#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;
 
ll mod = 1e9 + 7ll;
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; }
const ll inf = 1ll << 60;

int n, m, p;
vector<vector<pair<int, int>>> rpass(3000);
vector<vector<int>> pass(3000);
vector<int> cango(3000);
vector<int> cancome(3000);
vector<int> s;
vector<vector<int>> opt(3000, vector<int>(3000, -1000000000));
int A, B, M;
vector<int> pa(101010);
vector<int> pb(101010);

int main(){
    cin >> A >> B >> M;
    int ma = 101010;
    rp(i, 0, A){
        int a;
        scanf("%d", &a);
        pa.at(i) = a;
        chmin(ma, a);
    }
    int mb = 101010;
    rp(i, 0, B){
        int b;
        scanf("%d", &b);
        pb.at(i) = b;
        chmin(mb, b);
    }

    int ans = ma + mb;
    rp(i, 0, M){
        int x, y, c;
        scanf("%d%d%d", &x, &y, &c);
        chmin(ans, pa.at(x-1)+pb.at(y-1)-c);
    }
    printf("%d", ans);
    return 0;

}

Measured memory_bytes: 36608
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef vector<lint> vlint;

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

int main(){
    int n; cin >> n;
    int a[n]; rep(i, n) cin >> a[i];
    int b[n], c[n];
    map<int, int> cnt_b;
    rep(i, n){
        b[i] = i+1 + a[i];
        c[i] = i+1 - a[i];
    }
    lint ans = 0;
    for (int j = 1; j < n; j++){
        ans += cnt_b[c[j]];
        if (c[j] == b[j-1]) ans++;
        cnt_b[b[j-1]] ++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 22960
# 文字列の問題で、同じような文字列をまとめたいので、
# どう考えても Trie を使いたい気持ちになる

# あとは適当にやったらなんとかなった
# 1100 点の割には簡単っぽい

class TrieNode:
    def __init__(self):
        self.child = {}
        self.count = 0  # 自身を含めた部分木の大きさ

class Trie:
    def __init__(self):
        self.root = TrieNode()

    def add(self, s):
        node = self.root
        node.count += 1
        for c in s:
            c = ord(c) - 97
            if c not in node.child:
                node.child[c] = TrieNode()
            node = node.child[c]
            node.count += 1
        node.child[26] = TrieNode()
        node.child[26].count += 1

    def query(self, s):
        res = [[0]*27 for _ in range(26)]
        node = self.root
        for c in s:
            c = ord(c) - 97
            res_c = res[c]
            for i, child in node.child.items():
                res_c[i] += child.count
            node = node.child[c]
        return res

from itertools import groupby
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    S = [input()[:-1] for _ in range(N)]
    trie = Trie()
    for s in S:
        trie.add(s)

    Q = int(input())
    KP = [input().split() for _ in range(Q)]
    Ans = [-1] * Q
    Idx_Q = sorted(range(Q), key=lambda x: KP[x][0])
    for v, g in groupby(Idx_Q, key=lambda x: KP[x][0]):
        K = int(v) - 1
        L_K = trie.query(S[K])
        for idx in g:
            _, P = KP[idx]
            P = [ord(c) - 97 for c in P]
            ans = 1
            for i, pi in enumerate(P):
                for pj in P[:i]:
                    ans += L_K[pi][pj]
                ans += L_K[pi][26]
            Ans[idx] = ans
    print("\n".join(map(str, Ans)))

main()


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

bool visit[8][8];

int ans(int v, int N, bool *visited){

  int ret=0;
  bool all_visited;

  all_visited = true;
  for(int i=0; i<N; i++){
    if(!visited[i]) all_visited=false;
  }
  if(all_visited) return 1;

  for(int i=0; i<N; i++){
    if(visit[v][i] && !visited[i]){
      visited[i]=true;
      ret += ans(i,N,visited);
      visited[i]=false;
    }
  }

  return ret;
}

int main(){

  bool visited[8];
  for(int i=0; i<8; i++) visited[i]=false;
  visited[0]=true;

  for(int i=0; i<8; i++){
    for(int j=0; j<8; j++){
      visit[i][j] = false;
    }
  }

  int N,M;
  cin >> N >> M;
  int a[M],b[M];
  for(int i=0; i<M; i++){
    cin >> a[i] >> b[i];
    visit[a[i]-1][b[i]-1]=true;
    visit[b[i]-1][a[i]-1]=true;
  }

  cout << ans(0, N, visited) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int dfs(const vector<vecint>& g, vecint& d, int i) {
  if (d[i] >= 0) return d[i];
  int ans = 0;
  for(auto&& to:g[i]) {
    ans = max(ans, dfs(g, d, to)+1);
  }
  d[i] = ans;
  return ans;
}

int main()
{
  int n,m;
  cin>>n>>m;
  vector<vecint> g(n);
  vector<vecint> rg(n);
  for(auto&& i:irange(0,m)) {
    int x,y;
    cin>>x>>y;
    --x;--y;
    g[x].push_back(y);
    rg[y].push_back(x);
  }
  int ans = 0;
  vecint d(n, -1);
  for(auto&& i:irange(0,n)) {
    if (g[i].size() == 0) {
      ans = max(ans, dfs(rg, d, i));
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 17792