akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0) return 1;

  if (p % 2 == 0) {
    ll half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1;  // 分母
  ll numerator = 1;    // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

class UnionFind {
 private:
  vector<ll> parents;

 public:
  UnionFind(ll n) : parents(n, -1) {}

  bool issame(ll x, ll y) { return root(x) == root(y); }

  bool merge(ll x, ll y) {
    if (issame(x, y)) return false;

    ll rx = root(x);
    ll ry = root(y);
    if (parents[rx] > parents[ry]) swap(rx, ry);
    // サイズ情報を更新
    parents[rx] += parents[ry];
    // yの親を更新
    parents[ry] = rx;

    return true;
  }

  ll size(ll x) { return -parents[root(x)]; }

 private:
  ll root(ll x) {
    if (parents[x] < 0) return x;
    // 根の親の値に木の(-)サイズの情報を入れる
    return parents[x] = root(parents[x]);
  }
};

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

int main() {
  ll A, B;
  cin >> A >> B;

  ll n = gcd(A, B);

  // cout << n << endl;

  vector<ll> primes;

  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      // cout << i << endl;
      primes.push_back(i);
      while (n % i == 0) {
        n /= i;
      }
    }
  }

  if (n != 1) {
    primes.push_back(n);
  }

  cout << primes.size() + 1 << endl;

  return 0;
}


Measured memory_bytes: 256
def main():

    N, M, C = map(int, input().split())
    B = [int(b) for b in input().split()]
    A = [None]*N
    for n in range(N):
        A[n] = [int(a) for a in input().split()]

    count = 0

    for n in range(N):
        dot = C
        for m in range(M):
            dot += A[n][m]*B[m]
        if dot > 0:
            count += 1

    print(count)


main()


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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<string> W;
    string S;
    for(int i=0; i<n; i++) {
        cin >> S;
        W.push_back(S);
    }

    for(int i=0; i<W.size() - 1; i++) {
        if(W[i].back()!=W[i+1].front()){
            cout << "No" << endl;
            goto END;
        }
    }

    sort(W.begin(), W.end());
    for(int i=0; i<n-1; i++) {
        if(W[i]==W[i+1]){
            cout << "No" << endl;
            goto END;
        }
    }
    cout << "Yes" << endl;
    END:
    return 0;
}

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

int main(){
	ll x;
	cin >> x;
	ll a = x/500;
	ll b = x%500;
	ll c = b/5;
	ll ans = a*1000 + c*5;
	cout << ans << endl;
    return 0;
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n=1,cnt=0,ans=0,a,b,c,cmp,data,m,h,x,y,xcmp=0,ycmp=0,sum=0;

string s,w;

vector<int> z;

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

        bool fl=true;
       cin >> s;
       a=s[0]-'0';
       a--;
       rep(i,s.size()){
           if(s[i]!='9' && i!=0){
               fl=false;
           }
       }
       b=9*(s.size()-1);
       if(fl==false){
           Cout(a+b);
       }
       else{
       Cout(a+b+1);
       }
       
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long     ll;
#define fast          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define last          freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fr            first
#define sc            second
#define lcm(a,b)      (a*b)/__gcd(a,b)
#define com(i,n)      for(int i=0;i<n;i++)
#define dom(i,n)      for(int i=1;i<=n;i++)
#define mom(i,n)      for(int i=n;i>=0;i--)
#define sortI(a,n)    sort(a,a+n)
#define sortD(a,n)    sort(a,a+n,greater<int>())
#define sortvi(a)     sort(a.begin(),a.end())
#define sortvd(a)     sort(a.begin(),a.end(),greater<int>())
#define sumall(a,x)   accumulate(a.begin(),a.end(),x)
#define pi            3.14159265358979323846264338327950
#define endl          '\n'
using namespace std;
int main()
{
     ll n;
     cin>>n;
     ll cnt=1e18;
     for(ll i=1;i*i<=n;i++)
     {
          if(n%i==0)
          {
               ll x=n/i;
               cnt=min(cnt,i+x);
          }
     }
     cout << cnt-2 << endl;
}


Measured memory_bytes: 3596
a,b,c = map(int, input().split())
k = int(input())

if b <= a:
    while k > 0:
        b *= 2
        k -= 1
        if b > a:
            break

if c <= b:
    while k > 0:
        c *= 2
        k -= 1
        if c > b:
            break

if c > b and b > a:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9176
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    cin >> n;
    map<int, int> mp;
    REP(i,n){
        int a;
        cin >> a;
        mp[a]++;
    }

    int ans = 0;
    for (P p : mp){
        if (p.second >= p.first) ans += p.second - p.first;
        else ans += p.second;
    }
    cout << ans << endl;

    return 0;
}





Measured memory_bytes: 4736
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
typedef long long ll;
ll a[20000],dp[20001];
ll n, m, k;
const ll inf = 98989899898989;
int main() {
	cin >> n >> m >> k;
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
		dp[i] = inf;
	}
	dp[n] = inf;
	dp[0] = 0;
	ll mi, ma;
	for (ll i = 0; i < n; i++) {
		ma = a[i];
		mi = a[i];
		for (ll j = 1; j <= m&&i + j <= n; j++) {
			ma = max(ma, a[i + j - 1]);
			mi = min(mi, a[i + j - 1]);
			dp[i + j] = min(dp[i + j], (dp[i] + k + j*(ma - mi)));
		}
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 3408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

namespace ABC176
{
    class Program
    {
        static void Main(string[] args)
        {
            string N = Console.ReadLine();
            int[] nums = new int[N.Length] ;
            char[] ns = N.ToCharArray();
            for(var i= 0; i<N.Length; i++)
            {
                nums[i] = int.Parse(ns[i].ToString());
            }
            int result = nums.Sum();
            if(result%9 == 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

            
        }
    }
}


Measured memory_bytes: 34544
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


int main() {
	init();

	int N, K; cin >> N >> K;
	vector<ll>vec(N);
	vector<ll>ng, ps;
	ng.push_back(0);
	ps.push_back(0);
	rep(i, 0, N) {
		cin >> vec[i];
		if (vec[i] < 0)ng.push_back(abs(vec[i]));
		else ps.push_back(vec[i]);
	}
	sort(all(ng));
	ll ans = (ll)1e18;
	rep(i, 0, min((int)ng.size(), K + 1)) {
		if (K - i >= ps.size() || ps.size() - 1 - i < 0)continue;
		ll cnt = min(ng[i] * 2 + ps[K - i], ng[i] + ps[K - i] * 2);
		chmin(ans, cnt);
	}
	cout << ans << "\n";

	return 0;
}

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

int gcd(int a, int b)
{
	if(a < b) swap(a, b);
	if(a % b == 0) return b;
	else return gcd(b, a % b);
}
int main(void)
{
	int a, b;
	cin >> a >> b;
	cout << gcd(a, b) << endl;
	return 0;
}


Measured memory_bytes: 3096
use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn input_vec() -> Vec<u64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn main() {
    let n: u64 = input();
    let a_vec = input_vec();
    for a in a_vec {
        if a % 2 == 0 {
            if a % 3 != 0 && a % 5 != 0 {
                println!("DENIED");
                return;
            }
        }
    }
    println!("APPROVED");
}


Measured memory_bytes: 4352
N,M = map(int,input().split())
A = set([int(input()) for _ in range(M)])
dp = [0]*(N+1)
dp[0] = 1
for i in range(1,N+1):
    dp[i] = (dp[i-1] + dp[i-2])%(1000000007)
    if i in A:dp[i] = 0
    
print(dp[N])

Measured memory_bytes: 13192
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 
 
int32_t main()
{
    fast;
    int n; cin >> n;
    cout << n + n*n + n*n*n;
    
    
    
    return 0;
}

Measured memory_bytes: 3588
def modsum(n)
  case n % 4
  when 0 then n
  when 1 then 1
  when 2 then n + 1
  when 3 then 0
  end
end

a,b = gets.to_s.split.map{ |v| v.to_i }
puts modsum(b) ^ modsum(a-1)

Measured memory_bytes: 14196
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int total = 0;
		int pow = 0;
		int av = 0;
		int[] X = new int[N];
		for (int i = 0; i < N; i++) {
			X[i] = sc.nextInt();
			total += X[i];
		}
		if ((10*total/N)%10 < 5) {
			av = total/N;
		} else {
			av = total/N + 1;
		}
		for (int x : X) {
			int p = x - av;
			pow += p*p;
		}
		System.out.println(pow);
	}
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    ll a,b,c,k;cin>>a>>b>>c>>k;
    if(abs(b-a)>=1e18){co("Unfair");return 0;}
    co((k%2==1)?b-a:a-b);
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a,b;
scanf("%d %d",&a,&b);
if(a==b)printf("Draw\n");
else if(a==1)printf("Alice\n");
else if(b==1)printf("Bob\n");
else if(a>b)printf("Alice\n");
else printf("Bob\n");
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cassert>
#include <unordered_map>

#define _(x) { cout << #x << " = " << x << " "; }

const double E = 1e-8;
const double PI = acos(-1);

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x,y,z;
    cin >> x >> y >> z;
    swap(x,y);
    swap(x,z);

    cout << x << " " << y << " " <<  z << '\n';
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
 
signed main() {
    int A1,A2,A3;
    cin>>A1>>A2>>A3;
    cout<<(int)max(abs(A2-A3),max(abs(A1-A2),abs(A1-A3)))<<endl;
    return 0;
}

Measured memory_bytes: 256
# sys.stdin.readline
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        abc = list(map(int, input().split()))

        M = max(abc)
        if M % 2 == sum(abc) % 2:
            print((3 * M - sum(abc)) // 2)
        else:
            print((3 * (M + 1) - sum(abc)) // 2)


# Run main
if __name__ == '__main__':
    AtCoder().main()


Measured memory_bytes: 38384
s=gets.chomp.chars
f=false
r=0
s.size.times{|i|
  if !f && i<s.size-1 && s[i+1]<"9"
    f=true;r+=s[i].to_i-1;s[i+1]="9"
  elsif f
    r+=9
  else
    r+=s[i].to_i
  end
}
p r

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

signed main(){

  int q;
  cin>>q;
  map<string,int> mp;
  while(q--){
    int c;
    cin>>c;
    if(c==0){
      string key;
      int x;
      cin>>key>>x;
      mp[key] = x;
    }
    if(c==1){
      string key;
      cin>>key;
      cout<<mp[key]<<endl;
    }
    if(c==2){
      string key;
      cin>>key;
      mp.erase(key);
    }
  }

}


Measured memory_bytes: 27776
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

const int MOD = 1000000000+7;
int vs[100005];

int hist[100000+10];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) {
    scanf("%d", &vs[i]);
    hist[vs[i]]++;
    if((n % 2 == vs[i] % 2) || hist[0] > 1 || hist[vs[i]] > 2) {
      puts("0");
      return 0;
    }
  }
  ll res = 1;
  REP(i, n / 2) {
    res *= 2;
    res %= MOD;
  }
  printf("%lld\n", res);
  
  return 0;
}


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


#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 all(v) v.begin(), v.end()
#define print(x) cout << x << endl;
typedef long long ll;

constexpr ll INF = 1'010'000'000'000'000'017LL;\
constexpr ll MOD = 1'000'000'007LL;\
constexpr double EPS = 1e-12;\
constexpr double PI = 3.14159265358979323846;

int main()
{
    double L;
    cin >> L;
    print(setprecision(20) << pow(L/3., 3));

    return 0;
}

Measured memory_bytes: 256
//|  ADARSH SINGH KUSHWAHA |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Bahut_tej_gand_faad ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define pb push_back
#define ff first
#define ss second
#define mp map<ll,ll>
#define ve vector<ll>
#define st set<int>
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rep(i, n) for (int i = 0; i < n; i++)
#define srt(v) sort(v.begin(),v.end(),greater<int>())
#define mod 1000000007
#define max 1000001
vector<int> a(200005);
void solve(){
	string s;
	cin>>s;
	string k;
	k.append(s);
	if(s[s.size()-1]=='e'){
		k.append("s");
	}else if(s[s.size()-1]=='s'){
		k.append("es");
	}else{
		k.append("s");
	}
	cout<<k<<endl;
}
int main(){
	Bahut_tej_gand_faad;
	int t=1;
	//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3852
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main() {
  string s;
  int n, k;
  cin >> k >> n >> s;
  // cout << (char)('a' + s.at(n) - 'A') << endl;
  s.at(n - 1) = (char)('a' + s.at(n - 1) - 'A');
  
  cout << s << endl;

}


Measured memory_bytes: 256
import collections
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]

c = collections.Counter(s).most_common()
C = []
for i in range(len(c)):
    C.append([c[i][0], c[i][1]])

ans = []
for j in range(len(C)):
    if C[j][0] in t:
        C[j][1] -= t.count(C[j][0])
    ans.append(C[j][1])

print(max(ans) if max(ans) > 0 else 0)

Measured memory_bytes: 3316
#!/usr/bin/env python3
import sys
from collections import defaultdict
# input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))


def main():
    N = INT()
    P = [INT() for _ in range(N)]

    # dp[i] = iを最後とする1づつ連続する増加列の長さ
    dp = [0]*(N+1)

    for i in range(N):
        dp[P[i]] = dp[P[i]-1] + 1
    
    print(N-max(dp))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 19188
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    string s1,s2;
    cin>>s1>>s2;
    ll n=s1.length(),m=s2.length();
    ll dp[n+1][m+1]={0};
    for(int i=0;i<=m;i++)
        dp[0][i]=0;
    for(int i=0;i<=n;i++)
        dp[i][0]=0;

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(s1[i-1]==s2[j-1])
                dp[i][j] = dp[i-1][j-1]+1;
            else
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
        }
    }
    string ans;
    int i=n,j=m;
    while(i>0 && j>0 && dp[i][j]>0){
        while(dp[i][j]==dp[i-1][j])
            i--;
        while(dp[i][j]==dp[i][j-1])
            j--;
        ans.pb(s1[i-1]);
        i--;j--;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
}


Measured memory_bytes: 70656
#include<stdio.h>
char index2mark(int);
int mark2index(char);
int main(void){
    int card[52] = {};
    char mark;
    int num, N, i, j;

    scanf("%d", &N);
    while(getchar() != '\n');
    for(i = 0; i < N; i++){
        scanf("%c %d", &mark, &num);
        card[mark2index(mark) * 13 + (num - 1)] = 1;
        while(getchar() != '\n');
        // printf("%d",mark2index(mark));
        
    }
    for(j = 0; j < 52; j++){
        if(card[j] == 0){
            printf("%c %d\n", index2mark(j / 13), (j % 13) + 1);
        }
    }
    

    return 0;
}
char index2mark(int index){
    char mark;
    switch (index)
    {
    case 0:
        mark = 'S';
        break;

    case 1:
        mark = 'H';
        break;

    case 2:
        mark = 'C';
        break;

    case 3:
        mark = 'D';
        break;

    default:
        mark = '\0';
        break;
    }
    return mark;
}
int mark2index(char mark){
    int index;

    switch (mark)
    {
    case 'S':
        index = 0;
        break;

    case 'H':
        index = 1;
        break;

    case 'C':
        index = 2;
        break;

    case 'D':
        index = 3;
        break;

    default:
        index = -1;
        break;
    }
    return index;
}


Measured memory_bytes: 2044
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int N,T[4][15],Y[15],i,j,t,f=0;
char CS[5][2],s[]="SCHD",n[]="A23456789TJQKA";

int ns(char a){int i,c=0;for(i=0;i<5;i++)c+=CS[i][0]==a;return c;}
int cf(){
	int i;for(i=1;i<5&&CS[i][1]==CS[i-1][1];i++);
	return i==5;
}
int crs()
{
	return ns('T')&&ns('J')&&ns('Q')&&ns('K')&&ns('A');}
int cs()
{
	int i;
	for(i=0;i<10;i++)
	{
		if(ns(n[i])&&ns(n[i+1])&&ns(n[i+2])&&ns(n[i+3])&&ns(n[i+4]))
			return 1;
	}
	return 0;
}
int cp(int num)
{
	int r=0,i;
	for(i=0;i<13;i++)
	{
		if(ns(n[i])==num)
			r++;
	}
	return r;
}

int role()
{
	if(cf()&&crs())return Y[8];
	if(cf()&&cs())return Y[7];
	if(cp(4))return Y[6];
	if(cp(3)&&cp(2))return Y[5];
	if(cf())return Y[4];
	if(cs())return Y[3];
	if(cp(3))return Y[2];
	if(cp(2)==2)return Y[1];
	if(cp(2)==1)return Y[0];
	return 0;
}

int base(char c,char r)
{
	int a,b;
	for(a=0;s[a]!=r;a++);
	for(b=0;n[b]!=c;b++);
	return T[a][b];
}

int main()
{
	for(;~scanf("%d",&N);f++)
	{
		if(f)puts("");
		for(i=0;i<4;i++)
			for(j=0;j<13;j++)
				scanf("%d",&T[i][j]);
		for(i=0;i<9;i++)scanf("%d",&Y[i]);
		getchar();
		for(i=0;i<N;i++)
		{
			t=0;
			for(j=0;j<5;j++)
			{
				scanf("%c%c%*c",&CS[j][0],&CS[j][1]);
				t+=base(CS[j][0],CS[j][1]);
			}
			printf("%d\n",t*role());
		}
	}
	return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e5+3;
int h,w,k;
string s[10];

int32_t main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>h>>w>>k;
	// cout<<h<<" "<<w<<k<<"\n";
	for(int i=0;i<h;i++) cin>>s[i];
	int ans=1e12;
	for(int i=0;i<(1LL<<(h-1));i++)
	{
		vector<int> pos;
		for(int j=0;j<(h-1);j++)
		{
			if(i&(1LL<<j))
			{
				pos.pb(j);
			}
		}
		vector<pii> oof;
		int prev=0;
		for(auto x:pos)
		{
			oof.pb({prev,x});
			prev=x+1;
		}
		oof.pb({prev,h-1});
		vector<int> lol(oof.size(),0);
		int cnt=pos.size();
		for(int j=0;j<w;j++)
		{
			for(int o=0;o<oof.size();o++)
			{
				int cnt1=0;
				for(int p=oof[o].fi;p<=oof[o].se;p++)
				{
					cnt1+=(s[p][j]=='1');
				}
				lol[o]+=cnt1;
			}
			bool ok=true;
			for(auto x:lol)
			{
				if(x>k)
				{
					ok=false;
				}
			}
			if(i==0){
				// cout<<oof[0].fi<<" "<<oof[0].se<<"\n";
				// for(auto x:lol)
				// {
				// 	cout<<x<<" ";
				// }
				// cout<<"\n";
			}
			if(!ok){
				cnt++;
               // if(i==0) cout<<j<<" ";
              for(auto &x:lol) x=0;
				for(int o=0;o<oof.size();o++)
				{
					int cnt1=0;
					for(int p=oof[o].fi;p<=oof[o].se;p++)
					{
						cnt1+=(s[p][j]=='1');
					}
					lol[o]+=cnt1;
				}
			}
		}	
		bool ok=true;
		for(auto x:lol)
		{
			if(x>k)
			{
				ok=false;
			}
		}
		// for(auto x:oof)
		// {
		// 	cout<<x.fi<<" "<<x.se<<"\n";
		// }
	
		if(ok)
		{
			ans=min(ans,cnt);
		}
	}
	cout<<ans;
}
// Don't be afraid to fail. Be afraid not to try.
// "Become grindian instead of greendian" - aryanc403
// When you want to succeed as bad as you want to breathe, only then you’ll Be Successful!
// No Matter,How Fast You Are Driving If You Are Driving in a Wrong Direction You Will Never Reach Your Destination
// When failures hit you, you hit the failures back with Bounce Back!
// When you face failures, Don’t change your goal, Change your strategy!


Measured memory_bytes: 256
#include<stdio.h>

#define MAP_NUM 21
#define NEUTRAL 10
#define COMMAND_NUM 30

void trace(int A[], int n){
	int i;
	for ( i = 1; i <= n; i++ ){
		if ( i > 1 ) printf(" ");
		printf("%d", A[i]);
	}
	printf("\n");
}

int main(){
    int jewel_num, command_num;
    int map[MAP_NUM][MAP_NUM], command[COMMAND_NUM];
    char direction[COMMAND_NUM], d_char;
    int k, m, i, j, flg;
    int x, y;

    while(1){
        /* ?????°???????????? */
        for(i = 0; i < MAP_NUM; i++){
            for(j = 0; j < MAP_NUM; j++){
                map[i][j] = 0;
            }
        }
        for(i = 0; i < COMMAND_NUM; i++){
            direction[i] = ' ';
            command[i] = 0;
        }
        x = NEUTRAL;
        y = NEUTRAL;

        /* ???????????°?????? */
        scanf("%d", &jewel_num);
        if(jewel_num == 0){
            /* 0????????????????????? */
            break;
        }

        /* ????????????????????? */
        for(i = 0; i < jewel_num; i++){
            scanf("%d", &k);
            scanf("%d", &m);
            map[k][m] = 1;
        }

        /* ?????????????§??????????????????°?????? */
        scanf("%d", &command_num);
        
        /* ?????????????§?????????????????????? */
        for(i = 0; i < command_num; i++){
            scanf("%c", &d_char);
            scanf("%c", &d_char);
            scanf("%d", &m);
            direction[i] = d_char;
            command[i] = m;
        }

        /* ???????????¢??? */
        for(i = 0; i < command_num; i++){
            for(j = 1; j <= command[i]; j++){
                /* ????§?????¢?????????? */
                if(direction[i] == 'N'){
                    y++;
                }
                if(direction[i] == 'E'){
                    x++;
                }
                if(direction[i] == 'W'){
                    x--;
                }
                if(direction[i] == 'S'){
                    y--;
                }

                /* ??????????????? */
                map[x][y] = 0;
            }
        }

        /* ??????????????°????????????????????????????????? */
        map[NEUTRAL][NEUTRAL] = 0;

        /* ???????????°????????§???????????? */
        flg = 0;
        for(i = 0; i < MAP_NUM; i++){
            for(j = 0; j < MAP_NUM; j++){
                if(map[i][j] != 0){
                    flg = 1;
                }
            }
        }
        if(flg != 0){
            /* ?????????????????§????????£???????????°No??????????????? */
            printf("No\n");
        }
        else{
            /* ???????????????????????£?????????????????°Yes??????????????? */
            printf("Yes\n");
        }
    }

	return 0;
}

Measured memory_bytes: 1680
#include <bits/stdc++.h>
using namespace std;
#define debug(a) cout << #a": " << a << endl;
#define mst(a, b) memset(a, b, sizeof(a))
inline int lowbit(int x) { return x & -x; }
typedef long long LL;
const int N = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
const int mod = 1e9 + 7;

LL dp[N];
int w[N];
int v[N];

int main() {
#ifdef purple_bro
    freopen("in.txt","r",stdin);
#endif
    int n, W;
    int tot = 0;

    scanf("%d%d", &n, &W);

    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &w[i], &v[i]);
        tot += v[i];
    }

    mst(dp, 0x3f);
    dp[0] = 0;

    for (int i = 1; i <= n; i++) {
        for (int j = tot; j - v[i] >= 0; j--) if (dp[j - v[i]] != INF)
            dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
    }

    for (int i = tot; i >= 0; i--) if (dp[i] <= W)
        return printf("%d\n", i), 0;

    return 0;
}


Measured memory_bytes: 1024
while 1:
	n = input()
	if n == 0: break
	xy = [map(int,raw_input().split()) for i in range(n)]
	S = set(map(tuple,xy))
	ans = 0
	for i in range(n):
		x1,y1 = xy[i]
		for j in range(n-1,i,-1):
			x2,y2 = xy[j]
			a = (x2-y2+y1,y2+x2-x1)
			b = (x1-y2+y1,y1+x2-x1)
			if a in S and b in S:
				ans = max(ans,(x1-x2)**2 + (y1-y2)**2)
	print ans

Measured memory_bytes: 5792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll t,n,k,a,b,c,p,q,r,s,x,y,z;
    cin>>a>>b>>k;
    if((b-a+1)<=2*k)
    {
    for(ll i=a;i<=b;i++)
        cout<<i<<endl;
    }
    else
    {
        for(ll i=a;i<a+k;i++)
            cout<<i<<endl;
        for(ll i=b-k+1;i<=b;i++)
            cout<<i<<endl;
    }
    return 0;
}




Measured memory_bytes: 256
n = gets.to_i
preo, ino = 2.times.map{gets.split(' ').map(&:to_i)}

Tree = Hash.new([])

build = -> (i, t) do
  j = t.index i
  if j.nil?
    preo.unshift i
    return nil
  end
  Tree[i] = []
  Tree[i][0] = build.(preo.shift, t[0...j])
  Tree[i][1] = build.(preo.shift, t[j+1...t.size])
  i
end

postorder = -> (a, i) do
  l = Tree[i][0]
  r = Tree[i][1]
  postorder.(a, l) if !l.nil?
  postorder.(a, r) if !r.nil?
  a << i
end

root = preo.first
build.(preo.shift, ino)
puts postorder.([], root).join(' ')


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

using namespace std;

class UF {
public:
    vector<int> p;
    UF(size_t n) : p(n) {
        for(size_t i=0; i<n; i++)
            p[i] = i;
    };
    int find(int x) {
        if(p[x] == x) return x;
        return p[x] = find(p[x]);
    };
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        p[x] = y;
    };
};

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

    map<long,vector<long>> xs, ys;
    for(int i=0; i<n; i++) {
        long x, y;
        cin >> x >> y;
        x--, y--;
        xs[y].push_back(x);
        ys[x].push_back(y);
    }

    UF uf(1e5);

    for(int y=0; y<1e5; y++) {
        for(auto &x: xs[y])
            uf.unite(xs[y][0], x);
    }

    map<long,vector<long>> fri;
    for(int i=0; i<1e5; i++)
        if(ys.count(i))
            fri[uf.find(i)].push_back(i);

    long r = 0;
    for(auto &t: fri) {
        auto &xs = t.second;

        long u = 0;
        set<long> s;
        for(auto &x: xs) {
            u += ys[x].size();
            s.insert(ys[x].begin(), ys[x].end());
        }
        r += s.size() * xs.size() - u;
    }

    cout << r << endl;
}


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

class Progaram
{
    static void Main(string[] args)
    {
        var x = long.Parse(Console.ReadLine());
        long ans;
        long y = x / 11 * 2;
        long f = x % 11;
        if (f == 0) ans = y;
        else if (f > 6) ans = y + 2;
        else ans = y + 1;
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for (int i = 0; i<(n); i++)
#define in(n) cin >> (n)
#define out(ans) cout << (ans) << endl;
using ll = int64_t;
using v = vector<int>;

int main() {
  int N, K;
  in(N);
  in(K);
  vector<double> kitai(N);
  rep(i, N) {
    double p;
    in(p);
    double sum = (p+1)/2;
    if (i==0) kitai.at(i) = sum;
    else kitai.at(i) = kitai.at(i-1) + sum;
  }
  
  double ans = 0;
  for (int i = 0; i+K-1<N; i++) {
    if (i==0) ans = kitai.at(i+K-1);
    else ans = max(ans, kitai.at(i+K-1)-kitai.at(i-1));
  }
  cout << fixed << setprecision(7);
  out(ans);
}

Measured memory_bytes: 1792
import random
import time
import copy
import math
start=time.time()
d=int(input())
c=list(map(int,input().split()))
s=[]
cli=[]
for i in range(d+1):
  ch=[]
  for j in c:
    ch.append(i*j)
  cli.append(ch)
for i in range(d):
  s.append(list(map(int,input().split())))
last=[0]*26
score=0
solution=[]
for day in range(1,d+1):
  co=[]
  dla=[]
  down=0
  for (i,j) in zip(last,c):
    down+=(day-i)*j
  for (i,j) in zip(last,c):
    dla.append(down-(j*(day-i)))
  for con in range(26):
    co.append(s[day-1][con]-dla[con])
  choice=co.index(max(co))
  score+=co[choice]
  last[choice]=day
  #print(choice+1)
  #print(score)
  solution.append(choice)
#print(score)
stemp=6000
etemp=1
def tem():
  return stemp-((stemp-etemp)*(time.time()-start)/1.9)
while time.time()-start<1.9:
  
  sc=0
  sol=copy.deepcopy(solution)
  for x in [random.randrange(d) for i in range(1)]:
    sol[x]=random.randrange(26)
  last=[0]*26
  for (day,i) in zip(range(1,d+1),sol):
    sc+=s[day-1][i]
    last[i]=day
    for (i,j) in zip(last,range(26)):
      sc-=cli[day-i][j]
  try:
    prob = math.exp((sc-score)/tem())
  except:
    prob=0
  #print("{} {}".format(sc,prob))
  if prob>random.random():
    solution=copy.deepcopy(sol)
    score=sc
    #print(score)
for i in solution:
  print(i+1)
#print(sco)


Measured memory_bytes: 10516
#include <stdio.h>
#define N 10000

int sosu(int);

int main(){
  int num[10000];
  int n,i,j,count=0;

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

  for(i=0; i<n; i++){
    count += sosu(num[i]);
  }
  printf("%d\n",count);
  return 0;
}


int sosu(int n){
  int i;
  if(n <= 1){
    return 0;
  }else if(n <= 3){
    return 1;
  }else{
    if(n%2 == 0)return 0;
    for(i=3; (i*i)<=n; i=i+2){
      if(n%i == 0){
	return 0;
      }
    }
    return 1;
  }
}



Measured memory_bytes: 2072
// AOJ ALDS1_9_A Complete Binary Tree
// 2018.5.1 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif

int in()
{
	int n = 0, c = gc();
	if (c == '-') { c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

#define QSIZE     300
#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

int que[QSIZE+5];

int main()
{
	int H, i, t;

	H = in();
	for (i = 1; i <= H; i++) que[i] = in();
	for (i = 1; i <= H; i++) {
		printf("node %d: key = %d, ", i, que[i]);

		t = PARENT(i);
		if (t > 0 && t <= H) printf("parent key = %d, ", que[t]);

		t = LEFT(i);
		if (t > 0 && t <= H) printf("left key = %d, ", que[t]);

		t = RIGHT(i);
		if (t > 0 && t <= H) printf("right key = %d, ", que[t]);

		putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 2056
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

/**
 * Created by darshan on 5/30/19.
 */
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;

        st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int k = Integer.parseInt(st.nextToken());
        int q = Integer.parseInt(st.nextToken());
        int[] num = new int[n];
        st = new StringTokenizer(br.readLine());
        for (int i = 0; i < n; i++) {
            num[i] = Integer.parseInt(st.nextToken());
        }

        int minDiff = Integer.MAX_VALUE;
        PriorityQueue<Integer> currentSubsequence = new PriorityQueue<>();
        PriorityQueue<Integer> leastQElements = new PriorityQueue<>((o1, o2) -> o2 - o1);
        for (int i = 0; i < n; i++) {
            int low = num[i];
            currentSubsequence.clear();
            leastQElements.clear();
            for (int j = 0; j <= n; j++) {
                if (j == n || num[j] < low) {
                    while (currentSubsequence.size() - k + 1 > 0) {
                        leastQElements.add(currentSubsequence.poll());
                    }
                    currentSubsequence.clear();
                } else {
                    currentSubsequence.add(num[j]);
                }
            }
            while (leastQElements.size() > q) {
                leastQElements.poll();
            }
            if (leastQElements.size() == q) {
                minDiff = Math.min(minDiff, leastQElements.poll() - low);
            }
        }
        System.out.println(minDiff);
    }
}


Measured memory_bytes: 55036
from collections import Counter
import sys
sys.setrecursionlimit(10**6)

MOD = 998244353

ABC = "abc".index
*S, = map(ABC, input())
N = len(S)

def bruteforce(S):
    used = set()
    def dfs(s):
        key = tuple(s)
        if key in used:
            return
        used.add(key)
        for i in range(len(s)-1):
            if s[i] != s[i+1]:
                a = s[i]; b = s[i+1]
                s[i] = s[i+1] = 3 - a - b
                dfs(s)
                s[i] = a; s[i+1] = b
    dfs(S)
    return len(used)

if len(S) <= 3:
    print(bruteforce(S))
else:
    c = Counter(S)
    if c[0] == N or c[1] == N or c[2] == N:
        print(1)
    else:
        P = [[[0,0] for i in range(3)] for j in range(3)]
        Q = [[[0,0] for i in range(3)] for j in range(3)]
        P[0][0][0] = P[1][1][0] = P[2][2][0] = 1
        for i in range(N-1):
            for p in range(3):
                for q in range(3):
                    for r in range(2):
                        Q[p][q][r] = 0
            for p in range(3):
                for q in range(3):
                    for r in range(2):
                        for k in range(3):
                            Q[k][(q+k)%3][r | (p == k)] += P[p][q][r] % MOD
            P, Q = Q, P
        ans = 0
        r = sum(S) % 3
        for i in range(3):
            ans += P[i][r][1]
        if all(S[i] != S[i+1] for i in range(N-1)):
            ans += 1
        print(ans % MOD)

Measured memory_bytes: 61024
/*Author: Satyajeet Singh, Delhi Technological University*/
import java.io.*;
import java.util.*;
import java.text.*; 
import java.lang.*;

public class Main {
/*********************************************Constants******************************************/
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));        
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

/****************************************Solutions Begins*****************************************/
    public static void main (String[] args) throws Exception {
        String st[]=br.readLine().split(" ");
        long A=Long.parseLong(st[0]);
        long B=Long.parseLong(st[1]);
        long q=Long.parseLong(st[2]);
        TreeSet<Long> tem=new TreeSet<>();
        TreeSet<Long> shr=new TreeSet<>();
        for(long i=0;i<A;i++){
            st=br.readLine().split(" ");
            long a=Long.parseLong(st[0]);
            shr.add(a);
        }
        for(long i=0;i<B;i++){
            st=br.readLine().split(" ");
            long a=Long.parseLong(st[0]);
            tem.add(a);
        }
       // System.out.println("ans)");
        while(q-->0){
            ArrayList<Long> list=new ArrayList<>();
            st=br.readLine().split(" ");
            Long x=Long.parseLong(st[0]);
            Long vv=shr.higher(x-1);
            Long oo=tem.higher(x-1);
            Long xx=0l;
            if(vv!=null&&oo!=null){
                xx=Math.max(oo,vv)-x;
                if(xx!=null){
                    list.add(xx);
                }        
            } 
             
            vv=tem.floor(x);
            oo=shr.floor(x);
            if(vv!=null&&oo!=null){
                xx=x-Math.min(oo,vv);
                if(xx!=null){
                    list.add(xx);
                }
            }
            
            Long tr=0l;
            Long yy=shr.floor(x);
            if(yy!=null){
                tr=x-yy;
                Long aa=tem.higher(yy-1);
                if(aa!=null){
                    list.add(tr+aa-yy);
                }
            }
            
            yy=tem.floor(x);
            tr=0l;
            if(yy!=null){
                tr=x-yy;
                Long aa=shr.higher(yy-1);
                if(aa!=null){
                    list.add(tr+aa-yy);
                }
            } 


            tr=0l;
            yy=shr.higher(x-1);
            if(yy!=null){
                tr=yy-x;
                Long aa=tem.lower(yy);
                if(aa!=null){
                    list.add(tr-aa+yy);
                }
            }
            tr=0l;
            yy=tem.higher(x-1);
            if(yy!=null){
                tr=yy-x;
                Long aa=shr.lower(yy);
                if(aa!=null){
                    list.add(tr-aa+yy);
                }
            }

            
            Collections.sort(list);
            out.println(list.get(0));          
        }
 
/****************************************Solutions Ends**************************************************/
        out.flush();
        out.close();
    }
}

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

/* #pragma */
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int GCD(int a,int b){return b?GCD(b,a%b):a;}
long long GCD(long long a, long long b){return b ? GCD(b, a%b) : a;}
int LCM(int a, int b){return a * b / GCD(a, b);}
long long LCM(long long a, long long b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right

//#define int long long

//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

/*global*/



signed main()
{
	int n,d; cin >> n>>d;
	vector<vector<int>> x(n, vector<int>(d));
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < d; ++j){
			cin >> x[i][j];
		}
	}
int cnt{};
	for(int i = 0; i < n-1; ++i){//gyou
		for(int k = 1; k < n-i; ++k){//zenntann
			double sq{};
			for(int j = 0; j < d; ++j){//retu & count
				sq += pow(abs(x[i][j] - x[i+k][j]),2);
				//int a = (int)sqrt((double)sq);
				//if(a*a == sq)cnt++;
			}
			if(floor(sqrt(sq)) == ceil(sqrt(sq))) cnt++;
		}
	}
	cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return scanner
}

var sc = newScanner()

func scanInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

func scanString() string {
	if sc.Scan() {
		return sc.Text()
	}
	panic(sc.Err())
}

func main() {
	a, v := scanInt(), scanInt()
	b, w := scanInt(), scanInt()
	t := scanInt()
	answer := isReachable(a, v, b, w, t)
	fmt.Println(answer)
}

const NO = "NO"
const YES = "YES"

func isReachable(a, v, b, w, t int) string {
	if v <= w {
		return NO
	}
	posDiff := abs(a - b)
	mvDiff := v - w
	if posDiff%mvDiff == 0 && posDiff/mvDiff <= t {
		return YES
	} else if posDiff/mvDiff+1 <= t {
		return YES
	}
	return NO
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func debug(a ...interface{}) {
	fmt.Println(a...)
}


Measured memory_bytes: 1756
//  ROAD TO GREEN
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>

using namespace std;
typedef long long ll;
const ll MAXN = 1e5;
vector<bool> used(MAXN,false);

int cnt[1000];

int main(){
    string s; cin >> s;
    string ss; cin >> ss;
    int cnt = 0;
    for(int i = 0; i < 3; i++){
        if(s[i] == ss[i])
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
using namespace std;
vector<pair<int, int>> prefix, postfix;

pair<int,int> cntBrace(string& str){
    int l = 0,r = 0;
    for(auto s : str){
        if(s == '(')  r++;
        else          r--;
        l = min(l,r);
    }
    return {l,r};
}

void setVector(int l, int r){
    if(r < 0)
        postfix.emplace_back(-r+l,-r);
    else
        prefix.emplace_back(l,r);
}

string getAns(){
    int i=0,j=0;
    for(auto o : prefix){
        if(o.first + i < 0)
            return "No";
        i += o.second;
    }
    for(auto c : postfix){
        if(c.first + j < 0)
            return "No";
        j += c.second;
    }
    if(i != j)  return "No";
    return "Yes";
}

int main(){
    int n;
    cin >> n;
    while(n--){
        string str;
        cin >> str;
        int l = 0,r = 0;
        tie(l,r) = cntBrace(str); 
        setVector(l,r);
    }
    auto cmp = [](pair<int,int> l, pair<int,int> r) -> bool {
        if(l.first == r.first) return l.second > r.second;  
        return l.first > r.first;
    };
    sort(prefix.begin(), prefix.end(), cmp);
    sort(postfix.begin(), postfix.end(), cmp);

    cout << getAns() << endl;
        
    return 0;
}

Measured memory_bytes: 11100
package main

import (
  "fmt"
)
func maxInt(a ...int) int {m := a[0]; for _, x := range a {if x > m {m = x}}; return m}
func minInt(a ...int) int {m := a[0]; for _, x := range a {if x < m {m = x}}; return m}

func main() {
  res := 0
  m := 0
  for i := 0; i < 5; i++ {
    var a int
    fmt.Scan(&a)
    b := (a + 9) / 10 * 10
    res += b
    m = maxInt(m, b - a)
  }
  res -= m
  fmt.Println(res)
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int N=310;
int n,f[N][N];char s[N][N];
int main(){
  cin>>n;
  for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
  for(int i=1;i<=n;i++)
	  for(int j=1;j<=n;j++){
		  for(int k=0;k<=n;k++){
			  int ti=(i+k)%n,tj=(j+k)%n;
			  if(ti==0)ti=n;if(tj==0)tj=n;
			  if(s[ti][j]==s[i][tj])f[i][j]++;
			  else break;
		  }
	  }
  int ans=0;
  for(int i=0;i<n;i++)
	  for(int j=0;j<n;j++){
		  bool flag=1;
		  for(int k=1;k<=n;k++){
			  int ti=(k+i)%n,tj=(k+j)%n;
			  if(ti==0)ti=n;if(tj==0)tj=n;
			  if(f[ti][tj]<n-k+1){flag=0;break;}
		  }
		  ans+=flag;
	  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
// types
typedef long long ll; 
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
// IO
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define sc(n) scanf("%d", &n) 
#define sca(a, n) fo(i, n) sc(a[i])
#define pd(a) printf("%d ", a)
#define pld(a) printf("%d\n", a)
#define pda(a, n) fo(i, n) pd(a[i])
#define pl printf("\n")
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b) 
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
// math
const int mod = 1e9+7;
template<typename T> T gcf(T a, T b) {return (b == 0) ? a : gcf(b, a%b);} 
template<typename T> T lcm(T a, T b) {return (a*b)/gcf(a, b);}
template<typename T> T sumTo(T x) {return x * (x+1) / 2;}
template<typename T> T sumSquaresTo(T x) {return x * (x+1) * (2*x+1) / 6;}
template<typename T> T ceilDiv(T n, T d) {return (n+d-1)/d;}

vector<bool> binaryBackwards(ll n) {
    // returns binary representation of the vector backwards
    vector<bool> ans;
    while (n > 0) {
        ans.push_back(n%2);
        n /= 2;
    }
    return ans;
}

ll emod(ll base, ll exponent) {
    vector<bool> bb = binaryBackwards(exponent);
    ll ans = 1;
    ll bp = base % mod;
    for (int i = 0; i < bb.size(); i++) {
        if (bb[i]) {
            ans *= bp;
            ans %= mod;
        }
        bp = (bp * bp) % mod;
    }
    return ans;
}

ll comb(ll n, ll r) {
    ll ans = 1;
    for(ll x = n; x > n-r; x--) ans = (ans*x) % mod;
    ll rf = 1;
    for (ll i = 2; i <= r; i++) rf = (rf*i) % mod;
    return (ans * emod(rf, mod-2)) % mod;
}

void solve() {
    ll n, a, b; cin >> n >> a >> b;
    // formula = 2^n - 1 - nCa - nCb
    ll x = emod(2, n)-1;
    ll nCa = comb(n, a);
    ll nCb = comb(n, b);
    ll ans = (x-nCa-nCb) % mod;
    if (ans < 0) ans += mod;
    cout << ans;
} 

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



int main()
{
  string S; cin>>S;
  ll N=S.size();
  
  ll p=0; rep(i,N) if(S.at(i)=='p') p++;
  
  cout<<N/2-p<<endl;
  return 0;
}

Measured memory_bytes: 3724