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

template<class T> struct rge { T b, e; };
template<class T> rge<T> range(T i, T j) { return rge<T>{i, j}; }
struct debug {
#ifdef LOCAL
    ~debug(){cerr<<endl;}
    template<class T> debug& operator<<(T x){cerr<<boolalpha<<x; return *this;}
    template<class B, class C> debug& operator<<(pair<B, C> x){return *this<<"("<<x.first<<", "<<x.second<<")";}
    template<class T> debug& operator<<(rge<T> x){*this<<"[";for(auto it=x.b;it!=x.e;it++){*this<<", "+2*(it==x.b)<<*it;}return *this<<"]";}
    template<class T> debug& operator<<(vector<T> x){ return *this<<range(x.begin(),x.end());}
#else
    template<class T> debug& operator <<(const T&){return *this;}
#endif
};
#define nav(...) << "[ " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " ] "
using ll = long long;

#define forn(i, n) for(int i = 0; i < int(n); i++)
#define ford(i, n) for(int i = n-1; i >= 0; i--) 

template<typename T> 
void min_self(T& a, T b) { 
    a = min(a, b); 
}
template<typename T>
void max_self(T& a, T b) { 
    a = max(a, b); 
}



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

    string s, t;
    cin >> s >> t;
    int n = s.length();
    forn(i, n) if(s[i]!=t[i]) {
        cout << "No\n";
        exit(0);
    }
    cout << "Yes\n";
}













// Those who say they can, and those who say they can't - are both usually right.

// Read statement carefully
// Solve on paper first!
// Overflows (long long)

// Author: blondie


Measured memory_bytes: 3544
/*
 * For debug of betit0919's code
 */

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>
 
using namespace std;
typedef long long ll;
 
const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
 
struct UnionFind {
  vector<int> par;
 
  UnionFind(int n) : par(n, -1) { }
  void init(int n) { par.assign(n, -1); }
 
  int root(int x) {
    if (par[x] < 0) return x;
    else return par[x] = root(par[x]);
  }
 
  bool issame(int x, int y) {
    return root(x) == root(y);
  }
 
  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }
 
  int size(int x) {
    return -par[root(x)];
  }
};
 
int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;
  cin>>N;
  vector<pair<int,int>> X(N),Y(N);
  for(int i=0;i<N;i++){
    int x,y;cin>>x>>y;
    X[i]=make_pair(x,i);
    Y[i]=make_pair(y,i);
  }
  map<int,pair<set<int>,set<int>>> mp;
  sort(ALL(X));sort(ALL(Y));
 
  UnionFind uf(N);
 
  for(int i=0;i<N-1;i++){
    if(X[i].first==X[i+1].first){
      uf.merge(X[i].second,X[i+1].second);
    }
    if(Y[i].first==Y[i+1].first){
      uf.merge(Y[i].second,Y[i+1].second);
    }
  }
  for(int i=0;i<N;i++){
    mp[uf.root(X[i].second)].first.insert(X[i].first);
    mp[uf.root(Y[i].second)].second.insert(Y[i].first);
  }
  ll ans=0ll;
  for(auto e : mp){
    ans+=1ll*e.second.first.size()*e.second.second.size();
  }
  cout<<ans-N<<endl;
}

Measured memory_bytes: 11648
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
using namespace std;

const double PI=acos(-1);

int main(){
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    char t = ' ';
    int cnt = 1;
    bool z = true;
    for(int i = 0; i < s.length(); i++, cnt++){
        if(s.length() == 1){
            z = false;
            break;
        }
        if(s[i] != t){
            if(i != 0 && cnt%2 != 0){
                z = false;
                break;
            }
            t = s[i];
            cnt = 0;
        }
    }
    if(z) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    N, M = map(int, input().split())
    num = [None for i in range(N)]

    for i in range(M):
        s, c = map(int, input().split())
        
        if num[s-1] == None:
            num[s-1] = c
        elif num[s-1] == c:
            pass
        else:
            print("-1")
            exit()

    for i in range(N):
        if i == 0:
            if len(num) == 1:
                if num[i] == None:
                    num[i] = 0
            else:
                if num[i] == None:
                    num[i] = 1
        else:
            if num[i] == None:
                num[i] = 0

    if N == len(str(int("".join(map(str, num))))):
        print("".join(map(str, num)))
    else:
        print("-1")

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a % 3 == 0 || b % 3 == 0 || (a+b)%3 == 0) {
            System.out.println("Possible");
        } else {
            System.out.println("Impossible");
        }
    }
}

Measured memory_bytes: 22996
n, m = [int(i) for i in input().split()]
L = [[int(i) for i in input().split()] for i in range(m)]

imos = [0] * (n + 2)

for l, r in L:
    imos[l] += 1
    imos[r + 1] -= 1

ans = 0

for i in range(n + 1):
    imos[i + 1] += imos[i]
    if imos[i + 1] >= m:
        ans += 1

print(ans)

Measured memory_bytes: 61272
#include<stdio.h> 
#include <iostream>
#include <algorithm>
#include<string>
#include<string.h>
#include<math.h>
/****  STL  ****/
#include<vector>
#include<queue>
#include<unordered_map>
#include<unordered_set>

#define uint unsigned int
#define ll long long
#define kMin -1
using namespace std;

const int kMax = 1600;
const int kInf = 1e9;

int a[30], ax = 0;
int b[30], bx = 0;
char cs[105];
int  main()
{
	int n;
	while (cin >> n)
	{
		memset(a, 0, sizeof(a));
		memset(b, 0, sizeof(b));
		ax = 0;
		bx = 0;

		char c;
		for (int i = 0; i < n; i++)
		{
			cin >> c;
			cs[i] = c;
			if (b[c - 'a'] == 0)
			{
				bx++;
			}
			b[c - 'a']++;
		}
		int maxx = -1;
		for (int i = 0; i < n - 1; i++)
		{
			b[cs[i] - 'a']--;
			if (a[cs[i] - 'a'] == 0)ax++;
			if (b[cs[i] - 'a'] == 0)
			{
				ax--;
				if (ax < 0)ax = 0;
			}
			a[cs[i] - 'a']++;

			maxx = max(maxx, ax);
		}
		cout << maxx << endl;
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var N = int.Parse(Console.ReadLine());
			List<int> tmp = new List<int>();
			for (int i = 0; i < N; i++)
			{
				tmp.Add(int.Parse(Console.ReadLine()));
			}
			var tmpMax = tmp.Max();
			bool isAddMax = false;
			int result = 0;
			for (int i = 0; i < tmp.Count; i++)
			{
				if (!isAddMax && tmpMax == tmp[i])
				{
					result += tmp[i] / 2;
					isAddMax = true;
					continue;
				}
				result += tmp[i];
			}
			Console.Write(result);
		}
	}
}


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

void Main() {
  int H, W, K;
  cin >> H >> W >> K;
  char m[H][W];

  int bnum = 0;
  int c[W], r[H];
  memset(c, 0, sizeof(c));
  memset(r, 0, sizeof(r));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> m[i][j];
      if (m[i][j] == '#') {
        bnum++;
        c[j]++;
        r[i]++;
      }
    }
  }

  long long ans = 0;
  for (int i = 0; i < (1 << H); i++) {
    for (int j = 0; j < (1 << W); j++) {
      vector<int> rows, cols;
      int btor = 0;
      for (int ii = 0; ii < H; ii++) {
        if (i & (1 << ii)) {
          rows.push_back(ii);
          btor += r[ii];
        }
      }

      for (int jj = 0; jj < W; jj++) {
        if (j & (1 << jj)) {
          cols.push_back(jj);
          btor += c[jj];
        }
      }

      int d = 0;
      for (auto row: rows) {
        for (auto col: cols) {
          if (m[row][col] == '#') d++;
        }
      }

      if (K == bnum - (btor - d)) ans++;
    }
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<string>
#include<map>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    map<P, ll> cnt;
    rep(i, 1, N + 1) {
        int d = 0;
        int tmp = i;
        while (tmp > 0) {
            ++d;
            tmp /= 10;
        }
        int a = i;
        rep(j, 0, d - 1) {
            a /= 10;
        }
        int b = i % 10;
        ++cnt[P(a, b)];
    }
    ll ans = 0;
    rep(i, 1, 10) rep(j, 0, 10) {
        ans += cnt[P(i, j)] * cnt[P(j, i)];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// review
#include <iostream>

using namespace std;

bool candidate[2] = {true, false};

bool state[100010];
int n;
string s;

bool next(int pos) {
  return (s[pos-1] == 'o') ^ state[pos-1] ^ state[pos-2];
}

bool dfs(int pos) {
  if (pos == n + 2) {
    if (state[0] == state[n] && state[1] == state[n+1]) {
      for (int i=0;i<n;i++) {
        if (state[i]) {
          cout << 'S';
        } else {
          cout << 'W';
        }
      }
      cout << endl;
      return true;
    }
    return false;
  }
  state[pos] = next(pos);
  return dfs(pos+1);
}

void solve() {
  s = s + s[0] + s[1];
  for (int i=0;i<2;i++) {
    for (int j=0;j<2;j++) {
      state[0] = candidate[i];
      state[1] = candidate[j];
      if (dfs(2)) {
        return;
      }
    }
  }
  cout << -1 << endl;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> s;
  solve();
}


Measured memory_bytes: 5356
#include <iostream>

int main(){
   int N;
   std::cin >> N;

   int M = N;
   int sum = 0;
   for(int i=0; i<10; ++i){
      sum += M % 10;
      M /= 10;
   }
   if(N%sum==0) std::cout << "Yes" << std::endl;
   else std::cout << "No" << std::endl;

   return 0;
}


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

bitset<100010> prime;
const int ub = 100003;

void sieve()
{
    prime.set();
    prime[0] = prime[1] = 0;

    for(int I = 4; I<=ub; I+=2)
    {
        prime[I] = 0;
    }

    for(int I = 3; I*I<=ub; I+=2)
    {
        if(prime[I])
        {
            for(int J = I*I; J<=ub; J+=I)
            {
                prime[J] = 0;
            }
        }
    }

}

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

    sieve();
    int N;
    cin>>N;
    while(!prime[N])N++;
    cout<<N<<endl;
    return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int N,M; cin >> N >> M;
	vector<int> A(N),B(M);
	repp(i,0,N) cin >> A[i];
	repp(j,0,M) cin >> B[j];
	sort(A.begin(),A.end(),greater<int>());
	sort(B.begin(),B.end(),greater<int>());
	A.push_back(-1); B.push_back(-1);
	const LL mod = 1e9 + 7;
	LL ans = 1;
	int x = 0, y = 0;
	repm(i,N*M,0){
		if(A[x] == i){
			if(B[y] == i){
				++y;
			} else {
				(ans *= y) %= mod;
			}
			++x;
		} else if(B[y] == i){
			(ans *= x) %= mod;
			++y;
		} else {
			if(x*y-N*M+i <= 0) return cout << 0 << endl, 0;
			(ans *= x*y-N*M+i) %= mod;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x,a,b;
    cin>>x>>a>>b;
    if(b-a>x)
        cout<<"dangerous"<<endl;
    else if(a>=b)
        cout<<"delicious"<<endl;
    else 
        cout<<"safe"<<endl;
}

Measured memory_bytes: 256
n = int(input())
a = sorted(list(map(int,input().split())))
double_cnt = 0
flag = 0
for i in range(n):
  if flag == a[i]:
    double_cnt += 1
  else:
    flag = a[i]
if double_cnt % 2 == 0:
  print(n-double_cnt)
else:
  print(n-double_cnt-1)

Measured memory_bytes: 52908
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))

L = [0]
for i in range(N):
    L.append(gcd(L[i],A[i]))
    
R = [0]
for i in range(N-1,-1,-1):
    R.append(gcd(R[-(i-N+1)],A[i]))
R.reverse()

M = []
for i in range(N):
    M.append(gcd(L[i],R[i+1]))
    
print(max(M))

Measured memory_bytes: 16148
import math
N=int(input())
A=[int(i) for i in input().split()]
ans=0
d=0
for i in range(N):
    if A[i]!=i+1:
        ans+=int(math.ceil(d/2))
        d=0
    else:
        d+=1
ans+=int(math.ceil(d/2))
print(ans)

Measured memory_bytes: 13812
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, sta, n) for (int i = sta; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
const int mod = 1000000007;
ll dp[100100][3];

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);

    rep(i, n) cin >> a[i] >> b[i] >> c[i];
    rep(i, n) {
        dp[i+1][0] = max(dp[i][1] + a[i], dp[i][2] + a[i]);
        dp[i+1][1] = max(dp[i][0] + b[i], dp[i][2] + b[i]);
        dp[i+1][2] = max(dp[i][0] + c[i], dp[i][1] + c[i]);
    }
    cout << max({dp[n][0],dp[n][1],dp[n][2]}) << endl;
    return 0;
}


Measured memory_bytes: 3712
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner
var out *bufio.Writer

const INF = 1 << 30

func main() {
	sc = bufio.NewScanner(os.Stdin)
	//bytes, _ := ioutil.ReadFile("./stdin.txt")
	//sc = bufio.NewScanner(strings.NewReader(string(bytes)))
	out = bufio.NewWriter(os.Stdout)
	buf := make([]byte, 1<<20)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	N, M, K := nextInt3()
	G1 := make([][]int, N+1)
	G2 := make([][]int, N+1)
	c, d := make([]int, K), make([]int, K)
	for i := 0; i < M; i++ {
		a, b := nextInt2()
		G1[a] = append(G1[a], b)
		G1[b] = append(G1[b], a)
	}
	for i := 0; i < K; i++ {
		a, b := nextInt2()
		G2[a] = append(G2[a], b)
		G2[b] = append(G2[b], a)
		c[i], d[i] = a, b
	}
	G := [2]*[][]int{&G1, &G2}
	group := [2][]int{make([]int, N+1), make([]int, N+1)}
	for i := 0; i < 2; i++ {
		id := 1
		for j := 1; j <= N; j++ {
			if group[i][j] == 0 {
				dfs(*G[i], group[i], j, id)
				id++
			}
		}
	}
	c1 := make([]int, N+1)
	c2 := make([]map[int]int, N+1)
	for i := 1; i <= N; i++ {
		c2[i] = make(map[int]int)
	}
	for i := 1; i <= N; i++ {
		c1[group[0][i]]++
	}
	for i := 0; i < K; i++ {
		if group[0][c[i]] == group[0][d[i]] {
			c2[c[i]][group[1][c[i]]]++
			c2[d[i]][group[1][d[i]]]++
		}
	}
	for i := 1; i <= N; i++ {
		result := c1[group[0][i]] - len(G1[i]) - c2[i][group[1][i]] - 1
		fmt.Fprint(out, result)
		if i == N {
			fmt.Fprintln(out, "")
		} else {
			fmt.Fprint(out, " ")
		}
	}

}

func dfs(G [][]int, group []int, u, id int) {
	group[u] = id
	for e := 0; e < len(G[u]); e++ {
		v := G[u][e]
		if group[v] == 0 {
			dfs(G, group, v, id)
		}
	}
}

func next() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}
func nextInt2() (int, int)      { return nextInt(), nextInt() }
func nextInt3() (int, int, int) { return nextInt(), nextInt(), nextInt() }
func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func cond(condition bool, t, f int) int {
	if condition {
		return t
	}
	return f
}
func abs(a int) int { return cond(a < 0, -a, a) }
func min(a ...int) int {
	ret := a[0]
	for i := 1; i < len(a); i++ {
		chmin(&ret, a[i])
	}
	return ret
}
func max(a ...int) int {
	ret := a[0]
	for i := 1; i < len(a); i++ {
		chmax(&ret, a[i])
	}
	return ret
}
func chmin(a *int, b int) { *a = cond(*a < b, *a, b) }
func chmax(a *int, b int) { *a = cond(*a > b, *a, b) }


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

using namespace std;
using ll = long long;

int main() {
    int N = 0;
    cin >> N;
    int pay = 0;
    int change = 0;

    if (N%1000 == 0)
    {
        pay = N;
        change = pay - N;
        cout << change << endl;
    }else
    {
        pay = N/1000*1000 + 1000;
        change = pay-N;
        cout << change << endl;
    }
    
}

Measured memory_bytes: 3624
#include<stdio.h>
int main()
{
	long long int n, m;
	scanf("%lld %lld", &n, &m);
	long long int i;
	long long int x[100005], y[100005];
	for (i = 0; i < n; i++)
		scanf("%lld", &x[i]);
	for (i = 0; i < m; i++)
		scanf("%lld", &y[i]);
	long long int p = 1e9 + 7;
	long long int X, Y;
	X = Y = 0;
	for (i = 0; i < n - 1; i++)
		X = (X + (x[i + 1] - x[i]) * (i + 1) * (n - i - 1)) % p;
	for (i = 0; i < m - 1; i++)
		Y = (Y + (y[i + 1] - y[i]) * (i + 1) * (m - i - 1)) % p;
	printf("%lld\n", X * Y % p);
	return 0;
}

Measured memory_bytes: 1664
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations, product
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

N = int(input())
L = [0]*26
for _ in range(N):
    S = input()
    L[ston(S[0],'A')] += 1
s = ['M','A','R','C','H']
ans = 0
for l in combinations(s,3):
    x,y,z = map(lambda x:ston(x,'A'), l)
    ans += L[x]*L[y]*L[z]
print(ans)

Measured memory_bytes: 74788
#include <iostream>

using namespace std;

int f(int ab, int bc, int ca) {
    if (ab > bc && ab > ca) {
        return bc * ca / 2;
    }
    if (bc > ab && bc > ca) {
        return ab * ca / 2;
    }
    return ab * bc / 2;
}

int main() {

    int ab, bc, ca;
    cin >> ab >> bc >> ca;

    int result = f(ab, bc, ca);
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#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##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T1, class T2>bool chmax(T1& a, const T2& b) { return a < b ? a = b, 1 : 0; }
template<class T1, class T2>bool chmin(T1& a, const T2& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int N, M, P;
vector<vector<pair<ll, int>>> graph;
vector<ll> dist;
vector<vector<int>> igraph;
vector<bool> visited;

void dfs(int v) {
    visited[v] = true;
    for (int u : igraph[v]) {
        if (!visited[u]) {
            dfs(u);
        }
    }
}

bool spfa(int s) {
    dist.assign(N, LINF);
    dist[s] = 0;
    queue<int> que;
    que.push(s);
    vector<bool> in_queue(N);
    vector<int> cnt_update(N, 0);
    cnt_update[s]++;

    while (!que.empty()) {
        int v = que.front(); que.pop();
        in_queue[v] = false;

        for (auto& e : graph[v]) {
            if (dist[v] + e.first < dist[e.second]) {
                dist[e.second] = dist[v] + e.first;

                if (!in_queue[e.second]) {
                    que.push(e.second);
                    in_queue[e.second] = true;

                    cnt_update[e.second]++;
                    if (cnt_update[e.second] == 2 * N && e.second == N - 1) {
                        return true;
                    }
                    if (cnt_update[e.second] == 4 * N) {
                        if (visited[e.second]) {
                            return true;
                        }
                        else {
                            return false;
                        }
                    }
                }
            }
        }
    }

    return false;
}

int main() {
    cin >> N >> M >> P;
    graph.resize(N);
    igraph.resize(N);
    rep(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        graph[a].emplace_back(P - c, b);

        igraph[b].push_back(a);
    }

    visited.assign(N, false);
    dfs(N - 1);

    bool nega_cycle = spfa(0);
    if (nega_cycle) {
        write(-1);
    }
    else {
        write(max(0LL, -dist[N - 1]));
    }
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <iterator>
#include <functional>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <list>
#include <sstream>
#include <cstring>
#include <stdio.h>
#include <complex>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

typedef double LD;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<string> VS;
typedef vector<VS> VSS;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define next fake_next
#define prev fake_prev
#define left fake_left
#define right fake_right

#define FOR(i, a, b) for(LL i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i, 0, t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))

const LD PI = acos(-1.0);
const LD EPS = 1e-6;
const LL INF = 1e9;
const LL LINF = 1e18;
const LL mod = 1000000007;
const LL MAXN = 5e5 + 47;
const LL MAX = 47;

int n;
int od = 0;
string s;
int DP[MAXN];
int next[MAXN];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	
	int n;
	string s;
	cin >> n >> s;
	FOR(i, 0, MAXN)
		DP[i] = n;
	
	DP[0] = 0;
	next[n] = n;
	FOR(i, 0, n)
	{
		next[i] = n;
		if (s[i] == '1')
			++od;
	}

	RFOR(i, n, 0)
	{	
		if (s[i] == '0')
			next[i] = i;
		else
			next[i] = next[i + 1];
	}

	FOR(i, 0, n)
	{
		if (s[i] == '0')
		{
			DP[i + 1] = DP[i];
			continue;
		}
		
		DP[i + 1] = min(DP[i] + 1, DP[i + 1]);
		if (next[i] == i + 1)
		{
			FOR(j, i + 2, n)
				if (s[j] == '1')
					DP[j + 1] = min(DP[j + 1], DP[i] + 1);
				else
					break;

			continue;
		}
		
		DP[next[i] + 2] = min(DP[next[i] + 2], DP[i] + 1);
	}

	cout << od - DP[n];
	cin >> n;
	return 0;
}

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

int main(){
  char s[1000000];
  char t[1000000];
  scanf("%s",s);
  int len = strlen(s);
  int n;
  int count=0;
  for(n=0;n<len;n++){
    if(s[n]!='x'){
      t[count] = s[n];
      count++;
    }
  }
  int left[100000]={};
  int right[100000]={};
  int left_p=0;
  int right_p=0;





  int flag = 1;
  for(n=0;n < count/2 ; n++){
    if(t[n] != t[count-1-n]){
      flag = 0;
    }
  }
  if(flag == 0){
    printf("-1");
  }
  else{
      for(n=0;n<len;n++){
        if(s[n]=='x'){
          left[left_p]++;
        }
        else{
          left_p++;
        }
      }
      for(n=len-1;n>=0;n--){
        if(s[n]=='x'){
          right[right_p]++;
        }
        else{
          right_p++;
        }
      }
      int sum=0;

      for(n=0;n<100000;n++){
        sum += (left[n] > right[n]) ? (left[n]-right[n]) : (right[n]-left[n]);
      }

      printf("%d",sum/2);
    }




}

Measured memory_bytes: 2816
void main() {
    string n = readln.chomp;
    while (n.count(n[0]) != 3) {
        n = n.succ;
    }
    n.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons;

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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;

#define forn(i, n) for(int i=0; i<n; i++)
#define mp makepair
#define pb push_back

const int MOD = 1e9 + 7;

int main(){
    int H,W;
    string m[1000];
    int ans[1000][1000] = {0};
    scanf("%d%d",&H, &W);
    for(int i=0;i<H;i++){
        cin >> m[i];
    }
    ans[0][0] = 1;

    for(int i=0;i<H;i++)
        for(int j=0;j<W;j++) {
            if(i > 0 && m[i-1][j] != '#')
                ans[i][j] = (ans[i][j] + ans[i-1][j]) % MOD;
            if(j > 0 && m[i][j-1] != '#')
                ans[i][j] = (ans[i][j] + ans[i][j-1]) % MOD;
        }

    cout<<ans[H-1][W-1]<<endl;

}


Measured memory_bytes: 5248
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
using namespace std;

#define fi first
#define se second
typedef long long LL;
typedef long double LD;


struct edge{
    LL x,y,c;
    edge(){}
    edge(LL x, LL y, LL c) : x(x), y(y), c(c) {}
};

int N,t[100010],sz[100010],x[100010],y[100010],ind[100010];
edge a[300010]; int K;
LL res=0;

int getf(int x){
    return (t[x]==x ? x : t[x]=getf(t[x]));
}

void add_edge(int x, int y, LL c){
    x=getf(x),y=getf(y);
    if (x==y) return;
    if (sz[x]>sz[y]) swap(x,y);

    t[x]=y,sz[y]+=sz[x];
    res+=c;
}

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

    int i;
    for (i=1; i<=N; i++){
        cin >> x[i] >> y[i];
        ind[i]=t[i]=i;
        sz[i]=1;
    }

    sort(ind+1,ind+N+1,[](int a, int b){ return x[a]<x[b]; });
    for (i=1; i<N; i++)
        a[++K]=edge(ind[i],ind[i+1],min(abs(x[ind[i]]-x[ind[i+1]]),abs(y[ind[i]]-y[ind[i+1]])));

    sort(ind+1,ind+N+1,[](int a, int b){ return y[a]<y[b]; });
    for (i=1; i<N; i++)
        a[++K]=edge(ind[i],ind[i+1],min(abs(x[ind[i]]-x[ind[i+1]]),abs(y[ind[i]]-y[ind[i+1]])));

    sort(a+1,a+K+1,[](edge A, edge B){ return A.c<B.c; });
    for (i=1; i<=K; i++)
        add_edge(a[i].x,a[i].y,a[i].c);

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


Measured memory_bytes: 9344
import java.util.*;
public class Main {
  public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
  int a = sc.nextInt();
  int b = sc.nextInt();
  if ((a*b)%2==0) {
  System.out.println("Even");
  }
  else{
  System.out.println("Odd");
  }
  }
}


Measured memory_bytes: 22996
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#include<bitset>
#include<stack>
#include<set>
#include<vector>
#include <time.h>
#include<string.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 1e5+5;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e=exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define ok cout<<"OK"<<endl
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
int k[maxn],p[maxn];
vector<int> km[maxn];
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,m,x;
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++)
    {
        scanf("%d",&k[i]);
        for(int j=0;j<k[i];j++)
        {
            scanf("%d",&x);
            km[i].push_back(x-1);
        }
    }
    int ans=0;
    for(int i=0;i<m;i++) scanf("%d",&p[i]);
    for(int i=0;i<(1<<n);i++)
    {
        int sum=0;
        for(int j=0;j<m;j++)
        {
            int cnt=0;
            for(int t=0;t<km[j].size();t++)
            {
                int to=km[j][t];
                if(i&(1<<to)) cnt++;
            }
            if((cnt%2)==p[j]) sum++;
        }
        if(sum==m)
        {
           // dbg(i);
            ans++;
        }
    }
    printf("%d\n",ans);
    //cout << "time: " ;<< (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 2560
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt
  val a = Seq.fill(n)(sc.nextInt)

  val (m1, m2) = a.foldLeft((0, 0)) {
    case ((m1, m2), v) =>
      if (v > m1) {
        (v, m1)
      } else if (v > m2) {
        (m1, v)
      } else {
        (m1, m2)
      }
  }

  a.foreach { a =>
    if (a == m1) {
      println(m2)
    } else {
      println(m1)
    }
  }
}

Measured memory_bytes: 102368
fun solve(n:Int, k:Int, a:List<Int>){
    val b = a.sorted()
    var ans = 0
    for(i in 0 until k) {
        ans += b[i]
    }
    println(ans)

}

fun main(){
    val (n, k) = readLine()!!.split(" ").map{it.toInt()}
    val a = readLine()!!.split(" ").map{it.toInt()}
    solve(n,k,a)
}

Measured memory_bytes: 40680
N,M = [int(i) for i in input().split()]

submissions = {str(i):[] for i in range(1,N+1)}

AC,WA = 0,0

for i in range(M):

    P,S = [j for j in input().split()]

    submissions[P].append(S)

for i in submissions:

    if 'AC' not in submissions[i]:

        continue

    for j in submissions[i]:

        if j == 'AC':

            AC+=1

            break

        WA +=1

print(AC,WA)

Measured memory_bytes: 31248
import java.util.Scanner;

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

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

    long[][] dp = new long[1 << N][N + 1];
    dp[0][0] = 1;

    for (int i = 1; i < 1 << N; i++) {
      int j = (i >> 1) & 03333333333;
      j = i - j - ((j >> 1) & 03333333333);
      j = ((j + (j >> 3)) & 0707070707) % 077;

      for (int k = 0; k < N; k++) {
        if ((i & (1 << k)) != 0) {
          dp[i][j] += dp[i ^ (1 << k)][j - 1] * a[j][k];
          if (dp[i][j] > M) dp[i][j] -= M;
        }
      }
    }
    System.out.println(dp[(1 << N) - 1][N]);
  }
}


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

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String[] words = new String[N];
        for (int i = 0; i < N; i++) {
            words[i] = sc.next();
        }
        long c1 = Arrays.stream(words).filter(s -> s.startsWith("B") && s.endsWith("A")).count();
        long c2 = Arrays.stream(words).filter(s -> s.startsWith("B") && !s.endsWith("A")).count();
        long c3 = Arrays.stream(words).filter(s -> !s.startsWith("B") && s.endsWith("A")).count();
        long containsAB = cotntains(words);

        long min = Math.min(c3 + c1, c2 + c1);

        if (c3 + c2 == 0 && c1 > 0) {
            System.out.println(containsAB + c1 - 1);
        } else {
            System.out.println(containsAB + min);
        }
    }

    private static long cotntains(String[] words) {
        long cnt = 0;
        for (String string : words) {
            int size = string.length();
            for (int i = 0; i < size; i++) {
                if (string.charAt(i) == 'A' & i + 1 < size && string.charAt(i + 1) == 'B') {
                    cnt++;
                }
            }
        }
        return cnt;
    }
}


Measured memory_bytes: 33836
class Integer
  def combination
    n = self
    r = 0
    (0..9).each do |a|
      (0..9).each do |b|
        (0..9).each do |c|
          (0..9).each do |d|
            if a + b + c + d == n
              r += 1
              break
            end
          end
        end
      end
    end
    r
  end
end

while line = gets
  puts line.chomp.to_i.combination
end

Measured memory_bytes: 6092
#include<iostream>
#include<cstring>
using namespace std; // 575

const int MAX = 1000000;
int main() {
	int s;
	cin >> s;
	bool table[MAX];
	memset(table, false, sizeof(table));
	for (int i = 1;i <= MAX;++ i) {
		if (table[s]) {
			cout << i;
			return 0;
		}
		table[s] = true;
		s = (s & 1) == 0 ? s / 2 : 3 * s + 1;
	}
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

実際にやってみれば解決するよ
*/

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mset(x, y) memset((x), (y), sizeof(x))
#define sz(x) ((int)(x).size())
#define rep(i, a, b) for(i = a; i < b; i++)
#define per(i, a, b) for(i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define cerr cout
#define endl '\n'
using namespace std;

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ld eps = 1e-7;
const ll mod = 1000000007;
const ll N = 998244353;

ll binpow(ll b, ll p){ ll ans = 1; while(p > 0){if(p & 1) ans = (ans * b) % mod; b = (b * b) % mod; p >>= 1;}return ans;}
ll modinv(ll x){return binpow(x, mod - 2);}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int x;
	cin >> x;
	cout << (x >= 30 ? "Yes" : "No");
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
using namespace std;
int main() {
    fast();
    // /ll t;
    // cin>>t;
    // while(t--)			
    // {
    
    // }
    ll n;
    cin>>n;
    if(n>=30)
    cout<<"Yes"<<endl;
    else
    cout<<"No";
}

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

int main(){
	long long int n;
	cin >> n;
	long long int res = 0;
	res += (n / 11) * 2;
	if(n % 11 >= 7) res += 2;
	else if(n % 11 >= 1) res += 1;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
    char num[1001];
    while(1){
        int a=0;
        scanf("%s",num);
        if(num[0]=='0') break;
        for(int i=0;num[i]!='\0';i++){
            a+=num[i]-'0';
        }
        printf("%d\n",a);
    }
    
}


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

int main(){
    int k, n;
    cin >> k >> n;
    vector<int> a(n),b(n);
    rep(i,n)cin >> a[i];
    int maxi = -1;
    rep(i,n){
        if(i==n-1){
            b[i] = k - a[i] + a[0];
        }else{
            b[i] = a[i+1] - a[i];
        }
        if(maxi < b[i])maxi = b[i];
    }
    // sort(b.begin(),b.end(),greater<int>())
    cout << k - maxi << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using vi=vector<int>;
using pii=pair<int, int>;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

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

int dp[6010];

int N,T;
int a[3010], b[3010];

signed main()
{
	cin >> N >> T;
	vector<pii> menu;
	rep1(i, N) {
		cin >> a[i] >> b[i];
		menu.PB(pii(a[i], b[i]));
	}

	sort(all(menu));

	rep1(i, N) {
		for (int t = T - 1; t >= 0; --t) {
			chmax(dp[t + menu[i-1].fst], dp[t] + menu[i-1].scd);
		}
	}

	int mx = 0;
	for (int i = 6005; i >= 0; --i) {
		chmax(mx, dp[i]);
	}

	cout << mx << endl;
}


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

typedef long long ll;

int main(){
    int n;
    cin >> n;
    ll x = 1e18;
    ll ret = 1;
    bool zero = false;
    bool ng = false;
    while(n--){
        ll a;
        cin >> a;
        zero |= a==0;
        if(ng || x/ret < a){
            ng = true;
            continue;
        }
        ret *= a;
    }
    if(zero)        cout << 0 << endl;
    else if(ng)     cout << -1 << endl;
    else            cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3640
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 1000000000000000000
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    multimap<string,ll>m;
    ll q;cin>>q;
    while(q--){
        ll a;cin>>a;
        if(a==0){
            string key;cin>>key;
            ll x;cin>>x;
            m.insert(pair<string,int>(key,x));
            //cout<<m[key]<<endl;
        }
        else if(a==1){
            string key;cin>>key;
            auto it = m.lower_bound(key);
            for(;it!=m.end();it++){
                if(it->fi!=key)break;
                cout<<it->se<<endl;
            }
        }
        else if(a==2){
            string key;cin>>key;
            m.erase(key);
        }
        else{
            string l,r;cin>>l>>r;
            auto left=m.lower_bound(l);
            auto right=m.upper_bound(r);
            for(auto it=left;it!=right;it++){
                if(it->se)
                cout<<it->fi<<" "<<it->se<<endl;
            }
        }
    }
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------





































Measured memory_bytes: 24796
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N;
    cin >> N;
    cout << 800 * N - N / 15 * 200 << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n,k; cin >> n >> k;
  vector<ll> a(n), sa(n+1);
  REP(i,n) cin >> a[i];
  vector<ll> b;
  REP(i,n) {
    sa[i+1] = sa[i]+a[i];
  }
  REP(i,n) {
    for(int j = i+1; j <= n; ++j) {
      b.push_back(sa[j]-sa[i]);
    }
  }
  vector<ll> ans;
  for(ll i=60; i>=0; --i) {
    int cnt = 0;
    vector<ll> tmp;
    for(ll j=0; j<b.size(); ++j) {
      if (b[j]&(1LL<<i)) tmp.push_back(b[j]);
    }
    if (tmp.size()>=k) {
      ans.push_back(i);
      b = tmp;
    }
  }
  sort(ans.begin(),ans.end(),greater<>());
  //for(auto &&e: ans) cout << e << endl;
  ll X = 0;
  REP(i,ans.size()){
    X += pow(2,ans[i]);
  }
  cout << X << endl;
  return 0;
}


Measured memory_bytes: 6388
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)

int lcm(int x, int y){

    int r;

    while(( r = x % y ) != 0){
        x = y;
        y = r;
    }

    return y;
}

int main() {

    int n,x;
    int d[100000];

    scanf("%d %d", &n, &x);

    Rep(i,n){
        scanf("%d", d+i);
        d[i] = abs( d[i] - x);
    }

    int ans = d[0];
    Repe(i,n,1){
        ans = lcm(d[i], ans);
    }
    
    printf ("%d\n", ans);
    return 0;
}



Measured memory_bytes: 640
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	A = getlist()
	D = defaultdict(int)
	for i in range(N - 1):
		D[A[i]] += 1
	for i in range(N):
		print(D[i + 1])	
	


if __name__ == '__main__':
	main()

Measured memory_bytes: 114140
#include <stdio.h>
int main(){
  int k,n,num1,num2,num,s,number,big,a;

  scanf("%d %d",&k,&n);

  scanf("%d %d",&num1,&num2);

  s=num2-num1;

  num=num2;

  big=s;

  for(int i=2;i<n;i++){

    scanf("%d",&number);

    s=number-num;

    num=number;

    if(big<s){
      big=s;
    }
  }

  a=k+num1-num;

  if(big<a){
    big=a;
  }

  printf("%d",k-big);

  return 0;
}

Measured memory_bytes: 128
import math

a, b, x = list(map(int, input().split()))

s = x / a # 二次元上で見た水の面積
if s >= (a*b / 2): # パターン1
	h = (2 * (a*b - s)) / a
	result = math.degrees(math.atan2(h, a)) #得られたラジアンを度に変換

else: # パターン2
	w = 2*s / b
	result = math.degrees(math.atan2(b, w))

print(result)

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


int main(){
    int c[5],a,b=0;
    c[1]=0;
    c[2]=0;
    c[3]=0;
    c[4]=0;
    
    for (int i=1; i<=6; i++) {
        cin>>a;
        c[a]+=1;
        
    }
    for (int i=1; i<=4; i++) {
        if (c[i]==3) {
            cout<<"NO"<<endl;b++;
        }
    }
    if (b==0) {
        cout<<"YES"<<endl;b++;
    }
}


Measured memory_bytes: 256