akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

const int size = 301;
int P[size];
int PC;
int dp[size];

int main() {
    for ( int i = 0; i <= 17; ++ i ) {
        P[PC++] = ( i + 1 ) * ( i + 1 );
    }
    
    for ( int i = 0; i < size; ++ i ) {
        dp[i] = 0;
    }
    dp[0] = 1;
    for ( int i = 0; i < PC; ++ i ) {
        for ( int j = 0; j < size; ++ j ) {
            int next = j + P[i];
            if ( next >= size ) continue;
            dp[next] += dp[j];
        }
    }
    
    int n;
    while ( cin >> n && n ) {
        cout << dp[n] << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
string x,y;
int n; 
int main()
{
	cin >>n>>x>>y;
	for (int i=0;i<n;i++) cout <<x[i]<<y[i];
	return 0;
}

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

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

using namespace std;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	cout << min(a, b) + min(c, d) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <sstream>
#include <algorithm>
#include <fstream>
#include <list>
#include <map>
#include <istream>
#include <bitset>
#include <sstream>
#include <unordered_map>
#include <stack>
#include <set>
#include <cmath>
#include <random>
#include <iostream>
#include <bitset>
#include <iomanip>
#include <queue>
#include <string>

#define int long long
#define endl "\n"
#define all(x) x.begin(),x.end()
#define rr return 0
#define xx first
#define yy second
#define pii pair<int,int>

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

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i++){
        cin >> a[i];
    }
    sort(all(a));
    double p = a[0];
    for(int i = 1;i < n;i++){
        p = (p + a[i]) / 2;
    }
    cout << fixed << setprecision(10) << p;
    rr;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using intpair=pair<int,int>;
using llpair=pair<ll,ll>;
using llvec=vector<ll>;
using llmat=vector<vector<ll>>;
#define PI 3.141592653589793
#define llmattp(name,a,b,num) name(a,vector<ll>(b,num))
#define INTINF 1<<30
#define LLINF 1LL<<60
#define ABS(x) ( (x)>0 ? (x) : -(x) )
#define gsort(vbeg,vend) sort(vbeg,vend,greater<>())

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==0||b==0) return 0;
	if(a<b) swap(a,b);
	ll tmp = a%b;
	while(tmp!=0) {
		a = b;
		b = tmp;
		tmp = a%b;
	}
	return b;
}

ll factorial(ll x) { //階乗
	ll f=1;
	for(ll i=2; i<x; i++) {
		f*=i;
	}
	return f;
}

ll nPr(ll n, ll r) {
	ll result=1;
	for(ll i=r+1; i<=n; i++) result*=i;
	return result;
}

ll nCr(ll n, ll r) {
	if (n == r) { return 1; }
	if (r > n) { return 0; }

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

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

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

	return (ll)result;
}

ll GreaterBinarySearch(ll *array, ll key, ll max, ll min) { //にぶたんgreater
	if(array[max]<array[min]) {
		return NULL;
	} else {
		ll mid = max + (min-max)/2;
		if(array[mid]<key) {
			return GreaterBinarySearch(array,key,max,mid-1);
		} if(array[mid]>key) {
			return GreaterBinarySearch(array,key,mid+1,min);
		} else {
			return mid;
		}
	}
}

int DigitNum(ll n) { //桁数
	int digit=0;
	ll wari=1LL;
	while(n/wari) {
		digit++;
		wari*=10;
	}
	return digit;
}

bool IsPrime(ll num) { //素数判定
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (ll i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

vector<ll> Divisor(ll x) { // 約数列挙
	vector<ll> result;
	ll i=1LL;
	for( ; i*i<x; i++) {
		if(x%i) continue;
		result.push_back(i);
		result.push_back(x/i);
	}
	if(i*i==x&&x%i==0)
		result.push_back(i);
	
	sort(result.begin(),result.end());
	return result;
}

vector<llpair> PrimeFact(ll x) { // 素因数分解 {素因数,指数}
	vector<llpair> result;
	ll ex=0LL;
	if(x%2==0) {
		while(x%2==0) {
			x/=2;
			ex++;
		}
		result.push_back({2,ex});
	}

	for(ll i=3LL; i*i<=x; i+=2) {
		if(x%i) continue;

		ex=0LL;
		while(x%i==0) {
			x/=i;
			ex++;
		}
		result.push_back({i,ex});
	}

	if(x!=1) result.push_back({x,1});

	return result;
}

bool Palind(string s) { //回文判定
	return s == string(s.rbegin(), s.rend());
}

int main() {
	int N; cin>>N;
	int C[N-1],S[N-1],F[N-1]; for(int i=0; i<N-1; i++) cin>>C[i]>>S[i]>>F[i];
	for(int i=0; i<=N-1; i++) {
		int tm=0;
		for(int j=i; j<N-1; j++) {
			if(S[j]>tm) tm=S[j];
			if(tm%F[j]) tm=tm/F[j]*F[j]+F[j];
			tm+=C[j];
		}
		cout<<tm<<endl;
	}
}


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

int main() {
    char a, b;
    cin >> a >> b;
    if (a == 'H' && b == 'H') {
        cout << "H";
    } else if (a == 'H' && b == 'D') {
        cout << "D";
    } else if (a == 'D' && b == 'H') {
        cout << "D";
    } else if (a == 'D' && b == 'D') {
        cout << "H";
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a,q=0;
  int b[100],c[100];
  cin>>a;
  for(int i=0;i<a;i++){
    cin>>b[i];
    c[i]=b[i];
  }
  sort(c,c+a);
    for(int i=0;i<a;i++){
      if(b[i]!=c[i]){
	q++;
      }
    }
    if(q<=2){
      cout<<"YES\n";
    }
    else{
      cout<<"NO\n";
    }
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.util.TreeSet;

public class Main {

    public static void main(String[] args) {
	FastScanner scanner = new FastScanner();
	int N = scanner.nextInt();
	int[] digit = new int[N];
	for (int i = 0; i < digit.length; i++) {
	    digit[i] = scanner.nextInt();
	}
	String string = "";
	for (int i = 0; i < digit.length; i++) {
	    string = string + String.valueOf(digit[i]);
	}

	final int limd = 4;
	TreeSet<Integer> set = new TreeSet<Integer>();
	for (int i = 0; i < digit.length; i++) {
	    for (int j = 1; j <= limd && i + j <= N; j++) {
		String tString = string.substring(i, i + j);
		set.add(Integer.parseInt(tString));
	    }
	}

	Integer[] array = set.toArray(new Integer[set.size()]);
	for (int i = 0, pos = 0;;) {
	    if (pos < array.length && i == array[pos]) {
		pos++;
		i++;
	    } else {
		System.out.println(i);
		return;
	    }
	}

    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
	if (ptr < buflen) {
	    return true;
	} else {
	    ptr = 0;
	    try {
		buflen = in.read(buffer);
	    } catch (IOException e) {
		e.printStackTrace();
	    }
	    if (buflen <= 0) {
		return false;
	    }
	}
	return true;
    }

    private int readByte() {
	if (hasNextByte())
	    return buffer[ptr++];
	else
	    return -1;
    }

    private static boolean isPrintableChar(int c) {
	return 33 <= c && c <= 126;
    }

    private void skipUnprintable() {
	while (hasNextByte() && !isPrintableChar(buffer[ptr]))
	    ptr++;
    }

    public int nextInt() {
	return (int) nextLong();
    }

    public boolean hasNext() {
	skipUnprintable();
	return hasNextByte();
    }

    public String next() {
	if (!hasNext())
	    throw new NoSuchElementException();
	StringBuilder sb = new StringBuilder();
	int b = readByte();
	while (isPrintableChar(b)) {
	    sb.appendCodePoint(b);
	    b = readByte();
	}
	return sb.toString();
    }

    public long nextLong() {
	if (!hasNext())
	    throw new NoSuchElementException();
	long n = 0;
	boolean minus = false;
	int b = readByte();
	if (b == '-') {
	    minus = true;
	    b = readByte();
	}
	if (b < '0' || '9' < b) {
	    throw new NumberFormatException();
	}
	while (true) {
	    if ('0' <= b && b <= '9') {
		n *= 10;
		n += b - '0';
	    } else if (b == -1 || !isPrintableChar(b)) {
		return minus ? -n : n;
	    } else {
		throw new NumberFormatException();
	    }
	    b = readByte();
	}
    }
}

Measured memory_bytes: 30872
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int buka[N]={0};
    int A;
    for(int i=1; i<N; i++){
        cin >> A;
        buka[A-1]++;
    }
    for(int i=0; i<N; i++){
        cout << buka[i] << endl;
    }
    return 0;
}


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

int main()
{
	#ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	#endif
    	
    int n;
    cin>>n;
    vector<int >v(n);
    for(int i=0;i<n;i++)
    	cin>>v[i];

   	ll stool=0;
   	int maximum=v[0];
   	for(int i=1;i<n;i++)
   	{
   		if(maximum>v[i])
   			stool+=maximum-v[i];
   		maximum=max(maximum,v[i]);
   	}
   	cout<<stool<<endl;
	return 0;
}

Measured memory_bytes: 4056
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")

#include <bits/stdc++.h>

#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;

#define popCnt(x) (__builtin_popcountll(x))
#define all(v) begin(v), end(v)

typedef long long Long;
typedef vector<int> vi;

const int N = 1e5 + 5;

struct DSU {
  int parent[N];
  void init() {
    for (int i = 0; i < N; ++i) {
      parent[i] = i;
    }
  }
  int getRoot(int x) {
    if (parent[x] == x) return x;
    return parent[x] = getRoot(parent[x]);
  }
  void join(int x, int y) {
    x = getRoot(x);
    y = getRoot(y);
    parent[x] = y;
  }
} dsu;

struct Edge {
  int from, to;
  bool out_to = false;
};

vector<Edge> edges;
vector<int> mst_adj[N];
bool deg[N];

void kruskal() {
  dsu.init();
  for (int i = 0; i < edges.size(); ++i) {
    auto& edge = edges[i];
    if (dsu.getRoot(edge.from) == dsu.getRoot(edge.to)) {
      edge.out_to = false;
      deg[edge.from] ^= 1;
    } else {
      dsu.join(edge.from, edge.to);
      mst_adj[edge.from].emplace_back(i);
      mst_adj[edge.to].emplace_back(i);
    }
  }
}

void dfs(int node, int parent, int p_edge) {
  for (int v : mst_adj[node]) {
    auto& edge = edges[v];
    int to = edge.from ^ edge.to ^ node;
    if (to == parent) continue;
    dfs(to, node, v);
  }
  if (deg[node]) {
    if (p_edge == -1) {
      cout << -1 << endl;
      exit(0);
    }
    auto& edge = edges[p_edge];
    if (node == edge.to) {
      edge.out_to = true;
    }
    deg[node] ^= 1;
  } else {
    if (p_edge == -1) return;
    auto& edge = edges[p_edge];
    if (node != edge.to) {
      edge.out_to = true;
    }
    deg[parent] ^= 1;
  }
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  int n, m;
  cin >> n >> m;

  edges.resize(m);
  for (auto& edge : edges) {
    cin >> edge.from >> edge.to;
  }

  kruskal();
  dfs(1, -1, -1);

  for (auto& edge : edges) {
    if (edge.out_to) {
      cout << edge.to << " " << edge.from << endl;
    } else {
      cout << edge.from << " " << edge.to << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 15232
#include<bits/stdc++.h>
#define LL long long
#define RG register
#define R RG int
#define YL 1000000007
using namespace std;
const int N=1<<16;
int sum[N],f[N],g[N],c[N],e[19];LL pw[199];
int main(){
	R n,m,x,y,ans=0;
	cin>>n>>m;
	pw[0]=1;
	for(R i=1;i<=m;++i){
		pw[i]=2*pw[i-1]%YL;
		cin>>x>>y;
		if(x>y)swap(x,y);
		e[y]|=1<<(x-1);
	}
	const int S=1<<n;
	for(R i=1;i<S;++i)
		c[i]=c[i>>1]+(1&i);
	for(R i=1;i<=n;++i)
		for(R j=(1<<(i-1))-1;~j;--j)
			sum[1<<(i-1)|j]=sum[j]+c[e[i]&j];
	for(R i=1;i<S;++i){
		if(i&1){
			f[i]=pw[sum[i]];
			for(R j=(i-1)&i;j;j=(j-1)&i)
				f[i]=(f[i]-(LL)f[j]*pw[sum[i^j]]%YL+YL)%YL;
		}
		if(i&2){
			g[i]=pw[sum[i]];
			for(R j=(i-1)&i;j;j=(j-1)&i)
				g[i]=(g[i]-(LL)g[j]*pw[sum[i^j]]%YL+YL)%YL;
		}
	}
	for(R i=3;i<S;i+=4)
		for(R j=(i-1)&i;j;j=(j-1)&i)
			if(1&(i^j)&&2&j&&sum[i^j]+sum[j]==sum[i])
				ans=(ans+(LL)f[i^j]*g[j]%YL*pw[sum[(S-1)^i]])%YL;
	printf("%lld\n",(pw[m]-ans+YL)%YL);
	return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  bool ans=true;
  for(int i=0;i<s.length();i++)
  {
      if(i%2==0)
      {
          if(s[i]!='R' && s[i]!='U' && s[i]!='D')
          {
              ans=false;
              break;
          }
      }
      else
      {
          if(s[i]!='L' && s[i]!='U' && s[i]!='D')
          {
              ans=false;
              break;
          }

      }
  }
  if(ans) cout<<"Yes";
  else cout<<"No";
  return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

int main() {

    ll A, B, C;
    cin >> A >> B >> C;

    if(A <= C && B >= C){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int n;
	int date;
	int Y, M, D;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		date = 0;
		scanf("%d%d%d", &Y, &M, &D);
		date += (1000 - (Y + 1)) * (5 * 20 + 5 * 19);
		date += ((1000 - Y + 1) / 3) * 5;

		if (Y % 3) {
			date += (5 * 20 + 5 * 19) - ((M - 1) * 20 + D);
			date += (M + 1) / 2;
		} else {
			date += (10 * 20) - ((M - 1) * 20 + D);
			date += 1;
		}
		printf("%d\n", date);
	}
	return 0;
}



Measured memory_bytes: 2032
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	n := scanInt()
	a := make([]int, n+1)
	for i := 1; i <= n; i++ {
		x := scanInt()
		a[i] = a[i-1] + x
	}

	ans := math.MaxInt64
	for i := 1; i < n; i++ {
		ans = min(ans, abs(a[len(a)-1]-a[i]*2))
	}
	fmt.Println(ans)
}


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

namespace AOJ0100
{
    class Program
    {
        public Dictionary<int, ulong> IDs;
        public List<int> target;

        public void Proc()
        {
            while (true)
            {
                string input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) continue;
                int N = int.Parse(input);
                if (N == 0) break;

                IDs = new Dictionary<int, ulong>();

                for (int i = 0; i < N; i++)
                {
                    input = Console.ReadLine();
                    string[] data_s = input.Split(' ');
                    int ID = int.Parse(data_s[0]);
                    ulong sales = (ulong) (int.Parse(data_s[1]) * int.Parse(data_s[2]));

                    if (IDs.ContainsKey(ID))
                    {
                        IDs[ID] += sales;
                    } else
                    {
                        IDs[ID] = sales;
                    }
                }

                target = new List<int>();

                foreach (KeyValuePair<int, ulong> pair in IDs)
                {
                    if (pair.Value >= 1000000)
                    {
                        target.Add(pair.Key);
                    }
                }

                if (target.Count == 0)
                {
                    Console.WriteLine("NA");
                    continue;
                }

                for (int i = 0; i < target.Count; i++)
                {
                    Console.WriteLine(target[i]);
                }
            }
        }

        static void Main(string[] args)
        {
            Program prg = new Program();
            prg.Proc();
        }
    }
}

Measured memory_bytes: 9884
#include <iostream>
#include <stdlib.h>

int main() {
    int a,b,c,d;
    std::cin>>a>>b>>c>>d;
    int h=std::abs(c-a);
    int i=std::abs(a-b);
    int j=std::abs(b-c);
    if(h<=d){
        std::cout<<"Yes";
    }else
    if(i<=d && j<=d){
        std::cout<<"Yes";
    }else{
        std::cout<<"No";
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 1000000007 
#define eps 1e-9
#define PI 3.14159265358979323846
#define F first
#define S second
#define ll long long
#define pb push_back
#define mp make_pair
#define Fr(i,a,b) for(int i=a;i<b;i++)
#define RF(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pii>
using namespace std;
ll dp[3005][3005];
ll f(ll i,ll j,ll a[],ll n)
{
	if(i>j)
	return 0;
	
	if(dp[i][j]!=-1)
	return dp[i][j];
	
	dp[i][j]=max(a[i]+min(f(i+2,j,a,n),f(i+1,j-1,a,n)),a[j]+min(f(i,j-2,a,n),f(i+1,j-1,a,n)));
	return dp[i][j];
}
int main()
{
	SPEED;
   ll n,k,i,s,j;
   cin>>n;
   ll a[n];
   s=0;
   Fr(i,0,n)
   {
   	cin>>a[i];
   	s+=a[i];
   }
   memset(dp,-1,sizeof(dp));
   ll p=f(0,n-1,a,n);
   cout<<2*p-s<<endl;
return 0;   
}

   

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;

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

    std::cin >> N;

    if(N < 1000){
        std::cout << "ABC" << std::endl;
    }else{
        std::cout << "ABD" << std::endl;
    }
}


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

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

    long long a[N];

    for (int i = 0; i < N; ++i) { 
        cin >> a[i];
    }

    long long dp[N][N]={};

    for (int i = 0; i < N; ++i) { 
        dp[i][i]=a[i];
    }

    for (int j = 1; j < N; ++j) { 
        for (int i = 0; i < N-j; ++i) { 
            long long m;
            m=a[i]-dp[i+1][i+j];
            if (m<a[i+j]-dp[i][i+j-1]){m=a[i+j]-dp[i][i+j-1];}
            dp[i][i+j]=m;
        }
    }


    cout << dp[0][N-1] << endl;
    return 0;

}

Measured memory_bytes: 70528
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int count = 0;
  for (int i = 0; i < 3; i++) {
    if (S.at(i) == S.at(i + 1)) {
      count++;
    }
  }
  if (count == 0) {
    cout << "Good" << endl;
  }
  else {
    cout << "Bad" << endl;
  }
}

Measured memory_bytes: 256
a, b, c=map(int, input().split())
if a>b:
    x=a
    a=b
    b=x
if b>c:
    x=b 
    b=c 
    c=x 
if a>b: 
    x=a 
    a=b
    b=x
print(a, b, c)


Measured memory_bytes: 5596
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>

using namespace std;

const int MAX = 370;
struct data{
  int s,g,r;
  bool operator < (const data& d) const { return s < d.s;}
};
int dp[2][MAX][MAX];
int N;
vector<data> V;

void init(){
  V.clear();
  memset(dp,0,sizeof(dp));
}

void input(){
  V.resize(N);

  for(int i = 0; i < N; i++)
    cin >> V[i].s >> V[i].g >> V[i].r;
}

void solve(){

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

  for(int i = 0; i < N; i++){
    int now = i%2;
    int nex = 1-now;

    for(int j = 0; j < MAX; j++)
      for(int k = 0; k < MAX; k++){
	dp[nex][j][k] = max(dp[nex][j][k],dp[now][j][k]);
	if(j < V[i].s) dp[nex][V[i].g][k] = max(dp[nex][V[i].g][k],dp[now][j][k]+V[i].r);
	if(k < V[i].s) dp[nex][j][V[i].g] = max(dp[nex][j][V[i].g],dp[now][j][k]+V[i].r);
      }
  }

  int ans = 0;
  
  for(int i = 0; i < MAX; i++)
    for(int j = 0; j < MAX; j++) ans = max(ans,dp[N%2][i][j]);

  cout << ans << endl;
}

int main(){
  
  while(cin >> N && N){
    init();
    input();
    solve();
  }
  return 0;
}

Measured memory_bytes: 2296
M, D = map(int, input().split())
ans = 0
for m in range(4, M+1):
    for d1 in range(2, 10):
        for d2 in range(2, 10):
            if d1*10 + d2 <= D and d1 * d2 == m:
                ans += 1
print(ans)

Measured memory_bytes: 2940
class Array
  def how_many_sort
    uniq_arr = self.uniq
    result = []
    uniq_arr.each do |uni|
      result << [self.count(uni), uni]
    end
    result.sort_by {|r| [-r[0], r[1]] }.map{|r| r[1]}
  end
end

while (n = gets.to_i) != 0 do
  words = []
  n.times do
    words += gets.chomp.split
  end

  first_char = gets.chomp
  words = words.select{|w| w[0] == first_char }

  result = words.how_many_sort
  puts result.empty? ? 'NA' : result[0..4].join(' ')
end

Measured memory_bytes: 6288
#include<bits/stdc++.h>
using namespace std;
#define MAX 100005

int n,a,b,c;
vector<int> G[MAX];//*
int size[MAX];// *
int par[MAX];// *
int cur[MAX];// *
int dep[MAX];// *
int depth[MAX];
int het[MAX];
int parent[MAX];

void idfs(int pos,int prev){
  int m=-1;
  parent[pos]=prev;
  if(G[pos].size()==1&&prev!=-1)return;  
  for(int i=0;i<(int)G[pos].size();i++){
    int to=G[pos][i];
    if(to==prev)continue;
    depth[to]=depth[pos]+1;
    idfs(to,pos);
    size[pos]+=size[to];
    het[pos]=max(het[pos],het[to]+1);
    if(m==-1||size[m]<size[to]){
      m=to;
    }
  }
  cur[pos]=m;
  par[m]=pos;
  het[pos]=max(het[pos],het[m]);
}

int calc(int x){
  if(par[x]==x)return x;
  return par[x]=calc(par[x]);
}

void init(){
  for(int i=0;i<MAX;i++){
    G[i].clear();
    size[i]=1;
    par[i]=i;
    cur[i]=-1;
    dep[i]=0;
    depth[i]=0;
    het[i]=0;
    parent[i]=0;
  }
  for(int i=0;i<n;i++){    
    scanf("%d",&a);
    while(a--){
      scanf("%d",&b);
      G[i].push_back(b);
      G[b].push_back(i);
    }
  }
  for(int i=0;i<n;i++)sort(G[i].begin(),G[i].end());
  depth[0]=0;
  idfs(0,-1);
  for(int i=0;i<n;i++){
    int root=calc(i);
    het[i]=het[root];
    int p=par[i];
    while(p>0){
      p= par[ parent[p] ];      
      dep[i]++;
    }

    /*    
    cout<< (char)('A'+i) <<"   -> ";
    cout<< (char)('A'+par[i]) <<endl;    
    cout<<"size = "<< size[i]<<" , ";    
    cout<<"depth = "<< depth[i]<<" , ";
    cout<<"dep = "<< dep[i]<<" , ";
    cout<<"parent = "<< (char)('A'+parent[i]) <<" , ";
    cout<<"cur = "<< (char)('A'+cur[i]) <<" , ";
    cout<<"het = "<< het[i] << endl;
    
    cout<<endl;
    */
  }

  
}

int main(){
  while( scanf("%d",&n)!=EOF){
    init();
    int q;
    scanf("%d",&q);
    while(q--){
      scanf("%d %d",&a,&b);

      while(par[a]!=par[b]){
        if(dep[a]<dep[b])swap(a,b);
        a=parent[par[a]];
      }
      printf("%d\n",(depth[a]<depth[b]?a:b));      

    }
    break;
  }

  
  return 0;
}

Measured memory_bytes: 17216
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
#include<map>
using namespace std;
typedef long long LL; 
typedef pair<LL,LL> P;//Pでpair<-,->を表す。
typedef map<LL,LL>::iterator Itr;
LL MOD=1000000007;

struct S{
    LL x;LL y;LL z;
    bool operator<(const S&a)const{
        return x<a.x||(x==a.x&&y<a.y)||(x==a.x&&y==a.y&&z<a.z);
    }
    bool operator==(const S&a)const{
        return (x==a.x)&&(y==a.y)&&(z==a.z);
    }
};

int main()
{ 
    LL n,Q;
    cin>>n>>Q;
    vector<S> v;
    for(int i=0;i<n;i++){
        LL a,b,c;
        cin>>a>>b>>c;
        S s;
        s.x=c;s.y=a;s.z=b;
        v.push_back(s);
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());

    /*for(int i=0;i<v.size();i++){
        S s=v[i];
        cout<<s.x<<' '<<s.y<<' '<<s.z<<endl;
    }*/

    map<LL,LL> m;
    for(int i=0;i<Q;i++){
        LL a;
        cin>>a;
        m.insert(P(a,i));
    }
    LL ans[Q];
    for(int i=0;i<n;i++){
        S s=v.back();
        v.pop_back();
        LL begin=s.y-s.x;
        LL end=s.z-s.x;
        vector <LL>d;
        for(Itr itr=m.lower_bound(begin);itr!=m.lower_bound(end);advance(itr,1)){
            ans[(*itr).second]=s.x;
            d.push_back((*itr).first);
        }
        while(!d.empty()){m.erase(d.back());d.pop_back();}
    }
    for(Itr itr=m.begin();itr!=m.end();advance(itr,1)){
        ans[(*itr).second]=-1;
    }
    for(int i=0;i<Q;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 22764
N, M = map(int,input().split())
B = [list(map(int,input().split())) for k in range(M)]
H = [1]*N
E = [0]*N
E[0] = 1
for e in B:
    x, y = e[0]-1, e[1]-1
    if E[x] == 1:
        if H[x] == 1:
            E[x] = 0
            E[y] = 1
        else:
            E[y] = 1
    H[x] -= 1
    H[y] += 1
print(E.count(1))


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

int main(){
	char S[100001];
	int ichi=0,zero=0,ans=0;
	cin>>S;
	for(int i=0;i<strlen(S);i++)
	{
		if(S[i]=='1')ichi++;
		else zero++;
	}
	ans=min(ichi,zero)*2;
	cout<<ans;
	return 0;
	}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#pragma region include

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;

void solve() {
	int N, M;
	cin >> N >> M;
	vector<int> A(M), B(M);//左桁,数字
	vector<int> num(N, -1);
	for(int i=0;i<M;++i){
		cin >> A[i] >> B[i];
		if (A[i] > N) {//桁数超過
			cout << -1 << endl;
			return;
		}
		if (A[i] == 1 && B[i] == 0 && N > 1) {//先頭の0はN==1のみ
			cout << -1 << endl;
			return;
		}
		if (num[A[i]-1] == -1) {//未指示
			num[A[i]-1] = B[i];
		}
		else if(num[A[i]-1] != B[i]){//指示の相違
			cout << -1 << endl;
			return;
		}
	}
	//////////////////////////////
	if (N == 1) {
		if (num[0] == -1) {
			num[0] = 0;
		}
	}
	else {
		for (int i = 0; i < N; ++i) {
			if (num[i] == -1) {
				if (i == 0) {
					num[i] = 1;
				}
				else {
					num[i] = 0;
				}
			}
		}
	}
	for (int i = 0; i < N; ++i) {
		cout << num[i];
	}
	cout << endl;
}

#pragma region main
signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


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

using namespace std;

#define S scanf
#define P printf
#define G getline
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define MP make_pair
#define LL long long int
#define ULL unsigned long long int
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>
#define PLI pair<long long int,int>
#define PLL pair<long long int,long long int>
#define MII map<int,int>
#define MSI map<string,int>
#define MIS map<int,string>
#define MLI map<long long int,int>
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)





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






int main()
{
    FAST();

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    int n,k,ans=0;
    cin >> n >> k;
    while(n > 0)++ans,n/=k;
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define N 100000
typedef struct Graph
{
  int group;
  int numOfAdj;
  int *adj;
} graph;
int n;//the number of users
graph *user;//array of users
void initUser(void);
void setConnection(int,int);
void setWholeGroup(void);
void setGroup(int,int);
int isGrouped(int,int);
void printGroup(void);//debugging
int main(void)
{
  int i;//counter
  int user1,user2;
  int num;//the number of relaions / questions
  scanf("%d",&n);
  user=(graph*)malloc(sizeof(graph)*n);
  initUser();
  scanf("%d",&num);
  for(i=0;i<num;i++)
    {
      scanf("%d%d",&user1,&user2);
      setConnection(user1,user2);
      setConnection(user2,user1);
    }
  setWholeGroup();
  //printGroup();
  scanf("%d",&num);
  for(i=0;i<num;i++)
    {
      scanf("%d%d",&user1,&user2);
      if(isGrouped(user1,user2)==1) printf("yes\n");
      else printf("no\n");
    }
  return 0;
}
void initUser(void)
{
  int i;//counter
  for(i=0;i<n;i++)
    {
      user[i].group=0;
      user[i].numOfAdj=0;
    }
}
void setConnection(int user1,int user2)
{
  int i;//counter
  int *temp;
  temp=user[user1].adj;
  user[user1].adj=(int*)malloc(sizeof(int)*(user[user1].numOfAdj+1));
  for(i=0;i<user[user1].numOfAdj;i++) user[user1].adj[i]=temp[i];
  user[user1].numOfAdj++;
  user[user1].adj[i]=user2;
  free(temp);
}
void setWholeGroup(void)
{
  int i;//counter
  int groupNum=0;
  for(i=0;i<n;i++)
    {
      if(user[i].group==0)
        {
          groupNum++;
          setGroup(i,groupNum);
        }
    }
}
void setGroup(int key,int num)
{
  int i;//counter
  user[key].group=num;
  for(i=0;i<user[key].numOfAdj;i++)
    {
      if(user[user[key].adj[i]].group!=user[key].group) setGroup(user[key].adj[i],num);
    }
}
int isGrouped(int user1,int user2)
{
  if(user[user1].group==user[user2].group) return 1;
  else return 0;
}
void printGroup(void)
{
  int i;//counter
  for(i=0;i<n;i++)
    {
      printf("%d: Group %d\n",i,user[i].group);
    }
}


Measured memory_bytes: 9528
#include<bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
using namespace std;
namespace IO
{
    const int sz=1<<15;
    char inbuf[sz],outbuf[sz];
    char *pinbuf=inbuf+sz;
    char *poutbuf=outbuf;
    inline char _getchar()
    {
        if (pinbuf==inbuf+sz)fread(inbuf,1,sz,stdin),pinbuf=inbuf;
        return *(pinbuf++);
    }
    inline void _putchar(char x)
    {
        if (poutbuf==outbuf+sz)fwrite(outbuf,1,sz,stdout),poutbuf=outbuf;
        *(poutbuf++)=x;
    }
    inline void flush()
    {
        if (poutbuf!=outbuf)fwrite(outbuf,1,poutbuf-outbuf,stdout),poutbuf=outbuf;
    }
}
inline int read(){
	int v=0,f=1;
	char c=getchar();
	while (c<'0' || c>'9'){
		if (c=='-') f=-1;
		c=getchar();
	}
	while (c>='0' && c<='9'){
		v=v*10+c-'0';
		c=getchar();
	}
	return v*f;
}
const int Mod=1e9+7;
const int Maxn=262144;
int qp(int x,int p){
	int ret=1;
	while (p){
		if (p&1) ret=1ll*ret*x%Mod;
		p>>=1;
		x=1ll*x*x%Mod;
	}
	return ret;
}
int inv(int x){
	return qp(x,Mod-2);
}
const int mod=134217727;
int H,p[Maxn],n,hd[134217727],P[Maxn],iP[Maxn];
int nxt[42467388],cnt[42467388],ke;
LL val[42467388];

void Ins(LL X,int t){
	int pos=X&mod;
	int p=hd[pos];
	while (p!=-1 && val[p]!=X){
		p=nxt[p];
	}
	if (p!=-1){
		cnt[p]+=t;
		if (cnt[p]>=Mod) cnt[p]-=Mod;
	}
	else{
		cnt[ke]=t;val[ke]=X;nxt[ke]=hd[pos];hd[pos]=ke++;
	}
}
int Q(LL X){
	int pos=X&mod;
	for (int i=hd[pos];~i;i=nxt[i]){
		if (val[i]==X) return cnt[i];
	}
}
void Add(int&x,int y){
	x+=y;
	if (x>=Mod) x-=Mod;
}
int A[18][18];
signed main(){
	/*
	for (int i=70000000;i>=0;i--){
		int flag=1;
		for (int j=2;j*j<=i;j++){
			if (i%j==0) flag=0;
		}
		if (flag){
			cerr<<i<<endl;
			return 0; 
		}
	}*/
//	freopen("input.txt","r",stdin);
	for (int i=0;i<134217727;i++) hd[i]=-1;
	H=read();
	n=1<<H;
	P[1]=1;
	for (int i=2;i<n;i++){
		P[i]=1ll*P[i>>1]*i%Mod;
	}
	for (int i=1;i<n;i++){
		iP[i]=inv(P[i]);
		if (i>1){
			iP[i]=1ll*iP[i]*inv(P[i>>1])%Mod;
		} 
	}
	for (int i=n>>1;i<n;i++){
		p[i]=read();p[i]--;p[i]+=n>>1;
	//	cerr<<i<<' '<<p[i]<<endl;
		int d=1ll*P[i]*P[p[i]]%Mod;
		for (int j=i;j;j>>=1){
			for (int k=p[i];k;k>>=1) Ins((LL)j*Mod+k,d);
		}
	//	cerr<<i<<endl;
	}
//	cerr<<123<<endl;
	int ans=0;
	for (int i=n>>1;i<n;i++){
		
		for (int j=0;j<H;j++){
			for (int k=0;k<H;k++){
				LL v=((LL)(i>>j)*Mod)+(p[i]>>k);
				A[j][k]=Q(v);
			}
		}
		int bas=1ll*P[i]*P[p[i]]%Mod;
		for (int j=1;j<H;j++){
			for (int k=1;k<H;k++){
				int X=A[j][k]+A[j-1][k-1]-A[j-1][k]-A[j][k-1];
				if (X){
					Add(ans,1ll*bas*X%Mod*iP[i>>j]%Mod*iP[p[i]>>k]%Mod);
					if (ans<0) ans+=Mod;
				}
			}
		}
	}
	ans=1ll*ans*inv(2)%Mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 889260
#include<bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
#define chmax(x, a)  do { x = max(x, a); } while(0)
#define chmin(x, a)  do { x = min(x, a); } while(0)

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll,ll> PLL;

void solve() {
  ll n, ans = 0;
  cin >> n;
  vector<ll> a(n);
  rep(i, n)
    cin >> a[i];
  for (ll i = 0; i < n; i++)
  for (ll j = i+1; j < n; j++)
  for (ll k = j+1; k < n; k++) {
    ll x = a[i], y = a[j], z = a[k];
    if (x == y || x == z || y == z) continue;
    if (x >= y + z) continue;
    if (y >= x + z) continue;
    if (z >= x + y) continue;
    ans++;
  }
  cout << ans << endl;
}

int main() {
  //ll T;
  //cin >> T;
  //rep(_,T)
    solve();
  return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include<iostream>
#include<cmath>
#include<math.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
const double PI=M_PI;
//gcd
ll gcd(ll a,ll b){
    if(min(a,b)==0)return max(a,b);
    if(max(a,b)%min(a,b)==0)return min(a,b);
    return gcd(min(a,b),max(a,b)%min(a,b));
}
ll rui(ll a,ll b){
    ll res=1,x=a;
    while(b){
        if(b&1)res=res*x%inf;
        x=x*x%inf;
        b/=2;
    }
    return res;
}
signed main(){
    ll n;cin>>n;
    map<pll,ll>ma;
    ll cnt=0;
    rep(i,n){
        ll a,b;cin>>a>>b;
        if(a<0){
            a=-a;
            b=-b;
        }
        if(a==0){
            if(b!=0)b=1;
        }else{
            if(b!=0){
                ll c=gcd(a,abs(b));
                a/=c;
                b/=c;
            }
            else{
                a=1;
            }
        }
        if(a==b&&a==0){
            cnt++;
            continue;
        }
        ma[mp(a,b)]++;
    }
    ll ans=1;
    for(auto e:ma){
        ll x=e.second;
        ll a=e.first.first;
        ll b=e.first.second;
        ll c,d;
        if(b<0){
            c=-b;
            d=a;
        }else{
            c=b;
            d=-a;
        }
        ll y=ma[mp(c,d)];
        //cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<x<<' '<<y<<endl;
        ans=ans*(rui(2,y)+rui(2,x)-1)%inf;
        ma[mp(a,b)]=0;
        ma[mp(c,d)]=0;
    }
    ans+=cnt-1;
    ans%=inf;
    if(ans<0)ans+=inf;
    cout<<ans<<endl;
}

Measured memory_bytes: 28560
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::collections::VecDeque;

fn main() {
    input!(n: usize, x: [usize1; n]);
    let mut ans = vec![0; n * n];
    for i in 0..n {
        ans[x[i]] = i + 1;
    }

    let mut q = VecDeque::new();
    for i in 0..(n * n) {
        if ans[i] == 0 {
            q.push_back(i);
        } else {
            if q.len() < ans[i] - 1 {
                println!("No");
                return;
            }
            for _ in 0..(ans[i] - 1) {
                let j = q.pop_front().unwrap();
                ans[j] = ans[i];
            }
        }
    }

    q.clear();
    for i in (0..(n * n)).rev() {
        if ans[i] == 0 {
            q.push_back(i);
        } else if x[ans[i] - 1] == i {
            let rest = n - ans[i];
            if q.len() < rest {
                println!("No");
                return;
            }
            for _ in 0..rest {
                let j = q.pop_front().unwrap();
                ans[j] = ans[i];
            }
        }
    }

    println!("Yes");
    for i in 0..(n * n) {
        if i > 0 {
            print!(" ");
        }
        print!("{}", ans[i]);
    }
    println!();
}


Measured memory_bytes: 9340
x,k,d = gets.split.map(&:to_i)
y = x.abs-d*k
a = [x%d,d-x%d].min
b = [x%d,d-x%d].max
if y >= 0
  puts y
else
  if ( (x-a)%d == 0 && (k-((x-a)/d).abs).even? ) || ( (x+a)%d == 0 && (k-((x+a)/d).abs).even? )
    puts a
  else
    puts b
  end
end

Measured memory_bytes: 14332
def main():
    X,K,D = map(int,input().split())
    X = abs(X)
    
    if X-D*K >= 0:
        print(X-D*K)
    else:
        k0 = X//D
        x0 = X%D
        x1 = abs(x0-D)
        if (K - k0)%2==0:
            print(x0)
        else:
            print(x1)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 9176
#include<iostream>
using namespace std;
int main(){
    int n,i,a,t;
    cin >>n;
    int gyaku[n];
    for( i=0;i<n;i++){
        cin>>a;
        gyaku[n-1-i]=a;
        
    }
    for(t=0;t<n;t++){
        if(t==0){
            cout<<gyaku[t];
        }
        else {
            cout<<" "<<gyaku[t];
        }
    }
    cout<<endl;
    return 0;
}


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

using namespace std;

int main() {

    int h,w;
    cin >> h >> w;

    vector<string> s(h);

    for(int i = 0;i < h;i++){
        cin >> s[i];
    } 

    for(int i = 0;i < w +  2;i++){
        cout << "#";
    }
    cout << endl;

    for(int i = 0;i < h;i++){
        cout << '#' << s[i] << '#' << endl;
    }

    for(int i = 0;i < w +  2;i++){
        cout << "#";
    }
    cout << endl;

    return 0;

}

Measured memory_bytes: 256
k= int(input())

mozi_list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(mozi_list[k - 1])

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>

typedef struct {
	int t, h;
} edge;

typedef struct List {
	struct List *next;
	edge *e;
} list;

typedef struct {
	edge *e;
	list **inc;
} graph;

void input_graph(graph *G, int n, int m)
{
	int i;
	list *data = (list*)malloc(sizeof(list) * m * 2);
	G->e = (edge*)malloc(sizeof(edge) * m);
	G->inc = (list**)malloc(sizeof(list*) * (n + 1));
	for (i = 0; i < m; i++) {
		scanf("%d %d", &(G->e[i].t), &(G->e[i].h));
		data[i*2].e = &(G->e[i]);
		data[i*2+1].e = &(G->e[i]);
		data[i*2].next = G->inc[G->e[i].t];
		data[i*2+1].next = G->inc[G->e[i].h];
		G->inc[G->e[i].t] = &(data[i*2]);
		G->inc[G->e[i].h] = &(data[i*2+1]);
	}
}

int main()
{
	int i, N, M;
	graph G;
	scanf("%d %d", &N, &M);
	if (M % 2 == 1) {
		printf("-1\n");
		fflush(stdout);
		return 0;
	}
	input_graph(&G, N, M);
	
	int k = 0, v, tmp, parity[100001] = {}, flag[100001] = {}, q[100001], head, tail;
	edge *prev[100001];
	list *p;
	for (i = 1; i <= N; i++) {
		for (p = G.inc[i]; p != NULL; p = p->next) if (p->e->t == i) parity[i] ^= 1;
	}
	for (i = 1; i <= N; i++) {
		if (parity[i] == 0) continue;
		q[0] = i;
		parity[i] = 0;
		flag[i] = ++k;
		for (head = 0, tail = 1; head < tail; head++) {
			for (p = G.inc[q[head]]; p != NULL; p = p->next) {
				v = (p->e->t == q[head])? p->e->h: p->e->t;
				if (flag[v] < k) {
					flag[v] = k;
					prev[v] = p->e;
					q[tail++] = v;
				}
				if (parity[v] == 1) {
					parity[v] = 0;
					break;
				}
			}
			if (p != NULL) break;
		}
		if (head == tail) {
			printf("-1\n");
			fflush(stdout);
			return 0;
		} else {
			for (; v != i; v = (prev[v]->t == v)? prev[v]->h: prev[v]->t) {
				tmp = prev[v]->h;
				prev[v]->h = prev[v]->t;
				prev[v]->t = tmp;
			}
		}
	}
	
	for (i = 0; i < M; i++) printf("%d %d\n", G.e[i].t, G.e[i].h);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 7936
m = list(map(int, input().split()))
A = m[0]
B = m[1]
K = m[2]

ans = []

for v in range(A, min(A+K, B)):
    ans.append(v)
for v in range(max(B-K+1, A), B+1):
    ans.append(v)

ans = sorted(list(set(ans)))
for v in ans:
    print(v)


Measured memory_bytes: 3060
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		long k=sc.nextLong();
		long a[] = new long[n];
		for(int i=0; i<n; i++) {
			a[i]=sc.nextLong();
		}

		int b[] = new int[40];
		for(int i=0; i<n; i++) {
			for(int j=39; j>=0; j--) {
				b[j] += (a[i]>>j)&1;
			}
		}
		long x = 0;
		for(int i=39; i>=0; i--) {
			if(((1L<<i)+x<=k) && b[i]*2<n) {
				x += (1L<<i);
			}
		}

		long ans = 0;
		for(int i=0; i<n; i++) {
			ans += a[i] ^ x;
		}
		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 50600
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int ans = 0, n;
  cin >> n;
  vector<int> v;
  int a[3] = {3, 5, 7};
  for (int i = 1; i <= 7; i++)
    for (int j = 1; j <= 8 - i; j++)
      for (int k = 1; k <= 9 - i - j; k++) {
        v.clear();
        for (int l = 0; l < i; l++)
          v.push_back(0);
        for (int l = 0; l < j; l++)
          v.push_back(1);
        for (int l = 0; l < k; l++)
          v.push_back(2);
        do {
          long long num = 0;
          for (int l = 0; l < v.size(); l++) {
            num *= 10;
            num += a[v[l]];
          }
          if (num <= n)
            ans++;
        } while (next_permutation(v.begin(), v.end()));
      }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

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

ll cnt[41];

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    ll a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n;i++){
        ll tmp = a[i];
        for(int j=0;j<41;j++){
            if(tmp %2 == 1) cnt[j]++;
            tmp /= 2;
        }
    }
    ll ans = 0;
    for(ll j=40;j>=0;j--){
        if(cnt[j] < n - cnt[j]){
            if(ans + (1LL << j) <= k){
                ans = ans + (1LL << j);
            }
        }
    }
    // cout << ans << endl;
    ll res = 0;
    for(int i=0;i<n;i++){
        res += (ans ^ a[i]);
    }
    cout << res << endl;
}

Measured memory_bytes: 1024
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
 
public class Main
{
    public static void main(String[] args)
    {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        int x=in.nextInt();
        int t=in.nextInt();
        int ans=0;
        if(n%x==0)
            ans=n/x;
        else
            ans=1+n/x;
        ans*=t;
        System.out.println(ans);
    }
}


Measured memory_bytes: 35620
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;
// spring s; cin >> s;
// cout << res << endl;
// --------write my code!!!!!----------//

// I'm trying to ~~~
int main(){
    int A,B; cin >> A >> B;
    cout << max({A+B,A-B,A*B}) << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
tmpA = A
ans = 0
while True:
    tmpA = [a/2 for a in tmpA if a%2==0 and a!=0 ]
    if len(A) == len(tmpA):
        ans+=1
    else:
        print(ans)
        exit()


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

int main()
{
  char O[51], E[51];
  cin >> O >> E;

  int oLen=strlen(O);
  int eLen=strlen(E);
  rep(i,oLen){
    cout << O[i];
    if(eLen>i) cout << E[i];
  }
  cout << endl;
}


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

using namespace std;
typedef long long lint;

#define RPT(i, b, e) for (int i = ((int)b); i <= ((int)e); i++)
#define RPT0(i, n) RPT(i, 0, ((int)n) - 1)
#define RPT1(i, n) RPT(i, 1, (n))
#define EACH(it, v) for (const auto& it : v)
#define ALL(v) v.begin(), v.end()

void resolve()
{
    int N;
    cin >> N;

    map<int, string> m;
    m[0] = "pon";
    m[1] = "pon";
    m[2] = "hon";
    m[3] = "bon";
    m[4] = "hon";
    m[5] = "hon";
    m[6] = "pon";
    m[7] = "hon";
    m[8] = "pon";
    m[9] = "hon";
    string ans = m[N % 10];
    cout << ans << endl;
}

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

/*
#include <chrono>
int main()
{
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();

    resolve();

    end = chrono::system_clock::now();
    double time = static_cast<double>(
        chrono::duration_cast<chrono::microseconds>(end - start).count() /
        1000.0);
    cout << "resolve(): " << time << "[ms]" << endl;

    return 0;
}
*/


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

const long long INF = 1LL << 60;
long long dp[100005];

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; ++i)
        cin >> h[i];
    for (int i = 0; i < 100005; ++i)
        dp[i] = INF;

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

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


Measured memory_bytes: 1408