akhauriyash/Code-Regression huggingface dataset:
public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		java.util.Scanner scan = new java.util.Scanner(System.in);
		java.lang.StringBuilder sb = new java.lang.StringBuilder();

		java.lang.String str = scan.nextLine();
		int q = scan.nextInt();
		scan.nextLine();
		//System.out.println(str);
		for (int i = 0; i < q; i++) {
			String meirei = scan.next();
			switch (meirei) {
			case "print":
				int a = scan.nextInt();
				int b = scan.nextInt();
				System.out.println( str.substring(a, b+1) );
				scan.nextLine();
				break;
			case "reverse":
				int aa = scan.nextInt();
				int bb= scan.nextInt();
				String substr = str.substring(aa, bb+1);
				java.lang.StringBuilder subsb = new StringBuilder();
				subsb.append(substr).reverse();
				str = str.substring(0, aa) + subsb.toString() + str.substring(bb+1);
				scan.nextLine();
				break;
			case "replace":
				int aaa = scan.nextInt();
				int bbb = scan.nextInt();
				String p = scan.next();
				str = str.substring(0, aaa) + p + str.substring(bbb+1);
				break;
			}
//			if ( "print".equals( meirei ) ) {
//				int a = scan.nextInt();
//				int b = scan.nextInt();
//				System.out.println( str.substring(a, b+1) );
//				scan.nextLine();
//			} else if ( "reverse".equals( meirei ) ) {
//				int a = scan.nextInt();
//				int b = scan.nextInt();
//				String substr = str.substring(a, b+1);
//				java.lang.StringBuilder subsb = new StringBuilder();
//				subsb.append(substr).reverse();
//				str = str.substring(0, a) + subsb.toString() + str.substring(b+1);
//				scan.nextLine();
//				//System.out.println(str);
//			} else if ( "replace".equals( meirei ) ) {
//				int a = scan.nextInt();
//				int b = scan.nextInt();
//				String p = scan.next();
//				str = str.substring(0, a) + p + str.substring(b+1);
//				System.out.println(str);
//			}
		}
	}

}

Measured memory_bytes: 29392
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

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

const int MAXM = 7, MAXB = 10, MAXN = 1001, MAXC = 71;

int dp[MAXM + 1][MAXN + 10];//dp[i][j] i番目までのカードでjを作る場合の数
int a[MAXM];
int b[MAXM];


int m;

int main()
{
    while(cin >> m && m)
    {
        REP(m){cin >> a[i] >> b[i];}

        memset(dp, 0, sizeof(dp));
        dp[0][0] = 1;

        REP(m)rep(j,MAXN)
        {
            dp[i+1][j] += dp[i][j];
            for(int k = 1;k <= b[i];k++)if(j+ a[i]*k <= MAXN)
                dp[i+1][j+a[i] * k] += dp[i][j];

        }
        int g, n;
        cin >> g;
        REP(g)
        {
            cin >> n; cout << dp[m][n] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 0
S = str(input())
N = len(S) - 1

res = 0

for i in range(1<<N):
    t = ''
    for j in range(N):
        t += S[j]
        if((i>>j&1) > 0): t += '+'
    t += S[-1]
    res += eval(t)
print(res)

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


int main() {
  int a,b,c,d,l,r;cin>>a>>b>>c>>d;
  l=a+b;r=c+d;
  if(l>r)cout<<"Left"<<endl;
  else if(l<r)cout<<"Right"<<endl;
  else cout<<"Balanced"<<endl;
}

  

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define abs(zz) ((zz>=0) ? (zz) : (-(zz)))

int main()
{
    int i,n,a,ans=0,max=0;
	scanf("%d",&n);
	
	for(i=0;i<n;i++)
	{
		scanf("%d",&a);
		if(a>max)max=a;
		ans+=a;
	}
	printf("%d",ans-(max/2));
}


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

#define INF 1e9
#define MAX 100005
#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define ull long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define nl '\n'
#define zai <<' '<<
#define all(a) a.begin(),a.end()
#define pc __builtin_popcount
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

bool cmp(pair<string,pair<int,int>> s,pair<string,pair<int,int>> s1){
	return s.xx<s1.xx || (s.xx==s1.xx && s1.yy.xx<s.yy.xx);
}
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	vector<pair<string,pair<int,int>>>v;
	for(int i=0;i<n;i++){
		string s; int a;
		cin >> s >> a;
		v.pb({s,{a,i}});	
	}
	sort(all(v),cmp);
	for(auto it:v){
		cout << it.yy.yy+1 << nl;
	}
	return 0;
}

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

int main(){
  string s;
  cin >> s;
  if(s[0]!=s[1] && s[1]!=s[2] && s[2]!=s[3]){
    cout << "Good" << endl;
  }
  else{
    cout << "Bad" << endl;
  }
}
  

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

int main(){
   int l,r; cin>>l>>r;
   r=min(r,l+4038);
   int ans=2018;
   for(ll i=l;i<=r;i++){
      for(ll j=i+1;j<=r;j++){
         int x=i*j%2019;
         ans=min(ans,x);
      }
   }
   cout<<ans<<endl;
   return 0;
}


   


Measured memory_bytes: 384
#include <stdio.h>

int main(){
	int a, b;
	scanf("%d %d", &a, &b);
	if (a > b)
		printf("a > b\n");
	if (a < b)
		printf("a < b\n");
	if (a == b)
		printf("a == b\n");
	return 0;

}

Measured memory_bytes: 580
#include <iostream>
using namespace std;
int main(void){
    int a, b, c, d, e;
    cin >> a >> b >> c;
    if (a < b) {
        d = a;
        e = b;
    } else {
        d = b;
        e = a;
    }
    if (c < d) {
        cout << c << ' ' << d << ' ' << e << endl;
    } else if (c > d && c > e) {
        cout << d << ' ' << e << ' ' << c << endl;
    } else {
        cout << d << ' ' << c << ' ' << e << endl;
    }
}



Measured memory_bytes: 3096
#include <cstdio> 
#include <ctime> 
#include <cmath>   
#include <cstring>
#include <cstdlib>          
#include <iostream>                                      
#include <map>                
#include <queue>                
#include <stack>                 
#include <vector>             
#include <string>  
#include <algorithm>  
#define e 2.718281828459045     
#define pi 3.141592653589793239 
using namespace std;
typedef long long ll;            //>10^18
typedef long double ld;          //3.3621e-4932 ~ 1.18937e4932
typedef unsigned long long ull;  //>10^20
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 5;
const int INF = 0x3f3f3f3f;      
const int INFS = 0xc0c0c0c0;     
const double eps = 1e-8;         
int main(int argc, char *argv[]){
	string s; cin >> s;
	int len = s.size();
	if(s[len - 1] != 's') cout << s + 's';
	if(s[len - 1] == 's') cout << s + "es";	
	return 0;
}

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	for(int a,b;cin>>a>>b;){
		if(a<=0 && 0<=b)
			cout<<"Zero"<<endl;
		else if(0<a)
			cout<<"Positive"<<endl;
		else{
			int l=b-a+1;
			cout<<(l&1?"Negative":"Positive")<<endl;
		}
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;

//#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no { cout << -1; return; }

void solve() {
    string s, t;
    cin >> s >> t;
    int ans = 0;
    loop(i, s.size())
        if (s[i] != t[i])
            ++ans;
    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

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

using namespace std;

int main() {
  int A, P;
  cin >> A >> P;
  cout << (3 * A + P) / 2 << endl;
}


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

Measured memory_bytes: 592
s = input()
s = s[::-1]

w = ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]

current_position = 0


while current_position <= len(s):
    if s[current_position:current_position+5] == w[0]:
        current_position += 5
    
    elif s[current_position:current_position+7] == w[1]:
        current_position += 7
    
    elif s[current_position:current_position+6] == w[3]:
        current_position += 6
    
    elif s[current_position:current_position+5] == w[2]:
        current_position += 5
    
    else:
        break
    
if current_position == len(s):
    print('YES')
else:
	print('NO')

Measured memory_bytes: 3188
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.util.Calendar.Builder;



public class Main {
	static int INF = 2 << 27;
	static int N;
	static int M;
	static int A;
	static int B;
	static int C;
	static int T;
	static long[][] dp;
	public static void main(String[] args) {	
		//FastScanner sc = new FastScanner();
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		while(true) {
			int d = sc.nextInt();
			int e = sc.nextInt();
			if(d == 0 && e == 0) break;
			double min = INF;
			for(int i = 0; i <= d; i++) {
				int j = d - i;
				min = Math.min(Math.abs(Math.sqrt(i * i + j * j) - e),min);
			}
			System.out.printf("%.10f\n",min);
		}
	}
}

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

int main() {
	int n, a, b;
  	scanf("%d %d %d", &n, &a, &b);
  	int r = min(a, b);
  	int s = max(a + b - n, 0);
  	printf("%d %d\n", r, s);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define COUT(x) cout << (x) << endl
using namespace std;
typedef pair<int,int> P;
typedef long long int ll;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main() {
    vector<int> vec(3);
    rep(i, 3) cin >> vec[i];
    sort(vec.begin(), vec.end());
    COUT(vec[0] + vec[1]);

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
using namespace std;

int main() {
int n;
int co=0;
string s;

scanf("%d",&n);
cin>>s;

        
  for(int i=0;i<n-2;i++){
        if  (s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
            co++;
        }
	printf("%d",co);


return 0;
}



Measured memory_bytes: 256
get_input(Number):-
    current_input(Input),
    read_string(Input, ' \n', '', _, String),
    number_string(Number, String). 

main:-
    get_input(A),
    get_input(B),
    get_input(C),
    get_input(D),
    get_input(E),
    N is 15 - A - B - C - D - E,
    write(N).


Measured memory_bytes: 8048
// https://atcoder.jp/contests/abc109/tasks/abc109_d
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
inline int read() {
    int tmp = 0;
    char c = getchar(), f = 1;
    for (; c < '0' || '9' < c; c = getchar())
        if (c == '-')
            f = -1;
    for (; '0' <= c && c <= '9'; c = getchar())
        tmp = (tmp << 3) + (tmp << 1) + c - '0';
    return tmp * f;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    h = read(), w = read();
    vector<vector<int>> v(h, vector<int>(w));
    REP(i, h) REP(j, w) v[i][j] = read();
    bool coin = false;
    vector<pii> ans, tmp;
    REP(i, h) REP(j, w) {
        int k = (i % 2 == 0 ? j : (w - j - 1));
        if (coin) {
            // ボールの合計が奇数の場合、ボールを持ったまま終わることを考慮
            tmp.push_back({i + 1, k + 1});
        }
        if (v[i][k] % 2 == 1) {
            if (coin) {
                coin = false;
                ans.insert(ans.end(), ALL(tmp));
                tmp.clear();
            } else {
                coin = true;
            }
        }
        if (coin) {
            tmp.push_back({i + 1, k + 1});
        }
    }
    cout << ans.size() / 2 << "\n";
    REP(i, ans.size()) {
        cout << ans[i].first << " " << ans[i].second << (i % 2 ? "\n" : " ");
    }

    return 0;
}


Measured memory_bytes: 5392
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef pair<long long,long long>P;
int main() {
	vector<long long>v;
	long long now = 1;
	for (int i = 0;i<30; i++) {
		v.push_back(now);
		now *= 2;
	}
	int n;
	cin >> n;
	for (int j = 0; j < n; j++) {
		long long s, g;
		cin >> s >> g;
		queue<P>que;
		que.push(P(s, g));
		long long ans = 0;
		long long mg = 0;
		long long ms = 0;
		while (!que.empty()) {
			P p = que.front();
			que.pop();
			ans++;
			if (p.second > 0) {
				for (int i = 29; i >= 0; i--) {
					long long tmp = p.second / v[i];
					if (tmp >= 1) {
						mg = tmp * v[i];
						if (p.first <= mg) {
							if (mg - v[i] >= p.first) {
								ms = mg - v[i];
								break;
							}
						}
					}
				}
			}
			if (p.second < 0) {
				long long abps = abs(p.second);
				for (int i = 29; i >= 0; i--) {
					long long tmp = abps / v[i];
					if (p.second % v[i] != 0) tmp++;
					mg = -1 * tmp * v[i];
					if (mg - v[i] >= p.first) {
						ms = mg - v[i];
						break;
					}
				}
			}
			if (p.second == 0) {
				for (int i = 29; i >= 0; i--) {
					if (-1 * v[i] >= p.first) {
						ms = -1 * v[i];
						mg = 0;
						break;
					}
				}
			}
			if (p.first != ms) {
				que.push(P(p.first, ms));
			}
			if (p.second != mg) {
				que.push(P(mg, p.second));
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3160
import java.util.Scanner;

/**
 * Main
 */
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] x = new int[5];

        for(int i=0; i<5; i++){
            x[i] = sc.nextInt();
            if(x[i] == 0){
                System.out.println(i+1);
                break;
            }
        }
    }
}

Measured memory_bytes: 26968
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder sb = new StringBuilder();

		br.readLine();
		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int x, y, b, p;
			int regular, discount;
			StringTokenizer st = new StringTokenizer(line);
			x = Integer.parseInt(st.nextToken());
			y = Integer.parseInt(st.nextToken());
			b = Integer.parseInt(st.nextToken());
			p = Integer.parseInt(st.nextToken());
			regular = x * b + y * p;
			discount = (x * (b > 5 ? b : 5) + y * (p > 2 ? p : 2)) * 4 / 5;
			sb.append(regular < discount ? regular : discount).append('\n');
		}
		System.out.print(sb.toString());
	}
}

Measured memory_bytes: 18248
package main

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

func main() {
	scn := bufio.NewScanner(os.Stdin)
	scn.Split(bufio.ScanWords)
	nextInt := func() int { scn.Scan(); r, _ := strconv.Atoi(scn.Text()); return r }
	w := bufio.NewWriter(os.Stdout)

	n := nextInt()
	vecs := make([][]int, n)
	for i := 0; i < n; i++ {
		u := nextInt()
		k := nextInt()
		for j := 0; j < k; j++ {
			vecs[u-1] = append(vecs[u-1], nextInt()-1)
		}
	}

	ds := make([]int, 0, n)
	for i := 0; i < n; i++ {
		ds = append(ds, -1)
	}

	q := make([]int, 0, n)
	q = append(q, 0)
	ds[0] = 0

	for len(q) > 0 {
		i := pop(&q)
		for _, v := range vecs[i] {
			if ds[v] == -1 {
				ds[v] = ds[i]+1
				q = append(q, v)
			}
		}
	}

	for i, d := range ds {
		fmt.Fprintln(w, i+1, d)
	}

	w.Flush()
}

func pop(q *[]int) int {
	v := (*q)[0]
	*q = (*q)[1:]
	return v
}



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

using namespace std;

int main(void) {
	int out;
	int t[5];
	for(int i=0;i<5;i++) {
		scanf("%d", &t[i]);
	}
	for(int i=0; i<5; i++) {
		if(t[i] == 0) {
			if(i+1 < 5) {
				out = t[i+1] -1;
				break;
			} else {
				out = t[i-1] +1;
				break;
			}
		}
	}
	printf("%d\n", out);

	return 0;
}

Measured memory_bytes: 3820
#!/usr/bin/env python3

N = int(input().split()[0])
a_list = list(map(int, input().split()))

odd_n = 0
even_n = 0

for a in a_list:
    if a % 2 == 1:
        odd_n += 1
    else:
        even_n += 1

ans = "YES" if odd_n % 2 == 0 else "NO"

print(ans)


Measured memory_bytes: 14112
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args){
        int N = in.i();
        int[] a = in.ii(3 * N);
        PriorityQueue<Integer> q = new PriorityQueue<>();
        long sum = 0;
        for (int i = 0; i < N; i++) {
            q.add(a[i]);
            sum += a[i];
        }
        long[] b = new long[N + 1];
        b[0] = sum;
        for (int i = 0; i < N; i++) {
            int x = a[N + i];
            q.add(x);
            b[i + 1] = b[i] + x - q.poll();
        }

        q = new PriorityQueue<>((x, y) -> -x + y);
        sum = 0;
        for (int i = 2 * N; i < 3 * N; i++) {
            q.add(a[i]);
            sum += a[i];
        }
        long[] c = new long[N + 1];
        c[N] = sum;
        for (int i = N; i > 0; i--) {
            int x = a[N + i - 1];
            q.add(x);
            c[i - 1] = c[i] + x - q.poll();
        }
        q.clear();
        long ans = Long.MIN_VALUE;
        for (int i = 0; i < b.length; i++) {
            long t = b[i] - c[i];
            if (ans < t) {
                ans = t;
            }
        }

        out.println(ans);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = read(cbuf, 0, cbuf.length);
            } catch (IOException e) {}
            head = 0;
        }
        return cbuf[head++];
    }

    void back() {
        head--;
    }

    boolean minus() {
        boolean minus;
        while (true) {
            char c = next();
            if (c != ' ' && c != '\n' && c != '\r') {
                if (!(minus = c == '-')) back();
                return minus;
            }
        }
    }

    void skip() {
        while (true) {
            char c = next();
            if (c != ' ' && c != '\n' && c != '\r') {
                back();
                break;
            }
        }
    }

    char[] s(final int N) {
        skip();
        char[] s = new char[N];
        for (int i = 0; i < s.length; i++) {
            s[i] = next();
        }
        return s;
    }

    int i() {
        boolean minus = minus();
        int n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        boolean minus = minus();
        long n = 0;
        while (true) {
            int k = next() - '0';
            if (k < 0 || 9 < k) break;
            n = 10 * n + k;
        }
        return minus ? -n : n;
    }
}


Measured memory_bytes: 49968
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

// https://suikaba.hatenablog.com/entry/2017/08/20/232530
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  string a; cin >> a;
  int sz = a.size();
  // next[i][char] = a の i 文字目以降 (i 文字目を含む)で
  //                 最初に文字 char が現れる index (0-based)
  vector<vector<int> > next(sz, vector<int>(26, sz));
  next[sz - 1][a[sz - 1] - 'a'] = sz - 1;
  for (int i = sz - 2; i >= 0; --i) {
    REP(j, 26) next[i][j] = next[i + 1][j];
    next[i][a[i] - 'a'] = i;
  }
  // dp[i] = a の i 文字目以降 (i 文字目を含む) で
  //         部分列とならない最短の文字列長 (0-based)
  // dp[0] が求める解の長さ
  vector<int> dp(sz + 1, sz + 1);
  dp[sz] = 1;
  for (int i = sz - 1; i >= 0; --i) REP(j, 26) {
    if (next[i][j] == sz) dp[i] = 1;
    else dp[i] = min(dp[i], dp[next[i][j] + 1] + 1); // A to Z
  }
  string ans = "";
  int now_pos = 0; // 現在見ている a の index
  REP(i, dp[0]) {
    // 次に文字 c が現れる index で丁度 dp の値が変わっているか
    REP(j, 26) {
      if (i == dp[0] - 1) {
        if (next[now_pos][j] == sz) {
          ans += (char)('a' + j);
          break;
        }
      } else if (dp[next[now_pos][j] + 1] == dp[0] - i - 1) {
        now_pos = next[now_pos][j] + 1;
        ans += (char)('a' + j);
        break;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 27796
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin.bytes().map(|c| c.expect("faild") as char).skip_while(|c| c.is_whitespace()).take_while(|c| !c.is_whitespace()).collect();
    token.parse().ok().expect("faild parse")
}
fn main(){
    loop{
        let a: i32 = read();
        let b: i32 = read();
        if a==0 && b==0{
            break;
        }
        for i in 0..a{
            for i2 in 0..b{
                if (i+i2)%2 ==0 {
                    print!("#");
                }else{
                    print!(".");
                }
            }
            println!("");
        }
        println!("");
    }
}


Measured memory_bytes: 1056
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SI(): return input().split()

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

from math import ceil, floor, log2
from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product
from heapq import heapify, heappop, heappush

def solve():
    n = II()

    keta = [0] * (n+1)
    for i in range(2, n+1):
        # iを素因数分解
        for j in range(2, int(pow(i, 0.5))+1):
            if i % j: continue
            ex = 0
            while i % j == 0:
                i = i // j
                ex += 1
            keta[j] += ex
        if i != 1:
            keta[i] += 1
    # print(fact)

    mod = 1000000007
    ans = 1
    for ex in keta:
        ans = ans * (ex + 1)
        ans %= mod
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3316
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1e9;

int main(){

  int n;cin>>n;
  int a[n+10];
  map<int,int>mp;
  rep(i,0,n){
    cin>>a[i];
    if(n%2==0&&a[i]%2==0){out(0);return 0;}
    else if(n%2==1&&a[i]%2==1){out(0);return 0;}
    mp[a[i]]++;
    if(mp[a[i]]>2){out(0);return 0;}
  }

  if(n%2==0&&mp[0]!=0){out(0);return 0;}
  if(n%2==1&&mp[0]!=1){out(0);return 0;}

  rep(i,0,n){
    if(a[i]!=0&&mp[a[i]]!=2){out(0);return 0;}
  }

  ll ans=1;
  int k=mp.size()-1;
  if(k==1)out(ans);
  else {
    rep(i,0,k){
      ans*=2;ans%=mod;
    }
    out(ans);
  }


  return 0;
}


Measured memory_bytes: 2944
import sys
from collections import deque

S = input()
Q = int(input())
QUERY = sys.stdin.readlines()

state = 0
q = deque()
for s in S:
    q.append(s)

for i in range(Q):
    query = QUERY[i]
    if query[0] == '1':
        state ^= 1
    else:
        _, F, C = query.split()
        F = int(F) - 1
        if state ^ F:
            q.append(C)
        else:
            q.appendleft(C)

ans = []
if state == 0:
    while q:
        ans.append(q.popleft())
else:
    while q:
        ans.append(q.pop())

print(''.join(ans))


Measured memory_bytes: 21324
from collections import Counter 
from collections import defaultdict
from collections import deque
import math
import itertools
import heapq
import numpy as np
import sys
sys.setrecursionlimit(10**6)

#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
ceil=lambda x,y: (x+y-1)//y
input_list = lambda : list(map(int,input().split()))
import fractions

n=int(input())
a=input_list()
b=input_list()
c=[]
for i in range(n):
    c.append(a[i]-b[i])

c.sort(reverse=True)
ans=0
for i in c:
    if i<0:
        break
    ans+=i

print(ans)

Measured memory_bytes: 13504
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";}
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 998244353;

const bool DEBUG = 0;
const int MAXN = 305;

int n;
int a[4];
ld dp[MAXN][MAXN][MAXN];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	setp(10);
	
	cin>>n;
	forn(i,0,n)
	{
		int x; cin>>x;
		a[x]++;
	}
	
	dp[0][0][0]=0;
	fore(k,0,n) fore(j,0,n) fore(i,0,n)
	{
		if(i+j+k==0) continue;
		ld tmp=1;
		if(i) tmp+=i*1.0L/n*dp[i-1][j][k];
		if(j) tmp+=j*1.0L/n*dp[i+1][j-1][k];
		if(k) tmp+=k*1.0L/n*dp[i][j+1][k-1];
		dp[i][j][k]=tmp*n/(i+j+k);
	}
	
	cout<<dp[a[1]][a[2]][a[3]]<<'\n';
	
	return 0;
}


Measured memory_bytes: 436788
#include<iostream>
#include <algorithm>
#include <string>
using namespace std;
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(int)(n); i++)
typedef long long ll;
const int INF = numeric_limits<int>::max();
const int MOD = (1e9 + 7);
#include <vector>

int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>>vals(N);
  vector<int> a(M), b(M);
  rep(i, M){
    cin >> a[i] >> b[i];  a[i]--;
    vals[a[i]].push_back(b[i]);
  }
  rep(i, N){
    sort(vals[i].begin(), vals[i].end());
  }
  rep(i, M){
    printf("%06d", a[i]+1);
    int p = lower_bound(vals[a[i]].begin(), vals[a[i]].end(), b[i]) -  vals[a[i]].begin();
    printf("%06d\n", p+1);
  }
}


Measured memory_bytes: 7808
using System;
using System.Collections.Generic;
 class Program
 {
     static void Main(string[] args)
     {
         double data0 = 0, data1 = 0, data2 = 0;

         String nyuryoku;
         string[] data;
         var strList = new List<string>();
              
         while (true)
         {
             nyuryoku = Console.ReadLine();
 
             if (nyuryoku == "0 0")
                 break;
             data0++;
             strList.Add(nyuryoku);
         }
         for (int k = 0; k < data0; k++)
         {
             data = strList[k].Split(' ');
             for (int i = 0; i < int.Parse(data[0]); i++)
             {
                 for (int j = 0; j < int.Parse(data[1]); j++)
                     Console.Write("#");
                 Console.Write("\n");
             }
             Console.Write("\n");
         }
 
      }
 }



Measured memory_bytes: 17940
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val map = mutableMapOf<Char, Long>()
    val march = mutableListOf('M', 'A', 'R', 'C', 'H')
    for (i in march) {
        map[i] = 0L
    }
    for (i in 1..n) {
        val s = readLine()!!
        val first = s.first()
        if (first in march) map[first] = map[first]!! + 1
    }

    var count = 0L
    for (i in 0..2) {
        for (j in i + 1..3) {
            for (k in j + 1..4) {
                count += map[march[i]]!! * map[march[j]]!! * map[march[k]]!!
            }
        }
    }

    println(count)
}


Measured memory_bytes: 37568
// #define STOPIT
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

void debug_impl() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
    #define debug(...)\
    do {\
        cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        cerr << std::noboolalpha;\
    } while (false)
#else
    #define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr>
istream& operator>> (istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, enable_if_t<!is_same< Container, string >::value, nullptr_t> = nullptr >
ostream& operator<< (ostream& os, Container const& v) {
  os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

vector<string> ans = {};
void dfs(string& now, const int& N, int mx)
{
    if (now.size() == N)
    {
        ans.push_back(now);
        return;
    }

    rep(n, 0, mx+2)
    {
        char c = 'a'+n;
        now += c;
        dfs(now, N, max(mx, n));
        now.pop_back();
    }
}

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

    string now = "a";
    dfs(now, N, 0);

    for (string a: ans)
        cout << a << endl;
    return 0;
}


Measured memory_bytes: 9588
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <unordered_map>
#include <string>
//typedef long long LL;
//typedef long double LD;
using namespace std;

//#define MOD 1000000007

int main() {
    int n;
    string s;
    int tmp;
    int ans=0;
    int tmp_ans;
    cin >> n;
    cin >> s;
    vector<vector<int>> left_s(n, vector<int>(26, 0));
    vector<vector<int>> right_s(n, vector<int>(26, 0));

    for(int i=0; i<n; i++){
        tmp = s[i] - 'a';
        left_s[i][tmp]=1;
        for(int j=0; j<26; j++){
            if(j!=tmp && i!=0){
                left_s[i][j] = left_s[i-1][j];
            }
        }
    }

    for(int i=n-1; i>=0; i--){
        tmp = s[i] - 'a';
        right_s[i][tmp]=1;
        for(int j=0; j<26; j++){
            if(j!=tmp && i!=n-1){
                right_s[i][j] = right_s[i+1][j];
            }
        }
    }

    for(int i=1; i<n; i++){
        tmp_ans=0;
        for(int j=0; j<26; j++){
            if(left_s[i-1][j]==1 && right_s[i][j]==1){
                tmp_ans++;
            }
        }
        if(tmp_ans>ans){
            ans=tmp_ans;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
k = int(input())
ans = []


def dfs(x):
    if x > 10**10:
        return 0
    else:
        ans.append(x)
        y = x % 10
        for i in range(10):
            if abs(y-i) <= 1:
                dfs(10*x+i)
                
for i in range(1, 10):
    dfs(i)
ans.sort()
print(ans[k-1])

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    string S;
    cin >> S;

    if(S == "RRR"){
        cout << 3 << endl;
        return 0;
    }
    if(S == "RRS"){
        cout << 2 << endl;
        return 0;
    }
    if(S == "SRR"){
        cout << 2 << endl;
        return 0;
    }
    REP(i, 3){
        if(S[i] == 'R'){
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
// You should only debug a pair of simple data types. For example,
// the debug won't work if one of pair's elements is collection type
// (std::vector, std::map, std::set...).
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


// bool check_prime(int n)  return whether a number is prime or not O(sqrt(N));
// int BE(int x,int n,int m)  return x^n%m; O(logN);
// void sieve()  from number 1-1000001 saare prime store kar lega  in bool is_prime[1000001] array
// vector<int> z_array(string s)  return vector which is Z-array of string s;
// vector<int> lps(string s)      return vector which is lps array of string s;
// int power(int x,int n) return x^n; O(logN);
// using_ordered_set (template for using ordered set , replace first 2 lines of this page with this code..);


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	string s;
	cin >> s;
	if (s[0] == s[1] && s[2] == s[0] && s[0] == 'R')
		cout << 3 << en;
	else if (s[0] != s[1] && s[1] != s[2] && s[0] == s[2])
		cout << 1 << en;
	else if (s[0] == s[1] && s[0] == 'R')
		cout << 2 << en;
	else if (s[1] == s[2] && s[1] == 'R')
		cout << 2 << en;
	else if (s[0] == 'R' || s[1] == 'r' || s[2] == 'R')
		cout << 1 << en;
	else
		cout << 0 << en;


	return 0;
}




Measured memory_bytes: 3612
import Data.List (unfoldr)

main = do
  getLine
  st <- getLine
  let [s,t] = words st
  let ans = compute s t
  putStrLn ans

-- compute s t = foldr (\(a,b) u -> a:b:u) [] $ zip s t
compute (s:ss) (t:ts) = s : t : compute ss ts
compute [] [] = []
{-
compute s t = unfoldr step (s,t)
  where
    step ([],_) = Nothing
    step (s:ss,ts) = Just (s, (ts,ss))
-}


Measured memory_bytes: 508
#include<iostream>
#include<algorithm>
#include<queue>

using namespace std;

int main() {
	string s;
	queue<int> top;
	queue<int> lake;
	int area = 0;
	cin >> s;
	int* height = new int[s.length() + 1];
	height[0] = 0;
	for (int i = 0;i < s.length();i++) {
		switch (s[i])
		{
		case '/':
			height[i + 1] = height[i] + 1;
			break;
		case '_':
			height[i + 1] = height[i];
			break;
		case '\\':
			height[i + 1] = height[i] - 1;
		default:
			break;
		}
	}
	bool flag;
	if (height[0] >= height[1])top.push(0);
	for (int i = 1;i < s.length();i++) {
		flag = true;
		if (height[i - 1] > height[i] || height[i + 1] > height[i]) {
			continue;
		}
		for (int j = i - 1;j >= 0;j--) {
			if (height[j] > height[i]) {
				flag = false;
				break;
			}
		}
		if (!flag) {
			flag = true;
			for (int j = i + 1;j <= s.length();j++) {
				if (height[j] > height[i]) {
					flag = false;
					break;
				}
			}
		}
		if (flag)top.push(i);
	}
	if (height[s.length() - 1] <= height[s.length()])top.push(s.length());


	int indexl, indexr, level;
	double lakesize;
	if (top.size() <= 1) {
		cout << "0\n0\n";
		return 0;
	}
	indexl = top.front();
	top.pop();
	while (!top.empty()) {
		indexr = top.front();
		top.pop();
		level = min(height[indexl], height[indexr]);
		lakesize = 0;
		for (int i = indexl;i < indexr;i++) {
			switch (s[i]) {
			case '/':
				lakesize += max(0.0, level - height[i] - 0.5);
				break;
			case '_':
				lakesize += max(0, level - height[i]);
				break;
			case '\\':
				lakesize += max(0.0, level - height[i] + 0.5);
				break;
			}
		}
		area += lakesize;
		if (lakesize > 0)lake.push((int)lakesize);
		indexl = indexr;
	}
	cout << area << endl << lake.size();
	while (!lake.empty()) {
		cout << " ";
		cout << lake.front();
		lake.pop();
	}
	cout << endl;


}


Measured memory_bytes: 3328
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N;
        long D,A;
        N = sc.nextInt();
        D = sc.nextLong();
        A = sc.nextLong();
        long X, H;
        TreeMap<Long, Long> mp = new TreeMap<>();
        for(int i=0;i<N;i++){
            X = sc.nextLong();
            H = sc.nextLong();
            mp.put(X, H);
        }
        List<Long> keys = new ArrayList<>();
        for(Long k:mp.navigableKeySet()){
            keys.add(k);
        }
        long[] diffs = new long[N];
        Arrays.fill(diffs, 0);

        long damage = 0;
        long sum=0;
        int ind=0;
        for(Long k:keys){
//            System.out.println(mp);
//            for(long df:diffs){System.out.print(df);}System.out.println();
            damage += diffs[ind];
            mp.put(k, mp.get(k)-damage);
            if(mp.get(k) > 0){
                long cnt = ((mp.get(k) - 1) / A + 1);
                long killDmg = cnt * A;
                damage += killDmg;
                sum += cnt;
                Long to = mp.floorKey(k+2*D);
                int toInd = indexOf(keys, to);
                if(toInd+1 < N)
                    diffs[toInd+1] -= killDmg;
            }
            ind++;
        }
        System.out.println(sum);
    }

    private static int indexOf(List<Long> lst, Long val){
        int l=0;
        int r=lst.size()-1;
        while(l<r){
            int m=(l+r)/2;
            if(lst.get(m) < val){
                l=m+1;
            }else{
                r=m;
            }
        }
        return l;
    }
}



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

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;

const int mod = 998244353;
const ll inf = 3e18 + 5;

int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }  

int main(){
    vector<vi> a(3);
    vector<vi> sol(3);
    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            int tmp;
            cin >> tmp;
            a[i].push_back(tmp);
            sol[i].push_back(0);
        }
    }
    int n;
    cin >> n;
    vi b(n);
    for(int i = 0; i < n; i++)
        cin >> b[i];
    for(int k = 0; k < n; k++){
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++){
                if(a[i][j] == b[k])
                    sol[i][j] = 1;
            }
        }
    }
    bool check = false;
    for(int i=0; i<3; i++){
        if(sol[i][0] + sol[i][1] + sol[i][2] == 3)
            check = true;
    }
    for(int i=0; i<3; i++){
        if(sol[0][i] + sol[1][i] + sol[2][i] == 3)
            check = true;
    }
    if(sol[0][0] + sol[1][1] + sol[2][2] == 3)
        check = true;
    if(sol[0][2] + sol[1][1] + sol[2][0] == 3)
        check = true;

    if(check)
        cout << "Yes";
    else
        cout << "No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    if(__builtin_popcount(N) == 1){
        cout << "No" << '\n';
        return 0;
    }
    else{
        cout << "Yes" << '\n';
    }

    vc<pair<ll, ll>> ans = {{1, 2}, {2, 3}, {3, N + 1}, {N + 1, N + 2}, {N + 2, N + 3}};

    repe(i,2,(N-1)/2 + 1){
        ll x = 2 * i;
        ans.eb(x, x + 1), ans.eb(x + 1, N + 1), ans.eb(N + 1, N + x), ans.eb(N + x, N + x + 1);
    }
    
    if(N%2==0){
        ll n = N | 1;
        while (n - (n & -n)) n -= n & -n;
        ans.eb(N, N + n), ans.eb(2 * N, N - n + 1);
    }

    repa(p, ans) cout << p.first << " " << p.second << '\n';
}

Measured memory_bytes: 8044
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;

void cinv(vector<ll> &V){
	ll t;
	cin >> t;
	V.push_back(t);
}

int main()
{
	ll N;
	string ANS="No";
	cin >> N;

	fore(i,0,26){
		fore(j,0,15){
			if((i*4)+(j*7)==N){
				ANS="Yes";
			}
		}
	}
	cout << ANS << endl;
}

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

using pii = pair<int, int>;
using ll  = long long;
#define rep(i, j) for (int i = 0; i < (int)(j); i++)
#define repeat(i, j, k) for (int i = (j); i < (int)(k); i++)
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << " : " << x << endl

template <class T>
bool set_min(T &a, const T &b) {
    return a > b ? a = b, true : false;
}

template <class T>
bool set_max(T &a, const T &b) {
    return a < b ? a = b, true : false;
}
// vector
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &a : v) is >> a;
    return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (const T &t : v) os << "\t" << t;
    return os << endl;
}
// pair
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &v) {
    return os << "<" << v.first << ", " << v.second << ">";
}

const int INF = 1 << 30;
const ll INFL = 1LL << 60;

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> H(N);
    cin >> H;

    vector<vector<int>> E(N);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        E[a].push_back(b);
        E[b].push_back(a);
    }
    int ans = 0;
    rep(i, N) {
        bool ok = true;
        for (int j : E[i]) {
            ok &= H[i] > H[j];
        }
        ans += ok;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9064