akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#define inf 1e9

using namespace std;
typedef pair<int, int> P;

int h, w, k;
char c[1005][1005];
int px[25], py[25];
int d[1005][1005];
int dist[25][25];
int dp[1<<20][20];
int pop[1<<20];
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};

void bfs(int sx, int sy)
{
	for(int y = 1; y <= h; y++){
		for(int x = 1; x <= w; x++){
			d[x][y] = inf;
		}
	}
	d[sx][sy] = 0;
	
	queue<P> Q;
	Q.push(P(sx, sy));
	
	while(Q.size()){
		int x = Q.front().first, y = Q.front().second;
		Q.pop();
		for(int i = 0; i < 4; i++){
			int nx = x + dx[i], ny = y + dy[i];
			if(nx < 1 || nx > w || ny < 1 || ny > h) continue;
			if(d[nx][ny] < inf) continue;
			if(c[nx][ny] == '#') continue;
			d[nx][ny] = d[x][y] + 1;
			Q.push(P(nx, ny));
		}
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> h >> w >> k;
	int m = 0;
	for(int y = 1; y <= h; y++){
		for(int x = 1; x <= w; x++){
			cin >> c[x][y];
			if(c[x][y] == 'a') px[m] = x, py[m] = y, m++;
		}
	}
	for(int y = 1; y <= h; y++){
		for(int x = 1; x <= w; x++){
			if(c[x][y] == 's') px[m] = x, py[m] = y;
			if(c[x][y] == 'e') px[m+1] = x, py[m+1] = y;
		}
	}
	
	for(int i = 0; i <= m+1; i++){
		bfs(px[i], py[i]);
		for(int j = 0; j <= m+1; j++) dist[i][j] = d[px[j]][py[j]];
	}
	
	int M = 1<<m;
	for(int i = 0; i < M; i++){
		for(int j = 0; j < m; j++){
			dp[i][j] = inf;
		}
	}
	for(int i = 0; i < m; i++) dp[1<<i][i] = dist[m][i];
	for(int i = 0; i < M; i++){
		for(int j = 0; j < m; j++){
			for(int k = 0; k < m; k++){
				if(i & (1<<k)) continue;
				dp[i|(1<<k)][k] = min(dp[i|(1<<k)][k], dp[i][j] + dist[j][k]);
			}
		}
	}
	
	for(int i = 1; i < M; i++) pop[i] = pop[i&(i-1)] + 1;
	int ans = inf;
	for(int i = 0; i < M; i++){
		if(pop[i] < k) continue;
		for(int j = 0; j < m; j++){
			ans = min(ans, dp[i][j] + dist[j][m+1]);
		}
	}
	if(ans > inf/2) cout << -1 << endl;
	else cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 94088
#include <stdio.h>

int zeinuki(int a) {
  return (int)((a+ 0.999f) / 1.08f);
}

int main() {
  int a, b, c;
  scanf("%d", &a);
  b = zeinuki(a);
  c = b * 1.08;
  if (a != c) printf(":(\n"); else printf("%d\n", b);
  return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <cstring>
using namespace std;
const int inf = 100000000;
int i,j;
int flag[1005][1005];
int a[1005][1005];

int main()
{
	int n;
	while (cin >> n)
	{
		if (n == 0) break;
		memset(flag, 0, sizeof(flag));
		for (i = 1; i <= n; i++)
		{
			for (j = 1; j <= n; j++)
			{
				cin >> a[i][j];
			}
		}
		for (i = 1; i <= n; i++)
		{
			int mmin = inf;
			int pmin = -1;
			for (j = 1; j <= n; j++)
			{
				if (a[i][j] < mmin)
				{
					pmin = j;
					mmin = a[i][j];
				}
			}
			for (j = 1; j <=n; j++)
			{
				if (a[i][j] == mmin)
				{
					flag[i][j] ++;
				}
			}
		}
		for (j = 1; j <= n; j++)
		{
			int mmax = -1;
			int pmax = -1;
			for (i = 1; i <= n; i++)
			{
				if (a[i][j] > mmax)
				{
					pmax = i;
					mmax = a[i][j];
				}
			}
			for (i = 1; i <= n; i++)
			{
				if (a[i][j] == mmax)
				{
					flag[i][j]++;
				}
			}
		}
		int px = -1, py = -1;
		for (i = 1; i <= n; i++)
		{
			for (j = 1; j <= n; j++)
			{
				if (flag[i][j] == 2)
				{
					px = i;
					py = j;
					break;
				}
			}
		}
		if (px == -1 && py == -1)
		{
			cout << 0 << endl;
		}
		else
		{
			cout << a[px][py] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int X = sc.nextInt();
    int c[] = new int[N];
    int a[][] = new int[N][M];
    
    for(int i = 0 ; i < N ; ++i){
      c[i] = sc.nextInt();
      for(int j = 0 ; j < M ; ++j){
        a[i][j] = sc.nextInt();
      }
    }
    int ans = 1000000000;
    
    for(int i = 1 ; i < (1<<N) ; ++i){
      int k[] = new int[M];
      int l = 0;
      for(int j = 0 ; j < N ; ++j){
        if((1&(i>>j))==1){
          l += c[j];
          for(int o = 0 ; o < M ; ++o){
            k[o] += a[j][o];
          }
        }
      }
      for(int j = 0 ; j < M ; ++j){
        if(k[j] < X) break;
        if(j == M-1) ans = Math.min(ans,l);
      }
    }
    if(ans == 1000000000) System.out.println(-1);
    else System.out.println(ans);
    
  }
}


Measured memory_bytes: 37344
#include <bits/stdc++.h>
#define FILES                    \
	ifstream cin( "input.txt" ); \
	ofstream cout( "input.txt" );
#define FAST                             \
	std::ios_base::sync_with_stdio( 0 ); \
	std::cin.tie( 0 );                   \
	std::cout.tie( 0 );
#define FIXED cout << fixed << setprecision( 20 )
#define pb push_back
#define eps 1e-9
#define mod 1000000007
#define int long long
using graph = std::vector<std::vector<int>>;
using pll = std::pair<int, int>;
using ll = long long;
namespace my {
	int max( int x ) {
		return x;
	}
	template<typename... Args>
	int max( int x, Args... args ) {
		int y = max( args... );
		return ( x < y ) ? y : x;
	}
	int min( int x ) {
		return x;
	}
	template<typename... Args>
	int min( int x, Args... args ) {
		int y = min( args... );
		return ( x < y ) ? x : y;
	}
	int max( std::vector<int>& t ) {
		int mx = -1e18;
		for( int i = 0; i < t.size(); i++ ) {
			mx = std::max( mx, t[i] );
		}
		return mx;
	}
	int min( std::vector<int>& t ) {
		int mn = 1e18;
		for( int i = 0; i < t.size(); i++ ) {
			mn = std::min( mn, t[i] );
		}
		return mn;
	}
}	// namespace my

void z_f( std::vector<int>& z, std::string& s ) {
	int l = 0, r = 0;
	for( int i = 1; i < s.size(); i++ ) {
		if( r >= i ) {
			z[i] = std::min( r - i + 1, z[i - l] );
		}
		int& x = z[i];
		while( i + x < s.size() && ( s[i + x] == s[x] ) ) {
			++x;
		}
		if( i + x - 1 > r ) {
			l = i;
			r = i + x - 1;
		}
	}
}
void solve() {
	int n, k;
	std::cin >> n >> k;
	std::vector<int> p( n + 1, 0 ), c( n + 1, 0 );
	for( int i = 1; i <= n; i++ ) {
		std::cin >> p[i];
	}
	for( int i = 1; i <= n; i++ ) {
		std::cin >> c[i];
	}
	int ans = -1e18;
	std::map<int, int> cycle, ves;
	for( int i = 1; i <= n; i++ ) {
		if( cycle[i] )
			continue;
		int y = i, dl = 0, cur_ans = 0;
		do {
			cur_ans += c[p[y]];
			y = p[y];
			dl++;
		} while( y != i );
		do {
			y = p[y];
			cycle[y] = dl;
			ves[y] = cur_ans;
		} while( y != i );
	}
	for( int num = 1; num <= n; num++ ) {
		int cur_ans = 0;
		int y = num;
		int rr = 0;
		if( ves[num] <= 0 ) {
			cur_ans = 0;
			rr = std::min( cycle[num], k );
		} else {
			if( k % cycle[num] != 0 ) {
				cur_ans = ( k / cycle[num] ) * ves[num];
				ans = std::max( ans, cur_ans );
				rr = k % cycle[num];
			} else {
				cur_ans = ( k / cycle[num] - 1 ) * ves[num];
				ans = std::max( ans, cur_ans );
				rr =  cycle[num];		
			}
		}
		for( int i = 0; i < rr; i++ ) {
			int dir_ans = c[p[y]];
			y = p[y];
			cur_ans += dir_ans;
			ans = std::max( ans, cur_ans );
		}
	}
	std::cout << ans << '\n';
}
main() {
	int t = 1;
	FAST;
	// std::cin >> t;
	while( t-- ) {
		solve();
	}
}


Measured memory_bytes: 4304
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const string EMP = " ";
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

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

  int ans = 0, now = 0;
  for(int i = 0; i < n; i++){
    if(a[i] > now){
      ans += a[i] - now;
    }
    now = a[i];
  }
  cout << ans << endl;
  return 0;
}


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

#define int long long
#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
using namespace std;

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

int H, W;

void clear(queue<pair<int, int>> &q)
{
    queue<pair<int, int>> empty;
    swap(q, empty);
}

int _hash(int a, int b)
{
    return (a << 10) + b;
}

signed main()
{

    cin >> H >> W;
    char A[H][W];
    int dis[H][W];

    rep(i, H)
    {
        rep(j, W)
        {
            cin >> A[i][j];
        }
    }

    queue<pair<int, int>> q;
    rep(i, H)
    {
        rep(j, W)
        {
            if (A[i][j] == '#')
            {
                q.push(mp(i, j));
                dis[i][j] = 0;
            }
            else
            {
                dis[i][j] = -1;
            }
        }
    }

    int c = q.size();

    while (!q.empty())
    {
        auto itr = q.front();
        q.pop();
        int f = itr.fst;
        int s = itr.sec;

        if (f - 1 >= 0)
        {
            if (dis[f - 1][s] == -1)
            {
                q.push(mp(f - 1, s));
                dis[f - 1][s] = dis[f][s] + 1;
            }
        }

        if (f + 1 < H)
        {
            if (dis[f + 1][s] == -1)
            {
                q.push(mp(f + 1, s));
                dis[f + 1][s] = dis[f][s] + 1;
            }
        }

        if (s - 1 >= 0)
        {
            if (dis[f][s - 1] == -1)
            {
                q.push(mp(f, s - 1));
                dis[f][s - 1] = dis[f][s] + 1;
            }
        }

        if (s + 1 < W)
        {
            if (dis[f][s + 1] == -1)
            {
                q.push(mp(f, s + 1));
                dis[f][s + 1] = dis[f][s] + 1;
            }
        }
    }

    int ans = 0;

    rep(i, H)
    {
        rep(j, W)
        {
            ans = max(ans, dis[i][j]);
        }
    }

    cout << ans << endl;

    return 0;
}


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

bool Get_is_palindrome(string s) {

    bool result = true;
    for (int i = 0; i < s.size() / 2; i++) {
        if (s[i] != s[s.size() - i - 1]) {
            result = false;
        }
    }
    return result;
}

int main()
{
    string s; cin >> s;
    
    int n = s.size();
    
    bool can = true;
    if (!Get_is_palindrome(s)) can = false;
    if (!Get_is_palindrome(s.substr(0, (n - 1) / 2))) can = false;
    if (!Get_is_palindrome(s.substr((n - 1) / 2 + 1))) can = false;

    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
/**********************************************
 * author : deepak nayan
 * file   : e:/Solutions/atcoder/abc082_a.cpp
 * time   : Wed Apr 29 23:08:05 2020
 * quest  : A - Round Up the Mean
 *********************************************/
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  cout << ceil(float(a + b) / 2) << "\n";
  return 0;
}


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

int main()
{
    int n;
    cin>>n;
    string a;
    set<string>b;
    for(int i=0; i<n; i++)
    {
        cin>>a;
        b.insert(a);
    }
    cout<<b.size()<<endl;
    return 0;
}
//-----------------------//
/*
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin>>n;
    string a;
    vector<string>b;
    for(int i=0; i<n; i++)
    {
        cin>>a;
        b.push_back(a);
    }
    sort(b.begin(),b.end());
    b.erase(unique(b.begin(),b.end()),b.end());

    cout<<b.size()<<endl;
}
*/
//------------------------------------------//
/*
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin>>n;
    string a;
    list<string>b;
    for(int i=0; i<n; i++)
    {
        cin>>a;
        b.push_back(a);
    }
    b.sort();
    b.unique();
    cout<<b.size()<<endl;
    return 0;
}
*/



Measured memory_bytes: 19260
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'
const int MOD = 1e9 + 7;

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

int dp[100005];
int s[100005];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, m;
	cin >> n >> m;
	int a[m];
	memset(s, 0, sizeof(s));
	rep(i, m) cin >> a[i], s[a[i]] = 1;
	memset(dp, 0, sizeof(dp));
	dp[0] = 1;
	repn(i, 0, n){
		repn(j, 1, 3){
			if(i + j <= n && !s[i + j]){
				dp[i + j] = (dp[i + j] + dp[i]) % MOD;
			}
		}
	}
	cout << dp[n] << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 1408
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#https://atcoder.jp/contests/agc017/tasks/agc017_a
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n,p=mii()
arr=limii()
even=0
odd=0
for i in arr:
    if i%2==0:
        even+=1
    else:
        odd+=1

ans=0

if p==0:
    for i in range(0,even+1):
        for j in range(0,odd+1,2):
            ans+=cmb(even,i)*cmb(odd,j)
else:
    for i in range(1,odd+1,2):
        for j in range(0,even+1):
            ans+=cmb(odd,i)*cmb(even,j)
print(ans)

Measured memory_bytes: 63980
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
#define LL long long
using namespace std;
const int N=1e5+10;
int n,k,a[N],b[N];
LL ans;
inline int read(){
	char ch=getchar(); int x=0, f=1;
	while(ch<'0' || ch>'9') {if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
	return x*f;}
template<typename I>inline I mx(const I a,const I b){return a>b ? a : b;}
int main()
{
	//freopen("IntegerotS.in","r",stdin);
	//freopen(".out","w",stdout);
	n=read(); k=read();
	for(RG int i=1;i<=n;i++)
	{
		a[i]=read(); b[i]=read();
		if((a[i]&k)==a[i]) ans+=b[i];
	}
	for(RG int i=0;i<=30;i++)
	{
		if(((1<<i)&k)==0) continue;
		int tt=(k^(1<<i))|((1<<i)-1); LL re=0;
		for(RG int i=1;i<=n;i++) if((a[i]&tt)==a[i]) re+=b[i];
		ans=mx(ans,re);
	}
	printf("%lld\n",ans);
	//fclose(stdin); fclose(stdout);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <boost/range/adaptor/indexed.hpp>
using namespace std;

#define repi(i, a, b) for(int i = (int)(a); i < int(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

template <typename T>
std::ostream &operator<<(std::ostream &ostr, const std::vector<T> &v) {
  for (const auto &i : v | boost::adaptors::indexed())
    ostr << (i.index() > 0 ? " " : "") << i.value();
  return ostr;
}

inline void Main() {
  // code
  int n, y;
  cin >> n >> y;

  int c;
  rep(a, n+1) {
    rep(b, n+1-a) {
      c = n - a - b;
      if(10000*a+5000*b+1000*c==y) {
        cout << a << " " << b << " " << c << endl;
        return;
      }
    }
  }

  cout << "-1 -1 -1" << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main (){
  int A,B;
  cin >> A >> B;
  bool kiyonaga = true;
  for(int i=10*B;i<20*B;i++){
    if(i*2/25==A&&i/10==B){
      cout << i << endl;
      kiyonaga = false;
      break;
    }
  }
  if(kiyonaga)
    cout << -1 << endl;
}

Measured memory_bytes: 256
(defvar +inf+ most-positive-fixnum)

(defun most-difficult-problem-index (d bits)
  (loop for i from (1- d) downto 0
        if (not (logbitp i bits))
        do (return i)))

(defun bits-problem-counts (d bits problems)
  (loop for i from 0 to d
        if (logbitp i bits)
        sum (car (nth i problems))))

(defun solve (d g problems)
  (loop for bits from 0 below (expt 2 d)
        for points = (loop for i from 0 below d
                           if (logbitp i bits)
                           sum (destructuring-bind (count . bonus)
                                   (nth i problems)
                                 (+ bonus (* count (1+ i) 100))))
        minimize
        (cond
          ((<= g points)
           (bits-problem-counts d bits problems))
          ((most-difficult-problem-index d bits)
           (let ((j (most-difficult-problem-index d bits)))
             (let ((extra-counts (ceiling (- g points)
                                          (* 100 (1+ j)))))
               (if (<= extra-counts (car (nth j problems)))
                   (+ (bits-problem-counts d bits problems)
                      extra-counts)
                   +inf+))))
          (t +inf+))))

#-swank
(let* ((d (read))
       (g (read))
       (problems (loop repeat d
                       collect (cons (read) (read)))))
  (format t "~A~%" (solve d g problems)))


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

//2で割り切れる回数を求める
int f(int x) {
    int res = 0;

    while (x % 2 == 0) {
        x /= 2;
        res++;
    }

    return res;
}

int main() {

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

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

    //2で割る
    for (int i = 0; i < n; ++i) {
        if (a[i] % 2 == 1) {
            cout << 0 << endl;
            return 0;
        }
        a[i] /= 2;
    }

    int t = f(a[0]); //2で割り切れる回数
    for (int i = 0; i < n; ++i) {
        //2で割り切れる回数が一緒でないとダメ
        if (f(a[i]) != t) {
            cout << 0 << endl;
            return 0;
        }

        a[i] >>= t; //a[i] /= 2^t
    }

    m >>= t;

    ll lcm = 1;
    for (int i = 0; i < n; ++i) {
        lcm = lcm / __gcd(lcm, (ll)a[i]) * a[i];

        //lcmはかなり大きい数値になる可能性がある
        if (lcm > (ll)m) {
            cout << 0 << endl;
            return 0;
        }
    }

    m /= lcm;
    int ans = (m + 1) / 2;

    cout << ans << endl;
}

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

int a,b,k,x,z;


int main(){
    scanf("%d %d %d",&a,&b,&k);
    for(int i=0;i<k;i++){
        
        if(i%2){x=b;z=a;}
        else {x=a;z=b;}
        
        if(x%2){
            x--;
            
        }
        
        x/=2;
        z+=x;
        
        if(i%2){b=x;a=z;}
        else {a=x;b=z;}
    }
    printf("%d %d\n",a,b);
}

Measured memory_bytes: 256
/**
 * @author: Mackenzie
**/
#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int n;
    cin>>n;
    vector<pii> v(n);
    forn(i,n)cin>>v[i].F,v[i].S=i;
    sort(all(v));
    forn(i,n)cout<<v[i].S+1<<" ";
    cout<<endl;
    return 0;
}

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

int main(){
  int n,m;
  vector<string> Amap;
  vector<string> Bmap;
  cin >> n >> m;
  for(int i=0; i<n; ++i){
    string tmp;
    cin >> tmp;
    Amap.push_back(tmp);
  }
  
  for(int i=0; i<n; ++i){
    string tmp;
    cin >> tmp;
    Bmap.push_back(tmp);
  }
  int sum = 0;
  for(int i=0; i<n; ++i){
    for(int j=0; j<m; ++j){
      if(Amap[i][j] != Bmap[i][j])++sum;
    }
  }
  cout << sum << endl;
}



Measured memory_bytes: 11124
#include <bits/stdc++.h>
#define FOR(i,a,b)  for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n)    FOR(i,0,n)
#define RER(i,n)    FOR(i,0,(n+1))
#define pb          push_back
#define mp(a,b)     make_pair((a),(b))
#define mset(m,v)   memset(m,v,sizeof(m))
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pair<ll, ll> > vpll;
typedef vector<string> vs;
typedef long double ld;
const double EPS    = 1e-10;
const int INF       = 1e+9;
const double PI     = acos(-1);


auto main() -> int
{
    int r, g, b;
    cin >> r >> g >> b;

    cout << (((r*100 + g*10 + b)%4 ==0) ? "YES" : "NO") << endl;

    return 0;
}



Measured memory_bytes: 256
/*
17/10/2017
*/
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
bool ok=1;
int mx=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
if(mx-a[i]>=2)
{
ok=0;
}
mx=max(mx,a[i]);
}
cout<<(ok ? "Yes" : "No")<<endl;
}

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

int main(){
    int day;
    int co;
    int to;

    to = 0;

    cin >> day >> co;
vector<int> data(co);
for (int i = 0; i < co; i++){
    cin >> data.at(i);
}
for (int i = 0; i < co; i++){
   to += data.at(i);
}
if ((day - to) < 0){
    cout << -1 << endl;
}

else {
    cout << day - to << endl;
}
}

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

int main() {
  string S;
  cin>>S;
  if(S=="Sunny")cout<<"Cloudy"<<endl;
  if(S=="Cloudy")cout<<"Rainy"<<endl;
  if(S=="Rainy")cout<<"Sunny"<<endl;
  return 0;
}

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

using namespace std;

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

    int ans;

    if(K == 1){
        cout << 0 << endl;
    }else{
        ans = N - K;
        cout << ans << endl;
    }    
}

Measured memory_bytes: 256
from collections import defaultdict as dd

n, mm = [int(i) for i in input().split()]
c = 0
A = []

m = dd(tuple)

for i in range(n):
    B = input()
    for j in range(mm):
        m[(i, j)]=c
        c+=1
    A.append([i=='#' for i in B])

par = [i for i in range(c)]

def find(a):
    if par[a] == a:
        return a
    par[a] = find(par[a])
    return par[a]

def unite(a, b):
    if a < b:
        a, b = b, a
    par[find(a)] = find(b)

def issafe(x,y):
    return x>=0 and x<n and y>=0 and y<mm

for i in range(n):
    for j in range(mm):
        dx = [[-1, 0], [0, 1], [0, -1], [1, 0]]
        for k in range(len(dx)):
            if issafe(i+dx[k][0], j+dx[k][1]) and A[i][j] != A[i+dx[k][0]][j+dx[k][1]]:
                unite(m[(i, j)], m[(i+dx[k][0], j+dx[k][1])])
                
bl = [0]*c
wh = [0]*c

for i in range(n):
    for j in range(mm):
        if A[i][j] == 1:
            bl[find(m[i, j])]+=1
        else:
            wh[find(m[i, j])]+=1

ans = 0
for i in range(c):
    ans += bl[i]*wh[i]

print(ans)


Measured memory_bytes: 36848
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws Exception {
		new Main().run();
	}
	
	void run() {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int R=sc.nextInt();
		if(N>=10) {
			System.out.println(R);
		}else {
			System.out.println(R+100*(10-N));
		}
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
	
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<ll>>;
using P = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef vector<ll> vi;
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  ll n;
  cin >> n;
  vi p(n);
  rep(i,n){
    cin >> p[i];
  }
  ll count = 0;
  for (ll i = 1; i < n - 1; i++){
    if(p[i]>p[i-1]&&p[i]<p[i+1]){
      count++;
    }
    else if(p[i]<p[i-1]&&p[i]>p[i+1]){
      count++;
    }
  }
  print(count);
}

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1<<29;
/****** define constant end ********/

/****** define variable start ******/
vector< vector<ll> > a;
ll n;
vl b;
/******* define variable end *******/
ll solve() {
	vector< vector<bool> > ans_vec(3, vector<bool>(3));
	REP(i, 3){
		REP(j, 3){
			ans_vec[i][j] = false;
		}
	}
	vector< vector<ll> > a(3, vector<ll>(3));
	REP(i, 3){
		REP(j, 3){
			cin >> a[i][j];
		}
	}
	cin >> n;
	b.resize(n);
	REP(i, n){
		cin >> b[i];
	}
	REP(i, n){
		REP(j, 3){
			REP(k, 3){
				if(b[i] == a[j][k]){
					ans_vec[j][k] = true;
				}
			}
		}
	}
	REP(i, 3){
		if(ans_vec[i][0] && ans_vec[i][1] && ans_vec[i][2]){
			cout << "Yes" << endl;
			return 0;
		}
        if (ans_vec[0][i] && ans_vec[1][i] && ans_vec[2][i]) {
            cout << "Yes" << endl;
            return 0;
            }
        }
	if(ans_vec[0][0] && ans_vec[1][1] && ans_vec[2][2]){
		cout << "Yes" << endl;
		return 0;
	}
	if(ans_vec[2][0] && ans_vec[1][1] && ans_vec[0][2]){
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}
int main(){
    //clock_t start = clock();
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll end_solve = solve();
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */
    
    return (int)end_solve;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int main(void){
	int x,y,z,w;
	scanf("%d%d%d%d",&x,&y,&z,&w);
	int u,v,s,t;
	u = z - (w-y);
	v = y + w-y + z-x;
	s = u+x-z;
	t = v+y-w;
	printf("%d %d %d %d",u,v,s,t);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5, inf = 1e9 + 7;
long long n, m, v, w, dp[N];
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
    {
        cin >> w >> v;
        for (int j = m; j >= w; --j)
            dp[j] = max(dp[j], dp[j - w] + v);
    }
    cout << dp[m];
}

Measured memory_bytes: 4340
a = gets.chomp.to_i
b = gets.chomp.to_i
c = gets.chomp.to_i
d = gets.chomp.to_i
e = gets.chomp.to_i

A = [a, b, c, d, e]

# 1桁目を切り上げして合計→合計から1桁目が一番大きい値をマイナスする
p A.map { |a| (a + 9) / 10 * 10 }.inject(:+) - A.map { |a| (a + 9) / 10 * 10 - a }.max


Measured memory_bytes: 1788
N, K = map(int, input().split())
mod = int(1e9+7)

left = 0
right = 0
for i in range(K):
    left += i
    right += N-i
ans = 0
for i in range(K, N+2):
    ans += right -left +1
    ans %= mod
    left += i
    right += N-i
print(ans)

Measured memory_bytes: 63940
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
  int n, k;
  string s;
  cin >> n >> k >> s;
  k--;
  s[k] += 32;

  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
def mergesort(l):
    n = len(l)
    if(n == 0):
        return 0
    elif(n == 1):
        return l
    elif(n <= 2):
        if(l[0] > l[1]):
            return [l[1],l[0]]
        else:
            return l
    else:
        tmp1 = mergesort(l[:n//2])
        tmp2 = mergesort(l[n//2:])
        x = n//2
        y = n-x
        l = []
        for i in range(n):
            if(tmp1[-x] < tmp2[-y]):
                l.append(tmp1[-x])
                x -= 1
            else:
                l.append(tmp2[-y])
                y -= 1
            if(x*y == 0):
                if(x == 0):
                    l += tmp2[-y:]
                else:
                    l += tmp1[-x:]
                break
        return l
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = []
c = []
s,t,u = 0,0,0
for i in range(n):
    if(a[i] < 0):
        t += 1
        c.append(a[i])
    else:
        s += 1
        b.append(a[i])
b = mergesort(b)
c = mergesort(c)
p = 1
if(s == 0 and k%2 == 1):
    for i in range(1,k+1):
        p *= c[-i]
        p %= 1000000007
else:
    if(n == k):
        for i in range(n):
            p *= a[i]
            p %= 1000000007
    else:
        if(k%2 == 1):
            s-=1
            p = b[s]
            k -= 1
        while(k>0):
            if(s >= 2 and t >= u+2):
                if(b[s-1]*b[s-2] > c[u]*c[u+1]):
                    p *= b[s-1]*b[s-2]
                    p %= 1000000007
                    s -= 2
                else:
                    p *= c[u]*c[u+1]
                    p %= 1000000007
                    u += 2
            elif(s <= 1):
                p *= c[u]*c[u+1]
                p %= 1000000007
                u += 2
            else:
                p *= b[s-1]*b[s-2]
                p %= 1000000007
                s -= 2
            k -= 2
print(p)

Measured memory_bytes: 129076
#include<iostream>
using namespace std;
int a,b,c;
string check()
{
    if((b>12||b<1)&&(a>12||a<1))return "NA";
    if(!((b>12||b<1)||(a>12||a<1)))return "AMBIGUOUS";
    if(b>=1&&b<=12)return "MMYY";
    if(a>=1&&a<=12)return "YYMM";
}
int main()
{
    cin>>a;
    b=a/100,c=a%100;
    a=c;
    cout<<check()<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<complex>
#include<vector>
#include<algorithm>
#include<functional>
#include<array>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	int a, b;
	cin >> a >> b;
	if (a + b == 15) {
		cout << "+" << endl; return 0;
	}
	if (a*b == 15) { cout << "*" << endl; return 0; }
	cout << "x" << endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <array>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;
const int  INF=10e7;

typedef  pair<int,int> P;


int main(){
     string s;
     cin>>s;
     bool a[26]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
     bool ans=1;
     for(int i=0;i<s.size();++i){
          int nn=s[i]-'a';
          a[nn]^=1;
     }
     
     for(int i=0;i<26;++i){
          if(a[i]){ans=false;
          break;
          }

     }
     if(ans)cout<<"Yes"<<endl;
     else cout<<"No"<<endl;

}


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


int main() {
	int n;
	cin >> n;
	int min_count = INT_MAX;
	for (int i = 0; i < n; i++) {
		int num;
		cin >> num;
		int count = 0;
		while (num % 2 == 0) {
			count++;
			num /= 2;
		}
		if (count < min_count) min_count = count;
	}
	cout << min_count << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n = int(input())
l = []
for _ in range(n):
	l.append(int(input()))
p = sorted(l)
fm = p[-1]
sm = p[-2]
if fm == sm:
	for _ in range(n):
		print(fm)
else:
	for i in range(n):
		if l[i] == fm:
			print(sm)
		else:
			print(fm)

Measured memory_bytes: 59600
import collections

n = int(input())
s = [input() for i in range(n)]
c = collections.Counter(s)
z = c.most_common()[0][1]
ans = []
for i in c.most_common():
    if i[1] == z:
        ans.append(i[0])
    else:
        break
ans.sort()
for j in ans:
    print(j)

Measured memory_bytes: 122192
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define lld long long
#define llu unsigned long long

using namespace std;
int main()
{
	lld i,k,n,s,t;
	scanf("%lld%lld",&n,&k);
	s=0;
	for(i=k+1;i<=n;i++)
	{
		t=(n%i-k+1);
		//cout<<t<<endl;
		s+=(n/i)*(i-k);
		if(t>0)
			s+=t;
	}
	if(k==0)
		s=n*n;
	printf("%lld\n",s);
	return 0;
}

Measured memory_bytes: 256
from itertools import combinations

N = int(input())
L = list(map(int, input().split()))

ans = 0
for i, j, k in combinations(range(N),3):
  ell = sorted([L[i], L[j], L[k]])
  if ell[2] < ell[0] + ell[1] and len(set(ell)) == 3:
    ans += 1
print(ans)

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

int main(){
	string str;
	string s[8];
	s[0] = "*****     ";
	s[1] = "     *****";
	s[2] = "==========";
	s[3] = " **** ****";
	s[4] = "* **** ***";
	s[5] = "** **** **";
	s[6] = "*** **** *";
	s[7] = "**** **** ";
	bool flag = false;
	while(cin >> str){
		if(flag) cout << endl;
		int len = str.size();
		int num[5]={0};
		int cou=0;
		for(int i=5-len;i<5;i++){
			string tmp = "";
			tmp += str[cou];
			istringstream ss(tmp);
			ss >> num[i];
			cou++;
		}
		for(int i=0;i<8;i++){
			for(int j=0;j<5;j++){
				cout << s[i][num[j]];
			}
			cout << endl;
		}
		flag = true;
	}
}

Measured memory_bytes: 1212
#include<stdio.h>
int main()
{
    int h,w,n,count=0;
    scanf("%d%d%d",&h,&w,&n);
    int max=h;
    max=(h>w)?h:w;
    for(int i=1;;i++)
    {
        if(max*i>=n)
        {
            printf("%d",i);
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 128
#include <vector>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <sstream>
#include <map>
#include <unordered_map>
#include <ctime>
#include <cassert>
#include <cstring>
#include <sys/time.h>
#include <stdlib.h>
using namespace std;

int main(int argc, char *argv[]){
  int n;
  cin >> n;
  vector<int> a;
  for(int i=0;i<n;i++){
    int ai;
    cin >> ai;
    a.push_back(ai);
  }
  long long int sum = 0;
  for(int i=0;i<n;i++){
    sum += a[i];
  }
  long long int first = 0;
  long long int second = 0;
  long long int diff;
  long long int min = sum;
  for(int i=0;i<n;i++){
    first += a[i];
    second = sum - first;
    diff = abs(second-first);
    if(min>diff){
      min = diff;
    }
  }
  cout << min << endl;
  return 0;
}


Measured memory_bytes: 1400
from operator import itemgetter
N,M = map(int,input().split())
p = [0] * M
S = [0] * M
BUF = [[0 for i in range(2)] for i in range(M)]

for i in range(M) :
    p[i],S[i] = map(str,input().split())
    p[i] = int(p[i])
    BUF[i][0] = p[i]
    BUF[i][1] = S[i]
BUF_new = sorted(BUF,key=itemgetter(0))
#print(BUF_new)

Flag = False
buf_goal = 0
buf_pena = 0
buf = -1
buf_2 = 0
buf_3 = -1

for i in range(M) : #余分な情報削除
    if Flag == True :
        if BUF_new[i][0] == buf :
            #BUF_new.pop(i)
            BUF_new[i][1] = 'NULL'
        else :
            Flag = False
            buf = -1
    if Flag == False :
        if BUF_new[i][1] == 'AC' :
            Flag = True
            buf = BUF_new[i][0]

for i in range(M) :
    if BUF_new[i][1] == 'WA' :
        if buf_3 == BUF_new[i][0] :
            buf_2 += 1
        else :
            buf_2 = 0
            buf_2 += 1
        buf_3 = BUF_new[i][0]

    if BUF_new[i][1] == 'AC' :
        if buf_3 == BUF_new[i][0] :
            buf_pena += buf_2
            buf_goal += 1
            buf_2 = 0
            buf_3 = -1
        else :
            buf_goal += 1
            buf_2 = 0
            buf_3 = -1
#print(BUF_new)
print(buf_goal,buf_pena)

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

using namespace std;

int main() {

	int n;
	cin >> n;

	vector<int> a(n+2, 0);

	a[0] = 0;
	int total = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		total += abs(a[i] - a[i - 1]);
	}
	a[n+1] = 0;
	total += abs(a[n+1] - a[n]);

	for (int i = 1; i < n+1; i++) {
		cout << total - abs(a[i] - a[i - 1]) - abs(a[i+1] - a[i]) + abs(a[i+1] - a[i - 1]) << endl;
	}

}

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

#include <bits/stdc++.h>
//#include "../library/dsu.hpp"
//#include "../library/fenwicktree.hpp"
//#include "../library/modint.hpp"
//#include "../library/segtree.hpp"
//#include "../library/string.hpp"
//#include "../library/math.hpp"

using namespace std;
//using namespace atcoder;

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

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

void ANot(std::istream& in, std::ostream& out) {
    int x;
    in >> x;
    out << 1 - x << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    ANot(in, out);
    return 0;
}

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

inline int read ( )  {
	register int x, c ;
	while ( isspace ( c = getchar ( ) ) ) ;
	for ( x = -48 + c ; isdigit ( c = getchar ( ) ) ; ( x *= 10 ) += c - 48 ) ;
	return x ;
}

# define N 200010

int a [N], b [N] ;

int main ( )  {
	int n ( read ( ) ) ;
	for ( int i = 1 ; i <= n ; ++ i )  *(a + i) = read ( ) ;
	for ( int i = 1 ; i <= n ; ++ i )  *(b + i) = read ( ) ;

	int ans ( 0 ) ;
	static int ta [N], tb [N] ;
	for ( int i = 0 ; i < 29 ; ++ i )  {
		const int T = 1 << i ;
		const int module = ( ( 1 << ( i + 1 ) ) - 1 ) ;
		for ( int i = 1 ; i <= n ; ++ i )  ta [i] = a [i] & module, tb [i] = b [i] & module ;
		std :: sort ( tb + 1, tb + 1 + n ) ;
		int cnt ( 0 ) ;
		for ( int i = 1 ; i <= n ; ++ i )  {
			int p1 = std :: lower_bound ( tb + 1, tb + 1 + n, T - ta [i] ) - tb ;
			int p2 = std :: lower_bound ( tb + 1, tb + 1 + n, T * 2 - ta [i] ) - tb ;
			int p3 = std :: lower_bound ( tb + 1, tb + 1 + n, T * 3 - ta [i] ) - tb ;
			int p4 = std :: lower_bound ( tb + 1, tb + 1 + n, T * 4 - ta [i] ) - tb ;
			cnt += ( p2 - p1 ) + ( p4 - p3 ) ;
		}
		if ( cnt & 1 )  ans += T ;
	}
	return ! printf ( "%d\n", ans ) ;
}


Measured memory_bytes: 3328
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 100010
using namespace std;
typedef long long ll;
int n,m;
struct node{
	int x;
	node *nxt;	
}edge[MAXN*2];
node *head[MAXN],*ncnt=edge;
void add_edge(int u,int v){
	++ncnt;
	ncnt->x=v;
	ncnt->nxt=head[u];
	head[u]=ncnt;
}
int dep[MAXN],ods[MAXN],cirlen,sum[MAXN],tot,cu,cv;
bool vis[MAXN];
ll ans;
void dfs(int x,int f){
	vis[x]=1;
	dep[x]=dep[f]^1;
	if(dep[x]==0)
		sum[x]=1;
	else
		sum[x]=-1;
	tot+=sum[x];
	for(node *v=head[x];v!=NULL;v=v->nxt){
		int u=v->x;
		if(u==f)
			continue;
		if(vis[u]==1){
			cirlen=dep[u]^dep[x]^1;
			cu=x;
			cv=u;
			continue;
		}
		dfs(u,x);
	}
}
void solve(int x,int f){
	vis[x]=1;
	for(node *v=head[x];v!=NULL;v=v->nxt){
		int u=v->x;
		if(u==f||vis[u]==1)
			continue;
		solve(u,x);
		ods[x]+=ods[u];
		sum[x]+=sum[u];
	}
}
int A[MAXN],cnt;
int main(){
	SF("%d%d",&n,&m);
	int u,v;
	for(int i=1;i<=m;i++){
		SF("%d%d",&u,&v);
		add_edge(u,v);
		add_edge(v,u);
	}
	dep[0]=1;
	dfs(1,0);
	if(n==m+1){
		if(tot!=0){
			PF("-1");
			return 0;	
		}
	}
	else{
		if(cirlen==1){
			if(tot%2!=0){
				PF("-1");
				return 0;
			}
			sum[cu]-=tot/2;
			sum[cv]-=tot/2;
			ans+=abs(tot/2);
		}
		else{
			if(tot!=0){
				PF("-1");
				return 0;
			}
			ods[cu]=1;
			ods[cv]=-1;
		}
	}
	memset(vis,0,sizeof vis);
	solve(1,0);
	for(int i=1;i<=n;i++){
		if(ods[i]==0)
			ans+=abs(sum[i]);
		else{
			if(ods[i]==1)
				sum[i]=-sum[i];
			A[++cnt]=sum[i];
		}
	}
	if(cirlen==0&&cu!=0){
		A[++cnt]=0;//LCA of cu and cv
		sort(A+1,A+1+cnt);
		ll mid=A[(cnt+1)/2];
		for(int i=1;i<=cnt;i++)
			ans+=abs(A[i]-mid);
	}
	PF("%lld",ans);
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
	int k;
	cin>>k;
	if(k%2==1){
			cout<<k/2*(k/2+1)<<endl;
			}
	else cout<<k/2*k/2<<endl;
		
					return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<iomanip>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<double,double>P;

ll Combination(int n, int r){
        ll num = 1;
        for(int i = 1; i <= r; i++){
            num = num * (n - i + 1) / i;
        }
        return num;
    }
int main()
{
    int n,p;
    cin>>n>>p;
    vector<int> a(n);
    rep(i,n)
    {
        cin>>a[i];
    }
    int oddcount=0;
    rep(i,n)
    {
        if(a[i]%2==1)
        {
            oddcount++;
        }
    }
    ll oddc=0;
    ll nc=0;
    if(p==0)
    {
        
        int oddnum=0;
        while(oddnum<=oddcount)
        {
            oddc+=Combination(oddcount,oddnum);
            oddnum+=2;
        }
        
    }
    else
    {
        int oddnum=1;
        while(oddnum<=oddcount)
        {
            oddc+=Combination(oddcount,oddnum);
            oddnum+=2;
        }
        
    }
    if((n-oddcount)%2==1)
        {
            for(int i=0;i<=(n-oddcount)/2;i++)
            {
                nc+=Combination(n-oddcount,i);
            }
            nc*=2;
        }
        else
        {
            for(int i=0;i<(n-oddcount)/2;i++)
            {
                nc+=Combination(n-oddcount,i);
            }
            nc*=2;
            nc+=Combination(n-oddcount,(n-oddcount)/2);
        }

    cout<<nc*oddc<<endl;
    
}

Measured memory_bytes: 256
#define pi 3.14159265358979323846
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <numeric>
#include <algorithm>
//#include <iomanip> : 表示桁数

using namespace std;

int N;

int main() {
	cin >> N;
	cout << ceil(N/2.0)-1 << endl;
	return 0;
}

Measured memory_bytes: 256
// abc075_d
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    ll N, K;
    cin >> N >> K;
    vector<ll> X(N), Y(N);

    REP(i, N) cin >> X[i] >> Y[i];

    auto orig_x = X;
    auto orig_y = Y;

    sort(ALL(X));
    sort(ALL(Y));

    ll ans = (ll)1e20;
    REP(xi, N-1) REPN(xj, xi+1, N) REP(yi, N-1) REPN(yj, yi+1, N){

        ll l = X[xi];
        ll r = X[xj];
        ll u = Y[yi];
        ll d = Y[yj];

        ll cnt = 0;
        REP(k, N){
            if (l <= orig_x[k] && orig_x[k] <= r && u <= orig_y[k] && orig_y[k] <= d) cnt++;
        }

        if (cnt >= K){
            ll area = (r - l) * (d - u);
            ans = min(ans, area);
        }
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>

using namespace std;

int sq(int x) { return x * x; }

struct Circle {
	int x, y, r, c;
	int tops;
	Circle (int _x, int _y, int _r, int _c) : x(_x), y(_y), r(_r), c(_c) {}
};

bool CC(const Circle& c1, const Circle& c2) {
	if (sq(c1.x - c2.x) + sq(c1.y - c2.y) < sq(c1.r + c2.r)) return true;
	return false;
}

int n;
vector<Circle> cs;

int ans;
bool memo[1 << 25];

void rec(int cur) {
	if (memo[cur]) return;
	
	int ret = __builtin_popcount(cur);	// 現在取り除いた個数
	ans = max(ans, ret);
	
	int rmbit = ~cur;	// bit反転をとる
	
	// 今取り除ける円盤を見つける
	for (int i = 0; i < n; i++) {
		if (cur >> i & 1) continue;	// すでにとりのぞかれている
		
		int topsi = cs[i].tops;
		if ( (topsi & rmbit) != 0) continue;
		
		// i番目の円盤は現在のこっている円盤によらずに取り除ける
		for (int j = i + 1; j < n; j++) {
			if (cur >> j & 1) continue;	// すでにとりのぞかれている
			
			int topsj = cs[j].tops;
			if ((topsj & rmbit) != 0) continue;
			
			// j番目の円盤も現在のこっている円盤によらずに取り除ける
			
			// 同じ色なら取り除ける
			if (cs[i].c != cs[j].c) continue;
			
			// i と j を取り除いた場合について再帰
			int nxt = cur | (1 << i);
			nxt |= 1 << j;
			rec(nxt);
		}
	}
	
	memo[cur] = true;
}

int main() {
	while (1) {
		cin >> n; if (n == 0) break;
		
		cs.clear();
		for (int i = 0; i < n; i++) {
			int x, y, r, c; cin >> x >> y >> r >> c;
			cs.push_back(Circle(x, y, r, c));
		}
		
		// 各円盤に対して、どの円盤が取り除かていればその円盤をとりだせるかを入れる
		// 取り除かなければならない円盤にbitをたてる
		for (int i = n - 1; i >= 0; i--) {
			int tops = 0;
			for (int j = i - 1; j >= 0; j--) {
				if (CC(cs[i], cs[j])) {
					tops |= 1 << j;
				}
			}
			cs[i].tops = tops;
		}
		
		// すべての円盤が残っている状態から開始		
		memset(memo, 0, sizeof(memo));
		ans = 0;
		rec(0);
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 33980
#include<bits/stdc++.h>
#define maxn 100010
using namespace std;
int n;
long long t[maxn];
long long c,k;
long long last;
int main()
{
    scanf("%d%lld%lld",&n,&c,&k);
    for(int i=1;i<=n;i++)scanf("%lld",&t[i]);
    sort(t+1,t+n+1);
    int cnt=1;
    last=t[1];
    int ans=1;
    for(int i=2;i<=n;i++)
    {
        if(last<=t[i]&&t[i]<=last+k)
        {
            if(cnt<c)cnt++;
            else {last=t[i];cnt=1;ans++;}
        }
        else {
            last=t[i];
            cnt=1;
            ans++;
        }
    }
    printf("%d\n",ans);
   return 0;
}

Measured memory_bytes: 1024