akhauriyash/Code-Regression huggingface dataset:
import glob


# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = 'ABC\\159\\B'

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    def resolve(self):

        tmp = [int(i) for i in self.input_data().split()]
        H = tmp[0]
        W = tmp[1]

        if H ==1 or W ==1:
            print("1")
        else:
            count = int(H * W / 2)

            if H % 2 == 1 and W % 2 == 1:
                count += 1

            print(str(count))


solver = Solver(REL_PATH)
solver.exec_resolve()


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

const int MAX_N = 3000;
const int MAX_M = 100;
const int INF = 1000000;

int dist[MAX_M + 1][MAX_M + 1], cost[MAX_M + 1][MAX_M + 1];

void initialize(int m) {
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= m; j++) {
      dist[i][j] = dist[j][i] = (i == j)? 0:INF;
      cost[i][j] = cost[j][i] = (i == j)? 0:INF;
    }
  }
}

void minify(int m) {
  for (int k = 1; k <= m; k++) {
    for (int i = 1; i <= m; i++) {
      for (int j = 1; j <= m; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
        cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
      }
    }
  }
}

int query(int p, int q, int r) {
  if (r == 0) {
    return cost[p][q];
  } else {
    return dist[p][q];
  }
}

int main() {
  int n, m;
  while(cin >> n >> m and (n != 0 or m != 0)) {
    int a, b, c, d;
    initialize(m);

    for (int i = 0; i < n; i++) {
      cin >> a >> b >> c >> d;
      cost[a][b] = cost[b][a] = c;
      dist[a][b] = dist[b][a] = d;
    }

    minify(m);

    int k, p, q, r;
    cin >> k;

    for (int i = 0; i < k; i++) {
      cin >> p >> q >> r;
      cout << query(p, q, r) << endl;
    }
  }
}

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

const int N=100005;
int n,m,sum[N],fa[N];
char s[N];

int find(int x){return !fa[x]?x:fa[x]=find(fa[x]);}
void unite(int x,int y){x=find(x),y=find(y);if(x!=y)fa[x]=y,sum[y]=(sum[y]+sum[x])%26;}

int main(){
	scanf("%s%d",s+1,&m),n=strlen(s+1);
	s[0]=s[n+1]='a';
	for(int i=1;i<=n+1;++i)sum[i]=(s[i]-s[i-1]+26)%26;
	for(int i=1,l,r;i<=m;++i)
		scanf("%d%d",&l,&r),unite(l,r+1);
	for(int i=1;i<=n/2+1;++i)unite(i,n+2-i);
	for(int i=1;i<=n+1;++i)if(!fa[i]&&sum[i])return puts("NO"),0;
	puts("YES");
}


Measured memory_bytes: 1152
N = int(input())
P = list(map(int,input().split()))
#PS = [i for i in range(1,N+1)]

cnt = 0
i = 0
while i < N:
    if P[i] == i+1:
        if i < N-1 and P[i+1] == i+2:
            cnt += 1
            i += 1
        else:
            cnt += 1
                   
    i += 1   
print(cnt)
    
    

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

int main(){
  int n,k;
  cin>>n>>k;
  vector<int>p(n);
  
  rep(i,n)cin>>p[i];
  int ans=0;
  sort(p.begin(),p.end());
  rep(i,k)ans+=p[i];
  
  cout<<ans<<endl;
  
  return 0;
}

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

int main() {
  int N,K,L=1,i=0;
  cin >> N >> K;
  
  for(; i<N; i++){
    if(L<K){
      L=L*2;
    }
    else{
      L+=K;
    }
  }
  
  cout << L << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;


typedef tree<int,null_type,less<int>,rb_tree_tag,
		tree_order_statistics_node_update> indexed_set;
#define P pair<int,int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define st std::string 
#define pb push_back 
#define ll long long 
#define pq(x) std::priority_queue<x> 
#define ultapq(x) priority_queue<x,vector<x>,greater<x>> 
#define show_pq(x,n) for(int i = 0; i < n; i++){cout<<x.top(); x.pop();} 
#define itrt(yo) for(auto x:yo){std::cout<<x<<" ";} 
#define vec(x) std::vector<x> 
#define nl '\n' 
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define ALL(x) x.begin(),x.end() 
#define just int i= 0; i<n ; i++

const int MOD = 1e9+7;


int solve(){
    int k,s; cin>>k>>s;

    int x=0,y=0,z=0;
    int ans=0;
    for (int i = 0; i <= k; i++)
    {
        for (int j = 0; j <= k; j++)
        {
            z = s -i - j ;
            if (z>=0 && z<=k)
            {
                ans++;
            }
            
            
        }
        
    }
    cout<<ans;
    return 0;
    
}

int main()
{
    IOS;
    int t=1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    
}

    

    
	

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <stack>
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
int main(void) {
	int k,n;
	cin >> n >> k;
	vector<ll> h(n);
	for (int i = 0;i < n;i++) {
		cin >> h[i];
	}
	sort(h.begin(), h.end(), std::greater<int>());
	ll ans = 0;
	for (int i = k;i < n;i++) {
		ans += h[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string.h>
using namespace std;
int N, K;
const long long mod = 1e9+7;
long long a[101];
long long dp[2][100005];
int main() {
	cin >> N >> K;
	for (int i = 1; i <= N; i++) cin >> a[i];
	dp[1][0] = 1;
	for (int i = 1; i <= N; i++) {
		dp[0][0] = dp[1][0];
		for (int j = 1; j <= K; j++) dp[0][j] = (dp[0][j - 1] + dp[1][j]) % mod;
		memset(dp[1], 0, sizeof(dp[1]));
		for (int j = K; j >= 0; j--) {
			if (j - a[i] > 0) {
				dp[1][j] = ((dp[1][j] + dp[0][j] - dp[0][j - a[i] - 1]) % mod + mod) % mod;
			} else {
				dp[1][j] = (dp[1][j] + dp[0][j]) % mod;
			}
		}
	}
	cout << dp[1][K] << endl;
}


Measured memory_bytes: 1792
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m = li()
py = []
for _ in range(m):
    py.append(list(li()))
    
towns = [[] for _ in range(n+1)]
table = [{} for _ in range(n+1)]
for p,y in py:
    towns[p].append(y)
    
for i in range(n+1):
    if len(towns[i]) > 0:
        towns[i].sort()
        
for i in range(n+1):
    if len(towns[i]) > 0:
        for j, tj in enumerate(towns[i]):
            table[i].update({tj: j+1})
            
for p,y in py:
    print(str(p).zfill(6) + str(table[p][y]).zfill(6))

Measured memory_bytes: 77924
n, x, y = map(int, input().split())
x -= 1 
y -= 1

dist_count = {}
for i in range(n-1):
	for j in range(i+1, n):
		dist_simple = j - i
		dist_bridge1 = abs(i-x) + 1 + abs(j-y)
		dist_bridge2 = abs(i-y) + 1 + abs(j-x)
		res_dist = min(dist_simple, dist_bridge1, dist_bridge2)
		dist_count[res_dist] = dist_count.get(res_dist, 0) + 1


for dist in range(1, n):
	print(dist_count.get(dist, 0))


Measured memory_bytes: 51164
#include <iostream>
#define ll long long
const int K=1e5+5;
const int mod=1e9+7;
using namespace std;
ll dp[K];
ll quick_pow(ll x,ll y){
	ll res=1;
	while(y){
		if(y%2==1) res=(res*x)%mod;
		x=(x*x)%mod;
		y>>=1;
	}
	return res;
}
int main(){
	ll n,k; cin>>n>>k;
	for(int i=k;i>=1;i--){
		dp[i]=quick_pow(k/i,n);
		for(int j=2*i;j<=k;j+=i) dp[i]-=dp[j];
	}
	ll ans=0;
	for(int i=1;i<=k;i++)
		ans=(ans+(dp[i]*i)%mod)%mod;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4348
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include<bitset>
#include<math.h>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int ans=0;
  string s;
  cin>>s;

  for(int i=2;i<(int)s.size();i+=2){
    if(s.substr(0,i/2)==s.substr(i/2,i/2)) ans=i;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int seconds, h, m, s;
	scanf("%d", &seconds);
	h = seconds / 3600;
	seconds %= 3600;
	m = seconds / 60;
	s = seconds % 60;
	printf("%d:%d:%d\n", h, m, s);

	return 0;
}

Measured memory_bytes: 592
def dijkstra(s,n,cost):
  d=[float('inf')]*n
  visited=[0]*n
  d[s]=0
  while True:
    v=-1
    for i in range(n-1,-1,-1):
      if visited[i]==0 and v==-1:
        v=i
      elif visited[i]==0 and d[i]<d[v]:
        v=i
    if v==-1:
      break
    visited[v]=1
    for j in range(n-1,-1,-1):
      d[j]=min(d[j],d[v]+cost[j][v])
  return d

h,w=map(int,input().split())
c=[list(map(int,input().split())) for _ in range(10)]
a=[list(map(int,input().split())) for _ in range(h)]
cost=dijkstra(1,10,c)
ans=0
for i in range(h):
  for j in range(w):
    ans+=(cost[a[i][j]] if a[i][j]>-1 else 0)
print(ans)

Measured memory_bytes: 3444
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
using namespace std;

typedef pair<int, int> P;
struct Edge{ int to, cost; };
const int INF = 1 << 30;
const int V = 100010;
vector<Edge> list[V];
int d[V];

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int v, e, r;
	cin >> v >> e >> r;
	
	int a, b, c;
	for(int i = 0; i < e; ++i){
		cin >> a >> b >> c;
		list[a].push_back(Edge{b, c});
	}
	
	priority_queue<P, vector<P>, greater<P> > pque;
	fill(d, d + v, INF);
	d[r] = 0;
	pque.push(P(0, r));
	
	while(!pque.empty()){
		P p = pque.top();
		pque.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		
		for(size_t i = 0; i < list[v].size(); ++i){
			Edge e1 = list[v][i];
			if(d[e1.to] > d[v] + e1.cost){
				d[e1.to] = d[v] + e1.cost;
				pque.push(P(d[e1.to], e1.to));
			}
		}
	}
	
	for(int i = 0; i < v; ++i){
		if(d[i] == INF)
			cout << "INF";
		else
			cout << d[i];
		cout << endl;
	}
	
	return 0;
}

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

signed main(){
    long long H,W;cin>>H>>W;
    long long ans=LLONG_MAX;
    if(H%3==0) ans=0;
    else if(W%3==0) ans=0;
    else{
        long long Sx,Sy,Sz;
        REP(i,W-1){
            Sx=(i+1)*H;
            Sy=(H/2)*(W-i-1);
            Sz=((H+1)/2)*(W-i-1);
            ans=min(ans,max({Sx,Sy,Sz})-min({Sx,Sy,Sz}));
        }
        REP(i,H-1){
            Sx=(i+1)*W;
            Sy=(W/2)*(H-i-1);
            Sz=((W+1)/2)*(H-i-1);
            ans=min(ans,max({Sx,Sy,Sz})-min({Sx,Sy,Sz}));
        }
        ans=min(ans,min(((W+2)/3)*H-(W/3)*H,((H+2)/3)*W-(H/3)*W));
    }
    cout<<ans<<endl;
}

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

namespace AtCoderTemplate
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Scanner.scanint[0];
            var h = Scanner.scanint;

            var max = 0;
            var res = 0;
            for(var i = 0; i < n; i++)
            {
                if(max <= h[i])
                {
                    max = h[i];
                    res++;
                }
            }
            Console.WriteLine(res); 
        }
    }

    public class Scanner
    {
        public static string[] scan => Console.ReadLine().Split(' ');
        public static int[] scanint => Array.ConvertAll(scan, int.Parse);
        public static long[] scanlong => Array.ConvertAll(scan, long.Parse);
        public static string[][] rescan(int n) => Enumerable.Repeat(0, n).Select(_ => scan).ToArray();
        public static int[][] rescanint(int n) => Enumerable.Repeat(0, n).Select(_ => scanint).ToArray();
        public static long[][] rescanlong(int n) => Enumerable.Repeat(0, n).Select(_ => scanlong).ToArray();

    }

    public class Ex
    {
        public static int[] subarr(int[] arr, int begin, int n) { int[] a = new int[arr.Length]; Array.Copy(arr, begin, a, 0, n); return a; }
    }
}


Measured memory_bytes: 11220
/*  ex5_3
    pptenshi  */

#include<stdio.h>
#define LIMIT 101

int main(void) {
    int height,                 // H
        width,                  // W
        is_del_row[LIMIT] = {0},  // 取り除く行
        is_del_col[LIMIT] = {0};  // 取り除く列
    char squares[LIMIT][LIMIT];  // マス目

    // input
    scanf("%d%d", &height, &width);
    for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
            scanf(" %c", &squares[i][j]);
        }
    }

    // 圧縮できる行を求める
    for (int i = 0; i < height; i++) {
        for(int j = 0; j < width; j++) {
            
            if (squares[i][j] == '#') break;

            // 全て白いマスの場合
            if (j == width - 1) {
                is_del_row[i] = 1;
            }
        }
    }

    // 圧縮できる列を求める
    for (int j = 0; j < width; j++) {
        for (int i = 0; i < height; i++) {

            if (squares[i][j] == '#') break;

            // 全て白いマスの場合
            if (i == height - 1) {
                is_del_col[j] = 1;
            }
        }
    }

    //output
    for (int i = 0; i < height; i++) {
        if (is_del_row[i]) continue;  // 圧縮された行は出力しない

        for (int j = 0; j < width; j++) {
            if (is_del_col[j]) continue;  // 圧縮された列は出力しない

            printf("%c", squares[i][j]);
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int f[110][10];
    rep(i, 0, n){
        rep(j, 0, 10) cin >> f[i][j];
    }
    int p[110][11];
    int ans = -INF;
    rep(i, 0, n) rep(j, 0, 11) cin >> p[i][j];
    for(int mask = 1; mask < (1LL << 10); mask++){
        int tmp = 0;
        rep(i, 0, n){
            int cnt = 0;
            rep(j, 0, 10){
                if(f[i][j] == 1 && (mask & (1LL << j)) != 0){
                    cnt++;
                }
            }
            tmp += p[i][cnt];
            // cout << " " << cnt << " " << p[i][cnt] << " ";
        }
        // cout << mask << " " << tmp << endl;
        chmax(ans, tmp);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

map<ll,int>mp;

int main(){
    int n;
    cin >> n;
    rep(i, n) {
        int a;
        cin >> a;
        mp[a]++;
    }
    ll ans = 0;
    for(auto v : mp){
        if (v.second < v.first) ans += v.second;
        else ans += v.second - v.first;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9340
n, m = map(int, input().split())
a = sorted([list(map(int, input().split())) for i in range(n)])
total = 0
num_of_drinks = 0

i = 0
while(num_of_drinks < m):
    if num_of_drinks + a[i][1] < m:
      total += a[i][0] * a[i][1]
      num_of_drinks += a[i][1]
    else:
      total += a[i][0] * (m - num_of_drinks)
      num_of_drinks = m
    i += 1
    
print(total)

Measured memory_bytes: 28652
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main(void)
{
	long long int n,A[100001],i,a,b;
	scanf("%lld",&n);
	for(i=0;i<n;i++) scanf("%lld",&A[i]);
	sort(A,A+n,greater<int>());
	a=0; b=0;
	for(i=0;i<n;i++){
		if(a==0){
			if(A[i]==A[i+1]){
				a=A[i]; i++;
			}
		}
		else{
			if(A[i]==A[i+1]){
				b=A[i];
				break;
			}
		}
	}
	if(b==0) printf("0\n");
	else printf("%lld\n",a*b);
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;

using Weight=int;
using DArray=vector<Weight>;
using DMatrix=vector<DArray>;

static const Weight INF=1<<29;

struct Edge {
    size_t src, dst;
    Weight weight;
    Edge() {}
    Edge(size_t src, size_t dst, Weight weight=1):
        src(src), dst(dst), weight(weight)
    {}
};


bool operator<(const Edge &e, const Edge &f) {
    if (e.weight != f.weight) {
        return e.weight > f.weight;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Edges=vector<Edge>;
using Vertex=vector<Edge>;
using Graph=vector<Vertex>;

void join(Graph &g, size_t s, size_t d, Weight w=1) {
    // non-directed
    g[s].push_back(Edge(s, d, w));
    g[d].push_back(Edge(d, s, w));
}

void connect(Graph &g, size_t s, size_t d, Weight w=1) {
    // directed
    g[s].push_back(Edge(s, d, w));
}

int main() {
    size_t n;
    scanf("%zu", &n);

    Graph g(n);
    vector<size_t> parent(n, -1);
    for (size_t i=0; i<n; ++i) {
        size_t p, m;
        scanf("%zu %zu", &p, &m);
        for (size_t j=0; j<m; ++j) {
            size_t c;
            scanf("%zu", &c);
            connect(g, p, c);
            parent[c] = p;
        }
    }

    for (size_t i=0; i<n; ++i) {
        printf("node %zu: ", i);
        if (~parent[i]) {
            printf("parent = %zu, ", parent[i]);
        } else {
            printf("parent = -1, ");
        }

        size_t d=0;
        for (size_t j=i; ~parent[j]; j=parent[j])
            ++d;

        printf("depth = %zu, ", d);
        if (!d) {
            printf("root, ");
        } else if (g[i].empty()) {
            printf("leaf, []\n");
            continue;
        } else {
            printf("internal node, ");
        }

        printf("[");
        if (g[i].empty()) {
            printf("]\n");
            continue;
        }

        for (size_t j=0; j<g[i].size(); ++j)
            printf("%zu%s", g[i][j].dst, j<g[i].size()-1? ", ":"]\n");
    }

    return 0;
}

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

int main(){
    string a, b;
    cin >> a >> b;
    int size = a.length();
    int i;
    int cnt = 0;
    for (i = 0; i < size; i++){
        if (a[i] == b[i]) {
            cnt++;
        }
    }
    if(cnt == size){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}

Measured memory_bytes: 3540
#include <stdio.h>

int primenum(int a){
  int i;
  if(a == 2) return 1;
  if(a < 2 || a % 2 == 0) return 0;
  for(i = 3;i*i<=a;i=i+2){
    if(a % i == 0) return 0;
  }
  return 1;

}

int main(){
  int n,cnt=0,a,i;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a);
    if(primenum(a) == 1) cnt++;
  }
  printf("%d\n",cnt);
  return 0;
}



Measured memory_bytes: 2140
n, k = [ int(v) for v in input().split() ]

if k == 0:
    ans = n ** 2
else:
    ans = 0
    for i in range(k+1,n+1):
        j = n - k + 1
        a, b = j // i, j % i
        ans += a * (i-k) + min(b, i-k)
print(ans)


Measured memory_bytes: 39664
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int a, b;
  cin >> a >> b;
  cout << max({(a + b), (a - b), (a * b)}) << endl;
}


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

using namespace std;

int main()
{
    int len, aux, cant = 0;
    cin>>len;
    vector<int> nums;
    nums.assign(len,0);
    map<int,int> dict;
    for(int i = 0; i < len; i++)
    {
        cin>>aux;
        dict.insert(pair<int,int>(aux,i));
        nums[i] = aux;
    }
    sort(nums.begin(),nums.end());
    for(int i = 0; i < len; i++)
    {
        if(dict[nums[i]]%2 != i%2)
            cant++;
    }
    cout<<cant/2<<endl;
    return 0;
}


Measured memory_bytes: 5376
/*input
1 5 2 0
*/
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
int main()
{
	ios_base::sync_with_stdio(false);
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	vector<string>A(h, string(w, '0'));
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
		{
			if ((i < b) ^ (j < a))
				A[i][j] = '1';
		}
	for (int i = 0; i < h; i++)
		cout << A[i] << "\n";
}

Measured memory_bytes: 2304
#include <stdio.h>
#include <string.h>
#include <math.h>
int main(void){
  char o[50],e[50];
  int i,j;
  scanf("%s %s",o,e);
  double sum=fmax(strlen(o),strlen(e));
  for(i=0;i<sum;i++){
    if(o[i]!='\0') printf("%c",o[i]);
    if(e[i]!='\0') printf("%c",e[i]);
  }
  return 0;
}

Measured memory_bytes: 128
#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;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
ll f[MAX];
ll modex(ll a, ll b)
{
    ll ans = 1;
    while(b)
    {
        if(b & 1)
            ans = (ans * a) % mod;
        b >>= 1;
        a = (a * a) % mod;
    }
    return ans;
}
ll ncr(ll n, ll r)
{
    if(r == 0 || r == n)
        return 1;
    ll ans = f[n];
    ans = (ans * modex(f[n - r], mod - 2)) % mod;
    ans = (ans * modex(f[r], mod - 2)) % mod;
    return ans;
}
int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, m, i, k;
    f[0] = 1;
    for(i = 1; i < MAX; i++)
        f[i] = (f[i - 1] * i) % mod;
    cin >> n >> m >> k;
    ll ans = ncr(n * m - 2, k - 2);
    ll e1 = ((m % mod) * (n * n - 1) % mod) % mod;
    ll e2 = ((n % mod) * (m * m - 1) % mod) % mod;
    // cout << e1 << ' ' <<  e2 << endl;
    e1 = (e1 + e2) % mod;
    // cout << e1 << ' ' <<  e2 << endl;
    e1 = (e1 * (n * m) % mod) % mod;
    e1 = (e1 * modex(6, mod - 2)) % mod;
    // cout << e1 << ' ' <<  e2 << endl;
    // cout << ans << endl;
    ans = (ans * e1) % mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(n) begin(n), end(n)
#define IN(a, x, b) (a <= x && x < b)
#define INIT                        \
  std::ios::sync_with_stdio(false); \
  std::cin.tie(0);
template <class T>
inline T CHMAX(T& a, const T b) {
  return a = (a < b) ? b : a;
}
template <class T>
inline T CHMIN(T& a, const T b) {
  return a = (a > b) ? b : a;
}

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

int main() {
  INIT;
  ll n;
  cin >> n;
  string ans;
  ll c;
  while (n != 0) {
    n -= 1;
    c = n % 26;
    ans = char(c + 97) + ans;
    n /= 26;
  }

  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(c)  c.begin(),c.end()

int main()
{
    //freopen("in.txt","r",stdin);
    bool flag = false;
    ll a,b,x = 0;
    cin >> a >> b;
    for(ll i=a;(i<=b);i++){
        if(i%4 == 2){
            flag = true;
            break;
        }
        x ^= i;
    }
    for(ll i=b;i>=a && flag == true;i--){
        if(i%4 == 1){
            break;
        }
        x ^= i;
    }
    cout << x << endl;
}


Measured memory_bytes: 256
from collections import deque
def check(arr):
	num=1
	Q=deque(arr)
	while len(Q):
		while len(Q) and Q[0]!=num:
			Q.popleft()
		if len(Q):
			num+=1
			Q.popleft()
	return len(arr)-(num-1)

n=int(input())
arr=[int(x) for x in input().split()]
ans=check(arr)
if ans==n:
	print(-1)
else:
	print(ans)

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

int main(){
    double W,H,x,y; cin >> W >> H >> x >> y;
    double ans1=0;
    int ans2=0;
    double S=W*H;
    
    if (x==W/2.0 && y==H/2.0) ans2=1;
    else ans2=0;
    
    ans1=W*H/2.0;
    
    printf("%lf %d",ans1,ans2);

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main()
{
	int R[MAX],n;
	
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> R[i];
	}
	
	int maxv = -2000000000;
	int minv = R[0];
	
	for(int i = 1; i < n; i++)
	{
		maxv = max(maxv,R[i] - minv);
		minv = min(minv,R[i]);
	}
	
	cout << maxv << endl;
	
	return 0;
}

Measured memory_bytes: 3860
n=int(input())
w=[input() for _ in range(n)]
for i in range(n-1):
	if	w[i][-1] != w[i+1][0]:
		print('No')
		exit(0)
	else:
		pass
if len(set(w)) == len(w):
	print('Yes')
else:
	print('No')

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

using namespace std;

using ll = long long;

#define ALL(A) A.begin(),A.end()

int main()
{
    int N;
    cin >> N;
    vector<string> S(N);
    set<string> ans;
    for(int i=0;i<N;i++)
    {
        cin >> S.at(i);
        ans.insert(S.at(i));
    }
    
    cout << ans.size() << endl;

    return 0;
}

Measured memory_bytes: 24944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int n, m; cin >> n >> m;
    P itv[m];
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        a--;b--;
        itv[i].first = b;
        itv[i].second = a;
    }

    sort(itv, itv + m);

    int ans = 0, cur = 0;
    rep(i, m)
    {
        if (cur <= itv[i].second)
        {
            //cout << itv[i].second << endl;
            ans++;
            cur = itv[i].first;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <cstdlib>
//#include <cstdlib>
using namespace std;



int main()
{
    char n[100000];
    cin>>n;
    int l=0,r=0;
    for(int i=0;i<strlen(n);i++){
        if(i%2==0) r+=(n[i]-'0');
        else l+=(n[i]-'0');
    }
    int ans;
    if(strlen(n)%2==0) ans=strlen(n)/2-max(l,r)+min(l,r);
    else ans=min((strlen(n)/2+1-r+l),(strlen(n)/2-l+r));
    cout<<ans;
    return 0;

}

Measured memory_bytes: 384
#include<cstdio>
#include<algorithm>
#include<cstring>

int main(){
	using namespace std;
	int table[300][300][2],n,m,a,b,INF=10000000;
	while(true){
		scanf("%d%d",&n,&m);
		if(n==0&&m==0) break;
		for(int i=0;i<300;i++)
			for(int j=0;j<300;j++)
				for(int k=0;k<2;k++)
					table[i][j][k]=INF;
		for(int i=0;i<300;i++){
			table[i][i][0]=0;
			table[i][i][1]=0;
		}
		while(n--){
			scanf("%d%d",&a,&b);
			scanf("%d",&table[a-1][b-1][0]);
			table[b-1][a-1][0]=table[a-1][b-1][0];
			scanf("%d",&table[a-1][b-1][1]);
			table[b-1][a-1][1]=table[a-1][b-1][1];
		}

		for(int i=0;i<m;i++){
			for(int j=0;j<m;j++){
				for(int k=0;k<m;k++){
					table[j][k][0]=min(table[j][k][0],table[j][i][0]+table[i][k][0]);
					table[j][k][1]=min(table[j][k][1],table[j][i][1]+table[i][k][1]);
				}
			}
		}
		scanf("%d",&m);
		while(m--){
			scanf("%d%d%d",&a,&b,&n);
			printf("%d\n",table[a-1][b-1][n]);
		}
	}	
	return 0;

}

Measured memory_bytes: 1468
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define repr4(i,s,n) for(ll i = (n);i>=(s);i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
using Graphw = vector<vector<pair<ll,ll>>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/



int main() {
int H,W;
cin>>H>>W;
string S[H];

rep(i,H){
    cin>>S[i];
}
char grid[H+1][W+1];
rep3(i,H){
    rep3(j,W){
        grid[i][j]=S[i-1][j-1];
    }
}
int left[H+1][W+1];
rep3(i,H){
    left[i][0]=0;
}
int right[H+1][W+2];
rep3(i,H){
    right[i][W+1]=0;
}
int over[H+1][W+1];
rep3(i,W){
    over[0][i]=0;
}
int under[H+2][W+1];
rep3(i,W){
    under[H+1][i]=0;
}
rep3(i,H){
    rep3(j,W){
        if(grid[i][j]=='#'){
            left[i][j]=0;
        }
        else{
            left[i][j]=left[i][j-1]+1;
        }
    }
}
rep3(i,H){
    repr3(j,W){
        if(grid[i][j]=='#'){
            right[i][j]=0;
        }
        else{
            right[i][j]=right[i][j+1]+1;
        }
    }
}
rep3(i,W){
    rep3(j,H){
        if(grid[j][i]=='#'){
            over[j][i]=0;
        }
        else{
            over[j][i]=over[j-1][i]+1;
        }
    }
}
rep3(i,W){
    repr3(j,H){
        if(grid[j][i]=='#'){
            under[j][i]=0;
        }
        else{
            under[j][i]=under[j+1][i]+1;
        }
    }
}
int max_spot=0;
rep3(i,H){
    rep3(j,W){
        if(grid[i][j]=='#')continue;
        max_spot=max(max_spot,left[i][j]+right[i][j]+over[i][j]+under[i][j]-3);
    }
}
cout<<max_spot<<endl;
return 0;
}

Measured memory_bytes: 70912
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  ll ten=1,nin=1,eig = 1;
  for(int i=0;i<n;i++){
    ten *= 10;
    nin *= 9;
    eig *= 8;
    ten %= MOD;
    nin %= MOD;
    eig %= MOD;
  }
  cout<<(ten-nin*2+eig+(ll)MOD*10)%MOD<<endl;
  return 0;
}


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

int main() {
  string S;
  cin>>S;
  if(S=="SAT")cout<<1<<endl;
  if(S=="SUN")cout<<7<<endl;
  if(S=="MON")cout<<6<<endl;
  if(S=="TUE")cout<<5<<endl;
  if(S=="WED")cout<<4<<endl;
  if(S=="THU")cout<<3<<endl;
  if(S=="FRI")cout<<2<<endl;




  }


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll N, od=0;
    cin>>N;
    rep(i, N){
        ll A;
        cin>>A;
        if(A%2==1){
            od++;
        }
    }
    if(od%2==0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

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

#define all(c) begin(c),end(c)

template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


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


auto solve() {
    int N, Q;
    cin >> N >> Q;
    vi A(N);
    for (auto &&e:A) cin >> e;

    vi left(N);
    left[N - 1] = N - 1;
    for (int j = N - 2; j >= 0; --j) {
        left[j] = max(0, left[j + 1] - 2);
    }

    vll acc(N, 0);
    acc[N - 1] = A[N - 1];
    for (int j = N - 2; j >= 0; --j) {
        acc[j] = acc[j + 1] + A[j];
    }
    vll even(N, 0), odd(N, 0);
    even[0] = A[0];
    FOR(i, 1, N) {
        even[i] = even[i - 1];
        odd[i] = odd[i - 1];
        if (i % 2 == 0) even[i] += A[i];
        else odd[i] += A[i];
    }

    while (Q--) {
        int X;
        cin >> X;

        auto it = lower_bound(all(A), X);
        int i = distance(begin(A), it);
        int l = i - 1;
        int r = N - 1;

        while (r - l > 1) {
            int med = ((ll) l + r) / 2;
            int L = N - med - 1;
            if (med - i + 1 > L) {
                r = med;
            } else if (med < L) {
                l = med;
            } else {
                if (abs(A[left[med]] - X) > abs(X - A[med])) {
                    l = med;
                } else {
                    r = med;
                }
            }
        }

        ll res = acc[r];
        int L = N - r;
        int s = r - L - 1;
        if (s >= 0) {
            if (s % 2 == 0) res += even[s];
            else res += odd[s];
        }

        cout << res << endl;
    }
}


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

//    cout << solve() << endl;
    solve();

    return 0;
}


Measured memory_bytes: 4992
def isBingo(card):
    for i in range(3):
        if card[i][0] == card[i][1] and card[i][0] == card[i][2]:
            return True

    for i in range(3):
        if card[0][i] == card[1][i] and card[0][i] == card[2][i]:
            return True

    if(card[1][1] == card[0][0] and card[1][1] == card[2][2]):
        return True
    
    if(card[1][1] == card[0][2] and card[1][1] == card[2][0]):
        return True
    
    return False

bingo_nums = [[0 for i in range(3)] for j in range(3)]

for i in range(3):
    a,b,c = map(int,input().split())
    bingo_nums[i][0] = a
    bingo_nums[i][1] = b
    bingo_nums[i][2] = c


N = int(input())
for i in range(N):
    num = int(input())
    
    for i in range(3):
        for j in range(3):
            if bingo_nums[i][j] == num:
                bingo_nums[i][j] = 0
                break
            
if isBingo(bingo_nums):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
/*
Author : Aditya Gupta
Team : TechTurtle
Date : 02-06-2020
Time : 20:05:54
*/

 
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define vll vector<ll>
#define vvll vector< vll >
#define vld vector< ld >
#define vvld vector< vld >
#define pll pair<ll ,ll >
#define vpll vector< pll >
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define endl "\n"
#define flash ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test ll t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define ff first
#define ss second
#define mk(arr,n,type)  type *arr=new type[n];

 
#define forn(i,n) for(ll (i) = 0 ; (i) < (n) ; ++(i))
#define for1(i,n) for(ll (i) = 1 ; (i) <= (n) ; ++(i))
#define forr(i,n) for(ll (i) = (n)-1 ; (i)>=0 ; --(i))
#define forab(i,a,b,c) for(ll (i) = a ; (i) <= (b) ; (i)+=(c))
 
using namespace std;
 
///////////////////////////////////////////////////////////////////////// Maths //////////////////////////////////////////////////////////////////////////////

//vll sieve;
//void Sieve(int N){  //smallest prime factor
//	const ll maxn = N;
//	sieve.resize(maxn);
//	forn(i,maxn) sieve[i] = i;
//	sieve[1] = -1;
//	sieve[0] = -1;
//	forab(i,2,maxn,1) if(i == sieve[i]) for(ll j = i*i ; j < maxn ; j+=i) if(sieve[j] == j) sieve[j] = i;
//	
////	for(auto i:sieve){
////		cout<<i<<" ";
////	}
//
//}
vll sieve;
vll* Sieve(int N){
	const ll maxn = N;
	sieve.resize(maxn);
	forn(i,maxn) sieve[i] = 1;
	sieve[1] = 0;
	sieve[0] = 0;
	forab(i,2,maxn,1) if(1 == sieve[i]) for(ll j = i*i ; j < maxn ; j+=i) sieve[j] = 0;
	
	vll* primes=new vll();
	primes->pb(2);
	for(int i=3;i<maxn;i+=2)
	if(sieve[i]){
		primes->pb(i);
	}
	return primes;
 
}
 
   
ll extended_GCD(ll a , ll b , ll &x , ll &y){
	if(a == 0){
		x = 0;
		y = 1;
		return b;
	}
	ll x1 , y1;
	ll gcd = extended_GCD(b%a , a , x1 , y1);
	x = y1 - (b/a)*x1; 
	y = x1;
	return gcd;
}
 
ll power(ll a, ll b, ll m = MOD) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
 
ll modinv(ll a , ll mod = MOD){
	ll x , y;
	extended_GCD(a , mod , x , y);
	if(x < 0) x += mod;
	return x;
}
  
 
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 bool prime(int n){
 	int c=0;
 	for(int i=2;(i*i)<=n;i++)
 	{
	 if(n%i==0)
 	{
	 c++;
	 return false;
}
}
 	if(c==0)
 	return true;
 }
// bool compareInterval(char i1, char i2) 
//{ 
//    return (i1 < i2); 
//}
// int countoperation(int n,m){
// 	vector<int> d<m+1,-1>;
// }

int val[100001];
pair<int,int> st[4*100001];


void solve(){
	int n;
	cin>>n;
	if(n>=30)
	cout<<"Yes\n";
	else
	cout<<"No\n";
	
}
	

int main()
{
	flash
//	freopen("input.txt","r",stdin);
//	freopen("output.txt","w",stdout); 

//  test
	 solve();
    return 0;
}


Measured memory_bytes: 3648
// luogu-judger-enable-o2
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<ctime>
const  int N = 2e6 + 5;
const long long mod = 2e10 + 7;
const int INF = 0x3f3f3f3f;
typedef long long ll;
typedef long double lw;
#define sc(n) scanf("%d",&n)
#define fo(i,a,b) for(int i=a;i<b;i++)
#define mem(a,b) memset(a,b,sizeof a)
using namespace std;
int n,m;
int ans=INF;
int a[N];
int sum1,sum2;
int main()
{
   cin>>n;
   fo(i,0,n)
   {
   sc(a[i]);
   sum2+=a[i];
   } 
   fo(i,0,n)
   {
   	sum1+=a[i];
   	sum2-=a[i];
   	ans=min(ans,abs(sum1-sum2));
	}   
	cout<<ans<<endl;
}

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

int abs(int a)
{       
        if(a<0){
                return(-1*a);
        }else{  
                return(a);
        }        
}       
        


int main()
{       
        int N,L;
        cin >> N >> L;
        int apple = 1000;
        for(int i = 0;i<N;++i){                
                int apple_i = L+i;
                if(abs(apple_i)<abs(apple)){
                        apple = apple_i;
                }       
        }       
        int ans = ((L+L+N-1)*N/2)-apple;
        cout << ans << endl;
}       

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    long long d, a;
    cin >> n >> d >> a;
    vector<pair<int, int>> p(n);
    for(int i = 0; i < n; i++){
    	cin >> p[i].first >> p[i].second;
    }
    sort(p.begin(), p.end());
    d *= 2;
    long long tot = 0;
    queue<pair<long long, long long>> q;
    long long ans = 0;
    for(int i = 0; i < n; i++){
    	long long x = p[i].first;
    	long long h = p[i].second;
    	while(q.size() && q.front().first < x){
    		tot -= q.front().second;
    		q.pop();
    	}
    	h -= tot;
    	if(h > 0){
    		long long num = (h+a-1)/a;
    		ans += num;
    		long long dam = num * a;
    		tot += dam;
    		q.emplace(x+d, dam);
    	}
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3456
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
d = defaultdict(int)
m = 0
for i in a:
    d[i] += 1
    m = max(m,i)
res = 1
tmp = 1
for i in range(m+1):
    if i == 0:
        if d[i] != 1 or a[0] != 0:
            print(0)
            quit()
        continue
    if d[i] == 0:
        res = 0
        break
    if i == 1:
        tmp = d[i]
        continue
    res *= (tmp ** d[i] )%998244353
    tmp = d[i]
print(res%998244353)


Measured memory_bytes: 62352
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w",stdout);
    #endif
    int x,y;
    cin>>x>>y;
    if(y&1){
        cout<<"No";
        return 0;
    }
    int turtle = (y/2) - x;
    if(turtle<0){
        cout<<"No";
        return 0;
    }
    int cranes = x - turtle;
    if(cranes>=0){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if (s.length() < 26) {
        vector<int> used(26, false);
        for (char c : s) used[c - 'a'] = true;
        for (int i = 0; i < 26; i++) {
            if (used[i]) continue;
            s += (char)('a' + i);
            break;
        }
        cout << s << endl;
    } else {
        vector<int> v;
        for (char c : s) v.push_back(c - 'a');
        if (next_permutation(v.begin(), v.end())) {
            for (int i = 0; i < 26; i++) {
                char c = (char)('a' + v[i]);
                cout << c;
                if (c != s[i]) break;
            }
            cout << endl;
        } else {
            cout << -1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input!{
        n: u64,
        m: u64,
    }
    println!("{}", 2u64.pow(m as u32) * (100 * (n - m) + 1900 * m));
}


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

#define ll long long
#define pb push_back
#define F first
#define S second

using namespace std;

const int N = 300005;

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    char a, b, c, d;
    cin >> a >> b >> c >> d;
    int x = 10 * (a - '0') + b - 48;
    int y = 10 * (c - '0') + d - 48;
    if (x < 1 || x > 12) {
        if (y >= 1 && y <= 12) {
            cout << "YYMM" << endl;
        } else {
            cout << "NA" << endl;
        }
    } else if (y < 1 || y > 12) {
        if (x >= 1 && x <= 12) {
            cout << "MMYY" << endl;
        } else {
            cout << "NA" << endl;
        }
    } else {
        cout << "AMBIGUOUS" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef pair<int,int> P;
bool pole[5001][5001];
int main() {
	int n;
	while(scanf("%d",&n),n) {
		vector<P> V;
		fill((bool*)pole,(bool*)(pole+5001),0);
		for(int i=0;i<n;i++) {
			int x,y;
			scanf("%d %d",&x,&y);
			pole[x][y]=1;
			V.push_back(P(x,y));
		}
		sort(V.begin(),V.end());
		int ans=0;
		for(int i=0;i<V.size();i++) {
			for(int j=i+1;j<V.size();j++) {
				int x1=V[i].first,y1=V[i].second;
				int x2=V[j].first,y2=V[j].second;
				int dx=x2-x1;
				int dy=abs(y2-y1);
				bool OK=0;
				for(int k=1;k>=-1;k-=2) {
					int nx1=x1+k*dy,ny1=y1+k*dx;
					int nx2=x2+k*dy,ny2=y2+k*dx;
					if(0>nx1||nx1>=5000||0>ny1||ny1>=5000||0>nx2||nx2>=5000||0>ny2||ny2>=5000||!pole[nx1][ny1]||!pole[nx2][ny2]) continue;
					OK=1;
					break;
				}
				if(OK) ans=max(ans,dx*dx+dy*dy);
			}
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 25516