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

// 0-indexed
template <class T>
struct SegmentTree {
  // a,b,c: T, e:T(unit)
  // abc = (ab)c = a(bc)
  // ae = ea = a
  typedef function<T(T, T)> F;
  int n;
  F f;
  T unit;
  vector<T> dat;
  SegmentTree(){};
  SegmentTree(int newn, F f, T t) : f(f), unit(t) {
    init(newn);
  }
  SegmentTree(const vector<T> &v, F f, T t)
      : f(f), unit(t) {
    int _n = v.size();
    init(v.size());
    for(int i = 0; i < _n; ++i) dat[n + i] = v[i];
    for(int i = n - 1; i; --i)
      dat[i] = f(dat[i << 1], dat[(i << 1) | 1]);
  }
  void init(int newn) {
    n = 1;
    while(n < newn) n <<= 1;
    dat.assign(n << 1, unit);
  }

  // "go up" process
  void update(int k, T newdata) {
    dat[k += n] = newdata;
    while(k >>= 1) {
      dat[k] = f(dat[(k << 1) | 0], dat[(k << 1) | 1]);
    }
  }
  // [a,b)
  T query(int a, int b) {
    T vl = unit, vr = unit;
    for(int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
      if(l & 1) vl = f(vl, dat[l++]);
      if(r & 1) vr = f(dat[--r], vr);
    }
    return f(vl, vr);
  }
};

long long n, k, c;
vector<long long> pre, limit;
string s;
SegmentTree<long long> suf;

void solve();

int main() {
  cin >> n >> k >> c >> s;
  solve();
  return 0;
}

void solve() {
  pre.assign(n, 0);
  limit.assign(n, 0);
  auto f = [](long long l, long long r) {
    return max(l, r);
  };
  suf = SegmentTree<long long>(n + c + 3, f, 0);
  for(int i = 0, cnt = 0, lim = -1; i < n; ++i) {
    if(lim < i) {
      if(s[i] == 'o') {
        lim = i + c;
        ++cnt;
      }
    }
    limit[i] = lim;
    pre[i] = cnt;
  }
  for(int i = n - 1; i >= 0; --i) {
    long long p = suf.query(i + 1, i + 2);
    suf.update(i, p);
    if(s[i] == 'o') {
      long long now = suf.query(i + c + 1, n + c + 3);
      if(++now > p) suf.update(i, now);
    }
  }

  for(int i = 0; i < n; ++i) {
    long long now = 0, lim = 0;
    if(i > 0) lim = limit[i - 1];
    if(i > 0) now += pre[i - 1];
    if(lim < n)
      now +=
          suf.query(max(lim + 1, (long long)i + 1), n + 1);
    if(now < k) cout << i + 1 << endl;
  }
}

Measured memory_bytes: 9092
//2011
#include<iostream>
using namespace std;
int main(void){
	int i,j,n;
	cin>>n;
	int a,b,c,d,e,team[101]={0};
	e=n*(n-1)/2;
	for(i=1;i<=e;i++){
		cin>>a>>b>>c>>d;
		if(c>d){
			team[a]+=3;
		}
		else if(c<d){
			team[b]+=3;
		}
		else{
			team[a]++;
			team[b]++;
		}
	}
	int cnt=1;
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			if(team[i]<team[j]){
				cnt++;
			}
		}
		cout<<cnt<<endl;
		cnt=1;
	}
	
	return 0;
}


Measured memory_bytes: 3100
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
    static void Main(string[] args)
    {
		string[] input = Console.ReadLine().Split(' ');
		int X = int.Parse(input[0]);
		int A = int.Parse(input[1]);

		if (X < A)
		{
			Console.WriteLine("0");
		}
		else { Console.WriteLine("10"); }

	}
}


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

const int inf=1<<29;

int N;
int d1[100001];
int dn[100001];
vector<int>v[100001];

void bfs_d1(){
	d1[1]=0;
	queue<int>q;
	q.push(1);
	while(!q.empty()){
		int x=q.front();
		q.pop();
		for(int i=0;i<v[x].size();i++){
			if(d1[v[x][i]]==inf){
				d1[v[x][i]]=d1[x]+1;
				q.push(v[x][i]);
			}
		}
	}
}

void bfs_dn(){
	dn[N]=0;
	queue<int>q;
	q.push(N);
	while(!q.empty()){
		int x=q.front();
		q.pop();
		for(int i=0;i<v[x].size();i++){
			if(dn[v[x][i]]==inf){
				dn[v[x][i]]=dn[x]+1;
				q.push(v[x][i]);
			}
		}
	}
}

int main(){
	cin>>N;
	for(int i=0;i<N-1;i++){
		int a,b;
		cin>>a>>b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	for(int i=1;i<=N;i++){
		d1[i]=dn[i]=inf;
	}
	bfs_d1();
	bfs_dn();
	int fennec=0,snuke=0;
	for(int i=1;i<=N;i++){
		if(d1[i]<=dn[i]){
			fennec++;
		}else{
			snuke++;
		}
	}
	if(fennec>snuke){
		cout<<"Fennec"<<endl;
	}else{
		cout<<"Snuke"<<endl;
	}
	return 0;
}

Measured memory_bytes: 6656
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
const long long mod = 1000000007;
const long long inf = 11451419198109130;
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<int, PP> PPP;
struct edge { int to; int to2; int cost; };

signed main() {
	int a[5];
	rep(i, 5)cin >> a[i];
	int sum = 0;
	rep(i, 5) {
		sum += (a[i] + 9) / 10 * 10;
	}
	int ans = 0;
	rep(i, 5) {
		ans = max(ans, (10 - a[i] % 10) % 10);
	}
	cout << sum - ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
long long f[100];
int main()
{
	f[0]=2;
	int n;
	cin>>n;
	for(int i=0;i<=n;i++)
		f[i]=f[i-1]*2+2;
	cout<<f[n]<<endl;
	return 0;
}

Measured memory_bytes: 384
# include <iostream>
# include <stdio.h>
# include <cmath>
# include <iomanip>
# include <cstring>
# include <string>
# include <cctype>
# include <algorithm> //transformの関数はaslgorithmライブラリに入っているみたい。
using namespace std;
class dice{
public:
  int label[6];
  void roll(char);
  bool is_samedice(int[]);
};
void dice::roll(char direction){
  int temp;
  if(direction == 'E'){
    temp = label[2];
    label[2] = label[0];
    label[0] = label[3];
    label[3] = label[5];
    label[5] = temp;
  }else if(direction == 'N'){
    temp = label[4];
    label[4] = label[0];
    label[0] = label[1];
    label[1] = label[5];
    label[5] = temp;
  }else if(direction == 'S'){
    temp = label[1];
    label[1] = label[0];
    label[0] = label[4];
    label[4] = label[5];
    label[5] = temp;
  }else if(direction == 'W'){
    temp = label[3];
    label[3] = label[0];
    label[0] = label[2];
    label[2] = label[5];
    label[5] = temp;
  }else if(direction == 'R'){
    // 右回転
    temp = label[2];
    label[2] = label[1];
    label[1] = label[3];
    label[3] = label[4];
    label[4] = temp;
  }
}
bool dice::is_samedice(int other_label[]){
    bool flag;
    flag = true;
    for(int i =0;i<6;i++){
      if(label[i] != other_label[i]){
        flag = false;
      }
    }
    return flag;
}
int main(){
  dice d1,d2;
  int q,num1,num2;
  int count =0;
  bool flag = false;
  for(int i = 0;i<6;i++){
    cin >> d1.label[i];
  }
  for(int i = 0;i<6;i++){
    cin >> d2.label[i];
  }
  for(int i = 0;i<6;i++){
      // 上面を合わせる
            switch (i) {
              case 1:
              d1.roll('N');
              break;
              case 2:
              d1.roll('W');
              break;
              case 3:
              d1.roll('N');
              d1.roll('N');
              break;
              case 4:
              d1.roll('W');
              break;
              case 5:
              d1.roll('S');
              break;
          }
          for(int j = 0;j<4;j++){
            flag = d1.is_samedice(d2.label);
            if(flag){
              cout << "Yes" << endl;
              return 0;
            }
            d1.roll('R');
        }
      }
  cout << "No" << endl;
  return 0;
}



Measured memory_bytes: 3096
from collections import deque
H, W = map(int,input().split())
s = [input() for _ in range(H)] #'_'は、その変数は使っていないという表現(習慣)

def func(h,w): #黒のみ
    move = [(0,-1), (-1,0),(0,1), (1,0)]
    w_cnt = 0
    b_cnt = 0
    que = deque()
    que.append((h,w))
    while len(que) > 0:
        xh, xw = que.popleft()
        if visited[xh][xw] == 0:
            visited[xh][xw] = 1
            if s[xh][xw] == "#":
                b_cnt += 1
            else:
                w_cnt += 1
        else:
            continue
        for mh, mw in move:
            if 0 <= xh + mh < H and 0 <= xw + mw <W:
                if s[xh][xw] != s[xh+mh][xw+mw] and visited[xh+mh][xw+mw] == 0:
                    que.append((xh+mh,xw+mw))
    return b_cnt, w_cnt

cnt = 0
visited = [[0 for _ in range(W)] for _ in range(H)]

for i in range(H):
    for j in range(W):
        if s[i][j] == "#" and visited[i][j] == 0:
            b_cnt, w_cnt = func(i,j)
            cnt += b_cnt * w_cnt

print(cnt)

Measured memory_bytes: 4852
while 1:
	n,m = map(int,raw_input().split())
	if n == 0: break
	taro = sorted([int(raw_input()) for i in range(n)])
	hana = [int(raw_input()) for i in range(m)]
	d = sum(hana) - sum(taro)
	t,h = 101,101
	for i in taro:
		if d/2.0 + i in hana:
			t,h = i,d/2 + i
			break
	print "%d %d"%(t,h) if t < 101 else -1

Measured memory_bytes: 4240
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[5];
  int b[5];
  for(int i=0;i<5;i++){
    cin>>a[i];
    b[i]=ceil((double)a[i]/10)*10;
  }
  int ans=0;
  for(int i=0;i<5;i++)ans+=b[i];
  int s=10;
  for(int i=0;i<5;i++){
    if(a[i]%10!=0)s=min(s,a[i]%10);
  }
  cout<<ans-10+s<<endl;
}
  



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

int main()
{
  int theta1, theta2;
  double mean_of_angles;
  
  scanf("%d %d", &theta1, &theta2);

  if (abs(theta1 - theta2) < 180) {
    mean_of_angles = (double)(theta1 + theta2) / 2;
  } else {
    mean_of_angles = (double)(theta1 + theta2) / 2 + 180;
  }

  if (mean_of_angles >= 360) {
    mean_of_angles -= 360;
  }

  printf("%lf\n", mean_of_angles);

  return 0;
}



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

int main() {
	int ary[3];
	cin >> ary[0] >> ary[1] >> ary[2];
	sort(ary, ary + 3);
	cout << ary[0] << " " << ary[1] << " " << ary[2] << endl;
	return 0;
}

Measured memory_bytes: 3128
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 1005
struct node {
	int x,y;
}red[MAXN],blue[MAXN];
int N;
vector<int> bag[MAXN];
bool vis[MAXN];
int matched[MAXN];
bool un(int u) {
	for(int i=0;i<int(bag[u].size());i++)
		if(!vis[bag[u][i]]) {
			int v=bag[u][i];
			vis[v]=1;
			if(!matched[v]||un(matched[v])){
				matched[u]=v;
				matched[v]=u;
				return 1;
			}
		}
	return 0;
}
int result() {
	int ans=0;
	for(int i=1;i<=2*N;i++){
		if(!matched[i]) {
			memset(vis,0,sizeof vis);
			ans+=un(i);
		}
	}
	return ans;
}
int main() {
	scanf("%d",&N);
	for(int i=1;i<=N;i++)
		scanf("%d%d",&red[i].x,&red[i].y);
	for(int i=1;i<=N;i++)
		scanf("%d%d",&blue[i].x,&blue[i].y);
	
	for(int i=1;i<=N;i++)
		for(int j=1;j<=N;j++)
			if(red[i].x<blue[j].x&&red[i].y<blue[j].y){
				bag[i].push_back(j+N);
				bag[j+N].push_back(i);
			}
	int ans=result();
	printf("%d\n",ans);
	return 0;
}

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

#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
map <int,int> d;
int n,P,x;
string s;
int t[int(1e5)*2+10];
int mu[int(1e5)*2+10];
int sum;
ll cnt;
int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);cout.tie(0);
  // freopen("input.txt","r",stdin);
   cin >> n >> P;
   cin >> s;
   n=s.size();
   s='0'+s;
   mu[0] = 1;
   sum=0;
   for(int i=1;i<=n;i++) mu[i] = (mu[i-1]*10)%P;
   if (P!=2 && P!=5){
   int mod = 0;
   for(int i=n;i>0;i--){
        int t1 = (s[i]-'0');
        mod = (mod + (s[i]-'0')*mu[n-i])%P;
        t[i] = mod;
        d[mod]++;
   }
   x = mod;
   d[0]++;
   for(int i=0;i<=n-1;i++){
        int t1 = d[0];
        if (i+1<=n) d[t[i+1]]--;
        sum = (sum*10 + (s[i]-'0'))%P;
        cnt = cnt + d[(x-(sum*mu[n-i])%P+P)%P];
   }
   cout << cnt << endl;
   return 0;
   }
   if (P==2 || P==5){
        for(int i=1;i<=n;i++)
            if ((s[i]-'0')%P==0) cnt = cnt + i;
        cout << cnt << endl;
        return 0;
   }
   cout << n << endl;

}


Measured memory_bytes: 2512
fn main() {
    let n: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };

    if n % 1000 == 0 {
        println!("0");
    } else {
        println!("{}", 1000 - n % 1000);
    }
}

Measured memory_bytes: 2168
// from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!(s: String);
    let s: String = s;
    let x = s.chars().collect::<Vec<_>>();
    let ans = calc(0, &x);
    println!("{}", ans);
}

fn calc(total: u64, tail: &Vec<char>) -> u64 {
    if tail.is_empty() {
        return total;
    }

    let mut ans = 0;

    for i in 0..tail.len() {
        let a: String = tail.clone().into_iter().take(i + 1).collect();
        let b = a.parse::<u64>().unwrap();
        ans += calc(total + b, &tail[i + 1..].to_vec())
    }
    ans
}


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

namespace apple
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> input = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToList();
            int num = input[0];
            int baseTaste = input[1];

            int maxTaste = baseTaste + num - 1;
            int eatApple = 0;
            if (maxTaste < 0)
            {
                eatApple = num;
            }
            else if (baseTaste > 0)
            {
                eatApple = 1;
            }
            else
            {
                //1-baseTaset番目のリンゴを除く
                eatApple = 1 - baseTaste;
            }

            int applePie = 0;
            for (int i = 1; i <= num; i++)
            {
                if (i == eatApple)
                {
                    continue;
                }
                applePie += baseTaste + i - 1;
            }

            Console.WriteLine(applePie);
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using vc=vector<char>;
using vvc=vector<vc>;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using tiii = tuple<int,int,int>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int X;
  cin >> X;
  cout << (2199-X)/200 << endl;
}

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

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

int main()
{
    int y, m, d;
    scanf("%d/%d/%d", &y, &m, &d);

    bool ok = true;
    if (y > 2019)
        ok = false;
    else if (y == 2019 && m >= 5)
        ok = false;

    if (ok)
        printf("Heisei\n");
    else
        printf("TBD\n");

    return 0;
}


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

const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, ans=0, tmp=0;
vector<ll> A;

signed main(){
    cin >> N;
    N /= 100;
    if(N>=4) ans = 8;
    if(N>=6) ans = 7;
    if(N>=8) ans = 6;
    if(N>=10) ans = 5;
    if(N>=12) ans = 4;
    if(N>=14) ans = 3;
    if(N>=16) ans = 2;
    if(N>=18) ans = 1;
    cout << ans << endl;
    return 0;
}

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

int main()
{
  string S;
  int index=0;
  bool flag;
  string dd[4] = {"maerd", "remaerd", "esare", "resare"};

  cin >> S;
  reverse(S.begin(), S.end());
  bool ans=true;
  for (int i = 0; i < S.size();){
    bool flag=false;
    for(int j=0;j<4;j++){
      string d = dd[j];
      if(S.substr(i,d.size()) == d){
        i+=d.size();
        flag=true;
      }
    }
    if(flag == false){
      ans=false;
      break;
    }
  }
  if(ans) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
const int MOD = 1e9 + 7;

/*  divisor(n)
    入力：整数 n
    出力：nのすべての約数
    計算量：O(√n)
*/
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}

int N, M, K, Q, W, H, L, R, C, A, B, D;
string S;
vector<vector<int>> X;

int main() {
    cin >> N >> D;
    X.assign(N, vector<int>(D));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> X[i][j];
        }
    }

    int ans = 0;
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {
            ll dis = 0;
            for (int k = 0; k < D; k++) {
                dis += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
            }
            vector<ll> a = divisor(dis);
            if ((int)a.size() % 2 == 1) ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
    int N, A[MAXN + 3], F[MAXN + 3];
    LL K;

    cin >> N >> K;
    for (int i = 1; i <= N; i++)
        cin >> A[i];
    for (int i = 1; i <= N; i++)
        cin >> F[i];

    sort(A + 1, A + N + 1);
    sort(F + 1, F + N + 1, greater<int>());

    LL lo = 0, hi = 1e18 + 10, mid;
    while (hi >= lo) {
        mid = (lo + hi)/2;

        LL need = 0;
        for (int i = 1; i <= N; i++)
            need += max((LL) 0, A[i] - mid/F[i]);

        if (need <= K)
            hi = mid - 1;
        else
            lo = mid + 1;
    }

    cout << lo << endl;
}


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

#define FOR(x,n) for(int x=0;x<n;x++)
#define mp make_pair
typedef long long ll;
typedef pair<int,int> iPair;

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

  int a, b, c;
  cin >> a >> b >> c;
  swap(a, b);
  swap(a, c);
  cout << a << ' ' << b << ' ' << c << '\n';
}

// UPDATE N WHEN UR DONE AAAAAAAAAAAAAAAAAAAAAAAAAAA (if it applies lol)

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#include <list>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    string s;
    cin >> s;
    if(s[2] == s[3] and s[4] == s[5]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
import java.io.*;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input = br.readLine().split(" ");
        int a = Integer.parseInt(input[0]);
        int b = Integer.parseInt(input[1]);
        int gcd = 1;
        if (a > b) {
            int temp = b;
            b = a;
            a = temp;
        }
        int i = 1;
        while (i > 0) {
            if (a%(a/i) == 0 && b%(a/i) == 0) {
                System.out.println(a/i);
                return;
            } else {
                i++;
            }
        }

        
    }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll t,d,l;

template< class T >
struct CumulativeSum {
    vector< T > data;

    CumulativeSum(int sz) : data(sz, 0) {};

    void add(int k, T x) {
        data[k] += x;
    }

    void build() {
        for(int i = 1; i < data.size(); i++) {
            data[i] += data[i - 1];
        }
    }

    T query(int k){
        if(k < 0) return (0);
        return (data[min(k, (int) data.size() - 1)]);
    }

    T query(int l,int r){// 区間[l,r]
        return query(r) - query(l - 1);
    }
};

int main(){
    while(cin >> t >> d >> l && t){
        // cout << "!!" << t << endl;
        CumulativeSum<ll> cs(t);
        rep(i,t){
            ll num;
            cin >> num;
            if(num >= l){
                cs.add(i,1);
                if(i+d < cs.data.size())cs.add(i+d,-1);
            }
        }
        cs.build();
        ll ans = 0;
        rep(i,t-1){
            if(cs.data[i] > 0)ans++;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3924
import math

N = int(input())
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

#find bottle neck (the smallest of A,B,C,D,E)
neck = min(A,B,C,D,E)

#find number of groups of neck. 
#(How many groups of neck people can be made)
groups = math.ceil(N / neck)

if groups <= 1:
    ans = 5
else:
    ans = 5 + (groups - 1)
    
print(ans)

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

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define loop(i,a,b) for(int (i)=(a);(i)<(b);++(i))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;

bool checkBeginEnd(vector<string> vs){
  rep(i,vs.size()-1){
    if(vs[i][vs[i].size() - 1 ] != vs[i+1][0]){
      return false;
    }
  }
  return true;
}

bool checkSameWords(vector<string> vs){
  sort(vs.begin(), vs.end());
  rep(i,vs.size()-1){
    if(vs[i] == vs[i+1]){
      return false;
    }
  }
  return true;
}

int main(void){
  int n;
  cin>>n;  
  vector<string> vs(n);
  rep(i,n)cin>>vs[i];
  bool result = checkBeginEnd(vs) && checkSameWords(vs);
  cout<<(result? "Yes" : "No")<<endl;
}




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

int main() {
   string S ;
   cin >>  S ;
   int ans=0 ;
  for ( int i=0 ; i<4 ; i++ ){
   if ( S.at(i)=='+') ans++ ;
    if ( S.at(i)=='-') ans-- ;
}
cout << ans << endl ;
}

      

Measured memory_bytes: 256
data_num = int(input())
nums = list(map(int, input().split(" ")))
cnt = 0
for i in range(data_num):
    for j in range(data_num-1, i,-1):
        if nums[j]<nums[j-1]:
            nums[j], nums[j-1] = nums[j-1], nums[j]
            cnt = cnt + 1

print(" ".join(map(str,nums)) + "\n" + str(cnt))

Measured memory_bytes: 7648
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var s = next();
  var sLen = s.length;
  var K = myconv(next(),1);
  var set = new Set();
  for(var i = 0; i < K; i++){
    for(var j = 0; j < sLen - i; j++){
      set.add(s.slice(j, j + i + 1));
    }
  }
  var strings = Array.from(set);
  strings.sort();
  myout(strings[K - 1]);
}

Measured memory_bytes: 11304
from collections import defaultdict
import sys
input = sys.stdin.readline


class UnionFind:
    def __init__(self, size):
        self.parent = list(range(size))
        self.rank = [0] * size

    def find(self, x):
        if self.parent[x] != x:
            self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)


N, M, K = map(int, input().split())
uf = UnionFind(N)
friend = [0] * N
for _ in range(M):
    A, B = map(lambda x: int(x)-1, input().split())
    friend[A] += 1
    friend[B] += 1
    uf.unite(A, B)
block = [0] * N
for _ in range(K):
    C, D = map(lambda x: int(x)-1, input().split())
    if uf.same(C, D):
        block[C] += 1
        block[D] += 1
counter = defaultdict(int)
for i in range(N):
    counter[uf.find(i)] += 1
ans = [0] * N
for i in range(N):
    ans[i] = counter[uf.find(i)] - friend[i] - block[i] - 1
print(' '.join(map(str, ans)))


Measured memory_bytes: 99032
#include <bits/stdc++.h>
#define ll long long
#define PI 3.141592653589
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define EPS 1e-7
#define f first
#define s second
using namespace std;
string s, t;
int main() {
    IO;
    cin >> s >> t;
    int dp[s.size()+1][t.size()+1];
    for(int i = 0; i <= t.size(); ++i)
        dp[0][i] = 0;
    for(int i = 1; i <= s.size(); ++i){
        dp[i][0] = 0;
        for(int j = 1; j <= t.size(); ++j){
            if(s[i-1]==t[j-1])
                dp[i][j] = 1+dp[i-1][j-1];
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }
    string ans;
    int i = s.size(), j = t.size();
    ans.resize(dp[i][j]);
    while(dp[i][j]){
        if(s[i-1]==t[j-1]){
            ans[dp[i][j]-1] = s[i-1];
            i--;
            j--;
        }else if(dp[i][j]==dp[i-1][j])
            i--;
        else
            j--;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 35456
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val h = sc.nextInt()
  val w = sc.nextInt()
  val s = (1..h).map { sc.next() }

  val array = Array(h) { Array(w) { '.' } }
  for (i in 0 until h) {
    val si = s.get(i)!!
    for (j in 0 until w) {
      array[i][j] = si[j]
    }
  }

  var ok = true
  for (i in 0 until h) {
    if (!ok) break
    for (j in 0 until w) {
      if (!ok) break
      if (array[i][j] == '.') {
        continue
      }

      var tmp = false

      if (i != 0) {
        val top = array[i-1][j]
        if (top == '#') {
          tmp = true
        }
      }
      if (i != h-1) {
        val bottom = array[i+1][j]
        if (bottom == '#') {
          tmp = true
        }
      }
      if (j != 0) {
        val left = array[i][j-1]
        if (left == '#') {
          tmp = true
        }
      }
      if (j != w-1) {
        val right = array[i][j+1]
        if (right == '#') {
          tmp = true
        }
      }
      if (!tmp) {
        ok = false
      }
    }
  }

  if (ok) {
    println("Yes")
    return
  }
  println("No")
}


Measured memory_bytes: 37772
#include <iostream>

#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

#include <cmath>
#include <algorithm>

#include <fstream>

using namespace std;


const long long INF = 1e9;
using LD = long double;





int main()
{
    //ifstream cin ("/Users/Roman/ClionProjects/Calculations/input.txt");
    //ofstream cout ("/Users/Roman/ClionProjects/Calculations/output.txt");

    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    cout.setf(ios_base::fixed);
    cout.precision(10);
    srand(179);
    int n, k;
    int maxn = (2 << 15);
    //cout << maxn << endl;
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        ans += (a % 2);
    }
    ans %= 2;
    if (ans) {
        cout << "NO";
    } else {
        cout << "YES";
    }

    return 0;
}

Measured memory_bytes: 884
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 200020
using namespace std;
int read(){
	int nm=0,fh=1; char cw=getchar();
	for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
	return nm*fh;
}
int n,m,ans1,ans2,p[M][2],v[M],now1,now2,tot;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read(),tot=n;
	for(int i=1;i<=n;i++) v[i]=read(),p[v[i]][i&1]++;
	for(int i=1;i<=100000;i++){
	    if(p[i][0]>=ans1&&p[i][0]) now2=now1,now1=i,ans2=ans1,ans1=p[i][0];
	    else if(p[i][0]>ans2) ans2=p[i][0],now2=i;
	}
	for(int i=1;i<=100000;i++){
		if(i==now1) tot=min(tot,n-ans2-p[i][1]);
		else tot=min(tot,n-ans1-p[i][1]);
	}
	printf("%d\n",tot);
	return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
#define Mod 1e9+7
const LL mod=1e9+7;
const LL inf=0x3f3f3f3f;
using namespace std;
int a[1005],n;
int main()
{
	int mins=0xfffffff;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(int i=-100;i<=100;i++)
	{
		int sum=0;
		for(int j=0;j<n;j++)
			sum+=(a[j]-i)*(a[j]-i);
		if(sum<mins)
		{
			mins=sum;
		}
	}
	printf("%d\n",mins);
    return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;

vector<vector<int> > g;
vector<int> ids;

void rec(int v, int id)
{
  int n = g[v].size();
  ids[v] = id;
  for (int i = 0; i < n; ++i) {
    if (ids[g[v][i]] == -1) {
      rec(g[v][i], id);
    }
  }
}

int main()
{
  int n, m;
  fscanf(stdin, "%d %d", &n, &m);
  g = vector<vector<int> >(n);
  ids = vector<int>(n, -1);
  for (int i = 0; i < m; ++i) {
    int s, t;
    fscanf(stdin, "%d %d", &s, &t);
    g[s].push_back(t);
    g[t].push_back(s);
  }
  int id = 0;
  for (int i = 0; i < n; ++i) {
    if (ids[i] == -1) {
      rec(i, id);
      ++id;
    }
  }
  int q;
  fscanf(stdin, "%d", &q);
  for (int i = 0; i < q; ++i) {
    int s, t;
    fscanf(stdin, "%d %d", &s, &t);
    fprintf(stdout, "%s\n", ids[s] == ids[t] ? "yes" : "no");
  }
  return 0;
}

Measured memory_bytes: 11660
#include <stdio.h>

int main(void) {
	int i,ii,n,ds,hmb,now,next,min,max,dat[200]={0};
	scanf("%d",&ds);
		for (i = 1;i <= ds;i++){
			scanf("%d",&hmb);
				for (ii = 0;ii < hmb;ii++){
					scanf("%d",&n);
					dat[ii] = n;
				}
				max = 0;
				min = 0;
				for (ii = 0;ii < hmb - 1;ii++){
					now = dat[ii];
					next = dat[ii + 1];
					if (max < next - now){
						max = next - now;
					}
					if (min > next - now){
						min = next - now;
					}
				}
			printf("%d %d\n",max,-min);
		}
	return 0;
}
//aoj 2100

Measured memory_bytes: 596
import sys
from heapq import heappop as hpp, heappush as hp
inf = 10**20
def dijkstra(N, s, Edge):
    dist = [inf] * N
    Q = [(0, s)]
    decided = set()
    for _ in range(N):
        while True:
            dn, vn = hpp(Q)
            if vn not in decided:
                decided.add(vn)
                dist[vn] = dn
                break
        for vf, df in Edge[vn]:
            if vf not in decided:
                hp(Q, (dn + df, vf))
    return dist

readline = sys.stdin.readline
N, M = map(int, readline().split())

Edge = [[] for _ in range(N)]
for i in range(M):
    L, R, C = map(int, readline().split())
    L -= 1
    R -= 1
    Edge[L].append((R, C))

for i in range(1, N):
    Edge[i].append((i-1, 0))
for i in range(1, N):
    Edge[0].append((i, inf))
dist = dijkstra(N, 0, Edge)
if dist[N-1] == inf:
    ans = -1
else:
    ans = dist[N-1]
print(ans)


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

int main() {
  int A, B, c = 0;
  cin >> A >> B;

  for (int i = A; i <= B; i++) {
    if(i/10000 == i%10 && i/1000%10 == i%100/10){
      c++;
    }
  }
  cout << c << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <math.h>
#include <algorithm>


using namespace std;

int main(){
	
	int answer;

	int s = 0, t = 0;
	int ibuf;

	for (int i = 0; i < 4; i++) {
		cin >> ibuf;
		s += ibuf;
	}
	for (int i = 0; i < 4; i++) {
		cin >> ibuf;
		t += ibuf;
	}

	answer = max(s, t);

	cout << answer << endl;

	return 0;
}


Measured memory_bytes: 3100
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 	3.14159265358979323846


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int sum=0;
    for(int i=0;i<n;i++){
        int r,l;
        cin >> r >> l;
        sum += 1+l-r;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define pb push_back
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  ll cnt=0, enemy=0;
  cin >> N;
  vector<int> A(N+1);
  REP(i,N+1) cin >> A[i];
  vector<int> B(N);
  REP(i,N) cin >> B[i];
  REP(i,N) {
    if(A[i]>=B[i]) cnt+=B[i];
    else {
      enemy=A[i]+A[i+1];
      if(enemy>=B[i]) {
        cnt+=B[i];
        A[i+1]-=B[i]-A[i];
      }
      else {
        cnt+=enemy;
        A[i+1]=0;
      }
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 1152
# 追加クエリにおける直線の傾きが単調であり、最小値クエリにおけるxが単調である時の Convex-Hull Trick
# もっと言うと、今回は追加クエリの傾きが単調減少で、最小値クエリにおけるxが単調増加
# 参考 : http://satanic0258.hatenablog.com/entry/2016/08/16/181331

from collections import deque
deq = deque()

# 直線 l1, l2, l3のうち l2が不必要かどうか (不必要なら1, 必要なら0を返す)
def check(f1, f2, f3):
    return (f3[1] - f2[1]) * (f2[0] - f1[0]) >= (f2[1] - f1[1]) * (f3[0] - f2[0])

# f1(x)を返す
def f(f1, x):
    return f1[0] * x + f1[1]

# 直線 y = ax + b を追加
def add(a, b):
    # 直線 l1: deq[-2], l2: deq[-1], l3: (a, b)のうち, l2が不必要なら除くことを繰り返す
    while len(deq) >= 2 and check(deq[-2], deq[-1], (a, b)):
        deq.pop()
    deq.append((a, b))

#
def get(x):
    # 今回はクエリのxが単調増加であることを利用する
    # すると、あるクエリに置いて f1(x0) >= f2(x0)となればそれ以降(x > x0)でf1は最小となることはないので, f1を取り除く
    while len(deq) >= 2 and f(deq[0], x) >= f(deq[1], x):
        deq.popleft()
    # 上の操作後、deq の先頭が最小になるのでそれを返す
    return f(deq[0], x)


n, c = map(int, input().split())
h = list(map(int, input().split()))

INF = float('inf')
dp = [INF] * n
dp[0] = 0
add(-2 * h[0], h[0]**2 + dp[0])

for i in range(1, n):
    dp[i] = get(h[i]) + h[i]**2 + c
    add(-2 * h[i], h[i]**2 + dp[i])

print(dp[n-1])


Measured memory_bytes: 40148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define X first
#define Y second
#define REP(i,a) for(int i=0;i<a;++i)
#define REPP(i,a,b) for(int i=a;i<b;++i)
#define FILL(a,x) memset(a,x,sizeof(a))
#define foreach( gg,itit )  for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
#define mp make_pair
#define pb push_back
#define all(s) s.begin(),s.end()
#define sz(s) (int)s.size()
#define present(c,x) ((c).find(x) != (c).end())
const double EPS = 1e-8;
const int mod = 1e9+7;
const int N = 1e6+10;
const ll INF = 1e18;

ll power(ll x,ll y){
	ll t=1;
	while(y>0){
		if(y%2) y-=1,t=t*x%mod;
		else y/=2,x=x*x%mod;
	}
return t;
}

vector <ll> vx,vy;

int main(){
	int n,m;
	ll x,y,ysum=0,xsum=0,pref=0;
	scanf("%d%d",&n,&m);
	REP(i,n){
		scanf("%lld",&x);
		vx.pb(x);
	}
	sort(all(vx));
	REP(i,m){
		scanf("%lld",&x);
		vy.pb(x);
	}
	sort(all(vy));
	REP(i,n){
		xsum+=(i*vx[i]-pref+mod);
		xsum%=mod;
		pref=(pref+vx[i]+mod)%mod;
	}
	pref=0;
	REP(i,m){
		ysum+=(i*vy[i]-pref+mod);
		ysum%=mod;
		pref=(pref+vy[i]+mod)%mod;
	}
	printf("%lld\n",(xsum*ysum)%mod);
	return 0;
}

Measured memory_bytes: 2548
import collections

N = int(input())
l = [s for s in input().split()]

c = collections.Counter(l)
ans_dict = {}

hoge = list(c.values())
full_fuga = [(i*(i-1))/2 if i >= 2 else 0 for i in hoge]
full_ans = sum(full_fuga)

for i in l:
    v = c[str(i)]
    if v < 2:
        print(int(full_ans))
    elif v == 2:
        print(int(full_ans - 1))
    elif v > 2:
        print(int(full_ans - ((v*(v-1))/2) + (((v-1) *(v-2))/2)))


Measured memory_bytes: 27140
N, M, X, Y = map(int,input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))


x_max  = max(x)
y_min = min(y)
if x_max >= y_min or x_max >= Y or y_min <= X:
    print("War")
else :
    print("No War")

Measured memory_bytes: 3060
//52行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

template<class T> bool chmin(T& a,T b){if(a > b){a = b;return true;}else return false;}
template<class T> bool chmax(T& a,T b){if(a < b){a = b;return true;}else return false;}
///////////////////////////////////////////////////////////

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(20);
    string s;cin >> s;
    int n = s.size();
    for(int i = 0;i < (n-1)/2;i++){
        if(s[i] != s[n-1-i]){
            cout << "No" << '\n';
            return 0;
        }
    }
    int m = (n-1)/2;
    for(int i = 0;i < m;i++){
        if(s[i] != s[m-1-i]){
            cout << "No" << '\n';
            return 0;
        }
        if(s[m+1+i] != s[n-1-i]){
            cout << "No" << '\n';
            return 0;
        }
    }
    cout << "Yes" << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int main(){
	int n,ans=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(i%2==1&&a[i]%2==1) ans++;
	}
	cout<<ans;
	return 0;
}

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

using namespace std;

typedef long long ll;

#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 INF 1000000000

int main() {

	int n;
	cin >> n;
	vector<int> a(n);
	FOR(i, n) {
		cin >> a[i];
		a[i] = a[i] - i - 1;
	}

	ll ans = 0;
	int b;
	SORT(a);
	if (n % 2 == 1)b = a[n / 2];
	else b = (a[n / 2 - 1] + a[n / 2]) / 2;
	FOR(i, n)ans += abs(a[i] - b);

	cout << ans << endl;

	return 0;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

int main() {
	ll n;
	cin >> n;
	vector<ll> as(n), bs(n), cs(n);
	rep(i, n) cin >> as[i];
	rep(i, n) cin >> bs[i];
	rep(i, n) cin >> cs[i];
	sort(as.begin(), as.end());
	sort(bs.begin(), bs.end());
	sort(cs.begin(), cs.end());

	vector<ll> pb(n);
	rep(i, n) {
		auto b = bs[i];
		auto it = upper_bound(cs.begin(), cs.end(), b);
		pb[i] = cs.end() - it;
	}
	vector<ll> pbsum(n+1, 0);
	rep(i, n) {
		pbsum[n - 1 - i] = pbsum[n - i] + pb[n - i - 1];
	}
	ll sum = 0;
	rep(i, n) {
		auto a = as[i];
		auto it = upper_bound(bs.begin(), bs.end(), a);
		int index = it - bs.begin();
		sum += pbsum[index];
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 7220
n = int(input())
b = list(map(int, input().split()))

a = [b[0]]

for i in range(n-1):
    if i < n-2:
        a.append(b[i] if b[i+1] >= b[i] else b[i+1])
    else:
        a.append(b[i])

    while b[i] < max(a[i], a[i+1]):
        a[i+1] += 1

print(sum(a))


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

typedef struct list_t_tag {
	int x,y,dx,dy;
	struct list_t_tag* next;
} list_t;

void add_tama(list_t* head,int x,int y) {
	static const int dxy[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
	int i;
	list_t* head_next=head->next;
	list_t* now_head=head;
	for(i=0;i<4;i++) {
		now_head->next=malloc(sizeof(list_t));
		now_head->next->x=x;
		now_head->next->y=y;
		now_head->next->dx=dxy[i][0];
		now_head->next->dy=dxy[i][1];
		now_head=now_head->next;
	}
	now_head->next=head_next;
}

int main(void) {
	int board[4][4];
	int i,j;
	int nowans;
	for(i=0;i<4;i++) {
		for(j=0;j<4;j++)scanf("%d",&board[i][j]);
	}
	for(nowans=0;nowans<=5;nowans++) {
		int nowboard[4][4];
		int smax=(1<<(nowans*4));
		int search;
		int ok=0;
		for(search=0;search<smax;search++) {
			for(i=0;i<4;i++) {
				for(j=0;j<4;j++)nowboard[i][j]=board[i][j];
			}
			for(i=0;i<nowans;i++) {
				int x=(search>>(i*4+2))&3;
				int y=(search>>(i*4))&3;
				list_t head_buf={0,0,0,0,NULL};
				list_t* head=&head_buf;
				nowboard[y][x]++;
				if(nowboard[y][x]>=5) {
					nowboard[y][x]=0;
					add_tama(head,x,y);
				}
				while(head->next!=NULL) {
					list_t* now;
					list_t* prev;
					int xx,yy;
					/* move tama */
					for(now=head->next,prev=head;now!=NULL;) {
						now->x+=now->dx;
						now->y+=now->dy;
						if(now->x<0 || now->x>=4 || now->y<0 || now->y>=4) {
							list_t* now_next_bak=now->next;
							free(now);
							prev->next=now_next_bak;
							now=now_next_bak;
						} else if(nowboard[now->y][now->x]>0) {
							list_t* now_next_bak=now->next;
							nowboard[now->y][now->x]++;
							free(now);
							prev->next=now_next_bak;
							now=now_next_bak;
						} else {
							prev=now;
							now=now->next;
						}
					}
					/* erase drops */
					for(yy=0;yy<4;yy++) {
						for(xx=0;xx<4;xx++) {
							if(nowboard[yy][xx]>=5) {
								nowboard[yy][xx]=0;
								add_tama(head,xx,yy);
							}
						}
					}
				}
			}
			ok=1;
			for(i=0;i<4;i++) {
				for(j=0;j<4;j++) {
					if(nowboard[i][j]>0) {
						i=j=4;
						ok=0;
						break;
					}
				}
			}
			if(ok)break;
		}
		if(ok)break;
	}
	printf("%d\n",nowans<=5?nowans:-1);
	return 0;
}

Measured memory_bytes: 600