akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node {
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;
    
    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;
    
    while (x != NIL) {
        y = x;
        if (z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }
    
    z->parent = y;
    if (y == NIL) {
        root = z;
    } else {
        if (z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

void inorder(Node *u) {
    if (u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u) {
    if (u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main() {
    int n, i, x;
    string com;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        cin >> com;
        if (com == "insert") {
            scanf("%d", &x);
            insert(x);
        } else if (com == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    
    return 0;
}


Measured memory_bytes: 26644
// atcoder/m-solutions2020/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  int a, b, c, k;
  while (cin >> a >> b >> c >> k) {
    bool f = false;
    for (int i = 0; i <= k; ++i) {
      for (int j = 0; j <= k; ++j) {
        if (i + j <= k) {
          int x = b * (1 << i);
          int y = c * (1 << j);
          if (a  < x && x < y) f = true;
        }
      }
    }
    cout << (f ? "Yes" : "No") << endl;
  }

  return 0;
}


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

int main() {
  int a,b,c,d;
  
  cin >> a >> b >> c >> d;
  
  int s1,s2;
  
  s1 = a*b;
  s2 = c*d;
  
  if(s1>s2)
    cout << s1;
  if(s1<s2)
    cout << s2;
  if(s1==s2)
    cout << s1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, -1, 0, 1};
bool search(int n, int m, int distr, int distc, vector<vector<bool>> &sel, int dir, int r, int c) {
  if(r == distr && c == distc) return true;
  if(0 <= r + dr[(dir + 1) % 4] && r + dr[(dir + 1) % 4] < n &&
      0 <= c + dc[(dir + 1) % 4] && c + dc[(dir + 1) % 4] < m &&
      sel[r + dr[(dir+1)%4]][c + dc[(dir+1)%4]]) {
    sel[r + dr[(dir+1)%4]][c + dc[(dir+1)%4]] = false;
    bool ok = search(n, m, distr, distc, sel, (dir + 1) % 4, r + dr[(dir + 1) % 4], c + dc[(dir + 1) % 4]);
    if(ok) return true;
  }
  if(0 <= r + dr[dir] && r + dr[dir] < n &&
      0 <= c + dc[dir] && c + dc[dir] < m &&
      sel[r + dr[dir]][c + dc[dir]]) {
    sel[r + dr[dir]][c + dc[dir]] = false;
    bool ok = search(n, m, distr, distc, sel, dir, r + dr[dir], c + dc[dir]);
    if(ok) return true;
  }
  if(0 <= r + dr[(dir + 3) % 4] && r + dr[(dir + 3) % 4] < n &&
      0 <= c + dc[(dir + 3) % 4] && c + dc[(dir + 3) % 4] < m &&
      sel[r + dr[(dir + 3) %4]][c + dc[(dir + 3) % 4]]) {
    sel[r + dr[(dir + 3) % 4]][c + dc[(dir + 3) % 4]] = false;
    bool ok = search(n, m, distr, distc, sel, (dir + 3) % 4, r + dr[(dir + 3) % 4], c + dc[(dir + 3) % 4]);
    if(ok) return true;
  }
  return false;
}
bool solve() {
  int n, m; cin >> n >> m;
  if(n == 0) return false;
  vector<vector<bool>> sel(n, vector<bool>(m, false));
  for(int i=0;i<n;++i) {
    for(int j=0;j<m;++j) {
      char tmp; cin >> tmp;
      sel[i][j] = tmp == '.';
    }
  }
  bool ok = search(n, m, n-1, 0, sel, 0, 0, 0);
  if(ok) ok = search(n, m, n-1, m-1, sel, 3, n-1, 0);
  if(ok) ok = search(n, m, 0, m-1, sel, 2, n-1, m-1);
  if(ok) ok = search(n, m, 0, 0, sel, 1, 0, m-1);
  cout << (ok ? "YES" : "NO") << endl;
  return true;
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  while(solve()) {}
}



Measured memory_bytes: 3072
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()

int main() {
  //
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];

  vector<vector<int> > vert(h, vector<int>(w, 0));
  vector<vector<int> > horz(h, vector<int>(w, 0));

  for (int i = 0; i < h; i++) {
    vector<int> block;
    // block.push_back(-1);
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') block.push_back(j);
    }
    block.push_back(w);
    int left = -1;
    int idx = 0;
    for (int j = 0;j < w; j++) {
      if (block.size() == 1) {
        horz[i][j] = w;
        continue;
      }
      if (s[i][j] == '.') {
        if (j < block[idx]) {
          horz[i][j] = block[idx] - left - 1;
        } else {
          while (block[idx] < j) idx++;
          left = block[idx-1];
          horz[i][j] = block[idx] - left - 1;
        }
      }
      // cout << horz[i][j];
    }
    // cout << endl;
  }

  for (int j = 0; j < w; j++) {
    vector<int> block;
    // block.push_back(-1);
    for (int i = 0; i < h; i++) {
      if (s[i][j] == '#') block.push_back(i);
    }
    block.push_back(h);
    int left = -1;
    int idx = 0;
    for (int i = 0; i < h; i++) {
      if (block.size() == 1) {
        vert[i][j] = h;
        continue;
      }
      if (s[i][j] == '.') {
        if (i < block[idx]) {
          vert[i][j] = block[idx] - left - 1;
        } else {
          while (block[idx] < i) idx++;
          left = block[idx-1];
          vert[i][j] = block[idx] - left - 1;
        }
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      // cout << vert[i][j];
      if (s[i][j] == '.')
        ans = max(ans, horz[i][j] + vert[i][j] - 1);
    }
    // cout << endl;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
    int n, k;
    cin >> n >> k;
    int r, s, p;
    cin >> r >> s >> p;
    string t;
    cin >> t;
    vector<char> tak(n);
    for(int i = 0; i < n; i++){
        if(t.at(i) == 'r'){
            tak.at(i) = 'p';
        } else if(t.at(i) == 's'){
            tak.at(i) = 'r';
        } else if(t.at(i) == 'p'){
            tak.at(i) = 's';
        }
    }
    for(int i = 0; i < t.size()-k; i++){
        if(tak.at(i) == tak.at(i+k)){
            tak.at(i+k) = '0';
        }
    }
    int rc = 0;
    int sc = 0;
    int pc = 0;
    for(int i = 0; i < n; i++){
        if(tak.at(i) == 'r'){
            rc++;
        } else if(tak.at(i) == 's'){
            sc++;
        } else if(tak.at(i) == 'p'){
            pc++;
        }
    }
    int point = rc * r + sc * s + pc * p;
    cout << point << endl;
}

Measured memory_bytes: 512
c500 = int(input())
c100 = int(input())
c50 = int(input())
price = int(input())
ans = 0

for i in range(c500+1):
    for j in range(c100+1):
        for k in range(c50+1):
            if 500*i + 100*j + 50*k == price:
                ans += 1

print(ans)


Measured memory_bytes: 3060
#include <stdio.h>

int main(void){

  int a, b, c;
  scanf("%d %d %d",&a,&b,&c);
  if(a!=b&&b!=c&&c!=a){
    printf("No");
  }
  else if(a==b&&a==c){
    printf("No");
  }
  else{
    printf("Yes");
  }

  return 0;
}


Measured memory_bytes: 128
import java.io.*;
import java.util.*;
import java.lang.*;

class Main {

	public static void main(String[] args) {
		final FastScanner sc = new FastScanner(System.in);
		int k = sc.nextInt();
		String s = sc.next();
		if (s.length() <= k) {
			System.out.println(s);
		} else {
			System.out.println(s.substring(0, k) + "...");
		}
	}

	static class FastScanner {
		private final InputStream in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		public FastScanner(InputStream source) {
			in = source;
		}

		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: 25316
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
 size_t strlen(const char *s);
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int N=10010;
int compare_int(const void *a, const void *b)
{
    return *(long long int*)b - *(long long int*)a;
}
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}

int main(){
	int n, len, x, y;
	int ans=0;
	int bnuma[2][2]={};
//	long long int  a[N];
	char b[20];
	cin>>n;

	cout<<(n-2)*180<<endl;
//		memset(b, '\0', sizeof(b));初期化
}

Measured memory_bytes: 256
import numpy as np

n = int(input())
h = list(map(int, input().split()))

a = []

for i in range(n - 1):
    if h[i] >= h[i + 1]:
        a.append(1)
    else:
        a.append(0)

def long_repeat(line):

    max = 0
    cnt = 1

    for i in range(len(line)-1):
        if cnt > 1:
            cnt -= 1
            continue
        for j in range(i+1,len(line)):
            if line[i] == 1 and line[j] == 1:
                cnt += 1
            else:
                break
        if max < cnt:
            max = cnt

    return max

ans = long_repeat(a)

if a.count(1) == 0:
    ans = 0

print(ans)


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

int main()
{
    int A[3];
    int sum = 0;
    for (int i = 0; i < 3; i++)
    {
        cin >> A[i];
        sum += A[i];
    }
    if (sum >= 22)
    {
        cout << "bust" << endl;
    }
    else
    {
        cout << "win" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def main():
   ARR = raw_input()
   ABC = list(map(int, ARR.split()))
   A = ABC[0]
   B = ABC[1]
   C = ABC[2]
   ans = 0
   while B >= A:
      B = B - A
      ans += 1
      if ans == C:
         break;
   print(ans)
main()

Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
signed main(){
  int n,k,q,a,p[100005]={};
  cin>>n>>k>>q;
  
  for(int i=0;i<q;i++){
    cin>>a;
    p[a-1]++;
  }

  for(int i=0;i<n;i++){
    if(k+p[i]-q > 0)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }

  return(0);
}
  


Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define forr(i, a, b) for (int i = (int)(b); i >= (int)(a); --i)
#define sz(a) (int)((a).size())
 
using namespace std;

const int ooi = INT_MAX;
const long long ool = LLONG_MAX;
const int mod = 1e9 + 7;
const double PI = acos(-1);
 
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
typedef unsigned long long ui64;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

void solve(){
    int n;
    cin >> n;
    vi v(n);
    forn(i, n) cin >> v[i];
    sort(all(v));
    int res = 0;
    int m = sz(v);
    ford(i, m){
        if(v[i] >= m - i) res = m - i;
    }
    cout << res << endl;
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.precision(10); cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    int n;
    cin >> n;
    if(n & 1)
        cout << n / 2 << endl;
    else 
        cout << n / 2 - 1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
//プロトタイプ宣言
int gcd(int , int);
void often(void);
ll get_digent(ll);


int main(){
  often();
  string s;
  cin >> s;
  int cnt=0;
  rep(i,s.size())REP(j,i+1,s.size()){
    if(s[i] == s[j]) cnt++;
  }
  if(cnt == 2) cout << "Yes" << endl;
  else cout << "No" << endl;
}








































//以下、ライブラリ

int gcd(auto a, auto b) {
  return b ? gcd(b, a%b) : a;
}  //ユークリッドの互除法

void often(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

ll get_digent(ll x){
  string s;
  s = to_string(x);
  ll digent = s.size();
  return digent;
} 

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

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

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	
	public Main(){
		Scanner sc = new Scanner(System.in);
		int a,b,k;
		int w[]=new int[7];

		for(k=0;k<7;k++){
	a = sc.nextInt();
	b = sc.nextInt();
	System.out.println(a - b);
}
}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
         Main w = new Main();
	}

}

Measured memory_bytes: 17176
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
inline bool read(ll &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
int main(){
char c=gc();
puts(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'?"vowel":"consonant");
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

		static void solve() {
			Scanner sc = new Scanner(System.in);
			int n = sc.nextInt();
			int T = sc.nextInt();
			int[] c = new int[n];
			int[] t = new int[n];
			int res = 0;
			int min = Integer.MAX_VALUE;
			for(int i = 0;i<n;i++) {
				c[i] = sc.nextInt();
				t[i] = sc.nextInt();
			}
			for(int i = 0;i<n;i++) {
				if(t[i]<=T) {
					if(min>c[i]) {
					min = c[i];
					res = c[i];
					}
				}
			}
			if(res == 0) {
				System.out.println("TLE");
			}else
			System.out.println(res);
			
			sc.close();
			
		}
	public static void main(String[] args) {
		solve();
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define ri register int
namespace io {
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	// getchar
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	// print the remaining part
	inline void flush () {
		fwrite (obuf, 1, oS - obuf, stdout);
		oS = obuf;
	}
	// putchar
	inline void putc (char x) {
		*oS ++ = x;
		if (oS == oT) flush ();
	}
	// input a signed integer
	template <class I>
	inline void gi (I &x) {
		for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = (x << 1) + (x << 3) + (c & 15); x *= f;
	}
	// print a signed integer
	template <class I>
	inline void print (I x) {
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10;
		while (qr) putc (qu[qr --]);
	}
	// no need to call flush at the end manually!
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} 
using io :: gi;
using io :: putc;
using io :: print;
const int N=1e5+5,inf=2e9;
int p[N],q[N],bep[N],beq[N];
struct flow{
	int s,t,cur[N],dep[N],tot=1,head[N],nxt[N<<2],adj[N<<2],w[N<<2];
	inline void addedge(ri x,ri y,ri z){
		nxt[++tot]=head[x];
		adj[head[x]=tot]=y;
		w[tot]=z;
	}
	inline void add(ri x,ri y,ri z){
		addedge(x,y,z);
		addedge(y,x,0);
	}
	inline bool bfs(){
		ri l,r,x,y,i;
		for(i=s;i<=t;++i) dep[i]=0,cur[i]=head[i];
		q[l=r=1]=s;
		dep[s]=1;
		while(l<=r){
			x=q[l++];
			for(i=head[x];i;i=nxt[i])
				if(w[i]&&!dep[y=adj[i]])
					dep[y]=dep[x]+1,
					q[++r]=y;
		}
		return dep[t];
	}
	inline int dfs(ri x,ri now){
		if(x==t) return now;
		ri y,tmp,res=0;
		for(int &i=cur[x];i;i=nxt[i])
			if(w[i]&&dep[y=adj[i]]==dep[x]+1){
				tmp=dfs(y,min(w[i],now-res));
				w[i]-=tmp;
				w[i^1]+=tmp;
				if((res+=tmp)==now)
					return res;
			}
		return res;
	}
	inline int maxflow(){
		ri flow=0;
		while(bfs()) flow+=dfs(s,inf);
		return flow;
	}
}flow;
int main(){
	ri n,i,j,cnt,res;
	gi(n);
	for(i=1;i<=n;++i) gi(p[i]),++p[i];
	for(i=1;i<=n;++i) gi(q[i]),++q[i];
	cnt=0;
	for(i=1;i<=n;++i)
		if(!bep[i]){
			bep[i]=++cnt;
			for(j=p[i];j!=i;j=p[j])
				bep[j]=cnt;
		}
	for(i=1;i<=n;++i)
		if(!beq[i]){
			beq[i]=++cnt;
			for(j=q[i];j!=i;j=q[j])
				beq[j]=cnt;
		}
	flow.s=0;
	flow.t=++cnt;
	res=0;
	for(i=1;i<=n;++i)
		if(p[i]==i&&q[i]==i) ++res;
		else if(p[i]==i)
			flow.add(beq[i],flow.t,1);
		else if(q[i]==i)
			flow.add(flow.s,bep[i],1);
		else if(p[i]!=q[i])
			flow.add(beq[i],bep[i],1);
		else
			flow.add(bep[i],beq[i],1),
			flow.add(beq[i],bep[i],1);
	res+=flow.maxflow();
	printf("%d\n",n-res);
    return 0;
}

Measured memory_bytes: 12160
#!usr/bin/env python3
import sys
import math
import string
import collections
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = 10 ** 18
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

n = int(input())
a = [1] * n
b = [1] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())

dp = [[INF] * (n + 10) for _ in range(n + 10)]
up = [[1] * (n + 10) for _ in range(n + 10)]
down = [[1] * (n + 10) for _ in range(n + 10)]
for i in range(n):
    dp[i][i] = 0
    up[i][i] = a[i]
    down[i][i] = b[i]
for L in range(n - 2, -1, -1):
    for R in range(L + 1, n):
        dp[L][R] = min(dp[L][i] + dp[i+1][R] + up[L][i] * down[L][i] * up[i + 1][R] * down[i + 1][R] for i in range(L, R))
        for i in range(L, R):
            if dp[L][i] + dp[i+1][R] + up[L][i] * down[L][i] * up[i + 1][R] * down[i + 1][R] == dp[L][R]:
                up[L][R] = up[L][i]
                down[L][R] = down[i + 1][R]
print(dp[0][n - 1])


Measured memory_bytes: 9100
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`


		`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */

	a, b, c := nextInt(), nextInt(), nextInt()

	ans := 0
	for a%2 == 0 && b%2 == 0 && c%2 == 0 {
		na, nb, nc := (b+c)/2, (c+a)/2, (a+b)/2
		ans++
		if na == a && nb == b && nc == c {
			ans = -1
			break
		}
		a, b, c = na, nb, nc
	}

	//fmt.Fprintln(out, "[DEBUG]", a)
	fmt.Fprintln(out, ans)
}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){

  int n,m,result=0,i;

  cin>>n;
  for(i=0;i<n;i++){
    cin>>m;
    if(m%2==0 && m>2) continue;
    for(int j=2;j*j<=m;j++) if(m%j==0){
	result--;
        break;
      }
    result++;
  }

  cout<<result<<endl;
  return 0;

}

Measured memory_bytes: 3068
#include<bits/stdc++.h>
#define int long long
using namespace std;
int N,K,sum=0;
vector<int> A;
bool a(int i){
  vector<int> B(N+1);
  for(int j=0;j<N;j++)B[j]=A[j]%i;
  sort(B.begin(),B.end());
  vector<int> C(N+1);
  for(int j=0;j<N;j++)C[j]=i-B[j+1];
  for(int j=0;j<N;j++)B[j+1]+=B[j],C[N-j-1]+=C[N-j];
  for(int j=0;j<N;j++)
    if(B[j]<=K && C[j+1]<=K)return true;
  return false;
}
signed main(){
  cin>>N>>K;
  A.resize(N);
  for(int &i:A){
    cin>>i;
    sum+=i;
  }
  int mx=0;
  for(int i=sqrt(sum);i>0;i--){
    if(sum%i)continue;
    if(a(i))mx=max(mx,i);
    if(a(sum/i))mx=max(mx,sum/i);
  }
  cout<<mx<<endl;
}

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

using namespace std;

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

ll MOD = 1000000007;

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

  vi t(n), a(n);
  for (ll i = 0; i < n; i++) {
    cin >> t[i];
  }
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }

  vi x1(n, -1), y1(n, 1);

  for (ll i = 0; i < n; i++) {
    if (i == 0 || t[i] > t[i - 1]) {
      x1[i] = y1[i] = t[i];
    } else {
      x1[i] = t[i];
    }
  }

  vi x2(n, -1), y2(n, 1);

  for (ll i = n - 1; i >= 0; i--) {
    if (i == n - 1 || a[i] > a[i + 1]) {
      x2[i] = y2[i] = a[i];
    } else {
      x2[i] = a[i];
    }
  }

  ll ans = 1;
  for (ll i = 0; i < n; i++) {
    ll tmp = min(x1[i], x2[i]) - max(y1[i], y2[i]) + 1;
    if (tmp <= 0) {
      ans = 0;
    } else {
      ans = ans * tmp % MOD;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 4992
n = gets
as = gets.split(" ").map(&:to_i)
prev = nil
as.length.times do |i|
  key = as[i]
  j = i - 1
  while j >= 0 && as[j] > key
    as[j+1] = as[j]
    j -= 1
  end
  as[j+1] = key
  puts as.join(" ")
end

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

int main() {
    string s;
    cin >> s;
    int a = s[0] - '0', b = s[1] - '0', c = s[2] - '0', d = s[3] - '0';
    if (a - b - c - d == 7) printf("%d-%d-%d-%d=7\n", a, b, c, d);
    else if (a - b - c + d == 7) printf("%d-%d-%d+%d=7\n", a, b, c, d);
    else if (a - b + c - d == 7) printf("%d-%d+%d-%d=7\n", a, b, c, d);
    else if (a - b + c + d == 7) printf("%d-%d+%d+%d=7\n", a, b, c, d);
    else if (a + b - c - d == 7) printf("%d+%d-%d-%d=7\n", a, b, c, d);
    else if (a + b - c + d == 7) printf("%d+%d-%d+%d=7\n", a, b, c, d);
    else if (a + b + c - d == 7) printf("%d+%d+%d-%d=7\n", a, b, c, d);
    else if (a + b + c + d == 7) printf("%d+%d+%d+%d=7\n", a, b, c, d);

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100000
#define NIL -1
struct Node {
  int parent;
  int left;
  int right;
};
struct Node T[N];
int D[N];


void getDepth(int x,int y){
  D[x]=y;
  if(T[x].right != NIL)
    getDepth(T[x].right,y);
  if(T[x].left != NIL)
    getDepth(T[x].left,y+1);
}



int main(){
  int a,n,i,j,x;
  int id,ks,y,z;

  for(i=0;i<N;i++){
    T[i].parent=NIL;
    T[i].left=NIL;
    T[i].right=NIL;    
  }
    
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&id,&ks);
    for(j=0;j<ks;j++){
      scanf("%d",&y);
      if(j==0){
	T[id].left=y;
      }
      else{
	T[x].right=y;
      }
      x=y;
      T[y].parent=id;
    }
  }
  for(i=0;i<n;i++){
    if(T[i].parent==NIL)
      z=i;
  }
  
  getDepth(z,0);
  
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, depth = %d, ",i,T[i].parent,D[i]);
    if(T[i].parent==NIL)
      printf("root, [");
    else if(T[i].left==NIL)
      printf("leaf, [");
    else
      printf("internal node, [");

    for(j=0,a=T[i].left;a!=NIL;j++,a=T[a].right){
      if(j)
	printf(", ");
      printf("%d",a);
    }
    printf("]\n");
  }

  return 0;
}

Measured memory_bytes: 5292
#include<iostream>
using namespace std;
int main(){
  int n,a,b;
  while(cin>>a>>b>>n,n){
    int ans=0;
    while(1){
      int cnt=0;
      for(int i=2;i*i<=a;i++){
        if(a%i==0){
          cnt++;
          break;
        }
      }
      if(cnt==0&&a!=1)ans++;
      if(ans==n){
        cout<<a<<endl;
        break;
      }
      a+=b;
    }
  }
  return 0;
}

Measured memory_bytes: 2952
def q(a,h):
 d[a]=str(h)
 for b in t[a]:q(b,h+1)
t,p,d={},{},{}
for _ in[0]*int(input()):
 e=input().split()
 t[e[0]]=e[2:]
 for i in e[2:]:p[i]=e[0]
r=(set(t)-set(p)).pop()
p[r]='-1'
q(r,0)
for i in sorted(map(int,t)):
 i=str(i)
 f='root'if'-1'==p[i]else'internal node'if t[i]else'leaf'
 print(f'node {i}: parent = {p[i]}, depth = {d[i]}, {f}, {list(map(int,t[i]))}')


Measured memory_bytes: 55920
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;

int main() {
  int h, w;
  cin >> h >> w;
  char a;
  int b;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      string tmp;
      cin >> tmp;
      if (tmp == "snuke") {
	a = 'A'+j;
	b = i+1;
      }
    }
  }
  cout << a << b << endl;
  return 0;
}


Measured memory_bytes: 256
import sys

def parse(inp):
    S=list(next(inp))
    return S
  
def main(inp):
    S = inp
    zeros=0
    ones=0
    for i in range(len(S)):
        if(S[i]=='0'): zeros+=1
        elif(S[i]=='1'): ones+=1
            
    return 2*min(ones,zeros)
  
print(main(parse(sys.stdin)))

Measured memory_bytes: 3956
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.Exception
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    println(if (n >= 30) "Yes" else "No")
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


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

int main() {
	int n,i,m;
	cin>>n;
	int a[n],x=0;
	for(i=0;i<n;i++)
	cin>>a[i];
	m=a[0];
	for(i=0;i<n;i++)
	{
		if(a[i]<=m) x++;
		m=min(m,a[i]);
	}
	cout<<x;
	return 0;
}

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

using namespace std;
typedef long long ll;

int main(){
	int n; cin >> n;
	vector<int> T(n), U(n);

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

	vector<int> U_sum(n), T_sum(n);

	T_sum[0] = T[0];
	U_sum[n-1] = U[n-1];

	for(int i = 1; i < n; i++){
		T_sum[i] = T_sum[i-1] + T[i];
	}

	for(int i = n-2; i >= 0; i--){
		U_sum[i] = U_sum[i+1] + U[i];
	}

	int ans = 0;


	for(int i = 0; i < n; i++){
		int temp_ans;
		temp_ans = T_sum[i] + U_sum[i]; 
		ans = max(ans, temp_ans);
	}

	cout << ans << endl;

}

Measured memory_bytes: 256
// Itp1_6_a.java
import java.io.*;
import java.lang.Integer;
public class Main
{
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			int length = Integer.parseInt(br.readLine());
			String[] nums = (br.readLine()).split(" ");
			for( int i = length-1 ; i >= 0 ; i-- ) {
				if ( i != 0 ) {
					System.out.print(nums[i] + " ");
				} else {
					System.out.println(nums[i]);
				}
			}
		} catch ( IOException e ) {
			System.out.println("??¨??????????????????????????????");
		}
	}
}

Measured memory_bytes: 24304
#include<bits/stdc++.h>
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
using namespace std;
//#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
 
template<class T> inline bool chmin(T &a, T b){
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b){
	if(a<b){a=b;return true;}
	return false;
}
constexpr int mod = 1e9+7;
constexpr long long inf = 3e18;

struct Dinic{
	struct Edge{int to,cap,rev;};
	vector<vector<Edge>>G;
	vector<int>level,iter;
	void addEdge(int from,int to,int cap){
		G[from].push_back({to,cap,len(G[to])});
		G[to].push_back({from,0,len(G[from])-1});
	}
	void bfs(int s){
		fill(all(level),-1);
		level[s]=0;
		queue<int>que;que.push(s);
		while(len(que)){
			int p=que.front();que.pop();
			for(Edge e:G[p]){
				if(e.cap>0&&level[e.to]==-1){
					level[e.to]=level[p]+1;
					que.push(e.to);
				}
			}
		}
	}
	int dfs(int v,int t,int f){
		if(v==t)return f;
		for(int &i=iter[v];i<len(G[v]);i++){
			Edge &e=G[v][i];
			if(e.cap>0&&level[e.to]>level[v]){
				int d=dfs(e.to,t,min(f,e.cap));
				if(d>0){
					e.cap-=d;
					G[e.to][e.rev].cap+=d;
					return d;
				}
			}
		}
		return 0;
	}
	int maxFlow(int s,int t){
		int flow=0;
		while(1){
			bfs(s);
			if(level[t]<0)return flow;
			fill(all(iter),0);
			int f=0;
			while((f=dfs(s,t,mod))>0){
				flow+=f;
			}
		}
	}
	Dinic(int N):G(N),level(N),iter(N){}
};

int H,W;
char c[105][105];
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
char ans[105][105];
signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	cin>>H>>W;
	Dinic F(H*W+2);
	rep(i,H)rep(j,W){
		cin>>c[i][j];ans[i][j]=c[i][j];
		if((i+j)%2)F.addEdge(H*W,i*W+j,1);
		else F.addEdge(i*W+j,H*W+1,1);
	}
	rep(i,H)rep(j,W)if((i+j)%2&&c[i][j]=='.')rep(k,4){
		int nx=i+dx[k],ny=j+dy[k];
		if(nx<0||ny<0||nx>=H||ny>=W||c[nx][ny]=='#')continue;
		F.addEdge(i*W+j,nx*W+ny,1);
	}
	cout<<F.maxFlow(H*W,H*W+1)<<"\n";
	rep(i,H){
		rep(j,W){
			if(c[i][j]=='#'||(i+j)%2==0)continue;
			for(auto e:F.G[i*W+j])if(e.cap==0&&e.to/W<H){
				if(e.to/W==i-1){ans[i][j]='^';ans[i-1][j]='v';}
				else if(e.to/W==i+1){ans[i][j]='v';ans[i+1][j]='^';}
				else if(e.to%W==j-1){ans[i][j]='<';ans[i][j-1]='>';}
				else {ans[i][j]='>';ans[i][j+1]='<';}
				break;
			}
		}
	}
	rep(i,H){rep(j,W)cout<<ans[i][j];cout<<"\n";}
}

Measured memory_bytes: 4892
#include <bits/stdc++.h>
	#include <cstdio>
	#include <cstring>
	#include <cmath>
	#include <cstring>
	#include <chrono>
	#include <complex>
	#define endl "\n"
	#define ll long long int
	#define vi vector<int>
	#define vll vector<ll>
	#define vvi vector < vi >
	#define pii pair<int,int>
	#define pll pair<long long, long long>
	#define mod 1000000007
	#define inf 1000000000000000001;
	#define all(c) c.begin(),c.end()
	#define mp(x,y) make_pair(x,y)
	#define mem(a,val) memset(a,val,sizeof(a))
	#define eb emplace_back
	#define f first
	#define s second
	
	using namespace std;
	
	int main()
	{
		std::ios::sync_with_stdio(false);
		int T = 1;
		//cin>>T;
		// cin.ignore(); must be there when using getline(cin, s)
		while(T--)
		{
			string s;
			cin>>s;
			if(s =="ABC")
				cout<<"ARC";
			else if(s == "ARC")
				cout<<"ABC";
		}
		return 0;
	}


Measured memory_bytes: 3632
//#define _CRT_SECURE_NO_WARNINGS
//#include <bits/stdc++.h>
#include "bits/stdc++.h"

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

#define PI (3.14159265358979323)
#define MOD (1000000007LL)
#define INF (1LL<<60LL)
#define MAX_N (10000001)
#define MAX (1000000000000000000LL)
using namespace std;

signed main() {
	int n; cin >> n;
	vector<int> isprime(MAX_N, 1);
	isprime[0] = isprime[1] = 0;
	rep(i, MAX_N) {
		if (isprime[i]) {
			int k = i * 2;
			while (k < MAX_N) {
				isprime[k] = 0;
				k += i;
			}
		}
	}
	int ans = 0;
	for (int i = 1; i < MAX_N; i++) if(isprime[i]){
		int j = i;
		while (n % j == 0) {
			//cout << j << endl;
			ans++;
			n /= j;
			j *= i;
			//cout << n << endl;
		}
	}
	bool flag = true;
	if (n == 1)flag = false;
	for (int i = 2; i < MAX_N; i++) if (isprime[i]) {
		if (n % i == 0) {
			flag = false;
		}
	}
	if(flag)ans++;
	cout << ans << endl;
}

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

int main(void){
    int N;
    string S;
    cin >> N >> S;

    int count{0};
    char former{'0'};
    for(int i{0}; i<N; ++i){
        if(S[i]!=former){
            count++;
            former = S[i];
        }
    }
    cout << count << endl;


}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()

int a[26];

int main(void){
	string s;
	cin >> s;
	for(int i=0;i<s.size();i++){
			a[(int)s[i]-'a']++;
	}
	vector<int> v;
	if(s.size()==26){
        if(s == "zyxwvutsrqponmlkjihgfedcba"){
            cout << -1 << endl;
        }else{
            string t = s;
            next_permutation(t.begin(), t.end());
            for(int i=0;i<s.size();i++){
                if(s[i] == t[i]){
                    cout << s[i];
                }else{
                    cout << t[i] << endl;
                    return 0;
                }
            }
            
        }
		// for(int i=25;i>=1;i--){
		// 	if(s[i-1]<s[i]){
		// 		for(int j=0;j<i-1;j++)cout << s[j];
		// 		for(int j=i;j<26;j++){
		// 			v.push_back(s[j]);
		// 		}
		// 		sort(ALL(v));
		// 		cout << (char) v[0] << endl;
		// 		return 0;
		// 	}
		// }
		// cout << -1 << endl;
		// return 0;
	}else{
		for(int i=0;i<26;i++){
			if(a[i]==0){
				cout << s << (char)('a' + i) << endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 256
N = int(input())
c = list(input())
r, w = 0, 0
r = c.count('R')
a = r
for i in range(N):
    if c[i] == 'R':
        r -= 1
    else:
        w += 1
    ai = max(r, w)
    a = min(a, ai)
print(a)

Measured memory_bytes: 10712
def solve(h, w, d):
    col = 'RYGB'
    if d & 1:
        cols = col * (w // 4 + 2)
        buf = []
        for i in range(h):
            j = i % 4
            buf.append(cols[j:j + w])
        print('\n'.join(buf))
        return
    e = d // 2
    r = w // (2 * d) + 1
    s = []
    for i in range(1, e + 1):
        cf1 = 2 * (e - i) + 1
        cf2 = 2 * i - 1
        t = 'R' * i + 'Y' * cf1 + 'G' * cf2 + 'B' * cf1 + 'R' * (i - 1)
        s.append((t * r)[:w])
    for i in range(e, 0, -1):
        cf1 = 2 * (e - i) + 1
        cf2 = 2 * i - 1
        t = 'R' * i + 'B' * cf1 + 'G' * cf2 + 'Y' * cf1 + 'R' * (i - 1)
        s.append((t * r)[:w])
    for i in range(1, e + 1):
        cf1 = 2 * (e - i) + 1
        cf2 = 2 * i - 1
        t = 'G' * i + 'B' * cf1 + 'R' * cf2 + 'Y' * cf1 + 'G' * (i - 1)
        s.append((t * r)[:w])
    for i in range(e, 0, -1):
        cf1 = 2 * (e - i) + 1
        cf2 = 2 * i - 1
        t = 'G' * i + 'Y' * cf1 + 'R' * cf2 + 'B' * cf1 + 'G' * (i - 1)
        s.append((t * r)[:w])
    print('\n'.join(s[i % (2 * d)] for i in range(h)))


solve(*map(int, input().split()))


Measured memory_bytes: 4980
def gcd(a, b):
  return a if b == 0 else gcd(b, a%b)

def lcm(a, b):
    return (a*b)//gcd(a,b)

def solve(a, b, c, d):
    div = ((b//c) - ((a-1)//c)) + ((b//d) - ((a-1)//d)) - ((b//lcm(c,d)) -
            ((a-1)//lcm(c,d))) 

    return (b - a + 1) - div

a, b, c, d = map(int, input().split())
print(solve(a,b,c,d))


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
  long long L, R;
  cin >> L >> R;

  long long ret = 2020;
  for (long long i = L; i - L <= 2019 && i < R; ++i) {
    for (long long j = i + 1; j < i + 2019 && j <= R; ++j) {
      long long m = (i * j) % 2019;
      ret = min(m, ret);
    }
  }

  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def solve(S: str):
    total = 0
    for s in S:
        if s == '?':
            total += 1
    tri = [1]
    for i in range(1, total + 1):
        tri.append(tri[i - 1] * 3 % MOD)
    n = len(S)
    dp = [[0] * 4 for _ in range(n + 1)]
    cnt = 0
    for i in range(n):
        s = S[i]
        #dp[i + 1][0] = dp[i][0]
        #dp[i + 1][1] = dp[i][1]
        #dp[i + 1][2] = dp[i][2]
        #dp[i + 1][3] = dp[i][3]
        if s == '?':
            dp[i + 1][0] = dp[i][0]
            dp[i + 1][1] = dp[i][1] + 1
            dp[i + 1][2] = (dp[i][2] * 3 + dp[i][0] * tri[cnt] + dp[i][1] * tri[cnt - 1]) % MOD
            dp[i + 1][3] = (dp[i][3] + dp[i][2] * tri[total - cnt - 1]) % MOD
            cnt += 1
        elif s == 'A':
            dp[i + 1][0] = dp[i][0] + 1
            dp[i + 1][1] = dp[i][1]
            dp[i + 1][2] = dp[i][2]
            dp[i + 1][3] = dp[i][3]
        elif s == 'B':
            dp[i + 1][0] = dp[i][0]
            dp[i + 1][1] = dp[i][1]
            dp[i + 1][2] = (dp[i][2] + dp[i][0] * tri[cnt] + dp[i][1] * tri[cnt - 1]) % MOD
            dp[i + 1][3] = dp[i][3]
        elif s == 'C':
            dp[i + 1][0] = dp[i][0]
            dp[i + 1][1] = dp[i][1]
            dp[i + 1][2] = dp[i][2]
            dp[i + 1][3] = (dp[i][3] + dp[i][2] * tri[total - cnt]) % MOD
    #print(dp)
    ret = dp[n][3] % MOD
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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

#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pb push_back
#define pf push_front
#define eb emplace_back 
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";
#define INF 10000000000000000

// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>


// using namespace __gnu_pbds;
using namespace std;

using ll  = long long;
using vi  = vector<int>;
using pii = pair<int,int>;
using vii = vector<pii>;
using mi  = multiset<int>;
using mii = multiset<pii>;

int lcm(int a,int b) {return (a*(b/__gcd(a,b)));}

bool isprime(int n)
{
    int i;
    if(n==1) return false;
    if(n<4) return true;
    for(int i=2;i*i<=n;i++)
    {
        if(n%i==0) return false;
    }
    return true;
}



void solve()
{
    int t,n,m,i,k,r,l,u,v,w,j,s,sum=0,pos,flag=0,count=0;
    string S,T,U;
    int x,y;
    cin>>n;
    vi a(n);
    rep(i,0,n) cin>>a[i];
    map<int,int> cnt;
    bool prime[1000000+5]; 
    int mx=*max_element(all(a));
    memset(prime, true, sizeof(prime)); 
    sortA(a);
    rep(i,0,n)
    {
        cnt[a[i]]++;
    }
    rep(i,0,n)
    {
        if(prime[a[i]])
        {
            for(int j=2*a[i];j<=mx;j+=a[i])
            {
                prime[j]=false;
            }
        }
    }
    rep(i,0,n)
    {
        if(prime[a[i]]&&cnt[a[i]]==1) count++;
    }
    cout<<count;
}


signed main()
{
    #ifndef ONLINE_JUDGE 
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        if(t)cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 18228
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Iterator;
import java.util.Collections;
import java.util.Comparator;
import java.util.Random;
import java.util.Map;
import java.util.HashMap;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int sum = A + B;
		int hiku = A - B;
		int kakeru = A * B;
		int a = Math.max(sum,hiku);
		System.out.println(Math.max(a,kakeru));
	}
}

Measured memory_bytes: 23764
n = int(input())
s = [input() for i in range(n)]

import collections
ans=[]
c = collections.Counter(s).most_common()
zzz = c[0][1]
for i in range(len(c)):
    if zzz == c[i][1]:
        ans.append(c[i][0])
    else:
        break
ans.sort()
for i in ans:
    print(i)

Measured memory_bytes: 121424
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int n;
int a[maxn], b[maxn];
int main() {
	int i,x,y;
	long long c1,c2;
	scanf("%d",&n);
	for(i=1;i<=n;i++) scanf("%d",&a[i]);
	for(i=1;i<=n;i++) scanf("%d",&b[i]);
	c1 = c2 = 0;
	for(i=1;i<=n;i++) {
		x = a[i]; y = b[i];
		if(x<y) {
			if((x-y)%2==0) c1 += (y-x)/2;
			else c1 += (y+1-x)/2, c2++;
		}
		else c2 += x-y;
//		printf("c1 = %lld c2 = %lld\n",c1,c2);
	}
	if(c1>=c2) printf("Yes");
	else printf("No");
}


Measured memory_bytes: 384
using System;
namespace ITP1_3_D
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] S = Console.ReadLine().Trim().Split();
            var a = int.Parse(S[0]);
            var b = int.Parse(S[1]);
            var c = int.Parse(S[2]);
            var count = 0;
            int i;
            for(i = a; i <= b; i++)
            {
                if(c % i == 0)
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 18048
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

int main()
{
    int N, M;
    cin >> N >> M;
    priority_queue<ll> pq;
    for(int i=0; i<N; i++){
        ll tmp; cin >> tmp;
        pq.push(tmp);
    }

    for(int i=0; i<M; i++){
        ll tmp = pq.top(); pq.pop();
        pq.push(tmp/2);
    }

    ll ans = 0;
    for(int i=0; i<N; i++){
        ans += pq.top(); pq.pop();
    }

    cout << ans << endl;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int T = 3e3+23;
const int N = 3e3+23;

long long dp[N][T];
pair<int, int> a[N];
int n, t;

long long rek(int pos, int w) {
  if (w >= t) return 0;
  if (n == pos) return 0;
  long long &ret = dp[pos][w];
  if (ret != -1) return ret;
  return ret = max(rek(pos+1, w), rek(pos+1, w+a[pos].first)+a[pos].second);
}

void solve() {
  memset(dp, -1, sizeof(dp));
  scanf("%d%d", &n, &t);
  for (int i = 0; i < n; ++i) scanf("%d%d", &a[i].first, &a[i].second);
  sort(a, a+n, [](const pair<int, int> &x, const pair<int, int> &y) {
    if (x.first == y.first) return x.second > y.second;
    return x.first < y.first;
  });
  printf("%lld", rek(0, 0));
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 75424
#include <stdio.h>
int main(void){
    int t,x,y,r;
    scanf("%d %d",&x,&y);
    if(y>x){		
    	t=x;
    	x=y;
    	y=t;
    }
    while(y>0){
    	r=x%y;
    	x=y;
    	y=r;
    }	
    printf("%d\n",x);
    
    return 0;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N, K, Q;
    cin >> N >> K >> Q;

    vector<ll> A(Q);
    vector<ll> m(100010, 0);
    rep (i, Q) {
        cin >> A[i];
        A[i]--;
        m[A[i]]++;
    }

    rep (i, N) {
        if (m[i] > Q-K) {
            Yes;
        } else {
            No;
        }
    }

    return 0;
}

Measured memory_bytes: 2176