akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	int h, w, z;
	cin >> h >> w >> z;
	vector<vector<int>>grid(h, vector<int>(w));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			char x;
			cin >> x;
			if (x == '.')grid.at(i).at(j) = 0;
			else grid.at(i).at(j) = 1;
		}
	}
	ll ans = 0;
	for (int bit = 0; bit < (1 << h); bit++) {
		vector<int> l(0);
		for (int i = 0; i < h; i++) if (bit & (1 << i))l.push_back(i);
		for (int bitj = 0; bitj < (1 << w); bitj++) {
			vector<int> m(0);
			for (int j = 0; j < w; j++) if (bitj & (1 << j))m.push_back(j);
			vector<vector<int>>gridc = grid;
			for (int j = 0; j < l.size(); j++) {
				for (int k = 0; k < w; k++) gridc.at(l.at(j)).at(k) = 2;
			}
			for (int j = 0; j < m.size(); j++) {
				for (int k = 0; k < h; k++)gridc.at(k).at(m.at(j)) = 2;
			}
			ll res = 0;
			for (int j = 0; j < h; j++) {
				for (int k = 0; k < w; k++) {
					if (gridc.at(j).at(k) == 1)res++;
				}
			}
			if (res == z)ans++;
		}

	}
	cout << ans << endl;
}

Measured memory_bytes: 3604
#define _CRT_SECURE_NO_WARNINGS

//#include "stdafx.h"
#include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "map"
#include "set"
#include "list"
#include "deque"
#include "complex"
#include "bitset"
#include "cmath"
#include "unordered_set"
#include "unordered_map"
#include "iterator"
#include <ctime>
#include <cassert>
#include "numeric"
#include <cstdio>
#include "random"
#include "chrono"
#include "cstring"

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target_ans("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;

//#define f(i,n) for(int i=0; i<n;i++)
//#define rf(i, n) for(int i=n-1;i>=0;i--)
//#define forn(i, j, n) for(int i=j; i<n; i++)
//#define ff(i, j, n) f(i, n)f(j, n)
#define pb push_back
#define maxi(a,b) a = max(a, b);
#define mini(a,b) a = min(a, b);
//#define endl '\n'

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sqr(x) ((x) * (x))
#define SZ(a) ((int)(a.size()))
#define watch(x) cout << (#x) << " = " << x << endl;
//typedef long long ll;
typedef long double ld;

#define int long long
//#define int unsigned int
#define double ld
typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<pii> vpii;
typedef vector<char> vc;
typedef vector<vi> vvi;

template<class T>
void show(const vector<T> &a)
{
	for (T x : a)
		cout << x << " ";
	cout << endl;
}

vi xx = { 1, 0, -1, 0 };
vi yy = { 0, 1, 0, -1 };
string dir = "LRUD";

const int N = 2e5 + 50, oo = 5e18 + 500;
//const int mod = 998244353;
const int mod = 1e9 + 7;
//const int mod = 1e9 + 9;
const double eps = 1e-6, PI = 2 * acos(0.0);
int n, m, k;
int cnt = 0;
int lg = 18;
vi g[N];
vi rg[N];
vi visit(N, 0);

vi fact(N);

int inv(int a)
{
	int deg = mod - 2;
	int res = 1;
	while (deg)
	{
		if (deg & 1)
		{
			res = res * a % mod;
		}

		deg >>= 1;
		a = a*a % mod;
	}
	return res;
}

int C(int n, int k)
{
	return fact[n] * inv(fact[k]) % mod*inv(fact[n - k]) % mod;
}


signed main()
{
	ios::sync_with_stdio(0);
	cout.tie(0); cin.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	cin >> n >> m;
	int a, b;
	cin >> a >> b;

	fact[0] = 1;
	for (int i = 1; i <= n+m; i++)
	{
		fact[i] = fact[i - 1] * i % mod;
	}

	cnt = C(n + m - 2, n - 1);
	for (int y = n - a; y <= min(n - 1, n - a + b - 1); y++)
	{
		cnt = (cnt - C(n - a + b - 1, y)*C((n + m - 2) - (n - a + b - 1), n - 1 - y) % mod + mod) % mod;
	}

	cout << cnt << endl;
}



Measured memory_bytes: 15048
#include<bits/stdc++.h>
using namespace std;
int main(){
	int h,n;
  	cin>>h>>n;
  	int a[n];
  	for(int i=0;i<n;i++){
    	cin>>a[i];
    }
  	int sum=0;
  	for(int i=0;i<n;i++){
    	sum=sum+a[i];
    }
  	if(sum>=h){
    	cout<<"Yes"<<endl;
    }
  	else{
    	cout<<"No"<<endl;
    }

}

Measured memory_bytes: 640
def main():
    import sys
    from collections import deque
    from operator import itemgetter
    M=10**10
    b=sys.stdin.buffer
    n,d,a=map(int,b.readline().split())
    m=map(int,b.read().split())
    q=deque()
    popleft,append=q.popleft,q.append
    s=b=0
    for x,h in sorted(zip(m,m),key=itemgetter(0)):
        while q and q[0]//M<x:b-=popleft()%M
        if h>b:
            t=(b-h)//a
            s-=t
            t*=a
            b-=t
            append((x+d+d)*M-t)
    print(s)
main()

Measured memory_bytes: 56136
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

long long get_val(long long h){
	if(h==1)
		return 1ll;
	return 1ll+2ll*get_val(h/2);
}

void solve(){
	unordered_map<long long,long long> ht;
	long long h;
	long long ans=0;
	cin>>h;
	ans=get_val(h);
	cout<<ans<<"\n";
}

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

Measured memory_bytes: 256
N = int(input())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

if(N == 1):
  print(0)
else:
  result = factorization(N)
  ans = 0
  for i in range(len(result)):
    count = 1
    temp = 0
    while(result[i][1] - count >= 0):
      result[i][1] -= count
      count += 1
      temp += 1
    ans += temp
  print(ans)

Measured memory_bytes: 9508
// https://ynucpc.github.io/blog/2018/04/15/cp_vscode/
// http://www.atmarkit.co.jp/ait/articles/1509/08/news019.html

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rep3(i,n,m) for(ll i=(n);i<(ll)(m);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
// #define max(a, b) ((a) > (b) ? (a) : (b))
// #define min(a, b) ((a) < (b) ? (a) : (b)) 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
int stoi (string s, int tmp=10){
	istringstream stm(s);
	int res;
	stm >> res;
	return res;
}
double stod(string s, int tmp=10){
	istringstream stm(s);
	double res;
	stm >> res;
	return res;
}


// 配列の総和
// greater


ll dp[101][101010] = {};

int main(){	
	// ll A;
    // cin >> A;
	// cout << "hello" << endl;
	// cout << stoi("14") << endl;
	// cout << max({1,3}) << endl;
	ll N, W;
	cin >> N >> W;
	rep1(i, N){
		ll w, v;
		cin >> w >> v;
		rep1(j, W){
			dp[i][j] = dp[i-1][j];
			if (j>=w) chmax(dp[i][j], dp[i-1][j-w]+v);
		}
	}
	cout << dp[N][W] << endl;

}








Measured memory_bytes: 79104
#include<stdio.h>
int main()
{
	int A,B,C,D,P,X,Y;	
	scanf("%d",&A);
	scanf("%d",&B);
	scanf("%d",&C);
	scanf("%d",&D);
	scanf("%d",&P);
	X=A*P;
	
	if(P<=C)
	{	Y=B;
	}else{
		Y=B+(P-C)*D;
	}

	if(X<=Y){
	printf("%d\n",X);
	}else{
	printf("%d\n",Y);		
	}
	return 0;
}

Measured memory_bytes: 596
from itertools import permutations

n = int(input())
p = tuple(map(str,input().split()))
q = tuple(map(str,input().split()))
s=''
for i in range(n):
    s+=str(i+1)
l=list(permutations(s,n))

for i in range(len(l)):
    if l[i]==p:
        a=i
    if l[i]==q:
        b=i
print(abs(a-b))


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

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define All(x) (x).begin(),(x).end()
#define cAll(x) (x).cbegin(),(x).cend()
#define COL(x) cout << x << endl
#define CO(x) cout << x
#define int long long

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = INT64_MAX;
const int INF = INT_MAX;

inline int sqr(int x) { return (x * x); }
inline void printd(double x) { printf("%.10lf\n", x); }
inline void upsort(VI& x) { sort((x).begin(), (x).end()); }
inline void downsort(VI& x) { sort((x).begin(), (x).end(), greater<int>()); }
inline int absdiff(int a, int b) { return (a - b)*(1|((a - b)>>(8*sizeof(int)-1)));}
int gcd(int a, int b) { // 最大公約数
	if (a < b) return gcd(b, a);
	int r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
inline int lcm(int a, int b) { return a * b / gcd(a, b); } // 最小公倍数

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

	int pattern = 0;
	while (K <= N + 1) {
		pattern += (K * (N - K + 1) + 1) % MOD;
		K++;
	}

	pattern %= MOD;
	COL(pattern);

	return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
inline int min(int x,int y){
	return x<y?x:y;
}
const int N=2009;
bool f[N];
int sz[N],ans[N],val[N];
int he[N],to[N<<1],ne[N<<1];
char str[N];
void dfs(int x,int y){
	register int i,j,r;
	sz[x]=f[x],val[x]=ans[x]=0;
	for(i=he[x];i;i=ne[i]){
		j=to[i];
		if(j==y)continue;
		dfs(j,x),sz[x]+=sz[j];
		if(val[x]>=val[j]){
			val[x]-=val[j],r=min(val[x]>>1,ans[j]),val[x]-=r<<1,ans[x]+=val[j]+ans[j]+r;
		}else{
			val[j]-=val[x],r=min(val[j]>>1,ans[x]),val[j]-=r<<1,ans[x]+=val[x]+ans[j]+r,val[x]=val[j];
		}
	}
	val[x]+=sz[x];
}
int main(){
	register int n,i,j,k,t=0,num=0,s=1e9;
	scanf("%d%s",&n,str+1);
	for(i=1;i<=n;++i)f[i]=str[i]-48,num+=f[i];
	for(i=1;i<n;++i){
		scanf("%d%d",&j,&k);
		ne[++t]=he[j],to[t]=k,he[j]=t;
		ne[++t]=he[k],to[t]=j,he[k]=t;
	}
	for(i=1;i<=n;++i){
		dfs(i,0);
		if(val[i]==num)s=s<ans[i]?s:ans[i];
	}
	if(s>9e8)puts("-1");
	else printf("%d",s);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define fir first
#define sec second
#define mod 998244353
#define ll long long
#define int long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
#define N 200005
#define M 40
int a[M+M][M+M];
signed main()
{
	int n=read();
	for(int i=1;i<=n;i++)
	{
		double x; scanf("%lf",&x);
		ll X=x*1000000000+0.5;
		int ca=-9,cb=-9;
		while(X%2==0) ca++,X/=2;
		while(X%5==0) cb++,X/=5;
		// printf("%d %d\n",ca,cb);
		a[ca+M][cb+M]++;
	}
	int ans=0;
	for(int i=0;i<M+M;i++)
	{
		for(int j=0;j<M+M;j++)
		{
			for(int A=0;A<M+M;A++)
			{
				for(int b=0;b<M+M;b++)
				{
					if(i+A-M-M<0) continue;
					if(j+b-M-M<0) continue;
					if(i==A&&j==b) ans+=(a[i][j]-1)*a[i][j];
					else ans+=a[i][j]*a[A][b];
				}
			}
		}
	}
	cout<<ans/2<<endl;
	return 0;
}




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

int main()
{
  ll N;cin>>N;
  vector<ll> A(N+1);
  vector<ll> B(N,0);
  vector<ll> R(N+1,0);
  
  for (int i=0;i<N+1;i++)
    cin>>A[i];
  for (int i=0;i<N;i++)
    cin>>B[i];
 
  ll ans=0;
  for (int i=0;i<N;i++)
  {
    int a,b;
    a=A[i],b=B[i];
    ans += min(A[i],B[i]);
    B[i] -= min(A[i],B[i]);
    A[i] -= min(A[i],B[i]);
    ans += min(A[i+1], B[i]);
    A[i+1] -= min(A[i+1],B[i]);
  }
  cout<<ans<<endl;
} 

Measured memory_bytes: 2560
import { readFileSync } from 'fs'

const gcd = (a: number, b: number): number => b ? gcd(b, a % b) : a

function main(input: string) {
  const [n, ...numbers] = input.trim().split(/\s+/).map(Number)

  numbers.sort((a, b) => a - b)

  let current = Infinity
  let set = new Set<number>()

  for (const v of numbers) {
    set = new Set(
      Array.from(set.values()).map(value => gcd(value, v))
    )

    set.add(current)

    current = gcd(current, v)
  }

  console.log(Math.max(...Array.from(set.values())))
}

main(readFileSync('/dev/stdin', 'utf8').trim())


Measured memory_bytes: 28820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
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; }
const int INF = 1<<30;
const ll LINF = 1LL<<58;
const ll mod = 1000000007;

int main(){
    int a, b;
    cin >> a >> b;
    int n = 0;
    while(n*(a-1) + 1 < b)n++;
    cout << n << endl;
    return 0;
}

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

int main(){
    string a, b;
    cin >> a >> b;

    if(a.length() < b.length()){
        cout << "LESS" << endl;
    }else if(a.length() > b.length()){
        cout << "GREATER" << endl;
    }else{
        int i;
        for(i = 0; i < a.length(); i++){
            if(a[i] != b[i]){
                if(a[i] > b[i]) cout << "GREATER" << endl;
                else            cout << "LESS" << endl;
                break;
            }
        }

        if(i == a.length())  cout << "EQUAL" << endl;
    }

    return 0;
}

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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while (!(line = br.readLine()).equals("0")) {
			int n = Integer.parseInt(line);
			int sum, max;
			int[] num = new int[n];
			//
			for (int i = 0; i < n; i++) {
				num[i] = Integer.parseInt(br.readLine());
			}
			//
			max = Integer.MIN_VALUE;
			for (int i = 0; i < n; i++) {
				sum = 0;
				for (int j = i; j < n; j++) {
					sum += num[j];
					if (sum > max)
						max = sum;
				}
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 21936
#include <stdio.h>
#include <stdlib.h>
  
struct node{
  
int id;
struct node* parentNode;
struct node* leftChild;
struct node* rightChild;
  
};
  
struct node *createNode(int);
void insert(struct node*);
void printNodes(void);
void preOrder(struct node *);
void inOrder(struct node *);
  
struct node* nodes[500001];
struct node* root;
 
int n; 
 
main(){
  
int i, id;
char command[7];
 struct node* tmpNode;
  
scanf("%d",&n);
  
for(i=0; i<n; i++){
  
scanf("%s",command);
if(command[0]=='i'){
scanf("%d",&id);
insert(createNode(id));
}else if(command[0]=='p'){
printNodes();
}
  
}/* END OF LOOP */
 
 return 0;
  
}
 
struct node *createNode(int id){
  struct node *newNode;
  if(id<0) return NULL;
 
  newNode=(struct node*)malloc(sizeof(struct node));
  newNode->id=id;
  newNode->parentNode=NULL;
  newNode->rightChild=NULL;
  newNode->leftChild=NULL;
   
  nodes[id]=newNode;
  return newNode;
}

void insert(struct node* z){
  
  struct node* y = NULL;
  struct node* x = root;
 
  while(x != NULL){
    y = x;
    if(z->id < x->id){
      x = x->leftChild;
    }else{
      x = x->rightChild;
    }
  }
  z->parentNode = y;
  if(y == NULL){
    root = z;
  }else{
    if(z->id < y->id){
      y->leftChild = z;
    }else{
      y->rightChild = z;
    }
  }
  
}
  
void printNodes(void){
	
  inOrder(root);
  printf("\n");
  preOrder(root);
  printf("\n"); 
 
}
  
void preOrder(struct node* nd){
  printf(" %d",nd->id);
  if(nd->leftChild){
    preOrder(nd->leftChild);
  }
  if(nd->rightChild){
    preOrder(nd->rightChild);
  }
  
}
  
void inOrder(struct node* nd){
  if(nd->leftChild){
    inOrder(nd->leftChild);
  }
  printf(" %d",nd->id);
  if(nd->rightChild){
    inOrder(nd->rightChild);
  }
  
}

Measured memory_bytes: 13000
#include<bits/stdc++.h>
using namespace std;
#define de_x(x) cout<<"debug_val: "<<x<<endl;
#define de_ve(x) for(auto it: x) cout<<it<<" ";
#define rep(i,a,n) for (int i=a;i<n;i++)
#define _rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef double db;
std::mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x ; }
const ll mod=1000000007;
ll ksm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int _;
/***********************/

void run(){
}
int main(){
//	for(scanf("%d",&_); _;_--) run();	
	int n ,r;
    cin>> n >>r;

    if( n < 10 ) r  = r + (10 - n )*100;
    cout<<r<<endl; 
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(void) {
  int a, b, c;
  cin >> a >> b >> c;
  int ans=0;
  
  ans = 100*a+10*b+c;
  if (ans % 4 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int N; cin >> N;
    VI A(N);
    REP(i,N) cin >> A[i];
    int pre = A[0];
    int deg = 0;
    int ans = 1;

    FOR(i,1,N){
        dump(i)
        if(deg == 0){
            if(A[i] == A[i-1]) continue;
            if(A[i] > A[i-1]) deg = 1;
            else deg = -1;
        }else if(deg == -1){
            if(A[i] > A[i-1]){
                ans++;
                deg = 0;
            }
        }else{
            if(A[i] < A[i-1]){
                ans++;
                deg = 0;
            }
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 640
#include <stdio.h>

int main()
{
  int n,i,j,k;
  int b,f,r,v;
  int count[4][3][10];

  for (i=0;i<4;i++){
    for (j=0;j<3;j++){
      for (k=0;k<10;k++){
        count[i][j][k]=0;
      }
    }
  }
  scanf("%d",&n);

  for (i=0;i<n;i++){
    scanf("%d",&b);
    scanf("%d",&f);
    scanf("%d",&r);
    scanf("%d",&v);
    count[b-1][f-1][r-1]+=v;
  }

  for (i=0;i<4-1;i++){
    for (j=0;j<3;j++){
      for (k=0;k<10;k++){
        printf(" %d",count[i][j][k]);
      }
      printf("\n");
    }
    printf("####################\n");
  }

  for (j=0;j<3;j++){
    for (k=0;k<10;k++){
      printf(" %d",count[3][j][k]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 612
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

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

typedef long long ll;

int main()
{
    string s;
    cin>>s;
    //ll c=0,x=0;
    for(int i=0;i<3;i++)
    {
        cout<<s[i];
    }

    return 0;
}


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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

int main() {
    int N;
    string s, ans;
    cin>>N>>s;
    vector<string> init={"SS", "SW", "WS", "WW"};
    for(string i: init){
        string ans = i;
        REP(j, 1, N){
            if(s[j] == 'o'){
                if(ans[j] == 'S') ans += (ans[j-1] == 'S') ? "S" : "W";
                if(ans[j] == 'W') ans += (ans[j-1] == 'S') ? "W" : "S";   
            }else{
                if(ans[j] == 'S') ans += (ans[j-1] == 'S') ? "W" : "S";
                if(ans[j] == 'W') ans += (ans[j-1] == 'S') ? "S" : "W";   
            }
        }
        bool correct = false;
        if(s[0] == 'o'){
            if(ans[0] == 'S' && (ans[N-1] == ans[1])) correct = true;
            if(ans[0] == 'W' && (ans[N-1] != ans[1])) correct = true;
        }else{
            if(ans[0] == 'S' && (ans[N-1] != ans[1])) correct = true;
            if(ans[0] == 'W' && (ans[N-1] == ans[1])) correct = true;
        }
        if(ans[N] == ans[0] && correct){
            ans.pop_back();
            cout << ans << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3932
from collections import deque
n,m=map(int,input().split())

ab=[list(map(int,input().split())) for _ in range(m)]
ans=[0]*n
def dfs():
    deq.append(0)#1
    finish=set()
    finish.add(0)
    while deq:
        now=deq.popleft()
     #   print(now+1)
        for ad_i in adlist[now]:
            if ad_i-1 != now and ad_i-1 not in finish:
                if ans[ad_i-1]==0:
                    ans[ad_i-1]=now+1
                deq.append(ad_i-1)
                finish.add(ad_i-1)

adlist=[[] for _ in range(n)]
for j in range(m):
    x=ab[j][0]
    y=ab[j][1]
    adlist[x-1].append(y)
    adlist[y-1].append(x)
#print(adlist)
deq=deque()
dfs()
print("Yes")
for i in range(1,n):
    print(ans[i])

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

# define ll long long
ll mod=pow(10,9)+7;

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

    ll n,cnt=0,d,x,y,dist;
    cin>>n>>d;
    while(n--){
        cin>>x>>y;
        dist=x*x + y*y;
        if(dist<=d*d)
            cnt++;
    }
    cout<<cnt<<endl;
}



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

#define cc(x) cout << (x) << endl
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<long long> vll;

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

const ll inf = 1LL<<58;
const int iinf = 1<<30;

int takasa[101][101];
int t[3];

int main(){
    int n;
    cin >> n;
    vector<int> x(n), y(n), h(n);
    rep(i,n){
        cin >> x[i] >> y[i] >> h[i];
        if(h[i]>0){
            t[0]=x[i];t[1]=y[i];t[2]=h[i];
        }
    }
    int xza, yza;
    int tmp=0;

    rep(i,101){
        rep(j,101){
            takasa[i][j]=t[2]+abs(t[0]-i)+abs(t[1]-j);
            int flag=0;
            rep(k,n){
                int a = max(takasa[i][j]-abs(x[k]-i)-abs(y[k]-j),0);
                if(h[k]!=a){
                    flag=1;
                }
            }
            if(flag==0){
                xza=i;yza=j;
            }
        }
    }

    cout << xza << " " << yza << " " << takasa[xza][yza] << endl;
}


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

int main()
{
  string s;
  char c;
  int Q, t, f;
  bool inverse = false;
  cin >> s >> Q;
  deque<char> S;
  for (int i = 0; i < s.size(); i++)
  {
    S.push_back(s.at(i));
  }
  for (int i = 0; i < Q; i++)
  {
    cin >> t;
    if (t == 1)
    {
      inverse = !inverse;
    }
    else
    {
      cin >> f >> c;
      f--;
      if ((!f && !inverse) || (f && inverse))
      {
        S.push_front(c);
      }
      else
      {
        S.push_back(c);
      }
    }
  }
  if (inverse)
  {
    reverse(S.begin(), S.end());
  }
  for (char cs : S)
    cout << cs;
  cout << endl;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
ll mod = 1e9 + 7;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

ll sum (ll l, ll r) {
  return (l + r) * (r - l + 1) / 2;
}

int main() {
  int n, k;
  cin >> n >> k;

  mint ans = 0;
  for (int i = k; i <= n + 1; i++) {
    ll l = sum(0, i - 1);
    ll r = sum(n - i + 1, n);
    ans += r - l + 1;
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long a, b, k;
    cin >> a >> b >> k;
    cout << max(0LL, a - k) << " " << (a - k < 0 ? max(0LL, b + a - k) : b) << endl;
    return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
SC = []
for i in range(M):
    s,c = map(int,input().split())
    SC.append([s,c])

flag = 0
ans = -1
if N==1:
    for i in range(10):
        i = str(i)
        flag2 = 1
        for j in SC:
            s,c = j
            if i[s-1]!=str(c):
                flag2=0
        if flag2==1:
            flag=1
            ans = int(i)
            break
else:
    for i in range(10**(N-1),10**N):
        i = str(i)
        flag2 = 1
        for j in SC:
            s,c = j
            if i[s-1]!=str(c):
                flag2=0
        if flag2==1:
            flag=1
            ans = int(i)
            break
if flag==1:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 39024
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

int N, A[110];

void trace(int A[], int N) {
    for (int i = 0; i < N; i++) {
        if (i) cout << " ";
        cout << A[i];
    }
    cout << endl;
}

void bubbleSort(int A[], int N) {
    int flag = 1;
    int cnt = 0;
    while (flag) {
        flag = 0;
        for (int j = N - 1; j > 0; j--) {
            if (A[j] < A[j - 1]) {
                swap(A[j], A[j - 1]);
                flag = 1;
                cnt++;
            }
        }
    }
    trace(A, N);
    cout << cnt << endl;
}

int main() {
    cin >> N;
    REP(i, N) cin >> A[i];
    bubbleSort(A, N);
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
int x[300000];
signed main(){
	int n;
	cin>>n;
	f(i,n){
		int a;
		cin>>a;
		x[a-1]++;
	}
	sort(x,x+n);
	for(int i=1;i<=n;i++){
		int z=0,cnt=0;
		while(i*cnt<=z){
			z+=n-(lower_bound(x,x+n,cnt+1)-x);
			cnt++;
		}
		cout<<cnt-1<<endl;
	}
}


Measured memory_bytes: 3200
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <map>

using namespace std;


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

    int n;
    cin >> n;
    
    vector<double> v(n);
    double ans = 0;
    
    for(int i=0; i<n; i++) cin >> v[i];
    
    sort(v.begin(), v.end());
    
    for(int i=1; i<n; i++)
    {
        v[0] = (v[0] + v[i]) / 2;
    }
    
    
    
    printf("%.10f\n", v[0]);
    
    return 0;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    vp ans;
    if (a[0] <= 0) {
        for (int i = 1; i < n-1; ++i) {
            if (a[i] <= 0) {
                ans.eb(a[n-1], a[i]);
                a[n-1] -= a[i];
            } else {
                ans.eb(a[0], a[i]);
                a[0] -= a[i];
            }
        }
        ans.eb(a[n-1], a[0]);
        a[n-1] -= a[0]; 
    } else {
        for (int i = 1; i < n-1; ++i) {
            ans.eb(a[0], a[i]);
            a[0] -= a[i];
        }
        ans.eb(a[n-1], a[0]);
        a[n-1] -= a[0];
    }
    cout << a[n-1] << endl;
    rep(i, n-1) {
        cout << ans[i].fi << " " << ans[i].se << endl;
    }
}

Measured memory_bytes: 3188
#include <iostream>

int main()
{
    int a, b, c;
    std::cin >> a >> b >> c;

    if (c - (a - b) <= 0) { std::cout << 0 << std::endl; }
    else
    {
        std::cout << c - (a - b) << std::endl;
    }

    return 0;
}

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

int main() {
  string S;
  cin >> S;
  
  bool judge = true;
  for (int i = 0; i < S.size(); ++i) {
    if (i % 2 == 0 && S[i] == 'L') judge = false;
    if (i % 2 == 1 && S[i] == 'R') judge = false;
  }
  
  if (judge) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 998244353;
 
// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
const int biggg = 2000000000;
const long long bigggest = 1000000000000000000LL;
const double eps = .0000000001; 

int main ()
{
  prep();
  string s;
  cin >> s;
  int acnt = 0;
  for (char c : s) if (c == 'A') acnt++;
  if (acnt < 3 && acnt) cout << "Yes";
  else cout << "No";
  return 0;
}

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

using ll =long long;

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

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

int main()
{
ll N,K;
  cin>>N>>K;
  vector<int> vec(N);
  for(ll i=0;i<N;i++){
    cin>>vec[i];
  }
  sort(vec.begin(),vec.end());
  int m=vec[K-1]-vec[0];
  for(ll i=0;i<N-K+1;i++){
    m=min(m,vec[i+K-1]-vec[i]);
  }
  
  cout<<m<<endl;
    
    
    
}



Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
int main(int argc, const char * argv[]) {

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

    string s;
    cin>>s;
    int f=0,b=0;
    if(s[0]=='0'&&s[1]!='0'){
        f=1;
    }
    else if(s[0]=='1'&&(s[1]=='0'||s[1]=='1'||s[1]=='2')){
        f=1;
    }
    if(s[2]=='0'&&s[3]!='0'){
        b=1;
    }
    else if(s[2]=='1'&&(s[3]=='0'||s[2]=='1'||s[3]=='2')){
        b=1;
    }

    if(f==1&&b==1){
        cout<<"AMBIGUOUS"<<endl;
    }
    else if(f==1){
        cout<<"MMYY"<<endl;
    }
    else if(b==1){
        cout<<"YYMM"<<endl;
    }
    else{
        cout<<"NA"<<endl;
    }


    return 0;
}


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

using namespace std;
using ll = long long;

#define rep(i, a) for (int (i) = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int (i) = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int (i) = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int (i) = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif

struct uni_find_weight
{
	vector<int> par;
	vector<int> rank;
	vector<int> diff_weight;
	int sz;
	uni_find_weight(int n) {init(n);}
	void init(int n) {
		par.resize(n);
		rank.resize(n);
		diff_weight.resize(n);
		rep(i, n) par[i] = i, rank[i] = 0, diff_weight[i] = 0;
		sz = n;
	}
	int root(int x) {
		if (par[x] == x) return x;
		int r = root(par[x]);
		diff_weight[x] += diff_weight[par[x]];
		return par[x] = r;
	}
	int weight(int x) {
		root(x);
		return diff_weight[x];
	}
	int diff(int x, int y) {return weight(y) - weight(x);}
	bool same(int x, int y) {return root(x) == root(y);}
	bool unite(int x, int y, int w) {
		w += weight(x);
		w -= weight(y);
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (rank[x] < rank[y]) swap(x, y), w = -w;
		if (rank[x] == rank[y]) rank[x]++;
		par[y] = x;
		diff_weight[y] = w;
		return true;
	}
	int size() {return sz;}
};

int main()
{
	int n, q;
	cin >> n >> q;
	uni_find_weight uf(n);
	rep(i, q) {
		CIN(int, t);
		CIN(int, a);
		CIN(int, b);
		if (t == 0) {
			CIN(int, w);
			uf.unite(a, b, w);
		}
		if (t == 1) {
			if (!uf.same(a, b)) cout << '?' << endl;
			else {
				cout << uf.diff(a, b) << endl;
			}
		}
	}
}



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


const long long INF = 1LL << 60;

int main() {
    queue<INT> a;
    int state = 0,size;
    INT k,n=0;

    cin >>k;
    
    for (int i = 1;;) {
        if (i <= 9) {
            a.push(i);
            i++;
            if (i > k)break;
        }
        else {
            if (a.front() % 10 > 0) {
                a.push(a.front() * 10 + a.front() % 10 - 1);
                i++;
                if (i > k)break;
            }
            a.push(a.front() * 10 + a.front() % 10);
            i++;
            if (i > k)break;
            if (a.front() % 10 < 9) {
                a.push(a.front() * 10 + a.front() % 10 + 1);
                i++;
                if (i > k)break;
            }
            a.pop();
        }
    }

    size = a.size()-1;

    rep(h, size)a.pop();

    cout << a.front()<< endl;

    return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  while (A > 0) {
    C -= B;
    A -= D;
    if (C <= 0) {
      cout << "Yes" << endl;
      break;
    }
    else if (A <= 0) {
      cout << "No" << endl;
      break;
    }
  }
}

Measured memory_bytes: 3640
#include<stdio.h>

#include<stdlib.h>


#include<string.h>


int main(void)


{


    char num_str[1002];


    int num;


    long sum;


    int i;


    char tmp;


    sum=0;


    while(1){


             fgets(num_str,sizeof(num_str),stdin);


             if(num_str[0]=='0')break;


             for(i=0;i<strlen(num_str)-1; i++)


             {


                  tmp=num_str[i];


                  num=atoi(&tmp);


                  sum+=num;


               }


           printf("%ld\n",sum);


           sum=0;


           memset(num_str,1002,0);


 }


 return 0;


}

Measured memory_bytes: 532
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;



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

	cin >> N;
	vector<int>v(N - 1);
	for (auto &i : v)cin >> i;
	int ans = 0;
	ans += v.front() + v.back();
	for (int i = 1; i < v.size(); i++) {
		ans += min(v[i], v[i - 1]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#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;
typedef tuple<long long, long long, long long> tllint;

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

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
bool compTuple(const tllint& arg1, const tllint& arg2) { return get<2>(arg1) > get<2>(arg2); }
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 n;
    string s;
    cin >> n >> s;

    int ans = 0;
    vector<vector<int>> dp(n+1, vector<int>(n+1, 0));
    for(int in=n-1;in>=0;--in) {
        for(int jn=n-1;jn>in;--jn) {
            if(s[in]==s[jn]) chmax(dp[in][jn], dp[in+1][jn+1]+1);
            chmax(ans, min(dp[in][jn], jn-in));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 101108
#include<stdio.h>

int main(){
	int i,n,add;
	int temp=1;
	scanf("%d %d", &n,&add);
	for(i=1;i<=n;i++){
		//printf("Temp awal adalah %d\n", temp);
		if(((temp*2)<=add)&&(temp<=add)){
			temp*=2;
			//printf("Temp untuk hasil perkalian adalah %d\n", temp);
		}
		else if((temp*2>=add)&&(temp<=add)){
			temp*=2;
		}
		else{
			temp+=add;
			//printf("Temp untuk hasil penjumlahan adalah %d\n", temp);
		}
	}
	printf("%d\n", temp);
	return 0;
}

Measured memory_bytes: 1728
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] s = br.readLine().split(" ");
		int n = Integer.parseInt(s[0]);
		s = br.readLine().split(" ");
		double[] probs = new double[n + 1];
		double[][] dp = new double[n + 1][n + 1];
		for (int i = 1; i <= n; i++)
			probs[i] = Double.parseDouble(s[i - 1]);

		dp[1][0] = 1 - probs[1];
		dp[1][1] = probs[1];

		for (int i = 2; i <= n; i++)
			dp[i][0] = (1 - probs[i]) * dp[i - 1][0];

		for (int i = 2; i <= n; i++) {
			for (int j = 1; j <= i; j++) {
				dp[i][j] = (dp[i - 1][j - 1] * probs[i]) + (dp[i - 1][j] * (1 - probs[i]));

			}
		}

//		for (int j = 0; j <= n; j++) {
//			for (int i = 1; i <= n; i++)
//				System.out.printf("%.4f %-10s", dp[i][j], "");
//			System.out.println();
//		}

		double sum = 0;
		for (int i = n; i >= (n + 1) / 2; i--)
			sum += dp[n][i];

		System.out.println(sum);
	}

}


Measured memory_bytes: 131152
import heapq

n,m,s,t = map(int,input().split())
edgesYen = [[]for _ in range(n+1)]
edgesSnuuk = [[]for _ in range(n+1)]

for _ in range(m):
    u,v,a,b = map(int,input().split())
    edgesYen[u].append((v,a))
    edgesYen[v].append((u,a))
    edgesSnuuk[u].append((v,b))
    edgesSnuuk[v].append((u,b))


def dijkstra(edges,costDic,que):
    while que:
        cost,now = heapq.heappop(que)
        if now not in costDic:
            costDic[now] = cost
            for nx,c in edges[now]:
                if nx not in costDic:
                    heapq.heappush(que,(cost+c,nx))
#都市sから各都市に円で行く場合の最小コストを求める。
costYen = {}
que1 = [(0,s)]
heapq.heapify(que1)
dijkstra(edgesYen,costYen,que1)

costSnuuk = {}
que2 = [(0,t)]
heapq.heapify(que2)
dijkstra(edgesSnuuk,costSnuuk,que2)


minimumCosts = []
for i in range(1,n+1):
    cost = costYen[i] + costSnuuk[i]
    minimumCosts.append((cost,i))
heapq.heapify(minimumCosts)

money = 10**15
tmp = heapq.heappop(minimumCosts)
for i in range(n):
    while tmp[1] <= i:
        tmp = heapq.heappop(minimumCosts)
    print(money-tmp[0])


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

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ldb long double 
#define db double
#define int long long

#define fr first
#define se second
#define lb lower_bound 
#define ub upper_bound 
#define pb push_back
#define mpr make_pair

#define pi pair<int,int>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >

#define mi map<int,int>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(a,b) for (int i = (a); i < (b); ++i)
#define rrof(a,b) for (int i = (b)-1; i >= (a); --i)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int md = 1e9+7;
const int MX = 2e5+5;
const int INF = 1e18; 
const ldb PI = 4*atan((ldb)1);

int power_md(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res=(res%md*a%md)%md;
  a=(a%md*a%md)%md;
  n/=2;
}
res%=md;
return res;
}

int power(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a=a*a;
  n/=2;
}
return res;
}

int abst(int a)
{
 return ((a<0)?(-1*a):(a));
}

class cmp_set{
public:
	bool operator() (int a, int b){
		return a > b;
	}
};

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int32_t main()
{
    fast;
    int x;
    cin>>x;
    int a,b;
    int p,q;
    for(int i=1;i<=800;i++)
    {
        for(int j=-800;j<=800;j++)
        {
            a=power(i,(int)5);
            b=power(j,(int)5);
            if(a-b==x)
            {
              p=i;
              q=j;
             break;
             }
        }
        if(a-b==x)
         break;
    }
    cout<<p<<" "<<q<<"\n";
      return 0;
}

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

int main(){
    int n; cin>>n;
    string a,b,c; cin>>a>>b>>c;
    int ans=0;
    for(int i=0;i<n;++i){
        map<int,int> mp;
        ++mp[a[i]];
        ++mp[b[i]];
        ++mp[c[i]];
        int mx=0;
        for(auto &p:mp)mx=max(mx,p.second);
        ans+=3-mx;
    }
    cout<<ans<<endl;
}


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

int main(){
    int N;
    cin >> N;
    if(N <= 2){
        cout << 0 << endl;
        return 0;
    }
    vector<int> L(N+1);
    for(int i = 1; i <= N; i++){
        cin >> L[i];
    }
    int count = 0;
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N; j++){
            for(int k = 1; k <= N; k++){
                if(i == j || j == k || i == k) continue;
                if(L[i] == L[j] || L[j] == L[k] || L[i] == L[k]) continue;
//                cout << "(i, j, k) = " << i << j << k << endl;
                vector<int> edges(3);
                edges[0] = L[i]; edges[1] = L[j]; edges[2] = L[k];
                sort(edges.begin(), edges.end());
                long long longer = edges[0] + edges[1];
                if(edges[2] < longer) count++;
            }
        }
    }

    cout << count / 6 << endl;
}



Measured memory_bytes: 3624