akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>

#define rep(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define rangeRep(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

int intervalX[1500];
int intervalY[1500];
int intervalsX[1500 * 1000];
int intervalsY[1500 * 1000];

class Solve {
public:
	Solve() {};
	~Solve() {};

	void solver() {
		int n, m;
		while (std::cin >> n >> m, n, m) {
			std::memset(intervalX, 0, sizeof(intervalX));
			std::memset(intervalY, 0, sizeof(intervalY));
			std::memset(intervalsX, 0, sizeof(intervalsX));
			std::memset(intervalsY, 0, sizeof(intervalsY));
			//input
			rep(i, n) {
				std::cin >> intervalX[i];
			}
			rep(i, m) {
				std::cin >> intervalY[i];
			}
			//All patterns enumeration
			int squares = 0;
			int edgeXNo = 0;
			int cnt = 0;
			int maxLen = 0;
			rep(i, n) {
				rep(j, n - i) {
					int len = 0;
					rangeRep(k, j, j + i + 1) {
						len += intervalX[k];
					}
					intervalsX[len]++;
					if (maxLen < len) maxLen = len;
					++cnt;
				}
			}
			rep(i, m) {
				edgeXNo = 0;
				rep(j, m - i) {
					int len = 0;
					rangeRep(k, j, j + i + 1) {
						len += intervalY[k];
					}
					intervalsY[len]++;
					if (maxLen < len) maxLen = len;
				}
			}
			rep(i, maxLen + 1) {
				squares += intervalsX[i] * intervalsY[i];
			}
			std::cout << squares << std::endl;
		}
	}
private:

};

int main() {
	Solve solve;
	solve.solver();
	return 0;
}

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

using namespace std;

int dp[100007][5], a[100007][5];

int main() {
	int n;
	cin >> n;
	for ( int i = 0; i < n; i++ ) {
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	}  
	dp[0][0] = a[0][0];
	dp[0][1] = a[0][1];
	dp[0][2] = a[0][2];
	for ( int i = 1; i < n; i++ ) {
		dp[i][0] = max( dp[i - 1][1], dp[i - 1][2] ) + a[i][0];
		dp[i][1] = max( dp[i - 1][0], dp[i - 1][2] ) + a[i][1];
		dp[i][2] = max( dp[i - 1][0], dp[i - 1][1] ) + a[i][2];  
	}
	cout << max( { dp[n - 1][0], dp[n - 1][1], dp[n - 1][2] } );
}

Measured memory_bytes: 4096
def func(amat, bmat, nm):
    for i in range(nm[0]):
        ans = 0
        for j in range(nm[1]):
            ans += amat[i][j] * bmat[j][0]
        print(ans)


if __name__ == '__main__':
    nm = input().split(' ')
    nm = [int(i) for i in nm]
    amat = [[0 for i in range(nm[1])] for j in range(nm[0])]
    bmat = [[0] for i in range(nm[1])]

    for i in range(nm[0]):
        a = input().split(' ')
        for j in range(nm[1]):
            amat[i][j] = int(a[j])

    for i in range(nm[1]):
        b = int(input())
        bmat[i][0] = b

    func(amat, bmat, nm)

Measured memory_bytes: 7904
/*
  Contest 090
  A - Diagonal String
  Rakesh Kumar --> 18/09/2020
 */

#include <bits/stdc++.h>

inline bool palindrome(const std::string& s) {
    int i = 0;
    int j = s.size() - 1;
    while (i < j) {
        if (s[i++] != s[j--])
            return false;
    }
    return true;
}

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

    int a = 0, b = 0;
    std::cin >> a >> b;

    int count = 0;
    for (int n = a; n <= b; ++n)
        if (palindrome(std::to_string(n)))
            ++count;
    std::cout << count << std::endl;

    return 0;
}


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

int main() {
  ll r, D, x0;
  cin >> r >> D >> x0;
  ll x1;
  for (int i = 0; i < 10; i++) {
    x1 = r * x0 - D;
    cout << x1 << endl;
    x0 = x1;
  }
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <boost/dynamic_bitset.hpp>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeindex>
#include <typeinfo>
#include <vector>

#define DEBUG(x) cout << #x << ": " << x << endl
#define INFILE() freopen("input.txt", "r", stdin)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define REPC(i, a) REP(i, 0, a)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)
#define RREPC(i, a) RREP(i, a, 0)
#define ALL(s) begin(s), end(s)
#define RALL(s) rbegin(s), rend(s)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_i = pair<ll, int>;
using i_ll = pair<int, ll>;
using d_i = pair<double, int>;
using ll_ll = pair<ll, ll>;
using d_d = pair<double, double>;

static constexpr ll LL_MOD = 1000000009;
static constexpr int I_MOD = 1000000007;
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr double PI = 3.14159265358979323846264338327950288;

static map<type_index, const char *const> scanType = {{typeid(int), "%d"},
                                                      {typeid(ll), "%lld"},
                                                      {typeid(double), "%lf"},
                                                      {typeid(char), "%c"}};

template <class T> static void scan(vector<T> &v);
static void scan(vector<string> &v, bool isWord = true);
static boost::dynamic_bitset<> scan(char trueValue = 'o');

int main(int argc, char *argv[]) {
  // INFILE();
  auto b = scan('g');
  ll gCount = b.count();
  ll pCount = b.size() - gCount;

  if (gCount == pCount) {
    cout << "0\n";
    return 0;
  }

  cout << (gCount - pCount) / 2 << "\n";
  return 0;
}

template <class T> static void scan(vector<T> &v) {
  auto tFormat = scanType[typeid(T)];
  for (T &n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string> &v, bool isWord) {
  if (isWord) {
    for (auto &n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

static boost::dynamic_bitset<> scan(char trueValue) {
  string s;
  getline(cin, s);

  if (s.size() == 0) {
    getline(cin, s);
  }

  for_each(begin(s), end(s),
           [trueValue](char &c) { c = (c == trueValue) ? '1' : '0'; });
  return boost::dynamic_bitset<>(string(rbegin(s), rend(s)));
}


Measured memory_bytes: 512
package main

import "fmt"

func main() {
	var cast string
	var weather string
	fmt.Scan(&cast)
	fmt.Scan(&weather)

	ans := 0
	if cast[0] == weather[0] {
		ans++
	}
	if cast[1] == weather[1] {
		ans++
	}
	if cast[2] == weather[2] {
		ans++
	}
	fmt.Println(ans)
}


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

int main(){
    int N;
    cin >> N;
    vector<int> H(N);
    for(int i = 0;i < N;i++) cin >> H[i];
    int ans = 0;
    for(int i = 0;i < N;i++){
        int value = *max_element(H.begin(),H.begin() + i);
        if(H[i] >= value) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define PI acos(-1.0)
typedef long long ll;
const int INF=0x3f3f3f3f;
int d[8][2]={{-1,0},{0,-1},{0,1},{1,0},{1,1},{-1,-1},{-1,1},{1,-1}};
int main()
{
    int n,m,num,a,b;
    long long sum=0;
    scanf("%d%d",&n,&m);
    sum=((n-m)*100+m*1900)*pow(2,m);
    cout<<sum<<endl;
    return 0;
}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int[] h = new int[n];
		Arrays.setAll(h, i -> sc.nextInt());
		Arrays.sort(h);
		
		int minH = Integer.MAX_VALUE;
		for (int i = 0; i < n - k + 1; i++) {
			int dif = h[i + k - 1] - h[i];
			minH = Math.min(minH, dif);
		}
		
		System.out.println(minH);
		
	}
	
}


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

int main() {
  int H,W;
  cin >> H >> W;

  int t[H+2][W+2];
  for(int i=0;i<H+2;i++)for(int j=0;j<W+2;j++) t[i][j]=1;

  for(int i=1;i<=H;i++){
    string s; cin >> s;
    for(int j=1;j<=W;j++){
      t[i][j] = s[j-1]=='#'?1:0;
    }
  }

  int h[H+2][W+2];
  for(int i=0;i<H+2;i++)for(int j=0;j<W+2;j++) h[i][j]=0;

  for(int i=1;i<=H;i++){
    int b=0;
    for(int j=0;j<=W;j++){
      if( t[i][j]==1 && t[i][j+1]==0 )
        b=j+1;
      if( t[i][j]==0 && t[i][j+1]==1 )
        for(int k=b;k<=j;k++)
          h[i][k]=j-b+1;
    }
  }

  int v[H+2][W+2];
  for(int i=0;i<H+2;i++)for(int j=0;j<W+2;j++)v[i][j]=0;

  for(int j=1;j<=W;j++){
    int b=0;
    for(int i=0;i<=H;i++){
      if( t[i][j]==1 && t[i+1][j]==0 )
        b=i+1;
      if( t[i][j]==0 && t[i+1][j]==1 )
        for(int k=b;k<=i;k++)
          v[k][j]=i-b+1;
    }
  }

  int ans=0;
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      ans = max(h[i][j]+v[i][j]-1,ans);
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define ll 				long long
#define vi 				vector<ll>
#define vvi				vector<vector<ll>>
#define mii 			map<ll,ll>
#define rev(a); 		reverse(a.begin(), a.end());
#define sortv(a); 		sort(a.begin(), a.end());
#define sortd(a); 		sort(a.begin(), a.end(), greater<int>());
#define FOR(i,a,b) 		for (int i = (a); i < (b); i++)
#define ROF(i,a,b) 		for (int i = (b)-1; i >= (a); i--)
#define pb 				push_back
#define mp 				make_pair
#define printv(a);		FOR(_Q,0,(int)(a).size()) cout<<(a)[_Q]<<" "; cout<<'\n';

ll MOD = 1000000007;
ll INF = LLONG_MAX;

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


void solve() {
	
}

signed main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n,m;cin>>n>>m;
	vi a(m);
	FOR(i,0,m) cin>>a[i];
	ll sum =0 ;
	FOR(i,0,m) sum+=a[i];
	cout<<max((ll)-1,n-sum);

}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int x,y,z; cin>>x>>y>>z;
    swap(x,y);
    swap(x,z);
    cout << x << ' ' << y << ' ' << z << '\n';
    return 0;
}

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

int main(){
  int N,K,sum=0;
  cin >> N >> K;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  for(int i=0;i<K;i++){
    sum+=A.at(i);
  }
  cout << sum << endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define in inline
#define int long long
#define re register
using namespace std;
in int read() {
	re int t=0;
	re char v=getchar();
	while(v<'0'||v>'9')v=getchar();
	while(v>='0'&&v<='9') {
		t=(t<<3)+(t<<1)+(v^48);
		v=getchar();
	}
	return t;
}
int n,m,ans;
signed main(){
	n=read();
	for(re int i=-1000;i<=1000;++i){
		for(re int j=-1000;j<=1000;++j){
			if(i*i*i*i*i-j*j*j*j*j==n){
				printf("%lld %lld\n",i,j);
				return 0;
			}
		}
	}
}

Measured memory_bytes: 3760
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int main() {
	int x, y, tmp;
	while (1) {
		scanf("%d %d", &x, &y);
		if (x == 0 && y == 0)
			break;
		if (x > y) {
			tmp = x;
			x = y;
			y = tmp;
		}
		printf("%d %d\n", x, y);
	}
	return 0;
}

Measured memory_bytes: 1028
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(M)]

def find_root(root,x):
    y = root[x]
    if x == y:
        return x
    z = find_root(root,y)
    root[x] = z
    return z
 
def merge(root,size,x,y):
    x = find_root(root,x)
    y = find_root(root,y)
    if x == y:
        return
    sx,sy = size[x],size[y]
    if sx < sy:
        sx,sy = sy,sx
        x,y = y,x
    root[y] = x
    size[x] += sy

def UF_make(graph,n):
    Root=list(range(n+1))
    Size=[1] * (n+1)
    for i in range(len(graph)):
        merge(Root,Size,graph[i][0],graph[i][1])
    for i in range(n+1):
        Root[i] = find_root(Root,i)
    Root.pop(0)  #
    return Root

ans=0
for i in range(M):
    if len(set((UF_make(AB[:i]+AB[i+1:],N))))!=1:
        ans+=1

print(ans)

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

int main(){
    int n;cin>>n;
    int ans=0;
    vector<vector<pair<int,int>>> f(n);
    for(int i=0;i<n;i++){
        int a;cin>>a;
        for(int j=0;j<a;j++){
            int x,y;cin>>x>>y;
            x--;
            f[i].push_back(make_pair(x,y));
        }
    }
    for(int bit=0;bit<(1<<n);bit++){
        int flag=1;
        int c=0;
        vector<int> h(n);
        for(int j=0;j<n;j++){
            if(bit>>j&1) h[j]=1;
        }
        for(int i=0;i<n;i++){
            if(h[i]==1){
                for(int j=0;j<f[i].size();j++){
                    if(h[f[i][j].first]!=f[i][j].second) flag=0;
                }
            }
        }
        if(flag){
            for(int i=0;i<n;i++) c+=h[i];
        }
        ans=max(ans,c);
    }
    cout<<ans<<endl;
}

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

int main() {
    ios_base::sync_with_stdio(false);	
    cin.tie(0);
	ll n;
	cin >> n;
	vector<ll> a(n);
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
	}	
	ll zero = 0;
	for (ll i = 0; i < n; i++) {
		if (a[i] == 0) zero++;
	}
	if (zero > 0) {
		cout << "0" << "\n";
		return 0;
	}
	ll ans = 1;
	for (ll i = 0; i < n; i++) {
		if (a[i] <= 1000000000000000000 / ans) {
			ans *= a[i];
		} else {
			cout << "-1" << "\n";
			return 0;
		}
	}	
	cout << ans << "\n";
	return 0;
}


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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

int main(int argc, char **argv)
{
	ll N, A, B; cin >> N >> A >> B;
	vector<ll> X(N);
	REP(i, N) cin >> X[i];
	vector<ll> diff(N-1);
	REP(i, N-1) diff[i] = (X[i+1] - X[i]) * A;
	
	ll res{0};
	REP(i, N-1)
		res += min(diff[i], B);
	std::cout << res << std::endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	set<string> s;
	for(int i =0 ;i<n; i++)
	{
		string sl;
		cin>>sl;
		s.insert(sl);
	}
	cout<<s.size()<<endl;
	return 0;
}

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

int main()
{
    int n, a, dv = 0, tw = 0;

    cin >> n;

    for (int i = 0; i < n; ++i)
    {
        cin >> a;

        if (a % 4 == 0)
            ++dv;
        else if (a % 2 == 0)
            ++tw;
    }

    if(tw > 0)
        n -= (tw - 1);

    if (n - dv > dv + 1)
        cout << "No\n";
    else
        cout << "Yes\n";
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

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

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

template <class T>
std::vector<T> enum_div(T n) {
    std::vector<T> ret;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

bool isPrime(ll num) {
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    for (ll i = 3; i * i <= num; i += 2) {
        if (num % i == 0) { return false; }
    }

    return true;
};

template <typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
bool is_integer(T x) {
    return std::floor(x) == x;
}

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N;
    cin >> N;
    cout << round_up(N,2) << endl;
    return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
#define el endl
typedef long long ll;
typedef long double ld;

int main() {
    int n, x;
    cin >> n >> x;
    if(500 * n >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	int x,y;
	cin>>x>>y;
	if (2*x>y) {
		cout<<"No";
	}
	if (2*x<y) {
		if ((y-2*x)%2==0) {
			if ((y-2*x)/2<=x) {
				cout<<"Yes";
			}
			else {
				cout<<"No";
			}
		}
		else {
			cout<<"No";
		}
	}
	if (2*x==y) {
		if (2*x==0) {
			cout<<"No";
		}
		else {
			cout<<"Yes";
		}
	}
return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
int main() {
	long int n,aSum=0,bSum=0,gcnt=0;
	cin >> n;
	vector<int > a(n), b(n);
	rep(i, n) {
		cin >> a[i];
		aSum += a[i];
	}
	rep(i, n) {
		cin >> b[i];
		bSum += b[i];
	}
	if (aSum > bSum) {
		cout << "No";
		return 0;
	}
	rep(i, n) {
		gcnt += a[i] < b[i] ? (int)((b[i] - a[i] + 1) / 2) : 0;
	}
	if (gcnt > bSum - aSum)
		cout << "No";
	else
		cout << "Yes";
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    string s; cin >> s;
    int n = s.size();
    string t1 = s.substr(0,n/2);
    string t2 = s.substr(n/2+1,n/2);
    bool ok = true;
    rep(i,n){
        if(s[i] != s[n-i-1]) ok = false;
    }
    rep(i,n/2){
        if(t1[i] != t1[n/2-i-1]) ok = false;
    }
    rep(i,n/2){
        if(t2[i] != t2[n/2-i-1]) ok = false;
    }
    cout << (ok?"Yes":"No") << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define PII pair<int,int>
#define VS vector<string>
#define VI vector<int>
#define ll long long
#define ull unsigned long long
#define FST first
#define SEC second
int main(){
  VI V;
  REP(i,4){
    int a;cin>>a;
    V.PB(a);
  }
  sort(ALL(V));
  if(V[0]==V[1]&&V[2]==V[3]){
    cout<<"yes"<<endl;
  }else{
    cout<<"no"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3132
# @author 

import sys

class DKnapsack1:
    def solve(self):
        n, W = [int(_) for _ in input().split()]
        w = [0] * (n + 1)
        v = [0] * (n + 1)
        for i in range(1, n + 1):
            w[i], v[i] = [int(_) for _ in input().split()]

        dp = [[0] * (n + 1) for _ in range(W + 1)]

        for we in range(W + 1):
            dp[we][0] = 0
            for k in range(1, n + 1):
                dp[we][k] = dp[we][k - 1]
                if w[k] <= we:
                    dp[we][k] = max(dp[we][k], dp[we - w[k]][k - 1] + v[k])

        print(dp[W][n])

solver = DKnapsack1()
input = sys.stdin.readline

solver.solve()


Measured memory_bytes: 130652
#include <cstdio>
#include <string>
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <map>
using namespace std;

int main() {
    
    int a, b, c, k;
    int sum = 0;
    scanf("%d %d %d\n", &a, &b, &c);
    scanf("%d", &k);
    for (int i = 0; i < k; i++) {
        if (a >= b && a >= c) a = a*2;
        else if (b >= a && b >= c) b = b*2;
        else if (c >= a && c >= b) c = c*2;
    }
    printf("%d\n", a + b + c);

    return 0;
}

Measured memory_bytes: 256
import sys
N,M=map(int,input().split())
slist=list(map(int,input()))

seq=0
for s in slist:
  if s==0:
    seq=0
  else:
    seq+=1
    if seq==M:
      print(-1)
      sys.exit(0)

#####segfunc#####
def segfunc(x,y):
  return min(x,y)

#####ide_ele#####
ide_ele=float("inf")

class SegTree:
  """
  init(init_val, ide_ele): 配列init_valで初期化 O(N)
  update(k, x): k番目の値をxに更新 O(logN)
  query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
  """
  def __init__(self, init_val, segfunc, ide_ele):
    """
    init_val: 配列の初期値
    segfunc: 区間にしたい操作
    ide_ele: 単位元
    n: 要素数
    num: n以上の最小の2のべき乗
    tree: セグメント木(1-index)
    """
    n = len(init_val)
    self.segfunc = segfunc
    self.ide_ele = ide_ele
    self.num = 1 << (n - 1).bit_length()
    self.tree = [ide_ele] * 2 * self.num
    # 配列の値を葉にセット
    for i in range(n):
      self.tree[self.num + i] = init_val[i]
    # 構築していく
    for i in range(self.num - 1, 0, -1):
      self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

  def update(self, k, x):
    """
    k番目の値をxに更新
    k: index(0-index)
    x: update value
    """
    k += self.num
    self.tree[k] = x
    while k > 1:
      self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
      k >>= 1

  def query(self, l, r):
    """
    [l, r)のsegfuncしたものを得る
    l: index(0-index)
    r: index(0-index)
    """
    res = self.ide_ele

    l += self.num
    r += self.num
    while l < r:
      if l & 1:
        res = self.segfunc(res, self.tree[l])
        l += 1
      if r & 1:
        res = self.segfunc(res, self.tree[r - 1])
      l >>= 1
      r >>= 1
    return res
  
seg=SegTree([float("inf")]*(N+1), segfunc, ide_ele)
seg.update(N,0)

for i in reversed(range(N)):
  if slist[i]==0:
    left=i+1
    right=min(i+M,N)
    seg.update(i,seg.query(left,right+1)+1)

dist_list=[]
for i in range(N+1):
  dist_list.append(seg.query(i,i+1))
#print(dist_list)

answer_list=[]
i=0
while i<N:
  for j in range(1,M+1):
    if dist_list[i]>dist_list[i+j]:
      answer_list.append(j)
      i+=j
      break
    
print(*answer_list)

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

using namespace std;

int main(void)
{
    int N,K;
  cin >> N >>K;

    int result =0;
    for(int i=0;i<N;i++){
        int cm;
        cin>>cm;
        if(cm>=K){
            result++;
        }
    }
    cout <<result << endl;

    return 0;
}

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

using namespace std;

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

    unordered_set<int> lst;
    for (int i = 0; i < N; ++i) {
        int A;
        cin >> A;

        unordered_set<int>::iterator it;
        if ((it = lst.find(A)) == lst.end())
            lst.emplace(A);
        else
            lst.erase(it);

    }

    cout << lst.size() << endl;

    return 0;
}


Measured memory_bytes: 4388
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD = 1e9+7;

int main(){
  ll n,m;
  string s,t;
  cin>>n>>m>>s>>t;
  int gc=__gcd(n,m);
  if(gc==1){
	if(s[0]==t[0])cout<<n*m<<endl;
	else cout<<-1<<endl;
  }else {
	//	cout<<gc<<endl;
	ll nc=n/gc;
	ll mc=m/gc;
	int cnt1=0,cnt2=0;
	int f=1;
	while(cnt1<n){
	  if(s[cnt1]!=t[cnt2])f=0;
	  cnt1+=nc;
	  cnt2+=mc;
	}
	if(f)cout<<n*m/gc<<endl;
	else cout<<-1<<endl;
  }
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <queue>
using namespace std;
int main(){
  int n;cin>>n;
  queue<int> J;
  for(int i = 0; (1<<n) > i; i++){
    int t;cin>>t;
    J.push(t);
  }
  while(J.size() != 1){
    int A = J.front();J.pop();
    int B = J.front();J.pop();
    J.push((A==B?A:abs(A-B)));
  }
  cout << J.front() << endl;
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[])
{
	double i, a, b;
	bool ans = false;
	cin >> a >> b;
	for (i = b * 10;; i++) {
		if (floor(i * 0.08) == a &&
			floor(i * 0.10) == b) {
			ans = true;
			break;
		}
		if (floor(i * 0.10) > b)
			break;
	}

    if (ans)
		cout << i << endl;
	else
		cout << "-1" << endl;
			

	return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input!{
      n: usize,
    }

    let mut ans = 0;
    for i in 1..n+1 {
        if i%3 != 0 && i%5 != 0 {
            ans += i;
        }
    }
    puts!("{}\n", ans);
}


Measured memory_bytes: 2184
a, b = map(int, input().split())
if a <= 0 and 0 <= b:
    print("Zero")
elif a < 0 and b < 0:
    if (b - a + 1) % 2 == 0:
        print("Positive")
    else:
        print("Negative")
else:
  print("Positive")  


Measured memory_bytes: 2940
fn main() {
    let input = read_vec::<i32>();
    let mut res = 0;

    for i in 1..input[0]+1 {
        let mut tmp = 0;
        for c in i.to_string().chars() {
            tmp += c as i32 - 48;
        }
        if tmp >= input[1] && tmp <= input[2] {
            res += i;
        }
    }
    println!("{}", res);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define VAR(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

int N;

inline i64 parent(i64 u) { return (u - 1) / N; }

inline i64 depth(i64 u) {
    i64 d = 0;
    while (u > 0) ++d, u = parent(u);
    return d;
}

inline i64 findLCA(i64 a, i64 b) {
    if (N == 1) {
        return min(a, b);
    }
    while (a != b) {
        const i64 depA = depth(a);
        const i64 depB = depth(b);
        if (depA > depB) {
            a = parent(a);
        } else if (depA < depB) {
            b = parent(b);
        } else {
            a = parent(a);
            b = parent(b);
        }
    }
    return a;
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    int Q;
    read(N, Q);

    while (Q--) {
        VAR(int, a, b);
        --a, --b;
        print(findLCA(a, b) + 1);
    }

    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

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

    string s(n,' ');
    rep(i,n){
        int rem = n-1-i;
        if(x[i]=='1'){
            if(d<=rem) s[i] = '1';
            else{
                s[i] = '0';
                --d;
            }
        }
        else{
            if(d>0){
                s[i] = '1';
                --d;
            }
            else s[i] = '0';
        }
    }
    cout << s << endl;
    return 0;
}



Measured memory_bytes: 3228
h, w = gets.chomp.split(' ').map(&:to_i)
a = []
h.times do |i|
  a << gets.chomp.split('')
end
r = []
c = []
h.times do |i|
  w.times do |j|
    if a[i][j] == '#'
      r << i
      break
    end
  end
end
w.times do |j|
  h.times do |i|
    if a[i][j] == '#'
      c << j
      break
    end
  end
end
r.each do |i|
  c.each do |j|
    print a[i][j]
  end
  print "\n"
end


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

int main(){
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  int x = (n/a)*b + (n%a>0?1:0)*b;
  int y = (n/c)*d + (n%c>0?1:0)*d;
  if ( x > y ) cout << y << endl;
  else cout << x << endl;

  return 0;
}





Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int INF = 0x3f3f3f3f;

int main()
{
	int n, m[105];
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> m[i];
	int ans = 0;
	for(int i = 0; i < n; i++)
	{
		int Min = INF, loc = i;
		for(int j = i; j < n; j++)
		{
			if(m[j]<Min)
			{
				Min = m[j];
				loc = j;
			}
		}
		if(loc != i)
			ans++;
		int temp = m[i];
		m[i] = m[loc];
		m[loc] = temp;
	}

	cout<<m[0];
	for(int i = 1; i < n; i++)
		cout<<" "<<m[i];
	cout<<endl<<ans<<endl;
	return 0;
}

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

// a,b,c,d <= 1000    n <= 4000

int main(){
	long int root[5][4001] = {};
	for (int i = 0; i < 1001; i++) {
		root[1][i] = 1;
	}
	for (int i = 1; i < 5; i++) {
		root[i][0] = 1;
	}
	for (int i = 2; i < 5; i++) {
		for (int j = 1; j < 4001; j++) {
			for (int k = j; k >= 0 && k >= j - 1000; k--) {
				root[i][j] += root[i - 1][k];
			}
		}
	}
	int n;
	while(cin >> n){
		cout << root[4][n] << endl;
	}
	return 0;
}

Measured memory_bytes: 3216
import sys
from collections import deque as dq
input = sys.stdin.readline
H, W = map(int, input().split())
a = [list(input())[: -1] for _ in range(H)]
dist = [[H * W] * W for _ in range(H)]
Q = dq([])
for i in range(H):
  for j in range(W):
    if a[i][j] == "#":
      Q.append((i, j))
      dist[i][j] = 0

d = [-1, 0, 1, 0]
while len(Q):
  y, x = Q.popleft()
  for k in range(4):
    u = y + d[k]
    v = x + d[-1 - k]
    if u in range(H) and (v in range(W)):
      if dist[u][v] > dist[y][x] + 1:
        dist[u][v] = dist[y][x] + 1
        Q.append((u, v))
print(max([max(dist[i]) for i in range(H)]))

Measured memory_bytes: 121180
def gcd(c, d):
  if c < d:
    tmp = d
    d = c
    c = tmp
  ret = c
  if d != 0:
    ret = gcd(d, c % d)
  return ret

def lcm(c, d):
  return (c * d) // gcd(c, d)

def union_cardinality(a_cardi, b_cardi, ab_cardi):
  return a_cardi + b_cardi - ab_cardi

def count_cm(maxi, divi):
  return maxi // divi

def count_cm2(maxi, divi1, divi2):
  num1 = count_cm(maxi, divi1)
  num2 = count_cm(maxi, divi2)
  num12 = count_cm(maxi, lcm(divi1, divi2))
  return union_cardinality(num1, num2, num12)

def count_cm2_band(mini, maxi, divi1, divi2):
  return count_cm2(maxi, divi1, divi2) - count_cm2(mini - 1, divi1, divi2)

a, b, c, d = (int(x) for x in input().split())
print(b - a + 1 - count_cm2_band(a, b, c, d))


Measured memory_bytes: 3064
//  Created by conan1024hao in 2020.
//  Copyright © 2020 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e17
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------
ll sum[200001];
//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????统一类型        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll n;cin>>n;
    V<ll>a(n);
    for(ll i=0;i<n;i++)cin>>a[i];
    sum[0]=a[0];
    for(ll i=1;i<n;i++){
        sum[i]=sum[i-1]+a[i];
    }
    ll ans=0;
    ll cnt=0;
    ll now=0;
    ll precnt=0;
    ll right=0;
    for(ll i=0;i<n;i++){
        while(right<n&&(now^a[right])==now+a[right]){
            now+=a[right];
            right++;
            
        }
        ans+=right-i;
        if(i==right)right++;
        else{
            now-=a[i];
        }
    }
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------








Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		sc.close();
		int[] Num = new int[N];
		for(int i = 0;i < N;i++) {
			Num[i] = i+1;
		}
		int cnt = 0;
		int max = 0;
		int ans = 0;
		for(int i = 0;i < N;i++) {
			if(N == 1) {
				ans = 1;
				break;
			}
			int k = Num[i];
			while(k%2 == 0) {
				k /= 2;
				cnt++;
			}
			if(max < cnt) {
				max = cnt;
				ans = Num[i];
			}
			cnt = 0;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21588
def move(x, y, direction):
    global ans, nx, ny
    if direction in ['U', 'D']:
        ans += direction * abs(ny - y)
    if direction in ['L', 'R']:
        ans += direction * abs(nx - x)
    nx, ny = x, y


sx, sy, tx, ty = map(int, input().split())
ans = ''
nx, ny = sx, sy

move(sx, ty, 'U')
move(tx, ty, 'R')

move(tx, sy, 'D')
move(sx, sy, 'L')

move(sx-1, sy, 'L')
move(sx-1, ty+1, 'U')
move(tx, ty+1, 'R')
move(tx, ty, 'D')

move(tx+1, ty, 'R')
move(tx+1, sy-1, 'D')
move(sx, sy-1, 'L')
move(sx, sy, 'U')

print(ans)

Measured memory_bytes: 3064
//https://vjudge.net/contest/339141#problem/C
/*
* Author : MaxSally
*/
/********   All Required Header Files ********/
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define rep(i, j, k) for (int i = j ; i <= k ; ++i)
#define rrep(i, j, k) for (int i = j; i >= k; --i)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define foreach(i, a) for(auto i: a)
#define forEach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define in(A, B, C) assert( B <= A && A <= C)
#define mp make_pair
#define pb push_back
#define inf (int) (1e9 + 7)
#define epsi 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007
#define read(type) readInt<type>()
#define io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define left tuyiuoi
#define right fgjhk
#define ss second
#define ff first
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) rep(i, l, r) cout << a[i] << " "; cout << endl
#define Flag(n) cout << "here " << n << endl
const double pi=acos(-1.0);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<ll, ll> pll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;

const int N = 100005;
int sparseTable[30][N], n;

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

void createSparseTable(){
    int row = (int)log2(n);
    rep(i, 1, row){
        rep(j, 0, n - (1 << i)){
            sparseTable[i][j] = gcd(sparseTable[i - 1][j], sparseTable[i - 1][j + (1 << (i - 1))]);
        }
    }
}

int query(int l, int r){
    int k = (int)log2(r - l + 1);
    return gcd(sparseTable[k][l], sparseTable[k][r - (1 << k) + 1]);
}

int main(){
    io;
    //freopen("input.txt", "r", stdin);
    cin >> n;
    rep(i, 0, n - 1){
        cin >> sparseTable[0][i];
    }
    createSparseTable();
    int res = max(query(1, n - 1), query(0, n - 2));
    rep(i, 1, n - 2){
        res = max(gcd(query(0, i - 1), query(i + 1, n - 1)), res);
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 8448
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}
long long gcd(long long x,long long y){
	return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
	return x/gcd(x,y)*y;
}

// konoshita kara kaku

int main(void){
	int h=in(),w=in(),i,j,ah,aw;
	char s[10];
	rep(i,h){
		rep(j,w){
			chin(s);
			if(strcmp(s,"snuke")==0){
				ah=i+1;
				aw=j;
			}
		}
	}
	printf("%c%d\n",'A'+aw,ah);
	return 0;
}

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

class Program
 {
        static void Main(string[] args)
        {
          	int n;
          	n = int.Parse(Console.ReadLine());
        	string[] str = Console.ReadLine().Split(' ');
          	int[] person = str.Select(int.Parse).ToArray();
            int ave = Convert.ToInt32(person.Average());
          	int[] dist = person.Select(value => (int)Math.Pow(value-ave,2)).ToArray();
          	Console.WriteLine(dist.Sum());
　　　　　}
 }

Measured memory_bytes: 28272
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> P2;
#define int ll
ll h,w,k;
bool cando[805][805],block[805][805];
ll dx[]={0,1,0,-1},dy[]={1,0,-1,0};
void bfs(ll x,ll y,ll d){
  queue<P2> que;
  que.push(P2(P(x,y),d));
  while(!que.empty()){
    P2 p=que.front();
    que.pop();
    ll px=p.first.first,py=p.first.second,pd=p.second;
    if(pd>=k) continue;
    for(int i=0;i<4;i++){
      ll nx=px+dx[i],ny=py+dy[i];
      if(0<nx&&nx<=h&&0<ny&&ny<=w){
        if(!cando[nx][ny]&&!block[nx][ny]){
          cando[nx][ny]=true;
          que.push(P2(P(nx,ny),pd+1));
        }
      }
    }
  }
}
ll dis(ll x,ll y){
  ll d1=x-1,d2=h-x,d3=y-1,d4=w-y;
  return min({d1,d2,d3,d4});
}
signed main(){
  cin>>h>>w>>k;
  ll sx,sy;
  for(int i=1;i<=h;i++){
    string s;
    cin>>s;
    for(int j=1;j<=w;j++){
      if(s[j-1]=='S') {
        cando[i][j]=true;
        sx=i;
        sy=j;
      }
      else cando[i][j]=false;
      if(s[j-1]=='#') block[i][j]=true;
      else block[i][j]=false;
    }
  }
  if(sx==1||sx==h||sy==1||sy==w) {
    cout<<0<<endl;
    return 0;
  }
  bfs(sx,sy,0);
  ll mdis=34883488348838;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      if(i==1||i==h||j==1||j==w){
        if(cando[i][j]){
          cout<<1<<endl;
          return 0;
        }
      }
      else if(cando[i][j]) mdis=min(mdis,dis(i,j));
    }
  }
  ll ans=(mdis+k-1)/k;
  cout<<min(ans+1,((dis(sx,sy)+k-1)/k)+1)<<endl;
}


Measured memory_bytes: 1536