akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int3(int *a1, int *a2, int *a3) {
  scanf("%d %d %d", a1, a2, a3);
  return 0;
}

#define HEIGHT_MAX 100
#define WIDTH_MAX 8
#define DIVISOR 1000000007
#define PATTERN_MAX (1<<(WIDTH_MAX-1))

void swap(int *a, int *b) {
    int tmp = *a;
    *a = *b;
    *b = tmp;
}

void get_next(int pat, int size, int *out) {
    int i, bit;
    for(i = 0; i < size; i++) out[i] = i;
    for(bit = 0; bit < size-1; bit++) {
        if(!(pat & (1<<bit))) continue;
        // swap
        swap(&out[bit], &out[bit+1]);
    }
}

int main(void) {
    int height, width, goal;
    get_int3(&height, &width, &goal);
    // 1-indexed -> 0-indexed
    goal--;
    static int64_t dp[HEIGHT_MAX+2][WIDTH_MAX];
    dp[0][0] = 1;
    int h, w, pat;
    static char pat_valid[PATTERN_MAX];
    static int next_idx[WIDTH_MAX];
    for(pat = 0; pat < (1<<(width-1)); pat++) {
        int bit;
        int prev = 0;
        int flag = 1;
        for(bit = 0; bit < width-1; bit++) {
            int cur = !!(pat & (1<<bit));
            if(prev == cur && cur == 1) { flag = 0; break; }
            prev = cur;
        }
        pat_valid[pat] = flag;
#ifdef DEBUG
        int i;
        printf("%d -> %d\n", pat, pat_valid[pat]);
        get_next(pat, width, next_idx);
        for(i = 0; i < width; i++) printf(" %d", next_idx[i]);
        putchar('\n');
#endif
    }

    for(h = 1; h <= height; h++) {
        for(pat = 0; pat < (1<<(width-1)); pat++) {
            if(!pat_valid[pat]) continue;
            get_next(pat, width, next_idx);
            for(w = 0; w < width; w++) {
                int nidx = next_idx[w];
                dp[h][nidx] = (dp[h][nidx] + dp[h-1][w])%DIVISOR;
#ifdef DEBUG
                printf("[%d] dp[%d][%d] = %lld\n", w, h, nidx, dp[h][nidx]);
#endif
            }
        }
    }
    printf("%d\n", (int)dp[height][goal]);
    return 0;
}

Measured memory_bytes: 128
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a=inp()
        a-=1
        g[i].append(a)
        g[a].append(i)
    return n,g

def main():
    h, w = map(int, input().split())
    maze = [tuple(input()) for _ in range(h)]
    # h,w = inpm()
    # maze = []
    # for _ in range(h):
    #     s = tuple(input())
    #     maze.append(s)
    ans = 0
    dx = (1,0,-1,0)
    dy = (0,1,0,-1)

    for sx in range(h):
        for sy in range(w):
            if maze[sx][sy] == '#':
                continue
            else:
                d = [[-1 for _ in [0]*w] for _ in [0]*h]
                que = deque()
                d[sx][sy] = 0
                que.append((sx,sy))
                M = 0
                while que:
                    (qx,qy) = que.popleft()
                    for i in range(4):
                        nx=qx+dx[i]
                        ny=qy+dy[i]
                        if nx >= 0 and h>nx and ny>=0 and w>ny and maze[nx][ny]=="." and d[nx][ny]==-1:
                            d[nx][ny]=d[qx][qy]+1
                            if d[qx][qy]+1>M:
                                M= d[qx][qy]+1
                            que.append((nx,ny))
                ans = max(ans,M)
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 46936
import java.math.BigInteger;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args){

		solve_abc145_d();
	}
  
  	public static void solve_abc145_d(){

		Scanner sc = new Scanner(System.in);

		final int MOD = 1000000007;

		int X = sc.nextInt();
		int Y = sc.nextInt();

		if((2 * Y - X) % 3 != 0 || (2 * X - Y) % 3 != 0){
			System.out.println(0);
			sc.close();
			return;
		}

		
		int a = (2 * Y - X) / 3;
		int b = (2 * X - Y) / 3;

		int n = a + b;

		//final int MAX = 700000;
		final int MAX = n + 1;
		BigInteger[] fac = new BigInteger[MAX];
		BigInteger[] finv = new BigInteger[MAX];
		BigInteger[] inv = new BigInteger[MAX];


		solve_abc034_c_COMinit(MOD, MAX, fac, finv, inv);
		BigInteger ans = solve_abc034_c_COM(MOD, n, a, fac, finv);

		System.out.println(ans.intValue());
		sc.close();

	}
  
  	public static void solve_abc034_c_COMinit(final int MOD, final int MAX,
			BigInteger[] fac, BigInteger[] finv, BigInteger[] inv ){

		// final int MAX = 510000;
		// final int MOD = 1000000007;

		fac[0] = fac[1] = BigInteger.valueOf(1);
		finv[0] = finv[1] = BigInteger.valueOf(1);
		inv[1] = BigInteger.valueOf(1);

		for(int i=2; i<MAX; i++){
			fac[i] = fac[i-1].multiply(BigInteger.valueOf(i)).mod(BigInteger.valueOf(MOD));
			inv[i] = BigInteger.valueOf(MOD).subtract(inv[MOD%i].multiply(BigInteger.valueOf(MOD/i).mod(BigInteger.valueOf(MOD))));
			finv[i] = finv[i-1].multiply(inv[i]).mod(BigInteger.valueOf(MOD));
		}
	}

	public static BigInteger solve_abc034_c_COM(final int MOD, int n, int k, BigInteger fac[], BigInteger[] finv){

		if(n < k) return BigInteger.valueOf(0);
		if(n < 0 || k < 0) return BigInteger.valueOf(0);
		return fac[n].multiply(finv[k].multiply(finv[n-k]).mod(BigInteger.valueOf(MOD))).mod(BigInteger.valueOf(MOD));
	}
}

Measured memory_bytes: 457232
#include <bits/stdc++.h>
#define LL long long
#define INF (1LL << 60)
using namespace std;

template<class T> inline
void read(T& x) {
	int f = 1; x = 0;
	char ch = getchar();

	while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

/*============ Header Template ============*/

const int N = 100000 + 5;

int n;
int a[N], f[N], vis[N];
std::vector<int> v[N];

int cmp(const int &a, const int &b) {
	return f[a] < f[b];
}

void solve(int x) {
	if (vis[x]) return;
	vis[x] = 1;
	for (int i = 0; i < v[x].size(); i++) solve(v[x][i]);
	sort(v[x].begin(), v[x].end(), cmp);
	int mx = 0;
	for (int i = 0; i < v[x].size(); i++) mx = max(mx + 1, f[v[x][i]] + 1);
	f[x] = mx;
}

int main() {
	read(n);
	for (int i = 2; i <= n; i++) read(a[i]);
	for (int i = 2; i <= n; i++) v[a[i]].push_back(i);
	solve(1);
	printf("%d\n", f[1]);
	return 0;
}

Measured memory_bytes: 13056
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        String[] lines = getStdin();
        
        String[] str = lines[0].split(" ");
        
        String tmp = str[0];
        String tmp1 = str[1];
        String tmp2 = str[2];
        
        str[0] = str[1];
        str[1] = tmp;
        str[0] = str[2];
        str[2] = tmp1;
            for (int i = 0; i < str.length; i++){
                 System.out.print(str[i] + " ");
            }
       
   }
  private static String[] getStdin() {
    Scanner scanner = new Scanner(System.in);
    ArrayList<String> lines = new ArrayList<>();
    while (scanner.hasNext()) {
      lines.add(scanner.nextLine());
    }
    return lines.toArray(new String[lines.size()]);
  }
}

Measured memory_bytes: 26992
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int a,b;
  cin>>a>>b;
  if(a==b){
    cout<<"Draw"<<endl;
  }
  else if(a==1){
    cout<<"Alice"<<endl;
  }
  else if(b==1){
    cout<<"Bob"<<endl;
  }
  else if(a>b){
    cout<<"Alice"<<endl;
  }
  else{
    cout<<"Bob"<<endl;
  }
}

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

int main() {
    int X, N, p;
    cin >> X >> N;
    bool use[100+2] = {};
    rep(i, N) {
        cin >> p;
        use[p] = true;
    }
    int ans = 0;
    rep(i, 102) {
        if (!use[i]) {
            int x = abs(i - X), y = abs(ans - X);
            if (x == y && i < ans) ans = i;
            else if (x < y) ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
using namespace std;
int a,b;
int main()
{
    scanf("%d%d",&a,&b);
    if(a>0)
    puts("Positive");              
    else if(b>=0)
    puts("Zero");             
    else if((a&1)^(b&1))
    puts("Positive");  
    else puts("Negative");
    return 0;
}

Measured memory_bytes: 128
// 2012/11/19 Tazoe

#include <iostream>
using namespace std;

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

		if(n==0)
			break;

		char G[257][257];
		for(int y=1; y<=n; y++){
			for(int x=1; x<=n; x++){
				cin >> G[y][x];
			}
		}

		int dp[4][257][257];
		for(int i=0; i<4; i++){
			for(int y=0; y<=n+1; y++){
				for(int x=0; x<=n+1; x++){
					dp[i][y][x] = 0;
				}
			}
		}

		int dp_max = 0;

		for(int y=1; y<=n; y++){
			for(int x=1; x<=n; x++){
				if(G[y][x]=='1'){
					dp[0][y][x] = dp[0][y-1][x]+1;
					dp[1][y][x] = dp[1][y][x-1]+1;
					dp[2][y][x] = dp[2][y-1][x-1]+1;
					dp[3][y][x] = dp[3][y-1][x+1]+1;

					for(int i=0; i<4; i++){
						if(dp[i][y][x]>dp_max){
							dp_max = dp[i][y][x];
						}
					}
				}
			}
		}

		cout << dp_max << endl;
	}

	return 0;
}

Measured memory_bytes: 2252
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, M;
vector<int> E[101010];
int ans[101010];
bool vis[101010];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M;
	rep(i, 0, M) {
		int a, b; cin >> a >> b;
		a--; b--;
		E[a].push_back(b);
		E[b].push_back(a);
	}

	queue<int> que;
	que.push(0);
	vis[0] = true;

	while (!que.empty()) {
		int cu = que.front(); que.pop();
		fore(to, E[cu]) if (!vis[to]) {
			ans[to] = cu;
			vis[to] = true;
			que.push(to);
		}
	}

	printf("Yes\n");
	rep(i, 1, N) printf("%d\n", ans[i] + 1);
}







Measured memory_bytes: 10716
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
// vector<ll> a;
// vector<ll> dp;
ll a[100010];
ll dp[100010];
const ll n_max = 1LL << 60;
ll rec(int i){
    if(dp[i]<n_max)return dp[i];
    if(i==0)return 0;
    ll res = n_max;
    chmin(res, rec(i-1) + abs(a[i] - a[i - 1])); // 足場 i-1 から来た場合
    if (i > 1) chmin(res, rec(i-2) + abs(a[i] - a[i - 2])); // 足場 i-2 から来た場合

    return dp[i] = res;
}

int main(int argc, char const *argv[])
{
    ll n;cin>>n;
    for(int i=0;i<n;++i)cin>>a[i];
    for(int i=0;i<100010;++i)dp[i]=n_max;

    cout << rec(n-1) << endl;
    return 0;
    
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=1<<17;



int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a+b>=c) puts("Yes");
    else puts("No");
    return 0;
}

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

typedef long long ll;

int main() {
    string input_str;
    cin >> input_str;

    ll ans = 0, N = input_str.size();
    ll i = 0, j, k;
    while(i < N) {
        for(j = i; j < N; j++) {
            if (input_str[j] == 'A' || 
                input_str[j] == 'T' ||
                input_str[j] == 'C' ||
                input_str[j] == 'G') {
                ans = max(ans, j - i + 1);
            } else {
                j++;
                break;
            }
        }
        i = j;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3584
/// Kazuki Hoshino


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define endl '\n'

int n, cnt, c;


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

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);


cin >> n;

rep(i, 1, n){
    if(i%2){
        c=0;
        rep(j, 1, i){
        if(i%j==0)c++;
        }
        if(c==8)cnt++;
    }
}



cout << cnt << endl;






return 0;}
///....


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

int gcd(int a, int b)
{
    if (a < b)
        int c = a, a = b, b = c;

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

int main()
{
    int n, k, g, a_, ma;
    cin >> n >> k;

    ma = 0;
    REP(i, n)
    {
        int a;
        cin >> a;

        ma = max(ma, a);

        if (i == 0)
            g = a;
        else
            g = gcd(a, a_);

        a_ = a;
    }

    if (k % g == 0 && ma >= k)
        cout << "POSSIBLE" << endl;
    else
        cout << "IMPOSSIBLE" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i=(a); i<=int(b); i++)
#define loop(k,a) for (int k=(a); ~k; k=link[k])
using namespace std;
typedef long long LL;
 
const int maxn = 1009, maxm = 10009;
const LL INF = 2e15;
struct edge { int u, v; LL f, c; };
struct ISAP {
	int n, m, s, t, head[maxn], link[maxm];
	int d[maxn], p[maxn], cur[maxn], num[maxn];
	edge e[maxm];
	void init(int _n) {
		n = _n; m = 0;
		memset(head, -1, sizeof head);
		memset(cur, -1, sizeof cur);
	}
	void addEdge(int u, int v, LL w) {
		e[m].u = u; e[m].v = v; e[m].f = 0; e[m].c = w;
		link[m] = head[u]; cur[u] = head[u] = m++;
		e[m].u = v; e[m].v = u; e[m].f = 0; e[m].c = 0;
		link[m] = head[v]; cur[v] = head[v] = m++;
	}
	LL augment() {
		LL mn = INF; int u = t;
		while (u != s) {
			mn = min(mn, e[p[u]].c - e[p[u]].f);
			u = e[p[u]].u;
		}
		u = t;
		while (u != s) {
			e[p[u]].f += mn; e[p[u]^1].f -= mn;
			u = e[p[u]].u;
		}
		return mn;
	}
	LL Maxflow(int _s, int _t) {
		LL res = 0; int u = _s, flag;
		memset(d, 0, sizeof d);
		memset(num, 0, sizeof num);
		s = _s; t = _t; num[0] = n;
		while (d[s] < n) {
			if (u == t) { res += augment(); u = s; }
			flag = 0;
			loop (k, cur[u])
				if (e[k].f < e[k].c && d[u] == d[e[k].v] + 1) {
					p[e[k].v] = cur[u] = k;
					u = e[k].v; flag = 1;
					break;
				}
			if (flag) continue;
			int mn = n;
			loop (k, head[u])
				if (e[k].f < e[k].c)
					mn = min(mn, d[e[k].v] + 1);
			if (--num[d[u]] == 0) return res;
			num[d[u] = mn]++; cur[u] = head[u];
			if (u != s) u = e[p[u]].u;
		}	
		return res;
	}
} G;
int n, S, T, a;
LL sum, tot;

int main() {
	scanf("%d", &n);
	S = n + 1; T = n + 2;
	G.init(n + 2);
	rep (i, 1, n) {
		scanf("%d", &a); tot += a; a = -a;
		if (a > 0) G.addEdge(S, i, a), sum += a;
		else if (a < 0) G.addEdge(i, T, -a);
		rep (j, 2, n/i)
			G.addEdge(i, i*j, INF);
	}
	printf("%lld\n", tot + (sum - G.Maxflow(S, T)));
	return 0;
}

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

void scanArrayInt(int N, int* A){
    int i;
    for(i = 0; i < N; i++){
        scanf("%d", &A[i]);
    }
}

void printArray(int N, int* A){
    int i;
    for(i = 0; i < N - 1; i++){
        printf("%d ", A[i]);
    }
    printf("%d\n", A[N - 1]);
}

void insertionSort(int N, int* A){
    int i, j, v;
    for(i = 1; i < N; i++){
        printArray(N, A);

        v = A[i];
        j = i;
        while(v < A[j - 1] && j > 0){
            A[j] = A[j - 1];
            j--;
        }
        A[j] = v;
    }
}



int main(){
    int N;
    scanf("%d", &N);
    int* A;
    A = (int*)malloc(sizeof(A[0]) * N);
    scanArrayInt(N, A);
    insertionSort(N, A);
    printArray(N, A);
    return 0;
}


Measured memory_bytes: 2128
class Combination:
    """
    SIZEが10^6程度以下の二項係数を何回も呼び出したいときに使う
    使い方:
    comb = Combination(SIZE, MOD)
    comb(10, 3) => 120
    """

    def __init__(self, N, MOD=10 ** 9 + 7):
        self.MOD = MOD
        self.fact, self.inv = self._make_factorial_list(N)

    def __call__(self, n, k):
        if k < 0 or k > n:
            return 0
        res = self.fact[n] * self.inv[k] % self.MOD
        res = res * self.inv[n - k] % self.MOD
        return res

    def _make_factorial_list(self, N):
        fact = [1] * (N + 1)
        inv = [1] * (N + 1)
        MOD = self.MOD
        for i in range(1, N + 1):
            fact[i] = (fact[i - 1] * i) % MOD
        inv[N] = pow(fact[N], MOD - 2, MOD)
        for i in range(N, 0, -1):
            inv[i - 1] = (inv[i] * i) % MOD
        return fact, inv


if __name__ == "__main__":
    N, M, K = map(int, input().split())
    mod = 998244353
    comb = Combination(N + 10, mod)

    ans = 0
    for i in range(K + 1):
        p = comb(N - 1, i) * M * pow(M - 1, N - i - 1, mod) % mod
        ans = (ans + p) % mod
    print(ans)

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
Pii P[int(2e5+5)];

int main(){
  cin >> N;
  for (int i = 0; i < N; i++){
    cin >> P[i].fi;
    P[i].se = i;
  }
  sort(P, P + N);

  int cnt = 1, ans = 0;
  for (int i = 1; i < N; i++){
    if (P[i-1].se < P[i].se){
      cnt++; continue;
    }else{
      ans = max(ans, cnt);
      cnt = 1;
    }
  }
  ans = max(ans, cnt);
  cout << N - ans << endl;


  return 0;
}


Measured memory_bytes: 5176
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
    #include <atcoder/all>
#endif
using namespace std;
using namespace atcoder;
namespace defines{
    typedef long long ll;
    typedef pair<ll,ll> P;
    #define FOR(i,a,b) for(ll i = a ; i < b ; i++) // for i in range(a,b)
    #define REP(i,n) for(ll i = 0 ; i < n ; i++) // for i in range(b)
    #define FORD(i,a,b) for(ll i = a ; i > b ; i--) // for i in range(a,b,-1)
    #define ALL(x) x.begin(),x.end()
    template<class T> vector<T> make_vec(size_t a){return vector<T>(a);}
    template<class T, class... Ts> auto make_vec(size_t a, Ts... ts){ return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));}

    /* for debug print */
    #define DEBUG(x) cerr << #x << ": " << x << '\n'
    #define DEBUGP(x) cerr << #x << ": (" << x.first << ", " << x.second << ")" << '\n' 
    #define DEBUGL(xl) dbgl_f(#xl,xl)
    #define DEBUGLP(xl) dbglp_f(#xl,xl)
    #define DEBUGLL(xll) dbgll_f(#xll,xll)
    #define DEBUGM(xl) dbgm_f(#xl,xl)
    template<class T> void dbgl_f(string name, vector<T> xl){cerr<<name<<": "; for(T x: xl) cerr<<x<<" "; cerr << '\n';}
    template<class T, class U> void dbgm_f(string name, map<T,U> xl){cerr<<name<<": ";for(auto x: xl)cerr<<"("<<x.first<<": "<<x.second<<") ";cerr<<'\n';}
    template<class T> void dbglp_f(string name, vector<T> xl){cerr<<name<<": ";for(T x: xl)cerr<<"("<<x.first<<", "<< x.second<<") ";cerr<<'\n';}
    template<class T> void dbgll_f(string name, vector<vector<T>> xll){
        cerr<< name << ": " << '\n'; 
        for(vector<T> xl: xll){
            for(T x : xl) cerr << x << " ";
            cerr << '\n';
        }
    }
}
using namespace defines;

const int IINF = 1'001'001'001;
const ll INF = 1'001'001'001'001'001'001ll;
const int MOD = 1'000'000'007;

using mint = modint998244353;
vector<mint> keta_to_mint10(200001);
vector<mint> keta_to_mint(200001);

// lazy_segtree<S, op, e, F, mapping, composition, id> seg(int n);

struct S{
    mint v;
    int keta;
    S() : v(1), keta(1) {}
    S(mint v, int keta) : v(v), keta(keta) {}
};

S op(S a, S b){
    return S{a.v*keta_to_mint10[b.keta] + b.v, a.keta+b.keta};
}

S e(){ return S{0,0}; }

using F = int;
const F ID = 0;

S mapping(F f, S x){
    if( f == ID ) {
        return x;
    } else {
        return S{keta_to_mint[x.keta]*f, x.keta};
    }
}

F composition(F f, F g){
    if( f == ID ) return g;
    else return f;
}

F id(){return ID;}

void solve(){
    int n,q; cin >> n >> q;
    keta_to_mint10[0] = 1;
    FOR(i,1,200001){
        keta_to_mint10[i] = keta_to_mint10[i-1]*10;
        keta_to_mint[i] = (keta_to_mint10[i]-1)/9;
    }
    // DEBUG(keta_to_mint10[2].val());
    // DEBUG(keta_to_mint[2].val());

    vector<S> vals(n); 
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(vals);
    // cout << seg.all_prod().v.val() << endl;
    REP(i,q){
        int l,r,d; cin >> l >> r >> d;
        seg.apply(l-1,r,d);
        cout << seg.all_prod().v.val() << endl;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}

Measured memory_bytes: 11424
import sys

input = sys.stdin.readline


def main():
    N, M = [int(x) for x in input().split()]

    if M < N * 2:
        print(M // 2)
    else:
        ans = N
        M = M - N * 2
        ans += M // 4
        print(ans)
        

if __name__ == '__main__':
    main()



Measured memory_bytes: 2940
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const double PI=3.141592653589;
const ll INF=1000000007;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);ll c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};


int main(){
  int n,r; cin>>n>>r;
  if(n>=10)
  cout<<r<<endl;
  else
  cout<<r+100*(10-n)<<endl;

  return 0;
}


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

#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9

using namespace std;

int main(){
  string target;
  while(getline(cin, target) and target != "."){
    stack<char> st;
    bool consistent = true;
    REP(i, target.size()){
      if(target[i] == '(') st.push('(');
      if(target[i] == ')') { if(!st.empty() and st.top() == '(') st.pop(); else consistent = false; }
      if(target[i] == '[') st.push('[');
      if(target[i] == ']') { if(!st.empty() and st.top() == '[') st.pop(); else consistent = false; }
      if(!consistent) break;
    }
    if(!st.empty()) consistent = false;
    cout << (consistent ? "yes" : "no") << endl;
  }
  return 0;
}

Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INF INT_MAX/10

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int main() {
  int N, T, S; cin >> N >> T >> S;
  cout << min(N*T, S) << endl;
}


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

int main(){
	int n;
	cin>>n;
	int a, b, c;
	while(cin>>a>>b>>c){
		int ansflg = false;
		if(a*a==b*b+c*c) ansflg = true;
		if(b*b==a*a+c*c) ansflg = true;
		if(c*c==b*b+a*a) ansflg = true;
		if(ansflg)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
	return 0;
}

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

using namespace std;

int main() {
	// freopen("input.txt", "r", stdin);
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;

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

	vector<bool> used(n, false);
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		if (used[i])
			continue;

		int local_ans = 0;
		for (int j = i; j + 1 < n; ++j) {
			if (a[j + 1] > a[j])
				break;
			used[j + 1] = true;
			++local_ans;
		}

		ans = max(ans, local_ans);
	}

	cout << ans << "\n";
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>


using namespace std;
using namespace __gnu_pbds;
#define MOD  1000000007
#define ll long long
#define int long long
#define INF 1e18
#define ar array
#define MAX 1000004
#define wt(x) int x;cin>>x;while(x--)

typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> pbds;

void  c_p_c(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
 
#ifndef ONLINE_JUDGE
  freopen("input1.txt","r",stdin);
  freopen("output1.txt","w",stdout);
#endif
 
}
ll power(ll a,ll b,int mod){
    a=a%mod;
    if(a==0){
        return 1;
    }
    ll res=1;
    while(b){
        if(b&1){
            res=(res*a)%mod;
        }
        b>>=1;
        a=(a*a)%mod;
    }
    return res;
 }
 
  

 int32_t main() {

c_p_c();
ll n;
    cin>>n;
    ll a[n];
    ll hi = 1e18, prod = 1;
    int flag = 0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i] == 0)
            flag = 1;
    }
 
    if(flag){
        cout<<"0\n";
        return 0;
    }
    
    for(int i=0;i<n;i++){
        if(a[i] <= hi/prod)
            prod *= a[i];
        else{
            prod = -1;
            break;
        }
    }
 
    if(prod > hi)
        prod = -1;
    cout<<prod<<endl;


    

return 0;

}
 


   

        


Measured memory_bytes: 4428
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fi first
#define sc second
#define ALL(x) x.begin(), x.end()
#define RALL(X) x.begin(), x.end()
#define FOR(i, n, k) for(i=0; i<n; i+=k)
#define FO(i, n, k) for(i=1; i<=n; i+=k)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define N 100005
#define mid ((l+r)/2)
#define dbg(x) (cerr << #x << " : " << x << endl)
#define endl "\n"
#define MOD 100000009

using namespace std;

typedef long long lli;
#define int long long

signed main(){
	ios_base::sync_with_stdio(false);
	int n, k, q;
	cin >> n >> k >> q;
	map <int, int> ar;
	
	for(int i=0; i<q; i++){
		int x;
		cin >> x;
		ar[x]++;
	}

	for(int i=1; i<=n; i++){
		if(k > q-ar[i]){
			cout << "Yes" << endl;
		}else
			cout << "No" << endl;
	}	
	return 0;
}

Measured memory_bytes: 6912
a,b,c=map(int,input().split())
if a==b and b==c and a%2==0 and b%2==0 and c%2==0:
    print(-1)
else:
    k=0
    while a%2==0 and b%2==0 and c%2==0:
        A=a
        B=b
        C=c
        a=B//2+C//2
        b=A//2+C//2
        c=A//2+B//2
        k+=1
    print(k)

Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
using LL = long long;

int main(){
    LL N;
    cin >> N;
    LL n = N;
    LL d = 1;
    int count = 0;
    while(n >= 10){
        d *= 10;
        n /= 10;
        count++;
    }
    int mdig = N/d;
    if(N < 10)  cout << N << endl;
    else if((N+1)%d == 0)   cout << count*9+mdig << endl;
    else    cout << count*9+mdig-1 << endl;
}

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

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;

constexpr int MAXN = 1000;

ui a[MAXN + 2];
ull psum[(MAXN + 1) * MAXN / 2 + 2];

int main() {
	int N, K;
	cin >> N >> K;
	for(int i = 0; i < N; i++)
		cin >> a[i];
	int npsum = (N + 1) * N / 2;
	for(int i = 0, k = 0; i < N; i++) {
		ull sum = 0;
		for(int j = i; j < N; j++) {
			sum += a[j];
			psum[k++] = sum;
		}
	}
	for(ull k = 1ull << 40; k; k >>= 1) {
		int i = 0, j = npsum - 1;
		while(i < j) {
			while(i < j && psum[i] & k)
				i++;
			while(i < j && !(psum[j] & k))
				j--;
			swap(psum[i], psum[j]);
		}
		if(i >= K)
			npsum = i;
	}
	ull ans = psum[0];
	for(int i = 1; i < npsum; i++)
		ans &= psum[i];
	cout << ans << endl;
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
int n,k,a,b,s=0;
cin>>n>>k>>a>>b;
if(n>k)
{
    s+=k*a+(n-k)*b;
}
else
{
    s+=n*a;
}
cout<<s;
return 0;
}


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

//C++14 (GCC 5.4.1)
int main() {
    int A,B;
    cin >>A>>B;
    //-----------------------------------
    bool is=(A<=8&& B<=8);

    cout << ((is) ? "Yay!" : ":(") <<endl;
    return (0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
struct edge{int from,to,cost;};
signed main(){
  int a;
  cin>>a;
  vector<int> b(a);
  rep(i,a)
    cin>>b[i];
  int ans=0;
  bool s=0;
  bool g=0;
  rep(i,a-1){ 
  if(b[i]<b[i+1])
    s=1;
  if(b[i]>b[i+1])
    g=1;
    if(s&&g){
    s=0;
    g=0;
    ans++;
    }
  }
  cout<<ans+1<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define   ll            long long int
#define   endl          "\n"
#define   vi            vector<int>
#define   vll           vector<ll>
#define   pb            push_back
#define   all(p)        p.begin(),p.end()
#define   F             first
#define   S             second
#define   mp            make_pair
using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    int t=1;
    while(t--){
        string s,t;
        int mn=INT_MAX,cnt,c;
        cin>>s>>t;
        int x=s.size();
        int y=t.size();

        for(int i=0;i<=x-y;i++){
            c=0,cnt=0;
            for(int j=i; ;j++){
                if(s[j]!=t[c])cnt++;
                c++;
                if(c==y)break;
            }
            if(cnt<mn) mn=cnt;
        }
        cout<<mn<<endl;
    }


return 0;
}





Measured memory_bytes: 3652
#include<stdio.h>
#define max(x,y) ((x)>(y)?(x):(y))
#define rpt(n) for(register int ttxyc=0;ttxyc<(n);++ttxyc)//宏定义
inline int read()//快读
{
	register int x=0,t=0;register char c=getchar();for(;c<'0'||c>'9';t|=c=='-',c=getchar());
	for(;c>='0'&&c<='9';x=(x<<3)+(x<<1)+(c^48),c=getchar());return t?-x:x;
}
int n,l,maxn,sum;
main()
{
	n=read();rpt(n){l=read();maxn=max(maxn,l);sum+=l;}
	if(sum-maxn<=maxn)puts("No");
	else puts("Yes");
}/**/

Measured memory_bytes: 128
N,M = [int(i) for i in input().split()]
An = []
Am = []
for i in range(N):
    a = input()
    An.append(a)
for i in range(M):
    a = input()
    Am.append(a)

a = 0
b = 0

for i in range(N-M+1):
    for j in range(N-M+1):
        for k in range(M):
            for l in range(M):
                if An[i][j] == Am[0][0]:
                    if An[i+l][j+k] == Am[l][k]:
                        a += 1
                        if a == M*M:
                            b = 1
                        continue
                    else:
                        a = 0
                        break
                else:
                    a = 0
                    break

if b == 1:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    a=parseInt(readline())
    println(n^2-a)
end
main()

Measured memory_bytes: 165148
# -*- coding: utf-8 -*-
from sys import stdin

A = stdin.readline().rstrip()
B = stdin.readline().rstrip()
C = stdin.readline().rstrip()
turn = "a"

for i in range(300):
    if turn == "a":
        if A != "":
            turn = A[0]
            A = A[1:]
        else:
            print("A")
            exit()
    elif turn == "b":
        if B != "":
            turn = B[0]
            B = B[1:]
        else:
            print("B")
            exit()
    elif turn == "c":
        if C != "":
            turn = C[0]
            C = C[1:]
        else:
            print("C")
            exit()

Measured memory_bytes: 3064
a,b,c,k = [int(i) for i in input().split(' ')]
ret = [a,b,c]
A = 1*a
B = 0
C = -1*c

if a >= k:
    print(1*k)
elif sum(ret[:2]) >= k:
    print(A)
elif sum(ret) > k:
    tmp = k - a - b 
    print(A+(tmp* -1))
else:
    #sum == k
    print(A+B+C)


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

int main (){
    int A;
    cin>>A;
    bool t=false;
    for(int i=0; i<50001; i++){
      	int S=i*0.08;
        if((i+S)==A){
            cout<<i<<endl;
            t=true;
            break;
        }
    }
    if(!t){
        cout<<":("<<endl;
    }
  	
	
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);

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

int main() {
    char c[4]; cin >> c;
    
    int ans = 0;
    for (auto a : c) {
        if (a == '+') {
            ans++;
        } else {
            ans--;
        }
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int read()
{
  int x=0,f=1;
  char ch=getchar();
  while((ch<'0')||(ch>'9'))
    {
      if(ch=='-')
        {
          f=-f;
        }
      ch=getchar();
    }
  while((ch>='0')&&(ch<='9'))
    {
      x=x*10+ch-'0';
      ch=getchar();
    }
  return x*f;
}

const int maxn=3000;
const int mod=1000000007;

int n,k,f[maxn+10][maxn+10][2],ans;

int main()
{
  n=read();
  k=read();
  for(int i=0; i<=n; ++i)
    {
      f[0][i][(i==0)]=1;
    }
  for(int i=0; i<k; ++i)
    {
      for(int j=0; j<=n; ++j)
        {
          for(int sta=0; sta<2; ++sta)
            {
              if(j>0)
                {
                  f[i+1][j-1][sta|(j==1)]+=f[i][j][sta];
                  if(f[i+1][j-1][sta|(j==1)]>=mod)
                    {
                      f[i+1][j-1][sta|(j==1)]-=mod;
                    }
                  f[i+1][j][sta|(j==1)]+=f[i][j][sta];
                  if(f[i+1][j][sta|(j==1)]>=mod)
                    {
                      f[i+1][j][sta|(j==1)]-=mod;
                    }
                }
              if(j<n)
                {
                  f[i+1][j+1][sta]+=f[i][j][sta];
                  if(f[i+1][j+1][sta]>=mod)
                    {
                      f[i+1][j+1][sta]-=mod;
                    }
                  f[i+1][j][sta]+=f[i][j][sta];
                  if(f[i+1][j][sta]>=mod)
                    {
                      f[i+1][j][sta]-=mod;
                    }
                }
            }
        }
    }
  for(int i=0; i<=n; ++i)
    {
      ans+=f[k][i][1];
      if(ans>=mod)
        {
          ans-=mod;
        }
    }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 70784
import itertools

N, M = map(int, input().split())
lst = [set() for _ in range(N + 1)]
for _ in range(M):
    a, b = map(int, input().split())
    lst[a].add(b)
    lst[b].add(a)

ans = 0
for t in itertools.permutations(range(2, N + 1)):
    tmp = 1
    for x in t:
        if x not in lst[tmp]:
            break
        tmp = x
    else:
        ans += 1
print(ans)


Measured memory_bytes: 3064
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

#from fractions import gcd

def gcd(a, b): 
    if a == 0: return b 
    if b == 0: return a 
    k = 0
    while ((a | b) & 1) == 0: 
        a >>= 1
        b >>= 1
        k += 1
    while (a & 1) == 0: 
        a >>= 1
    while b:  
        while (b & 1) == 0: 
            b >>= 1
        if a > b : 
            a,b = b,a
        b = b - a 
    return a << k 

from math import sqrt
def pfact(num):
    global dt
    if num&1 == 0:
        num >>= 1
        if dt[2]:
            dt[2] = 0
        else:
            return 'setwise coprime'
    while num&1 == 0:
        num >>= 1
    for i in range(3,int(sqrt(num))+1,2):
        if num%i == 0:
            num //= i
            if dt[i]:
                dt[i] = 0
            else:
                return 'setwise coprime'
        while num%i == 0:
            num //= i
    if num>2:
        if dt[num]:
            dt[num] = 0
        else:
            return 'setwise coprime'
    return 'pairwise coprime'

n = inp()
x = ip()
x.sort(reverse=True)
t = x[0]
for i in range(1,n):
    t = gcd(t,x[i])
    if t == 1:
        break
if t != 1:
    ans = 'not coprime'
else:
    ans = 'pairwise coprime'
    dt = {i+1:1 for i in range(10**6)}
    for i in x:
        if pfact(i) == 'setwise coprime':
            ans = 'setwise coprime'
            break
print(ans)


Measured memory_bytes: 215892
#include <bits/stdc++.h>
#define ll long long
#define N 100005
using namespace std;
ll n,ds,d[N],sz[N];map<ll,int>S;pair<int,int>v[N];
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&d[i]),S[d[i]]=i,sz[i]=1;
	sort(d+1,d+n+1);
	for(int i=n;i>1;i--)
    {
		int p=S[d[i]];ll d2=d[i]-(n-sz[p])+sz[p];
		if(S.find(d2)==S.end()){puts("-1");return 0;}
		int q=S[d2];sz[q]+=sz[p];ds+=sz[p];
		v[n-i+1]=make_pair(p,q);
	}
	if(d[1]!=ds){puts("-1");return 0;}
	for(int i=1;i<n;i++) printf("%d %d\n",v[i].first,v[i].second);
}

Measured memory_bytes: 12396
// Created by ...Lusifer
#include<bits/stdc++.h>
using namespace std;
 
#define pb 		push_back
#define mp 		make_pair
#define prior   priority_queue
#define MOD 	1000000007
#define INF64 	(long long)1e18
#define INF 	(int)1e9
#define PI 		3.1415926535897932384626433832795 
#define ll      long long
#define ld		long double
#define ret     return
#define NUM 	1000001
const int SIZE = 2e5+4;
void fastio(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

void solveTest(){
	ll n;
	cin>>n;
	cout<<n*(n-1)/2<<endl;
	return ;
}
 
int main(){
	fastio();

	int t=1;
	//cin>>t;
	while(t--){
		solveTest();
 
	}
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {

	int r;
	cin >> r;
	cout << r*r << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int int64_t
#define pii pair<int,int>
#define rep(i,n) for(int i = 0;i < (n);++i)
#define reps(i,n) for(int i = 1;i <= (n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(10)
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr long long mod = 1000000007;
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string x;
    cin >> x;
    int n = x.size();
    int s = 0,sum = 0;
    bool flg = false;
    rep(i,n){
        if(x[i] == 'S'){
            ++s;
        }
        else{
            if(s){
                --s;
            }
            else{
                ++sum;
            }
        }
    }

    cout << s + sum << '\n';

    return 0;
}

Measured memory_bytes: 720
n=int(input())
dic_name={}
dic_num={}
S=[]
P=[]
for i in range(n):
    s,p=input().split()
    S.append(s)
    P.append(int(p))
    dic_name.setdefault(S[i],[]).append(P[i])
    dic_num.setdefault(S[i],[]).append(i+1)
S=sorted(S)

i=0
while(i<n):
    arr_name=list(dic_name[S[i]])
    arr_num=list(dic_num[S[i]])
    for a in range(len(arr_name)):#bubble sort
        for b in range(a,len(arr_name)):
            if arr_name[a]<arr_name[b]:
                arr_name[a],arr_name[b]=arr_name[b],arr_name[a]
                arr_num[a],arr_num[b]=arr_num[b],arr_num[a]#sort num
                
    for a in range(len(arr_name)):
        print(arr_num[a])
    i+=len(dic_name[S[i]])
    

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

int main(void) {
  int n, m; cin >> n >> m;
  vector<vector<int>> a;
  for (int i=0; i<n; i++) {
    int k, t; cin >> k;
    vector<int> tmp;
    for (int j=0; j<k; j++) {
      cin >> t;
      tmp.push_back(t);
    }
    a.push_back(tmp);
  }
  
  int cnt = 0;;
  for (int k=1; k<m+1; k++) {
    int flag = 0;
    for (int i=0; i<n; i++) {
      for (int j=0; j<a[i].size(); j++) {
        if (a[i][j] == k) flag++;
      }
    }
    if (flag == n) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
const ll MOD=1000000007;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const vector<pll> dir={{0,1},{1,0},{-1,0},{0,-1},{1,1},{-1,1},{1,-1},{-1,-1}};
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=b-1;i>=a;i--)
#define range(i) (i).begin(),(i).end()
#define rrange(i) (i).rbegin(),(i).rend()
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm (ll a,ll b) {return a*b/gcd(a,b);}
inline constexpr int intpow(ll a,ll b){
    if(b==0) return 1;
    ll ans=intpow(a,b/2);
    return ans*ans%MOD*(b&1?a:1)%MOD;
}
inline constexpr int modf(ll n){
    ll ans=1;
    rep(i,0,n) {ans=ans*(n-i)%MOD;}
    return ans;
}

vector<ll> func,inv;
void init(ll n){
    func.resize(n+1);inv.resize(n+1);
    func[0]=1;
    rep(i,0,n) {func[i+1]=func[i]*(i+1)%MOD;}
    inv[n]=intpow(func[n],MOD-2);
    rrep(i,1,n+1) {inv[i-1]=inv[i]*i%MOD;}
}
ll comb(ll a,ll b) {return func[a]*inv[b]%MOD*inv[a-b]%MOD;}

inline long double median(vector<ll> v){
    ll size=v.size();
    sort(v.begin(),v.end());
    if (size % 2 == 1) return v[(size - 1) / 2];
    else return v[(size / 2) - 1] ;
}
template<class T> inline bool chmax(T& a,T b) {if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b) {if(a>b){a=b;return 1;} return 0;}

int main(){
    ll m,d,cnt=0;
    cin>>m>>d;
    rep(i,1,d+1) rep(j,1,m+1) {
        if(i/10<2||i%10<2) continue;
        if((i/10)*(i%10)==j) cnt++;
    }
    cout<<cnt;
}

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

using namespace std;

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

    vector <int> height(no_of_stones + 1, 0);
    for(int i = 1; i <= no_of_stones; i++)
        cin >> height[i];

    vector <int> minimum_cost(no_of_stones + 1);
    minimum_cost[2] = abs(height[2] - height[1]);
    for(int i = 3; i <= no_of_stones; i++)
        minimum_cost[i] = min(minimum_cost[i - 1] + abs(height[i] - height[i - 1]),
                              minimum_cost[i - 2] + abs(height[i] - height[i - 2]));

    cout << minimum_cost[no_of_stones];
    return 0;
}

Measured memory_bytes: 1024
import static java.lang.System.*;
import java.util.*;

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

        int h = sc.nextInt();
		int w = sc.nextInt();
		boolean[][] map = new boolean[h][w];
		for(int i=0; i<h; i++) {
			char[] cmap = sc.next().toCharArray();
			for(int j=0; j<w; j++) map[i][j] = cmap[j] == '.';
		}
			
		int[][][] cost = new int[h][w][4];
		for(int i=0; i<h; i++) 
			for(int j=0; j<w; j++) Arrays.fill(cost[i][j], 0);
		
		//left down
		for(int i=0; i<h; i++) {
			for(int j=0; j<w; j++) {
				if(map[i][j]) {
					cost[i][j][0] = 1;
					if(j>0) cost[i][j][0] += cost[i][j-1][0];
					
					cost[i][j][2] = 1;
					if(i>0) cost[i][j][2] += cost[i-1][j][2];
				}
			}		
		}

		//right up
		for(int i=h-1; i>=0; i--) {
			for(int j=w-1; j>=0; j--) {
				if(map[i][j]) {
					cost[i][j][1] = 1;
					if(j<w-1) cost[i][j][1] += cost[i][j+1][1];

					cost[i][j][3] = 1;
					if(i<h-1) cost[i][j][3] += cost[i+1][j][3];
				}
			}		
		}

		int ans = Integer.MIN_VALUE;
		for(int i=0; i<h; i++) {
			for(int j=0; j<w; j++) {
				int csum = 1;
				for(int k=0; k<4; k++) csum += cost[i][j][k]-1;
				ans = Math.max(ans, csum);
			}
		}
		
/*
		for(int k=0; k<4; k++) {
			for(int i=0; i<h; i++) {
				for(int j=0; j<w; j++) {
					out.printf("%2d ",cost[i][j][k]);
				}
				out.println();
			}
			out.println();
		}
*/

        out.println(ans);
    }
}


Measured memory_bytes: 284692