akhauriyash/Code-Regression huggingface dataset:
/*****/

#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);
#include <stdexcept>

//#define int long long

using namespace std;
using ll = long long;
using ld = long double;
using vecll = vector<ll>;

#define nextline() (std::cerr << "\n")
#define debug(x) (#x " : " + (x))
#define debug_cout(x) (std::cerr << #x << " : " <<  (x) << "\n")
#define debug_tabcout(n, x) (std::cerr << strMulti("\t",n) << #x << " : " <<  (x) << "\n")
#define debug_headcout(h, x) (std::cerr << h << " : " <<  (x) << "\n")
#define debug_tabheadcout(n, h, x) (std::cerr << strMulti("\t",n) << h << " : " <<  (x) << "\n")

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep1(i, n) for(int i=1, i##_len=(n); i<=i##_len; 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 all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair(a, b)
constexpr int INF = 2000000100;
constexpr ll DIV = 1000000007;	// 10e9+7
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> T divup(T a, T b) { if (a % b == 0) { return a / b; } return a / b + 1; }
std::string strMulti(std::string t, int n) { std::string out = ""; for (int i = 0; i < n; i++) { out += t; } return out; }
template<class T> T math_P(T m, T n) { T ret = 1; for (T i = m; i > m - n; i--) { ret *= i; } return ret; }
template<class T> T math_C(T m, T n) { T ret = mathP(m, n); for (T i = 2; i <= n; i++) { ret /= i; } return ret; }
template<class T> bool compare_by_b(pair<T, T> a, pair<T, T> b) { if (a.second != b.second) { return a.second < b.second; } return a.first < b.first; }
template<class T> T math_gcd(T a, T b) { a = abs(a); b = abs(b); if (a < b) { std::swap(a, b); } T tmp; while (b != 0) { tmp = b; b = a % b; a = tmp; } return a; }
template<class T> T math_lcm(T a, T b) { a = abs(a); b = abs(b); if (a > b) { std::swap(a, b); } if (a == 1) { return b; } T i = a; while (i % b != 0) { i += a; } return i; }

/*****/

void Main()
{
	ll N, M;
	cin >> N >> M;
	cout << (N == M ? "Yes" : "No");
}

/*****/

int main()
{
	//std::ios::sync_with_stdio(false);
	//std::cin.tie(0);

	//std::cout << std::fixed << std::setprecision(10);


	/*
	while (true)
	{
		Main();
		cout << endl;
	}
	//*/


	Main();

	return 0;
}


Measured memory_bytes: 256
N,W=map(int,input().split())
dp=[[0 for _ in range(W+1)] for _ in range(N+1)]
v=[0]*(N+1)
w=[0]*(N+1)
for i in range(1,N+1):
  v[i],w[i]=map(int,input().split())

for i in range(1,N+1):
  for j in range(1,W+1):
    dp[i][j]=max(dp[i][j],dp[i-1][j])
    if j-w[i]<0: continue
    dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]]+v[i])

print(dp[N][W])


Measured memory_bytes: 25936
#include<bits/stdc++.h>
#define INF (1e9)
#define N 205
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> P1;
int sx,sy,gx,gy,n,lx,ly;
int d[N][N][6];
int dx[6]={0,1,1,0,-1,-1};
int dy[2][6]={
  {1,0,-1,-1,-1,0},
  {1,1,0,-1,0,1}
};
set<P> s;

int dijkstra(){
  priority_queue<P1,vector<P1>,greater<P1> > q;
  for(int i=0;i<=ly*2;i++)
    for(int j=0;j<=lx*2;j++)
      for(int k=0;k<6;k++)d[i][j][k]=INF;
  d[sy][sx][0]=0;
  q.push(P1(P(0,0),P(sy,sx)));
  while(!q.empty()){
    P1 t=q.top(); q.pop();
    int cost=t.first.first;
    int tim=t.first.second;
    int y=t.second.first;
    int x=t.second.second;
    if(d[y][x][tim%6]<cost)continue;
    if(y==gy&&x==gx)return cost;
    for(int i=0;i<6;i++){
      int ny=y+dy[abs(x-lx)%2][i];
      int nx=x+dx[i],ncost=cost;
      if(ny<0||nx<0||ly*2<ny||lx*2<nx)continue;
      if(s.count(P(ny-ly,nx-lx)))continue;
      if(i!=(abs((x-lx)*(y-ly)*tim)%6))ncost++;
      if(d[y][x][(tim+1)%6]>cost+1){
	d[y][x][(tim+1)%6]=cost+1;
	q.push(P1(P(cost+1,tim+1),P(y,x)));
      }
      if(d[ny][nx][(tim+1)%6]>ncost){
	d[ny][nx][(tim+1)%6]=ncost;
	q.push(P1(P(ncost,tim+1),P(ny,nx)));
      }
    }
  }
  return -1;
}

int main(){
  cin>>sx>>sy>>gx>>gy;
  cin>>n;
  int x,y;
  for(int i=0;i<n;i++){
    cin>>x>>y;
    s.insert(P(y,x));
  }
  cin>>lx>>ly;
  sx+=lx; sy+=ly;
  gx+=lx; gy+=ly;
  cout<<dijkstra()<<endl;
  return 0;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll a[3];
  REP(i,3) cin >> a[i];
  sort(a,a+3);
  ll ans = a[2] - a[1];
  ll diff = a[1] - a[0];
  if(diff&1){
    ans += diff/2 + 2;
  }else{
    ans += diff/2;
  }

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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
	string S;
	int K;
	cin >> S >> K;
  	int cnt = S.size();
	set<string> st;
	for(int i = 0;i < cnt;i++) {
		for(int j = 1;j <= min(K + 1,cnt - i);j++) {
			st.insert(S.substr(i,j));
		}
	}
	auto itr = st.begin();
	for(int i = 0;i < K - 1;i++) {
		++itr;
	}
	cout << *itr << endl;
}


Measured memory_bytes: 2176
s = list(input())
s_set = list(set(s))
length = len(s)

indexes = []
for a in s_set:
    tmp = [-1]
    for i, v in enumerate(s):
        if v == a:
            tmp.append(i)
    tmp.append(length)
    indexes.append(tmp)

distance = []
for i in indexes:
    tmp = []
    for j in range(len(i) - 1):
        tmp.append(i[j+1] - i[j] - 1)
    distance.append(max(tmp))

print(min(distance))

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

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long
#define double long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
#define ceil(a,b) (a+b-1)/b
#define endl "\n"
const int N=100005;
const int inf=1e18;
const double eps=1e-9;

#define oa(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define o1(a) cout<<" "<<#a<<" : "<<a<<"\n"
#define o2(a,b) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<"\n"
#define o3(a,b,c) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<"\n"
#define o4(a,b,c,d) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<"\n"

int power(int a,int b){
    int res=1;
    while(b>0){
        if(b&1){
        	res=res*a;
		}
        a=a*a;
        b>>=1;
    }
    return res;
}
int pow1(int a,int b){
    int res=1;
    while(b>0){
        if(b&1){
            res=res*a;
            res%=mod;
        }
        a=a*a;
        a%=mod;
        b>>=1;
    }
    return res;
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int c,k,d;
    cin>>c>>k>>d;

    c=abs(c);
    int w=c/d;
    int ans=inf;
    if(w<=k){
        c-=d*w;
        k-=w;
        if(k%2==0){
            ans=min(ans,abs(c));
        }
    }else{
        c-=k*d;
        cout<<c;
        return 0;
    }
    // int ans=inf;
    // ans=min(abs(c),ans);
    if(k%2==1){
    ans=min(abs(c+d),ans);
    ans=min(abs(c-d),ans);
    if(k>=3){
        ans=min(abs(c-3*d),ans);
    }
    }
    // if(k>0){
    //     c-=d;
    //     ans=min(abs(c),d);
    //     k--;
    //     if(k>0){
    //         ans=min(abs(c-d),ans);
    //     }
    // }
    cout<<ans<<endl;








	
return 0;
}


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

int const md = 998244353;

inline void ad(int &x, int y) { if ((x += y) >= md)x -= md; }
inline void sb(int &x, int y) { if ((x -= y) <  0 )x += md; }
inline int pw(int x, int p){
	int an = 1;
	while (p){
		if (p & 1)an = (ll)an * x % md;
		x = (ll)x * x % md;
		p >>= 1;
	}
	return an;
}

void xc(vector<int> &v, bool inv){
	for (int w = 1; w < v.size(); w <<= 1)for (int l = 0; l < v.size(); l += w << 1)f(i, 0, w){
		int a = v[l + i], b = v[l + w + i];
		ad(v[l + i] = a, b);
		sb(v[l + w + i] = a, b);
	}
	if (inv)f(i, 0, v.size())v[i] = (ll)v[i] * pw(v.size(), md - 2) % md;
}

int main(){
	int n;
	scanf("%d", &n);
	n = 1 << n;
	vector<int> pr(n), z(n);
	f(i, 0, n)scanf("%d", &pr[i]);
	int s = 0;
	f(i, 0, n)s += pr[i];
	int inv = pw(s, md - 2);
	f(i, 0, n)pr[i] = (ll)pr[i] * inv % md;
	pr[0] -= 1;
	z[0] = n - 1;
	f(i, 1, n)z[i] = md - 1;
	xc(pr, false);
	xc(z, false);
	f(i, 0, n)z[i] = (ll)z[i] * pw(pr[i], md - 2) % md;
	xc(z, true);
	f(i, 1, n)sb(z[i], z[0]);
	printf("0\n");
	f(i, 1, n)printf("%d\n", z[i]);
}

Measured memory_bytes: 4864
#include <iostream>
#define INF 1e+18
#define int long long
using namespace std;

signed main(){
	int n,m,k,a[20000];
	static int dp[20001][1001];
	cin >> n >> m >> k;
	for(int i = 0;i <= n;i++){
		for(int j = 0;j <= 1000;j++) dp[i][j] = INF;
	}
	dp[0][0] = 0;
	dp[0][1000] = 0;
	for(int i = 0;i < n;i++) cin >> a[i];
	for(int i = 1;i <= n;i++){
		int mi = a[i - 1],ma = a[i - 1];
		for(int j = 0;j < min(m,i);j++){
			dp[i][j] = dp[i - j - 1][1000] + k + (j + 1) * (ma - mi);
			dp[i][1000] = min(dp[i][1000],dp[i][j]);
			if(i - j - 2 >= 0) {
				mi = min(mi,a[i - j - 2]);
				ma = max(ma,a[i - j - 2]);
			}
		}
	}
	cout << dp[n][1000] << endl;
	return 0;
}

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

const int MOD = 1000000007;

int main(void){
    int n, m, xbuf, ybuf;
    cin >> n >> m;
    long long xsum = 0LL;
    long long xxsum = 0LL;
    long long ysum = 0LL;
    long long yysum = 0LL;
    for(int i=0; i<n; i++){
        cin >> xbuf;
        xxsum += MOD + (long long)i*xbuf%MOD;
        xxsum %= MOD;
        xxsum += MOD - xsum;
        xxsum %= MOD;
        xsum += MOD + xbuf;
        xsum %= MOD;
    }
    for(int i=0; i<m; i++){
        cin >> ybuf;
        yysum += MOD + (long long)i*ybuf%MOD;
        yysum %= MOD;
        yysum += MOD - ysum;
        yysum %= MOD;
        ysum += MOD + ybuf;
        ysum %= MOD;
    }
    cout << xxsum * yysum % MOD << endl;
}

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

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        int[] a = in.nextIntArray(n);

        Set<Integer> set = new HashSet<>();
        for (int i : a) {
            if (set.contains(i)) {
                out.println("NO");
                return;
            }
            set.add(i);
        }
        out.println("YES");
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 57136
#include <stdio.h>

int main(void){

    char O[51], E[51];
    char a[200] = "AAA";
    scanf("%s %s", O, E);

    for(int i = 0; i < 100; i++){
        if(i % 2 == 0){
            a[i] = O[i / 2];
        }else{
            a[i] = E[i / 2];
        }
    }

    printf("%s", a);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}

signed main()
{
  int N;
  cin >> N;
  vector<int> x(N), y(N);
  for (int i = 0; i < N; i++)
  {
    cin >> x.at(i) >> y.at(i);
  }
  
  map<pair<int, int>, int> mp;
  int m = 0;
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
      if (i == j) continue;
      //if (x.at(i) - x.at(j) < 0) continue;
      pair<int, int> pq;
      pq.first = x.at(i) - x.at(j);
      pq.second = y.at(i) - y.at(j);
      mp[pq]++;
    }
  }
  
  auto begin = mp.begin(), end = mp.end();
  for (auto it = begin; it != end; it++)
  {
    chmax(m, it->second);
    //cerr << it->first.first << " " << it->first.second << " " << it->second << endl;
  }

  int ans = N - m;
  cout << ans << endl;
}

Measured memory_bytes: 384
a,b=map(int,input().split())
for s in range(b//10000+1):
    for t in range(b//5000+1):
        r=a-s-t
        if r<0:
            break
        if 10000*s+5000*t+1000*r==b and s+t+r==a:
            print(s,t,r)
            exit()
print(-1,-1,-1)

Measured memory_bytes: 3060
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    global a, p
    N, X = LI()
    #  N = 50
    #  X = 4321098765432109
    a, p = [1], [1]
    for i in range(N):
        a.append(a[i] * 2 + 3)
        p.append(p[i] * 2 + 1)
    print(make_burger(N, X))
    return


def make_burger(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + a[N-1]:
        return make_burger(N-1, X-1)
    elif X == 2 + a[N-1]:
        return p[N-1] + 1
    elif X <= 2 + 2*a[N-1]:
        return p[N-1] + 1 + make_burger(N-1, X - 2 - a[N-1])
    else:
        return 2*p[N-1] + 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 67564
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def factorial(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n,d=0) Array.new(n,d)end
def arrp(a) a.each{|aa|p aa} end
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
n = inp[0]
t = inp
ans = 0
max = t.max
gg = t.inject(:*)
tes = gg - 1
  t.each do |o|
    ans += tes%o
  end
p ans

Measured memory_bytes: 18940
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int l1 = sc.nextInt();
        int m1 = sc.nextInt();
        int n1 = sc.nextInt();
        int o1 = sc.nextInt();
        int p1 = sc.nextInt();
        int q1 = sc.nextInt();
        int l2 = sc.nextInt();
        int m2 = sc.nextInt();
        int n2 = sc.nextInt();
        int o2 = sc.nextInt();
        int p2 = sc.nextInt();
        int q2 = sc.nextInt();
        sc.close();
        Dice3 dice1 = new Dice3(l1, m1, n1, o1, p1, q1);
        Dice3 dice2 = new Dice3(l2, m2, n2, o2, p2, q2);
        final String order = "NNNNWNNNWNNNENNNENNNWNNNWNNNWNNNENNNENNNWNNN";
        //topがあったときのフラグ
        boolean flg = false;
        //order 回して合ってるか確認する。
        for(int r=0;r < order.length(); r++){
        	if (dice1.equals(dice2)) {
        		flg = true;
        		break;
        	}
        	String odr = order.substring(r, r+1);
        	if ("N".equals(odr)){
        		dice1.N();
        	} else if ("E".equals(odr)) {
        		dice1.E();
        	} else if ("W".equals(odr)) {
        		dice1.W();
    		} else if ("S".equals(odr)) {
        		dice1.S();
			}
        }
        if(flg) {
        	System.out.println("Yes");
        } else {
        	System.out.println("No");
        }
    }
}
    class Dice3{
		int one;
		int two;
		int three;
		int four;
		int five;
		int six;
		int tmp;
    	Dice3(int a, int b, int c, int d, int e, int f){
    		one=a;
    		two=b;
    		three=c;
    		four=d;
    		five=e;
    		six=f;
    	}
    	boolean equals(Dice3 b) {
    		if ((this.one==b.one)&&(this.two==b.two)&&(this.three==b.three)&&(this.four==b.four)&&(this.five==b.five)&&(this.six==b.six)){
    			return true;
    		}
    		return false;
    	}
       	void N(){//1-2-6-5
    		tmp =this.one;
    		one=this.two;
    		two=this.six;
    		six=this.five;
    		five=tmp;
    	}
    	void E(){//1-4-6-3
    		tmp =this.one;
    		one=this.four;
    		four=this.six;
    		six=this.three;
    		three=this.tmp;
    	}
    	void W(){//1-3-6-4
    		tmp =this.one;
    		one=this.three;
    		three=this.six;
    		six=this.four;
    		four=tmp;
    	}
    	void S(){//1-5-6-2
    		tmp =this.one;
    		one=this.five;
    		five=this.six;
    		six=this.two;
    		two=tmp;
    	}
    	void turnR(){
    		tmp=this.two;
    		two=this.three;
    		three=this.five;
    		five=this.four;
    		four=tmp;
    	}
    	void print(){
    		System.out.printf("%d %d %d %d %d %d %n", one,two,three,four,five,six);
    	}
    }



Measured memory_bytes: 26368
// https://atcoder.jp/contests/abc070/tasks/abc070_c
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef set<int> IntSet;
typedef set<int, greater<int>> IntRevSet;

#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define LEN(x) (sizeof(x) / sizeof(*(x)))

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, t, ans = 0;
    cin >> n >> ans;
    REP(i, n - 1) {
        cin >> t;
        ans = lcm(ans, t);
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;
using ll = long long;
constexpr int mod = 1e9+7;
constexpr int md = mod;
int main(){
    string str;
    cin>>str;
    ll cur = 0ll;
    ll ret = 0ll;
    for(int i=0;i<(int)str.size();++i){
        if(str[i] == 'A'){
            cur++;
        }else if(i <(int)str.size()-1 && str[i] == 'B' && str[i+1] == 'C'){
            ret += cur;
            i++;
        }else{
            cur = 0ll;
        }
    }
    cout << ret << endl;
    return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
typedef pair<string,string> Ps;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	// 1 変数を入れる;
	ll x,cost;
};
int main() {

	ll n;
	ll a[200002];
	cin>>n;
	rep(i,n)cin>>a[i];
	sort(a,a+n);
	rep(i,n-1){
		if(a[i]==a[i+1]){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
}


Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG //GCC環境での[]デバッグ
#include <bits/stdc++.h> //全ての標準ライブラリ
#define rep(i,n) for(int i = 0;i < n;i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
using namespace std;
using ll = long long;
int sumVector (const std::vector<int>& v){ //int配列計算
    int sum = 0;
    rep(i, v.size()) sum += v.at(i);
    return sum; 
}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x;
    cin >> x;
    int pre = x;
    
    x= ceil(sqrt(sqrt(x)));
    for(int i = -x; i <= x; i++){
        for(int j = -x; j<= x;j++){
            if(i*i*i*i*i - j*j*j*j*j == pre){
                cout << i << " "<< j;
                return 0;
            }
        }
    }
    
    
    
}

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

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028L;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int r, D, x;
signed main() {
    cin >> r >> D >> x;
    rep(i, 10) {
        x = r * x - D;
        cout << x << endl;
    }
}

Measured memory_bytes: 256
using System;

public class hello
{
    public static void Main()
    {
        var count = 0;
        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < n; i++)
        {
            var s = Console.ReadLine().Trim();
            if (s == "A") count++;
            else
            {
                count--;
                if (count < 0) { Console.WriteLine("NO"); goto end; }
            }
        }
        if (count == 0) Console.WriteLine("YES");
        else Console.WriteLine("NO");
        end:;
    }
}

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

#define int long long
int A, B, C;
signed main() {
  cin >> A >> B >> C;
  if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0) cout << 0 << "\n";
  else {
    int m = min(A*C, min(A*B, B*C));
    cout << m << "\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i,j=0,a,b,c;
  while(scanf("%d %d",&a,&b)){
    if(a==b && a==0)break;
    if(j!=0)printf("\n");
    j=1;
    c=0;
    for(i=a;i<=b;i++){
      if(i%400==0){
	printf("%d\n",i);
	c=1;
      }
      else if(i%100==0);
      else if(i%4==0){
	printf("%d\n",i);
	c=1;
      }
    }
    if(c==0)printf("NA\n");
  }
  return 0;
}


Measured memory_bytes: 616
//q006.cpp
//Sat Sep 19 16:39:00 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

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

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;

	int l[n][10],r[n][10];
	rep(i,n)rep(j,10){
		l[i][j] = 0;
		r[i][j] = 0;
	}

	rep(i,n-1){
		l[i][s[i]-'0']++;
		rep(j,10) l[i+1][j] = l[i][j];
	}

	for(int i=n-1;i>0;i--){
		r[i][s[i]-'0']++;
		rep(j,10) r[i-1][j] = r[i][j];
	}

	set<int> ans;
	for(int i=1;i<n-1;i++){
		rep(j,10)rep(k,10){
			if (l[i-1][j]!=0 && r[i+1][k]!=0){
				ans.insert(j*100+k+(s[i]-'0')*10);
			}
		}
	}
	cout << ans.size() << endl;
//	printf("%.4f\n",ans);
}

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

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

ll gcd(ll a,ll b){
	if(a>b) swap(a,b);
	if(a==0) return b;
	return gcd(b%a,a);
}


int main(){
	ll a[3],m[3],x[3];
	while(cin>>a[0]>>m[0]>>a[1]>>m[1]>>a[2]>>m[2],a[0]||a[1]||a[2]||m[0]||m[1]||m[2]){
		rep(i,3) x[i]=1;
		ll c[3]={0};
		rep(i,3){
			do{
				c[i]++;
				x[i]=a[i]*x[i]%m[i];
			}while(x[i]!=1);
			// cout<<c[i]<<endl;
		}
		ll ans=c[0]*c[1]/gcd(c[0],c[1]);
		// cout<<ans<<endl;
		ans=ans*c[2]/gcd(ans,c[2]);
		cout<<ans<<endl;
	}
}

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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define trav(a, x) for (auto& a : x)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;
#define INF (1ll<<60)

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)


int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int A, B;
    cin >> A >> B;
    vector<string> V(100);
    REP(i, 100) {
        REP(j, 100) {
            if (j > 49) {
                V[i].pb('#'); 
            } else {
                V[i].pb('.');
            }
        }
    }
    int cntA = 1;
    int cntB = 1;
    for (int i = 3; i < 90; i+= 3) {
        for (int c = 1, r = i - c; r >= 1; c++, r = i - c) {
            if (cntB >= B) goto done;
            if (c > 46) break;
            V[r][c] = '#';
            cntB++;
        }
    }
    done:
    for (int i = 52; i < 140; i+= 3) {
        for (int c = 52, r = i - c; r >= 1; c++, r = i - c) {
            if (cntA >= A) goto done1;
            if (c > 96) break;
            V[r][c] = '.';
            cntA++;
        }
        // for (int r = 1, c = i - r; c >= 52; r++, c = i - r) {
        //     // if (c < 52) break;
        //     if (cntA >= A) goto done1;
        //     V[r][c] = '.';
        //     cntA++;
        // }
    }
    done1:
    cout << "100 100\n";
    for (string s : V) {
        cout << s << '\n';
    }


}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
#define double long double
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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 (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
#define eps 1e-12 
//priority_queue<int,vector<int>, greater<int> > q2;



signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int a, b, c; cin >> a >> b >> c;
	if ((a&&b && !c) || (!a && !b&&c)) {
		cout << "Open" << endl;
	}
	else {
		cout << "Close" << endl;
	}


	return 0;
}




Measured memory_bytes: 3208
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
 
using namespace std;
 
int main(int argc, char const *argv[]){
    vector<int> pages;
    map<string, vector<int> > books; 
    string name;
    int page, page_count;
 
    while (cin>>name>>page){
        auto it = books.find(name);
        if (it != books.end()){
            books[name].push_back(page);
        }
        else{
            vector<int> pages = {page};
            books.insert(make_pair(name, pages));
        }
    }
 
    for (auto& book : books){
        cout<<book.first<<endl;
        page_count=0;
        sort(book.second.begin(), book.second.end());
        for (int page : book.second){
            if (page_count) cout<<" "<<page;
            else cout<<page;
            page_count++;
        }
        cout<<'\n';
    }
    return 0;
}

Measured memory_bytes: 3140
n = int(input())
a, b = map(int, input().split())
p = list(map(int, input().split()))
c, d, e = 0, 0, 0
for pp in p:
    if pp <= a:
        c += 1
    elif pp <= b:
        d += 1
    else:
        e += 1
print(min(c, d, e))


Measured memory_bytes: 9172
using System.Collections.Generic;
using System.Linq;
using System;

public class Ba
{
    public int s { get; set; }
    public int t { get; set; }
}

public class Hello
{
    public static void Main()
    {
        var d = new Dictionary<int, List<Ba>>();
        var tmax = 0;
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var C = int.Parse(line[1]);
        for (int i = 0; i < C; i++) d[i] = new List<Ba>();
        for (int i = 0; i < n; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var s = int.Parse(line[0]);
            var t = int.Parse(line[1]);
            tmax = Math.Max(tmax, t);
            var c = int.Parse(line[2]) - 1;
            d[c].Add(new Ba { s = s, t = t });
        }
        var bas = setData(d, n, C);
        Console.WriteLine(getAns(bas, tmax));
    }
    public static int getAns(List<Ba> bas, int tmax)
    {
        var a = new int[tmax + 2];
        for (int i = 0; i < bas.Count(); i++)
        {
            a[bas[i].s]++;
            a[bas[i].t ]--;
        }
        var ret = a[0]; var rw = a[0];
        for (int i = 1; i < a.Length; i++)
        {
            rw = a[i] + rw;
            ret = Math.Max(ret, rw);
        }
        return ret;
    }
    public static List<Ba> setData(Dictionary<int, List<Ba>> d, int n, int C)
    {
        var ret = new List<Ba>();
        for (int i = 0; i < C; i++)
        {
            if (d[i].Count() >= 2)
            {
                var sortd = d[i].OrderBy(x => x.s).ToArray();
                var ns = sortd[0].s; var nt = sortd[0].t;
                var wns = false;
                for (int j = 1; j < sortd.Length; j++)
                {
                    if (sortd[j].s == nt) { nt = sortd[j].t; wns = true; }
                    else { ret.Add(new Ba { s = ns - 1, t = nt }); ns = sortd[j].s; nt = sortd[j].t; }
                    if (j == sortd.Length - 1 && wns) ret.Add(new Ba { s = ns - 1, t = nt });
                    else if (j == sortd.Length - 1 && !wns)  ret.Add(new Ba { s = sortd[j].s -1 , t = sortd[j].t });
                }
            }
            else if (d[i].Count() == 1) ret.Add(new Ba { s = d[i][0].s -1, t = d[i][0].t });
        }
        return ret;
    }
}


Measured memory_bytes: 32316
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int p[] = new int[N+1];
    for (int i=1; i<=N; i++) {
      p[i] = sc.nextInt();
    }

    DS ds = new DS(N+1);
    for (int i=1; i<=M; i++) {
      ds.union(sc.nextInt(), sc.nextInt());
    }

    int ans = 0;
    for (int i=1; i<=N; i++) {
      if (p[i] == i) {
        ans++;
      } else if (ds.root(i) == ds.root(p[i])) {
        ans++;
      }
    }
    System.out.println(ans);
  }

  static class DS {
    int[] parent;
    int[] counter;

    DS(int n) {
      parent = new int[n];
      counter = new int[n];
      Arrays.fill(counter, 1);
      Arrays.setAll(parent, i -> i);
    }

    int root(int a) {
      if (parent[a] == a) {
        return a;
      } else {
        return parent[a] = root(parent[a]);
      }
    }

    void union(int i, int j) {
      int ri = root(i);
      int rj = root(j);
      if (ri == rj) {
        return;
      }
      if (counter[rj] < counter[ri]) {
        // swap ri and rj to avoid infinite loop (ex. A -> B -> C -> A)
        int s = ri;
        ri = rj;
        rj = s;
      }
      parent[ri] = rj;
      counter[rj] += counter[ri];
    }
  }
}


Measured memory_bytes: 96532
/* */

#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
#include <deque>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;

#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
#else
	#define errp(...)
#endif
#define dbg(x) errp(" %s = %s\n", #x, to_string(x).data())
/* ==================== */ 
int main() {
	
	int n, x;
	scanf("%d", &n);
	deque<int> Q;
	for (int i = 0; i < n; i++) {
		scanf("%d", &x);
		if (i & 1) Q.push_front(x);
		else Q.push_back(x);
	}
	vector<int> res;
	if (n & 1)
		while (!Q.empty()) {
			res.push_back(Q.back());
			Q.pop_back();
		}
	else
		while (!Q.empty()) {
			res.push_back(Q.front());
			Q.pop_front();
		}
	for (int i = 0; i < n; i++) printf("%d ", res[i]);
	printf("\n");
}


Measured memory_bytes: 3960
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

int gcd(int a, int b){
    if (a < b) return gcd(b, a);
    else if(b == 0) return a;
    else return gcd(b, a % b);
}
int a, b, c, d, e;
int f(int x) {
    return x/c + x/d - x/e;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> a >> b >> c >> d;
    e = c * d / gcd(c, d);
    cout << b - a + 1 - (f(b) - f(a - 1)) << endl;
    //cout << f(b) << " " << f(a - 1) << endl;


    return 0;
}


Measured memory_bytes: 256
while True:
  m, n = map(int, input().split())
  if m == 0:
    break

  plst = [i for i in range(1, m + 1)]
  length = m
  ind = 0
  for i in range(1, n + 1):
    s = input()
    if length == 1:
      continue
    if i % 15 == 0:
      if s != "FizzBuzz":
        plst.pop(ind)
        length -= 1
        ind %= length
      else:
        ind += 1
        ind %= length
    elif i % 5 == 0:
      if s != "Buzz":
        plst.pop(ind)
        length -= 1
        ind %= length
      else:
        ind += 1
        ind %= length
    elif i % 3 == 0:
      if s != "Fizz":
        plst.pop(ind)
        length -= 1
        ind %= length
      else:
        ind += 1
        ind %= length
    else:
      if s != str(i):
        plst.pop(ind)
        length -= 1
        ind %= length
      else:
        ind += 1
        ind %= length
  print(*plst)


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

int main() {
    int N, K; cin >> N >> K;
    int table[N] = {0};
    for (int i = 0; i < K; i++) {
        int d; cin >> d;
        for (int j = 0; j < d; j++) {
            int s; cin >> s;
            table[s - 1]++;
        }
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (table[i] == 0) ans++;
    }  
    cout << ans << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,nn) for(int i=0;i<nn;i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}


int main(){
  int n,a,b,c,d;
  cin >> n >> a >> b >> c >> d;
  string s;
  cin >> s;
  bool ans=1;

  for(int i=a-1;i<max(c,d)-2;i++){
    if(s[i]=='#' && s[i+1]=='#'){
      ans=0;
    }
  }
  bool z=0;
  if(c<d){
    
  }else{

    for(int i=max(a,b)-2;i<d-1;i++){
      if(i<0){
        continue;
      }
      if(s[i]=='.' && s[i+1]=='.' && s[i+2]=='.'){
        z=1;
      }
      
    }

    if(!z){
      ans=0;
    }

    
        
  }

  if(ans){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  
}

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

#define DEBUG(x) cerr << #x << " = " << x << endl

const int MAX_N = 50;
// x, y
int field[2 * (2 * MAX_N) + 1][2 * (2 * MAX_N) + 1];

int X, Y;

typedef pair<int, int> P;
void dfs(int x, int y) {
    queue<P> Q;
    Q.push(P(x, y));
    while(!Q.empty()) {
        P p = Q.front(); Q.pop();
        for(int i = 0; i < 4; i++) {
            int dx[4] = { 1, 0, -1, 0 };
            int dy[4] = { 0, 1, 0, -1 };
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];
            if(0 <= nx && nx < X && 0 <= ny && ny < Y && field[nx][ny] == 0) {
                field[nx][ny] = 1;
                Q.push(P(nx, ny));
            }
        }
    }
}

void show() {
#if 0
   cerr << '-' << endl;
   for(int i = Y - 1; i >= 0; i--) {
       for(int j = 0; j < X; j++) {
           cerr << field[j][i];
       }
       cerr << '|' << endl;
   }
   cerr << '-' << endl;
#endif
}

int main() {
    while(true) {
        int N; cin >> N;
        if(N == 0) break;
        vector<int> x1(N), y1(N), x2(N), y2(N);
        vector<int> xs;
        vector<int> ys;
        for(int i = 0; i < N; i++) {
            cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
            xs.push_back(x1[i]);
            xs.push_back(x2[i]);
            ys.push_back(y1[i]);
            ys.push_back(y2[i]);
        }
        sort(xs.begin(), xs.end());
        sort(ys.begin(), ys.end());
        xs.erase(unique(xs.begin(), xs.end()), xs.end());
        ys.erase(unique(ys.begin(), ys.end()), ys.end());
        for(int i = 0; i < N; i++) {
            x1[i] = find(xs.begin(), xs.end(), x1[i]) - xs.begin();
            y1[i] = find(ys.begin(), ys.end(), y1[i]) - ys.begin();
            x2[i] = find(xs.begin(), xs.end(), x2[i]) - xs.begin();
            y2[i] = find(ys.begin(), ys.end(), y2[i]) - ys.begin();
        }
        memset(field, 0, sizeof(field));
        for(int i = 0; i < N; i++) {
            for(int x = 2 * x1[i]; x <= 2 * x2[i]; x++) {
                field[x + 1][2 * y1[i] + 1] = 1;
                field[x + 1][2 * y2[i] + 1] = 1;
            }
            for(int y = 2 * y1[i]; y >= 2 * y2[i]; y--) {
                field[2 * x1[i] + 1][y + 1] = 1;
                field[2 * x2[i] + 1][y + 1] = 1;
            }
        }
        X = 2 * (int)xs.size() + 1;
        Y = 2 * (int)ys.size() + 1;
        show();
        int ans = 0;
        for(int x = 0; x < X; x++) {
            for(int y = 0; y < Y; y++) {
                if(field[x][y] == 0) {
                    ans++;
                    field[x][y] = 1;
                    dfs(x, y);
                    show();
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1388
n = int(input())
l = list(map(int,input().split()))
dp = [0]*n
dp[1] = abs(l[0] - l[1])
for i in range(2,n):
    dp[i] = min(dp[i-1] + abs(l[i] - l[i-1]), dp[i-2] + abs(l[i] - l[i-2]))
    
print(dp[n-1])
    
    

Measured memory_bytes: 13980
s = input()
t = input()
n = len(s)
m = len(t)
dp = [[0] * 3100 for _ in range(3100)]
for i in range(n):
    for j in range(m):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1)
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i + 1][j])
        dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j + 1])

# print(dp)
ans = ""
i, j = n, m
while i > 0 and j > 0:
    if dp[i][j] == dp[i - 1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j - 1]:
        j -= 1
    else:
        ans = s[i - 1] + ans
        i -= 1
        j -= 1
print(ans)

Measured memory_bytes: 119132
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, K, S;
    cin >> N >> K >> S;
    int notS = S+1;
    if (notS > (int)1e9) notS = 1;
    for (int i = 0; i < N; ++i) {
        if (i < K) printf("%d%c", S, i == N-1 ? '\n' : ' ');
        else printf("%d%c", notS, i == N-1 ? '\n' : ' ');
    }
    return 0;
}


Measured memory_bytes: 1280
def chmin(a, b):
  if (a > b):
    return b

  return a

def chmax(a, b):
  if (a < b):
    return b

  return a

N,W = map(int, input().split())
li = [list(map(int, input().split())) for i in range(N)]

dp = [[0] * (10**5+10) for i in [0] * (N+1)]

for n in range(N):
  for w in range(1, W+1):
    if (w - li[n][0] >= 0):
      dp[n+1][w] = chmax(dp[n+1][w], dp[n][w - li[n][0]] + li[n][1])

    dp[n+1][w] = chmax(dp[n+1][w], dp[n][w])


print(max(max(dp)))

Measured memory_bytes: 118768
from queue import deque

h,w = map(int,input().split())
li = [input() for _ in range(h)]

inf = 10**10
dx = [1,0]
dy = [0,1]
que = deque()

#そのマスにたどり着くまでに色が変わった最小の回数を保存するリスト
flip_count = [[inf for i in range(w)]for j in range(h)]

if li[0][0] == "#":
    flip_count[0][0] = 1
else:
    flip_count[0][0] = 0

que.append([0,0])

while que:
    k = que.popleft()
    x = k[0]
    y = k[1]
    for i,j in zip(dx,dy):
        nx = x + i
        ny = y + j
        if nx >= w or ny >= h:
            continue
        if flip_count[ny][nx] == inf:
            que.append([nx,ny])
        if li[ny][nx] != li[y][x]:
            flip_count[ny][nx] = min(flip_count[ny][nx],flip_count[y][x]+1)
        else:
            flip_count[ny][nx] = min(flip_count[ny][nx],flip_count[y][x])

if li[-1][-1] == "#":
    flip_count[-1][-1] += 1

print(flip_count[-1][-1]//2)

Measured memory_bytes: 41964
#include <iostream>
#include <string>
using namespace std;
 
int n;
int cnt = 0;
 
long long func(long long a) {
	if (a > n) return 0;
	string s = to_string(a);
	auto pos1 = s.find_first_of('7');
	auto pos2 = s.find_first_of('5');
	auto pos3 = s.find_first_of('3');
	if (pos1 != string::npos && pos2 != string::npos 
		&& pos3 != string::npos) 
		++cnt;
	func(a * 10 + 3);
	func(a * 10 + 5);
	func(a * 10 + 7);
	return 0;
}
 
int main(void) {
	cin >> n;
	long long a = 0;
	func(a);
	cout << cnt;
	return 0;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

def LI(): return list(map(int, stdin.readline().split()))
def LS(): return list(stdin.readline())

n = int(input())
a = LI()
a = [i for i in a if i%2==0]
flg = 0
for i in a:
    if i%3==0 or i%5==0:
        # print(i)
        pass
    else:
        flg = 1
print('APPROVED' if flg==0 else 'DENIED')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(),in.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 (b < a) { a = b; return 1; } return 0; }

using ll = long long;
using namespace std;
// cout << fixed << setprecision(10）<<  << endl;

int main() {
    int n; cin >> n;
    int count = 0;
    rep(i,n) {
        int a, b; cin >> a >> b;
        if (a == b) count++;
        else count = 0;
        if (count == 3) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
    int a[3][3], N, t[3][3];
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            scanf("%d", &a[i][j]);
            t[i][j] = 0;
        }
    }
    scanf("%d", &N);
    int b[N];
    for (int k = 0; k < N; k++)
    {
        scanf("%d", &b[k]);
    }

    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])
                {
                    t[i][j] = 1;
                }
            }
        }
    }

    int ans = 0;

    for (int i = 0; i < 3; i++)
    {
        if (t[i][0] == 1 && t[i][0] == t[i][1] && t[i][2] == t[i][0])
        {
            ans = 1;
        }
    }
    for (int j = 0; j < 3; j++)
    {
        if (t[0][j] == 1 && t[0][j] == t[1][j] && t[2][j] == t[0][j])
        {
            ans = 1;
        }
    }
    if (t[0][0] == 1 && t[0][0] == t[1][1] && t[1][1] == t[2][2])
    {
        ans = 1;
    }
    if (t[0][2] == 1 && t[0][2] == t[1][1] && t[1][1] == t[2][0])
    {
        ans = 1;
    }
    if (ans > 0)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 256