akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int MaxN = 200003;
#define x0 Fuck_the_GCC_header_x0
#define y0 Fuck_the_GCC_header_y0
#define x1 Fuck_the_GCC_header_x1
#define y1 Fuck_the_GCC_header_y1
#define X first
#define Y second
int x0,x1,y0,y1,n,cnt;
#define M_PI 3.14159265358979323846
constexpr double len=M_PI*20,len2=M_PI*10,len4=M_PI*5;
PII e[MaxN];
int a[MaxN],mn[MaxN];

int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    cin >> x0 >> y0 >> x1 >> y1 >> n;
    if (x0>x1) {swap(x0,x1);swap(y0,y1);}
    cout << fixed << setprecision(15);
    cnt=0;
    for (int i=1;i<=n;++i) {
        int x,y;
        cin >> x >> y;
        if (x<min(x0,x1) || x>max(x0,x1) || y<min(y0,y1) || y>max(y0,y1)) continue;
        cnt++;
        e[cnt].first=x,e[cnt].second=y;
    }
    if (x1==x0) {
        double ans=(long long)abs(y1-y0)*100LL;
        for (int i=1;i<=cnt;++i) if (e[cnt].X==x1) ans=ans-20LL+len2;
        cout << ans << endl;
        return 0;
    }
    if (y1==y0) {
        double ans=(long long)abs(x1-x0)*100LL;
        for (int i=1;i<=cnt;++i) if (e[cnt].Y==y1) ans=ans-20LL+len2;
        cout << ans << endl;
        return 0;
    }
    sort(e+1,e+cnt+1);
    //if (x1<x0) reverse(e+1,e+cnt+1);
    if (y1<y0) for (int i=1;i<=cnt;++i) e[i].Y=2LL*y0-e[i].Y;
    for (int i=1;i<=cnt;++i) a[i]=e[i].Y;
    for (int i=1;i<=cnt;++i) mn[i]=0x7fffffff;
    mn[0]=0x80000000;
    int sum=0;
    for (int i=1;i<=cnt;++i) {
        int x=lower_bound(mn,mn+cnt+1,a[i])-mn;
        mn[x]=a[i];
        sum=max(sum,x);
    }
    double ans=100LL*(abs(x0-x1)+abs(y0-y1));
    if (sum==abs(x0-x1)+1 || sum==abs(y0-y1)+1) ans+=len4;
    ans=ans-20*sum+len4*sum;
    cout << ans << endl;
    return 0;
}

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

#define ll long long

using namespace std;

int main() {

	ll x,k,d;

	cin >> x >> k >> d;

	ll val = abs(x)/d;

	if(k>=val)
	{
		ll n = abs(x) - (val * d);
		k -= val;
		if(k%2 == 0)
		cout << n;
		else
		{
			n -= d;
			cout << abs(n);
		}
	}
	else
	{
		ll n = abs(x) - (k*d);
		cout << n;
	}
}


Measured memory_bytes: 3640
from sys import stdin
from collections import deque
V, E = map(int, stdin.readline().split())
adj_list = [[] for _ in [0] * V]
is_visited = [False] * V
for _ in [0] * E:
    s, t = map(int, stdin.readline().split())
    adj_list[s].append(t)
out = deque()
def dfs(u):
    is_visited[u] = True
    for v in adj_list[u]:
        if not is_visited[v]:
            dfs(v)
    out.appendleft(u)
for s in range(V):
    if not is_visited[s]:
        dfs(s)
print(*out, sep='\n')

Measured memory_bytes: 11332
#include <iostream>
using namespace std;
 
int main() {
	int a,b;
	cin >> a;
	b=0;
	for(int i = a;i>0;i--){
		if(0<i&&i<10){b++;}
		else if(99<i&&i<1000){b++;}
		else if(9999<i&&i<100000){b++;}
	}
	cout << b << endl;
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;
int main() {
    int N;
    cin >> N;
    int i = 0;
    int ookii = 0;
    int kosuu = 0;
    while(i < N){
        int H;
        cin >> H;
        if(H >= ookii){
            ookii = H;
            i++;
            kosuu++;
        }
        else{
            i++;    
        }
    }
    cout << kosuu <<endl;
}

Measured memory_bytes: 256
n = int(input())
w = list(map(int, input().split()))
s = [0]
ans = 10**18
ws = sum(w)
for i in w:
    s.append(s[-1]+i)
for i in range(1, n+1):
    ans = min(ans, abs((ws-s[i])-s[i]))
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cassert>
#include <string>
#include <cmath>
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define lowbit(x) (x & -x)
using namespace std;
typedef long long ll;
const int MAX = 0x7ffffff;
int t;

void slove()
{
	int n;
	cin >> n;
	ll sum = 0;
	for(int i = 1;i <= n ;i ++)
	{
		if(i % 3 == 0 || i % 5 == 0)continue;
		else sum += i;
	}
	cout <<  sum << endl;
}
int main()
{
	SIS;
	slove();
}

Measured memory_bytes: 3648
#include <stdio.h>

int main()
{
    int n,a;
    scanf("%d", &n);
    scanf("%d", &a);
    int max = a,min = a;
    long long sum = a;

    for(int i=2;i<=n;i++) {
        scanf("%d", &a);
        if(max<a)
          max=a;
        else if(min>a)
          min=a;
        sum += a;
    }

    printf("%d %d %ld\n", min, max,sum);
    return 0;
}



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

using namespace std;

int pow2(int n){
    int ret=1;
    while(n>0){
        ret=ret*2;
        --n;
    }
    return ret;
}

inline string recov(string s,int key){
    for (int i = 0; i < s.size(); ++i) {
        if(key&(1<<i)){
            ++s[i];
        }
    }
    return s;
}

int main(){
    string s;
    while(true){
        cin>>s;
        if(s=="#")break;
        int bitmax=pow2(s.size());
        vector<string> ans;
        for (int i = 0; i < bitmax; ++i) {
            vector<bool> changed(26,false);
            bool valid=true;
            for (int j = 0; j < s.size(); ++j) {
                if(i&(1<<j)){//変更されてる
                    if(s[j]=='z'){
                        valid=false;
                        break;
                    }
                    if(changed[s[j]-'a']){
                        valid=false;
                        break;
                    }
                    else{
                        changed[s[j]-'a']=true;
                    }
                }
                else{
                    if(s[j]=='a')continue;
                    if(!changed[s[j]-'a'-1]){
                        valid=false;
                        break;
                    }
                }
            }
            if(valid){
                ans.push_back(recov(s,i));
            }
        }
        cout<<ans.size()<<endl;
        sort(ans.begin(),ans.end());
        if(ans.size()==0)continue;
        else if(ans.size()<=10){
            for(auto i:ans)cout<<i<<endl;
        }
        else{
            for (int i = 0; i < 5; ++i) {
                cout<<ans[i]<<endl;
            }
            for (int j = 0; j < 5; ++j) {
                cout<<ans[ans.size()-1-(4-j)]<<endl;
            }
        }
    }
    return 0;
}


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

#define mod 1000000007

using namespace std;
typedef long long ll; 
 
int main(void){
	
	ll A, B;
	
	cin >> A >> B;
	
	if((A + B) % 2 == 0)
		cout << (A + B) / 2;
	else
		cout << "IMPOSSIBLE";
	
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<double, double> P;

int main()
{
	int a, b, c, d, flg;
	
	
	cin >> a >> b >> c >> d;
	
	if (c + c == a && d + d == b) {
		flg = 1;
	} else {
		flg = 0;
	}
	
	// 標準出力
	cout << double(a) * double(b) / 2;
	cout << " ";
	cout << flg << endl;
	
	return 0;
}

	

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

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

// int main(){
//     int x;
//     cin >> x;
//     if(x){
//         cout << "0";
//     }else{
//         cout << "1";
//     }
//     return 0;
// }

int main () {
    long long a, b, c, d;
    long long o,p,q,r, ans;
    cin >> a >> b >> c >> d;
    o = a * c;
    p = a * d;
    q = b * c;
    r = b * d;

    ans = max(max(o,p), max(q,r));
    //if(ans < 0 && (((a<0 && b>0)) || ((c<0) && (d>0)))) ans = 0;

    cout << ans;
 }
// const int MOD = 1000000007;
// int main(){
//     int n,m=1;
//     unsigned long int ans;
//     cin >> n;

//     for(int i=2; i<n+1; i++){
//         for(int j=n; j>n-i; j--){
//             m = m*j*8/(n-j+1)%MOD;
//         }
//         ans += m;
//     }

//     // ans = n*(n-1)%MOD;
//     // for(int i = 0; i<n-2; i++){
//     //     ans = (ans * 10)%MOD; 
//     // }
//     cout << ans;
//}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll gcd(ll a,ll b){
  ll r = a%b;
  while(r > 0){
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,x;cin>>n>>x;
  ll ho = -1;
  while(n--){
    ll a;cin>>a;
    if(ho == -1)ho = abs(x-a);
    else ho = gcd(ho,abs(x-a));
  }
  cout<<ho<<endl;
  return 0;
}


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

int main(){
	string s,t;
	cin>>s;
	cin>>t;
	int ans = 0;
	for(int i=0;i<s.size();i++){
		if(s[i]!=t[i])ans++;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3916
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n,k,h[100000],df=1000000000;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    sort(h,h+n);
    for(int i=0;i<=n-k;i++){
        if(h[i+k-1]-h[i]<df){
            df=h[i+k-1]-h[i];
        }
    }
    cout<<df<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;
ll n, m, x;
vector<ll> c;
vector<vector<ll>> a;

ll ans;

void dfs(int state, ll b){
  if (b == n){
    vector<ll> sum(m, 0);
    ll cost = 0;
    for (int i = 0; i < n; i++){
      if ((state >> i) & 1){
        cost += c[i];
        for (int j = 0; j < m; j++){
          sum[j] += a[i][j];
        }
      }
    }
    int ok = 1;
    for (int j = 0; j < m; j++){
      if (sum[j] < x)
        ok = 0;
    }
    if (ok){
      ans = min(ans, cost);
    }
  }
  else {
    dfs(state, b + 1);
    dfs(state | (1 << b), b + 1);
  }
}


int main(void){
  cin >> n >> m >> x;

  c = vector<ll>(n);
  a = vector<vector<ll>>(n, vector<ll>(m));
  for (int i = 0; i < n; i++){
    cin >> c[i];
    for (int j = 0; j < m; j++){
      cin >> a[i][j];
    }
  }
  ans = INF;
  
  dfs(0, 0);
  if (ans == INF){
    cout << -1 << endl;
  }
  else
    cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3632
n = int(input())
a = list(map(int, input().split()))

res1 = 0
S = 0
# 偶数番目のとき正
for i in range(n):
    S += a[i]
    if i % 2 == 0:
        if S <= 0:
            res1 += abs(1 - S)
            S = 1
    else:
        if S >= 0:
            res1 += abs(-1 - S)
            S = -1

res2 = 0
S = 0
for i in range(n):
    S += a[i]
    if i % 2 == 1:
        if S <= 0:
            res2 += abs(1 - S)
            S = 1
    else:
        if S >= 0:
            res2 += abs(-1 - S)
            S = -1

print(min(res1, res2))


Measured memory_bytes: 14468
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    vector<int> a;
    cin >> n;
    for(int i = 0;i<n;i++){
      int z;
      scanf("%d",&z);
      z--;
      a.push_back(z);
    }
    int now = 0,c = 0;
    for(;;){
        if(now == 1){
            cout << c <<endl;
            break;
        }
        if(c >= n){
            cout << -1 <<endl;
            break;
        }
        c++;
        now = a[now];
    }
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class Task{
public:
    void solve(istream& in, ostream& out){
        int N;
        in>>N;
        vc<int> A(N);
        REP(i, N) in>>A[i];
        int h = 0, ans = 0;
        REP(i, N){
            ans += max(A[i] - h, 0);
            h = A[i];
        }
        out<<ans<<'\n';
    }
};

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

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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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


#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/

// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
	os << "(" << pair_var.first << ", " << pair_var.second << ")";
	return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
	os << "{";
	for (int i = 0; i < vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
	}
	os << "}";
	return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
	os << "{";
	repi(itr, map_var) {
		os << *itr;
		itr++;
		if (itr != map_var.end()) os << ", ";
		itr--;
	}
	os << "}";
	return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
	os << "{";
	repi(itr, set_var) {
		os << *itr;
		itr++;
		if (itr != set_var.end()) os << ", ";
		itr--;
	}
	os << "}";
	return os;
}

#define DUMPOUT cerr

void dump_func() {
	DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
	DUMPOUT << head;
	if (sizeof...(Tail) > 0) {
		DUMPOUT << ", ";
	}
	dump_func(std::move(tail)...);
}
#ifdef _DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


int N, K;
vector<int> A, F;

// valが可能かどうか
bool isOK(int val) {
	int k = 0;
	rep(i, N) {
		if (A[i] * F[i] >= val) k += ceil(A[i] - (double)val / F[i] - 0.00000001);
	}
	if (k <= K) return true;
	else return false;
}


signed main() {

	cin >> N >> K;
	A.resize(N); F.resize(N);
	rep(i, N) cin >> A[i];
	rep(i, N) cin >> F[i];


	sort(F.begin(), F.end(), greater<int>());

	sort(A.begin(), A.end());

	int ng = -1;
	int ok = 1000000000000;

	while (abs(ok - ng) > 1) {
		int mid = (ok + ng) / 2;

		if (isOK(mid)) ok = mid;
		else ng = mid;
	}

	cout << ok << endl;

	return 0;
}


Measured memory_bytes: 3328
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	for(int i=0;10000;i++){
		int v = in();
		if(!v) break;
		cout<<"Case "<<i+1<<": "<<v<<endl;
	}
	
	return 0;
}



Measured memory_bytes: 3032
X[8],Y[8],Z[8];char*R="012024031043135152254345120240310430351521542453201402103304513215425534",D[8][7];S(p,u,d,r){p-8||main(puts("YES"));for(r=p?24:1;r--;)for(d=8;d--;)u&1<<d&&(~p&1?X[p]=D[d][R[r]-48]:(X[p-1]^D[d][53-R[r]])==32)&&(~p&2?Y[p]=D[d][R[r+24]-48]:(Y[p-2]^D[d][53-R[r+24]])==32)&&(~p&4?Z[p]=D[d][R[r+48]-48]:(Z[p-4]^D[d][53-R[r+48]])==32)&&S(p+1,u^1<<d);}main(){for(;read(0,D,56)==56;puts("NO"))S(0,255);exit(0);}

Measured memory_bytes: 332
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int MOD = 1000000007;
const int N = 3005;

int n, q, i, j, tab[N], GR[N][N], LE[N][N], GR1[N][N], LE1[N][N], a[N], b[N], a1, b1, res, k, mn;

int div(int w) {
	if (w % 2 == 0) return w / 2;
	return (w + MOD) / 2;
}

int main() {
scanf("%d %d", &n, &q);
for (i=1;i<=n;i++) scanf("%d", &tab[i]);
for (i=0;i<q;i++) {
	scanf("%d %d", &a[i], &b[i]);
	if (a[i] > b[i]) swap(a[i], b[i]);
}
for (i=1;i<=n;i++) for (j=i + 1;j<=n;j++) {
	GR[i][j] = tab[i] > tab[j] ? 1 : 0;
	LE[i][j] = tab[i] < tab[j] ? 1 : 0;
}
mn = 1;
for (k = 0;k < q;k++) {
	mn = (mn * 2) % MOD;
	a1 = a[k];
	b1 = b[k];
	GR1[a1][b1] = LE1[a1][b1] = div((GR[a1][b1] + LE[a1][b1]) % MOD);
	for (i = 1;i < a1;i++) {
		GR1[i][a1] = div((GR[i][a1] + GR[i][b1]) % MOD);
		LE1[i][a1] = div((LE[i][a1] + LE[i][b1]) % MOD);
	}		
	for (i = a1 + 1;i <= n;i++) if (i != b1) {
		GR1[a1][i] = div((GR[a1][i] + (i > b1 ? GR[b1][i] : LE[i][b1])) % MOD);
		LE1[a1][i] = div((LE[a1][i] + (i > b1 ? LE[b1][i] : GR[i][b1])) % MOD);
	}
	for (i = 1;i<b1;i++) if (i != a1) {
		GR1[i][b1] = div((GR[i][b1] + (i < a1 ? GR[i][a1] : LE[a1][i])) % MOD);
		LE1[i][b1] = div((LE[i][b1] + (i < a1 ? LE[i][a1] : GR[a1][i])) % MOD);
	}
	for (i = b1 + 1; i<= n;i++) {
		GR1[b1][i] = div((GR[b1][i] + GR[a1][i]) % MOD);
		LE1[b1][i] = div((LE[b1][i] + LE[a1][i]) % MOD);
	}
	
	for (i=1;i<=n;i++) if (i != a1) {
		GR[min(a1, i)][max(a1, i)] = GR1[min(a1, i)][max(a1, i)];
		LE[min(a1, i)][max(a1, i)] = LE1[min(a1, i)][max(a1, i)];
	}
	for (i=1;i<=n;i++) if (i != b1) {
		GR[min(b1, i)][max(b1, i)] = GR1[min(b1, i)][max(b1, i)];
		LE[min(b1, i)][max(b1, i)] = LE1[min(b1, i)][max(b1, i)];
	}
}

res = 0;
for (i=1;i<=n;i++) for (j=i + 1;j<=n;j++) {
	res = ((GR[i][j] * 1LL * mn) + res) % MOD; 
	//printf("%d %d %d\n", i, j, res);
}
printf("%d\n", res);
return 0;
}



Measured memory_bytes: 140160
#!/usr/bin/env python3
import sys
# input = sys.stdin.r/eadline
def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))

def main():
    N = INT()
    A = LI()
    count = 0
    for i in range(N):
        if A[i]&1:
            count += 1
    if count&1:
        print('NO')
    else:
        print('YES')


if __name__ == '__main__':
    main()


Measured memory_bytes: 14104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<class U, class V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}

struct Edge {
    int u, v;
    int dir = 0;
    bool spanning = false;
};

int N, M;
vector<Edge*> edges;
vector<vector<Edge*>> adj;
vector<int> parent;
vector<int> out;

void dfs(int curr, int prev) {
    parent[curr] = prev;
    for(auto e : adj[curr]) {
        int next;
        if(e->u == curr) next = e->v;
        else next = e->u;
        if(parent[curr] != next && parent[next] == -1) {
            dfs(next, curr);
            e->spanning = true;
        }
    }
}

void setDirection(int curr) {
    for(auto e : adj[curr]) {
        if(e->spanning) {
            int next;
            if(e->u == curr) next = e->v;
            else next = e->u;
            if(parent[curr] != next) {
                setDirection(next);
                if(out[next] % 2 == 0) {
                    if(curr == e->u) {
                        e->dir = 1;
                        out[curr]++;
                    } else {
                        e->dir = -1;
                        out[curr]++;
                    }
                } else {
                    if(curr == e->u) {
                        e->dir = -1;
                        out[next]++;
                    } else {
                        e->dir = 1;
                        out[next]++;
                    }
                }
            }
        }
    } 
}


int main() {
    FAST_IO();
    int N, M; cin >> N >> M;
    adj.resize(N);
    rep(i, M) {
        Edge *e = new Edge();
        cin >> e->u >> e->v;
        --(e->u); --(e->v);
        edges.push_back(e);
        adj[e->u].push_back(e);
        adj[e->v].push_back(e);
    }
    // if M is odd -> impossible
    if(M % 2 == 1) {
        cout << "-1\n";
        return 0;
    }
    // make spanning tree
    parent.resize(N, -1);
    dfs(0, -2);
    out.resize(N, 0);
    for(auto e : edges) {
        if(e->spanning == false) {
            e->dir = 1;
            out[e->u]++;
        }
    }
    setDirection(0);
    for(auto e : edges) {
        if(e->dir == 1) {
            cout << e->u + 1 << " " << e->v + 1 << "\n";
        } else if(e->dir == -1) {
            cout << e->v + 1 << " " << e->u + 1 << "\n";
        } else {
            cout << "FUCK\n";
        }
    }
}


Measured memory_bytes: 17780
#include<bits/stdc++.h>
#include<cmath>
#define PB push_back
#define REP(i,a,b) for(int i=a; i<b; i++)
typedef long long ll;
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,d,ans=0;
	cin>>n>>d;
	d=d*d;
	for(int i=0; i<n; i++){
		ll x,y;
		cin>>x>>y;
		if(x*x+y*y<=d) ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 3588
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		int X = sc.nextInt();
		boolean ans = true;
		if(A > X) ans = false;
		if(A + B < X + 1) ans = false;
		
		System.out.println(ans?"YES":"NO");
	}
}

Measured memory_bytes: 23124
#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
using namespace std;
typedef pair<int,int> PII;
int n,m;
int an;
int q[2050];
int head[2050];
int id[2050][2050];
int anc[2050][2050];
struct edge
{
	int to,nex;
	edge(int to=0,int nex=0):to(to),nex(nex){}
};
vector<edge> G;
void addedge(int u,int v)
{
	G.push_back(edge(v,head[u])),head[u]=G.size()-1;
	G.push_back(edge(u,head[v])),head[v]=G.size()-1;
}
void BFS(int a,int b,vector<PII> &E)
{
	int hd=0,tl=0;
	q[tl++]=b;
	while(hd<tl)
	{
		int u=q[hd++];
		for(int i=head[u];~i;i=G[i].nex)
		{
			int v=G[i].to;
			if(v!=anc[a][u])
			{
				if(id[a][v]!=-1)
				{
					E.push_back(make_pair(b,v));
					continue;
				}
				id[a][v]=b;
				q[tl++]=v;
			}
		}
	}
}
void adde(int a,int b)
{
	if(a==b)
	{
		return;
	}
	if(id[a][b]!=-1)
	{
		adde(id[a][b],b);
		return;
	}
	if(id[b][a]!=-1)
	{
		adde(id[b][a],a);
		return;
	}
	vector<PII> E;
	id[a][b]=b,BFS(a,b,E);
	id[b][a]=a,BFS(b,a,E);
	for(unsigned int i=0;i<E.size();++i)
	{
		adde(E[i].first,E[i].second);
	}
}
void dfs1(int u,int root)
{
	for(int i=head[u];~i;i=G[i].nex)
	{
		int v=G[i].to;
		if(v!=anc[root][u])
		{
			anc[root][v]=u;
			dfs1(v,root);
		}
	}
}
void dfs2(int u,int lst)
{
	int t=lst;
	if(id[lst][u]!=-1)
	{
		++an;
		t=u;
	}
	for(int i=head[u];~i;i=G[i].nex)
	{
		int v=G[i].to;
		if(v!=anc[lst][u])
		{
			dfs2(v,t);
		}
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	memset(head,-1,sizeof(head));
	for(int i=1;i<n;++i)
	{
		int u,v; scanf("%d%d",&u,&v);
		addedge(u,v);
	}
	for(int i=1;i<=n;++i)
	{
		anc[i][i]=-1;
		dfs1(i,i);
	}
	memset(id,-1,sizeof(id));
	for(int i=1;i<=m;++i)
	{
		int a,b; scanf("%d%d",&a,&b);
		adde(a,b);
	}
	for(int i=1;i<=n;++i)
	{
		dfs2(i,i);
	}
	an>>=1;
	printf("%d\n",an);
	return 0;
}

Measured memory_bytes: 33280
// UNNECESSARY
// #include <chrono>//std::chrono::/system_clock/steady_clock/high_resolution_clock/duration
// #include <cstdio>//printf/scanf/fopen/fclose/fprintf/fscanf/snprintf/putc/puts/getc/gets
// #include <fstream>//ifstream/ofstream

// DATA STRUCTURES
#include <array>
#include <bitset>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <valarray>
#include <vector>

// MISCELLANEOUS
#include <algorithm>//min/max/sort(rand-access it)/merge
#include <cassert>
#include <climits>//INT_MAX/INT_MIN/ULLONG_MAX
#include <cmath>//fmin/fmax/fabs/sin(h)/cos(h)/tan(h)/exp/log/pow/sqrt/cbrt/ceil/floor/round/trunc
#include <cstdlib>//abs/atof/atoi/atol/atoll/strtod/strtof/..., srand/rand, calloc/malloc, exit, qsort
#include <iomanip>//setfill/setw/setprecision/fixed/scientific
#include <iostream>//cin/cout/wcin/wcout/left/right/internal/dec/hex/oct/fixed/scientific
#include <iterator>
#include <limits>//numeric_limits<type>::max/min/lowest/epsilon/infinity/quiet_NaN/signaling_NaN
#include <new>
#include <string>//stoi/stol/stoul/stoll/stoull/stof/stod/stold/to_string/getline
#include <utility>//pair

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

#ifndef REPST
#define REPST(i,n) for (size_t i = 0; i < n; ++i)
#endif

#ifndef READ
#define READ(x) std::cin >> x
#endif

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> plli;
typedef std::pair<ull, int> puli;
typedef std::pair<double, int> pdi;
typedef std::pair<ll, ll> pllll;
typedef std::pair<ull, ull> pulul;
typedef std::pair<double, double> pdd;
typedef std::tuple<int, int, int> ti3;
typedef std::tuple<int, int, int, int> ti4;

const bool debug = true;

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

using namespace std;

int main(void)
{
    int D, N;
    cin >> D >> N;
    if (N == 100) N = 101;
    if (D == 0) {
        cout << to_string(N) << endl;
    } else if (D == 1) {
        cout << to_string(N) + "00" << endl;
    } else {
        cout << to_string(N) + "0000" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> VI;
typedef vector<long long int> VLLI;
typedef vector<pair<int, int> > VPI;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll, ll> PLL;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

int main() {
    int k;
    string s;
    cin >> k >> s;
    if (s.length() > k) {
        cout << s.substr(0, k) + "...\n";
    } else {
        cout << s << "\n";
    }
}



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

int main() {
	int n,a[55],b[55];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		b[i]=a[i];
	}
	sort(a,a+n);
	int t=0;
	for(int i=0;i<n;i++){
		if(a[i]!=b[i]){
			t++;
		}
	}
	if(t>2)
		printf("NO\n");
	else
		printf("YES\n");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define ll long long
#define debug(x) cout << "debug: " << x << endl
const int MOD = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    vector<int> dp_table(n + 1, 0);
    dp_table[2] = abs(h[1] - h[0]);
    repk(i, 3, n + 1) {
        dp_table[i] = min(abs(h[i - 1] - h[i - 2]) + dp_table[i - 1],
                          abs(h[i - 1] - h[i - 3]) + dp_table[i - 2]);
    }
    cout << dp_table[n] << endl;
}

Measured memory_bytes: 1024
A,B= map(int,input().split())
S = input()
flag = 0
#フラグ関数。　条件を満たしているかどうかを判定する。 0以外なら条件を満たしていない。
if S[A] == "-":
  for i in range(0,A):
    if 48<=ord(S[i])<=57:
      #ここではasciiコード (0 = 48, 9 = 57)を用いていますが、整数をリストにした解法でも大丈夫です。
      continue
    else:
      flag += 1
      break
  for i in range(A+1,A+B+1):
    if 48<=ord(S[i])<=57:
      continue
    else:
      flag += 1
      break
else:
  flag += 1
if flag == 0:
  print("Yes")
else:
  print("No")

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    int ans = 0;
    for(int i=0; i<N; i++)
    {
        if(i%2==0 && A[i]%2==1) ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3612
import java.io.BufferedReader
import java.io.InputStreamReader

fun main(args: Array<String>) {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val x = br.readLine().toInt()
    val a = br.readLine().toInt()
    val b = br.readLine().toInt()
    println((x - a) % b)
}

fun err(print: Any) {
    System.err.println(print)
}

Measured memory_bytes: 31268
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
#define coutfix(i) cout << fixed << setprecision(i)		//coutの浮動小数出力の桁数設定
using namespace std;

int main()
{
	int64 nn, m4 = 0, m2 = 0, ot = 0;
	cin >> nn;
	vector<int64> aa(nn);
	for(int64 ii = 0;ii < nn;ii++)
	{
		cin >> aa[ii];
		if(aa[ii] % 4 == 0)
		{
			m4++;
		}
		else if(aa[ii] % 2 == 0)
		{
			m2++;
		}
		else
		{
			ot++;
		}
	}
	if(m4 + m2 / 2 >= nn / 2)
	{
		puts("Yes");
	}
	else
	{
		puts("No");
	}
	return 0;
}


Measured memory_bytes: 3980
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> g[100005];
ll A[2];
ll n;
ll D[100005];
string ans[2] = {"Snuke", "Fennec"};
int bfs()
{
	queue<ll> q;
	q.push(1); q.push(n);
	/*塗られてないマスを-1とする*/
	for(int i = 2; i < n; i++){
		D[i] = -1;
	}
	/*初期色設定*/
	D[1] = 0; D[n] = 1;
	while(!q.empty()){
		ll cur = q.front(); q.pop();
		A[D[cur]&1]++;
		for(int i=0;i<(ll)g[cur].size();i++){
			ll j=g[cur][i];
			/*塗られていたらはじく*/
			if(D[j]>= 0) continue;
			/*塗る*/
			D[j]=D[cur]+2;
			q.push(j);
		}
	}
	return A[0]>A[1];
}
int main(){
	cin>>n;
	int a,b;
	for(int i=0;i<n-1;i++){
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	cout<<ans[bfs()].c_str()<<endl;
	return 0;
}

Measured memory_bytes: 6720
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

n = ini()
d = [ini() for _ in range(n)]


def solve():

    return len(set(d))


print(solve())


Measured memory_bytes: 9108
import java.util.*;

public class Main {
	public Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new aoj1147().doIt();
	}
	class aoj1147{
		void doIt(){
			while(true){
				int n = sc.nextInt();
				if(n == 0)break;
				int num[] = new int [n];
				int max = 0;
				int min = Integer.MAX_VALUE;
				int ave = 0;
				for(int i = 0;i < n;i++){
					num[i] = sc.nextInt();
					if(num[i] > max)max = num[i];
					if(num[i] < min)min = num[i];
				}
				for(int i = 0;i < n;i++){
					if(num[i] == max){
						max = Integer.MAX_VALUE;
					}else if(num[i] == min){
						min = Integer.MAX_VALUE;
					}else{
						ave = ave + num[i];
					}
				}
				ave = ave / (n - 2);
				System.out.println(ave);
			}
		}
	}
}

Measured memory_bytes: 20948
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<set>
#include<regex>
#include<ctype.h>
using namespace std;

int main(void) {

	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	
	int x = x2 - x1, y = y2 - y1;
	cout << x2 - y << " " << y2 + x << " " << x1 - y << " " << y1 + x << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

import static java.lang.System.*;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int H = ni();
        int W = ni();
        int N = ni();
        int sr = ni();
        int sc = ni();
        String S = ns();
        String T = ns();


        // 右で落とせるか
        int r = sc;
        for(int n = 0; n < N; n++){
            if(S.charAt(n) == 'R'){
                r++;
            }

            if(r > W){
                out.println("NO");
                return;
            }

            if(T.charAt(n) == 'L' && r > 1){
                r--;
            }
        }

        // 左で落とせるか
        r = sc;
        for(int n = 0; n < N; n++){
            if(S.charAt(n) == 'L'){
                r--;
            }

            if(r < 1){
                out.println("NO");
                return;
            }

            if(T.charAt(n) == 'R' && r < W){
                r++;
            }
        }

        // 下で落とせるか
        int h = sr;
        for(int n = 0; n < N; n++){
            if(S.charAt(n) == 'D'){
                h++;
            }

            if(h > H){
                out.println("NO");
                return;
            }

            if(T.charAt(n) == 'U' && h > 1){
                h--;
            }
        }

        // 上で落とせるか
        h = sr;
        for(int n = 0; n < N; n++){
            if(S.charAt(n) == 'U'){
                h--;
            }

            if(h < 1){
                out.println("NO");
                return;
            }

            if(T.charAt(n) == 'D' && h < H){
                h++;
            }
        }

        out.println("YES");
    }

    static int ni() {
        return sc.nextInt();
    }

    static long nl() {
        return sc.nextLong();
    }

    static String ns() {
        return sc.next();
    }

    static int[] niarr(int N) {
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        return a;
    }

    static long[] nlarr(int N) {
        long[] a = new long[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextLong();
        }
        return a;
    }
}

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

#define REP(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define REPS(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define RREP(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define RREPS(i, n) for (int i = ((int)(n)); i > 0; i--)
#define IREP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define IREPS(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVISORT(v) sort(v.begin(), v.end(), greater<int>());
#define ALL(v) v.begin(), v.end()

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using ll = long long;

typedef long long ll;

template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

const ll mod=1e9+7;
int main()
{
    cin.tie( 0 );
    ios::sync_with_stdio( false );
	
	int n;cin>>n;
	vector<PII> v(n);
	REP(i,n){
		int p,q;cin>>p>>q;
		v[i]=make_pair(p,q);
	}

	int ans=n;
	REP(i,n-1){
		IREP(j,i+1,n){
			int p=v[i].first-v[j].first;
			int q=v[i].second-v[j].second;
			if(p==0&&q==0)continue;
			int tmp=n;
			REP(k,n-1){
				IREP(l,k+1,n){
					if((v[k].first-v[l].first)==p&&(v[k].second-v[l].second)==q) tmp--;
					if((v[l].first-v[k].first)==p&&(v[l].second-v[k].second)==q) tmp--;
				}
			}
			if(ans>tmp)ans=tmp;
			//cout << "v[i]="<< v[i].first << "," << v[i].second << " v[j]="<< v[j].first << "," << v[j].second <<" ,p,q=" << p << "," << q << " ,tmp=" << tmp<< endl;
		}
	}
	
	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <ctime>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to
#define mp(a, b) make_pair(a, b)

using namespace std;

typedef long long LL;
const int N = 4010;
const int mod = 1e9 + 7;

int s[N][N], t[N][N], p[N * N];

LL qpow(LL a, LL b)
{
	LL ret = 1, base = a;
	while (b) {
		if (b & 1) ret = ret * base % mod;
		base = base * base % mod, b >>= 1;
	}
	return ret;
}

LL C(int a, int b) { return 1ll * p[a] * qpow(p[b], mod - 2) % mod * qpow(p[a - b], mod - 2) % mod;}

int main()
{
	int n;
	scanf("%d", &n);
	LL ans = 0;
	p[0] = 1;
	Rep(i, 4000 * 4000) p[i] = 1ll * p[i - 1] * i % mod;
	Rep(i, n) {
		int x, y;
		scanf("%d%d", &x, &y);
		s[x + 2000][y + 2000] ++;
		t[2000 - x][2000 - y] ++;
		ans = (ans - C(x + x + y + y, x + x) + mod) % mod;
	}
	for (int i = 4000; i >= 0; i --) for (int j = 4000; j >= 0; j --) {
		s[i][j] = (s[i][j] + s[i + 1][j]) % mod;
		s[i][j] = (s[i][j] + s[i][j + 1]) % mod;
		ans = (ans + 1ll * t[i][j] * s[i][j] % mod) % mod;
	}
	
	printf("%lld\n", ans * qpow(2, mod - 2) % mod);
	
	return 0;
}
/*
3
1 1
1 1
2 1
*/

Measured memory_bytes: 157824
#include<cstdio>
#include<algorithm>
using namespace std;

#define ll long long

#define file_io 0

ll i,t,j;
ll n,k,a[100005][5],dp[100005][5];

int main() {
	if (file_io) {
		freopen(".in","r",stdin);
		freopen(".out","w",stdout);
	}

	scanf("%lld",&n);

	for (i=1; i<=n; ++i) {
		for (t=1; t<=3; ++t) {
			scanf("%lld",&a[i][t]);
		}
	}


	for (i=1; i<=n; ++i) {
		for (t=1; t<=3; ++t) {
			for (j=1; j<=3; ++j) {
				if (j!=t) {
					dp[i][t]=max(dp[i][t],dp[i-1][j]+a[i][t]);
				}
			}
		}
	}

	printf("%lld\n",max(max(dp[n][1],dp[n][2]),dp[n][3]));

	return 0;
}

Measured memory_bytes: 7936
// Code for A - Number of Multiples
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define FOR(i,x,y) for(ll i=x;i<(ll)(y);i++)

#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

int main() {
  int L, R, d;
  cin >> L >> R >> d;

  int total = 0;
  FOR (i, L, R + 1) {
    if (i % d == 0) {
      total ++;
    }
  }

  cout << total << endl;
  return 0;
}


Measured memory_bytes: 3568
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

public class Main{
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		if((N-2)*(N-1)/2<K) {
			pl("-1");
		}
		else {
			int g=N-1+(N-1)*(N-2)/2-K;
			pl(g);
			int yokei=(N-1)*(N-2)/2-K;
			for(int i=1; i<N; i++) {
				pl(i+" "+N);
			}
			for(int i=1; i<N; i++) {
				for(int j=1; j<i; j++) {
					if(yokei>0) {
						yokei--;
						pl(i+" "+j);
					}
				}
			}
		}
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}

Measured memory_bytes: 21332
/*
	0079:Area of Polygon
*/
#include	<iostream>
#include	<vector>
#include	<utility>
#include	<cstdio>

using namespace std;

typedef pair<double, double> P_DD;

int main(void) {
	double x, y, sx, sy, sum = 0.0;
	vector<P_DD> data;
	bool fir = true;
	
	while( scanf("%lf,%lf", &x, &y) != EOF) {
		if(fir) {
			sx = x;	sy = y;
			fir = false;
		}
		data.push_back( P_DD(x, y) );
	}
	data.push_back( P_DD(sx, sy) );
	
	vector<P_DD>::iterator it = data.begin();
	
	while( it+1 != data.end() ) {
		double b1x = (*it).first, b1y = (*it).second, b2x = (*(it+1)).first, b2y = (*(it+1)).second;
		
		sum += (b1x - b2x) * (b1y + b2y);
		it++;
	}
	sum /= 2;
	if(sum < 0) { sum *= -1.0; }
	printf("%f\n", sum);
	
	return 0;
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif
int n,m;
const int MaxN = 1005;
char a[MaxN][MaxN];
int dp[MaxN][MaxN];
int solve(int i,int j){

    if(a[i][j]=='#'){
        return 0;
    }
    if(i==n-1&&j==m-1){
        return 1;
    }
    
    if(i>=n||j>=m){
        return 0;
    }

    int &ans = dp[i][j];
    if(ans!=-1){
        return ans;
    }

    return ans = solve(i+1,j) %MOD + solve(i,j+1) % MOD;
    

}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    memset(dp,-1,sizeof(dp));
    cout<<solve(0,0)%MOD<<endl;
    return 0;
    
}


Measured memory_bytes: 9216
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <queue>
#include <math.h>
#include <assert.h>
#include <set>
#include <map>
#include <bitset>
#include <ctime>
#include <time.h>
#include <algorithm>
#include <cstdio>
#include <fstream>
#include <stack>
#include <ctype.h>
#include <numeric>
#include <sstream>
#include <unistd.h>
#include <unordered_map>
#include <limits>
const int oo = 1 << 30;
using namespace std;


void solve(){
    int n;
    scanf("%d", &n);
    vector<vector<int>> dp(2, vector<int>(3, -oo));
    int cur = 1;
    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    for(int i = 0; i < n; ++i){
        vector<int> c(3);
        for(int j = 0; j < 3; ++j){
            scanf("%d", &c[j]);
        }
        dp[cur].assign(3, -oo);
        for(int k = 0; k < 3; ++k){
            for(int l = 0; l < 3; ++l){
                if(k != l){
                    dp[cur][l] = max(dp[cur][l], dp[!cur][k] + c[l]);
                }
            }
        }
        cur = !cur;
    }
    int best = 0;
    for(int i = 0; i < 3; ++i){
        best = max(best, dp[!cur][i]);
    }
    printf("%d\n", best);
}
int main(){
    // freopen("/Users/deepsajeda/Documents/FIRST/in", "r", stdin);
    // freopen("/Users/deepsajeda/Documents/FIRST/out", "w", stdout);
    for(int i = 0; i < 1; ++i){
        solve();
    }
}
//printf("%.5f\n", clock() / (float)CLOCKS_PER_SEC); time in seconds


Measured memory_bytes: 384
# 要素数を取得
num = gets.to_i

# 要素値を取得
ue = gets.split(' ')
shita = gets.split(' ')

#p ue.class
#p ue

# 最初に右にi移動するとする
# i =< num - 1 
i_min = 0
i_max = num - 1

ue_sum = 0
shita_sum = 0
candi_num = 0

for i in i_min..i_max do
	for u_num in 0..i do
		ue_sum += ue[u_num].to_i
	end  

	for s_num in i..i_max do
		shita_sum += shita[s_num].to_i
	end

	candi_num_tmp = ue_sum + shita_sum

	if candi_num < candi_num_tmp then
		candi_num = candi_num_tmp
	end
    # p "-------------------------" 
	# p i
	# p ue_sum
	# p shita_sum
	# p candi_num_tmp
	# p candi_num
	# p "-------------------------"
	ue_sum = 0
	shita_sum = 0
end

p candi_num

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main
{

    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);

        long n = scan.nextInt();
        long a = 0;
        if (n != 1) {

            for (long i = n - 1; i > 0; i--) {
                a = n * i;
                n = a;

            }

            System.out.println(a);

        } else {
            System.out.println(n);
        }
    }
}



Measured memory_bytes: 26232
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9+7;

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

  int n; cin >> n;
  vector<string> s(n);
  rep(i, n) {
    cin >> s.at(i);
  }
  int mat[n][26];
  rep(i, n) {
    rep(j, 26) {
      mat[i][j] = 0;
    }
  }
  rep(i, n) {
    int size = s.at(i).size();
    rep(j, size) {
      mat[i][s.at(i).at(j)-'a']++;
    }
  }

  rep(j, 26) {
    int mi = INT_MAX;
    rep(i, n) {
      mi = min(mi, mat[i][j]);
    }
    rep(i, mi) {
      cout << (char)('a' + j);
    }
  }
  cout << endl;

}

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

#define F first 
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 100010, M = 2 * N;

LL a, b;

LL gcd(LL a, LL b)
{
	return b ? gcd(b, a % b) : a;
}

int main()
{
	cin >> a >> b;
	LL t = gcd(a, b);
	
	int res = 0;
	for (LL i = 2; i <= t / i; i ++ )
		if (t % i == 0)
		{
			res ++ ;
			while (t % i == 0) t /= i;
		}
	
	if (t > 1) res ++ ;
	res ++ ;
	
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;


signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int A, B, C, D, N;
	cin >> A >> B >> C >> D >> N;
	A *= 8;
	B *= 4;
	C *= 2;
	int ans = N / 2 * min({A, B, C, D});
	if(N % 2 == 1) ans += min({A/2, B/2, C/2});
	cout << ans << endl;
}

Measured memory_bytes: 256