akhauriyash/Code-Regression huggingface dataset:
// mod custom_lib;
use std::collections::HashMap;

use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

pub fn read_n<T: FromStr>(n: u32) -> Vec<T> {
  read_n_logic::<T>(n, vec![])
}

pub fn read_n_logic<T: FromStr>(n: u32, mut a: Vec<T>) -> Vec<T> {
  match n {
    0 => a,
    _ => {
      a.push(read::<T>());
      read_n_logic(n - 1, a)
    }
  }
}

fn main() {
  let n = read::<u32>();
  let m = read::<u32>();

  let mut s_map: HashMap<u32, Vec<u32>> = HashMap::new();
  let light_status = vec![0; m as usize];
  let mut answer = 0;

  for k_index in 0..m {
    let k = read::<u32>();
    let conn_switch = read_n::<u32>(k);
    for switch in conn_switch {
      if s_map.contains_key(&switch) {
        let mut prev_vec = s_map.get_mut(&switch).unwrap();
        prev_vec.push(k_index);
      } else {
        s_map.insert(switch, vec![k_index]);
      }
    }
  }

  let idial_light_status = read_n::<u32>(m);


  let two: i32 = 2;
  for i in 0..two.pow(n) {
    let result: String = format!("{:0>keta$b}", i, keta = n as usize);
    let mut clone_status = light_status.clone();

    for (keta, value) in result.chars().enumerate() {
      if value == '1' {
        search(&mut clone_status, (keta + 1) as u32, &s_map);
      }
    }

    if check_the_same(&clone_status, &idial_light_status) {
      answer += 1
    };
  }

  println!("{}", answer);
}

fn search(current_status: &mut Vec<u32>, change_switch: u32, s_map: &HashMap<u32, Vec<u32>>) {
  let target_lights = match s_map.get(&change_switch) {
    Some(s) => s,
    None => return,
  };

  for light in target_lights {
    current_status[*light as usize] = if current_status[*light as usize] == 0 {
      1
    } else {
      0
    };
  }
}

fn check_the_same(c_status: &Vec<u32>, i_status: &Vec<u32>) -> bool {
  let c_status_str: String = c_status
    .into_iter()
    .map(|i| i.to_string())
    .collect::<String>();
  let i_status_str: String = i_status
    .into_iter()
    .map(|i| i.to_string())
    .collect::<String>();
  if i_status_str == c_status_str {
    true
  } else {
    false
  }
}


Measured memory_bytes: 4352
#define DEBUG 0
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n, q; std::cin >> n >> q;
  std::vector<int> ac(n, false);
  std::vector<int> wa(n, 0);
  loop(q) {
    int p; std::string s; std::cin >> p >> s;
    p--;
    if (s=="AC") {
      ac.at(p) = true;
    } else {
      if (!ac.at(p)) {
        wa.at(p)++;
      }
    }
  }
  debug(ac,wa);

  int ac_ = std::accumulate(all(ac), 0);
  int wa_ = 0;
  rep(i,0,n) {
    if (ac.at(i)) {
      wa_ += wa.at(i);
    }
  }
  std::cout << ac_ << " " << wa_ << std::endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>

using namespace std;

int main()
{
	const int N = 'z' - 'a' + 1;
	string S;
	cin >> S;

	bool str[N];

	for (int i = 0; i < N; i++)
		str[i] = false;

	for (int i = 0; i < S.length(); i++)
	{
		str[S[i] - 'a'] = true;
	}

	for (int i = 0; i < N; i++)
	{
		if (!str[i])
		{
			cout << (char)(i + 'a') << endl;
			return 0;
		}
	}

	cout << "None" << endl;

	return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for ( int i = 0; i < N; ++i){
        cin >> a[i];
    }
    
    int count = 0;
    for ( int i = 0; i < N; ++i){
        if ( (i+1)%2 == 1 and a[i] % 2 == 1){
            ++count;
        }
    }
    
    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 3592
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        if(A - B >= 0) {
            System.out.println("delicious");
        }else if(A - B >= -X){
            System.out.println("safe");
        }else{
            System.out.println("dangerous");
        }
    }
}

Measured memory_bytes: 21716
#include<iostream>
#include<math.h>
using namespace std;

int main()
{
	int n;
	int m;
	float x;

	cin >> n;
	
	if (n % 2 == 0) {
		m = n / 2;
	}
	else {
		m = (n + 1) / 2;
	}
	
	x = (float)m / n;

	cout << x;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N,M;
    cin >> N;
    map<string,int> s,t;
    REP(i,N) {
        string S; cin >> S; s[S]++;
    }
    cin >> M;
    REP(i,M) {
        string S; cin >> S; t[S]++;
    }
    int ans = 0;
    for(auto p : s) {
        if(t.count(p.first)) chmax(ans,p.second-t[p.first]);
        else chmax(ans,p.second);
    }
    cout << ans << endl;
}


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

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

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    int[][] a = new int[N][M];
    for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) a[i][j] = scanner.nextInt() - 1;

    boolean[] available = new boolean[M];
    Arrays.fill(available, true);

    int min = N;
    for (int i = 0; i < M - 1; i++) {
      Result res = solve(N, M, a, available);
      min = Math.min(min, res.num);
      available[res.sport] = false;
    }
    System.out.println(min);
  }

  private static Result solve(int N, int M, int[][] a, boolean[] available) {
    int[] count = new int[M];
    int max = 0;
    int sport = -1;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < M; j++) {
        int k = a[i][j];
        if (available[k]) {
          count[k]++;
          if (count[k] > max) {
            max = count[k];
            sport = k;
          }
          break;
        }
      }
    }
    return new Result(sport, max);
  }

  private static class Result {
    private final int sport;
    private final int num;

    private Result(int sport, int num) {
      this.sport = sport;
      this.num = num;
    }
  }
}


Measured memory_bytes: 50268
#include "bits/stdc++.h"
using namespace std;

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(tx, ty, w, h) (0 <= tx && tx <= w && 0 <= ty && ty <= h)

/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;

/* constant */
const int inf = pow(2, 62);
const int mod = 1e9 + 7;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}

/* general_method */
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; }
template<class T>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}

/* main */

int n;
vi arr;

void in(){
    cin >> n;
    rep(i,0,n) arr.push_back(input());
}

void solve(){

    int ans = 0;
    while(true){
        int l = 0;
        while(l < n && arr[l] == 0) l++;

        if(l == n) break;
        int r = l;
        while(r + 1 < n && arr[r + 1] != 0) r++;

        rep(i,l,r + 1){
            arr[i]--;
        }
        ans++;
    }
    print(ans);

}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

Measured memory_bytes: 256
//%std
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
int n,p[8],a[8],b[8],x,y,t=0;
bool A()
{
	for(int i=0;i<n;++i)
		if(p[i]!=a[i])
			return false;
	return true;
}
bool B()
{
	for(int i=0;i<n;++i)
		if(p[i]!=b[i])
			return false;
	return true;
}
int main()
{
	n=read();
	for(int i=0;i<n;++i)
		a[i]=read();
	for(int i=0;i<n;++i)
		b[i]=read();
	iota(p,p+n,1);
	do
	{
		++t;
		if(A())
			x=t;
		if(B())
			y=t;
	}while(next_permutation(p,p+n));
	cout<<abs(x-y)<<endl;
	return 0;
}


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

#define ll long long int

using namespace std;

int main() {
	ll n;
	cin >> n;
	ll ar[n+1][3], dp[n+1][3] = {0};
	for (int i = 0 ; i < n ; i++) 
		cin >> ar[i][0] >> ar[i][1] >> ar[i][2];
	for (int i = 0 ; i < 3 ; i++) 
		dp[0][i] = ar[0][i];
	for (int i = 1 ; i <n ; i++) {
		for (int j = 0 ; j < 3 ; j++) {
			for(int k = 0 ; k < 3 ; k++) {
				if (j != k) 
					dp[i][j] = max(dp[i][j], ar[i][j] + dp[i-1][k]);
			}
		}
	}
	cout << max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]);
	return 0;
}

Measured memory_bytes: 4992
import copy

N=int(input())
X1=list(map(int,input().split()))
X=copy.deepcopy(X1)
X.sort()
ma=X[N//2-1]
mb=X[N//2]


for i in range(N):
    if X1[i]<=ma:
        print(mb)
    else:
        print(ma)





Measured memory_bytes: 121592
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(a) setprecision(a)<<fixed
#define ss second
#define fori(v) for(ll i=0; i<v; i++)
#define forj(v) for(ll j=0; j<v; j++)
#define fork(v) for(ll k=0; k<v; k++)
#define forl(v) for(ll l=0; l<v; l++)
#define fort(v) for(ll t=0; t<v; t++)
#define forz(v) for(ll z=0; z<v; z++)
#define forx(v) for(ll x=0; x<v; x++)
#define fory(v) for(ll y=0; y<v; y++)
#define ll long long
#define double long double
#define pb(a) push_back(a)
const ll INF = 0x3f3f3f3f;
const ll inf = pow(10,18);
ll modulo = 998244353 ;
#define MAX 300100

void deal(){
	ll n, d ;
	cin>>n>>d;
	vector<vector<ll> > all(n, vector<ll>(d));
	fori(n)
		forj(d)
			cin>>all[i][j];
	ll ans =  0;
	fori(n)
		forj(i){
			ll s = 0;
			fork(d)
				s+=(all[i][k] - all[j][k])*(all[i][k] - all[j][k]);
			ll kok  = sqrt(s);
			ans += (kok*kok == s);
		}
	cout<<ans;
}


int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	deal();
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
	input! {
		mut a: isize,
		b: isize,
		mut c: isize,
		d: isize,
	}

	loop {
		c -= b;
		if c < 1 {
			println!("Yes");
			return;
		}
		a -= d;
		if a < 1 {
			println!("No");
			return;
		}
	}
}


Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
#define inf 999999999
#define nmax 2005
int n,m,edge[nmax][nmax];
int vis[nmax]={0};
int main ()
{
    ios::sync_with_stdio(false);
    int n,x,y;
    cin>>n>>x>>y;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            edge[i][j]=min(j-i,abs(j-y)+abs(i-x)+1);
            vis[edge[i][j]]++;
        }
    }
    for(int i=1;i<n;i++){
        cout<<vis[i]<<"\n";
    }
    return 0;
}

Measured memory_bytes: 15360
while(1):
    e=int(raw_input())
    if e==0:
        break
    else:
        sum=99999999999999
        for z in range(101):
            edash=e-z**3
            if edash<0:
                break
            y=int(edash**(1/2.0))
            x=edash-y**2
            if x+y+z<sum:
            	[X,Y,Z]=[x,y,z]
                sum=x+y+z
        print sum

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

int main() {
    // input
    string S;
    cin >> S;

    // solve
    int ans = 0;
    int n = S.length();
    for (int i = 0; i < n; ++i) {
        S.pop_back();
        if (S.length() % 2 == 0) {
            if (S.substr(0, S.length() / 2) == S.substr(S.length() / 2, S.length() / 2)) {
                ans = S.length();
                break;
            }
        }
    }

    // output
    cout << ans << endl;

    return 0;
}


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

#A
def A():
    s = LI()
    if sum(s) ==  2*max(s):
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    w,h,n = LI()
    l,r = 0,w
    d,u = 0,h
    for i in range(n):
        x,y,a = LI()
        if a == 1:
            l = max(x,l)
        elif a == 2:
            r = min(x,r)
        elif a == 3:
            d = max(y,d)
        else:
            u = min(y,u)
    print(max(r-l,0)*max(u-d,0))
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

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


Measured memory_bytes: 38640
#include <stdio.h>
int main(void){
  int i,j,H,W;
  while(scanf("%d %d\n",&H,&W) != EOF){
      if(H == 0 && W == 0){
          break;
      }
      for(i=0; i<H; i++){
          for(j=0; j<W; j++){
              if(i >= 1 && j >= 1 && i < H-1 && j < W-1){
                  printf(".");
              }else{
                  printf("#");
              }
          }
          printf("\n");
      }
      printf("\n");
  }
  return 0;
}


Measured memory_bytes: 1980
#include <bits/stdc++.h>
#define OP_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define fo(i,a,b) for(int i = a; i < b; i++)
#define foi(i,a,b) for(int i = a; i>=b; i--)
#define fi first
#define si second
#define pb push_back
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

//const ll INF = 1e18L + 5;
const int MAXN = 1e5+5;
const ll modn = 1e9+7;
ll dp[MAXN][2];
vi adj[MAXN];

void solve(int n, int u, int p){
  dp[u][0] = dp[u][1] = 1;
  fo(i, 0, adj[u].size()){
    int v = adj[u][i];
    if(v == p){
      continue;
    }
    solve(n, v, u);
    dp[u][0] = ((dp[u][0]*dp[v][0])%modn + (dp[u][0]*dp[v][1])%modn)%modn;
    dp[u][1] = (dp[u][1]*dp[v][0])%modn;
  }
}

int main(){
  OP_IO;
  int n;
  cin>>n;
  fo(i,0,n-1){
    int x, y;
    cin>>x>>y;
    --x; --y;
    adj[x].pb(y);
    adj[y].pb(x);
  }
  solve(n, 0, -1);
  cout<<(dp[0][0] + dp[0][1])%modn<<endl;
  return 0;
}


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

using namespace std;

int main() {
    int n, ret = 0, i = 0;
    cin >> n;
    while (++i < n){
        int limit = ceil(sqrt(i));
        if (limit * limit > i) {
            limit--;
        }
        int x = 0;
        while (++x <= limit) {
            if(i % x == 0)
                ret += 2;
        }
        if (limit * limit == i) {
            ret --;
        }
    }
    cout << ret;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
ll N;
map<ll,ll> mp;
vector<ll> A;
vector<ll> dp;

ll dfs(int t){
    if(dp[t] != -1){
        return dp[t];
    }
    if(t == N-1){
        dp[t] = 1;
        return 1;
    }
    ll v = A[t];
    if(v ==N){
        dp[t] = 1;
        return 1;
    }
    if(mp[v+1] <t){
        return 1;
    }
    dp[t] = dfs(mp[v+1])+1;
    // cerr <<"t=" <<t <<"v= " << v <<"dp=" << dp[t] << endl;
    return dp[t];

}

void solve(){
    for(int i=0;i<N;i++){
        mp[A[i]] =i;
    }
    dp.resize(N,-1);
    ll ans =0;
    for(int i=0;i<N;i++){
        ans = max(ans,dfs(i));
    }
    cout << N-ans << endl;

}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    scanf("%lld",&N);
    A.resize(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve();
    return 0;
}


Measured memory_bytes: 28416
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;


int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a*b>=c*d)cout<<a*b<<endl;
    else cout<<c*d<<endl;
}


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    long int n;
    cin>>n;
    
    string str;
    cin>>str;
    
    int j=1;
    for(int i=1;i<n;i++)
    {
        char b=str[i-1];
        if(str[i]!=b)
        j++;
    }
    
    cout<<j<<endl;
    
   return 0;
}



Measured memory_bytes: 512
a,b,c,d,e,f = map(int, input().split())
s = [0,0,0,0]
con1 = 0
for x in range(31):
    for y in range(31):
        for v in range(1501):
            if x == y == 0:
                continue
            else:
                w1 = (f-(100*a*x + 100*b*y + c*v))//d
                w2 = (100*a*x + 100*b*y -c*v)//d
                w3 = ((100*a*x + 100*b*y)*e -c*v*100)//(100*d)
                w = min(w1,w2,w3)
                con2 = 100*(c*v + d*w)/(100*a*x + 100*b*y +c*v +d*w)
                if con1 <= con2 and w >= 0:
                    con1 = con2
                    s = [x,y,v,w]
                else:
                    continue

ans1 = 100*a*s[0] + 100*b*s[1] + c*s[2] + d*s[3]
ans2 = c*s[2] + d*s[3]
print(ans1,ans2)

Measured memory_bytes: 9084
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    const int N = 4;
    int n, w;
    cin >> n >> w;
    vector<vector<int>> vv(N,vector<int>());
    ll w1,v1;
    cin >> w1 >> v1;
    vv[0].push_back(v1);
    REP(i,n-1) {
        ll w, v;
        cin >> w >> v;
        vv[w-w1].push_back(v);
    }
    REP(i,N) sort(RALL(vv[i]));
    vector<vector<int>> vsum(N,vector<int>{0});
    REP(i,N) REP(j,vv[i].size()) {
        vsum[i].push_back(vsum[i][j] + vv[i][j]);
    }
    int ans = 0;

    for (ll i = 0; i < vsum[0].size(); i++) {
        ll wi = w1 * i;
        if (wi > w) break;

        for (ll j = 0; j < vsum[1].size(); j++) {
            ll wj = wi + (w1+1) * j;
            if (wj > w) break;

            for(ll k = 0; k < vsum[2].size(); k++) {
                ll wk = wj + (w1+2) * k;
                if (wk > w) break;

                for(ll l = 0; l < vsum[3].size(); l++) {
                    ll wl = wk + (w1+3) * l;
                    if (wl > w) break;
                    ans = max(ans,vsum[0][i]+vsum[1][j]+vsum[2][k]+vsum[3][l]);
                    // cerr << i << j << k << l << " " << ans << endl;
                }
            }
        }
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
N, Y = map(int, input().split())
flag = False
for i in range(N+1):    # 1万円札がi枚の時
    for j in range(0, N+1-i):   # 5000円札がj枚の時
        if Y == 10000*i + 5000*j + 1000*(N-i-j):
            print(i, j, (N-i-j))
            flag = True
            break
    if flag:
        break
if flag == False:
    print("-1 -1 -1")


Measured memory_bytes: 3064
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve();

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

void solve(){
    ll h,w;cin>>h>>w;
    vvl a(h,vl(w));
    rep(i,h)rep(j,w)cin>>a[i][j];

    vl y1,x1,y2,x2;
    rep(i,h*w-1){
        ll y=i/w,x=i%w;
        ll d=1;
        if(y%2)x=w-1-x,d=-1;
        if(a[y][x]%2==0)continue;
        y1.push_back(y);
        x1.push_back(x);
        if(d==1&&x==w-1||d==-1&&x==0){
            y2.push_back(y+1);
            x2.push_back(x);
            ++a[y+1][x];
        }else{
            y2.push_back(y);
            x2.push_back(x+d);
            ++a[y][x+d];
        }
    }

    ll n=y1.size();
    cout<<n<<endl;
    rep(i,n){
        cout<<y1[i]+1<<' '<<x1[i]+1<<' '<<y2[i]+1<<' '<<x2[i]+1<<endl;
    }
}

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

int f(int x, int y, int z) {
    return x*x + y*y + z*z + x*y + y*z+ z*x;
}

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

    vector<int> a(n+1);

    for (int x = 1; x*x < n; x++) {
        for (int y = 1; y*y < n; y++) {
            for (int z = 1; z*z < n; z++) {
                int s = f(x, y, z);
                if (0 < s && s < n+1) {
                    a.at(s)++;
                }
            }
        }
    }

    for (int i = 1; i <= n; i++) {
        cout << a.at(i) << endl;
    }
    return 0;
}

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

int main() {

  int N;
  cin >> N;
  vector<int> d(N);
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  sort(d.begin(), d.end());
  cout << d.at(N / 2) - d.at(N / 2 - 1) << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
  set<int> S;
  int q;
  cin >> q;
  for (int i = 0; i < q; i++){
    int t;
    cin >> t;
    if (t == 0){
      int x;
      cin >> x;
      S.insert(x);
      cout << S.size() << endl;
    }
    if (t == 1){
      int x;
      cin >> x;
      if (S.count(x)){
        cout << 1 << endl;
      } else {
        cout << 0 << endl;
      }
    }
    if (t == 2){
      int x;
      cin >> x;
      S.erase(x);
    }
    if (t == 3){
      int L, R;
      cin >> L >> R;
      auto itr = S.lower_bound(L);
      while (*itr <= R && itr != S.end()){
        cout << *itr << endl;
        itr++;
        if (R < *itr){
          break;
        }
      }
    }
  }
}


Measured memory_bytes: 12472
n=int(input())
ans=0
i = 1
while i <= n:
    if i % 15 == 0:
      i += 1
    elif i % 3 == 0:
      i += 1
    elif i % 5 == 0:
      i += 1
    else:
      ans += i
      i += 1
    
print(ans)

Measured memory_bytes: 9124
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
cnt = 0
for k in c.keys():
    if c[k] % 2 == 0:
        cnt += 1
if cnt % 2:
    print(len(c) - 1)
else:
    print(len(c))

Measured memory_bytes: 18656
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>

using namespace std;

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)

int main()
{
    int a, b;
    while(cin >> a >> b) {
        int l = static_cast<int>(log10(a+b));
        cout << l+1 << "\n";
    }

    return 0;
}

Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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;
}
int main(){
ll n;
cin >> n;
vector<ll> x(n);
for (ll i = 0; i < n; i++) cin >> x[i];
vector<ll> y = x;
sort(y.begin(),y.end());
ll mid1 = n / 2 - 1;
ll mid2 = n / 2;
for (ll i = 0; i < n;i++){
    if (x[i] <= y[mid1])
        cout << y[mid2] << endl;
    else if (x[i] >= y[mid2])
        cout << y[mid1] << endl;
}
}

Measured memory_bytes: 5376
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int f[5];
	f[1]=a;
	f[2]=b;
	f[3]=c;
	f[4]=d;
	for(int i=1;i<5;i++){
		for(int j=i+1;j<5;j++){
			if(f[i]>f[j]){
				int t=f[i];
				f[i]=f[j];
				f[j]=t;
			}
		}
	}
	if(c>=b){
		cout<<'0'<<endl;
	}
	if(c<b){
		if(a>=d){
			cout<<'0'<<endl;
		}
		else{
			cout<<f[3]-f[2]<<endl;
		}
	}
	return 0;
}

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

int n;
int dp[1000005];
/*
int solve(ll a[], int i)
{
	if (i == n - 1)
	{
		return 0;
	}
	if (i > n - 1)
	{
		return INT_MAX;
	}

	if (dp[i] != -1)
	{
		return dp[i];
	}

	int value;
	value = min(abs(a[i + 1] - a[i]) + solve(a, i + 1), abs(a[i + 2] - a[i]) + solve(a, i + 2));

	return dp[i] = value;
}
*/

int main()
{
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	dp[1] = abs(a[1] - a[0]);
	for (int  i = 2; i < n; i++)
	{
		dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
	}
	cout << dp[n - 1] << endl;
	return 0;
}


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

alpha = {
    'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
}

S = input()

flg = True
for a in alpha:
    if S.count(a) % 2 != 0:
        flg = False
        break

if flg:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 8972
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,x;
  cin >> n >> x;
  vector<int> A(n);
  for(int i=0;i<n;i++){
    cin >> A.at(i) ;
  }
  int s = accumulate(A.begin(),A.end(),0);
  int m = *min_element(A.begin(),A.end());
  int ans = A.size()+(x-s)/m;
  cout << ans << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<queue>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
ll dx[4] = {1,0,0,-1};
ll dy[4] = {0,1,-1,0};

#define ARRAY_MAX 1005
int a[ARRAY_MAX];

int main(){

    int n;
    while(cin >> n,n){

        int maxi = -1;
        int mini = INF;
        vector<int> a(n);
        REP(i,n){
            cin >> a[i];
        }
        VSORT(a);
        int sum = 0;
        for(int i = 1;i < n-1;i++){
            sum += a[i];
        }
        cout << sum/(n-2) << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int main(){
	string s;
	cin>>s;
	int N=s.size();
	if(s[0]==s[N-1]){
	   if(N%2==0){
	      cout<<"First"<<endl;
	   }else{
	      cout<<"Second"<<endl;
	   }
	}else{
	   if(N%2==0){
	      cout<<"Second"<<endl;
	   }else{
	      cout<<"First"<<endl;
	   }
	}
	return(0);
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
using namespace std;
class dice
{
private:
  int men[100][10];
  int num;
public:
  void set_num();
  void throw_dice(int a, const char c);
  void try_dice();
};
void dice::throw_dice(int a,const char c)
{
  int buf;
  switch(c)
  {
    case 'N':
    {
      buf = men[a][0];
      men[a][0] = men[a][1];
      men[a][1] = men[a][5];
      men[a][5] = men[a][4];
      men[a][4] = buf;
      break;
    }
    case 'S':
    {
      buf = men[a][0];
      men[a][0] = men[a][4];
      men[a][4] = men[a][5];
      men[a][5] = men[a][1];
      men[a][1] = buf;
      break;
    }
    case 'W':
    {
      buf = men[a][0];
      men[a][0] = men[a][2];
      men[a][2] = men[a][5];
      men[a][5] = men[a][3];
      men[a][3] = buf;
      break;
    }
    case 'E':
    {
      buf = men[a][0];
      men[a][0] = men[a][3];
      men[a][3] = men[a][5];
      men[a][5] = men[a][2];
      men[a][2] = buf;
      break;
    }
    case 'L':
    {
      buf = men[a][1];
      men[a][1] = men[a][3];
      men[a][3] = men[a][4];
      men[a][4] = men[a][2];
      men[a][2] = buf;
      break;
    }
  }
}
void dice::set_num()
{
  cin >> num;
  for(int j = 0 ; j < num; j++)
  {
    for(int i = 0; i< 6; i++)
    {
      cin >> men[j][i];
    }
  }
}
void dice::try_dice()
{
  int cnt;
  int cnt2 = 0;
  for(int i = 0 ; i < (num - 1); i++)
  {
    for(int j = i + 1 ; j <num; j++)
    {
      if(men[j][0] == men[i][2] || men[j][0] == men[i][3])throw_dice(j,'E');
      cnt = 0;
      while(men[j][0] != men[i][0])
      {
        throw_dice(j,'S');
        cnt ++;
        if(cnt > 7)break;
      }
      cnt = 0;
      while(men[j][1] != men[i][1])
      {
        throw_dice(j,'L');
        cnt ++;
        if(cnt > 5)break;
      }
      for(int k = 0; k < 6; k++)
      {
        if(men[j][k] != men[i][k])
        {
          cnt2 = 1;
          break;
        }
        if(k == 5)cnt2 = 0;
      }
      if(cnt2 == 0)break;
    }
    if(cnt2 == 0)break;
  }
  if(cnt2 == 1)cout << "Yes" << endl;
  else cout << "No" << endl;

}
int main()
{
  dice dice1;
  dice1.set_num();
  dice1.try_dice();
  return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<ll,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  vector<ll> W(n), S(n), V(n);
  vector<P> A(n);
  rep(i,n) {
    cin >> W[i] >> S[i] >> V[i];
    A[i] = P(W[i]+S[i], i);
  }
  sort(all(A));
  vector<vector<ll> > dp(n+5, vector<ll>(20010, 0));
  rep(i,n) {
    int k = A[i].second; //k番目のブロック
    for (int j = 0; j <= 20005; ++j) {
      if (j - W[k] >= 0 && S[k] >= j - W[k]) {
        chmax(dp[i+1][j], dp[i][j - W[k]] + V[k]);
      }
      chmax(dp[i+1][j], dp[i][j]); //k番目を使わない
    }
  }
  ll ans = 0;
  for (int j = 0; j <= 20005; ++j) {
    chmax(ans, dp[n][j]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 161280
import numpy as np

N, M = map(int, input().split())

ab = []
for i in range(N):
    tmp = list(map(int, input().split()))
    ab.append(tmp)

ab = np.array(ab)
dist = np.full([N, M], np.inf)

for m in range(M):
    tmp = np.array(list(map(int, input().split())))
    for n in range(N):
        dist[n, m] = np.abs(ab[n] - tmp).sum()

dist = dist.astype("int")

for d in dist:
    print(d.argmin()+1)

Measured memory_bytes: 12868
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
using namespace std;

int main(){
  int n,input;
  cin >> n;
  vector<int> A;
  for(int i = 0; i < n ; i++) {
    cin >> input;
    A.push_back(input);
  }
  //descendingSort
  sort(A.begin(),A.end());
  //unique
  A.erase(unique(A.begin(),A.end()),A.end());
  cout << A.size() << endl;
}

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

int main(){
  int a, b;
  string op;

  while(1){
    cin >> a >> op >> b;
    if(op == "+"){
      cout << a + b << endl;
    }
    else if(op == "-"){
      cout << a - b << endl;
    }
    else if(op == "*"){
      cout << a * b << endl;
    }
    else if(op == "/"){
      cout << a / b << endl;
    }
    else break;
  }

}



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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << res << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, l, r)  (a).begin()+(l),(a).begin()+(r)

int main() {
	int n, m;
	cin >> n >> m;
	vector<pair<bool, int>> v(n + 1);
	FOR(i, 1, m) {
		int p;
		string s;
		cin >> p >> s;
		if (!v[p].first) {
			if (s == "AC") {
				v[p].first = true;
			}
			else {
				v[p].second++;
			}
		}
	}
	int res1 = 0, res2 = 0;
	FOR(i, 1, n) {
		if (v[i].first) {
			res1++;
			res2 += v[i].second;
		}
	}
	cout << res1 << " " << res2 << endl;
	return(0);
}

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
int p, q; double s;
int main() {
	while (1) {
		cin >> p >> q; s = 0;
		if (!p) { break; }
		s += p*p;
		s += 2.0 * p * sqrt(q*q + (double)(p*p) / 4);
		cout << fixed << setprecision(15) << s << endl;
	}
}

Measured memory_bytes: 1232
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
int compare(const void *a,const void *b){
    if(*(int *)a>*(int *)b)return 1;
    return -1;
}
int main()
{   int a[33]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
};
    int k;
    scanf("%d",&k);
    printf("%d",a[k-1]);
    return 0;
}


Measured memory_bytes: 128
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let mut it = line.trim().split_whitespace();
    let a = it.next().unwrap();
    let b = it.next().unwrap();
    if a < b {
        println!("<");
    } else if a == b {
        println!("=");
    } else {
        println!(">");
    }
}


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

const int MAXN = 100010;

inline int read() {
	int x = 0, f = 1;
	char ch = getchar();
	for(; !isdigit(ch); ch = getchar()) if(ch=='-') f=-1;
	for(; isdigit(ch); ch = getchar()) x = (x*10)+(ch^48);
	return x * f;
}

int st[MAXN], to[MAXN<<2];
int nxt[MAXN<<2], d[MAXN<<2], e;
inline void Add(int u, int v, int D) {
	to[++e] = v, nxt[e] = st[u];
	st[u] = e, d[e] = D;
	to[++e] = u, nxt[e] = st[v];
	st[v] = e, d[e] = -D;
}

int n, m, dis[MAXN];
bool vis[MAXN];

void dfs(int u) {
	vis[u] = true;
	int i;
	for(i = st[u]; i; i = nxt[i]) {
		int v = to[i];
		if(vis[v]) {
			if(dis[v] != dis[u]+d[i]) {
				printf("No\n");
				exit(0);
			}
			continue;
		}
		dis[v] = dis[u]+d[i], dfs(v);
	}
}

int main() {

	int i;
	n = read(), m = read();

	for(i = 1; i <= m; i++) {
		int u = read(), v = read();
		Add(u, v, read());
	}

	for(i = 1; i <= n; i++) 
		if(!vis[i]) dfs(i);
	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 7680
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef pair<int,int> ii;
#define inf 1e9
#define F first
#define S second
#define dbg(x) cout<<#x<<" value : "<<x<<"\n";
#define rep(i,j,k) for(int i = (j); i <= (k); i++)
#define rep__(i,j,k) for(int i = (j); i < (k); i++)
#define per(i,j,k) for(int i = (j); i >= (k); i--)
#define per__(i,j,k) for(int i = (j); i > (k); i--)
#define mst(a,b) memset(a,b,sizeof(a))
#define sf(n) scanf("%d",&n)
#define stf(n,m) scanf("%d%d",&n,&m)
#define pf(n) printf("%d\n",n)
#define slf(n) scanf("%lld",&n)
#define plf(n) printf("%lld\n",n)
priority_queue<int,vector<int>,less<int> > q;
const int N=1e5+10;
const int mod=1e9+7;
int n,m,sum,t,x,a[N],num;
inline int mx(int c,int y){return c>y?c:y;}
int main()
{
	LL t;
	cin>>t;
	cout<<t*(t-1)/2<<endl;
	
	return 0;
}


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

#define num sizeof(a)/sizeof(int)

long long ncr(long long,long long);//combi

int main(){
    long long i,j,k,n,instead,sum=0;scanf("%lld",&n);
    long long a[n+1],b[n+1];
    for(i=1;i<=n;i++){scanf("%lld",&a[i]);}
    for(i=0;i<=n;i++){b[i]=0;}//b[i]はa[]==iのときのiの個数

    for(i=1;i<=n;i++){
        b[a[i]]++;
    }//個数を数える
    
    for(j=1;j<=n;j++){
            if(b[j]>=2){
                sum+=ncr(b[j],2);
        }
    }//除かない場合の同数の組み合わせの数


    for(i=1;i<=n;i++){//a[i]を一つ除くときに減少する組み合わせ数をsumから引く
        if(b[a[i]]>=2){
            sum-=(b[a[i]]-1);
        }
        printf("%lld\n",sum);
        if(b[a[i]]>=2){
            sum+=(b[a[i]]-1);
        }
    }
    return 0;
}
long long ncr(long long a,long long b){//combination計算
    long long i,ans=1;
    for(i=1;i<=b;i++){
        ans=ans*(a-i+1)/i;
    }
    return ans;
}

Measured memory_bytes: 5632
#include<iostream>
#include<algorithm>
#define MAX_V 100
#define INF (1<<21)
using namespace std;

int cost[MAX_V][MAX_V];
int mincost[MAX_V];
bool used[MAX_V];
int V;
int prim(){
  for(int i = 0; i < V; i++){
    mincost[i] = INF;
    used[i] = false;
  }
  mincost[0] = 0;
  int res = 0;
  while(1){
    int v = -1;
    for(int u = 0; u < V; u++){
      if(!used[u] && (v == -1 || mincost[u] < mincost[v])) v = u;
    }
    if(v == -1) break;
    used[v] = true;
    res += mincost[v];
    for(int u = 0; u < V; u++){
      mincost[u] = min(mincost[u], cost[v][u]);
    }
  }
  return res;
}

int main(){
  int m;
  while(1){
    cin >> V;
    if(V == 0) break;
    for(int i = 0; i < V; i++){
      for(int j = 0; j < V; j++){
	cost[i][j] = INF;
      }
    }
    cin >> m;
    for(int i = 0; i < m; i++){
      int a, b, c;
      char d, e;
      cin >> a >> d >> b >> e >> c;
      cost[a][b] = c;
      cost[b][a] = c;
    }
    int t = prim();
    t = t / 100 - V + 1;
    cout << t << endl;
  }
}

Measured memory_bytes: 1200
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int n,k,d[2005],q[2005],ans;
vector<int> v[2005];
void dfs(int x,int y){
    memset(d,-1,sizeof(d));
    int s=0,o=k/2,qr=1;
    d[x]=0,q[1]=x;
    for(int ql=1;ql<=qr;++ql){
        ++s;
        int _=q[ql];
        if(d[_]==o) continue;
        for(int i=0;i<v[_].size();++i){
            if(v[_][i]!=y&&d[v[_][i]]==-1){
                d[v[_][i]]=d[_]+1;
                q[++qr]=v[_][i];
            }
        }
    }
    if(y){
        o=k-o-1,qr=1;
        d[y]=0,q[1]=y;
        for(int ql=1;ql<=qr;++ql){
            ++s;
            int _=q[ql];
            if(d[_]==o) continue;
            for(int i=0;i<v[_].size();++i){
                if(v[_][i]!=x&&d[v[_][i]]==-1){
                    d[v[_][i]]=d[_]+1;
                    q[++qr]=v[_][i];
                }
            }
        }
    }
    ans=max(ans,s);
    for(int i=0;i<v[x].size();++i)if(v[x][i]!=y)dfs(v[x][i],x);
}
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<n;++i){
        int x,y;
        scanf("%d%d",&x,&y);
        v[x].pb(y);
        v[y].pb(x);
    }
    dfs(1,0);
    printf("%d\n",n-ans);
    //system("pause");
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

const int MAXN = 100010;
typedef long long ll;

int n, m;

inline int add(int x, int y){return (x+=y)>=m?x-m:x;}
inline int mul(int x, int y){return 1ll*x*y%m;}

struct edge{
	int next, to;
	edge(int N=0,int T=0):next(N),to(T){}
}e[MAXN<<1];
int fir[MAXN], num = 0;
inline void join(int a, int b)
{
	e[++num].next = fir[a];
	fir[a] = num;
	e[num].to = b;
}

int f[MAXN], g[MAXN], ans[MAXN], pre[MAXN], suf[MAXN], t[MAXN];
vector<int> in[MAXN];

void dfs1(int u, int fa)
{
	int cnt = 0;
	f[u]    = 1;
	in[u].push_back(1);
	for(int i=fir[u]; i; i=e[i].next)
	{
		int v = e[i].to;
		if(v == fa) continue;
		dfs1(v, u);
		f[u] = mul(f[u], add(f[v], 1));
		cnt++;
		in[u].push_back(v);
	}
	pre[0] = suf[cnt+1] = 1;
	for(int i=1; i<=cnt; i++)
		pre[i] = mul(pre[i-1], add(f[in[u][i]], 1));
	for(int i=cnt; i>=1; i--)
		suf[i] = mul(suf[i+1], add(f[in[u][i]], 1));
	for(int i=1; i<=cnt; i++)
		t[in[u][i]] = mul(pre[i-1], suf[i+1]);
}
void dfs2(int u, int fa)
{
	int cnt = 0;
	for(int i=fir[u]; i; i=e[i].next)
	{
		int v = e[i].to;
		if(v == fa)continue;
		++cnt;
		g[v] = add(mul(g[u], t[v]), 1);
		ans[v] = mul(g[v], f[v]);
		dfs2(v, u);
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1,a,b;i<n;i++)
		scanf("%d%d",&a,&b), join(a, b), join(b, a);
	dfs1(1, 0);
	g[1] = 1; ans[1] = f[1];
	dfs2(1, 0);
	for(int i=1;i<=n;i++)
		printf("%d\n" ,ans[i]);
	return 0;
}

Measured memory_bytes: 17664
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647 -> 10桁
// MAX ll 9,223,372,036,854,775,807 -> 19桁
// MAX O(n) 10^18 -> 18回
// double pi = M_PI or acos(-1)


int main() {
    int a, b, h, m;
    cin >> a >> b >> h >> m;

    // 角度を求める
    double cAngle = 2 * M_PI * (((h + (double)m / 60) / 12) - (double)m / 60);
    double tmp = a * a + b * b - 2 * a * b * cos(cAngle);
    double ans = sqrt(tmp);

    cout << fixed << setprecision(9) << ans << endl;

    return 0;
}


Measured memory_bytes: 4260
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        try(Scanner sc = new Scanner(System.in)){
            int w = sc.nextInt();
            int n = sc.nextInt();
            int[] values = new int[w];

            for(int i=0;i<values.length; i++){
                values[i] = i + 1;
            }

            for(int i=0; i<n; i++) {
                String str = sc.next();
                String[] ab = str.split(",");
                int a = Integer.parseInt(ab[0]) - 1;
                int b = Integer.parseInt(ab[1]) - 1;

                int x = values[a];
                values[a] = values[b];
                values[b] = x;

            }
            for(int i=0; i<w; i++) {
                System.out.println(values[i]);
            }
        }
    }
}


Measured memory_bytes: 25956