akhauriyash/Code-Regression huggingface dataset:
from collections import deque
while 1:
    N = int(input())
    if N == 0:
        break

    T = [0]*N; C = [0]*N
    que0 = deque()
    que1 = deque()
    P = [list(map(int, input().split())) for i in range(N)]
    P.sort()
    for i in range(N):
        t, c = P[i]
        que0.append((i, t))
        T[i] = t
        C[i] = c

    INF = 10**18
    ans = 0
    rest = N
    while rest:
        t = min(que0[0][1] if que0 else INF, que1[0][1] if que1 else INF)
        st0 = []; st1 = []
        while que0 and que0[0][1] <= t:
            st0.append(que0.popleft()[0])
        st0.sort()
        for i in st0:
            que1.append((i, t+T[i]))
        while que1 and que1[0][1] <= t:
            st1.append(que1.popleft()[0])
        st1.sort()
        for i in st1:
            if C[i] == 1:
                rest -= 1
            else:
                que0.append((i, t+T[i]))
            C[i] -= 1
        ans = max(ans, t)
    print(ans)



Measured memory_bytes: 6012
# 標準入力
## Nの入力受付
N = int(input())
## Aの入力受付
A = input().split()
for i in range(N):
    A[i] = int(A[i])


count=0
flag = True
# 2で割り切れる間回す
while flag:
    for i in range(N):
        d = A[i] % 2
        if d != 0:
            flag = False
        else:
            A[i] = A[i]/2
    if flag:
        count+=1
print(count)

Measured memory_bytes: 3064
n, k = list(map(int, input().split()))
a = input()
ans = []
left = a.index('1')
right = n -left -1
for i in range(k):
    l = left-i
    r = right-k+1+i
    if l==0:
        ans.append(right//k+1)
    else:
        ans.append((l-1)//(k-1)+1+1+(r-1)//(k-1)+1)
print(min(ans))

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

void solve(){
  LL h, n; cin >> h >> n;
  LL a[n]; for (int i = 0; i < n; i++) cin >> a[i];

  LL sum = 0;
  for (int i = 0; i < n; i++) sum += a[i];
  cout << (h <= sum ? "Yes" : "No") << endl;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 1024
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus >= 201703L
#        pragma GCC target("avx2")
#    else
#        pragma GCC target("avx")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    string s;
    cin >> s;
    if (s[0] == '7' || s[1] == '7' || s[2] == '7') {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define cin1(x) scanf("%d",&x)
#define cin2(x,y) scanf("%d%d",&x,&y)
#define cin3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define rr read()
#define ll long long
#define CloseIo ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
const int N = 1e3 + 5;
int main(){
	CloseIo;
	int n;
	cin>>n;
	int ans=0;
	repb(i,1,n){
		int x;
		cin>>x;
		if(x!=i)
			ans++;
	}
	if(ans>2)
		cout<<"NO\n";
	else
		cout<<"YES\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <algorithm>

#define lson l, m, o << 1
#define rson m + 1, r, o << 1 | 1

const int N = 1e5 + 1;

int mn[N << 2];

void up(int o) {
  mn[o] = std::min(mn[o << 1], mn[o << 1 | 1]);
}

void build(int l, int r, int o) {
  if (l == r) {
    mn[o] = INT_MAX;
    return;
  }
  int m = (l + r) >> 1;
  build(lson);
  build(rson);
  up(o);
}

void modify(int v, int L, int R, int l, int r, int o) {
  if (L <= l && R >= r) {
    mn[o] = v;
    return;
  }
  int m = (l + r) >> 1;
  if (L <= m) modify(v, L, R, lson);
  if (R > m) modify(v, L, R, rson);
  up(o);
}

int query(int L, int R, int l, int r, int o) {
  if (L <= l && R >= r) {
    return mn[o];
  }
  int m = (l + r) >> 1;
  int res = INT_MAX;
  if (L <= m) res = std::min(res, query(L, R, lson));
  if (R > m) res = std::min(res, query(L, R, rson));
  return res;
}

int main() {
  int n, q;
  while (std::cin >> n >> q) {
    build(1, n, 1);
    while (q --) {
      int op;
      std::cin >> op;
      if (op == 0) {
        int l, v;
        std::cin >> l >> v;
        l ++;
        modify(v, l, l, 1, n, 1);
      } else {
        int l, r;
        std::cin >> l >> r;
        l ++;
        r ++;
        std::cout << query(l, r, 1, n, 1) << std::endl;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 4116
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;


signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> A(n,0);
    for(ll i=0;i<n;++i)cin>>A[i];

    vl a=A;

    ll &N=n;

    //正からはじまる
    ll sum=0;
    ll ans1=0;
    for(ll i=0;i<N;++i){
        if(i%2==0){
            if(sum+a[i]>0)sum+=a[i];
            else {
                ans1+=llabs(1-sum-a[i]);
                a[i]=1-sum;
                sum+=a[i];
            }
        }
        else {
            if(sum+a[i]<0)sum+=a[i];
            else {
                ans1+=llabs(-1-sum-a[i]);
                a[i]=-1-sum;
                sum+=a[i];
            }
        }
    }

    a=A;

    sum=0;
    ll ans2=0;
    for(ll i=0;i<N;++i){
        if(i%2==1){
            if(sum+a[i]>0)sum+=a[i];
            else {
                ans2+=llabs(1-sum-a[i]);
                a[i]=1-sum;
                sum+=a[i];
            }
        }
        else {
            if(sum+a[i]<0)sum+=a[i];
            else {
                ans2+=llabs(-1-sum-a[i]);
                a[i]=-1-sum;
                sum+=a[i];
            }
        }
    }

    prt(min(ans1,ans2))

    return 0;
}


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

int main(){
  
  int N , A;
  
  cin >> N >> A;
  
  if ( N % 500 <= A ){
    cout << " Yes " << endl;
  }
  if ( N % 500 > A ){
    cout << " No " << endl;
  }
}

Measured memory_bytes: 3552
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        int n=cin.nextInt();
        int[] a=cin.ArrayInt(n,0);
        Dictionary<int, int> x = new Dictionary<int, int>();

        for(int i=0;i<n;i++)
        {
            x.Add(a[i],i+1);
        }
        for(int i=0;i<n-1;i++)
        {
            Console.Write(x[i+1]+" ");
        }
        Console.WriteLine(x[n]);
        
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}

Measured memory_bytes: 29912
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
struct QuickFind{
  int n;
  vector<int> rs,ps;
  vector<vector<int> > vs;
  QuickFind(){}
  QuickFind(int sz):n(sz),rs(sz,1),ps(sz),vs(sz){
    iota(ps.begin(),ps.end(),0);
    for(int i=0;i<n;i++) vs[i].assign(1,i);
  }
  int find(int x) const{return ps[x];}
  bool same(int x,int y) const{
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=ps[x];y=ps[y];
    if(x==y) return;
    if(rs[x]<rs[y]) swap(x,y);
    rs[x]+=rs[y];
    for(int e:vs[y]){
      ps[e]=x;
      vs[x].push_back(e);
    }
    vs[y].clear();
    vs[y].shrink_to_fit();
  }
  const vector<int>& elements(int x) const{return vs[x];}
};
//END CUT HERE

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n,q;
  cin>>n>>q;
  QuickFind qf(n);
  for(int i=0;i<q;i++){
    int c,x,y;
    cin>>c>>x>>y;
    if(c==0) qf.unite(x,y);
    if(c==1) cout<<qf.same(x,y)<<"\n";
  }
  cout<<flush;
  return 0;
}
/*
  verified on 2019/08/11
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_1_A&lang=jp
*/



Measured memory_bytes: 3688
yasumi = 0
syukudai = 1
nissu = list(map(int,input().split()))
syukudaiNissu = list(map(int,input().split()))
if sum(syukudaiNissu) > nissu[yasumi]:
  print(-1)
  exit()
print(nissu[yasumi] - sum(syukudaiNissu))

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

public class Main {

    static class Pair {
        boolean left;
        int right;
        Pair(boolean l, int r) {
            left = l;
            right = r;
        }
    }

    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        int n = std.nextInt();
        int[] a = new int[n];

        for (int i = 0; i < n; i++) {
            int x = std.nextInt() - 1;
            a[x]++;
        }

        Arrays.sort(a);
        int[] sorted = a;
        int[] s = new int[n + 1];
        for (int i = 0; i < n; i++) {
            s[i + 1] = s[i] + sorted[i];
        }

        // 1 ~ n takes
        int ans = n;
        int i = n;
        for (int k = 1; k <= n; k++) {
            while (true) {
                Pair p = calc(i, k, a, ans, n, s);
                i = p.right;
                if (p.left) {
                    break;
                } else {
                    ans--;
                }
            }

            System.out.println(ans);
        }

    }

    static Pair calc(int i, int k, int[] a, int c, int n, int[] s) {
        while (i > 0 && a[i - 1] >= c) {
            --i;
        }
        int sum = c * (n - i) + s[i];
        return new Pair (sum >= c * k, i);
    }
}


Measured memory_bytes: 98344
#define _USE_MATH_DEFINES //M_PI, M_E
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
ll power(ll a,ll b){ll r=1;for(;b;b>>=1){if(b&1)r=r*a%mod;a=a*a%mod;}return r;}
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	map<int,int> m;
	for(int i = 0,j; i<n; i++)
	{
		cin>>j;
		m[j]++;
	}
	int ans = 0;
	for(auto i:m)
	{
		if(m[i.first]>i.first)
			ans += m[i.first]-i.first;
		else if(m[i.first]<i.first)
			ans += m[i.first];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4736
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int ans = 0;
    int cnt = 0;

    for (int i = 0; i < n; i++) {
      int l1 = sc.nextInt();
      int l2 = sc.nextInt();
      if (l1 == l2) {
        cnt++;
      } else {
        cnt = 0;
      }
      if (cnt == 3) {
        ans++;
        cnt = 0;
      }
    }

    if (ans > 0) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }

  }
}

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

int main() {
    int n;
    cin>>n;
    double ans;
    vector<double> v(n);
    rep(i,n) cin>>v.at(i);
    sort(v.begin(),v.end());
    for (int i=1; i<n; i++) {
        ans=(v[0]+v[1])/2.0;
        v.erase(v.begin(),v.begin()+2);
        v.push_back(ans);
        sort(v.begin(),v.end());
    }
    printf("%.10f\n",ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int i[500][500];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=1,f=0;
  string s[3];
  cin >>s[0]>>s[1]>>s[2];
  cout <<s[0][0]<<s[1][0]<<s[2][0]<<'\n';
  return (0);
}


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

int main(){
    int N;
    cin >> N;
    vector<vector<int>> A(N,vector<int>(N,0));
    vector<vector<int>> v(N*N);
    vector<int> cnt(N*N,0);
    auto id = [&](int x,int y){
        return x*N+y;
    };
    for(int i=0;i<N;i++){
        for(int j=0;j<N-1;j++){
            cin >> A[i][j];
            A[i][j]--;
            if(j==0) continue;
            int a = (i<A[i][j-1]? id(i,A[i][j-1]):id(A[i][j-1],i)),b = (i<A[i][j]? id(i,A[i][j]):id(A[i][j],i));
            v[a].push_back(b);
            cnt[b]++;
//            cerr << A[i][j] << " " << a << " " << b << endl;
        }
    }
    vector<int> vis(N*N,0);
    function<bool(int)> dfs = [&](int n){
        bool ok = true;
        vis[n] = -1;
        for(auto x:v[n]){
            if(vis[x]==0) ok &= dfs(x);
            else if(vis[x]==-1) return false;
        }
        vis[n] = 1;
        return ok;
    };
    for(int i=0;i<N*N;i++){
        if(!vis[i] && !dfs(i)){
            cout << -1 << endl;
            return 0;
        }
    }
    for(int i=0;i<N*N;i++) vis[i] = 0;
    vector<int> u;
    function<void(int)> dfs2 = [&](int n){
        vis[n] = 1;
        for(auto x:v[n]) if(vis[x]==0) dfs2(x);
        u.push_back(n);
    };
    for(int i=0;i<N*N;i++) if(cnt[i]==0 && vis[i]==0) dfs2(i);
    reverse(u.begin(),u.end());
    vector<int> dp(N*N,0);
    for(int i=0;i<u.size();i++){
        for(auto x:v[u[i]]){
            dp[x] = max(dp[x],dp[u[i]]+1);
        }
    }
    int ans = 0;
    for(int i=0;i<N*N;i++) ans = max(ans,dp[i]);
    cout << ans+1 << endl;
}

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

const int N = 1e5 + 5;

int n, a[N], l;

int main() {
	cin >> n >> l;
	for (int i = 1; i <= n; ++ i) cin >> a[i];
	for (int i = 1; i < n; ++ i) {
		if (a[i] + a[i + 1] >= l) {
			puts("Possible");
			for (int j = 1; j <= i - 1; ++ j) printf("%d\n", j);
			for (int j = n - 1; j >= i + 1; -- j) printf("%d\n", j);
			printf("%d\n", i);
			return 0;			
		}
	}
	puts("Impossible");
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

vector<ll> a(5);

int main()
{
    ll n;
    cin>>n;
    REP(i,5) {
        cin>>a[i];
    }
    ll mina = *MIN_ELEMENT(a);
    cout<<(n + mina - 1) / mina + 4<<endl;

    return 0;
}


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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

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

    ll a = k / 50 + 49;
    int b = k % 50;

    cout << 50 << endl;
    for (int i = 0; i < b; i++) {
        cout << a + 50 - (b - 1) << " ";
    }
    for (int i = b; i < 50; i++) {
        cout << a - b;
        if (i == 49) {
            cout << endl;
        } else {
            cout << " ";
        }
    }

}


Measured memory_bytes: 256
let n = Scanf.scanf " %d" (+) 0
let a_s = Array.init n @@ fun i -> Scanf.scanf " %d" @@ fun a -> a, i
let _ = Array.sort (fun x y -> compare y x) a_s;
  Array.iteri (fun i _ -> Printf.printf "%d\n" @@ fst @@ if snd a_s.(0) = i then a_s.(1) else a_s.(0)) a_s

Measured memory_bytes: 11652
#include <iostream>
#include <algorithm>
using namespace std;
bool f(string a, string b){
 string ab = a.append(b);
   string ba =  b.append(a);
  return ab.compare(ba)>0?0:1;
}

int main(){
 int n,l;
 cin>>n>>l;
  string arr[n];
  for (int i=0;i<n;i++){
  cin>>arr[i];
  }
  sort(arr,arr+n);
  for (int i=0;i<n;i++){
    cout<<arr[i];
  }
  
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
int N, A[3][3], b[10];
bool appear[3][3]; 
int main() {
		for(int i = 0; i < 3; i++) {
		for(int j = 0; j < 3; j++) cin >> A[i][j];
	}
	cin >> N; 
	for(int i=0;i<N;i++) 
	cin>>b[i]; 
		for(int i=0;i<N;i++) {
			for(int j=0;j<N;j++) {
				appear[i][j] = false;
					for(int k = 0; k < N; k++) {
						if(A[i][j] == b[k]) 
							appear[i][j] = true;
					}
			}
		} 
	string ANS="No";
	for(int i=0;i<3;i++) 
	{ 
		if(appear[i][0]and appear[i][1]and appear[i][2]) ANS = "Yes"; 
	}
	for(int i=0; i<3;i++){ 
		if(appear[0][i]and appear[1][i]and appear[2][i]) ANS = "Yes"; 
	}
		if(appear[0][0]and appear[1][1]and appear[2][2]) ANS = "Yes"; 
			if(appear[0][2]and appear[1][1]and appear[2][0]) ANS = "Yes"; 
	cout<<ANS<<endl; 
	return 0; 
}


Measured memory_bytes: 256
/*Coded by::
    **Avinash Tiwary**
    **BE/10298/2015**
    **Production Engineer**
    **Producing <code>**
*/
#include<bits/stdc++.h>
#define buf ios_base::sync_with_stdio (0), cin.tie (0)
typedef long long ll;
typedef double dob;
#define MAX 1300009
#define M 1000000007
#define INF 5e17
using namespace std;
typedef vector<ll> V;
typedef queue<ll > Q;
typedef stack<ll> S;
typedef pair<ll,ll> P;
#define mp make_pair
#define mt make_tuple
#define pb push_back
bool desc(ll i, ll j) { return i > j; }
ll power(ll x,ll n)
{   if(n==0||x==0) return 1;
    else if(n%2 == 0) return power((x*x)%M,n/2);
    else return (x*power((x*x)%M,(n-1)/2))%M;
}
ll fac[MAX],not_prime[MAX],ar[MAX],dp[MAX];
string s[MAX];
void fact(){
    fac[0]=1;
    for(ll i=1;i<=1000009;i++) fac[i]=(i*fac[i-1])%M;
}
void sieve(){
    not_prime[1]=1; not_prime[0]=1;
    for(ll p=2;p*p<=MAX;p++){
        if(!not_prime[p]){
            for(ll i=p*2;i<=MAX;i+=p) not_prime[i]=1;
        }
    }
}
int main(){
    //buf; 
    //sieve(); 
    //fact();
    ll i,j,test,ans,a,b,c,d,n,z,m,p,k,flag; string sk; 
    test=1;
    while(test--){
        cin>>a>>b>>c>>d;
        ans=0;
        for(i=0;i<=100;i++){
            if(i>a&&i<=b&&i>c&&i<=d) ans++;
        }
        cout<<ans;
    }
    return 0;
} 

Measured memory_bytes: 10496
n = int(input())

s = [input() for _ in range(n)]

def f(a, b):
    if len(a) > len(b):
        a, b = b, a
    c = ""
    for i in range(len(a)):
        if a[i] in b:
            idx = b.index(a[i])
            b = b[:idx] + b[idx + 1:]
            c += a[i]
    return c

a = s[0]

for i in range(n):
    b = s[i]
    c = f(a, b)
    a = c

ans = ""
for ch in sorted(list(a)):
    ans += ch

print(ans)


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

int main() {
  int r,g,b,n; cin >> r >> g >> b >> n;
  int count = 0;
  for(int i=0; i<=n; i++) {
    for(int j=0; j<=n; j++) {
      if((n-r*i-g*j)>=0&&(n-r*i-g*j)%b==0) count++;
    }   
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3608
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007ll //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second 
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)    
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=2005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    vi v1,v2,v3;
    for(int i=0;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        v1.pb(x+y);
        v2.pb(x-y);
        v3.pb(y-x);
    }
    sort(all(v1));
    sort(all(v2));
    sort(all(v3));
    cout<<max({v1[n-1]-v1[0], v2[n-1]-v2[0], v3[n-1]-v3[0]});
}

Measured memory_bytes: 8156
/**
	*    author:  accesss_denied
	**/
	#include <bits/stdc++.h>
	using namespace std;
	#define ll long long int
	#define ff first
	#define ss second
	#define pb push_back
	#define endl "\n"
	#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	ll mod=1e9+7;			
	ll inf=1e18;

	int main() {
				fast
				
				ll n,m;
				cin>>n>>m;
				ll sx,sy,dx,dy;
				cin>>sx>>sy>>dx>>dy;

				char arr[n+2][m+2];
				for(ll i=1;i<=n;i++)
				for(ll j=1;j<=m;j++)
				cin>>arr[i][j];

				deque<ll>q;
				q.push_back(sx);
				q.push_back(sy);
				ll dp[n+2][m+2];
				for(ll i=1;i<=n;i++)
				for(ll j=1;j<=m;j++)
				dp[i][j]=inf;

				dp[sx][sy]=0;
				while(!q.empty())
				{
					ll cx=q.front();
					q.pop_front();
					ll cy=q.front();
					q.pop_front();

					// cout<<cx<<" "<<cy<<endl;

					for(ll x=max(1ll,cx-2);x<=min(n,cx+2);x++)
					{
						for(ll y=max(1ll,cy-2);y<=min(m,cy+2);y++)
						{
							if(arr[x][y]=='#')
							continue;

							ll dist= abs(x-cx)+abs(y-cy);
							if(dist<=1)
							dist=0;
							else
							dist=1;
							if(dp[cx][cy]+dist<dp[x][y])
							{
								dp[x][y]=dp[cx][cy]+dist;
								if(dist==0)
								{
									q.push_front(y);
									q.push_front(x);
								}
								else
								{
									q.push_back(x);
									q.push_back(y);
								}
							}
						}
					}
				}
				

				if(dp[dx][dy]==inf)
				cout<<-1;
				else
				cout<<dp[dx][dy];

				
				return 0;
			}	




Measured memory_bytes: 12660
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

int main()
{
	int x[6];
	cin >> x[1] >> x[2] >> x[3] >> x[4] >> x[5];
	for(int i = 1; i <= 5; i++){
		if(x[i] == 0){
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}


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

int main() {
	int N;
	cin >> N;
	int ACans = 0, WAans = 0, TLEans = 0,REans = 0;
    vector<string> data(N);
    for (int i = 0; i < N; i++){
        cin >> data.at(i);
    }

    for (int i = 0; i < N; i++){
        if(data.at(i)=="AC"){
            ACans++;
        }else if(data.at(i)=="WA"){
            WAans++;
        }else if(data.at(i)=="TLE"){
            TLEans++;
        }else if(data.at(i)=="RE"){
            REans++;
        }
    }
    cout << "AC x " << ACans << endl;
    cout << "WA x " << WAans << endl;
    cout << "TLE x " << TLEans << endl;
    cout << "RE x " << REans << endl;
}

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

int table[102][10002];

int main()
{
	int v[105];
	int w[105];
	int n;
	int m;

	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> v[i] >> w[i];
	}

	for (int i = 0; i < n + 1; i++)
	{
		for (int j = 0; j < m + 1; j++)
		{
			table[i][j] = -1;
		}
	}

	table[0][0] = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m + 1; j++)
		{
			if (table[i][j] == -1) continue;
			if (j + w[i] < m + 1) table[i + 1][j + w[i]] = table[i][j] + v[i];
			table[i + 1][j] = max(table[i + 1][j], table[i][j]);
		}
	}

	int ans = 0;
	for (int j = 0; j < m + 1; j++)
	{
		ans = max(ans, table[n][j]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 5104
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef unsigned int uii;
const int maxn=100005;
int n,k,a[maxn],r,d[maxn];
vector<int> vec[maxn];
void dfs(int u) {
    for (uii i=0;i<vec[u].size();++i) {
        dfs(vec[u][i]);
        d[u]=max(d[u],d[vec[u][i]]+1);
    }
    if (a[u]!=1&&d[u]==k-1) {
        d[u]=-1;
        ++r;
    }
}
int main()
{
    scanf("%d%d%d",&n,&k,&a[1]);
    if (a[1]!=1) {
        ++r;
        a[1]=1;
    }
    for (int i=2;i<=n;++i) {
        scanf("%d",&a[i]);
        vec[a[i]].push_back(i);
    }
    dfs(1);
    printf("%d\n",r);
    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>  // ver1.9.4
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define mp make_pair
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define Vout(a) rep(i,0,a.size()-1)cout<<a[i]<<' ';cout<<a[a.size()-1]<<endl;
#define INF 9000000000000000000  //  9.0 * 10^18
#define MOD 1000000007  //  10^9 + 7
using namespace std;

signed main() {
  cout << fixed << setprecision(8);
  int now=1,k,a,b;
  cin >>k>>a>>b;
  if(b-a <= 2 || k-(a-1) < 2) {cout<<k+1<<endl;return 0;}
  now += a-1;
  k -= a-1;
  if(k%2==1) {k--;now++;}
  now += (k/2)*(b-a);
  cout << now << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

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

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

int main() {
    INIT;
    ll X, K, D;
    cin >> X >> K >> D;

    ll a = abs(X) / D;
    if (a >= K) {
        if (X < 0) {
            cout << abs(X + K * D) << endl;
        } else {
            cout << abs(X - K * D) << endl;
        }
        return 0;
    }

    ll last_K = K - a;
    ll now_X, next_X;
    if (X < 0) {
        now_X = X + a * D;
        next_X = now_X + D;
    } else {
        now_X = X - a * D;
        next_X = now_X - D;
    }

    if (abs(now_X) > abs(next_X)) {
        last_K--;
        if (last_K % 2 == 0) {
            cout << abs(next_X) << endl;
        } else {
            cout << abs(now_X) << endl;
        }
    } else {
        if (last_K % 2 == 0) {
            cout << abs(now_X) << endl;
        } else {
            cout << abs(next_X) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3644
#include<stdio.h>
#define MAX 100000

int A[MAX + 1];
int H; // 要素数

int parent(int i)
{
	return i / 2;
}

int left(int i)
{
	return i * 2;
}

int right(int i)
{
	return i * 2 + 1;
}

/*
node 2: key = 8, parent key = 7, left key = 2, right key = 3,
#行の最後は空白
#親、左の子、右の子はなければ出力しない
*/
int main()
{
	scanf("%d", &H);
	for (int i = 1; i <= H; i++)
	{
		scanf("%d", &A[i]);
	}

	for (int i = 1; i <= H; i++)
	{
		printf("node %d: ", i);
		printf("key = %d, ", A[i]);
		int p = parent(i);
		int l = left(i);
		int r = right(i);
		if (p > 0)
		{
			printf("parent key = %d, ", A[p]);
		}
		if (l <= H)
		{
			printf("left key = %d, ", A[l]);
		}
		if (r <= H)
		{
			printf("right key = %d, ", A[r]);
		}
		printf("\n");
	}
}

/*
二分ヒープ(Binary Heap)とは、完全二分木の各節点に割り当てられたキーが
配列の各要素に対応して表されたデータ構造。

二分ヒープには以下の種類がある。
maxヒープ : 節点のキーがその親のキー以下
minヒープ : 節点のキーがその親のキー以上
*/


Measured memory_bytes: 2688
#include<stdio.h>
int main (void){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if (a<b && b<c)
    {
        printf("Yes\n");
    }else {
        printf("No\n");

    }
        return 0;
    
    
    
}


Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
static const int INF = 2000000000;


int main(){
  int n;
  cin >> n;
  int m = n%10;
  string ans = "hon";
  if (m == 3) ans = "bon";
  else if (m == 0 || m == 1 || m == 6 || m == 8) ans = "pon";
  cout << ans << endl;
} 

Measured memory_bytes: 3616
sum = 0
stack = [] # \??????????????£???index???stack
res = [] # /???????????????\???index??¨?????????????¨????????????¢??????tuple???stack. ?????????????????¢?????¢?????¨????????¨?????????
gets.split("").each_with_index { |v, i|
  if v == "\\"
    stack << i
  elsif v == "/"
    j = stack.pop
    if !j.nil? # \????????????/?????\?????¨????????????
      a = i - j # index??????????????§?¨???????????¨??????????
      sum += a

      loop do
        k, b = res.pop
        if !k.nil?
          if j < k
            a += b
          else
            res << [k, b] # ??????pop??????????????§???????????????????????°??????push????????????
            break
          end
        else
          break
        end
      end
      res << [j, a]
    end
  end
}
puts sum
if res.size() == 0
  puts "0"
else
  puts "#{res.size()} #{res.map{|n| n[1]}.join(" ")}" # size == 0?????????map??????????????????????????
end

Measured memory_bytes: 10004
#include <stdio.h>
#define MAX 100

char S[MAX];
char T[MAX];
char ans[MAX*2];

int main(void){
	scanf("%s", S);
	scanf("%s", T);	

	int i = 0, j = 0;
	int length = 0;

	while(T[i] != '\0' ){
		ans[i] = T[i];
		length++;
		i++;
	}

	while(S[j] != '\0'){
		ans[length+j] = S[j];
		j++;
	}

	printf("%s\n", ans);


	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
#define ll int1024_t

// a C b
ll Combination(ll a,ll b) {
  ll ans = 1;
  for (ll i = a; i >= a - b + 1; i--) {
    ans *= i;
  }
  for (ll i = b; i >= 1; i--) {
    ans /= i;
  }
  return ans;
}

signed main() {
  int N,A,B;
  cin >> N >> A >> B;
  long long v[N];
  long double av = 0;
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }
  sort(v,v+N);
  reverse(v,v+N);
  for (int i = 0; i < A; i++) {
    av += v[i];
  }
  av /= A;
  cout << setprecision(120) << av << endl;
  bool all_same = true;
  for (int i = 0; i < A; i++) {
    if (v[0] != v[i]) {
      all_same = false;
    }
  }
  ll ans = 0;
  if (all_same) {
    int cnt = 0;
    for (int i = 0; i < N; i++)   {
      if (v[0] == v[i]) cnt++;
    }
    for (int i = A; i <= min(cnt,B); i++) {
      ans += Combination((ll)cnt,(ll)i);
    }
  } else {
    int cnt = 0;
    int num = 0;
    for (int i = 0; i < A; i++) {
      if (v[A-1] == v[i]) {
        cnt++;
      }
    }
    for (int i = 0; i < N; i++) {
      if (v[A-1] == v[i]) {
        num++;
      }
    }
    ans += Combination((ll)num,(ll)cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3812
n = int(input())

adj = [None]
for i in range(n):
    adj_i = list(map(int, input().split()[2:]))
    adj.append(adj_i)

isSearched = [None] + [False] * n

distance = [None] + [-1] * n

import collections

def bfs(u):
    isSearched[u] = True
    distance[u] = 0
    edge = collections.deque()
    edge.append(u)
    while edge:
        c_e = edge.popleft()
        for n_e in adj[c_e]:
            if not isSearched[n_e]:
                isSearched[n_e] = True
                distance[n_e] = distance[c_e] + 1
                edge.append(n_e)


bfs(1)

for i, x in enumerate(distance[1:], start=1):
    print(i, x)

Measured memory_bytes: 8020
using System;
using System.Linq;

namespace Aizu
{
    class OnlineJudge
    {
        public static void Main()
        {
            var d = Console.ReadLine().Split().Select(p => int.Parse(p)).ToArray();
            Console.WriteLine("{0} {1}", d[0] * d[1], d[0] * 2 + d[1] * 2);
        }
    }
}

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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    unordered_set<int> S;
    int n, q, ans=0;
    cin >> n;
    for(int i=0;i<n;i++){
        int s;
        cin >> s;
        S.insert(s);
    }
    cin >> q;
    for(int i=0;i<q;i++){
        int t;
        cin >> t;
        if(S.count(t)>0) ans++;
    }

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


Measured memory_bytes: 3112
#include <stdio.h>
int main(){

  int i,j,array[100],n,count=0,t;
  
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&array[i]);
  }
 
  for(i=0; i<n-1;i++){
    for(j=0; j<n-1;j++){
      if(array[j]>array[j+1]){
	t=array[j];
	array[j]=array[j+1];
	array[j+1]=t;
	count++;
      }
    }
  }

  for(i=0; i<n; i++){
    printf("%d",array[i]);
    if(i<n-1)
      printf(" ");
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}
 

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

int main() {
  string S;
  cin >> S;
  
  if (S.at(0) == S.at(1) || S.at(1) == S.at(2) || S.at(2) == S.at(3))
    cout << "Bad" << endl;
  else
    cout << "Good" << endl;
  
}

Measured memory_bytes: 256
#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(a, b) for(int unsafe_cnt=a; unsafe_cnt < b;unsafe_cnt++)
#define fn auto
#include <iostream>
#include <stdio.h>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;

void newline() {cout << endl;}
template <typename T> void display(T input){cout << input;}
template <typename T> void put(T input){display(input); newline();}
void iput(int input) {put(input);}

fn main() -> int {
  string a, b, c;
  cin >> a >> b >> c;
  auto a_iter_end   = a.end();
  auto b_iter_begin = b.begin();
  auto b_iter_end   = b.end();
  auto c_iter_begin = c.begin();
  a_iter_end--;
  b_iter_end--;
  string output = (*a_iter_end == *b_iter_begin) && 
                  (*b_iter_end == *c_iter_begin) ? "YES" : "NO";
  put(output);
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}



//head

int n;
string s;
bool b2 = false;
int ans = 1;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  cin >> s;
  rep(i, n) if(s[i] == '2') b2 = true;
  if(!b2) {
    ans <<= 1;
    rep(i, n) {
      if(s[i] == '3') s[i] = '2';
    }
  }

  int now = 0;
  int u = 0;
  rep(i, n) {
    if(i) {
      int j = n-i;
      now += __builtin_ctz(j) - __builtin_ctz(i);
    }
    if(!now and s[i] == '2') u ^= 1;
  }

  ans *= u;

  cout << ans << endl;
}

Measured memory_bytes: 4212
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <tuple>

using namespace std;

using P = pair<int, int>;
using i64 = int64_t;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;

bool is_less(const std::vector<int>& v) {
    for (int i=1; i < v.size()-1; ++i) {
        if (v[i-1] > v[i] ||
                v[i] > v[i+1])
            return false;
    }
    return true;
}

std::vector<int> swap(std::vector<int>& v, int i, int j) {
    vector<int> ret = v;
    ret[i] = v[j];
    ret[j] = v[i];
    return ret;
}

int main(int argc, char **argv) {
    int n;
    cin >>n;
    std::vector<int> v(n);
    for (int i=0; i<n; ++i) {
        cin >> v[i];
    }
    bool ans{false};
    for (int i=0; i<n; ++i) {
        for (int j=0; j<n; ++j) {
            ans = is_less(swap(v, i, j));
            if (ans) break;
        }
        if (ans) break;
    }

    cout << (ans? "YES": "NO") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int main () {
	cin >> n;
	if (n<1200){
		cout << "ABC" << endl;
	} else if (n<2800) {
		cout << "ARC" << endl;
	} else {
		cout << "AGC" << endl;
	}
}

Measured memory_bytes: 256
import sys
h,w = map(int,input().split())
s = ['']*h
for i in range(h):
  s[i] = input()
 
black = False
for i in range(h):
  for j in range(w):
    if s[i][j] == '#':
      if j != w - 1:
        if s[i][j + 1] == '#':
          continue
      if  j != 0:
        if s[i][j - 1] == '#':
          continue
      if i != h - 1:
        if s[i + 1][j] == '#':
          continue
      if i != 0:
        if s[i - 1][j] == '#':
          continue
      print('No')
      sys.exit()       
print('Yes')


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

const int max_n = 53;
int g[max_n][max_n];
int d[max_n];

int main(){
    int N, M;
    int a, b;
    cin >> N >> M;
    int h[N];
    int ans=0;

    for(int i =0 ; i < M; i++){
        cin >> a >> b;
        g[a-1][b-1]=1;
        g[b-1][a-1]=1;
        d[a-1]++;
        d[b-1]++;
    }
    bool flg = true;
    
    while(flg){
        flg = false;
        for(int i =0 ; i < N; i++){
            if (d[i]==1){
                flg = true;
                ans++;
                for(int j =0 ; j < N; j++){    
                    if(g[i][j]==1){
                        g[i][j]=0;
                        g[j][i]=0;
                        d[i]--;
                        d[j]--;
                    }

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

Measured memory_bytes: 256
N, K = map(int, input().split())
x = [0] * N
for _ in range(K):
    d = int(input())
    A = list(map(int, input().split()))
    for a in A:
        x[a-1] += 1
ans = 0
for y in x:
    if y == 0:
        ans += 1
print(ans)

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


int main() {
  long long int a,b,c,d;
  cin>> a>>b>>c>>d;
  vector<long long int>vec={a*c,a*d,b*c,b*d};
  sort(vec.begin(),vec.end());
{cout<<vec.at(3)<<endl;}
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main(void){
    char a,b;
    while(1){
        scanf("%c",&a);
        if(islower(a)){
            b=toupper(a);
            cout<<b;
        }else{
            b=tolower(a);
            cout<<b;
        }
        if(a =='\n') break;
    }
}



Measured memory_bytes: 3116
#include <iostream>
#include <limits>
#include <iterator>
#include <vector>
#include <algorithm>

int main()
{
    int A, B, M;
    std::cin >> A >> B >> M;

    std::vector<int> a_prices, b_prices;
    a_prices.reserve(A);
    b_prices.reserve(B);

    std::copy_n(std::istream_iterator<int>(std::cin), A, std::back_inserter(a_prices));
    std::copy_n(std::istream_iterator<int>(std::cin), B, std::back_inserter(b_prices));

    int min_sum_price = std::numeric_limits<int>::max();

    for (auto i = 0; i < M; i++) {
        int x, y, c;
        std::cin >> x >> y >> c;

        auto tmp_price = a_prices.at(x - 1) + b_prices.at(y - 1) - c;
        min_sum_price = std::min(min_sum_price, tmp_price);
    }

    auto tmp_price = *std::min_element(a_prices.cbegin(), a_prices.cend())
                     + *std::min_element(b_prices.cbegin(), b_prices.cend());
    min_sum_price = std::min(min_sum_price, tmp_price);

    std::cout << min_sum_price;

    return 0;
}

Measured memory_bytes: 1024
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_091_A.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP    PIC X(13).
    01 maxlen PIC 9(1)  VALUE 3.
    01 cur    PIC 9(13)  VALUE 1.
    01 i      PIC 9(18) VALUE 1.
    01 j      PIC 9(18).
    01 len    PIC 9(13).
    01 tmp    PIC 9(4).
    01 ABC1.
        03 ABC11 OCCURS 3.
            05 ABC PIC 9(4).
PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    PERFORM maxlen TIMES

        PERFORM VARYING j FROM cur BY 1
            UNTIL INP(j:1) = SPACE
        END-PERFORM

        COMPUTE len = j - cur

        MOVE INP(cur:len) TO ABC(i)

        COMPUTE cur = j + 1

        ADD 1 TO i

    END-PERFORM.

    ADD ABC(1) TO tmp.
    ADD ABC(2) TO tmp.

    IF tmp < ABC(3) THEN
        DISPLAY "No"
    ELSE
        DISPLAY "Yes"
    END-IF.

    STOP RUN.


Measured memory_bytes: 1016
#include <iostream>
#include <cstdio>
#include <vector>
#include <array>
#include <set>
#include <algorithm>

#define X first
#define Y second

using namespace std;

char table[52][52]; // [x][y]

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

int g_count[2];

void breadth(int x, int y) {
	std::vector<pair<int, int>> queue;
	queue.emplace_back(x,y);
	set<char> owner;
	table[x][y] = 'H';
	int count = 1;
	while (!queue.empty()) {
		auto a = queue.back();
		int x = a.X;
		int y = a.Y;
		queue.pop_back();

		for (int i = 0; i < 4; ++i) {
			if (table[x + dx[i]][y + dy[i]] == '.') {
				++count;
				queue.emplace_back(x + dx[i], y + dy[i]);
				table[x + dx[i]][y + dy[i]] = 'H';
			} else {
				owner.insert(table[x + dx[i]][y + dy[i]]);
			}
		}
	}

	if (owner.count('W') != 0 && owner.count('B') == 0) {
		g_count[1] += count;

	} else if (owner.count('W') == 0 && owner.count('B') != 0) {
		g_count[0] += count;
	}
}

int main() {
	for (int i = 0; i < 52; ++i) {
		table[i][0] = 'H';
		table[0][i] = 'H';
	}

	while (true) {
		int w, h;
		cin >> w >> h;
		if (w == 0) break;

		g_count[0] = 0;
		g_count[1] = 0;

		for (int y = 1; y <= h; ++y) {
			for (int x = 1; x <= w; ++x) {
				cin >> table[x][y];
			}
		}

		for (int i = 0; i < 52; ++i) {
			table[i][h+1] = 'H';
			table[w+1][i] = 'H';
		}

		for (int x = 1; x <= w; ++x) {
			for (int y = 1; y <= h; ++y) {
				if (table[x][y] != '.') continue;
				breadth(x,y);
			}
		}
		cout << g_count[0] << " " << g_count[1] << endl;
	}
}

Measured memory_bytes: 1228
# -*- coding: utf-8 -*-
# 学籍番号 17D8101029G 石塚 博之 ID: mcatpolo 言語: python3

n = int(input())
dic = set()

for i in range (n):
    com = input().split()

    

    if com[0] == "insert":
        dic.add(com[1])

    else:
        if com[1] in dic:
            print("yes")
        else:
            print("no")


Measured memory_bytes: 30992
// 173

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
#include <iomanip>
#include <climits>
#include <string>
#include <cmath>

using namespace std;
using ll = long long int;
#define NUM 1000000007

int main(){
    ll x, k, d, buf;
    cin >> x >> k >> d;
    x = abs(x);
    buf =  x/d;
    if(buf < k){
        if ((k-buf)%2 == 1) cout << abs(x-(buf+1)*d) << endl;
        else if((k-buf)%2 == 0)cout << abs(x-(buf)*d) << endl;
    }else{
        cout << abs(x-k*d) << endl;
    }
}

Measured memory_bytes: 3552