akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
 
#define lli long long int
#define endl "\n"
 
using namespace std;
 
typedef long long int LLI;
typedef double DB;
 
void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
}
 
 
bool comparator(pair<lli,lli> a,pair<lli,lli> b)
{
    if(a.first>b.first)
        return true;
    else if (a.first==b.second)
    {
        if(a.second>=b.second)
            return false;
        return true;
    }
    return false;
}
 
int mods(int x)
{
    if(x>0)
        return x;
    return -x;
}
 
lli gcd(lli a,lli b)
{
    return __gcd(a,b);
}
 
lli lcm(lli x,lli y,lli z)
{
    lli j=gcd(x,y);
    lli k=gcd(y*x/j,z);
    return (((x*y)/j)*z)/k;
} 

int arr[3][3];
bool vis[3][3]={0};

int main()
{
    fastio();
    for(int i=0;i<3;++i) for(int j=0;j<3;j++) cin>>arr[i][j];
    int n,k; cin>>n; 
    for(int i=0;i<n;i++) 
    {
        cin>>k;
        for(int i=0;i<3;++i) 
        {
            for(int j=0;j<3;j++) 
            {
                if(k==arr[i][j]) vis[i][j]=1;
            }
        }
    }
    for(int i=0;i<3;i++)
    {
        if((vis[i][1] && vis[i][0] && vis[i][2])||(vis[0][i] && vis[1][i] && vis[2][i]))
        {
            cout<<"Yes"<<endl; return 0;
        }
    }
    if((vis[1][1] && vis[0][0] && vis[2][2])||(vis[0][2] && vis[1][1] && vis[2][0]))
    {
        cout<<"Yes"<<endl;
        return 0;
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]

#[allow(unused_macros)]
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)*} };}
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, 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") }; }

fn main() {
    input!{
        N: u32,
        A: u32,
        B: u32,
    }
    println!(
        "{}",
        (1..N + 1)
            .into_iter()
            .filter(|&i| {
                let mut buf = 0;
                let mut j = i;
                while j != 0 {
                    buf += j % 10;
                    j /= 10;
                }
                A <= buf && buf <= B
            }).sum::<u32>()
    );
}

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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int n;
    cin>> n;

    ll s[n], a[n], sum= 0;

    cin>> a[0];
    s[0]= a[0];
    for(int i=1; i<n; i++)
    {
        cin>> a[i];
        s[i]= (a[i] % MOD+ s[i-1]% MOD) % MOD;
    }

    for(int i= n-1; i>0; i--)
        sum += (((a[i] % MOD)* (s[i-1] % MOD) )% MOD);

    cout << sum % MOD << '\n';

    return 0;
}




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

using ll = long long;
using ld = long double;
using vi = vector<int>;

#define rep(i, a, b) for(auto i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back

struct edge{int to;};
using graph = vector<vector<edge>>;

auto maxx(auto& a, auto b){a = max(a, b);}

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

  int n;
  cin >> n;
  auto a = vector<vi>(n, vi(3));
  trav(row, a) trav(i, row)
    cin >> i;
  vector<vi> dp(n + 1, vi(3, -1));
  trav(i, dp[0]) i = 0;
  rep(i, 0, n) {
    rep(p, 0, 3) {
      rep(choice, 0, 3) {
	if (choice == p) continue;
	maxx(dp[i + 1][choice], dp[i][p] + a[i][choice]);
      }
    }
  }
  auto best = -1;
  trav(i, dp[n])
    maxx(best, i);
  cout << best << '\n';
}


Measured memory_bytes: 11264
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int n,i;
	unsigned long long kane=100000;
	cin>>n;
	for(i=0;i<n;i++){
		kane=kane*1.05;
	kane=((kane+999)/1000)*1000;
	}
	cout<<kane<<endl;
	return 0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
long long kaijo(long long n){
  long long mon=1;
  while(n){
    mon*=n;
    mon%=1000000007;
    n--;
  }
  return mon;
}

int main(){
  long long a,b,ans;
  cin>>a>>b;
  if(abs(a-b)>1) ans=0;
  else if(a==b) ans=2*kaijo(a)*kaijo(b);
  else ans=kaijo(a)*kaijo(b);
  cout<<ans%1000000007<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define umii            unordered_map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define rep(i,st,end)   for(int i=st;i<end;i++)
#define w(x)            int x; cin>>x; while(x--)
//mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void s_g_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
	s_g_c();
	int a;
	float b;
	cin >> a >> b;
	int d = b * 100 + 0.1;
	int c = a * d / 100;
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;

int main() {
  int N,M;
  cin >> N;
  string a;
  vector<string> s,t;
  for (size_t i = 0; i < N; i++) {
    /* code */
    cin >> a;
    s.push_back(a);
  }
  cin >> M;
  for (size_t i = 0; i < M; i++) {
    /* code */
    cin >> a;
    t.push_back(a);
  }
  int num = 0;
  for (size_t i = 0; i < N; i++) {
    string temp = s[i];
    int g = 0;
    for (size_t j = 0; j < N; j++) {
      if (s[i] == s[j]) g++;
    }
    for (size_t l = 0; l < M; l++) {
      if (s[i] == t[l]) g--;
    }
    if (num < g) num = g;
  }

  cout << num << endl;
}


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

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

using namespace std;

struct Data {
  int h,m,time;
  bool operator < ( const Data& data ) const { return time < data.time; }
  bool operator == ( const Data& data ) const { return time == data.time; }
};

int main(){
  vector<Data> vec;
  int N,M;
  cin >> N;
  rep(_,N) {
    int h,m;
    cin >> h >> m;
    vec.push_back((Data){h,m,h*60+m});
  }
  cin >> M;
  rep(_,M){
    int h,m;
    cin >> h >> m;
    vec.push_back((Data){h,m,h*60+m});
  }
  sort(vec.begin(),vec.end());
  vec.erase(unique(vec.begin(),vec.end()),vec.end());
  rep(i,vec.size()) {
    if( i ) printf(" ");
    printf("%d:%02d",vec[i].h,vec[i].m);
  } puts("");
  return 0;
}

Measured memory_bytes: 1220
def examC():
    N = I()
    St = [S() for _ in range(N)]
    d = [[0]*N for _ in range(26)]
    ans = ""
    for i in range(N):
        for s in St[i]:
            d[ord(s)-97][i] += 1
    for i in range(26):
        cur = min(d[i])
        for _ in range(cur):
            ans = ans + chr(i+97)
    print(ans)


import sys
import copy
import bisect
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()


Measured memory_bytes: 38896
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits.h>

using namespace std;

typedef long long ll;


int main(void) {
    
    
    ll N;
    ll m = LLONG_MAX;
    ll max = 0;
    vector<ll> a;
    
    cin >> N;
    
    for (ll i = 0; i < N; ++i) {
        
        ll tmp; cin >> tmp;
        
        max += tmp;
        
        a.push_back(max);
        
    }
    
    for (ll i = 0; i < N - 1; ++i) {
        
        m = min(m, abs(a[i] - (max - a[i])));
        
    }
    
    
    cout << m << endl;
    
    
    return 0;
    
}





















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

using namespace std;

#define prec(n) fixed << setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int>>
#define PI 3.14159265
#define pb push_back
#define bits(n) __builtin_popcount(n)
#define ll long long int

void solve()
{
    char a,b;
    cin>>a>>b;
    string a1="",b1="";
    for(int i=0;i<(int)(b-48);i++)
    {
        a1+=a;
    }
    for(int i=0;i<(int)(a-48);i++)
    {
        b1+=b;
    }
    if(a1>b1)
    cout<<b1;
    else
    {
        cout<<a1;
    }
    

    
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input1.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output1.txt", "w", stdout);
#endif

    int t=1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

ll N, A, B, C, D;
string S;

void solve() {
	cin >> N >> A >> B >> C >> D >> S;

	bool change = false;
	if (C > D) change = true;

	bool ans = true;

	ll pos = A - 1;
	while (1) {
		if (S[pos] == '#' && S[pos + 1] == '#') {
			ans = false;
			break;
		}
		if (pos == C - 2) break;
		pos++;
	}

	pos = B - 1;
	while (1) {
		if (S[pos] == '#' && S[pos + 1] == '#') {
			ans = false;
			break;
		}
		if (pos == D - 2) break;
		pos++;
	}

	bool ans2 = false;
	pos = B - 2;
	while (1) {
		if (S[pos] == '.' && S[pos + 1] == '.' && S[pos + 2] == '.') {
			ans2 = true;
			break;
		}
		if (pos == D - 2) break;
		pos++;
	}
	//if (S[B - 2] == '.' && S[B - 1] == '.' && S[B] == '.') ans2 = true;
	//if (S[D-2]=='.' && S[D-1]=='.' && S[D]-1)

	if (ans && (change ? ans2 : true)) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

}

int main() {
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define INF = numeric_limits<long long>::max();
#define intf int_fast64_t
int main(){
    string s;
    intf n=0,m=0;

    cin >>s;
    for(int i=0;i<s.length();i++){
        n+= s[i] - '0';
        m += (s[i]-'0')*pow(10,s.length()-1-i);
    }

    if(m%n==0){
        cout << "Yes"<<endl;
    }else{
        cout << "No" <<endl;
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6+7;
const ll mod = 1e9+7;
const int sz = 62;
#define afdafafafdafaf y1;
int n,m;
char ch[maxn];
int ar[maxn], site[maxn];

int aa[maxn];
int main()
{
    scanf("%d", &n);
    vector<int> cur;
    multiset<int> s;
    for(int i=1;i<=(1<<n);i++){
        scanf("%d", ar+i);
        s.insert(-ar[i]);
    }
    cur.push_back(*s.begin());
    s.erase(*s.begin());
    for(int i=1;i<=n;i++){
        vector<int> nex = cur;
        for(int x : cur){
            auto it = s.upper_bound(x);
            if(it==s.end()){
                printf("No\n");
                return 0;
            }
            nex.push_back(*it);
            s.erase(it);
        }
        cur = nex;
    }
    printf("Yes\n");

    return 0;
}


Measured memory_bytes: 18672
#include<cstdio>
using namespace std;
int main(){
    int n;
    bool flag=1;
    scanf("%d",&n);
    for(int i=0;i<=14;i++){
        int tmp=n-7*i;
        if(tmp<0) break;
        if(tmp%4==0){
            printf("Yes\n");
            flag=0;
            break;
        }
    }
    if(flag)
    printf("No\n");
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N, A, B;
  std::cin >> N >> A >> B;
  std::vector< ll > vx(N, 0LL);
  for (ll i = 0; i < N; i++) {
    std::cin >> vx[i];
  }

  ll ans = 0LL;
  for (ll i = 1; i < N; i++) {
    ll dist = vx[i] - vx[i-1];
    ans += std::min(dist * A, B);
  }

  print(ans);
  return 0;
}


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

int main(){
    int n,v,sum=0;
    cin >> n;
    v = n;
    while(n != 0){
        sum += n%10;
        n/=10;
    }
    if(v%sum==0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;    
}

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

#define N 100

int compare1(const void *a, const void *b) {
	char ca = *(char *) a;
	char cb = *(char *) b;

	return ca - cb;
}

int compare2(const void *a, const void *b) {
	char ca = *(char *) a;
	char cb = *(char *) b;

	return cb - ca;
}

int main() {
	static char s[N + 1], t[N + 1];
	int n, m;

	scanf("%s%s", s, t);
	n = strlen(s);
	m = strlen(t);
	qsort(s, n, sizeof *s, compare1);
	qsort(t, m, sizeof *t, compare2);
	printf(strcmp(s, t) < 0 ? "Yes\n" : "No\n");
	return 0;
}


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

int main(){
    int h,w;
    while(1){
        cin>>h>>w;
        if(h==0&&w==0)break;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(i==0||j==0||i==h-1||j==w-1)cout<<"#";
                else cout<<".";
            }cout<<endl;
        }cout<<endl;
    }return 0;
}


Measured memory_bytes: 3080
l=input()
n=len(l)
mod=10**9+7
dp=[[0,0]for _ in range(n)]
dp[0]=[2,1]
for i in range(1,n):
  if l[i]=="1":
    dp[i][0]=dp[i-1][0]*2
    dp[i][1]=dp[i-1][1]*3+dp[i-1][0]
  else:
    dp[i][0]=dp[i-1][0]
    dp[i][1]=dp[i-1][1]*3
  dp[i][0]%=mod
  dp[i][1]%=mod
print(sum(dp[n-1])%mod)

Measured memory_bytes: 23988
import java.util.HashMap;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String[] str_array = new String[n];
    long[] cost_array = new long[n];
    PriorityQueue<Pair> queue = new PriorityQueue<>();
    for(int i = 0; i < n; i++){
      str_array[i] = sc.next();
      cost_array[i] = sc.nextLong();
      queue.add(new Pair(cost_array[i], str_array[i]));
    }
    sc.close();
    long ans = Long.MAX_VALUE;
    //無限ループ対応
    HashMap<String, Long> memo = new HashMap<>();

    while (!queue.isEmpty()){
      Pair p = queue.poll();
      if(p.cost > ans) {
        continue;
      }
      if(memo.containsKey(p.str)){
        if(memo.get(p.str) < p.cost){
          continue;
        }
      } else {
        memo.put(p.str, p.cost);
      }
      if(isPalindrome(p.str)){
        ans = Math.min(ans, p.cost);
        continue;
      }
      for(int i = 0; i < n; i++){
        String next = nextStatus(p.str, str_array[i]);
        if(next != null){
          queue.add(new Pair(p.cost + cost_array[i], next));
        }
      }
    }

    System.out.println(ans != Long.MAX_VALUE ? ans : -1);
  }

  static String nextStatus(String cur, String next){
    String left_str, right_str;
    if(cur.endsWith("_")){
      left_str = next;
      right_str = cur.substring(0, cur.length() - 1);
    } else if(cur.startsWith("_")){
      left_str = cur.substring(1);
      right_str = next;
    } else {
      left_str = cur;
      right_str = next;
    }
    int len = Math.min(left_str.length(), right_str.length());
    int idx = 0;
    while(idx < len){
      if(left_str.charAt(idx) != right_str.charAt(right_str.length() - 1 - idx)){
        return null;
      }
      idx++;
    }
    if(left_str.length() > right_str.length()){
      return "_" + left_str.substring(len);
    } else if(left_str.length() < right_str.length()){
      return right_str.substring(0, right_str.length() - len) + "_";
    } else {
      return "";
    }
  }

  static boolean isPalindrome(String str){
    str = str.replaceAll("_", "");
    if("".equals(str) || str.length() == 1){
      return true;
    }
    int left = 0;
    int right = str.length() - 1;
    while(left < right){
      if(str.charAt(left) != str.charAt(right)){
        return false;
      }
      left++;
      right--;
    }
    return true;
  }
}
class Pair implements Comparable<Pair> {
  long cost;
  String str;
  Pair(long cost, String str){
    this.cost = cost;
    this.str = str;
  }
  @Override
  public int compareTo(Pair o) {
    return this.cost != o.cost ? Long.compare(this.cost, o.cost) : this.str.compareTo(str);
  }
}


Measured memory_bytes: 43556
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        long N = s.nextLong(),K = s.nextLong();
        System.out.println(GCD(N, K));
    }
    private static long GCD(long a, long b) {
        long val = a%b;
        return Math.min(val, b-val);
    }
}

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

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

    vector<int> a(n);
    int l = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] > l) {
            l = a[i];
        }
    }
    int output = 0;
    if (l % 2 == 0) {
        for (int i = 0; i < n; i++) {
            if (abs(l / 2 - a[i]) < abs(l / 2 - output) && a[i] != l) {
                output = a[i];
            }
        }
    } else {
        for (int i = 0; i < n; i++) {
            if (abs(l / 2 + 1 - a[i]) < abs(l / 2 + 1 - output) && a[i] != l) {
                output = a[i];
            }
        }
    }

    cout << l << " " << output << endl;

    return 0;
}


Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ld long double
#define dd double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;
typedef vector<pll> vplll;
ll mod = 1e9+7;
const ld PI = 2 * acos(0.0);
const vector<ll> dx = {1, -1, 0, 0};
const vector<ll> dy = {0, 0, 1, -1};
#define round(x, y) ((x + y - 1) / y)
#define ce(x, y) ((x + y - 1) / y)
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define lcm(x, y) ((x) * (y) / __gcd(x, y))
#define len(x) (ll) x.length()
#define sq(x) ((x) * (x))
#define cb(x) ((x) * (x) * (x))
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,t,n,m,k,q; 
    t = 1;
    // cin>>t;
    while(t--)
    {
    	cin>>n;
    	ll fr[n+2];
    	memset(fr,0,sizeof(fr));
    	for(int i=0;i<n-1;i++)
    	{
    		cin>>a;
    		fr[a]++;
    	}
    	for(int i=1;i<=n;i++)
    	{
    		cout<<fr[i]<<endl;
    	}
    }
    return 0;
}

Measured memory_bytes: 5220
// ConsoleApplication106.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<set>
#include<map>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;

int main()
{
	int h=0,ii=0,la = 0;
	string a, s, b, c;
	cin >> s;
	if (s.length() == 1)
	{		cout << "No" << endl;
	return 0;
	}
	for (int i = 0; i < s.length(); i += 2)
	{
		if (s[i] == 'h' && s[i + 1] == 'i')
		{
			la = 1;
		}
	}
	for (int i = 0; i < s.length(); i ++)
	{
		if (s[i] == 'h')
		{
			h++;
		}
		else
		{
			ii++;
		}
	}
	if (h != ii)
	{
		la = 0;
	}
	if (la == 0)
	{
		cout << "No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
	}
}


Measured memory_bytes: 256
Public Class Main
    Public Shared Sub Main(ByVal args() As String)

        Dim tmp() As String
        tmp = Split(Console.ReadLine())
        Dim S, T, U As String
        Dim a, b As Integer
        S = tmp(0) : T = tmp(1)
        tmp = Split(Console.ReadLine())
        a = tmp(0) : b = tmp(1)
        U = Console.ReadLine()

        If U.Contains(S) Then
            a -= 1
        Else
            b -= 1
        End If

        Console.WriteLine(a.ToString & " " & b.ToString)

    End Sub
End Class


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

int main() {
    int N;
    int t[110000], x[110000], y[110000];
    cin >> N;
    t[0] = x[0] = y[0] = 0;
    for  (int i = 0; i < N; i++) cin >> t[i+1] >> x[i+1] >> y[i+1];

    bool can = true;
    for (int i = 0; i < N; i++) {
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
        if (dt < dist) can = false;
        if (dist % 2 != dt % 2) can = false;
    }

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

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

int main() {
    size_t N, K;
    cin >> N >> K;
    vector<size_t> A(N+1);
    for (size_t i = 1; i <= N; ++i) {
        cin >> A[i];
    }
    for (size_t i = K+1; i <= N; ++i) {
        if (A[i] > A[i-K]) {
            cout << "Yes" << endl;
        }
        else {cout << "No" << endl;}
    }
    return 0;
}

Measured memory_bytes: 4848
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(a) for(int k=head[a];k;k=e[k].ne)
#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef double db;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ll,ll> pa;
const int N=1e6+5,M=5e3+5,INF=1e9,mod=998244353;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
char A[N],B[N];
int n,lx[N],rx[N],ans,mx[N];
void gao(){
	re(i,0,n){
		lx[i]=rx[i]=0;
		while(B[(i+n+lx[i])%n]!='1')lx[i]--;
		while(B[(i+rx[i])%n]!='1')rx[i]++;
	}re(pos,0,n){
		re(i,0,n)mx[i]=0;int cd=0;
		re(i,0,n)if(A[i]!=B[(i+pos)%n])gmax(mx[-lx[i]],rx[i]-pos),cd++;
		int smx=0,len=1e9;
		repd(i,n-1,0)gmin(len,smx+i),gmax(smx,mx[i]);
		gmin(ans,len+len+pos+cd);
	}
}
int main(){
	scanf("%s%s",A,B);n=strlen(A);ans=1e9;
	int exa=0,exb=0;
	re(i,0,n){
		if(A[i]=='1')exa=1;
		if(B[i]=='1')exb=1;
	}
	if(!exb){
		if(exa)puts("-1");else puts("0");
		return 0;
	}
	gao();
	reverse(A,A+n);reverse(B,B+n);
	gao();
	cout<<ans<<endl;
}

Measured memory_bytes: 6400
gets
f = gets.split.map(&:to_i)
m = gets.split.map(&:to_i)
c = []
while a = gets
  c << a.split.map(&:to_i)
end
ans = f.min + m.min
c.each{|i|
  cp = f[i[0] - 1] + m[i[1] - 1] - i[2]
  ans = [ans, cp].min
}
puts ans

Measured memory_bytes: 18972
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  string S[N];
  ll M = 0;
  ll A = 0;
  ll R = 0;
  ll C = 0;
  ll H = 0;
  for (int i = 0; i < N; i++) {
    cin >> S[i];
    if (S[i][0] == 'M') {
      M++;
    } else if (S[i][0] == 'A') {
      A++;
    } else if (S[i][0] == 'R') {
      R++;
    } else if (S[i][0] == 'C') {
      C++;
    } else if (S[i][0] == 'H') {
      H++;
    }
  }
  ll ans = M*A*R + M*A*C + M*A*H + M*R*C + M*R*H + M*C*H + A*R*C + A*R*H + A*C*H + R*C*H;
  cout << ans << endl;
  return 0;
}


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

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

 	if((a*b - c*d) >= 0)
 		cout <<a*b <<endl;
 	else
 		cout << c*d <<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <queue>
#include <math.h>
using namespace std;
typedef long long int ll;

int d[200200];
vector<int> g[200200];

void dfs(int s){
	d[s]=1;
	for(int t:g[s]){
		dfs(t);
		d[s]+=d[t];
	}
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	for(int i=1;i<n;i++){
		int a; cin >> a;
		a--;
		//g[a].push_back(i);
		d[a]++;
	}
	//dfs(0);
	for(int i=0;i<n;i++){
		printf("%d\n",d[i] );
	}
}

Measured memory_bytes: 9144
n, m = map(int, input().split())
l = list(map(int, input().split()))

l = [0] + l
from itertools import accumulate
cum =list(accumulate(l))
cum = [c%m for c in cum]

d = {}
ans = 0
for i in range(n+1):
  if cum[i] not in d:
    d[cum[i]] = 1
  else:
    ans += d[cum[i]]
    d[cum[i]] += 1
print(ans)

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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


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

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


signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int n;
    cin >> n;
    vector<pair<int,int>> a;
    for(int i = 0; i < n; ++i){
        int x;
        cin >> x;
        a.emplace_back(x, i + 1);
    }
    sort(a.begin(), a.end());
    cout << a[0].second << endl;
}



Measured memory_bytes: 3816
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int n;
string a[11111];
int main(){
	cin>>n;
	for(int i=0; i<=n; i++)
		cin>>a[i];
	int A=0,B=0;
	for(int i=0; i<n; i++){
		string in = "", ax = "";
		for(int j=0; j<a[i].length(); j++)
			if(a[i][j] == '?'){
				in += 'a';
				ax += 'z';
			}else{
				in += a[i][j];
				ax += a[i][j];
			}
		if(in < a[n] && ax < a[n])
			A++;
		else
		if(in > a[n] && ax > a[n])
			B++;
	}
	++n;
	for(int i=A+1; i<=n-B; i++)
		printf("%d%c",i,i<n-B?' ':'\n');
	return 0;
}


Measured memory_bytes: 896
from itertools import combinations, permutations

N, M, R = [int(_) for _ in input().split()]
r_list = [int(_) for _ in input().split()]

INF = 10 ** 9
G = [[INF] * (N + 1) for _ in range(N + 1)]
for i in range(M):
    a, b, c = [int(_) for _ in input().split()]
    G[a - 1][b - 1] = c
    G[b - 1][a - 1] = c

for k in range(N):
    for i in range(N):
        for j in range(N):
            G[i][j] = min(G[i][j], G[i][k] + G[k][j])

ans = INF * R
for p in permutations(range(R)):
    val = 0
    for i in range(R - 1):
        c = r_list[p[i]]-1
        n = r_list[p[i + 1]]-1
        val += G[c][n]
    ans = min(ans, val)
print(ans)


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

int main(){
  string s;
  cin>>s;
  for(int i=0;i<s.size();i++){
    s[i]-=3;
    if(s[i]<'A')s[i]+=26;
  }
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 3188
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {

        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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


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

fn main() {
    input! {
        a: i64,
        b: i64,
        k: usize,
    }
    let mut a = a;
    let mut b = b;
    for i in 1..k + 1 {
        if i % 2 == 1 {
            if a % 2 == 1 {
                a = a - 1;
            }
            b += a / 2;
            a = a / 2;
        } else {
            if b % 2 == 1 {
                b = b - 1;
            }
            a += b / 2;
            b = b / 2;
        }
    }
    println!("{} {}", a, b);
}


Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
	int N, ans = 0;
	string S;
	cin >> N >> S;
	for (string i = "1000"; stoi(i) < 2000; i = to_string(stoi(i) + 1)) {
		vector<bool> a(3);
		for (char& j : S) {
			if (!a[0]) {
				if (i[1] == j) a[0] = true;
			}
			else if (!a[1] & a[0]) {
				if (i[2] == j) a[1] = true;
			}
			else if (!a[2] & a[0] & a[1]) {
				if (i[3] == j) a[2] = true;
			}
		}
		if (all_of(a.begin(), a.end(), [](bool a) { return a; })) ans++;
	}
	cout << ans;
}

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

int main(){
    int n,m;
    vector<int> mp[100005];
    vector<int> ans(100005,-1);
    cin>>n>>m;
    vector<int> dist(n,INF);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--;b--;
        mp[a].push_back(b);
        mp[b].push_back(a);
    }
    
    dist[0]=0;
    ans[0]=0;
    queue<int> que;
    que.push(0);
    while(!que.empty()){
        int q=que.front();que.pop();
        for(auto u:mp[q]){
            if(dist[u]!=INF) continue;
            dist[u]=dist[q]+1;
            que.push(u);
            ans[u]=q;
        }
    }
    cout<<"Yes"<<endl;
    for(int i=1;i<n;i++) cout<<ans[i]+1<<endl;
}

Measured memory_bytes: 10612
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
int n, ma, mb;
vector<int> a, b;
vector<int> c;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>ma>>mb;
     int dp[401][401][41];
    for (int i = 0; i < n; i++)
    {
        int temp, temp1, temp2;
        cin >> temp>>temp1>>temp2;
        a.push_back(temp);
        b.push_back(temp1);
        c.push_back(temp2);
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<=400;j++){
            for(int k=0;k<=400;k++){
                dp[j][k][i]=0;
            }
        }
    }
    dp[a[0]][b[0]][0]=c[0];
    for(int i=1;i<n;i++){
        for(int j=0;j<=400;j++){
            for(int k=0;k<=400;k++){
                if(j-a[i]<0||k-b[i]<0){
                    dp[j][k][i]=dp[j][k][i-1];
                }
                else if(dp[j-a[i]][k-b[i]][i-1]==0&&j-a[i]==0&&k-b[i]==0){
                    if(dp[j][k][i-1]==0){
                        dp[j][k][i]=dp[j-a[i]][k-b[i]][i-1]+c[i];
                    }
                    else
                    dp[j][k][i]=min(dp[j][k][i-1],dp[j-a[i]][k-b[i]][i-1]+c[i]);
                }
              	else if(dp[j-a[i]][k-b[i]][i-1]==0){
                  dp[j][k][i]=dp[j][k][i-1];
                }
                else{
                    if(dp[j][k][i-1]==0){
                        dp[j][k][i]=dp[j-a[i]][k-b[i]][i-1]+c[i];
                    }
                    else
                    dp[j][k][i]=min(dp[j][k][i-1],dp[j-a[i]][k-b[i]][i-1]+c[i]);
                }
            }
        }
    }
    int i=1;
    int ans=INF;
    while(true){
        if(ma*i>400||mb*i>400){
            if(ans!=INF){
                break;
            }
            ans=-1;
            break;
        }
        if(dp[ma*i][mb*i][n-1]!=0){
            ans=min(ans,dp[ma*i][mb*i][n-1]);
        }
      i++;
    }
    cout<<ans<<"\n";
}





Measured memory_bytes: 25984
#include<bits/stdc++.h>
using namespace std ;
#define rep(i,a,n) for(int i =a;i<n;i++)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);

int main(){
	ios;
	int a,b,c=0,n=1;
	cin>>a>>b;
	while(n<b)
	{n+=(a-1);
	 c++;
	}
	cout<<c<<endl;
	return 0;
	
}

Measured memory_bytes: 256
N,T = map(int,input().split())
A = list(map(int,input().split()))
cnt = 0
cur = 0
for i in range(1,N):
    if A[i]-A[i-1]>T:
        cnt += A[i-1]-cur+T
        cur = A[i]
cnt += A[N-1]+T-cur
print(cnt)

Measured memory_bytes: 103836
$,=$";$k=(4-($K=<>)%4)%4;print$K-1?($n=$K+3>>2<<1,map{map{($t=($'+$_)%$n)+1+($'%2?$n-$k:$t<$n-$k?0:$K-$n)}//..$n}1..$n):(1,1)

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

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    
    ll ans = (a+b*(n-1)) - (a*(n-1)+b) + 1;
    cout << max(ans, 0LL) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

int n, q;
string s;
int l, r;
int ans[100005];

int main(){
  cin >> n >> q;
  cin >> s;
  s[n] = '0';
  for(int i = 0; i < n; ++i){
    ans[i] = 0;
  }
  for(int i = 0; i < n; ++i){
    if(s[i] == 'A' && s[i + 1] == 'C'){
      ans[i + 1] = ans[i] + 1;
      //cout << ans[i + 1] << endl;
    }else{
      ans[i + 1] = ans[i];
    }
  }
  //cout << ans[n - 1] << endl;
  for(int i = 0; i < q; ++i){
    cin >> l >> r;
    cout << ans[r - 1] - ans[l - 1] << endl;
  }
}

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

using namespace std;

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

    string s;
    string t ="CODEFESTIVAL2016";

    int res = 0;

    cin >> s;

    for(int i=0;i<16;i++)
    {
    	if(s[i]!=t[i])
    	{
    		res++;
    	}
    }

    cout << res << '\n';
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define ll long long
using namespace std;
ll a[3001];
ll dp[3001][3001];
ll sum[3001][3001];
int main() {
	int n;
	cin>>n;
	ll S = 0;
	for(int i=0;i<n;i++) {
		cin>>a[i];
		dp[i][i] = a[i];
		sum[i][i] = a[i];
	}
	for(int len = 2; len <= n; len++) {
		for(int i = 0; i + len - 1 < n; i++) {
			int j = i + len - 1;
			dp[i][j] = max(a[i] + sum[i+1][j] - dp[i+1][j],
						 a[j] + sum[i][j-1] - dp[i][j-1]);
			sum[i][j] = sum[i][j-1] + sum[j][j];
		}
	}
	cout<<2* dp[0][n-1] - sum[0][n-1] <<endl;
	return 0;
}


Measured memory_bytes: 139776
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <map>
#include <cstdlib>
#include <istream>
#include <set>
#define rep0(i,n) for (long long int i = 0; i <= (n); ++i)
#define rep1(i,n) for (long long int i = 1; i <= (n); ++i)
#define REP(a,b) for (long long int i = a; i <= (b); ++i) 
using namespace std;
typedef long long ll;
int main() {
	int n;
	cin >> n;
	ll ans = 0;
	vector<ll>v(n);
	vector<ll>c(n);
	rep0(i, n - 1)cin >> v[i];
	rep0(j, n - 1)cin >> c[j];
	rep0(k, n - 1) {
		if (v[k] - c[k] > 0) {
			ans += v[k] - c[k];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = 1e9 + 1;

int main() {
  int x;
  cin >> x;
  int sum = x/500 * 1000;
  x -= x/500 * 500;
  sum += x/5 * 5;

  cout << sum << endl;
}

Measured memory_bytes: 3624
fun main(args: Array<String>) {
    val N = nextInt()
    val XY = Array<Pair<Int, Int>>(N) { listOfIntToPair(listOfInt(0)) }
    val A = Array<Int>(N) { 0 }
    fun F(n: Int): Int = if (n > 1) n * F(n - 1) else 1
    fun D(n: Int, m: Int): Double = Math.sqrt(Math.pow((XY[n].first - XY[m].first).toDouble(), 2.0) + Math.pow((XY[n].second - XY[m].second).toDouble(), 2.0))
    var sum: Double = 0.0
    fun P(n: Int) {
        if (n == N) {
            for (m in 0 until N-1) {
                sum += D(A[m], A[m + 1])
            }
        } else {
            for (m in 0 until N) {
                var f = true
                for (x in 0 until n) if (A[x] == m) f = false
                if (f) {
                    A[n] = m
                    P(n + 1)
                }
            }
        }
    }
    P(0)
    var ans = sum / F(N).toDouble()
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }
fun listOfIntToPair(p: List<Int>): Pair<Int, Int> = Pair(p[0], p[1])

Measured memory_bytes: 47104
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define FOR(x, b, e) for(int x=(b); x<=(e); ++x)
#define FORD(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define ALL(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	ios_base::sync_with_stdio(false);
int k,a,b;
cin >> k >> a >> b;
	FOR(i, a, b) {
		if (i % k == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}
	cout <<"NG" << endl;;

}

Measured memory_bytes: 3104
from operator import itemgetter

def main():
    N,M = map(int,input().split())
    ABC = [list(map(int,input().split())) + list(map(int,input().split())) for _ in range(M)]
    dp = [float("inf")]*(2**N)
    S = [sum([2**(c - 1) for c in abc[2:]]) for abc in ABC]
    dp[0] = 0
    for i in range(M):
        for bit in range(2**N):
            result = int(bit | S[i])
            dp[result] = min(dp[result],dp[bit] + ABC[i][0])        
    print(dp[2**N - 1] if dp[2**N - 1] < float("inf") else -1)
    return

if __name__ == "__main__":
    main()

Measured memory_bytes: 46568
#include <set>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

const int N=100005; 

using namespace std;

int n,m,t,a[N]; 
long long ans,cnt,mx; 

struct node{
	int c,lim;
	node(){}
	node(int _c,int _lim){ c=_c; lim=_lim; }
	friend bool operator<(node A,node B){
		return A.lim>B.lim;
	}
}; 

node ys[N<<1]; int num; 
vector<int> list[N]; 

multiset<int> s;
multiset<int>::iterator it;  

int main(){
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; ++i) scanf("%d",&a[i]);
	ans=0; 
	for(int i=1; i<n; ++i){
		if(a[i]==a[i+1]) continue; 
		if(a[i]<a[i+1]) ans+=(a[i+1]-a[i]);
		else ans+=(m-a[i]+a[i+1]); 
	}
	for(int i=1; i<n; ++i){
		if(a[i]==a[i+1]) continue; 
		else{
			if(a[i]<a[i+1]) ys[++num]=node(-a[i]-1,a[i+1]); 
			else{
				ys[++num]=node(-a[i]-1,m); 
				list[a[i]].push_back(-a[i]-1); 
				ys[++num]=node(-1+(m-a[i]),a[i+1]); 
			}
		}
	}
	sort(ys+1,ys+num+1); 
	t=m; 
	cnt=mx=0; 
	for(int i=1; i<=num; ++i){
		for(; t>ys[i].lim && t>0; --t){
			int siz=list[t].size();
			for(int j=0; j<siz; ++j){
				it=s.find(list[t][j]); 
				if(it!=s.end()) cnt-=(*it),s.erase(it);  
			}
		}
		while(1){
			it=s.begin();
			if(it==s.end()) break; 
			//printf("%d\n",(*it));  
			if((*it)<=-ys[i].lim) cnt-=(*it),s.erase(it);  
			else break; 
		}
		cnt+=ys[i].c; 
		s.insert(ys[i].c); 
		mx=max(mx,cnt+(long long)(s.size()*ys[i].lim)); 
	}
	printf("%lld\n",ans-mx); 
	return 0; 
}

Measured memory_bytes: 11648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int n;
    cin >> n;
    VI p(100003, 0);
    int in;
    FOR(i, 0, n) {
        cin >> in;
        p[in]++;
        p[in + 1]++;
        p[in + 2]++;
    }
    SORT(p);
    cout << p[100002] << "\n";
}

Measured memory_bytes: 640
import sys

N=int(input())
edge=[[] for i in range(N)]
for i in range(N-1):
    a,b=map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)

ans=(10**15,10**15)

root=-1
depth=[0]*N
Mdata=[0]*100

def dfs(v,pv):
    for nv in edge[v]:
        if nv!=pv:
            depth[nv]=depth[v]+1
            Mdata[depth[nv]]=max(Mdata[depth[nv]],len(edge[nv])-1)
            dfs(nv,v)

for i in range(N):
    depth=[0]*N
    Mdata=[0]*100
    Mdata[0]=len(edge[i])
    dfs(i,-1)
    tempc=max(depth)+1
    res=1
    for j in range(N):
        if Mdata[j]!=0:
            res*=Mdata[j]
        else:
            break
    ans=min(ans,(tempc,res))

#print(ans)

for i in range(N):
    for j in edge[i]:
        depth=[0]*N
        Mdata=[0]*100
        depth[i]=1
        depth[j]=1
        Mdata[1]=max(len(edge[i]),len(edge[j]))-1
        Mdata[0]=2
        dfs(i,j)
        dfs(j,i)
        tempc=max(depth)
        res=1
        for k in range(N):
            if Mdata[k]!=0:
                res*=Mdata[k]
            else:
                break
        ans=min(ans,(tempc,res))

print(*ans)

Measured memory_bytes: 9336