akhauriyash/Code-Regression huggingface dataset:
class Edge:

    def __init__(self, from_node, to_node, weight):
        self.from_node = from_node
        self.to_node = to_node
        self.weight = weight


def bellman_ford(N, edges, start, goal):
    # Weight Maximization
    MIN_INF = - 10**15
    d = [MIN_INF for _ in range(N)]
    d[start] = 0
    for loop in range(N):
        updated = False
        goal_updated = False
        for edge in edges:
            new_d = edge.weight + d[edge.from_node]
            if d[edge.to_node] < new_d:
                d[edge.to_node] = new_d
                updated = True
                if edge.to_node == goal:
                    goal_updated = True
        if not updated:
            return d[goal]
        if loop == N - 1:
            if not goal_updated:
                return d[goal]
            # exists a positive loop which connected to the goal node.
            return None


def main():
    N, M = list(map(int, input().split(' ')))
    edges = list()
    for _ in range(M):
        a, b, c = list(map(int, input().split(' ')))
        from_node = a - 1 
        to_node = b - 1
        weight = c
        edges.append(Edge(from_node, to_node, weight))
    start, goal = 0, N - 1
    result = bellman_ford(N, edges, start, goal)
    if result is None:
        print('inf')
    else:
        print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3620
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

using namespace std;

int main()
{
    int a,b;
    cin >> a;
    cin >> b;
    for (int i = 1;i <= 3;i++){
        if (i != a && i != b){
            cout << i << endl;
            break;
        }
    }
}


Measured memory_bytes: 256
n = int(input())
p_ls = list(map(int, input().split()))
same_ls = [0] * n

for i in range(n):
    if p_ls[i] == i+1:
        same_ls[i] = 1
count = 0
for i in range(n-1):
    if same_ls[i] == 1:
        same_ls[i+1] = 0
        count += 1
if same_ls[n-1] == 1:
    count += 1
print(count)





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

int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<char>>data(h,vector<char>(w));
    rep(i,h){rep(j,w)cin >> data[i][j];}
    rep(i,h){
        rep(j,w){
            cout << data[i][j];
        }
        cout << endl;
        rep(j,w){
            cout << data[i][j];
        }
        cout << endl;

    }
    return 0;
}

Measured memory_bytes: 256
def flip(color)
  if color == 0 then 1 else 0 end
end

n = gets.to_i
sides = (n-1).times.map { gets.split.map(&:to_i) }
sides_on = {}
sides.each do |side|
  u, v, w = side
  sides_on[u] ||= []
  sides_on[u] << side
  sides_on[v] ||= []
  sides_on[v] << [v, u, w]
end
visited = {}
arr = Array.new(n+1)
arr[1] = 0 # vertex 1 is white
queue = [1]

until queue.empty?
  u = queue.pop
  visited[u] = true
  sides = sides_on[u]
  if sides
    sides.each do |side|
      u, v, w = side
      unless visited[v]
        if w.even?
          arr[v] = arr[u]
        else
          arr[v] = flip(arr[u])
        end
        queue.push(v)
      end
    end
  end
end

1.upto(n) do |i|
  puts arr[i]
end


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


int main()
{
	map<string, int> a;
	map<string, int>::iterator it;
	int n, m;
	string x;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x;
		if (a.find(x) == a.end()) {
			a[x] = 1;
		}
		else {
			a[x] += 1;
		}
	}
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> x;
		if (a.find(x) == a.end()) {
			a[x] = -1;
		}
		else {
			a[x] -= 1;
		}
	}

	int v = 0;
	for (it = a.begin(); it != a.end(); it++) {
		v = max(v, it->second);
	}
	cout << v << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define END return 0
typedef int64_t ll;
const int mod7 = 1e9 + 7;
const int mod9 = 1e9 + 9;
const int inf = 1 << 30;
const ll INF = 1LL << 60;
template<typename T> T gcd(T a, T b) {return b ? gcd(b, a % b) : abs(a);}
template<typename T> T lcm(T a, T b) {return a / gcd(a, b) * b;}
template<typename T> bool chmax(T &a, T b) {if (a < b) {a = b; return true;} return false;}
template<typename T> bool chmin(T &a, T b) {if (a > b) {a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) {fill((T*)array, (T*)(array+N), val);}

int main() {
    int n;
    cin >> n;
    int a[n], p[n], q[n];
    rep(i, n) a[i] = i + 1;
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];
    int index = 1;
    int pin, qin;
    do {
        bool pok = true, qok = true;
        rep(i, n) if(a[i] != p[i]) pok = false;
        rep(i, n) if(a[i] != q[i]) qok = false;
        if(pok) pin = index;
        if(qok) qin = index;
        index++;
    } while(next_permutation(a, a + n));
    cout << abs(pin - qin) << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int>vi;
#define pb push_back
#define sc(n) scanf("%d",&n)
#define lsc(n) scanf("%lld",&n)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define rev1(i,n) for(i=n;i>0;i--)
#define in insert
#define IT ::iterator
#define pr(n) printf("%d\n",n)
#define lpr(n) printf("%lld\n",n);


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


Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
 int N,P[200001],x=1,y=0;
 cin>>N;
 for(int i=0;i<N;i++){
   cin>>P[i];
 }
 y=P[0];
 for(int i=1;i<N;i++){
   if(P[i]<=y){
     x=x+1;
   }
   y=min(y,P[i]);
 }
cout<<x;

 return 0;
}


Measured memory_bytes: 1024
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int64_t a, b, ans;
	char s[10];
	memset(s, 0, sizeof(0));
	cin >> a >> s;
	b = (s[0] - '0') * 100 + (s[2] - '0') * 10 + (s[3] - '0');
	cout << a * b / 100 << endl;
	return 0;
}

Measured memory_bytes: 3196
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

using ll = long long;
const ll MOD = 998244353;

int main() {
    int N;
    cin >> N;
    int P[8], Q[8], R[8];
    rep(i, N) cin >> P[i];
    rep(i, N) cin >> Q[i];
    rep(i, N) R[i] = i + 1;
    int i = 0, a, b;
    while (true) {
        bool f = true;
        rep(j, N) if (R[j] != P[j]) f = false;
        if (f) {
            a = i;
            break;
        }
        i++;
        next_permutation(R, R + N);
        //rep(i, N) cout << R[i];
        //cout << endl;
    }
    i = 0;
    rep(i, N) R[i] = i + 1;
    while (true) {
        bool f = true;
        rep(j, N) if (R[j] != Q[j]) f = false;
        if (f) {
            b = i;
            break;
        }
        i++;
        next_permutation(R, R + N);
    }
    cout << abs(a - b) << endl;
    //cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<61;
const double EPS=1e-9;
const int MOD=1e9+7;
struct edge{int to,cost;};
int main(){
    int n,m;cin>>n>>m;
    vector<vector<edge>> G(n+2*m),G2(n);
    vector<vector<int>> cs(n);
    for(int i=0;i<m;i++){
        int a,b,c;cin>>a>>b>>c;--a;--b;
        G2[a].emplace_back((edge){b,c});
        G2[b].emplace_back((edge){a,c});
        cs[a].emplace_back(c);
        cs[b].emplace_back(c);
    }
    int id=n;
    map<P,int> mp;
    for(int i=0;i<n;i++){
        sort(all(cs[i]));
        cs[i].erase(unique(all(cs[i])),cs[i].end());
        for(int j=0;j<cs[i].size();j++){
            mp[P(i,cs[i][j])]=id+j;
            G[i].emplace_back((edge){id+j,1});
            G[id+j].emplace_back((edge){i,0});
        }
        id+=cs[i].size();
    }
    for(int i=0;i<n;i++){
        for(auto e:G2[i]){
            int u=mp[P(i,e.cost)],v=mp[P(e.to,e.cost)];
            G[u].emplace_back((edge){v,0});
            G[v].emplace_back((edge){u,0});
        }
    }
    vector<int> d(id);
    fill(all(d),INF);
    priority_queue<P,vector<P>,greater<P>> q;
    d[0]=0;
    q.emplace(P(0,0));
    while(!q.empty()){
        int v=q.top().second;q.pop();
        for(auto e:G[v]){
            if(d[e.to]<=d[v]+e.cost)continue;
            d[e.to]=d[v]+e.cost;
            q.push(P(d[e.to],e.to));
        }
    }
    cout<<(d[n-1]==INF?-1:d[n-1])<<endl;
}


Measured memory_bytes: 90096
#include<stdio.h>
 
int main()
{
  int t[4][14];
  int n, i,j,c;
  char m, d;
  for(i=0; i < 4; i++){
    for(j=0; j < 14; j++){
      t[i][j]=0;
    }
  }
 scanf("%d", &c);
  for(i = 0; i < c; i++){
    scanf("%c", &d);
    scanf("%c %d", &m, &n);
    if(m == 'S'){
      t[0][n] = 1;
    }
    else if(m == 'H'){
      t[1][n] = 1;
    }
    else if(m == 'C'){
      t[2][n] = 1;
    }
    else if(m == 'D'){
      t[3][n] = 1;
    }
  }
  for(j=1; j < 14; j++){
    if(t[0][j] != 1){
      printf("S %d\n", j);
    }
  }
 
 for(j=1; j < 14; j++){
    if(t[1][j] != 1){
      printf("H %d\n", j);
    }
  }
 
 for(j=1; j < 14; j++){
    if(t[2][j] != 1){
      printf("C %d\n", j);
    }
  }
 
 for(j=1; j < 14; j++){
    if(t[3][j] != 1){
      printf("D %d\n", j);
    }
  }
 return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}


int N;
vector<int> W;
vector<vector<int>> dp;

void solve(){
  W.assign(N, 0); rep(i, N) cin >>W[i];
  dp.assign(N+1, vector<int>(N+1, -N));
  rep(i, N+1) dp[i][i] = 0;
  rep(i, N) dp[i][i+1] = 0;
  // dp[i][j]...[i,j) のブロックが残っているとき最適な叩き出しを行って取り除けるブロックの個数
  for (int len=2; len<=N; len++){
    for (int i=0; i+len<=N; i++){
      int j = i + len;
      if (dp[i+1][j-1] == len-2){
        if (abs(W[i]-W[j-1]) <= 1) chmax(dp[i][j], len);
        else chmax(dp[i][j], len-2);
      }
      for (int k=i+1; k<j; k++){
        chmax(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }
  cout <<dp[0][N] <<endl;
}

int main() {
  cin >>N;
  while (N > 0){
    solve();
    cin >>N;
  }
}



Measured memory_bytes: 3232
#!/usr/bin/perl

while (<>) {
    chomp;
    @w = split //, $_;
    last;
}

foreach (@w) {
    $n{$_}++;
}

$b = 1;
foreach (keys %n) {
    if ($n{$_} % 2 == 1) {
        $b = 0;
        last;
    }
}

if ($b) {
    print "Yes\n";
} else {
    print "No\n";
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  bool win = false;
  rep(i, n) {
    if (a[i] % 2) win = true;
  }
  if (win) cout << "first" << endl;
  else cout << "second" << endl;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    double n;
    cin>>n;
  int a=n;
    if(a%2==0){
        cout<<0.5;
    }else{
    cout<<((n+1)/2)/n;
    }
    return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
ary_a = gets.split(" ").map(&:to_i)
ary_b = []

n.times do |i|
  if i.even?
    ary_b.push(ary_a[i])
  else
    ary_b.unshift(ary_a[i])
  end
end

if n.odd?
  puts ary_b.reverse.join(" ")
else
  puts ary_b.join(" ")
end


Measured memory_bytes: 27104
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>

using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...
    int N;
    cin >> N;
    vector <int> a(N);
    for (auto i=0; i<N; ++i){
        cin >> a[i];
    }
    int ret = accumulate(a.begin(), a.end(), 0);
    ret -= N;
    cout << ret << endl;
    
    return 0;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

const llong inf = 1'000'000'000'000'007ll;
const llong mod = 1e9+7;

int main() {
	llong N, Q;
	vector<vector<llong> > edges;
	vector<llong> cnt;

	cin >> N >> Q;
	edges.resize(N+1);
	cnt.resize(N+1, 0);

	llong a, b;
	for (int i = 0; i < N-1; ++i) {
		cin >> a >> b;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}

	llong p, x;
	for (int i = 0; i < Q; ++i) {
		cin >> p >> x;
		cnt[p] += x;
	}

	queue<lpair> que;
	vector<llong> used(N+1, 0);
	que.push(lpair(0, 1));
	used[1] = 1;
	while (que.size()) {
		llong now = que.front().second;
		llong before = que.front().first;
		que.pop();

		cnt[now] += cnt[before];
		for (auto edge: edges[now]) {
			if (used[edge] == 1) continue;
			used[edge] = 1;
			que.push(lpair(now, edge));
		}
	}

	for (int i = 1; i <= N; ++i)
		cout << cnt[i] << " ";
	cout << endl;

	return 0;
}


Measured memory_bytes: 21104
/**
*    author:  y_takano
*    created: 18.06.2020 15:25:16
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  int i, j, k;
  cin >> i >> j >> k;

  if (i < j && j < k)
  {
      cout << "Yes\n";
  }
  else
  {
      cout << "No\n";
  }
  
  return 0;
}


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

struct Edge{
  int src,dst,weight;
  Edge(int src,int dst,int weight) : src(src), dst(dst), weight(weight) { }
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int bfs(Graph &g) {
  int n = g.size();
  vector<int> done(n, 0);

  int ans = 1;
  for(int i=0; i<n; ++i) {
    if(done[i] != 0) continue;
    queue<Edge> q;
    int cost = 0,st = 0;
    done[i] = 1;
    for(q.push(g[i][0]),q.push(g[i][1]);!q.empty();) {
      Edge e = q.front();
      q.pop();
      if(e.weight>cost) cost = e.weight;
      if(done[e.dst] != 0) continue;
      done[e.dst] = 1;
      q.push(g[e.dst][0]);
      q.push(g[e.dst][1]);
    }

    for(int i=0; i<n; ++i) {
      if(done[i]==1 && g[i][0].weight == cost)
	st++;
      if(done[i]==1 && g[i][1].weight == cost)
	st++;
      if(done[i]==1)
	done[i] = 2;
    }

    st /= 2;
    ans *= st;
    ans %= 10007;
  }
  return ans;
}

int main() {
  int n;
  while(cin>>n, n) {
    Graph g(n);
    int b1,b2,f1,f2;
    for(int i=0; i<n; ++i) {
      cin>>b1>>f1>>b2>>f2;
      g[i].push_back( Edge(i, b1, f1) );
      g[i].push_back( Edge(i, b2, f2) );
    }
    cout<<bfs(g)<<endl;
  }
}

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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
        A[i]--;
    }

    int icur = 0;
    queue<int> q;
    q.push(icur);
    set<int> visited;
    visited.insert(icur);
    int s_loop = -1;
    while(true){
        auto inext = A[icur];
        if(visited.count(inext) == 0){
            icur = inext;
            visited.insert(inext);
            q.push(inext);
        }else{
            s_loop = inext;
            break;
        }
    }
    int ishift = 0;
    int res = -1;
    while(!q.empty()){
        auto v = q.front();
        if(K == ishift) res = v;
        if(v == s_loop) break;
        q.pop();
        ishift++;
    }
    vector<int> loop_vec;
    while(!q.empty()){
        loop_vec.push_back(q.front());
        q.pop();
    }

    if(K <= ishift) cout << 1 + res << endl;
    else{
        K -= ishift;
        cout << 1 + loop_vec[K % loop_vec.size()] << endl;
    }

    return 0;
}

Measured memory_bytes: 14536
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();

		System.out.println(a * b / 2 * Math.sin(Math.toRadians(c)));
		System.out.println(a
				+ b
				+ Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2) - 2 * a * b
						* Math.cos(Math.toRadians(c))));
		System.out.println(b * Math.sin(Math.toRadians(c)));
	}
}

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

int main(){
  long long x;
  long long ans;

  scanf(" %lld",&x);

  if(x%11>6){
    ans=2;
  }else if(x%11==0){
    ans=0;
  }else{
    ans=1;
  }

  ans+=x/11+x/11;

  printf("%lld\n",ans);

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
int dp[3005][3005];
main()
{
   char s[3005],t[3005];
   cin>>s;
   cin>>t;
   int i,j,l1,l2;
   l1=strlen(s);l2=strlen(t);
   for(i=1;i<=l1;i++)
   {
       for(j=1;j<=l2;j++)
       {
           if(s[i-1]==t[j-1])
           {
               dp[i][j]=dp[i-1][j-1]+1;
           }
           else
           {
               dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
           }
       }
   }
   //cout<<dp[l1][l2];
   /*for(i=0;i<=l1;i++)
   {
       for(j=0;j<=l2;j++)
       {
           cout<<dp[i][j]<<" ";
       }
       cout<<endl;
   }*/
   char ans[3055];int k1=0;
   int a=l1,b=l2;
   while(1)
   {
       if(a==0 || b==0)break;
       if(dp[a][b]==dp[a-1][b-1]+1 && s[a-1]==t[b-1])
       {
           ans[k1]=s[a-1];k1++;a--;b--;
       }
       else
       {
           if(dp[a-1][b]==dp[a][b])
           {
               a--;
           }
           else
           {
               b--;
           }
       }
   }
   //cout<<ans<<endl;
   for(i=k1-1;i>=0;i--)
   {
       printf("%c",ans[i]);
   }
   cout<<endl;
}


Measured memory_bytes: 38736
#include <cstdio>

const int MN = 100005;

int N, M, Ans;
int num[MN], typ[MN];

int main() {
	scanf("%d%d", &N, &M);
	for (int i = 1; i <= N; ++i)
		num[i] = 1, typ[i] = i == 1;
	for (int i = 1; i <= M; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		if (num[x] == 1) {
			if (typ[x] == 1) typ[y] = 1;
			else if (typ[x] == 2) typ[y] = 2;
			typ[x] = 0;
		} else if (typ[x] != 0) typ[x] = typ[y] = 2;
		--num[x], ++num[y];
	}
	for (int i = 1; i <= N; ++i) if (typ[i]) ++Ans;
	printf("%d\n", Ans);
	return 0;
}

Measured memory_bytes: 896
N, W = [int(_) for _ in input().split()]
WV = [[int(_) for _ in input().split()] for _ in range(N)]
dp = {}
dp[0] = 0
for weight, value in WV:
    dp_old = dp.copy()
    for k, v in dp_old.items():
        if k + weight <= W:
            dp[k + weight] = max(dp.get(k + weight, 0), v + value)
ans = 0
for k, v in dp.items():
    ans = max(ans, v)
print(ans)


Measured memory_bytes: 3716
from collections import defaultdict
    
class Combinatorics:
    def __init__(self, N, mod):
        '''
        Preprocess for calculating binomial coefficients nCr (0 <= r <= n, 0 <= n <= N)
        over the finite field Z/(mod)Z.
        Input:
            N (int): maximum n
            mod (int): a prime number. The order of the field Z/(mod)Z over which nCr is calculated.
        '''
        self.mod = mod
        self.fact = {i: None for i in range(N+1)}         # n!
        self.inverse = {i: None for i in range(1, N+1)}   # inverse of n in the field Z/(MOD)Z
        self.fact_inverse = {i: None for i in range(N+1)} # inverse of n! in the field Z/(MOD)Z
        
        # preprocess
        self.fact[0] = self.fact[1] = 1
        self.fact_inverse[0] = self.fact_inverse[1] = 1
        self.inverse[1] = 1
        for i in range(2, N+1):
            self.fact[i] = i * self.fact[i-1] % self.mod
            q, r = divmod(self.mod, i)
            self.inverse[i] = (- (q % self.mod) * self.inverse[r]) % self.mod
            self.fact_inverse[i] = self.inverse[i] * self.fact_inverse[i-1] % self.mod
    
    def perm(self, n, r):
        '''
        Calculate nPr = n! / (n-r)! % mod
        '''
        if n < r or n < 0 or r < 0:
            return 0
        else:
            return (self.fact[n] * self.fact_inverse[n-r]) % self.mod
    
    def binom(self, n, r):
        '''
        Calculate nCr = n! /(r! (n-r)!) % mod
        '''
        if n < r or n < 0 or r < 0:
            return 0
        else:
            return self.fact[n] * (self.fact_inverse[r] * self.fact_inverse[n-r] % self.mod) % self.mod
        
    def hom(self, n, r):
        '''
        Calculate nHr = {n+r-1}Cr % mod.
        Assign r objects to one of n classes.
        Arrangement of r circles and n-1 partitions:
            o o o | o o | | | o | | | o o | | o
        '''
        if n == 0 and r > 0:
            return 0
        if n >= 0 and r == 0:
            return 1
        return self.binom(n + r - 1, r)
    
n, k = map(int, input().split())
MOD = 10**9 + 7
com = Combinatorics(k, MOD)
ans = com.perm(k, n)
print(ans)


Measured memory_bytes: 6184
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>

using namespace std;
int X;
int main(void) {

	cin >> X;

	if (X >= 30) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
	
	return 0;
}

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

long long gcd(long long a, long long b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
long long chmax(long long a,long long b){
  a = max(a,b);
}
long long chmin(long long a, long long b){
  a = min(a,b);
}

int main() {
  long long n,k,X,sum=0,a=0,b=0,c=0,d=0,ans=0;
  long long MOD = 1000000007;
  long long INF = 1LL << 60;
  string S="";
  cin >> n >> X;
  ans = (n * X) /gcd(n,X);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define Fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MOD 1000000007
 
ll n,i,a[200005],minn,ann;

int main()
{

    Fast;
    
    cin>>n;
    for(i=0;i<n;i++)
        cin>>a[i];
    minn=a[0];
    ann=1;
    for(i=1;i<n;i++)
    {
        if(a[i]<=minn)
            ann++;
        minn=min(minn,a[i]);
    }
    cout<<ann;
}

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

int main(){
    struct data{
        int y;
        int m;
        int d;
        int ny;
    } nn;
    
    while(cin >> nn.y >> nn.m >> nn.d){
        int num = nn.d+nn.m*100+nn.y*10000;
        
        if(num < 18680908){
            cout << "pre-meiji" << endl;
            continue;
        }
        else if(18680908 <= num && num <= 19120729){
            cout << "meiji" << ' ';
            nn.ny = nn.y - 1867;
        }
        else if(19120730 <= num && num <= 19261224){
            cout << "taisho" << ' ';
            nn.ny = nn.y - 1911;
        }
        else if(19261225 <= num && num <= 19890107){
            cout << "showa" << ' ';
            nn.ny = nn.y - 1925;
        }
        else{
            cout << "heisei" << ' ';
            nn.ny = nn.y - 1988;
        }
        cout << nn.ny << ' ' << nn.m << ' ' << nn.d << endl;
    }


    return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    ll N; cin >> N;
    vector<long double> v;
    for (int i = 0; i < N; i++) {
        long double a; cin >> a;
        v.pb(a);
    }
    asort(v);
    long double ans = (v[0]+v[1])/2;
    for (int i = 2; i < N; i++) {
        ans = (ans+v[i])/2;
    }
    printf("%.10Lf\n",ans);
}

Measured memory_bytes: 3836
#include<stdio.h>
#include<stdlib.h>
void push(int);
int pop(void);
int s[100];
int top=0;
int main(){
  int ch,x,y;
  char c[100];
  while(scanf("%s",c)!=EOF){
    if('0'<=c[0] && c[0]<='9'){
      ch=atoi(c);
      push(ch);
      continue;
    }
    y=pop();
    x=pop();
    if(c[0]=='+')push(x+y);
    else if(c[0]=='-')push(x-y);
    else if(c[0]=='*')push(x*y);
  }
  printf("%d\n",pop());
  return 0;
}

void push(int x){
  s[top++]=x;
}

int pop(){
  return s[--top];
}



Measured memory_bytes: 2144
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let n: usize = read();
    let mut xs = vec![0i64; n];
    let mut ys = vec![0i64; n];
    for i in 0..n {
        let v: Vec<i64> = read_vec();
        xs[i] = v[0];
        ys[i] = v[1];
    }
    let mod_0 = (xs[0] + ys[0]).abs() % 2;
    // println!("mod_0 {:?}", mod_0);
    for i in 1..n {
        if (xs[i] + ys[i]).abs() % 2 != mod_0 {
            println!("-1");
            return;
        }
    }
    let mut arms: Vec<i64> = Vec::new();
    for i in (0..34).rev() {
        arms.push(2i64.pow(i));
    }
    if mod_0 == 0 {
        arms.push(1);
    }
    let arms = arms;

    println!("{:?}", arms.len());
    println!("{}", arms.iter().map(|x| x.to_string()).collect::<Vec<_>>().join(" "));

    for (x_goal, y_goal) in xs.iter().zip(ys.iter()) {
        let mut x_cur:i64 = 0;
        let mut y_cur:i64 = 0;
        let mut modes = Vec::new();
        for arm in arms.iter() {
            if (x_cur - x_goal).abs() >= (y_cur - y_goal).abs() {
                if x_cur >= *x_goal {
                    x_cur -= *arm;
                    modes.push("L")
                } else {
                    x_cur += *arm;
                    modes.push("R")
                }
            } else {
                if y_cur >= *y_goal {
                    y_cur -= *arm;
                    modes.push("D")
                } else {
                    y_cur += *arm;
                    modes.push("U")
                }
            }
        }
        println!("{}", modes.join(""));
        // println!("{:?}", (x_cur, y_cur));
    }
}


Measured memory_bytes: 4352
def conv(s)
  s.chars.map{ |c| c.ord - ?a.ord }
end

def solve(s,k)
  a = conv(s)
  n = a.size
 
  (n-1).times do |i|
    next if a[i] + k < 26
    next if a[i] == 0
    
    k -= 26 - a[i]
    a[i] = 0
  end  

  a[-1] = (a[-1] + k) % 26
  
  return a.map{ |c| (c + ?a.ord).chr }.join
end  

def main
  s = gets.chomp
  k = gets.to_i
  puts solve(s,k)
end

main

Measured memory_bytes: 15996
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  ll ans[N+1];
  ans[0] = 2;
  ans[1] = 1;
  for(int i=2;i<=N;++i) ans[i] = ans[i-1]+ans[i-2];
  cout<<ans[N]<<endl;
}


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

int main(){
    ll n, x, m;
    cin >> n >> x >> m;

    ll ans=x;
    ll num=x;
    set<int> s;
    s.insert(x);

    rep(i, n-1){
        num=(num*num)%m;
        // cout<<num<<endl;
        if(num==0){
            cout<<ans<<endl;
            return 0;
        }

        if(s.count(num)==1){
            //count
            // cout<<"in"<<endl;
            ans+=num;
            int cnt=0;
            int st=num;
            ll sum=num;
            while(true){
                cnt++;
                num=(num*num)%m;
                if(num==st) break;
                sum+=num;
            }
            ans+=(sum)*((n-i-2)/cnt);
            ll di=(n-i-2)%cnt;
            rep(j, di){
                num=(num*num)%m;
                ans+=num;
            }
            break;
        }
        s.insert(num);
        ans+=num;
    }

    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5900
#coding:utf-8

            
def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))
    sumv = sum(a)
    s = sumv / (4 * m)
    cnt = 0
    for v in a:
        if v >= s:
            cnt += 1
    if cnt >= m:
        print('Yes')
    else:
        print('No')
    
if __name__ == '__main__':
    main()

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

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int &p:a){
        cin>>p;
    }
    bool fl=1;
    sort(a.begin(),a.end());
    for(int i=0;i<n-1;i++){
        if(a.at(i)==a.at(i+1)){
            cout<<"NO"<<endl;
            fl=0;
            break;
        }
    }
    if(fl) cout<<"YES"<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define loop for(;;)
typedef std::vector<long> LI;
template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   bool memo[8000000];
   void solve() {
      long m, n; scan(m, n);
      if( m == 0 and n == 0 ) exit(0);
      for(bool &b : memo) b = false;
      long rem = n;
      for(long i = m; i < 8000000; ++i) {
         if( not memo[i] ) {
            rem -= 1;
            if( rem < 0 ) {
               printf("%ld\n", i);
               return;
            }
            for(long k = 2 * i; k < 8000000; k+=i) {
               memo[k] = true;
            }
         }
      }
   }
};

int main() {
   loop std::shared_ptr<Solver>(new Solver())->solve();
}

Measured memory_bytes: 11016
#include <iostream>
#include <algorithm>
#include <climits>

using namespace std;


int main(void) {
    int n;

    while (std::cin >> n) {
        if (n == 0) {
            break;
        }

        int s = 0;
        int max_sum = INT_MIN;
        int min_sum = 0;

        for (int i = 0; i < n; i++) {
            int a;
            cin >> a;

            s += a;

            max_sum = max(max_sum, s - min_sum);
            min_sum = min(min_sum, s);
        }

        std::cout << max_sum << std::endl;
    }

    return 0;
}

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

using namespace std;

#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;

int main(){
    int A,B;
    cin >> A >> B;
    cout << max(max(A+B, A-B),A*B) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
int main() {
	string s, t, u, v;cin >> s;bool b = false;
	t = s.substr(0, ((s.size() - 1) / 2));
	u = s.substr((s.size() + 1) / 2);
	if (t == u) {
		rep(i, t.size() / 2) {
			if (t[i] != t[t.size() - i - 1]) {
				b = true;
				break;
			}
		}
		if (!b) {
			rep(i, u.size() / 2) {
				if (u[i] != u[u.size() - i - 1]) {
					b = true;
					break;
				}
				if (i == u.size() / 2 - 1) {
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}
	if (s.size() == 3 && t == u) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  int sum=0;
  int x=0;
  for(int i=0;i<N;i++){
    cin >> x;
    sum += x;
  }
  vector<int> C(N-1);
  for(int i=0;i<N-1;i++){
    cin >> C.at(i);
  }
  for(int i=0;i<N-1;i++){
    if(A.at(i)+1==A.at(i+1)){
      sum += C.at(A.at(i)-1);
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
A,B,C,D = map(int, input().split())
import fractions
LCM = (C * D) // fractions.gcd(C, D)
ans = (B - A + 1)  - ((B // C - (A - 1) // C) + (B // D - (A - 1) // D) - (B // LCM - (A - 1) // LCM))
print(ans)


Measured memory_bytes: 5176
#include <iostream>
#include <vector>
using namespace std;
void p(vector<char> xs) {
  for(auto x:xs) cout<<x;
  cout<<endl;
}
main() {
  char c;
  vector<char> xs;
  int sum=0;
  while(cin>>c) {
    if(c!='0' && c!='1') break;
    if(!xs.empty() && c!=xs.back()) {
      xs.pop_back();
      sum += 2;
    } else xs.push_back(c);
  }
  cout<< sum <<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int i,j,k,n,m,l,count1=0;
void ABC130(void);
void ABC131(void);
void ABC132(void);
void ABC133(void);
void ABC134(void);
void ABC135(void);
void ABC136(void);
void ABC137(void);
void ABC138(void);
void ABC139(void);

int main(void){
    ABC136();
}

void ABC136(){
    string s;
    cin>>n;
    for(i=1;i<=n;i++){
        s=to_string(i);
        if(s.length()%2==1)count1++;
    }
    cout<<count1<<endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.util.regex.*;

class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s;
        while ((s = br.readLine()) != null) {
            System.out.println(poor(s));
        }
    }

    static String poor(String str) {
        Pattern data = Pattern.compile("this|that|the");
        char[] c=str.toCharArray();
        int poor=0;
        while(!data.matcher(String.valueOf(c)).find()&&poor<=26){
            for(int i=0;i<c.length;i++){
                if('a'<=c[i]&&c[i]<='z'){
                    if(c[i]!='z') c[i]++;
                    else c[i]='a';
                }
            }
            poor++;
        }
        return String.valueOf(c);
    }
}

Measured memory_bytes: 24552
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
ll cnt[1001];
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  int n;cin>>n;
  REP(i,1001)cnt[i]=1;
  for(int i=1;i<=n;i++){
    int f=i;
    for(int j=2;j<=1000;j++){
      while(f%j==0){
        f=f/j;
        cnt[j]++;
      }
    }
  }
  ll ans=1;
  // REP(i,1000)P(cnt[i]);
  REP(i,1000){
    ans*=cnt[i];
    ans%=MOD;
  }
  P(ans);
  return 0;
}


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

int c[20], a[20][20], p[20];
int ans = INT_MAX;
int n, m, x;

void dfs(int s, int co)
{
	if (s == n + 1)
	{
		for (int i = 1; i <= m; i++) if (p[i] < x) return;
		ans = min(ans, co);
		return;
	}
	dfs(s + 1, co);
	for (int i = 1; i <= m; i++) p[i] += a[s][i];
	dfs(s + 1, co + c[s]);
	for (int i = 1; i <= m; i++) p[i] -= a[s][i];
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n >> m >> x;
	for (int i = 1; i <= n; i++)
	{
		cin >> c[i];
		for (int j = 1; j <= m; j++)
			cin >> a[i][j];
	}
	dfs(1, 0);
	if (ans > 1e9) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define debug(x) cout << #x << " -> " << x << endl
#define booga cout << "booga" << endl
#define ll long long int
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;


void reverseStr(string& str){ 
    int n = str.length(); 
  
    // Swap character starting from two 
    // corners 
    for (int i = 0; i < n / 2; i++) 
        swap(str[i], str[n - i - 1]); 
}

void testcase(){
	ll n;
	cin >> n;
	//n--;
	string ans;
	while(n > 0){
		n--;
		ans += (char)('a' + (n % 26));
		n /= 26;
	}
	reverseStr(ans);
	cout << ans << "\n";
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	while(t--){
		testcase();
	}
	return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int a[3],type[4];
    for(int i=0;i<4;i++)type[i]=0;
    while(true){
        bool f=false;
        for(int i=0;i<3;i++)cin>>a[i];
        for(int i=0;i<3;i++){
            if(a[i]>=a[(i+1)%3]+a[(i+2)%3])f=true;
        }
        if(f)break;
        type[0]++;
        sort(a,a+3);
        if(a[2]*a[2]>a[1]*a[1]+a[0]*a[0])type[3]++;
        else if(a[2]*a[2]==a[1]*a[1]+a[0]*a[0])type[1]++;
        else type[2]++;

    }
    while(cin>>a[0]);
    for(int i=0;i<4;i++){
        if(i==0)cout<<type[0];
        else cout<<" "<<type[i];
    }
    cout<<endl;
    return 0;
}
/*3 4 5
2 1 2
6 3 4
1 1 1
1 2 3*/

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
int s[100000];
int N;

int ans[100000]; // 1: sheep, 0: wolf

int sub(int k) {
    int a = ans[k];
    int b = ans[(k - 1 + N) % N];
    if (s[k]) {
        return a ? b : (1 - b);
    } else {
        return a ? (1 - b) : b;
    }
}

int main() {
    cin >> N;
    string S;
    cin >> S;
    for(int i = 0; i < N; i++) {
        s[i] = S[i] == 'o';
    }
    for(int i = 0; i < 2; i++) {
        for(int j = 0; j < 2; j++) {
            ans[0] = i;
            ans[1] = j;
            for(int k = 1; k < N - 1; k++) {
                ans[k + 1] = sub(k);
            }
            if(sub(N - 1) == ans[0] && sub(0) == ans[1]) {
                for (int k = 0; k < N; k++) {
                    cout << (ans[k] ? 'S' : 'W');
                }
                cout << endl;
                return 0;
            }
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
#define forn(i,n) for(ll i=0;i < ll (n); i++)

class DisjointSet{
public:
    vector<ll>Parent, Rank, Size;
    ll MaxSize=1;
    DisjointSet(ll n)
    {
        forn(i,n+1) Parent.push_back(i), Rank.push_back(0), Size.push_back(1);
    }
    ll Find(ll x)
    {
        if(Parent[x]==x) return x;
        else Parent[x]=Find(Parent[x]);
        return Parent[x];
    }
    void Union(ll x, ll y)
    {
        ll u=Find(x);
        ll v=Find(y);
        if(u==v) return;
        if(Rank[u] > Rank[v]) Parent[v]=u, Size[u]+=Size[v];
        else
        {
            Parent[u]=v;
            Size[v]+=Size[u];
            if(Rank[u]==Rank[v]) Rank[u]++;
        }
        MaxSize=max(MaxSize, max(Size[u], Size[v]));
        return;
    }
};

int main()
{
    ll n,m;
    cin>>n>>m;
    DisjointSet dis(n);
    ll j,k;
    forn(i,m)
    {
        cin>>j>>k;
        dis.Union(j,k);
    }
    cout<<dis.MaxSize<<endl;
    return 0;
}


Measured memory_bytes: 8208
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;

int d,n;
int t[201];
int dp[201][201];
int a[201],b[201],c[201];
int check(int i,int j)
{
  if(i==d-1)
    return 0;
  if(i>=d || j>=n)
    return -999999;
  if(dp[i][j]!=-1)
    return dp[i][j];
  int sum=0;

  for(int ii=0;ii<n;ii++)
    {
      if(a[ii]<=t[i+1] && t[i+1]<=b[ii])
	sum=max(sum,check(i+1,ii)+abs(c[j]-c[ii]));
    }
  dp[i][j]=sum;
  return sum;

}
int main()
{
  memset(dp,-1,sizeof(dp));
  cin>>d>>n;

  for(int i=0;i<d;i++)
    cin>>t[i];
  for(int i=0;i<n;i++)
    cin>>a[i]>>b[i]>>c[i];
  int ans=0;
  for(int i=0;i<n;i++)
    {
      if(a[i]<=t[0] && t[0]<=b[i])
	ans=max(ans,check(0,i));
    }
  cout<<ans<<endl;
}

Measured memory_bytes: 1340
#include <stdio.h>

#define MAX (8)

void spin(char map[MAX + 1][MAX + 1])
{
	static int no;
	char a_map[MAX + 1][MAX + 1];
	int i, j;
	
	printf("%d\n", ++no * 90);
	
	for (i = 0; i < MAX; i++) for (j = 0; j < MAX; j++) a_map[j][MAX - i - 1] = map[i][j];
	for (i = 0; i < MAX; i++) for (j = 0; j < MAX; j++) map[i][j] = a_map[i][j];
	
	for (i = 0; i < MAX; i++) puts(map[i]);
	
	if (no == 3) return;
	else spin(map);
}


int main(void)
{
	char map[MAX + 1][MAX + 1];
	int i;
	
	for (i = 0; i < MAX; i++) scanf("%s", map[i]);
	
	spin(map);
	
	return (0);
}

Measured memory_bytes: 0
fn main() {
    let mut sc = Scanner::new();
    let n = sc.usize_read();
    let m = sc.usize_read();
    let xyz: Vec<(i64, i64, i64)> = (0..n).map(|_| (sc.read(), sc.read(), sc.read())).collect();

    println!(
        "{}",
        (0..8).map(|mask| maximize(&xyz, mask, m)).max().unwrap()
    );
}

fn maximize(xyz: &Vec<(i64, i64, i64)>, mask: usize, m: usize) -> i64 {
    let mut v = xyz.iter()
        .map(|&(x, y, z)| {
            let x = if mask & (1 << 0) != 0 { -x } else { x };
            let y = if mask & (1 << 1) != 0 { -y } else { y };
            let z = if mask & (1 << 2) != 0 { -z } else { z };
            (x + y + z, x, y, z)
        })
        .collect::<Vec<_>>();
    v.sort();
    v.reverse();

    let mut sx = 0;
    let mut sy = 0;
    let mut sz = 0;
    for i in 0..m {
        let (_, x, y, z) = v[i];
        sx += x;
        sy += y;
        sz += z;
    }
    sx.abs() + sy.abs() + sz.abs()
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        (0..n).map(|_| self.read()).collect()
    }

    fn usize_read(&mut self) -> usize {
        self.read()
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            int[] p = new int[4];
            for (int i = 0; i < 6; i++) {
                int a = in.nextInt();
                p[a - 1] ++;
            }
            int i;
            for (i = 0; i < 4; i++) {
                if(p[i] > 2 || p[i] == 0){
                    break;
                }
            }
            if(i == 4){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
        }
    }
}

Measured memory_bytes: 23252
import java.util.*

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
    var kotlin=scan.nextLine().toLong()
    var ans = ""

    while(kotlin>0)
    {
        var x : Long = kotlin%26
        ans+=getchar(x)
        if(x==0.toLong())
            kotlin=(kotlin/26)-1
        else
        {
            if (kotlin == 26.toLong())
                kotlin = 0
            else
                kotlin /= 26
        }
    }
    ans=ans.reversed()
    println(ans)

}

fun getchar(n : Long) : Char
{
    if(n==0.toLong())
        return 'z'
    var n :Long = (n)+96
    return n.toChar()
}


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

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

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

def Christmas(x):
    result25 = 'Christmas'
    if(x==25):
        return result25
    elif(x==24):
        result24 = result25 + ' Eve'
        return result24
    elif(x==23):
        result23 = result25 + ' Eve Eve'
        return result23
    else:
        result22 = result25 + ' Eve Eve Eve'
        return result22

print(Christmas(day))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int a,b;
    cin>>a>>b;
    long long int result=0;
    if(b-a<100){
        result = a;
        FOR(i,a+1,b+1){
            result^=i;
        }
    }else{
        if(a%2){
            result^=a;
            a++;
        }
        if(b%2==0){
            result^=b;
            b--;
        }
        result^=((b-a+1)/2)%2;


    }
    cout<<result<<endl;
    return 0;
}


Measured memory_bytes: 888