akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////


int main() {
	ll N;
	string s, t;
	cin >> N >> s >> t;

	ll db = 0;

	repn(i, N) {
		ll b = 1;

		rep(j, i) {
			if (s[j + N - i] != t[j]) { b = 0; }
		}

		if (b == 1) { db = max(db, i); }
	}

	cout << 2 * N - db;


	system("PAUSE");

}





Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int O = 0;
  for (int i = 0; i < M; i++) {
    int P;
    cin >> P;
    O += P;
  }
  if (N < O) {cout << -1 << endl;}
  else {cout << N - O << endl;}
}

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

bool ng[26];
int ten[8];
int kiyo[26];
vector<char> vc;

int dfs(int i, int used, int sum){
    if(i == vc.size())  return sum==0;
    int ret = 0;
    for(int j = 0; j < 10; j++){
        if((used>>j)&1) continue;
        if(j == 0 && ng[vc[i]-'A']) continue;
        ret += dfs(i+1, used|(1<<j), sum+j*kiyo[vc[i]-'A']);
    }
    return ret;
}

int main(){
    ten[0] = 1;
    for(int i = 1; i < 8; i++){
        ten[i] = ten[i-1]*10;
    }

    int n;
    while(cin >> n, n){
        // init
        for(int i = 0; i < 26; i++) ng[i] = kiyo[i] = 0;
        vc.clear();

        string s[n];
        for(int i = 0; i < n; i++)  cin >> s[i];

        for(int i = 0; i < n; i++){
            for(int j = 0; j < s[i].length(); j++){
                vc.push_back(s[i][j]);
                kiyo[s[i][j]-'A'] += (i==n-1 ? -1 : 1) * ten[s[i].length()-1-j];
            }
            if(s[i].length() > 1)   ng[s[i][0]-'A'] = true;
        }
        sort(vc.begin(), vc.end());
        vc.erase(unique(vc.begin(),vc.end()), vc.end());
        cout << dfs(0, 0, 0) << endl;
    }

    return 0;
}


Measured memory_bytes: 3056
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#pragma gcc target ("avx2")
#pragma gcc optimization ("Ofast")
#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int d;
	scanf("%d", &d);
	rep(i, d)printf("%d\n", (i % 25) + 1);

	Please AC;
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001001001001001;
const int MOD = 1000000007;

template <typename T>
void print(const T &v);

int main()
{
    int k;
    cin >> k;
    set<ll> s;
    // if (k % 2 == 0)
    // {
    //     cout << -1 << endl;
    //     return 0;
    // }
    ll num = 7;
    for (int i = 1;; i++)
    {
        num %= k;
        if (num == 0)
        {
            cout << i << endl;
            return 0;
        }
        if (s.count(num))
        {
            cout << -1 << endl;
            return 0;
        }
        s.insert(num);
        num = num * 10 + 7;
    }
}

// Use For Debug
template <typename T>
void print(T const &v)
{
    for (int i = 0; i < v.size(); i++)
    {
        if (i)
            cout << ' ';
        cout << v[i];
    }
    cout << endl;
};

Measured memory_bytes: 50392
while true
  n,x = gets.split(" ").map(&:to_i)
  if (n==0&&x==0) then
    break
  end   
  count = 0
  for i in 1..n
    
    for j in 1..n
      if i == j then
        break
      end
      
      for k in 1..n
        if k == j then
          break
        end
        if( x == i + j + k ) then
          count+=1
        end
      end
    end
  end
  puts count
end

Measured memory_bytes: 8816
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define ok cout << "ok" << endl;
#define sp << " " <<
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const ll inf = 9e18;
template<typename T1, typename T2> ll ceill(T1 a, T2 b){ return (a+b-1)/b; }
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(a>b){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

#include <iostream>
#include <vector>
#include <map>
using namespace std;

class debug
{
public:
    typedef long long ll;
    template<typename T> void vd(vector<T> vec);
    template<typename T> void vd2(vector<vector<T>> vec);
    template<typename T> void ad(T *arr, ll n);
    template<typename T, size_t N> void ad2(T (&arr)[N], ll n);
    template<typename T> void md(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vd(vector<T> vec)
{
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T> void debug::vd2(vector<vector<T>> vec)
{
    for(auto vv : vec) for(auto vvv : vv) cout << vvv << " ";
    cout << endl;
}

template<typename T> void debug::ad(T *arr, ll n)
{
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T, size_t N> void debug::ad2(T (&arr)[N], ll n)
{
    for(int i=0; i<=N; i++) for(int j=0; j<=n; j++) cout << arr[i][j] << " ";
    cout << endl;
}

template<typename T> void debug::md(T mp)
{
    cout << "key : value" << endl;
    for(auto const& m : mp) cout << m.first << " : " << m.second << endl;
    cout << endl;
}
debug debug;

double dp[3000][3000];

class ICoins {
public:
    void solve(std::istream& in, std::ostream& out)
    {
        int n;
        in >> n;
        vector<double> p(n);
        for(int i=0; i<n; i++){
            in >> p[i];
        }

        for(int i=0; i<3000; i++){
            for(int j=0; j<3000; j++){
                dp[i][j] = 0.0;
            }
        }
        dp[0][0] = 1.0;
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                dp[i+1][j+1] += dp[i][j] * p[i];
                dp[i+1][j] += dp[i][j] * (1.0 - p[i]);
            }
        }

        double res = 0.0;
        for(int i=(n+1)/2; i<=n; i++){
            //cout << dp[n][i] << endl;
            res += dp[n][i];
        }

        out << setprecision(10) << res << endl;
    }
};


int main() {
	ICoins solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 70528
s = [list(map(int,input().split())) for i in range(3)]

def solve():
    if not (s[0][1] - s[0][0] == s[1][1] - s[1][0] == s[2][1] - s[2][0]): return False
    if not (s[0][2] - s[0][1] == s[1][2] - s[1][1] == s[2][2] - s[2][1]): return False
    if not (s[1][0] - s[0][0] == s[1][1] - s[0][1] == s[1][2] - s[0][2]): return False
    if not (s[2][0] - s[1][0] == s[2][1] - s[1][1] == s[2][2] - s[1][2]): return False
    return True

print('Yes' if solve() else 'No')


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

/*-------------------Define Start-------------------*/
typedef bool BL;    					// 布尔类型
typedef char SB;    					// 有符号1字节,8位
typedef unsigned char UB;    			// 无符号1字节,8位
typedef short SW;    					// 有符号短整型,16位
typedef unsigned short UW;    			// 无符号短整型,16位
typedef long SDW;    					// 有符号整型,32位
typedef unsigned long UDW;   			// 无符号整型,32位
typedef long long SLL;    				// 有符号长整型,64位
typedef unsigned long long ULL;			// 无符号长整型,64位
typedef char CH;    					// 单个字符
typedef float R32;    					// 单精度浮点数
typedef double R64;    					// 双精度浮点数

#define Rep(i, n) for (register SDW i = 0; i < (n); ++i)
#define For(i, s, t) for (register SDW i = (s); i <= (t); ++i)
#define rFor(i, t, s) for (register SDW i = (t); i >= (s); --i)
#define foreach(i, c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,0x7f,sizeof(a))
#define LOWBIT(x) ((x)&(-x))

#define MP make_pair
#define PB push_back
#define ft first
#define sd second
#define ALL(x) x.begin(),x.end()

#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl

const ULL mod = 1e9 + 7;				//常用模数(可根据题目需要修改)
const ULL inf = 0x7fffffff;				//用来表示无限大
const ULL infLL = 0x7fffffffffffffffLL;	//用来表示无限大

// 重载<<操作符，用来打印vector 
template < typename T >
ostream& operator<< (ostream& out, vector< T > vec) {
	foreach(i, vec) {
		if(i != vec.begin()) {
			out << " ";
		}
		out << *i;
	}
    return out;
}
/*-------------------Define End-------------------*/

const UDW maxN = 1e5 + 7;

struct Bomb{
	SDW pos; // 炸弹的坐标 
	BL st; // 激活状态 
	
	Bomb() {}
	Bomb(SDW pos, BL st) : pos(pos), st(st) {}
	
	BL operator< (const Bomb &x) const {
		return pos < x.pos;
	}
};

struct Vertex{
	vector< SDW > next;
}; 

struct Edge{
	SDW id, from, to;
	
	Edge(SDW id, SDW from, SDW to) : id(id), from(from), to(to) {}
};

SDW N, M; 
Bomb bomb[maxN];
vector< Edge > E;
Vertex V[maxN];
BL vis[maxN];
SDW k;
vector< SDW > c;

void addEdge(Edge x) {
    V[x.from].next.PB(E.size());
    E.PB(x);
}

void input(){
	cin >> N >> M;
	Rep(i, N) {
		cin >> bomb[i].pos >> bomb[i].st;
	}
	sort(bomb, bomb + N); // 把炸弹按坐标排序，bomb[N]为假想的炸弹 
	
	Rep(i, M) {
		SDW L, R;
		cin >> L >> R;
		if(L > bomb[N - 1].pos || R < bomb[0].pos) {
			continue;
		}
		L = lower_bound(bomb, bomb + N, Bomb(L, false)) - bomb; 		// 把L移动到L右边离L最近的第一个炸弹的下标
		R = upper_bound(bomb, bomb + N, Bomb(R, false)) - bomb - 1; 	// 把R移动到R左边离L最近的第一个炸弹的下标
		addEdge(Edge(i << 1, L, R + 1));
		addEdge(Edge(i << 1 | 1, R + 1, L));
	}
}

BL dfs(SDW x) {
	vis[x] = true;
	
	BL flag = bomb[x].st;
	
	foreach(i, V[x].next) {
		Edge e = E[*i];
		
		if(!vis[e.to] && dfs(e.to)) {
			c.PB((e.id >> 1) + 1);
			++k;
			flag ^= 1;
		}
	}
	
	return flag;
}

void solve(){
	rFor(i, N, 1) {
		bomb[i].st ^= bomb[i - 1].st;
	} 
	
	For(i, 0, N) {
		if(!vis[i] && dfs(i)) {
			k = -1;
			break;
		}
	}
	
	sort(ALL(c));
}

void output(){
	cout << k << endl;
	if(k != -1) {
		cout << c << endl;
	}
}

int main() {
	input();
	solve();
	output();
	return 0;
}


Measured memory_bytes: 26920
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int n;
    cin >> n;
    int cnt=0;
    bool used[100010] = {0};
    for (int i=0; i<n; i++) {
        int ai; cin >> ai;
        if (used[ai]) cnt++;
        else used[ai] = true;
    }
    cout << max(1, n - (cnt + cnt%2)) << '\n';
    return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n;
string ss;
int main() {
	cin>>n>>ss;
	int len=ss.length();
	for (int i=0;i<len;++i)
		ss[i]=(ss[i]-'A'+n)%26+'A';
	cout<<ss<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main (String [] args) {
		Scanner scan = new Scanner (System.in);
		int n = scan.nextInt();
		int data[] = new int[n];
		
		for (int i = 0; i < n; i++) {
			data[i] = scan.nextInt();
		}
		scan.close();
		
		ShellSort(data, n);
		
	}
	
	public static void InsertionSort(int[] A, int n, int[] g) {
		
		int cnt = 0;
		
		for ( int i = 0; i < g.length; i++) {
			for (int j = g[i]; j < n; j++) {
				int v = A[j];
				int k = j - g[i];
				
				
				while ( k >= 0 && A[k] > v) {
					A[k + g[i]] = A[k];
					k -= g[i];
					cnt++;
				}
				A[k + g[i]] = v;
			}
		}
		
		System.out.println(cnt);
		
		for (int i = 0; i < n; i++) {
			System.out.println(A[i]);
		}
	}
	
	public static void ShellSort(int A[], int n) {
		int m = 1;
		int mm = 0;
		int leng = A.length;
		int[] G;
		
		for ( int g = leng / 2; g > 0; g /= 2) {
			m++;
		}

		if (m == 1) {
			 G = new int[m];
			 G[0] = m;
			 System.out.println(m);
			 System.out.println(G[0]);
		} else {
			 G = new int[m - 1];
			 System.out.println(m - 1);
				
			for ( int g = leng / 2; g > 0; g /= 2, mm++) {
				G[mm] = g;
				if (mm != m - 2) {
					System.out.print(G[mm] + " ");
				} else {
					System.out.println(G[mm]);
				}
			}
		}
			
		InsertionSort (A, n, G);
	}
}



Measured memory_bytes: 299764
#include <bits/stdc++.h>
#define ll long long int
#define FASTIO std::ios::sync_with_stdio(false);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define inf 1e18
#define g(x) cout<<x<<" "<<endl;
#define gg(x,y) cout<<x<<" & "<<y<<" "<<endl
#define ggg(x,y,z) cout<<x<<" & "<<y<<" & "<<z<<" "<<endl
#define all(x) x.begin(),x.end()
#define input_from_file  freopen("input.txt", "r", stdin);
#define mod 1000000007
#define sz 200005
using namespace std;


ll dp[sz];
ll seg[4*sz];
ll h[sz];
ll a[sz];
void updt(ll qs,ll qe,ll s,ll e,ll idx,ll val)
{
  if(qs<=s&&qe>=e)
  {
    seg[idx] = val;
    return;
  }
  if(qs>e||qe<s)return;
  ll mid = (s+e)/2;
  updt(qs,qe,s,mid,2*idx+1,val);
  updt(qs,qe,mid+1,e,2*idx+2,val);
  seg[idx] = max(seg[2*idx+1],seg[idx*2+2]);
  return;

}
ll query(ll qs,ll qe,ll s,ll e,ll idx)
{
    if(s>e)return 0;
  if(qs<=s&&qe>=e)
  {
    return seg[idx];
  }

    if(qs>e||qe<s)return 0;
    ll mid = (s+e)/2;
    ll f1 = query(qs,qe,s,mid,2*idx+1);
    ll f2 = query(qs,qe,mid+1,e,2*idx+2);
    return max(f1,f2);
}

int main()
{


    FASTIO
    cin.tie(NULL);
    ll n;
    cin >> n;
    for(ll i=1;i<=n;i++)cin >> h[i];
    for(ll i=1;i<=n;i++)cin >> a[i];

    for(ll i=1;i<=n;i++)
    {
      ll hi = h[i];
      ll bst = query(1,hi-1,1,n,1);
      dp[i] = max(dp[i],bst+a[i]);
      updt(hi,hi,1,n,1,dp[i]);

    }
    ll ans = 0;
    for(ll i=1;i<=n;i++)ans = max(ans,dp[i]);cout<<ans<<endl;







return 0;
}


Measured memory_bytes: 11264
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
	string s,t;
	int i,j,f=0,k;
	cin>>s>>t;
	for(i=s.length()-1;i>=0&&f==0;i--)
	{
		if(s[i]=='?'||s[i]==t[t.length()-1])
		{
			if(t.length()==1)
			{
				s[i]=t[0];f=1;//cout<<"*"<<endl;
				break;
			}
			int sum=1;
			for(j=t.length()-2,k=i-1;j>=0;j--,k--)
			{
				if((s[k]=='?'||s[k]==t[j])&&(k<s.length()))++sum;
				else break;
			}
			if(sum==t.length())
			{
				f=1;//cout<<"**"<<endl;
				for(j=t.length()-1,k=i;j>=0;j--,k--)
					s[k]=t[j];
			}
		}
	}
	
	for(i=0;i<s.length()&&f==1;i++)
		if(s[i]=='?')s[i]='a';
	if(f==1)cout<<s<<endl;
	else cout<<"UNRESTORABLE"<<endl;
	return 0;
}

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

int func(int a, int b, int c) {
    if (a%2 or b%2 or c%2) return 0;
    if (a == b and b == c) return -1;
    return func(b/2+c/2, a/2+c/2, b/2+a/2) + 1;
}

int main() {

    int a, b, c;
    cin >> a >> b >> c;
    cout << func(a, b, c) << endl;

}


Measured memory_bytes: 256
from heapq import heapify, heappop, heappush
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
#print(A)
ans = A[0]
Q = [(-A[1],-A[0]),(-A[1],-A[0])] #一つ目が大きいほうへ入れる
heapify(Q)
for i in range(2,N):
  nxt = A[i]
  s,t = heappop(Q)
  s *= -1; t*= -1 #正に戻す
  #print(s,ans)
  ans += s
  heappush(Q,(-nxt,-s))
  heappush(Q,(-nxt,-t))
  #print(Q)
print(ans)


         
         

Measured memory_bytes: 106992
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;

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

    int d;
    cin >> d;

    vector<int> c(26);
    rep(i, 26) cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    rep(i, d) rep(j, 26) cin >> s[i][j];

    vector<int> t(d);
    // rep(i, d){
    //     cin >> t[i];
    //     --t[i];
    // }

    vector<int> last(26, 0);
    vector<pair<int, int>> sms(d);
    int total = 0;
    rep(i, d){
        int res = -1001001001;
        int mxidx = -1;
        rep(tt, 26){
            int sm = 0;
            sm += s[i][tt];
            vector<int> l = last;
            
            int minus = 0;

            rep(j, 26) ++l[j];
            l[tt] = 0;
            rep(j, 26) minus += c[j] * l[j];

            sm -= minus;
            if(sm > res){
                mxidx = tt;
                res = sm;
            }
        }
        rep(j, 26) ++last[j];
        last[mxidx] = 0;
        t[i] = mxidx;
        sms[i] = make_pair(res, i);
        total += res;
    }

    // rep(i, d) cout << t[i] << endl;

    sort(sms.begin(), sms.end());

    int res = total;
    rep(didx, d){
        if(didx > 10) break;
        int to = -1;
        rep(kidx, 26){
            vector<int> tt = t;
            tt[sms[didx].second] = kidx;

            vector<int> last(26, 0);
            int res_c = 0;
            rep(i, d){
                res_c += s[i][tt[i]];
                
                int minus = 0;

                rep(j, 26) ++last[j];
                last[tt[i]] = 0;
                rep(j, 26) minus += c[j] * last[j];

                res_c -= minus;
                
            }
            if(res_c > res){
                to = kidx;
                res = res_c;
            }
        }

        if(to != -1) t[sms[didx].second] = to;
    }

    rep(i, d) cout << t[i]+1 << endl;


    return 0;
}

Measured memory_bytes: 3708
// D - Maximum Average Sets
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using DBL = double;
#define allr(x) (x).rbegin(),(x).rend()
#define rp(i,s,e) for(ll i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)
#define MAX 50

vvl nCr(MAX+1, vl(MAX+1, 0));

void nCr_table_create(ll N){
	rp(n, 0, N+1) rp(r, 0, n+1){
		if(r==0 || n==r) nCr[n][r] = 1;
		else nCr[n][r] = nCr[n-1][r-1] + nCr[n-1][r];
	}
}

int main(){
	int N,A,B; cin>>N>>A>>B;
	vl V(N); rpz(i, N) cin>>V[i];
	sort(allr(V));

	nCr_table_create(N);

	DBL maxave = 0.0;
	rpz(i, A) maxave += V[i];
	maxave /= A;

	int n = 0, r = 0;
	rpz(i, N){
		if(V[A-1] == V[i]){
			n++;
			if(i < A) r++;
		}
	}

	ll maxcnt = 0;
	// if(r == A) rp(r, A, B+1) maxcnt += nCr[n][r];
	if(r == A) rp(r, A, min(n, B)+1) maxcnt += nCr[n][r];
	else maxcnt = nCr[n][r];

	printf("%.6f\n", maxave);
	cout<< maxcnt <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()

int main(){
  ll d,n;cin>>d>>n;

  if(d==0){
    if(n==100){
      cout<<n+1<<endl;
    }else{
      cout<<n<<endl;
    }
  }else if(d==1){
    if(n==100){
      cout<<100*(n+1)<<endl;
    }else{
      cout<<100*n<<endl;
    }
  }else{
    if(n==100){
      cout<<10000*(n+1)<<endl;
    }else{
      cout<<10000*n<<endl;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
vector<int> Z;
void z_algorithm(string str){//計算量はO(str.size())
  Z.resize(str.size());
  Z.at(0)=str.size();
  int m=1,n=0;
  while(m<(int)str.size()){
    while(m+n<(int)str.size()&&str.at(n)==str.at(m+n)){n++;}
    Z.at(m)=n;
    if(n==0){
      m++;
      continue;
    }
    int k=1;
    while(k+Z.at(k)<n){
      Z.at(m+k)=Z.at(k);
      k++;
    }
    m+=k;
    n-=k;
  }
}
int main(){
  int N,ans=0;
  string S;
  cin>>N>>S;
  for(int i=0;i<N-1;i++){
    z_algorithm(S);
    for(int j=i+1;j<N;j++){
      if(Z.at(j-i)<=(N-i)/2 && Z.at(j-i)<=j-i){ans=max(ans,Z.at(j-i));}
    }
    S.erase(S.begin());
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3700
from collections import deque

def bfs(sx, sy, gx, gy):
    dist = [[-1] * w for _ in range(h)]
    dist[sx][sy] = 0
    q = deque()
    r = deque()
    q.append([sx, sy])
    while True:
        if not q:
            while r:
                x, y = r.popleft()
                for i in range(-2, 3):
                    for j in range(-2, 3):
                        xx, yy = x + i, y + j
                        if 0 <= xx < h and 0 <= yy < w:
                            if s[xx][yy] == "." and dist[xx][yy] == -1:
                                dist[xx][yy] = dist[x][y] + 1
                                q.append([xx, yy])
        if not q:
            return dist[gx][gy]
        x, y = q.popleft()
        r.append([x, y])
        for u in v:
            xx, yy = x + u[0], y + u[1]
            if 0 <= xx < h and 0 <= yy < w:
                if s[xx][yy] == "." and dist[xx][yy] == -1:
                    dist[xx][yy] = dist[x][y]
                    q.append([xx, yy])
    return dist[gx][gy]

h, w = map(int, input().split())
ch, cw = map(int, input().split())
dh, dw = map(int, input().split())
s = [list(input()) for _ in range(h)]
v = [[1, 0], [-1, 0], [0, 1], [0, -1]]
ans = bfs(ch - 1, cw - 1, dh - 1, dw - 1)
print(ans)

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


using namespace std;

using ll   = long long;
using ii   = pair < int , int >;
using i3   = pair < int , ii >;
using li   = pair < ll , int >;
using lii  = pair <  ll,  ii >;
using vi   = vector < int >;
using vl   = vector < ll >;
using vli  = vector < li >;
using vii  = vector < ii >;
using vi3  = vector < i3 >;
using vlii = vector < lii >;

const int N = 2e5 + 5;
const ll INF = 1e17;
const double eps = 1e-12 , PI = acos(-1);

int n , m;

void solve(int cs){
    string s;
    cin >> s;

    n = s.length();

    for(int i = 0 ; i < n ; i += 2){
        if(s[i] == 'L'){
            printf("No\n");
            return;
        }
    }

    for(int i = 1 ; i < n ; i += 2){
        if(s[i] == 'R'){
            printf("No\n");
            return;
        }
    }

    printf("Yes\n");

}

main(){
    int t = 1;
    //scanf("%d" , &t);

    for(int cs = 1 ; t -- ; cs ++){
        solve(cs);
    }

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    string s;
    int n;
    double val,sum = 0;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        scanf("%lf", &val);
        cin >> s;
        if(s == "BTC") {
            val *= 380000;
        }
        sum += val;
    }
    printf("%lf",sum);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define mp make_pair
#define pb push_back
#define VI vector<int>
#define pii pair<int,int>
using namespace std;
const int MAXN = 2e5;
int F[MAXN+10];
int A[MAXN+10];
int main(){
	int n;
	scanf("%d", &n);
	LL ways = 0;
	for(int i = 0; i < n; i++){
		scanf("%d", &A[i]);
		ways += F[A[i]]++;
	}
	for(int i = 0; i < n; i++) printf("%lld\n", ways - F[A[i]] + 1);
	return 0;
}

Measured memory_bytes: 3712
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

map<int, ll> dist[101010];

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,M; cin >> N >> M;
    vector<map<int, vector<int>>> G(N);
    rep(i,M) {
        int u,v,c; cin >> u >> v >> c;
        --u; --v;
        G[u][c].emplace_back(v);
        G[v][c].emplace_back(u);
    }

    dist[0][0] = 0;
    deque<pll> deq;
    deq.emplace_back(0,0);
    while (!deq.empty()) {
        ll v,c;
        tie(v,c) = deq.front(); deq.pop_front();
        if (c) {
            for (auto nv : G[v][c]) {
                if (dist[nv].count(c) and dist[nv][c] <= dist[v][c]) continue;
                dist[nv][c] = dist[v][c];
                deq.emplace_front(nv,c);
            }
            if (dist[v].count(0) and dist[v][0] <= dist[v][c]) continue;
            dist[v][0] = dist[v][c];
            deq.emplace_front(v,0);
        } else {
            for (auto i : G[v]) {
                if (dist[v].count(i.first) and dist[v][i.first] <= dist[v][0] + 1) continue;
                dist[v][i.first] = dist[v][0] + 1;
                deq.emplace_back(v,i.first);
            }
        }
    }

    cout << (dist[N-1].count(0) ? dist[N-1][0] : -1) << ln;
}

Measured memory_bytes: 85120
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int n = sc.nextInt();
        int x = n * 800;
        int y = (n - n % 15) / 15 * 200;
    
		// 出力
		System.out.println(x - y);
	}
}

Measured memory_bytes: 23252
#include <assert.h>
#include <limits.h>
#include <stdio.h>

#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
#include <utility>

using namespace std;

typedef long long LL;

static constexpr LL LIMIT = 1000000007;

LL norm(LL v) {
  return (v + LIMIT) % LIMIT;
}

LL sq(LL v) {
  return norm(v * v);
}

int main() {
  int N, M;
  int S, T;
  cin >> N >> M >> S >> T;
  vector<vector<pair<LL, int>>> edges(N+1);
  for (int i = 0; i < M; i++) {
    int u, v, d;
    cin >> u >> v >> d;
    edges[u].emplace_back(d, v);
    edges[v].emplace_back(d, u);
  }

  vector<LL> dists(N+1);
  {
    for (LL& d : dists) d = -1;
    multimap<LL, int> q;
    q.emplace(0, S);
    while (!q.empty()) {
      auto iter = q.begin();
      LL d = iter->first;
      int v = iter->second;
      q.erase(iter);
      if (dists[v] >= 0)
        continue;

      dists[v] = d;
      for (pair<LL, int> p : edges[v]) {
        q.emplace(d + p.first, p.second);
      }
    }
  }

  vector<LL> dp1(N+1);
  {
    for (LL& d : dp1) d = 0;
    dp1[S] = 1;

    multimap<LL, int> verts;
    for (size_t i = 1; i < dists.size(); i++) {
      verts.emplace(dists[i], i);
    }

    for (pair<LL, int> p : verts) {
      LL d = p.first;
      int v = p.second;
      if (v == S)
        continue;

      LL num_paths = 0;
      for (pair<LL, int> np : edges[v]) {
        LL nd = np.first;
        int nv = np.second;
        if (dp1[nv] > 0 && d - nd == dists[nv]) {
          num_paths = norm(num_paths + dp1[nv]);
        }
      }

      dp1[v] = num_paths;
    }
  }

  vector<LL> dp2(N+1);
  {
    for (LL& d : dp2) d = 0;
    dp2[T] = 1;

    multimap<LL, int> verts;
    for (size_t i = 1; i < dists.size(); i++) {
      verts.emplace(-dists[i], i);
    }

    for (pair<LL, int> p : verts) {
      LL d = -p.first;
      int v = p.second;
      if (v == T)
        continue;

      LL num_paths = 0;
      for (pair<LL, int> np : edges[v]) {
        LL nd = np.first;
        int nv = np.second;
        if (dp2[nv] > 0 && d + nd == dists[nv]) {
          num_paths = norm(num_paths + dp2[nv]);
        }
      }

      dp2[v] = num_paths;
    }
  }

  LL ans = sq(dp1[T]);
  LL dt = dists[T];

  for (int v = 1; v <= N; v++) {
    if (dists[v] * 2 == dt) {
      LL s = norm(sq(dp1[v]) * sq(dp2[v]));
      ans = norm(ans - s);
    }
  }

  for (int v = 1; v <= N; v++) {
    for (pair<LL, int> p : edges[v]) {
      LL c = p.first;
      int u = p.second;
      LL du = dists[u];
      LL dv = dists[v];
      if (du * 2 < dt && dv * 2 > dt && du + c == dv) {
        LL s = norm(sq(dp1[u]) * sq(dp2[v]));
        ans = norm(ans - s);
      }
    }
  }

  printf("%lld\n", ans);
}


Measured memory_bytes: 21616
#include <iostream>
#include <vector>
#include <functional>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
const int INF = 1e9;

template<typename T>struct SegTree {
  private:
    using F = function<T(T,T)>;
    int n;
    vector<T> node;
    const F f;
    const T init;
  public:
    SegTree(int size, T init, const F f) : init(init), f(f) {
      n = 1;
      while (n < size) n *= 2;
      node.resize(2*n-1, init);
    }
    void update(int index, T value) {
      index = n - 1 + index;
      node[index] = value;
      while (index != 0) {
        index = (index-1) / 2;
        node[index] = f(node[2*index+1], node[2*index+2]);
      }
    }
    T query(int left, int right, int k = 0, int l = 0, int r = -1) {
      if (r < 0) r = n;
      if (r <= left || right <= l) return init;
      if (left <= l && r <= right) return node[k];
      return f(query(left, right, 2*k+1, l, (l+r)/2), query(left, right, 2*k+2, (l+r)/2, r));
    }
};

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

  int P[N];
  SegTree<int>
    T_min(N, INF, [](int a, int b){return min(a, b);}),
    T_max(N, -INF, [](int a, int b){return max(a, b);});
  rep(i, N) {
    cin >> P[i];
    T_min.update(i, P[i]); T_max.update(i, P[i]);
  }
  int count[N];
  count[0] = 0;
  rep(i, N-1) count[i+1] = count[i] + (P[i] > P[i+1]);

  int ans = 1;
  bool flag = count[K-1]>0;
  rep(i, N-K) {
    if ((flag || count[i+K] - count[i+1] > 0) &&
        (P[i] != T_min.query(i, i+K+1) || T_max.query(i, i+K+1) != P[i+K])) {
      if (count[i+K] - count[i+1] == 0)
        flag = false;
      ++ans;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5888
#include<stdio.h>

int main(void){
  int N,K;
  int a,b,i,j;
  int h,w,rh;
  long long ans=0;
  scanf("%d%d",&N,&K);

  for(b=K+1;b<=N;b++){
    h=b-K;
    w=N/b;
    rh=(N%b>=K)?(N%b-K+1):0;
    if(K==0) rh-=1;
    //printf("b=%d,ans+=%d\n",b,h*w+rh);
    ans+=(long long)h*w+rh;
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include <iostream> 
#include <algorithm> 
#include <cstring> 
#include <cstdio>
#include <vector> 
#include <queue> 
#include <cstdlib> 
#include <iomanip>
#include <cmath> 
#include <ctime> 
#include <map> 
#include <set> 
using namespace std; 
#define lowbit(x) (x&(-x)) 
#define max(x,y) (x>y?x:y) 
#define min(x,y) (x<y?x:y) 
#define MAX 100000000000000000 
#define MOD 1000000007
#define pi acos(-1.0) 
#define ei exp(1) 
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f 
#define mem(a) (memset(a,0,sizeof(a))) 
typedef long long ll;
int a[105],n;
void init()
{
    a[0]=0;
    for(int i=1;i<=100;i++)
    {
        a[i]=0;
        int k=i;
        while(k)
        {
            if(k&1) break;
            k/=2;
            a[i]++;
        }
    }
}
int main()
{
    init();
    while(scanf("%d",&n)!=EOF)
    {
        int ans,maxn=-1;
        for(int i=1;i<=n;i++)
        {
            if(maxn<a[i]) maxn=a[i],ans=i;
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
#include<string.h>
#include<vector>
#include<set>
#include<stdio.h>
#include<math.h>
//#include<algothm>
#include<queue>
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(abs(a-c)<=d)
		cout<<"Yes"<<endl;
	else if((abs(a-b)<=d) && (abs(b-c)<=d))
		cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	system("pause");
	return 0;
}	

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

void koch_curve(const int n, const pair<double, double>& begin, const pair<double, double>& end){
    if(n == 0){
        return;
    }
    // 各点の計算
    pair<double, double> p1, p2, p3;
    p1.first = (2.0 * begin.first + end.first) / 3;
    p1.second = (2.0 * begin.second + end.second) / 3;
    p3.first = (begin.first + 2.0 * end.first) / 3;
    p3.second = (begin.second + 2.0 * end.second) / 3;
    p2.first = (p3.first - p1.first) * cos(M_PI / 3) - (p3.second - p1.second) * sin(M_PI / 3) + p1.first;
    p2.second = (p3.first - p1.first) * sin(M_PI / 3) + (p3.second - p1.second) * cos(M_PI / 3) + p1.second;

    koch_curve(n - 1, begin, p1);
    cout << p1.first << " " << p1.second << endl;
    koch_curve(n - 1, p1, p2);
    cout << p2.first << " " << p2.second << endl;
    koch_curve(n - 1, p2, p3);
    cout << p3.first << " " << p3.second << endl;
    koch_curve(n - 1, p3, end);
}

int main(){

    int n;
    cin >> n;

    cout << fixed << setprecision(10);
    pair<double, double> begin = {0.0, 0.0};
    pair<double, double> end = {100.0, 0.0};

    cout << begin.first << " " << begin.second << endl;
    koch_curve(n, begin, end);
    cout << end.first << " " << end.second << endl;

    return 0;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

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


signed main() {
	ll n; cin>>n;
	map<PLL, PLL> s;
	ll p2[n+1];
	p2[0]=1LL;
	rep(i,n) p2[i+1]=p2[i]*2%MOD;
	ll zeros=0LL;
	rep(i,n){
		ll a,b; cin>>a>>b;
		if(a==0&&b==0) zeros++;
		else if(a==0){
			s[MP(0,1)].first++;
		}else if(b==0){
			s[MP(0,1)].second++;
		}else{
			ll p=abs(a), q=abs(b);
			ll g=gcd(p,q); a/=g; b/=g;
			if((a>0&&b>0)||(a<0&&b<0)){
				a=abs(a); b=abs(b);
				s[MP(a,b)].first++;
			}else{
				a=abs(a); b=abs(b);
				s[MP(b,a)].second++;
			}
		}
	}

	ll ans=1LL;
	for(auto e: s){
		ll p = p2[e.second.first]+p2[e.second.second]-1LL%MOD;
		// cerr<<e.first.first SP e.first.second SP e.second.first SP e.second.second SP p<<endl;
		ans=(ans*p)%MOD;
	}
	cout<<(ans+zeros-1+MOD)%MOD<<endl;
	return 0;
}


Measured memory_bytes: 20644
#include<stdio.h>
#include<math.h>

int main(){
  char retu[10];int tmp = 753;
  scanf("%s",retu);
  for(int i=0;i<10;i++){
    if(retu[i+2] == '\0') break;
    if(abs((retu[i]-'0')*100+(retu[i+1]-'0')*10+(retu[i+2]-'0')-753)<=tmp){
      tmp = abs((retu[i]-'0')*100+(retu[i+1]-'0')*10+(retu[i+2]-'0')-753);
    }
  }
  printf("%d",tmp);
  return 0;
}


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

int main()
{
int N;
int a[100001];
int i;
int odd;
int yon;

odd=0;
yon = 0;

scanf("%d", &N);

for(i = 1; i<=N; i++){
scanf("%d", &a[i]);
	if(a[i]%2 == 1){
	odd = odd +1;
	}
 else if(a[i]%4 == 0){
	yon = yon +1;
	}
}

if( odd <= yon || (N==odd + yon && odd == yon +1)){
printf("Yes\n");
}else
printf("No\n");


return 0;
}


Measured memory_bytes: 512
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    ans = 1000
    for i in range(n-1):
        if a[i] < a[i+1]:
            k = ans//a[i]
            ans -= k*a[i]
            ans += k*a[i+1]
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


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

int main() {
  int H, W;
  cin >> H >> W;
  
  for (int i = 0; i < W + 2; i++) {
    cout << "#";
  }
  
  cout << endl;
  
  for (int i = 0; i < H; i++) {
    string X;
    cin >> X;
    
    cout << "#" << X << "#" << endl;
  }
  
  for (int i = 0; i < W + 2; i++) {
    cout << "#";
  }
  
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

int main() {
  int n;
  string s;
  cin >> n >> s;
  if (n % 2 != 0) {
    cout << "No" << endl;
    return 0;
  } else {
    REP(i, n / 2) {
      if (s[i] != s[i + n / 2]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using ll = long long;
using P = pair<int,int>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}




int main()
{
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N+1);

    rep(i,N){
        cin >> A[i+1];
    }

    int C;
    C = A[1];
    vector<int> V;
    vector<int> deg(N+1,-1);
    V.push_back(1);
    deg[1] = 1;
    V.push_back(C);
    deg[C] = 2;
    
    int icount = 3;
    int num = 0;
    int start = 1000000;
    while(true){
        C = A[C];
        if(deg[C] != -1){
            num = icount - deg[C];
            start = deg[C] - 1;
            break;
        }
        deg[C] = icount;
        V.push_back(C);
        if(icount == N) break;
        icount++;
    }

    if(start >= K) cout << V[K] << endl;
    else{
        ll amari = (K - (ll)start)%(ll)num;
        cout << V[amari + start] << endl;
    }

    return 0;
}
//Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

Measured memory_bytes: 6672
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(void)
{
	int n;
	while (cin >> n){
		if (n == 0) break;
		n++;
		vector <int> h(n);
		for (int i = 0; i < n; i++){
			cin >> h[i];
		}

		// i が雑草だとする
		for (int i = 0; i < n; i++){
			bool flag = true;
			vector <int> nh;
			for (int j = 0; j < n; j++){
				if (i != j) nh.push_back(h[j]);
			}
			int dis = nh[1] - nh[0];
			for (int j = 0; j < nh.size()-1; j++){
				if (nh[j] + dis != nh[j+1]) flag = false;
				// cout << nh[j] << " " << nh[j+1] << endl;
			}
			if (flag){
				cout << h[i] << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1220
n = int(input())
a = list(map(int,input().split()))

cnt = 0
cnt4 = 0
for i in a:
    if i%2==1:
        cnt+=1
    if i%4==0:
        cnt4+=1
    
if n-cnt == cnt4:
    if cnt4>=n//2:
        print('Yes')
    else:
        print('No')
elif cnt4>=cnt:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 20076
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    ll x, y;
    cin >> x >> y;

    if(abs(x-y) <= 1) {
        cout << "Brown";
    }
    else {
        cout << "Alice";
    }

    cout << endl;
    return 0;
}

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

int main() {
  string S;
  cin >> S;
  
  bool app[26];
  for(int i=0;i<26;++i){
    app[i]=false;
  } 
  for(int i=0;S[i]!='\0';++i){ //'\0'はヌル文字
    app[S[i]-'a'] = true; //char(キャラ）型は実は数字として扱える。
    //つまりこれは入力されたキャラ文字をtrue判定している
  }
  for(int i=0;i<26;++i){
    if(!app[i]){
      cout << char(i + 'a') << endl;
      return 0;
    }
  }
  puts("None");
  return 0;
}


Measured memory_bytes: 512
N, Q = map(int, input().split())
s = input()
TD = [input().split() for _ in range(Q)]

def simulate(n):
    if n == -1:
        return -1
    elif n == N:
        return 1
    for t, d in TD:
        if t == s[n]:
            if d == 'L':
                n -= 1
            else:
                n += 1
        if n == -1:
            return -1
        elif n == N:
            return 1
    return 0

low = -1
high = N
# 左端を調べる
while low + 1 < high:
    mid = (low + high) // 2
    if simulate(mid) == -1:
        low = mid
    else:
        high = mid
L = low

low = -1
high = N
# 右端を調べる
while low + 1 < high:
    mid = (low + high) // 2
    if simulate(mid) == 1:
        high = mid
    else:
        low = mid
H = high

print(H-L-1)


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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100001,INF=1<<30;

int main(){
    
    int N,A,B;cin>>N>>A>>B;
    cout<<min(N*A,B)<<endl;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

#include <iostream>

#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>

#include <algorithm>

using namespace std;

long long int f(vector<long long int> v) {
	int s = 0, e = v.size() - 1;
	long long int res = 0;
	int flag = 1;
	long long int last1 = -1, last2 = -1;
	while (s <= e) {
		// cout << s << " " << e << " " << res << endl;
		if (s == 0) {
			s++;
			last1 = v[0];
			last2 = v[0];
		}
		if (s == e) {
			res += max(abs(v[s] - last1), abs(v[s] - last2));
			break;
		}
		if (flag) {
			e -= 2;
			res += abs(last1 - v[e+2]) + abs(last2 - v[e+1]);
			last2 = v[e+2];
			last1 = v[e+1];
			flag = 0;
		}
		else {
			s += 2;
			res += abs(last1 - v[s-2]) + abs(last2 - v[s-1]);
			last1 = v[s-2];
			last2 = v[s-1];
			flag = 1;
		}
	}
	return res;
}

int main() {
	int n;
	cin >> n;
	vector<long long int> v;
	for (int i = 0; i < n; i++) {
		long long int temp;
		scanf("%lld", &temp);
		v.push_back(temp);
	}
	sort(v.begin(), v.end());
	long long int res = f(v);
	// cout << res << " ";
	reverse(v.begin(), v.end());
	// cout << f(v) << " ";
	res = max(res, f(v));
	cout << res;
	return 0;
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

struct Vertex {
    vector<ll> node;
};

Vertex V[100005];
ll C[100005][3];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    REP(i, M) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        V[a].node.push_back(b);
    }
    ll S, T;
    cin >> S >> T;
    S--;
    T--;
    REP(i, N) {
        REP(j, 3) {
            C[i][j] = INF;
        }
    }

    C[S][0] = 0;
    queue<pll> q;
    q.push(pll(S, 0));
    while (!q.empty()) {
        pll t = q.front();
        q.pop();
        ll cost = t.second + 1;
        REP(i, V[t.first].node.size()) {
            ll n = V[t.first].node[i];
            if (C[n][cost % 3] <= cost)
                continue;
            C[n][cost % 3] = cost;
            q.push(pll(n, cost));
        }
    }

    if (C[T][0] == INF)
        cout << -1 << endl;
    else
        cout << C[T][0] / 3 << endl;
    return 0;
}

Measured memory_bytes: 8064
#include<stdio.h>
#define H_size 250

int main(){
    int size,i;
    int H[H_size+1];
    scanf("%d",&size);

    for(i=1;i<=size;i++)  scanf("%d",&H[i]);

    for(i=1;i<=size;i++){
        printf("node %d: key = %d, ",i,H[i]);
        if(i != 1) printf("parent key = %d, ",H[i/2]);
        if(2*i <= size) printf("left key = %d, ",H[2*i]);
        if(2*i+1 <= size) printf("right key = %d, ",H[2*i+1]);
        puts("");
    }
    return 0;
}

Measured memory_bytes: 608
n = int(input())
a = list(map(int, input().split()))
res = 1
non_increasing = True
non_decreasing = True
for i in range(1, n):
    non_decreasing &= a[i-1] <= a[i]
    non_increasing &= a[i-1] >= a[i]
    if not (non_increasing or non_decreasing):
        res += 1
        non_increasing = True
        non_decreasing = True
print(res)


Measured memory_bytes: 14224