akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
// 標準入力からデータを読み込む準備
try (Scanner sc = new Scanner(System.in)) {
String line = sc.nextLine();
String answer = "";
int length = line.length();
for (int i = 0; i < length; i++) {
char ch = line.charAt(i); 
if(Character.isLowerCase(ch)==true){
  char o=Character.toUpperCase(ch);
  System.out.printf("%c",o);
}else{
char o=Character.toLowerCase(ch);
System.out.printf("%c",o);
}
}
System.out.println();



// 文字列(line)からi番目の文字を取り出す
// Character.isLowerCase で小文字かどうか判断可能
// Character.toUpperCase, Character.toLowerCase で変換
// 記号は上記メソッドで変換にかけても変化しない
}
//System.out.println(answer);
}
}



Measured memory_bytes: 29900
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, a, x;
  cin >> n >> a;

  x = n % 500;
  
  if (x == 0) {
    cout << "Yes" << endl;
  } else if (x <= a) {
    cout << "Yes" << endl; 
  } else {
    cout << "No" << endl; 
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Falun_Dafa_is_good {puts("No");return 0;}
#define Falun_Dafa_Hao {puts("Yes");return 0;}
using namespace std;

const int S=(1<<20)+5;
char buf[S],*H,*T;
inline char Get()
{
	if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
	if(H==T) return -1;return *H++;
}
inline int read()
{
	int x=0;char c=Get();
	while(!isdigit(c)) c=Get();
	while(isdigit(c)) x=x*10+c-'0',c=Get();
	return x;
}

inline void upmin(int &x,const int &y){if(y<x) x=y;}
inline void upmax(int &x,const int &y){if(y>x) x=y;}

int a[100010],n;

int main()
{
	n=read();
	int mn=n+1,mx=0;
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
		upmin(mn,a[i]);
		upmax(mx,a[i]);
	}
	if(mx>mn+1) Falun_Dafa_is_good
	if(mx==mn)
	{
		if(mn==n-1) Falun_Dafa_Hao
		if(2*mn<=n) Falun_Dafa_Hao
		else Falun_Dafa_is_good
	}
	else
	{
		int cnt=0;
		for(int i=1;i<=n;i++) cnt+=(a[i]==mn);
		if(mn<cnt) Falun_Dafa_is_good
		if(n-cnt<2*(mx-cnt)) Falun_Dafa_is_good
		else Falun_Dafa_Hao
	}
	return 0;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    
    if(a < b) cout << "a < b" << endl;
    else if(a > b) cout << "a > b" << endl;
    else cout << "a == b" << endl;
    
    return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <vector>
using namespace std;
const int MAX = 1 << 12;
const int INF = 1001001001;

int main() {
	int n, m;
	cin >> n >> m;
	int dp[MAX]; fill(dp, dp+MAX, INF);
	dp[0] = 0;
	for (int j = 1; j <= m; j++) {
		int a, b, c = 0;
		cin >> a >> b;
		for (int k = 0; k < b; k++) {
			int x;
			cin >> x;
			x--;
			c |= (1 << x);
		}
		for (int i = (1<<n)-1; i > 0; i--) {
			dp[i] = min(dp[i], a + dp[i&(~c)]);
		}
	}
	int ans = dp[(1<<n) - 1];
	if (ans >= INF) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}

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

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

int solve(vi &h, int l, int r) {
  if (l == r) return 0;
  int mi = inf, idx = -1;
  for (int i = l; i < r; i++) {
    if (mi > h[i]) {
      mi = h[i];
      idx = i;
    }
  }

  int res = mi;
  for (int i = l; i < r; i++) {
    h[i] -= mi;
  }

  res += solve(h, l, idx) + solve(h, idx + 1, r);
  return res;
}

signed main() {
  int n;
  cin >> n;
  vi h(n);
  rep (i, n) cin >> h[i];

  cout << solve(h, 0, n) << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] iaary = new long[n];
		long[] ibary = new long[n];
		long[] icary = new long[n];
		long[] kakeary = new long[n];
		long iret = 0;
		int iqx = 0;
		int iqz = 0;
        for(int i=0;i<n;i++){
        	iaary[i] = sc.nextLong();
        }
        for(int i=0;i<n;i++){
        	ibary[i] = sc.nextLong();
        }
        for(int i=0;i<n;i++){
        	icary[i] = sc.nextLong();
        }
        Arrays.sort(iaary);
        Arrays.sort(ibary);
        Arrays.sort(icary);
        iret = 0;
        
    	for(int y=0;y<n;y++){
    		for(int x=iqx;x<n;x++){
    			if(iaary[x] >= ibary[y]){
    				kakeary[y] = x;
    				x = n;
    				break;
    			}
    			if(x==n-1){
    				kakeary[y] = x + 1;
    				x = n;
    			}
    			else{
    				iqx++;
    			}
    		}
       		for(int z=iqz;z<n;z++){
    			if(ibary[y] < icary[z]){
    				kakeary[y] *= (n-z);
    				z = n;
    				break;
        		}
    			if(z==n-1){
    				kakeary[y] = 0;
    			}
    			else{
        			iqz++;
    			}
    		}
       		iret += kakeary[y];
    	}
	    System.out.println(iret);
    }
}


Measured memory_bytes: 100012
#include<cstdio>
#include<string>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#define For(i,j,k) for(ll i=j;i<=k;++i)
#define Dow(i,j,k) for(ll i=k;i>=j;--i)
#define ll long long
#define inf 1e17
using namespace std;
inline ll read()
{
	ll t=0,f=1;char c=getchar();
	while(c<'0'||c>'9')	{if(c=='-')	f=-1;c=getchar();}
	while(c<='9'&&c>='0')	t=t*10LL+c-48LL,c=getchar();
	return t*f;
}
int cnt,head[2000001],nxt[2000001],poi[2000001],k,dis[2000001],v[2000001];
bool inq[2000001];
inline void add(int x,int y,int z){poi[++cnt]=y;nxt[cnt]=head[x];head[x]=cnt;v[cnt]=z;}
inline void spfa()
{
	queue<int> q;
	For(i,0,k-1)	dis[i]=1e9;	
	For(i,1,9)	{q.push(i);inq[i]=1;dis[i]=i;}
	while(!q.empty())
	{
		int x=q.front();q.pop();inq[x]=0;
		for(int i=head[x];i;i=nxt[i])
		{
			if(dis[x]+v[i]<dis[poi[i]])
			{
				dis[poi[i]]=dis[x]+v[i];
				if(!inq[poi[i]])	q.push(poi[i]),inq[poi[i]]=1;
			}
		}
	}
	cout<<dis[0]<<endl;
}
int main()
{
	k=read();
	For(i,1,k)
		For(j,0,9)	add(i,(i*10+j)%k,j);
	spfa();
}

Measured memory_bytes: 21376
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

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


const int MAX_N = 100000;
struct UnionFind
{
  int par[MAX_N];	//親
  int height[MAX_N];	//木の深さ
  int num[MAX_N];

	//n要素で初期化
  void init (int n)
  {
    for (int i = 0; i < n; i++)
    {
      par[i] = i;
      height[i] = 0;
      num[i] = 1;
    }
  }

	//木の根を求める
  int find (int x)
  {
    if (par[x] == x)
    {
      return x;
    }
    else
    {
      return par[x] = find(par[x]);
    }
  }

	//xとyの属する集合を併合
  void unite (int x, int y)
  {
    x = find(x);
    y = find(y);
    if (x == y)
    {
      return;
    }

    if (height[x] < height[y])
    {
      par[x] = y;
      num[y] = num[x] + num[y];
    }
    else
    {
      par[y] = x;
      num[x] = num[x] + num[y];
      if (height[x] == height[y])
      {
        height[x]++;
      }
    }
  }

	//xとyが同じ集合に属するか否か
  bool same (int x, int y)
  {
    return find(x) == find(y);
  }
};

int main()
{
  ll n, m;
  cin >> n >> m;
  int a[100100], b[100100];
  for (int i = 0; i < m; i++)
  {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  reverse(a, a + m);
  reverse(b, b + m);
  UnionFind uf;
  uf.init(n);

  ll ans[100100];
  ll res = 0;
  ll start = n * (n - 1) / 2;
  ans[0] = start;
  for (int i = 0; i < m; i++)
  {
    if (uf.same(a[i], b[i]))
    {
      ans[i + 1] = start - res;
    }
    else
    {
      ll x = uf.num[uf.find(a[i])];
      ll y = uf.num[uf.find(b[i])];
      res += (x + y) * (x + y - 1) / 2 - x * (x - 1) / 2 - y * (y - 1) / 2;
      ans[i + 1] = start - res;
      uf.unite(a[i], b[i]);
    }
  }

  for (int i = 0; i < m; i++)
  {
    cout << ans[m - 1 - i] << "\n";
  }
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

vvint Q;
int n, m, q;

int dfs(int v, int id, vint &x) {
    if (id == n) {
        int sum = 0;
        rep(i,q) {
            if (x[Q[i][1]]-x[Q[i][0]] == Q[i][2]) sum += Q[i][3];
        }
        return sum;
    }
    int res = 0;
    x[id] = v;
    for (int i = v; i <= m; i++) {
        res = max(dfs(i,id+1,x),res);
    }
    return res;
}

int main() {
    cin >> n >> m >> q;
    Q.assign(q,vint(4));
    vint x(n);
    rep(i,q) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--; b--;
        Q[i] = {a,b,c,d};
    }
    int ans = 0;
    for (int i = 1; i <= m; i++) {
        ans = max(dfs(i,0,x),ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
n ,m,x = map(int,input().split())
books = []
cost = 2000000000
for i in range(n):
  books.append(list(map(int,input().split())))

for i in range(1,2**n):
  bag = []
  total = 0
  value = [0]*m
  for j in range(n):
    if (i >> j) & 1:
      bag.append(books[j])
      total += books[j][0]
      for k in range(m):
        value[k] += books[j][k+1]
  if(all([e >=x for e in value])):
    cost = min(cost,total)
    
if(cost == 2000000000):
  print(-1)
else:
  print(cost)

Measured memory_bytes: 69260
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int mx, a[100005];
ll n, bit[100005];

// iが与えられた時に、a[1]+a[2]+...+a[i]を計算する
ll sum(int i) {
    ll s = 0;
    while (i > 0) {
        s += bit[i];
        i -= i & -i; // 最後の1ビット
    }
    return s;
}

// iとxが与えられた時に、a[i]に1を足す
void add(int i) {
    while (i <= mx) {
        bit[i]++;
        i += i & -i;
    }
}

// Mediansのうち、k以上のものが n(n+1)/4 個以上あるかどうか
bool check(int k) {
    vector <int> b(n+1, 0);
    for (int i = 1; i <= n; i++) {
        if (a[i] >= k) b[i] = 1;
        else b[i] = -1;
    }

    int mn = 0;
    for (int i = 1; i <= n; i++) {
        b[i] += b[i-1];
        mn = min(mn, b[i]);
    }

    mx = 0;
    for (int i = 0; i <= n; i++) {
        b[i] += 1 - mn;
        mx = max(mx, b[i]);
    }

    ll inv = 0;
    fill(bit, bit+100005, 0);
    for (int i = 0; i <= n; i++) {
        inv += sum(b[i]);
        add(b[i]);
    }

    if (inv >= n * (n + 1) / 2 - n * (n + 1) / 4) {
        return true;
    } else {
        return false;
    }
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];

    if (n == 1) {
        cout << a[1] << "\n";
        return 0;
    }

    int l = 0, r = 1e9+1;
    while (r - l > 1) {
        int mid = (r + l) / 2;
        if (check(mid)) {
            l = mid;
        } else {
            r = mid;
        }
    }

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

Measured memory_bytes: 1796
#include<stdio.h>

int main(){
  int sum_r=0,sum_c[100]={0},sum=0;
  int i,k,r,c,input;
  
  scanf("%d %d", &r, &c);

  for(i=0;i<r;++i){
    sum_r = 0;
    for(k=0;k<c;++k){
      scanf("%d",&input);
      
      printf("%d ",input);

      sum_r+=input;
      sum_c[k]+=input;
    }
    sum+=sum_r;
    printf("%d\n",sum_r);
  }

  for(i=0;i<c;++i){
    printf("%d ", sum_c[i]);
  }
  printf("%d\n", sum);
  
  return 0;
}



Measured memory_bytes: 2104
import sys
input = sys.stdin.readline

def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    b = sum(A) / (4 * M)
    ans = 0
    for a in A:
        if a >= b:
            ans += 1
    if ans >= M:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
def main():
    from collections import deque
    import sys
    input = sys.stdin.readline
    n = int(input())
    l = list(map(int,input().split()))
    check = [[1]*n for i in range(n)]
    d =  [[min(i, n-i-1, j, n-j-1) for j in range(n)] for i in range(n)]
    
    ans = 0
    for t in l:
        t -=1
        x = t//n
        y = t%n
        check[x][y] = 0
        ans += d[x][y]
        q = deque([])
        q.append((x,y,d[x][y]))
        while q:
            bx,by,z = q.popleft()

            if bx != 0:
                if d[bx-1][by] > z:
                    d[bx-1][by] = z
                    q.append((bx-1,by,z+check[bx-1][by]))
            if bx != n-1:
                if d[bx+1][by] > z:
                    d[bx+1][by] = z
                    q.append((bx+1,by,z+check[bx+1][by]))
            if by != 0:
                if d[bx][by-1] > z:
                    d[bx][by-1] = z
                    q.append((bx,by-1,z+check[bx][by-1]))
            if by != n-1:
                if d[bx][by+1] > z:
                    d[bx][by+1] = z
                    q.append((bx,by+1,z+check[bx][by+1]))  
    print(ans)
if __name__ =="__main__":
    main()

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

using namespace std;
using ll = long long int;

class UF {
    public:
        vector<int> p, sz;
        UF(size_t n) : p(n), sz(n) {
            for(size_t i=0; i<n; i++)
                p[i] = i, sz[i] = 1;
        };
        int find(int x) {
            if(p[x] == x) return x;
            return p[x] = find(p[x]);
        };
        void unite(int x, int y) {
            x = find(x);
            y = find(y);
            if(x == y) return;
            sz[y] += sz[x];
            p[x] = y;
        };
};


int main(void) {
    constexpr ll MOD = 1e9 + 7;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(16);
    cin.tie(0); ios::sync_with_stdio(false);

    ll n, m;
    cin >> n >> m;
    vector<tuple<ll,ll>> es(m);
    for(auto &e: es) {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        e = make_tuple(a, b);
    }

    vector<tuple<ll,ll>> used, unused;

    UF uf(n);
    vector<ll> idx(n);
    for(auto &e: es) {
        ll a, b;
        tie(a, b) = e;
        if(uf.find(a) == uf.find(b)) {
            idx[a] ^= 1;
            used.push_back(e);
        } else {
            uf.unite(a, b);
            unused.push_back(e);
        }
    }

    vector<vector<ll>> G(n);
    for(auto &e: unused) {
        ll a, b;
        tie(a, b) = e;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    {
        vector<tuple<ll,ll>> res;
        auto dfs = [&](auto dfs, ll cur, ll pre) -> ll {
            ll s = idx[cur];
            for(auto &v: G[cur]) {
                if(v == pre) continue;
                s ^= dfs(dfs, v, cur)^1;
            }
            if(s)
                res.push_back(make_tuple(cur, pre));
            else if(pre > -1)
                res.push_back(make_tuple(pre, cur));
            return s;
        };

        if(dfs(dfs, 0, -1)) {
            cout << -1 << endl;
            return 0;
        }

        for(auto &e: used)
            cout << get<0>(e)+1 << ' ' << get<1>(e)+1 << endl;
        for(auto &e: res)
            cout << get<0>(e)+1 << ' ' << get<1>(e)+1 << endl;
    }
}


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

using namespace std;

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<int, int> pi;

int a[501][501];

int main()
{
    int n, m;
    cin >> n >> m;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            cin >> a[i][j];
        }
    }
    vector<pair<pi, pi> > v;
    int t = 0;
    for(int i=1; i<=n; i++){
        for(int j=1; j<m; j++){

            t += (a[i][j]%2);
            if(t%2){
                v.push_back({{i, j}, {i, j+1}});
            }
        }
        if(i==n)break;

        t += (a[i][m]%2);
        if(t%2){
            v.push_back({{i, m},{i+1, m}});
        }
        i++;
        for(int j=m; j>1; j--){
            t += (a[i][j]%2);
            if(t%2){
                v.push_back({{i, j}, {i, j-1}});
            }
        }
        if(i==n)break;
        t += (a[i][1]%2);
        if(t%2){
            v.push_back({{i, 1},{i+1, 1}});
        }
    }
    cout << v.size() << "\n";
    for(auto x: v){
        cout << x.first.first << " " << x.first.second << " " << x.second.first << " " << x.second.second << "\n";
    }

    return 0;
}


Measured memory_bytes: 5104
#include <bits/stdc++.h>
#define ll long long
#define FAST {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pll pair<ll,ll>
#define LB lower_bound
#define UB upper_bound
#define endl "\n"
using namespace std;


int main()
{
    FAST
    string s[4];
    s[0]="AC";
    s[1]="WA";
    s[2]="TLE";
    s[3]="RE";
    map<string ,int> m;
    ll n;cin>>n;
    string t;
    f(i,0,n)
    {
        cin>>t;
        m[t]++;
    }
    f(i,0,4)
    {
        cout<<s[i]<<" x "<<m[s[i]]<<endl;
    }
}


Measured memory_bytes: 3664
// package coffee.acupof.atcoder.solution.abc162.e

import kotlin.ranges.step

const val mod = 1000000007L

fun pow(x: Long, n: Long): Long {
    return when {
        n == 0L -> 1
        n % 2 == 0L -> {
            val y = pow(x, n/2)
            (y * y) % mod
        }
        else -> {
            val y = pow(x, n/2)
            ((x * y) % mod * y) % mod
        }
    }
}

fun main() {
    val (n, k) = readLine()!!
        .split(" ")
        .map { it.toLong() }

    val memo = Array(k.toInt() + 1) { 0L }

    for (i in k downTo 1) {
        val x = (k / i)
        var m = pow(x, n)
        for (j in (i * 2)..k step i) {
            m = (m + mod - memo[j.toInt()]) % mod
        }
        memo[i.toInt()] = m
    }

    var answer = 0L
    for (j in 1..k) {
        answer =  (answer + j * memo[j.toInt()]) % mod
    }
    println(answer)
}

Measured memory_bytes: 51980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;

int main(){
      ll x,y,z,k;
      cin>>x>>y>>z>>k;
      ll a[x],b[y],c[z];
      rep0(i,x) cin>>a[i];
      rep0(i,y) cin>>b[i];
      rep0(i,z) cin>>c[i];
      vector<ll> pos;
      rep0(i,x) rep0(j,y) pos.push_back(a[i]+b[j]);
      sort(pos.begin(),pos.end());
      reverse(pos.begin(),pos.end());
      vector<ll> ans;
      ll kk=min((ll)pos.size(),k);
      rep0(i,kk)rep0(j,z) ans.push_back(pos[i]+c[j]);
      sort(ans.begin(),ans.end());
      reverse(ans.begin(),ans.end());
      rep0(i,k){
            cout<<ans[i]<<endl;
      }
      return 0;
}

Measured memory_bytes: 42596
#include <stdio.h>
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define N 100
int n,M[N][N];
int color[N],d[N],f[N],tt;
void dfs_b(int u){
        int i,j,v;
        color[u]=GRAY;
        d[u]= ++tt;
        for(v=0; v<n; v++) {
                if(M[u][v]==0) {
                        continue;
                }
                if(color[v]==WHITE) {
                        dfs_b(v);
                }
        }
        color[u]=BLACK;
        f[u]=++tt;
}
void dfs_a(){
        int u;
        for(u=0; u<n; u++) {
                color[u]=WHITE;
        }
        tt=0;
        for(u=0; u<n; u++) {
                if(color[u]==WHITE) {
                        dfs_b(u);
                }
        }
        for(u=0;u<n;u++){
          printf("%d %d %d\n",u+1,d[u],f[u]);
        }

}
int main(){
        int u,k,v;
        int i,j;


        scanf("%d",&n);
        for(i=0; i<n; i++) {
                for(j=0; j<n; j++) {
                        M[i][j]=0;
                }
        }
        for(i=0; i<n; i++) {
                scanf("%d%d",&u,&k);
                u--;
                for(j=0; j<k; j++) {
                        scanf("%d",&v);
                        v--;
                        M[u][v]=1;
                }
        }
        dfs_a();
        // for(i=0; i<n; i++) {
        //         for( j=0; j<n; j++) {
        //                 printf("%d",M[i][j]);
        //                 if(j==n-1)
        //                         printf("\n");
        //                 else
        //                         printf(" ");
        //         }
        //
        // }
        return 0;
}



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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};

string grid[105];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, m;
    cin >> n >> m;
    for (int i=0; i<n; i++)
        cin >> grid[i];

    mf_graph<int> mf(n * m + 2);
    for (int i=0; i<n; i++)
        for (int j=0; j<m; j++) {
            if (grid[i][j] == '#')
                continue;
            if ((i + j) % 2) {
                mf.add_edge(n * m, i * m + j, 1);
                for (int d=0; d<4; d++)
                    if (0 <= i + dr[d] && i + dr[d] < n && 0 <= j + dc[d] && j + dc[d] < m && grid[i + dr[d]][j + dc[d]] == '.')
                        mf.add_edge(i * m + j, (i + dr[d]) * m + j + dc[d], 1);
            } else {
                mf.add_edge(i * m + j, n * m + 1, 1);
            }
        }

    cout << mf.flow(n * m, n * m + 1) << "\n";
    auto edges = mf.edges();
    for (auto &e : edges)
        if (e.from != n * m && e.to != n * m + 1 && e.flow > 0) {
            int r0 = e.from / m, c0 = e.from % m, r1 = e.to / m, c1 = e.to % m;
            if (r0 > r1 || c0 > c1) {
                swap(r0, r1);
                swap(c0, c1);
            }
            if (r1 == r0 + 1) {
                grid[r0][c0] = 'v';
                grid[r1][c1] = '^';
            } else {
                grid[r0][c0] = '>';
                grid[r1][c1] = '<';
            }
        }

    for (int i=0; i<n; i++)
        cout << grid[i] << "\n";

    return 0;
}


Measured memory_bytes: 5644
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 9e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

ll dp[22][1<<21];

class OMatching {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int n;
	    in >> n;
	    vector<vector<int>> a(n, vector<int>(n));
	    for(int i=0; i<n; i++){
	        for(int j=0; j<n; j++){
	            in >> a[i][j];
	        }
	    }

	    for(int i=0; i<21; i++){
	        for(int j=0; j<(1<<21); j++){
	            dp[i][j] = 0;
	        }
	    }

	    dp[0][0] = 1;
	    for(int i=0; i<n; i++){
	        for(int msk=0; msk<(1<<n); msk++){
	            if(i == __builtin_popcount(msk)) {
                    for(int j=0; j<n; j++){
                        if(!(msk & 1<<j) && a[i][j]){
                            dp[i+1][msk | 1<<j] += dp[i][msk];
                            dp[i+1][msk | 1<<j] %= mod;
                        }
                    }
                }
	        }
	    }

	    out << dp[n][(1<<n) - 1] << endl;
	}
};


int main() {
	OMatching solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 346368
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n,c,k,t[N];
int ok(int num)
{
    int last = t[0],tot = 1,pass = 1;
    for (int i = 1;i < n;i++)
    {
        if (t[i] - last > k||pass == c)
        {
            pass = 1;
            tot++;
            last = t[i];
        } else pass++;
    }
    return tot<=num;
}
int ask(int l,int r)
{
    if (l == r) return l;
    int mid = (l+r) >> 1;
    if (ok(mid)) return ask(l,mid);
    else return ask(mid+1,r);
}
int main()
{
    cin >> n >> c >> k;
    for (int i = 0;i < n;i++) scanf("%d",t+i);
    sort(t,t+n);
    int ans = ask(1,n);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 640
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readInteger()
    val hList = readIntegerList().toIntArray()
    var ans = 0
    while (true) {
        val noneZeroCount = hList.count { it > 0 }
        if (noneZeroCount == 0) break

        var left = 0
        while (left < n - 1 && hList[left] == 0) left++

        var right = left
        while (right < n && hList[right] > 0) right++

        for (i in left until right) hList[i]--

        ans++
    }
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


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

int main(){
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    int c;
    rep(i, a+b+1){
        if(i==a){
            if(s[i]!='-'){
                cout << "No" << endl;
                return 0;
            }
        }else{
            c = (int)(s[i] - '0');
            if(c<0 || c>9){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
A = list(map(int,input().split()))
A.sort()

k = A[0]
l = A[1]
m = A[2]

if (2*m - k - l) % 2 == 0:
    print(int(m - (l+k)/2))
else:
    print(int(1 + m - (l + k - 1)/2))

Measured memory_bytes: 3060
#include<stdio.h>

int main()
{
	int d, n, m, i;
	scanf("%d%d", &d, &n);
	m = 1;
	for (i = 0; i < d; i++)
	{
		m = m * 100;
	}
	if (n == 100)
	{
		n++;
	}
	printf("%d", (m*n));
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
unsigned long a;
int n;
main()
{
	cin>>n;
	for(;n--;)
	{
		int t;cin>>t;
		if(t==0)
		{
			int b;cin>>b;
			cout<<(a>>b&1)<<endl;
		}
		else if(t==1)
		{
			int b;cin>>b;
			a|=1L<<b;
		}
		else if(t==2)
		{
			int b;cin>>b;
			a&=~(1L<<b);
		}
		else if(t==3)
		{
			int b;cin>>b;
			a^=1L<<b;
		}
		else if(t==4)
		{
			cout<<(__builtin_popcountl(a)==64)<<endl;
		}
		else if(t==5)
		{
			cout<<!!a<<endl;
		}
		else if(t==6)
		{
			cout<<!a<<endl;
		}
		else if(t==7)
		{
			cout<<__builtin_popcountl(a)<<endl;
		}
		else cout<<a<<endl;
	}
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b=0,c=0;cin >> a;
    string s;cin >> s;
    for (int i=0;i<a;i++){
        if (s[i]=='I'){
            c++;
        }
        else if (s[i]=='D'){
            c--;
        }
        if (b<c){
            b=c;
        }
    }
    cout << b;
}

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

typedef pair<int, int> P;

int main() {

    ll n,m;
    cin >> n >> m;
    ll r[m],l[m];
    rep(i,m){
        cin >> l[i] >> r[i];
    }

    ll L = 0, R = 1e9;
    rep(i,m){
        if(l[i]>L){
            L = l[i];
        }
        if(r[i]<R){
            R = r[i];
        }
    }

    ll ans = R - L + 1;
    if(ans < 0) ans = 0;
    cout << ans << endl;

    return 0;
}

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

// 1～nまでの整数でbで割った余りがk以上となるものの数を算出
ll f(ll b, ll k, ll n) {
	if (k==0) return n;
	ll d = n / b;
	ll r = n % b;
	ll cnt_low = d*k + min(r+1,k) - 1;
	return n - cnt_low;
}

int main() {
	ll n,k;
	cin >> n >> k;
	ll ans = 0;
	for(ll b=k+1;b<=n;b++) {
		ans += f(b,k,n);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int Read(void)
{
	char ch;
	int sum=0;
	ch=getchar();
	while((ch<='9'&&ch>='0')||ch==' ')
	{
		if(ch!=' ')
			sum=sum*10+ch-'0';
		ch=getchar();
	}
	return sum;
}
int main()
{
	int a=Read();
	int t=sqrt(a);
	if(t*t==a)
		return!(cout<<"Yes\n");
	return!(cout<<"No\n");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back()
#define INF 1000000000

using namespace std;

const int mod = 1e9+7;
int check[1000010];
int main(){
	
	int x;
	cin>>x;
	vector<int>ve(x+1);
	int mn = 0;
	for(int i = 0; i < x;i++){
		cin>>ve[i];
		mn = max(mn, ve[i]);
	}
	
	for(int i = 0; i < x;i++){
		for(int j = 1; j <= mn/ve[i];j++){
			if(check[j*ve[i]] == 1 || check[j*ve[i]] == -1) check[j*ve[i]] = -1;
			else if(j == 1) check[j*ve[i]] = 1;
			else  check[j*ve[i]] = -1;
		}
	}
	int k = 0;
	for(int i = 0; i < x;i++) if(check[ve[i]] == 1) k++;
	
	cout<<k<<endl;
	
	
}


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

const int MAX = 100100;
const ll INF = 1LL<<60;

int main() {
  int n, w;
  cin >> n >> w;
  vector<int> weight(n), value(n);
  rep(i,n) cin >> weight[i] >> value[i];
  vector<vector<ll>> dp(n+1, vector<ll>(MAX, INF));
  dp[0][0] = 0;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j <= MAX; j++) {
      if(j - value[i] >= 0) {
        dp[i+1][j] = min(dp[i+1][j], dp[i][j-value[i]] + weight[i]);
      }
      dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
    }
  }
  ll ans = 0;
  rep(i,MAX) {
    if(dp[n][i] <= w) ans = i;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
	int k; cin>>k;
	string s; cin>>s;
	
	if(s.size()<=k)
		cout<<s<<endl;
	else{
		string sub = s.substr(0, k);
		sub+="...";
		cout<<sub<<endl;
	}
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define inf 0x3f3f3f3f
#define debug(x) cout << #x << " = " << x << endl
#define Debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;

typedef double db;
typedef long long ll;
typedef long double ldb;
typedef pair<int,int> PII;
#define fir first
#define sec second

inline void File(){
#ifndef ONLINE_JUDGE
	freopen("AT2672.in","r",stdin);
	freopen("AT2672.out","w",stdout);
#endif
}

template<typename T>inline void read(T &_)
{
	_=0;T __=getchar(),___=1;
	while(!isdigit(__)){if(__=='-')___=-1;__=getchar();}
	while(isdigit(__)){_=(_<<1)+(_<<3)+(__^'0');__=getchar();}
	_*=___;
}

template<typename T>inline bool Chkmax(T &_,T __){return _<__?_=__,1:0;}
template<typename T>inline bool Chkmin(T &_,T __){return _>__?_=__,1:0;}

const int N=1e5+1e2;

priority_queue<int,vector<int>,greater<int> >q;

struct node{
	int x,y,z;
	inline void Input(){
		read(x),read(y),read(z);
	}
	bool operator < (const node &ch)const{
		return x-y == ch.x-ch.y ? y>ch.y : x-y<ch.x-ch.y; 
	}

}a[N];

int x,y,z;
ll totc,Ans;
ll Left[N];
int main()
{
	//File();
	read(x),read(y),read(z);
	int n=x+y+z;
	for(int i=1;i<=n;i++)
		a[i].Input(),totc+=a[i].z;
	sort(a+1,a+1+n);
	ll sum=0;
	for(int i=1;i<=y;i++){
		sum+=a[i].y-a[i].z;
		q.push(a[i].y-a[i].z);
	}
	for(int i=y+1;i<=n-x;i++){
		Left[i]=sum;
		q.push(a[i].y-a[i].z);
		sum-=q.top();
		sum+=a[i].y-a[i].z;
		q.pop();
	}
	Left[n-x+1]=sum;
	while(!q.empty())q.pop();
	sum=0;
	for(int i=n;i>=n-x+1;i--){
		sum+=a[i].x-a[i].z;
		q.push(a[i].x-a[i].z);
	}
	for(int i=n-x;i>=y;i--){
		Chkmax(Ans,Left[i+1]+sum+totc);
		q.push(a[i].x-a[i].z);
		sum-=q.top();
		sum+=a[i].x-a[i].z;
		q.pop();
	}
	printf("%lld\n",Ans);
	return 0;
}


Measured memory_bytes: 2176
#ITP1_9_A
c=0
W=input().lower()
while True:
  T=input()
  if T == "END_OF_TEXT":
    break
  L=T.lower()
  L=L.split(" ")
  for i in range(len(L)):
    if W==L[i]:
      c += 1
    
print(c)
  


Measured memory_bytes: 5560
#include<iostream>
using namespace std;
int main(void)
{
    int k;string s;
    cin>>k>> s;
    if(s.size()<=k)
    {
        cout << s;
        return 0;
    }
    for(int i=0;i<k;i++)
        cout <<s[i];
    cout << "...";
    return 0;
}


Measured memory_bytes: 3624
import itertools
import math
from collections import defaultdict

def input_ints():
    return list(map(int, input().split()))

def solve():
    s = input()
    x = int(s[:2])
    y = int(s[2:])
    ans = 0
    if 1 <= x <= 12:
        ans |= 1
    if 1 <= y <= 12:
        ans |= 2
    print(['NA', 'MMYY', 'YYMM', 'AMBIGUOUS'][ans])

if __name__ == '__main__':
    solve()


Measured memory_bytes: 3444
s = input()
t = input()
dic1 = {}
dic2 = {}
for i in range(len(s)):
    if dic1.get(s[i]) == None:
        dic1[s[i]] = t[i]
    elif dic1[s[i]] != t[i]:
        print("No")
        exit()
    if dic2.get(t[i]) == None:
        dic2[t[i]] = s[i]
    elif dic2[t[i]] != s[i]:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s[3];
    cin >> s[0] >> s[1] >> s[2];
    int len[3];
    len[0] = s[0].length();
    len[1] = s[1].length();
    len[2] = s[2].length();
    int turn = 0, next;
    char ans;
    while(1){
        if(len[turn] == 0) {ans = turn + 'A'; break;}
        next = s[turn][0] - 'a';
        if(len[turn] > 1) s[turn] = s[turn].substr(1);
        else s[turn] = "";
        len[turn]--;
        turn = next;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
#define pi acos(-1)
#define fastIO_ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
int main()
{
    fastIO_
    double r;
    cin>>r;
    printf("%.9lf\n", 2*pi*r);
    return 0;
}

Measured memory_bytes: 3804
#include <stdio.h>

int main() {
  int W, H, x, y, r;
  scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
  if (x-r < 0 || x+r > W || y-r < 0 || y+r > H) {
    puts("No");
  } else {
    puts("Yes");
  }
  return 0;
}



Measured memory_bytes: 2104
#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define btinpct(x) __builtin_popcountll((x))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?b:gcd(b%a,a); }

#define ll long long int 
#define ld long double
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
typedef pair <ll, ll> pi; typedef pair <ll, pi> spi; typedef pair <pi, pi> dpi;

#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
// #define cerr if(0)cout
#define MAXN (100006)
ll pA[MAXN], pB[MAXN];
void in(ll &x) {
	x=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=(x<<3)+(x<<1)+ch-48;
		ch=getchar();
	}
}
int main()
{
	FAST
	char ch; ch=getchar();
	ll co = 1;
	while(ch=='A'||ch=='B') {
		pA[co] = pA[co-1] + (ch == 'A' ? 1 : 2);
		++ co;
		ch=getchar();
	}
	ch=getchar();
	co = 1;
	while(ch=='A'||ch=='B') {
		pB[co] = pB[co-1] + (ch == 'A' ? 1 : 2);
		++ co;
		ch=getchar();
	}
	ll q; in(q);
	FOR(i,0,q-1) {
		ll a, b, c, d; in(a), in(b), in(c), in(d);
		if((pA[b] - pA[a-1])%3 == (pB[d] - pB[c-1])%3) cout<<"YES\n";
		else cout<<"NO\n";
	}
}


Measured memory_bytes: 2176
n = int(input())
ar = list(map(int,input().split(" ")))
br = [0]
for i in range(n):
    if i == 1:
        br.append(abs(ar[i-1] - ar[i]))
    elif i != 0:
        a = br[-2] + abs(ar[i-2] - ar[i]) 
        b = br[-1] + abs(ar[i-1] - ar[i]) 
        br.append(min(a,b))
print(br[-1])
    

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

const int INF = 0x3f3f3f3f;
const int MAXW = 112345;
const int MAXN = 112;

int n, w_max;
long long int w[MAXN], v[MAXN];
long long int pd[MAXN][MAXW];

long long int rec(int cur, int available)
{
	if(available<0)
		return -INF;

	if(cur>=n)
		return 0;

	if(available==0)
		return 0;

	if(pd[cur][available]!=-1)
		return pd[cur][available];

	return pd[cur][available] = max(v[cur]+rec(cur+1,available-w[cur]), rec(cur+1,available));
}

int main() {
	memset(pd, -1 , sizeof(pd));

	cin >> n >> w_max;

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

	cout << rec(0, w_max) << endl;

	return 0;
}

Measured memory_bytes: 98560
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

string tp[1010];
ll dp[1010];
vector<int> G[1010];

ll solve(int cur) {
    vector<ll> vals;
    for(auto to : G[cur]) {
        auto v = solve(to);
        vals.emplace_back(v);
    }

    ll res;
    if(tp[cur][0] == 'E') {
        res = 1;
        for(auto v : vals) (res *= v) %= MOD;
        if(tp[cur].size() > 1) (res += 1) %= MOD;
    }
    if(tp[cur][0] == 'A') {
        res = 0;
        for(auto v : vals) (res += v) %= MOD;
        if(tp[cur].size() > 1) (res += 1) %= MOD;
    }
    if(tp[cur][0] == 'R') {
        res = 1;
        for(auto v : vals) (res *= 1 + v) %= MOD;
        if(tp[cur].size() == 1) (res += MOD - 1) %= MOD;
    }
    // fprintf(stderr, "solve %d: %lld\n", cur, res);
    return res;
}
 
int main() {
    int N; cin >> N;
    for(int i=0; i<N; i++) {
        cin >> tp[i];
    }

    for(int i=0; i<N-1; i++) {
        int s, t; cin >> s >> t;
        s--; t--;
        G[s].emplace_back(t);
    }

    cout << solve(0) << endl;
    return 0;
}



Measured memory_bytes: 3292
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int hoge[1010];

int main() {
	int n,m;bool fir=true;
	while(n=in(),m=in()){
		if(!fir)cout<<endl;
		fir=false;
		int i;bool na=true;
		for(i=n;i<=m;i++){
			if(i%4?false:i%100?true:i%400?false:true){
				cout<<i<<endl;
				na=false;
			}
		}
		if(na)cout<<"NA\n";
	}
	return 0;
}

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

int main(){
 int N,M,p;
  cin>>N>>M>>p;
  vector<int>vec={N,M,p};
  
  	sort(vec.begin(), vec.end());
  cout<< vec.at(0)+vec.at(1) <<endl;
  
  
}

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

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

int main()
{
  int n,d,temp;
  cin>>n>>d;
  if(n<=d){cout<<1;return 0;}
  temp = 2*d + 1;
  if(n%temp==0){cout<<n/temp;}
  else {
    cout<< (n/temp)+1;
  }
}


Measured memory_bytes: 256
N = int(input())

c = 0

flg = "No"

for i in range(N):
    a,b = map(int,input().split())
    if a == b:
        c  = c + 1
    else:
        c = 0
    if c == 3:
        flg = "Yes"
        break
        
print(flg)
    

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

vector<vector<int>> G;
vector<int> d;
vector<bool> seen;
vector<bool> finished;
bool cycle;

void dfs(int v) {
    if (finished[v]) return;
    seen[v] = true;

    for (auto nv : G[v]) {
        if (seen[nv] && !finished[nv]) {
            cycle = true;
            return;
        }
        dfs(nv);
        if (cycle) return;

        chmax(d[v], d[nv] + 1);
    }

    finished[v] = true;
}


int main(){
    int n;
    cin >> n;
    int size = n * (n-1) / 2 + 1;
    G.resize(size);
    int a;
    for (int i = 0; i < n; ++i) {
        int now = 0;
        int next;
        for (int j = 0; j < n-1; ++j) {
            cin >> a;
            a--;
            if (i < a) next = a * (a-1) / 2 + i + 1;
            else next = i * (i-1) / 2 + a + 1;
            G[now].push_back(next);
            now = next;
        }
    }

    d.assign(size, 0);
    seen.assign(size, false);
    finished.assign(size, false);

    dfs(0);
    if (cycle) {
        cout << -1 << endl;
    } else {
        cout << d[0] << endl;
    }
}

Measured memory_bytes: 32780
#include<iostream>
#include<complex>
#include<vector>
#include<algorithm>
#include<cstdio>

using namespace std;

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

#define X real()
#define Y imag()

typedef complex<double> P;

vector<pair<P, P> > p;
vector<double> xx;

int main() {
  int n;
  for (int iii = 1;; ++iii) {
    cin >> n;
    if (n == 0) break;
    p.clear();
    xx.clear();
    rep (i, n) {
      double x, y, r;
      cin >> x >> y >> r;
      p.push_back(make_pair(P(x - r, y - r), P(x + r, y + r)));
      xx.push_back(x - r);
      xx.push_back(x + r);
    }
    sort(xx.begin(), xx.end());
    double res = 0;
    rep (i, xx.size() - 1) {
      vector<pair<double,int> > imos;
      double m = (xx[i] + xx[i + 1]) / 2;
      rep (j, n) {
	if (p[j].first.X <= m && m <= p[j].second.X) {
	  imos.push_back(make_pair(p[j].first.Y, 1));
	  imos.push_back(make_pair(p[j].second.Y, -1));
	}
      }
      sort(imos.begin(), imos.end());
      int im = 1;
      rep (j, imos.size() - 1) {
	if (im > 0) {
	  res += (xx[i + 1] - xx[i]) * (imos[j + 1].first - imos[j].first);
	}
	im += imos[j + 1].second;
      }
    }
    printf("%d %.2lf\n", iii, res);
  }
}

Measured memory_bytes: 0
//D
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+10;
ll suf[maxn][3];
string s;
int main(){
	int n;
	cin >> n >> s;
	for(int i = n-1;i >= 0;i--){
		for(int j = 0;j <= 2;j++)suf[i][j] = suf[i+1][j];
		if(s[i] == 'R')suf[i][0]++;
		if(s[i] == 'G')suf[i][1]++;
		if(s[i] == 'B')suf[i][2]++;
	}
	ll ans = 0;
	for(int i = 0;i < n;i++)
		for(int j = i+1;j < n;j++)if(s[i] != s[j]){
			int d = 3;
			if(s[i] == 'R'){
				if(s[j] == 'G')d = 2;
				else d = 1;
			}
			else if(s[i] == 'G'){
				if(s[j] == 'R')d = 2;
				else d = 0;
			}
			else if(s[i] == 'B'){
				if(s[j] == 'R')d = 1;
				else d = 0;
			}
			ans += suf[j+1][d];
			if(j+j-i < n and s[j+j-i] != s[i] and s[j+j-i] != s[j])ans--;
		}
	cout << ans;
	return 0;
}


Measured memory_bytes: 3664
# frozen_string_literal: true

n = gets.to_i
a = []
b = []
n.times do
  ab = gets.split.map(&:to_i)
  a.push ab[0]
  b.push ab[1]
end

a.sort!
b.sort!

m = n.odd? ? n/2 : n/2 - 1
if n.odd?
  puts b[m] - a[m] + 1
else
  puts b[m + 1] + b[m] - a[m + 1] - a[m] + 1
end


Measured memory_bytes: 20500