akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define INF 1<<30
#define MOD 1000000007

long frac[200010];

// return x^n mod m
long mod_pow(long x, long n, long m){
    x = x%m;
    long res=1;
    while(n>0){
        if(n&1) res=res*x%m;
        x=x*x%m;
        n>>=1;
    }
    return res;
}


// (h+w)! / h! / w!
long route(int h, int w){
    long res = frac[h+w] * mod_pow(frac[h], MOD-2, MOD) % MOD;
    res = res * mod_pow(frac[w], MOD-2, MOD) % MOD;
    return res;
}

int main(){
    long h,w,a,b;
    cin>>h>>w>>a>>b;

    frac[0]=1;
    repl(i,1,h+w+2){
        frac[i] = i*frac[i-1]%MOD;
    }

    long res=0;
    rep(i,h-a){
        long add = (route(i, b-1) * route(h-i-1, w-b-1)) % MOD;
        res = (res+add)%MOD;
    }

    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 1792
k = list(input())
l = len(k)
if ''.join(k) == ''.join(reversed(k)):
  if ''.join(k[0:int(l//2)]) == ''.join(reversed(k[0:int(l//2)])) and ''.join(k[int(l//2) + 1 : l]) == ''.join(reversed(k[int(l//2) + 1 : l])):
    print('Yes')
  else:
    print('No')
else:
  print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <queue>
using namespace std;
typedef long long int ll;
const int INF = 100000000;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
int main(){
    const int n = 9;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            printf("%dx%d=%d\n", i, j, i*j);
        }
    }
    return 0;
}

Measured memory_bytes: 1096
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n;
  int x;
  int *a;
  cin>>n>>x;
  a=new int[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n);
  int sum=0;
  int count=0;
  for(int i=0;i<n;i++){
    sum+=a[i];
    if(sum>x){
      break;
    }
    count++;
  }
  if(sum<x)count--;
  cout<<count;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define enld endl

int main() {
	int N=4;
	vector<lint>V(4);
	rep(i, 4) {
		cin >> V[i];
	}
	lint ans = 10000000;
	for (int S = 0; S < 1 << N; S++) {
		//作成
		vector<int>A;
		rep(i, N) {
			A.push_back(S >> i & 1);
		}
		//操作
		int cnt = 0;
		lint X = 0, Y = 0;
		rep(i, N) {
			if (A[i] == 0) {
				X += V[i];
				cnt++;
			}
			else {
				Y += V[i];
			}
		}
		if (cnt == 2) {
			ans = min(ans, abs(X - Y));
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3160
#include "bits/stdc++.h"
using namespace std;

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

	cin>>a>>b;
	if(a>=13){
		cout<<b;
	}
	else if(a<=5){
		cout<<0;
	}
	else{
		cout<<b/2;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <numeric>
#include <set>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 999999999
#define MINF -999999999
#define ALL(n) n.begin(),n.end()
ll s[110000], ma,sama;

int main() {
	set<int> a;
	ll m,n,ans = 0;
	cin >> n >> m;
	m /= 2;
	REP(i, n) {
		cin >> s[i];
	}
	REPR(i, n - 1) {
		ma = max(ma, s[i]);
		sama = max(sama, ma - s[i]);
	}
	REP(i, n) {
		a.insert(s[i]);
		if (a.find(s[i] - sama) != a.end()) ans++;
	}
	cout << ans << endl;
}



Measured memory_bytes: 5760
import sys
sys.setrecursionlimit(100000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    s = input()
    t = input()
    if s == t[:-1] and len(t) == len(s) + 1:
        print('Yes')
    else:
        print('No')
         
if __name__ == '__main__':
    main()
    

Measured memory_bytes: 9040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(v) v.begin(), v.end()
#define MOD (int) (1e9+7)
#define INF (int) 1e9
#define LLINF (ll) 1e18

int main(){
    int x, y;
    cin >> x >> y;

    rep(i, x+1){
        if(2*i + 4*(x-i)==y){
            cout << "Yes" << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string S;
	cin >> S;
	if (S == "keyence") {
		puts("YES");
		return 0;
	}
	for (int i = 0; i < S.size() - 1; ++i) {
		for (int j = i + 1; j < S.size(); ++j) {
			string s = S.substr(0, i);
			string t = S.substr(j, S.size() - j);
			if (s + t == "keyence") {
				puts("YES");
				return 0;
			}
		}
	}
	puts("NO");
	return 0;
}

Measured memory_bytes: 256
import math

X = int(input())

# √nまでで判定すればいい
def is_prime(n):
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

while True:
    if is_prime(X):
        print(X)
        exit()

    X = X + 1


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

using namespace std;

int main()
{
	int n,i,max=0,sum=0;
	vector<int> l;
	cin>>n;
	while(cin>>i)
	{
		l.push_back(i);
		if(i>max) max=i;
		sum+=i;
	}
	if(sum-max>max) cout<<"Yes";
	else cout<<"No";	
	return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define TEST int t = 1; while(t--) solve()
vector<vector<int> >G;
vector<bool> visited;
vector<int> parent;
vector<int> siz;
void dfs(int u)
{
	 visited[u]=true;
	 for(auto v:G[u])
	 {
	 	if(!visited[v])
	 	{
	 		 dfs(v);
	 	}
	 	else if(v==0)
	 	{
	 		 parent[u]=0;
	 		 siz[u]=1;

	 	}
	 	else
	 	{
	 		 if(siz[v]+1<siz[u])
	 		 {
	 		 	 siz[u]=siz[v]+1;
	 		 	 parent[u]=v;
	 		 }
	 	}
	 }
}

void solve(){
    
    int n,m;
    cin>>n>>m;
     G.resize(n);
     visited.resize(n,false);
     parent.resize(n,-1);
     siz.resize(n,2*n);
     for(int i=0;i<m;i++)
     {
     	 int u,v;
     	 cin>>u>>v;
     	 u--;
     	 v--;
     	 G[u].push_back(v);
     	 G[v].push_back(u);
     }
   queue<int> q;
vector<bool> used(n);
vector<int> d(n), p(n,-1);

q.push(0);
used[0] = true;
p[0] = -1;
while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int u : G[v]) {
        if (!used[u]) {
            used[u] = true;
            q.push(u);
            d[u] = d[v] + 1;
            p[u] = v;
        }
    }
}

for(int i=1;i<n;i++)
{
	 if(p[i]==-1)
	 {
	 	 cout<<"No\n";
	 	 return;
	 }
}

cout<<"Yes\n";
for(int i=1;i<n;i++)
{
	 cout<<p[i]+1<<"\n";
}

 }

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); TEST; return 0;
}

Measured memory_bytes: 15368
using System;
using System.Linq;

namespace b
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();

            var minVal = int.MaxValue;
            for(var i = 0; i <= s.Length - 3; i++){
                var x = int.Parse(s.Substring(i, 3));
                minVal = Math.Min(minVal, Math.Abs(x - 753));
            }

            Console.WriteLine(minVal);
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;

int main() {
  ll n,k;
  cin>>n>>k;
  int ans=0;
  while(n>0){
    n/=k;
    ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
l.sort()
d=dict()
for i in l:
  if i in d:
    d[i]+=1
  else:
    d[i]=1
#print(d)
li=list(d.keys()) 
ans=0
for i in range(len(li)-1,0,-1):
  a,b=0,i-1
  while(a<b):
    if li[a]+li[b]>li[i]:
      #print(li[a],li[b],li[i])
      for kk in range(a,b):
      	ans+=d[li[kk]]*d[li[b]]*d[li[i]]
      b-=1
    else:
      a+=1
print(ans)

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(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

int main() {
    fastio();

    int a, b;
    cin >> a >> b;

    if (a + b >= 10) {
        cout << "error" << endl;
    } else {
        cout << a + b << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

inline int add_(int x,int y)
{
    return (x + y)%MOD;
}

template<typename V> class BIT {
private:
	int n; vector<V> bit;
public:
	void add(int i,V x){ i++; while(i < n) bit[i] = add_(bit[i], x), i += i & -i;}
	V sum(int i){ i++; V s = 0; while(i>0) s = add_(s, bit[i]), i -= i & -i; return s;} //0_indexedで[0,i]の要素の和
	BIT(){} BIT(int sz){ n = sz + 1, bit.resize(n,0);} //初期値がすべて0の場合
	BIT(vector<V>& v){ n = (int)v.size()+1; bit.resize(n, 0); rep(i,n-1) add(i,v[i]);}
	void print(){ rep(i,n-1)cout<<sum(i)-sum(i-1)<< " ";cout<<endl;}
	void print_sum(){ rep(i,n)cout<<sum(i-1)<<" ";cout<<endl;}	//-1スタート
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vi x(n), y(m);
    vp vec(n+m);
    rep(i,n){
        cin >> x[i];
        vec[i] = P(x[i], 0);
    }
    rep(i,m){
        cin >> y[i];
        vec[i+n] = P(y[i], 1);
    }
    sort(all(vec));
    vi R = {0};
    int pre = -1;
    vi res;
    vp hoge;
    rep(i,n+m){
        if(vec[i].se){
            if(pre > 0){
                each(val,res){
                    hoge.pb(P(val, -(vec[i].fi-pre-val)));
                    R.pb(vec[i].fi-pre-val);
                }
                res.clear();
            }
            pre = vec[i].fi;
        }else{
            if(pre > 0){
                res.pb(vec[i].fi-pre);
            }
        }
    }
    zip(hoge), zip(R);
    BIT<int> bt(len(R)+1);
    bt.add(0, 1);
    each(val,hoge){
        int y = lower_bound(all(R),-val.se)-R.begin();
        bt.add(y,bt.sum(y-1));
    }
    cout << bt.sum(len(R)) << "\n";
    return 0;
}


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

using namespace std;

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

    for (int i = 0; i < str.size(); ++i) {
        if(i%w == 0) cout << str[i];
    }
    cout << endl;

    return 0;
}

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

using namespace std;

class ParseError {};
typedef string::const_iterator State;

bool expression(State &begin) {
	bool ret;
	if(*begin == 'T'){begin++; ret = true;}
	else if(*begin == 'F'){begin++; ret = false;}
	else if(*begin == '-'){begin++; ret = !expression(begin);}
	else {
		begin++;
		bool a = expression(begin);
		if(*begin == '*'){
			begin++;
			ret = a & expression(begin);
		}
		else if(*begin == '-'){
			begin++; begin++;
			ret = (a & !expression(begin) ? false : true);
		}
		else if (*begin == '+') {
			begin++;
			ret = a | expression(begin);
		}
		begin++;
	}
	return ret;
}

int main(){
	string e;
	while(cin >> e, e != "#"){
		bool possible = true;
		for(int i=0; i < 1<<11; i++){
			string s = e;
			string t = "abcdefghijk";
			for(int j=0; j < s.size(); j++){
				for(int k=0; k < t.size(); k++){
					if(s[j] == t[k]) s[j] = ((i >> k) & 1 == 1 ? 'T' : 'F');
				}
			}
			string a, b;
			for(int i=0; i< s.size(); i++) if(s[i] == '='){a = s.substr(0, i); b = s.substr(i+1);}
			State abegin = a.begin();
			State bbegin = b.begin();

			if(!(expression(abegin) == expression(bbegin))){possible = false; break;}
		}
		cout << (possible ? "YES" : "NO") << endl;
	}
}

Measured memory_bytes: 1220
#include "bits/stdc++.h"
using namespace std;

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

constexpr auto inf = 1e9;

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; }

using ll = long long;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n, -1);
	for (auto& x : a)
	{
		cin >> x;
	}

	int maxnum = *max_element(all(a));

	vector<int> tmp(n);
	tmp = a;

	sort(all(tmp));

	for (int i = 0; i < n; i++)
	{
		int ans = 0;

		if (tmp[n-1] == tmp[n-2])
		{
			ans = maxnum;
		}
		else
		{
			if (maxnum == a[i])
			{
				ans = tmp[n - 2];
			}
			else
			{
				ans = maxnum;
			}
		}

		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> Pii;
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1000000000
#define rep(i,a,b) for(int i =(a);i<(b);i++)
#define fs first
#define ss second
inline int Scan() {
    int x=0;int f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}

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

// call by reference is used in x
template<typename T, typename U>
static inline void amax(T &x, U y)
{
    if (x < y)
        x = y;
}
//////////////////////////////////////end of template//////////////////////////////////////

bool dp[90][90][25600];
int a[90][90];

int main(){

   int h,w;
   cin >> h >> w;
   
   int x;
   for(int i =1;i<=h;i++) for(int j =1;j<=w;j++) cin >> a[i][j]; 
   for(int i =1;i<=h;i++) for(int j =1;j<=w;j++) { cin >> x; a[i][j] = abs(a[i][j] -x);};
  
   
   for(int i=0;i<=80;i++) for(int j =0;j<=80;j++) for(int k=0;k<=12800;k++) dp[i][j][k] = false;
   
   
   dp[1][1][a[1][1]] = true;
   
   
   for(int i = 1;i<=h;i++){
	   for(int j =1;j<=w;j++){
         for(int k = 0;k<=12800;k++){
			  if( dp[i][j][k]){
                dp[i][j+1][ k + a[i][j+1]] = true;
	            dp[i][j+1][abs(k - a[i][j+1])] = true;
	            
	            dp[i+1][j][k + a[i+1][j]] = true;
	            dp[i+1][j][abs(k - a[i+1][j])] = true;
	         }   
	      }
       } 
   }
   
   for(int i = 0;i<=12800;i++){
	   if( dp[h][w][i]) {
		   cout << i << endl;
	       break;
	   }
   }
   
  return 0;
  
}




Measured memory_bytes: 183808
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,M;
    while(cin >> N >> M && N){
        vec<int> S(N);
        set<int> s;
        for(auto& x:S) cin >> x;

        int inf = 1e9;
        auto calc = [&](int x){
            int cnt = 0;
            int now = 1;
            while(now+x<=S[N-1]){
                int ma = -1;
                auto it = upper_bound(S.begin(),S.end(),now);
                if(*it<now+x){
                    ma = max(1,x-abs(now-*it));
                }
                if(it!=S.begin()){
                    it--;
                    if(*it<now+x){
                        ma = max(ma,max(x-abs(now-*it),1));
                    }
                }
                if(ma==-1) return inf;
                cnt++;
                now += ma;
            }
            return cnt+1;
        };

        int mi = S[0];
        if(calc(mi)<M){
            cout << -1 << "\n";
            continue;
        }
//        cerr << calc(3) << "\n";
        int l = mi,r = S[N-1];
        while(l+1<r){
            int m = (l+r)/2;
            if(calc(m)>=M) l = m;
            else r = m;
        }
        cout << l << "\n";
    }
}



Measured memory_bytes: 3532
/*
 * 1645025T ????±± ??????
 */

#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;

// dp[i][j] := i??????????¢¨????????§?????????, j????¢¨???????????£???????????¨?????????????????¢
int dp[50][5];

void solve(const int n, const vector<int> & p, const vector<int> & t) {

	for (int i = 0; i < 50; ++i) for (int j = 0; j < 5; ++j) dp[i][j] = INF;
	dp[0][0] = 0; // ?????????????¨????

	for (int i = 1; i <= n + 1; ++i) { // ?????????
		for (int j = 0; j <= 3; ++j) { // ?????¨????¢¨????????°
			if(dp[i - 1][j] == INF) continue;
			// ???????????????????????????
			{
				int dist = p[i - 1] + p[i]; // ?????¢
				int time = p[i - 1] * (j + 1) + p[i]; // ??????
				if(time <= (t[i] - t[i - 1])) { // ????????????
					dp[i][1] = min(dp[i][1], dp[i - 1][j] + dist);
				}
			}
			// ??????????????????
			{
				if(j == 3) continue;
				int dist = abs(p[i] - p[i - 1]); // ?????¢
				int time = abs(p[i] - p[i - 1]) * (j + 1); // ??????
				if(time <= (t[i] - t[i - 1])) { // ????????????
					dp[i][j + 1] = min(dp[i][j + 1], dp[i - 1][j] + dist);
				}
			}
		}
	}

	int ans = INF;
	for (int i = 0; i < 4; ++i) ans = min(ans, dp[n + 1][i]);

	if (ans == INF) {
		// ???????????§?????????????????????
		int idx = 0;
		for (int i = 0; i <= n + 1; ++i) for (int j = 0; j <= 3; ++j) {
			if (dp[i][j] != INF) idx = max(idx, i + 1);
		}
		cout << "NG " << idx << endl;
	} else {
		cout << "OK " << ans << endl;
	}
}

int main(void) {

	while(1) {
		int n; cin >> n;
		if(n == 0) break;
		vector<int> p(n + 2), t(n + 2);

		p[0] = t[0] = 0; // ???????????????????????????
		for (int i = 1; i < n + 1; ++i)  cin >> p[i] >> t[i];
		p[n + 1] = 0, t[n + 1] = INF; // ???????????????

		solve(n, p, t);
	}

	return 0;
}

Measured memory_bytes: 2972
#include<bits/stdc++.h>
#define sf1(n) scanf("%d",&n)
#define sf2(n,q) scanf("%d %d",&n,&q)
#define f first
#define ss second
#define pb push_back
#define lli long long
#define mem(ar,false) memset(ar,false,sizeof(ar))
#define mpr make_pair
#define endl "\n"
#define mod 1000000007
#define inf 9000000000000000000LL
#define M 200005

using namespace std;


int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    if(s.back()!='s')
        s.pb('s');
    else s+="es";
    cout <<s  << endl;

    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n, m;
vector<lli> x;
int main() {
  cin >> n >> m; read_n(x, m);
  if (m==1) { cout << 0 << endl; return 0; }
  sort(begin(x), end(x));
  vector<lli> d(m-1);
  for (lli i=0; i<m-1; ++i) {
    d[i] = x[i+1] - x[i];
  }
  sort(begin(d), end(d));
  lli ans = 0;
  for (lli i=0; i<m-n; ++i) ans += d[i];
  cout << ans << endl;
  return 0;
}



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

int main() {
    string s, t;
    cin >> s >> t;
    ll ans = 0;
    for(ll i = 0; i < s.length(); i++){
        if(s[i] == t[i]) ans++;
    }

    cout << ans << endl;

    
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int A , B;
    cin>>A>>B;
    if(0<=A<=100&&2<=B<=1000&&B%2==0)
    {
        if(A<6)
        {
            B=0;
            cout<<B<<endl;
        }
        else if(6<=A&&A<=12)
        {
            B=0.5*B;
            cout<<B<<endl;
        }
        else if(A>=13)
        {
            cout<<B<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 384
# coding: utf-8
#ABC106B_105.rb
n = gets.to_i
count = 0
ans = 0

(1..n).each do |nn|
  count = 0
  (1..nn).each do |mm|
    if nn % mm == 0
      count += 1
    end
  end
  ans += 1 if count==8 && nn%2==1
end

puts ans



Measured memory_bytes: 1788
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
  
using namespace std;
 
struct tree{
    int node;
    tree *left;
    tree *right;
    tree *parent;
};
 
typedef struct tree T;
 
void insert(T *t)
{
    T *insert_node, *nownode;
    insert_node = (T *)malloc(sizeof(T));
    cin >> insert_node->node;
    insert_node->parent = NULL;
    insert_node->left = NULL;
    insert_node->right = NULL;
    if(t->left == NULL && t->right == NULL){
        t->left = insert_node;
    }
    else {
        insert_node->parent = t;
        nownode = t->left;
        bool isleft = true;
        while(nownode != NULL){
            insert_node->parent = nownode;
            if(nownode->node > insert_node->node) {
                nownode = nownode->left;
                isleft = true;
            }else {
                nownode = nownode->right;
                isleft = false;
            }
        }
        if(isleft) (insert_node->parent)->left = insert_node;
        else (insert_node->parent)->right = insert_node;}
    return;
}

bool find(T *t, int k)
{
    if(t == NULL) return false;
    else if(t->node == -1) return find(t->left, k);
    else if(t->node == k) return true;
    else if(t->node < k) return find(t->right, k);
    else return find(t->left, k);
}
 
void inorder(T *t)
{
    if(t == NULL) return;
    inorder(t->left);
    if(t->node != -1) cout << " " << t->node;
    inorder(t->right);
}
 
void preorder(T *t)
{
    if(t == NULL) return;
    if(t->node != -1) cout << " " << t->node;
    preorder(t->left);
    preorder(t->right);
}
 
void print(T *t)
{
    inorder(t);
    cout << endl;
    preorder(t);
    cout << endl;
}
 
int main()
{
    T *root_p;
    root_p = (T *)malloc(sizeof(T));
    root_p->node = -1;
    root_p->left = NULL;
    root_p->right = NULL;
    root_p->parent = NULL;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        string meirei;
        cin >> meirei;
        if(meirei == "insert") insert(root_p);
        else if(meirei == "print") print(root_p);
        else if(meirei == "find"){
            int key;
            cin >> key;
            if(find(root_p, key)) cout << "yes" << endl;
            else cout << "no" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 19964
import sys
import itertools
import math


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    k = [i for i in range(1, int(readline()) + 1)]
    t = 0
    for v in itertools.product(k, repeat=3):
        t += math.gcd(math.gcd(v[0], v[1]), v[2])
    print(t)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 67644
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ABC073 D - joisino's travel
  int N, M, R; cin >> N >> M >> R;
  vector<int> r(R, 0);
  REP(i, R){
    int tmp; cin >> tmp; tmp--;
    r[i] = tmp;
  }
  sort(r.begin(), r.end());
  int INF = 1e8;
  vector<vector<int> > dp(N, vector<int>(N, INF));
  REP(i, M){
    int a, b, c; cin >> a >> b >> c; a--; b--;
    dp[a][b] = c; dp[b][a] = c;
  }
  REP(i, N) dp[i][i] = 0;
  
  // ワーシャルフロイド法
  REP(k, N) REP(i, N) REP(j, N){
    dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]);
  }
  
  int ans = INF;
  do{
    int cst = 0;
    REP(i, R-1){
      cst += dp[r[i]][r[i+1]];
    }
    ans = min(ans, cst);
  }while(next_permutation(r.begin(), r.end()));
  
  cout << ans << endl;
}

Measured memory_bytes: 384
function main(input) {
  var x = parseInt(input.split("\n")[0], 10);

  var hoge = [];
  for (var i = 0; i < 150; i++) {
    hoge.push(Math.pow(i, 5));
  }
  var fuga = hoge.concat();

  for (var i = 0; i < hoge.length; i++) {
    for (var j = 0; j < fuga.length; j++) {
      var a5 = hoge[i];
      var b5 = fuga[j];
      
      if (a5 - b5 == x) {
        console.log(i + " " + j);
        return;
      }

      b5 = b5 * -1;
      if (a5 - b5 == x) {
        console.log(i + " " + "-" + j);
        return;
      }
    }
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// chmax, chmin
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;
}


vector<int> g[10010];
vector<long long> cc;

vector<int> res;

void dfs(int r, int p = -1) {
    res[r] = cc.back();
    cc.pop_back();
    for (auto i : g[r]) {
        if (p == i) continue;
        dfs(i, r);
    }
}

void solve(long long N, std::vector<long long> a, std::vector<long long> b,
           std::vector<long long> c) {
    cc = c;
    for (int i = 0; i < N - 1; i++) {
        a[i]--;
        b[i]--;
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }
    res.resize(N);
    sort(cc.begin(), cc.end());
    dfs(0);

    cout << accumulate(c.begin(), c.end(), 0ll) - *max_element(c.begin(), c.end()) << endl;
    for(int i = 0 ; i < N ; i++){
        cout << res[i] << (i + 1 == N ? "\n" : " ");
    }
}

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


Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define ll long long
#define INF 1000000000
#define getc(x) scanf("%s",x+1);
#define rep(i,x,y) for(register int i=x;i<=y;++i)
using namespace std;
const int N=15;
int n,m,X,ans=INF,vis[N];
int c[N],a[N][N],b[N];
inline int read()
{
	int x=0,ff=1;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();}
	while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*ff;
}

inline bool check()
{
	memset(b,0,sizeof(b));
	rep(i,1,n)
	{
		if(vis[i]) 
		{
			rep(j,1,m) b[j]+=a[i][j];
		}
	}
	rep(i,1,m) if(b[i]<X) return false;
	return true;
}

inline void dfs(int x,int v)
{
	if(v>ans) return;
	if(x==n) 
	{
		if(check()) ans=min(ans,v);
		return;
	}
	dfs(x+1,v);
	vis[x+1]=1;
	dfs(x+1,v+c[x+1]);
	vis[x+1]=0;
}

int main()
{
//	freopen("1.in","r",stdin);
	n=read(),m=read(),X=read();
	rep(i,1,n)
	{
		c[i]=read();
		rep(j,1,m) a[i][j]=read();
	}
	dfs(0,0);
	printf("%d",ans==INF?-1:ans);
	return 0;
}


Measured memory_bytes: 3760
//File Name: B.cpp
  //Author: long
  //Mail: 736726758@qq.com
  //Created Time: 2016年10月24日 星期一 19时38分00秒
                                   
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
int a[105];
int solve(int k,int n){
	int res = 0,pre = 0,m1,m2;
	while(k){
		m1 = m2 = 0;
		for(int i=1;i<=n;i++){
			if(a[i] > a[m1]) m2 = m1,m1 = i;
			else if(a[i] > a[m2]) m2 = i;
		}
		if(m2 == 0){
			if(m1 == pre)  res++;
			pre = m1;
			a[m1]--;
		}
		else if(m1 == pre){
			a[m2]--;
			pre = m2;
		}
		else{
			a[m1]--;
			pre = m1;
		}
		k--;
	}
	return res;
}
int main(){
	int k,n;
	cin >> k >> n;
	for(int i=1;i<=n;i++)
		cin >> a[i];
	cout << solve(k,n) << endl;
	return 0;
}

Measured memory_bytes: 256
N,M,Q = map(int,input().split())
A = [[0 for _ in range(N+1)] for _ in range(N+1)]
for _ in range(M):
    L,R = map(int,input().split())
    A[L][R] += 1
dp = [[0 for _ in range(N+1)] for _ in range(N+1)]
dp[1][1] = A[1][1]
for j in range(2,N+1):
    dp[1][j] = A[1][j]+dp[1][j-1]
for i in range(2,N+1):
    dp[i][1] = A[i][1]+dp[i-1][1]
for i in range(2,N+1):
    for j in range(2,N+1):
        dp[i][j] = A[i][j]+dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]
for _ in range(Q):
    p,q = map(int,input().split())
    if p==1:
        cnt = dp[N][q]
    else:
        cnt = dp[N][q]-dp[p-1][q]
    print(cnt)

Measured memory_bytes: 62428
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

int main(void){
	ll l, r, d;
	cin >> l >> r >> d;
	ll ans = 0;
	REPN(i, l, r){
		if (i % d == 0) ans++;
	}
	co(ans);

	return 0;
}


Measured memory_bytes: 3648
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    N, K, X, Y = [int(input()) for _ in range(4)]

    if N <= K:
        print(N * X)
    else:
        print(K * X + (N - K) * Y)


main()


Measured memory_bytes: 4644
#include <bits/stdc++.h>
using namespace std;
long double a, b, x, c, angle;
#define PI 3.14159265359
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
	cin >> a >> b >> x;
	if (2*x>(a*a*b)) {
		x = (a*a*b)-x;
		c=(2*x)/(a*a*a);
		angle = atan(c) * 180/PI;
		printf("%Lf", angle);
	}
	else {
		c=(a*b*b)/(2*x);
		angle = atan(c) * 180/PI;
		printf("%Lf", angle);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <cstring>
using namespace std;
#define ref goto refrain
int main(){
	char str[256];
	refrain:
	cin>>str;
	if(str[0]=='-') return 0;
	int a=strlen(str);
	int m;
	cin>>m;
	int b,c;
	for(int i=0;i<m;i++){
		cin>>b;
		char temp[b];
		for(int j=0;j<b;j++){
			temp[j]=str[j];
		}
		c=0;
		for(int j=b;j<a;j++){
			str[c]=str[j];
			c++;
		}
		c=0;
		for(int j=a-b;j<a;j++){
			str[j]=temp[c];
			c++;
		}
	}
	cout<<str<<endl;
	ref;
}
		
	

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define int long long
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB(x) push_back(x)
#define MP make_pair
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) max_element(x.begin(),x.end())
#define MIN(x) min_element(x.begin(),x.end())
#define couty cout<<'Y'<<'e'<<'s'<<endl
#define coutn cout<<'N'<<'o'<<endl
#define coutY cout<<'Y'<<'E'<<'S'<<endl
#define coutN cout<<'N'<<'O'<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;
//fixed<<setprecision(15);

int h,w;
vstr s;
int dist[51][51];

void bfs(){
    dist[0][0]=0;
    queue<P> que;
    que.push(P(0,0));
    while(!que.empty()){
        int y=que.front().first;
        int x=que.front().second;
        que.pop();
        rep(i,4){
            int ny=y+dy[i];
            int nx=x+dx[i];
            if(ny<0||ny>=h||nx<0||nx>=w||s[ny][nx]=='#'||dist[ny][nx]!=-1) continue;
            dist[ny][nx]=dist[y][x]+1;
            que.push(P(ny,nx));
        }
    }
}

signed main(){
    cin >> h >> w;
    s.resize(h);
    rep(i,h)rep(j,w)dist[i][j]=-1;
    rep(i,h) cin >> s[i];
    int white=0,black=0;
    rep(i,h){rep(j,w){if(s[i][j]=='.') white++; else black++;}}
    bfs();
    if(dist[h-1][w-1]==-1) cout<<-1<<endl;
    else cout<<white-dist[h-1][w-1]-1<<endl;
}

Measured memory_bytes: 256
import math
n = int(input())
m = n**0.5
ans = 1
x = 0 #確認
#print(n)
#print(m)
for i in range(1,math.floor(m)+1):
    x += 1 #確認
    if n%i==0:
        ans = i

print(math.floor(ans+ n/ans -2))

Measured memory_bytes: 3188
n = int(input())
a = list(map(int, input().split()))
min = 1000000
max = -1000000
sum = 0
for i in range(n):
    if a[i] < min:
        min = a[i]
    if a[i] > max:
        max = a[i]
    sum += a[i]
print(min, max, sum)


Measured memory_bytes: 6592
### ABC087B - Coins
a = int(input())
b = int(input())
c = int(input())
x = int(input())
cnt = 0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i+100*j+50*k == x:
                cnt += 1
print(cnt)

Measured memory_bytes: 40176
#include<stdio.h>
#include <string>
#include <sstream>

void solve(int c, int d)
{
	int num=0;
	for (int i=0; i<d; i++){
		num = c + num * 10;
	}

	std::ostringstream oss;
	oss<<num;

	printf("%s\n", oss.str().c_str());
}

int main()
{
	int a,b;
	scanf("%d %d", &a, &b);

	if (a>=b) solve(b, a);
	else solve(a, b);

	return 0;
}

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

main() {
  int N;
  cin >> N;
  int S=0;
  int dig,num;
  num =N;
  while(num){
    dig= num%10;
    S+= dig;
    num /= 10;
  }
  if(N%S ==0)
    cout << "Yes";
  else
    cout << "No";
  return 0;
}  
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);

void solve(){
    ll n; cin >> n;
    string s; cin >> s;
    ll numr = 0, numg = 0, numb = 0;
    REP(i,n){
        if(s[i] == 'R') numr++;
        if(s[i] == 'G') numg++;
        if(s[i] == 'B') numb++;
    }
    ll res = numr*numg*numb;
    
    REP(i, n){
        for(int j=i+1; j<n; j++){
            int k=j+(j-i);
            if(k < n){
                char c1 = s[i];
                char c2 = s[j];
                char c3 = s[k];
                if(c1 != c2 && c2 != c3 && c3 != c1){
                    res--;
                }
            }
        }
    }
    cout << res << endl;
}

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

Measured memory_bytes: 3656
#include <iostream>
#include <string>
using namespace std;
int check(char b){
    if(b=='A'||b=='C'||b=='G'||b=='T') return 1;
    else return 0;
}
int main(void){
    string S;
    cin>>S;
    bool counter_started=0;
    int max=0,count;
    for(int i=0;i<S.size();i++){
        if(counter_started==0) count=0;
        if(check(S[i])){
            counter_started=1;
            count++;
        }
        if(count>max) max=count;
        if(check(S[i+1])==0) count=0;
    }
    cout<<max<<endl;
}


Measured memory_bytes: 256
import math
N = int(input())
# N = A*Bに変形したいが、A,Bの組み合わせはいくつかあるはず。
# 50なら、(1,50)(2,25)(5,10)(10,5)(25,2)(50,1)
# 基本的に、順に並べた時に真ん中にあるやつが一番A,Bの間に桁数の差がない。なのでこれを使えば最小値は求められそう。
# 7*7 < 50 < 8*8 なので、検索範囲はsqrt(50)まで。
# そうすると、1<=  N <= 10**10 なので、検索範囲を10**5まで減らせる。あとは全部やればいい


def f(a, b):
    return len(a) if len(a) >= len(b) else len(b)


ans = float('inf')
for a in range(1, int(math.sqrt(N)) + 1):
    if N % a != 0:
        continue
    b = int(N / a)
    a = str(a)
    b = str(b)
    # print(a, b)
    ans = min(ans, f(a, b))
print(ans)


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

int main(int argc, char const *argv[]) {
    int n;
    cin >> n;
    vector<int> h(n);
    for (size_t i = 0; i < n; i++) cin >> h[i];

    bool ok = false;
    for (int i = n-2; i >= 0; i--) {
        if (h[i] > h[i+1]) {
            h[i]--;
            if (h[i] > h[i+1]) break;
        }

        if (i == 0) ok = true;
    }

    if (ok || n == 1) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3800
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Sagor
 */

#include <fstream>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define gap                        ' '
#define EPS                        1e-9
#define P_INF                      2e9+17
#define N_INF                     -2e9-17
#define MOD                        1000000007
#define PI                         2*acos(0.0)
#define All(x)                     x.begin(),x.end()
#define Mem(Name, type)            memset(Name, type, sizeof(Name))

template<typename T>
T GCD(T a, T b) { return a ? GCD(b % a, a) : b; }

template<typename T>
T LCM(T a, T b) { return (a * b) / GCD(a, b); }

template<typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
    for (auto ob : v) os << ob << " ";
    return os;
}

template<typename T, typename S>
std::ostream &operator<<(std::ostream &os, const std::map<T, S> &v) {
    for (auto ob : v) os << ob.first << " : " << ob.second << std::endl;
    return os;
}

using ld = double;
using ll = long long int;
using ul = unsigned long long int;
using namespace std;

class BMultipleOf9 {
public:
    void solve(std::istream &in, std::ostream &out) {
        string s;
        in >> s;
        ll sum = 0;
        for (char x : s) {
            sum += x - '0';
        }
        if (sum % 9 == 0) {
            out << "Yes" << endl;
        } else {
            out << "No" << endl;
        }
    }
};


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    BMultipleOf9 solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3784
a=input().split(" ")
n=int(a[0])
m=int(a[1])
b=input().split(" ")
num=[]
total=0
for i in range(n):
    num.append(int(b[i]))
    total+=int(b[i])
num=sorted(num,reverse=True)

if num[m-1]>=total/(m*4):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
typedef long long ll;
ll n,k;
ll Plus(ll x){
  if(x>0) return x;
  else return 0;
}
int main(){
  cin >> n >> k;
  ll res=0;
  if(k==0) res=n*n;
  else{
    res+=(n-k)*(n-k+1)/2;//a<b
    for(ll i=1;i<=n;i++){
      res+=Plus(i-k)*((n-i+1)/i)+Plus((n-i+1)%i-k);
    }
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define f first
#define s second
typedef long long ll;
typedef unsigned long long ull;

void IO(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("test.txt","r",stdin);
    #endif
}

const int N=1e6+3,M=1e3+5,mod=1e9+7,dx[]={1,-1,0,0},
                                    dy[]={0,0,1,-1};
const double eps=1e-9;


int tc,n;

char s[N];

int main(){
    //IO();
    ll a,b,n;
    scanf("%lld%lld%lld",&a,&b,&n);
    ll x = min(b-1,n);
    x = (a*x)/b - a * (x/b);
    printf("%lld\n",x);
}


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

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

int main()
{
    int N;
    cin >> N;
    int Ci[N], Si[N], Fi[N];
    rep(i, N - 1)
    {
        cin >> Ci[i] >> Si[i] >> Fi[i];
    }
    rep(i, N)
    {
        int total = 0;
        for (int j = i; j < N - 1; j++)
        {
            int start = 0;
            if (total <= Si[j])
            {
                start = Si[j];
            }
            else
            {
                int d = total - Si[j];
                start = d / Fi[j];
                if (d % Fi[j] > 0) {
                    start += 1;
                }
                start *= Fi[j];
                start += Si[j];
            }
            total = start + Ci[j];
        }
        cout << total << endl;
    }
    return 0;
}

Measured memory_bytes: 256