akhauriyash/Code-Regression huggingface dataset:
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
long long cnt[1000000] = {};
int main() {
	long long n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) {
		cnt[i % k]++;
	}
	long long ans = 0;
	for (int i = 0; i < k; ++i) {
		long long geko = k - i;
		geko %= k;
		if ((geko + geko) % k == 0) {
			ans += cnt[i] * cnt[geko] * cnt[geko];
		}
	}
	cout << ans << endl;
	return 0;
}

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


def main():
    n = int(input())
    p = list(map(int, input().split()))
    count = 0

    for i in range(1, n - 1):
        value_max = max(p[i - 1], p[i], p[i + 1])
        value_min = min(p[i - 1], p[i], p[i + 1])

        if p[i] != value_max and p[i] != value_min:
            count += 1

    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
let n=read_int()open Array
let a=init n(fun _->Scanf.scanf"%d "(fun e->e))and b=make n 0and c=make 10001 0;;iter(fun e->c.(e)<-c.(e)+1)a;iteri(fun i _->if i<>0then c.(i)<-c.(i)+c.(i-1))c;for i=n-1downto 0do c.(a.(i))<-c.(a.(i))-1;b.(c.(a.(i)))<-a.(i);done;print_int b.(0);for i=1to n-1do print_string" ";print_int b.(i);done;print_newline()

Measured memory_bytes: 36156
x,k,d = list(map(int, input().split()))

x=abs(x)
if k<=(x/d):
    print(x-d*k)
else:
    tmp=(x//d)
    x=x-tmp*d
    if (k-tmp)%2==0:
        print(x)
    else:
        print(abs(x-d))

Measured memory_bytes: 9164
#include<iostream>
using namespace std;
int main()
{
  int a,b,i,res=0;
  cin >> a >> b;
  for(i=a;i<=b;i++)
    if(i/10000==i%10&&(i/1000)%10==(i/10)%10)
      res++;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
//小さい順にソート
char c[2][200002];
void merge(int i,int j,char s[2][200002]){
  if(i!=j){
    merge(i,(i+j)/2,s);
    merge((i+j)/2+1,j,s);
    int a=i,b=(i+j)/2+1;
    int d;
    for(d=i;d<=j;d++){
      if((i+j)/2<a){
        c[0][d]=s[0][b];
        c[1][d]=s[1][b];
        b++;
      }
      else if(j<b){
        c[0][d]=s[0][a];
        c[1][d]=s[1][a];
        a++;
      }
      else if(s[0][a]<s[0][b]){
        c[0][d]=s[0][a];
        c[1][d]=s[1][a];
        a++;
      }
      else{
        c[0][d]=s[0][b];
        c[1][d]=s[1][b];
        b++;
      }
    }
    for(d=i;d<=j;d++){
      s[0][d]=c[0][d];
      s[1][d]=c[1][d];
    }
  }
}

int main(){
  char s[2][200002];
  scanf("%s",s[0]);
  scanf("%s",s[1]);
  int len,i,change[27];
  for(i=0;i<27;i++)
    change[i]=0;
  len=strlen(s[0]);
  merge(0,len-1,s);
  for(i=0;i<len;i++)
    if(s[0][i]==s[1][i])
      change[s[0][i]-'a']=1;
  for(i=0;i<len;i++){
    if(i!=len && s[0][i]==s[0][i+1] && s[1][i]!=s[1][i+1]){
      puts("No");
      return 0;
    }
    else if(s[0][i]!=s[1][i] && change[s[1][i]-'a']==1){
      puts("No");
      return 0;
    }
    else if(s[0][i]!=s[0][i+1])
      change[s[1][i]-'a']=1;
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 896
if __name__ == "__main__":
    N = int(input())
    S = input()

    l_count = 0
    r_count = 0
    shift = 0
    for i in range(len(S)):
        if S[i + shift] == '(':
            l_count += 1
        else:
            r_count += 1

        if r_count > l_count:
            S = '(' + S
            l_count += 1
            shift += 1

    if l_count > r_count:
        n = l_count - r_count
        S = S + ')' * n

    print(S)


Measured memory_bytes: 3060
N, M = map(int, input().split())
l = []
for i in range(M):
  l.append(list(map(str, input().split())))
for i in range(M):
  l[i][0] = int(l[i][0])
check_l = [0] * N
temp_penalty = [0] * N

penalty = 0
ans_count = 0

for i in range(M):
  if check_l[l[i][0]-1] == 0:
    if l[i][1] == 'AC':
      check_l[l[i][0]-1] = 1
      ans_count += 1
      penalty += temp_penalty[l[i][0]-1]
    else:
      temp_penalty[l[i][0]-1] += 1

print(ans_count, penalty)

Measured memory_bytes: 36900
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#![allow(unused_mut)]
#![allow(unused_variables)]
#![allow(dead_code)]

use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};

#[allow(unused_macros)]
#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    //($arg:expr) => (println!("{:?}",$arg));
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}
#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}

macro_rules! echo {
    ($($a:expr),*) => {
          $(println!("{}",$a))*
      }
}

use std::cmp::*;
use std::collections::*;
use std::ops::{Add, Div, Mul, Sub};

#[allow(dead_code)]
static INF_I64: i64 = 92233720368547758;
#[allow(dead_code)]
static INF_I32: i32 = 21474836;
#[allow(dead_code)]
static INF_USIZE: usize = 18446744073709551;
#[allow(dead_code)]
static M_O_D: usize = 1000000007;
#[allow(dead_code)]
static PAI: f64 = 3.1415926535897932;

trait IteratorExt: Iterator {
    fn toVec(self) -> Vec<Self::Item>;
}

impl<T: Iterator> IteratorExt for T {
    fn toVec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

trait CharExt {
    fn toNum(&self) -> usize;
    fn toAlphabetIndex(&self) -> usize;
    fn toNumIndex(&self) -> usize;
}
impl CharExt for char {
    fn toNum(&self) -> usize {
        return *self as usize;
    }
    fn toAlphabetIndex(&self) -> usize {
        return self.toNum() - 'a' as usize;
    }
    fn toNumIndex(&self) -> usize {
        return self.toNum() - '0' as usize;
    }
}

trait VectorExt {
    fn joinToString(&self, s: &str) -> String;
}
impl<T: ToString> VectorExt for Vec<T> {
    fn joinToString(&self, s: &str) -> String {
        return self
            .iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(s);
    }
}

trait StringExt {
    fn get_reverse(&self) -> String;
}
impl StringExt for String {
    fn get_reverse(&self) -> String {
        self.chars().rev().collect::<String>()
    }
}

trait UsizeExt {
    fn pow(&self, n: usize) -> usize;
}
impl UsizeExt for usize {
    fn pow(&self, n: usize) -> usize {
        return ((*self as u64).pow(n as u32)) as usize;
    }
}

fn main() {
    input! {
       N: usize,
    }

    let mut ans: usize = 0;

    echo!(if N == 0 { 1 } else { 0 });
}


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

int n, a[200001];
map<int, int> m;

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

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

    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        if(m.find(a[i]) != m.end())
            ans += (ll)m[a[i]];
    }

    cout << ans << '\n';
    return 0;
}


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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;

void run_case()
{
    ll x;
    cin >> x;
    int ans = 0;
    for (ll i = 2; i * i <= x; i++)
    {
        //int cnt = 0;
        if (x % i == 0)
        {
            int cnt = 0;
            while (x % i == 0)
            {
                x /= i;
                cnt++;
            }
            //DBG(cnt);
            for (int k = 1;; k++)
            {
                cnt -= k;
                ans++;
                if (cnt <= k)
                    break;
                //ans++;
            }
        }
    }
    if (x > 1)
        ans++;
    cout << ans << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define ll long long
#define maxn 200005
#define INF 1000000000000000005ll
using namespace std;

int n,m;
vector<pair< pair<ll,ll>, ll> > interval;
struct S {
    ll mx,prop;
}tree[maxn*3+5];

void add(int node,int b,int e,int i,int j,ll x)
{
    if(j<b || i>e) return;
    if(b>=i && e<=j) {
        tree[node].prop+=x;
        if(tree[node].mx!= -INF)
        tree[node].mx+=x;
        else
        tree[node].mx = x;
      //  cout<<"tree node "<<b<<" "<<e<<" "<<tree[node].mx<<endl;
        return;
    }
    int left = 2*node;
    int right = 2*node + 1;
    int mid =(b+e)/2;
    add(left,b,mid,i,j,x);
    add(right,mid+1,e,i,j,x);
    tree[node].mx = max(tree[left].mx,tree[right].mx)+tree[node].prop;
}

ll query(int node,int b,int e,int i,int j,ll carry)
{
    if(j<b || i>e) return -INF;
    if(b>=i && e<=j) {
     //   cout<<"qqqq "<<b<<" "<<e<<" "<<tree[node].mx<<endl;
        return tree[node].mx+ carry;
    }
    int left = 2*node;
    int right = 2*node+1;
    int mid = (b+e)/2;
    ll q1 = query(left,b,mid,i,j,tree[node].prop+carry);
    ll q2 = query(right,mid+1,e,i,j,tree[node].prop+carry);
    return max(q1,q2);
}

int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<=3*n;i++) tree[i].mx = -INF;
    for(int i=0;i<m;i++)
    {
        ll a,b,c;
        cin>>a>>b>>c;
        interval.push_back(make_pair(make_pair(b,a),c));
    }
    sort(interval.begin(),interval.end());
    int sz = interval.size();
    int p = 0;
    for(int i=1;i<=n;i++) {
        ll val = query(1,1,n,0,i-1,0);
        val = max(val,0ll);
       // if(val!=0)
        //cout<<i-1<<" "<<val<<endl;
        add(1,1,n,i,i,val);
        while(p<sz && interval[p].first.first == i) {
         //   cout<<" interval "<<interval[p].first.second<<" "<<interval[p].first.first<<endl;
            add(1,1,n,interval[p].first.second, interval[p].first.first,interval[p].second);
         //   cout<<query(1,1,n,1,interval[p].first.first,0)<<endl;
            p++;
        }
    }
    cout<<max(0ll,query(1,1,n,1,n,0))<<endl;

    return 0;
}


Measured memory_bytes: 17904
import numpy as np

length = int(input())
B = list(map(int,input().split(" ")))

A = [0 for i in range(length)]
for i in range(len(B)):
    #次の数ののほうが大きければ
    if i == 0:
        A[i],A[i+1] = B[i],B[i]
    
    else:
        if B[i]<=A[i]:
            A[i] = B[i]
    
    A[i+1] = B[i]

print(np.sum(A))

Measured memory_bytes: 16060
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int dp[100005]; //we need dp at h

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int h, n;
	cin >> h >> n;
	vi a(n), b(n);
	rep(i, n) cin >> a[i] >> b[i];
	rep(i, 100005) dp[i] = 1e9;
	dp[0] = 0;
	repn(i, 1, 100005){
		rep(j, n) if(i >= a[j]){
			dp[i] = min(dp[i], dp[i - a[j]] + b[j]);
		}
	}
	int ans = 1e9;
	repn(i, h, 100005) ans = min(ans, dp[i]);
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cctype>

#define div 1000000000+7

typedef long long ll;

using namespace std;


int main() {
    int a, b, c;
    int sum=0;
    cin >> a >> b >> c;
    for(int i = 1; i < 100; i++){
        sum += a*i;
        //cout << sum << endl;
        if(sum % b == c || a*i % b == c){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <utility>
#define FR first
#define SE second

using namespace std;

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

pr a[100005];
map <ll,int> mp;

int size[100005],p[100005],n;
ll num[100005];

struct Edge {
  int t,next;
  Edge() {}
  Edge(int a,int b):t(a),next(b) {}
};

Edge e[200005];
int head[100005];

ll up[100005],down[100005];
int sz[100005];

void dfs1(int x,int fa) {
  sz[x]=1;
  for(int i=head[x];i;i=e[i].next)
    if (e[i].t!=fa) {
    	int u=e[i].t;
    	dfs1(u,x);
    	down[x]+=down[u]+sz[u];
    	sz[x]+=sz[u];
	}
}

void dfs2(int x,int fa) {
  ll s=up[x];
  for(int i=head[x];i;i=e[i].next)
    if (e[i].t!=fa) s+=down[e[i].t]+sz[e[i].t];
  for(int i=head[x];i;i=e[i].next)
    if (e[i].t!=fa) {
    	int u=e[i].t;
    	up[u]=s-down[u]-sz[u]+n-sz[u];
    	dfs2(u,x);
	}
}

int main() {
  scanf("%d",&n);
  for(int i=1;i<=n;i++) {
  	ll x;
  	scanf("%lld",&x);
  	a[i]=pr(x,i);
  	mp[x]=i;
  	num[i]=x;
  }
  sort(a+1,a+n+1);
  for(int i=n;i>1;i--) {
  	int x=a[i].SE;
  	size[x]++;
  	if (n-2*size[x]<=0) {
  		puts("-1");
  		return 0;
	  }
	ll t=a[i].FR-(n-2*size[x]);
	if (!mp.count(t)) {
		puts("-1");
		return 0;
	}
	p[x]=mp[t];
	size[p[x]]+=size[x];
	e[2*i-1]=Edge(x,head[p[x]]);
	head[p[x]]=2*i-1;
	e[2*i]=Edge(p[x],head[x]);
	head[x]=2*i;
  }
  dfs1(1,0);
  dfs2(1,0);
  for(int i=1;i<=n;i++)
    if (up[i]+down[i]!=num[i]) {
    	puts("-1");
    	return 0;
	}
  for(int i=1;i<=n;i++)
    if (p[i]) printf("%d %d\n",p[i],i);
  return 0;
}

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

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

    int cnt = 1;
    int d = 0;
    for (int i = 0; i < n; i++) {
        int l; cin >> l;
        d += l;
        if (d > x) break;
        cnt++;
    }

    cout << cnt << endl;

    return 0;
}


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

#include <cstring>
    #define mp make_pair
    #define pb push_back
    #define p push

    #define FOR(a,c) for(int a = 0;a<c;a++)
    #define ll long long int

    #define getI(a) scanf("%d",&a)
    #define getII(a,b) scanf("%d%d",&a,&b)
    #define getIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
    #define getL(a) scanf("%lld",&a)
    #define getLL(a,b) scanf("%lld%lld",&a,&b)
    #define BEND(c) (c).begin(),(c).end()
    #define BEND2(c) (c).begin(),(c).end(),greater<int>()
    #define fi first
    #define se second
    #define pi 3.1415926535897932384626
    #define getS(a) scanf("%s",a)
    #define pfi(a) printf("%d",a);
    #define pfii(a,b) printf("%d%d",a,b);
    #define pfl(a) printf("%lld",a);
    #define pfll(a,b) printf("%lld%lld",a,b);
    #define pfd(a) printf("%lf",a);


    #define sag (sol|1)
    #define sol (root<<1)
    #define ort (bas+son)/2
    #define SIZE 1000000007
    using namespace std;

    typedef vector<int> vi;
    typedef vector<vector<int>> vvi;
    typedef vector<long long> vl;
    typedef vector<pair<int, int>> vpi;
    typedef vector<pair<long long, long long>> vpl;
    typedef pair<int, int> pii;
    typedef pair <ll, ll> pll;


    int main(){
        string s;
        cin >>s;
        if(s== "SUN"){
            cout<<7;
        }else if(s== "MON"){
            cout<<6;
        }else if(s== "TUE"){
            cout<<5;
        }else if(s== "WED"){
            cout<<4;
        }else if(s== "THU"){
            cout<<3;
        }else if(s== "FRI"){
            cout<<2;
        }else if(s== "SAT"){
            cout<<1;
        }


        return 0;
    }






    /*
    int main(){
        double a ,b;
        cin>>a>>b;
        ll res =0;
        while(1){
            if(a > b){
                cout<<"t1\n";

                ll k = a /b;
                a -= (b*k);
                res+=k;
            }
            if(a < b){
                cout<<b;
                ll k = b/a;
                b -= (a*k);
                res+=k;
            }
            if(a ==b){
                res++;
                break;
            }
        }



        cout<<res;
        return 0;
    }
    */

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

ll N, M, A[3000], B[3000];
vector<ll> E[50];
bool used[50];

void dfs(ll v, ll a, ll b) {
  if(used[v]) return;
  used[v] = true;
  for(ll u : E[v]) if(!((u == a && v == b) || (u == b && v == a))) dfs(u, a, b);
}

int main(void) {
  cin >> N >> M;
  REP(i, 0, M) {
    cin >> A[i] >> B[i]; A[i]--; B[i]--;
    E[A[i]].push_back(B[i]);
    E[B[i]].push_back(A[i]);
  }

  ll ans = 0;
  REP(i, 0, M) {
    REP(i, 0, N) used[i] = false;
    dfs(0, A[i], B[i]);
    bool f = true;
    REP(j, 0, N) f = f && used[j];
    if(!f) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
void main() {
  import std.stdio, std.string, std.conv, std.algorithm;

  int x, y, z;
  rd(x, y, z);
  writeln((x - z) / (y + z));
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}


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

int main(){
    
    int n,r,maxv=-2000000000,minv=2000000000;
    cin >> n;

    for( int i=0; i<n; i++) {
        cin >> r;
        maxv = max( maxv, r - minv);
        minv = min( minv, r);
    }
    
    cout << maxv << endl;
    
    return 0;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  int s;
  cin>>s;
  bool first=false;
  bool second=false;
  int s1=s;
  int s2=s1/100;
  if(s2>=1&&s2<=12){
    first=true;
  }

  int s5=s%100;
  if(s5>=1&&s5<=12){
    second=true;
  }
  string ans;
  if(first==true&&second==true){
    ans="AMBIGUOUS";
  }else if(first==true&&second==false){
    ans="MMYY";
  }else if(first==false&&second==true){
    ans="YYMM";
  }else{
    ans="NA";
  }
  cout<<ans<<endl;    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef long long int ll;
typedef vector<pair<ll,ll> > vpl;
typedef vector<pair<int,int> > vpi;
typedef vector<ll> vec;
typedef map<ll,ll> mp;
ll GCD(ll a,ll b)
{
    if(a == 0)
    {
        return b;
    }
    return GCD(b%a,a);
}
int main()
{
    FastIO;
    int q = 1;
    //cin >> q;
    while(q--)
    {
        int n;
        cin >> n;
        int ara[n];
        for(int i =0;i<n;i++)
        {
            cin >> ara[i];
        }
        ll res = 0;
        int s = ara[0];
        for(int i =1;i<n;i++)
        {
            if(ara[i] < s)
            {
                res+=(s-ara[i]);
            }
            else
            {
                s = ara[i];
            }
        }
        cout << res << endl;
    }
}



Measured memory_bytes: 4432
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include<algorithm>
#define inf 0x3f3f3f3f
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef double dd;
const int N = 3e5+5;
const dd eps = 1e-8;
const int mod = 1e9+7;
int fa[N],siz[N];
int find(int x){return fa[x] == x ? x : fa[x] = find(fa[x]);}
void merge(int u,int v){
  int x = find(u),y = find(v);
  if(x != y){
    fa[x] = y;
    siz[y] += siz[x];
  }
}
int n,m,a,b;
int main(){
  // freopen("input.txt","r",stdin);
  cin>>n>>m;
  for(int i = 1;i <= n;i++) fa[i] = i,siz[i] = 1;
  for(int i = 1;i <= m;i++){
    cin>>a>>b;
    merge(a,b);
  }
  int ans = 0;
  for(int i = 1;i <= n;i++){
    ans = max(ans,siz[find(i)]);
  }
  cout<<ans<<endl;
  return 0;
}


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

const int N = 1 << 17;

int n, m, q;

vector<int> g[N];
int c[N], d[N], f[N], ver[N], dist[N], col[N];

void bfs(int idx) {
	deque<int> dq({ver[idx]});
	f[ver[idx]] = idx;
	d[ver[idx]] = dist[idx];

	int u;
	while (!dq.empty()) {
		u = dq.front(), dq.pop_front();
		c[u] = c[u] ? c[u] : col[idx];

		if (d[u])
		for (auto v: g[u]) if (d[v] < d[u] - 1 && f[v] != idx) {
			dq.push_back(v); 
			d[v] = d[u] - 1;
			f[v] = idx; } } }

int main() {
#ifdef HOME
	freopen("agc12b.in", "r", stdin);
	freopen("agc12b.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int a, b;

	cin >> n >> m;
	while (m--) {
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a); }

	cin >> q;
	for (int i = 1; i <= q; ++i)
		cin >> ver[i] >> dist[i] >> col[i];

	memset(d, 0xff, sizeof d);
	for (int i = q; i >= 1; --i)
		bfs(i);

	for (int i = 1; i <= n; ++i)
		cout << c[i] << '\n';

	return 0; }


Measured memory_bytes: 10232
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using static System.Console;
using static System.Math;

class Program
{
    static void Main()
    {
        var N = int.Parse(ReadLine());
        var d = ReadLine().Split().Select(int.Parse).ToArray();
        var ans = 0;
        for (int i = 0; i < N; i++)
        {
            for (int j = i + 1; j < N; j++)
            {
                ans += d[i] * d[j];
            }
        }
        WriteLine(ans);
    }
}


Measured memory_bytes: 13268
using System;
using System.Collections.Generic;
using System.Data.SqlTypes;
using System.IO.Pipes;
using System.Linq;

class Program
{ 
	public static int Main()
	{
    Scanner cin = new Scanner();
	  while (true)
	  {
	    int n = cin.nextInt(), m = cin.nextInt();
	    if (n == 0 && m == 0)
	    {
	      break;
	    }
      int[] nums = new int[n];
	    for (int i = 0; i < n; i++)
	    {
	      nums[i] = cin.nextInt();
	    }
	    int ans = 0, score = 0;
	    for (int i = 0; i < n; i++)
	    {
	      if (i < m)
	      {
	        score += nums[i];
	      }
	      else
	      {
	        ans = Math.Max(ans, score);
	        score -= nums[i - m];
	        score += nums[i];
	        ans = Math.Max(ans, score);
	      }
	    }
	    Console.WriteLine(ans);
	  }
	  return 0;
	}

}

class Scanner {
	string[] s;
	int i;

	char[] cs = new char[] { ' ' };

	public Scanner() {
		s = new string[0];
		i = 0;
	}

	public string next() {
		if (i < s.Length) return s[i++];
		do {
			s = Console.ReadLine().Split(cs, StringSplitOptions.RemoveEmptyEntries);
		} while ((s.Length == 1 && s[0] == "") || s.Length == 0);
		i = 0;
		return s[i++];
	}

	public int nextInt() {
		return int.Parse(next());
	}

	public long nextLong() {
		return long.Parse(next());
	}

	public double nextDouble() {
		return double.Parse(next());
	}

}

Measured memory_bytes: 6504
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)
typedef double D;
typedef complex<D> P;
typedef pair<P, P> L;
typedef vector<P> VP;
const D EPS = 1e-9;
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)
D dot(P a, P b) {return (conj(a)*b).X; }
D cross(P a, P b) {  return (conj(a)*b).Y;}
int ccw(P a, P b, P c) {
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1; 
  if (cross(b,c) < -EPS) return -1;
  if (dot(b,c)   < -EPS) return +2;
  if (norm(b) < norm(c)) return -2;  
  return 0; 
}
P crosspointLL(P a1, P a2, P b1, P b2) {
  D d1 = cross(b2-b1, b1-a1);
  D d2 = cross(b2-b1, a2-a1);
  if (EQ(d1, 0) && EQ(d2, 0)) return a1;
  if (EQ(d2, 0)) throw "kouten ga nai";
  return a1 + d1/d2 * (a2-a1);
}
VP convexCut(const VP& ps, P a1, P a2) {
  int n = ps.size();
  VP ret;
  rep(i,n) {
    int ccwc = ccw(a1, a2, ps[i]);
    if (ccwc != -1) ret.push_back(ps[i]);
    int ccwn = ccw(a1, a2, ps[(i + 1) % n]);
    if (ccwc * ccwn == -1) ret.push_back(crosspointLL(a1, a2, ps[i], ps[(i + 1) % n]));
  }
  return ret;
}
D area(const VP& ps) {
  D a = 0;
  rep (i, ps.size()) a += cross(ps[i], ps[(i+1) % ps.size()]);
  return a / 2;
}
VP voronoiCell(P p, const VP& ps, const VP& outer) {
  VP cl = outer;
  rep (i, ps.size()) {
    if (EQ(norm(ps[i]-p), 0)) continue;
    P h = (p+ps[i])*0.5;
    cl = convexCut(cl, h, h + (ps[i]-h)*P(0,1) );
  }
  return cl;
}
int n,m;
VP v1,v2;
double x,y;
int main(){
  while(cin>>n>>m,n){
    v1.clear();
    v2.clear();
    rep(i,n){
      cin>>x>>y;
      v1.push_back(P(x,y));
    }
    rep(i,m){
      cin>>x>>y;
      v2.push_back(P(x,y));
    }
    rep(i,m){
      VP t=voronoiCell(v2[i],v2,v1);
      printf("%.10f\n",area(t));
    }
  }
}

Measured memory_bytes: 3160
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;


const int INF = (1<<30) - 1;
const D EPS = 1e-11;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

D dot(P a, P b) {
    return (conj(a)*b).X;
}

D cross(P a, P b) {
    return (conj(a)*b).Y;
}

int ccw(P a, P b, P c) {
    b -= a;	c -= a;
    //3???????????´???????????????
    if (cross(b,c) > EPS) return +1;	// counter clockwise
    if (cross(b,c) < -EPS) return -1;	// clockwise
    //3???????????´???????????????
    if (dot(b,c) < -EPS) return +2;		// c--a--b on line
    if (norm(b) < norm(c)) return -2;	// a--b--c on line or a==b
    return 0;							// a--c--b on line or a==c or b==c
}

bool isecSS(P a1, P a2, P b1, P b2) {
    return ccw(a1, a2, b1)*ccw(a1, a2, b2) <= 0 &&
    ccw(b1, b2, a1)*ccw(b1, b2, a2) <= 0;
}

P crosspointLL(P a1, P a2, P b1, P b2) {
    D d1 = cross(b2-b1, b1-a1);
    D d2 = cross(b2-b1, a2-a1);
    return a1 + d1 / d2 * (a2-a1);
}

int N;

void solve(){
    vector<L> lines(N);
    
    for(int i=0; i<N; i++){
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        lines[i] = L(P(x1, y1), P(x2, y2));
    }
    
    int ans = 1;
    for(int i=0; i<N; i++){
        ans++;
        vector<P> isects;
        for(int j=0; j<i; j++){
            L l1 = lines[i];
            L l2 = lines[j];
            
            if(isecSS(l1.first, l1.second, l2.first, l2.second)){
                P p = crosspointLL(l1.first, l1.second, l2.first, l2.second);
                if(EQ(abs(p.X), 100) || EQ(abs(p.Y), 100)) continue;
                
                bool add = true;
                for(int i=0; i<isects.size(); i++){
                    if(EQ(isects[i].X, p.X) && EQ(isects[i].Y, p.Y))
                        add = false;
                }
                if(add)
                    isects.push_back(p);
            }
        }
        ans += isects.size();
    }
    
    cout << ans << endl;
}

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    
    while(cin>>N, N)
        solve();
    
    return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 100000

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

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int H,W;
    cin >> H >> W;
    vector<string> m(H);
    for(int i = 0; i < H; i++) cin >> m[i];
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            int count = 0;
            if(m[i][j] == '.'){
            for(int x = -1; x <= 1; x++){
                for(int y = -1; y <= 1; y++){
                    int X = j + x;
                    int Y = i + y;
                    if(0 <= X && X < W && 0 <= Y && Y < H){
                        if(m[Y][X] == '#') count++; 
                    }
                }
            }
            m[i][j] = (char)('0' + count);
            }
            cout << m[i][j];
        }
        cout << endl;
    }
    return 0;
}


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

using namespace std;

int main()
{
	string s, ans;

	for (int i = 0;i < 3;i++)
	{
		cin >> s;
		ans.push_back(s[0] + 'A' - 'a');
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
main = do
  a <- readLn
  b <- readLn
  c <- readLn
  d <- readLn
  let as = zipWith (*) [0..a] [500, 500..]
  let bs = zipWith (*) [0..b] [100, 100..]
  let cs = zipWith (*) [0..c] [50, 50..]
  print $ length $ filter (d == ) [ (x + y + z) | x <- as, y <- bs, z <- cs ]

Measured memory_bytes: 1020
import sys
def input(): return sys.stdin.readline().strip()

def f(a):
    """
    (0 ^ 1 ^ 2 ^ ... ^ a)を返す関数。
    各ビットにおける1の個数をカウントしなくても、
            (2k) ^ (2k+1) = 0
    であることを使えばO(1)で求まる。例えば
    0 ^ 1 ^ 2 ^ 3 ^ 4 ^ 5 ^ 6 = (0 ^ 1) ^ (2 ^ 3) ^ (4 ^ 5) ^ 6
                              =    1    ^    1    ^    1    ^ 6
                              =    1    ^    6
    """
    if a % 4 == 3: return 0
    if a % 4 == 1: return 1
    if a % 4 == 2: return 1 ^ a
    if a % 4 == 0: return a


def main():
    A, B = map(int, input().split())
    print(f(A - 1) ^ f(B))


if __name__ == "__main__":
    main()


Measured memory_bytes: 38384
import java.util.Scanner;
class Main{
	public static void main(String[] a){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int num1 = scan.nextInt(), num2 = scan.nextInt();
			if(num1 < num2){
				int sub = num1;
				num1 = num2;
				num2 = sub;
			}
			int div = euclid(num1, num2);
			System.out.println(div + " " + num1 / div * num2);
		}
	}
	static int euclid(int num1, int num2){
		if(num1 % num2 == 0) return num2;
		return euclid(num2, num1 % num2);
	}
}

Measured memory_bytes: 17216
#include <iostream>

using namespace std;

int main () {

    int64_t N;
    cin >> N;

    if(N % 2) {
        cout << 0 << endl;
        return 0;
    }

    int64_t count = 0;
    N /= 2;
    while(N) {
        N /= 5;
        count += N;
    }
    cout << count << endl;

    return 0;
}

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

int main() {
  string S1, S2, T;
  cin >> S1 >> T;
  S2 = S1;

  int N = S2.size() - T.size() + 1;
  //stack<string> ans;
  vector<string> ans;

  if ( N < 1) cout << "UNRESTORABLE" << endl;

  else{
    rep(i, N){
      S1 = S2;
      bool judge = true;
      rep(j, T.size()){
        if(S2.at(i + j) != '?' && S2.at(i + j) != T.at(j))
        judge = false;
      }
      if(judge){
        rep(j, T.size()){
          S1.at(i + j) = T.at(j);
          //ans.push(S1);
        }
        rep(k, S1.size()){
          if(S1.at(k) == '?') S1.at(k) = 'a';
        }
        ans.push_back(S1);
      }
    }


    if(ans.size() == 0) cout <<  "UNRESTORABLE" << endl;
    else{
      /*cout <<  ans.size() << endl;
      S1 = ans.top();
      rep(i, S1.size()){
      if(S1.at(i) == '?') S1.at(i) = 'a';
    }
    cout << S1 << endl;*/
    sort(ans.begin(), ans.end());
    cout << ans.at(0) << endl;
  }
}
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cctype>
#include <stdlib.h>
#include <string>

using namespace std;

int main(void){
	while(1){
		int sum=0,n;
		string str;
		cin>>str;
		if(atoi(str.c_str())==0)
			break;
		n = str.size();
		for(int i=0;i<n;i++){
			sum += str[i] - '0';
		}
		cout<<sum<<endl;
	}
  return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

bool between(int a, int b, int c){
	return a <= b && b < c;
}

void paint(
	int x, int y, const vector<string> &field,
	vector< vector<int> > &canvas)
{
	const int W = field[0].size(), H = field.size();
	if(!between(0, x, W) || !between(0, y, H)){ return; }
	if(field[y][x] != '.' || canvas[y][x]){ return; }
	canvas[y][x] = 1;
	for(int i = 0; i < 4; ++i){
		paint(x + dx[i], y + dy[i], field, canvas);
	}
}

int main(){
	while(true){
		int w, h;
		cin >> w >> h;
		if(w == 0 && h == 0){ break; }
		vector<string> field(h);
		for(int i = 0; i < h; ++i){ cin >> field[i]; }
		vector< vector<int> > white(h, vector<int>(w));
		vector< vector<int> > black(h, vector<int>(w));
		for(int y = 0; y < h; ++y){
			for(int x = 0; x < w; ++x){
				for(int i = 0; i < 4; ++i){
					if(field[y][x] == 'W'){
						paint(x + dx[i], y + dy[i], field, white);
					}else if(field[y][x] == 'B'){
						paint(x + dx[i], y + dy[i], field, black);
					}
				}
			}
		}
		int wsum = 0, bsum = 0;
		for(int y = 0; y < h; ++y){
			for(int x = 0; x < w; ++x){
				if(white[y][x] == black[y][x]){ continue; }
				if(white[y][x]){ ++wsum; }
				if(black[y][x]){ ++bsum; }
			}
		}
		cout << bsum << " " << wsum << endl;
	}
	return 0;
}

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

int main()
{
 	int N;
  	cin >> N;
  
  	vector< pair<int, int> > BA;
      
  	for (int n = 0; n < N; n++) {
      int a, b;
      cin >> a >> b;
      BA.push_back( make_pair(b, a) );
    }
 
  	sort(BA.begin(), BA.end());

  	int ok = 1;
  	int sum = 0;
  	for (int n = 0; n < N; n++) {
 		sum += BA[n].second;
 		if (sum > BA[n].first) {
          ok = 0;
          break;
        }
    }
  
  	if (ok)
		cout << "Yes" << endl;
  	else
		cout << "No" << endl;
  
	return 0;
}

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

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

  vector<int> v(n+1, 0);
  rep(i, m){
    int x, y;
    cin >> x >> y;
    v[x]++;
    v[y]++;
  }

  rep(i, n+1){
    if(i == 0) continue;
    cout << v[i] << endl;
  }
}

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

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

	int res=0;
	for (int i = 0;i < n;i++) {
		int l, r;
		cin >> l >> r;
		res += r - l + 1;
	}
	cout << res << endl;

}


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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/e.in", "r", stdin);
//  freopen("../IO/e.out", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}

int mp[1 << 11][1 << 11];
void solve(std::istream &in, std::ostream &out) {
  int n, m;
  in >> n >> m;
  mp[1][1] = 1;
  for (int len = 1; len < max(n, m); ++len) {
    int L = 1 << len;
    mp[L][L] = 1;
    for (int i = 1; i < L; ++i)
      for (int j = 1; j < L; ++j)
        mp[i + L][j + L] = mp[i + L][j] = mp[i][j + L] = mp[i][j];
  }
  for (int i = 1; i < 1 << n; ++i, out << '\n')
    for (int j = 1; j < 1 << m; ++j)
      out << char('0' + mp[i][j]);
    out << '\n';
}


Measured memory_bytes: 11520
from collections import deque
s = input()
q = int(input())

dq = deque(s)
rev = False

for _ in range(q):
    t = list(input().split())
    if t[0] == "1":
        rev = not rev
    elif t[0] == "2":
        f = t[1]
        c = t[2]
        if f == "1":
            if rev:
                dq.append(c)
            else:
                dq.appendleft(c)
        else:
            if rev:
                dq.appendleft(c)
            else:
                dq.append(c)
                
if rev:
    print("".join(list(dq)[::-1]))
else:
    print("".join(list(dq)))
            


Measured memory_bytes: 10100
#include <bits/stdc++.h>
#include <tr1/unordered_map>
#include <tr1/unordered_set>
using namespace std::tr1;
using namespace std;
/* cau troi cho Garena nhap de con Bach */
#define FSYNC ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define int long long
#define endl '\n'
#define inf 0x3f3f3f3f
#define lb lower_bound
#define pob pop_back
#define ub upper_bound
#define ite ::iterator
#define db(x) {cout <<"#db " << x << endl;}
#define here() {cout <<"here \n";}
#define mod 1000000007
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int MOD = 1e9 + 7;
const int N = 2e5+5;


signed main(){
	int n;cin >> n;
	if(n%2 == 0) cout << n;
	else cout << n*2;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    long K = scan.nextLong();
    long[] num = new long[100001];
    
    for(int i = 0; i < N; i++){
      int A = scan.nextInt();
      int B = scan.nextInt();
      num[A] += B;
    }
    
    long n = 0;
    int ans = 0;
    for(int i = 1; i < 100001; i++){
      n += num[i];
      if(n >= K){
        ans = i;
        break;
      }
    }
    System.out.println(ans);
  }
}

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

int main(void)
{
    int n = 0;
    int m = 0;
    cin >> n >> m;

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

    int suma = 0;
    for (int i = 0; i < m; ++i)
    {
        suma += a[i];
    }

    if (suma <= n)
    {
        cout << n - suma;
    }
    else
    {
        cout << -1;
    }

    return 0;
}

Measured memory_bytes: 3600
N, K = map(int, input().split())
if (N - 1) * (N - 2) // 2 < K:
    print(-1)
else:
    M = (N - 1) + ((N - 1) * (N - 2) // 2 - K)
    print(M)
    for i in range(N - 1):
        print(i + 1, N)
    count = M - N + 1
    now = 1
    while count > 0:
        for i in range(now, N - 1):
            print(now, i + 1)
            count -= 1
            if count == 0:
                break
        now += 1

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

int main()
{
  long long n,m;
  cin>>n>>m;
  long long ansx=0LL,ansy=0LL;
  for(long long i=1LL;i<=n;i++){
    long long x;
    cin>>x;
    ansx+=(((i-1LL)-(n-i))*x)%1000000007;
    ansx%=1000000007;
  }
  for(long long i=1LL;i<=m;i++){
    long long y;
    cin>>y;
    ansy+=(((i-1LL)-(m-i))*y)%1000000007;
    ansy%=1000000007;
  }
  cout<< (ansx*ansy)%1000000007 <<endl;
}



Measured memory_bytes: 256
fn main() {
  let _: usize = read();
  let mut vec: Vec<i64> = read_vec();
  
  vec.sort();
  let mut vec: Vec<i64> = vec.iter().scan(0, |a, &x| {*a+=x; Some(*a)}).collect();
  vec.reverse();
  
  let ans = 1 + vec.windows(2).map(|w| if w[0]-w[1]<=w[1]*2 {Some(1)} else {None}).take_while(|o| o.is_some()).count();
  println!("{}", ans);
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  buf.trim().split_whitespace().map(|t| t.parse::<T>().ok().unwrap()).collect()
}

fn read<T: std::str::FromStr>() -> T {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  buf.trim().parse::<T>().ok().unwrap()
}

Measured memory_bytes: 8444
from operator import mul
from functools import reduce
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N = int(input())
str_dict = {}
for n in range(N):
  l = ''.join(sorted(input()))
  if l in str_dict:
    str_dict[l] += 1
  else:
    str_dict[l] = 1
print(sum([cmb(v,2) if v>= 2 else 0 for v in str_dict.values()]))

Measured memory_bytes: 18340
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

using cat = long long;

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	string S;
	cin >> N >> S;
	for(int k = 0; k < 4; k++) {
		vector<int> ans(N, 0);
		ans[0] = k&1, ans[1] = k>>1;
		for(int i = 2; i < N; i++) ans[i] = ans[i-2]^ans[i-1]^(S[i-1] == 'x');
		if(ans[0]^ans[N-1]^ans[N-2]^(S[N-1] == 'x')) continue;
		if(ans[1]^ans[0]^ans[N-1]^(S[0] == 'x')) continue;
		string ansS;
		for(int i = 0; i < N; i++) ansS += ans[i] ? 'W' : 'S';
		cout << ansS << "\n";
		return 0;
	}
	cout << "-1\n";
}

// look at my code
// my code is amazing


Measured memory_bytes: 1096
#include<bits/stdc++.h>
#include<math.h>
#define ll long long int
#define ve vector<int>
#define vl vector<long long int>
#define all(a) a.begin(),a.end()
using namespace std;
ll inf= 998244353;

int jou(int x,int y){
  ll A=1;
  for(int i=1;i<=y;i++){
    A*=x;
    A%=inf;
  }
  return A;
}

int main(){
  int n;
  ll A=1;
  cin>>n;
  vl d(n),L(n-1);
  for(int i=0;i<n;i++){
    cin>>d[i];
  }
  for(int i=0;i<n;i++){
    L[d[i]]++;
  }
  for(int i=0;i<n-2;i++){
    A=(A*jou(L[i],L[i+1]));
    A%=inf;
  }
  if(d[0]!=0||L[0]!=1) cout<<0<<endl;
  else cout<<A<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<long,long>
#define INF 1000000000000000000
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<int, int> mp;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
int gcd2(int a, int b) {
	if (a < b)swap(a, b);
	while (a%b != 0) {
		int t = b; b = a % b; a = t;
	}
	return b;
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
class Union_Find {
private:
	vector<int> par;
	vector<int> rank;
public:
	Union_Find(int n) {
		rep(i, n) {
			par.push_back(i);
			rank.push_back(0);
		}
	}
	int find(int x) {
		if (par.at(x) == x) return x;
		else return par.at(x) = find(par.at(x));
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank.at(x) < rank.at(y)) {
			par.at(x) = y;
		}
		else {
			par.at(y) = x;
			if (rank.at(x) == rank.at(y)) rank.at(x)++;
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
};

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, X; cin >> N >> X;
	vector<int>x(N); rep(i, N) { cin >> x[i]; x[i] = abs(X - x[i]); }
	int ans = x[0];
	for (int i = 1; i < N; i++) {
		ans = gcd2(ans, x[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
// 偶奇で数えて登場回数最大以外を書き換えるんじゃないの
// 書き換える先が偶奇で同じになってしまったら二番目に大きいやつで勝負してぶつける
// コーナーケース注意（二番目が存在しない）
// 実装がクソ
package main

import (
	"fmt"
	"sort"
)

type KV struct {
	k, v int
}

type KVS []KV

func (kvs KVS) Len() int {
	return len(kvs)
}

func (kvs KVS) Less(i, j int) bool {
	return kvs[i].v > kvs[j].v
}

func (kvs KVS) Swap(i, j int) {
	kvs[i], kvs[j] = kvs[j], kvs[i]
}

func main() {
	var N int
	fmt.Scan(&N)
	evenMap, oddMap := make(map[int]int), make(map[int]int)
	for i := 0; i < N; i++ {
		var V int
		fmt.Scan(&V)
		if i%2 == 0 {
			oddMap[V]++
		} else {
			evenMap[V]++
		}
	}
	var evenKVSS, oddKVSS KVS
	for k, v := range evenMap {
		evenKVSS = append(evenKVSS, KV{k: k, v: v})
	}
	for k, v := range oddMap {
		oddKVSS = append(oddKVSS, KV{k: k, v: v})
	}
	sort.Sort(evenKVSS)
	sort.Sort(oddKVSS)
	if len(evenKVSS) == 1 && len(oddKVSS) == 1 {
		if evenKVSS[0].k == oddKVSS[0].k {
			// 登場する数が全て同じなのでどっちかをまるっと変更する
			fmt.Println(N / 2)
		} else {
			// そのまんまでいい
			fmt.Println(0)
		}
	} else if len(evenKVSS) == 1 || len(oddKVSS) == 1 {
		// 2つ以上あるやつを変更したいがこれもkで決まるな...めんどくせ
		if evenKVSS[0].k == oddKVSS[0].k {
			if len(evenKVSS) == 1 {
				fmt.Println(N/2 - oddKVSS[1].v)
			} else {
				fmt.Println(N/2 - evenKVSS[1].v)
			}
		} else {
			if len(evenKVSS) == 1 {
				fmt.Println(N/2 - oddKVSS[0].v)
			} else {
				fmt.Println(N/2 - evenKVSS[0].v)
			}
		}
	} else {
		if evenKVSS[0].k == oddKVSS[0].k {
			// 数が被るので少ないほうをまるっと変更する
			if evenKVSS[0].v == oddKVSS[0].v {
				// しょうがないので二番目に大きい方で比較する
				if evenKVSS[1].k == oddKVSS[1].k {
					// どっちかを最大、他方を二番目のやつを採用する
					fmt.Println(N/2 - evenKVSS[0].v + N/2 - oddKVSS[1].v)
				} else {
					// 二番目のやつの登場回数が多い方を採用する
					if evenKVSS[1].v > oddKVSS[1].v {
						fmt.Println(N/2 - evenKVSS[1].v + N/2 - oddKVSS[0].v)
					} else if evenKVSS[1].v < oddKVSS[1].v {
						fmt.Println(N/2 - evenKVSS[0].v + N/2 - oddKVSS[1].v)
					} else {
						// なんだこれ
						// どっちかを最大、他方を二番目におおきいやつ
						fmt.Println(N/2 - evenKVSS[0].v + N/2 - oddKVSS[1].v)
					}
				}
			} else {
				// 登場回数の少ない方は二番目のやつを採用
				if evenKVSS[0].v > oddKVSS[0].v {
					fmt.Println(N/2 - evenKVSS[0].v + N/2 - oddKVSS[1].v)
				} else {
					fmt.Println(N/2 - evenKVSS[1].v + N/2 - oddKVSS[0].v)
				}
			}
		} else {
			// どちらも最大のやつはかぶらないのでどちらもそれ以外のやつを最大のやつに合わせる
			fmt.Println(N/2 - evenKVSS[0].v + N/2 - oddKVSS[0].v)
		}
	}
}

// 8
// 2 5 2 9 1 5 3 5


Measured memory_bytes: 11648
#include<bits/stdc++.h>
#define long long long
#define N 100005
using namespace std;
long arr[N],n;
vector<long>v;
map<long,long>fr;
int main()
{
    ///ofstream cout("out.txt");
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(long i=1;i<=n;i++)
    {
        cin>>arr[i];
        fr[arr[i]]++;
        if(fr[arr[i]]==2)
        {
            v.push_back(arr[i]);
            fr[arr[i]]=0;
        }
    }
    sort(v.begin(),v.end());
    if(v.size()<2)
    {
        cout<<0<<endl;
    }
    else
    {
        cout<<v[v.size()-1]*v[v.size()-2]<<endl;
    }
    return 0;
}


Measured memory_bytes: 7296
count :: [Int] -> [Int] -> [Int] -> Int -> Int
count [] b c prev = 0
count (a0:a1) b c prev
    | a0 == prev + 1  = b !! a0 + c !! prev + count a1 b c a0
    | otherwise         = b !! a0 + count a1 b c a0  



main = do
    getLine 
    a <- map read . words <$> getLine
    b <- map read . words <$> getLine
    c <- map read . words <$> getLine
    let a' = map (+(-1)) a
        c' = map (+(-1)) c
    print (count a' b c 100)


Measured memory_bytes: 764
n = int(input())
s = []
t = []
for i in range(n):
    st = input().split()
    s.append(st[0])
    t.append(int(st[1]))
x = input()
check = 0
time = 0

for i in range(n):
    if check == 1:
        time += t[i]
    if s[i] == x:
        check += 1


print(time)


Measured memory_bytes: 3060