akhauriyash/Code-Regression huggingface dataset:
///////////////////////////////////////////////////////////////////////////////

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

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

void intin(int &a)
{
        cin >> a;
}

void intinl1(auto &v, int count)
{
        for (int i = 0; i < count ; ++i) {
                int a;
                cin >> a;
                v.push_back(a);
        }
}

void intinl2(auto &v, int count)
{
        for (int i = 0; i < count ; ++i) {
                int a, b;
                cin >> a >> b;
                v.push_back({a, b});
        }
}

void intinl3(auto &v, int count)
{
        for (int i = 0; i < count ; ++i) {
                int a, b, c;
                cin >> a >> b >> c;
                v.push_back({a, b, c});
        }
}

void intina(auto &v, int count)
{
        intinl1(v, count);
}


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

int main()
{
        int a, b;
        intin(a); intin(b);

        if (a == b) {
                cout << a * 2;
        }
        else {
                int c = max(a, b);
                cout << c * 2 - 1;
        }

        return 0;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll h,w;
  cin >> h >>w;
  char s[h+2][w+2];

  for(ll i=0;i<h+2;i++){
    for(ll j=0;j<w+2;j++){
      if(i==0 || i==h+1 || j==0 || j==w+1)s[i][j]='#';
      else cin >> s[i][j];
    }
  }

  // for(ll i=0;i<h+2;i++){
  //   for(ll j=0;j<w+2;j++)cout << s[i][j] ;
  //   cout << endl;
  // }

  ll m=0;

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

  for(ll i=1;i<h+1;i++){
    for(ll j=1;j<w+1;j++){
      if(s[i][j]=='#')continue;
      ll d[h+2][w+2];
      for(int a=0;a<h+2;a++){
        for(int b=0;b<w+2;b++){
          d[a][b]=-1;
        }
      }
      queue<vector<ll>> que;
      d[i][j]=0;
      que.push({i,j});

      while(!que.empty()){
        vector<ll> v =que.front();
        que.pop();

        for(int c=0;c<4;c++){
          if(d[v[0]+dx[c]][v[1]+dy[c]]== -1 && s[v[0]+dx[c]][v[1]+dy[c]]=='.'){
            d[v[0]+dx[c]][v[1]+dy[c]]=d[v[0]][v[1]]+1;
            que.push({v[0]+dx[c],v[1]+dy[c]});
          }
        }
      }
      ll p=0;
      for(ll a=1;a<h+1;a++){
        for(ll b=1;b<w+1;b++){
          p=max(p,d[a][b]);
        }
      }
      m=max(m,p);
    }
  }

  cout << m << endl;
}

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

long f(long k) {
  return k * (k + 1) / 2;
}

int main() {
  string s;
  cin >> s;
  const int n = s.size() + 1;
  vector<long> lens;
  int current = 1;
  if (s.at(0) == '>') lens.push_back(0);
  for (int i = 0; i < n - 2; i++) {
    if (s.at(i + 1) == s.at(i)) {
      current++;
    } else {
      lens.push_back(current);
      current = 1;
    }
  }
  lens.push_back(current);
  if (s.at(n - 2) == '<') lens.push_back(0);
  long ans = 0;
  for (int i = 0; i < lens.size(); i += 2) {
    ans += f(lens.at(i)) + f(lens.at(i + 1)) - min(lens.at(i), lens.at(i + 1));
  }
  cout << ans << endl;
}


Measured memory_bytes: 3068
#include <cstring>
#include <cstdio>
using namespace std;

const int N = 2e3 + 10;
const int inf = 0x3f3f3f3f;
int n, ans = inf, a[N], b[N], mx[N], pre[N], nxt[N];

inline int max(int a, int b) {return a > b ? a : b;}
inline int min(int a, int b) {return a < b ? a : b;}
inline void swap(int &a, int &b) {int t = a; a = b, b = t;}
inline void red(int *a) {
	n = 0; char ch = getchar();
	for (; ch<'0' || ch>'1';) ch = getchar();
	for (; ch>='0' && ch<='1';) a[n++] = ch-'0', ch = getchar();
}

inline void work() {
	int mn, cnt, tot;
	for (int i = 0; i < n; ++i) {
		pre[i] = nxt[i] = 0;
		for (int p = 0; p < n; ++pre[i], ++p) if (b[(i-p+n)%n]) break;
		for (int p = 0; p < n; ++nxt[i], ++p) if (b[(i+p)%n]) break;
	}
	for (int i = 0; i < n; ++i) {
		tot = 0, memset(mx, 0, sizeof mx);
		for (int p = 0; p < n; ++p) if (a[p] != b[(p+i)%n])
			++tot, mx[pre[p]] = max(mx[pre[p]], nxt[p]);
		mn = inf, cnt = i;
		for (int p = n-1; ~p; --p)
			mn = min(mn, cnt + p), cnt = max(cnt, mx[p]);
		ans = min(ans, 2 * mn - i + tot);
	}
}

int main() {
	int suma = 0, sumb = 0;
	red(a), red(b);
	for (int i = 0; i < n; ++i) suma += a[i], sumb += b[i];
	if (!suma && !sumb) {puts("0"); return 0;}
	if (!sumb) {puts("-1"); return 0;}
	work();
	for (int i = 0; i + i < n; ++i)
		swap(a[i], a[n-i-1]), swap(b[i], b[n-i-1]);
	work(); printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
# input
n = int(input())
A = [[0 for i in range(n)] for j in range(n)]

for i in range(n):
    u, k, *v_list = list(map(int, input().split()))
    for v in v_list:
        A[u-1][v-1] = 1

# init
d = [0] * n
f = [0] * n
t = 0

# recursive
def dfs(u):
    global t
    t += 1
    d[u] = t
    for v in range(n):
        if A[u][v] == 1 and d[v] == 0:
            dfs(v)
    t += 1
    f[u] = t

# dfs
for i in range(n):
    if d[i] == 0:
        dfs(i)

# output
for i in range(n):
    print(i+1, d[i], f[i])


Measured memory_bytes: 5796
import sys
sys.setrecursionlimit(10**7)
mo=10**9+7
n=int(input())
a=[0]*9
for s in map(int,input().split()):
    for i in range(8):
        if int(s)>=i*400 and (i+1)*400>int(s):
            a[i]=1
    if int(s)>=3200:
        #print(int(s),'rain')
        a[8]+=1
    
#print(a)
ans=sum(a[0:8])
#ans=[ans,min(8,a[8]+ans)]
ans=[max(1,ans),a[8]+ans]
print(*ans)


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define MOD 1000000007

using namespace std;

typedef long long ll;

ll X, Y;
ll factmod(ll n, ll p)
{
    ll res = 1;
    while (n > 1)
    {
        res = (res * ((n / p) % 2 ? p - 1 : 1)) % p;
        for (ll i = 2; i <= n % p; ++i)
            res = (res * i) % p;
        n /= p;
    }
    return res % p;
}

ll gcdExtended(ll a, ll b, ll *x, ll *y)
{
    if (a == 0)
    {
        *x = 0, *y = 1;
        return b;
    }

    ll x1, y1;
    ll gcd = gcdExtended(b % a, a, &x1, &y1);

    *x = y1 - (b / a) * x1;
    *y = x1;

    return gcd;
}

ll modInverse(ll b, ll m)
{
    ll x, y;
    ll g = gcdExtended(b, m, &x, &y);

    if (g != 1)
        return -1;

    return (x % m + m) % m;
}

int main()
{
    cin >> X >> Y;
    ll ans = 0;
    for (ll i = 0; i <= X; i++)
    {
        if ((X - i) % 2 != 0)
            continue;
        ll a = i, b = (X - i) / 2;
        // cout << a << " " << b << "\n";
        if (2 * a + b != Y)
            continue;
        // cout << "HERE" << i << "\n";
        ans += (factmod(a + b, MOD) * modInverse((factmod(a, MOD) * factmod(b, MOD)) % MOD, MOD)) % MOD;
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define RREPALL(i,v) for (int i = v.size()-1; i >= 0; i--)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

vector<ll> a;

int main()
{
    int n, mcnt = 0;
    ll ans = 0ll;
    cin>>n;
    REP(i,n) {
        ll ta;
        cin>>ta;
        if (ta < 0) {
            mcnt++;
            ta = -ta;
        }
        a.push_back(ta);
    }
    SORT(a);
    REP(i,n)
        ans += a[i];
    if (mcnt % 2 == 1) {
        ans -= a[0] * 2;
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define dump(x) cout << #x << " = " << (x) << endl

using namespace std;
using ll = long long;
const ll MAX = 2000005;
const ll MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];

void cominit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;

    for (int i=2;i<MAX;++i){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


ll com(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
    int x, y;
    cin >> x >> y;

    if ((x + y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }

    cominit();

    int total = (x + y) / 3;
    int n = y - total;
    int m = x - total;

    if (n < 0 || m < 0) {
        cout << 0 << endl;
        return 0;
    }

    cout << com(total, n) % MOD << endl;
}

Measured memory_bytes: 47104
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    vector<double> p(n);
    vector<double> kitai(n);
    double sum = 0,ans = 0;
    for(ll i = 0; i < n;i++){
        cin >> p[i];
        kitai[i] = (p[i]+1);
        sum += kitai[i];
        if(i >= k-1){
            ans = max((sum)/2,ans);
            sum-=kitai[i-(k-1)];
        }
        
    
    }
    printf("%lf\n",ans);
    

    return 0;
}

Measured memory_bytes: 3456
import java.util.Scanner;

public class Main {
    static Node SENTINEL = new Node(-1, null, null, null);

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        Node[] nodes = new Node[n];
        for (int i = 0; i < n; i++) {
            nodes[i] = new Node(i, SENTINEL, SENTINEL, SENTINEL);
        }

        for (int i = 0; i < n; i++) {
            int id = sc.nextInt();
            int left = sc.nextInt();
            int right = sc.nextInt();

            if (left != -1) {
                nodes[left].parent = nodes[id];
                nodes[id].left = nodes[left];
            }
            if (right != -1) {
                nodes[right].parent = nodes[id];
                nodes[id].right = nodes[right];
            }
        }
        for (int i = 0; i < n; i++) {
            Node nd = nodes[i];
            String kind = 
                    (isEmpty(nd.parent)) ? "root" :
                    (isEmpty(nd.left) && isEmpty(nd.right)) ? "leaf" : "internal node";
                
            System.out.println(
                    "node " + i + ": "
                   +   "parent = "  + nd.parent.val
                   + ", sibling = " + nd.getSibling().val 
                   + ", degree = "  + nd.getDigree()
                   + ", depth = "   + nd.getDepth()
                   + ", height = "  + nd.getHeight()
                   + ", " + kind);
        }
    }

    public static class Node {
        int  val;
        Node parent;
        Node left;
        Node right;

        public Node(int val, Node parent, Node left, Node right) {
            this.val = val;
            this.parent = parent;
            this.left = left;
            this.right = right;
        }

        public Node getSibling() {
            Node p = this.parent;
            if (p.val == -1)
                return SENTINEL;
            else if (p.left != null && p.left.val != this.val)
                return p.left;
            else if (p.right != null && p.right.val != this.val)
                return p.right;
            else
                return SENTINEL;
        }
        
        public int getDigree() {
            int count = 0;
            if (!isEmpty(this.left)) count++;
            if (!isEmpty(this.right)) count++;
            return count;
        }
        
        public int getDepth() {
            int depth = 0;
            Node p = this.parent;
            while (p.val != -1) {
                depth++;
                p = p.parent;
            }
            return depth;
        }
        
        public int getHeight() {
            int heightL = -1;
            int heightR = -1;
            if (!isEmpty(this.left)) {
                heightL = this.left.getHeight();
            }
            if (!isEmpty(this.right)) {
                heightR = this.right.getHeight();
            }
            
            return Math.max(heightL, heightR) + 1;
        }
    }
    static boolean isEmpty(Node n) {
        return n == null || n.val == -1;
    }
}


Measured memory_bytes: 26320
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let it = stdin.lock().bytes().map(|c| c.unwrap() as char);
    let (fs, ft) = (|c: &char| c.is_whitespace(), |c: &char| !c.is_whitespace());
    let token = it.skip_while(fs).take_while(ft).collect::<String>();
    token.parse().ok().unwrap()
}
#[allow(dead_code)]
fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    f(std::io::BufWriter::new(out.lock()));
}
#[allow(unused_macros)]
macro_rules! debug {
    ($($var:expr),*) => { #[cfg(debug_assertions)] {
        $({ match &$var { v => eprint!("{}={:?} ", stringify!($var), v) } })*
        eprintln!();
    }};
}

fn main() {
    let n: usize = input();
    let a: Vec<Vec<usize>> = (0..n)
        .map(|_| (0..n - 1).map(|_| input::<usize>() - 1).collect())
        .collect();

    let mut matchid = vec![vec![0; n]; n];
    let mut v = 0;
    for i in 0..n {
        for j in i + 1..n {
            matchid[i][j] = v;
            v += 1;
        }
    }
    let to_matchid = |i: usize, j: usize| {
        let (mut i, mut j) = (i, j);
        if i > j {
            std::mem::swap(&mut i, &mut j);
        }
        matchid[i][j]
    };

    let mut g = vec![vec![]; v];
    for i in 0..n {
        for j in 0..n - 2 {
            let u = to_matchid(i, a[i][j]);
            let v = to_matchid(i, a[i][j + 1]);
            g[u].push(v);
        }
    }

    let mut dist = vec![-1; v];
    let mut vis = vec![false; v];
    let mut ok = true;
    let mut ans = 0;
    for i in 0..v {
        let res = dfs(i, &g, &mut dist, &mut vis);
        if res < 0 {
            ok = false;
            break;
        }
        ans = std::cmp::max(ans, res + 1);
    }

    if !ok {
        println!("-1");
    } else {
        println!("{}", ans);
    }
}

fn dfs(i: usize, g: &Vec<Vec<usize>>, dist: &mut Vec<i32>, vis: &mut Vec<bool>) -> i32 {
    if vis[i] {
        -1
    } else if dist[i] >= 0 {
        dist[i]
    } else {
        dist[i] = 0;
        vis[i] = true;
        for &j in &g[i] {
            let res = dfs(j, g, dist, vis);
            if res < 0 {
                return -1;
            }
            dist[i] = std::cmp::max(dist[i], res + 1)
        }
        vis[i] = false;
        dist[i]
    }
}


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

#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll mod = 1e9+7;
ll INF = 1e17;

int main()
{
    int n,m;
    cin>>n>>m;

    if(m==n)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 256
def main():
    N=int(input())
    for k in range(1000):
        if k*(k-1)//2==N:
            print("Yes")
            print(k)
            break
        if k*(k-1)//2>N:
            print("No")
            return
    S=[[0]*(k-1) for _ in range(k)]
    a=1
    for i in range(k-1):
        for j in range(k-i-1):
            S[j][i]=a
            S[k-i-1][i+j]=a
            a+=1
    for s in S:
        print(len(s), *s)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9296
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass
{
    static void Main()
    {
        int N = int.Parse(ReadLine());
        var d = new List<int>();
        int n = 0;
        if (N == 0)
        {
            WriteLine(0);return;
        }
        while (N != 0)
        {
            if (N % Pow(2, n + 1) != 0)
            {
                N -= (int)Pow(-2, n);
                d.Add(1);
            }
            else d.Add(0);
            n++;
        }
        d.Reverse();
        WriteLine(string.Join("",d));
    }
}


Measured memory_bytes: 28244
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#define N 110000
using namespace std;
int a[N],n,ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	int i=1;
	while(i<=n)
	{
		ans++;int st=i;
		while(i<=n && a[i]==a[st]) i++;
		if(i>n) break;
		i--;
		int o;
		if(a[i]<a[i+1]) o=1;
		else o=2;
		while(i<n)
		{
			if(o==1)
			{
				if(a[i]<=a[i+1]) i++;
				else break;
			}
			else 
			{
				if(a[i]>=a[i+1]) i++;
				else break;
			}
		}
		i++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main()
{
	int a[5];
	int i,flag1,flag2,flag3,flag4;
	flag1=flag2=flag3=flag4=0;
   
	for(i=0;i<4;i++)
	scanf("%d",&a[i]);
		for(i=0;i<4;i++)
		{
			if(a[i]==1)
			{
			 flag1=1;
	        }
	        	if(a[i]==9)
			{
			 flag2=1;
	        }
	        	if(a[i]==7)
			{
			 flag3=1;
	        }
	        	if(a[i]==4)
			{
			 flag4=1;
	        }
		}
		if(flag1&&flag2&&flag3&&flag4) printf("YES\n");
		else printf("NO\n");

}

Measured memory_bytes: 128
n, m = gets.chomp.split(" ").map(&:to_i)
a = {}
1.upto(m) do |i|
  idx = gets.chomp.to_i
  a[idx] = true
end

cnt = {}
cnt[-1] = 0
cnt[0] = 1
1.upto(n) do |i|
  if a[i]
    cnt[i] = 0
  else
    cnt[i] = cnt[i - 1] + cnt[i - 2]
    if cnt[i].zero?
      puts 0
      exit
    end
  end
end
puts cnt[n] % 1_000_000_007


Measured memory_bytes: 438652
#include <iostream>
using namespace std;
int n, m, k;
int main() {
	cin >> n >> m >> k;
	for (int i = 0; i <= n; i ++) {
		for (int j = 0; j <= m; j ++) {
			if (i * m + j * n - i * j * 2 == k) {
				cout << "Yes";
				return 0;
			}
		}
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>

using namespace std;

int main()
{
  vector<int> tasks(3);
  cin >> tasks[0] >> tasks[1] >> tasks[2];
  sort(tasks.begin(), tasks.end());
  cout << (tasks[2] - tasks[0]) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define mod 1000000007
using namespace std;
int main() {
	int n;
	int a[100500];
	scanf("%d",&n);
	for(int i=1; i<=n; i++) {
		scanf("%d",&a[i]);
	}
	int cnt=1;
	bool b[100500]= {0};
	for(int i=1; i<=n;) {
		if(a[i]!=2) {
			if(b[i]==1) {
				printf("-1");
				break;
			} else {
				cnt++;
				b[i]=1;
				i=a[i];
			}
		}else{
			printf("%d",cnt);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

void solve(int n,int d){
    vector<int> a[n];
    vector<int> sum(n);
    int cnt=0;
    rep(i,n){
        int m;cin>>m;
        cnt+=m;
        rep(j,m){
            int x;
            cin>>x;
            sum[i]+=x;
            a[i].push_back(x);
        }
    }
    vector<int> lmi(n+1,inf),rmi(n+1,inf),lma(n+1,0),rma(n+1,0);
    rep(i,n){
        lma[i+1]=max(lma[i],sum[i]);
    }
    for(int i=n-1;i>=0;i--){
        rma[i]=max(rma[i+1],sum[i]);
    }
    while(cnt--){
        bool ok=false;
        rep(i,n){
            if(a[i].empty())continue;
            int nxt=sum[i]-a[i].back();
            int ma = max(lma[i],rma[i+1]);
            if(nxt+d>=ma){
                sum[i]=nxt;
                a[i].pop_back();
                ok=true;
                break;
            }
        }
        if(!ok){
            cout<<"No"<<endl;
            return;
        }
        rep(i,n){
            lma[i+1]=max(lma[i],sum[i]);
        }
        for(int i=n-1;i>=0;i--){
            rma[i]=max(rma[i+1],sum[i]);
        }
    }
    cout<<"Yes"<<endl;
}

int main(){
    int n,d;
    while(cin>>n>>d,n)solve(n,d);
    return 0;
}


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

typedef struct{
  int id;
  int idx;
  int num;
} Data;

int r, c;
bool isSumi(int d, char b){
  if(b == 'x'){
    if(d == 0 || d == r){
      return true;
    }
  }else{
    if(d == 0 || d == c){
      return true;
    }
  }
  return false;
}

bool ask(const Data& l, const Data& r){
  return l.idx == r.idx ? l.num < r.num : l.idx < r.idx;
}



int main(){
  int n, m;
  cin >> r >> c >> n;
  Data data[200010];
  int x1,x2,y1,y2;
  m = 0;
  int l = 0;
  for(int i = 0;i < n;i++){
    cin >> x1 >> y1 >> x2 >> y2;
    if((isSumi(x1,'x') || isSumi(y1,'y')) && (isSumi(x2,'x') || isSumi(y2,'y'))){

      data[m].id = l;
      if(x1 == 0){
        data[m].idx = 1;
        data[m].num = y1;
      }else if(y1 == c){
        data[m].idx = 2;
        data[m].num = x1;
      }else if(x1 == r){
        data[m].idx = 3;
        data[m].num = r-y1;
      }else if(y1 == 0){
        data[m].idx = 4;
        data[m].num = c-x1;
      }
      m++;
      data[m].id = l;
      if(x2 == 0){
        data[m].idx = 1;
        data[m].num = y2;
      }else if(y2 == c){
        data[m].idx = 2;
        data[m].num = x2;
      }else if(x2 == r){
        data[m].idx = 3;
        data[m].num = r-y2;
      }else if(y2 == 0){
        data[m].idx = 4;
        data[m].num = c-x2;
      }
      m++;
      l++;
    }
  }

  sort(data,data+m,ask);

  bool isfin[100010] = {};
  stack<int> st;
  for(int i = 0;i < m;i++){
    if(isfin[data[i].id]){
      int j = st.top();
      st.pop();
      if(j != data[i].id){
        cout << "NO" << endl;
        return 0;
      }
    }else{
      st.push(data[i].id);
      isfin[data[i].id] = true;
    }
  }

  cout << "YES" << endl;
  return 0;
}



Measured memory_bytes: 2944
#include<cstdio>

int main(){
int a,b;
while(true){
scanf("%d %d",&a,&b);
if((a==0)&&(b==0))break;
if(a<=b) printf("%d %d\n",a,b);
if(a>b) printf("%d %d\n",b,a);
}
return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define __TRUE "Yes"
#define __FALSE "No"

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if(a<=c && c<=b) cout << __TRUE << endl;
  else cout << __FALSE << endl;
}

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

typedef long long ll;

const int N = 104206969;

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

int main () {
	ios_base::sync_with_stdio(false); cin.tie(0);
	// cout.precision(6);
	
	ll k; cin >> k;
	ll ans = 0;
	for (ll i = 1; i <= k; ++i) {
		for (ll j = 1; j <= k; ++j) {
			for (ll kk = 1; kk <= k; ++kk) {
				ans += gcd(i,gcd(j,kk));
			}
		}
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 3188
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<iostream>
#include<cmath>
#include<algorithm>
#define debug(x) cout<<"***"<<x<<"***"<<endl;
using namespace std;//3 GGGBBBRRR
int main()//R  B  G  RG  RB  GB 216
{
	long long n,ans=1,len;
	long long a[7]={0};
	string str;
	cin>>n>>str;
	a[0]=n;
	len=str.size();
	for(int i=0;i<len;i++){
		if(str[i]=='R')
		{
			if(a[6]) {ans=ans*a[6]%998244353;a[6]--;}
			else if(a[2]) {ans=ans*a[2]%998244353;a[2]--;a[5]++;} 
			else if(a[3]) {ans=ans*a[3]%998244353;a[3]--;a[4]++;}
			else {ans = ans*a[0]%998244353;a[0]--;a[1]++;} 
		}
		else if(str[i]=='B')
		{
			if(a[4]) {ans=ans*a[4]%998244353;a[4]--;}
			else if(a[1]) {ans=ans*a[1]%998244353;a[1]--;a[5]++;}
			else if(a[3]) {ans=ans*a[3]%998244353;a[3]--;a[6]++;}
			else {ans=ans*a[0]%998244353;a[0]--;a[2]++;}
		}
		else
		{
			if(a[5]) {ans=ans*a[5]%998244353;a[5]--;}
			else if(a[2]) {ans=ans*a[2]%998244353;a[2]--;a[6]++;}
			else if(a[1]) {ans=ans*a[1]%998244353;a[1]--;a[4]++;}
			else {ans=ans*a[0]%998244353;a[0]--;a[3]++;}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
const ll mod=1e9+7;
string s;ll dp[N],g[N],p[N];
int n;ll ans=3;
int main(){
    ios::sync_with_stdio(false);
    g[0]=1;for(int i=1;i<=100000;i++)g[i]=g[i-1]*3%mod;
    cin>>s;
    n = s.length();
    reverse(s.begin(),s.end());
    for(int i=0;i<n;i++){
        if(s[i]=='1'){
            if(i==0)p[i]=3;
            else p[i]=(p[i-1]*2+g[i])%mod;
        }else{
            if(i==0)p[i]=1;
            else p[i]=p[i-1];
        }
    }
    cout<<p[n-1];
//    dp[0]=3;
//    for(int i=1;i<n;i++){
//        if(i==n-1){
//            ans+=p[i]-g[i];
//            break;
//        }else {
//            dp[i] = 2ll * g[i] % mod;
//            ans += dp[i];
//        }
//        dp[i]%=mod;
//        ans%=mod;
//    }
//    cout<<ans%mod<<endl;
}


Measured memory_bytes: 2000
import java.util.Scanner;


public class Main {
	
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();

        String[] split = line.split(" ");
        
        int x = Integer.parseInt(split[0]);
        int a = Integer.parseInt(split[1]);
        int b = Integer.parseInt(split[2]);
        
        if (a >= b) {
        	System.out.println("delicious");
        } else if (x >= (b-a)) {
        	System.out.println("safe");
        } else {
        	System.out.println("dangerous");
        }
        
        
	}
	

	

}


Measured memory_bytes: 23636
N,W = map(int,input().split())
L=[]
for _ in range(N):
    w,v=map(int,input().split())
    L.append([w,v])

DP=[[0]*(W+1) for _ in range(N+1)]
for j in range(1,N+1):
    if L[j-1][0]<=W:
        for k in range(L[j-1][0],W+1):
            DP[j][k]=max(DP[j-1][k],DP[j-1][k-L[j-1][0]]+L[j-1][1])
        for l in range(L[j-1][0]):
            DP[j][l]=DP[j-1][l]
    else:
        for m in range(0,W+1):
            DP[j][m]=DP[j-1][m]
            
print(DP[N][W])

Measured memory_bytes: 149324
from functools import lru_cache

@lru_cache(None)
def solve(n,k) :
  if n<=9:
    if k==0: return 1
    if k==1: return n
    return 0
  if k==0: return 1
  m, r = divmod(n, 10)
  return r*solve(m, k-1)+(9-r)*solve(m-1, k-1)+solve(m, k)

N = int(input())
K = int(input())
print(solve(N, K))

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

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

Measured memory_bytes: 256
import sys


def resolve():
    readline = sys.stdin.readline

    A, B, C = map(int, readline().split())
    K = int(readline())

    for i in range(K + 1):
        len_j = K - i
        if len_j > 0:
            for j in range(len_j + 1):
                len_k = len_j - j
                if len_k > 0:
                    for k in range(len_k + 1):
                        a = A * 2 ** i
                        b = B * 2 ** j
                        c = C * 2 ** k
                        if a < b < c:
                            print('Yes')
                            exit()
    print('No')


resolve()


Measured memory_bytes: 9196
import java.util.*;

public class Main {

    static final int MOD = 1000000007;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if(n==1) System.out.println("Hello World");
        else {
            int a = sc.nextInt(),b=sc.nextInt();
            System.out.println(a+b);
        }

    }
}


Measured memory_bytes: 21844
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	//input = input.split("\n");
	tmp = input.split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var a = parseInt(tmp[0], 10);
	var b = parseInt(tmp[1], 10);
	var output_string="";
	output_string= a * b % 2 == 0 ? "Even" : "Odd" ;
	//出力
	console.log(output_string);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>

#define INF 1e18
#define MOD 1000000007

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

int main() {
    ios_base::sync_with_stdio(false);

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    bool turn = true;
    while(a > 0 && c > 0) {
        if(turn) c -= b;
        else a -= d;
        turn = !turn;
    }
    if(a <= 0) cout << "No\n";
    else cout << "Yes\n";
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define int long long
const int inf=1145141919ll;
const int mod=1000000007ll;
const int dd[]={0,-1,0,1,0};
using namespace std;
int a,b,c,d;
int count(string s,char c){
	string t;
	bool f=true,g=false;
	for(auto x:s){
		if(x!=c){
			f=false;
			break;
		}
	}
	if(f)
		return 0;
	for(auto x:s)
		if(x==c){
			g=true;
			break;
		}
	if(!g)
		return inf;
	for(int i=0;i<s.size()-1;i++)
		if(s[i+1]==c)
			t.push_back(s[i+1]);
		else
			t.push_back(s[i]);
	return count(t,c)+1;
}
signed main(){
	int i,j;
	string s;
	cin>>s;
	int ans=inf;
	for(char c='a';c<='z';c++)
		ans=min(count(s,c),ans);
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#!/usr/bin/ruby
#
# 2353.rb: Four Arithmetic Operations
#

### main

n = gets.to_i
x = Rational(0)

n.times do
  op, y = gets.split.map(&:to_i)

  case op
  when 1
    x += y
  when 2
    x -= y
  when 3
    x *= y
  when 4
    x /= y
  end
end

puts x.numerator

Measured memory_bytes: 155508
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;
    if(a < b)
        cout << b * 2 - 1;
    else if(a > b)
        cout << a * 2 - 1;
    else
        cout << a + b;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define INF (INT_MAX / 4)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
// #define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  int h, w, ans = 0;
  cin >> h >> w;
  bool maze[w][h];
  REP(y, h) {
    REP(x, w) {
      char c;
      cin >> c;
      if (c == '.')
        maze[x][y] = true;
      else
        maze[x][y] = false;
    }
  }

  REP(sy, h) {
    REP(sx, w) {
      REP(gy, h) {
        REP(gx, w) {
          if (!maze[sx][sy] || !maze[gx][gy]) continue;
          vector<vector<int>> cnt(w, vector<int>(h, -1));
          queue<pair<int, int>> bfs;
          while(!bfs.empty()) bfs.pop();
          bfs.push(make_pair(sx, sy));
          cnt[sx][sy] = 0;

          while (!bfs.empty()) {
            int nowx, nowy;
            tie(nowx, nowy) = bfs.front();
            if (nowx == gx && nowy == gy) {
              ans = max(cnt[nowx][nowy], ans);
              break;
            }

            if (nowx + 1 < w) {
              if (maze[nowx + 1][nowy] && cnt[nowx + 1][nowy] == -1) {
                cnt[nowx + 1][nowy] = cnt[nowx][nowy] + 1;
                bfs.push(make_pair(nowx + 1, nowy));
              }
            }
            if (0 <= nowx - 1) {
              if (maze[nowx - 1][nowy] && cnt[nowx - 1][nowy] == -1) {
                cnt[nowx - 1][nowy] = cnt[nowx][nowy] + 1;
                bfs.push(make_pair(nowx - 1, nowy));
              }
            }
            if (nowy + 1 < h) {
              if (maze[nowx][nowy + 1] && cnt[nowx][nowy + 1] == -1) {
                cnt[nowx][nowy + 1] = cnt[nowx][nowy] + 1;
                bfs.push(make_pair(nowx, nowy + 1));
              }
            }
            if (0 <= nowy - 1) {
              if (maze[nowx][nowy - 1] && cnt[nowx][nowy - 1] == -1) {
                cnt[nowx][nowy - 1] = cnt[nowx][nowy] + 1;
                bfs.push(make_pair(nowx, nowy - 1));
              }
            }
            bfs.pop();
          }
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())

a = sorted(list(map(int, input().split())))

change = []
for i in range(m):
	b, c = map(int, input().split())
	change.append([b,c])

change = sorted(change, key=lambda x: x[1], reverse=True)

cur = 0
done = False
for vals in change:
	b, c = vals
	for i in range(b):
		if a[cur] < c:
			a[cur] = c
		else:
			done = True
			break
		cur = (cur+1)%len(a)
	if done:
		break

print(sum(a))

Measured memory_bytes: 26280
# coding: utf-8
import math
class Point():
    def __init__(self, x, y):
        self.x = x
        self.y = y
        # self.z = 0
        self.length = math.sqrt(x**2 + y**2)

init_point = map(float,raw_input().split())
p0 = Point(init_point[0], init_point[1])
p1 = Point(init_point[2], init_point[3])

q = int(raw_input())
for i in range(q):
    xp2,yp2 = map(float,raw_input().split())
    p2 = Point(xp2,yp2)
    p0p2 = Point(p2.x - p0.x, p2.y - p0.y)
    p0p1 = Point(p1.x - p0.x, p1.y - p0.y)
    p1p2 = Point(p2.x - p1.x, p2.y - p1.y)
    # ?????????????????????(3)(4)(5)
    if p0p1.x * p0p2.y - p0p1.y * p0p2.x == 0:
        if max(p0p1.length, p0p2.length) < p1p2.length: 
            print "ONLINE_BACK"
        elif p0p1.length < p0p2.length:
            print "ONLINE_FRONT"
        elif p0p1.length >= p0p2.length:
            print "ON_SEGMENT"
    else:
        # ?????????z????????????
        z = p0p1.x * p0p2.y - p0p1.y * p0p2.x
        if z > 0:
            print "COUNTER_CLOCKWISE"
        else:
            print "CLOCKWISE"

Measured memory_bytes: 4456
#include <algorithm>
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

int main()
{
	int n = 0;
	std::cin >> n;
		
	int maxCount = 0;
	std::unordered_multiset<std::string> voteStr;
	std::unordered_set<std::string> maxStrings;
	std::unordered_map<std::string, int> voteStrMap;

	for (int index = 0; index < n; ++index)
	{
		std::string curVoteStr;
		std::cin >> curVoteStr;

		voteStr.emplace(curVoteStr);

		const auto itr = voteStrMap.find(curVoteStr);

		int curStrCount = 0;

		if (itr == voteStrMap.end())
		{
			// 初出の文字
			voteStrMap.emplace(std::make_pair(curVoteStr, 1));
			curStrCount = 1;
		}
		else
		{
			++itr->second;
			curStrCount = itr->second;
		}


		if (curStrCount == maxCount)
		{
			//最大値に到達したらただ登録するだけ
			maxStrings.emplace(curVoteStr);
		}
		else if (curStrCount > maxCount)
		{
			// 超えたら更新する
			maxCount = curStrCount;
			maxStrings.clear();
			maxStrings.emplace(curVoteStr);
		}
	}

	std::vector<std::string> maxStrVec;
	maxStrVec.reserve(maxStrings.size());

	for (const std::string& str : maxStrings)
	{
		maxStrVec.emplace_back(str);
	}

	std::sort(maxStrVec.begin(), maxStrVec.end());

	for (const std::string& str : maxStrVec)
	{
		std::cout << str << std::endl;
	}
}



Measured memory_bytes: 42200
#pragma warning( disable : 6031)
 
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <math.h>
int minimum(int a, int b) { return a < b ? a : b; }
int maximum(int a, int b) { return a > b ? a : b; }
//const long long mod = 1000000007;
const long long mod = 998244353;
using std::vector;
using std::pair;
using std::string;
using std::map;
int main() {
	int N;
	scanf("%d", &N);
	long long res = 0;
	for (int i = 0; i < N; i++) {
		if ((i + 1) % 3 && (i + 1) % 5) {
			res += i + 1;
		}
	}
	printf("%lld", res);
	return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep2(i, m, n) for(int i=(int)m; i<(int)n; i++)
#define ALL(vec) vec.begin(), vec.end()
typedef long long ll;
typedef long double ld;

int main(){
    string N;
    cin >> N;
    ll n = N.size();
    ll inc = 0;
    vector<ll> f(n+1), g(n+1);
    f[0] = 0;
    g[0] = 1;
    rep(i, n){
        int a = N[i] - '0';
        f[i+1] = min(f[i] + a, g[i] + 10 - a);
        g[i+1] = min(f[i] + a + 1, g[i] + 9 - a);
    }
    cout << f[n] << endl;
}

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

#define LL long long
#define DD long double

#define M 1000000007
#define INF 1e18

void setIO(string s = "") { 
  cin.sync_with_stdio(0); 
  cin.tie(0);
  cout.tie(0);
  if (s.size()) s += ".in", freopen(s.c_str(), "r", stdin);
}

int tt = 1;
void solve() {
  int n;
  cin >> n;
  vector<int> f (100050);
  
  for (LL i = 1; i <= 105; i++) {
    for (LL j = 1; j <= 105; j++) {
      for (LL k = 1; k <= 105; k++) {
        LL ff = i*i + j*j + k*k + i*j + j*k + i*k;
        if (ff <= n) f[ff]++;
      }
    }
  }

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

}

int main() {
  setIO();
  while (tt--) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 3636
#include<iostream>
 
int main(){
    int W,H,x,y,r;
    int flag=1;
    std::cin>>W>>H>>x>>y>>r;

    if(x-r<0||y-r<0){
	flag=0;
    }
    
    if(x+r>W||y+r>H){
	flag=0;
    }

    if(flag==1){
    std::cout << "Yes" << std::endl;
    }else{
    std::cout << "No" << std::endl;
    }
    return 0;
    }

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> g[100000];
int dist[2][100000],id;
void dfs(int idx,int par=-1){
	if(~par) dist[id][idx]=dist[id][par]+1;
	for(auto &to : g[idx]) if(to!=par) dfs(to,idx);
}
int main(){
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		--a,--b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	id=0;
	dfs(0);
	id=1;
	dfs(n-1);
	int ret=0;
	for(int i=0;i<n;i++){
		if(dist[0][i]<=dist[1][i]) ++ret;
	}
	if(ret>=(n+2)/2) cout<<"Fennec\n";
	else cout<<"Snuke\n";
	return 0;
} 

Measured memory_bytes: 11136
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/
auto cmx = [](auto& x, auto y){ if (x<y) { x=y; return true; } return false; };
int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    usize n;
    std::cin >> n;
    vec<u32> a(n);
    vec<vec<i32>> b(n, vec<i32>(11));
    for (usize i=0; i<n; i++) for (usize j=0; j<10; j++) {
        u32 x;
        std::cin >> x;
        if (x) a.at(i) |= u32{1} << j;
    }
    for (usize i=0; i<n; i++) for (usize j=0; j<=10; j++) {
        std::cin >> b.at(i).at(j);
    }

    i32 ans = numr<i32>::min();
    for (u32 bs=1; bs<(u32)1<<10; bs++) {
        i32 now = 0;
        for (usize i=0; i<n; i++) {
            now += b.at(i).at(__builtin_popcount(a.at(i) & bs));
        }
        cmx(ans, now);
    }
    std::cout << ans << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

class Weighted_UnionFind {
  public:
    // 親の番号を格納する。親の場合 -1 になる
    vector<int> Parent;
    vector<long long> Weight;

    // 宣言されたとき Parent の値はすべて -1 にする
    Weighted_UnionFind(int N) {
        Parent = vector<int>(N, -1);
        Weight.resize(N);
    }

    // 与えられた値 x がどの親であるか調べる
    int root(int x) {
        if (Parent[x] < 0)
            return x;
        int par = root(Parent[x]);
        Weight[x] += Weight[Parent[x]];
        return Parent[x] = par;
    }

    // 木の全体の数を返す
    int size(int x) { return -Parent[root(x)]; }

    // 引数と親の重さを返す
    long long weight_to_parent(int x) {
        root(x);
        return Weight[x];
    }

    // 2つの引数を同じ親にする
    bool update(int x, int y, long long w) {
        w += weight_to_parent(x);
        w -= weight_to_parent(y);
        x = root(x);
        y = root(y);
        if (x == y)
            return false;
        if (size(x) < size(y)) {
            swap(x, y);
            w *= -1;
        }
        Parent[x] += Parent[y];
        Parent[y] = x;
        Weight[y] = w;
        return true;
    }

    // 引数の親が同じか判定する
    bool is_same(int x, int y) { return root(x) == root(y); }

    // 引数の差を求める。存在しないしない場合、0 を返す
    long long diff(int x, int y) {
        if (!is_same(x, y))
            return 0;
        return Weight[y] - Weight[x];
    }
};

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

    int N, M;
    cin >> N >> M;
    auto uni = Weighted_UnionFind(N);
    REP(i, M) {
        int l, r, d;
        cin >> l >> r >> d;
        l--;
        r--;
        if (uni.is_same(l, r)) {
            int diff = uni.diff(l, r);
            if (diff != d) {
                std::cout << "No" << '\n';
                return 0;
            }
        } else {
            uni.update(l, r, d);
        }
    }
    std::cout << "Yes" << '\n';

    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define SZ(c) int(c.size())
#define pb push_back
#define loop(i,start,n)  for(int i=start;i<n;i++)
#define rloop(i,start,n)  for(int i=start;i>n;i--)

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;
const ll inf = 2e9+3;

void solve(){
    int tc=1 ;
    //cin >> tc;
    while(tc--) {
        ll n,k,res=0;
        cin >> n >> k;
        vll v(n);
        loop(i,0,n) cin >> v[i];
        sort(v.begin(),v.end());
        loop(i,0,k) res+=v[i];
        cout << res << endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

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

inline int num (const std::string& S, int idx){ return S.at(idx) - '0'; }
inline unsigned int bitMask(int i){ return (1 << i); }
inline bool isTrue(unsigned int bit, int i){ return bit & bitMask(i); }

int main(){
	string S;
	cin >> S;
	for(std::size_t i=0; i<S.length(); ++i){
		cout << "x";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long int n , k , a[500] , b[500] , suma = 0 , sumb = 0 , w;

int main() {
	long long int cnt = 0;
	cin >> n >> k;
	for(long long int i = 0; i < n; i++){
		cin >> a[i];
		suma += a[i];
	}
	long long int i2;
	long long int s = sqrt(suma);
	for(long long int i = 1; i <= s; i++){
		sumb = 0;
		if((suma % i) == 0){
			i2 = suma / i;
			for(long long int j = 0; j < n; j++){
				b[j] = a[j] % i2;
				sumb += b[j];
			}
			sort(b , b + n);
			w = sumb / i2;
			cnt = 0;
			for(long long int q = 0; q < w; q++){
				cnt += (i2 - b[n - q - 1]);
			}
			if(cnt <= k){
				cout << i2 << endl;
				return 0;
			}
		}
	}
	for(long long int i = s; i > 0; i--){
		sumb = 0;
		if((suma % i) == 0){
			for(long long int j = 0; j < n; j++){
				b[j] = a[j] % i;
				sumb += b[j];
			}
			sort(b , b + n);
			w = sumb / i;
			cnt = 0;
			for(long long int q = 0; q < w; q++){
				cnt += (i - b[n - q - 1]);
			}
			if(cnt <= k){
				cout << i << endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    A = [a - i for i, a in enumerate(A, 1)]
    A.sort()

    b = A[N // 2]
    ans = sum(abs(a - b) for a in A)

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 31068
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int i,n,flag=1,t,x,y,nx=0,ny=0,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d%d%d",&t,&x,&y);
		j+=abs(x-nx)+abs(ny-y);
		if((t-j)%2==1||j>t)
		{
			flag=0;
			break;
		}
		nx=x;
		ny=y;
	}
	if(flag)
		printf("Yes");
	else
		printf("No");
	return 0;
} 

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

using namespace std;

bool pali(string s) {
  int i = 0;
  int j = (int)s.size() - 1;
  while (i <= j) {
    if (s[i] != s[j]) return false;
    i++;
    j--;
  }
  return true;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = (int)s.size();
  if (n % 2 == 0) {
    cout << "No\n";
    return 0;
  }
  int mid = n / 2;
  string foo = "";
  for (int i = 0; i < mid; i++) {
    foo += s[i];
  }
  string bar = "";
  for (int i = mid + 1; i < n; i++) {
    bar += s[i];
  }
  if (pali(foo) && pali(bar) && pali(s)) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
  return 0;
}

Measured memory_bytes: 256
N=int(input())
a=input().split()
a=[int(b) for b in a]
numbers=[]
number=0
for a_ in a:
    number+=a_
    numbers.append(number)
del numbers[-1]
if N==2:
    print(abs(a[0]-a[1]))
else:
    whole=sum(a)
    answers=[]
    for number in numbers:
        answer=abs(number*2-whole)
        answers.append(answer)
    print(min(answers))
    

Measured memory_bytes: 114904
#include <stdio.h>
#include <string.h>

int main(void){
	int n, i, j, out, flag[3], point;
	char str[9];
	scanf("%d",&n);
	for(i = 0;i < n;i++){
		out = 0;
		point = 0;
		for(j = 0;j < 3;j++)
			flag[j] = 0;
		while(out < 3){
			gets(str);
			if(strncmp(str,"HOMERUN",5) == 0){
				for(j = 0;flag[j] == 1;j++)
					flag[j] = 0;
				point = j + 1 + point;
			}
			if(strncmp(str,"OUT",3) == 0)
				out++;
			if(strncmp(str,"HIT",3) == 0){
				if(flag[2] == 1)
					point++;
				if(flag[1] == 1)
					flag[2] = 1;
				if(flag[0] == 1)
					flag[1] = 1;
				if(flag[0] == 0)
					flag[0] = 1;
			}
		}
		printf("%d\n",point);
	}
	return 0;
}

Measured memory_bytes: 596