akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
#define All(x) (x).begin(),(x).end()
#define RAll(x) (x).rbegin(),(x).rend()


int main(){
	ll X, Y, A, B, C;
	cin >> X >> Y >> A >> B >> C;
	vector<ll> P(A), Q(B), R(C);
	for(auto &t : P) cin >> t;
	for(auto &t : Q) cin >> t;
	for(auto &t : R) cin >> t;
	//sort(All(p));
	//sort(All(q));
	//sort(All(r));
	priority_queue<pair<ll,int>> pq;
	for(auto t: P) pq.push({t,1});
	for(auto t: Q) pq.push({t,2});
	for(auto t: R) pq.push({t,3});
	ll ans = 0;
	ll r = 0, g = 0, n = 0;
	while(!pq.empty()) {
		auto tmp = pq.top();
		pq.pop();
		if(tmp.second == 1 and r < X) {
			r++;
			ans += tmp.first;
		}
		if(tmp.second == 2 and g < Y) {
			g++;
			ans += tmp.first;
		}
	   	if(tmp.second == 3)	{
			n++;
			ans += tmp.first;
		}
		if(r + g + n == X + Y) {
			break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 12780
# include <bits/stdc++.h>
using namespace std;
inline int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(!isdigit(ch))  
	{
		if(ch=='-') w=-1;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		s=(s<<1)+(s<<3)+ch-'0';
		ch=getchar();
	}
	return s*w;
}
string s;
int n;
bool check(int l)
{
	if(s[l]=='A'&&s[l+1]=='B'&&s[l+2]=='C') return 1;
	return 0;
}
int ans;
int main()
{
	n=read();
    cin >> s;
    for(int i=0;i<=n-3;i++) 
    {
        if(check(i)) 
        {
 			++ans;
        }
    }
    printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define cnt(v, x) count(all(v), x)
#define el "\n"
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
typedef long long lint;

lint dx[8] = { 0,1,1,1,0,-1,-1,-1 },
	 dy[8] = { 1,1,0,-1,-1,-1,0,1 };

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

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

	lint n;
	cin >> n;
	if (n % 2)co(n * 2);
	else co(n);
	gc();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rp(i,n) for (int i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define all_acc(x) (x).begin(), (x).end(), 0LL
#define int long long
#define absSort(v) sort(a.begin(), a.end(), [](int i, int j) -> bool { return abs(i) < abs(j); });
using namespace std;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
using ll = long long;
double pi=3.14159265359;

//出力するよ
void output_tate(vector<int> s){
    int n = s.size();
    for (int i = 0; i < n; i++){
        //if (i != 0)
        //    cout << " ";
        cout << s[i]<<endl;
    }
    //cout << endl;
}

void output_yoko(vector<int> s){
    int n = s.size();
    for (int i = 0; i < n; i++){
        if (i != 0)
            cout << " ";
        cout << s[i];//<<endl;
    }
    cout << endl;
}

int MOD = pow(10, 9) + 7;

int kaijou(int n){
    if(n==0) return 1;
    else{
        return ((n%MOD)*(kaijou(n-1)%MOD))%MOD;
    }
}

bool ispow(int n){
    int rn=sqrt(n);
    if(rn*rn==n) return true;
    else return false;
}

map<int,int> soinsu;

void soinsuu(int n){
    vector<pair<int,int>> ret;
    for(int i=2;i*i<=n;i++){
        if(n%i !=0) continue;
        int ex=0;
        while(n%i ==0){
            ex++;
            n /= i; //n変更することで、それ以降の約数で割り切れることはない
        }
        ret.push_back(make_pair(i,ex));
    }
    //nが素数だった場合
    if(n!=1) ret.push_back(make_pair(n,1));

    for(auto p:ret){
        int i=p.first;
        int num=p.second;
        soinsu[i]+=num;
    }
}

bool check(int a,int b,int c){
    if(a<b){
        if(b<c) return true;
    }

    return false;
}

signed main() {
    int a,b,c; cin>>a>>b>>c;
    int k; cin>>k;
    int cnt=0;

    while(a>=b){
        b=b*2;
        cnt++;
    }

    while(b>=c){
        c=c*2;
        cnt++;
    }
    
    if(cnt<=k) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 3720
#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;
const int N = 100;
const LL INF = 2e9;
LL dp[N+1][N+1][3*N+1]; //dp[i][ct][sz] -> max value if you take exactly ct items of the first i, exact weight sz
LL w[N+1];
LL v[N+1];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n, W; cin >> n >> W;
	LL comW;
	for(int i = 1; i <= n; i++)
	{
		cin >> w[i] >> v[i];
		if(i==1) comW = w[i];
		w[i] -= comW;
	}

	for(int i = 0; i <= n; i++)
		for(int ct = 0; ct <= n; ct++)
			for(int sz = 0; sz <= 3*n; sz++)
				dp[i][ct][sz] = -INF;
	for(int i = 0; i <= n; i++)
		dp[i][0][0] = 0;
	for(int i = 1; i <= n; i++)
		for(int ct = 1; ct <= i; ct++)
			for(int sz = 0; sz <= 3*n; sz++)
				if(sz >= w[i] && dp[i-1][ct-1][sz-w[i]] >= 0)
					dp[i][ct][sz] = max(dp[i-1][ct-1][sz-w[i]]+v[i], dp[i-1][ct][sz]);
				else
					dp[i][ct][sz] = dp[i-1][ct][sz];

	LL ans = 0;
	for(int ct = 1; ct <= n; ct++)
		for(int sz = 0; sz <= min(3LL*n,W-comW*ct); sz++)
			ans = max(ans,dp[n][ct][sz]);

	cout<<ans<<endl;

	cout<<flush;
	return 0;
}

Measured memory_bytes: 24824
from enum import Enum
from queue import Queue
import collections

import sys
import math

class Info:
    def __init__(self,arg_start,arg_end,arg_S):
        self.start = arg_start
        self.end = arg_end
        self.S = arg_S

LOC=[]
POOL=[]

line = input()
loc = 0
sum_S = 0

for ch in line:
    if ch == '\\':
        LOC.append(loc)
    elif ch == '/':
        if len(LOC) ==0:
            continue
        tmp_start = int(LOC.pop())
        tmp_end = loc
        tmp_S = tmp_end-tmp_start
        sum_S += tmp_S

        while len(POOL) > 0:
            if POOL[-1].start > tmp_start and POOL[-1].end < tmp_end:
                tmp_S += POOL[-1].S
                POOL.pop()
            else:
                break
        POOL.append(Info(tmp_start,tmp_end,tmp_S))

    else:
        pass

    loc += 1
print("%d"%(sum_S))
print("%d"%(len(POOL)),end = "")

while len(POOL) > 0:
    print(" %d"%(POOL[0].S),end = "") #先頭から
    POOL.pop(0)

print()
    



Measured memory_bytes: 8072
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 55);

template <typename T> 
struct SegmentTree {
  
  int n;
  vector<T> node;
 
  T f(T a, T b) {return (a + b);}
 
  SegmentTree (int sz, T init = 0) {
    n = 1; while (n < sz) n <<= 1;
    node.assign(2*n, init);
  }
 
  void update(int k, T x) {
    k += (n - 1);
    node[k] += x;
    while (k > 0) {
      k = (k - 1) >> 1;
      node[k] = f(node[2*k+1], node[2*k+2]);
    } 
  }
 
  T query(int a, int b, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    if (r <= a || b <= l) return 0;
    if (a <= l && r <= b) return node[k];
    T vl = query(a, b, 2*k+1, l, (l+r)/2);
    T vr = query(a, b, 2*k+2, (l+r)/2, r);
    return f(vl, vr);
  }
 
  T getvalue(int k) {
    return query(k,k+1);
  }
 
};

int main(){ 
  int n, q;
  cin >> n >> q;
  SegmentTree<ll> seg(n);
  while (q--) {
    int a, x, y;
    cin >> a >> x >> y;
    if (a) cout << seg.query(x - 1, y) << endl;
    else seg.update(x - 1, y);
  }
  return 0;  
} 


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

}

Measured memory_bytes: 256
//

fun main() {
    intro_heuristicsa()
}

fun intro_heuristicsa() {
    val d = readLine()!!.toInt()
    val c = readLine()!!.split(" ").map { it.toInt() }
    val s = MutableList(d) { listOf<Int>()}
    repeat(d) {
        s[it] = readLine()!!.split(" ").map { it.toInt() }
    }
    var score = 0
    for (i in 0 until d) {
        val contest = i % 26
        score += s[i][contest]
        println(contest + 1)
    }
}


Measured memory_bytes: 40176
n,t=map(int,input().split())
ab=[]
for i in range(n):
    a,b=map(int,input().split())
    ab.append((a,b))
ab.sort()
am=ab[-1][0]
dp=[-1]*(t+am+1)
dp[0]=0


for j in range(n):
    for i in range(t-1,-1,-1):
        if dp[i]!=-1:
            dp[i+ab[j][0]]=max(dp[i+ab[j][0]],dp[i]+ab[j][1])
#print(dp)
print(max(dp))

Measured memory_bytes: 45416
def main():
    n, k = map(int, input().split()) 
    h = [int(input()) for _ in range(n)]
    h = sorted(h)
    ans = 10**9
    for i in range(n - k + 1):
        ans = min(ans, h[i + k - 1] - h[i])
        
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 8280
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>


using namespace std;

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


int main() {
	string s, t;
	cin >> s >> t;
	int sx = (int) s.size() - (int) t.size();
	int index = -1;
	for(int i = sx; i >= 0; i--) { 
		bool is_ok = true;
		for(int j = 0; j < t.size(); j++) {
			if (s[i + j] == '?') {
				continue;
			}
			if (s[i + j] == t[j]) {
				continue;
			}
			is_ok = false;
			break;
		}
		if (is_ok) {
			index = i;
			break;
		}
	}
	if (index == -1) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}

	for (int i = 0; i < t.size(); i++) {
		s[i + index] = t[i];
	}

	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '?') {
			s[i] = 'a';
		}
	}

	cout << s << endl;

	return 0;
}

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

#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,a,n) for(ll i=a;i<n;i++)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tiii;
typedef pair<ll, ll> pll;

const int INF = 100000000;
const ll LINF = 1e18+5;

ld distance(ld x1, ld y1, ld x2, ld y2) {
    return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}

int main() {
    ll N;
    cin >> N;
    ll X[50] = {};
    ll Y[50] = {};
    rep(i,N) {
        cin >> X[i] >> Y[i];
    }
    ld R = 10000.0;
    ld lhs = 0.0;
    ld rhs = 20000.0;
    rep(i,50) {
        R = (lhs + rhs) / 2.0;
        vector<ld> X1;
        vector<ld> Y1;
        bool dameflag = false;
        rep(j,N) {
            REP(k,j+1,N) {
                ld dis = distance(X[j],Y[j],X[k],Y[k]);
                dis/=2.0;
                if(R+0.000000001<dis) dameflag = true;
                else {
                    ld h = sqrt(R*R - dis*dis);
                    ld midx = (ld)(X[j]+X[k])/2.0;
                    ld midy = (ld)(Y[j]+Y[k])/2.0;
                    if(X[j]!=X[k]) {
                        if(Y[j]!=Y[k]) {
                            ld a = (ld)(Y[j]-Y[k])/(ld)(X[j]-X[k]);
                            ld difx = h*sqrt(a*a/(a*a+1.0));
                            X1.push_back(midx+difx);
                            X1.push_back(midx-difx);
                            Y1.push_back(midy-difx/a);
                            Y1.push_back(midy+difx/a);
                        } else {
                            X1.push_back(midx);
                            X1.push_back(midx);
                            Y1.push_back(midy+h);
                            Y1.push_back(midy-h);
                        }
                    } else {
                        X1.push_back(midx+h);
                        X1.push_back(midx-h);
                        Y1.push_back(midy);
                        Y1.push_back(midy);
                    }
                }
                if(dameflag) break;
            }
            if(dameflag) break;
        }
        if(dameflag) {
            lhs = R;
        } else {
            bool okflag = true;
            for(ll j=0;j<X1.size();j++) {
                okflag = true;
                rep(k,N) {
                    if(distance(X1[j],Y1[j],X[k],Y[k]) > R + 0.0000001) {
                        okflag = false;
                        break;
                    }
                }
                if(okflag) break;
            }
            if(okflag) {
                rhs = R;
            } else {
                lhs = R;
            }
        }
        X1.clear();
        Y1.clear();
    }
    cout << fixed;
    cout << setprecision(8) << (lhs+rhs)/2.0 << endl;
    return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int f(int n) {
  if(n % 2) return 3 * n + 1;
  else return n / 2;
}

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

  int n, m; cin >> n >> m;
  bitset<31> bs;
  for(int i=0;i<31;++i) {
    bs[i] = 1;
  }

  for(int i=0;i<n;++i) {
    int k; cin >> k;
    bitset<31> now;
    for(int j=0;j<k;++j) {
      int a; cin >> a;
      a--;
      now[a] = 1;
    }
    bs &= now;
  }

  cout << bs.count() << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        a = a^b;
        b = a^b;
        a = a^b;
    }
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }
    cout<<  ans << endl;
    }
}

void ys(){
    cout << "Yes" << endl;
}

void yb(){
    cout << "YES" << endl;
}

void ns(){
    cout << "No" << endl;
}

void nb(){
    cout << "NO" << endl;
}


void solve(void){
    string in;
    cin >> in;
    vector<int> s;
    rep(i,0,in.size()){
        s.push_back(in[i]-'0');
    }
    int ans = INF;
    rep(i,0,s.size()-2){
       ans = min(abs(s[i]*100+s[i+1]*10+s[i+2]-753),ans);
    }
    cout << ans << endl;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}

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

int main(){
    int n,x,res=0;
    cin >> n >> x;
    int a[110];
    for(int i=0;i<n;i++)cin >> a[i];
    sort(a,a+n);
    int sum=0;
    for(int i=0;i<n;i++){
        sum+=a[i];
        if(sum>x)break;
        res++;
    }
    if(sum<x && res==n)res--;
    cout << res << endl;
}

Measured memory_bytes: 256
N = int(input())
T, A = map(int, input().split())

H_list = list(map(int, input().split()))
ans_list = []

for i in H_list:
  kion = T - (i * 0.006)
  kion_abs = abs(kion - A)
  ans_list.append(kion_abs)

print(ans_list.index(min(ans_list))+1)


Measured memory_bytes: 38384
#include <stdio.h>

int main(void)
{
	int H = 0, W = 0, i, j;

	while(1)
	{
		scanf("%d %d", &H, &W);

		if (H == 0 && W == 0) break;

		for (i = 0; i < H; i++)
		{
			if (i == 0 || i == H - 1)
			{
				for (j = 0; j < W; j++)
				{
					printf("#");
				}
			}
			else
			{
				printf("#");
				for (j = 0; j < W - 2; j++)
				{
					printf(".");
				}
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
import java.util.*;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			int N=in.nextInt();//PC数
			int M=in.nextInt();//学生数
			if((N|M)==0)
				return;
			int r=in.nextInt();//利用記録数
			ArrayList<int []>AL=new ArrayList<int[]>(); 
			boolean login[][]=new boolean[M+1][1261];
			for(int i=0;i<r;i++)
			{
				int t=in.nextInt();//時刻
				int n=in.nextInt();//PCn
				int m=in.nextInt();//学生m
				int s=in.nextInt();//log_in log_out
				if(s==1)
				{
					AL.add(new int[]{n,m,t});
				}
				else //log_out
				{
					int x=0;
					for(int j=0;j<AL.size();j++)
					{
						int y[]=AL.get(j);
						if(y[0]==n&&y[1]==m)
						{
							x=y[2];//log_in時間
							AL.remove(j);
							break;
						}
					}
					for(int j=x;j<t;j++)
						login[m][j]=true;
				}
			}
			int q=in.nextInt();
			for(int i=0;i<q;i++)
			{
				int ts=in.nextInt();
				int te=in.nextInt();
				int m=in.nextInt();
				int ans=0;
				
				for(int j=ts;j<te;j++)
					if(login[m][j])
						ans++;
				System.out.println(ans);
			}
		}
	}

	static public void debug(Object... o)
	{
		System.err.println(Arrays.deepToString(o));
	}
}

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

int i,j,n;
string str;
long long a[200000];

int main(){
  long long ans = 100000000000;
  cin >> n;
  for(i = 0;i < n;i++) cin >> a[i];
  long long sum = 0;
  for(i = 0;i < n;i++) sum += a[i];
  long long l = 0,r = sum;
  for(i = 0;i < n-1;i++){
      l += a[i];
      sum -= a[i];
      long long dis = abs(l-sum);
      if(ans > dis) ans = dis;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#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>;
 
 
int main() {
    int n,m;
    cin >> n >> m;
    vector<int>a(m);
    vector<int>b(m);
    rep(i,m) cin >> a.at(i) >> b.at(i);
    rep(i,n){
        int count=0;
        rep(j,m){
            if(a.at(j)==i+1||b.at(j)==i+1)count++;
        }
        cout << count << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 文字列の入力
		String s = sc.next();
        int l=s.length();
        String o="Yes";
        for (int i=0;2*i+1<=l;i++){	//奇数文字目
            char a=s.charAt(2*i);
            if(a=='R' || a=='U' ||a=='D' ){

            }else{
                o="No";
                break;
            }
        }
        if(o.equals("Yes")){
            for (int i=0;2*i+2<=l;i++){	//偶数文字目
                char a=s.charAt(2*i+1);
                if(a=='L' || a=='U' ||a=='D' ){

                }else{
                    o="No";
                    break;
                }
            }
        }
          // 出力
          System.out.println(o);
      }
}

Measured memory_bytes: 23252
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main() {
  string s;
  cin >> s;
  if (s.size() == 2)
    cout << s << endl;
  else {
    reverse(s.begin(), s.end());
    cout << s << endl;
  }
}


Measured memory_bytes: 768
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;

namespace Print_a_Frame
{
    class Program
    {
        static void Main(string[] args)
        {
            String str;
            while ((str = Console.ReadLine()) != "0 0")
            {
                String[] ss = str.Split(' ');
                for (int i = 0; i < int.Parse(ss[0]); ++i)
                {
                    if (i == 0 || i == (int.Parse(ss[0]) - 1))
                    {
                        for (int j = 0; j < int.Parse(ss[1]); ++j)
                        {
                            Console.Write("#");
                        }
                        Console.WriteLine();
                    }
                    else
                    {
                        Console.Write("#");
                        for (int j = 0; j < int.Parse(ss[1]) - 2; ++j)
                        {
                            Console.Write(".");
                        }
                        Console.WriteLine("#");
                    }
                }
                Console.WriteLine();
            }
        }
    }
}


Measured memory_bytes: 8840
import java.util.Scanner;
public class Main {
	private static Scanner sc=new Scanner(System.in);
	private static int[] index=new int[6];
	public static void main(String[] args){
		for(int i=0;i<6;i++){
			index[i]=sc.nextInt();
		}
		String command=sc.next();
		for(int i=0;i<command.length();i++){
			move(command.charAt(i));
		}
		System.out.println(index[0]);
	}
	private static void move (char c){
		switch(c){
		case 'E':
			int tempE=index[0];
			index[0]=index[3];
			index[3]=index[5];
			index[5]=index[2];
			index[2]=tempE;
			break;
		case 'W':
			int tempW=index[0];
			index[0]=index[2];
			index[2]=index[5];
			index[5]=index[3];
			index[3]=tempW;
			break;
		case 'N':
			int tempN=index[0];
			index[0]=index[1];
			index[1]=index[5];
			index[5]=index[4];
			index[4]=tempN;
			break;
		case 'S':
			int tempS=index[0];
			index[0]=index[4];
			index[4]=index[5];
			index[5]=index[1];
			index[1]=tempS;
			break;
		}
	}
}

Measured memory_bytes: 26216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int N;//個数
  string C;//色
  int x;//色数
  cin >>N;
  x =0;
  
  rep(i,N){
    cin>>C;
    if(C=="Y"){
      x=4;
        break;
    }
      if(C!="Y"){
       x=3;
         continue;
      }
      }
  
  if(x==3){
   cout<<"Three"<<endl;
  }
  if(x==4){
    cout<<"Four"<<endl;
  }
}

Measured memory_bytes: 256
#指定数分の３つの整数を順番に受けてリストに入力
n = int(input())
a = [0]*n
b = [0]*n
c = [0]*n
for i in range(n):
    a[i],b[i],c[i] = map(int, input().split())

'''
前日までの選択による最大値が分かれば、当日の最適選択ができる
dpテーブルを３枠用意する形にして、下から順に更新していけば良い
'''

# 初日の効用
dp = []
dp.append([a[0],b[0],c[0]])

# ２日目以降のループ
for i in range(1,n):
    dp.append( [ \
        a[i] + max(dp[i-1][1],dp[i-1][2]), \
        b[i] + max(dp[i-1][0],dp[i-1][2]), \
        c[i] + max(dp[i-1][0],dp[i-1][1])  \
        ] )

print(max(dp[n-1][0],dp[n-1][1],dp[n-1][2]))


Measured memory_bytes: 34676
import java.util.*;

public class Main {
    static int cnt = 0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        String ans = "";
        selectionSort(A, N);
        for (int i = 0; i < N ; i++) {
            ans += A[i] + " ";
        }
        System.out.println(ans.substring(0, ans.length()-1));
        System.out.println(cnt);
    }

    static void selectionSort(int[] A, int N){
        int tmp;
        for (int i = 0; i < N; i++) {
            int min_j = i;
            for (int j = i; j < N; j++) {
                if(A[j] < A[min_j]) min_j = j;
            }
            if(A[i] != A[min_j]) cnt++;
            tmp = A[i];
            A[i] = A[min_j];
            A[min_j] = tmp;
        }
    }
}



Measured memory_bytes: 26392
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;
using plli=pair<ll,int>;
using vplli=vector<pair<ll,int>>;
using pllll=pair<ll,ll>;
using vpllll=vector<pair<ll,ll>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    string S;
    ll K;
    cin>>S>>K;
    int  s=S.size();
    //何文字目，そのままなら0,使った0の数
    vector<vvll> dp(s+1,vvll(2,vll(K+1,0)));
    dp[0][0][0]=1;
    rep(i,0,s){
        rep(j,0,2){
            rep(k,0,4){
                rep(l,0,10){
                    int d=S[i]-'0';
                    int ni=i+1;int nj=j;int nk=k;
                    if(l!=0)nk++;
                    if(nk>K)continue;
                    if(j==0){
                        if(d<l)continue;
                        if(d>l)nj=1;
                    }
                    dp[ni][nj][nk]+=dp[i][j][k];
                }
            }
        }
    }
    cout<<dp[s][0][K]+dp[s][1][K]<<endl;
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
 
using namespace std;

bool prime[200001];

void solve(){
	ll x; cin>>x;
	
	for(int i=2; i<200001; i++){
		if(!prime[i]){
			for(int j=2; i*j<=200000; j++){
				prime[i*j] = 1;
			}
		}
	}
	for(int i=2; i<=200000; i++){
		if(prime[i] == 0 && i>=x){
			cout<<i; break;
		}
	}


}


int main()
{ 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//cout<<fixed<<setprecision(12);
	
	int t =1; 
	//cin>>t;

	for(int i=1; i<=t; i++){
		solve();
		cout<<"\n";
	}
	return 0;

}




Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
int l[105];
int sum;
int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		scanf("%d", &l[i]);
	sort(l, l+n);
	for(int j = n - 2 ; j >= 0; j--)
		sum += l[j];
		if(l[n - 1] < sum) puts("Yes");
		else puts("No");

}




Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#include<string>
#include<sstream>
#include<stack>
#include<queue>
#include<list>
#define _USE_MATH_DEFINES

#include<math.h>
#include<unordered_map>

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

class Flood
{
public:
	int startStep;
	int volume;
};

int main()
{
	vector<Flood> floods;
	Flood flood;
	int memo[50000];

	string input;
	cin >> input;

	int nowFloor;
	int nowStep;

	nowFloor = 25000;
	nowStep = 0;

	for (int i = 0; i < 50000; i++)
	{
		memo[i] = -1;
	}

	memo[nowFloor] = nowStep;
	flood.startStep = nowStep;
	flood.volume = 0;

	for (char c : input)
	{
		nowStep++;
		switch (c)
		{
		case '\\':
			nowFloor++;
			memo[nowFloor] = nowStep;
			if (flood.volume != 0)
			{
				floods.push_back(flood);
				flood.volume = 0;
			}
			break;
		case '/':
			nowFloor--;
			if (memo[nowFloor] != -1)
			{
				flood.volume += (nowStep - memo[nowFloor] - 1);
				flood.startStep = memo[nowFloor];
				while (floods.size() != 0)
				{
					if (flood.startStep < floods.back().startStep)
					{
						flood.volume += floods.back().volume;
						floods.pop_back();
					}
					else
					{
						break;
					}
				}
			}
			memo[nowFloor] = nowStep;
			break;
		case '_':
			memo[nowFloor] = nowStep;
			break;
		default:
			cout << "illegal input" << endl;
		}
	}

	if (flood.volume != 0)
	{
		floods.push_back(flood);
		flood.volume = 0;
	}

	int sum = 0;

	for (int i = 0; i != floods.size(); i++)
	{
		sum += floods[i].volume;
	}

	cout << sum << endl;
	cout << floods.size();
	
	for (int i = 0; i != floods.size(); i++)
	{
		if (i == 0)
		{
			cout << " ";
		}
		cout << floods[i].volume;
		if (i != (floods.size() - 1))
		{
			cout << " ";
		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 3448
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            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)*) => {
        let $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")
    };
}

fn main() {

    let mut p = 1;
    let mut n = 0;

    input!{
        A: i32,
        B: i32,
    }

    while p < B {
        p += A - 1;
        n += 1;
    };

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


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 2e18;

struct path {
    int from, to, score;
};

signed main() {
    int N, M;
    cin >> N >> M;
    vector<path> edge;
    for (int i = 0; i < M; i++) {
        int A, B, C;
        cin >> A >> B >> C;
        --A;
        --B;
        edge.push_back({A, B, C * -1});
    }
    vector<bool> check(N, false);
    {
        vector<bool> checkS(N, false), checkE(N, false);
        checkS[0] = true;
        checkE[N - 1] = true;
        for (int i = 0; i < N; i++) {
            for (auto e : edge) {
                if (checkS[e.from]) checkS[e.to] = true;
                if (checkE[e.to]) checkE[e.from] = true;
            }
        }
        for (int i = 0; i < N; i++) check[i] = checkS[i] && checkE[i];
    }

    vector<int> ans(N, INF);
    ans[0] = 0;
    for (int i = 0; i < N; i++) {
        for (auto e: edge) {
            if (ans[e.to] > ans[e.from] + e.score) {
                ans[e.to] = ans[e.from] + e.score;
                if (i == N - 1 && check[e.to] && check[e.from]) {
                    cout << "inf" << endl;
                    return 0;
                }
            }
        }
    }
    cout << ans[N - 1] * -1 << endl;
}


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

using namespace std;

int main(){
  int H, W, K;
  cin >> H >> W >> K;
  
  vector<vector<char>> choco(H, vector<char>(W));
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> choco[i][j];
    }
  }
  
  int count = H + W + 1;
  for(int b = (1 << (H - 1)); b < (1 << H); b++){
    int n = 0;
    for(int i = 0; i < H; i++){
      if((1 << i) & b){
        n++;
      }
    }
    
    int cnt = n - 1;
    vector<int> bar(n, 0);
    vector<int> last(n, 0);
    for(int j = 0; j < W; j++){
      n = 0;
      for(int i = 0; i < H; i++){
        if(choco[i][j] == '1'){
          last[n]++;
        }
        if((1 << i) & b) n++;
      }
      
      for(int k = 0; k < bar.size(); k++){
        bar[k] += last[k];
      }
      
      for(int i = 0; i < bar.size(); i++){
        if(bar[i] > K){
          cnt++;
          for(int k = 0; k < bar.size(); k++){
            bar[k] = last[k];
          }
          break;
        }
      }
      
      for(int k = 0; k < bar.size(); k++){
        if(last[k] > K){
          cnt = H + W + 1;
        }
        last[k] = 0;
      }
      if(cnt == H + W + 1) break;
    }
    
    count = min(cnt, count);
  }
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

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

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.14159265358979323846;

void solve() {
    string s, t;
    cin >> s >> t;
    s += t[t.size() - 1];
    bool ans = s == t;
    cout << (ans ? "Yes" : "No") << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 3656
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<math.h>
#include <iomanip>

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

using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;

	string S;
	cin >> S;

	int d = 0;
	vector<int> V;

	while(d < N) {

		//最大手を求める。
		int x = M;
		while (x > 0) {
			if (N - x - d < 0) {
				x--;
				continue;
			}
			if (S[N - d - x] == '0')break;
			x--;
		}

		if (x == 0)break;

		d += x;
		V.push_back(x);
	}

	if (d != N) {
		cout << -1 << endl;
	}
	else {
		for (int i = V.size() - 1; i >= 0; i--) {
			cout << V[i] << " ";
		}
	}

	return 0;
}


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

using namespace std;

template <typename T>
using vec1 = vector<T>;

template <typename T>
T cin2var()
{
    T val;
    cin >> val;
    return val;
}

void sub()
{
    const auto N(cin2var<int64_t>());
    const auto M(cin2var<int64_t>());

    int64_t ok_count = 0;

    using AB = tuple<int64_t, int64_t>;
    priority_queue<AB> abs;
    for (auto i = 0; i < M; ++i) {
        const auto A(cin2var<int64_t>());
        const auto B(cin2var<int64_t>());
        if (N <= A) {
            // 交換可能
            ++ok_count;
            continue;
        }
        abs.push(make_tuple(A, B));
    }

    int64_t ans = 0;
    while (M - 1 > ok_count) {
        const auto& ab(abs.top());
        ans += N - get<0>(ab);
        ++ok_count;
        abs.pop();
    }
    cout << ans << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    sub();
    return 0;
}


Measured memory_bytes: 3172
n,m=map(int,input().split())
h=list(map(int,input().split()))

g=[[]for _ in range(n)]
for _ in range(m):
    a,b=map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)

ans=0
for i in range(n):
    M=max([h[c] for c in g[i]]+[0])
    if M<h[i]:
        ans+=1
print(ans)

Measured memory_bytes: 98152
import collections
import math


n = int(input())
aa = list(map(int, input().split()))
ls = [0] * (n+1)

c = collections.Counter(aa)

for i, j in c.items():
    ls[i] = j*(j-1)//2

total = sum(ls)

for i in aa:
    before = (c[i]-1)*(c[i]-2) // 2
    print(total - ls[i] + before)


Measured memory_bytes: 25892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3e5+5;
const ll mod = 1e9 + 7;
const ll INF = 1e9 + 7;
int a[100005];
int dis[100005],tot;
int main()
{
	int n,m;
	tot=0;

	cin>>n>>m;

	for (int q=0;q<m;q++) cin>>a[q];
	sort(a,a+m);
	int s=0;
	for (int q=1;q<m;q++)
	{
		dis[q]=a[q]-a[q-1];
		s+=dis[q];
	}

	sort(dis+1,dis+m,greater<int>() );
	for (int q=1;q<min(n,m);q++)
	s-=dis[q];

	cout<<s<<endl;

	

	return 0;
}

Measured memory_bytes: 1024
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());
        int y = Integer.parseInt(sc.next());
        int[] dis = new int[n];
        for(int i=1; i<=n; i++) {
            for(int j=i+1; j<=n; j++) {
                int s = min(j-i, min(sa(x, i)+1+sa(y, j), sa(y, i)+1+sa(x, j)));
                dis[s]++;
            }
        }
        for(int i=1; i<n; i++) {
            System.out.println(dis[i]);
        }
        
    }
    
    public static int min(int a, int b) {
        if(a <= b) return a;
        else return b;
    }
    static int sa(int a, int c) {
        if(a <= c) return c-a;
        else return a-c;
    }
}

Measured memory_bytes: 23252
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0]);
  var A = input[1].split(" ").map(i => parseInt(i));
  A.sort(function(a,b){return a-b});
  var anssub=[0];
  if(A[0]<=0&&A[A.length-1]>=0){
    var min=A[0];
    var max=A[A.length-1];
    A.splice(0,1);
    A.splice(A.length-1,1);
    for(var i=0;i<A.length;i++){
      if(A[i]<=0){
        anssub.push(max+" "+A[i]);
        max=max-A[i];
      }else{
        anssub.push(min+" "+A[i]);
        min=min-A[i];
      }
    }
    anssub.push(max+" "+min);
    anssub[0]=max-min;
  }else if(A[0]<0){
    var max=A[A.length-1]-A[0];
    anssub.push(A[A.length-1]+" "+A[0]);
    for(var i=1;i<N-2;i++){
      anssub.push(max+" "+A[i]);
      max=max-A[i];
    }
    anssub.push(max+" "+A[A.length-2]);
    anssub[0]=max-A[A.length-2];
  }else{
    var min=A[0]-A[A.length-1];
    anssub.push(A[0]+" "+A[A.length-1]);
    for(var i=1;i<N-2;i++){
      anssub.push(min+" "+A[i]);
      min=min-A[i];
    }
    anssub.push(A[A.length-2]+" "+min);
    anssub[0]=A[A.length-2]-min;
  }
  ans=anssub.join("\n");

  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 64328
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

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;}

typedef long long lint;

using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    int x,n;
    cin>>x>>n;
    int ans=600;
    vector<int>p(n);
    rep(i,n)cin>>p[i];
    rrep(i,102){
        if(abs(x-i)<=abs(x-ans)){
            bool flag=true;
            rep(j,n)if(i==p[j])flag=false;
            if(flag)ans=i;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    while(cin>>a>>b){
        if(a==0&&b==0)break;
        for(int i=0;i<a;i++){
            for(int j=0;j<b;j++){
                if((i+j)%2==0)cout << '#';
                else cout<<'.';
            }
            cout << endl;
        }
        cout << endl;
    }
}


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

int niz[100000];
int dp[100000];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n, k;
    cin >> n;
    cin >> k;
    dp[0] = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> niz[i];
        if(i > 0)
        {
            int mini = INT_MAX;
            for(int j = i-1, br = 0; j >= 0 && br < k; j--, br++)
            {
                mini = min(mini, dp[j] + abs(niz[j]-niz[i]));
            }
            dp[i] = mini;
        }
    }
    cout << dp[n-1];
    
    
    return 0;
}

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

using namespace std;
#define ll long long
#define ld long double

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    string s;
    cin >> s;
    int len = s.size(), ans = 0;;
    for(int i=0;i<len/2;i++) {
        if(s[i] != s[len-i-1]) ans++;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int size = (1 << N);

        int[] S = new int[size];
        boolean[] spawned = new boolean[size];
        spawned[size - 1] = true;

        for (int i = 0; i < size; i++) S[i] = sc.nextInt();

        Arrays.sort(S);

        List<Integer> active = new ArrayList<>();

        active.add(S[size - 1]);
        spawned[size - 1] = true;

        for (int i = 0; i < N; i++) {
            active.sort(Collections.reverseOrder());
            List<Integer> activated = new ArrayList<>();
            int next = size - 1;
            for (int slime : active) {
                while (next >= 0 && (S[next] >= slime || spawned[next])) {
                    next--;
                }

                if (next < 0) {
                    System.out.println("No");
                    return;
                }

                spawned[next] = true;
                activated.add(S[next]);
            }
            active.addAll(activated);
        }

        System.out.println("Yes");
    }
}


Measured memory_bytes: 93656
s = input()
prev = s[0]
n = len(s)
cnt= 0
L = [0]*(n+1)
R = [0]*(n+1)
for i in range(n):
    if s[i] =="<":
        cnt+=1
    else:
        cnt=0
    L[i+1] = cnt
s= s[::-1]
for i in range(n):
    if s[i] ==">":
        cnt+=1
    else:
        cnt=0
    R[i+1] = cnt
ans = 0
for i in range(n+1):
    ans+=max(L[i],R[-i-1])
print(ans)


Measured memory_bytes: 27560
// Created by martinezdiego on 19/5/19

#include <bits/stdc++.h>

using namespace std;

#define N 1000005

vector<pair<int,int>> adj[N];
int color[N];

void dfs(int node, int parent, long long distance) {
  for (auto current : adj[node]) {
    if (current.first != parent) {
      if ((distance + current.second)%2 == 0) color[current.first] = color[0];
      else color[current.first] = (color[0] + 1)%2;
      dfs(current.first, node, distance + (long long)current.second );
    }
  }  
}

int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n-1; i++) {
    int u,v,w;
    cin >> u >> v >> w;
    adj[u].push_back({v, w});
    adj[v].push_back({u, w});
  }
  color[0] = 0;
  dfs(1,0,0);
  for (int i = 1; i <= n; i++) {
    cout << color[i] << '\n';
  }
  return 0;
}


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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

ll gcd(ll a, ll b) {
  return (!a || !b) ? 0 : ((a % b == 0) ? b : gcd(b, a % b));
}

// ====================================================================

int main() {
  ll a, b;
  cin >> a >> b;
  cout << a * b / gcd(a, b) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <string>

using namespace std;

int main(){
    string s;
    char t = '0';
    int i=2,sum=0,gap,ans=10000,k;
    cin >> s;
    while( s[i]%t <10 && s[i]%t > 0){
        sum = 0;
        
        for(int j=i;j > i-3;j--){
       // cout <<  <<endl;
            k = i-j;
            sum += (s[j]%t)*pow(10,k);
            //cout << sum << " ";
        }
        //cout << sum << " ";
        gap = abs(753 -sum);
        if(gap < ans) ans = gap;
        i++;

    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int n;

  while(1){
    int star[31] = { 0 };
    cin >> n;
    if(n == 0) break;
    star[0] = 1;

    for(int i = 1; i <= n; i++){
      if(i > 0) star[i] += star[i-1];
      if(i > 1) star[i] += star[i-2];
      if(i > 2) star[i] += star[i-3];
    }
    
    cout << star[n]/3650 + 1 << endl;
  }

  return 0;
}

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

using P = pair<ll,ll>;
#define v first
#define w second

// v高い順（vが同じならw軽い方優先）
bool comp(P a, P b){
    return a.v == b.v ? a.w < b.w : a.v > b.v;
}

int main(void){
    int N,W;
    cin>>N>>W;
    vector<P> a(N);
    rep(i,N){
        ll v,w;
        cin>>v>>w;
        a[i] = {v,w};
    }
    vector<P> dp = {{0,0}};

    rep(i,N){
        vector<P> tmp;
        for(auto& s : dp){
            tmp.push_back(s);
            tmp.push_back({s.v + a[i].v, s.w + a[i].w});
        }

        sort(all(tmp),comp);
        dp.clear();
        ll w_border = W+1;
        for(auto& s : tmp){
            if( w_border > s.w){
                w_border = s.w;
                dp.push_back(s);
            }
        }
    }
    cout<<dp[0].v<<endl;
    return 0;
}



Measured memory_bytes: 3208