akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <tuple>
#include <vector>
#include <set>
using namespace std;

void input_int2(int &a, int &b) {
	cin >> a >> b;
	cin.ignore();
}

void input_int3(int &a, int &b, int &c) {
	cin >> a >> b >> c;	
	cin.ignore();
}

void input_int_array(int n,vector<int> &vec) {
	for (int i=0,tmp=0; i<n && cin >> tmp; i++) vec[i]=tmp;
}

void input_int_matrix(int n, int m, vector<vector<int>> &matrix) {
	int tmp;
	for(int i=0; i<n; i++) {
		for (int j=0; j<m; j++) {
			cin >> tmp;
			matrix[i][j] = tmp;
		}
	}
}

void input_int_var_array(int n,vector<int> &vec) {
	for (int tmp=0; cin >> tmp;) {
		vec.push_back(tmp);
	}
}

void input_int_var_matrix(int n, int m, vector<vector<int>> &matrix) {
	int tmp;
	for(int i=0; i<n; i++) {
		for (int j=0; j<m; j++) {
			cin >> tmp;
			matrix[i][j] = tmp;
		}
	}
}

void input_var_str(vector<string> & array) {
	string s;
	getline(cin, s);
	
	stringstream ss{s};
	while(getline(ss, s, ' ')) {
		array.push_back(s);
	}
}

void input_var_int(vector<int> &array) {
	string s;
	getline(cin, s);
	
	stringstream ss{s};
	while(getline(ss, s, ' ')) {
		array.push_back(stoi(s));
	}
}

void input_var_int(set<int> &array) {
	string s;
	getline(cin, s);
	
	stringstream ss{s};
	while(getline(ss, s, ' ')) {
		array.insert(stoi(s));
	}
}

template <typename T> void print_var_vector(vector<T> vec) {
	for(typename vector<T>::iterator i=begin(vec); i!=end(vec); i++) {
		cout << *i;
	}
	cout << endl;
}

void print_vector(int N, vector<int> vec) {
	for(int i=0; i<N; i++){
		cout << vec[i] << " ";
	}
	cout << endl;
}

int T, X;

void input() {
	vector<int> array;
	input_int2(T, X);
}

float solve() {
	return (float)T / X;
}

int main() {
	input();
	cout << solve() << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <map>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define INF 1e10
typedef long long ll;
typedef long double ld;
int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    ll cnt=0;
    while(a%2!=1&&b%2!=1&&c%2!=1){
        if(a==b&&b==c){
            cnt=-1;
            break;
        }else{
            ll n,m,l;
            n=a/2, m=b/2, l=c/2;
            a=m+l;
            b=n+l;
            c=n+m;
            cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3640
// =====================================================================
// macros
// =====================================================================

/// input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        #[allow(unused_mut)]
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            #[allow(unused_mut)]
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        #[allow(unused_mut)]
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/// yet another input macro from https://qiita.com/hatoo@github/items/fa14ad36a1b568d14f3e
#[allow(unused_macros)]
macro_rules! inputln {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

// =====================================================================
// functions
// =====================================================================

fn main() {
    input!{
        n: usize,
        m: usize,
    }
    let result = if n == m {"Yes"}else{"No"};
    println!("{}",result.to_string());
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    ll N;cin>>N;
    N*=3;
    vl info(N);
    rep(i,N)cin>>info[i];
    sort(all(info),greater<ll>());
    ll ans=0;
    rep(i,N/3)ans+=info[i*2+1];
    cout<<ans<<endl;
    return 0;
}

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

vector<int> edges[100001];
int n,m;
bool *visited = new bool[100001]();

void dfs(int ind){
	
	visited[ind] = true;
	for(int i=0;i<edges[ind].size();i++){
		if(!visited[edges[ind][i]]){
			dfs(edges[ind][i]);
		}
			
	}
	
}

int main() {
	// your code goes here

	cin>>n>>m;
	
	for(int i=0;i<m;i++){
		int f,s;
		cin>>f>>s;
		edges[f].push_back(s);
		edges[s].push_back(f);
	}
	int cnt = 0;
	for(int i=1;i<=n;i++){
		if(!visited[i]){
			cnt++;
			dfs(i);
		}	
	}
	cout<<cnt-1;
	return 0;
}

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


int main () {
    ll a, b, c, d;
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
    printf("%lld\n", max(max(c * b, b * d), max(a * c, a * d)));


    return 0;
}


Measured memory_bytes: 3808
#include <bits/stdc++.h>
#include <time.h>
#define int long long int
#define pb push_back
#define mem(a, x) memset(a, x, sizeof a)
#define all(a) a.begin(), a.end()
#define scnarr(a, n) for (int i = 0; i < n; ++i) cin >> a[i]
#define vi vector<int>
#define si set<int>
#define pii pair <int, int>
#define sii set<pii>
#define vii vector<pii>
#define mii map <int, int>
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
using namespace chrono;
/*
	----------------------------------------------------------------------
	Things to remember : check for coners n = 1, pass references instead
*/
/* -------------------------------Solution Sarted--------------------------------------*/

//Constants
const int MOD = 1000000007; // 1e9 + 7
const int MAXN = 1000005; // 1e6 +5
const int INF = 100000000000005; // 1e15 +5

void solve(){
	int n, ans = 0;
	cin >> n;
	vii a(n);
	for(int i = 0; i < n; ++i){
		cin >> a[i].first >> a[i].second;
	}
	for(int i = 2; i < n; ++i){
		if(a[i].first == a[i].second and a[i -1].first == a[i -1].second and a[i -2].first == a[i -2].second){
			cout << "Yes\n";
			return;
		}
	}
	cout << "No\n";
	return;
	
}

signed main()
{
	faster;
#ifndef ONLINE_JUDGE
	freopen("ip.txt", "r", stdin);
	freopen("op.txt", "w", stdout);
#endif
	// int t; cin >> t; while(t--)
		solve();
	return 0;
}


//Author : Ankit Raj
//Problem Link :

/*Snippets*/
/*
sieve - prime factorization using sieve and primes in range
zpower - pow with mod
plate - Initial template
bfs 
dfs
fenwik - BIT
binary_search
segment_tree
*/
	

Measured memory_bytes: 3652
a, b = gets.split.map(&:to_i)
res = 0
arr = []
res_arr = []
i = 1
while i <= 999
  arr[i-1] = res += i
  res_arr[i-1] = arr[i-1] - arr[i-2] unless i === 1
  i += 1
end
puts arr[res_arr.index(b-a)] - b

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define MP make_pair
#define ii pair<int,int>
#define N 2*100005
using namespace std;
map<ii,int> mp;
ii p[N];
int a[2][N];
int n,k,l,x,y;
int bul(int q,int m) {
    if(a[q][m]==m) return m;
    return a[q][m]=bul(q,a[q][m]);
}
int main() {
    cin>>n>>k>>l;
    for(int i=1;i<=n;i++) {
        a[0][i]=a[1][i]=i;
    }
    for(int i=1;i<=k;i++) {
        cin>>x>>y;
        a[0][bul(0,x)]=bul(0,y);
    }
    for(int i=1;i<=l;i++) {
        cin>>x>>y;
        a[1][bul(1,x)]=bul(1,y);
    }
    for(int i=1;i<=n;i++) {
        p[i]=MP(a[0][bul(0,i)],a[1][bul(1,i)]);
        mp[p[i]]++;
    }
    for(int i=1;i<=n;i++) {
        cout<<mp[p[i]]<<' ';
    }
}


Measured memory_bytes: 15104
#include<bits/stdc++.h>
using namespace std;
#define sc(a) scanf("%d", &a)
#define sc2(a,b) scanf("%d%d", &a, &b)
#define sc3(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define pri(x) printf("%d\n", x)
#define mp make_pair
#define pb push_back
#define BUFF ios::sync_with_stdio(false);
#define imprime(v) for(int X=0;X<v.size();X++) printf("%d ", v[X]); printf("\n");
#define endl "\n"
const int INF= 0x3f3f3f3f;
const long double pi= acos(-1);
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector< vector< int > > vvi;
const int MOD=1e9+7;
const ll LINF=0x3f3f3f3f3f3f3f3f;

int gcd(int a, int b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
int n, k;
int a[100005];
set<int> st;
int main() {
  sc2(n, k);
  for(int i = 0; i < n; i++) {
    sc(a[i]);
    st.insert(a[i]);
  }
  int g = a[0];
  for(int i = 1; i < n; i++) {
    g = gcd(g, a[i]);
  }
  if(k % g != 0) {
    puts("IMPOSSIBLE");
    return 0;
  }
  bool tem = false;
  for(int i = 0; i < n; i++) {
    if(a[i] >= k) {
      tem = true;
      if((a[i] - k) % g == 0) {
        puts("POSSIBLE");
        return 0;
      }
    }
  }
  puts("IMPOSSIBLE");
  return 0;
}

Measured memory_bytes: 5376
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    if(str.charAt(0) == '9' || str.charAt(1) == '9'){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 20564
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 2e5 + 5;

int n;
int d[N], c[N], fin[N];

pair<int, int> recur(int d, int c)
{
	if(c == 1)
		return {d, 0};
	int nw = d + d;
	int val = 10 * d + d;
	int step = 1;
	if(nw > 9)
	{
		step++;
		if(val % 9 == 0)
			nw = 9;
		else
			nw = val % 9;
	}
	pair<int, int> p;
	p = recur(nw, c / 2);
	p.second += (step * (c / 2));
	if(c % 2)
	{
		int nw2 = p.first + d;
		int val = 10 * p.first  + d;
		int step = 1;
		if(nw2 > 9)
		{
			step++;
			if(val % 9 == 0)
				nw2 = 9;
			else
				nw2 = val % 9;
		}
		p.first = nw2;
		p.second += step;
	}
	return p;
}

int32_t main()
{
	IOS;
	int ans = 0;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> d[i] >> c[i];
		pair<int, int> p = recur(d[i], c[i]);
		fin[i] = p.first;
		ans += p.second;
	}
	for(int i = 1; i + 1 <= n; i++)
	{
		int nw = fin[i];
		int d = fin[i + 1];
		int nw2 = nw + d;
		int val = 10 * nw  + d;
		int step = 1;
		if(nw2 > 9)
		{
			step++;
			if(val % 9 == 0)
				nw2 = 9;
			else
				nw2 = val % 9;
		}
		fin[i + 1] = nw2;
		ans += step;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const int INF{int(1e9)};

int main()
{
  int k;	cin >> k;
  string s; cin >> s;
  
  int n = s.size();
  
  if (n<=k) cout << s << endl;
  
  else if (n>k) {
    for (int i=0; i<k; i++) {
      
      cout << s[i] ;
    }
      cout << "..." << endl;
  }
}

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

int main(){
    string s;
    cin >> s;
    rep(i, 3){
        if( (int)s.at(i) ==  (int)s.at(i+1) ){
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>

using namespace std;

int main(){
   int R,G,B,n;
   cin>>R>>G>>B>>n;
   int ans=0;
   for(int r=0;r*R<=n;r++){
      for(int g=0;r*R+g*G<=n;g++){
         if((n-r*R-g*G)%B==0)ans++;
      }
   }

   cout<<ans<<endl;
}

   


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int ans[100010];
        memset(ans,0,sizeof(ans));
        for(int i=1;i<=n;i++)
        {
            int x;
            scanf("%d",&x);
            ans[x]++;
            ans[x+1]++;
            if(x-1>=0) ans[x-1]++;
        }
        int mx=0;
        for(int i=0;i<=100001;i++)
            mx=max(mx,ans[i]);
        cout<<mx<<endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include <iostream>

int main() {
	unsigned long n, h, w, a, b;
	std::cin >> n >> h >> w;

	unsigned long res = 0;
	for (unsigned long i = 0; i < n; ++i) {
		std::cin >> a >> b;
		if (a >= h && b >= w) {
			res++;
		}
	}
	std::cout << res << std::endl;
}

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

int main(){
	int H, W;
  	cin >> H >> W;

  	vector<char> s(H*W);
  	int h, w;
  	for(h=0; h<H; h++){
    	for(w=0; w<W; w++){
    		cin >> s[w+h*W];
    	}
    }

  	int ans=0, temp=0;
  	int up, down, left, right;
  	vector<int> yoko(H*W, 0), tate(H*W, 0);
  	for(h=0; h<H; h++){
    	for(w=0; w<W; w++){
        	if(s[w+h*W] == '.'){
              	if(w==0 || yoko[w-1 +h*W] == 0){
                	for(right=w; right<W; right++){
                    	if(s[right+h*W] == '.') yoko[w+h*W]++;
                        else break;
                    }
                }
              	else yoko[w+h*W] = yoko[w-1 +h*W];

              	if(h==0 || tate[w+(h-1)*W] == 0){
                	for(down=h; down<H; down++){
                    	if(s[w+down*W] == '.') tate[w+h*W]++;
                        else break;
                    }
                }
              	else tate[w+h*W] = tate[w+(h-1)*W];
              	
              	temp = yoko[w+h*W] + tate[w+h*W] - 1;
            	if(ans < temp) ans = temp;
          	}
        }
    }

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

Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
char T;int l,a,b,x[999],d[999],M,N,y[999],z[999],i,j;
main(){
while(1){
M=0;
memset(y,0,999);
cin>>b>>l;if(!l){break;}
for(i=1;i<=b;i++){
cin>>T>>x[i];
if(T=='L'){d[i]=0;M=max(M,x[i]);}
else{d[i]=1;M=max(M,l-x[i]);}
}
N=0;
for(i=1;i<M+2;i++){
memset(z,0,sizeof(z));
for(j=b;j>0;j--) {
if(!y[j]) {
if(!d[j]){
x[j]--;
}
else{
x[j]++;
}
if(x[j]<0||x[j]>l){
y[j]=1;
}
z[x[j]]++;
if(M+1==i){
if(N){
if(x[j]<0){N=j;}
}
else{
N=j;
}
}
}
}
for(j=b;j>0;j--){
if(z[x[j]]>1){
if(d[j]){d[j]=0;}
else{d[j]=1;}
}
}
}
printf("%d %d\n",M,N);
}
}

Measured memory_bytes: 1160
using System;
using System.Collections;

namespace aoj1166
{
    class Program
    {
        static void Main()
        {
            while (true)
            {
                string wh = Console.ReadLine();
                string[] whs = wh.Split(' ');
                int w = int.Parse(whs[0]);
                int h = int.Parse(whs[1]);
                
                if (w == 0 || h == 0)
                    break;

                int[,] xwall = new int[w, h - 1];
                int[,] ywall = new int[w - 1, h];
                for (int i = 0; i < h; ++i)
                {
                    wh = Console.ReadLine();
                    whs = wh.Split(' ');
                    for (int j = 0; j < w - 1; ++j) 
                        ywall[j, i] = int.Parse(whs[j + 1]);

                    if (i == h - 1)
                        break;

                    wh = Console.ReadLine();
                    whs = wh.Split(' ');
                    for (int j = 0; j < w; ++j)
                        xwall[j, i] = int.Parse(whs[j]);
                }

                int[,] node = new int[w, h];
                
                Queue xq = new Queue();
                Queue yq = new Queue();
                
                for (int i = 0; i < w; ++i) 
                {
                    for (int j = 0; j < h; ++j) 
                    {
                        node[i, j] = 0;
                    }
                }
                node[0, 0] = 1;
                
                xq.Enqueue(0);
                yq.Enqueue(0);

                while (xq.Count > 0) 
                {
                    int nx = (int)xq.Dequeue();
                    int ny = (int)yq.Dequeue();

                    if (nx > 0 && ywall[nx - 1, ny] == 0 && (node[nx - 1, ny] == 0 || node[nx - 1, ny] > node[nx, ny] + 1)) 
                    {
                        node[nx - 1, ny] = node[nx, ny] + 1;
                        xq.Enqueue(nx - 1);
                        yq.Enqueue(ny);
                    }
                    if (ny > 0 && xwall[nx, ny - 1] == 0 && (node[nx, ny - 1] == 0 || node[nx, ny - 1] > node[nx, ny] + 1))
                    {
                        node[nx, ny - 1] = node[nx, ny] + 1;
                        xq.Enqueue(nx);
                        yq.Enqueue(ny - 1);
                    }
                    if (nx < w - 1 && ywall[nx, ny] == 0 && (node[nx + 1, ny] == 0 || node[nx + 1, ny] > node[nx, ny] + 1))
                    {
                        node[nx + 1, ny] = node[nx, ny] + 1;
                        xq.Enqueue(nx + 1);
                        yq.Enqueue(ny);
                    }
                    if (ny < h - 1 && xwall[nx, ny] == 0 && (node[nx, ny + 1] == 0 || node[nx, ny + 1] > node[nx, ny] + 1))
                    {
                        node[nx, ny + 1] = node[nx, ny] + 1;
                        xq.Enqueue(nx);
                        yq.Enqueue(ny + 1);
                    }
                }
                Console.WriteLine(node[w - 1, h - 1].ToString());
            }
        }
    }
}

Measured memory_bytes: 5864
#include <stdio.h>

int s[100];
int main(void)
{
	int i, n, max;
	
	while (scanf("%d", &n) != EOF){
		s[n - 1]++;
	}
	
	max = 0;
	for (i = 0; i < 100; i++){
		if (max < s[i]){
			max = s[i];
		}
	}
	
	for (i = 0; i < 100; i++){
		if (max == s[i]){
			printf("%d\n", i + 1);
		}
	}
	
	return 0;
}

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

using namespace std;

char box3[5][5] = {
"aab",
"c.b",
"cdd"
};

char box4[5][5] = {
"aabc",
"ccbc",
"dbaa",
"dbcc"
};

char box5[6][6] = {
"a.bbc",
"a.c.c",
"ddcbb",
"bb.ac",
".ccac"
};

char box6[7][7] = {
"aabbaa",
"bc..b.",
"bc..b.",
"..ca.a",
"..ca.a",
"aabbcc"
};

char box7[8][8] = {
"a...baa",
"a.a.b..",
"bbacc..",
".cca.aa",
".a.a.bb",
"bab....",
"b.baa.."
};

int dp[1050],pre[1050];
char ans[1050][1050];

int main()
{
	int n;
	scanf("%d",&n);
	if(n <= 2)
	{
		printf("-1\n");
	}
	else if(n % 3 == 0)
	{
		for(int i = 1;i <= n; ++ i)
			for(int j = 1;j <= n; ++ j)
				ans[i][j] = '.';
		for(int i = 1;i <= n;i += 3)
		{
			for(int j = 0;j < 3; ++ j)
				for(int k = 0;k < 3; ++ k)
					ans[i + j][i + k] = box3[j][k];
		}
		for(int i = 1;i <= n; ++ i)
			printf("%s\n",ans[i] + 1);
	}
	else
	{
		dp[0] = 1;
		for(int i = 0;i <= 1000; ++ i)
		{
			if(!dp[i]) continue;
			if(!dp[i + 4]) dp[i + 4] = 1,pre[i + 4] = i;
			if(!dp[i + 5]) dp[i + 5] = 1,pre[i + 5] = i;
			if(!dp[i + 6]) dp[i + 6] = 1,pre[i + 6] = i;
			if(!dp[i + 7]) dp[i + 7] = 1,pre[i + 7] = i;
		}
		for(int i = 1;i <= n; ++ i)
			for(int j = 1;j <= n; ++ j)
				ans[i][j] = '.';
		for(int i = 1,cur = n;i <= n;i += cur - pre[cur],cur = pre[cur])
		{
			int ln = cur - pre[cur];
			for(int j = 0;j < ln; ++ j)
				for(int k = 0;k < ln; ++ k)
					ans[i + j][i + k] = ln == 4 ? box4[j][k] : ln == 5 ? box5[j][k] : ln == 6 ? box6[j][k] : box7[j][k];
		}
		for(int i = 1;i <= n; ++ i)
			printf("%s\n",ans[i] + 1);
	}
}

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

int main() {
    //freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(NULL);

    int n;
    cin >> n;
    vector<int> a;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        a.push_back(x);
    }
    sort(a.begin(), a.end(), greater<int>());

    int cur = 0;
    int cnt = 1;
    long long res = 0;
    for (int i = 0; i < n - 1; i++) {
        
        res += a[cur];
        cnt++;

        if (cnt == 2) {
            cnt = 0;
            cur++;
        }
    }    

    cout << res;
    return 0;
}


Measured memory_bytes: 4284
#include <stdio.h>

int main(void)
{
	int k;
	int p;
	int n;
	int i;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		scanf("%d %d", &k, &p);
		
		if (k % p == 0){
			printf("%d\n", p);
		}
		else {
			printf("%d\n", k % p);
		}
	}
	
	return (0);
}

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

using namespace std;

typedef long double ld;
typedef double db;
typedef long long ll;

#define int long long
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) (signed)a.size()

const int INF = 1e18;
const ld EPS = 1e-7;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    int cnt0 = n / k, cnt1 = (k % 2 != 0 ? 0 : cnt0 + ((n % k >= (k / 2)) ? 1 : 0));
    int ans = cnt0 * cnt0 * cnt0 + cnt1 * cnt1 * cnt1;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<map>
#define ll long long
using namespace std;
const int mod=1e9+7;
map<ll,ll> DP;
ll DFS(ll x){
    if(DP[x])return DP[x];
    return DP[x]=(DFS(x>>1)+DFS(x-1>>1)+DFS(x-2>>1))%mod;
}
int main(){
	//freopen("a.in","r",stdin);
    ll n;scanf("%lld",&n);
    DP[0]=1;DP[1]=2;
    ll res=DFS(n)%mod;
    printf("%lld\n",res);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define fi first
#define se second
using namespace std;

ll dp[1000005]={0};


int main(){
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(int i=0;i<=n;i++)dp[i]=1000000000;
    for(int i=0;i<n;i++)cin>>a[i];
    dp[0]=0;
    
    for(int i=1;i<n;i++){
        for(int j=1;j<=k;j++)
        if(i-j>=0)dp[i]=min(abs(a[i]-a[i-j])+dp[i-j],dp[i]);
    }
    cout<<dp[n-1];
}

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

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int n,m,k,a,num[50],ans=0;

int main()
{
	cin>>n>>m;
	rep(i,n)
	{
		cin>>k;
		rep(j,k)
		{
			cin>>a;
			num[a]++;
		}
	}
	repn(i,m) if(num[i]==n) ans++;
	cout<<ans<<endl;
	rt0;
}

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

int main() {
  string s;
  cin>>s;
  if(s=="SUN"){
    cout<<7<<endl;
  }
  else if(s=="MON"){
    cout<<6<<endl;
  }
  else if(s=="TUE"){
  cout<<5<<endl;
  }
  else if(s=="WED"){
    cout<<4<<endl;
  }
  else if(s=="THU"){
    cout<<3<<endl;
  }
  else if(s=="FRI"){
    cout<<2<<endl;
  }
  else if (s=="SAT"){
    cout<<1<<endl;
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
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; }

using Graph = vector<vector<int>>;
bool visited[200010];

void dfs(int v, int d, Graph &G){
	if(visited[v]) return;
	visited[v] = true;
	for(auto nv : G[v]){
		if(visited[nv]) continue;
		dfs(nv, d+1, G);
	}
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    Graph G(n+m);
    rep(i, n){
    	int k;
    	cin >> k;
    	rep(j, k){
    		int l;
    		cin >> l;
    		G[i].push_back(n+l-1);
    		G[n+l-1].push_back(i);
    	}
    }
    dfs(0, 1, G);
    bool yes = true;
    rep(i, n){
    	if(!visited[i]) yes = false;
    }
    if(yes) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 8568
def iin(): return int(input())
def nl(): return list(map(int, input().split()))

n = iin()
a = nl()
b = nl()

cnt = 0
for i in range(n):
    if a[i] <= b[i]:
        cnt += (b[i] - a[i]) // 2
    else:# a[i] > b[i]
        cnt -= a[i] - b[i]
ans = 'Yes' if cnt >= 0 else 'No'
print(ans)

Measured memory_bytes: 4596
import math

#グラフの作成   
def make_list(V,E):
 
    edges = []
    path=[[0]*E for i in range(V) ]   #ルート作成に必要になる
    
    for i in range(V):
        a=[int(x) for x in str(input()).split()]
        for j in range(len(a)):
            #print("j",j)
            path[i][j]=i
           # if j!= i and a[j]==0:
                #a[j]=2000
                #path[i][j]=-2000
	
        edges.append((a))    #  有効辺グラフ
	

   
     
    return edges ,path


#フロイド・ワーシャル
def warshall_floyd(glath,path):
	
	for k in range(len(glath)):
		for i in range(len(glath)):
			for j in range(len(glath[i])):
				if glath[i][j] > glath[i][k] + glath[k][j]:
                                   glath[i][j] = glath[i][k] + glath[k][j]
                                   path[i][j] = path[k][j]
				#glath[i][j]= min(int(glath[i][j]),int(glath[i][k])+int(glath[k][j]))
				
	return glath,path





H, W = [int(x) for x in str(input()).split()]  #グラフの大きさ 

cost_graph,graph=make_list(10,10)
wall ,wall_graph= make_list(H,W)
    #print(cost_graph)

un_label=[]
for i in wall:
   for j in i: 
            if j !=-1 and j!=1:
                 un_label.append(j)
cost=0
 
all_cost,all_graph=warshall_floyd(cost_graph,graph)
    
   

for i in un_label:
        cost+=all_cost[i][1]

print(cost)

Measured memory_bytes: 4212
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static System.Array;

class Program
{
    public static void Main()
    {
        var n = int.Parse(ReadLine());
        var a = ReadLine().Split().Select(int.Parse).ToArray();
        int count = 0;
        for(int i = 0; i < n; i += 2)
        {
            if(a[i] % 2 == 1)
                count++;
        }
        WriteLine(count);
    }
}


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n;cin >> n;
    vector<lint> a(n),v(3);
    lint x;
    REP(i,n){
        cin >> x;
        v[(x % 2 == 0) + (x % 4 == 0)]++;
    }
    bool ans;
    if(v[1]>0){
        ans = v[2] >= v[0];
    }else
    {
        ans = v[2] >= v[0] - 1;
    }
    
    cout << (ans?("Yes"):"No") << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
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;
}

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

namespace detail {
template <typename T, std::size_t NDIMS>
struct vector_builder {
  using type = std::vector<typename vector_builder<T, NDIMS - 1>::type>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    const auto vec = std::vector<T>(dims.empty() ? 0 : dims.back(), v);
    if (!dims.empty()) dims.pop_back();
    return vector_builder<std::vector<T>, NDIMS - 1>::make(dims, vec);
  }
};

template <typename T>
struct vector_builder<T, 1> {
  using type = std::vector<T>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    return type(dims.empty() ? 0 : dims.back(), v);
  }
};
}  // namespace detail

template <typename T, typename... SIZE_T>
auto exvector(const T& v, SIZE_T... dims) {
  static_assert(sizeof...(dims) != 0, "invalid dimension");
  std::vector<std::size_t> vec_dims{dims...};
  return detail::vector_builder<T, sizeof...(dims)>::make(vec_dims, v);
}

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T& data, vector<int>& iter) {
  cout << data << " ";
}
template <typename T>
void dump(const vector<T>& data, vector<int>& iter) {
  for (auto elem : data) dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>>& data, vector<int>& iter) {
  for (auto elem : iter) {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++) {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T>& data, int dummy) {
  for (int i = 0; i < data.size(); i++) {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T& data) {  // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

void solve(long long N, std::vector<std::string> ss) {
  LL ans = 0;
  for (auto s : ss) {
    for (int i = 0; i < (int)s.size() - 1; i++) {
      if (s[i] == 'A' && s[i + 1] == 'B') ans++;
    }
  }

  int bs = 0;
  int as = 0;
  int cs = 0;
  for (auto s : ss) {
    if (s[0] == 'B') bs++;
    if (s[s.size() - 1] == 'A') as++;
    if (s[0] == 'B' && s[s.size() - 1] == 'A') cs++;
  }
  ans += min(as, bs);
  if (as > 0 && as == bs && as == cs) ans--;
  cout << ans << endl;
}

int main() {
  cout << setprecision(10);
  long long N;
  scanf("%lld", &N);
  std::vector<std::string> s(N);
  for (int i = 0; i < N; i++) {
    std::cin >> s[i];
  }
  solve(N, std::move(s));
  return 0;
}


Measured memory_bytes: 768
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        k: usize,
        d: [usize;k],
    }

    let mut ok: bool = true;
    let mut ok1: bool = true;
    let mut not_d: Vec<usize> = Vec::new();

    for i in 0..10 {
        for j in 0..k {
            if i!=d[j] {
                continue;
            } else {
                ok = false;
            }
        }
        if ok {
            not_d.push(i);
        } else {
            ok = true;
        }
    }
    ok = false;
    let nl = not_d.len();
    for i in n..10*n+1 {
        let mut x = i;
        while x!=0 {
            let r = x%10;
            ok = false;
            for j in 0..nl {
                if r==not_d[j] {
                    ok = true;
                    break;
                } 
            }
            x /= 10;
            if ok==false {
                ok1 = false;
                break;
            }
        }
        if ok1==true {
            println!("{}", i);
            return;
        } else {
            ok1 = true;
        }
    }

}


Measured memory_bytes: 2136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7,INF=1e17;
const int iINF=1e9;
int main(){
	char a,b;
	cin>>a>>b;
	if(a==b)cout<<"="<<endl;
	else if(a>b)cout<<">"<<endl;
	else cout<<"<"<<endl;
	
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
    int A, B; cin >> A >> B;
    if (A+B > 9) cout << "error" << endl;
    else cout << A + B << endl;
}



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

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

int main(){
    int H, W;
    cin >> H >> W;
    string S[100];
    for(int i=0; i<H; i++) cin >> S[i];

    vector<vector<int>> dist(H+1, vector<int>(W+1, 1e9));
    dist[0][0] = (S[0][0] == '#');
    for(int i=0; i<H; i++) for(int j=0; j<W; j++){
        if(i<H-1) chmin(dist[i+1][j], dist[i][j] + (S[i][j] == '.' && S[i+1][j] == '#'));
        if(j<W-1) chmin(dist[i][j+1], dist[i][j] + (S[i][j] == '.' && S[i][j+1] == '#'));
    }
    cout << dist[H-1][W-1] << endl;
    return 0;
}


Measured memory_bytes: 256
<?php
$array_data=array();
$array_temp=array();
$input=trim(fgets(STDIN));

while($input<>""){
	$array_data[]=$input;
	$input=trim(fgets(STDIN));
}


// print_r($array_data);

foreach($array_data as $val){

	$array_temp[]=explode(" ",$val);
}

// print_r($array_temp);

// ?????????????´????????????????
array_pop($array_temp);

foreach($array_temp as $arr){

	printf("%d\n",mycalc($arr));
}

function mycalc($v){

	// print_r($v);
	if($v[1]=="?"){

		break;

	}

	switch($v[1]){

		case "+":

			$result=$v[0]+$v[2];
			break;

		case "-":

			$result=$v[0]-$v[2];
			break;

		case "/":

			$result=floor($v[0]/$v[2]);
			break;

		case "*":

			$result=$v[0]*$v[2];
			break;


	}

	return $result;


}

Measured memory_bytes: 15424
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a+b>c+d)
    {
    	cout<<"Left"<<endl;
    	
    }else
    	{
    		if(a+b<c+d)
    		{
    			cout<<"Right"<<endl;
    		}
    		else
    		{
    			cout<<"Balanced"<<endl;
    		}
    	}
}

Measured memory_bytes: 256
def main():
  t = input().split(" ")
  A, B, C = int(t[0]), int(t[1]), int(t[2])
  M = max(A, B, C)
  n = (M-A)//2 + (M-B)//2 + (M-C)//2
  r = (M-A)%2 + (M-B)%2 + (M-C)%2
  if r == 1:
    n += 2
  elif r == 2:
    n += 1
  print(n)
main()

Measured memory_bytes: 3064
N = int(input())
As = list(map(int,(input().split())))

As.sort()
# print(As)

all_nums = [0] * (As[-1] + 1)

for A in As:
    all_nums[A] += 1
#print(all_nums)
dup = 0

for i, num in enumerate(all_nums):
    if num == 0: #その数が一つもないなら無視
        continue
    if num > 1: #同じ数が複数ある場合はあとで除くためにカウント
        dup += num
    j = 2
    while i * j <= As[-1]:
        all_nums[i*j] = 0
        j += 1
    #print(all_nums)

print(sum(all_nums)-dup)


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

	lli n;
	cin>>n;

	vector<lli> p(n);
	REP(i,0,n)cin>>p[i];
	lli cnt=0;
	lli ansMin=INF;

	REP(i,0,n){
		if(ansMin>p[i]){
			cnt++;
			ansMin=p[i];
		}
	}
	cout<<cnt<<endl;

	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>
int main(){
    long l, r, i, j, k, s, s1;
    long min = s1 = 2020;
    long mod = 2019;
    int count = 0;
    scanf("%ld %ld", &l, &r);
    for(i = l; i < l+2019; i++){
        count = 0;
        for(j = i + 1; j <= r; j++){
            s = (i*j)%mod;
            if(min > s) min = s;
            count++;
            if(count > 2020)break;
        }
    }
    printf("%ld\n", min);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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 int INF=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}


int main() {
  int x,n;
  cin>>x>>n;
  vector<int>p(n);
  for(int i=0;i<n;i++){
    cin>>p[i];
  }
  int ans=9999;
  int k=0;
  for(int i=0;i<=101;i++){
    bool ok=true;
    for(int j=0;j<n;j++){
     if(i==p[j]){ok=false;}
    }
    if(ok){if(ans>abs(i-x)){ans=abs(i-x);k=i;}
  }
  }
  cout<<k<<endl;
  return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define VAL 100000
#define ll  long  long
#define INF 1000000000000000000LL
#define pll pair<long long , long long>
const int MAX=5e6+9;
const ll MOD=1e9+7;
const int TOT_PRIMES=19;
const int MAX_A=70;
using namespace std;
int main() 
{
    string s;
    cin>>s;
    int rem =0;
    for(int i=0;i<s.size();i++)
        rem = (rem+(s[i]-'0'))%9;
    if(rem==0)
        cout<<"Yes";
    else
        cout<<"No";

}


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

using namespace std;

typedef long long ll;

const int MAXN = 300005;

int cnt[MAXN];

int N, A, B;

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> N >> A >> B;
	if (A + B - 1 > N || (ll)A * B < N)
		cout << -1 << endl;
	else
	{
		int tot = N;
		for (int i = 1; i <= A; i++)
			--tot;
		cnt[1] += B - 1, tot -= B - 1;
		for (int i = 2; i <= A && cnt; i++)
		{
			if (tot >= B - 1)
				cnt[i] += B - 1, tot -= B - 1;
			else
				cnt[i] += tot, tot = 0;
		}
		for (int i = 1; i <= A; i++)
			cout << N - A + i << " ";
		int cur = 0;
		for (int i = 1; i <= A; i++)
		{
			for (int j = 1; j <= cnt[i]; j++)
				cout << cur + cnt[i] - j + 1 << " ";
			cur += cnt[i];
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3072
package main

import (
	"fmt"
)

func main() {
	var w, h int

	for {
		fmt.Scan(&h, &w)

		if w == 0 && h == 0 {
			break
		}

		for i := 0; i < h; i++ {
			for j := 0; j < w; j++ {
				if (i+j)%2 == 0 {
					fmt.Print("#")
				} else {
					fmt.Print(".")
				}
			}
			fmt.Println()
		}
		fmt.Println()
	}
}



Measured memory_bytes: 1156
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define clr(s, x) memset(s, x, sizeof(s))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
inline int read(){int r=0;char c=getchar();while(c<'0'||c>'9') {c=getchar();}while(c>='0'&&c<='9') {r=r*10+c-'0';c=getchar();}return r;}
inline ll readll(){ll r=0;char c=getchar();while(c<'0'||c>'9') {c=getchar();}while(c>='0'&&c<='9') {r=r*10+c-'0';c=getchar();}return r;}
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
inline ll gcd(ll a,ll b){while(b^=a^=b^=a%=b);return a;}
const double eps = 1e-8;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 1e6+100;
const int MAXM = 1e5;
ll dp[MAXN];
ll v[MAXN],w[MAXN];
int main(){
	ll n,s;
	cin>>n>>s;
	for(ll i=1;i<=n;i++){
		cin>>w[i]>>v[i];
	}
	memset(dp,0,sizeof(dp));
	for(ll i=1;i<=n;i++){
		for(ll j=s;j>=w[i];j--){
			dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
		}
	}
	cout<<dp[s]<<endl;
	return 0;
}


Measured memory_bytes: 11392
INF, MAX_N = 1e9, 100000
coins = set()
coins.add(1)
six, nine = 6, 9
while six <= MAX_N:
    coins.add(six)
    six *= 6
while nine <= MAX_N:
    coins.add(nine)
    nine *= 9
coins = list(coins)

count = {}
for coin in coins:
    count[coin] = 1

for n in range(1, MAX_N + 1):
    if n in count.keys():
        continue
    count[n] = INF
    for coin in coins:
        if n - coin < 0:
            continue
        count[n] = min(count[n], count[n - coin] + 1)

print(count[int(input())])

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


int main()
{
	int k;
	string s;
	cin >> k;
	cin >> s;
	if (s.length()<=k)
	{
		cout << s;
	}
	else {
		cout << (s.substr(0,k)+"...");
	}

	return 0;
}



Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<string>
#include<set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<n; i++)

int n;

void dfs(string s, char mc){
  if(s.length()==n){
    cout << s << endl;
    return;
  }

  for(char c='a'; c<=mc; c++){
    dfs(s+c, mc==c?(char)(mc+1) : mc);
  }
}

int solve(){
  cin >> n;

  dfs("", 'a');
}

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


Measured memory_bytes: 1536
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define debug(x) cout << #x << " = " << x << '\n'
#define debug_arr(a , n) for(ll i = 0 ; i < n ; i++)cout << a[i] << " "
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<ll>
#define vll vector<ll> 
#define inf 1000000000
#define mod 1000000007

const ll max_n = 2e5 + 9;

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
ll dp[max_n];
ll t[4*max_n];
void update(ll v , ll l , ll r , ll pos){
    if(l == r){
        t[v] = dp[pos];
    }
    else{
        ll tm = (l + r) >> 1;
        if(pos <= tm){
            update(2*v , l , tm , pos);
        }
        else update(2*v+1 , tm+1 , r , pos);
        t[v] = max(t[2*v] , t[2*v+1]);
    }
}
ll query(ll v , ll tl , ll tr , ll l , ll r){
    if(l > r)return -1;
    if(l == tl && r == tr){
        return t[v];
    }
    ll tm = (tl + tr) >> 1;
    return max(query(2*v, tl , tm , l , min(r, tm)) , query(2*v+1 , tm + 1 , tr , max(l , tm+1) , r));
}
int main()
{
    ll n;
    cin >> n;

    ll h[n] , a[n];
    for(ll i = 0 ; i < n ; i++)
        cin >> h[i];
    
    for(ll i = 0 ; i < n ; i++)
        cin >> a[i];
    
    for(ll i = 0 ; i < n ; i++){
        ll maximum = query(1 , 0 , n , 0 , h[i]);
        dp[h[i]] = max(dp[h[i]] , maximum + a[i]);
        update(1 , 0 , n , h[i]);
    }
    
    ll max1 = -1;
    for(ll i = 0 ; i <= n ; i++)
        max1 = max(dp[i] , max1);
    
    cout << max1 << endl;
    return 0;
}

Measured memory_bytes: 11008
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define pb push_back
#define vi vector<int >
#define vii vector < pair<int ,int > >
#define IO ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define IOfiles freopen("input.txt","r+",stdin) ; freopen("output.txt","w+",stdout)
#define PI 3.14159265
const long long mod = 1e9 + 7LL;
typedef long long ll;
typedef pair<int, int> ii;
typedef double db;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;}
ll pwr(ll x , ll n) { ll ans = 1; while (n) {ans *= x; n--;} return ans;}

int arr[10];
int n,m,q;
int rel[55][4];
int ans;
void foo(int i,int s){
    if(i==n){
        int tmp=0;
        for(int j=0;j<q;j++){
            int a,b,c,d;
            a=rel[j][0];
            b=rel[j][1];
            c=rel[j][2];
            d=rel[j][3];
            if(arr[b-1]-arr[a-1]==c)
                tmp+=d;
        }
        ans=max(ans,tmp);
        return;
    }
    for(int j=s;j<=m;j++){
        arr[i]=j;
        foo(i+1,j);
    }
}

int main()
{
    IO;
    cin>>n>>m>>q;
    for(int i=0;i<q;i++){
        cin>>rel[i][0]>>rel[i][1]>>rel[i][2]>>rel[i][3];
    }
    ans=0;
    foo(0,1);
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main() {
	string S;
	cin >> S;
	if (S <= "2019/04/30") {
		cout << "Heisei" << endl;
	}
	else {
		cout << "TBD" << endl;
	}
	return 0;

}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;

int main(){
	ll n,m,k,in;
	cin >> n >> m >> k;
	vector<ll> a(n+1,0),b(m+1,0);
	REP(i,n){
		cin >> in;
		a[i+1] = a[i]+in;
	}
	REP(i,m){
		cin >> in;
		b[i+1] = b[i]+in;
	}
	
	ll best=m,ans=0;
	REP(i,n+1){
		if(a[i] > k) break;
		for(int j=best; j >= 0; j--){
			if(k >= a[i]+b[j]){
				best = j;
				ans = max(ans, (ll)i+j);
				break;
			} 
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
#define ll long long;
int main(){
  int n,f=0;
  char a;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a;
    if(a=='Y')f=1;
  }
  cout<<(f?"Four":"Three")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstring>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <memory.h>
using namespace std;
typedef long long ll;
typedef long double ldbl;

char s[11];

int main() {
  scanf("%s", s);
  puts((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3]) ? "Yes"
                                                                        : "No");
  return 0;
}

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

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

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define ALL(v) ((v).begin(), (v).end())

int main() {
    int L;
    cin >> L;
    int siz = 0;
    while(L>=(1<<(siz+1)))siz++;
    vector<P> v[25];
    REP(i,siz){
        v[i].push_back({i+1,0});
        v[i].push_back({i+1,1<<(siz-i-1)});
    }
    int t = 1<<siz;
    for(int i=0;i<siz;i++){
        if((L>>(siz-i-1))&1){
            v[0].push_back({i+1,t});
            t += (1<<(siz-i-1));
        }
    }
    int M=0;
    REP(i,siz)M += v[i].size();
    cout << siz+1 << " " << M << endl;
    REP(i,siz){
        for(auto it : v[i]){
            cout << i+1 << " " << it.first+1 << " " << it.second << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256