akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int sort(const void * a, const void * b){
    if( *(long long int*)a - *(long long int*)b < 0 )
        return -1;
    if( *(long long int*)a - *(long long int*)b > 0 )
        return 1;
    return 0;
}

int main(void){
    int n;
    scanf("%d",&n);
    long long a[n],sum[n+1],ans=0,tmp=0;
    sum[0]=0;
    for (int i=0; i<n; i++){
        scanf("%lld",&a[i]);
        sum[i+1]=sum[i]+a[i];
    }
    qsort (sum,n+1,sizeof(long long),sort); 
    for (int i=0; i<n+1; i++){
        if(sum[i]==sum[i+1]){
            tmp++;
        } else {
            tmp++;
            ans+=(tmp-1)*tmp/2;
            tmp=0;
        }
    }
    ans+=(tmp-1)*tmp/2;
    printf("%lld\n",ans);
	return 0 ;
}

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

#define ll long long
#define ull unsigned long long

const ull MOD = 1000000007;

using namespace std;

const ull maxN = 100010;

ull dp[maxN];

int main() {
	ull N, M;
	cin >> N >> M;

	vector <bool> skip(N, false);
	for (int ii = 0; ii < M; ++ii){
		int index;
		cin >> index;
		skip[index] = true;
	}

	//dpの初期化
	dp[0] = 1;
	for (int ii = 1; ii < maxN; ++ii){
		dp[ii] = 0;
	}

	//1段目
	if (!skip[1]){
		dp[1] = dp[0];
	}
	//2段目以降
	for (int ii = 2; ii <= N; ++ii){
		if (!skip[ii]){
			dp[ii] = (dp[ii-1] + dp[ii-2]) % MOD;
		}
	}

	cout << dp[N] << endl;

	return 0;
}


Measured memory_bytes: 1024
H, W, N = map( int, input().split())
V = [H-1]*W
X = [(0,0)]*N
#X = [ tuple( map( int, input().split())) for _ in range(N)]
for i in range(N):
    x, y = map( int, input().split())
    X[i] = (y,x)
X.sort()
#X.sort(key = lambda x:x[1])
d = 0
for i in range(N):
    y, x = X[i]
    x, y = x-1, y-1
    if x == y+d:
        d += 1
    elif x > y+d:
        V[y] = min( V[y], x-1)
print( min(V)+1)


Measured memory_bytes: 33232
#include <iostream>

using namespace std;

int main(){
	int i,j,N,c;
	int k;
	cin >> N >> k;
	int d[k];
	for(i=0;i<k;i++){
		cin >> d[i];
	}
	
	for(i=0;i<10;i++){
		c = 0;
		for(j=0;j<k;j++){
			if(i==d[j] || i<N){
				c = 1;
			}
		}
		if(c==0){
			cout << i << endl;
			return 0;
		}
	}
	
	for(i=10;i<100;i++){
		c = 0;
		for(j=0;j<k;j++){
			if((i/10)==d[j] || i%10==d[j] || i<N){
				c = 1;
			}
		}
		if(c==0){
			cout << i << endl;
			return 0;
		}
	}
	
	for(i=100;i<1000;i++){
		c = 0;
		for(j=0;j<k;j++){
			if((i/100)==d[j] || (i-i/100*100)/10==d[j] || i%10==d[j] || i<N){
				c = 1;
			}
		}
		if(c==0){
			cout << i << endl;
			return 0;
		}
	}
	
	for(i=1000;i<10000;i++){
		c = 0;
		for(j=0;j<k;j++){
			if((i/1000)==d[j] || (i-i/1000*1000)/100==d[j] || (i%100-i%10)/10==d[j]|| i%10==d[j] || i<N){
				c = 1;
			}
		}
		if(c==0){
			cout << i << endl;
			return 0;
		}
	}
	
	for(i=10000;i<100000;i++){
		c = 0;
		for(j=0;j<k;j++){
			if((i/10000)==d[j] || (i-i/10000*10000)/1000==d[j] || (i%1000-i%100)/100==d[j]|| (i%100-i%10)/10==d[j] || i%10==d[j] || i<N){
				c = 1;
			}
		}
		if(c==0){
			cout << i << endl;
			return 0;
		}
	}
}

	

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

using ll = long long;

// Union-Find木
struct UnionFind {
  vector<int> par;
  
  // Constructor
  UnionFind(int n): par(n) {
    for(int i = 0; i < n; i++) par[i] = i;
  }
  
  // n要素で初期化
  void init(int n) {
    par.resize(n);
    for(int i = 0; i < n; i++) par[i] = i;
  }
  
  // 根の検索
  int find(int x) {
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
  }
  
  // xとyの属する集合を併合
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return false;
    par[x] = y;
    return true;
  }
  
  // xとyが同じ集合に属するか
  bool same(int x, int y) {
    return find(x) == find(y);
  }
};

static const ll MAX = 1e5 + 1;

// クラスカル法(Union-Findと同時に使う) O(|E|log|E|)
vector<pair<ll, ll>> G[MAX];
// main関数からこれらを削除すること

ll kruskal(int n) { // n:頂点数
  vector<tuple<int, int, int>> x;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < G[i].size(); j++){
      x.emplace_back(make_tuple(G[i][j].second, i, G[i][j].first));
    }
  }
  
  sort(x.begin(), x.end()); // 辺の重みでソート
  
  UnionFind uf(n);
  
  int totalCost = 0;
  // vector<tuple<int, int, int>> MST; // 最小全域木
  for(int i = 0; i < x.size(); i++){
    if(!uf.same(get<1>(x.at(i)), get<2>(x.at(i)))){
      totalCost += get<0>(x.at(i));
      // MST.emplace_back(make_tuple(get<1>(x.at(i)), get<2>(x.at(i)), get<0>(x.at(i))));
      uf.unite(get<1>(x.at(i)), get<2>(x.at(i)));
    }
  }
  return totalCost;
  // return MST;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  // 重み付き無向(有向)グラフの隣接リスト
  int n; // n:頂点数
  cin >> n;
  
  //vector<pair<ll, ll>> G[n]; // G:頂点数がnのグラフを表す隣接リスト
  
  int u, v;
  vector<tuple<ll, ll, ll>> x, y;
  for(int i = 0; i < n; i++){
    cin >> u >> v;
    x.emplace_back(make_tuple(u, v, i));
    y.emplace_back(make_tuple(v, u, i));
  }
  
  sort(x.begin(), x.end());
  
  tuple<ll, ll, ll> t1, t2;
  for(int i = 1; i < n; i++){
    t1 = x.at(i - 1);
    t2 = x.at(i);
    G[get<2>(t1)].emplace_back(make_pair(get<2>(t2), min(abs(get<0>(t1) - get<0>(t2)), abs(get<1>(t1) - get<1>(t2)))));
    G[get<2>(t2)].emplace_back(make_pair(get<2>(t1), min(abs(get<0>(t1) - get<0>(t2)), abs(get<1>(t1) - get<1>(t2)))));
  }
  
  sort(y.begin(), y.end());
  
  for(int i = 1; i < n; i++){
    t1 = y.at(i - 1);
    t2 = y.at(i);
    G[get<2>(t1)].emplace_back(make_pair(get<2>(t2), min(abs(get<0>(t1) - get<0>(t2)), abs(get<1>(t1) - get<1>(t2)))));
    G[get<2>(t2)].emplace_back(make_pair(get<2>(t1), min(abs(get<0>(t1) - get<0>(t2)), abs(get<1>(t1) - get<1>(t2)))));
  }
  
  cout << kruskal(n) << '\n';
}

Measured memory_bytes: 24488
N = int(input())
P = [int(i) for i in input().split()]
Q = [int(i) for i in input().split()]

import itertools

A = list(range(1, N + 1))
L = []

for i in itertools.permutations(A, N):
    L.extend([list(i)])

for index, value in enumerate(L):
    if L[index] == P:
        p = index
    if L[index] == Q:
        q = index

print(abs(p - q))

Measured memory_bytes: 10228
from collections import deque

def main():
    n, m = map(int, input().split())
    graph = [[] for _ in range(n+1)]
    parents = [0] * (n+1)
    for _ in range(m):
        src, dst = map(int, input().split())
        graph[src].append(dst)
        parents[dst] += 1

    q = deque()
    for i in range(1, n+1):
        if parents[i] == 0:
            q.append(i)

    dists = [0] * (n+1)
    for i in q:
        dists[0] = 0

    while q:
        at = q.popleft()
        for to in graph[at]:
            parents[to] -= 1
            if parents[to] == 0:
                q.append(to)
                dists[to] = dists[at] + 1

    print(max(dists[1:]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 23832
import sys
import queue
input = sys.stdin.readline

def main():
    N, M, P = map(int, input().split())
    g = [[] for _ in range(N+1)]
    g2 = [[] for _ in range(N+1)]
    data = [list(map(int, input().split())) for _ in range(M)]
    for a, b, _ in data:
        g2[b].append(a)
        g[a].append(b)

    visit = [False]*(N+1)
    visit2 = [False]*(N+1)

    q = queue.Queue()
    q.put(1)
    visit[1] = True
    while (not q.empty()):
        now = q.get()
        for next in g[now]:
            if not visit[next]:
                visit[next] = True
                q.put(next)

    q = queue.Queue()
    q.put(N)
    visit2[N] = True
    while (not q.empty()):
        now = q.get()
        for next in g2[now]:
            if not visit2[next]:
                visit2[next] = True
                q.put(next)

    for i in range(1, N+1):
        visit[i] = visit[i] and visit2[i]


    INF = 1000000001
    d = [(-1)*INF for i in range(N+1)]
    d[1] = 0

    for i in range(N):
        d_N = [d[i] for i in range(1, N+1) if visit[i]]
        for j in range(M):
            a = data[j][0]
            b = data[j][1]
            c = data[j][2]
            d[b] = max(d[b], d[a]+c-P)
        if i == N-1:
            if d_N != [d[i] for i in range(1, N+1) if visit[i]]:
                ans = -1

            else:
                ans = d[N]

    if ans == -1:
        print(-1)
    else:
        print(max(0, ans))

if __name__ == "__main__":
    main()


Measured memory_bytes: 60884
using System;

namespace atcoderA
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            int B = int.Parse(input[1]);
            var ans = "";
            if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)
            {
                ans = "Possible";
            }
            else
            {
                ans = "Impossible";
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
int main(){
    ll a,b,c; cin >> a >> b >> c;
    ll x,y; cin >> x >> y;
    c *= 2;
    ll ans = INF;
    rep(i,max(x,y)+1){
        ll temp = 0;
        temp += i*c;
        temp += max(0LL,x-i) * a;
        temp += max(0LL,y-i) * b;
        chmin(ans,temp);
    }
    cout << ans << endl;
}

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

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

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

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

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

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

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
      n: usize,
    }
    let mut w = 1;
    let mut s = 0;
    while s < n {
        s += w;
        w += 1;
    }
    w -= 1;
    if n != s {
        println!("{}", "No");
        return;
    }

    let mut t = vec![vec![0; w]; w+1];
    {
        let mut w = w;
        let mut i = 0;
        let mut s = 1;
        while w > 0 {
            for (j, v) in (s..s+w).enumerate() {
                t[i][i+j] = v;
                t[i+j+1][i] = v;
            }
            s += w;
            w -= 1;
            i += 1;
        }
    }
    println!("Yes");
    println!("{}", w+1);
    for i in 0..w+1 {
        print!("{} ", w);
        for j in 0..w {
            print!("{}", t[i][j]);
            if j != w - 1 {
                print!(" ")
            }
        }
        println!("");
    }
}


Measured memory_bytes: 5500
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && b == c && c == a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.Stack;

public class Main{
	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	static int mod = (int) (1e9+7),n;
	static long cf = 998244353;
    static final int MAX = (int) 1e6;
    public static List<Integer>[] edges;
    public static int[][] parent;
    public static int col = 20;
    public static long[] Bit;
    public static long[] fac,inv;
    public  static int[] prime; 
    public static long[] dp;
	public static FastReader sc = new FastReader();
	public static void main(String[] args) {
	//	Scanner sc = new Scanner(System.in);
 
		char[] s = sc.next().toCharArray();
		int n = s.length;
		int ans = 0;
		for(int i=0;i<n/2;++i) {
			if(s[i] != s[n-i-1]) ++ans;
		}
		out.print(ans);
		out.close();
	}
	
	
}

Measured memory_bytes: 22612
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author jignesh1604
 */

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

using namespace std;

class AtcoderA {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	    int k ;
	    in >> k ;
	    out << a[k-1] << "\n" ;

	}
};


int main() {
	AtcoderA solver;
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

ll d,s,a[11],b[11],c[11],ans=INF;
bool e[11];

void cal(){
	ll sum=0,num=0;
	for(int i=0;i<d;i++){
		if(e[i]){
			sum+=c[i];
			num+=a[i];
		}
	}
	ll now=d-1;
	while(sum<s){
		if(e[now]!=1){
			sum+=a[now]*(now+1)*100;
			num+=a[now];
		}
		if(sum>s){
			num-=(sum-s)/((now+1)*100);
		}
		now--;
	}
	ans=min(ans,num);
}
void dep(ll n){
	if(n==d){
		cal();
		return;
	}
	e[n]=0;dep(n+1);
	e[n]=1;dep(n+1);
}

int main() {
	cin>>d>>s;
	for(int i=0;i<d;i++){
		ll x,y;
		cin>>x>>y;
		a[i]=x;
		b[i]=y;
	}
	for(int i=0;i<d;i++){
		c[i]=a[i]*100*(i+1)+b[i];
	}
	dep(0);
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #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
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;


 int ans1,ans2;

 int arr[1000];


int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS

    

      int n,m;
      cin >> n >> m;

      for(int i = 1; i <= m; i++)
      {
        int x,y;
        cin >> x >> y;
        arr[x]++;
        arr[y]++;
      }

      for(int i = 1; i <= n; i++)
      {
        cout << arr[i] << endl;
      }







    return 0;   
}


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

int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int i,n,m,s=0;
    
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        scanf("%d",&m);
        if(m%4==0) s+=2;
        else if(m%2==0) s++;
    }
    
    if(s>=n-n%2)
        printf("Yes\n");
    else
        printf("No\n");
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    int n,m;cin >> n >> m;
    vector<vector<int>> s(m);
    rep(i,m){
        int k;cin >> k;
        rep(j,k){
            int a;cin >> a;--a;
            s[i].push_back(a);
        }
    }
    vector<int> p(m);
    rep(i,m) cin >> p[i];

    ll res =0;
    for (int bit = 0;bit < (1<<n);++bit){
        bool ok = true;
        rep(i,m){
            int con = 0;
            for (auto v :s[i]){
                if (bit & (1<<v)) ++con;
            }
            if (con % 2 != p[i]) ok = false;
        }
        if (ok) ++res;
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<iomanip>
#include<cmath>
#include<vector>
#include<set>

using namespace std;
int main(){
int n,m,c;
cin >>n>>m>>c;
int b[m];
for(int i=0;i<m ;i++)
cin >>b[i];
int count=n;
int ans=0;
while(count){
  int sum=0;
  int a[m];
  for(int i=0; i<m; i++){
    cin>>a[i];
    sum+=a[i]*b[i];
  }
  if(sum+c>0) ans++;

  count--;
}
cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <string.h>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>

#define MP(A,B) make_pair(A,B)
#define PB(A) push_back(A)
#define SIZE(A) ((int)A.size())
#define LEN(A) ((int)A.length())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define fi first
#define se second

using namespace std;

template<typename T>inline bool upmin(T &x,T y) { return y<x?x=y,1:0; }
template<typename T>inline bool upmax(T &x,T y) { return x<y?x=y,1:0; }

typedef long long ll;
typedef unsigned long long ull;
typedef long double lod;
typedef pair<int,int> PR;
typedef vector<int> VI;

const lod eps=1e-11;
const lod pi=acos(-1);
const int oo=1<<30;
const ll loo=1ll<<62;
const int mods=998244353;
const int MAXN=100005;
const int INF=0x3f3f3f3f;//1061109567
/*--------------------------------------------------------------------*/
inline int read()
{
	int f=1,x=0; char c=getchar();
	while (c<'0'||c>'9') { if (c=='-') f=-1; c=getchar(); }
	while (c>='0'&&c<='9') { x=(x<<3)+(x<<1)+(c^48); c=getchar(); }
	return x*f;
}
int n,ans,d[MAXN],a[MAXN],c[MAXN],b[MAXN];
vector<int> e[MAXN];
char s[MAXN];
void dfs1(int x,int father) 
{
	b[x]=c[x];
	for (int v:e[x]) 
		if (v!=father) dfs1(v,x),b[x]|=b[v];
	ans+=b[x];
	if (!b[x]) a[father]^=1;
}

void dfs2(int x,int father) 
{
	d[x]=d[father]+c[x];
	for (int v:e[x])
		if (b[v]&&v!=father) dfs2(v,x);
}

int main() 
{
	n=read();
	for (int i=1,x,y;i<n;i++) 
		x=read(),y=read(),e[x].PB(y),e[y].PB(x),a[x]^=1,a[y]^=1;
	scanf("%s",s+1);
	int rt=0;
	for (int i=1;i<=n;i++) 
	{
		c[i]=(s[i]=='W');
		if (s[i]=='W') rt=i;
	}
	if (!rt) { puts("0"); return 0; }
	dfs1(rt,0);
	ans=(ans-1)<<1;
	if (!ans) { puts("1"); return 0; }
	for (int i=1;i<=n;i++) if (b[i]) ans+=c[i]^=a[i];
	d[rt]=0,dfs2(rt,0); for (int i=1;i<=n;i++) if (b[i]&&d[i]>d[rt]) rt=i;
	d[rt]=0,dfs2(rt,0); for (int i=1;i<=n;i++) if (b[i]&&d[i]>d[rt]) rt=i;
	printf("%d\n",ans-d[rt]*2);
	return 0;
}


Measured memory_bytes: 18648
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int n, l[15];
    cin >> n;
    int sum = 0, max = 0;
    for (int i = 0; i < n; i++) {
        cin >> l[i];
        if (l[i] > max) max = l[i];
        sum += l[i];
    }
    
    if (sum - max <= max) cout << "No" << endl;
    else cout << "Yes" << endl;
    
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,M,A,i,s=0,l;
    cin>>N>>M;
    for(i=0;i<M;i++)
    {
        cin>>A;
        s+=A;

    }
    if(N>s)
    {
      l=N-s;
     printf("%d",l);
    }
    else if(N<s)
    {
printf("-1");
    }
    else
    {
        printf("0");
    }
return 0;
}


Measured memory_bytes: 3764
from sys import stderr

def debug(*args):
    print(*args, file=stderr)

n_observatory_num, m_roads_num = map(int, input().split())
hi_heights = list(map(int, input().split()))

# def get_height_for(a_observaotry):
#     return hi_heights[a_observaotry+1]

ab_roads_fromto = [map(lambda x: int(x) - 1, input().split()) for _ in range(m_roads_num)]


observatory_x_connected_to = {}

for a, b in ab_roads_fromto:
    if not a in observatory_x_connected_to:
        observatory_x_connected_to[a] = []
    if not b in observatory_x_connected_to:
        observatory_x_connected_to[b] = []

    observatory_x_connected_to[a].append(b)
    observatory_x_connected_to[b].append(a)

# debug(observatory_x_connected_to)

result = 0
for observatory_i, observatory_i_height in enumerate(hi_heights):
    # observatory_i_height = get_height_for(observatory_i)
    if not observatory_i in observatory_x_connected_to:
        # debug('good no connection' + str(observatory_i))
        result += 1
        continue

    good = True
    for connected_to in observatory_x_connected_to[observatory_i]:
        if observatory_i_height <= hi_heights[connected_to]:
            good = False
            # debug('not good' + str(observatory_i))
            break
    
    if good:
        # debug('good highest' + str(observatory_i))
        result += 1

print(result)


Measured memory_bytes: 76520
#include<iostream>
#include<vector>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int main(){
  int n; cin >>n;
  vector<int> vec(1);
  cin >>vec[0];
  int flag=0,temp=vec[0];
  rep(i,n-1){
    int x; cin >>x;
    if(flag){
      if(temp<=x) *vec.rbegin()=x;
      else{
        vec.push_back(x);
        flag^=1;
      }
    }else{
      if(temp>=x) *vec.rbegin()=x;
      else{
        vec.push_back(x);
        flag^=1;
      }
    }
    temp=x;
  }
  if(vec.size()%2) vec.pop_back();
  li a=1000,b=0;
  n=vec.size();flag=1;
  if(df)rep(i,n)print(vec[i]);
  rep(i,n){
    if(flag){
      b=a/vec[i];
      a%=vec[i];
    }else{
      a+=b*vec[i];
      b=0;
    }
    flag^=1;
  }
  print(a);
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define int long long
#define endre getchar();getchar();return 0
#define INF 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define in for(int i=0;i<n;i++)cin>>a[i];
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return (y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int n) {
	if (n == 0)return 1;
	return (kai(n - 1)*n) % INF;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int mystoi(string s) {
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		cnt += (int)(s[i] - '0') * pow(10, s.size() - i - 1);
	}
	return cnt;
}
int h, w, c[15][15], a, ans;
signed main() {
	cin >> h >> w;
	rep(i, 10) {
		rep(j, 10) {
			cin >> c[i][j];
		}
	}
	rep(k, 10) {
		rep(i, 10) {
			rep(j, 10) {
				c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
			}
		}
	}
	rep(i, h) {
		rep(j, w) {
			cin >> a;
			if (a != -1) {
				ans += c[a][1];
			}
		}
	}
	cout << ans << endl;
	endre;
}

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

int main()
{
    int N, K;
    cin >> N >> K;
    bool A[N] = {false};

    for (int i = 0; i < K; ++i)
    {
        int d;
        cin >> d;
        for (int j = 0; j < d; ++j)
        {
            int a;
            cin >> a;
            A[a - 1] = true;
        }
    }
    int ans = 0;
    for (int i = 0; i < N; ++i)
    {
        if (!A[i])
        {
            ++ans;
        }
    }
    cout << ans << endl;
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N; cin >> N;
	vector<int>B(N + 2,INF);
	rep(i, 1, N) {
		cin >> B[i];
	}

	int ans = 0;
	rep(i, 1, N + 1) {
		ans += min(B[i - 1], B[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
const long long mod = 1e9 + 7;
typedef long long ll;
typedef priority_queue<int> PQ;
typedef vector<long long> VL; // VL a(n);
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VL> VLL; // VII a(n,VI(m)) n * m
typedef pair<ll, ll> PL;
typedef map<ll, ll> MP; // MP a;
typedef vector<pair<ll, ll>> PS; // PS a(n);

template <class T, class U>
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp
// operator << (cout,a);
// chmin(min,a)

int main() {
  ll n,k,m,x=0,y=0,z = 0,h=0,w=0,ans=0,sum = 0, Max = -1, Min = 3e9+1;
  string t;
  bool ok=true; 
  cin >> n >> h;
  VL a(n),b(n);
  rep(i,n){
    cin >> a[i] >> b[i];
  }

  sort(ALL(a));
  sort(RALL(b));
  Max = a[n-1];


  rep(i,n){
    if(Max < b[i]){
      h -= b[i];
      ans++;
    }
    if(h<=0){
      pri(ans);
      return 0; 
    }
  }
  ans += (ll)ceil((double)h/(double)Max);
  pri(ans);
  return 0;
}

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

int fa(int x){
  return x/10000;  
}

int main() 
{
    int A, B,Smin=0, Smax=0, res=0,cnt=0;
    cin >> A >> B;
 
    Smin = fa(A);
    Smax = fa(B);

    for (int a = Smin; a <= Smax; a++) {
      for (int b = 0; b <= 9; b++) {
        for (int c = 0; c <= 9; c++) {
          res = 10000*a+1000*b+100*c+10*b+a;
          if (A <= res && B >= res) cnt++; 
          res = 0;
        }
      }
    }
  
    cout << cnt << endl; 
  return 0;
}


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

using namespace std;

int n, k;
long long a[100001];
long long sum[100001];
long long sum_plus[100001];

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

        long long s1 = 0;
        long long s2 = 0;
        for (int i = 0; i < n; i++) {
                cin >> a[i];
                s1 += a[i];
                s2 += max(0LL, a[i]);

                sum[i + 1] = s1;
                sum_plus[i + 1] = s2;
        }

        sum[0] = 0;
        sum_plus[0] = 0;

        long long ans = 0;
        for (int i = 0; i <= n - k; i++) {
                ans = max(ans,
                          sum_plus[i] + max(sum[i + k] - sum[i], 0LL) +
                              (sum_plus[n] - sum_plus[i + k]));
        }

        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 2560
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
int main()
{
  char A,B;
  scanf("%c %c",&A,&B);
  if(A-B == 0)
    printf("=\n");
  else if( A - B > 0){
    printf(">\n");
  }else
    printf("<\n");
  return 0;
}


Measured memory_bytes: 128
x, n = gets.split.map(&:to_i)
p = gets.split.map(&:to_i)
(0..100).each do |t|
  unless p.include?(x-t)
    puts x-t
    exit 0
  end
  unless p.include?(x+t)
    puts x+t
    exit 0
  end
end

Measured memory_bytes: 14328
#include<cstdio>
#include<cstring>
int main(){
    int n;
    double ans=0.0,x;
    char s[5];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%lf %s",&x,s);
        if(strcmp(s,"JPY")==0){
            ans+=x;
        }
        else{
            ans+=x*380000.0;
        }
    }
    printf("%.6f\n",ans);
}

Measured memory_bytes: 128
n=int(input())
A=list(map(int,input().split()))
q=int(input())
BC=[list(map(int,input().split())) for i in range(q)]
Alist=[0]*(10**5+1)
ans=[]

for a in A:
    Alist[a]+=1

sum=0
for i in range(1,len(Alist)):
    sum+=i*Alist[i]

for bc in BC:
    sum=sum-bc[0]*Alist[bc[0]]+bc[1]*Alist[bc[0]]
    Alist[bc[1]]+=Alist[bc[0]]
    Alist[bc[0]]=0
    ans.append(sum)
ans='\n'.join(map(str,ans))
print(ans)

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

main(){
    int n, i, ans;
    double minv, bmi, w, h;
    while( cin >> n && n ){
	minv = (1<<21);
	for ( int j = 0; j < n; j++ ){
	    cin >> i >> h >> w;
	    h *= 0.01;
	    bmi = w/(h*h);
	    if ( fabs(22-bmi) < minv ){
		minv = fabs(22-bmi);
		ans = i;
	    }
	}
	cout << ans << endl;
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int a, b, c, x;
	cin >> a >> b >> c >> x;
	int cnt=0;
	for(int i=0; i<=a; i++){
		for(int j=0; j<=b; j++){
			if(0 <= (x-500*i-100*j)/50 && (x-500*i-100*j)/50 <= c){
				cnt++;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int a,b;
int main()
{
    scanf("%d%d",&a,&b);
    if(a>0)puts("Positive");              
    else if(b>=0)puts("Zero");             
    else if((a&1)^(b&1))puts("Positive");  
    else puts("Negative");
    return 0;
}

Measured memory_bytes: 128
<?php
// D
fscanf(STDIN, '%d', $k);
$arr = f();
// var_dump($arr);
echo $arr[$k - 1];

function f()
{
    global $k;
    $res = [];
    for ($i = 1; $i <= 9; $i++) {
        $res[] = $i;
    }
    $keta = 2;
    while (count($res) < $k) {
        for ($i = 1; $i <= 9; $i++) {
            $res = array_merge($res, getRunrun($i, $keta - 1));
        }
        $keta++;
    }
    sort($res);
    return $res;
}

function getRunrun($n, $keta)
{
    static $memo;
    if (isset($memo[$n][$keta])) return $memo[$n][$keta];
    for ($i = max($n - 1, 0); $i <= min($n + 1, 9); $i++) {
        $arr[] = (int) (strval($n) . strval($i));
    }
    if ($keta === 1) {
        $memo[$n][$keta] = $arr;
        return $arr;
    }
    $res = [];
    foreach ($arr as $v) {
        $tmp = getRunrun($v % 10, $keta - 1);
        foreach ($tmp as $v2) {
            $res[] = (int) (strval($n) . str_pad($v2, $keta, 0, STR_PAD_LEFT));
        }
    }
    $memo[$n][$keta] = $res;
    return $res;
}

Measured memory_bytes: 31216
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;
//const ll mod = 998244353LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,0,-1,0,1,1,-1,-1 }, dy[9] = { 0,0,1,0,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222



ll mat[77][55][55];
ll mat1[55][55], mat2[55][55];


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


  cin >> n >> m;
  rep(i, n) rep(j, n) cin >> mat[0][i][j];
  rep(i, 64) {
    rep(x, n) rep(y, n) {
      ll sum = 0;
      rep(k, n) {
        (sum += mat[i][x][k] * mat[i][k][y]) %= mod;
      }
      mat[i + 1][x][y] = sum;
    }
  }

  rep(i, n) mat1[i][i] = 1;

  rep(i, 64) {
    if (!(m >> i & 1)) continue;
    rep(x, n) rep(y, n) {
      ll sum = 0;
      rep(k, n) {
        (sum += mat[i][x][k] * mat1[k][y]) %= mod;
      }
      mat2[x][y] = sum;
    }
    rep(x, n) rep(y, n) mat1[x][y] = mat2[x][y];
  }

  rep(x, n) rep(y, n) (ans += mat1[x][y]) %= mod;
  cout << ans << endl;


  return 0;
}

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

inline int64_t hilbertOrder(int x, int y, int pow, int rotate) {
	if (pow == 0) {
		return 0;
	}
	int hpow = 1 << (pow-1);
	int seg = (x < hpow) ? (
		(y < hpow) ? 0 : 3
	) : (
		(y < hpow) ? 1 : 2
	);
	seg = (seg + rotate) & 3;
	const int rotateDelta[4] = {3, 0, 0, 1};
	int nx = x & (x ^ hpow), ny = y & (y ^ hpow);
	int nrot = (rotate + rotateDelta[seg]) & 3;
	int64_t subSquareSize = int64_t(1) << (2*pow - 2);
	int64_t ans = seg * subSquareSize;
	int64_t add = hilbertOrder(nx, ny, pow-1, nrot);
	ans += (seg == 1 || seg == 2) ? add : (subSquareSize - add - 1);
	return ans;
}



const int N = 5e5+7, RT = 800;
int cnt[N], a[N], out[N], l[N], r[N];
long long ord[N];
int ans = 0;

void add(int x) {
    if (cnt[x] == 0)    ans++;
    cnt[x]++;
}

void rem(int x) {
    cnt[x]--;
    if (cnt[x] == 0)    ans--;
}


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

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

    for (int i=1; i<=n; i++)    cin>>a[i];

    vector<int> qq;
    for (int i=1; i<=q; i++) {
        cin>>l[i]>>r[i];
        qq.push_back(i);
        ord[i] = hilbertOrder(l[i], r[i], 20, 0);
    }

    sort(qq.begin(), qq.end(), [](auto a, auto b) {return ord[a] < ord[b];});

    int cl = 1, cr = 0;

    for (int id: qq) {
        while (cr < r[id])  add(a[++cr]);
        while (cl > l[id])  add(a[--cl]);
        while (cr > r[id])  rem(a[cr--]);
        while (cl < l[id])  rem(a[cl++]);

        out[id] = ans;
    }

    for (int i=1; i<=q; i++)    cout<<out[i]<<"\n";
}


Measured memory_bytes: 19532
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<queue>
#include<map>
#include<stack>
#include<string>
#include<algorithm>
#include<cmath>
#define rg register
#define il inline
using namespace std;
typedef long long ll;
ll read(){
    ll ans=0,flag=1;char ch;
    while((ch=getchar())<'0'||ch>'9') if(ch=='-') flag=-1;ans=ch^48;
    while((ch=getchar())>='0'&&ch<='9') ans=(ans<<3)+(ans<<1)+(ch^48);
    return flag*ans;
}
int main(){
    int a,b,c;cin>>a>>b>>c;
    if(c<max(a,b)&&c>min(a,b)) puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,j,k,l,c=0;
    cin>>n>>m;
    int ar[m+10];
    string s[m+10];
    for(i=0; i<m; i++)
    {
        cin>>ar[i]>>s[i];
    }
    int br[n+10]= {0};

    l=0;
    for(i=0; i<m; i++)
    {
        if(s[i]=="WA")
        {
            if(br[ar[i]]>=0)
            {
                br[ar[i]]++;

            }
        }
        else
        {
            if(br[ar[i]]>=0)
            {
                c++;
                l=l+br[ar[i]];
//                cout<<l<<endl;
                br[ar[i]]=-1;
            }
        }
    }
    cout<<c<<" "<<l<<endl;
}


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


void solve(long long A, long long B, long long K){
    if(A-K>=0){
        cout<<A-K<<" "<<B<<endl;
    }
    else{
        ll a=max(0LL,B-K+A);
        cout<<0<<" "<<a<<endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long K;
    scanf("%lld",&K);
    solve(A, B, K);
    return 0;
}


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

#define sz(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;++i)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

////////////////////////

int const N = 3e5 + 41;
ll const INF = 1e18;

int n;
ll ans;
int a[N];
ll dl[N], dr[N];

multiset<int> q;

void solve(){
	cin >> n;
	rep(i, 1, n * 3 + 1) cin >> a[i];

	ll sum = 0;
	rep(i, 1, n+1){
		sum += a[i];
		q.insert(a[i]);
	}
	dl[n] = sum;
	rep(i, n+1, n * 2 + 1){
		sum += a[i];
		q.insert(a[i]);
		sum -= (*(q.begin()));
		q.erase(q.begin());
		dl[i] = sum;
	}

	sum = 0;
	q.clear();
	rep(i, n*2+1, n*3+1){
		sum += a[i];	
		q.insert(a[i]);
	}
	dr[n*2+1] = sum;
	for(int i=n*2;i>=n+1;--i){
		q.insert(a[i]);
		sum += a[i];
		auto it = q.end();
		--it;
		sum -= (*it);
		q.erase(it);
		dr[i] = sum;
	}
	ans = -INF;
	for(int i=n;i<=n*2;++i){
		ans = max(ans, dl[i] - dr[i+1]);
	}
	cout << ans << endl;
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();

	return 0;
}

Measured memory_bytes: 8960
import random

D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]

out = [random.randint(1,26) for i in range(D)]

sat = 0
last = [0] * 26
for d in range(D):
    assert(1 <= out[d] and out[d] <= 26)
    j = out[d] - 1
    last[j] = d + 1
    for i in range(26):
        sat -= (d + 1 - last[i]) * c[i]
    sat += s[d][j]

for i in range(D):
    print(out[i])

Measured memory_bytes: 9880
H,W=map(int,input().split())
ans='Impossible'
j=0

for i in range(H):
  A=[x for x in input()]
  count=A.count('#')
  if i==0 and A[0]=='.':
    break
  try:
    if i>0 and '#' in A[:j]:
      break
    else:
      if i==0:
        if count!=A[:count].count('#'):
        	break
      elif count!=A[j:j+count].count('#'):
        break
  except:
    j+=(count-1)
    pass
  j+=(count-1)
else:
  ans='Possible'
print(ans)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define ip pair<ll,ll>
#define ff first
#define ss second
#define MAX 100005
const ll MOD = 1000000007;

inline ll addmod(ll a, ll b){
	return (a+b)%MOD;
}

inline ll mulmod(ll a, ll b){
	return (a*b)%MOD;
}

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

	ll n,k,x;
	cin>>n>>k;
	vector<ll> ap,an;
	ll cnt = 0;
	for(int i=0;i<n;i++){
		cin>>x;
		if(x<0)
			an.pb(-x);
		else if(x>0)
			ap.pb(x);
		else
			++cnt;
	}

	int n1 = an.size();
	int n2 = ap.size();

	if(n == k){
		if(cnt > 0)
			cout<<"0\n";
		else{
			ll ans = 1;
			int sign = n1%2;
			for(int i=0;i<n1;i++)
				ans = mulmod(ans,an[i]);
			for(int i=0;i<n2;i++)
				ans = mulmod(ans,ap[i]);
			if(sign)
				ans = (MOD-ans)%MOD;
			cout<<ans<<"\n";
		}
		return 0;
	}

	if(cnt > n-k){
		cout<<"0\n";
		return 0;
	}
	else if(cnt == n-k && n1%2 == 1){
		cout<<"0\n";
		return 0;
	}
	
	sort(an.begin(),an.end());
	sort(ap.begin(),ap.end());
	

	if(n2 == 0){
		ll ans = 1;
		if(k&1){
			if(cnt > 0){
				cout<<"0\n";
				return 0;
			}

			for(int i=0;i<k;i++)
				ans = mulmod(ans,an[i]);

			ans = (MOD-ans)%MOD;
			cout<< ans << "\n";
		}
		else{
			for(int i=n1-1;i>=n1-k;i--)
				ans = mulmod(ans,an[i]);
			cout<< ans << "\n";
		}
		return 0;
	}

	
	int l = n1-1, r = n2-1;
	int total = 0;
	while(total < k && l>=0 && r>=0){
		if(an[l] > ap[r])
			--l;
		else
			--r;
		++total;
	}

	while(total<k && l>=0){
		--l;
		++total;
	}

	while(total<k && r>=0){
		--r;
		++total;
	}

	if((n1-l)%2 == 0){
		if(r+1 < n2 && l >= 0){
			if(r >= 0 && l+1 < n1){
				if(an[l]*an[l+1] < ap[r]*ap[r+1]){
					--r;
					++l;
				}
				else{
					--l;
					++r;
				}
			}
			else{
				--l;
				++r;
			}
		}
		else{
			if(r>=0 && l+1<n1){
				++l;
				--r;
			}
		}
	}

	ll prod = 1;
	for(int i=l+1;i<n1;i++)
		prod = mulmod(prod,an[i]);
	for(int i=r+1;i<n2;i++)
		prod = mulmod(prod,ap[i]);
	cout<< prod <<"\n";
}

Measured memory_bytes: 5536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  string S;
  cin >> S;
  set<string> s;
  int n = S.length();
  if (n == 1) {
    cout << "1\n";
    return 0;
  }
  if (n == 2) {
    if (S[0] == S[1]) {
      cout << "1\n";
    } else {
      cout << "2\n";
    }
    return 0;
  }

  int dp[n + 1][2]{};
  dp[0][0] = 1;
  dp[0][1] = 0;
  if (S[0] == S[1]) {
    dp[1][0] = 1;
    dp[1][1] = 1;
  } else {
    dp[1][0] = 2;
    dp[1][1] = 1;
  }

  for (int i = 2; i < n; i++) {
    if(S[i] != S[i - 1]) {
      dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]) + 1; 
      dp[i][1] = max(dp[i - 2][0] + 1, dp[i - 1][1]);
    } else {
      dp[i][0] = dp[i - 1][1] + 1;
      dp[i][1] = max(dp[i - 2][0] + 1, dp[i - 1][1]);
    }
  }
  cout << max(dp[n -1][0], dp[n - 1][1]) << "\n";
  return 0;
}

Measured memory_bytes: 2180
package main
import "fmt"

func main() {
    var result int
    ints := scanNums(2)
    if ints[1] % ints[0] == 0 {
        result = ints[1] + ints[0]
    } else {
        result = ints[1] - ints[0]
    }
    fmt.Println(result)
}

func scanNum() (num int) {
    fmt.Scan(&num)
    return
}

func scanString() (str string) {
    fmt.Scanf("%s", str)
    return
}

func scanNums(len int) (nums []int) {
    var num int
    for i := 0; i < len; i++ {
        fmt.Scan(&num)
        nums = append(nums, num)
    }
    return
}

func scanStrings(len int) (strings []string) {
    var str string
    for i := 0; i < len; i++ {
        fmt.Scanf("%s", str)
        strings = append(strings, str)
    }
    return
}

Measured memory_bytes: 512