akhauriyash/Code-Regression huggingface dataset:
def isEvenStr(s):
  if len(s) % 2 == 1:
    return False
  elif s[0:int(len(s)/2)] == s[int(len(s)/2):]:
    return True
  else:
    return False

s = input()
l = len(s)
i = 0

while not isEvenStr(s) or i == 0:
  s = s[:-1]
  i += 1
  if isEvenStr(s):
    print(l - i)

Measured memory_bytes: 9036
/*********************************************************************************\
*  _________  _      _  ________  _       _       __       ________               *
* |___   ___|| |    | ||  ______|| |     | |     /  \     |  ____  |              *
*     | |    | |    | || |______ | |_____| |    / /\ \    | |____| |              *
*     | |    | |    | ||______  ||  _____  |   / /__\ \   |  __  __|              *
*     | |    | |____| | ______| || |     | |  / ______ \  | |  \ \                *
*     |_|    |________||________||_|     |_| /_/      \_\ |_|   \_\               *
*  ________       __      ________  _    __       __       ________               *
* |  ______|     /  \    |  ____  || |  / /      /  \     |  ____  |              *
* | |______     / /\ \   | |____| || |_/ /      / /\ \    | |____| |              *
* |______  |   / /__\ \  |  __  __||  __ \     / /__\ \   |  __  __|              *
*  ______| |  / ______ \ | |  \ \  | |  \ \   / ______ \  | |  \ \                *
* |________| /_/      \_\|_|   \_\ |_|   \_\ /_/      \_\ |_|   \_\               *
*                                                                                 *
*                                                                                 *
*   Department of Computer Science & Engineering                                  *
*   Student ID : 18CSE035                                                         *
*   Bangabnadhu Sheikh Mujibur Rahman Science & Technology University,Gopalgonj.  *
*                                                                                 *
\*********************************************************************************/

//Now Write to Code ___________________________

#include<bits/stdc++.h>
using namespace std;


int main()
{
	int A,B;
    char S[11],T[11],U[11];

    cin >> S >> T >> A >> B >> U;

    if(strcmp(S,U) == 0)
    {
        cout << A-1 << " " << B << endl;
    }
    else
    {
        cout << A << " " << B-1 << endl;
    }

	return 0;
}


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


int main() {
  int num = 0;
  std::string S;

  std::cin >> S;

  for (int i=0;i<4;i++) {
    if (S[i] == '+') {
      num++;
    } else {
      num--;
    }
  }

  std::cout << num;
  return 0;
}

Measured memory_bytes: 256
# Aizu Problem 0216: Cutting Down Water Bills

import sys, math, os, fractions

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def water_bill(n):
    if n <= 10:
        return 4280 - 1150
    elif n <= 20:
        return 4280 - (1150 + (n - 10) * 125)
    elif n <= 30:
        return 4280 - (1150 + 1250 + (n - 20) * 140)
    else:
        return 4280 - (1150 + 1250 + 1400 + (n - 30) * 160)

while True:
    n = int(input())
    if n == -1:
        break
    print(water_bill(n))
        

Measured memory_bytes: 10160
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


def road():
    N = int(input())
    A = tuple(tuple(map(int, input().split())) for _ in range(N))

    res = 0
    for s in range(N - 1):
        for t in range(s + 1, N):
            # s-t間に辺を張るかを決める
            dist = A[s][t]
            is_connect = True
            for m in range(N):
                if m in [s, t]:
                    continue
                d = A[s][m] + A[m][t]
                if d < dist:
                    return -1
                elif d == dist:
                    is_connect = False
            if is_connect:
                res += dist
    return res


if __name__ == "__main__":
    print(road())

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

//関数
    
    
    
//main関数
int main() {
    
    
    //入力
    long N,A,B;
    cin>>N>>A>>B;
    
    
    
    
    
    
    //計算
    long ans=0;
    if(A<=B &&(A==B || N>=2)){
        ans=(N-2)*(B-A)+1;
    }
    
    //出力
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using ll = long long int;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

	int x; cin >> x;
	cout << 1-x;
}

Measured memory_bytes: 3648
import collections
n = int(input())
a = list(map(int, input().split()))
c = collections.Counter(a)
d = {}
for i in c:
    if c[i] >= 2:
        d[i] = c[i]

if d != {}:
    dct = sorted(d.items(), key=lambda x: -x[0])
    if len(d) == 1:
        if dct[0][1] >= 4:
            print(dct[0][0] ** 2)
        else:
            print(0)
    else:
        if dct[0][1] >= 4:
            print(dct[0][0] ** 2)
        else:
            print(dct[0][0] * dct[1][0])
else:
    print(0)

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

using namespace std;

typedef long long int ll;

string blue[100];
string red[100];
int ans = -987654321;
int main() {
    
    int n, m;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> blue[i];
    cin >> m;
    for (int i = 0; i < m; i++)
        cin >> red[i];
    
    
    for (int i = 0; i < n; i++) {
        
        string t = blue[i];
        int value = 0;
        for (int j = 0; j < n; j++) {
            if (t == blue[j])
                value++;
        }
        for (int j = 0; j < m; j++) {
            if (t == red[j])
                value--;
        }
        if (value > ans)
            ans = value;
    }
    if (ans < 0)
        cout << 0 << endl;
    else
        cout << ans << endl;
    
    
    
    
}

Measured memory_bytes: 256
#include <stdio.h>

int linearSearch(int *,int,int);

int main(){
  int i,n,data[10000],a,b,c=0;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&data[i]);
      }

  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&b);
    if(linearSearch(data,n,b)){
      c++;
    }
  }
  printf("%d\n",c);

  return 0;
}

int linearSearch(int data[],int n,int b){
  int i=0;
  data[n]=b;
  while(data[i]!=b){
    i++;
  }
    return i!=n;
}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
#define IN freopen("input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define pf printf
#define sf scanf
#define pb push_back
#define MAX5 100005
#define MAX6 1000005
#define MAX7 10000005
#define FOR(a,n) for(int i=a;i<n;i++)
#define all(x) x.begin(),x.end()
#define mod7 1000000007
typedef long long int ll;
typedef long double lld;
const double PI=2*acos(0.0);
int CASE=1,TEST=0;
template<typename T>T ceilling(T a){return ((double)((ll)a))==a?  (T)a :  (T)((ll)(a+1.0));}
template<typename T>T flooring(T a){return (T)((ll)a);}
template<typename T>T pairmin(T a,T b){return (a>b) ? b : a;}
template<typename T>T pairmax(T a,T b){return (a>b) ? a : b;}
template<typename T>T arrymax(T arr[],int arrsize){T m=arr[0]; for(int i=0;i<arrsize;i++){ if(arr[i]>m){m=arr[i];}} return m;}
template<typename T>T arrymin(T arr[],int arrsize){T m=arr[0]; for(int i=0;i<arrsize;i++){ if(arr[i]<m){m=arr[i];}} return m;}
template<typename T>T LCM(T a,T b){ return ((a*b)/__gcd(a,b));}
template<typename T>T ABS(T a){return a<0 ? (-1*a): a ;}
struct vpair{
    int a;
    int b;
    vpair(int a,int b){this->a=a;this->b=b;}
};
bool cmp(vpair &a,vpair &b){
    if(a.a<b.a)return true;
    else if(a.a==b.a){
        if(a.b<b.b)return true;
        else return false;
    }else{
        return false;
    }
}
ll a,b,m,n,ans;
int main(void){
    sf("%lld %lld",&n,&m);
    for(int i=2;i<100005;i++){
        if(n*i%m!=0){
            pf("%lld\n",n*i);
            return 0;
        }
    }
    pf("-1\n");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+9;


vector<int> g[maxn];
set<pair<int,int>> se;
int vis[maxn],n,m,cnt;
bool dfs1(int u,int pre){
    vis[u]=++cnt;
    //cout<<"pre, u, vis = "<<pre<<" "<<u<<" "<<vis[u]<<endl;
    for(int i=0;i<g[u].size();i++){
        int v=g[u][i];
        if(v==pre)continue;
        if(se.count(make_pair(u,v)))continue;
        //cout<<u<<" "<<v<<" "<<vis[u]<<" "<<vis[v]<<endl;
        bool flag=0;
        if(!vis[v])flag=dfs1(v,u);
        if(vis[u]>=vis[v]){
            //cout<<u<<" "<<v<<endl;
            se.insert(make_pair(u,v));
            se.insert(make_pair(v,u));
            vis[u]=vis[v];
            return 1;
        }
        if(flag)return 1;
    }
    return 0;
}
bool de_dfs(){
    //cout<<"de_dfs\n";
    memset(vis,0,sizeof(vis));
    cnt=0;
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            if(dfs1(i,-1))return 1;
        }
    }
    return 0;
}
int edges = 0, now = 0;
int dfs2(int u,int pre){
    for(int i=0;i<g[u].size();i++){
        int v=g[u][i];
        if(v==pre || se.count(make_pair(u,v)))continue;
        now++;
        se.insert(make_pair(u,v));
        se.insert(make_pair(v,u));
        return dfs2(v,u);
    }
    return u;
}
bool che(){
    memset(vis,0,sizeof(vis));
    cnt=0;
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            now = 0;
            if(dfs2(i,-1)!=i)return 0;
            if(now>0){
                if(se.size()==m*2)return 1;
                else return 0;
            }
        }
    }
    //cout<<"se.size() = "<<se.size()<<"\n";
    return 0;
}
bool dfs3(int u,int pre,int x,int y){
    vis[u]=1;
    for(int i=0;i<g[u].size();i++){
        int v=g[u][i];
        if(v==pre || v==y)continue;
        if(v==x)return 1;
        if(!vis[v] && dfs3(v,u,x,y))return 1;
    }
    return 0;
}
bool chee(int x,int y){
    memset(vis, 0,sizeof(vis));
    return dfs3(x,-1,x,y);
}
int dd[maxn];
int main()
{
    scanf("%d%d",&n,&m);
    //cout<<"m,m = "<<m<<endl;
    memset(dd,0,sizeof(dd));
    for(int i=1;i<=m;i++){
        int a,b;scanf("%d%d",&a,&b);
        assert(a!=b);
        g[a].push_back(b);
        g[b].push_back(a);
        dd[a]++;
        dd[b]++;
    }
    bool flag = de_dfs();/*
    for(auto it=se.begin();it!=se.end();it++){
        cout<<(it->first)<<" "<<(it->second)<<endl;
    }*/
    //cout<<"flag1 = "<<flag<<endl;
    if(flag)flag = de_dfs();
    if(flag){
        flag = che();
    }
    //if(flag)printf("Yes\n");
    //else printf("No\n");
    int ins=0;
    bool ff=1;
    int a=0,b=0;
    for(int i=1;i<=n;i++){
        if(dd[i]&1)ff=0;
        if(dd[i]>=6)ins += maxn;
        else if(dd[i]==4){
            ins++;
            if(a==0)a=i;
            else if(b==0)b=i;
        }
    }
    if(ins<2){
        ff=0;
    }
    else if(ins==2 && ff){
        if(chee(a,b));
        else ff=0;
    }
    printf("%s\n",ff?"Yes":"No");
    return 0;
}


Measured memory_bytes: 22144
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
#define int long long
#define ll long long
#define EPS 0.00000000000001
#define ld long double
#define inf 200000000
#define N 51




int32_t main()
{
    IOS;

    int n;
    cin >> n;
    vector<int> b(n-1);
    for(int i = 0;i < n - 1;i++)
        cin >> b[i];
    vector<int> a(n);
    a[n - 1] = b[n-2];
    a[0] = b[0];
    for(int i = 1;i < n - 1;i++)
    {
        a[i] = min(b[i-1],b[i]);
    }
    int ans = 0;
    for(int i = 0;i < n;i++)
        ans += a[i];
    cout << ans;
}   
 
 


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  long long n,d,i,m=1e16;
  scanf("%lld",&n);
  for(i=0;i<5;i++){
    scanf("%lld",&d);
    if(m>d)m=d;
  }
  d=n/m;
  if(n%m)d++;
  printf("%lld\n",d+4);
  return 0;
}


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

int compare(const void *a, const void *b)
{
    return *(int *)a - *(int *)b;
}

int main()
{
    int n, k, s;
    long long int min;
    long long int h[100005];
    scanf("%d%d", &n, &k);
    s = k - 1;
    for (int i = 0; i < n; i++)
    {
        scanf("%lld", &h[i]);
    }
    qsort(h, n, sizeof(long long int), compare);
    min = h[s] - h[0];
    for (int i = 1; i + s < n; i++)
    {
        min = (h[i + s] - h[i] < min) ? h[i + s] - h[i] : min;
    }

    printf("%d\n", min);
}

Measured memory_bytes: 1788
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args){
        Deque<String> formula = new ArrayDeque<String>();
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            String input = scan.next();
            switch(input){
                case "+":
                    input = String.valueOf(Double.parseDouble(formula.poll())+Double.parseDouble(formula.poll()));
                    break;
                case "-":
                    input = String.valueOf(-1*Double.parseDouble(formula.poll())+Double.parseDouble(formula.poll()));                    
                    break;
                case "/":
                    input = String.valueOf(1.0/Double.parseDouble(formula.poll())*Double.parseDouble(formula.poll()));
                    break;
                case "*":
                    input = String.valueOf(Double.parseDouble(formula.poll())*Double.parseDouble(formula.poll()));
                    break;
            }
            formula.push(input);
        }
        double ans = Double.parseDouble(formula.poll());
        if(ans==(int)ans){
            System.out.println((int)ans);
        }else{
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 26280
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, x = MAP()
A = LIST()

A.sort()
cnt = 0
# print(A)
for a in A:
    # if a < x:
    x -= a
    if x >= 0:
        cnt += 1
    else:
        break
# print(x)
if x > 0:
    print(cnt - 1)
else:
    print(cnt)


Measured memory_bytes: 5684
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  LL n, m;
  cin>>n>>m;

  if(n==1&&m==1){
    cout<<1<<endl;
    return 0;
  }
  if(n==1||m==1){
    cout<<max(max(n, m)-2, (LL)0)<<endl;
    return 0;
  }
  if(m==2||n==2){
    cout<<0<<endl;
    return 0;
  }
  cout<<(n-2)*(m-2)<<endl;
  return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/keyence2020/tasks/keyence2020_a

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll H, W, N;
  cin >> H >> W >> N;

  ll ct = max(H, W);
  ll res = (N + ct - 1) / ct;
  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
typedef long long ll;

int main() {
	fast;
	int n;
	cin >> n;
	n %= 1000;
	if (n == 0) {
		cout << 0;
		return 0;
	}
	cout << 1000 - n;
	return 0;
}



















Measured memory_bytes: 3612
/*
(1)for binary shift operator always use 'LL' 1LL<<63

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set_pair tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
  const double  pi=3.1415926535; 
  struct pair_hash
{
	template <class T1, class T2>
	std::size_t operator () (std::pair<T1, T2> const &pair) const
	{
		std::size_t h1 = std::hash<T1>()(pair.first);
		std::size_t h2 = std::hash<T2>()(pair.second);

		return h1 ^ h2;
	}
};
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,k,i,j;cin>>n>>k;
	ll c=pow(k-1,n-1)*k;
	cout<<c;


	return 0;
} 

Measured memory_bytes: 3980
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    char c; cin >> c;
    cout << char(c + 1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
  ll N,M;
  cin >> N >> M;
  vector<long long> x(N),y(N),z(N);
  for(int i=0;i<N;i++)cin >> x[i] >> y[i] >> z[i];
  vector<pair<pair<ll,ll>,pair<ll,ll>>> t(N);
  long long ans=0;
  for(int i=0;i<8;i++){
    ll a=1,b=1,c=1;
    if(i&(1<<2))a*=-1;
    if(i&(1<<1))b*=-1;
    if(1&i)c*=-1;
    for(int j=0;j<N;j++){
      t[j]=make_pair(make_pair(x[j]*a+y[j]*b+z[j]*c,x[j]),make_pair(y[j],z[j]));
    }
    sort(t.begin(),t.end());
    reverse(t.begin(),t.end());
    long long X=0,Y=0,Z=0;
    for(int j=0;j<M;j++){X+=t[j].first.second; Y+=t[j].second.first; Z+=t[j].second.second;}
    ans=max(ans,abs(X)+abs(Y)+abs(Z));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[4003];
ll r[4003];
ll g[4003];
ll b[4003];
ll cnt;
int main()
{
    int n;
    cin >> n;
    scanf("%s", s);
    if(s[0] == 'R')
        r[0]++;
    if(s[0] == 'G')
        g[0]++;
    if(s[0] == 'B')
        b[0]++;
    for(int i = 1; i < n; i++)
    {
        if(s[i] == 'R')
        {
            r[i] = r[i - 1] + 1;
            g[i] = g[i - 1];
            b[i] = b[i - 1];
        }
        else if(s[i] == 'G')
        {
            r[i] = r[i - 1];
            g[i] = g[i - 1] + 1;
            b[i] = b[i - 1];
        }
        else
        {
            r[i] = r[i - 1];
            g[i] = g[i - 1];
            b[i] = b[i - 1] + 1;
        }
    }
    if(n <= 2)
    {
        cout << 0;
        return 0;
    }
    for(int i = 0; i < n - 3; i++)
    {
        for(int k = i + 2; k < n; k++)
        {
            if(s[i] == s[k])
                continue;
            if((s[i] == 'R' && s[k] == 'G') || (s[i] == 'G' && s[k] == 'R'))
            {
                cnt += b[k] - b[i];
            }
            if((s[i] == 'R' && s[k] == 'B') || (s[i] == 'B' && s[k] == 'R'))
            {
                cnt += g[k] - g[i];
            }
            if((s[i] == 'B' && s[k] == 'G') || ((s[i] == 'G' && s[k] == 'B')))
            {
                cnt += r[k] - r[i];
            }
            if((k + i) % 2 == 0)
            {
                int j = (k + i) / 2;
                if(s[i] != s[j] && s[j] != s[k])
                    cnt--;
            }
        }
    }
    cout << cnt;
    return 0;
}



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

int main() {
  int N;
  cin >> N;
  int k = 1;
  for (int i = 1800; i > 0; i -= 200) {
    if (N >= i) {
      cout << k << endl;
      break;
    }
    k++;
  }
}
  
      

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++) cin>>arr[i];
  int dp[n+1];
  dp[0]=0; dp[1]=abs(arr[1]-arr[0]);
  for(int i=2;i<n;i++)
  {
    int a = dp[i-1]+abs(arr[i]-arr[i-1]);
    int b = dp[i-2]+abs(arr[i]-arr[i-2]);
    dp[i] = min(a, b);
  }
  cout<<dp[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 4384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){

            int n,x;
             cin>>x>>n;

              set<int>p;

            for(int i=1;i<=n;i++){

                 int y;
                  cin>>y;

                  p.insert(y);
            }
             int val = 1e6;
               int num;
            for(int i=-200;i<=200;i++){

                 if(p.find(i)==p.end()){

                     if(val > abs(i-x))
                      {
                        num = i;
                         val = abs(i-x);
                      }
                 }
            }
            cout<<num;
}


Measured memory_bytes: 3616
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).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; }

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

    int N;
    cin >> N;

    string S1, S2;
    cin >> S1 >> S2;

    ll ans = 1;
    int pos = 0;
    int prev = -1;
    while (pos < N)
    {
        int mode = 0;
        if (S1[pos] == S2[pos])
        {
            mode = 0;
        }
        else
        {
            mode = 1;
        }

        if (mode == 0)
        {
            if (prev == 0)
            {
                ans *= 2;
            }
            else if (prev == 1)
            {
                ans *= 1;
            }
            else
            {
                ans *= 3;
            }

            pos += 1;
        }
        else
        {
            if (prev == 0)
            {
                ans *= 2;
            }
            else if (prev == 1)
            {
                //以下の3通り
                //AABB AABB AACC 
                //BBAA BBCC BBAA
                ans *= 3;
            }
            else
            {
                ans *= 6;
            }

            pos += 2;
        }

        ans %= MOD;

        prev = mode;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3604
from heapq import heappush, heappop

def resolve():
    n, m = map(int, input().split())
    jobs = [[] for _ in range(m+1)]
    for i in range(n):
        days, reward = map(int, input().split())
        if days <= m:
            jobs[days].append(-reward)

    res = 0
    heap = []
    # 残りi日の時点でどの仕事をするか
    for i in range(m+1):
        for j in jobs[i]:
            heappush(heap, j)
        if len(heap) > 0:
            res += -heappop(heap)

    print(res)
resolve()

Measured memory_bytes: 68000
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <complex>
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;

int main() {
	ll n, k;
	cin >> n >> k;
	ll num=0,ans;
	num = n % k;
	if (num == 0)ans = 0;
	else ans = min(abs(num - k), num);
	
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define se second
#define fi first

int32_t main(){
    
  int a,b,c;
  cin>>a>>b>>c;
  if((a==b && a!=c)  || (a==c && a!=b) ||(c==b && c!=a ))
    	cout<<"Yes";
  else
    	cout<<"No";
    
  
    
}

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

using namespace std;
using ll =long long;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
#define leftunique(a) {sort((a).begin(),(a).end());(a).erase(unique((a).begin(),(a).end()),(a).end());}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
static const ll INF = 1LL << 60;
//Write From this Line

int main()
{
	ll x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vector<ll> p(a), q(b), r(c);
	rep(i,a) cin >> p[i];
	rep(i,b) cin >> q[i];
	rep(i,c) cin >> r[i];
	sort(p.rbegin(),p.rend());
	sort(q.rbegin(),q.rend());
	sort(r.rbegin(),r.rend());
	// p(つまり赤)を大きい方からx個食べる
	// q(つまり緑)を大きい方からy個食べる
	ll ans = 0;
	vector<ll> look(x+y);
	rep(i,x){
		ans += p[i];
		look[i] = p[i];
	}
	rep(i,y){
		look[x+i] = q[i];
		ans += q[i];
	}
	sort(look.begin(),look.end());
	int count = 0;
	int tmp;
	rep(i,x+y){
		tmp=r[count];
		if(look[i] < r[count]){
			ans -= look[i];
			ans += r[count];
			count ++ ;
		}
	}
	cout << ans << endl;
}


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

class Mondai
{
    static void Main()
    {
        var N = Int32.Parse(Console.ReadLine());
        var x = new long[N];
        var y = new long[N];
        var dic = new Dictionary<string, int>();
        var max = 0;
        for (int i=0;i<N;++i)
        {
            var xy = Console.ReadLine().Split(' ').Select(n => Int64.Parse(n)).ToArray();
            x[i] = xy[0];
            y[i] = xy[1];
        }
        for (int i=0;i<N;++i)
        {
            for (int j=0;j<N;++j)
            {
                if (i == j) continue;
                var saX = x[i] - x[j];
                var saY = y[i] - y[j];
                var key = saX.ToString() + "_" + saY.ToString();
                if (!dic.ContainsKey(key))
                {
                    dic.Add(key, 1);
                    if (max < 1) max = 1;
                }
                else
                {
                    int num;
                    dic.TryGetValue(key, out num);
                    var updatedNum = num + 1;
                    dic[key] = updatedNum;
                    if (max < updatedNum) max = updatedNum;
                }
            }
        }
        var ans = N - max;
        if (ans < 0) ans = 1;
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13536
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, N);
    vector<ll> A(N);

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        ans += (a-1);
    }
    
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
ans = 0

for b in range(1, n+1):
    if b <= k:
        continue
    ans += (b-k)*(n//b)
    if n%b >= k:
        if k != 0:
            ans += n%b - k + 1
        else:
            ans += n%b - k
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
# define ll long long
# define mo 1000000009
using namespace std;
int main()
{
int n,r,sum=0;
cin>>n>>r;
if(n<=10)
sum=100*(10-n)+r;
else
sum=r;
cout<<sum;
return 0;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200200;
set<int>adj[N];
int n , pr[N] , d[N];

void dfs0(int u,int p=0){
pr[u]=p;
d[u]=1+d[p];
for(auto v:adj[u])
    if( v!=p )
        dfs0(v,u);
}

int dfs(int u,int p=0){
int ret=1;
for(auto v:adj[u])
if( v!=p ){
    ret+=dfs(v,u);
}
return ret;
}

int main(){

cin>>n;
for(int i=1;i<n;i++){
    int a,b;
    cin>>a>>b;
    adj[a].insert(b);
    adj[b].insert(a);
}

dfs0(1);

int x=n;
for(int i=0;i<(d[n]-2)/2;i++){
    x=pr[x];
}

adj[pr[x]].erase(x);
adj[x].erase(pr[x]);

int _1 = dfs(1);
int _2 = n - _1;

if( _1 > _2 )cout<<"Fennec"<<endl;
else         cout<<"Snuke"<<endl;

return 0;
}


Measured memory_bytes: 24448
import math
import bisect
import collections
import itertools
def gcd(a,b):return math.gcd #最大公約数
def lcm(a,b):return (a*b) // math.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i: divisors.append(n//i)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True

N,K = imn()
RSP = iln()
T = input()

Point = {}
Point['r'] = RSP[2]
Point['s'] = RSP[0]
Point['p'] = RSP[1]

ans = 0
for i in range(len(T)):
    prev = i - K
    if prev >= 0 and T[prev] == T[i]:
        T = T[:i] + 'x' + T[i+1:]
        continue
    ans += Point[T[i]]
print(ans)








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


int main(){
    int a,b;
    cin >> a >> b;
    if ( (0<a)&&(a<10)&&(0<b)&&(b<10) ){
        cout << a*b << endl;
    } else {
        cout << "-1" << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
    
    int train = 0;
    int bus = 0;
    
    if (a <= b) {
      train += a;
    } else {
      train += b;
    }
    if (c <= d) {
      bus += c;
    } else {
      bus += d;
    }
    
    System.out.println(train + bus);
  }
}

Measured memory_bytes: 21972
import java.util.*;
 
public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    String s=sc.next();
    if (s.charAt(2)==s.charAt(3)&&s.charAt(4)==s.charAt(5)) {
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#define N 100005
using namespace std;
typedef long long ll;
const ll mod = 1000000007LL;
ll n, m;
int main() {
  int a,b;
  cin>>a>>b;
  cout<<(a+b)%24<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int queue[1000];
int head=0;
int tail=0;
int n;
int adj[101][101];
int d[101];
int used[101];
void push(int x){
  queue[head]=x;
  head++;
}
int pop(){
  int x;
  x=queue[tail];
  tail++;
  return x;
}
void bfs(int x){
  int i;
  int v;
  push(x);
  used[x]=1;
  while(head!=tail){
    // for(i=tail;i<head;i++)printf("%d ",queue[i]);
    // printf("\n");
    v=pop();
    for(i=1;i<=n;i++){
      if(adj[v][i]==1 && used[i]==0){
    push(i);
    d[i]=d[v]+1;
    used[i]=1;
      }
    }
  }
}
int main(){
  int i,j;
  int u,k,v;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
    adj[u][v]=1;
    }
  }
 
  for(i=1;i<=n;i++)d[i]=0;
  bfs(1);
  for(i=2;i<=n;i++){
    if(d[i]==0)d[i]=-1;
  }
  for(i=1;i<=n;i++)printf("%d %d\n",i,d[i]);
  return 0;
}

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

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

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  LL N, D;
  cin >> N >> D;
 
  VL ds(N);
  REP(i,N) cin >> ds[i];
 
  VL xs(N+1);
  xs[0] = D;
  REP(i,N){
	xs[i+1] = min(xs[i], abs(xs[i] - ds[i]));
  }

  VL gr(N+1);
  gr[N] = 1;
  for(int i=N-1;i>=0;--i){
	if(gr[i+1] > ds[i] / 2)
	  gr[i] = gr[i+1] + ds[i];
	else
	  gr[i] = gr[i+1];
  }

  //REP(i,N+1) cout << xs[i] << " "; cout << endl;
  //REP(i,N+1) cout << gr[i] << " "; cout << endl;

  LL Q;
  cin >> Q;
  REP(i,Q){
	LL q;
	cin >> q;
	--q;
	if(xs[q] < gr[q+1]){
	  cout << "NO" << endl;
	}
	else
	  cout << "YES" << endl;
  }

  return 0;
}


Measured memory_bytes: 15104
#include<iostream>
    #include<vector>
    #include<math.h>
    #include<bits/stdc++.h>
    #include<sstream>
     
    using namespace std;
     
    int main()
    {
        float x, ans = 1;
        string a, b, c;

        cin >> a >> b;

        c = a + b;

        stringstream d(c);

        d >> x;

        while(ans < x)
        {
            if(x / pow(ans,2) == 1)
            {
                cout << "Yes";
                exit(0);
            }

            ans++;
        }

        cout << "No";
    }

Measured memory_bytes: 3724
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main()
{
	int N, M;

	while (cin >> N >> M && N > 0 && M > 0) {

		int h[1500], w[1500];
		int x[1501], y[1501];
		vector<int> b_m(1500001), b_p(1500001);
		int sum = 0;

		x[0] = 0;
		y[0] = 0;

		for (int i = 0; i < N; i++) {
			cin >> h[i];
			y[i + 1] = y[i] - h[i];
		}

		for (int i = 0; i < M; i++) {
			cin >> w[i];
			x[i + 1] = x[i] + w[i];
		}

		for (int i = 0; i <= M; i++) {
			for (int j = 0; j <= N; j++) {
				if (y[j] + x[i] < 0)
					b_m[(-1) * (x[i] + y[j])]++;

				else
					b_p[y[j] + x[i]]++;
			}
		}

		for (int i = 0; i < 1500001; i++) {
			int cnt;
			int n = b_p[i];
			if (n < 2)
				cnt = 0;
			else
				cnt = n*(n - 1) / 2;
			sum += cnt;
		}

		for (int i = 1; i < 1500001; i++) {
			int cnt;
			int n = b_m[i];
			if (n < 2)
				cnt = 0;
			else
				cnt = n*(n - 1) / 2;
			sum += cnt;
		}

		cout << sum << endl;
	}

    return 0;
}

Measured memory_bytes: 14488
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
  int sum, c[3];
  while (scanf("%d %d %d ", c, c + 1, c + 2) == 3) {
    sum = c[0] + c[1];
    int lower = 20 - sum;
    int counter = 0;
    for (int i = 0; i < 3; i++) {
      if (c[i] <= lower) {
	counter++;
      }
    }
    if ((double)(lower - counter) / 7 >= 0.5) {
      printf("YES\n");
    } else {
      printf("NO\n");
    }
  }
  return 0;
}

Measured memory_bytes: 0
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
signed main(){
    fastio
    int d ; 
    cin >> d ;
    int a , b ; 
    cin >> a >> b ; 
    for(int i = a; i < b + 1; i++){
        if ( i % d == 0 ){
            cout << "OK" << endl;
            return 0 ;
        }
    }
    cout << "NG" << endl;
    return 0; 
}

Measured memory_bytes: 3640
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
#from scipy.misc import comb

N,K = map(int, input().split())
A = [list(map(int, input().split())) for i in range(N)]
A.sort()

cnt = 0
for a,b in A:
    cnt += b
    if cnt >= K:
        print(a)
        break

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

using namespace std;

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

const int N = 1e5 + 10;

string a; 

int main()
{
	cin >> a;
	if(a == "SUN")
	{
		puts("7");
	}
	else if(a == "MON")
	{
		puts("6");
	}
	else if(a == "TUE")
	{
		puts("5");
	}
	else if(a == "WED")
	{
		puts("4");
	}
	else if(a == "THU")
	{
		puts("3");
	}
	else if(a == "FRI")
	{
		puts("2");
	}
	else
	{
		puts("1");
	}
 } 

Measured memory_bytes: 256
#include <iostream>
#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 n = s.length();

  int ans1 = (n+1)/2;
  for (int i = (n+1)/2; i < n; i++) {
    if (s[i] == s[(n+1)/2-1]) ans1++;
    else break;
  }
  reverse(s.begin(), s.end());
  int ans2 = (n+1)/2;
  for (int i = (n+1)/2; i < n; i++) {
    if (s[i] == s[(n+1)/2-1]) ans2++;
    else break;
  }
  int ans = min(ans1, ans2);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <algorithm>

using namespace std;

int n, m;
int p[1001];
int sp[1001*1001];

int main()
{
	for (;;)
	{
		scanf("%d %d", &n, &m);
		if (!n && !m)break;
		for (int i = 0; i < n; ++i)
		{
			scanf("%d", &p[i]);
		}
		p[n] = 0;
		int it = 0;
		for (int a = 0; a <= n; ++a)
		{
			for (int b = 0; b <= a; ++b)
			{
				sp[it++] = p[a] + p[b];
			}
		}
		sort(sp, sp + it);
		int *fr = sp;
		int *bk = sp + it - 1;
		int ans = 0;
		while(fr <= bk)
		{
			if ((*fr) + (*bk) <= m)
			{
				ans = max(ans, (*fr) + (*bk));
				++fr;
			}
			else
			{
				--bk;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 4660
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

def LI(): return list(map(int, sys.stdin.readline().split()))

a,b,x = LI()

water_area = x / a
if water_area >= (a * b / 2):
    b_ = (a * b - water_area) * 2 / a
    theta = math.degrees(math.atan(b_ / a))
else:
    a_ = (water_area * 2 / b)
    theta_ = math.degrees(math.atan(a_ / b))
    theta = 90 - theta_
print(theta)


Measured memory_bytes: 64876
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int K = scanner.nextInt();
        int[] numbers = new int[N+1];
        for (int i=0; i<=N; i++) {
            numbers[i] = i;
        }

        long sum = 0;

        long min = sum(numbers, K);
        long max = sumReverse(numbers, K);
        sum += max - min + 1;

        for (int i=K; i<=N; i++) {
            min = min + i;
            max = max + N - i;
            sum += max - min + 1;
        }
        System.out.println(sum % 1000000007);
    }
    static long sum(int[] array, int length) {
        long sum = 0;
        for (int i=0; i<length; i++) {
            sum += array[i];
        }
        return sum;
    }
    static long sumReverse(int[] array, int length) {
        long sum = 0;
        for (int i=array.length-1; i > array.length - 1 - length; i--) {
            sum += array[i];
        }
        return sum;
    }
}


Measured memory_bytes: 36464
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << #x << " " << x << '\n';
#define int long long
signed main()
{
    int n;
    cin >> n;
    string s;
    vector<string> v(n);
    for(int i=0;i<n;i++)
    {
        cin >> s;
        sort(s.begin(),s.end());
        v[i] = s;
    }
   int cnt=0;
    sort(v.begin(),v.end());
    int pos = 0,en=0;
    while(pos <=n-1)
    {
        en = pos;
        int t=0;
        while(en <= n-1)
        {
            if(v[pos]==v[en])
                en++;
            else break;
        }
        t = en-pos;
        cnt += t*(t-1)/2;
        pos = en;;
    }
    cout << cnt;

}


Measured memory_bytes: 5760
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    int N;
    cin >> N;
    set<char> ans;
    REP(i, N) {
        char s;
        cin >> s;
        ans.emplace(s);
    }
    YESNO(ans.size() == 3, "Three", "Four");
    return 0;

}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define F first
#define S second

int sen[10][10000];

main(){
  int c,r;
  while(cin>>r>>c,c|r){
    int ans=0;
    rep(i,r)rep(j,c)cin>>sen[i][j],ans+=sen[i][j];

    rep(i,1<<r){
      int tomote=0;
      rep(j,c){
        int romote=0;
        rep(k,r){
          if(sen[k][j]+(i>>k&1)&1)++romote;
          //cout<<(sen[k][j]^(i>>k&1))<<" ";
        }
        //cout<<endl;
        tomote+=max(romote,r-romote);
      }
      //cout<<tomote<<" "<<i<<endl;
      ans=max(ans,tomote);
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1252
from collections import deque

def search(tx, ty, kx, ky, mp):
  direct = ((-1, 0, 1, 0), (1, 0, -1, 0), (0, -1, 0, 1), (0, 1, 0, -1))
  dic = {}
  dic[(tx, ty, kx, ky)] = 0
  que = deque()
  que.append((0, (tx, ty, kx, ky)))
  while que:
    dist, p = que.popleft()
    tx, ty, kx, ky = p
    for dtx, dty, dkx, dky in direct:
      if mp[ty + dty][tx + dtx] == 0:
        ntx, nty = tx + dtx, ty + dty
      else:
        ntx, nty = tx, ty
      if mp[ky + dky][kx + dkx] == 0:
        nkx, nky = kx + dkx, ky + dky
      else:
        nkx, nky = kx, ky
      if (ntx, nty, nkx, nky) not in dic:
        if (ntx, nty) == (nkx, nky):
          print(dist + 1)
          return
        dic[(ntx, nty, nkx, nky)] = True
        que.append((dist + 1, (ntx, nty, nkx, nky)))
  else:
    print("NA")

while True:
  w, h = map(int, input().split())
  if w == 0:
    break
  tx, ty = map(int, input().split())
  kx, ky = map(int, input().split())
  mp = [[1] + list(map(int, input().split())) + [1] for _ in range(h)]
  mp.insert(0, [1] * (w + 2))
  mp.append([1] * (w + 2))

  search(tx, ty, kx, ky, mp)


Measured memory_bytes: 38108