akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <string>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) (a)=(a>b)?(a):(b);
#define chmin(a, b) (a)=(a<b)?(a):(b);
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PL;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/



int main(void) {
  ll i, j, k;
  
  ll K, N;
  cin >> K >> N;
  ll a[MAX*2];
  
  
  for(i=0; i<N; i++) cin >> a[i];
  a[N]=a[0]+K;
  
  ll s=0;
  for(i=0; i<N; i++) s+=a[i+1]-a[i];
  
  ll ans=INF;
  for(i=0; i<N; i++) chmin(ans, s-(a[i+1]-a[i]));
  pt(ans);
  
}




Measured memory_bytes: 1792
#include<cstdio>
#define int long long
int n,S,x[300100],p[300100],ans;
signed main(){
	scanf("%lld%lld",&n,&S);
	for(int i=1;i<=n;i++)
		scanf("%lld%lld",&x[i],&p[i]);
	int l=1,r=n,dir=0;
	while(1){
		if(x[l]>=S){
			ans+=x[r]-S;
			break;
		}
		if(x[r]<=S){
			ans+=S-x[l];
			break;
		}
		if(p[l]>=p[r]){
			if(dir!=1)ans+=x[r]-x[l],dir=1;
			p[l]+=p[r];
			r--;
		}
		else{
			if(dir!=2)ans+=x[r]-x[l],dir=2;
			p[r]+=p[l];
			l++;
		}
	}
	printf("%lld\n",ans);
}

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

int main() {
    int n, k;
    cin >> n >> k;
    int a[n];
    rep(i,n) {
        cin >> a[i];
    }
    sort(a, a+n);
    int ans = accumulate(a+n-k, a+n, 0);
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        while(true){
            String[] str = sc.nextLine().split("");
            if(Integer.parseInt(str[0]) == 0){
                break;
            }
            int ans = 0;
            for(int i = 0; i < str.length; i++){
                ans += Integer.parseInt(str[i]);
            }
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 27324
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
#define P(a,b) make_pair(a,b);
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;

ll N,X;
map<pair<ll,ll>,ll> mp;

ll F(ll k,ll x){
    if(mp.count(make_pair(k,x)) != 0) return mp[make_pair(k,x)];
    ll n = 4 * (ll)pow(2,k) - 3,m = 2 * (ll)pow(2,k) - 1;
    if(x == 0)return 0;
    if(k == 0)return 1;
    if(x == 1)return 0;
    if(x > n) return 0;
    if(x < m){
        return mp[make_pair(k,x)] = F(k-1,x-1);
    }else{
        return mp[make_pair(k,x)] = (F(k-1,m-2) + 1 + F(k-1,min(x-m,4 * (ll)pow(2,k-1) - 3)));
    }
}

int main(){
    cin >> N >> X;
    cout << F(N,X) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
using namespace std;

int main() {
    int n;
    long long int k;
    cin >> n >> k;
    vector<int> v;
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        v.push_back(t);
    }

    unordered_map<int, int> um1, um2;
    int t = 1;
    for (long long int i = 1; i <= k; i++) {
        if (um1[t] == 0) {
            um1[t] = i;
            um2[i] = t;
            t = v[t - 1];
        } else {
            int c = i - um1[t];
            int index =  (k - i) % c + um1[t] + 1;
            while (index >= i) index -= c;
            cout << um2[index] << endl;
            return 0;
        }
    }
    cout << t << endl;
}


Measured memory_bytes: 18148
#include <bits/stdc++.h>
using namespace std;
static const int INF = 1e9+7;

int main(){
    int W;
    int ans;
    cin>>W;
    vector<int> a(W+10);
    
    for(int i=0; i<W; i++){
        cin>>a[i];
    }

    vector<int> left(W+10,-INF);
    vector<int> right(W+10,-INF);

    for(int i=0; i<W; i++){
        if(a[i] == 0) left[i] = INF;
        else if(a[i] > 0 && i >0) left[i] = left[i-1]-1;
        else {
            if(i > 0) left[i] = min(left[i-1]-1,-a[i]);
        }
    }

    for(int i=W-1; i>=0; i--){
        if(a[i] == 0) right[i] = INF;
        else if(a[i] > 0 && i != W-1) right[i] = right[i+1] - 1;
        else {
            if(i != W-1) right[i] = min(right[i+1]-1,-a[i]);
        }
    }

    ans = 0;

    for(int i=0; i<W+1; i++){
        int tmp1 = max(left[i],right[i]);
        int tmp2 = min(a[i],tmp1);
        ans += max(tmp2,0);
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3888
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n; cin>>n;
  vector<int> p(n+1,1);
  for(int i=2; i<=n; ++i) for(int j=1; j*i<=n; ++j) ++p[j*i];
  long long res=0;
  for(long long i=1; i<=n; ++i) res+=i*p[i];
  cout<<res<<endl;
  return 0;
}

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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

vector<int> depth(vector<vector<int>>& edges,int i,int par) {
    vector<int> d(2,0);
    d[1] = i;
    for (int j : edges[i]) if (j != par) {
        vector<int> e = depth(edges,j,i);
        if (e[0]+1 > d[0]) {
            d = e;
            d[0]++;
        }
    }
    return d;
}

vector<int> calc_diameter(vector<vector<int>>& edges) {
    int n = edges.size();
    vector<int> a(2),b(2),ret(3);
    a = depth(edges,0,-1);
    b = depth(edges,a[1],-1);
    ret[0] = b[0];
    ret[1] = a[1];
    ret[2] = b[1];
    return ret;
}

int main() {
    int n;
    cin >> n;
    vector<vector<int>> edges(n);
    for (int i = 0;i < n-1;++i) {
        int u,v;
        cin >> u >> v;
        u--;v--;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    vector<int> d = calc_diameter(edges);
    if (d[0]%3 == 1) cout << "Second" << endl;
    else cout << "First" << endl;
    return 0;
}

Measured memory_bytes: 36224
s=input()
ans = 0
p_n = 0; g_n = 0
for s_i in s:
    if s_i == "g":
        if p_n < g_n:
            ans += 1
            p_n += 1
        else:
            g_n += 1
    else:
        if p_n < g_n:
            p_n += 1
        else:
            g_n += 1
            ans -= 1
print(ans)


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

int main() {
  int h, w;
  cin >> h >> w;
  vector< vector<int> > a(h, vector<int>(w));

  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      cin >> a[i][j];
    }
  }

  vector<vector<int>> ans;
  for (int i = 0; i < h; ++i) {
    if (i % 2 == 0) {
      for (int j = 0; j < w ; ++j) {
	if (a[i][j] % 2 == 1) {
	  if (j == w - 1 && i < h - 1) {
	    vector<int> x = {i, j, i + 1, j };
	    ans.push_back(x);
	    a[i][j]--;
	    a[i + 1][j]++;
	  } else if (j < w - 1) {
	    vector<int> x = {i, j, i, j + 1};
	    ans.push_back(x);
	    a[i][j]--;
	    a[i][j + 1]++;
	  }
	}
      }
    } else {
      for (int j = w - 1; j >= 0; --j) {
	if (a[i][j] % 2 == 1) {
	  if (j == 0 && i < h - 1) {
	    vector<int> x = {i, j, i + 1, j};
	    ans.push_back(x);
	    a[i][j]--;
	    a[i + 1][j]++;
	  } else if (j > 0) {
	    vector<int> x = {i, j, i, j - 1};
	    ans.push_back(x);
	    a[i][j]--;
	    a[i][j - 1]++;	    
	  }
	}
      }
    }
  }

  cout << ans.size() << endl;
  for (size_t i = 0; i < ans.size(); ++i) {
    for (int j = 0; j < 4; ++j) {
      cout << ans[i][j] + 1;
      if (j == 3) cout << endl;
      else cout << " ";
    }
  }
  return 0;
}


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

int main(){
    ll l,r,ans=3000;
    cin >> l >> r;
    for(ll i=l;i<=r;i++){
        ll num=i%2019;
        if(num==0){
            cout << 0;
            return 0;
        }
        for(ll j=i+1;j<=r;j++){
            if(j%2019==0){
                cout << 0;
                return 0;
            }
            ans = min(ans,(i*j)%2019);
        }
    }
    cout << ans << endl;
}  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define arr array

using namespace std;

const int e = 2e6 + 69;
const ll mod = 1e9 + 7;

ll a[e];
arr<int, 2>b[e];

//beginner 1999 127

int main()
{
    int n, m;
    cin >> n >> m;
    multiset<arr<int, 2>, greater<arr<int, 2>>>cur;
    for(int i=1; i<=n; i++){
        cin >> a[i];
        cur.insert({a[i], 1});
    }
    for(int i=1; i<=m; i++){
        int x, y;
        cin >> x >> y;
        cur.insert({y, x});
    }
    int dem = n;
    ll ans = 0;
    /*for(auto j : cur){
        cout << j[0] <<" "<<j[1] <<"\n";
    }*/
    for(auto j : cur){
        ans += 1LL* min(dem, j[1])*j[0];
        dem -= min(dem , j[1]);
        if(dem == 0){
            cout << ans;
            return 0;
        }
    }

}


Measured memory_bytes: 13712
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {
 
	public static void main(String[] args) {  
		Scanner input = new Scanner(System.in);
		long itCoord = input.nextLong();
		long itSpeed = input.nextLong();
		long altC = input.nextLong();
		long altS = input.nextLong();
		long T = input.nextLong();
		long diff = itSpeed-altS;
		//if (altC<itCoord) System.out.println("NO");
		if (diff*T>=Math.abs(itCoord-altC)) System.out.println("YES");
		else System.out.println("NO");
	}
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int N, M;
int D[1100], C[1100];
int dp[1100][1100];

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

    std::cin >> N >> M;

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

    for(int i=0;i<M;++i){
        std::cin >> C[i];
    }

    fill(&dp[0][0], &dp[0][0]+1100*1100, 1001001001);
    dp[0][0] = 0;
    
    for(int i=0;i<M;++i){
        for(int j=0;j<=N;++j){
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            if(j + 1 <= N){
                dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + D[j] * C[i]);
            }
        }
    }

    std::cout << dp[M][N] << std::endl;
}



Measured memory_bytes: 7908
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
void YN(bool flg){cout<<(flg?"YES":"NO")<<endl;}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<endl;}
void yn(bool flg){cout<<(flg?"yes":"no")<<endl;}
signed main(){
	int n;cin>>n;
	vector<int> d(n);
	rep(i,n) cin>>d[i];
	sort(All(d));
	int ans=1;
	rep(i,n-1) if(d[i]<d[i+1])ans++;
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
 #include <cmath>

 using namespace std;
 typedef long long ll;

 int main(void){
 ll a,b,c;

 cin >> a >> b >> c;

 ll d = c - a - b;
 if(d > 0 && d * d > 4 * a * b){
 cout << "Yes" << endl;
 } else {
 cout << "No" << endl;
 }

 return 0;
 }

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

int main() {
    ll A,X;
    cin>>X>>A;
    ll ans=0;
    if (X<A) ans=0;
    else ans=10;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    private static final boolean N_CASE = false;

    private void solve() {
        int n = sc.nextInt();
        int m = sc.nextInt();

        int ans = Math.max(0, n * (n - 1) / 2) + Math.max(0, m * (m - 1) / 2);
        out.println(ans);
    }

    private void run() {
        int T = N_CASE ? sc.nextInt() : 1;
        for (int t = 0; t < T; ++t) {
            solve();
        }
    }

    private static MyWriter out;
    private static MyScanner sc;

    private static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        private MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        int[] nextArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = nextInt();
            }
            return a;
        }

        List<Integer> nextList(int n) {
            List<Integer> list = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                list.add(nextInt());
            }
            return list;
        }
    }

    private static class MyWriter extends PrintWriter {
        private MyWriter(OutputStream outputStream) {
            super(outputStream);
        }

        void printArray(int[] a) {
            for (int i = 0; i < a.length; ++i) {
                print(a[i]);
                print(i == a.length - 1 ? '\n' : ' ');
            }
        }

        void printlnArray(int[] a) {
            for (int v : a) {
                println(v);
            }
        }

        void printList(List<Integer> list) {
            for (int i = 0; i < list.size(); ++i) {
                print(list.get(i));
                print(i == list.size() - 1 ? '\n' : ' ');
            }
        }

        void printlnList(List<Integer> list) {
            list.forEach(this::println);
        }
    }

    public static void main(String[] args) {
        out = new MyWriter(new BufferedOutputStream(System.out));
        sc = new MyScanner();
        new Main().run();
        out.close();
    }
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int x, t;cin >> x >> t;
    cout << max(0, x-t) << endl;
    return 0;
}


Measured memory_bytes: 256
/* 166-C.cpp
 *     Created on : May 3, 2020 
 *     Time       : 7:47:31 PM
 *     Author     : null_ptr
 */
#include<iostream>
#include<vector>

using namespace std;

int main()
{
	int n,m;
	cin>>n>>m;
	vector<long long int>height(n),ans(n,1);
	for(int i=0;i<n;++i)
		cin>>height[i];

	int u,v;

	for(int i=0;i<m;++i)
	{
		cin>>u>>v;
		--u,--v;
		if(height[u]>=height[v])
			ans[v]=0;

		if(height[v]>=height[u])
			ans[u]=0;
	}
	int cnt=0;
	for(int i=0;i<n;++i)
		if(ans[i])cnt++;

	cout<<cnt;
}


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

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

    long long h, w;
    cin >> h >> w;

    if(h == 1 && w == 1)
        cout << 1 << '\n';
    else if(h == 1 || w == 1)
        cout << 1 << '\n';
    else if((h*w) % 2 == 0)
        cout << (h * w)/2 << '\n';
    else
        cout << (h * w)/2 + 1 << '\n';
    return 0;
}

Measured memory_bytes: 256
#include"iomanip"
#include"iostream"
#include"limits"
#include"cmath"
#include"vector"
#include"algorithm"
#include"list"
#include"queue"
#include"stack"
#include"set"
#include"unordered_set"
#include"map"
#include"unordered_map"
#include"string"
#include"cstring"
#include"assert.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define mp make_pair
#define pb push_back
#define mset(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll maxn=2e5+10;;
ll pre[maxn];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;cin>>n;
    ll tot=0;
    for(int i=1;i<=n;++i)
    {
        ll x;cin>>x;
        pre[i]=x+pre[i-1];
        tot+=x;
    }
    ll ans=1e14;
    for(int i=1;i<=n-1;++i)
    {
        ans=min(ans,          abs(pre[i]-(tot-pre[i]))         );
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 1000000
//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//スタックにデータを追加
void push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) exit(1);
    new->elem = elem;
    new->next = *first;
    *first = new;
}

//スタックからデータを取り出す
char pop(node **first){
    char elem;
    node *tmp = *first;
    if(tmp == NULL) exit(1);
    elem = tmp->elem;
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}

int main(void){
    char cube[SIZE];
    char under_cube;
    int i,count = 0,answer = 0;
    scanf("%s",cube);
    //最初のノードの指す先
    node *first = NULL;
    /* 文字の数だけループ */
    for ( i = 0; i < strlen(cube); i++)
    {
        if (count == 0)
        {
            /* stackがからの場合、挿入 */
            push(&first,cube[i]);
            count += 1;
        }
        else
        {
            /* stackに要素がある場合、取り出す */
            under_cube = pop(&first);
            if (under_cube == cube[i])
            {
                /* 1か0が連続している場合、stackに追加 */
                push(&first,under_cube);
                push(&first,cube[i]);
                count += 1;
            }
            else
            {
                /* 連続していない場合は、追加せず */
                answer += 2;
                count -= 1;
            }
            
        }
        
    }
    printf("%d\n",answer);
    return 0;
}


Measured memory_bytes: 4932
N, M, C = (int(x) for x in input().split())
B = [int(x) for x in input().split()]
A = []
for i in range(N):
    temp = [int(x) for x in input().split()]
    A.append(temp)


count = 0
    
for i in range(N):
    sum_value = 0
    for j in range(len(A[i])):
        sum_value += A[i][j] * B[j]
    if sum_value + C > 0:
        count += 1

print(count)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
using namespace std;

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

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

const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;

int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };

using MIte = multimap<long, long, greater<long> >::iterator;

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

	// long long?
	long long N,M,C;
	cin >> N >> M >> C;

	vector<int> vB(M, 0);
	rep(i, M) cin >> vB[i];

	int ans = 0;
	rep(i, N) {
		vector<int> vA(M, 0);
		int val = C;
		rep(i, M) {
			cin >> vA[i];
			val += vA[i] * vB[i];
		}
		if (val > 0) {
			ans++;
		}
	}

	cout << ans << endl;
	return 0;

}

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

int main() {
  int N;
  cin >>N;
  vector<tuple<string,int,int>> A(N);
  for(int i;i<N;i++){
    cin>>get<0>(A[i])>>get<1>(A[i]);
    get<2>(A[i]) = i+1;
    get<1>(A[i])*=-1;
  }
  sort(A.begin(), A.end());
  for(int i;i<N;i++){
    cout<<get<2>(A[i])<<endl;
  }
  
}


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

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

int showAll(vector<char> v) {
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << endl;
  return 0;
}

int main() {
  string s, t;
  cin >> s >> t;
  vector<char> vs, vt;
  rep(i, s.size()) {
    vs.push_back(s.at(i));
  }
  rep(i, t.size()) {
    vt.push_back(t.at(i));
  }
  sort(vs.begin(), vs.end());
  sort(vt.begin(), vt.end(), greater<char>());

  // showAll(vs);
  // showAll(vt);

  int loop = min(vs.size(), vt.size());
  rep(i, loop) {
    if (vs[i] < vt[i]) {
      cout << "Yes" << endl;
      return 0;
    } else if (vs[i] > vt[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  if (vs.size() < vt.size()) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;

  // cout << vs[] << endl;


  return 0;
}



Measured memory_bytes: 256
n, m = map(int,input().split())
a = [int(input()) for i in range(m)]
dp = [float("inf")] * (n+1)
dp[0] = 1
dp[1] = 1
for i in a:
    dp[i] = 0
for i in range(2, n+1):
    dp[i] = min(dp[i], (dp[i-1] + dp[i-2])%(10**9+7))
print(dp[n])


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

int x[100000];

int main(){
	int n;
	scanf("%d", &n);
	f(i, 0, n)scanf("%d", x + i);
	int an = 1, i = 1, s = 0;
	while (i < n){
		if (s == 0){
			if (x[i] > x[i - 1])s = 1;
			else if (x[i] < x[i - 1])s = 2;
		}else if (s == 1){
			if (x[i] < x[i - 1])++an, s = 0;
		}else if (s == 2){
			if (x[i] > x[i - 1])++an, s = 0;
		}
		++i;
	}
	printf("%d\n", an);
}

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

int main() {

    int K, A, B;
    cin >> K >> A >> B;

    for (int i = A; i <= B; ++i) {
        if (i%K == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;

    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;

ll N;
vector<ll> dp((1<<21)+1,-1);
vector<vector<ll>> a(21, vector<ll>(21));

//既に組んでる女性の集合がxで表される時
ll ans(ll x){
    if(dp[x]!=-1)return dp[x];
    if(x==0)return dp[x]=1;
    vector<bool> f(N,0);
    ll count=0;
    for(ll i=0;i<N;i++){
        if(x&(1<<i)){f[i]=1;count++;}
    ;}
    ll k=0;
    for(ll i=0;i<N;i++){
        if(f[i]&&a[count-1][i]){
            k+=ans(x-(1<<i));
            k%=MOD;
        }
    ;}
    return dp[x]=k;
}

int main(){
    cin >> N;
    for(ll i=0;i<N;i++){
     for(ll j=0;j<N;j++){
         cin>>a[i][j]
     ;}
    ;}  
    cout<<ans((1<<N)-1)<<endl;

    return 0;
}


Measured memory_bytes: 16640
from functools import reduce

n, m, x = map(int, input().split())
lb = []
for i in range(n):
	lb.append(list(map(int, input().split())))

mincost = 10**8

for i in range(2**n):
	case = [0] * (m+1)
	for j in range(n):
		if (i >> j) & 1:
			case = list(map(sum, zip(case, lb[j])))
	
	if reduce(lambda u, v: u and v, list(map(lambda y: y >= x, case[1:]))):
		mincost = min(mincost, case[0])

if mincost < 10**8:
	print(mincost)
else:
	print(-1)

	
			
			

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

int map[14][14] = {0};

void bomb( int x, int y ) {

  for ( int i = -3; i <= 3; i++ ) {

    if ( map[x+i][y] != 0 ) {
      map[x+i][y] = 0;
      bomb( x+i, y );
    }

    if ( map[x][y+i] != 0 ) {
      map[x][y+i] = 0;
      bomb( x, y+i );
    }

  }

  return;

}

int main() {

  int n;
  cin >> n;

  char input;

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

    for ( int y = 0; y < 8; y++ ) {

      for ( int x = 0; x < 8; x++ ) {

	cin >> input;
	map[x+3][y+3] = input - '0';

      }

    }

    int x_in,y_in;
    cin >> x_in >> y_in;

    bomb( x_in+2, y_in+2 );

    cout << "Data " << i+1 << ":" << endl;

    for ( int y = 0; y < 8; y++ ) {

      for ( int x = 0; x < 8; x++ ) {

	cout << map[x+3][y+3];

      }
      cout << endl;

    }

  }

  return 0;

}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    char a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a==b&&b==c){cout<<"Yes"<<endl;return 0;}
    else if(b==c&&c==d){cout<<"Yes"<<endl;return 0;}
    else{cout<<"No"<<endl;return 0;}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/*******  All Required define Pre-Processors and typedef Constants *******/
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define Dcout(a) cout << setprecision(20) << a << endl
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
using ll = long long;
using PAIR = pair<int, int>;
using Graph = vector<vector<int>>;
const double pi=acos(-1.0);
#define debug cout << "line : " << __LINE__ << " debug" << endl
/****** Template of some basic operations *****/
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; }
/**************************************/
/******** User-defined Function *******/

/**************************************/
/********** Main()  function **********/
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    vector<ll> a(n), b(n), c(n);

    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];

    sort(all(a));
    sort(all(c));

    ll ans = 0;

    rep(i,n){
        int val_b = b[i];

        ll num_a = lower_bound(a.begin(), a.end(), val_b) - a.begin();
        ll num_c = upper_bound(c.begin(), c.end(), val_b) - c.begin();

        ans += (num_a * (n - num_c));
    }

    cout << ans << endl;

}
/********  Main() Ends Here *************/


Measured memory_bytes: 5572
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(ll i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;


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

	ll x, y;
	cin >> x >> y;

	ll ans1, ans2;
	ans2 = (y - 2 * x) / 2;
	ans1 = (y - 4 * ans2) / 2;

	if (ans2<0 || ans1 < 0 || ans1+ans2!=x || ans1*2+ans2*4!=y)
	{
		cout << "No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
	}

	return 0;
}

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

using namespace std;
using ll=long long;
const ll mod = 1e9 + 7;
int dy[] = {1, -1, 0, 0};
int dx[] = {0, 0, 1, -1};

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

    int a;
    int odd=0;
    for (int i = 0; i < N; ++i) {
        cin>>a;
        if(a%2==1){
            odd++;
        }
    }
    if(odd%2==0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e8;
const ll infl = 1LL << 60;
int n,m,q;
vector<int> a,b,c,d;
int ans;
  
void dfs(vector<int> A){
  if(A.size() == n+1){
    int now = 0;
    rep(i,q){
      if(A[b[i]]-A[a[i]] == c[i]) now += d[i];
    }
  
  ans = max(ans,now);
  return;
  }
  A.push_back(A.back());
  while(A.back() <= m){
    dfs(A);
    A.back()++;
  }
}
int main(){
  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);
  rep(i,q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  } 
  dfs(vector<int>(1,1));
  cout << ans << endl;
  return 0;
}

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

int main() {
	int a, b, q;
	string str, comm, sub;

	cin >> str >> q;
	for(int i=0; i<q; i++) {
		cin >>  comm >> a >> b;

		if(comm=="replace") {
			cin >> sub;
			str = str.substr(0,a) + sub + str.substr(b+1, str.size());
		}else if(comm=="reverse") {
			sub = "";
			for(int i=b; i>=a; i--) sub += str[i];
			str = str.substr(0,a) + sub + str.substr(b+1, str.size());
		}else{
			sub = "";
			for(int i=a; i<=b; i++) sub += str[i];
			cout << sub << endl;
		}
	}

	return 0;
}


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

namespace ConsoleApp62 {
    class Program {
        static void Main(string[] args) {
            string S = Console.ReadLine();
            int N = S.Length;

            int ans = N;

            //1010…のパターン
            int ans_A = 0;
            for (int i = 0; i < N; i++) {
                //0, 2, 4...番目の数字が、0のときカウントする
                if (i % 2 == 0 && S[i] == '0') {
                    ans_A++;
                } else if (i % 2 == 1 && S[i] == '1') {
                    ans_A++;
                }
            }
            
            //0101…のパターン
            int ans_B = 0;
            for (int i = 0; i < N; i++) {
                //0, 2, 4...番目の数字が、1のときカウントする
                if (i % 2 == 0 && S[i] == '1') {
                    ans_B++;
                } else if (i % 2 == 1 && S[i] == '0') {
                    ans_B++;
                }
            }

            ans = Math.Min(ans_A, ans_B);

            Console.WriteLine(ans);

        }
    }
}


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

int main(){
    char ch;
    while(1){
        scanf("%c", &ch);
        if(isalpha(ch)){
            if(islower(ch)) printf("%c", toupper(ch));
            else printf("%c", tolower(ch));
        }
        else printf("%c", ch);
        if(ch == '\n') break;
    }
    return 0;
}


Measured memory_bytes: 3156
#include<stdio.h>

int main(void){
        
        int a = 0; //縦
        int b = 0; //横
        int area=0; //面積
        int circuit=0; //周の長さ
        
        scanf("%d",&a);
        scanf("%d",&b);
    
    
            if(1 <= a && b <= 100){
                area=a*b;
                circuit=a*2 + b*2;
            }else{
                printf("整数xは1 ? x ? 100です。もう一度入力して下さい\n");
            }
    
        printf("%d %d\n",area,circuit);
        return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

public class Main{
	public static void main(String[] args)
	{
		Scanner sc =new Scanner(System.in);
		String a=sc.next();
		String b=sc.next();
		
		if(a.equals("H")){
			if(b.equals("H")) System.out.println("H");
			else System.out.println("D");
		}else{
			if(b.equals("H")) System.out.println("D");
			else System.out.println("H");
		}
	}
} 

Measured memory_bytes: 21716
i = input()
j = i.split(' ')
c,b,r = int(j[0]),int(j[1]),int(j[2])
if b == 0:
    print(0)
elif b <= c%(b+r):
    rsl = b*(c//(b+r))+b
    print(rsl)
else:
    rsl = b*(c//(b+r))+(c%(b+r))
    print(rsl)

Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main()
{
  while(true){
    int w;
    int val = 0;
    cin >> w;
    if( w == -1 ) break;
    
    val = 1150;
    int n = 0;
    int vs[] = {125,140,160};
    while(true){
      int t = w - 10*(n+1);
      if( t < 0 ) t = 0;
      if( t > 10 && n <= 1 ) t = 10;
      val += t * vs[n];
      ++n;
      if( n == 3 ) break;
    }
    cout << 4280 - val << endl; 
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
using namespace std;
int main(){
    vector<bool> prime(1000000,true);
    vector<int> p;
    for(int i = 2; i < 1000000; i++)if(prime[i]){
        p.push_back(i);
        for(int j = 2; i*j < 1000000; j++)prime[i*j] = false;
    }
    int n;
    while(cin >> n,n){
        int ans = 0;
        for(int i = 0; i < n; i++)ans += p[i];
        cout << ans << endl;
    }
}



Measured memory_bytes: 3380
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=105;
LL read(){
    LL x=0,f=1;
    char ch=getchar();
    while (!isdigit(ch)&&ch!='-')
        ch=getchar();
    if (ch=='-')
        f=-1,ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+ch-48,ch=getchar();
    return x*f;
}
int n,m=0,L;
int A[N],B[N],C[N];
void push(int a,int b,int c){
    m++;
    A[m]=a;
    B[m]=b;
    C[m]=c;
}
int main(){
    L=read()-1;
    n=20;
    int cnt=1;
    while (L>=0){
        if (L==0){
            if (cnt<n)
                push(cnt,n,0);
            break;
        }
        if (L==1){
            push(cnt,n,0);
            push(cnt,n,1);
            break;
        }
        if (L%2==0)
            push(cnt,n,L);
        L=(L+1)/2;
        push(cnt,cnt+1,0);
        push(cnt,cnt+1,L);
        L--;
        cnt++;
    }
    printf("%d %d\n",n,m);
    for (int i=1;i<=m;i++)
        printf("%d %d %d\n",A[i],B[i],C[i]);
    return 0;
}

Measured memory_bytes: 256
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
const long long MAX = (ll)1e5+100;

vector<ll> dp(13);
vector<ll> mo(10);
string S;

void Update(int i) {
   vector<ll> dp2(13);
   if (S[S.size()-1-i]=='?') {
      rep(k,0,10) {
         rep(j,0,13) {
            dp2[(j+mo[k])%13] += dp[j]%MOD;
         }
      }
   } else {
      int k = S[S.size()-1-i] - '0';
      rep(j,0,13) {
         dp2[(j+mo[k])%13] += dp[j]%MOD;
      }
   }
   swap(dp2,dp);
   rep(k,0,10) {
      mo[k] *= 10;
      mo[k] %= 13;
   }
   return;
}

int main(void) {
   cin>>S;
   rep(i,0,13) dp[i] = 0;
   dp[0] = 1;
   rep(i,0,10) mo[i] = i;
   rep(i,0,S.size()) {
      Update(i);
   }

   // rep(i,0,13) cout<<dp[i]%MOD<<endl;
   cout<<dp[5]%MOD<<endl;





   return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
#define FOR(i, n) for(int i = 1; i<=n; i++)
#define F0R(i, n) for(int i = 0; i<n; i++)
#define mp make_pair
#define pb push_back
#define f first
#define s second


//var 
int n, x, t;

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

	cin >> n >> x >> t;
	cout << ((n+x-1)/x) * t << endl;

	cout.flush();
	return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#pragma warning(disable: 4996)
#define INF (1e9)
#define mod (ll(1e9)+7)

using namespace std;
typedef long long ll;
typedef long double ld;

ll n, r;
ld t, a, minim, x;

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n;
	cin >> t >> a;
	minim = 1e9;
	for (int i = 1; i <= n; i++)
	{
		cin >> x;
		ld ans = t - x * 0.006;
		if (abs(ans - a) < minim)
		{
			minim = abs(ans - a);
			r = i;
		}
	}
	cout << r;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int m, nmin, nmax;

int main() {
    while(1) {
        cin >> m >> nmin >> nmax;
        if(m == 0 && nmin == 0 && nmax == 0) break;
        vector<int> pvec(m, 0);
        for(int i = 0; i < m; ++i) {
            cin >> pvec[i];
        }
        int ans = 0;
        int num = 0;
        for(int i = nmin; i <= nmax; ++i) {
            int pass = pvec[i-1];
            int npass = pvec[i];
            int g = pass-npass;
            if(ans <= g) {
                num = i;
                ans = g;
            }
        }
        cout << num << endl;
    }
}


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

int main(){
    int alunos, checkpoints;
    scanf("%d %d", &alunos, &checkpoints);
    int pos_alunosX[alunos], pos_alunosY[alunos], pos_checkpointsX[checkpoints], pos_checkpointsY[checkpoints], manhattan[checkpoints];
    for (int i = 0; i < alunos; i++){
        scanf("%d %d", &pos_alunosX[i], &pos_alunosY[i]);
    }
    for (int i = 0; i < checkpoints; i++){
        scanf("%d %d", &pos_checkpointsX[i], &pos_checkpointsY[i]);
    }
    for (int i = 0; i < alunos; i++){
        int menor = 0, dist[50] = {};
        for (int j = 0; j < checkpoints; j++){
            manhattan[j] = abs(pos_alunosX[i] - pos_checkpointsX[j]) + abs(pos_alunosY[i] - pos_checkpointsY[j]);
            if (manhattan[j] < manhattan[menor])
                menor = j;
        }
        printf("%d\n", menor+1);
    }
    return 0;
}


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

string s;

int main() {
    cin >> s;

    string rud = "RUD";
    string lud = "LUD";
    for(lint i = 0; i < s.size(); i++) {
        if(i % 2 == 0 && rud.find(s[i]) != string::npos)  continue;
        if(i % 2 == 1 && lud.find(s[i]) != string::npos)  continue;
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
}

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

int n, ai, sum;
bitset<2000001> dp[2];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	dp[0][0]=1;
	for(int i=0; i<n; ++i) {
		cin >> ai;
		dp[i&1^1]=dp[i&1]|(dp[i&1]<<ai);
		sum+=ai;
	}
	for(int i=sum/2; i>=0; --i) {
		if(dp[n&1][i]) {
			cout << sum-i;
			break;
		}
	}
}

Measured memory_bytes: 1536
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <queue>
#include <list>
#include <string>
using namespace std;

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

int main()
{
  ll N,B_ct = 0, W_ct = 0,B_ct_ = 0, W_ct_ = 0,min;
  cin >> N;
  min = N;
  char S[2*100000];
  for(int i=0;i<N;i++){
    cin >> S[i];
    if(S[i] == '.') W_ct++;
    else B_ct_++;
  }
  for(int i=0;i<N;i++){
    if(S[i] == '.') W_ct--;
    else B_ct++;
    if(min > W_ct+B_ct) min = W_ct+B_ct;
  }
    for(int i=N-1;i>=0;i--){
    if(S[i] == '#') B_ct_--;
    else W_ct_++;
    if(min > W_ct_+B_ct_) min = W_ct_+B_ct_;
  }
  cout << min;
}


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

string field[15];

void dfs(int x, int y){
    if(x>=0 && x<12 && y>=0 && y<12){
    if(field[x][y]=='1'){
        field[x][y]='2';
        dfs(x+1, y);
        dfs(x-1, y);
        dfs(x, y+1);
        dfs(x, y-1);
    }
    }
}


int main(void){
    while(cin >> field[0]){
        for(int i=1; i<12; i++){
            cin >> field[i];
        }
        int sum = 0;
        for(int i=0; i<12; i++){
            for(int j=0; j<12; j++){
                if(field[i][j]=='1'){
                dfs(i, j);
                sum++;
                }
            }
        }
        cout << sum << endl;
    }
    
    
    return 0;
}


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

int main(){
	int n;
	int p[100000];
	int c = 0;
	for(int i = 2; i < 300000; i++){
		int f = 0;
		for(int j = 2; j <= sqrt(i); j++){
			if(i%j ==0) f= 1;
		}
		if(f == 0){
			p[c] = i;
			c++;
		}
	}
	cin>>n;
	while(n!=0){
		int ans = 0;
		int m=0,M=0;
		for(int i = 0; i < c; i++){
			 if(m == 0&&p[i] > n)m = i;
			 else if(M == 0&&p[i] > 2*n)M = i -  1;
		}
		cout << M-m+1 << endl;
		cin >> n;
	}
	return 0;
}


Measured memory_bytes: 3204
/*Stay true to yourself, yet always be open to learn. Work hard, and never give up on your dreams, 
even when nobody else believes they can come true but you. These are not cliches but real tools you 
need no matter what you do in life to stay focused on your path.
*/

 /*Pppppppp    UU      UU     CCCCCCCC    CCCCCCCC     HH     HH     UU      UU
   pp    pp    UU      UU     CC          CC           HH     HH     UU      UU
   pp    pp    UU      UU     CC          CC           HHHHHHHHH     UU      UU
   pppppppp    UU      UU     CC          CC           HHHHHHHHH     UU      UU
   pp          UU      UU     CC          CC           HH     HH     UU      UU
   pp          UUUUUUUUUU     CCCCCCCC    CCCCCCCC     HH     HH     UUUUUUUUUU
   */

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long l,r;
    cin >> l >> r;
    long long d1 = l/2019;
    long long d2 = r/2019;
    int m1 = l%2019;
    int m2 = r%2019;

    if(d1==d2)
    {
        int n = m2-m1+1;
        int a[n]={0};
        //int j=0;
        for(int i=0;i<n;i++)
        {
            a[i]=m1+i;
           // cout<<a[i]<<endl;
        }
        int min= 2019;
        for(int i=0;i<n;i++)
        {
            for(int j=i+1;j<n;j++)
            {
               int k = (a[i]*a[j])%2019;
               if(k<min){
               min = k;
               //cout<<a[i]<<" "<<a[j]<<endl;
               }
            }

        }
        cout<<min<<endl;
        
    }
    else
    cout<<0;
    //cout<<" "<<sqrt(2019);
    return 0;
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  string head, foot;
  head = "";
  foot = "";
  int q;
  cin >> s>>q;
  bool desc = true;
  int t, f;
  char c;

  for(int i=0; i<q; i++){
    cin >> t;
    if(t==1) desc = !desc;
    else{
      cin >> f>>c;
      if((f==1 && desc) || (f==2 && !desc))
        head = c + head;
      else
        foot = foot + c;
    }
  }

  if(desc)
    cout << head + s + foot << endl;
  else{
    reverse(s.begin(), s.end());
    reverse(head.begin(), head.end());
    reverse(foot.begin(), foot.end());
    cout << foot + s + head << endl;
  }

  return 0;
}


Measured memory_bytes: 1424
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int c = sc.nextInt();
		int[][] table = new int[c + 1][c + 1];
		for (int i = 1; i <= c; i++) {
		    for (int j = 1; j <= c; j++) {
		        table[i][j] = sc.nextInt();
		    }
		}
		ArrayList<Integer>[] lists = new ArrayList[3];
		for (int i = 0; i < 3; i++) {
		    lists[i] = new ArrayList<Integer>();
		}
		for (int i = 1; i <= n; i++) {
		    for (int j = 1; j <= n; j++) {
		        lists[(i + j) % 3].add(sc.nextInt());
		    }
		}
		int[][] order = new int[3][c];
		for (int i = 0; i < 3; i++) {
		    for (int j = 1; j <= c; j++) {
		        int sum = 0;
		        for (int x : lists[i]) {
		            sum += table[x][j];
		        }
		        order[i][j - 1] = sum;
		    }
		}
		long min = Long.MAX_VALUE;
		for (int i = 0; i < c; i++) {
		    for (int j = 0; j < c; j++) {
		        if (i == j) {
		            continue;
		        }
		        for (int k = 0; k < c; k++) {
		            if (i == k || j == k) {
		                continue;
		            }
		            min = Math.min(min, order[0][i] + order[1][j] + order[2][k]);
		        }
		    }
		}
	    System.out.println(min);
   }
}




Measured memory_bytes: 79828
def main():
    while True:
        m,minn,maxn = map(int,input().split())
        if m == 0 and minn == 0 and maxn == 0:
            return
        scores = []
        for _ in range(m):
            p = int(input())
            scores.append(p)
        ans,ansgap = 0,0
        for n in range(minn,maxn+1):
            gap = scores[n-1] - scores[n]
            if gap >= ansgap:
                ansgap = gap
                ans = n
        print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5620
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i, n) for (int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"
#define fcout cout << fixed << setprecision(18)

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926535
/*
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
*/
#define ll long long int         // 10^18
#define INF 1000000001           // 1e9+1
#define LINF 1000000000000000001 // 1e18+1

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
//---------------------------
class ModuloCombination {
private:
  vector<ll> fact, fact_inv;

  static ll mod_pow(ll a, ll n){
    if(n == 0) return 1;
    if(n%2 == 0) return mod_pow((a * a) % MOD, n / 2);
    return (a * mod_pow(a, n - 1)) % MOD;
  }

public:
  ModuloCombination(ll N): fact(N + 1), fact_inv(N + 1) {
    fact[0]=1;
    for(ll i = 1; i < N + 1; i++) {
      fact[i] = (i * fact[i - 1]) % MOD;
    }
    for(ll i = 0; i < N + 1; i++) {
      fact_inv[i] = mod_pow(fact[i], MOD - 2);
    }
  }

  ll operator()(ll n, ll r) {
    return (((fact[n] * fact_inv[r]) % MOD) * fact_inv[n - r]) % MOD;
  }
};
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    
    ll h,w,a,b;cin>>h>>w>>a>>b;
    ModuloCombination C(h+w);
    
    ll ans=0;
    for(ll i=b+1;i<=w;i++){
        ans += C(h-a+i-2, h-a-1) * C(a+w-i-1, a-1) % MOD;
        ans %= MOD;
    }
    P(ans);

    return 0;
}

Measured memory_bytes: 3328
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
b = a[::-1]
ai = [a[0]]
bi = [b[0]]
for i in range(1, n):
    ai.append(gcd(ai[i-1], a[i]))
    bi.append(gcd(bi[i-1], b[i]))
ans = max(ai[n-2], bi[n-2])
for i in range(1, n-1):
    ans = max(gcd(ai[i-1], bi[n-i-2]), ans)
print(ans)


Measured memory_bytes: 16064