akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()

int main(){
    vector <string> S(3);
    rep(i,3) cin >> S[i];

    int la=S[0].size(), lb=S[1].size(), lc=S[2].size();

    int ac=0, bc=0, cc=0;
    int tmp = 0;
    string turn= "a";
    bool ok=true;
    while(ok){
        if(turn == "a"){
            if(ac >= S[0].size()){
                ok = false;
                break;
            }
            turn = S[0][ac];
            ac++;
        }
        else if(turn == "b"){
            if(bc >= S[1].size()){
                ok = false;
                break;
            }
            turn = S[1][bc];
            bc++;
        }
        else{
            if(cc >= S[2].size()){
                ok = false;
                break;                
            }
            turn = S[2][cc];
            cc ++;
        }
    }

    if(turn == "a") cout << "A" << endl;
    else if(turn == "b") cout << "B" << endl;
    else cout << "C" << endl;


}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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

signed main() {
  int N,K; cin >> N >> K;
  vector<P> input(N);
  rep(i, N) {
    cin >> input[i].first >> input[i].second;
  }
  sort(all(input));
  int count = 0;
  for(auto v:input){
    count += v.second;
    if(K <= count){
      cout << v.first << endl;
      PRINT(v.first)
      return 0;
    }
  }
}

Measured memory_bytes: 1024
n = input()
if n == "MON":
    print("6")
elif n == "TUE":
    print("5")
elif n == "WED":
    print("4")
elif n == "THU":
    print("3")
elif n == "FRI":
    print("2")
elif n == "SAT":
    print("1")
else:
    print("7")

Measured memory_bytes: 2940
#include<stdio.h>
#include<string.h>
#define N 1001
 
int LCS_Length(char [] ,char []);
char X[N],Y[N];
int c[N][N];
int x,y;
int main(void){
  int i;
  int n;
  scanf("%d",&n);
 
  for(i=1;i<=n;i++){
    scanf("%s %s",X,Y);
 
    printf("%d\n",LCS_Length(X,Y));
   
}
  
  
  return 0;
}

int LCS_Length(char X[] ,char Y[]){
  int i,j;
  x = strlen(X);
  y = strlen(Y);
  
  for(i=1;i<=x;i++){
    c[i][0] = 0;
  }
  for(j=0;j<=y;j++){
    c[0][j] = 0;
  }
  
  for(i=1;i<=x;i++){
    for(j=1;j<=y;j++){
      if(X[i-1]==Y[j-1]){
	c[i][j]=c[i-1][j-1]+1;
      }
      else if(c[i-1][j]>=c[i][j-1]){
	c[i][j]=c[i-1][j];
      }
      else{
	c[i][j]=c[i][j-1];
      }
    }
  }
  return c[x][y];
}

Measured memory_bytes: 4524
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    vector<int> a(3);
    in_arr(int, a, 3);
    sort(a.begin(), a.end());
    cout << a[2] - a[0] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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; }

long long a[300300];

int main() {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < 3*N; ++i) {
    scanf("%lld", &a[i]);
  }

  sort(a,a+3*N,greater<long long>());

  long long sum = 0;
  for(int i = 1; i<=2*N-1; i+=2){
    sum += a[i];
  }

  cout << sum << endl;

}



Measured memory_bytes: 2688
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include <utility>      // std::swap
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 200000000000;


    ll W,H,N,M;
    ll sum;
    ll ans=0;
    ll sm,lr;
    ll A[1100];
    ll C[10];
    bool f=false;
int main(){
    ios_base::sync_with_stdio(false);
    cin>>N>>M;
    if(abs(N-M)>1)ans=0;
    else if(N==M){
        ans=1;
        EREP(i,N){
            ans*=(i%MOD);
            ans%=MOD;
        }
        ans=(((ans*ans)%MOD)*2)%MOD;
    }else{
        if(N>M)swap(N,M);
        ans=1;
        EREP(i,N){
            ans*=(i%MOD);
            ans%=MOD;
        }
        ll mq=(ans*M)%MOD;
        ans=(ans*mq)%MOD;
    }


    cout<<ans;
    return 0;
}


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

using namespace std;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		vector<int> d(n, 0);
		for (int i = 1; i < n; i++) {
			d[i] = d[i - 1] + i;
		}
		int ans = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 2; j < n; j++) {
				if (d[j] - d[i] == n) {
					ans++;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

long long MAX_N = 1000000000000001;
long MAX_idx = MAX_N / 26;

int main()
{
    vector<int> c;
    string s = "";
    long long N;
    int res;
    int order = 0;
    cin >> N;
    N -= 1;
    while(true) {
        res =  N % 26;
        c.push_back(res);
        if (N < 26) break;
        N /= 26;
        N -= 1;
        order += 1;
    }
    reverse(begin(c), end(c));
    for (char v: c) {
        cout << (char)('a' + v);
    }
    cout << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define PI acos(-1)
#define sz 18500000
#define RUN_FAST ios::sync_with_stdio(false);
using namespace std;

int main()
{
    RUN_FAST; cin.tie(nullptr);
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    cout << s1[0] << s2[1] << s3[2] << endl;
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
char s[SIZE];
int main(){
   RS(s);
 set<char>H;
 for(int i=0;s[i];i++)H.insert(s[i]);
 if(H.count('W')^H.count('E'))puts("No");
 else if(H.count('S')^H.count('N'))puts("No"); 
 else puts("Yes");
 return 0;
}

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

int main()
{
	int N, T, t[200000],j,sum=0;
	cin >> N>>T;
	for (int i = 0; i < N; i++)
	{
		cin >> t[i];
	}
	for (int i = 1; i < N; i++)
	{
		j = t[i-1]+T;
		if (j > t[i])
			sum += t[i] - t[i - 1];
		else
			sum += T;
	}
	sum += T;
	cout << sum;
	return 0;
}

Measured memory_bytes: 1024
H,W = map(int,(input().split()))
a = [[] for _ in range(H)]
b = []
deh = []
for i in range(H):
    a[i] = list(input())
    
for i in range(H):
    if a[i] != ["."]*W:
        b.append(a[i])

for i in range(W)[::-1]:
    c = 0
    for j in range(len(b)):
        if b[j][i] == ".":
            c += 1
    if c == len(b):
        for j in range(len(b)):
            b[j].pop(i)

for i in range(len(b)):
    ans = "".join(b[i])
    print(ans)

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

int main(){

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

  int cnt = 0;
  for(int x = a; x <= b; x++){
    if(c % x == 0) cnt++;
  }
  cout<<cnt<<endl;
  
   return 0;
}


Measured memory_bytes: 3100
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def main():
    x = [y for y in map(int,input().split())]
    x.sort()
    if x[0]+x[1]==x[2]:
        print("Yes")
    else:
        print("No")
    return

if __name__=='__main__':
    main()

Measured memory_bytes: 38636
/**
*   @author: Kshitiz Srivastava (Pirate_ksh) @ MNNIT Allahabad
*   @note: To read about Matrix Exponentiation: https://www.hackerearth.com/practice/notes/matrix-exponentiation-1/
*/
#include<bits/stdc++.h>
using namespace std;
 
// General
#define ll long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define mod_ 998244353 
#define endl "\n"
#define debug(x) cout<<x<<endl
#define REP(i,n) for(i=0;i<n;++i)
#define FOR(i,x,n) for(i=x;i<n;++i)
 
// Bounds
#define lb(a, x) a.lower_bound(x)
#define ub(a, x) a.upper_bound(x)
#define all(a) a.begin(),a.end()
 
// Vector
#define vi vector <int>
#define pb(v, x) v.push_back(x)
#define vsi vector <set <int> >
 
// Map
#define mii map <int, int>
 
// Set
#define si set <int>
 
// Pair
#define vpii vector<pair < int, int > >
#define pii pair < int, int >
#define mp(a,b) make_pair(a,b)
#define F first
#define S second

ll dp[405][405], a[405], N, actu[405][405];
pair<ll,ll> DP(ll i, ll j) {
    if(i >= j) {
        dp[i][j] = actu[i][j] = a[i];
        return mp(a[i],a[i]);
    }
    if(dp[i][j] != -1) return mp(dp[i][j],actu[i][j]);
    pair<ll,ll> ans = mp((ll)1e18,0);
    for(ll k=i;k<j;++k) {
        pair<ll,ll> p1 = DP(i,k);
        pair<ll,ll> p2 = DP(k+1,j);
        pair<ll,ll> temp_ans = mp(p1.F+p2.F+p1.S+p2.S, p1.S+p2.S);
        if(ans.F > temp_ans.F) ans = temp_ans;
    }
    dp[i][j] = ans.F;
    actu[i][j] = ans.S;
    return ans;
}


int main(){
    io
    ll t;
    t = 1;
    // cin >> t;
    while(t--) {
        cin >> N;
        ll it;
        REP(it,N) cin >> a[it];
        memset(dp, -1, sizeof(dp));
        pair<ll,ll> FIN = DP(0,N-1);
        cout << FIN.F - FIN.S << endl;
    }
    return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll ans[333][333];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll h,w,k;cin>>h>>w>>k;
  string ma[h+10];
  ll cnt=0;
  ll hoge=1;
  for(int i=0;i<h;i++){
    cin>>ma[i];
    ll mae=0;
    bool fl=false;
    for(int j=0;j<w;j++){
      //cout<<j<<endl;
      if(ma[i][j] == '#'){
	fl=true;
	ll cncn=0;
	for(int k=mae;k<w;k++){
	  //cout<<"!"<<k<<endl;
	  if(ma[i][k] == '#'){cncn++;}
	  if(cncn == 2){mae=k;break;}
	  //else if(mae==0&&ma[i][k]=='#'){mae=1;}
	  ans[i][k]=hoge;
	  //cout<<cnt<<"!!!!!"<<endl;
	  for(int l=0;l<cnt;l++){
	    ans[i-l-1][k]=hoge;
	  }
	  // cout<<"!!!"<<endl;
	}
	hoge++;
      }
    }
    if(fl==false)cnt++;
    else cnt=0;
  }
  for(int i=0;i<cnt;i++){
    for(int j=0;j<w;j++){
      ans[h-1-i][j]=ans[h-1-cnt][j];
    }
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cout<<ans[i][j]<<" ";
    }
    cout<<endl;
  }
  
  return 0;
}


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

string n;

int digitsum(string x){
	int ret = 0;
	rep(i, x.size()) ret += (x[i]-'0');
	return ret;
}

int maxsum(string x){
	int m = x.size();
	if(m == 1) return x[0]-'0';
	int p = x[0]-'0';
	int d = 9*(x.size()-1);
	return max(p+maxsum(x.substr(1)), p-1+d);
}

int main(void){
	cin >> n;
	cout << maxsum(n) << endl;
	return 0;
}


Measured memory_bytes: 3572
import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        if(a*b == c*d){
            System.out.println(a*b);
            return;
        }
        if(a*b > c*d){
            System.out.println(a*b);
        }else{
            System.out.println(c*d);
        }
    
    }
}

Measured memory_bytes: 21972
K, N = map(int, input().split())
A = list(map(int, input().split()))

B = [None] * N


for i in range(0, N):
    if i == N-1:
        B[i] = K - A[i] + A[0]
    else:
        B[i] = abs(A[i] - A[i+1])

print(sum(B) - max(B))


Measured memory_bytes: 25836
import sys
tmp = input()
a = int(tmp[0])
b = int(tmp[1])
c = int(tmp[2])
d = int(tmp[3])
def tonum(a, n):
    if (a == 0):
        return n
    else:
        return - 1 * n
def operand(n):
    if (n == 0):
        return '+'
    else:
        return '-'

def format(a, b, c, d, ab, bc, cd):
    string = str(a) + operand(ab) + str(b) + operand(bc) + str(c) + operand(cd) + str(d)+'=7'
    return string
tmp=0
for i in range(2):
    for j in range(2):
        for k in range(2):
                tmp = a+tonum(i, b)+tonum(j, c)+tonum(k,d)
                if (tmp == 7):
                    print(format(a, b, c, d, i, j, k))
                    sys.exit()


Measured memory_bytes: 3064
n = int(input())
A = list(map(int, input().split()))

POINT = 0
for i in A:
    if i % 2 == 0:
        if i % 3 != 0 and i % 10 != 0:
            POINT = 1
if POINT == 1:
  print("DENIED")
else:
  print("APPROVED")


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

int main(){
   long long int h,a,s=0,b,l,k;
   cin>>h>>a;

   long long int arr[h];

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

   sort(arr,arr+h);

   if(a>=h)
    cout<<0<<endl;

   else{
      l=h-a;
      s=0;
      k=0;
      for(int i=0;i<l;i++){
         s+=arr[i];
      }

      cout<<s<<endl;
   }


}


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

int main() {
  vector<int> vec(5);
  for (int i = 0; i < 5; i++) {
    cin >> vec.at(i);
  }
  int sum = 0;
  for (int j : vec ) {
    sum += j;
  }
  cout << 15 - sum << endl;
}


Measured memory_bytes: 3484
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

int main(void){
	int n,val[3];

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

		for(int j=0;j<2;j++)
	        	for(int k=0;k<2-j;k++)
        			if(val[k]>val[k+1]){
                			int tmp = val[k];
                			val[k]=val[k+1];
                			val[k+1]=tmp;
				}
		string str = (pow(val[0],2.0)+pow(val[1],2.0)==pow(val[2],2.0))?"YES":"NO";
		cout << str << endl;
	}

	return 0;
}

Measured memory_bytes: 1196
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -std=c++11 */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int gcd(const int a, const int b)
{   return b == 0 ? a : gcd(b,a%b); }

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    int n,m; string s,t;
    while (cin >> n >> m >> s >> t) {
        const int g = gcd(n,m);
        LL i = 1;
        map<LL,char> A,B;
        FOR_ALL(ch,s) {
            A[i] = *ch; i += m/g;
        }
        i = 1;
        FOR_ALL(ch,t) {
            B[i] = *ch; i += n/g;
        }
        bool good = true;
        FOR_ALL(a,A) {
            const LL k = a->first;
            if (in_(k,B) && B[k] != A[k])
                good = false;
        }
        LL ans = -1;
        if (good) {
            ans = 1LL*n/g*m;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 10880
const main = stdin => {
  const input = stdin.trim().split('\n')
  const [A, B] = input[0].split(' ')
  const S = input[1]
  const pattern = new RegExp('\\d{' + A + '}' + '-' + '\\d{' + B + '}', 'g')

  if (S.match(pattern)) {
    console.log('Yes')
  } else {
    console.log('No')
  }
}


// 標準入力
main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 29496
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (long long i = 0; i < (n); ++i)
#define rep(i, a, b) for (long long i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

typedef long long ll;
const ll MOD = 1'000'000'007;
ll mod_powe(ll x, ll n, ll mod)
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
int main(void)
{
    ll n, k;
    ll ans = 0;

    cin >> n >> k;

    map<ll, ll> mp;
    // gcd が 1 ~ k のものを全部合算する
    // gcdがkのもの (k / i) ^ n 個存在する
    for (ll i = k; i >= 1; i--)
    {
        ll tmp = 1;
        /*
        REP(j, n)
        {
            tmp = (tmp * (k / i)) % MOD;
        }
        */
        tmp = mod_powe(k / i, n, MOD);

        // x
        mp[i] = tmp;
        // - 2x - 3x ...
        for (ll j = i * 2; j <= k; j += i)
        {
            if (mp.count(j) > 0)
            {
                mp[i] = (mp[i] + MOD - mp[j]) % MOD;
            }
        }

        ans = (ans + mp[i] * i) % MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 9772
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

int main(void){
	int N, M;
	cin >> N >> M;
	vector<pair<int, int>> pairs(N);
	for(int nIndex = 0; nIndex < N; ++nIndex){
		int A, B;
		cin >> A >> B;
		pairs[nIndex] = make_pair(A, B);
	}
	sort(pairs.begin(), pairs.end());

	long long result = 0;
	for(int nIndex = 0; nIndex < N && M > 0; ++nIndex){
		if(pairs[nIndex].second > M){
			result += (long long)pairs[nIndex].first * M;
			break;
		}else{
			M -= pairs[nIndex].second;
			result += (long long)pairs[nIndex].first * pairs[nIndex].second;
		}
	}

	cout << result << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  string s;
  ll z=0,o=0;
  cin>>s;
  for(ll i=0;i<s.size();i++){if(s[i]=='0')z++;else o++;}
  cout<<min(o,z)*2<<endl;
}


Measured memory_bytes: 512
import sys

def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    S = sum(A)
    divs = set()
    for d in range(1, int(S**(0.5) + 1)):
        if S % d != 0:
            continue
        divs.add(d)
        divs.add(S // d)

    ans = 0
    cost = 0
    for d in divs:
        mods = []
        for a in A:
            mods.append(a % d)
        mods.sort()
        total = sum(mods)
        sub = 0
        for i, m in enumerate(mods, start=1):
            sub += m
            add = d*(N-i) - (total - sub)
            if add == sub:
                cost = sub
                break     
        if cost <= K:
            ans = max(ans, d)

    return ans


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int num1 = Integer.parseInt(s.next());
		int num2 = Integer.parseInt(s.next());
		int sub;
		
		if(num2 > num1){
			sub = num2;
			num2 = num1;
			num1 = sub;
		}
		
		while(num1 != num2){
			sub = num1;
			num1 = Math.max(num1 - num2, num2);
			num2 = Math.min(sub - num2, num2);
		}
		
		System.out.println(num1);
		
	}

}

Measured memory_bytes: 26144
class Main{
  public static void main(String[]z){
    int t=0,u=0,i=0,j=0;
    Scanner x=new Scanner(System.in);
    for(;x.hasNext();t=u=i=j=0){
      String s=x.nextLine();
      for(;(t=s.indexOf("IOI",t))!=-1;t+=2)i++;
      for(;(u=s.indexOf("JOI",u))!=-1;u+=3)j++;
      System.out.println(j+"\n"+i);
    }
  }
}

Measured memory_bytes: 12000
#include<iostream>
using namespace std;
#define MAX 100000

int parent(int i) { return i / 2; }
int left(int i) { return 2 * i; }
int right(int i) { return 2 * i + 1; }


int main() {

	int H, i, A[MAX + 1];

	cin >> H;

	for (i = 1; i <= H; i++)cin >> A[i];

	for (i = 1; i <= H; i++) {
		cout << "node " << i << ": key = " << A[i] << ", ";
		if (parent(i) >= 1)cout << "parent key = " << A[parent(i)] << ", ";
		if (left(i) <= H)cout << "left key = " << A[left(i)] << ", ";
		if (right(i) <= H)cout << "right key = " << A[right(i)] << ", ";
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3092
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)

const ll INF =0xfffffffffffffff;
struct T{
	ll val,min,max;
};

T dp[2][1001];//
T (*prv);
T (*nxt);
ll N,M,K;
ll A[20001];
ll valmin[20001];

int main()
{
	scanf("%lld%lld%lld",&N,&M,&K);
	rep(i,N) scanf("%lld",&A[i]);
	fill(dp[0],dp[2],T{INF,INF,-INF});
	prv=dp[0];
	nxt=dp[1];
	prv[1]=T{K,A[0],A[0]};
	valmin[0]=K;
	rep(i,N-1){
		rep(j,M+1) nxt[j]=T{INF,INF,-INF};
		valmin[i+1]=nxt[1].val=valmin[i]+K;
		nxt[1].min=nxt[1].max=A[i+1];
		
		rep1(j,M-1){
			if(prv[j].val==INF) continue;
			nxt[j+1]=prv[j];
			if(prv[j].min<=A[i+1]&&A[i+1]<=prv[j].max){
				nxt[j+1].val+=(nxt[j+1].max-nxt[j+1].min);
			}
			else if(prv[j].max<A[i+1]){
				nxt[j+1].max=A[i+1];
				nxt[j+1].val+=(A[i+1]-prv[j].max)*j;
				nxt[j+1].val+=(nxt[j+1].max-nxt[j+1].min);
			}
			else{
				nxt[j+1].min=A[i+1];
				nxt[j+1].val+=(prv[j].min-A[i+1])*j;
				nxt[j+1].val+=(nxt[j+1].max-nxt[j+1].min);
			}
			valmin[i+1]=min(valmin[i+1],nxt[j+1].val);
		}
		swap(nxt,prv);
	}
	printf("%lld\n",valmin[N-1]);
}

Measured memory_bytes: 3576
from math import log,ceil
N=int(input())
A=list(map(int,input().split()))
inf=float("inf")
p=[0]*(N+1)
n=[0]*(N+1)
Stack_p=[(-inf,N-1)]
Stack_n=[(-inf,0)]
for i in range(N-1)[::-1]:
  k=ceil(log(A[i]/A[i+1],4))
  p[i]=p[i+1]
  t=i
  if k>=1:
    while k>0:
      #print(Stack_p,k,t,p)
      s,m=Stack_p.pop()
      p[i]+=k*(m-t)
      if k+s>=0:
        k+=s
        t=m
      else:
        Stack_p.append((k+s,m))   
        k=0
  elif k<0:
    Stack_p.append((k,i))
for i in range(2,N+1):
  k=ceil(log(A[i-1]/A[i-2],4))
  n[i]=n[i-1]
  t=i-1
  if k>=1:
    while k>0:
     # print(Stack_n,k,t,n)
      s,m=Stack_n.pop()
     # print(s,m)
      n[i]+=k*(t-m)
      t=m
      if k+s>=0:
        k+=s
      elif k+s<0:
        Stack_n.append((k+s,m))  
        k=0
     # print(Stack_n)
  elif k<0:
    Stack_n.append((k,i-1))
#print(p)
#print(n)
ans=inf
for i in range(N+1):
  ans=min(ans,i+2*n[i]+2*p[i])
print(ans)

Measured memory_bytes: 117428
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<iomanip>
#include<string>
#include<algorithm>
#include<numeric>
#include<utility>
#define ll long long int
#define ss string
#define endl "\n"
using namespace std;
int main()
{
  int s,w;
  cin>>s>>w;
  if(w>=s)
    cout<<"unsafe";
  else
    cout<<"safe";

  return 0;
}


Measured memory_bytes: 3640
// code.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
ll n,k,val,ans;
cin>>n>>k;
vector<ll> a;
for(int i=0; i<n; i++){
	cin>>val;
	a.push_back(val);
}
if(k>=a.size()){
	cout<<"0";
}
else{

sort(a.begin(),a.end());
ll sum =0;
int q = n-k;
for(int i=0; i<q; i++){
	sum = sum+a[i];
}
cout<<sum;
}
}
	


Measured memory_bytes: 2420
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] strArgs) throws Exception {
		BufferedReader br = null;

		try {
			br = new BufferedReader(new InputStreamReader(System.in));

			String[] strValues = readValues(br);
			int waribikiCount = toInt(strValues[2]);

			String[] strReizoukoPrices = readValues(br);
			String[] strRangePrices = readValues(br);

			int iReizoukoMin = Integer.MAX_VALUE;
			int iRangeMin = Integer.MAX_VALUE;
			for (String strReizouko : strReizoukoPrices) {
				iReizoukoMin = Math.min(iReizoukoMin, toInt(strReizouko));
			}
			for (String strRange : strRangePrices) {
				iRangeMin = Math.min(iRangeMin, toInt(strRange));
			}

			int iMinPrices = Integer.MAX_VALUE;
			for (int i = 0; i < waribikiCount; i++) {
				String[] strWaribikiPairs = readValues(br);

				iMinPrices = Math.min(iMinPrices, toInt(strReizoukoPrices[toInt(strWaribikiPairs[0]) - 1])
												+ toInt(strRangePrices[toInt(strWaribikiPairs[1]) - 1])
												- toInt(strWaribikiPairs[2]));
			}

			iMinPrices = Math.min(iMinPrices, iReizoukoMin + iRangeMin);

			System.out.println(iMinPrices);

		} finally {
			br.close();
		}
	}

	private static String[] readValues(BufferedReader br) throws IOException {
		return br.readLine().split("\\s");
	}

	private static int toInt(String str) {
		return Integer.parseInt(str);
	}
}


Measured memory_bytes: 78624
import sys
input = sys.stdin.readline
inf = float('inf')
mod = 10**9+7


def INT_(n): return int(n)-1


def MI(): return map(int, input().split())


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [input() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')


def main():
    import heapq
    N, Q = MI()
    event = []
    for _ in range(N):
        s, t, x = MI()
        event.append((s - x-0.5, 1, x))
        event.append((t - x-0.5, -1, x))

    for _ in range(Q):
        d = I()
        event.append((d, 0))

    event.sort(key=lambda x: x[0])
    occur = set()
    occur_priority = []
    for e in event:
        if e[1] == 1:
            occur.add(e[2])
            heapq.heappush(occur_priority, e[2])
        elif e[1] == -1:
            if e[2] in occur:
                occur.remove(e[2])
        # クエリ
        elif e[1] == 0:
            if occur:
                while 1:
                    if occur_priority[0] in occur:
                        min_occur = occur_priority[0]
                        break
                    else:
                        heapq.heappop(occur_priority)
                print(min_occur)
            else:
                print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 126940
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<string > vecstr;
int main()
{
  int n, m;
  cin >> n >> m;
  vecint s(n + 1, -1);
  int ts, tc;
  if(m == 0){
    if(n == 1){
      cout << "0" << endl;
    }else{
      cout << pow(10,n -1) << endl;
    }
    return 0;
  }

  //n == 0
  bool ok = true;
  // if(n == 0){
  //   REP(i,m){
  //     cin >> ts >> tc;
  //     if(tc != 0){
  // 	ok = false;
  //     }
  //   }
  //   if(ok){
  //     cout << "0" << endl;
  //   }else{
  //     cout << "-1" << endl;
  //   }
  //   return 0;
  // }
  // //n == 0


  //n != 0
  REP(i,m){
    cin >> ts >> tc;
    if(s[ts] != -1){
      if(s[ts] != tc){
	ok = false;
      }
    }
    s[ts] = tc;
  }
  if(n == 1){
    if(ok){
      cout << s[1] << endl;
    }else{
      cout << "-1" << endl;
    }
    return 0;
  }
  if(s[1] == 0){
    ok = false;
  }
  if(!ok){
    cout << "-1" << endl;
    return 0;
  }
  //n != 0
  if(s[1] == -1){
    s[1] = 1;
  }
  for(int i = 2; i <= n; i ++ ){
    if(s[i] == -1)s[i] = 0;
  }
  for(int i = 1; i <= n; i ++ ){
    cout << s[i];
  }
  cout << endl;


}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		// 文字列入力strLine
		String strLine = scanner.next();
		// 命令回数intCommand
		int intCount = scanner.nextInt();

		for (int intI = 0; intI < intCount; intI++) {
			// 命令strCommand入力
			String strCommand = scanner.next();
			// 各条件で処理
			if (("print").equals(strCommand)) {
				int intBegin = scanner.nextInt();
				int intEnd = scanner.nextInt();
				System.out.println(strLine.substring(intBegin, intEnd + 1));

			} else if (("reverse").equals(strCommand)) {
				int intBegin = scanner.nextInt();
				int intEnd = scanner.nextInt();
				// 指定部分を切り抜き反転し置換
				StringBuilder strReverse = new StringBuilder(strLine.substring(intBegin, intEnd + 1));
				strReverse.reverse();
				StringBuilder strReLine = new StringBuilder(strLine);
				strReLine.replace(intBegin, intEnd + 1, strReverse.toString());
				// strLineを上書き
				strLine = strReLine.toString();

			} else if (("replace").equals(strCommand)) {
				int intBegin = scanner.nextInt();
				int intEnd = scanner.nextInt();
				// 置換する文字列strReplace読み込み
				String strReplace = scanner.next();
				StringBuilder strReLine = new StringBuilder(strLine);
				// intBegin～intEnd文字目をstrReplaceに置換
				strReLine.replace(intBegin, intEnd + 1, strReplace);
				// strLineにstrReLineで上書き
				strLine = strReLine.toString();
			}
		}
	}
}



Measured memory_bytes: 29648
//{$R-,Q-,S-,I-}
{$OPTIMIZATION LEVEL2}
{$INLINE ON}

uses math;

procedure mofile;
begin
        {$IFDEF ONLINE_JUDGE}
        assign(input,'');
        reset(input);
        assign(output,'');
        rewrite(output);
        {$ELSE}
        assign(input,'checking.inp');
        reset(input);
        assign(output,'');
        rewrite(output);
        {$ENDIF}
end;

procedure dongfile;
begin
        close(input);
        close(output);
end;

const
        maxc=1000000000+69;
        modulo=1000000000+7;
        maxn=400000+10;

type
        re=record
                x,y:longint;
        end;

var
        n,q,dem,res:longint;
        s:array[0..maxn] of ansistring;
        a,c:array[0..maxn*4,'`'..'z'] of longint;
        cnt:array[0..maxn,'`'..'z','`'..'z'] of longint;
        al:ansistring;

procedure insert(p,x,i:longint);
begin
        if x=length(s[i])+1 then exit;
        inc(c[p][s[i,x]]);
        if a[p][s[i,x]]>0 then insert(a[p][s[i,x]],x+1,i) else
        begin
                inc(dem);
                a[p][s[i,x]]:=dem;
                insert(dem,x+1,i);
        end;
end;

procedure nhapdl;
var
        i:longint;
begin
        readln(n);
        for i:=1 to n do
        begin
                readln(s[i]);
                s[i]:=s[i]+'`';
                insert(0,1,i);
        end;
end;

procedure dfs(p,x,i:longint);
var
        j:char;
begin
        if x=length(s[i])+1 then exit;
        for j:='`' to 'z' do
        begin
                inc(cnt[i,j,s[i,x]],c[p,j]);
        end;
        dfs(a[p][s[i,x]],x+1,i);
end;

procedure xuli;
var
        o,i,j,x:longint;
        blank:char;
begin
        for i:=1 to n do dfs(0,1,i);
        readln(q);
        for o:=1 to q do
        begin
                readln(x,blank,al);
                al:='`'+al;

                res:=0;
                for i:=1 to 26 do
                for j:=i+1 to 27 do
                res:=res+cnt[x,al[i],al[j]];

                writeln(res+1);
        end;
end;

begin
        //mofile;
        nhapdl;
        xuli;
        dongfile;
end.














Measured memory_bytes: 360704
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i > 0; i--)
#define repc(i, m, n) for (int i = m; i < n; i++)
#define reprc(i, m, n) for (int i = m; i > n; i--)
#define all(v) v.begin(), v.end()
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

int main()
{
    int K;
    string S,A;
    cin >> K;
    cin >> S;

    if(S.size() > K){
        A = S.substr(0, K) + "...";
        cout << A << endl;
    }else{
        cout << S << endl;
    }
}

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

using namespace std;

int main(){
   int X, N;
   cin >> X >> N;
   int p[N];
   for (int i = 0; i < N; i++) {
      cin >> p[i];
   }
   int ans = 0;
   int diff = INT_MAX;
   for(int i = -1000; i <= 1000; i++){
      bool ok = true;
      for(int j=0;j<N;j++){
         if(p[j]==i){
            ok = false;
            break;
         }
      }
      if(ok&&diff > abs(i-X)){
         diff = abs(i-X);
         ans = i;
      }
   }
   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 3672
from math import gcd

N = int(input())
A = list(map(int, input().split()))
MAX = 10**6 + 1

def prime_factor_sieve(n):
    """
    エラトステネスの篩で、
    2 ~ Nの各数に対して、その整数のもつ最小の素因数
    (その整数を篩落とした最小の素因数)を記録して返す
    O(nloglog(n))
    """
    res = [i for i in range(n+1)]
    for i in range(2, int(n**0.5)+1):
        if res[i] < i:
            continue
        for j in range(i*i, n+1, i):
            if res[j] == j:
                res[j] = i
    return res

def factorization(n, min_factor, used_factor, cnt):
    """
    エラトステネスの篩で手に入れた、各整数の最小素因数のリスト
    からO(log(n))で素因数分解する
    """
    
    while n > 1:
        if used_factor[min_factor[n]] == 0:
            used_factor[min_factor[n]] = cnt
        elif used_factor[min_factor[n]] != cnt:
            return False
        n //= min_factor[n]
        # 割った後の素因数についてもO(1)で参照できる
    return True


# 素因数が重複しているかを調べる
min_factor = prime_factor_sieve(MAX)
res = set()
is_ok = 1
used_factor = [0]*(MAX+1)
cnt = 1
for a in A:
    if a == 1:
        continue
    is_ok = factorization(a, min_factor, used_factor, cnt)
    cnt += 1
    if not is_ok:
        break

if is_ok:
    print("pairwise coprime")
else:
    g = A[0]
    for i in range(1, N):
        g = gcd(g, A[i])
    if g == 1:
        print("setwise coprime")
    else:
        print("not coprime")

Measured memory_bytes: 223972
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] x = new int[n];
        int[] y = new int[n];
        
        for (int i = 0; i< n; i++) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }
        
        double length = 0;
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j) continue;
                
                length += Math.sqrt(Math.pow(x[i] - x[j], 2) + Math.pow(y[i] - y[j] , 2));
                count++;
            }
        }
        
        length *= n - 1;
        length /= count;
        System.out.println(length);
    }
}


Measured memory_bytes: 21844
/********************************
*** ******** ********** *********
*** * ****** ********* * ********
*** ** ***** ******** *** *******
*** *** **** ******* ***** ******
*** **** *** ****** ******* *****
*** ***** ** ***** +++++++++ ****
*** ****** * **** *********** ***
*** *******  *** ************* **
*** ******** ** *************** *
**********_**********************
* |   /  / \  \     /    /\     *
* |  /  |   |  \   /    /  \    *
* | /   |   |   \ /    /    \   *
* |+\   |   |    |    /______\  *
* |  \  |   |    |   |        | *
* |   \  \_/     |   |        | *
********************************/
#include<bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define KING 1000000002
#define queen 1000002
#define fi first
#define se second
#define se second
#define lsb(i) (i & -i)
#define Pi 3.141592653589793238
#define nl cout<<'\n'
#define TEST cout<<"TEST",nl
#define all(a) a.begin(), a.end()
#define remax(a, b) (a = ((a<b) ? b : a))
#define remin(a, b) (a = ((a<b) ? a : b))
#define pr pair<lli,lli>
#define pb push_back
#define eb emplace_back
#define precise(a) cout<<fixed<<setprecision(a)
#define mp make_pair
#define vi vector<lli>
#define vpi vector<pr> 
#define P pair<lli,pr>
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define NA(i,s,n) for(lli i=s;i<n;i++)
using namespace std;

lli power(lli x,lli y,lli p = (lli)(1e13)) { 
	lli res = 1;	 
	x = x % p; 
	while (y > 0) 
	{ 
		if (y & 1) 
			res = (res*x) % p; 
		y = y>>1; 
		x = (x*x) % p; 
	} 
	return res; 
}

const lli N = 1e5+2;
lli n, a[N], k;

struct cmp{
    bool operator()(const lli &a, const lli &b) {
        return a>b;
    }
};

void solve(){
    lli n; cin >> n;
    lli p = (n/1000) + (n%1000 > 0);
    lli ans = p*1000 - n;
    cout << ans ;
    return;
}

int main(){
    fastIO;
    solve();
	return 0;
}



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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N;
    cin >> N;
    ll num,cnt=1;
    cin >> num;
    ll ans = 0;
    for (int i = 1; i < N; i++) {
        ll a; cin >> a;
        if(num == a){
            cnt++;
        } else {
            if(cnt != 1){
                ans += cnt / 2;
            }
            num = a;
            cnt = 1;
        }
    }
    if(cnt != 1){
        ans += cnt / 2;
    }
    cout << ans << endl;
}

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

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const int inf = 1e9;
const int maxn = 2505;
struct edge { int u,v,c; };
int dist[maxn], vis[maxn];
VI G[maxn]; vector<edge> E;

void dfs(const int u)
{
    vis[u]++;
    FOR_ALL(e,G[u]) {
        const int v = E[*e].v;
        if (!vis[v])
            dfs(v);
    }
}

int bfs(const int n)
{
    memset(vis,0,sizeof(vis));
    FOR(i,1,n+1)
        dist[i] = -inf;
    dist[1] = 0;
    queue<int> Q; Q.push(1); vis[1]++; VI cnt(n+1); cnt[1]++;
    while (Q.size()) {
        const int u = Q.front(); Q.pop(); vis[u] = 0;
        FOR_ALL(e,G[u]) {
            const int v = E[*e].v;
            const int c = E[*e].c;
            const int d = dist[u]+c;
            if (d > dist[v]) {
                dist[v] = d;
                if (!vis[v]) {
                    Q.push(v); vis[v]++; 
                    if (++cnt[v] > n)
                        return -1;                                
                }
            }
        }
    }
    return max(0,dist[n]);
}

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m,p;
    while (cin >> n >> m >> p) {
        FOR(i,1,n+1)
            G[i].clear();
        E.resize(m);
        FOR(i,0,m) {
            int u,v,c; cin >> u >> v >> c;
            E[i].u = u; E[i].v = v; E[i].c = c-p;
            G[u].push_back(i);
        }
        VI good(n+1);
        FOR(i,1,n+1) {
            memset(vis,0,sizeof(vis));
            dfs(i);
            good[i] = vis[n];
        }
        FOR(i,1,n+1)
            G[i].clear();
        FOR(i,0,m) {
            const int u = E[i].u;
            const int v = E[i].v;
            if (good[v])
                G[u].push_back(i);
        }
        cout << bfs(n) << endl;
    }
    return 0;
}


Measured memory_bytes: 512
//code by parshuram_84
#include <bits/stdc++.h>
#define floop(i,a,n) for (int i=a;i<n;i++)
#define pii pair<int,int>
#define pll pair<long long,long long>
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define vvl vector<vector<long long> >
#define vp vector<pair<long long,long long>>
#define vpp vector<pair<pair<long long,long long>,long long>>
#define mp make_pair
#define all(c) c.begin(),c.end()
#define tr(container, it) \
for(typeof(container.begin()) it = container.begin();it != container.end(); it++)
typedef std::numeric_limits< double > dbl;
using namespace std;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll ncr(ll n,ll r) { ll p=1,k=1; if(n-r<r) r=n-r; if(r!=0) {while(r!=0) {p*=n; k*=r; ll temp=gcd(p,k); p/=temp; k/=temp; n--; r--;} } else p=1; return p;}
ll pm(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=((result%mod)*(x%mod))%mod; x=((x%mod)*(x%mod))%mod; n/=2;} return result;}
ll p(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=result*x; x=x*x; n/=2;} return result;}
ll factorial[300000+1];
void fact(ll n) { factorial[0]=1; factorial[1]=1; floop(i,2,n+1) factorial[i] = (i * factorial[i-1]%mod) % mod; }

int32_t main() {
	IOS;
	ll t,i,j,k,n,x,y,z;
	string s;
	cin>>t;
	for(i=0;i<t;i++)
	{
		cout<<"ACL";
	}
	return 0;
}

Measured memory_bytes: 3616