akhauriyash/Code-Regression huggingface dataset:
from bisect import *

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

a.sort()

cn = 0

for i in range(n):
    for j in range(i+1,n):
        
        t = a[i]+a[j]
        ind = bisect_left(a, t)
        cn += len(a)-ind
        # print(cn,ind,i,j)
        
d = n*(n-1)*(n-2)//6

print(d-cn)
        


Measured memory_bytes: 42972
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
int p[110000];
int q[110000];
int segtree[262144];
int query(int a,int b,int c,int d,int e){
	if(d<a||b<c)return 0;
	if(c<=a&&b<=d)return segtree[e];
	return max(query(a,(a+b)/2,c,d,e*2),query((a+b)/2+1,b,c,d,e*2+1));
}
void update(int a,int b){
	a+=131072;
	while(a){
		segtree[a]=max(segtree[a],b);
		a/=2;
	}
}
pair<int,int>t[110000];
int z[110000];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++){
		scanf("%d%d",p+i,q+i);
		z[i]=p[i]+q[i];
		t[i]=make_pair(p[i]-q[i],p[i]+q[i]);
	}
	std::sort(z,z+a);
	std::sort(t,t+a);
	int ret=0;
	for(int i=0;i<a;i++){
		int L=t[i].first;
		int T=upper_bound(z,z+a,L)-z-1;
		int tmp=1;
		if(T>=0)tmp=query(0,131071,0,T,1)+1;
		ret=max(ret,tmp);
		update(lower_bound(z,z+a,t[i].second)-z,tmp);
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=205,p=998244353,inf=0x3f3f3f3f;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int n,m,f[N][N];
char ch[N][N];
int main(){
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	n=read();m=read();
	for (int i=1;i<=n;i++)
	scanf(" %s",ch[i]+1);
	memset(f,0x3f,sizeof(f));
	f[1][1]=(ch[1][1]=='#');
	for (int i=1;i<=n;i++)
	for (int j=1+(i==1);j<=m;j++){
		if (ch[i][j]=='.') f[i][j]=min(f[i][j-1],f[i-1][j]);
		else f[i][j]=min(f[i][j-1]+(ch[i][j-1]=='.'),f[i-1][j]+(ch[i-1][j]=='.'));
	}
	printf("%d\n",f[n][m]);
	return 0;
}


Measured memory_bytes: 1020
#define _USE_MATH_DEFINES

#include <iostream>	//cin, cout
#include <vector>	//vector
#include <algorithm> //sort,min,max,count
#include <string>	//string,getline
#include <ios>		//fixed
#include <iomanip>	//setprecision
#include <utility> //swap
#include <cstdlib>	//abs(int)
#include <cmath>	//sqrt
#include <sstream>	//stringstream,getline
#include <cmath>	//ceil,M_PI
#include <numeric>	//gcd

using namespace std;

int main() {

	string S, T;
	cin >> S >> T;

	string ans = T + S;
	cout << ans << endl;
	
	return 0;

}

Measured memory_bytes: 3564
import java.util.ArrayDeque;
import java.lang.reflect.Array;
import java.util.Arrays;

import sun.tools.jar.resources.jar;

import java.util.*;

public class Main {

  public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextInt();
    long a = N / 500;
    N %= 500;
    long b = N / 5;
    System.out.println(1000 * a + (5 * b));
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)

using namespace std;


int32_t main(){IOS;
	int n ; cin >> n ; 
	stack<int>st;
	int arr[n] ; 
	for(int i=0;i<n;i++){
		st.push(n-i);
		cin >> arr[i];
	}
	for(int i = 0 ;i < n;i++){
		if(arr[i] == st.top() ){
			st.pop();
		}
		if(st.empty()) break;
	}
	
	if((int)st.size() != n) cout << st.size() << endl;
	else cout << -1 << endl; 
	 
	return 0;
}


Measured memory_bytes: 3456
//https://atcoder.jp/contests/abc153/tasks/abc153_a
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
int main() {
    ll H,A; cin>>H>>A;
    ll ans=(H+A-1)/A;
    cout<<ans<<endl;

    return 0;
}

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

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  int n;
  cin >> n;

  string s;
  cin >> s;

  int q;
  cin >> q;

  while (q--) {
    int k;
    cin >> k;
    ll ans = 0;
    ll sum = 0;
    ll delta = 0;
    queue<pair<int, int>> q;
    for (int i = 0; i < n; ++i) {
      auto c = s[i];
      if (c == 'D') {
        sum += delta;
        q.emplace(i, delta);
      } else if (c == 'M') {
        ++delta;
      } else if (c == 'C') {
        while (q.size() && i - q.front().first >= k) {
          sum -= q.front().second;
          q.pop();
        }
        ans += delta * q.size() - sum;
      } else {
      }
    }
    cout << ans << "\n";
  }
}

Measured memory_bytes: 9488
#include<bits/stdc++.h>
using namespace std;
int dp[1000001];
int ans(int a[] , int n)
{
    if(n==0||n==1)
     return 0;
    if(n==2) return abs(a[n-1]-a[n-2]);
    
    if(dp[n-1]!=-1)
     return dp[n-1];
     
    int x= abs(a[n-1]-a[n-2])+ans(a,n-1);
    int y= abs(a[n-1]-a[n-3])+ans(a,n-2);
    dp[n-1]=min(x,y);
    return dp[n-1];
    
}
int main()
{
   int n,i;
   cin>>n;
   int a[n];
    memset(dp, -1, sizeof dp); 
   for(i=0;i<n;i++)
    cin>>a[i];
   cout<<ans(a,n);
}

Measured memory_bytes: 15652
from math import degrees
from math import atan

a, b, x = map(int, input().split())
s1 = degrees(atan(2*b/a - 2*x/(a*a*a)))
s2 = 90 - degrees(atan(2 * x / (a * b * b)))

if(a*a*b/2 <= x):
    print(s1)
else:
    print(s2)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
 
/* vector<int> A(N); 
    vector<pair<int, int> > tasks; ＃ソートした場合、１つ目でソート
　tie(b, a) = p.at(i); #pairを分割
    tasks.emplace_back(b, a)  ＃配列tasksの最後に(b,a)を追加
　xの二乗:  pow(x, 2.0) 
    小さい順: sort(v.begin(), v.end());
    大きい順: reverse(v.begin(), v.end());
    int: -2,147,483,648 ～ 2,147,483,647
    ll: -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807
    // int型の2次元配列(3×4要素の)の宣言
    vector<vector<int>> data(3, vector<int>(4));
*/
 
int main() {
  
  ll a,b , c, count=0, ans=0;
  string D, E;
  cin >> a >> b >> c;
  if(4*a*b<c*c+a*a+b*b-2*(b*c+a*c)+2*a*b && (c-a-b)>0){
  	cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

Measured memory_bytes: 256
n=[]
t=[]
nq=list(map(int,input().split()))
for i in range(nq[0]):
	inp=input().split()
	n.append(int(inp[1]))
	t.append(inp[0])
cnt1=0
while len(n)!=0:	
	n[0]=n[0]-nq[1]
	if n[0]<=0:
		cnt1=cnt1+nq[1]+n[0]
		print(t[0],cnt1)
		n.pop(0)
		t.pop(0)	
		
	else:
		n.append(n[0])
		t.append(t[0])
		n.pop(0)
		t.pop(0)
		cnt1+=nq[1]
	


Measured memory_bytes: 9540
/*program by mangoyang*/
#pragma GCC optimize("Ofast", "inline")
#include<bits/stdc++.h>
#define inf (0x7f7f7f7f)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;
using namespace std;
template <class T>
inline void read(T &x){
    int ch = 0, f = 0; x = 0;
    for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    if(f) x = -x;
}
const int N = 1000005;
int a[N], n, m, p, v;
inline int check(int mid){
    int num = 0; ll tot = 0;
    vector<int> vec;
    for(int i = 1; i <= n; i++)
        if(a[i] <= mid){
            tot += min(mid - a[i], m);
            if(m > mid - a[i])
                vec.push_back(m - mid + a[i]);
        } 
        else num++, tot += m;
    if(num >= p) return 0;
    ll now = 1ll * v * m - tot;
    if(now <= 0) return 1;
    sort(vec.begin(), vec.end(), greater<int>());
    for(int i = 0; i < (int) vec.size(); i++){
        now -= vec[i], num++;
        if(now <= 0) break;
    }
    if(num >= p) return 0;
    return 1;
}
int main(){
    read(n), read(m), read(v), read(p);
    for(int i = 1; i <= n; i++) read(a[i]);
    int l = 0, r = 2e9, res = 2e9;
    while(l <= r){
        int mid = (1ll * l + r) >> 1ll;
        if(check(mid)) res = mid, r = mid - 1;
        else l = mid + 1;
    }
    int ans = 0;
    for(int i = 1; i <= n; i++)
        if(a[i] + m >= res) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4488
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  





void solve(){
	int n , k ;
	string s ; 
	cin >> n >> k >> s ;
	k--;
	s[k] = tolower(s[k]);
	cout << s << endl ;
}

signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();












#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef vector<ll> vll;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll n;
        in >> n;
        vll l(n + 1);
        l[0] = 2;
        l[1] = 1;
        for (ll i = 2; i <= n; i++) {
            l[i] = l[i - 1] + l[i - 2];
        }
        out << l[n] << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  deque<char> ans;
  int score = 0;
  for(int i = 0; i < N; ++i) {
    auto c = S[i];
    ans.push_back(c);
    if(c == ')') {
      score--;
    } else if(c == '(') {
      score++;
    }

    if(score < 0) {
      ans.push_front('(');
      score++;
    }
  }
  for(int i = 0; i < score; ++i) {
    ans.push_back(')');
  }
  for(auto c : ans) {
    cout << c;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env ruby

def main
  loop do
    n,r = gets.chomp.split(' ').map(&:to_i)
    break if (n|r) == 0
    puts solve(n, r)
  end
end

def solve n, r
  cards = make_cards(n)

  r.times do
    p,c = gets.chomp.split(' ').map(&:to_i)
    cards = cut(cards, p, c)
  end

  cards.first
end

def make_cards n
  cards = []
  n.downto(1) do |i|
    cards << i
  end
  cards
end

def cut cards, p, c
  result_cards = cards.dup

  0.upto(c-1) do |i|
    result_cards[i] = cards[p-1+i]
  end

  0.upto(p-2) do |i|
    result_cards[c+i] = cards[i]
  end

  result_cards
end

main

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

typedef pair<string, int> si;
vector<si> vs[11];

int main(){
    vs[1].push_back(si("a", 1));
    string alp = "abcdefghijklmn";
    int n; cin >> n;
    for(int i = 2; i <= n; i++){
        for(si& p : vs[i-1]){
            rep(j, p.se){
                vs[i].push_back(si(p.fi + string(1, alp[j]), p.se));
            }
            vs[i].push_back(si(p.fi + string(1, alp[p.se]), p.se+1));
        }
    }

    rep(i, vs[n].size()){
        out(vs[n][i].fi);
    }
}


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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<ll> vll;
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;
typedef unsigned long long ull;

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

int const MAX = 2e5 + 41;

int n, m;
int l[MAX];
int r[MAX];
int ans;

vi e[MAX];

void solve() {
	multiset<int> t;
	fi(1, n) {
		t.insert(l[i]);
	}	
	
	int ql = 0;
	while (sz(t)) {
		auto it = t.upper_bound(ql);
		if (it == t.end()) break;
		t.erase(it);
		ql++;				
	}

	t.clear();
	fi(1, n) {
		e[l[i]].pb(r[i]);
	}

	fdi(m, 0) {
		for (auto z : e[i]) {
			t.insert(z);
		}
		if (i >= 1 && i <= ql) {
			int x = (*t.rbegin());
			t.erase(t.find(x));
		}
	}

	int k = m - ql;
	multiset<int> t2;
	for (int x : t) {
		t2.insert(m - x + 1);
	}

	int qr = 0;
	while (sz(t2) && qr < k) {
		auto it = t2.upper_bound(qr);
		if (it == t2.end()) break;
		t2.erase(it);
		qr++;
	}

	ans = n - ql - qr;
	printf("%d\n", ans);
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

  scanf("%d %d", &n, &m);
  fi(1, n) {
  	scanf("%d %d", &l[i], &r[i]);
  }
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 26112
#include <bits/stdc++.h>
#define rep(n) for(int I = 0; (I) < (n); ++(I) )
#define repeat(i, n) for( int i = 0; (i) < (n); ++(i) )
#define repeat_to(i, n) for( int i = 0; (i) <= (n); ++(i) )
#define repeat_from(i, m, n) for( int i = (m); (i) < (n); ++(i) )
#define repeat_from_to(i, m, n) for( int i = (m); (i) <= (n); ++(i) )
#define el cout << endl
#define dump(x) cout << " " << #x << "=" << x
#define vdump(v) for(size_t T=0; T<v.size(); ++T){cout << " " << #v << "[" << T << "]=" << v[T];} cout << endl
using namespace std;
using lint = long long;
using ld = long double;

int main(void) {
    int n;
    cin >> n;
    vector<int> a(n);
    repeat(i, n) cin >> a[i];
    repeat(i, n) a[i] /= 400;
    
    vector<int> color(9, 0);
    repeat(i, n) {
        if (a[i] < 8) {
            color[a[i]] = 1;
        }
        else if (a[i] >= 8) {
            color[8] += 1;
        }
    }
    
    int ans = 0;
    repeat(i, 8) {
        ans += color[i];
    }
    
    int min_ans = 0, max_ans = 0;
    if (ans == 0) {
        min_ans = 1;
    }
    else {
        min_ans = ans;
    }
    
    max_ans = ans + color[8];
    
    cout << min_ans << " " << max_ans << endl;
}

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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define MOD 1e9+7;

using ll = long long;
using namespace std;

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

    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());

    string ans;
    if(t.compare(s) > 0) ans = "Yes";
    else ans = "No";

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 508
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit((i8[:], i8[:]), cache=True)
def main(A, B):
    N = len(A)
    st, p = np.arange(1 << 20), N
    ans = 0
    while p:
        i, p = st[p - 1], p - 1
        i %= N
        a, b, c = B[i - 1], B[i], B[(i + 1) % N]
        if b < a + c:
            continue
        if b == A[i]:
            continue
        k = (B[i] - A[i]) // (a + c)
        ans += k
        B[i] -= (a + c) * k
        st[p], p = i - 1, p + 1
        st[p], p = i + 1, p + 1
    return ans if np.all(A == B) else -1

N = int(readline())
A = np.array(readline().split(), np.int64)
B = np.array(readline().split(), np.int64)

print(main(A, B))

Measured memory_bytes: 121280
/*
以下のような、たてH cm よこ W cm の枠を描くプログラムを作成して下さい。
##########
#........#
#........#
#........#
#........#
##########
上図は、たて 6 cm よこ 10 cm の枠を表しています。
 */

#include <stdio.h>

int main(void)
{
    int height, width;
    int i, j;

    for (;;)
    {
        scanf("%d %d", &height, &width);
        if (height == 0 && width == 0)
            break;
        for (i = 0; i < height; i++)
        {
            for (j = 0; j < width; j++)
            {
                // 2行目からheight - 1行目の出力（ex: #.....#）
                if (i != 0 && i != height - 1)
                {
                    if (j != 0 && j != width - 1)
                        printf(".");
                    else
                        printf("#"); 
                }
                // 最初と最後の行の出力（ex: ###########）
                else
                {   
                    printf("#");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return (0);
}


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

main(){
	double x,y;
  	cin>> x>>y;
  	if (x > y){
      cout <<"GREATER"<<endl;
    }
  	else if (x <y){
      cout <<"LESS"<<endl;
    }
  	else {
      cout <<"EQUAL"<<endl;
    }
}

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

public class Main {

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

		int[][] paper = new int[14][14];
		byte x, y, size;
		int whites = 0, blot = 0;

		StringTokenizer st;
		while ((line = br.readLine()) != null) {

			st = new StringTokenizer(line, ",");
			x = Byte.parseByte(st.nextToken());
			y = Byte.parseByte(st.nextToken());
			size = Byte.parseByte(st.nextToken());

			x += 2;
			y += 2;

			if (size == 1) {
				paper[x - 1][y]++;
				paper[x][y - 1]++;
				paper[x][y]++;
				paper[x][y + 1]++;
				paper[x + 1][y]++;
			} else if (size == 2) {
				paper[x - 1][y - 1]++;
				paper[x - 1][y]++;
				paper[x - 1][y + 1]++;
				paper[x][y - 1]++;
				paper[x][y]++;
				paper[x][y + 1]++;
				paper[x + 1][y - 1]++;
				paper[x + 1][y]++;
				paper[x + 1][y + 1]++;
			} else {
				paper[x - 2][y]++;
				paper[x - 1][y - 1]++;
				paper[x - 1][y]++;
				paper[x - 1][y + 1]++;
				paper[x][y - 2]++;
				paper[x][y - 1]++;
				paper[x][y]++;
				paper[x][y + 1]++;
				paper[x][y + 2]++;
				paper[x + 1][y - 1]++;
				paper[x + 1][y]++;
				paper[x + 1][y + 1]++;
				paper[x + 2][y]++;
			}

		}
		for (int i = 2; i < 12; i++) {
			for (int j = 2; j < 12; j++) {
				if (paper[i][j] == 0)
					whites++;
				else if (paper[i][j] > blot)
					blot = paper[i][j];
			}
		}
		System.out.println(whites + "\n" + blot);
	}
}

Measured memory_bytes: 15032
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;


main(){
    ll digsum=0;
    string s;cin>>s;
    for(int i=0;i<s.size();i++){
        digsum+= (s[i]-'0');
    }
    if(digsum%9 == 0) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 3716
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>

using namespace std;

int main() {
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;

	set<int> s_water, s_suger;

	for (int i = 0; i <= f; i += a * 100) {
		for (int j = 0; j <= f; j += b * 100) {
			int w = i + j;
			if (w <= f) {
				s_water.insert(w);
			}
		}
	}
	s_water.erase(0);

	for (int i = 0; i <= f; i += c) {
		for (int j = 0; j <= f; j += d) {
			if (i + j > f) {
				break;
			}
			s_suger.insert(i + j);
		}
	}

	vector<int> v_water(s_water.begin(), s_water.end());
	vector<int> v_suger(s_suger.begin(), s_suger.end());
	sort(v_water.begin(), v_water.end());
	sort(v_suger.begin(), v_suger.end());

	int ans_total = a * 100;
	int ans_suger = 0;

	for (auto ww : v_water) {
		for (auto ss : v_suger) {
			if (ww + ss > f || ss > ww / 100 * e) {
				break;
			}
			if (ss * ans_total > ans_suger * (ss + ww)) {
				ans_total = ss + ww;
				ans_suger = ss;
			}
		}
	}

	cout << ans_total << " " << ans_suger << endl;
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>
 
double dist(double x1, double y1, double x2, double y2)
{
    //return (pow(x1 - x2, 2) + pow(y1 - y2, 2));
    return (hypot(x1 - x2, y1 - y2));
} 
 
int main(void)
{
    double ax, ay;
    double bx, by;
    double ar, br;
    double abdist;
    int n, i;
 
    scanf("%d", &n);
    for (i = 0; i < n; i++){
        scanf("%lf %lf %lf %lf %lf %lf", &ax, &ay, &ar, &bx, &by, &br);
 
        abdist = dist(ax, ay, bx, by);
        if (abdist <= ar + br){
            if (ar > br + abdist){
                puts("2");
            }
            else if (br > ar + abdist){
                puts("-2");
            }
            else {
                puts("1");
            }
        }
        else {
            puts("0");
        }
    }
 
    return (0);
}

Measured memory_bytes: 632
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define REPe(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 REPei(i, a, b) for(int i = int(a); i <= int(b); ++i)

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

    int n;
    cin >> n;
    if (n/100 == n%10) cout << "Yes";
    else cout << "No";

}



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

int main() {
	// your code goes here
	int a,b,c,x,y;
	cin >> a >> b >> c >> x >> y;
	int count=0;
	if(a+b<=c*2){
		count=a*x+b*y;
//		cout << "1banme" << endl;
	}
	else if(x==y){
		count=2*x*c;
//		cout << "2banme" << endl;
	}
	else if(x>y){
		count=2*y*c;
		if(a>c*2){
			count=2*x*c;
//		cout << "3banme" << endl;
		}
		else count=count+a*(x-y);
//		cout << "4banme" << endl;
	}
	else if(b>c*2){
		count=2*y*c;
//		cout << "5banme" << endl;
	}
	else count=2*x*c+b*(y-x);
	cout << count << endl;  
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
 
using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 
 
#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
typedef pair<int, int> P;
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}


ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

int h,w;
vs field;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
vvi d(50,vi(50));
 
 
int bfs(int sx,int sy,int gx,int gy){
  queue<P> que;
  for (int i = 0; i < 50; i++){
    for (int j = 0; j < 50; j++) d[i][j] = 100000000;
  }
  que.push(P(sx, sy));
  d[sx][sy] = 0;
  
// キューが空になるまでループ
  while (que.size()){
//キューの先頭を取り出す
    pair<int,int> p = que.front(); que.pop();
//取り出してきた状態がゴールなら探索をやめる
    if (p.first == gx && p.second == gy) break;
//移動4方向をループ
    for (int i = 0; i < 4; i++) {
//移動した後の点を(nx, ny)とする
      int nx = p.first + dx[i], ny = p.second + dy[i];
//移動が可能かの判定とすでに訪れたことがあるかの判定(d[nx][ny] != INFなら訪れたことがある)
      if (0 <= nx && nx < h && 0 <= ny && ny < w && field[nx][ny] != '#' &&d[nx][ny] ==100000000) {
//移動できるならキューに入れ、その点の距離をpからの距離+1で確定する
        que.push(P(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
return d[gx][gy];
}


int main(){
  cin>>h>>w;
  
  rep(i,h){
    string stri; 
    cin>>stri;
    field.push_back(stri);
  }
  int ans=0;
  rep(i,h){
    rep(j,w){
      rep(k,h){
        rep(l,w){
          if(field[i][j]!='#' && (i !=k ||j!=l) && field[k][l]!='#'){
            ans = max(ans,bfs(i,j,k,l));
          }
        }
      }
    }
  }
  cout<<ans<<endl;
}




Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math 
l = [int(input()) for i in range(5)]
m = 10
s = 0
for n in l:
        if (n%10)!=0 and (n%10)<m:
                m= n%10
n = sum([math.ceil(s/10.0)*10 for s in l])
print(n-(10-m))


Measured memory_bytes: 3060
#include <stdio.h>

int main() {
  int rows, columns, n, tempR = 1, tempC = 1;
  scanf("%d %d %d", &rows, &columns, &n);

  int i = 1, j = 1;
  while(tempR < n && i <= rows) {
    tempR = i * columns;
    i++;
  }
  while(tempC < n && j <= columns) {
    tempC = j * rows;
    j++;
  }

  if(i == 1 && j == 1) printf ("1");
  else if(i < j) printf("%d", i - 1);
  else printf("%d", j - 1);
  return 0;
}

Measured memory_bytes: 1696
using System;

public class Pea{
  public double x;
  public double y;
  public Pea(double x,double y){
    this.x = x;
    this.y = y;
  }

  public static void koh(int n,Pea p1,Pea p2){
    if(n > 0){
      var s = new Pea(2.0/3*p1.x+1.0/3*p2.x,2.0/3*p1.y+1.0/3*p2.y);
      var t=new Pea(1.0/3*p1.x+2.0/3*p2.x, 1.0/3*p1.y+2.0/3*p2.y);
      var st=new Pea(t.x-s.x, t.y-s.y);
      var u=new Pea(1.0/2*st.x-Math.Sqrt(3)/2*st.y+s.x,
      Math.Sqrt(3)/2*st.x+1.0/2*st.y+s.y);

      koh(n - 1,p1,s);
      Console.WriteLine(s.x+" "+s.y);
      koh(n-1, s, u);
      Console.WriteLine(u.x+" "+u.y);
      koh(n-1, u, t);
      Console.WriteLine(t.x+" "+t.y);
      koh(n-1, t, p2);
    }
  }
}

class C5{
  public static void Main(){
    var n=int.Parse(Console.ReadLine());
       var p1=new Pea(0, 0);
       var p2=new Pea(100, 0);
       Console.WriteLine(p1.x+" "+p1.y);
       Pea.koh(n, p1, p2);
       Console.WriteLine(p2.x+" "+p2.y);
  }
}



Measured memory_bytes: 15880
#include <stdio.h>
 
main(){
 
  long d = 1,e;
  long a,b,c;
 
  scanf("%ld %ld",&a,&b);
 
if(b>a){
c = a;
a = b;
b = c;
}
 
  while(d != 0){
    d = a % b;
e=d;
    a = b;
    b = d;
  }
 
  printf("%ld\n",a);
}

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

using namespace std;

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

  int n, m;
  cin >> n >> m;
  vector<int> cnt(n + 1);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    cnt[a]++;
    cnt[b]++;
  }
  for (int i = 1; i <= n; ++i) {
    cout << cnt[i] << "\n";
  }
}


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

int main() {
  ll n,k,q;
  cin >> n >> k >> q;
  vector<int> a(n);
  for(ll i=0;i<q;i++){
    int b;
    cin >> b;
    a.at(b-1)++;
  }
  for(int i=0;i<n;i++){
    if(k-q+a.at(i)>0)
    cout << "Yes" << endl;
    else
    cout << "No" << endl;
  }
}



Measured memory_bytes: 3780
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
//void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
													 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]"<<endl;}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
const ll mod = 998244353;
const ll maxn = 1000005;
const ll mm = 1e+18;
bool chk(int x,int y){
	long double xx=x;
	long double yy=y;
	long double ff=xx*yy;
	if(ff>mm) return true;
	return false;
}
void solve()
{
	int n;
	cin>>n;
	int res=1;
	int a[n];
	rep0(i,n) cin>>a[i];
	rep0(i,n){
		if(a[i]==0){
			cout<<0;
			return;
		}
	}
	rep0(i,n){
		int x=a[i];
		if(chk(res,x)){
			cout<<-1;
			return;
		}
		res*=x;
	}
	cout<<res;
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
        //nx;
    }
    return 0;
}


Measured memory_bytes: 4424
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<iomanip>
using namespace std;
//int father[100001];
//queue<int>p;
//priority_queue<long long ,vector<long long>,greater<long long> >pp;
/*int cmp(wo a,wo b)
return a.   <b.   ;
*/
/*
void unionn (int x,int y){
x=find(x);y=find(y);
father[y]=x;
}
int find(int x)
{
if(father[x]!=x)father[x]=find(father[x]);
return father[x];
}
int judge(int a,int b){
if(find(a)!=find(b))return 0;
else return 1;
}
*/
/*
int dij(){
for(int i=1;i<=n;i++){
	for(int j=i+1;j<=n;j++){
		t++;
		dis[t].distance=0;
	   for(int k=0;k<7;k++){
	   	if(car[i][k]!=car[j][k]){
	   		dis[t].distance++;
		   }
	   }
	   dis[t].x=i;dis[t].y=j;
	}
}
for(int i=1;i<=n;i++){
	father[i]=i;
}
sort(dis+1,dis+t+1,cmp);
for(int i=1;i<=t;i++){
	if(find(dis[i].x)!=find(dis[i].y)){
		unionn(dis[i].x,dis[i].y);
		ans+=dis[i].distance;
	}
}
}
?
*/
int main(){
long long a[101111]={0},ans=1,n;
//char b[100001];
cin>>n;
/*for(int i=1;i<=n;i++){
cin>>a[i];
}*/
/*
if()cout<<"No";
else cout<<"Yes";
*/
while(ans<=n)ans*=2;
cout<<ans/2;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

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

    int N;
    cin >> N;
    vector<vector<int> > V(N);
    int ans = 0;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        a--;
        V.at(i).push_back(a);
        if (find(V.at(a).begin(), V.at(a).end(), i) != V.at(a).end()) {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <cstdio>
#include <string.h>
#include <cstring>

using namespace std;

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

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

int x,y,ny,nx,nexty,nextx;
int wall_cnt;
char c[100][100];
int d[100][100] = {0};
int d1[] = {0,0,-1,1};
int d2[] = {1,-1,0,0};
int dc;
int cnt;
int main(){
    cin >> y >> x;

    REP(i,y){
        REP(j,x){
            cin >> c[i][j];
            if(c[i][j] == '#'){
                wall_cnt++;
            }
        }
    }

    queue<P> que;
    que.push(P(0,0));
   // memset(d,-1,sizeof(d));
   d[0][0] = 0;

    while(que.size()){
        P p = que.front(); que.pop();
        ny = p.first;
        nx = p.second;
        dc = d[ny][nx];
        if(ny == y - 1 && nx == x - 1) {
            cnt = d[ny][nx];
            break;
        }

        REP(i,4){
            nexty = ny + d1[i];
            nextx = nx + d2[i];
            if(nexty < 0 || nexty >= y || nextx < 0 || nextx >= x) continue;
            if(c[nexty][nextx] == '#' || d[nexty][nextx] != 0) continue;

            que.push(P(nexty,nextx));
            d[nexty][nextx] = dc + 1;
        }
        if(!que.size()){
            cout << -1 << endl;
            return 0;
        }
    }

    int ans = x * y - wall_cnt - cnt - 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int r, s, p;
    cin >> r >> s >> p;
    string t;
    cin >> t;

    map<char, int> mp;
    mp['r'] = p;
    mp['s'] = r;
    mp['p'] = s;

    ll ans = 0;

    int m = (n + k - 1)/k;

    for(int i=0; i<m; i++){
        for(int j=0; j<k; j++){
            if(j+k*i >= n) continue;
            if(t[j+i*k] == t[j+(i+1)*k]){
                t[j+(i+1)*k] = 'm';
                ans += mp[t[j+i*k]];
                continue;
            }
            ans += mp[t[j+i*k]];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sort(a) sort(all(a))
using P = pair<int, int>;
using ll = long long;
using ld = long double;
int dx[4] = { 0, 1, 0,-1 };
int dy[4] = { 1, 0,-1, 0 };

signed main() {
  int x;
  cin >> x;
  int ans =0;
  int a = x/500;
  ans += a*1000;
  x -= 500*a;
  int b = x/5;
  ans += b*5;
  cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  for(int i=1; i<10; i++){
    for(int j=i; j<10; j++){
      if(i*j == N) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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


int main() {

    string s;
    cin >> s;


    int diff = 10000;
    REP(i, s.size() - 2){
        int tmp = stoi(s.substr(i, 3));
        //cout << tmp << endl;
        diff = min(diff, abs(tmp - 753));
    }
    cout << diff << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void) {
	long long n, i, end, max = 0;
	scanf("%lld", &n);

	end = sqrt(n);
	for (i = 1; i <= end; i++) {
		if (n % i == 0)
			max = i;
	}

	printf("%lld\n", max + (n / max) - 2);
	return 0;

}

Measured memory_bytes: 128
s = input()
n = len(s)

num = 1
l = [0]
for i in range(n-1, -1, -1):
    l.append((l[-1] + int(s[i]) * num) % 2019)
    num *= 10
    num %= 2019

from collections import Counter
dic = Counter(l)

ans = 0
for i in dic.values():
    ans += i * (i - 1) // 2
print(ans)

Measured memory_bytes: 16608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 100000000;
const int MOD = 1000000007;
std::vector<long> enum_div(long n)//nの約数を列挙
{
	std::vector<long> ret;
	for(long i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}
int main(){
  long n;
  std::cin >> n;
  vector<long>  v;
  v=enum_div(n);
  sort(all(v));
  int mi=10000;
  for (int i = 0; i < v.size()/2+1; i++) {
    /* code */
    long a,b;
    a=n/v[i];b=n/a;
    if(mi>max((int)log10(a),(int)log10(b))+1)mi=max((int)log10(a),(int)log10(b))+1;
  }
  std::cout << mi << std::endl;
}

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

#define INF 1e9

int *p;
int **m;

/**
* 配列を動的に確保し、初期化する
* @parm n 配列要素数
*/
void init(int n) {
	int i;

	// pの領域を確保
	p = (int *)malloc(sizeof(int) * (n + 1));

	// mの領域を確保
	m = (int **)malloc(sizeof(int *) * (n + 1));
	for (i = 0; i <= n; i++)
		m[i] = (int *)malloc(sizeof(int) * (n + 1));

	// m[i][i]を初期化
	for (i = 1; i <= n; i++)
		m[i][i] = 0;
}

/**
* 小さい方の値を返す
* @parm a
* @parm b
* @return 小さい方の値
*/
int min(int a, int b) {
	if (a <= b) return a;
	else return b;
}

int matrixChainOrder(int n) {
	int i, j, k, l;
	int tmp;

	for (l = 2; l <= n; l++) {
		for (i = 1; i <= n - l + 1; i++) {
			j = i + l - 1;
			m[i][j] = INF;
			for (k = i; k <= j - 1; k++) {
				tmp = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
				m[i][j] = min(m[i][j], tmp);
			}
		}
	}

	return m[1][n];
}

/**
* 動的に確保した配列を解放する
* @parm n 配列の要素数
*/
void allFree(int n) {
	int i;
	// pを解放
	free(p);

	// mを解放
	for (i = 0; i < n; i++) free(m[i]);
	free(m);
}

main() {
	int n, i;

	scanf("%d", &n);

	init(n);

	for (i = 0; i < n; i++) {
		scanf("%d%d", &p[i], &p[i+1]);
	}
	printf("%d\n", matrixChainOrder(n));

	allFree(n);

	return 0;
}

Measured memory_bytes: 636
// clang-format off
#include <bits/stdc++.h>

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()
 
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }
// clang-format on

const int MAX_N = 100000;
int n, m, s, t;

struct edge {
    int to;
    ll cost;
};
vec<vec<edge>> g1;
vec<vec<edge>> g2;

vl dijkstra(int s, vec<vec<edge>>& g) {
    vl d(g.size(), LLONG_MAX);
    d[s] = 0;
    priority_queue<pli, vector<pli>, greater<pli>> q;
    q.push(mp(0LL, s));

    while (!q.empty()) {
        int u;
        ll cost;
        tie(cost, u) = q.top();
        q.pop();

        if (d[u] < cost) continue;

        d[u] = cost;

        for (edge e : g[u]) {
            if (d[u] + e.cost >= d[e.to]) continue;

            d[e.to] = d[u] + e.cost;

            q.emplace(d[e.to], e.to);
        }
    }

    return d;
}

int main() {
    fastio();

    cin >> n >> m >> s >> t;
    s--, t--;

    vec<vec<edge>> g1(n), g2(n);

    forn(i, m) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--, v--;
        g1[u].push_back((edge) { v, a });
        g1[v].push_back((edge) { u, a });
        g2[u].push_back((edge) { v, b });
        g2[v].push_back((edge) { u, b });
    }

    vl d1 = dijkstra(s, g1);
    vl d2 = dijkstra(t, g2);

    vl ans(n);
    set<pli> s;
    forn(i, n) {
        //cout << d1[i] << " " << d2[i] << endl;
        ans[i] = d1[i] + d2[i];
        s.emplace(ans[i], i);
    }

    forn(i, n) {
        cout << TEN(15) - s.begin()->fst << '\n';
        s.erase(mp(ans[i], i));
    }

    return 0;
}

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

#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define dbg(var) {std::cout << #var << "  = " << var << nl;}
#define vi vector<int>
typedef long long ll;

using namespace std;


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

	ll a , b , c , d;
	cin >> a >> b >> c >> d;
	
	auto f = [](ll a , ll x)
	{
		return a / x;
	};
	
	auto lcm = [](ll a , ll b)
	{
		return a * b / __gcd(a , b);
	};

	cout << (b - a + 1) - (f(b , c) - f(a - 1 , c)) - (f(b , d) - f(a - 1 , d)) + (f(b , lcm(c , d)) - f(a - 1 , lcm(c , d)))<< nl;
	
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int inf = 1e9+7;
const int N = 1e6+9;

int main() {
    ios_base::sync_with_stdio(0);
    int a,b,n,d,t,s;
    cin>>d>>t>>s;
    if(s*t>=d) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define INF (300*300*1000)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int h,w;
string fie[301];
int dp[310][310];
int cost[301][310][310];

void calc(int x,int y1,int y2){
	int cnt=0;
	int l=h-max(y1,y2);
	for(int i=0;i<l;i++){
		if(fie[y1-min(y1,y2)+i][x]==fie[y2-min(y1,y2)+i][x+1])cnt++;
		cost[x][y1+l-i-1][y2+l-i-1]=cnt;
	}
}

int func(int x,int a,int b){
	if(a==h || b==h)return 0;
	if(dp[a][b]!=-1)return dp[a][b];
	return dp[a][b]=min(func(x,a+1,b),func(x,a,b+1))+cost[x][a][b];
}

int main(void){
	scanf("%d%d",&h,&w);
	for(int i=0;i<h;i++){
		cin >> fie[i];
	}
	memset(dp,-1,sizeof(dp));
	for(int k=0;k<w;k++){
		for(int i=0;i<=h;i++){
			for(int j=0;j<=h;j++){
				cost[k][i][j]=INF;
			}
		}
	}
	for(int k=0;k<w-1;k++){
		for(int i=0;i<h;i++){
			for(int j=0;j<h;j++){
				if(cost[k][i][j]==INF)calc(k,i,j);
			}
		}
	}
	int res=0;
	for(int i=0;i<w-1;i++){
		memset(dp,-1,sizeof(dp));
		res+=func(i,0,0);
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 111360
'''input
3 5
5
1 2 3 4 5
'''
h , w = map(int ,raw_input().split())
al = input()
a = map(int ,raw_input().split())
lia = []
for i in range(al):
	lia += [i+1]*a[i]
ansl = []
liac = 0
for i in range(h):
	temp = []
	for j in range(w):
		temp.append(lia[liac])
		liac += 1
	if i%2 == 0:
		ansl.append(temp)
	else:
		ansl.append(list(reversed(temp)))
for i in range(h):
	for j in range(w):
		print ansl[i][j],
	print




Measured memory_bytes: 3460
#include <iostream> 

using namespace std;

int main(int argc, char *argv[]) {
	int A, B;
	cin >> A >> B;
	if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)
		cout << "Possible" << endl;
	else
		cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 256