akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5,M=998244353;
int n,b[N],c[N];
long long g[N],ans;
struct BIT{
	int tr[N];
	void Ad(int i,int x){
		for(;i<=n;i+=i&-i)tr[i]+=x;
	}
	int Qr(int i){
		int rs=0;
		for(;i;i-=i&-i)rs+=tr[i];
		return rs;
	}
}T1,T2;
void ck(long long &x){if(x>=M)x-=M;}
struct P{
	int x,y;
	bool operator < (const P&t)const{
		return x<t.x;
	}
}a[N];
long long so(int ul,int ur,int dl,int dr){
	long long rs=g[n-1];
	rs+=(g[ul]-1)*(g[dr]-1)%M*(g[ur]+g[dl]-1)%M;ck(rs);
	rs+=(g[ur]-1)*(g[dl]-1)%M*(g[ul]+g[dr]-1)%M;ck(rs);
	rs+=(g[ur]-1)*(g[dl]-1)%M*(g[ul]-1)%M*(g[dr]-1)%M;ck(rs);
	return rs;
}
int main(){
	scanf("%d",&n);g[0]=1;
	for(int i=1;i<=n;++i){
		scanf("%d %d",&a[i].x,&a[i].y);
		b[i]=a[i].y;
		c[i]=a[i].x;
		g[i]=g[i-1]<<1;
		ck(g[i]);
	}
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	sort(c+1,c+n+1);
	for(int i=1;i<=n;++i){
		a[i].y=lower_bound(b+1,b+n+1,a[i].y)-b;
		a[i].x=lower_bound(c+1,c+n+1,a[i].x)-c;
		T2.Ad(a[i].y,1);
	}
	for(int i=1;i<=n;++i){
		T2.Ad(a[i].y,-1);T1.Ad(a[i].y,1);
		int dl=T1.Qr(a[i].y-1),dr=T2.Qr(a[i].y-1);
		int ul=i-dl-1,ur=n-i-dr;
		ans+=so(ul,ur,dl,dr);
		ck(ans);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef pair<int,int> pii;
const int inf = 1e9;

int n, d[1000005], m;
bool vis[1000005];

priority_queue<pii> pq;

int main()
{
	scanf("%d",&n);
	for(m=1;m<n;m*=10);
	if(m == n) {puts("1"); return 0;}
	for(int i=0;i<=m*10;i++) d[i] = inf;
	for(int i=1;i<=9;i++) {
		int I = n*i/10, V = n*i%10;
		if(d[I] > V) {
			d[I] = V;
			pq.push({-d[I], I});
		}
	}
	while(!pq.empty()) {
		int A, B; tie(A, B) = pq.top(); A *= -1; pq.pop();
		if(vis[B]) continue;
		vis[B] = true;
		for(int i=0;i<=9;i++) {
			int I = (B+n*i)/10, V = (B+n*i)%10;
			if(d[I] > A + V) {
				d[I] = A + V;
				pq.push({-d[I], I});
			}
		}
	}
	printf("%d\n",d[0]);
}


Measured memory_bytes: 10352
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;


int seki[100][100];
int te[100][100];

main(){
	int n;
	
	while(cin>>n){
		if(n==0)break;
		
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				int t;
				cin>>t;
				seki[j][i]=t;
				te[j][i]=0;
			}
		}
		
		for(int i=0;i<n;i++){
			int min=seki[i][0];
			for(int j=0;j<n;j++){
				if(min<seki[i][j]){
					min=seki[i][j];
				}
			}
			for(int j=0;j<n;j++){
				if(min==seki[i][j]){
					te[i][j]+=1;
				}
			}
		}
		
		int pr=0;
		for(int i=0;i<n;i++){
			int max=seki[0][i],maxj=0;
			for(int j=0;j<n;j++){
				if(max>seki[j][i]){
					max=seki[j][i];
					maxj=j;
				}
			}
			if(te[maxj][i]){
				cout<<seki[maxj][i]<<endl;
				pr=1;
				break;
			}
		}
		if(pr==0)puts("0");
	}
}

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

int N, K, L;

struct UnionFind {
    vector<int> par;

    UnionFind(int N) : par(N) {
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    cin >> N >> K >> L;
    UnionFind road(N);
    for (int i = 0; i < K; i++) {
        int p, q;
        cin >> p >> q;
        road.unite(p-1, q-1);
    }
    UnionFind rail(N);
    for (int i = 0; i < L; i++) {
        int r, s;
        cin >> r >> s;
        rail.unite(r-1, s-1);
    }

    map<Pii, int> mp;
    for (int i = 0; i < N; i++) {
        int road_root = road.root(i);
        int rail_root = rail.root(i);
        mp[Pii(road_root, rail_root)]++;
    }

    for (int i = 0; i < N; i++) {
        int road_root = road.root(i);
        int rail_root = rail.root(i);
        cout << mp[Pii(road_root, rail_root)] << " ";
    }
    cout << endl;

    
    return 0;
}

Measured memory_bytes: 13568
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

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

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

/* 再帰下降法 */
// char *p = str; res = expr(p);

pair<int,int> term(char* &s);
pair<int,int> number(char* &s);
pair<int,int> factor(char* &s);
pair<int,int> expr(char* &s);

//数
pair<int,int> number(char* &s){
  s++;
  return {1, 1};
}

//乗算除算(優先順位:高)
pair<int,int> term(char* &s){
  pair<int,int> res = factor(s);
  while(1){
    if(*s == '&') {
      auto p = factor(++s);
      res = {min(res.first, res.second + p.first), res.second + p.second};
    } else {
      break;
    }
  }
  return res;
}

//括弧か数
pair<int,int> factor(char* &s){
  if(*s != '(') return number(s);
  pair<int,int> res = expr(++s); s++;
  return res;
}

//式(優先順位: 低)
pair<int,int> expr(char* &s){
  pair<int,int> res = term(s);
  while(1){
    if(*s == '|') {
      auto p = term(++s);
      res = {res.first + p.first,
             min(res.second, res.first + p.second)};
    } else {
      break;
    }
  }
  return res;
}

char S[SIZE];

int main(){
  scanf("%s", S);

  char *p = S;

  auto ans = expr(p);

  cout << ans.first << " " << ans.second << endl;

  return 0;
}



Measured memory_bytes: 3444
from collections import defaultdict, deque

N = int(input())

edges = defaultdict(list)

for _ in range(N-1):
    u, v, w = map(int, input().split())
    edges[u-1].append((v-1, w))
    edges[v-1].append((u-1, w))


colors = [None] * N
colors[0] = 0
que = deque([0])

while que:
    u = que.popleft()
    for v, w in edges[u]:
        if colors[v] != None:
            continue
        if edges[v] != []:
            que.append(v)

        if w % 2 == 0:
            colors[v] = colors[u]
        else:
            colors[v] = 1 ^ colors[u]

for c in colors:
    print(c)


Measured memory_bytes: 47632
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

int main(void){
	ll n;
	cin >> n;
	Vec a(n);
	rep(i, n) cin >> a[i];

	map<P, ll> mp;

	rep(i, n){
		REPN(k, i / 2, i / 2 + 1) mp[{i, k}] = -LINF;
		mp[{-2, 0}] = 0;
		mp[{-1, 0}] = 0;
		REPN(j, i - 5, i - 2){
			REPN(k, i / 2, i / 2 + 1){
				if(mp.find({j, k - 1}) != mp.end()) chmax(mp[{i, k}], mp[{j, k - 1}] + a[i]);
			}
		}
	}

	ll ans = -LINF;
	rep(i, n) if(mp.find({i, n / 2}) != mp.end()) chmax(ans, mp[{i, n / 2}]);
	co(ans);

	return 0;
}


Measured memory_bytes: 29808
#include <bits/stdc++.h>
using namespace std;
char c[60][60];
int n, m;
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%s", c[i]);
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (c[i][j] == '#') {
				printf("%c", c[i][j]);
			} else {
				int cnt = 0;
				for (int k = max(i - 1, 0); k <= min(i + 1, n - 1); k++) {
					for (int l = max(j - 1, 0); l <= min(j + 1, m - 1); l++) {
						if (c[k][l] == '#') {
							cnt++;
						}
					}
				}
				printf("%d", cnt);
			}
		}
		printf("\n");
	}
	return 0;
}

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

void Sort(int length[], int N){
  int i,j,k,m ;
  for(i=1;i<N;i++){
    k=i ;
    m=length[i] ;
    j=i-1 ;
    while(length[j]>m && j>=0){
      length[j+1] = length[j] ;
      j-- ;
    }
    length[j+1] = m ;
  }
}


int main(){
  int N,x,i,counter=0;
  int a[101] ;

  cin >> N >> x ;
  for(i=0;i<N;i++){
    cin >> a[i] ;
  }

  Sort(a,N) ;


  for(i=0;i<N;i++){
    x = x-a[i] ;
    if(x<0){
      break ;
    }
    counter ++ ;
  }

  if(x>0) counter --;

  cout << counter ;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

int main() {

	int N;
	std::cin >> N;
	int change;

	change = N % 1000;

	if (0 == change) {
		std::cout << "0" << std::endl;
	}else {
		change = 1000 - change;
		std::cout << change << std::endl;
	}

	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
const int MAXN = 1e5+5;

int dp[MAXN];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, q;
	string s;
	cin >> n >> q >> s;
	for (int i = 1; i < n; i++) {
	    if (s[i] == 'C' && s[i-1] == 'A')
	    	dp[i]++;
	    dp[i] += dp[i-1];
	}
	while (q--) {
		int l, r;
		cin >> l >> r;
		l--, r--;
		cout << dp[r]-dp[l] << '\n';
	}
	return 0;
}

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

namespace AtCoder_20190707_1
{    class Program
    {
        static void Main(string[] args)
        {
            string[] SW = Console.ReadLine().Split(' ');
            int S = int.Parse(SW[0]);
            int W = int.Parse(SW[1]);

            if(W >= S)
            {
                Console.WriteLine("unsafe");
            }
            else
            {
                Console.WriteLine("safe");
            }
        }
    }
}

Measured memory_bytes: 27532
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	int N;
	cin >> N;
	map <string, vector <int> > mp;
	map <pair <string, int>, int> num;
	rep( i, 0, N ){
		int p;
		string s;
		cin >> s >> p;
		mp[ s ].push_back( p );
		pair <string, int> hoge = make_pair( s, p );
		num[ hoge ] = i + 1;
	}
	for(auto vec: mp){
		sort_desc( vec.second );
		for(auto v:vec.second){
			pair <string, int> pa = make_pair( vec.first, v );
			cout << num[ pa ] << endl;
		}
	}
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}


Measured memory_bytes: 256
(n,q),c,*z=[[*map(int,t.split())]for t in open(0)]
a=[0]*q
j,*b=t=[0]*9**6
for i in sorted(range(q),key=lambda x:z[x][1]):
 l,r=z[i]
 while j<r:
  d=c[j];j+=1;x,y,b[d]=b[d]+1,j+1,j
  while x<=n:t[x]+=1;x+=x&-x
  while y<=n:t[y]-=1;y+=y&-y
 while l:a[i]+=t[l];l-=l&-l
print(*a)

Measured memory_bytes: 228796
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll h;
    cin >> h;

    ll a = 1;
    while (a <= h)
    {
        a <<= 1;
    }
    cout << a - 1 << endl;
}

Measured memory_bytes: 256
import bisect

def ctoi(char):
  return ord(char)-97

s=input()
ls=len(s)
t=input()
lt=len(t)
pos=[[] for _ in range(26)]
for i in range(ls):
  val=ctoi(s[i])
  pos[val].append(i)
larr=[0]*26
for i in range(26):
  larr[i]=len(pos[i])
pos2=[]
cnt=[0]*26
flag=True
num=-1
for i in range(lt):
  val=ctoi(t[i])
  if larr[val]==0:
    flag=False
    break
  tmp=bisect.bisect_right(pos[val],num)
  if tmp==larr[val]:
    num=pos[val][0]
  else:
    num=pos[val][tmp]
  pos2.append(num)
if flag==False:
  print(-1)
else:
  loop=0
  tmp=pos2[0]
  for i in range(1,lt):
    if pos2[i]<=tmp:
      loop+=1
    tmp=pos2[i]
  ans=loop*ls+(pos2[-1]+1)
  print(ans)

Measured memory_bytes: 8436
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
	
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String input = sc.nextLine();
		sc.close();
		//String[] stringArr = input.split("");
		
		long ans = 0;
		int wCnt = 0;
		
		for(int i = input.length() - 1; i >= 0; i--) {
			if(input.charAt(i) == 'B') {
				ans += wCnt;
			}else if(input.charAt(i) == 'W'){
				wCnt++;
			}
		}
		
		System.out.println(ans);
	}
	
//	public static void swap(int a, int b,List<String> strArr) {
//		String aElm = strArr.get(a);
//		String bElm = strArr.get(b);
//		strArr.set(b, aElm);
//		strArr.set(a, bElm);
//	}
}


Measured memory_bytes: 26572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=(ll)(1e9+7);
vector<ll> v;

int main(){
    int n;
    cin>>n;
    bool second=true;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        second&=(x%2==0);
    }
    if(!second)
        cout<<"first";
    else cout<<"second";
    return 0;
}

Measured memory_bytes: 256
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<double>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll a,b,c;
    cin >> a >> b >> c;
    ll t = c - a - b;
    if (t < 0)
    {
        cout << "No";
        return 0;
    }
    ll l = 4 * a * b;
    ll r = t * t;
    yes(l < r);
    //
    return 0;
}

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

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

  int n, k;
  cin >> n >> k;
  double ans = 0;
  rep(i, 1, n + 1) {
    double p = 1.0 / n;
    int mul_val = i;
    while (mul_val < k) {
      mul_val *= 2;
      p /= 2;
    }
    ans += p;
  }

  cout << fixed << setprecision(12) << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
	long long N,M;
	cin >> N >> M;
	if(N == 1  || M == 1){
		if(N == 1 && M == 1){
			cout << 1 << endl;
		}else{
			cout << max(0,(int)(N + M - 3)) << endl;
		}
	}else if(N == 2 || M == 2){
		cout << 0 << endl;
	}else{
		long long tmp = 0;
		tmp = (N-2) * (M-2);
		cout << tmp << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

const ll INF = 1e18;
ll ans;
ll N, A, B, C, D;
map<ll, ll> mp;
    
void dfs(ll n, ll tmp){
    // cout << n << ' ' << tmp << endl;
    if(mp.count(n) != 0 && mp[n] <= tmp) return;
    mp[n] = tmp;
    if(n == 0){
        ans = min(ans, tmp);
        return;
    }
    if(n < 5){
        ans = min(ans, tmp+D*(n));
    }
    double d = (double)(n)*(double)D;
    if((double) ans > (double)tmp+d) ans = tmp+(n)*D;
    
    for(ll i = 0; i < 5; i++){
        if((n+i)%5 == 0){
            dfs((n+i)/5, tmp+D*i+C);
            break;
        }
    }
    for(ll i = 1; i < 5; i++){
        if((n-i)%5 == 0){
            dfs((n-i)/5, tmp+D*i+C);
            break;
        }
    }
    // 3
    for(ll i = 0; i < 3; i++){
        if((n+i)%3 == 0){
            dfs((n+i)/3, tmp+D*i+B);
            break;
        }
    }
    for(ll i = 1; i < 3; i++){
        if((n-i)%3 == 0){
            dfs((n-i)/3, tmp+D*i+B);
            break;
        }
    }

    // 2
    for(ll i = 0; i < 2; i++){
        if((n+i)%2 == 0){
            dfs((n+i)/2, tmp+D*i+A);
            break;
        }
    }
    for(ll i = 1; i < 2; i++){
        if((n-i)%2 == 0){
            dfs((n-i)/2, tmp+D*i+A);
            break;
        }
    }
}

void solve(){
    cin >> N >> A >> B >> C >> D;
    ans = INF;
    dfs(N, 0);
    mp.clear();
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int T;
    cin >> T;
    for(int i = 0; i < T; i++) solve();
}

Measured memory_bytes: 4308
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            long a = in.nextLong();
            long b = in.nextLong();
            System.out.println("" + gcd(a,b) + " " + lcm(a,b));
        }
    }
    static long gcd(long a, long b){
        return b!=0 ? gcd(b,a%b) : a;
    }
    static long lcm(long a, long b){
        return a/gcd(a,b)*b;
    }
}

Measured memory_bytes: 17208
class UnionFind(object):
    def __init__(self, n):
        self.par = [-1] * n
    
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return False
        else:
            if self.par[x] > self.par[y]:
                x, y = y, x
            self.par[x] += self.par[y]
            self.par[y] = x
            return True

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.par[self.find(x)]

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.par) if x < 0]

    def group_count(self):
        return len(self.roots())

N, M = map(int, input().split())
uf = UnionFind(N)

# 最後は全部つながってない
# うしろから順番につなぐ
edges = []
for _ in range(M):
    ai, bi = map(int, input().split())
    ai, bi = ai - 1, bi - 1
    edges.append((ai, bi))
edges.reverse()

ans = [N * (N - 1) // 2]
for (ai, bi) in edges:
    if not uf.same(ai, bi):
        ans.append(ans[-1] - uf.size(ai) * uf.size(bi))
    else:
        ans.append(ans[-1])
    uf.unite(ai, bi)

for a in ans[::-1][1:]:
    print(a)

Measured memory_bytes: 92800
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

/*
   cin.tie(0);
   ios::sync_with_stdio(false);
 */

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int n,e[300005]={0},w[300005]={0},e_num=0,w_num=0;
  string s;
  cin>>n>>s;
  for(int i=0;i<n;i++){
    if(s[i]=='E'){e[i]=1;e_num++;}
    if(s[i]=='W'){w[i]=1;w_num++;}
  }
  for(int i=1;i<n;i++){
    w[i]+=w[i-1];
  }
  for(int i=n-1;i>=1;i--){
    e[i-1]+=e[i];
  }
  /*
  rep(i,n)cout<<e[i]<<" ";
  cout<<endl;
  rep(i,n)cout<<w[i]<<" ";
  cout<<endl;
  */
  int mini=INF;
  for(int i=0;i<n;i++){
    //cout<<i<<": "<<e[i]+w[i]-1<<endl;
    mini=min(mini,e[i]+w[i]-1);
  }
  
  cout<<mini<<endl;
  return 0;
}


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

#define COUT(x) cout << x << endl
#define CIN(x) cin >> x
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define EXIST(s, e) (s.find(e) != s.end())
#define SORT(c) sort(c.begin(), c.end())
#define ERASEUNIQE(v) v.erase(unique(v.begin(), v.end()), v.end())

// conversion
inline int toInt(string s)
{
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}
template <class T>
inline string toString(T x)
{
    ostringstream sout;
    sout << x;
    return sout.str();
}

// math
template <class T>
inline T sqr(T x) { return x * x; }

// typedef
typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

// container util
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()

// constant
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

// clear memory
#define CLR(a) memset((a), 0, sizeof(a))

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

int main(int argc, char const *argv[])
{
    int N, M, X, Y;
    bool warFlag;
    CIN(N),CIN(M),CIN(X),CIN(Y);
    VI xn(N), ym(M);
    REP(i, N){
        CIN(xn.at(i));
    }

    REP(i, M) {
        CIN(ym.at(i));
    }

    SORT(xn);
    SORT(ym);


    for(int z = X + 1; z <= Y; z++)
    {
        if (xn.at(N-1) < z && z <= ym.at(0)) {
            warFlag = false;
            break;
        } else {
            warFlag = true;
        }
    }

    if(warFlag) {
        COUT("War");
    } else {
        COUT("No War");
    }

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define len(x) ((int)(x).size())
#define fastio ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

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

const ll LINF = 1e18;
const int INF = 1e9;
const int MOD = 1e9+7;

/// command for char arrays with spaces -> scanf(" %[^\n]", text);
 
////////////////////////// Solution starts below. //////////////////////////////

int main(){

	int n;
	cin >> n;
	cout << pow(n, 3) << endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,j;
	char a[404],b[404];
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>a[i];
	for(i=1;i<=n;i++)
		cin>>b[i];
	for(i=1;i<=n;i++)
		cout<<a[i]<<b[i];
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const int maxn = 1e6 + 10;
ll a, b;
int q;
ll ans = 0;
int main()
{
	cin >> q;
	while (q--)
	{
		cin >> a >> b;
		if (a>b)swap(a, b);
		ll temp = sqrt(a*b);
		ans = 2 * temp;
		if (a*b == temp*temp)ans -= 2;
		else if ((a*b - 1) / temp == temp)ans--;
		if (!(a == b&&b == temp))ans--;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define initdp(a, b)  for (int i = 0; i <= a; i++)   for (int j = 0; j <= b; j++) dp[i][j] = -1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define ll long long
#define pll pair<ll, ll>
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define umapi unordered_map<ll, ll>
#define umapc unordered_map<char, int>
#define endl "\n"
using namespace std;
 
 
void solve()
{
    int n;
    cin>>n;

    if(n>=30) {
        cout<<"Yes";
    } else {
        cout<<"No";
    }
    
}
 
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
  //  cin >> t;
    while (t--)
    {
        solve();
    }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
#define all(obj) obj.begin(), obj.end()
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);

using namespace std;

typedef unsigned long long ull;
typedef int long long ll;
constexpr ll bigNum = 1000000007;

signed main()
{
    fast;
    int n  = 0;
    cin >> n;
    cout << n * n * n;
}


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

int main() {
    long MAX=-1000000;
    long MIN=1000000;
    long n;
    long S=0;
    cin >>n;
    for (long i=0; i<n; i++) {
        long d;
        cin >>d;
        S+=d;
        MIN=min(MIN, d);
        MAX=max(MAX, d);
    }
    cout <<MIN <<' ' <<MAX <<' ' <<S <<endl;
    return 0;
}


Measured memory_bytes: 3112
$h, $w = gets.split.map(&:to_i)
n = gets.chomp.to_i
a = gets.split.map(&:to_i)
c = Array.new($h) { Array.new($w) { 0 } }
def nex(x, y)
  nx = x
  ny = y
  if y.even?
    if x < $h - 1
      nx = x + 1
    else
      ny = y + 1
    end
  else
    if x > 0
      nx = x - 1
    else
      ny = y + 1
    end
  end
  [nx, ny]
end
x = 0
y = 0
i = 0
while i < n do
  a[i].times do
    c[x][y] = i + 1
    np = nex(x, y)
    x = np.first
    y = np.last
  end
  i += 1
end
c.each do |e|
  puts e.join(' ')
end


Measured memory_bytes: 3836
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

struct UnionFind {
private:
  vector<int> child, tree;
  vector<vector<int>> list;

public:
  //頂点数v
  UnionFind(int v) {
    tree.resize(v);
    list.resize(v);
    for(int i = 0; i < v; i++) {
      tree[i] = i;
      list[i].push_back(i);
    }
  }

  //木の根を求める
  int root(int x) {
    if(x == tree[x]) {
      for(int i = 0; i < child.size(); i++) {
        tree[child[i]] = x;
      }
      child.clear();
      return x;
    } else {
      child.push_back(x);
      return x = root(tree[x]);
    }
  }
  // xの所属するグループの大きさ
  int size(int x) { return list[root(x)].size(); }

  vector<int> nodes(int no) { return list[root(no)]; }

  // xとyの集合を合わせる
  bool unit(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) {
      return false;
    }
    if(list[x].size() < list[y].size()) {
      swap(x, y);
    }
    for(int no : list[y]) {
      list[x].emplace_back(no);
    }
    tree[y] = x;
    return true;
  }

  // xとyが同じグループに所属するか
  bool isUnit(int x, int y) { return root(x) == root(y); }
};
int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  for(int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    uf.unit(a, b);
  }
  int ans = 0;
  for(int i = 1; i < n; i++) {
    if(uf.isUnit(0, i) == false) {
      uf.unit(0, i);
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 10212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX_N 200010
#define lb lower_bound

int main()
{
  ll N;cin>>N;
  vector<ll> L(N);
  for (int i=0;i<N;i++)
  {
    cin>>L[i]; 
  }
  
  sort(L.begin(),L.end());
  
  //keyに初めてなる時のイテレーターを返す
  ll test = lower_bound(L.begin(),L.end(),4)-L.begin();
  //cout<<test<<endl;
  
  ll ans = 0;
  for (int i=0;i<N-2;i++)
  {
    for (int j=i+1;j<=N-1;j++)
    {
      ans += lb(L.begin(),L.end(),L[i]+L[j])-lb(L.begin()+j+1,L.end(),L[j]); 
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 2000000000
#define INFL 2000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;


//#define DEBUG

#ifdef DEBUG
#define dprintf printf
#define dbg 
#define drepl(i,a,b) repl(i,a,b)
#define drep(i,n) rep(i,n)
#else
#define dprintf (true)?0:printf
#define dbg if(false)
#define drepl(i,a,b) int i; if(false)
#define drep(i,n) int i; if(false)
#endif // DEBUG



int main() {
	int N, M;
	cin >> N >> M;
	vi x(N), y(M);
	ll ans1 = 0;
	rep(i, N) {
		cin >> x[i];
	}
	rep(i, M) {
		cin >> y[i];
	}

	rep(i, N - 1) {
		if (i < N / 2) {
			ans1 += (((ll)N - 1 - i)*(i + 1) % MOD) * (x[i + 1] - x[i]);
			ans1 %= MOD;
		}
		else {
			ans1 += (((ll)N - 1 - (N - 2 - i))*((N - 2 - i) + 1) % MOD) * (x[i + 1] - x[i]);
			ans1 %= MOD;
		}
	}
	ll ans2 = 0;
	rep(i, M - 1) {
		if (i < M / 2) {
			ans2 += (((ll)M - 1 - i)*(i + 1) % MOD) * (y[i + 1] - y[i]);
			ans2 %= MOD;
		}
		else {
			ans2 += (((ll)M - 1 - (M - 2 - i))*((M - 2 - i) + 1) % MOD) * (y[i + 1] - y[i]);
			ans2 %= MOD;
		}
	}

	cout << (ans1*ans2) % MOD << endl;

	return 0;
}

Measured memory_bytes: 1024
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
fact = math.factorial
sys.setrecursionlimit(10**9)
INF = 10**9
mod = 10**9+7

N = i()
X = s()[::-1]
num1 = 1
num2 = 1
num3 = 0
num4 = 0
cnt = X.count('1')
cnt1 = cnt+1#0用
cnt2 = cnt-1#1用
nums1 = []
nums2 = []
ans = [1]*N

for i in range(N):
    if X[i] == '0':
        nums1.append(num1)
    else:
        num3 += num1
        num4 += num2
        nums1.append(num2)
    if cnt1 != 0:
        num1 = (num1*2)%cnt1
    if cnt2 != 0:
        num2 = (num2*2)%cnt2

for i in range(N):
    if X[i] == '0':
        if cnt1 != 0: 
            nums2.append((num3+nums1[i])%cnt1)
        else:
            nums2.append(0)
            ans[i] = 0
    else:
        if cnt2 != 0:    
            nums2.append((num4-nums1[i])%cnt2)
        else:
            nums2.append(0)
            ans[i] = 0
nums2.reverse()
ans.reverse()

def p(n):
    if n == 0:
        return
    ans[i] += 1
    c = n%(bin(n).count('1'))
    p(c)

for i in range(N):
    p(nums2[i])
for i in range(N):
    print(ans[i])

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

int main()
{
	int n,money=100000;
	double debt;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		debt=money*1.05;
		money=debt;
		if((money%1000)!=0)
			money=money-(money%1000)+1000;
	}
	cout<<money<<endl;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  std::string S;
  std::cin >> S;
  std::cout << (std::count(S.begin(), S.end(), 'x') <= 7 ? "YES" : "NO") << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int N, Ma, Mb;
	cin >> N >> Ma >> Mb;
	int dp[401][401];
	int inf = (1 << 31) - 1;
	for (int i = 0; i < 401; ++i) {
		for (int j = 0; j < 401; ++j) {
			dp[i][j] = inf;
		}
	}
	dp[0][0] = 0;
	int a, b, c;
	for (int i = 0; i < N; ++i) {
		cin >> a >> b >> c;
		for (int j = 400; j > -1; --j) {
			for (int k = 400; k > -1; --k) {
				if (dp[j][k] != inf) {
					dp[j + a][k + b] = min(dp[j + a][k + b], dp[j][k] + c);
				}
			}
		}
	}
	int ans = inf;
	int i = 1;
	while (Ma*i < 401 && Mb*i < 401) {
		if (dp[Ma*i][Mb*i] != inf) {
			ans = min(ans, dp[Ma*i][Mb*i]);
		}
		++i;
	}
	cout << (ans == inf ? -1 : ans) << endl;
	return 0;
}

Measured memory_bytes: 896
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

inline void add(int &x, int val) {
  x = (x + val) % MOD;
}

int N, M;
int dp[3001][3001][2];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> M;
  rep(i, N+1) dp[0][i][i==0] = 1;
  rep(i, M) {
    rep(j, N+1) {
      rep(k, 2) {
        if (j+1 <= N) {
          // RR
          add(dp[i+1][j+1][k], dp[i][j][k]);
          // RB
          add(dp[i+1][j][k], dp[i][j][k]);
        }
        if (j > 0) {
          int nk = k | (j == 1);
          // BR
          add(dp[i+1][j][nk], dp[i][j][k]);
          // BB
          add(dp[i+1][j-1][nk], dp[i][j][k]);
        }
      }
    }
  }
  int s = 0;
  rep(i, N+1) add(s, dp[M][i][1]);
  cout << s << "\n";
  return 0;
}


Measured memory_bytes: 70656
import re

s = str(input())
flag = True

s_array = s.split('hi')
    
for list in s_array:
    res = re.match('[a-z0-9]', list)
    
    if res and len(res.group()) > 0 :
        flag = False
        break
            
if flag:
    print('Yes')
else:
    print('No')

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

int a[3],b[3];
bool flag=1;
int main(){
	rep(i, 3)
	cin >> a[i] >> b[i];

	int cnt[4] = {};
	rep(i, 3) {
		cnt[a[i]-1]++;
		cnt[b[i] - 1]++;
	}

	rep(i, 4) {
		if (cnt[i] == 0 || cnt[i] > 2) flag = 0;
	}

	if (flag) {
		cout << "YES\n";
		return 0;
	}
	else cout << "NO\n";
	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
a = [int(ai) - 1 for ai in input().split()]
s = [0]
cur = 0
for ai in a:
    cur += ai
    cur %= k
    s.append(cur)

d = {}
ans = 0

# first interval
for si in s[:k]:
     if si in d:
         d[si] += 1
     else:
        d[si] = 1
for key in d:
    val = d[key]
    if val > 1:
        ans +=  val * (val - 1) // 2

# syakutori
r = 0
for l in range(k, n+1):
    d[s[r]] -= 1
    if s[l] in d:
        ans += d[s[l]]
        d[s[l]] += 1
    else:
        d[s[l]] = 1
    r += 1

print(ans)


Measured memory_bytes: 112580
// 木の直径
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>

using namespace std;

#define MAX 100000
#define INFTY ( 1 << 30 )

class Edge
{
    public:
        int t, w;
        Edge(){}
        // t : 辺の end 側,  w : 辺の重み
        Edge(int t, int w): t(t), w(w){}
};

vector<Edge> G[MAX];
int n;
// 任意のスタート点から、各頂点までの距離を保持する配列
int d[MAX];

void bfs(int s)
{
    for(int i = 0; i < n; i++)
    {
        d[i] = INFTY;
    }

    queue<int> Q;
    // スタート点の情報を設定する
    Q.push(s);
    d[s] = 0;

    int u;

    while( !Q.empty() )
    {
        u = Q.front();
        Q.pop();

        for(unsigned int i = 0; i < G[u].size(); i++)
        {
            Edge e = G[u][i];

            // 未訪問の頂点について距離を求める
            if( d[e.t] == INFTY )
            {
                d[e.t] = d[u] + e.w;
                Q.push(e.t);
            }
        }
    }
}

void solve()
{
    // 適当な始点 s から最も遠い節点 tgt を求める
    bfs(0);

    int maxv = 0;
    int tgt = 0;

    for(int i = 0; i < n; i++)
    {
        if( d[i] == INFTY )
        {
            continue;
        }

        if( maxv < d[i] )
        {
            maxv = d[i];
            tgt = i;
        }
    }

    // tgt から最も遠い節点の距離 maxv を求める
    bfs(tgt);
    maxv = 0;

    for(int i = 0; i < n; i++)
    {
        if( d[i] == INFTY )
        {
            continue;
        }

        maxv = max(maxv, d[i]);
    }

    cout << maxv << endl;
}

int main(void)
{
    int s, t, w;

    cin >> n;

    for(int i = 0; i < n - 1; i++)
    {
        cin >> s >> t >> w;

        G[s].push_back(Edge(t, w));
        G[t].push_back(Edge(s, w));
    }

    solve();

    return 0;
}



Measured memory_bytes: 9936
s=int(input())
a=[s]
for i in range(1000000):
    if a[i]%2==0:
        a.append(int(a[i]/2))
    else:
        a.append(int(3*a[i]+1))
a_duplicate=sorted([j for j in set(a) if a.count(j)>1],key=a.index)
a[a.index(a_duplicate[0])]=0
print(a.index((a_duplicate[0]))+1)  





Measured memory_bytes: 10900
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		int sum = 0;
		int l[] = new int[n];
		for(int i = 0; i < n; i++) {
			l[i] = sc.nextInt();
			sum += l[i];
		}
		
		int ans = Integer.MAX_VALUE;
		for(int left = 0; left < n; left++) {
			int low = 0;
			for(int right = left; right < n; right++) {
				low += l[right];
				int[] dp = new int[n + 1];
				dp[0] = low;
				
				for(int position = 0; position < n; position++) {
					int length = 0;
					dp[position + 1] = Integer.MAX_VALUE;
					
					for(int le = position; le >= 0; le--) {
						length += l[le];
						
						if(position == n - 1 && le == 0) continue;
						
						
						if(length >= low) dp[position + 1] = Math.min(dp[position + 1], Math.max(length, dp[le ]));
					}
				}
				
				ans = Math.min(ans, dp[n] - low);
			}
		}
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 27460
import java.io.*;
import java.util.*;
import java.lang.*;

public class Main {
    public static MyScanner scan;
    public static PrintWriter out;
    public static void main(String[] args) {
        scan=new MyScanner();
        out=new PrintWriter(new BufferedOutputStream(System.out));

        int t=1;
//        int t=scan.nextInt();
        while(t-->0) {

            int x=scan.nextInt();
            out.println((x==1)?0:1);

        }
        out.close();
    }



    //scanner
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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

Measured memory_bytes: 25404
n = int(input())
arr = list(map(int, input().split()))

count = 0
for idx1 in range(0, len(arr)):
    mins = idx1
    for idx2 in range(idx1, len(arr)):
        if arr[idx2] < arr[mins]:
            mins = idx2
    
    if mins != idx1:
        arr[idx1], arr[mins] = arr[mins], arr[idx1]
        count += 1

print(" ".join(map(str, arr)), count, sep="\n")


Measured memory_bytes: 5604
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
void solve(int H, int W){
    int D[H][W];
    int ans = 0;
    rep(i,0,H)rep(j,0,W)cin >> D[i][j];
    rep(i,0,H)rep(j,i+2,H)rep(k,0,W)rep(l,k+2,W){
        int mini = INF, maxi = 0;
        rep(y,i,j+1)rep(x,k,l+1){
            if(y == i || y == j || x == k || x == l){
                mini = min(mini, D[y][x]);
            }else{
                maxi = max(maxi, D[y][x]);
            }
        }
        if(mini <= maxi)continue;
        int sum = 0;
        rep(y,i+1,j)rep(x,k+1,l){
            sum += mini - D[y][x];
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
}
main(){
    int H,W;
    cin >> H >> W;
    while(H){
        solve(H,W);
        cin >> H >> W;
    }
}


Measured memory_bytes: 3088