akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main(){
    int h, w;   cin >> h >> w;
    vector<vector<ll>> spell(10, vector<ll>(10)), wall(h, vector<ll>(w));
    
    REP(i, 10) REP(j, 10) cin >> spell[i][j];
    REP(i, h) REP(j, w) cin >> wall[i][j];
    
    
    REP(k ,10){
        REP(i, 10){
            REP(j, 10){
                spell[i][j] = min(spell[i][j], spell[i][k]+spell[k][j]);
            }
        }
    }
    ll res=0;
    REP(i, h){
        REP(j, w){
            int x = wall[i][j];
            if(x<0) continue;
            res += spell[x][1];
        }
    }
    cout << res << endl;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long n,ans=1,mod=1000000007;
    cin >> n;
    for(int i=1;i<=n;i++){
        ans = ans*i%mod;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

#----------
A_list = list(map(int, input().rstrip().split()))
#----------

A_list.sort()

min_cost=A_list[-1]*A_list[-1]
for i,i_v in enumerate(A_list):
    A_list_i = A_list[:]
    del A_list_i[i]
    for j,j_v in  enumerate(A_list_i):
        A_list_j = A_list_i[:]
        del A_list_j[j]
        for k,k_v in  enumerate(A_list_j):
            cost = abs(j_v - i_v) + abs(k_v - j_v)
            if cost < min_cost:
                min_cost = cost

print(min_cost)


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int n; cin >> n;
    vll a(n), sum(n+1, 0); 
    rep(i, n) {
        cin >> a[i];
        sum[i+1] = sum[i] + a[i];
    }
    
    ll ans = 1e18;
    
    auto f = [&](int a, int b){
        return sum[a+1] - 2 * sum[b+1];    
    };
    
    auto g = [&](int a, int b){
        return sum[(n-1)+1] - 2 * sum[b+1] + sum[a+1];    
    };
    
    rep3(m,1,n-3){
        // a[0] -> a[m], a[m+1] -> a[n-1]
        set<ll> cand;
        auto cpush = [&](int a, int b){
            cand.insert(sum[a+1] - sum[b+1]);
            return;
        };

        int l = 0, r = m;
        while(l + 1 != r){
            int mid = (l + r) / 2;
            if(f(m, mid) >= 0){
                l = mid;
            }else{
                r = mid;
            }
        }
        // cout << "debug1: " << l << " " << r << " " << m << endl;
        if(abs(f(m,l)) > abs(f(m,l+1))){
            cpush(l+1, -1);
            cpush(m, l+1);
        }else{
            cpush(l, -1);
            cpush(m, l);
        }
        
        l = m+1; r = n-1;
        while(l + 1 != r){
            int mid = (l + r) / 2;
            if(g(m,mid) >= 0){
                l = mid;
            }else{
                r = mid;
            }
        }
        // cout << "debug2: " << l << " " << r << " " << m << endl;
        if(abs(g(m,l)) > abs(g(m,l+1))){
            cpush(l+1, m);
            cpush(n-1, l+1);
        }else{
            cpush(l, m);
            cpush(n-1, l);
        }
        
        /*
        cout << m << ": ";
        for(auto c : cand){
            cout << c << " ";
        }
        cout << endl;
        //*/
        
        ll tmp = abs(*cand.begin() - *cand.rbegin());
        ans = min(ans, tmp);        
    }
    cout << ans << endl;
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 6320
int main(int argc,const char*argv[])
{
    int a,b;
    scanf("%d %d",&a,&b);
    if(a<b){
        printf("a < b\n");
    }else if(a>b){
        printf("a > b\n");
    }else{
        printf("a == b\n");
    }
    return 0;
}

Measured memory_bytes: 580
#include<stdio.h>
#define N 8
int putqueen(int);
void print();
int row1[15],x[8],k,row[15],col[15],dpos[15],dneg[15];


int main(){
int i,y,e,m=0;
  scanf("%d",&k);
  for(i=0;i<k;i++){
scanf("%d%d",&x[i],&y);
row1[x[i]]=y;

  if(x==0)m=1;

  }
  if(m==1)e=putqueen(1);
  else e=putqueen(0);
  return 0;
}

int putqueen(int i){
  int c=0,j,a;
  if(i==N ){
    for(j=0;j<k;j++){
      a=x[j];
      if(row1[a]==row[a]){
         c++;
       }

    }
    if(c==k){
    print();
    return 0;
  }
  c=0;
  }
  for(j=0;j<N;j++){
    if (col[j] == -1 || dpos[i+j] == -1 || dneg[i-j+N-1] == -1 ) {
      continue;
    }
    row[i] = j;
     col[j] = dpos[i+j] = dneg[i-j+N-1] = -1;

    putqueen(i+1);
  col[j] = dpos[i+j] = dneg[i-j+N-1] = 0;
}
}


void print(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]!=j)printf(".");
      else printf("Q");
    }
    printf("\n");
  }
}



Measured memory_bytes: 2112
a, b = map(int, input().split())

def f(x):
  if x == 1:
    return 300000
  if x == 2:
    return 200000
  if x == 3:
    return 100000
  return 0

ans = f(a) + f(b)
if a == 1 and b == 1:
  ans += 400000
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(ll i=0;i<n;++i)
#define FOR(i,j,n) for(ll i=j;i<n;++i)
#define MOD (1e9 + 7)

int main(void){
    ll N,M;
    cin >> N >> M;
    ll H[N], good[N];
    REP(i,N){cin >> H[i]; good[i] = 1;}
    ll a, b;
    REP(i,M){
        cin >> a >> b;
        if(H[a-1]>H[b-1]){
            good[b-1] = 0;
        }
        else if(H[a-1]<H[b-1]){
            good[a-1] = 0;
        }
        else{
            good[a-1] = 0;
            good[b-1] = 0;
        }
    }
    ll res = 0;
    REP(i,N) res += good[i];
    cout << res << endl;
}

Measured memory_bytes: 5184
#include <stdio.h>

int main(void){
  int a,b,c;
  int sum;
  scanf("%d %d %d",&a,&b,&c);
  sum = a+b+c;
  if(sum >= 22){
    printf("bust\n");
  }
  if(sum < 22){
    printf("win\n");
  }
}


Measured memory_bytes: 1636
from operator import itemgetter
n,m = map(int, input().split())
py = []
for i in range(m):
  p,y = map(int, input().split())
  py.append([p,y,i])
py.sort(key=itemgetter(1))
num = [1]*n
for i in range(m):
  zen = py[i][0]
  koh = num[py[i][0]-1]
  zenhan = str(zen)
  kouhan = str(koh)
  z = 6 - len(zenhan)
  k = 6 - len(kouhan)
  zenkan = '0' * z
  koukan = '0' * k
  zenkan += zenhan
  koukan += kouhan
  py[i] = py[i] + [zenkan + koukan]
  num[py[i][0]-1] = num[py[i][0]-1] +1
py.sort(key=itemgetter(2))
for i in range(m):
  pri = py[i][3]
  print(pri)

Measured memory_bytes: 33984
#include<iostream>
#include<string>
#include<math.h>

using namespace std;

int main(){
    
    int x[5];
    for(int i=0;i<5;i++){
        cin>>x[i];
    }
    int ans;
    for(int i=0;i<5;i++){
        if(x[i]!=i+1){
            ans=i+1;
        }
    }
    cout<<ans<<"\n";
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<long long>data(n);
  for(int i = 0;i < n;i++){
    cin >> data.at(i);
    if(i > 0){
      if(i == 1 && data.at(i) < data.at(i-1)){
        data.at(i-1)--;
      }
      if(data.at(i) >= data.at(i-1)){
        if(data.at(i)-data.at(i-1) >= 1){
          data.at(i)--;
        }
      }
      else{
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 1024
# coding: utf-8

# https://atcoder.jp/contests/abc109


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


def main():
    N, X = map(int, input().split())
    x = list(map(int, input().split()))
    x = [val-X if val >= X else X-val for val in x]
    x = sorted(x)

    # w = [None] * N
    # w[0] = x[0] - X
    # for i in range(1, N):
    #     w[i] = x[i] - x[i-1]

    ans = x[0]
    for i in range(N-1):
        ans = gcd(ans, x[i+1])

    return ans


print(main())


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    ll n,m;cin>>n>>m;
    vl a(n),b(n);
    vl c(m),d(m);
    rep(i,n)cin>>a[i]>>b[i];
    rep(i,m)cin>>c[i]>>d[i];
    rep(i,n){
        ll k=1,l=abs(a[i]-c[0])+abs(b[i]-d[0]);
        rep(j,m){
            if(l>(abs(a[i]-c[j])+abs(b[i]-d[j]))){
                l=abs(a[i]-c[j])+abs(b[i]-d[j]);
                k=j+1;
            }
        }
        cout<<k<<endl;
    }
}

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

using namespace std;

int main() {
    char c;
    scanf("%c", &c);
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') cout << "vowel";
    else cout << "consonant";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>

using namespace std;

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

	int N, M, X, Y;
	cin >> N >> M >> X >> Y;

	int x[N], y[M];
	for(int i = 0; i < N; i++) {
		cin >> x[i];
	}
	for(int i = 0; i < M; i++) {
		cin >> y[i];
	}

	sort(x, x + N);
	sort(y, y + M);

	int xRight = x[N - 1];
	int yLeft = y[0];

	bool ans = false;
	for(int z = X + 1; z <= Y; z++) {
		if(xRight < z && z <= yLeft) {
			ans = true;
			break;
		}
	}

	if(ans) {
		cout << "No War" << endl;
	}
	else {
		cout << "War" << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <time.h>
#include <iomanip>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define double long double
#define int long long
#define low lower_bound
#define upp upper_bound
#define mod (int)1e9+7
#define inf (int)1e16
#define rep(i,n) for (int i = 0; i < n; i++)
#define Rep(i,n) for (int i = n; i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define vsort(vec) sort(all(vec))
#define vrever(vec) reverse(all(vec));
#define vunsort(vec) vsort(vec); vrever(vec);
#define cend cout<<endl;
#define P pair<int, int>
#define prique priority_queue<P, vector<P>, greater<P>>
struct edge { int to, cost; };
using namespace std;
int n;
vector<edge>g[114514];
int d[114514];
bool ans[114514];
// true = 黒
signed main() {
	cin >> n;
	rep(i, n - 1) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		g[a].push_back({ b,c });
		g[b].push_back({ a,c });
	}
	ans[0] = true;
	prique que;
	fill(d, d + n, inf);
	d[0] = 0;
	que.push(P(0, 0));
	while (que.size()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		rep(i, g[v].size()) {
			edge e = g[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				if (d[e.to] % 2 == 0) {
					ans[e.to] = true;
				}
				que.push(P(d[e.to], e.to));
			}
		}
	}
	end:
	rep(i,n) {
		if (ans[i]) cout << 1 << endl;
		else cout << 0 << endl;
}
}


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

#define ll long long
#define pp pair<int, int>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPU(i, a, b, s) for(int i = a; i < b; i += s)
#define REPD(i, a, b, s) for(int i = a; i > b; i -= s)
#define endl "\n"

ll INF = 2e18;
ll MOD = 1e9 + 7;
int i, j, k, t;

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

    vector<int> L(N);
    REP(i, N) { cin >> L[i]; }

    vector<int>::iterator it = max_element(L.begin(), L.end());
    int max_num = *it;
    int max_index = distance(L.begin(), it);
    int non_max_sum = 0;

    REP(i, N) {
        if(i != max_index) {
            non_max_sum += L[i];
        }
    }

    if(max_num < non_max_sum) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3640
n,k = gets.chomp.split(" ").map(&:to_i)
a_arr = [0] + gets.chomp.split(" ").map(&:to_i)
tmp_arr = []
flag_arr = []

index = 1
count = 0
k.times do |i|
  index = a_arr[index]
  if flag_arr[index] == 1
    a_i = tmp_arr.index{|a| a == index}
    q = (k - a_i) % (count - a_i)
    if q == 0
      puts tmp_arr[-1]
    else
      puts tmp_arr[a_i + q - 1]
    end
    exit 0
  else
    flag_arr[index] = 1
    count += 1
    tmp_arr << index
  end
end

puts index


Measured memory_bytes: 33016
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)

int main() {
    // your code goes here
    ll n,a,b,d,r;
    cin >> n >> a >> b;
    r=n%(a+b);
    d=(n-r)/(a+b);
    cout << d*a+min(a,r) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
int main()
{
  int n;cin >> n;
  string s;cin >> s;
  int q;cin >> q;
  vector<int> k(q);
  rep( i, q ) cin >> k[i];
  rep( i, q ) {
    ll d = 0, m = 0, dm = 0, dmc = 0;
    rep( j, k[i] ) {
      if( s[j] == 'D' ) d++;
      else if( s[j] == 'M' ) {
	dm += d;
	m++;
      }
      else if( s[j] == 'C' ) dmc += dm;
    }
    rep( j, n - k[i] ) {
      if( s[j] == 'D' ) {
	d--;
	dm -= m;
      }
      else if( s[j] == 'M' ) m--;

      if( s[ j + k[i] ] == 'D' ) d++;
      else if( s[ j + k[i] ] == 'M' ) {
	m++;
	dm += d;
      }
      else if( s[ j + k[i] ] == 'C' ) dmc += dm;
    }
    cout << dmc << "\n";
  }
  return 0;
}


Measured memory_bytes: 1412
#include<stdio.h>
	int main()
{
	int n, i, j, card[4][13] = {0}, rank;
	char type;
	scanf("%d", &n);
	for(i = 0; i < n; i++){
		scanf(" %c %d", &type, &rank);
		switch(type){
			case 'S' : card[0][rank - 1] += 1;
			break;
			case 'H' : card[1][rank - 1] += 1;
			break;
			case 'C' : card[2][rank - 1] += 1;
			break;
			case 'D' : card[3][rank - 1] += 1;
			break;
		}
		rank -= rank;
	}
	for(i = 0; i < 4; i++){
		for(j = 0; j < 13; j++){
			if(card[i][j] == 0){
					switch(i){
						case 0 : printf("S %d\n", j+1);
						break;
						case 1 : printf("H %d\n", j+1);
						break;
						case 2 : printf("C %d\n", j+1);
						break;
						case 3 : printf("D %d\n", j+1);
						break;
					}
			}
		}
	}
	return 0;
}

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

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

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

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

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

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

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

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

int main()
{
    ll n;
    cin >> n;
    ll a;
    cin >> a;
    ll ans = a;
    for (int i = 1; i < n; i++)
    {
        cin >> a;
        ans = gcd(ans, a);
    }
    cout << ans << endl;
}

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

int main()
{

  string s;
  cin >> s;

  if(s=="Sunny")
    cout << "Cloudy" << endl;
  else if(s=="Cloudy")
    cout << "Rainy" << endl;
  else
    cout << "Sunny" << endl;
  


  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e6;
const int inf=1e9+10; 
int n,a[N],b[N],ans;
int l,r,mid;
bool small(int x,int y,int q){
	return a[x]<=q && a[y]<=q;
}

bool big(int x,int y,int q){
	return a[x]>q && a[y]>q;
}

bool check(int x){
	for(int i=0;i<n-1;i++){
		if(small(n+i,n+i+1,x) || small(n-i,n-i-1,x)) return true;
		if(big(n+i,n+i+1,x) || big(n-i,n-i-1,x)) return false;
	}
	return a[1]<=x;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=2*n-1;i++) scanf("%d",&a[i]);
	l=1; r=2*n-1;
	while(l<=r){
		mid=(l+r)/2;
		if(check(mid)){
			ans=mid;
			r=mid-1;
		}else l=mid+1;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 4352
#include<iostream>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<vector>
#include<utility>
#define vi vector<int>
#include<algorithm>
#include<list>
#define li list<int>
#include<stack>
#include<queue>
#define ll long long
using namespace std;
class node{
    public:
        int data;
        node*left;
        node*right;

        node(int d){
            data = d;
        }
};
int main(){
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    if(n<=1){
        cout<<"0";
        exit(0);
    }
    if(n==2){
        cout<<abs(arr[1]-arr[0]);
        exit(0);
    }
    int dp[n];
    memset(dp,0,sizeof(dp));
    dp[1]=abs(arr[1]-arr[0]);
    for(int i=2;i<n;i++){
        dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
    }
    cout<<dp[n-1];
    return 0;
}                   

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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  int i;
  int count0 = 0;
  int countf = 0;
  long long ans = 0;
  for(i = 0; i < n; i++)
  {
    cin >> a.at(i);
    if(a.at(i) == 0) count0++;
    if(a.at(i) < 0) countf++;
  }
  if(count0 > 0 || countf%2==0)
  {
    for(i = 0; i < n; i++)
    {
      ans += abs(a.at(i));
    }
  }
  else
  {
    for(i = 0; i < n; i++)
    {
      a.at(i) = abs(a.at(i));
    }
    sort(a.begin(), a.end());
    ans -= a.at(0);
    for(i = 1; i < n; i++)
    {
      ans += abs(a.at(i));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
n = int(input())
u = list(map(int, input().split()))
u0 = u[0::2]
u1 = u[1::2]
s0 = [0] * 100001
s1 = [0] * 100001
for i in u0:
  s0[i] += 1
for i in u1:
  s1[i] += 1
maxi_0 = 0
maxi2_0 = 0
for i in range(100001):
  if s0[i] >= s0[maxi_0]:
    maxi2_0 = maxi_0
    maxi_0 = i
  elif s0[i] >= s0[maxi2_0]:
    maxi2_0 = i
maxi_1 = 0
maxi2_1 = 0
for i in range(100001):
  if s1[i] >= s1[maxi_1]:
    maxi2_1 = maxi_1
    maxi_1 = i
  elif s1[i] >= s1[maxi2_1]:
    maxi2_1 = i
if maxi_0 != maxi_1:
  print(n - s0[maxi_0] - s1[maxi_1])
else:
  print(n - max(s0[maxi_0] + s1[maxi2_1], s0[maxi2_0] + s1[maxi_1]))


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

const int MAX_N = 100005;
int cnt[MAX_N]; //cnt[i] := 0文字目からi文字目までに何個ACがあるか

int main()
{
	int N,Q;
	cin >> N >> Q;
	string S;
	cin >> S;

	for (int i = 0; i < MAX_N; ++i)
	{
		cnt[i] = 0;
	}

	for (int i = 1; i < S.size(); ++i)
	{
		if (S[i-1] == 'A' && S[i] == 'C')
		{
			cnt[i] = cnt[i-1] + 1;
		}
		else
		{
			cnt[i] = cnt[i-1];
		}
	}

	for (int i = 0; i < Q; ++i)
	{
		int l,r;
		cin >> l >> r;
		if (l != 0) l--;
		r--;
		cout << cnt[r] - cnt[l] << endl;
	}
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <map>
#define ll long long
const int MOD = 1e9+7;
using namespace std;

ll llmax(ll x, ll y){
	if (x > y) return x;
	return y;
}

ll llmin(ll x, ll y){
	if (x > y) return y;
	return x;
}


int main(){
	ll a, b, k;
	cin >> a >> b >> k;
	cout << llmax(a-k, 0) << " " << llmax(0, llmin(a+b-k, b)) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//size_t f = string::npos
//make pair

int main(){
      int n,k;cin >> n >> k;
      vector<int> arr;
      int ans = 0;
      for(int i = 0;i < n;i++){
            int t;cin >> t;
            arr.push_back(t);
      }
      sort(arr.rbegin(), arr.rend());
      for(int i = 0;i < k;i++)ans += arr[i];
      cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fast_I_O ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int mod = 1e9+7 , INF = 1e9 ,  mx = 100005 ;
main()
{
    fast_I_O;
    int i,j,n,m,x,y,sum=0,p=0,l,k,mn=LLONG_MAX,mx=LLONG_MIN;
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    x=a*d,y=a*c,k=b*c,l=b*d;
    cout<<max(max(x,y),max(k,l));
    return 0;
}

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

using namespace std;

int main(){
  long long N,K; cin >> N >> K;
  
  if( K % 2 != 0){  
    long long x = N / K;
    cout << (long long)pow(x,3.0) << endl;}
  else{
    long long x = N / K; long long y = ( N + ( K / 2) ) / K; 
    cout << (long long)pow(x,3.0) +  (long long)pow(y,3.0) << endl; }
  
  return 0;}
    

Measured memory_bytes: 512
def count_diff(s,t) :
    lst_s = list(s)
    lst_t = list(t)
    len_s = len(lst_s)
    ng = 0
    for i in range(len_s) :
        if lst_s[i] != lst_t[i] :
            ng += 1
    print(ng)
        
s = input()
t = input()

count_diff(s,t)

Measured memory_bytes: 12572
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll n,m;
	scanf("%lld%lld",&n,&m);
	printf("%lld",(n+m+1)/2);
}

Measured memory_bytes: 128
#include <stdio.h>
#define NOT_FREE -1
#define FREE -2
#define EXIST -3
#define NOT_EXIST -4
#define N 8
void putQueen(int);
void printBoard();
int col[N], row[N], dpos[2*N-1], dneg[2*N-1], Board[N][N];

int main(){
  int k, r, c, i, j;
  for(i = 0; i < N; i++){
      col[i] = FREE;
      row[i] = FREE;
  }
  for(i = 0; i < 2*N-1; i++){
      dpos[i] = FREE;
      dneg[i] = FREE;
  }
  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++) Board[i][j] = NOT_EXIST;
  }

  scanf("%d",&k);
  for(i = 0; i < k; i++){
    scanf("%d %d",&r, &c);
    Board[r][c] = EXIST;
  }
  putQueen(0);
  return 0;
}

void putQueen(int i){
  int j;
  if( i == N ){
    printBoard();
    return;
  }
  for(j = 0; j < N; j++){
    if( col[j] == NOT_FREE || dpos[i+j] == NOT_FREE ||
	dneg[i-j+N-1] == NOT_FREE ) continue;
    //put a queen at (i,j)
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
    //try the next row
    putQueen(i+1);
    //remove the queen at (i,j) for backtracking
    col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
  }
}

void printBoard(){
  int i, j;
  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      if( Board[i][j] == EXIST && row[i] != j ) return;
    }
  }
  for(i = 0; i < N; i++){
    for(j = 0; j < N; j++){
      if( row[i] == j ) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}



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

int main()
{
double x ;
cin >> x ;
ll a=100;
rep(i,1000000){
  a*=1.01;
  if(a>=x){ans=i+1;break;}
}
cout << ans << endl;
return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,K;
int dp[1111][1111];

signed main(){
    cin>>N>>K;
    rep(i,K)dp[1][i]=1;
    for(int i=1;i<N;i++){
        int sum=0;
        rep(j,K)sum+=dp[i][j];
        for(int j=0;j<K;j++)dp[i+1][j]=sum-dp[i][j];
    }
    int ans=0;
    rep(i,K)ans+=dp[N][i];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++) {
    cin >> a[i];
    if (a[i]%2 == 0 && a[i]%3 != 0  && a[i]%5 != 0) {
      cout << "DENIED" << endl;
      return 0;
    }
  }
  cout << "APPROVED" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/*
 public class arc086b {

 }

 */
public class Main {
  public void solve() throws FileNotFoundException {
    InputStream inputStream = System.in;

    InputHelper in = new InputHelper(inputStream);

    // actual solution
    int n = in.readInteger();

    int[] a = new int[n];

    for (int i = 0; i < n; i++) {
      a[i] = in.readInteger();
    }

    int lm = -1;
    Boolean isp = null;
    int lmi = -1;

    for (int i = 0; i < n; i++) {
      int abs = Math.abs(a[i]);

      if (abs > lm) {
        lm = abs;
        lmi = i;
        if (a[i] < 0) {
          isp = false;
        }
        if (a[i] >= 0) {
          isp = true;
        }
      } else if (abs == lm) {
        if (a[i] >= 0 && (isp == null || isp == false)) {
          lmi = i;
          isp = true;
        }
      }
    }

    if (lm <= 0) {
      System.out.println("0");
      return;
    }

    System.out.println(2 * n);
    if (isp) {
      System.out.println(lmi + 1 + " " + 1);
      System.out.println(lmi + 1 + " " + 1);

      for (int i = 2; i <= n; i++) {
        System.out.println(i - 1 + " " + i);
        System.out.println(i - 1 + " " + i);
      }
    } else {
      System.out.println(lmi + 1 + " " + n);
      System.out.println(lmi + 1 + " " + n);

      for (int i = n - 1; i >= 1; i--) {
        System.out.println(i + 1 + " " + i);
        System.out.println(i + 1 + " " + i);
      }
    }
    // end here
  }

  public static void main(String[] args) throws FileNotFoundException {
    (new Main()).solve();
  }

  class InputHelper {
    StringTokenizer tokenizer = null;
    private BufferedReader bufferedReader;

    public InputHelper(InputStream inputStream) {
      InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
      bufferedReader = new BufferedReader(inputStreamReader, 16384);
    }

    public String read() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          String line = bufferedReader.readLine();
          if (line == null) {
            return null;
          }
          tokenizer = new StringTokenizer(line);
        } catch (IOException e) {
          e.printStackTrace();
        }
      }

      return tokenizer.nextToken();
    }

    public Integer readInteger() {
      return Integer.parseInt(read());
    }

    public Long readLong() {
      return Long.parseLong(read());
    }
  }
}


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

int main(){
  int x,i=0;
  char s[100];
  int n[101];

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){//printf("DEBUG %d+ %d\n",n[i],n[i-1]);
      n[i-1] = n[i-1] + n[i];
      //printf("DEBUG %d\n",n[i]);
      i--;
    } else if ( s[0] == '-' ){//printf("DEBUG %d- %d\n",n[i],n[i-1]);
      n[i-1] = n[i-1] - n[i];
      i--;
    } else if ( s[0] == '*' ){//printf("DEBUG %d* %d\n",n[i],n[i-1]);
      n[i-1] = n[i-1] * n[i];
      i--;
    } else {
      x = atoi(s);
      n[i+1] = x;
      i++;
    }
  }
  printf("%d\n",n[i]);
  return 0;
}

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

typedef struct Eachtop {
  double x;
  double y;
  struct Eachtop *next;
} Top;

Top *topnode, *lastnode, *thisnode;

void makenewpoint(Top* a, Top* b){
  Top *firstnode, *secondnode, *thirdnode;
  firstnode = (Top*)malloc(sizeof(Top));
  firstnode->x = (b->x - a->x)/ 3.0+a->x;
  firstnode->y = (b->y - a->y)/ 3.0+a->y;
  secondnode = (Top*)malloc(sizeof(Top));
  secondnode->x = (b->x - a->x)/ 3.0*2+a->x;
  secondnode->y = (b->y - a->y)/ 3.0*2+a->y;
  thirdnode = (Top*)malloc(sizeof(Top));
  thirdnode->x =1/sqrt(3.0)* ((b->x - a->x) * cos(M_PI/6.0) - (b->y - a->y)*sin(M_PI/6.0)) + a->x;
  thirdnode->y =1/sqrt(3.0)* ((b->x - a->x) * sin(M_PI/6.0) + (b->y - a->y)*cos(M_PI/6.0)) + a->y;
  a->next = firstnode;
  firstnode->next = thirdnode;
  thirdnode->next = secondnode;
  secondnode->next = b;
  thisnode = b;
}
int main(void){
  int n, i;
  scanf("%d", &n);
  topnode = NULL;
  lastnode = NULL;
  topnode = (Top*)malloc(sizeof(Top));
  topnode->x = 0;
  topnode->y = 0;
  lastnode = (Top*)malloc(sizeof(Top));
  lastnode->x = 100;
  lastnode->y = 0;
  thisnode = topnode;
  topnode->next = lastnode;
  lastnode->next = NULL;
  for(i=0; i<n ;i++){
    thisnode = topnode;
    while(thisnode != lastnode)
      makenewpoint(thisnode, thisnode->next);
  }
  thisnode = topnode;
  while(thisnode != NULL){	
    printf("%f %f\n", thisnode->x, thisnode->y);
    thisnode = thisnode->next;
  }
  return 0;
}
  

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

int abs(int a, int b);
int main()
{
    bool flag = true;
    int n, in;
    std::cin >> n;
    std::vector<int> x, y, t;
    for(int i = 0; i < n; i++){
        std::cin >> in;
        t.push_back(in);
        std::cin >> in;
        x.push_back(in);
        std::cin >> in;
        y.push_back(in);
    }
    int dt, dx, dy;
    for(int i = 0; i < n; i++){
        if(i == 0){
            dx = abs(0, x[0]);
            dy = abs(0, y[0]);
            dt = abs(0, t[0]);
        }
        else{
            dx = abs(x[i-1], x[i]);
            dy = abs(y[i-1], y[i]);
            dt = abs(t[i-1], t[i]);
        }
        if(((dt - dx - dy) % 2 ==1)||(dx + dy > dt)){
            flag = false;
            break;
        }
    }
    if (flag == true){
        std::cout << "Yes" << std::endl;
    }
    else{
        std::cout << "No" << std::endl;
    }
    return 0;
}

int abs(int a, int b)
{
    if(a > b){
        return a-b;
    }
    else{
        return b-a;
    }
}

Measured memory_bytes: 1644
using System;
using System.Collections.Generic;
using System.Linq;

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

            var a = str[0].ToString();
            var b = str[1].ToString();
            var c = str[2].ToString();

            if (a == "1")
            {
                a = "9";
            }
            else
            {
                a = "1";
            }

            if (b == "1")
            {
                b = "9";
            }
            else
            {
                b = "1";
            }
            if(c == "1")
                {
                c = "9";
            }
            else
            {
                c = "1";
            }

            Console.WriteLine("{0}{1}{2}", a, b, c);
        }
    }
}


Measured memory_bytes: 13140
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=24;
int a[N],b[N],c[N],n,sum;
int main() {
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",&a[i]);
	for (int i=1;i<=n;++i) scanf("%d",&b[i]),sum+=b[i];
	for (int i=1;i<n;++i) scanf("%d",&c[i]);
	for (int i=1;i<n;++i) {
		if (a[i+1]==a[i]+1)
			sum+=c[a[i]];
	}
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 256
import itertools
n = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))

lst = [i for i in range(1,n+1)]
#list(itertools.permutations([1, 2, 3]))
s = list(itertools.permutations(lst))
a,b = 0,0
for i in range(len(s)):
    if s[i] == P:
        a = i
    if s[i] == Q:
        b = i

print(abs(a-b))


Measured memory_bytes: 45808
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define reps(i,n) for(ll i = 0; i <= n; i++)
#define REP(i, n) for(ll i = 1; i < (ll)(n); i++)
#define P pair<ll, ll>
typedef long long ll;
const ll mod = 1e9+7;

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

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 1) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
// n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i=1; i<a.size() && res!=1; i++){
    res = gcd(res, a[i]);
  }
  return res;
}
// n個の最小公倍数
ll nlcm(vector<ll> a){
  ll res;
  res = a[0];
  REP(i, a.size()){
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}

ll f(ll f3, ll f5, ll f7, ll val, ll n){
  ll sum = 0;
  if(val > n) return 0;
  if(f3!=0 && f5!=0 && f7!=0) sum++;
  sum += f(f3+1, f5, f7, val*10+3, n);
  sum += f(f3, f5+1, f7, val*10+5, n);
  sum += f(f3, f5, f7+1, val*10+7, n);
  return sum;
}

int main(){
  ll n;
  cin >> n;
  ll ans = f(0, 0, 0, 0, n);
  cout << ans << endl;
}






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

const int N = 65539, p = 1e9+7;
int fac[N], inv[N];
int f[N], g[N], bit[N];
int n, m, a[17], bin[17];

inline int C(const int nn, const int mm) {return (ll)fac[nn] * inv[mm]%p * inv[nn-mm]%p;}
inline int qpow(int A, int B) {
	int res = 1; while(B) {
		if(B&1) res = (ll)res * A%p;
		A = (ll)A * A%p, B >>= 1;
	} return res;
}

int main() {
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;++i) scanf("%d",a+i);
	
	bin[0] = 1;
	for(int i=1;i<=n;++i) bin[i] = bin[i-1] << 1;
	const int L = bin[n];
	
	fac[0] = 1;
	for(int i=1;i<=L;++i) fac[i] = (ll)fac[i-1] * i%p;
	inv[L] = qpow(fac[L], p-2);
	for(int i=L;i;--i) inv[i-1] = (ll)inv[i] * i%p;
	
	g[0] = 1;
	for(int i=m;i;--i) {
		swap(f, g);
		for(int S = 0; S < L; ++ S) g[S] = f[S];
		for(int S = 0; S < L and a[i] + S <= L; ++ S) {
			if(!f[S]) continue;
			for(int j=0;j<n and L-a[i]-S >= bin[j]-1;++j)
				if(!(S & bin[j]))
					g[S|bin[j]] = (g[S|bin[j]] + (ll)f[S] * C(L-a[i]-S, bin[j]-1)%p * fac[bin[j]])%p;
		}
	}
	
	ll ans = 0ll;
	for(int S = 0; S < L; ++ S) {
		bit[S] = bit[S>>1] ^ (S&1);
		int v = (ll)fac[L-S-1] * g[S]%p;
		if(bit[S]) v = -v;
		ans += v;
	}
	
	ans = (ans + (ll)p * p)%p;
	ans = (ll)ans * L%p;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1536
#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<ll> A(N), sum(N + 1);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		sum[i + 1] = sum[i] + A[i];
	}
	ll res = 0;
	map<ll, int> cnt;
	cnt[0] = 1;
	for (int i = 0; i < N; i++) {
		res += cnt[sum[i + 1]];
		cnt[sum[i + 1]]++;
	}
	cout << res << endl;
	return 0;
}


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

void Main()
{
  ll N,K; cin >> N >> K;
  ll cnt[100000] = {(ll)0};
  rep(i,N) {
    ll ai, bi;
    cin >> ai >> bi;
    cnt[--ai] += bi;
  }
  ll order = 0;
  rep(i,100000) {
    if (order + cnt[i] >= K) {cout << ++i << endl; return;}
    order += cnt[i];
  }
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define MOD 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define forr(i,p,n) for(ll i=p;i<n;i++)
#define MAXN 500003
typedef long long ll;
inline ll mod(ll x,ll n)
{
    if(x<n)
    {
        return x;
    }
    return x-n;
}
using namespace std;
ll mult(ll a,ll b, ll p=MOD){return ((a%p)*(b%p))%p;}
ll add(ll a, ll b, ll p=MOD){return (a%p + b%p)%p;}
ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n%p; n = n * n%p;} return r;}
ll inv(ll a, ll p = MOD) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = MOD){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}



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

vector<ll>v;
 ll sum=0,act=0,k,n,q,f;
cin>>n;
ll arr[n][3];
forr(i,0,n)cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
ll dp[n][3];
dp[0][0]=arr[0][0];
dp[0][1]=arr[0][1];
dp[0][2]=arr[0][2];
forr(i,1,n)
{
    dp[i][0]=arr[i][0]+max(dp[i-1][1],dp[i-1][2]);
    dp[i][1]=arr[i][1]+max(dp[i-1][0],dp[i-1][2]);
    dp[i][2]=arr[i][2]+max(dp[i-1][1],dp[i-1][0]);
}
cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));

return 0;
}


Measured memory_bytes: 8344
#include <stdio.h>
#include <stdlib.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define MAX_DATA 100100
typedef long long ll;

struct queue
{
    int arr[MAX_DATA];
    int first; //次にpopする配列の添え字
    int last;  //次にpushする配列の添え字
};

int push(struct queue *que, int input)
{
    if (que->arr[que->last] <= MAX_DATA)
    {
        que->arr[que->last] = input;
        que->last++;
        //printf("push:%d\n", input);
        return 0;
    }
    else
    {
        printf("これ以上データを追加できません。\n");
        return -1;
    }
}

int pop(struct queue *que)
{
    int output = que->arr[que->first];

    if (output != -1)
    {
        que->arr[que->first] = -1;
        que->first++;
        //printf("pop:%d\n", output);
        return output;
    }
    else
    {
        printf("データがありません。\n");
        return -1;
    }
}

void init_queue(struct queue *que)
{
    int i;

    for (i = 0; i < MAX_DATA; i++)
        que->arr[i] = -1;

    que->first = 0;
    que->last = 0;
}

void show_queue(struct queue *que, int n)
{
    int i;
    for (i = 0; i < n; i++)
    {
        if (que->arr[i] != -1)
            printf("%d ", que->arr[i]);
    }

    printf("\nfirst:%d last%d\n\n", que->first, que->last);
}

int main(void)
{
    long *graph[100001], cnt[100001] = {0};
    long n, m;
    int ans[100100] = {0};

    scanf("%ld%ld", &n, &m);
    rep(i, m)
    {
        long a, b;
        scanf("%ld%ld", &a, &b);

        graph[a] = (long *)realloc(graph[a], sizeof(long) * (cnt[a] + 1));
        graph[a][cnt[a]] = b;
        cnt[a]++;

        graph[b] = (long *)realloc(graph[b], sizeof(long) * (cnt[b] + 1));
        graph[b][cnt[b]] = a;
        cnt[b]++;
    }
    graph[0] = (long *)realloc(graph[0], sizeof(long) * (cnt[0] + 1));
    graph[0][cnt[0]] = 0;
    cnt[0]++;
    /*
    rep(i, n + 1)
    {
        printf("graph[%d]={ ", i);
        rep(j, cnt[i])
            printf("%ld ", graph[i][j]);
        printf("} cnt:%ld\n", cnt[i]);
    }
*/
    // 初期化してから先頭に1をpush
    struct queue que;
    init_queue(&que);
    push(&que, 1);

    // -1：未発見の頂点
    // 頂点1を初期ノードとして初期化
    int dist[n + 1];
    rep(i, n + 1)
        dist[i] = -1;
    dist[1] = 0;

    // queが空になるまで探索
    while (que.first != que.last)
    {
        // queから先頭頂点を取り出す
        int v = pop(&que);

        // vから訪問できる頂点を調べる
        rep(i, cnt[v])
        {
            // graphから頂点を取得し発見済みは探索しない
            int nv = graph[v][i];
            if (dist[nv] != -1)
                continue;

            // 未発見の頂点nvについて距離を更新してqueにpush
            dist[nv] = dist[v] + 1;
            ans[nv] = v;
            push(&que, nv);
        }
        //show_queue(&que, n);
    }

    puts("Yes");
    for (int i = 2; i < n + 1; i++)
        printf("%d\n", ans[i]);

    return 0;
}

Measured memory_bytes: 10148
#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
const int N=1e5+5;
int n,q,f[N];
ll m;
int getf(int x){return x==f[x]?x:f[x]=getf(f[x]);}
vector<pair<int,int> >vc;
int main()
{
    scanf("%d%lld%d",&n,&m,&q);
    for(int i=1;i<=n;i++) f[i]=i;
    for(int i=1;i<=q;i++)
    {
        int u,v,c;scanf("%d%d%d",&u,&v,&c);
        u++;v++;
        if(!c) f[getf(u)]=getf(v);
        else vc.push_back({u,v});
        if(c&&m==n-1) return printf("No\n"),0;
    }
    if(m==n-1) return printf("Yes\n"),0;
    for(int i=0;i<vc.size();i++)
        if(getf(vc[i].fi)==getf(vc[i].se)){printf("No\n");return 0;}
    int tot=0;
    for(int i=1;i<=n;i++) if(getf(i)==i) tot++;
    m-=n-tot;
    if(tot==2&&vc.size()) {printf("No\n");return 0;}
    if(m<=(ll)tot*(tot-1)/2) printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

class UnionFind{
  vector<int> p;
public:
  UnionFind(int n){
    p = vector<int>(n, -1);
  }
  int root(int x){
    if (p[x] < 0)
      return x;
    return p[x] = root(p[x]);
  }
  int size(int x){
    return -p[root(x)];
  }
  bool unite(int x, int y){
    x = root(x);
    y = root(y);
    if(x == y){
      return false;
    }
    if(size(x) < size(y))
      swap(x, y);
    p[x] += p[y];
    p[y] = x;
    return true;
  }
};

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  UnionFind uf(n);
  vector<int> num(n, -1);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    uf.unite(a, b);
    --num[a], --num[b];
  }
  rep(i, n)
    num[i] += uf.size(i);
  rep(i, k) {
    int c, d;
    cin >> c >> d;
    --c, --d;
    if (uf.root(c) == uf.root(d))
      --num[c], --num[d];
  }
  rep(i, n) {
    if (i) cout << ' ';
    cout << num[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1664
#include <iostream>
using namespace std;
typedef long long ll;
ll dp[110][10] = {{0}},fib[10] = {0},inf = 1e9+7;
int H,W,K;
int main(){
	cin >> H >> W >> K;
	fib[0] = 1; fib[1] = 1;
	for(int i=2;i<=9;i++){
		fib[i] = fib[i-1]+fib[i-2];
	}
	dp[0][1] = 1;
	for(int i=0;i<H;i++){
		for(int j=1;j<=W;j++){
			if(j>=2){
				dp[i+1][j-1] += (fib[j-2]*fib[W-j])*dp[i][j];
				dp[i+1][j-1] %= inf;
			}
			if(j<=W-1){
				dp[i+1][j+1] += (fib[j-1]*fib[W-j-1])*dp[i][j];
				dp[i+1][j+1] %= inf;
			}
			dp[i+1][j] += (fib[j-1]*fib[W-j])*dp[i][j];;
			dp[i+1][j] %= inf;
		}
	}
	cout << dp[H][K] << endl;
}

Measured memory_bytes: 256
// package app;

import java.util.Arrays;
import java.util.Objects;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);

        // final String s = sc.next();
        final long N = sc.nextLong();
        final long A = sc.nextLong();
        final long B = sc.nextLong();
        // final String s = sc.next();
        // final String b = sc.next();

        // final int b = sc.nextInt();
        // final int D = sc.nextInt();
        // System.out.println();

        long result = 0;
        if(A == 0) {
            result = 0;
        } else if (B == 0) {
            result = N;
        }else {
            long sum = N / (A + B);
            long remain = N % (A + B);
            result = sum * A;
            result += remain >= A ? A : remain;
        }

        System.out.println(result);

        // System.out.println(A <= X && A + B >= X ? "YES" : "NO");

    }
}

Measured memory_bytes: 23636
#include <stdio.h>
int n;
long long x[60],y[60];
int flag[60];
int fin(long long p,long long q)
{
    //printf("%lld %lld\n",p,q);
    int oo=0;
    for (int i=1;i<=n;i++)
        flag[i]=1;
    for (int i=1;i<=n;i++)
    {
        if (flag[i])
        {
            oo++;
            int jia=1;int tmpx=x[i],tmpy=y[i];
            while(jia)
            {
                jia=0;
                for (int j=1;j<=n;j++)
                if ((x[j]==tmpx+p) && (y[j]==tmpy+q))
                {
                    jia=1;flag[j]=0;tmpx=x[j];tmpy=y[j];break;
                }
            }
            int jian=1;tmpx=x[i];tmpy=y[i];
            while(jian)
            {
                jian=0;
                for (int j=1;j<=n;j++)
                if ((x[j]==tmpx-p) && (y[j]==tmpy-q))
                {
                    jian=1;flag[j]=0;tmpx=x[j];tmpy=y[j];break;
                }
            }
        }
        //for (int i=1;i<=n;i++) printf(":%d",flag[i]);printf("%d\n",oo);
    }
    return oo;

}

int main()
{

    scanf("%d",&n);
    for (int i=1;i<=n;i++)
        scanf("%lld%lld",&x[i],&y[i]);

    int ans=n;
    for (int i=1;i<=n;i++)
    for (int j=1;j<=n;j++)
    if (i!=j)
    {
        int asd=fin(x[i]-x[j],y[i]-y[j]);
        if (asd<ans)
            ans=asd;
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 128
#include <stdio.h>

	int a[100005];
	int c;
	int ans;

int main(void)
{
	scanf("%d", &c);

	int i;
	
	for (i = 1; i <= c; ++i) {
		scanf("%d", &a[i]);
	}

	for (i = 1; i <= c; ++i) {
		if (i == a[a[i]]) ans++;
	}

	printf("%d\n", ans / 2);
	return 0;
}


Measured memory_bytes: 512