akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int a, b, n;
        cin >> a >> b >> n;
        if(a == 0)
            return 0;
        
        vector<vector<bool> > ng(a+1, vector<bool>(b+1, false));
        for(int i=0; i<n; ++i){
            int c, d;
            cin >> c >> d;
            ng[c][d] = true;
        }

        vector<vector<int> > num(a+1, vector<int>(b+1, 0));
        num[0][1] = 1;
        for(int i=1; i<=a; ++i){
            for(int j=1; j<=b; ++j){
                if(ng[i][j])
                    continue;
                num[i][j] = num[i-1][j] + num[i][j-1];
            }
        }
        cout << num[a][b] << endl;
    }
}

Measured memory_bytes: 0
from decimal import *
a,b,c = map(int,input().split())
getcontext().prec = 50
if Decimal(a)**Decimal(0.5) + Decimal(b)**Decimal(0.5) < Decimal(c)**Decimal(0.5):
    ans = "Yes"
else:
    ans = "No"
print(ans)

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

int main() {
	long long n, k, ans = 0; cin >> n >> k;
	for (long long b = k + 1; b <= n; b++) {
		long long m = n / b;
		ans += (b - k) * m + max(n - (b * m + k - 1), 0LL) - (k == 0 ? 1 : 0);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

typedef unsigned long long UL;
typedef long long LL;
typedef long double LD;
#define LP(i, a, b) for (LL i = int(a); i < int(b); i++)
#define LPE(i, a, b) for (LL i = int(a); i <= int(b); i++)
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<vector<PII> > WAL;
typedef vector<vector<int> > SAL;
#define Ep 1e-8
#define INF 1e9
#define LINF 1e18

LL const MOD = 1e9 + 7;
LL const MaxSize = 2e5 + 5;
//LL const MOD = 998244353;

/*

 https://atcoder.jp/contests/abc132/tasks/abc132_d
 D - Blue and Red Balls

 Easy problem, but python version gives TLE in the last two cases
 */

//NOTE WORKS ONLY WHEN MOD IS PRIME

int main() {
	ios_base::sync_with_stdio(false);
	//freopen("/Users/georgeli/A_1.in", "r", stdin);

	LL S, b;
	cin >> S;
	b = 1e9;

	LL y3 = (b - (S % b)) % b;
	LL x3 = (S + y3)/ b;
	printf("%d %d %d %d %d %d", 0, 0, 1, b, x3, y3);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <iomanip>
#include <cmath>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ll long long
using namespace std;
const ll N = 2e5 + 42;
ll naive(ll cur) {
  ll ans = 0;
  while(cur) {
    ll pp = __builtin_popcountll(cur);
    cur %= pp;
    ans++;
  }
  return ans;
}
ll pt[2][N] = {0};
int main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  ll n = 0, beg = 0;

  string x;

  cin >> n >> x;

  pt[0][0] = 1;
  pt[1][0] = 1;

  for(ll i = 0; i < n; i++) beg += x[i] == '1';

  if(beg - 1 > 0) pt[0][0] %= (beg - 1);
  pt[1][0] %= (beg + 1);

  for(ll i = 1; i < N; i++) {
    if(beg - 1 > 0) pt[0][i] = (pt[0][i - 1] * 2) % (beg - 1);
    pt[1][i] = (pt[1][i - 1] * 2) % (beg + 1);
  }

  reverse(all(x));

  ll ans[2] = {0, 0};

  for(ll i = 0; i < n; i++) {
    ans[0] += pt[0][i] * (x[i] - '0');
    ans[1] += pt[1][i] * (x[i] - '0');
    if(beg - 1 > 0) ans[0] %= (beg - 1);
    ans[1] %= (beg + 1);
  }

  vector<ll> totans(n);

  for(ll i = 0; i < n; i++) {
    string cx = x;
    ll curpp = beg, cur = 0;
    ll ind = (cx[i] == '0');
    if(cx[i] == '1') curpp--;
    else curpp++;
    if(curpp == 0) totans[i] = 0;
    else {
      cur = ans[ind];
      if(cx[i] == '1') cur -= pt[ind][i];
      else cur += pt[ind][i];
      cur %= curpp;
      while(cur < 0) cur += curpp;
      totans[i] = naive(cur) + 1;
    }
  }

  for(ll i = n - 1; i >= 0; i--) cout << totans[i] << '\n';

  return 0;
}
/*

*/


Measured memory_bytes: 8356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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;}
const ll INF = 1LL<<60;

int main()
{
  ll n;cin>>n;
  string s;cin>>s;
  ll i=2,ans=0;
  while(i<n){
    if(s[i-2]=='A'&&s[i-1]=='B'&&s[i]=='C'){
      ans++;i+=3;
    }else{
      i++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
N, X = gets.chomp.split(" ").map(&:to_i)
Ax = gets.chomp.split(" ").map(&:to_i)

ax = Ax.sort

count = 0
amount = 0
loop do
  amount += ax.shift
  break if amount > X
  if ax.size == 0
    count += 1 if amount == X
    break
  end
  count += 1
end

puts count


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

int main() {
	int n;
	cin >> n;
	vector <int> a(n);
	for(int i = 0;i<n;i++) cin >> a[i];
	sort(a.begin(),a.end());
	for(int i = 0;i<n-1;i++){
		if(a[i] == a[i+1]){
			cout << "NO" << endl;
			return 0;
		}
		}
	cout << "YES" << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    ll n, k, s;
    cin >> n >> k >> s;
    vector<ll> A(n);
    rep(i, n) {
        if(i < k) A[i] = s;
        else {
            if(s == 1000000000) A[i] = 1;
            else A[i] = s + 1;
        }
    }
    rep(i, n) {
        cout << A[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 2048
def bubble_sort(n, nums):
    flag = 1
    cnt = 0
    while flag:
        flag = 0
        for i in range(n-1, 0, -1):
            if nums[i] < nums[i-1]:
                tmp = nums[i]
                nums[i] = nums[i-1]
                nums[i-1] = tmp
                flag = 1
                cnt += 1
    print(' '.join(map(str, nums)))
    print(cnt)

def main():
    n = int(input())
    line = input()
    nums = list(map(int, line.split()))

    bubble_sort(n, nums)

if __name__ == "__main__":
    main()


Measured memory_bytes: 5600
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>

using namespace std;

#define N 3
#define N2 9

struct Puzzle {
	int f[N2];
	int space;
	string path;

	bool operator <(const Puzzle p) const {
		for (int i = 0; i < N2; ++i) {
			if (f[i] == p.f[i])
				continue;
			return f[i] > p.f[i];
		}
		return false;
	}
};

bool isComplete(Puzzle p) {
	for (int i = 0; i < N2; ++i) {
		if (p.f[i] != i + 1)
			return false;
	}
	return true;
}

const int dx[4] { -1, 0, 1, 0 };
const int dy[4] { 0, -1, 0, 1 };
const char dir[4] { 'u', 'l', 'd', 'r' };

string bfs(Puzzle p) {
	queue<Puzzle> Q;
	p.path = "";
	Q.push(p);
	Puzzle u, v;
	map<Puzzle, bool> M;
	M[p] = true;
	while (!Q.empty()) {
		u = Q.front();
		Q.pop();
		if (isComplete(u))
			return u.path;
		int sx = u.space / N;
		int sy = u.space % N;
		for (int r = 0; r < 4; ++r) {
			int tx = sx + dx[r];
			int ty = sy + dy[r];
			if (tx < 0 || ty < 0 || tx >= N || ty >= N)
				continue;
			v = u;
			swap(v.f[u.space], v.f[tx * N + ty]);
			v.space = tx * N + ty;
			if (!M[v]) {
				M[v] = true;
				v.path += dir[r];
				Q.push(v);
			}
		}
	}

	return "unresolved";
}

int main() {
	Puzzle p;
	for (int i = 0; i < N2; ++i) {
		scanf("%d", &p.f[i]);
		if (p.f[i] == 0) {
			p.f[i] = N2;
			p.space = i;
		}
	}
	string ans = bfs(p);
	cout << ans.size() << endl;

	return 0;
}

Measured memory_bytes: 30656
#include <iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    int count=0;
    for(int i=1;i<=N;i+=2){
        int count2=0;
        for(int j=1;j<=i;j++){
            if(i%j==0) count2++;
        }
        if(count2==8){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  int t[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> t[i];
  }
  int m;
  cin >> m;
  int p[m + 1], x[m + 1];
  for (int i = 1; i <= m; i++) {
    cin >> p[i] >> x[i];
  }

  for (int i = 1; i <= m; i++) {
    int sum = 0;
    for (int j = 1; j <= n; j++) {
      if (j == p[i]) {
        sum += x[i];
      } else {
        sum += t[j];
      }
    }
    cout << sum << endl;
    sum = 0;
  }
  return 0;
}

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

using ll = long long;
const int INF = 1001001001;

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

int main(void)
{
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p[i];

  bool flag = false;
  int point = INF;
  rep(i,n) {
    if (p[i] == i+1) continue;
    if (!flag) {
      flag = true;
      point = i;
    } else {
      int tmp;
      tmp = p[point];
      p[point] = p[i];
      p[i] = tmp;
      break;
    }
  }

  bool result = true;
  rep(i,n) {
    if (i+1 == p[i])  continue;
    else result = false;
  }

  result ? cout << "YES" << endl : cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int N, M;
char b1[60][60], b2[60][60];

signed main() {
    cin >> N >> M;
    cin.ignore();
    rep(i,0,N) {
        rep(j,0,N) {
            cin >> b1[i][j];
            // printf("%c", b1[i][j]);
        }
        // cout << endl;
    }
    rep(i,0,M) {
        rep(j,0,M) {
            cin >> b2[i][j];
            // printf("%c", b2[i][j]);
        }
        // cout << endl;
    }

    rep(i,0,N-M+1) rep(j,0,N-M+1) {
        bool ok = true;
        rep(x,0,M) rep(y,0,M) {
            if(b1[i+x][j+y] != b2[x][y]) {
                ok = false;
            }
        }
        if(ok) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    using ll=long long;
    int main()
    {
       ios::sync_with_stdio(0);
       cin.tie(0);
       int n;
       cin>>n;
       int x=n%10;
       if(x==2||x==4||x==5||x==7||x==9)
       cout<<"hon";
       else if(x==0||x==1||x==6||x==8)
       cout<<"pon";
       else
       cout<<"bon";
        return 0;
    }

Measured memory_bytes: 3648
# coding: utf-8
# Your code here!

N, M, Q = map(int, input().rstrip().split(' '))

count = [[0] * (N + 1) for _ in range(N+1)]
memo = [[0] * (N + 1) for _ in range(N+1)]

for _ in range(M):
    p, q = map(int, input().rstrip().split(' '))
    count[p][q] += 1

for i in range(1,N+1):
    for j in range(1,N+1):
        memo[i][j] = count[i][j] + memo[i-1][j] + memo[i][j-1] - memo[i-1][j-1]

for i in range(Q):
    p, q = map(int, input().rstrip().split(' '))
    print(memo[q][q] - memo[p-1][q] - memo[q][p-1] + memo[p-1][p-1])
    

Measured memory_bytes: 58840
#include <iostream>
#include <algorithm>

using namespace std;
#define ll long long
int main(){
    int n;
    cin >> n;
    ll ans=0;
    int said[n];
    for(int i=0;i<n;i++){
        cin>>said[i];
    }
    sort(said,said+n);
    int bef=0;
    int cnt=0;
    for(int i=0;i<n;i++){
        if(said[i]!=bef){
//            cout <<"aa"<<endl;
            ans+=cnt%2;
            bef=said[i];
            cnt=0;
        }
//        cout <<said[i]<<endl;
        cnt++;
    }
    ans+=cnt%2;
    cout <<ans<<endl;
    return 0;
}

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

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

    h[0]--;
    for(int i=1;i<n;i++){
        if(h[i-1]<h[i]) h[i]--;
    }
    for(int i=0;i<n-1;i++){
        if(h[i]>h[i+1]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl

const int N=2e5+5;

string s;
int n;

bool check(int k)
{
   char cur=s[0];
   int i;
   for(i=1;i<k&&i+k-1<n&&i<n;i++)
   {
      if(s[i]!=cur)
      {
         if(cur=='0')
            cur='1';
         else
            cur='0';
      }
   }
   bool check=1;
   for(;i<k;i++)
   {
      if(s[i]!=cur)
         check=0;
   }
   cur=s[n-1];
   int ct=0;
   for(i=n-2;i<=k;i--)
   {
      if(ct==k-1)
         break;
      ct++;
      if(s[i]==cur)
      {
         if(cur=='0')
            cur='1';
         else
            cur='0';
      }
      if(ct==k-1)
         break;
   }
   bool check2=1;
   for(;ct<=k;i--)
   {
      if(s[i]!=cur)
         check2=0;
      ct++;
   }
   return (check||check2);
}

int binsearch(int lo, int hi)
{
   while(lo<hi)
   {
      int mid=(lo+hi+1)>>1;
      if(check(mid))
         lo=mid;
      else
         hi=mid-1;
   }
   return lo;
}

int32_t main()
{
   IOS;
   cin>>s;
   n=s.size();
   int ans=binsearch(0 , n);
   cout<<ans;
   return 0;
}

Measured memory_bytes: 640
/* ex3_4
   KKOO  */

#include <stdio.h>

int main(void) {
    int num,i,j,result;
    //整数の入力
    scanf("%d",&num);

    //九九の計算
    i = 0;
    j = 0;
    result=0;
    for(i=1; i < 10; i++){
        for(j=1; j < 10; j++){
            //九九が一致したらresultを1にする
            if(i*j == num){
                result = 1;
            }
        }
    }

    //resultが1ならYes
    if(result == 1){
        printf("Yes\n");
    }
    //resultが0ならNo
    else{
        printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 128
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    s = SI()

    res = 0
    for l in range(len(s)):
        for r in range(l, len(s)):
            t = s[l:r + 1]
            if all([1 if c in 'ACGT' else 0 for c in t]):
                res = max(res, len(t))

    return res


print(main())


Measured memory_bytes: 3064
import copy
N = int(input())
H = [i for i in map(int,input().split())]
res = 0
while True:
  i = 0
  if max(H) == 0:
    break
  while (i<N):
    if H[i] == 0:
      i += 1
    else:
      res += 1
      while (i < N and H[i] > 0):
        H[i] -= 1
        i += 1
print(res)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(x, a) for(auto &x : a)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second

using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
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; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

int n, k;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> k;
    int ans = 1;
    rep(i, 0, n) {
      if (ans <= k) ans *= 2;
      else ans += k;
    }
    cout << ans << endl;
    return 0;
}



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

class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String str = br.readLine();

//		StringTokenizer st = new StringTokenizer(str," ");
		
		String[] strAry = str.split(" ");
		
		int ar[] = new int[3];

		for (int i=0;i<3;i++){
			 ar[i] = Integer.parseInt(strAry[i]);
		}
		
		Arrays.sort(ar);			
		System.out.println(ar[0] +" "+ar[1]+" "+ar[2] );
	}
}

Measured memory_bytes: 24264
#include <bits/stdc++.h>
using namespace std;
int main() {
  int R;
  cin >> R;
  if (R < 1200) {
    cout << "ABC" << endl;
  }
  else if (R < 2800) {
    cout << "ARC" << endl;
  }
  else {
    cout << "AGC" << endl;
  }
}

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

const int MAXN = 200005;
int pre[MAXN], suf[MAXN];
string s;

int main () {
    int n, k, c;
    cin >> n >> k >> c;
    cin >> s;

    int lst = -c-1, sum = 0;
    for (int i=0; i<n; i++) {
        if (s[i] == 'o' && i - lst > c) {
            lst = i;
            sum++;
        }
        pre[i] = sum;
    }

    lst = n+c+1, sum = 0;
    for (int i=n-1; i>=0; i--) {
        if (s[i] == 'o' && lst - i > c) {
            lst = i;
            sum++;
        }
        suf[i] = sum;
    }

    assert(pre[n-1] >= k && suf[0] >= k);
    for (int i=0; i<n; i++) {
        if (s[i] == 'o' && (i?pre[i-1]:0) + suf[i+1] < k) {
            cout << i + 1 << endl;
        }
    }
}


Measured memory_bytes: 3332
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define INF 1e9
typedef long long llong;
using namespace std;

int main(){
	int n;
	cin>>n;
	
	int top=0;
	int ans=0;
	REP(i,n){
		int tmp;
		cin>>tmp;
		if(tmp>=top) ans++;
		top=max(top,tmp);
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 256
function main(D){
    if(D=="22\n"){
      console.log("Christmas Eve Eve Eve");
    } else if (D=="23\n"){
        console.log("Christmas Eve Eve");
    } else if (D=="24\n"){
        console.log("Christmas Eve");
    } else if (D=="25\n"){
        console.log("Christmas");
    } 
    }
    main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 21192
//26
#include<iostream>
#include<set>
#include<string>
#include<vector>

using namespace std;

vector<string> rot(vector<string> d,int a,int b,int c,int x){
  string t=d[a];
  d[a]=d[b];
  d[b]=d[c];
  d[c]=d[x];
  d[x]=t;
  return d;
}

vector<string> rotu(vector<string> d){
  return rot(d,0,1,5,4);
}

vector<string> rotr(vector<string> d){
  return rot(d,3,0,2,5);
}

vector<string> roth(vector<string> d){
  return rot(d,1,2,4,3);
}

int main(){
  for(int n;cin>>n,n;){
    set<vector<string> > s;
    for(int i=0;i<n;i++){
      vector<string> d(6);
      for(int j=0;j<6;j++){
	cin>>d[j];
      }
      for(int j=0;j<6;j++){
	if(j%2){
	  d=rotu(d);
	}else{
	  d=rotr(d);
	}
	for(int k=0;k<4;k++){
	  d=roth(d);
	  s.insert(d);
	}
      }
    }
    cout<<n-s.size()/24<<endl;
  }
  return 0;
}

Measured memory_bytes: 1288
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
/* #include <regex> */

using namespace std;

/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */

/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

/* the recursive version can't go to 2e5 */

const int inf = 1e9;
int n; string s;

bool isW(const int i)
{ return s[i] == '.'; }
bool isB(const int i)
{ return !isW(i); }

int main()
{
#ifdef foo_
    freopen("foo", "rt", stdin);
#endif
    ios::sync_with_stdio(false);
    while (cin >> n >> s) {
        s = '.' + s; n++;
        int sumB[n+1], sumW[n+1];
        memset(sumB,0,sizeof(sumB));
        memset(sumW,0,sizeof(sumW));
        FOR(i,1,n)
            sumB[i] += sumB[i-1] + isB(i);
        FORR(i,n-1,0)
            sumW[i] += sumW[i+1] + isW(i);
        int ans = min(sumB[n-1], sumW[1]);
        FOR(i,1,n)
            ans = min(ans, sumB[i] + sumW[i+1]);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 2128
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	register int number_read=0,if_ok_read=1;
	char ch_read=getchar();
	while(ch_read<'0'||ch_read>'9')
	{
		if(ch_read=='-')
			if_ok_read=-1;
		ch_read=getchar();
	}
	while(ch_read>='0'&&ch_read<='9')
	{
		number_read=number_read*10+ch_read-'0';
		ch_read=getchar();
	}
	return number_read*if_ok_read;
}
inline void write(register int x_write)
{
    if(x_write<0)
	{
    	putchar('-');
		x_write=-x_write;
	}
    if(x_write>9)
		write(x_write/10);
    putchar(x_write%10+'0');
    return ;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	char ch=getchar();
	if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
		printf("vowel");
	else
		printf("consonant");
	putchar('\n');
	return 0;
}


Measured memory_bytes: 256
from collections import deque


def main():
    height, width = [int(x) for x in input().split()]
    init_h, init_w = [int(x) - 1 for x in input().split()]
    dest_h, dest_w = [int(x) - 1 for x in input().split()]
    grid = [input() for _ in range(height)]

    adjacents = (
        (1, 0),
        (0, 1),
        (-1, 0),
        (0, -1)
    )

    def gen_warp_can_reach():
        for h in range(-2, 3):
            for w in range(-2, 3):
                if h == 0 == w:
                    continue
                if (h, w) in adjacents:
                    continue
                yield (h, w)

    warp_can_reach = tuple(gen_warp_can_reach())

    qu = deque()
    qu.append((init_h, init_w))
    arrived_total = set()
    arrived_total.add((init_h, init_w))
    distances = [[-1] * width for _ in range(height)]
    warp_count = 0

    def append_qu(now_h, now_w, next_go_to):
        """行き先へ進めそうならキューに追加し， arrived_total に記録する。"""
        for h_delta, w_delta in next_go_to:
            new_h, new_w = h + h_delta, w + w_delta
            if new_h < 0 or new_h >= height or new_w < 0 or new_w >= width:
                continue
            if (new_h, new_w) in arrived_total:
                continue
            if grid[new_h][new_w] == '#':
                arrived_total.add((new_h, new_w))
                continue
            qu.append((new_h, new_w))
            arrived_total.add((new_h, new_w))

    while qu:
        arrived_set_by_cost = set()
        # ワープなしのBFS
        while qu:
            h, w = qu.popleft()
            distances[h][w] = warp_count
            arrived_set_by_cost.add((h, w))
            append_qu(h, w, adjacents)

        warp_count += 1
        # 1回ワープして行ける場所を列挙し，次期スタート地点とする。
        for h, w in arrived_set_by_cost:
            append_qu(h, w, warp_can_reach)

    return distances[dest_h][dest_w]


if __name__ == '__main__':
    print(main())


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define MP make_pair
#define PB push_back

typedef pair<double, int> pdi;
typedef vector<pdi> vp;

int main() {
	vp v[4];
	
	REP(i, 3) {
		REP(j, 8) {
			int num;
			double t;
			scanf("%d %lf", &num, &t);
			v[i].PB(MP(t, num));
		}
		sort(v[i].begin(), v[i].end());
	}
	
	REP(i, 3) {
		REP(j, 2) {
			cout << v[i][j].second << " " << v[i][j].first << endl;
		}
		FOR(j, 2, 8)
			v[3].PB(v[i][j]);
	}
	
	sort(v[3].begin(), v[3].end());
	REP(i, 2) cout << v[3][i].second << " " << v[3][i].first << endl;
	
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	char c[10][10];
	REP(i, 2){
		REP(j, 3) cin>>c[i][j];
	}
	bool ok=true;
	REP(i, 3){
		if(c[0][i]!=c[1][2-i]) ok=false;
	}
	ok ? cout<<"YES"<<'\n' : cout<<"NO"<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; ll s; cin>>n>>s;
	deque<ii> dq;
	for(int i=0;i<n;i++)
	{
		ll x,p; cin>>x>>p; dq.pb(mp(x,p));
	}
	ll ans=0; vector<ll> V;
	while(!dq.empty()&&dq.front().fi<s&&dq.back().fi>s)
	{
		if(dq.front().se>=dq.back().se)
		{
			dq.front().se+=dq.back().se;
			V.pb(dq.back().fi);
			dq.pop_back();
		}
		else
		{
			dq.back().se+=dq.front().se;
			V.pb(dq.front().fi);
			dq.pop_front();
		}
	}
	if(s>=dq.front().fi) V.pb(dq.front().fi);
	else V.pb(dq.back().fi);
	V.pb(s);
	for(int i=0;i+1<V.size();i++) ans+=abs(V[i]-V[i+1]);
	cout<<ans<<'\n';
}


Measured memory_bytes: 2632
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    s=input()
    k=int(input())
    ans=1
    # k文字目までずっと１だったらans=1
    # そうじゃないなら1以外の数で最初に出てくるやつがans
    for i in range(k):
        if s[i]!='1':
            ans=s[i]
            break
    print(ans)
resolve()

Measured memory_bytes: 38256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <unordered_map>
#define maxn 100005
#define mod 1000000007
using namespace std;
typedef long long LL;
int main()
{
    int n;
    scanf("%d",&n);
    int a[2*maxn];
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    int minn=a[0],ans=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]<=minn)
        {
            ans++;
            minn=a[i];
        }
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <cctype>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

struct dice{
    ll p1,p2,p3,p4,p5,p6;
};

void rotate (dice& d, char c){
    dice e=d;
    if(c=='S'){
        e.p2=d.p1;
        e.p6=d.p2;
        e.p5=d.p6;
        e.p1=d.p5;
    }
    if(c=='N'){
        e.p1=d.p2;
        e.p2=d.p6;
        e.p6=d.p5;
        e.p5=d.p1;
    }
    if(c=='E'){
        e.p3=d.p1;
        e.p6=d.p3;
        e.p4=d.p6;
        e.p1=d.p4;
    }
    if(c=='W'){
        e.p1=d.p3;
        e.p3=d.p6;
        e.p6=d.p4;
        e.p4=d.p1;
    }
    d=e;
}

int main(){
    dice d;
    cin >> d.p1 >> d.p2 >> d.p3 >> d.p4 >> d.p5 >> d.p6;
    string s;
    cin >> s;
    rep(i,s.size()){
        rotate(d,s.at(i));
    }
    cout << d.p1 << endl;
}


Measured memory_bytes: 3204
s = input()
l, count = [], 0
for i in s:
    if i=='>': count+=1
    else:
        if count: l.append(count)
        count = 0
if count: l.append(count); count = 0
j = 0
ans = []
if s[0]=='<': ans.append(0)
else:
    ans.append(l[0])
    l[0]-=1

for i in range(len(s)):
    if s[i]=='<': ans.append(ans[-1]+1)
    else:
        if i==0: ans.append(ans[-1]-1); continue
        if l[j]==0: j+=1
        if ans[-1]>=l[j]:
            l[j]-=1
            ans.append(l[j])
                
        else:
            ans[-1]=l[j]
            l[j]-=1
            ans.append(l[j])
print(sum(ans))


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

bool is_upper(char c)
{
    if ('A' <= c && c <= 'Z')
    {
        return true;
    }
    else
    {
        return false;
    }
}

bool is_lower(char c)
{
    if ('a' <= c && c <= 'z')
    {
        return true;
    }
    else
    {
        return false;
    }
}

int main()
{
    char c;
    int diff = 'A' - 'a';
    string str;
    getline(cin, str);

    for (auto c : str)
    {
        if (is_lower(c))
        {
            cout << (char)(c + diff);
        }
        else if (is_upper(c))
        {
            cout << (char)(c - diff);
        }
        else
        {
            cout << c;
        }
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<string> a(n);
  vector<string> b(m);
  for(int i=0;i<n;i++)
    cin>>a.at(i);
  for(int i=0;i<m;i++)
    cin>>b.at(i);
  bool c=0;
  for(int i=0;i+m-1<n;i++){
    for(int j=0;j+m-1<n;j++){
      bool f=1;
      for(int y=0;y<m;y++)
        for(int x=0;x<m;x++)
          f=(a.at(y+i).at(x+j)!=b.at(y).at(x)?0:f);
      c=(f?1:c);
    }
  }
  cout<<(c?"Yes":"No")<<endl;
}

Measured memory_bytes: 3628
n=int(input())
s=input()
p=0
for i in range(10):
  pi=s.find(str(i))
  if pi==-1:
    continue
  for j in range(10):
    pj=s.find(str(j),pi+1)
    if pj==-1:
      continue
    for k in range(10):
      pk=s.find(str(k),pj+1)
      if pk==-1:
        continue
      p=p+1
print(p)

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

typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string str;
    int q,mp=0,t;
    deque<char>d;
    cin>>str>>q;
    for(int i=0;i<str.size();i++)
    {
        d.push_back(str[i]);
    }
    while(q--)
    {
        cin>>t;
        if(t==1)
        {
            mp++;
        }
        else
        {
            int f;
            char c;
            cin>>f>>c;
            if(mp%2)
            {
                if(f==1)
                {
                    d.push_back(c);
                }
                else
                {
                    d.push_front(c);
                }
            }
            else
            {
                if(f==2)
                {
                    d.push_back(c);
                }
                else
                {
                    d.push_front(c);
                }
            }
        }
    }
    if(mp%2)
    {
        for(int i=d.size()-1;i>=0;i--)
        {
            cout<<d[i];
        }
        cout<<endl;
    }
    else
    {
        for(int i=0;i<d.size();i++)
        {
            cout<<d[i];
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 976
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
}
template<class T> inline void chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
}

typedef complex<long double> co;
const long double EPS = 1e-10;
bool EQ(long double a, long double b) {
    return (abs(a-b) < EPS);
}
bool EQV(co a, co b) {
    return EQ(a.real(), b.real()) and EQ(a.imag(), b.imag());
}

long double dot(co a, co b) {
    return (a.real() * b.real() + a.imag() * b.imag());
}

long double cross(co a, co b) {
    return (a.real() * b.imag() - a.imag() * b.real());
}

co intersection(co a1, co a2, co b1, co b2) {
    co a = a2 - a1; co b = b2 - b1;
    return a1 + a * cross(b, b1 - a1) / cross(b, a);
}

co gaishin(co a, co b, co c) {
    co e1 = b - a, e2 = c - a;
    co h1 = e1 * co(0, 1), h2 = e2 * co(0, 1);
    return intersection(a+e1/co(2, 0), a+e1/co(2, 0)+h1, a+e2/co(2, 0), a+e2/co(2, 0)+h2);
}

bool ccw(co a, co b, co c) {
    return EQ(cross(b-a, c-a), 0.0);
}

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

    ll N;
    cin >> N;
    vector<co> points(N);
    Rep (i, N) {
        long double a, b;
        cin >> a >> b;

        points[i] = {a, b};
    }

    vector<co> koho;

    Rep (i, N) {
        for (ll j = i+1; j < N; j++) {
            koho.push_back((points[i]+points[j])/co(2, 0));
            for (ll k = j+1; k < N; k++) {
                if (!ccw(points[i], points[j], points[k])) {
                    koho.push_back(gaishin(points[i], points[j], points[k]));
                }
            }
        }
    }

    long double ans = inf;
    for (co e : koho) {
        long double tmp = 0;
        Rep (i, N) {
            chmax(tmp, abs(e-points[i]));
        }
        chmin(ans, tmp);
    }

    cout << fixed << setprecision(10) << ans << endl;
}

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

int main()
{
	int N;
	cin >> N;
	while (N--)
	{
		int n;
		cin >> n;
		char c[2][2*n];
		for (int i=0; i<4*n; i++)
			cin >> c[i/(2*n)][i%(2*n)];

		bool ex[2][n+1];
		for (int i=0; i<2; i++)
		for (int k=0; k<=n; k++)
			if (k==0)
				ex[i][k] = c[i][k]=='Y';
			else if (k==n)
				ex[i][k] = c[i][2*k-1]=='Y';
			else
				ex[i][k] = c[i][2*k-1]=='Y'||c[i][2*k]=='Y';

		int cost[6] = { 0 };

		for (int i=0; i<=n; i++)
		{
			for (int k=0; k<3; k++)
			{
				if (i==0 && k>0) continue;
				int t=cost[k];
				switch (k)
				{
					case 0:
						if (ex[1][i])
						{
							cost[5] = cost[4] = t+2;
							cost[3] = t+3;
						}
						else if (ex[0][i])
						{
							cost[3] = cost[4] = t+1;
							cost[5] = t+2;
						}
						else
						{
							cost[3] = t;
							cost[4] = t+1;
							cost[5] = t+2;
						}
						break;
					case 1:
						if (ex[0][i])
						{
							if (ex[1][i])
							{
								cost[3] = min(cost[3], t+2);
								cost[4] = min(cost[4], t+2);
								cost[5] = min(cost[5], t+2);
							}
							else
							{
								cost[3] = min(cost[3], t+1);
								cost[4] = min(cost[4], t+1);
								cost[5] = min(cost[5], t+2);
							}
						}
						else if (ex[1][i])
						{
							cost[3] = min(cost[3], t+2);
							cost[4] = min(cost[4], t+1);
							cost[5] = min(cost[5], t+1);
						}
						else
						{
							cost[3] = min(cost[3], t+1);
							cost[4] = min(cost[4], t);
							cost[5] = min(cost[5], t+1);
						}
						break;
					case 2:
						if (ex[0][i])
						{
							cost[3] = min(cost[3], t+2);
							cost[4] = min(cost[4], t+2);
							cost[5] = min(cost[5], t+3);
						}
						else if (ex[1][i])
						{
							cost[3] = min(cost[3], t+2);
							cost[4] = min(cost[4], t+1);
							cost[5] = min(cost[5], t+1);
						}
						else
						{
							cost[3] = min(cost[3], t+2);
							cost[4] = min(cost[4], t+1);
							cost[5] = min(cost[5], t);
						}
						break;
				}
			}

			if (i < n)
			{
				cost[3]++; cost[4]++; cost[5]++;
			}

			cost[0] = cost[3];
			cost[1] = cost[4];
			cost[2] = cost[5];
		}

		cout << cost[0] << endl;
	}
}

Measured memory_bytes: 0
//July Challenge 2020
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll N = 1e10 + 5;
const double E= 1e-9;
 
//------------------------------------------------------------------------------

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    /*ifstream cin("input.txt");
    ofstream cout("output.txt");*/
    int n;
    cin>>n;
    if(n%1000)
    cout<<(1000-(n%1000));
    else
    cout<<0;
    return 0;
}
//Date: ###### Sun Jul 5 17:32:23 IST 2020
//------------------------------------------------------------------------------

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

int main() {
  int x,a;
  cin >> x;
  
  for(int i=1;i<=360;i++){
  	if(360*i%x==0){
      a=i;
      break;
    }
  }
  int b;
  b=360*a/x;
  cout << b << endl;
}



Measured memory_bytes: 3592
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000

int min(int a, int b){
  if(a>=b){
    return b;
  }
  else{
    return a;
  }
}

int main(){
  char buf[1024];
  int N;

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%d", &N);

  int *A=(int *)malloc(sizeof(int)*N);
  rep(i,N){
    scanf("%d",&A[i]);
  }

  int count=0;
  int min_a=abs(A[0]);
  long sum=0;
  rep(i,N){
    if(A[i]<0){
      count++;
      A[i]=A[i]*(-1);
    }
    min_a=min(min_a, A[i]);
    sum+=A[i];
  }

  long ans;
  if(count%2==0){
    ans=sum;
  }
  else{
    ans=sum-2*min_a;
  }

  printf("%ld\n", ans);

  return 0;

}


Measured memory_bytes: 512
import Debug.Trace

main = do
  _ <- read <$> getLine :: IO Int
  a1s <- map read . words <$> getLine :: IO [Int]
  a2s <- map read . words <$> getLine :: IO [Int]
  print $ solve a1s a2s

solve :: [Int] -> [Int] -> Int
solve a1s a2s =
--  traceShow cumsum1
--  traceShow cumsum2
--  traceShow candidate
  ans
  where
    cumsum1 =  scanl1 (+) a1s
    cumsum2 = scanr1 (+) a2s
    sumcandy [] [] acc = acc
    sumcandy (a1:a1s) (a2:a2s) acc =
      sumcandy a1s a2s (a1+a2:acc)
    candidate = sumcandy cumsum1 cumsum2 []
    ans = maximum candidate


Measured memory_bytes: 1020
import itertools
import math
import fractions
import functools
import copy
n, m, c = map(int, input().split())
b  = list(map(int, input().split()))
a=[]
for i in range(n):
    a.append(list(map(int, input().split())))
count = 0
for i in range(n):
    sum = 0
    for j in range(m):
        sum += a[i][j]*b[j]
    if sum + c > 0:
        count += 1

print(count)

Measured memory_bytes: 63980
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int A,B;
	scanf("%d %d",&A,&B);

	printf("%d\n",A-B+1);

	return 0;
}


Measured memory_bytes: 3696
W, H, N = map(int, input().split())
input_list = [[int(i) for i in input().split()] for j in range(N)]

x_max, x_min, y_max, y_min = W, 0, H, 0

for i in range(N):
    if input_list[i][2] == 1:
        x_min = max(x_min, input_list[i][0])
    elif input_list[i][2] == 2:
        x_max = min(x_max, input_list[i][0])
    elif input_list[i][2] == 3:
        y_min = max(y_min, input_list[i][1])
    elif input_list[i][2] == 4:
        y_max = min(y_max, input_list[i][1])

if x_max - x_min > 0 and y_max - y_min > 0:
    print((x_max-x_min)*(y_max-y_min))
else:
    print(0)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
 ll H,W,N;
bool onBoard(ll y,ll x){
    if(y>=1 && y<H-1 && x>=1 && x <W-1){
        return true;
    }
    return false;
}

int main() {
   
    cin >>  H >>W >>N;
    map<pair<ll,ll>,ll> mp;
    for(int i=0;i<N;i++){
        ll a,b;
        cin >> a >>b;
        --a;--b;
        mp[make_pair(b,a)] =1;
    }
    vector<ll> ans(10,0);
    set<pair<ll,ll>> already;
    for(auto itr = mp.begin();itr != mp.end();++itr){
        auto P =itr->first;
        ll x = P.first;
        ll y = P.second;
        for(int i=-1;i<2;i++)for(int j=-1;j<2;j++){
            ll cx = x +i;
            ll cy = y+j;
            if(!onBoard(cy,cx)){
                continue;
            }
            if(already.find(make_pair(cx,cy)) != already.end()){
                continue;
            }
            ll num=0;
            for(int a=-1;a<2;a++)for(int b=-1;b<2;b++){
                
                ll nx = cx+a;
                ll ny = cy+b;
                
                if(mp.find(make_pair(nx,ny)) != mp.end()){
                    num++;
                }
                
            }
            ans[num]++;
            already.insert(make_pair(cx,cy));
        }
    }
    ll sum=0;
    for(int i=0;i<10;i++){
        sum +=ans[i];
    }
    ans[0] = (H-2)*(W-2) -sum;
    for(int i=0;i<10;i++){
        cout << ans[i] << endl;
    }


    return 0;
}

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

int main()
{
    int n;string s;cin>>n>>s;
    char now=s.at(0);
    int ans=1;
    int i;
    for(i=1;i<n;i++)
    {
        if(now!=s.at(i))
        {
            ans++;
            now=s.at(i);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 512
#include<stdio.h>
int main()
{
    int x;
    scanf("%d",&x);
    int i,j;
    int a[x],b[x],c[x];
    for(i=0;i<x;i++)
        scanf("%d",&a[i]);
    for(i=0;i<x;i++)
        scanf("%d",&b[i]);
    for(i=0;i<x;i++)
        c[i]=a[i]-b[i];
    int sum=0;
    for(i=0;i<x;i++){
        if(c[i]>=0)
            sum=sum+c[i];
    }
    printf("%d",sum);
    return 0;
}


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

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

    vector<int> H(N);
    rep(i, N) cin >> H.at(i);

    int position = 0;

    vector<int> costs(N);
    costs.at(0) = 0;
    rep(i, N)
    {
        if (i == 0)
        {
            costs.at(i) = 0;
        }
        else if (i == 1)
        {
            costs.at(i) = abs(H.at(i - 1) - H.at(i));
        }
        else
        {
            costs.at(i) = min(costs.at(i - 1) + abs(H.at(i - 1) - H.at(i)), costs.at(i - 2) + abs(H.at(i - 2) - H.at(i)));
        }
    }

    cout << costs.at(N - 1) << endl;
    return 0;
}

Measured memory_bytes: 4032
def main():
    n = int(input())
    A = [int(e) for e in input().split()]

    ma = max(A)
    N = [0] * (10 ** 6 + 1)
    for a in A:
        for i in range(a, ma + 1, a):
            N[i] += 1

    ans = 0
    for a in A:
        if N[a] == 1:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 103872
#include<bits/stdc++.h>
using namespace std;
const int INF = (1<<30);
typedef pair<int,int> P;

int main()
{
  ios_base::sync_with_stdio(false);
  
  int n,m;  
  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0) break;
    priority_queue<P,vector<P>,greater<P> > que;
    vector<P>vec[105];
    long long  min_cost[105];
    for(int cas=0;cas<m;cas++){
      int a,b,c;
      cin >> a;
      if(a == 1){
	cin >> a >> b >> c;
	vec[a].push_back(P(b,c));
	vec[b].push_back(P(a,c));
      } else{
	cin >> a >> b;
	
	for(int i=0;i<105;i++) min_cost[i] = INF;
	que.push(P(0,a));
	while(!que.empty()){
	  P now = que.top(); que.pop();
	  int pos = now.second;
	  long long cost = now.first;
	  for(int i=0;i<vec[pos].size();i++){
	    int next = vec[pos][i].first;
	    long long ncost = vec[pos][i].second;
	    if(cost+ncost < min_cost[next]){
	      min_cost[next] = cost+ncost;
	      que.push( P(min_cost[next],next) );
	    }
	  }
	}
	if(min_cost[b] == INF) cout << "-1" << endl;
	else cout << min_cost[b] << endl;
      }
    }
  }
  
  return 0;
}

Measured memory_bytes: 3128
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=2e5+5,inf=0x3f3f3f3f;
int a[N],cnt[N],n,m,res,l,r,mid,ans;
inline int calc(R int l,R int r){
	if(l>r)swap(l,r);
	return l+r<=n?l+r:l+r-n;
}
bool ck(){
	fp(i,1,n)cnt[i]=0;
	fp(i,1,n){
		R int l=lower_bound(a+1,a+1+n,mid-a[i]+1)-a;
		R int r=lower_bound(a+1,a+1+n,m-a[i])-a-1;
		l+=((l&1)^(i&1)^1),r-=((r&1)^(i&1)^1);
		if(l<=r){
//			printf("First FIND %d %d %d\n",i,l,r);
			l=calc(l,i),r=calc(r,i);
//			printf("UPD %d %d %d\n",i,l,r);
			if(l<=r)++cnt[l],--cnt[r+1];
			else ++cnt[1],++cnt[l],--cnt[r+1];
		}
		l=lower_bound(a+1,a+1+n,m+mid-a[i]+1)-a;
		r=n;
		l+=((l&1)^(i&1)^1),r-=((r&1)^(i&1)^1);
		if(l<=r){
//			printf("Second FIND %d %d %d\n",i,l,r);
			l=calc(l,i),r=calc(r,i);
//			printf("UPD %d %d %d\n",i,l,r);
			if(l<=r)++cnt[l],--cnt[r+1];
			else ++cnt[1],++cnt[l],--cnt[r+1];
		}
	}
	fp(i,1,n){
		cnt[i]+=cnt[i-1];
		if((i&1)&&!cnt[i])return true;
	}
	return false;
}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d%d",&n,&m),res=inf,n<<=1;
	fp(i,1,n)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
//	fp(i,0,m-1){
//		mid=i;
//		printf("%d %d\n",i,ck());
//	}
//	mid=0;printf("%d\n",ck());
	l=0,r=m-1;
	while(l<=r){
		mid=(l+r)>>1;
		ck()?(ans=mid,r=mid-1):l=mid+1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1792