akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		
		int a = fs.nextInt();
		int b = fs.nextInt();
		
		if(a % 3 == 0 || b % 3 == 0 || (a+b) % 3 == 0) {
			System.out.println("Possible");
		}else {
			System.out.println("Impossible");
		}
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}


}


Measured memory_bytes: 21332
#include <iostream>
#include <sstream>
#include <bitset>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>

using namespace std;


int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	vector<int> v;
	unordered_map<int, int> um;
	long long int res = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		v.push_back(a);
		um[a]++;
	}
	for (auto p : um) {
		res += (long long int)p.second * (p.second - 1) / 2;
	}
	for (int i = 0; i < n; i++) {
		cout << res - (um[v[i]] - 1) << endl;
	}
}









Measured memory_bytes: 8380
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def lcm(x, y) : return (x * y) // math.gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

A, B = LI()

ans = max(A+B, max(A+A-1, B+B-1))
print(ans)


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

int main()
{
  int x, y, z;
  while (scanf("%d %d %d", &x, &y, &z) != EOF)
  {
    swap(x, y);
    swap(x, z);
    printf("%d %d %d\n", x, y, z);
  }
  return 0;
}

Measured memory_bytes: 256
A, B = map(int, input().split())

def gcd(a, b):
    if b == 0: return a
    return gcd(b, a % b)

num = gcd(A, B)

if num < 2:
    print(1)
    quit()

length = int(num ** 0.5) + 2
isPrime = [True for i in range(length)]
isPrime[2] = True
for i in range(2, length):
    if isPrime[i]:
        for j in range(2 * i, length, i):
            isPrime[j] = False

count = 1

cur = 2
while num != 1 and cur < length:
    if isPrime[cur] and num % cur == 0:
        while num % cur == 0:
            num //= cur
        count += 1
    cur += 1

print(count + (num != 1))


Measured memory_bytes: 114032
import heapq
N, M = map(int, input().split())
A = list(map(int, input().split()))

pque = []

for i in A:
    heapq.heappush(pque, -i)

for i in range(M):
    p = -heapq.heappop(pque)
    p //= 2
    heapq.heappush(pque, -p)

print (-sum(pque))

Measured memory_bytes: 14180
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

LL N;
vector<LL>a, b;
LL as, bs;
LL av, bv;

int main(void)
{
	cin >> N;
	for (int i = 0; i < N; ++i) {
		LL aa; cin >> aa;
		a.push_back(aa);
		as += aa;
	}
	for (int i = 0; i < N; ++i) {
		LL bb; cin >> bb;
		b.push_back(bb);
		bs += bb;
	}
	LL tim = bs - as;
	for (int i = 0; i < N; ++i) {
		LL ap = 0, bp = 0;
		if (a[i] < b[i]) {
			LL dif = b[i] - a[i];
			if (dif % 2) {
				ap = dif / 2 + 1;
				bp = 1;
			}
			else {
				ap = dif / 2;
				bp = 0;
			}
		}
		else if (a[i] > b[i]) {
			bp = a[i] - b[i];
		}
		av += ap;
		bv += bp;
	}
	if (av <= tim && bv <= tim) {
		LL ad = tim - av;
		LL bd = tim - bv;
		if ((ad == 0 && bd == 0) || (bd % ad == 0 && bd / ad == 2)) {
			cout << "Yes\n";
			return 0;
		}
	}
	cout << "No\n";
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007

int main(){
    int n,m;
    cin>>n>>m;
    vector<long long> dp(n+1);
    vector<bool> a(n+1);
    rep(i,m){
        int tmp;
        cin>>tmp;
        a[tmp]=true;
    }
    dp[0]=1;
    if(a[1]){
        dp[1]=0;
    }
    else{
        dp[1]=1;
    }
    for(int i=2;i<=n;i++){
        if(a[i]){
            dp[i]=0;
        }
        else{
            dp[i]=(dp[i-1]+dp[i-2])%mod;
        }
    }
    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言
#define MAX 1200000

int S[MAX];

//問題をよく読もう！
//論理的に考えよう！
//サンプルを確認しよう!
//絶対に諦めるな！
//工夫をしろ！
int main() {
  int s;
  cin >> s;
  int i = 1;
  int index = 1;
  int A;
  int flag = 0;

  S[0] = s;

  while(1) {
    if(S[index-1] % 2 ==0) {
      A = S[index-1] / 2;
    } else {
      A = S[index-1]*3 + 1;
    }

    rep(j, index) {
      if(S[j] == A) {
        flag = 1;
        break;
      }
    }
    if(flag) break;

    S[index] = A;
    index += 1;
  }

  cout << index + 1 << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

// ARC 77-C
// http://arc077.contest.atcoder.jp/tasks/arc077_a

public class Main {
	
	public static void main (String[] args) throws InterruptedException {
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		int M = in.nextInt();
		int K = in.nextInt();
		
		boolean isPossible = false;
		
		for (int x = 0; x <= N && !isPossible; x++) {
			for (int y = 0; y <= M && !isPossible; y++) {
				int numBlack = (x * M - x * y) + (y * N - x * y);
//				System.out.printf("x: %d, y: %d, numBlack: %d\n", x, y, numBlack);
				if (numBlack == K) {
					isPossible = true;
				}
			}
		}
		
		System.out.println(isPossible ? "Yes" : "No");
	}
	
}


Measured memory_bytes: 23764
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// #define ll long long 
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 998244353; //1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e5+2;
vector<int> a[N];
bool viss[N];
int d1[2][N];
void dfs1(int x,int ind,int d=0)
{
	if(viss[x]) return;
	viss[x]=true;
	d1[ind][x]=d;
	for(auto y:a[x])
	{
		dfs1(y,ind,d+1);
	}
}
int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);

      int n;
      cin>>n;
      for(int i=0;i<n;i++)
      {
      	int x,y;
      	cin>>x>>y;
      	a[x].pb(y);
      	a[y].pb(x);
      }
      dfs1(1,0);
      for(int i=1;i<=n;i++) viss[i]=false;
      dfs1(n,1);
 	 int cnt1=0,cnt2=0;
 	 for(int i=1;i<=n;i++)
 	 {
 	 	if(d1[0][i]<=d1[1][i])
 	 	{
 	 		cnt1++;
 	 	}
 	 	else cnt2++;
 	 }
 	 if(cnt1>cnt2)
 	 {
 	 	cout<<"Fennec";
 	 }
 	 else cout<<"Snuke";
 	 // cout<<cnt1<<" "<<cnt2<<"\n";
 	 
}
// I never lose. I either win or I learn

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

int main()
{
 bool prime[10000000];

 prime[0]=prime[1]=false;
 for(int i=2;i<10000000;i++){
	prime[i]=true;
 }
 for(int i=2;i*i<10000000;i++){
	if(prime[i]){
		for(int j=i*i;j<10000000;j+=i){
			prime[j]=false;
		}
	}
 }
//???????????§?´???°??¨
 int n;
 while(1){
	cin>>n;
  if(n==0)break;
	for(int i=n;i>0;i--){
		if(prime[i-8]&&prime[i-6]&&prime[i-2]&&prime[i]){
			cout<<i<<endl;
			break;
		}
	}
 }
 return 0;
}
	

Measured memory_bytes: 12832
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int ans = 0;
	int n = s.size();
	for(int i=0;i<s.size()/2;i++){
		if(s[i]!=s[n-1-i])ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import heapq
def dijkstra_heap(s,edge):
    #始点sから各頂点への最短距離
    d = [float("inf")] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,[e[0]+d[v],e[1]])
    return d

import sys
input = sys.stdin.readline
n = int(input())
edge = [[] for i in range(n)]
for i in range(n-1):
    x,y,z = map(int,input().split())
    edge[x-1].append([z,y-1]) # list限定
    edge[y-1].append([z,x-1]) 

q,k = map(int,input().split())
chk = dijkstra_heap(k-1,edge)
  

for i in range(q):
  x,y = [int(i) for i in input().split()] 
  print(chk[x-1] + chk[y-1])

Measured memory_bytes: 55960
#include <iostream>
#include <map>
#include <vector>
using namespace std;
#define MOD 1000000007
#define ll long long

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, a, b) for (int i = a; i < b; i++)
#define REPR(i, a, b) for (int i = a; i >= b; i--)

int main()
{
    int d, g;
    cin >> d >> g;
    vector<int> p(d), c(d);
    REP(i, d)
    {
        cin >> p[i] >> c[i];
    }
    vector<int> ans_f(1001, 0);
    int mxp = 0;
    for (int i = 0; i < d; i++)
    {
        vector<int> ans = ans_f;
        for (int j = 1; j <= p[i]; j++)
        {
            for (int np = 0; np <= mxp; np++)
            {
                if (np + j <= 1000)
                {
                    if (j == p[i])
                    {
                        ans_f[np + j] = max(ans_f[np + j], ans[np] + (i + 1) * 100 * j + c[i]);
                    }
                    else
                    {
                        ans_f[np + j] = max(ans_f[np + j], ans[np] + (i + 1) * 100 * j);
                    }
                    //if (np + j < 10)
                    //cout << i << " " << np + j << " " << ans_f[np + j] << endl;
                }
            }
        }
        mxp += p[i];
    }
    for (int i = 0; i <= 1000; i++)
    {
        if (ans_f[i] >= g)
        {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int huw(int n)
{
	int a[5],i,j,k;
	for(i=4,j=1;i>=0;i--,j*=10) a[i]=n/j%10;
	for(k=0;a[k]==0;k++) {}
	for(i=k,j=0;j<(5-k)/2;i++,j++)
	{
		if(a[i]!=a[4-j]) 
			return 0;
	}
	return 1;
}
int main()
{
	int n,i;
	while(~scanf("%d",&n))
	{
		if(huw(n)) printf("%d\n",n);
		else
		{
			for(i=1; ;i++)
			{
				if(huw(n-i)) 
				{
					printf("%d\n",n-i);  goto End;
				}
				if(huw(n+i)) 
					{
						printf("%d\n",n+i); goto End;
					}
			}
		}End: ;
	}
	return 0;
}


Measured memory_bytes: 2756
h,w = gets.chomp.split().map(&:to_i)
s= []
h.times do
  s.push gets.chomp.split(//)
end

def solve(grid,yy,xx, h,w)
  dy = [0, 1, 0, -1]; dx = [1, 0, -1, 0]

  visited = Array.new(h){Array.new(w, 0)}
  visited[yy][xx] = true
  q = [[yy,xx,0]]

  ans = 0
  until q.empty?
    y,x,cost = q.shift
    4.times do |i|
      ny = y + dy[i]; nx = x + dx[i]
      if (0 <= ny && ny < h) && (0 <= nx && nx < w) && grid[ny][nx] != '#' && visited[ny][nx] == 0
        visited[ny][nx] = 1
        q.push [ny, nx, cost+1]
        ans = cost+1 if ans < cost+1
      end
    end
  end
  ans
end

ans = 0
h.times do |i|
  w.times do |j|
    if s[i][j] != '#'
      solved = solve(s,i,j, h,w)
      ans = solved if ans < solved
    end
  end
end

puts ans




Measured memory_bytes: 1788
#include <bits/stdc++.h> 
 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<long, long> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const double EPS=1e-10;

int main(){
    int N,K;
    cin>>N>>K;
    vector<LL>x(N);
    REP(i,N)cin>>x[i];
    LL res=1e10;
    REP(ld,N-K+1){
        LL rd=ld+K-1;
        if(x[rd]<=0){
            res=min(res,abs(x[ld]));
        }else if(x[ld]>=0){
            res=min(res,abs(x[rd]));
        }else if(x[rd]>0){
            res=min(res,min(abs(x[ld])*2+x[rd],abs(x[ld])+x[rd]*2));
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	Scanner sc;

	Main() {
		sc = new Scanner(System.in);
	}

	void run() {
		for (;;) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}
			double[] sx = new double[n];
			double[] sy = new double[n];
			double[] sz = new double[n];

			for (int i = 0; i < n; i++) {
				sx[i] = sc.nextDouble();
				sy[i] = sc.nextDouble();
				sz[i] = sc.nextDouble();
			}
			int m = sc.nextInt();

			double[] tx = new double[m];
			double[] ty = new double[m];
			double[] tz = new double[m];
			double[] phi = new double[m];
			for (int i = 0; i < m; i++) {
				tx[i] = sc.nextDouble();
				ty[i] = sc.nextDouble();
				tz[i] = sc.nextDouble();
				double length = tx[i]*tx[i] + ty[i]*ty[i] + tz[i]*tz[i];
				length = Math.sqrt(length);

				tx[i] /= length;
				ty[i] /= length;
				tz[i] /= length;
				
				phi[i] = sc.nextDouble();
			}
			
			int ans= 0; 
			for(int i = 0; i < n ; i++){
				double length = sx[i]*sx[i]+sy[i]*sy[i]+sz[i]*sz[i];
				length = Math.sqrt(length);
				
				double x = sx[i]/length;
				double y = sy[i]/length;
				double z = sz[i]/length;
				
				for(int j = 0; j < m; j++){
					double v = x*tx[j]+y*ty[j]+z*tz[j];
					double v2 = Math.cos(phi[j]);
					if(v > v2){
						ans++;
						break;
					}
				}
				
			}
			System.out.println(ans);
			
		}
	}

	public static void main(String args[]) {
		Main m = new Main();
		m.run();
	}
}

Measured memory_bytes: 0
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {

	LL n, m; cin >> n >> m;

	LL p = 0;
	LL q = 0;

	for (LL i = 0; i < n; i++) {
		LL x; cin >> x;
		x += MOD;

		p = (p - x * (n - 1 - i) % MOD + x * i + MOD) % MOD;
	}

	for (LL i = 0; i < m; i++) {
		LL y; cin >> y;
		y += MOD;

		q = (q - y * (m - 1 - i) % MOD + y * i + MOD) % MOD;
	}

	cout << p * q%MOD << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct student
{
    int name;
    int val;
};
bool compare( struct student a ,struct student b )
{
    return a.val< b.val;
}
int main()
{
    int n;
    cin>>n;
    auto* stu = new student[n];
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        stu[i].name = i+1;
        stu[i].val = x;
    }
    sort(stu , stu + n, compare);
    for(int i=0;i<n;i++)
    {
        cout << stu[i].name << " ";
    }
}

Measured memory_bytes: 4400
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Mid (l+r)/2
#define int ll
const int mod=1e9+7,inf=0x3f3f3f3f,maxn=2e5+5;
int n,m,Q,K;

int read(){
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-'0';c=getchar();}
    return x*f;
}
string s[maxn],q[maxn];
map<string,int>p;
bool cmp(string a,string b){
    return a<b;
}
signed main(){
//  freopen("a.in","r",stdin);
//  freopen("a.out","w",stdout);
    n=read();
    for(int i=1;i<=n;++i){
        cin>>s[i];
        p[s[i]]++;
    }//cout<<endl;
    int Max=0,len=0;
    for(int i=1;i<=n;++i)Max=max(Max,p[s[i]]);
    for(int i=1;i<=n;++i){
        if(p[s[i]]==Max){
            p[s[i]]=-1;
            q[++len]=s[i];
        }
    }sort(q+1,q+1+len);
    for(int i=1;i<=len;++i){
        for(int j=0;j<q[i].size();++j){
            cout<<q[i][j];
        }cout<<endl;
    }
    return 0;
}

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

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), p(n), q(n);
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> q[i];

  iota(a.begin(), a.end(), 1);

  ll i = 0, np, nq;
  do {
    bool flgp = true, flgq = true;
    rep(i, n) if (a[i] != p[i]) flgp = false;
    rep(i, n) if (a[i] != q[i]) flgq = false;

    if (flgp) np = i;
    if (flgq) nq = i;

    i++;
  } while (next_permutation(a.begin(), a.end()));

  cout << abs(np - nq) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 100000000000000000;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

ll modpow(ll a,ll n,ll m){//modpow(a,n,m) := a ^ n (mod m)
  ll res = 1;
  while(n > 0){
    if(n & 1)res = res * a % m;
    a = a * a % m;
    n >>= 1;
  }
  return res;
}

int main(){
    ll N;cin >> N;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    ll ans = 0;
    sort(ALL(A));
    rep(i,N){
        ll cost = 0;
        cost = A[i] * modpow(2,i,MOD);
        cost %= MOD;
        cost *= (modpow(2,N-i-1,MOD) + (N-i-1) * modpow(2,N-i-2,MOD)) % MOD;
        ans += cost;
        ans %= MOD;
    }
    ans *= modpow(2,N,MOD);
    cout << ans % MOD << endl;
}



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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


using vvll = vector< vector<ll> >;
using vll = vector<ll> ;

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

ll fast(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        y >>= 1;
    }
    return res;
}

ll inv(ll n){
    return fast(n,mod-2);
}

ll fact[maxs];
ll ifact[maxs];

void pre(){

    fact[0] = ifact[0] = 1;
    for(ll i=1;i<maxs;i++){
        fact[i] = fact[i-1]*i%mod;
        ifact[i] = inv(fact[i]);
    }

}

ll ncr(ll n,ll r){
    ll tmp  = fact[n]*ifact[n-r]%mod;
    tmp = tmp*ifact[r]%mod;
    return tmp;
}

ll suf[maxs];

void solve(){

    ll n,m;
    cin >> n >> m;
    suf[n] = 1;
    for(ll i=n-1;i>=0;i--){
        suf[i] = m-i;
        suf[i] *= suf[i+1];
        suf[i] %= mod;
    }
    ll ans = ncr(m,n)*fact[n]%mod;
    ll ways = 0;
    ll cur = 1;
    for(ll i=0;i<=n;i++){
        ways += cur*(ncr(n,i)*ncr(m-i,n-i))%mod*fact[n-i]%mod;
        ways %= mod;
        cur = -cur;
    }
    ways %= mod;
    ways += mod;
    ways %= mod;
    ans *= ways;
    ans %= mod;
    cout << ans << endl;

}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 22988
S = input()
K = int(input())

L = []
temp = S[0]
c = 1
for i in range(1, len(S)):
    if S[i] == temp:
        c += 1
    else:
        L.append(c)
        c = 1
        temp = S[i]
    if i == len(S)-1:
        L.append(c)
        
ans = 0

if S[0] != S[-1]:
    for i in range(len(L)):
        ans += (L[i]//2)
    ans *= K
else:
    if len(L) == 1:
        ans += K*L[0]//2
    elif len(L) == 0:
        ans += K//2
    else:
        for i in range(1, len(L)-1):
            ans += (L[i]//2)
        ans *= K
        ans += L[0]//2
        ans += L[-1]//2
        ans += (L[0]+L[-1])//2*(K-1)
        
print(ans)

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

int main() {
  int n;
  cin >> n;
  int R[n];
  for (int t=0; t<n; t++) {
    cin >> R[t];
  }
  int maxv=R[1]-R[0];
  int minv=R[0];
  for (int j=1; j<n; j++) {
    maxv=max(maxv,R[j]-minv);
    minv=min(minv,R[j]);
  }
  printf("%d\n",maxv);
  return 0;
}

Measured memory_bytes: 3976
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B,L;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MOD = (1e+9) + 7;

int main(){
    cin>>S;
    N = S.size();
    ll t = 1;
    vec tmod(N,0);
    rep(i,N){
        tmod[i] = t%13;
        (t *= 10)%=13;
    }
    mat dp(N+1,vec(13,0));
    dp[0][0] = 1;
    rep(i,N){
        if(S[i] != '?'){
            A = S[i] - '0';
            rep(j,13) (dp[i+1][(j+A*tmod[N-1-i])%13] += dp[i][j])%=MOD;
        }else{
            rep(a,10){
                rep(j,13) (dp[i+1][(j+a*tmod[N-1-i])%13] += dp[i][j])%=MOD;
            }
        }
    }
    cout<<dp[N][5]<<endl;
}


Measured memory_bytes: 14464
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;

int main(){
    int w, h;
    while(cin>>w>>h && h|w){
        static int dp[111][111][4];
        for(int i=0;i<111;i++)
            for(int j=0;j<111;j++)
                for(int k=0;k<4;k++)dp[i][j][k]=0;
        for(int i=0;i<h;i++)dp[i][0][0]=1;
        for(int i=0;i<w;i++)dp[0][i][2]=1;
        for(int i=1;i<h;i++){
            for(int j=1; j<w; j++){
                if(i-1>=0)dp[i][j][0]+=dp[i-1][j][0]+dp[i-1][j][1];
                if(i-1>=0)dp[i][j][1]+=dp[i-1][j][2];
                if(j-1>=0)dp[i][j][2]+=dp[i][j-1][2]+dp[i][j-1][3];
                if(j-1>=0)dp[i][j][3]+=dp[i][j-1][0];
                for(int k=0; k<4; k++)dp[i][j][k]%=100000;
            }
        }

        int ans=0;
        for(int i=0; i<4; i++) ans+=dp[h-1][w-1][i];
        cout << ans%100000 << endl;
    }
}

Measured memory_bytes: 1352
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
typedef long long ll;
const int INF = 1e9+1;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
using namespace std;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << max(a * b, c * d);
	return 0;
}

Measured memory_bytes: 3620
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int min = Integer.MAX_VALUE;
    for(int i = 0; i < n; i++) {
      int num = sc.nextInt();
      min = Math.min(min, count(num));
    }
    System.out.println(min);
  }
  public static int count(int num) {
    int count = 0;
    while(num % 2 == 0) {
      count++;
      num /= 2;
    }
    return count;
  }
}


Measured memory_bytes: 23892
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		String res = "No";
		for(int i = 1;i < 10;i++){
			if(N%i==0 && N/i < 10){
				res = "Yes";
				break;
			}
		}
		System.out.println(res);
	}
}

Measured memory_bytes: 22608
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextLong()
    val a = sc.nextLong()
    val b = sc.nextLong()
    if ((b - a) % 2L == 0L) {
        println((b - a) / 2L)
    } else {
        println(Math.min(a + (b - a) / 2L, n - b + 1 + (b - a) / 2L))
    }
}


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

using namespace std;
int main(){
    string s;cin>>s;

    if(s=="ABC") {cout << "ARC" <<endl;}
    else cout << "ABC" <<endl;

    return 0;
}

Measured memory_bytes: 3636
/**
* Author : zzy
* Date : 2020-04-12-19.51.56 Sunday
*/
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string.h>
#include <limits.h>
#include <string>
#include <iostream>
#include <queue>
#include <math.h>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <iterator>
#include <list>
#include <cstdio>
#include <iomanip>
#include <climits>

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) ((int)(x).size())

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

string s;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    cin >> s;
    bool ok = false;
    forn(i, 3) {
        if (s[i] == '7') ok = true;
    }
    cout << (ok ? "Yes" : "No") << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <math.h>

int main(void){
	int hen1, hen2, hen3;
	int i, j, n;
	int s, m, l;
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf("%d %d %d", &hen1, &hen2, &hen3);
		if((hen1 < hen2) && (hen1 < hen3)){
			s = hen1;
			if(hen2 < hen3){
				m = hen2;
				l = hen3;
			}
			else{
				m = hen3;
				l = hen2;
			}
		}
		else if((hen2 < hen1) && (hen2 < hen3)){
			s = hen2;
			if(hen1 < hen3){
				m = hen1;
				l = hen3;
			}
			else{
				m = hen3;
				l = hen1;
			}
		}
		else{
			s = hen3;
			if(hen1 < hen2){
				m = hen1;
				l = hen2;
			}
			else{
				m = hen2;
				l = hen1;
			}
		}
		if((l * l) == (s * s + m * m)){
			printf("YES\n");
		}
		else{
			printf("NO\n");
		}
	}

	return 0;
}

Measured memory_bytes: 580
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
const int mod=1e9+7;
int modp(int a,int b)
{
	if(b==0)return 1;
	int u=modp(a,b/2);
	u=(u*u)%mod;
	if(b&1)return (a*u)%mod;
	return u;
}
int32_t main()
{

	int n=in();
	
	int rem=(2*modp(9,n))%mod;
	int base=modp(10,n);
	int common=modp(8,n);
	rem-=common;rem%=mod;rem+=mod;rem%=mod;
	base-=rem;base%=mod;base+=mod;base%=mod;
	cout<<base;
	
}


Measured memory_bytes: 3760
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int wallet = sc.nextInt();
    int cake = sc.nextInt();
    int donut = sc.nextInt();

    int change = (wallet - cake) % donut;

    System.out.println(change);

  }
}

Measured memory_bytes: 21844
def preorder(u, tree, res)
  return if u == -1
  res << u 
  preorder(tree[u].left, tree, res)
  preorder(tree[u].right, tree, res)
  res
end
 
def inorder(u, tree, res)
  return if u == -1
  inorder(tree[u].left, tree, res)
  res << u
  inorder(tree[u].right, tree, res)
  res
end
 
def postorder(u, tree, res)
  return if u == -1
  postorder(tree[u].left, tree, res)
  postorder(tree[u].right, tree, res)
  res << u
  res
end
 
class Node
  attr_accessor :left, :right, :parent
  def initialize(parent, left, right)
    @parent = parent
    @left = left
    @right = right
  end
end

n = gets.to_i
 
tree = []
n.times do |i|
  tree[i] = Node.new(-1, -1, -1)
end


 

n.times do
  id, l, r = gets.chomp.split(' ').map(&:to_i)
  tree[id].left = l
  tree[id].right = r
  tree[l].parent = id if l != -1
  tree[r].parent = id if r != -1
end
 
root = tree.index{|i| i.parent == -1}

puts 'Preorder'
puts " #{preorder(root, tree, []).join(' ')}"
puts 'Inorder'
puts " #{inorder(root, tree, []).join(' ')}"
puts 'Postorder'
puts " #{postorder(root, tree, []).join(' ')}"

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

using namespace std;

typedef long long ll;

const int INF = 1e9+7;


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

    vector <bool> position(k+1, 0);
    vector <int> a(n);
    for (int i=0; i<n; ++i)
        cin >> a[i];

    for (int i=1; i<=k; ++i)
        for (int j=0; j<n; ++j)
            if (i - a[j] >= 0 && position[i-a[j]] == 0)
                position[i] = 1;

    if (position[k])
        cout << "First";
    else
        cout << "Second";
    return 0;
}

Measured memory_bytes: 256
// Let's bring the sky down :)
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 3e5 + 5;
ll a[N];
ll dp[N];
int main()
{
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n, k;
    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 0; i < N; i++) dp[i] = INT_MAX;
    dp[1] = 0;
    for(int i = 1; i <= n; i++){
        int l = max(1, i - k);
        for(int j = i - 1; j >= l; j--)
        dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
    }
    cout << dp[n];
return 0;
}


Measured memory_bytes: 4352
//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    char s[262144];
    long long i,b[256]={0},r,l;
    scanf("%s",s);
    l=strlen(s);
    r=llnCr(l,2)+1;
    for(i=0;i<l;i++){b[s[i]]++;}
    for(i='a';i<='z';i++){r-=llnCr(b[i],2);}
    printf("%lld\n",r);
    return 0;
}

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

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

using ll = long long;

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

vector<string> grid;
int H,W;

struct UnionFind {
    vector<int> par,rank,large,wsize;

    void init(int N){
        rank.assign(N,0);
        large.assign(N,1);
        par.resize(N);
        wsize.resize(N);
        for(int i= 0; i < N; i++){
            par[i]=i;
            if(grid[i/W][i%W]=='.') wsize[i]=1;
            else wsize[i]=0;
        }
    }

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

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if(rank[rx]<rank[ry]) {
            par[rx]=ry;
            large[ry]+=large[rx];
            large[rx]=0;
            wsize[ry]+=wsize[rx];
            wsize[rx]=0;
        }
        else {
            par[ry]=rx;
            large[rx]+=large[ry];
            large[ry]=0;
            wsize[rx]+=wsize[ry];
            wsize[ry]=0;
            if(rank[rx]==rank[ry])rank[x]++;
        }
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

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

int main() {
  cin>>H>>W;
  grid.resize(H);
  for(int i = 0; i < H; i++) cin>>grid[i];
  UnionFind tree;
  tree.init(H*W);
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++){
      for(int k = 0; k < 4; k++) {
        int nx,ny;
        nx=i+dx[k];
        ny=j+dy[k];
        if(nx>=H||nx<0||ny>=W||ny<0) continue;
        if(grid[i][j]!=grid[nx][ny]) tree.unite(W*i+j,W*nx+ny);
      }
    }
  }
  ll ans = 0LL;
  for(int i = 0; i < H*W;i++){
    ans+=(ll)tree.wsize[i]*((ll)tree.large[i]-(ll)tree.wsize[i]);
  }cout<<ans<<endl;
}
        

Measured memory_bytes: 2944
#include <stdio.h>
#include <math.h>

int intcount(int *a, int *b, int len) {
  int sum = 0;
  for (int i = 0; i < len; i++) {
    sum += (a[i] - b[i]) * (a[i] - b[i]);
  }
  if ((sqrt(sum) - (int)sqrt(sum)) == 0)
    return 1;
  else
    return 0;
}

int main(int argc, const char *argv[])
{
  int n, d;
  scanf("%d%d", &n, &d);
  int x[n][d];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++) {
      scanf("%d", &x[i][j]);
    }
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      if (i != j)
        count += intcount(x[i], x[j], d);
    }
  }
  printf("%d\n", count);
  return 0;
}

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

using namespace std;

int main(int argc, char* argv[]) {
    int N;
    std::cin >> N;

    auto x = new int[N];
    auto y = new int[N];
    auto h = new int[N];

    int hmin = 1000000001;
    int hmax = 0;
    for (int i = 0; i < N; i++) {
        std::cin >> x[i] >> y[i] >> h[i];
        if (hmin > h[i]) hmin = h[i];
        if (hmax < h[i]) hmax = h[i];
    }

#if 0
    auto v1 = std::max(1 , hmin - 200);
    for (int H = 1; H <= 1000000000; H++) {
        for (int cx = 0; cx <= 100; cx++) {
            for (int cy = 0; cy <= 100; cy++) {
                bool ok = false;
                for (int i = 0; i < N; i++) {
                    auto v = std::max(H - abs(x[i] - cx) - abs(y[i] - cy), 0);
                    if (h[i] == v) ok = true;
                    else {
                        ok = false;
                        break;
                    }
                }
                if (ok) {
                    std::cout << cx << " " << cy << " " << H << std::endl;
                    return 0;
                }
            }
        }
    }
#else
    for (int cx = 0; cx <= 100; cx++) {
        for (int cy = 0; cy <= 100; cy++) {

            int index = 0;
            int H = 0;
            for (int i = 0; i < N; i++) {
                if (h[i] != 0) {
                    H = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
                    index = i;
                }
            }

            bool ok = false;
            for (int i = 0; i < N; i++) {
                if (h[i] != 0) {
                    if (H == h[i] + abs(x[i] - cx) + abs(y[i] - cy))
                        ok = true;
                    else {
                        ok = false;
                        break;
                    }
                } else {
                    if (H - abs(x[i] - cx) - abs(y[i] - cy) <= 0)
                        ok = true;
                    else {
                        ok = false;
                        break;
                    }
                }
            }
            if (ok) {
                std::cout << cx << " " << cy << " " << H << std::endl;
                return 0;
            }
        }
    }
#endif

    return 0;
}

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

#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int h, w;
char field[120][120];

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

void dfs(int x, int y, char c) {
  if(c != field[y][x]) return;
  field[y][x] = '.';
  rep(i, 4) {
    int nx = x+dx[i], ny = y+dy[i];
    if(0 <= nx && nx < w && 0 <= ny && ny < h && field[ny][nx] == c) {
      dfs(nx, ny, c);
    }
  }
}

int main() {
  while(cin >> h >> w, h+w) {
    rep(i, h) rep(j, w) cin >> field[i][j];

    int ans = 0;
    rep(i, h) {
      rep(j, w) {
        if(field[i][j] == '.') continue;
        else {
          ans++;
          dfs(j, i, field[i][j]);
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1636
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define acc(v) accumulate(v.begin(), v.end(), 0)

using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;

int main()
{
	int count = 0;
	ll x;
	cin >> x;
	ll now = 100;
	while (now < x){
		count++;
		now = floor(now * 1.01);
	}
	cout << count << endl;
}


Measured memory_bytes: 3712
#include<cstdio>
#include<iostream>
using namespace std;
#define max lshfisdhflsih
int dp[2001][2001][2];
int main(void){
	int i,j,m,n,max,x,nn,k;
	char s[2001],t[2001];
	cin>>m>>n>>s>>t;
	for(i=0;i<=m;i++){
		for(j=0;j<=n;j++){
			dp[i][j][0]=-1; dp[i][j][1]=-1;
		}
	}
	dp[0][0][0]=0;
	for(i=0;i<=m;i++){
		for(j=0;j<=n;j++){
			if(i<m){
				if(dp[i][j][0]!=-1){
					if(s[i]=='I'){
						nn=dp[i][j][0]+1;
						if(dp[i+1][j][1]<nn) dp[i+1][j][1]=nn;
					}
					else {
						if(dp[i+1][j][0]==-1) dp[i+1][j][0]=0;
					}
				}
				if(dp[i][j][1]!=-1){
					if(s[i]=='O'){
						nn=dp[i][j][1]+1;
						if(dp[i+1][j][0]<nn) dp[i+1][j][0]=nn;
					}
					else {
						if(dp[i+1][j][1]==-1) dp[i+1][j][1]=1;
					}
				}
			}
			if(j<n){
				if(dp[i][j][0]!=-1){
					if(t[j]=='I'){
						nn=dp[i][j][0]+1;
						if(dp[i][j+1][1]<nn) dp[i][j+1][1]=nn;
					}
					else {
						if(dp[i][j+1][0]==-1) dp[i][j+1][0]=0;
					}
				}
				if(dp[i][j][1]!=-1){
					if(t[j]=='O'){
						nn=dp[i][j][1]+1;
						if(dp[i][j+1][0]<nn) dp[i][j+1][0]=nn;
					}
					else {
						if(dp[i][j+1][1]==-1) dp[i][j+1][1]=1;
					}
				}
			}
		}
	}
/*	for(i=0;i<=m;i++){
		for(j=0;j<=n;j++) printf("%d:%d ",dp[i][j][1],dp[i][j][0]);
		cout<<endl;
	}*/
	max=0;
	for(i=0;i<=m;i++){
		for(j=0;j<=n;j++){
			if(max<dp[i][j][1]) max=dp[i][j][1];
		}
	}
	cout<<max<<endl;
	return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;

    int mn = min(a, b);
    int mx = max(a, b);

    for (int i = 0; i < mx; i++) {
        cout << mn;
    }
    cout << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ALDS1_8A{
    public class Program{
        public static void Main(string[] args){
            var N = int.Parse(Console.ReadLine());
            var tree = new Tree();

            for(var i = 0; i < N; i++){
                var rl = Console.ReadLine().Split(' ');
                if(rl[0] == "insert"){
                    tree.Add(int.Parse(rl[1]));
                }
                if(rl[0] == "print"){
                    Console.WriteLine(" " + string.Join(" ", tree.Order(TreeWalk.InOrder).Select(n => n.Id.ToString()).ToArray()));
                    Console.WriteLine(" " + string.Join(" ", tree.Order(TreeWalk.PreOrder).Select(n => n.Id.ToString()).ToArray()));
                }
            }
        }
    }

    public enum TreeWalk{
        PreOrder,
        InOrder,
        PostOrder
    }

    public class Tree{
        public Dictionary<int, Node> Nodes = new Dictionary<int, Node>();
        public Node Root;

        public void Add(int id){
            Nodes.Add(id, new Node(id));

            if(Root == null){
                Root = Nodes[id];
                return;
            }

            var curNode = Root;
            while(true){
                if(curNode.Id > id){
                    if(curNode.Left == null){
                        curNode.Left = Nodes[id];
                        Nodes[id].Parent = curNode.Left;
                        break;
                    }
                    curNode = curNode.Left;
                }

                if(curNode.Id < id){
                    if(curNode.Right == null){
                        curNode.Right = Nodes[id];
                        Nodes[id].Parent = curNode.Right;
                        break;
                    }
                    curNode = curNode.Right;
                }
            }

        }

        public List<Node> Order(TreeWalk tw){
            var res = new List<Node>();

            Action<Node> parse = null;
            parse = node =>{
                if(node == null) return;

                if(tw == TreeWalk.PreOrder) res.Add(node);
                parse(node.Left);
                if(tw == TreeWalk.InOrder) res.Add(node);
                parse(node.Right);
                if(tw == TreeWalk.PostOrder) res.Add(node);
            };
            parse(Nodes.Single(n => n.Value.Parent == null).Value);

            return res;
        }
    }

    public class Node{
        public int Id;
        public Node Parent;
        public Node Left;
        public Node Right;

        public Node(int id){
            Id = id;
        }
    }
}

Measured memory_bytes: 117740