akhauriyash/Code-Regression huggingface dataset:
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN2(n,m);
  Vi weight(n);
  Vi value(n);
  REP(i,n){
    IN2(weight[i],value[i]);
  }
  int dp[n+10][m+10];
  REP(i,n+10) REP(j,m+10) dp[i][j] = 0;
  REP(i,n){
    REP(sum_w,m+1){
      if (sum_w - weight[i] >= 0) {
        chmax(dp[i+1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
      }
      chmax(dp[i+1][sum_w], dp[i][sum_w]);
    }
  }
  OUT(dp[n][m]);
}

Measured memory_bytes: 86272
// Author - Abhishek giri

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 100000000007
#define V(type) vector<type> 
#define all(c) ((c).begin(),(c).end())
#define in(var) cin>>(var)
#define out(var) cout<<(var)
#define on(var) cout<<var<<"\n"
#define f(i,n) for(ll i = 0 ; i < n ;i++)
#define mfor(i,init,n,b) for(ll i = (init) ; i < (n) ; i+= (b))
#define cfor(i,c) for(auto i = (c).begin() ; i!= (c).end(); i++)

/*##################################################################################*/


/*
bitset<10000000> prime ;
void calculateprime()
{
    //calculating primes
    prime[0] = prime[1] = 1 ;
    for(int i = 2 ; (ll)i*i <= 10000000 ; i++)
    {
        if(prime[i] == 0)
        {
            for(ll j = i*i ; j <= 10000000 ; j += i )
            {
                prime[j] = 1 ;
            }
        }
    }
}
*/

bool isprime(long n)
{
    for(int i = 2 ; (ll) i*i <= n ; i++)
    {
        if(n % i == 0){
            return false;
        }
    }
    return true;
}


/*
ll fib(int n) 
{ 
  ll a = 0, b = 1, c, i; 
  if( n == 0) 
    return a; 
  for (i = 2; i <= n; i++) 
  { 
    c = (a + b); 
    a = b; 
    b = c; 
  } 
  return b; 
}
*/


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


ll findgrouplcm(ll arr[], ll n) 
{ 
    ll ans = arr[0]; 
  
    for (ll i = 1; i < n; i++) 
        ans = (arr[i] * (ans/(gcd(arr[i], ans))));
  
    return ans; 
}



ll powerwithmod(ll x, unsigned ll y, ll p)  
{  
    ll res = 1;    
  
    x = x % p; 
   
    if (x == 0) return 0;
  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
   
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}

ll setBitNumber(ll n) 
{ 
    n |= n >> 1; 
    n |= n >> 2; 
    n |= n >> 4; 
    n |= n >> 8; 
    n |= n >> 16; 
    n |= n >> 32;
    n = n + 1; 
  
    return (n >> 1); 
} 
void decToBinary(ll n,string &s) 
{ 
    for (int i = 63; i >= 0; i--) { 
        int k = n >> i; 
        if (k & 1) 
            s += "1"; 
        else
            s += "0"; 
    } 
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        string s;
        in(s);
        if( s == "ABC")
        {
            out("ARC");
        }
        else{
            out("ABC");
        }
    }
    return 0;
}

Measured memory_bytes: 3604
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    cout << min(c, b / a) << '\n';
}


Measured memory_bytes: 888
import math

N = int(input())
L = list(map(int, input().split()))

Nagasa = len(L)
over = 0

counter = [0]*8

for i in range (0, Nagasa):
	if L[i] >= 3200:
		over+=1
	else:
		counter[math.floor(L[i]/400)]=1

count = sum(counter)

print(max(1, count), count+over)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int ll;
typedef unsigned long long int ull;
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pii>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define MAX 1000000001

int main(){
	fast;
	int test=1;
	//cin >> test;
	while(test--){
	    int n;
	    cin >> n;
	    ll arr[n];
	    for(int i=0 ; i<n ; i++){
	        cin >> arr[i];
	    }
	    ll sum[n];
	    sum[n-1]=arr[n-1];
	    for(int i=(n-2) ; i>=0 ; i--){
	        sum[i]=sum[i+1]+arr[i];
	        sum[i]%=mod;
	    }
	    ll ans=0;
	    for(int i=0 ; i<(n-1) ; i++){
	        ans+=(arr[i]*(sum[i+1]));
	        ans%=mod;
	    }
	    cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 6764
#include <bits/stdc++.h>
using namespace std;
int64_t keisan(vector<bool> &p,vector<int> &s){
  int64_t j=0;
  int64_t k=s.at(0);
  for(int i=1;i<s.size();i++){
    if(p.at(i)){
      j+=k;
      k=s.at(i);
    }
    else{
      k=k*10+s.at(i);
    }
  }
  j+=k;
  return j;
}

void tasu(vector<bool> &p,vector<bool> &bo,int k,vector<int> &s,int64_t &j){
  if(k==p.size()){
    j+=keisan(p,s);
    return;
  }
  for(bool i:bo){
    p.at(k)=i;
    tasu(p,bo,k+1,s,j);
  }
}
    

int main() {
  int64_t S;
  cin >> S;
  vector<int> s(0);
  for(;S>0;S/=10)
    s.push_back(S%10);
  reverse(s.begin(),s.end());
  vector<bool> p(s.size(),false),bo={false,true};
  int64_t j=0;
  tasu(p,bo,1,s,j);
  cout << j << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/











int N, M;
vector<int> E[101010];
int S, T;
ll dst[101010][3];
int vis[101010][3];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M;
	rep(i, 0, M) {
		int a, b; cin >> a >> b;
		a--; b--;
		E[a].push_back(b);
	}
	cin >> S >> T; S--; T--;

	queue<pair<int, int>> que;

	que.push({ S, 0 });
	vis[S][0] = 1;

	while (!que.empty()) {
		int cu, jmp;
		tie(cu, jmp) = que.front(); que.pop();

		if (cu == T and jmp == 0) {
			cout << dst[cu][jmp]/3 << endl;
			return;
		}

		int jmp2 = (jmp + 1) % 3;
		fore(to, E[cu]) if (!vis[to][jmp2]) {
			vis[to][jmp2] = 1;
			dst[to][jmp2] = dst[cu][jmp] + 1;
			que.push({ to, jmp2 });
		}
	}

	cout << -1 << endl;
}







Measured memory_bytes: 9344
/*input
999983
*/

#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>




#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define fill(a)  memset(a, 0, sizeof (a))
#define mp make_pair
#define pb push_back
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define pdd pair<double, double>
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define forstl(i,v) for(auto &i: v)
#define dbg(x) cout << #x << " = " << x << '\n'
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;
#define dbgstl(v) cout<<#v<<" = \n"; { int c=0; forstl(it,v) \
cout<<"    "<<#v<<"["<< ++c <<"] = "<<it<<endl;} cerr<<endl
#define dbgstlp(v) cout<<#v<<" = \n"; { int c=0; forstl(it,v) \
cout<<"    "<<#v<<"["<< ++c <<"] = "<<it.f<<" , "<<it.s<<endl;} cerr<<endl
#define PI           3.14159265358979323846

#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define pdd pair<double, double>
#define in(v,n) vll v(n);rep(i,n) cin>>v[i]


using namespace std;


int main(){
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    cin.exceptions(cin.failbit);
    int T;
	// cout<<std::fixed<<std::setprecision(35);
	// cin>>T;while(T--)
	{
		ll t,n,i,j,x,y,m,l,d,k;
		cin>>n;
		ll ans=1,curr=7;
		for(int i=0;i<=n;i++){
			curr=curr%n;
			if(curr==0){
				cout<<ans<<endl;
				return 0;
			}
			curr=curr*10+7;
			ans++;
		}
		cout<<-1<<endl;
	}
}

Measured memory_bytes: 3648
n, m, x = map(int, input().split())

c = []
for i in range(n):
  c.append([int(j) for j in input().split()])

ans = []

for bit in range(2 ** len(c)):
  u = []
  for j in range(len(c)):
    if (bit >> j) & 1:
      u.append(c[j])

  f = [False] * m
  for h in range(m):
    mm = 0
    for z in u:
      mm += z[h+1]

    if mm == x or mm > x: 
      f[h] = True

  if f.count(True) == m:
    jj = 0
    for i in u:
      jj += i[0]
    ans.append(jj)

if len(ans) == 0:
  print("-1")
else:
  print(min(ans))

Measured memory_bytes: 9312
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE false
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

/*
 
 8/6/2018
 
 17:10-17:20 analysis
 17:35 RE
 
 */

// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
const int MAX_N=300+1;
int H,W,D,Q;
II P[MAX_N*MAX_N];
const int MAX_Q=1e5+1;
int L[MAX_Q],R[MAX_Q];
vector<LL> cum[MAX_N*MAX_N];
void solve() {
  REP(d,D) {
    int x=d;
    cum[d].clear();
    cum[d].push_back(0);
    while(x+D<H*W) {
      cum[d].push_back(cum[d].back());
      int xx=x+D;
      auto p1=P[x],p2=P[xx];
      LL cost=abs(p1.first-p2.first)+abs(p1.second-p2.second);
      cum[d].back()+=cost;
      dump4(d,x,xx,cost);
      x=xx;
    }
  }
  REP(i,Q) {
    int g=L[i]%D;
    int l=L[i]/D,r=R[i]/D;
    dump4(i,L[i],R[i],g);
    dump4(l,cum[g][l],r,cum[g][r]);
    cout<<cum[g][r]-cum[g][l]<<endl;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>H>>W>>D;
  REP(i,H)REP(j,W) {
    int p; cin>>p;
    P[p-1]={i,j};
  }
  cin>>Q;
  REP(i,Q) cin>>L[i]>>R[i],--L[i],--R[i];
  solve();
  return 0;
}


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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    int x, a; cin >> x >> a;
    if (x < a) cout << 0 << endl;
    else cout << 10 << endl;
}


Measured memory_bytes: 888
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static AL[] adjArr;
	public static boolean visited[];
	public static int d[]; // discover time
	public static int f[]; // finish time
	public static int currentTime;
	
	public static void dfs(int id){
		// update discover time of current node
		d[id] = currentTime++;
		
		int next;

		// Start checking paths from id
		for(int i = 0; i < adjArr[id].al.size(); i++){
			next = adjArr[id].al.get(i);
			// If already visited, keep checking until new node found
			if(visited[next])continue;
			visited[next] = true;
			dfs(next);
		}
		// When unvisited node found, set finish time
		f[id] = currentTime++;
	}

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {

		Scanner in = new  Scanner(System.in);

		int totalVertex = in.nextInt();
		adjArr = new AL[totalVertex];

		for(int i = 0; i < totalVertex; i++){
			adjArr[i] = new AL();
		}

		visited = new boolean[totalVertex];
		// Initialize visited array with false
		for(int i = 0; i < totalVertex; i++){
			visited[i] = false;
		}

		d = new int[totalVertex];
		f = new int[totalVertex];

		int id, connections, neighbor;
		currentTime = 1;

		for(int j = 0; j < totalVertex; j++){
			id = in.nextInt();
			// de-increment to get correct arr index
			id--;

			connections = in.nextInt();

			for(int i = 0; i < connections; i++){
				neighbor = in.nextInt();
				// Again, de-increment for correct index
				neighbor--;
				// Connect the neighbor
				adjArr[id].al.add(neighbor);
			}
		}

		for(int i = 0; i < totalVertex; i++){
			if(visited[i])continue;
			visited[i] = true;
			dfs(i);
		}

		for(int i = 0; i < totalVertex; i++){
			System.out.println((i+1) + " " + d[i] + " " + f[i]);
		}
		
		in.close();
	}

}

// To deal with unchecked warnings for ArrayList<Integer>
class AL{
	ArrayList<Integer> al;
	
	AL() {
		al = new ArrayList<Integer>();
	}
}



Measured memory_bytes: 28284
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
#define endl "\n"
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}while(0)

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll modncrlistp[200000],modncrlistm[200000];

ll modncrs(ll n,ll r){
  ll i,j;
  if(modncrlistp[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistp[i])break;
    }
    if(i<0){
      modncrlistp[0]=1;
      rep1(i,n+1){
        modncrlistp[i]=(modncrlistp[i-1]*i)%mod;
      }
    }else{
      For(j,i+1,n+1){
        modncrlistp[j]=(modncrlistp[j-1]*j)%mod;
      }
    }
  }
  if(modncrlistm[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistm[i])break;
    }
    if(i<0){
      modncrlistm[0]=1;
      rep1(i,n+1){
        modncrlistm[i]=(modncrlistm[i-1]*modinv(i))%mod;
      }
    }else{
      For(j,i+1,n+1)modncrlistm[j]=(modncrlistm[j-1]*modinv(j))%mod;
    }
  }
  return (((modncrlistp[n]*modncrlistm[r])%mod)*modncrlistm[n-r])%mod;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

vec eratosthenes(ll N){
  ll i;
  vec ch(N+1,1),p;
  ch[0]=ch[1]=0;
  rep(i,N+1){
    if(ch[i]){
      p.push_back(i);
      for(ll j=2;i*j<=N;j++){
        ch[i*j]=0;
      }
    }
  }
  return p;
}
int main(){
  ll i,j,N,M=0,m=0;
  cin>>N;
  vec v(N);
  rep(i,N){
    cin>>v[i];
    M=max(M,v[i]);
    m=min(m,v[i]);
  }
  if(M+m==0&&m==0){
    cout<<0<<endl;
    return 0;
  }else if(M+m>0){
    rep(i,N){
      if(v[i]==M)break;
    }
    cout<<N*2-1<<endl;
    rep(j,N){
      cout<<i+1<<" "<<j+1<<endl;
    }
    rep1(i,N){
      cout<<i<<" "<<i+1<<endl;
    }
  }else{
    rep(i,N){
      if(v[i]==m)break;
    }
    cout<<N*2-1<<endl;
    rep(j,N){
      cout<<i+1<<" "<<j+1<<endl;
    }
    brep(i,N-1){
      cout<<i+2<<" "<<i+1<<endl;
    }
  }
  return 0;
}

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

   typedef long long ll;
   typedef pair<ll, ll> Pii;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}


   ll dx[4]={1,0,-1,0};
   ll dy[4]={0,1,0,-1};
const ll MAX_N = 1e5;
ll N;
vector<ll> G[MAX_N] = {}; //頂点iに隣接する頂点
//dp1[i] = 頂点iを黒く塗った時に部分木を塗る方法, dp2[i] = 頂点iを白く塗った時に部分木を塗る方法
ll dp1[MAX_N] = {}, dp2[MAX_N] = {}, is_reached[MAX_N] = {};

void dfs(ll v){
  if (is_reached[v] == 0){
    is_reached[v] = 1;
    dp1[v] = 1; dp2[v] = 1;
    for (auto u = G[v].begin(); u != G[v].end();u++){
      if (is_reached[*u] == 0){
        dfs(*u);
        dp1[v] *= dp2[*u];
        dp1[v] %= MOD;
        dp2[v] *= (dp1[*u] + dp2[*u]);
        dp2[v] %= MOD;
      }
    }
//    printf("dp1[%lld] = %lld, dp2[%lld] = %lld\n", v, dp1[v], v, dp2[v]);
  }
}

int main(){
  cin >> N;
  REP(i, N - 1){
    ll xi, yi;
    cin >> xi >> yi;
    G[xi - 1].pb(yi - 1);
    G[yi - 1].pb(xi - 1);
  }
  dfs(0);
  cout << (dp1[0] + dp2[0]) % MOD << endl;
}


Measured memory_bytes: 12288
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <cstdint>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;

int main(void){
    int n;
    cin >> n;
    vi a(n);
    for(i64 &x : a){
        cin >> x;
        if(x == 0){
            cout << 0 << '\n';
            return 0;
        }
    }
    i64 p = 1;
    for(i64 &x : a){
        if(x <= 1000000000000000000LL / p) p *= x;
        else{
            cout << -1 << '\n';
            return 0;
        }
    }
    cout << p << '\n';
    return 0;
}

Measured memory_bytes: 4056
// https://atcoder.jp/contests/abc162/tasks/abc162_e
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

long long modpow(long long a, long long n, long long mod)
{
    long long ret = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            ret *= a;
            ret = ret % mod;
        }
        a *= a;
        a = a % mod;
        n = (n >> 1);
    }
    return ret;
}

int main()
{
    static const long long mod = 1e9 + 7;
    long long N, K;
    cin >> N >> K;
    vector<long long> cnt(K + 1, 0);
    long long ans = 0;
    for (long long i = K; i >= 1; --i)
    {
        long long q = K / i;
        cnt[i] = modpow(q, N, mod);
        for (long long j = i + i; j <= K; j += i)
        {
            cnt[i] -= cnt[j];
        }
        ans += cnt[i] * i;
        ans = ans % mod;
        if (ans < 0) ans = (ans + mod) % mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4040
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
 
const ll inf = 1e9 + 7;
const ll Mod = 998244353;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

const int Size = 5e3 * 5e3 + 5;
ll DP1[Size], DP2[Size];

int main(){
  ll N; cin >> N;
  ll GA, SA, BA; cin >> GA >> SA >> BA;
  ll GB, SB, BB; cin >> GB >> SB >> BB;

  for (ll i = 0; i <= N; i++){
    if (i + GA <= N){
      DP1[i + GA] = max(DP1[i + GA], DP1[i] + GB - GA);
    }
    if (i + SA <= N){
      DP1[i + SA] = max(DP1[i + SA], DP1[i] + SB - SA);
    }
    if (i + BA <= N){
      DP1[i + BA] = max(DP1[i + BA], DP1[i] + BB - BA);
    }
  }

  ll M = 0;
  for (ll i = 0; i <= N; i++){
    M = max(M, i + DP1[i]);
  }

  for (int i = 0; i <= M; i++){
    if (i + GB <= M){
      DP2[i + GB] = max(DP2[i + GB], DP2[i] + GA - GB);
    }
    if (i + SB <= M){
      DP2[i + SB] = max(DP2[i + SB], DP2[i] + SA - SB);
    }
    if (i + BB <= M){
      DP2[i + BB] = max(DP2[i + BB], DP2[i] + BA - BB);
    }
  }
  
  ll ans = 0;
  for (ll i = 0; i <= M; i++){
    ans = max(ans, DP2[i] + i);
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)
const long double PI = 3.141592653589793238L;

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 4e5 + 9, M = 5e3 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;



int main(){
    init();

    int R;  cin >> R;
    cout << fixed << setprecision(10) << 2.0 * PI * R;

}

Measured memory_bytes: 3800
import java.io.*;
import java.util.*;
import java.math.*;
class Main{
    public static void main(String[] args){
	BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
	try {
	    while(true){
		long z = Integer.valueOf(sc.readLine());
		if(z==0)
		    break;
		long mulz = z*z*z;
		long max = 0;
		for(long i=1; i<z; i++)
		    for(long j=1; j<z; j++){
			long tmp = i*i*i+j*j*j;
			if(tmp<mulz)
			    max = Math.max(max,tmp);
		    }
		System.out.println(mulz-max);
	    }
	}catch(Exception e){
	    System.out.println("Error");
	}
    }
}

Measured memory_bytes: 9484
N, K = map(int, input().split())
tmp = input().split()
P = [int(tmp[i]) for i in range(N)]
max_sum = 0
for i in range(K):
    max_sum += P[i]

tmp_sum = max_sum
for i in range(K,N):
    tmp_sum -= P[i-K]
    tmp_sum += P[i]
    if tmp_sum > max_sum:
        max_sum = tmp_sum


ret = max_sum/2 + K/2
print(ret)


Measured memory_bytes: 25188
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define lcm( a, b ) ((a)/__gcd(a,b)*(b))
#define MP make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef pair< LL, LL > L_P;

const int INF = INT_MAX;
const int MIN = INT_MIN;
const LL LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const int SIZE = 100005;

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

    vector< P > v(SIZE);
    int n, m;
    cin >> n >> m;
    for( int i = 0; i < SIZE; ++i ) v[i].F = 0, v[i].S = 1;
    v[1].F = 1;
    for( int i = 0; i < m; ++i ) {
        int x, y;
        cin >> x >> y;
        if( v[x].F == 1 ) {
            if( v[x].S == 1 ) {
                v[x].F = 0;
                v[x].S = 0;
                ++v[y].S;
                v[y].F = 1;

            } else {
                --v[x].S;
                ++v[y].S;
                v[y].F = 1;

            }
        } else {
            --v[x].S;
            ++v[y].S;

        }
    }

    int res = 0;
    for( int i = 1; i <= n; ++i ) {
        if( v[i].F ) ++res;

    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr LL M = 1e9+7;
LL inv(LL a,LL p){
    return a==1?1:(p-p/a)*inv(p%a,p)%p;
}
LL C(LL n, int k){
	if(n<k) return 0;
	if(k==0) return 1;
	LL r = 1;
	for(int i=0;i<k;++i){
		r = r*(n-i)%M*inv(i+1,M)%M;
	}
	return r;
}
int main() {
	//freopen("in","r",stdin);
	std::ios::sync_with_stdio(false);std::cin.tie(nullptr);
	int cas;
	cin >> cas;
	while(cas--){
		LL n ,r = 0;
		cin >> n;
		for(int i=(n+1)%2;i<=11;i+=2) {
			r+=C(11,i)*C((n-i+25)/2,15)%M;
		}
		cout<<r%M<<endl;
	}
	return 0;
}

Measured memory_bytes: 3652
open System.Collections.Generic

type Scanner() = class
    let mutable hold = [||]
    let mutable index = 0
    member public this.Next() =
        if hold.Length > index
        then 
            index <- index + 1
            hold.[index - 1]
        else
            let mutable st = stdin.ReadLine()
            while st = "" do st <- stdin.ReadLine()
            hold <- st.Split(' ')
            if hold.Length = 0
            then
                this.Next()
            else
                index <- 1
                hold.[index - 1]
            
    member public this.NextI32() =
        this.Next() |> int

    member public this.ArrayI32(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextI32()|]

    member public this.NextI64() =
        this.Next() |> int64
    
    member public this.ArrayI64(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextI64()|]

    member public this.NextF32() =
        this.Next() |> float32
    
    member public this.ArrayF32(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextF32()|]

    member public this.NextF64() =
        this.Next() |> double
    
    member public this.ArrayF64(n: int) =
        [|for _ in 0 .. n - 1 -> this.NextF64()|]

    member public __.Tuple2Array n (f : int -> 'a list) =
        [|for _ in 0 .. n - 1 -> f 2 |> fun x -> x.[0], x.[1]|]
    
    member public __.Tuple3Array n (f : int -> 'a list) =
        [|for _ in 0 .. n - 1 -> f 3 |> fun x -> x.[0], x.[1], x.[2]|]

    member public __.CountDic n (f : unit -> 'a) =
        let seqs = seq {for _ in 0 .. n - 1 -> f()}
        let dic = new Dictionary<'a, int64>();
        for i in seqs do
            if dic.ContainsKey(i)
            then dic.[i] <- dic.[i] + 1L
            else dic.Add(i, 1L)
        dic

end

type Ordering =
    | LT = -1
    | EQ = 0
    | GT = 1

[<EntryPoint>]
let main _ =
    let scanner = Scanner()
    let n = scanner.NextI32()
    let arr = scanner.ArrayI64(n)
    let order a b = if a > b then Ordering.GT else if a < b then Ordering.LT else Ordering.EQ
    let ff b bb = if b = bb || b = Ordering.EQ || bb = Ordering.EQ then 0L else 1L
    let rec f b c =
        function
        | [] -> c
        | (x,y)::xs -> 
            let ord = order x y
            if ord = Ordering.EQ
            then
                f b c xs
            else
                let ad = ff b ord
                f (if ad = 1L then Ordering.EQ else ord) (c + ad) xs
 
    if (Array.length arr) < 2
    then 1L
    else
        let pairs = Array.pairwise arr
        let (x, y) = pairs.[0]
        Array.toList pairs
        |> f (order x y) 1L
    |> printfn "%i"
    
    0


Measured memory_bytes: 34140
#!/usr/bin/env python3
import sys


def solve(a: int):
    print(a+a**2+a**3)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    solve(a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9184
n,m,k = map(int,input().split())
def nCr(n,r,fac,finv):
    mod = 998244353
    ans = fac[n] * (finv[r] * finv[n-r] % mod) % mod
    return ans
ans = 0
mod = 998244353
fac = [1,1]+[0]*n
finv = [1,1]+[0]*n
inv = [1,1]+[0]*n
for i in range(2,n+1):
    fac[i] = fac[i-1] * i % mod
    inv[i] = mod - inv[mod%i] * (mod//i) % mod
    finv[i] = finv[i-1] * inv[i] % mod
for i in range(k+1):
    ans += m*pow(m-1,n-1-i,mod)*nCr(n-1,i,fac,finv) % mod
    ans %= mod
print(ans)


Measured memory_bytes: 34096
#pragma region noncode
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SORT(v) sort(all(v))
#define TROS(v) sort(all(v), std::greater<Type>());
#pragma endregion

int main() {
    // template
    int a,b,c,d;cin>>a>>b>>c>>d;
    if(abs(a-b)<=d && abs(b-c)<=d || abs(a-c)<=d) cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m=0,N;cin>>n;
  N=n;
  while(N>0){
    N/=10;
    m+=1;
  }
  if(m==1)cout<<n<<endl;
  if(m==2)cout<<9<<endl;
  if(m==3)cout<<n-90<<endl;
  if(m==4)cout<<909<<endl;
  if(m==5)cout<<n-9090<<endl;
  if(m==6)cout<<90909<<endl;
}
  
      
    
    
    


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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/d.in", "r", stdin);
//  freopen("../IO/d.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}

constexpr int MOD = (int)1e9 + 7;

void solve(std::istream &in, std::ostream &out) {
  int n, k;
  in >> n >> k;
  vector<int> sm(n + 1, 0);
  for (int i = 1; i <= n; ++i) {
    sm[i] = (sm[i - 1] + i) % MOD;
  }
  int ans = 0;
  for (int i = n; i >= k - 1; --i) {
    int minsum = sm[i];
    int maxsum = sm[n];
    if (i < n) maxsum = (maxsum + MOD - sm[n - i - 1]) % MOD;
    ans = ((ans + maxsum) % MOD + MOD  - minsum + 1) % MOD;
  }
  cout << ans << '\n';
}



Measured memory_bytes: 3928
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, m, cur = 0;
string s;
vector<ll> ans;

int main() {
	cin >> n >> m;
	cin >> s;
	cur = n;
	while (cur > 0) {
		bool flag = false;
		for (int i = max(cur - m, (ll)0); i < cur; i++) {
			if (s[i] == '0') {
				ans.pub(cur - i);
				cur = i;
				flag = true;
				break;
			}
		}
		if (!flag) {
			cout << -1 << endl;
			return 0;
		}
	}
	for (int i = sz(ans) - 1; i >= 0; i--)cout << ans[i] << endl;
	return 0;
}

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

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

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}



void _main() {
        int r; cin >> r;
        cout << 3 * r * r;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

void add(ll &a, ll b) {
    a = (a + b) % mod;
}

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

    string L;
    cin >> L;
    int N = L.size();
    static ll dp[100010][2];
    dp[0][0] = 1;
    rep(i, N) {
        add(dp[i+1][1], 3 * dp[i][1]);
        if (L[i] == '1') {
            add(dp[i+1][0], 2 * dp[i][0]);
            add(dp[i+1][1], dp[i][0]);
        } else {
            add(dp[i+1][0], dp[i][0]);
        }
    }
    cout << (dp[N][0] + dp[N][1]) % mod << endl;
    return 0;
}

Measured memory_bytes: 2000
#include <iostream>
#include <vector>
#include <utility>

int main(){
    int n;
    std::cin >> n;
    std::vector<int> a(n);

    for(auto &&i : a)
        std::cin >> i;

    int count=0;

    bool flag = true;
    while(flag){
        flag = false;
        for(int j=n-1; j>0; j--){
            if(a[j] < a[j-1]){
                std::swap(a[j], a[j-1]);
                flag = true;
                count += 1;
            }
        }
    }

    for(int i=0; i<n; i++){
        std::cout << a.at(i) << ((i == n - 1) ? "\n" : " ");
    }
    std::cout << count << std::endl;
}


Measured memory_bytes: 3104
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define maxn 1005
using namespace std;
int vis[maxn];
long double dis[maxn][maxn];
long double d[maxn];
const long double inf = 1e18;
int n;
struct point
{
	int x, y, r;
}p[maxn];
long double getdis(int i, int j)
{
	long double ans = (long double)sqrt((long double)(p[j].x - p[i].x)*(p[j].x - p[i].x) + (long double)(p[j].y - p[i].y)*(p[j].y - p[i].y)) - (long double)p[i].r - (long double)p[j].r;
	if (ans > (long double)0)
		return ans;
	else
		return (long double)0;
}
void dij(int s)
{
	memset(vis, 0, sizeof(vis));
	for (int i = 0; i < maxn; i++)
		d[i] = dis[0][i];
	for (int i = 0; i <= n + 1; i++)
	{
		int x;
		long minn = inf;
		for (int y = 0; y <= n + 1; y++)
			if (!vis[y] && minn >= d[y])
				minn = d[x = y];
		vis[x] = 1;
		for (int y = 0; y <= n + 1; y++)
			d[y] = min(d[y], d[x] + dis[x][y]);
	}
}
int main()
{
	int x1, y1, x2, y2;
	scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
	scanf("%d", &n);
	p[0].x = x1;	p[0].y = y1;
	p[0].r = 0;
	p[n + 1].x = x2;
	p[n + 1].y = y2;
	p[n + 1].r = 0;
	for (int i = 1; i <= n; i++)
		scanf("%d%d%d", &p[i].x, &p[i].y, &p[i].r);
	for (int i = 0; i <= n; i++)
		for (int j = i + 1; j <= n + 1; j++)
			dis[i][j] = dis[j][i] = getdis(i, j);
	dij(0);
	printf("%.9Lf\n", d[n + 1]);
}


Measured memory_bytes: 19632
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct node{
	struct node*oya,*ko[2];
	char key[30];
	int val,p;
}node;

void rot(node*v,int d){
	node*nnn=v->ko[d];
	
	v->ko[d]=nnn->ko[d^1];
	if(v->ko[d])v->ko[d]->oya=v;
	
	v->oya->ko[v->oya->ko[1]==v]=nnn;
	nnn->oya=v->oya;
	
	nnn->ko[d^1]=v;
	v->oya=nnn;  
}
void ins(node*v,node*oya,int dir,node*n){
	if(!v){
		n->oya=oya;
		oya->ko[dir]=n;
	}else{
		int d=strcmp(v->key,n->key)<0;
		ins(v->ko[d],v,d,n);
		if(v->ko[d]->p > v->p)rot(v,d);
	}
}
node*find(node*v,char*s){
	if(!v)return 0;
	int flag=strcmp(v->key,s);
	if(!flag)return v;
	return find(v->ko[flag<0],s);
}
void del(node*v){
	while(v){
		if(v->ko[0]){
			if(v->ko[1])rot(v,v->ko[1]->p > v->ko[0]->p);
			else rot(v,0);
		}else{
			if(v->ko[1])rot(v,1);
			else v=v->oya->ko[v->oya->ko[1]==v]=0;
		}
	}
}

node root;
int main(){
	int q;
	scanf("%d",&q);
	while(q--){
		int t;
		char s[30];
		scanf("%d%s",&t,s);
		if(t==0){
			int x;
			scanf("%d",&x);
			node*crr=find(root.ko[0],s);
			if(crr){
				crr->val=x;
			}else{
				node*v=calloc(1,sizeof(node));
				memcpy(v->key,s,20);
				v->val=x;
				v->p=rand();
				ins(root.ko[0],&root,0,v);
			}
		}else if(t==1){
			node*v=find(root.ko[0],s);
			printf("%d\n",v?v->val:0);
		}else{
			del(find(root.ko[0],s));
		}
	}
}


Measured memory_bytes: 17356
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
	int n;
	cin >> n;
	vector<ll> a(n);
	ll total = 0;
	ll result = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		total += a[i];
		total %= mod;
	}

	for (int i = 0; i <n-1;i++) {
		total -= a[i];
		if (total <= 0) total += mod;
		result += total * a[i];
		result %= mod;
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 4756
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline long toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline long toLong(string s) {long v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-6;
const long INF = 1e10;


int main(){
	vector<long> sat,prime;
	
	FOR(i,2,300001)if(i%7==1||i%7==6)sat.PB(i);
	
	for(long i=0;i<SZ(sat);i++){
		bool flag=true;
		for(long j=0;sat[j]*sat[j]<=sat[i];j++)if(sat[i]%sat[j]==0)flag=false;
		if(flag)prime.PB(sat[i]);
	}
	long tmp;
	while(cin>>tmp){
		if(tmp==1)break;
		vector<long>res;
		REP(j,SZ(prime))if(tmp%prime[j]==0)res.PB(prime[j]);
		cout<<tmp<<":";
		REP(j,SZ(res))cout<<" "<<res[j];
		cout<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 2504
#include<bits/stdc++.h>
using namespace std;
const int N=3005;
int n,t,dp[N];
struct node
{
    int x,y;
    bool operator<(const node&o)const
    {
        return x<o.x;
    }
}a[N];
int main()
{
    scanf("%d%d",&n,&t);
    for(int i=1;i<=n;i++) scanf("%d%d",&a[i].x,&a[i].y);
    sort(a+1,a+1+n);
    for(int i=1;i<=n;i++)
    {
        for(int j=t-1;j>=0;j--)
        {
            int s=min(j+a[i].x,t);
            dp[s]=max(dp[s],dp[j]+a[i].y);
        }
    }
    int ans=0;
    for(int i=0;i<=t;i++)
        ans=max(ans,dp[i]);
    printf("%d\n",ans);
}


Measured memory_bytes: 256
S=input()
forward=""
back=""
yymm=0
mmyy=0
for i in range(4):
    forward=S[:2]
    back=S[2:]
forward=int(forward)
back=int(back)
if ((1<=forward)and(forward<=12)):
    mmyy=1
if ((1<=back)and(back<=12)):
    yymm=1
if (mmyy==1):
    if (yymm==1):
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if(yymm==1):
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

ll N, K;
ll A[200010], visited[200010];

signed main(){
    cin >> N >> K;
    REP(i, N){
        cin >> A[i];
        A[i]--;
        visited[i] = -1;
    }
    ll index = 0, cnt = 0;
    while(visited[index] == -1){
        visited[index] = cnt;
        cnt++;
        index = A[index];
    }
    //REP(i, N) cerr << visited[i] << " ";
    //cerr << endl;
    if(K < visited[index]){
        REP(i, N){
            if(visited[i] == K){
                PRINT(i + 1);
                return 0;
            }
        }
    }
    //cerr << index << " " << cnt << endl;
    //cerr << (K - visited[index]) % (cnt - visited[index]) << endl;
    REP(i, N){
        if(visited[i] >= visited[index] && (visited[i] - visited[index]) == (K - visited[index]) % (cnt - visited[index])){
            PRINT(i + 1);
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 6744
def main():
    import sys
    import math
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    A, B, N = [int(x) for x in input().strip().split()]
    ans = 0
    for x in range(min(N, B), max(min(N, B)-A-1, -1), -1):
        ans = max(ans, math.floor((A*x)/B)-A*math.floor(x/B), 0)
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9204
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int x,a,b;
    cin>>x>>a>>b;
    if(a>=b)cout<<"delicious"<<endl;
    else if(b-a<=x)cout<<"safe"<<endl;
    else cout<<"dangerous"<<endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
	"strconv"
)

func main() {
	N := readInt()
	A := make([]*big.Int, N)
	for i := 0; i < N; i++ {
		A[i] = big.NewInt(int64(readInt()))
	}

	t := new(big.Int)

	v := big.NewInt(1)
	for i := 0; i < N; i++ {
		t.GCD(nil, nil, v, A[i])
		v.Mul(v, A[i])
		v.Div(v, t)
	}

	result := big.NewInt(0)
	for i := 0; i < N; i++ {
		result.Add(result, t.Div(v, A[i]))
	}
	result.Rem(result, big.NewInt(1000000007))

	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 5760