akhauriyash/Code-Regression huggingface dataset:
using System;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int N = sc.NextInt();
        int[] D = sc.IntArray();
        long sum = 0;
        for (int i = 0; i < N - 1; i++)
        {
            for (int j = i + 1; j < N; j++)
            {
                sum += D[i] * D[j];
            }
        }
        Console.WriteLine(sum);
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);i++)
#define FORE(x,arr) for(auto &x:arr)
#define FOR(i,a,n) for(int i=a;i<(int)(n);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) begin(c),end(c)
const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0};
const int INF = 1e9;

int main(int argc, char const *argv[]) {
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(ALL(a));
    if(a[0]==5&&a[1]==5&&a[2]==7) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


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

#define lli long long int

int main()
{
  int n;
  scanf("%d", &n);
  lli sum = 0;
  for (int i = 1; i <= n; i++)
  {
    if (i % 3 == 0 || i % 5 == 0)
      continue;
    else
      sum += i;
  }
  printf("%lld\n", sum);
  return 0;
}

Measured memory_bytes: 3816
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long int ll;

ll henkan(int n){
	if( n < 4 ){ return n; }
	return henkan(n/4ll) * 10ll + n % 4ll;
}

int main(){
	int n;
	while( cin >> n ){
		if( n == -1 ) break;
		cout << henkan(n) << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

struct UnionFind {
  vector<int> par;
  vector<int> sizes;

  UnionFind(int N) : par(N), sizes(N, 1) {
    for (int i = 0; i < N; i++) par.at(i) = i;
  }

  int find(int x) {
    if (par.at(x) == x) return x;
    return par.at(x) = find(par.at(x));
  }

  void unite(int x, int y) {
    int rx = find(x);
    int ry = find(y);
    if (rx == ry) return;
    if (sizes.at(rx) < sizes.at(ry)) swap(rx, ry);
    par.at(ry) = rx;
    sizes.at(rx) += sizes.at(ry);
  }

  bool same(int x, int y) { return find(x) == find(y); }

  int size(int x) { return sizes.at(find(x)); }

  int num_of_connected_components() {
    int ret = 0;
    for (int i = 0; i < par.size(); i++) {
      if (find(i) == i) ret++;
    }
    return ret;
  }
};

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> ans(m);
  vector<ll> a(m), b(m);
  REP(i, m) {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
  }
  ans[m - 1] = n * (n - 1) / 2;
  UnionFind uf(n);
  IFOR(i, 1, m) {
    ans[i - 1] =
        ans[i] - (uf.same(a[i], b[i]) ? 0 : uf.size(a[i]) * uf.size(b[i]));
    uf.unite(a[i], b[i]);
  }

  REP(i, m) { cout << ans[i] << endl; }
}

Measured memory_bytes: 4480
#include<iostream>
#include<vector>
#include <unordered_map>  
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <sstream>
#include <cmath>
using namespace std;

int main() {
	float a, b;
	cin >> a >> b;
	cout << ceil((a + b) / 2) << endl;
	return 0;
}

Measured memory_bytes: 384
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array
import Data.Char

main = do
  x <- (read::String -> Int) <$> getLine
  print . head . filter (\n -> judge n 2) $ reverse [1..x]

judge::Int -> Int -> Bool
judge n m
  | n == 1 = True
  | m * m > n = False
  | otherwise = if isPower n m then True else judge n (m + 1)

isPower::Int -> Int -> Bool
isPower n m
  | n == 1 = True
  | otherwise = if n `mod` m /= 0 then False else isPower (n `div` m) m



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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  string S, T;
  cin >> S >> T;
  vector<int> vecS(30);
  vector<int> vecT(30);
  for(int i = 0; i < S.size(); i++){
    if(vecS[S[i]-'a'] == NULL){
      vecS[S[i]-'a'] = T[i]-'a';
    } else{
      if(vecS[S[i]-'a'] != T[i]-'a'){
        cout << "No" <<endl;
        return 0;
      }
    }
    if(vecT[T[i]-'a'] == NULL){
      vecT[T[i]-'a'] = S[i]-'a';
    } else{
      if(vecT[T[i]-'a'] != S[i]-'a'){
        cout << "No" <<endl;
        return 0;
      }
    }
  }
  cout << "Yes" <<endl;
  return 0;
}


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

int main(){
 int n, m;

while(true){
 int max=0;
 cin >> n >> m;
 if(n==0&&m==0) break;

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

 for(int h=0; h<n-1; h++){
  for(int i=h+1; i<n; i++){
   if(a[h]+a[i]<=m && a[h]+a[i]>=max){
    max = a[h]+a[i];
   }
  }
 }

 if(max==0){
  cout << "NONE" << endl;
 }else{
  cout << max << endl;
 }
}
 
 return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(v) for (auto itr = v.begin(), itr != v.end(); ++itr)
#define LB(v, x) lower_bound(v.begin(), v.end(), x) - v.begin()
#define UB(v, x) upper_bound(v.begin(), v.end(), x) - v.begin()
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while (true) {
        c -= b;
        if (c <= 0) {
            cout << "Yes\n";
            return 0;
        }
        a -= d;
        if (a <= 0) {
            cout << "No\n";
            return 0;
        }
    }

    return 0;
}


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

int main(){
    int n;
    cin >> n;
    bool flag = false;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        if(a[i] == 1) flag = true;
    }

    int ans = 0;
    if(!flag) ans = -1;
    else{
        int num = 1;
        for(int i = 0; i < n; i++){
            if(a[i] == num) num++;
            else ans++;
        }
    }

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

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int n, m, k;
  cin >> n >> m >> k;

  bool ok = false;
  for(int i = 0; i <= n; i++){
    for(int j = 0; j <= m; j++){
      if(i * m + j * n - 2 * i * j == k){
        ok = true;
        break;
      }
    }
  }

  if(ok){
    cout<< "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int
var t float64

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	k := intScanner()
	fmt.Println(50)
	ans := make([]int, 50)
	for i, _ := range ans {
		ans[i] = i + k/50
	}
	for i := 0; i < k%50; i++ {
		for j, _ := range ans {
			if i == j {
				ans[j] += 50
			} else {
				ans[j]--
			}
		}
	}
	fmt.Println(strings.Trim(fmt.Sprint(ans), "[]"))
}


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

int main(){
	int k;
	int a,b;
	cin >> k;

	cin >> a >> b;
	for(int i = a; i<=b; i++){
		if(i % k ==0){
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<queue>

using namespace std;

int main()
{
	
	while(1)
	{
		int sum = 0;
		int n;
		cin >> n;
		if(n == 0) break;
		
		queue<int> q;
		bool checked[4000];
		long long list[4000];
		for(int i = 0;i < 4000;i++)
		{
			checked[i] = false;
			list[i] = 0;
		}
		for(int i = 0;i < n;i++)
		{
			long long no, x, y;
			cin >> no >> x >> y;
			list[no - 1] += x * y;
			if(!checked[no - 1])
			{
				q.push(no);
				checked[no - 1] = true;
			}
		}
		
		while(!q.empty())
		{
			int no = q.front();
			q.pop();
			if(list[no - 1] >= 1000000)
			{
				cout << no << endl;
				sum++;
			}
		}
		if(sum == 0) cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 0
s = str(input())
_s = []
s.count('BC')
p = 0
for i in range(len(s)-1):
    if p == 1:
        p = 0
    elif s[i:i+2]=='BC':
        _s+=['D']
        p = 1
    else:
        _s+=[s[i]]

# print(_s)
len_s = len(_s)
cnt = 0
ans = 0
for i in range(1, len_s+1):
    # print(_s[-i])
    if _s[-i] == 'A':
        ans += cnt
    elif _s[-i] == 'D':
        cnt += 1
    elif _s[-i] in ('B','C'):
        cnt = 0

print(ans)


Measured memory_bytes: 58060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N;
    cin >> N;
    vector<int> h(N),w(N);
    rep(i,N){
        int x,y;
        cin >> x >> y;
        h[i]=x+y;
        w[i]=x-y;
    }
    sort(h.begin(),h.end());
    sort(w.begin(),w.end());
    ll ans = max(h[N-1]-h[0],w[N-1]-w[0]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4788
#include<iostream>
#include<vector>
using namespace std;
int main() {
    int n, m = 0;
    cin >> n;
    vector<long long int>l(n);
    for (int i = 0; i < n; i++)cin >> l[i];
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = j + 1; k < n; k++) {
                if (l[i] != l[j] && l[j] != l[k] && l[k] != l[i]) {
                    if (l[i] + l[j] > l[k] && l[j] + l[k] > l[i] && l[k] + l[i] > l[j])m++;
                }
            }
        }
    }
    cout << m << endl;
    return 0;
}

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

vector<int> to;
vector<bool> v(200000, false);

int main(){
  int N, M;
  cin >> N >> M;
  for(int i=0; i<M; i++){
    int a, b;
    cin >> a >> b;
    if(a==1) to.push_back(b-1);
    else if(b==N) v[a-1]=true;
  }
  for(int i=0; i<to.size(); i++){
    if(v[to[i]]){
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> piii;
#define rep(i, n) for(ll i = 0;i < n;i++)
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  int n;
  cin >> n;
  vector<int> a(n), b(n);
  rep(i, n) cin >> a[i] >> b[i];

  vector<pii> tmp(n);
  rep(i, n) {
    tmp[i] = pii(a[i]+b[i], i);
  }
  sort(tmp.rbegin(), tmp.rend());

  ll taka = 0, ao = 0;
  rep(i, n) {
    cerr << tmp[i].first << " " << tmp[i].second << endl;
    if (i%2 == 0) {
      taka += a[tmp[i].second];
    } else {
      ao += b[tmp[i].second];
    }
  }
  cout << taka - ao << endl;
}


Measured memory_bytes: 1792
# coding=utf-8


def solve_under_stair(high: float) -> int:
    one_under = int((high + 5) // 5)
    return one_under + 1


def solve_need_time(velocity: float) -> float:
    return velocity / 9.8


def solve_need_height(fall_time: float) -> float:
    return 4.9 * fall_time * fall_time


if __name__ == '__main__':
    while True:
        try:
            v = float(input())
        except EOFError:
            break
        time = solve_need_time(v)
        minimum_height = solve_need_height(time)
        floor_number = solve_under_stair(minimum_height)
        print(floor_number)

Measured memory_bytes: 5588
using System;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] In = Console.ReadLine().Split(' ');
            long w = int.Parse(In[0]);
            long h = int.Parse(In[1]);
            long x = int.Parse(In[2]);
            long y = int.Parse(In[3]);
            int v = (2*x==w && 2*y==h) ? 1 : 0;
            Console.WriteLine((double)w * h / 2 + " " + v);
        }
    }
}


Measured memory_bytes: 27464
N = int(input())
A = list(map(lambda x:int(x), input().split(' ')))
# サーチ用変数定義
C = 1
H = 0
# サーチ処理
for i in A:
  if  i==C:
    H += 1
    C += 1
# hitした数を総和から消す
print( N-H if H > 0 else -1)

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

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a,a+3);
	ll x=a[2]-a[0];
	ll y=a[2]-a[1];
	ll ans=x/2 + y/2;
	ll p=x%2;
	ll q=y%2;
	if(p+q==2) ans++;
	else if(p+q==0) ans;
	else ans+=2;
	cout << ans;
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * overflow (ll vs int?)
 * * array bounds
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


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

namespace ABC175C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            long X = long.Parse(input[0]);
            long K = long.Parse(input[1]);
            long D = long.Parse(input[2]);
            if (X < 0)
            {
                X *= -1;
            }
            if (X == 0)
            {
                if (K % 2 == 0)
                {
                    Console.WriteLine(0);
                }
                else
                {
                    Console.WriteLine(D);
                }
            }
            else
            {
                if (D <= X / K)
                {
                    Console.WriteLine(X - D * K);
                }
                else
                {
                    long amari = X % D;
                    long count = ((X - amari) / D) + 1;
                    long temp = X - (D * count);
                    if ((K - count) % 2 == 0)
                    {
                        Console.WriteLine(temp * (-1));
                    }
                    else
                    {
                        Console.WriteLine(temp + D);
                    }
                }
            }
        }
    }
}


Measured memory_bytes: 27548
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  int N;
  cin >> N;

  bool is_ok = false;
  rep(i, N) {
    if (N - 4*i < 0) break;
    if ( (N - 4*i)%7 == 0) {
      is_ok = true;
      break;
    }
  }
  if (is_ok == true) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}


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

using namespace std;

string s;
unordered_map <string,long long> m;
unordered_map <string,long long>::iterator it;
int N;
long long sum;

int main() {
    cin.tie(0),ios_base::sync_with_stdio(0);
    cin >> N;
    for(; N; --N) {
        cin >> s;
        sort(s.begin(),s.end());
        m[s]++;
    }
    for(it = m.begin(); it != m.end(); ++it)
        sum += (it -> second) * (it -> second - 1) / 2;
    cout << sum;
    return 0;
}


Measured memory_bytes: 10660
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  if((s.at(2)==s.at(3))&&(s.at(4)==s.at(5))){
      cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

char x[1001], y[1001];

void LCS(char x[], char y[]){
  int i,j;
  int c[1001][1001];  
  int m = strlen(x+1), n = strlen(y+1);

  for(i = 1; i <= m; i++){
    c[i][0] = 0;
  }

  for(j = 0; j <= n; j++){
    c[0][j] = 0;
  }

  for(i = 1; i <= m; i++){
    for(j =1; j <= n; j++){
      if(x[i] == y[j]){
	c[i][j] = c[i-1][j-1] + 1;
      }else if(c[i-1][j] >= c[i][j-1]){
	c[i][j] = c[i-1][j];
      }else{
	c[i][j] = c[i][j-1];
      }
    }
  }

  printf("%d\n",c[i-1][j-1]);
}

int main(){
  int i,len;

  scanf("%d",&len);
  for(i = 0; i < len; i++){
    scanf("%s",x+1);
    scanf("%s",y+1);
    LCS(x,y);
  }

  return 0;
}

Measured memory_bytes: 4520
#include <iostream>
#include<string>
using namespace std;
#define endl "\n"
#define MOD 1000000007
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LLI long long int
#define LI long int 
#define pb push_back
#define pob pop_back()
#define sp " "
#define ff first
#define ss second
//               When something is important enough, you do it even if the odds are not in your favor.

int main(){   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    // code goes here
    int t=1;//cin>>t;
    while(t--){
      string s,t;cin>>s>>t;
      LI i;
      if(t.length()-s.length()!=1) {cout<<"No";return 0;}
      fo(i,0,s.length()){
        if(s[i]!=t[i]) {cout<<"No";return 0;}
      }
      cout<<"Yes";
    }
    return 0;
}

Measured memory_bytes: 3036
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--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 gcd(int a,int b){
	return a%b?gcd(b,a%b):b;
}

signed main() {
  INIT;
	VAR(int,n);
	VEC(int,a,n);
	int ans = a.back();
	REP(i,n){
		ans = min(ans, gcd(ans,a[i]));
	}
	OUT(ans)BR;
  
  return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	static BufferedReader reader;
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		reader = new BufferedReader(new InputStreamReader(System.in));
		String[] s = readLine().split(" ");
		int N = Integer.parseInt(s[0]);
		int M = Integer.parseInt(s[1]);
		boolean[] dislike = new boolean[M];
		for(int i=0;i<N;i++){
			String[] st = readLine().split(" ");
			boolean[] l_tmp = new boolean[M];
			int ki = Integer.parseInt(st[0]);
			for(int j=0;j<ki;j++){
				l_tmp[Integer.parseInt(st[j+1])-1] = true;
			}
			for(int j=0;j<M;j++){
				if(!l_tmp[j]){dislike[j]=true;}
			}
			
		}
		int cnt = 0;
		for(int i=0;i<M;i++){
			if(!dislike[i]){
				cnt++;
			}
		}
		System.out.println(cnt);
		return;
	}

	private static String readLine(){
		try{
			return reader.readLine();
		}catch(Exception e){
			return e.getMessage();
		}
	}
}

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

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	
	ll a, b;
	cin >> a >> b;
	ll g = __gcd(a, b);
	int cnt = 0;
	for(ll i = 2; i*i <= g; ++i) {
		if(g%i == 0) {
			++cnt;
			g/=i;
			while(g%i == 0) g/=i;
		}
		if(g == 1) break;
	}
	if(g != 1) ++cnt;
	cout << cnt+1;
	return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define sep                         ' '
#define endl                        '\n'
#define SZ(x)                       ll(x.size())

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 1e6 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll n , m;

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

    cin >> n >> m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;

    return 0;
}
/*

*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll max(ll a,ll b){return a<b ? b:a;}
int main(void){
    ll n, a, b; cin>>n>>a>>b;
    ll ma = b*(n-1)+a;
    ll mi = b+a*(n-1);
    cout<<max(0,ma-mi+1)<<endl;
}


Measured memory_bytes: 256
H,W = gets.split.map(&:to_i)

hash = Hash.new(0)
H.times{gets.chomp.chars{|c| hash[c]+=1}}
ar = hash.map{|k,v| v}

need4 = (H/2)*(W/2)       #かけ4する前
need2 = (H%2)*(W/2)+(W%2)*(H/2)  #かけ2する前
#のこるのはセーフなので1はいいや

while need4!=0 || need2!=0 do
  maxidx = ar.index(ar.max)
  if need4 > 0 then
    if  ar[maxidx] >= 4 then
      ar[maxidx] -= 4
      need4 -=1
    else
      puts "No"
      exit
    end
  elsif need2 > 0 then
     if  ar[maxidx] >= 2 then
      ar[maxidx] -= 2
      need2 -=1
    else
      puts "No"
      exit
    end
  end
end

puts "Yes"

Measured memory_bytes: 1916
#include<iostream>

using namespace std;

int main() {
	int N;
	cin >> N;
	for (int p = 0; p <= 50000; p++) {
		int val = (double)p * 1.08;
		if (val == N) {
			cout << p << endl;
			return 0;
		}
	}
	cout << ":(" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    int N, P;
    string S;
    cin >> N >> P >> S;

    ll ans = 0;
    if (P != 2 && P != 5) {
        vector<int> modcnt(P);
        modcnt[0] = 1;
        int num = 0, pow = 1;
        for (int i = N - 1; i >= 0; --i) {
            (num += (S[i] - '0') * pow % P) %= P;
            modcnt[num]++;
            ans += modcnt[num] - 1;
            (pow *= 10) %= P;
        }
    } else {
        for (int i = N - 1; i >= 0; --i) {
            int num = S[i] - '0';
            if (num % P == 0)
                ans += i + 1;
        }
    }

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


Measured memory_bytes: 720
#include<cstdio>
#include<cmath>

int main(){
    double r;
    scanf("%lf",&r);

    double area = M_PI * r * r;
    double circumference = 2.0 * M_PI * r;

    printf("%.5f %.5f\n",area,circumference);
    return 0;
} 


Measured memory_bytes: 2708
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <array>
#include <cmath>
#include <iomanip>

using namespace std;
int main(void)

{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	for (int i = 1; i < 10; i++)
	{
		if (N % i == 0 && N / i < 10)
		{
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}


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

int main() {
  ll n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  bool ans = false;
  for(int k=0;k<n;k++) {
    ll lb = a + c * k - d * (n- 1 - k);
    ll ub = a + d * k - c * (n - 1 - k);
    //cout << lb << " "<< ub << endl;

    if(lb <= b && b <= ub) {
      ans = true;
      break;
    }
  }
  if(ans)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

}


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

int main()
{
   int n;
   cin >> n;
   string s;
   cin >> s;
   int l = 1;
   rep(i,n-1)
   {
      if(s[i]!=s[i+1])l++;
   }
   cout<<l<<endl;
   return 0;
}

Measured memory_bytes: 512
n=int(input())
a=[0,0,0,0,0]
for i in range(n):
  s=input()
  if s[0]=='M':
    a[0]+=1
  elif s[0]=='A':
    a[1]+=1
  elif s[0]=='R':
    a[2]+=1
  elif s[0]=='C':
    a[3]+=1
  elif s[0]=='H':
    a[4]+=1
ans=0
for i in range(0,3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      ans+=a[i]*a[j]*a[k]
print(ans)

Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author kessido
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int k = in.NextInt();
            long cur = 1;
            while (k-- != 0) {
                out.println(cur);
                cur = getNext(cur + 1);
            }
        }

        private long getNext(long l) {
            double curVal = getVal(l);
            long best = l;
            for (int i = 0; MathExtentions.power(10, i) - 1 < l; i++) {
                long new_l = l / MathExtentions.power(10, i);
                new_l *= MathExtentions.power(10, i);
                new_l += MathExtentions.power(10, i) - 1;
                double new_v = getVal(new_l);
                if (new_v < curVal) {
                    curVal = new_v;
                    best = new_l;
                }
            }
            return best;
        }

        private double getVal(long o) {
            return ((double) o) / IntegerExtention.sumDigits(o);
        }

    }

    static class MathExtentions {
        public static long power(final long x, final long y) {
            if (y == 0)
                return 1;

            long p = power(x, y / 2);
            p = (p * p);

            if (y % 2 == 0)
                return p;
            else
                return (x * p);
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine(), " \t\n\r\f,");
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }

    static class IntegerExtention {
        public static int sumDigits(long i) {
            if (i == 0) return 0;
            int res = 0;
            do {
                long i1 = i / 10;
                res += i - i1 * 10;
                i = i1;
            } while (i != 0);
            return res;
        }

    }
}



Measured memory_bytes: 20692
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main(){
    int m1, d1, m2, d2;
    cin >> m1 >> d1 >> m2 >> d2;
    if(m1 != m2)cout << 1;
    else cout << 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
priority_queue<int> p[100005];
int a[100005];
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++) p[i].push(0);
	for(int i=1;i<=n;i++) cin>>a[i];
	while(m--){
		int t1,t2;
		cin>>t1>>t2;
		p[t1].push(a[t2]);
		p[t2].push(a[t1]);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(p[i].top()<a[i]) ans++;
	}
	cout<<ans<<endl;
	
	return  0;
}

Measured memory_bytes: 10884
#include <iostream>
#include <queue>
#include <algorithm>

int main(void) {
    std::priority_queue<int> heights;
 
    for (int h, i = 0; i < 10; ++i) {
        std::cin >> h;
        heights.push(h);
    }
 
    for (int i = 0; i < 3; ++i) {
        std::cout << heights.top() << std::endl;
        heights.pop();
    }

    return 0;
}

Measured memory_bytes: 1216
#include <iostream>
using namespace std;
int A[2000005],B[2000005];

void CountingSort(int *A,int *B,int k,int n){
  int i,j,C[10005];

  for (i=0;i<=k;i++)
    C[i]=0;

  for (j=1;j<=n;j++)
    C[A[j]]++;

  for (i=1;i<=k;i++)
    C[i] += C[i-1];

  for (j=n;j>=1;j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

}

int main(){
  int n,k=-1;

  cin >> n;
  for (int i=1;i<=n;i++){
    cin >> A[i];
    if (k<A[i]) k = A[i];
  }

  CountingSort(A,B,k,n);

  for (int i=1;i<=n;i++){
    cout << B[i];
    if (i<n) cout << " ";
    else cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 18744
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
string s[1010];
int b1[4] = { 0,0,1,-1 };
int b2[4] = { 1,-1,0,0 };
bool b[1010][1010] = { false };
int main() {
	int h, w;
	cin >> h >> w;
	int ch, cw, dh, dw;
	cin >> ch >> cw >> dh >> dw;
	ch--; cw--; dh--; dw--;
	b[ch][cw] = true;
	for (int i = 0; i < h; i++) {
		cin >> s[i];
	}
	queue<tuple<int,int,int>> que, que1;
	que.push(make_tuple(ch, cw, 0));
	while (!que.empty() || !que1.empty()) {
		if (!que.empty()) {
			tuple<int, int, int> now = que.front();
			int x = get<0>(now);
			int y = get<1>(now);
			int z = get<2>(now);
			que1.push(make_tuple(x, y, z));
			if (x == dh && y == dw) {
				cout << z << endl;
				return 0;
			}
			for (int i = 0; i < 4; i++) {
				if (x + b1[i] < 0 || x + b1[i] >= h || y + b2[i] < 0 || y + b2[i] >= w) {
					continue;
				}
				if (s[x + b1[i]][y + b2[i]] == '.') {
					if (!b[x + b1[i]][y + b2[i]]) {
						b[x + b1[i]][y + b2[i]] = true;
						que.push(make_tuple(x + b1[i], y + b2[i], z));
					}
				}
			}
			que.pop();
		}
		else {
			while (!que1.empty()) {
				tuple<int, int, int> now = que1.front();
				int x = get<0>(now);
				int y = get<1>(now);
				int z = get<2>(now);
				for (int i = -2; i <= 2; i++) {
					for (int j = -2; j <= 2; j++) {
						if (x + i < 0 || x + i >= h || y + j < 0 || y + j >= w) {
							continue;
						}
						if (s[x + i][y + j] == '.') {
							if (!b[x + i][y + j]) {
								b[x + i][y + j] = true;
								que.push(make_tuple(x + i, y + j, z + 1));
							}
						}
					}
				}
				que1.pop();
			}
		}
	}
	cout << "-1" << endl;
	return 0;
}


Measured memory_bytes: 6612
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int GCD(long long int a, long long int b){
	long long int dummy1, dummy2, dummy;
	dummy1 = max(a, b);
	dummy2 = min(a, b);
	while(true){
		dummy = dummy1 % dummy2;
		dummy1 = dummy2;
		dummy2 = dummy;
		if(dummy == 0){
			break;
		}
	}
	return dummy1;
}

int main(){
	
	long long int X, Y;
	cin >> X >> Y;
	
	if(GCD(X, Y) == Y){
		cout << -1 << endl;
	}else{
		cout << X << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define F first
#define S second
constexpr auto INF = 1000000000;
constexpr auto LLINF = 9223372036854775807;
constexpr auto mod = 1000000007;
int main() {

	string s, t;
	cin >> s >> t;
	if (s.length() < t.length()) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	set<string> ans;
	FOR(i, s.length() - t.length() + 1) {
		bool ok = 1;
		FOR(j, t.length()) {
			if (s[i + j] != t[j] && s[i + j] != '?')ok = 0;
		}
		if (ok) {
			string a = s;
			FOR(j, t.length())a[i + j] = t[j];
			FOR(j, a.length())if (a[j] == '?')a[j] = 'a';
			ans.insert(a);
		}
	}
	if(ans.empty())cout << "UNRESTORABLE" << endl;
	else cout << *ans.begin() << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;

using namespace std;

int main()
{
  ll N, M, X, Y;

  cin >> N >> M >> X >> Y;
  vector<ll> xs(N);
  vector<ll> ys(M);

  auto cond = true;
  for (auto i = 0; i < N; i++) cin >> xs[i];
  for (auto i = 0; i < M; i++) cin >> ys[i];

  sort(xs.begin(), xs.end());
  sort(ys.begin(), ys.end());
  if (!(xs.back() < ys.front())) cond = false;
  if (!(X < ys.front())) cond =false;
  if (!(xs.back() < Y)) cond =false;

  auto res = cond ? "No War" : "War";

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  int N, M;
  cin >> N >> M;
  int A[M], B[M];
  vector<int> count(N, 0);

  for (int i = 0; i < M; i++)
  {
    cin >> A[i] >> B[i];
  }
  for (int i = 0; i < M; i++)
  {
    for (int j = 0; j < N; j++)
    {
      if (A[i] == j + 1 || B[i] == j + 1)
      {
        count[j]++;
      }
    }
  }
  for (int j = 0; j < N; j++)
  {
    cout << count[j] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;
int p[100000],a[100000],b[100000],c[100000],tetu[100001];
int main(void)
{
	int i,j,n,m;
	long long int sum[100001],kip,ic,kin;
	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++) scanf("%d",&p[i]);
	for(i=1;i<n;i++) scanf("%d %d %d",&a[i],&b[i],&c[i]);
	for(i=0;i<m;i++) tetu[i]=0;
	for(i=0;i<m-1;i++) {
		if(p[i]>p[i+1]) {
			tetu[p[i+1]]++;
			tetu[p[i]]--;
		}
		else {
			tetu[p[i]]++;
			tetu[p[i+1]]--;
		}
	}
	for(i=0;i<n;i++) sum[i]=0;
	for(i=1;i<n;i++) sum[i]+=sum[i-1]+tetu[i];
    kin=0;
	for(i=1;i<n;i++) {
		kip=(long long)a[i]*sum[i];
		ic=(long long)c[i]+(long long)b[i]*sum[i];
		if(kip>ic) kin+=ic;
		else kin+=kip;
	}
	printf("%lld\n",kin);
	return 0;
}

Measured memory_bytes: 3760
# -*- coding: utf-8 -*-


def main():
    n = int(input())

    points = [tuple(map(int, input().split())) for i in range(n)]

    pre_t, pre_x, pre_y = 0, 0, 0
    flg = True
    for t, x, y in points:
        time = t - pre_t
        ido_kyori = abs(x - pre_x) + abs(y - pre_y)

        if ido_kyori > time or time % 2 != ido_kyori % 2:
            flg = False
            break

        pre_t, pre_x, pre_y = t, x, y

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


if __name__ == '__main__':
    main()


Measured memory_bytes: 17312
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	string s;
	cin >> s;
	int cnt = 0;
	rep(i, 4) {
		if (s[i] == '2') cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <fstream>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
#include <cassert>
#pragma warning (disable: 4996)
using namespace std;

using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

struct UnionFind {
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    if (n < 0)return 0;
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

ll merge_cnt(vector<ll>& a) {
    int n = a.size();
    if (n <= 1) { return 0; }

    ll cnt = 0;
    vector<ll> b(a.begin(), a.begin() + n / 2);
    vector<ll> c(a.begin() + n / 2, a.end());

    cnt += merge_cnt(b);
    cnt += merge_cnt(c);

    int ai = 0, bi = 0, ci = 0;
    while (ai < n) {
        if (bi < b.size() && (ci == c.size() || b[bi] <= c[ci])) {
            a[ai++] = b[bi++];
        }
        else {
            cnt += n / 2 - bi;
            a[ai++] = c[ci++];
        }
    }
    return cnt;
}

int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    vector<ll> bik(5000);
    bik[0] = 1;
    for (ll i = 1; i < 5000; i++) {
        bik[i] = bik[i - 1] * i%1000000007;
    }
    for (ll i = 1; i <= n; i++) {
        ll k = n - i * 3;
        if (k < 0)break;
        ans += bik[k + i - 1] * modinv(bik[i - 1], 1000000007) % 1000000007 * modinv(bik[k], 1000000007) % 1000000007;
    }
    cout << ans % 1000000007 << endl;
}

Measured memory_bytes: 3668
#include <stdio.h>

void gc(int* x){
    *x = 0;
    for(;;){
        int c=getchar();
        if('0'<= c && c <='9'){
            *x = *x*10 + c-'0';
        }else{
            break;
        }
    }
}

int main(void){
    using namespace std;
    constexpr int KMAX = 1000;
    static int s[KMAX+1][2*KMAX+1];
    char c;
    int n, k, x, y;
    /*
       cin.sync_with_stdio(false);
       cout.sync_with_stdio(false);
       cin.tie(nullptr);
       cout.tie(nullptr);
       cin >> n >> k;
       */
    scanf("%d %d\n", &n, &k);
    for(int i=0; i<n; i++){
        //cin >> x >> y >> c;
        gc(&x);
        gc(&y);
        c=getchar();
        getchar();
        //scanf("%d %d %c", &x, &y, &c);
        y %= 2*k;
        if(c=='W'){
            if(y>=k){
                y-=k;
            }else{
                x+=k;
            }
        }else{
            if(y>=k){
                y-=k;
                x+=k;
            }
        }
        x %= 2*k;
        s[y+1][x+1]++;
    }
    for(int y=0; y<k; y++){
        for(int x=0; x<2*k; x++){
            s[y+1][x+1] += s[y][x+1] + s[y+1][x] - s[y][x];
        }
    }
    int max = 0;
    int v = s[0][0] - s[0][2*k];
    for(int y=0; y<k; y++){
        int u = v - s[y][0] + s[y][2*k];
        for(int x=0; x<k; x++){
            int t = u - s[0][x] - s[k][x] + s[0][x+k] + s[k][x+k] + 2*s[y][x] - 2*s[y][x+k];
            t = t<n/2 ? n-t : t;
            max = t>max ? t : max;
        }
    }
    //cout << max;
    printf("%d", max);
    return 0;
}


Measured memory_bytes: 7936
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
int H,W,N;
int cntX[505][505],cntY[505][505];
int sx,sy,gx,gy;
vector<pair<pair<int,int>,int> >G[505][505];
long dp[505][505];
main()
{
	cin>>W>>H>>N;
	cin>>sy>>sx>>gy>>gx;
	for(int tm=0;tm<N;tm++)
	{
		int x,y;cin>>y>>x;
		int t;string s;cin>>t>>s;
		for(;t--;)
		{
			for(int i=0;i<s.size();i++)
			{
				if(s[i]=='L')
				{
					if(y>0)
					{
						cntY[x][y]++;
						y--;
					}
				}
				else if(s[i]=='R')
				{
					if(y+1<W)
					{
						y++;
						cntY[x][y]++;
					}
				}
				else if(s[i]=='U')
				{
					if(x>0)
					{
						cntX[x][y]++;
						x--;
					}
				}
				else
				{
					if(x+1<H)
					{
						x++;
						cntX[x][y]++;
					}
				}
			}
		}
	}
	for(int i=0;i<=H;i++)for(int j=0;j<W;j++)
	{
		G[i][j].push_back(make_pair(make_pair(i,j+1),cntX[i][j]));
		G[i][j+1].push_back(make_pair(make_pair(i,j),cntX[i][j]));
	}
	for(int i=0;i<H;i++)for(int j=0;j<=W;j++)
	{
		G[i][j].push_back(make_pair(make_pair(i+1,j),cntY[i][j]));
		G[i+1][j].push_back(make_pair(make_pair(i,j),cntY[i][j]));
	}
	for(int i=0;i<=H;i++)for(int j=0;j<=W;j++)dp[i][j]=1e18;
	priority_queue<pair<long,pair<int,int> > >P;
	P.push(make_pair(0,make_pair(sx,sy)));
	dp[sx][sy]=0;
	while(!P.empty())
	{
		long c=-P.top().first;
		int x=P.top().second.first,y=P.top().second.second;
		P.pop();
		if(dp[x][y]<c)continue;
		for(pair<pair<int,int>,int>e:G[x][y])
		{
			long nxt=c+e.second;
			int tx=e.first.first,ty=e.first.second;
			if(dp[tx][ty]>nxt)
			{
				dp[tx][ty]=nxt;
				P.push(make_pair(-nxt,make_pair(tx,ty)));
			}
		}
	}
	cout<<dp[gx][gy]<<endl;
}



Measured memory_bytes: 32692