akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int N = 0;
    int M = 0;
    cin >> N >> M;
    vector<int> s;
    vector<int> c;
    vector<int> result(N, 0);
    for (int i = 0; i < M; ++i) {
        int sinput = 0;
        int cinput = 0;
        cin >> sinput >> cinput;
        s.push_back(sinput);
        c.push_back(cinput);
        result[sinput - 1] = cinput;
    }
    if (result[0] == 0 && N != 1) {
        result[0] = 1;
    }
    
    
    bool ok = true;
    if (result[0] == 0 && N != 1) {
        ok = false;
    }
    for (int i = 0; i < M; ++i) {
        if (result[s[i] - 1] != c[i]) {
            ok = false;
            break;
        }
    }
    if (ok) {
        for (int i = 0; i < N; ++i) {
            cout << result[i];
        }
        cout << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
sx,sy,tx,ty = map(int,input().split())

yl = ty - sy
xl = tx - sx

ans = ''
ans += 'U'*yl
ans += 'R'*xl
ans += 'D'*yl
ans += 'L'*(xl+1)
ans += 'U'*(yl+1)
ans += 'R'*(xl+1)
ans += 'DR'
ans += 'D'*(yl+1)
ans += 'L'*(xl+1)
ans += 'U'

print(ans)

Measured memory_bytes: 3064
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    if(b%a==0){
        cout << a+b << endl;
    }else{
        cout << b-a << endl;
    }



    return 0;
}

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

using i64 = long long;
using P = pair<i64, i64>;

vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}


void solve(long long X){
    auto mp = prime_table(200000);
    for(int i = X; i < 200000; ++i){
        if(mp[i]){
            cout << i << endl;
            return;
        }
    }
}

int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;


/**
 * Created by Seiya on 2016/10/16.
 */

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();

        String[] s = new String[103];

        for (int i = 0; i < n; i++) {
            s[i] = scanner.next();
        }


        for (int i = 0; i < m+ 2; i++) {
            System.out.print("#");
        }
        System.out.println();
        for (int i = 0; i < n; i++) {
            System.out.println("#" + s[i] +"#");
        }
        for (int i = 0; i < m + 2; i++) {
            System.out.print("#");
        }
        System.out.println();





    } // mainMethod


} // MainClass


Measured memory_bytes: 21716
#include<stdio.h>
#include<math.h>

int main() {

	int a, b, C;
	double S, L, h,pai,rad,c;

	pai = acos(-1);

	scanf("%d %d %d", &a, &b, &C);

	rad = 2 * pai * C / 360;

	S = a * b * sin(rad) / 2;

	c = (a * a) + (b * b) -( 2 * a * b * cos(rad));

	L = a + b + sqrt(c);

	h = 2 * S / a;

	printf("%f\n%f\n%f\n", S, L, h);

	return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

int main() {
	int n;
	cin>>n;
	if(n>=1000){
		n-=999;
		cout<<"ABD";
	}else{
		cout<<"ABC";

	}
}

Measured memory_bytes: 3620
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		long have = sc.nextLong();
		long want[] = new long[num];
		for(int i = 0; i < num; i ++) {
			want[i] = sc.nextLong();
		}
		Arrays.sort(want);
		int ans = 0;
		long tmp = 0;
		for(int i = 0; i < num; i ++) {
			tmp += want[i];
			if(tmp <= have) {
				ans ++;
			}else {
				break;
			}
			if(i == num - 1 && tmp < have) {
				ans --;
				break;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
n, m = gets.split.map(&:to_i)
# as = Array.new(n)
# bs = Array.new(n)
abs = Array.new(n)
n.times do |i|
  # as[i], bs[i] = gets.split.map(&:to_i)
  abs[i] = gets.split.map(&:to_i)
end

abs.sort! {|(a1,b1),(a2,b2)| a1<=>a2}

# puts abs.inspect
ans = 0
abs.each do |a, b|
  buyc = [m, b].min
  m -= buyc
  ans += buyc * a
  if m == 0
    break
  end
end
puts ans


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

#define For(i, l, r) for (register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for (register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Rep(i, r) for (register int i = (0), i##end = (int)(r); i < i##end; ++i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl

using namespace std;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
    int x(0), sgn(1); char ch(getchar());
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
    for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
    return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("C.in", "r", stdin);
	freopen ("C.out", "w", stdout);
#endif
}

int main() {

	File();

	int x = read(), sum = 0;
	For (i, 1, 1e5)
		if ((sum += i) >= x) return printf ("%d\n", i), 0;

	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

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

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

inline double nCr(const int n, int r)
{

    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

//----------------------------------------------------------------

int main()
{
    ll n, m;
    cin >> n >> m;
    if (n >= 2 && m >= 2)
    {
        cout << (n - 2) * (m - 2) << endl;
    }
    else if (n == 1 && m == 1)
    {
        cout << "1" << endl;
    }
    else if (n == 1)
    {
        cout << m - 2 << endl;
    }
    else if (m == 1)
    {
        cout << n - 2 << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int x,y;
    for(int i=0;;i++){
        scanf("%d %d",&x,&y);
        if(x ==0 && y ==0){
            break;
        }
        if(x > y){
            printf("%d %d\n",y,x);
        }else{
            printf("%d %d\n",x,y);
        }
    }
}


Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>

using namespace std;
/*
int find(int x, vector<int> &p) {
if (p[x] == x)return x;
return p[x] = find(p[x], p);
}

void uni(int x, int y, vector<int> &p) {
x = find(x, p);
y = find(y, p);
p[x] = y;
}

int same(int x, int y, vector<int> p) {
if (find(x, p) == find(y, p))return 1;
return 0;
}
*/

int main()
{
	int N, S=0;

	cin >> N;

	int n = N;

	while (n != 0) {
		S += (n % 10);
		n /= 10;
	}

	if (S != 0 && N % S == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


	char qq;
	cin >> qq;
	return 0;
}

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

int main(){
    long long int k;
    cin>>k;
    long long int n=50;
    vector<long long int> a(n,n-1+k/n);
    for(int i=0;i<k%n;i++){
        a[i]+=n-k%n+1;
    }
    for(int i=k%n;i<n;i++){
        a[i]-=k%n;
    }
    cout<<n<<endl;
    for(int i=0;i<n;i++){
        cout<<a[i];
        if(i!=n-1) cout<<" ";
        else cout<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SMALLPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
ll inf=1000000007;
const int mod=1000000007;
void chmin(auto &a,auto b){if(b<a)a=b;}
void chmax(auto &a,auto b){if(a<b)a=b;}
int main(){
  int n;cin>>n;
  ll ans=0;
  vi v(n);
  rep(i,n)cin>>v[i];
  rep(i,n){
    REP(j,i+1,n)ans+=v[i]*v[j];
  }
  cout<<ans<<endl;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> L(M);
  vector<int> R(M);
  for (int i = 0; i < M; i++) {
    cin >> L.at(i) >> R.at(i);
  }
  
  sort(L.begin(), L.end());
  sort(R.begin(), R.end());
  
  int Lmax = L.at(M-1); //Lたちの右端
  int Rmin = R.at(0); //Rたちの左端
  
  if (Lmax > Rmin) {
    cout << 0 << endl;
  }
  else {
    cout << Rmin-Lmax+1 << endl;
  }
}


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

typedef complex<double> P;

namespace std {
  bool operator < (const P &a, const P &b) {
    return (make_pair(a.real(), a.imag())
            < make_pair(b.real(), b.imag()));
  }
}

const int MAXN = 111;

int n;
P s[MAXN], t[MAXN];

double cross(P a, P b) {
  return a.real()*b.imag() - a.imag()*b.real();
}

P getCrossP(P a1, P a2, P b1, P b2) {
  P a = a2 - a1;
  P b = b2 - b1;
  return a1 + a * cross(b, b1 - a1)/cross(b, a);
}

int main() {
  while (cin >> n && n) {
    for (int i = 0; i < n; ++i) {
      cin >> s[i].real() >> s[i].imag()
          >> t[i].real() >> t[i].imag();
    }
    
    int res = 1 + n;
    for (int i = 0; i < n; ++i) {
      set<P> ps;
      for (int j = 0; j < i; ++j) {
        if (cross(s[i]-t[i], s[j]-t[j]) == 0.0) {
          continue;
        }
        P c = getCrossP(s[i], t[i], s[j], t[j]);
        if (-100 < c.real() && c.real() < 100 &&
            -100 < c.imag() && c.imag() < 100) {
          ps.insert(c);
        }
      }
      res += ps.size();
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
using namespace std;
#define INF (1<<29)//INF
#define LLINF (1LL<<59)//LLINF
#define F first
#define S second
#define VS vector<string>
#define VI vector<int>
#define REP(i,s,num,n) for(int i=s;num<n;i++)//sからn未満の間iを回す
#define REPL(i,s,num,n) for(int i=s;num<=n;i++)
#define RREP(i,s,num,n) for(int i=s;num>=n;i--)//sからn以下の間iを回す
#define ALL(a) a.begin(),a.end()//ソートとかに使える sort(ALL(vec))のように
#define SET(a,c) memset(a,c,sizeof(a))//aをc（0or1）で初期化する
#define DEBUGONE(x) cout<<#x<<" : "<<x<<endl//デバックで一つの変数を表示
#define DEBUGTWO(x,y) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl//デバックで二つの変数を表示
#define DEBUGTHREE(x,y,z) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl//デバックで三つの変数を表示
#define OUTFORONE(x,n)for(int i=0;i<n;i++){if(i!=0){cout<<" ";}cout<<x[i];}cout<<endl;
#define OUTFOR(x,n)for(int i=0;i<n;i++){cout<<x[i]<<endl;}
#define DEBUGFORONE(x,n)for(int i=0;i<n;i++){if(i!=0){cout<<" ";}cout<<#x<<"["<<i<<"]"<<" : "<<x[i];}cout<<endl;
#define DEBUGFOR(x,n)for(int i=0;i<n;i++){cout<<#x<<"["<<i<<"]"<<" : "<<x[i]<<endl;}
#define OUTONE(x) cout<<x<<endl//一つの変数を表示
#define OUTTWO(x,y) cout<<x<<" "<<y<<endl//二つの変数を表示
#define OUTTHREE(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl//三つの変数を表示
#define FILLN(a,n,c) fill_n(a,n,c)//aをnまでcで初期化する
#define FILL(a,n,c) fill(a,n,c)///aをnまでcで初期化する
 
typedef long long int64;
typedef pair<string,int> Psi;
typedef pair<int,int> Pii;
main(){
  int n;
  int rui[100005]={0};
  int ans=0;
  int den[100005];
  int cnt=0;
  int p=0;
  cin>>n;
  cin>>den[0];
  cnt=1;
  REP(i,1,i,n){
    cin>>den[i];
    if(den[i-1]!=den[i]){
      cnt++;
    }
    else{
      rui[p]=cnt;
      cnt=1;
      p++;
    }
  }
  rui[p]=cnt;
  p++;
  REP(i,1,i,p+1){
    ans=max(ans,rui[i-1]+rui[i]+rui[i+1]);
  }
  OUTONE(ans);
}

Measured memory_bytes: 1948
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
	string s;
	ll time=0;
	cin>>s;
	for(ll i=0;i<s.size()-1;i++){
		if(s[i]==s[i+1]){
			if(s[i]=='0')
				s[i+1]='1';	
			else
				s[i+1]='0';		
			time++;
		}
	}	
	cout<<time<<endl;
}

Measured memory_bytes: 512
c_1 = list(map(int, input().split()))
c_2 = list(map(int, input().split()))
c_3 = list(map(int, input().split()))

diff = []

for i in range(2):
    diff.append(c_1[i] - c_1[i+1])

if c_2[0] - c_2[1] != diff[0] or c_2[1] - c_2[2] != diff[1]:
    print("No")
    exit()

if c_3[0] - c_3[1] != diff[0] or c_3[1] - c_3[2] != diff[1]:
    print("No")
    exit()

print("Yes")


Measured memory_bytes: 61720
// https://beta.atcoder.jp/contests/abc073
// status:

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

int main() {
    int N;
    cin >> N;
    if (N / 10 == 9 || N % 10 == 9) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main()
{
	int H, W, h, w;
	cin >> H >> W;
	cin >> h >> w;
	
	int x;
	x = H*W + h*w - h*W - H*w;

	cout << x << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define MOD (long long int)(998244353)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}


int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  string N;cin>>N;
  ll n = N.size();
  vector<ll> dp(n+1, LINF), dp2(n+1, LINF);
  dp[0] = 0;
  dp2[0] = 1;
  rep(i,n){
    chmin(dp[i+1], dp[i] + N[i] - '0');
    chmin(dp[i+1], dp2[i] + '9' + 1 - N[i]);
    chmin(dp2[i+1], dp[i] + N[i] - '0' + 1);
    chmin(dp2[i+1], dp2[i] + '9' - N[i]);
  }
  cout<<dp[n]<<endl;
  return 0;
}

Measured memory_bytes: 17052
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	//min(a,b)...a,bの小さいほう
	//max(a,b)...     大きいほう
	//int a;
	//int b;
	//int c;
	//int d;
	int e;
	//cin >> a >> b;
	int num;
	num == 0;
	string s;
	std::cin >> s;
	if (s[0] == '1') {
		num++;
	}
	if(s[1] == '1'){
		num++;
	}
	if (s[2] == '1') {
		num++;
	}
	cout << num << "\n";
	std::cin >> e;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef pair<int, int> pi;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MKP 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())
 
const int INF = 999999;
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll MOD = 1000000007;
 int K;
 
int main()
{
  cin.tie(0);
	ios::sync_with_stdio(false);
  cin >> K;
  if(K%2){
    cout << K/2 * (K/2 + 1) << endl;
  }else{
    cout << K/2 * K / 2 << endl;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll inf_=-174417441744;
ll ans[100005]={0};
ll val[100005]={0};
vector<ll> dl,tl,xl;
P mp(P p1,P p2){
  if(p1.first==p2.first){
    if(p1.second<p2.second) return p1;
    else return p2;
  }
  else{
    if(p1.first>p2.first) return p1;
    else return p2;
  }
}
struct segtree{
private:
  vector<P> node;
  ll siz;
public:
  segtree(ll n){
    siz=1;
    while(siz<=n) siz*=2;
    node.resize(siz*2+1,P(0,0));

    for(ll i=0;i<siz;i++){
      ll pos=i+siz-1;
      node[pos]=P(0,i);
    }
    for(ll i=siz-2;i>=0;i--){
      node[i]=mp(node[i*2+1],node[i*2+2]);
    }
  }
  void upd(ll pos,ll x){
    pos+=siz-1;
    node[pos]=P(x,pos-(siz-1));
    while(pos>0){
      pos=(pos-1)/2;
      node[pos]=mp(node[pos*2+1],node[pos*2+2]);
    }
  }
  P get_max(ll a,ll b,ll pos,ll l,ll r){
    if(a<=l&&r<=b) return node[pos];
    if(r<=a||b<=l) return P(inf_,-inf_);
    ll mid=(l+r)/2;
    P lb=get_max(a,b,pos*2+1,l,mid);
    P rb=get_max(a,b,pos*2+2,mid,r);
    return mp(lb,rb);
  }
  P max_q(ll a,ll b){
    return get_max(a,b,0,0,siz);
  }
};
int main(){
  ll n,r,l;
  cin>>n>>r>>l;
  dl.push_back(1);
  tl.push_back(0);
  xl.push_back(0);
  for(ll i=0;i<r;i++){
    ll d,t,x;
    cin>>d>>t>>x;
    dl.push_back(d);
    tl.push_back(t);
    xl.push_back(x);
  }
  tl.push_back(l);

  segtree seg=segtree(n+5);
  for(ll i=0;i<=r;i++){
    seg.upd(dl[i],val[dl[i]]+xl[i]);
    val[dl[i]]+=xl[i];
    P p=seg.max_q(1,n+1);
    ans[p.second]+=tl[i+1]-tl[i];
  //  cout<<dl[i]<<" "<<now_seg+xl[i]<<" "<<p.first<<" "<<p.second<<" "<<tl[i+1]-tl[i]<<endl;
  //  cout<<p.second<<endl;
  }
  ll as=0;
  ll ot=0;
  for(ll i=n;i>=1;i--){
    if(as<=ans[i]){
      as=ans[i];
      ot=i;
    }
  }
  //for(int i=1;i<=n;i++) cout<<val[i]<<" ";
  //cout<<endl;
  cout<<ot<<endl;
}



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

#define ll long long

using namespace std;

int main() {
	int n;
	cin >> n;
	ll d;
	cin >> d;
	d *= d;
	int cnt = 0;
	for (int i=0; i<n; ++i) {
		ll a, b;
		cin >> a >> b;
		cnt += (a*a+b*b <= d);
	}
	cout << cnt;
}


Measured memory_bytes: 3476
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <algorithm>
#define ll long long

using namespace std;

const long long mod = 1e9+7;

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

    int count = 0;
    int t = 0;
    while(t < n){
        t += 1 + d + d;
        count++;
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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


	int N;
	cin >> N;
	string S;
	cin >> S;

	unordered_set<string> ST1, ST2, ST3;
	rep(i, N) {
		for (auto s : ST2) ST3.insert(s + S[i]);
		for (auto s : ST1) ST2.insert(s + S[i]);
		ST1.insert(S.substr(i, 1));
	}
	co(ST3.size());

	Would you please return 0;
}

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

#define ll long long
#define vt vector
#define pb push_back
#define sz(x) (int)(x).size()

int main(){
  int n,k;cin>>n>>k;
  vt<int> H(n), dp(n,1e9);
  for(int i=0;i<n;i++) cin>>H[i];

  dp[0]=0;
  for(int i=1;i<n;i++){
    for(int j=1;j<=k&&i-j>=0;j++){
      dp[i]=min(dp[i],dp[i-j]+abs(H[i]-H[i-j]));
    }
  }

  cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 4052
package main

import "fmt"

func main() {
	var point [2]int
	var n int

	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		var t, h string

		fmt.Scan(&t, &h)
		if t == h {
			point[0]++
			point[1]++
		} else {
			point[map[bool]int{true:1, false:0}[t<h]] += 3
		}
	}

	fmt.Printf("%d %d\n", point[0], point[1])
}



Measured memory_bytes: 1400
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int n,count=0,q=0;
	cin >> n;
	vector<string>w(n);
	for (int i = 0; i < n; i++) {
		cin >> w[i];
	}
	for (int i = 1; i < n; i++) {
		if (w[i - 1][w[i - 1].size() - 1] == w[i][0]) {
			count = 0;
			for (int j = 0; j < i; j++) {
				if (w[i] != w[j]) {
					count++;
					//cout << count << endl;
					if(count == i) {
						q++;
						//cout << q << endl;
					}

				}
			}

		}
		else {
			break;
		}
	}
	if (q == n-1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

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

bool is_prime[100001];

void eratos(int N) {
  is_prime[0] = false, is_prime[1] = false;
  for (int i = 2; i * i <= N; ++i) {
    if (is_prime[i]) {
      for (int j = i * i; j <= N; j += i) {
        is_prime[j] = false;
      }
    }
  }
}

int main() {
  for (int i = 0; i <= 100000; ++i) {
    is_prime[i] = true;
  }
  eratos(100000);

  int n;
  while (cin >> n) {
    for (int i = n - 1; i >= 0; --i) {
      if (is_prime[i]) {
        cout << i << ' ';
        break;
      }
    }

    for (int i = n + 1; i <= 100000; ++i) {
      if (is_prime[i]) {
        cout << i << endl;
        break;
      }
    }
  }
}


Measured memory_bytes: 3176
#include <iostream>

using namespace std;

int main(){
    long long N;
    cin >> N;
    long long ans = 0;
    for (long long i = 1; i <= N; i++) {
        long long j = N / i;
        ans += i * j * (j+1) / 2;
    }
    cout << ans << endl;
}




Measured memory_bytes: 3644
//
//  main.cpp
//  CF-B
//
//  Created by Jeffrey on 2016/7/19.
//  Copyright © 2016年 com.jeffrey. All rights reserved.
//

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <sstream>
#include <cstdio>
#include <cstring>
#define ll long long
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int n, a[200] = {};
    cin >> n;
    for (int i = 0; i < n + n; i++) cin >> a[i];
    sort(a, a + n + n);
    int ans = 0;
    for (int i = 0; i < n + n; i += 2) ans += a[i];
    cout << ans;
}


Measured memory_bytes: 256
d,g=map(int,input().split())
s=[list(map(int,input().split()))for i in range(d)]
def dfs(d,g):
    if d==0:
        return 1e9
    l=min(g//(d*100),s[d-1][0])
    k=100*d*l
    if l==s[d-1][0]:
        k+=s[d-1][1]
    if k<g:
        l+=dfs(d-1,g-k)
    return min(l,dfs(d-1,g))
print(dfs(d,g))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <cstdio>
#include <cstdlib>

#ifdef _MSC_VER
#include <Windows.h>
#else
#include <unistd.h>
#endif

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int 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 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 emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD=(LL)1e9+7;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

#define INF 1LL << 50


LL C[51][51];
int calc(){
    CLR(C);
    REP(i,51)C[i][0]=1;
    FOR(n,1,51){
        FOR(k,1,n+1){
            C[n][k]=C[n-1][k]+C[n-1][k-1];
        }
    }
    return 0;
}
int A[102];
int main(){
    calc();
    int N,P;cin>>N>>P;
    REP(i,N)cin>>A[i];
    int odd=0,even=0;
    REP(i,N){
        if(A[i]%2==0)even++;
        else odd++;
    }
    LL res=0;
    if(P==0){
        for(int i=0;i<=even;i++)for(int j=0;j<=odd;j+=2){
            res+=C[even][i]*C[odd][j];
        }
    }else{
        for(int i=0;i<=even;i++)for(int j=1;j<=odd;j+=2){
            res+=C[even][i]*C[odd][j];
        }
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 764
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]


mod = 998244353

inf = 1e10


#solve
def solve():


    def init_max(init_max_val):
        #set_val
        for i in range(n):
            seg_max[i+num_max-1] = init_max_val[i]
        #built
        for i in range(num_max-2, -1, -1):
            seg_max[i] = max(seg_max[2*i+1], seg_max[2*i+2])


    def update_max(k, x):
        k += num_max-1
        seg_max[k] = x
        while k:
            k = (k-1)//2
            seg_max[k] = max(seg_max[k*2+1], seg_max[k*2+2])


    def query_max(p, q):
        if q <= p:
            return ide_ele_max
        p += num_max-1
        q += num_max-2
        res = ide_ele_max
        while q-p > 1:
            if p & 1 == 0:
                res = max(res, seg_max[p])
            if q & 1 == 1:
                res = max(res, seg_max[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = max(res, seg_max[p])
        else:
            res = max(max(res, seg_max[p]), seg_max[q])
        return res

    n = II()
    #####単位元######
    ide_ele_max = -1

    #num_max:n以上の最小の2のべき乗
    num_max = 2**(n).bit_length()
    seg_max = [ide_ele_max]*2*num_max
    xd = LIR(n)
    xd.sort()
    x = [x for x, d in xd]
    dp = [[0] * 2 for i in range(n + 1)]
    On = 0
    Off = 1
    dp[-1][On] =  1
    for i in range(n - 1, -1, -1):
        dp[i][Off] = (dp[i + 1][On] + dp[i + 1][Off]) % mod
        j = bisect_right(x, x[i] + xd[i][1] - 1) - 1
        if j == i:
            dp[i][On] = (dp[i + 1][On] + dp[i + 1][Off]) % mod
            update_max(i, i)
        else:
            j = query_max(i, j + 1)
            dp[i][On] = dp[j][On]
            update_max(i, j)
        
    print(sum(dp[0]) % mod)
    return


#main
if __name__ == '__main__':
    solve()


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

#define ii pair<int, int>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define vvi vector<vi>
#define INF int(1e9)

using namespace std;

int main () {
    ios_base::sync_with_stdio(false);

    string str;
    cin >> str;
    if(str.size()>=6 and str[2]==str[3] and str[4]==str[5])
        cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 10000
#define Q 500
#define NOT_FOUND -1

int linearSearch(int *, int, int);

int main()
{
  int n,m,i,j,s[N],t[Q],ret,cnt = 0;

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%d",&s[i]);
  }

  scanf("%d",&m);

  for(i = 0; i < m; i++){
    scanf("%d",&t[i]);
  }

  for(j = 0; j < m; j++){
    ret = linearSearch(s,n,t[j]);
    if(ret != NOT_FOUND){
      cnt++;
    }
  }
  printf("%d\n",cnt);
  
  return 0;
}

int linearSearch(int A[], int n, int key)
{
  int i;

  i = 0;

  A[n] = key;
  while(A[i] != key){
    i++;
  }
  if(i == n)return NOT_FOUND;
  return i;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define repr(i,n) for(int i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;

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


    int ans = a*a*a;
    cout << ans << endl;
}

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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	int n, k;
	cin >> n >> k;
	Vec<int> l(n);
	for (auto&& i : l) {
		cin >> i;
	}
	sort(rbegin(l), rend(l));
	cout << accumulate(begin(l), begin(l) + k, 0) << "\n";
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,s=0,t=0,a,b;
cin>>n;
for(int i=0;i<n;i++)
{
    cin>>a>>b;
    if(a==b)
    {
        s++;
    }

    else
    {
        if(s>=t)
        {
         t=s;
        }
        s=0;
    }
}
if(t>=3||s>=3)
{
    cout<<"Yes"<<endl;
}
else
{
    cout<<"No"<<endl;
}
    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
#include <map>
#include <iomanip>
#include <math.h>
using namespace std;
 
#define pb push_back
#define f first
#define s second
#define endl '\n'
#define EPS 1e-9
#define PI acos(-1)
 
using ll = long long;
using ii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<ii>;
using vll = vector<ll>;
using ui = unsigned int;

double dist(double x,double y,double x1,double y1){
    return sqrt((x-x1)*(x-x1) + (y-y1)*(y-y1));
}
ll facto(int a){
    if(a == 0) return 1;
    return a*facto(a-1);
}

int main() {
    ofstream out("output.txt");
    ios_base::sync_with_stdio(false);
    
    int n;
    cin>>n;
    vii v;
    int a,b;
    string path = "";
    for(int i=1;i<=n;i++){
        cin>>a>>b;
        path += (i+'0');
        v.pb({a,b});
    }
    double promedio;
    double sumaTot = 0;
    double longitud = 0;
    for(int i =0;i<n-1;i++){
        //cout<<path[i]-'0'<<" "<<path[i+1]-'0'<<endl;
        longitud += dist(v[path[i]-'0'-1].f,v[path[i]-'0'-1].s,v[path[i+1]-'0' -1].f,v[path[i+1]-'0' -1].s);
    }
    sumaTot += longitud;
    while(next_permutation(path.begin(),path.end())){
        longitud = 0;
        for(int i =0;i<n-1;i++){
            longitud += dist(v[path[i]-'0'-1].f,v[path[i]-'0'-1].s,v[path[i+1]-'0' -1].f,v[path[i+1]-'0' -1].s);
        }   
        sumaTot += longitud;
    }
    promedio = sumaTot / facto(n);

    cout<<setprecision(10)<<fixed<<promedio<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;

const ll INF = LONG_LONG_MAX;

ll cntOnes(ll x) {
  ll ret = 0;
  for (ll i = 0; i < 20; i++) {
    ll v = (x >> i) & 1;
    if (v == 1) ret++;
  }
  return ret;
}

int main() {
  ll N;
  cin >> N;

  vector<vector<P>> lst(N);
  for (ll i = 0; i < N; i++) {
    ll Ai;
    cin >> Ai;
    for (ll j = 0; j < Ai; j++) {
      ll man, b;
      cin >> man >> b;
      man--;
      lst[i].push_back(P(man, b));
    }
  }

  ll maxv = (1 << N) - 1;
  ll ans = 0;
  for (ll i = 0; i <= maxv; i++) {
    bool ok_i = true;
    for (ll j = 0; j < N; j++) {
      ll curman = (i >> j) & 1;
      if (curman == 1) {
        for (auto p : lst[j]) {
          ll man = p.first;
          ll b = p.second;
          ll manb = (i >> man) & 1;
          if (manb != b) {
            ok_i = false;
            break;
          }
        }  // p
      }
      if (ok_i == false) break;
    }  // j
    if (ok_i == true) {
      ll cnt = cntOnes(i);
      ans = max(ans, cnt);
    }
  }  // i

  cout << ans << endl;

  return 0;
}


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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1, 0};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<int> p(n), q(n+1);
    for(int i = 0; i < n; ++i){
        cin >> p[i];
        q[p[i]] = i;
    }
    vector<int> ml(n), ML(n), mr(n), MR(n);
    set<int> place;
    place.insert(q[n]);
    for(int i = n-1; i >= 1; --i){
        place.insert(q[i]);
        auto it = place.find(q[i]);
        if(it == place.begin()) {
            ML[i] = -1;
            ml[i] = -1;
        }
        else{
            --it;
            if(it == place.begin()) {
                ML[i] = *it;
                ml[i] = -1;
            }
            else{
                auto it2 = it;
                --it2;
                ML[i] = *it;
                ml[i] = *it2;
            }
        }
        it = place.find(q[i]);
        ++it;
        if(it == place.end()) {
            mr[i] = MR[i] = n;
        }
        else {
            mr[i] = *it;
            ++it;
            if(it == place.end()) {
                MR[i] = n;
            }
            else {
                MR[i] = *it;
            }
        }
    }
    ll ans = 0;
    for(int i = 1; i <= n-1; ++i) {
        ans += i * (ll(ML[i] - ml[i]) * (mr[i] - q[i]) + ll(q[i] - ML[i]) * (MR[i] - mr[i]));
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
const ll INF = 9999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    vl A;
    ll dp[n][4]; //どこまで見たか・i番目まで見たときにi-(使った数)*2+2
    rep(i, n) {
        cin >> a;
        A.push_back(a);
    }

    rep(i, n) {
        if(i == 0) {
            dp[0][0] = A[0];
            dp[0][1] = -INF;
            dp[0][2] = -INF;
        } else {
            if(i == 1)
                dp[i][0] = -INF;
            else
                dp[i][0] = dp[i - 2][0] + A[i];
            if(i == 1)
                dp[i][1] = A[i];
            else
                dp[i][1] = dp[i - 2][1] + A[i];
            if(i > 2)
                dp[i][1] = max(dp[i - 3][0] + A[i], dp[i][1]);
            if(i == 1)
                dp[i][2] = -INF;
            else if(i == 2)
                dp[i][2] = A[i];
            else
                dp[i][2] = dp[i - 2][2] + A[i];
            if(i > 2)
                dp[i][2] = max(dp[i - 3][1] + A[i], dp[i][2]);
            if(i > 3)
                dp[i][2] = max(dp[i - 4][0] + A[i], dp[i][2]);
        }
    }

    if(n % 2 == 0)
        ans = max(dp[n - 2][0], dp[n - 1][1]);
    else
        ans = max({dp[n - 3][0], dp[n - 2][1], dp[n - 1][2]});

    cout << ans << endl;
}


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

int main()
{
	while (true) {
		int e;
		cin >> e;

		if (e == 0) {
			break;
		}

		int ans = e;

		for (int y = 0; y*y <= e; y++) {
			for (int z = 0; z*z*z <= e; z++) {
				if (y*y + z*z*z <= e) {
					ans = min(e - y*y - z*z*z + y + z, ans);
				}
			}
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
const int MOD=100000;
int main(){
      int n,m,s,t,e,l;
      cin>>n>>m;
      vector<P> V[10000];
      while(cin>>s>>t>>e&&(s||t||e)){
            s--;t--;
            V[s].PB(P(t,e));
      }
      cin>>l;
      while(l--){
            int b[m];
            REP(i,m)cin>>b[i];
            REP(i,n){
                  int res=0;
                  REP(j,V[i].size()){
                        res+=b[V[i][j].first]*V[i][j].second;
                  }
                  cout<<res;
                  if(i!=n-1)cout<<" ";
                  else cout<<endl;
            }
      }
}

Measured memory_bytes: 2256
#include <iostream>
#include <cmath>
#include <utility>

using namespace std;

int main(void) {
	long n;
	cin >> n ;
	long t = n;
	long d = 0;
	while(t != 0) {
		d += t % 10;
		t = t / 10;
	}
	if(n % d == 0)
		cout << "Yes" << endl;
	else 
		cout << "No" << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class program
{
    static void Main()
    {
        int num = int.Parse(Console.ReadLine());

        int[] nums = new int[num];
      
        string[] str = Console.ReadLine().Split(' ');

        for (int i = 0;i < nums.Length;i++)
        {
            nums[i] = int.Parse(str[i]);
        }

        for (int i = 0;i<nums.Length-1;i++)
        {
            Console.Write("{0} ", nums[nums.Length-1-i]);
        }
        Console.Write("{0}", nums[0]);
        Console.WriteLine();

    }

    
}

Measured memory_bytes: 8996
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
void main()
{
    auto input = stdin.byLine.map!split.joiner;

    string S;
    S = input.front.to!string;
    input.popFront;

    string T;
    T = input.front.to!string;
    input.popFront;

    solve(S, T);
}

void solve(string S, string T)
{
    iota(S.length - T.length + 1).map!(x => eval(S[x .. x + T.length], T))
        .reduce!min().writeln;
}

long eval(string s, string t)
{
    dprint(s, t);
    long ret;
    foreach (i; 0 .. s.length)
    {
        ret += s[i] != t[i];
    }
    return ret;
}


Measured memory_bytes: 3684
package main

import (
	"fmt"
)

func main() {
	// Code for B - Substring
	var S, T string
	fmt.Scanf("%s", &S)
	fmt.Scanf("%s", &T)

	var count int
	var ans int = len(T)
	for i := 0; i < len(S)-len(T)+1; i++ {
		count = 0
		for j := 0; j < len(T); j++ {
			if S[i+j] != T[j] {
				count++
			}
		}

		if ans > count {
			ans = count
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1852
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define M 100010


int main(){
	IOS;
	tihs;
	
	
	string s;cin>>s;

	if(s[0]=='7' or s[1]=='7' or s[2]=='7')cout<<"Yes";
	else cout<<"No";

	return 0;
}

Measured memory_bytes: 3652
#include <cmath>
#include <vector>
#include <list>
#include <stdio.h>
#include <iostream>
using namespace std;


//-----------------------------------------
vector<int> bubble_sorting(int *numset, int num_size){  
    int hit  = 0;
    vector<int> sorted_box;
    auto it = sorted_box.begin();

    do{
        hit = 0;
        for(int curr=0; curr<num_size-1; curr++){  
            int num_l = numset[curr];
            int num_r = numset[curr+1];
            if(num_l > num_r){
                numset[curr]   = num_r;
                numset[curr+1] = num_l;
            }else{
                hit +=1;
            };
        };
    }while( hit!=(num_size-1) );

    for(int i=0; i<num_size; i++){ 
        it = sorted_box.insert(it, numset[i]);
        it++;
    };

   return sorted_box;
}


int max_add(int max, int a1, int a2){
    int ans;
    ans = (10*max) + a1 + a2;
    return ans;
}


int main() {
    // I/O format
    int A, B, C; cin >> A >> B >> C;
    int box[] = {A, B, C};
    vector<int> sorted_box;
    sorted_box = bubble_sorting(box, 3);

    int out = max_add(sorted_box[2], sorted_box[1], sorted_box[0]);
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<queue>
#include<map>
#include<stack>
using namespace std;
const int N = 1e5;


int main()
{
	int n;
    cin>>n;
    int p=n/1000;
    if(n%1000>0)    p++;
    cout<<p*1000-n<<endl;



    int ab;
    cin>>ab;
} 

Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define ll long long

using namespace std;
ll dp[100001][101];

int main()
{
    ll n,m,W,i,j;
    cin>>n>>W;
    //cout<<"b";
    ll w[n],v[n];

    //cout<<"a";
    for(i=0;i<n;i++)
    {
        cin>>w[i]>>v[i];
    }

    for(i=1;i<=100000;i++)
    {
        dp[i][n] = W+1;
    }
    for(i=0;i <= 100000;i++)
    {
        for(j=n-1;j >= 0;j--)
        {
            if(i==0)
            {
                dp[i][j] = 0;
                continue;
            }

            if((i - v[j]) >= 0)
            {
                dp[i][j] = min(dp[i][j+1],dp[i-v[j]][j+1]+w[j]);
            }
            else
                dp[i][j] = dp[i][j+1];

        }
    }

    ll ans = 0;

    for(i=0;i<=100000;i++)
    {
        if(dp[i][0]>0&&dp[i][0]<=W)
            ans = i;
    }

    cout<<ans;

    return 0;
}


Measured memory_bytes: 79104
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


n=int(input())
graph=[[] for i in range(n+1)]
for i in range(n-1):
    a,b,c=map(int,input().split())
    graph[a].append((b,c))
    graph[b].append((a,c))
    
q,k=map(int,input().split())

dis=[None]*(n+1)

def set_dis(x,d):
    dis[x]=d
    for yy,dd in graph[x] :
        if dis[yy] is not None:
            continue
        set_dis(yy,dd+d)
set_dis(k,0)

for i in range(q):
    x,y=map(int,input().split())
    print(dis[x]+dis[y])


Measured memory_bytes: 131760
#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;

int main(){
	int people[21], Total, Total2;
	for (int i = 0; i < 20; i++){
		cin >> people[i];
	}
	sort(people, people + 10,greater<int>());
	sort(people + 10, people + 20,greater<int>());
	Total = people[0] + people[1] + people[2];
	Total2 = people[10] + people[11] + people[12];
	cout << Total <<" "<< Total2 << endl;
	return 0;
}

Measured memory_bytes: 1180