akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int h, w, c;
int field[10][10][10];
bool visit[10][10];
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int dfs(int depth, int x, int y, int tc) {
  if (visit[y][x]) { return 0; }
  visit[y][x] = true;
  const int ndepth = depth + 1;
  const int pc = field[depth][0][0];
  field[ndepth][y][x] = tc;
  int ret = 1;
  REP(dir, 4) {
    int nx = x + dx[dir];
    int ny = y + dy[dir];
    if (nx < 0 || nx >= w || ny < 0 || ny >= h) { continue; }
    if (field[depth][ny][nx] != pc) { continue; }
    ret += dfs(depth, nx, ny, tc);
  }
  return ret;
}

int calc(int depth) {
  if (depth == 5) {
    if (field[depth][0][0] != c) { return 0; }
    MEMSET(visit, false);
    memcpy(field[depth + 1], field[depth], sizeof(field[depth]));
    return dfs(depth, 0, 0, c);
  }
  int ret = 0;
  FOREQ(i, 1, 6) {
    if (depth == 4 && i != c) { continue; }
    MEMSET(visit, false);
    memcpy(field[depth + 1], field[depth], sizeof(field[depth]));
    dfs(depth, 0, 0, i);
    ret = max(ret, calc(depth + 1));
  }
  return ret;
}

int main() {
  while (scanf("%d %d %d", &h, &w, &c), h|w|c) {
    REP(y, h) {
      REP(x, w) {
        scanf("%d", &field[0][y][x]);
      }
    }
    cout << calc(0) << endl;
  }
}

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

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

    rep(bit, 0, 1 << 4) {
        int sum = s[0] - '0';
        vector<string> vs(3);
        rep(i, 0, 3) {
            if (bit >> i & 1) {
                sum += s[i + 1] - '0';
                vs[i] = "+";
            } else {
                sum -= s[i + 1] - '0';
                vs[i] = "-";
            }
        }

        if (sum == 7) {
            cout << s[0];
            rep(i, 1, 4) cout << vs[i - 1] << s[i];
            cout << "=7" << endl;
            break;
        }
    }
    
    return 0;
}

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

using namespace std;

int main(){
  string str,res;
  bool flg = false;
  cin >> str;
  for(auto x : str){
    if(flg){
      if(x == 'Z'){
        flg = false;
        res += "AZ";
      }
    }else{
      if(x == 'A'){
        flg = true;
      }
    }
  }
  if(res.empty()){
    cout << -1 << endl;
  }else{
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
struct __test {} test;
using namespace std;
template <typename T>const __test &operator<<(const __test& d,
const T& v) {return cerr << "\033[31m" << v << "\033[0m",d;}
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;

const int N = 1e5+5;
bool b[N];
string s;

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> s;
	int n = s.size();
	b[0] = 1;
	for(int i = 1; i <= n; ++i) {
		b[i] |= i >= 5 && b[i-5] && s.substr(i-5,5) == "erase";
		b[i] |= i >= 5 && b[i-5] && s.substr(i-5,5) == "dream";
		b[i] |= i >= 7 && b[i-7] && s.substr(i-7,7) == "dreamer";
		b[i] |= i >= 6 && b[i-6] && s.substr(i-6,6) == "eraser";
	}
	if(b[n]) cout << "YES\n";
	else cout << "NO\n";
}

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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(a);i>=(long long int)(b);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pop pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define bb begin()
#define ee end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;





int arr[g_size];



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

	int n,m,T,res;

	int maxi=-mx,mini=mx,count=0;

	int i,j,k;

	bool flag;

	string s1,s2;

	char s[100000];

	int ara[n_size],ara2[n_size];

	cin>>n;

	map<int,int>mp;

	f(i,0,n-1){
        cin>>m>>k;

        count+=((k-m)+1);
	}
	cout<<count<<endl;


}


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


int main() {
    int N, K;
    cin >> N >> K;
    cout << N % K << endl;
    return 0;
}

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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define PB push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second

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

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

	int n; cin >> n;

	if(n < 600) cout << "8\n";
	else if(n < 800) cout << "7\n";
	else if(n < 1000) cout << "6\n";
	else if(n < 1200) cout << "5\n";
	else if(n < 1400) cout << "4\n";
	else if(n < 1600) cout << "3\n";
	else if(n < 1800) cout << "2\n";
	else cout << "1\n";

	return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const int INF=100000000;
const int MOD=1000000007;

int main()
{
 long double x, y;
 int ans;
 cin >> x >> y;
 ans=log2(y/x);
 cout<< ans+1;
  return 0;
}

Measured memory_bytes: 512
s = input()
n = len(s)
for i in range(n-1):
    if s[i] == s[i+1]:
        print(i + 1, i + 2)
        exit()

for i in range(n-2):
    if s[i] == s[i + 2]:
        print(i + 1, i + 3)
        exit()
print(-1, -1)

Measured memory_bytes: 39408
#include <bits/stdc++.h>
using namespace std;
const int INF = (1 << 29);

int main()
{
  int H, N;
  cin >> H >> N;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A[i] >> B[i];
  }
  vector<vector<int>> dp(N + 1, vector<int>(H + 1, INF));
  dp[0][0] = 0;
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j <= H; j++)
    {
      dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
      dp[i + 1][min(H, j + A[i])] = min(dp[i + 1][min(H, j + A[i])], dp[i + 1][j] + B[i]);
    }
  }
  cout << dp[N][H] << endl;
}

Measured memory_bytes: 39424
import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
#import heapq
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
n = ri()
a = rl()

ans=[0]*n

for i in range(n,0, -1):
    sum_=0
    iter_=2
    while i*iter_<=n:
        sum_+=ans[i*iter_-1]
        iter_+=1

    if sum_%2!=a[i-1]:
        ans[i-1]=1

print(sum(ans))
if sum(ans)!=0:
    for i, num in enumerate(ans):
        if num==1:
            print(i+1)

Measured memory_bytes: 99648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    string s;
    cin >> s;
    string ans;
    rep(i,s.size()){
        ans.push_back('x');
    }
    cout << ans << endl;
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

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

const int maxn = 20005;

int n;
int a[maxn], b[maxn];
int p[maxn];

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    for(int i = 1;i <= n;i++){
        a[i] = i * n * 2;
        b[i] = (n + 1 - i) * n * 2;
    }
    for(int i = 1;i <= n;i++){
        cin >> p[i];
        a[p[i]] += i - 1;
        b[p[i]] += i - 1;
    } 
    for(int i = 1;i <= n;i++){
        cout << a[i] << (i == n ? '\n' : ' ');
    }
    for(int i = 1;i <= n;i++){
        cout << b[i] << (i == n ? '\n' : ' ');
    }
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
 
#define int long long

const int N = 2e3 + 10, mod = 1e9 + 7;
int n, m, ans = 1, s[N], t[N], psum[N][N];

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
		cin >> s[i];
	for (int i = 1; i <= m; i++)
		cin >> t[i];
	
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++) {
			ans = (ans + (s[i] == t[j]) * (psum[i - 1][j - 1] + 1)) % mod;
			psum[i][j] = (psum[i][j - 1] + psum[i - 1][j] - psum[i - 1][j - 1] + (s[i] == t[j]) * (psum[i - 1][j - 1] + 1)) % mod;
		}
	cout << (ans + mod) % mod << endl;
}

Measured memory_bytes: 31744
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
    int M,N;
    int T[16][16];
    bool Vert[17][17];
    bool Horiz[17][17];
    cin>>M;
    for(int i=0;i<M;++i){
        int gx,gy;
        cin>>gx>>gy;
        cin>>N;
        memset(Vert,true,sizeof(Vert));
        memset(Horiz,true,sizeof(Horiz));
        for(int i=0;i<N;++i){
            int x1,y1,x2,y2;
            cin>>x1>>y1>>x2>>y2;
            if(y1==y2){
                Horiz[max(x1,x2)][y1]=false;
            }
            if(x1==x2){
                Vert[x1][max(y1,y2)]=false;
            }
        }
        memset(T,0,sizeof(T));
        T[0][0]=1;
        for(int x=0;x<gx+1;++x){
            for(int y=0;y<gy+1;++y){
                if(x==0&&y==0){continue;}
                if(y>0&&Vert[x][y]){
                    T[x][y]+=T[x][y-1];
                }
                if(x>0&&Horiz[x][y]){
                    T[x][y]+=T[x-1][y];
                }
                if(x>0&&y>0&&Vert[x][y]&&Horiz[x][y]){
                    T[x][y]=(T[x-1][y]+T[x][y-1]);
                }
            }
        }
        if(T[gx][gy]==0){
            cout<<"Miserable Hokusai!"<<endl;
        }
        else
        {
         cout<<T[gx][gy]<<endl;
        }
    }
}

Measured memory_bytes: 3024
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <utility>
#include <algorithm>
#include <vector>
#include <cmath>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
  int n;
  cin>>n;
  vi p(n);
  rep(i,n)cin>>p[i];
  sort(all(p));
  int s=0;
  rep(i,n-1)s+=p[i];
  cout<<s+p[n-1]/2<<endl;
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

const int INF = 1001001001;

int main() {

    string s, t;
    cin >> s >> t;

    int count = 0;
    for (int i = 0; i < 3; i++) {
        if (s[i] == t[i]) {
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
import bisect

n = int(input())
l = list(map(int, input().split()))
ans = 0
length = len(l)
l.sort()
 
for i in range(n):
    for j in range(i+1,n):
        k = bisect.bisect_left(l,l[i]+l[j])
        ans += max(k - (j+1),0)
print(ans)

Measured memory_bytes: 3188
s = gets.chomp.split('')
t = gets.chomp.split('')
# p s, t

pre = {}
# binding.pry
s.each_index do |i|
  pre[s[i]] ||= {}
  pre[s[i]][t[i]] ||= 0
  pre[s[i]][t[i]] += 1
  if pre[s[i]].size >= 2
    puts "No"
    exit
  end
end
# p pre
pre2 = {}
s.each_index do |i|
  pre2[t[i]] ||= {}
  pre2[t[i]][s[i]] ||= 0
  pre2[t[i]][s[i]] += 1
  if pre2[t[i]].size >= 2
    puts "No"
    exit
  end
end
# p pre2
puts "Yes"

Measured memory_bytes: 22780
import numpy as np
import sys
input = sys.stdin.readline
#actions=[]
N=int(input())
actions=[[int(x) for x in input().split()] for i in range(N)]
dp=np.zeros((N,3),dtype=int)
dp[0]=actions[0]
for i in range(1,N):
  dp[i][0]=max(dp[i-1][1],dp[i-1][2])+actions[i][0]
  dp[i][1]=max(dp[i-1][0],dp[i-1][2])+actions[i][1]
  dp[i][2]=max(dp[i-1][1],dp[i-1][0])+actions[i][2]
print(max(dp[N-1]))

Measured memory_bytes: 48724
#include <stdio.h>
main(){
  int S[10000],T[500];
  int n,q,i,j,count=0;
   
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&S[i]);
    }
  scanf("%d",&q);
  for(j=0;j<q;j++)
    {
      scanf("%d",&T[j]);
    }
 
  for(j=0;j<q;j++)
    {
      for(i=0;i<n;i++)
    {
      if(S[i]==T[j])
        { 
          count++;
        break;
        }
    }
    }
 
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 640
H=int(input())

counter=1
ans=0
while H!=1:
    H=int(H/2)

    counter=counter*2

    ans+=counter

#4   2,2 1,1,1,1
#6 3,3 1,1,1,1
#8 4,4 2,2,2,2 1,1,1,1,1,1,1,1,1,1


print(ans+1)


Measured memory_bytes: 2940
// atcoder - dp - F
#include <bits/stdc++.h>

using namespace std;

const int N = 100005;

int n, W; 

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s, t;
	cin >> s >> t;
	vector<vector<int>> dp(s.length()+1, vector<int>(t.length()+1, 0));
	vector<vector<int>> tracer(dp);
	// dp[i][j] the max length so far
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == t[0]) { 
			dp[i][0] = 1;
			tracer[i][0] = 1;
		} else if (i > 0) {
			dp[i][0] = dp[i-1][0];
			tracer[i][0] = 2;
		}
	}
	for (int i = 0; i < t.length(); i++) {
		if (s[0] == t[i]) { 
			dp[0][i] = 1;
			tracer[0][i] = 1;
		} else if (i > 0) {
			dp[0][i] = dp[0][i-1];
			tracer[0][i] = 3;
		}
	}
	for (int i = 1; i < s.length(); i++) {
		for (int j = 1; j < t.length(); j++) {
			if (s[i] == t[j]) {
				dp[i][j] = dp[i-1][j-1] + 1;
				tracer[i][j] = 1;
			}else {
				if (dp[i-1][j] > dp[i][j-1]) {
					dp[i][j] = dp[i-1][j];
					tracer[i][j] = 2;
				} else {
					dp[i][j] = dp[i][j-1];
					tracer[i][j] = 3;
				}
			}
		}
	}
	// for (int i = 0; i < s.length(); i++) {
	// 	for (int j = 0; j < t.length(); j++) {
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }
	// cout << endl;
	// for (int i = 0; i < s.length(); i++) {
	// 	for (int j = 0; j < t.length(); j++) {
	// 		cout << tracer[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }
	int row = s.length()-1, col = t.length()-1, len = 0;
	string ans(s);

	while (row >= 0 && col >= 0) {
		// cout << row << " " << col << endl;
		if (tracer[row][col] == 1){
			ans[len++] = s[row];
			row--;
			col--;
		} else if (tracer[row][col] == 2) {
			row--;
		} else {
			col--;
		}
	}
	for (int i = len-1; i>= 0; i--){
		cout << ans[i];
	}
	cout << endl;
	return 0;
}

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

ll sigma(ll n, ll m)
{
  return ((n + m) * (m - n + 1) * 0.5);
}

//実行部
void Main()
{
  ll n, k; cin >> n >> k;
  vll flag(n + 1); rep(i, n + 1) flag[i] = i;
  ll Min = 0, Max = 0, ans = 0;
  for(ll i = 0;i < k;i++)
  {
    Min += i;
    Max += (n - i);
  }
  for(ll i = k;i <= n + 1;i++)
  {
    ans += (Max - Min + 1) % MOD;
    Min += i;
    Max += (n - i);
    ans %= MOD;
  }
  fin(ans);
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


Measured memory_bytes: 5172
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;


public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		String line2 = br.readLine();
		String[] ary = line2.split(" ");
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < ary.length; i++) {
			list.add(new Integer(ary[i]));
		}
		Collections.reverse(list);
		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));
			if (i == list.size() - 1) {
				System.out.println();
			} else {
				System.out.print(" ");
			}
		}
	}
}

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

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  
  int count = 0;
  for (int a = 0; a <= A; a++) {
    for (int b = 0; b <= B; b++) {
      for (int c = 0; c <= C; c++) {
        if ((500 * a + 100 * b + 50 * c) == X) {
          count++;
        }
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3584
import numpy as np
c=np.array([list(map(int,input().split())) for _ in range(3)])
flag = True
a=[c[0]-c[1],c[1]-c[2]]
c.transpose()
b=[c[0]-c[1],c[1]-c[2]]
for i in range(2):
    flag = flag and a[i][0]==a[i][1] and a[i][2]==a[i][1]
    flag = flag and b[i][0]==b[i][1] and b[i][2]==b[i][1]
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 12508
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int A, B; cin >> A >> B;
  if (A > 9 || B > 9) cout << -1 << endl;
  else                cout << A * B << endl;
}


Measured memory_bytes: 3624
#include<bits//stdc++.h>
using namespace std;
#define MAX_V 500
#define INF 1<<28
typedef pair<int,int> P;
struct edge{int to,cap,cost,rev;};
int V; vector<edge> G[MAX_V];
int h[MAX_V],dist[MAX_V],prevv[MAX_V],preve[MAX_V];
void add_edge(int from,int to,int cap,int cost){
  G[from].push_back({to,cap,cost,G[to].size()});
  G[to].push_back({from,0,-cost,G[from].size()-1});
}
int min_cost_flow(int s,int t,int f){
  int res=0;
  fill(h,h+V,0);
  while(f>0){
    priority_queue<P,vector<P>,greater<P> > que;
    fill(dist,dist+V,INF);
    dist[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
      P p=que.top();que.pop();
      int v=p.second;
      if(dist[v]<p.first) continue;
      for(int i=0;i<G[v].size();i++){
	edge &e=G[v][i];
	if(e.cap>0&&dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
	  dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
	  prevv[e.to]=v;
	  preve[e.to]=i;
	  que.push(P(dist[e.to],e.to));
	}
      }
    }
    if(dist[t]==INF) return -1;
    for(int v=0;v<V;v++) h[v]+=dist[v];
    int d=f;
    for(int v=t;v!=s;v=prevv[v]){
      d=min(d,G[prevv[v]][preve[v]].cap);
    }
    f-=d;  res+=d*h[t];
    for(int v=t;v!=s;v=prevv[v]){
      edge &e=G[prevv[v]][preve[v]];
      e.cap-=d;
      G[v][e.rev].cap+=d;
    }
  }return res;
}
int main(){
  int e,f,u,v,c,d,i;cin>>V>>e>>f;
  for(i=0;i<e;i++){
    cin>>u>>v>>c>>d;
    add_edge(u,v,c,d);
  }
  cout << min_cost_flow(0,V-1,f) << endl;
}


Measured memory_bytes: 3224
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <iostream>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define tii tuple<int,int,int>
#define pq priority_queue<ll>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}
const ll mod = 1000000007;
int main(){
    int n=in();
    string s=stin();
    int ans=0;
    rep(a,10){
        rep(b,10){
            rep(c,10){
                bool aa=false;
                bool bb=false;
                bool cc=false;
                rep(i,n){
                    int ch=s[i] - '0';
                    if(!aa){
                        if(ch == a)aa=true;
                    }else if(!bb){
                        if(ch == b)bb=true;
                    }else{
                        if(ch == c)cc=true;
                    }
                }
                if(aa && bb && cc){
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
}


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

const int MAX = 2*1000005; //適当に変更する
const long long MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  COMinit();
    long long k;
    string str_in;
    cin >> k;
    cin >> str_in;
    long long n = str_in.size();
  
    long long p_25[1000005], p_26[1000005];
    p_25[0]=1;
    p_26[0]=1;
    for(int i=0; i<1000003; i++){
         p_25[i+1] = (p_25[i]*25)%MOD;
         p_26[i+1] = (p_26[i]*26)%MOD;
    }
    long long ans=0;
    for(int i=0; i<=k; i++){
        long long x;
        x =  p_26[i]*p_25[k-i];
        x %= MOD;
      //cout <<  COM(k+n-1-i, n-1) << endl;
        x *= COM(k+n-1-i, n-1);
        x %= MOD;
        ans += x;
        ans %= MOD;
      //cout << x << endl;
    }
    cout << ans << endl;

}

Measured memory_bytes: 66948
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    int ans = c * 2 * (x + y);
    for (int i = 0; i / 2 <= max(x, y); i += 2) {
        int price = c * i + a * max(0, x - i / 2) + b * max(0, y - i / 2);
        ans = price < ans ? price : ans;
    }

    cout << ans << endl;
}

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


int main(void){
  
	string s, t;
  	cin>>s>>t;
  	int n=(int)s.size()-(int)t.size();
  	if(n==0) n=1;
  	int d[n]={0};
  	
  	for(int i=0;i<n;i++){
      	//d.push_back(0);
    	for(int j=0;j<(int)t.size();j++){
          if(s[i+j]!=t[j]){
			d[i]++;
          }
        }
    }
  
  	//sort(d.begin(), d.end());
  	sort(d, d+n);
  	
  	cout<<d[0]<<endl;
  		
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string& s) {
  return '"' + s + '"';
}
string to_string(const char* s) {
  return to_string((string) s);
}
string to_string(bool b) {
  return (b ? "true" : "false");
}
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif
const long long mod = 1e9+7; // CHECK
long long power(long long a, long long b, long long m = mod) {
    if(b < 0) {
        return power(power(a, -b), mod-2);
    }
    long long x = 1;
    while(b) {
        if(b & 1) {
            x = 1ll * x * a % m;
        }
        a = 1ll * a * a % m;
        b /= 2;
    }
    return x;
}
#define ll long long
const int INT_INF = 1e9+9;
const ll LL_INF = 2e18;
const int N = 3e5+9; // check N, mod

signed main() {  
    ios_base::sync_with_stdio(false); 
    cin.tie(0); cout.tie(0);
    
    int n; ll a, b, c, d; 
    cin >> n >> a >> b >> c >> d;
    n--;
    for (int m = 0; m <= n; m++) {
        ll mn = -m * d + (n - m) * c;
        ll mx = -m * c + (n - m) * d;
        if (mn <= b-a && mx >= b-a) {
            // dbg(m, mn, mx);
            cout << "YES\n";
            return 0;
        }
    }
    cout << "NO\n";


    

    

    return 0;
}



Measured memory_bytes: 3628
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

h,m=map(int, input().split())
s=[list(input()) for i in range(h)]
uf1=UnionFind(h*m)
for i in range(h):
    for j in range(m):
        if s[i][j]!=s[min(i+1,h-1)][j]:uf1.union(i*m+j,i*m+j+m)
        if s[i][j]!=s[i][min(j+1,m-1)]:uf1.union(i*m+j,i*m+j+1)
from collections import Counter
c1=Counter()
c2=Counter()
for i in range(h):
    for j in range(m):
        k = i*m+j
        if s[i][j] == '.':c1[uf1.find(k)] += 1
        else:c2[uf1.find(k)] += 1
ans=0
for i in range(h*m):
    ans+=c1[i]*c2[i]
print(ans)

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

std::vector<int> divisors(int n) {
  std::vector<int> divisor;
  for(int i = 1; i <= n / i; ++i) if(n % i == 0) {
    divisor.emplace_back(i);
    if(i != n / i) divisor.emplace_back(n / i);
  }
  return divisor;
}

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for(auto& i: a) cin >> i;
  a.insert(begin(a), 0);

  vector<int> res;
  vector<int> s(N+1);
  for(auto i = N; 0 < i; --i) if(a[i] != s[i]) {
    res.emplace_back(i);
    for(auto d: divisors(i)) (s[d] += 1) %= 2;
  }

  if(a[1] == s[1]) {
    cout << res.size() << endl;
    for(auto i: res) cout << (i==res[0] ? "" : " ") << i;
    cout << endl;
  } else {
    cout << -1 << endl;
  }
}


Measured memory_bytes: 3516
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

#define all(x) begin(x),end(x)

using namespace std;
using ll = long long;

int main()
{
	vector<int>a(2);
	for (int i = 0; i < 2; ++i)
		cin >> a[i];
	sort(all(a));
	int ans = a[1];
	a[1]--;
	sort(all(a));
	ans += a[1];
	cout << ans << endl;
}



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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }

  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
  ll N; cin >> N;

  vector<ll> div;
  div = divisor(N);

  ll ans = pow(10, 13) + 7;
  ll a = 0;
  ll b = 0;
  REP(i, div.size()) {
    ll tmp = 0;
    tmp = N / div[i];
    if(ans > abs(div[i] - tmp)) {
      ans = abs(div[i] - tmp);
      a = div[i];
      b = tmp;
    }
  }
  cout << (a - 1) + (b - 1) << endl;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
 
using namespace std;
int MOD = 1000000007;
   
signed main(){
    
    int n,m;
    cin >> n >> m;
    vector<int> p[100010];
    int used[100010] = {0};
    vector<int> g;
    vector<int> s;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        p[a].pb(b);
        p[b].pb(a);
        if(i == 0){
            s.pb(a);
            g.pb(b);
            used[a] = 1;
            used[b] = 1;
        }
    }
    int cnt = 2;
    int now = g[0];
    while(1){
        int c = 0;
        for(auto x:p[now]){
            if(used[x] == 0){
                c = 1;
                now = x;
                g.pb(x);
                used[x] = 1;
                cnt++;
                break;
            }
        }
        if(c == 0)break;
    }
    now = s[0];
    while(1){
        int c = 0;
        for(auto x:p[now]){
            if(used[x] == 0){
                c = 1;
                now = x;
                s.pb(x);
                used[x] = 1;
                cnt++;
                break;
            }
        }
        if(c == 0)break;
    }
    cout << cnt << endl;
    for(int i = s.size()-1;i >= 0;i--)cout << s[i] << " ";
    for(int i = 0;i < g.size();i++)cout << g[i] << " ";
    cout << endl;


    return 0;   
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://ddcc2019-final.contest.atcoder.jp/tasks/ddcc2019_final_a
// rm -r -f test;oj dl http://agc013.contest.atcoder.jp/tasks/agc013_b

Measured memory_bytes: 7924
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


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 = 1LL <<60;
const int INF = 10000;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始
int main(){
  int a,b;
  cin>>a>>b;
  cout<<max(0,a-b*2)<<endl;
  return 0;
}


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

// #define multitest 1
#ifdef WIN32
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
#define pc(...) PC(#__VA_ARGS__, __VA_ARGS__);
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.first << ", " << p.second << ']';
	return out;
}
template <typename Arg>
void PC(const char *name, Arg &&arg)
{
	std::cerr << name << " { ";
	for (const auto &v : arg)
		cerr << v << ' ';
	cerr << " }\n";
}
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#define pc(...)
#endif

using ll = long long;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;
auto TimeStart = chrono::steady_clock::now();

const int nax = 2e5 + 10;

void solve()
{
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	for (auto &x : a)
		cin >> x;
	ll ans = 0;
	ll temp = 0;
	for (int i = 0; i < n; ++i)
		for (int j = i + 1; j < n; ++j)
			if (a[i] > a[j])
				temp++;
	ans += (temp * k) % mod;
	auto b = a;
	sort(b.begin(), b.end());
	temp = (k * (k - 1) / 2) % mod;
	for (int i = 0; i < n; ++i)
	{
		ll cnt = upper_bound(b.begin(), b.end(), a[i]) - b.begin();
		cnt = n - cnt;
		ans = (ans + cnt * temp) % mod;
	}
	cout << ans;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
#ifdef WIN32
	cerr << "\n\nTime elapsed: " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " seconds.\n";
#endif
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
class Main
{
    public static void main(String args[])throws IOException
    {
	BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
	String str;
	while((str=input.readLine())!=null)
	    {
		String str_ary[]=str.split(" ");
		int x[]=new int[3];
		for(int i=0;i<3;i++)
		    {
			x[i]=Integer.parseInt(str_ary[i]);
		    }
		if(
		   x[0]<1868
		   ||x[0]==1868 && x[1]<9
		   ||x[0]==1868 && x[1]==9 && x[2]<8)System.out.println("pre-meiji");
		if(
		   1869<=x[0] && x[0]<=1911
		   ||x[0]==1868 && 9<x[1]
		   ||x[0]==1868 && x[1]==9 && 8<=x[2]
		   ||x[0]==1912 && x[1]<7
		   ||x[0]==1912 && x[1]==7 && x[2]<30)System.out.println("meiji"+" "+(x[0]-1868+1)+" "+x[1]+" "+x[2]);
		if(
		   1913<=x[0] && x[0]<=1925
		   ||x[0]==1912 && 7<x[1]
		   ||x[0]==1912 && x[1]==7 && 30<=x[2]
		   ||x[0]==1926 && x[1]<12
		   ||x[0]==1926 && x[1]==12 && x[2]<25)System.out.println("taisho"+" "+(x[0]-1912+1)+" "+x[1]+" "+x[2]);
		if(
		   1927<=x[0] && x[0]<=1988
		   ||x[0]==1926 && 12==x[1] && 25<=x[2]
		   
		   ||x[0]==1989 && x[1]==1 && x[2]<8
		   )System.out.println("showa"+" "+(x[0]-1926+1)+" "+x[1]+" "+x[2]);
		if(
		   1990<=x[0]
		   ||x[0]==1989 && 1==x[1] && 8<=x[2]
		   
		   
		   )System.out.println("heisei"+" "+(x[0]-1989+1)+" "+x[1]+" "+x[2]);
	    }
    }
}

Measured memory_bytes: 16904
def selectionSort(a, n)
  count = 0
  n.times do |i|
    minj = i
    i.upto(n-1) do |j|
      minj = j if a[j] < a[minj]
    end
    if i != minj
      a[i], a[minj] = a[minj], a[i]
      count += 1
    end
  end
  return count
end

n = gets.to_i
a = gets.chomp.split(' ').map(&:to_i)
count = selectionSort(a, n)
puts a.join(' ')
puts count

Measured memory_bytes: 8704
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,s,t;
  cin>>n>>s>>t;

  auto ask=
    [&](Int a,Int b){
      cout<<"? "<<a<<" "<<b<<endl;
      Int x;
      cin>>x;
      return x;
    };

  vector<Int> ds(n+1,0);
  vector<Int> dt(n+1,0);

  for(Int i=1;i<=n;i++){
    if(i==s||i==t) continue;
    ds[i]=ask(s,i);
    dt[i]=ask(t,i);
  }

  Int dist=ask(s,t);
  ds[t]=dt[s]=dist;

  using P = pair<Int, Int>;
  vector<P> vp;
  for(Int i=1;i<=n;i++){
    if(i==s||i==t) continue;
    if(ds[i]+dt[i]>dist) continue;
    vp.emplace_back(ds[i],i);
  }

  if(vp.empty()){
    cout<<"! "<<s<<" "<<t<<endl;
    return 0;
  }

  vp.emplace_back(ds[t],t);
  sort(vp.begin(),vp.end());

  Int pos=s;
  vector<Int> ans;
  ans.emplace_back(pos);

  Int i=0;
  while(pos!=t){
    while(1){
      //cerr<<":::"<<i<<" "<<vp.size()<<endl;
      Int k=vp[i].second;
      i++;
      if(ask(pos,k)+dt[k]==dt[pos]){
        pos=k;
        break;
      }
    }
    ans.emplace_back(pos);
  }

  cout<<"!";
  for(Int x:ans) cout<<" "<<x;
  cout<<endl;
  return 0;
}



Measured memory_bytes: 4652
import fractions

N, X = map(int, input().split())
x = list(map(int, input().split()))

if N == 1:
    print(abs(x[0] - X))

else:
    diff = []

    for i in x:
        diff.append(abs(X - i))

    g = fractions.gcd(diff[0],diff[1])

    for i in range(1,len(diff)):
        g = fractions.gcd(g,diff[i])

    print(g)

Measured memory_bytes: 16236
'''input
3
1 3 2
3 1 2
'''
# A coding delight
from sys import stdin, stdout
import gc
from copy import deepcopy
from itertools import permutations
gc.disable()
input = stdin.readline

	
# main starts
n = int(input().strip())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

a = list(permutations(P))
a.sort()
for i in range(len(a)):
	if tuple(P) == a[i]:
		first = i 
	if tuple(Q) == a[i]:
		second = i 
# print(first, second)
print(abs(first - second))



Measured memory_bytes: 8432
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード(アルファベット順,bits/stdc++.hは使わない派閥)
#include<algorithm>//sort,二分探索,など
#include<iostream>//入出力
#include<cmath>
#include<vector>
#include <iomanip>
#include <cstdio>

using namespace std;
#define INF 1000000000+9
int main(){
    long long H,W;
    string s="";
    while(1){
        cin >> H >> W;
        if((H==0)&&(W==0)){
            break;
        }
        for(int i=0; i<H; i++){
            s = "";
            for(int j=0; j<W; j++){
                if(i==0 || i==(H-1)){
                    s+="#";
                    continue;
                }
                if(j==0 || j==(W-1)){
                    s+="#";
                    continue;
                }
                s+=".";
            }
            cout << s << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3212
function main(input) {
    const args = input.split(' ');
    var arr = [parseInt(args[0], 10), parseInt(args[1], 10), parseInt(args[2], 10)];
    arr.sort();
    if (arr[0] == 5 && arr[1] == 5 && arr[2] == 7) {
        console.log("YES")
    } else {
        console.log("NO")
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
int main(void)
{
    long long N, ans=0;

    cin >> N;

    if(N==10 || N==100 || N==1000 || N==10000 || N==100000){
        cout << 10 << endl;
    }

    else{
        while(N > 0){
            ans += N%10;

            N /= 10;
        }

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<stdio.h>
using namespace std;
int dfn[503],low[503];
int n,m,u,v,dep,ans;
int head[503],to[1003],nxt[1003],tot;
inline void add(int a,int b){
	to[++tot]=b;  nxt[tot]=head[a];  head[a]=tot;
}
void tarjan(int u,int fa){
    dfn[u]=low[u]=++dep;
    for(int i=head[u];i;i=nxt[i]){
        int v=to[i];
        if(!dfn[v]){
            tarjan(v,u);
            low[u]=min(low[u],low[v]);
            if(low[v]>dfn[u]){
            	ans++;
			}
        }else if(v!=fa){
        	low[u]=min(low[u],dfn[v]);
		}
    }
}
int main(){
	cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>u>>v;
        add(u,v),add(v,u);
    }
    tarjan(1,-1);
    cout<<ans<<endl;
    return 0;
}
/*

in:
7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7

out:
4

*/

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n = 0;
  string s;
  cin >> n >> s;
  for(int i = 0;i <= s.size() - 1;i++){
    if(s[i] > 'Z' - n){
      s[i] = 'A' + n - ('Z' - s[i]) - 1;
    }
    else{
      s[i] = s[i] + n;
    }
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}


int main()
{
  ll n;
  cin >> n;
  printf("%lld",POW(sqrt(n),2));
}

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++ i)
#define ALL(r) r.begin(), r.end()
#define DUP(x, y) (((x) + (y) - 1) / (y))
#define YES puts("YES")
#define NO puts("NO")
#define Yes puts("Yes")
#define No puts("No")
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end())

using ll = std::int64_t;
using vint = std::vector<int>;
using vll = std::vector<ll>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

void Main() {
    int N, T;
    cin >> N >> T;
    vint c(N), t(N);
    rep(i, N) {
        cin >> c[i] >> t[i];
    }

    int ans = INF;
    rep(i, N) {
        if (t[i] <= T)ans = min(ans, c[i]);
    }
    if (ans == INF)puts("TLE");
    else {
        cout << ans << endl;
    }
}

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



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll a = in(), b = in();
	if (a == b) {
		cout << "Draw" << endl;
	} else if (a == 1) {
		cout << "Alice" << endl;
	} else if (b == 1) {
		cout << "Bob" << endl;
	} else {
		cout << (a < b ? "Bob" : "Alice") << endl;
	}
}

Measured memory_bytes: 256