akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cmath>

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

#include <iostream>
#include <vector>

using namespace std;

const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }

    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }

    friend std::istream &operator>>(std::istream &in, mint &o) {
        ll a;
        in >> a;
        o = a;
        return in;
    }

    friend std::ostream &operator<<(std::ostream &out, const mint &o) {
        out << o.x;
        return out;
    }

};

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<vector<mint>> dp(n + 1, vector<mint>(13));
    dp[0][0] = 1;
    rep(i, n) {
        if (s[i] == '?') {
            rep(j, 13) {
                rep(k, 10) {
                    int l = (j * 10 + k) % 13;
                    dp[i + 1][l] += dp[i][j];
                }
            }
        } else {
            int k = s[i] - '0';
            rep(j, 13) {
                int l = (j * 10 + k) % 13;
                dp[i + 1][l] += dp[i][j];
            }
        }
    }

    cout << dp[n][5] << endl;

}





Measured memory_bytes: 13696
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cstring>
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(int i=0;i<n;i++)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())

int main(){
	int n,k;
	int our[3];
	cin>>n>>k;
	string t;
	fo(i,3) cin>>our[i];
	cin>>t;
	
	std::vector<int> visited(n,0);
	int ans=0;
	int a,b,c,na,nb,nc;
	fo(i,n){
		if(visited[i]) continue;
	    a=0,b=0,c=0;
		int index=i;
		while(index<n){
			visited[index]=1;
		    na=0,nb=0,nc=0;
			if(t[index]=='r'){
				na=max(b,c);
				nb=max(a,c);
				nc=max(a+our[2],b+our[2]);
			}
			if(t[index]=='s'){
				nc=max(a,b);
				nb=max(a,c);
				na=max(b+our[0],c+our[0]);
			}
			if(t[index]=='p'){
				na=max(b,c);
				nc=max(a,b);
				nb=max(a+our[1],c+our[1]);
			}
			a=na,b=nb,c=nc;
			index=index+k;



		}
		ans=ans+max(a,max(b,c));


	}
	cout<<ans<<endl;


	

}

Measured memory_bytes: 896
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<limits.h>

int main() {
	int loop;
	int N;
	int *a;
	int x, y;
	int sum;
	int best;

	scanf("%d", &N);
	a = malloc(sizeof(int)*N);
	best = INT_MAX;
	for (loop = 0; loop < N; loop++) {
		scanf("%d", &a[loop]);
	}
	for (x = -100; x <= 100; x++) {
		sum = 0;
		for (y = 0; y < N; y++) {
			sum += pow(x - a[y], 2);
		}
		if (sum < best)
			best = sum;
	}
	printf("%d", best);

	return 0;
}


Measured memory_bytes: 128
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count=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:
                count += 1
print(count)

Measured memory_bytes: 3060
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF (1 << 29) * 2
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

typedef struct
{
  ll node;
  ll val;
  ll index;
} sd;

int sortsd(const void *a, const void *b)
{
  return ((sd *)a)->val < ((sd *)b)->val ? -1 : ((sd *)a)->val > ((sd *)b)->val ? 1 : 0;
}

sd a[100005];
ll b[100005];
ll res[2][100005];
int main()
{
  ll n, k;
  scanf("%lld%lld", &n, &k);
  for (int i = 0; i < k; i++)
  {
    scanf("%lld%lld", &a[i].node, &a[i].val);
    a[i].index = i;
  }
  qsort(a, k, sizeof(a[0]), sortsd);
  for (int i = 0; i < k; i++)
  {
    res[0][a[i].index] = a[i].node;
    b[a[i].node]++;
    res[1][a[i].index] = b[a[i].node];
  }
  for (int i = 0; i < k; i++)
  {
    printf("%06lld%06lld\n", res[0][i], res[1][i]);
  }
  return 0;
}

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

using namespace std;

#define endl '\n'

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

    int N, M;
    cin >> N >> M;

    vector<int> V;
    vector<int> W;

    for (int i = 0; i < N; ++i){
    	int vi, wi, mi;
    	cin >> vi >> wi >> mi;
    	int p = 1;
    	while (p < mi){
    		V.push_back(vi * p);
    		W.push_back(wi * p);
    		mi -= p;
    		p = p << 1;
    	}
    	V.push_back(vi * mi);
		W.push_back(wi * mi);
    }

    N = V.size();
    vector<vector<int>> dp(N + 1, vector<int>(M + 1, 0));

    for (int i = N - 1; i >= 0; --i){
    	for (int j = 0; j <= M; ++j)
    		dp[i][j] = max(dp[i + 1][j], (j >= W[i]) * (dp[i + 1][max(0, j - W[i])] + V[i]));
    }

    cout << dp[0][M] << endl;
}



Measured memory_bytes: 57544
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;

int main() {
  int a;
  cin >> a;
  cout << a + a * a + a * a * a << endl;
  return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define inf 100000000000000000
#define ll long long int
#define pb push_back
#define f first
#define s second
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}

int main(){
	//mahakal();fast;

	ll k , n ;
	cin>>k>>n ;
	ll ans = k*500;
	if(ans>=n)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int n;
    cin >> n;
    string s;
    cin >> s;

    ll r = 0, g = 0, b = 0;
    for(auto c : s) {
        if (c == 'R') r++;
        if (c == 'G') g++;
        if (c == 'B') b++;
    }

    ll all = r*g*b;
    ll sub = 0;

    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            if(s[i] == s[j]) continue;
            int k = j*2-i;
            if(k >= n || s[k] == s[i] || s[k] == s[j]) continue;
            sub++;
        }
    }

    cout << all - sub << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
const int INF = 100100100;
using namespace std;

int main()
{
  int a,b;
  int res=0;
  cin >> a>>b;

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

Measured memory_bytes: 256
use std::io::{self, Read};

fn main() {
    let mut buffer = String::new();
    io::stdin().read_to_string(&mut buffer);
    buffer = buffer.trim().to_string();

    let x: u8 = buffer.parse().unwrap();
    let m = x % 7;
    let msg = match m {
        0 => "thu",
        1 => "fri",
        2 => "sat",
        3 => "sun",
        4 => "mon",
        5 => "tue",
        6 => "wed",
        _ => "something is wrong",
    };

    println!("{}", msg);
}


Measured memory_bytes: 5020
/*
  Vivek Rathi
  CSE 2nd Year
  MNNIT
*/
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long int
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define present(c,x) ((c).find(x) != (c).end())
#define null NULL
#define mp make_pair
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf 1e18
#define flush fflush(stdout);
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}
//-------------------------------Template--Above------------------------------------------------


int main()
{
	string s;
	cin>>s;
	ll n=s.length();
	ll co=0;
	for(ll i=0;i<n;i++)
	{
		if(s[i]=='o')
			co++;
	}
	if(co>=8||co+(15-n)>=8)
	{
		cout<<"YES"<<endl;
	}
	else
		cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
    #include<cstring>

    int main()
    {
        int n,ans=0,m=1;
        int num;
        scanf("%d", &n);
        for (int i = 0; i < n;i++)
        {
            scanf("%d", &num);
            if(num==m)
            {
                m++;
            }
            else
                ans++;
        }
        if(ans==n)
            printf("-1");
        else
            printf("%d",ans);
        return 0;
    }

Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int64_t>A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  vector<int64_t>B(1+N);
  map<int64_t,int64_t>M;
  M[1]=A.at(0);
  for(int i=2;i<=N;i++)
    if(i%2==1)
      M[i]=M.at(i-2)+A.at(i-1);
  B.at(0)=0;
  B.at(0)=0;
  B.at(2)=max(A.at(0),A.at(1));
  for(int i=3;i<=N;i++){
  if(i%2==0)
    B.at(i)=max(A.at(i-1)+B.at(i-2),A.at(i-2)+M.at(i-3));
    else
      B.at(i)=max(A.at(i-1)+B.at(i-2),A.at(i-2)+B.at(i-3));
  
  }cout<<B.at(N)<<endl;
   return 0;
}

Measured memory_bytes: 12700
/// __Macro's__
#include <bits/stdc++.h>
using namespace std;
#define ll                   long long
#define II                   pair<int,int>
#define III                  pair<int, II>
#define VL                   vector<ll>
#define VI                   vector<int>
#define VII                  vector<II>
#define VIII                 vector<III>
#define VVI                  vector<vector<int>>
#define VVII                 vector<vector<II>>
#define fr                   first
#define sc                   second
#define mkpr                 make_pair
#define PQ                   priority_queue
#define pb                   push_back
#define eb                   emplace_back
#define all(v)               v.begin(), v.end()
#define LINE                 putc('\n', stdout)
#define SPACE                putc(' ' , stdout)
#define TAB                  putc('\t', stdout)
#define fillarr(arr, val)    fill((int*)arr, (int*)arr+(sizeof(arr)/sizeof(int)), val)
#define Log2(x)              (31^__builtin_clz(x))
#define INF                  1000000007 
#define MOD                  1000000007 
#define getint ReadInt()
const char IO_MODE = 0; // in-->00<--out (MSB-->LSB) | 0: Norm, 1: Fast 
inline ll ReadInt(){ll x=0,s=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')s=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';
c=getchar();}return s*x;}inline void WriteInt(ll x){char c[20];if(!x){putchar('0');return;}if(x<0)putchar('-'),x=-x;int i=0;while(x>0)
c[++i]=x%10,x/=10;while(i)putchar(c[i--]+48);}template <typename T>inline void out(T x){if(IO_MODE&1)WriteInt(x);else if(typeid(x)==typeid(int))
printf("%i", x);else printf("%lld", (ll)x);}template<typename T, typename... Args>inline void out(T x,Args...args){out(x);SPACE;out(args...);}
template <typename T>inline void in(T &x){if(IO_MODE&2) x=ReadInt();else if(typeid(x)==typeid(int))scanf("%i",&x);else if(typeid(x)==typeid(ll))
scanf("%lld",&x);}template<typename T, typename... Args>inline void in(T &x,Args&...args){in(x);in(args...);}
int aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,kk,mm,nn,oo,pp,qq,rr,ss,tt,uu,vv,ww,xx,yy,zz;
int tc;
///

int n;
ll A[22][22];
ll W[1<<18];
ll Dp[1<<18];
int main()
{
  in(n);
  for(int i=0 ; i<n ; i++)
    for(int j=0 ; j<n ; j++)
     in(A[i][j]);
  
  for(int mask=1 ; mask<1<<n ; mask++)
  {
    int x = Log2(mask);
    W[mask] = W[mask^1<<x];
    for(int i=x-1 ; i>=0 ; i--)
      if(mask&1<<i)
        W[mask]+=A[x][i];
  }
  for(int mask=(1<<n)-1; mask>=0 ; mask--)
    for(int cur=mask ; cur>0 ; cur=mask&(cur-1)){
      int New = mask^cur;
      Dp[New] = max(Dp[New], Dp[mask] + W[cur]);
    }

  cout << Dp[0] << endl;
}

Measured memory_bytes: 2816
import java.util.Scanner;

class Main
{
	public static void main(String[] args)
	{
		Scanner stdIn = new Scanner(System. in);
		int a= stdIn.nextInt();
		int b= stdIn.nextInt();
		int c = a*b;
		int d = 2*(a+b);
		System.out.println( c + " " + d );
	}
}

Measured memory_bytes: 25848
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX/2-1
#define pb push_back

using namespace std;

int main() {
  int Q, N, tmp1, tmp2, digit, x, max, count = 0;;
  cin >> Q;
  while (Q--) {
    cin >> N;
    count = 0;
    while (N/10) {
      max = -INF;
      x = 10;
      for (digit = 1; N/x; digit++) {
        x *= 10;
      }
      x /= 10;
      for (int i = 1; i < digit; i++, x /= 10) {
        tmp1 = N / x;
        tmp2 = N % x;
        if (max < tmp1*tmp2) {
          max = tmp1*tmp2;
        }
      }
      N = max;
      count++;
    }
    cout << count << el;
  }
}

Measured memory_bytes: 1164
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X = LIST()

for i, x in enumerate(X):
    if i+1 != x:
        print(i+1)


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



void solve(long long N, std::vector<long long> A){
    ll ans = 1;
    bool flg = false;
    sort(A.begin(), A.end());
    rep(i, N) {
        // cout << A[i] << " "<< ans << " " << sqrt(LONG_LONG_MAX) << endl;
        if ((A[i]>=sqrt(LONG_LONG_MAX) && ans>=sqrt(LONG_LONG_MAX)) ||
            (A[i]>=sqrt(LONG_LONG_MAX) && A[i]/sqrt(LONG_LONG_MAX)*ans >= sqrt(LONG_LONG_MAX)) || 
            (ans >= sqrt(LONG_LONG_MAX) && ans/sqrt(LONG_LONG_MAX)*A[i] >= sqrt(LONG_LONG_MAX))) {
            
            flg = true;
            break;
        }
        else
            ans *= A[i];
    }
    if(ans > 1000000000000000000 || flg)
        cout << -1 << endl;
    else
    {
        cout << ans << endl;
    }
    
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 4060
N,M,C = map(int,input().split())
B = list(map(int,input().split()))

count = 0
for _ in range(N):
    A = list(map(int,input().split()))
    count += 1 if sum([a*b for a,b in zip(A,B)])+C > 0 else 0

print(count)

Measured memory_bytes: 3060
#include<iostream>
#include<map>
#include<vector>

using namespace std;

class data
{
public:
	int n;
	int score;
	int rank;
};

int main(void)
{
	vector<data> d;
	while(1)
	{
		int a,b;
		char c;
		cin>>a>>c>>b;
		if(a==0&&b==0)break;
		data tmp;
		tmp.n=a;
		tmp.score=b;
		d.push_back(tmp);
	}

	for(int i=0;i<d.size();i++)
	{
		int max=i;
		for(int j=i+1;j<d.size();j++)
		{
			if(d[max].score<d[j].score)
			{
				max=j;
			}
		}
		data tmp=d[i];
		d[i]=d[max];
		d[max]=tmp;
	}
	
	int rank=1;
	int score=d[0].score;
	for(int i=0;i<d.size();i++)
	{
		if(d[i].score!=score){
			score=d[i].score;
			rank++;
		}
		d[i].rank=rank;
	}
	while(1)
	{
		int n;
		cin>>n;
		if(cin.eof())break;
		for(int i=0;i<d.size();i++)
		{
			if(d[i].n==n)
			{
				cout<<d[i].rank<<endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 1212
//Pyramid
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000009
#define N 1000005
using namespace std;

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

ll n, a[N], ans;

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%lld",&n);
	for(ll i = 1; i <= n; i++)
		scanf("%lld",&a[i]);
	for(ll i = 0; i < 60; i++){
		ll say = 0;
		for(ll j = 1; j <= n; j++)
			if(a[j] & (1ll<<i))
				say++;
		ll kac = n*(n - 1)/2ll;
		kac -= say * (say - 1)/2ll;
		kac -= (n - say) * (n - say - 1)/2ll;
		// cout << kac << endl;
		kac %= mod;
		ans = (ans + ((1ll<<i)%mod)*kac%mod )%mod;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 4352
//By Don4ick 
//#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qewr1234

const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};

const int N = (int)1e5 + 228;

using namespace std;

int n, pr[N];
set < int > a[N], b[N];

int get(int v)
{
	if (pr[v] == v)
		return v;
	return pr[v] = get(pr[v]);	             	
}

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

	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	//~read
	scanf("%d", &n);
	forn(i, n - 1)
	{
		int v, u;
		scanf("%d%d", &v, &u);
		a[v].insert(u);
		a[u].insert(v);
	}	
	forn(i, n - 1)
	{
		int v, u;
		scanf("%d%d", &v, &u);
		b[v].insert(u);
		b[u].insert(v);
	}
	//~solve
	queue < pair < int, int > > q;
	forn(i, n)
	{
		for (auto it : b[i])
			if (a[i].find(it) != a[i].end())
				q.push({i, it});
	}
	forn(i, n)
	{
		pr[i] = i;	
	}
	int res = 0;                
	while(!q.empty())
	{
		int v = q.front().first, u = q.front().second;
		q.pop();
		v = get(v), u = get(u);
		if (v == u)
			continue;
		res++;
		int sz1 = a[v].size() + b[v].size();
		int sz2 = a[u].size() + b[u].size();
		if (sz1 > sz2)
			swap(v, u);
		for (auto it : a[v])
			if (b[u].find(get(it)) != b[u].end())
				q.push({it, u});
	    for (auto it : b[v])
			if (a[u].find(get(it)) != a[u].end())
				q.push({it, u});
		for (auto it : a[v])
		{
			a[get(it)].insert(u);
			a[u].insert(get(it));
		}
		for (auto it : b[v])
		{
			b[get(it)].insert(u);
			b[u].insert(get(it));
		}
		pr[v] = u;	
	}
	if (res == n - 1)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;	

	return 0;
}



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

int main() {
int n, x;
cin >> n >> x;
vector<int> vec(n);
for(int i = 0; i < n; i++){
    cin >> vec.at(i);
}
int tall = 0;
int answer = 1;
for(int i = 0; i < n; i++){
    tall = tall + vec.at(i);
    if(tall <= x){
        answer++;
    }
}
cout << answer << endl;

}


Measured memory_bytes: 256
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
#include<map>
using namespace std;

int main() {

	long long N;
	cin >> N;
	for (int h = 1; h <= 3500; h++) {
		for (int n = 1; n <= 3500; n++) {
			long long d = 4 * h*n - N*(n + h);
			if (d != 0) {
				double w = (double)N*h*n / d;
				if (w >1 && w == floor(w)) {
					cout << h << " " << n << " " << (long long)w<<endl;
					return 0;
				}
			}
		}
	}


	return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 100001
#define fto(i,a,b) for(int i=a; i<=b; i++)
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
int n, xd[maxn];
pii a[maxn], b[maxn];
void solve1()
{
    int cnt=0, m=0;
    fto (i, 0, n/2) a[++cnt]={i, n-i};
    a[0]=a[cnt];
    fto (i,1 , cnt-1) {
        b[++m]={a[i].fi, a[i-1].fi};
        b[++m]={a[i].fi, a[i-1].se};
        b[++m]={a[i].se, a[i-1].fi};
        b[++m]={a[i].se, a[i-1].se};
        b[++m]={a[i].fi, a[i+1].fi};
        b[++m]={a[i].fi, a[i+1].se};
        b[++m]={a[i].se, a[i+1].fi};
        b[++m]={a[i].se, a[i+1].se};
    }
    fto (i, 1 , m) if (b[i].fi>b[i].se) swap(b[i].fi, b[i].se);
    int res=0;
    sort(b+1, b+1+m);
    fto (i, 1, m) if (b[i]!=b[i-1] && (b[i].fi*b[i].se)) {
        xd[i]=1;
        ++res;
    }
    cout << res << endl;
    fto (i, 1, m) if (xd[i]) cout << b[i].fi << ' ' << b[i].se << endl;
}
void solve2()
{
    int cnt=0, m=0;
    fto (i, 1, n/2) a[i]={i, n-i+1};
    n/=2;
    a[0]=a[n];
    fto (i, 1, n) {
        b[++m]={a[i].fi, a[i-1].fi};
        b[++m]={a[i].fi, a[i-1].se};
        b[++m]={a[i].se, a[i-1].fi};
        b[++m]={a[i].se, a[i-1].se};
    }

    fto (i, 1 , m) if (b[i].fi>b[i].se) swap(b[i].fi, b[i].se);
    int res=0;
    sort(b+1, b+1+m);
    fto (i, 1, m) if (b[i]!=b[i-1] && (b[i].fi*b[i].se)) {
        xd[i]=1;
        ++res;
    }
    cout << res << endl;
    fto (i, 1, m) if (xd[i]) cout << b[i].fi << ' ' << b[i].se << endl;
}
int main()
{
    //freopen("b.inp", "r", stdin);
    //freopen("b.out", "w", stdout);
    cin >> n;
    if (n%2) solve1(); else solve2();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    if(n%10==7||(n/10)%10==7||(n/100)==7)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll * pos,ll val){*pos=max(*pos,val);}//Max(&dp[i][j],dp[i-1][j]);
void Min(ll * pos,ll val){*pos=min(*pos,val);}
void Add(ll * pos,ll val){*pos=mod(*pos+val);}
const long double EPS=1E-8;
////////////////////////////////////////
#define MAX_V 30000//調節！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！
//辺を表す構造体{行き先、容量、逆辺}
struct edge{ll to,cap,rev;};
vector<edge> G[MAX_V];
bool used[MAX_V];//dfsですでに調べたかのフラグ
//fromからtoへの流量capの辺をグラフに追加
void add_edge(ll from,ll to,ll cap){
    //cout<<from<<" "<<to<<" "<<cap<<endl;
    G[from].push_back((edge){to,cap,static_cast<ll>(G[to].size())});
    G[to].push_back((edge){from,0,static_cast<ll>(G[from].size()-1)});
}
//増加パスをdfsで探す
ll dfs(ll v,ll t,ll f){
    if(v==t)return f;
    used[v]=true;
    for(ll i=0;i<G[v].size();i++){
        edge &e=G[v][i];
        if(!used[e.to]&&e.cap>0){
            ll d=dfs(e.to,t,min(f,e.cap));
            if(d>0){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}
ll max_flow(ll s,ll t){
    ll flow=0;
    while(1){
        memset(used,0,sizeof(used));
        ll f=dfs(s,t,inf);
        if(f==0)return flow;
        flow+=f;
    }
}
///////////////////////////////////////

int gcd(int a,int b){
    if(a>b)swap(a,b);
    if(a==0)return b;
    else return gcd(b%a,a);
}

int main(){
    int N=505;
    while(1){
        int m,n;cin>>m>>n;if(m==0)return 0;
        rep(i,0,MAX_V-1)G[i].clear();
        int a[m],b[n];rep(i,0,m-1)cin>>a[i];rep(i,0,n-1)cin>>b[i];
        rep(i,0,m-1){
            rep(j,0,n-1){
                if(gcd(a[i],b[j])>=2){
                    add_edge(i,j+N,1);
                }
            }
        }
        int sta=2*N,end=2*N+1;
        rep(i,0,m-1){
            add_edge(sta,i,1);
        }
        rep(i,0,n-1){
            add_edge(i+N,end,1);
        }
        cout<<max_flow(sta,end)<<endl;
    }
    return 0;
}



Measured memory_bytes: 16684
import sys
input = sys.stdin.readline

n, q = map(int, input().split())
C = [0] + list(map(int, input().split()))
D = [-1]*(n+1)
A = [0]*q
U = 10**6
LR = tuple(tuple(map(int, input().split())) for _ in range(q))
W = tuple(sorted(r*U+i for i, (l, r) in enumerate(LR)))
B = [0]*(n+1)
def add(i, a):
  while i <= n:
    B[i] += a
    i += i & -i
def acc(i):
  res = 0
  while i:
    res += B[i]
    i -= i & -i
  return res
temp = 1
for w in W:
  r, i = divmod(w, U)
  while temp <= r:
    c = C[temp]
    add(temp, 1)
    if D[c] != -1:
      add(D[c], -1)
    D[c] = temp
    temp += 1
  l = LR[i][0]
  A[i] = acc(r) - acc(l-1)
print(*A, sep="\n")

Measured memory_bytes: 239636
#include <cstdio>
#include <algorithm>
#define maxn 100000+10
using namespace std;

int n,a[maxn],l=-1,r=-1,pos;

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for (int i=n;i>1;--i)
	  if (a[i]==a[i-1]) 
	  {
	  	l=a[i],pos=i-2;break;
	  }
	for (int i=pos;i>1;--i)
	  if (a[i]==a[i-1]) 
	  {
	  	r=a[i];break;
	  }
	if (r<0) printf("0\n");
	else printf("%lld\n",(long long)l*(long long)r);
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
char a[16], b[16] = {'C', 'O', 'D', 'E', 'F', 'E', 'S', 'T', 'I', 'V', 'A', 'L', '2', '0', '1', '6'};
int ans;
int main()
{
	cin >> a;
	for(int i = 0; i < 16; i ++){
		if(a[i] != b[i]) ans ++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>

using namespace std;

typedef pair <double, string> P;

int main(void)
{
	int n;
	while (cin >> n, n){
		int p, a, b, c, d, e, f, s, m;
		string l;
		vector <P> ret;
		for (int i = 0; i < n; i++){
			cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
			double per = (double)(f * s * m - p) / (a + b + c + ((d + e) * m));
			ret.push_back(make_pair(-per, l));
		}
		sort(ret.rbegin(), ret.rend());
		for (int i = n-1; 0 <= i; i--){
			cout << ret[i].second << endl;
		}
		puts("#");
	}

	return 0;
}

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

int main() {
  vector<int> ant(5);
  rep(i,5){
    cin >> ant.at(i);
  }
  int k = 0;
  cin >> k;
  sort(ant.begin(),ant.end());
  if(ant.at(4) - ant.at(0) <= k){
    cout << "Yay!" << endl;
  }
  else{
    cout <<":(" << endl;
  }
}
  
  
    

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int n, blacks = 0, s[200000] = { }, currentblack_white = 0, maxblack_white = 0;
  scanf("%d\n", &n);
  for (int i = 0; i < n; i++) {
    if (getchar() == '#') {
      blacks++;
      s[i] = 1;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 1) {
      currentblack_white++;
      if (currentblack_white > maxblack_white) {
        maxblack_white = currentblack_white;
      }
    } else {
      currentblack_white--;
    }
  }
  printf("%d\n", blacks - maxblack_white);
  return 0;
}


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

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

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int a, b;
  cin >> a >> b;
  cout << (a<=8&&b<=8&&a+b<=16?"Yay!":":(") << endl;

  return 0;
}


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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int main(){
	string s;
	string t;
	cin >> s;
	cin >> t;
	if(s.length()>t.length()) cout <<"GREATER";
	else if(t.length()>s.length()) cout <<"LESS";
	else {
		int i=0;
		while(i < s.length()){	
			if(s[i]==t[i]) i++;
			if(s[i] < t[i]) {
				cout << "LESS";
				break;
			}
			if(s[i] > t[i]){
				cout << "GREATER";
				break;
			}
		}
		if(i==s.length()) cout <<"EQUAL";
	}

	return 0;
}

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

#define fi first
#define se second
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int(v.size())
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

template<class T, class U> void chmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> void chmin(T &a, U b) { if (b < a) a = b; }

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

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

  if (a < 6) cout << 0 << endl;
  else if (a < 13) cout << b/2 << endl;
  else cout << b << endl;
  
  return (0);
}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int w, h, p, q;
vector<pair<int,char>> vec;
int ans;
int maw, mah;

signed main() {
	cin >> w >> h;
	maw = h + 1;
	mah = w + 1;
	for (int i = 0; i < w; i++) {
		cin >> p;
		vec.push_back({ p,'W' });
	}
	for (int i = 0; i < h; i++) {
		cin >> q;
		vec.push_back({ q,'H' });
	}
	sort(all(vec));
	for (int i = 0; i < w + h; i++) {
		if (vec[i].second == 'W') {
			ans += vec[i].first*maw;
			mah--;
		}
		else {
			ans += vec[i].first*mah;
			maw--;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 6512
#include <string>
#include <iostream>
using namespace std;
string s;
int main() {
	getline(cin, s);
	for(int i = 0; i < s.size() - 4; i++) {
		string t = s.substr(i, 5);
		if(t == "apple") s.replace(s.begin() + i, s.begin() + i + 5, "peach");
		if(t == "peach") s.replace(s.begin() + i, s.begin() + i + 5, "apple");
	}
	cout << s << endl;
}

Measured memory_bytes: 3132
#include<iostream>

using namespace std;

int main(){
 int n, m;
  cin >> n >> m;
  
  int sum{};
  int a;
  for(int i=0; i<m; i++)
  	cin >> a, sum += a;
  
  if(n-sum < 0)
    cout << -1;
  else
    cout << n-sum;
  
  
  
}

Measured memory_bytes: 3568
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n, k;
    cin >> n >> k;
    vi l(n);
    for (int i = 0; i < n; ++i) {
        cin >> l[i];
    }
    sort(l.begin(), l.end(), greater<int>());
    int ret = 0;
    for (int i = 0; i < k; ++i) {
        ret += l[i];
    }
    cout << ret << "\n";
    return 0;
}

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

ll gcd(ll a,ll b){
    if(a<b)return gcd(b,a);
    if(a%b==0)return b;
    return gcd(b ,a%b);
}
int main(){
    ll n;cin >> n;
    vector<ll>t(n);
    for(int i=0;i<n;i++) cin >> t[i];

    ll lcm = t[0];
    for(int i=1;i<n;i++) lcm = (lcm/gcd(t[i] ,lcm))*t[i];
    cout << lcm << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
x = list(map(int, input().split())) 
y = list(map(int, input().split()))

MOD = 1000000007

w = sum(
  (x[i+1] - x[i]) * (i + 1) * (n - 1 - i) % MOD 
  for i
  in range(n-1)
) % MOD 

h = sum(
  (y[i+1] - y[i]) * (i + 1) * (m - 1 - i) % MOD 
  for i
  in range(m-1)
) % MOD 

print(w*h % MOD)

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

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n)  FOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)


class BSmallAndLargeIntegers {
public:
	void solve(std::istream& in, std::ostream& out) {
    int a,b,k;
    in >> a >> b >> k;
    set<int> s;
    REP(i, min(k, b - a + 1)){
      s.insert(a + i);
    }
    REP(i, min(k, b - a + 1)){
      s.insert(b - i);
    }
    ITR(itr, s){
      out << *itr << endl;
    }
	}
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
	BSmallAndLargeIntegers solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3612
n = int(input())
a = [0]*n
b = [0]*n
c = [0]*n
for i in range(n):
    a[i], b[i], c[i] = map(int, input().split())

dpa = [a[0]]+[0]*(n-1)
dpb = [b[0]]+[0]*(n-1)
dpc = [c[0]]+[0]*(n-1)
for i in range(1,n):
    dpa[i] = max(dpb[i-1],dpc[i-1])+a[i]
    dpb[i] = max(dpc[i-1],dpa[i-1])+b[i]
    dpc[i] = max(dpa[i-1],dpb[i-1])+c[i]

print(max(dpa[-1], dpb[-1], dpc[-1]))

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

int main (){
  long long num[10001];
  num[0]=1;
  for(int i=1;i<=10000;i++) num[i]=num[i-1]+i;
  int n;
  while(cin>>n)
    cout <<num[n]<<endl;
  return 0;
}

Measured memory_bytes: 1232
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;	
	
int main()
{
	int r,d,n;
	
	cin >> r >> d >>n;
	
	for(int i=0;i<10;i++){
		cout << (n*r)-d << endl;
		
		n = (n*r)-d;
	}
	
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		
		if (s.equals("Sunny")){
			System.out.println("Cloudy");
		} else if(s.equals("Cloudy")){
			System.out.println("Rainy ");
		} else {
			System.out.println("Sunny");
		}
	}
}

Measured memory_bytes: 20436
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int ans = 0;
    rep(i, N) {
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 256
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

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

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

signed main(){
    FastIO;
    string s;
    cin>>s;
    cout<<(s=="ABC"?"ARC":"ABC");
    return 0;
}


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

using namespace std;

const int N = 3000, mod = int(1e9) + 7;

int fpow(int x, int y) {
	int r = 1;
	for (; y; y >>= 1, x = 1LL * x * x % mod)
		if (y & 1) r = 1LL * r * x % mod;
	return r;
}

const int inv2 = (mod + 1) / 2;

int n, q, a[N + 5], dp[N + 5][N + 5];

int main() {
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; ++i) scanf("%d", a + i);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			dp[i][j] = a[i] > a[j];

	for (int i = 1; i <= q; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		dp[x][y] = dp[y][x] = 1LL * (dp[x][y] + dp[y][x]) * inv2 % mod;
		for (int j = 1; j <= n; ++j)
			if (j != x && j != y) {
				dp[x][j] = dp[y][j] = 1LL * (dp[x][j] + dp[y][j]) * inv2 % mod;
				dp[j][x] = dp[j][y] = 1LL * (dp[j][x] + dp[j][y]) * inv2 % mod;
			}
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i)
		for (int j = i + 1; j <= n; ++j)
			ans = (ans + dp[i][j]) % mod;
	ans = 1LL * ans * fpow(2, q) % mod;
	printf("%d\n", ans);
}

Measured memory_bytes: 39020
H, W = list(map(int, input().split()))  #リスト
A = list(input() for i in range(H)) #スペース抜きの複数行
#A = [input() for _ in range(H)]

B = [False] * H
C = [False] * W

for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            B[i] = True
            C[j] = True

for i in range(H):
	if B[i]:
		for j in range(W):
			if C[j]:
				print(A[i][j], end = '')
		print()

Measured memory_bytes: 4468
// Problem : B - Break Number
// Contest : AtCoder - AtCoder Beginner Contest 068
// URL : https://atcoder.jp/contests/abc068/tasks/abc068_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
int n;cin>>n;
int ans=1,cnt=0;
for(int i=2;i<=n;i++)
{
	int t=i;int cntt=0;
	while(t%2==0)
	{
		cntt++;
		t/=2;
	}
	if(cntt>cnt)
	{
		cnt=cntt;
		ans=i;
	}
}
cout<<ans;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll W, a, b;
        cin >> W >> a >> b;
        ll ans = -inf;
        if (a+W <= b) {
                ans = b - (a+W);
        } else if ((a <= b and b <= a+W) or (a <= b+W and b+W <= a+W)) {
                ans = 0;
        } else if (b+W <= a) {
                ans = a - (b+W);
        }
        cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define Max(x,y) ((x>y)?x:y)

long long t[100005],ans;
int m,len[100005];
long long func(int n){
	long long x=0;
	if(len[n]==0)return t[n];
	if(len[n]>len[n-1] && len[n]>len[n+1]){
		if(len[n-1]==0)x=Max(x,t[n-1]);
		if(len[n+1]==0)x=Max(x,t[n+1]);
	}
	else if(len[n-1]<len[n] && len[n]<len[n+1]){
		x=func(n+1);
		if(len[n-1]==0)x=Max(x,t[n-1]);
	}
	else if(len[n-1]>len[n] && len[n]>len[n+1]){
		x=func(n-1);
		if(len[n+1]==0)x=Max(x,t[n+1]);
	}
	else x=Max(func(n-1),func(n+1));
	t[n]=x+m-len[n];
	len[n]=0;
	return t[n];
}
int main(){
	int i,j,n;
	scanf("%d%d",&n,&m);
	len[0]=len[n+1]=0;
	for(i=1;i<=n;i++)scanf("%d",&len[i]);
	memset(t,0,sizeof(t));
	ans=0;
	for(i=1;i<=n;i++){
		ans=Max(ans,func(i));
		//printf("%lld\n",func(i));
	}
	printf("%lld\n",ans);
	
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define N 100100
lli n, k;

int main(void){
	cin >> n >> k;
	vector<lli> a(N);
	rep(i, n){
		lli ai, bi;
		cin >> ai >> bi;
		a[ai]+=bi;
	}
	lli s = 0;
	for(int i = 1; i <= N; i++){
		s+=a[i];
		if(s >= k){
			cout << i << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 4044