akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, L):
    t = [L + i-1 for i in range(1, N+1)]
    b = sys.maxsize
    for c in t:
        if abs(c) < abs(b):
            b = c
    return sum(t) - b


def main():
    N, L = read_int_n()
    print(slv(N, L))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7748
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    N, M, X = lr()
    C = []
    A = []
    for i in range(N):
        CA = lr()
        C.append(CA[0])
        A.append(CA[1:])
    ans = float('inf')
    for i in range((1<<N)+1):
        rikai = [0]*M
        d = [0]*M
        tmp = 0
        for j in range(N):
            if (i>>j)&1:
                tmp += C[j]
                for k in range(M):
                    if d[k] == 1:
                        continue
                    rikai[k] += A[j][k]
                    if rikai[k] >= X:
                        d[k] = 1
        if d == [1]*M:
            ans = min(ans, tmp)
    if ans == float('inf'):
        print(-1)
    else:
        print(ans)
resolve()

Measured memory_bytes: 68528
// C - Exception Handling
#include <stdio.h>
#include <stdlib.h>

int compare(const void* a, const void* b){
    return *(int *)a - *(int *)b;
}

int main(void){
    int n;
    int a[200001], b[200001];
    scanf("%d", &n);
    for(int i=0; i<n; i++){ scanf("%d", &a[i]); b[i] = a[i]; }
    qsort(b, n, sizeof(int), compare);
    int ans = b[n - 1], flag = 0;
    for(int i=0; i<n; i++){
        if(a[i] == ans) flag++;
    }
    for (int i = 0; i < n; i++){
        if (a[i]==ans && flag==1){
            printf("%d\n", b[n - 2]);
        }else{
            printf("%d\n", ans);
        }
        
    }
    return 0;
}

Measured memory_bytes: 3116
#include<cstdio>
#include<iostream>
#include<cctype>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

#define ll long long
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define MD 1000000007

char sep[3] = " \n";
int i, j, k, l, m, n;
double PI = acos(-1);


int main() {
  double a, b, c;
  cin >> a >> b >> c;
  c = PI*c/180;
  printf("%.5f\n%.5f\n%.5f\n",
         0.5 * a * b * sin(c),
         a + b + sqrt(a*a + b*b - 2.0*a*b*cos(c)),
         b * sin(c));

  return 0;
}
  

Measured memory_bytes: 1256
#include <stdio.h>
#include <limits.h>
const int N = 500000;
const int INFTY = INT_MAX;
int cunt = 0;
void merge(int*, int, int, int);
void mergeSort(int*, int, int);
int main() {
	int i,S[N],n;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &S[i]);
	}
	mergeSort(S, 0, n);
	for (i = 0; i < n; i++) {
		if (i) printf(" ");
		printf("%d", S[i]);
	}
	printf("\n");
	printf("%d\n",cunt);
	return 0;
}
void merge(int *A, int left, int mid, int right) {
	int n1, n2, i, j, k,R[N],L[N];
	n1 = mid - left;
	n2 = right - mid;
	//L[0...n1], R[0...n2] を生成
	for (i = 0; i < n1; i++) {
		L[i] = A[left + i];
	}
	for (i = 0; i < n2; i++) {
		R[i] = A[mid + i];
	}

	L[n1] = INFTY;
	R[n2] = INFTY;
	i = 0;
	j = 0;
	for (k = left; k < right; k++) {
		if (L[i] <= R[j]) {
			A[k] = L[i];
			i = i + 1;
		}
		else {
			A[k] = R[j];
			j = j + 1;
		}
		/*
		for (a = 0; a < n; a++) {
			if (a) printf(" ");
			printf("A[%d] %d",a, A[a]);

		}
		printf("\n");
		*/
		cunt++;
	}
}

void mergeSort(int *A, int left, int right) {
	int mid, i;
	if (left + 1 < right) {
		mid = (left + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}
}


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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;

  if (A + B > C + D){ 
  cout << "Left" << endl; 
  }
  
  else if (A + B == C + D)
  {
  cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    String s = sc.next();

    sc.close();

    String[] S = s.split("");

    for (int i = S.length - 2; 2 <= i; i = i - 2) {
      String s1 = s.substring(0, i / 2);
      String s2 = s.substring(i/2, i);
      if (s1.equals(s2)) {
        System.out.println(i);
        break;
      }
    }

  }

}


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

int main() {
  long long x;
  cin >> x;
  long long ans=0;
  long long i = x/500;
  ans = i*1000;
  int num = (x%500)/5;
  ans = ans + num*5;
  cout << ans << endl;
  
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cctype>
#include <cmath>
#include <math.h>
using namespace std;

int isprime(int x){
  if (x<2) return 0;
  if (x==2) return 1;
  if (x%2==0) return 0;
  for (int i=3;i<=sqrt(x);i+=2){
    if (x%i==0) return 0;
  }
  return 1;
}

int main(){
  int n,cnt;
  int a[100];
  cin >> n;
  for (int i=0;i<n;i++) {
    cin >> a[i];
  }
  for (int i=0;i<n;i++) {
    for (int j=n-1;0<j;j--) {
      if (a[j]<a[j-1]) {
        swap(a[j],a[j-1]);
        cnt++;
      }
    }
  }
  for (int i=0;i<n;i++) {
    if (i==(n-1)) {
      cout << a[i] << endl;
    } else { cout << a[i] << " "; }
  }
  cout << cnt <<endl;
}



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

int main(){
    int n;
    string s;
    cin >> n >> s;
    bool kurikaeshi = true;

    if(n % 2 == 1){
        kurikaeshi = false;
        }
    else{
        rep(i, n/2){
            if (s[i] != s[n/2 + i]){
                kurikaeshi = false;
            }
        }
    }
    if(kurikaeshi == true) {
        cout << "Yes" << endl;
    }
    else{
        cout << "No" <<endl;
    } 
}

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

int main() {
	int N, M;
	cin >> N >> M;
	vector<int>v(M);
	for (int i = 0; i < M; i++) {
		cin >> v.at(i);
	}
	sort(v.begin(), v.end());
	vector<int>u(M - 1);
	for (int i = 0; i < M - 1; i++) {
		u.at(i) = v.at(i + 1) - v.at(i);
	}
	sort(u.begin(), u.end());
	int ans = 0;
	for (int i = 0; i < M - N; i++) {
		ans += u.at(i);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	map<string, int> ms;
	rep(i, n){
		string in;
		cin >> in;
		sort(in.begin(), in.end());
		ms[in]++;
	}
	ll ans = 0;
	for(auto p : ms){
		// cerr << p.first << " " << p.second << endl;
		if(p.second > 1) ans += (ll)p.second * (p.second - 1) / 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11136
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var S string
	fmt.Scan(&S)
	N := len(S)
	a := make([]int, N)
	for i, r := range S {
		a[i], _ = strconv.Atoi(string(r))
	}
	MOD := 2019
	sum := 0
	pow := 1
	ms := make([]int, N)
	for i := N - 1; i >= 0; i-- {
		sum += a[i] * pow
		sum %= MOD
		ms[i] = sum
		// sum %= MOD
		pow *= 10
		pow %= MOD
	}
	m := make(map[int]int)
	m[0]++
	for _, val := range ms {
		m[val]++
	}
	count := 0
	for _, val := range m {
		if val > 1 {
			count += val * (val - 1) / 2
		}
	}
	fmt.Println(count)
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)

using namespace std;
using ll = long long;
typedef pair<int, int> Pair;

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

  vector<int> a(n);
  vector<int> b(n - 1);
  rep(i, n - 1) cin >> b[i];

  a[0] = b[0];
  if (n > 2) {
    for (int i = 1; i < n; i++) {
      a[i] = min(b[i - 1], b[i]);
    }
  }
  a[n-1] = max(a[n - 2], b[n - 2]);
  int ans = accumulate(a.begin(), a.end(), 0);
  // rep(i, n - 1) cout << "b:" << b[i] << " " << endl;
  // rep(i, n) cout << "a:" << a[i] << " ";
  // cout << endl;
  cout << ans << endl;
}

Measured memory_bytes: 256
// Snippets
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

macro_rules! stdin {
    () => ({
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    })
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => (
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input.to_string()), $output);
            )*
        }
    )
}

// End Snippets

fn main() {
    println!("{}", solve(stdin!()));
}

fn solve(src: String) -> String {
    input!{
        source = src,
        n: usize,
        h: [i32; n]
    }
    let mut ans = 1;
    let mut max = h[0];
    for i in 1..n {
        if h[i] >= max {
            ans += 1;
            max = h[i];
        }
    }
    ans.to_string()
}

test! {
r"4
6 5 6 8
" => "3",
r"5
4 5 3 5 4
" => "3",
r"5
9 5 6 8 4
" => "1",
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <utility>

using namespace std;

int main() {
  int a[3];
  scanf("%d %d %d", &a[0], &a[1], &a[2]);
  if(a[0] > a[1]) {
    swap(a[0], a[1]);
  }
  if(a[1] > a[2]) {
    swap(a[1], a[2]);
  }
  if(a[0] > a[1]) {
    swap(a[0], a[1]);
  }
  printf("%d %d %d\n", a[0], a[1], a[2]);
  return 0;
}


Measured memory_bytes: 2752
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
int main(){
  int n;
  scanf("%d", &n);
  std::vector<int > v(n);
  for (int i=0; i<n; i++){
    scanf("%d", &v[i]);
  }
  std::map<int, int > mp1, mp2;
  int odd = 0, even = 0;
  for (int i=1; i<n; i=i+2){
    //printf("i=%d\n", i);
    mp1[v[i]]++;
    even++;
  }
  for (int i=0; i<n; i=i+2){
    //printf("i=%d\n", i);
    mp2[v[i]]++;
    odd++;
  }
  int mp1_count1 = -1;
  int mp1_value1;
  for (auto entry : mp1){
    if (entry.second>mp1_count1){
      mp1_count1 = entry.second;
      mp1_value1 = entry.first;
    }
  }
  int mp2_count1 = -1;
  int mp2_value1;
  for (auto entry : mp2){
    if (entry.second>mp2_count1){
      mp2_count1 = entry.second;
      mp2_value1 = entry.first;
    }
  }
  int ans = 0;
  //  printf("checking %d == %d\n", mp1_value1, mp2_value1);
  //printf("%d,%d\n", mp1_count1, mp2_count1);
  if (mp1_value1!=mp2_value1){
    //printf("%d-%d + %d-%d = %d\n",even,mp1_count1,odd,mp2_count1, ans);
    ans = (even-mp1_count1)+(odd-mp2_count1);
  } else {
    int mp1_count2 = 0;
    int mp1_value2 = 0;
    mp1.erase(mp1_value1);
    for (auto entry: mp1){
      if (entry.second>mp1_count2){
        mp1_count2 = entry.second;
        mp1_value2 = entry.first;
      }
    }
    int mp2_count2 = 0;
    int mp2_value2 = 0;
    mp2.erase(mp2_value1);
    for (auto entry: mp2){
      if (entry.second>mp2_count2){
        mp2_count2 = entry.second;
        mp2_value2 = entry.first;
      }
    }
    ans = std::min((even-mp1_count2)+(odd-mp2_count1),
                   (even-mp1_count1)+(odd-mp2_count2));
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rbf(a, x) for (auto& a : x)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define drep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define Maxe(x) *max_element(all(x))
#define Mine(x) *min_element(all(x))
#define Size(x) ((ll)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
#define Fi first
#define Se second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    template<typename Num>
        constexpr Num mypow(Num a, long long b) {
            if(b==0)return 1;
            if (a==0)return 0;
            Num x = 1;
              while (b > 0) {
                if(b & 1)x*=a;
                a*=a;
                b >>= 1;
              }
              return x;
        }

    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;
    }

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo
//mint,dijkstra,gyakugen

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        string s,t;
        cin>>s>>t;
        ll n=Size(s);
        ll res=0;
        rep(i,n){
            if(s[i]!=t[i])res++;
        }
        cout<<res<<endl;
    }

Measured memory_bytes: 3780
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#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 all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> A(N); rep(i, 0, N) {
		cin >> A[i];
	}
	vector<int> s(N + 1);
	unordered_map<int, int> mp;
	rep(i, 0, N)s[i + 1] = s[i] + A[i];
	rep(i, 0, N + 1)mp[s[i]]++;
	dump(s);
	int ans = 0;
	for (auto p : mp) {
		dump(p);
		ans += p.second * (p.second - 1) / 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11592
nmax = 8
graph = [[False] * nmax for _ in range(nmax)]


def dfs(v, N, visited):
    all_visited = True
    for i in range(N):
        if not visited[i]:
            all_visited = False
    if all_visited:
        return 1

    ret = 0
    for i in range(N):
        if not graph[v][i]:
            continue
        if visited[i]:
            continue

        visited[i] = True
        ret += dfs(i, N, visited)
        visited[i] = False
    return ret


N, M = map(int, input().split())
for _ in range(M):
    a, b = map(int, input().split())
    graph[a - 1][b - 1] = graph[b - 1][a - 1] = True

visited = [False] * nmax
visited[0] = True
print(dfs(0, N, visited))


Measured memory_bytes: 3064
#include <stdio.h>
#define M 5000000

int heap[M];
int n;
void getmax(int);

void build(void);

int main(){
    int i;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&heap[i]);
    }
    build();
    for(i = 1;i <= n;i++){
        printf(" %d",heap[i]);
    }
    printf("\n");
    
    return 0;
    
}

void getmax(int i){
    int l=2*i;
    int r=2*i+1;
    int m,p;
    
    if(l<=n && heap[i]< heap[l]){
        m=l;
    }
    else {
        m=i;
    }
    if(heap[r] > heap[m] && r<=n){
        m=r;
    }
    if(m!=i){
        p=heap[i];
        heap[i]=heap[m];
        heap[m]=p;
        getmax(m);
    }
}

void build(void){
    int i;
    for(i=(n/2);i>=1;i--){
        getmax(i);
    }
}



Measured memory_bytes: 3752
while True:
    n, m = map(int, raw_input().split())
    if n==0 and m==0:
        break
    p = range(1,n+1); idx = n-1;
    while len(p)>1:
        idx = (idx + m)%len(p)
        p.pop(idx)
        idx = (idx + len(p) - 1)%len(p)
    print p[0]

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

int main()
{
    int w, h, n;
    cin >> w >> h >> n;
    vector<int> x(n), y(n), a(n);
    for (int i = 0; i < n; i++)
        cin >> x[i] >> y[i] >> a[i];
    int lw = 0, uw = w, lh = 0, uh = h;
    for (int i = 0; i < n; i++)
    {
        if (a[i] == 1 && x[i] > lw)
            lw = x[i];
        if (a[i] == 2 && x[i] < uw)
            uw = x[i];
        if (a[i] == 3 && y[i] > lh)
            lh = y[i];
        if (a[i] == 4 && y[i] < uh)
            uh = y[i];
    }
    w = uw - lw;
    h = uh - lh;
    if (w < 1 || h < 1)
        cout << 0 << endl;
    else
        cout << w * h << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <math.h>
#include <climits>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <map> 
#include <set>
#include <string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
const ll MD = 1000000007;

/* sample input

*/

int main()
{
	ll h, w;
	char a[101][101];
	ll num[26] = {};
	bool flug = true;

	cin >> h >> w;
	for (ll i = 0; i < h; i++) {
		for (ll j = 0; j < w; j++) {
			cin >> a[i][j];
			for (int k = 0; k < 26; k++) {
				if (a[i][j] == 'a' + k) {
					num[k]++;
					break;
				}
			}
		}
	}

	ll num1 = 0, num2 = 0, num4 = 0;

	for (int i = 0; i < 26; i++) {
		while (num[i] > 0) {
			if (num[i] >= 4) {
				num[i] -= 4;
				num4++;
			}
			else if (num[i] >= 2) {
				num[i] -= 2;
				num2++;
			}
			else {
				break;
			}
		}
	}

	//偶-偶
	if (h % 2 == 0 && w % 2 == 0) {
		for (int i = 0; i < 26; i++) {
			if (num4*4<h*w) {
				flug = false;
			}
		}
	}
	//偶h-奇w
	else if (h % 2 == 0 && w % 2 == 1) {
		//2コペアhコ
		//4コペアh*(w-1) 

		if (w == 1) {
			if (!(num4 * 4 + num2 * 2 == h*w)) {
				flug = false;
			}
		}
		else if (num4*4 <h*(w - 1) ||num4*4+num2*2 < h*w||num1>0) {
			flug = false;
		}

	}
	//奇h-偶w
	else if (h % 2 == 1 && w % 2 == 0) {
		//2コペアwコ
		//4コペアw*(h-1)

		if (h == 1) {
			if (!(num4 * 4 + num2 * 2 == h*w)) {
				flug = false;
			}
		}
		else if (num4 * 4 <w*(h - 1) || num4 * 4 + num2 * 2 < h*w || num1>0) {
			flug = false;
		}
	}
	//奇-奇
	else if (h % 2 == 1 && w % 2 == 1) {
		//1コペア1コ
		//2コペア(n+m-2)コ
		//4コペア(w-1)*(h-1)
		if (num1>1|| num4*4 < (h - 1)*(w-1) || num4*4+num2*2 <h*w-1) {
			flug = false;
		}

	}

	if (flug) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll & a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll & a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N=500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
#include <cstdint>                                                                                                              

template <std::uint_fast64_t Modulus> class modint {
	using u64 = std::uint_fast64_t;

public:
	u64 a;

	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept {
		return modint(*this) /= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) {
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint& operator/=(modint rhs) noexcept {
		u64 exp = Modulus - 2;
		while (exp) {
			if (exp % 2) {
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};

using mint = modint<MOD>;
map<ll,mint> M;
map<ll,ll> S;
mint dp(ll n){
    if(S[n]>0)return M[n];
    if(n==0)M[n]=1;
    else if(n%2==1)M[n]=dp(n/2);
    else M[n]=dp(n/2)+dp(n/2-1);
    S[n]=1;
    return M[n];
}
mint solve(ll n){
    if(n==0)return 1;
    if(n%2==1)return solve(n/2)*3-M[n/2];
    if(n%2==0)return solve(n/2)*3-M[n/2]*2;
}
int main() {
    cin>>n;
    dp(n);
    cout<<solve(n).a<<endl;
}

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 check(vec, init_pos, target_pos):
    base = 8000
    dp = [False] * 16001
    dp[init_pos + base] = True

    for i in range(len(vec)):
        dp, dp_prev = [False] * 16001, dp
        for j in range(16001):
            if (
                j - vec[i] >= 0
                and dp_prev[j - vec[i]]
                or j + vec[i] <= 16000
                and dp_prev[j + vec[i]]
            ):
                dp[j] = True

    return dp[target_pos + base]


def main():
    S = readline().strip()
    x, y = map(int, readline().split())

    idx = len(S)
    for i, c in enumerate(S):
        if c == 'T':
            idx = i
            break

    init_x = idx
    step = [[] for _ in range(2)]
    i = 0
    for c in S[idx:]:
        if c == 'T':
            i = 1 - i
            step[i].append(0)
        else:
            step[i][-1] += 1
            
    for row in step:
        row = [v for v in row if v != 0]
        if not row:
            row = [0]

    ok = check(step[0], init_x, x) and check(step[1], 0, y)

    if ok:
        print('Yes')
    else:
        print('No')

    return


if __name__ == '__main__':
    main()


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

int main(){
  long long N,R,ans;
  cin>>N;
  vector<long long>a(N),b(40);
  for(int i=0;i<40;i++){
  b[i]=0;
  }
  for(int i=0;i<N;i++){
    cin>>a[i];
      for(int j=39;j>0;j--){
      if(a[i]%2==1){
      b[j]++;
     }
        a[i]/=2;
        if(a[i]==0){
        break;
        }
      }
  }
  if(N%3==0){
  for(int i=0;i<40;i++){
    if(b[i]==0){
    continue;
    }
  if(b[i]!=(N*2)/3){
  cout<<"No"<<endl;
  return 0;
  }
  }
  }
  else{
    for(int i=0;i<40;i++){
    if(b[i]==0){
    continue;}
  cout<<"No"<<endl;
  return 0;
    }
    }
    cout<<"Yes"<<endl;
    return 0;
  }

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  map<int, int> mp;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    int sa = i - a[i];
    ans += mp[sa];
    int wa = a[i] + i;
    mp[wa]++;
  }
  cout << ans << endl;
  return 0;
}

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

bool isEven(int x) {
	if(x % 2 == 0) return true;
	else return false;
}
 
class UnionFind {
public:
	vector<int> parent;
	
	UnionFind(int n) : parent(n) {
		for(int i = 0; i < n; i++) {
			parent[i] = i;
		}
	}
	
	int root(int x) {
		if(parent[x] == x) return x;
		return parent[x] = root(parent[x]);
	}
	
	void unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		parent[rx] = ry;
	}
	
	bool same(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
 
int main() {
	int n, m;
	cin >> n >> m;
	int x[m];
	int y[m];
	int z[m];
	
	UnionFind card(n);
	int ans = n;
	
	for(int i = 0; i < m; i++) {
		cin >> x[i] >> y[i] >> z[i];
		if(!card.same(x[i]-1, y[i]-1)) {
			ans--;
		}
		card.unite(x[i]-1, y[i]-1);
		
		/*for(int i = 0; i < n; i++){
			cout << card.root(i) << " ";
		}
		cout << endl;*/
	}
	
	cout << ans << endl;
	
	return 0;
}


/*
class node {
	int number;
	int parent;
	
	node(int num) {
		this.number = num;
		this.parent = this;
	}
	
	void setNumber(int num) {
		this.number = num;
	}
	
	void setParent(int par) {
		this.parent = 
	}
	
	int getParent() {
		return this.parent;
	}
};*/


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <climits>
#include <cfloat>
#include <map>

using namespace std;

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

const int INF = INT_MAX;

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

int main(){
    vector<string> str;
    map<string,int> m;
    string s;
    while(cin>>s){
        str.push_back(s);
        m[s]++;
    }
    int ans1=0;
    string ans1str,ans2str;
    int ans2=0;
    int n=str.size();
    rep(i,n){
        if(str[i].length()>ans2){
            ans2=str[i].length();
            ans2str=str[i];
        }
    }
    rep(i,n){
        if(m[str[i]]>ans1){
            ans1=m[str[i]];
            ans1str=str[i];
        }
    }
    cout << ans1str << " " << ans2str << endl;
    return 0;
}

Measured memory_bytes: 1208
package main

import (
  "os"
  "fmt"
)

func main() {
  var S, W int
  fmt.Fscanf(os.Stdin, "%d %d", &S, &W)
  if S <= W {
  	fmt.Println("unsafe")
  } else {
  	fmt.Println("safe")
  }
}

Measured memory_bytes: 1824
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);


int main() {
    int n, m;
    cin >> n >> m;
    vector<int> c(n);
    fill(c.begin(), c.end(), 0);
    rep(i, m) {
        int ta, tb;
        cin >> ta >> tb;
        ta--, tb--;
        c[ta]++, c[tb]++;
    }
    rep(i, n) cout << c[i] << endl;
    return 0;
}

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

using namespace std;

int main(){
  int n;
  cin>>n;
  int g,k;
  if (n%2){
    k=n/2+1;
    g=n/2;
  }
  else {
    k=n/2;
    g=n/2;
  }
  cout<<k*g<<endl;
  return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll big = 1000000007;
const ll mod = 998244353;

ll n,m,k;
vector<string> A;
vector<vl> C(13, vl());
string alfa = "abcdefghijklmnopqrstuvwxyz";

ll M[13][13] = {0};


void combine(ll i, ll j, ll diff){
    for(int c1 = 0; c1 < m; c1++){
        for(int c2 = 0; c2 < m; c2++){
            if(A[i][c1] == A[j][c2] && A[i][c2] == A[j][c1]){
                M[c1][c2]+=diff;
                if(i != j)M[c1][c2] += diff;
            }
        }
    }
}

bool mark2[15] = {0};
bool match2(){
    for(int c1 = 0; c1 < m; c1++){
        mark2[c1] = 0;
    }
    ll alone = 0;
    for(int c1 = 0; c1 < m; c1++){
        if(mark2[c1])continue;
        bool done = 0;
        for(int c2 = c1+1; c2 < m; c2++){

            if(M[c1][c2] == n && !mark2[c2]){
                mark2[c1] = 1;
                mark2[c2] = 1;
                done = 1;
                break;
            }
        }
        if(!done){
           // cout << M[c1][c1] << "\n";
            if(M[c1][c1] != n){
                return 0;
            }
            alone++;
        }
    }
    return (alone == (m%2));
}

bool mark[15] = {0};
ll mid = 0;
bool match(ll i){
    if(i == n){

        return match2();

    }
    if(mark[i])return match(i+1);
    bool ans = 0;
    for(int c1 = i; c1 < n; c1++){
        if(c1 == i && mid >= n%2)continue;
        if(!mark[c1]){
            combine(i,c1,1);
            mark[c1] = 1;
            mark[i] = 1;
            mid += (i == c1);
            ans |= match(i+1);
            mid -= (i == c1);
            mark[c1] = 0;
            mark[i] = 0;
            combine(i,c1,-1);
        }
    }



    return ans;
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,e;

    cin >> n >> m;

    for(int c1 = 0; c1 < n;c1++){
        string s;
        cin >> s;
        A.push_back(s);
    }

    if(match(0)){
        cout << "YES\n";
    }
    else{
        cout << "NO\n";
    }

    return 0;
}


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

using namespace std;

int n, m;
vector<vector<int>> ed(1e5 + 5);
vector<int> dp, ind;

int solve(int x){
    if(dp[x] != -1) return dp[x];
    int res = 0;
    for(auto y : ed[x]){
        res = max(res, 1 + solve(y));
    }
    return dp[x] = res;
}

int main(){
    cin>>n>>m;
    dp.assign(n, 0);
    ind.assign(n, 0);
    while(m--){
        int x, y;
        cin>>x>>y; x--; y--;
        ed[x].push_back(y);
        ind[y]++;
    }
    int res = -1;
    // for(int i = 0; i < n; i++){
    //     res = max(res, solve(i));
    // }
    queue<int> q;
    for(int i = 0; i < n; i++){
        if(ind[i] == 0){
            q.push(i);
        }
    }
    while(!q.empty()){
        int fr = q.front(); q.pop();
        for(int i = 0; i < ed[fr].size(); i++){
            int v = ed[fr][i];
            ind[v]--;
            dp[v] = max(dp[v], 1 + dp[fr]);
            if(ind[v] == 0) q.push(v);
        }
    }
    for(auto x : dp){
        res = max(res, x);
    }
    cout<<res<<endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int l, r;
  int ans = 0;
  for (int i=0; i<N; i++){
    cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")

#include<bits/stdc++.h>
#define sp " "
#define endl "\n"
#define MAX 10e9
#define MAXN 100001
#define mod 1000000007
#define inf_int 2e9
#define inf_ll 2e18
#define e 1e-9
#define vi vector<int>
#define vl vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpl vector<pair<ll,ll>>
#define vpc vector<pair<char,char>>
#define adj_list vector<vl>
#define umap unordered_map<ll, ll>
#define pll pair<ll,pair<ll, ll>>
#define clr(x) memset(x,0,sizeof(x))
#define cy cout << "YES" << endl
#define cn cout << "NO" << endl
#define google cout << "Case #" << ++it << ": " << ans << endl;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
typedef long long int ll;

ll it = 0, ans = 0;

ll spf[MAXN];
void sieve()
{
    spf[1] = 1;
    for (auto i=2; i<MAXN; i++)
  		spf[i] = i;
  	for (auto i=4; i<MAXN; i+=2)
        spf[i] = 2;
    for (auto i=3; i*i<MAXN; i++)
    {
        if (spf[i] == i)
        {
            for (auto j=i*i; j<MAXN; j+=i)
                if (spf[j]==j)
                    spf[j] = i;
        }
    }
	return;
}

vl getFactorization(ll x)
{
    vl ret;
    while (x != 1)
    {
        ret.push_back(spf[x]);
        x = x / spf[x];
    }
    return ret;
}


void check()
{
	string s = "ACL";
	ll k;
	cin >> k;
	for(int i=0;i<k;i++) cout << s;
    return ;
}

int32_t main()
{
    fastio
    ll t = 1;
    // cin >> t;
    while(t--)
        check();
    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int64_t Kaijo(int n){
    int64_t v=1;
    _rep(i,n,1) v*=i;
    return v;
}

int64_t Comb(int n, int m){
    return Kaijo(n)/Kaijo(m)/Kaijo(n-m);
}

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

    int64_t t=100*(N-M)+1900*M;
    double p=pow(0.5,M);
    int64_t ans=t/p;

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int N;
pair<pair<string,int>,int> SPN[100];

int main(){
    cin>>N;
    rep(i,N){
        cin>>SPN[i].first.first;
        cin>>SPN[i].first.second;
        SPN[i].first.second*=-1;
        SPN[i].second=i+1;
    }

    sort(SPN,SPN+N);

    rep(i,N){
        cout<<SPN[i].second<<endl;
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

signed main() {
    while(1) {
        int r,c;
        cin>>r>>c;
        if(r+c==0) break;

        vector<int> col(c,0);
        REP(i,r) {
            REP(j,c) {
                int k;
                cin>>k;
                col[j]|=(k<<i);
            }
        }

        int ans=0;
        REP(mask,(1<<r)) {
            int tmp=0;
            REP(i,c) {
                int t=col[i]^mask;
                int senbei_rev=__builtin_popcount(t);
                tmp+=max(senbei_rev,r-senbei_rev);
            }
            chmax(ans,tmp);
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

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

    vector<vector<int>> x(n+1, vector<int>(n+1, 0));

    int ans=0,tmp;


    int a, b;
    REP(i, m) { 
        cin >> a>>b;
        x[a][b] = 1;
    }
    REP(_,max(10,n/6))
    REP(i,n+1)REP(j,n+1){
        if(x[i][j] == 1){
            REP(k, n+1)
            x[i][k] = max(x[i][k],x[j][k]);
        }
    }

    
    FOR(i, 1, n + 1)
    {
        string s = "";
        FOR(j, 1, n + 1)
        {
            if(i==j){
                //cout << i << " ";
                s += to_string(i) + " ";
            }else if(x[i][j]+x[j][i]==2){
                //cout << j <<" ";
                s += to_string(j) + " ";
            }
        }
        //cout << "\n";
        s.erase(--s.end());
        cout << s << "\n";
    }
    //cout << s << "/n";

    return 0;
}


Measured memory_bytes: 3376
#include <bits/stdc++.h>  
 
using namespace std;
 
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; --i)
#define repr(i, j) FOR(i, j, 0)
#define INF (1 << 30)
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
 
const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};
 
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
 
int fact[100005];
 
int elePow(int a, int b) {
	int num = 1;
	while(b != 0) {
		if(b & 1) num = 1ll * num * a % MOD;
		b /= 2;
		a = 1ll * a * a % MOD;
	}
	return num;
}
 
int nCr(int n, int r) {
	if(r > n) return 0;
	if(r == 0) return 1;
	int a = fact[n], b = 1ll * fact[r] * fact[n - r] % MOD;
	int res = 1ll * a * elePow(b, MOD - 2) % MOD;
	return res;
}
 
int a[100005];
map<int, bool> went;
 
int main() {
	int n;
	scanf("%d", &n);
	int l, d, r;
	rep(i, n + 1) {
		scanf("%d", &a[i]);
		if(!went[a[i]]) went[a[i]] = true;
		else {
			r = i;
			d = a[i];
		}
	}
	rep(i, n + 1) if(a[i] == d) {
			l = i;
			break;
	}
	fact[0] = 1;
	FOR(i, 1, n + 2) {
		fact[i] = 1ll * fact[i - 1] * i % MOD;
		//cout << fact[i] << endl;
	}
	printf("%d\n", n);
	FOR(i, 2, n + 2) {
		printf("%d\n", (nCr(n + 1, i) - nCr(l + n - r, i - 1) + MOD) % MOD);
	}
	return 0;
}

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

int main(){

  int i,N,j,minj,box,count = 0;
  int A[100];

  scanf("%d",&N);

  for(i=0;i<N;i++)
    scanf("%d",&A[i]);

  for(i=0;i<N;i++){
    minj = i;
    for(j=i;j<N;j++){
      if(A[j]<A[minj])
	minj = j;
    }
    if(i != minj){
      box = A[i];
      A[i] = A[minj];
      A[minj] = box;
      count++;
    }
  }
  for(i=0;i<N-1;i++)
    printf("%d ",A[i]);

  printf("%d\n%d\n",A[i],count);

  return 0;
}

Measured memory_bytes: 600
#include <vector>
#include <cstdio>
#define M(x,y)push_back(std::make_pair(x,y))
typedef std::pair<int,int>pii;
main(){
	int n,x,i,q;
	pii p;
	for(;scanf("%d%d",&n,&x),n;printf("%d\n",x)){
		std::vector<pii>v;
		v.M(x,1);
		for(i=1;i<n;i++)
			if(p=v.back(),scanf("%d",&x),x==p.first)v.back().second++;
			else if(i&1){
				if(v.pop_back(),q=0,v.size())q=v.back().second,v.pop_back();
				v.M(x,q+p.second+1);
			}else v.M(x,1);
		for(x=i=0;i<v.size();i++)if(!v[i].first)x+=v[i].second;
	}
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
int x,k,d;
signed main(){
    scanf("%lld%lld%lld",&x,&k,&d);
    x=abs(x);
    int ned=x/d;
    if(k<=ned) printf("%lld",x-k*d);
    else {
        int lst=k-ned;
        if(lst&1) printf("%lld",abs(x-ned*d-d));
        else printf("%lld",abs(x-ned*d));
    }
    return 0;
}

Measured memory_bytes: 3812
use std::io::*;
use std::str::FromStr;
use std::cmp::min;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let k: usize = read();
    let h: Vec<i64> = (0..n).map(|_| read()).collect();
    let mut dp: Vec<i64> = (0..n).map(|_| std::i64::MAX).collect();
    dp[0] = 0;

    for i in 0..n {
        let l = k + 1;
        for j in 1..l {
            if i < j {
                continue;
            }
            dp[i] = min(dp[i - j] + (h[i - j]- h[i]).abs(), dp[i]);
        }
    }
    println!("{}", dp[n - 1]);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll a;
  cin>>a;
  ll b;
  cin>>b;
  ll c=a/b;
  ll d=c*c*c;
  if(b%2==0){
    ll e=a/(b/2)-c;
    d+=e*e*e;
  }
  cout<<d<<endl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <limits.h>
#include <map>

using namespace std;
typedef long long int ll;

ll solve(void);
bool isValid(const ll y, const ll x, vector<string> &maze);
void search(ll &y, ll&x, ll&d, ll&cnt, ll L, vector<string>&maze, vector<vector<vector<ll>>> &memo);


int main(void) {

	while (solve());
	return 0;

}

ll solve(void) {

	ll H, W, L;
	cin >> H >> W >> L;
	if (!(H | W | L)) { return 0; }
	vector<string> maze(H);

	/*
		memo[y][x][direction] = the number of steps
	*/
	vector<vector<vector<ll>>> memo
		(H, vector<vector<ll>>(W, vector<ll>(4,INT64_MAX) ) );
	vector<vector<vector<ll>>> memo_s;

	//input

	map<char, ll> mp;
		mp['E'] = 0;
		mp['S'] = 1;
		mp['W'] = 2;
		mp['N'] = 3;
	vector<char> v = {'E','S','W','N'};

	ll x, y, d, cnt = 0;
	ll loop_start = 0, loop_end;

	for (ll i = 0; i < H; i++) {
		cin >> maze[i];
		for (ll j = 0; j < maze[i].length(); j++) {
			if (maze[i][j] != '.' && maze[i][j] != '#') {
				y = i; x = j; d = mp[maze[i][j]];
				memo[y][x][d] = cnt;
			}
		}
	}
	memo_s = memo;

	search(y, x, d, cnt, L, maze, memo);

	loop_start = memo[y][x][d];
	loop_end = cnt;

	if (L <= loop_end) {
		cnt = 0;
	} else {
		L -= loop_end;
		L %= (loop_end - loop_start);
		cnt = 0;
		if (L == 0) L = loop_end - loop_start;
		search(y, x, d, cnt, L, maze, memo_s);
	}

	cout << y + 1 << " " << x + 1 << " " << v[d] << endl;

	return 1;
}

bool isValid(const ll y, const ll x, vector<string>& maze)
{
	return (0<=y && 0<=x && y < maze.size() && x < maze[y].length() && maze[y][x] != '#');
}

void search(ll & y, ll & x, ll & d, ll & cnt, ll L, vector<string>& maze, vector<vector<vector<ll>>>& memo)
{

	ll dd[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };

	while (true) {

		if (cnt == L) { 
			break;
		}

		if (isValid(y + dd[d][0], x + dd[d][1], maze)) {

			y += dd[d][0];
			x += dd[d][1];
			cnt++;

			if (memo[y][x][d] < INT64_MAX) { break; }
			memo[y][x][d] = min(cnt, memo[y][x][d]);

		}
		else {

			d = (d + 1) % 4;

			if (memo[y][x][d] < INT64_MAX) { break; }
			memo[y][x][d] = min(cnt, memo[y][x][d]);

		}


	}
}

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

int main()
{
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(m);
  for (int i = 0; i < m; i++)
  {
    cin >> b[i];
  }

  int ans = 0;
  for (int i = 0; i < n; i++)
  {
    int sum = 0;
    for (int j = 0; j < m; j++)
    {
      int a;
      cin >> a;
      sum += a * b[j];
    }
    if (sum + c > 0)
    {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3596
n,*a=`dd`.split.map &:to_i;a.sort_by! &:-@;i=(0...n).find{|x|a[x]<x+1}||n;j=(i...n).find{|x|a[x]<i}||n;puts (a[i-1]-i)%2+(j-i)%2>0?:First: :Second

Measured memory_bytes: 12028
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define mod 1000000007LL
#define eps 1e-13
// #define PI 3.141592653589793238L
#define INF 1000000011
#define INFLL 1000000000000000011LL
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define fo(i,a,n) for(i = (a); i < (n); i++)
#define gtl(x) getline(cin, (x))
#define flsh fflush(stdout)
#define sws ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define gcd __gcd
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)((a).size())
#define io_file freopen("D:/Coding Problems/Contest/input_file.in", "r", stdin); freopen("D:/Coding Problems/Contest/output_file.out", "w", stdout)

ll modx(ll Base, ll exponent)
{
	ll ans = 1;
	if(Base == 1)
		return Base;
	while(exponent)
	{
		if(exponent & 1)
			ans = (ans * Base)%mod;
		Base = (Base * Base)%mod;
		exponent = exponent >> 1;
	}
	return ans;
}

ll inmodx(ll num)
{
	return (modx(num, mod-2LL));
}

bool cmp(pair < pii, int > a, pair < pii, int > b)//true for a before b
{
	if(a.F.F/300 < b.F.F/300)
		return 1;
	if(a.F.F/300 > b.F.F/300)
		return 0;
	if(a.F.S < b.F.S)
		return 1;
	if(a.F.S > b.F.S)
		return 0;
	if(a.F <= b.F)
		return 1;
	return 0;
}

const int N = (2e5) + 9;
const int M = (N<<2) + 9;
const int LOGN = ((int)log2(N)) + 3;
const int LOGM = ((int)log2(M)) + 3;
const int BUCK = 2*550;
const int SQRT = BUCK+9;

ll sum[N];
map < ll, ll > mapp;

void solve()
{
	int n, i;
	ll ans = 0, a;
	cin >> n;
	fo(i,1,n+1)
	{
		cin >> a;
		sum[i] = sum[i-1] + a;
	}
	fo(i,0,n+1)
		mapp[sum[i]]++;
	for(auto x : mapp)
		ans += (x.S*(x.S-1LL));
	ans /= 2LL;
	cout << ans << '\n';
	return;
}

int main()
{
	sws;
	clock_t clk;
	clk = clock();
	// io_file; yoyo
	// srand (time(NULL));

	//Code here
	int t = 1, cs;
	cout << fixed << setprecision(9);
	// cin >> t;
	fo(cs,1,t+1)
	{
		// cout << "Case #" << cs << ": ";
		solve();
	}
	// Code ends here

	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << "\n";
	return 0;
}

Measured memory_bytes: 14336