akhauriyash/Code-Regression huggingface dataset:
function Main(input) {
  input = input.split("\n");
  tmp = input[0].split(" ");
  A = Number(tmp[0]);
  B = Number(tmp[1]);
  if(A%2!=B%2){
    console.log("IMPOSSIBLE");
  }else{
    console.log((A+B)/2);
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<map>
#include<iomanip>
#include<limits>
#include<queue>
#include<set>
#include<cstdio>
#include<climits>
#include<cstring>

using namespace std;

int divisor(int n){
	int cnt = 0;

	while(n%2 == 0){
		n/=2;
		cnt++;
	}

	return cnt;
}

int main(){

   int N;
   cin >> N;

   int ans = 0;
   while(N--){
	   int a;
	   cin >> a;
	   if(a%2 == 0){
	    ans += divisor(a);
	   }
   }

	cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
# ARC058D - いろはちゃんとマス目 / Iroha and a Grid (ABC042D)
def get_fact(lim):
    # compute a toble of factorials (1-idx)
    fact = [1] * (lim + 1)
    x = 1
    for i in range(1, lim + 1):
        x = (x * i) % MOD
        fact[i] = x
    return fact

def get_inv(lim):
    # compute a toble of inverse factorials (1-idx)
    inv = [1] * (lim + 1)
    inv[lim] = pow(fact[lim], MOD - 2, MOD)
    x = inv[lim]
    for i in range(lim - 1, 0, -1):
        x = (x * (i + 1)) % MOD
        inv[i] = x
    return inv

def comb(n: int, r: int) -> int:
    # compute nCr (n! / r!(n - r)!)
    return fact[n] * inv[n - r] * inv[r]


def main():
    global MOD, fact, inv
    H, W, A, B = tuple(map(int, input().split()))
    MOD = 10 ** 9 + 7
    fact = get_fact(H + W)
    inv = get_inv(H + W)
    ans = 0
    for i in range(B, W):
        ans += comb(i + H - A - 1, i) * comb(W - i - 1 + A - 1, A - 1)
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 18804
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;

int main() {

	int d, t, s;

	cin >> d;
	cin >> t;
	cin >> s;

	if (t * s >= d )cout << "Yes";
	else cout << "No";

	return 0;
}


Measured memory_bytes: 3632
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf,comb
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

h, w, a, b = MAP()

for i in range(h+1):
    for j in range(w+1):
        if a*i + (w-a)*(h-i) == b*j + (h-b)*(w-j):
            aa = i
            bb = j
            break
    else:
        continue
    break

s = [[0]*w for i in range(h)]
sum = [0]*w

for i in range(h):
    tmp = 0
    for j in range(w):
        if ( i < aa and tmp < a ) or ( i >= aa and tmp < w-a ):
            if ( j < bb and sum[j] < b ) or ( j >= bb and sum[j] < h-b ):
               s[i][j] = 1
               tmp += 1
               sum[j] += 1

for i in range(h):
    print(*s[i][:], sep="")

Measured memory_bytes: 18952
N=int(input())
p=list(map(int,input().split()))
temp=1
ans=0
for i in range(N):
    if p[i]==(i+1):
        temp+=1
    else:
        if temp==1:
            pass
        else:
            ans+=temp//2
        temp=1
ans+=temp//2

print(ans)


Measured memory_bytes: 20564
#include<bits/stdc++.h>
using namespace std;
const int MAX = 1e9+5;
signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n,c=1,ans=1;cin>>n;
  vector<int> a(n),b(100001,0);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  for(int j=0;j<n-1;j++){
    if(a[j]==a[j+1]){c++;}
    else{b[a[j]]=c;c=1;}
  }
  b[a[n-1]]=c;
  for(int i=1;i<100001;i++){
    ans=max(ans,b[i-1]+b[i]+b[i+1]);
  }
  cout<<ans;
}

Measured memory_bytes: 1024
#include <stdio.h>
void merge(int,int,int);
void sort(int,int);
int m[500000];
int a = 0;
main()
{
  int i,n;
  scanf("%d",&n);
  for(i=0;i<n;i++)
   {
    scanf("%d",&m[i]);
   }
  sort(0,n);
  for(i=0;i<n;i++)
   {
    printf("%d",m[i]);
    if(i < n-1)
      printf(" ");
   }
  printf("\n");
  printf("%d\n",a);
  return 0;
}
 
void merge(int left,int mid,int right)
  {
  int i,j,k, g = mid - left,h = right - mid;
  int L[g],R[h];
  for(i=0;i<g;i++){
    L[i]=m[left + i];
  }
 
  for(i=0;i<h;i++){
    R[i]=m[mid + i];
  }
  L[g] = 1000000000;
  R[h] = 1000000000;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i] <= R[j]){
      m[k] = L[i];
      i++;
    }
    else{
      m[k]=R[j];
      j+=1;
    }
    a+=1;
  }
}
 
void sort(int left,int right){
  int mid;
  if (left+1 <right){
    mid = (left + right) / 2;
    sort(left, mid);
    sort(mid, right);
    merge(left, mid, right);
  }
}

Measured memory_bytes: 4504
#include <stdio.h>
#include <stdlib.h>
#define MAX 100000

int n, A[MAX];
int partition(int, int);

int main(){
  int i, q;
  scanf("%d",&n);
  for(i = 0; i < n; i++)scanf("%d",&A[i]);

  q = partition(0, n - 1);

  for(i = 0; i < n; i++){
    if(i == q)printf("[");
    printf("%d",A[i]);
    if(i == q)printf("]");
    if(i < n - 1)printf(" ");
  }
  printf("\n");
  return 0;
}

int partition(int p, int r){
  int x, i, j, t;
  x = A[r];
  i = p - 1;
  for(j = p; j < r; j++){
    if(A[j] <= x){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }
  t = A[i + 1];
  A[i + 1] = A[r];
  A[r] = t;
  return i + 1;
}



Measured memory_bytes: 2120
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
# import math
from fractions import gcd

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)


n = int(input())
A = list(map(int, input().split()))
sA = list(itertools.accumulate(A[::-1]))[::-1]
# print(sA)

num = 0
par = 1
for i in range(n+1):
    tmp_num = min(par, sA[i])
    if tmp_num <= 0:
        print(-1)
        exit()
    # print(tmp_num)
    num += tmp_num
    par = 2*(tmp_num-A[i])
    # print(par)

print(-1 if par < 0 else num)


Measured memory_bytes: 91264
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int X = sc.nextInt();

		if (500 * K >= X) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22740
#include "bits/stdc++.h"
using namespace std;
int search(vector<vector<char>>& A, pair<int, int>P, int H, int W) {
	int ans = 0;
	if (P.first - 1 >= 0) {
		if (A.at(P.first - 1).at(P.second) == '#') ans++;
		if (P.second - 1 >= 0 && A.at(P.first - 1).at(P.second - 1) == '#') ans++;
		if (P.second + 1 < W && A.at(P.first - 1).at(P.second + 1) == '#')ans++;
	}
	if (P.first + 1 < H) {
		if (A.at(P.first + 1).at(P.second) == '#') ans++;
		if (P.second - 1 >= 0 && A.at(P.first + 1).at(P.second - 1) == '#') ans++;
		if (P.second + 1 < W && A.at(P.first + 1).at(P.second + 1) == '#')ans++;
	}
	if (P.second - 1 >= 0 && A.at(P.first).at(P.second - 1) == '#') ans++;
	if (P.second + 1 < W && A.at(P.first).at(P.second + 1) == '#') ans++;
	return ans;
}
int main() {
	int H, W;
	cin >> H >> W;
	vector<vector<char>>A(H, vector<char>(W));
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> A.at(i).at(j);
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (A.at(i).at(j) == '.') {
				int num = search(A, make_pair(i, j), H, W);
				cout << num;
			}
			else {
				cout << '#';
			}
		}
		cout << endl;
	}
}

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

char weather[103][103];
int board[103][103];

int main(){
	int h,w;
	cin>>h>>w;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			board[i][j]=-1;
			}
		}
		
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin>>weather[i][j];
			}
		}	
		
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(weather[i][j]=='c'){board[i][j]=0;}
				else if(j!=0&&board[i][j-1]!=-1){board[i][j]=board[i][j-1]+1;}
				}
			}
			
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				cout<<board[i][j];
				if(j==w-1){cout<<endl;}
				else{cout<<' ';}
				}
			}
			return 0;	
	}

Measured memory_bytes: 3132
// Problem : B - Shift only
// Contest : AtCoder - AtCoder Beginner Contest 081
// URL : https://atcoder.jp/contests/abc081/tasks/abc081_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
	int n;cin>>n;
	int ans=INT_MAX;
	for(int i=0;i<n;i++)
	{
		int x;cin>>x;
		int cnt=0;
		while(x%2==0)
		x/=2,cnt++;
		ans=min2(ans,cnt);
	}
	cout<<ans;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
const long long int mod1=1000000007;
const long long int mod2 = -1;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back                                       
#define ff first
#define ss second
#define ll long long int
#define ull unsigned long long int
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define ordered1 tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define inf mod1
ll gcd(ll a, ll b){
    ll c;
     while(b){
        c = b;
        b = a % b;
        a = c;
     }
     return a;
}
ll power1(ll a, ll b){
     if(b == 0) return 1;
     else if(b % 2) return a * power1(a, b - 1);
     else {
        ll temp = power1(a, b / 2);
        return temp * temp;
     }
}
ll power2(ll a, ll b, ll m){
     a %= m;
     if(b == 0) return 1;
     else if(b % 2) return (a * power2(a, b - 1, m)) % m;
     else{
        ll temp = power2(a, b / 2, m);
        return (temp * temp) % m;
     }
}
ll mod(ll x, ll p){
return (x % p + p) % p;
}
ll lcm(ll x, ll y){
return (x * y)/gcd(x, y);
}
int main(){
	fast;
	ll h = 1;
	//cin >> h;
    while(h--){
        ll n;
        cin >> n;
        vector<pair<string, ll> > v;
        for(int i = 0; i < n; i++){
            string x; ll y;
            cin >> x >> y;
            v.pb({x, y});
        } 
        string cur;
        cin >> cur;
        ll tot = 0;
        bool g = false;
        for(int i = 0; i < v.size(); i++){
            if(!g){
                if(v[i].ff == cur){g = true;}
            }
            else{
                tot += v[i].ss;
            }
        }
        cout << tot << endl;
}
}

Measured memory_bytes: 256
/* bellman_ford.cpp
    ベルマンフォード法で、ある頂点から各頂点への最短距離を求めるアルゴリズム
    負の辺が含まれる場合も適用でき、負の閉路も検出可能

    始点から終点に行くまでに通らない負の閉路は検出したくない時:
        http://sigma1113.hatenablog.com/entry/2019/08/12/130042

    verified: AOJ GRL_1_B
        http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_B
*/

#include <bits/stdc++.h>
using namespace std;

struct Edge {
    long long from;
    long long to;
    long long cost;
};
using Edges = vector<Edge>;
const long long INF = 1LL << 60;

/* bellman_ford(Es,s,t,dis)
    入力: 全ての辺Es, 頂点数V, 開始点 s, 最短経路を記録するdis
    出力: 負の閉路が存在するなら ture
    計算量：O(|E||V|)
    副作用：dis が書き換えられる
*/
bool bellman_ford(const Edges &Es, int V, int s, vector<long long> &dis) {
    dis.resize(V, INF);
    dis[s] = 0;
    int cnt = 0;
    while (cnt < V) {
        bool end = true;
        for (auto e : Es) {
            if (dis[e.from] != INF && dis[e.from] + e.cost < dis[e.to]) {
                dis[e.to] = dis[e.from] + e.cost;
                end = false;
            }
        }
        if (end) break;
        cnt++;
    }
    cnt = 0;
    while (cnt < V) {
        bool end = true;
        for (auto e : Es) {
            if (dis[e.from] != INF && dis[e.from] + e.cost < dis[e.to]) {
                dis[e.to] = -INF;
                end = false;
            }
        }
        if (end) break;
        cnt++;
    }
    return dis[V - 1] == -INF;
}

int main() {
    int V, E, P;
    cin >> V >> E >> P;
    Edges Es;
    for (int i = 0; i < E; i++) {
        long long s, t, d;
        cin >> s >> t >> d;
        s--, t--;
        Es.push_back({s, t, -(d - P)});
    }
    vector<long long> dis;
    if (bellman_ford(Es, V, 0, dis)) {
        cout << "-1" << endl;
    } else {
        if (-dis[V - 1] >= 0) {
            cout << -dis[V - 1] << endl;
        } else {
            cout << 0 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 512
def cost( i,k,j ):
  return m[i][k] + m[k+1][j] + M[i][0] * M[k][1] * M[j][1]
 
n = input()
M = []
m = [[ 0 for i in range(n) ] for j in range(n) ]
for i in range(n):
  M.append( map (int, raw_input().split() ) )
 
M_long = len(M)
for l in range( 2,M_long+1 ):
  for i in range( 0,M_long-l+1 ):
    j = i+l-1
    m[i][j] = min( cost( i,k,j ) for k in range( i,j ) )
 
print m[0][M_long-1]

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> A(n, 0);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    A.at(a-1)++;
    A.at(b-1)++;
  }
  for (int i = 0; i < n; i++) cout << A.at(i) << endl;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include"math.h"
using namespace std;
int main(){int N;cin>>N;
           vector<int> A(N),B(N),C(N-1);
           for(int i=0;i<N;i++){
             cin >>A.at(i);}
for(int i=0; i<N;i++){
  cin >> B.at(i);}
           for(int i=0; i<N-1;i++){
             cin >> C.at(i);}
           
           int sum=0;
           for(int i=0;i<N;i++){
             sum+=B.at(i);}
           for(int i=0;i<N-1;i++){
           
             if(A.at(i)+1==A.at(i+1)){
               sum+=C.at(A.at(i)-1);}}
             cout << sum << endl;}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        
        int sum = 0;
        int count = 0;
        
        for(int i=0; i<=25; i++){
            for(int j=0; j<=14; j++){
                sum = 4*i + 7*j;
                if(sum == N){
                    count++;
                }
            }
        }
        
        if(count >= 1){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    S = input().replace("BC", "D")

    res = 0
    cnt = 0
    for s in S:
        if s == "A":
            cnt += 1
        elif s == "D":
            res += cnt
        else:
            cnt = 0
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 9356
#include <bits/stdc++.h>
#define endl '\n'
#define int long long

using namespace std;
const int MAXN = (1 << 20);
const int64_t inf = (int64_t)1e17 + 42;
const int N = 2e5 + 10;

int n, c, h[N], dp[N];

void read()
{
   cin>>n>>c;

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

struct convex_hull_trick_min
{
   struct line
   {
      int64_t m, b;
      bool is_query;
      double line_x;

      line() {m = 0; b = 0; line_x = 0; is_query = 0; }
      line(int64_t _m, int64_t _b) {m = _m; b = _b; line_x = 0; is_query = 0; }

      bool operator<(const line &l2) const
      {
         if(!is_query && !l2.is_query) return m > l2.m;
         else return line_x < l2.line_x;
      }

      int64_t value_at(int64_t x) const { return m * x + b; }
   };

   bool parallel(const line &l1, const line &l2) { return l1.m == l2.m; }

   double intersect_x(const line &l1, const line &l2)
   {
      if(parallel(l1, l2)) return (double)inf;
      return (double)(l1.b - l2.b) / (double)(l2.m - l1.m);
   }

   set<line> hull;
   void clear() { hull.clear(); }
   void init() { clear(); }

   bool has_next(set<line>::iterator it) { return it != hull.end() && next(it) != hull.end(); }
   bool has_prev(set<line>::iterator it) { return it != hull.end() && it != hull.begin(); }

   bool irrelevant(const line &l1, const line &l2, const line &l3) { return intersect_x(l1, l3) <= intersect_x(l1, l2); }
   bool irrelevant(set<line>::iterator it) { return has_prev(it) && has_next(it) && irrelevant(*prev(it), *it, *next(it)); }

   set<line>::iterator update_border(set<line>::iterator it)
   {
      line tmp(*it);

      double val;
      if(has_next(it)) val = intersect_x(*it, *next(it));
      else val = inf;

      it = hull.erase(it);
      tmp.line_x = val;
      it = hull.insert(it, tmp);

      return it;
   }

   void add_line(int64_t m, int64_t b)
   {
      line curr_line = line(m, b);
      set<line>::iterator it = hull.lower_bound(curr_line);

      if(it != hull.end() && it->m == m)
      {
         if(it->b > b) it = hull.erase(it);
         else return;
      }

      it = hull.insert(it, curr_line);
      if(irrelevant(it))
      {
         hull.erase(it);
         return;
      }

      while(has_prev(it) && irrelevant(prev(it))) hull.erase(prev(it));
      while(has_next(it) && irrelevant(next(it))) hull.erase(next(it));

      it = update_border(it);
      if(has_prev(it)) update_border(prev(it));
      if(has_next(it)) update_border(next(it));
   }

   int64_t query(int64_t x)
   {
      line to_find;
      to_find.line_x = x;
      to_find.is_query = 1;

      set<line>::iterator best_line = hull.lower_bound(to_find);
      if(best_line == hull.end())
         return inf;

      return best_line->value_at(x);
   }
}s2;

void solve()
{
   dp[0] = 0;
   s2.add_line(-2*h[0], h[0]*h[0]);

   int y = 0;
   for (int i = 1; i < n; ++i)
   {
      int tt = s2.query(h[i]);
      y = h[i]*h[i] + c + s2.query(h[i]);
      s2.add_line(-2*h[i], h[i]*h[i] + y);
   }
   cout<<y;
}

int32_t main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);

   read();
   solve();
   return 0;
}

Measured memory_bytes: 17408
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "YES"; }
  string_type do_falsename() const { return "NO"; }
};

void solve(ll N, ll K, vector<ll> x) {
  int res = 0;
  REP(i,N) res += min(abs(x[i]), abs(x[i] - K)) * 2;
  cout << res << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll K;
	ll N;
	scanf("%lld", &N);
	vector<ll> x(N-1+1);
	scanf("%lld", &K);
	for (int i = 0 ; i <= N-1 ; i++) {
	  scanf("%lld", &x[i]);
	}
	solve(N, K, x);
	return 0;
}


Measured memory_bytes: 256
S = input()
n = len(S)
NG = 0
for i in range(n):
  tmp = S[i]
  if (tmp == "U" or tmp == "D"):
    pass
  else:
    if(i % 2 == 0):
      if(tmp == "R"):
        pass
      else:
        NG += 1
    else:
      if(tmp == "L"):
        pass
      else:
        NG += 1
if (NG == 0):
  print("Yes")
else:
  print("No")
  

Measured memory_bytes: 3060
toInt :: (String -> Int)
toInt x = read x ::Int

getInts = do
  x <- getLine
  let y = (map$toInt)$words x
  return y
    where
      toInt x = read x ::Int
getInt = do
	x <- getLine
	let y = toInt x
	return y

main = do
	k <- getInt
	ab <- getInts
	let r = [x | x <- [(ab!!0)..(ab!!1)],x`mod`k==0]
	putStr$(\t->if length t>0 then "OK" else "NG") r

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

int get_gcd(int a, int b) {
  int r;
  while (r = a % b) {
    a = b;
    b = r;
  }
  return b;
}

int main() {
  int a, b;
  while (cin >> a >> b) {
    int gcd = get_gcd(a, b);
    int lcm = a / gcd * b;
    cout << gcd << " " << lcm << endl;
  }
  return 0;
}


Measured memory_bytes: 3004
//Compete against Yourself.
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];

int32_t main(){_
   
   cin>>n;
   
   vector<int> p(n), q(n);
   for (int i = 0; i < n; ++i)
   {
      cin >> p[i];
   }

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

   vector<int> a(n);
   iota(a.begin(), a.end(), 1);

   int idx = 0;
   int P = 0, Q = 0;
   do{

      if(a == p){
         P = idx;
      }
      if(a == q){
         Q = idx;
      }

      ++idx;
   }while(next_permutation(a.begin(), a.end()));
   
   cout<<abs(P-Q);  

   return 0;
}

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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadLong();

            Console.WriteLine(N * (N - 1) / 2);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

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


int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> G;
    vector<vector<int>> D;
    G.assign(H, vector<char>(W, '.'));
    D.assign(H, vector<int>(W, 0));
    int black_num = 0;
    char si;
    rep(i, H) rep(j, W) {
        cin >> si;
        G[i][j] = si;
        if (si == '#') black_num++;
    }

    int dyx[4][2] = {{1,0}, {-1,0}, {0,1}, {0,-1}};
    queue<int> qy, qx;
    int vy, vx, next_vy, next_vx;

    qy.push(0), qx.push(0);
    D[0][0] = 1;
    while (!qy.empty()) {
        vy = qy.front(), vx = qx.front();
        qx.pop(), qy.pop();
        rep(i, 4) {
            next_vy = vy + dyx[i][0];
            next_vx = vx + dyx[i][1];
            if ((next_vy < 0) || (next_vy >= H)) continue;
            if ((next_vx < 0) || (next_vx >= W)) continue;

            if ((G[next_vy][next_vx] == '.') && (D[next_vy][next_vx] == 0)) {
                D[next_vy][next_vx] = D[vy][vx] + 1;
                qy.push(next_vy), qx.push(next_vx);
            }
        }
    }

    if (D[H-1][W-1] == 0) cout << -1 << endl;
    else cout << H * W - D[H-1][W-1] - black_num << endl;

    return 0;
}

 

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const ll MOD = ll(1e9 + 7);

// A: 1, C: 2, G: 3, T: 4
vector<vector<ll>> dp;

ll str_to_id(const string str) {
    ll id = 0;
    for (auto &c : str) {
        int x;
        if (c == 'A') x = 0;
        else if (c == 'C') x = 1;
        else if (c == 'G') x = 2;
        else x = 3;
        id = id * 4 + x;
    }
    return id;
}

string id_to_str(ll id) {
    string S;
    for (int i = 0; i < 3; i++) {
        int x = id % 4;
        char c;
        if (x == 0) c = 'A';
        else if (x == 1) c = 'C';
        else if (x == 2) c = 'G';
        else c = 'T';
        S += c;
        id /= 4;
    }
    reverse(S.begin(), S.end());
    return S;
}

bool check(const string last4) {
    if (last4.substr(1) == "AGC" ||
            last4.substr(1) == "GAC" ||
            last4.substr(1) == "ACG" ||
            (last4[0] == 'A' && last4[1] == 'G' && last4[3] == 'C') ||
            (last4[0] == 'A' && last4[2] == 'G' && last4[3] == 'C')) {
        return false;
    }
    return true;
}

void solve(const int N) {
    const vector<char> cs = {'A', 'C', 'G', 'T'};

    for (int i = 1; i < N; i++) {
        for (int j = 0; j < 64; j++) {
            const ll id = j;
            const string last3 = id_to_str(j);

            // printf("last3: %s, val: %lld\n", last3.c_str(), dp[i][id]);

            for (auto c : cs) {
                const string str = last3 + c;
                if (check(str)) {
                    const ll next_id = str_to_id(str.substr(1));
                    dp[i + 1][next_id] = (dp[i + 1][next_id] + dp[i][id]) % MOD;
                }
            }
        }
    }
}

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

    dp.resize(N + 1, vector<ll>(64, 0));
    dp[1][str_to_id("TTA")] = 1;
    dp[1][str_to_id("TTC")] = 1;
    dp[1][str_to_id("TTG")] = 1;
    dp[1][str_to_id("TTT")] = 1;

    solve(N);

    ll ans = 0;
    for (int i = 0; i < 64; i++) {
        ans = (ans + dp[N][i]) % MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    for(int i=0;i<3;i++){
        if(S[i]=='1')S[i]='9';
        else if(S[i]=='9')S[i]='1';
    }
    cout << S << endl;
}

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

const int MOD=1000000007;
//~ const int MOD=998244353;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	int K;cin>>K;
	int ans=0;
	for(int a=1;a<=K;a++){
		for(int b=1;b<=K;b++){
			for(int c=1;c<=K;c++){
				ans+=__gcd(a,__gcd(b,c));
			}
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3632
n = int(input())
a = list(map(int,input().split()))
k = 1000
s = 0
for i in range(n-1):
    if s == 0:
        if a[i] < a[i+1]:
            s = k // a[i]
            k -= s * a[i]
    else:
        if a[i] > a[i+1]:
            k += s * a[i]
            s = 0
print(k + s * a[-1])

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

int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if (a >= k)
    {
        cout << k << endl;
    }
    else if (a + b >= k)
    {
        cout << a << endl;
    }
    else
    {
        int ans = a;
        k -= (a + b);
        while (k > 0)
        {
            ans--;
            k--;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
from itertools import product 
n=int(input())
x=[]
ans=0
for _ in range(n):
    temp=[]
    A=int(input())
    for _ in range(A):
        temp.append(list(map(int,input().split())))
    x.append(temp)
for i in product([0,1],repeat=n):
    for j in range(n):
            for k in x[j]:
                if i[k[0]-1]!=k[1] and i[j]==1:
                    break
            else:
                continue
            break
    else:
      ans=(max(ans,list(i).count(1))) 
print(ans)      
    

Measured memory_bytes: 9136
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
  static void Main(string[] args)
  {
        int sumPower = 0;
        int[] arr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var n = arr[0];
        var q = arr[1];
        var nodeArr = new Node[n];
        for (int i = 0; i < n; i++)
        {
            nodeArr[i] = new Node(i + 1);
        }
        for (int i = 0; i < n - 1; i++)
        {
            int[] arrTwo = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int a = arrTwo[0];
            int b = arrTwo[1];
            nodeArr[a - 1].Children.Add(nodeArr[b - 1]);
            nodeArr[b - 1].Children.Add(nodeArr[a - 1]);
        }
        for(int i = 0; i < q; i++)
        {
            int[] arrThree = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int c = arrThree[0];
            int d = arrThree[1];
            nodeArr[c - 1].Power += d;
        }
        Search(nodeArr[0],sumPower);
        foreach(Node element in nodeArr)
        {
            Console.WriteLine(element.Power);
        }
        



    }

    public static void Search(Node root, int sumPower)
    { 
        root.Visited = true;
        root.Power += sumPower;
        sumPower = root.Power;
        if (root.Children != null)
        {
            foreach (var node in root.Children)
            {
                if (!node.Visited)
                {
                    Search(node,sumPower);
                }
            }
        }
    }



}

public class Node
{
    public int node;
    public Node(int i)
    {
        this.node = i;
    }

    public bool Visited { get; set; }
    public List<Node> Children = new List<Node>();
    public int Power { get; set; }

}



Measured memory_bytes: 68272
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

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

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  int n;cin>>n;
  vector<vector<int> > vertex(n, vector<int>());
  map<P, int> color;
  vector<P> edge(n-1);
  rep(i, n-1){
    int a, b;cin>>a>>b;a--;b--;
    if(a>b)swap(a, b);
    edge[i]=P(a, b);
    color[P(a, b)]=0;
    vertex[a].push_back(b);
    vertex[b].push_back(a);
  }
  int k=-1, root;
  rep(i, n){
    if(k<(int)vertex[i].size()){
      k=vertex[i].size();
      root=i;
    }
  }
  cout<<k<<endl;
  queue<P> que;
  que.push(P(root, 0));
  while(que.size()){
    P v=que.front();que.pop();
    int c=1;
    for(auto &e: vertex[v.first]){
      int &p = color[P(min(e, v.first), max(e, v.first))];
      if(p!=0)continue;
      if(c==v.second)c++;
      p=c;
      que.push(P(e, c++));
    }
  }
  rep(i, n-1){
    cout<<color[edge[i]]<<endl;
  }
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 13184
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(ll i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
//typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<int,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};
int n=19,m=15;
vs in(n);
int t=inf;
void dfs(int x,int y,int c){
	rep(i,8){
		int nx=x+dx[i],ny=y+dy[i];
		int co=0;
		while(nx>=0&&nx<19&&ny>=0&&ny<15&&in[nx][ny]=='X'){
			in[nx][ny]='.';
			co++;
			nx+=dx[i];
			ny+=dy[i];
		}
		if(co&&nx<=18&&ny>=0&&ny<=14)dfs(nx,ny,c+1);
		
		if(co&&(nx==18&&ny>=0&&ny<15)||nx>18){
			t=min(t,c+1);
		}
		nx-=dx[i],ny-=dy[i];
		while(nx!=x||ny!=y){
			in[nx][ny]='X';
			nx-=dx[i];ny-=dy[i];
		}
	}
}
int main(){
	rep(i,n)cin>>in[i];
	rep(i,n)rep(j,m)if(in[i][j]=='O'){
		dfs(i,j,0);
		in[i][j]='.';
		if(t==inf)t=-1;
		cout<<t<<endl;
		return 0;
	}
}







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

int ans;
char S[17];
char an[17] = "CODEFESTIVAL2016";

int main(){
    scanf("%s", S);
    for(int i = 0; i <16; i++){
        if(S[i] != an[i]){
            ans++;
        }
    }
    cout <<ans <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
int a,b,c[101];
bool check(int d)
{
	for (int i=0;i<b;i++)
		if (d==c[i])
			return false;
	return true;
}
int main()
{
	cin>>a>>b;
	for (int i=0;i<b;i++)
		cin>>c[i];
	for (int i=0;;i++)
	{
		if (check(a-i))
		{
			cout<<a-i;
			return 0;
		}
		if (check(a+i))
		{
			cout<<a+i;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3676
import sys
sys.setrecursionlimit(10**6)
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]

n=I()
a,b=[],[]
for i in range(n):
    a.append(I())
b=sorted(a)[::-1]
M=b[0]
m=b[1]
ans=0
for i in range(n):
    if a[i]==M:
        ans=m
    else:
        ans=M
    print(ans)


Measured memory_bytes: 70204
from math import *
a, b, h, m = map(int, input().split())

m = m * 6
h = h * 5 * 6 + (30 * m / 360)

if h == m:
    print(abs(b - a))
    exit()

if abs(h - m) == 180:
# if abs(h - m) == 30:
    print(a + b)
    exit()

a1, a2 = 0, 0
x1, y1, x2, y2 = 0,0,0,0

# print('h, m:', h, m)

if h == 0:
    x1 = 0
    y1 = a
elif 0 < h < 90:
    a1 = tan(radians(90 - h))
    x1 = (a ** 2 / (1 + a1 ** 2)) ** 0.5
    y1 = a1 * x1
elif h == 90:
    x1 = a
    y1 = 0
elif 90 < h < 180:
    a1 = -tan(radians(h - 90))
    x1 = (a ** 2 / (1 + a1 ** 2)) ** 0.5
    y1 = a1 * x1
if h == 180:
    x1 = 0
    y1 = -a
if 180 < h < 270:
    a1 = tan(radians(270 - h))
    x1 = -((a ** 2 / (1 + a1 ** 2)) ** 0.5)
    y1 = a1 * x1
if h == 270:
    x1 = -a
    y1 = 0
if 270 < h < 360:
    a1 = -tan(radians(h - 270))
    x1 = -((a ** 2 / (1 + a1 ** 2)) ** 0.5)
    y1 = a1 * x1

# print('x1, y1:', x1, y1)

if m == 0:
    x2 = 0
    y2 = b
elif 0 < m < 90:
    a2 = tan(radians(90 - m))
    x2 = (b ** 2 / (1 + a2 ** 2)) ** 0.5
    y2 = a2 * x2
elif m == 90:
    x2 = b
    y2 = 0
elif 90 < m < 180:
    a2 = -tan(radians(m - 90))
    x2 = (b ** 2 / (1 + a2 ** 2)) ** 0.5
    y2 = a2 * x2
if m == 180:
    x2 = 0
    y2 = -b
if 180 < m < 270:
    # print('here')
    a2 = tan(radians(270 - m))
    x2 = -((b ** 2 / (1 + a2 ** 2)) ** 0.5)
    y2 = a2 * x2
if m == 270:
    x2 = -b
    y2 = 0
if 270 < m < 360:
    a2 = -tan(radians(m - 270))
    x2 = -((b ** 2 / (1 + a2 ** 2)) ** 0.5)
    y2 = a2 * x2

# print('a1, a2:', a1, a2)
# print('x1, y1:', x1, y1)
# print('x2, y2:', x2, y2)

print(((x1-x2)**2 + (y1-y2)**2)**0.5)

Measured memory_bytes: 62928
#include <bits/stdc++.h>
 
using namespace std;
 
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.10lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
const int mod = 1000 * 1000 * 1000 + 7;
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define clr(x) x.clear()
#define LOG(x) std::cout << x << std::endl;
 
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265359;
 
int dx[6] = {-1,-1,0,0,1,1};
int dy[6] = {-1,0,-1,1,0,1};

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

int main(){
    int n;
    cin>>n;
    ll sum=0;
    for(int i=1;i<=n;++i){
        for(int j=1;j<=n;++j){
            for(int k=1;k<=n;++k){
                sum+=gcd(i,gcd(j,k));
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

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

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

    solve();
    return 0;
}
 


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

int main() {
  int x1, x2, y1, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  int a = x2 - x1, b = y2 - y1;
  int x3 = x2 - b, y3 = y2 + a;
  int x4 = x3 - a, y4 = y3 - b;
  cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
int main(){
	int a,b,c;cin>>a>>b>>c;
	int ans=a*b/2;
	cout<<ans<<endl;
}

Measured memory_bytes: 888
#include <iostream>
#include <cstdio>                                               //scanf,printf
#include <algorithm>                                            //max,min
#include <string>                                               //string
#include <cstring>                                              //strlen,strcat
#include <cctype>                                               //isalpha,tolower
#include <cmath>                                                //sqrt,sin
#include <stack>                                                //top,push
#include <queue>                                                //front,push
#include <vector>                                               //push_back,sort
#include <set>                                                  //insert,begin
#include <map>                                                  //insert,find
#include <list>                                                 //push_front,begin
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>                                               //pow,powf
#define INF (1<<21)
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
#define ll long long
#define pl pair<long long, long long>
#define pr pair<int,int>

#define MAX 105
#define WHITE '.'
#define BLACK '#'
int a,b;

int main(){
  cin>>a>>b;
  int grid[MAX][MAX];
  
  for(int i=1; i<=100; i++){
    for(int j=1; j<=100; j++){
      if(j<=50){
        grid[i][j]=WHITE;
      }else{
        grid[i][j]=BLACK;
      }
    }
  }
  a--; b--;
  int k=1,j=1;
  for(int i=b; i!=0; i--){
    grid[k][j]=BLACK;
    if(k==99){
      j+=2;
      k=-1;
    }
    k+=2;
  }
  j=52;
  k=1;
  for(int i=a; i!=0; i--){
    grid[k][j]=WHITE;
    if(k==99){
      j+=2;
      k=-1;
    }
    k+=2;
  }
  
  cout<<"100 100"<<endl;
  for(int i=1; i<=100; i++){
    for(int j=1; j<=100; j++){
      if(grid[i][j]==WHITE) cout<<WHITE;
      else cout<<BLACK;
    }
    cout<<endl;
  }
}












































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

int main(){
  int a,b;
  cin>>a>>b;
  if(b-a>0){
    if((b-a)%(a-1)==0) cout<<(b-a)/(a-1)+1<<endl;
    else cout<<(b-a)/(a-1)+2<<endl;
  }
  else if(b==1) cout<<0<<endl;
  else cout<<1<<endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double ld;
#define F first
#define S second
#define fi(a, b) for(ll i=(a);i<=b;i++)
#define fj(a, b) for(ll j=(a);j<=b;j++)
#define fid(a, b) for(ll i=(a);i>=b;i--)
#define fjd(a, b) for(ll i=(a);i>=b;j--)

template<class T> ostream& operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for(auto v : V) os << v << " ";
    os << "]";
	return os;
}
template<class T> ostream& operator<<(ostream &os, set<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class T> ostream& operator<<(ostream &os, multiset<T> S){
    os << "{ ";
    for(auto s:S) os<<s<<" ";
    return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
template<class L, class R> ostream& operator<<(ostream &os, map<L,R> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") ";
    return os<<"}";
}
template<class L, class R> ostream& operator<<(ostream &os, unordered_map<L,R> M) {
    os << "{ ";
    for(auto m:M) os<<"("<<m.F<<":"<<m.S<<") ";
    return os<<"}";
}

// Kevin Mathew T
// Birla Institute of Technology, Mesra
// LinkedIn - https://www.linkedin.com/in/KevinMathewT/
// GitHub - https://github.com/KevinMathewT
// CodeForces - https://codeforces.com/profile/KevinMathew
// CodeChef - https://www.codechef.com/users/KevinMathew
// HackerRank - https://www.hackerrank.com/KevinMathew

const ll N = 1, M = 1e9 + 7;
ll n;

void solve(){
	cin >> n;
	cout << ((n * (n - 1))) / 2 << "\n";
}

int main(){
	// freopen("input.txt", "r", stdin);		//Comment
	// freopen("output.txt", "w", stdout);		//this out.
	ios::sync_with_stdio(false);			//Not
	cin.tie(NULL);							//this.
	cout.tie(0);							//or this.

	// ll T;
	// cin >> T;
	// while(T--)
		solve();

	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();

		int p[] = new int[n];

		for (int i=0; i<n; i++){
			p[i] = sc.nextInt();
		}

		Arrays.sort(p);

		int ans = 0;
		for (int i=0; i<k; i++){
			ans += p[i];
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 38828
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<utility>
#include<iomanip>
using namespace std;
int read(){
    int xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
long long READ(){
    long long xx=0,ff=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')ff=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){xx=xx*10+ch-'0';ch=getchar();}
    return xx*ff;
}
char one(){
	char ch=getchar();
	while(ch==' '||ch=='\n')
		ch=getchar();
	return ch;
}
const int maxn=100010;
char s[maxn];
int N;
int main(){
	//freopen("in","r",stdin);
	int ans=0;
	scanf("%s",s+1);
	N=strlen(s+1);
	for(int i=2;i<=N;i++)
		if(s[i]!=s[i-1])
			ans++;
	printf("%d\n",ans);
	return 0;
}



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

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

  int ans;
  if (A == B)
    ans = A + B;
  else
    ans = max(A, B) * 2 - 1;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>	
using namespace std;
#define all(v)			((v).begin()), ((v).end())
#define sz(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
typedef long long         ll;
const double EPS = (1e-7);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }
#define pb					push_back
#define P(x)				cout<<#x<<" = { "<<x<<" }\n"
clock_t T;
#define ctime cerr << "Time : " << double(clock() - T) / CLOCKS_PER_SEC << endl
void GOAT()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("output.txt", "w	", stdout);
#else
#endif

}
string a, b, finans = "";
int mem[3001][3001];
int lcs(int i, int j)
{
	if (i >= sz(a) || j >= sz(b))
		return 0;
	int& ret = mem[i][j];
	if (~ret)return ret;
	ret = -1;
	if (a[i] == b[j]) {
		return lcs(i + 1, j + 1)+1;
	}
	int ch1 = lcs(i, j + 1);
	int ch2 = lcs(i + 1, j);
	return ret = max(ch1, ch2);
}
void solve(int i, int j)
{
	if (i >= sz(a) || j >= sz(b)) return;
	if (a[i] == b[j])
	{
		cout << a[i];
		solve(i + 1, j + 1);
	}
	else
	{
		if (lcs(i + 1, j) >= lcs(i, j + 1)) solve(i + 1, j);
		else solve(i, j + 1);
	}
}

int main()
{
	//GOAT();
	clr(mem, -1);
	cin >> a >> b;
	 lcs(0, 0);
	solve(0, 0);
	


}

Measured memory_bytes: 36096
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int n;
  	cin>>n;
    int a[n],count=1,min;
    for (int i=0;i<n;i++)
    {
        cin>>a[i];
        if(i==0) min=a[i];
        else if(a[i]<min)
        {
            min =a[i];
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 1024