akhauriyash/Code-Regression huggingface dataset:
def gcd(a,b):
  while b > 0:
    a, b = b, a % b
  return a

n = int(input())
arr = list(map(int , input().split()))
lcm = arr[0]
for i in range(1,n):
  hcf = gcd(lcm, arr[i])
  lcm = (lcm*arr[i])//hcf
sum =0
for i in range(0,n):
  sum = sum +(lcm//arr[i])
sum =sum%1000000007
print(int(sum))
  


Measured memory_bytes: 4084
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        string[] cin = Console.ReadLine().Split();
        int n = int.Parse(cin[0]);
        int m = int.Parse(cin[1]);

        long[] a = new long[n];
        int[] b = new int[n];

        for (int i = 0; i < n; i++)
        {
            cin = Console.ReadLine().Split();
            a[i] = long.Parse(cin[0]);
            b[i] = int.Parse(cin[1]);
        }

        Array.Sort(a, b);

        long ans = 0;
        for (int i = 0; i < n; i++)
        {
            ans += Math.Min(m, b[i]) * a[i];
            m -= Math.Min(m, b[i]);
            if (m == 0) break;
        }

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 17432
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44

/*
const int MOD = ;

inline void mod(int &x) {
    if(x >= MOD)
        x -= MOD;
}

inline void add(int &x, int y) {
    x += y;
    mod(x);
}

inline void sub(int &x, int y) {
    x += MOD - y;
    mod(x);
}


inline void mul(int &x, int y) {
    x = (1LL * x * y) % MOD;
}
*/

using namespace std;



int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n;

    vector <int> arr(n + 1);
    for(i = 1; i <= n; i++) {
        cin >> arr[i];
    }

    int ans = 0;
    for(i = 2; i < n; i++) {
        if(arr[i] > min(arr[i - 1], arr[i + 1]) && max(arr[i - 1], arr[i + 1]) > arr[i]) {
            ans++;
        }
    }

    cout << ans;

    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 892
A,B,C,D,E,F = map(int,input().split())

dp = [[False]*(F-100*i+1) for i in range(F//100+1)]
dp[0][0] = True
dp[A][0] = True

for i in range(A,F//100+1):
    for j in range(C,F-100*i+1):
        if i < B and j < D:
            if (dp[i-A][j] or dp[i][j-C]) and j<=i*E:
                dp[i][j] = True
        elif i >= B and j < D:
            if (dp[i-A][j] or dp[i-B][j] or dp[i][j-C]) and j<=i*E:
                dp[i][j] = True
        elif i < B and j >= D:
            if (dp[i-A][j] or dp[i][j-C] or dp[i][j-D]) and j<=i*E:
                dp[i][j] = True
        else:
            if (dp[i-A][j] or dp[i-B][j] or dp[i][j-C] or dp[i][j-D]) and j<=i*E:
                dp[i][j] = True

#print(dp)
#print(dp[5])
#print(dp[5][500])

mi = A
mj = 0
for i in range(F//100+1):
    for j in range(F-100*i+1):
        if dp[i][j] and (j*(100*mi+mj) > mj*(100*i+j)):
            mi = i
            mj = j
            #print(mi,mj)
print(100*mi+mj,mj)


Measured memory_bytes: 41840
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
const ll INF=100000000000000001;
const double PI=3.141592653589;


int main(){
  int r,d,x; cin>>r>>d>>x;
  ll a=x;
  rep(i,10){
    a=r*a-d;
    cout<<a<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
n = int(input())
v = list(map(int,input().split()))
dict1 = {0:0}
dict2 = {0:0}
ans = 0
for i in v[::2]:
    if i not in dict1:
        dict1[i] = 1
    else:
        dict1[i] += 1
for i in v[1::2]:
    if i not in dict2:
        dict2[i] = 1
    else:
        dict2[i] += 1
lisa = sorted(dict1.items(),key=lambda x: x[1],reverse=1)
lisb = sorted(dict2.items(),key=lambda x: x[1],reverse=1)
if lisa[0][0] != lisb[0][0]:
    ans = n-lisa[0][1]-lisb[0][1]
else:
    ans = n-max(lisa[0][1]+lisb[1][1],lisa[1][1]+lisb[0][1])
print(ans)

Measured memory_bytes: 20732
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0){
				break;
			}
			int[][] students = new int[n][n];
			boolean[][] tallest = new boolean[n][n];
			boolean[][] shortest = new boolean[n][n];
			int[][] x = new int[n][n];
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					students[i][j] = sc.nextInt();
				}
			}
			
			for(int i = 0; i < n; i++){
				int columnMax = -1, maxj = -1;
				for(int j = 0; j < n; j++){
					if(columnMax < students[j][i]){
						columnMax = students[j][i];
                        maxj = j;
                    }
				}
/*				if(columnMax == students[maxj][i]){
					tallest[maxj][i] = true;
					x[maxj][i] |= 2;
				}
*/				for(int j = 0; j < n; j++){
					if(columnMax == students[j][i]){
						tallest[j][i] = true;
						x[j][i] |= 2;
					}
				}
			}
			for(int i = 0; i < n; i++){
				int rowMin = Integer.MAX_VALUE, minj = -1;
				for(int j = 0; j < n; j++){
					if(rowMin > students[i][j]){
						rowMin = students[i][j];
                        minj = j;
                    }
				}
/*				if(rowMin == students[i][minj]){
					shortest[i][minj] = true;
					x[i][minj] |= 1;
				}
*/				for(int j = 0; j < n; j++){
					if(rowMin == students[i][j]){
						shortest[i][j] = true;
						x[i][j] |= 1;
					}
				}
			}
			
			Set<Integer> both = new HashSet<Integer>();
            for(int i = 0;i < n;i++){
                for(int j = 0;j < n;j++){
                    if(x[i][j] == 3){
                        both.add(students[i][j]);
                    }
                }
            }
			
            if(both.size() == 1){
            	StringBuilder sb = new StringBuilder();
                for(int v : both){
                    sb.append(v + " ");
                }
                sb.deleteCharAt(sb.length() - 1);
                System.out.println(sb);
            }else{
            	System.out.println(0);
            }
/*			boolean noAns = true;
			StringBuilder sb = new StringBuilder();
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					if(shortest[i][j] && tallest[i][j]){
						sb.append(students[i][j] + " ");
						noAns = false;
					}
				}
			}
			
			if(noAns){
				System.out.println(0);
			}else{
				sb.deleteCharAt(sb.length() - 1);
				System.out.print(sb);
			}
*/		}
		
	}
}

Measured memory_bytes: 19432
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)

using namespace std;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

ll solve(ll h, ll w) {
  ll mn = h*w;
  FOR(i,1,h) {
    ll h1 = i;
    ll s1 = h1*w;
    ll hr = h-i;
    ll w2 = w/2;
    ll s2 = hr*w2;
    ll w3 = w-w2;
    ll s3 = hr*w3;
    mn = min(mn, max({s1, s2, s3}) - min({s1, s2, s3}));
  }
  return mn;
}

int main()
{
  ll h,w;
  cin>>h>>w;
  if (h%3 == 0 || w%3 == 0) {
    cout << 0 << endl;
    return 0;
  }
  cout << min({solve(h,w),solve(w,h),h,w}) << endl;
  return 0;
}


Measured memory_bytes: 256
/*
      author : nishi5451
      created: 11.08.2020 22:34:37
*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;


int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b+c >= 22) cout << "bust" << endl;
    else cout << "win" << endl;
    return 0;
}

Measured memory_bytes: 3616
#include<iostream>
//#include<vector>

int main(){
    int n,b,f,r,v;
    int mem[4][3][10]={{},{},{}};    
    std::cin>>n;

    for(int i=0; i<n;i++){
        std::cin>>b>>f>>r>>v;
        mem[b-1][f-1][r-1]+=v;
    }
    
    for(int i=0; i<4; i++){
        for(int j=0; j<3;j++){
            for(int k=0; k<10; k++){
                 std::cout<<" "<<mem[i][j][k];
            }
            std::cout<<std::endl;
        }
        if(i!=3){
        std::cout<<"####################"<<std::endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3096
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readString = map BS.unpack . BS.words

getString = readString <$> BS.getLine

calc :: String -> [Int]
calc s | length s >= 3 = abs ((read (take 3 s) :: Int) - 753) : calc (tail s)
       | otherwise = []

main = do
  [s] <- getString
  print $ minimum (calc s)


Measured memory_bytes: 508
#include<stdio.h>
int gcd(int a, int b)
{
	int r = a % b;
	while (r > 0)
	{
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if (a % b == 0 && c > 0)
		printf("NO\n");
	else if (c % gcd(b, a % b) != 0)
		printf("NO\n");
	else
		printf("YES\n");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
//#define attrib +h /s /d
using namespace std;
int main(){

   long long  int n,a,b,c,d,e,i,t=0;
   set<int> s;
   cin>>a;
   for(i=0;i<2000;i++){
    for(int j=0;j<2000;j++){
        if((pow(i,5)+pow(j,5))==a){
            cout<<i<<" "<<-j<<endl;
            t++;
            break;
        }
        if(pow(i,5)-pow(j,5)==a){
             cout<<i<<" "<<j<<endl;
             t++;
             break;
        }
    }
    if(t>0){
        break;
    }
   }



   return 0;
}


Measured memory_bytes: 4184
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
const int64_t INF=9999999999999999;

int main() {
 int N;
 cin>>N;
 char S;
 while(cin>>S){
   if(S=='Y'){cout<<"Four"<<endl;return 0;}
 }
 cout<<"Three"<<endl;
 return 0;}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long X = sc.nextLong();
    long G = X/500;
    long r = X%500;
    long S = r/5;
    System.out.println(G*1000+S*5);
  }
  

  
}

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

typedef long long ll;

main()
{
    int n, c = 0;
    cin >> n;
    int arr[n];
    vector<int> v = {0};
    for(int i = 0; i < n; i++){
        cin >> arr[i];
        if(i >= 1){
            if(arr[i-1] >= arr[i]){
                c++;
                v.push_back(c);
            }
            else{
                c = 0;
            }
        }
    }
    cout << *max_element(v.begin(), v.end()) << endl;


}





///promy_pompom
//hello world


Measured memory_bytes: 4064
//Tonight's the night and it is going to happen again and again.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define endl "\n"
int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
   #endif
 string s,t;
 cin>>s>>t;
 int n=s.length();int m=t.length();
 int lcsarr[n+1][m+1];string s1;
 memset(lcsarr,0,sizeof(lcsarr));
 for(int i=1;i<n+1;i++)
 {
 	for(int j=1;j<m+1;j++)
 	{
 		if(s[i-1]==t[j-1])
 		{
 			lcsarr[i][j]=1+lcsarr[i-1][j-1];
 		}
 		else
 		{
 			lcsarr[i][j]=max(lcsarr[i-1][j],lcsarr[i][j-1]);
 		}
 	}
 }
 while(m>0&&n>0)
 {
 	if(s[n-1]==t[m-1])
 	{
 		s1+=s[n-1];
 		m--;n--;
 	}
 	else if(lcsarr[n-1][m]>lcsarr[n][m-1])
 	{
 		n--;
 	}
    else{m--;}
 }
 reverse(s1.begin(),s1.end());
 cout<<s1;
}

Measured memory_bytes: 38764
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

#define v(type) vector<type>
#define p(type1, type2) pair<type1 , type2>
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    int k , n;
    cin>>k>>n;
    int a[n];
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
    }
    sort(a , a + n);
    if(k == 1)
        cout<<0<<endl;
    else if(n == 1){
        cout<<a[0]-1<<endl;
    }else {
        int s1 = 0;
        for(int i = 0 ; i< n -1 ; i++){
            s1 += a[i];
        }
        int s2 = a[n-1];
        if(s2 > s1){
            if(s2 - s1 < 2){
                cout<<0<<endl;
            }else{
                cout<<s2 - s1 - 1 <<endl;
            }
        }else {
            cout<<0<<endl;
        }
    }


}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%lld",&x);
int main(){
    string s; cin >> s;
    ll k, cnt = 0, ans; sc(k)
    for (int i = 0; i < s.size(); i++){
        if (s[i] == '1') cnt++;
        else{
            ans = i;
            break;
        }
    }
    if (k <= cnt) cout << '1' << endl;
    else cout << s[ans] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;
 
int main(){
int a,b,sum,count=0;
 
while(cin >> a >> b){
        
        sum = a + b;
        while(sum>0){
                sum /= 10;
                count++;
                }
        cout << count << endl;
        count = 0;
        }
 
 
 
 
return 0;
}

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

int main() {
  long long n, k;

  cin >> n >> k;

  long long ans;
  if (k % 2 == 0) {
    if (n < k/2) {
      ans = pow(n/k, 3);
    }
    else {
      ans = pow(n/k, 3) + pow((n - k/2)/k + 1, 3);
    }
  }
  else if (k % 2 == 1) {
    ans = pow(n/k, 3);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include"atcoder/all"
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
//using namespace atcoder;
int main(){
  int N,M,i,x,y;scanf("%d%d",&N,&M);
  int ball[N];fill(ball,ball+N,1);
  bool red[N] = {};red[0] = true;
  for(i=0;i<M;i++){
    scanf("%d%d",&x,&y);x--;y--;
    ball[x]--;ball[y]++;
    red[y] |= red[x];
    red[x] &= ball[x]>0;
  }
  printf("%d\n",accumulate(red,red+N,0));
}

Measured memory_bytes: 4292
#include <bits/stdc++.h>
using namespace std;
int main(){
  char ch;
  int co = 0;
  for(int i = 0; i < 3; i++){
    scanf("%c", &ch);
    if(ch == 'o') co += 100;
  }
  cout << co + 700 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;++i)
#define MOD (int) 1e9+7

int main(){
    string s;
    cin >> s;
    vector<int>  rlr, lrl;
    rep(i, s.size()-1){
        if(s[i]=='R' && s[i+1]=='L'){
            rlr.emplace_back(i);
        }
        if(s[i]=='L' && s[i+1]=='R'){
            lrl.emplace_back(i);
        }
    }
    lrl.emplace_back(s.size()-1);

    vector<int> num(s.size());
    int j=0;
    rep(i, s.size()){
        if(i>lrl[j]){
            j++;
        }
        // cout << i << " " << j << " " << lrl[j] << " " << rlr[j] << " " << endl;
        if((i-rlr[j])%2==0){
            num[rlr[j]]++;
        }else{
            num[rlr[j]+1]++;
        }
    }
    rep(i, s.size()-1){
        cout << num[i] << " ";
    }
    cout << num[s.size()-1] << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 1532
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a,b;
        a=sc.nextInt();
        b=sc.nextInt();
        if(a<=b) System.out.println(a);
        else System.out.println(a-1);
    }
}


Measured memory_bytes: 21076
#include <iostream>
#include <algorithm>
using namespace std;
#define NUM 100

int main(){
    int n, x, m[NUM];
    cin >> n >> x;
    int ans = n;
    for(int i = 0; i < n; i++){
        cin >> m[i];
        x -= m[i];
    }
    sort(m, m + n);
    ans += x / m[0];
    cout << ans << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
using Graph = vector<vector<ll>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1 << 29;
/****** define constant end ********/
/****** define variable start ******/
ll k;
/******* define variable end *******/
ll solve()
{
    cin >> k;
    vl hairetu = {1,
                  1,
                  1,
                  2,
                  1,
                  2,
                  1,
                  5,
                  2,
                  2,
                  1,
                  5,
                  1,
                  2,
                  1,
                  14,
                  1,
                  5,
                  1,
                  5,
                  2,
                  2,
                  1,
                  15,
                  2,
                  2,
                  5,
                  4,
                  1,
                  4,
                  1,
                  51};

    cout << hairetu[k - 1] << endl;
    return 0;
}
int main()
{
    //clock_t start = clock();
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll end_solve = solve();
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */

    return (int)end_solve;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();

		if (K < N) {
			System.out.println(K * X + (N - K) * Y);
		} else {
			System.out.println(N * X);
		}
	}
}


Measured memory_bytes: 9548
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdio.h>
using namespace std;

char a[105][105];
int used[105][105];
int n,m;
int dir[4][2]={1,0,-1,0,0,1,0,-1};
void dfs(int x,int y)
{
	used[x][y]=1;
	for(int i=0;i<4;i++)
	{
		int xx=x+dir[i][0];
		int yy=y+dir[i][1];
		if(xx>=0&&xx<n&&yy>=0&&yy<m&&(a[xx][yy]==a[x][y])&&used[xx][yy]==0)
		{
			dfs(xx,yy);
		}
	}
	return ;
}
int main()
{
	int i,j,res;
	while(~scanf("%d %d",&n,&m))
	{
		if(n==0&&m==0)
		break;
		res=0;
		memset(used,0,sizeof(used));
		for(i=0;i<n;i++)
	{
		scanf("%s",a[i]);
	 } 
	for(i=0;i<n;i++)
	for(j=0;j<m;j++)
	{
		if((a[i][j]=='#'||a[i][j]=='*'||a[i][j]=='@')&&used[i][j]==0)
		{
			dfs(i,j);
			res++;
		}
	 }
	 printf("%d\n",res);
	}
	return 0; 
 } 


Measured memory_bytes: 3780
n = int(input())
a = input()
i1 = 0
i2 = n-1
t = 0

while i1 < i2:
	if a[i1] == "W" and a[i2] == "R":
		t += 1
		i1 += 1
		i2 -= 1
	elif a[i1] == "R":
		i1 += 1
	elif a[i2] == "W":
		i2 -= 1
print(t)


Measured memory_bytes: 9472
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();
		int ans = 0;
		for (int i=1; i<=n; i++) {
			for (int j=1; j<=n; j++) {
				for (int k=1; k<=n; k++) {
					ans +=gcd3(i,j,k);
				}
			}
		}
		System.out.println(ans);
	}
	static int gcd3 (int a, int b, int c) {return gcd(gcd(a,b),c);}
	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
}


Measured memory_bytes: 27240
# coding: utf-8
from collections import deque
N, Q = map(int, input().split())
lst = [[] for _ in range(N)]
ans = [0] * N
for i in range(N-1):
    a,b = map(int, input().split())
    lst[b-1].append(a-1)
    lst[a-1].append(b-1)
for j in range(Q):
    p, x = map(int, input().split())
    ans[p-1] += x

q = deque()
q.append(0)
flag = [0] * N
while q:
    y = q.pop()
    flag[y] = 1
    for k in lst[y]:
        if flag[k] == 1:
            continue
        ans[k] += ans[y]
        q.append(k)
print(*ans)



Measured memory_bytes: 105236
package main

import (
	"bufio"
	"fmt"
	"os"
)

var sc = bufio.NewScanner(os.Stdin)

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func rs() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	h, w := ri(), ri()

	for i := 0; i < w+2; i++ {
		fmt.Printf("#")
	}
	fmt.Printf("\n")

	for i := 0; i < h; i++ {
		fmt.Printf("#%s#\n", rs())
	}

	for i := 0; i < w+2; i++ {
		fmt.Printf("#")
	}
	fmt.Printf("\n")
}


Measured memory_bytes: 640
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val a = Array(n) { sc.nextInt() }
    var ans = 1L
    for (i in 0 until n) {
        ans *= 3
    }
    var odd = 1L
    for (i in 0 until n) {
        if (a[i] % 2 == 0) {
            odd *= 2
        }
    }
    ans -= odd
    println(ans)
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 34304
use scanner::Scanner;

fn main() {
    let mut sc = Scanner::new();
    let mut abc: Vec<i32> = (0..3).map(|_| sc.read()).collect();
    abc.sort();
    println!("{}", if abc[0] + abc[1] == abc[2] { "Yes" } else { "No" });
}

mod scanner {
    pub struct Scanner<'a> {
        s: String,
        words: ::std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new() -> Scanner<'a> {
            let s = String::new();
            let words = unsafe { ::std::mem::transmute(s.split_whitespace()) };
            Scanner { s: s, words: words }
        }

        pub fn read<T: ::std::str::FromStr>(&mut self) -> T {
            match self.words.next() {
                Some(x) => x.parse().ok().unwrap(),
                None => {
                    self.load();
                    self.read()
                }
            }
        }

        fn load(&mut self) {
            self.s.clear();
            ::std::io::stdin().read_line(&mut self.s).unwrap();
            self.words = unsafe { ::std::mem::transmute(self.s.split_whitespace()) };
        }
    }
}


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

int main()
{
    int n; cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++) cin >> d[i];
    
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            ans += d[i]*d[j];
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define X real()
#define Y imag()
#define value(x,y,w,h) (x >= 0 && x < w && y >= 0 && y < h)
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

typedef long long ll ;
typedef deque<int> di ;
typedef deque<ll> dl ;
typedef map<string,int> dict;
typedef complex<double> comd;
typedef pair<int,int> pii;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,h,m,m2,l,d,mn;
  int lc,dc,mnc;
  char c;
  while(cin >> n){
    if(n == 0) break;
    l = d = mn = 0;
    lc = dc = mnc = 0;
    rep(_,n){
      cin >> h >> c >> m >> m2;
      if(11 <= h && h <= 14){
        ++lc;
        if(m2 - m >= 0 && m2-m <9){
          ++l;
        }
        else if(m2 - m < 0 && 60 - m + m2 <9){
          ++l;
        }
      }
      else if ( 18 <= h && h <= 20){
        ++dc;
        if(m2 - m >= 0 && m2-m <9){
          ++d;
        }
        else if(m2 - m < 0 && 60 - m + m2 <9){
          ++d;
        }
      }
      else if((21 <= h && h <= 23) ||(0 <= h && h <= 1)){
        ++mnc;
        if(m2 - m >= 0 && m2-m <9){
          ++mn;
        }
        else if(m2 - m < 0 && 60 - m + m2 <9){
          ++mn;
        }
      }
    }
    cout << "lunch ";
    if(lc != 0)
      cout<< (int)(1.0*l/lc*100 )<< endl;
    else
      cout << "no guest" <<endl;
    cout << "dinner ";
    if(dc != 0)
      cout << (int)(1.0*d/dc*100 )<< endl;
    else
      cout << "no guest" <<endl;
    cout << "midnight ";
    if(mnc != 0)
      cout << (int)(1.0*mn/mnc*100 )<< endl;
    else
      cout << "no guest" <<endl;
  }
  return 0;
}

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

int main(){
    string s;
    cin >> s;
    vector<int> l;
    vector<int> r;
    rep(i,s.length()){
        if(s[i] == 'L') l.push_back(i);
        else r.push_back(-i);
    }
    sort(r.begin(),r.end());
    vector<int> ans(s.length(),0);
    rep(i,s.length()){
        if(s[i] == 'R'){
            int a = lower_bound(l.begin(),l.end(),i) - l.begin();
            if((l[a] - i) % 2) ans[l[a]-1]++;
            else ans[l[a]]++;
        } else {
            int b = lower_bound(r.begin(),r.end(),-i) - r.begin();
            if((i + r[b]) % 2) ans[-r[b]+1]++;
            else ans[-r[b]]++;;
        }
    }
    rep(i,s.length()) cout << ans[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 1532
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i, a, n) for(int i = a;i < n;++i)
#define repe(i, a, n) for(int i = a;i <= n;++i)
#define repr(i, a, n) for(int i = a;i > n;--i)
#define reper(i, a, n) for(int i = a;i >= n;--i)
using namespace std;


using P = pair<int, int>;


int N;
P ab[110];
P cd[110];
vector<int> g[210];
int match[210];
bool used[210];


void add_edge(int u, int v){
	g[u].push_back(v);
	g[v].push_back(u);
}


bool dfs(int v){
	used[v] = true;
	rep(i, 0, (int)g[v].size()){
		int u = g[v][i], w = match[u];
		if(w < 0 || !used[w] && dfs(w)){
			match[v] = u;
			match[u] = v;
			return true;
		}
	}
	return false;
}


int solve(){
	rep(i, 0, N)
		rep(j, 0, N)
			if(ab[i].first < cd[j].first && ab[i].second < cd[j].second) add_edge(i, N+j);

	int ans = 0;
	fill(&match[0], &match[210], -1);
	rep(v, 0, 2*N){
		if(match[v] < 0){
			fill(&used[0], &used[210], false);
			if(dfs(v)) ans++;
		}
	}
	return ans;
}


int main(){
	cin >> N;
	rep(i, 0, N) cin >> ab[i].first >> ab[i].second;
	rep(i, 0, N) cin >> cd[i].first >> cd[i].second;

	cout<< solve() << endl;

	return 0;
}

Measured memory_bytes: 256
function Main(input) {
  input=input.split("\n");
　var cards={};
  var next;
  cards['a']=input[0];
  cards['b']=input[1];
  cards['c']=input[2];
  var turn='a';
  while(true){
    if(cards[turn].length===0){
      console.log(turn.toUpperCase());
      return;
    }
    next=cards[turn][0];
    cards[turn]=cards[turn].slice(1);
    turn=next;
    //console.log(cards);
  }
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  
  


Measured memory_bytes: 29568
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - +-x
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int a, b;
  scanf("%d%d", &a, &b);
  printf("%d\n", max(max(a + b, a - b), a * b));
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    if(A >= 13){
      System.out.println(B);
    }else if(12 >= A && A>= 6)
    {
      System.out.println(B/2);
    }
    else if(5 >= A && A >=0)
      System.out.println(0);
  }
}



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n; cin>>n;
	cout << n*n*n << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mo 1000000007
//#define add(a,b) (a+b>=mo)?(a+=b-mo):(a+=b)
#define lowbit(s) ((s)&(-(s))) 
using namespace std;
int f[2][22][1<<20],a[22][22];
inline void add(int &a,int b){(a+b>=mo)?(a+=b-mo):(a+=b);}
int main()
{
	int n,m,q;scanf("%d%d%d",&n,&m,&q);
	memset(a,255,sizeof(a));
	while (q--)
	{
		int u,v,w;scanf("%d%d%d",&u,&v,&w);
		a[u][v]=w;
	}
	f[1][0][0]=1;
	for (int i=1;i<=m;i++)
	{
		memset(f[(i&1)^1],0,sizeof(f[(i&1)^1]));
		for (int j=0;j<n-1;j++)
		{
			for (int s=0;s<(1<<(n-1));s++)
			{
				add(f[i&1][j+1][s],f[i&1][j][s]*((a[i][j+1]!=1)&&((s&(1<<j))==0)));
				add(f[i&1][j+1][s+(!(bool)(s&(1<<j)))*(-(lowbit(s>>j)<<j)+(1<<j))],f[i&1][j][s]*(a[i][j+1]!=0));
			}
		}
		for (int s=0;s<(1<<(n-1));s++) add(f[(i&1)^1][0][s],f[i&1][n-1][s]);
	}
	int ans=0;
	for (int s=0;s<(1<<(n-1));s++) add(ans,f[m&1][n-1][s]);
	printf("%d\n",ans);
}
	
	
	
	
	
	
	
	
	
	
	

Measured memory_bytes: 180608
def solve():
    n, x = map(int, input().split())
    l = input().split()
    d = []
    for i in range(n+1):
        d.append(0)
    total = 1
    for i in range(1, n+1):
        d[i] = d[i-1] + int(l[i-1])
        if(d[i] <= x):
            total += 1
    print(total)

if __name__ == "__main__":
    solve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define array_input int n;cin>>n;int a[n+1],i;for(i=1;i<=n;i++){cin>>a[i];}
#define array_output for(i=1;i<=n;i++){cout<<a[i]<<" ";}cout<<endl;
#define quicker ios::sync_with_stdio(false);
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;
const double pi=acos(-1);
const double eps=1e-6;
#define INF 2147483647
#define long_INF 18446744073709551615
#define hehe 23333333

void read(int &x)
{
    x=0;
	char c=getchar();
    while(c<'0' || c>'9')c=getchar();
    while(c>='0' && c<='9')
	{
        x=x*10+c-'0';
        c=getchar();
    }
}

void write(int x)
{
    if(x==0)
	{
		putchar(48);
		return;
	}
    int len=0,dg[20];
    while(x>0)
	{
		dg[++len]=x%10;
		x/=10;
	}
    for(int i=len;i>=1;i--)
	{
		putchar(dg[i]+48);
	}
}

int main()
{
	int x;
	cin>>x;
	string s;
	cin>>s;
	int qian[271],hou[271],i,j;
	int cnt=0,maxv=-1;
	for (i=1;i<=s.size();i++)
	{
		cnt=0;
		for (j=1;j<=270;j++)
		{
			qian[j]=0;
			hou[j]=0;
		}
		for (j=0;j<=i;j++)
		{
			qian[s[j]-'0']=1;
		}
		for (j=i+1;j<=s.size();j++)
		{
			hou[s[j]-'0']=1;
		}
		for (j=1;j<=270;j++)
		{
			if (qian[j]==1 && hou[j]==1)
			{
				cnt++;
			}
		}
		if (cnt>maxv)
		{
			maxv=cnt;
		}
	}
	cout<<maxv<<endl;
	return 0;
}

Measured memory_bytes: 256
//By Bibi
///                 .-~~~~~~~~~-._       _.-~~~~~~~~~-.
///             __.'              ~.   .~              `.__
///           .'//                  \./                  \\`.
///        .'//                     |                     \\`.
///       .'// .-~"""""""~~~~-._     |     _,-~~~~"""""""~-. \\`.
///     .'//.-"                 `-.  |  .-'                 "-.\\`.
///   .'//______.============-..   \ | /   ..-============.______\\`.
/// .'______________________________\|/______________________________`.
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define dep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
int read(){
	int sum=0,flag=1;
	char c;
	for(;c<'0'||c>'9';c=getchar())if(c=='-') flag=-1;
	for(;c>='0'&&c<='9';c=getchar())sum=(sum<<1)+(sum<<3)+c-'0';
	return sum*flag;
}
int a,b,c,d; 
void init(){
	a=read();b=read();c=read();d=read();
}
int main(){
	init();
	printf("%d",min(a,b)+min(c,d));
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define swap(type,a,b) do{type temp=a; a=b; b=temp;}while(0);
#define FOR(i,a,n) for(i=a;i<n;i++)

typedef struct LIST{
	int to;
	struct LIST *next;
}Edge;

Edge *edge[100001];
int used[100001];
int ans[100001];
int size=0;

void reverse(int a[],int left,int right){
	while(right>left){
		swap(int,a[left],a[right]);
		left++,right--;
	}
	return;
}

void add(int v,int t){
	Edge *temp = (Edge*)malloc(sizeof(Edge));
	temp->to = t;
	temp->next = edge[v];
	edge[v] = temp;
	return;
}

void end(int v){
	for(int i=1;i<=v;i++){
		for(Edge *e=edge[i]->next;e!=NULL;e=e->next)
		    free(e);
	}
	return;
}

void dfs(int v){
	used[v]=1;
	for(Edge* e=edge[v];e!=NULL;e=e->next){
		if(!used[e->to]){
			ans[size++]=e->to;
			dfs(e->to);
			return;
		}
	}
	return;
}

int main(void)
{
 	int n,m,i,a,b;
 	scanf("%d%d",&n,&m);
 	FOR(i,0,m){
 		scanf("%d%d",&a,&b);
 		add(a,b); add(b,a);
 	}
 	int s=1;
 	int g=edge[s]->to;
 	used[s]=used[g]=1;
 	ans[size++]=s;
 	dfs(s);
 	reverse(ans,0,size-1);
 	ans[size++]=g;
 	dfs(g);
 	printf("%d\n",size);
 	FOR(i,0,size) printf("%d\n",ans[i]);
 	end(n);
 	return 0;
}

Measured memory_bytes: 8448
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <queue>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

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

int w, h;
int dy[6] = {-1, 0,+1,+1, 0,-1};
int dx[6] = { 0,-1, 0,+1,+1,+1};

int dy2[6] = {-1, 0,+1,+1, 0,-1};
int dx2[6] = {-1,-1,-1, 0,+1, 0};

bool can(int y,int x) {
	if(0 <= y && y < h + 2 && 0 <= x && x < w + 2) return true;
	return false;
}

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

	vector< vector<int> > v(h + 2, vector<int>(w + 2));
	rep(i, h) {
		rep(j, w) cin >> v[i+1][j+1];
	}

	int sy = 0, sx = 0;

	queue<P> que;
	que.push(mp(sy, sx));

	bool used[105][105];
	memset(used, 0, sizeof(used));
	used[sy][sx] = true;

	int ans = 0;

	while(que.size()) {
		P p = que.front();
		que.pop();

		rep(i, 6) {
			int y, x;

			if(p.first % 2 == 0) {
				y = p.first + dy2[i];
				x = p.second + dx2[i];
			} else {
				y = p.first + dy[i];
				x = p.second + dx[i];
			}

			if(can(y, x)) {
				if(v[y][x] == 1) {
					ans++;
				} else if(!used[y][x]) {
					used[y][x] = true;
					que.push(mp(y, x));
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>
#include <vector>
#include <algorithm>

#define MAX_SIZE 1500000

using namespace std;

int main(){
	int dansu,kansu,shelf[20],book[100],min_size,left,right,m,dansu_index;

	while(true){
		scanf("%d %d",&dansu,&kansu);
		if(dansu == 0 && kansu == 0)break;

		for(int i = 0; i < kansu; i++){
			scanf("%d",&book[i]);
		}

		min_size = MAX_SIZE;
		left = 0,right = MAX_SIZE;
		m = (left+right)/2;

		while(left < right){

			for(int i = 0; i < dansu; i++)shelf[i] = m;
			dansu_index = 0;
			for(int i = 0; i < kansu && dansu_index < dansu;){
				if(shelf[dansu_index] >= book[i]){
					shelf[dansu_index] -= book[i];
					i++;
				}else{
					dansu_index++;
				}
			}

			if(dansu_index == dansu){
				left = m + 1;
				m = (left + right)/2;
			}else{
				min_size = min(min_size,m);
				right = right - 1;
				m = (left + right)/2;
			}
		}

		printf("%d\n",min_size);

	}

    return 0;
}

Measured memory_bytes: 2584
from collections import Counter
N, M = map(int, input().split())
A = list(map(int, input().split()))
B = [0]
for a in A:
    B.append((B[-1]+a) % M)
B = Counter(B)
ans = 0
for c in B.values():
    ans +=  c*(c-1)//2
print(ans)


Measured memory_bytes: 17360
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>

namespace nygdr
{
	int gcd(int a,int b){return b?gcd(b,a%b):a;}
	const int N=2010,M=N*N*2;
	int begin[N],next[M],to[M];
	int A[N];
	int n,e;
	void add(int x,int y,bool k=1)
	{
		to[++e]=y;
		next[e]=begin[x];
		begin[x]=e;
		if(k)add(y,x,0);
	}
	bool vis[N];
	int predfs(int p)
	{
		vis[p]=1;
		int ret=p;
		for(int i=begin[p],q;i;i=next[i])
			if(!vis[q=to[i]])
			{
				q=predfs(q);
				if(A[q]<A[ret])ret=q;
			}
		return ret;
	}
	void initialize()
	{
		scanf("%d",&n);
		for(int i=1;i<=n;i++)
		{
			scanf("%d",A+i);
			for(int j=1;j<i;j++)
				if(gcd(A[i],A[j])>1)add(i,j);
		}
		for(int i=1;i<=n;i++)
			if(!vis[i])add(0,predfs(i));
		memset(vis,0,sizeof(vis));
		A[0]=2147483647;
	}
	std::vector<int> s[N];
	std::vector<int> tmp;
	void dfs(int p=0)
	{
		vis[p]=1;s[p].clear();

		for(int q=19260817;q;)
		{
			q=0;
			for(int i=begin[p];i;i=next[i])
				if(!vis[to[i]] && A[to[i]]<A[q])q=to[i];
			if(!q)continue;
			dfs(q);

			std::vector<int>::iterator itp=s[p].begin(),itq=s[q].begin();
			while(itp!=s[p].end() || itq!=s[q].end())
			{
				if(itp==s[p].end())tmp.push_back(*itq),itq++;
				else if(itq==s[q].end() || (*itp)>(*itq))tmp.push_back(*itp),itp++;
				else tmp.push_back(*itq),itq++;
			}

			s[p]=tmp;tmp.clear();
		}
		if(p)s[p].insert(s[p].begin(),A[p]);

//		printf("%d : ",p);for(auto it:s[p])printf("%d ",it);printf("\n");
	}
	void solve()
	{
		initialize();
		dfs();
		for(auto it:s[0])printf("%d ",it);
		printf("\n");
	}
}

int main()
{
	nygdr::solve();
	return 0;
}


Measured memory_bytes: 38784
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

void dfs(const vector<vector<int>>& graph, vector<int>& color, int node, int parent, int c) {
    color[node] = c;
    for (auto next_node : graph[node]) {
        if (next_node == parent) {
            continue;
        }
        dfs(graph, color, next_node, node, c ^ 1);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int A, B;
    vector<vector<int>> graph(N);
    rep(i, 0, N - 1) {
        cin >> A >> B;
        --A, --B;
        graph[A].push_back(B);
        graph[B].push_back(A);
    }
    vector<int> color(N, -1);
    dfs(graph, color, 0, -1, 0);
    vector<stack<int>> node_idx(2);
    rep(node, 0, N) {
        node_idx[color[node]].push(node);
    }
    int less_color = node_idx[0].size() < node_idx[1].size() ? 0 : 1;
    int mod_is_zero = N / 3;  // %3=0となる値の個数
    vector<int> ans(N, -1);
    vector<bool> used(N, false);
    if ((int)node_idx[less_color].size() <= mod_is_zero) {
        // 少ない色のノードを3の倍数で埋める
        int now_val = 3;
        while (!node_idx[less_color].empty()) {
            int node = node_idx[less_color].top();
            node_idx[less_color].pop();
            ans[node] = now_val;
            used[now_val] = true;
            now_val += 3;
        }
        now_val = 1;
        while (!node_idx[less_color ^ 1].empty()) {
            int node = node_idx[less_color ^ 1].top();
            node_idx[less_color ^ 1].pop();
            while (used[now_val]) {
                ++now_val;
            }
            ans[node] = now_val;
            used[now_val] = true;
            ++now_val;
        }
    }
    else {
        // 少ない色のノードを2の倍数で埋めて, 残りを3で埋める
        int now_val = 2;
        while (!node_idx[less_color].empty() && now_val <= N) {
            int node = node_idx[less_color].top();
            node_idx[less_color].pop();
            ans[node] = now_val;
            used[now_val] = true;
            now_val += 3;
        }
        now_val = 3;
        while (!node_idx[less_color].empty()) {
            int node = node_idx[less_color].top();
            node_idx[less_color].pop();
            ans[node] = now_val;
            used[now_val] = true;
            now_val += 3;
        }
        now_val = 1;
        while (!node_idx[less_color ^ 1].empty()) {
            int node = node_idx[less_color ^ 1].top();
            node_idx[less_color ^ 1].pop();
            while (used[now_val]) {
                ++now_val;
            }
            ans[node] = now_val;
            used[now_val] = true;
            ++now_val;
        }
    }
    rep(i, 0, N) {
        cout << ans[i] << " \n"[i + 1 == N];
    }
    return 0;
}

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

int main() {
    int N, a, b, ans = 1;
    bool first = true, up;
    cin >> N >> a;
    rep(i, N-1) {
        cin >> b;
        if (a == b) continue;
        if (first) {
            up = a < b;
            first = false;
        }
        if (up && a > b || !up && a < b) {
            ans++;
            first = true;
            up = a < b;
        }
        //printf("%d %d %d %d\n", i, a, b, ans);
        a = b;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
#define N 300001
int mod=1000000007;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
vector<int> parent(N),sz(N),indegree(N),vis(N); char st[N];
vector<int> adj[N];
int modexp(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        
        return modexp((x*x)%M,n/2,M);
    else                             
        return (x*modexp((x*x)%M,(n-1)/2,M))%M;
}
void make_set(int s)
{
    parent[s]=s;
    sz[s]=1;
}
int find_parent(int p)
{
    if(p==parent[p])
    return p;
    return parent[p]=find_parent(parent[p]);
}
void union_set(int a,int b)
{
    a=find_parent(a);b=find_parent(b);
    if(a!=b)
    {
        if(a<b)
        swap(a,b);
        parent[b]=parent[a];
        sz[a]+=sz[b];
    }
}
void solve()
{
    int n; cin>>n;
    vector<vector<int>>v;
    v.resize(n+1,vector<int>(3,0));
    for(int i=1;i<=n;i++)
    {
        cin>>v[i][0]>>v[i][1]>>v[i][2];
    }
    vector<vector<int>> dp;
    dp.resize(n+1,vector<int>(3,0));
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<3;j++)
        {
            for(int k=0;k<3;k++)
            {
                if(j!=k)
                dp[i][j]=max(dp[i][j],dp[i-1][k]+v[i][j]);
            }
        }
    }
    cout<<max(dp[n][2],max(dp[n][0],dp[n][1]));
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test; test=1;
    while(test--)
    {
        solve();
    }
    return 0;
}

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

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

int main(){
  int K;
  cin >> K;
  long long sum = 0;
  for(int a = 1; a <= K; a++){
    for(int b = 1; b <= K; b++){
      for(int c = 1; c <= K; c++){
        sum += gcd(a, gcd(b, c));
      }
    }
  }
  cout << sum << endl;
  
}

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

int printout(int n,int A[])
{
  for(int i=0;i<n;i++)
  {
    if(i) cout<<" ";
    cout<<A[i];
  }
  cout<<endl;
}

int selectionSort(int n,int A[])
{
  int sw=0;
  for(int i=0;i<n;i++)
  {
    int minj=i;
    for(int j=i;j<n;j++)
    {
      if(A[j]<A[minj]) minj=j;
    }
    if(minj!=i)
    {
      swap(A[minj],A[i]);
      sw++;
    }
  }
  return sw;
}

int main()
{
  int n;
  int A[100];
  cin>>n;
  for(int i=0;i<n;i++)
  {
    cin>>A[i];
  }
  int count;
  count=selectionSort(n,A);
  printout(n,A);
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n + 1);
  FOR(i, 1, n + 1) cin >> a[i];

  rep(i, n) {
    a[i + 1] = (a[i + 1] - 1 + a[i] + k) % k;
  }
  map<ll, ll> m;
  ll ans = 0;
  rep(i, n + 1) {
    if (i >= k) m[a[i - k]]--;
    ans += m[a[i]]++;
  }
  cout << ans << endl;


  
  return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include <bitset>

int main()
{	
	unsigned int x; std::cin >> x;
	std::bitset<32> bs(x);
	
	std::cout << bs << std::endl;
	std::cout << ~bs << std::endl;
	std::cout << (bs<<1) << std::endl;
	std::cout << (bs>>1) << std::endl;
	
	return 0;
}



Measured memory_bytes: 3152