akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;
ll n,m,ans,mod=1e9+7,z,fact[200005],inv[200005];


ll fastpow(ll x,ll y){
    if(y==0)return 1;
    if(y==1)return x%mod;
    //if(x==0)return 0;
    ll a=fastpow(x,y/2)%mod;
    a=(a*a)%mod;
    a=(a*fastpow(x,y%2))%mod;
    return a;
}
ll ch(ll n,ll m){
	return (ll)fact[n]*inv[m]%mod*inv[n-m]%mod;
}


ll way(ll x1,ll y1,ll x2,ll y2){
    return ch(x2+y2-x1-y1,min(x2-x1,y2-y1));
}
ll a,b;
pair<ll,ll>bloc[3030];
ll sol[3030];
bool mys(pair<ll,ll>a,pair<ll,ll>b){
    return b.first>=a.first&&b.second>=a.second;
}
bool check(ll i,ll j){
    return (bloc[i].first>=bloc[j].first)&&(bloc[i].second>=bloc[j].second);
}
void init(){
	fact[0]=1;
	for(ll i=1;i<200005;i++)fact[i]=(ll)fact[i-1]*i%mod;
	inv[200004]=fastpow(fact[200004],mod-2);
	for(ll i=200003;i>=0;i--)inv[i]=(ll)inv[i+1]*(i+1)%mod;
}
int main(){
    init();
    cin>>n>>m>>z;
    ans=way(1,1,n,m);
    for(ll i=0;i<z;i++){
        cin>>bloc[i].first>>bloc[i].second;
    }

    sort(bloc,bloc+z);

    for(ll i=0;i<z;i++){
        sol[i]=way(1,1,bloc[i].first,bloc[i].second);
    }
    for(ll i=0;i<z;i++){
        for(ll j=0;j<i;j++){
            if(check(i,j)){
                b=way(bloc[j].first,bloc[j].second,bloc[i].first,bloc[i].second);
                b=(b*sol[j])%mod;
                sol[i]=(sol[i]-b+mod)%mod;
            }
        }
    }

    for(ll i=0;i<z;i++){
        a=sol[i];
        b=ch(n+m-bloc[i].first-bloc[i].second,min(n-bloc[i].first,m-bloc[i].second));
        //cout<<a<<' '<<b<<endl;
        a=(a*b)%mod;
        ans=(ans-a+mod)%mod;
    }
    //cout<<fact[5]<<endl;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<pair<int, int> > p(n);
        for(int i=0; i<n; ++i)
            cin >> p[i].first >> p[i].second;
        sort(p.begin(), p.end());

        int ret = 0;
        for(int i=0; i<n; ++i){
            for(int j=0; j<n; ++j){
                int x = p[j].first - p[i].first;
                int y = p[j].second - p[i].second;
                pair<int, int> p1(p[i].first + y, p[i].second - x);
                pair<int, int> p2(p[j].first + y, p[j].second - x);
                if(binary_search(p.begin(), p.end(), p1) && binary_search(p.begin(), p.end(), p2))
                    ret = max(ret, x*x + y*y);
            }
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 0
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	S := scanner.Text()

	for i := 0; i < len(S); i++ {
		if i%2 == 0 {
			if S[i:i+1] == "L" {
				fmt.Println("No")
				os.Exit(0)
			}
		} else {
			if S[i:i+1] == "R" {
				fmt.Println("No")
				os.Exit(0)
			}
		}
	}

	fmt.Println("Yes")
}


Measured memory_bytes: 1772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
const ll mod=998244353;
int main(void){
    ll n,k;
    cin>>n>>k;
    vector<pair<ll,ll>>p(k);
    rep(0,i,n){
        cin>>p[i].first>>p[i].second;
    }
    ll dp[n+1],pre[n+1];
    rep(0,i,n+1){
        dp[i]=pre[i]=0;
    }
    pre[1]=1,dp[1]=1;
    rep(2,i,n+1){
        rep(0,j,k){
            ll l=p[j].first,r=p[j].second;
            if(i-l<=0)continue;
            dp[i]=(dp[i]+pre[i-l]-pre[max((ll)0,i-r-1)]+mod)%mod;
        }
        pre[i]=(dp[i]+pre[i-1])%mod;
        //cout<<dp[i]<<endl;
    }
    cout<<dp[n];
}

Measured memory_bytes: 6776
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7


H, W = MI()
print('#' * (W + 2))
for _ in range(H):
    print('#' + input() + '#')
print('#' * (W + 2))

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
const ll MOD=1e9+7;
int n,m;
int a[100];
int dp[101][100001];

void solve(){
    rep(i,0,n+1){
        dp[i][0]=1;
    }
    rep(i,0,n){
        rep(j,1,m+1){
            if(j-1-a[i]>=0){
                dp[i+1][j]=(dp[i+1][j-1]+dp[i][j]-dp[i][j-1-a[i]]+MOD)%MOD;
            }
            else dp[i+1][j]=(dp[i+1][j-1]+dp[i][j])%MOD;
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m;
    rep(i,0,n) cin>>a[i];
    solve();
    cout <<dp[n][m]<<"\n";
}

Measured memory_bytes: 39296
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
const int N = 1e5 + 5;
int n, k, r, s, p;
string t, play = "rspt";
ll dp[N][5];
ll score(char a, char b){
    if(a == 'r' && b == 'p') return p;
    else if(a == 's' && b == 'r') return r;
    else if(a == 'p' && b == 's') return s;
    else return 0;
}
ll solve(int idx, int prev){
    if(idx >= n) return 0;
    if(dp[idx][prev] != -1) return dp[idx][prev];
    ll ans = 0;
    for(int i = 0; i < 3; i++)
        if(i != prev)
            ans = max(ans, solve(idx + k, i) + score(t[idx], play[i]));
    dp[idx][prev] = ans;
    return dp[idx][prev];
}
int main(){
    Hello
    cin >> n >> k >> r >> s >> p >> t;
    ll ans = 0;
    memset(dp, -1, sizeof dp);
    for(int i = 0; i < k; i++) ans += solve(i, 3);
    cout << ans;
    return 0;
}

Measured memory_bytes: 12284
#include <iostream>
#include <cstring>
#include <string>

using namespace std;

class saikoro {
    int down;                   // 底面の番号　（０....5)
    int work[6];
 
    void copy(int table[]);
    void s();                   // S方向に転がす
    void n();                   // N方向に転がす
    void e();                   // e方向に転がす
    void w();                   // w方向に転がす
public:
    saikoro() { for (int i = 0; i < 6; i++) number[i] = i + 1; }

    int number[6];              // サイコロ上の番号

    int& getnumber(int i) { return number[i]; }
    void cmd(string& c);        // コマンド実行
    int up();                   // 上面の番号を取得
 };

int saikoro::up()
{
    return number[0];
}

void saikoro::copy(int table[])
{
//  cout << table[0] << " " << table[1] << " " << table[2] << " " << table[3] << " " << table[4] << " " << table[5] << endl; 
//  cout << number[0] << " " << number[1] << " " << number[2] << " " << number[3] << " " << number[4] << " " << number[5] << endl; 

    for (int i = 0; i < 6; i++) {
        int tmp = table[i];
        if (tmp) {
            work[i+tmp] = number[i];
        } else {
            work[i] = number[i];
        }
    }
    memcpy(number, work, sizeof(number));
}

void saikoro::s()
{
    static int table[] = { 1, 4, 0, 0, -4, -1 };

    copy(table);
}

void saikoro::n()
{
    static int table[] = { 4, -1, 0, 0, 1, -4 };

    copy(table);
}

void saikoro::e()
{
    static int table[] = { 2, 0, 3, -3, 0, -2 };

    copy(table);
}

void saikoro::w()
{
    static int table[] = { 3, 0, -2, 2, 0, -3 };

    copy(table);
}

void saikoro::cmd(string& c)
{
    int len = c.length();

    for (int i = 0; i < len; i++) {
        switch (c.at(i)) {
        case 'S': s(); break;
        case 'N': n(); break;
        case 'E': e(); break;
        case 'W': w(); break;
        default: break;
        }
//      cout << c.at(i) << " " << number[0] << " " << number[1] << " " << number[2] << " " << number[3] << " " << number[4] << " " << number[5] << endl; 
    }
}

istream& operator>>(istream& s, saikoro& sai)
{
    s >> sai.number[0] >> sai.number[1] >> sai.number[2] >> sai.number[3] >> sai.number[4] >> sai.number[5];
    return s;
}

int main()
{
    saikoro si;

    // さいころの面上の番号
//    for (int i = 0; i < 6; i++) {
//        cin >> si.getnumber(i);
//    }
 
    string buf;

    cin >> si;
    getline(cin, buf);              // 改行
 
    getline(cin, buf);              // コマンド

    si.cmd(buf);

    cout << si.up() << endl;
   
    return 0;
}


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

int main(void){
    int l,r;
    cin >> l >> r;
    r = min(l+2019,r);

    int minmod = 2019;
    for(int i=l;i<r;i++){
        for(int j=l+1;j<=r;j++){
            if(minmod>(i%2019)*(j%2019)%2019){
                minmod = (i%2019)*(j%2019)%2019;
            }
        }
    }
    cout << minmod << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int n,A[110000];
int check(int K){
	long long now=A[K];
	for (int i=1;i<=n;i++)
		if (i!=K){
			if (A[i]>(now<<1)) return 0;
			now+=A[i];
		}
	return 1;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&A[i]);
	sort(A+1,A+n+1);
	int l=1,r=n+1,ans=n+1;
	while (l<r){
		int mid=l+r>>1;
		if (check(mid)){
			ans=mid; r=mid;
		} else l=mid+1;
	}
	printf("%d\n",n-ans+1);
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<algorithm>

#define ll long long

using namespace std;

const int MAXN=200010;

int n,a[MAXN];
ll ans;

int main()
{
//	freopen("in.in","r",stdin);
	
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",a+i);
	sort(a+1,a+n+1);
	
	ans+=a[n];
	
	int i=2,j=n;
	while(1)
	{
		--j;
		if(i<=n-1){ans+=a[j];++i;}
		if(i<=n-1){ans+=a[j];++i;}
		if(i>n-1)break;
	}
	
	printf("%lld\n",ans);
	
	return 0;
}

Measured memory_bytes: 2512
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef long long int ll;

int main() {
  string T;
  cin>>T;
  
  rep(i,T.size()){
    if(T[i]=='?')
      T[i]='D';
  }
  
  cout<<T<<endl;
}


Measured memory_bytes: 3768
#include <iostream>
using namespace std;
#define MAX 2000000

int H, A[MAX+1];
int parent(int i)
{
    return i/2;
}
int left(int i)
{
    return 2*i;
}
int right(int i)
{
    return 2*i+1;
}
void maxHeapify(int A[], int i)
{
    int l = left(i), largest;
    int r = right(i);
    if(l<=H && A[l]>A[i])
        largest = l;
    else
        largest = i;
    if(r<=H && A[r]>A[largest])
        largest = r;
    if(largest != i)
    {
        swap(A[i], A[largest]);
        maxHeapify(A,largest);
    }
}
void buildMaxHeap(int A[])
{
    for(int i=H/2; i>=1; i--)
        maxHeapify(A,i);
}
int main()
{
    cin >> H;
    for(int i=1; i<=H; i++)
        cin >> A[i];
    buildMaxHeap(A);
    for(int i=1; i<=H; i++)
        cout << " " << A[i];
    cout << endl;
    return 0;
}

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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  
  char a[50][50], b[50][50];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> a[i][j];
    }
  }

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

  bool exist = false;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (i + m - 1 >= n || j + m - 1 >= n) {
        continue;
      }

      bool match = true;
      for (int k = 0; k < m; ++k) {
        for (int l = 0; l < m; ++l) {
          if (a[i + k][j + l] != b[k][l]) {
            match = false;
          }
        }
      }
      if (match) {
        exist = true;
      }
    }
  }

  if (exist) {
    py();
  } else {
    pn();
  }
}

Measured memory_bytes: 256
N,M = map(int,input().split())
a = [int(input()) for _ in range(M)]
MOD = 10 **9 + 7

import sys
for i in range(M-1):
    flag = a[i+1]-a[i]
    if flag == 1:
        print(0)
        sys.exit()
        
        
dp = [0] * (N+10)
dp[1] = 1
dp[2] = 1
for i in range(1,N+5):
    dp[i+2] = dp[i+1] + dp[i]
    dp[i+2] %= MOD
    
if M == 0:
    print(dp[N+1])
    sys.exit()
ans = 1
for i in range(M+1):
    if i == 0:
        number = a[i]
    elif i == M:
        number = N - a[i-1]
    else:
        number = a[i]-a[i-1] - 1
    number = max(1,number)
    ans *= dp[number]
    ans %= MOD
print(ans)
    

Measured memory_bytes: 8984
import * as fs from 'fs'
const reader = (s: string) => s.split('\n')

function Main(input: string) {
  const [tmp, tmp2] = reader(input)
  const [N, K] = tmp.split(' ').map(x => parseInt(x, 10))
  const D = tmp2.split(' ')
  let ans = N

  while (1) {
    let count = 0
    for (const i of D) {
      if (ans.toString().indexOf(i) !== -1) {
        break
      }
      count++
    }
    if (count === K) {
      break
    }
    ans += 1
  }
  console.log(ans)
}

Main(fs.readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 10292
#include <stdio.h>
int main(void)
{
    long long int a,b,x,ans=0,i,j;
    scanf("%lld%lld%lld", &a,&b,&x);
    if(a==0) i=0;
    else i=((a-1)-((a-1)%x))/x+1;
    j=(b-(b%x))/x+1;
    ans=j-i;

    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 128
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans = 0
for i in range(n)[::-1]:
  if (A[i+1] + A[i]) <= B[i]:
    ans += (A[i+1]+A[i])
    A[i], A[i+1] = 0, 0
  else:
    ans += B[i]
    if A[i+1] - B[i] >= 0:
      A[i+1] = A[i+1] - B[i]
    else:
      A[i] = (A[i+1] + A[i] - B[i]) if (A[i+1] + A[i] - B[i]) else 0
      A[i+1] = 0

print(ans)

Measured memory_bytes: 19416
#include<bits/stdc++.h>
using namespace std;
long long int f[1000006];
long long int a[1000006];
int main()
{

    long long int mod,t,k=0,i,m,n,x,j=0,l,c=0,r=0,w,s,d=0,sum=0,mul,mx1,mx,s1=10000000,s2=0;

    cin>>n;


    for(i=1; i<=n; i++)
    {

        cin>>a[i];
    }
    f[n+1]=1e9;


    for(i=n-1; i>=1; i--)
    {
        d=f[i+1]+abs(a[i]-a[i+1]);
        c=f[i+2]+abs(a[i]-a[i+2]);

        f[i]=min(d,c);
    }
    cout<<f[1]<<endl;
    return 0;

}


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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, start, end) for(int i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define INFL (1e18)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

template<typename A, size_t N, typename T>
void array_fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    int a, b;
    cin >> a >> b;

    cout << max(a + b, max(a + a - 1, b + b - 1)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
const int MAXN = 100005;
const int mod = 998244353;

struct disj{
	int pa[MAXN];
	void init(){
		iota(pa, pa + MAXN, 0);
	}
	int find(int x){
		return pa[x] = (pa[x] == x ? x : find(pa[x]));
	}
	bool uni(int p, int q){
		p = find(p);
		q = find(q);
		if(p == q) return 0;
		pa[q] = p; return 1;
	}
}disj;

int n, m;
vector<int> v[MAXN];

int main(){
	scanf("%d %d",&n,&m);
	for(int i=1; i<=n; i++){
		int x; scanf("%d",&x);
		while(x--){
			int y; scanf("%d",&y);
			v[y].push_back(i);
		}
	}
	disj.init();
	int ret = 0;
	for(int i=1; i<=m; i++){
		for(int j=1; j<v[i].size(); j++){
			ret += disj.uni(v[i][j-1], v[i][j]);
		}
	}
	if(ret != n - 1) puts("NO");
	else puts("YES");
}



Measured memory_bytes: 4992
import math
A,B,H,M = map(int,input().split())

L_S =  H*30 + M/2 - 6*M

L_S = abs(L_S)
if L_S > 180 :
       L_S = 360 - L_S

print(math.sqrt(A**2+B**2 - 2*A*B*math.cos( L_S/180 * math.pi)))

Measured memory_bytes: 9504
use input::Input;

fn main() {
    let mut input = Input::default();

    let x = input
        .read_line()
        .trim_end()
        .split_whitespace()
        .map(String::from)
        .collect::<Vec<_>>();

    for (i, a) in x.iter().enumerate() {
        if a == &"0" {
            println!("{}", i + 1);
            return;
        }
    }
}

#[allow(dead_code)]
pub mod input {
    #[derive(Default)]
    pub struct Input(Vec<String>);

    impl Input {
        pub fn read_line(&mut self) -> String {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).ok().expect("read error");
            s
        }
        pub fn parse<T: std::str::FromStr>(&mut self) -> T {
            let x = if let Some(x) = self.0.pop() {
                x
            } else {
                let s = self.read_line();
                self.0 = s.split_whitespace().map(String::from).rev().collect();
                self.0.pop().expect("reached EOF")
            };
            x.parse().ok().expect("parse error")
        }
    }
}


Measured memory_bytes: 2060
#include <iostream>
#include <string>

std::string Shuffle(const std::string& s, int h)
{
    int l = s.length();
    return s.substr(h, l - h) + s.substr(0, h);
}
std::string Shuffle(std::string s, std::istream& in)
{
    int m;
    in >> m;
    for(int i = 0; i < m; ++i){
        int h;
        in >> h;
        s = Shuffle(s, h);
    }
    return s;
}

int main()
{
    std::string s;
    std::cin >> s;
    for(; s != "-"; std::cin >> s){
        std::cout << Shuffle(s, std::cin) << std::endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <string>
#include <cstdlib>
#include <typeinfo>

using namespace std;

int main() {
    int r, g, b;
    cin >> r >> g >> b;

    string s  = to_string(r) + to_string(g) + to_string(b);
    int t = atoi(s.c_str());
    if (t % 4 == 0) {
	cout << "YES" << endl;
    } else {
	cout << "NO" << endl;
    }
}


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

int main() {
  string S;
  cin >> S;
  
  long long result = 0;
  for (int i = 0; i < 4; i++) {
    if (S[i] == '+') {
      result++;
    } else {
      result--;
    }
  }
  
  cout << result << endl;
  
  return 0;
}

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

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()
#define bin(x) static_cast<bitset<16> >(x)



/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;


/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}

/* main */

string s;
string t;
void in(){
    cin >> s >> t;
}

void solve(){
    
    map<char, char> mp;
    map<char, char> mp2;

    bool isok = true;
    rep(i,0,sz(s)){


        if(exist(mp, s[i])){
            if(mp[s[i]] != t[i]){
                isok = false;
                break;
            }
        }else{
            mp[s[i]] = t[i];
        }

    }
    rep(i,0,sz(s)){

        if(exist(mp2, t[i])){
            if(mp2[t[i]] != s[i]){
                isok = false;
                break;
            }
        }else{
            mp2[t[i]] = s[i];
        }
    }

    print(isok ? "Yes" : "No");


}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

Measured memory_bytes: 916
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> a(n); for (auto&& e : a) cin >> e, --e;
  V<> b(n); for (auto&& e : b) cin >> e;
  V<> c(n - 1); for (auto&& e : c) cin >> e;
  
  int res = accumulate(begin(b), end(b), 0);
  for (int i = 0; i < n - 1; ++i) {
    if (a[i + 1] == a[i] + 1) {
      res += c[a[i]];
    }
  }
  cout << res << '\n';
}

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

inline long long read(){
    long long s = 0, w = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9'){
        if (ch == '-') w = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9'){
        s = s * 10 + ch - '0';
        ch = getchar();
    }
    return s * w;
}

int main(){
    string s;
    cin >> s;
    int n = s.size();
    for (int i = 0; i < n; i++){
        if (s[i] == '7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long a = sc.nextLong();
		String b = sc.next();
		String d = "";
		
		for(int i = 0; i< b.length(); i++) {
			if(b.charAt(i) == '.') {
				continue;
			}
			d+=b.charAt(i);
		}
		int c= new Integer(d).intValue();
		System.out.println(a*c/100);
	}
}

Measured memory_bytes: 27044
#include <bits/stdc++.h>
using namespace std;
const int INF = 2100100100;
using ll = long long;

int main(){
    int L;
    cin >> L;
    float f = L/3.f;
    printf("%.12f\n",pow(f,3));
    return 0;
}

// int main() {
//     int L;
//     cin >> L;
 
//     double d = L / 3.l;
//     // double ans = );
 
//     printf("%.12f\n", pow(d,3));
 
//     return 0;
// }

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
  int n,d,x;
  cin>>n>>d>>x;
  int sum = x;
  for(int i = 0; i < n; i++){
    int a;
    cin>>a;
    sum+=(d-1)/a+1;
  }
  cout<<sum<<endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int a, b;


signed main(){
    cin >> a >> b;

    cout << max(0LL, a-2*b) << endl;

    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import bisect

N,K=map(int,input().split())
X=list(map(int,input().split()))

zero=bisect.bisect_left(X,0)

ans=10**18
start=max(0,zero-K)
for i in range(start,start+N-K+1):
    #print(i)
    m=min(0,X[i])
    M=max(0,X[i+K-1])
    ans=min((abs(m)+abs(M)*2),(abs(m)*2+abs(M)),ans)
    if i+K==N:
        break
    
print(ans)



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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  cout << accumulate(v.begin(), v.begin() + K, 0LL) << endl;
}


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

int main() {

  string S;
  cin >> S;
  
  if(S == "ABC")
     cout << "ARC" << endl;
  else
    cout << "ABC" << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A,B,C,D;
    cin>>A>>B>>C>>D;
if(A+B==C+D){
    cout<<"Balanced"<<endl;
}
else if(A+B>C+D){
    cout<<"Left"<<endl;
}
else if(A+B<C+D){
    cout<<"Right"<<endl;
}
}

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

using namespace std;

typedef vector<int> Vec;
typedef vector<Vec> Mat;

Mat a(5, Vec(5));
int score[5];

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

bool inField(int x, int y)
{
    return (0 <= x && x < 5 && 0 <= y && y < 5);
}

bool up;

int erase(Mat &m)
{
    bool e[5][5] = {{}};
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 5; j++) {                        
            if (m[i][j] == 0) {
                continue;
            }
            int cnt[2] = {1, 1};
            for (int k = 0; k < 4; k++) {
                int ni = i + dy[k];
                int nj = j + dx[k];
                while (inField(ni, nj) &&
                       m[i][j] == m[ni][nj]) {
                    ni += dy[k];
                    nj += dx[k];
                    ++cnt[k&1];
                }
            }
            if (cnt[0] >= 3 || cnt[1] >= 3) {
                e[i][j] = 1;
            }
        }
    }
    int point = 0;
    for (int i = 0; i < 5; i++) {
        for (int j = 0; j < 5; j++) {
            if (e[i][j]) {
                up = 1;
                point += score[m[i][j]-1];
                m[i][j] = 0;
            }
        }
    }
    return point;
}

void fall(Mat &m)
{
    for (int j = 0; j < 5; j++) {
        for (int i = 4; i >= 1; i--) {
            if (m[i][j] == 0) {                
                for (int k = i-1; k >= 0; k--) {
                    if (m[k][j] != 0) {
                        swap(m[i][j], m[k][j]);
                        break;
                    }
                }
            }
        }
    }
}

int calc(Mat &m, int bp)
{
    int point = erase(m) * bp;
    fall(m);
    return point;
}

int get_point()
{
    Mat b = a;
    int point = 0, bp = 1;
    bool update = 1;
    
    while (update) {
        update = 0;        
        Mat nb = b;
        up = 0;
        int p = calc(nb, bp++);
        if (up) {
            point += p;
            update = 1;
            b = nb;
        }
    }
    return point;
}

int dfs(int y, int x, int n)    
{
    int point = get_point();
    if (n > 0) {
        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (inField(nx, ny)) {
                swap(a[ny][nx], a[y][x]);
                point = max(point, dfs(ny, nx, n-1));
                swap(a[ny][nx], a[y][x]);
            }        
        }
    }
    return point;
}

int main()
{
    int n;
    while (cin >> n, n != -1) {
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
                cin >> a[i][j];
            }
        }
    
        for (int i = 0; i < 5; i++) {
            cin >> score[i];
        }

        int max_point = 0;
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
                max_point = max(max_point, dfs(i, j, n));
            }
        }   
        cout << max_point << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s;
	cin>>s;
	if(s[2]==s[3]&&s[4]==s[5]){
		cout << "Yes";
	}
	else{
		cout << "No";
	}
	// your code goes here
	return 0;
}

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



int main(){
    int N,count=0,b;
    int64_t K,cycle;
    cin>>N>>K;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A.at(i);
    }
    vector<int> pre(N,-1);
    pre.at(0)=0;
    int index=0;
    while(true){
        count++;
        if(pre.at(A.at(index)-1)!=-1){
            cycle=count-pre.at(A.at(index)-1);
            b=pre.at(A.at(index)-1);
            break;
        }
        else{
            pre.at(A.at(index)-1)=count;
            index=A.at(index)-1;
        }
    }
    if(count>K){
        for(int i=0;i<N;i++){
            if(pre.at(i)==K){
                cout<<i+1<<endl;
            }
        }
    }
    else{
        int64_t a=(K-count)%cycle+b;
        for(int i=0;i<N;i++){
            if(pre.at(i)==a){
                cout<<i+1<<endl;
            }
        }
    }
}

Measured memory_bytes: 4844
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
a = tuple(map(int,input().split()))
mod =10**9+7

#dp[i][j]:0~iまでの子がj個分け合う場合の数
dp = [[0]*(k+1) for i in range(n)]
#b[q+1]-b[p] = dp[x][p]+...+dp[x][q]
b = [0]*(k+2)

for i in range(k+1):
    if i <= a[0]:
        dp[0][i] = 1
    b[i+1] = b[i]+dp[0][i] 

for i in range(1,n):
    for j in range(k+1):
        dp[i][j] = (b[j+1]-b[max(0,j-a[i])])%mod
    #bの更新
    b[0] = 0
    for j in range(k+1):
        b[j+1] = (b[j]+dp[i][j])%mod
        dp[i][j] = dp[i][j]%mod
print(dp[-1][-1])

Measured memory_bytes: 119532
//https://atcoder.jp/contests/abc135/tasks/abc135_d
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
constexpr ll MOD=1e9+7;
ll dp[100007][13]={};
int main() {
#if LOCAL&0
    //13で割って5余る、6桁
    for(ll i=1;i<1000;++i){
        cout<<13*i+5<<endl;
    }
#endif    
    string S; cin>>S;
    auto get_val = [&](ll p){ //-1だと?
        if(S[p]=='?'){
            return -1;
        }
        return S[p]-'0';
    };
    ll s=get_val(0);
    if(s<0){
        for(ll i=0;i<=9;++i){
            dp[0][i]=1;
        }
    } else {
        dp[0][s]=1;
    }
    for(ll i=1;i<S.size();++i){
        ll v=get_val(i);
        for(ll d=0;d<=9;++d){ //今のけたの数字
            if(v==d||v<0){
            for(ll p=0;p<13;++p){ //前の桁あまり
                ll r=(p*10+d)%13;
                dp[i][r] += dp[i-1][p];
                dp[i][r] %= MOD;
            }
            }
        }
    }
    cout<<dp[S.size()-1][5]<<endl;
    return 0;
}

Measured memory_bytes: 10624
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << '\n'

typedef int64_t Int;
const double pi = M_PI;

using namespace std;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;

int N, M, K;
Graph G, F, B;
vector<bool> seen;
int vt_count;
vector<int> graph_size, fb_count, ans;
queue<int> temp_v;
map<int, int> v_to_comp;

void dfs(const Graph &graph, int v) {
    seen[v] = true;
    temp_v.push(v);

    for (auto e : graph[v]) {
        if (seen[e.first])
            continue;

        dfs(graph, e.first);
    }

    vt_count++;
}

int main() {
    cin >> N >> M >> K;
    G.assign(N, vector<Edge>());
    F.assign(N, vector<Edge>());
    B.assign(N, vector<Edge>());
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;

        G[a].push_back({b, 1});
        G[b].push_back({a, 1});

        F[a].push_back({b, 1});
        F[b].push_back({a, 1});
    }
    for (int i = 0; i < K; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;

        G[b].push_back({a, -1});
        G[a].push_back({b, -1});

        B[a].push_back({b, -1});
        B[b].push_back({a, -1});
    }

    graph_size.assign(N, 0);
    fb_count.assign(N, 0);
    ans.assign(N, 0);

    seen.assign(N, false);
    int comp = 0;
    for (int v = 0; v < N; v++) {
        if (seen[v]) {
            continue;
        }
        vt_count = 0;
        dfs(F, v);

        while (!temp_v.empty()) {
            v_to_comp.insert({temp_v.front(), comp});
            graph_size[temp_v.front()] = vt_count;
            temp_v.pop();
        }
        comp++;
    }

    for (int v = 0; v < N; v++) {
        for (auto e : G[v]) {
            if (v_to_comp[v] == v_to_comp[e.first]) {
                fb_count[v]++;
            }
        }
    }

    // for (int v = 0; v < N; v++) {
    //     dump(v + 1 << ':' << graph_size[v] << "  " << fb_count[v]);
    // }
    // for (auto e : v_to_comp) {
    //     dump(e.first << ':' << e.second);
    // }

    seen.assign(N, false);
    for (int v = 0; v < N; v++) {
        if (seen[v]) {
            continue;
        }
        dfs(F, v);
    }

    for (int v = 0; v < N - 1; v++) {
        ans[v] = graph_size[v] - fb_count[v] - 1;
        cout << ans[v] << ' ';
    }
    ans[N - 1] = graph_size[N - 1] - fb_count[N - 1] - 1;
    cout << ans[N - 1] << endl;
}


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

int main() {
  int n,a,b;
  cin >> n >> a >> b;
  if((b-a-1)%2 == 0) cout << "Borys" << endl;
  else cout << "Alice" << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import kotlin.math.max

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
//        repeat(readInteger()) { solve() }
        solve()
        out.flush()
    } }
}

fun solve() {
    val (n, m) = readIntegerList()
    val uf = UnionFind(n)
    repeat(m) {
        val (a, b) = readIntegerList().map { it - 1}
        uf.unite(a, b)
    }

    var set = mutableSetOf<Int>()
    for (i in 0 until n) {
        set.add(uf.findRoot(i))
    }
    out.println(set.size - 1)
}

/**　Union find 0 ~ (n - 1)　*/
class UnionFind(n: Int) {
    val parent = IntArray(n) { it }
    val rank = IntArray(n)
    val size = IntArray(n) { 1 }

    /** O(α(n)) */
    fun findRoot(x: Int): Int {
        if (parent[x] == x) return x

        parent[x] = findRoot(parent[x])
        return parent[x]
    }

    /** O(α(n)) */
    fun sameRoot(x: Int, y: Int) = findRoot(x) == findRoot(y)

    /** O(α(n)) */
    fun unite(x: Int, y: Int) {
        val x = findRoot(x)
        val y = findRoot(y)
        if (x == y) return

        if (rank[x] < rank[y]) {
            parent[x] = y
            size[y] += size[x]
        } else {
            parent[y] = x
            if (rank[x] == rank[y]) rank[x]++

            size[x] += size[y]
        }
    }

    /** O(α(n)) */
    fun getSize(x: Int) = size[findRoot(x)]
}


fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 60212
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    os << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        os << ", " << *it;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    os << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        os << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint K; cin >> K;
    string S; cin >> S;
    cout << (S.size() <= K ? S : S.substr(0, K) + "...") << "\n";
}

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

using namespace std;

#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define REP2(i,n) for(int i=1;i<=n;i++)
#define DEBUG 0
#define MOD 1000000007

#define BLACK 0
#define WHITE 1

lli data[1010][1010];
lli dp[1010][1010];

lli h,w;

lli judge(){

	REP(i,h)REP(j,w){
		if(data[i][j]==WHITE)return 0;
	}

	return 1;
}

int main(){

	cin>>h>>w;

	queue<lli> qi;
	queue<lli> qj;
	queue<lli> qsize;
	REP(i,h)REP(j,w){
		char tmp;
		cin>>tmp;
		if(tmp == '#'){
			data[i][j]=BLACK;
			qi.push(i);
			qj.push(j);
			qsize.push(0);
		}
		else data[i][j] = WHITE;
	}

	/*幅有線探索を行う*/
	lli now = 0;
	lli lastSize=0;

	while(qi.size()){
		lli nowI = qi.front();
		lli nowJ = qj.front();
		lli nowSize = qsize.front();
		if(DEBUG)cout<<"nowI="<<nowI<<" nowJ="<<nowJ<<" nowsize="<<nowSize<<endl;
		qi.pop();
		qj.pop();
		qsize.pop();
		lastSize = nowSize;

		lli di[4]={-1,0,1,0};
		lli dj[4]={0,1,0,-1};
		lli nextSize = nowSize+1;
		REP(k,4){
			lli nextI = nowI+di[k];
			lli nextJ = nowJ+dj[k];
			if(nextI<0 || nextI>=h || nextJ<0 || nextJ>=w)continue;
			if(data[nextI][nextJ]==WHITE){
				data[nextI][nextJ]=BLACK;
				qi.push(nextI);
				qj.push(nextJ);
				qsize.push(nextSize);
			}
		}

		if(DEBUG){
			REP(i,h){
				REP(j,w)cout<<data[i][j]<<" ";
				cout<<endl;
			}
			cout<<endl;
		}
	}

	if(DEBUG){
		REP(i,h){
			REP(j,w)cout<<data[i][j]<<" ";
			cout<<endl;
		}
	}

	cout<<lastSize<<endl;

	return 0;
}

Measured memory_bytes: 34608
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pb push_back
#define pll pair<ll,ll> 
#define mll map<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0; i<n; i++)
#define All(x,v) for(auto x:v)
#define arrin(a,n) ll a[n]; rep(i,n) cin>>a[i]
#define vi vector<int>
#define nl "\n"
#define print(arr) All(x,arr) cout<<x<<" "; cout<<nl
#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define ing(m,ad) rep(i,m){ int u,v; cin>>u>>v; u--;v--; ad[u].pb(v); ad[v].pb(u);}
#define vdsort(v) sort(v.begin(),v.end(),greater<int>())
#define F first
#define S second
#define mod 1000000007
const int MAXN=100005;
int spf[MAXN];
ll fac1[MAXN],fac2[MAXN],inv[MAXN];
ll gcd(ll x, ll y){ return y?gcd(y,x%y):x; }

void sieve(){  
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++)  spf[i] = i; 
    for (int i=4; i<MAXN; i+=2) spf[i] = 2; 
    for (int i=3; i*i<MAXN; i++) { 
        if (spf[i] == i) 
            for (int j=i*i; j<MAXN; j+=i) 
                if (spf[j]==j)  spf[j] = i; 
    } 
} 
vector<int> getFactorization(int x){
    vector<int> ret; 
    while (x != 1) { 
        ret.push_back(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
}

ll exp(ll n, ll m){
    ll a = 1;
    while (m){
        if (m & 1) a = (a * n % mod) % mod;
        m /= 2;
        n = (n*n) % mod;
    }
    return a;
}

void pre(){
    fac1[0]=fac2[0]=inv[1]=1;
    for(int i=1;i<MAXN;i++){
        fac1[i]=(fac1[i-1]*i)%mod;
        if(i>1) inv[i]=( mod - ((ll)(mod/i)*inv[mod%i])%mod ) %mod;
    }
    for(int i=1;i<MAXN;i++) fac2[i]=(fac2[i-1]*inv[i])%mod;
}
ll C(int n,int k){
    if(n<k) return 0;
    return ((fac1[n]*fac2[n-k]%mod)*fac2[k]%mod);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    // freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    int n,t=1;
    // cin>>t;
    while(t--){
        cin>>n;
        pll p[n];
        rep(i,n){
            cin>>p[i].F>>p[i].S;
        }
        bool ok=0;
        rep(i,n-2){
            if(p[i].F==p[i].S && p[i+1].F==p[i+1].S && p[i+2].F==p[i+2].S){
                ok=1; break;
            }
        }
        if(ok) cout<<"Yes\n"; else cout<<"No\n";
    }
    return 0;
}

Measured memory_bytes: 3140
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
int main(){
    int N, Y, cnt = 0;
    cin >> N >> Y;
    for(int x = 0; x <= N; x++){
        for(int y = 0; y <= N; y++){
            int z = N - x - y;
            int sum = 10000 * x + 5000 * y + 1000 * z;
            if(sum == Y && z >= 0){
                cout << x << " " << y << " " << z << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <vector>
#include <algorithm>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;

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


// 配列a[0], a[1],... a[n]が与えられる。部分列で、すべての要素に対しa[j]<a[k] (j<k)が成り立つような最長の部分列の長さを求める。
// T[k]を長さkの単調増加部分列の最後の要素の内、最小のものとする。
// この時、T[j] < T[k] (j<k)である。何故なら、長さj+1の部分列は長さjの部分列に、長さjの部分列の最後の要素より大きい数値をつけ足したものであるため、
// 単調部分列の定義からT[J]<T[j+1]...<T[k]となる。したがってT[j]<T[k]が常に成り立つ。
// このようにTを定義したとき、新たに接続される要素に対して部分列を考えると、更新されるkの位置が自動的に決定される。
// もしTがkまで定義されていて、T[k] < a[m]なる要素が入力された時、明らかにkより長い部分列を作れるので、T[k+1] = a[m]となる。

int main() {
  LL N, D; scanf("%ld %ld" ,&N, &D);
  vector<vector<LL>> XY;
  vector<LL> r2;  
  LL X, Y;
  rep(i, N){
    scanf("%ld %ld" ,&X, &Y);
    XY.push_back({X,Y});
    r2.push_back(X*X+Y*Y);
  }
  // D2と比較
  int count = 0;
  rep(i, N) if(r2[i] <= D*D) count++;
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 15824
/*input
5
1 2 3 4 5
*/
#include<bits/stdc++.h>
using namespace std;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,d;
	cin>>n>>d;
	int  b[n][d];
	for(int i = 0; i < n; i++){
		for(int j = 0; j  < d; j++)
		{
			cin>>b[i][j];
		}
	}
	int count = 0;
	int sum =0; 
	for(int i = 0; i  < n-1; i++){

		for(int k =i+1; k <n;k++){
				sum = 0;
			if(i != k){
		for(int j =0; j < d; j++){
			sum += (b[i][j]- b[k][j])*(b[i][j]- b[k][j]);
		}
		float x = sqrt(1.0*sum);

		if(abs(x -int(x))== 0)
			count++;
	}
	}
}
	cout<<count;
}

Measured memory_bytes: 256