akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := ReadInt()
	T := ReadInts(N)
	v := 1
	for i := 0; i < N; i++ {
		v = LCM(v, T[i])
	}
	fmt.Println(v)
}

func LCM(a, b int) int {
	return a / GCD(a, b) * b
}
func GCD(a, b int) int {
	if b == 0 {
		return a
	}
	return GCD(b, a%b)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1844
#include<stdio.h>
#define A 200000
int main(){
	
    int n,i,j,k;
    int R[A];
    
	/* nを格納 */
    scanf("%d",&n);
	
	/* R[i]をn個格納 */
    for(i=0;i<n;i++){
        scanf("%d",&R[i]);
    }
     
    for(i=0;i<n-1;i++){
    	
        if(i==0||j>R[i]){/* 最小値を探し、jに格納 */
            j=R[i];
        }
        if(i==0||k<R[i+1]-j){/* 差の値の大きい方を格納 */
            k=R[i+1]-j;
        }
    }
	
    printf("%d\n",k);/* 最大の差を格納 */
     
    return 0;
}


Measured memory_bytes: 2568
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	int n;
	cin >> n;
	cout << "ABC" << n << endl;
	
	
	return 0;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
#define randome_generate srand(std::chrono::high_resolution_clock::now().time_since_epoch().count())
using namespace std;
char grid[1000][1000];
int n,m,k;
int dist[1000][1000];
queue<pair<int,int> >q;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m>>k;
	memset(dist,63,sizeof(dist));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>grid[i][j];
			if(grid[i][j]=='S'){
				q.push(make_pair(i,j));
				dist[i][j]=0;
			}
		}
	}
	int ans=2e9,res;
	while(q.size()){
		int x=q.front().first,y=q.front().second;
		q.pop();
		ans=min(ans,min(min(x-1,n-x),min(y-1,m-y)));
		for(int i=0;i<4;i++){
			int nx=x+dx[i],ny=y+dy[i];
			if(nx>=1&&nx<=n&&ny>=1&&ny<=m){
				if(grid[nx][ny]=='.'){
					if(dist[nx][ny]>dist[x][y]+1){
						dist[nx][ny]=dist[x][y]+1;
						if(dist[nx][ny]<=k)
							q.push(make_pair(nx,ny));
					}
				}
			}
		}
	}
	res=(ans+k-1)/k+1;
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 4992
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABeginner solver = new ABeginner();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABeginner {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int r = in.nextInt();
            int rate = n > 10 ? r : r + (10 - n) * 100;
            out.println(rate);
        }

    }

    static class Scanner {
        private final InputStream in;
        private final byte[] buffer;
        private int ptr;
        private int buflen;

        public Scanner(InputStream in) {
            this.in = in;
            this.buffer = new byte[1024];
            this.ptr = 0;
            this.buflen = 0;
        }

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

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

        private boolean isPrintableChar(byte c) {
            return '!' <= c && c <= '~';
        }

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

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

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

    }
}



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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int,string> Pis;

bool pairCompare_S(const Pis& firstElof, const Pis& secondElof)
{
    return firstElof.second < secondElof.second;
}
bool pairCompare_I(const Pis& firstElof, const Pis& secondElof)
{
    return firstElof.first > secondElof.first;
}
int main(){
  int n;
  cin>>n;
  Pis s[n];
  REP(i,n){
    Pis tmp;
    cin>>tmp.second;
    tmp.first=1;
    s[i]=tmp;
  }
  sort(s,s+n,pairCompare_S);
  /*
  REP(i,n){
    cout<<s[i].first<<" "<<s[i].second<<endl;
  }
  */
  REP(i,n){
    int k=0;
    while(s[i].second==s[i+1].second&&i<n){
      k++;
      i++;
    }
    s[i].first+=k;
  }
  sort(s,s+n,pairCompare_I);
  int k=s[0].first;
  int max_i=0;
  /*
  REP(i,n){
    cout<<s[i].first<<" "<<s[i].second<<endl;
  }
  */
  string max_s[n];

  while(s[max_i].first==k){
    max_s[max_i]=s[max_i].second;
    max_i++;
  }
  sort(max_s,max_s+max_i);
  REP(i,max_i){
    cout<<max_s[i]<<endl;
  }

}


Measured memory_bytes: 17408
N = int(input())

cards = list(map(int,input().split()))

Alice = 0
Bob = 0

for i in range(N):
  MaxPoint = max(cards)
  
  if i % 2 == 0:
    Alice += MaxPoint
  else:
    Bob   += MaxPoint

  cards.remove(MaxPoint)

print(Alice - Bob)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int x; cin >> x;
    if (x < 1200) cout << "ABC\n";
    else cout << "ARC\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long;


int main(){
    string s;
    cin >> s;
    bool same = false;
    for (int i=0;i<s.size()-1;i++) {
        if (s[i] == s[i + 1]) {
            same = true;
            break;
        }
    }
    cout << ((same) ? "Bad" : "Good") << endl;
}


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

int main() {
  string S, T, U;
  int A, B;
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  if (U == S) cout << A - 1 << " " << B;
  else cout << A << " " << B-1;
  return 0;
}

Measured memory_bytes: 256
import java.util.*; 
class Main {
   public static void main(String[] args) {
      
        Scanner sc = new Scanner(System.in);
       String str = sc.next();
       char[] c = str.toCharArray();
       int sam = str.length();
       int ki0=0;int ki1=0;int gu0=0;int gu1=0;
       int min1 = 0; int min2=0;int ans =0;
     
     if(sam>=2){
     
     for(int i =0;i<sam;i=i+2){//奇数の各数
      if(c[i]=='0'){ki0++;}
       else{ki1++;}
     }
          for(int i =1;i<sam;i=i+2){//偶数の各数
      if(c[i]=='0'){gu0++;}
       else{gu1++;}
     }
     
      min1 = ki0+gu1;
      min2 = ki1+gu0;
      ans = Math.min(min1,min2);
      System.out.print(ans);

      
     }else{
       System.out.print(0);
     }
     


   }
}


Measured memory_bytes: 26452
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353 ;

        
    
int main(){
  ll n; int x, m; cin >> n >> x >> m; set<ll> st;
  vector<ll> a; a.push_back(x); st.insert(x); int nyan;
  ll sum = x; ll now = x;
  if(n<101010){
    rep(i, n-1){
      now*=now; now%=m;
      sum+=now;
    }
    cout << sum << endl; return 0;
  }
  for(int i=1; i<101010; i++){
    a.push_back(a[i-1]*a[i-1]%m);
    if(st.count(a[i])){
      nyan = a[i]; break;
    }
    if(a[i]==0) break;
    st.insert(a[i]);
    sum+=a[i];
  }
  if(a[a.size()-1]==0){
    cout << sum << endl;  return 0;
  }
  a.pop_back(); int begin;
  rep(i, a.size()){
    if(a[i]==nyan) begin = i;
  }
  int syuki = a.size()-begin;
  ll ans = 0; ll ikkai = 0; ll sai = 0;
  for(int i=0; i<begin; i++){
    sai+=a[i];
  }
  for(int i=begin; i<a.size(); i++){
    ikkai+=a[i];
  }
  ans = sai+((n-begin)/syuki)*ikkai;
  for(int i=begin; i<begin+(n-begin)%syuki; i++){
    ans+=a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 5740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class T>bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll l;
    cin >> l;
    ll r = 0;
    while(powint(2, r) <= l){
        r++;
    }
    ll n = r;
    r--;
    vector<tuple<ll, ll, ll>> ans;
    repr(i, 1, n){
        ans.emplace_back(i, i+1, 0);
        ans.emplace_back(i, i+1, powint(2, i-1));
    }
    for(ll i = n-1; i >= 1; i--){
        if(l-powint(2, i-1) >= powint(2, r)){
            ans.emplace_back(i, n, l-powint(2, i-1));
            l -= powint(2, i-1);
        }
    }
    cout << n << " " << SZ(ans) << endl;
    rep(i, SZ(ans)){
        cout << get<0>(ans[i]) << " " << get<1>(ans[i]) << " " << get<2>(ans[i]) << endl;
    }
    return 0;
}

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

int main() {
    int N; cin >> N;
    int cnt = 0;
    bool ok = true;
    for(int i=0; i<N; ++i) {
        string s; cin >> s;
        if(s == "A") ++cnt;
        else --cnt;
        if(cnt < 0) ok = false;
    }
    if(cnt != 0) ok = false;
    cout << (ok ? "YES\n" : "NO\n");
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
/*int recursion(int x)
{
    if(x==0)
    {cout<<x;
        return 0;}
    cout<<x<<" ";
    recursion(x-1);
}*/

int main() {
 string str;
 cin>>str;
 if(str[2]==str[3]&&str[4]==str[5])
     cout<<"Yes";
 else
     cout<<"No";
}

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

constexpr long mod = 998244353;
vector<long> fact, inv;

long power(long n, long k) {
  if (k == 0) return 1;
  long res = power(n * n % mod, k / 2);
  if (k % 2) res = res * n % mod;
  return res;
}

void init(int n) {
  fact.push_back(1);
  inv.push_back(1);
  for (int i = 0; i < n; i++) {
    fact.push_back(fact.at(i) * (i + 1) % mod);
    inv.push_back(power(fact.at(i + 1), mod - 2));
  }
}

long ncr(long n, long r) {
  return fact.at(n) * inv.at(r) % mod * inv.at(n - r) % mod;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, M, K;
  cin >> N >> M >> K;
  init(N);
  long ans = 0;
  for (int i = 0; i <= K; i++) {
    (ans += M * power(M - 1, N - i - 1) % mod * ncr(N - 1, i) % mod) %= mod;
  }
  cout << ans << "\n";
}

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

long *tree[100001];

int main(void) {

  long n,u,v;
  scanf("%ld %ld %ld", &n, &u, &v);
  long tree_s[n+1];
  for (long i = 0; i <= n; i++) {
    tree_s[i] = 0;
  }
  long a,b;
  for (long i = 0; i < n-1; i++) {
    scanf("%ld %ld", &a, &b);
    tree[a] = realloc(tree[a], sizeof(long)*(tree_s[a]+1));
    tree[a][tree_s[a]] = b;
    tree_s[a]++;
    tree[b] = realloc(tree[b], sizeof(long)*(tree_s[b]+1));
    tree[b][tree_s[b]] = a;
    tree_s[b]++;
  }
  int visited[n+1];
  long depth_u[n+1],depth_v[n+1];
  for (long i = 0; i <= n; i++) {
    visited[i] = 0;
    depth_u[i] = 0;
    depth_v[i] = 0;
  }
  visited[u] = 1;
  long queue[n];
  queue[0] = u;
  long start = 0, end = 0, tail = 0;
  long cur,next;
  while (tail < n-1) {
    for (long i = start; i <= end; i++) {
      cur = queue[i];
      for (long j = 0; j < tree_s[cur]; j++) {
        next = tree[cur][j];
        if (visited[next] == 1) {
          continue;
        }
        visited[next] = 1;
        depth_u[next] = depth_u[cur]+1;
        tail++;
        queue[tail] = next;
      }
    }
    start = end+1;
    end = tail;
  }
  for (long i = 0; i <= n; i++) {
    visited[i] = 0;
  }
  visited[v] = 1;
  queue[0] = v;
  start = 0; end = 0; tail = 0;
  while (tail < n-1) {
    for (long i = start; i <= end; i++) {
      cur = queue[i];
      for (long j = 0; j < tree_s[cur]; j++) {
        next = tree[cur][j];
        if (visited[next] == 1) {
          continue;
        }
        visited[next] = 1;
        depth_v[next] = depth_v[cur]+1;
        tail++;
        queue[tail] = next;
      }
    }
    start = end+1;
    end = tail;
  }
  long move;
  long max = 0;
  long same = -1;
  for (long i = 1; i <= n; i++) {
    if (depth_u[i] > depth_v[i]) {
      continue;
    }
    if (depth_u[i] == depth_v[i]) {
      if (same == -1 || depth_u[i] < same) {
        same = depth_u[i];
      }
      continue;
    }
    move = depth_v[i]-1;
    if (move > max) {
      max = move;
    }
  }
  if (same > max) {
    max = same;
  }
  printf("%ld\n", max);

  return 0;
}

Measured memory_bytes: 7808
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] num = new int[4];
        for (int i = 0; i < 4; i++) {
            num[i] = sc.nextInt();
        }
        Arrays.sort(num);
        if (num[0] == 1 && num[1] == 4
                && num[2] == 7 && num[3] == 9) {
            System.out.println("YES");
            return;
        }
        System.out.println("NO");
    }

}


Measured memory_bytes: 23508
#include <stdio.h>
#include <math.h>
int main(){
  int t, h, m, s;
  scanf("%d", &t);
  h = floor(t / 3600);
  m = floor(t / 60) - 60 * h;
  s = t - (3600 * h + 60 * m);
  printf("%d:%d:%d\n", h, m, s);
  return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

int main() {
	std::string s; cin >> s;
	
	for(auto v : s) {
		if(v != ',') printf("%c", v);
		else printf(" ");
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int city,road,i,tag,tag2;
    scanf("%d %d",&city,&road);
    int count[city+1];
    for(i=0;i<=city;i++){
        count[i]=0;
    }
    for(i=0;i<road;i++){
        scanf("%d %d",&tag,&tag2);
        count[tag]++;
        count[tag2]++;
    }
    for(i=1;i<=city;i++){
        printf("%d\n",count[i]);
    }
    return 0;
}


Measured memory_bytes: 128
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.cpp                                           :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: monoue <marvin@student.42.fr>              +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/04/22 12:30:15 by monoue            #+#    #+#             */
/*   Updated: 2020/04/28 11:01:52 by monoue           ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include <bits/stdc++.h>

/* #include <boost/multi_array.hpp> */
/* #include <boost/optional.hpp> */
/* #include <boost/range/irange.hpp> */
/* #include <boost/range/algorithm.hpp> */
/* #include <boost/range/adaptors.hpp> */
/* #include <boost/multiprecision/cpp_int.hpp> */
/* #include <boost/algorithm/string/classification.hpp> // is_any_of */
/* #include <boost/algorithm/string/split.hpp> */
/* #include <boost/algorithm/string/join.hpp> */
/* #include <boost/algorithm/string/replace.hpp> */
/* #include <boost/math/tools/minima.hpp> */
/* namespace adaptor = boost::adaptors; */
/* using boost::math::tools::brent_find_minima; */
/* using boost::irange; */
/* using boost::algorithm::join; */
/* using boost::algorithm::split; */
/* using boost::algorithm::replace_all; */
/* using boost::multiprecision::cpp_int; */

#define MOD 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

using namespace std;
using ll = long long;
using P = pair<int, int>;

// TOP
void	Main()
{
	string	s;
	cin >> s;

	bitset<26>	bs;
	rep(i, s.size())
		bs.set(s.at(i) - 'a');
	if (!bs.all())
	{
		cout << s;
		rep(i, 26)
		{
			if (!bs.test(i))
			{
				cout << (char)(i + 'a') << endl;
				return ;
			}
		}
	}
	string	original;
	original = s;
	if (!next_permutation(s.begin(), s.end()))
	{
		cout << -1 << endl;
		return ;
	}
	int i = 0;
	while (original.at(i) == s.at(i))
		i++;
	cout << s.substr(0, i + 1) << endl;
}
// END

int		main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int m, h;

	for(;;){
		string deck;
		cin >> deck;
		if(deck[0] == '-') return 0;

		cin >> m;

		for(int i = 0; i < m; i++){
			cin >> h;
			string bottom = deck.substr(0, h);
			string top = deck.substr(h, deck.size()-h);
			deck = top + bottom;
		}
		cout << deck << endl;
	}

	return 0;
}

Measured memory_bytes: 3188
n = int(input())
ans = []

for i in range(n):
    s, p = map(str, input().split())
    ans.append([s,int(p),i+1])


ans.sort(key = lambda x: x[1], reverse = True)
ans.sort(key = lambda x: x[0])

for i in ans:
    print(i[2])

Measured memory_bytes: 3060
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	aa := make([]int64, n)
	ss := make([]int64, n+1)

	for i := 0; i < n; i++ {
		aa[i] = getNextInt64(scanner)
		ss[i+1] = ss[i] + aa[i]
	}

	var ans int64
	ans = math.MaxInt64
	for i := 1; i < n; i++ {
		size := absint64(ss[i]*2 - ss[n])
		if ans > size {
			ans = size
		}
	}
	fmt.Fprintln(writer, ans)
	writer.Flush()
}

func absint64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 7296
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 200010

void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int abs(int a){if(a<0)return -a;return a;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}
LL GCD(LL a,LL b){LL c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int POW(int a,int n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return (int)ans;}
int icmp(const void* a,const void* b){return *(int*)a-*(int*)b;}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}
LL fac[NUM],finv[NUM],inv[NUM];
void comi(){int i;fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fac[i]=fac[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
int com(int n,int k){if(n<k||n<0||k<0)return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}

int main(){
  int N,i,ans=0;
  scanf("%d",&N);
  char S[N+1];
  scanf("%s",S);
  FOR(i,0,N-2){
    if(S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C')ans++;
  }

  printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128
#include "iostream"
#include <vector>
#include <array>

int main()
{
    uint32_t N;
    std::cin >> N;

    std::vector<uint32_t> cardList(N);
    for (auto& cardValue : cardList) {
        std::cin >> cardValue;
    }

    std::array<uint32_t, 2> playerScoreList = {0, 0};
    uint32_t playerIndex = 0;
    while (!cardList.empty()) {
        auto maxCardValueItr = std::max_element(cardList.begin(), cardList.end());

        playerScoreList[playerIndex] += *maxCardValueItr;
        cardList.erase(maxCardValueItr);

        playerIndex = (playerIndex + 1) % 2;
    }

    std::cout << playerScoreList[0] - playerScoreList[1] << std::endl;

    return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static int N;
    static bool[] check = new bool[N];
    static bool[] ans = new bool[N];
    static List<Data>[] L = new List<Data>[N];

    static void Main()
    {
        N = int.Parse(ReadLine());
        check = new bool[N];
        ans = new bool[N];
        L = new List<Data>[N];
        for (int i = 0; i < N; i++) L[i] = new List<Data>();
        for(int i = 0; i < N - 1; i++)
        {
            var r = ReadLine().Split().Select(int.Parse).ToArray();
            int u = r[0] - 1;
            int v = r[1] - 1;
            int w = r[2];
            L[u].Add(new Data { to = v, d = w });
            L[v].Add(new Data { to = u, d = w });
        }
        DFS(0, false);
        for(int i = 0;i<N;i++)
            WriteLine(ans[i]?"1":"0");
    }
    static void DFS(int a,bool b)
    {
        ans[a] = b;
        check[a] = true;
        foreach(Data i in L[a])
        {
            if (!check[i.to])
            {
                DFS(i.to, i.d % 2 == 0 ? b : !b);
            }
        }
    }
}

struct Data
{
    public int to;
    public int d;
}

Measured memory_bytes: 32052
#include <cstdio>

int main(){
  int A, B, C, O; scanf("%d%d%*d%d%d%*d%*d", &C, &O, &A, &B);

  int g = A % 2 + B % 2 + C % 2;
  if(A > 0 && B > 0 && C > 0 && 3 - g < g) g = 3 - g;

  printf("%lld\n", 0LL + A + B + C + O - g);
  return 0;
}

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

int main(){

    int N; cin >> N;
    vector<int> x(N);
    vector<int> y(N);
    vector<int> h(N);

    int H, X, Y;

    for(int i = 0; i < N; i++){
        cin >> x[i] >> y[i] >> h[i];
        if(h[i] != 0){
            H = h[i];
            X = x[i];
            Y = y[i];
        }
    }

    for(int cx = 0; cx <= 100; cx++){
        for(int cy = 0; cy <= 100; cy++){
            
            int height = H + (int)abs(cx - X) + (int)abs(cy - Y);
            if(height == 0) continue;
            //cout << cx << " " << cy << " " << height << endl;
            bool ok = true;
            for(int i = 0; i < N; i++){
                //if(cx == 2 && cy == 2) cout << i << " " << cx << " " << cy << " " << height << " " << max(height - (int)abs(cx - x[i]) - (int)abs(cy - y[i]), 0) << endl;
                if(h[i] != max(height - (int)abs(cx - x[i]) - (int)abs(cy - y[i]), 0)){
                    ok = false;
                    break;
                }
            }

            if(ok){
                cout << cx << " " << cy << " " << height << endl;
                return 0;
            }

        }
    }

    while(1){}

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
char s[200020];
int main()
{
	int n,a,b,c,d,i;cin>>n>>a>>b>>c>>d;cin>>s+1;
	for (i=b;i<d;i++){
		if (s[i+1]=='#' && s[i]=='#') {puts("No");exit(0);}
	}
	for (i=a;i<c;i++){
		if (s[i+1]=='#' && s[i]=='#') {puts("No");exit(0);}
	}
		if (d>c) puts("Yes");
		else{
			for (i=b;i<=d;i++) if (s[i-1]==s[i] && s[i]==s[i+1] && s[i]=='.') {puts("Yes");exit(0);}
			puts("No");
		}
}

Measured memory_bytes: 384
// C++11
#include <algorithm>
#include <array>
#include <bitset>
#include <chrono>
#include <cmath>
#include <iostream>
#include <numeric>
#include <random>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>

using namespace std;

#define LOCAL 1

#if LOCAL
#define pv(val) cerr << #val << '=' << (val) << endl
#define pvn(name, val) cerr << name << '=' << (val) << endl
#define pl cerr << '@' << __LINE__ << endl
#else
#define pv(val)
#define pvn(name, val)
#define pl
#endif

template <class T>
ostream& operator<<(ostream& os, vector<T> const& vec) {
  if (vec.empty()) {
    os << "{}";
  } else {
    os << '{';
    for (size_t i = 0; i < vec.size() - 1; i++) os << vec[i] << ", ";
    os << vec.back() << '}';
  }
  return os;
}

template <class T, size_t S>
ostream& operator<<(ostream& os, array<T, S> const& arr) {
  if (arr.empty()) {
    os << "{}";
  } else {
    os << '{';
    for (size_t i = 0; i < arr.size() - 1; i++) os << arr[i] << ", ";
    os << arr.back() << '}';
  }
  return os;
}

int main(void)
{
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  int ans = 0;
  if(A + B > 2 * C){
    int d = min(X, Y);
    ans += d * 2 * C;
    if(X > Y){
      if(A < 2 * C) ans += A * (X - Y);
      else ans += 2*C*(X-Y);
    }else{
      if(B < 2*C) ans += B * (Y - X);
      else ans += 2*C * (Y-X);
    }
  }else{
    ans += A * X;
    ans += B * Y;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define pb push_back

vector<int> solve(int N){
  vector<int> a(N,0);
  for (int i = 1; i <= N; i++) {
    int j = 1;
    while(i*j <= N){
      // cout << i*j << endl;
      a[i*j-1]++;
      j++;
    }
  }
  return a;
}

int main() {
  int N;
  cin >> N;
  vector<int> a = solve(N);
  int cnt=0;
  rep(i, N){
    // cout << a[i] << endl;
    if(a[i] == 8 && (i+1)%2 == 1) cnt++;
  }
  cout << cnt << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    ll a,b,x;
    cin >> a>>b>>x;
	
  	ll ans = (b/x)-(a/x);
  	if(a%x==0) ans++;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vct vector<ll>
#define pr pair<ll,ll>
#define vpt vector<pr>
ll n,m;
ll mod=1LL*1000000007;
void deb(string s, ll vl){
  cout<<s<<" : "<<vl<<"\n";
}
void prv(vct v){
  for(ll i=0;i<v.size();i++)cout<<v[i]<<" ";
  cout<<"\n";
}


void solve(){
  cin>>n;
  set<pr> s;
  for(ll i=0;i<n;i++){
    ll t1,t2;
    cin>>t1>>t2;
    s.insert({t1,t2});
  }
  if(s.size()<2){
    cout<<"0\n";
    return;
  }
  ll ans;
  ll mina=LLONG_MAX,maxa=LLONG_MIN;
  ll minb=LLONG_MAX,maxb=LLONG_MIN;
  for(auto it: s){
    ll su=it.first+it.second;
    if(su>maxa){
      maxa=su;
    }
    if(su<mina){
      mina=su;
    }
    su=it.first-it.second;
    if(su>maxb){
      maxb=su;
    }
    if(su<minb){
      minb=su;
    }
  }
  ans=max(abs(maxa-mina),abs(maxb-minb));
  cout<<ans<<"\n";
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ll t;
  t=1;
  // cin>>t;
  while(t--){
    solve();
  }
}

Measured memory_bytes: 16144
#include<iostream>
using namespace std;
int main(){
	int s;
	int h,m;
	cin >> s;
	h=s/3600;
	s-=h*3600;
	m=s/60;
	s-=m*60;
	cout << h <<":"<<m<<":"<<s<<endl;
	return 0;
}

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

int main(){
    int n,count=0;
    cin>>n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a.at(i) ;
    }
    for(int i=n-1; i>0; i--){
        for(int j=0; j<i; j++){
            if(a[j]>a[i]){
                swap(a[j],a[i]);
                count++;
            }
        }
    }
    if(count>1){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
}

Measured memory_bytes: 256
#[allow(dead_code)]
fn main() {
    let mut s = i::s();
    let mut t = i::s();
    s.sort();
    t.sort();
    t.reverse();

    if s == t {
        println!("{}", "No");
        return;
    }

    let mut v = vec![s.clone(), t];
    v.sort();
    if v[0] == s {
        println!("{}", "Yes");
    } else {
        println!("{}", "No");
    }
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <stdlib.h>
#include <sstream>

using namespace std;

int find_max(int* arr, int size) {
    int max = -1;
    for (int i = 0; i < size; i++) {
        if (arr[max] < arr[i]) {
            max = i;
        }
    }
    return max;
}

int main() {
    int n, q;
    cin >> n >> q;
    int* m = (int*)malloc(sizeof(int) * n);

    for (int i = 0; i < n; i++)
        m[i] = 0;

    int max = -1;
    for (int i = 0; i < q; i++) {
        int a, v;
        cin >> a >> v;
        m[a - 1] += v;

        if (v > 0) {
            if (m[max] < m[a - 1]) {
                max = a - 1;
            } else if (m[max] == m[a-1]) {
                for (int j = 0; j < n; j++) {
                    if (m[max] == m[j]) {
                        max = j;
                        break;
                    }
                }
            }
        } else {
            max = find_max(m, n);
        }

        cout << max + 1 << " " << m[max] << endl;
    }
    return 0;
}

Measured memory_bytes: 6940
n = int(input())
p = list(map(int,input().split()))

count = 0

for i in range(1,n-1):
    if ( p[i-1] < p[i] and p[i] < p [i+1] ) or ( p[i-1] > p[i] and p[i] > p [i+1] ):
        count+=1 

print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;



int main() {
	vector<ll> v(3);
	for (int i = 0; i < 3;i++) {
		cin >> v[i];
	}

	for (int i = 0; i < 3;i++) {
		if (v[i] % 2 == 0) {
			cout << 0 << endl;
			return 0;
		}
	}

	sort(v.begin(), v.end());
	cout << v[0] * v[1] << endl;
	

}



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

int main(){
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	
	if(a[0]==a[1]&&a[2]!=a[0]){
		cout<<"Yes";
		return 0; 
	}else if(a[1]==a[2]&&a[0]!=a[1]){
		cout<<"Yes";
		return 0;
	}
	
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#define bye return 0
#define speedOne ios::sync_with_stdio(false)
#define speedtwo cin.tie(0)
typedef long long int lli;
typedef long long ll;
using namespace std;
int main()
{
    ll a=0;
    string str1, str2;
    cin >> str1 >> str2;
    for(auto i=0;i<str1.size();i++){
        if(str1[i] != str2[i]) a++;
    }
    cout << a << endl;
	bye;
}

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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    ll n,k;cin >> n >> k;
    ll shou = n/k;
    ll ans = n-shou*k;
    ans = min(abs(n - shou * k), abs(n-(shou+1)*k));
    cout << ans << endl;
}

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

namespace C___Walk_on_Multiplication_Table
{
    class Program
    {
        static void Main(string[] args)
        {
            Int64 N = Int64.Parse(Console.ReadLine());
            Int64 a = 1000000000000;
            Int64 j = 0;

            for (Int64 i = 2; i <= Math.Sqrt(N); i++)
            {
                if (N % i == 0)
                {
                    j = N / i;
                    if (a > (i - 1) + (j - 1))
                    {
                        a = (i - 1) + (j - 1);
                    }
                }
            }
            if (a == 1000000000000)
            {
                a = N - 1;
            }
            Console.WriteLine(a);
        }
    }
}


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

int main(){
    int N,T,A;
    cin >>N>>T>>A;
    vector<double> HT;
    for(int i=0;i<N;i++){
        int h;
        cin >>h;
        HT.push_back(fabs(A-(T-h*0.006)));
    }
    vector<double>::iterator itr = min_element(HT.begin(),HT.end());
    cout << distance(HT.begin(),itr)+1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <string.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
	unsigned long N, A[100000], B[100000];
	int flag = 0;
	int ans = 1;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	if (N % 2 == 0) {
		for (int i = 0; i < N; i++) {
			if (A[i] % 2 == 1) {
				B[A[i] / 2] += 1;
				
			}
			else {

				cout << 0 << endl;
				return 0;
			}
		}
		for (int i = 0; i < (N - 1) / 2; i++) {
			if (B[i] != 2) {
				cout << 0 << endl;
				return 0;
			}
		}
		for (int i = 0; i < N / 2; i++) {
			ans = (ans * 2) % 1000000007;
		}
		cout << ans << endl;
	}
	else {
		for (int i = 0; i < N; i++) {
			if (A[i] == 0) {
				flag += 1;				
			}
			else if (A[i] % 2 == 0) {

				B[A[i] / 2] += 1;

			}
			else {
				cout << 0 << endl;
				return 0;
			}
			
		}
		if (flag != 1) {
			cout << 0 << endl;
			return 0;
		}
		for (int i = 1; i < (N - 1) / 2; i++) {
			if (B[i] != 2) {
				cout << 0 << endl;
				return 0;
			}
		}
		for (int i = 0; i < N / 2; i++) {
			ans = (ans * 2) % 1000000007;
		}
		cout << ans << endl;
	}

	return 0;
}

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

using namespace std;

int gcd(int a, int b) {
    if (a < b ) {
        int tmp = a;
        a = b;
        b = tmp;
    }
    int r = a;
    while (r != 0) {
        r = a;
        while (r >= b) {
            r = r - b;
        }
        a = b;
        b = r;
    }

    return a;
}

int main() {
    int a, b, k;
    cin >> a >> b >> k;

    int count = 0;
    int i = gcd(a, b) + 1;
    while (count < k) {
        i--;
        if (a % i == 0 and b % i == 0) {
            count++;
        }
    }

    cout << i << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int m1,m2,d1,d2,ans=0;
    cin>>m2>>d2>>m1>>d1;
    if(d2==31&&(m2==1||m2==3||m2==5||m2==7||m2==8||m2==10||m2==12)) ans++;
    else if(d2==30&&(m2==4||m2==6||m2==9||m2==11)) ans++;
    else if(d2==28&&m2==2) ans++;
    cout<<ans;
}

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

using namespace std;

int D,N;
int temp[201];
int cloth[201][3];
int a[201][201][201];


int dp(int d,int yk,int k){
	if(d > 0){
		if(!(cloth[k][0] <= temp[d] && cloth[k][1] >= temp[d]))return 0;
	}

	if(a[d][yk][k] >= 0) return a[d][yk][k];

	if(d == D){
		return a[d][yk][k] = fabs(cloth[yk][2] - cloth[k][2]) ;
	}

	int eva = 0;
	int sum = 0;
	for(int i = 1; i <= N ;i++){
		if(d < 2){
			sum = dp(d+1, k, i);
			eva = max(eva,sum);
		}else{
			sum = dp(d +1, k, i) + fabs(cloth[yk][2] - cloth[k][2]);
			// cout <<d <<" "<< yk << " "<<k <<" "<< sum << endl;
			eva = max(eva,sum);
		}
	}

	return a[d][yk][k] = eva;


	// long long int eva = 0;
	// long long int sum = 0;
	// if(d >= 2){

	// 	eva = fabs(yeva - cloth[k][2]);
	// }

	// if(d == D){
	// 	// cout<<d<<" "<<k<<" "<<eva<<endl;
	// 	return a[d][k] = eva;
	// }


	// for(int i = 1;i <= N;i++){
	// 	if(d == 0){
	// 		eva = max(eva, dp(d+1, i, 0));
	// 	}else if( d == 1){
	// 		// cout<<sum<< " "<<eva<<endl;
	// 		// cout<<eva<<" "<<dp(d+1,i,cloth[k][2])<<endl;
	// 		eva = max(eva,dp(d+1, i, cloth[k][2]));
	// 	}else{
	// 		sum = dp(d+1,i,cloth[k][2]) + eva;
	// 		cout<<d<<" "<<dp(d+1,i,cloth[k][2])<<" "<<eva <<" "<<sum<<endl;
	// 		// cout<<eva<<" "<<dp(d+1,i,cloth[k][2])<<endl;
	// 		eva = max(eva,sum);
	// 	}
	// }
	// // cout << d <<" " <<k<<" " << eva <<endl; 
	// return a[d][k] = eva;
}


int main(){
	fill_n(temp,201,-1);
	fill_n(*cloth,201*3,-1);
	fill_n(**a,201*201*201,-1);
	cin >> D >> N;
	for(int i = 1;i <= D;i++){
		cin >>temp[i];
	}
	for(int i = 1;i <= N;i++){
		for(int j = 0;j < 3;j++){
			cin >> cloth[i][j];
		}
	}
	cout << dp(0,0,0) << endl;
}

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

using namespace std;

const int N = 3010;

double p[N];

long double dp[N][N];

int main() {

    int n;
    cin >> n;
    for(int i = 1 ; i <= n ; i++)
        cin >> p[i];


    dp[0][0] = 1;

    for(int i = 1 ; i <= n ; i++) 
        dp[i][0] = dp[i - 1][0] * (1 - p[i]);
    

    for(int i = 1 ; i <= n ; i++) {
        for(int j = 1; j <= i ; j++) {
            dp[i][j] = p[i] * dp[i - 1][j - 1] + (1 - p[i]) * dp[i - 1][j];
        }
    }

    double ans = 0;
    for(int i = (n + 1) / 2 ; i <= n ; i++) 
        ans = ans + dp[n][i];

    cout << setprecision(10) <<  ans << '\n';

    return 0;
}

Measured memory_bytes: 139776
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>

using namespace std;

#define INF 1e+9
#define mp make_pair
#define pb push_back
#define fi first
#define fs first
#define se second
#define i64 long long
#define li long long
#define lint long long
#define pii pair<int, int>
#define vi vector<int>

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define fore(i, b, e) for (int i = (int)b; i <= (int)e; i++)

const int maxn = 1e5+5;

set<int> pos, elems;
vi edges[maxn];
bool mark[maxn];
vi p;

void dfs(int i) {
    mark[i] = true;
    pos.insert(i);
    elems.insert(p[i]);
    for (int nxt : edges[i])
        if (!mark[nxt])
            dfs(nxt);
}

int main() {
#ifdef LOCAL
    freopen("inp", "r", stdin);
    //freopen("outp", "w", stdout);
#else
    // freopen(TASKNAME ".in", "r", stdin);
    // freopen(TASKNAME ".out", "w", stdout);
#endif
    int n, m;
    scanf("%d%d", &n, &m);
    p.resize(n);
    forn(i, n) {
        scanf("%d", &p[i]);
        p[i]--;
    }
    forn(i, m) {
        int x, y;
        scanf("%d%d", &x, &y);
        --x;
        --y;
        edges[x].pb(y);
        edges[y].pb(x);
    }
    int ans = 0;
    forn(i, n)
        if (!mark[i]) {
            //printf("i = %d\n", i);
            pos.clear();
            elems.clear();
            dfs(i);
            /*for (int x : pos) {
                printf("pos %d\n", x);
            }
            for (int x : elems*/
            for (int x : pos)
                if (elems.find(x) != elems.end())
                    ans++;
        }
    printf("%d", ans);
}



Measured memory_bytes: 18560
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <fstream>
#include <cassert>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;



int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	if (a > b)swap(a, b);
	for (int i = 0; i < b; i++)cout << a;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;(i) < (int)(n);i++)
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<vector<int>> to(n),cost(n);
    rep(i,n-1){
        int u,v,w;
        cin >> u >> v >> w;
        u--;
        v--;
        to[u].push_back(v); cost[u].push_back(w);
        to[v].push_back(u); cost[v].push_back(w);
    }
    vector<int> ans(n,-1);
    queue<int> q;
    ans[0] = 0;
    q.push(0);
    //幅優先
    while(!q.empty()){
        int v = q.front();
        q.pop();
        for(int i=0;i<to[v].size();i++){
            int u = to[v][i];
            int w = cost[v][i];
            if(ans[u] != -1) continue;
            ans[u] = (ans[v]+w) % 2;//偶奇をとる
            q.push(u);
        }
    }
    rep(i,n) cout << ans[i] << "\n"; 
}

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

int main(){
  int coin[] = {500, 100, 50, 10, 5, 1};
  int n;
  while(std::cin >> n, n){
    int p = 0, ans = 0;
    n = 1000 - n;
    while(n != 0){
      while(n - coin[p] < 0)p++;
      n -= coin[p];
      ans++;
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <cstdlib>
#include <iostream>
#include <map>
using namespace std;


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

	for(int n; cin >> n, n;) {
		char convert[256];
		for(int i = 0; i < 256; ++i)
			convert[i] = i;

		for(int i = 0; i < n; ++i) {
			char from, to;
			cin >> from >> to;
			convert[from] = to;
		}

		int m;
		cin >> m;

		for(int i = 0; i < m; ++i) {
			char in;
			cin >> in;
			cout << convert[in];
		}

		cout << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1196
#include <cstdio>

int main()
{
    int n, m, l;
    std::scanf("%d%d%d", &n, &m, &l);
    int gyoretsuA[n][m];
    int gyoretsuB[m][l];

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            std::scanf("%d", &gyoretsuA[i][j]);
        }
    }

    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < l; j++)
        {
            std::scanf("%d", &gyoretsuB[i][j]);
        }
    }

    long gyoretsuC[n][l];

    for (int p = 0; p < n; p++)
    {
        for (int q = 0; q < l; q++)
        {
            gyoretsuC[p][q] = 0;
            for (int r = 0; r < m; r++)
            {
                gyoretsuC[p][q] += (long)(gyoretsuA[p][r] * gyoretsuB[r][q]);
            }
        }
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < l; j++)
        {

            std::printf("%ld", gyoretsuC[i][j]);

            if (j != l - 1)
            {
                std::printf(" ");
            }
        }
        std::printf("\n");
    }
}


Measured memory_bytes: 2848
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
ans = float("inf")
s = input()
for i in s:
	t = s.split(i)
	l = -1
	for j in t:
		l = max(l,len(j))
	ans = min(ans,l)
print(ans)

Measured memory_bytes: 9336