akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"

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

const long long MOD = 1e9+7;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T>
void print(const vector<T> &v, const string &delimiter) { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

template<class T>
struct Bit {
    vector<T> bit[2];
    int N;

    Bit() {}
    Bit(int n): N(n) { for (int i = 0; i < 2; i++) bit[i].assign(n + 1, 0); }

    //[1, n]
    void init(int n) {
        for (int i = 0; i < 2; i++) bit[i].assign(n + 1, 0);
        N = n;
    }

    T sub_sum(int p, int i) {
        T s = 0;
        while (0 < i) {
            s += bit[p].at(i);
            i -= i & -i;
        }
        return s;
    }
    // 1-indexed
    T sum(int i) { return sub_sum(0, i) + sub_sum(1, i) * i; }
    // [a, b]
    T sum(int a, int b) { return sum(b) - sum(a - 1); }

    void sub_add(int p, int i, T v) {
        while (i <= N) {
            bit[p].at(i) += v;
            i += i & -i;
        }
    }
    //[a, b] 1-indexed
    void add(int a, int b, T v) {
        sub_add(0, a, -v * (a - 1));
        sub_add(1, a, v);
        sub_add(0, b + 1, v * b);
        sub_add(1, b + 1, -v);
    }
};

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

    vector<Bit<int>> bits(26);
    rep(i, 26) bits.at(i).init(n + 1);

    rep(i, n) {
        int c = s.at(i) - 'a';
        bits.at(c).add(i + 1, i + 1, 1);
    }

    int q;
    cin >> q;
    rep(_q, q) {
        int query;
        cin >> query;
        if (query == 1) {
            int idx;
            char c;
            cin >> idx >> c;

            int ci = c - 'a';
            int prev_ci = s.at(idx - 1) - 'a';

            bits.at(prev_ci).add(idx, idx, -1);
            bits.at(ci).add(idx, idx, 1);
            s.at(idx - 1) = c;
        }
        else {
            int l, r;
            cin >> l >> r;

            int cnt = 0;
            rep(i, 26) cnt += min(1, bits.at(i).sum(l, r));
            cout << cnt << endl;
        }
    }
}

Measured memory_bytes: 102660
#include <bits/stdc++.h>
#define pb push_back
#define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define fr first
#define sc second
using namespace std;
ll ar[26] ;
int main()
{
    ///freopen("input.txt" , "r" , stdin );
    ///freopen("output.txt", "w" , stdout );
    ///Murtazoev_2007
    speed ;
    ///Autor of the greatest code :: Ahmadjon Murtazoev
    string al = "abcdefghijklmnopqrstuvwxyz" ;
    string str ;
    cin >> str ;
    ll a = str.size() ;
    for (ll i = 0 ; i<26 ; i ++ )
    {
        for (ll j = 0 ; j<a ; j ++ )
        {
            if (str[j] == al[i])
            {
                ar[i] ++ ;
            }
        }
    }
    for (ll i = 0 ; i<26 ; i ++ )
    {
        if (ar[i]%2 != 0)
        {
            cout << "No" << endl ;
            return 0 ;
        }
    }
    cout << "Yes" << endl ;
    return 0 ;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
 
#ifndef ONLINE_JUDGE
	#define W(x, y) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << y;
#else
	#define W(x, y)
#endif
 
 
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<pii>
#define vl vector<ll>
#define vll vector<pll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pi acosl(-1)
#define ld long double
#define prime (1000000000 + 7)
#define INF 1000000000
 
using namespace std;



int main(){
	#ifdef ONLINE_JUDGE
		ios::sync_with_stdio(false);
		cin.tie(0); cout.tie(0);
	#endif

	ll n, k;
	cin >> n >> k;
	if(k >= (1 << n) || (n == 1 && k == 1)) {
		cout << -1 << "\n";
	} else if(n == 1 && k == 0) {
		cout << "0 0 1 1\n";
	} else{
		cout << k << " ";
		for(int i = 0; i < (1 << n); ++i){
			if(i != k){
				cout << i << " ";
			}
		}
		cout << k << " ";
		for(int i = (1 << n) - 1; i >= 0; --i){
			if(i != k){
				cout << i << " ";
			}
		}
		cout << "\n";
	}


	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(){
  int i,a,b,t=1;
  char s[12];
  scanf("%d%d%s",&a,&b,s);
  for(i=0;i<a;i++)if(s[i]=='-')t=0;
  if(s[a]!='-')t=0;
  for(i=0;i<b;i++)if(s[i+a+1]=='-')t=0;
  printf(t?"Yes":"No");
}


Measured memory_bytes: 1728
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include<string>

using namespace std;

int main()
{
    string S;
    cin >> S;
    for(int i = 0; i < S.length(); i++){
        cout << "x" ;
    }
    return 0;
}


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

constexpr int64_t MOD= 1'000'000'007;
constexpr bool is_FACTORIAL_STORED= false; // 階乗を配列に格納をする前処理をする/しない
constexpr int Nfac= is_FACTORIAL_STORED ? 100'007
                                        : 0;
/* 剰余環 Z/nZ */
struct mint{ // Z/nZ に関する演算(n:素数の場合は除算も)をサポートする構造体
  int64_t rep; // 出力すべき代表元 rep \in {0,1,..,MOD- 1}
  mint(int64_t x=0): rep(((x%MOD)+ MOD)% MOD){}
  mint operator-() const { return mint(-rep);}
  mint& operator+=(const mint& x){
    rep+= x.rep; 
    if(rep>= MOD) rep-= MOD;
    return *this;
  }
  mint& operator-=(const mint& x){
    rep-= x.rep;
    if(rep< 0) rep+= MOD;
    return *this;
  }
  mint& operator*=(const mint& x){
    rep*= x.rep; rep%= MOD;
    return *this;
  }
  mint operator+(const mint x) const {
    mint ans(*this);
    ans+= x;
    return ans;
  }
  mint operator-(const mint x) const {
    mint ans(*this);
    ans-= x;
    return ans;
  }
  mint operator*(const mint x) const {
    mint ans(*this);
    ans*= x;
    return ans;
  }
  bool operator==(const mint x) const {
    return rep==x.rep;
  }
  bool operator!=(const mint x) const {
    return rep!=x.rep;
  }

  mint pow(int64_t d) const{
    assert(d >= 0); // ここで引っかかったら this.pow(d)= 0 or this.pow(-d).inv() のどちらかを選べ
    assert(!(*this==0 && d==0)); //   this.pow(d)= 0 or 1           　     のどちらかを選べ
    mint ans= 1;
    mint x= *this;
    while(d > 0){
      if(d&1){ ans*= x; }
      d >>= 1;
      x*= x;
    }

    return ans;
  }

  friend istream& operator >> (istream &is, mint& x) noexcept{
    int64_t a;
    is >> a;
    x= a;
    return is;
  }
  friend ostream& operator << (ostream &os, const mint& x) noexcept{
      return os << x.rep;
  }
  // MOD が素数(<=> Z/nZ が体)のとき
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint& x){
    *this *= x.inv();
    return *this;
  }
  mint operator/(const mint x) const {
    mint ans(*this);
    ans/= x;
    return ans;
  }
};
// ^^^ テンプレここまで ^^^

int main(){
  constexpr char block= '#';

  int H,W;
  cin >> H >> W;

  vector<string> board(H);
  for(int h=0; h<H; h++){
    cin >> board.at(h);
  }

  vector<vector<mint>> dp(H, vector<mint>(W));
  for(int h=0; h<H; h++){
    dp.at(h).at(0)= (h==0)                     ? 1
                   :(board.at(h).at(0)==block) ? 0
                                               : dp.at(h-1).at(0);
    for(int w=1; w<W; w++){
      dp.at(h).at(w)= (board.at(h).at(w)==block) ? 0
                     :(h==0)                     ? dp.at(h).at(w-1)
                                                 : dp.at(h).at(w-1)+ dp.at(h-1).at(w);
    }
  }

  cout << dp.back().back() << endl;
}

Measured memory_bytes: 13028
import sys
from itertools import accumulate

def resolve():
        input = sys.stdin.readline
        N=int(input().rstrip())
        A1=list(map(int,input().rstrip().split()))
        A2=list(map(int,input().rstrip().split()))

        csumA1=[0]+A1
        csumA2=[0]+A2
        csumA1=list(accumulate(csumA1))
        csumA2=list(accumulate(csumA2))
        sum=0
        for i in range(1,N+1,1):
            sumA1=csumA1[i]-csumA1[0]
            sumA2=csumA2[N]-csumA2[i-1]
            sum=max(sum,sumA1+sumA2)
        print(sum)



from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """5
3 2 2 4 1
1 2 2 2 1"""
        output = """14"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """4
1 1 1 1
1 1 1 1"""
        output = """5"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """7
3 3 4 5 4 5 3
5 3 4 4 2 3 2"""
        output = """29"""
        self.assertIO(input, output)
    def test_入力例_4(self):
        input = """1
2
3"""
        output = """5"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

Measured memory_bytes: 50288
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
#define fi first
#define se second

int main()
{
	int k,a,b;
	cin >> k >> a >> b;
	if(a>b)swap(a,b);
	for(int i=a;i<=b;i++)
	{
		if(i%k==0)
		{
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
	return 0;
}


Measured memory_bytes: 3632
import sys,math,collections,itertools
input = sys.stdin.readline

x=0
y=0
z=0
xyz=[]
N,M=list(map(int,input().split()))
for _ in range(N):
    x0,y0,z0 = list(map(int,input().split()))
    x+=x0
    y+=y0
    z+=z0
    xyz.append([x0,y0,z0])
lmn =[]

for x0,y0,z0 in xyz:
    tmp = [x0,y0,z0]
    for fx in [-1,1]:
        for fy in [-1,1]:
            for fz in [-1,1]:
                tmp.append(x0*fx+y0*fy+z0*fz)
    lmn.append(tmp)

ans = 0
for i in range(8):
    lmn.sort(key = lambda x:-x[i+3])
    x=0
    y=0
    z=0
    for j in range(M):
        x += lmn[j][0]
        y += lmn[j][1]
        z += lmn[j][2]
    ans = max(ans,abs(x)+abs(y)+abs(z))
print(ans)
        
    


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

using namespace std;


int main()
{

    int N;
    vector<int> xv;
    vector<int> yv;
    vector<int> hv;
    int tmpch;
    bool check;

    cin>>N;

    xv.resize(N);
    yv.resize(N);
    hv.resize(N);

    for(int i=0; i<N; ++i)
    {
        int x, y, z;
        cin >> x >> y >> z;
        xv[i]=x;
        yv[i]=y;
        hv[i]=z;
    }


    int maxNum = *max_element(hv.begin(), hv.end());

    for(int cx=0; cx<=100; ++cx)
    {
        for(int cy=0; cy<=100; ++cy)
        {
            for(int ch=maxNum; ch<=maxNum+200; ++ch)
            {
                check=true;
                for(int k=0; k<N; ++k)
                {
                    int h=max(ch-abs(xv[k]-cx)-abs(yv[k]-cy), 0);
                    if(h!=hv[k])
                        check=false;
                }
                if(check)
                {
                    cout<<cx<<" "<<cy<<" "<<ch<<endl;
                    return 0;
                }


            }

        }
    }

    return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import System.IO.Unsafe
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
-- end of templete


main = do
    s <- sort <$> getLine
    t <- sortBy (flip compare) <$> getLine
    putStrLn $ cond "Yes" "No" $ s < t

Measured memory_bytes: 508
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

typedef struct{
  char name[128];
  unsigned int minprice;
  short fr_oth;
} item;

typedef struct{
  char to[128];
  unsigned int num;
  char **from;
} gosei;

item *list;
gosei *makelist;
unsigned int m,n;

void makegosei(gosei *var);
unsigned int makeans(item *var);
void freegosei(gosei *var);

int main(void){
  unsigned int i,j,k,ans;
  char tmpstr[128];
  unsigned int inputs;
  while(scanf("%u%*c",&n) &&n){
    list=(item *)calloc(n,sizeof(item));
    for(i=0;i<n;i++)
      scanf("%s %u%*c",list[i].name,&(list[i].minprice));

    scanf("%u%*c",&m);
    makelist=(gosei *)calloc(m,sizeof(gosei));
    for(i=0;i<m;i++){
      scanf("%s %u%*c",tmpstr,&inputs);
      for(j=0;j<n;j++){
	if(strcmp(list[j].name,tmpstr))continue;
	list[j].fr_oth=1;
	break;
      }
      strcpy(makelist[i].to,tmpstr);
      makelist[i].num=inputs;
      makegosei(makelist+i);
      for(j=0;j<makelist[i].num;j++)
	scanf("%s%*c",makelist[i].from[j]);
    }
    scanf("%s%*c",tmpstr);
    for(i=0;i<n;i++){
      if(strcmp(list[i].name,tmpstr)) continue;
      k=i;
      break;
    }
    
    ans=makeans(&list[k]);
    printf("%u\n",ans);
    free(list);
    for(i=0;i<m;i++) freegosei(makelist+i);
    free(makelist);
  }
  return 0;
}

void makegosei(gosei *var){
  unsigned int i;
  var->from=(char **)calloc(var->num,sizeof(char *));
  for(i=0;i<var->num;i++)
    (var->from)[i]=(char *)calloc(128,sizeof(char));
}

void freegosei(gosei *var){
  unsigned int i;
  for(i=0;i<var->num;i++)
    free((var->from)[i]);
  free(var->from);
}

unsigned int makeans(item *var){
  unsigned int i,j,k,tmp;
  if(var->fr_oth==1){
    tmp=0;
    for(i=0;i<m;i++){
      if(strcmp(makelist[i].to,var->name)) continue;
      k=i;
      break;
    }
    for(i=0;i<makelist[k].num;i++){
      for(j=0;j<n;j++){
	if(strcmp(makelist[k].from[i],list[j].name)) continue;
	break;
      }
      tmp+=makeans(&list[j]);
    }
    if(var->minprice>tmp) var->minprice=tmp;
    var->fr_oth=0;
  }
  return var->minprice;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll arr[100005];


int main()
{
    ll n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        arr[a]+=b;
    }
    for(ll i=1;i<=100000;i++){
        k-=arr[i];
        if(k<=0){
            cout<<i;
            return 0;
        }
    }

}


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

int main() {
  int N;
  cin >> N;
  vector<pair<int,int>> entries(0);
  int A;
  rep(i,N) {
    cin >> A;
    entries.push_back(make_pair(A, i+1));
  }
  sort(entries.begin(), entries.end());
  rep(i,N) {
    cout << entries.at(i).second;
    if ( i == N -1 ) {
      cout << endl;
    }
    else {
      cout << " ";
    }
  }
}

Measured memory_bytes: 1780
//<MIHIR KHAMBHATI/>
#include <bits/stdc++.h>
using namespace std;
#define _                             \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define ideb \
    int _p_; \
    cin >> _p_;
typedef long long int ll;
typedef unsigned long long int ull;

vector<int> dp(100002, 0);
bool vis[100002];
vector<vector<int>> v(100002);

void solve(int x, int n)
{
    int p = v[x].size();
    int c = 0;
    for (int i = 0; i < p; i++)
    {
        if (!vis[v[x][i]])
        {
            solve(v[x][i], n);
            vis[v[x][i]] = 1;
        }
        c = max(c, dp[v[x][i]] + 1);
    }
    dp[x] = c;
    vis[x] = 1;
}

void go(int n)
{
    for (int i = 1; i <= n; i++)
    {
        if (!vis[i])
            solve(i, n);
    }
}

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

    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
    }

    go(n);

    int ans = 0;

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


Measured memory_bytes: 8960
#include<stdio.h>
#include<string.h>
 
int main(void)
{
	int C = 0;
	int i,j,p;
	char S[26];
	scanf("%26s",S);
	p  = strlen(S);
	for( i = 0; i < p; i++){
	for( j = 0; j < p; j++){
		if( S[i] == S[j] ) C++ ;
	}
	}
	if( C == p)  printf("yes");
	else printf("no");
	return 0;
}

Measured memory_bytes: 128
n,m=map(int,input().split())
l=[]
for i in range(n):
  a,s=map(int,input().split())
  l.append([a,s])
l=sorted(l)
p=0
c=0
for i in range(len(l)):
  if c+l[i][1]>m:
    p+=l[i][0]*(m-c)
    break
  else:
    p+=l[i][0]*l[i][1]
    c+=l[i][1]
print(p)

Measured memory_bytes: 20832
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n,x;
int main(){
    cin>>n>>x;
    vector<int>l(n+1);
    for(int i=1;i<=n;i++)cin>>l[i];
    for(int i=1;i<=n;i++)l[i]+=l[i-1];
    cout<<upper_bound(l.begin(),l.end(),x)-l.begin()<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAX 123123
int arr[MAX],N;

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  if(A+B>C+D)cout << "Left" << endl;
  else if(A+B==C+D)cout << "Balanced" << endl;
  else cout << "Right" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define tarce(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n+1]; for(int i = 1 ; i<=n ; i++) cin>>a[i]
#define scan2() int n,k; cin>>n>>k ; int a[n+1]; for(int i = 1 ; i<=n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define mkp make_pair
using namespace std;
#define N 200005
/* The judge is never wrong! Your code is buggy ??
   Look for:
 * * an easier and alternate approach
 * * if concept is corret and still WA, try with a different implementation
 * * special cases (n=1?)
 * * overflow (ll vs int?)
 * * array bounds
 * * if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
 */




int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);

        int n,m;
        cin >> n >> m;
        int s=0;
        for(int i=0; i<m; i++){
            int x;
            cin >> x;
            s+=x;
        }
        if(n>=s){
            cout << n-s;
        }
        else{
            cout << -1;
        }

}


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

public class Main {

	//自分が書いたコード
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] in = new int[10];
		for (int i = 0; i < 10; i++) {
			in[i] = sc.nextInt();
		}

		Arrays.sort(in);
		for (int i = 9; 7 <= i; i--) {
			System.out.println(in[i]);
		}
	}

}


Measured memory_bytes: 26268
#include<bits/stdc++.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;

ll M,N,P[1001];

int main(){
	while(scanf("%lld%lld",&N,&M),N){
		for(int i=0;i<N;i++) scanf("%lld",&P[i]);
		vector<ll> d;
		for(int i=0;i<=N;i++) for(int j=0;j<=N;j++)
			d.push_back(P[i]+P[j]);
		sort(d.begin(),d.end());
		vector<ll>::iterator it;
		ll res=0;
		for(int i=0;i<d.size();i++){
			it=upper_bound(d.begin(),d.end(),M-d[i]);
			if(it!=d.begin()){
				it--;
				res=max(res,*it+d[i]);
			}
		}
		printf("%lld\n",res);
	}
}

Measured memory_bytes: 17152
#include <iostream>
  #include <iomanip>
  #include <algorithm>
  #include <cmath>
  #include <queue>
  #include <list>
  #include <limits>
  #include <string>
  #include <vector>
  #include <stack>
  using namespace std;
  typedef long long ll;

  typedef pair<ll, ll> curr;
  const int MOD = 998244353;


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

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

  }
  int main(){
    ll A,B;
    cin >> A >> B;
    if(A == B) cout << A;
    else
    if(A%2 == 0){
      if(B%2 != 0){
        if((B-A-1)/2%2 == 0) cout << 1;
        else cout << 0;
      }else{
        if((B-A-1)/2%2 == 0) cout << (B^1);
        else cout << B;
      }
    }else{
      if(B%2 != 0){
        if((B-A-1)/2%2 == 0) cout << (A^1);
        else cout << A;
      }else{
        if((B-A-1)/2%2 == 0) cout << (A^B);
        else cout << (A^B^1);
      }
    }
  }


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    int i;
    int ans;
    for (i = m / n; i > 0; i--)
        if (m%i == 0 && m / i >= n)
        {
            ans = i;
            break;
        }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<map>

using namespace std;

int main( ){
    string l;
    int t=0;
	string max="";
	map<string,int> str;
	string s;
	while(cin>>s){
            if(s.length()>max.length())max=s;
            str[s]++;
            if(str[s]>t){
                t=str[s];
                l=s;
            }
	}
	cout<<l<<" "<<max<<endl;
	return 0;
}

Measured memory_bytes: 1196
n = int(input())
csf = [list(map(int, input().split())) for _ in range(n-1)]
ans = []
for i in range(n-1):
    time = 0
    for p in range(i, n - 1):
        c, s, f = csf[p]
        if s >= time:
            time = s+c
        else:
            d = time - s
            time = s + f * (-(-d // f)) + c
    ans.append(time)

ans.append(0)

for i in range(n):
    print(ans[i])


Measured memory_bytes: 9092
#include <algorithm>
#include<string>
#include<iostream>
using namespace std;
int main() {
    int N;
    cin >> N;
    int B[N];
    for(int i=0;i<N-1;++i){
        cin >> B[i] ;
    }
    int s=B[0];
    int b=B[0];
    if(N>2){
        for(int i=1;i<N-1;++i){
            s+=min(b,B[i]);
            b=B[i];
        }
        cout << s +B[N-2] << endl;
    }else{
        cout << 2*s<< endl;
    }
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N, x int
	fmt.Scan(&N, &x)
	var c, l int
	fmt.Scan(&l)
	for i := 1; i < N; i++ {
		var r int
		fmt.Scan(&r)
		n := l + r - x
		if n < 0 {
			l = r
			continue
		}
		c += n
		l = r - n
		if l < 0 {
			l = 0
		}
	}
	fmt.Println(c)
}


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

#define endl '\n'
#define ll long long
#define rint register int

#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;
#define scan(a, n) 		for(int i = 0; i < n; i++)cin >> a[i];

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 100007

ll f[hell];

int32_t main() {
	ios::sync_with_stdio(0); 		cin.tie(0); cout.tie(0);

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

	ll t, i, x, j, y, 	z = 0, k, n;
	cin >> n;
	ll a[n];
	rep(i, 0, n, 1) {
		cin >> x;
		z += x;
		f[x]++;
	}
	cin >> t;
	while (t--) {
		cin >> x >> y;
		z -= x * f[x];
		z -= y * f[y];
		f[y] += f[x];
		f[x] = 0;
		z += y * f[y];
		
		ce(z)
	}
}


Measured memory_bytes: 4344
#include <stdio.h>
int main(){
    int n,h,w;
    scanf("%d %d %d",&n,&h,&w);
    int a[n];
    int b[n];
    int c;
    c = 0;
    for(int i = 0;i<n;i++){
        scanf("%d %d",a+i,b+i);
        if(a[i]>=h&&b[i]>=w){
            c++;
        }
    }
    printf("%d\n",c);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,K;
    cin >> N >> K;
    vector<ll> a(N), S(N+1), v,vv;
    rep(i,N){
        cin >> a[i];
    }
    rep(i,N){
        S[i+1] = a[i] + S[i];
    }
    //ll ans = 0;
    rep(l,N){
        REP(r,l+1,N+1){
            v.push_back(S[r] - S[l]);
        }
    }
    ll ans = 0;
    for(ll i = 40; i>=0; i--){
        ll cnt = 0;
        vv.clear();
        for(auto& b:v){
            if((1LL << i)&b){
                cnt++;
                vv.push_back(b);
            }
        }
        if(cnt >= K){
            ans += (1LL << i);
            v = vv;
        }
    }
    cout << ans << endl;
    /*
    vector<vector<ll>> S(N+1, vector<ll>(30));
    rep(i,N){
        rep(j,30){
            if((a[i]>>j)&1LL){
                S[i+1][j] = ((S[i][j]==0)?1LL:0LL);
            }else{
                S[i+1][j] = S[i][j];
            }
        }
    }
    ll ans = 0;
    rep(i,N){
        REP(j,i+1,N+1){
            ll tmp = 0;
            rep(k,30){
                if(S[i][k] != S[j][k]){
                    tmp += (1LL << k);
                }
            }
            cmax(ans, tmp);
        }
    }
    cout << ans << endl;*/
}

Measured memory_bytes: 8988
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/3/16
Solved on 2019/3/
@author: shinjisu
"""


# ABC 093 C Same Integer
#import math
#import numpy as np

def getInt(): return int(input())

def getIntList(): return [int(x) for x in input().split()]
# def getIntList(): return np.array(input().split(), dtype=np.longlong)

def zeros(n): return [0]*n
# def zeros(n): return np.zeros(n, dtype=np.longlong)

def getIntLines(n): return [int(input()) for i in range(n)]
"""
def getIntLines(n):
    data = zeros(n)
    for i in range(n):
        data[i] = getInt()
    return data
"""

def zeros2(n, m): return [zeros(m)]*n # obsoleted zeros((n, m))で代替

def getIntMat(n, m):  # n行に渡って、1行にm個の整数
    #mat = zeros((n, m))
    mat = zeros2(n, m)
    for i in range(n):
        mat[i] = getIntList()
    return mat

ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]
N1097 = 10**9 + 7
INF = 10**18

class Debug():
    def __init__(self):
        self.debug = True
 
    def off(self):
        self.debug = False
 
    def dmp(self, x, cmt=''):
        if self.debug:
            if cmt != '':
                print(cmt, ':  ', end='')
            print(x)
        return x


def prob():
    d = Debug()
    d.off()
    PATTERN = {(0,0,1):1, (0,1,1):2, (0,0,2):2, (0,1,2):3,
               (0,2,2):1, (1,1,2):1, (1,2,2):2, (0,0,0):0,}
    a = getIntList()
    d.dmp((a),'a')
    a.sort()
    b = zeros(3)
    b[0] =  (a[-1]-a[0]) // 2
    b[1] =  (a[-1]-a[1]) // 2
    d.dmp(b, 'b')
    a[0] +=  b[0]*2
    a[1] +=  b[1]*2
    mina = min(a)
    a.sort()
    d.dmp((a),'a')
    for i in range(3):
        a[i] -= mina
    d.dmp((a),'a')
    c = a[0], a[1], a[2]
    d.dmp(c, 'c')
    count = sum(b) + PATTERN[c]
    d.dmp(count, 'count')
    return count


ans = prob()
if ans is None:
    pass
elif type(ans) == tuple and ans[0] == 1:  # 1,ans
    for elm in ans[1]:
        print(elm)
else:
    print(ans)


Measured memory_bytes: 3192
MIS = lambda: map(int,input().split())

def match(L, R):
    #print(L, R)
    
    L.sort(); R.sort()
    match = 0
    lself = rself = 0
    lrem = rrem = 0
    while L:
        if len(L) >= 2 and L[-1] == L[-2]:
            lself+= 1; match+= 1
            L.pop(); L.pop()
        else: lrem+= 1; L.pop()
    while R:
        if len(R) >= 2 and R[-1] == R[-2]:
            rself+= 1; match+= 1
            R.pop(); R.pop()
        else: rrem+= 1; R.pop()
    while lrem and rrem:
        lrem-= 1; rrem-= 1
        match+= 1
    while lrem >= 2 and rself:
        lrem-= 2; rself-= 1
        match+= 1
    while rrem >= 2 and lself:
        rrem-= 2; lself-= 1
        match+= 1
    
    return match

n, m = MIS()
card = [[] for i in range(m)]
for x in MIS(): card[x%m].append(x//m)

tot = len(card[0])//2
for i in range(1, (m+1)//2):
    tot+= match(card[i], card[m-i])
if m%2 == 0: tot+= len(card[m//2])//2
print(tot)

Measured memory_bytes: 62256
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

using ll = long long;
#define INF 1e9
#define MOD 1e9 + 7
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop(i, a, n) for(int i = a; i < n; i++)
#define all(in) in.begin(), in.end()
int main(){
    int n, r;
    while(true){
        cin >> n >> r;
        if(n == 0 && r == 0) break;
        int p[r], c[r];
        rep(i, r) cin >> p[i] >> c[i];
        map<int, int> mp;
        for(int i = 1; i <= n; i++) mp[i] =  n + 1 - i;
        rep(i, r){
            const int P = p[i], C = c[i];
            int A[P + 1] = {0}, B[C + 1] = {0};
            loop(i, 1,  P) A[i] = mp[i];
            loop(i, 1 , C + 1) B[i] = mp[i + P - 1];
            loop(i, 1,  P + C){
                if(i <= C) mp[i] = B[i];
                else mp[i] = A[i - C];
            }
        }
        cout << mp[1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3004
S = list(input())
T = list(input())

for j in range(len(S)):
	for i in range(len(S)):
		if S[i] != T[i]:
			coincide = False
			break
		else :
		    coincide = True
	if coincide :
		break
	T.append(T[0])
	T.pop(0)

if coincide:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main(){
    int n,k;
    cin>>n>>k;
    vector<ll> sum(n+1);
    rep(i,n) {
        ll a;
        cin>>a;
        sum[i+1]=sum[i]+a;
    }
    
    vector<ll> beauty;
    FOR(r,1,n){
        FOR(l,0,r-1){
            beauty.push_back(sum[r]-sum[l]);
        }
    }
    
    //for(int x:beauty) cout<<x<<endl;
    
    int m=sz(beauty);
    vector<bool> check(m,true);
    rrep(d,41){
        int cnt=0;
        rep(i,m){
            if(!check[i]) continue;
            if(beauty[i]&(1ll<<d)) cnt++;
        }
        
        if(cnt<k) continue;
        
        rep(i,m){
            if(!(beauty[i]&(1ll<<d))) check[i]=false;
        }
        
        if(cnt==k) break;
        //cout<<d<<" "<<cnt<<endl;
    }
    
    ll ans=-1;
    int cnt=0;
    rep(i,m) if(check[i]) {
        if(ans==-1) ans=beauty[i];
        else ans &= beauty[i];
        cnt++;
        if(cnt==k) break;
    }
    cout<<ans<<endl;
}




Measured memory_bytes: 6388
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <random>

#include <fstream>
#include <vector>
#include <algorithm>

#define ll long long int

using namespace std;

int main(void)
{

    
    ll n;
    deque<char> res;
    
    cin >> n;
    
    for(ll i = 0; n > 0; i++)
    {
        switch(n % 26)
        {
            case 1:
                res.push_front('a');
                break;
            case 2:
                res.push_front('b');
                break;
            case 3:
                res.push_front('c');
                break;
            case 4:
                res.push_front('d');
                break;
            case 5:
                res.push_front('e');
                break;
            case 6:
                res.push_front('f');
                break;
            case 7:
                res.push_front('g');
                break;
            case 8:
                res.push_front('h');
                break;
            case 9:
                res.push_front('i');
                break;
            case 10:
                res.push_front('j');
                break;
            case 11:
                    res.push_front('k');
                    break;
                case 12:
                    res.push_front('l');
                    break;
                case 13:
                    res.push_front('m');
                    break;
                case 14:
                    res.push_front('n');
                    break;
                case 15:
                    res.push_front('o');
                    break;
                case 16:
                    res.push_front('p');
                    break;
                case 17:
                    res.push_front('q');
                    break;
                case 18:
                    res.push_front('r');
                    break;
                case 19:
                    res.push_front('s');
                    break;
                case 20:
                    res.push_front('t');
                    break;
                case 21:
                    res.push_front('u');
                    break;
                case 22:
                    res.push_front('v');
                    break;
                case 23:
                    res.push_front('w');
                    break;
                case 24:
                    res.push_front('x');
                    break;
                case 25:
                    res.push_front('y');
                    break;
                case 0:
                    res.push_front('z');
                    break;
        }
        
        if(n == 26)
        {
            break;
        }
        if(n % 26 == 0)
        {
            n = (ll)ceil(n/26);
            n--;
        }
        else
        {
            n = (ll)ceil(n/26);
        }
        
    }
    
    for(ll i = 0; i < (ll)res.size(); i++)
    {
        cout << res[i];
    }
    
    return 0;
}

Measured memory_bytes: 3608
# -*- coding: utf-8 -*-
from sys import stdin

def shisha(f):
    if f - int(f) >= 0.5:
        return int(f) + 1
    else:
        return int(f)

N = int(stdin.readline().rstrip())
a = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0

near = shisha(sum(a)/N)

for i in range(N):
    ans += (a[i] - near) ** 2
    
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define fir first
#define sec second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=3e5+5;
char buf[1<<12],*p1=buf,*p2=buf,nc;int ny;
inline char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}int n,a[MAXN],tot[2],Sum[MAXN];
inline bool chk(int mid){
	int k=0;
	for(int i=2;i<=n;i+=2)if(Sum[i-1]-k>=mid)
		k=min(k,Sum[i]);
	return Sum[n]-k>=mid;
}
int main(){
	n=read();Rep(i,1,n)tot[i&1]+=a[i]=read();
	if(!(n&1))cout<<max(tot[0],tot[1])<<' '<<min(tot[0],tot[1])<<"\n";
	else{
		Rep(i,1,n)Sum[i]=Sum[i-1]+(i&1?a[i]:-a[i]);
		int l=0,r=tot[0]+tot[1],ans=0;
		for(int mid;l<=r;)mid=l+r>>1,chk(mid)?l=mid+1,ans=mid:r=mid-1;
		cout<<tot[0]+ans<<" "<<tot[1]-ans<<'\n';
	}
	return 0;
}




Measured memory_bytes: 5984
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n)for(int i=0; i<n; i++)
using namespace std;

int main(){
    int n;
    string s;
    cin >> n >> s;
    vector<bool> flag(n);
    rep(i, n){
        if(s[i]=='R') flag[i]=false;
        if(s[i]=='W') flag[i]=true;
    }

    int ans=0;
    int mae=0;
    for(int j=n-1; j>=mae; j--){
        if(flag[j]==false){
            for(int i=mae; i<j ;i++){
                if(flag[i]==true){
                    flag[i]=false;
                    flag[j]=true;
                    mae=i+1;
                    ans++;
                    break;
                }
                if(i==j-1) mae=i;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3720
import sys

s = input()

rem = []
remrev = []

for i in s:
    if i != "x":
        rem.append(i)
        remrev.append(i)

remrev.reverse()

for i in range(len(rem)):

    if rem[i] != remrev[i]:
        print (-1)
        sys.exit()

nx = 0
xnum = []

for i in s:

    if i == "x":
        nx += 1
    else:
        xnum.append(nx)
        nx = 0

xnum.append(nx)

xnc = xnum.copy()
xnc.reverse()

ans = 0

for i in range((len(xnum) + 1) // 2):

    ans += abs(xnum[i]-xnc[i])

print (ans)

Measured memory_bytes: 6432
#include<stdio.h>
#define MAX 20000000

void CountingSort(int [],int [],int);
int Array1[MAX],Array2[MAX],k=0,n;

int main(){
  int i;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&Array1[i]);
    if(k<=Array1[i]){
      k=Array1[i];
    }
  }
  CountingSort(Array1,Array2,k);  
  for(i=1;i<=n;i++){
    if(i==n){
      printf("%d\n",Array2[i]);
    }
    else printf("%d ",Array2[i]);
  }
  return 0;
}

void CountingSort(int A[],int B[],int k){
  int i,j,C[k+1];
  for(i=0;i<=k;i++){
    C[i]=0;
  }
  for(j=1;j<=n;j++){
    C[A[j]]++;
  }
  for(i=1;i<=k;i++){
    C[i]+=C[i-1];
  }
  for(j=n;j>=1;j--){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
}

Measured memory_bytes: 17012
import sys
import collections
from functools import reduce
import operator as op


def nCr(n,r):
    r = min(r,n-r)
    """ operator.mul = 掛け算を行う関数"""
    """引数の２つ目は先頭を示す"""
    up = reduce(op.mul,range(n,n-r,-1),1)
    down= reduce(op.mul,range(r,0,-1),1)
    return up // down

def main():
    n = int(sys.stdin.readline().rstrip())
    
    sorted_letters =[''.join(sorted(sys.stdin.readline().rstrip())) for _ in range(n)]

    count = 0
    for c in collections.Counter(sorted_letters).values():
        if c >=2:
            count +=nCr(c,2)
        
    
    print(count)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 20028
from collections import deque
INF = -1
H,W = map(int,input().split())
Ch,Cw = map(int,input().split())
Ch -= 1
Cw -= 1
Dh,Dw = map(int,input().split())
Dh -= 1
Dw -= 1
S = []
for i in range(H):
    S.append(list(input()))
ans = [[INF] * W for _ in range(H)]
dx = (1,0,-1,0)
dy = (0,1,0,-1)
que = deque([(Ch,Cw,0)])
while len(que) != 0:
    p = que.popleft()
    if ans[ p[0] ][ p[1] ] == INF:
        ans[p[0]][p[1]] = p[2]
        if p[0] == Dh and p[1] == Dw:
            break
        for i in range(4):
            h = p[0]+dx[i]
            w = p[1]+dy[i]
            if (0 <= h and H > h) and (0 <= w and W > w) and (S[h][w] != '#') and ans[h][w] == INF:
                que.appendleft((h,w,p[2]))
        for i in range(-2,3):
            for j in range(-2,3):
                h = p[0]+i
                w = p[1]+j
                if (0 <= h and H > h) and (0 <= w and W > w) and (S[h][w] != '#') and ans[h][w] == INF:
                    que.append((h,w,p[2]+1))
    #print(que)
#print(ans)
print(ans[Dh][Dw])


Measured memory_bytes: 237088
#include<bits/stdc++.h>
using namespace std;
const int maxm = 2e3+10;
struct self
{
    int x,y,nxt;
}s[maxm*2];
int fst[maxm];
int m,tn,n;
int k;
const int inf = 0x3f3f3f3f;

void add(int x,int y)
{
    n++;
    s[n].x=x;s[n].y=y;
    s[n].nxt=fst[x];fst[x]=n;
}
int down,up;
int hasdown[maxm];
int hasup[maxm];
int totup[maxm];
int totdown[maxm];
int dep[maxm];

void dfs(int u,int fa)
{
    hasup[u]=hasdown[u]=0;
    if(dep[u]==up)hasup[u]=1;
    if(dep[u]==down)hasdown[u]=1;

    if(dep[u]<=up)totup[u]=1;
    if(dep[u]<=down)totdown[u]=1;

    if(dep[u]==up)
        return;
    
    for(int e=fst[u];e!=-1;e=s[e].nxt)
    {
        int v=s[e].y;
        if(v!=fa)
        {
            dep[v]=dep[u]+1;
            dfs(v,u);
            totup[u]+=totup[v];
            totdown[u]+=totdown[v];
            hasup[u]+=hasup[v];
            hasdown[u]+=hasdown[v];
        }
    }
    //cout<<"u="<<u<<" "<<totup[u]<<" "<<totdown[u]<<" "<<hasup[u]<<" "<<hasdown[u]<<endl;
}

int calc(int root)            
{
    int tot = totdown[root];
    int maxc = 0;
    if(up!=down)
    {
        for(int e=fst[root];e!=-1;e=s[e].nxt)
        {
            int v=s[e].y;
            maxc=max(maxc,hasup[v]);
        }
        tot+=maxc;
    }
    return m-tot;
}

int x,y;

int main()
{
    scanf("%d%d",&m,&k);
    up=(k+1)/2;
    down=k/2;
    memset(fst,-1,sizeof(fst));
    for(int i=1;i<m;i++)
    {
        scanf("%d%d",&x,&y);
        add(x,y);
        add(y,x);
    }
    int ans = inf;
    for(int root = 1;root<=m;root++)
    {
        memset(totup,0,sizeof(totup));
        memset(totdown,0,sizeof(totdown));
        dep[root]=0;
        dfs(root,-1);
        ans=min(ans,calc(root));
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
  using ll=long long;
  ll N;
  cin >> N;
  ll min=N-1;

  for(ll i=1;i<=sqrt(N);i++){
    if (N%i==0){
      ll min0=i+(N/i)-2;
      if (min0<min)
        min=min0;
    }
  }
  cout << min << endl;
  
}

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


int main()
{
    long long int a, b, m, n, ans;
    cin >> a >> b;

    m = max(a, b);
    n = min(a, b);
    if((m-n)%2)
    {
        cout << "IMPOSSIBLE\n";
        return 0;
    }
    ans = (m-n)/2;
    cout << m-ans << endl;
    return 0;
}


Measured memory_bytes: 256
D,G = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(D)]

ans = 0

for i in range(2**D):
    point = 0
    count = 0

    for j in range(D):
        if(i>>j)&1: # コンプリート
            point += X[j][0]*(j+1)*100 + X[j][1]
            count += X[j][0]
    
    if G > point:
        for k in range(D-1,-1,-1):
            if(i>>k)&1 == 0:
                if (G - point) <= X[k][0]*(k+1)*100:
                    count += (G - point - 1) // ((k+1)*100)  + 1
                    break
                else:
                    count = 10**5 # とりあえず大きい数
                    break
    
    if ans == 0 or count < ans:
        ans = count

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
 
#define MAX 25
 
typedef struct{
  int p, s, deg, dep, h, left, right;
}Node;
 

int depth(Node *T, int i){
 
  if(T[i].p == -1) return 0;
 
  return depth(T, T[i].p) + 1;
   
}


int height(Node *T, int i){
  int righth = 0, lefth = 0;
 
  if(T[i].right != -1) 
    righth = height(T, T[i].right) + 1;
 
  if(T[i].left != -1) 
    lefth = height(T, T[i].left) + 1;
 
  if(righth >= lefth) 
    return righth;
  else 
    return lefth;
}


void Preorder(Node *T, int i){
  if(i == -1)
    return;

  printf(" %d",i);
 
  Preorder(T, T[i].left);
   
  Preorder(T, T[i].right);
 
}


void Inorder(Node *T, int i){
  if(i == -1) 
    return;
 
  Inorder(T, T[i].left);
  printf(" %d",i);
 
  Inorder(T, T[i].right);
}


void Postorder(Node *T, int i){
  if(i == -1) 
    return;
 
  Postorder(T, T[i].left);
   
  Postorder(T, T[i].right);
  printf(" %d",i);
}

 
int main(){
  int i, n, id, r;
  Node T[MAX], tmp;
 
  scanf("%d",&n);

  for(i = 0; i < n; i++){
    T[i].p = -1;
    T[i].dep = 0;
    T[i].deg = 0;
    T[i].s = -1;
  }

  for(i = 0; i < n; i++){
    scanf("%d",&id);
    scanf("%d%d", &T[id].left, &T[id].right);
    T[T[id].left].p = id;
    T[T[id].right].p = id;
    if(T[id].left != -1){
      T[id].deg++;
      T[T[id].left].s = T[id].right;
    }
     if(T[id].right != -1){
      T[id].deg++;
      T[T[id].right].s = T[id].left;
    }
  }
 
  for(i = 0; i < n; i++){
    T[i].dep = depth(T, i);
    if(T[i].dep == 0) r = i;
    T[i].h = height(T, i);
  }
   
  printf("Preorder\n");
  Preorder(T, r);
  
  printf("\nInorder\n");
  Inorder(T, r);
  
  printf("\nPostorder\n");
  Postorder(T, r);
  printf("\n");
 
  return 0;
}
 
 
 
 
 

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

int main(){
    cin.sync_with_stdio(false);
    
    const static int MOD = (int)1e9+7;
    int n, m; cin >> n >> m;
    vector<string>grid(n);
    vector<vector<int>>dp(n, vector<int>(m,0));

    for(int i = 0; i < n; i++){
        cin>>grid[i];
    }

    dp[n-1][m-1] = 1;
    for(int i = n-2; i >= 0; i--){
        if(grid[i][m-1] == '.'){
            dp[i][m-1] = dp[i+1][m-1];
        }
    }

    for(int i = m-2; i >= 0; i--){
        if(grid[n-1][i] == '.'){
            dp[n-1][i] = dp[n-1][i+1];
        }
    }

    for(int i = n-2; i >= 0; i--){
        for(int j = m-2; j >= 0; j--){
            if(grid[i][j] == '.'){
                dp[i][j] = (dp[i+1][j]+dp[i][j+1])%MOD;
            }
        }
    }

    cout<<dp[0][0]<<endl;
}


Measured memory_bytes: 8544
package main

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

var sc = bufio.NewScanner(os.Stdin)

// 一行読み出し
func nextLine() string {
	sc.Scan()
	return sc.Text()
}

// 文字列リバース関数
func strReverse(s string) string {
	rs := []rune(s)
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		rs[i], rs[j] = rs[j], rs[i]
	}
	return string(rs)
}

// スペース区切りの文字列から int のスライスを得る
func intSlice(s string) []int {
	ss := strings.Split(s, " ")
	res := make([]int, len(ss))
	for i, v := range ss {
		iv, _ := strconv.Atoi(v)
		res[i] = iv
	}

	return res
}

func main() {

	var n int
	fmt.Scan(&n)
	s := nextLine()

	ns := intSlice(s)

	ans := 0
	for i := 0; i < n-2; i++ {
		if ns[i+1] > ns[i] && ns[i+1] < ns[i+2] {
			ans++
		} else if ns[i+1] < ns[i] && ns[i+1] > ns[i+2] {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
a,b = map(int,input().split())
ans_1 = 0
ans_2 = 0
for i in range(a):
    ans_1 += (10 ** i) * b
for j in range(b):
    ans_2 += (10 ** j) * a
if b <= a:
    print(ans_1)

else:
    print(ans_2)

Measured memory_bytes: 3060