akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
struct gr{
    vector<int> adj;
    bool vis;
    gr(){
        vis = false;
    }
}t[100005];
deque<int> q;

int main(){
    bool startfnd = false, endfnd= false;

    int n, m;
    cin >> n >> m;
    for(int i =0 ;i < m ;i++){
        int a,b;
        cin >> a >> b;
        t[a].adj.push_back(b);
        t[b].adj.push_back(a);
    }
    t[1].vis=true;
    q.push_front(1);
    bool fnd = true;
    while(fnd){
        int cnt = 0;
        int v = q.front();
        for(int i = 0; i < t[v].adj.size(); i++){
            if(!t[t[v].adj[i]].vis){
                t[t[v].adj[i]].vis=true;
                q.push_front(t[v].adj[i]);
                cnt++;
                break;
            }
        }
        if(!cnt)fnd=false;
    }

    fnd = true;
    while(fnd){
        int cnt = 0;
        int v = q.back();
        for(int i = 0; i < t[v].adj.size(); i++){
            if(!t[t[v].adj[i]].vis){
                q.push_back(t[v].adj[i]);
                t[t[v].adj[i]].vis=true;
                cnt++;
                break;
            }
        }
        if(!cnt)fnd=false;
    }
    cout << q.size()<< endl;
    while(q.size()){
        cout << q.back()<< " ";
        q.pop_back();
    }

    return 0;
}


Measured memory_bytes: 7424
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (n); ++i)

ll GCD(ll x, ll y) {
  if (x > y) swap(x, y);
  while (x) {
    ll z = x;
    x = y%x;
    y = z;
  }
  return y;
}

ll LCM(ll x, ll y) {
  ll g = GCD(x, y);
  return x / g * y;
}

string S, T;

int main() {

  ll N, M;
  cin >> N >> M;
  ll L = LCM(N,M);
  cin >> S >> T;

  REP(i, N) {
    ll x = L/N*i;
    if (x%(L/M) == 0 && S[i] != T[x/(L/M)]) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << L << endl;


  return 0;

}

Measured memory_bytes: 512
#include<stdio.h>

int main(){

  int i;
  int one, zero, minus_one;
  int select;
  int result = 0;

  scanf("%d %d %d %d", &one, &zero, &minus_one, &select);

  for(i = 0; i < select; i++){
    if(i < one){
      result += 1;
      continue;
    }
    else if(i < one + zero){
      continue;
    }
    else{
      result -= 1;
    }
  }
  printf("%d", result);
}

Measured memory_bytes: 1736
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function bfsTree(e::Array{Array{Int,1}},p)
	n=length(e)
	vst=zeros(Int,n)
	vst.-=1
	vst[p]=0
	vc=1
	stack=Int[]
	for i in 1:length(e[p])
		push!(stack,e[p][i])
		vst[e[p][i]]=1
		vc+=1
	end
	bef=0
	now=p
	while !isempty(stack)&&vc<n
		now=shift!(stack)
		for i in 1:length(e[now])
			if vst[e[now][i]]<0
				push!(stack,e[now][i])
				vst[e[now][i]]=vst[now]+1
				vc+=1
			end
		end
	end
	vst
end

function main()
	n = readline() |> parseInt
	e = [Int[] for i in 1:n]
	for i in 1:n-1
		a,b = readline() |> split |> parseMap
		push!(e[a],b)
		push!(e[b],a)
	end
	f = bfsTree(e,1)
	u = indmax(f)
	g = bfsTree(e,u)
	d = maximum(g)
	println(d%3==1?"Second":"First")
end
main()


Measured memory_bytes: 169420
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"h,w,n=map(int,input().split())\n"
"r,c=map(int,input().split())\n"
"s=input()\n"
"t=input()\n"
"xr=xl=xd=xu=yr=yl=yd=yu=0\n"
"for i in range(n):\n"
"    xr+=s[i]=='R'\n"
"    xl+=s[i]=='L'\n"
"    xd+=s[i]=='D'\n"
"    xu+=s[i]=='U'\n"
"    if w-c-(xr-yl)<0 or c-1-(xl-yr)<0 or h-r-(xd-yu)<0 or r-1-(xu-yd)<0:\n"
"        print('NO')\n"
"        break\n"
"    yr+=t[i]=='R'\n"
"    yr-=w-c-(yr-xl)<0\n"
"    yl+=t[i]=='L'\n"
"    yl-=c-1-(yl-xr)<0\n"
"    yd+=t[i]=='D'\n"
"    yd-=h-r-(yd-xu)<0\n"
"    yu+=t[i]=='U'\n"
"    yu-=r-1-(yu-xd)<0\n"
"else:\n"
"    print('YES')\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 7236
/*
	##############################
	#  Author: Pratyush Gaurav   #
	#  College: NIT ROURKELA     #
	##############################
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli > plli;
typedef vector<lli> vlli;
typedef vector<plli > vplli;

#define rep(i,a) for(i = 0 ; i < a ; i++)
#define repr(i,a) for(i = a ; i >= 0 ; i--)
#define REP(i,a,b) for(i = a ; i <= b ; i++)
#define REPR(i,a,b) for(i = a ; i >= b ; i--)
#define mem(a,b)memset(a,b,sizeof(a))
#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a)*((b)/gcd(a,b)))
#define sqr(x) (x)*(x)
#define all(a) a.begin(),a.end()

#define endl '\n'

const long long INF = 2000000000000;
const long long MOD = 1000000007;
const long long MAXN = 100005;

lli dx[]={0,0,-1,1,-1,-1,1,1};
lli dy[]={1,-1,0,0,1,-1,-1,1};

void solve()
{
    lli i,n;
    cin >> n;
    vlli v(n+2,0);
    lli tot = 0;
    rep(i,n) {
        cin >> v[i+1];
        tot += abs(v[i+1] - v[i]);
    }
    tot += abs(v[n]);

    REP(i,1,n) {
        lli ans = tot - abs(v[i] - v[i-1]) - abs(v[i+1]-v[i]) + abs(v[i+1] - v[i-1]);
        cout << ans << endl;
    }
}
int main()
{
	opt;
	lli t = 1;
	while(t--)
	    solve();
	return 0;
}










Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define MOD 1000000007
#define pb push_back
#define cy cout<<"Yes\n"
#define cn cout<<"No\n"
typedef unsigned long long int ull;
typedef long long int ll;

int a[500005];
int main()
{
    int n;
    cin>>n;
    if(n%1000)
    {
        int div=n/1000;
        cout<<(1000*(div+1))-n<<endl;
    }
    else
        cout<<0<<endl;
}


Measured memory_bytes: 3632
n, m = map(int, input().split())
cnt = [0 for _ in range(n)]
for _ in range(m):
    a, b = map(int, input().split())
    cnt[a-1] += 1
    cnt[b-1] += 1
for c in cnt:
    if c % 2:
        print("NO")
        quit()
print("YES")

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

public class Main {

	class Edge {
		int from, to, mark;

		public Edge(int from, int to, int mark) {
			super();
			this.from = from;
			this.to = to;
			this.mark = mark;
		}

		@Override
		public String toString() {
			return "Edge [from=" + from + ", to=" + to + ", mark=" + mark + "]";
		}
		
	}
	
	List<Edge>[] graph;
	
	int dfs(int u, int p) {
		int xor = 0;
		for (int t = 0; t < graph[u].size(); t++) {
			Edge e = graph[u].get(t);
			int to = u ^ e.from ^ e.to;
			if (to == p) {
				continue;
			}
			xor ^= e.mark;
			e.mark ^= dfs(to, u);
		}
		return xor;
	}
	
	void solve() {
		int n = in.nextInt();
		graph = new List[n];
		for (int i = 0; i < n; i++) {
			graph[i] = new ArrayList<>();
		}
		
		Edge[] e = new Edge[n - 1];
		for (int i = 0; i < n - 1; i++) {
			e[i] = new Edge(in.nextInt(), in.nextInt(), in.nextInt());
			graph[e[i].from].add(e[i]);
			graph[e[i].to].add(e[i]);
		}
		dfs(0, -1);
		int allMask = 0;
		int result = 0;
		for (int i = 0; i < n - 1; i++) {
			int bit = e[i].mark;
			if (bit == 0) {
				result++;
				continue;
			}
			if ((allMask & (1 << bit)) != 0) {
				result++;
			}
			allMask ^= 1 << bit;
		}
		int[] xor = new int[1 << 16];
		for (int i =0 ; i < 1 << 16; i++) {
			for (int j = 0; j < 16; j++ ) {
				if ((i & (1 << j)) != 0) {
					xor[i] ^= j;
				}
			}
		}
		int[] dp = new int[1 << 16];
		for (int mask = 1; mask < 1 << 16; mask++) {
			for (int submask = mask; submask > 0; submask = (submask - 1) & mask) {
				if (xor[submask] == 0) {
					dp[mask] = Math.max(dp[mask], dp[mask ^ submask] + 1);
				}
			}
		}
		out.println((n - 1) - (dp[allMask] + result));
	}

	FastScanner in;
	PrintWriter out;

	void run() {
		in = new FastScanner();
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

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

		public int nextInt() {
			return Integer.parseInt(nextToken());
		}

		public long nextLong() {
			return Long.parseLong(nextToken());
		}

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

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 65708
#include <bits/stdc++.h>
using namespace std;
#define int long long

int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int h, w;
	cin >> h >> w;
	if(h == 1 || w == 1) {
		return !(cout << 1);
	}
	cout << ((w+1)/2)*((h+1)/2) + w/2*(h/2); 
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n; cin >> n;
    int w[n+1];
    for (int i=0; i<n; i++) cin >> w[i];
    int s1, s2, ans=1000000000;
    for (int i=0; i<n-1; i++){
        s1=0, s2=0;
        for(int j=0; j<i+1; j++){
            s1 += w[j];
        }
        for(int k=i+1; k<n; k++){
            s2 += w[k];
        }
        ans = min(ans, abs(s1-s2));
    }
    cout << ans << endl;
}

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

int main()
{
    int A, N, N2;

    cin >> N;
    cin >> A;
    N2 = N % 500;

    if (N2 <= A){
        cout << "Yes" << endl;
        return (0);
    }
    else {
        cout << "No" << endl;
        return (0);
    }
}


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

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

template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf=1e9;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

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

	string c="",d="";
	for (int i = 0; i < b-'0'; i++){
		c+=a;
	}
	for (int i = 0; i < a-'0'; i++){
		d+=b;
	}

	if(c<d){
		cout<<c<<endl;
	}else{
		cout<<d<<endl;
	}


	return 0;
}


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


int main(void) {

    long X, Y;
    cin >> X >> Y;

    if (Y % 2 == 0 && 2 * X <= Y && Y <= 4 * X) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	while(cin>>n,n){
		string str;
		bool right=0,left=0;
		int ans=0;
		for(int i=0,now=1;i<n;i++){
			cin>>str;
			if(str=="lu")left=1;
			if(str=="ru")right=1;
			if(str=="ld")left=0;
			if(str=="rd")right=0;
			if(now==right&&right==left){
				ans++;
				now=(now+1)%2;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1208
#include <stdio.h>
#include <stdlib.h>

int cmp_int(void *a, void *b);

int main(){
    int N;
    long long sum = 0;
    scanf("%d", &N);

    int a[3 * N];
    for(int i = 0; i < 3 * N; i++){
        scanf("%d", &a[i]);
    }

    qsort(a, 3 * N, sizeof(int), cmp_int);

    for(int i = 0; i < N; i++){
        sum += a[2 * i + 1];
    }
    printf("%llu\n", sum);
    return 0;
}

int cmp_int(void *a, void *b){
    return *(int*)b - *(int*)a;
}

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

int main(void){
    int H, W;
    cin >> H >> W;

    vector<string> map(H);
    for(int i=0; i<H; i++){
        string S;
        cin >> S;
        map.at(i) = S;
    }

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(map.at(i).at(j) == '.'){
                int counter=0;
                
                if(i-1>=0 && j-1>=0 && map.at(i-1).at(j-1) == '#') counter++;
                if(i-1>=0 && map.at(i-1).at(j) == '#') counter++;
                if(i-1>=0 && j+1<W && map.at(i-1).at(j+1) == '#') counter++;

                if(j-1>=0 && map.at(i).at(j-1) == '#') counter++;
                if(j+1<W && map.at(i).at(j+1) == '#') counter++;

                if(i+1<H && j-1>=0 && map.at(i+1).at(j-1) == '#') counter++;
                if(i+1<H && map.at(i+1).at(j) == '#') counter++;
                if(i+1<H && j+1<W && map.at(i+1).at(j+1) == '#') counter++;
                
                switch(counter){
                    case 0:
                        map.at(i).at(j)='0';
                        break;
                    case 1:
                        map.at(i).at(j)='1';
                        break;
                    case 2:
                        map.at(i).at(j)='2';
                        break;
                    case 3:
                        map.at(i).at(j)='3';
                        break;
                    case 4:
                        map.at(i).at(j)='4';
                        break;
                    case 5:
                        map.at(i).at(j)='5';
                        break;
                    case 6:
                        map.at(i).at(j)='6';
                        break;
                    case 7:
                        map.at(i).at(j)='7';
                        break;
                    case 8:
                        map.at(i).at(j)='8';
                        break;
                    default:
                        break;
                }
            }
        }
    }

    for(int i=0; i<H; i++){
        cout << map.at(i) << endl;
    }

}

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

int main(void) {
    long long int N,M;
    cin >> N >> M;

    long long int H[N+1];

    bool A[N+1];

    for(int i=1; i<=N; i++){
      cin >> H[i];
      A[i] = true;
    }


    long long int a,b;
    for(int i=0; i<M; i++){
      cin >> a >> b;
      if(H[a]<H[b]){
        A[a] = false;
      }
      else if(H[a]>H[b]){
        A[b] = false;
      }
      else{
        A[a] = false;
        A[b] = false;
      }
    }

    int cnt = 0;

    for(int i=1; i<=N; i++){
      if(A[i]==true)
        cnt++;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 4452
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){
  Int N;
  cin>>N;
  const Int MAX=3500;
  for(Int h=1;h<=MAX;h++){
    for(Int n=1;n<=MAX;n++){
      Int a=N*h*n;
      Int b=4*h*n-N*n-N*h;
      if(b<=0) continue;
      if(a%b) continue;
      Int w=a/b;
      cout<<h<<" "<<n<<" "<<w<<endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

//最大公約数
template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}


int main(){
    long long N; cin >> N;
    long long taxi = 10000000000000000;
    for (int i = 0; i < 5; i++) {
        long long input;
        cin >> input;
        taxi = min(taxi, input);
    }
    long long ans = (N + taxi - 1) / taxi + 4;
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
int gg(int p,int k,vector<int> w,int n){
  int i=0;
  for(int j=0;j<k;j++){
    int s=0;
    while(s+w[i]<=p){
      s+=w[i];
      i++;
      if(i==n){
        return n;
      }
    }
  }
  return i;
}
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> w(n);
  for(int i=0;i<n;i++){
    cin>>w[i];
  }
  int left=0;
  int right=1000000000;
  int mid;
  while(right-left>1){
    mid=(left+right)/2;
    int v=gg(mid,k,w,n);
    if(v>=n){
      right=mid;
    }
    else{
      left=mid;
    }
    
  }
  cout<<right<<endl;
}
  


Measured memory_bytes: 3652
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    a, b, c, d = I2()
    #bまでのc,dの倍数 - a-1以下のc,dの倍数 重複分を加算
    cnt = b - a + 1
    cnt -= b//c
    cnt += (a-1)//c
    cnt -= b//d
    cnt += (a-1)//d
    cnt += b//(c*d//math.gcd(c,d))
    cnt -= (a-1)//(c*d//math.gcd(c,d))
    print(cnt)


Measured memory_bytes: 9020
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define mod 924844033
ll dp[2005][2005][2][2];
ll t[2005][2005];
ll DP[2005][2005];
ll f[2005];
int n,k;
int main()
{
	cin >> n >> k;
	dp[0][0][0][0] = 1;
	for(int i=0;i<n;i++){
		for(int j=0;j<=i;j++){
			for(int k=0;k<2;k++){
				dp[i+1][j][k][0] += dp[i][j][0][k]+dp[i][j][1][k];
				while(dp[i+1][j][k][0]>=mod) dp[i+1][j][k][0] -= mod;
				if(i){
					dp[i+1][j+1][k][0] += dp[i][j][0][k];
					while(dp[i+1][j+1][k][0]>=mod) dp[i+1][j+1][k][0] -= mod;
				}
				dp[i+1][j+1][k][1] += dp[i][j][0][k]+dp[i][j][1][k];
				while(dp[i+1][j+1][k][1]>=mod) dp[i+1][j+1][k][1] -= mod;
			}
		}
	}
	for(int i=0;i<=n;i++){
		for(int j=0;j<=i;j++){
			t[i][j] = (dp[i][j][0][0]+dp[i][j][1][0])%mod;
		}
	}
	DP[0][0] = 1;
	for(int i=1;i<=k;i++){
		int x = n/k; if(n%k>=i) x++;
		for(int a=0;a<=n;a++){
			if(!DP[i-1][a]) continue;
			for(int j=0;j<=x;j++){
				DP[i][a+j] += (DP[i-1][a] * t[x][j] % mod);
				while(DP[i][a+j]>=mod) DP[i][a+j]-=mod;
			}
		}
	}
	ll ret = 0; f[0] = 1;
	for(int i=1;i<=n;i++) f[i] = f[i-1]*i%mod;
	
	for(int j=0;j<=n;j++){
		ll sum = DP[k][j];
		sum *= f[n-j]; sum %= mod;
		if(j%2 == 0) ret = (ret+sum)%mod;
		else ret = (ret+mod-sum)%mod;
	}
	ret = ( (ret%mod+mod) % mod );
	cout << ret << endl;
}

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

int main(){
    int a,b;
    cin >> a >> b;
    for(int c=1;c<=3;c++){
        if((a*b*c)%2!=0){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}



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


int main() {
	int N,K;
  	cin>> N >> K;
  	vector<int> H(N);
   	long long int ans=0;
 	int max=0;
  	
  
  	for(int i=0;i<N;i++){
     	 cin>>H.at(i);
    }
  	
  	sort(H.begin(),H.end());
    reverse(H.begin(),H.end());
      
    for(int i=0;i<N;i++){
      	if(i>=K){
     	 	ans+=H.at(i);
        }
    }
    
    cout<<ans<<endl;
  	
 
}

Measured memory_bytes: 1024
// D - Coloring Dominoes
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define MOD 1000000007

ll solve(int N, string &S1, string &S2){

	ll ans = 6;//ドミノが横のとき
	int start = 2;
	bool isPreVertical = false;//前回の状態: 縦: true, 横: false
	if(S1[0] == S2[0]){// 縦
		isPreVertical = true;
		ans = 3;
		start = 1;
	}

	rp(i, start, N){
		if(S1[i] == S2[i]){// 縦
			if(isPreVertical) ans = ans * 2 % MOD;
			else ans = ans * 1 % MOD;
			isPreVertical = true;
		}
		else{//横
			if(isPreVertical) ans = ans * 2 % MOD;
			else ans = ans * 3 % MOD;
			isPreVertical = false;
			i++;
		}
	}

	return ans;
}

int main(){
	int N; string S1,S2;
	cin>>N>>S1>>S2;
	cout<< solve(N, S1, S2) <<endl;
}

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

int main() {
	int n;cin>>n;
	vector<double> x(n),y(n);
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i];
	}
	double ans=0;
	double def=1;
	for(int i=1;i<=n-2;i++){
		def*=i;
	}
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			double d=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
			ans+=d*2;
		}
	}
//	for(int i=1;i<=n;i++){
//		ans/=double(i);
//	}
	ans/=n;
	cout<<setprecision(13)<<ans<<endl;
	return 0;
}


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

int main() {
	stack<int> st;
	char ch[100];
	while(cin >> ch) {
		int a, b;
		if(ch[0] == '+') {
			a = st.top();
			st.pop();
			b = st.top();
			st.pop();
			st.push(b + a);
		} else if(ch[0] == '-') {
			a = st.top();
			st.pop();
			b = st.top();
			st.pop();
			st.push(b - a);
		} else if(ch[0] == '*') {
			a = st.top();
			st.pop();
			b = st.top();
			st.pop();
			st.push(b * a);
		} else st.push(atoi(ch));
	}
	cout << st.top() <<endl;
	return 0;
}

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int n,h[200005],a[200005];
int bit[200005];
void update(int x,int y){
    for(;x<=n;x+=x&(-x)) bit[x]=max(bit[x],y);
}
int query(int x){
    int res=0;
    for(;x>0;x-=x&(-x)) res=max(res,bit[x]);
    return res;
}
void solve(){
    int ans=0;
    cin>>n;
    rep(i,1,n+1) cin>>h[i];
    rep(i,1,n+1) cin>>a[i];
    rep(i,1,n+1){
        int cur=query(h[i])+a[i];
        ans=max(ans,cur);
        update(h[i],cur);
    }
    cout<<ans<<endl;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<climits>

#define IINF (INT_MAX)
#define ULLINF (ULLONG_MAX)

using namespace std;

typedef unsigned long long ull;
typedef pair<ull,ull> ull2;

ull N;
string M;

map<ull,int> prime_factor(ull n){
  map<ull,int> res;
  for(int i=2;i*i<=n;i++){
    while(n % i == 0){
      ++res[i];
      n /= i;
    }
  }
  if(n != 1ULL)res[n] = 1ULL;
  return res;
}

ull StoULL(){
  ull ret = 0;
  for(int i=0;i<M.size();i++){
    ret *= N;
    ull tmp = (('0'<=M[i]&&M[i]<='9')?(M[i]-'0'):(M[i]-'A')+10ULL);
    ret += tmp;
  }
  return ret;
}

ull calc(ull value,ull2 tmp){
  ull ret = 0;
  ull pf = tmp.first;
  ull denom = tmp.second;
  while(value){
    ret += value / pf;
    value /= pf;
  }
  return ret/denom;
}

void compute(){
  map<ull,int> ppf = prime_factor(N);
  vector<ull2> pf;

  for(map<ull,int>::iterator it = ppf.begin() ; it != ppf.end() ; it++ ){
    pf.push_back(ull2((it->first),(it->second)));
  }

  ull value = StoULL();
  //cout << "value = " << value << endl;
  ull ans = ULLINF;

  for(int i=0;i<pf.size();i++){
    ans = min(ans,calc(value,pf[i]));
  }

  cout << ans << endl;

}

int main(){
  //cout << ULLINF << endl;
  while(cin >> N >> M,(N!=0 || M!="0")){

    compute();

  }
  return 0;
}

Measured memory_bytes: 1196
//#typedef int ll
// include
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <tuple>
// namespace
using namespace std;
// typedef
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pint;
// const
const int inf = 1e9;
const int mod = ((int)1e9 + 7);
// loop
#define rep(i, n) for(int i = 0, i##_mx = n; i < i##_mx; i++)
#define brep(i, b, e) for(int i = b; i < e; i++)
#define erep(i, b, e) for(int i = b; i <= e; i++)
#define rrep(i, b, e) for(int i = b; i >= e; i--)
// STL
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
// function
int gcd(int a, int b){return b ? gcd(b, a % b) : a;}
void prime(vint& v, int n){brep(i, 2, n){bool fg = false; for(auto e : v){if(i % e == 0){fg = true;}} if(fg){continue;} v.pb(i);}}

signed main(){
    int n, m;
    cin >> n >> m;
    
    bool sl[11][11] = {{false}};
    erep(i, 1, m){
        int k;
        cin >> k;
        rep(j, k){
            int s;
            cin >> s;
            sl[i][s] = true;
        }
    }
    
    int p[11] = {false};
    erep(i, 1, m){
        cin >> p[i];
    }
    
    int ans = 0;
    rep(i, pow(2, n)){
        int cpy = i;
        int check[11] = {false};
        erep(j, 1, m){
            check[j] = p[j];
        }
        int cnt = 1;
        while(cpy){
            if(cpy % 2){
                erep(j, 1, m){
                    check[j] += sl[j][cnt];
                }
            }
            cnt++;
            cpy /= 2;
        }
        
        bool flg = true;
        erep(j, 1, m){
            if(check[j] % 2){
                flg = false;
                break;
            }
        }
        if(flg){
            ans++;
        }
    }
    
    cout << ans << endl;
    
	return 0;
}


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

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
     int max, ave, min;

if (a > b)
    {
             if (a > c)
             {
                      if (b > c)
                      {
                               max = a;
                               ave = b;
                               min = c;
                      }
                      else
                      {
                               max = a;
                               ave = c;
                               min = b;
                      }
             }
             else
             {
                      max = c;
                      ave = a;
                      min = b;
             }
    }
    else
    {
             if (b > c)
             {
                      if (a > c)
                      {
                               max = b;
                               ave = a;
                               min = c;
                      }
                      else
                      {
                               max = b;
                               ave = c;
                               min = a;
                      }
             }
             else
             {
                      max = c;
                      ave = b;
                      min = a;
             }
    }


        cout<<min<< " "<<ave<<" "<<max<< endl;
    return 0;
}









Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


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

    ll l = -inf;
    ll r = inf;
    while (l + 1 < r) {
        ll M = (l + r) / 2;
        ll cnt = 0;
        for (int i = 0; i < n; i++) {
            int l = i, r = n;
            while (l + 1 < r) {
                ll m = (l + r) / 2;
                if (a[i] * a[m] <= M) {
                    (a[i] > 0 ? l = m : r = m);
                } else {
                    (a[i] > 0 ? r = m : l = m);
                }
            }
            if (a[i] > 0) cnt += l - i;
            else cnt += n - r;
        }
        (cnt < k) ? l = M : r = M;
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String s = in.readLine();
    String t = in.readLine();
    String s_rt = "";
    boolean flg = false;
    for(int i=0; i<s.length(); i++) {
      s_rt = s.substring(s.length()-i,s.length()) + s.substring(0,s.length()-i);
      if(s_rt.equals(t))
        flg = true;
    }
    System.out.println(flg==true?"Yes":"No");
  }
}

Measured memory_bytes: 37188
#include <iostream>
#include <cstdio>
#define rep(i,n) for(int i=0;i<n;i++)
//#define int long long
using namespace std;

#define INF 999999

int n, m;
int a, b, c;

int cost[100][100];
int mincost[100];
bool used[100];

void init()
{
	rep(i,100) rep(j,100)
	{
		cost[i][j] = INF;
	}
}

int prim()
{
	rep(i,n)
	{
		mincost[i] = INF;
		used[i] = false;
	}

	mincost[0] = 0;
	int res = 0;

	while (true)
	{
		int v = -1;
		rep(u,n)
		{
			if (!used[u] && (v == -1 || mincost[u] < mincost[v])) v = u;
		}

		if (v == -1) break;
		used[v] = true;
		res += mincost[v];

		rep(u,n)
		{
			mincost[u] = min(mincost[u], cost[v][u]);
		}
	}

	return res;
}

int main()
{
	while (true)
	{
		cin >> n >> m;
		if (n == 0 && m == 0) break;

		init();

		rep(i,m)
		{
			cin >> a >> b >> c;
			cost[a][b] = c;
			cost[b][a] = c;
		}

		printf("%d\n", prim());
	}
}

Measured memory_bytes: 1184
#include<bits/stdc++.h>
#define mp make_pair
using namespace std;

const int MAXN = 1e4+10;
typedef long long ll;
typedef pair<ll,ll> PAIR;
ll MOD1=1e9+7,MOD2=1e9+9;

ll cal1[256],cal2[256];
ll init(){
	for(int i='a';i<='z';i++){
		ll ans=1;
		ll n=i-'a'+1;
		ll temp=i-'a'+1;
		while(n){
			if(n&1)	ans*=temp,ans%=MOD1;
			temp*=temp;
			temp%=MOD1;
			n>>=1;
		}
		cal1[i]=ans;
		ans=1,n=i-'a'+1,temp=i-'a'+1;
		while(n){
			if(n&1)	ans*=temp,ans%=MOD2;
			temp*=temp;
			temp%=MOD2;
			n>>=1;
		}
		cal2[i]=ans;
	}
}

int main(){
	init();
	char str1[MAXN],str2[MAXN];
	scanf("%s%s",str1,str2);
	PAIR Hash1[MAXN],Hash2[MAXN];
	int Len1=strlen(str1),Len2=strlen(str2);
	Hash1[0].first=Hash1[0].second=Hash2[0].first=Hash2[0].second=0;
	for(int i=0;i<Len1;i++){
		Hash1[i+1].first=cal1[str1[i]];
		Hash1[i+1].first+=Hash1[i].first;
		Hash1[i+1].first%=MOD1;
		Hash1[i+1].second=cal2[str1[i]];
		Hash1[i+1].second+=Hash1[i].second;
		Hash1[i+1].second%=MOD2;
	}
	for(int i=0;i<Len2;i++){
		Hash2[i+1].first=cal1[str2[i]];
		Hash2[i+1].first+=Hash2[i].first;
		Hash2[i+1].first%=MOD1;
		Hash2[i+1].second=cal2[str2[i]];
		Hash2[i+1].second+=Hash2[i].second;
		Hash2[i+1].second%=MOD2;
	}
	int M=min(Len1,Len2);
	int i,j,k;
	PAIR p1,p2;
	map<PAIR,bool> MAP;
	for(i=M;i>0;i--){
		MAP.clear();
		for(j=0;j+i<=Len1;j++){
			p1.first=((Hash1[j+i].first-Hash1[j].first)%MOD1+MOD1)%MOD1;
			p1.second=((Hash1[j+i].second-Hash1[j].second)%MOD2+MOD2)%MOD2;
			MAP[p1]=true;
		}
		for(k=0;k+i<=Len2;k++){
					
				p2.first=((Hash2[k+i].first-Hash2[k].first)%MOD1+MOD1)%MOD1;
				p2.second=((Hash2[k+i].second-Hash2[k].second)%MOD2+MOD2)%MOD2;
				if(MAP.count(p2)){
					printf("%d\n",i);
					return 0;
				}
			}
	}
	printf("0\n");
	return 0;
}

Measured memory_bytes: 3772
#include<iostream>
#include<algorithm>
using namespace std;
int num[100010],n;
int Ansb;
namespace Task2{
    int a[100010];
    int r=0;
    void main(){
        for(int i=0;i<n;i++){
            int *p=upper_bound(a,a+r,num[i],greater<int>());
            if(p-a==r)
                r++;
            *p=num[i];
        }
    }
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>num[i];
    Task2::main();
    Ansb=Task2::r;
    cout<<Ansb;
    return 0;
}

Measured memory_bytes: 1024
#define R register
#define ll long long
#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e5 + 5;

namespace IO
{
inline char gc()
{
	static char buf[1 << 18], *fs, *ft;
	return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 18, stdin)), fs == ft) ? EOF : *fs++;
}
inline int read()
{
	register int k = 0, f = 1;
	register char c = gc();
	for (; !isdigit(c); c = gc()) if (c == '-') f = -1;
	for (; isdigit(c); c = gc()) k = (k << 3) + (k << 1) + (c - '0');
	return k * f;
}
}

namespace ARC094E
{
int n, flag, m = 0x3f3f3f3f, a, b;
ll sum = 0;

inline void solve()
{
	using namespace IO;
	n = read();
	for (R int i = 1; i <= n; ++i)
	{
	    a = read(), b = read();
	    if(a != b) flag = 1;
	    if(b < a) m = min(m, b);
	    sum += b;
	}
	if(flag) printf("%lld\n", sum - m);
	else printf("%lld\n", 0);
}
}
int main()
{
	return ARC094E::solve(), 0;
}

Measured memory_bytes: 512
#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 INF (1LL<<59)
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define emp emplace
#define whoami(x) cerr<<#x<<" "<<x<<"\n";
#define mp make_pair
#define ins insert
#define sz size

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;

const int MOD = 1000000007;

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

struct h_llint {
  static uint64_t splitmix64(uint64_t x) {    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

struct h_pair{
  size_t operator()(const PLL&x)const{
    return hash<ll>()(((ll)x.ff)^(((ll)x.ss)<<32));
  }
};

typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;
typedef set<int> SI;
typedef set<ll> SL;
//ordered_set = order_of_key(.)
//ordered_set = find_by_order(.)
typedef ordered_set<int> OSI;
typedef ordered_set<ll> OSL;
typedef ordered_multiset<int> MOSI;
typedef ordered_multiset<ll> MOSL;
typedef unordered_map<ll, int, h_llint> UMLI;
typedef unordered_map<ll, ll, h_llint> UMLL;
typedef unordered_map<PLL, int, h_pair> UMPI;
typedef unordered_map<PLL, ll, h_pair> UMPL;

int ar[MV];
ll arr[MV];

void solve(int T)
{
	string s;
	cin>>s;
	ll td = 0, p10 = 1;
	arr[td]++;
	ll ax = 0;
	for(int i=(int)s.sz()-1;i>=0;i--)
	{
		td = (td + p10 * (s[i] - '0'))%2019;
		p10 = (p10 * 10)%2019;
		ax += arr[td];
		arr[td]++;
	}
	cout<<ax<<"\n";
	return;
}

int main(void)
{
	FLASH();
	int T;
	T = 1;

// #ifndef ONLINE_JUDGE
// 	time_t time_t1, time_t2;
// 	time_t1 = clock();
// #endif

	//cin>>T;
	while(T--)
	solve(T);

// #ifndef ONLINE_JUDGE
// 	time_t2 = clock();
// 	SETF();
// 	cout<<"Time taken: "<<setprecision(7)<<(time_t2 - time_t1)/(double)CLOCKS_PER_SEC<<"\n";
// 	UNSETF();
// #endif

	return 0;
}

Measured memory_bytes: 3800
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

signed main()
{
  int N, M;
  cin >> N >> M;
  priority_queue<int> q;
  REP(i, N){
    int x;
    cin >> x;
    q.push(x);
  }
  REP(i, M){
    int tmp = q.top();
    q.pop();
    int res = tmp / 2;
    q.push(res);
  }
  int ans = 0;
  REP(i, N){
    int tmp = q.top();
    q.pop();
    ans += tmp;
  }
  cout << ans << endl; 
}

Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).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; }
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  ll N, K, S; std::cin >> N >> K >> S;

  for(int i=0; i<N; i++) {
    if ( i < K ) std::cout << S << " ";
    else {
      if ( S == 1e9 ) std::cout << S-1 << " ";
      else std::cout << S+1 << " ";
    }
  }
  std::cout << std::endl;
  return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
typedef long long ll;

using namespace std;

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

  int h = s / 3600;
  s %= 3600;
  int m = s / 60;
  s %= 60;

  cout << h << ":" << m << ":" << s << "\n";

  return(0);
}



Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
typedef long long ll;

using namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  if (N % K == 0) cout << 0;
  else cout << 1;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
#define REPI(i, a, n)	for(ll (i)=(a);(i)<(int)(n);(i++))
#define REP(i,n) REPI(i,0,n)
#define REP1(i,n) for(ll (i)=1;(i)<=(n);(i++))
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
 
struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;
 
	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
 
template<typename T>
int contains(std::vector<T> vec, int number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(a % b, b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll fact(ll n) {
	ll m;
	if (n == 0) {
		return 1;
	}
	m = fact(n - 1);
	return n * m;
}
 
ll Combination(unsigned long long n, unsigned long long r) {
	if (r * 2 > n) r = n - r;
	uintmax_t dividend = 1;
	uintmax_t divisor = 1;
	for (unsigned int i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
 
struct vec {
	ll x, y;
 
	bool operator == (const vec &v) const{
		return x == v.x && y == v.y;
	}
 
};
 
namespace std {
	template<>
	class hash<vec> {
	public:
		size_t operator () (const vec& p) const { return p.x%SIZE_MAX; }
	};
}
 
int main() {
	int N, M;
	cin >> N >> M;
	int c = ((N * (N - 1)) / 2) + ((M * (M - 1)) / 2);
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#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;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {

    int x,k; cin >>k>>x;

    for (int i = 1; i < k*2; i++) {
        cout << x - k + i;
        if (i < 2*k-1) {
            cout << " ";
        } 
    }
    cout << endl;

    return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(long long i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    long long n;
    string s;
    cin >> n;
    long long ans = 0;
    long long topb = 0;
    long long downa = 0;
    long long cntt = 0;
    bool fl = true;
    rep(i,n){
        cin >> s;
        rep(j,s.size()-1){
            if(s[j] == 'A' && s[j+1] == 'B'){
                ans++;
            }
        }
        if(s[0] == 'B'){
            topb++;
            fl = false;
        }
        if(s[s.size()-1] == 'A'){
            if(fl){
                downa++;
            }
            else{
                topb--;
                cntt++;
            }
        }
        fl = true;
    }
    long long plus;
    if(downa == 0){
        if(topb == 0){
            if(cntt == 0){
                plus = 0;
            }
            else{
                plus = cntt-1;
            }
        }
        else{
            plus = cntt; 
        }
    }
    else{
        if(topb == 0){
            plus = cntt;
        }
        else{
            plus = cntt+1+min(topb-1,downa-1);
        }
    } 
    cout << plus+ans << endl;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    vector<ll> B(2*N);
    REP(i, N) B[i] = A[i];
    REP(i, N) B[i+N] = A[i];
    map<ll, ll> mp;
    REP(i, N) mp[A[N-1-i]] = N-1-i;
    vector<ll> next(N);
    REP(i, N){
    	next[N-1-i] = mp[A[N-1-i]];
    	mp[A[N-1-i]] = N-1-i;
    }

    ll now = 0;
    ll kai = 0;
    while(1){
    	ll ne = next[now];
    	if(ne <= now) kai++;
    	now = ne+1;
    	if(ne == N-1) break;
    }
    kai++;

    ll L = K%kai;
    //dump(kai)
    //dump(L)

    now = 0;
    kai = 0;
    while(1){
    	ll ne = next[now];
    	if(ne <= now) kai++;
    	if(kai >= L){
    		kai--;
    		break;
    	}
    	now = ne+1;
    }

    //dump(now)
    //dump(kai)

    vector<ll> cnt(202020, 0);
    deque<ll> dq;
    while(1){
    	ll kouho = A[now];
    	if(cnt[kouho] > 0){
    		while(1){
    			ll ketu = dq.back();
    			dq.pop_back();
    			cnt[ketu]--;
    			if(ketu == kouho) break;
    		}
    	}else{
    		dq.push_back(kouho);
    		cnt[kouho]++;
    	}
    	if(now == N-1 && kai == L-1) break;
    	/*
    	for(auto x: dq){
    		cout << x  << " ";
    	}
    	cout << endl;
    	*/
    	now = (now + 1)%N;
    	if(now == 0) kai++;
    }

    for(auto x: dq){
    		cout << x  << " ";
    	}
    cout << endl;

    return 0;
}

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

int a[10][10], b[10][10], c[10][10];
int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };
int main() {
	int n; scanf("%d", &n);
	rep(i, n) {
		rep(i, 10)rep(j, 10)scanf("%d", &a[i][j]);
		rep(i, 1 << 10) {
			rep(j, 10)rep(k, 10)b[j][k] = a[j][k];
			memset(c, 0, sizeof(c));
			rep(j, 10)rep(k, 10) {
				if (!j) {
					if (i >> k & 1)continue;
				}
				else if (!b[j - 1][k])continue;
				c[j][k] = 1; b[j][k] = !b[j][k];
				rep(t, 4) {
					int nx = j + dx[t], ny = k + dy[t];
					if (0 <= nx&&nx < 10 && 0 <= ny&&ny < 10)b[nx][ny] = !b[nx][ny];
				}
			}
			bool ok = true;
			rep(j, 10)rep(k, 10) {
				if (b[j][k]) { ok = false; break; }
			}
			if (!ok)continue;
			rep(j, 10) {
				rep(k, 10) {
					if (k)printf(" ");
					printf("%d", c[j][k]);
				}
				printf("\n");
			}
		}
	}
}

Measured memory_bytes: 3148
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(1, 1E8); \
                 auto rnd = bind(__dis, __gen)

const int INF = 1E18;
const int mod = 1E9 + 7;

int32_t main() {
    fastIO();
    
    int a, b;
    cin >> a >> b;
    cout << 100 << " " << 100 << "\n";
    
    vector<string> MAP1(50, string(100, '#')), MAP2(50, string(100, '.'));
    for (int i = 1; i <= 99; i += 2) {
        for (int j = 1; j <= 47; j += 2) {
            if (a > 1) --a, MAP1[i][j] = '.';
            if (b > 1) --b, MAP2[i][j] = '#';
        }
    }
    
    for (auto str : MAP1) cout << str << "\n";
    for (auto str : MAP2) cout << str << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int a[4] = {0,0,0,0};
    int n; cin >> n;
    for(int i = 0; i < n; i++)
    {
        int x; cin >> x;
        a[x%4]++;
    }

    int four = a[0];
    int not_four = a[1]+a[3]+(a[2] > 0 ? 1 : 0);
    cout<<(not_four <= four+1 ? "Yes" : "No")<<endl;
    return 0;
}

Measured memory_bytes: 3640