akhauriyash/Code-Regression huggingface dataset:
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10;
int n , ok[N];
char s[N];
string pat[4] = {"dream" , "dreamer" , "erase" , "eraser"};

int main(){
  scanf("%s",s+1);
  n = strlen(s+1);
  ok[0] = 1;
  rep(i,1,n+1) {
    rep(j,0,4) if(i>=sz(pat[j])&&ok[i-sz(pat[j])]&&string(s+i-sz(pat[j])+1,sz(pat[j]))==pat[j]) {
      ok[i] = 1;break;
    }
  }
  printf(ok[n] ? "YES" : "NO");
  return 0;
}


Measured memory_bytes: 768
import java.util.Scanner;
public class Main {
	static int a,b;
	static int ans;
	
	public static void main(String[] args) {
		 Scanner sc = new Scanner(System.in);
		 while(sc.hasNext()) {
			ans = 0;
			int n = sc.nextInt();
			int[] friend = new int[100011];
			for(int i=0;i<100011;i++) {
				friend[i] = 0;
			}
			while(n-->0){
				a = sc.nextInt();
				b = sc.nextInt();
				for(int i=a-1;i<b;i++) {
					friend[i]++;
				}
			}
			for(int i=0;i<=100001;i++) {
				if(i <= friend[i]) ans = i;
			}
			System.out.println(ans);
		 }	 
	}
}


Measured memory_bytes: 100080
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, m;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> m;
  vector<int> c(n + 1, 0);
  vector<bool> f(n + 1, false);

  int w_sum = 0, a_sum = 0;
  REP(i, m) {
    int p;
    string s;
    cin >> p >> s;

    if(!f[p]) {
      if(s == "WA") {
        c[p]++;
      } else {
        a_sum++;
        w_sum += c[p];
        f[p] = true;
      }
    }
  }

  cout << a_sum << " " << w_sum << endl;
}


Measured memory_bytes: 640
using System;
using CompLib.Util;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        long k = sc.NextInt();
        long a = sc.NextInt();
        long b = sc.NextInt();

        // 交換
        long ans = k + 1;

        if (a < b)
        {
            // a-1回
            long tmp = k - (a - 1);

            long a2 = a;
            // 2回でb-a増える
            a2 += (tmp / 2) * (b - a);
            if (tmp % 2 == 1)
            {
                a2++;
            }

            ans = Math.Max(ans, a2);
        }

        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 13140
import sys
input = sys.stdin.readline


def main():
    n, k = map(int, input().split())

    products = [int(input()) for _ in range(n)]

    left = 1
    right = 10000 * 100000  # 最大重量 × 最大貨物数

    while left < right:
        mid = (left + right) // 2
        # print("left:{}".format(left))
        # print("right:{}".format(right))
        # print("mid:{}".format(mid))

        v = allocate(mid, k, products)
        # print("count:{}".format(v))

        if n <= v:
            right = mid
        else:
            left = mid + 1

    print(right)


def allocate(capacity, truckNum, products):
    # print("===== start allocation capacity:{}======".format(capacity))
    v = 0
    tmp = 0
    truckNum -= 1
    while len(products) > v:
        product = products[v]

        # print("tmp weight:{}".format(tmp))
        # print("product weight:{}".format(product))

        if product > capacity:
            # print("capacity over")
            # そもそも１個も乗らない時避け
            return 0

        if tmp + product <= capacity:
            # 同じトラックに積み続ける
            tmp += product
        else:
            # 新しいトラックがまだあればつむ
            if truckNum > 0:
                # print("new truck")
                truckNum -= 1
                tmp = product
            else:
                return v

        v += 1

    return v


if __name__ == '__main__':
    main()



Measured memory_bytes: 9564
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    map<ll,ll> mp;
    ll ans = 0;
    for(ll i = 0; i < n; i++){
        cin >> a[i];
        ans += a[i];
        mp[a[i]]++;
    }
    ll q;
    cin >> q;
    vector<ll> can;
    for(ll i = 0; i < q; i++){
        ll b,c;
        cin >> b >> c;
        ll bc = mp[b],cc = mp[c];
        ans -= bc*(b-c);
        mp[c] += bc;
        mp[b] = 0;
        can.push_back(ans);
    }
    for(auto p:can) cout << p << endl;
    return 0;
}

Measured memory_bytes: 10756
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  vl a(n + 2, 0);
  ll sum = 0;
  rep2(i, 1, n + 1) {
    cin >> a[i];
    sum += abs(a[i] - a[i - 1]);
  }
  sum += abs(a[n] - 0);
  rep2(i, 1, n + 1) {
    ll ans = sum;
    ans -= abs(a[i] - a[i - 1]) + abs(a[i] - a[i + 1]);
    ans += abs(a[i - 1] - a[i + 1]);
    cout << ans << '\n';
  }
}

Measured memory_bytes: 2048
#include<iostream>
#include<deque>
#include<vector>
#include<string>
#include<stdio.h>
using namespace std;

#define SIZEOF(x) (sizeof x) / (sizeof x[0])

bool j(int *p , int n){
    if((p[n-1] >p[n] && p[n] > p[n+1])||(p[n+1]>p[n]&&p[n] > p[n-1])){
        return true;
    }else {
        return false;
    }
}


int main(){
    int n;
    cin >> n;
    int p[n];
    int y=0;
    for (int t = 0; t< n ; t++){
        cin>>p[t];
    }
    for (int t = 1; t<n-1;t++){
        if(j(p,t)){
            y += 1;
        }
    }
    
    printf("%d" , y);




    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int h,w;
char field[11][11];
int sang;
int sx,sy;
int leaf;
char rec[1001];
bool fin;
const string ss="UUULLDDRRR";

void dfs(int cx,int cy,int cang,int cnt){
	if(fin)return;
	if(leaf==cnt){
		fin=true;
		for(int i=0;i<leaf;i++)cout<<rec[i];
		cout<<endl;
		return;
	}
	string s;
	for(int i=0;i<cnt;i++)s+=rec[i];
	if(ss==s){
	//	cout<<endl;
	}
	if(cang!=2){
		for(int i=-1;i+cy>=0;i--){
			int nx=cx;
			int ny=i+cy;
			if(field[ny][nx]=='o'){
				field[ny][nx]='.';
				rec[cnt]='U';
				dfs(nx,ny,0,cnt+1);
				field[ny][nx]='o';
				break;
			}
		}
	}
	if(cang!=0){
		for(int i=1;i+cy<h;i++){
			int nx=cx;
			int ny=i+cy;
			if(field[ny][nx]=='o'){
				field[ny][nx]='.';
				rec[cnt]='D';
				dfs(nx,ny,2,cnt+1);
				field[ny][nx]='o';
				break;
			}
		}
	}
	if(cang!=3){
		for(int i=1;i+cx<w;i++){
			int nx=cx+i;
			int ny=cy;
			if(field[ny][nx]=='o'){
				field[ny][nx]='.';
				rec[cnt]='R';
				dfs(nx,ny,1,cnt+1);
				field[ny][nx]='o';
				break;
			}
		}
	}
	if(cang!=1){
		for(int i=-1;i+cx>=0;i--){
			int nx=cx+i;
			int ny=cy;
			if(field[ny][nx]=='o'){
				field[ny][nx]='.';
				rec[cnt]='L';
				dfs(nx,ny,3,cnt+1);
				field[ny][nx]='o';
				break;
			}
		}
	}
}

int main(){

	cin>>h>>w;
	fin=false;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>field[i][j];
			if(field[i][j]=='o')leaf++;
			else if(field[i][j]!='.'&&field[i][j]!='o'){
				switch(field[i][j]){
				case 'U':
					sang=0;
					break;
				case 'D':
					sang=2;
					break;
				case 'R':
					sang=1;
					break;
				case 'L':
					sang=3;
					break;
				}
				field[i][j]='.';
				sx=j;sy=i;
			}
		}
	}
	dfs(sx,sy,sang,0);

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  for(int i=0;i<N;i++){cin >> A[i];}
  int a=0; int ans=1;
  for(int i=0;i<N-1;i++){
    if(a==0){
      if(A[i]<A[i+1]){a=1;}
      else if(A[i]>A[i+1]){a=-1;}
    }
    else if(a==1){
      if(A[i]>A[i+1]){a=0; ans++;}
    }
    else if(a==-1){
      if(A[i]<A[i+1]){a=0; ans++;}
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string.h>

// ?°????????????§????????????
void toUpper(char *str) {
	int len = strlen(str);
	if (len <= 0) {
		return;
	}
	for (int i = 0; i < len; i++) {
		if (str[i] >= 'a' && str[i] <= 'z') {
			str[i] &= 0xdf;	//?°????????????§??????
		}
	}
}

int main(void) {


	char word[16];
	char sentense[1024];
	char t[1024];
	char tmp[16];

	int num[50];
	int combo[50];

	scanf("%s", word);
	toUpper(word);
	int cnt = 0;
	while (fgets(sentense, 1024, stdin) != NULL) {
		if ( strcmp(sentense, "END_OF_TEXT\n") == 0 ) {
			break;
		}
		toUpper(sentense);
		int len = strlen(sentense);
		if (len > 0) {
			sentense[len - 1] = '\0';
		}
		char *ptr = strtok(sentense, " ");
		while (ptr != NULL ) {
			if (strcmp(ptr, word) == 0) {
				cnt++;
			}
			ptr = strtok(NULL, " ");
		}

	}

	printf("%d\n", cnt);

	return 0;

}

Measured memory_bytes: 2716
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000



int main(){
	
	vector<int> A = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	
	int K;
	cin>>K;
	
	cout<<A[K-1]<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad

h 0 = 0
h n = 3 * h (n - 1) + 1

fa :: [Int] -> [Int] -> [Int] -> Int -> Int
fa [] [] [] 0 = 0
fa (a:as) b c n
  | a == n = fa as b c (n - 1)
fa a (b:bs) c n
  | b == n = fc a bs c (n - 1) + 1 + 2 * h (n - 1)
fa a b (c:cs) n
  | c == n = fa a b cs (n - 1) + 1 + h (n - 1) + h n

fb :: [Int] -> [Int] -> [Int] -> Int -> Int
fb [] [] [] 0 = 0
fb (a:as) b c n
  | a == n = fc as b c (n - 1) + 1 + h (n - 1)
fb a (b:bs) c n
  | b == n = fb a bs c (n - 1)
fb a b (c:cs) n
  | c == n = fa a b cs (n - 1) + 1 + h (n - 1)

fc :: [Int] -> [Int] -> [Int] -> Int -> Int
fc a b c n = fa c b a n

f :: [Int] -> [Int] -> [Int] -> Int -> Int
f a b c n = min stepA stepC
  where stepA = fa a b c n
        stepC = fc a b c n

g :: [Int] -> [Int] -> [Int] -> Int -> Int
g a0 b0 c0 n = f a b c n
  where a = map (\x -> n + 1 - x) a0
        b = map (\x -> n + 1 - x) b0
        c = map (\x -> n + 1 - x) c0

main = do
  [n, m] <- map read . words <$> getLine :: IO [Int]
  unless ([n, m] == [0, 0]) $ do
    _:a <- map read . words <$> getLine :: IO [Int]
    _:b <- map read . words <$> getLine :: IO [Int]
    _:c <- map read . words <$> getLine :: IO [Int]
    let step = g a b c n
    let answer = if step <= m then step else -1
    print answer
    main


Measured memory_bytes: 4060
import math
N, M = [int(i) for i in input().split()]
# for i in range(min(math.floor(math.sqrt(M)), M//N), 0, -1):
#   if M % i == 0:
#     if M // i <= M//N:
#       print(max(i, M // i))
#     else:
#       print(i)
#     break

ans = 1
for i in range(1, math.floor(M**0.5)+1):
  if M % i == 0:
    if M//i <= M//N:
      ans = max(ans, M//i)
    elif i <= M//N:
      ans = max(ans, i)
print(ans)



Measured memory_bytes: 64224
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<random>

//使い方がよくわからない
#include<stack>
#include<queue>
#include<bitset>
#include<sstream>

#define rep(i,n) for(int i=0;i<(n);i++) 
#define rep1(i,n) for(int i=1;i<(n);i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]){
    int  a,b;
    cin >> a >> b;
    if((a>=10) || (b>=10)){
        co(-1);
        return 0;
    }else{
        co(a*b);
        return 0;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> v;
  int n,m;
  cin >> n >> m;
  int a,b;
  int MAX_N = 8;
  int link[MAX_N][MAX_N];
  REP(i,MAX_N)REP(j,MAX_N)link[i][j]=0;
  REP(i,n){
      v.push_back(i);
  }
  REP(i,m){
      cin >> a >> b;
      link[a-1][b-1]=1;
      link[b-1][a-1]=1;
  }
  int ans = 0;
  do{
      //REP(i,n){cout << v[i];}
      //cout << endl;
      if (v[0]!=0)continue;
      bool flag = true;
      REP(i,n-1){
          if (link[v[i]][v[i+1]] == 0)flag = false;
      }
      if (flag)ans++;
  }while(next_permutation(ALL(v)));

  cout << ans << endl;
}


Measured memory_bytes: 256
/* atcoder */
#include "bits/stdc++.h"
using namespace std;

/* typedef */
/* long系 */
typedef long long ll;   // long long
typedef long double ld; // long double
/* vector系 */
typedef vector<int> vi;                    // intのvector
typedef vector<double> vd;                 // doubleのvector
typedef vector<ll> vll;                    // llのvector
typedef vector<ld> vld;                    // ldのvector
typedef vector<vector<int>> vvi;           // intの2次元vector
typedef vector<vector<double>> vvd;        // doubleの2次元vector
typedef vector<vector<ll>> vvll;           // llの2次元vector
typedef vector<vector<ld>> vvld;           // ldの2次元vector
typedef vector<pair<int, int>> vi_i;       // i_iのvector
typedef vector<pair<double, double>> vd_d; // d_dのvector
typedef vector<pair<ll, ll>> vl_l;         // l_lのvector
typedef vector<pair<ld, ld>> vld_ld;       // ld_ldのvector
typedef vector<string> vs;                 // stringのvector
/* pair系 */
typedef pair<int, int> i_i;       // int同士のpair
typedef pair<double, double> d_d; // double同士のpair
typedef pair<ll, ll> l_l;         // ll同士のpair
typedef pair<ld, ld> ld_ld;       // ld同士のpair

/* define */
#define all(v) v.begin(), v.end() // コンテナ全体
#define PI (acos(-1))             // 円周率pi

/* stringstream */
stringstream ss;
stringstream init_ss; // save default formatting

/* upper, lower */
struct ToUpper
{
    char operator()(char c)
    {
        return toupper(c);
    }
};
struct ToLower
{
    char operator()(char c)
    {
        return tolower(c);
    }
};

/* main */
void Main(void)
{
    string s;
    cin >> s;
    int N = s.size() - 1;
    ll ans = 0;
    for (int bit = 0; bit < (1 << N); ++bit)
    {
        int st = 0, go = 0;
        for (int i = 0; i < N; i++)
        {
            if (bit & (1 << i))
            {
                go = i;
                ll num;
                ss.str("");                      // バッファクリア
                ss.clear(stringstream::goodbit); // 状態クリア
                ss.copyfmt(init_ss);             // 書式クリア
                ss << s.substr(st, go - st + 1);
                ss >> num;
                ans += num;
                st = go + 1;
            }
        }
        go = s.size() - 1;
        ll num;
        ss.str("");                      // バッファクリア
        ss.clear(stringstream::goodbit); // 状態クリア
        ss.copyfmt(init_ss);             // 書式クリア
        ss << s.substr(st, go - st + 1);
        ss >> num;
        ans += num;
    }
    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();

    return 0;
}


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

using namespace std;

int main(){
	double a,b,c,d,e,f;
	while(cin>>a>>b>>c>>d>>e>>f){
		double y=(a*f-c*d)/(a*e-b*d);
		double x=(c-b*y)/a;
		cout<<fixed<<setprecision(3)<<x<<" "<<y<<endl;
	}
	return 0;
}



Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int a[100010];
vector<int>v[100010];
int main(){
	 int n,m;
	 cin>>n>>m;
	 for(int i=1;i<=n;i++) cin>>a[i];
	 for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		int w1=0;
		for(int j=0;j<v[i].size();j++){
			if(a[v[i][j]]>=a[i]){
				w1=1;
			 break;
		  }
		}
		if(!w1) ans++;
	}
	cout<<ans<<'\n';
}

Measured memory_bytes: 9156
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
 
int dxy[5] = {0, 1, 0, -1, 0};
// assign

vector <string> board;
vvb used;
int x, y;

bool solve(int a, int b);

signed main()
{
    cin >> x >> y;
    board.assign(x, "");

    rep(i, x) {
        cin >> board[i];
    }

    bool ret;
    rep(i, x) {
        rep(j, y) {
            if (board[i][j] == '%') {
                ret = solve(i, j);
            }
        }
    }

    cout << ( (ret) ? "Yes" : "No" ) << endl;

    return 0;
}

bool solve(int a, int b)
{
    queue< i_i > q;
    q.push(i_i(a, b));
    used.assign(x, vb(y, false));
    used[a][b] = true;
    bool ret = true, stop = false;

    while (!q.empty()) {
        queue <i_i> nxt;
        while (!q.empty()) {
            int c = q.front().first, d = q.front().second;
            q.pop();
            rep(i, 4) {
                int nx = c + dxy[i], ny = d + dxy[i+1];
                if (nx < 0 || ny < 0 || x <= nx || y <= ny
                        || used[nx][ny] ) {
                    continue;
                }
                if (board[nx][ny] == '.') {
                    nxt.push(i_i(nx, ny));
                } else if (board[nx][ny] == '$') {
                    ret = false;
                    stop = true;
                } else if (board[nx][ny] == '@') {
                    stop = true;
                } 
                used[nx][ny] = true;
            }
        }
        if (stop) { return ret; }
        q = nxt;
    }
    return false;
}

Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
char s[100005];
int dp[100005];
vector<int> del[100005], add[100005];
int main(){
    memset(dp, -1, sizeof(dp));
    int n, m;
    scanf("%d%d", &n, &m);
    scanf("%s", s);
    dp[n] = 0;
    multiset<int> cur;
    add[n].push_back(0);
    del[n-1].push_back(0);
    for(int i=n;i>=0;i--){
        for(int j=0;j<add[i].size();j++){
            int val = add[i][j];
            cur.insert(val);
        }
        for(int j=0;j<del[i].size();j++){
            int val = del[i][j];
            cur.erase(cur.find(val));
        }
        if(s[i] == '1' || cur.empty()) continue;
        dp[i] = *cur.begin();
        if(i-1 >= 0) add[i-1].push_back(dp[i]+1);
        if(i-m-1 >= 0) del[i-m-1].push_back(dp[i]+1);
    }
    if(dp[0] == -1) printf("-1\n");
    else{
        multiset<pii> cur;
        for(int i=0;i<=n;i++) if(s[i] == '0') cur.insert(pii(-dp[i], i));
        int ans = dp[0]-1;
        int l = 0;

        while(l < n){
            while(-cur.begin()->first > ans || cur.begin()->second <= l) cur.erase(cur.begin());
            printf("%d ", cur.begin()->second - l);
            l = cur.begin()->second;
            ans--;
        }
    }
}

Measured memory_bytes: 16512
n=int(input())
f=[ list(map(int,input().split())) for _ in range(n)]
#print(n)
p=[ list(map(int,input().split())) for _ in range(n)]
#print(f)
#print(p)
ans=-float('inf')
for mask in range(1,1<<10):
    su=0
    for i in range(n):
        cnt=0
        for j in range(10):
            if (mask>>j&1) and f[i][j]==1:
                cnt+=1
 #       print(i,cnt)
  #      print(len(p),len(p[0]))
        su+=p[i][cnt]
    ans=max(ans,su)
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
using namespace std;

int32_t main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	int n,ans=1;
	cin >> n;
	int a[n];
	for(int i=0;i<n;i++)
		cin >> a[i];
	int m=a[0];
	for(int i=1;i<n;i++){
		if(a[i]<=m){
			ans++;
			m=a[i];
		}
	}
	cout << ans;
}


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

int main() {
    int x, y, a, b, t, ans = 2000000100;
    cin >> x >> y;
    a = x;  b = y;

    if(x <= y) {
        t = y-x;
        ans = min(t, ans);
    }

    x *= -1;
    if(x <= y) {
        t = y-x+1;
        ans = min(t, ans);
    }

    x = a;
    y *= -1;
    if(x <= y) {
        t = y-x+1;
        ans = min(t, ans);
    }

    y = b;
    x *= -1;
    y *= -1;
    if(x <= y) {
        t = y-x+2;
        ans = min(t, ans);
    }
    
    cout << ans;

    cout << endl;
    return 0;
}

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

using namespace std;

int n;
char cs[105];
vector<int> parens;
int insert;
int depth;
int main() {
	scanf("%d",&n);
	scanf("%s",cs);
	for(int i=0;i<n;i++){
		if(cs[i]=='(')depth++;
		else depth--;
		if(depth<0){
			insert++;
			depth++;
		}
	}
	while(insert--)printf("(");
	for(int i=0;i<n;i++){
		printf("%c",cs[i]);
	}
	while(depth--)printf(")");
	printf("\n");
	return 0;
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int n, Y;
    cin >> n >> Y;
    for (int x=0; x<=n; ++x) {
        for (int y=0; y<=n-x; ++y) {
            for (int z=0; z<=n-x-y; ++z) {
                if (x+y+z == n and 10000*x + 5000*y + 1000*z == Y) {
                    cout << x << ' ' << y << ' ' << z << endl;
                    return 0;
                }
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int, int>
#define vi              vector<int>
#define si              set<int>
#define usi             unordered_set<int>
#define mii             map<int, int>
#define umii            unordered_map<int, int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int, vi, greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define endl            '\n'
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(t)            int t; cin>>t; while(t--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
void jaiswal_sahil()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
}
 
int32_t main()
{
    jaiswal_sahil();
    
    string s, t; cin>>s>>t;

    int n = s.size(), m = t.size();
    int dp[n+1][m+1];
    memset(dp, 0, sizeof(dp));

    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            if(s[i-1] == t[j-1]){
                dp[i][j] = 1 + dp[i-1][j-1];
            }else{
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }
    
    vector<char> ans;
    int i=n, j=m;
    while(i>=1 and j>=1){
        if(s[i-1] == t[j-1]){
            ans.push_back(s[i-1]);
            i--, j--;
        }else{
            if(dp[i-1][j] == dp[i][j]){
                i--;
            }else{
                j--;
            }
        }
    }

    reverse(ans.begin(), ans.end());
    for(auto a: ans)
        cout<<a;

    // cout<<dp[n][m]<<endl;

    return 0;

}

Measured memory_bytes: 70656
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { x.modm(y.modpow(mod - 2)); }

void main()
{
	auto A = RD;
	auto B = RD;
	auto N = RD;

	if (N >= B)
		writeln(A*(B-1)/B);
	else
		writeln(A*N/B);

	stdout.flush;
	debug readln;
}

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

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9)+7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n) {
  vector< pair<ll, ll> > p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    p.push_back(make_pair(i, 0));
    while ((n % i) == 0) {
      n /= i;
      p[i].second += 1;
    }
    p.push_back(make_pair(n, 0));
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
	ll b = MOD, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= MOD;
	if (u < 0) { u += MOD; }
	return u;
}
// 順列
ll permutation(const ll n, const ll m) {
	ll result = 1;
	for (ll i = n; i > n - m; i--) { result = (result * i) % MOD; }
	return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
	if (x == 0) return 1;
	ll res = repeat_square(n, x/2);
	res = res * res % MOD;
	if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ
ll combination(const ll n, const ll a) {
	ll x = 1, y = 1;
  for(ll i = 0; i < a; i++){
    x = x * (n-i) % MOD;
    y = y * (i+1) % MOD;
  }
  return x * repeat_square(y, MOD-2) % MOD;
}

int main() {
  int N;
  string S;
  cin >> N >> S;
  int r = 0, w = 0;
  rep(i, N) {
    if (S[i] == 'R') r++;
  }

  int ans = max(r, w);

  rep(i, N) {
    if (S[i] == 'R') r--;
    else w++;
    int x = max(r, w);
    ans = min(ans, x);
  }

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


Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 1; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
const int MOD = 1e9+7;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n,m; cin >> n >> m;
  vector<int> a(n), b(m);
  set<int> as,bs;
  REP(i,n){
    cin >> a[i];
    as.insert(a[i]);
  }
  REP(i,m){
    cin >> b[i];
    bs.insert(b[i]);
  }
  if(as.size()!=n || bs.size()!=m){
    cout << 0 << endl;
    return 0;
  }
  
  sort(ALL(a));
  sort(ALL(b));
  ll ans = 1;
  REPR(x,n*m){
    if(as.count(x) & bs.count(x)){
      continue;
    }else if(as.count(x)){
      auto itr = lower_bound(ALL(b), x);
      ans *= (b.end() - itr);
      ans %= MOD;
    }else if(bs.count(x)){
      auto itr = lower_bound(ALL(a), x);
      ans *= (a.end() - itr);
      ans %= MOD;
    }else{
      auto aitr = lower_bound(ALL(a), x);
      auto bitr = lower_bound(ALL(b), x);
      ll tmp = (a.end() - aitr) * (b.end() - bitr);
      ans *= (tmp - (n*m - x));
      ans %= MOD;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define LL_MAX LLONG_MAX
#define ULL_MAX ULLONG_MAX
#define ull unsigned long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb(x) push_back(x)
#define re() pop_back()
#define eb(x) emplace_back(x)
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define all(a) a.begin(),a.end()
#define msort(a) sort(a.begin(),a.end())
#define pii pair<int,int>
#define sz(x) int(x.size())
#define mk make_pair
#define endl '\n'

void solve()
{
    ll n,d;
    cin>>n>>d;
    int count=0;
    for (int i = 0; i < n; i++)
    {
        ll x,y;
        cin>>x>>y;
        if(x*x+y*y<=d*d) count++;
    }
    cout<<count<<endl;
}

int main()
{
    IOS;
    ll t=1; //cin>>t;
    while (t--)
    {
        solve();
    }
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define llong long long
#define mkpr make_pair
#define x first
#define y second
#define iter iterator
#define riter reversed_iterator
#define y1 Lorem_ipsum_
#define tm dolor_sit_amet_
using namespace std;

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

const int mxN = 1e5;
struct Element
{
	llong a,b;
	bool operator <(const Element &arg) const {return max(a,b)>max(arg.a,arg.b);}
} a[mxN+3];
llong s[mxN+3];
int n; llong sum;

struct Fraction
{
	llong a,b,c;
	Fraction() {}
	Fraction(llong _a,llong _b,llong _c) {a = _a,b = _b,c = _c;}
	bool operator <(const Fraction &arg) const
	{
		if(a!=arg.a) {return a<arg.a;}
		return b*arg.c<arg.b*c;
	}
};

llong gcd(llong x,llong y) {return y==0?x:gcd(y,x%y);}

int main()
{
	n = read();
	for(int i=1; i<=n; i++) scanf("%lld%lld",&a[i].a,&a[i].b),sum += a[i].a;
	sort(a+1,a+n+1);
	for(int i=1; i<=n; i++) s[i] = s[i-1]+max(a[i].a,a[i].b);
	Fraction ans(n,0,1);
	for(int i=1; i<=n; i++)
	{
		int pos = lower_bound(s+1,s+n+1,sum-a[i].b)-s,cnt = pos; llong rst = sum-s[pos];
		if(pos>=i) {pos = lower_bound(s+1,s+n+1,sum-a[i].b+max(a[i].a,a[i].b))-s,cnt = pos-1,rst = sum-s[pos]+max(a[i].a,a[i].b);}
		if(pos>n) {continue;}
		rst = max(0ll,rst);
		Fraction tmp(cnt,rst,a[i].b);
		if(tmp<ans) {ans = tmp;}
	}
	llong x = ans.c*ans.a+ans.b,y = ans.c*n; x = y-x;
	llong g = gcd(x,y); x/=g,y/=g;
	printf("%lld %lld\n",x,y);
	return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define per(i,l,r) for (int i=l;i>=r;i--)
using namespace std;
typedef long long ll;
char s[200500];
int ans;
ll sum,c;
int main(){
    scanf("%s",s+1);
    int len=strlen(s+1);
    rep(i,1,len) if (s[i]=='W') c++,sum+=i;
    printf("%lld\n",1ll*sum-c*(c+1)/2);
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

int main(){
    int a,b,x;
    cin >> x;
    if(x==1){
        cout << "Hello World" << endl;
    }
    else{
        cin >> a >> b;
        cout << a+b << endl;
    }
}

Measured memory_bytes: 256
S = input()
N = len(S)
ans = [0]*N
mark = "R"
start = 0
for i in range(N):
    if mark == "R":
        if S[i] == "L":
            ans[i] += (i-start)//2
            ans[i-1] += (i-start+1)//2
            start = i
            mark = "L"
    else:
        if S[i] == "R":
            ans[start] += (i-start+1)//2
            ans[start-1] += (i-start)//2
            start = i
            mark = "R"
else:
    ans[start] += (N-start+1)//2
    ans[start-1] += (N-start)//2
print (*ans)

Measured memory_bytes: 6400
using System;

namespace ABC073_C___Write_and_Erase
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var numbers = new long[N];
            for (int i = 0; i < N; i++) numbers[i] = long.Parse(Console.ReadLine());

            Array.Sort(numbers);
            var count = N;
            for (int i = 1; i < N; i++)
            {
                if (numbers[i] == numbers[i - 1])
                {
                    numbers[i] = 0;
                    numbers[i - 1] = 0;
                    count -= 2;
                }
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 17336
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
            string read = Console.ReadLine();
            string output = read;
            if (read.Length == 3)
            {
                var tca = read.ToCharArray();
                Array.Reverse(tca);
                read = new string(tca);

            }
            Console.WriteLine(read);
        }
    }
}


Measured memory_bytes: 11092
#pragma GCC optimize("O3", "unroll-loops")
//#pragma GCC target("avx2")
#pragma GCC target ("sse4")
#pragma optimize("fast-math")

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
#define endl '\n'
#define ull unsigned long long
#define si short int
#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int, int>
#define pdd pair<double, double>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define piii pair<pair<int, int>, int>
#define all(vec) (vec).begin(), (vec).end()
#define rall(vec) (vec).rbegin(), (vec).rend()
#define piiii pair<pair<int, int>, pair<int, int>>

void solve() {
    int n;
    cin>>n;
    vector<pli> arr(n);
    for(int i=0;i<n;i++){
        cin>>arr[i].first;
        arr[i].second=i;
    }
    //will see who is coming on prefix thats why if value equals latest is more
    static ll dp[2001][2001];
    sort(rall(arr));
    /*for(int i=0;i<n;i++) cout<<arr[i].first<<" ";
    cout<<endl;*/
    //dp[m][k] if we are looking on first m values and k from them is going to first
    //dp[0][0]=1;
    for(int m=1;m<=n;m++){
        for(int k=0;k<=m;k++){
            dp[m][k]=max((k<=m-1)?dp[m-1][k]+arr[m-1].first*abs(arr[m-1].second-(n-m+k)):0,
                    ((k-1>=0)?dp[m-1][k-1]+arr[m-1].first*abs(arr[m-1].second-k+1) : 0));
        }
    }
    ll mx=-1;
    for(int k=0;k<=n;k++){
        mx=max(dp[n][k], mx);
    }
    cout<<mx<<endl;
}

void testcases(int n) {
    n = 1 - n;
    if (!n) cin >> n;
    for (int i = 0; i < n; i++) {
        solve();
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    //freopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "r", stdin);
    //f=fopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "w");
    //freopen("C:\\Users\\Maximus\\CLionProjects\\Codeforces\\BestTeam\\output.txt", "w", stdout);

    unsigned int beg_time = clock();
    testcases(0);
    // 0 - no t, 1 - with t

    unsigned int end_time = clock();
    //cout << endl << endl << end_time - beg_time;
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second

#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)


int main(){
  int N;
  cin>>N;
  vector<int> L(2*N);
  for (int i=0;i<2*N;i++) {
    cin>>L[i];
  }
  sort(L.begin(),L.end());
  int ans = 0;
  for (int i=0;i<2*N;i+=2) {
    ans += L[i];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

const int mod = 1000000007;
struct mint{
	ll x;
	mint(ll x = 0):x((x%mod+mod)%mod){}
	mint operator-() const{return mint(-x);}
	mint& operator+=(const mint a){
		if((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if(!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if(t&1) a *= *this;
		return a;
	}
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
	bool operator==(const mint a){
		return x == a.x;
	}
};

mint dp[105][10];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int h, w, k;
	cin >> h >> w >> k;
	--k;
	dp[0][0] = 1;
	rep(i,h)rep(j,w){
		rep(S,(1<<(w-1))){
			bool ok = true;
			rep(l,w-2){
				if((S>>l & 1) && (S>>(l+1) & 1)) ok = false;
			}
			if(!ok) continue;
			if(j-1 >= 0 && (S>>(j-1) & 1)) dp[i+1][j-1] += dp[i][j];
			else if(j <= w-2 && (S>>j & 1)) dp[i+1][j+1] += dp[i][j];
			else dp[i+1][j] += dp[i][j];
		}
	}
	cout << dp[h][k].x << endl;
	return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); i++)

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main() {
  int n;
  cin >> n;
  map<string, bool> x;
  REP(i, n) {
    string s;
    cin >> s;
    x[s] = true;
  }
  cout << x.size() << endl;
  return 0;
}

Measured memory_bytes: 19104
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define append push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long int
#define pb push_back
#define print(a) cout<<a<<endl
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define all(x) x.begin(), x.end()
#define loop(i,n) for(int i=0;i<n;i++)
const int MOD = 1e9 + 7;
const ll longinf = 1000000000000000;
void solve();
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int t = 1;
	//cin>> t;
	while(t--){
		solve();
	}

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

vector<int> l;
ll dp[3000][3000];
ll fun(int i,int j)
{
	if(i>j)
		return 0;
	if(dp[i][j] > -longinf)
	{
		return dp[i][j];
	}
    dp[i][j]=max(l[i]-fun(i+1,j),l[j]-fun(i,j-1));
    return dp[i][j];
}
void solve()
{
	int n;
	cin>>n;
	loop(i,n)
	{
		loop(j,n)
		{
			dp[i][j]=-longinf;
		}
	}
	loop(i,n)
	{
		int x;cin>>x;
		l.pb(x);
		dp[i][i]=x;
	}
	cout<<fun(0,n-1);
}

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

typedef long long   ll;
const ll mod = 1e9 + 7;

#define speedup_IO      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n)     for(ll i = a; i < n; i++)
#define ford(i,n,a)     for(ll i = n-1; i >= a; i--)
#define pb              push_back
#define lb              lower_bound
#define ub              upper_bound
#define pll             pair<ll,ll>
#define all(a)          (a).begin(),(a).end()
#define reset(a,x)      memset(a,x,sizeof(a))

ll mypow(ll base, ll exp) {ll res = 1; while (exp) {if (exp & 1) res = (res * base) % mod; exp >>= 1, base = (base * base) % mod;} return res;}
ll gcd(ll a, ll b)  { return b ? gcd(b, a % b) : a;            }
ll mult(ll a, ll b) { return ((a % mod) * (b % mod)) % mod;    }
ll add(ll a, ll b)  { return (a % mod + b % mod) % mod;        }
ll sub(ll a, ll b)  { return (a % mod + mod - b % mod) % mod;  }

const ll inf = 1e18;
const int nax = 1e5 + 5;
const int SZ = 2;
const int MOD = 1e9 + 7;

int main()
{
	speedup_IO;
	char a;
	cin>>a;

	cout<<(char)(a+1);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_set>
#include <limits>

int main()
{
    using namespace std;
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    unordered_set<int> sizes;
    int size;

    // ignore N
    cin.ignore(numeric_limits<streamsize>::max(), '\n');

    while (cin >> size)
    {
        sizes.emplace(size);
    }
    
    cout << sizes.size() << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

    vector<ll> dp(n+1,2);
    dp[1] = 1;

    for(ll i = 2; i<=n/2; i++){
        ll jud = sqrt(i);
        for(ll j = 2; i * j <= n; j++){
            dp[i*j]++;
        }
    }

    ll ans = 0;
    rep(i,n){
        ans += (i+1) * dp[i+1];
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 81424
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main(){
    int h,w;
    cin>>h>>w;
    int sum=0;
    rep(i,0,h)rep(j,0,w){
        char c;
        cin>>c;
        if(c=='#')sum++;
    }
    if(sum==h+w-1)cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
    return 0;
}


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

int main() {
  int n;
  cin>>n;
  vector<pair<int,int> > a(n),b(n);
  for (int i=0; i<n; i++) {
    cin>>a[i].first>>a[i].second;
  }
  for (int i=0; i<n; i++) {
    cin>>b[i].first>>b[i].second;
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  int cnt=0;
  bool used[n];
  for (int i=0; i<n; i++) {
    used[i]=false;
  }
  for (int i=0; i<n; i++) {
    int t=-1,f=-1;
    for (int j=0; j<n; j++) {
      if (!used[j] && a[j].first<b[i].first && a[j].second<b[i].second && a[j].second>t) {
        t=a[j].second;
        f=j;
      }
    }
    if (f>-1) {
      used[f]=true;
      cnt++;
    }
  }
  cout<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 256
from collections import defaultdict


def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    ans = 10 ** 9 * n
    acc = 0
    s = sum(a)
    for i in range(n - 1):
        acc += a[i]
        diff = abs(s - 2 * acc)
        if diff < ans:
            ans = diff
    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 25324