akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int w,h,n;
	cin >> w >> h >> n;

	vector<vector<bool>> grid(h,vector<bool>(w,false));

	for(int i = 0;i < n;i++){
		int x,y,a;
		cin >> x >> y >> a;
		for(int j = 0;j < h;j++){
			for(int k = 0;k < w;k++){
				if(a == 1 && k < x){
					grid[j][k] = true;
				}
				if(a == 2 && k >= x)grid[j][k] = true;
				if(a == 3 && j < y){
					grid[j][k] = true;
				}
				if(a == 4 && j >= y){
					grid[j][k] = true;
				}
			}
		}
	}

	int cnt = 0;
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			if(!grid[i][j])cnt++;
		}
	}

	cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	int n;
	scanf("%d",&n);
	printf("%s\n",(n%10==9 || (n/10)%10==9)?"Yes":"No");
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    /* チェックリスト
     * 結果はintの範囲を超えていませんか？(必要な時以外はlongを使いましょう)
     * TLEしそうな処理はありませんか？
     */
    public static void main(String args[]){
        Scanner s = new Scanner(System.in);
        int a = Integer.parseInt(s.nextLine());
        String[] sa = s.nextLine().split(" ");
        List<Float> list = new ArrayList<Float>();
        for(String in : sa){
            list.add(Float.valueOf(in));
        }
        for(int i = 0;i < a - 1;i++){
            Collections.sort(list);
            float x = list.get(0);
            float y = list.get(1);
            list.remove(0);
            list.remove(0);
            list.add((x+y)/2);
        }
        System.out.println(list.get(0));
    }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
int main()
{

    int a,b,c,i,d;
    cin>>a>>b;
    c=a<=b?a:b;
    d=a>=b?a:b;
    for(i=0;i<d;i++) cout<<c;
    cout<<endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())

count = 0
count2 = 0

for a in range(2, n + 1):
    if n > a ** 2:
        count += 1
        if n % a == 0:
            count += 2 * ((n // a) - a - 1)
        else:
            count += 2 * (n // a - a)
    else:
        break
print(count+1+2*(n-2))


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

using namespace std;


bool isMirror(string const& str){
  return equal(str.begin(), str.begin()+str.size()/2,
    str.rbegin(), str.rbegin()+str.size()/2);
}

int main(){
  string str;
  cin >> str;
  
  // xを無視した文字列でミラーになってないと不可能
  string xRemovedStr = str;
  xRemovedStr.erase(remove(xRemovedStr.begin(), xRemovedStr.end(), 'x'), xRemovedStr.end());

  bool const xrMirror = isMirror(xRemovedStr);
  if(!xrMirror){
    cout << "-1" << endl;
    return 0;
  }
  
  
  // xなしでミラーになっている → xを挿入していく
  int count=0;
  int ptrA=0, ptrB=str.size()-1;
  while(ptrA<ptrB){
    if(str[ptrA]!=str[ptrB]){
      if(str[ptrA] == 'x'){ ptrA++; }else{ ptrB--; }
      count++;
    }else{
      ptrA++; ptrB--;
    }
  }
  
  cout << count;
  
  
  
  
  return 0;
}

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

int main(){
  string s;
  cin >> s;
  
  int n = 0;
  for (int i=0 ; i<4 ; i++){
    for (int j=0 ; j<4 ; j++){
      if (s.at(i) == s.at(j))
        n++;
    }
  }
  
  if (n == 8)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3596
import itertools

def ch(l,r):
    t=itertools.combinations(l,2)
    for i in t:
        if i[0]**2+i[1]**2<4*r**2:
            return True
    return False

while 1:
    l=list(map(int,input().split()))
    if l[0]==0 and l[1]==0 and l[2]==0:break
    o=[ch(l,int(input())) for i in range(int(input()))] 
    [print("OK") if i else print("NA") for i in o]


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

#define ll long long
#define mii make_pair<int, int>
#define mll make_pair<ll, ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define all(v) (v).begin(), (v).end()

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

    string s,s2;
    int k;
    cin >> k >> s;
    if (s.size() >k)
        s2 = string(s.begin(), s.begin() + k) + "...";
    else
        s2 = s;
    cout << s2;
}

Measured memory_bytes: 3652
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int []array=new int[N];
        for(int i=0;i<N;i++)array[i]=sc.nextInt();
        int num=0;
        for(int i=N;i>=1;i--){
            for(int j=0;j<i-1;j++){
                if(array[j+1]<array[j]){
                    int tmp=array[j];
                    array[j]=array[j+1];
                    array[j+1]=tmp;
                    num++;
                }
            }
        }
        for(int i=0;i<N;i++){
            System.out.print(array[i]);
            if(i<N-1)System.out.print(" ");
        }
        System.out.println();
        System.out.println(num);

        
    }
}


Measured memory_bytes: 26404
#include <cstdio>
#include <cctype>
#include <utility>
#include <vector>
#include <queue>
#include <functional>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;while(isspace(c)){c=gcu();}if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m?-n:n;}
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

using V = vector<int>;
using VV = vector<V>;
struct P {int x, y;};

int main() {
	int dx[] = {4, 2}, dy[] = {2, 4};
	for (int w, h; w = in(), h = in();) {
		P s = {in() - 1, in() - 1}, g = {in() - 1, in() - 1};
		int n = in();
		VV m(h, V(w));
		while (n--) {
			int c = in(), d = in(), x = in() - 1, y = in() - 1;
			for (int i = 0; i < dy[d]; i++)
				for (int j = 0; j < dx[d]; j++)
					m[i + y][j + x] = c;
		}
		int c = m[s.y][s.x];
		m[s.y][s.x] = 0;
		function<bool(int, int)> f = [&](int x, int y) {
			if (x == g.x && y == g.y)
				return true;
			P d = {1, 0};
			for (int i = 0; i < 4; i++) {
				int tx = x + d.x, ty = y + d.y;
				if (tx >= 0 && ty >= 0 && tx < w && ty < h && m[ty][tx] == c) {
					m[ty][tx] = 0;
					if (f(tx, ty))
						return true;
				}
				swap(d.x, d.y *= -1);
			}
			return false;
		};
		outl(c ? f(s.x, s.y) ? "OK" : "NG" : "NG");
	}
}


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

int main() {
    rep(i,5){
        int x; cin >> x;
        if(x == 0) cout << i+1 << endl;
    }
}


Measured memory_bytes: 3592
#include<cstdio>
#include<cstring>
const int MaxN=100;

char s[MaxN+5];

int main(){
	bool havC=false,havF=false;
    scanf("%s",s);
    int ls=strlen(s);
    for(int i=0;i<ls;i++){
        if(s[i]=='C') havC=1;
        if(s[i]=='F'&&havC){havF=1;break;}
    }
    printf(havF?"Yes\n":"No\n");
    return 0;
}

Measured memory_bytes: 128
N, X = map(int, input().split())
x = list(map(lambda i: abs(int(i) - X), input().split()))

x_min = min(x)

for i in range(x_min, 0, -1):
    cnt = 0
    for j in x:
        if j % i != 0:
            break
        else:
            cnt += 1
    if cnt == N:
        print(i)
        exit()

Measured memory_bytes: 62832
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var n = cin.nextInt();
            var s = cin.next();

            var ans = 0;
            var ss = s.ToCharArray();
            var before = ' ';
            for (int i = 0; i < s.Length; i++)
            {
                if(before == ss[i])
                {

                }
                else
                {
                    ans++;
                }
                before = ss[i];
            }

            Console.WriteLine(ans);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N+ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }   

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 13216
import java.util.*;

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

        int N = sc.nextInt();
        
        String[] s = new String[N];
        
        for(int i = 0; i < N; i++) {
            s[i] = sc.next();
        }
        int M = sc.nextInt();
        String[] t = new String[M];
        for(int i = 0; i < M; i++) {
            t[i] = sc.next();
        }

        int count = 0;
        for(int i = 0; i < N; i++) {
            int a = 0;
            int b = 0;
            for(int j = 0; j < N; j++) {
                if(s[j].equals(s[i])) a++;
            }
            for(int j = 0; j < M; j++) {
                if(t[j].equals(s[i])) b++;
            }
            count = Math.max(count, a - b);
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 21716
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

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

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int n = fs.nextInt();
		
		int worstNumRank = 0;
		int worstScore = 1_000_000_007;
		
		for(int i = 0; i < n; i++) {
			int a = fs.nextInt();
			int b = fs.nextInt();
			
			worstNumRank = Math.max(worstNumRank, a);
			worstScore = Math.min(worstScore, b);
		}
		
		while(worstScore > 0) {
			worstNumRank++;
			worstScore--;
		}
		
		System.out.println(worstNumRank);
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

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

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

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

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

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

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

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

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

}


Measured memory_bytes: 54364
import java.io.*;
import java.util.*;

public class Main{
    public static void main(String[] args)throws Exception{
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt(),m=sc.nextInt();
        boolean[] aw=new boolean[n];
        int[] ary=new int[n];
        int ac_c=0,wa_c=0;
        Arrays.fill(aw,false);
        Arrays.fill(ary,0);
        for(int i=0;i<m;i++){
            int p=sc.nextInt();
            String s=sc.next();
            if(s.equals("AC")){
                if(!aw[p-1]){
                    ac_c++;
                }
                aw[p-1]=true;
            }
            if(s.equals("WA")&&!aw[p-1]){
                ary[p-1]++;
            }
        }
        for(int i=0;i<n;i++){
            if(aw[i]){
                wa_c+=ary[i];
            }
        }
        System.out.println(ac_c +" "+ wa_c);
    }
}

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

int main(){
  int n,x;
  cin >> n >> x;
  vector<int> l(n);
  
  for(int i=0;i<n;i++){
    cin >> l.at(i);
  }
  int c=1,sum=0;
  
  for(int i=0;i<n;i++){
   sum+=l.at(i);
    if(x>=sum) c++;
  }
  
  cout << c <<endl;
  return 0;
}
 

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

int main() {
  int A, B, N;
  cin >> A >> B;
  int C = 0;
    
  for (int i = A; i <= B; i++){
    N = i;
    
    int n10000 = N / 10000;
    int n1000 = (N - n10000 * 10000) / 1000;
    int n100 = (N - n10000 * 10000 - n1000 * 1000) / 100;
    int n10 = (N - n10000 * 10000 - n1000 * 1000 - n100 * 100) / 10;
    int n1 = N - n10000 * 10000 - n1000 * 1000 - n100 * 100 - n10 * 10;

    if ((n10000 == n1) && (n1000 == n10)){
      C +=1;
    }
  }
  cout << C << endl;
}



Measured memory_bytes: 256
n = int(input())

#cake   : 4 dollar
#donuts : 7 dollar

cnt = "No"

if n % 4 == 0:
  cnt = "Yes"
  
if n % 7 == 0:
  cnt = "Yes"
  
# 7 * 14 = 98
for i in range(1,14):
  if( 7 * i > n ):
    break
  else:
    if( (n-7*i) % 4 == 0):
      cnt = "Yes"
      break
      
print(cnt)

Measured memory_bytes: 3060
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func main() {
	solve(NewScanner())
}

func solve(s *Scanner) {
	wtr := bufio.NewWriter(os.Stdout)
	N, Y := s.nextInt(), s.nextInt()

	for i := 0; i <= N; i++ {
		for j := 0; j <= N; j++ {
			k := N - i - j
			if k < 0 {
				break
			}
			if Y == i*10000+j*5000+1000*k {
				fmt.Fprintln(wtr, i, j, k)
				wtr.Flush()
				return
			}
		}
	}

	fmt.Fprintln(wtr, "-1 -1 -1")
	wtr.Flush()
}


Measured memory_bytes: 640
N = int(input())
P = list(map(lambda x: int(x),input().split()))
Q = list(map(lambda x: int(x),input().split()))

def fact(n):
  if n==1 or n==0:
    return 1
  return n*fact(n-1)

def idx(lst):
  ans=0
  res = list(range(1,N+1))
  for i in range(N):
    #print(res)
    order = res.index(lst[i])
    #print(order)
    ans += fact(len(res)-1)*order
    #print(ans)
    res.remove(lst[i])
    #print(ans)
  return ans

#print(idx(P))
print(abs(idx(P)-idx(Q)))

Measured memory_bytes: 3064
#include <iostream>
#include <string>

using namespace std;

int main(){

    string S;
    cin >> S;

    int A, Z;
    bool f = true;
    
    for (int i = 0; i < S.length(); i++){
        if (S[i] == 'A' && f == true){
            A = i;
            f = false;
        }
        if (S[i] == 'Z'){
            Z = i;
        }
    }
    
    cout << Z - A + 1 << endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long

int main()
{
    ll temp;
    cin>>temp;
    if(temp&1)
    {
        cout<<0<<endl;
    }
    else
    {
        ll answer=0;

        for(ll i=50;;i*=5)
        {
            ll x=temp/i;
            if(x==0)
                break;
            answer+=x;
        }
        cout<<(answer+temp/10)<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
int i,j,l,r;
string a;
cin>>a;
for(i=0;i<a.size();i++)
if(a[i]=='A') { l=i; break;}
for(j=a.size()-1;j>0;j--)
if(a[j]=='Z') {r=j; break;}
cout<<r-l+1<<endl;
return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void recDelIsland(boolean[][] map, int i, int j){
		map[i][j] = false;
		for(int di = -1; di <= 1; di++){
			for(int dj = -1; dj <= 1; dj++){
				if((di != 0 || dj != 0) &&
					di + i >= 0 && di + i < map.length &&
					dj + j >= 0 && dj + j < map[0].length &&
					map[di + i][dj + j]){
					recDelIsland(map, di + i, dj + j);
				}
			}
		}
	}
	public static int getNumOfIslands(boolean[][] map){
		int result = 0;
		for(int i = 0; i < map.length; i++){
			for(int j = 0; j < map[0].length; j++){
				if(map[i][j]){
					result++;
					recDelIsland(map, i, j);
				}
			}
		}
		return result;
	}
	public static void main(String[] args){
		Scanner scn = new Scanner(System.in);
		int w, h;
		w = scn.nextInt();
		h = scn.nextInt();
		while(w != 0 || h != 0){
			boolean[][] map = new boolean[h][w];
			for(int i = 0; i < h; i++)	for(int j = 0; j < w; j++)	map[i][j] = (scn.nextInt() == 1);
			System.out.println(getNumOfIslands(map));
			w = scn.nextInt();
			h = scn.nextInt();
		}
	}
}

Measured memory_bytes: 43096
import sys
input=sys.stdin.readline
n=int(input())
a=tuple(map(int,input().split()))
mod=10**9+7
cnt=[0]*60

for temp in a:
    if temp==0:continue
    digit=len(bin(temp))-2
    for j in range(digit):
        if (temp>>j)&1:
            cnt[j]=cnt[j]+1

#print(cnt)
ans=0
for i in range(60):
    if cnt[i]==0:continue
    ans=(ans+pow(2,i)*cnt[i]*(n-cnt[i]))%mod
print(ans%mod)


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

int main() {
  int n;
  cin >> n;
  long int mod = 1000000007;

  long long p = 1;
  for (int i = 1; i <= n; i++) {
    p = (p * i) % mod;
  }

  cout << p << endl;
}

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

const int N = 101010;

struct Node {
  int v, d, c;
};

vector<Node> tmp;
int col[N], n, m, Q, dep[N];
vector<int> g[N];

void Color(int v, int d, int c) {
  if(col[v] && dep[v] >= d) return;
  queue<pair<int, int> > q;
  q.push(make_pair(v, d));
  dep[v] = d;
  if(!col[v]) col[v] = c;
  while(!q.empty()) {
    pair<int, int> now = q.front(); q.pop();
    int u = now.first, w = now.second;
    if(!w) break;
    for(int i = 0; i < g[u].size(); i++) {
      int to = g[u][i];
      if(col[to] && dep[to] >= w - 1) continue;
      if(!col[to]) col[to] = c;
      dep[to] = w - 1;
      q.push(make_pair(to, w - 1));
    }
  }
}

int main(void) {
  scanf("%d%d", &n, &m);
  for(int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  scanf("%d", &Q);
  for(int i = 1; i <= Q; i++) {
    int v, d, c;
    scanf("%d%d%d", &v, &d, &c);
    tmp.push_back((Node){v, d, c});
  }
  for(int i = Q - 1; i >= 0; i--) {
    Node now = tmp[i];
    Color(now.v, now.d, now.c);
  }
  for(int i = 1; i <= n; i++)
    printf("%d\n", col[i]);
  return 0;
}


Measured memory_bytes: 9328
package main

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

func main() {
	s := sequenceGets()

	m := make(map[rune]int64, 26)
	for r := rune('a'); r <= 'z'; r++ {
		m[r] = 0
	}

	for _, v := range s {
		for _, v2 := range v {
			w := unicode.ToLower(v2)
			if w < 'a' || w > 'z' {
				continue
			}
			m[w] = m[w] + 1
		}
	}

	for r := rune('a'); r <= 'z'; r++ {
		fmt.Printf("%s : %d\n", string(r), m[r])
	}
}

func sequenceGets() (lines []string) {
	scanner := bufio.NewScanner(os.Stdin)

	for scanner.Scan() {
		str := scanner.Text()
		if str == "" {
			break
		}
		lines = append(lines, str)
	}

	return
}



Measured memory_bytes: 1092
#include <iostream>
using namespace std;
int main( void )
{
	int L;
	while ( cin >> L && L )
	{
		int kotae = 0;
		int now = 0;
		int M, N;
		for ( int i = 0; i < 12; i++ )
		{
			cin >> M >> N;

			now += M - N;
			if ( kotae == 0 && now >= L )
			{
				kotae = i + 1;
			}
		}

		if ( kotae )
			cout << kotae << endl;
		else
			cout << "NA" << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1000000007;
const long long INF = 1LL << 60;
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s; cin >> s;
    rep(i,3) {
        if(s[i] == s[i+1]){
            cout << "Bad" << endl;
            return 0;    
        }
    }
    cout << "Good" << endl;

    return 0;
}

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

#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, a, b) for(int i=a;i<int(b);i++)
#define FORS(i, a, b, s) for(int i=a;(s>0&&i<int(b))||(s<0&&i>int(b));i+=s)

using namespace std;


int X[1000000];
int main() {
  
  int N, T, A;
//  int X[N];
  
  cin >> N >> T >> A;
  REP(i,N){
    cin >> X[i];
  }
  
  int m = 999999999;
  int mi = -1;
  REP(i,N){
    if(abs(T*1000-6*X[i]-A*1000)<m){
      mi = i;
      m = abs(T*1000-6*X[i]-A*1000);
    }
  }
  
  printf("%d\n", mi+1);
  return 0;
}





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

struct ques
{
    int ac;
    int wa;
}a[100500];

int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        memset(a,0,sizeof(a));
        int i;
        for(i=0;i<m;i++)
        {
            char ok[5];
            int t;
            scanf("%d %s",&t,ok);
            if(ok[0]=='W'&&a[t].ac!=1)
                a[t].wa++;
            else
                a[t].ac=1;
        }
        int numA=0,numW=0;
        for(i=0;i<=n;i++)
        {
            numA+=a[i].ac;
            if(a[i].ac)
            numW+=a[i].wa;
        }
        printf("%d %d\n",numA,numW);
    }
    return 0;
}



Measured memory_bytes: 1024
//ditmeatcoder
#include<bits/stdc++.h>
using namespace std;
int dx[9]={-1,-1,-1,0,0,0,1,1,1};
int dy[9]={-1,0,1,-1,0,1,-1,0,1};
	map<pair<int,int>,int> cnt;
	long long H,W,N,a,b,p,q;
	long long ditmedevc[11];
int main (){

	cin>>H>>W>>N;
	ditmedevc[0]=(H-2)*(W-2);
  while(N--){
  	cin>>a>>b;
      for(int i=0;i<9;i++){
      	p=a+dx[i];
      	q=b+dy[i];
      	if(p>1&&p<=H-1&&q>1&&q<=W-1){
      		cnt[{p,q}]++;
      		ditmedevc[cnt[{p,q}]-1]--;
      		ditmedevc[cnt[{p,q}]]++;
		  }
	  } 
  }
   for(int i=0;i<10;i++){
	  	cout<<ditmedevc[i]<<endl;
	  }
}

Measured memory_bytes: 56448
n=input()
l=list(map(int,input().split()))
n=int(input())
for i in range(n):
    b,m,e=map(int,input().split())
    l1=l[b:e]
    l1=l1[m-e:]+l1[:m-e]
    l[b:e]=l1
l=map(str,l)
print(' '.join(map(str,l)))


Measured memory_bytes: 5628
def g(n):
    c = 0
    while n > 0:
        p = 0
        n2 = n
        while n2 > 0:
            if n2%2 == 1:
                p += 1

            n2 //= 2

        n %= p
        c += 1

    return c


def modPow(a, b, mod):
    x = 1
    
    while b > 0:
        if b & 1:
            x = (x*a)%mod

        a = (a**2)%mod
        b //= 2

    return x


# def h(b, m):
#     x = 1
#     for _ in range(b):
#         x = x*2%m

#     return x


def f(N, X):
    b = sum(1 if x == '1' else 0 for x in X)

    Xplus = 0
    Xminus = 0

    for x in X:
        Xplus = (Xplus*2 + (1 if x == '1' else 0))%(b+1)
        
        if b > 1:
            Xminus = (Xminus*2 + (1 if x == '1' else 0))%(b-1)

    for i in range(N):
        if X[i] == '0':
#            X2 = (Xplus + h(N-i-1, b+1))%(b+1)
            X2 = (Xplus + modPow(2, N-i-1, b+1))%(b+1)
            print(g(X2) + 1)
        elif b > 1:
#            X2 = (Xminus - h(N-i-1, b-1))%(b-1)
            X2 = (Xminus - modPow(2, N-i-1, b-1))%(b-1)
            print(g(X2) + 1)
        else:
            print(0)


N = int(input())
X = input()
f(N, X)



Measured memory_bytes: 9424
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define ll_MAX LONG_LONG_MAX
#define ll_MIN LONG_LONG_MIN
#define pi pair<int,int>
#define endl "\n"
#define MAXN 100005
#define mod 1000000007
using namespace std;

void solve()
{
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    solve();
    ll a,b,c;
    cin>>a>>b>>c;
    ll k;
    cin>>k;
    // ll p = 0;
    while (k)
    {
        /* code */
        if(b<=a)
        {
            b = 2*b;
            k--;
        }
        else if(c <= b)
        {
            c = c*2;
            k--;
        }
        else if(b>a && c>b)
        {
            break;
        }
    }
    if(b>a && c>b)
    {
        cout<<"Yes"<<'\n';
    }
    else
    {
        cout<<"No"<<'\n';
    }
    
}

Measured memory_bytes: 3668
#include<stdio.h>
#include<string.h>
int main()
{
    char str[100],str2[100];
    scanf("%s",str);
    int len=strlen(str),i,j,count=0,count2=0;
    for(i=0,j=len-1;i<len,j>=0;i++,j--)
    {
        if(str[i]!=str[j])
        {
            count++;
            break;
        }
    }
    if(len%2!=0 && count==0)
        {
            int dummy1=0,dummy2=0;
            dummy1=(len-1)/2;
            dummy2=(len+3)/2;

            for(i=0,j=dummy1-1;i<dummy1,j>=0;i++,j--)
            {
                if(str[i]!=str[j])
                {
                    count2++;
                    break;
                }
            }
            for(i=dummy2-1,j=len-1;i<len,j>=dummy2-1;i++,j--)
            {
                if(str[i]!=str[j])
                {
                    count2++;
                    break;
                }
            }

            if(count2==0)
            {
                printf("Yes\n");
            }
            else
            {
                printf("No\n");
            }

     }
    else
    {
        printf("No\n");
    }
   return 0;
}

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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	int n;
	vector<vector<llong> > a;

	cin >> n;
	a.resize(n, vector<llong>(2));
	for(int i = 0; i < n; i++){
		cin >> a[i][0];
		a[i][1] = a[i][0];
	}

	int w[2] = {0,1};
	llong ans = inf;
	for(int i = 0; i < 2; i++){
		llong sum = 0;
		llong res = 0;
		for(int j = 0; j < n; j++){
			llong next = sum + a[j][i];
			if(w[i]^(j&1)){
				// 正にしたい
				if(next <= 0){
					a[j][i]++;
					res += -next + 1;
					a[j][i] += -next;
				}
			}else{
				if(next >= 0){
					a[j][i]--;
					res += next + 1;
					a[j][i] += -next;
				}
				// 負にしたい
			}

			sum += a[j][i];
		}

		ans = min(ans, res);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 5760
#include<iostream>
#include<iomanip>
#include<cstdio>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
const ll INF = 1e9+1;

//Ai+Ai+1が負なら作用時結果が好転する
//全部に実施すると一番端だけ反転する
//偶数の場合まんべんなく実施すると全て反転する

//マイナスの数を端点として、中身が正の数の区間を一連の操作ですべてせいにすることができる
//したがって、マイナスのものは偶数個までなら全て反転することができる
//奇数個の時、絶対値最小のものだけ諦める

int main() {
    
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    ll cnt = 0;
    ll zerocnt = 0;
    ll minabs = INF;
    ll res = 0;
    for (int i = 0; i < N; i++) {
        chmin(minabs,abs(A[i]));
        res += abs(A[i]);
        if (A[i] < 0) {
            cnt++;
        }
        if (A[i] == 0) zerocnt++;
    }

    if (cnt % 2 == 1) {
        res -= 2 * minabs;
    }
    cout << res << endl;
    

}



Measured memory_bytes: 1024
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0; i<n; i++) a[i] = sc.nextInt();
        int[] front = new int[n+1];
        int[] end = new int[n+1];

        for(int i = 1; i<n+1; i++) {
            front[i] = Math.max(front[i-1],a[i-1]);
            //System.out.println(front[i]);
        }
        for(int i = n-1; i>=0; i--) {
            end[i] = Math.max(end[i+1],a[i]);
            //System.out.println(end[i]);
        }

        for(int i = 0; i<n; i++) {
            //System.out.println(front[i] +" " + end[i+1]);
            System.out.println(Math.max(front[i], end[i+1]));
        }
    }
}

Measured memory_bytes: 91944
import java.util.Scanner;

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

        sc.close();

        int sum = a + b;

        if (a % 3 == 0 || b % 3 == 0 || sum % 3 == 0) {
            System.out.println("Possible");
        } else {
            System.out.println("Impossible");
        }
    }
}

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

int main(){
  bool is_prime[50001];

  is_prime[0]=is_prime[1]=false;
  for(int i=2;i<50001;i++){
    is_prime[i] = true;
  }

  for(int i=2;i*i<50001;i++){
    if(is_prime[i]){
      for(int j=i*i;j<50001;j=j+i){
        is_prime[j] = false;
      }
    }
  }

  while(true){
    int n;
    cin >> n;

    int cnt=0;
    for(int i=2;i<=n/2;i++){
      if(is_prime[i] && is_prime[n-i]){
        cnt++;
      }
    }
    if(n==0)
        break;

    cout << cnt << endl;
  }

   return 0;
}



Measured memory_bytes: 3036
N, M = map(int, input().split())   
C = list(map(int, input().split()))

dp = [0] + [float('inf')] * N

for c in C:
    for i in range(N+1):
        if i >= c:
            dp[i] = min(dp[i], dp[i-c]+1)
print(dp[-1])




Measured memory_bytes: 7524
#include <bits/stdc++.h>
// it starts with your mind
using namespace std;
typedef long long ll;
#define len length

int main()
{
ios_base::sync_with_stdio(0);
 cin.tie(0); cout.tie(0);
int n;
cin >> n;
int arr[n];
for(int i =0 ; i < n; i++)
{
    cin >> arr[i];
}
sort(arr, arr + n );
reverse(arr , arr + n);
ll comfort = 0  ,cnt = 0 , i = 0;
while(n != 0)
{
  comfort += arr[i] ;
  n--;
 cnt ++;
 if(cnt == 2)
 {
     cnt = 0;
     i++;
 }
}

cout << comfort - arr[0];
return 0;
}




Measured memory_bytes: 4448
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
   cin >> N;
   if ((N - N % 1000) / 1000 == (N % 1000 - N % 100) / 100 && (N % 1000 - N % 100) / 100 == (N % 100 - N % 10 ) / 10 || (N % 1000 - N % 100) / 100 == (N % 100 - N % 10 ) / 10 && (N % 100 - N % 10 ) / 10 == N % 10 ) {
   cout << "Yes" << endl;
   }  
   else {
   cout << "No" << endl;
   }
}

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


int main() {
        int n, base; cin >> n >> base;
        int ans = 1e6;
        while(n--) {
                int x, t; cin >> x >> t;
                if( t <= base ) {
                        ans = min( ans, x);
                }
        }
        if(ans == 1e6)cout << "TLE" << endl;
        else cout << ans << endl;

        return 0;
}


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

int main(){
    //freopen("input.txt", "r", stdin);
    string s, t; cin >> s >> t;
    for(int i = 0; i < s.size(); i++){
        int flag = 1;
        for(int j = 0; j < s.size(); j++){
            if(t[j]!=s[(j + i)%s.size()]){
                flag = 0;
            }
        }
        if(flag){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
// beetに勝つ

#include <bits/stdc++.h>

using namespace std;

using int64 = long long;

int main() {
  int N, T, A, H[1000];
  cin >> N >> T >> A;
  double ans = 1e18;
  for(int i = 0; i < N; i++) {
    cin >> H[i];
    ans = min(ans, abs(A - (T - H[i] * 0.006)));
  }
  for(int i = 0; i < N; i++) {
    if(ans == abs(A - (T - H[i] * 0.006))) {
      cout << i + 1 << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

int main(){
	char str[27];
    int check[26];
	scanf(" %s", str);
    int i = 0;
    for(i = 0; i < 26; i++){
        check[i]=0;
    }
    i=0;
    while(str[i] != '\0'){
        if(check[(str[i] - 'a')] == 1){
            printf("no");
            return 0;
        }
        else{
            check[(str[i] - 'a')] = 1;
        }
        i++;
    }
    printf("yes");
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
#include <numeric>
#include <stack>
#include <queue>
#include <cassert>
#include <forward_list>
#include <chrono>
#include <deque>
#include <list>
#include <random>
#include <cstdio>
#include <sstream>
#include <tuple>

using namespace std;

//最大公約数
template<class T>
inline T GCD(T m, T n)
{
	T temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

//最小公倍数
template<class T>
inline T LCM(T m, T n)
{
	return m * n / GCD(m, n);
}

int main()
{
	int r; cin >> r;
	if (r < 1200)
	{
		cout << "ABC" << endl;
	}
	else if (r < 2800)
	{
		cout << "ARC" << endl;
	}
	else
	{
		cout << "AGC" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
# ワーシャルフロイド
def warshall_floyd(n, d):
    for i in range(n):
        for j in range(n):
            for k in range(n):
                d[j][k] = min(d[j][k], d[j][i] + d[i][k])


H, W = map(int, input().split())

N = 10
d = [None] * N
for i in range(N):
    d[i] = list(map(int, input().split()))
warshall_floyd(N, d)

m = [d[i][1] for i in range(N)]

result = 0
for _ in range(H):
    for i in map(int, input().split()):
        if i == -1:
            continue
        result += m[i]
print(result)


Measured memory_bytes: 3064
#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;
    cin>>n;
    vector<int>a(n+1),b(n);
    ll sum1=0,sum2=0;
    rep(i,n+1){
        cin>>a[i];
        sum1+=a[i];
    }
    rep(i,n){
        cin>>b[i];
    }
    ll ans=0;
    rep(i,n){
        if(a[i]-b[i]<0){
            a[i+1]-=b[i]-a[i];
            if(a[i+1]<0)a[i+1]=0;
            a[i]=0;
        }
        else{
            a[i]-=b[i];
        }
    }
    rep(i,n+1){
        sum2+=a[i];
    }
    cout<<sum1-sum2<<endl;
}


Measured memory_bytes: 1024
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn dev(a: i64, b: i64) -> i64 {
    (a + b - 1) / b
}

fn hit(hs: &Vec<i64>, a: i64, b: i64, t:i64) -> bool {
    let mut count = 0i64;
    for i in 0..hs.len() {
        if hs[i] < t * b {
            continue;
        }
        count += dev(hs[i] - t * b, a - b);
    }
    count <= t
}

fn main() {
    let v: Vec<i64> = read_vec();
    let (n, a, b) = (v[0], v[1], v[2]);
    let n = n as usize;
    let mut hs = vec![0i64; n];
    for i in 0..n {
        hs[i] = read();
    }
    hs.sort();

    let mut lb = 0;
    let mut ub = dev(hs[hs.len() - 1], b);
    while ub - lb > 1 {
        let mid = (ub + lb) / 2;
        if hit(&hs, a, b, mid) {
            ub = mid;
        } else {
            lb = mid;
        }
    }
    println!("{:?}", ub);
}


Measured memory_bytes: 4352
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		int c = stdIn.nextInt();
		int count = 0;
		for (int i=a; i<=b; i++) {
			if(c%i == 0)
				count++;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 17228
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007

long int combination(long int n, long int r);

//qsort用、昇順
int compare_int(const void *a, const void *b)
{
	return *(int*)a-*(int*)b;
}
//qsort(data, 10, sizeof(int), compare_int)

long int combination(long int n, long int r)
{
	if(r>n-r) r = n-r;
	if(r == 0) return 1;
	else if(r == 1) return n;
	return (combination(n-1, r) + combination(n-1, r-1));
	//大きくなるとき
	/*
	long int tmp1, tmp2, tmp3;
	tmp1 = combination(n-1, r);
	if(tmp1>=MOD) tmp1 = tmp1%MOD;
	tmp2 = combination(n-1, r-1);
	if(tmp2>=MOD) tmp2 = tmp2%MOD;
	tmp3 = tmp1+tmp2;
	if(tmp3>=MOD) tmp3 = tmp3%MOD;
	return (tmp3);
	*/
}


int main(){
	int n, m;
	scanf("%d%d", &n, &m);
	if(m==0){
		if(n==1) printf("0\n");
		else{
			int ans = pow(10, n-1);
			printf("%d\n", ans);
		}
	}
	else{
		int s[m], c[m];
		for(int i=0; i<m; i++){
			scanf("%d%d", &s[i], &c[i]);
		}
		int num[n+1];
		num[0] = 1;
		for(int i=1; i<=n; i++){
			num[i] = -1;
		}
		//printf("yey\n");

		for(int i=0; i<m; i++){
			if((num[s[i]] == -1) || (num[s[i]] == c[i])){
				num[s[i]] = c[i];
			}
			else{
				num[0] = -1; //printf("i:%d\n", i);
			}
		}

		//printf("year!\n");

		if(num[1]==0){
			if(n!=1) num[0] = -1;
		}
		if(num[1]==-1){
			if(n==1) num[1]=0;
			else num[1] = 1;
		}
		for(int i=2; i<=n; i++){
			if(num[i] == -1) num[i] = 0;
		}

		//printf("uui!\n");

		if(num[0]==1){
			int ans = 0;
			for(int i=1; i<=n; i++){
				ans = ans*10 + num[i];
			}
			printf("%d\n", ans);
		}
		else printf("-1\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)
#define print(x,n) for(int i_ = 0;i_ < n;i_++) printf("%lld%c",x[i_]," \n"[i_ == n - 1])

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T>
struct Edge{
	int from,to;
	T cost;
	Edge(int to,T cost) : to(to),cost(cost){}
	Edge(int from,int to,T cost) : from(from),to(to),cost(cost){}
};

template<class T>
using WeightedGraph = vector<vector<Edge<T>>>;
using Graph = vector<vector<int>>;
template<class T>
using Matrix = vector<vector<T>>;

const int INF = 1e+18;

template<class T>
void warshallFloyd(Matrix<T> &G){
	for(int k = 0;k < G.size();k++){
		for(int i = 0;i < G.size();i++){
			for(int j = 0;j < G.size();j++){
				if(G[i][k] == INF || G[k][j] == INF) continue;
				G[i][j] = min(G[i][j],G[i][k] + G[k][j]);
			}
		}
	}
}


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


template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 

signed main(){
	int h,w;
	string s[20];
	cin >> h >> w;
	Matrix<int> cost(h * w,vector<int>(h * w));
	for(int i = 0;i < h;i++) cin >> s[i];
	for(int i = 0;i < h * w;i++){
		for(int j = 0;j < h * w;j++) cost[i][j] = INF;
		cost[i][i] = 0;
	}
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			for(int k = 0;k < 4;k++){
				int x = i + dx[k],y = j + dy[k];
				if(isIn(x,y,h,w) && s[i][j] == '.' && s[x][y] == '.'){
					cost[i * w + j][x * w + y] = cost[x * w + y][i * w + j] = 1;
				}
			}
		}
	}
	warshallFloyd(cost);
	int ma = 0;
	for(int i = 0;i < h * w;i++){
		for(int j = 0;j < h * w;j++){
			if(s[i / w][i % w] == '.' && s[j / w][j % w] == '.') chmax(ma,cost[i][j]);
		}
	}
	cout << ma << endl;
}

Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
char s[1000005];
int main()
{
    cin >> s;
    int n=strlen(s);
    for(int i=0;i<n;i++){
        if(i%2){
            if(s[i]=='R'){
                printf("No\n");
                return 0;
            }
        }
        else{
            if(s[i]=='L'){
                printf("No\n");
                return 0;
            }
        }
    }
    printf("Yes\n");
    return 0;
}


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

using namespace std;

int main()
{
  int N;
  cin >> N;
  int L[N];
  for(int i = 0; i < N; i++) cin >> L[i];

  sort(L, &L[N]);
  int suml = 0;
  for(int i = 0; i < N-1; i++) suml += L[i];
  if(suml > L[N-1]) cout << "Yes" << "\n";
  else cout << "No" << "\n";

  return 0;
}


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

using namespace std;

constexpr int INF = 1e8;
constexpr int MAX_N = 1e5;

int N;
vector<int> L;

void input()
{
  scanf("%d", &N);
  L.resize(N);
  for(int i = 0; i < N; i++)
  {
    scanf("%d", &L[i]);
  }
}

void solve()
{
  sort(L.begin(), L.end());
  int sum = 0;
  for(int i = N-2; 0 <= i; i--)
  {
    sum += L[i];
  }
  if(L[N-1] < sum)
  {
    printf("Yes");
  }
  else
  {
    printf("No");
  }
}

int main()
{
  input();
  solve();

  return 0;
}

Measured memory_bytes: 256
#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,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

int main() {
  int n;
  while(cin>>n) {
    int ans = 0;
    for (int i=1; i<=n; i++) {
      int c = 0;
      int x = i;
      while(x) x/=10,c++;
      ans += (c%2);
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    int N;cin >> N;
    vector<int> B(N);
    int ans = 0;
    for(int i=0;i<N-1;i++){cin >> B[i];}
    for(int i=0;i<N;i++){
        if(i == 0) ans+=B[0];
        else if(i==N-1) ans+=B[N-2];
        else ans+=min(B[i-1],B[i]);
    }

    cout << ans << endl;

}


Measured memory_bytes: 256