akhauriyash/Code-Regression huggingface dataset:
a,b = map(int,input().split())
art = [list(str(input())) for _ in range(a)]

def check(x,y):
    if x > 0:
        if art[x-1][y] == "#":
            return
    if x < a-1:
        if art[x + 1][y] == "#":
            return

    if y > 0:
        if art[x][y-1] == "#":
            return
    if y < b-1:
        if art[x][y+1] == "#":
            return
    print('No')
    exit(0)

for i in range(a):
    for j in range(b):
        if art[i][j] == "#":
            check(i,j)

print('Yes')

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

using Graph=vector<vector<int>>;

void depth(Graph &G,int v,int p,vector<int> &dep){

  dep[v]=dep[p]+1;
  
  for(auto nv:G[v]){
    if(nv==p) continue;
    depth(G,nv,v,dep);
  }

}

void subtree_size(Graph &G,int v,int p,vector<int> &subtree){

  for(auto nv:G[v]){
    if(nv==p) continue;
    subtree_size(G,nv,v,subtree);
  }

  subtree[p]=subtree[v]+1;

}


int main(){
  int N,u,v;
  cin>>N>>u>>v;
  u,v;
  Graph G(N+1);
  
  for(int i=0;i<N-1;++i){
    int a,b;
    cin>>a>>b;
    a,b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  vector<int> u_depth(N+1),v_depth(N+1),v_subtree(N+1);
  u_depth[0]=-1,v_depth[0]=-1;
  depth(G,v,0,v_depth);
  depth(G,u,0,u_depth);
  subtree_size(G,v,0,v_subtree);

  int ans=0;
  for(int i=1;i<=N;++i){
    if(u_depth[i]<v_depth[i]){
      ans=max(ans,v_depth[i]+v_subtree[i]);
    }
  }

  cout<<ans-1<<endl;

}

Measured memory_bytes: 13312
{-# LANGUAGE BangPatterns #-}
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as C
import Data.List

main = do
    [n,k] <- unfoldr (C.readInt . C.dropWhile (==' ')) <$> C.getLine
    h <- U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

    let dp = U.constructN n (\dp_ ->
            if U.null dp_ then 0
                else let !i = U.length dp_
                         !hi = h U.! i
                         f = U.slice (max 0 (i-k)) (min i k)
                         refh = f h
                         refd = f dp_
                    in U.minimum (
                        U.zipWith (\dc hc -> dc + abs(hi - hc)) refd refh
                        )
            )

    print $ U.last dp



Measured memory_bytes: 3708
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        char[] ch = sc.next().toCharArray();
        final int N = ch.length;
        int zero = 0;
        int one = 0;

        for (int i = 0; i < N; i++) {
            if (ch[i] == '0') {
                zero++;
            } else {
                one++;
            }
        }

        out.println(N < 2 ? "0" : Math.min(zero, one) * 2);

        out.flush();
    }
}
// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
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 long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 22996
import datetime

if __name__ == "__main__":
    MD1 = input().split()
    MD2 = input().split()

    # hoge = datetime.date(2019, MD1[0], MD1[1])

    if int(MD1[0]) == int(MD2[0]):
        print("0")
    else:
        print("1")
    


Measured memory_bytes: 3440
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

static const double PI = 3.14159265358979;
static const ll MOD = 1e9 + 7;
static const ll INF = (ll)1 << 62;

int main() {
	ll _A = 0, B_ = 0, B_A = 0;
	ll n; cin >> n;

	ll sum = 0;
	rep(i, 0, n) {
		string s; cin >> s;
		//pattern 1
		rep(j, 0, s.size() - 1) {
			if (s[j] == 'A' && s[j + 1] == 'B')sum++;
		}

		if (s[0] == 'B' && s[s.size() - 1] == 'A') {
			B_A++;
		}
		else if (s[0] == 'B') {
			B_++;
		}
		else if (s[s.size() - 1] == 'A') {
			_A++;
		}
	}

	//pattern 2
	ll p2 = ((B_ < _A) ? B_ : _A);
	sum += p2;

	//pattern 3
	if (B_A != 0) {
		if (_A == 0 && B_ == 0) {
			sum += (B_A - 1);
		}
		//else if (_A == 0 || B_ == 0) {
		//	sum += B_A;
		//}
		else {
			sum += B_A;
		}
	}

	cout << sum << endl;
	return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<int> a(N);
  for (int i=0;i<N;i++){
    cin >>a[i];
  }
  sort(a.begin(),a.end());
  int count=0;
 
  for (int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      int h=(lower_bound(a.begin(),a.end(),a[i]+a[j])-a.begin());
      count=count+max(0,h-(j+1));
        }
      }

  //cout<<N<<a[0]<<a[1]<<a[2]<<endl;
  cout<<count<<endl;
  return 0;
}

        

Measured memory_bytes: 256
#include <cstdio>
#include <vector>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)

typedef long long ll;

ll N;

void solve() {
  N++;
  vector<int> vs;
  int k = 0;
  ll n = N;
  while (n > 1) {
    vs.push_back(++k);
    n >>= 1;
  }
  for (int i = k - 1; i >= 0; i--) {
    if (N >> i & 1) {
      vs.insert(vs.begin() + i, ++k);
    }
  }
  printf("%d\n", k * 2);
  REP(i, k)  printf("%d ", vs[i]);
  FOR(i, 1, k)  printf("%d%c", i, i == k ? '\n' : ' ');
}

void input() {
  scanf("%lld", &N);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 256
#https://atcoder.jp/contests/abc162/tasks/abc162_c
# -*- coding: utf-8 -*-
import math
ans = 0
K = int(input())
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      ans += math.gcd(math.gcd(i,j),k)
print(ans)

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

#define ll long long int
#define LD long double

const int N = 100010;

int inf = 1e9;
int mod = 1e9 + 7;

int level[N];

pair<int,int> bfs(vector<vector<int>> &graph, int cur, int n) {
    bool visited[n + 1];
    memset(visited, false, sizeof(visited));
    queue<int> q;
    q.push(cur);
    level[cur] = 1;
    visited[cur] = true;
    int last = 1;
    while(!q.empty()) {
        int x = q.front(); q.pop();
        last = x;
        for(int u : graph[x]) {
            if(!visited[u]) {
                level[u] = level[x] + 1;
                visited[u] = true;
                q.push(u);
            }
            else if(abs(level[u] - level[x]) != 1) {
                return {-1, -1};
            }
        }
    }
    return {last, level[last]};
}

signed main()
{
    //freopen("IN.txt", "r", stdin);
    //freopen("OUT.txt", "w", stdout);

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n; cin >> n;
    vector<vector<int>> graph(n + 1);
    string s[n + 1];
    for(int i = 1; i <= n; i++) {
        cin >> s[i];
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            if(s[i][j - 1] == '1') {
                graph[i].push_back(j);
            }
        }
    }

    bool visited[n + 1];
    memset(visited, false, sizeof(visited));

    int ans = 0;

    for(int i = 1; i <= n; i++) {
        pair<int,int> P = bfs(graph, i, n);
        if(P.first == -1) {
            cout << "-1\n";
            return 0;
        }
        ans = max(ans, P.second);
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
using namespace std;
int w[101000];
int n;
int main(){
    int i;
    scanf("%d",&n);
    for(i=1;i<=n;i++)scanf("%d",&w[i]);
    sort(w+1,w+n+1);
    if(w[n]-w[1]>1){
        printf("No\n");
        return 0;
    }
    if(w[n]-w[1]==0){
        if(w[1] <= n/2 || w[1] == n-1)printf("Yes\n");
        else printf("No\n");
        return 0;
    }
    for(i=1;i<n;i++)if(w[i]!=w[i+1])break;
    int t = i;
    if(t + 1 <= w[n] && t + (n-t)/2 >= w[n])printf("Yes\n");
    else printf("No\n");
}

Measured memory_bytes: 512
using System;
using System.IO;
using System.Linq;
using System.Text;

namespace ABC122C
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Console.SetIn(new StreamReader(args[0]));
            }

            new Program().Solve2();
        }

        void Solve2()
        {
            // TLE対策版
            var temp1 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var N = temp1[0];
            var Q = temp1[1];
            var S = Console.ReadLine();
            var count = 0;
            var dict = new int[N + 1];
            dict[0] = 0;
            var ans = new StringBuilder();

            for (int i = 1; i < S.Length; i++)
            {
                if (S[i - 1] == 'A' && S[i] == 'C')
                {
                    count++;
                }

                dict[i] = count;
            }

            for (int i = 1; i <= Q; i++)
            {
                var temp2 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                var l = temp2[0];
                var r = temp2[1];

                ans.AppendLine((dict[r - 1] - dict[l - 1]).ToString());
            }

            Console.Write(ans);
        }

        void Solve()
        {
            var temp1 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var N = temp1[0];
            var Q = temp1[1];
            var S = Console.ReadLine();
            var ans = new StringBuilder();

            for (int i = 1; i <= Q; i++)
            {
                var temp2 = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                var l = temp2[0];
                var r = temp2[1];
                var count = 0;

                for (int j = l - 1; j < r - 1; j++)
                {
                    if (S[j] == 'A' && S[j + 1] == 'C')
                    {
                        count++;
                    }
                }

                ans.AppendLine(count.ToString());
            }

            Console.Write(ans);
        }
    }
}


Measured memory_bytes: 20920
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int A = n - (n % 10);
  int B = n % 1000;
  if (A % 111 == 0||B % 111 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

  public static void main(String[] args) {
    FastScanner sc = new FastScanner();

    long A = sc.nextLong();
    long B = sc.nextLong();
    long N = sc.nextLong();

    long x = Math.min(N, B - 1);
    long ans = (long) Math.floor(A * x / B);
    System.out.println(ans);

  }
}

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

  private void skipUnprintable() {
    while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
      ptr++;
    }
  }

  public boolean hasNext() {
    skipUnprintable();
    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() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    int n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }

  public long nextLong() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }
    long n = 0;
    boolean minus = false;
    int b = readByte();
    if (b == '-') {
      minus = true;
      b = readByte();
    }
    if (b < '0' || '9' < b) {
      throw new NumberFormatException();
    }
    while (true) {
      if ('0' <= b && b <= '9') {
        n *= 10;
        n += b - '0';
      } else if (b == -1 || !isPrintableChar(b)) {
        return minus ? -n : n;
      } else {
        throw new NumberFormatException();
      }
      b = readByte();
    }
  }
}

Measured memory_bytes: 25296
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int64 n,k;
    cin >> n >> k;
    vector<int64> a(n);
    for (int i=0; i<n; i++) cin >> a[i];


    int64 l = 0;
    int64 r = a[0];
    for (int i=1; i<n; i++) r=max(r,a[i]);

    while(l+1 < r) {
        int64 m = (l+r)/2;

        int64 t = 0;
        for (int i=0; i<n; i++) {
            t += a[i] / m;
            if (a[i] % m == 0) t--;
            if (t > k) break;
        }

        if (t <= k) r = m;
        else l = m;
    }
    cout << r << endl;
}

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

int main() {
  int N;
  vector<int> R;

  cin >> N;
  for(int i=0;i<N;i++) {
    int r;
    cin >> r;
    R.push_back(r);
  }

  int max_p = R[1] - R[0];
  int min_r = R[0];
  for(int i=1;i<N;i++) {
    min_r = min(min_r,R[i-1]);
    max_p = max(max_p,R[i]-min_r);
  }
  cout << max_p << endl;
}

Measured memory_bytes: 2068
import numpy as np

def is_prime(a):
  if a == 1:
    return False
  
  for i in range(2, 1+int(a**0.5)):
    if a % i == 0:
      return False
  return True

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

n = int(input())

ans = 0
divisors = make_divisors(n)
for d in divisors[1:]:
  if d > n:
    break
  if is_prime(n):
    ans += 1
    break
    
  tmp_divisors = make_divisors(d)
  for p in tmp_divisors[1:]:
    if not is_prime(p):
      continue
    tmp = np.log(d)/np.log(p)
    if tmp > 0 and tmp == int(tmp) and n % d == 0:
      n = n/d
      ans += 1
      break

print(ans)

Measured memory_bytes: 27180
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#define FOR(i, n) for(int i = 0; i < n; i++) 
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;

void load() {
}

void solve() {
	int n; scanf("%d", &n);
	int m; scanf("%d", &m);
	int a[m], b[m];
	const int inf = 1e9;
	int dp[m+1][1<<n];
	FOR(i, (1<<n)) {
		for (int j = 0; j <= m; j++) dp[j][i] = inf;
	}
	dp[0][0] = 0;
	FOR(i, m) {
		scanf("%d%d", a + i, b + i);
		int mask = 0;
		FOR(j, (b[i])) {
			int c;
			scanf("%d", &c); c--;
			mask |= 1 << c;
		}
		FOR(mk, (1<<n)) {
			dp[i+1][mk] = dp[i][mk];
		}
		FOR(mk, (1<<n)) {
			dp[i+1][mk | mask] = min(dp[i+1][mk|mask], dp[i][mk] + a[i]);
		}
	}
	int sol = dp[m][(1<<n)-1];
	if (sol == inf) sol = -1;
	printf("%d\n", sol);
}

int main() {
	load();
	solve();
	return 0;
}


Measured memory_bytes: 16128
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <ctime>

using namespace std;
#define RN cout << "\r\n";
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef long long int ll;
typedef pair<ll, ll> P;

// combination
const int MAX = 510000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll toColor(ll rate) {
    if (rate < 400) {
        return 0;
    } else if (rate < 800) {
        return 1;
    } else if (rate < 1200) {
        return 2;
    } else if (rate < 1600) {
        return 3;
    } else if (rate < 2000) {
        return 4;
    } else if (rate < 2400) {
        return 5;
    } else if (rate < 2800) {
        return 6;
    } else if (rate < 3200) {
        return 7;
    } else {
        return 8;
    }
}

ll countColor(vector<ll> colors) {
    ll count = 0;
    REP(i, 8) {
        if (colors[i] > 0) {
            count++;
        }
    }
    return count;
}

int main() {
    ll n;
    cin >> n;
    vector<ll> colors(9, 0);
    REP(i, n) {
        ll a;
        cin >> a;
        colors[toColor(a)]++;
    }
    ll usedColors = countColor(colors);
    ll free = colors[8];
    cout << max((ll)1, usedColors) << ' ' << usedColors + free << endl;
    return 0;
}


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

typedef long long int ll;
typedef vector<int> vi;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define pvec(v) for(auto e: v) cout << e << " ";
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i, a, b) for(int i = (a); i<(b); ++i)
#define pb push_back
#define INF 1000000005
#define MOD 1000000007
#define all(v) v.begin(), v.end()

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

ll power(ll x, ll y, ll p = MOD){  
    ll res = 1LL; 
    x = x % p;
    if (x == 0) return 0;
    while (y > 0){
        if (y & 1LL)  
            res = (res*x) % p;
        y = y>>1LL; 
        x = (x*x) % p;  
    }  
    return res;  
}  

int main(){
	IO
	int n;
	cin >> n;

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

	int dp[n + 1] = {0};
	dp[2] = abs(h[1] - h[0]);
	for(int i = 3; i <= n; ++i) {
		dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i - 2]) , dp[i - 2] + abs(h[i - 1] - h[i - 3]));
	}

	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 4416
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<long long int> a(n);
  for (int i = 0; i < n; i++)
  {
    cin>>a[i];
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());

  long long int tmp[2] = {0};
  int j = 0;
  for (int i = 0; i <n; i++)
  {
    if(a[i] == a[i-1]){
      tmp[j] = a[i];
      j++;
      if (j > 1)
      {
        break;
      }
      i++;
    }
    if(i>=n){
      break;
    }
  }
  
  cout<< tmp[0] * tmp[1] <<"\n";
  return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env pypy3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import math,sys

n = int(sys.stdin.readline())
a = tuple(map(int,sys.stdin.readline().split()))
#n = int(input())
#a = list(map(int,input().split()))
g = math.gcd(a[0],a[1])
for i in range(2,n):
    g = math.gcd(g,a[i])
M = max(a)
acc = a[0]
for i in range(n):
    acc = math.gcd(acc,a[i])
if acc != 1:
    print("not coprime")
    exit()

LIMIT=max(a)
minPrime = [0]*(LIMIT+1)
minPrime[1] = 1
def make():
    for i in range(2,LIMIT+1):
        if minPrime[i] == 0:
            minPrime[i] = i
            #print(i)
            for j in range(i+i,LIMIT+1,i):
                #print(i,j)
                if minPrime[j] == 0:
                    minPrime[j] = i
make()
def factrial(N):
     ret = []
     while minPrime[N] != N:
         ret.append(minPrime[N])
         N = N//minPrime[N]
     if N != 1:
         ret.append(N)
     return ret

judge = set([])
pc = True

pairwise = True
p = set() #all prime

for e in a:
    if not pairwise:
        break
    asf = set(factrial(e))
    if judge & asf != set():
        pc = False
    #     #pairwise = False
    #     print("setwise coprime")
    #     exit(0)
    judge |= asf
# for i in a:
#     if not pc:
#         break
#     asf = set(factrial(i))

#     if judge & asf != set():
#         pc = False
#     judge |= asf
if pc:
    print("pairwise coprime")
elif g == 1:
    print("setwise coprime")
else:
    print("not coprime")


Measured memory_bytes: 203940
// ARC097C.cpp
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 2020;

int n, tablewb[MAX_N][MAX_N], tablebw[MAX_N][MAX_N], dp[MAX_N][MAX_N], wid[MAX_N], bid[MAX_N];
char cmdlet[20];

int main()
{
    scanf("%d", &n);
    for (int i = 1, x; i <= (n << 1); i++)
    {
        scanf("%s%d", cmdlet + 1, &x);
        if (cmdlet[1] == 'W')
            wid[x] = i;
        else
            bid[x] = i;
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j < i; j++)
            if (wid[i] < wid[j])
                tablewb[i][0]++;
        for (int j = 1; j <= n; j++)
            tablewb[i][j] = tablewb[i][j - 1] + (wid[i] < bid[j]);
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j < i; j++)
            if (bid[i] < bid[j])
                tablebw[0][i]++;
        for (int j = 1; j <= n; j++)
            tablebw[j][i] = tablebw[j - 1][i] + (bid[i] < wid[j]);
    }
    int prew = 0, preb = 0;
    for (int i = 1; i <= n; i++)
        prew += tablewb[i][0], dp[i][0] = prew, preb += tablebw[0][i], dp[0][i] = preb;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            dp[i][j] = min(dp[i - 1][j] + tablewb[i][j], dp[i][j - 1] + tablebw[i][j]);
    printf("%d\n", dp[n][n]);
    return 0;
}

Measured memory_bytes: 47872
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
LL p = 1000000007ll;

int main(void)
{
  string s;
  cin >> s;
  sort(s.begin(),s.end());
  bool flag = true
    && s[0] == s[1]
    && s[1] != s[2]
    && s[2] == s[3];
  cout << (flag?"Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = in.nextInt();
        final int m = in.nextInt();
        final Set<Integer> broken = new HashSet<>();
        for (int i = 0; i < m; i++) {
            broken.add(in.nextInt());
        }

        int[] dp = new int[n + 1];

        dp[0] = 1;
        for (int i = 1; i <= n; i++) {
            if (broken.contains(i)) {
                continue;
            }
            int count = 0;
            if (!broken.contains(i - 1)) {
                count += dp[i - 1];
            }
            if (i - 2 >= 0 && !broken.contains(i - 2)) {
                count += dp[i - 2];
            }
            count %= 1_000_000_007;
            dp[i] = count;
        }
        System.out.println(dp[n]);
    }
}


Measured memory_bytes: 64184
#include<bits/stdc++.h>
using namespace std;
const int N=2010,oo=1e9;
int n,m;
char s[N];
int g[N][N],a[N][N],h[N][N],l[N][N],r[N][N],ans;
int main(){
	char c;
	int fp;
	scanf("%d%d\n",&n,&m);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			c=getchar();
			g[i][j]=(c=='#');
		}
		getchar();
	}
	for(int i=1;i<n;i++)
		for(int j=1;j<m;j++){
			a[i][j]=(g[i][j]^g[i][j+1])==(g[i+1][j]^g[i+1][j+1]);
		}
	for(int i=1;i<n;i++) for(int j=1;j<m;j++)h[i][j]=a[i][j]?h[i-1][j]+1:0;
	for(int i=1;i<m;i++) l[0][i]=r[0][i]=oo;
	for(int i=1;i<n;i++){
		fp=0;
		for(int j=1;j<m;j++){
			if(a[i][j]) l[i][j]=min(l[i-1][j],j-fp);
			else fp=j,l[i][j]=oo;
		}
		fp=m;
		for(int j=m-1;j>=1;j--)
			if(a[i][j]) r[i][j]=min(r[i-1][j],fp-j);
			else fp=j,r[i][j]=oo;
	}
//	for(int i=1;i<n;i++){
//		for(int j=1;j<m;j++){
//			cout<<a[i][j]<<" ";
//		}
//		cout<<endl;	
//	}
//	cout<<endl;
//	for(int i=1;i<n;i++){
//		for(int j=1;j<m;j++){
//			cout<<h[i][j]<<" ";
//		}
//		cout<<endl;	
//	}
//	cout<<endl;
//	for(int i=1;i<n;i++){
//		for(int j=1;j<m;j++){
//			cout<<l[i][j]<<" ";
//		}
//		cout<<endl;	
//	}
//	cout<<endl;
//	for(int i=1;i<n;i++){
//		for(int j=1;j<m;j++){
//			cout<<r[i][j]<<" ";
//		}
//		cout<<endl;	
//	}
	ans=max(n,m);// !
	for(int i=1;i<n;i++)
		for(int j=1;j<m;j++){
			if(a[i][j]) ans=max(ans,(h[i][j]+1)*(l[i][j]+r[i][j]));
		}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 79104
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long A = in.nextLong();
		long B = in.nextLong();
		int K = in.nextInt();
		for (int i = 1; i <= K; i++) {
			if (i % 2 == 1) {
				if (A % 2 == 1) {
					A = A - 1;
				} 
				A = A / 2;
				B = B + A ;
			}
			else if (i % 2 == 0) {
				if (B % 2 == 1) {
					B = B - 1;
				} 
				B = B / 2;
				A = A + B ;
			}
		}
		System.out.println(A);
		System.out.println(B);

	}
}


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

int dp[502][2][10][500][3], m;
char S[2][550];
int solve(int o) {
	memset(dp, 0, sizeof(dp));
	dp[0][0][0][0][0] = 1;
	int i;
	for (i = 0; S[o][i]; i++)rep(j, 2)rep(k, 10)rep(l, m)rep(d, 3) {
		if (dp[i][j][k][l][d] == 0)continue;
		int s, g, p = S[o][i] - '0';
		if (d == 1)s = k + 1, g = (j ? 9 : p);
		else if (d == 2)s = 0, g = (j ? k - 1 : min(k - 1, p));
		else s = 0, g = (j ? 9 : p);
		for (int x = s; x <= g; x++) {
			if (x&&k == x)continue;
			int y;
			if (d == 1)y = 2;
			else if (d == 2)y = 1;
			else {
				if (k == 0)y = 0;
				else if (x < k)y = 1;
				else y = 2;
			}
			(dp[i + 1][j || x < p][x][(l * 10 + x) % m][y] += dp[i][j][k][l][d]) %= MOD;
		}
	}
	int sum = 0;
	rep(k, 2)rep(j, 10)rep(t, 3) {
		if (!k && !o)continue;
		(sum += dp[i][k][j][0][t]) %= MOD;
	}
	return sum;
}
int main() {
	scanf("%s%s%d", S[0], S[1], &m);
	printf("%d\n", (solve(1) + MOD - solve(0)) % MOD);
}

Measured memory_bytes: 62036
N, M = map(int,input().split())
As = sorted(list(map(int,input().split())))
BCs = sorted([list(map(int,input().split())) for _ in range(M)],key = lambda x:-x[1])

j = 0
for i in range(N):
  if BCs[j][0] <= 0:
    j += 1
  if j == M or As[i] > BCs[j][1]:
    break
  else:
    As[i] = BCs[j][1]
    BCs[j][0] -= 1


print(sum(As))
    

Measured memory_bytes: 36828
a=input()
a=int(a)
ll=[]
count=1
for i in range(a):
    x,y=input().split()
    y=int(y)
    ll.append([x,y,count])
    count+=1
ll=sorted(ll, key=lambda x:(x[0],-x[1]))
for i in ll:
    print(i[2])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define endl '\n'
#define vi vector<ll>
#define vb vector<bool>
#define mii map<ll, ll>
#define pii pair<ll, ll>
#define pb push_back
#define fi first
#define se second
//just see queue data structure, solve it like 600 rating problem.
ll power(ll a, ll b){
    ll res = 1;
    while(b!=0){
        if(b&1){
            res *= a; 
        }
        a = (a * a);
        b = (b / 2);
    }
    return res;
}
int main(){
    SPEED;
    ll a, b, i;
    cin>>a>>b;
    if(a>b)swap(a, b);
    string s = "";
    for(i=0;i<b;i++){
        ll x = a+48;
        s+=(char)x;
    }
    cout<<s;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
//    int a = sc.nextInt();  // input Integer
    String a = sc.next();  // input String
    String b = sc.next();  // input String
    int ans = 10000;
    int loop = a.length() - b.length() + 1;
    if (a.contains(b)){
      System.out.println(0);
    } else {
      for (int i=0; i<loop ;i++){
        int tmp=0;
        String sub = a.substring(i,i+b.length());
        for (int j=0 ; j<sub.length();j++){
          if(sub.charAt(j) != b.charAt(j)){
            tmp++;
          }
        }
        if(ans>tmp){
          ans=tmp;
        }
      }
      System.out.println(ans);
    }
  }
}


Measured memory_bytes: 36696
#include<iostream>
#include <algorithm>
#include<string>
#include <numeric>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;

int main(void) {

    string n;
    cin>>n;
    if(n[1]==n[2]&&n[0]==n[1]||n[1]==n[2]&&n[3]==n[1])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

int digit_sum(int num) {
    int res=0;
    while (num>0) {
        res += num%10;
        num /= 10;
    }
    return res;
}

int main() {
    int a, b, n;
    std::cin >> n;
    a = 1;
    b = n-1;
    int mid = n/2, res=100000;
    
    while ( a <= b ) {
        res = std::min( res, digit_sum(a)+digit_sum(b) );
        ++a;
        --b;
    }

    std::cout << res << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define STRING_MAX 101
#define TEICE 2
#define FRG_OFF 0
#define FRG_ON 1
#define ARRAY_RESET 0
#define LOOP_RESET 0
#define COUNT_RESET 0
#define RETURN 0

unsigned short s_scan_sentence(unsigned char * str, unsigned short length_max);
unsigned short s_sarch_text(unsigned char * ring, unsigned short r_length, unsigned char * look, unsigned short l_length);

int main(){
	unsigned char ubW_D_ring_text[STRING_MAX];	/* 検索元文字列の配列 */
	unsigned char ubW_D_look_text[STRING_MAX];	/* 検索文字列の配列 */
	unsigned short usW_D_ring_length;         	/* 検索元文字列の長さ */
	unsigned short usW_D_look_length;         	/* 検索文字列の長さ */
	unsigned short usW_F_frg_main = FRG_OFF;  	/* フラグ */
	unsigned short usW_C_i;                   	/* ループ変数 */
	
	/* 配列の初期化 */
	for(usW_C_i = LOOP_RESET;usW_C_i < STRING_MAX;usW_C_i++){
		ubW_D_ring_text[usW_C_i] = ARRAY_RESET;
		ubW_D_look_text[usW_C_i] = ARRAY_RESET;
	}
	
	/* 検索元文字列の入力 */
	usW_D_ring_length = s_scan_sentence(ubW_D_ring_text, STRING_MAX);
	/* 検索文字列の入力 */
	usW_D_look_length = s_scan_sentence(ubW_D_look_text, STRING_MAX);
	
	/* 文字列の検索 */
	usW_F_frg_main = s_sarch_text(ubW_D_ring_text, usW_D_ring_length, ubW_D_look_text, usW_D_look_length);
	
	/* フラグが0の場合Noを、1の場合Yesを出力 */
	if(usW_F_frg_main == FRG_OFF){
		printf("No\n");
	}
	else if(usW_F_frg_main == FRG_ON){
		printf("Yes\n");
	}
	
	return RETURN;
}


/* 関数名：文字列入力 */
/* 概要：文字列を入力する。その長さを返す */
/* 引数：文字列を格納する配列の先頭アドレス、その配列の大きさ */
/* 戻り値：入力された文字列の長さ */
unsigned short s_scan_sentence(unsigned char * str, unsigned short length_max)
{
	unsigned short usW_C_count_text = COUNT_RESET;  	/* 文字列長カウンタ */
	unsigned short usW_C_i;                         	/* ループ変数 */

	/* 文字列の入力 */
	for(usW_C_i = LOOP_RESET;usW_C_i < length_max;usW_C_i++){
		scanf("%c", str + usW_C_i);
		/* 入力終了の処理 */
		if(*(str + usW_C_i) == '\n'){
			break;
		}
		/* 文字数をカウント */
		usW_C_count_text++;
	}

	/* 文字列長を返す */
	return usW_C_count_text;
}

unsigned short s_sarch_text(unsigned char * ring, unsigned short r_length, unsigned char * look, unsigned short l_length)
{
	unsigned char twi_ring[STRING_MAX * TEICE]; 	/* 円状の文字列を再現する配列 */
	unsigned short usW_F_frg_fanc = FRG_OFF;    	/* フラグ */
	unsigned short usW_C_i, usW_C_j;            	/* ループ変数 */
	
	/* 配列を初期化 */
	for(usW_C_i = LOOP_RESET;usW_C_i < (STRING_MAX * TEICE);usW_C_i++){
		twi_ring[usW_C_i] = ARRAY_RESET;
	}
	
	/* 円状の文字列を再現 */
	/* 円状の文字列に検索元文字列を代入 */
	for(usW_C_i = LOOP_RESET;usW_C_i < r_length;usW_C_i++){
		twi_ring[usW_C_i] = *(ring + usW_C_i);
	}
	/* 円状の文字列の続きに検索元文字列を代入 */
	for(usW_C_i = LOOP_RESET;usW_C_i < r_length;usW_C_i++){
		twi_ring[r_length + usW_C_i] = *(ring + usW_C_i);
	}
	/* 円状の文字列を再現 ここまで */
	
	/* 文字列の検索 */
	/* 円状の文字列の始点をずらしながら検索 */
	for(usW_C_i = LOOP_RESET;usW_C_i <= r_length;usW_C_i++){
		/* 文字列の合致を一文字ずつ照合 */
		for(usW_C_j = LOOP_RESET;usW_C_j <= l_length;usW_C_j++){
			/* 検索する文字列が終端であればフラグを1に */
			if(*(look + usW_C_j) == '\n'){
				usW_F_frg_fanc = FRG_ON;
			}
			/* 二つの文字列の対象の文字が一致していなければループを抜ける */
			if(twi_ring[usW_C_i + usW_C_j] != *(look + usW_C_j)){
				break;
			}
		}
	}
	/* 文字列の検索 ここまで */
	
	/* フラグの値を返す */
	return usW_F_frg_fanc;
}



Measured memory_bytes: 2100
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
  int d;
  cin >> d;
  int c[26];
  for(int i = 0; i < 26; i++) {
    cin >> c[i];
  }
  vector<vector<int>> s(d, vector<int>(26));
  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++) {
    int idx = 0;
    int maxi = 0;
    for(int j = 0; j < 26; j++) {
      if(s[i][j] > maxi) {
        maxi = s[i][j];
        idx = j;
      }
    }
    cout << idx + 1 << endl;
  }
  return 0;
}

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

int main()
{
    long long a, b;
    cin >> a >> b;

    long long res = 0;
    long long pat = 2;
    long long mx = log2(b) + 1;


    for(long long i = 0; i < mx; ++i){
        long long tila = a / pat * (pat / 2) + max(0LL, a % pat - pat / 2);
        long long tilb = (b + 1) / pat * (pat / 2) + max(0LL, (b + 1) % pat - pat / 2);
        long long dif = tilb - tila;
        dif %= 2;
        if(dif){
            res += (1LL << i);
        }
        pat *= 2;
    }

    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
int main(){
    int n;
    cin>>n;
    V<ll> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    V<V<ll>> dp(n+1,V<ll>(3,-inf));
    dp[0][0]=0;
    int skip=(n&1)+1;
    for(int i=0;i<n;i++){
        for(int j=0;j<=skip;j++){
            if(j!=skip){
                chmax(dp[i+1][j+1],dp[i][j]);
            }
            chmax(dp[min(n,i+2)][j],dp[i][j]+a[i]);
        }
    }
    cout<<max(dp[n][skip-1],dp[n][skip])<<"\n";
}

Measured memory_bytes: 15856
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {

    	Scanner sc=new Scanner(System.in);

    	int A=sc.nextInt();
    	String op=sc.next();
    	int B=sc.nextInt();
    	
    	int result=0;
    	
    	if(op.equals("+")) {
    		result=A+B;
    	}else {
    		result=A-B;
    	}
    	
    	System.out.println(result);
    	
    }
}


Measured memory_bytes: 21716
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    int N;
    cin >> N;
    vector<int> ps(N);
    int sum = 0;
    int maximum = 0;
    for (int i = 0; i < N; i++) {
        cin >> ps[i];
        sum += ps[i];
        chmax(maximum, ps[i]);
    }

    sum -= maximum / 2;
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <set>
#include <map>

#define rep(i,n)   for(int i=0;i<n;++i)
#define all(c)     c.begin(),c.end()

using namespace std;
typedef set<int> iset;

string src;
int p;

iset U;
map<char, iset> sets;

iset parse_expr(); // proto

bool end() { return p >= (int)src.length(); }
char peek() { return src[p]; }
void succ() { if (!end()) ++p; }

iset set_u(const iset &a, const iset &b)
{
	iset c = a;
	c.insert(all(b));
	return c;
}

iset set_i(const iset &a, const iset &b)
{
	iset c;
	for (iset::const_iterator it = a.begin(); it != a.end(); ++it)
	{
		if (b.find(*it) != b.end()) c.insert(*it);
	}
	return c;
}

iset set_d(const iset &a, const iset &b)
{
	iset c;
	for (iset::const_iterator it = a.begin(); it != a.end(); ++it)
	{
		if (b.find(*it) == b.end()) c.insert(*it);
	}
	return c;
}

iset set_s(const iset &a, const iset &b)
{
	return set_u(set_d(a, b), set_d(b, a));
}

iset set_c(const iset &a)
{
	return set_d(U, a);
}

iset parse_primary()
{
	iset s;

	char c = peek();
	switch (c)
	{
	case 'c':
		succ();
		s = set_c(parse_primary());
		break;
	case '(':
		succ();
		s = parse_expr();
		if (peek() == ')') succ();
		break;
	default:
		succ();
		s = sets[c];
		break;
	}
	return s;
}

bool is_op()
{
	char c = peek();
	return c=='u'||c=='i'||c=='d'||c=='s';
}

iset parse_expr()
{
	iset a = parse_primary();

	while (!end() && is_op())
	{
		char op = peek();
		succ();

		iset b = parse_primary();
		switch (op)
		{
		case 'u':
			a = set_u(a, b);
			break;
		case 'i':
			a = set_i(a, b);
			break;
		case 'd':
			a = set_d(a, b);
			break;
		case 's':
			a = set_s(a, b);
			break;
		}
	}
	return a;
}

iset parse()
{
	p = 0;
	return parse_expr();
}

int main()
{
	while(!cin.eof())
	{
		char name;
		int N, e;

		U.clear();
		sets.clear();
		while(cin >> name >> N, name != 'R')
		{
			rep(i,N)
			{
				cin >> e;
				sets[name].insert(e);
				U.insert(e);
			}
		}

		cin >> src;
		iset s = parse();
		if (s.empty())
		{
			cout << "NULL" << endl;
			continue;
		}

		for (iset::const_iterator it = s.begin(); it != s.end(); ++it)
		{
			if (it != s.begin()) cout << " ";
			cout << *it;
		}
		cout << endl;

		cin.ignore();
		cin.peek();
	}
	return 0;
}

Measured memory_bytes: 0
def merge(A, left, mid, right):
    inf = float("inf")
    L, R = A[left:mid]+[inf], A[mid:right]+[inf]

    i = j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

    return right - left


def merge_sort(A, left, right, count=0):
    if left+1 < right:
        mid = (left + right) // 2
        count = merge_sort(A, left, mid, count)
        count = merge_sort(A, mid, right, count)
        count += merge(A, left, mid, right)

    return count


if __name__ == "__main__":
    n = int(input())
    A = list(map(int, input().split()))
    count = merge_sort(A, 0, n)
    print(*A)
    print(count)


Measured memory_bytes: 63692
import numpy as np
from operator import mul
from functools import reduce

MOD = 10**9+7
def calc(a,b=MOD-2):
    if b==0: return 1
    elif b%2==0: return (calc(a,b/2)**2)%MOD
    else: return (a*calc(a,b-1))%MOD

X,Y = list(map(int,input().split()))
i, j = (X-2*Y), (-2*X+Y)

if i%3==0 and i<=0 and j%3==0 and j<=0:
    i,j = -i//3,-j//3
    i,j = min(i,j), max(i,j)
    n,m = 1,1
    for k in range(i): n = (n * (i+j-k))%MOD
    m = calc(np.math.factorial(i))%MOD
    print((n*m)%MOD)
else: print(0)

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    ll sum = 0;
    rep(i, n) sum += a[i];
    ll k = sum/((1ll+n)*n/2);
    if(sum%((1ll+n)*n/2) != 0 || k <= 0){
        cout << "NO" << endl;
        return 0;
    }

    set<int> d;
    rep(i, n-1) d.insert(a[i]-a[i+1]);
    d.insert(a[n-1]-a[0]);

    for(auto x : d) d.erase(x), d.insert(x+k);    

    for(auto x : d){
        if(x < 0 || x%n != 0){
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;


    return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
//max=({});
//条件式が真ならwhileの中身を回し続ける

bool flag[1050000];

int main() {
	int n;
	cin >> n;
	vector<ll>H(n);
	rep(i, n) {
		cin >> H[i];
	}
	ll target = H[n - 1];
	bool flag = true;
	rep(i, n) {
		if (target + 1 == H[n - 1 - i]) {
			H[n - 1 - i]-=1;
		}
		else if (target + 1 < H[n - 1 - i]) {
			puts("No");
			return 0;
		}
		target = H[n - 1 - i];
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/
 
int n,m;
ll ans;
int wide[1500001],hight[1500001];
int w[1505],h[1505];
 
void enumerate_hight(){
  int sum;
  for(int i=0;i<n;i++){
    sum=0;
    for(int j=i;j<n;j++){
      sum+=h[j];
      hight[sum]++;
    }
  }
}
 
void enumerate_wide(){
  int sum;
  for(int i=0;i<m;i++){
    sum=0;
    for(int j=i;j<m;j++){
      sum+=w[j];
      wide[sum]++;
    }
  }
}
 
void solve(){
  ll max_w=0,max_h=0,maxi;
  ans=0;
  for(int i=0;i<n;i++){scanf("%d",&h[i]);max_h+=h[i];}
  enumerate_hight();
  for(int i=0;i<m;i++){scanf("%d",&w[i]);max_w+=w[i];}
  enumerate_wide();
  maxi=max(max_w,max_h);
  rep(i,maxi+1){ans+=wide[i]*hight[i];wide[i]=hight[i]=0;}
  cout<<ans<<endl;
}
 
int main(){
  while(scanf("%d%d",&n,&m)){
    if(n==0&&m==0)break;
    solve();
  }
}

Measured memory_bytes: 7132
import heapq
N,M = map(int,input().split())
AB = []
for i in range(N):
    a,b = map(int,input().split())
    if a <= M:
        AB.append([a,b])
    
AB.sort(reverse=True)
List = []

ans = 0
for i in range(1,M+1):
    while AB and AB[-1][0] <= i:
        tmp = AB.pop()
        heapq.heappush(List,-tmp[1])

    if len(List) > 0:
        ans -= heapq.heappop(List)
        
print(ans)

Measured memory_bytes: 20236
#include<bits/stdc++.h>
using namespace std;
int main(){
int num;
cin>>num;
int d=num%10,c=(num/10)%10,b=(num/100)%10,a=(num/1000)%10;
if(a+b+c+d==7)cout<<a<<'+'<<b<<'+'<<c<<'+'<<d;
else if(a-b+c-d==7)cout<<a<<'-'<<b<<'+'<<c<<'-'<<d;
else if(a-b-c-d==7)cout<<a<<'-'<<b<<'-'<<c<<'-'<<d;
else if(a+b-c-d==7)cout<<a<<'+'<<b<<'-'<<c<<'-'<<d;
else if(a-b-c+d==7)cout<<a<<'-'<<b<<'-'<<c<<'+'<<d;
else if(a+b+c-d==7)cout<<a<<'+'<<b<<'+'<<c<<'-'<<d;
else if(a-b+c+d==7)cout<<a<<'-'<<b<<'+'<<c<<'+'<<d;
else if(a+b-c+d==7)cout<<a<<'+'<<b<<'-'<<c<<'+'<<d;
cout<<"=7";
return 0;
}


Measured memory_bytes: 256
/*
 _____ ____ _____   ___   ___  __  ___  
|_   _/ __ \_   _| |__ \ / _ \/_ |/ _ \ 
  | || |  | || |      ) | | | || | (_) |
  | || |  | || |     / /| | | || |\__, |
 _| || |__| || |_   / /_| |_| || |  / / 
|_____\____/_____| |____|\___/ |_| /_/   
*/
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb push_back
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
using namespace std;
const double goldie = 1.61803398875;
int main(){
    int k,x;
    cin >> k >> x;
    vi v;
    v.pb(x);
    rep(i,1,k){
        v.pb(x+i);
        v.pb(x-i);
    }
    sort a(v);
    rep(i,0,2*k-1){
        cout << v[i] << " ";
    }
}

Measured memory_bytes: 256