akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i= a ; i < b ; ++i)
#define rep(i,n) fo(i,0,n)
#define pln(n) printf("%lld\n",n)
#define sll(n) scanf("%lld",&n)
#define ss(n) scanf("%s",n)
#define vi vector < int >
#define pii pair < int , int >
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define dbg3(x,y,z) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) <<" , "<< #z <<": "<<(z)<<endl; }
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<int>
#define tr(c, it) \
for(decltype(c.begin()) it = c.begin(); it!= c.end(); it++)
#define pis pair<int,string>
#define present(c, x) (c.find(x) != c.end())
#define cpresent(c, x) (find(all(c),x) != c.end())
using namespace std;
int main(){
    int n, W;
    cin >> n >> W;
    long long k[n][1000*100+1];
    memset(k, INT_MAX, sizeof(k));
    // max weight we can acheive for given value
    for(int i = 0; i < n; i++)k[i][0] = 0;
    for(int i = 0; i < n; i++){
    	long long wt, val;
    	cin >> wt >> val;
    	for(int j = 1; j <= 1000*100; j++){
    		if(i == 0){
    			if(j == val)k[i][j] = wt;
    			else k[i][j] = INT_MAX;
    			continue;
    		}
    		if(j >= val)k[i][j] = min(k[i-1][j], k[i-1][j - val] + wt);
    		else k[i][j] = k[i-1][j];
    	}
    }
    long long ans = 0;
    for(int j = 1000*100; j >= 0; j--){
    	if(k[n-1][j] <= W){
    		cout << j << endl;
    		return 0;
    	}
    }
}

Measured memory_bytes: 81800
import java.util.*;
public class Main {

	public static int mod = 1_000_000_007;
	public static long[] fac = new long[2001];
	public static long[] finv = new long[2001];
	public static long[] inv = new long[2001];
	public static void COMinit() {
		fac[0] = 1;
		fac[1] = 1;
		finv[0] = 1;
		finv[1] = 1;
		inv[1] = 1;
		for(int i = 2; i < 2001; 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;
		}
	}
	public static long combination(int n, int k){
		if(n < k) return 0;
		if(n < 0 || k < 0) return 0;
		return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
	}
	
	public static void main(String[] args) {
		COMinit();
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		for(int i = 1; i <= K; i++) {
			long ans = combination(N-K+1,i)*combination(K-1, i-1);
			ans %= mod;
			System.out.println(ans);	
		}

	}

}

Measured memory_bytes: 22356
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES




int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    int n,k;
    cin>>n>>k;
    cout<<(n-k)+1;
}

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

int main(){
    int x,y;
    while(cin>>x>>y && (x!=0 || y!=0)){
        if(x<y){
            cout << x << " " << y << endl;
        }else{
            cout << y << " " << x << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define repf(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define repfr(i, x, n) for (int i = (int)(x)-1; i >= (int)(n); i--)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
#define INF 1e9
using ll = int64_t;
#define waru 1000000007

std::int64_t gcd(std::int64_t a, std::int64_t b) {
  // a >= b && b != 0
  std::int64_t c;
  do {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb) {
  std::int64_t a = max(aa, bb);
  std::int64_t b = min(aa, bb);
  std::int64_t c;
  if (b == 0) {
    return -1;
  }
  do {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
void rle(std::vector<std::pair<char, std::int64_t>> &data, std::string str) {
  char now = str[0];
  std::int64_t count = 0;
  for (std::int64_t i = 0; i < str.size() + 1; i++) {
    if (i == str.size()) {
      data.push_back(make_pair(str[i - 1], count));
      break;
    } else if (now != str[i]) {
      data.push_back(make_pair(now, count));
      now = str[i];
      count = 0;
    }
    count++;
  }

  return;
}

void Main() {
  //自動整形防止用
  string s;
  std::cin >> s;
  string ans = s[0] + to_string(s.size() - 2) + s[s.size() - 1];
  std::cout << ans << '\n';
  return;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n,m;
    cin>>n>>m;
    cout<<n-m+1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
#define rep(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define per(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define enter cout << endl
#define siz(x) ((int)x.size())
typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi ;
typedef pair <int, int> pii ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int N = 1010 ;
const int INF = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const int MOD = 1000000007 ;
void print(int x) { cout << x << endl ; exit(0) ; }
void PRINT(string x) { cout << x << endl ; exit(0) ; }
void douout(double x){ printf("%lf\n", x + 0.0000000001) ; }
const int dx[] = {1, 0} ;
const int dy[] = {0, 1} ;

queue <pii> q ;
char s[N][N] ;
ll dp[N][N] ;
bool vis[N][N] ;
int n, m ;

signed main(){
	scanf("%d%d", &n, &m) ;
	for (int i = 1; i <= n; i++) scanf("%s", s[i] + 1) ;
	q.push(mp(1, 1)) ; dp[1][1] = 1 ; vis[1][1] = 1 ;
	while (!q.empty()) {
		pii now = q.front() ; q.pop() ;
//		vis[now.fi][now.se] = 1 ;
		for (int i = 0; i < 2; i++) {
			int tx = now.fi + dx[i], ty = now.se + dy[i] ;
			if (s[tx][ty] == '.') {
				dp[tx][ty] = (dp[tx][ty] + dp[now.fi][now.se]) % MOD ;
				if (!vis[tx][ty]) q.push(mp(tx, ty)), vis[tx][ty] = 1 ;
			}
		}
	}
	printf("%lld\n", dp[n][m]) ;
	return 0 ;
}

/*
写代码时请注意：
	1.ll？数组大小，边界？数据范围？
	2.精度？
	3.特判？
	4.至少做一些
思考提醒：
	1.最大值最小->二分？
	2.可以贪心么？不行dp可以么
	3.可以优化么
	4.维护区间用什么数据结构？
	5.统计方案是用dp？模了么？
*/


Measured memory_bytes: 10112
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
const ll MOD = 1000000007;

int main() {
	int N, K, S;
	cin >> N >> K >> S;
	if (S == 1000000000) {
		for (int i = 0;i < K;i++) {
			cout << S << " ";
		}
		for (int i = K;i < N;i++) {
			cout << 1 << " ";
		}
		cout << endl;
		return 0;
	}
	for (int i = 0;i < K;i++) {
		cout << S << " ";
	}
	for (int i = K;i < N;i++) {
		cout << 1000000000 << " ";
	}
	cout << endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=2005,K=1000000007;
int n,m,p,ans,fac[maxn],inv[maxn];
int Pow(int A,int B)
{
	int res=1;
	while (B)
	{
		if (B&1) res=(LL)res*A%K;
		A=(LL)A*A%K;
		B>>=1;
	}
	return res;
}
int C(int A,int B)
{
	return (LL)fac[A]*inv[B]%K*inv[A-B]%K;
}
int main()
{
	scanf("%d",&n);
	fac[0]=1;
	for (int i=1;i<=n;i++) fac[i]=(LL)fac[i-1]*i%K;
	inv[n]=Pow(fac[n],K-2);
	for (int i=n-1;i>=0;i--) inv[i]=(LL)inv[i+1]*(i+1)%K;
	m=n/3;
	for (int i=1;i<=m;i++)
	{
		p=n-i*3;
		ans+=C(i+p-1,p);
		if (ans>=K) ans-=K;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3796
/*
author: Apoorv Singh
*/
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
typedef vector <int> vi;
typedef pair <int, int> pii;
typedef vector <long long> vll;
typedef pair <long long, long long> pll;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define For(i, a, b) for (long long i = a; i < b; ++i)
#define Forr(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define ll long long 
#define endl "\n"
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout << name << " : " << arg1 << endl;	
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <class X>
void printarr(X arr[], int n) 
{
	for (int i = 0; i < n; ++i)
		cout << arr[i] << ' ';
	cout << endl;
}
 
template <class T, class cmp = less<T>> using ordered_set = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
 
ll modulo = 1e9 + 7;

ll fpow(ll a, ll n) 
{
	ll ans = 1;
	while (n) 
	{
		if (n&1) ans = (ans*a)%modulo;
		a = (a*a)%modulo; n = n >> 1;
	}
	return ans;
}

void solve() 
{
	string s; cin >> s;
	if (s[0] != s[1] or s[1] != s[2])
	{
		cout << "Yes" << endl;
		return;
	}	
	cout << "No" << endl;
}

int main() 
{
	fast_io();
	int t = 1;
	// cin >> t;
	while (t--) solve();
	return 0;
}

Measured memory_bytes: 256
[A, B, M]    = list(map(int, input().split()))
lst_a        = list(map(int, input().split()))
lst_b        = list(map(int, input().split()))
lst_discount = [list(map(int, input().split())) for i in range(M)]

def main(lst_a, lst_b, lst_discount):

    lst_price = [min(lst_a) + min(lst_b)]

    for discount in lst_discount:
        reizouko = lst_a[discount[0] - 1]
        renji    = lst_b[discount[1] - 1]
        lst_price.append(reizouko + renji - discount[2])
    
    return min(lst_price)


if __name__ == "__main__":

    answer = main(lst_a, lst_b, lst_discount)
    print(answer)
    

Measured memory_bytes: 42340
N = int(input())
List = [int(input()) for _ in range(N)]

List.sort()
List.reverse()
#print(List)
count = 0

for i in range(len(List)):
  if i==0:
    m = max(List)
    count += 1
    List.remove(m)
  elif m!=max(List):
    m = max(List)
    count += 1
    List.remove(m)
  else:
    List.remove(m)
    continue
    
print(count)

Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	static class Pair implements Comparable<Pair>{
		int pos;
		long val;
		Pair(int p , long v){
			pos = p;
			val = v;
		}
		@Override
		public String toString() {
			return pos+" "+val;
		}
		@Override
		public int compareTo(Pair o) {
			if(pos == o.pos){
				return Long.compare(val, o.val);
			}
			return pos - o.pos;
		}
	}
	static class VComparator implements Comparator<Pair>{
		@Override
		public int compare(Pair o1, Pair o2) {
			return Long.compare(o1.val, o2.val);
		}
	}
	static long solveNeg(List<Pair> list){
		Collections.sort(list);
		Collections.reverse(list);
		System.out.println(list);
		long S = 0;
		int N = list.size();
		PriorityQueue<Pair> pq = new PriorityQueue<Pair>(new VComparator());
		for(Pair p : list){
			if(p.pos >= N - 1){
				S += p.val;
			}
			N--;
		}
		return S;
	}
	static long solvePos(List<Pair> list){
		Collections.sort(list);
		PriorityQueue<Pair> pq = new PriorityQueue<Pair>(new VComparator());
		for(Pair p : list){
			if(p.pos < 0){
				continue;
			}
			if(p.pos >= pq.size()){
				pq.add(p);
			}else if(!pq.isEmpty()){ // p.pos < pq.size()
				Pair t = pq.peek();
				if(t.val < p.val){
					pq.poll();
					pq.add(p);
				}
			}
		}
		long ret = 0;
		while(!pq.isEmpty()){
			Pair p = pq.poll();
			ret += p.val;
		}
		return ret;
	}
	static long solve(int K[] , long L[] , long R[]){
		long H[] = new long[L.length];
		List<Pair> pos = new ArrayList<Pair>();
		List<Pair> neg = new ArrayList<Pair>();
		long X = 0;
		long Y = 0;
		for(int i = 0 ; i < H.length ; ++i){
			long h = L[i] - R[i];
			if(h >= 0){
				pos.add(new Pair(K[i] - 1, h));
				X += R[i];
			}else{
				neg.add(new Pair(H.length - K[i] - 1, - h));
				Y += L[i];
			}
		}
		long ret = X + Y + solvePos(pos);
		return ret + solvePos(neg);
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for(int cn = 1 ; cn <= T ; ++cn){
			int N = sc.nextInt();
			int K[] = new int[N];
			long L[] = new long[N];
			long R[] = new long[N];
			for(int i = 0 ; i < N ; ++i){
				K[i] = sc.nextInt();
				L[i] = sc.nextLong();
				R[i] = sc.nextLong();
			}
			long ret = solve(K , L , R);
			System.out.println(ret);
		}
	}
}


Measured memory_bytes: 64200
#include<bits/stdc++.h>
#define ll              long long int
#define nl              '\n'
using namespace std;

int main(void){

   ll t,n,a,b,mx=0,sum=0,cnt=0;
    cin>>t;
    
    vector<ll>ar,v;
    
   if(t==1) cout<<0;
   else cout<<1;
}


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

#define all(v) (v).begin(), (v).end()
#define sortv(v) sort(all(v))
#define uniqv(v) (v).erase(unique(all(v)), (v).end())
#define pb push_back
#define FI first
#define SE second
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define test 1
#define TEST if(test)

using namespace std;

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

const int MOD = 1000000007; // 998244353
const int INF = 2e9;
const ll INFLL = 1e18;
const int MAX_N = 1;

int N;
vector<int> v;
int ans =0 ;

int main(){
	cin>>N;
	for(int i=0; i<N; i++){
		int x; scanf("%d", &x);
		v.pb(x);
	}
	int cnt = 0;
	for(int i=N-1; i>=0; i--){
		if(i==N-1){
			cnt = 0;
		}else{
			if(v[i]>=v[i+1]){
				cnt++;
			}else{
				cnt = 0;
			}
		}
		ans = max(ans, cnt);
	}
	cout<<ans;
	return 0;
}


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

int N;
string S;

int solve(int k) {
  vector<int> c(26), d(26);
  rep(i, 0, k) c[S[i] - 'a']++;
  rep(i, k, N) d[S[i] - 'a']++;
  int res = 0;
  rep(i, 0, 26) if(c[i] && d[i]) res++;
  return res;
}

int main() {
  cin >> N >> S;
  int ans = 0;
  rep(i, 0, N) ans = max(ans,solve(i));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000000

int main(){
	
	int N;
	cin>>N;
	
	vector<long long> maxi(4,-Inf);
	
	rep(i,N){
		long long x,y;
		cin>>x>>y;
		
		rep(j,4){
			long long t = 0LL;
			if((j&1))t += x;
			else t -= x;
			if((j>>1)&1) t += y;
			else t -= y;
			maxi[j] = max(maxi[j],t);
		}
	}
	
	long long ans = -Inf;
	
	rep(i,4){
		ans = max(ans,maxi[i] + maxi[i^3]);
	}
	
	cout<<ans<<endl;
	
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;

  int n1, n2, n3, n4;
  n1 = N / 1000;
  n2 = N % 1000 / 100;
  n3 = N % 100 / 10;
  n4 = N % 10;

  if (n1 == n2 && n2 == n3)
    cout << "Yes" << endl;
  else if (n2 == n3 && n3 == n4)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<random>
#include<functional>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll h,w,k;
    cin>>h>>w>>k;
    char s[400][400];
    ll a[400][400];
    rep(i,400)rep(j,400) a[i][j]=0;
    ll cnt[400]={};
    rep(i,h){
        rep(j,w){
            cin>>s[i][j];
            if(s[i][j]=='#') cnt[i]++;
        }
    }
    ll now=1;
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='#'){
                a[i][j]=now;
                now++;
            }   
        }
        rep(j,w-1){
            if(a[i][j]!=0&&a[i][j+1]==0) a[i][j+1]=a[i][j];
        }
        for(ll j=w-1;j>0;j--){
            if(a[i][j]!=0&&a[i][j-1]==0) a[i][j-1]=a[i][j];
        }
    }
    rep(j,w){
        rep(i,h-1){
            if(a[i][j]!=0&&a[i+1][j]==0) a[i+1][j]=a[i][j];
        }
        for(ll i=h-1;i>0;i--){
            if(a[i][j]!=0&&a[i-1][j]==0) a[i-1][j]=a[i][j];
        }
    }
    rep(i,h){
        rep(j,w){
            cout<<a[i][j];
            if(j!=w-1) cout<<" ";
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 2176
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;
public class Program {
  public static void Main() {
    int N = ReadInt(), H = ReadInt(), W = ReadInt();
    Console.WriteLine( (N-H+1) * (N-W+1) );
  }

  private static int ReadInt() { return int.Parse(Console.ReadLine()); }
  private static double ReadDouble() { return double.Parse(Console.ReadLine()); }
  private static long ReadLong() { return long.Parse(Console.ReadLine()); }
  private static char ReadChar() { return Console.ReadLine()[0]; }
  private static string[] ReadStringArray() { return Console.ReadLine().Split(' '); }
  private static int[] ReadIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
  private static double[] ReadDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
  private static long[] ReadLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
  private static char[] ReadCharArray() { return Console.ReadLine().ToArray(); }
}


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

int n;
int A[500004];

int Merge(int lft, int mid, int rit){
  int res = 0;
  int n1 = mid - lft;
  int n2 = rit - mid;
  int L[n1 + 1], R[n2 + 1];

  for(int i = 0; i <= n1 - 1; i++){
    L[i] = A[lft + i];
  }
  for(int i = 0; i <= n2 - 1; i++){
    R[i] = A[mid + i];
  }
  L[n1] = INT_MAX;
  R[n2] = INT_MAX;

  int i = 0;
  int j = 0;
  for(int k = lft; k <= rit - 1; k++){
    res++;
    if(L[i] <= R[j]){
      A[k] = L[i];
      i = i + 1;
    }
    else{
      A[k] = R[j];
      j = j + 1;
    }
  }

  return res;
}

int MergeSort(int lft, int rit){
  int res = 0;

  if(lft + 1 < rit){
    int mid = (lft + rit) / 2;
    res += MergeSort(lft, mid);
    res += MergeSort(mid, rit);
    res += Merge(lft, mid, rit);
  }

  return res;
}

int main(){
  while(cin >> n){
    for(int i = 0; i < n; i++){
      cin >> A[i];
    }

    int ans = MergeSort(0, n);

    for(int i = 0; i < n; i++){
      if(i != 0) cout << " ";
      cout << A[i];
    }
    cout << endl;
    cout << ans << endl;
  }
}



Measured memory_bytes: 7000
using System;
 class Program
    {
        static void Main(string[] args)
        {
            //引数を読み込む
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int a = int.Parse(input[1]);
            int b = int.Parse(input[2]);
            int c = int.Parse(input[3]);
            int d = int.Parse(input[4]);
            string moji = Console.ReadLine();

            //判定する文字列を見る
            string sunuke = moji.Substring(a, c - a);
            string hunuke = moji.Substring(b, d - b);

            //判定を決める
            bool judge = false;

            // ##があるかどうかを見る
            if (sunuke.Contains("##"))
                judge = false;
            else if (hunuke.Contains("##"))
                judge = false;
            else if (c > d)
            {
                string hunukefor = moji.Substring(b - 2, d - b + 3);
                if (hunukefor.Contains("..."))
                    judge = true;
            }
            else
                judge = true;
            
            //結果を書き出す
            if (judge == true)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }

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

int main () {

    string S;
    cin >> S;

    bool comfortable = true;
    for (int i = 0; i < S.size(); i++) {
        if (i % 2 == 0) {
            if (S[i] == 'L') {
                comfortable = false;
                break;
            }
        }
        else {
            if (S[i] == 'R') {
                comfortable = false;
                break;
            }
        }
    }
    cout << ((comfortable)? "Yes" : "No") << endl;

    return 0;
}


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

using namespace std;

int main() {
int a,b,c;
cin >> a >> b >> c;
if((100*a+10*b+c)%4==0){
  cout << "YES" << endl;
}
else{
  cout << "NO" << endl;
}

  return 0;
}


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

using namespace std;
typedef long long ll;

int main()
{
	int N, C;
	scanf("%d%d", &N, &C);

	int D[30][30];
	for (int i = 0; i < C; i++)
		for (int j = 0; j < C; j++)
			scanf("%d", &D[i][j]);

	int c[500][500];
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++) {
			scanf("%d", &c[i][j]);
			c[i][j]--;
		}

	ll cost[3][30];
	for (int i = 0; i < 3; i++)
		fill(cost[i], cost[i] + C, 0);
	for (int i = 0; i < N; i++)
		for (int j = 0; j < N; j++) {
			int pos = (i + j + 2) % 3;
			for (int k = 0; k < C; k++)
				cost[pos][k] += (ll)D[c[i][j]][k];
		}

	ll res = numeric_limits<ll>::max();
	for (int i = 0; i < C; i++)
		for (int j = 0; j < C; j++) {
			if (j == i)
				continue;
			for (int k = 0; k < C; k++) {
				if (k == i || k == j)
					continue;
				res = min(res, cost[0][i] + cost[1][j] + cost[2][k]);
			}
		}

	printf("%lld\n", res);

	return 0;
}


Measured memory_bytes: 1280
#include <algorithm>
#include <array>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif


int main() {
    ios::sync_with_stdio(false);
#ifndef NEAL_DEBUG
    cin.tie(nullptr);
#endif

    int N;
    cin >> N;
    vector<int> A(N);

    for (auto &a : A)
        cin >> a;

    sort(A.begin(), A.end());
    int64_t width = 0, height = 0;

    while (A.size() >= 2 && height == 0) {
        int x = A.back();
        A.pop_back();
        int y = A.back();

        if (x == y) {
            if (width == 0)
                width = x;
            else
                height = x;

            A.pop_back();
        }
    }

    cout << width * height << '\n';
}


Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007

int main(){
  int N,M;
  cin>>N>>M;
  vector<int> possible(N,0);
  possible.at(0)=1;
  vector<int> num(N,1);
  for(int i=0;i<M;i++){
    int x,y;
    cin>>x>>y;
    x--;
    y--;
    if(num.at(x)>1){
      possible.at(y)=possible.at(x)|possible.at(y);
    }else{
      possible.at(y)=possible.at(x)|possible.at(y);
      possible.at(x)=0;
    }
    num.at(x)--;
    num.at(y)++;
  }

  int sum=0;
  for(int i=0;i<N;i++){
    sum+=possible.at(i);
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	ans := make([]string, n<<1)
	question := make([]string, n+1)
	question[0] = "?"

	another := map[string]string{
		"Blue": "Red",
		"Red":  "Blue",
	}
	output := map[string]string{
		"Blue": "B",
		"Red":  "R",
	}

	n2 := n << 1
	l := 0
	r := n
	for i := 1; i <= n; i++ {
		question[i] = fmt.Sprint(i)
	}
	prev := ask(strings.Join(question, " "), scanner, writer)

	for l < r {
		m := (l + r) >> 1
		for i := 1; i <= n; i++ {
			question[i] = fmt.Sprint(i + m)
		}
		res := ask(strings.Join(question, " "), scanner, writer)
		if res == prev {
			l = m + 1
			continue
		}
		r = m
	}
	ans[(r+n-1)%n2] = output[another[prev]]
	ans[(r-1)%n2] = output[prev]
	for i := 1; i <= n; i++ {
		question[i] = fmt.Sprint(i + r)
	}
	for i := 1; i < n; i++ {
		question[n] = fmt.Sprint((r+n-1+i)%n2 + 1)
		ans[(r+n-1+i)%n2] = output[ask(strings.Join(question, " "), scanner, writer)]
	}
	for i := 0; i < n; i++ {
		question[i+1] = fmt.Sprint((r+n+i)%n2 + 1)
	}
	for i := 0; i < n-1; i++ {
		question[n] = fmt.Sprint((r+i)%n2 + 1)
		ans[(r+i)%n2] = output[ask(strings.Join(question, " "), scanner, writer)]
	}
	fmt.Fprintf(writer, "! %s\n", strings.Join(ans, ""))
	writer.Flush()
}

func ask(s string, scanner *bufio.Scanner, writer *bufio.Writer) string {
	fmt.Fprintln(writer, s)
	writer.Flush()
	return getNextString(scanner)
}


Measured memory_bytes: 1232
N,M,Q=map(int,input().split())
L=[0 for i in range(M)]
R=[0 for i in range(M)]
p=[0 for i in range(Q)]
q=[0 for i in range(Q)]
ans=[0 for i in range(Q)]
B=[[0 for i in range(N+1)] for i in range(N+1)]
C=[[0 for i in range(N+1)] for i in range(N+1)]
D=[[0 for i in range(N+1)] for i in range(N+1)]
for i in range(M):
    L[i],R[i]=map(int,input().split())
    L[i]-=1
    R[i]-=1
for i in range(Q):
    p[i],q[i]=map(int,input().split())
    p[i]-=1
    q[i]-=1
for i in range(M):
    B[R[i]][0]+=1
    B[R[i]][L[i]+1]-=1
    B[N][0]-=1
    B[N][L[i]+1]+=1
for i in range(N+1):
    for j in range(N+1):
        if i==0:
            C[i][j]=B[i][j]
        else:
            C[i][j]=B[i][j]+C[i-1][j]
for i in range(N+1):
    for j in range(N+1):
        if j==0:
            D[i][j]=C[i][j]
        else:
            D[i][j]=C[i][j]+D[i][j-1]
for i in range(Q):
    ans[i]=D[q[i]][p[i]]

for line in ans:
    print(line)


Measured memory_bytes: 73804
#include <iostream>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;

int main()
{
	string s;
	cin >> s;
	ll n = s.size();
	vector<ll> R;
	vector<ll> L;
	vector<ll> dir;
	vector<ll> ans(n,0);
	vector<ll>::iterator pr,pl;
	int flag = 0, rtimes = 0, ltimes = 0;
	for (int i = 0; i < n; i++)
	{
		if (s[i] == 'R')
		{
			if (rtimes == 0)
			{
				if (ltimes > 0) L.push_back(ltimes);
				ltimes = 0;
			}
			rtimes++;
		}
		else
		{
			if (ltimes == 0)
			{
				if (rtimes > 0) R.push_back(rtimes);
				rtimes = 0;
			}
			ltimes++;
		}
	}
	L.push_back(ltimes);

	ll point = 0;
	pr = R.begin();
	pl = L.begin();
	while (pr != R.end())
	{
		for (ll i = point; i < point+*pr; i++)
		{
			if((i-(point+*pr))%2==0) ans[point+*pr]++;
			else ans[point + *pr-1]++;
		}
		point += *pr;
		for (ll i = point; i < point + *pl; i++)
		{
			if ((i - point) % 2 == 0) ans[point]++;
			else ans[point- 1]++;
		}
		point += *pl;
		pr++;
		pl++;
	}

	for (ll i = 0; i < ans.size(); i++) cout << ans[i]<<' ';
}

Measured memory_bytes: 2420
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>
#include <cmath>
#include <queue>

using namespace std;

int main(){
	
	double d;
	
	while(true){
		cin >> d;
		if(d < 0){
			break;
		}
		
		double step = 0.0625;
		int ans = -1;
		
		for(double loop = 0; loop < 4096; loop += 1){
			if(d == step * loop){
				ans = loop;
			}
		}
		
		if(ans == -1){
			cout << "NA" << endl;
		}else{
			int dig[12];
			for(int i = 11; i >= 0; i--){
				dig[i] = ans % 2;
				ans /= 2;
			}
			for(int i = 0; i < 8; i++){
				cout << dig[i];
			}
			cout << ".";
			for(int i = 8; i < 12; i++){
				cout << dig[i];
			}
			cout << endl;
		}
		
	}
	
	return 0;
}

Measured memory_bytes: 3144
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>

using namespace std;

using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define Rep(i, n) for (long long i = 0; i< (long long)(n); i++)
#define RRep(i,n) for (long long i = ((long long)(n)-1); i>=0; i--)

struct Edge{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w){ }
};

using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;

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

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

template <class T>
T gcd(T a, T b){
    if( b==0 ) return a;
    else return gcd(b, a%b);
}

template <class T>
T lcm(T a, T b){
    return (a*b)/gcd(a,b);
}

int INF = 1e9+7;

vector<int> dx = {-1,0,1,0};
vector<int> dy = {0,-1,0,1};

int main(){
    int H, W;
    cin >> H >> W;
    string S[400];
    for(int i=0; i<H; i++) cin >> S[i];
 
    vector<vector<bool>> visited(H,vector<bool>(W,false));

    ll ans = 0;
 
 
    for(int i=0; i<H; i++) for(int j=0; j<W; j++){
        if(visited[i][j]) continue;
        visited[i][j] = true;
        vector<ll> num(2, 0);
        queue<pair<int, int>> que;
        que.push({i, j});
 
        while(que.size()){
            auto p = que.front(); que.pop();
            int x = p.first, y = p.second;
            num[S[x][y] == '#']++;
 
            for(int k=0; k<4; k++){
                int x2 = x + dx[k];
                int y2 = y + dy[k];
                if(x2 >= 0 && x2 < H && y2 >= 0 && y2 < W && !visited[x2][y2] && S[x][y] != S[x2][y2]){
                    que.push({x2, y2});
                    visited[x2][y2] = true;
                }
            }
        }
        ans += num[0] * num[1];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int a[129]={0,1,1,0,1,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1};
int x;
int main(){
    cin>>x;
    for(int i=x;i>=1;i--)
    if(a[i]==1){cout<<i<<endl;break;}
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef pair<int,int> P;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[100000],dp[100][100];

int main(){
  cin >> s;
  t = "";
  m = 0;
  rep(i,0,s.sz){
    t += "_";
    if(s[i] == 'B'){
      if(m > 0)m--;
    }
    else{
      t[m] = s[i];
      m++;
    }
  }
  rep(i,0,m){
    if(t[i] != '_')cout << t[i];
  }
  puts("");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bitset<4000010> b;
int main(){
	long long n,p=0;
	scanf("%lld",&n);
	b[0]=1;
	long long m=n;
	while(m--){
		long long v;
		scanf("%lld",&v);
		b|=b<<v;
		p+=v;
	}
	long long ans=(1+p)/2;
	while(!b[ans])
		ans++;
	printf("%lld",ans);
}


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

int main(){
int n = 1;
while(1){
 cin >> n;
if (n == 0){
break;
}
int apoint = 0;int bpoint = 0;
int i = 1;
for(i = 1;i <= n;i++){
int a = 0;int b = 0;
cin >> a >> b;
if(a == b){
apoint = apoint + a;
bpoint = bpoint + b;
}
else if(a > b){
apoint = apoint + a + b;
}
else{
bpoint = bpoint + a + b;
}
} 
cout << apoint << " " << bpoint << endl;
}
    return 0;
}

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

using namespace std;

#define INF 1000007
#define MOD 1000000007
#define int long long int
#define maxn 100
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}

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

int mpow(int N, int P, int M) //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0)
    {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}

int counter(int x) //bit計算
{
    if (x == 0)
        return 0;
    return counter(x >> 1) + (x & 1);
}

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void)
{
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++)
    {
        if (!prime[i])
        {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i)
        {
            prime[j] = false;
        }
    }
}

bool IsPrime(int num) //素数判定
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return true;
}
vector<int> divisor(int n) //約数列挙
{
    vector<int> ret;
    for (int i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ret.push_back(i - 1);
            if (i * i != n)
            {
                ret.push_back((n / i) - 1);
            }
        }
    }
    sort(ret.begin(), ret.end());
    return (ret);
}
int max_n = 2001;
signed main()
{
    int S, W;
    cin >> S >> W;
    if (S > W)
    {
        cout << "safe" << endl;
    }
    else
    {
        cout << "unsafe" << endl;
    }
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

vector<int> graph[250000];
ll query[250000];
ll res[250000];

void dfs( int p, ll sum ){
	res[p] = sum;
	for( auto next : graph[p] )dfs( next, sum+query[next] );
}

int main(){
	int n, q; cin >> n >> q;
	for( int i = 0; i < n-1; ++i ){
		int a, b; cin >> a >> b; --a; --b;
		graph[a].push_back(b);
	}
	for( int i = 0; i < q; ++i ){
		int p; ll x; cin >> p >> x;
		query[p-1] += x;
	}
	dfs( 0, query[0] );
	for( int i = 0; i < n; ++i ) cout << res[i] << ' ';
	cout << endl;
	return 0;
}

Measured memory_bytes: 24192
from collections import Counter

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

acnt = Counter(a)
num = [0,0]
for i in acnt:
    if acnt[i] >= 4:
        num.append(i)
    if acnt[i] >= 2:
        num.append(i)
num.sort()
print(num[-1] * num[-2])


Measured memory_bytes: 18592
def solve(n):
    ret=""
    i=0 #n%2が元の何ビット目にあたるか
    while True:
        if i%2==1 and n%2==1: #奇数ビットが1のとき
            n+=2
        ret+=str(n%2)
        n//=2 #1ビット右にずらす
        i+=1
        if n==0:
            break
    return ret[-1::-1] #逆順に結合されているので反転

n=int(input())
if n==0:
    print(0)
elif n<0: #負数は左ビットシフト、一文字落として表示
    print(solve(n*(-2))[:-1])
else:
    print(solve(n))

Measured memory_bytes: 38512
#include<stdio.h>

int N, M;	//a
int a, b, c;
int i;
int sum, max;

int main()
{	
	scanf("%d %d", &N, &M);

	for (i = 0; i < M; i++) {
		scanf("%d %d", &a, &b);
		c = N - a;
		if (c>0) {
			sum += c;
		}
		if(c>=max){
			max = c;
		}
	}
	printf("%d\n", sum - max);

	return 0;
}

Measured memory_bytes: 1804
s = input()

for i in range(len(s) - 1, 0, -1):
  s2 = s[:i]
  if not len(s2) % 2 == 0:
    continue
  
  mid = int(len(s2) / 2)
  if s2[0:mid] == s2[mid:]:
    print(len(s2))
    break


Measured memory_bytes: 2940
from itertools import permutations

ABC = [input().rstrip(), input().rstrip(), input().rstrip()]

cache = [-1] * (3 * 3)


def canMatchShifted(index1, index2, shift):
    # Whether ABC[index1] can match with ABC[index2] shifted to the right by `shift`
    k = 3 * index1 + index2
    if cache[k] == -1:
        S1 = ABC[index1]
        S2 = ABC[index2]
        temp = [True] * (4001)
        for s in range(len(S1)):
            temp[s] = all(x == y or x == "?" or y == "?" for x, y in zip(S1[s:], S2))
        cache[k] = temp

    return cache[k][shift]


# Try all permutation orders of ABC
best = float("inf")
for a, b, c in permutations(range(3)):
    A = ABC[a]
    B = ABC[b]
    C = ABC[c]
    # Match A with `('?' * i) + B`
    for i in range(len(A) + 1):
        if not canMatchShifted(a, b, i):
            continue
        # Match B with `('?' * j) + C`
        # Match A with `('?' * (i + j)) + C`
        # Note that j can be longer than len(B) if B is a short string in the middle of A and C comes after A
        for j in range(2001):
            if canMatchShifted(b, c, j) and canMatchShifted(a, c, i + j):
                l = max(len(A), i + len(B), i + j + len(C))
                best = min(best, l)
print(best)


Measured memory_bytes: 57436
n,m=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(m)]

Tree=[[] for _ in range(n+1)]
for a,b in AB:
    Tree[a].append(b)
    Tree[b].append(a)

for i in range(1,n+1):
    if len(Tree[i])%2==0:continue
    else:
        print("NO")
        exit()
print("YES")

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

int main() {
  int64_t n, k;
  cin >> n >> k;
  vector<int64_t> ts(n), ds(n);
  for (int64_t i = 0; i < n; i++) {
    cin >> ts[i] >> ds[i];
    ts[i]--;
  }
  
  vector<pair<int64_t, int64_t>> vp(n);
  for (int64_t i = 0; i < n; i++) {
    vp[i] = {ds[i], ts[i]};
  }
  sort(vp.rbegin(), vp.rend());
  
  priority_queue<int64_t, vector<int64_t>, greater<>> pq;
  int64_t ret = 0, cnt = 0;
  vector<int64_t> num(n, 0);
  for (int64_t i = 0; i < k; i++) {
    ret += vp[i].first;
    if (num[vp[i].second]++) {
      pq.emplace(vp[i].first);
      continue;
    }
    cnt++;
  }
  
  int64_t ans = ret + cnt * cnt;
  
  for (int64_t i = k; i < n; i++) {
    if (num[vp[i].second]) {
      continue;
    }
    if (pq.empty()) {
      continue;
    }
    num[vp[i].second]++;
    cnt++;
    ret -= pq.top();
    pq.pop();
    ret += vp[i].first;
    ans = max(ans, ret + cnt * cnt);
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 4860
#include <iostream>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a>=b&&c>=d)
    {
        b=b+d;
        cout<<b;
    }
    else if(a<=b&&c<=d)
    {
        a=a+c;
        cout<<a;
    }
    else if(a>=b&&c<=d)
    {
        b=b+c;
        cout<<b;
    }
    else if(a<=b&&c>=d)
    {
        a=a+d;
        cout<<a;
    }
	return 0;
}

Measured memory_bytes: 3596
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	sc.Scan()
	c, _ := strconv.Atoi(sc.Text())

	d := make([][]int, c)
	for i := 0; i < c; i++ {
		d[i] = make([]int, c)
		for j := 0; j < c; j++ {
			sc.Scan()
			d[i][j], _ = strconv.Atoi(sc.Text())
		}
	}

	a := make([][]int, n)
	for i := 0; i < n; i++ {
		a[i] = make([]int, n)
		for j := 0; j < n; j++ {
			sc.Scan()
			a[i][j], _ = strconv.Atoi(sc.Text())
			a[i][j]--
		}
	}

	change := make([][]int, 3)
	for i := 0; i < 3; i++ {
		change[i] = make([]int, c)
	}
	//fmt.Println(change)
	for s := 0; s < 3; s++ {
		for color := 0; color < c; color++ {
			for i := 0; i < n; i++ {
				for j := 0; j < n; j++ {
					if (i+j)%3 != s {
						continue
					}
					change[s][color] += d[a[i][j]][color]
				}
			}
		}
	}
	//fmt.Println(change)

	ans := int(1e9)
	for c0 := 0; c0 < c; c0++ {
		for c1 := 0; c1 < c; c1++ {
			if c0 == c1 {
				continue
			}
			for c2 := 0; c2 < c; c2++ {
				if c0 == c2 || c1 == c2 {
					continue
				}
				res := change[0][c0] + change[1][c1] + change[2][c2]
				if ans > res {
					ans = res
				}
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,k;
  cin>>n>>k;
  vector<P> a(n);
  vector<int> used(n+1,0);
  priority_queue<P,vector<P>,greater<P>> cnt;
  rep(i,n) cin>>a[i].se>>a[i].fi;
  sort(begin(a),end(a),greater<P>());
  ll ans=0,kind=0;
  rep(i,k){
    ans+=a[i].fi;
    if(used[a[i].se]) cnt.push(P(a[i].fi,a[i].se));
    else kind++;
    used[a[i].se]++;
  }
  ans+=kind*kind;
  //cout<<ans<<endl;
  ll former=ans;
  FOR(i,k,n){
    if(used[a[i].se]) continue;
    if(!cnt.empty()){
      used[a[i].se]++;
      ll x=former;
      P now=cnt.top();
      cnt.pop();
      if(used[now.se]==1) continue;
      used[now.se]--;
      x-=now.fi;
      x+=a[i].fi;
      x-=kind*kind;
      x+=(kind+1)*(kind+1);
      kind++;
      //cout<<a[i].se<<' '<<a[i].fi<<' '<<x<<endl;
      ans=max(ans,x);
      former=x;
    }
    //cout<<ans<<endl;
  }
  //cout<<kind<<endl;
  cout<<ans<<endl;
}

Measured memory_bytes: 3320
#include <iostream>
#include <vector>

using namespace std;

// [0][偶数][奇数][偶数][0]
// dp[i+1][j] = i番目まで割り当てを確定し, i番目に区間jを割り当てたときの最小コスト
// dp[i+1][j] = min(dp[i][j], dp[i][j-1], ..., dp[i][0]) + cost

const int INF = 1 << 30;

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

    vector<vector<int>> dp(N + 1, vector<int>(5, INF));
    for (int j = 0; j < 5; j++) dp[0][j] = 0;

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 5; j++) {
            int mn = INF;
            int cost;
            switch (j) {
                case 0:
                case 4:
                    cost = A[i];
                    break;
                case 1:
                case 3:
                    if (A[i] == 0) cost = 2;
                    else cost = A[i] % 2 == 0 ? 0 : 1;
                    break;
                default:
                    cost = A[i] % 2 == 1 ? 0 : 1;
            }

            for (int k = j; k >= 0; k--) mn = min(mn, dp[i][k]);

            dp[i+1][j] = mn + cost;
        }
    }

    int ret = INF;
    for (int j = 0; j < 5; j++) ret = min(ret, dp[N][j]);
    cout << ret << endl;
}

Measured memory_bytes: 12032
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   int n, d;
   cin >> n >> d;
   cout << (int)ceil(n / (2.0 * d + 1.0)) << endl;
   return 0;
}


Measured memory_bytes: 256
n = int(raw_input())
mxs, minm = 0, 1000
for i in range(n):
    m, s  = map(int, raw_input().split())
    if s > mxs:
        mxs = s
        minm = m
    elif s == mxs:
        if m < minm:
            minm = m
print minm, mxs

Measured memory_bytes: 4204