akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1){
            res *= a; if(mod>=1) res %= mod;
        }
        a *= a; if(mod>=1) a %= mod;
        n >>= 1;
    }
    return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a[LIMIT2]={0},b[LIMIT1]={0},c[LIMIT1]={0};
  char s[LIMIT1];
  
  scanf("%lld %lld",&n,&m);
  rep(i,m){
    scanf("%d %d",&a[i],&b[i]);
    if(a[i]==1) c[b[i]-1] |= 1;
    else if(b[i]==n) c[a[i]-1] |= 2;
  }
  rep(i,n){
    if(c[i]==3){
      result = 1;
      break;
    }
  }
  if(result==1) printf("POSSIBLE");
  else printf("IMPOSSIBLE");
  return 0;
}



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

int main(void){
    string s;
    ll K;
    cin >> s >> K;
    for(int i = 0; i < s.size(); i++) s[i] -= 'a';

    char z = 'z' - 'a';
    for(int i = 0; i < s.size() - 1; i++){
        if(s[i] == 0) continue;
        if(s[i] + K > z){
            K -= z+1 - s[i];
            s[i] = 0;
        }
    }

    K = K % (z+1);
    char& last = s[s.size() - 1];
    last = (last + K) % (z+1);

    for(int i = 0; i < s.size(); i++){
        printf("%c", s[i] + 'a');
    }
    printf("\n");
    return 0;
}

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


int main(){
	int N;
	cin >> N;
	// For cost of X
	// You have to pay X * 1.08
	// If you pay N
	// Find the possible value of X
	for(int x = 0; x <= 50000; x++){
		if((int) (x*1.08) == N){
			cout << x;
			return 0;
		}
	}
	cout << ":(";
}


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

int main()
{
  int a,b;
  cin>>a>>b;
  if(a%3==0)
  {
    cout<<"Possible";
    return 0;
  }
  if(b%3==0)
  {
    cout<<"Possible";
    return 0;
  }
  if((a+b)%3==0)
  {
    cout<<"Possible";
    return 0;
  }
  cout<<"Impossible";
  return 0;
}

Measured memory_bytes: 256
#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 int INF=1000000001;
const double PI=3.141592653589;


int main(){
  int x,y,z; cin>>x>>y>>z;
  x-=2*z;
  int ans=x/(y+z);
  int sa=x%(y+z);
  if(sa>=y)
  ans++;
  cout<<ans<<endl;

  return 0;
}


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

using namespace std;

int n,m,a[210],odd,b[210];
int main()
{
	scanf("%d%d",&n,&m); odd=0;
	for(int i=1;i<=m;i++)
		scanf("%d",&a[i]),odd+=(a[i]&1);
	if(odd>2) {printf("Impossible\n"); return 0;}
	for(int i=2;i<=m;i++)
	{
		if(a[i]%2==0) continue;
		if(a[1]%2==0) swap(a[i],a[1]);
		else swap(a[i],a[m]);
	}
	for(int i=1;i<=m;i++) printf("%d ",a[i]); printf("\n");
	if(m==1) {
		if(n==1) printf("1\n1\n");
		else printf("2\n%d %d\n",n-1,1); 
		return 0;}
	b[1]=a[1]-1;
	for(int i=2;i<m;i++) b[i]=a[i];
	b[m]=a[m]+1;
	printf("%d\n",m-(b[1]==0));
	for(int i=1+(b[1]==0);i<m;i++)
		printf("%d ",b[i]);
	if(b[m]) printf("%d\n",b[m]);
	return 0 ;
}

Measured memory_bytes: 256
fn main() {
    let (n, m): (usize, usize) = readln();

    let mut cf = vec![false; n];
    let mut ce = vec![false; n];

    let edges: Vec<(usize, usize)> = readlns(m);

    for &(mut a, mut b) in &edges {
        a -= 1;
        b -= 1;
        if a > b {
            std::mem::swap(&mut a, &mut b);
        }
        if a == 0 {
            cf[b] = true;
        }
        if b == n - 1 {
            ce[a] = true;
        }
    }

    let ans = (0..n).any(|i| cf[i] && ce[i]);
    if ans {
        println!("POSSIBLE");
    } else {
        println!("IMPOSSIBLE");
    }
}

// --- template ---
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

pub trait FromLn {
    fn fromln(s: &str) -> Self;
}
pub fn readln<T: FromLn>() -> T {
    let mut buf = String::new();
    let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
    T::fromln(buf.trim())
}
pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
    let mut vs = vec![];
    for _ in 0..n {
        vs.push(readln());
    }
    vs
}
macro_rules! fromln_primitives {
    ($($t:ty),*) => { $(
        impl FromLn for $t {
            fn fromln(s: &str) -> $t {
                s.parse().unwrap()
            }
        }
    )* }
}
fromln_primitives!(
    String,
    bool,
    f32,
    f64,
    isize,
    i8,
    i16,
    i32,
    i64,
    usize,
    u8,
    u16,
    u32,
    u64
);
impl<T> FromLn for Vec<T>
where
    T: FromLn,
{
    fn fromln(s: &str) -> Vec<T> {
        s.split_whitespace().map(T::fromln).collect()
    }
}
impl FromLn for Vec<char> {
    fn fromln(s: &str) -> Vec<char> {
        s.chars().collect()
    }
}
macro_rules! fromln_tuple {
    ($($t:ident),*) => {
        impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
            fn fromln(s: &str) -> ($($t),*) {
                let mut it = s.split_whitespace();
                let t = ($($t::fromln(it.next().unwrap())),*);
                assert_eq!(it.next(), None);
                t
            }
        }
    }
}
fromln_tuple!(A, B);
fromln_tuple!(A, B, C);
fromln_tuple!(A, B, C, D);
fromln_tuple!(A, B, C, D, E);
fromln_tuple!(A, B, C, D, E, F);


Measured memory_bytes: 9284
#coding:utf-8
#1_5_A
from itertools import combinations

n = int(input())
A = list(map(int, input().split()))
q = int(input())
ms = list(map(int, input().split()))

numbers = set()
for i in range(1, n+1):
    for com in combinations(A, i):
        numbers.add(sum(com))

for m in ms:
    if m in numbers:
        print("yes")
    else:
        print("no")

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int D;
    cin >> D;
    cout << "Christmas";
    REP(i, 25 - D)
    {
        cout << " Eve";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {
    int N;
    int[] V,C;
    private void solve() {
        N = nextInt();
        V = new int[N];
        for(int i = 0;i < N;i++) {
            V[i] = nextInt();
        }

        C = new int[N];
        for(int i = 0;i < N;i++) {
            C[i] = nextInt();
        }

        int ans = 0;
        for(int i = 0;i < N;i++) {
            ans += Math.max(0, V[i] - C[i]);
        }

        out.println(ans);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 20820
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int max = Integer.max(a, c);
        int min = Integer.min(b, d);

        int cul = 0;
        if(min-max > 0) {
            cul = min-max;
        }
        System.out.println(cul);
    }
}

Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
int main()
{
    double x,a,b;
    long long co=0;
    cin>>x;
    a=100;
    b=0.01;
    while(a<x)
    {
        long long c=a*b;
        a+=c;
        co++;
    }
    cout<<co<<endl;
  return 0;
}

Measured memory_bytes: 3720
a_,b_ = map(int, (raw_input().strip().split(" ")))
foo = []
for i,a in enumerate(range(a_)):
    foo = raw_input().strip().split(" ")
    for j in range(b_):
        if foo[j] == 'snuke':
            print(chr(65 + j) + str(i + 1))


Measured memory_bytes: 2692
#include <iostream>
using namespace std;
int main(){
  int A, B;
  cin >> A >> B;
  if(A == B){
    cout << "Draw" << endl;
  }if(A > B and B != 1){
    cout << "Alice" << endl;
  }if(B > A and A != 1){
    cout << "Bob" << endl;
  }if(A == 1 and B != 1){
    cout << "Alice" << endl;
  }if(B == 1 and A != 1){
    cout << "Bob" << endl;
  }
}
    


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int N = Integer.parseInt(sc.next());
		String s[] = new String[N];
		for(int i=0;i<N;i++){
			s[i] = sc.next();
		}
		int M = Integer.parseInt(sc.next());
		String t[] = new String[M];
		for(int i=0;i<M;i++){
			t[i] = sc.next();
		}
		int ans = 0;
		for(int i=0;i<N;i++){
			int cnt = 0;
			for(int j=0;j<N;j++){
				if(s[i].equals(s[j])){
					cnt++;
				}
			}
			for(int j=0;j<M;j++){
				if(s[i].equals(t[j])){
					cnt--;
				}
			}
			if(cnt>0 && cnt> ans){
				ans = cnt;
			}
		}
		out.println(ans);
		out.flush();	
	}
}

Measured memory_bytes: 21716
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
int n, k, q;
vector<vector<pair<ll,ll> > > v(100000);
vector<ll> d(100000);
vector<bool> used(100000,false);
void dfs(ll k,ll score){
    d[k]=score;
    used[k]=true;
    for(int i=0;i<v[k].size();i++){
        if(used[v[k][i].first])continue;
        dfs(v[k][i].first,score+v[k][i].second);
    }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 0; i < n-1; i++)
    {
        ll a, b;
        ll c;
        cin >> a>>b>>c;
        a--;
        b--;
        v[a].push_back(make_pair(b,c));
        v[b].push_back(make_pair(a,c));
    }
    vector<ll> ans;
    cin>>q>>k;
    k--;
    dfs(k,0);

    for(int i=0;i<q;i++){
        ll x, y;
        cin>>x>>y;
        x--;
        y--;
        ans.push_back(d[x]+d[y]);
    }
    for(int i=0;i<ans.size();i++)
    cout << ans[i] << "\n";
}



Measured memory_bytes: 15220
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define allof(a) (a).begin(),(a).end()
using lint = long long;
template< typename T > using Vec = vector< T >;

template< typename T > bool inRange(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool inRange(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }
template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }
inline int bitCount(int x) { return __builtin_popcount(x); }
inline int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//



int main() {
	string S;
	cin >> S;
	puts(S[0] == S[1] || S[1] == S[2] || S[2] == S[3] ? "Bad" : "Good");
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 256
from collections import Counter
S = tuple(input())
c = Counter(S)
if not c['a']:
  c['a'] = 0
if not c['b']:
  c['b'] = 0
if not c['c']:
  c['c'] = 0
if max(c.values()) - min(c.values()) < 2:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 10084
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

void stackPos(string &input, stack<int> &st, string key){
	int k = input.find(key);
	while(true){
		if(k != string::npos) st.push(k);
		else break;
		k = input.find(key, k + 5);
	}
}

void replace(string &input, stack<int> &st, string key){
	while(!st.empty()){
		int k = st.top();
		st.pop();
		input.replace(k, 5, key);
	}
}

int main(){
	string key[] = {"apple", "peach"};
	string input;
	while(getline(cin, input)){
		if(cin.eof()) break;

		stack<int> a, p;
		stackPos(input, a, key[0]);
		stackPos(input, p, key[1]);

		replace(input, a, key[1]);
		replace(input, p, key[0]);
		
		cout << input << endl;
	}

	return 0;
}

Measured memory_bytes: 1188
import Control.Monad
import Data.Array
import Data.List
import Data.Tuple (swap)
import Debug.Trace

import Test.QuickCheck

main = do
  [h,w] <- fmap (map read . words) getLine
  wss <- replicateM h getLine
  let tab = listArray ((1,1),(h,w)) (concat wss)
  putStrLn (solve tab)


type Table = Array (IxRow,IxCol) Char
type IxRow = Int
type IxCol = Int


showTable :: Table -> String
showTable tab =
  unlines [[ tab!(r,c) | c<-[ca..cz]] | r<-[ra..rz]]
  where
    ((ra,ca),(rz,cz)) = bounds tab

findElem :: IxRow -> Char -> Table -> [IxRow]
findElem r x tab =
  elemIndices x (elems (ixmap ((r,ca),(r,cz)) id tab))
  where
    ((ra,ca),(rz,cz)) = bounds tab

transposeTable :: Table -> Table
transposeTable tab =
  ixmap ((ca,ra),(cz,rz)) swap tab
  where
    ((ra,ca),(rz,cz)) = bounds tab

swapRow :: IxRow -> IxRow -> Table-> Table
swapRow i j tab =
  ixmap (bounds tab) f tab
  where
    f (r,c) | r == i    = (j,c)
            | r == j    = (i,c)
            | otherwise = (r,c)

swapCol :: IxCol -> IxCol -> Table -> Table
swapCol i j tab =
  ixmap (bounds tab) f tab
  where
    f (r,c) | c == i    = (r,j)
            | c == j    = (r,i)
            | otherwise = (r,c)

solve :: Table -> String
solve tab =
--  trace (unlines $ map showTable rowSolved) $
  if null [t| t<-rowColSolved, checkSymmetric t] then "NO" else "YES"
  where
    ((ra,ca),(rz,cz)) = bounds tab

    rowSolved = concat [solveRow 1 r tab | r<-[ra..rz]]
    rowColSolved = concat [solveRow 1 c t' | t <- rowSolved, let t' = transposeTable t, c<-[ca..cz]]

solveRow :: IxRow -> IxRow -> Table -> [Table]
solveRow r1 r2 tab =
  go ca cz [] tab
  where
    go c1 c2 center t
--      | trace (showTable t ++ show (c1,cz)) False = undefined
      | length center > 1 = []
      | c1 >= c2  = [t]
      | otherwise = let ts = solveRowCol r1 r2 c1 c2 t
                    in if null ts && odd cz
                         then go c1 c2 (c1:center) (swapCol c1 (cz`div`2+1) t)
                         else concatMap (go (c1+1) (c2-1) center) ts

    ((ra,ca),(rz,cz)) = bounds tab

solveRowCol :: IxRow -> IxRow -> IxCol -> IxCol -> Table -> [Table]
solveRowCol r1 r2 c1 c2 tab
  | trace (showTable tab ++ show (r1,r2,c1,c2)) False = undefined
  | c1 == c2  = [tab]
  | otherwise = [swapCol c c2 tab |c<-[c1+1..c2], isSymmetric r1 r2 c1 c tab]

isSymmetric :: IxRow -> IxRow -> IxCol -> IxCol -> Table -> Bool
isSymmetric r1 r2 c1 c2 tab =
  x11 == x22 && x21 == x12
  where
    x11 = tab!(r1,c1)
    x21 = tab!(r2,c1)
    x12 = tab!(r1,c2)
    x22 = tab!(r2,c2)

checkSymmetric :: Table -> Bool
checkSymmetric tab =
  and [isSymmetric r (rz-r+1) c (cz-c+1) tab | r<-[ra..rz], r<=rz-r+1, c<-[ca..cz]]
  where
    ((ra,ca),(rz,cz)) = bounds tab

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

int main(){
    string S; cin >> S;
    int n = S.size(), ans = 0;

    for( int i = 0; i < n; i++ ){
        if( S[i] == '0' )ans++;
    }
    cout << n - ( max(n-ans,ans) - min(n-ans,ans) ) << endl;
}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll n;
  cin >> n;
  
  vector<ll> c(n-1);
  vector<ll> s(n-1);
  vector<ll> f(n-1);
  for (ll i = 0; i < n-1; ++i) {
    cin >> c[i];
    cin >> s[i];
    cin >> f[i];
  }

  for (ll i = 0; i < n-1; ++i) {
    ll t = 0;
    for (ll j = i; j < n-1; ++j) {
      if (t <= s[j]) t = s[j];
      else if (t % f[j] != 0) {
        t += f[j] - ((t - s[j]) % f[j]);
      }
      t += c[j];
    }
    cout << t << endl;
  }
  cout << 0 << endl;

  return 0;
}

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

bool f[3][3];

int main(){
  int a[3][3];
  rep(i,3) rep(j,3) cin>>a[i][j];
  int n;
  cin>>n;
  rep(i,n){
    int b;
    cin>>b;
    rep(i,3) rep(j,3){
      if(b==a[i][j]) f[i][j]=true;
    }
  }
  if(f[0][0]&&f[0][1]&&f[0][2]||f[1][0]&&f[1][1]&&f[1][2]||f[2][0]&&f[2][1]&&f[2][2]
     ||f[0][0]&&f[1][0]&&f[2][0]||f[0][1]&&f[1][1]&&f[2][1]||f[0][2]&&f[1][2]&&f[2][2]
     ||f[0][0]&&f[1][1]&&f[2][2]||f[0][2]&&f[1][1]&&f[2][0])
    puts("Yes");
  else puts("No");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

main() {
    int N; cin >> N;
    int A[N]; rep(i,N) cin >> A[i];
    int ans=0;
    rep(i,N){
        while(true){
            if(A[i]%2==0){
                A[i]/=2;
                ans++;
            }
            else break;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10;
const int MAX = 1e5 + 10;
const double exps = 1e-8;

inline int max(int a, int b) { return a > b ? a : b; }
inline int min(int a, int b) { return a > b ? b : a; }
int n, h[110];
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", h + i);
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        int tmp = INF, p0 = 0;
        for (int j = 1; j <= n; ++j) {
            if (h[j])
                tmp = min(tmp, h[j]);
            else {
                bool jj = false;
                for (int k = p0 + 1; k < j; ++k) {
                    h[k] -= tmp;
                    jj = true;
                }
                if (jj) ans += tmp;
                p0 = j;
                tmp = INF;
            }
        }
        bool ok = true;
        for (int p = 1; p <= n; ++p) {
            if (h[p]) {
                ok = false;
                break;
            }
        }
        if (ok) break;
        bool jj = false;
        for (int k = p0 + 1; k <= n; ++k) {
            h[k] -= tmp;
            jj = true;
        }
        if (jj) ans += tmp;
    }
    cout << ans;
}

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

int main()
{
    long long A,B,C,K;
    cin >> A >> B >> C >> K;
    if ( K <= A)
    {
        cout << K << endl;
        return 0;
    }else if (K <= A + B ){
        cout << A << endl;
        return 0;
    }else if ( K == A + B + C){
        cout << A - C << endl;
        return 0;
    }else{
        cout <<  A - ( K - B - A)  << endl;
        return 0;
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using llong = long long;
using vi    = vector<int>;
using vvi   = vector<vi >;
using vvvi  = vector<vvi >;
using pii   = pair<int,int>;
constexpr int    INF=1e9;
constexpr double EPS=1e-9;
constexpr int    MOD=1e9+7;
template<class Type>
void line(const Type &a){int cnt=0;for(const auto &elem:a){cerr<<(cnt++?' ':'>');cerr<<elem;}cerr<<endl;}

/*二項係数(mod付き)*/
struct Combination{
	const int mod=1e9+7;
	const int num;					//num:=(要素数). 宣言時に適宜変更する!
	vector<llong> fact,inv,finv;	//fact[i]:=(iの階乗),inv[i]:=(iの逆元),finv[i]:=(iの逆元の階乗).
	
	Combination(unsigned int num_=51e4):num(num_),fact(num_),inv(num_),finv(num_){
		fact[0]=fact[1]=1LL;
		inv[1]=1LL;
		finv[0]=finv[1]=1LL;
		for(int i=2;i<num;++i){
			fact[i]=fact[i-1]*i%mod;
			inv[i]=mod-inv[mod%i]*(mod/i)%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	
	int nCk(int n,int k){//組み合わせ.
		assert(n>=0 and k>=0 and n>=k);
		return fact[n]*(finv[k]*finv[n-k]%mod)%mod;
	}
	template<typename Type>
	Type big_nCk(Type n,int k){//組み合わせ(n>=numのとき). O(k).
		assert(n>=0 and k>=0 and n>=k);
		llong res=1LL;
		REP(i,k) res=res*((n-i)%mod)%mod;
		res=res*finv[k]%mod;
		return (Type)res;
	}
	int nPk(int n,int k){//順列.
		assert(n>=0 and k>=0 and n>=k);
		return fact[n]*finv[n-k]%mod;
	}
	int nHk(int n,int k){return nCk(k+n-1,n-1);}//重複組み合わせ.
};

int main(){
	int s;
	cin>>s;
	
	llong ans=0LL;
	Combination ob;
	for(int i=1;;++i){//数列をi個にする場合.
		int n=s/i-3,m=s%i;//(i*n+m):=(余分な数).
		if(n<0) break;
		
		ans=(ans+ob.nHk(i,i*n+m))%MOD;
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 15112
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://atcoder.jp/contests/dp/tasks/dp_b>
 問題文============================================================
 =================================================================
 解説=============================================================
 A問題と同じ
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int N,K; cin >> N >> K;
    vector<ll> h(N); for(auto& in:h) cin >> in;
    vector<ll> dp(N,LINF);
    dp[0] = 0;
    for(int i = 0; i < N;i++){
        for(int j = 1; j <= K;j++){
            if(i+j >= N) break;
            dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
        }
    }
    res = dp[N-1];
    return res;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 1792
# input
n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
al = (pow(2, n, mod) - 1)


# 参考：https://qiita.com/MyOden/items/b669bfbf6dbf83242bdf =>フェルマーの小定理を基に演算関数を用意
def fur(n, r):
    p, q = 1, 1
    for i in range(r):
        p = p * (n - i) % mod
        q = q * (i + 1) % mod
    return p * pow(q, mod - 2, mod) % mod


nca = fur(n, a)
ncb = fur(n, b)
ans = (al - nca - ncb) % mod

print(ans)

Measured memory_bytes: 3064
import java.util.*;
import java.io.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		Map<Integer , Integer> tm = new TreeMap<Integer , Integer>();
		int a;
		for(int i = 0 ; i < n ; i++){
			a = Integer.parseInt(sc.next());
			if(tm.containsKey(a)){
				tm.put(a , tm.get(a) + 1);
			}else{
				tm.put(a , 1);
			}
		}
		sc.close();
		if(tm.size() % 2 == 0) ou.println(tm.size() - 1);
		else ou.println(tm.size());
		ou.flush();
    }
}

Measured memory_bytes: 63336
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	char s;
	for (int i = 0; i < n; ++i) {
		cin >> s;
		if (s == 'Y') {
			cout << "Four\n";
			return 0;
		}
	}

	cout << "Three\n";

	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 rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

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

    const int M = 256;

    int N;
    while (cin >> N, N) {
        V I(N);
        rep(i, N) cin >> I[i];

        double mi = 1e9;
        int S, A, C;
        rep(s, 15 + 1) {
            rep(a, 15 + 1) {
                rep(c, 15 + 1) {
                    int r = s;
                    map<int, int> mp;   // O(i), #occurence
                    rep(i, N) {
                        r = (a * r + c) % M;
                        mp[(I[i] + r) % M]++;
                    }

                    double h = 0.;
                    for (auto& p : mp) {
                        h += - p.second * log((p.second * 1.) / N);
                    }

                    if (h + 1e-10 < mi) {
                        mi = h;
                        S = s, A = a, C = c;
                    }
                }
            }
        }

        cout << S << " " << A << " " << C << endl;
    }

}

Measured memory_bytes: 3344
n, k = map(int, input().split())

ans1 = 0
ans2 = 0
for a in range(1, n + 1):
    if a % k == 0:
        ans1 += 1
    if k % 2 == 0 and a % k == k / 2:
        ans2 += 1
ans = ans1 ** 3
if k % 2 == 0 and ans2 > 0:
    ans += ans2**3
print(ans)


Measured memory_bytes: 3060
N = int(input())
H = list(map(int,input().split()))

c = 0

for i in range(N):
    d = 0

    for j in range(i):
        #print(H[i], H[j])
        if H[i] > H[j] or H[i] == H[j]:
            d += 1
    if d == i:
        c += 1
print(c)

Measured memory_bytes: 2940
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST            ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll              long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define all(a)          (a).begin(),(a).end()
#define clz(a)          __builtin_clz(a) // count leading zeroes
#define ctz(a)          __builtin_ctz(a) // count trailing zeroes
#define popc(a)         __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define rep(i,a,b)      for(ll i=a;i<b;i++)
#define rfor(i,a,b)     for(ll i=a; i>=b; i--)
#define debug(x)        cerr << #x << " = " << x << endl;
#define F               first
#define S               second
#define endl            '\n'
#define SIZE            1000005
#define deci(n)         cout<<fixed<<setprecision(n)
#define ordered_set     tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll lul2 = 998244353;
const ll lul = 1000000007;

void mod(ll &x)
{
    if(x>=lul) x-=lul;
    if(x<0) x+=lul;
}

ll _gcd(ll a, ll b)
{
    if(b == 0) return a;
    return _gcd(b,a%b);
}

ll expo(ll n, ll p)
{
    if(p == 0) return 1;
    ll x = expo((n*n)%lul, p/2)%lul;
    if(p&1) return (x*n)%lul;
    return x;
}
//---------------------------------------------------------------------

vector<int> adj[200005],dist(200005,INF);
int par[200005] = {0}, vis[200005] = {0};
bool bfs(int n)
{
    queue<int> q;
    q.push(1);
    dist[1] = 0;
    while(!q.empty())
    {
        int node = q.front();
        q.pop();
        if(vis[node]) continue;
        vis[node] = 1;
        for(int i:adj[node])
        {
            if(!vis[i]) q.push(i);
            if(dist[i]>dist[node]+1)
            {
                dist[i] = dist[node] + 1;
                par[i] = node;
            }
        } 
    }
    bool ok = true;
    rep(i,2,n+1)
    {
        ok&=(par[i]!=0);
    }
    return ok;
}
void solve()
{
    int n,m; cin>>n>>m;
    rep(i,0,m)
    {
        int x,y; cin>>x>>y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    bool chck = bfs(n);
    if(!chck) {cout<<"No"; return;}
    cout<<"Yes"<<endl;
    rep(i,2,n+1)
    {
        cout<<par[i]<<endl;
    }
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    rep(i,1,t+1){
        solve();
    }
    return 0;
}

Measured memory_bytes: 13928
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(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; }
const ll INF = 1LL << 60;
int main(){
    string s;
    cin >> s;
    if(s[3]==s[2] && s[4]==s[5]) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
const int mod=1e9+7;

template< int mod >
struct ModInt {
  int x;
 
  ModInt() : x(0) {}
 
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
 
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
 
  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
    return *this;
  }
 
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
 
  ModInt operator-() const { return ModInt(-x); }
 
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
 
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
 
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
 
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
 
  bool operator==(const ModInt &p) const { return x == p.x; }
 
  bool operator!=(const ModInt &p) const { return x != p.x; }
 
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
 
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
 
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
 
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
 
  static int get_mod() { return mod; }
};
 
using modint = ModInt< mod >;

int main(){
    int n,m;cin>>n>>m;
    int s[n];rep(i,n)cin>>s[i];
    int t[m];rep(i,m)cin>>t[i];
    modint dp[n+1][m+1];
    dp[0][0]=1;
    rep(i,n+1) dp[i][0]=1;
    rep(i,m+1) dp[0][i]=1;
    rep(i,n) rep(j,m){
        if(s[i]==t[j]){
            dp[i+1][j+1]+=dp[i][j];
        }
         dp[i+1][j+1]+=dp[i+1][j]+dp[i][j+1]-dp[i][j];
    }
    cout<<dp[n][m]<<endl;
}

Measured memory_bytes: 15872
#include "bits/stdc++.h"
using namespace std;
const long long INF = 1LL << 60;

void chmin(int &a,int b){
    if(a>b)a=b;
    return;
}

void chmax(long long &a,long long b){
    if(a<b)a=b;
    return;
}

int we[110],v[110];

long long dp[110][100100];

int main()
{
    int n,w;
    cin >>n >> w;
    for(int i=0;i<n;i++)cin >> we[i] >> v[i];
    for(int i=0;i<n;i++){
        for(int j=0;j<=w;j++){
            if(j-we[i]>=0){
                chmax(dp[i+1][j],dp[i][j-we[i]]+v[i]);
            }
            chmax(dp[i+1][j],dp[i][j]);
        }
    }
    cout << dp[n][w]<< endl;
    return 0;
}


Measured memory_bytes: 79360
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000007
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
typedef pair<int,int> P;
typedef pair<P,P> PP;
int main(void){
	int n,m;
	PP d[100];
	
	cin>>n>>m;
	for(int i=0;i<m;i++) scanf("%d,%d,%d,%d",&d[i].ff,&d[i].fs,&d[i].sf,&d[i].ss);
	int s,g,v,p;
	scanf("%d,%d,%d,%d",&s,&g,&v,&p);
	
	int rin[21][21];
	for(int i=1;i<=n;i++) fill(rin[i]+1,rin[i]+n+1,INF);
	for(int i=0;i<m;i++) rin[d[i].ff][d[i].fs]=d[i].sf,
						  rin[d[i].fs][d[i].ff]=d[i].ss;
	
	int leng[21],flg[21];
	fill(leng+1,leng+n+1,INF); fill(flg+1,flg+n+1,0);
	leng[s]=0;
	int sum;
	for(int i=0;i<n;i++){
		int mn=INF,t;
		for(int j=1;j<=n;j++) if(flg[j]==0&&mn>leng[j]) t=j,mn=leng[j];
		if(t==g){
			sum=leng[t];
			break;
		}
		flg[t]=1;
		for(int j=1;j<=n;j++){
			if(rin[t][j]!=INF){
				if(leng[t]+rin[t][j]<leng[j]) leng[j]=leng[t]+rin[t][j];
			}
		}
	}
	
	fill(leng,leng+n+1,INF); fill(flg+1,flg+n+1,0);
	leng[g]=0;
	for(int i=0;i<n;i++){
		int mn=INF,t; 
		for(int j=1;j<=n;j++) if(flg[j]==0&&mn>leng[j]) t=j,mn=leng[j];
		if(t==s){
			sum+=leng[t];
			break;
		}
		flg[t]=1;
		for(int j=1;j<=n;j++){
			if(rin[t][j]!=INF){
				if(leng[t]+rin[t][j]<leng[j]) leng[j]=leng[t]+rin[t][j];
			}
		}
	}
	cout<<v-p-sum<<endl;
	return 0;
}


Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
#define maxn 200000
int n, cnt, fa[maxn];
set <int> E[maxn];

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

struct node {
	int u, v;
	node(int a = 0, int b = 0) {
		u = a, v = b;
	}
}; queue <node> q;

int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }

int main() {
	n = read(); int t = (n - 1) * 2;
	for(int i = 1; i <= t; i ++) {
		int u = read(), v = read();
		if(!E[u].count(v)) E[u].insert(v), E[v].insert(u);
		else q.push(node(u, v));
	}
	for(int i = 1; i <= n; i ++) fa[i] = i;
	while(!q.empty()) {
		node now = q.front(); q.pop(); cnt ++;
		int x = find(now.u), y = find(now.v);
		if(E[x].size() < E[y].size()) swap(x, y);
		for(set <int> :: iterator it = E[y].begin(); it != E[y].end(); it ++)
			if(*it != x) {
				int u = x, v = *it;
				E[v].erase(y);
				if(!E[u].count(v)) E[u].insert(v), E[v].insert(u);
				else q.push(node(u, v));
			}
		E[x].erase(y), fa[y] = x;
	}
	if(cnt == n - 1) puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 29440
N,M = [int(x) for x in input().split()]
if N>=M:
  print(0)
  exit()
X = [int(x) for x in input().split()]
X.sort()
L = []
for i in range(M-1):
  L.append(X[i+1]-X[i])
L.sort()
ans = sum(L[:M-N])
print(ans)

Measured memory_bytes: 13840
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <unordered_set>
//#include <unordered_map>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

void mainmain(){
	int n,m;
	cin>>n>>m;
	vvint bo(10);
	rep(i,n){
		int a,b;
		cin>>a>>b;
		bo[b-1].PB(a);
	}
	rep(i,10){
		sort(ALL(bo[i]));
		reverse(ALL(bo[i]));
	}
	vvint vv(10);
	rep(i,10){
		int t=0;
		vv[i].PB(0);
		rep(j,bo[i].size()){
			vv[i].PB(t+=bo[i][j]+2*j);
		}
	}
	vvint dp;
	initvv(dp,10,2020,0);
	rep(i,vv[0].size()){
		dp[0][i]=vv[0][i];
	}
	reep(i,1,10){
		rep(j,2020){
			rep(k,vv[i].size()){
				if(j-k<0) continue;
				dp[i][j]=max(dp[i][j],dp[i-1][j-k]+vv[i][k]);
			}
		}
	}
	cout<<dp[9][m]<<endl;
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1332
#include<bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <queue>
#define pb push_back
#define ll long long

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    int a, sum = 0;
    for(int i = 1; i <= n; i++) {
        cin >> a;
        if(a >= k) sum++;
    }
    cout << sum << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#define N 2000000
 
 
int h = 0;
 
void MaxHeapify(int *a, int i){
  int left, right, large, tmp;
  
  if(i * 2 <= h) 
    left = i * 2;
  else left = i;
  
  if(i * 2 + 1 <= h) 
    right = i * 2 + 1;
  
  else right = i;
  
  
  if(left < h + 1 && a[left] > a[i]) 
    large = left;
  else large = i;
  
  if(right < h + 1 && a[right] > a[large]) 
    large = right;
   
  if(large != i){
    tmp = a[i];
    a[i] = a[large];
    a[large] = tmp;
    MaxHeapify(a, large);
  }
}
 
void Insert(int *a, int key){
  int i, tmp;
 
  h++;
  i = h;
  a[i] = key;
  while(i > 1 && a[i / 2] < a[i]){
    tmp = a[i];
    a[i] = a[i / 2];
    a[i / 2] = tmp;
    i = i / 2;
  }
}
 
void Extract(int *a){
  int max;
 
  max = a[1];
  a[1] = a[h];
  h--;
  MaxHeapify(a, 1);
 
  printf("%d\n", max);
}

int main(void){
 
 int a[N], key;
  int i = 0, j;
  char c[8];
 
  while( 1 ){
      scanf("%s", c);
      if(c[2] == 'd') break;
      else if(c[0] == 'i'){
   
	scanf("%d", &key);
	Insert(a, key);
      }
      else Extract(a);
  }
 
  return 0;
}

Measured memory_bytes: 4988
if __name__ == '__main__':
	N, K = map(int, input().split())
	ans = 0
	P = 10**9 + 7
	for k in range(K,N+2):
		minimum = k * (k-1) // 2
		maximum = (2*N - k + 1) * k / 2
		v = maximum - minimum + 1
		ans += v%P

	print(int(ans%P))

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

class _0105
{
    public static void Main()
    {
        string data;
        SortedDictionary<string, SortedList<int, string>> index = new SortedDictionary<string, SortedList<int, string>>();
        index.Clear();
        while ((data = Console.ReadLine()) != null)
        {
            string[] d = data.Split();
            if (index.ContainsKey(d[0])) index[d[0]].Add(int.Parse(d[1]), d[1]);
            else { index[d[0]] = new SortedList<int, string>(); index[d[0]].Add(int.Parse(d[1]), d[1]); }
        }
        foreach (KeyValuePair<string, SortedList<int, string>> pair in index)
        {
            Console.WriteLine(pair.Key);
            Console.WriteLine(String.Join(" ", pair.Value.Values.ToArray()));
        }
    }
}

Measured memory_bytes: 7316
#include<bits/stdc++.h>                   // below comment for pbds
#include<ext/pb_ds/assoc_container.hpp>   // to use it make ordered_set
#include<ext/pb_ds/tree_policy.hpp>       // all set fnct + = 1. order_of_key(x); // number of 
#define ll long long                      //element strictly smaller than it;
#define ld long double                    // 2. find_by_order(x),pointer el at x pos after sort  use as s.f();
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std; // assert(a[i]<n ) // if we want to check for special cond , used for debug                     
using namespace __gnu_pbds; // make less_equal in order to make a multiset pbds
#define INF (ll)1e18 
const ll Mod = (ll)1e9+7;
ll CaseN=1;
const ld PI = 22/7.0;

ll tst()
{
ll ans=0;

return ans;
}

void solve()
{	
		ll a,b,c,d;
		cin>>a>>b>>c>>d;
		ll ans=-(ll)1e10;
		
		ans = max({a*c,a*d,b*c,b*d});
		
		cout<<ans<<endl;
		//cout<<"Case #"<<CaseN<<": ";
		CaseN++;
		// print your ans below;
	
return ;

}


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t=1;
	//cin>>t;
	while(t--)
	{
	solve();
	}
	
}


Measured memory_bytes: 3656
#include <cstdio>
#include <cstring>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
//#include <bits/stdc++.h>
#define pb push_back
#define FOR(x,st,n) for(int x = (st); x < (n); ++ x)

using namespace std;


typedef long long unsigned ll;
typedef pair<int,int> P;
//typedef vector<P> vp;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int N = 1e3+1;
int n,m,k,q;

const int MOD = 1e9+7;
int main(){


    cin>>n;
    ll ret=1;
    for(int i=1;i<=n;i++){
        ret*=i;
        ret%=MOD;
    }
    cout<<ret%MOD<<endl;


    return 0;
}


Measured memory_bytes: 256
import math

in1 = input()
t = math.log(int(in1),10)
t2 = math.floor(t)
t3 = math.ceil(t2/2)

ii = 0
sum = 0
for i,t in enumerate(range(t3)):
    c = 9*(10**ii)
    ii += 2    
    sum += c

t4 = int(in1) - 10**t2 + 1 if t2%2 == 0 else 0

print("{}".format(sum+t4))

Measured memory_bytes: 3064