akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES

#include <vector>
#include <list>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <utility>
#include <ctgmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll mod = 1000000007;
const ll inf = 10e17;
const ld eps = 10e-9;



ll solve(void);
ll gcd(ll x, ll y);

int main(void)
{
	while (solve())
	{
	}
	return 0;
}

ll mulmod(ll x, ll y)
{
	return (x * y) % mod;
}

ll submod(ll x, ll y)
{
	return (x - y + 100 * mod) % mod;
}

ll power(ll n, ll r)
{
	if ( r == 0 ) { return 1; }
	if ( r == 1 ) { return n; }
	if ( n == 0 ) { return 0; }
	if ( n == 1 ) { return 1; }

	if (r % 2 == 0)
	{
		ll y = power(n, r/2);
		return mulmod(y, y);
	}
	else
	{
		ll y = power(n, (r-1)/2);
		return n * mulmod(y, y) % mod;
	}
}

ll gcd(ll x, ll y)
{
	if (y == 1) { return 1;}
	if (x % y == 0) { return y; }
	return gcd(y, x % y);
}

vector<ll> perm;
vector<ll> inv;
void init_inv(ll m)
{
	perm.resize(m);
	inv.resize(m);
	
	perm[0] = 1;
	inv[0] = 1;

	for (ll i = 1; i < m; i++)
	{
		perm[i] = mulmod(perm[i-1], i);
	}
	
	for (ll i = 1; i < m; i++)
	{
		inv[i] = power(perm[i], mod - 2);
	}
}

ll ncr(ll n, ll r)
{
	// n (n-1) ... (n-r)
	if ( r == n || r == 0 ) { return 1; }

	ll ans = 1;
	//for (ll i = 0; i < r; i++)
	//	ans = mulmod(ans, n - i);

	// return mulmod(ans, inv[r]);
	return mulmod(perm[n], mulmod(inv[n-r], inv[r]));
}

ll h, w;
bool iswall(vector<vector<bool>> s, pll pl)
{
	if (pl.first < 0 || pl.first >= h) { return true; }
	if (pl.second < 0 || pl.second >= w) { return true; }
	return s[pl.first][pl.second];
}

vector<vector<ll>> func(vector<vector<bool>> s, pll start)
{
	if (iswall(s, start))
	{
		return vector<vector<ll>>();
	}

	queue<pll> q;
	q.push(start);

	vector<vector<ll>> d(h, vector<ll>(w, 0));
	vector<vector<bool>> v(h, vector<bool>(w, false));
	vector<pll> mv = {pll(1,0), pll(0,1), pll(-1, 0), pll(0,-1)};

	v[start.first][start.second] = true;

	while (!q.empty())
	{
		auto qf = q.front();
		auto df = d[qf.first][qf.second];
		q.pop();

		//cout << qf.first << " " << qf.second << endl;

		for (auto m : mv)
		{
			auto n = pll(m.first+qf.first, m.second+qf.second);
			auto nd = df + 1;

			//cout << "*" << n.first << " " << n.second << endl;

			if (!iswall(s, n) && (!v[n.first][n.second]))// || nd < d[n.first][n.second]))
			{
				v[n.first][n.second] = true;
				d[n.first][n.second] = nd;
				q.push(n);
			}
		}
	}

	return d;
}

ll solve(void)
{
	cin >> h >> w;
	vector<vector<bool>> s(h, vector<bool>(w, false));
	

	for (ll i = 0; i < h; i++)
	{
		string si;
		cin >> si;
		for (ll j = 0; j < si.length(); j++)
		{
			s[i][j] = (si[j] == '#');
		}
	}
	
	//ll ans = func(s, pll(2,0), pll(0,4));

	ll ans = 0;
	for (ll i = 0; i < h; i++)
		for (ll j = 0; j < w; j++)
		{
			pll start(i, j);
			auto c = func(s, start);
			for (auto x: c)
				for(auto y:x)
					ans = max(ll(y), ans);
			//cout << i << " " << j << " : " << k << " " << l << " : " << c << endl;
		}

	cout << ans << endl;

	return 0;
}



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

int main() {
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  
  if ((abs(b-a) <= d && abs(c-b) <= d) || (abs(c-a) <= d)) {
    puts("Yes");
  }
  else {
    puts("No");
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<n;i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int n;
char A = 'A';
vector<char> ary;

void solve(){
    vi a(n);
    string s;
    rep(i,n) cin >> a[i];
    cin >> s;

    string ans;
    for(int i=0;i<s.size();i++){
        char c = s[i];
        int idx = find(all(ary),c) - ary.begin();
        idx-=a[i%n];
        if(idx<0) idx += ary.size();
        ans.push_back(ary[idx]);
    }
    cout << ans << endl;
}

int main(){
    rep(i,26) ary.push_back(i+'a');
    rep(i,26) ary.push_back(i+'A');
    sort(all(ary));
    while(1){
        cin >> n;
        if(!n) break;
        solve();
    }
}

Measured memory_bytes: 3172
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		while (true) {
			int h = scanner.nextInt();
			int w = scanner.nextInt();
			if (h == 0 && w == 0) {
				break;
			}
			char[][] map = new char[h][w];
			boolean[][] loop = new boolean[h][w];
			for (int i = 0; i < h; i++) {
				map[i] = scanner.next().toCharArray();
			}
		
			int x = 0;
			int y = 0;
			boolean flag = false;
			while (true) {
				if (loop[y][x]) {
					flag = true;
					break;
				}
				loop[y][x] = true;
				if (map[y][x] == '>')
					x++;
				else if (map[y][x] == '<')
					x--;
				else if (map[y][x] == '^')
					y--;
				else if (map[y][x] == 'v')
					y++;
				else
					break;
			}
			if (flag) {
				System.out.println("LOOP");
			} else {
				System.out.println(x + " " + y);
			}
		}

	}

}

Measured memory_bytes: 21864
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		//入力
		Scanner sc = new Scanner(System.in);
		int rate = sc.nextInt();
		sc.close();
		
		String ans = rate>=1200 ? "ARC" : "ABC";
	
		//出力
		System.out.println(ans);

	}

}

Measured memory_bytes: 9804
#include<bits/stdc++.h>
#define pb push_back
#define PI acos(-1)
#define mp make_pair
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define F first
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sdl(x) scanf("%lld",&x)
#define sd2l(x,y) scanf("%lld%lld",&x,&y)
#define maxn 100010
#define S second
#define ll long long int
#define inf 1000002014
#define infl 1000000000000020000ll
#define mod 1000000007
#define clrs(x) memset(x,0,sizeof x)
#define sz(x) (int) x.size()
#define pi pair< int,int >
#define pii pair<pi,int>
#define pu push
#define ld long double
#define trace1(x)  cerr << #x << ": " << x << endl
#define trace2(x, y)  cerr << #x << ": " << x << " | " << #y << ": " << y << endl
using namespace std;
int cnt[100010];
int main(int argc, char const *argv[])
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n,x;
    sd(n);
    int left = 0;
    for (int i = 0; i < n; ++i)
    {
        sd(x);
        cnt[x]++;
    }
    int o,t;
    o = t = 0;
    for (int i = 1; i <=100000; ++i)
    {
       if(cnt[i]%2==1)
        {
            cnt[i] = 1;
            left++;
        }
        if(cnt[i]!=0 && cnt[i]%2==0)
        {
            t++;
            cnt[i] = 2;
            left+=2;
        }
    }
    if(t%2==1)
        t++;
    //printf("%d\n",left);
    left-=t;
    printf("%d\n",left);
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);


    public static void main(String[] args) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int x = sc.nextInt();

        if (a + b >= x && a <= x) {
            System.out.println("YES");
        } else {
            System.out.println("NO");

        }
    }
}


Measured memory_bytes: 22228
def main():
    '''
    メイン関数
    '''
    # 入力を取得
    N = int(input())
    T, A = map(int, input().split())
    H_list = map(int, input().split())

    delta = 99999
    n = 1
    good = 0

    for H in H_list :
        temp = T - H * 0.006
        temp_delta = abs(A-temp)
        
        if temp_delta < delta :
            delta = temp_delta
            good = n
        n += 1

    print(good)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#include <math.h>
#include <iostream>
#include <bitset>
#include <map>

#define db double
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define mod 998244353
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv(z,a,b) vector<vector<int>>z(a,vector<int>(b))
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) begin(c),end(c)
#define pp pair<int,int>
#define fix(n) fixed << setprecision(n)
#define gmax(a,b) __gcd(a,b)
#define gmin(a,b) a/__gcd(a,b)*b
using namespace std;
//obj;
class binary{
public:
    bool isOK(int index, int key,vi a) {
    if (a[index] >= key) return true;
    else return false;
}
int binary_search(int key,vi a) {
   
    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key,a)) ok = mid;
        else ng = mid;
    }
    return ok;
}
}obj;

int main(){
int n;cin>>n;
for(int i=1;i<=n;i++){
    int flag=0;
    for(int x=1;x<n;x++){
        if(x*x>i)break;
        for(int y=1;y<n;y++){
            if(y*y>i)break;
            for(int z=1;z<n;z++){
                if(x*x>i)break;
                ll sum=x*x+y*y+z*z+x*y+x*z+y*z;
                if(sum>i)break;
                if(sum==i)flag++;
                
            }
        }
    }
cout<<flag<<endl;
}
 }


Measured memory_bytes: 3592
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

template <class T>
inline bool chmax(T& a, T b) {
    return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
    return a = (a > b) ? b : a;
}

ll const INF = 1LL << 60;
ll const MOD = 1000000007;

class Radix {
   private:
    const char* s;
    int a[128];

   public:
    Radix(const char* s = "0123456789ABCDEF") : s(s) {
        int i;
        for (i = 0; s[i]; ++i) a[(int)s[i]] = i;
    }
    std::string to(long long p, int q) {
        int i;
        if (!p) return "0";
        char t[64] = {};
        for (i = 62; p; --i) {
            t[i] = s[p % q];
            p /= q;
        }
        return std::string(t + i + 1);
    }
    std::string to(const std::string& t, int p, int q) {
        return to(to(t, p), q);
    }
    long long to(const std::string& t, int p) {
        int i;
        long long sm = a[(int)t[0]];
        for (i = 1; i < (int)t.length(); ++i) sm = sm * p + a[(int)t[i]];
        return sm;
    }
};

int main() {
    INIT;

    ll N, K;
    cin >> N >> K;

    Radix r;
    cout << SZ(r.to(N, K)) << endl;

    return 0;
}

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


int main(){
    int N;
    int D1, D2;
    int count = 0;
    int judge = 0;

    std::cin >> N;
    for(int i = 0; i < N; i++){
        std::cin >> D1 >> D2;
        if(D1 == D2){
            count++;
            if(count >= 3){
                judge = 1;
            //    break;
            }
        }else{
            count = 0;
        }
    }

    if(judge == 1){
        std::cout << "Yes";
    }else{
        std::cout << "No";
    }
}

Measured memory_bytes: 3632
#include<iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>

using namespace std;

int main()
{
    // 整数の入力
    long long N,i;
    vector<long long> data;
    cin >> N;
    data.push_back(2);
    data.push_back(1);
    for (i=0;i<85;i++){
        data.push_back(data[data.size() -1] + data[data.size() -2]);
    }
    cout << data[N] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){ //for debug
    ll n = vec.size();
    cout << "------------------------------------\n" ;
    rep(i,n) cout << i << " " << vec.at(i) << "\n";
    cout << "------------------------------------\n" ;
}

void pr2d(vector<vector<ll>> vec){ // for debug
    ll h = vec.size();
    ll w = vec.at(0).size();
    cout << "------------------------------------\n" ;
    rep(i,h){
        rep(j,w){
            cout << vec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
    cout << "------------------------------------\n" ;
}

int main(){
    ll x; cin >> x;
    ll y = 100;
    for(int i=1;i<4000;i++){
        y *= 1.01;
        if(y>=x){
            cout << i << endl;
            return 0;
        }
    }
}

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

int main() {
    int n; cin >> n;
    vector<int> a(n*3);
    for (int i=0; i<(n*3); ++i) cin >> a[i];
    sort(a.begin(), a.end(), greater<int>());
    long long ans = 0;
    for (int i=1; i<n*2; i+=2) ans += a[i];
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define F first
#define S second
#define eps 1e-6
#define mp make_pair
const long long INF=1e18;
const int MX=200005;
int N, M, k;
int arr[MX];
ll n;
int gcd(int a, int b)
{
    while(a && b)
    {
        if(a > b) a%=b;
        else b%=a;
    }
    return a + b;
}
int solve(int a, int b)
{
    ll g=gcd(a, b);
    ll ag=a/g, bg=b/g;
    if(ag*ag*bg != a) return 0;
    if(bg*bg*ag != b) return 0;
    return 1;
///if()
}
int main()
{
    int an=133432432;
    int a[3];
    for(int i=0;i<3;i++) cin>>a[i];
    sort(a, a+3);
    do
    {
        an=min(abs(a[0]-a[1])+abs(a[1]-a[2]), an);
    }
    while(next_permutation(a, a+3));
    cout<<an;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
 
int main()
{
	
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     
	int a,b,c,d;
	cin>>a>>b>>c>>d;
    
	while(a>0&&c>0)
	{
	
		  c=c-b;
		  a=a-d;
		  
		  
		  if(c<=0)
		  {
		 
		  	cout<<"Yes"<<endl;
		  	return 0;
		  	
		  }
		  
		  
		  else if(a<=0)
		  {
		  
		  	cout<<"No"<<endl;
		    return 0;
		  	
		  	
		  }
		  
	
	}	
	
	


     return 0;
     
     
}

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

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

  if (abs(N - M) > 1) {
    cout << 0 << endl;
    return 0;
  }

  long long ans = 1;
  
  if (N == M) {
    for (long long i = 1; i <= N; i++) {
      ans *= i * i % 1000000007;
      ans %= 1000000007;
    }
    ans = ans * 2 % 1000000007;
    cout << ans << endl;
    return 0;
  }

  if (N < M) swap(N, M);
  for (long long i = 1; i < N; i++) {
    ans *= i * i % 1000000007;
    ans %= 1000000007;
  }
  ans = ans * N % 1000000007;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
int n,m,a[200010];
signed main()
{
	memset(a,0,sizeof(a));
	scanf("%d%d",&n,&m);int t,maxn(1),ans(0);
	while(n--)
	{
		scanf("%d",&t),a[t]++,maxn=(maxn>t?maxn:t);
	}
	sort(a,a+maxn+1,std::greater<int>());
	while(a[m])
	{
		ans+=a[m++];
	}
	return printf("%d\n",ans),0;
}

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

using namespace std;

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

    vector<int>A,Gusu;
    for(int i=0;i<N;++i)
    {
        int a;
        cin >>a;
        A.push_back(a);
    }

    while (!A.empty())
    {
        if(A.back()%2==0)
        {
            Gusu.push_back(A.back());
        }
        A.pop_back();
    }
    
    string kyoka;
    bool is = all_of(Gusu.begin(),Gusu.end(),[](int i){return i%3==0 || i%5==0;});
    is ? kyoka="APPROVED":kyoka="DENIED";
    cout<<kyoka<<endl;
}

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

using namespace std;

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, z, w;

    cin >> n >> z >> w;
    vi v(n);

    for (auto &i : v)
        cin >> i;

    if (n == 1)
        cout << abs(w - v[0]) << endl;
    else
        cout << max(abs(v[n - 1] - v[n - 2]), abs(v.back() - w)) << endl;

    return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())

"""
stage = [[0 for _ in range(W)] for _ in range(H)]
ds = ((0, 0), (1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1))

def setv(p, v):
	global stage
	stage[p[1]][p[0]] = v

def getv(p):
	return stage[p[1]][p[0]]

def move(p, d):
	r = (p[0] + d[0], p[1] + d[1])
	if not (0 <= r[0] < W) or not (0 <= r[1] < H):
		return None
	return r

for h in range(H):
	for w in range(W):
		for d in ds:
			nextp = move((w, h), d)
			if not nextp:
				continue
			setv(nextp, (getv(nextp) + 1) % 2)
			#setv(nextp, (getv(nextp) + 1))

for h in range(H):
	print(*stage[h], sep="")
print()
"""

if 1 == H == W:
	print(1)
	exit()

if 1 == H and not 1 == W:
	print(W - 2)
	exit()

if 1 == W and not 1 == H:
	print(H - 2)
	exit()

print((H - 2) * (W - 2))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(long int I=X;I<Y;I++)
#define REP(I,X) for(long int I=X;I>=0;I--)
#define INF 1e9+7
using namespace std;

int solve(vector<int> puzzle,int n){
  if(n == 8)return 0;
  bool flag = 1;
  FOR(i,16,18)if(puzzle[18] != puzzle[i])flag = 0;
  FOR(i,19,21)if(puzzle[21] != puzzle[i])flag = 0;
  FOR(i,1,9)if(puzzle[9] != puzzle[i])flag = 0;
  FOR(i,22,30)if(puzzle[30] != puzzle[i])flag = 0;
  if(flag)return 0;
  int ans = 8;

  FOR(i,1,4)swap(puzzle[i],puzzle[27+i]);
  swap(puzzle[15],puzzle[16]);
  swap(puzzle[19],puzzle[21]);
  ans = min(ans,solve(puzzle,n+1)+1);
  FOR(i,1,4)swap(puzzle[i],puzzle[27+i]);
  swap(puzzle[15],puzzle[16]);
  swap(puzzle[19],puzzle[21]);

  FOR(i,7,10)swap(puzzle[i],puzzle[15+i]);
  swap(puzzle[13],puzzle[18]);
  swap(puzzle[10],puzzle[12]);
  ans = min(ans,solve(puzzle,n+1)+1);
  FOR(i,7,10)swap(puzzle[i],puzzle[15+i]);
  swap(puzzle[13],puzzle[18]);
  swap(puzzle[10],puzzle[12]);

  swap(puzzle[1],puzzle[24]);
  swap(puzzle[4],puzzle[27]);
  swap(puzzle[7],puzzle[30]);
  swap(puzzle[10],puzzle[21]);
  swap(puzzle[16],puzzle[18]);
  ans = min(ans,solve(puzzle,n+1)+1);
  swap(puzzle[1],puzzle[24]);
  swap(puzzle[4],puzzle[27]);
  swap(puzzle[7],puzzle[30]);
  swap(puzzle[10],puzzle[21]);
  swap(puzzle[16],puzzle[18]);

  swap(puzzle[3],puzzle[22]);
  swap(puzzle[6],puzzle[25]);
  swap(puzzle[9],puzzle[28]);
  swap(puzzle[12],puzzle[19]);
  swap(puzzle[13],puzzle[15]);
  ans = min(ans,solve(puzzle,n+1)+1);
  swap(puzzle[3],puzzle[22]);
  swap(puzzle[6],puzzle[25]);
  swap(puzzle[9],puzzle[28]);
  swap(puzzle[12],puzzle[19]);
  swap(puzzle[13],puzzle[15]);

  return ans;
}

int main(){
  int N;
  cin >> N;
  vector<int> ans;
  FOR(i,0,N){
    vector<int> puzzle(31,0);
    FOR(j,1,31)cin >> puzzle[j];
    ans.push_back(solve(puzzle,0));
  }
  for(auto x:ans)cout << x << endl;
}
 


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
//char a[100005];
int main() {
    int n;
    cin>>n;
    int sma,cha=0,cnt=0;
    scanf("%*d%d",&sma);
    for(int i=2;i<=n;i++){
        int tem;
        scanf("%d",&tem);
        if(tem-sma==cha)cnt++;
        else if(tem-sma>cha)cha=tem-sma,cnt=1;

        if(tem<sma)sma=tem;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

int main() {
	int x;
	cin >> x;
	if (x == 1) {
		cout << 0;
	}
	else {
		cout << 1;
	}
}


Measured memory_bytes: 3620
#include <stdio.h>

int main(){
    char S[4];
    int counta=0;
    int countb;
    int a=100,b=100;
    scanf("%s",S);
    for(int i=0;i<3;i++){  
        for(int j=i+1;j<4;j++){
            if((S[i]==S[j])&&((a!=i)&&(b!=j))){
                counta++;
                a=i;
                b=j;
            }
        }
    }
    if(counta==2){
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define reverse(x) reverse(x.begin(), x.end())
#define sort(x) sort(x.begin(), x.end())
#define pb push_back
#define pii pair<int, int>
#define pll pair<long long,long long>
#define f first
#define s second
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
int a[100005], n, m;

int main(){
	int i, j;
	cin >> n;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	int ans = 1e9;
	for(i=1;i<=101;i++){
		int c = 0;
		for(j=0;j<n;j++){
			c += (a[j]-i)*(a[j]-i);
		}ans = min(ans , c);
	}
	cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp> 
  #include <ext/pb_ds/tree_policy.hpp>
  #pragma comment(linker, "/stack:200000000")
  #pragma GCC optimize("O3")
  #pragma GCC optimize("Ofast")
  #pragma GCC optimize("unroll-loops")
    using namespace std;
  using namespace __gnu_pbds;
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define endl "\n"
    #define int long long
    #define all(v) v.begin(),v.end()
    #define rep(i,a,b) for(int i = a; i <=b; i++)
    #define rep2(i,a,b) for(int i = a; i>=b; i--)
    #define PB push_back
    #define MP make_pair
    #define db long double
    #define trace1(x)                cerr<<#x<<": "<<x<<endl
    #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
    #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
    #define trace3race4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
    #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
    #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
    #define cases int testcases;cin>>testcases; while(testcases--)
    #define INF 2000000000
    const double PI = acos(-1);
    const int N = 100005;

    int dp[N];
    int arr[N];
    
  int32_t main() 
  {
    IOS

        
        int n;
        cin >> n;
        string s;
        cin >> s;

        char ch = s[0];
        int ans = 1;

        for(int i = 1; i < s.length(); i++)
        {
          if(ch != s[i])
          {
            ch = s[i];
            ans++;
          }
        }

        cout << ans;
    return 0;
      }

Measured memory_bytes: 512
import collections 

n = int(input())
A = list( map(int, input().split()))

d = collections.Counter(A)

x = sorted([i for i in d.items() if i[1]>1])
if len(x)==0 :
  print(0)
elif x[-1][1] >3 :
  print(x[-1][0]**2)
elif len(x) == 1 :
  print(0)
else:
  print(x[-1][0]*x[-2][0])

Measured memory_bytes: 18600
#include <bits/stdc++.h>
using namespace std;
#define MOD int(1e9 +7)
#define MAXN 100005
#define ll long long
inline ll mult(ll a, ll b, ll p = MOD) {return (ll) a * b % p;}
inline ll addmod(ll a, ll val, ll p = MOD) {{if ((a = (a + val)) >= p) a -= p;} return a;}

vector < int > adj[MAXN];
bool visited[MAXN];
ll wp[MAXN],bp[MAXN];
void __DFS(int v){
    visited[v] = true;
    ll wres=1,bres=1;        
    for(int u: adj[v])
        {
            if(!visited[u])
            {
               __DFS(u);
               wres=mult(wres,addmod(wp[u],bp[u]));
               bres=mult(bres,wp[u]);
            }
        }
        wp[v]=wres;bp[v]=bres;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;
    cin>>n;

    int m=n-1;
    while(m--)
    {
        int i, j;
        cin >> i >> j;
        adj[i].push_back(j);
        adj[j].push_back(i);
    }
    __DFS(1);
    cout<<addmod(wp[1],bp[1])<<endl;
    return 0;        
}


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

#define all(v) v.begin(), v.end()

const int N = 1e5;

int p[N];
vector<int> g[N];
vector<int> id, p_id;
bool used[N];

void dfs(int v)
{
    used[v] = true;
    for (int u : g[v])
    {
        if (!used[u])
            dfs(u);
    }
    id.push_back(v);
    p_id.push_back(p[v]);
}

int main()
{

    //freopen("input.txt", "r", stdin);


    int n, m;
    scanf("%d%d", &n, &m);

    for (int i = 0; i < n; ++i)
    {
        used[i] = false;
        scanf("%d", &p[i]);
        --p[i];
    }
	for (int i = 0, u, v; i < m; ++i)
	{
		scanf("%d%d", &u, &v);
		--u; --v;
		g[u].push_back(v);
		g[v].push_back(u);
	}

	int ans = 0;
	for (int v = 0, l, r, sz; v < n; ++v)
    {
        if (used[v]) continue;
        id.clear(); p_id.clear();
        dfs(v);
        sort(all(id)); sort(all(p_id));

        l = 0; r = 0; sz = (int)p_id.size();

        while(l < sz && r < sz)
        {
            while(l < sz && id[l] < p_id[r]) ++l;
            while(l < sz && r < sz && id[l] == p_id[r])
            {
                ++l; ++r;
                ++ans;
            }
            while(r < sz && id[l] > p_id[r]) ++r;
        }
    }

    printf("%d", ans);

}


Measured memory_bytes: 10156
# INPUT
# 普通の入力
n, k = map(int, input().split())
x = list(map(int, input().split()))

# PROCESS

# 全探索
answers = []

def start_to_end(start, end):
  first_move = abs(start)
  s_to_e_cost = abs(end - start)
  return first_move + s_to_e_cost

def end_to_start(start, end):
  first_move = abs(end)
  s_to_e_cost = abs(end - start)
  return first_move + s_to_e_cost

for s_idx in range(len(x)-k+1):
  start = x[s_idx]
  end = x[s_idx+k-1]
  # s -> e
  answers.append(start_to_end(start, end))
  # e -> s
  answers.append(end_to_start(start, end))

answer = min(answers)

# OUTPUT
print(answer)

Measured memory_bytes: 14384
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

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

struct DisjointSet {
    private:
        vector<int> par;
        vector<int> diff_weight;
        vector<int> rank;
    
    public:
        DisjointSet(int n) {
            par = vector<int>(n);
            rep(i, n) par[i] = i;
            diff_weight = vector<int>(n);
            rank = vector<int>(n);
        }
    
        int find(int i) {
            if (par[i] == i) return i;
            int p = find(par[i]);
            diff_weight[i] += diff_weight[par[i]];
            par[i] = p;
            return p;
        }

        int weight(int i) {
            int p = find(i);
            return diff_weight[i];
        }
    
        bool joint(int i, int j, int w) {
            w += weight(i); w -= weight(j);
            int pi = find(i);
            int pj = find(j);
            if (pi == pj) return false;
    
            if (rank[pi] < rank[pj]) {
                swap(pi, pj);
                w = -w;
            }
            if (rank[pi] == rank[pj]) rank[pj]++;

            par[pj] = pi;
            diff_weight[pj] = w;
            return true;
        }
    };

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

    int n, q;
    cin>>n>>q;
    DisjointSet ds(n);
    rep(i, q) {
        int c, x, y, z;
        cin>>c>>x>>y;
        if (c == 0) {
            cin>>z;
            ds.joint(x, y, z);
        }
        else {
            int px = ds.find(x);
            int py = ds.find(y);
            if (px != py) cout<<'?'<<endl;
            else cout<<ds.weight(y) - ds.weight(x)<<endl;
        }
    }
}


Measured memory_bytes: 4168
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
#include <cstdlib>
#include <map>
using ll = long long int;
using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    float average = (float)accumulate(A.begin(), A.end(), 0) / N;
    float flag = 100;
    int ans = 0;
    for (int i = N - 1; i >= 0; i--)
    {
        if (abs(average - A[i]) <= flag)
        {
            flag = abs(average - A[i]);
            ans = i;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  int i;
  while (i < N){
    string S;
    cin >> S;
    if(S == "Y"){
      cout << "Four"<<endl;
      break;
    }
    if(i == N-1){
      cout << "Three" << endl;
    }
    i++;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string first;
  string second;
  
  cin>>first>>second;
  
  if(first[0]==second[2]&&first[1]==second[1]&&first[2]==second[0]){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	final int _intMax = Integer.MAX_VALUE; // =2147483647>10^9
	final int _intMin = Integer.MIN_VALUE;
	final long _longMax = Long.MAX_VALUE; // =9223372036854775807L>10^18
	final long _longMin = Long.MIN_VALUE;
	static boolean bElapsed = false;

	void solve() {
		int[] ia = readNums();
		int n = ia[0];
		int y = ia[1];
		y /= 1000;
		for (int b = 0; b <= n; b++) {
			for (int c = 0; c <= n; c++) {
				int a = n - b - c;
				if (a < 0)
					continue;
				if (y == 10 * a + 5 * b + c) {
					pln(a + " " + b + " " + c);
					return;
				}
			}
		}
		pln("-1 -1 -1");
	}

	int abs(int a) {
		return (a >= 0) ? a : -a;
	}

	int max(int a, int b) {
		return (a > b) ? a : b;
	}

	int min(int a, int b) {
		return (a < b) ? a : b;
	}

	int pint(String s) {
		return Integer.parseInt(s);
	}

	long plong(String s) {
		return Long.parseLong(s);
	}

	String readLine() {
		try {
			return _in.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int readNum() {
		String line = readLine();
		return pint(line);
	}

	String[] readFlds() {
		String line = readLine();
		return line.split(" ");
	}

	int[] readNums() {
		String[] flds = readFlds();
		int[] nums = new int[flds.length];
		for (int i = 0; i < flds.length; i++) {
			nums[i] = pint(flds[i]);
		}
		return nums;
	}

	void p(char c) {
		_out.print(c);
	}

	void pln(char c) {
		_out.println(c);
	}

	void p(double d) {
		_out.print(d);
	}

	void pln(double d) {
		_out.println(d);
	}

	void p(long l) {
		_out.print(l);
	}

	void pln(long l) {
		_out.println(l);
	}

	void p(String s) {
		_out.print(s);
	}

	void pln(String s) {
		_out.println(s);
	}

	static BufferedReader _in;
	static PrintWriter _out;

	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		_in = new BufferedReader(new InputStreamReader(System.in));
		_out = new PrintWriter(System.out);
		new Main().solve();
		_out.flush();
		long end = System.currentTimeMillis();
		if (bElapsed) {
			System.err.println((end - start) + "ms");
		}
	}
}


Measured memory_bytes: 22740
n = []

for i in range(0,5) :
    n.append(int(input()))

k = int(input())

count = 0

for p in range(0, 4) :
    for q in range(p + 1, 5) :
        if n[q] - n[p] > k :
            print(':(')
            exit()

print('Yay!')

Measured memory_bytes: 3060
#include<iostream>
#include<set>
#include<string>
#include<string.h>
using namespace std;
const int maxn=5e5+10;
int q,n;
char s[maxn];
set<int>S[30];
int main()
{
	std::ios::sync_with_stdio(false);
	cin>>n>>s+1>>q; 
	int a;
	int l,r,i;
	char c;
	for(int i=0;i<26;i++)S[i].insert(n+1);
	for(int i=1;i<=n;i++)S[s[i]-'a'].insert(i);
	while(q--)
	{
		cin>>a;
		if(a==1)
		{
			cin>>i>>c;
			if(s[i]!=c)S[s[i]-'a'].erase(i);
			s[i]=c;
			S[c-'a'].insert(i);
		}
		else
		{
			cin>>l>>r;
			int ans=0;
			for(int i=0;i<26;i++)
			{
				if(*S[i].lower_bound(l)<=r)ans++;
			}
			cout<<ans<<endl;
		}
	}
	return 0;
 } 

Measured memory_bytes: 24192
using System;

namespace Make_Purse_Light
{
    class Program
    {
        private static void Main(string[] args)
        {
            int n, k, i = 0, q, j;
            int[] m, x = new int[4], y = new int[4], p = new int[] { 10, 50, 100, 500 };

            while (true)
            {
                n = int.Parse(Console.ReadLine());
                if (n==0) { break; }
                if (i!=0) { Console.WriteLine(); }
                i++;
                k = 0;
                m = Array.ConvertAll(Console.ReadLine().Trim().Split(' '), int.Parse);
                for (j = 3; j >= 0; j--)
                {
                    k += m[j] * p[j];
                }
                q = k - n;

                for (j = 3; j >= 0; j--)
                {
                    x[j] = q / p[j]; q -= x[j] * p[j];
                    y[j] = Math.Max(0, m[j] - x[j]);
                }

                for (j = 0; j < 4; j++)
                {
                    if (y[j]!=0) { Console.WriteLine("{0} {1}", p[j], y[j]); }
                }
            }
        }
    }
}


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

int n, m, q;
int ans = 0;


void dfs(int _now_len, vector<int> a_vec, vector<int> _a, vector<int> _b, vector<int> _c, vector<int> _d) {
	if (_now_len == n) {
		int num = 0;
		for (int i = 0; i < q; i++){
			if (a_vec[_b[i] - 1] - a_vec[_a[i] - 1] == _c[i])
				num += _d[i];
		}
		ans = max(num, ans);
	}
	else {
		int cnt = (_now_len == 0) ? 1: a_vec[_now_len - 1];
		for (int i = cnt; i <= m; i++) {
			a_vec[_now_len] = i;
			dfs(_now_len + 1, a_vec, _a, _b, _c, _d);
		}
	}
}


int main() {
	cin >> n >> m >> q;
	vector<int> a(q);
	vector<int> b(q);
	vector<int> c(q);
	vector<int> d(q);
	for (int i = 0; i < q; i++)
	    cin >> a[i] >> b[i] >> c[i] >> d[i];
	vector<int> queli(n);
	dfs(0, queli, a, b, c, d);
	cout << ans << endl;

	return 0;
}

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

auto chmin = [](auto&& a, auto b) { return b < a ? a = b, 1 : 0; };

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  while (cin >> n >> m, n) {
    vector<int> a(n), h(n);
    for (int i = 1; i < n - 1; ++i) {
      cin >> a[i] >> h[i];
    }
    h.back() = 1000;
    vector<vector<int>> g(n, vector<int>(n, 1e6));
    for (int i = 0; i < n; ++i) {
      g[i][i] = 0;
    }
    while (m--) {
      int i, j, w;
      cin >> i >> j >> w;
      --i, --j;
      g[i][j] = w;
    }
    vector<vector<int>> v(1001);
    vector<int> id(n);
    for (int i = 0; i < n; ++i) {
      id[i] = v[h[i]].size();
      v[h[i]].push_back(i);
    }
    vector<vector<vector<int>>> dist(n, vector<vector<int>>(n));
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        dist[i][j].assign(1 << v[max(h[i], h[j])].size(), numeric_limits<int>::max());
      }
    }
    priority_queue<tuple<int, int, int, int>, vector<tuple<int, int, int, int>>, greater<>> pq;
    pq.emplace(dist[0][0][1] = 0, 0, 0, 1);
    while (not pq.empty()) {
      int d, i, j, bt;
      tie(d, i, j, bt) = pq.top();
      pq.pop();
      if (d != dist[i][j][bt]) continue;
      for (int k = 0; k < n; ++k) {
        if (h[i] > h[k]) continue;
        int nh = max(h[k], h[j]), nbt = 0;
        if (max(h[i], h[j]) == nh) {
          nbt = bt;
        }
        if (h[k] == nh) {
          nbt |= 1 << id[k];
        }
        int cost = h[k] == max(h[i], h[j]) and bt >> id[k] & 1 ? 0 : a[k];
        if (chmin(dist[k][j][nbt], d + g[i][k] + cost)) {
          pq.emplace(dist[k][j][nbt], k, j, nbt);
        }
      }
      for (int k = 0; k < n; ++k) {
        if (h[j] > h[k]) continue;
        int nh = max(h[i], h[k]), nbt = 0;
        if (max(h[i], h[j]) == nh) {
          nbt = bt;
        }
        if (h[k] == nh) {
          nbt |= 1 << id[k];
        }
        int cost = h[k] == max(h[i], h[j]) and bt >> id[k] & 1 ? 0 : a[k];
        if (chmin(dist[i][k][nbt], d + g[k][j] + cost)) {
          pq.emplace(dist[i][k][nbt], i, k, nbt);
        }
      }
    }
    int res = dist.back().back()[1];
    if (res < 1e6) {
      cout << res << '\n';
    } else {
      cout << "-1\n";
    }
  }
}



Measured memory_bytes: 36848
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
int main() {
    int N, M, X; cin >> N >> M >> X;
    vector<int>C(N);
    vector<vector<int>>A(N, vector<int>(M));
    rep(i, N) {
        cin >> C[i];
        rep(j, M)cin >> A[i][j];
    }
    int ans = -1;
    rep(bit, 1 << N+1) {
        vector<int>sum(M+1);
        rep(i, N) {
            if (bit & (1 << i)) {
                rep(j, M)sum[j] += A[i][j];
                sum[M] += C[i];
            }
        }
        rep(i, M) {
            if (sum[i] < X)break;
            if (i == M - 1) {
                if (ans == -1)ans = sum[M];
                else ans = min(ans, sum[M]);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3556
fun main(args : Array<String>) {
    val (A, B) = readLine()!!.split(" ").map { it.toInt() }

    val isAEven = A.mod(2) == 0
    val isBEven = B.mod(2) == 0

    val answer = !(isAEven || isBEven)
    val ansStr = if (answer)  "Yes" else "No"

    println(ansStr)
}

Measured memory_bytes: 37880
d = input()
a = int(input())
p = []
k = len(d)
for i in range(k):
  for j in range(min(6,k-i+1)):
    p.append(d[i:i+j])
    
x = list(set(p))
x.sort()
del x[0]
 
print(x[a-1])

Measured memory_bytes: 5040
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

const int MAX = 107;
const int MOD = 1000000007;

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    if (n % 2) {cout << "No"; return;}
    for (int i = 0; i < n / 2; i++) {
        if (s[i] != s[i + n / 2]) {cout << "No"; return;}
    }
    cout << "Yes";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("in.in", "r", stdin); freopen("out.out", "w", stdout);
    //int tt; cin >> tt; for (int i = 1; i <= tt; i++) {cout << "Case #" << i << ": "; solve();}
    solve();
}

Measured memory_bytes: 3580
#include<stdio.h>
#include<math.h>
int num(int n){
  int count=0;
  while(n%2 == 0){
    n = n/2;
    count++;
  }
  return count;
}
int main(){
  int N,a[10000],i;
  int sum=0;
  scanf("%d",&N);
  for (i=0;i<N;i++){
    scanf("%d",&a[N]);
    sum += num(a[N]);
  }
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 128
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, product


def resolve():
    h, w = map(int, input().split())
    A = [[_ for _ in input()] for _ in range(h)]
    B = [i for i in A if '#' in i]
    C = zip(*[i for i in zip(*B) if '#' in i])
    for i in C:
        print(*i, sep='')

        # print(*C,sep='')


resolve()

Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1000000000 + 7;

bool debug = 0;

void solve() {
    string s;
    ll k;
    cin >> s >> k;
    ll scnt = 0;
    string t = s + s;
    ll tcnt = 0;
    bool same = true;
    for (int i = 0; i < (int)s.size() - 1; i++) {
        if (s[i] == s[i + 1]) {
            i++;
            scnt++;
        }
        if (s[0] != s[i]) same = false;
    }
    for (int i = 0; i < (int)t.size() - 1; i++) {
        if (t[i] == t[i + 1]) {
            i++;
            tcnt++;
        }
    }
    ll ans = scnt * k + (tcnt - 2 * scnt) * (k - 1);
    if (same) ans = (k * (ll)s.size()) / 2;
    cout << ans << endl;
}

int main() {
    if (debug) {
        while (true) {
            cout << "********" << endl;
            solve();
        }
    } else {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3656
#include "iostream"
#include "algorithm"
#include "vector"
#include "string"
#include "cmath"
typedef long long ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll NN;


  std::cin >> NN;

  int count = 0;

  for (size_t i = 0; i < 4; i++) {

    if (NN % 10 == 2) {
      count ++;
    }
    NN /= 10;
  }

  std::cout << count << '\n';


  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstring>
#include <tuple>
#include <utility>
#include <list>
#include <cmath>
#include <unordered_map>

using namespace std;

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

const int INF = 1 << 29;
const LL MOD = 100000;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define all(c) (c).begin(), (c).end()

struct edge{ int to, cost; edge(int t, int c) :to(t), cost(c){} };

int main()
{
	//while (cin >> n)
	stringstream ss;
	//ss << "result" << i + 1 << ".txt";
	//FILE* fp_out = freopen(ss.str().c_str(), "w", stdout);

	int n;
	while (cin >> n)
	{
		rep(k, n)
		{
			vector<int> balls(10);
			rep(i, 10) cin >> balls[i];
			function<bool(int, int, int)> dfs = [&](int left, int right, int idx)
			{
				if (idx == 10) return true;
				int x = balls[idx];
				return (left < x && dfs(x, right, idx + 1)) ||
					(right < x && dfs(left, x, idx + 1));
			};

			cout << (dfs(0, 0, 0) ? "YES" : "NO") << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1196
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    s = [''.join(sorted(list(SS()))) for _ in range(N)]

    cnt = collections.Counter(s)
    ans = sum([i * (i - 1) // 2 for i in cnt.values()])

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 24872