akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;


public class MyProgram
{	
  
    public static void Main()
	{
      　int n = int.Parse(Console.ReadLine());
        int[] ns = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        
        int a1 = 0, a2 = 0 , b1 = 0 , b2 = 0;
        
        Dictionary <int,int> nums1 = new Dictionary<int,int>();
        Dictionary <int,int> nums2 = new Dictionary<int,int>();
        
        for(int i = 0 ; i < n ; i++)
        {
            if(i % 2 == 0)
            {
                if(!nums1.Keys.Contains(ns[i])) nums1.Add(ns[i],1);
                else nums1[ns[i]]++;
            }
            else
            {
            if(!nums2.Keys.Contains(ns[i])) nums2.Add(ns[i],1);
            else nums2[ns[i]]++;
            }
        }
        nums1 = nums1.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
        List <int> sss1 = nums1.Keys.ToList();
        a1 = nums1[sss1[0]];
        
        nums2 = nums2.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
        List <int> sss2 = nums2.Keys.ToList();
        b1 = nums2[sss2[0]];
        
        if(sss1[0] != sss2[0])
        {
            Console.WriteLine(n-a1-b1);
        }
        else
        {
            if(sss1.Count > 1) a2 = nums1[sss1[1]];
            if(sss2.Count > 1) b2 = nums2[sss2[1]];
            
            int a1b2 = n - a1 - b2;
            int a2b1 = n - a2 - b1;
            
            Console.WriteLine(Math.Min(a1b2,a2b1));
        }
    }
}

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

using namespace std;

int main() {
  long long int n;
  cin >> n;
  vector<long long int> table(3*n);
  vector<pair<long long int, long long int>> p(n+1);
  for (long long int i = 0; i < 3*n; ++i) {
    cin >> table[i];
  }

  priority_queue<long long int, vector<long long int>, greater<long long int>> flist;
  long long int sum1 = 0;
  for (long long int i = 0; i < n; ++i) {
    flist.push(table[i]);
    sum1 += table[i];
  }
  p[0].first = sum1;
  for (long long int i = n; i < 2*n; ++i) {
    flist.push(table[i]);
    p[i - n + 1].first = p[i - n].first + table[i];
    p[i - n + 1].first -= flist.top();
    flist.pop();
  }

  priority_queue<long long int> llist;
  long long int sum2 = 0;
  for (long long int i = 3*n-1; i > 2*n-1; --i) {
    llist.push(table[i]);
    sum2 += table[i];
  }
  p[n].second = sum2;
  for (long long int i = 2*n-1; i > n-1; --i) {
    llist.push(table[i]);
    p[i - n].second = p[i - n + 1].second + table[i];
    p[i - n].second -= llist.top();
    llist.pop();
  }

  long long int S = LLONG_MIN;
  for (auto& x : p) {
    //cout << x.first << ", " << x.second << ", " << x.first - x.second << endl;
    S = max(S, x.first - x.second);
  }

  cout << S << endl;
  return 0;
}

Measured memory_bytes: 6516
#include <iostream>
using namespace std;
int main(void){
    
    int a,b,c;
    cin >> a >> b >> c;
    int x;
    x = b +c;
    
    if(a < x )
        {
        int ans;
        ans = x - a;
        cout << ans << endl;
        }
    else
        cout << "0" << endl;

}


Measured memory_bytes: 3616
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Program
{
    public class ABC061D
    {
        static class Console_
        {
            private static Queue<string> param = new Queue<string>();
            public static int NextInt() => int.Parse(NextString());
            public static long NextLong() => long.Parse(NextString());
            public static string NextString()
            {
                if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item);
                return param.Dequeue();
            }
        }
        static public void Main(string[] args)
        {
            var N = Console_.NextInt();
            var M = Console_.NextInt();

            var inf = 200000000000000L;

            var dist = new long[N];
            for (int i = 0; i < N; ++i)
            {
                dist[i] = i == 0 ? 0 : inf;
            }
            var paths = new List<Tuple<int, int, long>>();
            for (int i = 0; i < M; ++i)
            {
                var a = Console_.NextInt();
                var b = Console_.NextInt();
                var c = Console_.NextLong() * (-1);

                paths.Add(Tuple.Create(a - 1, b - 1, c));
            }

            for (int i = 0; i < N - 1; ++i)
            {
                foreach (var item in paths)
                {
                    var src = item.Item1;
                    var dst = item.Item2;
                    var cst = item.Item3;

                    if (dist[dst] > dist[src] + cst)
                    {
                        dist[dst] = dist[src] + cst;
                    }
                }
            }

            var neg = new bool[N];
            for (int i = 0; i < N; ++i)
            {
                foreach (var item in paths)
                {
                    var src = item.Item1;
                    var dst = item.Item2;
                    var cst = item.Item3;

                    if (dist[dst] > dist[src] + cst)
                    {
                        dist[dst] = dist[src] + cst;
                        neg[dst] = true;
                    }
                    if (neg[src])
                    {
                        neg[dst] = true;
                    }
                }
            }

            if (neg[N - 1])
            {
                Console.WriteLine("inf");
                return;
            }

            Console.WriteLine(dist[N - 1] * -1);
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
#include<vector>
#include<set>
#include<algorithm>

using namespace std;

#define T int t, q=0; scanf("%d", &t); while(q++<t)
#define ll long long
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
ll y,a,b,c=0,sum=0,ans,total,cnt,n,m,k,p,kase,i;
string s1,s2;
#define N 100001
#define MX 1000000001



int main()
{
    cin>>n>>m;
    int a[n];
    c=0,sum=0;
    for(int i=0;i<n;i++){
            cin>>a[i];
            sum+=a[i];
    }
    float z=4*m;
   float x=(1/z)*sum;
    for(int i=0;i<n;i++){
        if(a[i]>=x)c++;

    }
    if(c>=m){
            cout<<"Yes"<<endl;
        }
    else cout<<"No";



    return 0;
}
// Happy Coding  (:


Measured memory_bytes: 3588
def inp():
    return input()
def iinp():
    return int(input())
def inps():
    return input().split()
def miinps():
    return map(int,input().split())
def linps():
    return list(input().split())
def lmiinps():
    return list(map(int,input().split()))
def lmiinpsf(n):
    return [list(map(int,input().split()))for _ in range(n)]

n = iinp()
a = lmiinps()

ans = 0
count = 0

for i in range(n):
    count += (a[i]%(10**9+7))

for i in range(n):
    count -= a[i]
    ans += (a[i]%(10**9+7))*count


ans %= (10**9+7)

print(ans)

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

int main(){
  string s,t;
  cin>>s>>t;
  int count=0;
  for(int i=0;i<s.size();i++){
    if(s[i] != t[i]){
      count++;
    }
  }
  cout<<count;
  return 0;
}

Measured memory_bytes: 3776
N=int(input())
S=str(input())
ls = []
for i in range(len(S)):
    ls.append(S[i])
for i in range(len(S)):
    x = S[i]
    #print(ord(x)+N,ord("Z"))
    if ord(x)+N > ord("Z"):
        #print("if")
        #print(ord("A")-ord("Z")+(ord(x)+N))
        ls[i]=chr(ord("A")-ord("Z")+(ord(x)+N)-1)
    else:
        #print("else")
        ls[i]=chr((ord(x)+N))
print("".join(ls))


Measured memory_bytes: 67312
#include<iostream>
#include<bits/stdc++.h>
#define db(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define fr(i,a,n) for(int i=a;i<=(n);++i)
#define rf(i,a,n) for(int i=a;i>=(n);--i)
#define mod 1000000007
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll,ll>
#define _ <<" "<<
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<int,pair<int,int>> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

vvi dp;

// int words(set<string> a, int n, string s){
// 	// db2(s,n);
// 	if(n==0)
// 		if(s.length()==0)
// 			return 1;
// 		else
// 			return 0;
// 	if(dp[n][s.length()]!=-1)
// 		return dp[n][s.length()];
// 	if(a.find(s.substr(n-1))!=a.end()){
// 		dp[n][s.length()]= max(words(a,n-1,s.substr(0,n-1)),words(a,n-1,s));
// 	}
// 	else
// 		dp[n][s.length()]= words(a,n-1,s);
// 	return dp[n][s.length()];
// }

int main(){
	int t=1;
	while(t--){
		string a,b;
		cin>>a>>b;
		int n=a.length(),m=b.length();
		dp.clear();
		dp.resize(n+1,vi(m+1,0));
		// cout<<words(a,s.length(),s)<<endl;
		for(int i=0;i<=n;i++){
			for(int j=0;j<=m;j++){
				if(i==0||j==0){
					dp[i][j]=0;
					continue;
				}
				// db2(i,j);
				// db2(a[i-1],b[j-1]);
				if(a[i-1]==b[j-1]){
					dp[i][j]=1+dp[i-1][j-1];
				}
				else
					dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
		string s="";
		for(int i=n,j=m;i>0&&j>0;){
			if(a[i-1]==b[j-1]){
				s+=a[i-1];
				i--;j--;
				continue;
			}
			if(dp[i-1][j]>dp[i][j-1])
				i--;
			else
				j--;
		}
		reverse(s.begin(),s.end());
		cout<<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 70784
#include <iostream>

using namespace std;

int main()
{
    int a, b;
    
    cin>>a>>b;
    
    if(a%3==0 || b%3==0 || (a+b)%3==0)
    {
        cout<<"Possible";
    }else
    {
        cout<<"Impossible";
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int H,W;

while(1){
cin >> H >> W;
if(H==0&&W==0)break;
for(int i=1;i<=H;i++){
for(int j=1;j<=W;j++){if(i==1||i==H||j==1||j==W){cout << "#";}
else{cout << ".";}
}
cout << "\n";
}
cout << endl;
}



return 0;
}


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


int main(){
  ll n;
  cin >> n;
  if(n==0){
    cout << "0" << endl;
    return 0;
  }
  string ans="";

  while(n!=0){
    int r=n%2;
    if(r<0) r+=2;

    n=(n-r)/(-2);
    ans+=(char)('0'+r);
  }
  reverse(ans.begin(),ans.end());

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


Measured memory_bytes: 3620
h,w=map(int, input().split())
ch,cw=map(int, input().split())
ch-=1
cw-=1
dh,dw=map(int, input().split())
dh-=1
dw-=1
grid=[]
for i in range(h):
    s=list(input())
    news=[-1 if x=='#' else 0 for x in s]
    grid.append(news)
dif=[(1,0),(-1,0),(0,1),(0,-1)]
from collections import deque
col=0
for i in range(h):
    for j in range(w):
        if grid[i][j]==0:
            col+=1
            stack=deque([(i,j)])
            grid[i][j]=col
            while stack:
                nowi,nowj=stack.popleft()
                for di,dj in dif:
                    if 0<=nowi+di<h and 0<=nowj+dj<w and grid[nowi+di][nowj+dj]==0:
                        stack.append((nowi+di,nowj+dj))
                        grid[nowi+di][nowj+dj]=col
start=grid[ch][cw]-1
end=grid[dh][dw]-1
if start==end:
    print(0)
    exit()
es=[set([]) for _ in range(col)]
visited=[-1]*col

for i in range(h):
    for j in range(w):
        now=grid[i][j]
        if now!=-1: 
            for x in range(-2, 3):
                for y in range(-2, 3):
                    if 0<=i+x<h and 0<=j+y<w:
                        nex=grid[i+x][j+y]
                        if nex!=-1 and now!=nex:
                            es[now-1].add(nex-1)

stack=deque([start])
visited[start]=0
while stack:
    now=stack.popleft()
    for e in es[now]:
        if visited[e]==-1:
            visited[e]=visited[now]+1
            stack.append(e)
#print(grid)
print(visited[end])


Measured memory_bytes: 132844
#!/usr/bin/env python3
# CGL_4_B: Convex Polygon - Diameter of a Convex Polygon

from operator import itemgetter
from math import sqrt


def distance(p0, p1):
    x0, y0 = p0
    x1, y1 = p1
    return sqrt((x1-x0)**2 + (y1-y0)**2)


def cross(p0, p1, p2, p3):
    x0, y0 = p0
    x1, y1 = p1
    x2, y2 = p2
    x3, y3 = p3
    return (x1-x0) * (y3-y2) - (x3-x2) * (y1-y0)


def rotating_calipers(ps):
    ps.sort(key=itemgetter(0, 1))
    upper = []
    lower = []
    for p in ps:
        while (len(upper) > 1
               and cross(upper[-2], upper[-1], upper[-1], p) <= 0):
            upper.pop()
        while (len(lower) > 1
               and cross(lower[-2], lower[-1], lower[-1], p) >= 0):
            lower.pop()

        upper.append(p)
        lower.append(p)

    nu, nl = len(upper), len(lower)
    i, j = 0, nl-1
    dist = 0.0
    while i < nu and j >= 0:
        d = distance(upper[i], lower[j])
        if dist < d:
            dist = d

        if i == nu-1:
            j -= 1
        elif j == 0:
            i += 1
        elif cross(upper[i], upper[i+1], lower[j-1], lower[j]) > 0:
            i += 1
        else:
            j -= 1

    return dist


def run():
    n = int(input())
    ps = []

    for _ in range(n):
        x, y = [float(f) for f in input().split()]
        ps.append((x, y))

    print("{:.10f}".format(rotating_calipers(ps)))


if __name__ == '__main__':
    run()



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

int main() {
  string S;
  cin>>S;
  int N=S.length(),Ans=0;
  rep(i,N/2){if(S.at(i)!=S.at(N-i-1))Ans++;}
  cout<<Ans<<endl;
}

Measured memory_bytes: 3604
//
// Created by misclicked on 3/7/20.
//

#include <bits/stdc++.h>

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

#define ONLINE_JUDGE
#ifdef ONLINE_JUDGE
#define cerr if (false) cerr
#endif

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#else
    ios_base::sync_with_stdio(false);
    cin.tie();
#endif
    int a, b;
    cin >> a >> b;
    for (int i = 0; i < 5000; i++) {
        if (floor(i * 0.08) == a && floor(i * 0.1) == b) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

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

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

    for(int i = 0;i <= 150000;i++){
        int b = i*1.08;
        if(b == n){
            cout << i << endl;
            return 0;
        }
    }

    cout << ":(" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>

#define MAX_N 10000
#define MAX_Q 500

using namespace std;

int S[MAX_N + 5], T[MAX_Q + 5];

bool searchS(int x, int length)
{
    int place = 0;
    S[length] = x;
    while (true) {
        if (S[place] == x) {
            break;
        }
        else {
           place++;
        }
    }
    if (place < length) {
        return true;
    }
    else {
        return false;
    }
}

int main()
{
    int n, q, sum = 0;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &S[i]);
    }
    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
        scanf("%d", &T[i]);
        if (searchS(T[i], n)) {
            sum++;
        }
    }
    printf("%d\n", sum);

    return 0;
}

Measured memory_bytes: 2720
n = gets.to_i

sosu = (0..(55_555)).to_a
sosu[0] = nil
sosu[1] = nil

sosu.each do |x|
  if x != nil
    (2..((55_555 * 5) / x)).each do |i|
      sosu[x * i] = nil
    end
  end
end

sosu.compact!
sosu.select!{|x| x % 5 == 1}
puts sosu.first(n).join(' ')

Measured memory_bytes: 3964
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
	vector< vector<int> > data(1001, vector<int>(1001, 0));
	int c2 = 0;
	int dx[] = {-1, 0, 1, 0};
	int dy[] = {0, -1, 0, 1};
	int x, y;
	x = y = 1000;
	for (int i = 1001*1001; i >= 1; i--) {
		data[y][x] = i;
		if (x+dx[c2] >= 0 && x+dx[c2] < 1001 && y+dy[c2] >= 0 && y+dy[c2] < 1001 && data[y+dy[c2]][x+dx[c2]] == 0) {
			x += dx[c2];
			y += dy[c2];
		} else {
			c2++;
			if (c2 >= 4) {
				c2 = 0;
			}
			x += dx[c2];
			y += dy[c2];
		}
	}
	vector<int> furu(1000010, 0);
	furu[0] = furu[1] = 1;
	for (int i = 2; i*i <= 1000000; i++) {
		if (furu[i] == 0) {
			for (int j = 2; i*j <= 1000000; j++) {
				furu[i*j] = 1;
			}
		}
	}
	int m, n;
	while(cin >> m >> n) {
		if (m == 0 && n == 0) {
			break;
		}
		int si, sj;
		si = sj = -1;
		for (int i = 0; i < 1001; i++) {
			for (int j = 0; j < 1001; j++) {
				if (data[i][j] == n) {
					si = i;
					sj = j;
					break;
				}
			}
			if (si != -1 && sj != -1) {
				break;
			}
		}
		vector< vector<int> > d2(1001, vector<int>(1001, -1));
		vector< vector<int> > d3(1001, vector<int>(1001, -1));
		int gg = 0;
		int sososu = 0;
		if (furu[data[si][sj]] == 0) {
			gg = d2[si][sj] = 1;
			sososu = d3[si][sj] = data[si][sj];
		} else {
			gg = d2[si][sj] = 0;
			sososu = d3[si][sj] = 0;
		}
		for (int i = si+1; i < 1001; i++) {
			bool h = true;
			for (int j = 0; j < 1001; j++) {
				if (data[i][j] <= m) {
					bool hh = false;
					int ck = 0;
					int sosu = 0;
					if (j > 0) {
						if (d2[i-1][j-1] != -1) {
							if (d2[i-1][j-1] > ck) {
								ck = d2[i-1][j-1];
								sosu = d3[i-1][j-1];
								hh = true;
							} else if (d2[i-1][j-1] == ck) {
								sosu = max(sosu, d3[i-1][j-1]);
								hh = true;
							}
						}
					}
					if (d2[i-1][j] != -1) {
						if (d2[i-1][j] > ck) {
							ck = d2[i-1][j];
							sosu = d3[i-1][j];
							hh = true;
						} else if (d2[i-1][j] == ck) {
							sosu = max(sosu, d3[i-1][j]);
							hh = true;
						}
					}
					if (j < 1000) {
						if (d2[i-1][j+1] != -1) {
							if (d2[i-1][j+1] > ck) {
								ck = d2[i-1][j+1];
								sosu = d3[i-1][j+1];
								hh = true;
							} else if (d2[i-1][j+1] == ck) {
								sosu = max(sosu, d3[i-1][j+1]);
								hh = true;
							}
						}
					}
					if (furu[data[i][j]] == 0) {
						ck++;
						sosu = data[i][j];
					}
					if (!hh) {
						ck = -1;
					} else {
						h = false;
					}
					d2[i][j] = ck;
					d3[i][j] = sosu;
					if (ck > gg) {
						gg = ck;
						sososu = sosu;
					} else if (ck == gg) {
						sososu = max(sososu, sosu);
					}
				}
			}
			if (h) {
				break;
			}
		}
		cout << gg << ' ' << sososu << endl;
	}
	return 0;
}

Measured memory_bytes: 16848
s = gets.chomp
u = s[0, 2].to_i
d = s[2, 2].to_i
def maybe_month(m)
  1 <= m && m <= 12
end
result = ''
if maybe_month(u) && maybe_month(d)
  result = 'AMBIGUOUS'
elsif maybe_month(u)
  result= 'MMYY'
elsif maybe_month(d)
  result = 'YYMM'
else
  result = 'NA'
end

puts result


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
 
int main() {
  int k,a,b;
  cin>>k>>a>>b;
	for (int i = a; i <= b; i++)
    {if (i%k==0){
       cout<<"OK"<<endl;
    exit(0);}
    } 
  cout<<"NG"<<endl;
}

Measured memory_bytes: 3540
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //d
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i + 1 < n; i++) {
    if (s[i] == s[i + 1]) ans++;
  }
  vector<string> v;
  for (int i = 0; i + 1 < n; i++) {
    if (s[i] == s[i + 1]) continue;
    string t = s.substr(i, 2);
    v.push_back(t);
  }
  int lr = 0, rl = 0;
  int m = (int) v.size();
  for (int i = 0; i < (int) v.size(); i++) {
    string t = v[i];
    if (k == 0) continue;
    if (t == "RL") {
      if (lr > 0 && k) {
        ans += 2;
        lr--;
        k--;
      } else {
        rl++;
      }
    } else {
      if (rl > 0 && k) {
        ans += 2;
        rl--;
        k--;
      } else {
        lr++;
      }
    }
  }
  ans += min(lr + rl, k);
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;

int main()
{
    int n,m;
    cin >> n >> m;
    int constant = 1e9 + 7;
    if(n == m){
        ll ans = 2;
        int i;
        for(i = 1;i <= n;++i){
            ans *= i;
            ans %= constant;
        }
        for(i = 1;i <= m;++i){
            ans *= i;
            ans %= constant;
        }
        cout << ans << endl;
    }else if(n == m+1 || n == m-1){
        ll ans = 1;
        int i;
        for(i = 1;i <= n;++i){
            ans *= i;
            ans %= constant;
        }
        for(i = 1;i <= m;++i){
            ans *= i;
            ans %= constant;
        }
        cout << ans << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main(){
	int a, b; cin >> a >> b;
	if(a%3==0||b%3==0||(a+b)%3==0)
		cout << "Possible" << endl;
	else
		cout << "Impossible" << endl;
	return 0;
}

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

//安いお店から順に当たっていく
int main()
{
    long long n,m,cost;
    std::cin>>n>>m;
    cost = 0;
    std::vector<std::pair<long long,long long>> v(n);
    for(int i=0;i<n;i++){
        int a,b;
        std::cin>>a>>b;
        v[i] = {a,b};
    }
    std::sort(v.begin(),v.end());
    for(int i=0;m>0;i++){
        if(v[i].second<=m){
            m-=v[i].second;
            cost += v[i].second*v[i].first;
        }else{
            cost += m*v[i].first;
            break;
        }
    }
    std::cout<<cost<<std::endl;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main(void){
	int n,m,k;
	cin >> n;
	cin >> m;
	int deck[2][2*n+1],cur=0,nxt=1,i=1,j;

	for(;i<=2*n;i++){
		deck[cur][i] = i;
	}

	for(i=0;i<m;i++){
		cin >> k;
		if(k == 0){
			for(j=1;j<=2*n;j++){
				if(j%2==0){
					deck[nxt][j] = deck[cur][n+j/2];
				}else{
					deck[nxt][j] = deck[cur][j/2+1];
				}
			}
		}else{
			for(j=0;j<k;j++){
				deck[nxt][2*n-k+1+j] = deck[cur][j+1];
			}
			for(j=0;j<2*n-k;j++){
				deck[nxt][j+1] = deck[cur][k+1+j];
			}
		}
		cur = 1 - cur;
		nxt = 1 - nxt;
	}
	for(int i=1;i<=2*n;i++){
		cout << deck[cur][i] << endl;
	}

}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl '\n'

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;cin>>n;
	map<ll, ll> mp;
	ll sm = 0;
	for(int i = 0; i < n; ++i){
		int x;cin>>x;
		sm += x;
		mp[x]++;
	}
	int q;cin>>q;
	while(q--){
		int a, b;cin>>a>>b;
		sm += (b-a)*mp[a];
		mp[b] += mp[a];
		mp.erase(a);
		cout<<sm<<endl;
	}
	return 0;
}




Measured memory_bytes: 7472
import java.util.*;
public class Main {
	public static void main(String[] args){
       Scanner sc = new Scanner(System.in);
      
      // 取得
	  int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      int d = sc.nextInt();
      
      if(Math.abs(c-a)<=d || (Math.abs(b-a)<=d && Math.abs(c-b)<=d)){
        System.out.println("Yes");
      }else{
        System.out.println("No");
      }
    }
}

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

int main(void)
{
    int n;
    cin >> n;
    switch (n)
    {
        case 1:
            cout << "Hello World" << endl;
            break;
        case 2:
            int a, b;
            cin >> a >> b;
            cout << a + b << endl;
            break;
        default:
            break;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int k;
  cin>>k;
  string s;
  cin>>s;
  if(s.size()<=k){
    cout<<s<<endl;
  }
  else{
    for(int i=0;i<k;i++){
      cout<<s.at(i);
    }
    cout<<"..."<<endl;
  }

}


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

#define INF 100000000
int n;
int Graph[100][100] = {};

int color[100] = {}, d[100];

void bfs(int x){
  int u;
  queue<int> Q; //queueを生成
  Q.push(x); //始点をキューに積む
  for(int i = 0 ; i < n ; i++){
    d[i] = INF;
  }

  d[x] = 0; //始点を0にする
  
  while(!Q.empty()){
    u = Q.front(); //取り出して削除
    Q.pop();
    for(int v = 0 ; v < n ; v++){
      if(Graph[u][v] == 0) continue;
      if(d[v] != INF) continue;
      d[v] = d[u] + 1;
      Q.push(v); //次点を積む
    }
  }

  for(int i = 0 ; i < n ; i++){
    cout << i + 1 << " ";
    if(d[i] == INF){
      cout << -1 <<endl;
    }else{
      cout << d[i] << endl;
    }
  }
}


int main(){
  int u, k, v; //u = 頂点番号 k = 出次数 v = u に隣接する頂点番号

  cin >> n;
     
  for(int i = 0 ; i < n ; i++){
    cin >> u >> k; 
    u--;
    for(int j = 0 ; j < k ; j++){
      cin >> v; 
      v--;
      Graph[u][v] = 1;
    }
  }

  bfs(0);
     
  return 0;
}

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

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

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

#define INF 1e16
#define mod 1000000007

map<ll,ll> prime_factor(ll n){
  map<ll,ll> res;
  for(ll i=2;i*i<=n;i++){
    while(n%i==0){
      res[i]++;
      n/=i;
    }
  }
  if(n!=1)res[n]=1;
  return res;
}

ll n;
ll a[100010];
bool isprime[100010];
vector<ll> cs;

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

  cin>>n;
  rep(i,n+1){
    cin>>a[i];
  }

  ll m=abs(a[0]);
  map<ll,ll> ps=prime_factor(m);
  for(P p : ps)cs.push_back(p.fi);

  rep(i,n+2)isprime[i]=true;
  for(ll i=2;i<=n+1;i++){
    if(!isprime[i])continue;
    cs.push_back(i);
    for(ll j=i*2;j<=n+1;j+=i)isprime[j]=false;
  }

  sort(all(cs)); uni(cs);

  rep(i,cs.size()){
    if((ll)abs(a[n])%cs[i]!=0)continue;

    vector<ll> b(min(cs[i]-1,n+1),0);
    rep(j,n+1){
      (b[j%(cs[i]-1)]+=a[j])%=cs[i];
    }
    bool ok=true;
    rep(j,min(n+1,cs[i]-1))if(b[j]!=0)ok=false;
    if(ok)cout<<cs[i]<<endl;
  }

  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
long long a[200005]={0};
long long b[200005]={0};
int main() 
{
    long long x,i,j,k,sum=0,max=0;
    scanf("%lld%lld",&x,&k);
    for(i=0;i<k;i++)
    {
    	scanf("%lld",&a[i]);
	}
     for(i=0;i<k-1;i++)
	 {
	 	b[i]=a[i+1]-a[i];
   	} 
   	b[k-1]=x-(a[k-1]-a[0]);
	 for(i=0;i<k;i++)
	  {
		if(max<b[i])
		   max=b[i];
	 } 
	 for(i=0;i<k;i++)
	 {
	 	sum=sum+b[i];
	 }
    
	sum=sum-max;
	printf("%lld",sum); 
    return 0;
}








Measured memory_bytes: 3328
# -*- coding: utf-8 -*-
# 整数の入力
a = int(input())
# 整数の入力
b = int(input())
# 整数の入力
h = int(input())
# スペース区切りの整数の入力

# 出力
print("{:.0f}".format((a+b)*h/2))


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

int main(){
    int n;
    while(cin >> n, n){
        set<int> s[n];
        for(int i = 0; i < n; i++){
            int m, p;
            cin >> m;
            while(m-- > 0){
                cin >> p;
                s[i].insert(p);
            }
        }

        int k;
        cin >> k;
        int l[k];
        for(int i = 0; i < k; i++)  cin >> l[i];

        int ans = -1;
        for(int i = 0; i < n; i++){
            int cnt = 0;
            for(int j = 0; j < k; j++)  cnt += s[i].count(l[j]);
            if(cnt == k){
                if(ans != -1){
                    ans = -1;
                    break;
                }
                ans = i+1;
            }
        }

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


Measured memory_bytes: 3532
#include<bits//stdc++.h>
using namespace std;
int n,x,y,b,p,A,B;
int main(){
  cin>>n;
  while(n--){
    cin>>x>>y>>b>>p;
    A=(max(5,b)*x+max(2,p)*y)*4/5;B=b*x+p*y;
    cout<<min(A,B)<<endl;
  }
}


Measured memory_bytes: 3128
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>

using namespace std;

int main(){

    string S;

    cin >> S;

    S = S.substr(0,S.length() - 1);

    if(S.length()%2 == 1){
    	S = S.substr(0,S.length() - 1);
    }

    while(S.substr(0,S.length()/2) != S.substr(S.length()/2,S.length()/2)){
    	S = S.substr(0,S.length() - 2);
    }

    cout << S.length() << endl;

    return 0;

}


Measured memory_bytes: 256
l = []
a, b, c, d = map(int, input().split())

n2 = a * c
n3 = a * d
n4 = b * c
n5 = b * d

l.append(n2)
l.append(n3)
l.append(n4)
l.append(n5)

print(max(l))


Measured memory_bytes: 9192
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<vector>
#include<tuple>
using namespace std;
int main() {
	
	char x, y, z;
	cin >> x >> y >> z;
		
	if (x == y && y == z) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	return 0;

}

Measured memory_bytes: 256
#define _CRT_NONSTDC_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <numeric>
#include <vector>

using namespace std;
using ll = long long;
const int INTMAX = numeric_limits<int>::max();
const int INTMIN = numeric_limits<int>::min();
const ll LLMAX = numeric_limits<long long>::max();
const ll LLMIN = numeric_limits<long long>::min();
const int MOD = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

signed main() {
	ll l, r;
	int min = 10000;
	cin >> l >> r;
	if (r - l >= 2019) min = 0;
	else {
		for (ll i = l; i <= r - 1; i++) {
			for (ll j = i + 1; j <= r; j++) {
				int t = i * j % 2019;
				if (t < min) min = t;
			}
		}
	}

	cout << min << endl;


	return 0;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <ctime>
#include<complex>
#include<unordered_set>
using namespace std;

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

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

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

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

const int MAX = 4 * 1000 * 1000 + 47;
const int MOD = 998244353;

map<string, int> M;

void ADD(int& key, int val)
{
	key += val;
	if (key >= MOD) key -= MOD;
}

int f(const string& s)
{
	//cout << "!!" << s << endl;
	if (SZ(s) == 0) return 1;
	if (SZ(s) == 1)
	{
		if (s[0] == '1') return 2;
		return 1;
	}

	if (M.find(s) != M.end()) return M[s];

	int res = 0;
	int tmp = f(s.substr(1, SZ(s)));
	ADD(res, tmp);
	if (s[0] == '1') ADD(res, tmp);

	FOR(len, 1, SZ(s))
	{
		string cur = s.substr(0, len);

		FOR(k, 0, SZ(s) / len - 1)
		{
			FOR(i, 0, len)
			{
				cur[i] = ((cur[i] - '0') & (s[len * (k + 1) + i] - '0')) + '0';
			}

			int tmp = (f(cur) * (LL)f(s.substr(len * (k + 2), SZ(s)))) % MOD;
			ADD(res, tmp);
		}
	}

	return M[s] = res;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	//ios::sync_with_stdio(false); cin.tie(0);
	string s;
	cin >> s;
	cout << f(s) << endl;
	//for (auto i = M.begin(); i != M.end(); i++)
	//{
	//	cout << i->first << ": " << i->second << endl;
	//}
}

Measured memory_bytes: 4224
from fractions import gcd

n = int(input())
a = list(map(int, input().split()))
left = a[:]
right = a[:]
for i in range(1, n):
  left[i] = gcd(left[i], left[i-1])
  right[n-i-1] = gcd(right[n-i], right[n-i-1])
maximum = max(left[n-2], right[1])
for i in range(n-2):
  common_divisor = gcd(left[i], right[i+2])
  if common_divisor > maximum:
    maximum = common_divisor
print(maximum)

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

int main()
{
  string s;
  cin >> s;
  int cnt[2] = {0, 0};
  int color[2] = {0, 1};
  string colors = "01";
  for (int i = 0; i < s.length(); i++) {
	for (int j = 0; j < 2; j++) {
	  if (s[i] != colors[color[j]]) {
        cnt[j]++;
      }
      color[j] = (color[j] + 1) % 2;
    }
  }
  cout << min(cnt[0], cnt[1]) << endl;
  return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  string s;
  long long P = 1000000007;
  cin >> s;
  int d;
  cin >> d;
  if (s == "0") {
    cout << 0 << endl;
    return 0;
  }
  int n = s.size();
  long long dp[n + 1][d][10], sdp[n + 1][d];
  for (int i = 0; i < d; i++)
    for (int j = 0; j < 10; j++)
      for (int k = 0; k <= n; k++)
        dp[k][i][j] = 0;
  dp[0][0][0] = 1;

  for (int i = 0; i < d; i++)
    sdp[0][i] = 0;
  sdp[0][0] = 1;
  reverse(s.begin(), s.end());
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++) {
      for (int k = 0; k < 10; k++) {
        dp[i + 1][j][k] = 0;
        for (int l = 0; l < 10; l++) {
          dp[i + 1][j][k] += dp[i][((j - k) % d + d) % d][l];
          dp[i + 1][j][k] %= P;
        }
      }
      sdp[i + 1][j] = sdp[i][((j - (s[i] - '0')) % d + d) % d];
      for (int k = 0; i > 0 && k < s[i - 1] - '0'; k++) {
        sdp[i + 1][j] += dp[i][((j - (s[i] - '0')) % d + d) % d][k];
        sdp[i + 1][j] %= P;
      }
    }
  }
  long long ans = sdp[n][0];

  for (int i = 0; i < n; i++) {
    if (i == n - 1) {
      for (int j = 1; j < s[i] - '0'; j++) {
        ans += dp[i + 1][0][j];
        ans %= P;
      }
    } else {
      for (int j = 1; j < 10; j++) {
        ans += dp[i + 1][0][j];
        ans %= P;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 86272
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <limits>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <complex>

using namespace std;

//define
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define dump(x)  cerr << #x << " = " << (x) << endl;

#define INF (INT_MAX/3)
#define PI (2*acos(0.0))
#define EPS (1e-8)

typedef long long ll;
typedef unsigned long long ull;

int main(){
  ios_base::sync_with_stdio(0);
  int a, b;
  int cnt = 0;
  while(cin >> a >> b, a || b){
    if(cnt) cout << endl;
    bool exist = false;
    for(int i = a; i <= b; i++){
      if(i % 400 == 0) { exist = true; cout << i << endl; }
      else if(i % 4 == 0 && i % 100 != 0) { exist = true; cout << i << endl; }
    }
    if(!exist) cout << "NA" << endl;
    cnt++;
  }
  return 0;
}

Measured memory_bytes: 1192
input = gets.split

int1 = ''
int2 = ''
for i in 1..input[1].to_i do
  int1 += input[0]
end

for i in 1..input[0].to_i do
  int2 += input[1]
end

arr = []
arr.push(int1, int2)

arr = arr.sort
print arr[0].to_i

Measured memory_bytes: 1788
#include<iostream>
#include<math.h>

using namespace std;

int main(){

	int a,b;
	scanf("%d %d",&a,&b);
	//cin>>a>>b;

	int x,y,z;

	x=a+b;
	y=a-b;
	z=a*b;

	if(x>y){
		if(x>z)printf("%d",x);
		else printf("%d",z);
	}else{
		if(y>z)printf("%d",y);
		else printf("%d",z);
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int H = sc.nextInt();
			int W = sc.nextInt();
			if (H == 0 && W == 0){
				break ;
		}
		for (int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				System.out.printf("#");
			}
			System.out.printf("\n");
		}
		System.out.printf("\n");
 		}
	}
}


Measured memory_bytes: 63292
Module Module1

    Sub Main()

        Dim tmp As String() = Split(Console.ReadLine())
        Dim A As Integer = CInt(tmp(0))
        Dim B As Integer = CInt(tmp(1))
        Dim ans As Integer = 0

        If 1 <= A AndAlso A <= 9 AndAlso 1 <= B AndAlso B <= 9 Then
            ans = A * B
        Else
            ans = -1
        End If

        Console.WriteLine(ans)
        'Console.Read()

    End Sub

End Module


Measured memory_bytes: 13532
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
    string S; long long K;
    cin >> S >> K;
    int N = S.size();
    vector<vector<int> > g(26);
    for(int i = N - 1; i >= 0; --i) {
        g[S[i] - 'a'].push_back(i);
    }
    vector<int> bit(N + 1);
    function<void(int, int)> add = [&](int pos, int x) {
        for(int i = pos + 1; i <= N; i += i & (-i)) {
            bit[i] += x;
        }
    };
    function<int(int)> sum = [&](int r) {
        int ans = 0;
        for(int i = r; i >= 1; i -= i & (-i)) {
            ans += bit[i];
        }
        return ans;
    };
    for(int i = 0; i < N; ++i) {
        add(i, 1);
    }
    string str;
    while(true) {
        bool selected = false;
        for(int i = 0; i < 26; ++i) {
            if(g[i].empty()) continue;
            int u = sum(g[i].back());
            if(K >= u) {
                K -= u;
                selected = true;
                str += 'a' + i;
                add(g[i].back(), -1);
                g[i].pop_back();
                break;
            }
        }
        if(!selected) break;
    }
    cout << str << endl;
    return 0;
}


Measured memory_bytes: 5032
from collections import Counter
def main():
    n = int(input())
    s = []
    for _ in range(n):
        s.append(input())
    m = int(input())
    t = []
    for _ in range(m):
        t.append(input())

    sc = Counter(s)
    tc = Counter(t)
    r = 0
    for sce in sc:
        r = max(r, sc[sce] - tc[sce])

    print(r)


if __name__ == '__main__':
    main()


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

const int lim = 10e5 + 5;
const int INF = 10e9 + 5;

void minSelf(int &a, int b) {
	a = min(a,b);
	return;
}

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

	int h[lim];
	int dp[lim]={0};

	for (i=0;i<n;i++) {
		cin>>h[i];
		dp[i] = INF;
	}

	dp[0]=0;

	for (i=0;i<n;i++) {
		if (i+1<n) minSelf(dp[i+1], dp[i]+abs(h[i+1]-h[i]));
		if (i+2<n) minSelf(dp[i+2], dp[i]+abs(h[i+2]-h[i]));

	}
	cout<<dp[n-1]<<"\n";

	return 0;
}

Measured memory_bytes: 8064
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
//#define mp make_pair
#define pb push_back
#define int long long
#define pi 3.141592653589793238462643383279502
#define M 998244353
#define F first
#define S second
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
bool isPowerOfTwo(int n)
{
   if(n==0)
   return false;

   return (ceil(log2(n)) == floor(log2(n)));
}
int power(int x, unsigned int y)
{
    int res = 1;

    x = x;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x);

        y = y>>1;
        x = (x*x);
    }
    return res;
}
bool isprime(int x)
{
      if(x<2)
        return false;
    for(int i=2;i*i<=x;i++)
     {
        if (x%i==0)
            return false;
    }
    return true;
}
vector<int>primeFactors(int n)
{
    vector<int>v;
    while (n % 2 == 0)
    {
        v.pb(2);
        n = n/2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            v.pb(i);
            n = n/i;
        }
    }
    if (n > 2)
        v.pb(n);
    return v;
}

void solve()
{
string s,t;
cin>>s>>t;
for(int i=0;i<s.size();i++)
{
    if(s[i]!=t[i])
    {
        cout<<"No"<<endl;
        return ;
    }
}
cout<<"Yes"<<endl;
return ;
}
signed main()
{ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t;
//cin>>t;
t=1;
while(t--)
{
solve();
}
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define mxn 1000010
#define LL long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair<int,int> 
#define mp make_pair
#define fr first
#define sc second
#define node(a,b,c) (node){a,b,c}
using namespace std;
const int inf=1e9,mod=1e9+7;
int n,K,sl,fh,ans,a[mxn];
int t,h[mxn];
struct Tre
{
	int to,nxt;
}e[mxn<<1];
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
void add(int u,int v)
{
	e[++t]=(Tre){v,h[u]};h[u]=t;
	e[++t]=(Tre){u,h[v]};h[v]=t;
}
void dfs(int u,int f)
{
	int v;
	for(int j=2,i=h[u];i;i=e[i].nxt)
		if((v=e[i].to)!=f)
		{
			a[v]=K-j;++j;
			dfs(v,u);
		}
}
int main()
{
	n=rd();K=rd();int x,y;a[1]=K;ans=1;
	for(int i=1;i<n;++i) x=rd(),y=rd(),add(x,y);
	for(int j=1,i=h[1];i;++j,i=e[i].nxt) a[e[i].to]=K-j,dfs(e[i].to,1);
	for(int i=1;i<=n;++i) ans=1ll*ans*a[i]%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 9472
#pragma GCC optimize("Ofast")
#pragma GCC target ("avx")
#include <bits/stdc++.h>

constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int H, W;
	cin >> H >> W;
	vector<pair<int, int>> b;
	for (int i = 0; i < H; i++)for (int j = 0; j < W; j++) {
		char tmp;
		cin >> tmp;
		if (tmp == 'B')b.emplace_back(pair<int, int>{i, j});
	}
	int ans = -1;
	for (int i = 0; i < b.size(); i++)for (int j = 0; j < b.size(); j++) {
		ans = max(ans, abs(b[i].first - b[j].first) + abs(b[i].second - b[j].second));
	}
	cout << ans << endl;


}


Measured memory_bytes: 3116
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[][] data = new int[N+1][N+1];
		int[][] edge = new int[M][2];
		for(int i = 0 ; i<M; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			data[l][r] = 1;
			data[r][l] = 1;
			edge[i][0] = l;
			edge[i][1] = r;
		}
		int res = 0;
		for(int i = 0; i<M; i++) {
			int[][] clone = new int[N+1][N+1];
			for(int cr = 1; cr<=N; cr++) {
				for(int cc = 1; cc<=N; cc++) {
					clone[cr][cc] = data[cr][cc];
				}
			}
	//		int[][] test = Arrays.copyOf(data, N*M);
			int l = edge[i][0];
			int r = edge[i][1];
			clone[l][r] = 0;
			clone[r][l] = 0;
	/*		for(int t = 1; t<=N; t++) {
				System.out.println(Arrays.toString(clone[t]));
			}*/
			Set visited = new TreeSet();
			Queue wait = new LinkedList();
			wait.add(1);
			visited.add(1);
			while(!wait.isEmpty()) {
				int row = (int)wait.poll();
				for(int j = 1; j<=N; j++) {
					if(clone[row][j] == 1) {
						if(!visited.contains(j)) {
							visited.add(j);
							wait.add(j);
						}
					}
				}
			}
		//	System.out.print("size = "+visited.size());
			if(visited.size()<N) {
				res++;
		//		System.out.println("  true");
			}
	/*		else {
				System.out.println("   l "+ l +" r "+r+" false");
			}*/
		}
		System.out.println(res);
	}
}


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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

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

  reverse(S.begin(),S.end());
  for(int i = 0;i < 4;i++)reverse(divide[i].begin(),divide[i].end());

   bool can = true;
    for (int i = 0; i < S.size();) {
      bool can2 = false;
      for (int j = 0; j < 4; ++j) {
        string d = divide[j];
        if(S.substr(i,d.size()) == d){
          can2 = true;
          i += d.size();
        }
      }
      if(!can2){
        can = false;
        break;
      }
    }
    
    if (can) cout << "YES" << endl;
    else cout << "NO" << endl;
    
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

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);
}

ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

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

    ll a,b; cin >> a >> b;


    std::vector<ll> a_div = divisor(a);
    std::vector<ll> b_div = divisor(b);

    //rep(i,a_div.size()) cout << a_div[i] << " ";

    std::vector<ll> v;

    rep(i,a_div.size()){
        if(binary_search(b_div.begin(), b_div.end(), a_div[i])){
            v.push_back(a_div[i]);
            //cout << a_div[i] << " ";
        }
    }
    //cout << '\n';

    std::vector<bool> used(v.size(), false);

    int cnt = 0;

    rep(i,v.size()){

        if(used[i]) continue;
        if(v[i]==1) continue;

        for(int j=i+1; j<v.size(); j++){
            if(v[j]%v[i]==0 && !used[j]){
                used[j] = true;
                //cout << v[i] << " " << v[j] << endl;
            }
        }
    }

    rep(i,used.size()) if(!used[i]) cnt++;

    cout << cnt << endl;

    return 0;
}

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

typedef long long int64;
const int MAX = 2e6 + 5;
const int MOD = 1e9 + 7;
int r1, c1, r2, c2;
int64 f[MAX], inv[MAX];

int64 exp(int64 a, int64 n) {
	int64 ans = 1;
	while(n > 0) {
		if(n % 2LL == 1LL)
			ans = ans * a % MOD;
			
		a = a * a % MOD;
		n /= 2LL;
	}
	
	return ans;
}

int64 comb(int n, int k) {
	return f[n] * inv[k] % MOD * inv[n - k] % MOD;
}

int64 s(int x, int y) {
	int64 ans = 0;
	for(int i = 1; i <= y + 1; i++)
		ans = (ans + comb(i + x, x)) % MOD;

	return ans;
}

int main() {
	scanf("%d%d%d%d", &r1, &c1, &r2, &c2);

	f[0] = inv[0] = 1;
	for(int i = 1; i <= (int) 2e6 + 4; i++) {
		f[i] = 1LL * f[i - 1] * i % MOD;
		inv[i] = exp(f[i], MOD - 2);
	}

	int64 ans = (s(r2, c2) - s(r2, c1 - 1) + MOD) % MOD;
	ans = (ans - s(r1 - 1, c2) + MOD) % MOD;
	ans = (ans + s(r1 - 1, c1 - 1)) % MOD;

	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 31488
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
#include<numeric>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

#define rep(i,n) for (int i = 0; i < (n); ++i)

ll yakusu(ll n)
{
  ll ret = 0;

  for (ll i = 1; i * i <= n; i++) { // ルートnまで試す。i <= sqrt(n) だと、右辺が少数になってメンドイ
    if (n % i == 0) {
      ret++;
      if (n / i != i) { // ルートnが約数の時は、2つpush_backしないように注意
        ret++;
      }
    }
  }
  return ret;
}

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

  ll res = 0;

  vector<ll> u(n+5, 0);

  for (int i = n-1; i >= 1; i--) {
    for (int j = i; j < n; j += i) {
      u[i]++;
    }
  }
  rep(i, n) {
    res += u[i];
  }
  cout << res << endl;
}


Measured memory_bytes: 11096
// A - Odds of Oddness
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	int n;
	cin >> n;
	double a = n / 2 + n % 2;
	double ans = a / n;
	cout << fixed << setprecision(15) << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int x,a,b;
    cin>>x>>a>>b;
    a=x-a;
    a=abs(a);
    b=x-b;
    b=abs(b);
    if(a>b)
        cout<<"B";
    else
        cout<<"A";
    return 0;
}


Measured memory_bytes: 3544