akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;
//using ll=long long;

int main(){
    int A, B, C, K;
    cin >> A >> B >> C;
    cin >> K;
    
    int max3 = max(max(A,B),max(B,C));
    int maxtmp = max3;
    for(int i = 1; i <= K; i++) max3 *= 2;
    
    cout << A + B + C + max3 - maxtmp << endl;
    return 0;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int h, w;
    cin >> h >> w;

    string s;
    for(int ih=0;ih<h;ih++) {
        cin >> s;
        cout << s << endl;
        cout << s << endl;
    }
    return 0;
}



Measured memory_bytes: 3624
h,w=map(int,input().split())
s=[]
for i in range(h):
    s.append(list(input()))
a=0
for i in range(h):
    for j in range(w):
        if s[i][j]=='#':
            a+=1

visited = [[0]*w for _ in range(h)]

def dfs(s,visit,h,w,a):
    stack=[[0,0,1]]
    visit[0][0]=1
    while stack:
        sh,sw,c=stack.pop(0)
        if sh==h-1 and sw==w-1:
            return h*w-a-c
        for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_h, new_w = sh+j, sw+k
            if new_h < 0 or new_h >= h or new_w < 0 or new_w >= w:
                continue
            elif s[new_h][new_w] != "#" and visit[new_h][new_w] == 0:
                visit[new_h][new_w] = 1
                stack.append([new_h,new_w,c+1])
    return -1
  
print(dfs(s,visited,h,w,a))
  
    
        

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
int n,m,px,py,s1[107][107],s2[107][107],s3[107][107];
char s0[107][107];
short f[107][107][107][107],ans=0;
void maxs(short&a,int b){if(a<b)a=b;}
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a>b?a:b;}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i){
		scanf("%s",s0[i]+1);
		for(int j=1;j<=m;++j){
			if(s0[i][j]=='E')px=i,py=j;
			if(s0[i][j]=='o'){
				s1[i][j]=s2[i][j]=s3[i][j]=1;
			}
		}
	}
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			s1[i][j]+=s1[i][j-1];
			s2[i][j]+=s2[i-1][j];
			s3[i][j]=s3[i-1][j]+s1[i][j];
		}
	}
	for(int l=1;l<=n;++l){
		for(int r=n,xl,xr;r>=l;--r){
			xl=max(l,px-(n-r));
			xr=min(r,px+(l-1));
			if(xl>xr)continue;
			for(int u=1;u<=m;++u){
				for(int d=m,xu,xd,v;d>=u;--d){
					xu=max(u,py-(m-d));
					xd=min(d,py+(u-1));
					if(xu>xd)continue;
					v=f[l][r][u][d];
//					printf("[%d,%d][%d,%d] [%d,%d][%d,%d] %d\n",l,r,u,d,xl,xr,xu,xd,v);
					maxs(ans,v+s3[xr][xd]+s3[xl-1][xu-1]-s3[xr][xu-1]-s3[xl-1][xd]);
					maxs(f[l+1][r][u][d],(l==xl?s1[xl][xd]-s1[xl][xu-1]+v:v));
					maxs(f[l][r-1][u][d],(r==xr?s1[xr][xd]-s1[xr][xu-1]+v:v));
					maxs(f[l][r][u+1][d],(u==xu?s2[xr][xu]-s2[xl-1][xu]+v:v));
					maxs(f[l][r][u][d-1],(d==xd?s2[xr][xd]-s2[xl-1][xd]+v:v));
				}
			}
		}
	}
	printf("%d\n",(int)ans);
	return 0;
}

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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
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; }

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


int main() {
    cout<<fixed<<setprecision(10);

    ll x,k,d; cin>>x>>k>>d;
    if(x < 0) x*=-1;

    // if(x - k*d <= 0){
    if(x/d - k <= 0){
        ll cnt = x/d;
        ll res = k - cnt;
        x -= cnt*d;
        if(res%2 == 0){
            cout<<abs(x)<<endl;
        }else{
            cout<<abs(x-d)<<endl;
        }

    }else{
        cout<< abs(x - d*k) << endl;
    }

    return 0;

}

Measured memory_bytes: 3616
#include<stdio.h>

main(){

int i,x,y,z,m,c;

scanf("%d %d %d",&x,&y,&z);

 for(i=x;i<=y;i++){
 m = 0;
 m = z % i;

  if(m == 0){
  c = c + 1;
  }
  
 }

printf("%d\n",c);

return 0;
}


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

int main(){
  int n;
  cin >>n;
  if(n%10==3) cout << "bon" << endl;
  else if(n%10==0 || n%10==1 || n%10==6 || n%10==8) cout << "pon" << endl;
  else cout << "hon" << endl;
  return 0;
}

Measured memory_bytes: 3560
#include<stdio.h>
#include<string.h>
char name[50];
int name_len;
char t[200];
int t_len;
int n,ans=0;
 
int check(int a,int b){
  int i;
  for(i=0;i<name_len;i++){
    if(a+b*i>=t_len || t[a+b*i]!=name[i]){
      return 0;
    }
  }
  return 1;
}
 
int solve(){
  scanf("%s",t);
  t_len=strlen(t);
  int i,j;
  for(i=0;i<t_len;i++){
    for(j=1;j<t_len;j++){
      if(check(i,j)==1){
        return 1;
      }
    }
  }
  return 0;
}
 
int main(){
  int i;
  scanf("%d",&n);
  scanf("%s",&name);
  name_len=strlen(name);
  for(i=0;i<n;i++){
    ans+=solve();
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 600
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        Integer[] h = new Integer[n];
        Arrays.setAll(h, i -> Integer.parseInt(sc.next()));

        Map<Integer, Set<Integer>> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            map.put(i, new HashSet<>());
        }
        for (int i = 0; i < m; i++) {
            int a = Integer.parseInt(sc.next()) - 1;
            int b = Integer.parseInt(sc.next()) - 1;
            map.get(a).add(h[b]);
            map.get(b).add(h[a]);
        }
        sc.close();

        // 主処理
        int result = 0;
        for (int i = 0; i < n; i++) {
            boolean isGood = true;
            for (int height : map.get(i)) {
                if (h[i] <= height) {
                    isGood = false;
                    break;
                }
            }
            if (isGood) {
                result++;
            }
        }

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 89236
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORe(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    
    int n,x; cin >> n >> x;
    VI m(n); VIin(m);
    SORT(m);
    int ans = n;
    rep(i,n) x -= m[i];
    ans += x/m[0];
    ANS;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define endl  "\n"
#define ll long long
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);cout.tie(NULL);
using namespace std;
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}
int n;
int a[100050],b[100050],c[100050];
int dp[100050][3];

int f(int i,char x)
{
	if(i==n)
	return 0;
	
	if(dp[i][x-48]!=-1)
	return dp[i][x-48];
	
	int inc=0,exc=0;
	if(x=='a')
	{
		inc+=b[i]+f(i+1,'b');
		exc+=c[i]+f(i+1,'c');
	}
	else if(x=='b')
	{
		inc+=a[i]+f(i+1,'a');
		exc+=c[i]+f(i+1,'c');
	}
	else
	{
		inc+=a[i]+f(i+1,'a');
		exc+=b[i]+f(i+1,'b');
	}
	
	return dp[i][x-48] = max(inc,exc);
}

int32_t main()
{
	int t;
	t=1;
	while(t--)
	{
		memset(dp,-1,sizeof(dp));
		cin >> n;
		for(int i=0;i<n;i++)
		{
			cin >> a[i] >> b[i] >> c[i];
		}
		int mx=0;
		mx=max(mx,a[0]+f(1,'a'));
		mx=max(mx,b[0]+f(1,'b'));
		mx=max(mx,c[0]+f(1,'c'));
		
		cout << mx;
	}
}




Measured memory_bytes: 14536
#include <iostream>

using namespace std;

int main()
{
    string s, ans = "None", alp = "abcdefghijklmnopqrstuvwxyz";
    cin >> s;

    for (int i = 0; i < 26; ++i) {
        for (int j = 0; j < s.size(); ++j) {
            if (alp[i] == s[j]) {
                break;
            } else if (j == s.size() - 1) {
                ans = alp[i];
                cout << ans << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x,y,z;
  int ans=0;
  cin >> x >> y >> z;
  x-=z*2;
  while(1){
    x-=y;
    if(x>=0){
      ans++;
    }else{
      break;
    }
    x-=z;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int i, N, a[200001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(a[i]));
	
	int j, k, l, r, p[200001][2], past[200001][2];
	for (i = 1, k = 1, past[0][0] = 0, past[0][1] = 0; i <= N; i++) {
		l = 1;
		r = k;
		while (l < r) {
			if (past[(l+r)/2][0] > a[i]) r = (l + r) / 2;
			else l = (l + r) / 2 + 1;
		}
		p[i][0] = past[l-1][1];
		past[l][0] = a[i];
		past[l][1] = i;
		k = l + 1;
	}
	for (i = N, k = 1, past[0][0] = 0, past[0][1] = N + 1; i >= 1; i--) {
		l = 1;
		r = k;
		while (l < r) {
			if (past[(l+r)/2][0] > a[i]) r = (l + r) / 2;
			else l = (l + r) / 2 + 1;
		}
		p[i][1] = past[l-1][1];
		past[l][0] = a[i];
		past[l][1] = i;
		k = l + 1;
	}

	long long ans = 0;
	for (i = 1; i <= N; i++) ans += (long long)(i - p[i][0]) * (p[i][1] - i) * a[i];	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

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

int main(){
    long long N,n,num(1),ans(0);
    cin >> N;
    vector<long long> v;
    for(int j=0;j<N;j++){
        cin >> n;
        v.push_back(n);
    }
    for(int j=0;j<N;j++){
        ans+=v[j]-1;
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_set>
#include <random>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N; cin >> N;
	vector<int> v(N);
	for (int i = 0; i < N; i++) cin >> v[i];

	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (i % 2 == 0 && v[i] % 2 == 1) ans++;
	}
	cout << ans << '\n';
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double K;
typedef pair<int, int> pii;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()

const int inf = 2000000000;

main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    string s; 
    cin >> s; 
    int n = s.length(); 
    
    int a[2019];
    memset(a, 0, sizeof(a));
    
    a[0] = 1;
    int val = 0; 
    ll ans = 0; 
    for(int i = 0; i < n; i++){
        val = (val * 10 + (s[i] - '0')) % 2019;
        // cout << val << " ";

        ans += a[val];

        a[val]++;
        int b[2019];
        for(int j = 0; j < 2019; j++){
            b[j * 10 % 2019] = a[j];
        }
        for(int j = 0; j < 2019; j++){
            a[j] = b[j];
        }
    }

    // for(int i = 0; i < 2019; i++){
    //     ans += 1ll * a[i] * (a[i] - 1) / 2;
    // }

    cout << ans; 
}


Measured memory_bytes: 3680
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long  ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;


void solve() {
	string s; cin >> s;
	int n = s.length();
	int id = 0;
	ll ans = 0;
	int tmp = 0;
	per(i, n) {
		if (s[i] == 'A') {
			if (id == 1) {
				id = 0; tmp = 0;
				if (s[i] == 'C')id = 1;
			}
			ans += tmp;
		}
		else if (id==0) {
			if (s[i] == 'C') {
				id = 1;
			}
			else {
				tmp = 0;
			}
		}
		else {
			if (s[i] == 'B') {
				id = 0; tmp++;
			}
			else if(s[i]=='A'){
				id = tmp = 0;
			}
			else {
				id = 1; tmp = 0;
			}
		}
	}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	//while (cin >> n)solve();
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 720
from collections import  Counter
n =int(input())
a = [int(i) for i in input().split()]
c = Counter(a)
num = []

for k,v in c.items():
    if v >= 2:
        num.append([k,v])

if len(num) ==0:
    print(0)
else:
    k = sorted(num,reverse=True)
    l = k[0][0]
    s = k[1][0]
    if k[0][1] >= 4:
        print(l*l)
    else:
        print(l*s)

Measured memory_bytes: 18600
import java.util.*;

public class Main{

	public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int val = scan.nextInt();
        //System.out.println(val);
      
     
        double answer = val * 0.5 *(1+val);
          
        System.out.print((int)answer);
        
    }



}

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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

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

  ll count = 0;
  for (long long a = 1; a * a < n; a++) {
    for (long long b = a; a * b < n; b++) {
      if (a == b) {
        count++;
      } else {
        count += 2;
      }
    }
  }

  cout << count << endl;
}


Measured memory_bytes: 3672
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long &x, long long &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a%b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n;
	cin >> n;
	cout << n * 800 - n / 15 * 200 << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def main(n, k, a):
    total = sum(a)
    return total + min(2*k, n-total-1)


if __name__ == "__main__":
    n, k = map(int, input().split())
    s = input()
    a = []
    for i in range(n-1):
        if s[i] == s[i+1]:
            a.append(1)
        else:
            a.append(0)

    print(main(n, k, a))


Measured memory_bytes: 4120
def f(A): return A.count(a)>1
R=[0,3,6]
N=range(9)
Z=[0]*9

n=input()
while n:
  F=[[" " for _ in Z] for _ in Z]
  M=[map(int,raw_input().split()) for _ in Z]
  M1=[[M[y][x] for y in N] for x in N]
  M2=[M[y][x:x+3]+M[y+1][x:x+3]+M[y+2][x:x+3] for y in R for x in R]
  for y in N:
    p0=y/3*3
    for x in N:
      a=M[y][x]
      if any(map(f,[M[y],M1[x],M2[p0+x/3]])): F[y][x]="*"
    print "".join([a+b for a,b in zip(F[y],map(str,M[y]))])
  if n>1: print
  n-=1

Measured memory_bytes: 4288
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
	"unsafe"
)

func main() {
	N := sc.nextInt()
	aPair := make([]Pair, N)
	for i := 0; i < N; i++ {
		xy := sc.nextInts()
		aPair[i] = Pair{first: xy[0], second: xy[1]}
	}
	var ans float64
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			if i == j {
				continue
			}
			p1 := aPair[i]
			p2 := aPair[j]
			x1y1 := (p1.first - p2.first) * (p1.first - p2.first)
			x2y2 := (p1.second - p2.second) * (p1.second - p2.second)
			ans += math.Sqrt(float64(x1y1) + float64(x2y2))
		}
	}
	fmt.Println(ans / float64(N))
}

var (
	sc scanner
)

func init() {
	sc = scanner{
		buf: make([]string, 0, 0),
		cur: 0,
		r:   bufio.NewReader(os.Stdin),
	}
}

type scanner struct {
	buf []string
	cur int
	r   *bufio.Reader
}

func (s *scanner) readln() {
	rbuf := make([]byte, 0, 0)
	for {
		line, prefix, err := s.r.ReadLine()
		if err != nil {
			panic(err)
		}
		rbuf = append(rbuf, line...)
		if prefix == false {
			break
		}
	}
	s.cur = 0
	s.buf = strings.Split(*(*string)(unsafe.Pointer(&rbuf)), " ")
}
func (s *scanner) isFull() bool {
	if s.cur == len(s.buf) {
		return true
	}
	return false
}
func (s *scanner) resetCur() {
	s.cur = 0
}
func (s *scanner) next() string {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nexts() []string {
	s.readln()
	s.resetCur()
	return s.buf
}
func (s *scanner) nextInt() int {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.Atoi(s.buf[s.cur])
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextInts() []int {
	s.readln()
	res := make([]int, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.Atoi(s.buf[i])
	}
	s.resetCur()
	return res
}
func (s *scanner) nextFloat() float64 {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.ParseFloat(s.buf[s.cur],
		64)
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextFloats() []float64 {
	s.readln()
	res := make([]float64, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.ParseFloat(s.buf[i],
			64)
	}
	s.resetCur()
	return res
}
func digits(x int) int {
	return len(strconv.Itoa(x))
}
func powInt(x, p int) (result int) {
	result = 1
	for i := 0; i < p; i++ {
		result *= x
	}
	return
}
func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}
func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}
func abs(x int) int {
	return int(math.Abs(float64(x)))
}
func varDump(value ...interface{}) {
	for _, v := range value {
		fmt.Fprintf(os.Stderr, "%#v\n", v)
	}
}
func yes() {
	fmt.Println("Yes")
}
func no() {
	fmt.Println("No")
}

// Pair a
type Pair struct {
	first  int
	second int
}

// Queue a
type Queue struct {
	v []Pair
}

// Push for queue
func (q *Queue) Push(v Pair) {
	q.v = append(q.v, v)
}

// Pop for queue
func (q *Queue) Pop() Pair {
	r := q.v[0]
	q.v = q.v[1:]
	return r
}

// Front for queue
func (q Queue) Front() Pair {
	return q.v[0]
}

// Empty return true if empty
func (q Queue) Empty() bool {
	return len(q.v) == 0
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
typedef long long ll;
int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, cnt = 1, a = 1;
	cin>>n;
	if (n == 1)
	{
		cout<<1;
		return 0;
	} 
	for(;;)
	{
		n/=2;
		a*=2;
		if (n == 1) break;
		cnt+=a;
	}
	cout<<a+cnt;
	return 0;
}


Measured memory_bytes: 256
s = input()
u = int(s[0] + s[1])
l = int(s[2] + s[3])

if l == 0 or u == 0:
    if 0 < l and l < 13:
        print('YYMM')

    elif 0 < u and u < 13:
        print("MMYY")
    else:
        print('NA')

elif 0 < l and l < 13:

    if 0 < u and u < 13:
        print('AMBIGUOUS')
    else:
        print("YYMM")

elif 0 < u and u < 13:
    print("MMYY")
else:
    print('NA')


Measured memory_bytes: 3064
class RUQ(object):
    INF = 2 ** 31 - 1

    def __init__(self, num) -> None:
        n = 1
        while n <= num:
            n = n * 2
        self.n = n
        self.val = [self.INF] * (2 * n - 1)

    def update(self, beg: int, end: int, k: int, l: int, r: int, x: int) -> None:
        if (l == beg and r == end):
            self.val[k] = x
            return
        cv = self.val[k]
        if (cv != -1):
            self.val[k * 2] = self.val[k * 2 + 1] = cv
            self.val[k] = -1
        mid = (l + r) // 2
        if (end <= mid):
            self.update(beg, end, k * 2, l, mid, x)
        elif (beg > mid):
            self.update(beg, end, k * 2 + 1, mid + 1, r, x)
        else:
            self.update(beg, mid, k * 2, l, mid, x)
            self.update(mid + 1, end, k * 2 + 1, mid + 1, r, x)

    def find(self, k: int, l: int, r: int, idx: int) -> int:
        if self.val[k] != -1:
            return self.val[k]
        mid = (l + r) // 2
        if (idx <= mid):
            return self.find(k * 2, l, mid, idx)
        else:
            return self.find(k * 2 + 1, mid + 1, r, idx)


if __name__ == "__main__":
    n, q = map(lambda x: int(x), input().split())
    ruq = RUQ(n)

    for _ in range(q):
        com, *v = map(lambda x: int(x), input().split())
        if (0 == com):
            ruq.update(v[0], v[1], 1, 0, n - 1, v[2])
        else:
            print(f"{ruq.find(1, 0, n - 1, v[0])}")



Measured memory_bytes: 8704
# 解説などを参考に作成
"""
N = 10, LR = [2, 4] を例とする.
fi:=マスiまで移動する方法の個数とおく.
便宜上0マスから始めると、
    N:  0 1 2 3 4 5 6 7 8 9 10
    fi: 0 1 0 1 1 2 2 4 5 8 11
となる.(1マス目には最初からいるのでf1 = 1とする.)
ここで、N=5,6の時で考えると、LR=[2,4]から
    f5 = f1 + f2 + f3  (∵2～4マス前からしか遷移がないので)
    f6 =      f2 + f3 + f4
よってf5とf6の差はf1とf4によって求めることができる.
    f6 = f5 - f1 + f4
一般化すると、
    fi = fi-1 - fi-1-R + fi-L
LRが複数ある場合でも区間が重複しないので、各区間に対して - fi-1-R + fi-L 部分を計算して fi を求めることができる.
計算量はO(KN) (K:=重複しない区間LRの個数)
"""


# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from collections import deque
# from decorator import stop_watch
#
#
# @stop_watch
def solve(N, K, LR):
    mod = 998244353
    dp = [0] * (N + 1)
    dp[1] = 1
    # dp[0] は基本0として扱ってよいが, dp[2]の計算時のみ,dp[0]とdp[1]の差分=0となる必要がある.
    # => この時のみ、dp[0]を1として計算しないと fi = fi-1 - fi-1-R + fi-L のルールに合わなくなる.
    # 他の人の解答(#16897281, #16895566)見ると階差数列？敵なのを持つことで解決できそうだったけど,
    # 内容が理解できなかったのでdp[2]までは手動実装することにした.
    dp[2] = 1 if 1 in [lr[0] for lr in LR] else 0
    for i in range(3, N + 1):
        x = 0
        for l, r in LR:
            x += dp[max(i - l, 0)] - dp[max(i - 1 - r, 0)]
        dp[i] = (dp[i - 1] + x) % mod
    print(dp[N])


if __name__ == '__main__':
    N, K = map(int, input().split())
    LR = [[int(i) for i in input().split()] for _ in range(K)]
    solve(N, K, LR)

    # # test
    # from random import randint
    # from func import random_str
    # N, K = 2 * 10 ** 5, 1
    # LR = [[1, N]]
    # solve(N, K, LR)


Measured memory_bytes: 16828
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <vector>
#include <cstring>
#include <queue>
#include <map>
#include <set>

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

using namespace std;

typedef long long ll;
typedef vector<int> vi; 
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define present(i, c) ((c).find(i) != (c).end())
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i <= n; i++)
#define foreach(i, c) for(auto i : c)

#define TRACE(x...) x
#define watch(x) TRACE(cerr << #x" = " << x << endl)
#define watchc(x) TRACE(cerr << #x" = "); for(auto __i : x) cerr << __i << " "; cerr << endl

//=========================

void run_test() {
	int k; cin >> k;
    string s; cin >> s;
    string res = (sz(s) <= k ? s : s.substr(0, k) + "...");
    cout << res << endl;
}

//=========================

ifstream infile;
clock_t start__;
void open_func();
void close_func();

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	open_func();
	//int t; cin >> t;
	//while(t--) run_test();
	run_test();
	close_func();
	return 0;	
}

void open_func() {
	infile = ifstream("input.in");
	if(infile.good()) cin.rdbuf(infile.rdbuf());
	start__ = clock();
	cerr << "---" << endl;
}

void close_func() {
	clock_t elapsed = clock()-start__;
	cerr << "---" << endl;
	cerr << "(time " << fixed << setprecision(2) << elapsed * (1.0/CLOCKS_PER_SEC) << "s)" << endl;	
	if(infile.good()) infile.close();
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool visited[100000 + 5], dp[100000 + 5];
bool dfs(int cur) {
    if (visited[cur])
        return dp[cur];
    if (cur == 0)
        return 1;
    if (cur < 0)
        return 0;
    visited[cur] = 1;
    return dp[cur] = dfs(cur - 100) || dfs(cur - 101) || dfs(cur - 102) || dfs(cur - 103) || dfs(cur - 104) || dfs(cur - 105) ;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    cout << dfs(n) << '\n';
    return 0;
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp38 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int A = st[0];
            int B = st[1];
            int C = st[2];

            if (A == B) {
                Console.WriteLine(C);
            } else if (B == C) {
                Console.WriteLine(A);
            } else {
                Console.WriteLine(B);
            }


        }
    }
}


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

using namespace std;

int main()
{
	int n,count4,count2;
	cin >> n;

	vector<int> a;
	a.resize(n);

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

	count4 = count2 = 0;

	for (int i = 0;i < n;i++)
	{
		if (a[i] % 4 == 0) count4++;
		else if (a[i] % 2 == 0) count2++;
	}

	if ((n / 2) <= (count4 + (count2 / 2))) cout << "Yes" << endl;
	else cout << "No" << endl;




	return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>

using namespace std;

struct Node {
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k){
    Node *y = NIL;
    Node *x = root;
    Node *z;

    z = (Node*)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while(x != NIL){
        y = x;
        if(z->key < x->key){
            x = x->left;
        }else{
            x = x->right;
        }
    }
    z->parent = y;
    if(y == NIL){
        root = z;
    }else{
        if(z->key < y->key){
            y->left = z;
        }else{
            y->right = z;
        }
    }
}

void inorder(Node *u){
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u){
    if(u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(){
    int n, i, x;
    string com;

    scanf("%d", &n);

    for(i = 0; i < n; i++){
        cin >> com;
        if(com == "insert"){
            scanf("%d", &x);
            insert(x);
        }else if(com == "print"){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}



Measured memory_bytes: 26700
import itertools as it
n,m=map(int,input().split())
e=[[0 for i in range(n)] for j in range(n)]
for i in range(m):
  a,b=map(lambda x:int(x)-1,input().split())
  e[a][b]=1
  e[b][a]=1

c=0
for t in it.permutations([j+1 for j in range(n-1)]):
  i=(0,)+t
  c+=1
  for j in range(n-1):
    if e[i[j]][i[j+1]]==0:
      c-=1
      break
print(c)

Measured memory_bytes: 9152
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair <int,int> P;
typedef long long ll;
int main(){

  int d,n,m;
  while(cin>>d,d){
    cin>>n>>m;
  int D[100001],M[100001];;
  D[0]=0,D[n]=d;
  for(int i=1;i<n;i++) cin>>D[i];
  for(int i=0;i<m;i++) cin>>M[i];
  sort(M,M+m);
  sort(D,D+n+1);

  ll ans=0;
  int pos=1;
  for(int i=0;i<m;i++){
    while(D[pos]<=M[i])pos++;
    ans+=min(abs(D[pos]-M[i]),abs(D[pos-1]-M[i]));
  }
  cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1604
import java.util.*;
public 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();
		int i = 0;
		// 文字列の入力
		while( b < a + 1){
			b = 2 * b;
            i++;
		}
		while( c < b + 1){
			c = 2 * c;
            i++;
		}
		if(i < d + 1){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
		
		
	}
}

Measured memory_bytes: 35708
#include<bits/stdc++.h>
#define mp make_pair
#define F first 
#define S second
using namespace std;
int vis2[100001],visn[100001],vis[100001],recs[100001],flg=0;

vector<pair<int,int> > v[100001], vn[100001];
void dfs(int r)
{
    recs[r]=1;
    vis[r]=1;
    for(int i=0;i<v[r].size();i++)
    {
        int x = v[r][i].F;
        
        if(vis[x]==0)
        {dfs(v[r][i].F);}
        else{
            if(recs[x]==1){flg=1;}
        }
    }
    recs[r]=0;
    return;
}
void dfsn(int r,long long sum,int parent,int nd)
{
    visn[r]=1;
    recs[r]=sum;
    //cout<<r<<" "<<sum<<endl;
    for(int i=0;i<vn[r].size();i++)
    {  //if(r==3) cout<<vn[r][i].F<<endl;
        int x= vn[r][i].F;
        if(visn[x]==0)
        {
            dfsn(x,sum+ vn[r][i].S,r,nd);
        }
        else if(visn[x]==1)
        {
            if(x!=parent )
            {
                if(sum+vn[r][i].S -recs[x]!=0){flg=1;}
                //if(r==nd && sum-vn[r][i].S+recs[x]!=0)flg=1;
                vis2[r]=1;
                //cout<<"A"<<" "<<sum<<" "<<sum+vn[r][i].S-recs[x]<<" "<<r<<" "<<x<<" "<<parent<<endl;
            }
        }
    }
    //recs[r]=0;
    //vis2[r]=0;
    
}
int main()
{
    int i,j,n,m;
    cin>>n>>m;
    
    for(i=0;i<m;i++)
    {
        int l,r,d;
        cin>>l>>r>>d;
        v[l].push_back(mp(r,d));
    }
    for(i=1;i<=n;i++)
    {
        if(vis[i]==0)
        dfs(i);
    }
    if(flg==1){cout<<"No\n";return 0;}
    
    for(i=1;i<=n;i++)
    {
        for(j=0;j<v[i].size();j++)
        {
            int x= v[i][j].F;
            vn[i].push_back(mp(x, v[i][j].S));
            vn[x].push_back(mp(i, -1*v[i][j].S));
        }
    }
    flg=0;
    for(i=1;i<=n;i++)
    {
        if(visn[i]==0)
        dfsn(i,0,0,i);
    }
    if(flg==1){cout<<"No\n";return 0;}
    cout<<"Yes\n";
    return 0;
}


Measured memory_bytes: 22272
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ll_s long
#define mod 1000000007
#define forn(i,start,lim) for(ll i=start;i<lim;i++)
#define forn_d(i,start,lim) for(ll i=start;i>=lim;i--)
#define f first
#define s second
#define pb push_back
#define pf push_front
#define mp make_pair
#define debug1(a) cout<<"------\n"<<#a<<" = "<<a<<endl<<"------"<<endl
#define debug2(a,b) cout<<"--------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<endl<<"--------------"<<endl
#define debug3(a,b,c) cout<<"----------------------\n"<<#a<<" = "<<a<<" ; "<<#b<<" = "<<b<<" ; "<<#c<<" = "<<c<<endl<<"----------------------"<<endl
#define sz(a) (ll)(a.size())
#define debug4(a) cout<<"chu "<<a<<endl
#define endl "\n"

ll h[100005],dp[100005];

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  ll n;
  cin>>n;
  forn(i,0,n) cin>>h[i];
  forn(i,1,n){
    ll a=1e18,b=1e18;
    a=dp[i-1]+abs(h[i]-h[i-1]);
    if(i>=2)
      b=dp[i-2]+abs(h[i]-h[i-2]);
    dp[i]=min(a,b);
  }
  ll ans=dp[n-1];
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
<?php

class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    /**
     * @return mixed
     */
    public function next() {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }

    /**
     * @return bool
     */
    public function hasNext() {
        return $this->pointer < $this->count;
    }

    /**
     * @return int
     */
    public function nextInt() {
        return (int)$this->next();
    }

    /**
     * @return float
     */
    public function nextDouble() {
        return (double)$this->next();
    }
}

// 初期化
$sc = new Scanner();
$N = $sc->nextInt();
$W = $sc->nextInt();
$v = array();
$w = array();
for ($i = 1; $i <= $N; $i++) {
    $v[$i]= $sc->nextInt();
    $w[$i]= $sc->nextInt();
}
unset($sc);

$dp = array();
$dp[0] = array_fill(0, $W+1, 0);

for ($i = 1; $i <= $N; $i++) {
    for ($j = 0; $j <= $W; $j++) {
        if ($j >= $w[$i]) {
            // 取れる場合 前のやつと比較する (左が取る場合、右が取らない場合)
            $dp[$i][$j] = max($dp[$i-1][$j - $w[$i]] + $v[$i], $dp[$i-1][$j]);
        } else {
            // 取れない場合
            $dp[$i][$j] = $dp[$i-1][$j];
        }
    }
    // メモリ足りないのでもういらない分は解放
    if ($i >= 2) {
        unset($dp[$i-2]);
    }
}
echo $dp[$N][$W] . "\n";


Measured memory_bytes: 14064
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = Integer.parseInt(sc.next());
        Boolean result = false;
        PrintWriter out = new PrintWriter(System.out);

        while (true) {
            result = isSosu(X);

            if (!result) {
                X++;
            } else {
                break;
            }
        }

        out.println(X);

        sc.close();
        out.flush();
    }

    private static Boolean isSosu(int X) {
        if (X == 2)
            return true;
        if (X < 2 || X % 2 == 0)
            return false;

        for (int i = 3; i <= Math.sqrt((double) X); i += 2) {
            if (X % i == 0) {
                return false;
            }
        }
        return true;
    }
}

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

int main(){

   int N;
    cin >> N;

    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N-1);

    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }
    for (int i = 0; i < N; i++)
    {
        cin >> B.at(i);
    }
    for (int i = 0; i < N-1; i++)
    {
        cin >> C.at(i);
    }
    int cnt =0;

    for(int i=0; i<N; i++){
        cnt += B.at(A.at(i)-1);
    }

    for(int i=0;i<N-1;i++){
        if(A.at(i)==A.at(i+1)-1){
            cnt += C.at(A.at(i)-1);
        }
    }


    cout << cnt << endl;
}


Measured memory_bytes: 3584
import copy

h, w, k = map(int, input().split())
c = [list(input()) for _ in range(h)]
ans = 0

for i in range(1 << (h + w)):
    l = copy.deepcopy(c)
    for p in range(h):
        if i >> p & 1:
            l[p] = ['r'] * w
    for m in range(w):
        if i >> (m + h) & 1:
            for o in range(h):
                l[o][m] = 'r'
    s = ''
    for i in range(h):
        s += ''.join(l[i])
    if s.count('#') == k:
        ans += 1
print(ans)

Measured memory_bytes: 9300
# import inbuilt standard input output  
from sys import stdin, stdout  
  
# suppose a function called main() and 
# all the operations are performed 
def main(): 
  
    # input via readline method 
    info_input = stdin.readline() 
    vote_input = stdin.readline() 

    info = [int(x) for x in info_input.split()] 
    votes = [int(x) for x in vote_input.split()] 

    n = info[0]; m = info[1]; 

    counter = 0 
    bound = 1/(4*m)
    total = sum(votes)

    for vote in votes:
    	if vote >= bound*total:
    		counter += 1
    		if counter == m:
    			return "Yes"
    return "No"

   
# call the main method 
if __name__ == "__main__": 
    print(main())     

Measured memory_bytes: 3064
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;

typedef unsigned long long ll;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<" "<<y<<endl
#define pl(x)                   out<<x
#define p2l(x,y)                out<<x<<" "<<y
#define p1d(a,n)                for(int ix=0;ix<n;ix++) out<<a[ix]<<" "; out<<endl
#define p2d(a,n,m)              for(int ix=0;ix<n;ix++){ for(int jx=0;jx<m;jx++) out<<a[ix][jx]<<" "; out<<endl;}
#define range(v)                v.begin(),v.end()
#define w(x)                    while(x--)
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2

class AStrings {
public:
	void solve(std::istream& in, std::ostream& out) {
	    string S,T;
	    s2(S,T);
	    out<<T+S<<endl;

	}
};


main() {
	AStrings solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
}


Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
paths = Array.new
m.times do
  paths << gets.split.map(&:to_i)
end
paths.sort! { |a, b| (a[0] <=> b[0]).nonzero? || (a[1] <=> b[1]) }
shortests = Array.new(n)
shortests[0] = 0
paths.each do |l, r, c|
  if shortests[l - 1]
    cost = shortests[l - 1] + c
    (r - 1).downto(l) do |index|
      if !shortests[index] || shortests[index] > cost
        shortests[index] = cost
      else
        break
      end
    end
  end
end
if shortests.last
  puts shortests.last
else
  puts -1
end


Measured memory_bytes: 11928
#include<iostream>
#include<algorithm>
using namespace std;
 
struct Data{
  int num,id;
  char ch;
};
 
int Partition(Data A[],int p,int r){
  Data x = A[r];
  int i=p-1;
  for(int j=p;j<r;j++){
    if(A[j].num<=x.num){
      i++;
      swap(A[i],A[j]);
    }
  }
  swap(A[i+1],A[r]);
  return i+1;
}
 
void Quicksort(Data A[],int p,int r){
  if(p<r){
    int q = Partition(A,p,r);
    Quicksort(A,p,q-1);
    Quicksort(A,q+1,r);
  }
}
 
void check(Data A[],int n){
  for(int i=1;i<n;i++){
    if(A[i-1].num<A[i].num)continue;
    if(A[i-1].id<A[i].id)continue;
    cout<<"Not stable"<<endl;
    return;
  }
  cout<<"Stable"<<endl;
}
 
int main(){
  int n;
  Data A[100000];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>A[i].ch>>A[i].num;
    A[i].id=i;
  }
   
  Quicksort(A,0,n-1);
  check(A,n); 
  for(int i=0;i<n;i++){
    cout<<A[i].ch<<' '<<A[i].num<<endl;
  }
   
  return 0;
}



Measured memory_bytes: 4220
import java.util.*;
public class Main { 
    public static void main(String[] args) {
       Scanner sc=new Scanner(System.in);
       String o="";
       int a=sc.nextInt();
       int b=sc.nextInt();
      int m=Math.max(a,b);
      int n=Math.min(a,b);
      for(int i=0;i<m;i++){
      	o+=Integer.toString(n);
      }
      System.out.println(o);
    }
}

Measured memory_bytes: 21716
#include<iostream> 
#include<string> 
#include<vector> 
#include<algorithm> 
using namespace std; 
int main()
{
	string a;
	cin >> a;
	if (a=="ani")
	{
		cout << "square1001" << endl;
	}
	else
	{
		cout << "e869120" << endl;
	}
}



Measured memory_bytes: 3156
import sys
input = sys.stdin.readline

def multipleSum(A, n):
    sum = 0
    for i in range(n):
        sum += A[i]
    mulsum = sum*sum
    insum = 0
    for i in range(n):
        insum+=A[i]*A[i]
    return (mulsum-insum)//2

N = int(input())
A = list(map(int,input().split()))
n = len(A)
print(multipleSum(A,n)%1000000007)





Measured memory_bytes: 31304
#include<iostream>
using namespace std;
int main() {
	int *line;
	int size;
	while (cin >> size &&size!= 0) {
		line = new int[size + 2];
		line[0] = 0;
		line[size + 1] = 0;
		int answer = size;
		int count;
		int forward;
		int back;
		int moto;
		int nsize;
		int color;
		for (int i = 1; i <= size; ++i) {
			cin >> line[i];
		}
		for (int i = 1; i <= size; ++i) {
			moto = line[i];
			for (int j = 1; j <= 3; ++j) {
				nsize = size;
				line[i] = j;
				forward = i;
				back = i - 1;
				while (true) {
					count = 0;
					if (line[forward]) {
						color = line[forward];
					}
					else {
						color = line[back];
					}
					while (color == line[forward]) {
						++forward;
						++count;
					}
					while (color == line[back]) {
						--back;
						++count;
					}
					if (count >= 4) {
						nsize -= count;
					}
					else {
						break;
					}
				}
				if (nsize < answer) {
					answer = nsize;
				}
			}
			line[i] = moto;
		}
		cout << answer << endl;
		delete line;
	}
	return 0;
}

Measured memory_bytes: 3044
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

const int N = 2005, INF = 1E9 + 7;

int n, u, v, ans = INF, tot[N], mi[N], cnt[N];
char s[N];
vector<int> adj[N];

void DFS(int u, int p = 0) {
    tot[u] = 0; mi[u] = 0, cnt[u] = s[u] - '0';
    pair<int, int> mx = {0, 0};
    for (int &v : adj[u]) {
        if (v != p) {
            DFS(v, u);
            int ct = tot[v], cm = mi[v], cc = cnt[v];
            cnt[u] += cc; ct += cc; cm += cc;
            tot[u] += ct;
            mx = max(mx, {ct, cm});
        }
    }
    mi[u] = max(tot[u] & 1, mx.se - (tot[u] - mx.fi));
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> (s + 1);
    for (int i = 1; i < n; i++) {
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for (int u = 1; u <= n; u++) {
        DFS(u);
        if (mi[u] == 0) {
            ans = min(ans, tot[u] / 2);
        }
    }
    cout << (ans == INF ? -1 : ans);
}


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

const int MAX_N = 3e3;
ll dp[MAX_N + 1][MAX_N+1] = {0}; // dp[i][j] := iターン目に残ってる数列の左端がjの時の場合の数
bool used[MAX_N+1][MAX_N+1] = {0};
int N;
vector<ll> a;

ll rec(int k, int l, int r){ //手番がk番目で残ってる数列の左端、右端の座標
    if(k == N) return dp[k][l] = pow(-1, k + 1) * a[l];
    if(used[k][l]) return dp[k][l];

    used[k][l] = 1;

    if(k % 2 == 1) return dp[k][l] = max(rec(k+1, l, r-1) + a[r], rec(k+1, l+1, r) + a[l]);
    else return dp[k][l] = min(rec(k+1, l+1, r) - a[l] , rec(k+1, l, r - 1) - a[r]);

    return 0;
}

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

    cout << rec(1, 0, N - 1) << endl;

    /* for(int i = 0; i <= N; i++){
        for(int j = 0; j <= N; j++){
            cout  << i << " " << j << dp[i][j] << endl;
        }
    } */

}

Measured memory_bytes: 79616
#include <iostream>
#include <stdio.h>
using namespace std;
const int N = 1e5 + 9;
int a[N << 1], f[N << 1], n;
bool check(int x){
    int sum = 0;
    for(int i = 1; i < 2*n; i++) f[i] = a[i] >= x, sum += f[i];
    for(int i = n-1; i >= 1; i--){
        int xx = 2*n-i;
        if(f[xx] == f[xx - 1]) return f[xx]; 
        if(f[i] == f[i+1]) return f[i]; 
    }
    return sum >= n;
}
int erfen(int l, int r){
    while(l < r){
        int mid = (l + r + 1) / 2;
        if(check(mid)) l = mid;
        else r = mid - 1;
    }
    return l;
}
int main(){
    scanf("%d", &n);
    for(int i = 1; i < 2*n; i++) scanf("%d", &a[i]);
    printf("%d", erfen(1, 2*n-1));
    return 0;
}

Measured memory_bytes: 1792
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

struct Card {
    char suit;
    int value;
};
void deepCopy(Card A[] ,Card B[],int n){
    for(int i = 0; i < n ; i++){
        B[i].suit = A[i].suit;
        B[i].value = A[i].value;
    }
}
void swap(Card A[], int i, int j) {
    Card temp = A[i];
    A[i] = A[j];
    A[j] = temp;
}
int partition(Card A[], int p, int r) {
    Card x = A[r];
    int i = p - 1;
    for(int j = p; j < r; j++) {
        if(A[j].value <= x.value) {
            i++;
            swap(A, i, j);
        }
    }
    i++;
    swap(A, i, r);
    return i;
}
void quicksort(Card A[],int p,int r){
    if(p<r){
        int q = partition(A,p,r);
        quicksort(A,p,q-1);
        quicksort(A,q+1,r);
    }else{
        return ;
    }
}
void merge(Card A[], int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    Card L[n1 + 1], R[n2 + 1];

    for(int i = 0; i < n1; i++) {
        L[i] = A[left + i];
    }
    for(int i = 0; i < n2; i++) {
        R[i] = A[mid + i];
    }
    L[n1].value = INT32_MAX;
    R[n2].value = INT32_MAX;
    int i = 0;
    int j = 0;
    for(int k = left; k < right; k++) {
        if(L[i].value <= R[j].value) {
            A[k] = L[i];
            i++;
        } else {
            A[k] = R[j];
            j++;
        }
    }
}
void mergesort(Card A[], int left, int right) {
    if(left + 1 < right) {
        int mid = (left + right) / 2;
        mergesort(A, left, mid);
        mergesort(A, mid, right);
        merge(A, left, mid, right);
    } else {
        return;
    }
}
int main() {
    int n;
    cin >> n;
    Card A[n];
    Card B[n];
    for(int i = 0; i < n; i++) {
        scanf("%s %d", &A[i].suit,&A[i].value);
    }
    deepCopy(A,B,n);
    quicksort(A,0,n-1);
    mergesort(B,0,n);
    
    bool isStable = true;
    for(int i = 0; i < n ; i++){
        if(A[i].suit != B[i].suit){
            isStable = false;
            break;
        }
    }
    if(isStable){
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }
    for(int i=0; i<n; i++){
        printf("%c %d\n",A[i].suit,A[i].value);
    }
}


Measured memory_bytes: 5568