akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define MOD 1000000007

char temp[3] = {'A', 'B', 'C'};
string s;

long long pow_mod(long long a, long long b){
  long long ans = 1;
  while(b > 0){
    if(b & 1) ans = (ans * a) % MOD;
    a = (a * a) % MOD;
    b >>= 1;
  }

  return ans;
}

int memo[100010][4][4];
int hatena = 0;
long long solve(int i, int cnt, int hate){
  if(cnt == 3){
    return pow_mod(3, hatena-hate);
  }
  if(i == s.size()) return 0;

  if(memo[i][cnt][hate] != -1){
    return memo[i][cnt][hate];
  }

  long long ans = 0;
  if(s[i] == temp[cnt]){
    ans += solve(i+1, cnt+1, hate);
  }else if(s[i] == '?'){
    ans += solve(i+1, cnt+1, hate+1);
  }
  return memo[i][cnt][hate] = (ans + solve(i+1, cnt, hate)) % MOD;
}

int main(){
  cin >> s;
  for(int i = 0;i < s.size();i++){
    if(s[i] == '?') hatena++;
  }
  memset(memo, -1, sizeof(memo));

  cout << solve(0, 0, 0) << endl;

  return 0;
}

Measured memory_bytes: 14592
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, groupby
from math import floor, ceil, sqrt, factorial, log
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
from itertools import product
import sys
stdin = sys.stdin
mod = 10**9 + 7


def ns(): return stdin.readline().rstrip()


def ni(): return int(ns())


def na(): return list(map(int, stdin.readline().split()))


n = ni()
print(800 * n - 200 * (n // 15))


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

int main(void)
{
    int n = 0;
    
    while(cin >> n){
        int ans = 0;
        if(n >= 37){
            cout << ans << endl;
            continue;
        }

        for(int a = 0; a < 10; a++){
            for(int b = 0; b< 10; b++){
                for(int c = 0; c < 10; c++){
                    for(int d = 0; d < 10; d++){
                        if((a + b + c + d) == n) ans++;
                    }
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3012
#include<bits/stdc++.h>
using namespace std;
int main(){long long x,b=-1,p,q,a=1;cin>>x;while(1){p=a*a*a*a*a;q=b*b*b*b*b;if(p-q>x)b++;else if(p-q<x){a++;b=-a;}else break;}
cout<<a<<' '<<b<<endl;}

Measured memory_bytes: 3572
using System;
class Program
{
	static void Main(string[] args)
	{
		// 整数の入力
		string s = Console.ReadLine();
        string t = Console.ReadLine();
      	int count = 0;
        for (int i = 0; i < s.Length; i++) {
        	char sc = s[i];
          	char tc = t[i];
            if (sc != tc) {
            	count++;
            }
        }
        Console.WriteLine(count);
	}
}

Measured memory_bytes: 27528
# ITP1_3_B
# Print Test Cases
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_3_B
# encode : utf-8
numlist = []
while (1) :
    x = int(input())
    if x == 0 :
        break
    numlist.append(x)
case = 1
for x in numlist :
    print('Case {0}: {1}'.format(case, x))
    case += 1


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

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
// #define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...) 42
#define dump(x) 42
#define debug(x) 42
#endif

typedef long long ll;

const ll MOD = 1e9 + 7;

void solve(int H, int W, vector<string>& S) {
    vector<vector<int>> vObstacles(H);
    vector<vector<int>> hObstacles(W);

    REP(i,0,H){
        REP(j,0,W){
            if (S[i][j] == '#') {
                vObstacles[i].emplace_back(j);
                hObstacles[j].emplace_back(i);
            }
        }
    }
    int answer = 0;

    REP(i,0,H){
        REP(j,0,W){
            if (S[i][j] == '#') continue;

            int vertical = 0, horizonal = 0;
            auto vitr = lower_bound(all(vObstacles[i]), j);
            vertical += vitr == vObstacles[i].end() ? W - j - 1 : *vitr - j - 1;
            vertical += vObstacles[i].size() == 0 || vitr == vObstacles[i].begin() ? j : j - *(vitr-1) - 1;

            auto hitr = lower_bound(all(hObstacles[j]), i);
            horizonal += hitr == hObstacles[j].end() ? H - i - 1 : *hitr - i - 1;
            horizonal += hObstacles[j].size() == 0 || hitr == hObstacles[j].begin() ? i : i - *(hitr-1) - 1;

//            cout << i << "," << j << ":" << (vitr == vObstacles[i].end() ? W - j - 1 : *vitr - j - 1)
//            << "," << (vObstacles[i].size() == 0 || vitr == vObstacles[i].begin() ? j : j - *(vitr-1) - 1)
//            << "," << (hitr == hObstacles[j].end() ? H - i - 1 : *hitr - i - 1)
//            << "," << (hObstacles[j].size() == 0 || hitr == hObstacles[j].begin() ? i : i - *(hitr-1) - 1)
//            << '\n';

                 answer = max(answer, vertical + horizonal + 1);
        }
    }

	stringstream ss;
    ss << answer;
	cout << ss.str() << '\n';

    return;
}

signed main() {
    int H, W;
    cin >> H >> W;
    
    vector<string> S(H);
    REP(i,0,H) cin >> S[i];
    
    solve(H, W, S);

    return 0;
}



Measured memory_bytes: 38528
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0]);
    var ans = 0;

    // N = k * m + k = k(m + 1)
    for (var k = 1; k < Math.sqrt(N); k++) {
        if (N / k === Math.floor(N / k) && k !== N / k - 1) { ans += N / k - 1 }
    }

    console.log(ans);
});

Measured memory_bytes: 11596
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}


int gcd(int a,int b){
  if(a%b)return gcd(b,a%b);
  else return b;
}
int main(){
  int n;cin>>n;
  set<int> A;
  A.insert(n);
  int a = 1;
  while(true){
    if(n%2){
      n = 3*n+1;
    }else{
      n = n/2;
    }
    a++;
    if(A.find(n) != A.end()){
      cout << a << endl;
      return 0;
    }
    A.insert(n);
  }
}


Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 #-}

main :: IO ()
main = putStrLn . showResult =<< solve <$> getInput

showResult :: Maybe (Int, Int, Int) -> String
showResult Nothing          = "-1 -1 -1"
showResult (Just (a, b, c)) = show a ++ " " ++ show b ++ " " ++ show c

getInput :: IO (Int, Int)
getInput = do
  [n, y] <- map read . words <$> getLine
  return (n, y)

solve :: (Int, Int) -> Maybe (Int, Int, Int)
solve (n, y) = headMaybe [(a, b, c)
                         | a <- [0 .. n]
                         , b <- [0 .. n]
                         , let c = n - a - b
                         , c >= 0
                         , 10000 * a + 5000 * b + 1000 * c == y
                         ]

headMaybe :: [a] -> Maybe a
headMaybe []     = Nothing
headMaybe (x:xs) = Just x


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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N, Q; cin >> N >> Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

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

int main (){
  
    long long int N,i,j,k,ans=0;
    cin >> N;
    long long int w[5] = {0};
    char S[N][100];
    for(int i = 0; i < N; i++) {
        cin >> S[i]; 
    }

    for(i = 0; i < N; i++) {
        if(S[i][0] == 'M'){
            w[0]++;
        }else if(S[i][0] == 'A'){
            w[1]++;
        }else if(S[i][0] == 'R') {
            w[2]++;
        }else if(S[i][0] == 'C') {
            w[3]++;
        }else if(S[i][0] == 'H') {
            w[4]++;
        }else 
            continue;
        }
    
        for(i = 0; i < 3; i++) {
            for(j = i+1; j < 4; j++) {
                for(k = j+1; k < 5; k++) {
                    ans += w[i] * w[j] * w[k];
                }
            }
        }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9984
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
static const int MAX = 100000;
static const int NIL = -1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r , int c) {
  stack<int> S;
  S.push(r);
  color[r] = c;
  while(!S.empty()) {
    int u = S.top(); S.pop();
    for(int i = 0;i<G[u].size();i++) {
      int v=G[u][i];
      if(color[v] == NIL) {
        color[v] = c;
        S.push(v);
      }
    }
  }
}

void assingColor(){
  int id = 1;
  for(int i = 0;i<n;i++) color[i] = NIL;
  for(int u = 0;u<n;u++) {
    if(color[u] == NIL) dfs(u,id++);
  }
}

int main() {
  int s,t,m,q;

  cin >>n>>m;

  for(int i = 0;i<m;i++) {
    cin >> s>> t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  assingColor();
  cin>>q;
  for(int i=0;i<q;i++) {
    cin>>s>>t;
    if(color[s]== color[t]) {
      cout<<"yes"<<endl;

    }else {
      cout<<"no"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 9012
extern crate proconio;

use proconio::*;

fn main() {
    input! {
        bar_num: u32,
        mut bars: [u32; bar_num]
    }
    bars.sort();
    let mut count = 0;
    for i in 0..bars.len() {
        for j in 0..i {
            for k in 0..j {
                if bars[k] != bars[j] && bars[j] != bars[i] &&
                    bars[k] + bars[j] > bars[i] {
                    count += 1;
                }
            }
        }
    }
    println!("{}", count);
}


Measured memory_bytes: 2160
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    ll a,b;
    ll ans;
    cin>>a>>b;
    ans=a*b;
    cout<<ans<<endl;
}

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

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

// 階乗、階乗逆元テーブル
int fact[1100000], fact_inv[1100000], inv[1100000];
int mod_fact(int n, int m) {
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i <= n; i++) {
        fact[i] = fact[i - 1] * i % m;
        inv[i] = m - inv[m % i] * (m / i) % m;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % m;
    }
}

int N, X, Y;
int c[220000], w[220000];
int minc[220000], anominc[220000], cancan[220000];
int mod = 1e9 + 7;
signed main() {
    cin >> N >> X >> Y;
    for (int i = 0; i < N; i++)cin >> c[i] >> w[i], c[i]--;
    for (int i = 0; i < N; i++)minc[i] = LLONG_MAX;
    for (int i = 0; i < N; i++)minc[c[i]] = min(minc[c[i]], w[i]);
    for (int i = 0; i < N; i++) {
        if (minc[c[i]] + w[i] <= X)w[i] = minc[c[i]];
    }
    int minidx = 0;
    for (int i = 1; i < N; i++) {
        if (minc[i] < minc[minidx])minidx = i;
    }
    for (int i = 0; i < N; i++)anominc[i] = minc[minidx];
    int next = LLONG_MAX;
    for (int i = 0; i < N; i++) {
        if (i != minidx)next = min(next, minc[i]);
    }
    anominc[minidx] = next;
    for (int i = 0; i < N; i++) {
        if (w[i] + anominc[c[i]] <= Y)cancan[c[i]]++;
    }
    int all = 0;
    for (int i = 0; i < N; i++)all += cancan[i];
    mod_fact(N, mod);
    int ans = fact[all];
    for (int i = 0; i < N; i++) {
        (ans *= fact_inv[cancan[i]]) %= mod;
    }
    cout << ans << endl;


}


Measured memory_bytes: 18560
#include<cstdio>
#include<cstring>
const int N = 2e5+5;
char s[N];

int main(){
    int n,a,b,c,d;
    scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
    scanf("%s",s+1);
    int ok = 1;
    for(int i = a; i <= c-1; i++){
        if(s[i]=='#' && s[i+1]=='#') ok = 0;
    }
    for(int i = b; i <= d-1; i++){
        if(s[i]=='#' && s[i+1]=='#') ok = 0;
    }
    if(ok){
        if(c>d){
            int find = 0;
            for(int i = b; i <= d; i++){
                if(i-1>=1 && i+1<=n && s[i-1]=='.' && s[i]=='.' && s[i+1]=='.') find = 1;
            }
            if(!find) printf("No\n");
            else printf("Yes\n");
        }
        else printf("Yes\n");
    }
    else {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

int main()
{
	int x ,y;
	while ( 1 ){
		scanf("%d %d" ,&x ,&y);
		if( x == 0 && y == 0 ) break;
		if( x < y ){
			printf("%d %d\n",x ,y);
		} else {
			printf("%d %d\n",y ,x);
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <algorithm>
#include <queue>
using ll = long long;

/*int main() {
	int N, X[200000], V[200000], Pattern[200000] = { 0 };
	scanf("%d", &N);
	for (int i = 0; i < N; i++)
		scanf("%d %d", X + i, V + i);
	for(int i = 0; i < N; i++)
		for (int j = i + 1; j < N; j++)
			if ((X[i] < X[j] && V[j] < V[i]) || (X[j] < X[i] && V[i] < V[j]))
				Pattern[i]++, Pattern[j]++;
	for (int i = 0; i < N; i++)
		printf("%d\n", Pattern[i]);
	while (true);
}*/
int main() {
	int N, M, Q;
	char s[2002][2002] = { 0 };
	int DPsum[2002][2002] = { 0 }, DPHor[2002][2002] = { 0 }, DPVer[2002][2002] = { 0 };
	scanf("%d %d %d", &N, &M, &Q);
	for (int i = 1; i <= N; i++) {
		scanf("%s", &s[i][1]);
		for (int j = 1; j <= M; j++)
			s[i][j] -= '0';
		for (int j = 1; j <= M; j++)
			DPsum[i][j] = DPsum[i][j - 1] + s[i][j];
		for (int j = 1; j <= M; j++)
			DPHor[i][j] = DPHor[i][j - 1] + (s[i][j - 1] & s[i][j]);
		for (int j = 1; j <= M; j++)
			DPVer[i][j] = DPVer[i - 1][j] + (s[i - 1][j] & s[i][j]);
	}
	int x1, x2, y1, y2, b;
	for (int i = 0; i < Q; i++) {
		b = 0;
		scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
		for (int j = x1; j <= x2; j++)
			b += DPsum[j][y2] - DPsum[j][y1 - 1];
		for (int j = x1; j <= x2; j++)
			b -= DPHor[j][y2] - DPHor[j][y1];
		for (int j = y1; j <= y2; j++)
			b -= DPVer[x2][j] - DPVer[x1][j];
		printf("%d\n", b);
	}
}

Measured memory_bytes: 52608
from collections import deque

S = deque(input())
Q = int(input())
Queries = [input().split() for _ in range(Q)]

need_reverse = False

for q in Queries:
    if q[0] == "1":
        need_reverse = not need_reverse
    else:
        if q[1] == "1":
            if not need_reverse:
                S.appendleft(q[2])
            else:
                S.append(q[2])
        else:
            if not need_reverse:
                S.append(q[2])
            else:
                S.appendleft(q[2])

S = "".join(S)
print(S if not need_reverse else S[::-1])


Measured memory_bytes: 44532
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>
#include <set>

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::set;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    string s;
    cin >> s;
    int l = 0;
    int r = s.size() - 1;
    int res = 0;
    while (r > l) {
        if (s[l] == s[r]) {
            l++;
            r--;
        } else if (s[l] == 'x') {
            res++;
            l++;
        } else if (s[r] == 'x') {
            res++;
            r--;
        } else {
            cout << "-1\n";
            return 0;
        }
    }

    cout << res << "\n";
    return 0;
}

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

void solve(){
    ll a, b, c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b << endl;
}

int main()
{
    //ll t; cin >> t; while(t--)
    solve();
}


Measured memory_bytes: 256
import itertools


def main():
    s = input()
    n = len(s)
    a = list(itertools.product(['+', ''], repeat=n - 1))
    ans = 0
    for i in a:
        formula = s[0]
        for index, j in enumerate(i):
            formula += j
            formula += s[index + 1]
        ans += eval(formula)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import java.util.Scanner;

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

		while (true) {
			// ?????????????????°???n?????£??\
			int n = sc.nextInt();
			// ?????£????????????????????°???r?????£??\
			int r = sc.nextInt();
			if (n == 0 && r == 0)
				break;

			// ??????????????????????????????????´?????????¢??°deck
			int[] deck = scanCard(n);

			for (int i = 0; i < r; i++) {
				// ?????????????????????????????????
				int p = sc.nextInt();
				// p????????????c????????????????????????
				int c = sc.nextInt();

				// ?????£????????????????????¢??°
				// p???????????????????????????c???p???????????????
				deck = shuffle(preserve(1, p - 1, deck), preserve(p, c, deck), deck);
			}
			System.out.println(deck[0]);
		}
	}

	public static int[] scanCard(int n) {
		int[] card = new int[n];
		for (int i = 0; i < card.length; i++) {
			card[i] = card.length - i;
		}
		return card;
	}

	public static int[] preserve(int firstTerm, int termNum, int[] array) {
		int[] newArray = new int[termNum];
		for (int i = 0; i < termNum; i++) {
			newArray[i] = array[firstTerm - 1 + i];
		}
		return newArray;
	}

	public static int[] shuffle(int[] preArray, int[] postArray, int[] array) {
		for (int i = 0; i < postArray.length; i++) {
			array[i] = postArray[i];
		}
		for (int i = 0; i < preArray.length; i++) {
			array[postArray.length + i] = preArray[i];
		}
		return array;
	}
}

Measured memory_bytes: 38128
#include <algorithm>
#include <array>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N, M;
  cin >> N >> M;
  vll A(N), B(N), C(M), D(M);
  REP(i, 0, N) {
    ll a, b;
    cin >> a >> b;
    A[i] = a;
    B[i] = b;
  }
  REP(i, 0, M) {
    ll c, d;
    cin >> c >> d;
    C[i] = c;
    D[i] = d;
  }

  REP(i, 0, N) {
    ll min = kMod;
    ll min_idx = -1;
    REP(j, 0, M) {
      ll len = abs(A[i] - C[j]) + abs(B[i] - D[j]);
      if (len < min) {
        min = len;
        min_idx = j + 1;
      }
    }
    cout << min_idx << endl;
  }

  return 0;
}


Measured memory_bytes: 256
from itertools import permutations
N=int(input())
town=[]
for i in range(N):
    x,y=map(int,input().split())
    town.append((x,y))

ans=0
for i,j in permutations(town,2):
    ans+=(((i[0]-j[0])**2+(i[1]-j[1])**2)**0.5)
print(ans/N)

Measured memory_bytes: 38512
#http://abc057.contest.atcoder.jp/tasks/abc057_b
import sys

def myabs(a):
    return a if a >= 0 else -a

def dist(x1, y1, x2, y2):
    return myabs(x1-x2) + myabs(y1-y2)

def calc(people_points, check_points):
    ans = []

    #それぞれの人に関して、チェックポイントまでの距離を求める
    for x_p, y_p in people_points:
        dists = [ dist(x_p, y_p, check_point[0], check_point[1]) for check_point in check_points ]
        ans_ind, ans_dist = sorted(list(enumerate(dists)), key=lambda tpl:tpl[1])[0]
        ans_tpl = (ans_ind, ans_dist)
        ans.append(ans_tpl)


    return ans

def main():
    n_m = sys.stdin.readline().split()
    n = int(n_m[0])
    m = int(n_m[1])

    people_points = []
    check_points = []

    for i in range(n):
        a_b = sys.stdin.readline().split()
        a = int(a_b[0])
        b = int(a_b[1])
        people_points.append((a, b))

    for i in range(m):
        c_d = sys.stdin.readline().split()
        c = int(c_d[0])
        d = int(c_d[1])
        check_points.append((c, d))

    ans = [ind + 1 for ind, dist in calc(people_points, check_points)]
    print("\n".join([str(i) for i in ans]))

    return 0

if __name__ == '__main__':
    sys.exit(main())


Measured memory_bytes: 3064
/*head*/
#include<stdio.h>

/*main function*/

int main(){
        int a,b;
        int n=9;

        scanf("%d%d",&a,&b);

        if(a<1 || b<1){
                printf(":(\n");
        }
        else if(a<n && b<n){
                printf("Yay!\n");
        }
        else{
                printf(":(\n");
        }

        return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long int ll;
using namespace std;

int main()
{
    int n; cin >> n;
    vector<int> l(n);
    ll ans = 0;
    for(int i=0;i<n;i++) {
        cin >> l[i];
    }
    sort(l.begin(),l.end());
    for(int i=0;i<n-2;i++){
        int MIN = l[i];
        for(int j=i+1;j<n-1;j++){
            for(int k=j+1;k<n;k++){
                if(l[k]<MIN+l[j]) ans++;
                else break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
static const int N = 100;
static const int INFTY = (1<<21);

int n, M[N][N];
int d[N];
void bfs(int s) {
    queue<int> q;
    q.push(s);
    for ( int i = 0; i < n; i++ ) d[i] = INFTY;
    
    d[s] = 0;
    int u;
    while ( !q.empty() ) {
        u = q.front();
        q.pop();
        for ( int v = 0; v < n; v++ ) {
            if ( M[u][v] == 0 ) continue;
            if ( d[v] != INFTY ) continue;
            d[v] = d[u] + 1;
            q.push(v);
            }
        
    }
    for ( int i =0; i<n; i++){
         cout << i+1 << " " << ( (d[i] == INFTY) ? (-1) : d[i] ) << endl;
         }
    
}
         int main() {
             int u, k, v;
             cin >> n;
             for ( int i =0; i<n; i++){
                 for ( int j=0; j<n; j++)  M[i][j] = 0;
                       }
             
             for ( int i =0; i<n; i++){
                            cin >> u >> k;
                 u--;
                 for ( int j =0; j<k; j++){
                                 cin >> v;
                     v--;
                     M[u][v] =1;
                                 }
                 
             }
           bfs(0);
       return 0;
             
         }


Measured memory_bytes: 3148
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    String s = sc.next();
    int num = 0;
    
    int asl[] = new int [26];
    int asr[] = new int [26];
    String strl;
	String strr;
    
    int max = 0;
    int count = 0;

    for(int j = 1; j<n; ++j){
      for(int i = 0; i<26; ++i){
        asl[i] = 0;
        asr[i] = 0;
      }
      strl = s.substring(0,j);
      strr = s.substring(j,n);
      
      for(int i = 0 ; i < strl.length() ; ++i){
        num = (int)strl.charAt(i) - 97;
        asl[num] =1;
      }
      for(int i = 0 ; i < strr.length() ; ++i){
        num = (int)strr.charAt(i) - 97;
        asr[num] =1;
      }
      for(int i = 0 ; i < 26 ; ++i){
        if((asl[i] ==1) && (asr[i] == 1)){
          count++;
        }
      }
      
      max = Math.max(max,count);
      count = 0;
    }
    
    System.out.println(max);

  }
}

Measured memory_bytes: 35716
S = input()
T = ['dreamer', 'eraser', 'erase', 'dream']

ans = None

while S:
  n = len(S)
  found = False
  
  for t in T:
    x = len(t)
    if n >= x:
      s1 = S[-x:]
      if s1 == t:
        S = S[:-x]
        found = True
        break
  if not found:
    ans = "NO"
    break
    
if ans is None:
  ans = "YES"
print(ans)


Measured memory_bytes: 3188
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int n; cin>>n;
    vector<P> c(n);
    for(int i=0; i<n; i++){
        cin>>c[i].fs>>c[i].sc;
    }

    sort(c.begin(), c.end());

    vector<ll> vsum(n+10, 0);
    vsum[0] = c[0].sc;
    for(int i=1; i<n; i++){
        vsum[i] = vsum[i-1] + c[i].sc;
    }

    vector<ll> bestmin(n+10, 0);
    bestmin[0] = vsum[0] - c[0].fs - c[0].sc;
    for(int i=1; i<n; i++){
        bestmin[i] = min(bestmin[i-1], vsum[i] - c[i].fs - c[i].sc);
    }

    ll ans=c[0].sc;
    for(int i=1; i<n; i++){
        ll sum = (vsum[i] - c[i].fs) - (bestmin[i]);
        chmax(ans, sum);
    }

    cout << ans << endl;
}


Measured memory_bytes: 18408
#!/usr/bin/env python3

from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
INF = float('inf')

k = int(input())
s = list(input())

if len(s) <= k:
    print(''.join(s))
else:
    res = ''.join(s[:k])
    res += '...'
    print(res)


Measured memory_bytes: 68484
n = (int)(input())
l= (list)(map(int,input().split()))

def do(l):
  ans = 0
  if len(l)==0:
    return 0
  m= min(l)
  ans += m
  
  l = (list)(map(lambda x:x-m,l))
  
  s=0
  ret = []
  for i in range(len(l)):
    if l[i]==0:
      ret.append(l[s:i])
      s = i+1
  ret.append(l[s:])
  for i in ret:
    ans += do(i)
  return ans

print(do(l))

Measured memory_bytes: 3188
// 6565..を出す 11で割るのが浮かぶ 
// 16なら565でいいが17だと656としなければならない
package main
import "fmt"
func main(){
	var  N int
	fmt.Scan(&N)
	if N<=6{
		fmt.Println(1)
	}else if N%11==0{
		fmt.Println(N/11*2)
	}else if N%11<=6{
		fmt.Println(N/11*2+1)
	}else{
		 fmt.Println(N/11*2+2)
	}
}

Measured memory_bytes: 1772
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<long long>;
bool dfs(vector<vll> &G, vll &color, ll v, ll c){
    color[v] = c;
    for(ll i=0; i< G[v].size(); i++){
        if(color[G[v][i]] == c) return false;
        if(color[G[v][i]] == 0 && dfs(G, color, G[v][i], -c)==false) return false;
    }
    return true;
}
void solve(long long N, long long M, std::vector<long long> A, std::vector<long long> B){
    vector<vll> G(N);
    for(ll i=0; i< M; i++){
        G[A[i]-1].push_back(B[i]-1);
        G[B[i]-1].push_back(A[i]-1);
    }
    vll color(N, 0);
    bool isGood;
    isGood = dfs(G, color, 0, 1);
    if(!isGood) {
        cout << N*(N-1)/2 - M << endl;
    }
    else{
        ll cnt=0;
        for(ll i=0; i< N; i++){
            if(color[i] == 1) cnt++;
        }
        cout << (cnt * (N - cnt) - M) << endl;
    }

}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, M, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 9088
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

#define INF 1e15

int main(){
  int n;
  cin>>n;
  vector<ll> a;
  bool flag=false;
  for(int i=0;i<n;i++){
      ll x;
      cin>>x;
      if(x>0) flag=true;
      a.push_back(x);
  }

  if(!flag){
      ll ma=-INF;
      for(int i=0;i<n;i++){
          ma=max(ma,a[i]);
      }
      vector<int> ans;
      for(int i=0;i<n;i++){
          if(ma==a[i]){
              for(int j=i+1;j<n;j++){
                  ans.push_back(n-j+1);
              }
              i=n;
          }else ans.push_back(1);
      }
      cout<<ma<<endl;
      cout<<ans.size()<<endl;
      for(int i=0;i<ans.size();i++) cout<<ans[i]<<endl;
  }else{
      ll odd=0,even=0;
      bool O[n+1]={},E[n+1]={};
      for(int i=0;i<n;i++){
          if(i%2){
              if(a[i]>0){
                  odd+=a[i];
                  O[i]=true;
              }
          }else{
              if(a[i]>0){
                  even+=a[i];
                  E[i]=true;
              }
          }
      }
      vector<int> ans;
      int end=0,start=0;
      bool U[n+1]={};
      for(int i=0;i<n;i++){
          if(odd<even) U[i]=E[i];
          else U[i]=O[i];
      }
      if(odd<even) cout<<even<<endl;
      else cout<<odd<<endl;
          for(int i=n-1;i>=0;i--){
              if(U[i]){
                  end=i;
                  break;
              }
              ans.push_back(i+1);
          }
          for(int i=0;i<n;i++){
              if(U[i]){
                  start=i;
                  break;
              }
              ans.push_back(1);
          }
          for(int i=start+2;i<=end;i+=2){
              if(U[i]){
                  ans.push_back(2);
              }else{
                  ans.push_back(3);
              }
          }
          cout<<ans.size()<<endl;
          for(int i=0;i<ans.size();i++) cout<<ans[i]<<endl;
  }


  return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    x = LI()
    L = I()
    q = I()
    p = [[] for i in range(n)]
    for i in range(n):
        xi = x[i]
        l = i
        r = n
        while r-l > 1:
            m = (l+r) >> 1
            xm = x[m]
            if xm-xi <= L:
                l = m
            else:
                r = m
        p[i].append(l)
    N = 20
    for j in range(N):
        for i in range(n):
            p[i].append(p[p[i][-1]][-1])
    for i in range(q):
        a,b = LI()
        a -= 1
        b -= 1
        a,b = min(a,b),max(a,b)
        ans = 1
        for j in range(N)[::-1]:
            if p[a][j] < b:
                a = p[a][j]
                ans += 1<<j
        print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 120728
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define ll long long
#define rep(i,n) for(long long i=0;i<n;i++)
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
ll a[200100],b[200100];
int main()
{
	ll n,m,k;
  cin>>n>>m>>k;
  a[0]=0;
  forn(i,1,n)
  {
  	cin>>a[i];
  	if(i!=1)
  	{
  	  a[i]+=a[i-1];	
	}
  }
  b[0]=0; 
  forn(i,1,m)
  {
  	cin>>b[i];
  	if(i!=1)
  	{
  	  b[i]+=b[i-1];
    }
  }
  int ans=0;
  forn(i,0,n)
  {
  	if(a[i]>k)
  	{
  	  break;	
	}
  	int l=0,r=m,cnt=0;
  	while(l<=r)
  	{
  		int mid=(l+r)/2;
  	  	if(a[i]+b[mid]<=k)
		{
			cnt=max(cnt,mid);
			l=mid+1;
		}
		else
		{
			r=mid-1;
		}
	}
	//cout<<a[i]+b[l]<<endl;
	ans=max(ans,cnt+i);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 6720
/*
    author:  Maksim1744
    created: 18.01.2020 15:11:10
*/

#include <bits/stdc++.h>

using namespace std;

#define ll   long long
#define ld   long double

#define mp   make_pair
#define pb   push_back
#define eb   emplace_back

#define sum(a)     ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a)    (*min_element((a).begin(), (a).end()))
#define maxe(a)    (*max_element((a).begin(), (a).end()))
#define mini(a)    ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a)    ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())

template<typename T>             vector<T>& operator--            (vector<T>& v){for (auto& i : v) --i;            return  v;}
template<typename T>             vector<T>& operator++            (vector<T>& v){for (auto& i : v) ++i;            return  v;}
template<typename T>             istream& operator>>(istream& is,  vector<T>& v){for (auto& i : v) is >> i;        return is;}
template<typename T>             ostream& operator<<(ostream& os,  vector<T>& v){for (auto& i : v) os << i << ' '; return os;}
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p){is >> p.first >> p.second;        return is;}
template<typename T, typename U> ostream& operator<<(ostream& os, pair<T, U>& p){os << p.first << ' ' << p.second; return os;}
template<typename T, typename U> pair<T,U> operator-(pair<T,U> a, pair<T,U> b){return mp(a.first-b.first, a.second-b.second);}
template<typename T, typename U> pair<T,U> operator+(pair<T,U> a, pair<T,U> b){return mp(a.first+b.first, a.second+b.second);}
template<typename T, typename U> void umin(T& a, U b){if (a > b) a = b;}
template<typename T, typename U> void umax(T& a, U b){if (a < b) a = b;}

#ifdef HOME
#define TAG_LENGTH       25
#define LR_LEFT          left
#define LR_RIGHT         right
#define LR_VALUE         value
#define LR_SECOND_VALUE  mn
#include "C:/C++ libs/print.cpp"
#else
#define showl            42;
#define shows            42;
#define show(...)        42;
#define showm(...)       42;
#define showt(...)       42;
#define printTree(...)   42;
#define printGraph(...)  42;
#define printLRTree(...) 42;
#define printMatrix(...) 42;
#define printWGraph(...) 42;
#define debug     if (false)
#endif

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

    ll n, k, s;
    cin >> n >> k >> s;
    vector<ll> v;
    for (int i = 0; i < k; ++i) {
        v.pb(s);
    }
    ll x = 1e9;
    if (s == x) {
        x = 1;
    }
    for (int i = 0; i < n - k; ++i) {
        v.pb(x);
    }
    cout << v << endl;

    return 0;
}


Measured memory_bytes: 2292
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1e9+7;
main(){
    ll N,M,K;
    cin >> N >> M >> K;
    for(ll i = 0;i <= M;i++){
        for(ll j = 0;j <= N;j++){
            if(i*N + j*M - i*j*2 == K){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

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

//#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  vector<int> v(N);
  rep(i, 0, N) { cin >> v[i]; }
  rep(i, 0, N) rep(j, i + 1, N) {
    if (abs(v[i] - v[j]) % (N - 1) == 0) {
      cout << v[i] << " " << v[j] << endl;
      return 0;
    }
  }

  return 0;
}



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

int main(){
    ll N;
    cin >> N;
    ll ans = N * (N-1) / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// in the name of Allah

#include <bits/stdc++.h>

#define endl '\n'
#define ll long long
#define pb push_back
#define ld double
#define sz(x) ((int) (x.size()))

#define max_n 5123456
#define mod 1000000007
// #define mod 998244353
#define myPrime 97654321

#define fr first
#define se second

using namespace std;

ll add(ll a, ll b) {
	a += b;
	if(a >= mod) return a - mod;
	return a;
}

ll mul(ll a, ll b) {
	a *= b;
	if(a >= mod) return a % mod;
	return a;
}

ll power(ll x, ll y) {
	if(y == 0) return 1;
	ll foo = power(x, y/2);
	foo = mul(foo, foo);
	if(y&1) return mul(x, foo);
	return foo;
}

int n, m, k;
ll dp[123][123];
ll DP[123];

ll get(int len) {
    if(len <= 1) return 1;
    if(DP[len] != -1) return DP[len];
    return DP[len] = add(get(len-1), get(len-2));
}

ll memo(int c, int rows) {
    if(c < 1 || m < c) return 0;
    if(rows == 0) return (c == k);
    if(dp[c][rows] != -1) return dp[c][rows];
    ll res = 0;
    res = add(res, mul(mul(get(c - 2), get(m - c)), memo(c-1, rows-1)));
    res = add(res, mul(mul(get(c - 1), get(m - c)), memo(c, rows-1)));
    res = add(res, mul(mul(get(c - 1), get(m - c - 1)), memo(c+1, rows-1)));
    return dp[c][rows] = res;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m >> k;
	memset(dp, -1, sizeof dp);
	memset(DP, -1, sizeof DP);
	cout << memo(1, n) << endl;
	return 0;
}

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

int main() {
  char s[100001];
  scanf("%s", s);
  int n = strlen(s), r=0, b=0;
  for (size_t i = 0; i < n; i++) {
    if (s[i] == '0') {
      r++;
    } else {
      b++;
    }
  }
  if (r > b) {
    printf("%d\n", n + b - r);
  } else {
    printf("%d\n", n + r - b);
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    string s; cin >> s;
    string t = s;
    SORT(t);
    t.erase(unique(all(t)), t.end());
    cout << (s.length() == t.length() ? "yes" : "no") << "\n";
}

Measured memory_bytes: 256
A,B = map(int, input().split())
if A == 1:
    if B == 1:
        print("Draw")
    else:
        print("Alice")
elif B == 1:
    print("Bob")
else:
    if A > B:
        print("Alice")
    elif A < B:
        print("Bob")
    else:
        print("Draw")

Measured memory_bytes: 3060
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cstring>
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
 
#define VI vector<int>
#define PII pair<int,int>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define lint long long int
 
#define debug(x) {cerr <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; }
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; }
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}
 
#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue
 
#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
 
using namespace std;



 
int main() {
	VI v;
	make2(a, b); v.pb(a); v.pb(b);
	sort(v.begin(), v.end());
	FOR(i,0,2) {
		if (v[i]%3==0) {
			printf("0\n");
			return 0;
		}
	}
	lint best = v[0];
	FOR(i,0,2) {
		FOR(j,1,v[i]) {
			lint phi1 = v[1-i]*1LL*j;
			lint phi2 = (v[i]-j)*1LL*(v[1-i]/2);
			lint phi3 = (v[i]-j)*1LL*((v[1-i]+1)/2);
			best = min(best, max(max(abs(phi1-phi2), abs(phi3-phi1)),abs(phi3-phi2)));
		}
	}
	printf("%lld\n", best);
}


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

using namespace std;

int main(){
    int h,w;
    cin >> h >> w;
    char a[h][w];
    char c;
    for(int i=0;i < h;i++){
        for(int j = 0;j<w;j++){
            cin >> c;
            a[i][j] = c;
        }
    }
    int height = 0;
    int right = 0;
    for(int i=0;i<h;i++){
        for(int j =0;j<w;j++) {
            if(a[i][j] == '#'){
                if(height != i){
                    if(j < right) {
                        cout << "Impossible" << endl;
                        return 0;
                    }
                    height = i;
                }
                right = j;
            }
        }
    }
    cout << "Possible" << endl;
}

Measured memory_bytes: 256