akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;

class Program {
  static void Main() {
    var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int h = arr[0];
    int w = arr[1];
    var a = new List<string>();
    var c = new SortedSet<int>();
    var sb = new StringBuilder();
    while (h-- > 0) {
      var s = Console.ReadLine();
      if (s.All(x => x == '.')) continue;
      a.Add(s);
      for (int i = 0; i < w; i++) {
        if (s[i] == '#') c.Add(i);
      }
    }
    foreach (var i in a) {
      foreach (var j in c) {
        sb.Append(i[j]);
      }
      sb.AppendLine();
    }
    Console.Write(sb);
  }
}

Measured memory_bytes: 13596
/******************************************************************************
 
рассвет. 
 
*******************************************************************************/
#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
#define rapgame ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define eb emplace_back
#define vi vector <int>
#define vlli vector <lli>
#define vulli vector <ulli>
#define vchar vector <char>
#define vstr vector <string>
#define vb vector <bool>
#define fst first
#define sec second
#define all(a) (a).begin(),(a).end()
#define srt(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define vpii vector <pair <int,int> >
#define pii pair <int,int> 
#define vplli vector <pair <lli,lli> >
#define vvi vector <vector <int> >
#define vvlli vector <vector <lli> >
#define vvpii vector <vector <pair <int,int>> >
#define fr(i,n) for (int i = 0; i < (n); ++i)
#define frbig(i,n) for (lli i = 0; i < (n); ++i)
#define fra(i,a,n) for (lli i = a; i < (n); ++i)
#define run(c,s) for(auto c:s) 
#define read(n) int n; cin >> n;
#define readchar(n) char n; cin >> n;
#define readstr(n) string n; cin >> n;
#define readarr(a,n) fr(i,n) cin >> a[i];
#define read2(x,y) int x,y; cin >> x >> y;
#define read2ll(x,y) long long int x,y; cin >> x >> y;
#define readll(n) lli n; cin >> n;
#define watch(x) cout << (#x) << " is " << (x) << endl
#define print_array(x) fr(i,x.size()) cout << x[i] << " ";
using namespace std;
 
const lli MOD=1e9+7;
const lli MAXN=1e6+1;
const ld PI=acos(-1);

vi dp;

int dfs(vvi &g,int v){
    if(dp[v]!=-1) return dp[v];
    else{
        dp[v]=0;
        run(to,g[v]){
            dp[v]=max(dp[v],dfs(g,to)+1);
        }
        return dp[v];
    }
}

int main(){
    rapgame
    //freopen("unionday.in", "r", stdin);
    //freopen("unionday.out", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--){
        read2(n,m);
        dp.assign(n,-1);
        vvi g(n);
        fr(i,m){
            read2(a,b);
            a--;b--;
            g[a].pb(b);
        }
        int ans=0;
        fr(i,n){
            ans=max(dfs(g,i),ans);
        }
        cout << ans;
    }
    return 0;
}

Measured memory_bytes: 8192
#include <iostream>
#include <vector>
#include <cmath>

int main(int argc, char** argv) {
  int N, K;
  std::cin >> N >> K;
  std::vector<int> p(N);
  for (auto& e : p) std::cin >> e;
  std::vector<double> ave(N);
  for (auto i = 0;i < N;++i) {
    ave[i] = static_cast<double>(p[i]+1)/2;
  }
  double sum_tmp {};
  for (auto i = 0;i < K;++i) {
    sum_tmp += ave[i];
  }
  double sum_max = sum_tmp;
  for (auto i = K;i < N;++i) {
    sum_tmp += ave[i] - ave[i-K];
    sum_max = std::max(sum_max, sum_tmp);
  }
  std::cout << std::fixed << sum_max << '\n';
}


Measured memory_bytes: 2688
N, M = map(int, input().split())
num = 0
for i in range(1, int(M ** 0.5) + 2):
    if M % i == 0 and i * N <= M:
        num = max(i, num)
    if M % i == 0 and (M // i) * N <= M:
        num = max(M // i, num)
print(num)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdlib>

using namespace std;
int main()
{
    string s;
    cin >> s;

    int s3 = 0;
    int s3_abs = 0;
    int abs_min = 754;

    for (int i = 0; i <= s.length() - 3; i++) {
        s3 = atoi(s.substr(i, 3).c_str());
        s3_abs = abs(s3 - 753);
        if (s3_abs < abs_min) {
            abs_min = s3_abs;
        }
    }

    cout << abs_min << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<queue>
#include<utility>
#include<cmath>
#include<sstream>
#include<istream>
#include<numeric>
#include<stdlib.h>

using namespace std;

int main()
{

  string S;
  cin >> S;

  int N = S.size();

  long long ans=0;

  for(int mask=0; mask<(1<<N-1); mask++){
    string ss="";
    for(int i=0; i<N; i++){
      ss+=S[i];
      if(mask>>i&1){
        ans+=stoll(ss);
        ss="";
      }
      cout << endl;
    }
    ans+=stoll(ss);
    ss="";
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N, M;
  std::cin >> N >> M;
  std::vector<int> lis(M);;
  range(i, M){
    std::cin >> lis[i];
  }
  sort(lis.begin(), lis.end());
  reverse(lis.begin(), lis.end());
  vvi dp = vv(N+1, M + 1, 0, int);
  vvi usable = vv(M, 2, 0, int);
  int mach[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
  range(i, M){
    usable[i][0] = lis[i];
    usable[i][1] = mach[lis[i] - 1];
    //1: number 2: the number of match
  }
  ranges(i, 1, N+1){
    dp[i][M] = -1;
  }
  ranges(i, 1, N+1){
    range(j, M){
      if(usable[j][1] > i) {
        continue;
      }else if(dp[i - usable[j][1]][M]== -1){
        continue;
      }else{
        if(dp[i-usable[j][1]][M]+1 > dp[i][M]){
          range(k, M){
            dp[i][k] = dp[i - usable[j][1]][k];
          }
          dp[i][j]++;
          dp[i][M] = dp[i-usable[j][1]][M]+1;
        }
      }
    }
  }
  range(i, M){
    range(j, dp[N][i]){
      std::cout << usable[i][0];
    }
  }
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define fo(x, n) for(int i = x; i <= n; i++)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector <int> vi;
const int MOD = 1e9 + 7;
void solve(){
    int a, b, t;
    cin >> a >> b >> t;
    int cur = 0, ans = 0;
    while(cur + a <= t){
        cur += a;
        ans += b;
    }
    cout << ans;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
	int T = 1;
    //cin >> T;
    fo(1, T){
        solve();
    }
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; ll m;
    cin >> n >> m;
    vector <ll> as;
    REP(i, n){
        ll a; cin >> a;
        as.push_back(a);
    }
    sort(as.begin(), as.end());

    vector <ll> ruiseki = {0};
    REP(i, n){
        ruiseki.push_back(ruiseki[i] + as[i]);
    }

    ll ok = as[n-1] * 2;
    ll ng = -1;
    ll cnt;
    ll kagen;
    bool re = false;
    while (ok - ng > 1){
        kagen = (ok + ng)/2;
        cnt = 0;
        REP(i, n){
            ll gokei = kagen - as[i];
            ll matsubi_cnt = as.end() - upper_bound(as.begin(), as.end(), gokei);
            cnt += matsubi_cnt;
        }
        if (cnt > m){
            ng = kagen;
        } else {
            ok = kagen;
        }
    }
    kagen = ok;
    cnt = 0;
    ll ans = 0;
    REP(i, n){
        ll gokei = kagen - as[i];
        ll matsubi_cnt = as.end() - upper_bound(as.begin(), as.end(), gokei);
        cnt += matsubi_cnt;
        ans += as[i] * matsubi_cnt;
        ans += ruiseki[n];
        ans -= ruiseki[n - matsubi_cnt];
    }
    ans += (m-cnt) * kagen;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2548
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,ans,a[110],x;
int main(){
	cin>>n;
	for (int i=1;i<=n;i++)cin>>a[i];
	for (int i=1;i<=n;i++){cin>>x;ans+=x;}
	for (int i=1;i<n;i++){
		cin>>x;
		for (int j=1;j<n;j++){
				if (a[j]==i&&a[j+1]==i+1)ans+=x;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  int N, K;
  int ans = 0;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if (x - 0 > K - x) {
      ans += K - x;
    }
    else {
      ans += x;
    }
  }
  cout << ans * 2 << endl;
}

Measured memory_bytes: 256
s = list(input())
data = [0] * (len(s) + 1)
for i in range(len(s)):
    if s[i] == "<":
        data[i + 1] = data[i] + 1

for i in range(len(s) - 1, -1, -1):
    if s[i] == ">":
        data[i] = max(data[i], data[i + 1] + 1) 
print(sum(data))

Measured memory_bytes: 26808
#include <iostream>
#include <vector>
#include <algorithm> 
#include <queue>
#include <functional>
using namespace std;

vector<int> data;
vector<int> tube_B;
vector<int> tube_C;

const int MAX = 10;

int dfs(int count){

    if (count == MAX) return 1;

    int ret = 0;

    int b = tube_B.size() - 1;
    int c = tube_C.size() - 1;

    if (data[count] > tube_B[b]){
        tube_B.push_back(data[count]);
        ret = max(ret, dfs(count + 1));
        tube_B.pop_back();
    }

    if (data[count] > tube_C[c]){
        tube_C.push_back(data[count]);
        ret = max(ret, dfs(count + 1));
        tube_C.pop_back();
    }

    return ret;
}

int main(void){

    int n;
    cin >> n;
    tube_B.push_back(-1);
    tube_C.push_back(-1);

    for (int i = 0; i < n; i++){
        for (int j = 0; j < 10; j++){
            int s;
            cin >> s;
            data.push_back(s);
        }

        if (dfs(0)){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }

        data.erase(data.begin(), data.end());
        tube_B.erase(tube_B.begin(), tube_B.end());
        tube_C.erase(tube_C.begin(), tube_C.end());
    }


}

Measured memory_bytes: 3012
#include <stdio.h>



int main(){
    int In[10000],Out[500],Ni,No,i,j,C=0;
    scanf("%d",&Ni);
    for (i=0; i<Ni; i++) {
        scanf("%d",&In[i]);
    }
    scanf("%d",&No);
    for (j=0; j<No; j++) {
        scanf("%d",&Out[j]);
    }
    
    for(i=0; i<No; i++){
        j=0;
        In[Ni] = Out[i];
        while(In[j] != Out[i]){
            j++;
        }
        if(j < Ni) C++;
    }
    printf("%d\n",C);
    
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,M;
    cin >> N >>M;
    vector<int>vec(N);
   vector<int>vec2(M,0);
   for(int i=0;i<N;i++){
       int K;
       cin >>K;
       vector<int>vec3(K);
       for(int j=0;j<K;j++){
           cin >>vec3.at(j);
           vec2.at(vec3.at(j)-1)++;
       }
   }
   int count =0;
   for(int i=0;i<M;i++){
       if(vec2.at(i)==N){
           count++;
       }
   }
   cout << count <<endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;
ll n,k;

ll ans;
vector<int> D;
void dfs(ll a)
{
	//cout<<a<<endl;
	if(n<=a)
	{
		ans = min(ans,a);
		return;
	}
	for(ll i =0;i<10;i++)
	{
		if(*lower_bound(D.begin(),D.end(),i)!=i)
		if(10*a+i!=0)dfs(10*a+i);
	}
}

int main()
{
	ans = MOD;
	cin >> n >> k;
	
	for(int i =0;i<k;i++)
	{
		int a;
		cin >> a;
		D.push_back(a);
	}
	dfs(0);
	cout<<ans<<endl;
	return 0;
}

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

int main() {
    long long int a, b, c, k, ans = 0;
    cin >> a >> b >> c >> k;
    if(a >= k) ans = k;
    else {
        ans += a;
        k -= a;
        k -= b;
        if(k > 0) {
            ans -= k;
        } 
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>
#include <cmath>
#include <iostream>

using namespace std;
#define MAX 500000;
#define SENTINEL 2000000000;
//int count=0;

void merge(int A[], int left, int mid, int right){
    int n1=mid-left;
    int n2=right-mid;
    int L[500000/2+2],R[500000/2+2];
    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]=SENTINEL;
    R[n2]=SENTINEL;
    int i=0,j=0;
    for(int k=left;k<right;k++){
//        count++;
        if(L[i]<=R[j]){
            A[k]=L[i++];
        }else{
            A[k]=R[j++];
        }
    }

};

void mergeSort(int 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);
    }
}

int partition(int A[], int p, int r){
    int x=A[r];
    int i=p-1;
    for(int j=p; j<r; j++){
        if (A[j]<=x){
            i++;
            swap(A[i],A[j]);
        }
    }
    swap(A[i+1],A[r]);
    return i+1;
}

int main()
{
    int n,i;
    scanf("%d",&n);
    int A[100001];
    for(int i=0;i<n;i++)scanf("%d",&A[i]);
    int ans=partition(A,0,n-1);
    for(i=0;i<n;i++){
        if(i)cout<<" ";
        if(i==ans)cout<<"[";
        cout<<A[i];
        if(i==ans)cout<<"]";

    }
    cout<<endl;
//    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 3492
n, l = map(int, input().split())
taste = 0
ans = 0
diff = 999

for i in range(n):
    taste = taste + l + i

for i in range(n):
    if diff > abs(l + i):
        diff = abs(l + i)
        ans = taste - (l + i)
    
print(ans)

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

int main(){
    
    int num = 1;
    
    int N,K;
    
    cin >> N >> K;
    
    for(int i = 0; i < N; i++){
        
        if((num * 2) > (num + K)){
            
            num += K;
        }else{
            num *=2;
        }
    }
    cout << num << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
typedef long long ll;
long long mod = 1e9 + 7;
const int iINF = 0x3f3f3f3f;
const long long INF = 1LL << 60;
using namespace std;
using pint = pair<int, int>;

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

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

int main()
{
  int n;
  cin >> n;
  vector<ll> arr(10000005);

  rep(i, n + 1)
  {
    arr[i] = 1;
  }

  repi(i, 2, n + 1)
  {
    for (int j = 1; j <= n / i; j++)
    {
      arr[i * j]++;
    }
  }

  ll ans = 0;
  repi(i, 1, n + 1)
  {
    // cout << arr[i] << endl;
    ans += ll(i * arr[i]);
  }

  cout << ans << endl;
  return 0;
}

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

void solve()
{
    string s;
    int k;

    cin >> k >> s;

    cout << s.substr(0, k);
    if(s.length()>k)
    {
        cout << "...";
    }


}


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll t;
    solve();
    return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int h[n];
  for(int i = 0; i < n; ++i) cin >> h[i];
  sort(h, h + n);
  int m = INT_MAX;
  for(int i = k - 1; i < n; ++i) {
    m = min(h[i] - h[i - k + 1], m);
  }

  cout << m << endl;
  return 0;
}


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

using namespace std; 
 
#define int long long
#define M 1000000007

int dp[1000010][2][2],n; 
 
int fun(int i,int zero,int nine){
	int ans=0;
	if(i>=n){
		if(i==n&&zero&&nine){
			return(1);
		}
		return(0);
	}
	if(dp[i][zero][nine]!=-1){
		return(dp[i][zero][nine]);
	}
	for(int j=0;j<=9;j++){
		ans+=fun(i+1,(j==0)|zero,(j==9)|nine);
		ans%=M;
	}
	dp[i][zero][nine]=ans;
	return(ans);
} 
 
signed main(){
	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
	
//	int n;
	cin >> n;
	memset(dp,-1,sizeof(dp));
	cout << fun(0,0,0) << endl;
}


Measured memory_bytes: 97308
#include<stdio.h>
int main(void)
{
	int a,b,d,r;
	double f;
	scanf("%d %d",&a,&b);
	d=a/b;
	r=a%b;
	f=a/(b*1.00);
	printf("%d %d %lf\n",d,r,f);
	return 0;
}

Measured memory_bytes: 632
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    for(ll i=0;i<n;++i){
        cin>>a[i];
    }
    ll ans = gcd(a[0], a[1]);
    for(ll i=1;i<n;++i){
        ans = gcd(ans, a[i]);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1024
"""
author : halo2halo
date : 30, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a,b,c = map(int, readline().decode('utf8').split())

print('YES' if 2 * b == a + c else 'NO')


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
using namespace std;

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

vector<int> ch[1010];
string com[1010];
int n;
bool flg[1010];

void put(int k, int d){
    rep(i,d) putchar('.');
    cout << com[k] << endl;
    flg[k] = true;
    for(int i : ch[k]){
        put(i,d+1);
    }
}

int main(){
    while(cin >> n){
        rep(i,n) ch[i].clear(), flg[i] = false;
        rep(i,n){
            int k;
            cin >> k >> com[i];
            if(i!=0) ch[k-1].push_back(i);
        }
        rep(i,n){
            if(!flg[i]) put(i,0);
        }
    }
}

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

int main(){
  
  long long N, K, i;
  cin>>N>>K;
  vector<long long> A(N);
  for(i=0; i<N; i++){
    cin>>A[i];
  }
  
  for(i=K; i<N; i++){
    if(A[i-K]<A[i]){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 4836
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
#include <iomanip>
#include <fstream>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;
typedef long long ll;
typedef pair<int,int> pii;

int X[1000];
int Y[1000];

int dir(int a, int b) {
  if (X[a] == X[b]) {
    if (Y[a] < Y[b]) return 0;
    else return 2;
  } else {
    if (X[a] < X[b]) return 1;
    else return 3;
  }
}
int dis(int a, int b) {
  return abs(X[a]-X[b]) + abs(Y[a]-Y[b]);
}

struct P {
  int now, d, cost, len;
  P(int now, int d, int cost, int len) :
    now(now),d(d),cost(cost),len(len) {}
  bool operator<(const P &b) const {
    return cost != b.cost ? cost > b.cost : len > b.len;
  }
};

pii g[1000][4];
int dist[1000][4];
string name[1000];

int main() {
  int m,n;
  while(cin>>m>>n,m||n) {
    map<string,int> mp;
    REP(i,m) {
      cin >> name[i] >> X[i] >> Y[i];
      mp[name[i]] = i;
    }
    REP(i,m)REP(j,4) g[i][j]=pii(-1,0);
    REP(i,n) {
      string s,t;
      cin >> s >> t;
      int a = mp[s];
      int b = mp[t];
      g[a][dir(a,b)] = pii(b,dis(a,b));
      g[b][dir(b,a)] = pii(a,dis(a,b));
    }
    string s, t;
    cin >> s >> t;
    int start = mp[s];
    int end = mp[t];
    priority_queue<P> Q;
    REP(i,m)REP(j,4) dist[i][j] = INF;
    REP(i,4) {
      Q.push(P(start,i,0,1));
      dist[start][i] = 0;
    }
    int ans = INF;
    while(!Q.empty()) {
      P p = Q.top(); Q.pop();
      
      int nd = (p.d+3) % 4;
      int now = p.now;

      if (dist[now][p.d] > p.cost) continue;
      
      int dd[2] = {p.d,nd};

//      cout << now << " " << p.d << endl;
      if (now == end) {
        ans = p.len;
        break;
      }
      
      REP(i,2) {
        pii e = g[now][dd[i]];
        int b = e.first;
        if (b != -1) {
          int nd = dist[now][p.d] + e.second;
          if (dist[b][dd[i]] > nd) {
            dist[b][dd[i]] = nd;
            Q.push(P(b,dd[i],nd,p.len+1));
          }
        }
      }
    }
    if (ans == INF) cout << "impossible" << endl;
    else cout << ans << endl;
  }
}

Measured memory_bytes: 1448
def main():
    N = int(input())
    G = [[]*N for _ in range(N)]
    edge_color = {}
    key_ = []
    for _ in range(N-1):
        a, b = (int(i) for i in input().split())
        G[a-1].append(b-1)
        G[b-1].append(a-1)
        edge_color[(a-1, b-1)] = -1
        key_.append((a-1, b-1))
    from collections import deque
    deg_max = 0
    for g in G:
        deg_max = max(deg_max, len(g))

    G_color = ['WHITE' for _ in range(N)]
    G_distance = [float('inf') for _ in range(N)]
    G_parent = ['NIL' for _ in range(N)]

    def bfs(s):
        G_color[s] = 'GRAY'
        G_distance[s] = 0
        Q = deque()
        Q.append(s)
        while Q:
            u = Q.popleft()
            if G_parent[u] == 'NIL':
                now_color = 1
            else:
                now_color = (edge_color[(G_parent[u], u)] + 1) % deg_max
            for v in G[u]:
                if G_color[v] == 'WHITE':
                    G_color[v] = 'GRAY'
                    G_distance[v] = G_distance[u] + 1
                    G_parent[v] = u
                    Q.append(v)
                    edge_color[(u, v)] = now_color % deg_max
                    now_color += 1
            G_color[u] = 'BLACK'
    bfs(0)
    print(deg_max)
    for k in key_:
        print(edge_color[k]+1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 103712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pl;

int main(){
  string s;
  cin>>s;

  int i;
  int n=s.size();
  int cnt=0;
  vector<int> ans(n,0);

  for(i=0;i<n;i++){
    if(s[i]=='R'){
      cnt++;
    }else{
      ans[i]+=cnt/2;
      ans[i-1]+=cnt/2;
      if(cnt%2!=0)
      ans[i-1]+=1;
      cnt=0;
    }
  }
  cnt=0;
  for(i=n-1;i>=0;i--){
    if(s[i]=='L'){
      cnt++;
    }else{
      ans[i]+=cnt/2;
      ans[i+1]+=cnt/2;
      if(cnt%2!=0)
      ans[i+1]+=1;
      cnt=0;
    }
  }

  for(i=0;i<n;i++)
  cout<<ans[i]<<(i==n-1?'\n':' ');
}


Measured memory_bytes: 1024
n, k = map(int, input().split())
h = list(map(int, input().split()))
 
h_ = sorted(h)
 
for i in range(k):
    if len(h_) > 0:
        h_.pop()
    
s = [0]*(len(h_)+1)
for j in range(len(h_)):
    s[j+1] = s[j] + h_[j]

print(s[-1])

Measured memory_bytes: 26180
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;

string S,T;
string ans = "";

void solve(){
	ans = T+S;
}

int main(){
	cin >> S >> T;

	solve();

	cout << ans;
	return 0;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  in(int, n, m);
  vector<vector<int>> g(n + 1);
  rep(i, m) {
    in(int, u, v);
    g[u].push_back(v);
  }
  in(int, s, t);
  vector<vector<bool>> visited(n + 1, vector<bool>(3));
  visited[s][0] = true;
  queue<tuple<int, int, int>> que;
  que.push({s, 0, 0});
  while (!que.empty()) {
    auto [node, step, dist] = que.front();
    que.pop();
    if (node == t && step == 0) {
      out(dist);
      return 0;
    }
    for (int child : g[node]) {
      int nstep = step + 1;
      int ndist = dist;
      if (nstep == 3) {
        nstep = 0;
        ++ndist;
      }
      if (visited[child][nstep]) continue;
      visited[child][nstep] = true;
      que.push({child, nstep, ndist});
    }
  }
  out(-1);
}


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

class UnionFind {
   private:
    vector<int> data;

   public:
    UnionFind(const int& N) : data(vector<int>(N, -1)) {}

    int root(const int& x) {
        if (data[x] < 0) {
            return x;
        } else {
            return data[x] = root(data[x]);
        }
    }

    int size(const int& x) {
        return -data[root(x)];
    }

    bool same(const int& x, const int& y) {
        return root(x) == root(y);
    }

    void unite(int x, int y) {
        if (same(x, y)) return;
        x = root(x);
        y = root(y);
        if (size(x) < size(y)) {
            data[y] += data[x];
            data[x] = y;
        } else {
            data[x] += data[y];
            data[y] = x;
        }
    }
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    UnionFind UF(n);
    for (size_t i = 0; i < q; i++) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com == 0) {
            UF.unite(x, y);
        }
        if (com == 1) {
            cout << UF.same(x, y) << endl;
        }
    }
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define db(x) cout<<#x<<"="<<x<<endl
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
#define EPS 1e(-9);
using namespace std;
typedef long long ll;

void Main(){

  ll N;
  cin>>N;

  cout<< N*(N-1)/2 <<"\n";
}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
 
int main()
{
  int x, a, b;
  cin >> x >> a >> b;
  if(abs(x - a) < abs(x - b)){
    cout << 'A' << endl;
  }
  else{
    cout << 'B' << endl;
  }
}

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

using namespace std;

typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldbl;
typedef pair<int, int> pii;
typedef pair<uint, uint> puu;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<uint> vu;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pii> vpii;
typedef vector<puu> vpuu;
typedef vector<pll> vpll;
typedef vector<pull> vpull;
typedef vector<string> vstr;
typedef vector<double> vdbl;
typedef vector<ldbl> vldbl;
#define pb push_back
#define ppb pop_back
#define pfr push_front
#define ppfr pop_front
#define emp emplace
#define empb emplace_back
#define be begin
#define rbe rbegin
#define all(x) (x).be(), (x).end()
#define rall(x) (x).rbe(), (x).rend()
#define fir first
#define sec second
#define mkp make_pair
#define brif(cond) if (cond) break
#define ctif(cond) if (cond) continue
#define retif(cond) if (cond) return
void canhazfast() {ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);}
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a%b) : a;}
template<typename T> T extgcd(T a, T b, T &x, T &y)
{
    T x0 = 1, y0 = 0, x1 = 0, y1 = 1;
    while (b) {
        T q = a/b; a %= b; swap(a, b);
        x0 -= q*x1; swap(x0, x1);
        y0 -= q*y1; swap(y0, y1);
    }
    x = x0; y = y0; return a;
}
int ctz(uint x) {return __builtin_ctz(x);}
int ctzll(ull x) {return __builtin_ctzll(x);}
int clz(uint x) {return __builtin_clz(x);}
int clzll(ull x) {return __builtin_clzll(x);}
int popcnt(uint x) {return __builtin_popcount(x);}
int popcntll(ull x) {return __builtin_popcountll(x);}
int bsr(uint x) {return 31^clz(x);}
int bsrll(ull x) {return 63^clzll(x);}

int main()
{
    canhazfast();

    int n, a, b;

    cin >> n >> a >> b;
    cout << min(n*a, b) << '\n';

    return 0;
}


Measured memory_bytes: 256
N = int(input())

if int((N // 1.08) * 1.08) == N:
    print(int(N // 1.08))
    exit()
if int((N // 1.08 + 1) * 1.08) == N:
    print(int(N // 1.08 + 1))
    exit()
print(':(')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,x;
  int s=0;
  
  cin >> A >> B;
  
  x=A;
  
  while(x<=B){
    int c=x/1000;
    int d=x%100;
    
    if(x/10000==x%10&&c%10==d/10)
      s++;
    
    x++;
  }
  cout << s << endl;
}

Measured memory_bytes: 256
program main
      implicit none
      integer :: n, i, cnt, np, nq
      integer, allocatable :: p(:), q(:), x(:)
      logical, allocatable :: used(:)

      read *, n
      allocate( p(n) )
      allocate( q(n) )
      read *, p
      read *, q

      allocate( x(n) )
      allocate( used(n) )

      cnt = 0
      x = 1
      used(:) = .false.
      call DFS(1,n) 

      print *, abs(np-nq)
      
contains
recursive subroutine DFS(pos,v)
      implicit none
      integer, intent(in) :: pos,v
      integer :: i, j, k

      if( pos == v+1) then
         cnt = cnt + 1
         k = 0

         do j = 1, n
           if ( x(j) == p(j) ) then
             k = k + 1
           else
             exit
           end if
         end do
         if ( k == n ) np = cnt 

         k = 0
         do j = 1, n
           if ( x(j) == q(j) ) then
             k = k + 1
           else
             exit
           end if
         end do
         if ( k == n ) nq = cnt 

         return
      end if

      do i = 1, v
        if ( .not. used(i) ) then
          x(pos) = i
          used(i) = .true.
          call DFS(pos+1,v)
          used(i) = .false.
        end if
      end do

end subroutine DFS      

end program main


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define sz(c)       int(c.size())
#define rep(i,a,b)  for (int i=a; i<(b); ++i)
#define per(i,a,b)  for (int i=(b)-1; i>=(a); --i)
#define fore(c,...) for (auto __VA_ARGS__:(c))
using namespace std;
typedef long long ll;

struct segtree {
	using Item = bitset<26>;

	int n;
	vector<Item> tr;

	explicit segtree(int sz):n(sz),tr(2*n) {}

	static Item combine(const Item &a, const Item &b) {
		return a|b;
	}

	void build() {
		for (int i=n-1; i>0; --i) {
			tr[i]=combine(tr[2*i], tr[2*i+1]);
		}
	}

	void update(int i, const int x) {
		i+=n;
		tr[i].reset();
		tr[i].set(x);
		for (i/=2; i>0; i/=2) {
			tr[i]=combine(tr[2*i], tr[2*i+1]);
		}
	}

	Item query(int l, int r) const {
		Item resL{}, resR{};
		l+=n;
		r+=n;
		while (l<=r) {
			if (l%2==1) resL=combine(resL, tr[l]);
			if (r%2==0) resR=combine(tr[r], resR);
			l=(l+1)/2;
			r=(r-1)/2;
		}
		return combine(resL, resR);
	}

	Item& operator[](int i) {
		return tr[i+n];
	}
};

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	int N;
	cin>>N;
	string s;
	cin>>s;
	segtree seg(N);
	rep(i,0,N) seg[i].set(s[i]-'a');
	seg.build();

	int Q;
	cin>>Q;
	rep(q,0,Q) {
		int t;
		cin>>t;
		if (t==1) {
			int i;
			char c;
			cin>>i>>c;
			i--;
			// cerr<<i<<" "<<c<<endl;
			seg.update(i,c-'a');
			s[i]=c;
		} else {
			int l,r;
			cin>>l>>r;
			l--,r--;
			// cerr<<s<<endl;
			cout<<seg.query(l,r).count()<<'\n';
		}
	}
}


Measured memory_bytes: 8732
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}

ll f(ll n){
    return n*n*n*n*n;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll n;
    cin>>n;
    map<ll,ll> mp;
    for(ll i=-1000;i<=1000;i++){
        mp[f(i)] = i;
        if(mp.count(f(i)-n)){
            cout << i << " " << mp[f(i)-n] << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,k,sum=0,j;
    cin>>a>>b>>c>>k;
    for(j=0;j<=k;j++)
    {
        for(int i=1;i<=a;i++ )
    {

          if(j>=k)
        {
          break;
        }
        sum+=1;
        j++;



    }

    for(int i=1;i<=b;i++)
    {
        if(j>=k)
        {
            //cnt++;
          break;
        }
        sum+=0;
        j++;

    }
       for(int i=1;i<=c;i++)
     {
         if(j>=k)
        {
          break;
        }
        sum+=-1;
        j++;


    }


    }
    cout<<sum<<endl;
    sum=0;

}


Measured memory_bytes: 3564
#include <stdio.h> 
 
 
int main(){ 
    int h, w; 
    int i, j; 
    while(1){ 
        scanf("%d %d ", &h, &w); 
        if(h==0&&w==0)break; 
        for(i=0;i<h;i++){ 
            for(j=0;j<w;j++){ 
                if(i==0||i==h-1||j==0||j==w-1){ 
                    printf("#"); 
                }else{ 
                    printf("."); 
                }
            }
            printf("\n");
        } 
        printf("\n"); 
    } 
 
 
    return 0; 
}


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

int main(){
  cin >> N;
  long long L[90]={};
  L[0]=2;
  L[1]=1;
  for(int i=2;i<=86;i++){
    L[i]=L[i-1]+L[i-2];
    //if(i==N) return L[i];
  }
  cout << L[N] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

int main(){
  int n;
  cin >> n;
  int i;
  long long sum = 0;

  for(i=1;i<=n;i++){
    if(i%5 != 0 && i%3 != 0){
      sum += i;
    }
  }
  cout << sum << endl;

}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
int main(){
    //freopen("in","r",stdin);
    //freopen("out","w",stdout);
    int n;
    ll m;
    cin >> n >> m;
    map<int,ll> mp;
    while(n--){
        int x;
        ll y;
        cin >> x >> y;
        if(!mp[x])
            mp[x] = y;
        else
            mp[x] += y;
    }
    ll pos = 0;
    int ans = 0;
    fori(i,mp){
        if(pos < m){
            pos += i -> S;
            ans = i -> F;
        }
    }
    cout << ans << '\n'; 
    return 0;
}   

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

using namespace std;

#define f first
#define s second
#define pub push_back
#define pob pop_back

typedef vector<int> vi;
typedef vector<vi> graf;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vii> wgraf;

typedef vector<double> vd;
typedef pair<double,double> dd;
typedef vector<dd> vdd;

typedef uint64_t ui64;

int main(){

	string s;
	cin >> s;

	for(int i = 0; i < (int)s.size(); i++){

		if(!(i%2) && s[i] == 'L'){

			cout << "No" << endl;
			return 0;

		}

		if(i%2 && s[i] == 'R'){

			cout << "No" << endl;
			return 0;
 
		}
		
	}

	cout << "Yes" << endl;


	return 0;
}


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

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

    string s;
    cin >> s;
    
    string t = s;
    
    reverse(t.begin(), t.end());
    
    int cnt = 0;
    
    for(int i = 0; i < (int)s.size(); i++){
        if(s[i] != t[i]) cnt++;
    }
    
    cnt /= 2;
    
    cout << cnt << endl;
    
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int i,j,k;
    int count;
    int b,f,r,v;
    int a[4][3][10]={0};

    scanf("%d",&count);

    for(i=0;i<count;i++){
        scanf("%d %d %d %d",&b,&f,&r,&v);
        a[b-1][f-1][r-1] += v;
    }

    for(i=0;i<4;i++){
        for(j=0;j<3;j++){
            for(k=0;k<10;k++){
                printf(" %d",a[i][j][k]);
            }
            printf("\n");
        }
        if(i!=3){
            printf("####################\n");
        }
    }

    return 0;
}





Measured memory_bytes: 2704
N, Q = map(int, input().split())
rcx = [tuple(map(int, input().split())) for _ in range(Q)]

thres_1, thres_2 = N-2, N-2
nearest_white_1 = [0] * (N-2)
nearest_white_2 = [0] * (N-2)

reverse_count = 0
for rc, x in rcx:
    x = x-2
    if rc == 1:
        if x < thres_1:
            for i in range(x+1, thres_1):
                nearest_white_1[i] = thres_2
            thres_1 = x
            reverse_count += thres_2
        else:
            reverse_count += nearest_white_1[x]
    else:
        if x < thres_2:
            for i in range(x+1, thres_2):
                nearest_white_2[i] = thres_1
            reverse_count += thres_1
            thres_2 = x
        else:
            reverse_count += nearest_white_2[x]

    #print(reverse_count)
    #print(f"thres1:{thres_1} {nearest_white_1}")
    #print(f"thres2:{thres_2} {nearest_white_2}")
    #print('-'*20)

print((N-2)**2 - reverse_count)

Measured memory_bytes: 106656
from itertools import combinations_with_replacement

def calc_cases(num):
  cases = num
  if num == 2: cases += num*(num-1)*3
  elif num >= 3: cases += num*(num-1)*3 + num*(num-1)*(num-2)
  return int(cases)

N,K = map(int,input().split())
num, num2 = 0, 0
if K%2 ==1:
  for i in range(1,N+1):
    if i%K == 0: num +=1
else:
  for i in range(1,N+1):
    if i%K == 0:
      num +=1
    elif i%K == K//2:
      num2 += 1

print(calc_cases(num)+calc_cases(num2))
#print(num, calc_cases(num), num2, calc_cases(num2))

Measured memory_bytes: 3064
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    string o, e;
    cin >> o >> e;
    REP(i, o.size()) {
        cout << o[i];
        if (i < e.size()) {
            cout << e[i];
        }
    }
    cout << endl;
    return 0;
}

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

int main(){

int l,r,d,cnt=0;
cin >> l >> r >> d;
for(int i=l; i<=r; i++){
    if(i%d==0) cnt++;
}
cout << cnt << endl;

}

Measured memory_bytes: 3628
l1 = [1,3,5,7,8,10,12]
l2 = [4,6,9,11]
l3 = [2]
a,b = map(int,input().split())
f = False
if a in l1 and b in l1:
  f = True
if a in l2 and b in l2:
  f = True
print("Yes" if f else "No")

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    a = list(map(int, input().split()))
    cost = float('inf')

    for i in range(-100, 100 + 1):
        total = 0

        for ai in a:
            total += (ai - i) ** 2

        cost = min(cost, total)

    print(cost)


if __name__ == '__main__':
    main()


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

int num(string&s, int&i) {
	int n = 0;
	while (isdigit(s[i]))n = n * 10 + s[i++] - '0';
	return n;
}
int a = 0;
int dfs(string&s, int&i) {
	int b = a++;
	vector<int>v;
	while (s[i] == '[') {
		i++;
		if (isdigit(s[i])) {
			int n = num(s, i); i++;
			v.push_back(n / 2 + 1);
		}
		else v.push_back(dfs(s, i));
	}
	i++;
	sort(v.begin(), v.end());
	int sum = 0;
	rep(j, v.size() / 2 + 1)sum += v[j];
	return sum;
}
int main() {
	int n; scanf("%d", &n);
	rep(i, n) {
		string s; cin >> s;
		int j = 0;
		printf("%d\n", dfs(s, j));
	}
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    int h, w, cnt;
    cin >> h >> w;
    vector<vector<int>> field(h, vector<int>(w));
    vector<i_i> ans;

    rep(i, h){
        rep(j, w){
            cin >> field[i][j];
        }
    }
    bool increaseNext = false;
    cnt = 1;
    rep(hi, h){
        rep(wi, w){
            int chi,cwi;
            chi = hi;
            cwi = wi;
            if(hi % 2 == 1){
                cwi = w - 1 - wi;
            }
            if(increaseNext){
                field[chi][cwi]++;
                ans.push_back(make_pair(chi,cwi));
                increaseNext = false;
            }
            if(cnt == h * w) break;

            if(field[chi][cwi] % 2 == 1){
                field[chi][cwi]--;
                increaseNext = true;
                ans.push_back(make_pair(chi,cwi));
            }
            cnt++;
        }
    }
    int k = ans.size() / 2;
    cout << k << endl;
    rep(i, k){
        cout << ans[2 * i].first + 1 << " " << ans[2 * i].second + 1 << " " << ans[2 * i + 1].first + 1 << " " << ans[2 * i + 1].second + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 5232
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll A,B,C,K;
  cin >> A >> B >> C >> K;
  ll ans=A-B;
  if(K%2!=0){
    cout << -ans << endl;
  }
  else{
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
                     
#define int             long long
#define ld              long double
#define mp              make_pair
#define ff              first
#define ss              second
#define pb              push_back
#define fo(i,n)         for(i=0;i<n;i++)
#define fo1(i,n)        for(i=1;i<=n;i++)
#define FO(i,k,n)       for(i=k;k<=n?i<=n:i>=n;k<=n?i++:i--)
#define all(c)          c.begin(),c.end()
#define rall(c)         c.rbegin(),c.rend()
#define si              set<int>
#define vi              vector<int>
#define mii             map<int,int>
#define pii             pair<int,int>
#define vpii            vector<pii>
#define vvi             vector<vi>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int> >
#define sp(x)           cout<<setprecision(x)<<fixed;
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define in(a,n)         vi a(n);fo(i,n)cin>>a[i];
#define in1(a,n)        vi a(n+1);fo1(i,n)cin>>a[i];
#define w(t)            int t;cin>>t;while(t--)
#define gcd             __gcd
#define lcm(x,y)        x*(y/gcd(x,y))
#define endl            '\n'
#define PI              3.14159265358979323846
const int inf =         1e18;
const int mod =         1e9+7;
void __p(int x) {cout<<x;}
void __p(int32_t x){cout<<x;}
void __p(float x){cout<<x;}
void __p(double x){cout<<x;}
void __p(ld x) {cout<<x;}
void __p(char x){cout <<'\''<<x<<'\'';}
void __p(const char *x){cout <<'\"' <<x<<'\"';}
void __p(const string &x) {cout<<'\"'<<x<<'\"';}
void __p(bool x) {cout<<(x?"true":"false");}
void _p() {cout << "]\n";}
template<typename T,typename V>     void __p(const pair<T,V> &x) {cout<<'{';__p(x.first);cout<<',';__p(x.second);cout<<'}';}
template<typename T>                void __p(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __p(i); cout << "}";}
template <typename T,typename... V> void _p(T t, V... v) {__p(t);if(sizeof...(v))cout<<", ";_p(v...);}
int po(int x,int p,int m = inf) {int ans=1;x%=m;while(p>0){if(p&1)ans=(ans*x)%m;p=p>>1;x=(x*x)%m;}return ans;}
int inv(int x,int m=mod){return po(x,m-2,m)%m;}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout<<"["<<#x<<"]=[";_p(x)
#else 
#define dbg(x...)
#endif
//=================================================================================




const int N=1e6+6;
int n,m,k,x,y,z,a,b,c,d,i,j,l,r,f;








void sol()
{   string s;
    cin>>s;
    x=y=0;
    for(auto c:s)if(c=='A')x++;else y++;
    
    
    
    
    cout<< ((x&&y)?"Yes":"No") <<endl;
}





int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //sp(10);
    // w(t)
    sol();
    return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;

public class Main
{
    int n, k;
    Integer[] l = new Integer[51];
    
    public static void main(String args[])
    {
	new Main().run();
    }
    
    void run()
    {
	in();

	Arrays.sort(l, 0, n, Comparator.reverseOrder());

	int sum = 0;
	for(int i = 0; i < k; i++) sum += l[i];
		
	out(sum);
    }

    void in()
    {
	Scanner sc = new Scanner(System.in);
	n = sc.nextInt();
	k = sc.nextInt();
	for(int i = 0; i < n; i++) l[i] = sc.nextInt();
    }

    void out()
    {
	
    }
    
    void out(int ans)
    {
	System.out.println(ans);
    }
}


Measured memory_bytes: 21844