akhauriyash/Code-Regression huggingface dataset:
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#pragma endregion

constexpr ll mod = 1e9 + 7;

void solve() {
    int n, c;
    cin >> n >> c;
    vector<pair<int, int>> time(n);
    vector<int> channel(n);
    for (int i=0; i<n; i++) {
        cin >> time.at(i).first >> time.at(i).second >> channel.at(i);
        time.at(i).first--;
    }

    vector<int> cnt(1e5+1, 0);
    for (int i=1; i<=c; i++) {
        vector<int> tmp(1e5+1, 0);
        for (int j=0; j<n; j++) {
            if (channel.at(j) == i) {
                tmp.at(time.at(j).first)++;
                tmp.at(time.at(j).second)--;
            }
        }
        for (int j=1; j<1e5+1; j++) {
            tmp.at(j) += tmp.at(j-1);
        }
        for (int j=0; j<1e5+1; j++) {
            if (tmp.at(j)) {
                cnt.at(j)++;
            }
        }
    }
    int ans = 0;
    for (int i=0; i<1e5+1; i++) {
        chmax(ans, cnt.at(i));
    }

    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 2176
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        long N = Long.parseLong(sc.next());
        long ans = 0;
        long sqrt = (int)Math.sqrt(N);
        
        if(sqrt * sqrt == N){
            ans = N;
        }else{
            ans = sqrt * sqrt;
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
//============================================================================
// Name        : Hello5.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using p = pair<int,int>;//<key,value>


int main() {
ll n,a,b;
cin>>n>>a>>b;
ll m=a+b;
ll l=n%m;
ll o=min(a,l);
ll ans=o+a*(n/m);
cout<<ans<<endl;
return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int int64_t
#define rep(i, N) for(int i=0; i<N; i++)
using namespace std;
using pair = pair<int, int>;
using tup  = tuple<int, int, int>;
using vec  = vector<int>;
using vvec = vector<vec>;
// " ", ' '
// std::string str;
// str = std::to_string(int i);

// プロトタイプ宣言
// int myfunc(int, vvec);

// グローバル変数
// int N, M;
// vvec data(N, vec(M));

// 関数：

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string S,C;
	cin>>S;
	if(S=="Sunny"){
		C="Cloudy";
	}
	if(S=="Cloudy"){
		C="Rainy";
	}
	if(S=="Rainy"){
		C="Sunny";
	}
	cout<<C<<endl;
	return 0;
}


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

public class Main{
	final int INF = 1000000001;
	
	public int search(int[][] graph, int start, int goal){
		int[] cost = new int[graph.length];
		for(int i = 0; i < cost.length; i++){
			if( i == start ){
				cost[i] = 0;
				continue;
			}
			cost[i] = INF;
		}
		
		Set<Integer> set = new HashSet<Integer>();
		set.add(start);
		while( !set.contains(goal) ){
			int min_a = 0;
			int min_b = 1;
			for(Integer x : set){
				for(int i = 1; i < cost.length; i++){
					if( cost[i] < INF || x == i ){
						continue;
					}
					if( graph[x][i] + cost[x] < graph[min_a][min_b] + cost[min_a] ){
						min_a = x;
						min_b = i;
		//				System.out.println("reviewed  min_a = " + min_a + ", min_b = " + min_b);
					}
				}				
			}
			cost[min_b] = graph[min_a][min_b] + cost[min_a];
			set.add(min_b);			
		}
		return cost[goal];
	}
	public void solve() throws IOException{
		int n = nextInt(), m = nextInt();
		int[][] graph = new int[n+1][n+1];
		for(int i = 0; i < graph.length; i++){
			for(int j = 0; j < graph[0].length; j++){
				if( i == j ){
					continue;
				}
				graph[i][j] = INF;
			}
		}
		String[][] temp = new String[m+1][];
		for(int i = 0; i < m; i++){
			temp[i] = nextToken().split(",");
			int a = Integer.parseInt(temp[i][0]);
			int b = Integer.parseInt(temp[i][1]);
			graph[a][b] = Integer.parseInt(temp[i][2]);
			graph[b][a] = Integer.parseInt(temp[i][3]);
		}
	/*	System.out.println();
		for(int[] x : graph){
			for(int y : x){
				System.out.print(y + " ");
			}
			System.out.println();
		}*/
		temp[m] = nextToken().split(",");
		int start = Integer.parseInt(temp[m][0]);
		int goal = Integer.parseInt(temp[m][1]);
		int reward = Integer.parseInt(temp[m][2]);
		int cost = Integer.parseInt(temp[m][3]);
		int ans = reward - cost - search(graph, start, goal) - search(graph, goal, start);
		System.out.println(ans);
	}		
	public static void main (String args[]) throws IOException{
		new Main().run();
	}
	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;
	
	public void run() throws IOException{
		try{
			reader = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (Exception e){
			e.printStackTrace();
			System.exit(1);
		}
	}
	public int nextInt() throws IOException{
		return Integer.parseInt(nextToken());
	}
	public String nextToken() throws IOException{
		while( tokenizer == null || !tokenizer.hasMoreTokens() ){
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}

Measured memory_bytes: 9112
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;

const int MAX = 100000;
 
int main(){
    int N,M;
    pair<int,int> p[MAX];
    priority_queue<int> q;

    cin >> N >> M;
    for(int i = 0;i < N;i++){
        cin >> p[i].first >> p[i].second;
    }

    sort(p,p+N);

    int cnt = 0;
    long long ans = 0;

    for(int i = 0;i <= M;i++){
        while(cnt < N && p[cnt].first <= i){
            q.push(p[cnt].second);
            cnt++;
        }
        if(!q.empty()){
            ans += q.top();
            q.pop();
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1660
import sys
from io import StringIO
import unittest

sys.setrecursionlimit(10 ** 7)


def memoize(f):
    cache={}
    def helper(*args):
        if args not in cache:
            cache[args] = f(*args)
        return cache[args]
    return helper


def resolve():
    n = int(input())
    h = list(map(int, input().split()))
    inf = n * 10 ** 7

    """
    ボトムアップ型: for loopを使う
    ans = [inf for _ in range(n)]
    ans[0] = 0
    ans[1] = abs(h[1] - h[0])

    for i in range(2, n):
        ans[i] = min(ans[i], ans[i - 1] + abs(h[i] - h[i - 1]), ans[i - 2] + abs(h[i] - h[i - 2]))

    print(ans[-1])
    """

    # トップダウン(メモ再帰型)
    memo = [inf for _ in range(n)]
    # @memoize
    def dp(n: int) -> int:
        if n == 0:
            return 0
        elif n == 1:
            return abs(h[1] - h[0])
        elif memo[n] != inf:
            return memo[n]
        else:
            memo[n] = min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]))
            return memo[n]

    print(dp(n - 1))

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """4
10 30 40 20"""
        output = """30"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """2
10 10"""
        output = """0"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """6
30 10 60 10 60 50"""
        output = """40"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

Measured memory_bytes: 122620
// 2013/11/06 Tazoe

#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;

struct state{
	int p[8];
	int t;
};

int main()
{
	while(true){
		struct state s;

		cin >> s.p[0];

		if(cin.eof())
			break;

		for(int i=1; i<8; i++){
			cin >> s.p[i];
		}

		s.t = 0;

		if(s.p[0]==0 && s.p[1]==1 && s.p[2]==2 && s.p[3]==3 && s.p[4]==4 && s.p[5]==5 && s.p[6]==6 && s.p[7]==7){
			cout << s.t << endl;
			continue;
		}

		bool memo[8][8][8][8][8][8][8];		// メモリ節約のため7次元
		for(int i0=0; i0<8; i0++){
		for(int i1=0; i1<8; i1++){
		for(int i2=0; i2<8; i2++){
		for(int i3=0; i3<8; i3++){
		for(int i4=0; i4<8; i4++){
		for(int i5=0; i5<8; i5++){
		for(int i6=0; i6<8; i6++){
			memo[i0][i1][i2][i3][i4][i5][i6] = false;
		}
		}
		}
		}
		}
		}
		}
		memo[s.p[0]][s.p[1]][s.p[2]][s.p[3]][s.p[4]][s.p[5]][s.p[6]] = true;

		queue<struct state> q;
		q.push(s);

		while(true){
			if(q.empty())
				break;

			s = q.front();
			q.pop();
			s.t++;

			int I = 0;
			while(s.p[I]!=0){
				I++;
			}

			if(0<=I && I<=3){
				swap(s.p[I], s.p[I+4]);
				if(s.p[0]==0 && s.p[1]==1 && s.p[2]==2 && s.p[3]==3 && s.p[4]==4 && s.p[5]==5 && s.p[6]==6 && s.p[7]==7){
					cout << s.t << endl;
					break;
				}
				if(!memo[s.p[0]][s.p[1]][s.p[2]][s.p[3]][s.p[4]][s.p[5]][s.p[6]]){
					memo[s.p[0]][s.p[1]][s.p[2]][s.p[3]][s.p[4]][s.p[5]][s.p[6]] = true;
					q.push(s);
				}
				swap(s.p[I], s.p[I+4]);
			}

			if(4<=I && I<=7){
				swap(s.p[I], s.p[I-4]);
				if(s.p[0]==0 && s.p[1]==1 && s.p[2]==2 && s.p[3]==3 && s.p[4]==4 && s.p[5]==5 && s.p[6]==6 && s.p[7]==7){
					cout << s.t << endl;
					break;
				}
				if(!memo[s.p[0]][s.p[1]][s.p[2]][s.p[3]][s.p[4]][s.p[5]][s.p[6]]){
					memo[s.p[0]][s.p[1]][s.p[2]][s.p[3]][s.p[4]][s.p[5]][s.p[6]] = true;
					q.push(s);
				}
				swap(s.p[I], s.p[I-4]);
			}

			if(I!=0 && I!=4){
				swap(s.p[I], s.p[I-1]);
				if(s.p[0]==0 && s.p[1]==1 && s.p[2]==2 && s.p[3]==3 && s.p[4]==4 && s.p[5]==5 && s.p[6]==6 && s.p[7]==7){
					cout << s.t << endl;
					break;
				}
				if(!memo[s.p[0]][s.p[1]][s.p[2]][s.p[3]][s.p[4]][s.p[5]][s.p[6]]){
					memo[s.p[0]][s.p[1]][s.p[2]][s.p[3]][s.p[4]][s.p[5]][s.p[6]] = true;
					q.push(s);
				}
				swap(s.p[I], s.p[I-1]);
			}

			if(I!=3 && I!=7){
				swap(s.p[I], s.p[I+1]);
				if(s.p[0]==0 && s.p[1]==1 && s.p[2]==2 && s.p[3]==3 && s.p[4]==4 && s.p[5]==5 && s.p[6]==6 && s.p[7]==7){
					cout << s.t << endl;
					break;
				}
				if(!memo[s.p[0]][s.p[1]][s.p[2]][s.p[3]][s.p[4]][s.p[5]][s.p[6]]){
					memo[s.p[0]][s.p[1]][s.p[2]][s.p[3]][s.p[4]][s.p[5]][s.p[6]] = true;
					q.push(s);
				}
				swap(s.p[I], s.p[I+1]);
			}
		}
	}

	return 0;
}

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

#define INF 1234567890
#define ll long long

int N;
int A[200201], AA[200201], BB[200201], F[200201];
vector<int> PA[200201];
int res[200201];
set<int> s[200201];

int main()
{
	scanf("%d", &N);
	for(int i=1; i<=N; i++)
	{
		scanf("%d", &A[i]);
		AA[A[i]]++;
		F[A[i]]++;
		PA[A[i]].push_back(i);
	}
	for(int i=1; i<=N; i++)
	{
		int t;
		scanf("%d", &t);
		BB[t]++;
		F[t]++;
	}
	// 가능성 판별
	for(int i=1; i<=N; i++)
		if (F[i] > N)
			return !printf("No");
	printf("Yes\n");

	// 틀린 이유 : F[i]가 남아 있어도 AA[i]가 없을 수도 있다.
	for(int i=1; i<=N; i++)
		if (AA[i])
			s[F[i]].insert(i); // s[cnt] = col

	// 아무 순서로나 소거하자. 최빈값이랑 매칭시키자.
	int p = N, q = N;
	for(int i=1; i<=N; i++)
	{
		while(BB[i] > 0)
		{
			while (s[p].empty()) p--;
			q = min(q, p);
			while (q && s[p].size() == 1 && (p == q || s[q].size() == 0)) q--; // second 최빈값

			int j = *s[p].begin();
			if (i == j) j = *s[q].rbegin();

			//printf("%d vs %d\n", p, q);
			//printf("match %d vs %d\n", i, j);
			assert(!PA[j].empty());
			int k = PA[j].back(); PA[j].pop_back(); res[k] = i;
			if (AA[j]) s[F[j]].erase(j);
			if (AA[i]) s[F[i]].erase(i);
			AA[j]--; BB[i]--; F[j]--; F[i]--;
			if (AA[j]) s[F[j]].insert(j);
			if (AA[i]) s[F[i]].insert(i);

			// for(int i=1; i<=N; i++)
			// 	printf("%d ", res[i]);
			// printf("\n");
		}
	}

	for(int i=1; i<=N; i++)
		printf("%d ", res[i]);
	for(int i=1; i<=N; i++)
		if (A[i] == res[i])
			assert(0);
	return 0;
}

Measured memory_bytes: 37176
#include<bits/stdc++.h>
using namespace std;
const int M=998244353;
int i,n,f[305][305][305],dp[305][305][305],s0[305],s1[305],j,k;
int mx[305][305],C[305][305];
char c[1005];
void dfs(int i,int j,int k)
{
	if(f[i][j][k])
		return;
	f[i][j][k]=1;
	mx[j+s0[i]][k+s1[i]]=max(mx[j+s0[i]][k+s1[i]],i);
	if(i+1<=n)
	{
		if(c[i]=='0'||c[i+1]=='0')
			dfs(i+2,j+1,k);
		if(c[i]=='1'||c[i+1]=='1')
			dfs(i+2,j,k+1);
	}
	if(j+k>=2&&j)
		dfs(i,j-1,k);
	if(j+k>=2&&k)
		dfs(i,j,k-1);
	if(j+k>=1&&i<=n)
	{
		dfs(i+1,j,k);
		if(c[i]=='0')
			if(k)
				dfs(i+1,j+1,k-1);
		if(c[i]=='1')
			if(j)
				dfs(i+1,j-1,k+1);
	}
}
int dfs2(int i,int j,int k)
{
	if(i>n)
		return C[j+k][j];
	if(dp[i][j][k]!=-1)
		return dp[i][j][k];
	int s=0;
	if(c[i]=='0')
		if(k)
			s+=dfs2(i,j,k-1);
	if(c[i]=='1')
		if(j)
			s+=dfs2(i,j-1,k);
	s+=dfs2(i+1,j,k);
	return dp[i][j][k]=s%M;
}
int main()
{
	scanf("%s",c+1);
	n=strlen(c+1);
	for(i=n;i>=1;--i)
	{
		s0[i]=s0[i+1]+(c[i]=='0');
		s1[i]=s1[i+1]+(c[i]=='1');
	}
	for(i=0;i<=n;++i)
	{
		C[i][0]=C[i][i]=1;
		for(j=1;j<i;++j)
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%M;
	}
	memset(dp,-1,sizeof(dp));
	dfs(1,0,0);
	long long ans=0;
	for(i=0;i<=n;++i)
		for(j=0;j<=n;++j)
			if(mx[i][j])
				ans+=dfs2(mx[i][j],i-s0[mx[i][j]],j-s1[mx[i][j]]);
	cout<<(ans%M+M)%M;
}


Measured memory_bytes: 142924
#include<bits/stdc++.h>
using namespace std;
int main(){
    string aaa;
    cin>>aaa;
    string b=aaa;
    reverse(aaa.begin(),aaa.end());
    for(int i=0;i<aaa.size();++i)
    {
        if(aaa[i]=='b') aaa[i]='d';
        else if(aaa[i]=='d') aaa[i]='b';
        else if(aaa[i]=='p') aaa[i]='q';
        else if(aaa[i]=='q') aaa[i]='p';
    }
    if(aaa==b) cout<<"Yes";
    else cout<<"No";
}

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

int main(){
	int n, mx, mxp;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a.at(i);
	sort(a.begin(), a.end());
	mx = a.back();
	a.pop_back();
	
	auto itr = lower_bound(a.begin(), a.end(), mx/2);
	mxp = *itr;
	if(itr != a.begin()){
		auto itr2 = itr;
		itr--;
		if(mxp - mx/2 > mx/2 - *itr || itr2 == a.end()) mxp = *itr;
	}
	cout << mx << " " << mxp << endl;
	
	return 0;
}

Measured memory_bytes: 640
// best coder in the world do not mess with me!!
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a); i > (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod=1000000007;
void generate(int per[],int t)
{
	
	for(int i=t-1;i>0;i--)
	{
		int k=rand()%i;
		swap(per[k],per[i]);
	}
}


    int main()
    {
    	ll n;
    	cin>>n;
    	ll counter1 = 1;
    	ll result = 0;
    	while(n>0)
    	{
    		result+=counter1;
    		counter1*=2;
    		n/=2;
    	}
    	cout<<result<<endl;
    }



Measured memory_bytes: 384
/* ＵＴＦ－８ */
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}

	int N, M;
	std::string S;
	std::cin >> N >> M;
	std::cin >> S;

	int pos = N;
	std::vector<int> way;

	while (pos != 0) {
		int from;
		for (from = std::max(pos - M, 0); from < pos; ++from) {
			if (S[from] == '0') {
				break;
			}
		}
		if (from == pos) {
			std::cout << "-1\n";
			return 0;
		}
		way.push_back(pos - from);
		pos = from;
	}

	std::reverse(way.begin(), way.end());
	for (int i = 0; i < way.size(); ++i) {
		if (i != 0)
			std::cout << " ";
		std::cout << way[i];
	}
	std::cout << "\n";
}


Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int h, w, d;
    cin >> h >> w >> d;
    using P = pair<int, int>;
    vector<P> a(h*w);
    for(int i = 0; i < h*w; i++)
    {
        int b;
        cin >> b;
        a[i] = P(b, i);
    }
    sort(a.begin(), a.end());
    int q;
    cin >> q;
    vector<int> l(q);
    vector<int> r(q);
    for(int i = 0; i < q; i++)
    {
        cin >> l[i] >> r[i];
    }

    vector<int> s(h*w+1);
    for(int i = 0; i <= h*w; i++)
    {
        if(i <= d)
        {
          s[i] = 0;
          continue;
        }
        int d1 = (*lower_bound(a.begin(), a.end(), P(i-1, 100000))).second;
        int d2 = (*lower_bound(a.begin(), a.end(), P(i-d-1, 100000))).second;
        int dx = abs(d1 / w - d2 / w);
        int dy = abs(d1 % w - d2 % w);
        s[i] = s[i-d] + dx + dy;
    }

    for(int i = 0; i < q; i++)
    {
        cout << s[r[i]] - s[l[i]] << endl;
    }
}
        


Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int N, M;
int HpInit, HpMax;
int H, W;
vector<string> G;
int cost[256];
int portion[12];
int calc_heal[1<<12];

typedef pair<int, int> pii;
vector<pii> v;

int main() {

  while(cin >> HpInit >> HpMax && (HpInit | HpMax)) {
    cin >> H >> W;
    G.clear(); G.resize(H);
    rep(i, H) cin >> G[i];
    int Q; cin >> Q;
    rep(i, Q) {
      char c; cin >> c;
      cin >> cost[(int)c];
    }

    v.clear();
    int y = 0, x = 0;

    cin >> N;
    rep(i, N) {
      char d; cin >> d;
      int n; cin >> n;
      if(d == 'L') { rep(i, n) v.push_back({y, x-i-1}); x -= n; }
      if(d == 'U') { rep(i, n) v.push_back({y-i-1, x}); y -= n; }
      if(d == 'R') { rep(i, n) v.push_back({y, x+i+1}); x += n; }
      if(d == 'D') { rep(i, n) v.push_back({y+i+1, x}); y += n; }
    }

    cin >> M;
    rep(i, M)
      cin >> portion[i];

    rep(S, 1<<M) {
      calc_heal[S] = 0;
      rep(i, M) if(S >> i & 1)
        calc_heal[S] += portion[i];
    }

    static int sum[1010]; rep(i, 1010) sum[i] = 0;
    rep(i, v.size()) {
      if(i) sum[i] += sum[i-1];
      sum[i] += cost[(int)G[v[i].first][v[i].second]];
    }

    static int dp[1010][1<<12];
    rep(i, 1010) rep(j, 1<<12) dp[i][j] = -inf;
    dp[0][0] = HpInit;

    bool ok = 0;

    rep(i, v.size()) {
      const int damage = cost[(int)G[v[i].first][v[i].second]];
      rep(PS, 1<<M) {
        if(dp[i][PS] <= 0) continue;
        if(sum[v.size() - 1] - sum[i] + damage < dp[i][PS]) { ok = 1; goto ex; }

        int remain = (1 << M) - 1 - PS;
        for(int b=remain; b>=0; b--) {
          b &= remain;
          int NPS = PS | ((1 << M) - 1 - PS - b);
          const int heal = calc_heal[NPS ^ PS];
          const int cand = min(HpMax, dp[i][PS] + heal) - damage;
          if(cand > 0) maximize(dp[i+1][NPS], cand);
        }
      }
    }

    rep(i, 1<<M) {
      ok |= dp[v.size()][i] > 0;
    }

  ex:;
    cout << (ok ? "YES\n" : "NO\n");

  }
  
  return 0;
}

Measured memory_bytes: 19316
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

int main(void) {
  int r;
  cin>>r;
  std::cout << 3*r*r << std::endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MP make_pair
#define endl '\n'
const int mod = 10007;
const int MAXN = 2e5 + 5;
const int INF = 0x3f3f3f3f;

int a[MAXN];

int main(int argc, char* argv[]) {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", a + i);
    }
    int sum = 1, ans = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] == sum)
            sum++;
        else
            ans++;
    }
    if (sum == 1)
        printf("-1\n");
    else
        printf("%d\n", ans);
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    int number[n];
    for (int j = 0; j < n; j++) {
        cin >> number[j];
    }
    for (int i = n-1; i >= 0; i--) {
        if (i) {
            cout << number[i] << " ";
        } else {
            cout << number[i] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3076
#include "algorithm"
#include "iostream"
#include "set"
#include "vector"

using namespace std;

vector< int> conn[12];
int p[12];

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	for (int i = 0; i < m; ++i) {
		int k;
		scanf("%d", &k);
		while (k --) {
			int x;
			scanf("%d", &x);
			x --;
			conn[i].emplace_back(x);
		}
	}

	for (int i = 0; i < m; ++i) scanf("%d", &p[i]);

	int result = 0;
	
	for (int mask = 0; mask < (1 << n); mask ++) {
		bool all_ok = true;
		for (int i = 0; i < m; ++i) {
			int s = 0;
			for (int x : conn[i]) {
				if (mask >> x & 1) s ^= 1;
			}
			if (s != p[i]) all_ok = false;
		}
		if (all_ok) result ++;
	}

	printf("%d\n", result);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int vmax(std::vector<int> v)
{
    int maxVal = INT_MIN;       // 整数最小値
    for(int i = 0; i < (int)v.size(); ++i) {
        if( v[i] > maxVal )
            maxVal = v[i];
    }
    return maxVal;
}

int main() {

	int a,b;
	int c,d,e,max;
	vector<int> x;
  string s,str1,str2;

		cin >> a; 
		cin >> s;

		int i,j,k,l,m,n;
	  for(i=1; i<a; i++){
			max=0;
			map<string, int> mp;

			str1 = s.substr(0,i);
			str2 = s.substr(i,a-i);
	
			for(k=0;k<str1.size();k++){
			 for(l=0;l<str2.size();l++){
				if(str1.substr(k,1) == str2.substr(l,1)){
					mp[str1.substr(k,1)] = 1;
					break;
					}
				}
			}
			max = mp.size();
			x.push_back(max);		
		}
		
  e = vmax(x);
	
	cout << e << endl;	

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
typedef long long lint;
const int N=302;
const int mod=1e9+7;
int n,m,dp[N][N];
struct limit{
	int l,r,x;
	bool operator < (const limit b) const {
		return r<b.r;
	}
}lt[N];

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

inline int nxi(){
	int x=0;
	char c;
	while((c=getchar())>'9'||c<'0');
	while(x=x*10+c-48,(c=getchar())>='0'&&c<='9');
	return x;
}

int main(){
#ifndef ONLINE_JUDGE
	//  freopen("a.in","r",stdin);
#endif
	n=nxi(),m=nxi();
	for(int i=1;i<=m;++i){
		lt[i].l=nxi();
		lt[i].r=nxi();
		lt[i].x=nxi();
	}
	std::sort(lt+1,lt+m+1);
	dp[0][0]=1;
	for(int q=1,i=1;i<n;++i){
		int p=i&1;
		while(lt[q].r<i&&q<=m) ++q;
		for(int j=i;j>=0;--j){
			for(int k=i;k>=j;--k){
				for(int tp=q;lt[tp].r==i;++tp){
					if((k>=lt[tp].l)+(j>=lt[tp].l)+1!=lt[tp].x){
						dp[j][k]=0;
						break;
					}
				}
				twk(dp[j][i]+=dp[j][k]);
				if(j!=k) twk(dp[k][i]+=dp[j][k]);
			}
		}
	}
	for(int j=0;j<=n;++j){
		for(int k=j;k<=n;++k){
			for(int tp=m;lt[tp].r==n;--tp){
				if((k>=lt[tp].l)+(j>=lt[tp].l)+1!=lt[tp].x){
					dp[j][k]=0;
					break;
				}
			}
		}
	}
	int ans=0;
	for(int i=0;i<=n;++i){
		for(int j=i;j<=n;++j){
			if(i==0&&j==0) ans=(ans+(lint)dp[i][j]*3)%mod;
			else ans=(ans+(lint)dp[i][j]*6)%mod;
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

#define In inline
#define Op operator
#define St static
#define Rg register

const int p=1e9+7, mxN=1<<11, mxA=1<<20;

typedef long long ll;

In ll dPow(ll a, ll b)
{
	Rg ll r=1;
	for(; b; a=a*a%p, b>>=1)
		if(b & 1)
			r=r*a%p;
	return r;
}

int main()
{
	St int n, m, a[mxN], b[mxN], fact[mxA], invF[mxA];
	scanf("%d%d", &n, &m);
	for(Rg int i=1; i<=n; ++i)
		scanf("%d", a+i);
	for(Rg int i=1; i<=m; ++i)
		scanf("%d", b+i);
	sort(a+1, a+n+1);
	sort(b+1, b+m+1);
	a[n+1]=b[m+1]=1e9;
	Rg ll ans=1, used=0;
	for(Rg int i=1; i<n; ++i)
		if(a[i]==a[i+1])
			goto End;
	for(Rg int i=1; i<m; ++i)
		if(b[i]==b[i+1])
			goto End;
	fact[0]=1;
	for(Rg int i=1; i<mxA; ++i)
		fact[i]=(ll)i*fact[i-1]%p;
	invF[mxA-1]=dPow(fact[mxA-1], p-2);
	for(Rg int i=mxA-1; i; --i)
		invF[i-1]=(ll)i*invF[i]%p;
	for(Rg int i=1, j=1; i<=n || j<=m;)
	{
		if(a[i]==b[j])
		{
			if(used+(n-i)+(m-j)>=a[i])
				goto End;
			ans=ans*fact[a[i]-used-1]%p*invF[a[i]-used-1-n+i-m+j]%p;
			used+=n-i+m-j+1;
			++i;
			++j;
		}
		else if(a[i]<b[j])
		{
			if(used+(m-j)>=a[i])
				goto End;
			ans=ans*fact[a[i]-used-1]%p*invF[a[i]-used-1-m+j]%p*(m-j+1)%p;
			used+=(m-j)+1;
			++i;
		}
		else
		{
			if(used+(n-i)>=b[j])
				goto End;
			ans=ans*fact[b[j]-used-1]%p*invF[b[j]-used-1-n+i]%p*(n-i+1)%p;
			used+=(n-i)+1;
			++j;
		}
	}
	printf("%lld\n", (ans+p)%p);
	return 0;
	End : puts("0");
	return 0;
}

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

#define STR 200

int get_item_price(int N,char **S,int *price,char t[STR]){
	for(int i=0;i<N;i++){
		if(strcmp(S[i],t)==0){
			return price[i];
		}
	}
	return -1;
}

int get_alchemy_number(int M,char **O,char t[STR]){
	for(int i=0;i<M;i++){
		if(strcmp(O[i],t)==0){
			return i;
		}
	}
	return -1;
}

int frac(int N,char **S,int *price,int M,char **O,int *k,char ***q,char t[STR],int P){
	int alchemy_number=get_alchemy_number(M,O,t);
	int sum=0;
	int material_price;
	int n=0;

	if(alchemy_number!=-1){
		for(int i=0;i<k[alchemy_number];i++){
			if(get_alchemy_number(M,O,q[alchemy_number][i])==-1){
				sum+=get_item_price(N,S,price,q[alchemy_number][i]);
			}else{
				material_price=get_item_price(N,S,price,q[alchemy_number][i]);
				n=frac(N,S,price,M,O,k,q,q[alchemy_number][i],material_price);
				if(n<material_price){
					sum+=n;
				}else{
					sum+=material_price;
				}
			}
		}
	}else{
		return P;
	}
	return sum;
}

int calc(int N,char **S,int *price,int M,char **O,int *k,char ***q,char t[STR]){
	int item_price=get_item_price(N,S,price,t);

	int sum=frac(N,S,price,M,O,k,q,t,item_price);

	if(sum<item_price){
		return sum;
	}else{
		return item_price;
	}
}

int main(){
	int N;
	char **S;
	int *price;
	int M;
	char **O;
	int *k;
	char ***q;
	char t[STR];
	int result=0;

	while(1){
		scanf("%d",&N);
		if(N==0){break;}
		S=(char**)malloc(N*sizeof(char*));
		price=(int*)malloc(N*sizeof(int));
		for(int i=0;i<N;i++){
			S[i]=(char*)malloc(STR*sizeof(char));
			scanf("%s %d",S[i],&price[i]);
		}
		scanf("%d",&M);
		O=(char**)malloc(M*sizeof(char*));
		k=(int*)malloc(M*sizeof(int));
		q=(char***)malloc(M*sizeof(char**));
		for(int i=0;i<M;i++){
			O[i]=(char*)malloc(STR*sizeof(char));
			scanf("%s %d",O[i],&k[i]);
			q[i]=(char**)malloc(k[i]*sizeof(char*));
			for(int j=0;j<k[i];j++){
				q[i][j]=(char*)malloc(STR*sizeof(char));
				scanf("%s",q[i][j]);
			}
		}

		scanf("%s",t);
		printf("%d\n",calc(N,S,price,M,O,k,q,t));

		free(price);
		for(int i=0;i<N;i++){
			free(S[i]);
		}
		free(S);
		for(int i=0;i<M;i++){
			free(O[i]);
			for(int j=0;j<k[i];j++){
				free(q[i][j]);
			}
			free(q[i]);
		}free(O);
		free(q);
		free(k);
	}


	//printf("resukt=%d\n",calc(N,S,price,M,0,k,q,t));


	return 0;
}


Measured memory_bytes: 2128
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = read().rstrip().decode('utf-8')

S = S.replace('><','>,<').split(',')

answer = 0
for T in S:
    # <<<< >>>> の形
    a = T.count('<')
    b = T.count('>')
    x = a * (a-1) // 2 + b * (b-1) // 2 + max(a,b)
    answer += x

print(answer)

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

using namespace std;

using ll = long long;

const string KEY = "keyence";

const int N = 1e5 + 5;

int a[N];
int b[N];

int solve() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        scanf("%d", a + i);
    }
    vector<int> rich;
    int res = 0;
    ll have = 0;
    ll needed = 0;
    for (int i = 0; i < n; ++i) {
        int d;
        scanf("%d", &d);
        if (d > a[i]) {
            ++res;
            needed += d - a[i];
        } else if (a[i] > d) {
            rich.push_back(a[i] - d);
            have += a[i] - d;
        }
    }
    if (needed > have) {
        return -1;
    }
    if (needed == 0) {
        return 0;
    }
    sort(rich.begin(), rich.end(), greater<>{});
    for (int r : rich) {
        ++res;
        if (needed <= r) {
            break;
        }
        needed -= r;
    }

    return res;
}

int main() {
#ifdef LOCALHOST
    freopen("input", "r", stdin);
#endif
    printf("%d\n", solve());

    return 0;
}


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

typedef long long ll; // -9,223,372,036,854,775,808 から 9,223,372,036,854,775,807

template <class T> using vec = std::vector<T>;
template <class T> using vec2 = vec<vec<T>>;
template <class T> using vec3 = vec<vec<vec<T>>>;

// #define DEBUG

struct Result{
    ll twos;
    ll oddPart;
};

Result removeTwos(ll n){
    ll twos = 0;
    while(true){
        if(n % 2 == 0){
            n /= 2;
            twos++;
        }else{
            return Result{twos, n};
        }
    }
}

ll lcm2(vec<ll> a){
    ll g = a[0];
    for(int i=0; i < a.size(); i++){
        g = __gcd(g, a[i]);
    }
    ll res = g;
    for(int i=0; i < a.size(); i++){
        res *= a[i]/g;
    }

    return res;

}

ll lcm(ll a, ll b){
    ll g = __gcd(a, b);
    return g*(a/g)*(b/g);
}

ll lcmVec(vec<ll> a){
    ll res = a[0];
    for(int i=0; i < a.size(); i++){
        res = lcm(res, a[i]);
    }

    return res;
}

ll pow2(ll x){
    ll res = 1;
    ll twos = 2;
    while(x > 0){
        if(x & 1 == 1){
            res *= twos;
        }
        x >>= 1;
        twos *= twos;
    }

    #ifdef DEBUG
    printf("*START: pow2\n");
    cout << res << endl;
    printf("*END: pow2\n");
    #endif


    return res;
}

void solve(long long N, long long M, std::vector<long long> a){
    vec<Result> rs(N);
    set<ll> twoss;
    vec<ll> a2s(N);
    for(int i=0; i < N; i++){
        auto r = removeTwos(a[i]);
        twoss.insert(r.twos);
        a2s[i] = r.oddPart;
        #ifdef DEBUG
        printf("*START: a2s\n");
        cout << a2s[i] << endl;
        printf("*END: a2s\n");
        #endif
    }

    #ifdef DEBUG
    printf("*START: twos\n");
    cout << twoss.size() << endl;
    printf("*END: twos\n");
    #endif

    // 2の個数ちがうならおわり
    if(twoss.size() != 1){
        cout << 0 << endl;
        return;
    }

    #ifdef DEBUG
    printf("*START: lcm\n");
    cout << lcmVec(a2s) << endl;
    printf("*END: lcm\n");
    #endif

    ll x = (M)/(pow2(*twoss.begin() - 1)*lcmVec(a2s));
    ll res = x - x/2;
    cout << res << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, M, std::move(a));
    return 0;
}


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

const int INF = 2e9;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    a[n-1] /= 2;
    int sum;
    rep(i,n){
        sum += a[i];
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
from operator import mul
from functools import reduce
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under
s=int(input())
ans=0
mod=10**9+7
for i in range(1,s//3+1):
    num=s-(3*i)
    ans+=cmb(num+(i-1),i-1)%mod
ans%=mod
print(ans)


Measured memory_bytes: 9608
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] arr = sc.next().toCharArray();
        int idx = 0;
        int count = 0;
        while (idx < n - 1) {
            if (arr[idx] == 'O' && arr[idx + 1] == 'X') {
                count++;
                idx += 2;
            } else if (arr[idx] == 'X' && arr[idx + 1] == 'O') {
                count++;
                idx += 2;
            } else {
                idx++;
            }
        }
        System.out.println(count);
     }
}


Measured memory_bytes: 29860
#include <iostream>

using namespace std;
int main(){
    long long a,b,c,d; cin >> a >> b >> c >> d;
    long long x = a*c;
    x = max(x,a*d);
    x = max(x,b*c);
    x = max(x,b*d);
    cout << x << endl;
}

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
n = int(input())
dic = [0]*n
for i in range(n):
    s, p = input().split()
    dic[i] = (s, int(p), i+1)
dic.sort(key=lambda dic: dic[1],reverse=True)
dic.sort(key=lambda dic: dic[0])
for i in dic:
    print(i[2])


Measured memory_bytes: 3060
n, l = map(int, input().split())
a = list(map(int, input().split()))
ans = float("inf")
for i in range(n - 1):
    if a[i] + a[i + 1] >= l:
        ans = i + 1
if ans == float("inf"):
    print("Impossible")
else:
    print("Possible")
    print(*range(1, ans), sep="\n")
    print(*range(n - 1, ans, -1), sep="\n")
    print(ans)

Measured memory_bytes: 20000
var fs, max, scale, max_log2, max_pow2, series;

fs = require('fs');

max = 300;

function log2(n) {
	return n.toString(2).length - 1;
}

max_log2 = Math.floor(log2(max));
max_pow2 = Math.pow(2, max_log2);

series = function(max_pow2) {
	var i, series = [];
	for (i = max_pow2; i >= 1; i /= 2) series.push(i);
	return series;
} (max_pow2);

scale = function(max) {
	var scale, i, str;
	scale = [];
	str = "#";
	for (i = 1; i < max; i *= 2) {
		scale.push(str);
		str = str + str;
	}
	return scale.reverse();
}(max);

function get_column(W) {
	var i, res, rest;
	res = "";
	rest = W;
	for (i in series) {
		if (rest >= series[i]) {
			rest -= series[i];
			res = res + scale[i];
		}
	}
	return res;
}

function repeat(str, n) {
	return get_column(n).replace(/#/g, str);
}

function main() {
	var line, i, hw;
	line = fs.readFileSync('/dev/stdin', 'ascii').split("\n");
	for (i in line) {
		hw = line[i].split(' ', 2).map(Number);
		if (hw[0] === 0 && hw[1] === 0) break;
		console.log(repeat(get_column(hw[1]) + "\n", hw[0]));
	}
}

main();

Measured memory_bytes: 15460
n, l = gets.chomp.split.map(&:to_i)
if l > 0
  puts n * (l - 1) + n * (n + 1) / 2 - l
elsif l + n - 1 < 0
  puts n * (l - 1) + n * (n + 1) / 2 - (l + n - 1)
else
  puts n * (l - 1) + n * (n + 1) / 2
end
  



Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9+7);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
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; }
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,1,-1};

ll gcd(ll a,ll b){
    if(a < b)swap(a, b);
    if(b == 0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans % mod;
}

//modの値の確認をすること
int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll ans = 0;
    rep0(i, n){
        cin >> a[i];
        ans += abs(a[i]);
    }
    sort(all(a),greater<>());
    if(a[0] >= 0 && a[n - 1] < 0){
        pf(ans);
        ll i = 1;
        while (a[i] >= 0) {
            cout << a[n - 1] << " " << a[i] << endl;
            a[n - 1] -= a[i];
            ++i;
        }
        cout << a[0] << " " << a[i] << endl;
        ll m = a[0] - a[i];
        nfor(j, i + 1, n){
            cout << m << " " << a[j] << endl;
            m -= a[j];
        }
        
    }else if(a[n - 1] >= 0){
        pf(ans - a[n - 1] * 2);
        cout << a[n - 1] << " " << a[n - 2] << endl;
        ll m = a[n - 1] - a[n - 2];
        rep0(i, n - 3){
            cout << m << " " << a[i] << endl;
            m -= a[i];
        }
        if(n != 2)cout << a[n - 3] << " " << m << endl;
    }else{
        pf(ans + a[0] * 2);
        cout << a[0] << " " << a[1] << endl;
        ll m = a[0] - a[1];
        nfor(i, 2, n){
            cout << m << " " << a[i] << endl;
            m -= a[i];
        }
    }
    return 0;
}


Measured memory_bytes: 2688
#include <stdio.h>

int main() {
	int a, b;
	char c[255];
	scanf("%d %d", &a, &b);
	
	scanf("%s", c);
	
	int count = 0;
	
	for(int i = 0; c[i] != '\0'; i++) {
		
		if(c[a]  != '-') {
			printf("No\n");
			return 0;
		}
		
		if(c[i] >= '0' && c[i] <='9') {
			count++;
		}
	}
		if(count == a+b) {
			printf("Yes\n");
		}
		
		else {
			printf("No\n");
		}

	return 0;
}


Measured memory_bytes: 1648
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main() {
    ll N, X;
    cin >> N >> X;
    vector<ll> A(N);
    rep(i, N) cin >> A.at(i);
    if (N == 1) {
        cout << abs(A[0] - X) << endl;
        return 0;
    }
    sort(A.begin(), A.end());

    ll res = abs(A[1] - A[0]);
    rep(i, N - 1) {
        ll d = A[i+1] - A[i];
        res = GCD(res, d);
        if (A[i] == X) continue;
        if (A[i] < X && X < A[i+1]) {
            res = max(GCD(res, X - A[i]), GCD(res, A[i+1] - X));
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>

using namespace std;

void solve(){

	string strs[] = { "SAFE", "SUSPICIOUS" };

	int h, w;
	cin >> h >> w;

	vector< string > screen( h );
	vector< int > maxx( 26, 0 );
	vector< int > maxy( 26, 0 );
	vector< int > minx( 26, w );
	vector< int > miny( 26, h );

	for( int i = 0; i < h; i++ )
		cin >> screen[ i ];
	
	bool fig = true;

	for( int x = 0; x < w; x++ )
		for( int y = 0; y < h; y++ )
			if( screen[y][x] != '.' ) {
				int i = screen[y][x] - 'A';
				maxx[i] = max( maxx[i], x );
				minx[i] = min( minx[i], x );
				maxy[i] = max( maxy[i], y );
				miny[i] = min( miny[i], y );
			}


	while( fig ) {

		fig = false;

		for( int x = 0; x < w; x++ ) {
			for( int y = 0; y < h; y++ ) {

					char ch = screen[ y ][ x ];
					if( ch == '.' || ch == '*' ) continue;
					int i = ch - 'A';

					bool fflg = true;
					for( int tx = minx[i]; tx <= maxx[i] && fflg; tx ++ )
						for( int ty = miny[i]; ty <= maxy[i] && fflg; ty ++ )
							fflg &= ( screen[ ty ][ tx ] == ch || screen[ ty ][ tx ] == '*' );
					
					fig |= fflg;
					if( !fflg ) continue;

					for( int tx = minx[i]; tx <= maxx[i]; tx ++ )
						for( int ty = miny[i]; ty <= maxy[i]; ty ++ ) 
							screen[ ty ][ tx ] = '*';

				}
			}
		}
	

	bool b = false;
	for( int x = 0; x < w; x++ )
		for( int y = 0; y < h; y++ )
			b |= ( screen[ y ][ x ] != '.' && screen[ y ][ x ] != '*' );
	cout << strs[ b ] << endl;

}

int main( void ) {
	int n;
	cin >> n;
	for( int i = 0; i < n; i++ )
		solve();
	return 0;
}

Measured memory_bytes: 3132
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
#define INF 1000000000
typedef long long ll;

int b[2000][1000];
int s[2001][1001];


inline int calc( int x, int y, int w, int h) {
    return s[x+w][y+h] - s[x+w][y] - s[x][y+h] + s[x][y];
}

int main() {
    int n, k;
    cin >> n >> k;
    
    for( int i=0; i<n; i++) {
        int x, y;
        char c;
        
        scanf("%d %d %c", &x, &y, &c);
        y %= 2*k;
        if( c=='W' ) x+=k;
        
        if( y>=k){
            y-=k;
            x+=k;
        }
        x %= 2*k;
        b[x][y]++;
    }
    s[1][1] = b[0][0];
    for( int i=1; i<2*k; i++) s[i+1][1] += s[i][1] + b[i][0];
    for( int i=1; i<k; i++) s[1][i+1] += s[1][i] + b[0][i];
    for( int x=1; x<2*k; x++) {
        for( int y=1; y<k; y++) {
            s[x+1][y+1] = b[x][y] + s[x+1][y] + s[x][y+1] - s[x][y];
        }
    }
    
    int max=0;
    for( int x=0; x<k; x++) {
        for( int y=0; y<k; y++) {
            int t = calc( x, y, k, k-y );
            t += calc( 0, 0, x, y);
            t += calc( x+k, 0, k-x, y);
            t = t<n/2 ? n-t : t;
            max = t>max ? t : max;
        }
    }
    cout << max << endl;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
using namespace std;
int main(){
   long long n;
    cin>>n;
    vector<long long> a(n);
    rep(i,n) cin>>a.at(i);
    long long ans=1;
    bool x=false;
    bool y=false;
    sort(a.begin(),a.end());
    rep(i,n){
        if(a.at(i)==0){
            x=true;
            break;
        }
        if(1000000000000000000/ans<a.at(i)){
            y=true;
            break;
        }
        else ans*=a.at(i);
    }
        if(x){
            y=false;
            cout<<"0";
        }
        else if(y) cout<<"-1";
        else cout<<ans;
        
}

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

#define INF_LL (int64)1e18
#define INF (int64)1e9
#define REP(i, n) for(int64 i = 0; i < (n); i++)
#define FOR(i, a, b) for(int64 i = (a); i < (b); i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using int64 = int_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

template<typename A, typename B> inline void chmin(A &a, B b) { if(a > b) a = b; }
template<typename A, typename B> inline void chmax(A &a, B b) { if(a < b) a = b; }

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
    for(auto &e:u) fill_v<T>(e,v...);
}


int main(void) {
    int64 N;
    vector<int64> p(4), t(4);
    cin >> N;
    for (auto &x : p) cin >> x;
    for (auto &x : t) cin >> x;

    int64 cost = INF_LL;
    REP(i, 4) {
        REP(j, 4) {
            int64 now;
            if (N >= t[j])
                now = (N - t[j] + t[i] - 1) / t[i] * p[i] + p[j];
            else
                now = (N + t[i] - 1) / t[i] * p[i];
            chmin(cost, now);
        }
    }
    cout << cost << endl;
}


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

int gcdd(int a, int b)
{
	if(b==0)
		return a;

	return gcdd(b,a%b);
}

int main(int argc, char const *argv[])
{
	int n;
	long int a,gcd;
	cin>>n;
	
	cin>>a;
	gcd=a;


    for (int i = 0; i < n-1; ++i)
    {
    	cin>>a;
    	gcd=gcdd(gcd,a);

    	if(gcd==1)
    		break;

    }

    cout<<gcd;
	return 0;
}	

Measured memory_bytes: 256