akhauriyash/Code-Regression huggingface dataset:
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;
int x[M],v[M],sum=0;
int pre[M],back_pre[M];
int suf[M],back_suf[M];
 main()

{
    fast
    int n,c,ses=0;
    cin>>n>>c;
    f(i,1,n)
    {
        cin>>x[i]>>v[i];
    }
    f(i,1,n)
    {
        sum+=v[i];
        pre[i]=max(pre[i-1],(sum-x[i]));
        ses=max(ses,pre[i]);
    }
    sum=0;
    rf(i,n,1)
    {
        sum+=v[i];
        suf[i]=max(suf[i+1],(sum-(c-x[i])));
        ses=max(ses,suf[i]);
    }
   sum=0;
   f(i,1,n)
   {
       sum+=v[i];
       back_pre[i]=max(back_pre[i-1],(sum-2*x[i]));
   }
   sum=0;
   rf(i,n,1)
   {
       sum+=v[i];
       back_suf[i]=max(back_suf[i+1],sum-2*(c-x[i]));
   }
   f(i,1,n)
   {
       int x=back_pre[i]+suf[i+1];
       ses=max(ses,x);
   }
   rf(i,n,1)
   {
       int x=back_suf[i]+pre[i-1];
       ses=max(ses,x);
   }
   cout<<ses<<endl;
    return 0;

}





































Measured memory_bytes: 8316
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
class DIJ{
public:
  struct edge{
    int to,cost,cos;
  };
  vector<vector<edge> >G;
  int n;
  vi d;//distance
  DIJ(int size){
    n=size;
    G=vector<vector<edge> >(n);
  }
  void add_edge(int a,int b,int c,int d){
    edge e={b,c,d},ee={a,c,d};
    G[a].pb(e);
    G[b].pb(ee);
  }
  void dij(int s){
    d=vi(n,inf);
    d[s]=0;
    priority_queue<pii>q;
    q.push(pii(0,s));
    while(!q.empty()){
      pii p=q.top();
      q.pop();
      int pos=p.second,cost=-p.first;
      if(cost>d[pos])continue;
      rep(i,G[pos].size()){
	edge e=G[pos][i];
	int to=e.to;
	int nowcost=cost+e.cost;
	if(nowcost<d[to]){
	  d[to]=nowcost;
	  q.push(pii(-d[to],to));
	}
      }
    }
  }
  int f(){
    int sum=0;
    loop(i,1,n){
      int mi=inf;
      rep(j,G[i].size()){
	edge e=G[i][j];
	int to=e.to;
	if(d[i]-d[to]==e.cost)mi=min(mi,e.cos);
      }
      //     cout<<mi<<endl;
      sum+=mi;
    }
    return sum;
  }
};
int main(){
  int n,m;
  while(cin>>n>>m,n){
    DIJ dij(n);
    while(m--){
      int a,b,c,d;
      cin>>a>>b>>c>>d;
      a--;b--;
      dij.add_edge(a,b,c,d);
    }
    dij.dij(0);
    cout<<dij.f()<<endl;
  }
}

Measured memory_bytes: 3976
#define _USE_MATH_DEFINES
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {
	long long s, t;
	cin >> s >> t;
	long long ans = 0;
	if (2 * s<t) {
		ans += s;
		t -= 2 * s;
		ans += t / 4;
	}
	else if (2 * s == t) {
		ans = s;
	}
	else if (2 * s>t) {
		ans = t / 2;
	}
	cout << ans << endl;

}

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

int main()
{
    int n,i;
    long long int res=0, m=1e9+7, currSum;
    cin>>n;
    vector<long long int> a(n);
    for(long long int& x: a)
        cin>>x;

    currSum=a[n-1];
    for(i=n-2;i>=0;i--)
    {
        res=(res+((a[i]*currSum)%m))%m;
        currSum=((currSum+a[i])%m);
    }
    cout<<res<<endl;
    /*
    cout<<"BruteForce\n";
    res=0;
    for(i=0;i<n-1;i++)
        for(int j=i+1;j<n;j++)
            res=(res+(a[i]*a[j])%m)%m;
    cout<<res<<endl;
    */
    return 0;
}


Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main(){
  int n; cin >> n;
  map<string, int> mp;
  for(int i = 0; i < n; i++){
    string s; cin >> s;
    mp[s]++;
  }
  cout << "AC x " << mp["AC"] << endl;
  cout << "WA x " << mp["WA"] << endl;
  cout << "TLE x " << mp["TLE"] << endl;
  cout << "RE x " << mp["RE"] << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>

int main(void){
    int a, b;
    scanf("%d%d", &a, &b);
    if(a <= 8 && b <= 8){
        printf("%s\n", "Yay!");
        return 0;
    }
    else {
    printf("%s\n", ":(");
    return 0; 
    }
}

Measured memory_bytes: 128
class Bucket:
  def __init__(self, max_size):
    self.__max_size = max_size
    self.__busket = []
    self.__max = 0
    self.__busket_size = 0

  def add(self, price):
    if self.__busket_size < self.__max_size:
      self.__busket.append(price)
      self.__busket_size += 1
      self.__max = max(self.__max, price)
      return self

    if self.__max <= price:
      return self

    self.__busket.remove(self.__max)
    self.__busket.append(price)
    self.__max = max(self.__busket)

  def sum(self):
    return sum(self.__busket)

if __name__ == "__main__":
  n, k = map(int, input().split(' '))
  price_list = list(map(int, input().split(' ')))
  b = Bucket(k)
  for p in price_list:
    b.add(p)
  
  print(b.sum())
  

Measured memory_bytes: 9240
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include "bits/stdc++.h"
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, X, Y, par[MAXN], deep[MAXN];
vector<int> a[MAXN];

void dfs(int u, int p) {
    deep[u] = 0;
    FOR(i,0,SZ(a[u])-1) {
        int v = a[u][i];
        if (v == p) continue;
        par[v] = u;
        dfs(v, u);
        deep[u] = max(deep[u], deep[v] + 1);
    }
}

int getDist(int u, int v) {
    int res = 0;
    while (v != u) {
        v = par[v];
        res++;
    }
    return res;
}

int getParent(int u, int num) {
    while (num--) u = par[u];
    return u;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> X >> Y;
    FOR(i,1,n-1) {
        int u, v;
        cin >> u >> v;
        a[u].emplace_back(v);
        a[v].emplace_back(u);
    }
    dfs(Y, 0);
    int d = getDist(Y, X);
    int res = (d - 1) / 2 + (d % 2 == 0);
    int u = getParent(X, (d-1)/2);
    res += deep[u];
    cout << res;
    return 0;
}

Measured memory_bytes: 12928
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include <map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
#include <complex>
using namespace std;
#define eps 0.000001
#define LONG_INF 10000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 65536*4
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	string s;
	cin >> s;
	int a = (s[5] - '0');
	a *= 10;
	a += (s[6] - '0');
	if (a >= 5) {
		cout << "TBD" << endl;
	}
	else {
		cout << "Heisei" << endl;
	}
	return 0;
}


Measured memory_bytes: 888
a = 3.times.map { gets.split.map(&:to_i) }
yes = 2.times.all? do
  a = a.transpose
  2.times.all? do |i|
    a[i][1] - a[i][0] == a[i+1][1] - a[i+1][0] && a[i][2] - a[i][1] == a[i+1][2] - a[i+1][1]
  end
end
puts yes ? "Yes" : "No"


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

#define MOD 1000000007 // 1e9+7
#define PI acos(-1.0)
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

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

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

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

  int n,k,x,y;cin>>n>>k>>x>>y;
  int ans;
  if(n<=k){
    ans=x*n;
  }else{
    ans=x*k+y*(n-k);
  }
  P(ans);
  return 0;
}


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

public class Hello{
    public static void Main(){
        var S = Console.ReadLine();
        var K = int.Parse(Console.ReadLine());
        
        var list = new List<string>();
        for(var i = 0;i < K;i++){//文字列の長さを１つづつ増やす
            for(var j = 0;j < S.Length - i;j++){//
                list.Add(S.Substring(j,i + 1));
            }
        }
        
        var sub = list.OrderBy(s => s).Distinct().ToList();
        Console.WriteLine(sub[K - 1]);
    }
}


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

int main() {
    int x,y,z;
    cin >> x >> y >> z;
    int i=1;
    while(1){
        if((y*i+z*(i+1))>x){
            cout << i-1 << endl;
            break;
        }
        i++;
    }
}

Measured memory_bytes: 256
def my_print(s, a, b):
    print(s[a:b+1])

def my_reverse(s, a, b):
    return s[:a] + s[a:b+1][::-1] + s[b+1:]

def my_replace(s, a, b, p):
    return s[:a] + p + s[b+1:]

if __name__ == '__main__':
    s = input()
    q = int(input())
    for i in range(q):
        code = input().split()
        op, a, b = code[0], int(code[1]), int(code[2])
        if op == 'print':
            my_print(s, a, b)
        elif op == 'reverse':
            s = my_reverse(s, a, b)
        elif op == 'replace':
            s = my_replace(s, a, b, code[3])

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

using namespace std;

long long int Q, l[100001] = {}, r[100001] = {}, ans = 0, num[100001] = {};
vector<long long int> s;
bool p[100001] = {};

int main() {
	cin >> Q;
	for (int i = 1; i <= Q; i++)cin >> l[i] >> r[i];
	s.push_back(2);
	p[2] = true;
	num[1] = 0;
	for (int i = 3; i <= 100000; i += 2) {
		for (int j = 0; j <s.size(); j++) {
			if (s[j] * s[j] > i) {
				s.push_back(i);
				p[i] = true;
				break;
			}
			if (i%s[j] == 0)break;
			if (j == s.size()) {
				s.push_back(i);
				p[i] = true;
			}
		}
		if (p[i] && p[(i + 1) / 2]) {
			num[i] = num[i - 2] + 1;
		}
		else {
			num[i] = num[i - 2];
		}
	}
	for (int i = 1; i <= Q; i++) {
		if (l[i] > 1) {
			cout << num[r[i]] - num[l[i] - 2] << endl;
		}
		else {
			cout << num[r[i]] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
using namespace std;
int main(void){
   
   for(;;){
   int h,w;
   
   cin>>h>>w;
   
   if(!h) break;
   
   for(int i=0;i<h;i++){
     
     for(int j=0;j<w;j++) cout<<((i+j)%2?".":"#");
     cout<<endl;
   }
   
   cout<<endl;
   
}
   
}



Measured memory_bytes: 3096
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
int main() {
	int n, m, k, c;
	while (cin >> n&&n != 0) {
		bool a[101][101];
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) a[i][j] = false;
		}
		for (int i = 1; i <= n; i++) {
			cin >> m;
			for (int j = 0; j < m; j++) {
				cin >> c;
				a[i][c] = true;
			}
		}
		cin >> k;
		int d[101];
		for (int i = 0; i < k; i++) {
			cin >> c;
			d[i] = c;
		}
		vector<int>e;
		for (int i = 1; i <= n; i++) {
			for (int j = 0; j < k; j++) {
				if (!a[i][d[j]]) goto stop;
			}
			e.push_back(i);
		stop:;
		}
		if (e.size() == 1) cout << e[0] << endl;
		else cout << -1 << endl;
	}
}

Measured memory_bytes: 3120
Module Module1
    Sub Main()
        Dim x, a, b, c, a0, b0, c0, cnt As Integer
    
        a0 = Int(Console.ReadLine)
        b0 = Int(Console.ReadLine)
        c0 = Int(Console.ReadLine)
        x = Int(Console.ReadLine)
        
        cnt = 0
        For a = 0 To a0             '500円玉
            For b = 0 To b0         '100円玉
                For c = 0 To c0     ' 50円玉
                    If 500 * a + 100 * b + 50 * c = x Then
                        cnt = cnt + 1
                    End If
                Next c
            Next b
        Next a

        Console.WriteLine (cnt)

    End Sub
End Module


Measured memory_bytes: 13268
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline
n = int(input())
ab = []
for _ in range(n):
    a,b = map(int, input().split())
    ab.append((a,b))

ab.sort(key=lambda x:x[1])

t = 0
for i in range(n):
    t += ab[i][0]
    if t>ab[i][1]:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 31868
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++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 pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;

    while (cin >> n && n) {
        vector<char> c(n);
        REP(i,n) cin >> c[i];
        vector<pair<int, char> > v(26);
        REP(i,26) v[i].second = 'A'+i;
        REP(i,n){
            v[c[i]-'A'].first--;
            vector<pair<int, char> > vp(v);
            sort(vp.begin(), vp.end());
            int x = -vp[0].first, y = -vp[1].first;
            if (x - y > n - i - 1){
                cout << vp[0].second << " " << i+1 << endl;
                break;
            }
            if (i == n-1){
                cout << "TIE" << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3032
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define FORl(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORDl(i, a, b) for (ll i = (a); i >= (b); i--)
using namespace std;
int main () {
  int id;
  FOR(i, 1, 5) {
    int t;
    scanf("%d", &t);
    if (!t) id = i;
  }
  printf("%d\n", id);
  return 0;
}

Measured memory_bytes: 3760
import sys
# sys.setrecursionlimit(100000)
from collections import Counter


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    S = input()
    S_cnt = Counter(S).most_common()

    def simulation(org, target):
        cnt = 0
        while org.count(target) != len(org):
            t = ""
            for i in range(len(org) - 1):
                if org[i] == target or org[i + 1] == target:
                    t += target
                else:
                    t += org[i]
            cnt += 1
            org = t
        return cnt
    ans = float("inf")
    for k, v in S_cnt:
        ans = min(simulation(S, k), ans)
    print(ans)

    return


if __name__ == "__main__":
    main()


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

int main() {
    int h, n, sum=0;
    cin >> h >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
        sum += a.at(i);
    }
    cout << (sum >= h ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 640
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;
int n;
int ar[100005];
const int mod=1000000007;
int main(){
  cin>>n;
  REP(i,n) cin>>ar[i];

  int ever=0;
  lint res=1;
  REP(i,n){
    if(ar[i]<=ever*2){
      res=res*(ever+1)%mod;
    }else{
      ++ever;
    }
  }
  while(ever>0) res=res*ever%mod,--ever;
  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 640
import java.util.Scanner;

class Main {

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

		int str1 = scan.nextInt();
		int str2 = scan.nextInt();
		
		int i = 0;
		
		while(str1 != 0 && str2 != 0){
			for(i = 0; i < str1; i++){
				System.out.print("#");
				for(int j = 1; j < str2 - 1; j++){
					if(i == 0 || i == str1 - 1){
						System.out.print("#");
					}else{
						System.out.print(".");
				}
				}
				System.out.print("#");
				System.out.println();
			}
			System.out.println();
			str1 = scan.nextInt();
			str2 = scan.nextInt();

		}
		
	}
}

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

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

const int CASES = 2;


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

    vector<ll> ands;
    for(int i = 0; i < N ; ++i){
        ll tmp = A[i];
        ands.push_back(tmp);
        for(int j = 1; i + j < N ; ++j){
            tmp += A[i + j];
            ands.push_back(tmp);
        }
    }

    ll ans = 0;
    for(ll i = 61; i >= 0; --i){
        vector<ll> vec;
        ll tmp = (1LL << i);
        for(int j = 0; j < ands.size(); ++j){
            if( (ands[j] & tmp) != 0){
                vec.push_back(ands[j]);
            }
        }

        if(vec.size() >= K){
            ands = vec;
            ans |= tmp;
        }
    }

    cout << ans << '\n';
}



int main() {
    #ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
    #else

    solve();

    #endif
    return 0;
}



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

using namespace std;

int main()
{
    int N;
    cin >>N;
    vector<int> h(N);
    for(int i=0;i<N;i++)
        cin >>h[i]; 
    vector<int> dp(N);

    dp[0]=0;
    dp[1]=abs(h[0]-h[1]); 

    for(int i=2;i<N;i++)
    {
        dp[i] = min(dp[i-1]+abs(h[i-1]-h[i]), dp[i-2]+abs(h[i-2]-h[i])); 
    }
    cout <<dp[N-1]<<endl ; 
    

    return 0; 
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define AB_BHI_NI_DEGI                \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
#define int long long
#define pb push_back
#define N 100009
#define inf 1e18
const double PI = 3.141592653589793238462643383279;
int mod = 1e9 + 7;
//int mod = 998244353;
#define P pair<int, int>
#define F first
#define S second
#define ll long long
#define all(v) v.begin(), v.end()
#define vi vector<int>
#define ld long double

#define ordered_set tree<P, null_type, less<P>, rb_tree_tag, tree_order_statistics_node_update>

void end(int n = -1)
{
	cout << n << "\n";
	exit(0);
}
int n;
int a[3009];
int dp[3009][3009][2];
bool vis[3009][3009][2];

int fun(int i, int j, int ch)
{
	if (i > j)
		return 0;
	if (vis[i][j][ch])
		return dp[i][j][ch];
	int ans = 0;
	if (!ch)
	{
		ans = max(a[i] + fun(i + 1, j, !ch), a[j] + fun(i, j - 1, !ch));
	}
	else
	{
		ans = min(-a[i] + fun(i + 1, j, !ch), -a[j] + fun(i, j - 1, !ch));
	}
	vis[i][j][ch] = 1;
	return dp[i][j][ch] = ans;
}

int32_t main()
{
	AB_BHI_NI_DEGI
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	cout << fun(0, n - 1, 0) << "\n";

	return 0;
}

Measured memory_bytes: 158208
#include <iostream>

using namespace std;

int as[1000000];

int main(){
  int n;
  for(;;){
    cin >> n;
    if(cin.eof()) break;

    for(int i=1; i<=n; i++)
      as[i]=i;

    for(int i=2; i<=n; i++){
      if(as[i]==-1)
	continue;
      else
	for(int j=2*i; j<=n; j+=i)
	  as[j]=-1;
    }

    int cnt=0;
    for(int i=2; i<=n; i++)
      if(as[i]!=-1)
	cnt++;

    cout << cnt << endl;
  }
}

Measured memory_bytes: 4772
#include<stdio.h>
int main(void)
{
    int N,A,B,S=0;
    int i,S1,S2,S3,S4,S5=0;
  
    scanf("%d%d%d",&N,&A,&B);
  
    for(i=1;i<=N;i++){
      S1=i%10000;
      S2=S1%1000;
      S3=S2%100;
      S4=S3%10;
      S=i/10000+S1/1000+S2/100+S3/10+S4;
      if((S>=A)&&(S<=B)) S5+=i;
    }
    printf("%d\n",S5);
  
    return 0;
}
      
      

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
using int64 = long long;

int main() {
    int n, q;
    string s;
    cin >> n >> q >> s;
    vector<int> a, c;
    for (int i=1; i<n; i++) {
        if (s[i-1]=='A' && s[i]=='C') {
            a.push_back(i-1);
            c.push_back(i);
        }
    }

    for (int i=0; i<q; i++) {
        int l, r;
        cin >> l >> r;
        l--; r--;
        auto li = lower_bound(a.begin(), a.end(), l);
        if (li == a.end()) {
            cout << 0 << endl;
            continue;
        }
        auto ri = lower_bound(c.begin(), c.end(), r);
        if (ri == c.end() || *ri != r) ri--;

        cout << (ri-c.begin())-(li-a.begin())+1 << endl;
    }
}


Measured memory_bytes: 1596
//問題４　2704上石彩花
import java.util.Scanner;
public class Main{
	public void solve(){
		Scanner sc=new Scanner(System.in);
		int N,x;
		
		while(true){
			N=sc.nextInt();
			if(N==0) break;
			int cnt=0;
			boolean flag=false;
			for(int i=0;i<N;i++){
				x=sc.nextInt();
				if(x>0)
				cnt++;
				if(x>1)
				flag=true;
			}
			
			if(!flag)
			System.out.println("NA");
			else
			System.out.println(cnt+1);
		}
	}
	
	public static void main(String[]args){
		Main obj=new Main();
		obj.solve();
	}
}

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

int main() {
	int n;
	cin >> n;
	set<char> st;
	for (int i = 0; i < n; i++) {
		char c;
		cin >> c;
		st.emplace(c);
	}
	cout << (st.size() == 3 ? "Three" : "Four") << endl;
	return 0;
}

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

typedef long long ll;

int main()
{
    ll x, l, r, m;
    cin >> x;
    l = 1, r = x;
    while (l < r) {
        m = (l + r) >> 1;
        if ((m * (m+1))/2 >= x)
            r = m;
        else
            l = m+1;
    }

    cout << l << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    string s;
    cin>>n;
    set<string>a;
    for(i=0;i<n;i++)
    {
        cin>>s;
        a.insert(s);
    }
    cout<<a.size()<<endl;


    return 0;
}



Measured memory_bytes: 19256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
string S,ans;
int main()
{
	int n,k;
	cin>>n>>k;
	cin>>S;
	char mnc='z'+1;
	for(int i=0;i<n;i++)
		mnc=min(mnc,S[i]);
	for(int i=n-1;i>=0;i--)
		S+=S[i];
	int len=0;
	int cur=0;
	for(int i=0;i<n*2;i++)
	{
		if(S[i]==mnc)cur++;
		else cur=0;
		len=max(len,cur);
	}
	int llen=len;
	for(int i=1;i<k;i++)
	{
		llen<<=1;
		if(llen>=n){
			for(int j=0;j<n;j++)
				printf("%c",mnc);
			printf("\n");
			return 0;
		}
	}
	for(int i=0;i<n-llen;i++)
		ans+='z'+1;
	cur=0;
	for(int i=0;i<n*2;i++)
	{
		if(S[i]==mnc)cur++;
		else cur=0;
		if(cur==len&&i>=n){
			string tmp=S.substr(i-n-len+llen+1,n-llen);
			for(int j=0;j<n-llen-j-1;j++)
				swap(tmp[j],tmp[n-llen-1-j]);
			ans=min(ans,tmp);
		}
	}
	for(int i=0;i<llen;i++)
		printf("%c",mnc);
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
N = int(input())
count = [[0]*10 for i in range(10)]
ans = 0
for i in range(1,N+1):
    s = str(i)
    l = int(s[0])
    r = int(s[-1])
    count[l][r] += 1
for i in range(1,10):
    for j in range(1,10):
        ans += count[i][j] * count[j][i]
print(ans)


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

int main(){
    int a[10]={0};
    int temp;
    for(int i=0;i<10;i++){
        cin>>a[i];
    }
    int i=0;
    for(int j=0;j<=8;j++)
        for(i=0;i<=8;i++)
            if(a[i]<a[i+1]){
                temp=a[i];
                a[i]=a[i+1];
                a[i+1]=temp;
                }
    cout<<a[0]<<endl;
    cout<<a[1]<<endl;
    cout<<a[2]<<endl;        
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
//コピペするとこ



//-------------------------------------------------


int main()
{
  int r ;
  cin >> r ;
  cout << r*r <<endl ;

  return 0 ;
}




Measured memory_bytes: 256
/*input
4
ushi
tapu
nichia
kun
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=4e5+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
map<string,int> mp;
int32_t main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n;
    cin>>n;
    REP(i,n){
        string s;
        cin>>s;
        mp[s]++;
    }
    int x=0;
    for(auto z:mp){
        MXTO(x,z.s);
    }
    for(auto z:mp){
        if(z.s==x){
            cout<<z.f<<'\n';
        }
    }
}

Measured memory_bytes: 23808
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

const int MAX = 1e6+1;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
  if(n >= MAX){
    ll tmp = 1;
    rep(i,k){
      tmp *= (n-i);
      tmp %= MOD;
    }
    return tmp*finv[k]%MOD;
  }

  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll POW(ll x, ll n){
  ll ret = 1;

  if(n < 0){// n < 0 にも対応
    n *= -1;
    x = inv[x];
  }

  while(0 < n){
    if(n%2 == 0){
      x = x*x%MOD;
      n /= 2;
    }
    else{
      ret = ret*x%MOD;
      n--;
    }
  }

  return ret;
}

vi MP(string s){
  vi A(s.size()+1);
  A[0] = -1;
  int j = -1;
  rep(i,s.size()) {
    while(j >= 0 && s[i] != s[j]) j = A[j];
    j++;
    A[i+1] = j;
  }
  return A;
}

vi Manacher(string s){
  vi R(s.size());
  int i = 0, j = 0;
  while(i < s.size()){
    while(i-j >= 0 && i+j < s.size() && s[i-j] == s[i+j]) ++j;
    R[i] = j;
    int k = 1;
    while(i-k >= 0 && i+k < s.size() && k+R[i-k] < j) R[i+k] = R[i-k], k++;
    i += k; j -= k;
  }
  return R;
}

vi Z_algorithm(string &s){
  vi Z(s.size());
  Z[0] = s.size();
  int i = 1, j = 0;
  while(i < s.size()){
    while(i+j < s.size() && s[j] == s[i+j]) j++;
    Z[i] = j;
    if(j == 0){++i; continue;}
    int k = 1;
    while(i+k < s.size() && k+Z[k] < j) Z[i+k] = Z[k], ++k;
    i += k; j -= k;
  }
  return Z;
}

// z

int main(){
  int n; string s;
  cin >> n >> s;
  int ans = 0;
  rep(i,n) {
    string t = s.substr(i);
    vi Z = Z_algorithm(t);
    rep(j,t.size()) {
      chmax(ans,min(j,Z[j]));
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int n, a;

	cin >> n >> a;

	

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

	

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int x,y;
	cin >> x >> y;
	if( x<y ){
		swap(x,y);
	}
	while(1){
		if( y==0 )break;
		int tmp=x%y;
		x=y;
		y=tmp;
		//cout << x <<" "<<y << endl;
	}
	cout << x<<endl;
	return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define RS resize
#define CLR clear
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
#define LLI long long int
using namespace std;
template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename T> T gcd(T a, T b){a = abs(a); b = abs(b); if(a<b) swap(a,b); while(b>0){a %= b; swap(a,b);} return a;}
template <typename T> T lcm(T a, T b){return (1LL * a * b) / gcd(a,b);}
template <typename T, typename U> P<T,U> operator+(const P<T,U> &a, const P<T,U> &b){return {a.first + b.first, a.second + b.second};}
template <typename T, typename U> P<T,U> operator-(const P<T,U> &a, const P<T,U> &b){return {a.first - b.first, a.second - b.second};}

const int inf = INT_MAX;

template <typename T>
class SegmentTree{
private:
  int size;
  vector<T> vec;
  T e;
  function<T(T,T)> f;
  function<T(T,T)> upd;
  
  int aux(int x, int y, int i, int l, int r){
    if(r<=x || y<=l) return e;
    else if(x<=l && r<=y) return vec[i];
    else return f(aux(x,y,i*2+1,l,(l+r)/2), aux(x,y,i*2+2,(l+r)/2,r));
  };

public:
  SegmentTree(int n, T e, function<T(T,T)> f, function<T(T,T)> upd):
    size((1<<((int)ceil(log(n)/log(2))+1))-1), vec(size, inf), f(f), e(e), upd(upd){}
  void update(int i, T x){
    int j = i+(size+1)/2-1;
    vec[j] = upd(vec[j], x);
    --j;
    while(j>=0){
      vec[j/2] = f(vec[(j/2)*2+1], vec[(j/2)*2+2]);
      (j /= 2) -= 1;
    }
  }

  int find(int x, int y){return aux(x,y,0,0,(size+1)/2);}
};


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

  int n,q; cin >> n >> q;
  SegmentTree<int> rmq(n, inf, [](int a, int b){return min(a,b);}, [](int a, int b){return b;});

  REP(i,q){
    int com,x,y; cin >> com >> x >> y;
    if(com){
      cout << rmq.find(x,y+1) << endl;
    }else{
      rmq.update(x,y);
    }
  }
  
  return 0;
}



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

int main() {
    long long x;
    cin >> x;
    x++;

    int ans = 0;
    long long sum = 0;
    long long curr = 1;

    while (2*sum+curr <= x) {
        ans++;
        sum += curr;
        curr *= 3;
    }

    ans += ans-1;
    curr /= 3;
    sum += sum-curr;
    while (curr >= 1) {
        if (sum + curr <= x) {
            ans++;
            sum += curr;
        } else {
            curr /= 3;
        }
    }

    cout << ans-1 << endl;

}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
const int ZDN=1e3+8;
char a[ZDN]={};
int main(){
	cin>>a;
	int len=strlen(a);
	if ('s'==a[len-1]){
		a[len]='e';
		a[len+1]='s';
	} else{
		a[len]='s';
	}
	cout<<a<<"\n";
	return 0;
}

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

int main() {

    int sx,sy,tx,ty;

    cin >> sx >> sy >> tx >> ty;

    string ans = "";

    for(int i=sx; i<tx; i++){
        ans += 'R';
    }

    for(int i=sy; i<ty; i++){
        ans += 'U';
    }

    for(int i=tx; i!=sx; i--){
        ans += 'L';
    }

    for(int i=ty; i!=sy; i--){
        ans += 'D';
    }

    ans += 'D';

    for(int i=sx; i<tx+1; i++){
        ans += 'R';
    }

    for(int i=sy; i<ty+1; i++){
        ans += 'U';
    }

    ans += 'L';

    ans += 'U';

    for(int i=tx; i!=sx-1; i--){
        ans += 'L';
    }

    for(int i=ty; i!=sy-1; i--){
        ans += 'D';
    }

    ans += 'R';

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int i, j, n, n1, ten[1000] = { 0 }, a, b, c, d, jun[10000];
	cin >> n;
	n1 = n*(n - 1) / 2;
	for (i = 0; i < n1; i++){
		cin >> a >> b >> c >> d;
		if (c > d){
			ten[a] += 3;
		}
		else if (d > c){
			ten[b] += 3;
		}
		else{
			ten[a]++;
			ten[b]++;
		}
	}
	for (i = 0; i < n1; i++){
		for (j = 0; j < n1; j++){
			if (ten[i] < ten[j]){
				jun[i]++;
			}
		}
	}

	for (i = 1; i < n + 1; i++){
		jun[i]++;
		cout << jun[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3124
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <limits>
using namespace std;
typedef long long ll;
 
#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 FOREACH(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
 
int main() {

    ll H,W;
    cin >> H >> W;

    if(H % 3 == 0 || W % 3 == 0) {
        cout << 0 << endl;
    } else {
        ll ans = 1e18;
        ll W1 = W / 2;
        ll W2 = W / 2 + W % 2;
        for(ll i=1; i<=H-1; i++) {
            ll T1 = i * W;
            ll T2 = W1 * (H - i);
            ll T3 = W2 * (H - i);
            vector<ll> anst = {T1,T2,T3};
            sort(anst.begin(),anst.end());
            ans = min(ans,anst[2] - anst[0]);
        }
        ll H1 = H / 2;
        ll H2 = H / 2 + H % 2;
        for(ll i=1; i<=W-1; i++) {
            ll T1 = i * H;
            ll T2 = H1 * (W - i);
            ll T3 = H2 * (W - i);
            vector<ll> anst = {T1,T2,T3};
            sort(anst.begin(),anst.end());
            ans = min(ans,anst[2] - anst[0]);
        }
        for(int i=1; i<=(W-1)/2; i++) {
            ll W1 = W - i*2;
            ll W2 = i;
            ll diff = abs((W1 * H) - (W2 * H));
            ans = min(ans,diff);
        }
        for(int i=1; i<=(H-1)/2; i++) {
            ll H1 = H - i*2;
            ll H2 = i;
            ll diff = abs((H1 * W) - (H2 * W));
            ans = min(ans,diff);
        }
        cout << ans << endl;
    }

    return 0;
}

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

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static long cnt=0;
	public static PrintWriter pw = new PrintWriter(System.out);
	public static ArrayDeque<int[]> que = new ArrayDeque<>();
	public static boolean[] canMove ;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
		pw.flush();
		pw.close();
	}

	public static void solution(String[] args) throws Exception{

		int N = nextInt();
		int M = nextInt();
		canMove = new boolean[N+1];
		Arrays.fill(canMove, true);
		canMove[1]=false;
		ArrayList<Integer>[] list = new ArrayList[N+1];
		for(int i=0;i<list.length;i++){
			list[i] = new ArrayList<>();
		}
		for(int i=0;i<M;i++){
			int A =nextInt();
			int B =nextInt();
			list[A].add(B);
			list[B].add(A);
		}

		int[] ans = new int[N+1];
		Arrays.fill(ans, -1);
		que.add(new int[]{1,1});
		bfs(1,1,list,ans);

		for(int i=2;i<ans.length;i++){
			if(ans[i]==-1){
				System.out.println("No");
				return;
			}
		}

		System.out.println("Yes");
		for(int i=2;i<ans.length;i++){
			pw.println(ans[i]);
		}


	}

	public static void bfs(int parent ,int now, ArrayList<Integer>[] list ,int[] ans){

		while(que.size()!=0){
			int[] tmp = que.poll();
			parent=tmp[1];
			now=tmp[0];

			ans[now]=parent;

			if(list[now].size()==0){
				return;
			}
			for(int n:list[now]){
				if(canMove[n]==true){
					canMove[n]=false;
					que.add(new int[]{n,now});
				}
			}
		}
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}

}



Measured memory_bytes: 64052
# _*_ coding:utf-8 _*_
#  Atcoder_Beginners_Contest118-B
#  TODO https://atcoder.jp/contests/abc118/tasks/abc118_b

def solveProblem(persons,kinds,orgDataSet):
	kindsDict=[0 for i in range(0,kinds,+1)]
	for i in range(0,persons,+1):
		eachLine = orgDataSet[i]
		length = len(eachLine)
		for j in range(1,length,+1):
			likeKind = eachLine[j]-1
			kindsDict[likeKind]=kindsDict[likeKind]+1
	agreePerson = 0
	for i in range(0,len(kindsDict),+1):
		if kindsDict[i] == persons:
			agreePerson = agreePerson + 1
	answer = agreePerson
	return answer


if __name__ == '__main__':
	N,M = map(int,input().strip().split(' '))
	dataList = []
	for i in range(0,N,+1):
		dataList.append(list(map(int,input().strip().split(' '))))
	solution = solveProblem(N,M,dataList)
	print("{}".format(solution))


Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (int)(n); i++
using namespace std;

int main() {
	int n;cin>>n;
	deque<int> d;
	int a,b,c;
		for (int i = 0; i < n; i++) {
			cin >> a >> b;
				if (a == 0) {
					cin >> c;
						if (b == 0) {
							d.push_front(c);
						}
						else {
							d.push_back(c);
						}
				}
				else if (a == 1) {
					cout << d[b] << endl;
				}
				else {
					if (b == 0) {
						d.pop_front();
					}
					else {
						d.pop_back();
					}
				}
		}
}




Measured memory_bytes: 4664
if __name__ == '__main__':

	N = int(input())
	S = input()

	A = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

	ans = ""
	for i in S:
		ans += A [ ( A.index(i) + N ) % 26 ]

	print(ans)


Measured memory_bytes: 3064
from collections import deque

S = deque(list(input()))

ans = 0
while len(S) > 1:
    l = S.popleft()
    r = S.pop()
    if l == r:
        continue
    elif l == 'x':
        ans += 1
        S.append(r)
    elif r == 'x':
        ans += 1
        S.appendleft(l)
    else:
        print(-1)
        exit()
print(ans)


Measured memory_bytes: 10704
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
int dxx[8] = { 1, 1, 1, 0, 0, -1, -1, -1 }, dyy[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int n, m, q;
ll a[55], b[55], c[55], d[55];

ll dfs (vector<int>& A) {
    if (A.size() == n) {
        ll sum = 0;
        rep (i, q) {
            if (A[b[i] - 1] - A[a[i] - 1] == c[i]) sum += d[i];
        }
        return sum;
    }
    int last = 1;
    if (!A.empty()) last = A[A.size() - 1];
    ll ans = 0;
    for (int i = last; i <= m; i++) {
        A.push_back (i);
        ans = max (ans, dfs (A));
        A.pop_back();
    }
    return ans;
}

int main() {
    cin >> n >> m >> q;
    rep (i, q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    vector<int> vec;
    cout << dfs (vec) << "\n";
}

Measured memory_bytes: 3644
function Main(input) {
    input = input.split(" ");
    var m = Number(input[0]);
    var n = Number(input[1]);
    var a = ((n+1) * (m +1));
    console.log(a - ((((n+1)*2)+((m+1)*2))-4))
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

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

    int n;
    cin >> n;

    int base;
    cin >> base;
    int res = 1;

    rep1(i, n){
        int p;
        cin >> p;

        if(p<base){
            ++res;
            base = p;
        }
    }
    cout << res << endl;

    return 0;
}

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

pf={}

for i in range(2,int(m**0.5)+1):
    while m%i==0:
        pf[i]=pf.get(i,0)+1
        m//=i
if m>1:pf[m]=1

sum = 0
for key in pf:
    if pf[key] > 1:
        i = 1
        d = pf[key]
        while True:
            if d - i >= 0:
                d-=i
                sum+=1
                i+=1
            else:
                break
    else:
        sum+=1


print(sum)

Measured memory_bytes: 63524
#include <math.h>
#include <bits/stdc++.h>//一括で読み込み
typedef long long ll;
using namespace std;

int main() 
{
  ll n,m;
  string s;
  cin>>n>>m>>s;
  ll mod = 1000000007;
  int l = 0, r = 0;
  set<ll> setll;
  ll hash[n+1], p[n+1];
  hash[0] = 0;//[0]=0, [1]=s[0], [2]=[1]*mod+s[1]…
  p[0] = 1;//[0]=1, [1]=mod, [2]=mod^2…
  
  for(ll i = 0; i < n; i++)//文字列の長さ回
  {
    hash[i+1] = hash[i]*mod + s[i];
    p[i+1] = p[i]*mod;
  }
  
  for(ll i = 0; i < m; i++)
  {
    string q;
    cin>>q;
    if(q == "R++") r++;
    if(q == "R--") r--;
    if(q == "L++") l++;
    if(q == "L--") l--;
    setll.insert(hash[r+1] - hash[l]*p[r-l+1]);
  }

  cout<<setll.size()<<endl;
  return 0;
}


Measured memory_bytes: 21912
N = int(input())
H = list(map(int, input().split()))
H = list(reversed(H))

hi = 0
s = 0
while s < N:
    h = s
    while h + 1 < N and H[h+1] >= H[h]:
        h += 1
    hi = max(hi, h - s)
    s = h + 1

print(hi)


Measured memory_bytes: 63984