akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int k;
  string s;
  cin>>k>>s;
  if(s.size()>k){for(int i=0;i<k;i++){cout<<s.at(i);}
                cout<<"..."<<endl;}
  else{cout<<s<<endl;}
 
}

Measured memory_bytes: 3628
N,K = map(int,input().split())
li = list(map(int,input().split()))
time = 10**10

for i in range(N-K+1):
    if li[i+K-1] <= 0:
        time = min(time,abs(li[i]))
    if li[i]<= 0 and li[i+K-1]>=0:
        time = min(min(abs(li[i]),abs(li[i+K-1]))+li[i+K-1]-li[i],time)
    if li[i]>=0:
        time = min(time,abs(li[i+K-1]))

print(time)


Measured memory_bytes: 14252
#include"bits/stdc++.h"
using namespace std;

#define ll long long int
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define sz(a) int((a).size())
#define mod 1000000007
#define inf LLONG_MAX
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
template <typename T>
inline T gcd(T a, T b) { while (b != 0) swap(b, a %= b); return a; }

template <typename T>
inline void seethis(vector<T>vect)
{
    for(T x:vect)
        cout<<x<<" ";
    cout<<"\n";
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
//LCM
int lcm(int a, int b) {  return a * (b / gcd(a, b)); }

//For sort by second
bool cmp(const pair<int,int> &a)
{ return a.first<a.second; }

 const int MAXN = 200000 + 5;
vector<ll> adj[MAXN];
vector<bool>visited(MAXN,false);

ll n,m;


ll dfs(int par)
{
  visited[par]=true;
  ll res=1;
  for(int child:adj[par])
  {
    if(!visited[child])
        res+=dfs(child);

    
  }
  return res;


}



int main()
{
  FASTIO;
  #ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
  

  cin>>n>>m;
  set<pair<int,int>>se;
  for(int i=0;i<m;i++)
  {
    int u,v;
    cin>>u>>v;
     if(se.find({u,v})==se.end() and se.find({v,u})==se.end())
     {
       adj[u-1].push_back(v-1);
       adj[v-1].push_back(u-1);
       se.insert({u,v});
     }
   
  }

  ll ans= -inf;
  for(int i=0;i<n;i++)
  {
    if(!visited[i])
    { 
      ll x= dfs(i);
      ans=max(ans,x);
    }
  }
  cout<<ans<<"\n";
  
  return 0;
}

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

int main() {
  long n,ans=1;
  cin >> n;
  vector<long> a(n);
  vector<long> x(3);
  for(long i=0;i<n;i++) cin >> a[i];

  for(long i=0;i<n;i++) {
    long b=0;
    for(long j=0;j<3;j++) {
      if(x[j]==a[i]) {
        if(b==0) x[j]++;
        b++;
      }
    }
    ans=ans*b%1000000007;
  }

  cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

// h(n, r) = c(n+r-1, r)
struct combination
{
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1)
  {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i)
    fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i)
    ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k)
  {
    if (k < 0 || k > n)
    return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};

int main()
{
  int n;
  ll k;
  cin >> n >> k;
  vector<ll> a(n), f(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> f[i];
  sort(ALL(a));
  sort(rALL(f));

  ll l = -1, r = INF64;
  while(r - l > 1ll) {
    ll mid = l + (r-l)/2;
    ll tmp = 0;
    rep(i, n) {
      ll diff = max(0ll, a[i]*f[i]-mid);
      tmp += (ll)ceil((double)diff/f[i]);
    }
    if(tmp <= k) r = mid;
    else l = mid;
  }

  cout << r << endl;
}


Measured memory_bytes: 3328
from bisect import bisect_left, bisect_right

N = int(input())
L = [int(i) for i in input().split()]

L.sort()
ret = 0
for i in range(N) :
    a = L[i]
    for j in range(i + 1, N) :
        b = L[j]
        ret += bisect_left(L, a+b) - j - 1
print(ret)

Measured memory_bytes: 45604
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static PrintWriter out;

    public static void main(String[] args) throws IOException {
        out = new PrintWriter(new OutputStreamWriter(System.out));
        CF_Reader in = new CF_Reader();

        long radius = in.nextLong();
        int n = in.nextInt();
        long[] nums = new long[n];
        long prev = 0;
        long maxVal = 0;
        long total = 0;
        for (int i = 0; i < n; i++) {
            long num = in.nextLong();
            nums[i] = num - prev;
            maxVal = Math.max(nums[i], maxVal);
            total += nums[i];
            prev = num;
        }
        out.println(Math.min(total - nums[0], total + (radius - prev) - maxVal));

        out.close();
    }


    static class CF_Reader {
        BufferedReader br;
        StringTokenizer st;

        public CF_Reader() throws IOException {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine().trim());
            return st.nextToken();
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        char nextCharacter() throws IOException {
            return next().charAt(0);
        }

        String nextLine() throws IOException {
            return br.readLine().trim();
        }
    }
}


Measured memory_bytes: 47828
#include <stdio.h>

int W,a,b;

int main(){
	scanf("%d %d %d",&W,&a,&b);
	if(a+W>b && a<b+W){
		printf("0\n");
	}else if(a<b){
		printf("%d\n",b-(a+W));
	}else if(a>b){
		printf("%d\n",a-(b+W));
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int a, b, c; std::cin >> a >> b >> c;
  if ( b - a == c - b ) std::cout << "YES" << std::endl;
  else std::cout << "NO" << std::endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int num = Integer.parseInt(br.readLine());
		int[] su1 = new int[num];
		int[] su2 = new int[num];
		String[] str1 = br.readLine().split(" ");

		for(int i = 0; i < str1.length; i++){
			su1[i] = Integer.parseInt(str1[i]);
		}

		String[] str2 = br.readLine().split(" ");

		for(int i = 0; i < str2.length; i++){
			su2[i] = Integer.parseInt(str2[i]);
		}
		double p1 = 0;
		double p2 = 0;
		double p3 = 0;
		double infinity = 0;

		for(int i = 0; i < num; i++){
			p1 += Math.abs(su1[i] - su2[i]);
			p2 += Math.abs(Math.pow(su1[i] - su2[i],2));
			p3 += Math.abs(Math.pow(su1[i] - su2[i],3));
			if(infinity < Math.abs(su1[i]-su2[i])){
				infinity = Math.abs(su1[i] - su2[i]);
			}
		}
		System.out.println(p1);
		System.out.println(Math.sqrt(p2));
		System.out.println(Math.cbrt(p3));
		System.out.println(infinity);
	}
}

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


public class Main {
	
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		final int m = sc.nextInt();
		
		int[] costs = new int[n];
		for(int i = 0; i < n; i++){
			costs[i] = sc.nextInt();
		}
		
		int[] votes = new int[m];
		for(int i = 0; i < m; i++){
			votes[i] = sc.nextInt();
		}
		
		int[] count = new int[n];
		for(int i = 0; i < m; i++){
			final int lim_cost = votes[i];
			
			int selected = -1;
			for(int j = 0; j < n; j++){
				if(costs[j] <= lim_cost){
					selected = j;
					break;
				}
			}
			
			count[selected]++;
		}
		
		int max = -1, max_pos = -1;
		for(int i = 0; i < n; i++){
			if(max < count[i]){
				max = count[i];
				max_pos = i;
			}
		}
		
		System.out.println(max_pos + 1);
	}

}

Measured memory_bytes: 25108
#include<iostream>
#include<map>

using namespace std;
typedef pair<int, int> pii;
const pii dd[]={{-2, -2}, {-2, -1}, {-1, -2}, {-1, -1}, {-1, 0}, {0, -1}, {0, 0}, {-2, 0}, {0, -2}};

int main(){

   long long H, W, N;
   cin>> H>> W>> N;
   int a[N], b[N];
   for(int i=0; i<N; i++){
      cin>> a[i]>> b[i];
      a[i]--; b[i]--;
   }

   map<pii, int> P;
   for(int i=0; i<N; i++){
      for(pii d: dd){
         int y=a[i]+d.first;
         int x=b[i]+d.second;
         for(pii e: dd){
            int Y=y-e.first;
            int X=x-e.second;
            if(!(0<=Y&&Y<H&&0<=X&&X<W)){
               goto dame;
            }
         }
         P[pii(y, x)]++;
         dame:;
      }
   }

   long long ans[10]={};
   ans[0]=(H-2)*(W-2)-P.size();
   for(auto it=P.begin(); it!=P.end(); it++){
      ans[it->second]++;
   }

   for(long long answer: ans){
      cout<< answer<< endl;
   }

   return 0;
}


Measured memory_bytes: 57216
using System;
using System.Linq;
namespace ABC082
{
    class B
    {
        static void Main(string[] args)
        {
            string s = new string(Console.ReadLine().OrderBy(x => x).ToArray());
            string t = new string(Console.ReadLine().OrderByDescending(x => x).ToArray());

            Console.WriteLine(s.CompareTo(t) == -1 ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13536
S=input()
first2 = int(S[0:2])
last2 = int(S[2:4])

if 1 <= first2 and first2 <= 12:
  if 1 <= last2 and last2 <= 12:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:
  if 1 <= last2 and last2 <= 12:
    print("YYMM")
  else:
    print("NA")
  


Measured memory_bytes: 2940
#include<bits/stdc++.h>
 using namespace std;
int main(){
  string S;
  cin >> S;
  int n = S.length();
  int res = 0;
  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = 0; j < n - i; j++) {
      if (S[i+j] == 'A'||S[i+j] == 'T'||S[i+j] == 'G'||S[i+j] == 'C') {
        sum++;
      }else{
        break;
      }
    }
    if (sum > res) {
      res = sum;
    }
  }
  cout << res << "\n";
}


Measured memory_bytes: 256
from fractions import gcd
def lcm(x,y):
	return x*y//gcd(x,y)

a,b,c,d=map(int,input().split())
a-=1
print((b-a)-(b//c+b//d-b//lcm(c,d))+(a//c+a//d-a//lcm(c,d)))

Measured memory_bytes: 5688
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <utility>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;++i)
#define REP(i,n) for (int i=1;i<=n;++i)
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define read(x) scanf("%d",&x)
int n,q;
ll a[200005];
vector<int> G[200005];
inline void dfs(int u,int pa){
	a[u]+=a[pa];
	for (int i=0;i<G[u].size();++i){
		int v=G[u][i];if (v!=pa) dfs(v,u);
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>q;
	REP(i,n-1){
		int u,v;cin>>u>>v;G[u].pb(v);G[v].pb(u);
	}
	while(q--){
		ll p,x;cin>>p>>x;a[p]+=x;
	}
	dfs(1,0);
	REP(i,n) cout<<a[i]<<' ';
	return 0; 
}

Measured memory_bytes: 22528
#include <bits/stdc++.h>
using namespace std;
     
int main(){
  int n;
  cin >> n;

  int a,b,c,d;
  a = n / 1000;
  b = (n % 1000) / 100;
  c = (n % 100) / 10;
  d = n % 10;

  if(a == b && b == c )
    cout << "Yes" << endl;
  else if(b == c && c == d)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;  
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
static const int N = 100;

int main()
{
  int M[N][N];
  int n, u, k, v;

  cin >> n;

  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < n; j++)
      M[i][j] = 0;
  }

  for (int i = 0; i < n; i++)
  {
    cin >> u >> k;
    u--;
    for (int j = 0; j < k; j++)
    {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < n; j++)
    {
      if (j)
        cout << " ";
      cout << M[i][j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long ll;
#define print(x) cout<<(x)<<endl


#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


// DONT USE "int", USE "ll" !!!!!!!!!!!!
int main() {
	string S; cin >> S;
	string out;
	out += S[0];
	string p = to_string(S.size() - 2);
	
	out += p;
	out += S.back();
	print(out);



	



	return 0;
}

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

int main() {
int N;
cin >> N;
vector<int> vec(N);

for(int i=0;i<N;i++){
cin >> vec.at(i);
}
int A=0;
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
if(i<j){
A+=vec.at(i)*vec.at(j);
}
}
}

cout << A<<endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;

#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

#define N 2019
int main(){fastio
    ll l,r;cin>>l>>r;
    ll p1=l/N,p2=r/N;
    if(p1!=p2){
        cout<<0<<endl;
        return 0;
    }
    ll ans=inf;
    rep(i,l,r-1){
        rep(j,i+1,r){
            ll k=(i*j)%N;
            Min(ans,k);
        }
    }
    cout<<ans<<endl;
    
    return 0;
}





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

inline int64_t ceiling_div(int64_t a, int64_t b){
  int64_t ans= ((a>=0 && b > 0) || (a<=0 && b < 0)) ? (abs(a)+abs(b)-1)/abs(b)
                                                    : -abs(a)/abs(b);
  return ans;
}

int main(){
  const int Amax= 1'000'000'000;
  int64_t N,Nop;
  cin >> N >> Nop;

  vector<int64_t> data(N);
  for(int i=0; i<N; i++){
    cin >> data.at(i);
  }

  int64_t inc= Amax;
  int64_t exc= 0;
  while(abs(inc- exc) > 1){
    int64_t mid= (inc+ exc)/ 2;

    int64_t Nop_mid= 0;
    for(int i=0; i<N; i++){
      Nop_mid+= ceiling_div(data.at(i), mid)- 1;
    }

    if(Nop_mid <= Nop){ inc= mid; }
    else              { exc= mid; }
  }
  
  cout << inc << endl;
}

Measured memory_bytes: 4840
#include <iostream>
#include <cstdio>
#include <queue>

using namespace std;

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

int n, m, sx, sy, ex, ey, dis[1010][1010], vis[1010][1010];
char a[1010][1010];
priority_queue<pair<int, pair<int, int> > > q;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m >> sx >> sy >> ex >> ey;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			cin >> a[i][j];
	memset(dis, 0x3f, sizeof dis);
	memset(vis, 0, sizeof vis);
	q.push({ 0, {sx, sy} });
	dis[sx][sy] = 0;
	while (q.size()) {
		int x = q.top().second.first, y = q.top().second.second;
		q.pop();
		if (vis[x][y])
			continue;
		vis[x][y] = 1;
		for (int i = 0; i < 4; i++) {
			int tx = x + dx[i], ty = y + dy[i];
			if (tx && tx <= n && ty && ty <= m && a[tx][ty] == '.' && dis[tx][ty] > dis[x][y]) {
				dis[tx][ty] = dis[x][y];
				q.push({ -dis[tx][ty], {tx, ty} });
			}
		}
		for (int di = -2; di <= 2; di++)
			for (int dj = -2; dj <= 2; dj++) {
				int tx = x + di, ty = y + dj;
				if (tx > 0 && tx <= n && ty > 0 && ty <= m && a[tx][ty] == '.' && dis[tx][ty] > dis[x][y] + 1) {
					dis[tx][ty] = dis[x][y] + 1;
					q.push({ -dis[tx][ty], {tx, ty} });
				}
			}
	}
	if (dis[ex][ey] == 0x3f3f3f3f)
		dis[ex][ey] = -1;
	cout << dis[ex][ey] << endl;

	return 0;
}

Measured memory_bytes: 12072
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef vector<long long int> vint;
typedef vector<string> vstr;
typedef long long int llint;
llint gcd(llint x, llint y) {
	while (y != 0) {
		if (x > y) {
			llint r = x % y;
			x = y;
			y = r;
		}
		else {
			llint r = y % x;
			y = r;
		}
	}
	return x;
}


int main(void){
	llint N,an;
	llint ans = 1000000,a = 0, b = 0;
	cin >> N;
	vint W(N);
	for(int i=0;i<N;i++)cin>>W[i];

	for (int i = 0; i < N; i++) {
	    a=0;
	    b=0;
		for (int j = 0; j <= i;j++) {
			a += W[j];
		}
		for (int j = i + 1; j < N; j++) {
			b += W[j];
		}
		an = abs(a - b);
		ans = min(ans, an);
		
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  long long A, B, C;
  cin >> A >> B >> C;
  long long preA = A, preB = B, preC = C;
  long long ans = 0;
  while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0)
  {
    ans++;
    A = (preB + preC) / 2;
    B = (preC + preA) / 2;
    C = (preA + preB) / 2;
    if (preA == A && preB == B && preC == C)
    {
      ans = -1;
      break;
    }

    preA = A;
    preB = B;
    preC = C;
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
    int n,m,i,j,t,c;
    c=0;//answer
    cin >> n;
    vector<int> s(n+1);//入力+番兵
    for(i=0;i<n;i++) cin >> s.at(i);
    cin >> m;
    
    for(i=0;i<m;i++){
        cin >> t;
        s.at(n) = t;
        j=0;
        while(s.at(j)!=t) j++;
        if(j == n) continue;
        c++;
    }
    cout << c << endl;
    return 0;
}


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

int main(){
	string S, T;
	cin >> S >> T;

	int cnt = 0;
	for (int i = 0; i < 3; i++) {
		if (S[i] == T[i])cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    VL a(N),b(N);
    REP(i,N) cin >> a[i];
    REP(i,N) cin >> b[i];
    VL c(N);
    LL plus = 0;
    LL minus = 0;
    REP(i,N){
        c[i] = b[i]-a[i];
        if(c[i] > 0) {
            plus += c[i]/2;
        }
        else minus += -c[i];
    }
    if(plus >= minus) cout << "Yes" << endl;
    else cout << "No" << endl;


}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  unordered_map<string, int> hashMap;
  string s;
  for (int i = 0; i < N; ++i) {
    cin >> s;
    hashMap[s]++;
  }
  int max_count = 0;
  for (auto m : hashMap) {
    max_count = max(max_count, m.second);
  }
  vector<string> res;
  for (auto m : hashMap) {
    if (m.second == max_count) {
      res.push_back(m.first);
    }
  }
  sort(res.begin(), res.end());
  for (const string& str : res) {
    cout << str << endl;
  }
  return 0;
}

Measured memory_bytes: 26948
#include<cstdio>
#define MAX 100000
#define INF (1<<21)

int id[MAX], total[MAX];
int n;

int searchMin(){
    int minv = INF;
    int target;
    for ( int i = 0; i < n; i++ ){
	if ( total[i] < 0 ) continue;
	if ( total[i] < minv ){
	    minv = total[i];
	    target = i;
	}
    }
    total[target] = -1;
    return id[target];
}

int searchMax(){
    int maxv = 0;
    int target;
    for ( int i = 0; i < n; i++ ){
	if ( total[i] < 0 ) continue;
	if ( total[i] > maxv ){
	    maxv = total[i];
	    target = i;
	}
    }
    total[target] = -1;
    return id[target];
}

main(){
    int m, s;
    while(1){
	scanf("%d", &n);
	if ( n == 0 ) break;
	for ( int i = 0; i < n; i++ ){
	    scanf("%d", &id[i]);
	    total[i] = 0;
	    for ( int j = 0; j < 4; j++ ){
		scanf("%d %d", &m, &s);
		total[i] += m*60+s;
	    }
	}

	printf("%d\n", searchMin());
	printf("%d\n", searchMin());
	searchMax();
	printf("%d\n", searchMax());
    }
}

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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nk = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var n = nk[0];
        var k = nk[1];

        long m = n / k;
        long l = (n + k / 2) / k;
        var z = m * m * m + (-k % 2 + 1) * l * l * l;
        Console.WriteLine(z);
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int main(){
    int n;
    cin >> n;
    map<int,int> nums;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        nums[a]++;
    }
    int ans = 0;
    for(auto p: nums){
        if(p.second%2==1) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

#define REP(i,j) for(int i=0;i<j;i++)
#define REPR(i,j) for(int i=j;i>=0;i--)
#define FOR(i,j,k) for(int i=j;i<k;i++)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n = 0;
    char a[3];
    REP(i,3){
        cin >> a[i];
        if(a[i] == '1'){
            n++;
        }
    }
    cout << n << "\n" ;
    return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

		int total = 0, amount = 0, i, p, q;

		i = 0;
		while ((line = br.readLine()) != null) {
			p = Integer.parseInt(line.substring(0, line.indexOf(',')));
			q = Integer.parseInt(line.substring(line.indexOf(',') + 1));
			i++;

			total += p * q;
			amount += q;
		}
		System.out.println(total);
		System.out.println((int) Math.round((double) amount / i));
	}
}

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

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

    bool ju = true;
    for(auto p : m){
        if(p.second != 1) ju = false;
    }
    if(ju){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>            //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x) // also valid for set and multiset
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
int main()
{
 //	ios::sync_with_stdio(0);
 //   cin.tie(0);
    lli a,b,c;
    cin>>a>>b>>c;
    if(a==b && b==c)cout<<"Yes";
    else cout<<"No";
    
    
    return 0;
}


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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	string str;
	cin >> str;
	cout << count(begin(str), end(str), '2') << "\n";
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m;
ll ans=1e18;
void work(int n,int m){
    if(n%3==0)ans=0;
    else{
        ans=min(ans,m*1ll);
        ll x=n/3;
        vector<ll> v;
        v.push_back(x*m),v.push_back((n-x)*(m/2)),v.push_back((n-x)*((m+1)/2));
        sort(v.begin(),v.end());
        ans=min(ans,v[2]-v[0]);
        x=n/3+1;
        v.clear();
        v.push_back(x*m),v.push_back((n-x)*(m/2)),v.push_back((n-x)*((m+1)/2));
        sort(v.begin(),v.end());
        ans=min(ans,v[2]-v[0]);
    }
}
int main(){
    scanf("%d%d",&n,&m);
    work(n,m),work(m,n);
    printf("%lld\n",ans);
    return 0;
}

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

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


Measured memory_bytes: 3580
#include <iostream>
#include <vector>

using namespace std;

const int MAXN = 105;
int a[MAXN];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    int cnt1 = 0;
    for(int i = 0; i < m; i++) {
        cin >> a[i];
        if(a[i] & 1)
            cnt1++;
    }
    if(cnt1 > 2) {
        cout << "Impossible\n";
        return 0;
    }
    if(cnt1) {
        for(int i = 0; i < m; i++)
            if(a[i] & 1) {
                swap(a[i], a[0]);
                break;
            }
        if(cnt1 == 2)
            for(int i = 1; i < m; i++)
                if(a[i] & 1) {
                    swap(a[i], a[m - 1]);
                    break;
                }
    }
    vector<int> b;
    if(a[0] > 1)
        b.push_back(a[0] - 1);
    for(int i = 1; i < m; i++)
        if(a[i] & 1)
            b.push_back(a[i] + 1);
        else
            b.push_back(a[i]);
    if(cnt1 <= 1)
        b.push_back(1);
    for(int i = 0; i < m; i++)
        cout << a[i] << ' ';
    cout << '\n';
    cout << b.size() << '\n';
    for(size_t i = 0; i < b.size(); i++)
        cout << b[i] << ' ';
    cout << '\n';
    return 0;
}


Measured memory_bytes: 256
<?php
$input = trim(fgets(STDIN));
$c = 0;
while($text = trim(fgets(STDIN))){
    if($text == "END_OF_TEXT"){break;}
    $array = explode(" ", strtolower($text));
    $count = array_count_values($array);
    if(isset($count[$input])){
       $c += $count[$input]; 
    }
}echo $c.PHP_EOL;

Measured memory_bytes: 15208
import sys,queue,math,copy,itertools,bisect,collections,heapq

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

    N,K = LI()
    P = LI()

    N0 = 2 ** (N.bit_length())
    st1 = [0] * (2 * N0)
    st2 = [0] * (2 * N0)

    i = N0-1
    for x in P:
        st1[i] = st2[i] = x
        i += 1


    for i in range(N0-2,-1,-1):
        st1[i] = max(st1[i*2+1],st1[i*2+2])
        st2[i] = min(st2[i*2+1],st2[i*2+2])

    def query_max(l, r):
        L = l + N0;
        R = r + N0
        ret = 0
        while L < R:
            if L % 2:
                ret = max(ret, st1[L - 1])
                L += 1
            if R % 2:
                R -= 1
                ret = max(ret, st1[R - 1])
            L //= 2;
            R //= 2
        return ret


    def query_min(l, r):
        L = l + N0;
        R = r + N0
        ret = N + 1  # max value
        while L < R:
            if L % 2:
                ret = min(ret, st2[L - 1])
                L += 1
            if R % 2:
                R -= 1
                ret = min(ret, st2[R - 1])
            L //= 2;
            R //= 2
        return ret


    ans = 0
    cnt = 0
    flg = 0
    bp = N
    for i in range(N):
        if P[i] > bp:
            cnt += 1
        else:
            cnt = 0
        bp = P[i]

        if i < K - 1: continue

        if cnt >= K-1:
            flg = 1
        elif i >= K and query_min(i-K,i) == P[i-K] and query_max(i-K+1,i+1) == P[i]:
            pass
        else:
            ans += 1

    print(ans+flg)


if __name__ == '__main__':
    main()

Measured memory_bytes: 105884
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;
const ll INF = 0x3f3f3f3f3f3f3f3f;
#define DEBUG(x) cout << (x) << '\n'
#define fi first
#define se second

ll a, b, c, d;
ll calc(ll x, ll y){ return x * y; }
void run(){
    cin >> a >> b >> c >> d;
    ll res = max(max(calc(a, c), calc(a, d)), max(calc(b, c), calc(b, d)));
    DEBUG(res);
}
int main(){
#ifdef Irene
    freopen("in.txt", "r", stdin);
#endif // Irene
    ios_base::sync_with_stdio(false);

    run(); return 0;
}


Measured memory_bytes: 3648
N=int(input())
A=list(map(int,input().split()))
Q=int(input())

num=[0]*(1+10**5)
total=0
for i in range(N):
	total+=A[i]
for j in range(N):
	num[A[j]]+=1

for k in range(Q):
	B,C=map(int,input().split())
	total=total+num[B]*(C-B)
	print(total)
	num[C]+=num[B]
	num[B]=0

Measured memory_bytes: 21012
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : "\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
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;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

bool dp[110][10010];
signed main() {
    int n;
    cin>>n;
    vector<int> s(n);
    cin>>s;
    dp[0][0]=true;
    dp[0][s[0]]=true;
    REPF(i,1,n) {
        REP(j,10010) {
            if(dp[i-1][j]) {
                dp[i][j+s[i]]=true;
                dp[i][j]=true;
            }
        }
    }
    int ans=0;
    REP(i,10010) {
        if(dp[n-1][i]) {
            if(i%10!=0) {
                chmax(ans,i);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int n, m;
    cin >> n >> m;
    vector<vector<int>> v(n);
    vector<pair<int, int>> o(m);
    repi(i, m, 0)
    {
        int p, y;
        cin >> p >> y;
        v[p - 1].push_back(y);
        o[i].first = p;
        o[i].second = y;
    }
    repi(i, n, 0)
    {
        sort(v[i].begin(), v[i].end());
    }
    repi(i, m, 0)
    {
        int p = o[i].first,
            y = o[i].second;
        int cnt = 0;
        auto itr = lower_bound(v[p - 1].begin(), v[p - 1].end(), y);
        string pid = "000000",
               yid = "000000";
        pid += to_string(p);
        yid += to_string(distance(v[p - 1].begin(), itr)+1);
        cout << pid.substr(pid.size() - 6) + yid.substr(yid.size() - 6) << endl;
    }
    return 0;
}

Measured memory_bytes: 7808
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
	public static void main(String... args){
		// 入力
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		// 出力
                System.out.println(IntStream.of(a, b, c).sorted().limit(2).sum());
	}
}

Measured memory_bytes: 28884
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
using namespace std;
using ll = long long;
int main(){
  ll n;
  cin >> n;
  vector<ll> a(n+1);
  rep(i,n+1) cin >> a[i];
  vector<ll> b(n);
  rep(i,n) cin >> b[i];
  ll cnt=0;
  
  for(int i=n-1; i >= 0; i--){
//    cout << b[i] << endl;
    if(b[i] >= a[i] + a[i+1]){
      cnt += a[i]+a[i+1];
      a[i]=0;
      a[i+1]=0;
    }
    else if(b[i] >= a[i+1]){
      cnt +=b[i];
      a[i]=a[i]+a[i+1]-b[i];
      a[i+1]=0;
    }
    else{
      cnt+=b[i];
      a[i+1]=a[i+1]-b[i];
    }
//    cout << cnt << endl;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int a,b;
    cin >> a >> b;
    cout << max(0,a-2*b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    long long n,a;
    cin>>n>>a;
    for (int i=0;i<=n;i++)
    {
        for (int j=0;j<=n-i;j++)
        {
            if ((i*10000+j*5000+(n-i-j)*1000)==a)
                {cout<<i<<" "<<j<<" "<<n-i-j<<endl;
                system("pause");
                return 0;}
        }
    }
    cout<<"-1 -1 -1"<<endl;
    system("pause");
    return 0;
}

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

#define    ll     long long int

const int N = 100005;
int ara[N];

int main( )
{
    int n, i, j, k, s = 0;
    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> ara[i];
        s += abs(ara[i] - ara[i - 1]);
    }
    s += abs(ara[i - 1]);
    ara[i] = 0;
    for (i = 1; i <= n; i++) {
        cout << (s - abs(ara[i] - ara[i - 1]) - abs(ara[i + 1] - ara[i]) + abs(ara[i + 1] - ara[i - 1])) << '\n';
    }
    return 0;
}


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

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

    return 0;
}

Measured memory_bytes: 3000
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#define pi 3.14159265358979323846264338
using namespace std;

int main() {
	int a, b, c;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a >> b >> c;
		a *= a;
		b *= b;
		c *= c;
		int d = max(a, max(b, c));
		if (d == (a + b + c) - d) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3040
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        long sum = 0;
        for (int i = 0; i < (1 << (s.length() - 1)); i++) {
            String a = "";
            int x = 0;
            for (int j = 0; j < s.length() - 1; j++) {
                if ((i >> j & 1) == 1) {
                    a = s.substring(x, j + 1);
                    sum += Long.parseLong(a);
                    x = j + 1;
                }
            }
            a = s.substring(x);
            sum += Long.parseLong(a);
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 35684
n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
if a[0] > x:
    ans += (a[0] - x)
    a[0] = x
for i in range(len(a)-1):
    if a[i] + a[i+1] > x:
        ans += (a[i+1] + a[i] - x)
        a[i+1] -= (a[i+1] + a[i] - x)
print(ans)

Measured memory_bytes: 63984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;

int main()
{
  ll N;
  scanf("%lld",&N);
  string S;
  cin >> S;

  ll ans = 1;
  int r=0;
  int g=0;
  int b=0;
  for (int i=0; i<3*N; i++) {
    ll mul = 1;
    if (S[i]=='R') {
      if (r>=max(b,g)) mul = N-r;
      else if (r<min(b,g)) mul = min(b,g)-r;
      else mul = max(b,g)-r;
      r++;
    } else if (S[i]=='G') {
      if (g>=max(b,r)) mul = N-g;
      else if (g<min(b,r)) mul = min(b,r)-g;
      else mul = max(b,r)-g;
      g++;
    } else {
      if (b>=max(r,g)) mul = N-b;
      else if (b<min(r,g)) mul = min(r,g)-b;
      else mul = max(r,g)-b;
      b++;
    }
    ans = ans * mul % mod;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
#include <stdio.h>
typedef long long int LL;
#define fr(i,p,n) for(LL i=p;i<n;i++)
#define fr1(i,p,n) for(LL i=p;i>=n;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define precise cout << std::setprecision(10) << std::fixed;
using namespace std;
const int MAXN = 3002;

double dp[MAXN][MAXN],P[MAXN];
int vis[MAXN][MAXN],N;

double solve(int pos,int heads){
	
	if(heads < 0) return 0.0;

	if(pos == 0){
		return (heads == 0);
	}

	if(vis[pos][heads]) return dp[pos][heads];
	vis[pos][heads] = 1;

	return dp[pos][heads] =  (P[pos])*solve(pos-1,heads-1) + (1.0 - P[pos])*solve(pos-1,heads);

}

int main(){

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

	double tot = 0;
	for(int heads = 0;heads<=N;heads++){
		int tails = N - heads;
		if(heads > tails) tot += solve(N,heads);
	}

    cout<<std::setprecision(10) << std::fixed<<tot<<endl;

    return 0;
}

Measured memory_bytes: 105120
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> divide(long long n){//素因数分解
    map<long long , long long> res;
    for(long long i = 2; i * i <= n; i++){
        while(n % i == 0){
            res[i]++;
            n /= i;
        }
    }
    if(n != 1) res[n] = 1;
    return res;
}
int main(){
    long long N;
    cin >> N;
    map<long long, long long> m;
    m = divide(N);
    long long ans = 0;
    for(auto u: m){
        long long i = 1;
        while(i * (i + 1) / 2 <= u.second){
            i++;
        }
        ans += (i - 1);
    }
    cout<< ans << endl;
}


Measured memory_bytes: 3636
a,b,c,k = map(int,input().split())
# 1  a枚
# 0  b枚
# -1 c枚

ans = 0
if(a >= k):
  ans += k
  k = 0
else:
  ans += a
  k = k - a
  if(b >= k):
    k = 0
  else:
    k = k - b
    ans -= k

print(ans)


Measured memory_bytes: 9172
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }


struct SuffixArray {
	int n, k;
	string s;
	vector<int> ord, tmp, left;
	SuffixArray(const string &s) :s(s), n(s.size()), ord(n + 1), tmp(n + 1), left(n + 1) {
		for (int i = 0; i <= n; i++) {
			left[i] = i;
			ord[i] = i < n ? s[i] : -1;
		}
		auto compare = [&](int i, int j) {
			if (ord[i] != ord[j])return ord[i] < ord[j];
			else {
				int ri = i + k <= n ? ord[i + k] : -1;
				int rj = j + k <= n ? ord[j + k] : -1;
				return ri < rj;
			}
		};
		for (k = 1; k <= n; k *= 2) {
			sort(left.begin(), left.end(), compare);
			tmp[left[0]] = 0;
			for (int i = 1; i <= n; i++) {
				tmp[left[i]] = tmp[left[i - 1]] + (compare(left[i - 1], left[i]) ? 1 : 0);
			}
			ord = tmp;
		}
		dump(ord, tmp, left);
	}
	int search(const string &pattern) {
		int m = pattern.size();
		auto f = [&](int x) {
			string t = s.substr(left[x], min(m, n - left[x]));
			dump(x, t);
			return pattern <= t;
		};
		auto binarySearch = [&](int ng, int ok) {
			if (f(ng))return ng;
			while (ng + 1 < ok) {
				int m = (ng + ok) / 2;
				if (f(m))
					ok = m;
				else
					ng = m;
			}
			return ok;
		};
		int ok = binarySearch(0, n + 1);
		if (ok > n)
			return -1;
		else {
			string t = s.substr(left[ok], min(m, n - left[ok]));
			return pattern == t ? left[ok] : -1;
		}
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string T; cin >> T;
	int Q; cin >> Q;
	SuffixArray sa(T);
	rep(i, 0, Q) {
		string P; cin >> P;
		cout << (sa.search(P) != -1) << endl;
	}
	return 0;
}

Measured memory_bytes: 15868