akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int, int>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 1e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<"\n";
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

struct UnionFind {
  vector< int > par;
  UnionFind(int n = 1) {
    init(n);
  }

  void init(int n = 1) {
    par.resize(n);
    for(int i = 0; i < n; i++)
      par[i] = -1;
  }
  
  int root(int n) {
    if (par[n] < 0) return n;
    return par[n] = root(par[n]);
  }

  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;

    return true;
  }

  bool issame(int x, int y) {
    return root(x) == root(y);
  }
};

signed main() {
  INIT;
	VAR(int, n, m);
	vector< int > a(m), b(m);
	REP(i, m) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--;
	}

	int ans = 0;
	REP(i, m) {
		UnionFind uf(n + 1);
		REP(j, m) {
			if (i == j) continue;
			uf.merge(a[j], b[j]);
		}

		set< int > st;
		REP(i, n) {
			st.insert(uf.root(i));
		}

		if (st.size() > 1) ans++;
	}
	
	OUT(ans)BR;
  
  return 0;
}


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

#define ll long long

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

int main()
{
    ll N,A[200010]={},B[200010]={},sum=0;
    cin>>N;

    for(int i=1;i<=N;i++){
        B[i]=0;
    }

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

    for(int i=1;i<=N;i++){
        sum+= B[i]*(B[i]-1)/2;
    }

    for(int i=1;i<=N;i++){
        cout << sum - B[A[i]]*(B[A[i]]-1)/2 + max((B[A[i]]-1),(ll)0)*max((B[A[i]]-1-1),(ll)0)/2<<endl;
    }

    return 0;
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;
using Graph = vector<vector<int>>;

int main(int argc, char *argv[]) {
// 頂点数と辺数
    int N, M; cin >> N >> M;

    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
		a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    // BFS のためのデータ構造
    vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;
    que.push(0); // 0 を橙色頂点にする
	vector<int> nodeIdx(N,0);

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない
			nodeIdx[nv] = v+1;
            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }

    // 結果出力 (各頂点の頂点 0 からの距離を見る)
	cout << "Yes" << endl;	
    for (int v = 1; v < N; ++v) {
		cout << nodeIdx[v] << endl;	
	}

	return 0;
}


Measured memory_bytes: 10576
import java.util.*;

public class Main{

    String line;
    int[][] pqr;
    int idx,cnt;

    void solve(){
        Scanner sc = new Scanner(System.in);

        idx = 0;
        pqr = new int[27][3];
        getPQR(0,new int[3]);

        while(true){
            line = sc.next();
            if(line.equals(".")) break;

            cnt = 0;
            String line2 = line;
            LinkedList<Integer> left = new LinkedList<Integer>();
            for(int i=0; i<27; i++){
                line = line2;
                char[] c = line.toCharArray();
                for(int j=0; j<line.length(); j++){
                    if(c[j]=='P' || c[j]=='Q' || c[j]=='R'){
                        c[j] = (char)(pqr[i][c[j]-'P']+'0');
                    }
                    line = String.valueOf(c);
                }
                for(int j=0; j<line.length(); j++){
                    if(line.charAt(j)=='(') left.add(j);
                    if(line.charAt(j)==')'){
                        int l = left.pollLast();
                        String s = line.substring(l+1,j);
                        String front = line.substring(0,l);
                        String rear = "";
                        if(line.length()>=j+1) rear = line.substring(j+1,line.length());
                        String newS = getAns(s);
                        line = front + newS + rear;
                        j = j-(s.length()-newS.length())-2;
                    }
                }
                if(getAns(line).equals("2")) cnt++;
            }

            System.out.println(cnt);
        }
    }

    String getAns(String s){
        String x = "",y = "";
        boolean and = false,or = false;
        for(int i=0; i<s.length(); i++){
            if(s.charAt(i)=='*'){
                and = true;
                x = s.substring(0,i);
                y = s.substring(i+1,s.length());
            }else if(s.charAt(i)=='+'){
                or = true;
                x = s.substring(0,i);
                y = s.substring(i+1,s.length());
            }
        }

        if(and){
            return getAND(x,y);
        }else if(or){
            return getOR(x,y);
        }else{
            return String.valueOf(getNum(s));
        }
    }

    String getAND(String x,String y){
        int xx = getNum(x);
        int yy = getNum(y);
        return String.valueOf(Math.min(xx,yy));
    }

    String getOR(String x,String y){
        int xx = getNum(x);
        int yy = getNum(y);
        return String.valueOf(Math.max(xx,yy));
    }

    int getNum(String s){
        int ii = 0;
        while(s.charAt(ii)=='-') ii++;

        int n = Integer.parseInt(s.substring(ii,s.length()));
        for(int i=0; i<ii; i++) n = 2-n;

        return n;
    }

    void getPQR(int pos,int[] num){
        if(pos==3){
            for(int i=0; i<3; i++) pqr[idx][i] = num[i];
            idx++;
            return;
        }

        for(int i=0; i<3; i++){
            num[pos] = i;
            getPQR(pos+1,num);
        }
    }

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

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
vector<int> g[100005];
bool vis[100005];
void dfs(int x)
{
	vis[x]=1;
	for(int i=0;i<g[x].size();i++)
		if(!vis[g[x][i]])
			dfs(g[x][i]);
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int x,y,z;
		cin>>x>>y>>z;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	for(int i=1;i<=n;i++)
		if(!vis[i])
		{
			ans++;
			dfs(i);
		}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 8960
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include<cmath>
#include<map>

using namespace std;

long long X,D,N,Y,ans,i,j,K,r;

int main()
{
  cin>>K;
  
  r=7;
  for(i=1;i<10000000;i++)
  {
    r=r%K;
    if(r==0)
    {
      cout <<i;
      return 0;
    }
    else
    {
      r=r*10+7;
    }
  }
  
  cout<<-1;
  
  
  
  
}



Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>
#include<utility>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
typedef pair<int,int> p;

int main(){
	int n;
	while(cin>>n,n){
		p island[n];
		rep(i,n)cin>>island[i].second>>island[i].first;
		sort(island,island+n);
		int w=0;
		bool check=true;
		rep(i,n){
			if((w+island[i].second)<=island[i].first){
				w+=island[i].second;
			}else{
				check=false;
				break;
			}
		}
		cout<<((check)?"Yes":"No")<<endl;
	}
	return 0;
}

Measured memory_bytes: 3036
import sys


def solve():
    sys.setrecursionlimit(2000)
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, x = list(map(int, input().rstrip('\n').split()))
    l = list(map(int, input().rstrip('\n').split()))
    cnt = 1
    t = 0
    for i in range(n):
        t += l[i]
        if t <= x:
            cnt += 1
        else:
            break
    print(cnt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38256
while True:
    H, W = map(int,input().split())
    if H == 0 and W == 0:
        break
    else:
        for i in range(H):
            if i == 0 or i == H-1:
                print("#"*W)
            else:
                print("#","."* (W - 2),"#",sep="")
    print()



Measured memory_bytes: 5632
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using Debug = System.Diagnostics.Debug;
using StructLayoutAttribute = System.Runtime.InteropServices.StructLayoutAttribute;
using FieldOffsetAttribute = System.Runtime.InteropServices.FieldOffsetAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using System.Runtime.CompilerServices;

static class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray();
        int[] counts = new int[n];

        for (int i = 0; i < a.Length; i++) counts[a[i]]++;

        var diameter = a.Max();
        if (diameter == 1 && n > 2) goto impossible;
        if (diameter % 2 == 0)
        {
            if (counts[diameter / 2] != 1) goto impossible;
            counts[diameter / 2] = 0;
        }
        else
        {
            if (counts[(diameter + 1) / 2] != 2) goto impossible;
            counts[(diameter + 1) / 2] = 0;
        }
        for (int i = (diameter + 3) / 2; i <= diameter; i++)
        {
            if (counts[i] < 2) goto impossible;
            counts[i] = 0;
        }
        if (counts.Sum() > 0) goto impossible;
        Console.WriteLine("Possible");
        return;
        impossible:Console.WriteLine("Impossible");
    }
}


Measured memory_bytes: 13396
#include <stdio.h>
#include <string.h>


int n, card[203];

int main()
{
	int k, m, i, j;
	int t[203];

	scanf("%d%d", &n, &m);
	
	for(i=0; i<2*n; i++){
		card[i] = i+1;
	}

	for(;m--;){
		scanf("%d", &k);
		if(k==0){
			for(i=0; i<n; i++){
				t[2*i] = card[i];
				t[2*i+1] = card[i+n];
			}
		} else {//????????°???int???????????????
			memcpy(t, card+k, 4*(2*n-k));
			memcpy(t+2*n-k, card, 4*k);
		}
		memcpy(card, t, 8*n);
	}

	for(i=0; i<2*n; i++)
		printf("%d\n", card[i]);

	return 0;
}

Measured memory_bytes: 616
#include <bits/stdc++.h>
using namespace std; 
int main() {
    int ans=0;
    int k,s; cin >> k >> s;
    for (int i=0;i<k+1;i++){
        for (int o=0;o<k+1;o++){
            if (s-o-i>=0 && s-o-i<=k){
                ans++;
            }
        }
    }
           
    
    cout << ans << "\n";
    
}




Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace atcoder01a
{
    class Program
    {
        static void Main(string[] args)
        {
            string a = "A";
            string c = "C";
            string g = "G";
            string t = "T";
            string b =Console.ReadLine();
            if (b == a)
            {
                Console.WriteLine(t);
            }
            else if (b == c)
            {
                Console.WriteLine(g);
            }
            else if (b == t)
            {
                Console.WriteLine(a);
            }
            else if (b == g)
            {
                Console.WriteLine(c);
            }
            else return;
        }
    }
}


Measured memory_bytes: 11092
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:268435456")
#pragma warning( disable : 6031)
#pragma warning( disable : 4244)
#pragma warning( disable : 26451)
#ifndef _MSC_VER
#pragma GCC target ("sse4.2")
#endif
#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#  define __builtin_popcountll __popcnt64
#endif
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdint>
#include <climits>
#include <cassert>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <random>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <chrono>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-15)

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef pair<ll, ll> pll;
typedef vector< pii > vpii;
typedef vector< pll > vpll;
typedef vector<ll> vl;
typedef vector<vector<long long>> vvl;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef tuple<int, int, int> tiii;
const long long mod = int(1e9) + 7;
const int INF = 1e9;
const ll LINF = 1e18;




int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	int n;
	cin >> n;
	set<string> st;
	for (int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		st.insert(s);
	}
	cout << sz(st);
	return 0;
}

Measured memory_bytes: 19140
unittest
{
	assert( [ "erasedream" ].parse.expand.solve == "YES" );
	assert( [ "dreameraser" ].parse.expand.solve == "YES" );
	assert( [ "dreamerer" ].parse.expand.solve == "NO" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front;
	return tuple( s );
}

auto solve( string s )
{
	LOOP: while( 0 < s.length )
	{
		foreach( w; [ "dream", "dreamer", "erase", "eraser" ] )
		{
			if( w.length <= s.length && s[ $ - w.length .. $ ] == w )
			{
				s.length -= w.length;
				continue LOOP;
			}
		}
		return "NO";
	}
	return "YES";
}


Measured memory_bytes: 536
n = int(input())
arr = []
for i in range(n):
  arr.append(int(input()))

m = [1]
for i in range(1, 100):
  m.append(3 * m[-1] + 1)
m = list(reversed([x for x in m if x <= n]))

cnt = 0
def insertionSort(arr, n, g):
  for i in range(g, n):
    v = arr[i]
    j = i - g
    while j >= 0 and arr[j] > v:
      arr[j + g] = arr[j]
      j = j - g
      global cnt
      cnt += 1
    arr[j+g] = v

def shellSort(arr, n):
  for i in range(len(m)):
    insertionSort(arr, n, m[i])

shellSort(arr, n)

print(len(m))
print(' '.join([str(x) for x in m]))
print(cnt)
for i in range(len(arr)):
  print (arr[i])


Measured memory_bytes: 45520
#include <stdio.h>

void grade(int students)
{
    while(students != 0) {
        for(int i = 0; i < students; ++i) {
            int math, english, japanese;
            scanf("%d %d %d", &math, &english, &japanese);
            int mean = (math + english + japanese) / 3;
            if ((math == 100) || (english == 100) || (japanese == 100)) {
                printf("A\n");
            } else {
                if (((math + english) / 2 >= 90) || mean >= 80) {
                    printf("A\n");
                } else if ((mean >= 70) || ((mean >= 50) && ((math >= 80) || (english >= 80)))) {
                    printf("B\n");
                } else {
                    printf("C\n");
                }
            }
        }
        scanf("%d", &students);
    }
}

int main(void)
{
    int students;
    scanf("%d", &students);
    grade(students);
    return 0;
}

Measured memory_bytes: 1016
#include<cstdio>
#include<algorithm>
using namespace std;
int n, l, a[100010];
int memo[100010];
int solve(int i){
  if(memo[i]) return memo[i];
  
  int right, left;
  right = left = 0;
  if(a[i + 1] > a[i]) right = solve(i + 1);
  if(a[i - 1] > a[i]) left  = solve(i - 1);

  return max(right, left) + l - a[i];
}
int main(void){
  int ans = 0;
  scanf("%d %d", &n, &l);
  for(int i = 1;i <= n; i++) scanf("%d", a + i);
  for(int i = 1;i <= n; i++)
    ans = max(ans, solve(i));
  printf("%d\n", ans);
}


Measured memory_bytes: 2788
#include<stdio.h>
int main()
{
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    int e, f;
    e = a*b;
    f = c*d;
    if(e >= f)
    {
        printf("%d",e);
    }
    else
        printf("%d",f);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
int main()
{
    fastio;
    ll n=0,k=0;
    cin>>n>>k;
    ll ans=0;
    ll ar[n];
    for(ll i=0;i<n;++i){
        cin>>ar[i];
        if(ar[i]>=k)
            ++ans;
    }
    cout<<ans;
    return 0;
}


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

int main() {
	int N;
	cin >> N;
	vector<int> V(N), C(N);
	for (int i = 0; i < N; i++) cin >> V[i];
	for (int i = 0; i < N; i++) cin >> C[i];
	int ans = 0;
	for (int i = 0; i < N; i++) ans += max(0, V[i] - C[i]);
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc =new Scanner(System.in);
	String N=sc.next();
	String N2[]=N.split("");
	int ans=0;
	for(int i=0;i<N2.length/2;i++) {
		if(!N2[i].equals(N2[N2.length-1-i])) {
			ans++;
		}
	}
	System.out.println(ans);
}
}

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

typedef long long ll;
using namespace std;
int memo[100001][4];
int A[100001], B[100001], C[100001];
int get_val(int prev, int n) {
	if(prev==0) {
			return A[n];
	} else if(prev==1) {
			return B[n];
	} else if(prev==2) {
			return C[n];
	}
	return 0;
}

int calc(int n, int prev) {
	if(n==1) {
		return get_val(prev, n);
	}
	
	if(memo[n][prev]!=-1) {
		return memo[n][prev];
	}
	
	int mx = INT_MIN;
	for (int i=1; i<=3; i++) {
		if(i!=prev) {
			int val = get_val(prev, n);
			mx = max(mx, calc(n-1, i) + val);
		}
	}
	
	memo[n][prev] = mx;
	
	return memo[n][prev];
}

int main() {
 	int n;
 	cin>>n;
 	
 	int dp[100009][3];
 	for(int i = 0; i < 100009; i++)
        for(int j = 0; j < 3; j++)
            dp[i][j] = INT_MIN;
            
 	for (int i=1; i<=n; i++) {
 		cin>>A[i] >>B[i] >>C[i];
 		memo[i][1] = -1;
 		memo[i][2] = -1;
 		memo[i][3] = -1;
 	}
 	
 	//cout << calc(n+1, -1);
  
  dp[0][0] = dp[0][1] = dp[0][2] = 0;
  
  for (int i=1; i<=n; i++) {
  	for (int j=0; j<3; j++) {
  		for (int k=0; k<3; k++) {
				if(j!=k) {
					dp[i][j] = max(dp[i][j], dp[i-1][k] + get_val(j,i));
				}
			}
  	}
  }
  int mx = 0;
  mx = max(mx, max(dp[n][0], max(dp[n][1], dp[n][2])));
  cout << mx;
   
	return 0;
}

Measured memory_bytes: 4096
#include <algorithm>
#include <iostream>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int N;
vector<int> A;

int main() {
  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];

  vector<int> l(N), r(N);
  l[0] = A[0];
  r[N - 1] = A[N - 1];
  for (int i = 1; i < N; i++) {
    l[i] = gcd(l[i - 1], A[i]);
    r[N - i - 1] = gcd(r[N - i], A[N - i - 1]);
  }

  int res = max(l[N - 2], r[1]);
  for (int i = 1; i < N - 1; i++) {
    int tmp = gcd(l[i - 1], r[i + 1]);
    if (tmp > res)
      res = tmp;
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 4564
#include <bits/stdc++.h>
using namespace std;
int main(){
  random_device rnd;
  mt19937 mt(rnd());
  int D;
  cin >> D;
  vector<int> c(26);
  for (int i = 0; i < 26; i++){
    cin >> c[i];
  }
  vector<vector<int>> s(D, vector<int>(26));
  for (int i = 0; i < D; i++){
    for (int j = 0; j < 26; j++){
      cin >> s[i][j];
    }
  }
  vector<int> last(26, -1);
  for (int i = 0; i < D; i++){
    int t = min(30, D - i);
    vector<vector<int>> L(t, vector<int>(26, 0));
    for (int j = 0; j < t; j++){
      for (int k = 0; k < 26; k++){
        L[j][k] = c[k] * (i + j - last[k]);
      }
    }
    /*
    for (int j = 0; j < t; j++){
      for (int k = 0; k < 26; k++){
        cout << L[j][k] << ' ';
      }
      cout << endl;
    }
    */
    int mx = 0;
    int a = 0;
    vector<int> best(t);
    for (int j = 0; j < 1000; j++){
      vector<vector<int>> L2 = L;
      vector<int> next(t, 0);
      if (j < 500){
        for (int k = 0; k < t; k++){
          next[k] = mt() % 26;
        }
      } else if (j < 900){
        next = best;
        for (int k = 0; k < 5; k++){
          int pos = mt() % t;
          int upd = mt() % 26;
          next[pos] = upd;
        }
      } else {
        next = best;
        for (int k = 0; k < 2; k++){
          int pos = mt() % t;
          int upd = mt() % 26;
          next[pos] = upd;
        }
      }
      //calculate diff
      int diff = 0;
      for (int k = 0; k < t; k++){
        diff += s[i + k][next[k]];
        for (int l = k; l < t; l++){
          diff += L2[l][next[k]] - (l - k) * c[next[k]];
          L2[l][next[k]] = (l - k) * c[next[k]];
        }
      }
      if (diff > mx){
        mx = diff;
        best = next;
        /*
        cout << "best: " << endl;
        for (int k = 0; k < t; k++){
          cout << best[k] << ' ';
        }
        cout << endl;
        cout << "mx = " << mx << endl;
        */
      }
    }
    cout << best[0] + 1 << endl;
    last[best[0]] = i;
  }
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
bool det(int d) {
	if(d == 0) return true;
	return (d%3) != 1;
}
vvi g;
ii dm(int u,int p) {
	ii res = {0,u};
	for(int i=0;i<g[u].size();i++) {
		int v = g[u][i];
		if(v == p) continue;
		ii dv = dm(v,u);
		dv.first++;
		if(dv.first > res.first) {
			res = dv;
		}
	}
	return res;
}
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin >> n;
	g.assign(n,vi());
	for(int i=0;i<n-1;i++) {
		int a,b;
		cin >> a >> b;a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	ii fv = dm(0,-1);
	ii sv = dm(fv.second,-1);
	if(det(sv.first)) {
		cout << "First\n";
	} else {
		cout << "Second\n";
	}
}

Measured memory_bytes: 23680
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
   vector<vector<int>> v(3,vector<int> (3));
   rep(i,3){
      rep(j,3) cin >> v[i][j];
   }
   bool can = true;
   int ans = v[0][1]-v[0][0];
   rep(i,3){
      if (ans != (v[i][1] -v[i][0])){
         can = false;
         break;
      }
   }
   ans = v[0][2]-v[0][1];
   rep(i,3){
      if (ans != (v[i][2] - v[i][1])){
         can = false;
         break;
      }
   }
   ans = v[0][2]-v[0][0];
   rep(i,3){
      if (ans != (v[i][2] -v[i][0])){
         can = false;
         break;
      }
   }
   if (can) cout << "Yes" << endl;
   else cout << "No" << endl;
   
   
   
   return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <cassert>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef pair<T,int> F;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
struct edge
{
	int to,cost;
	edge(int to,int cost):to(to),cost(cost){}
};
int N,M,K;
int t[100100];
int day[100100],dist[100100];
int x[100100],d[100100],p[100100];
int par[100100][20];
vector<edge> G[100100];
bool used[100100];
priority_queue<F,vector<F>,greater<F> > q;
int ascend(int v,int k)
{
	for(int i=19;i>=0;i--)
	{
		if(k&(1<<i))v=par[v][i];
	}
	return v;
}
int main()
{
	scanf("%d %d",&N,&M);
	for(int i=0;i<N;i++)scanf("%d",&t[i]);
	for(int i=0;i<M;i++)
	{
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		a--;b--;
		G[a].pb(edge(b,c));
		G[b].pb(edge(a,c));
	}
	scanf("%d",&K);
	for(int i=0;i<K;i++)
	{
		scanf("%d %d %d",&x[i],&d[i],&p[i]);
		x[i]--;
	}
	memset(used,false,sizeof(used));
	for(int i=0;i<N;i++)day[i]=INF,dist[i]=INF;
	day[0]=0;dist[0]=0;
	q.push(F(T(P(0,0),t[0]),0));
	par[0][0]=-1;
	while(!q.empty())
	{
		F a = q.top();
		q.pop();
		int v = a.sec;
		int date = a.fi.fi.sec;
		int dis = a.fi.fi.fi;
		for(int i=0;i<G[v].size();i++)
		{
			edge e = G[v][i];
			if(dist[e.to]>dis+e.cost){
				day[e.to]=date+1;
				dist[e.to]=dis+e.cost;
				par[e.to][0]=v;
				q.push(F(T(P(dist[e.to],day[e.to]),t[e.to]),e.to));
				continue;
			}
			if(dist[e.to]==dis+e.cost&&day[e.to]>date+1){
				day[e.to]=date+1;
				dist[e.to]=dis+e.cost;
				par[e.to][0]=v;
				q.push(F(T(P(dist[e.to],day[e.to]),t[e.to]),e.to));
				continue;
			}
			if(dist[e.to]==dis+e.cost&&day[e.to]==date+1&&t[par[e.to][0]]>t[v]){
				day[e.to]=date+1;
				dist[e.to]=dis+e.cost;
				par[e.to][0]=v;
				q.push(F(T(P(dist[e.to],day[e.to]),t[e.to]),e.to));
				continue;
			}
		}
	}
	/*for(int i=0;i<N;i++)
	{
		printf("%d %d %d\n",day[i],dist[i],par[i][0]);
	}*/
	for(int i=0;i<19;i++)
	{
		for(int v=0;v<N;v++)
		{
			if(par[v][i]==-1)par[v][i+1]=-1;
			else par[v][i+1]=par[par[v][i]][i];
		}
	}
	for(int i=0;i<K;i++)
	{
		if(day[x[i]]<=d[i])printf("%d\n",max(0,dist[x[i]]-p[i]));
		else
		{
			int k = day[x[i]]-d[i];
			assert(k<=day[x[i]]);
			int y = ascend(x[i],k);
			//printf("y %d\n",y);
			if(dist[y]<=p[i])printf("%d\n",dist[x[i]]-dist[y]);
			else printf("%d\n",dist[x[i]]-p[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 29144
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int s=sc.nextInt();
		long mod=998244353;
		long[][][] dp=new long[3][n+1][s+1];
		//0は開始、１は継続、２は終了
		for(int i=1; i<=n; i++){
			int a=sc.nextInt();
			dp[0][i][0]=1;
			if(a<=s){
				dp[0][i][a]=1;
			}
			for(int t=s; t>=0; t--){
				dp[1][i][t]+=dp[0][i-1][t]+dp[1][i-1][t];
				if(t>=a){
					dp[1][i][t]+=dp[0][i-1][t-a]+dp[1][i-1][t-a];
				}
				dp[1][i][t]%=mod;
			}
			dp[2][i][s]=(dp[2][i-1][s]+dp[1][i][s]+((a==s)?1:0))%mod;
		}
		System.out.println(dp[2][n][s]);
	}
}


Measured memory_bytes: 328684
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in Actual solution is at the top
 * 
 * @author daltao
 */
public class Main {
    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "daltao", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            PrintWriter out = new PrintWriter(outputStream);
            FourColoring solver = new FourColoring();
            solver.solve(1, in, out);
            out.close();
        }
    }
    static class FourColoring {
        public void solve(int testNumber, FastInput in, PrintWriter out) {
            int h = in.readInt();
            int w = in.readInt();
            int d = in.readInt();

            char[] colors = new char[] {'R', 'Y', 'G', 'B'};
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    int ti = i + j;
                    int tj = i - j + w;

                    int val = 2 * (ti / d % 2) + tj / d % 2;
                    out.append(colors[val]);
                }
                out.append('\n');
            }
        }

    }
    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }
}



Measured memory_bytes: 27092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int rec(int n){
	vector<int> d;
	for(int i=0;i<4;i++){
		d.push_back(n%10);
		n/=10;
	}
	sort(d.begin(),d.end());
	int l=0,s=0,k=1;
	for(int i=0;i<4;i++){
		l+=d[i]*k;
		s+=d[3-i]*k;
		k*=10;
	}
	return l-s;
}
int main(){
	int n;
	while(cin>>n){
		if(n==0000)break;
		if(n%1111==0){
			cout<<"NA"<<endl;
			continue;
		}
		int cnt=0;
		while(1){
			if(n==6174){
				cout<<cnt<<endl;
				break;
			}
			n=rec(n);
			cnt++;
		}
	}
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k,a=1;
  cin>>n>>k;  
  
  for(int i=0;i<n;i++){
    if(a>k){
      a+=k;
    }
    else{
      a*=2;
    }
  }
  cout<<a<<endl;
   
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)

using namespace std;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
constexpr ll MOD = 1000000007;

ll solve(ll l, ll r, ll n) {
  vector<vecll> dp(n+1, vecll(4, 0));
  REP(flags,4) {
    dp[0][flags] = 1;
  }
  REP(i,n) {
    bool rhi = (r >> i) & 1;
    bool lhi = (l >> i) & 1;
    REP(flags,4) {
      if ((flags & 0b10) || !lhi) {
        int oldflags = flags | rhi;
        dp[i+1][flags] += dp[i][oldflags];
        dp[i+1][flags] %= MOD;
      }
      if (((flags & 0b10) || !lhi) && ((flags & 0b01) || rhi)) {
        int oldflags = flags;
        dp[i+1][flags] += dp[i][oldflags];
        dp[i+1][flags] %= MOD;
      }
      if ((flags & 0b01) || rhi) {
        int oldflags = flags | (!lhi << 1);
        dp[i+1][flags] += dp[i][oldflags];
        dp[i+1][flags] %= MOD;
      }
    }
  }
  return dp[n][0];
}

int main()
{
  ll l,r;
  cin>>l>>r;
  ll sum = 0;
  ll p2 = 1;
  ll q2 = 2;
  REP(i,60) {
    ll li = max(l, p2);
    ll ri = min(r, q2-1);
    if (li <= ri) {
      sum += solve(li, ri, i);
      sum %= MOD;
    }
    p2 <<= 1;
    q2 <<= 1;
  }
  cout<<sum<<endl;
  return 0;
}


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

#define F first
#define S second
#define all(x) x.begin(), x.end()

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
 
const int Maxn = 1e5 + 10;
const ll Inf = LONG_LONG_MAX >> 2;
const int Log = 20;
const ll Mod = 10133;

ll a[Maxn];
ll nx[Maxn][Log];

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n;
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	a[n + 1] = Inf;
	ll L, Q;
	cin >> L >> Q;
	int po = 1;
	for(int i = 1; i <= n; i++){
		while(a[po] - a[i] <= L) po ++;
		nx[i][0] = po - 1;
	}
	for(int j = 1; j < Log; j++)
		for(int i = 1; i <= n; i++) nx[i][j] = nx[nx[i][j - 1]][j - 1];
	ll s, e;
	for(int i = 1; i <= Q; i++){
		cin >> s >> e;
		if(s > e) swap(s, e);
		ll ans = 0;
		for(int j = Log - 1; j >= 0; j--){
			if(nx[s][j] < e){
				ans += (1 << j);
				s = nx[s][j];
			}
		}
		cout << ans + 1 << '\n';
	}
	return 0;
}


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

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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; }

int main()
{
  ll X, Y;
  cin >> X >> Y;

  ll ans=1;
  
  for(int i=1;(long long)pow(2,i)*X<=Y;i++)
    ans++;
  
  cout<<ans;

  return 0;
}


//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find
//vector.count



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

#define mp make_pair
#define pb push_back


typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

template <typename T> void dprint(T begin, T end) {
    for (auto i = begin; i != end; i++) {
        cerr << (*i) << " ";
    }
    cerr << "\n";
}

int n, m;
int e1[220000];
int e2[220000];

int main() {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < m; ++i) {
        int a, b;
        scanf("%d%d", &a, &b);
        --a, --b;
        if (a == 0)
            e1[b] = 1;
        if (b == n - 1)
            e2[a] = 1;
    }
    for (int i = 0; i < n; ++i) {
        if (e1[i] && e2[i]) {
            cout << "POSSIBLE\n";
            return 0;
        }
    }
    cout << "IMPOSSIBLE\n";
    return 0;
}




Measured memory_bytes: 1792
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
///////////////////////////
int main(){fastio
    ll k;cin>>k;
    cout<<(k/2)*((k+1)/2)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

int32_t main(){
	IOS;
	int n;
	cin >> n;
	int a, ans = 0;
	while( n-- ){
		cin >> a;
		while(a%2 == 0 && a > 0 )
			a = a/2, ans++;
	}

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

Measured memory_bytes: 3436
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for (int i = 0; i < N; i++) {
            par[i] = i;
        }
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) {
          return x;
        }
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) {
          return; //xとyの根が同じ(=同じ木にある)時はそのまま
        }
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    int N, K, L;
    cin >> N >> K >> L;

    UnionFind tree1(N);
    UnionFind tree2(N);

    for (int i = 0; i < K; i++) {
        int x, y;
        cin >> x >> y;
        tree1.unite(x - 1, y - 1);
    }
    for (int i = 0; i < L; i++) {
        int x, y;
        cin >> x >> y;
        tree2.unite(x - 1, y - 1);
    }

    map<pii, int> cnt;
    for(int i = 0; i < N; i++){
      cnt[pii(tree1.root(i), tree2.root(i))]++;
    }
  for(int i = 0; i < N; i++){
      cout << cnt[pii(tree1.root(i), tree2.root(i))] << " ";
    }
    cout << endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 30;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};



int main()
{
  int n; cin >> n;
  vector<int> p(n), q(n), x(n);
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> q[i];
  if(p == q) {
    cout << 0 << endl;
    return 0;
  }
  rep(i, n) x[i] = i+1;
  int i = 1;
  vector<int> ans;
  do {
    if(x == p || x == q) ans.push_back(i);
    ++i;
  } while(next_permutation(ALL(x)));

  cout << abs(ans[0]-ans[1]) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 1147483600;
const ll infl = 1e18 + 5;
const char ENDL = '\n';
//cout << fixed << setprecision(17) << res << endl;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int q;
    cin >> q;
    rep(xx,q){
        ll a, b;
        cin >> a >> b;
        if (a==b){
            cout << 2 * (a - 1) << ENDL;
            continue;
        }
        ll c = a * b;
        ll MIN = 1, MAX = 1e9;
        while (MIN+1<MAX){
            ll m = (MIN + MAX) / 2;
            if (m*m<c){
                MIN = m;
            }
            else{
                MAX = m;
            }
        }
        //基本は2*MIN-１
        //これに、MIN*MAXを比べて出す
        cout << 2 * MIN - 1 - (MIN * MAX >= c) << ENDL;
    }
}

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

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

constexpr int dx[]={1,0,-1,0};
constexpr int dy[]={0,1,0,-1};
constexpr int ddx[] = {1,1,-1,-1,2,2,2,2,2,-2,-2,-2,-2,-2,1,0,-1,1,0,-1};
constexpr int ddy[] = {1,-1,1,-1,0,1,2,-1,-2,2,1,0,-1,-2,2,2,2,-2,-2,-2};
constexpr int INF = 1<<28;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H,W,C_h,C_w,D_h,D_w;

  cin>>H>>W>>C_h>>C_w>>D_h>>D_w;
  C_h--,C_w--,D_h--,D_w--;
  vector<string> S(H);
  rep(i,H)cin>>S[i];

  vector dist(H,vector(W,INF));
  dist[C_h][C_w] = 0;
  deque<pair<int,int>> deq;
  deq.emplace_front(C_h,C_w);
  while(!deq.empty()){
    auto [y,x] = deq.front();
    deq.pop_front();
    rep(i,4){
      int ny = y+dy[i];
      int nx = x+dx[i];
      if(ny<0||nx<0||ny>=H||nx>=W)continue;
      if(S[ny][nx]=='#')continue;
      if(dist[ny][nx]>dist[y][x]){
        dist[ny][nx] = dist[y][x];
        deq.emplace_front(ny,nx);
      }
    }
    rep(j,20){
      int ny = y+ddy[j];
      int nx = x+ddx[j];
      if(ny<0||nx<0||ny>=H||nx>=W)continue;
      if(S[ny][nx]=='#')continue;
      if(dist[ny][nx]>dist[y][x]+1){
        dist[ny][nx] = dist[y][x]+1;
        deq.emplace_back(ny,nx);
      }
    }
  }
  int ans = dist[D_h][D_w];
  cout<<(ans==INF?-1:ans)<<endl;
}


Measured memory_bytes: 8752
/*
        Choo Lo jo mujhe tum kabhi, kho na jaoon main raat din
    Nazaron mein tum ho basey
        Keh do jo tum ek baar, Mere ho bas tum mere
    Nazaron mein tum ho basey
*/
 
#include<bits/stdc++.h>
#include<cstdio>
 
#define deb(x) cout << #x << " -> " << x << el
#define db double
#define ll long long int
#define ull unsigned long long int
#define umap unordered_map
#define sc(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define sclu(x) scanf("%llu", &x)
#define scd(x) scanf("%lf", &x)
#define pass cout<<"pass\n"
#define vi vector<int>
#define pb push_back
#define vec vector
#define el "\n"
#define pii pair<int, int>
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define umap unordered_map
#define f(i,x,y) for(int i=x;i<y;++i)
#define ff(i,x,y) for(int i=x;i<=y;++i)
#define mem(x) memset(x, 0, sizeof(x))
#define mems(x,y) memset(x, y, sizeof(x))
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ppi pair<int, pii>
#define mat vector<vector<ll> > 
#define mod 1000000007
#define MAX 100002
 
using namespace std;

int n, q;
ll k;
ll ar[MAX];

void solve() {
	cin >> n >> k >> q;

	int qq = q;
	while(qq--) {
		int x; cin >> x;
		++ar[x];
	}

	ff(i,1,n) {
		int p = ar[i] - q;
		if(k + p > 0LL) {
			cout << "Yes\n";
		} else {
			cout << "No\n";
		}
	}
}


int main() {
    int ccc = 1;
    // sc(ccc);
    while(ccc--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    cout << A * B / 2 << endl;
}

Measured memory_bytes: 256
from collections import deque

H,W = map(int,input().split())
A = [input() for i in range(H)]

L = [[float("inf") for x in range(W)] for y in range(H)]



dxy = [(-1,0), (1,0), (0,-1), (0,1)]

Q = deque()

for y in range(H) :
    for x in range(W) :
        if A[y][x] != "#" :
            continue
        
        L[y][x] = 0
        
        Q.append((y,x))

while Q :
    y,x = Q.popleft()

    for dy,dx in dxy :
        ny = y+dy
        nx = x+dx

        if (ny < 0) or (ny >= H) or (nx < 0) or (nx >= W) :
            continue

        if L[ny][nx] <= (L[y][x] + 1) :
            continue
        
        L[ny][nx] = L[y][x] + 1
        
        Q.append((ny,nx))

ans = 0

for y in range(H) :
    ans = max(ans, max(L[y]))
print(ans)


Measured memory_bytes: 123228
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  if(a <= 8 && b <= 8){
    cout << "Yay!" << endl;
  }
  else{
    cout << ":(" << endl;
  }
}


Measured memory_bytes: 256
use std::io;
use std::str::FromStr;
use std::collections::VecDeque;
use std::collections::HashSet;

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn bfs(edges: &Vec<Vec<u64>>) -> Vec<u64> {
    let mut prev: Vec<u64> = vec![0; edges.len()];
    let mut visited: HashSet<u64> = HashSet::new();
    let mut queue: VecDeque<u64> = VecDeque::new();
    queue.push_back(0);
    visited.insert(0);
    while !queue.is_empty() {
        let target = queue.pop_front().unwrap();
        visited.insert(target);
        for node in &edges[target as usize] {
            // println!("{}, {}", target, node);
            // println!("{:?}", visited);
            if !visited.contains(node) {
                // println!("{}, {}", target, node);
                queue.push_back(*node);
                prev[*node as usize] = target;
                visited.insert(*node);
            }   
        }
    }
    return prev;
}

fn main() {
    let (n, m) = input_tuple();
    let mut edges: Vec<Vec<u64>> = vec![Vec::new(); n as usize];
    for _i in 0..m {
        let (a, b) = input_tuple();
        edges[(a-1) as usize].push(b - 1);
        edges[(b-1) as usize].push(a - 1);
    }

    // println!("{:?}", bfs(&edges));

    let mut prev = bfs(&edges);
    prev.remove(0);
    println!("Yes");
    for i in prev {
        println!("{}", i + 1)
    }

}


Measured memory_bytes: 13284
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef  pair<int,int> P;
typedef long long LL;
typedef vector<LL> VEC;


const LL INF=1<<30;
const LL MOD=1000000007;

LL gcd(LL a,LL b){
    if(b==0)return a;

    return gcd(b,a%b);
}
LL lcm(LL a,LL b){
    LL g=gcd(a,b);
    return a/g*b;
}

LL kaijo(LL n){
    LL ans=1;
    for(LL i=1;i<=n;++i){
        (ans*=i)%=MOD;
    }
    return ans;
}


int main(){
    int x,a,b;
    cin>>x>>a>>b;
    if(abs(x-a)>abs(x-b))cout<<"B"<<endl;
    else cout<<"A"<<endl;
}

Measured memory_bytes: 256