akhauriyash/Code-Regression huggingface dataset:
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)


def main():
    N, X, Y = LI()
    X -= 1
    Y -= 1
    dist = [[N] * N for _ in range(N)]

    q = deque()
    for i in range(N):
        q.append(i)
        dist[i][i] = 0
        while q:
            u = q.popleft()
            if u < N - 1:
                if dist[i][u + 1] > dist[i][u] + 1:
                    q.append(u + 1)
                    dist[i][u + 1] = dist[i][u] + 1
            if u >= 1:
                if dist[i][u - 1] > dist[i][u] + 1:
                    q.append(u - 1)
                    dist[i][u - 1] = dist[i][u] + 1
            if u == X:
                if dist[i][Y] > dist[i][u] + 1:
                    q.append(Y)
                    dist[i][Y] = dist[i][u] + 1
            if u == Y:
                if dist[i][X] > dist[i][u] + 1:
                    q.append(X)
                    dist[i][X] = dist[i][u] + 1

    cnt = [0] * N

    for i in range(N):
        for j in range(i + 1, N):
            cnt[dist[i][j]] += 1

    for i in cnt[1:]:
        print(i)


main()


Measured memory_bytes: 141208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    ll H, W;
    cin >> H >> W;
    ll ans;
    ll a, b, c;
    ans = INF;
    if(W%3 == 0){
        ans = 0;
    }
    else{
        ans = min(ans, H);
    }
    if(H%3 == 0){
        ans = 0;
    }
    else{
        ans = min(ans, W);
    }
    
    for (int i = 1; i < H; i++) {
        a = W*i;
        b = (W/2) * (H-i);
        c = ((W+1)/2) * (H-i);
        ans = min(ans, max(a,max(b,c)) - min(a, min(b,c)));
    }
    for (int i = 1; i < W; i++) {
        a = H*i;
        b = (H/2) * (W-i);
        c = ((H+1)/2) * (W-i);
        ans = min(ans, max(a,max(b,c)) - min(a, min(b,c)));
    }
    printf("%lld\n", ans);
    

}

Measured memory_bytes: 3732
n, m = map(int, input().split())

A = [input() for _ in range(n)]
B = [input() for _ in range(m)]
#print(A, B)

for i in range(n - m + 1):
    for j in range(n - m + 1):
        ok = True
        for k in range(m):
            if A[i + k][j:j + m] != B[k]:
                ok = False
                break
        if ok:
            print("Yes")
            exit()
print("No")


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


def main():
    n = int(input())
    p = sorted([int(input()) for _ in range(n)])
    ans = 0

    for index, pi in enumerate(p, 1):
        if index == n:
            ans += int(pi / 2)
        else:
            ans += pi

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<cstdio>
#define R 100001
#define MOD 1000000007
int h, w, a, b;
long long way[R];
long long mul(long long x, long long y, long long p) {
	long long res = 1;
	while (y > 0) {
		if (y % 2 != 0) {
			res *= x;
			res %= p;
		}
		x *= x;
		x %= p;
		y /= 2;
	}
	return res;
}
int main() {
	scanf("%d%d%d%d", &h, &w, &a, &b);
	int i;
	long long comba=1,combb=1;
	long long ans = 0;
	for (i = 0; i < h - a; i++) {
		if (i > 0) {
			comba *= (b + i-1);
			comba %= MOD;
			combb *= i;
			combb %= MOD;
		}
		long long combc = mul(combb, MOD - 2, MOD);
		way[i] = (comba*combc) % MOD;
	}
	comba = 1; combb = 1;
	for (i = 1; i < a; i++) {
		comba *= (w - b - 1+i);
		combb *= i;
		comba %= MOD;
		combb %= MOD;
	}
	for (i = a; i < h; i++) {
		comba *= (w - b - 1 + i);
		combb *= i;
		comba %= MOD;
		combb %= MOD;
		long long combc = mul(combb, MOD - 2, MOD);
		long long comb = (comba*combc) % MOD;
		long long next = (comb * way[h-1 - i])%MOD;
		ans = (ans + next) % MOD;
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 896
import math
p = math.pi
A,B,H,M = map(int,input().split())
thita1 = 2*p*H/12+2*p/12*M/60
thita2 = 2*p*M/60
sin1 = math.sin(thita1)
sin2 = math.sin(thita2)
cos1 = math.cos(thita1)
cos2 = math.cos(thita2)
l2 = (A*sin1-B*sin2)**2+(A*cos1-B*cos2)**2
l = math.sqrt(l2)
print(l)
  

Measured memory_bytes: 9456
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<string>

using namespace std;
 
typedef long long ll;

ll memo[110][101000];

const ll MOD = 1e9 + 7;

ll a[110];

ll dp(ll i, ll j){
  if( j == 0){ return 1;}
  if( j < 0){ return 0;} //インデックスがマイナスのやばい場合を除外
  if( i < 0){ return 0;}
  //初期値 i == 0(0人に配る）も一通りとして考える
  if( memo[i][j] != -1){ return memo[i][j];}
  //すでに書き込まれている場合
  return memo[i][j] = ( (dp(i-1,j) + dp(i,j-1)) % MOD - dp( i-1,j-a[i] - 1)  +  MOD )% MOD;}
                       
  int main(){
    ll N,K; cin >> N >> K;
    for(ll i = 0; i < 110; i++){
      for(ll j = 0; j < 101000; j++){
        memo[i][j] = -1;}} //初期化(未記入)
    
    for(ll i = 0; i < N; i++){
      cin >> a[i];} //i番目の個の上限記入
    
    cout << dp(N-1,K) <<endl; return 0;}
      
    
  

Measured memory_bytes: 93312
num = [ int(n) for n in input()]
a = len(num) - 2
c = []
if a > 0:
  for i in range(a):
    b = 100*num[i] + 10*num[i+1] + num[i+2]
    c.append(abs(753 - b))
  print(min(c))

Measured memory_bytes: 3060
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

w = input()
c = collections.Counter(w)
li = []
for value in c.values():
    li.append(value)
for i in range(len(li)):
    if li[i]%2 != 0:
        print("No")
        sys.exit()
print("Yes")

Measured memory_bytes: 12500
#include<bits/stdc++.h>
using namespace std;
#define int long long
//BEGIN CUT HERE
struct KDTree{
  class Node{
  public:
    int location;
    int p,l,r;
    Node(){}
  };
  class Point{
  public:
    int id,x,y;
    Point(){}
    Point(int id,int x,int y): id(id),x(x),y(y){}
    bool operator<(const Point &p)const{
      return id<p.id;
    }
    void print(){
      printf("%lld\n",id);
    }
  };
  
  static const int NIL = -1;

  int N;
  vector<Point> P;
  vector<Node> T;
  int np;

  KDTree(){}
  KDTree(int N){init(N);}

  void init(int N_){
    N=N_;
    P.clear();
    T.clear();
    P.resize(N);
    T.resize(N);
  }
  
  static bool lessX(const Point &p1,const Point &p2){return p1.x<p2.x;}
  static bool lessY(const Point &p1,const Point &p2){return p1.y<p2.y;}
  
  int makeKDTree(int l,int r,int depth){
    if(!(l<r)) return NIL;
    int mid=(l+r)/2;
    int t = np++;
    if(depth%2==0){
      sort(P.begin()+l,P.begin()+r,lessX);
    }else{
      sort(P.begin()+l,P.begin()+r,lessY);
    }
    T[t].location=mid;
    T[t].l=makeKDTree(l,mid,depth+1);
    T[t].r=makeKDTree(mid+1,r,depth+1);
    return t;
  }
  
  void find(int v,int sx,int tx,int sy,int ty,int depth,vector<Point> &ans){
    int x=P[T[v].location].x;
    int y=P[T[v].location].y;
    if(sx<=x&&x<=tx&&sy<=y&&y<=ty){
      ans.push_back(P[T[v].location]);
    }
    if(depth%2==0){
      if(T[v].l!=NIL){
	if(sx<=x) find(T[v].l,sx,tx,sy,ty,depth+1,ans);
      }
      if(T[v].r!=NIL){
	if(x<=tx) find(T[v].r,sx,tx,sy,ty,depth+1,ans);
      }
    }else{
      if(T[v].l!=NIL){
	if(sy<=y) find(T[v].l,sx,tx,sy,ty,depth+1,ans);
      }
      if(T[v].r!=NIL){
	if(y<=ty) find(T[v].r,sx,tx,sy,ty,depth+1,ans);
      }
    }
  } 
};
//END CUT HERE

signed main(){
  int x,y;
  int N;
  scanf("%lld",&N);
  KDTree kd(N);
  for(int i=0;i<N;i++) {
    scanf("%lld %lld",&x,&y);
    kd.P[i]=KDTree::Point(i,x,y);
    kd.T[i].l = kd.T[i].r = kd.T[i].p = kd.NIL;
  }
  kd.np=0;
  int root=kd.makeKDTree(0,N,0);

  int q;
  scanf("%lld",&q);
  int sx,tx,sy,ty;
  vector<KDTree::Point> ans;
  for(int i=0;i<q;i++){
    scanf("%lld %lld %lld %lld",&sx,&tx,&sy,&ty);
    ans.clear();
    kd.find(root,sx,tx,sy,ty,0,ans);
    sort(ans.begin(),ans.end());
    for(int j=0;j<(int)ans.size();j++){
      ans[j].print();
    }
    printf("\n");
  }
  
  return 0;
}

/*
verified on 2017/07/13
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_C&lang=jp
*/

Measured memory_bytes: 29388
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;
int main(void){
    // Your code here!
    long double a,b,c,d,e,f,g;
    string A;
    cin>>a>>b>>c;
    c=c*acos(-1)/180;
    e=(a*b*sin(c))/2;
    f=sqrt(pow(a,2)+pow(b,2)-2*a*b*cos(c));
    //cout<<printf("%.10lf\n", sqrt(e))<<endl;
    //e=sqrt(e);
    // cout << f << endl;
    std::cout << setprecision(16) << e <<endl;
    std::cout << setprecision(16) << a + b + f<<endl;
    std::cout << setprecision(16) << e*2/a <<endl;
    return 0;
}



Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<cmath>
#include<string>
#include<map>
#include <cmath>
#include <set>
#include <complex>
#include <queue>
#include <functional>

using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define UN(v) sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define all(a) a.begin(), a.end()
#define N 5000000

const long long int  inf = 1e15 ;
const int M = 1e9+7;

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

LL arr[N],dp[N];
int n;
LL solve(int cur)
{
	if(cur>=n)
	{
		return 0;
	}
	if(dp[cur]==-1)
	{
		dp[cur]=min(solve(cur+1)+abs(arr[cur+1]-arr[cur]),solve(cur+2)+abs(arr[cur+2]-arr[cur]) ) ;
	}
	return dp[cur];
}

int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>arr[i];
		dp[i]=-1;
	}
	arr[n]=arr[n-1];
	dp[n]=-1;
	cout << solve(0) << endl;

	return 0;
}

Measured memory_bytes: 4608
n,k,q=map(int,input().split(' '))
qq=q
l=[k]*(n+1)
# print(l)
times=[0]*(n+1)
while qq:
    a=int(input())
    times[a]+=1
    qq-=1
# print(l)
for i in range(1,n+1):
    if l[i]-(q-times[i])>0:
        print("Yes")
    else :
        print("No")



Measured memory_bytes: 5448
#include <iostream>
#include <tuple>
std::tuple<int, int> NumbersOfBlack(int k, int x) {
  int min = x - (k-1);
  int max = x + (k-1);
  return std::forward_as_tuple(min, max);
}

int main() {
  int k, x;
  std::cin >> k;
  std::cin >> x;
  int min, max;
  std::tie(min, max) = NumbersOfBlack(k, x);
  for (int i=min; i<max+1; i++) {
    std::cout << i << " ";
  }
  std::cout << std::endl;
}

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

using namespace std;

#define boost ios::sync_with_stdio(0);cin.tie(0);
#define debug(s) cout << #s << " = " << s << endl
#define forn(i,n) for ( int i=0 ; i < n ; i++ )
#define all(a) (a).begin(), (a).end()
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ll long long
#define endl '\n'
#define mod 1000000007

int main()
{
	//freopen ("f.in","r",stdin);
 	//freopen ("f.out","w",stdout);
	boost
	//code
	int x,y;
	cin >> x >> y;
	cout << x+y/2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

vector<vector<ll>> G(100001, vector<ll>());

vector<bool> used(100001);
vector<ll> l, r;

void concatl(ll n) {
	rep(i, G[n].size()) {
		ll m = G[n][i];
		if (!used[m]) {
			used[m] = true;
			l.emplace_back(m);
			concatl(m);
			break;
		}
	}
} 

void concatr(ll n) {
	rep(i, G[n].size()) {
		ll m = G[n][i];
		if (!used[m]) {
			used[m] = true;
			r.emplace_back(m);
			concatr(m);
			break;
		}
	}
} 

int main(){	
	long long N;
	long long M;
	scanf("%lld",&N);
	scanf("%lld",&M);
	vector<long long> A(M-1+1);
	vector<long long> B(M-1+1);
	for(int i = 0 ; i <= M-1 ; i++){
		scanf("%lld",&A[i]);
		scanf("%lld",&B[i]);
		A[i]--; B[i]--;
		G[A[i]].emplace_back(B[i]);
		G[B[i]].emplace_back(A[i]);
	}
	l.emplace_back(A[0]);
	r.emplace_back(B[0]);
	used[A[0]] = true;
	used[B[0]] = true;
	concatl(A[0]);
	concatr(B[0]);
	cout << l.size()+r.size() << endl;

	rep(i, l.size()) {
		cout << l[l.size()-1-i]+1 << " ";
	}
	rep(i, r.size()-1) {
		cout << r[i]+1 << " ";
	}
	cout << r[r.size()-1]+1 << endl;

	return 0;
}



Measured memory_bytes: 11508
# https://atcoder.jp/contests/abc091/tasks/abc091_b
import collections
b = []
n = int(input())
for _ in range(n):
    b.append(input())
bc = collections.Counter(b)
r = []
n = int(input())
for _ in range(n):
    r.append(input())
rc = collections.Counter(r)
c = [0]
for bv in bc.keys():
    c.append(bc[bv] - rc[bv])
print(max(c))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
 
#define ST_ARR_LEN(array) (sizeof(array)/sizeof(*array))
#define MOD 1000000007
 
using namespace std;
 
using ll = long long;
const ll MAX = LLONG_MAX;
const ll MIN = LLONG_MIN;
 
typedef stack<ll> llStack;
typedef queue<ll> llQueue;
typedef vector<ll> llVector;
typedef list<ll> llList;
 
typedef struct S{
  int a;
  int b;
} Object;
 
int main(){
  ll N, M, Q;
  cin >> N >> M >> Q;
  ll a[Q], b[Q], c[Q], d[Q];
  for(int i=0;i<Q;i++){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  
  int A[N];
  for(int i=0;i<N;i++){
    A[i] = 1;
  }
  ll ans = 0;
  ll score = 0;
  ll aa;
  bool f = true;
  while(1){
    for(int i=0;i<N;i++){
      if(A[i] != M){
        f = false;
        break;
      }
    }
    for(int i=0;i<Q;i++){
      if(A[b[i]-1]-A[a[i]-1] == c[i]){
        score += d[i];
      }
    }
    ans = max(ans, score);
    score = 0;
    
    for(int i=N-1;i>=0;i--){
      if(A[i] == M){
        continue;
      }
      A[i]++;
      aa = A[i];
      for(int j=i;j<N;j++){
        A[j] = aa;
      }
      break;
    }
    if(f){
      break;
    }
    f = true;
  }
  cout << ans << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int n;
vector<int> res;
bool used[30001];

int main(){
  cin>>n;
  if(n==3){
    cout<<"2 5 63"<<endl;
    return 0;
  }
  if(n==4){
    cout<<"2 5 20 63"<<endl;
    return 0;
  }
  int r2=1,r3=2;
  res.push_back(2);
  res.push_back(3);
  repl(i,4,30001){
    if(i%2!=0&&i%3!=0)continue;
    if(res.size()==n-2)break;
    used[i]=true;
    res.push_back(i);
    r2=(r2+i)%2;
    r3=(r3+i)%3;
  }

  repl(i,4,30001){
    if(used[i]||(i%2!=0&&i%3!=0))continue;
    if((r2+i)%2==0){
      res.push_back(i);
      used[i]=true;
      r2=(r2+i)%2;
      r3=(r3+i)%3;
      break;
    }
  }

  repl(i,4,30001){
    if(used[i]||(i%2!=0&&i%3!=0))continue;
    if(i%2==0&&(r3+i)%3==0){
      res.push_back(i);
      used[i]=true;
      r2=(r2+i)%2;
      r3=(r3+i)%3;
      break;
    }
  }

  sort(all(res));

  rep(i,n)cout<<res[i]<<" ";
  cout<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
#include "bits/stdc++.h"

namespace adaptor = boost::adaptors;

const int64_t nmax = 100000;
const int64_t nil = -1;

struct Node {
    int64_t parent, left, right;
};

Node T[nmax];
int64_t n, D[nmax];

void print(int64_t u) {
    std::cout << "node " << u << ": ";
    std::cout << "parent = " << T[u].parent << ", ";
    std::cout << "depth = " << D[u] << ", ";
    if (T[u].parent == nil)
        std::cout << "root, ";
    else if (T[u].left == nil)
        std::cout << "leaf, ";
    else
        std::cout << "internal node, ";
    std::cout << "[";
    int64_t c;
    for (int64_t i = 0, c = T[u].left; c != nil; i++, c = T[c].right) {
        if (i > 0) std::cout << ", ";
        std::cout << c;
    }
    std::cout << "]" << std::endl;
}

void rec(int64_t u, int64_t p) {
    D[u] = p;
    if (T[u].right != nil) rec(T[u].right, p);
    if (T[u].left != nil) rec(T[u].left, p + 1);
}

void solve() {
    int64_t n;
    std::cin >> n;
    for (int64_t i = 0; i < n; i++) {
        T[i].parent = T[i].left = T[i].right = nil;
    }

    int64_t l, root;
    for (int64_t i = 0; i < n; i++) {
        int64_t v, d;
        std::cin >> v >> d;
        for (int64_t j = 0; j < d; j++) {
            int64_t c;
            std::cin >> c;
            if (j == 0)
                T[v].left = c;
            else
                T[l].right = c;
            l = c;
            T[c].parent = v;
        }
    }

    for (int64_t i = 0; i < n; i++) {
        if (T[i].parent == nil) root = i;
    }
    rec(root, 0);

    for (int64_t i = 0; i < n; i++) print(i);

    return;
}

int main() {
    std::cin.tie(0);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}



Measured memory_bytes: 9372
#include<stdio.h>
int main(void)
{
	int N=0;
    int a[1001]={0},b[1001]={0},c[1001]={0};
	int soto=0;
	int i=0;
	scanf("%d",&N);
	for (i=0;i<N;i++)
	{
		scanf("%d %d %d",&a[i],&b[i],&c[i]);
		if (a[i]<b[i])
		{
			soto=a[i];
			a[i]=b[i];
			b[i]=soto;
		}
		if (a[i]<c[i])
		{
			soto=a[i];
			a[i]=c[i];
			c[i]=soto;
		}
	}
	for (i=0;i<N;i++)
	{
		if (a[i]*a[i]==b[i]*b[i]+c[i]*c[i])
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 592
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var nm = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var pys = new PY[nm[1]];
            for (var i = 0; i < pys.Length; i++)
            {
                var py = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
                pys[i] = new PY { P = py[0], Y = py[1] };
            }
            var tmp = pys.OrderBy(x => x.P).ThenBy(x => x.Y).ToArray();
            var before = 0;
            var num = 1;
            for (var i = 0; i < tmp.Length; i++)
            {
                if (tmp[i].P != before)
                {
                    before = tmp[i].P;
                    num = 1;
                }
                tmp[i].Order = num++;
            }
            for (var i = 0; i < pys.Length; i++)
            {
                Console.WriteLine(pys[i].P.ToString("000000") + pys[i].Order.ToString("000000"));
            }
        }

        public class PY
        {
            public int Order { get; set; }
            public int P { get; set; }
            public int Y { get; set; }
        }
    }
}


Measured memory_bytes: 29380
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;


	static int[][][] undirectedGraph(int n, int[] v1, int[] v2, int[] cost) {
		int[] cnt = new int[n];
		for (int i : v1) cnt[i]++;
		for (int i : v2) cnt[i]++;

		int[][][] g = new int[n][][];
		for (int i=0; i<n; i++) g[i] = new int[cnt[i]][2];
		for (int i=0; i<v1.length; i++) {
			int s = v1[i];
			int t = v2[i];

			g[s][--cnt[s]][0] = t;
			g[s][cnt[s]][1] = cost[i];

			g[t][--cnt[t]][0] = s;
			g[t][cnt[t]][1] = cost[i];
		}

		return g;
	}

	static int doubleSweep(int[][][] g) {
		int n = g.length;
		int[] d = new int[n];

		bfsDoubleSweep(g,d,0);
		int max = 0;
		int t = 0;
		for (int i=0; i<n; i++) {
			if (d[i] == 1<<29) continue;
			if (max < d[i]) {
				max = d[i];
				t = i;
			}
		}

		bfsDoubleSweep(g,d,t);
		max = 0;
		for (int i=0; i<n; i++) {
			if (d[i] == 1<<29) continue;
			if (max < d[i]) max = d[i];
		}

		return max;
	}

	static void bfsDoubleSweep(int[][][] g, int[] d, int s) {
		Arrays.fill(d, 1<<29);
		ArrayDeque<Integer> que = new ArrayDeque<Integer>();
		que.add(s);
		d[s] = 0;
		while (!que.isEmpty()) {
			int cur = que.pollFirst();
			for (int[] to : g[cur]) {
				if (d[to[0]] == 1<<29) {
					d[to[0]] = d[cur] + to[1];
					que.add(to[0]);
				}
			}
		}
	}

	static void solve() {
		int n = in.nextInt();
		int[] s = new int[n-1];
		int[] t = new int[n-1];
		int[] w = new int[n-1];
		for (int i=0; i<n-1; i++) {
			s[i] = in.nextInt();
			t[i] = in.nextInt();
			w[i] = in.nextInt();
		}
		int[][][] g = undirectedGraph(n, s, t, w);
		out.println(doubleSweep(g));
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 109784
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

total = 0
for i in range(n):
    total += b[a[i] - 1]

for i in range(n - 1):
    if a[i] + 1 == a[i + 1]:
        total += c[a[i] - 1]
print(total)


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

typedef long long ll;
typedef double D;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }



void island(vcs& board, int i, int j) {
	if (i<0 || i>=12 || j<0 || j>=12) return;
	if (board[i][j]=='0') return;
	
	board[i][j]='0';
	
	island(board, i + 1, j);
	island(board, i, j + 1);
	island(board, i - 1, j);
	island(board, i, j - 1);
}

int main() {
	string s;
	vcs board(12);
	
	while (cin>>s) {
		board[0] = s;
		for_(i, 1, 12) {
			cin>>s;
			board[i] = s;
		}
		
		int ans = 0;
		for_(i, 0, 12) for_(j, 0, 12) {
			if (board[i][j]=='1') {
				ans++;
				island(board, i, j);
			}
		}
		cout << ans << endl;
		
		getline(cin, s);
	}
	
	return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100100

struct node {
	int num;
	ll dp;
	bool operator < (const node& x) const {
		return num<x.num;
	}
}b[N];
int n;
int a[N],c[N];
ll pre[N];

int find1(int x)
{
	if (x<=a[1]) return 0;
	int l=1,r=n,mid,ans;
	while (l<=r)
	{
		mid=(l+r)>>1;
		if (a[mid]<x)
		{
			ans=mid;
			l=mid+1;
		} else
			r=mid-1;
	}
	return ans;
}

int find(int x)
{
	if (x<=b[1].num) return 0;
	int l=1,r=n,mid,ans;
	while (l<=r)
	{
		mid=(l+r)>>1;
		if (b[mid].num<x)
		{
			ans=mid;
			l=mid+1;
		} else
			r=mid-1;
	}
	return ans;
}

ll ans;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&b[i].num);
		b[i].dp=find1(b[i].num);
	}
	sort(b+1,b+n+1);
	for (int i=1;i<=n;i++) pre[i]=pre[i-1]+b[i].dp;
	
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&c[i]);
		ans+=pre[find(c[i])];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string.h>

using namespace std;
typedef pair<int, int> P;
vector<int> prime;
bool isPrime[100001];
vector<int> primeCnt(100001);

void primeCalc()
{
	memset(isPrime, 1, 100001);
	isPrime[0] = isPrime[1] = false;
	primeCnt[0] = primeCnt[1] = 0;
	for (int i = 2; i < 100001; ++i)
	{
		if (isPrime[i])
		{
			if (isPrime[(i + 1) / 2])
			{
				primeCnt[i] = primeCnt[i - 1] + 1;
			}
			else
			{
				primeCnt[i] = primeCnt[i - 1];
			}
			prime.push_back(i);
			for (int j = i * 2; j < 100001; j += i)
			{
				isPrime[j] = false;
			}
		}
		else
		{
			primeCnt[i] = primeCnt[i - 1];
		}
	}
}

void solve()
{
	primeCalc();
	int Q;
	cin >> Q;
	for (int i = 0; i < Q; ++i)
	{
		int l, r;
		cin >> l >> r;
		cout << primeCnt[r] - primeCnt[l - 1] << endl;
	}
}

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

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

using namespace std;

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

    vector<int> t(n);
    for (int i = 0; i < n; ++i) {
        cin >> t[i];
    }
    int tot = accumulate(t.begin(), t.end(), 0);

    int m;
    cin >> m;
    int p, x;
    for (int i = 0; i < m; ++i) {
        cin >> p >> x;
        cout << tot - t[p - 1] + x << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    string s, t;
    cin >> s >> t;
    map<char,char> mp;
    int n = s.size();
    rep(i, n) {
        if(mp.count(s[i])) {
            if(mp[s[i]] != t[i]) {
                cout << "No" << endl;
                return 0;
            }
        }
        else mp[s[i]] = t[i];
    }
    mp.clear();
    swap(s, t);
    rep(i, n) {
        if(mp.count(s[i])) {
            if(mp[s[i]] != t[i]) {
                cout << "No" << endl;
                return 0;
            }
        }
        else mp[s[i]] = t[i];
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 776
#include <iostream>

 

using namespace std;

 

int main() 
{
    int a, b, c;
    cin >> a >> b >> c;
    if(a <= b && b <= c)
        cout << a << " " << b << " " << c << endl;
    else if(a <= c && c <= b)
        cout << a << " " << c << " " << b << endl;
    else if(b <= c && c <= a)
        cout << b << " " << c << " " << a << endl;
    else if(b <= a && a <= c)
        cout << b << " " << a << " " << c << endl;
    else if(c <= b && b <= a)
        cout << c << " " << b << " " << a << endl;
    else if(c <= a && a <= b)
        cout << c << " " << a << " " << b << endl;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define pb push_back

string S;
bool cent = false;
int cn = 0;

int main(){
    cin >> S;
    if(S[1] == 'R'){ cent = true; ++cn; }
    if(cent){
        if(S[0] == 'R') ++cn;
        if(S[2] == 'R') ++cn;
    }else{
        if(S[0] == 'R' || S[2] == 'R') ++cn;
    }

    cout << cn << endl;
    return 0;
}

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

int main()
{
    int h,w;
    cin >> h >> w;
    vector<vector<char>> a(h+10,vector<char>(w+10,'0'));
    vector<int> hflag(h+10,0),wflag(w+10,0);
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            cin >> a[i][j];
            if(a[i][j] == '#'){
                hflag[i]++;
                wflag[j]++;
            }
        }
    }
    for(int i = 1; i <= h; i++){
        if(hflag[i] == 0){
            continue;
        }
        for(int j = 1; j <= w; j++){
            if(wflag[j] == 0){
                continue;
            }
            cout << a[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
#define fi first
#define se second
using namespace std;
using pii = pair<int,int>;
using vi = vector<int>;
using ll = long long;

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

    int N;
    int cnt[16];
    char s[128];

    while (cin >> N, N) {
        cin >> s;
        memset(cnt, 0, sizeof(cnt));
        int ba = 0;

        for (int i=0; i<100; ++i) {
            if (s[i] == 'M') {
                ++cnt[i%N];
            } else if (s[i] == 'S') {
                ba += cnt[i%N] + 1;
                cnt[i%N] = 0;
            } else if (s[i] == 'L') {
                cnt[i%N] += ba + 1;
                ba = 0;
            }
        }

        sort(cnt, cnt+N);
        for (int i=0; i<N; ++i) {
            cout << cnt[i] << ' ';
        }
        outl(ba);
    }
}




Measured memory_bytes: 3224
import java.util.*;

class Main{
	static Scanner s=new Scanner(System.in);
	public static void main(String[] $){
		int n=s.nextInt();
		StringBuilder b=new StringBuilder(n);
		for(int i=0;i<n;++i)
			b.append(Integer.parseInt(s.next()));
		String c=b.toString();
		for(int i=0;i>=0;++i) {
			if(b.indexOf(String.valueOf(i))<0) {
				System.out.println(i);
				return;
			}
		}
	}
}


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

using namespace std;

int main()
{
    int n , k;
    cin>>n>>k ;
    int arr[n] ;
    for(int i = 0 ; i < n ; ++i)
        cin>>arr[i] ;
    int dp[k+1] ;
    dp[0] = 0 ;
    for(int i = 1 ; i <= k ; ++i)
    {
        dp[i] = 0 ;
        for(int j = 0 ; j < n ; ++j)
        {
            if(i - arr[j] < 0)
                continue;
            if(dp[i - arr[j]] == 0)
                dp[i] = 1 ;
        }
    }
    if(dp[k] == 1)
        cout<<"First\n";
    else
        cout<<"Second\n";
    return 0 ;
}


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

std::map<int, char> mp;
char s[101000], t[101000];

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

int main()
{
	long long n, m; scanf("%lld%lld", &n, &m);
	long long len = n * m / gcd(n, m);
	scanf("%s%s", s + 1, t + 1);
	for(long long i = 1; i <= n; i++) mp[(i - 1) * (len / n) + 1] = s[i];
	for(long long i = 1; i <= m; i++) if(mp.count((i - 1) * (len / m) + 1) && mp[(i - 1) * (len / m) + 1] != t[i]) return 0 * puts("-1");
	return 0 * printf("%lld\n", len);
	
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;

typedef long long ll;

const ll MAX_N=3e3;

ll N,M;

ll fact[MAX_N+1];

ll mpw(ll n,ll m,ll mod=M){
	if (m==0){
		return 1;
	}
	ll ret=mpw(n,m/2,mod);
	ret*=ret;
	ret%=mod;
	if (m%2==1){
		ret*=n;
		ret%=mod;
	}
	return ret;
}

ll inv(ll n,ll mod=M){
	return mpw(n,mod-2,mod);
}

ll comb(ll n,ll m){
	return fact[n]*inv(fact[m])%M*inv(fact[n-m])%M;
}

ll dp[MAX_N+1][MAX_N+1];

int main(){
	cin>>N>>M;
	fact[0]=1;
	FOR(i,1,N+1){
		fact[i]=(fact[i-1]*i)%M;
	}
	FOR(i,1,N+1){
		dp[0][i]=0;
	}
	REP(i,N+1){
		dp[i][0]=1;
	}
	FOR(i,1,N+1){
		FOR(j,1,N+1){
			dp[i][j]=(dp[i-1][j]+dp[i-1][j-1])%M+dp[i-1][j]*j%M;
			dp[i][j]%=M;
		}
	}
	REP(i,N+1){
		ll p2=mpw(2,N-i),pj2=1;
		ll pp2=mpw(2,mpw(2,N-i,M-1));
		REP(j,i+1){
			dp[i][j]*=pj2*pp2%M;
			dp[i][j]%=M;
			pj2*=p2;
			pj2%=M;
		}
	}
	ll ans=0;
	REP(i,N+1){
		ll s=0;
		REP(j,i+1){
			s+=dp[i][j];
			s%=M;
		}
		ll sign=(i%2) ? -1 : 1;
		ans+=sign*((comb(N,i)*s)%M);
		ans+=M;
		ans%=M;
	}
	cout<<ans<<endl;
	return 0;
}

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

#define int long long

using namespace std;

//int a[100001];
//int b[100001];

 main () {
 	int a, b, c;
 	cin >> a >> b >> c;
 	if (a == b && b == c && b % 2 == 0) {
 		cout << -1;
 		return 0;
 	}
 	int ans = 0;
 	while (1) {
		if (a & 1 || b & 1 || c & 1) break;
		ans ++;
		int aa = b / 2 + c / 2;
		int bb = a / 2 + c / 2;
		int cc = a / 2 + b / 2;
		a = aa;
		b = bb;
		c = cc;
 	}
 	cout << ans;
    return 0;           		
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, R: int):
    if N>=10:
        print(R)
    else:
        """
        R = ans - (1000 - 100 * N)
        ans = R + 1000 - 100 * N
        """
        ans = R + 1000 - 100 * N
        print(ans)
    #return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    solve(N, R)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<string>
#include<set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<n; i++)
#define per(i, n) for(int i=n-1; i>=0; i--)
#define reps(i, n) for(int i=1; i<n; i++)
#define pers(i, n)  for(int i=n-1; i>=1; i--)

const int INF = 1001001001;

void solve(){
  int x;  cin >> x;
  cout << x/500*1000 + x%500/5*5 << endl;
}

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


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define rp(a) while(a--)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	while(cin>>n,n){
		int co=0;
		loop(i,1,n+1){
			int tmp=i;
			while(!(tmp%5)){co++;tmp/=5;}
		}
		cout<<co<<endl;
	}
}

Measured memory_bytes: 1160
<?php
$server = "php://stdin";
$handle = fopen($server, "r");
$t = trim(fgets($handle));
$t=explode(' ',$t);
$map=[];
foreach ($t as $h)
{
    $map[$h]=1;
}
if(sizeof($map)==2)
{
    echo "Yes"."\n";
}else
{
    echo "No"."\n";
}

?>

Measured memory_bytes: 4856
#include<stdio.h>
#include<math.h>
#define N 10000

int isPrime(int n) {
  int i;

  if(n == 2) return 1;
  if(n < 2 || n % 2 == 0) return 0;
  i = 3;
  while(i <= sqrt(n)) {
    if(n % i == 0) return 0;
    i = i + 2;
  }
  return 1;
}

int main() {
  int i = 0, n, count = 0, flag, list[N];

  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf("%d", &list[i]);
    count += isPrime(list[i]);
  }

  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 628
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

int main(){
    int A,B;
    cin>>A>>B;
    cout << (A+B>=24?A+B-24:A+B) << endl;
}


Measured memory_bytes: 256
from collections import deque
import sys


readline = sys.stdin.readline
readall = sys.stdin.read
ins = lambda: readline().rstrip()
ini = lambda: int(readline().rstrip())
inm = lambda: map(int, readline().split())
inl = lambda: list(map(int, readline().split()))
prl = lambda x: print(*x ,sep='\n')


n,m = inm()
W = [[] for _ in range(n)]
for _ in range(m):
    a,b = inm()
    W[a-1].append(b-1)
    W[b-1].append(a-1)

res = [0] * n
dis = [n] * n
dis[0] = 0

q = deque()
q.append(0)
while q:
    c = q.popleft()
    for i in W[c]:
        if dis[i] > dis[c] + 1:
            dis[i] = dis[c] + 1
            res[i] = c + 1
            q.append(i)

print('Yes')
prl(res[1:])

Measured memory_bytes: 93552
// AOJ 2342 Light Road
// 2018.4.8 bal4u

#include <stdio.h>
#include <string.h>

#define QMAX 100000
typedef struct { char r, c, d, a, b; } Q;
Q que[QMAX+2]; int top, end;
char map[103][103];
char mk[103][103][4][11];
int  mv[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};
int  ma[4][4] = {{0,-1,-1,1},{-1,0,1,-1},{-1,1,0,-1},{1,-1,-1,0}};
int  mb[4][4] = {{0,1,-1,-1},{1,0,-1,-1},{-1,-1,0,1},{-1,-1,1,0}};

int main()
{
	int H, W, A, B, r, c, d, a, b, nr, nc, nd, na, nb, ans;
	int sr, sc, gr, gc;
	char buf[20];

	fgets(buf, 20, stdin), sscanf(buf, "%d%d%d", &H, &W, &A), B = A;
	for (r = 0; r < H; r++) {
		fgets(map[r], 103, stdin);
		for (c = 0; c < W; c++) {
			if (map[r][c] == 'S') sr = r, sc = c;
			if (map[r][c] == 'G') gr = r, gc = c;
		}
	}
	if (sr == H-1 || map[sr+1][sc] == '#') { puts("-1"); return 0; }
	que[0].r = sr+1, que[0].c = sc, que[0].d = 2, que[0].a = que[0].b = 0;
	memset(mk, 100, sizeof(mk));
	for (a = 0; a <= A; a++) mk[sr][sc][0][a] = 0;
	top = 0, end = 1;
	ans = 100;
	while (top != end) {
		r = que[top].r, c = que[top].c, d = que[top].d, a = que[top].a, b = que[top].b;
		if (++top == QMAX) top = 0;
		if (r == gr && c == gc) {
			if (a+b < ans) ans = a+b;
			continue;
		}
		if (mk[r][c][d][a] <= b) continue;
		mk[r][c][d][a] = b;
		for (nd = 0; nd < 4; nd++) {
			nr = r + mv[nd][0], nc = c + mv[nd][1], na = ma[d][nd], nb = mb[d][nd];
			if (na < 0 && nb < 0) continue;
			if (nr < 0 || nr >= H || nc < 0 || nc >= W || map[nr][nc] == '#') continue;
			que[end].r = nr, que[end].c = nc, que[end].d = nd;
			if (na > 0) {
				if (a+1 > A || map[r][c] == 'S') continue;
				if (mk[nr][nc][nd][a+1] <= b) continue;
				que[end].a = a+1, que[end].b = b;
			} else if (nb > 0) {
				if (b+1 > B || map[r][c] == 'S') continue;
				if (mk[nr][nc][nd][a] <= b+1) continue;
				que[end].a = a, que[end].b = b+1;
			} else if (!na)	{
				que[end].a = a, que[end].b = b;
				if (mk[nr][nc][nd][a] <= b) continue;
			}
			if (++end == QMAX) end = 0;
		}
	}
	if (ans > 20) puts("-1");
	else printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2680
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>
#include <string>
#include <map>
#include <set>
#include <tuple>

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<double> v(N);
  for (auto& vi: v) scanf("%lf", &vi);

  std::sort(v.rbegin(), v.rend());
  while (v.size() >= 2) {
    double v0 = v.back();
    v.pop_back();
    double v1 = v.back();
    v.pop_back();
    v.push_back((v0+v1) / 2.0);
  }
  printf("%.12f\n", v[0]);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main(){
  int n,count=0;
  cin >> n;
  rep(i,9){
    if(n%(i+1)==0&&n/(i+1)<10)
      count++;
  }
  if(count>0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

using namespace std;

int main()
{
    int n, m;

    while (cin >> n >> m, n || m) {
        int nc[100], mc[100];
        int ns, ms, diff;
        bool flag = false;

        ns = ms = 0;
        for (int i = 0; i < n; i++) {
            cin >> nc[i];
            ns += nc[i];
        }
        for (int i = 0; i < m; i++) {
            cin >> mc[i];
            ms += mc[i];
        }

        sort(nc, nc + n);
        sort(mc, mc + m);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (ns - nc[i] + mc[j] == ms - mc[j] + nc[i]) {
                    cout << nc[i] << " " << mc[j] << endl;
                    flag = true;
                    break;
                }
            }
            if (flag)
                break;
        }
        if (!flag)
            cout << "-1" << endl;
    }

    return 0;
}

Measured memory_bytes: 1180
#include<iostream>
#include<string>
#include<cctype>
using namespace std;

int main(){
  int n, taro_p = 0, hanako_p = 0;
  string taro, hanako;

  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> taro >> hanako;
    if( taro > hanako ) taro_p += 3;
    if( taro < hanako ) hanako_p += 3;
    if( taro == hanako ){
      taro_p++;
      hanako_p++;
    }
  }

  cout << taro_p << " " << hanako_p << endl;
  
  return 0;
}

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

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

const string rsp = "rsp";
int N, K;
long long R, S, P;
string T;

long long score(char a, char b) {
    if (a == 'p' && b == 'r') return P;
    if (a == 's' && b == 'p') return S;
    if (a == 'r' && b == 's') return R;
    return 0;
}

long long calc(string s) {
    long long dp[100010][3];
    int M = s.size();
    for (int i=0; i<M; ++i) {
        for (int j=0; j<3; ++j) {
            if (i > 0) {
                dp[i][j] = score(rsp[j], s[i]) + max(dp[i-1][(j+1)%3], dp[i-1][(j+2)%3]);
            } else {
                dp[i][j] = score(rsp[j], s[i]);
            }
        }
    }
    return max({dp[M-1][0], dp[M-1][1], dp[M-1][2]});
}

int main() {
    cin >> N >> K >> R >> S >> P >> T;
    long long res = 0;
    for (int i=0; i<K; ++i) {
        string t = "";
        for (int j=i; j<N; j+=K) {
            t += T[j];
        }
        if (t != "") res += calc(t);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2944
s=list(input())
t=list(input())
ns=len(s)
nt=len(t)
t_set=list(set(t))
s_set=list(set(s))
for i in range(len(t_set)):
    if t_set[i] not in s_set:
        print(-1)
        exit()

from collections import defaultdict, deque
from bisect import bisect_right
ds=defaultdict(list)
for i in range(ns):
    ds[s[i]].append(i)

components=[0]*26
for i in range(26):
    components[i]=len(ds[chr(i+97)])
lt=[-1]*nt
ord('a')
last=-1
for i in range(nt):
    j=bisect_right(ds[t[i]],last)
    if j==components[ord(t[i])-97]:
        lt[i]=ds[t[i]][0]
    else:
        lt[i]=ds[t[i]][j]
    last=lt[i]

kuriage=0
for i in range(1,nt):
    if lt[i]<=lt[i-1]:
        kuriage+=1

print(kuriage*ns+lt[-1]+1)

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

int main(){
  string s,t;
  int a,b;
  string u;
  
  cin >> s >> t >> a >> b >> u;
  
  if(s==u){
    a--;
  }
  else{
    b--;
  }
  cout << a <<" "<< b << endl;
}


Measured memory_bytes: 256
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    //標準入力をファイルに変更
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());

    string S;
    in(S);

    if (S == "SSS")
    {
        outl(0);
    }
    else if (S == "RSS" || S == "SRS" || S == "SSR" || S == "RSR")
    {
        outl(1);
    }
    else if (S == "RRS" || S == "SRR")
    {
        outl(2);
    }
    else if (S == "RRR")
    {
        outl(3);
    }

    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

class UnionFind {
public:
    vector<int> par, num;

    explicit UnionFind(int N) {
        par.resize(N);
        iota(par.begin(), par.end(), 0);
        num.assign(N, 1);
    }

    int find(int v) {
        return (par[v] == v) ? v : (par[v] = find(par[v]));
    }

    void unite(int u, int v) {
        u = find(u), v = find(v);
        if (u == v) return;

        if (num[u] < num[v]) swap(u, v);
        num[u] += num[v];
        par[v] = u;
    }

    bool same(int u, int v) { return find(u) == find(v); }
    bool ispar(int v) { return v == find(v); }
    int size(int v) { return num[find(v)]; }
};

int main() {
    int N, M;
    cin >> N >> M;

    UnionFind uf(N);
    for (int i = 0; i < M; ++i) {
        int u, v;
        cin >> u >> v;
        uf.unite(u, v);
    }

    int Q;
    cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int u, v;
        cin >> u >> v;
        cout << (uf.same(u, v) ? "yes" : "no") << endl;
    }
    return 0;
}



Measured memory_bytes: 3588
from collections import deque

inning = 0
point = 0
out = 0
base = deque([0] * 3)

n = input()
while True:
    event = raw_input()
    if event == "HIT":
        point += base.pop()
        base.appendleft(1)
    elif event == "HOMERUN":
        point += base.count(1) + 1
        base = deque([0] * 3)
    else:
        out += 1
        if out == 3:
            print point
            point = 0
            out = 0
            base = deque([0] * 3)
            inning += 1
            if inning == n: break

Measured memory_bytes: 4600
N=int(input())
List=[int(i) for i in input().split()]
P=int(round(sum(List)/N,0))
def length(x):
 return sum([(i-P-x)**2 for i in List])

i=0
data=length(0)
while True:
 if(length(i-1)<length(i)<length(i+1)):
  i-=1
 elif(length(i-1)>length(i)>length(i+1)):
  i+=1
 else:
  print(length(i))
  break

Measured memory_bytes: 38384