akhauriyash/Code-Regression huggingface dataset:
import sys
from io import StringIO
import unittest
import copy

# 検索用タグ、バージョンによる相違点(pypy)

def resolve():
    x, y, a, b, c = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))

    p.sort(key=lambda xx: -xx)
    q.sort(key=lambda xx: -xx)
    r.sort(key=lambda xx: -xx)

    # 着色を一切行わない場合の値
    # pypy3(2.4.0)ではlist.copy()が未実装。copy をインポートする必要がある。
    def_red = copy.copy(p[0:x])
    def_grren = copy.copy(q[0:y])

    # 無職のリンゴに置換していく・・
    redcnt = -1
    grncnt = -1
    def_red_cnt = len(def_red)
    def_grren_cnt = len(def_grren)

    for i in range(len(r)):
        if not (r[i] > def_red[redcnt] or r[i] > def_grren[grncnt]):
            continue

        if def_red[redcnt] > def_grren[grncnt] and r[i] > def_grren[grncnt]:
            # 透明のリンゴを緑に着色して、置き換える。
            def_grren[grncnt] = r[i]

            if grncnt is not -def_grren_cnt:
                grncnt -= 1

        else:
            # 透明のリンゴを赤に着色して、置き換える。
            def_red[redcnt] = r[i]

            if redcnt is not -def_red_cnt:
                redcnt -= 1


    print(sum(def_red) + sum(def_grren))


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """1 2 2 2 1
2 4
5 1
3"""
        output = """12"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """2 2 2 2 2
8 6
9 1
2 1"""
        output = """25"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4"""
        output = """74"""
        self.assertIO(input, output)
#     def test_自作成_1(self):
#         input = """1 1 1 1 1
# 10
# 20
# 90"""
#         output = """110"""
#         self.assertIO(input, output)
    # このパターンで「list index out of range」が発生。
#     def test_自作成_2(self):
#         input = """1 1 1 1 2
# 10
# 20
# 90 110"""
#         output = """200"""
#         self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Measured memory_bytes: 125656
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };
const long double PI = 3.141592653589793238462643383279502884197;

int R, C, K, bCnt;
char arr[15][15];
vector<int> pickedR, pickedC;
int ans;
bool visited[15][15];

void pickRow(int x);
void pickCol(int x);

int main() {
	cin.tie(NULL); cout.tie(NULL);
	ios_base::sync_with_stdio(false);

	cin >> R >> C >> K;

	for (int y = 0; y < R; y++) {
		for (int x = 0; x < C; x++) {
			cin >> arr[y][x];
			if (arr[y][x] == '#') bCnt++;
		}
	}

	pickRow(0);

	cout << ans;

	return 0;
}

void pickRow(int x) {
	if (x == R) {
		pickCol(0);
		return;
	}

	pickedR.push_back(x);
	pickRow(x + 1);
	pickedR.pop_back();
	pickRow(x + 1);
}

void pickCol(int x) {
	if (x == C) {
		memset(visited, 0, sizeof(visited));
		int nbCnt = 0;

		for (int y : pickedR) {
			for (int x = 0; x < C; x++) {
				if (visited[y][x]) continue;
				visited[y][x] = true;

				if (arr[y][x] == '#') nbCnt++;
			}
		}

		for (int x : pickedC) {
			for (int y = 0; y < R; y++) {
				if (visited[y][x]) continue;
				visited[y][x] = true;

				if (arr[y][x] == '#') nbCnt++;
			}
		}

		if (bCnt - nbCnt == K) ans++;
		
		return;
	}

	pickedC.push_back(x);
	pickCol(x + 1);
	pickedC.pop_back();
	pickCol(x + 1);
}

Measured memory_bytes: 3696
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

LL mod = 1000000007;

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

  LL N;
  cin >> N;

  vector<vector<vector<vector<LL>>>> v(4, vector<vector<vector<LL>>>(4, vector<vector<LL>>(4,vector<LL>(N+1,0))));

  v[0][0][0][0] = 1;

  //123,213,132 is out 1.23 12.3
  REP(i,N){
    REP(ii,4){
      REP(jj,4){
        REP(kk,4){
          REP(ll,4){
            if(ii==1&&jj==2&&kk==3)continue;
            if(ii==2&&jj==1&&kk==3)continue;
            if(ii==1&&jj==3&&kk==2)continue;
            if(ii==1&&kk==2&&ll==3)continue;
            if(ii==1&&jj==2&&ll==3)continue;
            v[ii][jj][kk][i + 1] += v[jj][kk][ll][i];
            v[ii][jj][kk][i + 1] %= mod;
          }
        }
      }
    }
  }

  LL ans = 0;
  REP(i, 4)
  {
    REP(j, 4)
    {
      REP(k,4){
        ans += v[i][j][k][N];
        ans %= mod;
      }
    }
  }

  cout << ans << endl;
}


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

int main()
{
    string a, b, c, ans = "NO";
    cin >> a >> b >> c;
    if (a.at(a.size() - 1) == b.at(0) && b.at(b.size() - 1) == c.at(0))
    {
        ans = "YES";
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.conv;
import std.string;

void main() {
    auto n = readln.chomp.to!(ulong);
    auto t = readln.split.to!(ulong[]);
    ulong ans = 1;
    sort(t);

    foreach (i, e; t) {
        if (e != i + (i + !(n % 2)) % 2) {
            0.writeln;
            return;
        }
    }

    foreach(i; 0..n / 2)
        ans = (ans * 2) % 1000000007;
    ans.writeln;
}


Measured memory_bytes: 3688
'''

1 <= D <= 10
1 ≤  pi≤100
100≤ ci≤10**6
100≤ G

＜回答・解説より＞
以下のような選択のみを考慮しても最適解はそれらの選択に含まれます。
• 中途半端に解く配点は 1 種類以下であり、それ以外の配点は完全に解くかまったく解かない。
• 中途半端に解く配点があるなら、それは完全に解く配点以外の配点の中で最も高い配点である。

このような選択をすべて列挙するには、D 種類の配点それぞれに対してその配点を完全に解くか否かを決定し、
必要であれば残りの配点のうち最も高いものを中途半端に解く配点とすればよいです
（中途半端に解く配点の問題を 1 問除きすべて解いても目標点に達しない場合は、完全に解く配点の選択が不適切であったとして無視します）。

↓
考え方
「ある点数帯の問題を全部解く」を全パターン試す。
・目標点数を満たす、最小の問題数（の組み合わせ）をAとする
・Aの次に目標点数に近い（が満たさない、組み合わせ）をBとする。
　→Bに、「完全に解く配点以外の配点の中で最も高い配点」の問題を条件を満たすまで解いて問題数を確認する。B'とする
　　→AとB'のうち、解く問題数が少ないほうを回答とする。

'''
# from collections import deque # キュー、スタックに利用
# import math # 数学的計算に利用
# import numpy as np # 行列計算などに利用

# sys.stdin.readline() # 標準入力の高速化に利用
import sys
input = sys.stdin.readline

inf = float('inf')
is_debug = False

d,g = map(int, input().split())

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

def main():
    '''メイン処理'''
    # 各点数帯の問題を全て解くor全て解かない　の組み合わせパターンは、2**d通り
    points_list = []
    for i in range(2**d):
        # 全て解くフラグのリスト
        solve_list = [0] * d
        # n桁の2進数文字列を生成
        bin_str = bin(i)[2:].zfill(d)
        # 2進数で1の立っている桁をフラグとみなし、全て解くフラグを1へ書き換え
        for j in range(d):
            if bin_str[j] == '1':
                solve_list[j] = 1

        solve_num = 0
        points = 0
        for k in range(d):
            if solve_list[k] == 1:
                q_num, bonus = M[k]
                solve_num += q_num
                points += (q_num*(k+1)*100) + bonus
        points_list.append([solve_num, points, solve_list])
    
    if is_debug:
        print(sorted(points_list))
    
    min_solve_num = inf
    for index, [solve_num, points, solve_list] in enumerate(sorted(points_list, reverse=True)):
        next_loop = False
        if points >= g and solve_num < min_solve_num:
            # 目標点数を満たす、最小の問題数（の組み合わせ）をAとする
            a_ans = [solve_num, points]
            min_solve_num = solve_num
        elif points < g and solve_num < min_solve_num:
            ## Aの次に目標点数に近い（が満たさない、組み合わせ）をBとし、追加で解いて目標点数を満たせばmin_solve_numを更新
            # 解いていない問題の中で、得点が高い順に解いて、目標点を超えた時点のsolve_numをここまでのmin_solve_numと比較する
            for i in range(len(solve_list)-1,-1,-1):
                if solve_list[i] == 0:
                    q_num = M[i][0]
                    for _ in range(q_num):
                        points += (i+1)*100
                        solve_num += 1
                        if solve_num >= min_solve_num:
                            next_loop = True
                        elif points >= g and solve_num < min_solve_num:
                            min_solve_num = solve_num # 条件を満たす問題数があったら、ここまでの最小値を更新
                        
                        if next_loop:
                            break
                if next_loop:
                    break

    if is_debug:
        print(a_ans)
    print(min_solve_num)


if __name__ == "__main__":
    # ファイル実行時に、main()関数を実行
    main()


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

#define ll long long

ll n;

int main(){
    cin >> n;
    vector<ll> v(n);
    for(int i=0; i<n; i++)
	cin >> v[i];
    sort(v.rbegin(), v.rend());
    ll ans = 0, ptr = 0;
    for(int i=0; i+1<n; i++){
	ans += v[ptr];
	if(i%2 == 0)
	    ptr++;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 4844
#include<iostream>
#include<cstdio>
using namespace std;
#define MAX 200200
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,a[MAX],val[MAX],cnt[MAX];
char s[MAX];
struct SegmentTree
{
#define lson (now<<1)
#define rson (now<<1|1)
	int t[MAX<<2];
	void Build(int now,int l,int r)
	{
		if(l==r){t[now]=1-1e9;return;}
		int mid=(l+r)>>1;
		Build(lson,l,mid);Build(rson,mid+1,r);
		t[now]=max(t[lson],t[rson]);
	}
	void Modify(int now,int l,int r,int p,int w)
	{
		if(l==r){t[now]=w;return;}
		int mid=(l+r)>>1;
		if(p<=mid)Modify(lson,l,mid,p,w);
		else Modify(rson,mid+1,r,p,w);
		t[now]=max(t[lson],t[rson]);
	}
	int Query(int now,int l,int r,int L,int R)
	{
		if(L<=l&&r<=R)return t[now];
		int mid=(l+r)>>1,ret=-1e9;
		if(L<=mid)ret=max(ret,Query(lson,l,mid,L,R));
		if(R>mid)ret=max(ret,Query(rson,mid+1,r,L,R));
		return ret;
	}
}Odd,Even;

bool check(int mx,int Q)
{
	if(Q<0)return false;
	if(Q&1)return Odd.Query(1,1,n,mx,n)>=Q;
	else return Even.Query(1,1,n,mx,n)>=Q;
}

int main()
{
	n=read();
	for(int i=1,mx=0;i<=n;++i)
		{
			a[i]=read();
			if(a[i]>mx)val[i]=2,mx=a[i];
			else val[i]=1;
		}
	Odd.Build(1,1,n);
	for(int i=n;i;--i)
		{
			int mx1=Odd.Query(1,1,n,a[i],n),mx0=Even.Query(1,1,n,a[i],n);
			if(val[i]&1)Odd.Modify(1,1,n,a[i],mx0+val[i]),Even.Modify(1,1,n,a[i],mx1+val[i]);
			else Odd.Modify(1,1,n,a[i],mx1+val[i]),Even.Modify(1,1,n,a[i],mx0+val[i]);
		}
	for(int i=n;i;--i)cnt[i]=cnt[i+1]+val[i]-1;
	int cntX=0,cntY=0,mxX=0,mxY=0;
	for(int i=1;i<=n;++i)
		{
			Odd.Modify(1,1,n,a[i],1-1e9);Even.Modify(1,1,n,a[i],0);
			if(check(mxY,cntX+cnt[i+1]-cntY+(a[i]>mxX)))s[i]='0',cntX+=a[i]>mxX,mxX=max(mxX,a[i]);
			else if(check(max(mxX,a[i]),cntY+cnt[i+1]-cntX-(a[i]>mxX)))s[i]='0',cntX+=a[i]>mxX,mxX=max(mxX,a[i]);
			else s[i]='1',cntY+=a[i]>mxY,mxY=max(mxY,a[i]);
		}
	if(cntX!=cntY){puts("-1");}
	else printf("%s\n",s+1);
	return 0;
}


Measured memory_bytes: 9216
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int dx[]={1,0,-1,0};
constexpr int dy[]={0,1,0,-1};
constexpr int ddx[] = {1,1,-1,-1,2,2,2,2,2,-2,-2,-2,-2,-2,1,0,-1,1,0,-1};
constexpr int ddy[] = {1,-1,1,-1,0,1,2,-1,-2,2,1,0,-1,-2,2,2,2,-2,-2,-2};
constexpr int INF = 1<<28;
int main(){
  int H,W,C_h,C_w,D_h,D_w;
  cin>>H>>W>>C_h>>C_w>>D_h>>D_w;
  C_h--,C_w--,D_h--,D_w--;
  vector S(H,vector<char>(W));
  rep(i,H)rep(j,W)cin>>S[i][j];

  vector dist(H,vector(W,INF));
  dist[C_h][C_w] = 0;
  deque<int> deq;
  deq.emplace_front(C_h*W+C_w);
  while(!deq.empty()){
    int cur = deq.front();
    deq.pop_front();
    int y = cur/W;
    int x = cur%W;
    rep(i,4){
      int ny = y+dy[i];
      int nx = x+dx[i];
      if(ny<0||nx<0||ny>=H||nx>=W)continue;
      if(S[ny][nx]=='#')continue;
      if(dist[ny][nx]>dist[y][x]){
        dist[ny][nx] = dist[y][x];
        deq.emplace_front(ny*W+nx);
      }
    }
    rep(j,20){
      int ny = y+ddy[j];
      int nx = x+ddx[j];
      if(ny<0||nx<0||ny>=H||nx>=W)continue;
      if(S[ny][nx]=='#')continue;
      if(dist[ny][nx]>dist[y][x]+1){
        dist[ny][nx] = dist[y][x]+1;
        deq.emplace_back(ny*W+nx);
      }
    }
  }
  int ans = dist[D_h][D_w];
  cout<<(ans==INF?-1:ans)<<endl;
}

Measured memory_bytes: 8476
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N;
int A[101010];

bool isok(int M)
{
	int only = 0, sev = 0;
	for (int i = 0; i < N; ++i) {
		if (A[i] == M) {
			++sev;
		} else if (A[i] == M - 1) {
			++only;
		} else {
			return false;
		}
	}

	if (sev == 1) return false;
	if (only + (sev ? 1 : 0) > M) return false;
	if (only + sev / 2 < M) return false;

	return true;
}

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) {
		scanf("%d", A + i);
	}

	int waf = 0;
	for (int i = 0; i < N; ++i) waf = max(waf, A[i]);

	bool ret = (isok(waf) || isok(waf + 1));
	puts(ret ? "Yes" : "No");

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<ll> G[100005];
std::vector<P> tree[100010];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,a,b) for(i=a;i<=b;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
 
ll rui(ll abc,ll bed){
	//aのb乗を計算する
	if(bed==0){return 1;}
	else{
		ll ced = rui(abc,bed/2);
		ced *= ced;
		ced %= mod;
		if(bed%2==1){ced*=abc; ced%=mod;}
		return ced;
	}
}

ll i,j,k,ii,jj;
ll n,m,sum,num;
ll a,b,c,d,e,ans;
ll x[500005],y[500005],z[500005];
ll ma,mi;
char s[100005];
double aa;

ll kai(ll a){
	ll ii=1;
	for(int i=1;i<=a;i++){
		ii *= i;
		ii %= mod;
	}
	return ii;
}
int main(){
	double n,m,d;
	cin>>n>>m>>d;
	aa = (n-d)/(n*n);
	aa = aa * 2* (m-1);
	if(d==0)aa /= 2;
	ps(aa);

	return 0;
}

Measured memory_bytes: 7036
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(void)
{
  long long a,b,c,d;
  scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
  printf("%lld\n",max(a*c,max(a*d,max(b*c,b*d))));
  return 0;
}

Measured memory_bytes: 1728
# -*- coding: utf-8 -*-
"""
Created on Sat Jun  2 16:19:14 2018

@author: hhh
"""

n,m=map(int,input().split())
p=list(map(int,input().split()))
f=[i for i in range(0,n)]
def F(x):
    if x==f[x]:
        return x
    else:
        f[x]=F(f[x])
        return f[x]
    
for i in range(0,m):
    x,y=map(int,input().split())
    x=x-1
    y=y-1
    if F(x)!=F(y):
        f[f[x]]=f[y]

ans=0
for i in range(0,n):
    if F(p[i]-1)==F(i):
        ans=ans+1
print(ans)

Measured memory_bytes: 14008
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
using Graph = vector<vector<int>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n,sum,b,now,ans;
  b=0;
  ans=10000000000;
  cin>>n;
  ll arr[n];
  fr(i,n){
    ll y;
    cin>>y;
    arr[i]=y;
  }
  if(arr[0]!=0){
    ans=-1;
  }
  b+=arr[n-1];
  iFr(i,n-1){
    if(arr[i]>arr[i-1]+1){
      ans=-1;
    }
    if(arr[i]<=arr[i-1]){
      b+=arr[i-1];
    }
  }
  cout<<min(ans,b);
}

Measured memory_bytes: 1792
import java.lang.Math.floor

fun main(args: Array<String>) {
    val (a, b) = readIntList()

    for (i in 0..10000) {
        if (
            floor((i * 8 / 100).toDouble()) == a.toDouble() &&
            floor((i / 10).toDouble()) == b.toDouble()
        ) {
            println(i)
            return
        }
    }
    println(-1)
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)


Measured memory_bytes: 37940
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long count = 0;

        while (H > 1) {
            H /= 2;
            count++;
        }
        // System.out.println("count: " + count);

        long node = 0;
        for (int i = 1; i <= count; i++) {
            node += Math.pow(2,i);
        }

        System.out.println(node+1);
    }
}

Measured memory_bytes: 22612
#include<stdio.h>
 
int main() {
 long N,A,B,shou=0,blue=0;
   scanf("%ld",&N);
   scanf("%ld",&A);
   scanf("%ld",&B);
  
  if(N<(A+B)){
    blue=0;
  }else if((N>=(A+B))&& ((A+B)!=0)){
  	shou=N/(A+B);
    blue=shou*A;
  }else{
    blue=0;
  }
 
  if((N!=0)&&(A!=0)&&((N%(A+B))<A)){
    blue=blue+(N%(A+B));
  }else if((N!=0)&&((N%(A+B))>=A)&&(A!=0)){
    blue=blue+A;
  }else{
    blue=0;
  }
  
  printf("%ld",blue);
  
  return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	static int h,w;
	static int minx,miny,maxx,maxy;
	static int[][] field,alpha;
	static int[] v1={1,0,-1,0};
	static int[] v2={0,-1,0,1};
	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		label2:for(int T=cin.nextInt();T--!=0;){
			h=cin.nextInt();	
			w=cin.nextInt();
			field=new int[h][w];
			
			for(int i=0;i<h;i++){
				char[] s=cin.next().toCharArray();
				for(int j=0;j<w;j++){
					if(s[j]=='.')
						continue;
					field[i][j]=s[j];
//					System.out.println(field[i][j]);
				}
			}
			boolean ans=true;
			label:while(true){
				alpha=new int[26][4];
				ans=true;
				boolean canBreak=true;
				for(int i=0;i<26;i++){
					alpha[i][0]=alpha[i][1]=1<<30;
					alpha[i][2]=alpha[i][3]=-1;
				}
				for(int i=0;i<h;i++){
					for(int j=0;j<w;j++){
						if(field[i][j]>0){
							alpha[field[i][j]-'A'][0]=Math.min(i, alpha[field[i][j]-'A'][0]);
							alpha[field[i][j]-'A'][1]=Math.min(j, alpha[field[i][j]-'A'][1]);
							alpha[field[i][j]-'A'][2]=Math.max(i, alpha[field[i][j]-'A'][2]);
							alpha[field[i][j]-'A'][3]=Math.max(j, alpha[field[i][j]-'A'][3]);
//							System.out.println(alpha[field[i][j]-'A'][0]=Math.min(i, alpha[field[i][j]-'A'][0]));
						}
					}
				}
				for(int k=0;k<26;k++){
					if(alpha[k][0]==1<<30){
//						System.out.println((char)(k+'A'));
						continue;
					}
					int color='A'+k;
					boolean f=true;
					for(int i=alpha[k][0];i<=alpha[k][2];i++){
//						System.out.println(color);
						for(int j=alpha[k][1];j<=alpha[k][3];j++){
//							System.out.print(field[i][j]+" ");
							if(color==field[i][j]||field[i][j]==-1){
							}
							else{
								f=false;
							}
						}
//						System.out.println();
					}
					if(f){
						canBreak=false;
						for(int i=alpha[k][0];i<=alpha[k][2];i++){
							for(int j=alpha[k][1];j<=alpha[k][3];j++){
								field[i][j]=-1;
							}
						}
					}
				}
//				output();
				if(canBreak){
					break;
				}
			}
			for(int i=0;i<h;i++){
				for(int j=0;j<w;j++){
					if(field[i][j]>0){
						System.out.println("SUSPICIOUS");
						continue label2;
					}
				}
			}
			System.out.println("SAFE");
		}
	}
	static void output(){
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(field[i][j]<=0){
					System.out.print(".");
				}
				else{
					System.out.print((char)field[i][j]);
				}
			}
			System.out.println();
		}
	}
	static void c(){
		for(int i=miny;i<=maxy;i++){
			for(int j=minx;j<=maxx;j++){
				field[i][j]=-1;
			}
		}
	}
	static boolean b(int color){
		for(int i=miny;i<=maxy;i++){
			for(int j=minx;j<=maxx;j++){
				if(field[i][j]!=color)return false;
			}
		}
		return true;
	}
}

Measured memory_bytes: 40760
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    if ((e - a) <= k) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
# import numpy as np
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))
# import profile

def solve():
    n, k =read(); arr = read()
    dp = [-1]*n; dp[0] = 0
    for i in range(n):
    	for j in range(1, k+1):
    		if i-j >-1:
    			tem = dp[i-j]+abs(arr[i-j] - arr[i])
    			if dp[i] == -1:
    				dp[i] = tem
    			elif dp[i] > tem:
    				dp[i] = tem
    				# dp[i] = min(dp[i], tem)
    print(dp[-1])

def one():
	l = [0]*10**7
def two():
	l = [0 for i in range(10**7)]

if __name__ == "__main__":
	solve()
	# cProfile.run(solve())
	# profile.run(one())
	# cProfile.run()

Measured memory_bytes: 42092
def answer():
    l = []
    for _ in range(5):
        l.append(int(input()))

    k = int(input())

    for i in range(5):
        for j in range(5):
            if abs(l[j] - l[i]) > k:
                return ':('
    return 'Yay!'



def main():
    print(answer())


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
 
inline int read()
{
    int X=0; bool flag=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
    while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
    if(flag) return X;
    return ~(X-1);
}
 
int n;
vector<int> a,b;

int main() {
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	n=read();
	for(int i=1;i<=n;++i){
		int x,y;
		x=read();
		y=read();
		a.pb(x+y);
		b.pb(x-y);
	}

	sort(a.begin(),a.end());
	sort(b.begin(),b.end());

	printf("%d\n",max(a[n-1]-a[0],b[n-1]-b[0]));


    return 0;
}

Measured memory_bytes: 4912
h, w = map(int,input().split())
S = [input() for i in range(h)]

A = [[0] * w for i in range(h)]

A[0][0] = 0 if S[0][0] == "." else 1

for i in range(1, w):
    if S[0][i-1] == "." and S[0][i] == "#":
        A[0][i] = A[0][i-1] + 1
    else:
        A[0][i] = A[0][i-1]

for i in range(1, h):
    if S[i-1][0] == "." and S[i][0] == "#":
        A[i][0] = A[i-1][0] + 1
    else:
        A[i][0] = A[i-1][0]

for i in range(1, h):
    for j in range(1, w):
        a = A[i-1][j]
        if S[i-1][j] == "." and S[i][j] == "#":
            a += 1
        b = A[i][j-1]
        if S[i][j-1] == "." and S[i][j] == "#":
            b += 1
        A[i][j] = min(a, b)
# print(A)
print(A[-1][-1])


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

int main(){
    int n;
    cin >> n;
    long long a[200];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int cnt=-1;
    bool f=true;
    while(f){
        for(int i=0;i<n;i++){
            if(a[i]%2!=0){
                f=false;
                break;
            }
            a[i]/=2;
        }
        cnt++;
    }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  char s[3];
  scanf("%s",s);
  
  int cnt=0;
  int i;
  for(i=0;i<3;i++){
    if(s[i]=='1'){
      cnt++;
    }
  }
  
  printf("%d",cnt);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const ll mod = 1000000007;
struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<ll> Size;
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n + 1); rank.resize(n + 1); Size.resize(n + 1);
        for (int i = 0; i <= n; ++i) par[i] = i, rank[i] = 0, Size[i] = 1;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        Size[x] += Size[y];
        return true;
    }

    ll size(int x){
        return Size[root(x)];
    }
};

ll beki[200000];
int main() {
    ll N, M;
    beki[0] = 1;
    for(ll i = 1; i <= 1e5; i++) {
        beki[i] = beki[i-1] * 2 % mod;
    }
    while(cin >> N >> M) {
        if(N == 0) break;
        UnionFind uni(N);
        set<ll> st;
        while(M--) {
            ll a, b;
            cin >> a >> b;
            a--;
            b--;
            uni.merge(a, b);
        }
        ll ans = 0;
        ll num = 0;
        bool two = false;
        for(int i = 0; i < N; i++) {
            if(uni.root(i) != i) continue;
            num++;
            if(uni.size(i) >= 2) two = true;
        }
        ans = beki[num];
        if(two) ans++;
        ans %= mod;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 5216
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){
  string s;
  int a;
  cin >> a >> s;

  if(a<3200)s="red";
  cout << s <<endl;
  //printf("%d\n", iteration);
  return 0;
}

Measured memory_bytes: 256
import sys

S = input()

for i in range(7):

    #print (S[:i] , S[-(7-i):])
    if S[:i] + S[-(7-i):] == "keyence":
        print ("YES")
        sys.exit()

if S[:7] == "keyence":
    print ("Yes")
    sys.exit()
print ("NO")



Measured memory_bytes: 38256
#include<stdio.h>
int H, W, K;
char c[9][9];
main(){
	scanf("%d%d%d",&H,&W,&K);
	for(int i=0; i<H; i++){
		scanf("%s",c[i]);
	}
	int cnt = 0;
	for(int k=0; k<(1<<H); k++){
		for(int l=0; l<(1<<W); l++){
			int tmp = 0;
			for(int i=0; i<H; i++){
				for(int j=0; j<W; j++){
					if(!((k>>i)&1) && !((l>>j)&1) && c[i][j]=='#')tmp++;
				}
            }
			cnt += (tmp == K);
		}
	}
	printf("%d\n",cnt);
	return 0;
}

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

int main() {
	long long N;
	long long K;
	int gaid;
	long long ans;
 	long long kai_count;
 	long long kai_max;
 	long long kai_max2;

	cin >> N >> K;
 	vector<long long> P(N+1);
 	vector<long long> C(N+1);
 	long long kai_1;
	ans=-1e10;
	rep3(i,1, N) cin >> P.at(i);
	rep3(i,1, N) cin >> C.at(i);

	rep3(i,1, N) {
 		kai_count=0;
 		kai_1=0;
 		kai_max=-1e10;
 		gaid=i;
		if (K<=N){
			rep3(j,1,K) {
				kai_1+=C.at(gaid);
				if(kai_max<kai_1) kai_max=kai_1;
	        	gaid=P.at(gaid);
			}
		} else {
			rep3(j,1,N) {
				kai_count=j;
				kai_1+=C.at(gaid);
				if(kai_max<kai_1) kai_max=kai_1;
				gaid=P.at(gaid);
				if (gaid!=i) continue;
				if (kai_1<=0) break;
				kai_max+=kai_1*(K/kai_count-1);
				kai_1*=(K/kai_count);
				if(K%kai_count==0) break;
				rep3(jj,1,K%kai_count){
					kai_1+=C.at(gaid);
					if(kai_max<kai_1) kai_max=kai_1;
       				gaid=P.at(gaid);
				}
				break;
			}
		}
		if(ans<kai_max) ans=kai_max;
	}

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


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

vector<vector<int>> to;
int cnt = 0;
vb seen;
int n, m;

void dfs(int v) {
    if (seen[v]) return;
    seen[v] = true;
    bool ok = true;
    rep(i, n) {
        if (!seen[i]) {
            ok = false;
            break;
        }
    }
    if (ok) cnt++;
    for (auto u : to[v]) dfs(u);
    seen[v] = false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n >> m;
    to.resize(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        to[a].pb(b);
        to[b].pb(a);
    }
    seen.resize(n, false);
    dfs(0);
    cout << cnt << endl;
}

Measured memory_bytes: 3584
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 C=sc.nextInt();
	int D=sc.nextInt();
	int i=0;
	int j=0;
	for(;;) {
		i++;
		C-=B;
		if(C<=0) {
			break;
		}
	}
	for(;;) {
		j++;
		A-=D;
		if(A<=0) {
			break;
		}
	}
	if(i<=j) {
		System.out.println("Yes");
	}
	else {
		System.out.println("No");
	}
	}
}

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

int main() {
    int n, m;
    cin >> n >> m;

    auto h = vector<int>(n);
    for (auto &h_i : h)
        cin >> h_i;

    auto road = vector<vector<int>>(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        road[a].emplace_back(b);
        road[b].emplace_back(a);
    }

    auto cnt = 0;
    for (int x = 0; x < n; x++) {
        auto h_x = h[x];
        auto h_y = 0;
        for (auto y : road[x])
            h_y = max(h[y], h_y);
        if (h_x > h_y)
            cnt++;
    }

    cout << cnt << "\n";
    return 0;
}


Measured memory_bytes: 8800
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d", &tmp);v.push_back(tmp);}}
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

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

  REP(i,x + 1){
    REP(j,x + 1){
      if(x - i - j >= 0 && x - i - j <= x){
        //int t = 10000 * x + 5000 * y + 1000 * (x - i - j);
        //if(x == 2000 && y == 0)
        //c/out << t << endl;;
        if(10000 * i + 5000 * j + 1000 * (x - i - j) == y){
          printf("%d %d %d\n", i, j, x - i -j);
          return 0;
        }
      }
    }
  }
  printf("-1 -1 -1\n");

  return 0;
}



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

typedef long long ll;
typedef pair<int, int> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int t[200001][30];

signed main() {
  int n, c;
  cin >> n >> c;
  rep(i, 0, n) {
    int a, b, d;
    cin >> a >> b >> d;
    t[a * 2 - 1][d]++;
    t[b * 2][d]--;
  }
  rep(i, 1, 200001) rep(j, 0, 30) {
    t[i][j] = t[i][j] + t[i - 1][j];
  }
  int ans = 0;
  for(int i = 2; i < 200001; i += 2) {
    int c = 0;
    rep(j, 0, 30) {
      if(t[i][j] || (!t[i][j] && t[i - 1][j])) c++;
    }
    ans = max(c, ans);
  }

  cout << ans << endl;
}


Measured memory_bytes: 23680
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

#define omajinai                 \
    ios::sync_with_stdio(false); \
    cin.tie(0)
#define endll '\n'

//container util
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQUE(a) (a).erase(unique((a).begin(), (a).end()), (a).end())
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, b, a) for (int i = (b)-1; i >= (a); --i)
#define RREP(i, n) RFOR(i, n, 0)

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
#define dump(x) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";

const int _N = 100000, _C = 100000;

/// BIT
struct BIT{
    int n;
    int el[_N+_C+2];
    BIT(int n):n(n+1){
        REP(i,n)el[i] = 0;
    }
    void add(int i, int a){
    		i++;
        while(i<=n){
            el[i]+=a;
            i+=i&-i;
        }
    }
    int sum(int i){
    		i++;
        int s=0;
        while(i>0){
            s+=el[i];
            i-=i&-i;
        }
        return s;
    }
};

///

int n,c;
typedef pair<ll, int> cond;
ll pts[_N];
int ctrs[_C];
int t[_C];
bool tp[_C];

VI teamref[_N];
int moved[_N];

bool comp(const cond& a, const cond& b){
	return a.first == b.first ? a.second > b.second : a.first < b.first;
}

int main(){
	cond conds[_N+_C]; // conditions <point, team no.>
    cin >> n >> c;
    BIT tree(n+c);
    int j=0;
    REP(i, c){
        cin >> tp[i];
        if(tp[i]){
            cin >> t[i];
        }else{
            int p;
            cin >> t[i] >> p;
            t[i]--;
            pts[t[i]]+=p;
            conds[j++]=MP(pts[t[i]], t[i]);
        }
    }
    REP(i,n){
    		conds[j+i]=MP(0, i);
    		tree.add(i, 1);
    }
    j+=n;
    sort(conds, conds + j, comp);
    REP(i, j){
        teamref[conds[i].second].push_back(i);
    }
    REP(i, c){
        if(tp[i]){
            // show score
            int low = 0, high = tree.n - 1;
            while(low<high){
                int mid = (low + high)/2;
                if(tree.sum(mid)<n-t[i]+1)low = mid+1;
                else high = mid;
            }
            cout << conds[high].second+1 << " " << conds[high].first << endl;
        }else{
            // move
            int pt = moved[t[i]]++;
            tree.add(teamref[t[i]][pt], -1);
            tree.add(teamref[t[i]][pt+1], 1);
        }
    }
}

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


def solve(N: int, Q: int, S: str, l: "List[int]", r: "List[int]"):
    ans = []
    carray = [0] * N
    for i in range(1,N):
        if(S[i-1:i+1] == 'AC'):
            carray[i] = carray[i-1]+1 
            # carray[i:] = map(lambda x:x+1, carray[i:])
        else:
            carray[i] = carray[i-1]
    # print(carray)
    for i in range(Q):
        # print(carray[l[i]-1:r[i]])
        t = carray[r[i]-1] - carray[l[i]-1]
        ans.append(t)

    for i in range(Q):
        print(ans[i])
    return


# Generated by 1.1.3 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
    Q = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    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(N, Q, S, l, r)

if __name__ == '__main__':
    main()


Measured memory_bytes: 18060
// 2014/07/18 Tazoe

#include <iostream>
using namespace std;

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

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

	for(int i=n-1; i>=0; i--){
		cout << a[i];

		if(i==0){
			cout << endl;
		}
		else{
			cout << ' ';
		}
	}

	return 0;
}

Measured memory_bytes: 1164
#include "bits/stdc++.h"
using namespace std;
typedef long long lint;
typedef vector<lint> LIV;
#define rep(i,n) for(int i=0;i<n;++i)
#define MAXN 100010
#define MAXM 1100000
#define all(v) v.begin(),v.end()
#define inf 2147483647
#define linf 1152921504606846976

int main(){
	string s;cin>>s;
	lint c=0,nc,a=0,n=s.size();
	rep(i,n){
		nc=c;
		if(s[i]=='1')++nc;
		else --nc;
		if(abs(c)>abs(nc))++a;
		c=nc;
	}cout<<2*a<<endl;
}

Measured memory_bytes: 512
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random;
import std.typecons, std.functional, std.traits,std.concurrency;
import std.algorithm, std.container;
import core.bitop, core.time, core.memory;
import std.bitmanip;
import std.regex;

enum INF = long.max/3;
enum MOD = 10L^^9+7;

//辞書順順列はiota(1,N),nextPermituionを使う


void end(T)(T v)
if(isIntegral!T||isSomeString!T||isSomeChar!T)
{
    import core.stdc.stdlib;
    writeln(v);
    exit(0);
}

T[] scanArray(T = long)()
{
    static char[] scanBuf;
    readln(scanBuf);
    return scanBuf.split.to!(T[]);
}

dchar scanChar()
{
    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    return cast(dchar)c;
}

T scanElem(T = long)()
{
    import core.stdc.stdlib;
    static auto scanBuf = appender!(char[])([]);

    scanBuf.clear;

    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    while (!isWhite(c) && c != -1)
    {
        scanBuf ~= cast(char) c;
        c = getchar;
    }
    return scanBuf.data.to!T;
}

dchar[] scanString(){
    return scanElem!(dchar[]);
}


void main()
{
  auto n=scanElem+scanElem;
  if(n>=10)end("error");end(n);
}


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

using namespace std;

int main(){
	
	int n;
	scanf("%d",&n);
	vector<double> arr(n);
	for(int i=0;i<n;i++){
		scanf("%lf",&arr[i]);
	}
	
	vector<vector<double> > dp(n,vector<double>(n+1,0));
	
	dp[0][0]=(1-arr[0]);
	
	for(int i=1;i<n;i++){
		dp[i][0]=dp[i-1][0]*(1-arr[i]);
	}
	
	for(int i=0;i<n;i++){
		for(int j=1;j<=i+1;j++){
			
			dp[i][j]+=((i-1>=0&&j-1>=0?dp[i-1][j-1]:1)*arr[i]);
			dp[i][j]+=((i-1>=0?dp[i-1][j]:0)*(1-arr[i]));	
			//cout<<dp[i][j]<<" ";
		}
		//cout<<"\n";
	}
	double res=0;
	for(int i=0;i<=n;i++){
		
		if(i>=n-i){
			res+=dp[n-1][i];
		}
	}
	printf("%.12lf",res);
}


Measured memory_bytes: 70656
while True:
    x,op,y = map(str,input().split())
    if x == 0 and y == 0:
        break

    if op == "+":
        print (int(x)+int(y))
    elif op == "-":
        print (int(x)-int(y))
    elif op == "*":
        print (int(x)*int(y))
    elif op == "/":
        print (int(x)//int(y))
    else:
        break


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int32 N, M, K;
vector<int64> A, B;
string s;

double abss(double x){
	if(x < 0) return x*-1;
	return x;
}

int main(void){
	cin >> N >> M;
	A = vector<int64>(N+1, 0);
	using T = tuple<int32, int32, int32>;
	vector<T> C(M);
	REP(i, M){
		int32 a, b, c;
		cin >> b >> a; c = i;
		C[i] = T(a, b, c);
	}
	sort(all(C));
	vector<PII> res(M);
	REP(i, M){
		int32 a, b, c;
		tie(b, a, c) = C[i];
		res[c] = PII(a, (A[a]++)+1);
	}
	REP(i, M){  
		cout << setw(6) << setfill('0') << res[i].fs << setw(6) << setfill('0') << res[i].sc << endl;
	}
}


Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
typedef long double ld;

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	string n;
	cin >> n;
	if (n[0] == n[1] && n[1] == n[2] || n[1] == n[2] && n[2] == n[3]) cout << "Yes\n";
	else cout << "No\n";
}


Measured memory_bytes: 256
/*input
10 30 15 0 120
*/ 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = long long;
using ld = long double;
using pii = pair<ll,ll>;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define MP make_pair
const ll INF64=4e17;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
const ll maxn=1e6+5;
const ll maxlg=__lg(maxn)+5;
int main(){
    int a,b,c,d,k;
    cin>>a>>b>>c>>d>>k;
    int t=(c-a)*60+(d-b);
    cout<<max(t-k,0);
}

Measured memory_bytes: 3568
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
#define seg_size 524288
int main() {
	string s;
	cin >> s;
	for (int i = 0;i < s.length();++i) {
		if (s[i] == 'K') {
			if (i == 0 || s[i - 1] != 'A') {
				s.insert(i, "A");
				i = 0;
			}
		}
		else if (s[i] == 'B') {
			if (i == 0 || s[i - 1] != 'A') {
				s.insert(i, "A");
				i = 0;
			}
		}
		else if (s[i] == 'R') {
			if (i == 0 || s[i - 1] != 'A') {
				s.insert(i, "A");
				i = 0;
				continue;
			}
			if (i == s.length() - 1) {
				s.push_back('A');
				break;
			}
		}
	}
	if (s == "AKIHABARA") {
		cout << "YES" << endl;
	}
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.Scanner;

class Main {	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		
		int u, d;
		String code;
		boolean flag = false;
		
        Node[] nd = new Node[201];
        Edge[] eg = new Edge[n];

        for(int i = 0; i < 201; i++) {
            nd[i] = new Node();
        }
        for(int i = 0; i < n; i++) {
            u = scan.nextInt();
            code = scan.next();
            d = scan.nextInt() + 100;
             
            if(code.equals("wait")) {
                Edge tmp = new Edge(u,false);
                eg[i] = tmp;
                nd[d].next.add(tmp);
            }
            else {
                Edge tmp = new Edge(d,false);
                eg[i] = tmp;
                nd[u].next.add(tmp);
            }
        }
        
        for(int i = 0; i < 201; i++) {
            flag |= dedolo(nd,i,true,i);
            for(int j = 0; j < n; j++) {
                eg[j].use = false;
            }
        }
		
		if(flag) {
			System.out.println(1);
		} else {
			System.out.println(0);
		}
		
		scan.close();
	}
	
    static boolean dedolo(Node[] list, int now, boolean first, int start) {
        if(!first && now == start) return true;
        boolean ret = false;
        for(int i = 0; i < list[now].next.size(); i++) {
            if(list[now].next.get(i).use) continue;
            list[now].next.get(i).use = true;
            ret |= dedolo(list,list[now].next.get(i).to,false,start);
        }
        return ret;
    }

    static class Edge {
        int to;
        boolean use;
        Edge(int to, boolean use) {
            this.to = to;
            this.use = use;
        }
    }
    
    static class Node {
        ArrayList<Edge> next = new ArrayList<Edge>();    
    }

}

Measured memory_bytes: 34104
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
      
      	int x = sc.nextInt();
      
      	int a = 1;
      
      	int b = 0;
      	int k = 0;
        while(a != 0){
            k += 360;
        	a = k % x;
        }
          	b = k / x;
      
      	System.out.print(b);
    }
}
 


Measured memory_bytes: 27048
n=int(input())
length = len(str(n))+1
se = set()
def moji(s):
    if len(s)>=length:
        return
    se.add(s)
    moji(s+'5')
    moji(s+'7')
    moji(s+'3')
moji('')
li=list(sorted(se))
ans = 0
for i in li:
    if i == '':
        continue
    if '3' not in i or '5' not in i or '7' not in i:
        continue
    if int(i)<=n:
        ans+=1
print(ans)

Measured memory_bytes: 7344