akhauriyash/Code-Regression huggingface dataset:
def create_list(n):
    result = [[i for i in map(int,input().split())] for j in range(n)]
    return result 

n,m = map(int,input().split())
x_list   = create_list(n)
y_list   = create_list(m)

for x in x_list:
    ans   = 0
    min_n = float('inf')
    for i,y in enumerate(y_list):
        temp = abs(x[0]-y[0]) + abs(x[1]-y[1])
        if temp < min_n:
            min_n = temp
            ans = i+1
    print(ans)

Measured memory_bytes: 3064
n=int(input())
a,b=map(int,input().split())
p=list(map(int,input().split()))
q1,q2=0,0
for i in range(n):
    if p[i]<=a:
        q1+=1
    elif p[i]<=b:
        q2+=1
print(min(q1,q2,n-(q1+q2)))

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
 
public class Main {
	static long mod=(long)1e9+7;
	static long[][][][]memo;
	static int n;
	static long dp(int i,int p1,int p2,int p3) {
		if(i==n)return 1l;
		if(memo[i][p1][p2][p3]!=-1)return memo[i][p1][p2][p3];
		if((p1==0 && p2==2) || (p1==2 && (p2==0 || p3==0)) || (p2==2 && p3==0)) {
			return memo[i][p1][p2][p3]=(dp(i+1,0,p1,p2)+dp(i+1,2,p1,p2)+dp(i+1,3,p1,p2))%mod;
		}
		if(p1==1 && p2==0) {
			return memo[i][p1][p2][p3]=(dp(i+1,0,p1,p2)+dp(i+1,1,p1,p2)+dp(i+1,3,p1,p2))%mod;
		}
		return memo[i][p1][p2][p3]=(dp(i+1,0,p1,p2)+dp(i+1,2,p1,p2)+dp(i+1,1,p1,p2)+dp(i+1,3,p1,p2))%mod;
	}
	public static void main(String[] args) throws IOException {
		MScanner sc = new MScanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		n=sc.nextInt();
		memo=new long[n][5][5][5];
		for(long[][][]i:memo) {
			for(long[][]j:i) {
				for(long[]o:j) {
					Arrays.fill(o, -1);
				}
			}
		}
		pw.println(dp(0,4,4,4));
		pw.flush();
 
	}
    static class MScanner {
		StringTokenizer st;
		BufferedReader br;
 
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
 
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

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

signed main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N + 1);
    for (int i = 0; i < M; i++) {
        int A, B;
        cin >> A >> B;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    vector<bool> check(N + 1, false);
    auto judge = [&](int now) {
        for (auto temp : G[now]) {
            if (check[temp]) continue;
            check[temp] = true;
            return temp;
        }
        return -1LL;
    };
    deque<int> ans;
    ans.push_back(1);
    check[1] = true;
    while (true) {
        int left = judge(*ans.begin());
        if (left != -1) {
            ans.push_front(left);
            continue;
        }
        int right = judge(*ans.rbegin());
        if (right != -1) {
            ans.push_back(right);
            continue;
        }
        break;
    }
    cout << ans.size() << endl;
    for (auto itr = ans.begin(); itr != ans.end(); itr++) {
        cout << *itr << (itr == next(ans.end(), -1) ? '\n' : ' ');
    }
}

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

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

    int ans = 0;
    for (int i = 1; i <= N; i += 2) {
        int cnt = 0;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) cnt++;
        }
        if (cnt == 8) ans++;
    }

    cout << ans << endl;
}

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

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

    string S;
    cin >> S;

    stack<char> s;
    int ans = 0;
    for(int i = 0; i < N; ++i){
        if(S[i] == '#'){
            s.emplace(S[i]);
        }else{
            if(!s.empty()){
                s.pop();
                ++ans;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 644
import java.util.*;

class Main {
	public static void main(String[] arg){
		Scanner in = new Scanner(System.in);
		while(true){
			int x = in.nextInt();	
			int y = in.nextInt();
			if (x == 0 && y == 0)break;
			StringBuilder sb = new StringBuilder();
			for(int i = 0;i < x;i++){
				for(int j=0;j < y;j++){
					if( (i%2 == 0 && j%2 == 0)||(i%2 == 1 && j%2 == 1)){
						sb.append("#");
					}
					else{
						sb.append(".");
					}
				}
				sb.append("\n");
			}
			System.out.println(sb);
		}	
	}
}

Measured memory_bytes: 21380
A, B, C = map(int, input().split())

tmp = A // 2
ans = abs(tmp * B * C - (A - tmp) * B * C)
tmp = B // 2
ans = min(ans, abs(tmp * A * C - (B - tmp) * A * C))
tmp = C // 2
ans = min(ans, abs(tmp * A * B - (C - tmp) * A * B))

print(ans)


Measured memory_bytes: 3060
#include<stdio.h>

int main()
{
	int i,j,n,m, s[100];
	int total;

	scanf("%d", &n);

	j = 0;
	total = 0;
	for (i = 1; n / i != 0; i *= 10)
	{
		m = n % (i * 10);
		s[j] = m / i;

		total += s[j];
	}

	if (n%total == 0)
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}

Measured memory_bytes: 128
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(13)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> Q;
//ll longinf=1ll<<60;
int inf=1<<29;
int dn[4]={-1,1,0,0};
int dm[4]={0,0,-1,1};
ll longinf=(1ll<<60);

const ll MOD = 1e9+7;

ll add(ll a,ll b){
      return ((a%MOD)+(b%MOD))%MOD;
}

ll mul(ll a,ll b){
      return ((a%MOD)*(b%MOD))%MOD;
}

ll pow(ll a,ll b){
      if(b==0) return 1;
      else if(b%2==0) return ((pow(a,b/2)%MOD)*(pow(a,b/2)%MOD))%MOD;
      else return ((pow(a,b-1)%MOD)*(a%MOD))%MOD;
}
ll div(ll a,ll b){
      return ((a%MOD)*(pow(b,MOD-2)%MOD))%MOD;
}

const int index = 1e5+1;
ll frac[index+1];
void calc(){ //main関数内にcalc();を入れること
      frac[0]=1;
      rep0(i,index){
            frac[i+1]=mul(frac[i],i+1);
      }
}
int n,m;
int p[100002];
vector<int> connected[100002];
bool visited[100002];

class unionFind{
      private:
      vector<int> parent;
      vector<int> rank;
      int root(int x){
            if(parent[x]==x){
                  return x;
            }
            else{
                  parent[x] = root(parent[x]);
                  return parent[x];
            }
      }

      public:
      unionFind(int n){
            rep0(i,n){
                  parent.push_back(i);
                  rank.push_back(0);
            }
      }
      void merge(int x,int y){
            x=root(x);
            y=root(y);
            if(x==y) return;
            if(rank[x]<rank[y]) swap(x,y);
            if(rank[x]==rank[y]) rank[x]++;
            parent[y]=x;
            
      }
      bool same(int x,int y){
            return root(x)==root(y);
      }
};

int main(){
      cin>>n>>m;
      rep1(i,n) cin>>p[i];
      unionFind u(n);
      rep1(i,m){
            int x,y;
            cin>>x>>y;
            u.merge(p[x],p[y]);
      }
      int ans=0;
      rep1(i,n){
            if(u.same(i,p[i]))ans++; 
      }
      cout<<ans<<endl;


      return 0;
}

Measured memory_bytes: 3964
import sys

N, M = map(int, input().split())
PYI = [list(map(int, line.split())) for line in sys.stdin.readlines()]

for i in range(M):
    PYI[i].append(i)

PYI.sort(key = lambda x: x[1])

num = [0] * (N + 1)

ans = [None] * M

for p, y, i in PYI:
    ans[i] = str(p).zfill(6) + str(num[p] + 1).zfill(6)
    num[p] += 1

for s in ans:
    print(s)

Measured memory_bytes: 41888
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int M = Integer.parseInt(st.nextToken());
         if(M >= N)
            System.out.println("unsafe");
         else
            System.out.println("safe");
      }
   }

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

vector <int> g[100000];
int f[100000];
int was[100000];
int n,m;

int dfs(int x){
	if(was[x]) return f[x];
	was[x]=true;
	for(int i=0;i<g[x].size();i++){
		int to=g[x][i];
		f[x]=max(f[x],dfs(to)+1);
	}
	return f[x];
}

int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		x--;y--;
		g[x].push_back(y);
	}
	int ans=0;
	for(int i=0;i<n;i++) ans=max(ans,dfs(i));
	printf("%d",ans);
	return 0;
}

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

int main(){
  int N ;
  cin >> N ;
  string s ;
  cin >> s ;
  
  int ans =0;
  for(int i=0;i<N-1;i++){
    if(s.at(i)!=s.at(i+1)) {
      ans++;
    }
  }
  
  cout << ans+1 << endl;
}



Measured memory_bytes: 512
import string
abcxyz = string.ascii_lowercase
abccount = [0]*26
while 1:
    try:
        S = input()
    except:
        for i in range(26):
            print('{0} : {1}'.format(abcxyz[i], abccount[i]))
        break
    for x in S:
        if x.lower() in abcxyz:
            abccount[abcxyz.index(x.lower())] += 1


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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  ll tl;cin>>tl;
  ll n;cin>>n;
  vector<ll> s(n);
  vector<ll> t(n);
  ll i;
  rep(i,n)cin>>s[i]>>t[i];
  vector<ll> sum(n+1,0);
  rep(i,n)
  {
    sum[i+1]=sum[i]+(t[i]-s[i]);
  }
  ll ans=0;
  map<ll,ll> m;
  rep(i,n)
  {
    m.insert({s[i],i});
    m.insert({t[i],i});
  }
  rep(i,n)
  {
    ll kans=0;
    ll kst=s[i];
    ll kend=kst+tl;
    auto it=m.lower_bound(kend);
    if(it==m.end())
    {
      ll low=max(i,(ll)0);
      kans=sum[n]-sum[low];
    }
    else
    {
      pair<ll,ll> p;
      p=*it;
      ll time,ind;
      time=p.first;
      ind=p.second;
      if(s[ind]==time)
      {
        kans=sum[ind]-sum[i];
      }
      else
      {
        kans=sum[ind]-sum[i];
        kans+=kend-s[ind];
      }
    }
    ans=max(ans,kans);
  }
  /*
  rep(i,n)
  {
    ll kans=0;
    ll kst=s[i];
    ll kend=s[i]+tl-1;
    ll inds=lower_bound(all(s),kend)-s.begin();
    ll indt=lower_bound(all(t),kend)-t.begin();
    inds--;
    indt--;
    if(s[inds]<=t[indt])
    {
      kans+=sum[indt+1]-sum[i];
    }
    else
    {
      kans+=sum[indt+1]-sum[i];
      kans+=kend-t[inds]+1;
    }
    ans=max(ans,kans);
  }*/
  cout<<ans<<endl;
} 



Measured memory_bytes: 17608
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Random;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		PrintWriter pw=new PrintWriter(System.out);
		int A=sc.nextInt();
		int B=sc.nextInt();
		int ans=Math.max(A+B, A-B);
		ans=Math.max(ans, A*B);
		pw.println(ans);
		pw.close();
	}

	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public int nextInt() {
    	return Integer.parseInt(next());
    }
    
    public long nextLong() {
    	return Long.parseLong(next());
    }
}

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

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

    if (x >= 30) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
ll dp[2010];
int s;

int main()
{
    std::ios::sync_with_stdio(false);
    cin >> s;
    for(int i = 3; i <= 2000; i++) dp[i] = 1;
    for(int i = 1; i <= s; i++)
    {
    	for(int j = 3; j <= i; j++)
    	{
    		dp[i] += dp[i - j];
    		dp[i] %= mod;
		}
	}
	cout << dp[s] << endl;
	return 0;
}


Measured memory_bytes: 3608
def judge(S):
    S = "zzz" + S
    update = True
    while update:
        update = False
        if S[len(S)-7:] == "dreamer":
            S = S[:len(S)-7]
            update = True
        elif S[len(S)-6:] == "eraser":
            S = S[:len(S)-6]
            update = True
        elif S[len(S)-5:] == "dream" or S[len(S)-5:] == "erase":
            S = S[:len(S)-5]
            update = True
    if len(S) == 3:
        return True
    else:
        return False

S = input()

if judge(S):
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3316
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    s = S()
    t = S()
    if s == t[:len(t)-1]:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 9528
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

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

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int N; cin >> N;
	vl L(N);
	REP(i,N) cin >> L[i];
	int ans = 0;
	REP(i,N) FOR(j,i + 1,N) FOR(k,j + 1,N) {
		ll A = L[i];
		ll B = L[j];
		ll C = L[k];
		if (A != B && B != C && C != A && A + B > C && B + C > A && C + A > B) {
			++ans;
		}
	}
	cout << ans << endl;
}

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


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define pli pair<ll, int>

const long long INF = 1LL<<60;
const int inf = 1 << 30;
const int mod = 1e9+7;


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


int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, 0, n){
    cin >> a[i];
    a[i] -= (i+1);
  }
  sort(all(a));
  int mid = a[n / 2];
  long long ans = 0;
  for(auto x: a) ans += abs(x - mid);
  cout << ans << endl;
}


// abs(a[i] - b)

Measured memory_bytes: 1024
#include <iostream>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <chrono>
#include <math.h>
using namespace std;

using lli = long long int;
using Vint = vector<int>;
using Vlli = vector<lli>;
using Wint = vector<Vint>;
using Wlli = vector<Vlli>;
using pii = pair<int, int>;
using pll = pair<lli, lli>;

constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {make_pair(1, 0), make_pair(-1, 0), make_pair(0, 1), make_pair(0, -1)};
constexpr char BR = '\n';

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(ele, vec) for(auto &(ele) : (vec))
#define vREPcopy(ele, vec) for(auto (ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())


template <class T> inline int argmin(vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline void chmax(T &a, T b){a = max(a, b);}
template <class T> inline void chmin(T &a, T b){a = min(a, b);}
inline int toInt(string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline int toInt(const string s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(const string s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
template <class T> inline std::string toString(T n){
  if(n == 0) return "0";
  std::string res = "";
  if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;}
  std::reverse(res.begin(), res.end()); return '-' + res;}
  while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



constexpr int MAX_SIZE = 2e5+1;
int n, q, l = 0, r;
char Golem[MAX_SIZE], T[MAX_SIZE], D[MAX_SIZE];

int main(void){
  scanf("%d %d\n", &n, &q);
  r = n - 1;
  scanf("%s", Golem);
  REP(i, q){scanf("\n%c %c", T + i, D + i);}
  rREP(i, q){
    if(D[i] == 'L'){ // L
      if(Golem[l] == T[i]) l++;
      if(r != n - 1 and Golem[r+1] == T[i]) r++;
    }
    else{
      if(l != 0 and Golem[l-1] == T[i]) l--;
      if(Golem[r] == T[i]) r--;
    }
  }
  printf("%d\n", r-l+1);
  return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>

using namespace std;

void b_can_you_solve_this(void) {
	int n, m, c;
	int* b;
	int a;
	int sum[20] = { 0 };
	int cnt = 0;
	cin >> n >> m >> c;
	b = (int*)calloc(m, sizeof(int));
	for (int i = 0; i < m; i++) cin >> b[i];
	for (int j = 0; j < n; j++) {
		for (int i = 0; i < m; i++) {
			cin >> a;
			sum[j] += (a * b[i]);
		}
		sum[j] += c;
		if (sum[j] > 0) cnt++;
	}

	cout << cnt << endl;

	free(b);
}

int main()
{
    b_can_you_solve_this();

    return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
#define f(a,b,x) for(int a=b;a<x;a++)
#define pb push_back
#define endl "\n"
#define MX 200000
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define vi vector<int>

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int x,y;
    cin>>x>>y;
    if(y>=2*x&&y<=4*x&&y%2==0)
        yes;
    else
        no;

    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(int argc, const char * argv[]){
    int x,y,r,W,H;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    if(x<=W-r && y<=H-r && 0<=x-r && 0<=y-r){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    
    return 0;
}

Measured memory_bytes: 584
import java.util.Scanner;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int offset = Integer.parseInt(scanner.nextLine().split(" ")[1]);
		System.out.println(
				Arrays.stream(scanner.nextLine().split(" "))
					.mapToInt(Integer::parseInt)
					.map(i -> i - offset)
					.map(Math::abs)
					.filter(i -> i != 0)
					.reduce((i1, i2) -> gcd(i1, i2))
					.getAsInt()
				);
	}
	public static int gcd(int i1, int i2) {
		int bg = i1 > i2 ? i1 : i2;
		int sm = i1 > i2 ? i2 : i1;
		int remainder = sm;
		while(bg % sm != 0) {
			remainder = bg % sm;
			bg = sm;
			sm = remainder;
		}
		return remainder;
	}
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

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 (a>b) { a=b; return 1; } return 0; }

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

const ll INF = 1e9+7;


int main(){
	//ios_base::sync_with_stdio(0);
	int N, ans=0;
	string s;

	cin >> s;
	string t = "YAKI";
	
	bool f = true;
	if( s.size() < 4 ) f = false;
	else rep(i,4) if(s[i] != t[i]) f = false;

	cout << (f?"Yes":"No") << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define pb(a) push_back(a)
using namespace std;
typedef long long ll;

int N;

void func(ll cur, int use, int &cnt)
{
    if (cur > N)
        return;

    if (use == 0b111)
        cnt++;

    func(cur * 10 + 3, use | 0b001, cnt);
    func(cur * 10 + 5, use | 0b010, cnt);
    func(cur * 10 + 7, use | 0b100, cnt);
}

int main()
{
    cin >> N;
    int cnt = 0;

    func(0, 0, cnt);
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
  using namespace std;
    #define ll long long
    #define ull unsigned long long
    #define fr(i,a,b) for(int i =a ; i < b; i++)
    #define FR(i,a,b) for(int i =a ; i > b; i--) 
    #define frj(j,a,b) for(int j =a ; j < b; j++)
    #define FRE(i,a,b) for(int i =a ; i >= b; i--) 
    #define fre(i,a,b) for(int i =a ; i <= b; i++)
    #define fra(s) for(auto it = s.begin(); it != s.end() ; ++it)

    #define mkp make_pair 
    #define pb push_back
    #define pii pair<int,int>
    #define speed   ios::sync_with_stdio(false), cin.tie(0) , cout.tie(0)
    //#define c(a,b) cout<<a<<"--"<<b<<endl;
    #define frv(i,a,v) for(int i =  a ; i < v.size() ; ++i)
    #define cp(a,i)  cout<<a[i].first<<" "<<a[i].second<<endl;
    #define pp(a) cout<<a.first<<" "<<a.second<<endl;
    //sum array
    #define sa(n) int a[n]; int s[n];cin>>a[0];s[0]=a[0];fr(i,1,n) {cin>>a[i];s[i]=s[i-1]+a[i];}
    #define sa1(n) int a[n+1]; long long s[n+1]; a[0]=0; s[0]=0;cin>>a[1];s[1]=a[1];fr(i,2,n+1) {cin>>a[i];\
    s[i]=s[i-1]+a[i];}

    #define pr(a,n) fr(i,0,n){cout<<a[i]<<" ";}cout<<endl;
    #define prv(v)   for(auto it = v.begin() ; it!= v.end() ;++it){cout<<*it<<" ";}cout<<endl;
    #define prs(s)   for(auto x : s){cout<<x<<" ";}cout<<endl;
    
    #define all(x)           x.begin(), x.end()
    #define prm(m,r,c) fr(i,0,r){frj(j,0,c){cout<<m[i][j]<<" "; }cout<<endl;}
    #define fillm(m,r,c,k) fr(i,0,r)frj(j,0,c)m[i][j]=k;
    constexpr auto PI  = 3.14159265358979323846L;
    constexpr auto eps = 1e-6;
    constexpr auto mod = 1000000007;
    #define MOD 1000000007
   // #define maxv 200005
    #define MAXN 100001

  template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }
  template<class T> ostream& operator<<(ostream& out, set<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }


    const int INF = 1e9 +5;

int main(){
      
      speed;
      int n;
      cin>>n;
      
      int w;
      cin>>w;

      vector<pair<int,int> > h;
      int x,y;
      fr(i,0,n)
      { cin>>x>>y;
        h.pb(mkp(x,y));
      }

      ll dp[n][w+1];
      fillm(dp,n,w+1,0);

      fr(i,0,w+1)
      {
        if(i>=h[0].first)
          dp[0][i]=h[0].second;
      }
      fr(i,0,n)
      {
        dp[i][0]=0;
      }
      //prm(dp,n,w+1);
      fr(i,1,n)
      {
      //prm(dp,n,w+1);

          fr(j,1,w+1)
          { 
            if((j-h[i].first)>=0)
            dp[i][j] = dp[i-1][j-h[i].first]+h[i].second;

        //    cout<<dp[i][j]<<" "<<i-1<<j-h[i].first<<dp[i-1][j-h[i].first]<<endl;
            dp[i][j]=max(dp[i-1][j],dp[i][j]);
          }
      }
      //prm(dp,n,w+1);
      cout<<dp[n-1][w]<<endl;

      return 0;

  }



Measured memory_bytes: 78336
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    x,a,b=map(int,input().split())
    if abs(a-x)>abs(b-x):
        print('B')
    else:
        print('A')

if __name__ == '__main__':
    main()


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

int main(){
    ll N,A,B;
    cin >> N >> A >> B;
    vector<ll> X(N);
    rep(i,N){
        cin >> X[i];
    }
    ll ans = 0;
    for (ll i = 0; i < N - 1; i++){
        ll walk = A * (X[i + 1] - X[i]);
        ll teleport = B;
        ans += min(walk, teleport);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4056
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());

        var hash = new HashSet<string>();
        string prev = null;

        for (int i = 0; i < n; i++) {
            var s = input.ReadLine();
            if (hash.Contains(s)) return No;
            if (prev != null && prev.Last() != s.First()) return No;

            hash.Add(s);
            prev = s;
        }

        return Yes;
    }
}


Measured memory_bytes: 11232
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  string a,b,c;
  string d = "",e = "Close",f = "Open",g;
  cin >> a >> b >> c;
  d += a+b+c;
  if(d == "100"||d == "010" || d == "000")g = e;
  else g = f;
  cout << g << endl;
  return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define ROOP() while (true)

int seg_size = 524288 * 2 - 1;
int seg[1048575];

int solve(int now, bool down){
	if(!down){
        if(now == 0) return -1;

        int new_now = (now-1) / 2;
        if(now == new_now*2+2){
            if(seg[now-1] >= 1) return solve(now-1, true);
            else return solve(new_now, false);
        }
        else return solve(new_now, false);
    }
    else{
        if(now >= seg_size/2) return now;

        if(seg[now*2+2] >= 1) return solve(now*2+2, true);
        return solve(now*2+1, true);
    }
}

int main(){
    
    int N;
    cin >> N;
    vector<pair<int,int> > all;
    for(int i=0; i<N; i++){
        int M;
        cin >> M;
        for(int j=0; j<M; j++){
            int tmp;
            cin >> tmp;
            all.push_back(make_pair(tmp, i));
        }
    }
    sort(all.begin(), all.end());
    reverse(all.begin(), all.end());

    seg_size = 1;
	while(seg_size < N) seg_size *= 2;
	seg_size = seg_size * 2 - 1;
    for(int i=0; i<N; i++) seg[seg_size/2+i] = 1;
    for(int i=seg_size/2+N; i<seg_size; i++) seg[i] = 0;
	for(int i=seg_size/2-1; i>=0; i--) seg[i] = seg[i*2+1] + seg[i*2+2];

    long long ans = 0;
    for(int i=0; i<all.size(); i++){
        int place;
        if(seg[seg_size/2 + all[i].second] == 1) place = seg_size/2 + all[i].second;
        else place = solve(seg_size/2 + all[i].second, false); //それ以下で最大のタクシーを呼ぶ
        if(place == -1) continue;

        //cout << all[i].first << " " << all[i].second << " " << place - seg_size/2 << endl;

        ans += all[i].first;
        seg[place] = 0;
        while(place > 0){
            place = (place-1) / 2;
            seg[place]--;
        }

        if(seg[0] == 0) break;
    }

    cout << ans << endl;

    
    return 0;
}



Measured memory_bytes: 9272
import java.io.IOException;
import java.util.Scanner;

public class Main {
    private static StringBuilder sb = new StringBuilder();

    public static void main(String... args) throws IOException {
        final int[] targetAry = load();

        insertionSort(targetAry);

        System.out.print(sb.toString());
    }

    public static int[] load() throws IOException {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int[] nums = new int[n];
        for (int i = 0; i < nums.length; i++) {
            nums[i] = scanner.nextInt();
        }

        return nums;
    }

    public static void insertionSort(final int[] targetAry) {
        for (int i = 0; i < targetAry.length; i++) {
            for (int j = i; 0 < j; j--) {
                if (targetAry[j - 1] > targetAry[j]) {
                    swap(targetAry, j - 1, j);
                }
                if ((1 < j) && (targetAry[j - 1] > targetAry[j - 2])) {
                    break;
                }
            }

            print(targetAry);
        }
    }

    public static void swap(final int[] targetAry, final int from, final int to) {
        final int tmp = targetAry[to];
        targetAry[to] = targetAry[from];
        targetAry[from] = tmp;
    }

    public static void print(final int[] ary) {
        final StringBuilder sb = new StringBuilder();
        for (int j = 0; j < ary.length; j++) {
            sb.append(ary[j]).append(j != ary.length - 1 ? ' ' : '\n');
        }
        System.out.print(sb.toString());
    }
}

Measured memory_bytes: 21592
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;
using ll = long long;
const int N = 200005;
const int mod = 998244353;
struct Seg
{
    int l, r;
    bool operator<(const Seg& rhs)const
    {
        return l < rhs.l;
    }
}seg[11];

ll c[N];
int n, k;

int lowbit(int x)
{
    return x & (-x);
}

void add(int x, ll d)
{
    for (int i = x; i <= n; i += lowbit(i))
        c[i] = (c[i] + d) % mod;
}

ll query(int x)
{
    ll res = 0;
    for (int i = x; i; i -= lowbit(i))
        res = (res + c[i]) % mod;
    return res;
}

ll Mod(ll a)
{
    return (a % mod + mod) % mod;
}

ll Query(int q)
{
    ll res = 0;
    for (int i = 1; i <= k; ++i)
    {
        int st = max(1, q - seg[i].r);
        int ed = q - seg[i].l;
        if (ed < 1) continue;
        res = Mod(res + query(ed) - query(st - 1));
    }
    return res;
}

int main()
{
    
    scanf("%d%d", &n, &k);
    
    for (int i = 1; i <= k; ++i)
    {
        scanf("%d%d", &seg[i].l, &seg[i].r);
    }

    sort(seg + 1, seg + k + 1);

    add(1, 1);

    for (int i = 2; i <= n; ++i)
    {
        ll now = Query(i);
        add(i, now);
    }

    printf("%lld\n", Mod(query(n) - query(n - 1)));


    return 0;
}

Measured memory_bytes: 5284
Imports System
Module ABC152B
	Sub Main()
		Dim inputs() As String
		inputs = Console.ReadLine().Split()
		Dim aa,bb As String
		aa = new String(inputs(0),Integer.Parse(inputs(1)))
		bb = new String(inputs(1),Integer.Parse(inputs(0)))
		If aa <= bb
			Console.WriteLine(aa)
		Else
			Console.WriteLine(bb)
		End If
	End Sub
End Module


Measured memory_bytes: 19792
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using std::cout;
using std::cin;
using std::endl;
using std::pow;
using std::vector;
using std::string;

int main(){
    int D,out=0,max,m_c;
    cin >> D;
    int c[26],s[D][26],t[D],l[26]={};
    for(int i=0;i<26;i++) cin >> c[i];
    for(int i=0;i<D;i++){
        for(int j=0;j<26;j++) cin >> s[i][j];
    }
    for(int i=0;i<D;i++){
        max = -10000000;
        m_c = 0;
        for(int j=0;j<26;j++){
            if(max < s[i][j]){
                max = s[i][j];
                m_c = j;
            }
        }
        cout << m_c + 1 << endl;
    }

    /* for(int i=0;i<D;i++) cin >> t[i];
    for(int i=0;i<D;i++){
        l[t[i]-1] = i+1;
        out += s[i][t[i]-1];
        for(int j=0;j<26;j++){
            out -= c[j] * (i + 1 - l[j]);
        }
        cout << out << endl;
    }
    */
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) (1 + (int)((a) - 1)/(int)(b))
//#define int long long

signed main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(rALL(a));
    
    int ans_i = a[0], ans_j = a[1];
    
    reps(i,2,n-1){
        if(abs(2 * ans_j - ans_i) > abs(2 * a[i] - ans_i)){
            ans_j = a[i];
        }
    }
    
    cout << ans_i << " " << ans_j << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n) - 1; (i) >= 0; --i)
#define SZ(n) (int)(n).size()
#define ALL(n) (n).begin(), (n).end()
#define MOD LL(1e9 + 7)
#define INF 1000000
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PI;

int main() {
	LL x, y;
	cin >> x >> y;
	LL ans = -1;
	for (LL i = 2; i < 64; ++i) {
		if (x * i % y != 0) {
			ans = x * i;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// #include "ext/pb_ds/assoc_container.hpp"
// #include "ext/pb_ds/tree_policy.hpp"
// #define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
//using namespace __gnu_pbds;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;
#define deb1a(v) cout << #v << "--->" << endl; for (auto it : v)  cout << it << " "; cout << endl;
#define deb2a(v) cout << #v << "--->" << endl;for (auto it:v){for(auto it1 : it){cout << it1 << " ";}cout<< endl;}
#define deb3a(v) cout << #v << "-->" << endl; for(auto it:v){cout << it.fi << " " << it.se << endl;}
#define mod 1000000007
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
int power(int x, unsigned int y, int p){ int res = 1;x = x % p;while (y > 0)  { if (y & 1)res = (res*x) % p;y = y>>1;  x = (x*x)% p;} return res;}
int mI(int a, int m)  {return power(a, m - 2, m);}
//int ans;
int n, m, q;
vector<vector<int>> v;
//vector<int> val;
int ans = 0;
void fun(vector<int> val){
    
    if(val.size()==n){
        int an = 0;
        for(int i=0;i<q;i++){
            if(val[v[i][1]-1]-val[v[i][0]-1]==v[i][2])
                an += v[i][3];
        }
        ans = max(ans, an);
        return;
    }
    int si = val.size();
    //deb(si);
    int start = 1;
    if(si!=0)
        start = val[si - 1];
    vec temp = val;
    foo(i,start,m+1){
        temp.pb(i);
        fun(temp);
        temp.pop_back();
    }
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m >> q;
    v.resize(q,vector<int> (4,0));
    for(int i=0;i<q;i++){
        for(int k=0;k<4;k++){
            cin >> v[i][k];
        }
    }
    vec temp;
    fun(temp);
    cout << ans;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;


int main(){
    int a,b; cin >> a >> b;
    int h = 100, w = 100;
    // int h = 10, w = 10;
    // vector<string> s(h);
    string s[h];
    rep(i,h)rep(j,w){
        if(i*2 < h)s[i] += '#';
        else s[i] += '.';
    }
    int cnt = 0;
    int x = 0, y = 0;
    int dx[8] = {0,0,1,-1,1,-1,1,-1};
    int dy[8] = {-1,1,0,0,1,-1,-1,1};
    while(cnt < a-1){
        bool ok = true;
        rep(i,8){
            int nx = x + dx[i], ny = y + dy[i];
            if(nx >= 0 && h > nx && ny >= 0 && w > ny){
                if(s[nx][ny] == '.')ok = false;
            }
        }
        if(ok){
            s[x][y] = '.';
            ++cnt;
        }
        if(y < w-1)++y;
        else{y = 0;++x;}
    }

    x = h-1;
    y = w-1;
    cnt = 0;
    while(cnt < b-1){
        bool ok = true;
        rep(i,8){
            int nx = x + dx[i], ny = y + dy[i];
            if(nx >= 0 && h > nx && ny >= 0 && w > ny){
                if(s[nx][ny] == '#')ok = false;
            }
        }
        if(ok){
            s[x][y] = '#';
            ++cnt;
        }
        if(0 < y)--y;
        else{y = w-1;--x;}
    }
    cout << h << " " << w << endl;
    rep(i,h){
        rep(j,w)cout << s[i][j];
        cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(b<a) { a=b; return 1; } return 0; }

int main(){
  string sa,sb,sc; cin >> sa >> sb >> sc;
  int a = 0, b = 0, c = 0;
  char now = 'a';
  char winner;
  while(true){
    if(now == 'a'){
      if(a == sa.size()){
        winner = 'A';
        break;
      }
      now = sa[a];
      a++;
    }else if(now == 'b'){
      if(b == sb.size()){
        winner = 'B';
        break;
      }
      now = sb[b];
      b++;
    }else if(now == 'c'){
      if(c == sc.size()){
        winner = 'C';
        break;
      }
      now = sc[c];
      c++;
    }
  }
  cout << winner;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3596
/*
 * main.c
 *
 *  Created on: 2020/03/28
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}


int A[101] = {0};
int main()
{
	int N = 0, M = 0;
	int i = 0, sum = 0, ans = 0, limit = 0, count = 0;
	scanf("%d %d", &N, &M);
	for (i = 0; i < N; i++ ) {
		scanf("%d", &A[i]);
		sum += A[i];
	}
    limit = sum/(4 * M);
    if (sum%(4*M) != 0) {
    	limit++;
    }
    qsort(A, N, sizeof(int), sort_dec);
    //printf("sum %d limit %d\n", sum, limit);
    for (i = 0; i < M; i++) {
    	if (limit > A[i]) {
    	} else {
    		count++;
    	}
    }
    if (count == M) {
    	ans = 1;
    }
	if (ans == 0) {
		printf("No\n");
	} else {
		printf("Yes\n");
	}


    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        boolean debug = false;
        if (debug != false) {
            return;
        }
        System.out.println(str);
    }

    public static void main(String[] args) {

        int  N;
        int[] pList;
        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            pList = new int[N];
            for(int i =0 ; i < N;i++){
                pList[i] = sc.nextInt();
            }
        }

        int result = 0;
        for(int i = 0 ; i < N -2;i ++){
            if(pList[i] < pList[i+1] && pList[i+2] > pList[i+1]){
                result++;
            }else if(pList[i] > pList[i+1] && pList[i+2] < pList[i+1]){
                result++;
            }
        }
        System.out.println(result);

    }

}


Measured memory_bytes: 22356
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iomanip>


#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;


// <<fixed<<setprecision(6)<<


int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}


int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}


int main(){
  int htotal=0;
  int ktotal=0;
  int h1,h2,k1,k2,a,b,c,d;
  cin>>h1>>h2>>k1>>k2>>a>>b>>c>>d;
  htotal=h1*a+h2*b;
  ktotal=k1*a+k2*b;
  if(h1>=10||h2>=20){
    htotal+=h1/10*c+h2/20*d;
  }
  if(k1>=10||k2>=20){
    ktotal+=k1/10*c+k2/20*d;
  }
  if(htotal>ktotal){
    cout<<"hiroshi"<<endl;
  }
  else if(htotal<ktotal){
    cout<<"kenjiro"<<endl;
  }
  else{
    cout<<"even"<<endl;
  }


}


Measured memory_bytes: 3104
#include<stdio.h>

int main(void){
    int a=0;
    int n=0;
    int temp=0;
    scanf("%d",&n);
    scanf("%d",&a);
    temp=n/500;
    n=n-500*temp;
    if(n<=a){
        printf("Yes\n");
    }
    else printf("No\n");
return 0;
}

Measured memory_bytes: 128