akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    string S;
    int Q;
    cin >> S >> Q;
    deque<char> A;
    for (int i = 0; i < S.size(); i++){
        A.emplace_back(S.at(i));
    }
    bool T = true;
    for (int i = 0; i < Q; i++){
        int a;
        cin >> a;
        if (a == 1){
            if (T){
                T = false;
            }
            else {
                T = true;
            }
        }
        else {
            int y;
            char c;
            cin >> y >> c;
            if (T && y == 2){
                A.emplace_back(c);
            }
            if (T && y == 1){
                A.emplace_front(c);
            }
            if (!T && y == 2){
                A.emplace_front(c);
            }
            if (!T && y == 1){
                A.emplace_back(c);
            }

        }
    }
    if (T){
        while(A.size() > 0){
            cout << A.front();
            A.pop_front();
        }
    }
    else {
        while(A.size() > 0){
            cout << A.back();
            A.pop_back();
        }
    }
    cout << endl;

}


Measured memory_bytes: 896
import scala.io.StdIn.{readLine,readInt}

object Main extends App {
  var w = ""

  def shuffle(cnt:Int, w:String):String = {
    if(cnt == 0) { w }
    else {
      val m = readInt
      shuffle(cnt-1, (w+(w take m)) drop m)
    }
  }

  while( { w = readLine.trim;w } != "-") {
    val n = readInt
    println(shuffle(n,w))
  }
}

Measured memory_bytes: 43804
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int q, t, f;
    char c;
    cin >> s >> q;
    string front, back;
    bool tgr = false;
    for (int i = 0; i < q; i++)
    {
        cin >> t;
        if (t == 1)
        {
            tgr = !tgr;
        }
        else
        {
            cin >> f >> c;
            if (tgr == false)
            {
                if (f == 1)
                    front = c + front;
                if (f == 2)
                    back = back + c;
            }
            else
            {
                if (f == 1)
                    back = back + c;
                if (f == 2)
                    front = c + front;
            }
        }
    }
    if(tgr == true) {
        reverse(front.begin(), front.end());
        reverse(back.begin(), back.end());
        reverse(s.begin(), s.end());
        cout << back + s + front << '\n';
    }
    else
        cout << front + s + back << '\n';


    return 0;
}

Measured memory_bytes: 1512
n=int(input())
a=list(map(int,input().split()))
dp=[0]*(n+1)
dp[0]=1000
for i in range(1,n+1):
    for j in range(i):
        dp[i]=max(dp[j]%a[j]+dp[j]//a[j]*a[i-1],dp[i])
    dp[i]=max(dp[i],dp[i-1])
print(dp[n])    

Measured memory_bytes: 9216
#include <iostream>

#include <set>
#include <vector>
#include <string>

using namespace std;

struct T
{
    int h;
    set<int> roads;
    bool flg;
};

int main()
{
    vector<T> vec;
    int n, m;

    cin >> n >> m;

    for(int i = 0; i < n; ++i)
    {
        vec.emplace_back();
        vec.back().flg = true;
        cin >> vec.back().h;
    }


    for(int i = 0; i < m; ++i)
    {
        int a, b;
        cin >> a >> b;
        vec[a - 1].roads.emplace(b - 1);
        vec[b - 1].roads.emplace(a - 1);
    }

    int ans = 0;
    for(auto& v : vec)
    {
        if(!v.flg)
            continue;
        bool flg = true;
        for(auto& r : v.roads)
        {
            if(v.h <= vec[r].h)
            {
                flg = false;
            }
            else
            {
                v.flg = false;
            }
            
        }

        if(flg)
        {
            ++ans;
        }
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 18980
from heapq import heappush, heappop
import sys
input = sys.stdin.readline
n, m = map(int, input().split())
ab = [tuple(int(i) for i in input().split()) for _ in range(n)]
ab.sort()
hq = []
result = 0
j = 0
for i in range(1, m + 1):
    while j < n and ab[j][0] <= i:
        heappush(hq, -ab[j][1])
        j += 1
    if hq:
        result -= heappop(hq)
print(result)

Measured memory_bytes: 20744
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_C
{
    class C068
    {
        static void Main(string[] args)
        {
            string[] s1 = Console.ReadLine().Split(' ');
            int N = int.Parse(s1[0]);
            int M = int.Parse(s1[1]);

            HashSet<int> connect1 = new HashSet<int>();
            HashSet<int> connectN = new HashSet<int>();

            bool possible = false;
            for(int i = 0; i < M; i++)
            {
                string[] s = Console.ReadLine().Split(' ');
                int a = int.Parse(s[0]);
                int b = int.Parse(s[1]);
                if (a == 1)
                {
                    if (connectN.Contains(b))
                    {
                        possible = true;
                        break;
                    }
                    connect1.Add(b);
                }
                if (b == N)
                {
                    if (connect1.Contains(a))
                    {
                        possible = true;
                        break;
                    }
                    connectN.Add(a);
                }
            }
            if (possible) Console.WriteLine("POSSIBLE");
            else Console.WriteLine("IMPOSSIBLE");
        }
    }
}


Measured memory_bytes: 25516
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

static constexpr int mod = (int)1e9 + 7;
static constexpr int inf = 100100100;
static constexpr ll linf = 1e18;
static constexpr double eps = 1e-9;
static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, n) for (ll i = n; i >= 0; --i)
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define pb push_back
#define ist insert
#define fst first
#define snd second



int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> A;
    rep (i, N) {
        ll a;
        cin >> a;
        A.pb(a);
    }
    ll a0 = A[0] + A[1];
    ll a1 = -a0;
    for (ll i = 1; i < N - 1; ++i) {
        ll a00 = a0 + A[i + 1];
        ll a01 = a0 - 2 * A[i] - A[i + 1];
        ll a10 = a1 + A[i + 1];
        ll a11 = a1 + 2 * A[i] - A[i + 1];
        a0 = max(a00, a10);
        a1 = max(a01, a11);
    }
    cout << max(a0, a1) << endl;
}


Measured memory_bytes: 1400
#include<iostream>
int R,C,s[10000][10],f[10],N,i,j,n,m;void rec(int k){if(k<R){f[k]=0;rec(k+1);f[k]=1;rec(k+1);}else{for(n=i=0;i<C;i++,n+=m>R-m?m:R-m)for(m=j=0;j<R;j++)m+=s[i][j]^f[j];N=N>n?N:n;}}main(){for(;std::cin>>R>>C,R;rec(0),printf("%d\n",N))for(j=R;j-->0;)for(i=C;i-->0;)std::cin>>s[i][j];}

Measured memory_bytes: 1256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int         long long
#define mod         1000000007
#define FAST        ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define f(i,n)      for(int i=0;i<n;i++)
#define fp(i,k,n)   for(int i=k;i<=n;i++)
#define fr(i,k,n)   for(int i=k;i>=n;i--)
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define dbg(x)      cout << (#x) << " is " << (x) << '\n' 
#define F           first
#define S           second
#define sz(x)       (int)(x).size()
#define lb          lower_bound
#define ub          upper_bound
#define mems(x)     memset(x,0,sizeof(x))
#define all(a)      a.begin(),a.end()
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
/*---------------------------------------------------------------------------------------------------*/

void solve()
{
  int n;
  cin >> n;
  map<string,int> m;
  f(i,n)
  {
      string s;
      cin >> s;
      m[s]++;
  }
  cout << "AC x " << m["AC"] << '\n';
  cout << "WA x " << m["WA"] << '\n';
  cout << "TLE x " << m["TLE"] << '\n';
  cout << "RE x " << m["RE"] << '\n';
  return;
} 

signed main()
{
  FAST
  int T=1;
//   cin >> T;
  while(T--)
  {
    solve();
  }
  return 0;
}


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

int main(void) {
    int n,m,q;
    cin >> n >> m >> q;

    vector<vector<int>> cnt(n, vector<int>(n, 0));
    for(size_t i=0; i<m; i++) {
        int l, r;
        cin >> l >> r;
        l--, r--;
        cnt[l][n-1]++;
        if(r-l>0)
            cnt[l][r-l-1]--;
    }

    for(auto &v: cnt)
        for(size_t i=n-1; i>0; i--)
            v[i-1] += v[i];

    for(size_t i=0; i<q; i++) {
        int p,q;
        cin >> p >> q;
        p--, q--;
        int r=0;
        for(size_t i=p; i<=q; i++)
            r += cnt[i][q-i];
        cout << r << endl;
    }

}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int A=0,B=0;
  vector<int> cards(N);
  for(int i=0;i<N;i++){
    cin >> cards[i];
  }
  sort(cards.begin(),cards.end());
  if(N%2==0){
    for(int i=0;i<N/2;i++){
      A += cards[2*i+1];
      B += cards[2*i];
    }
  }else{
    for(int i=0;i<N/2;i++){
      A += cards[2*i];
      B += cards[2*i + 1];
    }
    A += cards[N-1];
  }
  cout << A-B << endl;
}

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

int main(){

	while(1){
        
        int H,W;
		cin >> H >> W;
		if(0 == W && H == 0)break;
        
            for(int i=1; H>=i; i++){  //??????????????????????????????
                
                int j=1, w=W;

        		if( i%2 == 0){  //i???????????¶??°???????????????????????????
                   cout << ".";
                   w--; //??????????????????????????????w???????????????
        		}

        		while(w>=j){       //.??¨#??????????????????
        			if(j%2 != 0 )cout << "#";
        			else cout << ".";
        			j++;
        		}

        		cout <<endl;

        	}

        cout <<endl;   	
    }  

return 0;

}

Measured memory_bytes: 3092
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,sum=0,c,d,min=101;
    for(int i=0;i<4;i++){
        cin>>a;
        sum+=a;
        if(min>a)min=a;
    }
    sum-=min;
    cin>>c>>d;
    if(c>d)cout<<sum+c<<endl;
    else cout<<sum+d<<endl;
}



Measured memory_bytes: 3096
/**
*    created: 01.07.2020 21:07:29
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const int MOD = 1000000007;
// const int MOD = 998244353;
const long double pi = acos(-1.0);
const int INF = 1LL << 60;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int a, b;
    cin >> a >> b;
    if (a > 1 && b > 1) cout << (a-2)*(b-2) << endl;
    else if (a == 1 & b > 1) cout << b-2 << endl;
    else if (b == 1 & a > 1) cout << a-2 << endl;
    else cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
using namespace std;

int main() {
    int A, B;
    cin >> A >> B;
    int ans;
    if (A == B) {
        cout << 0 << endl;
    } else if ((A+B) % 2 == 0) {
        cout << (A + B) / 2 << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main (){
  int L,M,N,sum,x;
  cin >> L;
  
  for(int i = 0; i < L; i++){
    cin >> M >> N;
    x = N - M + 1;
    sum += x;
  }
  cout << sum << endl;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define vi                      vector<int>
#define vld                     vector<ld>
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define fi                      first
#define se                      second
#define fastIO                  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("debug.txt", "w", stderr);
	#endif
}

int dpx[8]={1,1,1,-1,-1,-1,0,0};
int dpy[8]={-1,1,0,1,-1,0,-1,1};

int32_t main()
{
	fastIO
	inp_out();
	int n; 
	cin >> n; 
	
	for(int i = 1; i <=  n;  ++ i)
	{
		int ans = 0; 
		for(int x = 1; ;  ++ x)
		{
			if(x * x > i)
				break; 
			for(int y = 1; ;  ++ y)
			{
				if(x * x + y * y + x * y > i)
					break; 
				for(int z  =  1; ;  ++ z)
				{
					if(x * x + y * y + z * z + x * y + y * z + z * x > i)
						break; 
					if(x * x + y * y + z * z + x * y + y * z + z * x == i)
						 ++ ans; 
				}
			}
		}
		cout << ans << "\n"; 
	}

	return 0;
}

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

using namespace std;

#define PROBLEM "B"

#define USE_CPPIO() ios_base::sync_with_stdio(0); cin.tie(0)

int main(int argc, char const *argv[])
{
	#ifdef DBG
	freopen(PROBLEM ".in", "r", stdin);
	freopen(PROBLEM ".out", "w", stdout);
	#endif

	int N, order[25], B[25], C[24], ans;
	while(cin >> N){
		ans = 0;
		for (int i = 1; i <= N; ++i)
			cin >> order[i];

		for (int i = 1; i <= N; ++i)
			cin >> B[i];

		for (int i = 1; i <= N-1; ++i)
			cin >> C[i];

		for (int i = 1; i <= N; ++i){
			if (i == 1){
				ans += B[order[i]];
			}
			else{
				if (order[i] - order[i-1] == 1){
					ans += (B[order[i]] +C[order[i-1]] );
				}
				else{
					ans += B[order[i]];
				}
			}
			//cout<<"ans: "<<ans<<endl;
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort()
bottle, cost, i = 0, 0, 0
while bottle < M:
    cost += AB[i][0] * AB[i][1]
    bottle += AB[i][1]
    i += 1

cost -= (bottle - M) * AB[i-1][0]
print(cost)



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

int main() {
  vector<vector<int>> c (3, vector<int>(3));
  
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> c.at(i).at(j);  
    }
  }
  
  if ( c.at(1).at(0)-c.at(0).at(0) == c.at(1).at(1)-c.at(0).at(1) && c.at(1).at(1)-c.at(0).at(1) == c.at(1).at(2)-c.at(0).at(2) && c.at(2).at(0)-c.at(0).at(0) == c.at(2).at(1)-c.at(0).at(1) && c.at(2).at(1)-c.at(0).at(1) == c.at(2).at(2)-c.at(0).at(2)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<pll> vp;
#define fr first
#define sc second

const int maxn=131073;

int n,tot;
ll dis[maxn];
int son[maxn][2],num[maxn];
ll l,r=1ll*maxn*maxn,limit;

vp f[maxn];

int read() {
	int x=0,f=1;char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return x*f;
}

vp dp(vp a,vp b) {
	vp res;res.clear();
	int x=a.size(),y=b.size(),st1=0,st2=0;
	if(!y)return res;
	while(st1!=x) {
		while(st2!=y&&a[st1].sc+b[st2].fr<=limit)st2++;
		if(st2)st2--;
		if(a[st1].sc+b[st2].fr<=limit)res.push_back(make_pair(a[st1].fr,b[st2].sc));
		st1++;
	}
	return res;
}

void insert(vp &a,pll b) {
	if(a.empty())a.push_back(b);
	else if(a.back().fr==b.fr)a.back().sc=min(a.back().sc,b.sc);
	else if(b.sc<a.back().sc)a.push_back(b);
}

vp merge(vp a,vp b) {
	vp res;res.clear();
	int x=a.size(),y=b.size(),st1=0,st2=0;
	while(st1!=x&&st2!=y) {
		if(a[st1].fr<b[st2].fr)insert(res,a[st1++]);
		else insert(res,b[st2++]);
	}
	while(st1!=x)insert(res,a[st1++]);
	while(st2!=y)insert(res,b[st2++]);
	return res;
}

void dfs(int u) {
	if(!num[u]) {
		f[u].clear();
		f[u].push_back(make_pair(dis[u],dis[u]));
		return;
	}
	dfs(son[u][0]),dfs(son[u][1]);limit+=dis[u]*2;
	vp tmp1=dp(f[son[u][0]],f[son[u][1]]);
	vp tmp2=dp(f[son[u][1]],f[son[u][0]]);
	f[u]=merge(tmp1,tmp2);
	limit-=dis[u]*2;
}

bool check() {
	dfs(1);
	if(!f[1].empty())return 1;
	return 0;
}

int main() {
	n=read();
	for(int i=2;i<=n;i++) {
		int fa=read(),v=read();
		dis[i]=dis[fa]+v;
		son[fa][num[fa]++]=i;
	}
	while(l<r) {
		limit=(l+r)>>1;
		if(check())r=limit;
		else l=limit+1;
	}
	printf("%lld\n",r);
	return 0;
}


Measured memory_bytes: 30184
#include<bits/stdc++.h>
using namespace std;
const int maxn=3003;
const int mod=1e9+7;
int Ans;
int n,m;
unsigned f[maxn][maxn][2];

int main(){
	scanf("%d%d",&n,&m);
	int Ans=0;
	f[0][0][1]=1;
	for(int i=1;i<=n;i++)f[0][i][0]=1;
	for(int i=0;i<m;i++){
		for(int j=0;j<=n;j++){
			if(j<n)(f[i+1][j+1][0]+=f[i][j][0])%=mod;
			if(j>1){
				f[i+1][j][0]=(f[i+1][j][0]+(1+(j<n))*f[i][j][0])%mod;
				(f[i+1][j-1][0]+=f[i][j][0])%=mod;
			}
			else if(j==1){
				(f[i+1][j][1]+=f[i][j][0])%=mod;
				if(n>1)(f[i+1][j][0]+=f[i][j][0])%=mod;
				(f[i+1][j-1][1]+=f[i][j][0])%=mod;
			}
			f[i+1][j][1]=(f[i+1][j][1]+(1+(j&&j<n))*f[i][j][1])%mod;

			if(j<n)(f[i+1][j+1][1]+=f[i][j][1])%=mod;
			if(j)(f[i+1][j-1][1]+=f[i][j][1])%=mod;
		}
	}
	for(int i=0;i<=n;i++)(Ans+=f[m][i][1])%=mod;
	printf("%d\n",Ans);
	return 0;
}


Measured memory_bytes: 70656
# 標準入力
input = list(map(int, input().split())) # map関数: listの各要素に対して一定の処理を行う
min, max, div = input[0], input[1], input[2]
count = 0
for i in range(min, max+1):
    if i % div == 0:
        count += 1
print(count)


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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	for(int n,k;cin>>n>>k&&n|k;){
		vi a(n);
		rep(i,n) cin>>a[i];

		int g=a[0];
		rep(i,n) g=__gcd(g,a[i]);

		bool ok=false;
		rep(i,n)
			ok|=a[i]>=k&&(a[i]-k)%g==0;

		cout<<(ok?"POSSIBLE":"IMPOSSIBLE")<<endl;
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
void print() {
    cout << endl;
}
template <class Head, class... Tail>
void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail) != 0)
        cout << " ";
    print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
    for (auto &a : vec) {
        cout << a;
        if (&a != &vec.back())
            cout << " ";
    }
    cout << endl;
}
template <class T>
void print(vector<vector<T>> &df) {
    for (auto &vec : df) {
        print(vec);
    }
}
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define xrep(i, a, b) for (int i = int(a); i < int(b); ++i)
#define zrep(i, a, b, c) for (int i = int(a); i < int(b); i+=int(c))
using ll = long long;
const int INF = 1001001001;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> H(N);

    rep(i, N) cin >> H[i];

    vector<vector<int>> to(N);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    vector<int> OK;
    int ans = 0;
    rep(i, N) {
        int my_height = H[i];
        int cnt = 0;
        for(auto v: to[i]) {
            if(my_height > H[v]) {
                cnt++;
            }
        }
        if(cnt == to[i].size()) {
            ans++;
            OK.push_back(i);
        }
    }

    print(ans);
    return 0;
}

Measured memory_bytes: 9364
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vectors<decltype(inner)>(x, inner); }
template<class T> void show_with_brank(T a){ int cnt = 0; for(auto itr :a){ if(cnt++ != 0) cout << " "; cout << itr;} }
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
#define int ll
class beki{
public:
    vector<bool>num;
    beki(int n){
        num = vector<bool>(n+1,false);
        for(int i = 2; i<=num.size();i++){
            for(int j = i*i; j<=num.size(); j*=i){
                num[j] = true;
            }
        }
    }
    int ask(int x){
        for(int i = x; ;i--)
            if(i == 1 || num[i]) return i;
    }
};
signed main(){
    int x; cin >> x;
    beki a (x);
    cout << a.ask(x) << endl;
}





Measured memory_bytes: 256
#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;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

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();}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)...);}

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

	ll N=in<ll>();
	ll sum = N*(N+1LL)/2LL;
	sum -= N;
	
	out(sum);
	return 0;
}


Measured memory_bytes: 256
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0 }, dy[] = { 0,1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}

	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑

int main() {
	long long a, b, c, d;
	cin >> a >> b >> c;
	d = max((long long)0, (c - b) / (a - b));
	a %= MOD; b %= MOD; c %= MOD; d %= MOD;
	cout << (d*b + c) % MOD << endl;
}


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

#define NREP() for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(),(x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

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

int main(int argc, char *argv[]) {
    ll n;
    cin >> n;

    ll a[n + 10];
    ll sum = 0;

    NREP() {
        cin >> a[i];
        sum += a[i];
    }

    ll a1 = sum;
    for (int i = 1; i < n; i+=2) {
        a1 -= a[i]*2;
    }
    cout << a1 << " ";

    ll bef = a1;
    for (int i = 0; i < n-1; ++i) {
        cout << a[i]*2 - bef << " ";
        bef = a[i]*2 - bef;
    }
    cout << endl;
}


Measured memory_bytes: 2048
/*
* Welcome to my code!
*---------------------------------------------*
* author : lynmisakura(twitter : @andoreiji11)
*/

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define repn for(int i = 0;i < n;i++)
#define ain(a) for(auto& i : a)cin >> i;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size()) 
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define cont continue

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using pi = pair<int,int>;
using vpi = vector<pi>;
using pl = pair<ll,ll>;
using vpl = vector<pl>;

template<class T> bool chmin(T& a,T b){if(a > b){a = b;return true;}else return false;}
template<class T> bool chmax(T& a,T b){if(a < b){a = b;return true;}else return false;}
template<class T> void print(std::vector<T> a){ int sz = a.size();
for(int i=0;i<a.size();i++)cout << a[i] << (i < sz-1 ? ' ' : '\n'); }
void ioboost(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}
///////////////////////////////////////////////////////////
//素因数分解 O(√n)
map<ll,ll>prime_factor(ll n){
    map<ll,ll> res;
    for(ll i = 2;i * i <= n;i++){
        while(n % i == 0){
            ++res[i];
            n /= i;
        }
    }
    if(n != 1) res[n] = 1LL;
    return res;
}


ll func(ll a,ll b){
	return a*a*a*a*a - b*b*b*b*b;
}
int main(int argc, char const *argv[])
{
	ioboost();
	ll x;cin >> x;

	for(ll a = -1000;a <= 1000;a++){
		for(ll b = -1000;b <= 1000;b++){
			if(func(a,b) == x){
				cout << a << ' ' << b << '\n';
				return 0;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int n[3];
	
	cin >> n[0] >> n[1] >> n[2];
	
	sort(n, n + 3);
	
	if (n[0] == 5 && n[1] == 5 && n[2] == 7) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	
	return (0);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <complex>
using namespace std;
using D = long double;
using P = complex<D>;
using Poly = vector<P>;
using L = pair<P,P>;
#define X real()
#define Y imag()
constexpr D EPS = 1e-10;

void debug(Poly p){
  cerr << "Polygon" << endl;
  for(auto e : p) cerr << e.X << " " << e.Y << endl;
  cerr << "..." << endl;
}

void debug(L l){
  fprintf(stderr,"Segment %Lf %Lf %Lf %Lf\n",l.first.X,l.first.Y,l.second.X,l.second.Y);
}

D dot(const P &a, const P &b){ return a.X*b.X + a.Y*b.Y; }
D cross(const P &a, const P &b){ return a.X*b.Y - a.Y*b.X; }

P intersection(const L &a, const L &b){
  P af = a.first, as = a.second, bf = b.first, bs = b.second;
  return af + cross(bs-bf,af-bf)/(-cross(bs-bf,as-bf)+cross(bs-bf,af-bf))*(as-af);
}

int ccw(P a, P b, P c){
  b -= a, c -= a;
  if(cross(b,c) > +EPS) return +1;
  if(cross(b,c) < -EPS) return -1;
  if(dot(b,c) < +EPS) return +2;
  if(norm(b) + EPS < norm(c)) return -2;
  return 0;
}

Poly convex_cut(const Poly &p, const L &l){
  // debug(p);
  // debug(l);
  Poly ret;
  int n = p.size();
  for(int i = 0; i < n; ++i){
    P cur = p[i], nex = p[(i+1)%n], lf = l.first, ls = l.second;
    if(ccw(lf,ls,cur) != -1)
      ret.push_back(cur);
    if((ccw(lf,ls,cur) != -1) ^ (ccw(lf,ls,nex) != -1))
      ret.push_back(intersection(L(cur,nex),l));
  }
  //debug(ret);
  //cerr << endl;
  return ret;
}

D area(const Poly &p){
  int n = p.size();
  D ret = 0;
  for(int i = 0; i < n; ++i){
    ret += cross(p[i],p[(i+1)%n]);
  }
  return ret/2;
}

int main(){
  int n;
  while(cin >> n, n){
    Poly p;
    for(int i = 0; i < n; ++i){
      D x, y;
      cin >> x >> y;
      p.emplace_back(x,y);
    }
    Poly S = {P(-10,-10),P(10010,-10),P(10010,10010),P(-10,10010)};
    for(int i = 0; i < n; ++i){
      S = convex_cut(S,L(p[i],p[(i+1)%n]));
      //cerr << S.size() << endl;
      // debug(L(p[i],p[(i+1)%n]));
      // debug(S);
    }
    if(area(S) < EPS) cout << 0 << endl;
    else cout << 1 << endl;
  }
}



Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll mod =1e9+7;
#define MAX 1000005
ll f[MAX];
ll iv[MAX];
ll poer(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=(res*a)%mod;
		a=(a*a)%mod;
		b/=2;
	}
	return res;
}
void in_it(){
	f[0]=1;
	iv[0]=1;
	for(int i=1;i<MAX;++i) f[i]=(f[i-1]*i)%mod;
	iv[MAX-1]=poer(f[MAX-1],mod-2);
	for(int i=MAX-2;i>=0;--i) iv[i]=(iv[i+1]*(i+1))%mod;
}
ll C(ll n, ll r){
	if(n<r) return 0;
	ll ans=(f[n]%mod*iv[r]%mod)%mod;
	ans =(ans*iv[n-r]%mod)%mod;
	return ans;
}
int main(){
	ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
	in_it();
	ll h,w,a,b;
	cin>>h>>w>>a>>b;
	ll ans=0;
	for(int i=b;i<w;++i){
		ll x1=i;
		ll y1=h-a-1;
		ll term1=C(x1+y1,x1);
		ll x2=w-1-i;
		ll y2=a-1;
		ll term2=C(x2+y2,y2);
		term1%=mod;
		term2%=mod;
		ans=(ans+(term1*term2)%mod)%mod;
	}
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 19244
#include<bits/stdc++.h>
#define ll long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=200005;
const ll mod=1e9+7;
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {x=x*10+ch-'0',ch=getchar();}
    return x*f;
}
struct node{
	int h,x;
	friend bool operator < (node a, node b){
		return a.x<b.x;
	}
}t[N];
int n,d,a;
ll cnt[N],x[N];
#define lowbit(x) (x&(-x))
ll qry(int x)
{
	ll ret=0;
	for(int i=x; i>0; i-=lowbit(i)) ret+=cnt[i];
//	for(int i=x-1; i>0; i-=lowbit(i)) ret-=cnt[i];
	return ret;
}
void upd(int x,ll v)
{
	if(!x) return;
	for(int i=x; i<=n; i+=lowbit(i)) cnt[i]+=v;
}
int main()
{
	n=read(); d=read(); a=read();
	for(int i=1; i<=n; i++){
		t[i].x=read(); t[i].h=read();
	}
	sort(t+1, t+n+1);
	for(int i=1; i<=n; i++){
		x[i]=t[i].x;
		ll k=t[i].h/a;
		if(t[i].h%a) k++;
		upd(i, k);
		upd(i+1, -k);
	}
	ll ans=0;
	for(int i=1; i<=n; i++){
		ll res=qry(i);
		if(res<=0) continue;
		ans+=res;
		int r=lower_bound(x+i, x+n+1, (ll)x[i]+2ll*d)-x;
		if(r>n || x[r]>x[i]+2ll*d) r--;
		upd(i, -res);
		upd(r+1, res);
	}
	cout<<ans<<endl;
}




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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long double ld;
typedef long long ll;
const int MOD =  1000000007;
const int IINF = INT_MAX;
const ll INF = 1LL << 60;

int n, m, q;
vector<int> a, b, c, d;
int ans = 0;

void dfs(vector<int> &A, int &res){
    if(A.size() == n + 1){
        int sum = 0;
        for(int i = 0; i < q; i++){
            if(A[b[i]] - A[a[i]] == c[i]) sum += d[i];
        }
        ans = max(ans, sum);
        return;
    }
    int x = A.back();
    for(int i = x; i <= m; i++){
        A.push_back(i);
        dfs(A, res);
        A.pop_back();
    }

}

int main() {
    cin >> n >> m >> q;
    a = b = c = d = vector<int>(q);
    for(int i = 0; i < q; i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    int res = 0;
    vector<int> A(1,1);
    dfs(A, res);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3524
#include<stdio.h>
#include<vector>
#include <algorithm>
int main()
{
	int N;
	scanf("%d", &N);

	std::vector<std::pair<int, int> > tasks;
	int tempRequire, tempLimit;
	for (int i = 0; i < N; i++) {
		scanf("%d %d", &tempRequire, &tempLimit);
		tasks.emplace_back(tempLimit, tempRequire);
	}

	std::sort(tasks.begin(), tasks.end());

	int sum_Time = 0;
	bool bYes = true;

	for (auto& temp: tasks) {
		sum_Time += temp.second;

		if (sum_Time > temp.first) {
			bYes = false;
			break;
		}
	}

	if (bYes) {
		printf("Yes");
	}
	else {
		printf("No");
	}
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           (ll)x.size()
#define hell            1000000007
#define inf             (ll)1e18 + 5
#define PI              3.14159265358979323844
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

ll n,m,vis[100005];
vi a[100005];
ll dp[100005];

ll find(ll node){
	vis[node]=1;
	if (sz(a[node])==0)return 0;
	if (dp[node]!=-1)return dp[node];
	ll temp=0;
	for (auto i:a[node]){
		if (!vis[i])
			temp=max(temp,find(i));
		else temp=max(temp,dp[i]);
	}
	dp[node]=1+temp;
	return dp[node];
}

void solve() {
    cin>>n>>m;
    rep(i,0,m){
    	ll x,y;
    	cin>>x>>y;
    	a[x].pb(y);
    }
    ll ans=0;
    memset(dp,-1,sizeof dp);
    rep(i,1,n+1){
    	ans=max(find(i),ans);
    }
    cout<<ans<<endl;
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}

Measured memory_bytes: 9344
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

bool is_palindromic(ll n){
  str s = to_string(n);
  return s[0]==s[4]&&s[1]==s[3];
}

int main(){
  ll a,b;
  cin >> a >> b;
  ll ans = 0;
  for(ll i = a; i <=b; i++){
    if(is_palindromic(i)) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
#define bin(x)     (bitset<3>(x))
using namespace std;
using ll = long long;

int swap_bits(int x,int i,int j) {
	int bit_i=x>>i&1;
	int bit_j=x>>j&1;
	return x^(bit_i<<i)^(bit_j<<j)^(bit_i<<j)^(bit_j<<i);
}

vector<int> solve(int n,int a,int b) {
	if (__builtin_parity(a) == __builtin_parity(b)) return {};

	if (n==1) return {a,b};

	int k=0;
	while ((a>>k&1)==(b>>k&1)) k++;
	a=swap_bits(a,k,0);
	b=swap_bits(b,k,0);
	assert((a&1)!=(b&1));

	int c=a>>1, d=b>>1;
	auto p=solve(n-1,c,c^1);
	auto q=solve(n-1,c^1,d);

	vector<int> res;
	for (auto x:p) {
		int nx=swap_bits(x<<1|(a&1),k,0);
		res.push_back(nx);
	}
	for (auto x:q) {
		int nx=swap_bits(x<<1|(b&1),k,0);
		res.push_back(nx);
	}

	return res;
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	int N,A,B;
	cin>>N>>A>>B;
	auto res=solve(N,A,B);
	if (res.empty()) {
		cout<<"NO\n";
	} else {
		cout<<"YES\n";
		for (int x:res) cout<<x<<" ";
		cout<<"\n";
	}
}


Measured memory_bytes: 1756
#include <bits/stdc++.h>
#define sz              size()
#define pb              push_back
#define Fr              first
#define Sc              second
#define Log2(x)         (31^__builtin_clz(x))
#define endl            "\n"
#define int             ll
using namespace std;
typedef long long ll;
int n, k;
int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin >> n >> k;
    if(n < k) cout << min(n, abs(n - k)) << endl;
    else {
        int t = n / k;
        cout << min({abs(n - t * k), abs(n - k * (t - 1)), abs(n - k * (t + 1))}) << endl;
    }
}


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

const ll MOD=1000000007;

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b){
  ll p=1;
  for(int i=0;i<b;i++){
    p*=a;
  }
  return p;
}

int digit(ll a,ll b){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p=MOD){
  a%=p;
  ll n=solveLinear(a,p,1);
  n%=p;
  if(n<0)return n+p;
  return n;
}

ll binom1(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i)/(i+1);
    if(ret>=p)ret%=p;
  }
  return ret;
}

int main(){
  int i,j,k,cnt=0;
  int n;
  cin>>n;
  int a[n+1],b[n+1],c[n+1];
  for(i=1;i<=n;i++)cin>>a[i]>>b[i]>>c[i];
  int da[n+1],db[n+1],dc[n+1];
  da[1]=a[1];db[1]=b[1];dc[1]=c[1];
  for(i=2;i<=n;i++){
    da[i]=max(db[i-1],dc[i-1])+a[i];
    db[i]=max(da[i-1],dc[i-1])+b[i];
    dc[i]=max(da[i-1],db[i-1])+c[i];
  }
  cout<<max(da[n],max(db[n],dc[n]));
}


Measured memory_bytes: 2560
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)

	var nums []int

	count := 0
	for i := 0; i < n; i++ {
		var x int
		fmt.Scan(&x)
		nums = append(nums, x)
		count += x
	}

	sort.Sort(sort.IntSlice(nums))

	fmt.Println(nums[0], nums[len(nums)-1], count)
}



Measured memory_bytes: 2192
(defun holiday ()
  (let ((day (read))
        (ans nil))
    (cond ((eq day 'SUN) (setf ans 7))
          ((eq day 'MON) (setf ans 6))
          ((eq day 'TUE) (setf ans 5))
          ((eq day 'WED) (setf ans 4))
          ((eq day 'THU) (setf ans 3))
          ((eq day 'FRI) (setf ans 2))
          ((eq day 'SAT) (setf ans 1)))
    (format t "~d" ans)))

(holiday)


Measured memory_bytes: 9824
import java.util.*;

public class Main {
	  public static void main(String args[]){
      	Scanner scan = new Scanner(System.in);
            
        int N = scan.nextInt();
        
        int num1000, num100, num10, num1;
        String cnt;
        
        num1 = N % 10;
        num10 = (N % 100 - num1) / 10;
        num100 = (N % 1000 - num10 - num1) / 100;
        num1000 = (N - num100 - num10 - num1) / 1000;
        
        if(num1000 == num100 && num100 == num10)cnt ="Yes";
        else if(num100 == num10 && num10 == num1)cnt ="Yes";
        else{
          cnt = "No";
        }
            
        System.out.println(cnt);
        
	   }
}

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

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

void test_case() {
  int n;
  cin >> n;
  vector<int> V(n + 1);
  map<int, int> cnt_odd, cnt_even;
  for (int i = 1; i <= n; ++i) {
    cin >> V[i];
    if (i & 1) {
      ++cnt_odd[V[i]];
    } else {
      ++cnt_even[V[i]];
    }
  }
  cnt_odd[0] = cnt_even[0] = 0;
  multiset<pair<int, int>> r_cnt;
  for (auto i : cnt_even) {
    r_cnt.insert({i.second, i.first});
  }
  int mn = INT_MAX;
  for (auto f : cnt_odd) {
    if (cnt_even.count(f.first)) {
      r_cnt.erase({cnt_even[f.first], f.first});
    }
    int curr = n - (f.second + (*r_cnt.rbegin()).first);
    mn = min(mn, curr);
    if (cnt_even.count(f.first)) {
      r_cnt.insert({cnt_even[f.first], f.first});
    }
  }
  cout << mn << "\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  test_case();
  return 0;
}


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

int N;
vector< int > g[100000];
int dist[2][100000], id;
 
void dfs(int idx, int par = -1)
{
  if(~par) dist[id][idx] = dist[id][par] + 1;
  for(auto &to : g[idx]) if(to != par) dfs(to, idx);
}
 
int main()
{
  cin >> N;
  for(int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
 
  id = 0;
  dfs(0);
  id = 1;
  dfs(N - 1);
 
  int ret = 0;
  for(int i = 0; i < N; i++) {
    if(dist[0][i] <= dist[1][i]) ++ret;
  }
  if(ret >= (N + 2) / 2) cout << "Fennec" << endl;
  else cout << "Snuke" << endl;
}

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

int main() {

	using namespace std;

	int N;
	cin >> N;
	
	int count = 0;
	
	for (int i = 1; i < N; i++) {
		count += N / i;
		if (N == i * (N / i)) count--;
	}

	cout << count << endl;

	return 0;

}

Measured memory_bytes: 3616
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

// 区間更新区間取得
// 遅延評価セグ木

template <typename T, typename E>
struct SegmentTree{
    using F = function<T(T, T)>;
    using G = function<T(T, E)>;
    using H = function<E(E, E)>;
    using P = function<E(E, int)>;
    int n;
    F f;
    G g;
    H h;
    P p;
    T ti;
    E ei;
    vector<T> dat;
    vector<E> laz;
    SegmentTree(){};
    SegmentTree(F f, G g, H h, T ti, E ei, const vector<T> &v, P p=[](E a, int b){return a;}):
                f(f),g(g),h(h),ti(ti),ei(ei),p(p){
        int sz = v.size();
        n = 1;
        while(n < sz) n <<= 1;
        dat.assign(2 * n - 1, ti);
        laz.resize(2 * n - 1, ei);
        for(int i = 0; i < sz; i++) dat[n - 1 + i] = v[i];
        for(int i = n - 2; i >= 0; i--) dat[i] = f(dat[2 * i + 1], dat[2 * i + 2]);
    }
    
    inline void eval(int len, int k){

        if(laz[k] == ei) return;
        if(k * 2 + 1 < n * 2 - 1){
            laz[k * 2 + 1] = h(laz[k * 2 + 1], laz[k]);
            laz[k * 2 + 2] = h(laz[k * 2 + 2], laz[k]);
        }
        dat[k] = g(dat[k], p(laz[k], len));
        laz[k] = ei;
    }

    // 区間[a, b) に x を g する
    T update(int a, int b, E x, int k, int l, int r){
        eval(r - l, k);
        if(r <= a || b <= l) return dat[k];
        if(a <= l && r <= b){
            laz[k] = h(laz[k], x);
            return g(dat[k], p(laz[k], r - l));
        }

        return dat[k] = f(update(a, b, x, k * 2 + 1, l, (l + r) / 2), update(a, b, x, k * 2 + 2, (l + r) / 2, r));
    }

    T update(int a, int b, E x){
        return update(a, b, x, 0, 0, n);
    }

    
    T query(int a, int b, int k, int l, int r){
        eval(r - l, k);
        if(r <= a || b <= l) return ti;
        if(a <= l && r <= b) return dat[k];
        T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
        T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return f(vl, vr);
    }

    T query(int a, int b){
        return query(a, b, 0, 0, n);
    }
      
};


signed main(){
    
    int n, q; cin >> n >> q;
    vector<int> v(n, 0);
    auto f = [](int a, int b){return a + b;};
    auto g = [](int a, int b){return a + b;};
    auto h = [](int a, int b){return a + b;};
    auto p = [](int a, int b){return a * b;};
    SegmentTree<int, int> sg(f, g, h, 0, 0, v, p);
    for(int i = 0; i < q; i++){
        int c, s, t, x;
        cin >> c;
        if(c){
            cin >> s >> t;
            cout << sg.query(s - 1, t) << endl;
        }else{
            cin >> s >> t >> x;
            sg.update(s - 1, t, x);
        }
    }

    return 0;
}




Measured memory_bytes: 7860