akhauriyash/Code-Regression huggingface dataset:
def main():  
  N, Y = map(int,input().split())
  Cash = [10000, 5000, 1000]
  for x in range(N+1):
    for y in range(N+1):
      Rem = Y - (10000*x + 5000*y)
      Rem = Rem//1000
      if Rem == (N - x - y) and Rem >=0:
        print(x, y, Rem)
        return 
  print(-1, -1, -1)
  return

main()

Measured memory_bytes: 9120
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < S.length(); i++) {
            ans.append((char)('A'+(S.charAt(i)-'A'+N)%26));
        }
        System.out.println(ans.toString());
    }
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define re return
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
const int dx[4]={-1,1,0,0};
const int dy[4]={0,0,-1,1};
int a[55],b[55],c[55],d[55];
int n,m,q;
int ans;
vector<int>v;
int val(vector<int>v){
	int x=0;
	for (int i=0;i<q;i++){
		if (v[b[i]]-v[a[i]]==c[i]){
			x+=d[i];
		}
	}
	re x;
}
void dfs(int dep){
	if (!dep){
		for (int i=1;i<=m;i++){
			v.pb(i);
			dfs(1);
			v.erase(v.end()-1);
		}
	}
	else if (dep==n){
		ans=max(ans,val(v));
	}
	else {
		for (int i=v[dep-1];i<=m;i++){
			v.pb(i);
			dfs(dep+1);
			v.erase(v.end()-1);
		}
	}
}
signed main()
{
	cin>>n>>m>>q;
	for (int i=0;i<q;i++){
		cin>>a[i]>>b[i]>>c[i]>>d[i];
		a[i]--, b[i]--;
	}
	dfs(0);
	cout<<ans;
	re 0;
}
/*
3 4 3
1 3 3 100
1 2 2 10
2 3 2 10
*/
/*
4 6 10
2 4 1 86568
1 4 0 90629
2 3 0 90310
3 4 1 29211
3 4 3 78537
3 4 2 8580
1 2 1 96263
1 4 2 2156
1 2 0 94325
1 4 3 94328
*/

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define For1(i, n) for(int i = 1; i <= (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    Cins(int, n, q);
    vc<int> p(n);
    For(i, n) p[q[i]-1] = i;
    
    vc<int> c(n-1);
    For(i, n-1) c[i] = 1 + max(p[i+1] - p[i], 0);
    Cusum(int, c, a);
    For(i, n) cout << a[i]+1 << " ";
    cout << endl;
    For(i, n) cout << p[i]-a[i] - (p[n-1]-a[n-1]-1) << " ";
    cout << endl;

}




Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<int, int>
int N, L, arr[100005];
int mx = 0, idx = 0;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> N >> L;
    for (int i = 1; i <= N; i++) {
        cin >> arr[i];
    }
    for (int i = 1; i < N; i++) {
        int amt = arr[i] + arr[i + 1];
        if (amt > mx) {
            mx = amt;
            idx = i;
        }
    }
    if (mx < L) {
        cout << "Impossible" << endl;
        return 0;
    }
    vector<int> v = {idx};
    for (int i = idx + 1; i < N; i++) v.push_back(i);
    for (int i = idx - 1; i >= 1; i--) v.push_back(i);
    reverse(v.begin(), v.end());
    cout << "Possible" << endl;
    for (int i = 0; i < (int)v.size(); i++) {
        cout << v[i] << endl;
    }

    return 0;
}


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

int main(int argc, char const *argv[])
{
    int H, W;
    std::vector<int> vector_H, vector_W;

    while (1)
    {
        std::cin >> H >> W;
        if (H == 0 && W == 0)
        {
            break;
        }
        else
        {
            vector_H.emplace_back(H);
            vector_W.emplace_back(W);
        }
    }

    for (int i = 0; i < vector_H.size(); i++)
    {
        for (int j = 0; j < vector_H[i]; j++)
        {
            for (int k = 0; k < vector_W[i]; k++)
            {
                std::cout << "#";
            }
            std::cout << std::endl;
        }
        std::cout << std::endl;
    }

    return 0;
}



Measured memory_bytes: 3164
#include "bits/stdc++.h"

using namespace std;
bool ismonth(int n){
    if(n==0){
        return false;
    }
    if(n>12){
        return false;
    }
    return true;
}
int main(){
    int s;
    
    cin>>s;

    string ans;
    int mae = s/100;
    int ushiro = s%100;
    if(ismonth(mae)){
        if(ismonth(ushiro)){
            ans = "AMBIGUOUS";
        }else{
            ans = "MMYY";
        }
    }else{
        if(ismonth(ushiro)){
            ans = "YYMM";
        }else{
            ans = "NA";
        }

    }
    cout << ans <<endl;
    return(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	string s;
	cin >> N;
	cin >> s;
	int l=0,r=0;
	int tmpr = 0,tmpl=0;int mxr=0,mxl=0;
	for(int i=0;i<N;++i){
		if(s[i]==')') ++tmpr;
		else --tmpr;
		mxr = max(mxr,tmpr);
	}
	for(int i=N-1;i>=0;--i){
		if(s[i]=='(') ++tmpl;
		else --tmpl;
		mxl = max(mxl,tmpl);
	}
	string a=string(mxr,'(');
	string b=string(mxl,')');
	cout << a+s+b << endl;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
--import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Fixed
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import Text.Printf
import System.IO
-- import System.IO.Unsafe
 
-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
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
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
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)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
whenM :: Monad m => m Bool -> m () -> m ()
whenM c a = c >>= flip when a
unconsU :: [a] -> (a, [a])
unconsU (x:xs) = (x, xs)
-- templete


main = do
    s <- getLine
    unless (s=="END OF INPUT") $ do
        putStrLn $ map intToDigit $ map length $ linesBy (==' ') s
        main


Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;


// DMC
int a[100], rui[2000000][3], dp[2000000], ans[100];
signed main(){
  int n, q;
  string str;
  cin >> n >> str >> q;
  rep(i,q)scanf("%lld", &a[i]);
  str = " " + str;
  rrep(i,n){
    if(str[i] == 'D')rui[i][0]++;
    if(str[i] == 'M')rui[i][1]++;
    if(str[i] == 'C')rui[i][2]++;
    rep(j,3)rui[i][j] += rui[i-1][j];
  }

  int C = 0;
  drep(i,n,1){
    dp[i] += dp[i+1];
    if(str[i] == 'C'){
      C++;continue;
    }else if(str[i] == 'M'){
      dp[i] += C;
    }
  }

  // rrep(i,n)printf("%2c", str[i]);
  // printf("\n");
  rep(ddd,q){
    int d = a[ddd]-1;
    int cnt1 = 0, cnt2 = 0;
    rrep(i,n){
      int r = i, l = max(1LL, r-d);
      if(str[i] == 'C'){ans[ddd] += cnt2;}
      // printf("%2lld", cnt2);
      if(str[i] == 'D')cnt1++;
      if(str[i] == 'M')cnt2 += cnt1;
      if(1 <= i-d and str[i-d] == 'D'){
        cnt2 -= rui[r][1]-rui[l-1][1];
        cnt1--;
      }
    }
    // printf("\n");
  }
  // rrep(i,n)printf("%lld", dp[i]);
  // printf("\n");
  rep(i,q){
    printf("%lld\n", ans[i]);
  }
  return 0;
}

Measured memory_bytes: 36144
from sys import stdin
import math
import re
import queue

input = stdin.readline

MOD = 1000000007
INF = 122337203685477580

def solve():
    H,W = map(int, input().split())
    vv = []
    for i in range(H):
        vv.append(list(input().split()))

    for i in range(H):
        for j in range(W):
            if(vv[i][j] == "snuke"):
                print(chr(ord('A') + j),i+1,sep="")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 4080
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    string s;
    cin >> s;
    int x, y;
    cin >> x >> y;
    vi h, v; // horizontal, vertical
    int curr = 0;
    bool ish = true;
    int init = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'F') {
            init++;
            x--;
        } else {
            break;
        }
    }
    for (int i = init; i < s.size(); ++i) {
        if (s[i] == 'F') {
            curr++;
        } else {
            if (ish)
                h.push_back(curr);
            else
                v.push_back(curr);
            curr = 0;
            ish  = !ish;
        }
    }
    if (ish)
        h.push_back(curr);
    else
        v.push_back(curr);
    int shift = 8000;
    vvi dp(h.size() + 1, vi(2 * shift + 1, 0));
    dp[0][shift] = 1;
    for (int i = 1; i <= h.size(); ++i) {
        for (int j = 0; j < 2 * shift; ++j) {
            if (j - h[i - 1] >= 0)
                chmax(dp[i][j], dp[i - 1][j - h[i - 1]]);
            if (j + h[i - 1] < 2 * shift + 1)
                chmax(dp[i][j], dp[i - 1][j + h[i - 1]]);
        }
    }
    vvi dpv(v.size() + 1, vi(2 * shift + 1, 0));
    dpv[0][shift] = 1;
    for (int i = 1; i <= v.size(); ++i) {
        for (int j = 0; j < 2 * shift; ++j) {
            if (j - v[i - 1] >= 0)
                chmax(dpv[i][j], dpv[i - 1][j - v[i - 1]]);
            if (j + v[i - 1] < 2 * shift + 1)
                chmax(dpv[i][j], dpv[i - 1][j + v[i - 1]]);
        }
    }
    if (dp[h.size()][x + shift] == 1 && dpv[v.size()][y + shift] == 1)
        cout << "Yes"
             << "\n";
    else
        cout << "No"
             << "\n";
    return 0;
}

Measured memory_bytes: 496768
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
INF = 10**12
import bisect

n, m, k = map(int, input().split())
a = [int(item) for item in input().split()]
b = [int(item) for item in input().split()]

acum = [0]
for item in a:
    acum.append(acum[-1] + item)
bcum = [0]
for item in b:
    bcum.append(bcum[-1] + item)

ans = 0
for i, item in enumerate(acum):
    if item > k:
        continue
    index = bisect.bisect_right(bcum, k - item) - 1
    num = i + index
    ans = max(ans, num)
print(ans)

Measured memory_bytes: 133344
//Code by: A Gokul Karthik
#include<bits/stdc++.h>

#define ll long long int
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define fast std::ios_base::sync_with_stdio(false)
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define clr1(arr) memset(arr,-1,sizeof(arr));
#define clr0(arr) memset(arr,0,sizeof(arr));
#define RANGE 255
#define po(a) if(a<0){a*=-1;}

using namespace std;

void swap(int *xp, int *yp)
{
    int temp = *xp;
    *xp = *yp;
    *yp = temp;
}

void bubbleSort(int arr[], int n)
{
    int i, j;
    for (i = 0; i < n-1; i++)
    for (j = 0; j < n-i-1; j++)
        if (arr[j] > arr[j+1])
            swap(&arr[j], &arr[j+1]);
}


int solve()
{
   int x;
   cin>>x;
  if(x==0)
   {
           cout<<1<<"\n";
   }
   if(x==1)
   {
           cout<<0<<"\n";
   }
  return 0;
}

int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
     int t;
     t=1;
     for(int i=0;i<t;i++)
     {
         solve();
     }

}




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

typedef long long ll;

ll a[100010];

int main() {
	// your code goes here
	ll n, i, j, ans=0;
	cin>>n;
	for(i=1; i<=n; ++i) {
		cin>>j;
		if(j!=0) {
			if(j%2) {
				ans+=(j-1LL)/2LL;
				a[i]=1;
			}
			else {
				ans+=(j-2LL)/2LL;
				a[i]=2;
			}
		}
	}
	//cout<<ans<<endl;
	for(i=1; i<=n-1; ++i) {
		if(a[i]==2 && a[i+1]==2) {
			ans+=2LL;
			a[i]=a[i+1]=0;
		}
		else if(a[i]==2 && a[i+1]==1) {
			a[i]=0;
			ans++;
		}
		else if(a[i]==1 && a[i+1]==1) {
			a[i]=a[i+1]=0;
			ans++;
		}
		else if(a[i]==2 && a[i+1]==0) {
			a[i]=0;
			ans++;
		}
		else if(a[i]==1 && a[i+1]==2) {
			a[i]=0;
			a[i+1]=1;
			ans++;
		}
	}
	//cout<<ans<<endl;
	if(a[n]!=0 && a[n]==2)
		ans++;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
vector<int> tobit(ll n, int keta) {
    vector<int> res(keta, 0);
    for(int i = 0; i < keta; i++) {
        res[i] = n % 2;
        n /= 2;
    }
    return res;
}
int sum(vector<vector<char>> &c) {
    int res = 0;
    for(int i = 0; i < c.size(); i++) {
        for(int j = 0; j < c[0].size(); j++) {
            res += (c[i][j] == '#');
        }
    }
    return res;
}
int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<char>> c(h, vector<char>(w));
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            cin >> c[i][j];
        }
    }
    vector<vector<int>> tan1, tan2;
    for(int i = 0; i < (1 << h); i++) {
        tan1.push_back(tobit(i, h));
    }
    for(int i = 0; i < (1 << w); i++) {
        tan2.push_back(tobit(i, w));
    }
    int m1 = tan1.size();
    int m2 = tan2.size();
    int ans = 0;
    for(int i = 0; i < m1; i++) {
        for(int j = 0; j < m2; j++) {
            auto tmp = c;
            for(int x = 0; x < h; x++) {
                for(int y = 0; y < w; y++) {
                    if(tan1[i][x] || tan2[j][y]) {
                        tmp[x][y] = 'r';
                    }
                }
            }
            if(sum(tmp) == k) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
/*{{{*/
#include<bits/stdc++.h>

typedef long long ll;

#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define FORR(i,a,b) for(ll i=b-1;i>=a;i--)

#define vl vector<ll>
#define pll pair<ll,ll>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;
/*}}}*/

int main() {
  ll n;
  cin >> n;
  ll ans = n * (n+1) * (n+2) / 6;
  REP(i,n-1){
    ll u,v;
    cin >> u >> v;
    if(u>v) swap(u,v);
    ans -= u * (n-v+1);
  }
  cout << ans << endl;
  return 0;
}


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

const ll INF = 1LL << 60;

struct Parser{
	string s;
	int N;
	int c;

	ll parse(string s){
		this->s = s;
		N = s.size();
		c = 0;
		try{
			ll ret = or_term();
			if(c != N) throw "";
			return ret;
		}
		catch(...){
			//cout << s << endl;
			return INF;
		}
	}

	void debug(string text){
		return;
		cout << text + " ";
		for(int i = 0; i < N; i++){
			if(i == c) cout << '[' << s[i] << ']';
			else cout << s[i];
		}
		cout << endl;
	}

	ll or_term(){
		debug("or_term");
		ll x = xor_term();
		while(c < N){
			if(s[c] == '|'){
				c++;
				x |= xor_term();
			}
			else break;
		}
		return x;
	}

	ll xor_term(){
		debug("xor_term");
		ll x = and_term();
		while(c < N){
			if(s[c] == '^'){
				c++;
				x ^= and_term();
			}
			else break;
		}
		return x;
	}

	ll and_term(){
		debug("and_term");
		ll x = expr();
		while(c < N){
			if(s[c] == '&'){
				c++;
				x &= expr();
			}
			else break;
		}
		return x;
	}

	ll expr(){
		debug("expr");
		ll x = term();
		while(c < N){
			if(s[c] == '+'){
				c++;
				x += term();
			}
			else if(s[c] == '-'){
				c++;
				x -= term();
			}
			else break;
		}
		return x;
	}

	ll term(){
		debug("term");
		ll x = factor();
		while(c < N){
			if(s[c] == '*'){
				c++;
				x *= factor();
			}
			else break;
		}
		return x;
	}

	ll factor(){
		debug("factor");
		if(s[c] == '('){
			c++;
			ll ret = or_term();
			if(s[c] != ')') throw "";
			//assert(s[c] == ')');
			c++;
			return ret;
		}
		return num();
	}

	ll num(){
		debug("num");
		if(s[c] == '0' || !isdigit(s[c])) throw "";
		ll ret = 0;
		while(c < N && isdigit(s[c])){
			ret = ret * 10 + s[c] - '0';
			c++;
		}
		return ret;
	}
};

int M;
Parser p;

ll f(string t, int turn, int n){
	if(n == M){
		return p.parse(t);
	}

	ll ret = turn == 0 ? -1e18 : 1e18;
	string cs = "0123456789*+-|^&";
	for(int i = 0; i < t.size() + 1; i++){
		for(auto c : cs){
			string tt = t;
			tt.insert(tt.begin() + i, c);
			ll res = f(tt, 1 - turn, n + 1);
			if(p.parse(tt) == INF) continue;
			if(turn == 0){
				//cout << tt << " " << res << endl;
				ret = max(ret, res);
			}
			else{
				ret = min(ret, res);
			}
		}
	}
	if(t.size() >= 2){
		for(int i = 0; i < t.size(); i++){
			string tt = t;
			tt.erase(tt.begin() + i);
			ll res = f(tt, 1 - turn, n + 1);
			if(p.parse(tt) == INF) continue;
			if(turn == 0){
				//cout << tt << " " << res << endl;
				ret = max(ret, res);
			}
			else{
				ret = min(ret, res);
			}
		}
	}
	return ret;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	string t;
	while(cin >> M >> t, M){
		M = M % 2 ? 1 : 2;
		cout << f(t, 0, 0) << endl;
	}
}

Measured memory_bytes: 3292
# -*- coding: utf-8 -*-
import sys
import itertools#これは色々使える組み込み関数みたいなやつ
#import math#数学的計算はこれでいける。普通に0.5乗しても計算可能
#w=input()
#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)
i=0
#N=int(input())
A, B=input().split()
A=int(A)
B=int(B)
print(lcm(A, B))


Measured memory_bytes: 3060
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

ans = gcd(A[0], A[1])

for i in range(2, N):
	ans = gcd(ans, A[i])

print(ans)

Measured memory_bytes: 16316
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;
#define ll long long
#define cpp mp::cpp_int
#define dequeue deque
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
struct edge {
	int to;
	ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << setprecision(20);
}
void reverse(string* s) {
	reverse((*s).begin(), (*s).end());
}
int main() {
	COME_LET_THE_GAMES_BEGIN();
	int N;
	int W[110];
	cin >> N;
	rep(i, N)cin >> W[i];
	ll ans = LLONG_MAX;
	rep(i, N) {
		int S1 = 0, S2 = 0;
		rep(j, N) {
			if (j <= i)S1 += W[j];
			else S2 += W[j];
		}
		ans = min(ans, (ll)abs(S1 - S2));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fr(i,a) for(int i=0;i<a;i++)
#define sup ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MX 100007
#define UI unsigned int
#define LL long long int

template<class M> M mod(M b,M c)
{
    return max(b,c)-min(b,c);
}
   
int dp[MX];
int FGI(int h[],int n)
{
    if(dp[n]!=-1)
        return dp[n];
    else if((n==1)||(n==2))
    {
        dp[n]= mod(h[n],h[0]);
        return dp[n];
    }
    else
    {
        dp[n]= min(FGI(h,n-1)+mod(h[n],h[n-1]),FGI(h,n-2)+mod(h[n],h[n-2]));
        return dp[n];
    }
}


int main()
{
    sup;
    int n;
    cin>>n;
    int h[n];
    fr(i,n)
    {
        cin>>h[i];
    }
    memset(dp,-1,sizeof(dp));
    cout<<FGI(h,n-1);
}



Measured memory_bytes: 4224
n,m = map(int,input().split())
a = list(map(int, input().split()))
x = sum(a) / (4 * m)
c = 0
for i in range(n):
  if a[i] >= x:
    c += 1
  if c >= m:
    print('Yes')
    break
if c < m:
  print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

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

	auto start = -1;
	auto end = -1;
	for (auto i = 0; i < (int)s.size() - 1; ++i)
	{
		if (s[i] == s[i + 1])
		{
			start = i + 1;
			end = i + 2;
			break;
		}
		if (i < (int)s.size() - 2)
		{
			if (s[i] == s[i + 2])
			{
				start = i + 1;
				end = i + 3;
				break;
			}
		}
	}

	cout << start << " " << end << endl;

	return 0;
}

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

long long _pow(int n, int m)
{
	long long ret = 1;
	for (int i = 0; i < m; i++)
		ret *= n;
	return ret;
}

using namespace std;
int main()
{
	int n, p;
	cin >> n >> p;
	map<int, int> m;
	for (int i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		m[a % 2]++;
	}
	if (m[1] == 0 && p == 1)
		cout << 0 << endl;
	else if (m[1] == 0)
		cout << _pow(2, n) << endl;
	else
		cout << _pow(2, n - 1) << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int,int>
#define mod 1000000007
#define endl "\n"

int power(int a,int b,int m=mod)
{
	if(b==0)	return 1;
	if(b==1)	return a;
	int res=power(a,b/2,m);
	res=(res*res)%m;
	if(b&1)	res=(res*a)%m;
	return res;
}

int modinv(int a){ return power(a,mod-2);}

void solve()
{
	int n,m;
	cin>>n>>m;
	int a[n],i,sum=0,cnt=0;
	for(i=0;i<n;i++){
		cin>>a[i];sum+=a[i];
	}
	sort(a,a+n);
	int val=(sum+4*m-1)/(4*m);
	for(i=n-1;i>=0;i--)
		if(a[i]>=val)	cnt++;
	if(cnt>=m)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int t=1;//cin>>t;
	while(t--)	solve();
	return 0;
}

Measured memory_bytes: 256
def merge(A,left,mid,right):
    L=A[left:mid]+[float("INF")]
    R=A[mid:right+1]+[float("INF")]
    i=0
    j=0
    global cnt
    for k in range(left,right+1):
        if L[i]<=R[j]:
            A[k]=L[i]
            i+=1
            cnt+=1
        else:
            A[k]=R[j]
            j+=1
            cnt+=1
def mergeSort(A,left,right):
    if left<right:
        mid=(left+right)//2+1
        mergeSort(A,left,mid-1)
        mergeSort(A,mid,right)
        merge(A,left,mid,right)
n=int(input())
S=list(map(int,input().split()))
cnt=0
mergeSort(S,0,n-1)
print(*S)
print(cnt)


Measured memory_bytes: 61648
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

int main(){
  int n, d, x;
  cin>>n>>d>>x;

  int a[n];
  REP(i,n) cin>>a[i];

  int ans = x;

  REP(i,n) {
    ans += (d - 1) / a[i] + 1;
  }

  cout<<ans<<endl;

  return 0;
}


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

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

//-----------
function main(lines){
	const tpl = lines[0].split(" ");
	const a = Number(tpl[0]);
	const b = Number(tpl[1]);
	log(a*b + " " + 2*(a+b));
}

Measured memory_bytes: 15444
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    string S;
    cin >> N >> S;
    int ret = 0;
    char prev = 'A';
    for (char c : S)
        if (c != prev) {
            ret++;
            prev = c;
        }

    cout << ret << endl;
    return 0;
};


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(){
	int n, m;
	string s;
	cin >> n >> m >> s;
	reverse(s.begin(), s.end());
	int now = 0;
	vector<int> vec;
	while(1){
		int temp = now;
		for (int i = m; i >= 1; i--){
			if (now+i <= n && s[now+i] == '0'){
				now += i;
				vec.push_back(i);
				if (now == n){
					for (int j = vec.size()-1; j >= 0; j--){
						cout << vec[j] << " ";
					}
					cout << endl;
					return 0;
				}
				break;
			}
		}
		if (temp == now) break;
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 1144
($a,$b,$c,$d,$e,$f)=glob<>;$_="$a 0";sub f{my($x,$y)=@_;$_="@_"if(${"@_"}//=$x*100+$y<=$f&$x*$e>=$y&&(f($x+$a,$y),f($x+$b,$y),f($x,$y+$c),f($x,$y+$d),$y/$x))>$$_}f$a,0;f$b,0;/ /;print$`*100+$',$",$'

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

int main() {
  int N, H;
  std::cin >> N >> H;

  std::vector<int> A(N), B(N);

  for (int i = 0; i < N; i++) {
    std::cin >> A[i] >> B[i];
  }

  std::sort(A.begin(), A.end(), std::greater<int>());
  std::sort(B.begin(), B.end(), std::greater<int>());

  int h = 0, times = 0;



  for (auto b : B) {
    if (b > A[0]) {
      h += b;
      times++;

      if (h >= H) {
        break;
      }
    }
  }

  if (h < H) {
    times += (H - h + A[0] - 1) / A[0];
  }

  std::cout << times << std::endl;
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int kotae(int,int,int,int);

int main(){
    int A,B,C,K,ans=0,max=-1;

    cin>>A>>B>>C>>K;

    max=A;

    if(C<=A && B<=A){
        for(int lop =0 ;lop<K ; lop++){
            A*=2;
        }
    }else if(A<=B && C<=B){
        for(int lop =0 ;lop<K ; lop++){
            B*=2;
        }
    }else{
        for(int lop =0 ;lop<K ; lop++){
            C*=2;
        }
    }


    cout<<A+B+C<<endl;
    return 0;
}

Measured memory_bytes: 256
def ii():
    return int(input())
def mi():
    return map(int, input().split())
def li():
    return list(mi())

l = li()
x, k, d = l[0], l[1], l[2]
x = abs(x)
calc = x // d
mi = min(k, calc)
k -= mi
x -= mi * d

if k % 2 == 0:
	print(x)
else:
	print(abs(x-d))

Measured memory_bytes: 9080
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;
using ll = long long int;

ll A, B, C;
ll a, b, c;
ll ret = 0;

bool check() {
	bool flag = true;
	if (a == A && b == B && c == C && ret > 0) {
		ret = -1;
		flag = false;
	}
	else if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1)
		flag = false;
	return flag;
}

int main(void) {
	cin >> A >> B >> C;
	a = A; b = B; c = C;
	while (check()) {
		ll atmp = a, btmp = b, ctmp = c;
		a = (btmp + ctmp) / 2;
		b = (ctmp + atmp) / 2;
		c = (atmp + btmp) / 2;
		ret++;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 10000000000000000
#define endl '\n'
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; }
using namespace std;

bool X[16001],Y[16001];
bool tmp2[16001];

signed main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s; cin>>s;
    int x,y; cin>>x>>y;
    s+='T'; X[x+8000]=Y[y+8000]=true;
    
    int cnt=0,che=0;
    vector<int> xc,yc;
    rep(i,s.size()){
        if(s.at(i)=='T'){
            if(cnt>0){
                if(che%2==0)xc.push_back(cnt);
                else yc.push_back(cnt);
            }
            cnt=0; che++;
        }else cnt++;
    }
    reverse(all(xc));
    reverse(all(yc));
    
    if(xc.size()==0)goto heaven;
    rep(i,xc.size()-1){
        bool tmp[16001]={false};
        rep(j,16001){
            if(X[j]){
                if(j+xc.at(i)<=16000)tmp[j+xc.at(i)]=true;
                if(j-xc.at(i)>=0)tmp[j-xc.at(i)]=true;
            }
        }
        rep(j,16001)X[j]=tmp[j];
    }
    rep(j,16001){
        if(X[j]){
            if(j-xc.back()>=0)tmp2[j-xc.back()]=true;
            if(s.front()=='T')if(j+xc.back()<=16000)tmp2[j+xc.back()]=true;
        }
    }
    rep(i,16001)X[i]=tmp2[i];
    
heaven:
    if(yc.size()==0)goto hell;
    rep(i,yc.size()){
        bool tmp[16001]={false};
        rep(j,16001){
            if(Y[j]){
                if(j+yc.at(i)<=16000)tmp[j+yc.at(i)]=true;
                if(j-yc.at(i)>=0)tmp[j-yc.at(i)]=true;
            }
        }
        rep(j,16001)Y[j]=tmp[j];
    }
    
hell:
    cout<<(X[8000] and Y[8000] ? "Yes":"No")<<endl;
}

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

int main(){
    int x,n;
    cin >> x >> n;
    set<int> s;
    rep(i,n){
        int a; cin >> a;
        s.insert(a);
    }
    int dx=0;
    while(1){
        if(!(s.count(x-dx))){
            cout << x-dx << endl;
            break;
        }
        if(!(s.count(x+dx))){
            cout << x+dx << endl;
            break;
        }
        dx++;
    }
}

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

#define FOR(i, j, k) for (int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {

  int N;

  cin >> N;

  vi primes;
  FOR(i, 2, 101) {

    bool isfound = false;
    for (auto p : primes) {
      if (i % p == 0) {
        isfound = true;
        break;
      }
    }

    if (!isfound)
      primes.push_back(i);
  }

  map<int, int> m;
  FOR(i, 2, N + 1) {
    int j = i;
    for (auto p : primes) {
      while (j > 1 and j % p == 0) {
        m[p]++;
        j /= p;
      }
    }
  }

  vi v2, v4, v14, v24, v74;
  for (auto p : m) {

    //    cout << p.first << " " << p.second << endl;

    if (p.second >= 2)
      v2.push_back(p.first);
    if (p.second >= 4)
      v4.push_back(p.first);
    if (p.second >= 14)
      v14.push_back(p.first);
    if (p.second >= 24)
      v24.push_back(p.first);
    if (p.second >= 74)
      v74.push_back(p.first);
  }

  int ans = 0;
  for (auto a : v2) {

    //   cout << "v2 : " << a << endl;
    int b = v4.size();
    for (auto c : v4) {
      if (a == c) {
        b--;
        break;
      }
    }

    //    cout << "v4 : ";
    //    for (auto c : v4) {
    //      cout << c << " ";
    //    }
    //    cout << endl;
    //
    //    cout << " add " << b * (b - 1) / 2 << endl;

    ans += b * (b - 1) / 2;
  }

  ans += v14.size() * (v4.size() - 1);
  ans += v24.size() * (v2.size() - 1);
  ans += v74.size();

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
N,M,X,Y = map(int, input().split())
xar = list(map(int, input().split()))
yar = list(map(int, input().split()))

if max(xar) >= min(yar):
    print('War')
    exit()


for i in range(max(xar)+1,min(yar)+1):
    if i > X and i <= Y:
        print('No War')
        exit()
else:
    print('War')





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

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C& _a4, C _b4) { _a4 = min(_a4, _b4); }
template<class C> void maxi(C& _a4, C _b4) { _a4 = max(_a4, _b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream& operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto& vv : V) os << vv << ","; os << "]";
  return os;
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int MAX = 310;
int n,m;
string z[MAX];
int dp[MAX][MAX];
int pom[MAX*2][MAX*2];
int licz(string a,string b){
  //reverse(ALL(a));
  //reverse(ALL(b));
  R(i,MAX*2)R(j,MAX*2)pom[i][j] = 0;
  R(i,n)R(j,n){
    if(a[i] == b[j]){
      pom[i - j + MAX][j + i + 2] ++;
    }
  }
  R(i,MAX*2)R(j,2*MAX-1)pom[i][j+1] += pom[i][j];
  
  R(i,n+1)R(j,n+1){
    if(i == 0 || j == 0)
      dp[i][j] = 0;
    dp[i][j] = pom[i - j + MAX][i+j] + min(dp[i-1][j], dp[i][j-1]);
  }
  debug(a,b,dp[n][n]);
  return dp[n][n];
}

int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n >> m;
  R(i,n){
    cin >> z[i];
  }
  
  int res = 0;
  R(i,m-1){
    string a,b;
    R(j,n){
      a += z[j][i];
      b += z[j][i+1];
    }
    res += licz(a,b);
  }
  
  cout << res << "\n";
}


Measured memory_bytes: 4096
a,b,c,d=input()
for i in range(2**3):
    l=["-","-","-"]
    for j in range(3):
        if (i>>j&1):
            l[j]="+"
    if eval(a+l[0]+b+l[1]+c+l[2]+d)==7:
        print(a+l[0]+b+l[1]+c+l[2]+d+"=7")
        break

Measured memory_bytes: 9076
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

bool cmp(P a, P b) {
    if(a.se!=b.se) return a.se > b.se;
    else return a.fi < b.fi;
}

signed main() {
    int d, g;
    cin >> d >> g;
    vi p(d), c(d);
    rep(i, d) cin >> p[i] >> c[i];

    int res = 1e10;
    rep(i, 1<<d) {
        int temp = 0, a = 1;
        int cnt = 0;
        V(bool) done(d, false);
        rep(j, d) {
            if(i&a) {
                temp += 100*(j+1)*p[j] + c[j];
                cnt += p[j];
                done[j] = true;
            }
            a <<= 1;
        }
        rep(j, d) {
            if(!done[d-1-j]) {
                rep(k, p[d-1-j]) {
                    if(temp >= g) break;
                    temp += 100*(d-j);
                    cnt++;
                }
            }
        }
        if(temp >= g) res = min(res, cnt);
    }

    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 256
def main():
    aa = []
    for _ in xrange(3):
        aa.extend(map(int, raw_input().split()))
    n = input()
    for _ in xrange(n):
        b = input()
        try:
            aa[aa.index(b)] = 0
        except ValueError:
            continue
    for i in xrange(3):
        if sum(aa[i*3:i*3+3]) == 0:
            print 'Yes'
            return
        if sum(aa[i::3]) == 0:
            print 'Yes'
            return
    if sum(aa[::4]) == 0:
        print 'Yes'
        return
    if sum(aa[2:7:2]) == 0:
        print 'Yes'
        return
    print 'No'

main()


Measured memory_bytes: 27884
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;

const lld N = 200043;
const lld MOD = 1000000007;

lld add(lld x, lld y)
{
    x += y;
    while(x >= MOD) x -= MOD;
    while(x < 0) x += MOD;
    return x;
}

lld mul(lld x, lld y)
{
    return (x * 1ll * y) % MOD;
}

lld binpow(lld x, lld y)
{
    lld z = 1;
    while(y)
    {
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}

lld inv(lld x)
{
    return binpow(x, MOD - 2);
}

lld divide(lld x, lld y)
{
    return mul(x, inv(y));
}

// Combinations

/*
lld fact[N];

void precalc()
{
    fact[0] = 1;
    for(lld i = 1; i < N; i++)
        fact[i] = mul(fact[i - 1], i);
}

lld C(lld n, lld k)
{
    return divide(fact[n], mul(fact[k], fact[n - k]));
}
*/
lld n,m;
string str[105];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t,i,j;
    //cin>>t;
    t=1;
    while(t--)
    {
        cin>>n>>m;
        for(i=0;i<n;i++)
            cin>>str[i];
        lld dp[n][m];
        for(i=0;i<n;i++)
            for(j=0;j<m;j++)
            dp[i][j]=10000000;
    // (0,0)-->(n-1,m-1)
    //dp[i][j]--> yahan tak jane ka cost
        if(str[0][0]=='#')
        dp[0][0]=1;
        else
            dp[0][0]=0;
        for(i=1;i<n;i++)
            {if((str[0][i]==str[0][i-1]) || (str[0][i]=='.'))
            dp[0][i]=dp[0][i-1];
            else
            dp[0][i]=dp[0][i-1]+1;
            }
        for(i=1;i<n;i++)
            if((str[i][0]==str[i-1][0])||str[i][0]=='.')
            dp[i][0]=dp[i-1][0];
        else
            dp[i][0]=dp[i-1][0]+1;
        for(i=1;i<n;i++)
        {
            for(j=1;j<m;j++)
            {   lld ans=10000000;
                if((str[i-1][j]==str[i][j]) || str[i][j]=='.')
                    ans=min(ans,dp[i-1][j]);
                else
                    ans=min(ans,dp[i-1][j]+1);
                if((str[i][j-1]==str[i][j]) || str[i][j]=='.')
                    ans=min(ans,dp[i][j-1]);
                else
                    ans=min(ans,dp[i][j-1]+1);
                dp[i][j]=ans;
            }
        }

        cout<<dp[n-1][m-1]<<endl;

    }

}



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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll N;
    string S;
    cin >> N;
    vector<ll> vec(N);
    vector<ll> X(N);
    REP(i,N)cin >>X.at(i);
    REP(i, N)
    vec.at(i) = X.at(i);

    sort(vec.begin(), vec.end());

    REP(i,N){
        if(X.at(i)>=vec.at(N/2)){
            cout << vec.at(N / 2-1) << endl;
        }
        else{
            cout << vec.at(N / 2 ) << endl;
        }
    }


}


Measured memory_bytes: 5376
#include <bits/stdc++.h>  // ver2.2.0
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<", ";cout<<a.back()<<']'<<endl
#define VVout(a) rep(lY,0,a.size()){Vout(a[lY]);}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MOD 1000000007  //  10^9 + 7
using namespace std;
 
int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm
void uniq(Vi &v){sort(ALL(v)); v.erase(unique(ALL(v)),v.end());}  //  uniqのやつ
 
int mypow(int x, int n, int m){  //  累乗x^n(mod m)  O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
 
signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n;
  cin >> n;
  if(n==1) {cout<<"node 0: parent = -1, depth = 0, root, []"<<endl;return 0;}
  Vi per(n,-1),dep(n);
  VVi chi(n,Vi(0));
  
  int qw,er,ty;
  rep(i,0,n){
    cin >> qw >> er;
    rep(j,0,er){
      cin >> ty;
      chi[qw].pb(ty);
      per[ty] = qw;
    }
  }
  
  //Vout(per);
  
  Vi zi(n,-5);
  rep(i,0,n){
    if(per[i]==-1){
      qw = i;
      zi[qw] = 0;
    }
  }
  
  int zict=1,sizect;
  queue<int> next;
  rep(i,0,chi[qw].size()) next.push(chi[qw][i]);
  
  while(!next.empty()){
    sizect = next.size();
    rep(i,0,sizect){
      qw = next.front();
      next.pop();
      zi[qw] = zict;
      if(chi[qw].size()!=0){
        rep(j,0,chi[qw].size()) next.push(chi[qw][j]);
      }
    }
    zict++;
  }
  //Vout(zi);
  
  rep(i,0,n){
    //sort(ALL(chi[i]));
    cout << "node "<<i<<": parent = " << per[i] <<", depth = "<<zi[i]<<", ";
    if(per[i]==-1) cout<<"root, [";
    else if(chi[i].size()==0) {cout<<"leaf, []"<<endl;continue;}
    else cout<<"internal node, [";
    Vout(chi[i]);
  }
  
  return 0;
}


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

int a, b, c, n, ans;

int main() {
	int i, j, t;
	cin >> a >> b >> c >> n;
	for(i=0; i<=3000; i++) for(j=0; j<=3000; j++) {
		t = n - a*i - b*j;
		if(t<0) break;
		if(t % c == 0) ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256