akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>
#include<map>
#include<deque>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=1000000007;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}


int main(void){
    ll N,K;
    cin>>N>>K;
    ll ans=N%K;
    ans=min(ans,ABS(ans-K));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
a = [int(i) for i in input().split(' ')]
N, M, D = a[0], a[1], a[2]

area = []
for i in range(N):
    area.append(input())

toori = 0
reverse_area = []
for tate in range(N):
    row_area = list(area[tate])
    for yoko in range(M - D + 1):
        mass = D
        for now_mass in range(D):
            if row_area[now_mass + yoko] == ".":
                mass -= 1
            if row_area[now_mass + yoko] == '#':
                break

            if mass == 0:
                toori += 1
                break


for tate in range(N - D + 1):
    for yoko in range(M):
        mass = D
        for now_mass in range(D):
            if area[now_mass + tate][yoko] == ".":
                mass -= 1
            if area[now_mass + tate][yoko] == '#':
                break

            if mass == 0:
                toori += 1
                break
print(toori)

Measured memory_bytes: 7824
///-----Bismillahir Rahmanir Rahim-----///

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

///---FAST I/O---///
#define Boost() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

///---DATA TYPE---///
typedef long long ll;
typedef long long int lli;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<int>::iterator vit;
typedef set<int>::iterator sit;

///---LOOP---///
#define rep0(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)

///---I/O---///
#define sf scanf
#define pf printf

///---OTHERS---///
#define pb push_back
#define all(c)		c.begin(),c.end()
#define MK make_pair
#define F first
#define S second
#define endl '\n'


///---INITIALIZATION---//
#define mem(a,b) memset(a, b, sizeof(a) )

///---CALCULATE---///
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) ((a) * (a))

///---BIT OPERATION---///
inline bool checkBit(ll n, int i)
{
    return n&(1LL<<i);
}
inline ll setBit(ll n, int i)
{
    return n|(1LL<<i);;
}
inline ll resetBit(ll n, int i)
{
    return n&(~(1LL<<i));
}

///------String/Char Related Functions-----///
string makeintString(int x)
{
    stringstream ss;
    ss << x;
    string str = ss.str();
    ///cout<<str<<endl;
    return str;
}
string makellString(ll x)
{
    stringstream ss;
    ss << x;
    string str = ss.str();
    ///cout<<str<<endl;
    return str;
}
char cpp(char c)
{
    return static_cast<char>(c + 1);
}

///------------Sorting STL----------///
struct func
{
	//this is a sample overloading function for sorting stl
	bool operator()(pii const &a, pii const &b)
	{
		if(a.F==b.F)
			return (a.S<b.S);
		return (a.F<b.F);
	}
};

///---CONSTANT---///
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

int main()
{
    Boost();

    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        int l,r,d,cnt=0;
        cin>>l>>r>>d;
        int st=ceil((1.0*l)/(1.0*d));
        st=st*d;
        //cout<<st<<endl;
        for(int i=st;i<=r;i+=d) cnt++;
        cout<<cnt<<endl;

    }
    return 0;
}


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

void dfs(const vvi& G, vi& cnt, vb& seen, int root, int cum) {
    seen[root] = true;
    cnt[root] += cum;

    for (int child : G[root]) {
        if (seen[child]) { continue; }
        dfs(G, cnt, seen, child, cnt[root]);
    }
}

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

    int n, q;
    cin >> n >> q;

    vvi G(n);
    rep(_, 0, n - 1) {
        int a, b;
        cin >> a >> b;
        G[a - 1].push_back(b - 1);
        G[b - 1].push_back(a - 1);
    }

    vi cnt(n, 0);
    rep(i, 0, q) {
        int p, x;
        cin >> p >> x;
        cnt[p - 1] += x;
    }

    vb seen(n, false);
    dfs(G, cnt, seen, 0, 0);

    rep(i, 0, n) { cout << cnt[i] << " "; }
    cout << endl;

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(4);
  for(int i = 0; i < 4; i++){
    a.at(i) = n % 10;
    n /= 10;
  }
  cout << ( ( a.at(0) == a.at(1) and a.at(1) == a.at(2) )
         or ( a.at(1) == a.at(2) and a.at(2) == a.at(3) ) ? "Yes" : "No" ) << endl;
}

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

int main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  for (int i = 0; i < n; ++i) std::cin >> a[i];
  std::sort(a.begin(), a.end());
  a.resize(std::unique(a.begin(), a.end()) - a.begin());
  int m = n - a.size();
  std::cout << a.size() - (m & 1) << "\n";
  return 0;
}


Measured memory_bytes: 640
class PrimeFactor():

    def __init__(self, n):
        """
        エラトステネス　O(N loglog N)
        """
        self.n = n
        self.table = list(range(n+1))       # 最小素因数のリスト
        self.table[2::2] = [2]*(n//2)
        for p in range(3, int(n**0.5) + 2, 2):
            if self.table[p] == p:
                for q in range(p * p, n + 1, 2 * p):
                    if self.table[q] == q:
                        self.table[q] = p

    def is_prime(self, x):
        """ 素数判定　O(1) """
        if x < 2:
            return False
        return self.table[x] == x

    def prime_factors(self, x):
        """ 素因数分解 O(logN)  (試し割りだとO(sqrt(N))) """
        res = []
        if x < 2:
            return res
        while self.table[x] != 1:
            res.append(self.table[x])
            x //= self.table[x]
        return res

    def prime_counter(self, x):
        """ 素因数分解（個数のリスト） O(logN) """
        res = dict()
        if x < 2:
            return res
        while self.table[x] != 1:
            res[self.table[x]] = res.get(self.table[x], 0) + 1
            x //= self.table[x]
        return res

#################################################################
N = int(input())
P = PrimeFactor(N)
Q = dict()
for i in range(1,N+1):
    for key, value in P.prime_counter(i).items():
        Q[key] = Q.get(key,0) + value
a, b, c, d, e = 0, 0, 0, 0, 0
for value in Q.values():
    if value >= 2: a += 1
    if value >= 4: b += 1
    if value >= 24: c += 1
    if value >= 14: d += 1
    if value >= 74: e += 1
print(b*(b-1)//2*(a-2) + c*(a-1) + d*(b-1) + e)

Measured memory_bytes: 62824
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define Rep(i, s, n) for (int i = (int)s; i < (int)n; i++)
typedef long long ll;

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

    int k, x;
    cin >> k >> x;

    Rep (i, x-k+1,x+k) {
        printf("%d ", i);
    }
    printf("\n");
}

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

string index[] = {
	"11010", "11011",
	"11100", "11101",
	"11110", "11111"
};

string code(char c){
	int i = (int)c - 'A';
	if(i >= 0 && i < 26){
		string s;
		for(int j = 16; j >= 1; j = j / 2){
			if(i / j){
				i = i - j;
				s.push_back('1');
			}else{
				s.push_back('0');
			}
		}
		return s;
	}else{
		if(c == ' ') return index[0];
		if(c == '.') return index[1];
		if(c == ',') return index[2];
		if(c == '-') return index[3];
		if(c == '\'') return index[4];
		if(c == '?') return index[5];
	}
}

int main(){
	const string nums[] = {
		"101", "000000",
		"000011", "10010001",
		"010001", "000001",
		"100101", "10011010",
		"0101", "0001",
		"110", "01001", "10011011",
		"010000", "0111",
		"10011000", "0110",
		"00100", "10011001",
		"10011110", "00101",
		"111", "10011111",
		"1000", "00110",
		"00111", "10011100",
		"10011101", "000010",
		"10010010", "10010011",
		"10010000"
	};

	const char chs[] = {
		' ', '\'', ',',
		'-', '.', '?',
		'A', 'B', 'C',
		'D', 'E', 'F', 'G',
		'H', 'I', 'J', 'K',
		'L', 'M', 'N', 'O',
		'P', 'Q', 'R', 'S',
		'T', 'U', 'V', 'W',
		'X', 'Y', 'Z'
	};
	const string z = "0000";

	string s;
	while(getline(cin, s)){
		string v;
		for(string::iterator iter = s.begin();
			iter != s.end(); iter++)
		{
			v += code(*iter);
		}
		string::iterator iter = v.begin();
		string::iterator iter2 = iter;
		while(iter != v.end()){
			if(search(z.begin(), z.end(), iter, v.end()) != z.end()) break;
			int i = 0;
			string s2(iter, iter2);
			while(s2 != nums[i]){
				i++;
				if(i == 32) break;
			}
			if(i == 32) iter2++;
			else{
				iter = iter2;
				cout << chs[i];
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 904
/* ****mittal**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define jell        998244353
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define DEC(N)  cout << std::fixed; cout << setprecision(N);
using namespace std;
ll add(ll x,ll y)
{
return (x%hell+y%hell)%hell;
}
ll mul(ll x,ll y)
{
return ((x%hell)*(y%hell))%hell;
}
ll sub(ll x,ll y)
{
return (x-y+hell)%hell;
}
#define N  100005
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;;
    for(int ok=1;ok<=t;ok++)
    {
      ll n;
      cin>>n;
      ll sum=0;
      for(int i=1;i<=n;i++)
      {
        
        if(i%3!=0&&i%5!=0)
            sum+=i;
            
      }  
      cout<<sum;
     
    }
    return 0;
}

Measured memory_bytes: 3608
import sys
# sys.stdin = open('input.txt')

def ispPlindrome(s):
    if len(s) <= 1:
        return True
    else:
        return s[0] == s[-1] and ispPlindrome(s[1:-1])

s = input()
n = len(s)

if ispPlindrome(s) and ispPlindrome(s[:(n-1)//2]) and ispPlindrome(s[(n+3)//2-1:n]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
n = int(input())
a = list(map(int,input().split()))
b = list(set(a))

if n%3 == 0:
    if len(b) == 1:
        if a[0] == 0:
            print('Yes')
        else:
            print('No')
    elif len(b) == 2:
        if a.count(0) == n//3:
            print('Yes')
        else:
            print('No')
    elif len(b) == 3:
        if b[0]^b[1] == b[2]:
            if a.count(b[0]) == a.count(b[1]) == a.count(b[2]):
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')
elif n%3 == 1:
    if b == [0]:
        print('Yes')
    else:
        print('No')
else:
    if b==[0]:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 60784
t = gets.to_i
list = {}
t.times do 
  name = gets.chomp
  if list.has_key?("#{name}")
    list[name.to_s] += 1
  else
    list.store("#{name}", 1)
  end
end
max =  list.max{ |x, y| x[1] <=> y[1] }
result = []
list.each{ |key, value|
  result << key if value == max[1]
}
puts result.sort

Measured memory_bytes: 34072
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

def foo(y):
    ans = 0
    while y>0:
        z = y
        sm = 0
        for i in range(20):
            if (1<<i)&z != 0:
                sm += 1
                z -= 1<<i
                if z==0:
                    break
        y = y%sm
        ans += 1
    #ddprint(f"foo {y=} {ans=}")
    return ans

n = inn()
x = ins()
m = list(x).count('1')
xn = int(x,2)
xremm = xn%(m-1) if m>1 else 0
xremp = xn%(m+1)
iremm = [0]*n
iremp = [0]*n
if m>1:
    iremm[0] = 1
iremp[0] = 1
for i in range(1,n):
    iremp[i] = (2*iremp[i-1])%(m+1)
    if m>1:
        iremm[i] = (2*iremm[i-1])%(m-1)

#ddprint(f"{m=} {xn=} {xremm=} {xremp=}")
#ddprint(iremm)
#ddprint(iremp)

for i in range(n):
    if x[i]=='1':
        if m==1:
            print(0)
        else:
            y = (xremm-iremm[n-1-i])%(m-1)
            print(foo(y)+1)
    else:
        y = (xremp+iremp[n-1-i])%(m+1)
        #ddprint(f"xrp {xremp} ir {iremp[n-1-i]} m+1 {m+1} {y=}")
        print(foo(y)+1)


Measured memory_bytes: 95688
#include<stdio.h>
int main(void)
{
	while(1){
	int n,i,j;
	int a[11]={0},b;
	scanf("%d",&n);
	if(n==0)break;
	for(i=0;i<n;i++){
		scanf("%d",&b);
		a[b]++;
	}
	for(i=0;i<=9;i++){
		if(a[i]==0){
			printf("-\n");
		}
		else{
			for(j=0;j<a[i];j++){
				printf("*");
			}
			printf("\n");
		}
	}
	}
}


Measured memory_bytes: 1920
#include<map>
#include<string>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<set>
#include<vector>
#include<cmath>
#include<queue>
using namespace std;


int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	int a, b;
	scanf("%d %d", &a, &b);
	if (b == 100)b = 101;
	for (int i = 0; i < a; i++)
		b *= 100;
	
	printf("%d\n", b);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std; using P=pair<int,int>; using ll=long long;
const ll m = 1e9+7;
int gcd(ll a, ll b) {if (b==0) return a; else return gcd(b, a%b);}

int main() {
  int n; string s; cin>>n>>s;
  ll r=0,g=0,b=0; for(int i=0;i<n;i++) r+=s[i]=='R', g+=s[i]=='G', b+=s[i]=='B';
  ll lf=0;
  for(int i=0;i<n-1;i++) {
    for(int j=i+1;j<n;j++) {
      int k=j+(j-i);
      if (k >= n) continue;
      if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) lf++;
    }
  }
  cout<<r*g*b-lf<<endl;
}

Measured memory_bytes: 3636
import sys
n=int(input())
S=[]
for i in range(n):
  s=list(input())
  S+=[s]
ANS=[]
if n==1:
  ANS=S[0]
  ANS.sort()
  ans="".join(ANS) 
  print(ans)
  sys.exit()
for k in range(len(S[0])):
  if S[0][k] in S[1]:
    ANS+=[S[0][k]]
    S[1].remove(S[0][k])
rem=[]
for i in ANS:
  flag=0
  for k in range(2,n):
    if i in S[k]:
      S[k].remove(i)
    elif flag!=1:
      rem+=[i]
      flag=1
for i in rem:
  ANS.remove(i)
ANS.sort()      
ans="".join(ANS)  
print(ans)

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

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

int main(){

    int N,i,j,x[100000];
    int count = 0;

    scanf("%d\n",&N);

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


    qsort(x,N, sizeof(int), asc);


        count = x[N/2]-x[N/2-1];
    

    printf("%d\n",count);
    return 0;


}


Measured memory_bytes: 892
from collections import Counter

n, m = map(int, input().split())
graph = []
for _ in range(m):
    graph.extend([int(i) for i in input().split()])
    
cnt = Counter(graph)
ans = 'YES'
for i in cnt.values():
    if i % 2 != 0:
        ans = 'NO'
        break
print(ans)    

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


using namespace std;
using ll = long long;

#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define trav(a, x) for(auto& a: x)

int main () {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    ll a; cin >> a;
    cout << a + a*a + a*a*a << '\n';

    return 0;
}



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

using namespace std;

using ll = long long;
using ld = long double;

const ld pi = 3.141592653589793;

int n, a[200005], s[200005];

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

  int sum = 0;
  for (int i = 0; i < (n - 1); i += 2) {
    // a[i] ^ a[i + 1] == 0 ^ s[i] ^ s[i + 1] == s[i] ^ s[i + 1]
    sum = sum ^ a[i] ^ a[i + 1];
  }

  for (int i = 0; i < n; i++) {
    cout << (sum ^ a[i]) << endl;
  }
}

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

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define F first
#define S second
#define int long double
int V;

int32_t main() {
	cout << setprecision(8) << fixed;
	cin >> V;
	V /= 3.0;
	cout << V * V * V;
	return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        string alphabet = "abcdefghijklmnopqrstuvwxyz";
        char[] alphabetChar = alphabet.ToCharArray();

        string input = Console.ReadLine();
        char[] inputChar = input.ToCharArray();

        bool none = true;

        for(int i=0; i<alphabetChar.Length; i++){
            if(!inputChar.Contains(alphabetChar[i])){
                Console.WriteLine(alphabetChar[i]);
                none = false;
                break;
            }
        }

        if(none==true){
            Console.WriteLine("None");
        }
    }
}

Measured memory_bytes: 13536
INF = 10**19

def dijkstra_back(s,t,n,w,cost):
    prev = [s] * n 
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
        
        for i in range(n):
            if d[i] > d[v] + cost[v][i]: 
                d[i] = d[v] + cost[v][i]
                prev[i] = v
    path = [t]
    while prev[t] != s:
        path.append(prev[t])
        prev[t] = prev[prev[t]]
    path.append(s)
    path = path[::-1]
    return path

N,M = map(int, input().split())

cost = [[float("inf") for i in range(N)] for j in range(N)]
edges = set()
for i in range(M):
    a,b,c = map(int, input().split())
    a -= 1
    b -= 1
    cost[a][b] = c
    cost[b][a] = c
    edges.add(min(a,b)*10**5 + max(a,b))

for i in range(N):
    for j in range(i+1,N):
        d = dijkstra_back(i,j,N,M,cost)
        for k in range(len(d)-1):
            a_ = min(d[k],d[k+1])
            b_ = max(d[k],d[k+1])
            X = a_*10**5+b_
            if X in edges:
                edges.remove(X)
print(len(edges))



Measured memory_bytes: 50108
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define foi(i,n) for(int i = 0 ; i< n ;i++)
#define mod 1000000007

string inp[1001];
int dp[1001][1001];
int solve(int i,int j,int h,int w){
    if(i == h-1 && j == w-1) return 1;
    if(i >= h || j >= w ) return 0;

    if(dp[i][j]!=-1) return dp[i][j];
    if(inp[i][j]=='#') return dp[i][j] = 0;
    else return dp[i][j] = (solve(i+1,j,h,w)%mod + solve(i,j+1,h,w)%mod)%mod;

}

/*
class graph{
public:
    int V,E;
    map<int,list<int>> adj;
    vector<pair<int,int>> count;
    void init(int v,int e){
        v = V; e = E;
        foi(i,e){
            int u,v;
            cin >> u >> v;
            adj[u].pb(v);
            adj[v].pb(u);
        }
    }

    int dfsHelper(int node,unordered_map<int,bool> &visited,int color,int *clr){ // 0 -> black y 1 -> white
            visited[node] = 1;
            clr[node] = color;
            int answer =0 ;
            for(auto y : adj[node]){
                if(visited[y] == false){
                    answer+= dfsHelper(y,visited,1,clr);
                    if(color == 1) answer += dfsHelper(y,visited,0,clr);
                }
                else{
                    if(color == 0 && clk[y] == 0) return 0;

                }

            }
            return answer;
    }

    void dfs(){
        unordered_map<int,bool> visited;
        int answer = 0;
        int *clr = new int[V+1];
        for(int i = 1 ; i <= V ; i++){
            if(visited[i] == false){

                int a = 0; int b = 0;
                unordered_map<int,bool> tempV;
                a +=  dfsHelper(i,tempV,0,clr);
                if(a!=0) dfsHelper(i,visited,0,clr);
                tempV.clear();
                b += dfsHelper(i,tempV,1,clr);
                if(a == 0 && b!=0) return temp
            }
        }
        int answer = 1;
        for(auto y : count){
            answer  = (answer*2)%mod;
        }
        cout << answer ;
    }



};
*/


int32_t main(){
    int h,w;
    foi(i,1000){
        foi(j,1000) dp[i][j] = -1;
    }
    cin >> h >> w;
    foi(i,h){
        cin >> inp[i];
    }
    //foi(i,h) cout << inp[i] << endl;
    cout << solve(0,0,h,w);
}


Measured memory_bytes: 9216
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine

getIntList = readIntList <$> BS.getLine

main = do
  [n, a, b] <- getIntList
  print $ minimum [a * n, b]


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

int main(){
    string S;
    cin>>S;
    int sum=0;
    for(int i=0;i<S.size()-1;i++){
        if(S.at(i)==S.at(i+1) && S.at(i)=='0'){
            S.at(i+1)='1';
            sum++;
        }
        else if((S.at(i)==S.at(i+1) && S.at(i)=='1')){
               S.at(i+1)='0';
               sum++;
        }
        
    }
    cout<<sum<<endl;

}

Measured memory_bytes: 512
import java.util.*;
public class Main{
	static ArrayList<Edge>[] map;
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		map=new ArrayList[n];
		for(int i=0; i<n; i++){
			map[i]=new ArrayList<>();
		}
		for(int i=1; i<n; i++){
			int a=sc.nextInt()-1;
			int b=sc.nextInt()-1;
			map[a].add(new Edge(b,i));
			map[b].add(new Edge(a,i));
		}
		
		int m=sc.nextInt();
		long[] s=new long[m];
		for(int i=0; i<m; i++){
			int u=sc.nextInt()-1;
			int v=sc.nextInt()-1;
			s[i]=dfs(u,v,-1);
		}
		long ans=0;
		for(int i=0; i<1<<m; i++){
			long tmp=0;
			for(int j=0; j<m; j++){
				if((i>>j & 1)==1){
					tmp|=s[j];
				}
			}
			long pm=Long.bitCount(tmp);
			if(Integer.bitCount(i)%2==0){
				ans+=1L<<(n-1-pm);
			}else{
				ans-=1L<<(n-1-pm);
			}
		}
		System.out.println(ans);
	}
	static long dfs(int now,int goal,int front){
		for(Edge i:map[now]){
			if(i.to==front){
				continue;
			}
			long tmp=dfs(i.to,goal,now);
			if(tmp!=-1){
				return tmp+(1L<<i.id);
			}
		}
		if(now==goal){
			return 0;
		}else{
			return -1;
		}
	}
	static class Edge{
		int to,id;
		Edge(int to,int id){
			this.to=to;
			this.id=id;
		}
	}
}


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

using ll = long long;
using pp = pair<ll,ll>;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end() //昇順
#define enb(a) a.rbegin(),a.rend() //降順
#define pb(a,b) a.push_back(b)
//fixed << setprecision(20)

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

		k -= d[i];
		if(k <= 0)break;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1024
n = gets.to_i

def pair(x)
  a = x%10
  while x!=0
    b = x
    x /= 10
  end
  return [a, b]
end

freq = {}

(1..n).each do |i|
  p = pair(i)
  freq[p] = 0 if !freq.has_key?(p)
  freq[p] += 1
end

ans = 0

(1..n).each do |i|
  p = pair(i)
  q = [p[1], p[0]]
  ans += freq[q] if freq.has_key?(q)
end

puts ans

Measured memory_bytes: 1788
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    int res = 0;
    for(int i = 1; i <= n; i ++)
    {
        for(int j = 1; j <= n / i; j ++)
        {
            if(i * j < n) res ++;
        }
    }
    printf("%d",res);
}

Measured memory_bytes: 3224
//パチンコ
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;


int N = 26;
int D;

vector<int> c(N+1);
vector<vector<int>> s;
vector<int> t;

ll now_score = 0;

ll greedy(){
    vector<int> last(N+1, 0);
    ll greedy_score=0;
    for(int d = 1; d <= D; d++){
        ll max_score = -1e9;
        vector<int> max_last;
        for(int n = 1; n <= N; n++){
            ll tmp_score = 0;
            vector<int> tmp_last(N+1);
            tmp_last = last;
            
            tmp_score +=  s[d][n];
            tmp_last[n] = d;
     
            int penalty = 0;
            for(int i = 1; i <= N; i++){
                penalty += c[i]*(d-tmp_last[i]);    
                
            }
            
            tmp_score -= penalty;

            if(max_score < tmp_score){
                max_score = tmp_score;
                max_last = tmp_last;
                t[d] = n;
            }                    
            
        }
        
        last = max_last;
        greedy_score += max_score;
    }

    return greedy_score;
}


ll scoring(){
    vector<int> last(N+1, 0);
    ll score = 0;
    for(int d = 1; d <= D; d++){

        score += s[d][t[d]];
        last[t[d]] = d;

        int penalty = 0;
        for(int i = 1; i <= N; i++){
            penalty += c[i]*(d-last[i]);    
        }
        
        score -= penalty;            
    }
    return score;
}


void exchange(int d, int x){
    swap(t[d], t[d+x]);

    ll swap_score = scoring();
    
    if(now_score >= swap_score){
        swap(t[d], t[d+x]);
    }else{
        now_score = swap_score;
    }

}

void pachinko(){
    srand((unsigned) time(NULL)); /* Use Mersenne Twister */
    for(int i=1; i<=D; i++){
        int pre = t[i];
        t[i] = rand()%26+1;

        ll pachi_score = scoring();
        if(now_score >= pachi_score){
            t[i] = pre;
        }else{
            now_score = pachi_score;
        }        
    }

}

int main(){
    cin>> D;

    s.resize(D+1);
    for(int i=0; i<=D; i++){
        s[i].resize(N+1);
    }
    t.resize(D+1);

    for(int i=1; i<=N; i++){
        cin>>c[i];
    }
 
    for(int i=1; i<=D; i++){
        for(int j=1; j<=N; j++){
            cin>>s[i][j];
        }
    }
    for(int i=1; i<=D; i++){
        cin>>t[i];
    }

    now_score = greedy();

    //乱数パチンコ
    pachinko();
    //解交換
    for(int x=1; x<D; x++){
        for(int d=1; d<=D-x; d++){
            exchange(d, x);
        }
    }
    //乱数パチンコ
    pachinko();    
    //解交換
    for(int x=1; x<D; x++){
        for(int d=1; d<=D-x; d++){
            exchange(d, x);
        }
    }    
    for(int i=1; i<=D; i++){           
        cout<<t[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			(3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
template<class T> void chmax(T &a, const T &b){if(a<b)a=b;}
template<class T> void chmin(T &a, const T &b){if(a>b)a=b;}
void YN(bool b){cout<<(b?"YES":"NO")<<endl;}
void Yn(bool b){cout<<(b?"Yes":"No")<<endl;}
void yn(bool b){cout<<(b?"yes":"no")<<endl;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,h,w;
	cin>>n>>h>>w;
	cout<<((n-h+1)*(n-w+1))<<endl;
}

 

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;


int main() {

    ll H;
    cin >> H;

    ll ans = 1;

    for(ll i = H; i >= 1; i /= 2){
        ans *= 2;
        //cout << i << endl;
    }

    cout << ans - 1 << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector<int> v,v2[10];
int main()
{
	int n,m;
	cin>>n>>m;
	int k[10],s[10][10],p[10];
	for(int i=0;i<m;i++)
	{
		cin>>k[i];
		v.push_back(k[i]);
		for(int j=0;j<k[i];j++)
		{
			cin>>s[i][j];
			v2[i].push_back(s[i][j]);
		}
	}
	for(int i=0;i<m;i++)
	cin>>p[i];
	int ans=0;
	for(int i=0;i<(1<<n);i++)
	{
		int j=0;
		for(;j<m;j++)
		{
			int su=0;
			for(int k1=0;k1<v[j];k1++)
			{
				if(i&(1<<(v2[j][k1]-1)))
				su+=1;
			}
			if(su%2==p[j]%2)
			{
				continue;
			}
			j--;
			break;
		}
		if(j==m)
		ans++;
	}
	cout<<ans;
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
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 INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n;
    cin >> n;
    vector<int> a(n), sa(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sa[i] = a[i];
    }
    sort(rall(sa));

    for (int i = 0; i < n; ++i) {
        if (a[i] == sa[0]) cout << sa[1] << endl;
        else cout << sa[0] << endl;
    }
}

Measured memory_bytes: 4792
/*
 * Ring.cpp
 *
 *  Created on: 2014/07/27
 *      Author: WanWan1985
 */
#include <iostream>
#include <string>
using namespace std;

int main(void) {


	string strS;
	getline(cin, strS);
	strS += strS;

	string strP;
	getline(cin, strP);

	if (strS.find(strP) == string::npos) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}

	return 0;
}

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

void solve(long long N, std::vector<long long> L){
    sort(L.begin(), L.end());
    ll res = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i + 1; j < N; j++) {
        for (int k = j + 1; k < N; k++) {
	    ll a = L[i];
	    ll b = L[j];
	    ll c = L[k];
            if ((a < (b + c)) and (b < (c + a)) and (c < (a + b))) {
		res++;
            }
        }
      }
    }
    cout << res << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> L(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&L[i]);
    }
    solve(N, std::move(L));
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{int max=0;int c=0;int m;
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++)
	{if(s[i]=='A'){
		m=i;
		if(c>0)
		break;
		for(m;m<s.length();m++){
			if(s[m]=='Z'){c++;
			if(c>max){
				max=c;
			}
			}
			else
			c++;
		}
	}
		
		}
		cout<<max;
		return 0;		
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	private long a = 1;

	public static void main(String[] args) {
		new Main().run();
	}
	
	private void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for (int i = n; i > 0; i--) {
			a *= i;
		}
		System.out.println(a);
	}
	
	private void debug() {
		System.out.println();
	}

}

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

typedef long long int ll;

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    
    ll byC = (b / c) - ((a - 1) / c);
    ll byD = (b / d) - ((a - 1) / d);
    ll lcm = (c / (ll) __gcd(c, d)) * d;
    ll byBoth = (b / lcm) - ((a - 1) / lcm);
    
    cout << b - a + 1 - (byC + byD - byBoth) << "\n";

    return 0;
}


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

int main() {

  int n,i,j,k,sum,t;
  int c[12],count = 0;
  char s[101],kara;

  while(1) {


    //    scanf("%d %c" ,&n,&kara);
    scanf("%d" ,&n);

    if(n == 0) break;

    for(i=0;i<n+1;i++) c[i] = 0;

  scanf("%s",s);

    j = 1;
    sum = 0;



    for(i=0;i<100; i++) {

      if(j == n+1){
	j = 1;
      }

      if(s[i] == 'M') {
	c[j] += 1;
      } else if(s[i] == 'S') {
	sum += c[j]+1;
	c[j] = 0;
      } else if(s[i] == 'L'){
	c[j] += sum +1;
	sum = 0;
      }
      count++;
      //printf("s = %c c[%d] = %d  sum = %d count = %d\n",s[i],j,c[j],sum,count);
   
      j++;
    }

    for(j=1;j<=n;j++) {
    for(i=1;i<=n;i++) {
      
      if(c[j] < c[i]){
	t = c[j];
	c[j] = c[i];
	c[i] = t;
      }
    }
    }

   

    for(i=1;i<=n;i++){
      printf("%d ",c[i]);
    }

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

  }

  return 0;

}
     

Measured memory_bytes: 604
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")
 
bool isprime(int p) {
  if (p==1) return false;
  FOR(i,2,p) {
    if (p%i==0) return false;
  }
  return true;
}

int main(){
  int n,m;
  long a,b,c,dp[1001][1001][8];
  cin >> n >> m;
  vector<long> x,y,z;
  REP(i,n){
    cin >> a >> b >> c;
    x.push_back(a);
    y.push_back(b);
    z.push_back(c);
  }
  REP(j,n){
    REP(i,8){
      dp[j][0][i]=0;
    }
  }
  REP1(i,m){
    dp[i-1][i][0]=0;
    dp[i-1][i][1]=0;
    dp[i-1][i][2]=0;
    dp[i-1][i][3]=0;
    dp[i-1][i][4]=0;
    dp[i-1][i][5]=0;
    dp[i-1][i][6]=0;
    dp[i-1][i][7]=0;
    REP(j,i){
    dp[i-1][i][0]+=x[j]+y[j]+z[j];
    dp[i-1][i][1]+=x[j]+y[j]-z[j];
    dp[i-1][i][2]+=x[j]-y[j]+z[j];
    dp[i-1][i][3]+=x[j]-y[j]-z[j];
    dp[i-1][i][4]+=-x[j]+y[j]+z[j];
    dp[i-1][i][5]+=-x[j]+y[j]-z[j];
    dp[i-1][i][6]+=-x[j]-y[j]+z[j];
    dp[i-1][i][7]+=-x[j]-y[j]-z[j];
    }
    //cout << "i:"<< i << " j:" << i-1 << " dp:" << dp[i-1][i][0] << endl;
    FOR(j,i,n){
      dp[j][i][0]=max(dp[j-1][i][0],dp[j-1][i-1][0]+x[j]+y[j]+z[j]);
      //cout << "i:"<< i << " j:" << j << " dp:" << dp[j][i][0] << endl;
      dp[j][i][1]=max(dp[j-1][i][1],dp[j-1][i-1][1]+x[j]+y[j]-z[j]);
      dp[j][i][2]=max(dp[j-1][i][2],dp[j-1][i-1][2]+x[j]-y[j]+z[j]);
      dp[j][i][3]=max(dp[j-1][i][3],dp[j-1][i-1][3]+x[j]-y[j]-z[j]);
      dp[j][i][4]=max(dp[j-1][i][4],dp[j-1][i-1][4]-x[j]+y[j]+z[j]);
      dp[j][i][5]=max(dp[j-1][i][5],dp[j-1][i-1][5]-x[j]+y[j]-z[j]);
      dp[j][i][6]=max(dp[j-1][i][6],dp[j-1][i-1][6]-x[j]-y[j]+z[j]);
      dp[j][i][7]=max(dp[j-1][i][7],dp[j-1][i-1][7]-x[j]-y[j]-z[j]);
    }
  }
  cout << max({dp[n-1][m][0],dp[n-1][m][1],dp[n-1][m][2],dp[n-1][m][3],dp[n-1][m][4],dp[n-1][m][5],dp[n-1][m][6],dp[n-1][m][7]});
  return 0;
}

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

int main(){
    int n,t,c,t1;
    cin>>n>>t;
    int ans=2000;
    for(int i=0;i<n;i++){
        cin>>c>>t1;
        if(t1<=t){        
            if(c<ans){
                ans=c;
            }
        }
    }
    if(ans==2000)cout<<"TLE"<<endl;
    else cout<<ans<<endl;
    return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) cin >> vec.at(i);

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

  int ans = 0;
  for (int i = 0; i < K; i++) ans += vec.at(i);

  cout << ans << endl;
}

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

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    i32 N;
    cin >> N;
    Vec<i64> a(N);
    for (i32 i = 0; i < N; i++) cin >> a[i];
    i64 c = a[0];
    for (i32 i = 1; i < N; i++) c ^= a[i];
    for (i32 i = 0; i < N; i++) {
        cout << (a[i] ^ c );
        if (i != N - 1) cout << " ";
    }
    cout << endl;

}


Measured memory_bytes: 4716
(defun ev (x y z)
  (+ (expt x 2)
     (expt y 2)
     (expt z 2)
     (* x y)
     (* y z)
     (* z x)))

(defun p (x y z)
  (cond ((= x y z) 1)
        ((and (= y z) (/= x y)) 3)
        ((and (= x y) (/= z x)) 3)
        (t 6)))

(defun f (n)
  (let ((c (make-array (list (1+ n)) :initial-element 0)))
    (loop :named x-loop
          :for x :from 1 :to 99
          :do (loop :named y-loop
                    :for y :from 1 :to 99
                    :do (loop :named z-loop
                              :for z :from 1 :to 99
                              :if (<= (ev x y z) n)
                              :do (incf (aref c (ev x y z))))))
    c))

(let* ((n (read))
       (ans (f n)))
  (loop :for x :from 1 :to n
        :do (format t "~A~%" (aref ans x))))


Measured memory_bytes: 24520
#include <stdio.h>

int main(){
  int n;
  long ans1=0;
  long ans2=0;
  scanf("%d",&n);
  
  int a[n+2],b[n+1];
  for(int i=1;i<=n+1;i++){
    scanf("%d",&a[i]);
  }
  for(int i=1;i<=n;i++){
    scanf("%d",&b[i]);
  }
  
  for(int i=1;i<=n;i++){
    if(a[i]<b[i]){
      if(a[i]+a[i+1]<=b[i]){
        ans1=ans1+a[i]+a[i+1];
        a[i+1]=0;
      }else{
        ans1=ans1+b[i];
        a[i+1]=a[i+1]-(b[i]-a[i]);
      }
    }else{
      ans1=ans1+b[i];
    }
  }
  
  for(int i=n;i>=1;i--){
    if(a[i+1]<b[i]){
      if(a[i+1]+a[i]<=b[i]){
        ans2=ans2+a[i]+a[i+1];
        a[i]=0;
      }else{
        ans2=ans2+b[i];
        a[i]=a[i]+a[i+1]-b[i];
      }
    }else{
      ans2=ans2+b[i];
    }
  }
  
  if(ans2<ans1){
    printf("%ld",ans1);
  }else{
    printf("%ld",ans2);
  }
  return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using P = pair<ll,ll>;

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main() {
    ll N,M;
    cin >>N >>M;
    UnionFind uf = UnionFind(N);
    vector<ll> a(N);
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    for(int i=0;i<M;i++){
        int x,y;
        cin >> x >>y;
        uf.unite(x,y);
    }
    vector<priority_queue<ll,vector<ll>,greater<ll>>> pq(N);
    vector<P> children(N);
    for(int i=0;i<N;i++){
        children[uf.find(i)] = P(uf.size(i),uf.find(i));
        pq[uf.find(i)].push(a[i]);
    }
    sort(children.rbegin(),children.rend());
    priority_queue<ll,vector<ll>,greater<ll>> allPq;
    while(!pq[children[0].second].empty()){
        ll A =pq[children[0].second].top();
        pq[children[0].second].pop();
        allPq.push(A);
    }
    ll ans =0;
    for(int i=1;i<N;i++){
        
        if(children[i].first ==0){
            break;
        }
        if(allPq.empty()){
            cout << "Impossible" << endl;
            return 0;
        }
        ll t = children[i].second;
        ans += allPq.top()+pq[t].top();
        allPq.pop();pq[t].pop();
        while(!pq[t].empty()){
        ll A =pq[t].top();
        pq[t].pop();
        allPq.push(A);
    }


    }
    cout << ans << endl;





    return 0;
}

Measured memory_bytes: 12240
#!/usr/bin/env python3

H,W = [int(x) for x in input().split(" ")]

if H == 1 or W == 1:
    ans = 1
elif H % 2 == 0 or W % 2 == 0:
    ans = (H * W) // 2
else:
    ans = (H - 1) * W // 2 + (W + 1) //2

print(ans)


Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef long long ll;
const int maxN = 2e3 + 10;
const ll inf = 1e18;

int n;
pair<ll, int> a[maxN];
ll dp[maxN][maxN];

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//  freopen("abc.inp", "r", stdin); freopen("abc.out", "w", stdout);
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i].F;
    a[i].S = i;
  }
  sort(a+1, a+n+1, greater<pair<ll,int> >());

  for (int i = 0; i < maxN; ++i)
    for (int j = 0; j < maxN; ++j)
      dp[i][j] = -inf;

  dp[0][0] = 0;
  ll ans = 0;
  for (int i = 0; i <= n; ++i)
  for (int j = 0; i + j <= n; ++j) {
    int k = i + j;
    if (k == n) {
      ans = max(ans, dp[i][j]);
      continue;
    }
    dp[i+1][j] = max(dp[i+1][j], dp[i][j] + a[k+1].F * abs(a[k+1].S - (i+1)) );
    dp[i][j+1] = max(dp[i][j+1], dp[i][j] + a[k+1].F * abs((n-j) - a[k+1].S) );
  }

  cout << ans;
  return 0;
}


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

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

    map<string, int> m;

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

    int maxnum = 0;
    for( auto i = m.begin(); i != m.end() ; ++i ) {
      if(maxnum < i->second){
          maxnum = i->second;
      }
    }
    for( auto i = m.begin(); i != m.end() ; ++i ) {
        if(maxnum == i->second){
            cout << i->first << endl;
        }
    }    
}

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

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)

        {

            var xyz = Input3();
            Console.WriteLine(xyz[2] + " " + xyz[0] + " " + xyz[1]);
                





        }

       
        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }

        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }
    }
}


Measured memory_bytes: 13140
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] a = new int[n];
    int[] b = new int[n];
    for (int i=0;i<n;i++){
      a[i] = sc.nextInt();
      b[i] = sc.nextInt();
    }
    int[] c = new int[m];
    int[] d = new int[m];
    for (int i=0;i<m;i++){
      c[i] = sc.nextInt();
      d[i] = sc.nextInt();
    }
    sc.close();
    int ans;
    int length;
    int dlength;
    for (int i=0;i<n;i++){
      ans = 0;
      length = 1000000000;
      for (int j=0;j<m;j++){
        dlength = Math.abs(a[i]-c[j])+Math.abs(b[i]-d[j]);
        if (length > dlength){
          ans = j+1;
          length = dlength;
        }
      }
      System.out.println(ans);
    }
  }
}

Measured memory_bytes: 23892
#include <iostream>

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

        long q = N / K;

        long m;
        if (K % 2 == 0) {
                long r = (N + K / 2) / K;
                m = q * q * q + r * r * r;
        } else {
                m = q * q * q;
        }
        std::cout << m << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    vector<pair<char, ll>> vec;
    ll count = 0;
    char tmp = s.at(0);

    ll ans = 0;

    rep(i,n){
        if(tmp != s.at(i)){
            vec.push_back(make_pair(tmp,count));
            ans += (count - 1);
            tmp = s.at(i);
            count = 1;
        }else{
            count++;
        }
    }
    vec.push_back(make_pair(tmp,count));
    ans += (count - 1);

    /*
    rep(i,vec.size()){
        cout << vec[i].first << " " << vec[i].second << endl;
    }
    */

    if(k >= (vec.size() / 2)){
        cout << n - 1 << endl;
    }else{
        cout << ans + (2 * k) << endl;
    }
    

}

Measured memory_bytes: 2548