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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


void solve() {
    int i,j,k,l,r,x,y; string s;
    bool exit = false;
    int N,A,B;
    cin>>N;
    
    if(N==2){
        cin>>A>>B;
    }
    if(N==1){
        cout<<"Hello World"<<endl;
    }else{
        cout<<A+B<<endl;
    }
    /*cin>>N;
    vector<ll> V;
    FOR(x,N+1) {
            FOR(y,N+1) {
                    ll ret=1;
                    FOR(i,x) ret*=2;
                    FOR(i,y) ret*=5;
                    V.push_back(ret);
            }
    }
    sort(ALL(V));
    FORR(v,V) cout<<v<<endl;*/
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int K,N;
  cin >> K >> N;
  vector<ll> A(N+1);
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  A[N] = K + A[0];
  ll ans = inf;
  for(int i=0; i<N; i++){
    chmin(ans,K-(A[i+1]-A[i]));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp>
#define priority_queue __gnu_pbds::priority_queue
typedef long long LL;
typedef long double LD;
typedef unsigned int ui;
typedef unsigned long long ul;
#define ri register int
#define pb push_back
#define fi first
#define se second
#define mid ((l + r) >> 1)
#define ls (i << 1)
#define rs (i << 1 | 1)
#define enum(i, j, k) for(int i = j; i <= k; i ++)
#define FO(x) { freopen(#x".in", "r", stdin); freopen(#x".out", "w", stdout); }
using namespace std;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef vector<int> vi;
#define ae(x) for(node *p = h[x]; p; p = p->nxt)
#define G \
	struct node { int v; node *nxt; } e[maxm], *h[maxn]; int z;\
	void adde(int u, int v) { e[++z].v = v; e[z].nxt = h[u]; h[u] = &e[z]; }\
	void addrev(int u, int v) { adde(u, v); adde(v, u); }
#define W \
	struct node { int v, w; node *nxt; } e[maxm], *h[maxn]; int z;\
	void adde(int u, int v, int w) { e[++z].v = v; e[z].w = w; e[z].nxt = h[u]; h[u] = &e[z]; }\
	void addrev(int u, int v, int w) { adde(u, v, w); adde(v, u, w); }
inline int _() // ret >= 0
{
	int ret = 0; char ch = getchar();
	while(ch < '0' || ch > '9') ch = getchar();
	do { ret = ret * 10 + ch - '0'; ch = getchar(); } while('0' <= ch && ch <= '9');
	return ret;
}
inline void _(int x) // x >= 0
{
	if(x < 10) { putchar(x + '0'); return ; }
	_(x / 10); putchar(x % 10 + '0');
}
void What_are_you_doing_at_the_end_of_the_world_Are_you_busy_Can_you_save_us()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(16);
}
/* Default Code Ends Here. */

#define maxn 100100
int n, k;
int a[maxn];
void no()
{
	cout << "Impossible";
	exit(0);
}
void yes()
{
	cout << "Possible\n";
}

int main()
{
	What_are_you_doing_at_the_end_of_the_world_Are_you_busy_Can_you_save_us();
	
	cin >> n >> k;
	enum(i, 1, n)
		cin >> a[i];
	int pos = 0;
	enum(i, 1, n - 1)
		if(a[i] + a[i + 1] >= k)
		{
			pos = i;
			break;
		}
	if(!pos)
		no();
	yes();
	enum(i, 1, pos - 1)
		cout << i << endl;
	for(int i = n - 1; i >= pos; i --)
		cout << i << endl;
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define INF 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int f[100][12];
int p[101][11];
int fu[11];
int bes=-INF;

void dfs(int v){
	if(v==10){
		int now=0;
		int ct=0;
		for(int i=0;i<10;i++){
			ct+=fu[i];
		}
		if(ct==0)return;
		for(int i=0;i<n;i++){
			int cnt=0;
			for(int j=0;j<10;j++){
				if(f[i][j]==1 && fu[j]==1)cnt++;
			}
			now+=p[i][cnt];
		}
		bes=max(bes,now);
	}else{
		fu[v]=1;
		dfs(v+1);
		fu[v]=0;
		dfs(v+1);
	}
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		for(int j=0;j<5;j++){
			scanf("%d %d",&f[i][j*2],&f[i][j*2+1]);
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<=10;j++){
			scanf("%d",&p[i][j]);
		}
	}
	dfs(0);
	printf("%d\n",bes);
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
    string A,B;
    cin >> A >> B;
    int AL=A.length(),BL=B.length();
    if(AL>BL) cout << "GREATER" << endl;
    else if(AL<BL) cout << "LESS" << endl;
    else{
        int check=0;
        rep(i,AL){
            if(A[i]>B[i]) cout << "GREATER" << endl,check=1;
            if(A[i]<B[i]) cout << "LESS" << endl,check=1;
            if(check==1) break;
        }
        if(check==0) cout << "EQUAL" << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
 
class Main {
    public static void main(String[] args) {
      
        Scanner sc = new Scanner(System.in);
        int nam[] = new int[3];

      for(int i = 0; i < 3 ;i++){
        nam[i] = sc.nextInt();
      }
       Arrays.sort(nam);
      
      System.out.print(nam[0]+nam[1]);
      
      

    }
}

Measured memory_bytes: 23508
use std::io::*;
use std::str::FromStr;

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

fn main() {
    for _ in 0..3 {
        let s = read::<String>().chars().collect::<Vec<char>>();
        let c = (s[0] as u8 - ('a' as u8 - 'A' as u8)) as char;
        print!("{}", c);
    }
    println!("");
}


Measured memory_bytes: 4476
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

class LCA{
public:
    ll V; // ????????°
    vector<vector<ll>> T; // Tree
    vector<pll> ET; // Euler Tour ET(dep, n)
    vector<int> visited;
    vector<ll> Ind; // ????????????????????????ET???index?????????
    
    ll N; // SegTree???????´???°
    vector<pll> node; // SegTree
    
    LCA(ll V):V(V){
        T.resize(V); Ind.resize(V);
    }
    
    void add_edge(ll u,ll v){
        T[u].emplace_back(v);
        T[v].emplace_back(u);
    }
    
    void fit(){
        visited.clear(); visited.assign(V,0);
        dfs(0,0);
        ll N_ = ET.size();
        N = 1;
        while(N < N_) N*=2;
        node.clear(); node.assign(2*N - 1,make_pair(INF,INF));
        for(int i = 0; i < N_;i++) node[N-1+i] = ET[i];
        for(int k = N - 2; k>=0;k--) node[k] = min(node[2*k+1],node[2*k+2]);
    }
    
    void dfs(ll n,ll dep){
        visited[n] = 1;
        ET.emplace_back(make_pair(dep, n));
        Ind[n] = (int)ET.size() - 1;
        for(auto next:T[n]){
            if(visited[next] == 1)continue;
            dfs(next,dep +1);
            ET.emplace_back(make_pair(dep,n));
        }
    }
    
    
    pll RMQ(ll a,ll b){ return RMQ(a,b,0,0,N); }
    pll RMQ(ll a,ll b,ll k,ll l, ll r){
        if(r <= a || b <= l)return make_pair(INF,INF);
        if(a <= l && r <= b)return node[k];
        auto vl = RMQ(a,b,2*k+1,l,(l+r)/2);
        auto vr = RMQ(a,b,2*k+2,(l+r)/2,r);
        return min(vl,vr);
    }
    
    ll solve(ll s,ll t){
        ll idx1 = Ind[s],idx2 = Ind[t];
        if(idx1 > idx2) swap(idx1,idx2);
        
        return RMQ(idx1,idx2+1).second;
    }
};

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll n; cin >> n;
    
    LCA lca(n);
    
    for(int i = 0; i < n;i++){
        ll k; cin >> k;
        for(int j = 0; j < k;j++){
            ll c; cin >> c;
            lca.add_edge(i, c);
        }
    }
    
    lca.fit();
    
    ll q; cin >> q;
    for(int i = 0; i < q;i++){
        ll u, v; cin >> u >> v;
        cout << lca.solve(u,v) << endl;
    }
    return 0;
}

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

#define rep(i,l,n) for(int (i)=(l);(i)<(n);(i)++)
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)

int main(){
	int N; scanf("%d",&N);
	long A[N],count[N];
	rep(i,0,N) count[i]=0;
	rep(i,0,N){
		scanf("%ld",&A[i]);
		A[i]--;
		count[A[i]]++;
	}
	long maxcount=0;
	rep(i,0,N) maxcount+=(count[i]*(count[i]-1))/2;
	rep(i,0,N){
		printf("%ld ",maxcount-count[A[i]]+1);
	}
	return 0;
}
	

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

using namespace std;
long long sum;
int n, a[100001];
int main(){
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        sum += abs(a[i] - a[i - 1]);
    }
    sum += abs(0 - a[n]);
    for(int i = 1; i < n; i++){
        sum -= (abs(a[i] - a[i - 1]) + abs(a[i + 1] - a[i]));
        sum += abs(a[i + 1] - a[i - 1]);
        cout << sum << '\n';
        sum += (abs(a[i] - a[i - 1]) + abs(a[i + 1] - a[i]));
        sum -= abs(a[i + 1] - a[i - 1]);
    }
    sum -= (abs(a[n] - a[n - 1]) + abs(0 - a[n]));
    sum += abs(0 - a[n - 1]);
    cout << sum;
}


Measured memory_bytes: 1664
// https://atcoder.jp/contests/arc086/tasks/arc086_b

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N;
  cin >> N;

  VL as(N);
  rep(i, N) cin >> as[i];

  ll max_i = -1;
  ll max_a = -INF;
  ll min_i = -1;
  ll min_a = INF;

  rep(i, N) {
    ll a = as[i];
    if (chmax(max_a, a)) max_i = i;
    if (chmin(min_a, a)) min_i = i;
  }

  VPL res(0);

  if (abs(max_a) >= abs(min_a)) {
    // 全部正にする
    rep(i, N) res.emplace_back(max_i, i);
    rep(i, N - 1) res.emplace_back(i, i + 1);
  } else {
    // 全部負にする
    rep(i, N) res.emplace_back(min_i, i);
    repr(i, N - 1) res.emplace_back(i + 1, i);
  }

  cout << res.size() << endl;

  for (auto pa : res) {
    print_ints({pa.fi + 1, pa.se + 1});
  }
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

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


const long long int mod = 1000000007;
const long long int INF = 99999999999999999;




long long int N,L[100],sum=0,res=INF;


int main()
{
    cout << fixed << setprecision(18);
    cin>>N;
    for(long long int i = 1; i*i <= N; i++){
        if(N%i==0){
            res=min(res,i-2+(N/i));
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sOut = "";
            string sS = Console.ReadLine().Trim();
            sOut += sS.Substring(0, 1);
            sS = Console.ReadLine().Trim(); ;
            sOut += sS.Substring(1, 1);
            sS = Console.ReadLine().Trim(); ;
            sOut += sS.Substring(2, 1);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            // 出力
            Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
}


Measured memory_bytes: 11220
using System;

class Program {
  static void Main() {
    var a = int.Parse(Console.ReadLine());
    var b = int.Parse(Console.ReadLine());
    var c = int.Parse(Console.ReadLine());
    var d = int.Parse(Console.ReadLine());
    var p = int.Parse(Console.ReadLine());
    var x = a * p;
    var t = p - c > 0 ? p - c : 0;
    var y = b + t * d;
    Console.WriteLine(Math.Min(x, y));
  }
}


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

char intoch(int num){
  switch(num){
    case 0: return 'S';break;
    case 1: return 'H';break;
    case 2: return 'C';break;
    case 3: return 'D';break;
  }
}
int chtoin(char ch){
  switch(ch){
    case 'S': return 0;break;
    case 'H': return 1;break;
    case 'C': return 2;break;
    case 'D': return 3;break;
  }
}
int main(){
  int n,num;
  char ch;
  cin>>n;
  int card[4][13];/*????????????0?????????1?????????2?????????3*/
  for(int i=0;i<4;i++)
    for(int j=0;j<13;j++) card[i][j]=0;

  for(int i=0;i<n;i++){
    cin>>ch>>num;
    card[chtoin(ch)][num-1]=1;
  }

  for(int i=0;i<4;i++){
    for(int j=0;j<13;j++){
      if(card[i][j]==0) cout<<intoch(i)<<" "<<j+1<<"\n";
    }
  }
}

Measured memory_bytes: 3076
a, b, h, m = gets.split.map(&:to_i)

hour_angle = 30 * h + m / 2.0
minute_angle = 6 * m

hour_x = a * Math.cos(hour_angle / 180.0 * Math::PI)
hour_y = a * Math.sin(hour_angle / 180.0 * Math::PI)
minute_x = b * Math.cos(minute_angle / 180.0 * Math::PI)
minute_y = b * Math.sin(minute_angle / 180.0 * Math::PI)
puts Math.sqrt((hour_x - minute_x).abs ** 2 + (hour_y - minute_y).abs ** 2)


Measured memory_bytes: 14560
#include<cstdio>
using namespace std;
int main()
{
    int m,n;
    scanf("%d%d",&m,&n);
    for(int i=0;i<=m;i++)
    {
        for(int j=0;j<=m;j++)
        {
            for(int k=0;k<=m,i+j+k<=m;k++)
            {
                if(i+j+k==m && i*1000+j*5000+k*10000==n)
                {
                    printf("%d %d %d\n",k,j,i);
                    return 0;   
                }
            }
        }
    }
    printf("-1 -1 -1\n");
    return 0;
}


Measured memory_bytes: 128
from fractions import gcd
# from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import fractions
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
# input = sys.stdin.readline


def main():
    n = int(input())
    s = input()
    c = Counter(s)
    ansm=1
    for i in range(26):
        v = chr(ord("a") + i)
        ansm *= (c[v] + 1)
        ansm%=MOD
    print((ansm -1 + MOD)%MOD)





if __name__ == '__main__':
    main()


Measured memory_bytes: 5728
// this is moxin's code

#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

#ifdef _LOCAL
struct Tester {
    Tester() { freopen("sample.in", "r", stdin); }
    ~Tester() { fprintf(stderr, "\nTime: %d ms\n", int(1000.0 * clock() / CLOCKS_PER_SEC)); }
} _tester;
#endif

const int INF = 0x3F3F3F3F;
const LL INFLL = 0x3F3F3F3F3F3F3F3FLL;
const int N = 2550;

map<string, int> mp;

int main() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    }
    LL sum = 0;
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        sum += (it->second - 1LL) * it->second / 2;
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
constexpr int MOD = 998244353, MX = 200005;
int n, m, k;
ll fact[MX] = {1}, invf[MX], ans;
ll exp(ll b, ll n){
	ll res = 1;
	for(; n; n/=2,(b*=b)%=MOD) if(n%2) (res *= b) %= MOD;
	return res;
}
void setcomb(int n){
	for(int i = 1; i <= n; i++) fact[i] = (fact[i-1] * i) % MOD;
	invf[n] =  exp(fact[n] ,MOD-2);
	for(int i = n; i > 0; i--) invf[i-1] = (invf[i] * i) % MOD;
}
inline ll comb(int a, int b){return fact[a] * invf[a-b] % MOD * invf[b] % MOD;}
int main(){
	scanf("%d%d%d", &n, &m, &k);
	setcomb(200000);
	rep(i,k+1) (ans += comb(n-1,i) * exp(m-1, n-i-1) % MOD * m) %= MOD;
	printf("%lld\n", ans);
}

Measured memory_bytes: 6896
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

string s, t;
ll DP[1001][1001];

int main() {
	cin >> s >> t;
	DP[0][0] = 1;
	for (int i = 1; i <= s.size(); ++i) {
		DP[i][0] = 1;
		for (int j = 1; j <= t.size(); ++j) {
			DP[i][j] = DP[i - 1][j];
			if (s[i - 1] == t[j - 1]) {
				DP[i][j] += DP[i - 1][j - 1];
				DP[i][j] %= mod;
			}
		}
	}
	cout << DP[s.size()][t.size()] << endl;
}


Measured memory_bytes: 11036
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,m;
vvp g;
vl a;
vp b;
vi par,used;

void dfs(int v,int pre){
	par[v]=pre;
	b[v]={0,v};
	for(auto p:g[v]){
		int u=p.first;
		if(u!=pre){
			dfs(u,v);
			b[v]=max(b[v],{b[u].first+p.second,b[u].second});
		}
	}
}

int main(){
	cin>>n>>m;
	g=vvp(n);
	for(int i=1;i<n;i++){
		int u,v,w;
		cin>>u>>v>>w;
		u--;v--;
		g[u].push_back({v,w});
		g[v].push_back({u,w});
	}
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		b=vp(n);
		par=used=vi(n);
		dfs(i,-1);
		priority_queue<P> q;
		q.push(b[i]);
		while(!q.empty()){
			P p=q.top();q.pop();
			int v=p.second;
			if(used[v]) continue;
			a.push_back(x*p.first);
			used[v]++;
			v=par[v];
			while(v>=0&&!used[v]){
				for(auto pp:g[v]){
					int u=pp.first,c=pp.second;
					if(u!=par[v]){
						int w=b[u].second;
						if(!used[w]) q.push({b[u].first+c,w});
					}
				}
				used[v]++;
				v=par[v];
			}
		}
	}
	sort(a.rbegin(),a.rend());
	int N=a.size();
	ll res=0;
	for(int i=0;i<min(N,m);i++) res+=a[i];
	cout<<res<<endl;
}


Measured memory_bytes: 36044
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){   
   int n,m;
   cin>>n>>m;
   
   int ac=0;
   int wa=0;
   int mondai[n];
   int b[n];
   rep(i,n){
      mondai[i]=0;
      b[i]=0;
   }
   rep(i,m){
      int p;
      string s;
      cin>>p>>s;
      p=p-1;
      if(s=="AC"){
         if(mondai[p]==0){
            mondai[p]=1;
            ac++;
         }
      }else{
         if(mondai[p]==0){
            b[p]++;
         }
      }
   }
   rep(i,n){
      if(b[i]!=0 && mondai[i]==1){
         wa+=b[i];
      }
   }
   cout<<ac<<" "<<wa<<endl;


   return 0;
}


Measured memory_bytes: 1024
//O(n) space
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int happiness[n][3];

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

    for(int i=1;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            happiness[i][j] = happiness[i][j] + max({ happiness[i-1][(j+1)%3],happiness[i-1][(j+2)%3] });
        }
    }

    int ans = 0;
    for(int i=0;i<3;i++)ans = max(ans,happiness[n-1][i]);

    cout<<ans;

}


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

int main(){
  string S;
  int count = 0;
  cin >> S;
  int N = S.size();
  for (int i = 0 ; i < N / 2 ; i ++){
    if(S.at(i) != S.at(N-i-1)){
      count ++ ;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<time.h>
#include<cstdlib>
typedef long long ll;
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mm(a) memset(a,0,sizeof(a))
#define lr rt<<1
#define rr rt<<1|1
#define sync std::ios::sync_with_stdio(false);std::cin.tie(0);
#define inf 0x3f3f3f3f
//#define eqs 1e-8
#define lb(x) (x&(-x))
#define ch(a) (int(a-'0'))
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
typedef pair<int,int> pii;
const double pi=acos(-1);
const int maxn=200010;
//const ll Mod=1000000007;
const ll Mod=998244353;
using namespace std;




string s;

int main()
{
    sync;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    
    
    
    
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static java.lang.Integer.parseInt;

/**
 * Problem A: Grey Area
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		Main main = new Main();

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n, w;
			n = parseInt(line.substring(0, line.indexOf(' ')));
			w = parseInt(line.substring(line.indexOf(' ') + 1));
			if ((n | w) == 0) break;

			int omax = 0;   //occurence
			int imax = 0;   //interval
			int[] h = new int[11];

			for (int i = 0; i < n; i++) {
				int v = parseInt(br.readLine());
				int c = v / w;
				h[c]++;
				omax = Math.max(omax, h[c]);
				imax = Math.max(imax, c);
			}

			Fraction ans = main.new Fraction(omax, h[0]);
			for (int i = imax - 1, j = 1; i >= 0; i--, j++) {
				ans = ans.plus(main.new Fraction(imax, i).multi(main.new Fraction(omax, h[j])));
			}
			System.out.println(ans.toDouble() + 0.01);
		} //end while
	} //end main


	class Fraction {
		int d;  //denominator
		int n;  //numerator

		Fraction(int d, int n) {
			this.d = d;
			this.n = n;
		}

		Fraction plus(Fraction o) {
			int _d = lcm(this.d, o.d);
			int _n = this.n * (_d / this.d) + o.n * (_d / o.d);
			int g = gcd(_d, _n);
			_d /= g;
			_n /= g;
			return new Fraction(_d, _n);
		}

		Fraction multi(Fraction o) {
			int _d = this.d * o.d;
			int _n = this.n * o.n;
			return new Fraction(_d, _n);
		}

		double toDouble() {
			return (double) n / d;
		}
	}

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

	static int lcm(int a, int b) {
		return a * (b / gcd(a, b));
	}
}

Measured memory_bytes: 25032
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
/*-----------------------------------------------------------------------------------------------------*/

const int M = 2e5 + 25, lgn = 40;
ll is[lgn][M];
ll sum[lgn][M];

signed main() {
	EmiliaMyWife

	ll n, x, m;
	cin >> n >> x >> m;
	for(ll i = 0; i < m; i++)
		is[0][i] = sum[0][i] = i * i % m;
	for(int j = 1; j < lgn; j++) {
		for(int i = 0; i < m; i++) {
			sum[j][i] = sum[j - 1][i] + sum[j - 1][is[j - 1][i]];
			is[j][i] = is[j - 1][is[j - 1][i]];
		}
	}
	ll res = x;
	ll ans = x;
	n--;
	for(int i = 0; i < lgn; i++)
		if((1LL << i) & n)
			ans += sum[i][res], res = is[i][res];//, cout << ans << ' ' << res << '\n';
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 66416
object Main extends App {
  val sc = new java.util.Scanner(Console.in)

  def nextInt() = Integer.parseInt(sc.next)
  def next() = sc.next

  def game(n:Int, taro:Int, hanako:Int): Tuple2[Int, Int] = {
    if (n == 0)
      (taro, hanako)
    else {
      val cmp = next compare next
      if (cmp > 0)
        game(n-1, taro+3, hanako)
      else if (cmp < 0)
        game(n-1, taro, hanako+3)
      else
        game(n-1, taro+1, hanako+1)
    }
  }

  val (taro, hanako) = game(nextInt, 0, 0)
  println(s"$taro $hanako")
}



Measured memory_bytes: 47356
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)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
    input!{
        n:usize,
        s:[chars;n],
    }
    let mut map = HashMap::new();
    for i in 0..n {
        let mut ss = s[i].clone();
        ss.sort();
        let ctos:String = ss.iter().map(|&c| c).collect();
        *map.entry(ctos).or_insert(0) += 1;
    }
    let mut ans : i64 = 0;
    for (_,c) in map.into_iter() {
        ans +=  c * (c-1)/2;
    }
    println!("{}",ans)
}


fn is_prime(x:i64) -> bool {
    if x == 2 {return true;}
    if x < 2 || x % 2 == 0 {return false;}
    let mut j = 3;
    while j <= (x as f64).sqrt() as i64 {
        if x % j == 0 {
            return false;
        }
        j += 2;
    }
    true
}


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

int main() {
  ll A, B, X; cin >> A >> B >> X;
  ll ans;
//  if (X > B) ans = 0;
  ans = B/X - A/X;
  if(A%X == 0) ans++;  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <string.h>
#include <inttypes.h>

#define INF INT64_C(99999999999999999)

int N, M;
int64_t x[1024], y[1024], z[1024];

int64_t score[1024];

int64_t memo[1024][1024];

int64_t mikakosi(int pos, int left) {
	int64_t answer, candidate;
	if (left <= 0) return 0;
	if (pos >= N) return -INF;
	if (memo[pos][left]) return ~memo[pos][left];

	/* 食べる */
	answer = mikakosi(pos + 1, left - 1) + score[pos];
	/* 食べない */
	candidate = mikakosi(pos + 1, left);
	if (candidate > answer) answer = candidate;

	return ~(memo[pos][left] = ~answer);
}

int main(void) {
	int i;
	int64_t answer = -INF;
	int search;
	if (scanf("%d%d", &N, &M) != 2) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%" SCNd64 "%" SCNd64 "%" SCNd64, &x[i], &y[i], &z[i]) != 3) return 1;
	}
	for (search = 0; search < 8; search++) {
		int64_t candidate;
		for (i = 0; i < N; i++) {
			score[i] = 0;
			if (search & 1) score[i] += x[i]; else score[i] -= x[i];
			if (search & 2) score[i] += y[i]; else score[i] -= y[i];
			if (search & 4) score[i] += z[i]; else score[i] -= z[i];
		}
		memset(memo, 0, sizeof(memo));
		candidate = mikakosi(0, M);
		if (candidate > answer) answer = candidate;
	}
	printf("%" PRId64 "\n", answer);
	return 0;
}


Measured memory_bytes: 8448
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	UL A[2000];
	UL m[2000];
	
	void Solve() {
		UL N; cin >> N;
		UL K; cin >> K;
		UL ans = 0;
		vector<UL> A(N); rep(i, N) { cin >> A[i]; A[i]--; }
		if (A[0] != 0) ans++;
		A[0] = 0;
		vector<UL> iA(N);
		for (UL i = 1; i < N; i++) {
			iA[A[i]]++;
		}
		vector<UL> dp(N);
		queue<UL> q;
		for (UL i = 1; i < N; i++) if(iA[i] == 0) q.push(i);
		while (q.size()) {
			UL p = q.front(); q.pop();
			dp[p]++;
			UL nx = A[p];
			if (nx == 0) continue;
			if (dp[p] == K) {
				ans++;
				dp[p] = 0;
			}
			dp[nx] = max(dp[nx], dp[p]);
			iA[nx]--;
			if (iA[nx] == 0) q.push(nx);
		}
		cout << ans << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 1792
import java.io.*;

public class Main{
	public static void main(String args[]){
		try{
			new Main();
		}catch(IOException e){
			e.printStackTrace();
		}
	}

	public String[][] unit = new String[][]{
		{"*", " ", "=", " ", "*", "*", "*", "*"},
		{"*", " ", "=", "*", " ", "*", "*", "*"},
		{"*", " ", "=", "*", "*", " ", "*", "*"},
		{"*", " ", "=", "*", "*", "*", " ", "*"},
		{"*", " ", "=", "*", "*", "*", "*", " "},
		{" ", "*", "=", " ", "*", "*", "*", "*"},
		{" ", "*", "=", "*", " ", "*", "*", "*"},
		{" ", "*", "=", "*", "*", " ", "*", "*"},
		{" ", "*", "=", "*", "*", "*", " ", "*"},
		{" ", "*", "=", "*", "*", "*", "*", " "},
	};

	public Main() throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line;
		int ln = 0;

		while((line = in.readLine()) != null){
			if(ln != 0) System.out.println();
			else ln++;
			int num = Integer.parseInt(line);
			String[][] abacus = new String[5][];
			int div = 10000;
			int current = 0;
			for(int i=0; i<5; i++){
				int digit = (num - current) / div;
				current += digit * div;
				div /= 10;
				abacus[i] = unit[digit];
			}

			for(int j=0; j<8; j++){
				for(int i=0; i<5; i++){
					System.out.print(abacus[i][j]);
				}
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 11000
#include <iostream>
#include <deque>
using namespace std;
int main() {
	// your code goes here
	int n,r,c;
	while(cin >> n>>r){
		deque<int> A,B,C;
		for(int i=0;i<n;i++)
		C.push_back(i);
		for(int i=0;i<r;i++){
			cin >>c;
			for(int i=0;i<n/2;i++)
				B.push_back(C[i]);
			for(int i=n/2;i<n;i++)
				A.push_back(C[i]);
			C.clear();
			while(!(A.empty()&&B.empty())){
				for(int i=0;i<c &&(!A.empty());i++){
					C.push_back(A.front());
					A.pop_front();
				}	
				for(int i=0;i<c &&(!B.empty());i++){
					C.push_back(B.front());
					B.pop_front();
				}
			}
		}
		cout << C.back() << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
import java.util.*;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		StringBuilder build = new StringBuilder();
		for(int i = 0; i < N; i++){
			build.append(sc.nextInt());
		}
		
		for(int i = 0; i < 10000; i++){
			if(build.indexOf(Integer.toString(i)) == -1){
				System.out.println(i);
				break;
			}
		}
	}

}

Measured memory_bytes: 30592
from collections import Counter
n = int(input())
a= list(map(int,input().split()))
if n == 1:
  print(1)
  exit()

a.sort()

c = Counter(a)
a = list(set(a))
dp = [0] * (10**6 +1)

for x in a:
  t = x * 2
  while t <= 10**6:
    dp[t] = 1
    t += x

ans = 0
for x in a:
  if (c[x] == 1) & (dp[x] == 0):
    ans += 1

print(ans)


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

int main(){
    //int flag=1;
    int a,b,k;
    //int ans=0;
    cin >>a>>b>>k;
    
    if((b-a+1)<2*k){

        for (int i = a; i <= b; i++){
            cout << i <<endl;
        }

    }else{
        for (int i = a; i < a+k; i++){
            cout << i <<endl;
        }
        for (int i = b+(1-k); i <= b; i++){
            cout << i <<endl;
        }
    }

    //cout <<fixed<<setprecision(16)<< ans <<endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int res;

int main() {
	int r,g,b,n,m,i,j,k;
	cin>>r>>g>>b>>n;
	m = n;
	for(i=0;i<=n/r;i++){
		m = n;
		m -= i*r;
		for(j=0;j<=m/g;j++){
			m -= j*g;
			if(m%b==0) res++;
			m += j*g;
		}
	}
	cout<<res;
	return 0;
}


Measured memory_bytes: 256
# AGC003A - Wanna go back home
def main():
    S = input().rstrip()
    D = {"N": 0, "S": 0, "E": 0, "W": 0}
    for i in S:
        D[i] += 1

    flg = [True] * 2
    if (D["N"] != 0 and D["S"] == 0) or (D["N"] == 0 and D["S"] != 0):
        flg[0] = False
    
    if (D["E"] != 0 and D["W"] == 0) or (D["E"] == 0 and D["W"] != 0):
        flg[1] = False

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


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using lint128 = __int128_t;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void assert_NO(T condition){ if(!condition){ cout << "NO" << endl; exit(0); } }
template<class T> inline void assert_No(T condition){ if(!condition){ cout << "No" << endl; exit(0); } }
template<class T> inline void assert_minus_1(T condition){ if(!condition){ cout << -1 << endl; exit(0); } }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
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; }
inline int at(lint x, int k){ return (x >> k) & 1; }
random_device rnd;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int N, M;
    cin >> N >> M;
    cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
}


Measured memory_bytes: 768
N = int(input())
ans = 0
a = 0
b = 0
ab = 0
for i in range(N):
    s = input()
    ans += s.count("AB")
    a += s[-1]=="A"
    b += s[0]=="B"
    ab += (s[-1]=="A" and s[0]=="B")
if a==b==ab:
    if a!=0:
    	ans += a - 1
else:
    ans += min(a, b)
print(ans)


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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;
string s;

int go(int x) {
  int n = s.length();
  int cnt=0;
  for (int i=0; i<n; i++) {
    int d = s[i]-'0';
    if (i%2==0 && d!=x) cnt++;
    if (i%2==1 && d==x) cnt++;
  }
  return cnt;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
char x; cin>>x;
  if (x=='A') out('T');
  if (x=='T') out('A');
  if (x=='G') out('C');
  if (x=='C') out('G');

  

  return 0;
}


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

using namespace std;

#define FOR(i,n) for(int i=0; i<n; ++i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
 
int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){

    int a,b,c, times;

    cin >> a >> b >> c;
    times = b/a;
    if(times > c)
        cout << c;
    else if(times == 0)
        cout << 0;
    else
        cout << times;

    return 0;
}


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

int main(void) {
  int N;
  cin >> N;
  set<int> s;
  for (int i = 0; i < N; i++) {
    int d;
    cin >> d;
    s.insert(d);
  }
  cout << s.size() << endl;
  return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.array, std.algorithm,
    std.numeric, std.math, std.range;

void main()
{
    string s = readln.strip;
    long[] xs = new long[](s.length);

    char prev = 'x';
    bool last_even = false;
    long last_marked = -1;
    long next = 0;
    long next_1 = 0;
    foreach (i; 0 .. s.length)
    {
        if (prev == 'R' && s[i] == 'L')
        {
            last_marked = i - 1;
            last_even = (i - 1) % 2 == 0;
            if ((i - 1) % 2 == 0)
            {
                xs[i - 1] = next;
                xs[i] = next_1;
            }
            else
            {
                xs[i - 1] = next_1;
                xs[i] = next;
            }
            next = 0;
            next_1 = 0;
        }
        if (s[i] == 'L')
        {
            if (last_even == (i % 2 == 0))
            {
                xs[last_marked]++;
            }
            else
            {
                xs[last_marked + 1]++;
            }
        }
        else
        {
            if (i % 2 == 0)
            {
                next++;
            }
            else
            {
                next_1++;
            }
        }

        prev = s[i];
    }
    xs.map!(x => x.to!string).join(" ").writeln;
}


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

#define rep(i, N) for (i = 0; i < N; i++)

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

  string S;
  cin >> S;
  int ans = 0;
  int i;
  rep(i, N - 2)
  {
    string tmp = "";
    tmp += S[i];
    tmp += S[i + 1];
    tmp += S[i + 2];

    if (tmp == "ABC")
      ans++;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int N=1e5+5,M=2e5+5;
int n,m;
int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
struct Node1{int a,b;}bomb[N];
struct Node2{int l,r,id;}cord[M];
struct Node3{int nxt,to,id;}Edges[M*2];
int num[N],cnt=0,w[N],head[N],tot=0;
bool vis[N],legal=true;
vector<int>c;
int getw(int x){return lower_bound(num+1,num+1+cnt,x)-num;}
void addedge(int u,int v,int id)
{
	Edges[++tot].nxt=head[u];
	head[u]=tot;
	Edges[tot].id=id,Edges[tot].to=v;
}
void dfs(int u,int f,int fEdge)
{
	vis[u]=1;
	for(int i=head[u];~i;i=Edges[i].nxt)
	{
		int v=Edges[i].to;
		if(!vis[v])dfs(v,u,Edges[i].id);
	}
	if(w[u]==1)
	{
		if(!f){legal=0;return;}
		w[u]^=1,w[f]^=1,c.push_back(fEdge);
	}
}
int main()
{
	memset(head,-1,sizeof(head));
	n=read(),m=read();
	for(int i=1;i<=n;i++)
	{
		bomb[i].a=read(),bomb[i].b=read();
		num[++cnt]=bomb[i].a;
	}
	sort(num+1,num+1+cnt);
	cnt=unique(num+1,num+1+cnt)-num-1;
	for(int i=1;i<=n;i++)w[getw(bomb[i].a)]=bomb[i].b;
	for(int i=cnt+1;i;i--)w[i]^=w[i-1];
	for(int i=1;i<=m;i++)
	{
		cord[i].l=read(),cord[i].r=read(),cord[i].id=i;
		int x=getw(cord[i].l),y=getw(cord[i].r+1);
		addedge(x,y,i),addedge(y,x,i);
	}
	for(int i=1;i<=cnt+1;i++)
	{
		if(!vis[i])dfs(i,0,0);
		if(!legal)break;
	}
	if(!legal)puts("-1");
	else
	{
		printf("%d\n",c.size());
		sort(c.begin(),c.end());
		for(int i=0;i<c.size();i++)printf("%d ",c[i]);
	}
	return 0;
}


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

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  
  map<ll, ll> length;
  for (int i = 0; i < N; i++) length[A.at(i)]++;
  ll a1 = 0;
  ll a2 = 0;
  for (auto i : length) {
    if (i.second >= 4) {
      a1 = max(a1,i.first);
      a2 = max(a2,i.first);
    } else if (i.second >= 2) {
      if (a1 > a2) a2 = max(a2,i.first);
      else a1 = max(a1,i.first);
    }
  }
  ll S = a1 * a2;
  cout << S << endl;  
}

Measured memory_bytes: 7296