akhauriyash/Code-Regression huggingface dataset:
import sys
# input = sys.stdin.readline
from itertools import accumulate

def readlines(h, w):
    for _ in range(h):
        row = input()
        if not all(cell == "." for cell in row):
            yield row

def main():
    h, w = map(int, input().split())
    grid = list(readlines(h, w))

    columns = set()
    for i in range(w):
        if all(row[i]=="." for row in grid):
            columns.add(i)
    
    for i in range(len(grid)):
        for j in range(w):
            if j not in columns:
                print(grid[i][j], end="")
        print()


main()

Measured memory_bytes: 4468
import java.util.*;

class Main{
	public static void main(String args[]){
		Solve s = new Solve();
		s.solve();
	}
}

class Solve{
	Scanner in = new Scanner(System.in);

	void solve(){
		int[][] s = {{1,2,3,4},{2,-1,4,-3},{3,-4,-1,2},{4,3,-2,-1}};
		while(in.hasNext()){
			int n = in.nextInt();
			if(n == 0) return;
			for(int k = 0; k < n; k++){
				int[] a = new int[4];
				int[] b = new int[4];
				long[] ans = new long[4];
				for(int i = 0; i < 4; i++) a[i] = in.nextInt();
				for(int i = 0; i < 4; i++) b[i] = in.nextInt();

				for(int i = 0; i < 4; i++){
					for(int j = 0; j < 4; j++){
						int t = s[i][j], d = 1;
						if(t < 0){
							t = -t;
							d = -1;
						}
						--t;
						ans[t] += (long)d * a[i] * b[j];
					}
				}

				for(int i = 0; i < 4; i++){
					if(i != 0) System.out.print(" ");
					System.out.print(ans[i]);
				}
				System.out.println();
			}
		}
	}
	
}

Measured memory_bytes: 31560
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    string s; cin >> s;
    int n = s.size();
 
    int ans = 0;
    int len = 0;
    for(int i=0; i<n; i++){
        if(string("ACGT").find(s[i]) == string::npos)
            len = 0;
            
        else{
            len++;
            ans = max(ans, len);
        }
    }
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 3592
import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {
	private static long slove(String p,long all){
        char m[]=p.toCharArray();
        for(int k=1;k<=p.length()/2;k++){
            for(int i=0;i<m.length;i++){
                if(i+2*k>=p.length())
                    break;
                else{
                    if(m[i]!=m[i+k]&&m[i+2*k]!=m[i+k]&&m[i]!=m[i+2*k]) {
                        all--;
                    }
                }
            }
        }
        return all;
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(new BufferedInputStream(System.in));
        int a=sc.nextInt();
        String p=sc.next();
        int countR=0;
        int countG=0;
        int countB=0;
        char m[]=p.toCharArray();
        for(int i=0;i<m.length;i++){
            if(m[i]=='R')
                countR++;
            if(m[i]=='G')
                countG++;
            if(m[i]=='B')
                countB++;
        }
        long all=countB*countG;
        all*=countR;
        System.out.println(Main.slove(p,all));
    }
}



Measured memory_bytes: 36340
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
using namespace std;

#define fi first
#define se second
typedef long long LL;
typedef long double LD;

int N,K,spd[2010]; vector<int> g[2010];

int dfs(int nod, int d, int f){
    int cnt=0;
    if (d<=K/2) cnt=1;
    spd[nod]=0;
    if (d==K/2+1) spd[nod]++;

    for (int nxt : g[nod])
        if (nxt!=f){
            cnt+=dfs(nxt,d+1,nod);
            spd[nod]+=spd[nxt];
        }

    return cnt;
}

int main(){
    cin >> N >> K;

    int i,x,y;
    for (i=1; i<N; i++){
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    int res=0;
    for (i=1; i<=N; i++){
        int cr=dfs(i,0,i);
        if (K%2){
            int mx=0;
            for (int nxt : g[i])
                mx=max(mx,spd[nxt]);
            cr+=mx;
        }
        res=max(res,cr);
    }

    cout << N-res << "\n";

    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

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

        if (a < b && b < c){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}


int main(){
  int n; cin >> n;
  vector<int> v(n-1);
  cin >> v;
  vector<int> ans(n);
  for(auto e:v){
    ans[e-1]++;
  }
  for(auto e:ans)cout << e << endl;
  return 0;
}


Measured memory_bytes: 4752
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>

using namespace std; 

// There is somehow a small intolerable error when calculating with sqr(pow(dx) + pow(dy))
// I guess it is better to avoid these methods as much as possible...
// Also setprecision in the output stream to make sure that everything is outputted correctly!
double dist(int x1, int y1, int x2, int y2) {
  double dx = x1 - x2;
  double dy = y1 - y2;
  return pow(dx * dx + dy * dy, 0.5);
}

int main() {
  int N; cin >> N;
  vector<vector<int>> coords(N, vector<int>(2));
  for (int i = 0; i < N; i++) {
    cin >> coords[i][0] >> coords[i][1];
  }

  vector<int> order(N);
  for (int i = 0; i < N; i++) order[i] = i;

  double sum = 0;
  int count = 0;
  do {
    double total_distance = 0;
    for (int j = 1; j < N; j++) {
      double distance = dist(coords[order[j]][0], coords[order[j]][1], coords[order[j-1]][0], coords[order[j-1]][1]);
      total_distance += distance;
    }
    sum += total_distance;
    count++;
  } while (next_permutation(order.begin(), order.end()));
  // We have to permute a separate 1d array because somehow if you permute a 2darray it never reaches the last permutation...
  // This should NEVER happen in a modern language

  double avg = sum / count; 
  cout << fixed << setprecision(10) << avg << endl; 
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
//const lint MOD = pow(10, 9) + 7;

int main() {
	double a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << setprecision(20) << sqrt((a - c) * (a - c) + (b - d) * (b - d)) << endl;
}


Measured memory_bytes: 3272
#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;
    cin >> N;
    vector<int> L(N);
    rep(i,N) cin >> L[i];
    sort(L.begin(),L.end());
    int 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( L[i] + L[j] > L[k]  ){
                    if( L[i] < L[j] and L[j] < L[k] ){
                        ++ans;
                    }
                }else{
                    break;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int main()
{
    string s,t[]={"Sunny","Cloudy","Rainy"};
    cin >> s;
    if(s == t[0])cout << t[1] << endl;
    else if(s==t[1])cout << t[2] << endl;
    else cout << t[0] << endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int i,count=0;
    for(i=0;i<s.size();i++)
    {
        if(s[i]==s[i+1])
        count++;
    }
    if(count>=1)
        cout<<"Bad"<<endl;
    else
        cout<<"Good"<<endl;
    return 0;

}


Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
#define MM 2100000000
using namespace std;
int dp[101][100001];
int main(void)
{
	int i,j,n,wm,w[100],v[100],mx,sum,m2,x;
	scanf("%d %d",&n,&wm);
	sum=0;
	for(i=0;i<n;i++)	{
		scanf("%d %d",&w[i],&v[i]);
		sum+=v[i];
	}
	for(i=0;i<=n;i++)	{
		for(j=0;j<=sum;j++)	{
			dp[i][j]=MM;
		}
	}
	mx=0;
	dp[0][0]=0;
	for(i=0;i<n;i++)	{
		m2=mx;
		for(j=0;j<=mx;j++)	{
			if(dp[i][j]!=MM)	{
				dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
				x=dp[i][j]+w[i];
//				printf("i=%d j=%d x=%d\n",i,j,x);
				if(x<=wm)	{
					dp[i+1][j+v[i]]=min(dp[i+1][j+v[i]],x);
					m2=max(m2,j+v[i]);
				}
			}
		}
		mx=m2;
	}
	printf("%d\n",mx);
	return 0;
}

Measured memory_bytes: 39552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))


int main(){
    int n;  cin >> n;
    vector<vector<pair<ll, ll>>> g(n);
    
    REP(i, n-1){
        ll a, b, c;     cin >> a >> b >> c;
        a--; b--;
        g[a].emplace_back(c, b);
        g[b].emplace_back(c, a);
    }
    
    priority_queue<pair<int, int>, vector<pair<int, int>>,  greater<pair<int, int>>> que;
    vector<ll> path(n, 1e+15);
    int q, k;   cin >> q >> k;
    path[k-1] = 0;
    que.emplace(0, k-1);
    while(!que.empty()){
        pair<ll, ll> p = que.top();   que.pop();
        int v = p.second;
        if(path[v]<p.first) continue;
        for(auto x: g[v]){
            if(path[v] + x.first<path[x.second]){
                path[x.second] = path[v] + x.first;
                que.emplace(path[x.second], x.second);
            }
        } 
    }
    
    REP(i, q){
        int x, y;   cin >> x >> y;
        cout << path[x-1]+path[y-1] << endl;
    }

    
}

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

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

#define rep(n) for (int i = 0; i < n; ++i)

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> pii;
typedef double D;
typedef complex<D> P;
typedef vector<string> vs;

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

#define fill(x,y) memset(x,y,sizeof(x))

// with compile option -DLOCAL
#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

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

#define pcnt __builtin_popcount
#define pcntll __builtin_popcountll

#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};



#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

const int MOD = 1e9 + 7;
const int INF = INT_MAX;

int get_ans(int val) {
    int ret = 0;
    while(val != 0) {
        ret += val % 10;
        val /= 10;
    }

    return ret; 
}

signed main() {
    Fast();

    int n;
    cin >> n;
    
    int ret = INF;
    for(int a=1; a < n; a++) {
        int b = n - a;
        ret = min(get_ans(a) + get_ans(b), ret);
    }

    cout << ret << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
int a[maxn];
int main()
{  
    int a,b;
    cin>>a>>b;
     if(a<b)
    swap(a,b);
    cout<<a+max(a-1,b)<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define N 2000000

using namespace std;

int main(){
  int i, j, n, k=0;
  int A[N], B[N], C[N];

  cin >> n;
  for(i=0;i<n;++i){
    cin >> A[i];
    if(A[i] > k) k = A[i];
  }
  
  for(i=0;i<=k;++i)C[i] = 0;
  for(i=0;i<n;++i)C[A[i]]++;
  for(i=0;i<=k;++i)C[i] += C[i-1];
  for(j=n-1;j>=0;--j){
    B[C[A[j]]-1] = A[j];
    C[A[j]]--;
  }
  
  for(i=0;i<n;++i){
    cout << B[i];
    if(i != n-1)cout << " ";
  }
  cout << "\n";
  return 0;
}



Measured memory_bytes: 18772
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x); i<=(y); i++)
#define ll long long
#define N 100005
using namespace std;
int n,q,L,a[N],f[N][20];
bool check(int x,int y,int z){
	rep (i,0,17) if (z>>i&1) x=f[x][i];
	return x>=y;
}
int main(){
	scanf("%d",&n);
	rep (i,1,n) scanf("%d",&a[i]);
	scanf("%d",&L);
	rep (i,1,n){
		int p=upper_bound(a+i,a+1+n,a[i]+L)-a; p--;
		f[i][0]=p;
	}
	rep (j,1,17) rep (i,1,n) f[i][j]=f[f[i][j-1]][j-1];
	scanf("%d",&q);
	while (q--){
		int x,y; scanf("%d%d",&x,&y);
		if (x>y) swap(x,y);
		int l=0,r=n,mid;
		while (l<=r){
			mid=l+r>>1;
			if (check(x,y,mid)) r=mid-1; else l=mid+1;
		}
		printf("%d\n",r+1);
	}
	return 0;
}

Measured memory_bytes: 9088
func is_prime(n: Int) -> Bool{
    if (n <= 1) {
        return false
    }

    if (n <= 3) {
        return true
    }

    var i = 2
    while (i*i <= n) {
        if (n % i == 0) {
           return false
        }
      
        i = i + 1
    }
    return true
}

let a=Int(readLine()!)!

var i = 0
while( true ) {
	if( is_prime(a + i) ) {
      print(a + i)
      break
    }
    i += 1
}
  
  

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    ll n, k; cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    
    vector<int> bits(41, 0);
    rep(i, n) {
        ll num = a[i];
        rep(j, 41) {
            if (num%2==0) bits[j]++;
            num /= 2;
        }
    }
    debug(bits);
    rep(i, 41) {
        if (bits[i]>n/2) bits[i]=1;
        else bits[i]=0;
    }
    debug(bits);
    ll tot = 0;
    for(int i=40; i>=0; i--) {
        ll num = 1ll<<i;
        if (bits[i] && tot+num>k) {
            bits[i]=0;
        } else if (bits[i]) {
            tot += num;
        }
    }
    debug(tot);
    ll ans = 0;
    rep(i, n) {
        ans += tot^a[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n,a,b = LI()
    if b < a:
        print(0)
        return
    if n == 1 and a != b:
        print(0)
        return
    mi = a*(n-1)+b
    ma = b*(n-1)+a
    print(abs(ma-mi)+1)
    return
#B
def B():

    return

#C
def C():

    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 40304
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
int cmp(const void *a, const void *b);
//your code here!

int main(void){
    ll A, B, C;
    scanf("%lld %lld %lld", &A, &B, &C);
    if(A==B)printf("%lld\n", C);
    else if(B==C)printf("%lld\n", A);
    else printf("%lld\n", B);
    return 0;
}

int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート
}


Measured memory_bytes: 128
import numpy as np
W,H,N=map(int, input().split())
R=np.zeros((H,W))
for i in range(N):
    x,y,a=map(int, input().split())
    if a==1:
        R[:,:x]=1
    elif a==2:
        R[:,x:]=1
    elif a==3:
        R[:y,:]=1
    else:
        R[y:,:]=1

print(int(W*H- R.sum()))


Measured memory_bytes: 22560
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string s;
	cin >> s;

	Int len = s.size();
	Int flag = 0;
	for (Int l = 0; l < len; l++) {
		for (Int r = l; r < len; r++) {
			string temp = "";
			for (Int i = 0; i < l; i++) {
				temp += s[i];
			}
			for (Int j = r+1; j < len; j++) {
				temp += s[j];
			}
			if (temp=="keyence") {
				flag = 1;
				break;
			}
		}
		if (flag) {
			break;
		}
	}

	if (s=="keyence") {
		flag = 1;
	}

	if (flag) cout << "YES" << "\n";
	else cout << "NO" << "\n";
}


Measured memory_bytes: 764
#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 a,b,ans;
    cin >> a >> b;
    ans=a*b;
    if(a>9 or b>9){
        ans=-1;
    }

    cout << ans << endl;

    return 0;
}

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

int bubbleSort(int A[], int N){
  int sw = 0;
  bool flag = 1;
  for(int i = 0; flag; i++){
    flag = 0;
    for(int j = N - 1;j >= i + 1; j--){
      if(A[j] < A[j - 1]){
          
	swap(A[j],A[j - 1]);
	flag = 1;
	sw++;

      }
    }
  }
  return sw;
}

int main(){
  int A[100],N,sw;
  cin >> N;
  for( int i = 0; i < N; i++) cin >> A[i];

  sw = bubbleSort(A, N);

  for(int i = 0; i < N; i++){
    if(i) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;

  return 0;
}



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



int main() {
   long long int a, b, c, k;
   cin >> a >> b >> c >> k;
   int ans = 0;
   if ((a > 0)) {
      for (int i=0; i<a; i++) {
         if (k>0){
            ans++;
            k = k-1;
         }
         else continue;
      }
   }
   if ((b > 0)) {
      for (int i=0; i<b; i++) {
         if (k>0){
            k = k-1;
         }
         else continue;
      }
   }
   if ((c > 0)) {
      for (int i=0; i<c; i++) {
         if (k>0){
            ans = ans - 1;
            k = k-1;
         }
         else continue;
      }
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 3676
import collections
import math
import operator as op
from functools import reduce
from collections import Counter
import numpy as np
import math
import bisect
import heapq


def get_inputs(cast_func=None):
    if cast_func is None:
        return input().split()
    else:
        return list(map(cast_func, input().split()))


def get_input(cast_func=None):
    if cast_func is None:
        return input()
    else:
        return cast_func(input())


def main():
    N = get_input(int)
    A = get_inputs(int)

    ans = 0
    Ai_plus_i = collections.Counter()
    for j in range(1, N+1):
        A_j = A[j-1]

        ans += Ai_plus_i[j - A_j]
        Ai_plus_i[A_j + j] += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 58000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for(int i = (int)(n); i>=0; --i)
struct fast_ios { fast_ios(){cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast_ios_;

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);

    int cnt = 0;
    rep(i, N)
    {
        cin >> a[i];
        if(i%2==0 && a[i]%2!=0)
        {
            cnt++;
        }
    }

    cout << cnt << endl;


    return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System. in);
      
      	boolean isBad = false;
      	String str = sc.next();
      	//String [] strArr = str.split("");
      	String a = "";
      
      	for (int i = 0; i <= 3; i++){
          //	System.out.println(strArr[i]);
           if (String.valueOf(str.charAt(i)).equals(a)){
            isBad = true; 
           }
          a = String.valueOf(str.charAt(i));
        }
      	String out = "";
      	if (isBad == true){
          out = "Bad";
        }else{
          out = "Good";
        }
		System.out.println(out);
	}
}

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

#define ll  long long
#define endl "\n" 
#define FOR(n) for(int i=0 ; i<n ; i++)
#define FORa(a, n) for(ll i=a ; i<=n ; i++)
ll mod=1000000007;
ll inf=1e9;

int gcd(int a , int b){
  if(a==0) return b;
  return gcd(b%a , a);
}
void solve()
{
  string s;
  int x,y,ct=0,n,mx=0;
  cin >> n;
  FOR(n){
    cin >> x >> y;
    if(x==y){
      ct++;
    }else{
      ct=0;
    }
   mx=max(ct,mx);
  }
  if(mx>=3) cout << "Yes\n";
  else cout << "No\n";


}

  


int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t=1;
  //cin >> t;
  while(t--)
    solve();
    return 0 ;
}


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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int INF = 0x3f3f3f3f;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;
//const int MOD = (int) 1e9 + 7;
const int MOD = (int) 998244353;
const int maxn = (int) 2e5 + 20;
const int maxm = (int) 1e6 + 20;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL MOD)
{
    if(n < 0) a = fp(a, MOD - 2, MOD), n = -n;
    LL res = 1; for(; n; n >>= 1, a = a * a % MOD) if(n & 1) res = res * a % MOD; return res;
}

int n, m;
LL dp[3333];

void work()
{
    cin >>n >>m;
    LL ans = 0;
    for(int i = 1; i <= n; i++)
    {
        int x; cin >>x;
        for(int j = m; j >= x; j--)
        {
            if(j == x) dp[j] += i;
            else dp[j] += dp[j - x];

            if(dp[j] >= MOD) dp[j] -= MOD;
        }

        ans += dp[m];
        if(ans >= MOD) ans -= MOD;
    }
    cout <<ans <<endl;
}

int main(int argc, char **argv)
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
//    pre();
    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


Measured memory_bytes: 256
a = input()
b = input()
c = input()

# 文字のマッチング(?はワイルドカード)
def match(a, b):
    return a=="?" or b=="?" or a==b

ab = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にBを置けるか？
ac = [True] * 100000 # Aに対して(i-50000)個左にスライドした位置にCを置けるか？
bc = [True] * 100000 # Bに対して(i-50000)個左にスライドした位置にCを置けるか？

def check(a, b, ab):
    for i in range(len(a)):
        for j in range(len(b)):
            if not match(a[i], b[j]):
                ab[i-j+50000] = False

check(a, b, ab)
check(a, c, ac)
check(b, c, bc)

len_max = 2000
len_a = len(a)
len_b = len(b)
len_c = len(c)

ans = len_a + len_b + len_c

# i = BをAに対していくつスライドして置くか
for i in range(-2 * len_max, 2 * len_max + 1):
    # j = CをAに対していくつスライドして置くか
    for j in range(-2 * len_max, 2 * len_max + 1):
        if ab[i+50000] and ac[j+50000] and bc[j-i+50000]:
            left = min(0, i, j)
            right = max(len_a, len_b+i, len_c+j)
            if right - left < ans:
                ans = right - left

print(ans)


Measured memory_bytes: 52688
#include<cstdio>
#include <iostream>
using namespace std;
int n,k,ans,p;
int map[12][6]={
    {4,2,0,9,7},
    {1,10,8,6,4},
    {9,7,5,3,1},
    {6,4,2,0,9},
    {3,1,10,8,6},
    {0,9,7,5,3},
    {8,6,4,2,0},
    {5,3,1,10,8},
    {2,0,9,7,5},
    {10,8,6,4,2},
    {7,5,3,1,10}};
int main()
{
    scanf("%d%d",&n,&k);n-=2;
    p=n%11;n/=11;
    ans=n*5;
    for(int i=0;i<p;i++)
     for(int j=0;j<5;j++)
      if(map[i][j]==k)ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<vector<int>> player(N,vector<int>(N));
    REP(i,N) REP(j,N-1){
        cin >> player[i][j];
        player[i][j]--;
    }
    int ans = 0;
    vector<int> cnt(N);
    int sum = 0;
    int step = 0;
    while(sum < N*(N-1)){
        ans++;
        int tmp = sum;
        vector<bool> done(N);
        REP(i,N){
            step++;
            if(cnt[i] > ans) continue;
            if(cnt[i] >= N-1) continue;
            int outside = player[i][cnt[i]];
            if(cnt[outside] < ans){
                if(i == player[outside][cnt[outside]] && !done[i] && !done[outside]){
                    //cout << i+1 << ":" << outside+1 << endl;
                    cnt[i]++;
                    cnt[outside]++;
                    done[i] = true;
                    done[outside] = true;
                    sum += 2;
                }
            }
            else continue;
        }
        if(sum == tmp){
            cout << -1 << endl;
            return 0;

        }
        if(sum >= N*(N-1)) break;
        //cout << ans << endl;
        if(step >= 1e8){
            cout << N*(N-1)/2 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}


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

int main() {
	string a,b,c,d;
	int ans=0;
	cin >> a ;
	for (int i = 0; i < 4; i++) {
		if (a[i] == '+') {
			ans++;
		}
		else {
			ans--;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
LL n,m,f[2010];
struct node{
	LL l,r,a;
}a[200010];
bool cmp(node a,node b) {return a.r<b.r;}
struct trnode{
	LL lc,rc,c,u;
}tr[400010];LL tot=0;
LL bt(LL l,LL r)
{
	LL x=++tot;
	if(l!=r)
	{
		LL mid=(l+r)/2;
		tr[x].lc=bt(l,mid);
		tr[x].rc=bt(mid+1,r);
	}
	return x;
}
void update(LL x)
{
	LL lc=tr[x].lc,rc=tr[x].rc,c=tr[x].u;
	tr[lc].c+=c;tr[rc].c+=c;
	tr[lc].u+=c;tr[rc].u+=c;
	tr[x].u=0;
}
void change(LL x,LL l,LL r,LL fl,LL fr,LL c)
{
	if(l==fl&&r==fr) {tr[x].c+=c;tr[x].u+=c;return;}
	LL mid=(l+r)/2;
	if(tr[x].u!=0) update(x);
	if(fr<=mid) change(tr[x].lc,l,mid,fl,fr,c);
	else if(fl>mid) change(tr[x].rc,mid+1,r,fl,fr,c);
	else change(tr[x].lc,l,mid,fl,mid,c),change(tr[x].rc,mid+1,r,mid+1,fr,c);
	tr[x].c=max(tr[tr[x].lc].c,tr[tr[x].rc].c);
}
LL findans(LL x,LL l,LL r,LL fl,LL fr)
{
	if(l==fl&&r==fr) return tr[x].c;
	LL mid=(l+r)/2;
	if(tr[x].u!=0) update(x);
	if(fr<=mid) return findans(tr[x].lc,l,mid,fl,fr);
	if(fl>mid) return findans(tr[x].rc,mid+1,r,fl,fr);
	return max(findans(tr[x].lc,l,mid,fl,mid),findans(tr[x].rc,mid+1,r,mid+1,fr));
}
int main()
{
	scanf("%lld %lld",&n,&m);
	for(LL i=1;i<=m;i++) scanf("%lld %lld %lld",&a[i].l,&a[i].r,&a[i].a);
	sort(a+1,a+m+1,cmp);
	LL p=0;bt(0,n);
	for(LL i=1;i<=n;i++)
	{
		change(1,0,n,i,i,findans(1,0,n,0,i-1));
		while(p<m&&a[p+1].r==i) p++,change(1,0,n,a[p].l,a[p].r,a[p].a);
	}
	printf("%lld",findans(1,0,n,0,n));
}


Measured memory_bytes: 17536
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int num = 0;

        if(N % 1000 != 0) {
        	num = 1000 - N % 1000;
        }

        System.out.println(num);

    }
}

Measured memory_bytes: 35792
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

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

struct xy{
    int x;
    int y;
};

int main(){

    int n, m;
    cin >> n >> m;
    xy student[60], check[60];
    for(int i=0; i<n; i++){
        cin >> student[i].x >> student[i].y;
    }

    for(int j=0; j<m; j++){
        cin >> check[j].x >> check[j].y;
    }

    int tmp;
    for(int k=0; k<n; k++){
        //生徒ごとにループ
        int min = 100000000*4;
        for(int l=0; l<m; l++){
            int kyori = abs(student[k].x - check[l].x) + abs(student[k].y - check[l].y);
            if(min > kyori){min = kyori; tmp=l;}
        }
        cout << tmp+1 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a[100010],f,ff;
int main(){
	cin>>n;
	for (int i=0;i<n;i++) cin>>a[i];
	f=a[0]-1;
	for (int i=1;i<n;i++)
		if (a[i]>f)
			f=a[i]-1;
		else if (a[i]!=f)
			ff=1;
	if (ff==1)
		cout<<"No"<<endl;
	else
		cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

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

    vector<int64_t> x(H * W + 1);
    vector<int64_t> y(H * W + 1);
    for(int i = 0; i < H; ++i) for(int j = 0; j < W; ++j){
        int A;
        cin >> A;
        x[A] = i;
        y[A] = j;
    }

    vector<int64_t> score(H * W + 1);
    for(int i = D + 1; i <= H * W; ++i){
        score[i] = abs(x[i] - x[i - D]) + abs(y[i] - y[i - D]);
    }

    for(int i = 1; i <= H * W - D; ++i){
        score[i + D] += score[i];
    }

    int Q;
    cin >> Q;
    for(int i = 0; i < Q; ++i){
        int L, R;
        cin >> L >> R;
        cout << score[R] - score[L] << endl;
    }
}

Measured memory_bytes: 3200
/*
    And I know I may end up failing too
*/




#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
#define dbg          cout<<"Freak"<<endl;
#define dbgg(i)      cout<<i<<endl;
#define N            1e9+7
#define pb           push_back
#define pf           push_front
#define pi           acos(-1)
#define all(x)       x.begin(),x.end()
#define fast         ios_base::sync_with_stdio(false);cin.tie(NULL);
#define INF          0x3f3f3f3f
struct hash_pair
{
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1> {}(p.first);
        auto hash2 = hash<T2> {}(p.second);
        return hash1 ^ hash2;
    }
};




ll t;
ll m=N;
ll arr[100005];
ll dp[100005];

int main()
{
    ll a,b,c,d,e,f,g,i,j;
    ll n,k,x;
    cin>>n>>k;
    for(i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    memset(dp,INF,sizeof(dp));
    dp[1]=0;
    for(i=2;i<=n;i++)
    {
        for(j=i-1;j>=1&&j>=i-k;j--)
        {
            dp[i]=min(dp[i],dp[j]+abs(arr[i]-arr[j]));
        }
    }
    cout<<dp[n]<<endl;
    return 0;

}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
	cout << fixed << setprecision(10);
	int n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	REP(i, n)
	{
		cout << s[i];
		cout << t[i];
	}
	return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
drink_dict = {}
for i in range(N):
  A,B = map(int,input().split())
  if A not in drink_dict:
  	drink_dict[A] = B
  else:
    drink_dict[A] += B 
drink_list = sorted(drink_dict.items())
total_number = 0
total_price = 0
for i in drink_list:
  if total_number + i[1] >= M:
    print(total_price + (M-total_number) * i[0])
    break;
  else:
    total_price+=i[0]*i[1]
    total_number+= i[1]

Measured memory_bytes: 22992
H, W = map(int, input().split())
l = [["." for i in range(W + 2)]]
for i in range(H):
    temp = list(input())
    temp.insert(0, ".")
    temp.append(".")
    l.append(temp)

l.append(["." for i in range(W + 2)])
Flag = True
for i in range(H + 2):
    if i == 0 or i == H + 1:
        continue
    
    for j in range(W + 2):
        if j == 0 or j == W + 1:
            continue
        if l[i][j] == "#":
            #上下左右
            if l[i-1][j] == "." and l[i+1][j] == "." and l[i][j-1] == "." and l[i][j+1] == ".":
                Flag = False
                break
    
    if Flag == False:
        break 

if Flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/



int main() {
	int N;
	cin >> N;
	vector<int>p(N);
	rep(i, N) {
		cin >> p[i];
	}
	int cnt = 0;
	for (int i = 1; i < N; i++) {
		if (p[i - 1] > p[i]) {
			cnt++;
		}
	}
	if (cnt == 0) {
		cout << "YES" << endl;
		return 0;
	}
	cnt = 0;
	int a = 0;
	int b = 0;
	vector<int>pp(N);
	rep(i, N) {
		rep(j, N) {
			if (i < j) {
				rep(k, N) {
					pp[k] = p[k];
				}
				a = pp[i];
				b = pp[j];
				pp[i] = b;
				pp[j] = a;
				for (int k = 1; k < N; k++) {
					if (pp[k - 1] > pp[k]) {
						cnt++;
					}
				}
				if (cnt == 0) {
					cout << "YES" << endl;
					return 0;
				}
				cnt = 0;
			}
		}
	}
	cout << "NO" << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 10007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //------------------------------
    
int n;cin>>n;
vector<int>a(n);
for(int i=0;i<n;i++)
    cin>>a[i];
reverse(all(a));
for(int i=0;i<n;i++){
    cout<<a[i];
    if(i<n-1)cout<<" ";
}
;cout<<endl;
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------


































Measured memory_bytes: 3232
test = False


def solve_a(test=False, a=0, b=0, c=0):
    if not test:
        a, b, c = map(int, input().split())
    d = max(c - (a - b), 0)
    print(d)


def solve_b(test=False, n=0):
    if not test:
        n = int(input())
    res = 0
    for i in range(1, n + 1):
        if len(str(i)) % 2 == 1:
            res += 1
    print(res)


def solve_c(test=False, n=0, h_list=[]):
    if not test:
        n = int(input())
        h_list = list(map(int, input().split()))
    res = 'Yes'
    new_h_list = [0] * n
    new_h_list[0] = h_list[0] - 1

    for i in range(1, n):
        # cannot down
        if h_list[i] == new_h_list[i - 1]:
            new_h_list[i] = h_list[i]
        elif h_list[i] < new_h_list[i - 1]:
            new_h_list[i] = h_list[i]
            res = 'No'
        else:
            new_h_list[i] = h_list[i] - 1
    print(res)


if __name__ == "__main__":
    if test:
        solve_a(test=True, a=6, b=4, c=3)
        solve_a(test=True, a=8, b=3, c=9)
        solve_a(test=True, a=12, b=3, c=7)
        solve_b(test=True, n=11)
        solve_b(test=True, n=136)
        solve_b(test=True, n=100000)
        solve_c(test=True, n=5, h_list=[1, 2, 1, 1, 3])
        solve_c(test=True, n=4, h_list=[1, 3, 2, 1])
        solve_c(test=True, n=5, h_list=[1, 2, 3, 4, 5])
        solve_c(test=True, n=1, h_list=[1000000000])
    else:
        # solve_a()
        # solve_b()
        solve_c()


Measured memory_bytes: 63984
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define break break
#define continue continue
#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
typedef long long ll;

using namespace std;


int main(void){
	int x, y; cin >> x >> y;
	int ans = 0;
	if(x == 1) ans += 300000;
	else if(x == 2) ans += 200000;
	else if(x == 3) ans += 100000;
	if(y == 1) ans += 300000;
	else if(y == 2) ans += 200000;
	else if(y == 3) ans += 100000;
	if(ans == 600000) ans += 400000;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

ll f(ll n) {return n * (n+1) / 2;}

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  string s[h];
  rep(i,h) cin >> s[i];
  int ans = 0, ss = 0;

  rep(i,h) rep(j,w) {
    if (s[i][j] == '#') ss++;
  }

  vector<int> sh(h), sw(w);
  rep(i,h) {
    int sum = 0;
    rep(j,w) {
      if (s[i][j] == '#') sum++;
    }
    sh[i] = sum;
  }
  rep(i,w) {
    int sum = 0;
    rep(j,h) {
      if (s[j][i] == '#') sum++;
    }
    sw[i] = sum;
  }
  
  for (int bit = 0; bit < (1<<h); bit++) {
    int sum = ss;
    vector<int> a;
    rep(i,h) {
      if (bit & (1 << i)) {
        sum -= sh[i];
        a.push_back(i);
      }
    }
  
    for (int bb = 0; bb < (1<<w); bb++) {
      vector<int> b;
      int rr = sum;
      rep(j,w) {
        if (bb & (1 << j)) {
          rr -= sw[j];
          b.push_back(j);
        }
      }

      for (auto x : a) {
        for (auto y : b) {
          if (s[x][y] == '#') rr++;
        }
      }
      
      if (rr == k) ans++;
    }
  }
  
  cout << ans << endl;
  
}



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

using namespace std;


class A {
	string s1, s2;
public:
	void solve()
	{
		cin >> s1 >> s2;

		if (s1[0] == s2[2] && s1[1] == s2[1] && s1[2] == s2[0]) cout << "YES" << endl;
		else cout << "NO" << endl;

	}
};


int main()
{
	A solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
int N;
int V[20], C[20];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>N;
    rep(i,0,N) cin>>V[i];
    rep(i,0,N) cin>>C[i];
    int ans=0;
    rep(i,0,N){
        if(V[i]>C[i]) ans+=V[i]-C[i];
    }
    cout <<ans<<"\n";
}

Measured memory_bytes: 256
S = list(input())
T = list(input())

def compare(s, t):
    if len(s) != len(t): return False
    res = True
    for i in range(len(s)):
        res &= (s[i] == t[i] or s[i] == '?')
    return res

n = len(S)
m = len(T)
pos = -1
for i in range(n):
    if compare(S[i:i+m], T):
        pos = i

if pos == -1:
    print('UNRESTORABLE')
else:
    S[pos:pos+m] = T
    S = ''.join(S)
    S = S.replace('?', 'a')
    print(S)

Measured memory_bytes: 3064
package main

import (
	"fmt"
)

func main() {

	var N int

	fmt.Scan(&N)

	A := SliceInt(N)

	for i:=0;i<N-1;i++{

		fmt.Scan(&A[i])
	}

	res := make(map[int]int)

	for i:=0;i< N-1;i++{

		val,ok := res[A[i]]

		if ok == true{

			res[A[i]] = val+1
		
		}else{

			res[A[i]]=1
		}
	}


	for i:=1;i<=N;i++{

		val,ok := res[i]

		if ok==true{

			fmt.Println(val)

		}else{

			fmt.Println(0)
		}

	}

}

//SliceInt 引数サイズのSliceを返す
func SliceInt(a int) []int {

	IntSample := make([]int, a)

	return IntSample

}

Measured memory_bytes: 15848