akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long
#define vi vector <int>
#define pii pair <int, int>
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i,n) for (int i = 0; i < (int) (n); ++ i)
#define foreach(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); ++ it)

inline int read() {
	int x = 0, f = 1, c = getchar();
	for (;!isdigit(c);c = getchar()) if (c == '-') f ^= 1;
	for (; isdigit(c);c = getchar()) x = x * 10 + c - '0';
	return f ? x : -x;
}

vi v, id;
bool cmp(int a, int b) {
	return v[a] < v[b];
}

int main() {
	int n = read();
	rep(i, n) v.pb(read());
	rep(i, n) id.pb(i);
	sort(id.begin(), id.end(), cmp);
	rep(i, n) printf("%d ", id[i] + 1);
	puts("");
	return 0;
}


Measured memory_bytes: 1784
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//ABC179D
//ABC179C
int main(void) {
  long long n, k, i, cou=0, tmp;
  scanf("%lld", &n);
  for(i=1; i < n; i++){
    if(n%i==0)cou+=n/i-1;
    else cou+=n/i;
  }
printf("%lld", cou);
}

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

int main(){
  long long X,Y,A,B,C;
  cin>>X>>Y>>A>>B>>C;
  long long p[A],q[B],r[C];
  
  for (long long i=0;i<A;i++){
    cin>>p[i];
  }
  sort(p,p+A);
  
  long long N[X+Y+C];
  for(long long i=0;i<X;i++){
  N[i]=p[A-1-i];
  }   
  for (long long i=0;i<B;i++){
    cin>>q[i];
  }
  sort(q,q+B);
  
  for(long long i=X;i<X+Y;i++){
    N[i]=q[B-1-i+X];
  }  
  
  for (long long int i=0;i<C;i++){
    cin>>r[i];
  }
  
  //cout<<r[0]<<" "<<r[1]<<endl;
    sort(r,r+C);
  //cout<<r[0]<<" "<<r[1]<<endl;

  for(long long i=0;i<C;i++){
    N[X+Y+i]=r[C-1-i];
  }  

  
  sort(N,N+X+Y+C);
  
  long long V=0;
  for (long long i=C;i<X+Y+C;i++){
    //cout<<i<<" "<<N[i]<<endl;
    V=V+N[i];
  }
  
  cout<<V<<endl;
  return 0;
  
}









Measured memory_bytes: 4864
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#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++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    int N, H, W;
    cin >> N >> H >> W;

    cout << (N - H + 1) * (N - W + 1) << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int n, ansNum;
    double ansBMIabs;

    void run(){
	while(sc.hasNext()){
	    n = sc.nextInt();
	    if(n!=0) {
		ansNum = Integer.MAX_VALUE;
		ansBMIabs = Double.MAX_VALUE;
		solve();
	    }
	}
    }

    void solve(){
	while(n>0){
	    n--;
	    int id = sc.nextInt();
	    double h = sc.nextDouble()/100;
	    double w = sc.nextDouble();
	    double abs = Math.abs(22 - (w/h/h));
	    //System.out.println(id+" "+abs);
	    if(abs<=ansBMIabs){
		ansNum = id;
		ansBMIabs = abs;
	    } 
	    else if(abs==ansBMIabs && id<ansNum){
		ansNum = id;
		ansBMIabs = abs;
	    }
	}

	System.out.println(ansNum);
    }
}

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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int m;
  cin >> m;
  ll n = 0;
  ll sum = 0;
  rep(i, m) {
    int d;
    ll c;
    cin >> d >> c;
    n += c;
    sum += d * c;
  }
  if (sum >= 10)
    n += (sum - 1) / 9;
  cout << n - 1 << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

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

int main()
{
  int A, B;
  cin >> A >> B;
  int ans = -1;
  if (1 <= A && A <= 9 && 1 <= B && B <= 9)
    ans = A * B;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A;
  cin >> A;
  string op;
  cin >> op;
  int B;
  cin >> B;
  if(op=="+") {
    cout << A+B << endl;}
  else {
    cout << A-B << endl;}
  }
    
  
  


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(long long i=0;i<(n);++i)
#define Fr(i,n) for(long long i=1;i<=(n);++i)
#define ifr(i,n) for(long long i=(n)-1;i>=0;--i)
#define iFr(i,n) for(long long i=(n);i>0;--i)
using Graph = vector<vector<int>>;
 
  int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  char a;
  cin>>a;
  fr(i,26){
    if(a=='a'+i) 
    {cout<<'a';
    exit(0);}
  }
  cout<<'A';
}


Measured memory_bytes: 3620
// In the name of God

#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<int> ch[26];
signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	string s, t;
	cin >> s >> t;
	for(int i=0;s[i];i++) ch[s[i]-'a'].push_back(i);
	int ans = 1, last=-1;
	for(int i=0;t[i];i++) {
		int c = t[i]-'a';
		if(ch[c].size()==0) {
			cout << -1;
			exit(0);
		}
		if(ch[c].back()<=last) {
			ans++;
			last=ch[c][0];
			continue;
		}
		auto it = upper_bound(ch[c].begin(), ch[c].end(), last);
		last = *it;
	}
	ans = (ans-1)*(long long)s.size();
	ans += last + 1;
	cout << ans;
	return 0;
}


Measured memory_bytes: 1736
mod=10**9+7
def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y//2)**2 % mod
    else            : return power(x, y//2)**2 * x % mod
def mul(x,y):
  return (x%mod)*(y%mod)%mod
def add(x,y):
  return (x+y)%mod

n=int(input())
alist=list(map(int,input().split()))
s=sum(alist)%mod
print(mul(add(mul(s,s),-sum(mul(a,a) for a in alist)),power(2,mod-2)))

Measured memory_bytes: 93924
/*
    Author:zeke

    pass System Test!
    GET AC!!
*/
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
// cout << "Case #" << index << " :IMPOSSIBLE";
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll n,k;
    cin>>n>>k;
    V vec(n);
    rep(i,k){
        ll d;
        cin>>d;
        rep(j,d){
            ll x;
            cin>>x;
            x--;
            vec[x]++;
        }
    }
    ll res=0;
    rep(i,n){
        if(!vec[i]){
            res++;
        }
    }
    cout<<res<<endl;
}


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

int main() {
	long long xs, ys, xt, yt, N;
	cin >> xs >> ys >> xt >> yt >> N;

	N += 2;
	vector<long double> x(N), y(N), r(N);
	x[0] = xs;
	y[0] = ys;
	x[1] = xt;
	y[1] = yt;

	for(int i = 2; i < N; ++i) {
		cin >> x[i] >> y[i] >> r[i];
	}

	priority_queue<pair<long double, int>> pq;
	pq.push({0, 0});

	vector<bool> visited(N);
	vector<long double> distances(N);

	while(!pq.empty()) {
		long double d; int i;
		tie(d, i) = pq.top(); d = -d;
		pq.pop();

		if(visited[i]) continue;

		visited[i] = true;
		distances[i] = d;

		for(int j = 0; j < N; ++j) {
			if(visited[j]) continue;

			pq.push({
				-(d + max(0.0l, hypot(x[j] - x[i], y[j] - y[i]) - r[i] - r[j])),
				j,
			});
		}
	}

	printf("%.10lf", (double)distances[1]);

	return 0;
}


Measured memory_bytes: 18796
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        List<Integer> list = new ArrayList<Integer>();
        
        for(int i=0;i<N;i++){
            list.add(sc.nextInt());
        }
        
        Collections.sort(list);
        
        //System.out.println(list.get(0));
        
        double value = list.get(0);
        
        for(int i=1;i<N;i++){
            value = (value + list.get(i))/2;
            //System.out.println(value);
        }
        
        System.out.println(value);
        
    }
}


Measured memory_bytes: 35712
#include<stdio.h>
int main(void)
{
    int a,b;
    char op;
    for(;;)
    {
        scanf("%d %c %d",&a,&op,&b);
        if(op=='?') break;
        switch(op)
        {
            case '+' : printf("%d\n",a+b); break;
            case '-' : printf("%d\n",a-b); break;
            case '*' : printf("%d\n",a*b); break;
            case '/' : printf("%d\n",a/b); break;
        }
    }
    return 0;
}


Measured memory_bytes: 2104
n = gets.to_i

result = []
commands = []

n.times do
  commands << gets.chomp
end

commands.each do |command|
  if command.include?(' ')
    command, num = command.split

    case command
    when 'insert'
      result.unshift(num)
    when 'delete'
      index = result.find_index(num)
      result.delete_at(index) if index
    end
  else
    case command
    when 'deleteFirst'
      result.shift
    when 'deleteLast'
      result.pop
    end
  end
end

puts result.join(' ')

Measured memory_bytes: 277020
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define erep(i,a,b) for(int i=a;i<=(int)(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>(a);i--)
#define eper(i,a,b) for(int i=((int)(a));i>=b;i--)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

string a, b;
int ans;
void check(string s) {
    bool flag = true;;
    rep(i, 0, s.size()) {
        if (s[i] == s[s.size()-1-i]) flag = true;
        else {
            flag = false;
            break;
        }
    }
    if (flag) ans++;
}   
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> a >> b;
    erep(i, stoi(a), stoi(b)) {
        check(to_string(i));
    }
    cout << ans << endl;
    return 0;
}


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

const ll INF = 1ll<<60;

typedef pair<ll,ll> P;

int main() {
  ll n, x, d;
  cin >> n >> x >> d;
  if (d==0){
    if(x==0){
      cout<<1;
      return 0;
    }
    else{
      cout<<n+1;
      return 0;
    }
  }

  if (d<0){
    d=-d;
    x=-x;
  }

  map<ll,vector<P>> mp;
  rep(i,n+1){

    ll mink=(i-1)*i/2;
    ll maxk=i*(2*n-i-1)/2;
    ll ix=i*x;
    ll rem=(ix+(d<<30))%d;
    ll front=(ix-rem)/d+mink;
    ll len=maxk-mink;
    ll s = ix+mink*d;//初項
    mp[(s+(d<<30))%d].emplace_back(s,len);

/*
    ll s = x*i;
   ll l = (ll)i*(i-1)/2;//iの和のmin
   ll r = l + (ll)i*(n-i);//iの和のmax
   s += l*d;//初項
   r -= l;//初項から最終項までのながさ（dで割っている）
   mp[(s+(d<<30))%d].emplace_back(s,r);//負の値がかえらないように十分大きくしている
*/
  }


  ll cnt=0;
  /*
  for(auto a:mp){
    auto A=a.second;
    sort(A.begin(),A.end());
    ll start=A[0].first;

    ll numA=A.size();
    ll now=start+A[0].second;
    //ll end=now;
    ll cnt1=0;
    rep(i,numA-1){
      if (A[i+1].first>now+1){
        cnt1+=A[i+1].first-now-1;
      }
      now=max(now,A[i+1].first+A[i+1].second);
  //    end=max()
    }

    ll sumall=now-start+1;
  //  cout<<sumall<<'s'<<cnt1<<'c'<<endl;
    cnt+=sumall-cnt1;

  }
  */
  ll ans=0;
  for (auto p : mp) {
    auto a = p.second;//(s,r)
    int m = a.size();
    rep(i,m) a[i].first = (a[i].first-p.first)/d;//初項から初項%dを引いてdで割る
    vector<P> ev;//event first:いつ　second:+1 or -1　
    //１以上になっている区間の長さがわかればok、区間の始まりを+1, 終わりを-1とする

    rep(i,m) {
      ev.emplace_back(a[i].first, 1);//初項を１に
      ev.emplace_back(a[i].first+a[i].second+1, -1);//初項＋長さを−１に
    }
    sort(ev.begin(), ev.end());
    ll cnt = 0, pre = -INF;//cnt:いま何個の区間に覆われているか pre:直前のイベント
    for (auto e : ev) {
      ll len = e.first-pre;//直前のイベントからのながさ
      if (cnt) ans += len;
      cnt += e.second;
      pre = e.first;
    }
  }
cout<<ans;
}


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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 1010;

int cnt[N];
string s;

int main()
{
    cin >> s;
    for(int i = 0; i < s.size(); i++)
        cnt[s[i] - 'a']++;

    for(int i = 0; i < 26; i++)
        if(cnt[i] & 1)
        {
            puts("No");
            return 0;
        }
    puts("Yes");
    return 0;
}


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

int Q(int n){
  if(1<=n&&n<=6){
    return n+1;
  }
  if(7<=n&&n<=11){
    return n-5;
  }
  return -1;
}

bool check(string str){
  reverse(str.begin(),str.end());
  
  int x=0;
  for(int n=11;n>=1;n--){
    x+=(str[n]-'0')*Q(n);
    x%=11;
  }

  int checkdigit=-1;
  
  if(x <= 1){
    checkdigit=0;
  }else{
    checkdigit=11-x;
  }

  if( str[0] == checkdigit+'0' ){
    return true;
  }else{
    return false;
  }
}

bool solve(string str,int num){
  for(int i=0;i<(int)str.size();i++){
    if( str[i] == '?' ){
      str[i]=num+'0';
    }
  }
  return check(str);
}

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

  int ans=-1;
  int count=0;
  
  for(int i=0;i<=9;i++){
    if( solve(str,i) ){
      ans=i;
      count++;
    }
  }

  if(count == 1){
    cout<<ans<<endl;
  }else{
    cout<<"MULTIPLE"<<endl;
  }
  return 0;
}



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

int main(){
    int n;
    bool corr=false;
    char s[10];
    scanf("%s",s);
    for(int i = 0 ; i < strlen(s)-1  ; i++){
        if(s[i]=='A'&&s[i+1]=='C'){
            corr=true;
        }
    }
    if(corr){
        printf("Yes");
    }
    else printf("No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int cantor(int *a,int n)
{
	int ans=0;
	for(int i=0;i<n;i++)
	{
		int x=0;int c=1,m=1;//c记录后面的阶乘
		for(int j=i+1;j<n;j++)
		{
			if(a[j]<a[i])x++;
			m*=c;c++;
		}
		ans+=x*m;
	}
	return ans;
}
int main()
{
    ll ans;
    int n,a[9],b[9];
    cin>>n;
    int i;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n;i++)
    {
        cin>>b[i];
    }
    ans=abs(cantor(a,n)-cantor(b,n));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <unordered_map>
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(LLI i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(LLI i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


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

	unordered_map<LLI, vector<LLI>> m(220000);

	LLI n;
	cin >> n;
	vector<LLI> a(n);

	REP(i, n)
	{
		cin >> a[i];

		if (m.count(a[i] - i) == 0)
		{
			m[a[i] - i] = {};
		}

		m[a[i] - i].push_back(i);
	}


	LLI ans = 0;
	REP(i, n)
	{
		if (m.count(-(a[i] + i)) == 0)continue;

		auto& ve = m[-(a[i] + i)];


		LLI add = ve.end() - upper_bound(ve.begin(), ve.end(), i);
		ans += add;
	}

	cout << ans;
	return 0;
}


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

int main(){
    int s,ans=1;
    cin >> s;
    map<int,int> mp;
    mp[s] ++;
    while(mp[s]<=1){
        if(s%2){
            s = 3*s+1;
            ans ++;
            mp[s] ++;
        }else{
            s /= 2;
            ans ++;
            mp[s] ++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	// AtCoder Beginner Contest 136
	// https://atcoder.jp/contests/abc136/tasks
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int res = 0;
		
		for (int i = 1 ; i <= n; i++) {
			if (String.valueOf(i).length() % 2 == 1) {
				res++;
			}
		}
		System.out.println(res);
	}

	static class FastReader { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine()); 
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() { 
            String str = ""; 
            try{ 
                str = br.readLine(); 
            } catch (IOException e) { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
}


Measured memory_bytes: 24148
/// ========== 入力用マクロ ====================================================
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
/// FromStr型, Vec<T: FromStr>, Vec<char>, に対応
/// 入力と平行して処理したいときには使えない
#[macro_export]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[macro_export]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[macro_export]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}


// ========== 常用関数 =======================================================


// 10^9 + 7 で割ったあまりを出力してください
pub const MOD: i64 = 1_000_000_007;

/// 標準入力から
/// 空白文字で囲まれた1つのトークンを
/// 指定の型に変換する
pub fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

/// 標準入力から1行読み取り
/// 空白文字で区切って
/// 指定の型のVecに格納する
pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

/// プログラムを終了
pub fn exit() {
    std::process::exit(0)
}


// Rustの言語アップデートありがたいです
// 頑張ってください！


// ========== main() ==========================================================


fn main() {
    input!{
        n: usize,
        x: [usize; n],
    }
    let mut v = x.clone();
    v.sort();
    for i in &x {
        if i < &v[n/2] {
            println!("{}", v[n/2]);
        } else {
            println!("{}", v[n/2 - 1]);
        }
    }
}


// ========== 以下使い捨て関数 ===================================================



Measured memory_bytes: 10364
///////////////////////////////////////////////////////////////
//__________________________________________________________//
// \\\\\\\\\\\---------------------------------------------//
//          //                 __    __                   // 
//         //     \\\\\\\\    |. \  / .|    /////////    //
//    ///////       ||   \\   |.|\\//|.|   //           //
//    /  // /       ||    \\  |.| \/ |.|  //   /////// //
//    / //  /       ||    //  |.|    |.|  \\     \\    \\
//    ///////      ////////   |.|    |.|   \\\\\\\\\\   \\
//    //                                                 \\
// \\\\\\\\\\\\-------------------------------------------\\
// ________________________________________________________\\
/////////////////////////////////////////////////////////////
 
#include <bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MAX 100005
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define vi vector<ll>
#define vp vector<pii >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define lb(v,x) lower_bound(all(v),x)
#define ub(v,x) upper_bound(all(v),x)
#define sz(x) x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
typedef long long ll;
using namespace std;
 
ll modexp(ll base,ll exp){
    if(exp==1)return base;
    else if(exp==0)return 1;
    else{
        if(exp%2 == 0){
            ll base1=pow(modexp(base, exp/2),2);
            if(base1 >= MOD)
            return base1%MOD;
            else return base1;
        }
        else{
            ll ans = (base *  pow(modexp(base,(exp-1)/2),2));
            if(ans >= MOD)return ans%MOD;
            else return ans;
        }
    }
}
 
ll gcd(ll a,ll b){
    if(!a)return b;
    return gcd(b%a,a);
}

int main(){
    IOS

    ll n,x;
    cin>>n>>x;
    ll d=gcd(n,x);
    cout<<3*(n-d);
}

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

void fnInput(int &rnMaxSiz, vector<int> &rvnBSort, int &rnMaxElm)
{
  rnMaxElm = 0;
  cin >> rnMaxSiz;

  rvnBSort.resize(rnMaxSiz);
  for (int i = 0; i < rnMaxSiz; i++)
  {
    cin >> rvnBSort[i];
    rnMaxElm = max(rnMaxElm, rvnBSort[i]);
  }
}

void fnCntSort(const vector<int> &cnrvnBSort,vector<int> &rvnASort, int nMaxElm)
{
  vector<int> vnCnt;
  vnCnt.resize(nMaxElm);

  for (int i = 0; i < cnrvnBSort.size(); i++)
    vnCnt[cnrvnBSort[i]]++;

  for (int i = 1; i <= nMaxElm; i++)
    vnCnt[i] += vnCnt[i - 1];

  for (int i = cnrvnBSort.size() - 1; i >= 0; i--)
  {
    rvnASort[vnCnt[cnrvnBSort[i]] - 1] = cnrvnBSort[i];
    vnCnt[cnrvnBSort[i]]--;
  }
}

void fnResult(const vector<int> &cnrvnASort)
{
  for (int i = 0; i < cnrvnASort.size(); i++)
  {
    if (i)  cout << " ";
    cout << cnrvnASort[i];
  }
  cout << endl;
}

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

  int nMaxSiz, nMaxElm;
  vector<int> vnBSort, vnASort;

  fnInput(nMaxSiz, vnBSort, nMaxElm);
  vnASort.resize(nMaxSiz);

  fnCntSort(vnBSort, vnASort, nMaxElm);
  fnResult(vnASort);

  return 0;
}

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

int bit[200010], N;

int sum(int i){
	int s = 0;
	while(i>0){
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(int i, int x){
	while(i<=N){
		bit[i] += x;
		i += i & -i;
	}
}

int main(){
	string S; cin >> S;
	N = S.size();
	vector<int> n[26];
	rep(i, N){
		int num = S[i] - 'a';
		n[num].push_back(i);
	}
	if(N % 2 == 1){
		int f = 0, odd;
		vector<PP> arr;
		rep(i, 26){
			rep(j, n[i].size()/2){
				arr.push_back({n[i][j], {i, j}});
			}
			if(n[i].size() % 2 == 1){ f++; odd = i; }
		}
		if(f > 1){
			cout << -1 << endl;
			return 0;
		}
		sort(ALL(arr));
		int ans[N];
		ans[N/2] = n[odd][n[odd].size()/2];
		rep(i, N/2){
			ans[i] = arr[i].first;
			int ch = arr[i].second.first, ind = arr[i].second.second;
			int si = n[ch].size();
			ans[N - 1 - i] = n[ch][si-ind-1];
		}
		ll res = 0;
		rep(i, N){
			res += i - sum(ans[i]+1);
			add(ans[i]+1, 1);
		}
		cout << res << endl;
	}else{
		vector<PP> arr;
		rep(i, 26){
			rep(j, n[i].size()/2){
				arr.push_back({n[i][j], {i, j}});
			}
			if(n[i].size() % 2 == 1){ cout << -1 << endl; return 0;}
		}
		sort(ALL(arr));
		int ans[N];
		rep(i, N/2){
			ans[i] = arr[i].first;
			int ch = arr[i].second.first, ind = arr[i].second.second;
			int si = n[ch].size();
			ans[N - 1 - i] = n[ch][si-ind-1];
		}
		ll res = 0;
		rep(i, N){
			res += i - sum(ans[i]+1);
			add(ans[i]+1, 1);
		}
		cout << res << endl;
	}
	return 0;
}


Measured memory_bytes: 4724
#include <iostream>

using namespace std;

int main()
{
	int d[5];
	string answ;
	int k,ans=0;
	for (int i = 0; i < 5; i++) {
		cin >> d[i];
	}
	
	cin >> k;
	
	for (int i = 0; i < 5; i++) {
		for (int g = i; g < 5; g++) {
			if (d[g] - d[i] > k)
				ans++;
		}
	}

	if (ans == 0) {
		answ = "Yay!";
	}
	else {
		answ = ":(";
	}

	cout << answ << "\n";

}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
using ll = long long;

const long double PI = acos(-1.0);
const int MOD = 1e9 + 7;

int main() {
    int x;
    cin >> x;

    int now = 0;
    int ans = 0;
    while(true) {
        now += x;
        ans++;
        if(now % 360 == 0) break;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
const int maxn = 123456;
vector<pair<int,int> > e[maxn];
long long dist[maxn];
void dfs(int u, int v){
  for(auto ee : e[u]){
    if(ee.first == v) continue;
    dist[ee.first] = dist[u] + ee.second;
    dfs(ee.first, u);
  }
}
int main(){
  int n; cin >> n;
  for(int i = 0; i < n - 1; i++){
    int a, b, c; cin >> a >> b >> c;
    e[a].push_back({b, c});
    e[b].push_back({a, c});
  }
  int q, k; cin >> q >> k;
  dfs(k, 0);
  for(int i = 0; i < q; i++){
    int x, y; cin >> x >> y;
    cout << dist[x] + dist[y] << endl;
  }
  return 0;
}

Measured memory_bytes: 13312
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <limits.h>
#define int long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;
const int INF = LLONG_MAX/3;

signed main(){
	int n;
	cin>>n;
	string s="";
	while(1){
		int a=n/-2;
		if(n-a*-2<0){
			a+=1;
			a=n-a*-2;
		}else{
			a=n-a*-2;
		}
		n=(n-a)/-2;
		s+=to_string(a);
		if(n==0)break;
	}
	reverse(s.begin(),s.end());
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace::std;
typedef long long lint;
typedef long double ldouble;
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
#define repi(i,a,b) for(lint i=lint(a);i<lint(b);i++)
#define rep2(i,a,b,c) for(lint i=lint(a);i>lint(b);i+=c)
#define all(x) (x).begin(),(x).end()
#define sl(c) (('a')<=(c)&&(c)<=('z'))
#define ll(c) (('A')<=(c)&&(c)<=('Z'))
#define PI 3.141592653589793
#define cout (cout<<fixed<<setprecision(15))
#define makeupper(t) (transform(all(t),t.begin(),::toupper))
#define makelower(t) (transform(all(t),t.begin(),::tolower))
#define dist(x1,y1,x2,y2) (pow(pow(x2-x1,2)+pow(y2-y1,2),0.5))
#define sum(a) accumulate(all(a),0)
#define NEXT_LINE string junk; getline(cin, junk);
#define output(v,s) do{rep(i,v.size())cout<<(i?s:"")<<v[i];cout<<"\n";}while(0)
inline string replace(string str, string before, std::string after) {
	string::size_type  Pos(str.find(before));
	while (Pos != std::string::npos) {
		str.replace(Pos, before.length(), after);
		Pos = str.find(before, Pos + after.length());
	}
	return str;
}
inline vector<string> split(string &s, string delim) {
	vector<string> elems;
	s=replace(s, "#", "HASH");
	s=replace(s, delim,"#");
	stringstream ss(s);
	string item;
	while (getline(ss, item, '#')) {
		elems.push_back(replace(item, "HASH", "#"));
	}
	return elems;
}
inline vector<int> cross(vector<int> a, vector<int> b) {
    return { a[1] * b[2] - a[2] * b[1],a[2] * b[0] - a[0] * b[2],a[0] * b[1] - a[1] * b[0] };
}
inline int GCD(int a, int b) {
    if (a < b)swap(a, b);
    if (a%b != 0)GCD(b, a%b);
    else return b;
}
inline vector<lint> primeList(lint n) {
    vector<bool> p(n+1);
    vector<lint> list;
    repi(i,1, n+1)p[i] = true;
    repi(i,2,sqrt(n)+1) {
        if (p[i]) {
            repi(j,2,n/i+1) {
                p[i*j] = false;
            }
        }
    }
    repi(i, 2, n+1)if (p[i])list.push_back(i);
    return list;
}
inline bool isPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0)return false;
    }
    return true;
}
template<typename T>class Stack{
    vector<T> stack;
    public:
        void push(T num) {
            stack.push_back(num);
        }
        T pop() {
            T num = stack[stack.size() - 1];
            stack.erase(stack.end() - 1);
            return num;
        }
};
template<typename T>class Queue{
    deque<T> queue;
    public:
        void push(T num) {
            queue.push_front(num);
        }
		void push_back(T num){
			queue.push_back(num);
		}
        T pop() {
            T num = queue[queue.size()-1];
            queue.pop_back();
            return num;
        }
        bool empty(){
            return queue.empty();
        }
};
int main(){
    string s;
    cin>>s;
    int a0=0,a1=0;
    for(char c:s){
        if(c-'0')a1++;
        else a0++;
    }
    cout<<min(a0,a1)*2<<"\n";
}

Measured memory_bytes: 512
#スペース区切りの整数の入力
A, B ,K = map(int, input().split())

if(K>=A):
  nokori = K - A
  ans = B - nokori
  if(ans<0):
    ans = 0
  print("0",ans)
else:
  nokori = A - K
  if(nokori<0):
    nokori = 0
  print(nokori,B)

Measured memory_bytes: 3060
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector< int > vi;
typedef pair< int , int > pi;
typedef set< int > se;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define Fn 1.618033987
int main() 
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    vector< ll >X(n);
    vector< ll >Y(n);
    REP(i,0,n-1)
    {
        ll x,y;
        cin>>x>>y;
        ll a=(x+y);
        ll b=(y-x);
        X[i]=a;
        Y[i]=b;
    }
    sort(X.begin(),X.end());
    sort(Y.begin(),Y.end());
    ll ans=LLONG_MIN;
    REP(i,1,n-1)
    {
        ll A=abs(X[0]-X[i]);
        ll B=abs(Y[0]-Y[i]);
        ans=max({ans,A,B});
    }
    cout<<ans<<'\n';
    return 0; 
}


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

int main(){
int N;

cin >> N;
if(105 > N){
  cout << "0" << endl;
}else if(135 > N){
  cout << "1" << endl;
}else if(165 > N){
  cout << "2" << endl;
}else if(189 > N){
  cout << "3" << endl;
}else if(195 > N){
  cout << "4" << endl;
}else if(201>N){
  cout << "5" << endl;
}

}


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

int main(){
	string a,b;
	cin >> a >> b ;
	int count = 0;
	for(int i = 0;i < 3;i++ ){
		if(a[i] == b[i]){
			count++;
		}

	}
	cout << count << endl;
	
	
}

Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int m,n;
    scanf("%d%d",&n,&m);
    if(n*10000<m){
        printf("-1 -1 -1");
        return 0;
    }
    if(n*1000>m){
        printf("-1 -1 -1");
        return 0;
    }
    if(m%1000!=0){
        printf("-1 -1 -1");
        return 0;
    }
    for(int i=0;i<=n;i++)
     for(int j=0;j<=n;j++)
      for(int k=0;k<=n,i+j+k<=n;k++)
       {
            if(i+j+k==n && i*1000+j*5000+k*10000==m)
            {
                printf("%d %d %d",k,j,i);
                return 0;   
            }
       }
    printf("-1 -1 -1");
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	  public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int n = sc.nextInt();
	    int m = sc.nextInt();
	    
	    int[] a = new int[m];
	    for (int i = 0; i < a.length; i++) {
			a[i] = n;
		}
	    
	    int[] b = new int[n];
	    for (int i = 0; i < b.length; i++) {
			b[i] = m;
		}
	    
	    if (n <= m) {
	    	for (int i : a) {
				System.out.print(i);
			}
	    } else {
	    	for (int i : b) {
				System.out.print(i);
			}
	    }
	    
	  }
	}

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

int main(){
  std::string S, T;
  std::cin >> S >> T;
  if (S.size() + 1 == T.size()){
    T.pop_back();
    if (S == T){
      std::cout << "Yes";
      return 0;
    }
  }
  std::cout << "No";
  return 0;
}

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

#define X first
#define Y second
#define mp make_pair
#define pb pop_back
#define eb emplace_back
#define sz(v) (int) v.size()

using namespace std;

typedef long long LL;
typedef long double LD;

void solve() {
	string a, b;
	cin >> a >> b;
	int ans = 0;
	for (int i = 0; i < 3; ++i) {
		ans += (a[i] == b[i]);
	}
	cout << ans << "\n";
}

signed main() {
// #define TASK ""
#if !defined(LOCAL) && defined(TASK)
	freopen(TASK".in", "r", stdin);
	freopen(TASK".out", "w", stdout);
#endif
	ios::sync_with_stdio(0); cin.tie(0);
	int tests = 1;
	// cin >> tests;
	while (tests--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
n,a,b=map(int, input().split())  
mod=10**9+7

def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a


def combmod(n, k, mod):
    a=1
    for i in range(n-k+1,n+1):
        a*=i
        a%=mod
    c=framod(k, mod)
    return (a * pow(c, mod-2, mod)) % mod

if n>2:
    print((pow(2,n,mod)-1-combmod(n,a,mod)-combmod(n,b,mod)+mod)%mod)
elif n==2:
    print('0')

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

using namespace std;

int main() {
  std::string s;
  int w;
  std::cin >> s >> w;
  int const n = s.length();
  for (int i = 0; i < n; i += w) {
    std::cout << s[i];
  }
  return 0;
}


Measured memory_bytes: 256
import itertools

N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]

count = 0
for path in itertools.permutations([i for i in range(2, N+1)], N-1):
  flag = True
  if [1, path[0]] in ab or [path[0], 1] in ab:
    pass
  else:
    flag = False
    continue
  for i in range(1, N):
    if flag:
      if i == N-1:
        count += 1
        continue
      if [path[i-1], path[i]] in ab or [path[i], path[i-1]] in ab:
        continue
      else:
        flag = False
print(count)


Measured memory_bytes: 42860
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

A = get_int
B = get_int
C = get_int
D = get_int
E = get_int

test = [A, B, C, D, E]
test = test.map { |x| [x, (x % 10 == 0) ? 10 : x % 10] }.sort { |a, b| a[1] <=> b[1] }.reverse

count = 0
test[0...-1].each do |x, _|
  count += (x / 10 + (x % 10 > 0 ? 1 : 0)) * 10
end

count += test.last[0]

puts count


Measured memory_bytes: 14376
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
int ans=0;
int x = Integer.parseInt(sc.next());
int t = Integer.parseInt(sc.next());
ans=max(x-t,0);
out.println(ans);
}
}

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

using namespace std;

int main(){
    long int a,b,c;
    cin >> a >> b >> c;
    long int cab=c-a-b;
    long int right=cab*cab;
    if(cab<0){
        cout << "No";
    }else if(right%4==0){
        right=right/4;
        if(a*b<right){
            cout << "Yes";
        }else{
            cout << "No";
        }
    }else{
        right=right/4;
        if(a*b<=right){
            cout << "Yes";
        }else{
            cout << "No";
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<cmath>
 
#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)
 
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9
#define MOD 1000000007
 
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; }
typedef long long ll;
typedef std::pair<ll, ll> P;
int gcd(ll a,ll b){return b?gcd(b,a%b):a;}
 
 
using namespace std;

int main()
{
    int n;
    cin >> n;
    ll ans = 0;
    rep(i, n){
        ll tmp;
        cin >> tmp;
        ans += (tmp-1);
    }
    cout << ans;

}

Measured memory_bytes: 256
def kumiawase(num):
    return num + 3*num*(num-1) + num*(num-1)*(num-2)

n, k = list(map(int, input().split()))
if k%2 == 1:
    ans = kumiawase(n//k)
else:
    m = k//2
    ans = kumiawase(n//k) + kumiawase(n//m - n//k)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define MAX 1001
const char INF = '#';
const int MM = 10000000;
typedef pair<int,int> P;

int num,d[MAX][MAX],n,m;
int dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};
char field[MAX+1][MAX+1];

int bfs(int sy,int sx,int gy,int gx){
    queue<P> que;
    for(int i = 0 ; i < n ; i++)
        for(int j = 0 ; j < m ; j++)
            d[i][j] = MM;
    
    que.push(P(sy,sx));
    d[sy][sx] = 0;
    
    while(que.size()){
        P p = que.front(); que.pop();
        if(p.first == gy && p.second == gx) break;
        
        for(int i = 0 ; i < 4 ; i++){
            int nx = p.first+dx[i];
            int ny = p.second+dy[i];
            
            if(0 <= nx && nx < n && 0 <= ny && ny < m && field[nx][ny] != 'X'
               &&d[nx][ny] == MM){
                que.push(P(nx,ny));
                d[nx][ny] = d[p.first][p.second]+1;
            }
        }
    }
    
    return d[gy][gx];
}

int main(){
    fill(field[0],field[MAX],INF);

    cin >> n >> m >> num;
    vector<P> v(num+1);
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < m ; j++){
            cin >> field[i][j];
            if(field[i][j]=='S'){
                v[0].first = i;
                v[0].second = j;
            }
            if('0' <= field[i][j] && field[i][j] <= '9'){
                v[field[i][j]-'0'].first = i;
                v[field[i][j]-'0'].second = j;
            }
        }
    }

    int ans = 0;
    for(int i = 1 ; i < num+1 ; i++){
        ans += bfs(v[i-1].first,v[i-1].second,v[i].first,v[i].second);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6112
def solve():
    l = len(S)
    R  = [-1]*26
    R1 = [-1]*26
    is_ok = True
    for i in range(l):
        S_num = ord(S[i]) - ord("a")
        T_num = ord(T[i]) - ord("a")
        if R[S_num] == -1:
            R[S_num] = T_num
        else:
            if R[S_num] != T_num:
                is_ok = False
                break
        if R1[T_num] == -1:
            R1[T_num] = S_num
        else:
            if R1[T_num] != S_num:
                is_ok = False
                break
        
    if is_ok:
        print("Yes")
    else:
        print("No")


if __name__=="__main__":
    S = input()
    T = input()
#    S = [c for c in s]
#    T = [c for c in t]
    solve()


Measured memory_bytes: 9352
num = input()
lst1 = list(map(int, num.split()))
n = lst1[0]
m = lst1[1]
lst2 = []
lst3 = []
s = 0
for i in range(n):
    line = input()
    lst2.append(list(map(int, line.split())))
#print(lst2)
for i in range(m):
    line = input()
    lst3.append(list(map(int, line.split())))
#print(lst3)
for i in range(n):
    for j in range(m):
        s += lst2[i][j]*lst3[j][0]
        #print(lst2[i][j]*lst3[j][0])
    print(s)
    s = 0
        


Measured memory_bytes: 6024
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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() {
  char X, Y;
  cin >> X >> Y;
  if (X < Y) {
    cout << "<" << endl;
  } else if (X > Y) {
    cout << ">" << endl;
  } else {
    cout << "=" << endl;
  }
}

Measured memory_bytes: 256
fn main() {
    proconio::input! {
        n: usize,
        a: [u64; n],
    }

    println!("{}", DP::new(n, a).calc(0, n - 1));
}

struct DP {
    dp: Vec<Vec<Option<u64>>>,
    cum: Vec<u64>,
}

impl DP {
    fn new(n: usize, a: Vec<u64>) -> DP {
        let mut cum = vec![0; n + 1];
        for i in 1..=n {
            cum[i] = cum[i - 1] + a[i - 1];
        }
        DP {
            dp: vec![vec![None; n]; n],
            cum: cum,
        }
    }

    fn calc(&mut self, l: usize, r: usize) -> u64 {
        if let Some(v) = self.dp[l][r] {
            v
        } else {
            let v = if l == r {
                0
            } else {
                let mut v = std::u64::MAX;
                for m in l..r {
                    v = std::cmp::min(v, self.calc(l, m) + self.calc(m + 1, r))
                }
                v + self.cum[r + 1] - self.cum[l]
            };
            self.dp[l][r] = Some(v);
            v
        }
    }
}


Measured memory_bytes: 4608
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
n, q = map(int, input().split())

trees = [ [] for i in range(n+1) ]
for i in range(n-1):
    a, b = map(int, input().split())
    trees[a].append(b)
    trees[b].append(a)

values = [ 0 for i in range(n+1) ]
for i in range(q):
    p, x = map(int, input().split())
    values[p] += x
#print(values)

def dfs2(i, parent):
    for j in trees[i]:
        if j == parent: continue
        values[j] += values[i]
        dfs2(j, i)

dfs2(1, -1)
print(*values[1:])


Measured memory_bytes: 230892
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(int X = 0; X < N; X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back

using namespace std;

class plan{
public:
    int t;
    int x;
    int y;

    plan();
    plan(int time, int xi, int yi){
        t = time;
        x = xi;
        y = yi;
    }

};

int main(){

    int n;
    cin >> n;

    vector<plan> v;

    v.push_back(plan(0,0,0));

    rep(i,n){
        int t,x,y;
        cin >> t >> x >> y;

        v.push_back(plan(t,x,y));
    }

    bool ans = true;

    rep(i,n){
        int time = v[i + 1].t - v[i].t;
        int d = abs(v[i + 1].x - v[i].x) + abs(v[i + 1].y - v[i].y);

        if(time < d || time % 2 != d % 2){
            ans = false;
        }

        if(!ans) break;
    }

    if(ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

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

int main(){
   string s;
   cin >> s;
   int cnt = 0;
   rep(i,s.size()/2){
      if (s[i] != s[s.size() - 1 - i]) cnt++;
   }
   cout << cnt << endl;

   return 0;
   

}


Measured memory_bytes: 3632
a, b = map(int, input().split())
array = list(map(int, input().split()))
impossible = "IMPOSSIBLE"
possible = "POSSIBLE"

array = list(set(array))

if len(array) == 1:
    if b == array[0]:
        print(possible)
    else:
        print(impossible)
    exit(0)

array.sort()

btw = [v1 - v2 for v1, v2 in zip(array[1:], array[0:])]
n = sorted(btw)[0]

same = len(set(btw)) == 1 or all([v % n == 0 for v in btw])

if b in array:
    print(possible)
elif array[-1] < b:
    print(impossible)
elif same and (b - array[0]) % n == 0:
    print(possible)
else:
    print(impossible)


Measured memory_bytes: 14604
import math
import copy

n = int(input())
# k, x = [int(i) for i in input().split()]
#table = [[int(i) for i in input().split()] for j in range(n)]
# table = [list(input()) for n in range(h)]
b = [int(i) for i in input().split()]

#num = [int(i) for i in range(n)]
# s = [input() for i in range(n)]
# s = input()
# list = list(s)
# dp = [[0 for _ in range(2)] for _ in range(13)]
#s = [input() for i in range(n)]

kotae = 0

for i in range(n) :
    if (i == 0) :
        kotae += b[0]
    elif (i < n-1) :
        kotae += min(b[i],b[i-1])
    else :
        kotae += b[n-2]

print(kotae)

Measured memory_bytes: 3572