akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

ll n;
vvl G(202020);
vl a(202020);
vl ans(202020);
vl dp;
ll siz = 0;

void dfs(ll u, ll p){
	ll id = inf;
	ll tmp = 0;
	if(dp.empty()){
		dp.push_back(a[u]);
	}else{
		auto itr = lower_bound(all(dp),a[u]);
		if(itr == dp.end()){
			dp.push_back(a[u]);
		}else{
			id = itr - dp.begin();
			tmp = *itr;
			*itr = a[u];
		}
	}
	ans[u] = dp.size();
	for(auto v : G[u]){
		if(v == p) continue;
		dfs(v,u);
	}
	if(id == inf) dp.pop_back();
	else dp[id] = tmp;
}


int main(){
	ll n; cin >> n;
	rep(i,n) cin >> a[i];
	rep(i,n-1){
		ll u,v; cin >> u >> v; u--; v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(0,-1);
	rep(i,n){
		cout << ans[i] << "\n";
	}
}

Measured memory_bytes: 28776
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
//codeforces289B
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
void parseArray(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cin >> A[K]; } }
ll modInverse(ll a, ll b){ return 1<a ? b - modInverse(b%a,a)*b/a : 1; }
ll gcd(ll a, ll b){ return b?gcd(b, a % b):a; }
ll lcm(ll a, ll b){ return (a*b)/gcd(a, b); }
ld dist(ll x, ll y, ll a, ll b){ return sqrt((x - a)*(x - a) + (y - b)*(y - b)); }
void debug(ll* a, ll n) { for ( int k = 0; k < n; k++ ){ cout << a[k] << " ";} cerr << "\n"; }

int main(){
	FASTIO;
	string s; cin >> s;
	ll n = s.length();
	ll r[n], l[n];
	r[0] = 0; l[n - 1] = n - 1;
	for ( int k = 1; k < n; k++ ){
		if (s[k] == 'R') r[k] = k;
		else r[k] = r[k - 1];
	}
	for ( int k = n - 2; k >= 0; k-- ){
		if (s[k] == 'L') l[k] = k;
		else l[k] = l[k + 1];
	}
	ll ans[n]; memset(ans, 0, sizeof ans);
	for ( int k = 0; k < n; k++ ){
		if (s[k] == 'R') {
			if ((l[k] - k)&1) ans[l[k] - 1]++;
			else ans[l[k]]++;
		}else {
			if ((r[k] - k)&1) ans[r[k] + 1]++;
			else ans[r[k]]++;
		}
	}
	for ( int k = 0; k < n; k++ ){ cout << ans[k] << " " ;} cout << endl;
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;

const double PI=acos(-1.0);

int A[3][3]; int N; vi b;
void input()
{
    for(int i=0;i<3;++i) for(int j=0;j<3;++j) cin>>A[i][j];
    cin>>N;
    for(int i=0;i<N;++i){
        int a; cin>>a; b.emplace_back(a);
    }
}

void solve()
{
    for(int i=0;i<N;++i){
        for(int j=0;j<3;++j){
            for(int k=0;k<3;++k){
                if(b[i]==A[j][k]) A[j][k]=0;
            }
        }
    }

    string ans="No";
    for(int i=0;i<3;++i){ 
        if(A[i][0]==0 && A[i][1]==0 && A[i][2]==0) ans="Yes";
    }
    for(int i=0;i<3;++i){ 
        if(A[0][i]==0 && A[1][i]==0 && A[2][i]==0) ans="Yes";
    }
    if(A[0][0]==0 && A[1][1]==0 && A[2][2]==0) ans="Yes";
    if(A[2][0]==0 && A[1][1]==0 && A[0][2]==0) ans="Yes";

    cout<<ans<<endl;
}

int main()
{
    cin.tie();
    ios::sync_with_stdio(false);
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3648
S=input()
T=input()
s,t=len(S),len(T)
ans=t
for i in range(s-t+1):
  d=0
  u=S[i:i+t]
  for j in range(t):
    if u[j]!=T[j]:
      d+=1
  ans=min(ans,d)
print(ans)

Measured memory_bytes: 9052
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template


int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    rep(i, N) {
        if(A[i] > i) {
            output(-1);
            return 0;
        }
    }
    rep(i, 1, N) {
        if(A[i] - A[i - 1] > 1) {
            output(-1);
            return 0;
        }
    }
    ll ans = 0;
    ll cur = 0;
    for(int i = N - 1; i >= 0; i--) {
        if(cur - 1 != A[i]) {
            ans += A[i];
        }
        cur = A[i];
    }
    output(ans);
    
    
    
    
    
    return 0;
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int h, w;
    cin >> h >> w;

    vector<vector<char>> pic(h, vector<char>(w, 0));

    for(int ih=0;ih<h;ih++) {
        for(int iw=0;iw<w;iw++) {
            cin >> pic.at(ih).at(iw);
        }
    }

    for(int ih=0;ih<h;ih++) {
        for(int iw=0;iw<w;iw++) {
            if(pic.at(ih).at(iw)=='.') continue;
            if(ih!=0) {
                if(pic.at(ih-1).at(iw)=='#') continue;
            }
            if(ih!=h-1) {
                if(pic.at(ih+1).at(iw)=='#') continue;
            }
            if(iw!=0) {
                if(pic.at(ih).at(iw-1)=='#') continue;
            }
            if(iw!=w-1) {
                if(pic.at(ih).at(iw+1)=='#') continue;
            }
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
#include<vector>
using namespace std;
typedef pair<int, int>P;
typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll MOD = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 5000100;
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)
//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; 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(ll n,ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll dx[8] = { 0,0,-1,1 };
ll dy[8] = { -1,1,0,0 };
ll dp[101010];

//long longしか使わない
//素数は1より大きい
int main() {
	ll n;
	cin >> n;
	ll ans = n * (n - 1) / 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define debugP int debug_point; cin>>debug_point;
const ll MOD= 1e9 + 7;
template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
ll pown(ll fi,ll se){
  ll ans=1;
  rep(i,se){
    ans*=fi;
  }
  return ans;
}
template <class T>
vector<T> getv(ll n){
	vector<T> Vector_temp;
	rep(i,n){
		T input;
		cin >> input;
		Vector_temp.emplace_back(input);
	}
	return Vector_temp;
}
ll gcd(ll c,ll b){
    while(1){
        if(c%b!=0){
        ll tmp=b;
        b=c%b;
        c=tmp;
        }else{
            return b;
        }
    }
}

/* <3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3<3*/


int main(){
  ll a,b;
  cin>>a>>b;
  if(a>b){
    cout<<a+a-1<<endl;
  }else if(a==b){
    op(a+b);
  }else op(b+b-1);
  return 0;
}

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

using namespace std;

long long int v[101][100003];

int main()
{
	long long int n,w,a[103],b[1002];
	scanf("%lld%lld",&n,&w);

	for(int i=1;i<=n;i++)
		scanf("%lld%lld",&a[i],&b[i]);

	for(int i =0;i<=w;i++)
	{
		v[0][i]=0;
	}

	for(int i=1;i<=n;i++)
	{
		for(int j =1;j<=w;j++)
		{
			if(j>=a[i])
				v[i][j] = max(b[i]+v[i-1][j-a[i]],v[i-1][j]);
			else
				v[i][j] = v[i-1][j];
		}

	}

	printf("%lld\n",v[n][w] );


	return 0;
}


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

main() {
	int n;
	cin>>n;
	int arr[n];
	int pos[n+1];
	for(int i=0; i<n; i++){
		cin>>arr[i];
		pos[arr[i]]=i;
	}
	set<int>s;
	int ans=0;
	
	for(int i=n; i>=1; i--){
		int position=pos[i];
		if(s.size()==0){
			s.insert(pos[i]);
			continue;
		}
		auto it=s.begin();
		int valf=(*it);
		it=s.end();
		it--;
		int vall=(*it);
		if(position<valf){
			auto it=s.begin();
			int fir=(*it);
			int las=n;
			it++;
			if(it!=s.end()){
				las=(*it);
			}
			ans+=(position+1)*(las-fir)*i;
			s.insert(position);
			continue;
		}
		if(position>vall){
			auto it=s.end();
			it--;
			int fir=(*it);
			int las=-1;
			if(it!=s.begin()){
				it--;
				las=(*it);
			}
			ans+=(n-position)*(fir-las)*i;
			s.insert(position);
			continue;
		}
		it=s.lower_bound(position);
		int afir=(*it);
		it++;
		int asec=n;
		if(it!=s.end()){
			asec=(*it);
		}
		it--;
		it--;
		int bfir=(*it);
		int bsec=-1;
		if(it!=s.begin()){
			it--;
			bsec=(*it);
		}
		s.insert(position);
		ans+=(asec-afir)*(position-bfir)*i;
		ans+=(bfir-bsec)*(afir-position)*i;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 9860
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = System.Console.ReadLine().Trim();
            string sT = System.Console.ReadLine().Trim();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            int iOut = 0;
            for (int i = 0; i < sS.Length; i++) { if (sS[i] != sT[i]) { iOut += 1; } }

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 27444
from collections import deque
# g : グラフ
# 例 [[1], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7], [6, 8], [7, 9], [8]]
# i : 始点
def bfs(g, i):
    
    #各頂点への距離
    dis = [float('Inf')] * N 
    
    #訪れたかどうか
    d = [False] * N
    #初期設定
    que = deque()
    que.append(i)
    d[i] = True
    dis[i] = 0
    
    while que:
        p = que.popleft()
        for k in g[p]:
            if d[k]:
                continue
            else:
                d[k] = True
                que.append(k)
                dis[k] = dis[p] + 1

    return dis
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]
g = [[] for _ in range(N)]
for a, b in ab:
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)
dis = bfs(g, 0)

if dis[-1] == 2:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 83152
#include <iostream>
#include <map>
#include <queue>
#include <vector>

#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define REP(i,n) FOR(i,0,n)

using namespace std;
vector <vector<int> > seamap, visit;

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

void bfs(int x, int y){
    queue <pair <int, int> > Q;
    visit[x][y] = 1;
    Q.push(pair<int,int>(x, y));
    while(!Q.empty()){
        pair<int,int> cur = Q.front();
        Q.pop();
        REP(i,8){
            nx = cur.first + dx[i];
            ny = cur.second + dy[i];
            if(seamap[nx][ny] && !visit[nx][ny]){
                visit[nx][ny] = 1;
                Q.push(pair<int,int>(nx, ny));
            }
        }
    }
}

int main(){
    int w,h;
    while(cin >> w >> h && !(w == 0 && h == 0)){
        int island = 0;
        seamap.resize(w + 2);
        REP(i,w + 2){
            seamap[i] = vector<int>(h + 2, 0);
        }
        visit = seamap;
        FOR(y,1,h + 1){
            FOR(x,1,w + 1){
                cin >> seamap[x][y];
            }
        }
       FOR(x,1,w + 1){
            FOR(y,1,h + 1){
                if(seamap[x][y] && !visit[x][y]){
                    island++;
                    bfs(x,y);
                }
            }
        }
        cout << island << endl;
    }
}

Measured memory_bytes: 1248
x1, y1, x2, y2 = map(int, input().split())

x3 = x2 - (y2 - y1)
y3 = y2 + (x2 - x1)

x4 = x1 - (y2 - y1)
y4 = y1 + (x2 - x1)

print(x3, y3, x4, y4)

Measured memory_bytes: 2940
import java.util.Scanner;
public class Main{
    public static long m(long a[], int b, int e){
        long Min = a[b];
        for(int i = b+1 ; i < e ; i++)
            Min = Math.min(Min,a[i]);
        return Min;
    }
    public static long M(long a[], int b, int e){
        long Max = a[b];
        for(int i = b+1 ; i < e ; i++)
            Max = Math.max(Max,a[i]);
        return Max;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long a[] = new long[n];
        for(int i = 0 ; i < n ; i++)
            a[i] = sc.nextLong();
        int q = sc.nextInt();
        for(int i = 0 ; i < q ; i++){
            int com = sc.nextInt();
            int b = sc.nextInt();
            int e = sc.nextInt();
            if(com == 0)
                System.out.println(m(a,b,e));
            else
                System.out.println(M(a,b,e));
        }
    }
}


Measured memory_bytes: 34484
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static Node root;
	public static final String INSERT = "insert";
	
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n =Integer.parseInt(br.readLine());
		
		for(int i = 0 ; i < n ; i++){
			String tmp = br.readLine();
			if(tmp.startsWith(INSERT)){
				insert(new Node(Integer.parseInt((tmp.substring(INSERT.length() + 1)))));
			}else if(tmp.startsWith("print")){
				print();
			}else{
				System.out.print("Error!!");
				System.exit(1);
			}
		}
		
	}
	
	private static void insert(Node node){
		if(root == null){
			root = node;
			return;
		}else{
			Node currentNode = root;
			Node parent = null;
			while(currentNode != null){
				parent = currentNode;
				if(node.id < currentNode.id){
					currentNode = currentNode.left;
				}else{
					currentNode = currentNode.right;
				}
			}
			
			node.parent = parent;
			
			if(node.id < parent.id){
				parent.left = node;
			}else{
				parent.right = node;
			}
		}
	}
	
	private static void print(){
		StringBuffer isb = new StringBuffer();
		inorderPrint(root,isb);
		isb.append("\n");
		System.out.print(isb.toString());
		StringBuffer psb = new StringBuffer();
		postorderPrint(root,psb);
		psb.append("\n");
		System.out.print(psb.toString());
	}
	
	private static void inorderPrint(Node node,StringBuffer sb){
		if(node == null){
			return;
		}
		inorderPrint(node.left,sb);
		sb.append(" ");
		sb.append(node.id);
		inorderPrint(node.right,sb);
	}
	
	private static void postorderPrint(Node node,StringBuffer sb){
		if(node == null){
			return;
		}
		sb.append(" ");
		sb.append(node.id);
		postorderPrint(node.left,sb);
		postorderPrint(node.right,sb);
	}
	
}

class Node{
	
	public Node(int id){
		this.id = id;
	}
	
	int id;
	Node parent;
	Node left;
	Node right;
}

Measured memory_bytes: 101252
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=2000010;
const ll mod=1e9+7;

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

vector<ll> inv,fact,invfact;
void mod_build(int n){  
  fact.resize(n+1); inv.resize(n+1); invfact.resize(n+1);
  fact[0]=inv[0]=invfact[0]=1; inv[1]=1;
  rep(i,n){
    fact[i+1]=fact[i]*(i+1)%mod;
    if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
    invfact[i+1]=invfact[i]*inv[i+1]%mod;
  }
}
ll perm(int n,int k){ if(n<0||k<0||k>n){ return 0; } else { return fact[n]*invfact[n-k]%mod; } }
ll comb(int n,int k){ if(n<0||k<0||k>n){ return 0; } else { return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod; }}
ll modpow(ll x,ll n){
  x%=mod; ll res=1;
  while(n>0){ if(n&1){res=res*x%mod;} x=x*x%mod; n>>=1; }
  return res;
}
ll modinv(ll a){ return modpow(a, mod-2); }

int main(){
  mod_build(mx);
  int k;
  string s;
  cin >> k >> s;
  int n = s.size();

  mint ans = 0;
  REP(i,n,k+n+1){
    mint tmp = comb(i-1,n-1);
    tmp *= modpow(25,i-n);
    tmp *= modpow(26,k+n-i);
    ans += tmp;
  }
  cout << ans.x << ln;
  return 0;
}

Measured memory_bytes: 52228
A,B,M=map(int,input().split())
a_1=list(map(int,input().split()))
b_1=list(map(int,input().split()))
L=[list(map(int,input().split())) for _ in range(M)]

count=[]
count.append(min(a_1)+min(b_1))

for k in range(M):
    count.append(a_1[L[k][0]-1]+b_1[L[k][1]-1]-L[k][2])

print(min(count))

Measured memory_bytes: 42400
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MOD 1000000007
typedef long long int ll;
void llswap(ll *x,ll *y){ll tmp;tmp=*x;*x=*y;*y=tmp;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
int rmax(int x,int y){return x>y?x:y;}
int rmin(int x,int y){return x>y?y:x;}
ll llrmax(ll x,ll y){return x>y?x:y;}
ll llrmin(ll x,ll y){return x>y?y:x;}
int asc(const void *a,const void *b){return *(int*)a-*(int*)b;}
int desc(const void *a,const void *b){return *(int*)b-*(int*)a;}

int main(){
    int n;
    char abc[3][200];

    scanf("%d",&n);
    for(int i=0;i<3;i++){
        scanf("%s",abc[i]);
    }

    int dif[200][26]={{}};

    int ans=0,flg=0;
    int cnt=0;
    for(int i=0;i<n;i++){
        flg=0;
        cnt=0;
        for(int j=0;j<2;j++){
            for(int k=j+1;k<3;k++){
                if(abc[j][i]==abc[k][i]){
                    cnt++;
                }
            }
        }

        //printf("cnt:%d\n",cnt);
        if(cnt>1){
            
        }else if(cnt==1){
            ans++;
        }else{
            ans+=2;
        }
    }

    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    delta = max(0, a[i] + a[i+1] - x)
    a[i+1] -= delta
    if a[i+1] < 0:
        a[i] += a[i+1]
        a[i+1] = 0
    ans += delta
print(ans)


Measured memory_bytes: 14252
#coding:utf-8
from copy import deepcopy
n = int(input())
A = []
for i in range(n):
    ch, num = input().split()
    A.append([ch, int(num)])

B = deepcopy(A)



def Merge(A, left, mid, right):
    L = A[left:mid]
    R = A[mid:right]
    L.append(["S",2000000000])
    R.append(["S",2000000000])
    i,j = 0,0
    for k in range(left,right):
        if L[i][1] <= R[j][1]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j += 1

def MergeSort(A, left, right):
    if left+1 < right:
        mid = (left + right)//2
        MergeSort(A, left, mid)
        MergeSort(A, mid, right)
        Merge(A, left, mid, right)

    

def partition(A, p, r):
    x = A[r-1][1]
    i = p-1
    for j in range(p, r):
        if A[j][1] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    return i


def quickSort(A, p, r):
    if p < r:
        q = partition(A, p, r)
        quickSort(A, p, q)
        quickSort(A, q+1, r)




        
quickSort(A, 0, n)
MergeSort(B, 0, n)

if A == B:
    print("Stable")
else:
    print("Not stable")
    
for a in A:
    a = " ".join([a[0],str(a[1])])
    print(a)





Measured memory_bytes: 39452
#include <iostream>

using namespace std;

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

    long long sum = 0;

    for (int i = 0; i < M; ++i) {
        int Ai;
        cin >> Ai;
        sum += Ai;
    }

    if (N < sum) {
        cout << -1 << endl;
    } else {
        cout << N - sum << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
N,M=map(int,input().split())
A=set()
for i in range(M):
    a = int(input())
    A.add(a)
d = [0] * (N+1)
for i in range(N+1):
    if i in A:
        d[i] == 0
    else:
        if i==0:
            d[i] = 1
        elif i==1:
            d[i] = 1
        else:
            d[i] = (d[i-1] + d[i-2]) % 1000000007
print(d[N])

Measured memory_bytes: 11884
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a,b,c;
  int p,q;
  char x,y,z,w;
  cin >>a>>b>>c;
  p=a.size();
  q=b.size();
  x=a.at(p-1);
  y=b.at(0);
  z=b.at(q-1);
  w=c.at(0);
  if (x==y&&z==w) {
    cout <<"YES"<<endl;
  }
  else {
    cout <<"NO"<<endl;
  }
}


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

int *read_array(int N)
{
    int *array;
    int i,m;
    array = new int[N];
    for(i=0;i<N;i++){
        scanf("%d",&m);
        array[i] = m;
    }

    return array;
}

void print_array(int *array, int N)
{
    int i;
    for(i=0;i<N;i++){
        if(i!=N-1){
            printf("%d ",array[i]);
        }else{
            printf("%d",array[i]);
        }
    }
    printf("\n");
    return;
}

int bubbleSort(int *A, int N)
{
    int flag,j,v,num;
    flag = 1;
    num = 0;
    while(flag){
        flag = 0;
        for(j=N-1;j>0;j--){
            if(A[j]<A[j-1]){
                v = A[j];
                A[j] = A[j-1];
                A[j-1] = v;
                flag = 1;
                num += 1;
            }
        }
    }
    return num;
}

int main()
{
    int *A;
    int N,num;
    scanf("%d",&N);
    A = read_array(N);
    num = bubbleSort(A,N);
    print_array(A,N);
    printf("%d\n",num);

    delete [] A;
    return 0;
}


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


void solve(long long N, std::vector<long long> A){

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

    long long ans = 0;
    for (auto it = A.begin(); it < A.end(); it++) {
        long long n = *it;
        bool b = true;
        for (long long j = 1; j * j <= n; j++) {
            if (n % j == 0) {
                if (binary_search(A.begin(), it, j)) {
                    b = false;
                    break;
                }
                if (binary_search(it + 1, A.end(), j)) {
                    b = false;
                    break;
                }
                if (binary_search(A.begin(), it, n/j)) {
                    b = false;
                    break;
                }
                if (binary_search(it + 1, A.end(), n/j)) {
                    b = false;
                    break;
                }

            }
        }
        if (b) ans++;
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 4848
#include <stdio.h>
#define NOT -1

int Bineary(int key ,int n ,int S[])
{
  int left = 0,mid,right = n;

  while(left < right)
    {
      mid = (left + right) / 2;
      if(S[mid] == key) return mid;
      else if(key < S[mid]) right = mid;
      else left = mid + 1;
    }
      return NOT;
}

 int main()
{
  int i,t = 0,n,q,S[1000000],T[1000000];;

  scanf("%d",&n);
  for(i = 0;i < n;i++) scanf("%d",&S[i]);

  scanf("%d",&q);
  for(i = 0;i < q;i++) scanf("%d",&T[i]);

  for(i = 0;i < q;i++) if(Bineary(T[i],n,S) != NOT) t++;

  printf("%d\n",t);

  return 0;
}




Measured memory_bytes: 2380
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  ll h,w;
  cin >> h >> w;
  if(h==1||w==1){
    cout << 1 << endl;
    return 0;
  }
  if(h*w%2==0){
    cout << h*w/2 << endl;
  }
  else{
    cout << (h*w+1)/2 << endl;
  }
  
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = nextInt(scanner);
        int b = nextInt(scanner);
        System.out.println(a * b);
    }

    public static int nextInt(Scanner scanner) {
        return Integer.parseInt(scanner.next());
    }

}





Measured memory_bytes: 35704
char S[101];
int n, i;
int k;
int f, l, s;
long ans;
int main(){
  scanf("%s%d", S, &k);
  n=1;
  while(S[i]){
    if(S[i]==S[i+1]){
      n++;
    }else{
      if(!f){
        f=n;
      }
      l=n;
      s+=n/2;
      n=1;
    }
    i++;
  }
  if(f==i){
    ans=((long)i)*k/2;
  }else{
    ans=((long)s)*k;
    if(S[0]==S[i-1] &&(f%2 && l%2)){
      ans+=k-1;
    }
  }
  printf("%ld\n", ans);
}

Measured memory_bytes: 128
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy

const int mxN = 2e5+10;

vi adj[mxN], vis(mxN);

int cnt = 0;

void dfs(int node) {
	vis[node] = 1;
	cnt++;
	for(auto u: adj[node]) {
		if(vis[u] == 0) {
			dfs(u);
		}
	}
}
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);  

/*#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r+", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w+", stdout);
#endif  */
	
    int N,M;
    cin >> N>>M;
    map<pi,int> store;
    vi grps(N+1);
    int ans = 0;
    for(int i=0;i<M;i++) {
    	int X,Y;
    	cin >> X >> Y;
    	if(X > Y) {
    		swap(X,Y);
    	}
    	if(store[mp(X,Y)] == 0) {
    		store[mp(X,Y)] = 1;
    		adj[X].pb(Y);
    		adj[Y].pb(X);
    	}
    }

    for(int i=1;i<=N;i++) {
    	if(vis[i] == 0) {
    		cnt = 0;
    		dfs(i);
    	}
    	ans = max(ans, cnt);
    }
    cout << ans << '\n';
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 34568
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

int main() {
    int n, l;
    cin >> n >> l;
    string s[n];
    for (int i = 0; i < n; i++) cin >> s[i];
    sort(s, s+n);
    for (int i = 0; i < n; i++) {
        cout << s[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    set<int> st;
    for(int i = 0; i < 3; i++) {
        int a;
        cin >> a;
        st.insert(a);
    }
    string ans = "No";
    if(st.size() == 2) ans = "Yes";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int n[21][21];
int b;
long long m[22][(1<<22)];
long long modz(long long x, long long y)
{
	if(x + y >= MOD)
	{
		return x+y-MOD;
	}
	return x+y;
}
long long r(int poz, int bio)
{
	if(poz == b)
	{
		return 1;
	}
	if(m[poz][bio] != -1)
	{
		return m[poz][bio];
	}
	long long u = 0;
	for(int i = 0; i < b; i++)
	{
		if(n[poz][i] == 1 && (bio&(1<<i)) == 0)
		{
			u = modz(u, r(poz+1, (bio|(1<<i))));
		}
	}
	return m[poz][bio] = u;
}
int main()
{
    cin >> b;
	for(int i = 0; i < b; i++)
	{
		for(int j = 0; j < (1<<(b+1)); j++)
		{
			m[i][j] = -1;
		}
	}
    for(int i = 0; i < b; i++)
    {
    	for(int j = 0; j < b; j++)
    	{
    		cin >> n[i][j];
		}
	}
	cout << r(0, 0) << endl;
}



Measured memory_bytes: 690560
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>


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

using namespace std;

int main()
{
    //    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());
    ll N,M,res;
    cin >> N >> M;

    ll dp[N+1];
    std::memset(dp, 0, sizeof dp);

    bool dan[N+1];
    std::memset(dan, true, sizeof dan);

    ll tmp;
    REP(i,M)
    {
        cin >> tmp;
        dan[tmp] = false;
    }

    dp[0] = 1;//1通り
    if(dan[1] == true)dp[1] = 1;//1段目が壊れてなければ1通り

    for(ll i = 2; i <= N; i++)
    {
        // i は　i-1 と　i-2　を組み合わせたもの
        //なぜdan[i]が壊れていたら、とできないのか →
        if(dan[i-1] == true)dp[i] += dp[i-1]; //i-1が壊れていたらなし
        if(dan[i-2] == true)dp[i] += dp[i-2]; //i-2が壊れていたらなし
        //else dp[i] = 0;
        dp[i] = dp[i] % 1000000007;
    }
    //1000000007
  
//    dp[N] = dp[N] % 1000000007;
    cout << dp[N] << endl;

    return 0;
}



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

int main(void) {
  string str;
  cin >> str;

  if(str[0] == '7' || str[1] == '7' || str[2] == '7'){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3632
from collections import defaultdict as dd
from pprint import pprint as pp

rs = lambda: input()
ri = lambda: int(input())
ria = lambda: list(map(int, input().split()))
rian = lambda n: [ria() for _ in range(n)]

N = ri()
s = dd(int)
for _ in range(N):
    s[rs()] += 1
M = ri()
t = dd(int)
for _ in range(M):
    t[rs()] += 1

names = set(s.keys()) | set(t.keys()) | set([None])
result = max(s[name] - t[name] for name in names)
print(result)

Measured memory_bytes: 3820
#include<stdio.h>

int main(){
  int n, i, j, lar=0, cnt, t, ans;
  
  scanf("%d", &n);

  if(n==1){
    ans=1;
  }
  
  for(i=1; i<n+1; i++){
    cnt=0;
    t=i;
    while(1){
      if(t==0) break;
      if(t%2==0){
	cnt++;
	t=t/2;
      }else{
	break;
      }
    }
    if(cnt>lar){
      ans=i;
      lar=cnt;
    }
  }

  printf("%d\n", ans);
  
  return 0;
}


Measured memory_bytes: 128
def resolve():
    #n=int(input())
    #a,b=map(int,input().split())
    #x=list(map(int,input().split()))
    #a=[list(map(lambda x:int(x)%2,input().split())) for _ in range(h)]
    import sys
    input = sys.stdin.readline
    H,W,m=map(int,input().split())
    bomb=set()
    cnt1=[0 for i in range(H)]
    cnt2=[0 for i in range(W)]
    for i in range(m):
        h,w=map(int,input().split())
        bomb.add((h-1,w-1))
        cnt1[h-1]+=1
        cnt2[w-1]+=1
    m1=max(cnt1)
    m2=max(cnt2)
    hk,wk=[],[]
    for i,x in enumerate(cnt1):
        if x==m1:
           hk.append(i)
    for i,x in enumerate(cnt2):
        if x==m2:
           wk.append(i)
    ans=m1+m2
    for i in hk:
        for j in wk:
            if (i,j) in bomb:
                continue
            print(ans)
            exit()
    print(ans-1)

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 83484
//ABC160 B

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

int X;
long long P;
int ans = 0;

int main() {
  cin >> X;
  
  int uresi1 = floor(X/500);
  int uresi2 = floor((X-uresi1*500)/5);

  ans = uresi1 * 1000 + uresi2 * 5;

  printf("%d\n",ans);

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>


#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

const int cons = 1e9 + 7;

//60D
int main(void) {
	vector<ll> w0 = vector<ll>();
	vector<ll> w1 = vector<ll>();
	vector<ll> w2 = vector<ll>();
	vector<ll> w3 = vector<ll>();
	ll n, w;
	cin >> n >> w;
	ll wf, vf;
	cin >> wf >> vf;
	w0.push_back(vf);
	rep(1, n) {
		ll wi, vi;
		cin >> wi >> vi;
		switch (wi - wf)
		{
		case 0:
			w0.push_back(vi);
			break;
		case 1:
			w1.push_back(vi);
			break;
		case 2:
			w2.push_back(vi);
			break;
		case 3:
			w3.push_back(vi);
			break;
		default:
			break;
		}
	}

	sort(w0.rbegin(), w0.rend());
	sort(w1.rbegin(), w1.rend());
	sort(w2.rbegin(), w2.rend());
	sort(w3.rbegin(), w3.rend());


	ll ans = 0;
	for (int i3 = 0; i3 <= w3.size(); i3++) {
		for (int i2 = 0; i2 <= w2.size(); i2++) {
			for (int i1 = 0; i1 <= w1.size(); i1++) {
				for (int i0 = 0; i0 <= w0.size(); i0++) {
					ll ansCo = 0;
					if (i0*wf + i1*(wf + 1) + i2*(wf + 2) + i3*(wf + 3) <= w) {
						rep(0, i0)if(i < w0.size())ansCo += w0[i];
						rep(0, i1)if (i < w1.size())ansCo += w1[i];
						rep(0, i2)if (i < w2.size())ansCo += w2[i];
						rep(0, i3)if (i < w3.size())ansCo += w3[i];
						ans = max(ans, ansCo);
					}
				}
			}
		}
	}
	cout << ans << endl;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/12  Problem: ABC 080 B / Link: http://abc080.contest.atcoder.jp/tasks/abc080_b  ----- */


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

	LL N; 
	cin >> N;
	auto f = [](LL x) {
		LL ret = 0;
		while (x) {
			ret += x % 10;
			x /= 10;
		}
		return ret;
	};

	LL ans = N%f(N);
	
	
	cout << (!ans?"Yes":"No") << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <bits/stdc++.h>
using namespace std;
/*inline int read(){
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}*/
int main()
{
    int a[6];
    for(int i=0;i<5;i++)
        cin>>a[i];
    int k,f=0;
    cin>>k;
    for(int i=0;i<5;i++)
    {
        for(int j=i+1;j<5;j++)
            if(a[j]-a[i]>k)
            {
                f=1;
                cout<<":("<<endl;
                break;
            }
        if(f==1)
            break;
    }
    if(f==0)
        cout<<"Yay!"<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
const int maxn = 1e5+10;
int n,m,tmp;
int main(){
	map<ll,ll> maps;
	cin >> n;
	ll ans = 0;
	for(ll i=1;i<=n;i++){
		scanf("%d",&tmp);
		maps[tmp+i] ++;
		if(maps.find(i-tmp)!=maps.end()){
			ans += maps[i-tmp];
		}
	}
	cout << ans << endl;
	return 0;
} 

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

int main(){
  char a,b;
  cin >> a >> b;
  if((a == 'H' && b == 'H') || a == 'D' && b == 'D'){
    cout << "H";
  }else{
    cout << "D";
  }
  cout << endl;
} 


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <list>
#include <iomanip>
#include <numeric>

using namespace std;
typedef long long ll;
ll mod = 1000000007;

template<class Type>
Type modpow(Type a, Type n, Type mod)
{
	Type res = 1;
	while (0 < n) {
		if (n & 1) {
			res = res * a % mod;
		}
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y) swap(x, y);

	while (0 < y) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
Type lcm(Type x, Type y)
{
	return x * y / gcd(x, y);
}

template<class Type>
bool is_prime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2) {
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++) {
		if (isPrime[i]) {
			Type j = i + i;
			while (j <= n) {
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binary_search_judge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binary_search(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok)) {
		int mid = (ng + ok) / 2;
		if (binary_search_judge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	int n, m;
	cin >> n >> m;
	if (n == m) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 768
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
	private static final int MOD = (int)Math.pow(10, 9);
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		String s = sc.next();
		
		int res = 0;
		
		for (int i = 1; i < s.length(); i++) {
			if (s.charAt(i) != s.charAt(i-1)) { res++; }
		}
		
		System.out.println(res);
	}
	
	private static boolean isTwoGroup(int[] w, int[] v, int ingore, int m, int n) {
		int[] groups = new int[n+1];
		for (int i = 1; i < n + 1; i++) {
			groups[i] = i;
		}
		
		for (int i = 0; i < w.length; i++) {
			if (i == ingore) { continue; }
			int pId = groups[w[i]];
			int qId = groups[v[i]];
			
			for (int j = 1; j < n + 1; j++) {
				if (groups[j] == pId) {
					groups[j] = qId;
				}
			}
		}
		
		Set<Integer> set = new HashSet<>();
		
		for (int g: groups) {
			if (g > 0) { set.add(g); }
		}
		
		return set.size() != 1;
	}
    static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}


Measured memory_bytes: 23124
#include<iostream>

using namespace std;

int main() {
    int n = 0;
    string s;
    cin >> n;
    cin >> s;
    if( n % 2 != 0 ) {
        cout << "No" << endl;
        return 0;
    }
    // 0 1 2 3 4 5  6 7
    int start = 0;
    int mid = n/2;
    while( mid < n ){
        if( s[start] != s[mid] ){
            cout << "No" << endl;
            return 0;
        }
        start++;
        mid++;
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
# 2019-11-12 15:53:47(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    a, b = (int(x) for x in sys.stdin.readline().split())
    print(a + b if b % a == 0 else b - a)



if __name__ == "__main__":
    main()


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

const int INF = (1 << 30) - 1;

int main()
{
    int N, C;
    while ( cin >> N >> C, N || C ) {
        int dp[33][(1 << 16) + 10];
        int a[33] = {};
        int b[33] = {};

        fill_n(*dp, 33 * ((1 << 16) + 10), -INF);

        dp[0][0] = 0; //turn joutai

        for ( int i = 0; i < N; i++ ) {
            for ( int j = 0; j < 16; j++ ) {
                int d;
                cin >> d;
                a[i] |= (d << j);
            }
        }

        for ( int i = 0; i < C; i++ ) {
            for ( int j = 0; j < 16; j++ ) {
                int d;
                cin >> d;
                b[i] |= (d << j);
            }
        }

        for ( int i = 0; i < N; i++ ) {
            for ( int j = 0; j < (1 << 16); j++ ) {
                if ( dp[i][j] != -INF) {
                    int val = j | a[i]; //i + 1 ターン目に光っているやつ
                    for ( int k = 0; k < C; k++ ) {
                        int valid = val & b[k];
                        int cpy = val;
                        int cnt = 0;
                        for ( int l = 0; l < 16; l++ ) {
                            if ( ((valid >> l) & 1) == 1 ) {
                                cnt++;
                                cpy &= ~(1 << l);
                            }
                        }
                        dp[i + 1][cpy] = max(dp[i + 1][cpy], dp[i][j] + cnt);
                    }
                }
            }
        }
        int maxv = 0;
        for ( int i = 0; i < (1 << 16); i++ ) {
            maxv = max(maxv, dp[N][i]);
        }
        cout << maxv << endl;
    }
    return ( 0 );
}



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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
// typedef vector<int> V;
typedef vector<double> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

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

    int N, M;
    cin >> N >> M;
    VV v(N, V(3));
    rep(i, N) cin >> v[i][0] >> v[i][1] >> v[i][2];
    VV d(N, V(N, 0));
    rep(i, N) rep(j, N) rep(k, 3) {
        d[i][j] += (v[i][k] - v[j][k]) * (v[i][k] - v[j][k]);
    }

    double mx = -1;
    rep(s, 1 << N) {
        if (__builtin_popcount(s) != M) continue;

        double sm = 0;
        rep(i, N) {
            if ((s >> i) % 2 == 0) continue;
            rep(j, i) {
                if ((s >> j) % 2 == 0) continue;
                sm += d[i][j];
            }
        }
        mx = max(mx, sm);
    }

    printf("%.10f\n", mx);

}

Measured memory_bytes: 3372
h = gets.to_i               # 単一整数

if h == 1
  puts 1
  exit
end

i = 0
loop do
  n = h / 2
  if  n <= 1
    i += 1
    break
  else
    h = n
    i += 1
  end
end

ans = 1
i.times do |c|
  ans += 2 ** (c + 1)
end

puts ans


Measured memory_bytes: 1916
import numpy as np

H, W = map(int, input().split())
b = []
for _ in range(H):
    b.append([0 if i == "#" else H+W for i in list(input())])
a = np.array(b)

for i in range(1, H):
    a[i, :] = np.minimum(a[i, :], a[i-1, :] + 1)
for i in range(H - 2, -1, -1):
    a[i, :] = np.minimum(a[i, :], a[i+1, :] + 1)
for j in range(1, W):
    a[:, j] = np.minimum(a[:,j], a[:, j-1] + 1)
for j in range(W -2, -1, - 1):
    a[:, j] = np.minimum(a[:, j], a[:, j+1] + 1)

print(np.max(a))

Measured memory_bytes: 62616