akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	N := readInt()
	s := make([]string, N)
	for i := range s {
		s[i] = readString()
	}
	t := make([]int64, 26)
	for _, x := range s {
		i := x[0] - 'A'
		t[i]++
	}
	u := make([]int64, 0)
	for _, b := range []byte{'M', 'A', 'R', 'C', 'H'} {
		i := b - 'A'
		if t[i] > 0 {
			u = append(u, t[i])
		}
	}
	var ans int64
	for i := 0; i+2 < len(u); i++ {
		for j := i + 1; j+1 < len(u); j++ {
			for k := j + 1; k < len(u); k++ {
				ans += u[i] * u[j] * u[k]

			}
		}
	}

	println(ans)
}


Measured memory_bytes: 3200
<?php
  fscanf(STDIN, "%s", $S);
  $arr = str_split($S);  
//aabb
  if ($arr[0] !==$arr[2] && $arr[0] === $arr[1] && $arr[2] === $arr[3]){
            echo "Yes";
            exit;
  }
//abab
  elseif($arr[0] !==$arr[1] && $arr[0] === $arr[2] && $arr[1] === $arr[3]){
            echo "Yes";
            exit;
  }
//abba
  elseif($arr[0] !==$arr[1] && $arr[0] === $arr[3] && $arr[1] === $arr[2]){
            echo "Yes";
            exit;
  }
   else{
                 echo "No";
   }

Measured memory_bytes: 3828
#include<cstdio>

int chou=0;
int hisi=0;

int date_1,date_2,date_3;

int main()
{
	while(scanf("%d,%d,%d",&date_1,&date_2,&date_3)!=EOF)
	{
		if(date_1*date_1+date_2*date_2==date_3*date_3)chou++;
		else if(date_1==date_2)hisi++;
	}
	printf("%d\n%d\n",chou,hisi);
	return 0;
}

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

int main(){
    int h,w;
    cin >> h >> w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            string s;
            cin >> s;
            if(s=="snuke"){
                cout <<(char)('A'+j)<< i+1 <<endl;
            }
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
const int INF = 1001001001;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define re0 return 0
#include<string.h>
int npr(int n , int r){//nPr
    r = n - r;
    int sum = 1;
    int i;
    for (i=n;i>=r+1;i--)sum*=i;
    return sum;
}
int gcd(int a, int b) {//最大公約数
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {//最小公倍数
    return a * b / gcd(a, b);
}
int digsum(int n) {//桁和
    int res = 0;
    while(n > 0) {
        //res += n%10;
        //　↑をres++;にすれば桁数
         res++;
        n /= 10;
    }
    return res;
}
bool isPrime(int x){//素数判定
    if(x==1)return 0;
    if(x==2)return 1;
    if(x%2==0)return 0;
    for(int i=3;i*i<=x;i++)if(x%i==0)return 0;
    return 1;
}
/*bit全探索
for (int bit = 0; bit < (1<<N); ++bit) {
}
if (bit & (1 << i)) {
}
*/


int main(void){
    int x,y;
    cin >> x >> y;
    if(y%2==0 && 2*x<=y && y<=4*x){
        cout << "Yes" <<endl; 
    }else{
        cout << "No" <<endl;
    }
    return 0;
}




Measured memory_bytes: 3636
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main(){
  string s1,s2;
  cin>>s1>>s2;
  cout << s2 << s1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#define all(c) c.begin(), c.end()
#define pb push_back
#define ll long long
const int MAXN = 1e5 + 5;

using namespace std;

int dp[15][1<<15], n;
vector<pair<int,int>> ve[15];

int rec(int u, int mask) {
  if (mask == (1<<n)-1) return 0;
  int &ret = dp[u][mask];
  if (ret != -1) return ret;
  ret = 1e9;
  for (auto v : ve[u])
    if (!(mask&(1<<v.first)) && (v.first != 0 || mask == (1<<n)-2))
      ret = min(ret, v.second+rec(v.first, mask|(1<<v.first)));
  return ret;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int e; cin >> n >> e;
  while (e--) {
    int u, v, w;
    cin >> u >> v >> w;
    ve[u].pb({v, w});
  }
  memset(dp, -1, sizeof dp);
  int mini = rec(0, 0);
  cout << (mini == 1e9? -1 : mini) << "\n";
  return 0;
}


Measured memory_bytes: 5136
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define INF 1 << 30

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

int main(void) {
	int num, i, ok = true;
	string s;
	cin >> s;
	if (s.size() & 1)
		ok = false;
	for (i = 0; i < s.size(); i+=2) {
		if (s[i] != 'h' || s[i + 1] != 'i')
			ok = false;
	}
	if (ok)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 256
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        n: usize,
        s: Chars,
    }

    let mut first = vec![None; 10];
    let mut last = vec![None; 10];
    let mut indices = vec![vec![]; 10];

    for i in 0..n {
        let num = s[i] as usize - '0' as usize;
        if first[num] == None {
            first[num] = Some(i);
        }
        last[num] = Some(i);
        indices[num].push(i);
    }

    let mut count = 0;
    for i in 0..10 {
        for j in 0..10 {
            for k in 0..10 {
                let left_index;
                let right_index;
                if let Some(index) = first[i] {
                    left_index = index;
                } else {
                    continue;
                }
                if let Some(index) = last[k] {
                    right_index = index;
                } else {
                    continue;
                }
                for &index in &indices[j] {
                    if left_index < index && index < right_index {
                        count += 1;
                        break;
                    }
                }
            }
        }
    }

    println!("{}", count);
}


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

int main()
{
    string s1,s2;
    cin>>s1>>s2;
    int l1= s1.length();
    int l2 = s2.length();
    int discount=0;
    int res = INT_MAX;
    for(int i=0;i<l1-l2+1;i++)
    {
        discount=0;
        int count=i;
        for(int j=0;j<l2;j++)
        {
            if(s1[count]!=s2[j])
            {
                discount++;
            }
            count++;
        }
        res=min(res, discount);
    }
    cout<<res<<endl;
}



Measured memory_bytes: 3612
'use strict'

function main(input) {
  input = input.split('\n').map(v => ~~v)
  const n = input[0]
  const buttons = input.slice(0, input.length)
  let tmp = 1
  let next = 0
  let cnt = 1

  while (cnt < n) {
    next = buttons[tmp] // index 3
    if (next == 2) {
      console.log(cnt)
      return
    }
    tmp = next
    cnt++
  }
  console.log(-1)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

int main(void){
		int n,m;
		cin >> n >> m;
		int a[n][m];
		int b[m];
		int c[n];
		for(int i = 0;i < n;i++){
				for(int j = 0;j < m;j++){
						a[i][j] = 0;
					b[j] = 0;
				}
				c[i] = 0;
		}
		//配列へ入力
		
		for(int i = 0;i < n;i++){
				for(int j = 0;j < m;j++){
						cin >> a[i][j];
				}
		}
		for(int i = 0;i < m;i++){
				cin >> b[i];
		}
		//計算、出力
		for(int i = 0;i < n;i++){
				for(int j = 0;j < m;j++){
						c[i] += a[i][j] * b[j];
				}
				cout << c[i] << endl;
		}
		return 0;
}
				
		

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

int main() {
  int R;
  cin>>R;
  if(R<1200) {
    cout<<"ABC"<<endl;
  }
  if(1200<=R&&R<2800) {
    cout<<"ARC"<<endl;
  }
  if(2800<=R) {
    cout<<"AGC"<<endl;
  }
}

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

int main(){
  int n,a[100];
  cin >>n;
  rep(i,n) cin >>a[i];
  sort(a, a+n, greater<int>());
  int ali = 0;
  int bob = 0;
  rep(i,n){
    if(i%2 == 0) ali += a[i];
    else bob += a[i];
  }
  cout << ali - bob << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#define rep(i, n) for(i = 0; i < n; i++)
#define rrep(i, n) for(i = n - 1; i >= 0; i--)
using namespace std;

int n;
int a, b, k;

int main() {
	int i;
	
	cin >> a >> b >> k;
	
	if (a + k - 1 < b - k + 1) {
		for (i = a; i < a + k; i++) cout << i << endl;
		for (i = b - k + 1; i <= b; i++) cout << i << endl;
	}
	else {
		for (i = a; i <= b; i++) cout << i << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



struct Point{
	Point(double arg_x,double arg_y){
		x = arg_x;
		y = arg_y;
	}

	Point(){
		x = y = 0.0;
	}

	Point operator + (Point p){ return Point(x+p.x,y+p.y); }
	Point operator - (Point p){ return Point(x-p.x,y-p.y);}
	Point operator * (double a){ return Point(a*x,a*y); }
	Point operator / (double a){ return Point(x/a,y/a); }

	double abs(){ return sqrt(norm()); }
	double norm(){ return x*x + y*y; }

	bool operator<(const Point &p) const{
		return x != p.x? x < p.x: y < p.y;
	}

	bool operator == (const Point &p) const{
		return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
	}

	double x,y;
};

typedef Point Vector;
int N;
Point point[8];

double norm(Vector a){
	return a.x*a.x+a.y*a.y;
}

double abs(Vector a){
	return sqrt(norm(a));
}

double cross(Vector a,Vector b){
    return a.x*b.y-a.y*b.x;
}

double dot(Vector a,Vector b){
    return a.x*b.x + a.y*b.y;
}


int main(){

	scanf("%d",&N);

	for(int i = 0; i < N; i++){

		scanf("%lf %lf",&point[i].x,&point[i].y);
	}

	int table[N];
	for(int i = 0; i < N; i++){

		table[i] = i;
	}

	double ans = BIG_NUM;

	do{

		Point pre;
		pre.x = 0;
		pre.y = 0;

		double tmp = 0;

		Vector vec,next_vec;
		vec.x = 1;
		vec.y = 0;

		for(int i = 0; i < N; i++){

			next_vec = point[table[i]]-pre;

			tmp += fabs(acos(dot(next_vec,vec)/(abs(next_vec)*abs(vec))));

			pre = point[table[i]];
			vec = next_vec;
		}

		//家に帰る
		double x = 0;
		double y = 0;

		next_vec.x = x-pre.x;
		next_vec.y = y-pre.y;

		tmp += fabs(acos(dot(next_vec,vec)/(abs(next_vec)*abs(vec))));

		ans = min(ans,tmp);

	}while(next_permutation(table,table+N));

	printf("%.10lf\n",(ans*180)/M_PI);

	return 0;
}



Measured memory_bytes: 3532
#!/usr/bin/env python3

#import
#import math
#import numpy as np
x, y = map(int, input().split())

ans = abs(abs(x) - abs(y))

if x == 0 or y == 0:
    if x > y:
        ans += 1
elif int(x > 0) ^ int(y > 0):
    ans += 1
else:
    if x > y:
        ans += 2

print(ans)

Measured memory_bytes: 9184
#include <stdio.h>
#include <string.h>

int main(void)
{
    char str[1001], p[1001], o[10];
    int a, b, q, i;

    scanf("%s", &str);
    scanf("%d", &q);

    while(q--)
    {
        scanf("%s %d %d", &o, &a, &b);

        if(!strcmp(o, "replace"))
        {
            scanf("%s", &p);
            for(i = a; i <= b; ++i)
            {
                str[i] = p[i - a];
            }
        }

        if(!strcmp(o, "reverse"))
        {
            for(i = a; i <= b; ++i)
            {
                p[i - a] = str[i];
            }

            for(i = a; i <= b; ++i)
            {
                str[i] = p[b - i];
            }
        }

        if(!strcmp(o, "print"))
        {
            for(i = a; i <= b; ++i)
            {
                printf("%c", str[i]);
            }

            printf("\n");
        }

        /*
        if(order == "replace")
        {
            scanf(" %d %d %s", &a, &b, &p);

            int i;
            for(i = a; i <= b; ++i)
            {
                str[i] = p[i - a];
            }
        }

        if(order == "print")
        {
            scanf(" %d %d", &a, &b);

            int i;
            for(i = a; i <= b; ++i)
            {
                printf("%c", str[i]);
            }

            printf("\n");
        }

        if(order == "reverse")
        {
            scanf(" %d %d", &a, &b);

            int i;
            for(i = 0; i < (b - a) / 2; ++i)
            {
                char temp = str[i + a];
                str[i + a] = str[b - i];
                str[b - i] = temp;
            }
        }
        */
    }

    return 0;
}

Measured memory_bytes: 572
import sys
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n = INT()
res = 0
for i in range(9, 1, -1):
    if n%i == 0:
        res = n//i
        break
if n == 1:
    print('Yes')
elif res == 0:
    print('No')
elif res >= 10:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 38480
H,W=map(int,input().split())
S=[list(input()) for i in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j]=='#':
            continue
            #もし見ている文字が#だったら通過
        cnt=0
        for k in [-1,0,1]:
            if i+k<0 or H<=i+k:
                continue
                #iが端の時通過
            for l in [-1,0,1]:
                if j+l<0 or j+l>=W:
                    continue
                    #jが端の時通過
                cnt+=1*(S[i+k][j+l]=='#')
                #一個前一個上~一個下一個右までの#の数を足す
        S[i][j]=str(cnt)
        #見ていた数を足した数字に変更
for i in range(H):
    print("".join(S[i]))

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;

class ABC_127_C
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(input[0]);
        int M = int.Parse(input[1]);

        int min = 1;
        int max = N;

        for (int i = 0; i < M; i++)
        {
            string[] input2 = Console.ReadLine().Split(' ');
            int l = int.Parse(input2[0]);
            int r = int.Parse(input2[1]);

            min = Math.Max(min, l);
            max = Math.Min(max, r);
        }

        if(min<=max) Console.WriteLine(max-min+1);
        else Console.WriteLine(0);
    }
}

Measured memory_bytes: 15296
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)n; i++)
#define REPR(i, n) for(int i=(int)n-1; i>=0; i--)
#define FOR(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define FORR(i, m, n) for(int i=(int)m-1; i>=(int)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
typedef long long ll;
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }



void solve(long long N, long long A, long long B){
	ll res = min(N*A, B);
	cout << res << "\n";
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(N, A, B);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
//typedef LL int;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    int a, b;

    cin >> a >> b;
    
    if(a == 1 && b != 1){
        cout << "Alice" << endl;
        return 0;
    }else if(a != 1 && b == 1){
        cout << "Bob" << endl;
        return 0;
    }

    if(a - b > 0){
        cout << "Alice" << endl;
    }else if(a - b < 0){
        cout << "Bob" << endl;
    }else{
        cout << "Draw" << endl;
    }
}


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

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

const int MAXN = 2e5 + 1;
const int MOD = 1e9 + 7;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define FAIL0 {printf("0\n"); return 0;}
#define FAIL1 {printf("-1\n"); return 0;}
#define FAILNO {printf("NO\n"); return 0;}

int N;

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //scanf("%d", &N);

    int a,b,c;
    scanf("%d %d %d", &a, &b, &c);
    int ans = min(c, b/a);
    printf("%d", ans);

    printf("\n");
	return 0;
}


Measured memory_bytes: 256
/*
  AOJ 1195
  Title:Encryption System
  @kankichi573
*/
#include <stdio.h>
#include <string.h>

char angou[21];
char memo[1048576]; //20bit
int  a_len;

solve(char *buf,int use,int flag)
{
  int ret,bit1,bit2,bitx,len;
  char c;

  //printf("input=%s use=[%d]\n",&buf[0],use);
  if(!(c=*buf))
    {
      memo[flag]=1;
      return(1);
    } 
  bitx=1<<(strlen(buf)-1);
  if(c=='a')
    {
      ret = solve(buf+1,use,flag);
      if(!(use & 1))
	ret += solve(buf+1,use|1,flag|bitx);
    }
  else
    {
      bit1 = 1<<(*buf-'a'-1);
      bit2 = bit1<<1;      
      //printf("bit1=%d use=%d\n",bit1,use);
      ret=0;
      if(use & bit1)
	ret=solve(buf+1,use,flag);
      if(c!='z' && !(use & bit2))
        ret += solve(buf+1,use|bit2,flag|bitx);
    }
  //printf("input=%s use=[%d]=>%d\n",&buf[0],use,ret);
  return(ret);
}
print_hirabun(char * angou,int flag,int length,char * out)
{
  int i;
  for(i=0;i<length;i++)
    out[i]=angou[i]+((flag & (1<<(length-1-i)))?1:0);
  out[length]='\0';
}
void output(int num)
{
  int i,cnt;
  char buffer[5][21];
  
    if(num < 10)
    {
      for(i=0;i<(1<<a_len);i++)
	if(memo[i])
	  {
	    print_hirabun(angou,i,a_len,&buffer[0][0]);
	    printf("%s\n",&buffer[0][0]);
	  }
    }
  else
    {
      for(i=0,cnt=0;i<(1<<a_len) & cnt<5;i++)
	if(memo[i])
	  {
	    print_hirabun(angou,i,a_len,&buffer[0][0]);
	    printf("%s\n",&buffer[0][0]);
	    cnt++;
	  }
      for(i=(1<<a_len)-1,cnt=0;i>=0 & cnt<5;i--)
	if(memo[i])
	  {
	    print_hirabun(angou,i,a_len,&buffer[cnt][0]);
	    cnt++;
	  }
      for(i=4;i>=0;i--)
	printf("%s\n",&buffer[i][0]);
    }
}

main()
{
  int  use,ret,i;
  

  while(scanf("%s",angou) && *angou!='#')
    {
      memset(memo,0,1048576);
      use=0;
      a_len=strlen(angou);
      ret=solve(angou,use,0);
      printf("%d\n",ret);

      output(ret);
      memset(angou,0,21);
    }
  return(0);
}

Measured memory_bytes: 1584
#include <stdio.h>
#include <stdlib.h>

int comDesc(const void *a, const void *b)
{
    return *(int *)b - *(int *)a;
}

int main(void)
{
    int n, d[110], count = 1;
    scanf("%d", &n);

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

    qsort(d, n, sizeof(int), comDesc);

    for(int i = 1; i < n; i++){
        if(d[i] != d[i-1]){
            count++;
        }
    }

    printf("%d", count);

    return 0;
}

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

int main(){
    long int H,W;
    
    while(H != 0 && W != 0){
        cin >> H >> W;

        for(int i=0; i<H; i++){
            if(1==i%2){
                for(int j=0; j<W; j++){
                    cout << "#."[j%2==0];
                }    
            }else if(0==i%2){
                for(int j=0; j<W; j++){
                    cout << ".#"[j%2==0];
                }
            }
            cout << endl;
        }
        if(H != 0 && W != 0){
            cout << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;

int main(void){
  int n, q;
  string s;
  cin >> n >> q >> s;
  vector<int> count(n);
  count[0] = 0;
  FOR(i, 1, n){
    count[i] = count[i-1];
    if(s[i-1] == 'A' && s[i] == 'C') count[i]++;
  }
  vector<int> ans(q);
  REP(i, q){
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    ans[i] = count[r] - count[l];
  }
  REP(i, q) cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 1792
from collections import Counter as C;r=range(3)
def s():
	H,W,N,*L=map(int,open(0).read().split());D={};M=[(H-2)*(W-2)]+[0]*9
	for a,b in zip(*[iter(L)]*2):
		for x in r:
			for y in r:
				if H-1>a-y>0<b-x<W-1:
					t=(a-y)*W+b-x
					D[t]=D.get(t,0)+1
	for k,v in C(D.values()).items():M[0]-=v;M[k]+=v
	print(*M)
if __name__=="__main__":s()

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

int main(){
  string s;
  while(1){
    int pa = 0 ,pb = 0,i;
    cin >> s;
    if(s == "0")
      break;
    for(i=1;i<s.size();i++){
      if(s[i] == 'A'){
	pa++;
      } else {
	pb++;
      }
    }
    if(pa > pb){
      pa++;
    } else {
      pb++;
    }
    cout << pa << ' ' << pb << endl;
  }
  return 0;
}

Measured memory_bytes: 3024
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n-1){
    cin >> a.at(i);
  }
  int p[n+1]={0};
  rep(i,n-1){
    p[a.at(i)]++;
  }

  for(int i=1;i<=n;i++){
    cout << p[i] <<endl;
  }

}

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

int main()
{
   int k, x;

   cin >> k >> x;

   if(500 * k >= x) cout << "Yes" << endl;
   else cout << "No" << endl;
    
    return 0;
}

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

using namespace std;

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

    int l = n / 100;
    int r = n % 100;

    auto flagL = (l >= 1 && l <= 12);
    auto flagR = (r >= 1 && r <= 12);

    if (flagL and flagR) {
        cout << "AMBIGUOUS" << endl;
    } else if (flagL) {
        cout << "MMYY" << endl;
    } else if (flagR) {
        cout << "YYMM" << endl;
    } else {
        cout << "NA" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;


int a[200];
int n;
int num(int m){
  int cnt = 0;
  rrep(i,n)if(a[i] >= m-1)cnt++;
  return cnt;
}

// 75 = 3*5^2
signed main(){
  scanf("%lld", &n);
  rrep(i,n){
    int t = i;
    repi(j,2,n+1){
      while(t % j == 0){
        a[j]++;t /= j;
      }
    }
  }
  
  int ans = num(75) + num(25)*(num(3)-1) + num(15)*(num(5)-1) + num(5)*(num(5)-1)*(num(3)-2)/2;
  printf("%lld\n", ans);
  return 0;
}






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

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define all(v) (v).begin(), (v).end()
#define sz(v) (int) (v).size()

int main(int argc, char* argv[]) {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  map<string, int> mp;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    ++mp[s];
  }   
  cout << "AC x " << mp["AC"] << '\n';
  cout << "WA x " << mp["WA"] << '\n';
  cout << "TLE x " << mp["TLE"] << '\n';
  cout << "RE x " << mp["RE"] << '\n';
  return 0;
}

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

int main(){
	int N;
	cin >> N;
	long long L[N];
	for(int i = 0;i<N;i++){
		cin >> L[i];
	}
	int ans = 0;
	for(int i=0;i<N-2;i++){
		for(int j=i+1;j<N-1;j++){
			for(int k=j+1;k<N;k++){
				if(L[i] != L[j] && L[j] != L[k] && L[i] != L[k]){
					if(L[i] + L[j] > L[k]){
						if(L[j] + L[k] > L[i]){
							if(L[i] + L[k] > L[j])ans++;
						}
					}
				}
			}
		}
	}
	cout << ans <<endl;
}


Measured memory_bytes: 3632
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Spandan Mishra
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AWeLoveGolf solver = new AWeLoveGolf();
        solver.solve(1, in, out);
        out.close();
    }

    static class AWeLoveGolf {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int k = in.readInt();
            int a = in.readInt();
            int b = in.readInt();

            int q = (int) Math.ceil(a * 1.0 / k);
            if (k * q <= b)
                System.out.println("OK");
            else
                System.out.println("NG");

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new RuntimeException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new RuntimeException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



Measured memory_bytes: 32532
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    string s;
    cin>>s;
    int f=0;
    if(s[2]==s[3]&&s[4]==s[5])
    {
        f=1;
    }
    if(f==1)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int N, i, a=0, b=0, c=0, d=0;
  char str[100000][4];
  scanf("%d",&N);
  for(i = 0; i < N; i++)
    scanf("%s", str[i]);
  
  for(i = 0; i < N; i++){
    if (str[i][0] == 'A')
      a++;
    else if (str[i][0] == 'W')
      b++;
    else if (str[i][0] == 'T')
      c++;
    else if (str[i][0] == 'R')
      d++;
  }
  printf("AC x %d\n",a);
  printf("WA x %d\n",b);
  printf("TLE x %d\n",c);
  printf("RE x %d\n",d);
  
  return 0;
}

Measured memory_bytes: 2124
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	string S; cin >> S;
    S[3] = '8';
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int H,W,k,i;
	while(1){
		scanf("%d %d",&H,&W);
		if(H==0&&W==0){
			break;
		}
		else if((H+W)==1||(H==1&&W==1)){
			printf("#\n");
		}
		else{
			if(H==0){
				H++;
			}
			if(W==0){
				W++;
			}
			for(k=1;k<=H;k++){
				for(i=1;i<=W;i++){
					if(W==1||W==i){
						printf("#\n");
					}
					else if(i==1){
						printf("#");
					}
					else{
						if(k==1||k==H){
							printf("#");
						}
						else{
							printf(".");
						}
					}
				}
			}
		}
	printf("\n");
	}
return 0;
}

Measured memory_bytes: 588
# include <iostream>
# include <algorithm>

constexpr int MAX = (int)1e5 + 1;
using ll = long long int;

int n, m;
int p[MAX];
ll a[MAX], b[MAX], c[MAX];
ll cnt[MAX], cost[MAX];

int main() {
	std::cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		std::cin >> p[i];
		--p[i];
	}
	for (int i = 1; i < n; ++i)
		std::cin >> a[i] >> b[i] >> c[i];
	for (int i = 0; i < m - 1; ++i) {
		if (p[i] <= p[i + 1]) {
			++cnt[p[i] + 1];
			--cnt[p[i + 1] + 1];
		}
		else {
			++cnt[p[i + 1] + 1];
			--cnt[p[i] + 1];
		}
	}
	for (int i = 1; i < n; ++i)
		cnt[i] += cnt[i - 1];
	for (int i = 1; i < n; ++i)
		cost[i] = std::min(cnt[i] * b[i] + c[i], cnt[i] * a[i]);
	ll ans = 0;
	for (int i = 1; i < n; ++i)
		ans += cost[i];
	std::cout << ans << std::endl;
	return 0;
}

Measured memory_bytes: 7336
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define INF LLONG_MAX
#define PI 3.14159265359
#define sz(c) (int)c.size()
#define len(c) (int)c.length()
#define hcf(a, b) __gcd(a, b)
#define all(c) c.begin(), c.end()
#define vint vector<int>
#define vll vector<ll>
#define vpint vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define tr(con, it) \
    for (auto it = con.begin(); it != con.end(); it++)
#define fr(it, a, b) \
    for (int it = (a); it < (b); it++)
#define present(con, ele) (con.find(ele) != con.end())
#define cpresent(con, ele) (find(all(con), ele) != con.end())
#define maximum(a, b, c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
#define minimum(a, b, c) (a < b ? (a < c ? a : c) : (b < c ? b : c))
typedef long long ll;
typedef long double lf;
typedef unsigned long long lu;
const ll mod = 1e9 + 7;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b, c, k, ans = 0;
    cin >> a >> b >> c >> k;
    if (k >= a)
    {
        k -= a;
        ans += a;
    }
    else
    {
        ans += k;
        k = 0;
    }
    if (k >= b)
    {
        k -= b;
    }
    else
    {
        k = 0;
    }
    if (k >= c)
    {
        k -= c;
        ans -= c;
    }
    else
    {
        ans -= k;
        k = 0;
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
 
template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
	out << '(' << p.first << ',' << p.second << ')';
	return out;
}
 
template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
	in >> p.first >> p.second;
	return in;
}
 
template <class T>
istream& operator >> (istream& in, vector<T> &v)
{
	for (T &x : v)
		in >> x;
	return in;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<vector<T>> &v)
{
	for (const vector<T> &x : v)
		out << x << '\n';
	return out;
}
 
template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
	for (const T &x : v)
		out << x << ' ';
	return out;
}
 
 
#define ll long long
#define lf long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef pair <ll,ll > ii;
typedef vector <ll> vi;
typedef vector <ii> vii;
typedef vector <bool> vb;
typedef vector <vector <ll> > vv;
typedef vector <vector <vector<ll> > > vvv;
typedef vector <string> vs;
typedef vector <lf> vf;
#define sz(x) (ll)(x).size()
#define tr1(x) cerr << #x << ": " << x << nl
#define tr2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << nl
#define tr3(x,y,z) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<nl
#define tr4(x,y,z,w) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#w<<": "<<w<<nl
#define trv(a) cerr<<#a<<": ";for(ll zz=0;zz<sz(a);zz++) cerr<<a[zz]<<" ";cerr<<nl
#define trset(s) cerr<<#s<<": ";for(auto &i:s) cerr<<i<<" ";cerr<<nl
#define epsilon 0.000000001L
#define inf 9999999999999999ll// ~ 10^16
#define nl endl
#define all(x) x.begin(), x.end()
#define r_all(x) x.rbegin(), x.rend()
#define fast()  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod 1000000007ll
#define modulo 998244353ll
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
 

int main() 
{
    fast();
    ll n;
    cin>>n;
    vi a(n);
    cin>>a;
    ll q;
    cin>>q;
    map <ll,ll> m;
    ll sum=0;
    for(ll i=0;i<n;i++)
    {
        m[a[i]]++;
        sum+=a[i];
    }
    while(q--)
    {
        ll b,c;
        cin>>b>>c;
        ll count=m[b];
        m[b]=0;
        m[c]+=count;
        sum-=count*b;
        sum+=count*c;
        cout<<sum<<nl;
    }
}


Measured memory_bytes: 9980
//g++ -std=c++14 test.cpp -o test.out
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6;
const LL mod = 1000000007ll;

int N;

vector<string> ans;

void add_string(string now,int ns){
	if(now.size()==N){
		ans.push_back(now);
		return;
	}
	string ret = now;
	for(int i=0;i<=ns;i++){
		add_string(now+char(i+'a'),max(ns,i+1));
	}
}

void solve(){
	add_string("a",1);
}
 
int main(){
	cin >> N;
 
	solve();

	for(int i=0;i<ans.size();i++) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 7796
#include <iostream>

using namespace std;

int main()
{
    int i,s=0,n,m,minn=10000;
    cin>>n>>m;
    int v[n+1];
    for(i=1;i<=n;i++)
    {
        cin>>v[i];
        s++;
        m-=v[i];
        if(v[i]<minn) minn=v[i];
    }
    s+=m/minn;
    cout<<s;
    return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/03/12.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//
//  
//

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
// const double PI=3.1415926535897932;

//#define __DBG__


void solve(void){
  
  int N;
  
  cin >> N;
  vector<int> A(N+1);  // 1-indexed
  vector<int> B(N);  // 1-indexed
  
  REP2(i,1,N){
  	cin >> B[i];
  }
  
  A[1]=B[1];
  
  REP2(i,2,N){
  	A[i]=min(B[i-1],B[i]);
  } 
  
  A[N]=B[N-1];

  int ans=0;
  
  REP2(i,1,N+1){    
    ans += A[i];
  }
  
  cout << ans << endl;

  return;
   
}


int main(int argc, const char * argv[]) {

    cin.tie(0);
    ios::sync_with_stdio(false);

    solve();
 
    return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

int N;
vector<VI>G;
VI ans;

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


	cin >> N;
	G.resize(N);
	ans.resize(N);

	REP(i, N - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	queue<int>Q;
	Q.push(0);
	VI kai(N, -1);
	kai[0] = 0;

	vector<VI>dan(2);
	dan[0].push_back(0);

	while (!Q.empty()) {
		int now = Q.front();
		Q.pop();
		int cnt = kai[now];
		fore(to, G[now]) {
			if (kai[to] != -1)continue;
			else {
				kai[to] = cnt + 1;
				dan[kai[to] % 2].push_back(to);
				Q.push(to);
			}
		}
	}
	
	int a0 = N, a1 = N, a2 = N;

	while (a0 % 3 != 0)a0++;
	if (a0 > N)a0 -= 3;
	while (a1 % 3 != 1)a1++;
	if (a1 > N)a1 -= 3;
	while (a2 % 3 != 2)a2++;
	if (a2 > N)a2 -= 3;

	if (dan[0].size() <= a0 / 3) {
		fore(i, dan[0]) {
			ans[i] = a0;
			a0 -= 3;
		}
		fore(i, dan[1]) {
			if (a0 > 0) {
				ans[i] = a0;
				a0 -= 3;
			}
			else if (a1 > 0) {
				ans[i] = a1;
				a1 -= 3;
			}
			else {
				ans[i] = a2;
				a2 -= 3;
			}
		}
	}
	else if (dan[1].size() <= a0 / 3) {
		fore(i, dan[1]) {
			ans[i] = a0;
			a0 -= 3;
		}
		fore(i, dan[0]) {
			if (a0 > 0) {
				ans[i] = a0;
				a0 -= 3;
			}
			else if (a1 > 0) {
				ans[i] = a1;
				a1 -= 3;
			}
			else {
				ans[i] = a2;
				a2 -= 3;
			}
		}
	}
	else {
		fore(i, dan[1]) {
			if(a1>0){
				ans[i] = a1;
				a1 -= 3;
			}
			else {
				ans[i] = a0;
				a0 -= 3;
			}
		}
		fore(i, dan[0]) {
			if (a2 > 0) {
				ans[i] = a2;
				a2 -= 3;
			}
			else {
				ans[i] = a0;
				a0 -= 3;
			}
		}
	}





	REP(i, N)cout << ans[i] << " ";
	cout << endl;
	return 0;
}

Measured memory_bytes: 20456
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstdlib>
#include <istream>
#include <set>
#define rep0(i,n) for (long long int i = 0; i <= (n); ++i)
#define rep1(i,n) for (long long int i = 1; i <= (n); ++i)
#define REP(a,b) for (long long int i = a; i <= (b); ++i) 
#define MOD 100000007
#define ps push_back 
using namespace std;
typedef long long ll;
int main() {
	string s;
	cin >> s;
	map<char, int>a;
	int sizee = s.length() - 1; 
	rep0(i, sizee) {
		a[s[i]]++;
	}
	for (auto& k : a) {
		if (k.second != 1) {
			cout << "no" << endl;
			return 0;
		}
	}
	cout << "yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <map>
#include <list>
#include <stack>
#define lar(a, b) ((a>b) ? (a):(b))
#define sml(a, b) ((a<b) ? (a):(b))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> p;

int main(void) {
    ll n, m;
    vector<ll> v1, v2;
    cin >> n >> m;
    ll i, a[n], b[n];
    for(i=0; i<m; i++) {
        cin >> a[i] >> b[i];
    }
    
    for(i=0; i<m; i++) {
        if(a[i]==1)
            v1.push_back(b[i]);
        if(b[i]==n)
            v2.push_back(a[i]);
    }
    
    sort(v2.begin(), v2.end());
    
    for(i=0; i<v1.size(); i++) {
        if(binary_search(v2.begin(), v2.end(), v1[i])) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
    
}


Measured memory_bytes: 5084
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
int a;
cin >> a;
if(a== 3 || a == 5 || a == 7){
  cout << "YES";
}
  else{
    cout << "NO";
  }
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N,T,ans;
  cin >> N;
  vector<long long> A(N);
  T=ans=0;
  for (int i=0;i<N;i++) {
    cin >> A.at(i);
	T+=A.at(i);
  }
  for (int i=0;i<N;i++) {
    ans+=A.at(i)*(T-A.at(i));
  }
  cout << ans/2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;
bool isvalid(vector<int>& vec, int k, int p){
    int idx = 0;
    for(int i = 0; i < k; ++i){
        int w = 0;
        while(idx < int(vec.size())){
            if(vec[idx]+w <= p){
                w += vec[idx];
                ++idx;
            } else {
                break;
            }
        }

    }
    if(idx == int(vec.size())){
        return true;
    }
    return false;
}

int lower_bound(vector<int>& vec, int l, int h, int k){
    if(h-l <= 1){
        return h;
    }
    int mid = (h+l)/2;
    if(isvalid(vec, k, mid)){
        return lower_bound(vec, l, mid, k);
    } else {
        return lower_bound(vec, mid, h, k);
    }
}

int main(){
    int n, k;
    cin >> n >> k;
    auto vec = vector<int>();
    for(int i = 0; i < n; ++i){
        int temp;
        cin >> temp;
        vec.push_back(temp);
    }
    cout << lower_bound(vec, 0, 1000000000, k) << '\n';
}

Measured memory_bytes: 1676
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define tez ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll dp[101][100001];
 
 
ll solve(ll n,ll v,ll wt[],ll val[])
{
     if(v==0)return 0;
     if(n<0)return INT_MAX;
     if(v<0)return INT_MAX;
    // if(n==0)return INT_MAX;
     if(dp[n][v]!=-1)
     return dp[n][v];
     return dp[n][v]=min(solve(n-1,v,wt,val),solve(n-1,v-val[n],wt,val)+wt[n]);
     
}
int main()
{
     tez;
     ll n,w;
     cin>>n>>w;
     ll wt[n],val[n];
     for(ll i=0;i<101;i++)
     {
          for(ll j=0;j<100001;j++)
          {
               dp[i][j]={-1};
          }
     }
     for(ll i=0;i<n;i++)
     {
          cin>>wt[i]>>val[i];
     }
     ll v;
     for( v=100000;v>=0;v--)
     {
      //    cout<<v<<"\n";
          ll ans=solve(n-1,v,wt,val);
          if(ans<=w)
          {
               break;
          }
     }
     cout<<v<<"\n";
     
}

Measured memory_bytes: 79232
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A[3][3];
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> A[i][j];
    }
  }
  int N;
  cin >> N;
  int b[N];
  for(int i=0;i<N;i++){
    cin >> b[i];
  }
  for(int i=0;i<N;i++){
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(A[j][k]==b[i]){
          A[j][k]=-1;
        }
      }
    }
  }
  int ans=1;
  for(int i=0;i<3;i++){
    int check=0;
    for(int j=0;j<3;j++){
      if(A[i][j]!=-1) check=1;
    }
    if(check==0) ans=0;
  }

  for(int i=0;i<3;i++){
    int check=0;
    for(int j=0;j<3;j++){
      if(A[j][i]!=-1) check=1;
    }
    if(check==0) ans=0;
  }

  if(A[0][0]==-1 && A[1][1]==-1 && A[2][2]==-1) ans =0;
  if(A[0][2]==-1 && A[1][1]==-1 && A[2][0]==-1) ans =0;

  if(ans == 0) cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 256