akhauriyash/Code-Regression huggingface dataset:
def resolve():
	s = input()
	k = 0
	for i in range(1 << len(s)-1):
		ts = s
		a = 1
		for j in range(len(s)):
			if ((i >> j) & 1):
				k += int(ts[:a] or 0)
				ts = ts[a:]
				a = 1
			else:
				a += 1
		k += int(ts or 0)
	print(k)

resolve()

Measured memory_bytes: 39536
import java.util.*;

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


Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define db long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IT iterator
 
#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define EB emplace_back
#define fi first
#define se second
 
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define UPD(x,y) (((x)+=(y))>=mo?x-=mo:233)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
 
#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2
 
#define inf 1e18
#define sqr(x) ((x)*(x))
using namespace std;
int n,ans,a[300005];
map<int,int> mp;
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	Rep(i,n,1){
		bool fl=0;
		for (int j=1;;){
			if (mp[j-a[i]]){
				mp[j-a[i]]--;
				fl=1;
				ans++;
				break;
			}
			if (j==(1<<30)) break;
			j*=2;
		}
		if (!fl) mp[a[i]]++;
	}
	printf("%d\n",ans);
} 

//

Measured memory_bytes: 300288
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  string s;
  cin >> s;

  int total = 0;
  for (auto &x: s) total += x - '0';

  if (total % 9 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 3760
#include<iostream>
#include<vector>
#include<set>
#include<map>
using namespace std;

// ???
int main(){
    int n;
    string s;
    cin >> n >> s;

    vector<vector<int>> dp(n, vector<int>(n, 0));
    for(int i = 1; i < n; i++){
        if(s[0] == s[i])    dp[0][i] = 1;
    }

    for(int i = 1; i < n; i++){
        for(int j = i+1; j < n; j++){
            if(s[i] != s[j])    continue;
            if(i < j-dp[i-1][j-1])  dp[i][j] = dp[i-1][j-1]+1;
        }
    }

    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 98176
#pragma GCC optimize (2)
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <deque>
#define INF 0x3f3f3f3f
#define NO 1000005
#define MO 10005
#define P 1000000007
#define mp(x, y) make_pair(x, y)
#define fi first
#define se second
#define lln putchar('\n')
typedef long long ll;
typedef double db;
using namespace std;
typedef pair<int, int> pii;
inline ll read()
{
	char ch = ' ', last;
	ll ans = 0;
	while (ch < '0' || ch > '9')
		last = ch, ch = getchar();
	while (ch >= '0' && ch <= '9')
		ans = ans * 10 + int(ch - '0'), ch = getchar();
	if (last == '-')
		return -ans;
	return ans;
}
void write(ll x)
{
	if (x >= 10)
		write(x / 10);
	putchar(x % 10 + '0');
}
//head

map<string, int> mp;
int a1[NO];
string a[NO];
int n, cnt;
//variable

void init()
{
    n = read();
    cnt = 1;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[cnt];
        for (int i = 1; i <= a[cnt].length(); i++)
        	a1[i] = a[cnt][i - 1] - 'a';
        sort(a1 + 1, a1 + 1 + a[cnt].length());
        for (int i = 1; i <= a[cnt].length(); i++)
        	a[cnt][i - 1] = a1[i] + 'a';
        //cout << mp[a[cnt]] << endl;
        if (!mp[a[cnt]]++)
            cnt++;
    }
    ll ans = 0;
    for (int i = 1; i < cnt; i++)
        ans += ll(mp[a[i]] - 1) * mp[a[i]] / 2;
    write(ans), lln;
}
//functions

int main()
{
	init();
	return 0;
}
//main

Measured memory_bytes: 25600
#include <iostream>
#include <map>
#include <ctime>
#include <vector>
#include <climits>
#include <algorithm>
#include <random>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <bitset> 
#include <queue>
#define inf 0x3f3f3f3f
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define rep(i, a, n) for(register int i = a; i <= n; ++ i)
#define per(i, a, n) for(register int i = n; i >= a; -- i)
#define ONLINE_JUDGE
using namespace std;
typedef long long ll;
const int mod=1e9+7;
template<typename T>void write(T x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9)
    {
        write(x/10);
    }
    putchar(x%10+'0');
}
 
template<typename T> void read(T &x)
{
    x = 0;char ch = getchar();ll f = 1;
    while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
    while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;};
ll ksm(ll a,ll n){//看是否要mod 
	ll ans=1;
	while(n){
		if(n&1) ans=(ans*a)%mod;
		a=a*a%mod;
		n>>=1;
	}
	return ans%mod;
}
//==============================================================
string str;


int main()
{
	#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
	clock_t c1 = clock();
	//===========================================================
    cin>>str;
    string pos="hi";
    while(pos.length()<str.length()){
        pos=pos+"hi";
    }
    if(pos==str&&str.length()%2==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
	//===========================================================
	std::cerr << "Time:" << clock() - c1 << "ms" << std::endl;
	return 0;
}

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

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int solve(){
  string s;cin>>s;
  map<int, int> d;
  rep(i,sz(s)){
    d[s[i]]++;
  }
  if (sz(d)!=2) {
    cout << "No" << endl;
    return 0;
  }
  each(e, d){
    if (e.second!=2){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }

void compute() {

}

int main() {
  int n;
  cin >> n;
  vector<ll> v(n);
  deque<int> a,b,c;
  rep(i,n) {
    cin >> v[i];
    int nari = 0;
    while( v[i] % 2 == 0 ) {
      v[i] /= 2LL;
      ++nari;
    }
    if( nari <= 1 ) {
      b.push_back(nari);
    } else {
      a.push_back(nari);
    }
  }
  sort(ALL(b));
  sort(ALL(a),greater<int>());
  while( !( a.empty() && b.empty() ) ) {
    if( !b.empty() ) {

      c.push_back(b.front());
      b.pop_front();
    }
    if( !a.empty() ) {
      c.push_back(a.front());
      a.pop_front();
    }
  }


  
  rep(i,(int)c.size()-1) {
    if( ( c[i] + c[i+1] ) < 2 ) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  compute();
  return 0;
}


Measured memory_bytes: 1408
#貪欲法による解法
# 000から999までの数字を作れるを調べる

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

V_cnt  = 0 

for i in range(10): # 数字は0から9
    for j in range(10): 
        for k in range(10):
            check_i = S.find(str(i)) # iのあるindexを探索
            if check_i != -1:   #探索で見つかった場合
                tmp_S = S[check_i + 1:] # iを見つけた文字以降の文字数で文字列作成
                check_j = tmp_S.find(str(j))
                if check_j != -1:  #探索で見つかった場合
                    tmp_T = tmp_S[check_j + 1:]
                    check_k = tmp_T.find(str(k))
                    if check_k != -1:
                        V_cnt += 1                  
print(V_cnt)

Measured memory_bytes: 3188
a,b,c,x,y=[int(i) for i in raw_input().split()]
if x<=y:
    print min(a*x+b*y,(2*x)*c+(y-x)*b,2*max(x,y)*c)
else:
    print min(a*x+b*y,(2*y)*c+(x-y)*a,2*max(x,y)*c)


Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;
struct Edge {
  ll s,t,d;

};
typedef vector<vector<Edge>> Graph;

vi getDist(Graph graph, ll V, ll r) {
  vi dist(V); REP(i,V) dist[i]=INF;
  priority_queue<pii,vpii,greater<pii>> pq;
  dist[r]=0; pq.push({0ll,r});
  while(pq.size()){
    ll s=pq.top().second;
    for(Edge e:graph[s]) if(dist[e.t] > dist[e.s]+e.d) {
      dist[e.t]=dist[e.s]+e.d;
      pq.push({dist[e.t],e.t});
    }
    pq.pop();
  }
  return dist;
}

int main() {
  ll N,M,R; cin>>N>>M>>R;
  vi r(R); REP(i,R) cin>>r[i];
  REP(i,R) r[i]--;
  Graph G(N);
  REP(i,M) {
    ll a,b,c; cin>>a>>b>>c; a-=1; b-=1;
    Edge x={a,b,c};
    Edge y={b,a,c};
    G[a].PB(x);
    G[b].PB(y);
  }

  UM<ll,vi> dist;
  REP(i,R) {
    dist[r[i]]=getDist(G,N,r[i]);
  }

  sort(ALL(r));
  ll ans=INF;
  do {
    ll sum=0;
    REP(i,R-1) {
      sum+=dist[r[i]][r[i+1]];
    }
    ans=min(ans,sum);
  } while(next_permutation(ALL(r)));
  cout<<ans<<endl;
}


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

typedef long long ll;

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

    ll sum[n+1];
    sum[0] = 0;

    for(int i = 1; i <= n; i++){
        cin >> sum[i];
        sum[i] += sum[i-1];
    }

    ll ans = LLONG_MAX;
    for(int i = 1; i < n; i++){
        ll a = sum[i] - sum[0];
        ll b = sum[n] - sum[i];
        ans = min(ans, abs(a-b));
    }

    cout << ans << endl;

    return 0;
}


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

const int N = 100005;

int n, l, q, x[N], p[N][17];

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n;
	for (int i = 0; i < n; ++i) std::cin >> x[i];
	std::cin >> l >> q;
	for (int i = 0, j = 0; i < n; p[i++][0] = j)
		while (j + 1 < n && x[j + 1] - x[i] <= l) ++j;
	for (int i = 1; i < 17; ++i)
		for (int j = 0; j < n; ++j)
			p[j][i] = p[p[j][i - 1]][i - 1];
	while (q--) {
		int l, r, ans = 1; std::cin >> l >> r, --l, --r; if (l > r) std::swap(l, r);
		for (int i = 16; ~i; --i) if (p[l][i] < r) ans += 1 << i, l = p[l][i];
		std::cout << ans << '\n';
	}
	return 0;
}

Measured memory_bytes: 7936
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>
#include<bitset>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++) //0から
#define REP(i,n) for(int j=i;j<n;j++) //iから

typedef long long ll;



//英字ならture、数字ならfalse
bool isalpha(char s){
    if(('A'<=s&&s<='Z')||('a'<=s&&s<='z')){
        return 1;
    }else{
        return 0;
    }
}
//全ての文字が英字ならture、数字ならfalse
bool Isalpha(string s){
    ll n;
    bool tmp = true;
    rep(i,n){
        if(isalpha(s[i])){
            tmp = false;
        }
    }
    return tmp;
}




using Graph = vector<vector<ll>>;



//cout<<fixed<<setprecision(10);

ll binary_search(vector<ll> a, ll n, ll key){
    ll right = n, left = -1;
    ll md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}



int main(){
    string s;
    cin>>s;
    if(s[0]>='A' && s[0]<='Z'){
        cout<<'A'<<endl;
    }
    else{
        cout<<'a'<<endl;
    }


    return 0;
}



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

const int INF = 1001001001;
int dist[100005][3];

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> to(n);
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
  }
  int sv, tv;
  cin >> sv >> tv;
  --sv; --tv;
  rep(i,n)rep(j,3) dist[i][j] = INF;
  queue<P> q;
  q.push(P(sv,0));
  dist[sv][0] = 0;
  while (!q.empty()) {
    int v = q.front().first;
    int l = q.front().second;
    q.pop();
    for (int u : to[v]) {
      int nl = (l+1)%3;
      if (dist[u][nl] != INF) continue;
      dist[u][nl] = dist[v][l]+1;
      q.push(P(u,nl));
    }
  }
  int ans = dist[tv][0];
  if (ans == INF) ans = -1;
  else ans /= 3;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6912
#include <stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p, int r) {
  int x, i, j, t;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j] <= x) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}

int main(void) {
  int i, q;

  scanf("%d", &n);
  for(i=0; i<n; i++) scanf("%d",&A[i]);
  q = partition(0,n-1);

  for(i=0; i<n; i++) {
    if(i) printf(" ");
    if(i==q) printf("[");
    printf("%d",A[i]);
    if(i==q) printf("]");
  }
  printf("\n");

  return 0;
}


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

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}



void _main() {
        int n; cin >> n;
        string s; cin >> s;
        for (int i = 0; i < s.size(); i++) {
                if (s[i] + n <= 'Z') cout << char(s[i] + n);
                else cout << char(s[i] + n - 'Z' + 'A' - 1);
        }
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}

Measured memory_bytes: 3612
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data',function(line){
	before(line);
});

var log = console.log;
function before(line){
	var lines = line.split("\n");
	lines = lines.filter(function(e){
		return (e !== "");
	});
	main(lines);
}

//-----------
function main(lines){
	var ls = lines.map(function(e){return Number(e);});
	while(ls.length > 1){
		var tpl = ls.shift();
		var arr = ls.slice(0,tpl);
		ls = ls.slice(tpl);
		var mid = arr.indexOf(Math.min.apply(this,arr));
		arr.splice(mid,1);
		var Mid = arr.indexOf(Math.max.apply(this,arr));
		arr.splice(Mid,1);
		var sum = arr.reduce(function(p,c,i,a){return p+c;});
		log(Math.floor(sum/arr.length));
	}
}

Measured memory_bytes: 16352
#include<iostream>
using namespace std;
int main() {
	int a, b;
	while (1) {
		cin >> a >> b;
		if (a == 0) {
			break;
		}
		int n;
		cin >> n;

		int r[17][17] = {0};
		for (int i = 0; i < n; i++) {
			int x, y;
			cin >> x >> y;
			r[x][y] = -1;
		}
		r[1][1] = 1;
		for (int y = 1; y <= b; y++) {
			for (int x= 1; x<= a; x++) {
				if (!((x == 1) && (y == 1))) {
					if (!(r[x][y] == -1)) {
						r[x][y] = r[x - 1][y] + r[x][y-1];
					}
					else {
						r[x][y] = 0;
					}
				}
			}
		}
		cout << r[a][b] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 2992
#include "bits/stdc++.h"
#define REP(i, m, n) for(long long i = m; i < n; ++i)
#define CO(n) cout << n << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int H, N;
int A[1010], B[1010];
int dp[1010][10010];

int main()
{
    ios::sync_with_stdio(false);
    cin >> H >> N;
    REP(i, 0, N) cin >> A[i] >> B[i];
    REP(j,0,H+1) dp[0][j] = 0;
    REP(i,0,N+1){
        REP(j,1,H+1){
            dp[i][j] = 1e8;
        }
    }
    for (int i=N-1; 0<=i; --i){
        for (int j=0; j<=H; ++j){
            // for (int k=0; (k-1)*A[i] < j; ++k){
            //     int rest = max(0, j-k*A[i]);
            //     int cost = k*B[i];
            //     if (rest == 0) dp[i][j] = min(dp[i][j], cost);
            //     else dp[i][j] = min(dp[i][j], dp[i+1][rest]+cost);
            if (j <= A[i]) dp[i][j] = min(min(dp[i][j], dp[i+1][j]), B[i]);
            else dp[i][j] = min(dp[i+1][j], dp[i][j-A[i]]+B[i]);
        }
    }
    // REP(i,0,N+1){
    //     REP(j,0,H+1){
    //         cout << dp[i][j] << ' ';
    //     }
    //     cout << endl;
    // }
    CO(dp[0][H]);
    return 0;
}

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

const int INF = 100000000;

int main() {
  int n, p, a, b, c;
  int m[10][10];
  while (1) {
    cin >> n;
    if (!n) break;
    for (int i=0; i<10; i++) {
      for (int j=0; j<10; j++) {
        m[i][j] = INF;
      }
      m[i][i] = 0;
    }
    p = 0;
    for (int i=0; i<n; i++) {
      cin >> a >> b >> c;
      p = max(p, a);
      p = max(p, b);
      m[a][b] = c;
      m[b][a] = c;
    }
    for (int i=0; i<=p; i++) {
      for (int j=0; j<=p; j++) {
        for (int k=0; k<=p; k++) {
          m[j][k] = min(m[j][k], m[j][i] + m[i][k]);
        }
      }
    }
    a = INF;
    b = -1;
    for (int i=0; i<=p; i++) {
      c = 0;
      for (int j=0; j<=p; j++) {
        c += m[i][j];
      }
      if (a > c) {
        a = c;
        b = i;
      }
    }
    cout << b << " " << a << endl;
  }
}

Measured memory_bytes: 1160
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(unknown_lints)]
#![allow(unused_variables)]
#![allow(unused_must_use)]
#![allow(unused_mut)]
#![allow(dead_code)]
#![allow(unused_assignments)]

use std::collections::HashMap;
use std::io::{stderr, Write};
use std::process::exit;

macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn csvec_new(src: Vec<char>) -> Vec<i32> {
    let mut cs: Vec<i32> = vec![0];
    cs.push(0);
    debug!(cs);
    let len = src.len();
    let mut new = 0;
    for i in 1..len {
        if src[i-1] == 'A' && src[i] == 'C' {
            new = new + 1;
        }
        cs.push(new);
        debug!(src[i-1]);
        debug!(src[i]);
        debug!(cs);
    }
    cs
}

fn main() {
    input!{
        n: usize,
        q: usize,
        s: String,
        lr: [(usize, usize); q]
    }
    debug!(n);
    debug!(q);
    debug!(s);
    debug!(lr);
    let s: Vec<char> = s.chars().collect();
    let cs = csvec_new(s);
    debug!(cs);
    for i in 0..q {
        debug!(i);
        let (l, r) = lr[i];
        debug!(l);
        debug!(r);
        let res = cs[r] - cs[l];
        println!("{}", res);
    }
}

Measured memory_bytes: 7036
n_str = input()
n = int(n_str)
o_n = len(n_str)

#print(n,o_n)

ans_str = '9'*(o_n-1)
     
for i in [9,8,7,6,5,4,2,1,0]:
    test_str = str(i)+ans_str
    if int(test_str) <= n:
        ans_str = test_str
        break
 
ans_array = [int(c) for c in ans_str]
#print(ans_array)
ans = sum(ans_array)
 
print(ans)


Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static final void main(String args[]) throws Exception {
        new Main().solve();
    }

    void solve() {
        try (Scanner in = new Scanner(System.in)) {
            int n = in.nextInt();
            int a[] = new int[n];
            for (int i = 0; i < n; ++i) {
                a[i] = in.nextInt();
            }
            long sum1 = 0, x = 0;
            long sum2 = 0, y = 0;
            for (int i = 0; i < n; ++i) {
                x += a[i];
                y += a[i];
                if (i % 2 == 0) {
                    if (x <= 0) {
                        sum1 += 1 - x;
                        x = 1;
                    }
                    if (y >= 0) {
                        sum2 += 1 + y;
                        y = -1;
                    }
                } else {
                    if (x >= 0) {
                        sum1 += 1 + x;
                        x = -1;
                    }
                    if (y <= 0) {
                        sum2 += 1 - y;
                        y = 1;
                    }

                }
            }
            System.out.println(Math.min(sum1, sum2));
        }
    }

    void tr(Object... o) {
        System.err.println(Arrays.deepToString(o));
    }
}

Measured memory_bytes: 50316
#include <bits/stdc++.h>
#define ll long long int
#define PI 3.14159265358979323846
#define ed "\n"
#define sp " "
#define f(i,a,n) for(ll i=a;i<n;i++)
#define pb push_back
using namespace std;

void solve()
{
 ll n;
 cin>>n;
 if(n%1000!=0)
 cout<<1000-n%1000;
  else cout<<0;
}
 
int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt","w",stdout);
    #endif
  ll t=1;
//  cin>>t;
  while(t--)
  {
    solve();
  }
return 0;
}


Measured memory_bytes: 3660
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef unsigned long long int ll;


struct edge{
	int to,cost;
};

typedef vector<vector<edge>> adjList;
typedef pair<int,int> P;
const int INF = 1e9;
vector<int> dist;
adjList graph;

void dijkstra(int n,int s){
	dist = vector<int>(n,INF);
	dist[s] = 0;
	priority_queue<P,vector<P>,greater<P>> que;
	que.push(make_pair(0,s));
	while( ! que.empty()){
		P p = que.top();
		que.pop();
		int v = p.second;
		if(dist[v] < p.first){
			continue;
		}
		for(int i = 0; i < graph[v].size(); i++){
			edge e = graph[v][i];
			if( dist[e.to] > dist[v] + e.cost){
				dist[e.to] = dist[v] + e.cost;
				que.push(make_pair(dist[e.to],e.to));
			}
		}
	}
}


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

	return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
int h,w,k,a[309][309],num;
int cnt[309];
char c[309][309];
void solve(int cl,int cr){
	vector<int> p;
	for(int i=cl;i<=cr;i++){
		for(int j=1;j<=w;j++){
			if(c[i][j]=='#')p.push_back(j);
		}
	}
	sort(p.begin(),p.end());
	for(int i=0;i<p.size();i++){
		int v1=1,v2=w;
		if(i>=1)v1=p[i-1]+1;
		if(i<(int)p.size()-1)v2=p[i];
		num++;
		for(int j=cl;j<=cr;j++){
			for(int k=v1;k<=v2;k++)a[j][k]=num;
		}
	}
}
int main(){
	cin>>h>>w>>k;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			cin>>c[i][j];
			if(c[i][j]=='#')cnt[i]++;
		}
	}
	vector<int> vec;
	for(int i=1;i<=h;i++){
		if(cnt[i]>=1){
			vec.push_back(i);
		}
	}
	for(int i=0;i<vec.size();i++){
		int v1=1,v2=h;
		if(i>=1)v1=vec[i-1]+1;
		if(i<(int)vec.size()-1)v2=vec[i];
		solve(v1,v2);
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(j>=2)cout<<" ";
			cout<<a[i][j];
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
 
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
 
using namespace std;

int main()
{
  int N, K, S, h = 1; cin >> N >> K >> S;
  
  if(S == 2) h = 2;
  if(S == 1) h = 2;
  
  REP(i, K)
    cout << S << " ";
  
  for(int i = K; i < N; i++)
    cout << (S / 2) + h << " ";
  
}

Measured memory_bytes: 1280
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <queue>
#include <list>
#include <string>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int A,B,C;
    cin >> A >> B >> C;
    if(A == B && A == C) cout << "Yes";
    else cout << "No";
}



Measured memory_bytes: 256
#include <stdio.h>

int binarySearch(int n, int A[], int key)
{
	int mid;
	int left = 0;
	int  right = n;
	
	while (left < right) {
		mid = (left + right) / 2;
		if (A[mid] == key)
			return 1;
		else if (key < A[mid])
			right = mid;
		else if (key > A[mid])
			left = mid + 1;
	}
	return 0;
}


int main()
{
	int N,Q, S[100000], T[50000], i;
	int  cnt = 0;
	
	scanf("%d", &N);
	for (i = 0; i < N; i++)
		scanf("%d", &S[i]);
	scanf("%d", &Q);
	for (i = 0; i < Q; i++)
		scanf("%d", &T[i]);
	for (i = 0; i < Q; i++) {
		if (binarySearch(N, S, T[i]) != 0)
			cnt++;
	}
	printf("%d\n", cnt);
	return 0;
}




Measured memory_bytes: 2312
// ref: https://img.atcoder.jp/arc092/editorial.pdf
// ref: https://qiita.com/shihou22/items/2e9522344917c0e39a00

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int N; cin >> N;
//    vector<pair<int,int>> vA(N); for(int i=0; i<N; ++i){ cin >> vA[i].first >> vA[i].second; } sort(vA.begin(), vA.end());
    vector<pair<int,int>> vA(N); for(int i=0; i<N; ++i){ cin >> vA[i].second >> vA[i].first; } sort(vA.begin(), vA.end());
    vector<pair<int,int>> vB(N); for(int i=0; i<N; ++i){ cin >> vB[i].first >> vB[i].second; } sort(vB.begin(), vB.end());
    
    int cnt = 0;
    for(int ib=0; ib<N; ++ib){
//        for(int ia=0; ia<N; ++ia){
        for(int ia=N-1; ia>=0; --ia){
//            if(! (vA[ia].first<vB[ib].first && vA[ia].second<vB[ib].second) ){ continue; }
            if(! (vA[ia].second<=vB[ib].first && vA[ia].first<=vB[ib].second) ){ continue; }
            ++cnt;
            vA[ia].first  = INT_MAX;
            vA[ia].second = INT_MAX;
            break;
        }
    }
    
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 3620
let N = Int(readLine()!)!
var sArr:[String]
var acCount = 0
var waCount = 0
var tleCount = 0
var reCount = 0
for i in 0..<N{
  let str = readLine()!
  if str == "AC"{
    acCount += 1
  }else if str == "WA"{
  	waCount += 1
  }else if str == "TLE"{
  	tleCount += 1
  }else if str == "RE"{
  	reCount += 1
  }
}

print("AC x \(acCount)")
print("WA x \(waCount)")
print("TLE x \(tleCount)")
print("RE x \(reCount)")


Measured memory_bytes: 7892
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <bitset>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2000000000
#define rep(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> P;
const ll MOD=1000000007;
using Graph = vector<vector<int>>;

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;
}



int n,m;

vector<ll> dp(100005,-1);
vector<bool> ch(100005,true);

ll rec(int i) {
    if (i == 0) return 1;
    if (i == 1) return 1;
    if (dp[i] != -1) return dp[i];
    
    if (ch[i - 1] && ch[i - 2]) return dp[i] = (rec(i - 1) + rec(i - 2))%MOD;
    else if (ch[i - 1] && !ch[i - 2])return dp[i] = rec(i - 1);
    else if (!ch[i - 1] && ch[i - 2]) return dp[i] = rec(i - 2);
    return 0;
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a;
        cin >> a;
        ch[a] = false;
    }
    //memset(dp, -1, sizeof(dp));
    cout << rec(n) << endl;
    
    return 0;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  int ma = 0, ans = 0;
  for (auto &i : a) {
    cin >> i;
    ma = max(ma, i);
    ans += ma - i;
  }
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 4780
#include <algorithm>
#include <iostream>
#include <queue>

using namespace std;

typedef pair<int, int> P;
const int inf = 1 << 28;

int w, h;
int a[21][21];
int sx, sy, gx, gy;

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

bool check(int x, int w) { return 0 <= x && x < w; }

int dfs(int x, int y, int cnt) {
    if (cnt >= 10) {
        return inf;
    }

    int ret = inf;

    for (int k = 0; k < 4; ++k) {
        int nx = x + dx[k], ny = y + dy[k];

        while (check(nx, w) && check(ny, h) && a[ny][nx] != 1 &&
               a[ny][nx] != 3) {
            nx += dx[k];
            ny += dy[k];
        }

        if (!check(nx, w) || !check(ny, h)) {
            continue;
        }

        if (a[ny][nx] == 3) {
            return 1;
        }

        if (nx - dx[k] == x && ny - dy[k] == y) {
            continue;
        }

        a[ny][nx] = 0;

        ret = min(ret, dfs(nx - dx[k], ny - dy[k], cnt + 1) + 1);

        a[ny][nx] = 1;
    }

    return ret;
}

int main() {
    while (cin >> w >> h, !(w == 0 && h == 0)) {
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                cin >> a[i][j];

                if (a[i][j] == 2) {
                    sy = i;
                    sx = j;
                }

                if (a[i][j] == 3) {
                    gy = i;
                    gx = j;
                }
            }
        }

        int ans = dfs(sx, sy, 0);

        if (ans <= 10) {
            cout << ans << endl;
        } else {
            cout << -1 << endl;
        }
    }
}

Measured memory_bytes: 2984
N,K=map(int,input().split())
def comb(n,k):
  s=(2*n-k+1)*k/2-k*(k-1)/2+1
  return s
l=0
for i in range(K,N+2):
  l+=comb(N,i)
print(int(l)%(10**9+7))

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

typedef long long ll;
typedef long double ld; //
typedef double db; //
typedef string str; //
//
typedef pair<int, int> pi;
typedef pair<ll,ll> pl; //
typedef pair<ld,ld> pd; //
#define mp make_pair
#define f first
#define s second

typedef vector<int> vi;
typedef vector<ll> vl; //
typedef vector<ld> vd; //
typedef vector<str> vs; //
typedef vector<pi> vpi; //
typedef vector<pl> vpl; //
typedef vector<pd> vpd; //
typedef vector<vi> vvi;
typedef vector<vl> vvll;

//
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend() //
#define rsz resize
#define ins insert //
#define ft front() //
#define bk back() //
#define pf push_front //
#define pb push_back
#define eb emplace_back //
#define lb lower_bound //
#define ub upper_bound //

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7; // 998244353; // = (119<<23)+1
const int MX = 2e5+5; //
const ll INF = 1e18; //
const ld PI = 4*atan((ld)1); 
const int xd[4] = {0,1,0,-1}, yd[4] = {1,0,-1,0}; //

template<class T> bool ckmin(T& a, const T& b) { 
    return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { 
    return a < b ? a = b, 1 : 0; }
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

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

    int N;
    ll D;
    cin >> N >> D;

    vl A(N);
    for (int i=0;i<N;i++) cin >> A[i];

    vl X(N);
    vl Y(N);
    for (int i=0;i<N;i++) {
        X[i] = A[i] + i*D;
        Y[i] = A[i] - i*D;
    }

    vl M(N);
    M[N-1] = N-1;
    for (int i=N-2;i>=0;i--) {
        if (X[i+1] < X[M[i+1]]) {
            M[i] = i+1;
        } else {
            M[i] = M[i+1];
        }
    }

    ll ans = 0;
    int st = 0;
    ll ymin = Y[st];
    while (st < N-1) {
        ymin = min(ymin, Y[st]);
        int nxt = M[st];
        ans += X[nxt] + ymin;

        for (int i=st+1;i<nxt;i++) {
            ans += min(Y[i] + X[nxt], ymin + X[i]);
            ymin = min(ymin, Y[i]);
        }

        st = nxt;
    }

    cout << ans << endl;
}

Measured memory_bytes: 6528
#define DEBUG(...)
/*                        Strip me down and go to town                        */
/*                          Lick me over upside down                          */
/*                     Pound and pound and pound and pound                    */
/*                        Baby make me make that sound                        */
/*                Aaah, aaah, aaah, aaah, aaaaaaaaaaaaaaaaaah!                */
#include<stdio.h>

int main() {
  int n;
  scanf("%d", &n);
  int v = 0;
  while (n--) {
    int x;
    scanf("%d", &x);
    v ^= x;
  }
  printf("%s\n", v == 0 ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

typedef long long ll;

const ll mod = 1e9 + 7;
ll n, ans, cnt[30];
string s;

int main()
{
    cin >> n >> s;
    ans = 1;
    for (int i = 0; i < s.length(); i++) cnt[s[i] - 'a']++;
    for (int i = 0; i < 26; i++) ans = ans * (cnt[i] + 1) % mod;
    cout << ans - 1 << endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt(),k=sc.nextInt(),count=1;
    for(int i=0;i<n;i++) {
    	int buff=sc.nextInt();
    }
    for(int i=k;i<n;i+=k-1) {
    	count++;
    	//System.out.println(i);
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 48912
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N;
    cin >> N;

    vector<ll> A(N);
    ll a_sum = 0;
    FOR(i, 0, N){
        cin >> A.at(i);
        a_sum += A[i];
    }

    vector<ll> B(N);
    ll b_sum = 0;
    FOR(i, 0, N){
        cin >> B.at(i);
        b_sum += B[i];
    }

    // 絶対に追いつけない
    if(a_sum > b_sum){
        p_no();
        return 0;
    }
    else{
        ll k = b_sum - a_sum;

        ll k_a = k;
        ll k_b = k;

        // やれるとすればk回
        FOR(i, 0, N){
            ll a = A[i];
            ll b = B[i];

            if(a==b){
                //
            }
            else if(a<b){
                ll diff = b - a;
                ll num = diff/2;
                k_a -= num;
                if(diff%2==1){
                    k_a--;
                    k_b--;
                }
            }
            else if(a>b){
                ll diff = a - b;
                k_b -= diff;
            }
        }

        if(k_a < 0 || k_b < 0){
            p_no();
        }
        else if(k_a * 2 == k_b){
            p_yes();
        }
        else{
            p_no();
        }
    }
    
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

ll A[100100];
int H[50];
ll DP[100][2];
ll N, K;

ll func(int i, bool bit){
    int h = H[i];
    int num;
    if(bit) num = N-h;
    else num = h;
    ll base = pow(2, i);
    return num*base;
}

int main(){
    cin >> N >> K;
    REP(i, N){
        ll a;
        cin >> a;
        A[i] = a;
    }

    int keta = 0;
    ll tmpK = K;
    while(tmpK > 0){
        tmpK /= 2;
        keta++;
    }
    if(keta == 0) keta++;

    for(int k = 0; k < 50; k++){
        int hbit = 0;
        for(int i = 0; i < N; i++){
            ll a = A[i];
            int bit = (a >> k) & 1;
            hbit += bit;
        }
        H[k] = hbit;
    }

    ll ans = 0;
    if(K != 0)
        DP[0][1] = func(keta-1, 1);
    else
        DP[0][1] = 0;
    DP[0][0] = func(keta-1, 0);
    int k;
    for(k = 1; k < keta; k++){
        int inv = keta-1-k;
        bool bit = (K >> inv) & 1;
        DP[k][1] = DP[k-1][1] + func(inv, bit);
        DP[k][0] = DP[k-1][0] + max(func(inv, 0), func(inv, 1));
        if(bit) DP[k][0] = max(DP[k][0], DP[k-1][1] + func(inv, 0));
    }
    for(; k < 50; k++){
        ans += func(k, 0);
    }

    //for(int i = 0; i < keta; i++){
    //    printf("%lld ", DP[i][1]);
    //}
    //printf("\n");
    //for(int i = 0; i < keta; i++){
    //    printf("%lld ", DP[i][0]);
    //}
    //printf("\n");

    ans += max(DP[keta-1][0], DP[keta-1][1]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        List<String> res = new ArrayList<String>();     
        while(true) {
            String line = br.readLine();
            String[] line2 = line.split(" ");
            int a1 = Integer.parseInt(line2[0]);
            int a2 = Integer.parseInt(line2[1]);
            int a3 = Integer.parseInt(line2[2]);
            if(a1==-1&&a2==-1&&a3==-1)break;
            if(a1==-1 || a2==-1) {
                res.add("F");
            }
            else if(a1+a2>=80) {
                res.add("A");
            }
            else if(a1+a2>=65) {
                res.add("B");
            }
            else if(a1+a2>=50) {
                res.add("C");
            }
            else if(a1+a2>=30) {
                if(a3>=50)
                    res.add("C");
                else
                    res.add("D");
            }else {
                res.add("F");
            }
        }
        print(res);
    }
    static void print(List<String> list) {
        for(String s:list) {
            System.out.println(s);
        }
    }
}

Measured memory_bytes: 17036
k = gets.to_i
a, b = gets.split("\s").map(&:to_i)
able = false

1.upto(b) do |i|
  if k * i >= a && b >= k * i
    print 'OK'
    able = true
    break
  end
  if k * i > b
    break
  end
end

print 'NG' unless able

Measured memory_bytes: 14428
/**
 * Author: PraveenKumarRana
**/

#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;

template <typename T> void max_self(T& a, T b){
    a=max(a,b);
}

bool first_row_or_col(pair<int,int> p){
    return p.first || p.second;
}

void solve(){
    string a,b; cin>>a>>b;
    vector< vector< pair<int,pair<int, int> > > > dp(a.size()+1, vector< pair<int, pair<int,int> > >(b.size()+1,make_pair(-mod,make_pair(0,0))));
    dp[0][0]={0,{0,0}};
    // dp[i][j] - total length so far.
    for(int i=0; i<a.size(); ++i){
        for(int j=0; j<b.size(); ++j){
            if(a[i]==b[j]){
                max_self(dp[i+1][j+1],make_pair(dp[i][j].first+1,make_pair(i,j)));
            }
            max_self(dp[i+1][j],make_pair((dp[i][j].first),make_pair(i,j)));
            max_self(dp[i][j+1],make_pair((dp[i][j].first),make_pair(i,j)));
        }
    }
    
    pair<int,pair<int,int> > answer={0,{0,0}};
    for(int i=0; i<=a.size(); ++i){
        for(int j=0; j<=b.size(); ++j){
            max_self(answer, make_pair(dp[i][j].first, make_pair(i,j)));
        }
    }

    //cout<<answer.first<<" "<<answer.second.first<<" "<<answer.second.second<<"\n";
    string s="";
    pair<int,int> curr = answer.second;
    while(first_row_or_col(curr)){
        int i=curr.first;
        int j=curr.second;
        pair<int,int> previous=dp[i][j].second;
        if(previous==make_pair(i-1,j-1)){
            assert(a[i-1]==b[j-1]);
            s+=a[i-1];
        }
        curr=previous;
    }

    //cout<<"Size: "<<s.size()<<"\n";
    reverse(s.begin(),s.end());
    cout<<s<<"\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 105984
#include <iostream>
#include <cstring>

using namespace std;

int n;
int niz[100100][3];
int memo[100100][3];

int rek(int i, int zad){

    if (memo[i][zad] != -1)return memo[i][zad];
    if (i == n)return 0;

    if (zad == 0){
        int ret1 = rek(i + 1, 1);
        int ret2 = rek(i + 1, 2);
        memo[i][zad] = max(ret1, ret2) + niz[i][zad];
        return max(ret1, ret2) + niz[i][zad];
    }
    if (zad == 1){
        int ret1 = rek(i + 1, 0);
        int ret2 = rek(i + 1, 2);
        memo[i][zad] = max(ret1, ret2) + niz[i][zad];
        return max(ret1, ret2) + niz[i][zad];
    }
    if (zad == 2){
        int ret1 = rek(i + 1, 0);
        int ret2 = rek(i + 1, 1);
        memo[i][zad] = max(ret1, ret2) + niz[i][zad];
        return max(ret1, ret2) + niz[i][zad];
    }

}

int main (){

    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> niz[i][0] >> niz[i][1] >> niz[i][2];
    }
    memset(memo, -1, sizeof memo);

    cout << max(rek(0,0), max(rek(0,1), rek(0,2))) << "\n";

    return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <stdio.h>
#include <string.h>
//#include <bits/stdc++.h>
using namespace std;
/*inline int read(){
    int s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}*/
long long yihuo(long long a)
{
    if(a%4==1)
        return 1;
    if(a%4==2)
        return a+1;
    if(a%4==3||a==0)
        return 0;
    return a;
}


int main()
{
        long long a,b;
        while(cin>>a>>b)
        {
            if(a==0)
                cout<<yihuo(b)<<endl;
            else
            {
                long long ans=yihuo(a-1)^yihuo(b);
                cout<<ans<<endl;}
        }
        return 0;
}

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

int main(){
  int N, M, C, a, temp, ans = 0;
  cin >> N >> M >> C;
  vector<int> B(M);
  for (int i = 0; i < M; i++){
    cin >> B[i];
  }
  for (int i = 0; i < N; i++){
    temp = 0;
    for (int j = 0; j < M; j++){
      cin >> a;
      temp += a * B[j];
    }
    temp += C;
    if (temp > 0){
      ans++;
    }
  }
  cout << ans;
}
  

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

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

using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}

int main(){
  vector<string> v = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  string S;
  cin >> S;
  rep(i,7){
    if(v[i] == S){
      cout << 7 - i <<endl;
      break;
    }
  }

 }

Measured memory_bytes: 256