akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1000000007
#define double long double
using namespace std;
typedef pair<ll, ll>P;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
ll a[4444];
ll cnt[2222];
ll memo[2222];
signed main() {
	ll n, k, ans = 0;
	cin >> n >> k;
	rep(i, n)cin >> a[i];
	rep(i, n) {
		for (int j = i + 1; j < n; j++) {
			if (a[i] > a[j])memo[a[i]]++;
		}
	}
	rep(i, n) {
		rep(j, n) {
			if (a[i] > a[j])cnt[a[i]]++;
		}
	}
	rep(i, 2001) {
		ans += ((memo[i] * k) % inf + (cnt[i] * (((k - 1)* k / 2) % inf)) %inf);
	}
	cout << ans % inf << endl;
	ggr
}


Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func binarySearch(a []int, key int) int {
	for l, r := 0, len(a); l < r; {
		mid := (l + r) / 2
		if a[mid] == key {
			return mid
		}
		if key < a[mid] {
			r = mid
		} else if a[mid] < key {
			l = mid + 1
		}
	}
	return -1
}

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

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n := nextInt()
	a, b := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
		b[i] = a[i]
	}

	sort.Sort(sort.IntSlice(b))

	ans := 0
	for i := 0; i < n; i++ {
		idx := binarySearch(b, a[i])
		ans += abs(i-idx) % 2
	}

	puts(ans / 2)
}


Measured memory_bytes: 4932
#include<bits/stdc++.h>
using namespace std;
const int MAX=5005;

int val[MAX];
vector<int> adj[MAX];
int st[MAX];

void dfs(int s,int p)
{
     for(int i=0;i<adj[s].size();i++)
     {
	int u=adj[s][i];
	if(u!=p)
	{
	   dfs(u,s);
	   if(st[u]==0&&val[s]>val[u])
	   {
		st[s]=1;
	   }
	}
     }
}

int main()
{
   int n;
   scanf("%d",&n);
   for(int i=1;i<=n;i++)
   {
	scanf("%d",&val[i]);
   } 
   for(int i=1;i<n;i++)
   {
	int a,b;
	scanf("%d %d",&a,&b);
	adj[a].push_back(b);
	adj[b].push_back(a); 
   }
   for(int i=1;i<=n;i++)
   {
	for(int j=1;j<=n;j++)
	{
	   st[j]=0;
	}
	dfs(i,0);
	if(st[i])
	{
	   printf("%d ",i);
	}
   }
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;

const int M = 1000005;

int main(){
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

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

    vector<int> counter(M, 0);

    for (int x : A){
        if( counter[x] > 0){
            counter[x]++;
            continue;
        }
        
        for(int i = x; i < 1000005; i = i + x) counter[i]++;
    }

    int ans = 0;
    for (int x : A){
        if (counter[x] == 1) ans++;
    }    

    cout << ans << endl;
}

Measured memory_bytes: 7920
main :: IO ()
main = do
    x <- map read . words <$> getLine :: IO [Int]
    let a = if head x == 1 then 14 else head x
        b = if last x == 1 then 14 else last x
    putStrLn $ if a == b then "Draw" else if a > b then "Alice" else "Bob"


Measured memory_bytes: 3812
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef  long long  ll;
typedef long double db;
#define pb push_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)
#define lb(v,val) lower_bound(v.begin(),v.end(),val)
#define sortv(vec) sort(vec.begin(),vec.end())
#define rev(p) reverse(p.begin(),p.end());
#define v vector
#define pi 3.1415926535
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define np(str) next_permutation(str.begin(),str.end())
#define fi first
#define se second
#define mset(a,val) memset(a,val,sizeof(a));
#define mt make_tuple
#define in insert
#define repr(i,n) for( i=n-1;i>=0;i--)
#define rep(i,n) for(  i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll M = 1e9 + 7;
ll inf = 1e18;
ll n, m, k;

int main() {
	// your code goes here
	IOS;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll  i, j, t,  x, y, z,  N;
	db in;
	cin >> in;
	if (in == 0)
		cout << 1;
	else if (in == 1)
		cout << 0;

	return 0;
}

























Measured memory_bytes: 3740
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
 
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String B = sc.nextLine();
    int max = 0;
    int count = 0;
    for(int i=0; i<B.length(); i++) {
      if(B.charAt(i) == 'A' || B.charAt(i) == 'C' || B.charAt(i) == 'G' || B.charAt(i) == 'T') {
        count++;
      } else {
        
        max = Math.max(max, count);
        count = 0;
      }
    }
    max = Math.max(max, count);
    System.out.println(max);
  }
}


Measured memory_bytes: 26988
#include <bits/stdc++.h>
#define M 1000000007 
#define mod 1000000007
typedef long long ll;
using namespace std;

void solve() 
{ 
    ll n;
    cin>>n;
    vector<ll> A(n);
    for(ll i=0; i<n; ++i) cin>>A[i];
    vector<ll> newarr(n);
	ll sum = 0, temp; 

    ll res = 0;
    newarr[0] = A[n-1]%M;
    // sort(A.begin(),A.end());
    for (ll i = 1; i < n; i++) { 
        newarr[i] = (newarr[i-1] + A[n-i-1])%M;
        newarr[i] %= M;
    }

    for (ll i = 0; i < n-1; i++) { 
        sum += (A[i] * newarr[n-i-2])%M;
        sum %= M;
    } 

	cout<<sum%M;
} 



int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int q;
    q=1;
    // cin>>q;
    while(q--) solve();


    return 0;
}


Measured memory_bytes: 6380
#include<stdio.h>
int main(void) {
    int i=1, j, m=1, s, a[10000]={ };
    scanf("%d", &s);
    a[0]=s;
    while(1) {
        if(a[i-1]%2==0)
            a[i]=a[i-1]/2;
        else
            a[i]=3*a[i-1]+1;
        for(j=0; j<i; j++) {
            if(a[j]==a[i]) {
                m+=i;
                break;
            }
        }
        if(m!=1)
            break;
        i++;
    }
    printf("%d\n", m);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

const int mod = 1000 * 1000 * 1000 + 7;

vector<vector<vector<int>>> dp;
int solve(const vector<int> &v, int current, bool is_top, int sum, int d) {
  sum = (sum + d) % d;

  if (current == -1) {
    return sum == 0;
  }

  int& ret = dp[current][is_top][sum];
  if (ret == -1) {
    ret = 0;
    int limit = is_top ? v[current] : 9;

    for (int digit = 0; digit <= limit; ++digit) {
      ret += solve(v, current - 1, is_top && digit == limit, sum + digit, d);
      ret %= mod;
    }
  }

  return ret;
}

int main() { IO;
  string k;
  int d;
  cin >> k >> d;

  vector<int> v(k.size());
  transform(k.begin(), k.end(), v.begin(), [](char c) { return c - '0'; });
  reverse(v.begin(), v.end());

  dp.resize(v.size());
  for (auto &g : dp) {
    g.resize(2);
    for (auto &v : g) {
      v.resize(d + 1);
      fill(v.begin(), v.end(), -1);
    }
  }

  int ans = solve(v, v.size() - 1, true, 0, d);
  ans = (ans - 1 + mod) % mod;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 10112
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <limits.h>
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;
signed main(){
    string s;
    cin>>s;
    if(s=="Sunny")cout<<"Cloudy"<<endl;
    if(s=="Cloudy")cout<<"Rainy"<<endl;
    if(s=="Rainy")cout<<"Sunny"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<queue>
#include<cmath>
using namespace std;
#define MAXN 1005
#define Max(a,b) a>b?a:b
#define INF 2828427224
double x[MAXN],y[MAXN],r[MAXN];
long double Dis(int i,int j)
{
	return sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
}
long double a[MAXN][MAXN];
bool vis[MAXN];
long double dis[MAXN];
queue<int>Q;
int main()
{
	scanf("%lf%lf%lf%lf",&x[0],&y[0],&x[1],&y[1]);
	int n;
	scanf("%d",&n);
	n++;
	for(int i=2;i<=n;i++)
		scanf("%lf%lf%lf",&x[i],&y[i],&r[i]);
	for(int i=0;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			a[i][j]=a[j][i]=Max(0.0,Dis(i,j)-r[i]-r[j]);
	for(int i=1;i<=n;i++)
		dis[i]=INF;
	Q.push(0);
	vis[0]=1;
	while(!Q.empty())
	{
		int u=Q.front();Q.pop();
		vis[u]=0;
		for(int v=1;v<=n;v++)
			if(dis[v]>dis[u]+a[u][v])
			{
				dis[v]=dis[u]+a[u][v];
				if(!vis[v])
				{
					Q.push(v);
					vis[v]=1;
				}
			}
	}
	printf("%.10Lf\n",dis[1]);
}

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


void dfs(int s,vector<int> g[],vector<int>&dp){
    int currAns = 0;
    for(int v : g[s]){
        if(dp[v] == -1){
            dfs(v,g,dp);
        }
        currAns = max(currAns,1 + dp[v]);
    }
    dp[s] = currAns;
    return;
}

int main(void){
    int v,e;
    cin >> v >> e;
    vector<int>g[v];
    for(int i = 0; i < e; i++){
        int a,b;
        cin >> a >> b;
        a--,b--;
        g[a].push_back(b);
    }
    vector<int> dp(v,-1);
    int ans = 0;
    for(int i = 0; i < v; i++){
        if(dp[i] == -1){
            dfs(i,g,dp);
        }   
        ans = max(ans,dp[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 9472
#include <iostream>
#include <fstream>
#include <sstream>

#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <deque>
#include <string>

#include <algorithm>
#include <numeric>

#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>

#define pb push_back
#define pbk pop_back
#define mp make_pair
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define foreach(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define len(a) ((int) (a).size())

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

using namespace std;

typedef long long int64;
typedef long double ld;
typedef unsigned long long lint;

const int N = 1e6 + 100;

const int inf = (1 << 30) - 1;
const int64 linf = (1ll << 62) - 1;

int n, m, k;
map<int, vector<pair<int, int>>> c;

int64 delta[N];

bool used[N];

vector<int> comp;
vector<pair<int, int>> g[N];

void dfs(int v, int64 cur = 0) {
    if (used[v]) {
        return ;
    }
    comp.pb(v);
    used[v] = true;
    delta[v] = cur;
    for (auto to : g[v]) {
        dfs(to.fs, cur + to.sc);
    }
}

map<int, vector<pair<int, int>>> cy;

int main() {
#ifdef XCODE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin >> n >> m >> k;
    for (int i = 0; i < k; i++) {
        int x, y, z; scanf("%d%d%d", &x, &y, &z);
        x--, y--;
        c[x].pb(mp(y, z));
        cy[y].pb(mp(x, z));
    }
    for (auto &i : c) {
        sort(all(i.sc));
        for (int j = 0; j < len(i.sc) - 1; j++) {
            g[i.sc[j].fs].pb(mp(i.sc[j + 1].fs, i.sc[j + 1].sc - i.sc[j].sc));
            g[i.sc[j + 1].fs].pb(mp(i.sc[j].fs, i.sc[j].sc - i.sc[j + 1].sc));
        }
    }
    for (int i = 0; i < m; i++) {
        comp.clear();
        dfs(i, 0);
        for (int v : comp) {
            for (auto to : g[v]) {
                if (delta[to.fs] != delta[v] + to.sc) {
                    puts("No");
                    return 0;
                }
            }
        }
        static int64 value[N];
        for (int v : comp) {
            for (auto j : cy[v]) {
                value[j.fs] = j.sc - delta[v];
            }
        }
        int64 minDelta = linf;
        for (int v : comp) {
            minDelta = min(minDelta, delta[v]);
        }
        for (int v : comp) {
            for (auto j : cy[v]) {
                if (value[j.fs] + minDelta < 0) {
                    puts("No");
                    return 0;
                }
            }
        }
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 47232
#include<stdio.h>
int main()
{
  int a,b,c,n,i,max,ans=0;
  scanf("%d %d %d",&a,&b,&c);
  scanf("%d",&n);
  if(a>b)max=a;
  else max=b;
  if(max<c)max=c;
  ans=a+b+c-max;
  for(i=0;i<n;i++)
  {
    max*=2;
  }
  printf("%d",ans+max);
}

Measured memory_bytes: 128
//#define LOCAL

#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <cstring>

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

#define MOD 1000000007

using namespace std;

int n;
int a[100010];

signed main()
{
#ifdef LOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    cin >> n;
    rep(i, n) cin >> a[i];

    //負正負正にするコスト
    int cost = 0;
    int sum = 0;
    rep(i, n) {
        sum += a[i];
        if (i % 2 == 0) {
            if (sum >= 0) {
                cost += sum + 1;
                sum = -1;
            }
        } else {
            if (sum <= 0) {
                cost += 1 - sum;
                sum = 1;
            }
        }
    }

    //正負正負にするコスト
    int cost2 = 0;
    int sum2 = 0;
    rep(i, n) {
        sum2 += a[i];
        if (i % 2 == 0) {
            if (sum2 <= 0) {
                cost2 += 1 - sum2;
                sum2 = 1;
            }
        } else {
            if (sum2 >= 0) {
                cost2 += sum2 + 1;
                sum2 = -1;
            }
        }
    }

    cout << min(cost, cost2) << endl;
}


Measured memory_bytes: 1024
# encoding:utf-8
import copy
import numpy as np
import random
n = int(input())

A = [int(i) for i in input().split()]


count_dic = {}
for a in A:
    if a in count_dic:
        count_dic[a] += 1
    else:
        count_dic[a] = 1

ans = 0

for key in count_dic.keys():
    if count_dic[key] == key:
        pass
    elif count_dic[key]<key:
        ans += count_dic[key]
    else:
        ans += count_dic[key]-key
        count_dic[key] = key


print(ans)


Measured memory_bytes: 27844
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstdint>
#include<unordered_map>
#include<sstream>
#include<boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

typedef pair<int, int> P;

bool ps1(const P& element1, const P& element2)
{//first昇順
	return element1.first < element2.first;
}
bool ps2(const P& element1, const P& element2)
{//first降順
	return element1.first > element2.first;
}
bool ps3(const P& element1, const P& element2)
{//second昇順
	return element1.second < element2.second;
}
bool ps4(const P& element1, const P& element2)
{//second降順
	return element1.second > element2.second;
}


int main()
{
	string s;
	cin >> s;
	vector<ll>num(s.size());
	ll count = 0;
	int no = 0;
	string prev="AD";
	for (int i = s.size() - 2; i > 0; i--) {
		string t = s.substr(i, 2);
		if (t=="BC") {
			count++;
		}
		else if(t=="AA") {
			if (prev == "AA" or prev == "AB") {

			}
			else {
				no++;
			}
		}
		else if(t=="AB"){
			if (prev == "BC") {

			}
			else {
				no++;
			}
		}
		else if (t == "CB") {
			if (prev == "BC"&& s[i-1]=='B') {

			}
			else {
				no++;
			}
		}
		else if (t == "CA") {
			if ((prev == "AB" or prev=="AA")&&s[i-1]=='B') {

			}
			else {
				no++;
			}
		}
		else {
			no++;
		}
		if (no>= 1) {
			count = 0;
			no = 0;
		}
		prev = t;
		num[i-1] = count;
	}
	ll ans = 0;
	rep(i, s.size()-1) {
		if (s[i] == 'A') {
			ans += num[i];
		}
	}
	cout << ans << endl;

}



Measured memory_bytes: 2180
#include<bits/stdc++.h>
using namespace std;
int main(){
  int c[3][3];
  int i, j, k;
  for(i=0; i<3; i++){
    cin >> c[i][0] >> c[i][1] >> c[i][2];
  }
  int a[3];
  int b[3];
  int ab12, ab13, ab23, ab21, ab32, ab31;
  for(i=0; i<=100; i++){
    a[0] = i;
    b[0] = c[0][0] - a[0];
    for(j=0; j<=100; j++){
      a[1] = j;
      b[1] = c[1][1] - a[1];
      for(k=0; k<=100;k++){
        a[2] = k;
        b[2] = c[2][2] - a[2];
        ab12 = a[0] + b[1];
        ab21 = a[1] + b[0];
        ab13 = a[0] + b[2];
        ab31 = a[2] + b[0];
        ab23 = a[1] + b[2];
        ab32 = a[2] + b[1];
        if(ab12 == c[0][1] && ab21 == c[1][0] &&
           ab13 == c[0][2] && ab31 == c[2][0] &&
           ab23 == c[1][2] && ab32 == c[2][1]){
             cout <<"Yes" << endl;
             return 0;
           }
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
  string s;
  cin >> s;
  int n = (s.size()+1)/2;
  vector<char> ans(n);
  int j = 0;
  for(int i = 0; i < s.size(); i+=2){
    ans.at(j) = s.at(i);
    j++;
  }
  for(int i = 0; i < n; i++){
    cout << ans.at(i);
  }
  return 0;
}

Measured memory_bytes: 3780
import io.{StdIn => in}

object Main extends App {
  val n = in.readInt.toString.toCharArray
  val ans = n match {
    case s if s(0) == s(1) && s(1) == s(2) => "Yes"
    case s if s(1) == s(2) && s(2) == s(3) => "Yes"
    case _ => "No"
  }
  println(ans)
}

Measured memory_bytes: 27304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long int lli;
typedef long double ld;
const int oo = 1e9;
const int mod = 1e9+9;
//===========================================================//
const int nax = 1e5+103;
int n, k;
int dp[nax];
int a[nax];
int f(int i){
	if (i==n-1) return 0;
	if(dp[i]!=-1) return dp[i];
	int ans = abs(a[i]-a[i+1])+f(i+1);
	for(int j=2; j<=k; j++){
		if(i+j<n) ans = min(ans, abs(a[i]-a[i+j])+f(i+j));
	}
	return dp[i]=ans;
}
int main(){
	cin>>n>>k;
	for(int i=0; i<n; i++) cin>>a[i];
	memset(dp, -1, sizeof dp);
	cout<<f(0)<<endl;
	return 0;
}

Measured memory_bytes: 5760
N = int(input())
As = [int(input())-1 for _ in range(N)]

#一度押したら-1にする
nowon = 0
cnt = 0
while 1:
  nexton = As[nowon]
  As[nowon] = -1
  cnt += 1
  if nexton == 1:
    print(cnt)
    exit()
  if nexton == -1:
    print(-1)
    exit()
  nowon = nexton

Measured memory_bytes: 49368
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    int R;
    cin >> R;
    if (R < 1200) {
        cout << "ABC" << endl;
    } else if (R < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }
    return 0;
}


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

int main(void)
{
    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 = 0;
    for(int i = 0; i < N; i++){
        for(int j = i+1; j < N; j++){
            double dist = 0;
            for(int k = 0; k < D; k++){
                dist += (X[i][k] - X[j][k])*(X[i][k] - X[j][k]);
            }
            dist = sqrt(dist);
            if(dist == (double)(int)dist){
                cnt++;
            }
        }
    }

    cout << cnt << endl;


    return 0;
}

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

long long power(long long a, long long n, long long m) {
    a %= m;
    long long r = 1;
    while (n > 0) {
        if (n & 1) r = (r * a) % m;
        a = (a * a) % m;
        n >>= 1;
    }
    return r;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long n, a, b;
    cin >> n >> a >> b;
    const long long m = int(1e9) + 7;
    long long ans = power(2, n, m);
    long long f[2 * int(1e5) + 1];
    f[0] = 1;
    f[1] = 1;
    long long max_x = max(a, b);
    for (int i = 2; i <= max_x; ++i) f[i] = (i * f[i - 1]) % m;
    long long d_a = 1;
    for (int i = 0; i < a; ++i) {
        d_a = ((n - i) * d_a) % m;
    }
    long long d_b = 1;
    for (int i = 0; i < b; ++i) {
        d_b = ((n - i) * d_b) % m;
    }
    a = (d_a * power(f[a] % m, m - 2, m)) % m;
    b = (d_b * power(f[b] % m, m - 2, m)) % m;
    ans -= a;
    if (ans < 0) ans += m;
    ans -= b;
    if (ans < 0) ans += m;
    ans = (ans == 0) ? m - 1 : ans - 1;
    cout << ans << '\n';
    return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline void fastio () {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
}

#define whats(x) cerr << #x << " = " << (x) << "\n"; 

using LL = long long;
using LD = long double;

const LL INF = LLONG_MAX;
const LL MOD = 998244353;
const LL N = 2e5+1;

int main() {
	fastio();

	LL n, k;
	cin >> n >> k;

	LL sum = 0;

	vector<LL> a(n);
	for (LL i = 0; i < n; ++i) {
		cin >> a[i];

	}

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

	for (LL i = 0; i < k; ++i) {
		sum += a[i];
	}

	cout << sum << "\n";
}

Measured memory_bytes: 3664
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func init() {
	sc.Split(bufio.ScanWords)
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	n := scanInt()
	type point struct{ x, y int }
	ps := make([]point, n)
	for i := range ps {
		ps[i].x, ps[i].y = scanInt(), scanInt()
	}

	mx := 0
	type no struct{ p, q int }
	xm := make(map[no]int)
	for _, v1 := range ps {
		for _, v2 := range ps {
			if v1 == v2 {
				continue
			}
			t := no{v1.x - v2.x, v1.y - v2.y}
			xm[t]++
			mx = max(mx, xm[t])
		}
	}
	fmt.Println(n - mx)
}


Measured memory_bytes: 2040
fun solve(R: Int) {
    println(R * 2 * Math.PI)
}

fun main() {
//    val S = readLine()!!
    val R = readLine()!!.toInt()
//    val (N, M) = readLine()!!.split(" ").map { it.toInt() }
//    val A = readLine()!!.split(" ").map { it.toInt() }
    solve(R)
}

Measured memory_bytes: 34640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

class Main {
    static Map<String, Integer> A = new HashMap<String, Integer>();

    static void insert(String s){
        A.put(s,1);
    }

    static String find(String s){
        if (A.containsKey(s)) return "yes";
        return "no";
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(
                new InputStreamReader(System.in));

        int n = Integer.parseInt(br.readLine());

        for (int i = 0; i < n; i++) {
            StringTokenizer st = new StringTokenizer(br.readLine());
            String operation = st.nextToken();

            if(operation.equals("insert")) insert(st.nextToken());
            else System.out.println(find(st.nextToken()));
        }
    }
}



Measured memory_bytes: 130076
s = input()
p = input()


bl = False
for i in range(len(s)):
    #bl = True
    for j in range(len(p)):
        if s[(i+j)%len(s)] !=p[j]:
            break
    if(j==len(p)-1 and s[(i+j)%len(s)] ==p[j]):
        bl = True
        break
if bl:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 5560
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <iostream>

#define pb push_back
#define mp make_pair

using namespace std;

char s[15][25];
int calc[15][15];
bool flag[15];
int list[15],cnt;
int n,N;
int len[15];
int dp[1<<15][15];

int gao(int x,int y){
    int lenx = strlen(s[x]) , leny = strlen(s[y]);
    int ret=0;
    for (int i=1; lenx-i>=0 && i-1 < leny ; i++){
        bool flag=true;
        for (int j=0;j<=i-1;j++)
            if (s[y][j]!=s[x][lenx-i+j]) flag=false;
        if (flag) ret=max(ret,i);
    }
    return ret;

}

bool inside(int x,int y){
    int lenx = strlen(s[x]) , leny = strlen(s[y]);
    if (lenx > leny) return false;
    bool flag=false;
    for (int i = 0 ; i <= leny - lenx ; i++){
        bool same=true;
        for (int j = 0 ; j < lenx ; j++)
            if (s[x][j]!=s[y][j+i]) same=false;
        if (same) flag=true;
    }
    return flag;
}

void prework(){
    // s[i]s[j]
    for (int i=0;i<n;i++)
        for (int j=0;j<n;j++)
            if (i!=j) calc[i][j] = gao(i,j);
}

int main(){

    //freopen("input.txt","r",stdin);

    while (~scanf("%d",&n) && n){
        for (int i=0;i<n;i++) scanf("%s",s[i]),flag[i]=true;

        for (int i=0;i<n;i++)
            for (int j=0;j<n;j++)
                if (i!=j && inside(i,j)) flag[i]=false;

        N=0;
        for (int i=0;i<n;i++)
            if (flag[i]) list[N++]=i;

        for (int i=0;i<n;i++) len[i]=strlen(s[i]);
        prework();

        for (int i=0;i<(1<<N);i++)
            for (int j=0;j<N;j++)
                dp[i][j]=0x3F3F3F3F ;

        for (int i=0;i<N;i++) dp[1<<i][i] = len[list[i]];
        for (int i=1;i<(1<<N);i++){
            for (int j=0;j<N;j++)
                if ((i>>j)&1)
                    for (int k=0;k<N;k++)
                        if (!((i>>k)&1))
                            dp[i|(1<<k)][k] = min(dp[i|(1<<k)][k] , dp[i][j] + len[list[k]] - calc[list[k]][list[j]]);
        }

        int ans=0x3F3F3F3F;
        for (int i=0;i<N;i++)
            ans = min(dp[(1<<N)-1][i],ans);
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 2164
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

int main(void){
	int n, i, j;
	long k;
	int a[2000];
	scanf("%d%d", &n, &k);
	for(i=0; i<n; i++){
		scanf("%d", a+i);
	}
	long A=0, b=0;
	for(i=0; i<n; i++){
		for(j=0; j<n; j++){
			if(i<j && a[i]>a[j]) A++;
			if(a[i]>a[j]) b++;
		}
		A%=P; b%=P;
	}
	long ans = (A*k%P) + (k*(k-1)/2%P*b%P);
	ans%=P;
	printf("%ld\n", ans);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	char c=getchar();int t=0,f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int n;
int main(){
	n=read();
	printf("%d\n",(n-2)*180);
	return 0;
}


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

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

char maze[50][50];
int  dist[50][50];

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

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  ll n , k,q;
  cin >> n >> k >>q;
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i,n){
    a[i]=k;
  }
  rep(i,n){
    b[i]=q;
  }
  rep(i,q){
    ll x; cin>>x;
    x--;
    b[x]--;
  }
  
  rep(i,n){
    a[i]-=b[i];
    
    
    if(a[i]>0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  
}
  



Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	int k, x; cin >> k >> x;
	if( k*500 >= x ) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	_, M := ReadInt(), ReadInt()
	minA := int(1e9)
	maxB := -1

	A := make(map[int][]int)
	B := make(map[int][]int)

	for i := 0; i < M; i++ {
		a, b := ReadInt(), ReadInt()
		minA = Min(minA, a)
		maxB = Max(maxB, b)
		A[a] = append(A[a], i)
		B[b] = append(B[b], i)
	}

	ans := 0
	foundPrerequisites := make(map[int]bool)
	for i := minA; i <= maxB; i++ {
		if len(foundPrerequisites) > 0 {
			for _, p := range B[i] {
				if foundPrerequisites[p] {
					ans++
					foundPrerequisites = make(map[int]bool)
				}
			}
		}

		for _, p := range A[i] {
			foundPrerequisites[p] = true
		}
	}

	fmt.Println(ans)
}

func Min(xs ...int) int {
	min := xs[0]
	for _, x := range xs[1:] {
		if min > x {
			min = x
		}
	}
	return min
}

func Max(xs ...int) int {
	max := xs[0]
	for _, x := range xs[1:] {
		if max < x {
			max = x
		}
	}
	return max
}

var sc = bufio.NewScanner(os.Stdin)

func init()        { sc.Buffer(make([]byte, 256), 1e9); sc.Split(bufio.ScanWords) }
func Read() string { sc.Scan(); return sc.Text() }

func ReadInt() int {
	v, e := strconv.Atoi(Read())
	if e != nil {
		panic(e.Error())
	}
	return v
}


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

//def
#define debug(x) cout << #x << ": " << x << '\n'
#define out(x) cout << x << '\n'
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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

    string n;
    bool ok = false;
    cin >> n;
    rep(i, 3) {
        if (n[i] == '7') ok = true;
    }
    if (ok)
        CYES;
    else
        CNO;
    return 0;
}


Measured memory_bytes: 3652
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.numeric;


void main()
{
  auto n = readln.chomp.to!int;
  //auto s = new string[](n);
  int ab, a, b;
  int res;
  
  foreach (i; 0..n) {
    immutable s = readln.chomp;
    res += s.count("AB");

    if (s[0] == 'B' && s[$-1] == 'A') {
      ab++;
    } else if (s[0] == 'B') {
      b++;
    } else if (s[$-1] == 'A') {
      a++;
    }
  }

  if (ab > 0) {
    res += ab - 1;
    if (b > 0) {
      res++;
      b--;
    }
    if (a > 0) {
      res++;
      a--;
    }
  }
  res += min(a, b);
  
  res.writeln;
}


Measured memory_bytes: 380
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <array>
#include <list>
#include <stack>
#include <valarray>

using namespace std;

typedef unsigned uint;
typedef long long Int;
typedef unsigned long long UInt;

const int INF = 1001001001;
const Int INFLL = 1001001001001001001LL;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
Int lin() { Int x; scanf("%lld", &x); return x; }

int A[2048];
UInt dp[1<<20];

int main() {
  int N = in();
  int S = 0;
  for (int i = 0; i < N; ++i) {
    A[i] = in();
    S += A[i];
  }
  const int H = (S + 1) / 2;

  const int B = 64;
  int pre = 0;
  dp[0] = 1;
  for (int i = 0; i < N; ++i) {
    int to = max(0, H + pre - S) / B;
    for (int j = min(H, pre) / B; j >= to; --j) {
      dp[j + A[i]/B] |= dp[j] << (A[i] % B);
      if (A[i] % B != 0) {
        dp[j + A[i]/B + 1] |= dp[j] >> (64 - A[i] % B);
      }
    }
    pre += A[i];
  }

  for (int i = H; i <= S; ++i) {
    if (dp[i / B] & (1ULL << (i % B))) {
      printf("%d\n", i);
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,K; cin >> N >> K;
    vector<ll> A(N);
    rep(i,N) {
        cin >> A[i];
        A[i]--;
    }

    vector<ll> B(N+1);
    rep(i,N) B[i+1] = B[i] + A[i];
    rep(i,N) B[i+1] %= K;

    map<ll, ll> dic;
    ll ans = 0;

    for (int i = 0; i < N+1; i++) {
        if (K <= i) dic[B[i-K]]--;
        ans += dic[B[i]];
        dic[B[i]]++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 15872
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
sum = 0

A.append(0)

for i in range(N):
  sum += B[A[i]-1]
  if A[i+1] == A[i] + 1:
    sum += C[A[i]-1]

print(sum)

Measured memory_bytes: 3064
#include <stdio.h>

main(){
    int N;
    scanf("%d",&N);
    int i,j,c=0,d=0;
    for(j=1;j<=N;j+=2){
        c=0;
        for(i=1;i<=j;i++){
            if(j%i==0)
                c++;
        }
        if(c==8)
            d++;
    }

    printf("%d\n",d);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

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

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int h, w; cin >> h >> w;
	vector<string> in(h); rep(i, h) cin >> in[i];
	
	int cnt[2] = {};
	function<void(int,int)> rec = [&](int y, int x){
		cnt[x + y & 1]++;
		char c = in[y][x];
		in[y][x] = '!';
		rep(d, 4){
			int ny = y + dy[d], nx = x + dx[d];
			if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
			if(in[ny][nx] != '!' && in[ny][nx] != c) rec(ny, nx);
		}
	};
	ll ans = 0;
	rep(i, h) rep(j, w) if(in[i][j] != '!'){
		cnt[0] = cnt[1] = 0;
		rec(i, j);
		ans += (ll)cnt[0] * cnt[1];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 20480
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
	int n, x, y;
	cin >> n >> x >> y;
	vector<int> res(n + 1, 0);
	rep(i, 1, n + 1)
		rep(j, i + 1, n + 1)
		{
			int z = min(abs(j - i), abs(x - i) + 1 + abs(j - y));
			res[z]++;
		}
	rep(i, 1, n)
		cout << res[i] << endl;
	return 0;
}

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

using namespace std;


int N, M, L;
vector<int> A, B, C;
int Q;
vector<int>s, t;

constexpr auto INF = 1000000001;

int main()
{

	cin >> N;
	cin >> M;
	cin >> L;

	A = vector<int>(M);
	B = vector<int>(M);
	C = vector<int>(M);

	auto cost_tbl = vector<vector<int>>(N + 1, vector<int>(N+1,INF));

	for (int i = 1; i < N + 1; i++) {
		cost_tbl[i][i] = 0;
	}

	for (int i = 0; i < M; i++) {
		cin >> A[i];
		cin >> B[i];
		cin >> C[i];

		cost_tbl[A[i]][B[i]]= C[i];
		cost_tbl[B[i]][A[i]] = C[i];

	}

	cin >> Q;

	s = vector<int>(Q);
	t = vector<int>(Q);


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


	for (int k = 1; k < N+1; k++) {   
		for (int i = 1; i < N+1; i++) { 
			for (int j = 1; j < N+1; j++) {
				cost_tbl[i][j] = min(cost_tbl[i][j], cost_tbl[i][k] + cost_tbl[k][j]);
			}
		}
	}

	auto recover_tbl = vector<vector<int>>(N + 1, vector<int>(N + 1, INF));
	for (int i = 1; i < N + 1; i++) {
		for (int j = 1; j < N + 1; j++) {
			if (cost_tbl[i][j] > 0 && cost_tbl[i][j] <= L) {
				recover_tbl[i][j] = 1;
			}
		}
	}
	for (int k = 1; k < N + 1; k++) {
		for (int i = 1; i < N + 1; i++) {
			for (int j = 1; j < N + 1; j++) {
				recover_tbl[i][j] = min(recover_tbl[i][j], recover_tbl[i][k] + recover_tbl[k][j]);
			}
		}
	}

	for (int i = 0; i < Q; i++) {
		int tmp = recover_tbl[s[i]][t[i]];

		cout << (tmp == INF ? -1 : tmp - 1) << endl;
	}

	return 0;
}


Measured memory_bytes: 2432
STDOUT.sync = true

def leap_year_judge(year)
  case
  when (year % 400).zero?
    true
  when (year % 100).zero?
    false
  when (year % 4).zero?
    true
  else
    false 
  end
end

count = 0

while line = gets do
  a,b = line.split.map(&:to_i)
  leap_count = 0
  break if a == 0 && b == 0
  puts "" unless count == 0
  count += 1

  (a..b).each do |current_year|
    if leap_year_judge(current_year)
      puts current_year
      leap_count += 1
    end
  end
  puts "NA" if leap_count == 0
end

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

int main(){
	int n, k;
	cin >> n >> k;
	vector<int> l(n);
	rep(i, n) cin >> l.at(i);

	sort(l.begin(), l.end());
	reverse(l.begin(), l.end());

	int ans = 0;
	rep(i, k){
		ans += l.at(i);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
/*
 * author :Sadik Hassan
 *
*/
#include "bits/stdc++.h"
using namespace std;
#define ll            long long
#define nl            "\n"
#define PB            push_back
#define fi            first
#define se            second
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define rep(i,n)      for(int i=0;i<n;i++)
#define repn(i,n)     for(int i=1;i<=n;i++)
#define rrep(i,n)     for(int i=n-1;i>=0;i--)
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
#define TSFL(s)       transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSFH(s)       transform(s.begin(),s.end(),s.begin(),::tolower);
/*---------------------------------------------------------------------*/
const int N = 2e5+10;
const int INF = (int)1e9+5;

int main()
{
    _SAD()
    int a,b;
    cin>>a>>b;
    cout<<a%b<<nl;
    return 0;
}


Measured memory_bytes: 256
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    a = f()
    x,y,z =abs(a[0]-a[1]), abs(a[0]-a[2]), abs(a[1]-a[2])
    print( x+y+z - max(x,y,z))

solve()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
// 最大公約数
ll gcd(ll m, ll n) {
  if (n == 0) return m;
  else return gcd(n, m % n);
}
 
// 動作確認
int main() {
  ll A, B;
  cin >> A >> B;
  ll m = min(A, B);
  int cnt = 1;
  ll g = gcd(A, B);
  ll t = g;
  for (ll i = 2; i * i <= t; i++) {
    if (g % i == 0) cnt++;
    while (g % i == 0) {
      g /= i;
    }
  }
  if (g != 1) cnt++;
  cout << cnt << "\n";
 
  return 0;
}

Measured memory_bytes: 256
import itertools
import functools
import math
from collections import Counter

N,X,Y=map(int,input().split())

k=[]

for i in range(1,N):
    for j in range(i+1,N+1):
        chk = min(abs(j-i),abs(X-i)+abs(j-Y)+1)
        k.append(chk)

a=Counter(k)

for i in range(1,N):
    print(a[i])


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

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

  vector<vector<int>> A(n, vector<int>(m, 0));
  vector<int> b(m, 0), c(n, 0);

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> A.at(i).at(j);
    }
  }

  for (int i = 0; i < m; i++) {
    cin >> b.at(i);
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      c.at(i) = inner_product(A.at(i).begin(), A.at(i).end(), b.begin(), 0);
    }
  }

  for (auto e : c) {
    cout << e << endl;
  }
}



Measured memory_bytes: 3156
#include <stdio.h>
#define x 10000
 
int main(){
  int i,j,n,t,c,Sawa[x],Hira[x];
  c = 0;
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&Sawa[i]);
  }
  scanf("%d",&t);
  for(i=0;i<t;i++){
    scanf("%d",&Hira[i]);
  }
   
  for(i=0;i<t;i++){
    for(j=0;j<n;j++){
      if(Hira[i]==Sawa[j]) {
    c++; break;
}
    }
  }
  printf("%d\n",c);
  return 0;
   
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define SPEED ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sz size()
#define all(x) x.begin(),x.end()
#define OO 1e18
#define iOO INT_MAX
#define Mdp memset(dp,-1,sizeof dp)
#define R return
#define Test int TT;cin>>TT;for(int T=1;T<=TT;T++)
using namespace std;
int n,k,a[200];
int dp[100010][3];


int Solve(int i=k,int Turn = 0)
{
    if(i == 0)
        R 0;

    int &State = dp[i][Turn];
    if(State != -1)
        R State;

    State = 0;
    for(int j=0;j<n;j++)
    {
        if(i-a[j] >= 0)
            State |= (!Solve(i-a[j],1-Turn));
    }

    R State;
}

int main()
{

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

    Mdp;

    cout << (Solve() ? "First" : "Second") << endl;

    R 0;
}


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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

const int INF = 1001001001;
// long long max => LLONG_MAX

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n, m; cin >> n >> m;
    vector<int> a(n), b(n);
    vector<int> c(m), d(m);

    for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
    for(int i = 0; i < m; i++) cin >> c[i] >> d[i];

    for(int i = 0; i < n; i++){
        int distMin = INF;
        int p = -1;
        for(int j = 0; j < m; j++){
            int dist = abs(a[i]-c[j]) + abs(b[i]-d[j]);
            if(distMin > dist){
                p = j+1;
                distMin = dist;
            }
        }
        cout << p << endl;
    }

    return 0;
}


Measured memory_bytes: 256
from collections import Counter


def combinations_count(n):
    return n*(n-1)//2


if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))
    c = Counter(a)
    t = 0
    for i in c:
        t += combinations_count(c[i])

    for i in range(n):
        print(t-c[a[i]]+1)


Measured memory_bytes: 26780