akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys


def solve(H: int, W: int, D: int, A: "List[List[int]]", Q: int, L: "List[int]", R: "List[int]"):
    N = H*W

    ## ある数字の座標をO(1)で取得するため
    matrix = [()]*(N+1)
    for h in range(H):
        for w in range(W):
            matrix[A[h][w]] = (h,w)
    
    def get_distance(start: int, end: int) -> int:
        start_x = matrix[start][0]
        start_y = matrix[start][1]
        end_x = matrix[end][0]
        end_y = matrix[end][1]
        return abs(start_x-end_x)+abs(start_y-end_y)

    distance = []

    for start in range(1,D+1):
        end = start
        ## 初期化
        distance_matrix = {}
        while end <= N:
            distance_matrix[end] = 0
            end += D

        end = start
        prev_end = end

        while end <= N:
            distance_matrix[end] = distance_matrix[prev_end]+ get_distance(prev_end,end)
            prev_end = end
            end += D
        
        distance.append(distance_matrix)
    
    for i in range(Q):
        s = L[i]%D
        if s == 0:
            s = D
        distance_matrix = distance[s-1]
        d = distance_matrix[R[i]]-distance_matrix[L[i]]
        print(d)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    A = [[int(next(tokens)) for _ in range(W)] for _ in range(H)]  # type: "List[List[int]]"
    Q = int(next(tokens))  # type: int
    L = [int()] * (Q)  # type: "List[int]"
    R = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        L[i] = int(next(tokens))
        R[i] = int(next(tokens))
    solve(H, W, D, A, Q, L, R)

if __name__ == '__main__':
    main()


Measured memory_bytes: 52592
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))
sortedA=sorted(A,reverse=True)
large_1=sortedA[0]
if sortedA[1]==large_1 or len(A)==1:
    for i in range(N):
        print(large_1)
else:
    num=A.index(large_1)
    for i in range(num):
        print(large_1)
    print(sortedA[1])
    for j in range(N-num-1):
        print(large_1)

Measured memory_bytes: 14112
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define printDoublePrecision(x,y) cout<<fixed<<setprecision(y)<<x
const int k = 3000;


double moreHeadThanTail(double * p, int i,int &n,int head_count,double dp[][3000]){
    if(i == n){
        if(head_count <= 0){
            return 1;
        }
        
        return 0;
    }

    if(head_count <= 0){
        return 1;
    }
    if(dp[i][head_count] >= 0){
        return dp[i][head_count];
    }


    double x = p[i] *moreHeadThanTail(p,i+1,n,head_count - 1,dp) + (1 - p[i]) * moreHeadThanTail(p,i+1,n,head_count,dp);
    return dp[i][head_count] = x;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    double p[n];
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    int head_count = (n / 2) + 1;
    double dp[n+1][3000];
    memset(dp,-1,sizeof(dp));
    printDoublePrecision( moreHeadThanTail(p,0,n,head_count,dp),10);
    cout<<endl;
    // cout<< fixed << setprecision(10) << moreHeadThanTail(p,0,n,head_count,dp)<<endl;
    return 0;
}

Measured memory_bytes: 74324
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 1000000000

int main(){
	string s;cin>>s;
	bool Bad=false;
	for(int i=0;i<3;i++){if(s[i]==s[i+1]){Bad=true;}}
	
	if(Bad){cout<<"Bad"<<endl;}
	else{cout<<"Good"<<endl;}
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int
main(void)
{
	int A, B;
	char op;

	scanf("%d %c %d", &A, &op, &B);

	int res;
	if (op == '+')
		res = A + B;
	else
		res = A - B;

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


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 105;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;
int deg[N];
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
cin>>n;
int mx=-1;
rep(i,0,n)
{
	int x;
	cin>>x;
	deg[x]++;
	mx=max(mx,x);
}
rep(i,mx+1,mx/2+1)
{
	deg[i]-=2;
	if(deg[i]<0)
	{
		cout<<"Impossible";
		return 0;
	}
}
if(!(mx%2))
{
	deg[mx/2]--;
	if(deg[mx/2]<0)
	{
		cout<<"Impossible";
		return 0;
	}
}
rep(i,1,mx+1)
{
	if(deg[i]!=0)
	{
		if(i<(mx+1)/2+1)
		{cout<<"Impossible";
		return 0;
		}
	}
}
cout<<"Possible";
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstdio>

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

#include<algorithm>
#include<cmath>
#include<numeric>

using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
const ll INF = 1e18+1;


/*
1,2,3,....,10^10^10の順列pとqで、
スコアはp[i]とq[i]の積

ai*biよりも小さいものの数を最大化したい

あまりにも数がでかいので、多分考察により単純化できる

pi*qi <= ai*bi

ざっくり可能性を絞ると、少なくともこれを満たす可能性がある
piは <= ai*biを満たすもの
piは1,2,....ai*biの列と仮定しちゃってよい

for i = 1....a*b
i人めの一つ目のコンテスト成績piが固定されているとき、
qiは a*b/pi 以下の最大の整数(でBiと重複しない)を取ればよい

a*b/pi と a*b/pi+1 の差が1以降になったらそれ以降は詰まって
それ以下の整数は全てカウントすることになる

↑の差が1以下になる境界iをみつけ、カウントはa*b/pi+iになる
のではなかろうか

|a*b(1/x - 1/(x+1))| <= 1

*/


int main() {
    /*
    int Q; cin >> Q;
    vector<ll> A(Q), B(Q);
    for (int i = 0; i < Q; i++) cin >> A[i] >> B[i];

    for (int i = 0; i < Q; i++) {
        ll a = A[i], b = B[i]; 
        ll ab = a * b;

        ll l=0,r=ab;
        while (r - l > 1) {
            ll mid = (l+r)/2;
            if (abs((double)ab * (1/(double)mid - 1/((double)mid+1))) < 1) {
                r = mid;
            } else l = mid;
            //cout << l << " " << r << endl;
        }
        ll ri = ab/r;
        while ((l+1) * (ri+1) < ab) ri++;
        ll res = ri + l - 1;
        if (ri * ri == ab) res--;
        if (abs(ri-ab/l) <= 1) res--;
        cout << res << endl;
    }*/


    ll q;
	cin >> q;
	ll a[110],b[110];
	for (size_t i = 0; i < q; i++)
	{
		cin >> a[i] >> b[i];
	}
 
	for (size_t i = 0; i < q; i++)
	{
		if (a[i] == b[i]) {
			cout << (a[i] - 1) * 2 << endl;
			continue;
		}
		if (a[i] > b[i]) {
			swap(a[i], b[i]);
		}
		ll v = a[i] * b[i];
		ll hi = sqrt(v) * 2;
		ll lo = 1;
		ll cnt = 0;
		bool p = false;
		while (cnt++ < 100)
		{
			ll mid = (lo + hi) / 2;
			if (mid * mid >= v) {
				hi = mid;
			}
			else {
				if ((mid + 1) * mid >= v) {
					if (a[i] <= (mid * 2 - 1)) {
						cout << (mid * 2 - 2) << endl;
					}else
						cout << (mid * 2 - 1) << endl;
					p = true;
					break;
				}
				else {
					lo = mid;
				}
			}
		}
		if (!p) {
			if (a[i] < lo * 2)
				cout << lo * 2 - 1 << endl;
			else
				cout << lo * 2 << endl;
		}
	}




}



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

int main(){
  int n;
  cin >> n;
  int a[100001];
  a[0]=0;
  for(int i=1;i<=n;i++) cin >> a[i];
  int d1[100000];
  for(int i=0;i<=n-1;i++) d1[i]=((a[i+1]>a[i])?(a[i+1]-a[i]):(a[i]-a[i+1]));
  int d2[99999];
  for(int i=0;i<=n-2;i++) d2[i]=((a[i+2]>a[i])?(a[i+2]-a[i]):(a[i]-a[i+2]));
  int sum=0;
  for(int i=0;i<=n-1;i++){
    sum+=d1[i];
  }
  for(int i=1;i<=n-1;i++){
    cout << sum-d1[i-1]-d1[i]+d2[i-1]+((a[n]>0)?(a[n]):(-a[n])) << endl;
  }
  cout << sum-d1[n-1]+((a[n-1]>0)?(a[n-1]):(-a[n-1])) << endl;

  return 0;
}
 

Measured memory_bytes: 2432
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int r,c,a[10][10000];
	while(true){
		scanf("%d%d",&r,&c);
		if(r==0&&c==0)return 0;
		for(int i=0;i<r;i++){
			for(int j=0;j<c;j++){
				scanf("%d",&a[i][j]);
			}
		}

		int x[11]={0,0,0,0,0,0,0,0,0,0,0};
		int b[10][10000];
		int ans=0;
		while(true){
			if(x[r]==1)break;
			for(int i=0;i<r;i++)for(int j=0;j<c;j++)b[i][j]=a[i][j];
			for(int i=0;i<r;i++){
				if(x[i]==1){
					for(int j=0;j<c;j++){
						if(b[i][j]==0)b[i][j]=1;
						else b[i][j]=0;
					}
				}
			}
			int k=0;
			
			for(int i=0;i<c;i++){
				int l=0;
				for(int j=0;j<r;j++){
					if(b[j][i]==1)l++;
				}
				
				k+=max(l,r-l);
			}
			ans=max(ans,k);
			
			int z=0;
			x[z]++;
			while(x[z]==2){
				x[z]=0;
				z++;
				x[z]++;
			}
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 1968
inputted = list(map(int, input().split()))
K = inputted[0]
N = inputted[1]
A = list(map(int, input().split()))

distancies = []
for i, Ai in enumerate(A):
    current = i
    to = (i + 1) % len(A)
    distance = A[to] - A[current] if to != 0 else K - A[current] + A[0]
    distancies.append(distance)

answer = K - max(distancies)

print(answer)


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

using namespace std;
using ll = long long;

int main() {
  double n, d;
  cin >> n >> d;
  vector<double> xs(n), ys(n);
  double d2;
  ll count = 0;
  rep(i, n) {
    cin >> xs[i] >> ys[i];
    d2 = xs[i] * xs[i] + ys[i] * ys[i];
    if (sqrt(d2) <= d) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 6496
#include<iostream>
#include<cmath>

int main(){

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

    if(a < b && b < c){
        std::cout << "Yes" << std::endl;
    }
    else{
        std::cout << "No" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <queue>
#include <unordered_set>
#define rep(i,n) for (int i=0;i<(n);++i)
#define REP(i,n) for (int i=0;i<=(n);++i)
#define all(x) (x).begin(), (x).end()

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

using namespace std;
typedef long long ll;
const int INF = 10000000;

int main() {
    int s, w;
    cin >> s >> w;

    if(w >= s) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}

Measured memory_bytes: 3512
from collections import deque
import sys
def main():
  a,b=map(int,sys.stdin.readline().split())
  e=[[]for i in range(a)]

  for i in range(a-1):
    c1,c2=map(int,sys.stdin.readline().split())
    e[c1-1].append(c2-1)
    e[c2-1].append(c1-1)

  g=[[]for i in range(a)]
  f=deque([(0,-1)])
  ans=[0 for _ in range(a)]
  for i in range(b):
    ten,p=map(int,input().split())
    ans[ten-1]+=p
  i=0
  while len(f)!=0:
    i,fr=f.pop()
    for j in e[i]:
      if j==fr:
        continue
      else:
        ans[j]+=ans[i]
        f.append((j,i)) 
  print(*ans)
if __name__ == '__main__':  
  main()
    
  

  
  


Measured memory_bytes: 105236
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    S=input()
    r=S.count("R")
    g=S.count("G")
    b=S.count("B")
    ans=r*g*b
    
    for i in range(N):
        for j in range(i+1,N):
            if S[i]!=S[j]:
                diff=j-i
                k=j+diff
                if k<N:
                    if S[i]!=S[k] and S[j]!=S[k]:
                        ans-=1
                        
                        
    print(ans)
                        
                
            

main()


Measured memory_bytes: 68104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in();
    vector<int> p(N);
    REP(i,N)p[i] = in();
    sort(ALL(p));
    p[N-1] = p[N-1]/2;
    int answer = 0;
    REP(i,N)answer += p[i];
    cout << answer << "\n";
}

Measured memory_bytes: 256
n, x = [int(s) for s in input().split()]
a_list = [int(s) for s in input().split()]
ans = 0
temp = a_list[0] - x
if temp > 0:
    ans += temp
    a_list[0] -= temp
for i in range(1, n):
    temp = a_list[i] + a_list[i - 1] - x
    if temp > 0:
        ans += temp
        a_list[i] -= temp
print(ans)

Measured memory_bytes: 19924
//#define NDEBUG
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <vector>

namespace n91 {

using i8 = std::int_fast8_t;
using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
using u8 = std::uint_fast8_t;
using u32 = std::uint_fast32_t;
using u64 = std::uint_fast64_t;
using isize = std::ptrdiff_t;
using usize = std::size_t;

struct rep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { ++i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr rep(const usize f, const usize l) noexcept
      : f(std::min(f, l)), l(l) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
struct revrep {
  struct itr {
    usize i;
    constexpr itr(const usize i) noexcept : i(i) {}
    void operator++() noexcept { --i; }
    constexpr usize operator*() const noexcept { return i; }
    constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
  };
  const itr f, l;
  constexpr revrep(const usize f, const usize l) noexcept
      : f(l - 1), l(std::min(f, l) - 1) {}
  constexpr auto begin() const noexcept { return f; }
  constexpr auto end() const noexcept { return l; }
};
template <class T> auto md_vec(const usize n, const T &value) {
  return std::vector<T>(n, value);
}
template <class... Args> auto md_vec(const usize n, Args... args) {
  return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> constexpr T difference(const T &a, const T &b) noexcept {
  return a < b ? b - a : a - b;
}
template <class T> void chmin(T &a, const T &b) noexcept {
  if (b < a)
    a = b;
}
template <class T> void chmax(T &a, const T &b) noexcept {
  if (a < b)
    a = b;
}
template <class T> T scan() {
  T ret;
  std::cin >> ret;
  return ret;
}

} // namespace n91
#include <algorithm>
#include <utility>
#include <vector>

namespace n91 {

template <class T> std::vector<T> divisors(const T &n) {
  std::vector<T> ret;
  T i = static_cast<T>(1);
  while (i * i < n) {
    if (n % i == static_cast<T>(0)) {
      ret.push_back(i);
      ret.push_back(n / i);
    }
    ++i;
  }
  if (i * i == n) {
    ret.push_back(i);
  }
  std::sort(ret.begin(), ret.end());
  ret.shrink_to_fit();
  return std::move(ret);
}

} // namespace n91

#include <algorithm>
#include <iostream>
#include <limits>
#include <utility>

namespace n91 {

void main_() {
  /*
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  //*/
  const u64 n = scan<u64>();
  const auto a = divisors(n);
  u64 ans = std::numeric_limits<u64>::max();
  for (const auto e : a) {
    chmin(ans, e - 1 + n / e - 1);
  }
  std::cout << ans << std::endl;
}

} // namespace n91

int main() {
  n91::main_();
  return 0;
}


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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

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

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

string minShift(string s)
{
	string res = s;
	FOR (it, 0, SZ(s))
	{
		s += s[0];
		s.erase(s.begin());
		res = min(res, s);
	}
	return res;
}

string getString(vector<string> v)
{
	string res;
	FOR (i, 0, SZ(v))
	{
		res += v[i];
	}
	return res;
}

string solveSmall(int a, int b, int c, string A, string B, string C)
{
	vector<string> v;
	FOR (i, 0, a)
	{
		v.PB(A);
	}

	FOR (i, 0, b)
	{
		v.PB(B);
	}

	FOR (i, 0, c)
	{
		v.PB(C);
	}
	sort(ALL(v));

	string res = getString(v);

	do
	{
		res = max(res, minShift(getString(v)));
	}while(next_permutation(ALL(v)));

	return res;

}

string getString(int cnt, string s)
{
	string res;
	FOR (i, 0, cnt)
	{
		res += s;
	}
	return res;
}

string solveLarge(int a, int b, int c, string A, string B, string C)
{
	//if (a + b + c <= 3) return solveSmall(a, b, c, A, B, C);

	if (a == 0)
	{
		a = b;
		A = B;
		b = c;
		B = C;
		c = 0;
		C = "";
	}

	if (b == 0)
	{
		b = c;
		B = C;
		c = 0;
		C = "";
	}

	if (b == 0 && c == 0)
	{
		return getString(a, A);
	}

	if (c >= a)
	{
		c -= a;
		A += C;
		return solveLarge(a, b, c, A, B, C);
	}

	C = A + C;
	a -= c;

	if (b >= a)
	{
		A += B;
		b -= a;
		swap(b, c);
		swap(B, C);
	}
	else
	{
		a -= b;
		B = A + B;
	}

	return solveLarge(a, b, c, A, B, C);



}

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int x, y, z;

	cin>>x>>y>>z;
	string res = solveLarge(x, y, z, "a", "b", "c");
	cout<<res<<endl;

//	FOR (a, 0, 5)
//	{
//		FOR (b, 0, 5)
//		{
//			FOR (c, 0, 5)
//			{
//				string r = solveSmall(a, b, c, "a", "b", "c");
//				string s = solveLarge(a, b, c, "a", "b", "c");
//				cout<<r<<endl<<s<<endl;
//				if (r != s)
//				{
//					cout<<"!! "<<endl;
//					cout<<a<<' '<<b<<' '<<c<<endl;
//					throw -1;
//				}
//			}
//		}
//	}
//
//	cout<<"Done"<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  double sum = 0;
  for (int i = 0; i < n; i++) {
    double x;
    string u;
    cin >> x >> u;
    if (u == "JPY") { sum += x; }
    else { sum += x * 380000; }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!

	int N;
	cin>>N;
	int g=0;
	rep(i,N){
		int x;
		cin>>x;
		g=__gcd(g,x);
	}
	cout<<g<<endl;
}


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

def conv(num):
    if num <= 26:
        return chr(96 + num)
    elif num % 26 == 0:
        return conv(num//26-1) + chr(96 + 26)
    else:
        return conv(num//26) + chr(96 + num%26)

print(conv(num))


Measured memory_bytes: 9152
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int h;
	while (cin >> h, h) {
		vvi cell(h, vi(5));
		int sum = 0;
		REP(i, h)
			REP(j, 5) {
			cin >> cell[i][j];
			sum += cell[i][j];
		}
		bool change;
		do {
			change = false;
			REP(i, h) {
				int a = -1;
				int cnt = 1;
				REP(j, 5) {
					if (cell[i][j] == a) {
						cnt++;
					}
					else {
						cnt = 1;
					}
					a = cell[i][j];
					if (cnt >= 3 && a != 0)
						FOR(k, j - cnt + 1, j + 1) {
						cell[i][k] = 0;
						change = true;
					}

				}
			}
			REP(k,h){
			for (int i = h - 1;i > 0;i--) {
				REP(j, 5)
					if (cell[i][j] == 0) {
						cell[i][j] = cell[i - 1][j];
						cell[i - 1][j] = 0;
					}
			}
		}
		 } while (change);
		 
		 REP(i, h)
			 REP(j, 5)
			 sum -= cell[i][j];
		 cout << sum << endl;
	}
}

Measured memory_bytes: 3136
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N, A, B;
  cin>>N>>A>>B;
  if(N==1 && A!=B) {
    cout<<0<<endl;
    return 0;
  }
  if(A>B) {
    cout<<0<<endl;
    return 0;
  }
  cout<<B*(N-1)+A-(A*(N-1)+B)+1<<endl;
}



Measured memory_bytes: 3588
#include <iostream>

constexpr long law = 1'000'000'000 + 7;

int main()
{
    long N, K;
    std::cin >> N >> K;

    long result = 0;
    for (long i = K; i <= N + 1; i++) {
        result += (i * (N - i + 1) % law) + 1;
        result %= law;
    }

    std::cout << result << std::endl;

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int inf = 1000000;

int main(int argc, const char * argv[]) {
  int N, K;
  cin >> N >> K;
  
  int ans = K;
  for (int i = 1; i < N; i++) {
    ans *= K -1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL)
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
vector<int> adj[100005];
int in[100005];
int dist[100005];
bool vis[100005];

void dfs(int s){
    vis[s] = 1;
    for(int u : adj[s]){
        dist[u] = max(dist[s] + 1, dist[u]);
        in[u]--; 
        
        if(in[u] == 0){
            dfs(u);  
        }
    }
}
int main(){
	FAST_IO;
    int n , m; 
    cin >> n >> m; 
    memset(in, 0, sizeof(in));
    memset(dist, 0, sizeof(dist));
    
    memset(vis, 0, sizeof(vis));
    while(m--){
        int a,b; 
        cin >> a >> b; 
        adj[a].push_back(b);
        in[b]++;
    }
    int ans = 0; 
    
    for(int i=1; i <= n; i++){
        if(in[i] == 0 && vis[i] == 0){
            dfs(i);
        }
    }
    for(int i=1; i <= n; i++){
        ans = max(ans, dist[i]); 
    }
    cout << ans << endl;



    return 0; 
}

Measured memory_bytes: 9728
//code by PARTH_4399 for competitive programming
#include<bits/stdc++.h>
using namespace std;
#define l long // -2^31 to +2^31-1 (upper limit ~ 2*(10^9))
#define ul unsigned long // 0 to +2^32-1
#define ll long long // -2^63 to +2^63-1 (upper limit ~ 9*(10^18))
#define ull unsigned long long // 0 to +2^64-1
#define mod(x, m) ((((x)%(m))+(m))%(m))
#define vi vector<int>
#define pi pair<int,int>
#define F first
#define S second
#define PB push_back
#define MP make_pair
//const double pi=acos(-1.0); // cout<<fixed<<setprecision(n)<<pi; - for n decimal digits, use <iomanip.h>
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//code
  	ll int n,m,i,j,k;
  	cin>>n>>m;
  	ll int a[n][m];
  	for(i=0;i<n;i++)
  	{
  		for(j=0;j<m;j++)
  		{
  			cin>>a[i][j];
  		}
  	}
  	ll int count=0;
  	l double sum;
  	for(i=0;i<n-1;i++)
  	{
  		for(j=i+1;j<n;j++)
  		{
  			sum=0;
  			for(k=0;k<m;k++)
  			{
  				sum+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
  			}
  			sum=sqrt(sum);
  			ll int sum1=int(sum);
  			if(sum==sum1)
  			count++;
  		}
  	}
  	cout<<count;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;


int main(){
    int n;cin>>n;
    vector<ll> v(n);
    for(int i=0;i<n;i++)cin>>v[i];
    for(int i=n-1;i>=1;i--){
        if(v[i-1]>v[i])v[i-1]--;
    }
    vector<ll> a=v;
    sort(a.begin(),a.end());
    if(a==v)cout<<"Yes";
    else cout<<"No";
}

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

int main(){
    int n;
    scanf("%d",&n);

    int a=100000;

    while(n--){
        a+=a/20;
        a=a/1000*1000+(a%1000!=0?1000:0);
    }
    printf("%d\n",a);

    return 0;
}

Measured memory_bytes: 1184
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.*;

class Main {
	public static void main(String[] args) throws IOException {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String str = br.readLine();
			int n = Integer.parseInt(str);
			System.out.println((int)Math.pow(n, 3));
	}
}

Measured memory_bytes: 24176
N=int(input())
S=str(N)
flag=False #999か判定するフラグ

for i in range(1,len(S)):
    #print(i,S[i])
    if S[i]!="9":
        flag=False
        break
else:
    flag=True

if flag:
    print( int(S[0]) + 9*(len(S)-1) )
else:
    top=int(S[0])-1
    print(top + 9*(len(S)-1))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 301;
const lli inf = 1e18;
char s[maxN]; int n; lli k;

lli solve()
{
  lli ans = 0;
  for (int i = 0; i < n - 1; i ++)
    if (s[i] == s[i + 1])
      ans ++, i ++;
  return ans;
}

int main()
{
  scanf("%s %lld", s, &k);
  n = strlen(s); int originalSize = n;

  lli f[4]; f[0] = 0; f[1] = solve();
  for (int j = 1; j < 3; j ++)
  {
    for (int i = 0; i < originalSize; i ++)
      s[i + originalSize*j] = s[i];
    n += originalSize;
    f[j + 1] = solve();
  }

  if (k <= 3) printf("%lld\n", f[k]);
  else
  {
    lli ans = f[1];
    ans += ((k - 1) >> 1LL) * (f[3] - f[1]);
    if ((k - 1) & 1LL) ans += f[2] - f[1];
    printf("%lld\n", ans);
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
 
vector<int>E[200000];
int in[200000];
int dp[200000];
 
int main(){
	int n,m;scanf("%d%d",&n,&m);
	rep(i,m){
		int x,y;scanf("%d%d",&x,&y);x--;y--;
		E[x].push_back(y);
		in[y]++;
	}
	queue<int>que;
	rep(i,n){
		if(!in[i]){
			que.push(i);
		}
	}
	while(!que.empty()){
		int p=que.front();que.pop();
		for(int u:E[p]){
			dp[u]=max(dp[u],dp[p]+1);
			in[u]--;
			if(!in[u])que.push(u);
		}
	}
	cout<<*max_element(dp,dp+n)<<endl;
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  vector<int>c(m);
  int i,j;
  for(i=0;i<m;i++){
    cin >> c[i];
  }
  sort(c.begin(),c.end(),greater<int>());
  vector<int>money(n+1,1<<30);
  money[0]=0;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      if(i+c[j]<=n){
        money[i+c[j]]=min(money[i+c[j]],money[i]+1);
      }
    }
  }
  cout << money[n] << endl;
}



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

using namespace std;

int n;
int a[4005], c[4];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    char ch;
    for (int i = 1; i <= n; i++)
    {
        cin >> ch;
        a[i] = (ch == 'R' ? 1 : (ch == 'G' ? 2 : 3));
    }
    long long Ans = 0;
    for (int i = 3; i <= n; i++)
    {
        c[1] = c[2] = c[3] = 0;
        for (int j = 1; j < i; j++)
        {
            if (a[j] != a[i])
            {
                for (int k = 1; k <= 3; k++)
                {
                    if (k != a[i] && k != a[j])
                    {
                        Ans = Ans + c[k];
                        int x = i - j;
                        if (j - x > 0 && a[j-x]==k)
                        {
                            Ans--;
                        }
                    }
                }
            }
            c[a[j]]++;
        }
    }
    cout << Ans;
    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define MOD 998244353

using namespace std;

typedef long long ll;

map <string,int> mp;

void merge(string &x,string y) {
  for(int i=0;i<x.length();i++)
    if (y[i]=='0') x[i]='0';
}

int dp(string s) {
  if (s.empty()) return 1;
  if (mp.count(s)) return mp[s];
  int n=s.length(),ans=0;
  ans=(ans+((s[0]=='1')?2LL:1LL)*dp(s.substr(1,n)))%MOD;
  for(int i=1;2*i<=n;i++) {
  	string cur=s.substr(0,i);
  	for(int j=2;i*j<=n;j++) {
  		merge(cur,s.substr(i*(j-1),i*j));
  		ans=(ans+(ll)dp(cur)*dp(s.substr(i*j,n)))%MOD;
	  }
  }
  return mp[s]=ans;
}

int main() {
  string s;
  cin>>s;
  cout<<dp(s)<<endl;
  return 0;
}

Measured memory_bytes: 6400
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define ALL(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif

int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
const int MAX = (int)1e5 + 5;

int K, T;
int a[100];
priority_queue<pair<int,int>> q;

signed main() {
	cin >> K >> T;
	rep(i, T) {
		cin >> a[i];
		q.push({ a[i],i });
	}
	int cnt = 0;
	int preused = -1;
	rep(i, K) {
		if (q.size() > 1) {
			pair<int,int> a, b;
			a = q.top(); q.pop();
			b = q.top(); q.pop();
			if (preused == a.second) preused = a.second;
			else preused = b.second;
			a.first--; b.first--;
			if (a.first != 0) q.push(a);
			if (b.first != 0) q.push(b);
			i++;
		}
		else {
			auto a = q.top();
			if (preused == a.second) {
				cnt++;
			}
			else {
				preused = a.second;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) for(int i = 0 ; i < n ; ++i)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int n, k;
vector<int> a;
int memo[2][100010];

int solve(int turn, int stone){
    if(stone == 0){
        return turn ^ 1;
    }
    if(memo[turn][stone] >= 0){
        return memo[turn][stone];
    }
    bool flag = false;
    rep(i, n){
        if(stone >= a[i]){
            flag |= solve(turn ^ 1, stone - a[i]) == turn;
        }
    }
    if(flag){
        return memo[turn][stone] = turn;
    }else{
        return memo[turn][stone] = turn ^ 1;
    }
}

int main(){
    cin >> n >> k;
    a.resize(n);
    rep(i, n){
        cin >> a[i];
    }
    fill(memo[0], memo[2], -1);
    int t = solve(0, k);
    if(t == 0){
        cout << "First" << endl;
    }else{
        cout << "Second" << endl;
    }
    return 0;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int x,y;
  cin >> x >> y;
  for(int i = 0; i <= x; ++i){
    if(i*2+(x-i)*4 == y){
      cout<<"Yes\n";
      return 0;
    }
  }
  cout<<"No\n";
}


Measured memory_bytes: 3632
from collections import Counter 

a,b = map(int,input().split())
l = ''
for i in range(a):
    t = input()
    l+=t

c = Counter(list(l))
# print(c)
dp = [0,0,0]
for i in c:
    if c[i]%2 ==1:
        dp[0] +=1
    elif c[i]%4 == 0:
        dp[2] += 1
    elif c[i]%2 == 0:
        dp[1] += 1
# print(dp)
ans = 'No'
if a%2 ==1 and b%2 ==1:
    A = 1
    B = (a+b-2)//2
    if A >= dp[0] and B >= dp[1]:
        ans = 'Yes'
elif  a%2 ==0 and b%2 ==0:
    A = 0
    B= 0
    if A >= dp[0] and B >= dp[1]:
        ans = 'Yes'
elif a%2 ==0 and b%2 ==1:
    A = 0
    B = a//2
    if A >= dp[0] and B >= dp[1]:
        ans = 'Yes'
else:
    A=0
    B= b//2
    if A >= dp[0] and B >= dp[1]:
        ans = 'Yes'
print(ans)


Measured memory_bytes: 38896
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int INF = 100000000;

int main(){
    ll n,k;cin>>n>>k;
    ll a,b,c,ans=0;
    vector<bool> visit(k,false);


    ll spare;//aに対しての、b,cのあまり(条件を満たすようにあまりで探索)
    for(a=1;a<=n;a++){
        if(a%k>=0){spare=k-(a%k);}//aとペアになれる数のあまりを求める->個数も求める
        else{spare=-(a%k);}

        if(!(visit[spare]) && (2*a)%k==0){ans+=(((n-spare)/k+1)*((n-spare)/k+1)*((n-spare)/k+1));}
        //!(visit[spare])は重複して数えるのを防ぐ
        //(2*a)%k==0は、上では(a,b) (a,c)の和しか判定できていないので(b,c)の判定を行っている(連立方程式を立てれば分かる)
        visit[spare]=true;
    }

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

Measured memory_bytes: 256
n = int(input())
t = [0] * n
x = [0] * n
y = [0] * n
for i in range(n):
    t[i],x[i],y[i] = map(int,input().split())
last_x = 0
last_y = 0

def load(t,x,y,last_x,last_y):
    dif = abs(last_x - x) + abs(last_y - y)
    if (dif <= t) and (dif % 2 == t % 2):
        return 'Yes'
    else:
        return 'No'
ans = 'Yes'
for i in range(n):
    if i == 0:
        test = load(t[i],x[i],y[i],last_x,last_y)
    else:
        test = load(t[i] - t[i - 1], x[i], y[i], last_x, last_y)
    if test == 'No':
        ans = 'No'
        break
    else:
        last_x = x[i]
        last_y = y[i]
print(ans)


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


int main()
{
	int X, A, B,C;
	cin >> X >> A >> B;
	C = 100 * X + 10 * A + B;
	if (C % 4 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
BC = [list(map(int,input().split())) for i in range(Q)]

import collections
ac = collections.Counter(A)

sumA = sum(A)

for b,c in BC:
    cha = 0
    cha += (c * ac[b])
    cha -= (b * ac[b])
    ac[c] += ac[b]
    ac[b] = 0
    sumA += cha
    print(sumA)

Measured memory_bytes: 40296
fun main(args: Array<String>) {
    val a = readLine()!!.split(' ').map { it.toInt() }

    var five = 0
    var seven = 0
    a.forEach {
        if (it == 5) five++
        else if (it == 7) seven++
    }
    if (five == 2 && seven == 1) println("YES")
    else println("NO")
}


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

using namespace std;

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

#define PB push_back
#define MP make_pair
#define L first
#define R second
#define sz(x) ((int)(x).size())
#define smax(x, y) ((x) = max((x), (y)))
#define smin(x, y) ((x) = min((x), (y)))
#define all(x) x.begin(),x.end()

const int maxn = 2e5 + 85 - 69,
	  maxl = 20;
int mst[maxl][maxn],
	stp[maxn],
	a[maxn],
	n;
LL ans;
queue<pii> q;

int merge(int i, int j){
	return min(MP(a[i], i), MP(a[j], j)).R;
}

int get(int l, int r){
	int f = stp[r - l + 1];
	return merge(mst[f][l], mst[f][r - (1 << f) + 1]);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	iota(mst[0], mst[0] + n, 0);
	stp[0] = -1;
	for(int i = 1; i < maxn; i++)
		stp[i] = stp[i >> 1] + 1;
	for(int i = 1; i < maxl; i++)
		for(int j = 0; j + (1 << i) <= maxn; j++)
			mst[i][j] = merge(mst[i - 1][j], mst[i - 1][j + (1 << (i - 1))]);
	q.push({0, n - 1});
	while(sz(q)){
		pii seg = q.front();
		q.pop();
		if(seg.L > seg.R) continue;
		int id = get(seg.L, seg.R);
		ans += 1LL * (id - seg.L + 1) * (seg.R - id + 1) * a[id];
		q.push({seg.L, id - 1});
		q.push({id + 1, seg.R});
	}
	cout << ans << '\n';
	return 0;
}

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

#define REP(i, n) for(auto i = 0;i < n;i++)
#define ll long long

int main(){
	string s, t;
	cin >> s >> t;
	vector<int> s_list(26, -1);
	vector<int> t_list(26, -1);
	REP(i, s.size()){
		if (!(s_list[s[i]-'a'] == -1) && !(s_list[s[i]-'a'] == t[i]-'a')){
			cout << "No" << endl;
			return 0;
		} else {s_list[s[i]-'a'] = t[i]-'a';}
		if (!(t_list[t[i]-'a'] == -1) && !(t_list[t[i]-'a'] == s[i]-'a')){
			cout << "No" << endl;
			return 0;
		} else {t_list[t[i]-'a'] = s[i]-'a';}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 776
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define INF 999999999
using namespace std;

const int hwmax=100;

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

          char c[hwmax][hwmax];
          REP(i,h)  REP(j,w)  cin >> c[i][j];

          REP(i,h){
                    REP(_,2){
                              REP(j,w){
                                        cout << c[i][j];
                              }
                              cout << endl;
                    }
          }
          return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <stack>
#include <limits>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <numeric>
//#include <tuple>

constexpr long long mod = static_cast<long long>(1e9 + 7);

std::vector<long long> create(int n, long long defaultValue) {
    int i = 1;
    while(i < n) i *= 2;
    return std::vector<long long>(2 * i - 1, defaultValue);
}

void update(std::vector<long long>& v, int i, long long data) {
    int n = (v.size() + 1) / 2;
    i += n - 1;
    v[i] = data;
    while(i > 0) {
        int p = (i - 1) / 2;
        v[p] = std::min(v[2 * p + 1], v[2 * p + 2]);
        i = p;
    }
}

long long queryImpl(const std::vector<long long>& v, int a, int b, int k, int l, int r, long long defaultValue) {
    if(r <= a || b <= l) return defaultValue;

    if(a <= l && r <= b) return v[k];
    else {
        auto vl = queryImpl(v, a, b, 2 * k + 1, l, (l + r) / 2, defaultValue);
        auto vr = queryImpl(v, a, b, 2 * k + 2, (l + r) / 2, r, defaultValue);
        return std::min(vl, vr);
    }
}

long long query(const std::vector<long long>& v, int a, int b, long long defaultValue) {
    return queryImpl(v, a, b, 0, 0, (v.size() + 1) / 2, defaultValue);
}

int main() {
    int N, q;
    std::cin >> N >> q;
    auto tree = create(N, std::pow(2ll, 31ll) - 1ll);

    while(q--) {
        int c, x, y;
        std::cin >> c >> x >> y;
        if(c == 0) {
            update(tree, x, y);
        } else {
            std::cout << query(tree, x, y + 1, std::numeric_limits<long long>::max()) << '\n';
        }
    }

    std::cout << std::flush;

    return 0;
}



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

int main() {
	// your code goes here
	string s;
	cin>>s;
	int n = s.length();
	if(s[n-1] == 's') s+="es";
	else s+='s';
	cout<<s<<"\n";
	return 0;
}

Measured memory_bytes: 3608
{-# OPTIONS_GHC -O2 -optc-O2 #-}
module Main where

import Control.Applicative
import Data.Int
import Data.List

data Test = Test Int [Int64]

slidingSums :: Int -> [Int64] -> [Int64]
slidingSums k as = zipWith (-) (drop k ps) ps
    where ps = scanl (+) 0 as

prefixPositiveSums, suffixPositiveSums :: [Int64] -> [Int64]
prefixPositiveSums = scanl (\x y -> if y >= 0 then x + y else x) 0
suffixPositiveSums = scanr (\x y -> if x >= 0 then x + y else y) 0

solve :: Test -> Int64
solve (Test k as) = maximum $ zipWith3 add ss pps (drop k sps)
    where ss = map (max 0) $ slidingSums k as
          pps = prefixPositiveSums as
          sps = suffixPositiveSums as
          add x y z = x + y + z

test0 = Test 3 [-10, 10, -10, 10, -10]
test1 = Test 2 [10, -10, -10, 10]
test2 = Test 1 [-10]
test3 = Test 5 [5, -4, -5, -8, -4, 7, 2, -4, 0, 7]
runTests = map solve [test0, test1, test2, test3]

main :: IO ()
main = do
  [_, k] <- map read . words <$> getLine
  as <- map read . words <$> getLine
  print . solve $ Test k as

Measured memory_bytes: 84348
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n), sorted(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sorted[i] = a[i];
  }
  sort(sorted.begin(), sorted.end());
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int x = upper_bound(sorted.begin(), sorted.end(), a[i]) - sorted.begin() - 1;
    if (x % 2 != i % 2) ans++;
  }
  cout << ans / 2 << endl;
  return 0;
}

Measured memory_bytes: 1024
N = int(input())
A = [x for x in map(int,input().split(" "))]

minus = 0
for i in A:
    if i < 0:
        minus += 1

if minus % 2 == 0:
    print(sum(map(abs,A)))
else:
    b = min(map(abs,A))
    print(sum(map(abs,A))-2*b)


Measured memory_bytes: 14412
///بِسْمِ الّٰلهِ الرَّحْمٰنِ الرَحِيْمِ
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1.0)
int main()
{
     ios_base::sync_with_stdio(false);cin.tie(NULL);
     ll int i,n,t,j=0,p,x,a=0,b,l=0,r=0,y,k,c,sum=0,m,d;
     for(i=1;i<=5;i++){
        cin>>a;
        if(a==0)b=i;
     }
     cout<<b<<endl;


     return EXIT_SUCCESS;
}


Measured memory_bytes: 3600
import sys

N = int(input())
tasks = []
for i in range(N):
    time, dead = [int(i) for i in input().split()]
    tasks.append([time, dead])

tasks = sorted(tasks, key=lambda task: task[1])

now = 0
for time, dead in tasks:
    now += time
    if now > dead:
        print("No")
        sys.exit()
print("Yes")


Measured memory_bytes: 39704
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        static void Main(string[] args)
        {

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            var p = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int K = int.Parse(Console.ReadLine());

            long m = p.Max();
            long sum = p.Sum() - m;
            for(var i = 0; i < K; i++)
            {
                m *= 2;
            }

            Console.WriteLine(sum + m);

            //Console.Out.Flush();
            
        }
    }



    public class Calculation
    {

    }

    public class Graph
    {

    }
}



Measured memory_bytes: 13396
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll d;
cin >> d;
vector<ll> contest_variety(26,0);
vector<ll> c(26,0);
rep(i,26){
    cin >> c[i];
}
vector<vector<ll>> calender(d,vector<ll> (26,0));
rep(i,d){
    rep(j,26){
        cin >> calender[i][j];
    }
}

vector<ll> choose(d);
rep(i,d){
    cin >> choose[i];
    choose[i]--;
}
ll ans = 0;
rep(i,d){
    ans += calender[i][choose[i]];
    contest_variety[choose[i]] = i + 1;
    rep(j,26){
        ans -= c[j] * (i + 1 - contest_variety[j]);
    }
    cout << ans << endl;
}
}

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

e = []

for i in range(m):
    a,b,c = map(int , input().split())
    e.append((a-1,b-1,c)) 

maxdis = [-float('inf') for i in range(n)]

maxdis[0] = 0
mugen = False

for i in range(n):
    for j in e:
        st,gl,cost = j
        if (maxdis[gl] < maxdis[st]+cost):
            maxdis[gl] = maxdis[st]+cost
            if (i >= n-1 and (gl == n-1)): 
                mugen = True 
                break
if mugen:
    print("inf")

else:
    print(maxdis[n-1])

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;

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

vi a, b, c; 
std::vector<vvi> dp;
int sol(int n, int x, int y) {
  if ( n < 0 && x == 0 && y == 0 ) return 0;
  if ( n < 0 ) return 1e8;
  if ( dp[n][x][y] != 1e7 ) return dp[n][x][y];

  if ( x - a[n] >= 0 && y-b[n] >= 0 ) {
    dp[n][x][y] = std::min( sol(n-1,x,y), sol(n-1,x-a[n],y-b[n])+c[n] );
  }
  else dp[n][x][y] = sol(n-1,x,y);
  return dp[n][x][y];
}

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N, Ma, Mb; std::cin >> N >> Ma >> Mb;
  a.resize(N); b.resize(N); c.resize(N);
  rep(i,N) std::cin >> a[i] >> b[i] >> c[i];

  dp.resize(N+1); 
  rep(i,N+1) dp[i].resize(401); 
  rep(i,N+1) rep(j,401) dp[i][j].resize(401, 1e7);

  int ans = 1e7;
  for(int i=1; i<=400; i++) for(int j=1; j<=400; j++) {
    if ( j*Ma != i*Mb ) continue;
    ans = std::min(ans, sol(N-1, i, j));
  }
  if ( ans == 1e7 ) std::cout << -1 << std::endl;
  else std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 26624
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int a = sc.nextInt();
		int b = sc.nextInt();
		int ans = 0;

		for (int i = 0; i <= (b - a); i++) {
			String sb = String.valueOf((b - i));
			String rb = (new StringBuilder(sb)).reverse().toString();
			if (sb.equals(rb)) {
				ans++;
			}
		}
		
		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 36436