akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    val s = readLine()!!
    val cnt = Array(4){0}
    for (i in 0 until s.length) {
        when (s[i]) {
            'N' -> cnt[0]++
            'S' -> cnt[1]++
            'E' -> cnt[2]++
            else -> cnt[3]++
        }
    }
    if ((cnt[0] > 0 && cnt[1] > 0 || cnt[0] == cnt[1]) && (cnt[2] > 0 && cnt[3] > 0 || cnt[2] == cnt[3])) {
        println("Yes")
    } else {
        println("No")
    }
}


Measured memory_bytes: 33728
#include <bits/stdc++.h>
#define FOR(i,b,e) for (common_type_t <decltype (b), decltype (e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define FORR(i,b,e) for (common_type_t <decltype (b), decltype (e)> i = (e), i ## __begin = (b); i -- > i ## __begin;)
#define rep(i,n) for (decay_t <decltype (n)> i = 0, i ## __len = (n); i < i ## __len; ++ i)
#define ALL(x) begin (x), end (x)
using namespace std;

auto main () -> int
{
  cin.tie (nullptr);
  ios::sync_with_stdio (false);

  int a, b; cin >> a >> b;

  auto push = [&] () {
    return a > b ? a -- : b --;
  };

  auto ans = 0;
  ans += push ();
  ans += push ();
  cout << ans << endl;
}


Measured memory_bytes: 384
n=int(input())
a=list(map(int,input().split()))
suml=[0]*n
suml[0]=a[0]
for i in range(1,n):
  suml[i]=suml[i-1]+a[i]
total=suml[-1]
ans=10**20
for i in range(n):
  if ans>abs(total-2*suml[i]):
    ans=abs(total-2*suml[i])
print(ans)

Measured memory_bytes: 89680
#include<bits/stdc++.h>
using namespace std;
int n;
int a[3][111];
int mem[3][111];
int f(int x,int y)
{
    if(x<1||y<1)return 0;
    if(mem[x][y]!=-1)
        return mem[x][y];
    return mem[x][y]=max(f(x-1,y),f(x,y-1))+a[x][y];
}
int main()
{
    memset(mem,-1,sizeof mem);
    cin>>n;
    for(int i=1;i<=2;++i)
    {
        for(int j=1;j<=n;++j)
            cin>>a[i][j];
    }
    cout<<f(2,n)<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define Nu 50
#define SUM_MAX 3000


long long int dp[Nu+1][Nu+1][SUM_MAX+1]={0};

int main(void)
{
	int i;
	int j;
	int k;
	int n;
	int a;
	int x[Nu+1];
	int k_max;
	long long int ans=0;
	scanf("%d %d",&n,&a);
	for(i=0;i<n;i++){
		scanf("%d",&x[i]);
	}
	for(i=0;i<n+1;i++){
		dp[i][0][0]=1;
	}
	for(i=0;i<n;i++){
		k_max=(i+1)*50;
		for(j=0;j<=i;j++){
			for(k=0;k<k_max+1;k++){
				if(k>=x[i]){
					dp[i+1][j+1][k]=dp[i][j][k-x[i]]+dp[i][j+1][k];
				}else{
					dp[i+1][j+1][k]=dp[i][j+1][k];
				}
			}
		}
	}
	for(i=1;i<n+1;i++){
		ans+=dp[n][i][i*a];
	}
	printf("%lld",ans);
}


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

int main() {
	int n, x, m[1001];
	int i, min = 100000;

	cin >> n >> x;
	for (i = 1; i <= n; i++) { 
		cin >> m[i]; 
		if (min > m[i])	min = m[i];
		x -= m[i];
	}

	int ans = n + x / min;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
x, n = map(int,input().split())
if n != 0:
  a = list(map(int,input().split()))
b = [i for i in range(-150,150)]
c = 1000

for i in range(n):
    b.remove(a[i])

for i in range(len(b)):
  if abs(b[i] - x) < abs(c - x):
      c = b[i]
  else:
      pass

print(c)

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

int memo[100010], n, k = 0, h[100010];

int dp(int pos) {
    if (pos > n - 1) return 1 << 30;
    if (pos == n - 1) return 0;
    if (memo[pos] != -1) return memo[pos];
    int res = 1 << 30;
    int x = abs(h[pos + 1] - h[pos]) + k + dp(pos + 1);
    int y = abs(h[pos + 2] - h[pos]) + k + dp(pos + 2);
    res = min(x,y);
    return memo[pos] = res;
}
int main() {
    cin >> n;
    memset(memo, -1, sizeof(memo));
    for(int i = 0; i < n; i++) cin >> h[i];
    cout << dp(0) << "\n";
    return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
const ll mod = 1e9+7;
const int N = 2e5+5;

void solve(){
    ld a,b;
    cin>>a>>b;
    ld c = a*b;
    ll ans =(c);
    cout<<ans<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
//    scanf("%d",&t);
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3748
n,k,s = map(int,input().split())
if s != 10**9:
    ans_ls = [s+1] * n
    for i in range(k):
        ans_ls[i] = s
    ans_ls = list(map(str,ans_ls))
else:
    ans_ls = [1] * n
    for i in range(k):
        ans_ls[i] = s
    ans_ls = list(map(str,ans_ls))
print(' '.join(ans_ls))


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

bool c[200][200];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        c[a][b] = true;
        //c[b][a] = true;
    }

    vector<pair<int, int> > v;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        v.push_back({a, b});
        //v.push_back({b, a});
    }
    sort(v.begin(), v.end());

    int ans = 0;
    for (int i = 0; i < n; i++) {
        int x = -1, y = -1;

        for (int j = 0; j < v[i].second; j++) {
            for (int k = 0; k < v[i].first; k++) {
                if (c[k][j]) x = k, y = j;
            }
        }

        if (x != -1) {
            c[x][y] = false;
            ans++;
        }
    }

    cout << ans;
}


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


using namespace std;
const long MOD = 1e9 + 7;

int main()
{
  int N, M;
  long a[100001];
  long b[100001];
  cin >> N;
  for (int i = 0; i < N; i++) {
    b[i] = 0;
  }

  for (int i = 0; i < N; i++) {
    cin >> a[i];
    b[a[i]]++;
  }

  //a[i]は左の人-右の人の人数の差の絶対値

  long count = 0;
  bool isEven = false;
  if (N % 2 == 0)isEven = true;

  int num2pair = N / 2;

  bool isFeasible = true;

  if (isEven) {
    for (int i = 0; i < num2pair; i++) {
      if (b[i * 2 + 1] != 2) {
        isFeasible = false;
        break;
      }
    }
  } else {
    if (b[0] != 1) {
      isFeasible = false;
    }
    for (int i = 1; i < num2pair + 1; i++) {

      if (b[i * 2] != 2) {
        isFeasible = false;
        break;
      }
    }
  }


  if (isFeasible){
      count = 1;
  for (int i = 0; i < num2pair; i++) {
    count *= 2;
    if (count > MOD)count = count % MOD;
  }


  cout << count << endl;
}else{
  cout << 0 << endl;
}



  return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
void FAIL() { printf("-1"); exit(0); }
const int N=210;
int mp[N][N];
int col[N],n;
int dis[N][N];
char S[N];
void dfs(int u,int c) {
	col[u]=c;
	for(int v=1;v<=n;++v) if(mp[u][v])
		if(col[v]&&col[v]!=-c) FAIL();
		else if(!col[v]) dfs(v,-c);
}
int main() {
	rd(n);
	for(int i=1;i<=n;++i) {
		scanf("%s",S+1);
		for(int j=1;j<=n;++j) mp[i][j]=S[j]-'0';
	}
	for(int i=1;i<=n;++i) if(!col[i]) dfs(i,1);
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			dis[i][j]=i==j?0:(mp[i][j]?1:1e9);
	for(int k=1;k<=n;++k)
		for(int i=1;i<=n;++i)
			for(int j=1;j<=n;++j)
				dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
	int ans=0;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			if(dis[i][j]<n) ans=max(ans,dis[i][j]);
	printf("%d",ans+1);
	return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;

    int a[100002];
    rep(i, 100002)a[i] = 0;

    rep(i, m){
        int p;
        string s;
        cin >> p >> s;

    if(s == "AC"){
        if(a[p] < 0){
            //do nothing
        }else{
            a[p]++;
            a[p] = -a[p];
        }
    }else{
        if (a[p] < 0)
        {       
            /* do nothing */
        }else{
            a[p]++;
        }
        
    }
        
    }

    int ans1 = 0;
    int ans2 = 0;

    for (int i = 1; i <= n; i++)
    {
        int wa=0, ac=0;

        if(a[i] > 0){
        }else if(a[i]==0){
        }else{
            wa = -(a[i]+1);
            ac = 1;
        }

        ans1 += ac;
        ans2 += wa;
    }
        cout << ans1 << " " << ans2 << endl;
        return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

template <class T>
void VecRowShow(vector<T> vec) {
	rep(i, vec.size()) {
		if (i != vec.size() - 1) cout << vec[i] << " ";
		else cout << vec[i] << endl;
	}
}

int main() {
	int k;
	cin >> k;

	if (k < 10) {
		cout << k << endl;
		return 0;
	}

	vector<ll> ans;
	FOR(i, 1, 10) {
		ans.push_back(i);
	}
	rep(i, 100000) {
		ll t = ans[i];
		ll t0 = t % 10;
		if (t0 ==0) {

			ans.push_back(t * (ll)10 + t0);
			if (ans.size() == k) {
				cout << ans[k - 1] << endl;
				return 0;
			}
			ans.push_back(t * (ll)10 + t0 + 1);
			if (ans.size() == k) {
				cout << ans[k - 1] << endl;
				return 0;
			}
		}
		else if (t0 == 9) {

			ans.push_back(t * (ll)10 + t0 - 1);
			if (ans.size() == k) {
				cout << ans[k - 1] << endl;
				return 0;
			}
			ans.push_back(t * (ll)10 + t0);
			if (ans.size() == k) {
				cout << ans[k - 1] << endl;
				return 0;
			}
		}
		else {
			ans.push_back(t * (ll)10 + t0 - 1);
			if (ans.size() == k) {
				cout << ans[k - 1] << endl;
				return 0;
			}
			ans.push_back(t * (ll)10 + t0);
			if (ans.size() == k) {
				cout << ans[k - 1] << endl;
				return 0;
			}
			ans.push_back(t * (ll)10 + t0 + 1);
			if (ans.size() == k) {
				cout << ans[k - 1] << endl;
				return 0;
			}
		}
	}
}




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

int main(){
  int N , L;
  cin >> N >> L;
  string S[N];
  for(int i = 0; i < N; i++){
    cin >> S[i];
  }
  sort(S , S + N);
  for(int i = 0; i < N; i++){
    cout << S[i];
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int 
#define endl '\n'
#define INF 1000000000
#define MOD 1000000007
#define MAX 100000000 
#define mp make_pair
#define pb push_back
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
    {
    	cin>>a[i];
    }
    sort(a,a+n);
    ll ans=0;
    for(int i=0;i<n;i++)
    {
    	for(int j=i+1;j<n;j++)
    	{
    		for(int k=j+1;k<n;k++)
    		{
    			if((a[i]+a[j])>a[k]&&a[i]!=a[j]&&a[j]!=a[k])
    			{
    				ans++;
    			}
    		}
    	}
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3668
h,w=map(int,input().split())
a=[]
mod=10**9+7
h+=2
w+=2
a.append("#"*w)
for i in range(h-2):
    a.append("#"+input()+"#")
a.append("#"*w)

dp=[[0 for i in range(w)]for j in range(h)]
dp[0][1]=1
for i in range(1,h-1):
    for j in range(1,w-1):
        if a[i][j]==".":
            dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod

print(dp[h-2][w-2])

Measured memory_bytes: 53852
cnt = 1
while 1:
    l = int(input())
    if l == 0:
        break
    n = int(input())
    v = [0] * (n+1)
    w = [0] * (n+1)

    for i in range(1, n+1):
        v[i], w[i] = map(int, input().split(','))

    dp = [[0]*(l+1) for i in range(n+1)]

    for i in range(1, n+1):
        for j in range(1, l+1):
            if (j < w[i]):
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = max(dp[i-1][j - w[i]] + v[i], dp[i-1][j])

    print('Case ', cnt, ':', sep='')
    print(dp[n][l])
    for i in range(l + 1):
        if dp[n][l] == dp[n][i]:
            print(i)
            break
    cnt += 1



Measured memory_bytes: 17156
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
map<pair<int,int>,int> Color;
int ncol = 0;

vector<bool> seen;//木でも往復を防ぐ
void dfs(const Graph &G, int color,int node){
  ncol = max(color,ncol);
  int ncolor = 1;
  seen[node] = true;
  //cout << node << endl;
  for(auto nnode : G[node]){
    if (seen[nnode]) continue;
    if(ncolor==color){ncolor += 1;}
    if(node<nnode){
      Color[make_pair(node,nnode)] = ncolor;
    }else{
      Color[make_pair(nnode,node)] = ncolor;
    }
    dfs(G,ncolor,nnode);
    ncolor++;
  }
}

int main(){
  int n; cin >> n;
  Graph G(n+1);
  //Color C;
  vector<pair<int,int>> pairs;//出力順
  for (int i=0; i<n-1; i++){
    int a,b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
    Color[make_pair(a,b)] = 0;
    pairs.push_back(make_pair(a,b));
  }
  seen.assign(n+1,false);
  dfs(G,0,pairs.at(0).first);
  cout << ncol << endl;
  for (auto p : pairs){
    cout << Color[p] << endl;
  }
}

Measured memory_bytes: 13560
e=enumerate
n,a=open(0)
n=int(n)
d=[0]+[-1e18]*n
for j,(a,i)in e(sorted((int(a),i)for i,a in e(a.split()))[::-1]):d=[max(t+a*abs(~i-j+k+n),k and d[k-1]+a*abs(~i+k))for k,t in e(d)]
print(max(d))

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

int main () {
  string S;
  cin >> S;
  int N = S.length(), cnt1 = 0, cnt2 = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == '0') cnt1++;
    else cnt2++;
  }
  cout << 2 * min(cnt1, cnt2) << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  sort(A.rbegin(), A.rend());
  long ans = A.at(0);
  for (int i = 2; i < N; i++) ans += A.at(i / 2);
  cout << ans << "\n";
}

Measured memory_bytes: 4048
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

const int MAX = 200000, SENTINEL = 2100000000;
int L[MAX / 2 + 2], R[MAX / 2 + 2];

ll merge(int A[], int n, int left, int mid, int right) {
    ll cnt = 0;
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; i++) L[i] = A[left + i];
    for (int i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1] = R[n2] = SENTINEL;
    int i = 0, j = 0;
    for (int k = left; k < right; k++) {
        if (L[i] <= R[j]) {
            A[k] = L[i++];
        } else {
            A[k] = R[j++];
            cnt += n1 - i;
        }
    }
    return cnt;
}

ll msort(int A[], int n, int left, int right) {
    ll res = 0;
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        res += msort(A, n, left, mid);
        res += msort(A, n, mid, right);
        res += merge(A, n, left, mid, right);
    }
    return res;
}


int main(void) {
    int n, A[MAX];

    cin >> n;
    for (int i = 0; i < n; i++) cin >> A[i];

    cout << msort(A, n, 0, n) << endl;

    return 0;
}

Measured memory_bytes: 2716
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
 
//#define int long long
#define ll long long
#define vi vector <int>
#define vii vector <pair<int,int> >
#define vvi vector <vi>
#define rep(i,a,b) for (int i=a;i<b;i++)
#define repD(i,a,b) for (int i=a;i>b;i--)
#define pb push_back
#define pii pair <int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define PI 3.14159265359
 
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;
///*X.find_by_order("index")
///X.order_of_key("key")
 
#define deb(x) {x}
#ifndef local
	#define deb(x) ;
#endif
 
///----------------------------------------------------------------------------------

const int mod = 61559;
int n, k, arr[5005];
unsigned short Forward[5005][5005], backward[5005][5005][2], DP[5005][5005];
bitset <5005> vis[5005];
int fun(int ind, int rem)
{
	if (ind == n && rem == 0) return 1;
	if (ind == n) return 0;
	if (vis[ind][rem]) return DP[ind][rem];
	
	// I go
	vis[ind][rem] = 1;
	int res = 0;
	backward[ind][rem][1] = fun(ind+1, max(0, rem-arr[ind]));
	res = backward[ind][rem][1];
	
	
	// I dont go
	
	backward[ind][rem][0] = fun(ind+1, rem);
	res += backward[ind][rem][0];
	
	if (res >= mod) res -= mod;
	return DP[ind][rem] = res;
}
bool upper = true;
int fun2(int ind, int rem)
{
	if (rem < 0)
	{
		if (! upper) return 0;
		rem = 0;
	}
	if (ind == n && rem == 0) return 1;
	if (ind == n) return 0;
	if (vis[ind][rem]) return DP[ind][rem];
	vis[ind][rem] = 1;
	// I go
	
	int res = fun2(ind+1,rem-arr[ind]);
	
	// I dont go
	
	Forward[ind][rem] = fun2(ind+1, rem);
	res += Forward[ind][rem];
	
	if (res >= mod) res -= mod;
	return DP[ind][rem] = res;
}


void solve()
{
	
	cin >> n >> k;
	rep(i,0,n) cin >> arr[i];
	
	memset(vis, 0, sizeof vis);
	
	
	rep(i,0,k+1)fun(0, i);
	
	reverse(arr, arr+n);
	
	
	memset(vis, 0, sizeof vis);
	
	fun2(0, k);
	upper = false;
	
	memset(vis, 0, sizeof vis);
	rep(i,0,k)fun2(0, i);
	
	reverse(arr, arr+n);
	
	int ans = 0;
	
	rep(i,0,n)
	{
		ll num_with_me = 0, num_without_me = 0;
		
		rep(j,0,k+1)
		{
				num_with_me += ( Forward[n-i-1][j] * backward[i][k-j][1]);
				num_without_me += ( Forward[n-i-1][j] * backward[i][k-j][0]);
			
		}
		if (num_without_me == num_with_me) ans++;
	}
	cout << ans << "\n";
}
signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
 	
 	#ifdef local
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	clock_t qwertyuiop = clock();
	#endif
 
	int t = 1;
	//cin >> t;	
	rep(a,0,t)
	{
		//cout<<"Case #"<<a+1<<": ";
		solve();
		#ifdef local
			cout << "\n";
		#endif

	}
	
	#ifdef local
	{qwertyuiop = clock() - qwertyuiop;double time_taken = ((double)qwertyuiop)/CLOCKS_PER_SEC;cerr<<fixed<<setprecision(5)<<"\n\nTime Taken : "<<time_taken<<" seconds\n";}
	#endif
}


Measured memory_bytes: 199296
//Use valgrind once if the submission doesn't go through. It can detect uninitialized variables and see where they could be an issue.
#include <bits/stdc++.h>
using namespace std;

int main(){

	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);

	int N,K;
	cin>>N>>K;
	vector<int> a(N);
	for(auto &i:a){
		cin>>i;
	}
	for(int i=K;i<N;i++){
		if(a[i]>a[i-K]){
			cout<<"Yes\n";
		}
		else{
			cout<<"No\n";
		}
	}
}


Measured memory_bytes: 3932
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// Nの桁数
ll dig(ll N) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= 10;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

int main() {
	int N; cin >> N;
	if (N <= 999)cout << "ABC" << endl;
	else cout << "ABD" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    char s;
    cin >> s;
    int q = 'A';
    if('A'<=s&&s<='Z'){
        cout <<"A";
    }
    else{
        cout <<"a";
    }



    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
 
using namespace std;
 
#define EPS 1e-10
#define equal(a,b) (fabs(a-b) < EPS)
#define lt(a,b) (a-b < -EPS)
 
struct Point{
    double x,y;
 
    Point(){}
    Point(double x,double y) : x(x),y(y) {}
 
    Point operator + (const Point &p)const{ return Point(x+p.x,y+p.y); }
    Point operator - (const Point &p)const{ return Point(x-p.x,y-p.y); }
    Point operator * (const double &k)const{ return Point(x*k,y*k); }
    Point operator / (const double &k)const{ return Point(x/k,y/k); }
    bool operator < (const Point &p)const{ return x != p.x ? x < p.x : y < p.y; }
};
 
double dot(const Point &a,const Point &b){ return a.x*b.x+a.y*b.y; }
double cross(const Point &a,const Point &b){ return a.x*b.y - b.x*a.y; }
double norm(const Point &p){ return dot(p,p); }
double abs(const Point &p){ return sqrt(norm(p)); }
 
istream &operator >> (istream &is,Point &p){ 
    return is >> p.x >> p.y;
}
 
typedef Point Vector;
 
struct Line{
    Point s,t;
    Line(){}
    Line(Point s,Point t) : s(s),t(t) {}
};
 
bool isIntersectLL(const Line &a,const Line &b){
    return abs(cross(a.t-a.s,b.t-b.s)) > EPS
	|| abs(cross(a.t-a.s,b.t-b.s)) < EPS;
}
 
Point crosspointLL(const Line &a,const Line &b){
    Vector va = a.t-a.s, vb = b.t-b.s;
    double d = cross(vb,va);
    return a.s+va*cross(vb,b.t-a.s)*(1.0/d);
}
 
int main(){
    int N;
    while(cin >> N,N){
	vector<Line> l(N);
	for(int i = 0 ; i < N ; i++){
	    cin >> l[i].s >> l[i].t;
	}
	int div = 1;
	for(int i = 0 ; i < N ; i++){
	    int cp = 0;
	    vector<Point> used;
	    for(int j = 0 ; j < i ; j++){
		if(isIntersectLL(l[i],l[j])){
		    Point p = crosspointLL(l[i],l[j]);
		    bool flg = false;
		    for(int k = 0 ; k < (int)used.size() ; k++){
			Point q = used[k];
			if(equal(p.x,q.x) && equal(p.y,q.y)){
			    flg = true;
			    break;
			}
		    }
		    if(flg) continue;
		    used.push_back(p);
		    if(lt(-100,p.x) && lt(p.x,100) &&
		       lt(-100,p.y) && lt(p.y,100)){
			cp++;
		    }
		}
	    }
	    div += cp+1;
	}
	cout << div << endl;
    }
    return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define int ll


string s;
int a[5];
bool ans=false;

void f(bool b[],int k){
  if(k==5) return;
  if(ans) return;

  int res=a[0];
  rep(i,4){
    if(b[i]){
      res+=a[i+1];
    }
    else{
      res-=a[i+1];
    }
  }
  if(res==7){
    rep(i,4){
      cout<<a[i];
      if(i==3){
        cout<<"=7"<<endl;
        ans = true;
        return;
      }
      else if(b[i])
        cout<<'+';
      else
        cout<<'-';
    }
  }

  FOR(i,k,4){
    b[i]=true;
    f(b,i+1);
    b[i]=false;
  }
}


signed main(){
  cin>>s;

  rep(i,s.size()){
    a[i]=s[i]-'0';
  }

  bool b[5]={};

  f(b,0);
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main { // "Main" should be used for most online judges
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int x = sc.nextInt();
		int fihundred = x / 500;
		while(fihundred > a) {
			fihundred--;
		}
		int largest = b * 100 + c * 50;
	    int count = 0;
	    for(int i = fihundred; i >= 0; i--) {
	    		int money = x - i * 500;
	    		if(money > largest) {
	    			System.out.println(count);
	    			return;
	    		}
	    		int hundred1 = money / 100;
	    		int fifty1 = money % 100 / 50;
	    		while(hundred1 > b) {
	    			hundred1--;
	    			fifty1 += 2;
	    		}
	    		if(fifty1 > c) {
	    			System.out.println(count);
	    			return;
	    		}
	    		count++;
	    		while(hundred1 > 0) {
	    			hundred1--;
	    			fifty1 += 2;
	    			if(fifty1 > c) break;
	    			else {

	    				count++;
	    			}
	    		}
	    }
	    System.out.println(count);
	}
}

Measured memory_bytes: 21844
from collections import defaultdict

n = int(input())
a = list(map(int, input().split()))
a.sort()
d = defaultdict(int)
for ai in a:
    d[ai] += 1

m = a[-1]
x = [True for _ in range(m + 1)]

ans = 0
c = defaultdict(bool)
for ai in a:
    if x[ai] and d[ai] == 1:
        ans += 1
    if not c[ai]:
        c[ai] = True
        for j in range(2 * ai, m + 1, ai):
            x[j] = False
print(ans)


Measured memory_bytes: 56300
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <queue>
#include <math.h>
#include <map>
#include <set>
#include <fstream>

//#define _debug
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sc(x) scanf("%d",&x)
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORd(i,a,b) for(int i=a;i>b;i--)
#define ff first
#define ss second
#define sz(x) x.size()
#define pb push_back
//#define _online_judge

using namespace std;

typedef pair<int,int> pii;
typedef vector<pii> vii;
const int con = static_cast<const int>(1e4 + 5);
const int MOD = 1000000007;



int main(){
    FASTIO;
#ifdef _online_judge
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif

    int n,ma=-1;cin >> n;
    int arr[n];FOR(i,0,n) cin >> arr[i],ma = max(ma,arr[i]);
    int cnt=0;
    while(1){
        if(*max_element(arr,arr+n) == 0) break;
        int j;
        for(j=0;arr[j]==0 && j<n;j++);

        while(arr[j]>0 && j<n){
            arr[j]--;
            j++;
        }
        cnt++;
    }
    cout << cnt;
}


Measured memory_bytes: 256
package main

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

func main() {
	a, b, c, d := readI(), readI(), readI(), readI()
	ans := make([]int, 4)
	ans[0] = a * c
	ans[1] = a * d
	ans[2] = b * c
	ans[3] = b * d
	fmt.Println(max(ans))
}

func max(a []int) int {
	l := len(a)
	m := a[0]
	for i := 1; i < l; i++ {
		if a[i] > m {
			m = a[i]
		}
	}
	return m
}

/*-----------Input utils-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const buf = 200100
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, buf), buf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

func readS() string {
	sc.Scan()
	return sc.Text()
}

func readR() []rune {
	return []rune(readS())
}

func readI() int {
	i, _ := strconv.Atoi(readS())
	return i
}

func readF() float64 {
	f, _ := strconv.ParseFloat(readS(), 64)
	return f
}


Measured memory_bytes: 1780
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node{int p, l, r;};
struct Node T[MAX];
int n;

void preParse(int u){
	if(u == NIL) return;
	printf(" %d",u);
	preParse(T[u].l);
	preParse(T[u].r);
}

void inParse(int u){
	if(u == NIL) return;
	inParse(T[u].l);
	printf(" %d",u);
	inParse(T[u].r);
}

void postParse(int u){
	if(u == NIL) return;
	postParse(T[u].l);
	postParse(T[u].r);
	printf(" %d",u);
}

int main(){
	int i,v,l,r,root;
	
	scanf("%d",&n);
	for(i = 0;i < n;i++){
		T[i].p = NIL;
	}
	
	for(i = 0;i < n;i++){
		scanf("%d %d %d",&v,&l,&r);
		T[v].l = l;
		T[v].r = r;
		if(l != NIL) T[l].p = v;
		if(r != NIL) T[r].p = v;
	}
	for(i = 0;i < n;i++) if(T[i].p == NIL) root = i;
	
	printf("Preorder\n");
	preParse(root);
	printf("\n");
	printf("Inorder\n");
	inParse(root);
	printf("\n");
	printf("Postorder\n");
	postParse(root);
	printf("\n");
	
	return 0;
}


Measured memory_bytes: 2040
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

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

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int N;
int x[200000], y[200000];
int a[200000];
int r_min[200000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> x[i] >> y[i]; x[i]--; y[i]--;
    }
    
    for(int i = 0; i < N; i++){
        a[x[i]] = y[i];
        r_min[x[i]] = y[i];
    }
    UnionFind uf(N);
    set<P> st;
    for(int i = 0; i < N; i++){
        auto p = st.begin();
        vector<P> smaller;
        while(p != st.end()){
            if(p->first < a[i]){
                smaller.push_back(*p);
            }else{
                break;
            }
            p++;
        }
        int m = a[i];
        for(P p : smaller){
            st.erase(p);
            int idx = p.second;
            uf.unionSet(i, idx);
            int r = uf.root(i);
            m = min(m, p.first);
        }
        int r = uf.root(i);
        st.insert(P(m, r));
    }
    for(int i = 0; i < N; i++) cout << uf.size(x[i]) << endl;
}

Measured memory_bytes: 12576
#include<bits/stdc++.h>
using namespace std;
const bool debug =0;

inline void read(int &x){
    char ch;
    bool flag=false;
    for (ch=getchar();!isdigit(ch);ch=getchar())if (ch=='-') flag=true;
    for (x=0;isdigit(ch);x=x*10+ch-'0',ch=getchar());
    x=flag?-x:x;
}

inline void write(int x){
    static const int maxlen=100;
    static char s[maxlen];
    if (x<0) {   putchar('-'); x=-x;}
    if(!x){ putchar('0'); return; }
    int len=0; for(;x;x/=10) s[len++]=x % 10+'0';
    for(int i=len-1;i>=0;--i) putchar(s[i]);
}

const int MAXN = 110000;

int n,m,A,B;

void out(int op,int x){
for(int i=1;i<=x;i++)
    printf("%d",op);
for (int i=x+1;i<=m;i++)
    printf("%d",1-op);
puts("");
}

int main(){
    read(n);read(m);
    read(A);read(B);
    for (int i=1;i<=n;i++)
        if ( i<=B )
            out( 1 , A );
        else
            out( 0 , A );
    return 0;
}


Measured memory_bytes: 1280
/*input
7
1 1 1 1 1 1 1
*/
 
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <climits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <stdint.h>
#include <tgmath.h>
 
using namespace std;
 
/*******  All Required define Pre-Processors and typedef Constants *******/
#define ar array
#define scd(t) scanf("%d",&t)
#define scld(t) scanf("%ld",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define tests int r; cin >> r; while(r--)
#define MP make_pair
#define PI acos(-1)
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
#define godspeed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
 
#define M(x) ((x)%(1000000007))
 

int arr[1010][1010];

int h;
int w;



bool legal(int x, int y){
	if(x>=1&&x<=h){
		if(y>=1&&y<=w){
			if(arr[x][y]){
				return true;

			}
		}
	}
	return false;
}


int main() {
 	int n;
 	cin>>n;
 	if(n<2){
 		cout<<0<<endl;
 	}
 	else{
		int64 arr[n];
		priority_queue<int64> s;
		rep(i,n){
			int64 a;
			cin>>a;
			arr[i] = a;
		}
		sort(arr,arr+n);
		s.push(arr[n-1]);
		int64 j = n-2;
		int64 ans = 0;
		while(j>=0){
			int64 a = arr[j];
			ans = ans + s.top();
			s.pop();
			s.push(a);
			s.push(a);
			j--;
		}
		cout<<ans<<endl;
 	}
 	


 	
}



 


Measured memory_bytes: 6876
#include<stdio.h>
#include<string.h>
int main(void){
  char S[1001];
  int i,a,b,c;
  int n,s,e,w;
  a=0;
  b=0;
  n=0;
  s=0;
  e=0;
  w=0;
  scanf("%s",S);
  c=strlen(S);
  for(i=0;i<c;i++){
  switch(S[i]){ 
  case 'N':
    n++;
    break; 
  case 'S':
    s++;
    break;  
  case 'E':
    e++;
    break;
  case 'W':
    w++;
    break;
  default:
    break;
  }
  }
  if(n>0){
    if(s>0){
      a=1;
    }
  }else{
    if(s==0){
      a=1;
    }
  }
  if(e>0){
    if(w>0){
      b=1;
    }
   }else{
    if(w==0){
      b=1;
    }
  }
  if(a==1&&b==1){
    a=1;
  }else{
    a=0;
  }
  if(a>=1){
    printf("Yes");
  }else{
    printf("No");
  }
  printf("\n");
  return 0;
}
      

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

void solve() {
  ll N, ans = 0;
  vector<ll> v(1e5 + 1, 0);
  cin >> N;
  ll x;
  rep(i, 0, N) {
    cin >> x;
    v[x]++;
    ans += x;
  }
  ll Q, a, b;
  cin >> Q;
  rep(i, 0, Q) {
    cin >> a >> b;
    ans -= a * v[a];
    ans += b * v[a];
    cout << ans << endl;
    v[b] += v[a];
    v[a] = 0;
  }
}

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

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

#define ll long long

const int MOD = 1e9 + 7;

int main(int argc, char **argv) {
	string s, t;
	cin >> s >> t;
	int resp = t.size();
	for (int i = 0; i <= (int)s.size() - (int)t.size(); i++) {
		int count = 0;
        int tmp = i;
		for (int j = 0; j < (int)t.size(); j++, i++)
			if (s[i] == t[j]) count++;
        i = tmp;
		resp = min(resp, (int)t.size() - count);
	}
	cout << resp << endl;
	return 0;
}

Measured memory_bytes: 3600
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p

N, M, K = map(int, input().split())

p = 998244353
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

ans = 0
col = M
for x in range(N - 1, -1, -1):
    now = col
    now *= cmb(N - 1, x, p)
    now %= p
    if x <= K:
        ans += now
        ans %= p
    col *= (M - 1)
    col %= p
print(ans)

Measured memory_bytes: 112612
#include<bits/stdc++.h>
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define nd second
#define st first
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>;
using mii=map<int,int>;
using si=set<int,int>;
using vpi=vector<pii>;
using vpl=vector<pll>;

const int N=(int)1e5+5;

int n,m,a,b,c,q,k,tab[N],dp[N];
vi V;

int R(int l, int p){
	return rand()%(p-l+1)+l;
}

void wczytaj(){
	cin>>n>>k>>tab[1];
	for (int i=2; i<=n; ++i){
		cin>>tab[i];
		dp[i]=(int)2e9;
		int j=i-1;
		while (j and i-j<=k){
			dp[i]=min(dp[i],dp[j]+abs(tab[j]-tab[i]));
			j--;
		}
	}
	cout<<dp[n]<<'\n';
}

void solve(){

}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int ilosc_przypadkow_testowych=1;
//	cin>>ilosc_przypadkow_testowych
	for (int i=1; i<=ilosc_przypadkow_testowych; ++i){
		wczytaj();
		solve();
	}
}

Measured memory_bytes: 1024
#include <stdio.h>
#define m_max 1000100
int main(void){
    int n;
    scanf("%d",&n);
    int collatz[m_max];
    for(int i=0;i<m_max;i++)
    {
        collatz[i] = 0;
    }
    
    collatz[n] = 1;
    int count = 1;
    while(1)
    {
        if(n%2)
        {
            if(collatz[3*n+1]>0)
            {
                printf("%d\n",count+1);
                return 0;
            }
            else
            {
                collatz[3*n+1] = count;
                count++;
                n = 3*n+1;
            }
        }
        else
        {
            if(collatz[n/2]>0)
            {
                printf("%d\n",count+1);
                return 0;
            }
            else
            {
                collatz[n/2] = count;
                count++;
                n /= 2;
            }
        }
    }
}

Measured memory_bytes: 4096
large_p = 10**9 + 7
def main():
    h, w = map(int, input().split())
    grid = [tuple(map(str, input())) for _ in range(h)]
    grid_root = [[0] * w for _ in range(h)]

    # 最もうえの行に「そのセルにいける場合の数」をいれる。右へ進み続けるしかないので１か０。
    flag = 1
    for i1 in range(w):
        if grid[0][i1] == '#':
            flag = 0
        grid_root[0][i1] += flag

    flag = 1
    for i2 in range(h):
        if grid[i2][0] == '#':
            flag = 0
        grid_root[i2][0] += flag
    for j1 in range(1, h):
        for j2 in range(1, w):
            if grid[j1][j2] == '.':
                grid_root[j1][j2] = grid_root[j1-1][j2] + grid_root[j1][j2-1]
    print(grid_root[h-1][w-1] % large_p)

if __name__ == '__main__':
    main()

Measured memory_bytes: 164336
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
	  String s = sc.next();
      boolean tf = true;
        for(int i = 0;i < s.length() && tf;i++){
           char a = s.charAt(i);
           if(a != 'U' && a != 'D'){
             if((i % 2) == 0){
               if(a != 'R'){
                 tf = false;
               }
             }else{
               if(a != 'L'){
                 tf = false;
               }
             }
           }
        }
      if(tf){
        System.out.println("Yes");
      }else{
        System.out.println("No");
      }
    }
}

Measured memory_bytes: 23764
#include<iostream>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		int a[4][3][10]={0};
		for(int i=0;i<n;i++){
			int b,f,r,v;
			cin>>b>>f>>r>>v;
			a[b-1][f-1][r-1]+=v;
		}
		for(int i=0;i<4;i++){
			for(int j=0;j<3;j++){
				for(int k=0;k<10;k++){
						cout<<" "<<a[i][j][k];
				}
				cout<<endl;
			}
			if(i!=3)
				cout<<"####################"<<endl;
		}
		
	}	
	return 0;
}


Measured memory_bytes: 3100
// start: 2:41
// AC: 3:02
#include <iostream>
#include <vector>
#include <queue>

#define REP(i, n) for ( int i = 0; i < n; i++ )
#define MP(a, b) make_pair(a, b)
#define MAX 101

using namespace std;

typedef pair<int, int> ab;

int sum(vector<int> arr) {
    int ret = 0;
    REP(i, arr.size()) ret += arr[i];
    return ret;
}

bool flg = false;
int N, M;

ab all_search(vector<int> &a, vector<int> &b) {
    int aa = MAX, bb = MAX;

    REP(ai, N) REP(bi, M) {
        // トレード
        int tmp = a[ai];
        a[ai] = b[bi];
        b[bi] = tmp;

        // 等しく、かつ最小
        if ( sum(a) == sum(b) && a[ai] + b[bi] < aa + bb ) {
            aa = b[bi];
            bb = a[ai];
        }

        // 戻す
        b[bi] = a[ai];
        a[ai] = tmp;
    }
    return MP(aa, bb);
}

int main() {
    while(cin >> N >> M, N||M) {
        vector<int> a(N), b(M);
        queue<ab> open;

        REP(i, N) cin >> a[i];
        REP(i, M) cin >> b[i];

        ab ans = all_search(a, b);

        if ( ans.first != MAX ) cout << ans.first << " " << ans.second << endl;
        else cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#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;
  cin >> N;
  vector<int> B(N-1);
  rep(i,N-1) cin >> B[i];
  vector<int> A(N);
  A[0] = B[0];
  A[N-1] = B[N-2];
  for (int i = 1; i < N-1; ++i) {
    A[i] = min(B[i-1], B[i]);
  }
  int ans = 0;
  rep(i,N) ans += A[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3108
from collections import deque

N,M = list(map(int,input().split()))
g = [[] for _ in range(N)]

for i in range(M):
	a,b = list(map(int,input().split()))
	g[a-1].append(b-1)
	g[b-1].append(a-1)


def depth_first_seach(idx_start):
	queue = deque([idx_start])
	distance = [None]*N
	to_go = [None]*N
	distance[idx_start] = 0
	while queue:
		v = queue.popleft()
		for i in g[v]:
			if distance[i] is None:
				to_go[i] = v
				distance[i] = distance[v] + 1
				queue.append(i)
				
	return to_go, distance

to_go, distance = depth_first_seach(0)

for i in range(1,N):
	if to_go[i] == None:
		print("No")
		exit()

print("Yes")
for i in range(1,N):
	print(to_go[i]+1)


Measured memory_bytes: 34936
/*
	LINES :
		* //WHAT?
*/
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define OJ
#define pb push_back
#define F first
#define S second
#define WLL(t) while(t--)
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define VFOR(i,a,b) for(int i = a; i >= b; i--)
#define ALL(v) v.begin(),v.end()
#define PRECISION(x) cout<<fixed<<setprecision(x)
#define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)

void solve(int d, int t, int s);
int main()
{
#ifndef OJ
	READ;
	WRITE;
#endif

	FASTIO;
	int d, t, s;
	cin >> d >> t >> s;
	solve(d, t, s);
	return 0;
}
void solve(int d, int t, int s)
{
	if (s * t >= d) {
		cout << "Yes" << "\n";
	}
	else {
		cout << "No" << "\n";
	}
}

Measured memory_bytes: 3600
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto n = readln.chomp.to!size_t;
  auto ai = n.iota.map!(_ => readln.chomp.to!int).array;

  auto gi = [1, 4, 13, 40, 121, 364, 1093, 3280, 9841, 29524, 88573, 265720, 797161];
  gi = gi.filter!(g => g <= n).array;
  gi.reverse();

  auto cnt = 0;

  shellSort(ai, n, gi, cnt);

  writeln(gi.length);
  writeln(gi.map!(to!string).join(" "));
  writeln(cnt);
  ai.each!(writeln);
}

void insertionSort(ref int[] ai, size_t n, int g, ref int cnt)
{
  foreach (ptrdiff_t i; g..n) {
    auto v = ai[i];
    auto j = i - g;
    for (; j >= 0 && ai[j] > v; j -= g) {
      ai[j + g] = ai[j];
      ++cnt;
    }
    ai[j + g] = v;
  }
}

void shellSort(ref int[] ai, size_t n, int[] gi, ref int cnt)
{
  foreach (g; gi)
    insertionSort(ai, n, g, cnt);
}

Measured memory_bytes: 7128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 

using namespace __gnu_pbds;
using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll i = 0; i < n; i++)
#define FORN(i, a, b) for (ll i = a; i < b; i++)
#define FORE(i, l) for (auto i : l)

#define pb push_back
#define pob pop_back
#define emp emplace
#define fi first
#define se second

#define all(n) n.begin(), n.end()
#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);	
    //cout << setprecision(15);
    ll a, b, c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b << '\n';
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a[3],d,i,j;
	scanf("%d%d%d",&a[0],&a[1],&a[2]);
	for(i=0;i<3;i++){
		for(j=i;j<3;j++){
			if(a[i]>a[j]){
				d=a[i];
				a[i]=a[j];
				a[j]=d;
			}
		}
	}
	printf("%d %d %d\n",a[0],a[1],a[2]);
	return 0;
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int fs[30];
int nxt[30][100000];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < s.size(); ++i)
        fs[s[i] - 'a']++;
    for (int i = 0; i < t.size(); ++i)
        if (!fs[t[i] - 'a'])
            return cout << -1, 0;

    for (int j = 'a'; j <= 'z'; ++j)
    {
        int occ = s.size();
        for (int i = s.size() - 1; i >= 0; --i)
        {
            if (s[i] == j)
                occ = i;
            nxt[j - 'a'][i] = occ;
        }
    }
    ll sol = 0;
    int si = 0;
    for (int i = 0; i < t.size(); ++i)
    {
        si = nxt[t[i] - 'a'][si];
        if (si == s.size())
        {
            sol += s.size();
            si = nxt[t[i] - 'a'][0];
        }
        si++;
        si %= s.size();
        if (si == 0)
            sol += s.size();
    }
    cout << sol + si;
}


Measured memory_bytes: 10832
S = input()

if S == 'SUN':
  print(7)
elif S == 'MON':
  print(6)
elif S == 'TUE':
  print(5)
elif S == 'WED':
  print(4)
elif S == 'THU':
  print(3)
elif S == 'FRI':
  print(2)
else:
  print(1)

Measured memory_bytes: 2940
# -*- coding: utf-8 -*-

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, A, B = MAP()

if A > B:
    print(0)
elif A == B:
    print(1)
else:
    if N < 2:
        print(0)
    elif N == 2:
        print(1)
    # A < B でNも3つ以上あれば色々できる
    else:
        print(A + B*(N-1) - (A*(N-1) + B)+1)


Measured memory_bytes: 5532
#include<iostream>
#include<cstdlib>
 
#include<cmath>
#include<map>
#include<string>
#include<vector>
#include<algorithm> 
 
using namespace std;
 
# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) std::cout << (j ? s1 : s2) << endl;
# define YES(j) std::cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define rep(n,i) for(i = 0 ; i < n ; i++)
# define swap_int(a,b) int t=a;a=b;b=t;
 
int gcd(int a,int b){
  int tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  int r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}
 
int main()
{
   int n;cin >> n;
 
   int a[100000]={};
   int b[100000]={};
   int c[100000]={};
   for(int i=0 ; i < n ; i++ ){
      cin >> a[i] ;
   }

   if(n==2){
      p(max(a[0],a[1]))
      return 0;
   }

   b[0]=a[0];
   c[n-1]=a[n-1];
   for(int i=1 ; i < n ; i++ ){
      b[i]=gcd(a[i],b[i-1]) ;
      c[n-1-i]=gcd(a[n-1-i],c[n-i]) ;
   }
 
   int ret=c[1];
   for(int i=1;i<n;i++){
      int tmp;
      if(i==n-1) {tmp=b[n-2];}
      else {tmp=gcd(b[i-1],c[i+1]);}
      ret=max(tmp,ret);
   }
   p(ret)
} 

Measured memory_bytes: 1408
#include<iostream>
int e(int a,int b){while(a%=b)a^=b^=a^=b;return b;}int main(){for(int a,b,c,s;s=!(std::cin>>a>>b).eof();s&&printf("%ld %ld\n",c,a/c*b))c=e(a,b);}

Measured memory_bytes: 0