akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	static int[][] price = new int[3][26];

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		for (int i = 0; i < 3; i++) {
		}

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = Integer.parseInt(line);
			if (n == 0) {
				break;
			}
			//
			for (int i = 0; i < 3; i++) {
				for (int j = 1; j < 26; j++) {
					switch (i) {
						case 0:
							price[i][j] = price[i][j - 1] + 380;
							if (j % 5 == 0) {
								price[i][j] -= 380;
							}
							break;
						case 1:
							price[i][j] = price[i][j - 1] + 550;
							if (j % 4 == 0) {
								price[i][j] -= 330;
							}
							break;
						case 2:
							price[i][j] = price[i][j - 1] + 850;
							if (j % 3 == 0) {
								price[i][j] -= 306;
							}
							break;
					}
				}
			}
			int min = Integer.MAX_VALUE;
			for (int i = 0; i < n / 200 + 1; i++) {
				for (int j = 0; j < n / 300 + 1; j++) {
					for (int k = 0; k < n / 500 + 1; k++) {
						if (i * 200 + j * 300 + k * 500 == n) {
							int sum = price[0][i] + price[1][j] + price[2][k];
							if (sum < min) {
								min = sum;
							}
						}
					}
				}
			}
			System.out.println(min);
		}
	}
}

Measured memory_bytes: 18400
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define FOR(i,a,b) for (size_t i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (size_t i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define INF 1e7

string s, t;
int size;

bool my_rotate(int i)
{
  bool flag = true;
  REP(j,size) {
    if(s[j] != t[(i+j)%size]) {
      flag = false;
    }
  }
  return flag;
}


int main()
{
  bool ans = false;
  cin>>s>>t;
  size = s.length();

  REP(i,size) ans |= my_rotate(i);

  if (ans) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
template<typename tn> void read(tn &a){
	tn x=0,f=1; char c=' ';
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	a=x*f;
}
int n;
char mp[45][45];
ll f[45][45][45],fs[45][45][45];
int main(){
	read(n);
	for(int i=1;i<=2*n;i++){
		cin>>mp[i]+1;
		f[i][i][i]=1;
		for(int j=i+1;j<=2*n;j++)
			fs[i][j][i]=mp[i][j]=='1';
	}
	n*=2;
	for(int len=3;len<=n;len++){
		for(int l=1;l<=n-len+1;l++){
			int r=l+len-1;
			for(int p=l;p<r;p++)
				for(int q=l+1;q<=r;q++){
					ll now=0;
					for(int k=q;k<=r;k++) now+=f[q][k][r]*fs[l][k][p];
					for(int mid=l+1;mid<r;mid++) f[l][mid][r]+=now*f[p+1][mid][q-1];
				}
			for(int mid1=l+1;mid1<r;mid1++)
				for(int mid2=r+1;mid2<=n;mid2++)
					if(mp[mid1][mid2]=='1')
						fs[l][mid2][r]+=f[l][mid1][r];
		}
	}
	ll ans=0;
	for(int i=2;i<=n;i++)
		if(mp[1][i]=='1') ans+=f[2][i][n];
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 1152
n,k=map(int,input().split())
s=input()

flag=1
i=0
ans=[0]*(n+1)
for ss in s:
    if int(ss)==flag:
        ans[i]+=1
    else:
        i+=1
        ans[i]+=1
        flag=(flag+1)%2

result=(sum(ans[:min(2*k+1,n)]))

tmp=result

l=0
r=2*k
#print(ans)
while 1:
    if r+2<(n+1):
        tmp=tmp-ans[l]-ans[l+1]+ans[r+1]+ans[r+2]
        l+=2
        r+=2
        result=max(result,tmp)
        #print(ans[l:r])
    else:
        break

    #print(tmp)
print(result)

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

int main() {
    int a, b;
    cin >> a >> b;
    
    if((a+b)%2==0) {
        cout << ( a + b ) / 2 << endl;
    }
    
    else cout << ( a + b ) / 2 + 1 << endl;
}

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

const int N = 10010;
typedef std::pair <int, int> pii;

std::set <int> e[N];
int ans[N];
int c[N];
std::vector <pii> edges;

int main(){
    int n;
    scanf("%d", &n);
    std::set <pii> set;
    for (int i = 0; i < n - 1; ++ i) {
        int u, v;
        scanf("%d%d", &u, &v);
        e[u].insert(v);
        e[v].insert(u);
        edges.push_back({u, v});
    }
    for (int i = 0; i < n; ++ i) {
        scanf("%d", &c[i]);
    }
    for (int i = 1; i <= n; ++ i){
        set.insert({e[i].size(), i});
    }
    std::sort(c, c + n);
    for (int i = 0; i < n; ++ i){
        auto u = set.begin();
        int x = u -> second;
        set.erase(u);
        ans[x] = c[i];
        for (auto v : e[x]){
            set.erase({e[v].size(), v});
            e[v].erase(x);
            set.insert({e[v].size(), v});
        }
    }
    int sum = 0;
    for (auto u : edges){
        sum += std::min(ans[u.first], ans[u.second]);
    }
    printf("%d\n", sum);
    for (int i = 1; i <= n; ++ i){
        printf("%d%c", ans[i], " \n"[i == n]);
    }
    return 0;
}

Measured memory_bytes: 2304
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;


public class Main {
	public void exec() throws IOException {
		Scanner input = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		double r = input.nextDouble();
		out.printf("%.6f %.6f", Math.PI*r*r, 2*Math.PI*r);
		out.flush();
		input.close();
	}

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

Measured memory_bytes: 28404
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main() {
    string str1, str2;
    cin >> str1;
    cin >> str2;
  
    sort(str1.begin(), str1.end());
    sort(str2.begin(), str2.end(),greater<char>());
  
    if (str1 < str2)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
 
    return 0;
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(a, b) << " " << max(0, a + b - n) << endl;
}

Measured memory_bytes: 256
import java.util.*;

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

		String s = sc.nextLine();
		int k = sc.nextInt();
		Set<String> set = new HashSet<>();
		List<String> a = new ArrayList<>();

		for (int i = 0; i < s.length() + 1; i++) {
			for (int j = i + 1; j < s.length() + 1 && Math.abs(j - i) <= k; j++) {
				if (!set.contains(s.substring(i, j))) {
					set.add(s.substring(i, j));
					a.add(s.substring(i, j));
				}
			}
		}

		Collections.sort(a);
		System.out.println(a.get(k - 1));
	}
}


Measured memory_bytes: 26828
void main()
{
    long a, b;
    rdVals(a, b);

    writeln(a + b < 10 ? (a + b).to!string : "error");
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define first fi
#define second se
#define MOD 1000000007
#define MAXN 1000006
#define endl "\n"
#define readln(x) getline(cin, x);
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
typedef pair<ll, ll> pll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;
ll fpow(ll x, ll n, ll mod){if (n==0) return 1%mod; ll u = fpow(x, n/2, mod); u = (u*u)%mod; if (n%2==1)u = (u*x)%mod;return u;}
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }

int k;
queue<ll> q;
int main(){
    //freopen("data.txt","r",stdin);
    cin >> k;
    for (int i = 1; i<=9; i++){
        q.push(i);
    }
    for (int i = 1; i<=k; i++){
        ll x = q.front();
        q.pop();
        if (i==k){
            cout << x << endl;
            return 0;
        }
        if (x % 10 != 0) q.push(10*x + (x%10) - 1);
        q.push(10*x + x%10);
        if (x%10 != 9) q.push(10*x + (x%10) + 1);
    }
    return 0;
}

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

int main() {
	string S;
	cin >>S;
	string ans;

	for (int i = 0; i < 4;i++) {
		if (S[i] == S[i + 1]) {
			ans = "Bad";
			break;
		}
		else {
			ans = "Good";
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define si(x) int(x.size())
const int mod=1000000007,MAX=6005,INF=1<<29;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N=1407,K=38;
    cout<<"1407 38"<<endl;
    
    vector<vector<int>> ans(N,vector<int>());
    
    for(int i=1;i<=K;i++){
        ans[0].push_back(i);
        for(int j=1;j<K;j++){
            ans[(i-1)*(K-1)+j].push_back(i);
        }
    }
    for(int i=1;i<K;i++){
        for(int j=K+(K-1)*(i-1)+1;j<=K+(K-1)*(i-1)+K-1;j++){
            ans[i].push_back(j);
        }
    }
    for(int j=0;j<K-1;j++){
        for(int k=0;k<K-1;k++){
            for(int i=0;i<K-1;i++){
                ans[i*(K-1)+K+(k+j*i)%(K-1)].push_back(K+j*(K-1)+k+1);
            }
        }
    }
    
    for(int i=0;i<N;i++){
        for(int j=0;j<si(ans[i]);j++){
            cout<<ans[i][j]<<" ";
        }
        cout<<endl;
    }
}


Measured memory_bytes: 896
#include <iostream>

using namespace std;

int ciel(int x) {
  while(x%10 != 0)
    x++;
  return x;
}

int main() {
  int nums[5], mods[5], ciels[5];
  for(int i = 0; i < 5; i++) {
    cin >> nums[i];
    mods[i] = nums[i]%10;
    if(mods[i] == 0)
      mods[i] = 10;
  }
  int minmod = mods[0], pos = 0; 
  for(int i = 1; i < 5; i++) {
    if(minmod > mods[i]) {
      pos = i;
      minmod = mods[i];
    }
  }
  int ans = 0;
  for(int i = 0; i < 5; i++) {
    if(i != pos)
      ciels[i] = ciel(nums[i]);
   	else
      ciels[i] = nums[i];
   	ans += ciels[i];
  }
  cout << ans << endl;
  return 0;
}

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

int k;
vector<ll> ans; 

void dfs(string s){
    ll a=stoll(s);
    if(a>3234566667) return;

    ans.push_back(a);

    int x=s[s.size()-1]-'0';
    if(x==0){
        dfs(s+'0');
        dfs(s+'1');
    }
    else if(x==9){
        dfs(s+'8');
        dfs(s+'9');
    }
    else{
        dfs(s+char((x-1)+'0'));
        dfs(s+char(x+'0'));
        dfs(s+char((x+1)+'0'));
    }

}


int main(){
    cin>>k;

    dfs("1");
    dfs("2"); 
    dfs("3"); 
    dfs("4"); 
    dfs("5"); 
    dfs("6"); 
    dfs("7");
    dfs("8");
    dfs("9");

    sort(all(ans));

    cout<<ans[k-1]<<endl;    
}

Measured memory_bytes: 1400
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H, W;
    cin >> H >> W;
    if (H == 1 || W == 1) {
        cout << 1 << endl;
    }
    else {
        cout << ((H + 1) / 2) * ((W + 1) / 2) + (H / 2) * (W / 2) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

// AOJ 0064
public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int res = 0, tmp = 0, mode = 0;
		boolean isn = false;
		while (sc.hasNext()) {
			char[] cs = sc.next().toCharArray();
			for (int i = 0; i < cs.length; i++) {
				isn = Character.isDigit(cs[i]);
				if (mode == 0) {
					if (isn) {
						mode = 1;
						tmp = cs[i] - '0';
					}
				} else {
					if (isn) {
						tmp = tmp * 10 + (cs[i] - '0');
					} else {
						mode = 0;
						res += tmp;
						tmp = 0;
					}
				}
			}
			res += tmp;
			tmp = 0;
		}
		System.out.println(res);
	}
}

Measured memory_bytes: 12000
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class T, class U> inline T GCD_L(T a, U b){
  T r;
  while(b){
    r=a;
    a=b;
    b=r%a;
  }
  return a;
}
template<class T, class U> inline T LCM_L(T a, U b){
  return a/GCD_L(a,b)*b;
}
int N;
int M;
int A[100000];
int main(){
  int i;
  int d;
  long long g = 1;
  rd(N);
  rd(M);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  d = 1;
  while(A[0]%2==0){
    d *= 2;
    A[0] /= 2;
  }
  M /= (d/2);
  for(i=(1);i<(N);i++){
    if(A[i]%d || (A[i]%(2*d)==0)){
      wt_L(0);
      wt_L('\n');
      return 0;
    }
    A[i] /= d;
  }
  for(i=(0);i<(N);i++){
    g =LCM_L(g, A[i]);
    if(g > M){
      wt_L(0);
      wt_L('\n');
      return 0;
    }
  }
  wt_L((M+g)/(2*g));
  wt_L('\n');
  return 0;
}
// cLay varsion 20200119-1

// --- original code ---
// int N, M, A[1d5];
// {
//   int d;
//   ll g = 1;
//   rd(N,M,A(N));
// 
//   d = 1;
//   while(A[0]%2==0) d *= 2, A[0] /= 2;
//   M /= (d/2);
//   rep(i,1,N){
//     if(A[i]%d || (A[i]%(2*d)==0)) wt(0), return 0;
//     A[i] /= d;
//   }
//   rep(i,N){
//     g = lcm(g,A[i]);
//     if(g > M) wt(0), return 0;
//   }
//   wt((M+g)/(2g));
// }


Measured memory_bytes: 640
using System;
using CompLib.Util;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        long i = sc.NextInt();
        long o = sc.NextInt();
        long t = sc.NextInt();
        long j = sc.NextInt();
        long l = sc.NextInt();
        long s = sc.NextInt();
        long z = sc.NextInt();

        long k = 0;

        // ii
        k += (i >> 1) << 1;
        // jj
        k += (j >> 1) << 1;
        // ll
        k += (l >> 1) << 1;

        // o
        k += o;

        // jil
        if (i % 2 == 1 && j % 2 == 1 && l % 2 == 1) k += 3;

        if (i > 0 && j > 0 && l > 0)
        {
            long k2 = 3 + o;
            k2 += ((i - 1) >> 1) << 1;
            k2 += ((j - 1) >> 1) << 1;
            k2 += ((l - 1) >> 1) << 1;
            k = Math.Max(k, k2);
        }

        Console.WriteLine(k);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 27532
attrs = Array.new
while line = $stdin.gets
    attrs << line.chomp.split.map{|v| v.to_i }
end

attr_0 = attrs.shift
N = attr_0[0]
M = attr_0[1]
B = attrs.shift
C = attr_0[2]
solved = 0
attrs.each do |a|
    solution = 0
    for i in 0..M do
       solution += ( a[i].to_i * B[i].to_i )
    end
    solution += C
    if solution > 0 then
        solved += 1
    end
end

print solved

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

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

void solve(int n, int q) {
    vector<int> days;
    int max_day = 0;
    rep(i,n) {
        int m; cin>>m;
        rep(j,m) {
            int date; scanf("%d",&date);
            days.push_back(date);
            max_day = max(max_day, date);
        }
    }

    for(int day=n; day>=q; day--) {
        for(int i=1; i<=max_day; i++) {
            if(count(ALL(days), i) == day) {
                cout << i << "\n";
                return ;
            }
        }
    }
    cout << 0 << "\n";
}

int main() {
    int n,q;
    while(cin>>n>>q and n) solve(n,q);
    return 0;
}

Measured memory_bytes: 3240
#include<bits/stdc++.h>
#define ll long long
#define int ll
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define r1 rt<<1
#define r2 rt<<1|1
#define fi first
#define se second
#define db double
#define ld long db
#define ri register int
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define rep2(i,a,b,c) for(ri i=(a);i<=(b);i+=(c))
#define REP(i,a,b) for(ri i=(a);i>=(b);--i)
#define REP2(i,a,b,c) for(ri i=(a);i>=(b);i-=(c))
using namespace std;

inline ll read(){
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}

const int N=2e5+5,p=1e9+7;
int a[N],inv[N]={0,1};
inline void add(ri &x,ri y){
	x+=y;x>=p?x-=p:0;
}
signed main()
{
	ri n=read();
	rep(i,1,n)a[i]=read();
	ri x=0,y=1,ans=0,cur=0;
	rep(i,2,n)inv[i]=p-(ll)p/i*inv[p%i]%p;
	rep(i,1,n-1)y=(ll)y*i%p;
	rep(i,1,n-1){
		add(cur,(ll)y*inv[i]%p);
		add(ans,(ll)cur*(a[i+1]-a[i])%p);
	}
	cout<<ans;
	return 0; 
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main() {
  int A11, A12, A13;
  int A21, A22, A23;
  int A31, A32, A33;
  cin >> A11 >> A12 >> A13;
  cin >> A21 >> A22 >> A23;
  cin >> A31 >> A32 >> A33;

  int N;
  cin >> N;

  vector<int> b_all(N);
  int l, i=0;
  while (cin >> l) {
    b_all[i] = l;
    i++;
  }

  int c11=0, c12=0, c13=0;
  int c21=0, c22=0, c23=0;
  int c31=0, c32=0, c33=0;
  for (auto b : b_all) {
    if (b==A11) c11=1;
    if (b==A12) c12=1;
    if (b==A13) c13=1;
    if (b==A21) c21=1;
    if (b==A22) c22=1;
    if (b==A23) c23=1;
    if (b==A31) c31=1;
    if (b==A32) c32=1;
    if (b==A33) c33=1;
  }

  int win = 0;

  // yoko
  if (c11+c12+c13==3) win=1;
  if (c21+c22+c23==3) win=1;
  if (c31+c32+c33==3) win=1;

  // tate
  if (c11+c21+c31==3) win=1;
  if (c12+c22+c32==3) win=1;
  if (c13+c23+c33==3) win=1;

  // naname
  if (c11+c22+c33==3) win=1;
  if (c13+c22+c31==3) win=1;

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

  return 0;
}

Measured memory_bytes: 384
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        N: usize,
        XU: [(f64, String); N],
    }
    let mut ans = 0.0;
    for (x,u) in XU{
        if u=="JPY"{
            ans += x;
        }else{
            ans += x*380000.0;
        }
    }
    println!("{}",ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

#include <atcoder/all>

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D, w) for(auto vec : vec2D) { for (auto v : vec) cerr << setw(w) << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

const char en = '\n';

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

typedef vector<vector<int>> Graph;
void add_edge(Graph& g, int from, int to, bool isDirected) {
	g[from].push_back(to);
	if (!isDirected) g[to].push_back(from);
}

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

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

	ll n,q; cin >> n >> q;

	atcoder::dsu uf(n);

	rep(i, q) {
		ll t, u , v; cin >> t >> u >> v;
		if (t) cout << uf.same(u,v) << endl;
		else uf.merge(u,v);
	}
}



Measured memory_bytes: 3896
import java.util.*;
import java.io.*;

public class Main
{
    static class Reader {
		BufferedReader br;
		StringTokenizer st;
 
		public Reader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
 
	}
    static class Ele implements Comparable<Ele> 
    {  
        public int x,y;  
        Ele(int x,int y) 
        {  
            this.x=x;this.y=y; 
        }  
        public int compareTo(Ele ob) {  
        if(ob.x!=x)return x-ob.x;
        return this.y-ob.y;  
        }   
    }
    int a[][];int b[][];
    
    long gcd(long a,long b)
    {
        long min=Math.min(a,b);
        long max=Math.max(a,b);
        while (max%min!=0)
        {
            a=max%min;
            max=min;min=a;
        }
        return min;
    }
	public static void main(String[] args) throws IOException 
	{
		Reader sc=new Reader();Main G=new Main();
		PrintWriter o = new PrintWriter(System.out);
		int t=1;//t=sc.nextInt();
		int x,x0,x1,x2;int y,y0,y1,y2;int s,s0,s1,s2;
		int n,m;int a[],b[],in[],in1[];
		long k,l;boolean b1,b2;String ss1[],ss;
		//long l;long a[]; 
		ArrayList<ArrayList<Integer>> ll=new ArrayList<>();
		ArrayList<Integer> a1=new ArrayList<>();
		ArrayList<Integer> a2=new ArrayList<>();
		ArrayList<Integer> a3=new ArrayList<>();
		ArrayDeque<Integer> deq=new ArrayDeque<>();
		TreeSet<Integer> h0=new TreeSet<>();
		TreeSet<Integer> h1=new TreeSet<>();
		HashMap<Integer,Integer> h=new HashMap<>();
		try{
		while (t-->0)
		{
		    ss=sc.next();
		    o.print(ss);
		    if (ss.charAt(ss.length()-1)=='s') o.println("es");
		    else
		    o.println("s");
		    //o.println(h);
		    //o.println(x2);
		    //o.println();
		    h0.clear();ll.clear();a1.clear();a2.clear();h1.clear();
		}
		}
		catch (Throwable e)
		{
		    e.printStackTrace();
		}
		//o.println("HI");
		
        o.flush();
        o.close();
	}
} 

Measured memory_bytes: 32940
import sys
input = sys.stdin.readline

from collections import deque

N,Q = map(int,input().split())

Queue = [deque([]) for _ in range(N)]

for _ in range(Q):
    q = list(map(int,input().split()))
    if q[0] == 0:
        Queue[q[1]].append(q[2])
    elif q[0] == 1:
        if Queue[q[1]]:
            print(Queue[q[1]][0])
    else:
        if Queue[q[1]]:
            Queue[q[1]].popleft()


Measured memory_bytes: 14536
import string

count = {x: 0 for x in string.ascii_lowercase}
lines = ""

while True:
    try:
        lines += input().lower()
    except EOFError:
        break

for c in lines:
    if 'a' <= c <= 'z':
        count[c] += 1

for key in string.ascii_lowercase:
    print("{0} : {1}".format(key, count[key]))

Measured memory_bytes: 8108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e+9 + 7;
 
int main(){
  ll a,b,k;
  cin >> a >> b >> k;
  a = a - k;
  if(a < 0){
    b = b + a;
    a = 0;
    if(b < 0){
      b = 0;
    }
  }
  cout << a << " " << b << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
ll INF = 1e18;

int main() {
  //
  ll n;
  cin >> n;
  REP(i, 1, 10) {
    REP(j, 1, 10) {
      if (i * j == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
const int MAX_NUM = 1000000+7;
int a[MAX_NUM];
int g[107];
int m; 
int n;
int cnt;
void insertSort(int g){
	int i;
	for(i = g; i < n; i++){
		int key = a[i];
		int j;
		for(j = i-g; j>=0 && a[j] > key;j-=g){
			a[j+g] = a[j];
			cnt++; 
		}
		a[j+g] = key;
	}
}
void shellSort(){
	cnt = 0;
	m = 0;
	int k = 1;
	while(true){
		if(k > n) break;
		g[m++] = k;
		k= 3*k+1;
	}
	
	cout << m << endl;
	
	int q;
	for(q = m-1; q>=0 ;q--){
		if(q!=m-1) cout << " ";
		cout << g[q]; 
	}
	cout << endl;
	int i;
	for(i = m-1; i >=0 ; i--){
		insertSort(g[i]);
	}
}
int main(){
	
	
	cin >> n;
	int i;
	for(i = 0; i < n; i++){
		cin >> a[i];
	}
	
	shellSort();
	cout << cnt<< endl;
	for(i = 0; i < n; i++){
		cout << a[i] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 6992
import sys
sys.setrecursionlimit(10 ** 7)


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def main():
    W, H, x, y = LI()
    if x == W/2 and y == H/2:
        c = 1
    else:
        c = 0
    print(W*H/2, c)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
n=int(input())

s=[]
p=[]
f=[]

for i in range(n):
    ss,pp=input().split()
    s.append(ss)
    p.append(int(pp))
    tmp=(ss,int(pp))
    f.append(tmp)

c=zip(s,p)
d=sorted(c,reverse=True)
e=sorted(d,key=lambda x:x[0])


for i in range(n):
    print(f.index(e[i])+1)


Measured memory_bytes: 3064
k=42
n=k*(k-1)+1
print n,k
for i in xrange(k) :
    for t in xrange(i*(k-1),(i+1)*(k-1)) :
        print t+1,
    print n

for i in xrange(k-1) :
    for d in xrange(k-1) :
        p=d
        for j in xrange(1,k) :
            p=(p+i)%(k-1)
            print j*(k-1)+p+1,
        print i+1


Measured memory_bytes: 2948
// Template //
#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()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)
#define db(i) cout << #i << " = " << i;

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvli = vector<vli>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vvs = vector<vs>;
using mii = map<int, int>;
using mili = map<int, lint>;
using mci = map<char, int>;
using mcli = map<char, lint>;
using msi = map<string, int>;
using msli = map<string, lint>;


// 関数 //
template<class T, class Q> lint gcd_(T a, Q b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

template<class T, class Q> lint lcm_(T a, Q b) {
    return a * b / gcd(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint combination(int n, int m) {
    long double c = 1;
    for (int i = n, k = 1; i > m; i--, k++) {
        c *= i;
        c /= k;
    }
    return (lint)c;
}

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

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

// 定数 //
const double pi = acos(-1);
const int mod = 1000000007;
const int MOD = 998244353;
const int inf = 1045141919;
const lint linf = ((1LL << 62) - 1);


// キーワード //
#define elif else if

// End of Template //



int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
        
    int N, M, K;
    cin >> K >> N >> M;
    for (int i = N; i <= M; i++) {
        if (i % K == 0) {
            cou("OK");
            exit(0);
        }
    }
    cou("NG");


}

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

#include <algorithm>
#include <array>
#include <chrono>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define P pair<ll, ll>
#define FOR(i, n, m) for (ll i = n; i < (ll)m; i++)
#define FORr(i, m, n) for (ll i = n; i >= (ll)m; i--)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define sortAl(v) sort(v.begin(), v.end())
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())
#define cout(n) cout << fixed << setprecision(n)

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

  ll N, M;
  cin >> N >> M;

  vector<pair<ll, ll>> requests(M);
  FOR(i, 0, M) { cin >> requests[i].first >> requests[i].second; }

#if 0
// firstは降順、secondは昇順
  sort(requests.begin(), requests.end(),
       [](pair<ll, ll> const& l, pair<ll, ll> const& r) {
         if (l.first > r.first) return true;
         if (l.first == r.first && l.second < r.second) return true;
         return false;
       });
#endif

  sortAlr(requests);

  ll cnt = 0;

  while (requests.size() > 0) {
    // requests[0].firstとrequests[0].first+1の間の橋を破壊
    ll t = requests[0].first;
    auto result = remove_if(requests.begin(), requests.end(),
                            [=](pair<ll, ll> r) { return t < r.second; });
    // remove_ifでは実際に削除はされていなく、最終的にeraseする必要がある
    requests.erase(result, requests.end());

    cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1920
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long LL;
const int N=305;
const int MOD=998244353;
int add (int x,int y)   {x=x+y;return x>=MOD?x-MOD:x;}
int mul (int x,int y)   {return (LL)x*y%MOD;}
int dec (int x,int y)   {x=x-y;return x<0?x+MOD:x;}
int Pow (int x,int y)
{
	if (y==1) return x;
	int lalal=Pow(x,y>>1);
	lalal=mul(lalal,lalal);
	if (y&1) lalal=mul(lalal,x);
	return lalal;
}
int n;
int a[N];
int sum;
int ans=0;
int f[N][N*N];
int g[N][N*N];
int main()
{
	scanf("%d",&n);
	ans=Pow(3,n);ans=dec(ans,mul(3,Pow(2,n)));ans=add(ans,3);
	for (int u=1;u<=n;u++) 	{scanf("%d",&a[u]);}
	f[0][0]=1;g[0][0]=1;sum=0;
	for (int u=1;u<=n;u++)
	{
		for (int i=0;i<=sum;i++)
		{
			f[u][i]=add(f[u][i],f[u-1][i]);
			g[u][i]=add(g[u][i],mul(2,g[u-1][i]));
			
			f[u][i+a[u]]=add(f[u][i+a[u]],f[u-1][i]);
			g[u][i+a[u]]=add(g[u][i+a[u]],g[u-1][i]);
		}
		sum=sum+a[u];
	/*	for (int i=0;i<=sum;i++) printf("%d ",f[u][i]);
		printf("\n");*/
	}
	for (int u=(sum+1)/2;u<=sum;u++)
	{
		ans=dec(ans,mul(3,g[n][u]));
		ans=add(ans,mul(6,f[n][u]));
	}
	ans=dec(ans,3);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 219392
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>

using namespace std;

int main() {
    long double a, b, c;
    long double eps = 1.0E-14;

    cin >> a >> b >> c;

    if ((sqrt(a) + sqrt(b) + eps) < sqrt(c)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = Integer.parseInt(scan.next());
        int b = Integer.parseInt(scan.next());
        int c = Integer.parseInt(scan.next());
        int x = Integer.parseInt(scan.next());
        int y = Integer.parseInt(scan.next());
        scan.close();

        long ans = Long.MAX_VALUE;

        ans = Math.min(ans, a * x + b * y);
        if (x >= y) {
            ans = Math.min(ans, a * (x - y) + c * 2 * y);
            ans = Math.min(ans, c * 2 * x);
        } else {
            ans = Math.min(ans, b * (y - x) + c * 2 * x);
            ans = Math.min(ans, c * 2 * y);
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
import sys
sys.setrecursionlimit(10 ** 7)

N = int(input())
G = [[] for _ in range(N+1)]

for _ in range(N-1):
  v, u, w = map(int, input().split())
  G[v].append((u, w))
  G[u].append((v, w))

res = [0]*(N+1)
# 現在頂点v を c に塗る。p は v の親
def dfs(v, p, c):
  res[v] = c
  for e, w in G[v]:   
    if e == p:
      continue    
    if w&1:
      # エッジの重みが奇数だったら、次のノードは異色 1-c で塗る
      dfs(e, v, 1-c)
    else:
      #エッジの重みが偶数だったら、次のノードも同色 c で塗る
      dfs(e, v, c)
# res:start[1:] even:cor==0   
dfs(1, 0, 0)      
[print(r) for r in res[1:]]

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

namespace GuessTheNumber
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputValue = Console.ReadLine().Split(' ');
            

            int contests = Convert.ToInt32(inputValue[0]);
            int displayRating = Convert.ToInt32(inputValue[1]);

            int innerRating = 0;
            if (contests < 10)
            {
                var temp = 100 * (10 - contests);
                innerRating = displayRating + temp;
            }
            else
            {
                innerRating = displayRating; 
            }

            Console.WriteLine(innerRating);
        }
    }
}


Measured memory_bytes: 13268
#include <stdio.h>

int main()
  {
  int a, A, N;
  scanf( "%d", &N );
  scanf( "%d", &A );
  if( N%500 <= A )
     {
       printf( "Yes\n" );
    }
  else
    {
    printf( "No\n" );
    }
  return 0;
  }


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 
/**
 *topic: find the diameter of a weighted tree
**/

// ref: LEGOSUKE submission
template <typename T>
struct edge{
  int s, t;
  T c;
  edge() {}
  edge(int t, T c) : s(-1), t(t), c(c) {}
  edge(int s, int t, T c) : s(s), t(t), c(c) {}	
};

template <typename T> using Edges = vector< edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;

template <typename T>
pair<T, int> dfs(const WeightedGraph<T> &g, int v, int par){
   pair<T, int>  ret(0, v);
   for(auto& e: g[v]){
	   if (e.t == par) continue;
	   auto cost = dfs(g, e.t, v);
	   cost.first += e.c;
	   ret = max(ret, cost);  
	 }
  return ret;
} 

template<typename T>
T tree_diameter(const WeightedGraph<T> &g){
  auto p = dfs(g, 0, -1);
  auto f = dfs(g, p.second, -1);
  return f.first;	
}

void solve(){
    int n;
    cin >> n;
    WeightedGraph<int> g(n);
    
    for(int i = 0; i < n - 1; i++){
	   int s, t, w;
	   cin >> s >> t >> w;
	   g[s].push_back({t,w});
	   g[t].push_back({s,w});
	}
   cout << tree_diameter(g) << endl;
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}



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

int top, S[100];

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

int pop() {
    top--;
    return S[top+1];
}

int main() {
    int a, b;
    top = 0;
    char s[100];
    
    while( scanf("%s", s) != EOF ) {
        if ( s[0] == '+' ) {
            a = pop();
            b = pop();
            push(a + b);
        } else if ( s[0] == '-' ) {
            b = pop();
            a = pop();
            push(a - b);
        } else if ( s[0] == '*' ) {
            a = pop();
            b = pop();
            push(a * b);
        } else {
            push(atoi(s));
        }
    }
    
    printf("%d\n", pop());
    
    return 0;
}


Measured memory_bytes: 2104
#define INF 10000000000
#define MOD 1000000007

#if 1   // use_templates

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, up) for (ll i = 0; i < (up); ++i)
#define repp(i, up) for (ll i = 0; i <= (up); ++i)
#define rrep(i, lo, up) for (ll i = (lo); i < (up); ++i)
#define rrepp(i, lo, up) for (ll i = (lo); i <= (up); ++i)
#define eep(i, lo, up) for ((i) = (lo); (i) < (up); ++(i))
#define eepp(i, lo, up) for ((i) = (lo); (i) <= (up); ++(i))
#define feach(it, vec) for (auto it = (vec).begin(); it != (vec).end(); ++it)


ll gcd(ll a, ll b);

ll gcd(ll a, ll b)
{
    if (a < b) {
        return gcd(b, a);
    }
    ll r;
    while (r = a % b) {
        a = b;
        b = r;
    }
    return b;
}

#endif  // end of use_templates


int main()
{
    ll n;
    cin >> n;
    vector<ll> l(n);
    rep(i, n) {
        cin >> l[i];
    }
    ll cnt = 0;
    rep(i, n) {
        rrep(j, i + 1, n) {
            if (l[i] == l[j]) {
                continue;
            }
            rrep(k, j + 1, n) {
                if (l[i] == l[k] || l[j] == l[k]) {
                    continue;
                }
                if (l[i] < l[j] + l[k] && l[j] < l[k] + l[i] && l[k] < l[i] + l[j]) {
                    ++cnt;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3224
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int pc[8][3] = 
{
    {0, 1, 2},
    {3, 4, 5},
    {6, 7, 8},
    {0, 3, 6},
    {1, 4, 7},
    {2, 5, 8},
    {0, 4, 8},
    {2, 4, 6}
};

int main()
{
    string str;
    while(cin >> str)
    {
        rep(i, 8)
        {
            if(str[pc[i][0]] == str[pc[i][1]] && str[pc[i][1]] == str[pc[i][2]])
            {
                if(str[pc[i][0]] == 'o'){ cout << "o" << endl; break;   }
                else if(str[pc[i][0]] == 'x'){ cout << "x" << endl; break; }
            }
            if(i == 7) cout << "d" << endl;
        }
    }
}

Measured memory_bytes: 0
import sys
def main():
    input = sys.stdin.readline
    H,W,K=map(int, input().split())
    oS=[list(map(int, list(input().rstrip()))) for _ in range(H)]

    ans=10**10
    for p in range(1<<(H-1)):
        S=[[oS[i][j] for j in range(W)] for i in range(H)]
        tmp=0
        flag=False
        for i in range(1,H):
            if p&1:
                for j in range(W):
                    S[i][j] += S[i-1][j]
                    if S[i][j]>K: flag=True
            else:
                tmp+=1
            p>>=1
        if flag: continue

        for j in range(W-1):
            for i in range(H):
                if S[i][j]+S[i][j+1]>K:
                    tmp+=1
                    break
            else:
                for i in range(H):
                    S[i][j+1] += S[i][j]

        ans = min(ans, tmp)

    print(ans)

if __name__ == '__main__':
    main()

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

int main(){
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	ll ret=0;
	if(k<a)cout<<k<<endl;
	else{
		k-=a;
		ret+=a;
		if(k<b)cout<<ret<<endl;
		else{
			k-=b;
			ret-=k;
			cout<<ret<<endl;
	
		}
	}
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int a[109];
  cin>>n;
  int sum=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  int p=sum/n;
  int x=0,y=0;
  for(int i=0;i<n;i++){
    x+=(a[i]-p)*(a[i]-p);
  }
  p++;
  for(int i=0;i<n;i++){
    y+=(a[i]-p)*(a[i]-p);
  }
  cout<<min(x,y)<<endl;
  return(0);
}


Measured memory_bytes: 256